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;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> P;
  P.reserve(n);
  copy_n(istream_iterator<int>(cin), n, back_inserter(P));
  vector<int> RP(n + 1);
  for (int i = 0; i < n; ++i) {
    RP[P[i]] = i;
  }
  stack<pair<int, int>> q;
  q.push({1234567, -1});
  vector<int> l_end(n);
  for (int i = 0; i < n; ++i) {
    int p = P[i];
    while (q.top().first < p) {
      q.pop();
    }
    l_end[i] = q.top().second;
    q.push({p, i});
  }
  q = stack<pair<int, int>>();
  q.push({1234567, n});
  vector<int> r_end(n);
  for (int i = n - 1; i >= 0; --i) {
    int p = P[i];
    while (q.top().first < p) {
      q.pop();
    }
    r_end[i] = q.top().second;
    q.push({p, i});
  }
  long long ans = 0LL;
  for (int i = 1; i < n - 1; ++i) {
    int l_size = i - l_end[i] - 1;
    int r_size = r_end[i] - i - 1;
    auto go_left = l_size < r_size;
    int j0 = (go_left ? l_end[i] + 1 : i + 1);
    int j1 = (go_left ? i : r_end[i]);
    int k0 = (go_left ? i + 1 : l_end[i] + 1);
    int k1 = (go_left ? r_end[i] : i);
    int p = P[i];
    for (; j0 < j1; ++j0) {
      int pj = P[j0];
      int rp = RP[p - pj];
      if (rp >= k0 && rp < k1) {
        ++ans;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
