Problems > Zero Triplets

Zero Triplets

Difficulty: 1600 3000 ms 128 MB

sorting two-pointers

Count the index triples i < j < k with ai + aj + ak = 0.

Input: the first line has N; the second line has N integers.

Output: the number of zero-sum triples (by INDEX, so duplicates matter).

Constraints:

  • 3 ≤ N ≤ 500
  • |ai| ≤ 30

Sample Tests

Input 1
5
-1 0 1 2 -2
Output 1
2
Input 2
3
0 0 0
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.