A. Even Substrings

A. Even Substrings

time limit per test
0.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a string s=s1s2sns=s1s2…sn of length nn, which only contains digits 11, 22, ..., 99.

A substring s[lr]s[l…r] of ss is a string slsl+1sl+2srslsl+1sl+2…sr. A substring s[lr]s[l…r] of ss is called even if the number represented by it is even.

Find the number of even substrings of ss. Note, that even if some substrings are equal as strings, but have different ll and rr, they are counted as different substrings.

Input

The first line contains an integer nn (1n650001≤n≤65000) — the length of the string ss.

The second line contains a string ss of length nn. The string ss consists only of digits 11, 22, ..., 99.

Output

Print the number of even substrings of ss.

Examples

input

4
1234

output

6

input

4
2244

output

10

Note

In the first example, the [l,r][l,r] pairs corresponding to even substrings are:

  • s[12]s[1…2]
  • s[22]s[2…2]
  • s[14]s[1…4]
  • s[24]s[2…4]
  • s[34]s[3…4]
  • s[44]s[4…4]

In the second example, all 1010 substrings of ss are even substrings. Note, that while substrings s[11]s[1…1] and s[22]s[2…2] both define the substring "2", they are still counted as different substrings.

题意:任取主串中的一个区间,判断这个是减是不是偶数,然后是偶数的话,就数量加1,找出有多少个这样的偶数区间。比如:第一个样例1234,其中12,2,1234,234,34,4为偶数,所以答案是6。其思路是从第一个字符遍历到最后一个字符,如果遇到偶数,就将这个数的位数加入sum中,依次遍历过就行。

 

#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int sum=0;
    for(int i=0;i<n;i++)
        if((s[i]-'0')%2==0)    //判断当前数字是不是偶数
            sum+=i+1;            //加上当前数字的位数
    cout<<sum<<endl;
    return 0;
}

 

 

posted @ 2019-03-31 19:07  不会fly的pig  阅读(120)  评论(0编辑  收藏  举报