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;
int n;
inline void read() {
  cin >> n;
  a.resize(n);
  for (auto &i : a) cin >> i;
}
inline int f(int l, int r) {
  if (r - l <= 1) return 0;
  int m = (l + r) / 2;
  int ans = f(l, m) + f(m, r);
  unordered_map<int, int> have_left, have_right;
  int max_num = 0;
  for (int i = m - 1; i >= l; i--) {
    max_num = max(max_num, a[i]);
    have_left[a[i]] = max_num;
  }
  max_num = 0;
  for (int i = m; i < r; i++) {
    max_num = max(max_num, a[i]);
    have_right[a[i]] = max_num;
  }
  for (auto i : have_left) {
    int num = i.first;
    int max_num = i.second;
    if (have_right.count(max_num - num) == 0) continue;
    if (have_right[max_num - num] > max_num) continue;
    ans++;
  }
  for (auto i : have_right) {
    int num = i.first;
    int max_num = i.second;
    if (have_left.count(max_num - num) == 0) continue;
    if (have_left[max_num - num] > max_num) continue;
    ans++;
  }
  return ans;
}
int ans;
inline void run() { ans = f(0, n); }
inline void write() { cout << ans << endl; }
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  read();
  run();
  write();
  return 0;
}
