#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s = "",
         g = "31283130313031313031303131293130313031313031303131283130313031313"
             "03130313128313031303131303130313128313031303131303130313129313031"
             "30313130313031312831303130313130313031312831303130313130313031";
  int n;
  string k;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> k;
    s += k;
  }
  if (g.find(s) != string::npos)
    cout << "YES";
  else
    cout << "NO";
}
