#include <bits/stdc++.h>
using namespace std;
const int INF = 1e+9;
const long long INFLL = 1e+17;
const long long MOD = 1e+9 + 7;
int N;
int a[100010];
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) cin >> a[i];
  bool f = true;
  if (N % 3 == 0) {
    for (int i = 0; i < N; i++) {
      if (i % 3 == 0) {
        if (a[i] != a[0]) {
          f = false;
          break;
        }
      } else if (i % 3 == 1) {
        if (a[i] != a[1]) {
          f = false;
          break;
        }
      } else {
        if (a[i] != a[2]) {
          f = false;
          break;
        }
      }
    }
  } else {
    for (int i = 0; i < N; i++) {
      if (a[i] != a[0]) {
        f = false;
        break;
      }
    }
  }
  if (f)
    cout << "Yes"
         << "\n";
  else
    cout << "No"
         << "\n";
  return 0;
}
