#include <bits/stdc++.h>
using namespace std;
int main() {
  char a[] = "121010110101121010110101121010110101";
  long long int n, i, j, k;
  while (cin >> n) {
    long long int y[n], leap = 0;
    char c[n];
    for (i = 0; i < n; i++) {
      cin >> y[i];
      if (y[i] == 29) {
        leap++;
      }
      if (y[i] == 31) {
        c[i] = '1';
      } else if (y[i] == 30) {
        c[i] = '0';
      } else {
        c[i] = '2';
      }
    }
    long long int x = 0, p = 0, flag = 0, len = 0, q = 0;
    for (i = 0; i < n; i++) {
      if (c[i] == a[x]) {
        len++;
        x++;
      } else {
        if (len == n) {
          flag = 1;
          break;
        } else {
          if (p + 1 < 36) {
            p++;
            x = p;
            len = 0;
            i = -1;
          }
        }
      }
    }
    if (len == n) {
      flag = 1;
    }
    if (leap > 1) {
      cout << "NO" << endl;
    } else if (flag == 1) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}
