#include <bits/stdc++.h>
using namespace std;
int a[3], b[3];
bool large() {
  if (b[2] + 18 != a[2]) return b[2] + 18 < a[2];
  if (b[1] != a[1]) return b[1] < a[1];
  if (b[0] != a[0]) return b[0] < a[0];
  return true;
}
bool legal() {
  int leap = (b[2] % 4 == 0);
  if (b[1] == 2) return b[0] <= 28 + leap;
  if (b[1] <= 7) return b[0] <= 30 + b[1] % 2;
  if (b[1] <= 12) return b[0] <= 31 - b[1] % 2;
  return false;
}
bool solve() {
  sort(b, b + 3);
  do {
    if (legal() && large()) return true;
  } while (next_permutation(b, b + 3));
  return false;
}
int main(void) {
  for (int i = 0; i < 3; i++) scanf("%d%*[^0-9]", &a[i]);
  for (int i = 0; i < 3; i++) scanf("%d%*[^0-9]", &b[i]);
  puts(solve() ? "YES" : "NO");
  return 0;
}
