#include <bits/stdc++.h>
using namespace std;
string x = "312831303130313130313031";
string y = "312931303130313130313031";
string a = x + x + x, b = x + y + x, c = y + x + x, d = x + x + y;
bool solve(string s) {
  if (strstr(a.c_str(), s.c_str()))
    return true;
  else if (strstr(b.c_str(), s.c_str()))
    return true;
  else if (strstr(c.c_str(), s.c_str()))
    return true;
  else if (strstr(d.c_str(), s.c_str()))
    return true;
  else
    return false;
}
int main() {
  int n;
  string s = "", temp;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    s += temp;
  }
  if (solve(s))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
