#include <bits/stdc++.h>
using namespace std;
string s1 = "312831303130313130313031", s2 = "312931303130313130313031", s, x;
int n;
int main() {
  string s3 = s1 + s1 + s2 + s1 + s1;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    s += x;
  }
  if (s3.find(s) == -1)
    puts("NO");
  else
    puts("YES");
  return 0;
}
