CF466C.Number of Ways

传统题 时间 2000 ms 内存 256 MiB 10 尝试 1 已通过 1 标签

Number of Ways

CF466C · Number of Ways

  • 难度:1700
  • 标签:binary search、brute force、data structures、dp、two pointers
  • 链接:https://codeforces.com/problemset/problem/466/C
  • 时间限制:2 seconds 内存限制:256 megabytes
  • 出现位置:Day22-阶段模拟4-S T1-T3综合卷

英文原题面

Statement

You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same. More formally, you need to find the number of such pairs of indices i, j (2 ≤ i ≤ j ≤ n - 1), that .

Input

The first line contains integer n (1 ≤ n ≤ 5·105), showing how many numbers are in the array. The second line contains n integers a[1], a[2], ..., a[n] (|a[i]| ≤  109) — the elements of array a.

Output

Print a single integer — the number of ways to split the array into three parts with the same sum.

样例

样例 1

输入:

5
1 2 3 0 3

输出:

2

样例 2

输入:

4
0 1 -1 0

输出:

1

样例 3

输入:

2
4 1

输出:

0

在线编程 IDE

建议全屏模式获得最佳体验