#include <bits/stdc++.h>
using namespace std;
int bb[2][12] = {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 main() {
  int a, b, c, aa[3], r;
  int j;
  scanf("%d.%d.%d", &a, &b, &c);
  scanf("%d.%d.%d", &aa[0], &aa[1], &aa[2]);
  for (int i = 0; i < 10; i++) {
    next_permutation(aa, aa + 3);
    if (aa[0] == 0 || aa[1] == 0 || aa[2] == 0) continue;
    if (aa[1] > 12) continue;
    if (aa[0] > 31) continue;
    if (aa[2] % 4 == 0)
      r = 1;
    else
      r = 0;
    if (bb[r][aa[1] - 1] < aa[0]) continue;
    if (c - aa[2] > 18) {
      printf("YES\n");
      return 0;
    }
    if (c - aa[2] == 18 && b > aa[1]) {
      printf("YES\n");
      return 0;
    }
    if (c - aa[2] == 18 && b == aa[1] && a >= aa[0]) {
      printf("YES\n");
      return 0;
    }
  }
  printf("NO\n");
  return 0;
}
