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;
int II() {
  int q;
  scanf("%d", &q);
  return q;
}
long long LII() {
  long long q;
  scanf("%lld", &q);
  return q;
}
const long long Mx = 200005;
long long ar[Mx];
long long br[Mx];
long long N;
long long tree[Mx * 4];
void update(long long node, long long b, long long e) {
  if (b == e) {
    tree[node] = ar[b];
    return;
  }
  update(node * 2, b, (b + e) / 2);
  update((node * 2) + 1, (b + e) / 2 + 1, e);
  tree[node] = max(tree[node * 2], tree[(node * 2) + 1]);
}
long long query(long long node, long long b, long long e, long long l,
                long long r) {
  if (b > r or e < l) return 0;
  if (b >= l and e <= r) return tree[node];
  return max(query(node * 2, b, (b + e) / 2, l, r),
             query((node * 2) + 1, (b + e) / 2 + 1, e, l, r));
}
pair<long long, long long> pa[Mx];
void find(long long l, long long r) {
  if (l > r) return;
  long long q = query(1, 1, N, l, r);
  pa[q] = {l, r};
  find(l, br[q] - 1);
  find(br[q] + 1, r);
}
void solve() {
  cin >> N;
  for (long long i = 1; i <= N; i++) {
    cin >> ar[i];
    br[ar[i]] = i;
  }
  update(1, 1, N);
  find(1, N);
  long long ans = 0;
  for (long long i = 1; i <= N; i++) {
    long long l = br[i] - pa[i].first, r = pa[i].second - br[i];
    if (l < r) {
      for (long long j = pa[i].first; j < br[i]; j++) {
        long long q = i - ar[j];
        long long qq = query(1, 1, N, j, br[q]);
        if (br[q] > br[i] && qq == i) ans++;
      }
    } else {
      for (long long j = br[i] + 1; j <= pa[i].second; j++) {
        long long q = i - ar[j];
        long long qq = query(1, 1, N, br[q], j);
        if (qq == i and br[q] < br[i]) ans++;
      }
    }
  }
  cout << ans << endl;
}
int32_t main() {
  long long tt;
  tt = 1;
  long long cas = 1;
  while (tt--) {
    solve();
  }
}
