atcoder#ARC130A. [ARC130A] Remove One Character

[ARC130A] Remove One Character

Score : 300300 points

Problem Statement

You are given a string SS of length NN. For each 1iN1\leq i\leq N, let SiS_i denote the string obtained by deleting the ii-th character from SS.

Find the number of pairs of integers (i,j)(i,j) that satisfy both of the conditions below.

  • 1i<jN1\leq i < j\leq N
  • Si=SjS_i = S_j

Constraints

  • 2N3×1052\leq N\leq 3\times 10^5
  • SS is a string of length NN consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

NN

SS

Output

Print the answer.

7
abbbcca
4

Here are the strings SiS_i in order: bbbcca, abbcca, abbcca, abbcca, abbbca, abbbca, abbbcc.

The following 44 pairs (i,j)(i,j) satisfy the conditions.

  • (i,j)=(2,3)(i,j) = (2,3)
  • (i,j)=(2,4)(i,j) = (2,4)
  • (i,j)=(3,4)(i,j) = (3,4)
  • (i,j)=(5,6)(i,j) = (5,6)
4
xxxx
6
2
pp
1
2
st
0