Hard String Problem
题号:NC210259
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld

题目描述

One day, Apollo and Avery find a collection T of n spells, each of which can be obtained by repeating some section infinitely.
For example, by repeating the section 'abc', we can get the spell 'abcabcabc...'.
The two kids learnt how to count common substrings of many strings in Mr.Calabash's string course yesterday. However, they find it hard to count that of these spells. Can you help the two poor kids?
Let F(s) be the set of all substrings of spell s. You should tell the two kids .

输入描述:

The first line contains one integer , the number of spells two kids found.
Then next n lines, each line contains a string , which represents the i-th spell repeated by s_is_i consists of lowercase English letters.
Note that .

输出描述:

One integer in one line, representing the number of common substrings of these n spells, or -1 instead if the number of common substrings is infinite.
示例1

输入

复制
3
bcbcbc
bbbccc
cbcbcb

输出

复制
4

说明

In the first example, there are three spells: `\textbf{bcbcbc}bcbcbc...' , `\textbf{bbbccc}bbbccc...', `\textbf{cbcbcb}cbcb...'. They have four common substrings: `\textbf{b}', `\textbf{c}', `\textbf{bc}', `\textbf{cb}'.
示例2

输入

复制
5
abacbc
abacabac
ccaccb
cbcaba
cbccac

输出

复制
5