#abc310c. C - Reversible

C - Reversible

Score : 300300 points

问题描述

NN 根棍子,每根棍子上粘着若干个球。每个球上都写有一个小写英文字母。

对于每个 i=1,2,,Ni = 1, 2, \ldots, N,第 ii 根棍子上的球所写的字母由字符串 SiS_i 表示。具体来说,第 ii 根棍子上粘着的球的数量就是字符串 SiS_i 的长度 Si|S_i|,而 SiS_i 是从棍子一端开始的球上的字母序列。

当一根棍子从一端开始的球上的字母序列等于另一根棍子从一端开始的字母序列时,这两根棍子被认为是相同的。更形式化地讲,对于整数 iijj 在闭区间 11NN 内,如果满足 SiS_i 等于 SjS_j 或其反转,则认为第 ii 根和第 jj 根棍子是相同的。

请输出这 NN 根棍子中有多少种不同的棍子。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There are NN sticks with several balls stuck onto them. Each ball has a lowercase English letter written on it.

For each i=1,2,,Ni = 1, 2, \ldots, N, the letters written on the balls stuck onto the ii-th stick are represented by a string SiS_i. Specifically, the number of balls stuck onto the ii-th stick is the length Si|S_i| of the string SiS_i, and SiS_i is the sequence of letters on the balls starting from one end of the stick.

Two sticks are considered the same when the sequence of letters on the balls starting from one end of one stick is equal to the sequence of letters starting from one end of the other stick. More formally, for integers ii and jj between 11 and NN, inclusive, the ii-th and jj-th sticks are considered the same if and only if SiS_i equals SjS_j or its reversal.

Print the number of different sticks among the NN sticks.

Constraints

  • NN is an integer.
  • 2N2×1052 \leq N \leq 2 \times 10^5
  • SiS_i is a string consisting of lowercase English letters.
  • Si1|S_i| \geq 1
  • i=1NSi2×105\sum_{i = 1}^N |S_i| \leq 2 \times 10^5

Input

The input is given from Standard Input in the following format:

NN

S1S_1

S2S_2

\vdots

SNS_N

Output

Print the answer.

Sample Input 1

6
a
abc
de
cba
de
abc

Sample Output 1

3
  • S2S_2 = abc equals the reversal of S4S_4 = cba, so the second and fourth sticks are considered the same.
  • S2S_2 = abc equals S6S_6 = abc, so the second and sixth sticks are considered the same.
  • S3S_3 = de equals S5S_5 = de, so the third and fifth sticks are considered the same.

Therefore, there are three different sticks among the six: the first, second (same as the fourth and sixth), and third (same as the fifth).

update @ 2024/3/10 08:48:04