Days of the Week#13105

Days of the Week (Editorial)

Number the days of the week from (monday) to (sunday), and let d_1, d_2, d_3 be the days of the week of the 1/8 stage, the 1/4 stage and SEERC. If one stage is held on weekday and the next one on weekday , the number of days between them is positive and congruent to b - a modulo . So it is at least g(a, b), where g(a, b) = (b - a) \bmod 7 taken in \{0, \ldots, 6\}, except that becomes : two stages on the same weekday are on different calendar days, hence at least a week apart.

The number of days from the 1/8 stage to SEERC inclusive is the sum of the two gaps plus one, so it is at least g(d_1, d_2) + g(d_2, d_3) + 1. This value is reached by holding every stage on the earliest suitable day after the previous one. The answer is therefore g(d_1, d_2) + g(d_2, d_3) + 1, which always lies between and .

In C++ and Java, (b - a) \,\%\, 7 is negative when b < a; use ((b - a) \,\%\, 7 + 7) \,\%\, 7.

The complexity is per test case.