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.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jenish
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ESpecialSegmentsOfPermutation solver = new ESpecialSegmentsOfPermutation();
        solver.solve(1, in, out);
        out.close();
    }

    static class ESpecialSegmentsOfPermutation {
        long ans = 0;
        int[] index;
        int[] arr;
        MaxSeg seg;

        void DFS(int l, int r) {
            if (l >= r) return;
            int max = seg.max(l, r);
            int id = index[max];
            if (id - l + 1 >= r - id + 1) {
                for (int i = id; i <= r; i++) if (check(l, id, index[max - arr[i]])) ans++;
            } else {
                for (int i = l; i <= id; i++) if (check(id, r, index[max - arr[i]])) ans++;
            }

            DFS(l, id - 1);
            DFS(id + 1, r);
        }

        boolean check(int l, int r, int index) {
            return index >= l && index <= r;
        }

        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();
            arr = new int[n + 1];
            index = new int[n + 5];
            for (int i = 1; i <= n; i++) index[arr[i] = in.scanInt()] = i;
            seg = new MaxSeg(n + 1);
            for (int i = 1; i <= n; i++) seg.setMax(i, arr[i]);
            DFS(1, n);
            out.println(ans);
        }

    }

    static class MaxSeg {
        int[] tree;
        int n;

        public MaxSeg(int n) {
            this.n = n;
            tree = new int[2 * n];
            Arrays.fill(tree, Integer.MIN_VALUE);
        }

        public void setMax(int i, int value) {
            i += this.tree.length / 2;
            this.tree[i] = value;
            for (; i > 1; i >>= 1)
                this.tree[i >> 1] = Math.max(this.tree[i], this.tree[i ^ 1]);
        }

        public int max(int a, int b) {
            int res = Integer.MIN_VALUE;
            for (a += this.tree.length / 2, b += this.tree.length / 2; a <= b; a = (a + 1) >> 1, b = (b - 1) >> 1) {
                res = Math.max(res, this.tree[a]);
                res = Math.max(res, this.tree[b]);
            }
            return res;
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int INDEX;
        private BufferedInputStream in;
        private int TOTAL;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (INDEX >= TOTAL) {
                INDEX = 0;
                try {
                    TOTAL = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (TOTAL <= 0) return -1;
            }
            return buf[INDEX++];
        }

        public int scanInt() {
            int I = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    I *= 10;
                    I += n - '0';
                    n = scan();
                }
            }
            return neg * I;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}

