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.

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.