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=s1s2…sns=s1s2…sn of length nn, which only contains digits 11, 22, ..., 99.

A substring s[l…r]s[l…r] of ss is a string slsl+1sl+2…srslsl+1sl+2…sr. A substring s[l…r]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 (1≤n≤650001≤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[1…2]s[1…2]
  • s[2…2]s[2…2]
  • s[1…4]s[1…4]
  • s[2…4]s[2…4]
  • s[3…4]s[3…4]
  • s[4…4]s[4…4]

In the second example, all 1010 substrings of ss are even substrings. Note, that while substrings s[1…1]s[1…1] and s[2…2]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=;
for(int i=;i<n;i++)
if((s[i]-'')%==) //判断当前数字是不是偶数
sum+=i+; //加上当前数字的位数
cout<<sum<<endl;
return ;
}

A. Even Substrings的更多相关文章

  1. [LeetCode] Unique Substrings in Wraparound String 封装字符串中的独特子字符串

    Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...

  2. Leetcode: Unique Substrings in Wraparound String

    Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...

  3. CSU-1632 Repeated Substrings (后缀数组)

    Description String analysis often arises in applications from biology and chemistry, such as the stu ...

  4. CF451D Count Good Substrings (DP)

    Codeforces Round #258 (Div. 2) Count Good Substrings D. Count Good Substrings time limit per test 2 ...

  5. LA4671 K-neighbor substrings(FFT + 字符串Hash)

    题目 Source http://acm.hust.edu.cn/vjudge/problem/19225 Description The Hamming distance between two s ...

  6. 后缀数组---New Distinct Substrings

    Description Given a string, we need to find the total number of its distinct substrings. Input T- nu ...

  7. Codeforces Round #258 D Count Good Substrings --计数

    题意:由a和b构成的字符串,如果压缩后变成回文串就是Good字符串.问一个字符串有几个长度为偶数和奇数的Good字串. 分析:可知,因为只有a,b两个字母,所以压缩后肯定为..ababab..这种形式 ...

  8. SPOJ 694. Distinct Substrings (后缀数组不相同的子串的个数)转

    694. Distinct Substrings Problem code: DISUBSTR   Given a string, we need to find the total number o ...

  9. Codeforces Round #306 (Div. 2) A. Two Substrings 水题

    A. Two Substrings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/pro ...

  10. CF Two Substrings

    Two Substrings time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

随机推荐

  1. P1828香甜的黄油

    这是一道关于最短路的绿题. 题目给出一些农场,每个农场有奶牛,农场与农场之间存在边,要使所有奶牛到达其中一个农场的总距离最短,输出他们到达这个农场的距离.首先我想到了最小生成树,但我发现其实并不是,因 ...

  2. 房地产大佬潘石屹推荐学Python编程,这本从0到1就够了

    潘石屹推荐学Python编程,很多人都不相信,他的微博真真切切. 连房地产都开始学Python了,因为要听懂机器,让机器为我所用. 再不学习Python真的晚了!!!! 如何学? 怎么学? 还是推荐高 ...

  3. Linux-1.2关机重启reboot,shutdown

    关机重启:reboot,shutdown reboot 重启操作系统 shutdown -r now 重启,shutdown会给其他用户提示

  4. LinkedList实现基于LRU算法的缓存

    LinkedList实现基于LRU算法的缓存 2015年08月07日 18:18:45 秦江波 阅读数 2068 文章标签: java算法linkedlist缓存LRU更多 分类专栏: Java   ...

  5. SSM和Spring Boot常用配置比较

    一.Dao层相关 1.Mysql相关: 1.1配置DataSource连接池: (1)SSM配置: <!-- 加密后配置自己写的解析文件 --> <bean class=" ...

  6. nginx+php设置大文件请求上传(502及504问题处理)

    502问题 php-fpm 修改项: request_terminate_timeout 位置: eg: /etc/php5/fpm2/pool.d/www.conf ; The timeout fo ...

  7. abap 优化之ST05

    DATA: gt_mara TYPE TABLE OF mara. SELECT * INTO TABLE gt_mara FROM mara WHERE MATKL = 'L000001' %_hi ...

  8. 转载:JavaWeb 文件上传下载

    转自:https://www.cnblogs.com/aaron911/p/7797877.html 1. 文件上传下载概述 1.1. 什么是文件上传下载 所谓文件上传下载就是将本地文件上传到服务器端 ...

  9. zencart产品属性dropmenu select只有一个选择项时自动变成radio单选的解决办法

    includes\modules\classic\attributes.php 在大约786行代码 case ($products_options->RecordCount() == 1): 的 ...

  10. 〇——HTML的本质以及在Web程序中的作用

    对于所有的Web应用,其实本质上都是一个socket服务端,用户的浏览器就是一个socket的client,我们看看下面这段代码 import socket def handle_request(cl ...