Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4.

You are given a string s consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero.

A substring of a string is a nonempty sequence of consecutive characters.

For example if string s is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04.

As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.

Input

The only line contains string s (1 ≤ |s| ≤ 3·105). The string s contains only digits from 0 to 9.

Output

Print integer a — the number of substrings of the string s that are divisible by 4.

Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.

Examples
input

Copy
124
output

Copy
4
input

Copy
04
output

Copy
3
input

Copy
5810438174
output

Copy
9

题目问的是子串不是子序列
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <xfunctional>
#define ll long long
#define mod 998244353
using namespace std;
int dir[][] = { {,},{,-},{-,},{,} };
const int maxn = ;
const long long inf = 0x7f7f7f7f7f7f7f7f; int main()
{
string s;
cin>>s;
ll ans = ;
for (int i = ; i < s.size(); i++)
{
if (s[i] % == )
ans++;
if (i >= )
{
if (((s[i - ] - '') * + (s[i] - '')) % == )
ans += i;
}
}
cout<<ans;
return ;
}

New Skateboard的更多相关文章

  1. Codeforces CF#628 Education 8 B. New Skateboard

    B. New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  2. CF 628B New Skateboard --- 水题

    CD 628B 题目大意:给定一个数字(<=3*10^5),判断其能被4整除的连续子串有多少个 解题思路:注意一个整除4的性质: 若bc能被4整除,则a1a2a3a4...anbc也一定能被4整 ...

  3. CodeForces 628B New Skateboard

    New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  4. CodeForces628-B.New Skateboard

    B. New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  5. Educational Codeforces Round 8 B. New Skateboard 暴力

    B. New Skateboard 题目连接: http://www.codeforces.com/contest/628/problem/A Description Max wants to buy ...

  6. Codeforces 628 B.New Skateboard

      B. New Skateboard   time limit per test 1 second memory limit per test 256 megabytes input standar ...

  7. codeforces 628B B. New Skateboard (数论)

    B. New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  8. CodeForces 628B New Skateboard 思维

    B. New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  9. Codefroces B. New Skateboard

    B. New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard in ...

随机推荐

  1. MySQL 8 用户定义函数

    MySQL Server可以通过创建或者加载UDFs(User-Defined Functions)来扩展服务器功能. 通过CREATE FUNCTION语句加载 UDF,比如: CREATE FUN ...

  2. Java 8 函数式编程

    今天打开Oracle Java官网一看,Java已经更新到 13 了 https://www.oracle.com/technetwork/java/javase/jdk-relnotes-index ...

  3. 第一个12PB的项目--2017年

    今年第一个上PB级的项目终于落地.准备了几年,期盼了几年的项目,终于有了市场.内心还是有成就感的. 可是年终沟通,就像是一瓢冷水,从头往下倒.拔凉拔凉的.什么是心寒.什么是希望.想了很多. 我还本想着 ...

  4. 在windows系统下,配置vue项目一键启动文件

    我的项目由客户端.后台管理.数据库和服务器三部分组件,每次启动项目都要一个一个启动,挺麻烦的,现在写一个.bat文件来批处理命令. 这个是我的启动文件内容. 第一行运行的我wampServer服务器, ...

  5. oracke数据库分区新增

    1.发现一些过程执行报错,报错原因是'ora-14400插入的分区关键字未映射到任何分区',原来是2020年库表的时间子分区未扩展: 2.扩展子分区的语句是 ALTER TABLE 表名 MODIFY ...

  6. javaweb利用javabean将数据库中内容遍历在页面输出

    效果如下图 它所实现的就是把数据库中一个表中所有的数据一条一条以表格的形式输出在网页上, 实现方法如下 首先我们要从数据库读取数据,这里要借助javabean来方便我们传递数据 以上面的为例,我要输出 ...

  7. LAMP环境搭建与配置(3)

    PHP配置 查看PHP配置文件的位置 #  /usr/local/php/bin/php   -i  |grep  -i  "loaded configuration file" ...

  8. jvm编译器的优化

    1.对byte.short.char赋值时,若右边范围没有超过左边类型的最大表达范围则会自动隐式的加上(byte).(short).(char)强制转换:若右边范围超过了左边类型的最大表达范围则编译失 ...

  9. 使用vue/cli 创建一个简单的项目

    首先,电脑安装了node.js官方要求8.9 或更高版本 (推荐 8.11.0+) npm install -g @vue/cli # OR yarn global add @vue/cli 全局安装 ...

  10. C# NanUI WinFormium监听页面加载开始\结束

    个人博客 地址:https://www.wenhaofan.com/article/20190501213608 因为NanUI文档中仅介绍了Formium窗口的监听,但是没有WinFormium相关 ...