#include <bits/stdc++.h>
using namespace std;
int d, m, y, bd, bm, by, D, M, Y, age, mage;
int mm[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main() {
  scanf("%d.%d.%d", &d, &m, &y);
  scanf("%d.%d.%d", &bd, &bm, &by);
  D = bd;
  M = bm;
  Y = by;
  age = 0;
  while (D != d || m != M || y >= Y) {
    if (Y % 4 == 0)
      mm[2] = 29;
    else
      mm[2] = 28;
    D++;
    if (D == mm[M] + 1) D = 1, M++;
    if (M == 13) M = 1, Y++;
    if ((M == bm && D == bd) ||
        (bm == 2 && bd == 29 && Y % 4 && D == 1 && M == 3))
      age++;
    if (d == D && M == m && y == Y) break;
  }
  mage = age;
  age = 0;
  swap(bm, by);
  D = bd;
  M = bm;
  Y = by;
  while (D != d || m != M || y >= Y) {
    if (D > 31 || M > 12) break;
    if (Y % 4 == 0)
      mm[2] = 29;
    else
      mm[2] = 28;
    D++;
    if (D == mm[M] + 1) D = 1, M++;
    if (M == 13) M = 1, Y++;
    if ((M == bm && D == bd) ||
        (bm == 2 && bd == 29 && Y % 4 && D == 1 && M == 3))
      age++;
    if (d == D && M == m && y == Y) break;
  }
  mage = max(mage, age);
  age = 0;
  swap(bd, bm);
  D = bd;
  M = bm;
  Y = by;
  while (D != d || m != M || y >= Y) {
    if (D > 31 || M > 12) break;
    if (Y % 4 == 0)
      mm[2] = 29;
    else
      mm[2] = 28;
    D++;
    if (D == mm[M] + 1) D = 1, M++;
    if (M == 13) M = 1, Y++;
    if ((M == bm && D == bd) ||
        (bm == 2 && bd == 29 && Y % 4 && D == 1 && M == 3))
      age++;
    if (d == D && M == m && y == Y) break;
  }
  mage = max(mage, age);
  age = 0;
  swap(by, bm);
  D = bd;
  M = bm;
  Y = by;
  while (D != d || m != M || y >= Y) {
    if (D > 31 || M > 12) break;
    if (Y % 4 == 0)
      mm[2] = 29;
    else
      mm[2] = 28;
    D++;
    if (D == mm[M] + 1) D = 1, M++;
    if (M == 13) M = 1, Y++;
    if ((M == bm && D == bd) ||
        (bm == 2 && bd == 29 && Y % 4 && D == 1 && M == 3))
      age++;
    if (d == D && M == m && y == Y) break;
  }
  mage = max(mage, age);
  age = 0;
  swap(bd, bm);
  D = bd;
  M = bm;
  Y = by;
  while (D != d || m != M || y >= Y) {
    if (D > 31 || M > 12) break;
    if (Y % 4 == 0)
      mm[2] = 29;
    else
      mm[2] = 28;
    D++;
    if (D == mm[M] + 1) D = 1, M++;
    if (M == 13) M = 1, Y++;
    if ((M == bm && D == bd) ||
        (bm == 2 && bd == 29 && Y % 4 && D == 1 && M == 3))
      age++;
    if (d == D && M == m && y == Y) break;
  }
  mage = max(mage, age);
  age = 0;
  swap(by, bm);
  D = bd;
  M = bm;
  Y = by;
  while (D != d || m != M || y >= Y) {
    if (D > 31 || M > 12) break;
    if (Y % 4 == 0)
      mm[2] = 29;
    else
      mm[2] = 28;
    D++;
    if (D == mm[M] + 1) D = 1, M++;
    if (M == 13) M = 1, Y++;
    if ((M == bm && D == bd) ||
        (bm == 2 && bd == 29 && Y % 4 && D == 1 && M == 3))
      age++;
    if (d == D && M == m && y == Y) break;
  }
  mage = max(mage, age);
  if (mage >= 18)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
