#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, k = 0, zerof = 0;
  cin >> N;
  vector<int> a(N);
  vector<int> num(N);
  vector<int> temp = {0, 1, 1};
  if (N % 3 != 0) {
    cout << "No" << endl;
    return 0;
  }
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  num[k] = a[0];
  for (int i = 1; i < N; i++) {
    if (num[k] == 0) zerof = 1;
    if (a[i] != num[k]) num[++k] = a[i];
  }
  if (num[k] == 0) zerof = 1;
  if (k > 2) {
    cout << "No" << endl;
    return 0;
  }
  if (k == 0 && zerof) {
    cout << "Yes" << endl;
    return 0;
  } else {
    cout << "No" << endl;
    return 0;
  }
  if (k == 1) {
    if (zerof) {
      for (int i = 0; i < N; i++) {
        if (a[i] != num[temp[i % 3]]) {
          cout << "No" << endl;
          return 0;
        }
      }
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  } else {
    if (!zerof) {
      for (int i = 0; i < N; i++) {
        if (a[i] != num[i % 3]) {
          cout << "No" << endl;
          return 0;
        }
      }
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}
