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;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l, int r) { return l + rng() % (r - l + 1); }
const int N = 200010;
int n;
long long ret;
int a[N], lz[N], b[N];
int f[N][25];
int que(int i, int j) {
  int t = lz[j - i + 1];
  return max(f[i][t], f[j - (1 << t) + 1][t]);
}
void dnc(int l, int r) {
  if (l >= r) return;
  int x = que(l, r);
  int p = b[x];
  if (p - l < r - p)
    for (int i = l, _c = p - 1; i <= _c; ++i)
      ret += r >= b[x - a[i]] && b[x - a[i]] > p;
  else
    for (int i = p + 1, _c = r; i <= _c; ++i)
      ret += l <= b[x - a[i]] && b[x - a[i]] < p;
  dnc(l, p - 1);
  dnc(p + 1, r);
}
int main() {
  n = ({
    int x = 0;
    int c = getchar(), n = 0;
    for (; !isdigit(c); c = getchar()) n = (c == '-');
    for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
    n ? -x : x;
  });
  for (int i = 1, _c = n; i <= _c; ++i)
    a[i] = f[i][0] = ({
      int x = 0;
      int c = getchar(), n = 0;
      for (; !isdigit(c); c = getchar()) n = (c == '-');
      for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
      n ? -x : x;
    }),
    b[a[i]] = i, lz[i] = log2(i);
  for (int j = 1, _c = 20; j <= _c; ++j)
    for (int i = 1, _c = n; i <= _c; ++i) {
      if (i + (1 << j - 1) > n) break;
      f[i][j] = max(f[i][j - 1], f[i + (1 << j - 1)][j - 1]);
    }
  dnc(1, n);
  cout << ret;
}
