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 int N = 2e6 + 10;
const long long int inf = 1e9 + 10;
const long double Pi = 3.14159265;
long long int n, x, ans, l[N], r[N], j, a[N];
stack<long long int> s;
map<long long int, vector<long long int>> p;
long long int sum(long long int t[], long long int l, long long int r,
                  long long int v = 1, long long int tl = 0,
                  long long int tr = n - 1) {
  if (l > r) return 0;
  if (l == tl && r == tr) return t[v];
  long long int tm = (tl + tr) / 2;
  return sum(t, l, min(r, tm), v * 2, tl, tm) +
         sum(t, max(l, tm + 1), r, v * 2 + 1, tm + 1, tr);
}
void update(long long int t[], long long int pos, long long int new_val,
            long long int v = 1, long long int tl = 0,
            long long int tr = n - 1) {
  if (tl == tr) {
    t[v] += new_val;
  } else {
    long long int tm = (tl + tr) / 2;
    if (pos <= tm)
      update(t, pos, new_val, v * 2, tl, tm);
    else
      update(t, pos, new_val, v * 2 + 1, tm + 1, tr);
    t[v] = t[v * 2] + t[v * 2 + 1];
  }
}
void solve() {
  cin >> n;
  for (long long int i = 1; i <= n; i++) cin >> a[i];
  for (long long int i = 1; i <= n; i++) p[a[i]].push_back(i);
  for (long long int i = 1; i <= n; i++) {
    while (s.empty() == 0 and a[s.top()] < a[i]) s.pop();
    if (s.empty() == 0) l[i] = s.top();
    s.push(i);
  }
  s = stack<long long int>();
  for (long long int i = n; i >= 1; i--) {
    while (s.empty() == 0 and a[s.top()] < a[i]) s.pop();
    if (s.empty() == 0)
      r[i] = s.top();
    else
      r[i] = n + 1;
    s.push(i);
  }
  for (long long int i = 1; i <= n; i++) ++l[i], --r[i];
  for (long long int i = 1; i <= n; i++) {
    if (i - l[i] < r[i] - i) {
      for (j = l[i]; j < i; j++) {
        if (p.count(a[i] - a[j]) == 0) continue;
        for (auto suspect : p[a[i] - a[j]])
          if (suspect <= r[i] and suspect >= i) ans++;
      }
    } else {
      for (j = r[i]; j > i; j--) {
        if (p.count(a[i] - a[j]) == 0) continue;
        for (auto suspect : p[a[i] - a[j]])
          if (suspect >= l[i] and suspect <= i) ans++;
      }
    }
  }
  cout << ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  solve();
  long long int xx = 0;
  return 0;
}
