#include <bits/stdc++.h>
using namespace std;
long long n, i, a[200000], c, t, b[12], j, k;
int main() {
  cin >> n;
  b[0] = 31;
  b[1] = 28;
  b[2] = 31;
  b[3] = 30;
  b[4] = 31;
  b[5] = 30;
  b[6] = 31;
  b[7] = 31;
  b[8] = 30;
  b[9] = 31;
  b[10] = 30;
  b[11] = 31;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 30 && a[i - 1] == 30) {
      cout << "NO" << endl;
      return 0;
    }
    if (a[i] == 29 && k > 0) {
      cout << "NO" << endl;
      return 0;
    }
    if (a[i] == 29) {
      k++;
      a[i]--;
    }
  }
  for (i = 0; i < 12; i++) {
    if (a[0] == b[i] || (a[0] == 29 && b[i] == 28)) {
      c = i + 1;
      if (c == 12) c = 0;
      for (j = 1; j < n; j++) {
        if (a[j] != b[c]) {
          t++;
          break;
        }
        c++;
        if (c == 12) c = 0;
      }
      if (t == 0) {
        cout << "YES" << endl;
        return 0;
      }
      t = 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}
