eolymp
bolt
Try our new interface for solving problems
Problems

Secret Code

Secret Code

Bogdan is a fan of riddles and puzzles. He asked his friend Anton to come up with a secret code that Bogdan would then decode.

Anton has decided to use a non-negative integer without extra leading zeroes as a secret code. The code must satisfy the following condition. If you consider any three consecutive digits of it as a three-digit integer, it is divisible by three.

Anton has given all digits of his secret code, as well as possibly some other digits, to Bodgan. He claims that the maximal number satisfying the above condition that can be created out of these digits is the secret code.

Help Bogdan to find out what is the secret code.

Input

One line contains 10 integers: c0, ..., c9, where ci (0ci100 000) is the number of digits i that Anton has given to Bogdan. The sum of ci is strictly positive and doesn’t exceed 100 000.

Output

Print the maximal integer that can be created out of these digits. It must satisfy the condition that an integer formed by any three consecutive digits is divisible by three. It is not required to use all of the given digits. Note that any one-digit or two-digit number automatically satisfies the above condition, because it doesn’t have three consecutive digits. The answer must not contain extra leading zeroes: the first digit can be 0 only if the number is zero, in this case it must be the only digit.

Time limit 1 second
Memory limit 128 MiB
Input example #1
1 2 3 0 0 0 0 0 0 0
Output example #1
21021
Input example #2
1 1 1 1 1 1 1 1 1 1
Output example #2
9876543210
Source 2018, XXVI Командный чемпионат школьников Санкт-Петербурга по программированию, 18 октября, Задача H