PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#PS0000122. Đếm cách chia mảng hợp lệ (Number of Ways to Split Array)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đếm cách chia mảng hợp lệ (Number of Ways to Split Array)

Number of Ways to Split Array

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

An integer array a0,…,an−1a_0,\ldots,a_{n-1} may contain negative values. Choose ii with 0≤i<n−10\le i<n-1 to split it into the nonempty parts with indices 0,…,i0,\ldots,i and i+1,…,n−1i+1,\ldots,n-1. A split is valid when the left sum is at least the right sum. Count valid indices.

Input

The first line contains nn. The second line contains nn integers a0,…,an−1a_0,\ldots,a_{n-1}.

Output

Print the number of valid splits.

Subtasks

  • Subtask 1 (20 points): 2≤n≤1002\le n\le 100; −105≤ai≤105-10^5\le a_i\le10^5 for 0≤i<n0\le i<n.
  • Subtask 2 (30 points): 2≤n≤1052\le n\le 10^5; 0≤ai≤1050\le a_i\le10^5 for 0≤i<n0\le i<n.
  • Subtask 3 (50 points): 2≤n≤1052\le n\le 10^5; −105≤ai≤105-10^5\le a_i\le10^5 for 0≤i<n0\le i<n.

Example 1

Input

4
10 4 -8 7

Output

2

Explanation

The three splits give sum pairs (10,3), (14,-1), (6,7). The first two qualify; the last does not.

Example 2

Input

4
2 3 1 0

Output

2

Explanation

The sum pairs are (2,4), (5,1), (6,0). Only the last two qualify.