#include <bits/stdc++.h>
using namespace std;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n >> b) & 1; }
inline void set_bit(int& n, int b) { n |= two(b); }
inline void unset_bit(int& n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) {
  int res = 0;
  while (n && ++res) n -= n & (-n);
  return res;
}
const double pi = acos(-1);
int cmp(double x, double y = 0, double tol = 1e-9) {
  return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}
template <class T>
inline T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  return (b == 0) ? a : gcd(b, a % b);
}
const int MAX_N = 200001;
int arr[MAX_N];
int a1[50];
int a2[50];
int a3[50];
int a4[50];
int a5[50];
int a6[50];
int a7[50];
int a8[50];
int a[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int b[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", arr + i);
  }
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 12; j++) {
      a1[12 * i + j] = a[j];
      a2[12 * i + j] = a[j];
      a3[12 * i + j] = a[j];
      a4[12 * i + j] = a[j];
    }
  }
  for (int i = 0; i < 12; i++) {
    a1[i] = b[i];
    a2[12 + i] = b[i];
    a3[24 + i] = b[i];
    a4[36 + i] = b[i];
  }
  bool ans = false;
  for (int i = 0; i < 48 - n; i++) {
    bool flag = true;
    for (int j = 0; j < n; j++) {
      if (arr[j] != a1[i + j]) {
        flag = false;
        break;
      }
    }
    if (flag) ans = true;
  }
  for (int i = 0; i < 48 - n; i++) {
    bool flag = true;
    for (int j = 0; j < n; j++) {
      if (arr[j] != a2[i + j]) {
        flag = false;
        break;
      }
    }
    if (flag) ans = true;
  }
  for (int i = 0; i < 48 - n; i++) {
    bool flag = true;
    for (int j = 0; j < n; j++) {
      if (arr[j] != a3[i + j]) {
        flag = false;
        break;
      }
    }
    if (flag) ans = true;
  }
  for (int i = 0; i < 48 - n; i++) {
    bool flag = true;
    for (int j = 0; j < n; j++) {
      if (arr[j] != a4[i + j]) {
        flag = false;
        break;
      }
    }
    if (flag) ans = true;
  }
  if (ans)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
