Tanya has nn candies numbered from 11 to nn. The ii-th candy has the weight aiai.

She plans to eat exactly n−1n−1 candies and give the remaining candy to her dad. Tanya eats candies in order of increasing their numbers, exactly one candy per day.

Your task is to find the number of such candies ii (let's call these candies good) that if dad gets the ii-th candy then the sum of weights of candies Tanya eats in even days will be equal to the sum of weights of candies Tanya eats in odd days. Note that at first, she will give the candy, after it she will eat the remaining candies one by one.

For example, n=4n=4 and weights are [1,4,3,3][1,4,3,3]. Consider all possible cases to give a candy to dad:

  • Tanya gives the 11-st candy to dad (a1=1a1=1), the remaining candies are [4,3,3][4,3,3]. She will eat a2=4a2=4 in the first day, a3=3a3=3 in the second day, a4=3a4=3 in the third day. So in odd days she will eat 4+3=74+3=7 and in even days she will eat 33. Since 7≠37≠3 this case shouldn't be counted to the answer (this candy isn't good).
  • Tanya gives the 22-nd candy to dad (a2=4a2=4), the remaining candies are [1,3,3][1,3,3]. She will eat a1=1a1=1 in the first day, a3=3a3=3 in the second day, a4=3a4=3 in the third day. So in odd days she will eat 1+3=41+3=4 and in even days she will eat 33. Since 4≠34≠3 this case shouldn't be counted to the answer (this candy isn't good).
  • Tanya gives the 33-rd candy to dad (a3=3a3=3), the remaining candies are [1,4,3][1,4,3]. She will eat a1=1a1=1 in the first day, a2=4a2=4 in the second day, a4=3a4=3 in the third day. So in odd days she will eat 1+3=41+3=4 and in even days she will eat 44. Since 4=44=4 this case should be counted to the answer (this candy is good).
  • Tanya gives the 44-th candy to dad (a4=3a4=3), the remaining candies are [1,4,3][1,4,3]. She will eat a1=1a1=1 in the first day, a2=4a2=4 in the second day, a3=3a3=3 in the third day. So in odd days she will eat 1+3=41+3=4 and in even days she will eat 44. Since 4=44=4 this case should be counted to the answer (this candy is good).

In total there 22 cases which should counted (these candies are good), so the answer is 22.

Input

The first line of the input contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of candies.

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1041≤ai≤104), where aiai is the weight of the ii-th candy.

Output

Print one integer — the number of such candies ii (good candies) that if dad gets the ii-th candy then the sum of weights of candies Tanya eats in even days will be equal to the sum of weights of candies Tanya eats in odd days.

Examples
input

Copy
  1. 7
  2. 5 5 4 5 5 5 6
output

Copy
  1. 2
input

Copy
  1. 8
  2. 4 8 8 7 8 4 4 5
output

Copy
  1. 2
input

Copy
  1. 9
  2. 2 3 4 2 2 3 2 2 4
output

Copy
  1. 3
  1. #include<iostream>
  2. using namespace std;
  3. int num[];
  4. int main(){
  5. int n;
  6. cin>>n;
  7. int evenPre=,oddPre=,even=,odd=;
  8. for(int i=;i<n;i++){
  9. cin>>num[i];
  10. if(i&)
  11. odd+=num[i];
  12. else
  13. even+=num[i];
  14. }
  15. int ans=;
  16. for(int i=;i<n;i++){
  17. if(i&)
  18. odd-=num[i];
  19. else
  20. even-=num[i];
  21. if(oddPre+even==evenPre+odd)
  22. ans++;
  23. if(i&)
  24. oddPre+=num[i];
  25. else
  26. evenPre+=num[i];
  27. }
  28. cout<<ans<<endl;
  29. return ;
  30. }

Ta

nn;njklya has nn candies numbered from 11 to nn. The ii-th candy has the weight aiai.

She plans to eat exactly n−1n−1 candies and give the remaining candy to her dad. Tanya eats candies in order of increasing their numbers, exactly one candy per day.

Your task is to find the number of such candies ii (let's call these candies good) that if dad gets the ii-th candy then the sum of weights of candies Tanya eats in even days will be equal to the sum of weights of candies Tanya eats in odd days. Note that at first, she will give the candy, after it she will eat the remaining candies one by one.

For example, n=4n=4 and weights are [1,4,3,3][1,4,3,3]. Consider all possible cases to give a candy to dad:

  • Tanya gives the 11-st candy to dad (a1=1a1=1), the remaining candies are [4,3,3][4,3,3]. She will eat a2=4a2=4 in the first day, a3=3a3=3 in the second day, a4=3a4=3 in the third day. So in odd days she will eat 4+3=74+3=7 and in even days she will eat 33. Since 7≠37≠3 this case shouldn't be counted to the answer (this candy isn't good).
  • Tanya gives the 22-nd candy to dad (a2=4a2=4), the remaining candies are [1,3,3][1,3,3]. She will eat a1=1a1=1 in the first day, a3=3a3=3 in the second day, a4=3a4=3 in the third day. So in odd days she will eat 1+3=41+3=4 and in even days she will eat 33. Since 4≠34≠3 this case shouldn't be counted to the answer (this candy isn't good).
  • Tanya gives the 33-rd candy to dad (a3=3a3=3), the remaining candies are [1,4,3][1,4,3]. She will eat a1=1a1=1 in the first day, a2=4a2=4 in the second day, a4=3a4=3 in the third day. So in odd days she will eat 1+3=41+3=4 and in even days she will eat 44. Since 4=44=4 this case should be counted to the answer (this candy is good).
  • Tanya gives the 44-th candy to dad (a4=3a4=3), the remaining candies are [1,4,3][1,4,3]. She will eat a1=1a1=1 in the first day, a2=4a2=4 in the second day, a3=3a3=3 in the third day. So in odd days she will eat 1+3=41+3=4 and in even days she will eat 44. Since 4=44=4 this case should be counted to the answer (this candy is good).

In total there 22 cases which should counted (these candies are good), so the answer is 22.

Input

The first line of the input contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of candies.

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1041≤ai≤104), where aiai is the weight of the ii-th candy.

Output

Print one integer — the number of such candies ii (good candies) that if dad gets the ii-th candy then the sum of weights of candies Tanya eats in even days will be equal to the sum of weights of candies Tanya eats in odd days.

Examples
input

Copy
  1. 7
  2. 5 5 4 5 5 5 6
output

Copy
  1. 2
input

Copy
  1. 8
  2. 4 8 8 7 8 4 4 5
output

Copy
  1. 2
input

Copy
  1. 9
  2. 2 3 4 2 2 3 2 2 4
output

Copy
  1. 3

Codeforces Round #540 (Div. 3)--1118B - Tanya and Candies(easy TL!)的更多相关文章

  1. Codeforces Round #540 (Div. 3) B. Tanya and Candies (后缀和)

    题意:有\(n\)个数,你可以任意去除某个位置的元素然后得到一个新数组,使得新数组奇数位和偶数的元素相等,现在问你有多少种情况合法. 题解:先求个后缀和,然后遍历,记录奇数和偶数位置的前缀和,删去\( ...

  2. Codeforces Round #540 (Div. 3)--1118D1 - Coffee and Coursework (Easy version)

    https://codeforces.com/contest/1118/problem/D1 能做完的天数最大不超过n,因为假如每天一杯咖啡,每杯咖啡容量大于1 首先对容量进行从大到小的排序, sor ...

  3. Codeforces Round #540 (Div. 3) D1. Coffee and Coursework (Easy version) 【贪心】

    任意门:http://codeforces.com/contest/1118/problem/D1 D1. Coffee and Coursework (Easy version) time limi ...

  4. Codeforces Round #540 (Div. 3) 部分题解

    Codeforces Round #540 (Div. 3) 题目链接:https://codeforces.com/contest/1118 题目太多啦,解释题意都花很多时间...还有事情要做,就选 ...

  5. Codeforces Round #540 (Div. 3) A,B,C,D2,E,F1

    A. Water Buying 链接:http://codeforces.com/contest/1118/problem/A 实现代码: #include<bits/stdc++.h> ...

  6. Codeforces Round #540 (Div. 3) F1. Tree Cutting (Easy Version) 【DFS】

    任意门:http://codeforces.com/contest/1118/problem/F1 F1. Tree Cutting (Easy Version) time limit per tes ...

  7. Codeforces Round #288 (Div. 2)D. Tanya and Password 欧拉通路

    D. Tanya and Password Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/508 ...

  8. Codeforces Round #346 (Div. 2) C Tanya and Toys

    C. Tanya and Toys 题目链接http://codeforces.com/contest/659/problem/C Description In Berland recently a ...

  9. Codeforces Round #346 (Div. 2) C. Tanya and Toys 贪心

    C. Tanya and Toys 题目连接: http://www.codeforces.com/contest/659/problem/C Description In Berland recen ...

随机推荐

  1. sharpsvn 继续,解决文件locked 问题,

    方法中少个方法就会出现一些问题. 比如进行了断线测试,结果再操作时就出现了文件被锁的情况,最终查了官网的论坛,才得以解决 How to unlock if the working copy is lo ...

  2. centos7.2下nginx安装教程

    1.准备工作 1)关闭iptables 关闭操作 iptables -t nat -F 查看操作 iptables -t nat -L 2)关闭selinux 查看操作 setenforce 关闭操作 ...

  3. gdal gdal2tiles.py 的使用

    I’m here showing how you can use GDAL2Tiles to generate map tiles of Tom Patterson’s Natural Earth I ...

  4. Python 环境安装教程(Windows 10)

    Python编程语言非常强大,非常容易上手,版本更新也不慢,在win10 x64中兼容性也很好,直接安装不需另外配置,虽然Python2和3有点异同.学习的话选择最新的 python 3.7.1版. ...

  5. AWVS基本用法

    https://www.bugbank.cn/q/article/5983de41cbb936102d397781.html

  6. jmeter多用户并发

    1.需要参数化 2.单用户需要在请求头里面传入cookie

  7. vue回到顶部组件

    html <template> <a href="javascript:;" class="toTop" @click="backT ...

  8. 数据库之mysql练习

    建表 部门表 #DROP IF EXISTS TABLE DEPT; CREATE TABLE DEPT( DEPTNO int PRIMARY KEY,##部门编号 DNAME VARCHAR(14 ...

  9. MVVM Light 笔记 - snippet

    RelayCommand有8个,看似很多,其实就是几个变化的组合: 1.是否Generic 2. 执行是使用lambda表达式还是method 3.是否有CanExecute 这些都在源代码Snipp ...

  10. HTML and CSS学习概述-续

    1,   CSS是层叠样式表(Cascading Style Sheets)的缩写,它用于定义HTML元素的显示形式,是一种格式化网页内容的技术.CSS现在已经被大多数浏览器所支持,成为网页设计者必须 ...