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("-O2")
using namespace std;
void err(istream_iterator<string> it) { cerr << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << "\t";
  err(++it, args...);
}
template <typename T1, typename T2>
ostream& operator<<(ostream& c, pair<T1, T2>& v) {
  c << "(" << v.first << "," << v.second << ")";
  return c;
}
template <template <class...> class TT, class... T>
ostream& operator<<(ostream& out, TT<T...>& c) {
  out << "{ ";
  for (auto& x : c) out << x << " ";
  out << "}";
  return out;
}
const int LIM = 2e5 + 5, MOD = 1e9 + 7;
int t, n, m, k, x, y, w;
int p[LIM], valL[LIM], valR[LIM];
long long ans = 0;
void solve(int l, int r) {
  if (l > r) return;
  int mid = (l + r) >> 1;
  int lf = mid, rt = mid, mx = p[mid];
  valL[p[mid]]++, valR[p[mid]]++;
  int c = 0;
  while (1) {
    if (lf == l && rt == r) break;
    bool R = 0;
    if (lf == l)
      R = 1;
    else if (rt < r && p[lf - 1] > p[rt + 1])
      R = 1;
    if (R) {
      rt++;
      mx = max(p[rt], mx);
      ans += valL[(mx - p[rt])];
      valR[p[rt]]++;
    } else {
      lf--;
      mx = max(p[lf], mx);
      ans += valR[(mx - p[lf])];
      valL[p[lf]]++;
    }
  }
  for (int i = l; i < r + 1; ++i) valL[p[i]] = valR[p[i]] = 0;
  if (l != r) {
    solve(l, mid - 1);
    solve(mid + 1, r);
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> p[i];
  solve(0, n - 1);
  cout << ans << '\n';
  return 0;
}
