Expiration Date
InterviewTime limit1sMemory limit1024 MB
For each food's expiration date, try every valid year/month/day reading and print invalid, safe, or unsafe by comparing with today's date.
- Level
Easy3 of 10
- Topics
- Implementation, Brute force
- Solved
- No attempts yet
Problem
Hanbyeol has lived alone for one year and is starting to worry whether the food in her refrigerator is still within its expiration date. However, she cannot tell the order of year, month, and day in the dates printed on the packages.
Date formats differ by country. There are three main formats.
- Year/Month/Day: East Asian countries such as South Korea, Japan, China, Lithuania, Mongolia, Bhutan, and Hungary
- Day/Month/Year: most other countries, including Greece, the Netherlands, Denmark, Germany, Russia, Vietnam, Egypt, and Italy
- Month/Day/Year: some English-speaking countries such as the United States, Guam, and the Philippines
For example, the date 10/12/32 can be either
- December 10, 2032 when read as Day/Month/Year
- October 12, 2032 when read as Month/Day/Year
December 32 does not exist, so the date cannot be in Year/Month/Day format (for example, year , month , day ).
Hanbyeol wants to know whether the food is safe under every format that reads the date as a valid date. Write a program that helps her decide.
Input
The first line contains integers , , and separated by spaces. Today is year month day. (, and year month day is a valid date)
The next line contains the number of food items . ()
Each of the next lines contains integers , , and separated by spaces, which is the expiration date of one food item. The expiration date is written in the form //. ()
All dates are between the years and , and only the remainder of the year divided by is given.
Output
For each date, print one of the following on its own line.
invalid: the date is not valid under any formatsafe: under every format that reads the date as a valid date, today is before or on the expiration dateunsafe: otherwise
Hint
, , , , , , and months each have days.
, , , and months each have days.
February has days in a leap year and days otherwise. Since the years in this problem are between and , every year divisible by is a leap year.