#include<string>
#include<stdlib.h>
#include<stdio.h>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
bool isrun(int a) {
if ((a % 4 == 0 && a % 100 != 0) || a % 400 == 0)
return true;
else
return false;
}
bool isbig(int a) {
int b[] = { 1,3,5,7,8,10,12 };
for (int i = 0; i < 7; i++)
{
if (a == b[i])
return true;
}
return false;
}
using namespace std;
int main() {
int Year;
int Mo;
int weeks;
int days;
int weekdays;
int outdays;
int sumdays;
cin >> Year;
cin >> Mo;
cin >> weeks;
cin >> days;
weekdays = ((Year - 2000) / 4 + (Year - 2000) * 365 + 6) % 7;
int weekday[12];
weekday[0] = (weekdays + 31) % 7;
weekdays = weekday[0];
if (isrun(Year))
{
weekday[1] = (weekdays + 29) % 7;
weekdays = weekday[1];
}
else {
weekday[1] = (weekdays + 28) % 7;
weekdays = weekday[1];
}
for (int i = 2; i < 12; i++)
{
if (isbig(i + 1)) {
weekday[i] = (weekdays + 31) % 7;
weekdays = weekday[i];
}
else {
weekday[i] = (weekdays + 30) % 7;
weekdays = weekday[i];
}
}
if (isrun(Year))
{
if (Mo == 2)
{
if ((weeks * 7 + days) > 29)
{
cout << "0" << endl;
return 0;
}
else if (days > 7)
{
cout << "0" << endl;
return 0;
}
else {
outdays = weeks * 7 + days;
sumdays = outdays + 31;
outdays = outdays - weekday[1];
}
}
else if (isbig(Mo))
{
if ((weeks * 7 + days) > 31)
{
cout << "0" << endl;
return 0;
}
else if (days > 7)
{
cout << "0" << endl;
return 0;
}
else {
outdays = weeks * 7 + days;
outdays = outdays - weekday[Mo - 1];
}
}
else {
if ((weeks * 7 + days) > 30)
{
cout << "0" << endl;
return 0;
}
else if (days > 7)
{
cout << "0" << endl;
return 0;
}
else {
outdays = weeks * 7 + days;
outdays = outdays - weekday[Mo - 1];
}
}
}
else {
if (Mo == 2)
{
if ((weeks * 7 + days) > 28)
{
cout << "0" << endl;
return 0;
}
else if (days > 7)
{
cout << "0" << endl;
return 0;
}
else {
outdays = weeks * 7 + days;
sumdays = outdays + 31;
outdays = outdays - weekday[1];
}
}
else if (isbig(Mo))
{
if ((weeks * 7 + days) > 31)
{
cout << "0" << endl;
return 0;
}
else if (days > 7)
{
cout << "0" << endl;
return 0;
}
else {
outdays = weeks * 7 + days;
outdays = outdays - weekday[Mo - 1];
}
}
else {
if ((weeks * 7 + days) > 30)
{
cout << "0" << endl;
return 0;
}
else if (days > 7)
{
cout << "0" << endl;
return 0;
}
else {
outdays = weeks * 7 + days;
outdays = outdays - weekday[Mo - 1];
}
}
}
if (Mo > 9)
{
if (outdays > 9)
cout << Year << "-" << Mo << "-" << outdays << endl;
else
cout << Year << "-" << Mo << "-0" << outdays << endl;
}
else {
if (outdays > 9)
cout << Year << "-0" << Mo << "-" << outdays << endl;
else
cout << Year << "-0" << Mo << "-0" << outdays << endl;
}
return 0;
}
08-18
08-18
08-18
08-18