#include <bits/stdc++.h>
using namespace std;
bool isleap(int year) {
  if (year % 4 == 0) {
    if (year % 100 == 0) {
      if (year % 400 == 0)
        return true;
      else
        return false;
    } else
      return true;
  } else
    return false;
}
int main() {
  int t = 1;
  while (t--) {
    int n;
    cin >> n;
    int arr[n];
    vector<int> search;
    int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    int k = 2001;
    for (int i = 0; i < 10; i++) {
      if (isleap(k)) {
        for (int j = 0; j < 12; j++) {
          if (j == 1) {
            search.push_back(29);
          } else
            search.push_back(month[j]);
        }
      } else {
        for (int j = 0; j < 12; j++) {
          search.push_back(month[j]);
        }
      }
      k++;
    }
    int flag = 0;
    for (int i = 0; i < 120 - n; ++i) {
      flag = 0;
      k = i;
      for (int j = 0; j < n; j++) {
        if (arr[j] != search[k++]) {
          flag = 1;
          break;
        }
      }
      if (flag == 0) {
        break;
      }
    }
    if (flag == 0) {
      cout << "Yes" << endl;
    } else
      cout << "No" << endl;
  }
  return 0;
}
