#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 3;
long long n, a, cnt, ans, sum;
deque<long long> v, vc;
void DNM() {
  v.clear();
  v.push_back(31);
  v.push_back(28);
  v.push_back(31);
  v.push_back(30);
  v.push_back(31);
  v.push_back(30);
  v.push_back(31);
  v.push_back(31);
  v.push_back(30);
  v.push_back(31);
  v.push_back(30);
  v.push_back(31);
  for (long long i = 0; i < 3; i++) {
    for (long long j = 0; j < v.size(); j++) vc.push_back(v[j]);
  }
  v[1] = 29;
  for (long long i = 0; i < v.size(); i++) vc.push_back(v[i]);
  v[1] = 28;
  for (long long j = 0; j < 2; j++)
    for (long long i = 0; i < v.size(); i++) vc.push_back(v[i]);
  v.clear();
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
  }
  for (long long i = 0; i < vc.size() - v.size() + 1; i++) {
    cnt = 0;
    for (long long j = i; j < i + v.size(); j++) {
      if (v[j - i] != vc[j]) {
        cnt = 1;
        break;
      }
    }
    if (cnt == 0) {
      cout << "Yes" << endl;
      return;
    }
  }
  cout << "No" << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int Qu_l_uQ = 1;
  while (Qu_l_uQ--) DNM();
}
