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 int N = 1e6 + 2;
int n, x, y;
int a[N];
class SegmentTree {
  int *tree;

 public:
  SegmentTree() { tree = new int[4 * N]; }
  void build(int, int, int);
  int query(int, int, int, int, int);
};
void SegmentTree ::build(int id, int start, int end) {
  if (start > end) return;
  if (start == end) {
    tree[id] = a[start];
    return;
  }
  int mid = (start + end) >> 1;
  build(2 * id, start, mid);
  build(2 * id + 1, mid + 1, end);
  tree[id] = max(tree[2 * id + 1], tree[2 * id]);
}
int SegmentTree ::query(int id, int start, int end, int qs, int qe) {
  if (start > end || start > qe || end < qs) return -N;
  if (start >= qs && end <= qe) {
    return tree[id];
  }
  int mid = (start + end) >> 1;
  int L = query(2 * id, start, mid, qs, qe);
  int R = query(2 * id + 1, mid + 1, end, qs, qe);
  return max(L, R);
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  unordered_map<int, int> pos;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    pos[a[i]] = i;
  }
  int ans = 0;
  SegmentTree ob;
  ob.build(1, 0, n - 1);
  for (int i = 0; i < n; i++) {
    int low, high;
    low = i, high = n - 1;
    int L, R;
    while (low <= high) {
      int mid = (low + high) >> 1;
      int k = ob.query(1, 0, n - 1, i, mid);
      if (a[i] == k) {
        low = mid + 1;
        R = mid;
      } else
        high = mid - 1;
    }
    low = 0, high = i;
    while (low <= high) {
      int mid = (low + high) >> 1;
      int k = ob.query(1, 0, n - 1, mid, i);
      if (a[i] == k) {
        high = mid - 1;
        L = mid;
      } else
        low = mid + 1;
    }
    if (i - L <= R - i) {
      for (int j = L; j < i; j++) {
        assert(a[i] - a[j] > 0);
        if (pos[a[i] - a[j]] > i and pos[a[i] - a[j]] <= R) {
          ans++;
        }
      }
    } else {
      for (int j = i + 1; j <= R; j++) {
        assert(a[i] - a[j] > 0);
        if (pos[a[i] - a[j]] < i and pos[a[i] - a[j]] >= L) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
