#include <bits/stdc++.h>
using namespace std;
int main() {
  string n, b;
  cin >> n >> b;
  vector<int> d(3, 0);
  vector<int> db(3, 0);
  vector<int> dc{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  vector<int> ldc{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  int st = 0;
  for (int i = 0; i < n.length(); i++) {
    if (n[i] == '.') {
      st++;
    } else if (st == 0) {
      d[0] = d[0] * 10 + n[i] - '0';
    } else if (st == 1) {
      d[1] = d[1] * 10 + n[i] - '0';
    } else if (st == 2) {
      d[2] = d[2] * 10 + n[i] - '0';
    }
  }
  st = 0;
  for (int i = 0; i < b.length(); i++) {
    if (b[i] == '.') {
      st++;
    } else if (st == 0) {
      db[0] = db[0] * 10 + b[i] - '0';
    } else if (st == 1) {
      db[1] = db[1] * 10 + b[i] - '0';
    } else if (st == 2) {
      db[2] = db[2] * 10 + b[i] - '0';
    }
  }
  bool mt = false;
  for (int i = 0; i < 3; i++) {
    if (d[2] - db[i] >= 18) {
      for (int j = 0; j < 3; j++) {
        if (j != i && db[j] <= 12) {
          int k = 3 - i - j;
          if ((db[i] % 4 == 0 && db[k] > ldc[db[j] - 1]) ||
              (db[i] % 4 != 0 && db[k] > dc[db[j] - 1])) {
            continue;
          }
          if (d[2] - db[i] > 18 || db[j] < d[1] ||
              (db[j] == d[1] && db[k] <= d[0])) {
            mt = true;
            break;
          }
        }
      }
    }
  }
  if (mt) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}
