#include <bits/stdc++.h>
using namespace std;
int T[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
           31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
           31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int W[24];
bool ok(int n) {
  bool l = false;
  for (int i = 0; i < 12; i++) {
    bool f = true;
    for (int j = 0; j < n; j++) {
      if (T[i + j] != W[j]) {
        if ((i + j) % 12 == 1 && W[j] == 29 && !l) {
          l = true;
          continue;
        } else
          f = false;
      }
    }
    if (f == true) return true;
  }
  return false;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &W[i]);
  if (ok(n))
    printf("YES\n");
  else
    printf("NO\n");
}
