#include <bits/stdc++.h>
using namespace std;
int DD, MM, YY;
int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool ok(int d, int m, int y) {
  if (12 < m) return false;
  if ((days[m] + ((y % 4 == 0) && (m == 2) ? 1 : 0)) < d) return false;
  int d1 = YY * 10000 + MM * 100 + DD;
  int d2 = y * 10000 + m * 100 + d;
  return (180000 <= (d1 - d2));
}
int main() {
  int BD, BM, BY;
  scanf("%d.%d.%d", &DD, &MM, &YY);
  scanf("%d.%d.%d", &BD, &BM, &BY);
  if (ok(BD, BM, BY) || ok(BD, BY, BM) || ok(BM, BD, BY) || ok(BM, BY, BD) ||
      ok(BY, BD, BM) || ok(BY, BM, BD))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
