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.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 beginner1010
 */
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);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        int count(int L, int R, int otherL, int otherR, int pivotIndex, int[] p, int[] permIndex) {
            int ans = 0;
            for (int i = L; i <= R; i++) {
                assert (p[i] < p[pivotIndex]);
                int other = p[pivotIndex] - p[i];
                int otherIndex = permIndex[other];
                if (otherL <= otherIndex && otherIndex <= otherR)
                    ans++;
            }
            return ans;
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] p = new int[n];
            for (int i = 0; i < n; i++) {
                p[i] = in.nextInt();
            }

            Stack<Integer> st = new Stack<Integer>();
            int[] left = new int[n];
            for (int i = 0; i < n; i++) {
                while (st.isEmpty() == false && p[st.peek()] < p[i]) {
                    st.pop();
                }
                left[i] = st.isEmpty() ? -1 : st.peek();
                st.push(i);
            }
            st.clear();

            int[] right = new int[n];
            for (int i = n - 1; i >= 0; i--) {
                while (st.isEmpty() == false && p[st.peek()] < p[i]) {
                    st.pop();
                }
                right[i] = st.isEmpty() ? n : st.peek();
                st.push(i);
            }

            int[] permIndex = new int[n + 1];
            for (int i = 0; i < n; i++) {
                permIndex[p[i]] = i;
            }

            int ans = 0;
            for (int i = 0; i < n; i++) {
                int lengthL = i - left[i];
                int lengthR = right[i] - i;
                if (lengthL < lengthR) {
                    ans += count(left[i] + 1, i - 1, i + 1, right[i] - 1, i, p, permIndex);
                } else {
                    ans += count(i + 1, right[i] - 1, left[i] + 1, i - 1, i, p, permIndex);
                }
            }
            out.println(ans);

        }

    }

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

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

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

        private 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 (isWhitespace(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 (!isWhitespace(c));
            return res * sgn;
        }

    }
}

