#include <bits/stdc++.h>
using namespace std;
const int MAXN = 30;
int normal[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int leap[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int type1[100] = {0,  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 type2[100] = {0,  31, 29, 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 type3[100] = {0,  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,
                  29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int type4[100] = {0,  31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
                  31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31,
                  28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int n;
int num[MAXN];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &num[i]);
  bool ans = 0;
  for (int i = 0; i + n <= 36; i++) {
    bool jud1 = 1, jud2 = 1, jud3 = 1, jud4 = 1;
    for (int j = 1; j <= n; j++) {
      if (num[j] != type1[i + j]) jud1 = 0;
      if (num[j] != type2[i + j]) jud2 = 0;
      if (num[j] != type3[i + j]) jud3 = 0;
      if (num[j] != type4[i + j]) jud4 = 0;
    }
    ans |= jud1 | jud2 | jud3 | jud4;
  }
  if (ans)
    puts("YES");
  else
    puts("NO");
  return 0;
}
