# Name: Christopher Liang
# Team: We Sense
# Intermediate Division
# ACSL Contest #3
# Date of Program: 3/8/2020
# Grade: 6
# Language: Python
# Input Data Method: Type in input
def hexadecimal(Grid):
    e = ''
    for i in range(4):
        a = str(Grid[i][0]) + str(Grid[i][1]) + str(Grid[i][2]) + str(Grid[i][3])
        e += str(hex(int(a,2)))[2:]
    e=e.upper()
    return e
def process(a,Grid):
    z = 0
    b = []
    for i in a:
        if z == 1:
            c = '~' + i
            b.append(c)
            z-=1
        elif i == '~':
            z += 1
        else:
            b.append(i)
    d = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
    x = 0
    for i in b:
        if i == 'A':
            d[0][0]+=1
            d[0][1]+=1
            d[1][0]+=1
            d[1][1]+=1
            d[2][0]+=1
            d[2][1]+=1
            d[3][0]+=1
            d[3][1]+=1
        if i == '~A':
            d[0][2]+=1
            d[0][3]+=1
            d[1][2]+=1
            d[1][3]+=1
            d[2][2]+=1
            d[2][3]+=1
            d[3][2]+=1
            d[3][3]+=1
        if i == 'B':
            d[0][0]+=1
            d[0][1]+=1
            d[0][2]+=1
            d[0][3]+=1
            d[1][0]+=1
            d[1][1]+=1
            d[1][2]+=1
            d[1][3]+=1
        if i == '~B':
            d[2][0]+=1
            d[2][1]+=1
            d[2][2]+=1
            d[2][3]+=1
            d[3][0]+=1
            d[3][1]+=1
            d[3][2]+=1
            d[3][3]+=1
        if i == 'C':
            d[0][1]+=1
            d[0][2]+=1
            d[1][1]+=1
            d[1][2]+=1
            d[2][1]+=1
            d[2][2]+=1
            d[3][1]+=1
            d[3][2]+=1
        if i == '~C':
            d[0][0]+=1
            d[0][3]+=1
            d[1][0]+=1
            d[1][3]+=1
            d[2][0]+=1
            d[2][3]+=1
            d[3][0]+=1
            d[3][3]+=1
        if i == 'D':
            d[1][0]+=1
            d[1][1]+=1
            d[1][2]+=1
            d[1][3]+=1
            d[2][0]+=1
            d[2][1]+=1
            d[2][2]+=1
            d[2][3]+=1
        if i == '~D':
            d[0][0]+=1
            d[0][1]+=1
            d[0][2]+=1
            d[0][3]+=1
            d[3][0]+=1
            d[3][1]+=1
            d[3][2]+=1
            d[3][3]+=1
        x+=1
    r = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
    aa = 0
    bb = 0
    for i in d:
        for j in i:
            if d[aa][bb]==x:
                r[aa][bb]+=1
            bb+=1
        bb=0
        aa+=1
    return r
def Veitch(Input):
    Input = Input.split("+")
    Grid = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
    w = 0
    for i in Input:
        b = process(i,Grid)
        for I in range(4):
            for J in range(4):
                if Grid[I][J]==0:
                    Grid[I][J] += b[I][J]
    Answer = hexadecimal(Grid)
    return Answer
while True:
    Input = input("PLEASE TYPR YOUR INPUT\n")
    print(Veitch(Input))
'''GG = input("PLEASE TYPE THE NAME OF THE INPUT FILE\n")
iFile = open(GG,'r')
allLines = iFile.readlines()
for i in allLines:
    print(Veitch(i))
'''