QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 32 MB Total points: 100

#570. Antisymmetry

Statistics

Byteasar studies certain strings of zeroes and ones. Let $x$ be such a string. By $x^R$ we will denote the reversed (i.e., "read backwards") string $x$, and by $\bar {x}$ we will denote the string obtained from x by changing all the zeroes to ones and ones to zeroes.

Byteasar is interested in antisymmetry, while all things symmetric bore him. Antisymmetry however is not a mere lack of symmetry. We will say that a (nonempty) string $x$ is antisymmetric if, for every position $i$ in $x$, the $i$-th last character is different than the $i$-th (first) character. In particular, a string $x$ consisting of zeroes and ones is antisymmetric if and only if $x = {\bar {x}}^R$. For example, the strings 00001111 and 010101 are antisymmetric, while 1001 is not.

In a given string consisting of zeroes and ones we would like to determine the number of contiguous nonempty antisymmetric fragments. Different fragments corresponding to the same substrings should be counted multiple times.

Input

The first line of the standard input contains an integer $n$ ($1 ≤ n ≤ 500\,000$) that denotes the length of the string. The second line gives a string of 0 and/or 1 of length $n$. There are no spaces in the string.

Output

The first and only line of the standard output should contain a single integer, namely the number of contiguous (non empty) fragments of the given string that are antisymmetric.

Example

Input

8
11001011

Output

7

Hints

Antisymmetric fragments are: 01 (occurs twice), 10 (also twice), 0101, 1100, and 001011.

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.