#P5690. Minimum Digit Changes to Form a Valid Date

    ID: 18918 Type: Default 1000ms 256MiB

Minimum Digit Changes to Form a Valid Date

Minimum Digit Changes to Form a Valid Date

Alice wrote a date on a paper in the format MM-DD (where both MM and DD are two-digit numbers), but the date might not be valid. Bob is asked to change some of the digits so that the resulting date is valid. A valid date must satisfy:

  • The month MM is between 01 and 12.
  • The day DD is valid for the corresponding month. Months with 31 days are: January, March, May, July, August, October and December; months with 30 days are: April, June, September and November; February always has 28 days.

Your task is to calculate the minimum number of digits Bob needs to change in order to make the date valid.

Mathematically, if the input date is represented as \( s = s_0s_1-s_3s_4 \), and we want to transform it into a valid date \( t = t_0t_1-t_3t_4 \), then the cost is defined as:

\[ \text{cost}(s,t)=\sum_{i\in\{0,1,3,4\}}[s_i\neq t_i], \]

Find the valid date \( t \) (of the form \( MM-DD \)) which minimizes the cost.

inputFormat

The input consists of a single line containing the date string in the format MM-DD.

outputFormat

Output a single integer representing the minimum number of digit changes required to make the input date valid.

sample

02-30
1