#include <bits/stdc++.h>
using namespace std;
int year[150] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int num[30];
bool chk(int a) {
  int i, j;
  for (i = 1; i <= 144 - a + 1; i++) {
    for (j = 1; j <= a; j++) {
      if (num[j] != year[i + j - 1]) break;
    }
    if (j > a) return true;
  }
  return false;
}
int main() {
  int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q;
  for (i = 13; i <= 144; i++) {
    year[i] = year[i - 12];
  }
  year[2] = year[98] = 29;
  scanf("%d", &a);
  for (i = 1; i <= a; i++) {
    scanf("%d", &num[i]);
  }
  if (chk(a))
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
