String rotations P62097


Statement
 

pdf   zip

Given a string ss of size nn, we define the ii-th rotation of ss (for 0i<n0 \le i < n) as sisi+1sn1s0si2si1.s_i s_{i+1} \dots s_{n-1} s_0 \dots s_{i-2} s_{i-1} \enspace .

Given two strings ss and tt, compute how many ii-th rotations of ss are equal to tt.

For instance, for s=s =abbabb” and t=t =babbab” the answer is 2, corresponding to i=2i = 2 and i=5i = 5.

Input

Input consists of several cases, each one with two strings ss and tt with only lowercase letters. Assume 1|s|=|t|1051 \le \vert s \vert = \vert t \vert \le 10^5. Every letter appears the same number of times in ss and in tt.

Output

For every case, print the number of ii-th rotations of ss that are equal to tt.

Public test cases
  • Input

    abbabb babbab
    abc acb
    abba bbaa
    zzzzz zzzzz
    

    Output

    2
    0
    1
    5
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C C++ Rust