#include <bits/stdc++.h>
using namespace std;
int m[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int m2[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int k[24];
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    m2[1] = 29;
    for (int i = 0; i < n; i++) {
      cin >> k[i];
    }
    int flag = 0;
    for (int i = 0; i < 12; i++) {
      if (k[0] == m[i] || k[0] == m2[i]) {
        if (k[0] == 29) {
          m2[1] = 28;
        }
        int j = i;
        int count = 1;
        int num = 0;
        while (1) {
          num++;
          j++;
          j %= 12;
          if (count == n) {
            flag = 1;
            break;
          }
          if (k[num] == m[j] || k[num] == m2[j]) {
            if (k[num] == 29) {
              m2[1] = 28;
            }
            count++;
          } else {
            m2[1] = 29;
            break;
          }
        }
        if (flag == 1) {
          break;
        }
      }
    }
    if (flag) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}
