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. LeetCode 面试题 02.01. 移除重复节点

    编写代码,移除未排序链表中的重复节点.保留最开始出现的节点. 示例1: 输入:[1, 2, 3, 3, 2, 1] 输出:[1, 2, 3]示例2: 输入:[1, 1, 1, 1, 2] 输出:[1, ...

  2. Burp Suite 实战指南--说明书

       burp使用指南 网址:https://t0data.gitbooks.io/burpsuite/content/

  3. 基于SSM开发大学食堂采购管理系统源码

    开发环境: Windows操作系统开发工具: Eclipse+Jdk+Tomcat+MySQL数据库 次项目分为管理员和普通用户两种角色 运行效果图

  4. jQuery---on注册事件的2种方式

    on注册事件的2种方式 on注册事件的语法 on注册简单事件 // 这个是p自己注册的事件(简单事件) $("p").on("click", function ...

  5. JN_0013:win10快速回桌面

    4.最后一种方法是最为实用的方法.按快捷键[windows键+D键],如下图所示,两键同时按,或者先按住windows键不放再按D键.这种方法在任何时候都是有用的,并且熟练使用后可以达到非常快的速度: ...

  6. Windows玩转Kubernetes系列4-搭建K8S Dashboard

    下载官方yaml文件 最新的配置文件v2.0.0-beta8版本recommended.yaml,UI地址 wget https://raw.githubusercontent.com/kuberne ...

  7. Git的学习和使用

    1.1. Git 了解git的仓库概念 熟悉何为版本控制,了解分布式版本控制(git)和集中式版本控制(svn) 能够熟练使用git的基本指令完成仓库的初始化/添加/提交/日志/回退/分支等操作 gi ...

  8. UVA10085-不知错在何处

    #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #i ...

  9. 深入浅出Mybatis系列八-mapper映射文件配置之select、resultMap

    注:本文转载自南轲梦 注:博主 Chloneda:个人博客 | 博客园 | Github | Gitee | 知乎 上篇<深入浅出Mybatis系列(七)---mapper映射文件配置之inse ...

  10. java学习笔记之IO编程—对象序列化

    对象序列化就是将内存中保存的对象以二进制数据流的形式进行处理,可以实现对象的保存或网络传输. 并不是所有的对象都可以被序列化,如果要序列化的对象,那么对象所在的类一定要实现java.io.Serial ...