Problem F. Fine segments

Author:Иван Кобец   Time limit:1 sec
Input file:Standard input   Memory limit:512 Mb
Output file:Standard output  

Statement

The young programmer Ilya was presented with a sequence of numbers ai of length n for his birthday. Ilya decided to select fine segments from this sequence. A fine segment is a sequence of successive elements of ai containing some element equal to the sum of its first and last elements. For example, the sequence [1, 2, 5, 4] is fine because the sum of the leftmost and rightmost elements is 5, and the number 5 is in this sequence; the sequence [1, 2, 3, 4] is not fine because the sum of the leftmost and rightmost elements is 5, and the number 5 is not in this sequence. Your program must count the number of fine segments in a given sequence.

Input format

The first line contains an integer n — the length of the sequence. The second line contains n integers ai — the elements of the sequence. All elements of the sequence are different.

Output format

Output a single integer — number of fine segments in the sequence.

Constraints

1 ≤ n ≤ 103

1 ≤ ai ≤ 105

Notes on samples

First sample has one fine segment: [3, 7, 5, 4].

Second sample has two fine segments: [1, 5, 4] и [1, 5, 4, 7, 6].

Sample tests

No. Standard input Standard output
1
5
3 7 5 4 8
1
2
5
1 5 4 7 6
2

0.125s 0.028s 13