#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<int> x = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  vector<int> y = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  auto check = [&](vector<int> a1, vector<int> a2, vector<int> a3,
                   vector<int> a4) {
    vector<int> x = a1;
    x.insert(end(x), begin(a2), end(a2));
    x.insert(end(x), begin(a3), end(a3));
    x.insert(end(x), begin(a4), end(a4));
    for (int i = 0; i + int(a.size()) - 1 < int(x.size()); i++) {
      bool ok = true;
      for (int j = 0; j < int(a.size()); j++) {
        ok &= (x[i + j] == a[j]);
      }
      if (ok) return true;
    }
    return false;
  };
  if (check(x, x, x, x) or check(y, x, x, x) or check(x, y, x, x) or
      check(x, x, y, x) or check(x, x, x, y))
    cout << "Yes\n";
  else
    cout << "No\n";
  return (0);
}
