B. Tanya and Candies (简单模拟)

题目链接:http://codeforces.com/contest/1118/problem/B

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

7
5 5 4 5 5 5 6

output

Copy

2

input

Copy

8
4 8 8 7 8 4 4 5

output

Copy

2

input

Copy

9
2 3 4 2 2 3 2 2 4

output

Copy

3

Note

In the first example indices of good candies are [1,2][1,2].

In the second example indices of good candies are [2,3][2,3].

In the third example indices of good candies are [4,5,9][4,5,9].

思考:偶数和奇数的性质,要掌握牢固。我们每去掉数组中的一个值,其后的奇偶性便发生变化。(打比赛的时候想不到怎么去实现,还是菜啊!)

#include <iostream>
using namespace std;
int n,a[200001],st[2],dr[2],r;
int main()
{
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
        dr[i%2]+=a[i];  //奇数下标和放一个,偶数下标和放一个
    }
    for(int i=1; i<=n; i++)  //我们每去掉1个值,其后的值的奇偶性便发生变化
    {
        st[(i-1)%2]+=a[i-1];  //也是向前挪1位,放奇数偶数和
        dr[i%2]-=a[i];      //减去当前位
        if(st[0]+dr[1]==st[1]+dr[0])  //交叉相加
            r++;
    }
    cout<<r;
    return 0;
}

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值