#include <bits/stdc++.h>
using namespace std;
int num1[] = {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 num2[] = {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 num3[] = {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 num4[] = {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 num[25];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> num[i];
  }
  int flag = 1;
  for (int i = 0; i + n < 36; i++) {
    flag = 1;
    int index = i;
    for (int j = 1; j <= n;) {
      if (num[j] == num1[index]) {
        j++;
        index++;
      } else {
        flag = 0;
        break;
      }
    }
    if (flag == 1) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  for (int i = 0; i + n < 36; i++) {
    flag = 1;
    int index = i;
    for (int j = 1; j <= n;) {
      if (num[j] == num2[index]) {
        j++;
        index++;
      } else {
        flag = 0;
        break;
      }
    }
    if (flag == 1) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  for (int i = 0; i + n < 36; i++) {
    flag = 1;
    int index = i;
    for (int j = 1; j <= n;) {
      if (num[j] == num3[index]) {
        j++;
        index++;
      } else {
        flag = 0;
        break;
      }
    }
    if (flag == 1) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  for (int i = 0; i + n < 36; i++) {
    flag = 1;
    int index = i;
    for (int j = 1; j <= n;) {
      if (num[j] == num4[index]) {
        j++;
        index++;
      } else {
        flag = 0;
        break;
      }
    }
    if (flag == 1) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}
