#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int MAXN = 500005;
const int mod = 1e9 + 7;
#define sz(v) ((int)v.size())

int n, a[MAXN];

int main(){
	scanf("%d",&n);
	for(int i=1; i<=n; i++) scanf("%d",&a[i]);
	vector<int> v;
	for(int i=1; i<=n; i++){
		if(a[i] != i) v.push_back(i);
	}
	for(int i=0; i<v.size(); ){
		int e = i + 1;
		while(e < v.size() && v[e] - v[e - 1] == 2) e++;
		if(e - i == 1){
			puts("No");
			return 0;
		}
		vector<int> toLeft, toRight;
		for(int j=v[i]; j<=v[e-1]; j++){
			if(a[j] < j) toLeft.push_back(a[j]);
			if(a[j] > j) toRight.push_back(a[j]);
		}
		if(!is_sorted(toLeft.begin(), toLeft.end()) ||
		   !is_sorted(toRight.begin(), toRight.end())){
		   	puts("No");
		   	return 0;
		}
		sort(a + v[i], a + v[e-1] + 1);
		for(int j=v[i]; j<=v[e-1]; j++){
			if(a[j] != j){
				puts("No");
				return 0;
			}
		}
		i = e;
	}
	puts("Yes");
}
