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. Linux运维必备工具

    1. 查看进程占用带宽情况 - Nethogs Nethogs 是一个终端下的网络流量监控工具可以直观的显示每个进程占用的带宽. 前提条件:安装c++环境 yum install -y gcc-c++ ...

  2. MySQL 中 savepoint 的使用

     介绍 savepoint 结点名; # 设置保存点,并和rollback结合使用,实现回滚到指定保存点 rollback to 结点名; # 回滚到指定点 样例演示 USE human; ; sta ...

  3. MySQL中出现的小问题

    ./scripts/mysql_install_db: line 249: /app/mysql/bin/my_print_defaults: cannot execute binary fileNe ...

  4. spark教程(11)-sparkSQL 数据抽象

    数据抽象 sparkSQL 的数据抽象是 DataFrame,df 相当于表格,它的每一行是一条信息,形成了一个 Row Row 它是 sparkSQL 的一个抽象,用于表示一行数据,从表现形式上看, ...

  5. CSP/NOIP 2019 游记

    Day0 打牌 Day1 \(T1\) 没开\(ull\), 不知道有几分 \(T2\) \(N^2\)暴力+链, 没搞出树上做法, \(70\)分 \(T3\) 标准\(10\)分( 感觉今年省一稳 ...

  6. Docker简易使用手册

    1. Docker介绍 Docker中文社区文档 Docker 是一个开源的软件部署解决方案. Docker 包括三个基本概念: 镜像(Image) Docker的镜像概念类似于虚拟机里的镜像,是一个 ...

  7. hiper、sitespeed性能工具

    https://github.com/pod4g/hiper   hiper:   A statistical analysis tool for performance testing https: ...

  8. 第十八篇 JS传参数

    JS传参数   参数,这是个什么东西呢?简单的说吧,我们去玩别人的网站,一般来个登录,有用户名和密码,当我们输入正确之后,那么这用户名和密码里面的值,就是参数的值,它将这个值传给“参数”,然后提交到后 ...

  9. 关于python3.8的一些新特性的解析与代码演示

    python3.8测试版出来了,我们来介绍一些变动,代码演示一下,当然底层相关的细节变动就不介绍了 只允许传位置参数 还记得如果我们想让某些参数只能以关键字参数的方式传递该怎么做吗? def foo1 ...

  10. MMU功能解析、深入剖析、配置与使用

    MMU = memory management unit 1.把虚拟地址转化成物理地址,防止地址冲突 2.访问权限管理 MMU把一个虚拟地址的20位到31位作为取出来,建立 一张表,叫做transla ...