#include<bits/stdc++.h>
using namespace std;

const int MAXN = 300010;

int n, a[MAXN];

bool Check(int l, int r)
{
	int mn = MAXN, mx = 0;
	for(int i = l; i <= r; ++i)
	{
		mn = min(mn, a[i]);
		mx = max(mx, a[i]);
	}
	if(mn != l || mx != r) return 0;
	int x = 0, y = 0;
	for(int i = l; i <= r; i += 2)
	{
		if(a[i] > i)
		{
			if(a[i] > x) x = a[i];
			else return 0;
		}
		else if(a[i] < i)
		{
			if(a[i] > y) y = a[i];
			else return 0;
		}
		else return 0;
	}
	return 1;
}

int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	for(int i = 1; i <= n; ++i)
	{
		if(a[i] == i) continue;
		int j = i;
		while(j <= n - 2)
		{
			if(a[j + 1] != j + 1) break;
			if(a[j + 2] == j + 2) break;
			j += 2;
		}
		if(j == i || !Check(i, j))
		{
			puts("No");
			return 0;
		}
		i = j;
	}
	puts("Yes");
	return 0;
}