#include <bits/stdc++.h>
using namespace std;
int years[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31,
               30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30,
               31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30,
               31, 30, 31, 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() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  for (auto &i : v) cin >> i;
  for (int i = 0; i < 72; i++) {
    if (years[i] != v[0]) continue;
    for (int j = 0; j < n; j++) {
      if (j == n - 1 && v[j] == years[i + j]) return cout << "Yes" << endl, 0;
      if (v[j] != years[i + j]) break;
    }
  }
  cout << "No" << endl;
  return 0;
}
