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 a[(int)2e5 + 10];
int maxVal[(int)2e5 + 10][20];
unordered_map<int, int> position;
void DataStructureBuilder(int n) {
  for (int i = 0; i < n; i++) maxVal[i][0] = a[i];
  int cur_pow = 1;
  while ((1 << (cur_pow - 1)) <= n) {
    int dist = 1 << (cur_pow - 1);
    for (int i = 0; i + 2 * dist <= n; i++) {
      maxVal[i][cur_pow] =
          max(maxVal[i][cur_pow - 1], maxVal[i + dist][cur_pow - 1]);
    }
    cur_pow++;
  }
}
int MaxBetween(int start, int end) {
  int len = end - start + 1;
  int cur_pow = 0;
  while (len > 1) {
    len /= 2;
    cur_pow++;
  }
  int left = maxVal[start][cur_pow];
  int right = maxVal[end - (1 << cur_pow) + 1][cur_pow];
  int ans = max(left, right);
  return ans;
}
long long f(int left, int right) {
  if (left > right) return 0;
  int maximum = MaxBetween(left, right);
  int maxPos = position[maximum];
  int leftSize = maxPos - left;
  int rightSize = right - maxPos;
  int start = (leftSize < rightSize) ? left : maxPos + 1;
  int end = (leftSize < rightSize) ? maxPos - 1 : right;
  int otherStart = (leftSize < rightSize) ? maxPos + 1 : left;
  int otherEnd = (leftSize < rightSize) ? right : maxPos - 1;
  long long ans = 0;
  for (int i = start; i <= end; i++) {
    int target = maximum - a[i];
    if (position[target] <= otherEnd && position[target] >= otherStart) {
      ans++;
    }
  }
  return ans + f(left, maxPos - 1) + f(maxPos + 1, right);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    position[a[i]] = i;
  }
  DataStructureBuilder(n);
  cout << f(0, n - 1);
}
