Under construction

Still being built. Things may change

Lazy to Win

Interview

Time limit1sMemory limit1024 MB

Summary
Given the point values of n problems, find the fewest consecutive problems, skipping at most one, needed to reach at least half of the total score.
Level

Medium4 of 10

Topics
Sliding window, Prefix sum, Array
Solved
No attempts yet

Problem

Alexey is probably the smartest and at the same time the laziest person in the world. Today he is participating in the Olympiad.

At the Olympiad, participants are given nn problems. A participant receives aia_i points for a correct solution of the ii-th problem. No points are given for an incorrect solution. Participants who receive at least half of the total points are awarded a winner's diploma. For example, if there are three problems worth 11, 33, and 44 points, a participant needs four points to earn the diploma.

Alexey came to the Olympiad to get a winner's diploma. He can correctly solve any problem. He is also very lazy and wants to solve as few problems as possible.

Alexey chooses his problems lazily too. He picks a problem number kk, then solves problems k,k+1,k+2,…k, k+1, k+2, \ldots until he has enough points for a diploma. He allows himself to skip at most one problem, if skipping it lets him solve fewer problems in the end.

Determine the minimum number of problems Alexey needs to solve with this strategy to get the winner's diploma.

Input

On the first line there is one integer nn, the number of problems (1≤n≤1051 \le n \le 10^5).

On the second line there are nn integers a1,a2,…,ana_1, a_2, \ldots, a_n, the cost of each problem in points (1≤ai≤1091 \le a_i \le 10^9).

Output

On the first line, output a single integer: the minimum number of problems Alexey needs to solve with his strategy to get the winner's diploma.

Hint

In the first example, participants need at least four points to get the winner's diploma. Alexey can start solving the third problem, then skip the fourth problem and get four points by solving two tasks.

In the second example, it is enough to solve only the second problem to receive three points.

Examples2

  1. Example 1

    Input
    5
    1 1 2 1 2
    
    Expected output
    2
    
  2. Example 2

    Input
    3
    2 3 1
    
    Expected output
    1