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
pythondef main(): import sys n = int(sys.stdin.readline()) s = sys.stdin.readline().strip() s_rev = s[::-1] m = len(s_rev) pi_rev = [0] * m for i in range(1, m): j = pi_rev[i - 1] while j > 0 and s_rev[i] != s_rev[j]: j = pi_rev[j - 1] if s_rev[i] == s_rev[j]: j += 1 pi_rev[i] = j res = [] for k in range(1, n + 1): L = n - k + 1 idx = L - 1 if idx >= m: m_max = 0 # Shouldn't happen since L <=n else: m_max = pi_rev[idx] if m_max == 0: res.append(-1) else: if m_max % 2 == 1: res.append(m_max) else: res.append(m_max - 1) print(' '.join(map(str, res))) 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.