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;
const int inf = 1e9 + 7;
const double eps = 1e-10;
const long long linf = 1e18 + 7;
const long long hh = 523;
pair<int, int> dat[1600007];
int le[1600007], ri[1600007];
int pos[200007], a[200007];
long long ans = 0;
pair<int, int> build(int l, int r, int id) {
  le[id] = l;
  ri[id] = r;
  if (l == r) {
    dat[id] = make_pair(a[l], l);
    return dat[id];
  }
  int mid = (l + r) >> 1;
  dat[id] = max(build(l, mid, id * 2), build(mid + 1, r, id * 2 + 1));
  return dat[id];
}
pair<int, int> query(int l, int r, int id) {
  int l1 = le[id], r1 = ri[id];
  if (l1 > r || l > r1) {
    return make_pair(0, 0);
  }
  if (l <= l1 && r1 <= r) {
    return dat[id];
  }
  return max(query(l, r, id * 2), query(l, r, id * 2 + 1));
}
void doit(int l, int r) {
  if (l > r) {
    return;
  }
  pair<int, int> q = query(l, r, 1);
  doit(l, q.second - 1);
  doit(q.second + 1, r);
  int mid = (l + r) >> 1;
  if (q.second <= mid) {
    for (int i = l; i <= q.second - 1; i++) {
      if (pos[q.first - a[i]] > q.second && pos[q.first - a[i]] <= r) {
        ans++;
      }
    }
  } else {
    for (int i = q.second + 1; i <= r; i++) {
      if (pos[q.first - a[i]] >= l && pos[q.first - a[i]] < q.second) {
        ans++;
      }
    }
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    pos[a[i]] = i;
  }
  pair<int, int> p = build(1, n, 1);
  doit(1, n);
  printf("%I64d\n", ans);
  return 0;
}
