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.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.Map;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.util.HashMap;
import java.io.IOException;
import java.io.InputStream;

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

    static class ESpecialSegmentsOfPermutation {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();

            int[] a = in.nextIntArray(n);


            out.println(rec(0, n - 1, a));
        }

        long rec(int s, int e, int[] a) {
            if (e - s == 0) {
                return 0;
            }

            if (e - s == 1) {
                if (Math.max(a[s], a[e]) == a[s] + a[e]) {
                    return 1;
                }
            }

            int mid = (s + e) / 2;

            long ans = 0;

            long left = rec(s, mid, a);
            long right = rec(mid + 1, e, a);

            Map<Integer, Integer> lm = new HashMap<>();
            Map<Integer, Integer> rm = new HashMap<>();

            int cmax = -1;
            for (int i = mid + 1; i <= e; i++) {
                cmax = Math.max(cmax, a[i]);

                rm.put(a[i], cmax);
            }

            cmax = -1;

            for (int i = mid; i >= s; i--) {
                cmax = Math.max(cmax, a[i]);

                lm.put(a[i], cmax);
            }

            for (int i = mid; i >= s; i--) {
                int num = a[i];

                int max = lm.get(num);

                if (rm.containsKey(max - num)) {
                    int rmax = rm.get(max - num);

                    if (rmax <= max) {
                        ans++;
                    }
                }
            }

            for (int i = mid + 1; i <= e; i++) {
                int num = a[i];

                int max = rm.get(num);

                if (lm.containsKey(max - num)) {
                    int lmax = lm.get(max - num);

                    if (lmax <= max) {
                        ans++;
                    }
                }
            }

            return left + ans + right;
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(long i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; ++i) array[i] = nextInt();
            return array;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

