시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
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+XHJcbnwtLS18LS0tfC0tLXwtLS18LS0tfFxyXG58I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