#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:64000000")
template <class T>
inline T sqr(T x) {
  return x * x;
}
int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool check_valid(int d, int m, int y) {
  return y >= 1 && y <= 99 && m && m <= 12 && d &&
         days[m - 1] + (!(y % 4) && m == 2) >= d;
}
inline bool check_18(int d1, int m1, int y1, int d2, int m2, int y2) {
  int cnt = -1;
  for (int y = y1; y <= y2; ++y) {
    for (int m = y == y1 ? m1 : 1; m <= (y == y2 ? m2 : 12); ++m) {
      int lim = days[m - 1];
      if (y % 4 == 0 && m == 2) ++lim;
      for (int d = y == y1 && m == m1 ? d1 : 1;
           d <= (y == y2 && m == m2 ? d2 : lim); ++d) {
        if (d == d1 && m == m1 ||
            m1 == 2 && d1 == 29 && y % 4 && m == 3 && d == 1)
          ++cnt;
      }
    }
  }
  return cnt >= 18;
}
bool solve(string a, string b) {
  int d, m, y;
  sscanf(a.c_str(), "%d.%d.%d", &d, &m, &y);
  int p[3];
  sscanf(b.c_str(), "%d.%d.%d", &p[0], &p[1], &p[2]);
  sort(p, p + 3);
  do {
    if (!check_valid(p[0], p[1], p[2])) continue;
    if (check_18(p[0], p[1], p[2], d, m, y)) return true;
  } while (next_permutation(p, p + 3));
  return false;
}
int main() {
  string a, b;
  cin >> a >> b;
  puts(solve(a, b) ? "YES" : "NO");
  return 0;
}
