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: c[0]
, ..., c[9]
, where c[i]
(0 ≤ c[i]
≤ 100 000) is the number of digits i that Anton has given to Bogdan. The sum of c[i]
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.