#include <bits/stdc++.h>
using namespace std;
int a[24];
int b[] = {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(NULL);
  cout.tie(NULL);
  int n, c = 0;
  vector<int> v;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    if (a[i] == 29) c++;
  }
  if (c > 1) {
    cout << "NO";
    return 0;
  }
  c = 0;
  for (int i = 0; i < 36 - n; i++) {
    for (int j = i; j < i + n; j++) v.push_back(b[j]);
    for (int j = 0; j < n; j++) {
      if (v[j] == 28 and (a[j] == 28 or a[j] == 29))
        c++;
      else if (v[j] == a[j])
        c++;
      else
        break;
    }
    if (c == n) {
      cout << "YES";
      return 0;
    } else {
      c = 0;
      v.clear();
    }
  }
  cout << "NO";
}
