import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);

//		ArrayList<Integer> p=new ArrayList<Integer>();
		int N = scanner.nextInt();
		int p[] = new int[N];
		int counter=0;

		for(int i=0;i<N;i++) {
			p[i]=scanner.nextInt();
		}

		if(p[0]-p[1]!=-1) counter++;
//		System.out.println(counter);

		for(int i=1;i<N-2;i++) {
			if(p[i]-p[i+1]!=-1) {
				counter++;
				i++;
			}
		}

		if(p[N-2]-p[N-1]!=-1) counter++;
//		System.out.println(counter);

//		System.out.println(counter);
		if(counter==0||counter==2) System.out.println("YES");
		else System.out.println("NO");

		scanner.close();


	}

} import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);

//		ArrayList<Integer> p=new ArrayList<Integer>();
		int N = scanner.nextInt();
		int p[] = new int[N];
		int counter=0;

		for(int i=0;i<N;i++) {
			p[i]=scanner.nextInt();
		}

		if(p[0]-p[1]!=-1) counter++;
//		System.out.println(counter);

		for(int i=1;i<N-2;i++) {
			if(p[i]-p[i+1]!=-1) {
				counter++;
				i++;
			}
		}

		if(p[N-2]-p[N-1]!=-1) counter++;
//		System.out.println(counter);

//		System.out.println(counter);
		if(counter==0||counter==2) System.out.println("YES");
		else System.out.println("NO");

		scanner.close();


	}

} Main public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);

//		ArrayList<Integer> p=new ArrayList<Integer>();
		int N = scanner.nextInt();
		int p[] = new int[N];
		int counter=0;

		for(int i=0;i<N;i++) {
			p[i]=scanner.nextInt();
		}

		if(p[0]-p[1]!=-1) counter++;
//		System.out.println(counter);

		for(int i=1;i<N-2;i++) {
			if(p[i]-p[i+1]!=-1) {
				counter++;
				i++;
			}
		}

		if(p[N-2]-p[N-1]!=-1) counter++;
//		System.out.println(counter);

//		System.out.println(counter);
		if(counter==0||counter==2) System.out.println("YES");
		else System.out.println("NO");

		scanner.close();


	} main {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);

//		ArrayList<Integer> p=new ArrayList<Integer>();
		int N = scanner.nextInt();
		int p[] = new int[N];
		int counter=0;

		for(int i=0;i<N;i++) {
			p[i]=scanner.nextInt();
		}

		if(p[0]-p[1]!=-1) counter++;
//		System.out.println(counter);

		for(int i=1;i<N-2;i++) {
			if(p[i]-p[i+1]!=-1) {
				counter++;
				i++;
			}
		}

		if(p[N-2]-p[N-1]!=-1) counter++;
//		System.out.println(counter);

//		System.out.println(counter);
		if(counter==0||counter==2) System.out.println("YES");
		else System.out.println("NO");

		scanner.close();


	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int p[] = new int[N]; p new int[N] N int counter=0; counter 0 for(int i=0;i<N;i++) {
			p[i]=scanner.nextInt();
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			p[i]=scanner.nextInt();
		} {
			p[i]=scanner.nextInt();
		} p[i]=scanner.nextInt() p[i] p i scanner.nextInt() scanner.nextInt scanner if(p[0]-p[1]!=-1) counter++; p[0]-p[1]!=-1 p[0]-p[1] p[0] p 0 p[1] p 1 -1 1 counter++ counter for(int i=1;i<N-2;i++) {
			if(p[i]-p[i+1]!=-1) {
				counter++;
				i++;
			}
		} int i=1; int i=1; i 1 i<N-2 i N-2 N 2 i++ i++ i {
			if(p[i]-p[i+1]!=-1) {
				counter++;
				i++;
			}
		} {
			if(p[i]-p[i+1]!=-1) {
				counter++;
				i++;
			}
		} if(p[i]-p[i+1]!=-1) {
				counter++;
				i++;
			} p[i]-p[i+1]!=-1 p[i]-p[i+1] p[i] p i p[i+1] p i+1 i 1 -1 1 {
				counter++;
				i++;
			} counter++ counter i++ i if(p[N-2]-p[N-1]!=-1) counter++; p[N-2]-p[N-1]!=-1 p[N-2]-p[N-1] p[N-2] p N-2 N 2 p[N-1] p N-1 N 1 -1 1 counter++ counter if(counter==0||counter==2) System.out.println("YES");
		else System.out.println("NO"); counter==0||counter==2 counter==0 counter 0 counter==2 counter 2 System.out.println("YES") System.out.println System.out System System.out "YES" System.out.println("NO") System.out.println System.out System System.out "NO" scanner.close() scanner.close scanner String[] args args public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);

//		ArrayList<Integer> p=new ArrayList<Integer>();
		int N = scanner.nextInt();
		int p[] = new int[N];
		int counter=0;

		for(int i=0;i<N;i++) {
			p[i]=scanner.nextInt();
		}

		if(p[0]-p[1]!=-1) counter++;
//		System.out.println(counter);

		for(int i=1;i<N-2;i++) {
			if(p[i]-p[i+1]!=-1) {
				counter++;
				i++;
			}
		}

		if(p[N-2]-p[N-1]!=-1) counter++;
//		System.out.println(counter);

//		System.out.println(counter);
		if(counter==0||counter==2) System.out.println("YES");
		else System.out.println("NO");

		scanner.close();


	}

} public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);

//		ArrayList<Integer> p=new ArrayList<Integer>();
		int N = scanner.nextInt();
		int p[] = new int[N];
		int counter=0;

		for(int i=0;i<N;i++) {
			p[i]=scanner.nextInt();
		}

		if(p[0]-p[1]!=-1) counter++;
//		System.out.println(counter);

		for(int i=1;i<N-2;i++) {
			if(p[i]-p[i+1]!=-1) {
				counter++;
				i++;
			}
		}

		if(p[N-2]-p[N-1]!=-1) counter++;
//		System.out.println(counter);

//		System.out.println(counter);
		if(counter==0||counter==2) System.out.println("YES");
		else System.out.println("NO");

		scanner.close();


	}

} Main
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);

//		ArrayList<Integer> p=new ArrayList<Integer>();
		int N = scanner.nextInt();
		int p[] = new int[N];
		int counter=0;

		for(int i=0;i<N;i++) {
			p[i]=scanner.nextInt();
		}

		if(p[0]-p[1]!=-1) counter++;
//		System.out.println(counter);

		for(int i=1;i<N-2;i++) {
			if(p[i]-p[i+1]!=-1) {
				counter++;
				i++;
			}
		}

		if(p[N-2]-p[N-1]!=-1) counter++;
//		System.out.println(counter);

//		System.out.println(counter);
		if(counter==0||counter==2) System.out.println("YES");
		else System.out.println("NO");

		scanner.close();


	}

}
