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 llINF = 1e18, llMOD = 1e9 + 7;
const int INF = 1e9, MOD = 1e9 + 7, P = 29, N = 2e5 + 2, K = 200, L = 20,
          A = 256;
const long double EPS = 1e-9, ldINF = 1e18, PI = acos(-1);
string sep = " ";
template <typename T, typename P>
istream &operator>>(istream &in, pair<T, P> &p) {
  in >> p.first >> p.second;
  return in;
}
template <typename T>
void in_seg(istream &in, T *dst_begin, T *dst_end) {
  while (dst_begin != dst_end) {
    in >> (*dst_begin);
    ++dst_begin;
  }
}
template <typename T>
istream &operator>>(istream &in, vector<T> &v) {
  for (int i = 0; i < v.size(); ++i) in >> v[i];
  return in;
}
template <typename T, typename P>
ostream &operator<<(ostream &out, pair<T, P> p) {
  out << p.first << ' ' << p.second;
  return out;
}
template <typename T>
ostream &operator<<(ostream &out, vector<T> &v) {
  for (int i = 0; i < v.size(); ++i) {
    out << v[i];
    if (i != v.size() - 1) out << sep;
  }
  return out;
}
template <typename T>
ostream &operator<<(ostream &out, vector<vector<T>> &v) {
  for (int i = 0; i < v.size(); ++i) {
    out << v[i];
    if (i != v.size() - 1) out << '\n';
  }
  return out;
}
void set_precision(ostream &out, int val) {
  out.setf(out.fixed, out.floatfield);
  out.precision(val);
}
pair<int, int> sp_t[L][N];
int l2[N], v[N], pos[N];
pair<int, int> sp_get(int l, int r) {
  return max(sp_t[l2[r - l + 1]][l],
             sp_t[l2[r - l + 1]][r + 1 - (1 << l2[r - l + 1])]);
}
long long rec(int l, int r) {
  if (r - l < 2) return 0;
  auto [mx, m] = sp_get(l, r);
  int res = 0;
  if (m - l < r - m) {
    for (int i = l; i < m; i++)
      if (pos[mx - v[i]] > m && r >= pos[mx - v[i]]) ++res;
  } else {
    for (int i = m + 1; i <= r; i++)
      if (pos[mx - v[i]] < m && l <= pos[mx - v[i]]) ++res;
  }
  return res + rec(l, m - 1) + rec(m + 1, r);
}
int main() {
  int n;
  cin >> n;
  for (int i = 2, l = 1; i <= n; i++) {
    if ((1 << (l + 1)) <= i) ++l;
    l2[i] = l;
  }
  for (int i = 0; i < n; i++) cin >> v[i];
  for (int i = 0; i < n; i++) pos[v[i]] = i;
  for (int i = 0; i < n; i++) sp_t[0][i] = {v[i], i};
  for (int k = 1; k <= l2[n]; k++) {
    for (int i = 0; i + (1 << k) <= n; i++) {
      sp_t[k][i] = max(sp_t[k - 1][i], sp_t[k - 1][i + (1 << (k - 1))]);
    }
  }
  cout << rec(0, n - 1);
}
