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;
long long mas[200005], pos[200005], lef[200005], ri[200005];
vector<pair<long long, long long> > st;
long long inf = 10000000;
long long ans;
void check(long long l, long long r, long long a, long long b, long long x) {
  for (long long i = l; i <= r; i++) {
    long long d = pos[x - mas[i]];
    if (d >= a && d <= b) ans++;
  }
}
int main() {
  long long n, m, i, j, a = 0, b, d, f, p, t;
  long long l, r, u, v, z, k, q, x;
  cin >> n;
  ans = 0;
  for (i = 1; i <= n; i++) {
    cin >> mas[i];
    pos[mas[i]] = i;
  }
  st.push_back({inf, 0});
  for (i = 1; i <= n; i++) {
    while (st[st.size() - 1].first < mas[i]) st.pop_back();
    lef[i] = st[st.size() - 1].second;
    st.push_back({mas[i], i});
  }
  st.clear();
  st.push_back({inf, n + 1});
  for (i = n; i >= 1; i--) {
    while (st[st.size() - 1].first < mas[i]) st.pop_back();
    ri[i] = st[st.size() - 1].second;
    st.push_back({mas[i], i});
  }
  for (i = 1; i <= n; i++) {
    l = lef[i] + 1, r = ri[i] - 1;
    a = i - l, b = r - i;
    if (b * a == 0) continue;
    if (b < a) {
      check(l, i - 1, i + 1, r, mas[i]);
    } else {
      check(i + 1, r, l, i - 1, mas[i]);
    }
  }
  cout << ans;
  return 0;
}
