#include <bits/stdc++.h>
using namespace std;
int month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool valid(int arr[3]) {
  if (arr[2] < 1 || arr[2] > 99) return false;
  if (arr[1] < 1 || arr[1] > 12) return false;
  int dd = month[arr[1]];
  if (arr[2] % 4 == 0 && arr[1] == 2) dd++;
  if (arr[0] < 1 || arr[0] > dd) return false;
  return true;
}
bool check(int a[], int b[]) {
  if (a[2] < b[2]) return false;
  if (a[2] > b[2]) return true;
  if (a[1] < b[1]) return false;
  if (a[1] > b[1]) return true;
  if (a[0] < b[0]) return false;
  return true;
}
int main() {
  int contest[3], bd[3], perm[3], final[3], i;
  bool ok;
  scanf("%d.%d.%d", &contest[0], &contest[1], &contest[2]);
  scanf("%d.%d.%d", &bd[0], &bd[1], &bd[2]);
  for (i = 0; i < 3; ++i) {
    perm[i] = i;
  }
  ok = false;
  do {
    for (i = 0; i < 3; ++i) {
      final[i] = bd[perm[i]];
    }
    if (valid(final)) {
      final[2] += 18;
      if (check(contest, final)) {
        ok = true;
        for (i = 0; i < 3; ++i) {
        }
        break;
      }
    }
  } while (next_permutation(perm, perm + 3));
  if (ok)
    puts("YES");
  else
    puts("NO");
  return 0;
}
