#include <bits/stdc++.h>
using namespace std;
const int N = 200004;
int n, a[N], l[N], r[N], id[N];
stack<int> st;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    id[a[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    while (!st.empty() && a[st.top()] <= a[i]) st.pop();
    if (st.empty())
      l[i] = 0;
    else
      l[i] = st.top();
    st.push(i);
  }
  while (!st.empty()) st.pop();
  for (int i = n; i >= 1; i--) {
    while (!st.empty() && a[st.top()] <= a[i]) st.pop();
    if (st.empty())
      r[i] = n + 1;
    else
      r[i] = st.top();
    st.push(i);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (i - l[i] < r[i] - i)
      for (int j = l[i] + 1; j < i; j++) {
        if (id[a[i] - a[j]] > i && id[a[i] - a[j]] < r[i]) ans++;
      }
    else
      for (int j = r[i] - 1; j > i; j--) {
        if (id[a[i] - a[j]] < i && id[a[i] - a[j]] > l[i]) ans++;
      }
  }
  cout << ans;
}
