Codeforces Round 385 (Div. 1)
E
Hongcow Masters the Cyclic Shift
Codeforces
3200
原题
← D→
翻译中…

Hongcow's teacher heard that Hongcow had learned about the cyclic shift, and decided to set the following problem for him.

翻译中…

You are given a list of $*n*$ strings $*s*_{1}, *s*_{2}, ..., *s*_{*n*}$ contained in the list $*A*$.

翻译中…

A list $*X*$ of strings is called stable if the following condition holds.

翻译中…

First, a message is defined as a concatenation of some elements of the list $*X*$. You can use an arbitrary element as many times as you want, and you may concatenate these elements in any arbitrary order. Let $*S*_{*X*}$ denote the set of of all messages you can construct from the list. Of course, this set has infinite size if your list is nonempty.

翻译中…

Call a single message good if the following conditions hold:

翻译中…
  • Suppose the message is the concatenation of $*k*$ strings $*w*_{1}, *w*_{2}, ..., *w*_{*k*}$, where each $*w*_{*i*}$ is an element of $*X*$.
  • Consider the $|*w*_{1}| + |*w*_{2}| + ... + |*w*_{*k*}|$ cyclic shifts of the string. Let $*m*$ be the number of these cyclic shifts of the string that are elements of $*S*_{*X*}$.
  • A message is good if and only if $*m*$ is exactly equal to $*k*$.
翻译中…

The list $*X*$ is called stable if and only if every element of $*S*_{*X*}$ is good.

翻译中…

Let $*f*(*L*)$ be $1$ if $*L*$ is a stable list, and $0$ otherwise.

翻译中…

Find the sum of $*f*(*L*)$ where $*L*$ is a nonempty contiguous sublist of $*A*$ (there are image contiguous sublists in total).

翻译中…

Input

翻译中…

The first line of input will contain a single integer $*n*$ ($1 ≤ *n* ≤ 30$), denoting the number of strings in the list.

翻译中…

The next $*n*$ lines will each contain a string $*s*_{*i*}$ (image).

翻译中…

Output

翻译中…

Print a single integer, the number of nonempty contiguous sublists that are stable.

翻译中…

Note

翻译中…

For the first sample, there are $10$ sublists to consider. Sublists ["a", "ab", "b"], ["ab", "b", "bba"], and ["a", "ab", "b", "bba"] are not stable. The other seven sublists are stable.

翻译中…

For example, $*X*$ = ["a", "ab", "b"] is not stable, since the message "ab" + "ab" = "abab" has four cyclic shifts ["abab", "baba", "abab", "baba"], which are all elements of $*S*_{*X*}$.

翻译中…

样例

Input #1
4
a
ab
b
bba
Output #1
7
InputCopy OutputCopy
Input #2
5
hh
ee
ll
ll
oo
Output #2
0
InputCopy OutputCopy
Input #3
6
aab
ab
bba
b
ab
c
Output #3
13
InputCopy OutputCopy
题目信息
题号
744E
时间限制
5 s
内存限制
256 MB
标签
字符串
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。