Figure 1.
Figure 1 shows a numerical matrix. Each row, each column, and both diagonals of the matrix are considered as a five-digit prime number. The rows are read from left to right. The columns are read from top to bottom. Both diagonals are read from left to right.
Write a program that, based on the given data, finds such matrices. The following conditions must be met:
The prime numbers must all have the same digit sum (for example, ).
The digit in the top left corner of the matrix is given in the input (for example, ).
The matrix may contain repeated prime numbers.
If there is more than one solution, output all of them.
A five-digit prime number cannot begin with zero, for example, is NOT a prime number.
The input consists of two lines. The first line contains the required digit sum of the primes, and the second line contains the digit in the top left corner of the matrix. It is guaranteed that at least one solution exists for the given data.
For each solution, output five lines, each containing a five-digit prime number. The solutions should be sorted by the prime in the first row, then the second row, and so on. Separate different solutions with a blank line.
Example 1