Codeforces Round 266 (Div. 2)
C
Number of Ways
Codeforces
1700
原题
← BD →
翻译中…

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 image.

翻译中…

Input

翻译中…

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*$.

翻译中…

Output

翻译中…

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

翻译中…

样例

Input #1
5
1 2 3 0 3
Output #1
2
InputCopy OutputCopy
Input #2
4
0 1 -1 0
Output #2
1
InputCopy OutputCopy
Input #3
2
4 1
Output #3
0
InputCopy OutputCopy
题目信息
题号
466C
时间限制
2 s
内存限制
256 MB
标签
二分
暴力
数据结构
动态规划
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。