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;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using vi = vector<long long>;
using vb = vector<bool>;
using pii = pair<long long, long long>;
using mii = map<long long, long long>;
const long long inf = (long long)1e16;
const long long upper = (long long)3e5 + 50;
const long long M = (long long)1e9 + 7;
const long long mod = (long long)998244353;
const double eps = 1e-8;
long long arr[upper];
set<long long> sets[upper];
long long which[upper];
long long cur_set = 0;
long long pos[upper], sz[upper];
signed main() {
  long long begtime = clock();
  ;
  cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false);
  memset(arr, 0, sizeof arr);
  long long n;
  cin >> n;
  for (long long i = 0; i <= n + 10; i += 1)
    which[i] = -1, sz[i] = 0, pos[i] = -1;
  for (long long i = 1; i <= n; i += 1) {
    cin >> arr[i];
    pos[arr[i]] = i;
  }
  long long ans = 0;
  for (long long i = 1; i <= n; i += 1) {
    long long bigger;
    if (sz[which[arr[pos[i] - 1]]] > sz[which[arr[pos[i] + 1]]]) {
      bigger = which[arr[pos[i] - 1]];
    } else {
      bigger = which[arr[pos[i] + 1]];
    }
    if (sz[bigger] == 0) {
      cur_set += 1;
      which[i] = cur_set;
      sets[cur_set].insert(i);
      sz[which[i]] += 1;
    } else {
      long long cnt = 0;
      long long smaller;
      if (bigger == which[arr[pos[i] - 1]])
        smaller = which[arr[pos[i] + 1]];
      else
        smaller = which[arr[pos[i] - 1]];
      if (sz[smaller] != 0) {
        vector<long long> hata;
        for (auto lol : sets[smaller]) {
          long long need = i - lol;
          if (sets[bigger].find(need) != sets[bigger].end()) {
            cnt += 1;
          }
          which[lol] = bigger;
          sz[bigger] += 1;
          hata.push_back(lol);
        }
        for (auto lol : hata) {
          sets[smaller].erase(lol);
          sets[bigger].insert(lol);
        }
      }
      which[i] = bigger;
      sz[bigger] += 1;
      sets[which[i]].insert(i);
      ans += cnt;
    }
  }
  cout << ans;
  long long endtime = clock();
  cerr << '\n'
       << "Time elapsed: " << (endtime - begtime) * 1000 / CLOCKS_PER_SEC
       << " ms";
  return 0;
}
