#include <bits/stdc++.h>
struct coor {
  int x[3];
};
int x[6][3] = {0, 1, 2, 0, 2, 1, 1, 0, 2, 1, 2, 0, 2, 0, 1, 2, 1, 0};
bool judge(coor a, coor b) {
  bool flag = 0;
  b.x[2] += 18;
  if (b.x[2] < a.x[2]) {
    flag = 1;
  } else if (b.x[2] > a.x[2]) {
  } else if (a.x[2] == b.x[2]) {
    if (b.x[1] < a.x[1]) {
      flag = 1;
    } else if (b.x[1] > a.x[1]) {
    } else if (b.x[1] == a.x[1]) {
      if (b.x[0] < a.x[0]) {
        flag = 1;
      } else if (b.x[0] > a.x[0]) {
      } else if (b.x[0] == a.x[0]) {
        flag = 1;
      }
    }
  }
  return flag;
}
bool hefa(coor a) {
  if (a.x[1] < 1 || a.x[1] > 12) return 0;
  if (a.x[1] == 1 || a.x[1] == 3 || a.x[1] == 5 || a.x[1] == 7 || a.x[1] == 8 ||
      a.x[1] == 10 || a.x[1] == 12) {
    if (a.x[0] < 1 || a.x[0] > 31) return 0;
  } else if (a.x[1] == 2) {
    if (a.x[2] % 4 == 0) {
      if (a.x[0] < 1 || a.x[0] > 29) return 0;
    } else {
      if (a.x[0] < 1 || a.x[0] > 28) return 0;
    }
  } else {
    if (a.x[0] < 1 || a.x[0] > 30) return 0;
  }
  return 1;
}
int main() {
  int i, j;
  coor a, b, c;
  scanf("%d.%d.%d", &a.x[0], &a.x[1], &a.x[2]);
  scanf("%d.%d.%d", &b.x[0], &b.x[1], &b.x[2]);
  bool flag = 0;
  for (i = 0; i < 6; i++) {
    c.x[0] = b.x[x[i][0]];
    c.x[1] = b.x[x[i][1]];
    c.x[2] = b.x[x[i][2]];
    if (hefa(c)) {
      if (judge(a, c)) {
        flag = 1;
        break;
      }
    }
  }
  if (flag)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
