#include <bits/stdc++.h>
using namespace std;
const int MAX = 510000;
const int MOD = 1000000007;
int main() {
  long long N;
  cin >> N;
  long long i, j, k, l;
  vector<long long> a(N);
  for (int i = 0; i < N; i++) cin >> a[i];
  bool bi = true;
  for (i = 0; i < N - 3; i += 3) {
    if (a[i] != a[i + 3]) bi = false;
  }
  for (i = 1; i < N - 3; i += 3) {
    if (a[i] != a[i + 3]) bi = false;
  }
  for (i = 2; i < N - 3; i += 3) {
    if (a[i] != a[i + 3]) bi = false;
  }
  if (bi)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
