#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
    --p[i];
  }
  bool valid = true;
  for (int l = 0, r = 1; l < n; l = r++) {
    while (r + 1 < n && p[r] == r && p[r + 1] != r + 1) {
      r += 2;
    }
    int ll = n - 1, rr = 0;
    for (int i = l; i < r; ++i) {
      ll = min(ll, p[i]);
      rr = max(rr, p[i]);
    }
    if (ll != l || rr != r - 1) {
      valid = false;
      break;
    }
    int foo = -1, bar = -1;
    for (int i = l; i < r; i += 2) {
      if (i > p[i]) {
        if (foo > p[i]) {
          valid = false;
          break;
        }
        foo = p[i];
      } else {
        if (bar > p[i]) {
          valid = false;
          break;
        }
        bar = p[i];
      }
    }
    if (!valid) {
      break;
    }
  }
  cout << (valid ? "Yes" : "No") << "\n";
  return 0;
}
