#include <bits/stdc++.h>
int flag = 0, flag1 = 0, flag2 = 0, flag3 = 0;
int fd(int D, int M, int Y) {
  if (M == 1 || M == 3 || M == 5 || M == 7 || M == 8 || M == 10 || M == 12) {
    if (D <= 31)
      return 1;
    else
      return 0;
  } else if (M == 4 || M == 6 || M == 9 || M == 11) {
    if (D <= 30)
      return 1;
    else
      return 0;
  } else if (M == 2) {
    if (Y % 4 == 0) {
      if (D <= 29)
        return 1;
      else
        return 0;
    } else {
      if (D <= 28)
        return 1;
      else
        return 0;
    }
  } else
    return 0;
}
int jk(int a, int b, int c, int x, int y, int z) {
  if (c - z > 18)
    return 3;
  else if (c - z == 18) {
    if (b > y)
      return 3;
    else if (b == y) {
      if (a >= x)
        return 3;
      else
        return 4;
    }
  } else
    return 4;
}
int main() {
  int DD, MM, YY;
  while (~scanf("%d.%d.%d", &DD, &MM, &YY)) {
    int BD, BM, BY, t, k;
    scanf("%d.%d.%d", &BD, &BM, &BY);
    if (fd(BD, BM, BY) == 1 && jk(DD, MM, YY, BD, BM, BY) == 3)
      printf("YES\n");
    else {
      if (fd(BD, BY, BM) == 1 && jk(DD, MM, YY, BD, BY, BM) == 3)
        printf("YES\n");
      else {
        if (fd(BM, BD, BY) == 1 && jk(DD, MM, YY, BM, BD, BY) == 3)
          printf("YES\n");
        else {
          if (fd(BM, BY, BD) == 1 && jk(DD, MM, YY, BM, BY, BD) == 3)
            printf("YES\n");
          else {
            if (fd(BY, BD, BM) == 1 && jk(DD, MM, YY, BY, BD, BM) == 3)
              printf("YES\n");
            else {
              if (fd(BY, BM, BD) == 1 && jk(DD, MM, YY, BY, BM, BD) == 3)
                printf("YES\n");
              else
                printf("NO\n");
            }
          }
        }
      }
    }
  }
  return 0;
}
