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;
long long a[200010], N, l[200010], r[200010], f[200010];
stack<long long> stk;
long long read(long long x = 0) {
  long long c, f = 1;
  for (c = getchar(); !isdigit(c); c = getchar())
    if (c == '-') f = -f;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;
  return f * x;
}
int main() {
  long long N = read(), i, ans(0), j;
  a[0] = a[N + 1] = (1ll << 60);
  for (i = 1; i <= N; i++) a[i] = read(), f[a[i]] = i;
  stk.emplace(0);
  for (i = 1; i <= N; i++) {
    while (a[stk.top()] < a[i]) stk.pop();
    l[i] = stk.top() + 1;
    stk.emplace(i);
  }
  while (!stk.empty()) stk.pop();
  stk.emplace(N + 1);
  for (i = N; i; i--) {
    while (a[stk.top()] < a[i]) stk.pop();
    r[i] = stk.top() - 1;
    stk.emplace(i);
  }
  for (i = 1; i <= N; i++) {
    if (i - l[i] < r[i] - i) {
      for (j = l[i]; j < i; j++) {
        if (i < f[a[i] - a[j]] and f[a[i] - a[j]] <= r[i]) ans++;
      }
    } else {
      for (j = i + 1; j <= r[i]; j++) {
        if (l[i] <= f[a[i] - a[j]] and f[a[i] - a[j]] < i) ans++;
      }
    }
  }
  printf("%lld", ans);
  return 0;
}
