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.*;
import static java.lang.Math.*;
import java.math.BigInteger;
public class Main {
    static final long MOD = 1_000_000_007 , INF = 1_000_000_000_000_000L;
    static final int INf = 1_000_000_000;
    static FastReader reader;
    static PrintWriter writer;
    public static void main(String[] args) {
        Thread t = new Thread(null, new O(), "Integer.MAX_VALUE", 100000000);
        t.start();
    }
    static class O implements Runnable {
        public void run() {
            try {
                magic();
            }
            catch (Exception e) {
                e.printStackTrace();
                System.exit(1);
            }
        }
    }
    static class FastReader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public FastReader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public FastReader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException {
            byte[] buf = new byte[1000000];
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n') break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ') c = read();
            boolean neg = (c == '-');
            if (neg) c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg) return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ') c = read();
            boolean neg = (c == '-');
            if (neg) c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg) return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ') c = read();
            boolean neg = (c == '-');
            if (neg) c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (c == '.') while ((c = read()) >= '0' && c <= '9') ret += (c - '0') / (div *= 10);
            if (neg) return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1) buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead) fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException {
            if (din == null) return;
            din.close();
        }
    }
    static int n, arr[], pos[], tree[];
    static void magic() throws IOException {
        reader = new FastReader();
        writer = new PrintWriter(System.out, true);
        n = reader.nextInt();
        arr = new int[n];
        pos = new int[n+1];
        for(int i=0;i<n;++i) {
            arr[i] = reader.nextInt();
            pos[arr[i]] = i;
        }
        int sz = (int)pow(2, ceil(log(n)/log(2))+1);
        tree = new int[sz];
        build(1,0,n-1);
        writer.println(f(0,n-1));
    }
    static long f(int l, int r) {
        if(l>=r) {
            return 0;
        }
        int ans = 0, max = query(l,r), idx = pos[max];
        if(idx-1-l+1<r-(idx+1)+1) {
            for(int i=l;i<idx;++i) {
                int req = max - arr[i];
                if(req>0 && pos[req]>=idx+1 && pos[req]<=r) {
                    ans++;
                }
            }
        }
        else {
            for(int i=idx+1;i<=r;++i) {
                int req = max - arr[i];
                if(req>0 && pos[req]>=l && pos[req]<idx) {
                    ans++;
                }
            }
        }
        return ans+f(l, idx-1) + f(idx+1,r);
    }
    static void build(int treein,int low,int high)
    {
        if(low==high)
            tree[treein] = arr[low];
        else
        {
            int mid = (low+high)>>1;
            build(2*treein,low,mid);
            build(2*treein+1,mid+1,high);
            tree[treein] = max(tree[2*treein],tree[2*treein+1]);
        }
    }
    static void update(int treein,int low,int high,int idx,int val)
    {
        if(low==high)
            tree[treein] = val;
        else
        {
            int mid = (low+high)>>1;
            if(idx<=mid)
                update(2*treein,low,mid,idx,val);
            else update(2*treein+1,mid+1,high,idx,val);
            tree[treein] = max(tree[2*treein],tree[2*treein+1]);
        }
    }
    static int query(int treein,int low,int high,int l,int r)
    {
        if(l<=low && high<=r)
            return tree[treein];
        if(low>r || high<l)
            return 0;
        int mid = (low+high)>>1;
        return max(query(2*treein,low,mid,l,r),query(2*treein+1,mid+1,high,l,r));
    }
    static int query(int l,int r)
    {
        return query(1,0,n-1,l,r);
    }
    static void update(int idx,int val)
    {
        update(1,0,n-1,idx,val);
    }
}