Arithmetic Subsequences

No attempts yetTime limit1sMemory limit128 MB

Problem

You are given a permutation of the numbers 1,2,,n1, 2, \ldots, n for some nn. Let the elements of the permutation, in order, form a sequence a1,a2,,ana_1, a_2, \ldots, a_n. Your task is to count how many arithmetic subsequences of aa have length exactly 33. More precisely, count the triples (i,j,k)(i, j, k) such that i<j<ki < j < k and ajai=akaja_j - a_i = a_k - a_j.

Input

The first line contains one integer nn (1n200000)(1 \le n \le 200\,000). The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n describing the permutation.

Output

Print the number of length-33 arithmetic subsequences of the given permutation. You may assume the answer does not exceed 10000001\,000\,000.