Consider the following "magic" ring, filled with the numbers to , and each line adding to nine.
Working clockwise, and starting from the group of three with the numerically lowest external node (4,3,2 in this example), each solution can be described uniquely. For example, the above solution can be described by the set: 4,3,2; 6,2,1; 5,1,3.
It is possible to complete the ring with four different totals: 9, 10, 11, and 12. There are eight solutions in total.
By concatenating each group it is possible to form 9-digit strings; the strings for a ring where total is are and .
Given , which represents the and the total print all concatenated solution strings in alphabetical sorted order.
Note: It is guaranteed that solution will exist for testcases.