#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int a[55], x[30];
int main() {
  std::ios::sync_with_stdio(false);
  int n, i, j, c = 0;
  cin >> n;
  a[0] = 31;
  a[1] = 28;
  a[2] = 31;
  a[3] = 30;
  a[4] = 31;
  a[5] = 30;
  a[6] = 31;
  a[7] = 31;
  a[8] = 30;
  a[9] = 31;
  a[10] = 30;
  a[11] = 31;
  for (j = 12; j < 50; j++) {
    a[j] = a[j - 12];
  }
  for (i = 0; i < n; i++) {
    cin >> x[i];
    if (x[i] == 29) c++;
  }
  if (c >= 2) {
    cout << "no" << endl;
    return 0;
  }
  for (i = 0; i < 12; i++) {
    for (j = 0; j < n; j++) {
      if (a[i + j] != x[j]) {
        if (x[j] != 29 || a[i + j] != 28)
          break;
        else
          v.push_back(j);
      }
    }
    v.clear();
    if (j == n) {
      if (v.size() == 0 || v.size() == 1 ||
          (v.size() == 2 && v[1] - v[0] == 12)) {
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  cout << "no" << endl;
}
