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::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), l(n), r(n), vt(n + 1);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    vt[a[i]] = i;
  }
  stack<int> s;
  for (int i = 0; i < n; ++i) {
    while (!s.empty() && a[s.top()] < a[i]) s.pop();
    if (s.empty())
      l[i] = -1;
    else
      l[i] = s.top();
    s.push(i);
    l[i]++;
  }
  while (!s.empty()) s.pop();
  for (int i = n - 1; i >= 0; --i) {
    while (!s.empty() && a[s.top()] < a[i]) s.pop();
    if (s.empty())
      r[i] = n;
    else
      r[i] = s.top();
    s.push(i);
    r[i]--;
  }
  int ans = 0;
  auto solve = [&](int l, int r, int ll, int rr, int val) {
    for (int i = l; i <= r; ++i) {
      int now = val - a[i];
      if (now && now <= n && vt[now] >= ll && vt[now] <= rr) ans++;
    }
  };
  for (int i = 0; i < n; ++i) {
    int sl = i - l[i], sr = r[i] - i;
    if (!sl || !sr) continue;
    if (sl < sr)
      solve(l[i], i - 1, i + 1, r[i], a[i]);
    else
      solve(i + 1, r[i], l[i], i - 1, a[i]);
  }
  cout << ans;
}
