#P9095. PA Contest Problem Assignment

    ID: 22254 Type: Default 1000ms 256MiB

PA Contest Problem Assignment

PA Contest Problem Assignment

Matthew is preparing for the PA online contest. The contest consists of 5 rounds numbered from \(1\) to \(5\). In each round, there are 3 groups labeled A, B, and C. In rounds \(1\) to \(4\), each group receives exactly 1 problem. In round \(5\), each group is assigned 2 problems. Hence, a total of \(18\) problems must be chosen and assigned to \(15\) distinct positions (each position is defined by a round and a group), with positions 5A, 5B, and 5C each receiving 2 problems.

Matthew has collected ideas for \(n\) problems. Each problem idea is suitable for exactly one specific position (for example, "3B" or "5C") and no other position. Your task is to determine whether it is possible to select \(18\) problem ideas from his collection such that every position receives the required number of problems. If it is possible, you must output one valid assignment scheme.

inputFormat

The input begins with an integer \(n\) (\(1 \le n\)) representing the number of available problem ideas. The following \(n\) lines each contain a string that denotes the unique position for which that problem idea is suitable. The valid position strings are: 1A, 1B, 1C, 2A, 2B, 2C, 3A, 3B, 3C, 4A, 4B, 4C, 5A, 5B, 5C. Note that for positions 5A, 5B, and 5C exactly 2 problems are required, while for every other position exactly 1 problem is required.

outputFormat

If a valid assignment scheme is impossible, output a single line containing NO. Otherwise, output YES on the first line, followed by 15 lines corresponding to each position in the order of rounds 1 to 5 (for each round, groups A, B, and C in that order). For rounds 1 to 4, each line should be formatted as:

rX: index

where r is the round number and X is the group letter, and index is the 1-indexed position in the input of the chosen problem for that slot. For round 5, each line should be formatted as:

5X: index1 index2

where index1 and index2 are the two selected problem idea indices for that slot (choose the first available ones in input order). Any valid assignment scheme is acceptable.

sample

18
1A
1B
1C
2A
2B
2C
3A
3B
3C
4A
4B
4C
5A
5A
5B
5B
5C
5C
YES

1A: 1 1B: 2 1C: 3 2A: 4 2B: 5 2C: 6 3A: 7 3B: 8 3C: 9 4A: 10 4B: 11 4C: 12 5A: 13 14 5B: 15 16 5C: 17 18

</p>