Near Future. Yamochka works at a string printing factory. She is currently tasked with printing the string S. To complete the job, Yamochka chooses a non-empty prefix of S of length l, after which she prints it several times in a row. She selects the number of repetitions and the length l such that the resulting string equals the original S. To print the prefix once, Yamochka requires l2 seconds.
If Yamochka works on the same task for too long, she starts to relax and gradually slows down her production, which displeases her boss Vadim, who has a set of M strings ti. To achieve maximum productivity from his worker, Vadim occasionally takes a string tkj from the set and selects an index pj, after which he replaces the substring Spj Spj+1 … Spj+|tkj|−1 with tkj. For example, if S = “aboba”, tkj = “pupa” and pj = 2, then as a result, S will become “apupa”.
Yamochka is still young, so she wants to work as little as possible. Help her: for the initial string and after each modification, tell her the minimum time required to print S.
Input
The first line contains three integers N, M and Q — the length of the string S, the number of strings in Vadim’s set, and the number of modifications (1 ≤ N ≤ 2 · 105, 0 ≤ M, Q ≤ 2 · 105).
The next line contains the initial string S consisting of lowercase English letters.
The following M lines contain non-empty strings ti — Vadim’s set (1 ≤ |ti| ≤ 106). It is guaranteed that the total length of the strings in the set does not exceed 106.
The next Q lines describe the modifications with two integers pj and kj — the start of the segment and the index of the string from the set (1 ≤ pj ≤ N − |tkj| + 1, 1 ≤ kj ≤ M).
Output
In the first line, output the minimum required time before any modifications. In the following Q lines, output the minimum time after each corresponding modification.
Sample
input | output |
---|
4 3 3
abab
be
ebb
ee
3 1
1 2
2 3
| 8
16
16
4
|
Notes
After the first modification, the string will become “abbe”. After the second — “ebbe”. After the third — “eeee”.
Problem Author: Konstantin Rychkov
Problem Source: Ural Regional Contest Qualifier 2024