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

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

    static class ESpecialSegmentsOfPermutation {
        PrintWriter out;
        InputReader in;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            int n = ni();
            int[] permutation = new int[n];
            int[] map = new int[n + 1];
            int i = 0;
            for (i = 0; i < n; i++) {
                permutation[i] = ni();
                map[permutation[i]] = i;
            }
            int[] left = new int[n];
            int[] right = new int[n];
            Stack<Integer> st = new Stack<>();
            st.push(n - 1);
            for (i = n - 2; i >= 0; i--) {
                if (st.empty()) {
                    st.push(i);
                    continue;
                }
                while (!st.empty() && permutation[st.peek()] < permutation[i])
                    left[st.pop()] = i;
                st.push(i);
            }
            while (!st.empty())
                left[st.pop()] = -1;
            st.clear();
            st.push(0);
            for (i = 1; i < n; i++) {
                if (st.empty()) {
                    st.push(i);
                    continue;
                }
                while (!st.empty() && permutation[st.peek()] < permutation[i])
                    right[st.pop()] = i;
                st.push(i);
            }
            while (!st.empty())
                right[st.pop()] = n;
            long ans = 0;
            for (i = 0; i < n; i++) {
                int len1 = i - left[i];
                int len2 = right[i] - i;
                if (len1 > len2) {
                    for (int j = i + 1; j < right[i]; j++) {
                        int id = map[permutation[i] - permutation[j]];
                        if (id > left[i] && id < i)
                            ans++;
                    }
                } else {
                    for (int j = i - 1; j > left[i]; j--) {
                        int id = map[permutation[i] - permutation[j]];
                        if (id < right[i] && id > i)
                            ans++;
                    }
                }
            }
            pn(ans);
        }

        int ni() {
            return in.nextInt();
        }

        void pn(long zx) {
            out.println(zx);
        }

    }

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

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

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

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}

