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 arr1[200005];
int tree1[800025];
int n;
void build1(int node, int start, int endi) {
  if (start == endi) {
    tree1[node] = arr1[start];
  } else {
    int mid = (start + endi) / 2;
    build1(2 * node, start, mid);
    build1(2 * node + 1, mid + 1, endi);
    tree1[node] = max(tree1[2 * node], tree1[2 * node + 1]);
  }
}
void update1(int node, int start, int endi, int idx, int val) {
  if (start == endi) {
    arr1[idx] = val;
    tree1[node] = val;
  } else {
    int mid = (start + endi) / 2;
    if (start <= idx and idx <= mid) {
      update1(2 * node, start, mid, idx, val);
    } else {
      update1(2 * node + 1, mid + 1, endi, idx, val);
    }
    tree1[node] = max(tree1[2 * node], tree1[2 * node + 1]);
  }
}
int query1(int node, int start, int endi, int l, int r) {
  if (r < start or endi < l) {
    return 0;
  }
  if (l <= start and endi <= r) {
    return tree1[node];
  }
  int mid = (start + endi) / 2;
  int p1 = query1(2 * node, start, mid, l, r);
  int p2 = query1(2 * node + 1, mid + 1, endi, l, r);
  return max(p1, p2);
}
int arr2[200005];
int tree2[800025];
void build2(int node, int start, int endi) {
  if (start == endi) {
    tree2[node] = arr2[start];
  } else {
    int mid = (start + endi) / 2;
    build2(2 * node, start, mid);
    build2(2 * node + 1, mid + 1, endi);
    tree2[node] = min(tree2[2 * node], tree2[2 * node + 1]);
  }
}
void update2(int node, int start, int endi, int idx, int val) {
  if (start == endi) {
    arr2[idx] = val;
    tree2[node] = val;
  } else {
    int mid = (start + endi) / 2;
    if (start <= idx and idx <= mid) {
      update2(2 * node, start, mid, idx, val);
    } else {
      update2(2 * node + 1, mid + 1, endi, idx, val);
    }
    tree2[node] = min(tree2[2 * node], tree2[2 * node + 1]);
  }
}
int query2(int node, int start, int endi, int l, int r) {
  if (r < start or endi < l) {
    return n + 1;
  }
  if (l <= start and endi <= r) {
    return tree2[node];
  }
  int mid = (start + endi) / 2;
  int p1 = query2(2 * node, start, mid, l, r);
  int p2 = query2(2 * node + 1, mid + 1, endi, l, r);
  return min(p1, p2);
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  int p[n + 1];
  int ind[n + 1];
  for (int i = 1; i <= n; i++) {
    int z;
    cin >> z;
    p[i] = z;
    ind[z] = i;
  }
  int answer = 0;
  for (int i = 1; i <= n; i++) {
    arr2[p[i]] = i;
    arr1[i] = 0;
  }
  build1(1, 1, n);
  build2(1, 1, n);
  for (int i = 1; i <= n; i++) {
    int x = query1(1, 1, n, p[i] + 1, n);
    int y = query2(1, 1, n, p[i] + 1, n);
    x++;
    y--;
    if (i - x <= y - i) {
      for (int j = x; j < i; j++) {
        if (p[i] - p[j] <= 0) {
          continue;
        } else {
          if (ind[p[i] - p[j]] > i && ind[p[i] - p[j]] <= y) {
            answer++;
          }
        }
      }
    } else {
      for (int j = y; j > i; j--) {
        if (p[i] - p[j] <= 0) {
          continue;
        } else {
          if (ind[p[i] - p[j]] < i && ind[p[i] - p[j]] >= x) {
            answer++;
          }
        }
      }
    }
    update1(1, 1, n, p[i], i);
    update2(1, 1, n, p[i], n + 1);
  }
  cout << answer;
}
