Lunch Line


One day, Lucas is lining up to buy lunch at campus centre when he notices his friend Parsa right behind him. Lucas realizes that instead of waiting and ordering separately, it would be much faster for one of them to place a combined order for both, saving time on the transaction.

Other students in the line notice their strategy, and the idea quickly catches on. The following week, Lucas returns to the food court and sees a new trend: people are merging their orders! Specifically, a person can take on the order of the person immediately in front of or behind them, provided their own current combined order size is greater than or equal to the order size of that adjacent person. Once merged, the person whose order was taken leaves the line.

Watching this unfold, Lucas wonders: given the number of items each person in the line initially intends to order, how many different people could theoretically end up placing the single, final order for the entire line?

More formally, given an array AA of nn positive integers, where AiA_i is the number of items the ithi^{th} person in the line initially is ordering, how many distinct people can end up being the final person ordering, if a person who is responsible for ordering items {Ab,,Ac}\{A_b, \ldots, A_c\}, 1bcn1 \le b \le c \le n can merge their order with:

  • the person responsible for ordering items {Aa,,Ab1}\{A_a, \ldots, A_{b-1}\}, 1a<b1 \le a < b if i=ab1Aii=bcAi\sum_{i=a}^{b-1} A_i \le \sum_{i=b}^{c} A_i
  • the person responsible for ordering items {Ac+1,,Ad}\{A_{c+1}, \ldots, A_{d}\}, c<dnc < d \le n if i=bcAii=c+1dAi\sum_{i=b}^{c} A_i \ge \sum_{i=c+1}^{d} A_i

Input

The first line contains an integer nn, the number of people initially in the line.

The second line contains nn integers: a1,a2,,ana_1, a_2, \ldots, a_n.

Output

The number of different people who can end up ordering for the whole line.

Constraints

  • 1n1061 \le n \le 10^6
  • 1ai1061 \le a_i \le 10^6

Example 1

Input 1
5
1 1 2 1 6
Output 1
1
Explanation

Only person 55 can end up ordering for the whole line.

Example 2

Input 2
5
3 1 3 3 2
Output 2
3
Explanation

People 1,3,41, 3, 4 can end up ordering for the whole line.

Example 3

Input 3
10
1 5 5 2 4 1 4 1 2 3
Output 3
6
Explanation

People 2,3,5,7,9,102, 3, 5, 7, 9, 10 can end up ordering for the whole line.

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.