#include <bits/stdc++.h>
void RI() {}
template <typename... T>
void RI(int& head, T&... tail) {
  scanf("%d", &head);
  RI(tail...);
}
using namespace std;
int arr[100005];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> arr[i];
  bool ans = true;
  for (int i = 3; i < n; i++) {
    if (arr[i] != arr[i - 3]) {
      ans = false;
      break;
    }
  }
  if (ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
