#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
bool dmy[MAXN][MAXN][MAXN];
void dfs(int d, int m, int y, int bd, int bm, int by) {
  if (dmy[bd][bm][by]) return;
  dmy[bd][bm][by] = true;
  if (bm > 12) return;
  if (bd > 31) return;
  if (!(by % 4) && bm == 2 && bd > 29) return;
  if ((by % 4) && bm == 2 && bd >= 29) return;
  if (y - by == 18) {
    if (bm < m) {
      puts("YES");
      exit(0);
    } else {
      if (bm == m && bd <= d) {
        puts("YES");
        exit(0);
      }
    }
  }
  if (y - by > 18) {
    puts("YES");
    exit(0);
  }
  dfs(d, m, y, by, bd, bm);
  dfs(d, m, y, bm, by, bd);
  dfs(d, m, y, bd, by, bm);
  dfs(d, m, y, by, bm, bd);
  dfs(d, m, y, bm, bd, by);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int d, m, y, bd, bm, by;
  string s;
  cin >> s;
  d = (s[0] - '0') * 10 + (s[1] - '0');
  m = (s[3] - '0') * 10 + (s[4] - '0');
  y = (s[6] - '0') * 10 + (s[7] - '0');
  cin >> s;
  bd = (s[0] - '0') * 10 + (s[1] - '0');
  bm = (s[3] - '0') * 10 + (s[4] - '0');
  by = (s[6] - '0') * 10 + (s[7] - '0');
  dfs(d, m, y, by, bd, bm);
  dfs(d, m, y, bm, by, bd);
  dfs(d, m, y, bd, by, bm);
  dfs(d, m, y, by, bm, bd);
  dfs(d, m, y, bm, bd, by);
  dfs(d, m, y, bd, bm, by);
  puts("NO");
  return 0;
}
