#pragma once
#include <iostream>
#include <vector>
#include <string>
#include <ctime>
#include <stdio.h>
#include <time.h>
#include <locale>

#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_NONSTDC_NO_DEPRECAT
#pragma warning(disable : 4996)


class Date {
public:
	int y, m, d;

	explicit Date(int year, int month, int day) {
		y = year;
		m = month;
		d = day;
	}

	bool IsLeap() const {
		if ((this->y % 4 == 0 && this->y % 100 != 0) || this->y % 400 == 0)
			return 1;
		return 0;
	}

	std::string ToString() const {
		std::string str_d = std::to_string(this->d + 100).erase(0, 1);
		std::string str_m = std::to_string(this->m + 100).erase(0, 1);
		std::string str_y = std::to_string(this->y + 10000).erase(0, 1);
		std::string str_date = str_d + "." + str_m + "." + str_y;
		return str_date;
	}

	Date DaysLater(int days) const {
		int new_d = this->d;
		int new_m = (this->m + 9) % 12;
		int new_y = this->y - new_m / 10;;
		int64_t days_count = 365 * new_y + new_y / 4 - new_y / 100 + new_y / 400 +
			(new_m * 306 + 5) / 10 + (new_d - 1);
		days_count += days;
		new_y = (10000 * days_count + 14780) / 3652425;
		int ddd = days_count - (365 * new_y + new_y / 4 - new_y / 100 + new_y / 400);
		if (ddd < 0) {
			new_y = new_y - 1;
			ddd = days_count - (365 * new_y + new_y / 4 - new_y / 100 + new_y / 400);
		}
		int mi = (100 * ddd + 52) / 3060;
		int mm = (mi + 2) % 12 + 1;
		new_y = new_y + (mi + 2) / 12;
		int dd = ddd - (mi * 306 + 5) / 10 + 1;
		Date new_date(new_y, mm, dd);
		return new_date;
	}

	int DaysLeft(const Date& date) const {
		int d1 = this->d;
		int m1 = (this->m + 9) % 12;
		int y1 = this->y - m1 / 10;;
		int64_t days_count1 = 365 * y1 + y1 / 4 - y1 / 100 + y1 / 400 +
			(m1 * 306 + 5) / 10 + (d1 - 1);

		int d2 = date.d;
		int m2 = (date.m + 9) % 12;
		int y2 = date.y - m2 / 10;;
		int64_t days_count2 = 365 * y2 + y2 / 4 - y2 / 100 + y2 / 400 +
			(m2 * 306 + 5) / 10 + (d2 - 1);
		return days_count2 - days_count1;
	}
};