# -----------------------------------------------------------------------------------------
# Oak Valley Coding Club 2019-2020
# Solution for 2020 ACSL Programming Problem #3 – Junior Division
# Author :  Aashray Rajagopalan
# Language: Python 3.x
# -----------------------------------------------------------------------------------------

import ovcc_grader_strings

# My vietch diagram 2d array
V = [['', 'A', 'A', '~A', '~A', ],
     ['B', '', '', '', ''],
     ['~B', '', '', '', ''],
     ['', '~C', 'C', 'C', '~C', ]]


def vietchoutput(S1):
    x = []
    num_of_bits = 8
    scale = 16  ## equals to hexadecimal
    # convert to binary
    my_bindata = bin(int(S1, scale))[2:].zfill(num_of_bits)
    c = 1
    # get first 4 binary digits from my_bindata and put it in row 1 of array.
    for b in range(0, 4):
        V[1][c] = my_bindata[b]
        c = c + 1
    # get last 4 binary digits from my_bindata and put it in row 2 of array.
    c = 1
    for b in range(4, 8):
        V[2][c] = my_bindata[b]
        c = c + 1
    # get number of rows
    ro = len(V)
    # get number of columns
    co = len(V[0])
    # priority 1: go through row 1 and 2
    for r in range(1, 3):
        # horizontal adjacent
        c = 1
        if V[r][c] == '1':
            # priority number one if there are 4 in a row
            if int(V[r][c]) + int(V[r][c + 1]) + int(V[r][c + 2]) + int(V[r][c + 3]) == 4:
                x.append(V[r][0])
                # append a + because there could be more items
                x.append('+')
                # if we use a digit make it 0 so we don't count it again
                V[r][c] = V[r][c + 1] = V[r][c + 2] = V[r][c + 3] = '0'

    c = 1
    # priority 2 4 adjacent ones as a square
    # if everything is 0, then there is nothing to do, so check for 0
    if (int(V[1][c]) + int(V[1][c + 1]) + int(V[1][c + 2]) + int(V[1][c + 3]) + int(V[2][c]) + int(V[2][c + 1]) + int(
            V[2][c + 2]) + int(V[2][c + 3])) != 0:
        for c in range(1, co - 1):
            if int(V[1][c]) + int(V[1][c + 1]) + int(V[2][c]) + int(V[2][c + 1]) == 4:
                # checking which column to pick. If adjacent values are equal pick it, because otherwise they cancel
                if V[0][c] == V[0][c + 1]:
                    x.append(V[0][c])
                    x.append('+')
                else:
                    x.append(V[3][c])
                    x.append('+')
                V[1][c] = V[1][c + 1] = V[2][c] = V[2][c + 1] = '0'
        #when all square 4s are done, check for corner 4 1s
        if (int(V[1][1]) + int(V[2][1]) + int(V[1][co - 1]) + int(V[2][co - 1])) == 4:
            # checking which column to pick. If adjacent values are equal pick it, because otherwise they cancel
            if V[0][1] == V[0][co - 1]:
                x.append(V[0][1])
                x.append('+')
            else:
                x.append(V[3][1])
                x.append('+')
            V[1][1] = V[2][1] = V[1][co - 1] = V[2][co - 1] = '0'
    # priority 3 2 adjacent in a row
    c = 1
    for i in range(1, 3):
        for c in range(1, co - 1):
            if int(V[i][c]) + int(V[i][c + 1]) == 2:
                V[i][c] = V[i][c + 1] = '0'
                if V[0][c] == V[0][c + 1]:
                    #use a string because it will have 2 items
                    doublecombination = V[0][c] + V[i][0]
                    x.append(doublecombination)
                    x.append('+')
                else:
                    doublecombination2 = V[3][c] + V[i][0]
                    x.append(doublecombination2)
                    x.append('+')
    # priority 4 .2 adjacent in collumns
    for c in range(1, 5):
        if int(V[1][c]) + int(V[2][c]) == 2:
            doublecombination3 = V[0][c] + V[3][c]
            x.append(doublecombination3)
            x.append('+')
            V[1][c] = V[2][c] = '0'
    # priority 4 . wrap around for 2 items. go by each row
    for i in range(1, 3):
        if int(V[i][1]) + int(V[i][co - 1]) == 2:
            doublecombination4 = V[i][0] + V[3][1]
            x.append(doublecombination4)
            x.append('+')
            V[i][1] = V[i][co - 1] = '0'
    # priority 5 just one
    for i in range(1, 3):
        for c in range(1, 5):
            if int(V[i][c]) == 1:
                doublecombination5 = V[0][c] + V[i][0] + V[3][c]
                x.append(doublecombination5)
                x.append('+')
    # taking out the extra plus sign in the end
    if x[len(x) - 1] == '+':
        x.pop(len(x) - 1)
    # converting into a sting
    y = ''.join(x)

    return (y)


input = ovcc_grader_strings.readinput()

ovcc_grader_strings.clearoutput()
for line in input:
    S1 = line[0]
    ovcc_grader_strings.writeoutput(vietchoutput(S1))