#include <iostream>
#include <string>
using namespace std;
string reverse(string s){
string y;
for (int i = 0; !s.empty(); i++){
if (s.back() != '.'){
y.push_back(s.back());
s.pop_back();
}
if (s.back() == '.') s.pop_back();
}
return y;
}
bool is_leap(int year){
bool leap;
if ((year % 400) == 0) leap = true;
else if ((year % 100) == 0) leap = false;
else if ((year % 4) == 0) leap = true;
else leap = false;
return leap;
}
int get_days (int month, int year){
int days;
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
days = 31;
break;
case 4:
case 6:
case 9:
case 11:
days = 30;
break;
case 2:
is_leap(year)?days = 29:days=28;
break;
default:
days = -1;
}
return days;
}
int main() {
bool booly = false;
string s,y;
getline(cin, s);
y = reverse(s);
int day = stoi(y.substr(0,2));
int month = stoi(y.substr(2,2));
int year = stoi(y.substr(4,4));
cout << (((month>=1)&&(month<=12)&&(day >= 1)&&(day <= (get_days(month, year))))?"YES":"NO");
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RyaW5nIHJldmVyc2Uoc3RyaW5nIHMpewoJc3RyaW5nIHk7Cglmb3IgKGludCBpID0gMDsgIXMuZW1wdHkoKTsgaSsrKXsKCQlpZiAocy5iYWNrKCkgIT0gJy4nKXsKCQkJeS5wdXNoX2JhY2socy5iYWNrKCkpOwoJCQlzLnBvcF9iYWNrKCk7CgkJfQoJCWlmIChzLmJhY2soKSA9PSAnLicpIHMucG9wX2JhY2soKTsKCX0KCXJldHVybiB5Owp9Cgpib29sIGlzX2xlYXAoaW50IHllYXIpewoJYm9vbCBsZWFwOwoJaWYgKCh5ZWFyICUgNDAwKSA9PSAwKSBsZWFwID0gdHJ1ZTsKCWVsc2UgaWYgKCh5ZWFyICUgMTAwKSA9PSAwKSBsZWFwID0gZmFsc2U7CgllbHNlIGlmICgoeWVhciAlIDQpID09IDApIGxlYXAgPSB0cnVlOwoJZWxzZSBsZWF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