#include <bits/stdc++.h>
using namespace std;
map<long long, vector<long long> > M;
set<long long> S;
const long long N = 1000001;
long long n, a[1000001], f[N];
void upd(long long i, long long mx) {
  for (; i > 0; i -= (i & -i)) {
    f[i] = max(f[i], mx);
  }
}
long long get(long long i) {
  long long mx = -N;
  for (; i < N; i += (i & -i)) mx = max(mx, f[i]);
  return mx;
}
signed main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  vector<long long> v;
  for (long long i = 1; i <= n; ++i) {
    cin >> a[i];
    v.push_back(a[i]);
  }
  sort(v.begin(), v.end());
  v.resize(unique(v.begin(), v.end()) - v.begin());
  for (long long i = 1; i <= n; ++i) {
    a[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin() + 1;
  }
  for (long long i = 1; i <= n; ++i) {
    if ((abs(get(a[i]) - i) - 1) % 2 != 0) {
      cout << "NO";
      return 0;
    }
    upd(a[i], i);
  }
  for (long long i = 0; i < N; ++i) f[i] = -(n + 1);
  for (long long i = n; i >= 1; --i) {
    if ((abs(abs(get(a[i])) - i) - 1) % 2 != 0) {
      cout << "NO";
      return 0;
    }
    upd(a[i], -i);
  }
  cout << "YES";
  return 0;
}
