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

public class D implements Runnable {
	FastReader scn;
	PrintWriter out;
	String INPUT = "";

	void solve() {
		int n = scn.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = scn.nextInt();
		}

		st = new int[4 * n][2];
		build(0, 0, n - 1, arr);
		func(0, n - 1, n);
		out.println(ans);
	}

	int ans = 0;

	LongHashCounter func(int l, int r, int n) {
		if (l > r) {
			return new LongHashCounter();
		}
		
		int[] rv = query(0, 0, n - 1, l, r);
		
		int max = rv[0];
		int m = rv[1];

		LongHashCounter a = func(l, m - 1, n);
		LongHashCounter b = func(m + 1, r, n);

		if (a.size > b.size) {
			LongHashCounter c = a;
			a = b;
			b = c;
		}

		for (int i = a.next(0); i < a.scale; i = a.next(i + 1)) {
			if (b.containsKey(max - a.keys[i])) {
				ans++;
			}
		}
		
		for (int i = a.next(0); i < a.scale; i = a.next(i + 1)) {
			b.put(a.keys[i], 1);
		}
		b.put(max, 1);

		return b;
	}
	
	public class LongHashCounter {
		public long[] keys;
		public int[] allocated;
		private int scale = 1 << 2;
		private int rscale = 1 << 1;
		private int mask = scale - 1;
		public int size = 0;

		public LongHashCounter() {
			allocated = new int[scale];
			Arrays.fill(allocated, NG);
			keys = new long[scale];
		}

		// if value is NG, entry is removed. (e.g. 0)
		private static final int NG = 0;

		public boolean containsKey(long x) {
			int pos = h(x) & mask;
			while (allocated[pos] != NG) {
				if (x == keys[pos])
					return true;
				pos = pos + 1 & mask;
			}
			return false;
		}

		public int get(long x) {
			int pos = h(x) & mask;
			while (allocated[pos] != NG) {
				if (x == keys[pos])
					return allocated[pos];
				pos = pos + 1 & mask;
			}
			return NG;
		}

		public int put(long x, int v) {
			int pos = h(x) & mask;
			while (allocated[pos] != NG) {
				if (x == keys[pos]) {
					int oldval = allocated[pos];
					allocated[pos] = v;
					return oldval;
				}
				pos = pos + 1 & mask;
			}
			if (size == rscale) {
				resizeAndPut(x, v);
			} else {
				keys[pos] = x;
				allocated[pos] = v;
			}
			size++;
			return NG;
		}

		public int inc(long x, int v) {
			int pos = h(x) & mask;
			while (allocated[pos] != NG) {
				if (x == keys[pos]) {
					allocated[pos] += v;
					return allocated[pos];
				}
				pos = pos + 1 & mask;
			}
			if (size == rscale) {
				resizeAndPut(x, v);
			} else {
				keys[pos] = x;
				allocated[pos] = v;
			}
			size++;
			return v;
		}

		public boolean remove(long x) {
			int pos = h(x) & mask;
			while (allocated[pos] != NG) {
				if (x == keys[pos]) {
					size--;
					// take last and fill rmpos
					int last = pos;
					pos = pos + 1 & mask;
					while (allocated[pos] != NG) {
						int lh = h(keys[pos]) & mask;
						// lh <= last < pos
						if (lh <= last && last < pos || pos < lh && lh <= last || last < pos && pos < lh) {
							keys[last] = keys[pos];
							allocated[last] = allocated[pos];
							last = pos;
						}
						pos = pos + 1 & mask;
					}
					keys[last] = 0;
					allocated[last] = NG;

					return true;
				}
				pos = pos + 1 & mask;
			}
			return false;
		}

		private void resizeAndPut(long x, int v) {
			int nscale = scale << 1;
			int nrscale = rscale << 1;
			int nmask = nscale - 1;
			int[] nallocated = new int[nscale];
			Arrays.fill(nallocated, NG);
			long[] nkeys = new long[nscale];
			for (int i = next(0); i < scale; i = next(i + 1)) {
				long y = keys[i];
				int pos = h(y) & nmask;
				while (nallocated[pos] != NG)
					pos = pos + 1 & nmask;
				nkeys[pos] = y;
				nallocated[pos] = allocated[i];
			}
			{
				int pos = h(x) & nmask;
				while (nallocated[pos] != NG)
					pos = pos + 1 & nmask;
				nkeys[pos] = x;
				nallocated[pos] = v;
			}
			allocated = nallocated;
			keys = nkeys;
			scale = nscale;
			rscale = nrscale;
			mask = nmask;
		}

		public int next(int itr) {
			while (itr < scale && allocated[itr] == NG)
				itr++;
			return itr;
		}

		private int h(long x) {
			x ^= x >>> 33;
			x *= 0xff51afd7ed558ccdL;
			x ^= x >>> 33;
			x *= 0xc4ceb9fe1a85ec53L;
			x ^= x >>> 33;
			return (int) x;
		}

		@Override
		public String toString() {
			StringBuilder sb = new StringBuilder();
			for (int i = next(0); i < scale; i = next(i + 1)) {
				sb.append(",");
				sb.append(keys[i] + ":" + allocated[i]);
			}
			return sb.length() == 0 ? "" : sb.substring(1);
		}
	}

	int[][] st;
	
	int[] query(int ind, int l, int r, int si, int li) {
		if(li < l || si > r) {
			return new int[2];
		}
		
		if(l >= si && r <= li) {
			return st[ind];
		}
		
		int m = (l + r) >> 1;
		int x = 2 * ind + 1, y = x + 1;
		
		int[] a = query(x, l, m, si, li);
		int[] b = query(y, m + 1, r, si, li);
		
		if(a[0] < b[0]) {
			a = b;
		}
		
		return a;
	}
	
	void build(int ind, int l, int r, int[] arr) {
		if(l == r) {
			st[ind][0] = arr[l];
			st[ind][1] = l;
			return;
		}
		
		int m = (l + r) >> 1;
		int x = 2 * ind + 1, y = x + 1;
		build(x, l, m, arr);
		build(y, m + 1, r, arr);
		
		if(st[x][0] < st[y][0]) {
			x = y;
		}
		
		st[ind][0] = st[x][0];
		st[ind][1] = st[x][1];
	}

	public void run() {
		long time = System.currentTimeMillis();
		boolean oj = System.getProperty("ONLINE_JUDGE") != null;
		out = new PrintWriter(System.out);
		scn = new FastReader(oj);
		solve();
		out.flush();
		if (!oj) {
			System.out.println(Arrays.deepToString(new Object[] { System.currentTimeMillis() - time + " ms" }));
		}
	}

	public static void main(String[] args) {
		new Thread(null, new D(), "Main", 1 << 26).start();
	}

	class FastReader {
		InputStream is;

		public FastReader(boolean onlineJudge) {
			is = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		}

		byte[] inbuf = new byte[1024];
		public int lenbuf = 0, ptrbuf = 0;

		int readByte() {
			if (lenbuf == -1)
				throw new InputMismatchException();
			if (ptrbuf >= lenbuf) {
				ptrbuf = 0;
				try {
					lenbuf = is.read(inbuf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return -1;
			}
			return inbuf[ptrbuf++];
		}

		boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		int skip() {
			int b;
			while ((b = readByte()) != -1 && isSpaceChar(b))
				;
			return b;
		}

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

		char nextChar() {
			return (char) skip();
		}

		String next() {
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		String nextLine() {
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while ((!isSpaceChar(b) || b == ' ')) { // when nextLine, (isSpaceChar(b) && b != ' ')
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		char[] next(int n) {
			char[] buf = new char[n];
			int b = skip(), p = 0;
			while (p < n && !(isSpaceChar(b))) {
				buf[p++] = (char) b;
				b = readByte();
			}
			return n == p ? buf : Arrays.copyOf(buf, p);
		}

		int nextInt() {
			int num = 0, b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		long nextLong() {
			long num = 0;
			int b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		char[][] nextMatrix(int n, int m) {
			char[][] map = new char[n][];
			for (int i = 0; i < n; i++)
				map[i] = next(m);
			return map;
		}

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

		long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		int[][] next2DInt(int n, int m) {
			int[][] arr = new int[n][];
			for (int i = 0; i < n; i++) {
				arr[i] = nextIntArray(m);
			}
			return arr;
		}

		long[][] next2DLong(int n, int m) {
			long[][] arr = new long[n][];
			for (int i = 0; i < n; i++) {
				arr[i] = nextLongArray(m);
			}
			return arr;
		}

		int[] shuffle(int[] arr) {
			Random r = new Random();
			for (int i = 1, j; i < arr.length; i++) {
				j = r.nextInt(i);
				int c = arr[i];
				arr[i] = arr[j];
				arr[j] = c;
			}
			return arr;
		}

		long[] shuffle(long[] arr) {
			Random r = new Random();
			for (int i = 1, j; i < arr.length; i++) {
				j = r.nextInt(i);
				long c = arr[i];
				arr[i] = arr[j];
				arr[j] = c;
			}
			return arr;
		}

		int[] uniq(int[] arr) {
			arr = scn.shuffle(arr);
			Arrays.sort(arr);
			int[] rv = new int[arr.length];
			int pos = 0;
			rv[pos++] = arr[0];
			for (int i = 1; i < arr.length; i++) {
				if (arr[i] != arr[i - 1]) {
					rv[pos++] = arr[i];
				}
			}
			return Arrays.copyOf(rv, pos);
		}

		long[] uniq(long[] arr) {
			arr = scn.shuffle(arr);
			Arrays.sort(arr);
			long[] rv = new long[arr.length];
			int pos = 0;
			rv[pos++] = arr[0];
			for (int i = 1; i < arr.length; i++) {
				if (arr[i] != arr[i - 1]) {
					rv[pos++] = arr[i];
				}
			}
			return Arrays.copyOf(rv, pos);
		}

		int[] reverse(int[] arr) {
			int l = 0, r = arr.length - 1;
			while (l < r) {
				arr[l] = arr[l] ^ arr[r];
				arr[r] = arr[l] ^ arr[r];
				arr[l] = arr[l] ^ arr[r];
				l++;
				r--;
			}
			return arr;
		}

		long[] reverse(long[] arr) {
			int l = 0, r = arr.length - 1;
			while (l < r) {
				arr[l] = arr[l] ^ arr[r];
				arr[r] = arr[l] ^ arr[r];
				arr[l] = arr[l] ^ arr[r];
				l++;
				r--;
			}
			return arr;
		}

		int[] compress(int[] arr) {
			int n = arr.length;
			int[] rv = Arrays.copyOf(arr, n);
			rv = uniq(rv);
			for (int i = 0; i < n; i++) {
				arr[i] = Arrays.binarySearch(rv, arr[i]);
			}
			return arr;
		}

		long[] compress(long[] arr) {
			int n = arr.length;
			long[] rv = Arrays.copyOf(arr, n);
			rv = uniq(rv);
			for (int i = 0; i < n; i++) {
				arr[i] = Arrays.binarySearch(rv, arr[i]);
			}
			return arr;
		}
	}
}