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.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * @author khokharnikunj8
 */

public class Main {
    public static void main(String[] args) {
        new Thread(null, new Runnable() {
            public void run() {
                new Main().solve();
            }
        }, "1", 1 << 26).start();
    }

    void solve() {
        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 {
        SegmentTreeMax sm;
        int ans;
        int[] indexs;
        int[] p;

        public void findIt(int l, int r) {
            if (l > r) return;
            int index = sm.query(l, r);
            if (index - l < r - index) {
                for (int i = l; i < index; i++) {
                    if (indexs[p[index] - p[i]] > index && indexs[p[index] - p[i]] <= r) ans++;
                }
            } else {
                for (int i = index + 1; i <= r; i++) {
                    if (indexs[p[index] - p[i]] >= l && indexs[p[index] - p[i]] < index) ans++;
                }
            }
            findIt(l, index - 1);
            findIt(index + 1, r);
        }

        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();
            p = new int[n + 1];
            indexs = new int[n + 1];
            for (int i = 1; i <= n; i++) indexs[p[i] = in.scanInt()] = i;
            sm = new SegmentTreeMax(p, n);
            ans = 0;
            findIt(1, n);
            out.println(ans);

        }

    }

    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 integer = 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') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

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

    }

    static class SegmentTreeMax {
        int n;
        int[] t;
        int[] data;

        public SegmentTreeMax(int[] data, int n) {
            this.data = data;
            this.n = n;
            this.t = new int[2 * (n + 3)];
            build();
        }

        void build() {
            for (int i = 0; i < n; i++) t[i + n] = i + 1;
            for (int i = n - 1; i > 0; --i)
                t[i] = (data[t[i << 1]] >= data[t[i << 1 | 1]] ? t[i << 1] : t[(i << 1 | 1)]);
        }

        public int query(int l, int r) {
            int res = l;
            for (l += n - 1, r += n; l < r; l >>= 1, r >>= 1) {
                if ((l & 1) != 0) {
                    res = (data[res] > data[t[l]] ? res : t[l]);
                    l++;
                }
                if ((r & 1) != 0) {
                    r--;
                    res = (data[res] > data[t[r]] ? res : t[r]);
                }
            }
            return res;
        }

    }
}

