Problem:
 Score : 300 points    Problem Statement Sitting in a station waiting room, Joisino is gazing at her train ticket.  The ticket is numbered with four digits A , B , C and D in this order, each between 0 and 9 (inclusive).  In the formula A  op1  B  op2  C  op3  D  =  7 , replace each of the symbols op1 , op2 and op3 with + or - so that the formula holds.  The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.      Constraints  0≤A,B,C,D≤9  All input values are integers.  It is guaranteed that there is a solution.         Input Input is given from Standard Input in the following format:  ABCD       Output Print the formula you made, including the part =7 .  Use the signs + and - .  Do not print a space between a digit and a sign.        Sample Input 1 1222      Sample Output 1 1+2+2+2=7  This is the only valid solution.       Sample Input 2 0290      Sample Output 2 0-2+9+0=7  0 - 2 + 9 - 0 = 7 is also a valid solution.       Sample Input 3 3242      Sample Output 3 3+2+4-2=7

Solution (Python):
a,b,c,d=input()

pm=['-','+']

def calc():
    for i in pm :
        for j in pm:
            for k in pm:
                s=a+i+b+j+c+k+d
                total=eval(s)
                if total==7:
                    return s+'='+str(total)

print(calc())

Solution (Python):
s = input()
n = len(s)


for i in range(2**(n-1)):
    
    exp = s[0]

    
    for j in range(1, n):
        if (i >> j-1) & 1:
            exp += '+'
        else:
            exp += '-'
        
        exp += s[j]

    if eval(exp) == 7:
        print('{}=7'.format(exp))
        exit()

Solution (Python):



a, b, c, d = list(map(int, list(input())))
op1, op2, op3 = [True, False], [True, False], [True, False]
for o1 in op1:
    for o2 in op2:
        for o3 in op3:
            ab = a + b if o1 else a - b
            abc = ab + c if o2 else ab - c
            abcd = abc + d if o3 else abc - d
            if abcd == 7:
                opr1 = "+" if o1 else "-"
                opr2 = "+" if o2 else "-"
                opr3 = "+" if o3 else "-"
                print("{}{}{}{}{}{}{}=7".format(a, opr1, b, opr2, c, opr3, d))
                exit()

Solution (Python):
A = list(map(int, input()))
signs = [None] * 3
for b in range(1 << 3):
    sum = A[0]
    for i in range(3):
        if (b & (1 << i)) != 0:
            signs[i] = '+'
            sum += A[i + 1]
        else:
            signs[i] = '-'
            sum -= A[i + 1]
    if sum == 7:
        break
result = [None] * (4 + 3 + 2)
result[:4*2:2] = map(str, A)
result[1:1+3*2:2] = signs
result[-2:] = "=7"
print("".join(result))

Solution (Python):
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

A, B, C, D = [int(v) for v in list(s())]

if A+B+C+D == 7:
    print('{}+{}+{}+{}=7'.format(A, B, C, D))
elif A+B+C-D == 7:
    print('{}+{}+{}-{}=7'.format(A, B, C, D))
elif A+B-C+D == 7:
    print('{}+{}-{}+{}=7'.format(A, B, C, D))
elif A-B+C+D == 7:
    print('{}-{}+{}+{}=7'.format(A, B, C, D))
elif A+B-C-D == 7:
    print('{}+{}-{}-{}=7'.format(A, B, C, D))
elif A-B+C-D == 7:
    print('{}-{}+{}-{}=7'.format(A, B, C, D))
elif A-B-C+D == 7:
    print('{}-{}-{}+{}=7'.format(A, B, C, D))
elif A-B-C-D == 7:
    print('{}-{}-{}-{}=7'.format(A, B, C, D))

Solution (Python):
s = str(input())
for i in range(0,8):
    if i//4%2==0:
        x = "+"
    else:
        x = "-"
    if i//2%2==0:
        y = "+"
    else:
        y = "-"
    if i%2==0:
        z = "+"
    else:
        z = "-"
    ans = s[0]+x+s[1]+y+s[2]+z+s[3]
    if eval(ans)==7:
        print(ans+"=7")
        exit()

Solution (Python):
import sys

input = sys.stdin.readline

s = input()

a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])

if a + b + c + d == 7:
    print(str(a) + "+" + str(b) + "+" + str(c) + "+" + str(d) + "=7")
elif a + b + c - d == 7:
    print(str(a) + "+" + str(b) + "+" + str(c) + "-" + str(d) + "=7")
elif a + b - c + d == 7:
    print(str(a) + "+" + str(b) + "-" + str(c) + "+" + str(d) + "=7")
elif a + b - c - d == 7:
    print(str(a) + "+" + str(b) + "-" + str(c) + "-" + str(d) + "=7")
elif a - b + c + d == 7:
    print(str(a) + "-" + str(b) + "+" + str(c) + "+" + str(d) + "=7")
elif a - b + c - d == 7:
    print(str(a) + "-" + str(b) + "+" + str(c) + "-" + str(d) + "=7")
elif a - b - c + d == 7:
    print(str(a) + "-" + str(b) + "-" + str(c) + "+" + str(d) + "=7")
elif a - b - c - d == 7:
    print(str(a) + "-" + str(b) + "-" + str(c) + "-" + str(d) + "=7")

Solution (Python):
s = input()
n = 3
t=[]
for i in range(1<<n):
    ans = int(s[0])
    k=1
    for j in range(n):
        if 1&(i>>j):
            ans += int(s[k:(j+2)])
            t.append("+")
        else: 
            ans -= int(s[k:(j+2)]) 
            t.append("-")
        k=j+2
    if ans==7:
        print(s[0]+t[0]+s[1]+t[1]+s[2]+t[2]+s[3]+"=7")
        break;
    ans = int(s[0])
    t=[]

Solution (Python):
a = input()
for i in range(2 ** 3):
    s = a[0]
    for j in range(3):
        s += "+-"[i >> j & 1] + a[j+1]
    if eval(s) == 7:
        print(s + "=7")
        break

Solution (Python):

import sys
import operator
import itertools

def op(op_str):
    funcs = {
            "+":operator.add,
            "-":operator.sub
            }
    return funcs[op_str]

def solve(A,B,C,D):
    for o in itertools.product(["+","-"], repeat = 3):
        ret = op(o[0])(A,B)
        ret = op(o[1])(ret,C)
        ret = op(o[2])(ret,D)
        if ret == 7:
            print("{0}{1}{2}{3}{4}{5}{6}=7".format(A,o[0],B,o[1],C,o[2],D))
            return


    return



def main():
    S = input()
    L = [int(c) for c in S]
    
    solve(*L)

if __name__ == '__main__':
    main()

Solution (Python):
ABCD  = list(input())
n = len(ABCD)
ans = 0

for i in range(2 ** (n-1)):

    list = ABCD[0]

    
    
    for j in range(1, n):

        if (i >> (j - 1)) & 1:

            list = list + "+" + ABCD[j]
            

        else:
            list = list + "-" + ABCD[j]


    if eval(list) == 7:
        print(list,"=7",sep='')
        exit()

Solution (Python):
a = [int(x) for x in list(input())]
op = 3
ops = [0] * op
for i in range(2 ** op):
    result = a[0]
    bry = list(format(i, "0{}b".format(op)))
    for index, value in enumerate(bry):
        if value == "1":
            result += a[index + 1]
            ops[index] = "+"
        else:
            result -= a[index + 1]
            ops[index] = "-"
    if result == 7:
        ans = str(a[0])
        for j in range(3):
            ans += "{}{}".format(ops[j], a[j+1])
        ans += "=7"
        print(ans)
        break

Solution (Python):
s = input()
a, b, c, d = s[0], s[1], s[2], s[3]
for op1 in "+-":
  for op2 in "+-":
    for op3 in "+-":
      f = a+op1+b+op2+c+op3+d
      if eval(f)==7:
        print(f+"=7")
        exit()

Solution (Python):
ABCD=input()
A,B,C,D=int(ABCD[0]),int(ABCD[1]),int(ABCD[2]),int(ABCD[3])
a,b,c,d,e,f,g,h=A+B+C+D,A+B+C-D,A+B-C+D,A-B+C+D,A+B-C-D,A-B+C-D,A-B-C+D,A-B-C-D
if a==7:print(str(A)+"+"+str(B)+"+"+str(C)+"+"+str(D)+"=7")
elif b==7:print(str(A)+"+"+str(B)+"+"+str(C)+"-"+str(D)+"=7")
elif c==7:print(str(A)+"+"+str(B)+"-"+str(C)+"+"+str(D)+"=7")
elif d==7:print(str(A)+"-"+str(B)+"+"+str(C)+"+"+str(D)+"=7")
elif e==7:print(str(A)+"+"+str(B)+"-"+str(C)+"-"+str(D)+"=7")
elif f==7:print(str(A)+"-"+str(B)+"+"+str(C)+"-"+str(D)+"=7")
elif g==7:print(str(A)+"-"+str(B)+"-"+str(C)+"+"+str(D)+"=7")
else:print(str(A)+"-"+str(B)+"-"+str(C)+"-"+str(D)+"=7")

Solution (Python):
s=input()
for i in range(2):
    for j in range(2):
        for k in range(2):
            t=int(s[0])
            ans=s[0]
            if i:
                t+=int(s[1])
                ans+='+'+s[1]
            else:
                t-=int(s[1])
                ans+='-'+s[1]
            if j:
                t+=int(s[2])
                ans+='+'+s[2]
            else:
                t-=int(s[2])
                ans+='-'+s[2]
            if k:
                t+=int(s[3])
                ans+='+'+s[3]
            else:
                t-=int(s[3])
                ans+='-'+s[3]
            if t==7:
                print(ans+'=7')
                exit()

Solution (Python):
In = list(map(int, list(input())))

import itertools
Bit = list(itertools.product(['+', '-'], repeat=3))

for l in Bit:
    seven = In[0]
    for i, bit in enumerate(l):
        if bit == '+':
            seven += In[i+1]
        else:
            seven -= In[i+1]
    if seven == 7:
        print("{}{}{}{}{}{}{}=7".format(In[0],l[0],In[1],l[1],In[2],l[2],In[3]))
        break

Solution (Python):
n = input()
a, b, c, d = n[0], n[1], n[2], n[3]

if int(a)+int(b)+int(c)+int(d) is 7:
  print(a+"+"+b+"+"+c+"+"+d+"=7")
elif int(a)+int(b)+int(c)-int(d) is 7:
  print(a+"+"+b+"+"+c+"-"+d+"=7")
elif int(a)+int(b)-int(c)+int(d) is 7:
  print(a+"+"+b+"-"+c+"+"+d+"=7")
elif int(a)+int(b)-int(c)-int(d) is 7:
  print(a+"+"+b+"-"+c+"-"+d+"=7")
elif int(a)-int(b)+int(c)+int(d) is 7:
  print(a+"-"+b+"+"+c+"+"+d+"=7")
elif int(a)-int(b)+int(c)-int(d) is 7:
  print(a+"-"+b+"+"+c+"-"+d+"=7")
elif int(a)-int(b)-int(c)+int(d) is 7:
  print(a+"-"+b+"-"+c+"+"+d+"=7")
elif int(a)-int(b)-int(c)-int(d) is 7:
  print(a+"-"+b+"-"+c+"-"+d+"=7")

Solution (Python):

ll = list(map(int, list(input())))
pm = ["+", "-"]
for i in range(2):
    for j in range(2):
        for k in range(2):
            ans = ll[0] + ll[1]*(-1)**i + ll[2]*(-1)**j + ll[3]*(-1)**k
            
            
            if ans == 7:
                print("{}{}{}{}{}{}{}=7".format(ll[0], pm[i], ll[1], pm[j], ll[2], pm[k], ll[3]))
                exit()

Solution (Python):


a,b,c,d=map(int,input())
flg=0
p=[1,-1]

for i in range(2):
    for j in range(2):
        for k in range(2):
            if a+p[i]*b+p[j]*c+p[k]*d==7:
                if p[i]>0:
                    p1="+"
                else:
                    p1="-"
                    
                if p[j]>0:
                    p2="+"
                else:
                    p2="-"
                    
                if p[k]>0:
                    p3="+"
                else:
                    p3="-"
                
                
                print("%d%s%d%s%d%s%d=7"%(a,p1,b,p2,c,p3,d))
                exit()

Solution (Python):

box=input()
l=len(box)
for i in range(pow(2,(l-1))):
    num=box[0]
    for j in range(1,l): 
        if (i>>(j-1))&1:
            num+="+"+box[j]
        else:
            num+="-"+box[j]
    if eval(num)==7:
        print(num+"=7")
        break

Solution (Python):
ABCD = input()
A,B,C,D = [int(ABCD[i]) for i in range(4)]

for op1 in range(2):
    for op2 in range(2):
        for op3 in range(2):
            if A + ((-1)**op1)*B + ((-1)**op2)*C + ((-1)**op3)*D == 7:
                ans = str(A)
                if op1 == 0:
                    ans += "+"
                else:
                    ans += "-"
                ans += str(B)
                if op2 == 0:
                    ans += "+"
                else:
                    ans += "-"
                ans += str(C)
                if op3 == 0:
                    ans += "+"
                else:
                    ans += "-"
                ans += str(D)
                ans += "=7"
                print(ans)
                break
        else:
            continue
        break
    else:
        continue
    break

Solution (Python):
s = list(map(int, input()))

def show(s, i):
  str_ = str(s[0])
  for j in range(3):
    if ((i >> (2-j)) & 1):
      str_ += '+' + str(s[j+1])
    else:
      str_ += '-' + str(s[j+1])
  str_ += '=7'
  print(str_)

for i in range(2 ** 3):
  t = bin(i)
  sum = s[0]
  for j in range(3):
    if ((i >> (2-j)) & 1):
      sum += s[j+1]
    else:
      sum -= s[j+1]
    
    if sum == 7:
      show(s, i)
      exit()

Solution (Python):
ABCD = input()
for i in range(2**3):
    bi = bin(i)[2:].zfill(3)
    tmp = int(ABCD[0])
    ops = []
    for j in range(3):
        if bi[j]=='1':
            tmp += int(ABCD[j+1])
            ops.append('+')
        else:
            tmp -= int(ABCD[j+1])
            ops.append('-')
    if tmp==7:
        print(ABCD[0]+ops[0]+ABCD[1]+ops[1]+ABCD[2]+ops[2]+ABCD[3] + '=7')
        break

Solution (Python):
ticket = input()
a = [int(t) for t in ticket]
op = ["" for i in range(3)]
for i in range(8):
    ans = a[0]
    for j in range(3):
        if format(i, "03b")[j] == "1":
            op[j] = "+"
            ans = ans + a[j+1]
        else:
            op[j] = "-"
            ans = ans - a[j+1]
    if ans == 7:
        for k in range(3):
            print(str(a[k])+op[k], end="")
        print(str(a[3])+"=7")
        break

Solution (Python):
s = input()
a,b,c,d = int(s[0]), int(s[1]), int(s[2]), int(s[3])
if a+b+c+d == 7:
    print("{0}+{1}+{2}+{3}=7".format(str(a),str(b),str(c),str(d)))
elif a+b+c-d == 7:
    print("{0}+{1}+{2}-{3}=7".format(str(a),str(b),str(c),str(d)))
elif a+b-c+d == 7:
    print("{0}+{1}-{2}+{3}=7".format(str(a),str(b),str(c),str(d)))
elif a-b+c+d == 7:
    print("{0}-{1}+{2}+{3}=7".format(str(a),str(b),str(c),str(d)))
elif a+b-c-d == 7:
    print("{0}+{1}-{2}-{3}=7".format(str(a),str(b),str(c),str(d)))
elif a - b + c - d == 7:
    print("{0}-{1}+{2}-{3}=7".format(str(a), str(b), str(c), str(d)))
elif a-b-c+d == 7:
    print("{0}-{1}-{2}+{3}=7".format(str(a),str(b),str(c),str(d)))
elif a-b-c-d == 7:
    print("{0}-{1}-{2}-{3}=7".format(str(a),str(b),str(c),str(d)))

Solution (Python):
abcd = input()
A,B,C,D = int(abcd[0]),int(abcd[1]),int(abcd[2]),int(abcd[3])    
if A + B + C + D == 7:
  print('{}+{}+{}+{}=7'.format(A, B, C, D))
elif A + B + C - D == 7:
  print('{}+{}+{}-{}=7'.format(A, B, C, D))
elif A + B - C + D == 7:
  print('{}+{}-{}+{}=7'.format(A, B, C, D))
elif A + B - C - D == 7:
  print('{}+{}-{}-{}=7'.format(A, B, C, D))
elif A - B + C + D == 7:
  print('{}-{}+{}+{}=7'.format(A, B, C, D))
elif A - B + C - D == 7:
  print('{}-{}+{}-{}=7'.format(A, B, C, D))
elif A - B - C + D == 7:
  print('{}-{}-{}+{}=7'.format(A, B, C, D))
else:
  print('{}-{}-{}-{}=7'.format(A, B, C, D))

Solution (Python):
import sys

S=sys.stdin.readline()
A=int(S[0])
B=int(S[1])
C=int(S[2])
D=int(S[3])

for i in range(8):
  candidate=A
  opeList=[]
  if i & (1 << 2) != 0:
    candidate = candidate+B
    opeList.append("+")
  else:
    candidate = candidate-B
    opeList.append("-")
  
  if i & (1 << 1) != 0:
    candidate = candidate+C
    opeList.append("+")
  else:
    candidate = candidate-C
    opeList.append("-")
    
  if i & 1 != 0:
    candidate = candidate+D
    opeList.append("+")
  else:
    candidate = candidate-D
    opeList.append("-")
    
  if candidate == 7:
    print(str(A)+opeList[0]+str(B)+opeList[1]+str(C)+opeList[2]+str(D)+"=7")
    break

Solution (Python):
n=list(input())
k=len(n)-1

for i in range(2**k):
    x=['-']*k
    for j in range(k):
        if (i >> j) & 1:
            x[j]='+'
    
    ans=""
    for a,b in zip(n,x+[""]):
        ans+=(a+b)
    if eval(ans)==7:
        print(ans+"=7")
        break

Solution (Python):
s = input()
n = len(s)
for i in range(2**n):

  total = 0
  ans = s[0]
  val = int(s[0])
  for j in range(1, n):
    if (i >> j) & 1:
      ans = ans + "+" + s[j]
      val = val + int(s[j])
    else:
      ans = ans + "-" + s[j]
      val = val - int(s[j])
  
  if val == 7:
    print(ans + "=7")
    exit()

Solution (Python):
S = input()
A,B,C,D = int(S[0]),int(S[1]),int(S[2]),int(S[3])

if A+B+C+D == 7:
    print(str(A)+"+"+str(B)+"+"+str(C)+"+"+str(D)+"=7")
elif A+B+C-D == 7:
    print(str(A)+"+"+str(B)+"+"+str(C)+"-"+str(D)+"=7")
elif A+B-C+D == 7:
    print(str(A)+"+"+str(B)+"-"+str(C)+"+"+str(D)+"=7")
elif A-B+C+D == 7:
    print(str(A)+"-"+str(B)+"+"+str(C)+"+"+str(D)+"=7")
elif A+B-C-D == 7:
    print(str(A)+"+"+str(B)+"-"+str(C)+"-"+str(D)+"=7")
elif A-B+C-D == 7:
    print(str(A)+"-"+str(B)+"+"+str(C)+"-"+str(D)+"=7")
elif A-B-C+D == 7:
    print(str(A)+"-"+str(B)+"-"+str(C)+"+"+str(D)+"=7")
elif A-B-C-D == 7:
    print(str(A)+"-"+str(B)+"-"+str(C)+"-"+str(D)+"=7")

Solution (Python):
s = input()
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])

if a + b + c + d  == 7:
  print(str(a)+"+"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
elif a + b + c - d == 7:
  print(str(a)+"+"+str(b)+"+"+str(c)+"-"+str(d)+"=7")
elif a + b - c + d == 7:
  print(str(a)+"+"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
elif a - b + c + d == 7:
  print(str(a)+"-"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
elif a + b - c - d == 7:
  print(str(a)+"+"+str(b)+"-"+str(c)+"-"+str(d)+"=7")
elif a - b + c - d == 7:
  print(str(a)+"-"+str(b)+"+"+str(c)+"-"+str(d)+"=7")
elif a - b - c + d == 7:
  print(str(a)+"-"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
elif a - b - c - d == 7:
  print(str(a)+"-"+str(b)+"-"+str(c)+"-"+str(d)+"=7")

Solution (Python):
s = list(input())

for i in range(2**3):
    cnt = int(s[0])
    ls = []
    for j in range(3):    
        if ((i>>j)&1):
            ls.append("+")
            cnt += int(s[j+1])
        else:
            ls.append("-")
            cnt -= int(s[j+1])
    if cnt==7:
        eq = [s[0],ls[0],s[1],ls[1],s[2],ls[2],s[3],"=7"]
        print("".join(eq))
        break

Solution (Python):
s=input()
n=len(s)-1

for i in range(2**n):
    ans=int(s[0])
    p=str(s[0])

    for j in range(n):
        if((i>>j)&1):
            ans += int(s[j+1])
            p=p+'+'+s[j+1]
        else:
            ans -= int(s[j+1])
            p=p+'-'+s[j+1]
    if ans==7:
        print(p+'=7')
        break

Solution (Python):
n = input()
m = len(n)
l = list(n)


for i in range(2 **(m-1)):
    op = ["-"]*(m-1) + [""]
    for j in range(m-1):
        if ((i>>j)&1):
            op[j] = "+"
    formula = ""
    for p_n, p_o in zip(l,op):
        formula += (p_n + p_o)
    if eval(formula) == 7:
        print("{}=7".format(formula))
        exit()

Solution (Python):
l = input().split()
ABCD = l[0]

A = int(ABCD[0])
B = int(ABCD[1])
C = int(ABCD[2])
D = int(ABCD[3])



def op(code, x, y):
    if code == 0:
        return x + y
    return x - y

def to_op(code):
    if code == 0:
        return '+'
    return '-'

for i in range(8):
    code1 = i % 2
    ans = op(code1, A, B)
    code2 = (i // 2) % 2
    ans = op(code2, ans, C)
    code3 = (i // 4) % 2
    ans = op(code3, ans, D)
    if ans == 7:
        print('{}{}{}{}{}{}{}=7'.format(
            A, to_op(code1),
            B, to_op(code2),
            C, to_op(code3),
            D
        ))
        break

Solution (Python):
import sys
S = str(input())
A = S[0]
B = S[1]
C = S[2]
D = S[3]

for i in range(2 ** 3):
    tmp = [(i >> t) & 1 for t in range(3)]
    sign = ['+' if t == 1 else '-' for t in tmp]
    string = A + sign[0] + B + sign[1] + C + sign[2] + D
    y = eval(string)
    if y == 7:
        print(string+'=7')
        sys.exit()

Solution (Python):


S = str(input())
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

for i in range(2):
    for j in range(2):
        for k in range(2):
            A = int(S[0])
            B = int(S[1])
            C = int(S[2])
            D = int(S[3])

            B *= (-1) ** i
            C *= (-1) ** j
            D *= (-1) ** k
            if(A + B + C + D == 7):
                shiki = ''
                shiki += str(A)
                if(B<0):
                    shiki += str(B)
                else:
                    shiki += '+' + str(B)

                if(C<0):
                    shiki += str(C)
                else:
                    shiki += '+' + str(C)

                if(D<0):
                    shiki += str(D)
                else:
                    shiki += '+' + str(D)
                shiki += '=7'
                print(shiki)
                exit()

Solution (Python):
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect
import sys
import random
import time
inf = 10**9


def main():
    abcd = input()
    bits = []

    for i in range(2 ** 3):
        eq = []
        for j in range(4):
            eq.append(abcd[j])
            if j > 2:
                break
            if (i >> j) & 1:
                eq.append('+')
            else:
                eq.append('-')
        eveq = ''.join(eq)
        if eval(eveq) == 7:
            print(eveq + '=7')
            return


if __name__ == '__main__':
    main()

Solution (Python):
A, B, C, D = list(map(int, list(input().strip())))

for op1 in [-1, 1]:
    for op2 in [-1, 1]:
        for op3 in [-1, 1]:
            if A + (op1 * B) + (op2 * C) + (op3 * D) == 7:
                print('{}{}{}{}{}{}{}=7'.format(A, "+" if op1 == 1 else "-", B, "+" if op2 == 1 else "-", C, "+" if op3 == 1 else "-", D))
                exit()

Solution (Python):

S = list(input())
for i in range(len(S)):
    S[i] = int(S[i])

L = len(S)
fugou = []


for i in range(2**(L-1)):
    total = S[0]
    
    moji = format(i,'b').zfill(4)
    
    for k in range(1,L):
        
        if int(moji[k]) == 1:
            total = total + S[k]
        else:
            total = total - S[k]
        
    if total == 7:
        moji_answer = moji


for i in range(1,L):
    if int(moji_answer[i]) == 1:
        fugou_tandoku = "+"
    else:
        fugou_tandoku = "-"
    fugou.append(fugou_tandoku)
print(S[0],fugou[0],S[1],fugou[1],S[2],fugou[2],S[3],'=7',sep='')

Solution (Python):
E = input()
N = len(E)

for n in range(2**(N-1)):
    s = 0
    ans = []
    B = bin(n)[2:]
    while len(B) < N - 1:
        B = "0" + B
    ans += "{:s}".format(E[0])
    s += int(E[0])
    for i, e in enumerate(E[1:]):
        if B[i] == "0":
            ans += "{:s}".format("-")
            s -= int(e)
        else:
            ans += "{:s}".format("+")
            s += int(e)
        ans += "{:s}".format(e)
    if s == 7:
        ans += "=7"
        print(*ans, sep="")
        break

Solution (Python):
import itertools
def rec (nums,st,step,cot,hugo):
    if step==4:
        if cot == 7:
            print(st+"=7")
            exit()
    else:

        if hugo > 0:
            temp = "+" + str(nums[step])
            cot += nums[step]
        else:
            temp = "-" + str(nums[step])
            cot -= nums[step]
        rec(nums,st+temp,step+1,cot,1)
        rec(nums, st+temp, step + 1, cot, -1)


def do():
    nums = list(map(int,list(input())))
    rec(nums,str(nums[0]),1,nums[0],1)
    rec(nums,str(nums[0]),1,nums[0],-1)


if __name__ == "__main__":
    do()

Solution (Python):
from itertools import zip_longest

abcd = input()

n = 3
op_li = [0] * 2**n

for i in range(2**n):
  op = ["-"] * n
  for j in range(n):
    if (i >> j) & 1 == 1:
      op[j] = "+"
  op_li[i] = op

for i in op_li:
  siki = ""
  for j, k in zip_longest(i, abcd, fillvalue=""):
    siki += k+j
  if eval(siki) == 7:
    print(siki + "=7")
    exit()

Solution (Python):
lst = list(map(str, input()))
n = len(lst) - 1
op_lst = ["+", "-"]
for i in range(2**n):
    op = ["-"] * 3
    for j in range(n):
        if ((i >> j) & 1):
            op[n-j-1] = op_lst[0]
    formula = ""
    for num,opp in zip(lst, op + [""]):
        formula += (num + opp)
    if eval(formula) == 7:
        print(formula + "=7")
        break

Solution (Python):
P = input()
A = int(P[0])
B = int(P[1])
C = int(P[2])
D = int(P[3])

if A+B+C+D == 7:
    print("{}+{}+{}+{}=7".format(A, B, C, D))
elif A-B+C+D == 7:
    print("{}-{}+{}+{}=7".format(A, B, C, D))
elif A+B-C+D == 7:
    print("{}+{}-{}+{}=7".format(A, B, C, D))
elif A-B-C+D == 7:
    print("{}-{}-{}+{}=7".format(A, B, C, D))
elif A+B+C-D == 7:
    print("{}+{}+{}-{}=7".format(A, B, C, D))
elif A-B+C-D == 7:
    print("{}-{}+{}-{}=7".format(A, B, C, D))
elif A+B-C-D == 7:
    print("{}+{}-{}-{}=7".format(A, B, C, D))
else:
    print("{}-{}-{}-{}=7".format(A, B, C, D))

Solution (Python):
num = input()
a,b,c,d = int(num[0]),int(num[1]),int(num[2]),int(num[3])

finish = False
if not finish:
    for i in range(2):
        if not finish:
            for j in range(2):
                if not finish:
                    for k in range(2):
                        if a + b*(-1)**i + c*(-1)**j + d*(-1)**k == 7:
                            A = [i,j,k]
                            finish = True 

ans = []
for l in A:
    if l == 0:
        ans.append('+')
    else:
        ans.append('-')
print(str(a)+ans[0]+str(b)+ans[1]+str(c)+ans[2]+str(d)+'=7')

Solution (Python):
A, B, C, D = list(input())

for n in range(2 ** 3):
	identity = ""
	identity += A + ["+", "-"][(n >> 0 & 1)]
	identity += B + ["+", "-"][(n >> 1 & 1)]
	identity += C + ["+", "-"][(n >> 2 & 1)]
	identity += D
	if 7 == eval(identity):
		print(identity + "=7")
		break

Solution (Python):
n=int(input())
a=n//1000
b=n//100%10
c=n//10%10
d=n%10
op=range(2)
def calc(i,a,b):
    if i==0:
        return a+b
    else:
        return a-b

def opdef(i):
    if i==0:
        return '+'
    else:
        return '-'
flg=False
for i in op:
    if flg:
        break
    for j in op:
        if flg:
            break
        for k in op:
            if flg:
                break
            ans=calc(k,calc(j,calc(i,a,b),c),d)
            if ans==7:
                flg=True
                print(str(a)+opdef(i)+str(b)+opdef(j)+str(c)+opdef(k)+str(d)+'=7')

Solution (Python):
abcd = input()
a = int(abcd[0])
b = int(abcd[1])
c = int(abcd[2])
d = int(abcd[3])

op = ["+", "-"]
for op1 in op:
    for op2 in op:
        for op3 in op:
            val = a
            if op1 == "+":
                val += b
            else:
                val -= b
 
            if op2 == "+":
                val += c
            else:
                val -= c
 
            if op3 == "+":
                val += d
            else:
                val -= d
            
            if val==7:
                print("{}{}{}{}{}{}{}=7".format(a,op1,b,op2,c,op3,d))
                exit(0)

Solution (Python):
 
def func(a,b,c,d,s):
    if a+b+c+d==7:
        s[1],s[3],s[5]="+","+","+"
    elif a+b+c-d==7:
        s[1],s[3],s[5]="+","+","-"
    elif a+b-c+d==7:
        s[1],s[3],s[5]="+","-","+"
    elif a+b-c-d==7:
        s[1],s[3],s[5]="+","-","-"
    elif a-b+c+d==7:
        s[1],s[3],s[5]="-","+","+"
    elif a-b+c-d==7:
        s[1],s[3],s[5]="-","+","-"
    elif a-b-c+d==7:
        s[1],s[3],s[5]="-","-","+"
    elif a-b-c-d==7:
        s[1],s[3],s[5]="-","-","-"
 
x=str(input())
ans=''
 
a=int(x[0])
b=int(x[1])
c=int(x[2])
d=int(x[3])
 
s=[a,"",b,"",c,"",d]
 
func(a,b,c,d,s)
 
for x in s:
    ans+=str(x)
 
print(ans+"=7")

Solution (Python):
"""
Bit全探索していく
"""
s = list(input())


for i in range(2**3):
    para = ["+","+","+"]
    ans = []
    for j in range(3):
        if (i >> j) & 1 :
            pass
        else : para[j] = "-"
    for i in range(4):
        ans.append(s[i])
        if i <=2 :
            ans.append(para[i])
    a = "".join(ans)
    if eval(a) == 7 :
        print(a+"=7")
        break
    else : pass

Solution (Python):
abcd = input()
a = int(abcd[0])
b = int(abcd[1])
c = int(abcd[2])
d = int(abcd[3])

op = ["+", "-"]
for op1 in op:
    for op2 in op:
        for op3 in op:
            val = a
            if op1 == "+":
                val += b
            else:
                val -= b

            if op2 == "+":
                val += c
            else:
                val -= c

            if op3 == "+":
                val += d
            else:
                val -= d
            
            if val==7:
                print("{}{}{}{}{}{}{}=7".format(a,op1,b,op2,c,op3,d))
                exit(0)

Solution (Python):
from itertools import product

ipt = input()
A, B, C, D = int(ipt[0]), int(ipt[1]), int(ipt[2]), int(ipt[3])
for b, c, d in product([1, -1], repeat=3):
    if A + b*B + c*C + d*D == 7:
        ans = str(A) + ('+' if b > 0 else '-') + str(B) + ('+' if c > 0 else '-') + str(C) + ('+' if d > 0 else '-') + str(D) + '=7'
        print(ans)
        break

Solution (Python):
A, B, C, D = [int(s) for s in input()]


def exec(x, y, op):
    if op == '+':
        return x + y
    else:
        return x - y

for op1 in ['+', '-']:
    for op2 in ['+', '-']:
        for op3 in ['+', '-']:
            if exec(exec(exec(A, B, op1), C, op2), D, op3) == 7:
                print('{A}{op1}{B}{op2}{C}{op3}{D}=7'.format(
                    A=A,
                    B=B,
                    C=C,
                    D=D,
                    op1=op1,
                    op2=op2,
                    op3=op3
                ))
                exit()

Solution (Python):
a,b,c,d = input()
op_list = ['-', '+']
for i in range(8):
    op = format(i, '03b')
    formula = a+op_list[int(op[0])]+b + op_list[int(op[1])]+c + op_list[int(op[2])] +d
    if eval(formula) == 7:
        print(formula + '=7')
        break

Solution (Python):
A, B, C, D = input()

op = ['+', '-']
for i in range(2):
    for j in range(2):
        for k in range(2):
            s = A + op[i] + B + op[j] + C + op[k] + D
            if eval(s) == 7:
                print(s + '=7')
                exit()

Solution (Python):
A, B, C, D = (int(i) for i in input())


def print_ans(op1, op2, op3):
    print('{}{}{}{}{}{}{}=7'.format(A, op1, B, op2, C, op3, D))



if A + B + C + D == 7:
    print_ans('+', '+', '+')

elif A + B + C - D == 7:
    print_ans('+', '+', '-')

elif A + B - C + D == 7:
    print_ans('+', '-', '+')

elif A + B - C - D == 7:
    print_ans('+', '-', '-')

elif A - B + C + D == 7:
    print_ans('-', '+', '+')

elif A - B + C - D == 7:
    print_ans('-', '+', '-')

elif A - B - C + D == 7:
    print_ans('-', '-', '+')

else:
    print_ans('-', '-', '-')

Solution (Python):
s = input()

for bit in range(1 << 3):
    ans = int(s[0])
    f = s[0]

    for i in range(3):
        
        if bit & (1 << i):
            ans += int(s[i + 1])
            f += "+"
        else:
            ans -= int(s[i + 1])
            f += "-"
        f += s[i + 1]

    if ans == 7:
        print(f + "=7")
        exit()

Solution (Python):
def dfs(i, f, sum):
    if i == 3:
        if sum == 7:
            
            print(f + "=7")
            exit()

    else:
        
        dfs(i + 1, f + "+" + s[i + 1], sum + int(s[i + 1]))
        dfs(i + 1, f + "-" + s[i + 1], sum - int(s[i + 1]))

s = input()

dfs(0, s[0], int(s[0]))

Solution (Python):
l=list(input())
a,b,c,d=map(str,l)
x=0
y=0
z=0
for i in range(2**3):
    if (i>>0)&1:
        x="+"
    else:
        x="-"
    if (i>>1)&1:
        y="+"
    else:
        y="-"
    if (i>>2)&1:
        z="+"
    else:
        z="-"
    ans=a+x+b+y+c+z+d
    if eval(ans)==7:
        print(ans+"=7")
        exit()

Solution (Python):
s = list(input())

op_cnt = len(s)-1
sum = 0
for i in range(2**op_cnt):
    op = ['+']*op_cnt
    for j in range(op_cnt):
        if (i>>j) & 1:
            op[j] = '-' 

    fomula = s[0]
    for j in range(op_cnt):
        fomula += op[j]
        fomula += s[j+1]
    
    if eval(fomula) == 7:
        print('{}=7'.format(fomula))
        break

Solution (Python):
from itertools import product


def find_eq():
    a, b, c, d = input()
    for x, y, z in product(("+", "-"), repeat=3):
        eq = a + x + b + y + c + z + d
        if eval(eq) == 7:
            return eq + "=7"


print(find_eq())

Solution (Python):

A, B, C, D = list(map(int, list(input())))
for b in (+B, -B):
    for c in (+C, -C):
        for d in (+D, -D):
            if A + b + c + d == 7:
                ans = str(A)
                ans += str(b) if b < 0 else "+" + str(b)
                ans += str(c) if c < 0 else "+" + str(c)
                ans += str(d) if d < 0 else "+" + str(d)
                ans += "=7"
                print(ans)
                break
        else:
            continue
        break
    else:
        continue
    break