#include <bits/stdc++.h>
using namespace std;
int year[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int year2[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), yr;
  for (int &x : a) cin >> x;
  for (int i = 0; i < 3; ++i)
    for (int &x : year) yr.push_back(x);
  for (int &x : year2) yr.push_back(x);
  for (int i = 0; i < 3; ++i)
    for (int &x : year) yr.push_back(x);
  auto kek = search(yr.begin(), yr.end(), a.begin(), a.end());
  if (kek == yr.end())
    cout << "NO" << endl;
  else
    cout << "YES" << endl;
  return 0;
}
