#include <bits/stdc++.h>
using namespace std;
vector<long long int> v;
char s[10], s1[10], s2[10];
long long int wow(char s[]) {
  long long int a = ((int)s[0] - 48) * 10 + ((int)s[1] - 48);
  return a;
}
int main() {
  long long int a, b, c, d, i, j, k, l, m, n, p, q, t,
      ct = 0, ct1 = 0, ct2 = 0, ck = 0, ck1 = 0, ck2 = 0, ln, ln1, start, end,
      mid;
  long long int a1, a2, a3, a4, a5, a6, sum = 0, sum1 = 0, max1, max2, min1,
                                        min2, b1, b2, b3;
  double x, y, z;
  char ch, ch1, ch2;
  ios ::sync_with_stdio(false);
  cin.tie(0);
  ;
  cin >> s >> s1;
  long long int arr[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  vector<long long int> v(arr, arr + 13);
  s2[0] = s[0];
  s2[1] = s[1];
  s2[2] = '\0';
  a1 = wow(s2);
  s2[0] = s[3];
  s2[1] = s[4];
  s2[2] = '\0';
  a2 = wow(s2);
  s2[0] = s[6];
  s2[1] = s[7];
  s2[2] = '\0';
  a3 = wow(s2);
  s2[0] = s1[0];
  s2[1] = s1[1];
  s2[2] = '\0';
  a4 = wow(s2);
  s2[0] = s1[3];
  s2[1] = s1[4];
  s2[2] = '\0';
  a5 = wow(s2);
  s2[0] = s1[6];
  s2[1] = s1[7];
  s2[2] = '\0';
  a6 = wow(s2);
  for (i = 1; i <= 6; i++) {
    if (i == 1) {
      b1 = a4;
      b2 = a5;
      b3 = a6;
    } else if (i == 2) {
      b1 = a4;
      b2 = a6;
      b3 = a5;
    } else if (i == 3) {
      b1 = a5;
      b2 = a4;
      b3 = a6;
    } else if (i == 4) {
      b1 = a5;
      b2 = a6;
      b3 = a4;
    } else if (i == 5) {
      b1 = a6;
      b2 = a4;
      b3 = a5;
    } else if (i == 6) {
      b1 = a6;
      b2 = a5;
      b3 = a4;
    }
    if (b2 <= 12) {
      if (b2 == 2) {
        if ((b3 % 4 == 0) && (b1 > 29))
          continue;
        else if ((b3 % 4 != 0) && (b1 > 28))
          continue;
      } else {
        if (v[b2] < b1) continue;
      }
    } else
      continue;
    if ((a3 - b3) > 18) {
      printf("YES\n");
      return 0;
    } else if ((a3 - b3) == 18) {
      if (a2 > b2) {
        printf("YES\n");
        return 0;
      } else if (a2 == b2) {
        if (a1 >= b1) {
          printf("YES\n");
          return 0;
        } else {
          continue;
        }
      }
    }
  }
  printf("NO\n");
  return 0;
}
