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 Maxn = 201000;
int n, a[Maxn], f[Maxn][31], lm[Maxn], rm[Maxn], p[Maxn];
long long ans;
int Max(int l, int r) {
  int m = 0;
  while ((1 << m) <= r - l + 1) ++m;
  --m;
  return max(f[l][m], f[r - (1 << m) + 1][m]);
}
int Get(int m, int x, int t) {
  int l = (t == 0) ? 1 : m;
  int r = (t == 0) ? m : n, ans = 0;
  while (l <= r) {
    int mid = (l + r) / 2;
    int L = (t == 0) ? mid : m;
    int R = (t == 0) ? m : mid;
    if (Max(L, R) <= x) {
      ans = mid;
      if (t == 0)
        r = mid - 1;
      else
        l = mid + 1;
    } else {
      if (t == 0)
        l = mid + 1;
      else
        r = mid - 1;
    }
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    p[a[i]] = i;
    f[i][0] = a[i];
  }
  for (int j = 1; j <= 30; ++j) {
    for (int i = 1; i <= n; ++i) {
      f[i][j] = f[i][j - 1];
      if (i + (1 << (j - 1)) <= n) {
        f[i][j] = max(f[i][j], f[i + (1 << (j - 1))][j - 1]);
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    lm[i] = Get(i, a[i], 0);
    rm[i] = Get(i, a[i], 1);
  }
  for (int i = 1; i <= n; ++i) {
    int L1 = 0, R1 = 0, L2 = 0, R2 = 0;
    if (rm[i] - i + 1 <= i - lm[i] + 1) {
      L1 = i + 1, R1 = rm[i];
      L2 = lm[i], R2 = i - 1;
    } else {
      L1 = lm[i], R1 = i - 1;
      L2 = i + 1, R2 = rm[i];
    }
    for (int j = L1; j <= R1; ++j) {
      if (p[a[i] - a[j]] >= L2 && p[a[i] - a[j]] <= R2) ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}
