#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  int l[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  int arr[25];
  int f = -1;
  int q = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] == 28 || arr[i] == 29) {
      if (f == -1) {
        f = i;
      }
    }
    if (arr[i] == 29) q++;
  }
  if (q > 1) {
    cout << "NO";
    return 0;
  }
  int j = 12 - f + 1;
  int ans = 0;
  if (f == -1) {
    if (n == 12) {
      cout << "NO" << endl;
      return 0;
    }
    int t = 0;
    for (int i = 1; i < n; i++) {
      if (arr[i] == arr[i - 1]) {
        if (arr[i] == 30 || t == 1) {
          cout << "NO";
          return 0;
        } else {
          t = 1;
        }
      }
    }
    cout << "YES";
    return 0;
  }
  for (int i = 0; i < f; i++) {
    if (arr[i] != a[j % 12] && arr[i] != l[j % 12]) {
      ans = 1;
    }
    j++;
  }
  j = 2;
  for (int i = f + 1; i < f + 12 && i < n; i++) {
    if (arr[i] != a[j % 12] && arr[i] != l[j % 12]) ans = 1;
    j++;
  }
  j = 2;
  for (int i = f + 12 + 1; i < n; i++) {
    if (arr[i] != a[j % 12] && arr[i] != l[j % 12]) ans = 1;
    j++;
  }
  if (ans)
    cout << "NO";
  else
    cout << "YES";
  return 0;
}
