#include <bits/stdc++.h>
int dd, mm, yy;
int month[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int get(int d, int m, int y) {
  if (m > 12) return 0;
  if (d > month[m]) return 0;
  if (d == 29 && m == 2 && y % 4 != 0) return 0;
  if (d + m * 30 + y * 365 + 365 * 18 <= dd + mm * 30 + yy * 365) {
    printf("YES\n");
    return 1;
  }
  return 0;
}
int main() {
  int d, m, y;
  scanf("%d.%d.%d", &dd, &mm, &yy);
  scanf("%d.%d.%d", &d, &m, &y);
  if (get(d, m, y)) return 0;
  if (get(d, y, m)) return 0;
  if (get(m, d, y)) return 0;
  if (get(m, y, d)) return 0;
  if (get(y, m, d)) return 0;
  if (get(y, d, m)) return 0;
  printf("NO\n");
  return 0;
}
