#include <bits/stdc++.h>
using namespace std;
class TaskB {
 public:
  void solve(std::istream& in, std::ostream& out) {
    int n;
    in >> n;
    string s = "";
    for (int i = 0; i < n; i++) {
      int x;
      in >> x;
      if (x == 30)
        s += "0";
      else if (x == 31)
        s += "1";
      else if (x == 28)
        s += "2";
      else if (x == 29)
        s += "3";
    }
    string p1 = "121010110101121010110101121010110101121010110101";
    string p2 = "131010110101121010110101131010110101121010110101";
    string p3 = "121010110101131010110101121010110101131010110101";
    if (p1.find(s) != string::npos or p2.find(s) != string::npos or
        p3.find(s) != string::npos)
      out << "YES";
    else
      out << "NO";
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  TaskB solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
