Programming contests

DEIK Regionális Programozó Csapatverseny, középiskolai kategória, 2024. december 1.

December 1, 2024, 10:00 AM – December 1, 2024, 3:00 PM

PIN

After decoding the encrypted text, you were able to determine the coordinates of the new secret hideout of the terrorists. However, it was not a big surprise that you encountered a PIN pad when you arrived to the hideout. The numbers 1-9 are arranged in the PIN pad in a 3x3 array (so the first row contains the numbers 1,2,3 from left to right, the second row contains the numbers 4,5,6 and the last row contains the numbers 7,8,9). The number 0 is directly below the number 8 on the pad.
Luckily, after spending the GPD of a smaller african nation on the Secret Service they were able to send you an envelope which contained the PIN code...kinda. Since the observers were only able to watch the terrorists from far away, they were not able to tell you the exact PIN, only that the digits of the actual PIN is "somewhere around" (horizontally and vertically, but never diagonally) the observed digits. This means that for example if the observed digit was 5, then the actual digit could of course be 5, or maybe 2 (above), or 4 (left) or 6 (right) or even 8 (below). Your task is to determine every possible PIN codes so that you may enter into the hideout!

Input

The input consists of a single line, closed with an end of line character. The line contains a string of at least 1 and at most 8 characters n whose every character is a digit between 0 and 9 (both endpoints are included and repetitions are allowed). This "number" is the observed PIN code. Important note that the PIN code can start with the number 0.

Output

The output is a single line which contains the possible PIN codes created by using the above rule. Each code should be separated from the next with a single space character and the codes should be in ascending order. Every number should only appear at most once.

Example

Input:
  1. 007
download as text file Output:
  1. 004 007 008 084 087 088 804 807 808 884 887 888
download as text file
University of Debrecen; Faculty of Informatics; v. 09/30/2024