You are given a string s consisting of n lowercase Latin letters. Let's denote…
- User
You are given a string s consisting of n lowercase Latin letters.
Let's denote k-substring of s as a string subsk = sksk + 1..sn + 1 - k. Obviously, subs1 = s, and there are exactly such substrings.
Let's call some string t an odd proper suprefix of a string T iff the following conditions are met:
- |T| > |t|;
- |t| is an odd number;
- t is simultaneously a prefix and a suffix of T.
For evey k-substring () of s you have to calculate the maximum length of its odd proper suprefix. Input
The first line contains one integer n (2 ≤ n ≤ 106) — the length s.
The second line contains the string s consisting of n lowercase Latin letters.
Output
Print integers. i-th of them should be equal to maximum length of an odd proper suprefix of i-substring of s (or - 1, if there is no such string that is an odd proper suprefix of i-substring).
Examples
Input
15 bcabcabcabcabca
Output
9 7 5 3 1 -1 -1 -1
Input
24 abaaabaaaabaaabaaaabaaab
Output
15 13 11 9 7 5 3 1 1 -1 -1 1
Input
19 cabcabbcabcabbcabca
Output
5 3 1 -1 -1 1 1 -1 -1 -1
Note
The answer for first sample test is folowing:
- 1-substring: bcabcabcabcabca
- 2-substring: cabcabcabcabc
- 3-substring: abcabcabcab
- 4-substring: bcabcabca
- 5-substring: cabcabc
- 6-substring: abcab
- 7-substring: bca
- 8-substring: c
Assistant
import sys def main(): n = int(sys.stdin.readline()) s = sys.stdin.readline().strip() s = ' ' + s # 1-based indexing base1 = 911382629 mod1 = 10**18 + 3 base2 = 357142857 mod2 = 10**18 + 7 max_n = n # Precompute power arrays for base1 and base2 power1 = [1] * (max_n + 1) for i in range(1, max_n + 1): power1[i] = (power1[i-1] * base1) % mod1 power2 = [1] * (max_n + 1) for i in range(1, max_n + 1): power2[i] = (power2[i-1] * base2) % mod2 # Precompute hash arrays hash1 = [0] * (n + 1) hash2 = [0] * (n + 1) for i in range(1, n + 1): hash1[i] = (hash1[i-1] * base1 + ord(s[i])) % mod1 hash2[i] = (hash2[i-1] * base2 + ord(s[i])) % mod2 def get_hash(a, b, h, power, base, mod): length = b - a + 1 res = (h[b] - h[a-1] * power[length]) % mod return res ans_list = [] max_k = (n + 1) // 2 for k in range(1, max_k + 1): start = k end = n + 1 - k L = end - start + 1 if L < 2: ans_list.append(-1) continue low = 1 high = L - 1 max_m = 0 while low <= high: mid = (low + high) // 2 a_f = start b_f = a_f + mid - 1 a_e = end - mid + 1 b_e = end h1_f = get_hash(a_f, b_f, hash1, power1, base1, mod1) h1_e = get_hash(a_e, b_e, hash1, power1, base1, mod1) h2_f = get_hash(a_f, b_f, hash2, power2, base2, mod2) h2_e = get_hash(a_e, b_e, hash2, power2, base2, mod2) if h1_f == h1_e and h2_f == h2_e: if mid > max_m: max_m = mid low = mid + 1 else: high = mid - 1 if max_m == 0: ans_list.append(-1) else: candidate = max_m if (max_m % 2 == 1) else (max_m - 1) if candidate >= 1: ans_list.append(candidate) else: ans_list.append(-1) print(' '.join(map(str, ans_list))) if __name__ == "__main__": main()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.