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 long long mod = 998244353;
const long long INF = mod * mod;
const long double eps = 1e-8;
struct SegT {
 private:
  int sz;
  vector<int> node;
  const int init_c = -mod;

 public:
  void init(vector<int> v) {
    int n = v.size();
    sz = 1;
    while (sz < n) sz *= 2;
    node.resize(2 * sz - 1, init_c);
    for (int i = 0; i < n; i++) {
      node[i + sz - 1] = v[i];
    }
    for (int i = sz - 1 - 1; i >= 0; i--) {
      node[i] = f(node[2 * i + 1], node[2 * i + 2]);
    }
  }
  int f(int a, int b) { return max(a, b); }
  void update(int k, int a) {
    k += sz - 1;
    node[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      node[k] = f(node[k * 2 + 1], node[k * 2 + 2]);
    }
  }
  int query(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = sz;
    if (r <= a || b <= l)
      return init_c;
    else if (a <= l && r <= b)
      return node[k];
    else {
      int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
      int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
      return f(vl, vr);
    }
  }
};
int n;
vector<int> p;
SegT st;
int trans[1 << 18];
long long ans = 0;
void d_and_c(int l, int r) {
  if (l > r) return;
  int ma = st.query(l, r + 1);
  int mid = trans[ma];
  d_and_c(l, mid - 1);
  d_and_c(mid + 1, r);
  int lenl = mid - l;
  int lenr = r - mid;
  if (lenl < lenr) {
    for (int i = l; i <= mid - 1; i++) {
      int loc = trans[ma - p[i]];
      if (mid + 1 <= loc && loc <= r) ans++;
    }
  } else {
    for (int i = mid + 1; i <= r; i++) {
      int loc = trans[ma - p[i]];
      if (l <= loc && loc <= mid - 1) ans++;
    }
  }
}
void solve() {
  cin >> n;
  p.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    trans[p[i]] = i;
  }
  st.init(p);
  d_and_c(0, n - 1);
  cout << ans << endl;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
