#include <bits/stdc++.h>
int main() {
  int n, i, d[100010];
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &d[i]);
  for (i = 3; i < n; i++) {
    if (d[i - 3] - d[i]) goto END;
  }
  printf("Yes\n");
  return 0;
END:;
  printf("No\n");
  return 0;
}
