1430_E. String Reversal
You are given a string s. You have to reverse it — that is, the first letter should become equal to the last letter before the reversal, the second letter should become equal to the second-to-last letter before the reversal — and so on. For example, if your goal is to reverse the string "abddea", you should get the string "aeddba". To accomplish your goal, you can swap the neighboring elements of the string. 

Your task is to calculate the minimum number of swaps you have to perform to reverse the given string.

Input

The first line contains one integer n (2 ≤ n ≤ 200 000) — the length of s.

The second line contains s — a string consisting of n lowercase Latin letters.

Output

Print one integer — the minimum number of swaps of neighboring elements you have to perform to reverse the string.

Examples

Input


5
aaaza


Output


2


Input


6
cbaabc


Output


0


Input


9
icpcsguru


Output


30

Note

In the first example, you have to swap the third and the fourth elements, so the string becomes "aazaa". Then you have to swap the second and the third elements, so the string becomes "azaaa". So, it is possible to reverse the string in two swaps.

Since the string in the second example is a palindrome, you don't have to do anything to reverse it.
```python
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
##########################################################
import math
import bisect
# for _ in range(int(input())):
from collections import Counter
# sys.setrecursionlimit(10**6)
# dp=[[-1 for i in range(n+5)]for j in range(cap+5)]
# arr= list(map(int, input().split()))
# n,m= map(int, input().split())
# arr= list(map(int, input().split()))
# for _ in range(int(input())):
import bisect
# n=int(input())
#for _ in range(int(input())):
n=int(input())
from collections import defaultdict
#n,m=map(int, input().split())
#arr= list(map(int, input().split()))
# Python3 program to count inversions using
s=input()
t=s[::-1]
d=defaultdict(lambda :[])
for ind,val in enumerate(t):
    d[val].append(ind)
for i in d.keys():
    d[i].reverse()
arr=[]
bit=[0]*(n+1)
for c in s:
    arr.append(d[c].pop())

def bit_sum(ind):
    val=0
    while ind>0:
        val+=bit[ind]
        ind-=(ind & -ind)
    return val

def bit_up(ind,w):
    while ind<=n:
        bit[ind]+=w
        ind+=(ind &-ind)



inv=0
for val in reversed(arr):
    inv+=bit_sum(val+1)
    bit_up(val+1,1)
print(inv)

```