#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> a = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
                 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
vector<int> b = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
                 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
vector<int> c = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
                 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  for (int i = 0; i < a.size(); ++i) {
    int cnt = 0;
    for (int j = 0; j < v.size(); ++j) {
      int qwe = i + j;
      qwe %= a.size();
      if (a[qwe] == v[j]) ++cnt;
    }
    if (cnt == n) {
      cout << "YES\n";
      return 0;
    }
  }
  a = b;
  for (int i = 0; i < a.size(); ++i) {
    int cnt = 0;
    for (int j = 0; j < v.size(); ++j) {
      int qwe = i + j;
      qwe %= a.size();
      if (a[qwe] == v[j]) ++cnt;
    }
    if (cnt == n) {
      cout << "YES\n";
      return 0;
    }
  }
  a = c;
  for (int i = 0; i < a.size(); ++i) {
    int cnt = 0;
    for (int j = 0; j < v.size(); ++j) {
      int qwe = i + j;
      qwe %= a.size();
      if (a[qwe] == v[j]) ++cnt;
    }
    if (cnt == n) {
      cout << "YES\n";
      return 0;
    }
  }
  cout << "NO\n";
}
