#include<bits/stdc++.h>
using namespace std;
int n, num[300007];
int read()
{
	int num = 0;
	char c = getchar();
	while (c < '0' || c>'9')c = getchar();
	while (c >= '0' && c <= '9')num = num * 10 + c - '0', c = getchar();
	return num;
}
int check(int l, int r)
{
	int lst = 0, rst = 0;
	for (int i = l; i <= r; i++)
		if (num[i] < i)
		{
			if (num[i]<l || num[i]>r || lst > num[i])return 0;
			lst = num[i];
		}
		else if (num[i] > i)
		{
			if (num[i]<l || num[i]>r || rst > num[i])return 0;
			rst = num[i];
		}
	return 1;
}
int main()
{
	n = read();
	for (int i = 1; i <= n; i++)
		num[i] = read();
	for (int i = 2; i < n; i++)
		if (num[i - 1] != i - 1 && num[i] != i && num[i + 1] != i + 1) { cout << "No" << endl; return 0; }
	for (int i = 1; i <= n; i++)
		if (num[i] != i)
		{
			int l = i, now = 1;
			while (((num[i] == i) ^ now) && i <= n)i++, now ^= 1;
			i--;
			if (!check(l, i)) { cout << "No" << endl; return 0; }
		}
	cout << "Yes" << endl;
	return 0;
}