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 maxn = 2e5 + 10, mod = 1e9 + 7;
const long long inf = 1e18;
vector<int> v[maxn];
set<int> st[maxn];
int bef[maxn], aft[maxn], a[maxn], ans;
void dfs(int u) {
  for (int y : v[u]) {
    dfs(y);
    if (int((st[u]).size()) < int((st[y]).size())) swap(st[u], st[y]);
    for (int x : st[y]) ans += st[u].count(u - x);
    for (int x : st[y]) st[u].insert(x);
    st[y].clear();
  }
  st[u].insert(u);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    bef[i] = i - 1;
    while (bef[i] >= 0 && a[bef[i]] < a[i]) bef[i] = bef[bef[i]];
  }
  for (int i = n - 1; i >= 0; i--) {
    aft[i] = i + 1;
    while (aft[i] < n && a[aft[i]] < a[i]) aft[i] = aft[aft[i]];
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == n) continue;
    if (bef[i] == -1)
      v[a[aft[i]]].push_back(a[i]);
    else if (aft[i] == n)
      v[a[bef[i]]].push_back(a[i]);
    else if (a[aft[i]] < a[bef[i]])
      v[a[aft[i]]].push_back(a[i]);
    else
      v[a[bef[i]]].push_back(a[i]);
  }
  dfs(n);
  return cout << ans << endl, 0;
}
