#include <bits/stdc++.h>
using namespace std;
int n, m[13], a[25];
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n;
  int d1 = 0, d2 = 0, vt1 = 0, vt2 = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == 29) d1++;
    if (a[i] == 28) d2++;
    if (a[i] == 28 || a[i] == 29)
      if (!vt1)
        vt1 = i;
      else
        vt2 = i;
  }
  m[1] = 31;
  m[3] = 31;
  m[4] = 30;
  m[5] = 31;
  m[6] = 30;
  m[7] = 31;
  m[8] = 31;
  m[9] = 30;
  m[10] = 31;
  m[11] = 30;
  m[12] = 31;
  if (d1 > 1) {
    cout << "NO";
    return 0;
  }
  if (d1 == 0 && d2 == 0) {
    for (int i = 1; i <= 12 - n + 1; i++) {
      bool kt = true;
      for (int j = 1; j <= n; j++)
        if (a[j] != m[j + i - 1]) kt = false;
      if (kt) {
        cout << "YES";
        return 0;
      }
    }
    cout << "NO";
    return 0;
  }
  int j = 1;
  for (int i = vt1 - 1; i >= 1; i--) {
    if (j == 0) j = 12;
    if (a[i] != m[j]) {
      cout << "NO";
      return 0;
    }
    j--;
  }
  j = 3;
  int k;
  if (!vt2)
    k = n;
  else
    k = min(12, n);
  for (int i = vt1 + 1; i <= k; i++) {
    if (j == 13) j = 1;
    if (a[i] != m[j]) {
      cout << "NO";
      return 0;
    }
    j++;
  }
  if (n > 12 && vt2) {
    j = 1;
    for (int i = vt2 - 1; i >= 13; i--) {
      if (j == 0) j = 12;
      if (a[i] != m[j]) {
        cout << "NO";
        return 0;
      }
      j--;
    }
    j = 3;
    for (int i = vt2 + 1; i <= min(24, n); i++) {
      if (j == 13) j = 1;
      if (a[i] != m[j]) {
        cout << "NO";
        return 0;
      }
      j++;
    }
  }
  cout << "YES";
}
