#include <bits/stdc++.h>
using namespace std;
int n;
int a1[50] = {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, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int a2[50] = {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, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int a3[50] = {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, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int a4[50] = {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, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int b[30];
map<int, int> mp;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < 48; i++) {
    int flag = 1;
    for (int j = 0; j < n; j++) {
      if (a1[i + j] != b[j]) {
        flag = 0;
        break;
      }
    }
    if (flag) {
      printf("YES\n");
      return 0;
    }
  }
  for (int i = 0; i < 48; i++) {
    int flag = 1;
    for (int j = 0; j < n; j++) {
      if (a2[i + j] != b[j]) {
        flag = 0;
        break;
      }
    }
    if (flag) {
      printf("YES\n");
      return 0;
    }
  }
  for (int i = 0; i < 48; i++) {
    int flag = 1;
    for (int j = 0; j < n; j++) {
      if (a3[i + j] != b[j]) {
        flag = 0;
        break;
      }
    }
    if (flag) {
      printf("YES\n");
      return 0;
    }
  }
  for (int i = 0; i < 48; i++) {
    int flag = 1;
    for (int j = 0; j < n; j++) {
      if (a4[i + j] != b[j]) {
        flag = 0;
        break;
      }
    }
    if (flag) {
      printf("YES\n");
      return 0;
    }
  }
  printf("NO\n");
  return 0;
}
