Signboard

Interview

Time limit1sMemory limit256 MB

Summary
Count how many of the given strings contain the store name as an equally spaced subsequence, where each string counts at most once.
Level

Medium4 of 10

Topics
String, Brute force, Implementation
Solved
No attempts yet

Problem

Someone opened a new convenience store near a school. A store's face is its signboard, and because this store is not part of a franchise, the owner has to pay for and build the signboard himself.

To save money, he decides to reuse the NN old signboards that the previous owner left behind. From a single old signboard he wants to erase some characters so that the remaining string is exactly the store's name. The catch is that the remaining characters must all be equally spaced: there must be some starting position and a fixed step d≥1d \ge 1 such that reading the character at that position and every dd-th position afterward spells the store's name.

A new signboard must be made from a single old signboard; it cannot be cut or glued together. Even if one old signboard can produce the name in several different ways, it still counts as only one usable signboard.

Given the store's name and the old signboards, write a program that counts how many new signboards can be made.

Input

The first line contains the number of old signboards NN (1≤N≤1001 \le N \le 100).

The second line contains the store's name, consisting only of lowercase letters, with length between 3 and 25 inclusive.

Each of the next NN lines contains the string written on one old signboard. Each string consists only of lowercase letters and has length between 1 and 100 inclusive.

Output

Print the number of new signboards that can be made.

Hint

Suppose the store's name is bar.

  • On the first signboard abracadabra, keeping only the 2nd, 6th, and 10th characters (step 4) spells bar.
  • On the second signboard bear, erasing the 2nd character leaves bar, but the remaining characters are not equally spaced.
  • The third signboard bar can be used as is.
  • On the fourth signboard baraxbara, keeping the 1st, 2nd, and 3rd characters, or the 6th, 7th, and 8th characters, spells bar.

So new signboards can be made from the first, third, and fourth signboards, and the answer is 3.

Examples6

  1. Example 1

    Input
    4
    bar
    abracadabra
    bear
    bar
    baraxbara
    
    Expected output
    3
    
  2. Example 2

    Input
    1
    abc
    abc
    
    Expected output
    1
    
  3. Example 3

    Input
    1
    abc
    ab
    
    Expected output
    0
    
  4. Example 4

    Input
    1
    abc
    abd
    
    Expected output
    0
    
  5. Example 5

    Input
    3
    aaa
    aaaaa
    abaca
    aabbb
    
    Expected output
    2
    
  6. Example 6

    Input
    1
    xyz
    xayaz
    
    Expected output
    1