#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  string l = "312931303130313130313031";
  string input = "";
  string s = "312831303130313130313031";
  string s1 = s + s + s;
  string s2 = l + s + s;
  string s3 = s + l + s;
  string s4 = s + s + l;
  long long int i;
  for (i = 0; i < n; i++) {
    string ch;
    cin >> ch;
    input += ch;
  }
  long long int flag1 = 0, flag2 = 0, flag3 = 0, flag4 = 0;
  for (i = 0; i < s1.length() - 2 * n; i++) {
    if (input.compare(s1.substr(i, n * 2)) == 0) {
      flag1 = 1;
    }
  }
  for (i = 0; i < s2.length() - 2 * n; i++) {
    if (input.compare(s2.substr(i, 2 * n)) == 0) {
      flag2 = 1;
    }
  }
  for (i = 0; i < s3.length() - 2 * n; i++) {
    if (input.compare(s3.substr(i, 2 * n)) == 0) {
      flag3 = 1;
    }
  }
  for (i = 0; i < s4.length() - 2 * n; i++) {
    if (input.compare(s4.substr(i, 2 * n)) == 0) {
      flag4 = 1;
    }
  }
  if (flag1 || flag2 || flag3 || flag4) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}
