Teams with Sum Zero

Time limit4sMemory limit128 MB

Problem

Elly must train students for a programming contest where every team must have exactly three members. Among these students, stronger coding ability tends to come with weaker teamwork, and better teamwork tends to come with weaker coding ability. The contest requires a good balance of both.

Elly knows the coding skill value of every student she can train. Each value A_i is an integer between -10000 and 10000. To form a balanced team, she wants the sum of the three selected students' coding skill values to be exactly 0.

Given the coding skill values of N students, count how many different three-person teams have total skill 0. Students with the same skill value are still distinct people, so teams are counted by the selected student indices.

Input

Input is given from standard input.

The first line contains the number of students N. The second line contains N integers A_i, the coding skill values of the students.

Output

Print one integer: the number of teams Elly can choose.

Constraints

  • 1 <= N <= 10000
  • -10000 <= A_i <= 10000

Hint

For the visible test case, the valid groups are (2, -5, 3), (2, 2, -4), (2, 2, -4), (-5, 2, 3), (3, -4, 1), and (3, -4, 1).

The two -4 values belong to different students, so (2, 2, -4) and (3, -4, 1) are each counted twice.