#include <bits/stdc++.h>
using namespace std;
int n;
int t[50];
int days[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &t[i]);
  for (int i = 0; i < 12; i++) {
    int nr = i;
    bool good = true;
    bool count = true;
    for (int j = 1; j <= n; j++) {
      if (t[j] != days[nr]) {
        if (days[nr] == 29 && t[j] > 29) {
          good = false;
          break;
        } else if (days[nr] != 29) {
          good = false;
          break;
        }
      }
      if (days[nr] == 29 && t[j] == 29 && !count) {
        good = false;
        break;
      }
      if (days[nr] == 29 && t[j] == 29) {
        count = false;
      }
      nr++;
      if (nr >= 12) nr = 0;
    }
    if (good) {
      puts("Yes");
      return 0;
    }
  }
  puts("No");
  return 0;
}
