CF1118B.Tanya and Candies

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

She plans to eat exactly n1n-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=1a_1=1 ), the remaining candies are [4,3,3][4, 3, 3] . She will eat a2=4a_2=4 in the first day, a3=3a_3=3 in the second day, a4=3a_4=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 737 \ne 3 this case shouldn't be counted to the answer (this candy isn't good).
  • Tanya gives the 22 -nd candy to dad ( a2=4a_2=4 ), the remaining candies are [1,3,3][1, 3, 3] . She will eat a1=1a_1=1 in the first day, a3=3a_3=3 in the second day, a4=3a_4=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 434 \ne 3 this case shouldn't be counted to the answer (this candy isn't good).
  • Tanya gives the 33 -rd candy to dad ( a3=3a_3=3 ), the remaining candies are [1,4,3][1, 4, 3] . She will eat a1=1a_1=1 in the first day, a2=4a_2=4 in the second day, a4=3a_4=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=3a_4=3 ), the remaining candies are [1,4,3][1, 4, 3] . She will eat a1=1a_1=1 in the first day, a2=4a_2=4 in the second day, a3=3a_3=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 .

输入格式

The first line of the input contains one integer nn ( 1n21051 \le n \le 2 \cdot 10^5 ) — the number of candies.

The second line of the input contains nn integers a1,a2,,ana_1, a_2, \dots, a_n ( 1ai1041 \le a_i \le 10^4 ), where aia_i is the weight of the ii -th candy.

输出格式

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.

输入输出样例

  • 输入#1

    7
    5 5 4 5 5 5 6
    

    输出#1

    2
    
  • 输入#2

    8
    4 8 8 7 8 4 4 5
    

    输出#2

    2
    
  • 输入#3

    9
    2 3 4 2 2 3 2 2 4
    

    输出#3

    3
    

说明/提示

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] .

首页