TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

The operating system of your computer indexes the files on your hard disk based on their contents,
and provides textual search over them. The content of each file is a non-empty string of lowercase
letters. To do a search, you specify a key, which is also a non-empty string of lowercase letters. The
result is a list of all the files that contain the key as a substring. A string s is a substring of a string t
if t contains all characters of s as a contiguous sequence. For instance, foofoo",cafoo", foota" and
foo" all contain foo" as a substring, whilefoa", fofo",fioo" and ``oofo" do not.


You know the content of each file on your hard disk, and wonder whether each subset of the files
is searchable. A subset of the files is searchable if there exists at least one key that produces exactly
the list of those files as a result. Given the contents of the files on your hard disk, you are asked to
compute the number of non-empty searchable subsets.

Input Format

Each test case is described using several lines. The first line contains an integer F representing the number of files on your hard disk (1 ≤ F ≤ 60). Each of the next F lines indicates the content of one of the files. The content of a file is a non-empty string of at most 104 characters; each character is one of the 26 standard lowercase letters (from a' toz').

The last test case is followed by a line containing one zero.

Output Format

For each test case output a line with an integer representing the number of non-empty searchable subsets.

Sample Input 1

6
form
formal
malformed
for
man
remake
3
cool
cool
old
0

Sample Output 1

11
3

Hints

Problem Source

Migrated from old NTUJ.

ICPC Latin American Regional – 2011

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 10000 65536 200