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].
#include <bits/stdc++.h>
using namespace std;
int n, m, a[200005], pos[200005], mx[200005][19], lg[200005];
long long ans;
int query(int x, int y) {
  int t = lg[y - x + 1];
  return max(mx[x][t], mx[y - (1 << t) + 1][t]);
}
void solve(long long l, long long r) {
  if (r - l < 2) return;
  long long t = query(l, r), p = pos[t], i;
  if (p - l < r - p) {
    for (i = l; i < p; i++) {
      if (pos[t - a[i]] > p && pos[t - a[i]] <= r) ans++;
    }
  } else {
    for (i = r; i > p; i--) {
      if (pos[t - a[i]] < p && pos[t - a[i]] >= l) ans++;
    }
  }
  solve(l, p - 1);
  solve(p + 1, r);
}
int main() {
  scanf("%d", &n);
  for (register int(i) = (1); (i) <= (n); (i)++) {
    scanf("%d", &a[i]);
    pos[a[i]] = i;
    mx[i][0] = a[i];
  }
  for (int i = 2; i <= n; i++) {
    lg[i] = lg[i / 2] + 1;
  }
  for (register int(j) = (1); (j) <= (18); (j)++)
    for (register int(i) = (1); (i) <= (n - (1 << j) + 1); (i)++) {
      mx[i][j] = max(mx[i][j - 1], mx[i + (1 << (j - 1))][j - 1]);
    }
  solve(1, n);
  cout << ans << endl;
  return 0;
}
