Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/ikki-korsatkich-anagramma-orinlari

Anagrams in a text

Medium 1000 ms 128 MB 64%
Share

Two strings $s$ and $p$ are given. How many segments of $|p|$ consecutive letters of $s$ are anagrams of $p$ (made of the same letters in the same quantities, possibly in a different order)? Segments starting at different positions are counted separately.

A window of length |p| slides over the string; the windows that are anagrams of p are highlighted

Input

The first line contains $s$, the second line contains $p$.

Output

One integer — the number of anagram segments.

Note

$1 \le |s|, |p| \le 10^{5}$
the strings consist of lowercase Latin letters

Examples

Input #1
cbaebabacd
abc
Output #1
2
Input #2
ab
abc
Output #2
0

Sign in to submit a solution

Signing up is free and takes a minute.