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;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const long long maxn = 4e5 + 1e2;
struct Node {
  long long pos, val;
};
long long l[maxn], r[maxn];
long long n, m;
long long a[maxn];
Node s[maxn];
long long top;
long long ans;
long long pos[maxn];
bool in(long long x, long long l, long long r) { return (x >= l) && (x <= r); }
signed main() {
  n = read();
  for (long long i = 1; i <= n; i++) a[i] = read(), pos[a[i]] = i;
  l[1] = 1;
  top = 1;
  s[1].val = a[1];
  s[1].pos = 1;
  for (long long i = 2; i <= n; i++) {
    while (top >= 1 && s[top].val <= a[i]) top--;
    if (!top)
      l[i] = 1;
    else
      l[i] = s[top].pos + 1;
    s[++top].val = a[i];
    s[top].pos = i;
  }
  r[n] = n;
  top = 1;
  s[1].val = a[n];
  s[1].pos = n;
  for (long long i = n - 1; i >= 1; i--) {
    while (top >= 1 && s[top].val < a[i]) top--;
    if (!top)
      r[i] = n;
    else
      r[i] = s[top].pos - 1;
    s[++top].val = a[i];
    s[top].pos = i;
  }
  for (long long i = 1; i <= n; i++) {
    long long mx = a[i];
    if (i - l[i] < r[i] - i) {
      for (long long j = l[i]; j < i; j++) {
        if (in(pos[mx - a[j]], i, r[i])) ans++;
      }
    } else {
      for (long long j = i + 1; j <= r[i]; j++) {
        if (in(pos[mx - a[j]], l[i], i)) ans++;
      }
    }
  }
  cout << ans;
  return 0;
}
