#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
bool Check(int N, int pos) { return (bool)(N & (1 << pos)); }
int Set(int N, int pos) { return N = N | (1 << pos); }
int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1};
int hr[] = {-2, -2, -1, +1, +2, +2, -1, +1};
int hc[] = {+1, -1, +2, +2, -1, +1, -2, -2};
int dx[] = {+1, -1, +0, +0};
int dy[] = {+0, +0, +1, -1};
const int MAXN = (int)1e5 + 9;
int main() {
  int i, j, k, l, m, n, p, q, x, y, u, v, r, tc, t;
  int year[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  cin >> n;
  int ara[n + 9];
  int leap = 0;
  for (i = 0; i < n; i++) {
    cin >> ara[i];
    if (ara[i] == 29) {
      leap++;
      ara[i] = 28;
    }
  }
  if (leap > 1) {
    cout << "No\n";
    return 0;
  }
  bool flag = false;
  for (i = 0; i < 12; i++) {
    for (j = 0; j < n; j++) {
      if (year[i] == ara[j]) {
        bool flag2 = true;
        x = i - 1;
        y = j - 1;
        if (x < 0) x = 11;
        while (y >= 0) {
          if (year[x] == ara[y])
            ;
          else {
            flag2 = false;
            break;
          }
          x--;
          y--;
          if (x < 0) x = 11;
        }
        if (flag2 == false) continue;
        x = i + 1;
        y = j + 1;
        if (x == 12) x = 0;
        while (y < n) {
          if (year[x] == ara[y])
            ;
          else {
            flag2 = false;
            break;
          }
          x++;
          y++;
          if (x == 12) x = 0;
        }
        if (flag2 == false)
          continue;
        else
          flag = true;
      }
    }
  }
  if (flag)
    cout << "Yes\n";
  else
    cout << "No\n";
  return 0;
}
