This page is still under construction.

Parts of this page are still being built. What you see may change.

Addition Affliction

Interview

Time limit1sMemory limit256 MB

Summary
Reorder each sum so numbers that pair to a multiple of 10 come first in adjacent pairs, using the most pairs and the smallest lexicographic order.
Level

Medium6 of 10

Topics
Greedy, Math, Sorting
Solved
No attempts yet

Problem

Albert is a computer science student who loves math. His grasp of the basics is weak, and addition has given him trouble since he was small.

Addition keeps coming up in daily life, so Albert wants to get comfortable with it at last. The way he sees it, an addition is easiest when the numbers add up to a multiple of 10.

Doing the work for him would not help him practice. Reorder the terms of each practice expression instead, so that the expression is easier for him to work through.

Input

The input has several lines. Each line is a sum of nonnegative integers written as

x1+x2+⋯+xNx_1+x_2+\dots+x_N

with 2≤N<10002 \le N < 1000, and every xix_i satisfies 0≤xi≤1000000 \le x_i \le 100000. Every number is written without leading zeros.

A line has no whitespace and contains only digits and plus signs. There are at most 100 expression lines. A line holding only 0 ends the input, and that line is not processed.

Output

For each expression print one line holding the terms in a new order. The order must follow these rules.

Two numbers whose sum is a multiple of 10 form a pair. A number belongs to at most one pair, and the number of pairs must be as large as possible, so no two unpaired numbers may add up to a multiple of 10. Every paired number comes before every unpaired number, and the two numbers of a pair are next to each other.

Several orders can satisfy the rules. Print the one that comes first in lexicographic order. Compare two orders term by term by numeric value, and the order with the smaller value at the first position where they differ comes first.

Write the answer in the same form as the input: a plus sign between consecutive numbers and no whitespace.

Examples2

  1. Example 1

    Input
    1+2+3+4+9
    153+214+64+7+26
    1+2+3+4+5
    1951+1569+481+4823+142+4677
    10+9+8+7+2+1
    1+3+5+10+15+20+30
    0
    
    Expected output
    1+9+2+3+4
    7+153+26+64+214
    1+2+3+4+5
    481+1569+4677+4823+142+1951
    1+9+2+8+7+10
    5+15+10+20+1+3+30
    
  2. Example 2

    Input
    0+0
    0+5
    5+5
    0
    
    Expected output
    0+0
    0+5
    5+5