#include <bits/stdc++.h>
using namespace std;
int a[36] = {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 b[36] = {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 c[36] = {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 d[36] = {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 m[36];
int main() {
  int n, key = 0;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> m[i];
  for (int i = 0; i < 36; i++) {
    if (m[0] == a[i]) {
      key = 0;
      for (int j = 0; j < n; j++) {
        if (i + j >= 36) break;
        if (m[j] == a[i + j]) key++;
      }
      if (key == n) {
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  for (int i = 0; i < 36; i++) {
    if (m[0] == b[i]) {
      key = 0;
      for (int j = 0; j < n; j++) {
        if (i + j >= 36) break;
        if (m[j] == b[i + j]) key++;
      }
      if (key == n) {
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  for (int i = 0; i < 36; i++) {
    if (m[0] == c[i]) {
      key = 0;
      for (int j = 0; j < n; j++) {
        if (i + j >= 36) break;
        if (m[j] == c[i + j]) key++;
      }
      if (key == n) {
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  for (int i = 0; i < 36; i++) {
    if (m[0] == d[i]) {
      key = 0;
      for (int j = 0; j < n; j++) {
        if (i + j > 35) break;
        if (m[j] == d[i + j]) key++;
      }
      if (key == n) {
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  cout << "NO" << endl;
  return 0;
}
