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;
#pragma GCC optimize("O3")
const int mod = (1e9) + 7, mod2 = 998244353;
const double eps = 1e-10;
const int siz = 2e5 + 5, siz2 = 21, lg = 31, block = 317, block2 = 1000,
          mxv = 1e6;
int n, arr[siz], indof[siz], l[siz], r[siz];
stack<int> locmx;
int solve(int l, int r, int mxind) {
  int mx = arr[mxind], tot = 0;
  if (mxind - l < r - mxind) {
    for (int i = l; i < mxind; i++) {
      int otherind = indof[mx - arr[i]];
      if (otherind > mxind && otherind <= r) {
        tot++;
      }
    }
  } else {
    for (int i = mxind + 1; i <= r; i++) {
      int otherind = indof[mx - arr[i]];
      if (otherind < mxind && otherind >= l) {
        tot++;
      }
    }
  }
  return tot;
}
void calclr() {
  for (int i = 0; i < n; i++) {
    while (!locmx.empty()) {
      int ind = locmx.top();
      if (arr[ind] < arr[i]) {
        r[ind] = i - 1;
        locmx.pop();
      } else {
        l[i] = ind + 1;
        break;
      }
    }
    if (locmx.empty()) {
      l[i] = 0;
    }
    locmx.push(i);
  }
  while (!locmx.empty()) {
    int ind = locmx.top();
    r[ind] = n - 1;
    locmx.pop();
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
    indof[arr[i]] = i;
  }
  calclr();
  int tot = 0;
  for (int i = 0; i < n; i++) {
    tot += solve(l[i], r[i], i);
  }
  printf("%d\n", tot);
  return 0;
}
