Under construction

Still being built. Things may change

Suffi⊗\otimes

Interview

Time limit0.5sMemory limit1024 MB

Summary
Count the suffixes that appear in an odd number of the N strings, since repeated XOR keeps only elements with odd multiplicity.
Level

Easy3 of 10

Topics
Hash map, String
Solved
No attempts yet

Statement

Bihaengssi is weak at strings and keeps studying string algorithms: LCS, KMP, Rabin-Karp, Aho-Corasick...

Bihaengssi's head exploded while staring at suffix arrays, so to cool off, they decide to organize the suffixes of the given strings. Plain sorting is dull, so they XOR the suffix sets instead.

For a string SS, the suffix set suffix[S]\text{suffix}[S] is the set whose elements are all suffixes of SS. The XOR A⊗BA\otimes B of two sets AA and BB is defined as follows.

A⊗B={x∣x∈A∪B and x∉A∩B}A\otimes B=\{x\mid x\in A\cup B\text{ and }x\not\in A\cap B\}

On behalf of Bihaengssi, write a program that counts the elements of the set obtained by XORing the suffix sets of the given strings S1,S2,⋯ ,SNS_1,S_2,\cdots,S_N in order: (⋯((suffix[S1]⊗suffix[S2])⊗suffix[S3])⋯⊗suffix[SN])(\cdots((\text{suffix}[S_1]\otimes\text{suffix}[S_2])\otimes\text{suffix}[S_3])\cdots\otimes\text{suffix}[S_N]).

Input

The first line contains an integer NN. (1≤N≤1 000)(1\le N\le 1\,000)

The following NN lines each contain one string SiS_i made of lowercase English letters only. (1≤∣Si∣≤50)(1\le |S_i|\le 50)

Output

Print the number of elements in (⋯((suffix[S1]⊗suffix[S2])⊗suffix[S3])⋯⊗suffix[SN])(\cdots((\text{suffix}[S_1]\otimes\text{suffix}[S_2])\otimes\text{suffix}[S_3])\cdots\otimes\text{suffix}[S_N]).

The empty set has 0 elements.

Examples1

  1. Example 1

    Input
    3
    a
    aba
    ababa
    
    Expected output
    3