Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.

The current state of the wall can be respresented by a sequence a of n integers, with a_i being the height of the i-th part of the wall.

Vova can only use 2 × 1 bricks to put in the wall (he has infinite supply of them, however).

Vova can put bricks only horizontally on the neighbouring parts of the wall of equal height. It means that if for some i the current height of part i is the same as for part i + 1, then Vova can put a brick there and thus increase both heights by 1. Obviously, Vova can't put bricks in such a way that its parts turn out to be off the borders (to the left of part 1 of the wall or to the right of part n of it).

Note that Vova can't put bricks vertically.

Vova is a perfectionist, so he considers the wall completed when:

  * all parts of the wall has the same height; 
  * the wall has no empty spaces inside it. 



Can Vova complete the wall using any amount of bricks (possibly zero)?

Input

The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of parts in the wall.

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the initial heights of the parts of the wall.

Output

Print "YES" if Vova can complete the wall using any amount of bricks (possibly zero).

Print "NO" otherwise.

Examples

Input


5
2 1 1 2 5


Output


YES


Input


3
4 5 3


Output


NO


Input


2
10 10


Output


YES

Note

In the first example Vova can put a brick on parts 2 and 3 to make the wall [2, 2, 2, 2, 5] and then put 3 bricks on parts 1 and 2 and 3 bricks on parts 3 and 4 to make it [5, 5, 5, 5, 5].

In the second example Vova can put no bricks in the wall.

In the third example the wall is already complete.
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
	public static void solve(FastIO io) {
		int N = io.nextInt();
		int[] A = io.nextIntArray(N);

		HeightMap hts = new HeightMap();
		for (int i = 0; i < N; ++i) {
			hts.insert(A[i], i);
		}

		TreeSet<Integer> seen = new TreeSet<>();
		seen.add(-1);
		seen.add(N);
		for (Map.Entry<Integer, ArrayList<Integer>> kvp : hts.entrySet()) {
			int h = kvp.getKey();
			ArrayList<Integer> idxs = kvp.getValue();
			for (int i : idxs) {
				seen.add(i);
			}
			for (int i : idxs) {
				int lo = seen.lower(i);
				int hi = seen.higher(i);
				if (((i - lo - 1) & 1) != 0 || ((hi - i - 1) & 1) != 0) {
					// System.out.format("fail at h = %d, i = %d, lo = %d, hi = %d, seen = %s\n", h, i, lo, hi, seen);
					io.println("NO");
					return;
				}
			}
		}
		io.println("YES");
	}

	private static class HeightMap extends TreeMap<Integer, ArrayList<Integer>> {
		public HeightMap() {
			super(Collections.reverseOrder());
		}

		private ArrayList<Integer> createIfEmpty(int k) {
			if (containsKey(k)) {
				return get(k);
			}
			ArrayList<Integer> lst = new ArrayList<>();
			put(k, lst);
			return lst;
		}

		private void insert(int k, int v) {
			createIfEmpty(k).add(v);
		}
	}

	public static class FastIO {
		private InputStream reader;
		private PrintWriter writer;

		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastIO(InputStream r, OutputStream w) {
			reader = r;
			writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(w)));
		}

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

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(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 (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n) {
			return nextIntArray(n, 0);
		}

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

		public long[] nextLongArray(int n) {
			return nextLongArray(n, 0);
		}

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

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

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

		public void print(Object... objects) {
			for (int i = 0; i < objects.length; i++) {
				if (i != 0) {
					writer.print(' ');
				}
				writer.print(objects[i]);
			}
		}

		public void println(Object... objects) {
			print(objects);
			writer.println();
		}

		public void printArray(int[] arr) {
			for (int i = 0; i < arr.length; i++) {
				if (i != 0) {
					writer.print(' ');
				}
				writer.print(arr[i]);
			}
		}

		public void printArray(long[] arr) {
			for (int i = 0; i < arr.length; i++) {
				if (i != 0) {
					writer.print(' ');
				}
				writer.print(arr[i]);
			}
		}

		public void printlnArray(int[] arr) {
			printArray(arr);
			writer.println();
		}

		public void printlnArray(long[] arr) {
			printArray(arr);
			writer.println();
		}

		public void printf(String format, Object... args) {
			print(String.format(format, args));
		}

		public void flush() {
			writer.flush();
		}
	}

	public static void main(String[] args) {
		FastIO io = new FastIO(System.in, System.out);
		solve(io);
		io.flush();
	}
}