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


import ovcc_grader_strings

def hex2bin(S):
    #print (S)
    digits = list(S)
    #print (digits)
    bin_dig0 = bin(int(digits[0], 16))[2:].zfill(4)
    bin_dig1 = bin(int(digits[1], 16))[2:].zfill(4)
    bin_str = str(bin_dig0)+str(bin_dig1)
    #print (bin_str)
    return bin_str

def find_matches(bin_str,list1):
    bin_str = list(bin_str)
    list1 = list(list1)
    count = 0
    for i in range (0, len(list1)):
        if bin_str[i] == list1[i] == '1':
            count = count+1   
    return count

def groups4(bin_str,bool_expr):
    #find groups of four 1s
    list1 = ['11001100','01100110','00110011','11110000','00001111','10011001']
    list2 = ['A','C','~A','B','~B','~C']
    expr = ''
    for i in range(0,len(list1)):
            matches = find_matches(bin_str,list1[i])
            if matches >= 4:
                expr = list2[i]
                bool_expr = bool_expr+'+'+expr
            bin_str = list(bin_str)
            if expr == "A":
                bin_str[0]=bin_str[1]=bin_str[4]=bin_str[5]='0'
            if expr == "~A":
                bin_str[2]=bin_str[3]=bin_str[6]=bin_str[7]='0'
            if expr == "B":
                bin_str[0]=bin_str[1]=bin_str[2]=bin_str[3]='0'
            if expr == "~B":
                bin_str[4]=bin_str[5]=bin_str[6]=bin_str[7]='0'
            if expr == "C":
                bin_str[1]=bin_str[2]=bin_str[5]=bin_str[6]='0'
            if expr == "~C":
                bin_str[0]=bin_str[3]=bin_str[4]=bin_str[7]='0'        

            bin_str = ''.join(bin_str)        
    

    return bin_str, bool_expr;

def groups2(bin_str,bool_expr):
    #find groups of two 1s
    list1 = ['00010001','00100010','01000100','10001000','11000000','01100000','00110000','10010000','00001100','00000110','00000011','00001001']
    list2 = ['~A~C','~AC','AC','A~C','AB','BC','~AB','B~C','A~B','~BC','~A~B','~B~C']
    #list1 = ['00010001','00100010','01000100','10001000','11000000','01100000','00110000','10010000','00001100','00000110','00000011','00001001','01010101','10101010','11000011','00111100']
    #list2 = ['~A~C','~AC','AC','A~C','AB','BC','~AB','B~C','A~B','~BC','~A~B','~B~C','~A~C+AC','AC+~AC','AB+~A~B','~AB+A~B']
    expr = ''
    for i in range(0, len(list1)):
        matches = find_matches(bin_str,list1[i])
        if matches >= 2:
            expr = list2[i]
            bool_expr = bool_expr+'+'+expr

        bin_str = list(bin_str)
        if expr == "~A~C": bin_str[3]=bin_str[7]='0'
        if expr == "~AC": bin_str[2]=bin_str[6]='0'
        if expr == "AC": bin_str[1]=bin_str[5]='0'
        if expr == "A~C": bin_str[0]=bin_str[4]='0'
        if expr == "AB": bin_str[0]=bin_str[1]='0'
        if expr == "BC": bin_str[1]=bin_str[2]='0'
        if expr == "~AB": bin_str[2]=bin_str[3]='0'
        if expr == "B~C": bin_str[0]=bin_str[3]='0'
        if expr == "A~B": bin_str[4]=bin_str[5]='0'
        if expr == "~BC": bin_str[5]=bin_str[6]='0'
        if expr == "~A~B": bin_str[6]=bin_str[7]='0'
        if expr == "~B~C": bin_str[4]=bin_str[7]='0'

        bin_str = ''.join(bin_str)
        #print (bin_str, "in the loop")        

        
    return bin_str, bool_expr;
    
def groups1(bin_str,bool_expr):
    #find groups of one 1s
    expr = ''
    bin_str = list(bin_str)
    for i in range(0, len(bin_str)):
        if bin_str[i] == '1':
            if i == 0: expr = expr+'+AB~C'
            if i == 1: expr = expr+'+ABC' 
            if i == 2: expr = expr+'+~ABC'
            if i == 3: expr = expr+'+~AB~C'
            if i == 4: expr = expr+'+A~B~C'
            if i == 5: expr = expr+'+A~BC'
            if i == 6: expr = expr+'+~A~BC'
            if i == 7: expr = expr+'+~A~B~C'
            bin_str[i]='0'

    bool_expr = bool_expr+expr
    bin_str = ''.join(bin_str)
    #print (bin_str)
    #print (bool_expr)
    return bin_str, bool_expr;

def boolean_expr(S):
    bool_expr=''
    bin_str = hex2bin(S)
    #print (bin_str, "after bin conversion")

    bin_str, bool_expr = groups4(bin_str, bool_expr)

    #print(bin_str, "after groups4")
    #print (bool_expr, "after groups4")

    bin_str, bool_expr = groups2(bin_str, bool_expr)
    #print(bin_str, "after groups2")
    #print (bool_expr, "after_groups2")
    
    bin_str, bool_expr = groups1(bin_str, bool_expr)

    #print (bin_str, "after groups1")
    #print(bool_expr, "after groups1")

    return bool_expr


input = ovcc_grader_strings.readinput()
ovcc_grader_strings.clearoutput()
for line in input:
    S = line[0]
    ovcc_grader_strings.writeoutput(boolean_expr(S)[1:])