#include <bits/stdc++.h>
using namespace std;
int ly1[] = {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 ly2[] = {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 ly3[] = {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 nly[] = {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 main() {
  int n;
  int i, j;
  cin >> n;
  int ara[n + 3];
  for (i = 0; i < n; i++) cin >> ara[i];
  int flg = 0;
  int cnt = 0;
  for (i = 0, cnt = 0; i < 36; i++, cnt++) {
    int pos = i % 36;
    for (j = 0; j < n; j++) {
      if (ara[j] != ly1[(i + j) % 36]) {
        flg = 1;
        break;
      }
      if (j == n - 1) {
        cout << "YES";
        return 0;
      }
    }
  }
  for (i = 0, cnt = 0; i < 36; i++, cnt++) {
    int pos = i % 36;
    for (j = 0; j < n; j++) {
      if (ara[j] != ly2[(i + j) % 36]) {
        flg = 1;
        break;
      }
      if (j == n - 1) {
        cout << "YES";
        return 0;
      }
    }
  }
  for (i = 0, cnt = 0; i < 36; i++, cnt++) {
    int pos = i % 36;
    for (j = 0; j < n; j++) {
      if (ara[j] != ly3[(i + j) % 36]) {
        flg = 1;
        break;
      }
      if (j == n - 1) {
        cout << "YES";
        return 0;
      }
    }
  }
  for (i = 0, cnt = 0; i < 36; i++, cnt++) {
    int pos = i % 36;
    for (j = 0; j < n; j++) {
      if (ara[j] != nly[(i + j) % 36]) {
        flg = 1;
        break;
      }
      if (j == n - 1) {
        cout << "YES";
        return 0;
      }
    }
  }
  cout << "NO";
}
