You are given a permutation of the numbers 1,2,…,n for some n. Let the elements of the permutation, in order, form a sequence a1,a2,…,an. Your task is to count how many arithmetic subsequences of a have length exactly 3. More precisely, count the triples (i,j,k) such that i<j<k and aj−ai=ak−aj.
The first line contains one integer n (1≤n≤200000). The second line contains n integers a1,a2,…,an describing the permutation.
Print the number of length-3 arithmetic subsequences of the given permutation. You may assume the answer does not exceed 1000000.