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;
template <class T>
inline bool setmin(T &a, T b) {
  if (a > b) return a = b, 1;
  return 0;
}
template <class T>
inline bool setmax(T &a, T b) {
  if (a < b) return a = b, 1;
  return 0;
}
template <class T>
inline T fast(T a, T b, T mod) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
template <class T>
istream &operator>>(istream &os, vector<T> &container) {
  for (auto &u : container) os >> u;
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &container) {
  for (auto &u : container) os << u << " ";
  return os;
}
template <typename T>
inline T gcd(T a, T b) {
  while (b) swap(a %= b, b);
  return a;
}
long double e = 2.7182818284590452353602874713526624;
long double PI = acos(-1);
long double PIjane = sqrt(2) + sqrt(3);
long double eps = 1e-11;
const long long T = 1 << 19;
const long long INF = 1e9 + 7;
const long long BIG_INF = 1e18 + 5;
const int N = 1e6 + 7;
const int K = 1e3 + 7;
const int mod = 1000000;
long long n, m, ans;
pair<int, int> tree[T * 2];
int tab[N];
int wart[N];
int ask(int pocz, int kon) {
  int maxi = -INF, ret = -1;
  pocz += T - 1;
  kon += T + 1;
  while (pocz / 2 != kon / 2) {
    if (pocz % 2 == 0) {
      if (maxi < tree[pocz + 1].first) {
        maxi = tree[pocz + 1].first;
        ret = tree[pocz + 1].second;
      }
    }
    if (kon % 2 == 1) {
      if (maxi < tree[kon - 1].first) {
        maxi = tree[kon - 1].first;
        ret = tree[kon - 1].second;
      }
    }
    pocz /= 2;
    kon /= 2;
  }
  return ret;
}
void solve(int pocz, int kon) {
  if (kon - pocz < 2) return;
  int poz = ask(pocz, kon);
  int L = poz - pocz;
  int P = kon - poz;
  int val = tree[poz + T].first;
  if (L < P) {
    for (int i = pocz; i < poz; i++) {
      int nowa = val - wart[i];
      int pozycja = tab[nowa];
      if (pozycja > poz && pozycja <= kon) {
        ans++;
      }
    }
  } else {
    for (int i = poz + 1; i <= kon; i++) {
      int nowa = val - wart[i];
      int pozycja = tab[nowa];
      if (pozycja < poz && pozycja >= pocz) {
        ans++;
      }
    }
  }
  solve(pocz, poz - 1);
  solve(poz + 1, kon);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> wart[i];
    tab[wart[i]] = i;
    tree[i + T] = {wart[i], i};
  }
  for (int i = T - 1; i >= 0; i--) {
    tree[i] = (tree[i * 2].first < tree[i * 2 + 1].first) ? tree[i * 2 + 1]
                                                          : tree[i * 2];
  }
  solve(1, n);
  cout << ans;
}
