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;
using namespace std::chrono;
const int N = 1e5 + 4, M = N, inf = (int)1e9;
const long long mod = 1e9 + 7;
int fastAbs(int n) { return (n ^ (n >> 31)) - (n >> 31); }
long long multiply(long long a, long long b) {
  return ((a % mod) * (b % mod)) % mod;
}
long long add(long long a, long long b) {
  return ((a % mod) + (b % mod)) % mod;
}
long long sub(long long a, long long b) {
  return ((a % mod) - (b % mod) + mod) % mod;
}
map<pair<int, int>, int> mp;
const int dx[4] = {1, 0, 0, -1};
const int dy[4] = {0, -1, 1, 0};
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  stack<int> s;
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<int> l(n), r(n);
  for (int i = 0; i < n; i++) {
    if (s.empty() || a[i] <= a[s.top()]) {
      l[i] = i;
      s.push(i);
    } else {
      while (!s.empty() && a[s.top()] <= a[i]) {
        int x = s.top();
        s.pop();
        l[i] = l[x];
      }
      s.push(i);
    }
  }
  while (!s.empty()) s.pop();
  for (int i = n - 1; i >= 0; i--) {
    if (s.empty() || a[i] <= a[s.top()]) {
      r[i] = i;
      s.push(i);
    }
    while (!s.empty() && a[s.top()] <= a[i]) {
      int x = s.top();
      s.pop();
      r[i] = r[x];
    }
    s.push(i);
  }
  int ans = 0;
  for (int i = 1; i < n - 1; i++) {
    if (l[i] == i || r[i] == i) continue;
    map<int, int> mp;
    for (int L = l[i]; L < i; L++) mp[a[i] - a[L]]++;
    for (int R = i + 1; R <= r[i]; R++) {
      if (mp.find(a[R]) != mp.end()) ans++;
    }
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int q = 1;
  while (q--) solve();
}
