#include <bits/stdc++.h>
using namespace std;
vector<int> calendar;
void build() {
  vector<int> tmp(12, 0);
  tmp[0] = 31;
  tmp[1] = 28;
  tmp[2] = 31;
  tmp[3] = 30;
  tmp[4] = 31;
  tmp[5] = 30;
  tmp[6] = 31;
  tmp[7] = 31;
  tmp[8] = 30;
  tmp[9] = 31;
  tmp[10] = 30;
  tmp[11] = 31;
  vector<int> tmp2 = tmp;
  tmp2[1] = 29;
  for (int i = 1; i <= 3; i++)
    for (int j = 0; j < 12; j++) calendar.push_back(tmp[j]);
  for (int i = 0; i < 12; i++) calendar.push_back(tmp2[i]);
  for (int i = 1; i <= 3; i++)
    for (int j = 0; j < 12; j++) calendar.push_back(tmp[j]);
}
int main() {
  build();
  int n;
  cin >> n;
  vector<int> a(n, 0);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < calendar.size(); i++) {
    if (calendar[i] == a[0]) {
      int z = i, j = 0;
      while (calendar[z] == a[j] && j < n && z < calendar.size()) {
        z++;
        j++;
      }
      if (j == a.size()) {
        cout << "YES";
        return 0;
      }
    }
  }
  cout << "NO";
}
