其他分享
首页 > 其他分享> > Codeforces Round #540 (Div. 3)--1118B - Tanya and Candies(easy TL!)

Codeforces Round #540 (Div. 3)--1118B - Tanya and Candies(easy TL!)

作者:互联网

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:

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

 

#include<iostream>
using namespace std;
int num[200005];
int main(){
    int n;
    cin>>n;
    int evenPre=0,oddPre=0,even=0,odd=0;
    for(int i=0;i<n;i++){
        cin>>num[i];
        if(i&1)
            odd+=num[i];
        else
            even+=num[i];
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(i&1)
            odd-=num[i];
        else
            even-=num[i];            
        if(oddPre+even==evenPre+odd)
            ans++;
        if(i&1)
            oddPre+=num[i];
        else
            evenPre+=num[i];
    }
    cout<<ans<<endl;
    return 0;
}

 

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:

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

标签:days,Candies,Codeforces,candy,day,will,candies,Tanya,eat
来源: https://www.cnblogs.com/albert67/p/10410316.html