#include <bits/stdc++.h>
using namespace std;
const int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
struct date {
  int arr[3];
  void read() {
    string s;
    cin >> s;
    for (int i = 0; i < 3; i++) {
      arr[i] = (s[i * 3] - '0') * 10 + (s[i * 3 + 1] - '0');
    }
  }
  void next() { next_permutation(arr, arr + 3); }
  bool valid() {
    if (arr[1] > 12) return false;
    if (arr[0] > (days[arr[1] - 1] + (arr[1] == 2 && arr[2] % 4 == 0)))
      return false;
    return true;
  }
  bool operator<=(const date& oth) const {
    for (int i = 2; i >= 0; i--) {
      if (arr[i] != oth.arr[i]) {
        return arr[i] < oth.arr[i];
      }
    }
    return true;
  }
};
int main() {
  date a, b;
  a.read();
  b.read();
  for (int i = 0; i < 6; i++) {
    if (b.valid()) {
      b.arr[2] += 18;
      if (b <= a) {
        cout << "YES\n";
        return 0;
      }
      b.arr[2] -= 18;
    }
    b.next();
  }
  cout << "NO\n";
}
