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>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long long MOD = 1e9 + 7;
const long long MOD2 = 998244353;
double eps = 1e-12;
using namespace std;
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
  return os << '(' << p.first << ", " << p.second << ')';
}
template <typename T_container, typename T = typename enable_if<
                                    !is_same<T_container, string>::value,
                                    typename T_container::value_type>::type>
ostream &operator<<(ostream &os, const T_container &v) {
  os << '{';
  string sep;
  for (const T &x : v) os << sep << x, sep = ", ";
  return os << '}';
}
void dbg_out() { cerr << "\n"; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}
template <typename T>
void get_ar(T *ar, long long n) {
  for (long long i = 0; i < n; i++) cin >> ar[i];
}
template <typename T>
void printar(T *ar, long long n) {
  for (long long i = 0; i < n; i++) cout << ar[i] << " ";
  cout << "\n";
}
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long imod(long long a, long long m) { return power(a, m - 2, m); }
template <typename T, size_t N, size_t M>
void print2dArray(T (&theArray)[N][M], long long n = N, long long m = M) {
  for (long long x = 0; x < n; x++) {
    for (long long y = 0; y < m; y++) {
      cout << theArray[x][y] << " ";
    }
    cout << "\n";
  }
}
template <typename T, size_t N>
void print_ar(T (&theArray)[N], long long n = N) {
  for (long long x = 0; x < n; x++) {
    cout << theArray[x] << " ";
  }
  cout << "\n";
}
const long long maxn = 3e5 + 5;
long long lge[maxn], lle[maxn], rge[maxn], rle[maxn];
void precompute(long long *h, long long n) {
  vector<pair<long long, long long> > st;
  for (long long i = 0; i < n; i++) {
    while (!st.empty() && st.back().first < h[i]) {
      st.pop_back();
    }
    if (st.empty())
      lge[i] = -1;
    else
      lge[i] = st.back().second;
    st.emplace_back(h[i], i);
  }
  st.clear();
  for (long long i = 0; i < n; i++) {
    while (!st.empty() && st.back().first > h[i]) {
      st.pop_back();
    }
    if (st.empty())
      lle[i] = -1;
    else
      lle[i] = st.back().second;
    st.emplace_back(h[i], i);
  }
  st.clear();
  for (long long i = n - 1; i >= 0; i--) {
    while (!st.empty() && st.back().first < h[i]) {
      st.pop_back();
    }
    if (st.empty())
      rge[i] = n;
    else
      rge[i] = st.back().second;
    st.emplace_back(h[i], i);
  }
  st.clear();
  for (long long i = n - 1; i >= 0; i--) {
    while (!st.empty() && st.back().first > h[i]) {
      st.pop_back();
    }
    if (st.empty())
      rle[i] = -1;
    else
      rle[i] = st.back().second;
    st.emplace_back(h[i], i);
  }
}
long long ar[maxn];
long long n;
void solve() {
  long long K, ans = 0, tmp;
  cin >> n;
  get_ar(ar, n);
  long long pos[maxn];
  for (long long i = 0; i < n; i++) pos[ar[i]] = i;
  precompute(ar, n);
  for (long long i = 0; i < n; i++) {
    long long l = lge[i], r = rge[i];
    long long llen = i - l, rlen = r - i - 1;
    if (llen <= rlen) {
      for (long long j = l + 1; j < i + 1; j++) {
        long long t = ar[i] - ar[j];
        ans += (pos[t] > i && pos[t] < r);
      }
    } else {
      for (long long j = i + 1; j < r; j++) {
        long long t = ar[i] - ar[j];
        ans += (pos[t] > l && pos[t] <= i);
      }
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  for (long long it = 1; it <= t; it++) {
    solve();
  }
  return 0;
}
