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 = 2e5 + 5;
int LG[N];
int sTable[N][20];
int n;
int a[N], idx[N];
void build() {
  LG[0] = -1;
  for (int i = 0; i < n; i++) {
    LG[i + 1] = LG[i] + !(i & (i + 1));
    sTable[i][0] = i;
  }
  for (int j = 1; (1 << j) <= n; j++)
    for (int i = 0; i + (1 << j) <= n; i++) {
      int x = sTable[i][j - 1];
      int y = sTable[i + (1 << (j - 1))][j - 1];
      sTable[i][j] = (a[x] > a[y] ? x : y);
    }
}
int query(int s, int e) {
  int len = e - s + 1;
  int lg = LG[len];
  int x = sTable[s][lg];
  int y = sTable[e - (1 << lg) + 1][lg];
  return (a[x] > a[y] ? x : y);
}
bool in(int mid, int l, int r) { return mid >= l && mid <= r; }
int solve(int l, int r) {
  if (l >= r) return 0;
  int mid = query(l, r);
  int Mx = a[mid];
  int ret = 0;
  if (mid - l <= r - mid) {
    for (int i = l; i < mid; i++) {
      int c = Mx - a[i];
      if (c >= 1 && c <= n && idx[c] >= mid + 1 && idx[c] <= r) ret++;
    }
  } else {
    for (int i = mid + 1; i <= r; i++) {
      int c = Mx - a[i];
      if (c >= 1 && c <= n && idx[c] >= l && idx[c] <= mid - 1) ret++;
    }
  }
  return ret + solve(l, mid - 1) + solve(mid + 1, r);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    idx[a[i]] = i;
  }
  build();
  printf("%d\n", solve(0, n - 1));
  return 0;
}
