#include <bits/stdc++.h>
using namespace std;
int mat[21], bir[21];
int day[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
    day2[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool Legal(int a[], int b[]) {
  if (a[1] > 12 || a[1] == 0) return false;
  if (b[1] > 12 || b[1] == 0) return false;
  if (a[2] % 4 == 0) {
    if (a[0] == 0 || a[0] > day2[a[1]]) return false;
  } else {
    if (a[0] == 0 || a[0] > day[a[1]]) return false;
  }
  if (b[2] % 4 == 0) {
    if (b[0] == 0 || b[0] > day2[b[1]]) return false;
  } else {
    if (b[0] == 0 || b[0] > day[b[1]]) return false;
  }
  if (a[2] > b[2] + 18 || a[2] == b[2] + 18 && a[1] > b[1] ||
      a[2] == b[2] + 18 && a[1] == b[1] && a[0] >= b[0])
    return true;
  return false;
}
int main() {
  scanf("%d.%d.%d", &mat[0], &mat[1], &mat[2]);
  scanf("%d.%d.%d", &bir[0], &bir[1], &bir[2]);
  do {
    do {
      if (Legal(mat, bir)) {
        printf("YES\n");
        return 0;
      }
    } while (next_permutation(bir, bir + 3));
  } while (next_permutation(mat, mat + 3));
  printf("NO\n");
  return 0;
}
