Under construction

Still being built. Things may change

Date Validation

Interview

Time limit1sMemory limit128 MB

Summary
Read day, month, year triples until a terminator and print whether each represents a real calendar date, accounting for leap years.
Level

Easy3 of 10

Topics
Implementation, Math
Solved
No attempts yet

Problem

A date is often written as three numbers for the day, month, and year. For instance, August 14, 2004 can be written as 14 8 2004. A program that accepts dates must decide whether the three numbers describe a date that really exists.

A date is invalid in cases such as these:

  • The month is not between 1 and 12.
  • The day does not exist in the given month.
  • The date is February 29, but the year is not a leap year.

Most months have 31 days. April, June, September, and November have 30 days. February has 28 days in a common year and 29 days in a leap year. A year divisible by 4 is usually a leap year, but a year divisible by 100 is not. A year divisible by 400 is a leap year after all.

Input

The input consists of several dates, one per line. Each date contains three non-negative integers d m y, representing the day, month, and year. The day and month are always less than 100, and the year is always between 1700 and 2200, inclusive.

The line 0 0 0 terminates the input and is not judged.

Output

For each input date, output one line containing a single word. Print Valid if the three numbers describe a valid date, and print Invalid otherwise.

Examples1

  1. Example 1

    Input
    14 8 2004
    12 0 2004 
    32 1 1976
    29 2 1974
    29 2 1976
    0 0 0
    
    Expected output
    Valid
    Invalid
    Invalid
    Invalid
    Valid