Number of Ways

题意翻译

题目描述 你得到了一个数组a,包含n个数字a[1],a[2],a[3],...,a[n]. 现在你要找到把它分成三份的方法,使得每一份之内所有数的和相等。 简单地说,你需要找到一个数对(i,j),使得![](https://cdn.luogu.org/upload/vjudge_pic/CF466C/6d268bd0e5773093a8b59275245964aa2b1c55f9.png) 输入数据 第一行是一个整数n(1<=n<=500000),表示数列中有多少个数。 接下来一行有n个数,分别表示a[1],a[2],a[3],...,a[n]。 输出数据 一行一个整数,表示满足条件的(i,j)的总数。 由 @Peter_Z 提供翻译

题目描述

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 ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF466C/6d268bd0e5773093a8b59275245964aa2b1c55f9.png).

输入输出格式

输入格式


The first line contains integer $ n $ $ (1<=n<=5·10^{5}) $ , showing how many numbers are in the array. The second line contains $ n $ integers $ a[1] $ , $ a[2] $ , ..., $ a[n] $ $ (|a[i]|<=10^{9}) $ — the elements of array $ a $ .

输出格式


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

输出样例 #1

2

输入样例 #2

4
0 1 -1 0

输出样例 #2

1

输入样例 #3

2
4 1

输出样例 #3

0