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 n;
int a[200005];
int st[200005 * 4];
int pos[200005];
void build(int p, int s, int e) {
  if (s == e) {
    st[p] = s;
    return;
  }
  int m = (s + e) / 2;
  build(p * 2 + 1, s, m);
  build(p * 2 + 2, m + 1, e);
  if (a[st[p * 2 + 1]] > a[st[p * 2 + 2]])
    st[p] = st[p * 2 + 1];
  else
    st[p] = st[p * 2 + 2];
}
int query(int p, int s, int e, int l, int r) {
  if (s == l && e == r) return st[p];
  int m = (s + e) / 2;
  int ans = -1;
  if (l <= m) ans = query(p * 2 + 1, s, m, l, min(m, r));
  if (m < r) {
    int tmp = query(p * 2 + 2, m + 1, e, max(m + 1, l), r);
    if (ans == -1 || a[ans] < a[tmp]) ans = tmp;
  }
  return ans;
}
long long solve(int l, int r) {
  if (r - l < 2) return 0;
  long long ans = 0;
  int pivot = query(0, 1, n, l, r);
  if (r - pivot <= pivot - l) {
    for (int i = pivot + 1; i <= r; i++) {
      int R = a[pivot] - a[i];
      if (l <= pos[R] && pos[R] < pivot) ans++;
    }
  } else {
    for (int i = l; i < pivot; i++) {
      int R = a[pivot] - a[i];
      if (pivot < pos[R] && pos[R] <= r) ans++;
    }
  }
  return ans + solve(l, pivot - 1) + solve(pivot + 1, r);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    pos[a[i]] = i;
  }
  build(0, 1, n);
  long long ans = solve(1, n);
  cout << ans << endl;
  return 0;
}
