You are given a permutation p of n integers 1, 2, ..., n (a permutation is an array where each element from 1 to n occurs exactly once).

Let's call some subsegment p[l, r] of this permutation special if p_l + p_r = max _{i = l}^{r} p_i. Please calculate the number of special subsegments.

Input

The first line contains one integer n (3 ≤ n ≤ 2 ⋅ 10^5).

The second line contains n integers p_1, p_2, ..., p_n (1 ≤ p_i ≤ n). All these integers are pairwise distinct.

Output

Print the number of special subsegments of the given permutation.

Examples

Input


5
3 4 1 5 2


Output


2


Input


3
1 3 2


Output


1

Note

Special subsegments in the first example are [1, 5] and [1, 3].

The only special subsegment in the second example is [1, 3].
import sys,math
from fractions import gcd
from bisect import bisect_left, bisect
from collections import defaultdict
from io import BytesIO
sys.stdin = BytesIO(sys.stdin.read())
input = lambda: sys.stdin.readline().rstrip('\r\n')
n = int(input())
#n,m,k = [int(_) for _ in input().split()]
p = [int(_) for _ in input().split()]

lf = [0] * n
rg = [0] * n
ans = 0
q = [0] * (n+1)

def update(l, r, l2, r2, sm):
    global ans
    for i in range(l,r+1):
        o = sm - p[i]
        if o >= 1 and o <= n and l2 <= q[o] and q[o] <= r2:
            ans += 1

for i in range(n):
	q[p[i]] = i

s = [[n + 1, -1],]
for i in range(n):
	while s[-1][0] < p[i]:
		s.pop()
	lf[i] = s[-1][1]
	s.append([p[i], i])

s = [[n + 1, n],]
for i in range(n-1,-1,-1):
	while s[-1][0] < p[i]:
		s.pop()
	rg[i] = s[-1][1]
	s.append([p[i], i])

for i in range(n):
	lenl = i - lf[i] - 1
	lenr = rg[i] - i - 1
	if lenl == 0 or lenr == 0:
		continue
	
	if lenl < lenr:
		update(lf[i] + 1, i - 1, i + 1, rg[i] - 1, p[i])
	else:
		update(i + 1, rg[i] - 1, lf[i] + 1, i - 1, p[i])
print(ans)