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;
template <typename T>
inline void ckmax(T& x, T y) {
  x = (y > x ? y : x);
}
template <typename T>
inline void ckmin(T& x, T y) {
  x = (y < x ? y : x);
}
namespace Fread {
const int SIZE = 1 << 20;
char buf[SIZE], *S, *T;
inline char getchar() {
  if (S == T) {
    T = (S = buf) + fread(buf, 1, SIZE, stdin);
    if (S == T) return EOF;
  }
  return *S++;
}
}  // namespace Fread
namespace Fwrite {
const int SIZE = 1 << 20;
char buf[SIZE], *S = buf, *T = buf + SIZE;
inline void flush() {
  fwrite(buf, 1, S - buf, stdout);
  S = buf;
}
inline void putchar(char c) {
  *S++ = c;
  if (S == T) flush();
}
struct _ {
  ~_() { flush(); }
} __;
}  // namespace Fwrite
template <typename T>
inline void read(T& x) {
  x = 0;
  int f = 1;
  char c = Fread::getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = Fread::getchar();
  }
  while (isdigit(c)) x = x * 10 + (c - '0'), c = Fread::getchar();
  x *= f;
}
template <typename T>
inline void write(T x, bool _enter = 0, bool _space = 0) {
  if (!x)
    Fwrite::putchar('0');
  else {
    if (x < 0) Fwrite::putchar('-'), x = -x;
    static char dig[41];
    int top = 0;
    while (x) dig[++top] = (x % 10) + '0', x /= 10;
    while (top) Fwrite::putchar(dig[top--]);
  }
  if (_enter) Fwrite::putchar('\n');
  if (_space) Fwrite::putchar(' ');
}
namespace Fastio {
struct reader {
  template <typename T>
  reader& operator>>(T& x) {
    ::read(x);
    return *this;
  }
  reader& operator>>(char& c) {
    c = Fread::getchar();
    while (c == '\n' || c == ' ') c = Fread::getchar();
    return *this;
  }
  reader& operator>>(char* str) {
    int len = 0;
    char c = Fread::getchar();
    while (c == '\n' || c == ' ') c = Fread::getchar();
    while (c != '\n' && c != ' ') str[len++] = c, c = Fread::getchar();
    str[len] = '\0';
    return *this;
  }
} cin;
const char endl = '\n';
struct writer {
  template <typename T>
  writer& operator<<(T x) {
    ::write(x, 0, 0);
    return *this;
  }
  writer& operator<<(char c) {
    Fwrite::putchar(c);
    return *this;
  }
  writer& operator<<(const char* str) {
    int cur = 0;
    while (str[cur]) Fwrite::putchar(str[cur++]);
    return *this;
  }
} cout;
}  // namespace Fastio
const int MAXN = 2e5;
const int LOG_MAXN = 18;
int n, a[MAXN + 5], pos[MAXN + 5];
long long ans;
struct RangeMaxQuery {
  int _log2[MAXN + 5];
  pair<int, int> st[MAXN + 5][LOG_MAXN + 1];
  void build(int* a, int n) {
    _log2[0] = -1;
    for (int i = 1; i <= n; ++i) {
      _log2[i] = _log2[i >> 1] + 1;
      st[i][0] = make_pair(a[i], i);
    }
    assert(_log2[n] <= LOG_MAXN);
    for (int j = 1; j <= LOG_MAXN; ++j) {
      for (int i = 1; i + (1 << (j - 1)) <= n; ++i) {
        st[i][j] = max(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
      }
    }
  }
  pair<int, int> rmq(int l, int r) {
    int k = _log2[r - l + 1];
    return max(st[l][k], st[r - (1 << k) + 1][k]);
  }
  int rmq_val(int l, int r) { return rmq(l, r).first; }
  int rmq_pos(int l, int r) { return rmq(l, r).second; }
  RangeMaxQuery() {}
} RMQ;
void solve(int l, int r) {
  if (l == r) return;
  int p = RMQ.rmq_pos(l, r);
  if (p - l < r - l) {
    for (int i = l; i < p; ++i) {
      assert(a[i] < a[p]);
      if (pos[a[p] - a[i]] > p && pos[a[p] - a[i]] <= r) {
        ans++;
      }
    }
  } else {
    for (int i = p + 1; i <= r; ++i) {
      assert(a[i] < a[p]);
      if (pos[a[p] - a[i]] >= l && pos[a[p] - a[i]] < p) {
        ans++;
      }
    }
  }
  if (p != l) solve(l, p - 1);
  if (p != r) solve(p + 1, r);
}
int main() {
  Fastio::cin >> n;
  for (int i = 1; i <= n; ++i) {
    Fastio::cin >> a[i];
    pos[a[i]] = i;
  }
  RMQ.build(a, n);
  solve(1, n);
  Fastio::cout << ans << Fastio::endl;
  return 0;
}
