#include <bits/stdc++.h>
using namespace std;
int tmp[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int m[5][48];
int v[24];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 12; j++) {
      m[0][i * 12 + j] = tmp[j];
      m[1][i * 12 + j] = tmp[j];
      m[2][i * 12 + j] = tmp[j];
      m[3][i * 12 + j] = tmp[j];
      m[4][i * 12 + j] = tmp[j];
    }
  }
  for (int i = 0; i < 4; i++) {
    m[i][i * 12 + 1] = 29;
  }
  for (int i = 0; i < n; i++) scanf("%d", &v[i]);
  for (int i = 0; i < 24; i++) {
    for (int z = 0; z < 5; z++) {
      bool good = true;
      for (int j = 0, k = i; j < n; j++, k++) {
        if (m[z][k] != v[j]) {
          good = false;
          break;
        }
      }
      if (good) return 0 & puts("YES");
    }
  }
  puts("NO");
  return 0;
}
