시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 14 4 4 30.769%

문제

|---|---|---|---|---|
| 1 | 1 | 3 | 5 | 1 |
|---|---|---|---|---|
| 3 | 3 | 2 | 0 | 3 |
|---|---|---|---|---|
| 3 | 0 | 3 | 2 | 3 |
|---|---|---|---|---|
| 1 | 4 | 0 | 3 | 3 |
|---|---|---|---|---|
| 3 | 3 | 3 | 1 | 1 |
|---|---|---|---|---|  (그림 1)

[그림 1]은 소수방진의 예를 보여준다. 소수방진이란 각 열, 행, 그리고 두 개의 대각선이 모두 5자리 소수로 해석되는 5x5 형태의 수의 나열을 말한다. 열은 위에서 아래로, 행은 왼쪽에서 오른쪽으로, 대각선은 둘 다 왼쪽에서 오른쪽으로 읽는다. 이러한 소수방진 중에서 다음 조건을 만족하는 것을 찾고자 한다.

  • 모든 소수들의 각 자리의 수의 합이 같아야 한다. (예제의 경우 11)
  • 가장 좌측 상단의 수는 미리 정해져있다. (예제의 경우 1)
  • 같은 소수가 한 소수방진에 두 번 이상 사용될 수 있다.
  • 가능한 답이 여러 개라면 모두 출력한다.
  • 0으로 시작하는 것은 5자리 소수로 보지 않는다. 예를 들어 00003은 5자리 소수가 아니다.

입력

입력의 첫번째 줄에 각 소수들이 만족해야 할 각 자리의 수의 합이 주어진다.

입력의 두번째 줄에 소수방진의 가장 좌측 상단의 수가 주어진다.

출력

가능한 소수방진을 모두 출력한다. 각 소수방진은 5줄에 걸쳐 5글자씩 출력하며, 각 소수방진 사이에는 빈 줄이 하나씩 존재한다.

예제 입력 1

11
1

예제 출력 1

11351
14033
30323
53201
13313

11351
33203
30323
14033
33311

13313
13043
32303
50231
13331

힌트

W3sicHJvYmxlbV9pZCI6IjU1MTkiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWMxOGNcdWMyMThcdWJjMjlcdWM5YzQiLCJkZXNjcmlwdGlvbiI6IjxwcmU+XHJcbnwtLS18LS0tfC0tLXwtLS18LS0tfFxyXG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