#P10366. [PA 2024] Bardzo Ulubiony Ciąg

[PA 2024] Bardzo Ulubiony Ciąg

Background

PA 2024 5C1

Problem Description

This problem is translated from Round 5 of PA 2024, Bardzo Ulubiony Ciąg. Thanks to Macaronlin for providing the translation.

Given an integer array aa of length nn, all subarray sums of aa form an array bb of length n(n+1)2\frac{n(n+1)}{2}. The subarray sums are ordered by increasing starting index of the subarray; if two subarrays have the same starting index, they are ordered by increasing ending index.

For the newly formed array bb, compute the number of triples (i,j,k)(i,j,k) such that bi+bj+bk=0 (i<j<k)b_i+b_j+b_k=0\ (i<j<k).

Input Format

The first line contains an integer n (1n500)n\ (1\le n\le 500), the length of array aa.

The second line contains nn integers a1,a2,,an (ai20000)a_1,a_2,\ldots,a_n\ (|a_i|\le 20\,000), representing array aa.

Output Format

Output one integer: the number of triples (i,j,k)(i,j,k) in array bb satisfying bi+bj+bk=0 (i<j<k)b_i+b_j+b_k=0\ (i<j<k).

3
7 -4 -2

1

10
0 0 0 0 0 0 0 0 0 0

26235

Hint

Sample Explanation 1

Array bb is [7,3,1,4,6,2][7,3,1,-4,-6,-2]. Only the three distinct elements 3,1,43,1,-4 satisfy the condition, so the answer is 11.

Sample Explanation 2

Array bb consists of 5555 zeros. Any choice of three indices i<j<ki<j<k has sum 00, so the answer is 2623526235.

Translated by ChatGPT 5