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.util.Vector;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Stack;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author revanth
 */
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(), ans = 0;
            int[] a = in.nextIntArray(n);
            Stack<Integer> s = new Stack<>();
            int[] r = new int[n];
            int[] l = new int[n];
            int[] inv = new int[n + 1];
            for (int i = 0; i < n; i++)
                inv[a[i]] = i;
            for (int i = 0; i < n; i++) {
                if (s.isEmpty() || a[i] < a[s.peek()])
                    s.push(i);
                else {
                    while (!s.isEmpty() && a[i] > a[s.peek()])
                        r[s.pop()] = i;
                    s.push(i);
                }
            }
            while (!s.isEmpty())
                r[s.pop()] = n;
            for (int i = n - 1; i >= 0; i--) {
                if (s.isEmpty() || a[i] < a[s.peek()])
                    s.push(i);
                else {
                    while (!s.isEmpty() && a[i] > a[s.peek()])
                        l[s.pop()] = i;
                    s.push(i);
                }
            }
            while (!s.isEmpty())
                l[s.pop()] = -1;
            for (int i = 0; i < n; i++) {
                if (i - l[i] <= r[i] - i) {
                    for (int j = l[i] + 1; j < i; j++) {
                        if (inv[a[i] - a[j]] > i && inv[a[i] - a[j]] < r[i])
                            ans++;
                    }
                } else {
                    for (int j = i + 1; j < r[i]; j++) {
                        if (inv[a[i] - a[j]] < i && inv[a[i] - a[j]] > l[i])
                            ans++;
                    }
                }
            }
            out.println(ans);
        }

    }

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

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

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

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

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

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

        }

    }

    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 print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println(Object... objects) {
            print(objects);
            writer.println();
        }

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

    }
}

