Pattern matching#4172

Pattern matching

2 sekunt
64 megabaýt
Örän kyn

A string consists of characters from two disjoint alphabets, A_1 and A_2. Two strings are considered equal if there exists a one-to-one mapping (bijection) of the alphabet A_2 to itself such that, when this mapping is applied to the characters of the first string, it results in the second string.

With this definition of equality, we say that a pattern occurs in a string if there exists a substring of the string that is equal to the pattern under some bijection of A_2 to itself.

Given a string and a pattern, count the number of occurrences of the pattern in the string.

Giriş

The first line contains two integers, and — the number of characters in the first and second alphabets, respectively (1 \le N, M < 52).

The next two lines contain, without spaces, the characters of the alphabets A_1 and A_2, respectively. The alphabet characters are Latin letters, either lowercase or uppercase.

The fourth line contains the string. The fifth line contains the pattern.

The lengths of the string and the pattern do not exceed 10^5.

Çykyş

Print a single integer — the number of times the pattern occurs in the string.

Mysallar

1-nji mysal

Loading
Loading