An iconic building in Heung Shing: Heung Shing Concert Hall, is filled with people watching performances from Heung Shing Philharmonic during weekends. People have to buy a ticket to listen to a single piece, and probably thousands of people want to get those tickets, so a well-regulated online ticketing system is created.
There are $N$ pieces that will be performed, numbered from $1$ to $N$, where the $i^{th}$ piece has a title of $S_i$ and $A_i$ tickets for sale. Each individual can buy one and only one ticket. There are exactly $M$ individuals, numbered $1$ to $M$, where the $i^{th}$ individual’s name is $T_i$. As only $A_i$ individuals can buy tickets to watch the $i^{th}$ piece, to satisfy the will of individuals better, every individual chooses exactly 3 distinct pieces numbered $i$, $j$ and $k$.
And with the first come first serve basis, for every person from $1$ to $M$, according to their chosen $i$, $j$ and $k$, ticket are assigned by this way: if there are tickets remaining for $i^{th}$ piece, a $i^{th}$ ticket piece will be sold to him/her. Else if there are tickets remaining for $j^{th}$ piece, a $j^{th}$ ticket piece will be sold to him/her. Else if there are tickets remaining for $k^{th}$ piece, a $k^{th}$ ticket piece will be sold to him/her. Else, the individual cannot get any tickets.
In a title of a piece, only the alphabets of the start of every word are capitalised, while other alphabets are all in lowercase. However, due to web attacks from Hackerland, some information in the ticketing system is being corrupted. For every $S_i$, some of its capital letters turned into lowercase ones, while some lowercase letters turned into capital ones (possibly none).
Given the corrupted titles of pieces, the number of tickets for sale for each piece, and everyone’s preferences. Find out the final list of ticket selling arrangements.
Input Specification
The first line contains an integer $N$.
The next $N$ lines contain $S_i$ quoted with "s and an integer $A_i$.
The next line contains an integer $M$.
The next $M$ lines contains the name of the $i^{th}$ individual $T_i$, and the numbers of their 3 chosen pieces $i$, $j$ and $k$ in order.
Output Specification
Output $N$ lines: [name of i-th piece]: [ppl 1], [ppl 2], ...
Subtasks
For all cases,
$3 \le N \le 1000$
$1 \le |S_i|, |T_i| \le 20$
$0 \le A_i \le 50$
$1 \le M \le 1000$
For every $1 \le i \le N$, $S_i$ does not contain "s
For every $1 \le i \le M$, $T_i$ contains alphabets only (no spaces).
Subtask 1: $A_i = 0$ for every $1 \le i \le N$ (40 pts)
Subtask 2: There is no data corruption occured (40 pts)
Subtask 3: No additional constraints (20 pts)
Sample Test Cases
| Input | Output | |
|---|---|---|
| 3 "TChaikovsky 5th Symphony" 1 "Mahler’S fIfth sYMPHONY" 2 "dvoraK SymphOny NO.9" 2 6 Alice 1 2 3 Bob 2 1 3 Charlie 1 3 2 David 3 1 2 Emma 3 1 2 Fred 1 2 3 |
Tchaikovsky 5th Symphony: Alice Mahler’s Fifth Symphony: Bob, Emma Dvorak Symphony No.9: Charlie, David |
|
The concert names without being corrupted are:
> There is 1 ticket left for piece 1, and Alice can buy it. |
||
| 4 "Violin and it’s Concerto" 1 "violA concertO" 2 "cELLO cONcERTO!" 1 "double base’S concerto" 2 5 James 2 1 4 John 2 3 4 Jack 2 3 1 Jake 3 1 4 Jacob 1 2 3 |
Violin And It’s Concerto: Jake Viola Concerto: James, John Cello Concerto!: Jack Double Base’s Concerto: |
|
Scoring: Per Subtask
Authored by wy24215
Appeared in 2026 Mini Comp 1 [WY Interschool Pre-CCC]