Synchronous Echo#13118

Synchronous Echo

3 Sekunden
256 Megabyte

You are given two strings and consisting of lowercase English letters.

For a nonempty string , let p_1<p_2<\ldots<p_k be all starting positions of its occurrences in , and let q_1<q_2<\ldots<q_m be all starting positions of its occurrences in . Positions are numbered starting from .

We call synchronous if k=m\ge 3 and there is an integer such that

q_i=p_i+d\quad\text{for every }1\le i\le k.

In other words, shifting all occurrences of in one string by the same amount makes them coincide with all its occurrences in the other string. The shift may be positive, negative, or zero, and may differ for different strings .

Find the number of distinct nonempty synchronous strings. Two strings are distinct if they have different lengths or differ in at least one character. Occurrences may overlap.

Eingabe

The first line contains , and the second line contains (1\le |s|,|t|\le 2\cdot 10^5). Both strings contain only lowercase English letters.

Ausgabe

Print one integer — the number of distinct nonempty synchronous strings.

Beispiele

Beispiel 1

Loading
Loading

Beispiel 2

Loading
Loading

Beispiel 3

Loading
Loading

Notiz

In the first example, the six suitable strings are a, b, c, ab, bc, and abc. In particular, abc occurs in at positions and in at positions , so its shift is d=1.

In the second example, a occurs three times in each string, but its starting positions are and . No single shift makes these sets coincide. No other string occurs at least three times in both strings.

In the third example, the suitable strings are a, aa, and aaa.

Bewertung

  1. Subtask ( points): |s|,|t|\le 12.

  2. Subtask ( points): |s|,|t|\le 100.

  3. Subtask ( points): |s|,|t|\le 2000.

  4. Subtask ( points): s=t.

  5. Subtask ( points): \min(|s|,|t|)\le 200.

  6. Subtask ( points): no additional constraints.