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):
import sys
A,B,C,D = str(input())
ops = ['+', '-']

for op1 in ops:
    for op2 in ops:
        for op3 in ops:
            a = A+op1+B+op2+C+op3+D
            if eval(a) == 7:
                print(a+'=7')
                sys.exit()

Solution (Python):
import itertools

def train_ticket(n):
	sum_n = n[0]
	A = ["+", "-"]
	for i in itertools.product(A, repeat=3):
		for idx,j in enumerate(i):
			if j == "+":
				sum_n += n[idx+1]
			else:
				sum_n -= n[idx+1]
		if sum_n == 7:
			print("{0}{1}{2}{3}{4}{5}{6}=7".format(n[0], i[0],n[1],i[1],n[2],i[2],n[3]))
			break
		else:
			sum_n = n[0]



n_ticket = list(map(int, input()))
train_ticket(n_ticket)

Solution (Python):

a,b,c,d = [int(x) for x in input()]
op = [[i,j,k] for i in ['+','-'] for j in ['+','-'] for k in ['+','-']]

for x,y,z in op:
    f = "%d%s%d%s%d%s%d" % (a,x,b,y,c,z,d)
    if eval(f) == 7:
        print(f+'=7')
        break

Solution (Python):
def c_train_ticket(N):
    A, B, C, D = int(N[0]), int(N[1]), int(N[2]), int(N[3])
    op = ['---', '--+', '-+-', '-++', '+--', '+-+', '++-', '+++']
    ans = 0
    for i, j in enumerate(op):
        code = 'A {0} B {1} C {2} D'.format(j[0], j[1], j[2])
        if eval(code) == 7:
            ans = i
    return '{0}{1}{2}{3}{4}{5}{6}=7'.format(A, op[ans][0], B, op[ans][1], C, op[ans][2], D)
  
N = input()
print(c_train_ticket(N))

Solution (Python):
S = input()
A,B,C,D = int(S[0]),int(S[1]),int(S[2]),int(S[3])
for i in [B,-1*B]:
    for j in [C,-1*C]:
        for k in [D,-1*D]:
            if A + i + j + k == 7:
                print("{:d}{:+d}{:+d}{:+d}=7".format(A,i,j,k),end="")
                exit()

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

while True:
    if int(val[0]) + int(val[1]) + int(val[2]) + int(val[3]) == 7:
        print("{0}+{1}+{2}+{3}=7".format(int(val[0]), int(val[1]), int(val[2]), int(val[3])))
        break
    elif int(val[0]) - int(val[1]) - int(val[2]) - int(val[3]) == 7:
        print("{0}-{1}-{2}-{3}=7".format(int(val[0]), int(val[1]), int(val[2]), int(val[3])))
        break
    elif int(val[0]) - int(val[1]) + int(val[2]) + int(val[3]) == 7:
        print("{0}-{1}+{2}+{3}=7".format(int(val[0]), int(val[1]), int(val[2]), int(val[3])))
        break
    elif int(val[0]) + int(val[1]) - int(val[2]) + int(val[3]) == 7:
        print("{0}+{1}-{2}+{3}=7".format(int(val[0]), int(val[1]), int(val[2]), int(val[3])))
        break
    elif int(val[0]) + int(val[1]) + int(val[2]) - int(val[3]) == 7:
        print("{0}+{1}+{2}-{3}=7".format(int(val[0]), int(val[1]), int(val[2]), int(val[3])))
        break
    elif int(val[0]) - int(val[1]) - int(val[2]) + int(val[3]) == 7:
        print("{0}-{1}-{2}+{3}=7".format(int(val[0]), int(val[1]), int(val[2]), int(val[3])))
        break
    elif int(val[0]) - int(val[1]) + int(val[2]) - int(val[3]) == 7:
        print("{0}-{1}+{2}-{3}=7".format(int(val[0]), int(val[1]), int(val[2]), int(val[3])))
        break
    elif int(val[0]) + int(val[1]) - int(val[2]) - int(val[3]) == 7:
        print("{0}+{1}-{2}-{3}=7".format(int(val[0]), int(val[1]), int(val[2]), int(val[3])))
        break

Solution (Python):
b = list(map(int, input().split()))
mozi = str(b)
A = b[0]//1000
B = (b[0]-A*1000)//100
C = (b[0]-A*1000-B*100)//10
D = b[0]%10

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):
istr = raw_input()
lis = [int(istr[0]),int(istr[1]),int(istr[2]),int(istr[3])]
if   lis[0] + lis[1] + lis[2] + lis[3] == 7:
    print (istr[0]+"+"+istr[1]+"+"+istr[2]+"+"+istr[3]+"=7")
elif lis[0] + lis[1] + lis[2] - lis[3] == 7:
    print (istr[0]+"+"+istr[1]+"+"+istr[2]+"-"+istr[3]+"=7")
elif lis[0] + lis[1] - lis[2] + lis[3] == 7:
    print (istr[0]+"+"+istr[1]+"-"+istr[2]+"+"+istr[3]+"=7")
elif lis[0] + lis[1] - lis[2] - lis[3] == 7:
    print (istr[0]+"+"+istr[1]+"-"+istr[2]+"-"+istr[3]+"=7")
elif lis[0] - lis[1] + lis[2] + lis[3] == 7:
    print (istr[0]+"-"+istr[1]+"+"+istr[2]+"+"+istr[3]+"=7")
elif lis[0] - lis[1] + lis[2] - lis[3] == 7:
    print (istr[0]+"-"+istr[1]+"+"+istr[2]+"-"+istr[3]+"=7")
elif lis[0] - lis[1] - lis[2] + lis[3] == 7:
    print (istr[0]+"-"+istr[1]+"-"+istr[2]+"+"+istr[3]+"=7")
elif lis[0] - lis[1] - lis[2] - lis[3] == 7:
    print (istr[0]+"-"+istr[1]+"-"+istr[2]+"-"+istr[3]+"=7")

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

mark = ["+", "-"]

for m1 in mark:
  for m2 in mark:
    for m3 in mark:
      if eval("{0} {1} {2} {3} {4} {5} {6}".format(A,m1,B,m2,C,m3,D)) == 7:
        print("{0}{1}{2}{3}{4}{5}{6}=7".format(A,m1,B,m2,C,m3,D))
        exit()

Solution (Python):
N = list(input())
A = int(N[0])
B = int(N[1])
C = int(N[2])
D = int(N[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):
N = list(input())

if int(N[0]) + int(N[1]) + int(N[2]) + int(N[3]) == 7:
    print(N[0]+"+"+N[1]+"+"+N[2]+"+"+N[3]+"=7")
elif int(N[0]) - int(N[1]) + int(N[2]) + int(N[3]) == 7:
    print(N[0]+"-"+N[1]+"+"+N[2]+"+"+N[3]+"=7")
elif int(N[0]) + int(N[1]) - int(N[2]) + int(N[3]) == 7:
    print(N[0]+"+"+N[1]+"-"+N[2]+"+"+N[3]+"=7")
elif int(N[0]) + int(N[1]) + int(N[2]) - int(N[3]) == 7:
    print(N[0]+"+"+N[1]+"+"+N[2]+"-"+N[3]+"=7")
elif int(N[0]) - int(N[1]) - int(N[2]) + int(N[3]) == 7:
    print(N[0]+"-"+N[1]+"-"+N[2]+"+"+N[3]+"=7")
elif int(N[0]) - int(N[1]) + int(N[2]) - int(N[3]) == 7:
    print(N[0]+"-"+N[1]+"+"+N[2]+"-"+N[3]+"=7")
elif int(N[0]) + int(N[1]) - int(N[2]) - int(N[3]) == 7:
    print(N[0]+"+"+N[1]+"-"+N[2]+"-"+N[3]+"=7")
elif int(N[0]) - int(N[1]) - int(N[2]) - int(N[3]) == 7:
    print(N[0]+"-"+N[1]+"-"+N[2]+"-"+N[3]+"=7")
else:
    pass

Solution (Python):
from itertools import product


def main():
    """
    A op1 B op2 C op3 D = 7
    op: +, -
    """

    _input = input()
    op1, op2, op3 = f(_input)
    A, B, C, D = list(_input)
    print(A + op1 + B + op2 + C + op3 + D + "=7")


def f(_input):
    A, B, C, D = map(int, list(_input))
    ans = 7 - A

    op = ("+", "-")
    op_p = product(op, op, op)
    bcd_p = product((B, -B), (C, -C), (D, -D))
    for ops, bcd in zip(op_p, bcd_p):
        if sum(bcd) == ans:
            return ops

if __name__ == '__main__':
    main()

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

for x1 in ["+","-"]:
    for x2 in ["+","-"]:
        for x3 in ["+","-"]:
            if eval(a+x1+b+x2+c+x3+d)==7:
                t=1
            if t==1:
                break
        if t==1:
            break  
    if t==1:
        break
        
print(a+x1+b+x2+c+x3+d+"=7")

Solution (Python):
N = input()
n = []
for i in N:
    n.append(int(i))
if n[0] + n[1] + n[2] + n[3] == 7:
    print(N[0] + "+" + N[1] + "+" + N[2] + "+" + N[3] + "=7")
elif n[0] - n[1] + n[2] + n[3] == 7:
    print(N[0] + "-" + N[1] + "+" + N[2] + "+" + N[3] + "=7")
elif n[0] + n[1] - n[2] + n[3] == 7:
    print(N[0] + "+" + N[1] + "-" + N[2] + "+" + N[3] + "=7")
elif n[0] - n[1] - n[2] + n[3] == 7:
    print(N[0] + "-" + N[1] + "-" + N[2] + "+" + N[3] + "=7")
elif n[0] + n[1] + n[2] - n[3] == 7:
    print(N[0] + "+" + N[1] + "+" + N[2] + "-" + N[3] + "=7")
elif n[0] - n[1] + n[2] - n[3] == 7:
    print(N[0] + "-" + N[1] + "+" + N[2] + "-" + N[3] + "=7")
elif n[0] + n[1] - n[2] - n[3] == 7:
    print(N[0] + "+" + N[1] + "-" + N[2] + "-" + N[3] + "=7")
elif n[0] - n[1] - n[2] - n[3] == 7:
    print(N[0] + "-" + N[1] + "-" + N[2] + "-" + N[3] + "=7")

Solution (Python):
N=raw_input()
A=int(N[0])
B=int(N[1])
C=int(N[2])
D=int(N[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 = []
for i in s:
    n.append(int(i))

for i in range(2):
    for j in range(2):
        for k in range(2):
            if i % 2 == 1:
                n1 = n[0] + n[1]
                o1 = '+'
            else:
                n1 = n[0] - n[1]
                o1 = '-'
            if j % 2 == 1:
                n2 = n1 + n[2]
                o2 = '+'
            else:
                n2 = n1 - n[2]
                o2 = '-'
            if k % 2 == 1:
                n3 = n2 + n[3]
                o3 = '+'
            else:
                n3 = n2 - n[3]
                o3 = '-'
            if n3 == 7:
                print(n[0], o1, n[1], o2, n[2], o3, n[3], '=7', sep='')
                exit()

Solution (Python):

def cal(arr, idx, res):

    if idx == 4 and res == 7:
        return True, ''

    if idx < 4:
        flg, op = cal(arr, idx+1, res+int(arr[idx]))
        if flg:
            return True, '+'+op

        flg, op = cal(arr, idx+1, res-int(arr[idx]))
        if flg:
            return True, '-'+op

    return False, ''

def main():
    n = input()
    _, op = cal(n, 0, 0)
    res = ''
    for i in range(3):
        res += n[i] + op[i+1]

    res += n[3] + '=7'
    print(res)
    return

if __name__ == '__main__':
    main()

Solution (Python):
z = [0, 0, 0, 0]
inp = input()
for i in range(4):
    z[i] = int(inp[i])
res = 0
out = ""
for i in range(2):
    for j in range(2):
        for k in range(2):
            if(res == 7):
                break
            res = 0
            if(i == 0):
                out = str(z[0]) + "+" + str(z[1])
                res = z[0] + z[1]
            else:
                out = str(z[0]) + "-" + str(z[1])
                res = z[0] - z[1]

            if(j == 0):
                out += "+" + str(z[2])
                res += z[2]
            else:
                out += "-" + str(z[2])
                res -= z[2]

            if(k == 0):
                out += "+" + str(z[3])
                res += z[3]
            else:
                out += "-" + str(z[3])
                res -= z[3]
print(out + "=7")

Solution (Python):
a = ['+', '-']
b = [lambda x,y: x+y, lambda x,y: x-y]

A, B, C, D = map(int, input())

end = False
for q, w in zip(a, b):
    for t, y in zip(a, b):
        for o, p in zip(a, b):
            if p(y(w(A,B), C), D) == 7:
                print('{0}{1}{2}{3}{4}{5}{6}=7'.format(A,q,B,t,C,o,D))
                exit()

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

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):
def main():
    ABCD = input()

    total = 0
    mask = 0
    n = len(ABCD)
    while mask < (1<<(n-1)):
        i = 0
        s = list(ABCD)
        while i < n-1:
            if mask & (1<<i):
                s[i] = s[i] + '+'
            else:
                s[i] = s[i] + '-'
            i += 1
        total = eval(''.join(s))
        if total == 7:
            break
        mask += 1

    print(*s, sep='', end='')
    print('=' + str(total))

main()

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

def Calc(a,b,op):
    if op == "+":
        return int(a) + int(b)
    else:
        return int(a) - int(b)

ops = [["+","+","+"], ["+","+","-"], ["+","-","+"], ["-","+","+"],
       ["-","-","+"], ["-","+","-"], ["+","-","-"], ["-","-","-"]]

for op1, op2, op3 in ops:
    AB = Calc(ABCD[0],ABCD[1],op1)
    ABC = Calc(AB, ABCD[2], op2)
    ans = Calc(ABC, ABCD[3], op3)

    if ans == 7:
        print(ABCD[0]+op1+ABCD[1]+op2+ABCD[2]+op3+ABCD[3] + "=7")
        break

Solution (Python):
x=list(map(int,list(input())))
a=x[0]
b=x[1]
c=x[2]
d=x[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):
from sys import stdin

def Int_all(): return list(map(int, stdin))
def IL():return list(map(int, stdin.readline().split()))


def dfs(i,s):

	if i == 4:
		return s==7

	if dfs(i+1,s+a[i]):
		if i != 0:
			ans[i] = "+"+str(a[i])
		else:
			ans[i] = str(a[i])
		return True
	if dfs(i+1, s-a[i]):
		if i != 0:
			ans[i] = "-"+str(a[i])
		else:
			ans[i] = str(a[i])
		
		return True

	return False



a = list(map(int,list(input())))
ans = [0 for i in range(4)]

def main():
	dfs(0,0)
	print("{}=7".format(''.join(ans)))

if __name__ == "__main__": main()

Solution (Python):
n = int(input())
a = n // 1000
b = n % 1000 // 100
c = n % 100 // 10
d = n % 10

def calc(ind, x):
    if ind == 0:
        return x
    else:
        return -x

flag = 0
for j in range(2):
    ans1 = a
    if flag:
        break
    ans2 = ans1 + calc(j, b)
    for k in range(2):
        if flag:
            break
        ans3 = ans2 + calc(k, c)
        for l in range(2):
            ans4 = ans3 + calc(l, d)
            if ans4 == 7:
                flag = 1
                result = ['+' if x == 0 else '-' for x in [j, k, l]]
                break
answer = str(a) + result[0] + str(b) + result[1] + str(c) + result[2] + str(d) + '=7'
print (answer)

Solution (Python):


N = int(input())

a = int(N/1000)
x = N % 1000
b = int(x/100)
x = x % 100
c = int(x/10)
x = x % 10
d = x

tmp = [0 for i in range(8)]
tmp2 = ['{}+{}+{}+{}'.format(a, b, c, d), '{}+{}+{}-{}'.format(a, b, c, d),
        '{}+{}-{}+{}'.format(a, b, c, d), '{}+{}-{}-{}'.format(a, b, c, d),
        '{}-{}+{}+{}'.format(a, b, c, d), '{}-{}+{}-{}'.format(a, b, c, d),
        '{}-{}-{}+{}'.format(a, b, c, d), '{}-{}-{}-{}'.format(a, b, c, d)]

tmp[0] = a + b + c + d
tmp[1] = a + b + c - d
tmp[2] = a + b - c + d
tmp[3] = a + b - c - d
tmp[4] = a - b + c + d
tmp[5] = a - b + c - d
tmp[6] = a - b - c + d
tmp[7] = a - b - c - d

for i in range(8):
    if(tmp[i] == 7):
        x = i
        break

print(str(tmp2[i])+'=7')

Solution (Python):
a,b,c,d = map(int,input())
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")
else:
    print(str(a)+ "-" +str(b) +"-"+ str(c) +"-"+ str(d)+ "=7")

Solution (Python):
s = input()
ops = "+-"

for op1 in ops :
    for op2 in ops :
        for op3 in ops :
            exp = s[0]+op1+s[1]+op2+s[2]+op3+s[3]
            val = eval(exp)
            if val == 7 :
                print(exp + '=7')
                exit(0)

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(a, '+', b, '+', c, '+', d, '=7', sep='')
elif a - b + c + d == 7:
    print(a, '-', b, '+', c, '+', d, '=7', sep='')
elif a + b - c + d == 7:
    print(a, '+', b, '-', c, '+', d, '=7', sep='')
elif a - b - c + d == 7:
    print(a, '-', b, '-', c, '+', d, '=7', sep='')
elif a + b + c - d == 7:
    print(a, '+', b, '+', c, '-', d, '=7', sep='')
elif a - b + c - d == 7:
    print(a, '-', b, '+', c, '-', d, '=7', sep='')
elif a + b - c - d == 7:
    print(a, '+', b, '-', c, '-', d, '=7', sep='')
elif a - b - c - d == 7:
    print(a, '-', b, '-', c, '-', d, '=7', sep='')

Solution (Python):
a = input()
b = [int(x) for x in a]
c = []
d = " +-"

for x in [1,-1]:
    for y in [1,-1]:
        for z in [1,-1]:
            if b[0]+x*b[1]+y*b[2]+z*b[3] == 7:
                c.append(""+str(b[0])+d[x]+str(b[1])+d[y]+str(b[2])+d[z]+str(b[3])+"=7")
print(c[0])

Solution (Python):

import sys
N = input()
a, b, c, d = int(N[0]),int(N[1]), int(N[2]), int(N[3])
n = a + b + c + d
if n == 7:
    print("{}+{}+{}+{}=7".format(a, b, c, d))
    sys.exit()
n = a - b + c + d
if n == 7:
    print("{}-{}+{}+{}=7".format(a, b, c, d))
    sys.exit()
n = a + b - c + d
if n == 7:
    print("{}+{}-{}+{}=7".format(a, b, c, d))
    sys.exit()
n = a + b - c + d
if n == 7:
    print("{}+{}-{}+{}=7".format(a, b, c, d))
    sys.exit()
n = a + b + c - d
if n == 7:
    print("{}+{}+{}-{}=7".format(a, b, c, d))
    sys.exit()
n = a - b - c + d
if n == 7:
    print("{}-{}-{}+{}=7".format(a, b, c, d))
    sys.exit()
n = a + b - c - d
if n == 7:
    print("{}+{}-{}-{}=7".format(a, b, c, d))
    sys.exit()
n = a - b + c - d
if n == 7:
    print("{}-{}+{}-{}=7".format(a, b, c, d))
    sys.exit()
n = a - b - c - d
if n == 7:
    print("{}-{}-{}-{}=7".format(a, b, c, d))
    sys.exit()

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

o = [1, 1, 1]
o2 = []

for i in range(2):
    o[0] *= -1
    for j in range(2):
        o[1] *= -1
        for k in range(3):
            o[2] *= -1
            ans = int(abcd[0]) + int(abcd[1])*o[0] + int(abcd[2])*o[1] + int(abcd[3])*o[2]
            
            if ans == 7:
                for l in o:
                    if l > 0:
                        o2.append('+')
                    else:
                        o2.append('-')
                print(abcd[0] + o2[0] + abcd[1] + o2[1] + abcd[2] + o2[2] + abcd[3] + '=7')
                quit()

Solution (Python):
def main():
    A = list(map(int,str(input())))

    s1 = "+"
    s2 = "+"
    s3 = "+"    

    if A[0] + A[1] + A[2] + A[3] == 7:
        s1 = "+"
        s2 = "+"
        s3 = "+"
    elif A[0] + A[1] + A[2] - A[3] == 7:
        s1 = "+"
        s2 = "+"
        s3 = "-"
    elif A[0] + A[1] - A[2] + A[3] == 7:
        s1 = "+"
        s2 = "-"
        s3 = "+"
    elif A[0] - A[1] + A[2] + A[3] == 7:   
        s1 = "-"
        s2 = "+"
        s3 = "+"
    elif A[0] + A[1] - A[2] - A[3] == 7:   
        s1 = "+"
        s2 = "-"
        s3 = "-"
    elif A[0] - A[1] + A[2] - A[3] == 7:   
        s1 = "-"
        s2 = "+"
        s3 = "-"
    elif A[0] - A[1] - A[2] + A[3] == 7:   
        s1 = "-"
        s2 = "-"
        s3 = "+"
    elif A[0] - A[1] - A[2] - A[3] == 7:   
        s1 = "-"
        s2 = "-"
        s3 = "-"

    print(str(A[0]) + s1 + str(A[1]) + s2 + str(A[2]) + s3 + str(A[3]) + "=7")


if __name__ == "__main__":
    main()

Solution (Python):
import itertools

ABCD = list(map(int, input()))

for ops in itertools.product('+-', '+-', '+-'):
    ans = ABCD[0]
    for i, op in enumerate(ops, 1):
        if op == '+':
            ans += ABCD[i]
        else:
            ans -= ABCD[i]

    if ans == 7:
        ss = str(ABCD[0])
        for i, op in enumerate(ops, 1):
            ss += op + str(ABCD[i])
        ss += '=7'
        print(ss)
        exit()

Solution (Python):
q = [int(x) for x in input()]

if sum(q) == 7:
	print("{}+{}+{}+{}=7".format(q[0], q[1], q[2], q[3]))
else:
	if q[0]-q[1]+q[2]+q[3] == 7:
		print("{}-{}+{}+{}=7".format(q[0], q[1], q[2], q[3]))
	elif q[0]+q[1]-q[2]+q[3] == 7:
		print("{}+{}-{}+{}=7".format(q[0], q[1], q[2], q[3]))
	elif q[0]+q[1]+q[2]-q[3] == 7:
		print("{}+{}+{}-{}=7".format(q[0], q[1], q[2], q[3]))	
	elif q[0]-q[1]-q[2]+q[3] == 7:
		print("{}-{}-{}+{}=7".format(q[0], q[1], q[2], q[3]))
	elif q[0]-q[1]+q[2]-q[3] == 7:
		print("{}-{}+{}-{}=7".format(q[0], q[1], q[2], q[3]))
	elif q[0]+q[1]-q[2]-q[3] == 7:
		print("{}+{}-{}-{}=7".format(q[0], q[1], q[2], q[3]))
	elif q[0]-q[1]-q[2]-q[3] == 7:
		print("{}-{}-{}-{}=7".format(q[0], q[1], q[2], q[3]))

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

ops = ["+","-"]

ans = []
for op1 in ops:
    for op2 in ops:
        for op3 in ops:
            tmp = 0
            if op1 == "+":
                tmp = int(A)+int(B)
            else:
                tmp = int(A)-int(B)

            if op2 == "+":
                tmp = tmp + int(C)
            else:
                tmp = tmp - int(C)

            if op3 == "+":
                tmp = tmp + int(D)
            else:
                tmp = tmp - int(D)

            if tmp == 7:
                ans.append(str(A) + op1 + str(B) + op2 + str(C) + op3 + str(D) + "=7")

print(ans[0])

Solution (Python):
import sys

N = int(sys.stdin.readline().strip())

a = int(N / 1000)
b = int(N / 100) - a * 10
c = int(N / 10) - b * 10 - a * 100
d = N % 10

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):



def main():
    A, B, C, D = [int(i) for i in input()]
    B, C, D = [[i, -i] for i in [B, C, D]]
    pm = ["+", ""]
    for i in range(2):
        for j in range(2):
            for k in range(2):
                if A + B[i] + C[j] + D[k] == 7:
                    ans = [A, pm[i], B[i], pm[j], C[j], pm[k], D[k], "=7"]
                    return("".join(map(str,ans)))

if __name__ == "__main__":
    print(main())

Solution (Python):
import sys
A, B, C, D = map(int, input())
ops = ['+', '-']
for op1 in ops:
    for op2 in ops:
        for op3 in ops:
            tmp = A
            if op1 == '+':
                tmp += B
            else:
                tmp -= B
            if op2 == '+':
                tmp += C
            else:
                tmp -= C
            if op3 == '+':
                tmp += D
            else:
                tmp -= D
            if tmp == 7:
                print("{}{}{}{}{}{}{}=7".format(A,op1,B,op2,C,op3,D))
                sys.exit()

Solution (Python):
n = input()

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

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

Solution (Python):

import itertools
input_str = input()
A = input_str[0]
B = input_str[1]
C = input_str[2]
D = input_str[3]

ops = ['+', '-']
all_ops = list(itertools.product(A, ops, B, ops, C, ops, D))
for tmp in all_ops:
    result = eval(''.join(tmp))
    if result == 7:
        print(''.join(tmp) + "=7")
        break

Solution (Python):




order=['+++','++-','+-+','+--','-++','-+-','--+','---']

s=input()
flag=-1
for i in range(8):
    ans=int(s[0])
    for j in range(1,len(s)):
        if order[i][j-1]=='+':
            ans+=(int(s[j]))
        else:
            ans-=(int(s[j]))
    if ans==7:
        flag=i

if flag>-1:
    for i in range(3):
        print(s[i],order[flag][i],sep="",end="")
    print(s[3],"=7",sep="")

Solution (Python):
A,B,C,D = list(input())
for op1 in ['+','-']:
    for op2 in ['+','-']:
        for op3 in ['+','-']:
            k = A + op1 + B + op2 + C + op3 + D
            if eval(k) == 7:
                print(k+'=7')
                exit()

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


for i in range(8):
    op1=1 if i%2 ==0 else -1
    op2=1 if (i//2)%2==0 else -1
    op3=1 if (i//4)%2==0 else -1
    
    if A + op1*B + op2*C + op3*D == 7:
        print(str(A)+ ("+" if op1==1 else "-")
              +str(B)+ ("+" if op2==1 else "-")
               + str(C) +( "+" if op3==1 else "-")
              +str(D)+"=7"
                )
        exit()

Solution (Python):
def ope(f):
    if f:
        return "+"
    return "-"

flag = False
A, B, C, D = map(int, list(input()))
for a in [1, 0]:
    for b in [1, 0]:
        for c in [1, 0]:
            for d in [1, 0]:
                result = eval("{} {} {} {} {} {} {}".format(A, ope(a), B, ope(b), C, ope(c), D))
                if result == 7:
                    print("{}{}{}{}{}{}{}=7".format(A, ope(a), B, ope(b), C, ope(c), D))
                    flag = True
                    break
            if flag:
                break
        if flag:
            break
    if flag:
        break

Solution (Python):


if __name__ == '__main__':
    N = raw_input()
    if int(N[0])+int(N[1])+int(N[2])+int(N[3]) == 7:
        print('{0}+{1}+{2}+{3}=7'.format(N[0],N[1],N[2],N[3]))
    elif int(N[0])+int(N[1])+int(N[2])-int(N[3]) == 7:
        print('{0}+{1}+{2}-{3}=7'.format(N[0],N[1],N[2],N[3]))
    elif int(N[0])+int(N[1])-int(N[2])+int(N[3]) == 7:
        print('{0}+{1}-{2}+{3}=7'.format(N[0],N[1],N[2],N[3]))
    elif int(N[0])+int(N[1])-int(N[2])-int(N[3]) == 7:
        print('{0}+{1}-{2}-{3}=7'.format(N[0],N[1],N[2],N[3]))
    elif int(N[0])-int(N[1])+int(N[2])+int(N[3]) == 7:
        print('{0}-{1}+{2}+{3}=7'.format(N[0],N[1],N[2],N[3]))
    elif int(N[0])-int(N[1])+int(N[2])-int(N[3]) == 7:
        print('{0}-{1}+{2}-{3}=7'.format(N[0],N[1],N[2],N[3]))
    elif int(N[0])-int(N[1])-int(N[2])+int(N[3]) == 7:
        print('{0}-{1}-{2}+{3}=7'.format(N[0],N[1],N[2],N[3]))
    elif int(N[0])-int(N[1])-int(N[2])-int(N[3]) == 7:
        print('{0}-{1}-{2}-{3}=7'.format(N[0],N[1],N[2],N[3]))

Solution (Python):
s=input()

for i in range(7):
    op=bin(i)[2:].zfill(3).replace('0','+').replace('1','-')
    v=s[0]+op[0]+s[1]+op[1]+s[2]+op[2]+s[3]+'==7'
    if eval(v):
        print(v.replace('==','='))
        exit(0)

Solution (Python):



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

op1 = "+"
op2 = "+"
op3 = "+"

if a+b+c+d==7:
    pass
elif a+b+c-d==7:
    op3 = "-"
elif a+b-c+d==7:
    op2 = "-"
elif a+b-c-d==7:
    op2 = "-"
    op3 = "-"
elif a-b+c+d==7:
    op1 = "-"
elif a-b+c-d==7:
    op1 = "-"
    op3 = "-"
elif a-b-c+d==7:
    op1 = "-"
    op2 = "-"
else:
    op1 = "-"
    op2 = "-"
    op2 = "-"

ans = abcd[0]+op1+abcd[1]+op2+abcd[2]+op3+abcd[3]+"=7"

print ans

Solution (Python):
import sys

line = sys.stdin.readline().strip()

for i in range(8):
    siki = line[0] + "+-"[(i >> 2) & 1] + line[1] + "+-"[(i >> 1) & 1] + line[2] + "+-"[(i >> 0) & 1] + line[3]
    r = eval(siki)
    if r == 7:
        print("%s=%d" % (siki, r))
        break

Solution (Python):
import sys

str_n = input()
N = [int(i) for i in str_n]

OPS = ['+', '-']

for op1 in OPS:
    for op2 in OPS:
        for op3 in OPS:
            ans = N[0]
            if op1 == '+':
                ans += N[1]
            else:
                ans -= N[1]
            if op2 == '+':
                ans += N[2]
            else:
                ans -= N[2]
            if op3 == '+':
                ans += N[3]
            else:
                ans -= N[3]
            if ans == 7:
                print(str_n[0] + op1 + str_n[1] + op2 + str_n[2] + op3 + str_n[3] + '=7')
                sys.exit()

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

q = ["+","-"]

now = a
for x2 in range(2):
  now2 = now + b * pow(-1,x2)
  for x3 in range(2):
    now3 = now2 + c * pow(-1,x3)
    for x4 in range(2):
      now4 = now3 + d * pow(-1,x4)
      if now4 == 7:
        print "%d%s%d%s%d%s%d=7" % (a,q[x2],b,q[x3],c,q[x4],d)
        exit(0)

Solution (Python):
import sys

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

for i in range(2):
    s0 = A
    if i == 0:
        s1 = s0 + B
    else:
        s1 = s0 - B

    for j in range(2):
        if j == 0:
            s2 = s1 + C
        else:
            s2 = s1 - C

        for k in range(2):
            if k == 0:
                s3 = s2 + D
            else:
                s3 = s2 - D

            if s3 == 7:
                ans = str(A)
                if i == 0:
                    ans += '+'
                else:
                    ans += '-'
                ans += str(B)
                if j == 0:
                    ans += '+'
                else:
                    ans += '-'
                ans += str(C)
                if k == 0:
                    ans += '+'
                else:
                    ans += '-'
                ans += str(D)
                ans += '=7'
                print(ans)
                sys.exit()