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

题目描述

Two strings u1 u2 ... uk and v1 v2 ... vl are isomorphic if and only if k = l and there exists a injection g such that ui = g(vi) for all i ∈ {1, 2, ..., k}.
Note that a function f is injection if and only if f(x) ≠ f(y) for all x ≠ y.
Bobo would like to choose some strings from all n(n +1)/2 substrings of the given string s1 s2 ... sn.
Find out the maximum number of strings he may choose so that no two chosen strings are isomorphic.

输入描述:

The input consists of several test cases and is terminated by end-of-file.
The first line of each test case contains an integer n.
The second line contains a string s1, s2, ..., sn.

输出描述:

For each test case, print an integer which denotes the result.
示例1

输入

复制
4
abaa
4
abab

输出

复制
6
4

备注:

* 1 ≤ n ≤ 5x 104
* si ∈ {a, b, c}
* The sum of n does not exceed 2 x 105.