#include <bits/stdc++.h>
using namespace std;
bool isSubArray(vector<long long> A, vector<long long> B, long long n,
                long long m) {
  long long i = 0, j = 0;
  while (i < n && j < m) {
    if (A[i] == B[j]) {
      i++;
      j++;
      if (j == m) return true;
    } else {
      i = i - j + 1;
      j = 0;
    }
  }
  return false;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cout << fixed << setprecision(12);
  vector<long long> leap = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  vector<long long> non_leap = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  vector<long long> arr;
  for (long long i = 0; i < 12; ++i) {
    arr.push_back(leap[i]);
  }
  for (long long i = 0; i < 12; ++i) {
    arr.push_back(non_leap[i]);
  }
  for (long long i = 0; i < 12; ++i) {
    arr.push_back(non_leap[i]);
  }
  for (long long i = 0; i < 12; ++i) {
    arr.push_back(non_leap[i]);
  }
  for (long long i = 0; i < 12; ++i) {
    arr.push_back(leap[i]);
  }
  for (long long i = 0; i < 12; ++i) {
    arr.push_back(non_leap[i]);
  }
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; ++i) cin >> a[i];
  if (isSubArray(arr, a, arr.size(), n)) {
    cout << ("YES") << "\n";
  } else {
    cout << ("NO") << "\n";
  }
  return 0;
}
