#include <bits/stdc++.h>
using namespace std;
int test[25];
int leap[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int ordin[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool isright(int tot) {
  int i, j, k;
  for (i = 0; i < 12; i++) {
    int beg = i;
    for (j = 0, k = 0; j < tot; j++, k++) {
      if (ordin[(beg + k) % 12] != test[j]) break;
    }
    if (j == tot) return true;
  }
  return false;
}
int main() {
  bool isleap = false;
  bool flag = true;
  int leapnum, n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &test[i]);
    if (test[i] == 29) {
      isleap = true;
      leapnum = i;
    }
  }
  if (!isleap && isright(n)) {
    printf("Yes\n");
  } else if (isleap) {
    for (int i = leapnum + 1, j = 1; i < n; i++, j++) {
      if (test[i] != ordin[(1 + j) % 12]) {
        flag = false;
        break;
      }
    }
    for (int i = leapnum - 1, j = 1; i >= 0; i--, j++) {
      if (test[i] != ordin[(1 - j + 24) % 12]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      printf("Yes\n");
    } else
      printf("No\n");
  } else {
    printf("No\n");
  }
}
