시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 179 25 22 13.836%

문제

K리그를 좋아하는 상근이는 요즘 들떠있다. 바로 K리그 클래식과 챌린지를 TV에서 중계해주기 때문이다. 어느날 전반전이 끝나고 TV광고를 보는 동안 순위표를 이용한 수학 게임을 생각했다.

순위표는 각 팀의 정보 다섯 개를 가지고 있다. 팀의 정보는 팀의 경기 수, 이긴 경기의 수, 진 경기의 수, 비긴 경기의 수, 얻은 승점으로 총 다섯 가지이다. 경기에서 이겼을 경우에는 승점 3점을 가져가고, 비겼을 경우에는 1점을 가져간다.

상근이는 순위표의 일부 숫자가 없다고 하더라도, 다른 정보를 통해서 유추할 수 있다는 사실을 알아냈다.

일부 숫자가 지워진 순위표가 주어졌을 때, 지워진 숫자를 알아내는 프로그램을 작성하시오.

각 팀의 정보는 서로 연관이 없다. 예를 들어, 실제 경기에서는 일어나지 않겠지만, 모든 팀이 모든 게임을 이겼을 수도 있다.

각 팀은 최대 100경기를 소화했다.

입력

첫째 줄에 팀의 수 N이 주어진다. (1 ≤ N ≤ 1000)

다음 N개 줄에는 각 팀의 정보 다섯 개가 공백으로 구분되어져서 주어진다. 정보는 정수 또는 물음표이며, 물음표인 경우에는 그 정보의 값을 알 수 없는 경우이다.

항상 빈 칸을 채우는 방법의 수가 유일한 경우만 입력으로 주어진다.

출력

지워진 칸을 채운 순위표를 출력한다. 순위표는 입력으로 주어진 순서대로 출력해야 한다.

예제 입력 1

5
27 21 3 3 66
27 18 6 3 ?
? 15 5 7 50
? 14 7 5 ?
? 14 ? 8 47

예제 출력 1

27 21 3 3 66
27 18 6 3 60
27 15 5 7 50
26 14 7 5 49
27 14 5 8 47
W3sicHJvYmxlbV9pZCI6IjMwMzEiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWI5YWNcdWFkZjgiLCJkZXNjcmlwdGlvbiI6IjxwPktcdWI5YWNcdWFkZjhcdWI5N2MgXHVjODhiXHVjNTQ0XHVkNT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