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, M = 18;
int LG[N];
int arr[N];
int sTable[N][M];
int ind[N];
void build(int n) {
  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 a = sTable[i][j - 1];
      int b = sTable[i + (1 << (j - 1))][j - 1];
      sTable[i][j] = (arr[a] > arr[b] ? a : b);
    }
}
int find_max(int s, int e) {
  int len = e - s + 1;
  int lg = LG[len];
  int a = sTable[s][lg];
  int b = sTable[e - (1 << lg) + 1][lg];
  return (arr[a] > arr[b] ? a : b);
}
int solve(int l, int r) {
  if (r < l) return 0;
  int max_ind = find_max(l, r);
  int ans = solve(l, max_ind - 1) + solve(max_ind + 1, r);
  if (max_ind - l < r - max_ind) {
    for (int i = l; i < max_ind; i++) {
      int j = ind[arr[max_ind] - arr[i]];
      ans += j > max_ind && j <= r;
    }
  } else {
    for (int i = max_ind + 1; i <= r; i++) {
      int j = ind[arr[max_ind] - arr[i]];
      ans += j < max_ind && j >= l;
    }
  }
  return ans;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", arr + i);
    ind[arr[i]] = i;
  }
  build(n);
  printf("%d\n", solve(0, n - 1));
}
