#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  string x =
      "312831303130313130313031312831303130313130313031312831303130313130313031"
      "31283130313031313031303131283130313031313031303131283130313031313031303"
      "1";
  string y =
      "312931303130313130313031312831303130313130313031312831303130313130313031"
      "31283130313031313031303131293130313031313031303131283130313031313031303"
      "1";
  string p =
      "312831303130313130313031312931303130313130313031312831303130313130313031"
      "31283130313031313031303131283130313031313031303131283130313031313031303"
      "1";
  int n;
  cin >> n;
  string chk = "";
  for (int i = 0; i < n; i++) {
    string z;
    cin >> z;
    chk += z;
  }
  for (int i = 0; i <= x.size() - chk.size(); i += 2) {
    if (x.substr(i, chk.size()) == chk || y.substr(i, chk.size()) == chk ||
        p.substr(i, chk.size()) == chk) {
      printf("YES\n");
      return 0;
    }
  }
  printf("NO\n");
}
