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

public class SpecialSegments {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        int N = sc.nextInt();
        val = new int[N];
        valToPos = new int[N + 1];
        for (int i = 0; i < N; i++) {
            val[i] = sc.nextInt();
            valToPos[val[i]] = i;
        }
        rmq = new RMQ(val);
        solve(0, N - 1);
        out.println(ans);
        out.close();
    }

    static int[] val, valToPos;
    static RMQ rmq;
    static int ans;

    static TreeSet<Integer> solve(int lo, int hi) {
        if (lo == hi) {
            return new TreeSet<>(Set.of(val[lo]));
        }
        else if (lo > hi) {
            return new TreeSet<>();
        }
        else {
            int max = rmq.query(lo, hi);
            int mid = valToPos[max];

            var left = solve(lo, mid - 1);
            var right = solve(mid + 1, hi);
            if (left.size() > right.size()) {
                var temp = left;
                left = right;
                right = temp;
            }
            // by iterating over the smaller, this bounds it by size / 2
            // So, since we keep recurring, it's worst case of N/2 + N/4, ...
            for (int x : left) {
                if (right.contains(max - x)) {
                    ans++;
                }
            }
            right.addAll(left);
            right.add(max);
            return right;
        }
    }

    static class RMQ {
        int[][] table;
        public RMQ(int[] a) {
            int k = 0;
            while ((1 << (k + 1)) < a.length) {
                k++;
            }
            table = new int[k + 1][a.length];
            for (int i = 0; i < a.length; i++) {
                table[0][i] = a[i];
            }

            for (int p = 1; p <= k; p++) {
                int len = 1 << (p - 1);
                for (int i = 0; i < a.length; i++) {
                    table[p][i] = Math.max(table[p - 1][i], table[p - 1][Math.min(a.length - 1, i + len)]);
                }
            }
        }

        public int query(int i, int j) {
            int len = j - i + 1;
            int k = 0;
            while ((1 << (k + 1)) <= len) {
                k++;
            }
            return Math.max(table[k][i], table[k][j - (1 << k) + 1]);
        }
    }

    static class FastScanner {
        private int BS = 1<<16;
        private char NC = (char)0;
        private byte[] buf = new byte[BS];
        private int bId = 0, size = 0;
        private char c = NC;
        private double cnt = 1;
        private BufferedInputStream in;

        public FastScanner() {
            in = new BufferedInputStream(System.in, BS);
        }

        public FastScanner(String s) {
            try {
                in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
            }
            catch (Exception e) {
                in = new BufferedInputStream(System.in, BS);
            }
        }

        private char getChar(){
            while(bId==size) {
                try {
                    size = in.read(buf);
                }catch(Exception e) {
                    return NC;
                }
                if(size==-1)return NC;
                bId=0;
            }
            return (char)buf[bId++];
        }

        public int nextInt() {
            return (int)nextLong();
        }

        public int[] nextInts(int N) {
            int[] res = new int[N];
            for (int i = 0; i < N; i++) {
                res[i] = (int) nextLong();
            }
            return res;
        }

        public long[] nextLongs(int N) {
            long[] res = new long[N];
            for (int i = 0; i < N; i++) {
                res[i] = nextLong();
            }
            return res;
        }

        public long nextLong() {
            cnt=1;
            boolean neg = false;
            if(c==NC)c=getChar();
            for(;(c<'0' || c>'9'); c = getChar()) {
                if(c=='-')neg=true;
            }
            long res = 0;
            for(; c>='0' && c <='9'; c=getChar()) {
                res = (res<<3)+(res<<1)+c-'0';
                cnt*=10;
            }
            return neg?-res:res;
        }

        public double nextDouble() {
            double cur = nextLong();
            return c!='.' ? cur:cur+nextLong()/cnt;
        }

        public String next() {
            StringBuilder res = new StringBuilder();
            while(c<=32)c=getChar();
            while(c>32) {
                res.append(c);
                c=getChar();
            }
            return res.toString();
        }

        public String nextLine() {
            StringBuilder res = new StringBuilder();
            while(c<=32)c=getChar();
            while(c!='\n') {
                res.append(c);
                c=getChar();
            }
            return res.toString();
        }

        public boolean hasNext() {
            if(c>32)return true;
            while(true) {
                c=getChar();
                if(c==NC)return false;
                else if(c>32)return true;
            }
        }
    }
}