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].
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String args[]) {
        new Main().run();
    }

    FastReader in = new FastReader();
    PrintWriter out = new PrintWriter(System.out);

    void run() {
        work();
        out.flush();
    }

    long mod = 1000000007;
    long gcd(long a, long b) {
        return a == 0 ? b : gcd(b % a, a);
    }
    long inf = Long.MAX_VALUE / 3;
    void work() {
        int n=ni();
        int[] A=nia(n);
        int[] rec=new int[n+1];
        for(int i=0;i<n;i++){
            rec[A[i]]=i;
        }
        int[] L=new int[n];
        int[] R=new int[n];
        for(int i=0;i<n;i++){
            int next=i-1;
            while(next!=-1&&A[next]<A[i]){
                next=L[next];
            }
            L[i]=next;
        }
        for(int i=n-1;i>=0;i--){
            int next=i+1;
            while(next!=n&&A[next]<A[i]){
                next=R[next];
            }
            R[i]=next;
        }
        long ret=0;
        for(int i=0;i<n;i++){
            int l=L[i];
            int r=R[i];
            if(i-l<r-i){
                for(int j=i-1;j>l;j--){
                    int v=A[i]-A[j];
                    int idx=rec[v];
                    if(idx<r&&idx>i){
                        ret++;
                    }
                }
            }else{
                for(int j=i+1;j<r;j++){
                    int v=A[i]-A[j];
                    int idx=rec[v];
                    if(idx>l&&idx<i){
                        ret++;
                    }
                }
            }
        }
        out.println(ret);
    }


    private ArrayList<long[]>[] ngw(int n, int m) {
        ArrayList<long[]>[] graph = (ArrayList<long[]>[]) new ArrayList[n];
        for (int i = 0; i < n; i++) {
            graph[i] = new ArrayList<>();
        }
        for (int i = 1; i <= m; i++) {
            long s = in.nextLong() - 1, e = in.nextLong() - 1, w = in.nextLong();
            graph[(int) s].add(new long[]{e, w});
            graph[(int) e].add(new long[]{s, w});
        }
        return graph;
    }

    private ArrayList<Integer>[] ng(int n, int m) {
        ArrayList<Integer>[] graph = (ArrayList<Integer>[]) new ArrayList[n];
        for (int i = 0; i < n; i++) {
            graph[i] = new ArrayList<>();
        }
        for (int i = 1; i <= m; i++) {
            int s = in.nextInt() - 1, e = in.nextInt() - 1;
            graph[s].add(e);
            graph[e].add(s);
        }
        return graph;
    }

    private int ni() {
        return in.nextInt();
    }

    private long nl() {
        return in.nextLong();
    }

    private String ns() {
        return in.next();
    }

    private long[] na(int n) {
        long[] A = new long[n];
        for (int i = 0; i < n; i++) {
            A[i] = in.nextLong();
        }
        return A;
    }

    private int[] nia(int n) {
        int[] A = new int[n];
        for (int i = 0; i < n; i++) {
            A[i] = in.nextInt();
        }
        return A;
    }
}

class FastReader {
    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }


    public String next() {
        while (st == null || !st.hasMoreElements())//回车，空行情况
        {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }
}