def getGroups(binar):
  rows, cols = (2, 4) 
  # method 2a 
  gArr = [[0 for i in range(cols)] for j in range(rows)] 
  k=0
  group=""
  for i in range(rows):
    for j in range(cols):
      gArr[i][j]=int(binar[k])
      k=k+1
      #print(gArr[i][j])
  for i in range(rows):
    for j in range(cols):
      if(gArr[i][j]==1):
        if(j+1<4 and gArr[i][j+1]==1):
          if(i+1 <2 and gArr[i+1][j]==1 and gArr[i+1][j+1]==1):
            group= group+"("+str(i) + "," + str(j)+")|("+ str(i) + "," + str(j+1) +")|("+ str((i+1)) + "," + str(j) +")|("+ str(i+1) + "," + str(j+1) +"):"
            gArr[i][j]=0
            gArr[i+1][j] =0
            gArr[i][j+1] =0
            gArr[i+1][j+1] =0
          else :
            group  = group + "("+str(i) + "," + str(j)+")|("+ str(i) + "," + str(j+1) +"):";
            gArr[i][j] =0;
            gArr[i][j+1] =0;
        elif(i==0 and j==3 and gArr[0][3]==1 and gArr[1][3]==1):
          group  = group + "("+str(i) + "," + str(j)+")|("+ str(i+1) + "," + str(j) +"):"
          gArr[i][j] =0
          gArr[i+1][j] =0
        else :
          group  = group + "("+ str(i) + "," + str(j) +"):";
  tGrp =""
  if(gArr[0][0]==1 and gArr[0][3] ==1 and gArr[1][0]==1 and gArr[1][3]==1):
    tGrp = group.replace("(0,0):","").replace("(0,3):","").replace("(1,0):","") ;
    group =  "(0,0)|(0,3)|(1,0)|(1,3)" + tGrp ;
    gArr[0][0] =0;
    gArr[0][3] =0;
    gArr[1][0] =0;
    gArr[1][3] =0;
  if(gArr[0][0]==1 and gArr[0][3] ==1):
    tGrp =  group.replace("(0,0):","").replace("(0,3):","") ;
    group = "(0,0)|(0,3):" + tGrp;
    gArr[0][0] =0;
    gArr[0][3] =0;
  if(gArr[1][0]==1 and gArr[1][3] ==1):
    tGrp = group.replace("(1,0):","").replace("(1,3):","");
    group =  "(1,0)|(1,3):" + tGrp;
    gArr[1][0] =0;
    gArr[1][3] =0;
  return group
def getExpression(groups):
  exprMap={"(0,0)":"ABF","(0,1)":"ABC","(0,2)":"DBC","(0,3)":"DBF","(1,0)":"AEF","(1,1)":"AEC", "(1,2)":"DEC","(1,3)":"DEF"}
  #print(groups)
  groups = groups.replace("|","")
  #print(groups)
  aExpr=[groups[i:i+5] for i in range(0, len(groups), 5)]
  #print(aExpr)
  expr=""
  for e in aExpr:
    #print("item" + e + "value" +exprMap.get(e) )
    expr =  expr + exprMap.get(e);
  if (expr.find("A")!=-1 and expr.find("D")!=-1):
    expr= expr.replace("A","").replace("D","")
  if (expr.find("B")!=-1 and expr.find("E")!=-1):
    expr= expr.replace("B","").replace("E","")
  if (expr.find("C")!=-1 and expr.find("F")!=-1):
    expr= expr.replace("C","").replace("F","")
  from collections import OrderedDict
  expr = "".join(OrderedDict.fromkeys(expr)).replace("D","~A").replace("E","~B").replace("F","~C")
  return expr;
def sortArray(x):
    n = len(x)
    for i in range(n):
        for j in range(i+1,n):
            if len(x[i]) < len(x[j]):
                temp = x[i]
                x[i] = x[j]
                x[j] = temp
    return x
count = 1 #no.of inputs
expression = []
print('Enter a valid input:')
for i in range(count):
  expression.append(input())
print('Output')
for s in expression:
  scale = 16 ## hexadecimal
  bits_size = 8
  groups = getGroups(bin(int(s.upper(), scale))[2:].zfill(bits_size))
  groups=groups[0:-1]
  exprArr = sortArray(groups.split(":"))
  expr = ""
  for e in exprArr:
    expr =  expr + "+" + getExpression(e)
  print(expr[1:])