#include <bits/stdc++.h>
using namespace std;
vector<long long> vc, fact(41, 1), segtree;
int main() {
  ifstream fin("Text.txt");
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long i, j, q;
  long long n, m, p, k, t;
  long long a = 0, b = 0, c, d;
  long long y, z;
  long long x = 0;
  long long one = 0, zero = 0;
  long long ans = 0;
  long long l, r;
  long long mod = 1000000000;
  string st1, st2, st3;
  char ch1;
  vector<long long> vc(2007);
  a = 2000;
  for (i = 1; i <= 1000; i++) {
    if (i % 12 == 1 || i % 12 == 3 || i % 12 == 5 || i % 12 == 7 ||
        i % 12 == 8 || i % 12 == 10) {
      vc[i] = 31;
    } else if (i % 12 == 0) {
      vc[i] = 31;
      a++;
    } else if (i % 12 == 2) {
      if (a % 400 == 0 || (a % 4 == 0 && a % 100 != 0))
        vc[i] = 29;
      else
        vc[i] = 28;
    } else
      vc[i] = 30;
  }
  cin >> n;
  vector<long long> vm(24);
  for (i = 0; i < n; i++) {
    cin >> vm[i];
  }
  for (i = 1; i <= 1000; i++) {
    for (j = 0; j < n; j++) {
      if (vc[i + j] != vm[j]) break;
    }
    if (j == n) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}
