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>
#pragma GCC optimize("O3")
using namespace std;
const int N = 2e5 + 5, M = 2 * N + 5;
int n, a[N], idxs[N], cnt;
int LG[N];
int sTable[N][19];
int ind[N];
void build(int n) {
  LG[0] = -1;
  for (int i = 0; i < n; i++) {
    LG[i + 1] = LG[i] + !(i & (i + 1));
    sTable[i][0] = i;
  }
  for (int j = 1; (1 << j) <= n; j++)
    for (int i = 0; i + (1 << j) <= n; i++) {
      int A = sTable[i][j - 1];
      int B = sTable[i + (1 << (j - 1))][j - 1];
      sTable[i][j] = (a[A] > a[B] ? A : B);
    }
}
int find_max(int second, int e) {
  int len = e - second + 1;
  int lg = LG[len];
  int A = sTable[second][lg];
  int B = sTable[e - (1 << lg) + 1][lg];
  return (a[A] > a[B] ? A : B);
}
int getMx(int l, int r) { return a[find_max(l, r)]; }
void first(int hna, int l, int r) {
  int idx = idxs[hna];
  int lf = idx - l;
  int rt = r - idx;
  if (lf <= rt) {
    for (int i = l; i < idx; ++i)
      if (hna - a[i] > 0 && idxs[hna - a[i]] > idx && idxs[hna - a[i]] <= r)
        ++cnt;
  } else {
    for (int i = idx + 1; i <= r; ++i)
      if (hna - a[i] > 0 && idxs[hna - a[i]] < idx && idxs[hna - a[i]] >= l)
        ++cnt;
  }
  if (l <= idx - 1) first(getMx(l, idx - 1), l, idx - 1);
  if (idx + 1 <= r) first(getMx(idx + 1, r), idx + 1, r);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
    idxs[a[i]] = i;
  }
  build(n);
  first(n, 0, n - 1);
  printf("%d\n", cnt);
  return 0;
}
