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.util.*;
import java.io.*;

public class E64 {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt();
        int [] p = new int[n + 1]; int [] index = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            p[i] = sc.nextInt();
            index[p[i]] = i;
        }
        TreeSet<Integer> set = new TreeSet<>();
        set.add(0); set.add(n + 1);
        long ans = 0;
        for (int i = n; i >= 1; i--) {
            int here = index[i];
            int lower = set.lower(here);
            int higher = set.higher(here);
            Set<Integer> nums = new HashSet<>();
            if (here - lower < higher - here) {
                for (int j = lower + 1; j < here; j++) nums.add(p[j]);
                for (Integer j: nums) {
                    if (index[i - j] > here && index[i - j] < higher) ans++;
                }
            } else {
                for (int j = here + 1; j < higher; j++) nums.add(p[j]);
                for (Integer j: nums) {
                    if (index[i - j] < here && index[i - j] > lower) ans++;
                }
            }
            set.add(here);
        }
        out.println(ans);
        out.close();
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}