P6458 [COCI 2006/2007 #5] LIGA

Description

There are $n$ teams participating in a tournament. Each team has $5$ values: total matches played, number of wins, number of draws, number of losses, and points. Each win gives $3$ points, each draw gives $1$ point, and losses give $0$ points. However, because the table was damaged, some values are unreadable (shown as `?`). You need to infer the missing values from the other data and restore the table. It is known that each team plays at most $100$ matches. It is guaranteed that each damaged entry has exactly one original value that matches it. Note that the win counts of all teams may not match the tournament logic. You may treat each team as an independent individual.

Input Format

The first line contains an integer $n$, the number of teams. The next $n$ lines each contain $5$ integers or `?`, in order: total matches played, wins, draws, losses, and points.

Output Format

Output $n$ lines. Each line contains $5$ integers, the fully restored table. **A unique solution is guaranteed.**

Explanation/Hint

#### Constraints For $100\%$ of the testdata, $1\le n\le 1000$. #### Notes **Translated from [COCI2006-2007](https://hsin.hr/coci/archive/2006_2007/) [CONTEST #5](https://hsin.hr/coci/archive/2006_2007/contest5_tasks.pdf) *T4 LIGA***。 Translated by ChatGPT 5