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;
template <class T>
inline bool chmax(T &a, const T &b) {
  return b > a ? a = b, true : false;
}
template <class T>
inline bool chmin(T &a, const T &b) {
  return b < a ? a = b, true : false;
}
template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T, class F = less<T>>
void sort_uniq(vector<T> &v, F f = F()) {
  sort(begin(v), end(v), f);
  v.resize(unique(begin(v), end(v)) - begin(v));
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), ord(n + 1);
  for (int i = 0; i < (int)(n); i++) {
    cin >> a[i];
    ord[a[i]] = i;
  }
  vector<int> mxL(n, -1), mxR(n, n);
  {
    vector<int> st;
    for (int i = 0; i < (int)(n); i++) {
      while ((int)((st).size()) && a[i] > a[st.back()]) st.pop_back();
      if ((int)((st).size())) mxL[i] = st.back();
      st.push_back(i);
    }
  }
  {
    vector<int> st;
    for (int i = n - 1; i >= 0; i--) {
      while ((int)((st).size()) && a[i] > a[st.back()]) st.pop_back();
      if ((int)((st).size())) mxR[i] = st.back();
      st.push_back(i);
    }
  }
  int ans = 0;
  for (int i = 0; i < (int)(n); i++) {
    int l = mxL[i], r = mxR[i];
    if (i - l < r - i) {
      for (int j = i - 1; j > l; j--) {
        int x = a[i] - a[j];
        if (ord[x] > i && ord[x] < r) ans++;
      }
    } else {
      for (int j = i + 1; j < r; j++) {
        int x = a[i] - a[j];
        if (ord[x] > l && ord[x] < i) ans++;
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
