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;
vector<int> A;
vector<int> idx;
vector<vector<int>> R;
void build_sparse_table(vector<vector<int>> &R) {
  int n = A.size();
  int k = floor(log2(n));
  R.resize(k + 1, vector<int>(n + 1, 0));
  for (int i = 1; i <= n; i++) {
    R[0][i] = A[i];
  }
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= n; j++) {
      R[i][j] = max(R[i - 1][j], R[i - 1][min(n, j + (1 << (i - 1)))]);
    }
  }
}
int range_max(vector<vector<int>> &R, int l, int r) {
  int d = r - l;
  d = floor(log2(d));
  return max(R[d][l], R[d][r - (1 << d) + 1]);
}
int solution(int i, int j) {
  if (j - i < 2) {
    return 0;
  }
  int num = range_max(R, i, j);
  int m = idx[num];
  int ans = 0;
  if (m - i <= j + 1 - (m + 1)) {
    for (int k = i; k < m; k++) {
      int q = num - A[k];
      if (m + 1 <= idx[q] && idx[q] <= j) ans++;
    }
  } else {
    for (int k = m + 1; k <= j; k++) {
      int q = num - A[k];
      if (i <= idx[q] && idx[q] <= m - 1) ans++;
    }
  }
  ans += solution(i, m - 1);
  ans += solution(m + 1, j);
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  A.resize(n + 1, 0);
  idx.resize(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
    idx[A[i]] = i;
  }
  build_sparse_table(R);
  cout << solution(1, n) << endl;
  return 0;
}
