#P6459. Valid Tennis Rounds
Valid Tennis Rounds
Valid Tennis Rounds
Two players participate in a tennis match which consists of \(n\) rounds. Each round is composed of between 1 to 5 individual encounters (games). The result of each encounter is given in the format A:B
where A
is the number of games won by the first player and B
by the second player.
The rules for each encounter are as follows:
- An encounter is considered won by a player if that player has won at least 6 balls and has at least a 2-ball lead. In other words, if either \(A \ge 6\) or \(B \ge 6\) and \(|A - B| \ge 2\), then the encounter is valid and the corresponding player is its winner.
- If the results of both the first and second encounters in a round are exactly
6:6
, then a special decider encounter is played to determine the winner of the round. In such a case, the round must contain exactly 3 encounter results. The first two results (both 6:6) are used solely to trigger the final decider; only the decider encounter (which must follow the normal winning rule and cannot be6:6
) decides the round. - Normally, as soon as one player wins two encounters in a round, the round ends and any subsequent encounters (if given) render the round invalid.
In addition, there is one special player – federer
– who never loses an encounter. This means that if either player's name is "federer", then in every encounter that player must be the winner.
Your task is to verify whether all \(n\) rounds of the match are valid according to the above rules. Print valid
if every round is valid, otherwise print invalid
.
inputFormat
Input is read from standard input and has the following format:
first_player second_player n round_1_results round_2_results ... round_n_results
The first line contains two strings representing the names of the players. The second line contains an integer \(n\), the number of rounds. Each of the following \(n\) lines contains the results for a round. Each round result is a space‐separated list of encounter results (between 1 and 5), each in the format A:B
.
outputFormat
Output a single line. Print valid
if every round is valid according to the rules. Otherwise, print invalid
.
sample
nadal roger
1
6:4 6:4
valid