#include <bits/stdc++.h>
using namespace std;
const int maxn = 40;
int key1[] = {
    31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30,
    31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
};
int key2[] = {
    31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30,
    31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
};
int key3[] = {
    31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30,
    31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
};
int key4[] = {
    31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30,
    31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
};
int n;
int a[maxn];
bool check_t(int p, int k[]) {
  for (int i = 0; i < n; ++i) {
    if (a[i] != k[p + i]) {
      return false;
    }
  }
  return true;
}
bool check(int k[]) {
  for (int i = 0; i + n - 1 < 36; ++i) {
    if (check_t(i, k)) {
      return true;
    }
  }
  return false;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  if (check(key1) || check(key2) || check(key3) || check(key4)) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }
  return 0;
}
