Under construction

Still being built. Things may change

Stringology

Time limit1sMemory limit1024 MB

Summary
For each i from 0 to n-1, find the longest prefix of s, shorter than n, that is a suffix of pre(s, i) + t.
Level

Medium7 of 10

Topics
String, String matching
Solved
No attempts yet

Problem

For a string u=u1…unu = u_1 \dots u_n, pre(u,i)\mathrm{pre}(u, i) denotes the prefix u1…uiu_1 \dots u_i. Likewise, suf(u,i)\mathrm{suf}(u, i) denotes the suffix un−i+1…unu_{n-i+1} \dots u_n. Both pre(u,0)\mathrm{pre}(u, 0) and suf(u,0)\mathrm{suf}(u, 0) are empty strings.

For two strings u=u1…unu = u_1 \dots u_n and v=v1…vmv = v_1 \dots v_m, u+vu + v denotes the concatenation u1…unv1…vmu_1 \dots u_n v_1 \dots v_m. Also,

presuf(u,v)=max⁡{i∣i<n and i≤m and pre(u,i)=suf(v,i)}\mathrm{presuf}(u, v) = \max\{i \mid i < n \text{ and } i \leq m \text{ and } \mathrm{pre}(u, i) = \mathrm{suf}(v, i)\}

Given two strings s=s1…sns = s_1 \dots s_n and t=t1…tmt = t_1 \dots t_m, let f(i)=presuf(s,pre(s,i)+t)f(i) = \mathrm{presuf}(s, \mathrm{pre}(s, i) + t). Find f(0),…,f(n−1)f(0), \dots, f(n-1).

Input

The input consists of several test cases, ending at end-of-file. Each test case has two lines. The first line contains the string s1…sns_1 \dots s_n, and the second line contains the string t1…tmt_1 \dots t_m.

Output

For each test case, output nn integers f(0),…,f(n−1)f(0), \dots, f(n-1).

Constraints

1≤n,m≤1061 \leq n, m \leq 10^6. Each sis_i and tit_i is a lowercase letter from a to z. In each input, the sum of max⁡(n,m)\max(n, m) is at most 10610^6.

Hint

For the second case, f(4)=presuf(ababa,abab+a)=presuf(ababa,ababa)f(4) = \mathrm{presuf}(\mathtt{ababa}, \mathtt{abab} + \mathtt{a}) = \mathrm{presuf}(\mathtt{ababa}, \mathtt{ababa}).

iipre(ababa,i)\mathrm{pre}(\mathtt{ababa}, i)suf(ababa,i)\mathrm{suf}(\mathtt{ababa}, i)
00(empty string)(empty string)
11a\mathtt{a}a\mathtt{a}
22ab\mathtt{ab}ba\mathtt{ba}
33aba\mathtt{aba}aba\mathtt{aba}
44abab\mathtt{abab}baba\mathtt{baba}

So f(4)=3f(4) = 3.

Examples1

  1. Example 1

    Input
    aaa
    a
    ababa
    a
    ab
    cd
    
    Expected output
    1 2 2
    1 1 3 1 3
    0 0