Adjacent Swapping
题号:NC243962
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

As usual, Cuber QQ will come up with a string-related problem to trouble you.

Cuber QQ wants to change the initial string to the string which is made from repetition through swapping adjacent characters in the string.

The string s which is made from repetition satisfies that s can be obtained by concatenating two identical strings x, i.e., .

Cuber QQ wants to know the least possible number of swaps of adjacent characters to make the string into the string which is made from repetition.

输入描述:

The first line contains an integer n (1\le n\le 200~000), which denotes the length of the string.

The second line contains a string s, which only contains the lowercase letters of the Latin alphabet.

It is guaranteed that the given string can change to the string which is made from repetition.

输出描述:

Output one integer which denotes the answer.
示例1

输入

复制
8
abbcdcad

输出

复制
4

说明

abbcdcad\leftarrow ab\underline{cb}dcad \leftarrow abc\underline{db}cad \leftarrow \underline{ba}cdbcad\leftarrow bacdb\underline{ac}d