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 main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long n;
  cin >> n;
  vector<long long> p((size_t)n + 1);
  for (long long i = 1; i <= n; i++) {
    cin >> p[i];
  }
  vector<long long> r((size_t)n + 1);
  for (long long i = 1; i <= n; i++) {
    r[p[i]] = i;
  }
  vector<long long> stack;
  vector<long long> left((size_t)n + 1), right((size_t)n + 1);
  for (long long i = n; i >= 1; i--) {
    while (!stack.empty() && p[stack.back()] < p[i]) {
      left[stack.back()] = i + 1;
      stack.pop_back();
    }
    stack.push_back(i);
  }
  while (!stack.empty()) {
    left[stack.back()] = 1;
    stack.pop_back();
  }
  for (long long i = 1; i <= n; i++) {
    while (!stack.empty() && p[stack.back()] < p[i]) {
      right[stack.back()] = i - 1;
      stack.pop_back();
    }
    stack.push_back(i);
  }
  while (!stack.empty()) {
    right[stack.back()] = n;
    stack.pop_back();
  }
  long long c = 0;
  for (long long i = 1; i <= n; i++) {
    if (i - left[i] > right[i] - i) {
      for (long long j = i + 1; j <= right[i]; j++) {
        if (r[p[i] - p[j]] >= left[i] && r[p[i] - p[j]] < i) {
          c++;
        }
      }
    } else {
      for (long long j = i - 1; j >= left[i]; j--) {
        if (r[p[i] - p[j]] > i && r[p[i] - p[j]] <= right[i]) {
          c++;
        }
      }
    }
  }
  cout << c << endl;
  return 0;
}
