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, a[210000], pos[210000], Log2[210000];
int f[210000][21];
void init() {
  for (int i = 1; i <= n; i++) f[i][0] = i;
  for (int j = 1; (1 << j) <= n; j++)
    for (int i = 1; i + (1 << j) - 1 <= n; i++)
      if (a[f[i][j - 1]] > a[f[i + (1 << (j - 1))][j - 1]])
        f[i][j] = f[i][j - 1];
      else
        f[i][j] = f[i + (1 << (j - 1))][j - 1];
}
int query(int l, int r) {
  int k = Log2[r - l + 1];
  if (a[f[l][k]] > a[f[r - (1 << k) + 1][k]])
    return f[l][k];
  else
    return f[r - (1 << k) + 1][k];
}
int dfs(int l, int r) {
  if (l >= r) return 0;
  int k = query(l, r), ans = 0, v;
  if (k - l <= r - k)
    for (int i = l; i <= k; i++) {
      v = a[k] - a[i];
      if (pos[v] > k && pos[v] <= r) ans++;
    }
  else
    for (int i = k + 1; i <= r; i++) {
      v = a[k] - a[i];
      if (pos[v] >= l && pos[v] <= k) ans++;
    }
  return ans + dfs(l, k - 1) + dfs(k + 1, r);
}
int main() {
  scanf("%d", &n);
  Log2[0] = -1;
  for (int i = 1; i <= n; i++) Log2[i] = Log2[i >> 1] + 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    pos[a[i]] = i;
  }
  init();
  printf("%d\n", dfs(1, n));
  return 0;
}
