Hyperdrome

Time limit2sMemory limit128 MB

Summary
Count substrings of S whose characters can be rearranged into a palindrome, where only the parity of each letter's count matters.
Level

Medium7 of 10

Topics
Bit manipulation, Prefix sum, Hash map, String
Solved
No attempts yet

Problem

A string is called a hyperdrome if its characters can be rearranged into a palindrome.

Given a string SS, count how many of its substrings are hyperdromes.

A substring of SS is the string formed by the ii-th through jj-th characters (1≤i≤j≤n1 \le i \le j \le n). Two substrings with the same content but different (i,j)(i, j) are counted as different substrings.

A string x1x2…xlx_1 x_2 \dots x_l is a palindrome if xi=xl−i+1x_i = x_{l-i+1} holds for every position ii.

SS consists of uppercase and lowercase letters ('a'–'z', 'A'–'Z'), and uppercase and lowercase letters are treated as different characters (for example, 'A' and 'a' are different).

Input

The first line contains the length nn of the string SS. (1≤n≤3⋅1051 \le n \le 3 \cdot 10^5)

The second line contains the string SS.

Output

Print the number of substrings of SS that are hyperdromes.

Hint

A substring can be a hyperdrome even if it is not itself a palindrome. For example, 'aAA' is not a palindrome, but it can be rearranged into the palindrome 'AaA', so it is a hyperdrome.

Examples3

  1. Example 1

    Input
    3
    aaa
    
    Expected output
    6
    
  2. Example 2

    Input
    7
    abadaba
    
    Expected output
    12
    
  3. Example 3

    Input
    3
    aAA
    
    Expected output
    5