#include <bits/stdc++.h>
using namespace std;
int n, ans, ans2;
string s1 =
    "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 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 s;
int main() {
  scanf("%d", &n);
  scanf("\n");
  getline(cin, s);
  ans = s1.find(s);
  if (ans == -1)
    puts("NO");
  else
    puts("YES");
  return 0;
}
