#include <bits/stdc++.h>
using namespace std;
const int maxn = 200200;
int n, k;
int ans = 0;
int buf;
string s;
bool solve() {
  scanf("%d", &n);
  string h = "";
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> buf;
    if (buf == 29) {
      h += "28";
      cnt++;
    } else
      h += to_string(buf);
  }
  if (cnt > 1) return 0;
  s = s + s;
  s = s + s;
  for (int i = 0; i + h.size() < s.size(); ++i) {
    if (s[i] == h[0]) {
      if (s.substr(i, h.size()) == h) return 1;
    }
  }
  return 0;
}
int main() {
  int t = 1;
  s = "312831303130313130313031";
  if (solve())
    cout << "Yes";
  else
    cout << "No";
}
