#include <bits/stdc++.h>
using namespace std;
int cond = 1;
int w[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int correct(int a, int b, int c) {
  if (b > 12) return 0;
  if (a > w[b - 1] + (b == 2 && c % 4 == 0)) return 0;
  return 1;
}
int main() {
  int d, m, y;
  scanf("%d.%d.%d", &d, &m, &y);
  int a[3];
  scanf("%d.%d.%d", &a[0], &a[1], &a[2]);
  sort(a, a + 3);
  do {
    if ((a[2] < y - 18 ||
         (a[2] == y - 18 && make_pair(m, d) >= make_pair(a[1], a[0]))) &&
        correct(a[0], a[1], a[2])) {
      puts("YES");
      return 0;
    }
  } while (next_permutation(a, a + 3));
  puts("NO");
  return 0;
}
