#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie();
  bool flag = 0;
  int months[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31,
                  29, 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, 31};
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < 48; i++) {
    flag = 1;
    if (months[i] == a[0]) {
      for (int j = 0; j < n; j++) {
        if (months[(i + j) % 48] != a[j]) {
          flag = 0;
          break;
        }
      }
      if (flag == 1) {
        cout << "YES";
        return 0;
      }
    }
  }
  cout << "NO";
  return 0;
}
