#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int normal[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int leap[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int n;
vector<int> a;
bool check(const vector<int>& b) {
  for (int i = 0; i < 12; ++i) {
    bool good = true;
    for (int j = 0; j < n; ++j) {
      if (a[j] != b[i + j]) {
        good = false;
        break;
      }
    }
    if (good) return true;
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    a.push_back(x);
  }
  vector<int> nnn;
  for (int iter = 0; iter < 3; ++iter) {
    for (auto e : normal) {
      nnn.push_back(e);
    }
  }
  vector<int> nln;
  for (auto e : normal) {
    nln.push_back(e);
  }
  for (auto e : leap) {
    nln.push_back(e);
  }
  for (auto e : normal) {
    nln.push_back(e);
  }
  vector<int> nnl;
  for (auto e : normal) {
    nnl.push_back(e);
  }
  for (auto e : normal) {
    nnl.push_back(e);
  }
  for (auto e : leap) {
    nnl.push_back(e);
  }
  vector<int> lnn;
  for (auto e : leap) {
    lnn.push_back(e);
  }
  for (auto e : normal) {
    lnn.push_back(e);
  }
  for (auto e : normal) {
    lnn.push_back(e);
  }
  if (check(nnn) or check(nln) or check(nnl) or check(lnn)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}
