#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string a;
  cin >> n;
  string c1 =
      "31 29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 "
      "31 28 31 30 31 30 31 31 30 31 30 31 ";
  string c2 =
      "31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 "
      "31 29 31 30 31 30 31 31 30 31 30 31 ";
  string c3 =
      "31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 "
      "31 28 31 30 31 30 31 31 30 31 30 31 ";
  string c4 =
      "31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31 "
      "31 28 31 30 31 30 31 31 30 31 30 31 ";
  string ch = "";
  int i;
  for (i = 0; i < n; i++) {
    cin >> a;
    ch = ch + a + " ";
    a = "";
  }
  size_t f1 = c1.find(ch);
  size_t f2 = c2.find(ch);
  size_t f3 = c3.find(ch);
  size_t f4 = c4.find(ch);
  if (f1 != string::npos || f2 != string::npos || f3 != string::npos ||
      f4 != string::npos) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}
