0197. A + B = C

Input file name: abc.in
Output file name: abc.out
Time limit: 500 ms
Memory limit: 32 megabytes

You are given an array A[1…N] of different integer numbers (all of its elements do not exceed 15⋅ 106 by their absolute value). Your task is to calculate the number of different triples (p,q,r), such that A[p] + A[q] = A[r] and p, q and r are different. Note that triples (1,2,3) and (2,1,3) are considered to be different.

Input file

The first line of input file contains positive integer N (0<N<3501). The next line consists of the numbers A[1], A[2], …, A[N] separated by spaces.

Output file

Write the only number – answer to this problem.

Examples:

abc.inabc.out
4 3 2 4 14


Source: Petrozavodsk Summer 2003. Saratov SU Contest, Wednesday, August 27

Discuss       Submit a solution



Printable version