#include <bits/stdc++.h>
using namespace std;
int main() {
  string s = "181010110101181010110101181010110101191010110101", m;
  s += s;
  int n;
  cin >> n;
  int t = 0;
  for (int i = 0; i < n; i++) {
    cin >> t;
    m += (char)((t % 10) + '0');
  }
  if (s.find(m) != string ::npos)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
