#include <bits/stdc++.h>
using namespace std;
long long n, a[30], x, y, c, d;
long long b[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool check(long long a, long long b) { return (a == b) || (a < 30 && b < 30); }
bool check2(long long i, long long j) {
  x = i, y = j, c = 0, d = 0;
  while (1) {
    c += (a[x] == 29);
    d += (a[x] == 28);
    if (!check(a[x], b[y])) return 0;
    x = (x + 1) % n, y = (y + 1) % 12;
    if (x == i) break;
  }
  return (c <= 1) && (d <= 2);
}
void solve() {
  cin >> n;
  for (__typeof((n)) i = (0); i < (n); i++) cin >> a[i];
  if (n == 1) {
    cout << "Yes" << endl;
    return;
  };
  for (__typeof((n)) i = (0); i < (n); i++) {
    for (__typeof((12)) j = (0); j < (12); j++) {
      if (check(a[i], b[j])) {
        if (check2(i, j)) {
          cout << "Yes" << endl;
          return;
        };
      }
    }
  }
  {
    cout << "No" << endl;
    return;
  };
}
void prep() {}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  prep();
  cout << fixed << setprecision(10);
  while (t--) solve();
  return 0;
}
