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):
s = list(input())

def calc(i, a, b):
  a ,b = int(a), int(b)
  if i==0:
    c = a+b
  elif i==1:
    c = a-b
  return c
 
def tag(t_list):
  t = []
  for p in t_list:
    if p==0:
        t.append('+')
    else:
        t.append('-')
  return(t)
    
for i in range(2):
  c = calc(i,s[0],s[1])
  for j in range(2):
    d = calc(j,c,s[2])
    for k in range(2):
      e = calc(k,d,s[3])
      if e == 7:
        t_list = [i,j,k]
        t = tag(t_list)
        print(s[0]+t[0]+s[1]+t[1]+s[2]+t[2]+s[3]+'=7')
        exit()

Solution (Python):
import random as rng
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)


def dump_impl(*objects):
    print(*objects, file=sys.stderr)


def dump_dummy(*objects):
    pass


dump = dump_impl if "DEBUG" in sys.argv else dump_dummy


S = input()
A, B, C, D = map(int, [S[0], S[1], S[2], S[3]])
dump(A, B, C, D)
for op1, op2, op3 in it.product(['+', '-'], repeat=3):
    dump(op1, op2, op3)

    def f(op, a): return a * (1 if op == '+' else -1)
    ans = A + f(op1, B) + f(op2, C) + f(op3, D)
    dump(A, f(op1, B), f(op2, C), f(op3, D))
    if(ans == 7):
        print(str(A)+op1+str(B)+op2+str(C)+op3+str(D)+"=7")
        exit(0)
print("")

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

idx = [0, 1, 2]
output = []
for i in range(1 << len(idx)):
    ops = ['+', '+', '+']
    if A+B+C+D == 7: 
        print(A,ops[0],B,ops[1],C,ops[2],D,'=7',sep='')
        exit()
    
    ans = A
    for j in range(len(idx)):
        if ((i >> j) & 1) == 1:
            ops[j] = '-'
    
    if ops[0] == '+' : ans += B
    else : ans -= B
    
    if ops[1] == '+' : ans += C
    else : ans -= C
    
    if ops[2] == '+' : ans += D
    else : ans -= D
    
    if ans == 7:
        print(A,ops[0],B,ops[1],C,ops[2],D,'=7',sep='')
        exit()

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
mod = 10**9+7


ABCD = input().rstrip()

from itertools import product
ops = list(product(["+","-"],repeat=3))

x = [0]*7
for op in ops:
    x[0::2] = ABCD
    x[1::2] = op
    exp = "".join(x)
    if eval(exp)==7:
        print(exp+"=7")
        sys.exit()

Solution (Python):



import pdb
import sys
F = sys.stdin

S = F.readline().rstrip()
A = int(S[:1])
B = int(S[1:2])
C = int(S[2:3])
D = int(S[3:4])

sum = A
nums = [B, C, D]
N = 3
l = [0, 0, 0]
ans = str(A)


for bit in range(1<<N):
    for i in range(N):
        if bit & (1<<i):
            sum -= nums[i]
            l[i] = 1
            continue
        sum += nums[i]

    if sum == 7:
        for j in range(N):
            if l[j] == 0:
                ans += ('+' + str(nums[j]))
                continue
            ans += ('-' + str(nums[j]))

        ans += '=7'

        print(ans)
        sys.exit()
    l = [0,0,0]
    sum = A

print('NO_ANSWER')

Solution (Python):
S = input()
str_list = list(S)

for i in range(2 ** 3):
    num = int(str_list[0])
    ans = str_list[0]
    for j in range(3):
        if (i >> j) & 1:
            num += int(str_list[j + 1])
            ans += '+'
        else:
            num -= int(str_list[j + 1])
            ans += '-'
        ans += str_list[j + 1]
    if num == 7:
        ans += '=7'
        print(ans)
        break

Solution (Python):
def solve():
    A, B, C, D = input()
    op = '+-'
    
    for op1 in op:
        for op2 in op:
            for op3 in op:
                left_hand = A + op1 + B + op2 + C + op3 + D
                if eval(left_hand) == 7:
                    return left_hand + '=7'

print(solve())

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

for i in range(2 ** 3):
    eq = a + ("+" if i % 2 else "-") + b + ("+" if (i >> 1) % 2 else "-") + c + ("+" if (i >> 2) % 2 else "-") + d
    if eval(eq) == 7:
        print(eq + "=7")
        break

Solution (Python):
s = input()
s = [s[_] for _ in range(len(s))]
l = ['-']*len(s)
answers = []
for i in range(8):
    l = ['-']*len(s)
    for j in range(3):
        if ((i>>j) & 1):
            l[j] = '+'
    ans = []
    for j, k in zip(s, l):
        ans.append(j)
        ans.append(k)
    ans = ans[:-1]
    ans1 = ''.join(ans)
    ans2 = 0
    for _, j in enumerate(s):
        if _ == 0:
            ans2 += int(j)
        else:
            if l[_-1] == '-':
                ans2 -= int(j)
            else:
                ans2 += int(j)
    answers.append([ans1, ans2])
for i in answers:
    if i[1] == 7:
        print(''.join(i[0]) + '=7')
        break

Solution (Python):
S = input()
ans = 0
f = ""
for i in range(1 << len(S)-1):
    f = S[0]
    for j in range(len(S)-1):
        if ((i >> j) & 1) == 1:
            f += "+"
        else:
            f += "-"
        f += S[j+1]
    if eval(f) == 7:
        print(f+"=7")
        exit()

Solution (Python):

S = input()

def solve(n, S, idx):

    if len(n) == 7:
        if eval(n) == 7:
            n+="=7"
            print(n)
            exit()
        return

    solve(n+"+"+S[idx], S,idx+1)
    solve(n+"-"+S[idx], S,idx+1)

solve(S[0], S, 1)

Solution (Python):
import sys


def main():
    ticket = list(input())

    op = [""] * 3

    for i in range(2):
        if i == 0:
            op[0] = "+"
        else:
            op[0] = "-"
        for j in range(2):
            if j == 0:
                op[1] = "+"
            else:
                op[1] = "-"
            for k in range(2):
                if k == 0:
                    op[2] = "+"
                else:
                    op[2] = "-"

                eq = ""
                for n in range(3):
                    eq += ticket[n] + op[n]
                eq += ticket[-1]

                if eval(eq) == 7:
                    print(eq + "=7")
                    sys.exit()


main()

Solution (Python):
n = [int(x) for x in input()]
op = len(n) - 1
for i in range(2**op):
    op_list = ["-"]*op
    for j in range(op):
        if (i>>j)&1:
            op_list[op-1-j] = "+"
    formula = ""
    for p_n,p_o in zip(n,op_list+[""]):
        formula += str(p_n) + p_o
    if eval(formula) == 7:
        print(formula+"=7")
        break

Solution (Python):
s = input()
print(filter(lambda x : eval(x) == 7, [''.join(sum(zip(s, ['+' if ((bit >> i) & 1) == 1 else '-' for i in range(4)]), ()))[:-1] for bit in range(1 << 3)]).__next__()+'=7')

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

op = ['+', '-']
for op1 in op:
    for op2 in op:
        for op3 in op:
            result = A+op1+B+op2+C+op3+D
            if eval(result) == 7:
                print(result + '=7')
                exit()

Solution (Python):
from itertools import product
X = list(map(int, input()))
op = {'+':1, '-':-1}

for ops  in product(op, repeat=3):
    v = X[0] + sum([x*op[o] for x,o in zip(X[1:], ops)])
    if v==7:
        print('{X[0]}{ops[0]}{X[1]}{ops[1]}{X[2]}{ops[2]}{X[3]}=7'.format(X=X, ops=ops))
        exit()

Solution (Python):
s = input()

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

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

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))
else:
    print('{}-{}-{}-{}=7'.format(a,b,c,d))

Solution (Python):
num = input()

for i in range(2**3):
    formula = num[0]
    for j in range(3):
        if (i>>j) & 1:
            formula += '+'
        else:
            formula += '-'
        formula += num[j+1]
    if eval(formula) == 7:
        print(formula + '=7')
        break

Solution (Python):
import sys

a, b, c, d = [int(i) for i in list(input())]

K = [1, -1]

for i in K:
    for j in K:
        for k in K:
            if i*b + j*c + k*d == 7 - a:
                if i*b >= 0:stb = "+{}".format(b)
                else:stb = "-{}".format(b)
                if j*c >= 0:stc = "+{}".format(c)
                else:stc = "-{}".format(c)
                if k*d >= 0:std = "+{}".format(d)
                else:std = "-{}".format(d)
                print(str(a)+stb+stc+std+"=7")
                sys.exit()

Solution (Python):
abcd=list(input())
lst=["+","-"]
lst_2=[]
lst_buf=[]
for x in lst:
    for y in lst:
        for z in lst:
            lst_buf=[x,y,z]
            lst_2.append(lst_buf)
buf=''
for l in lst_2:
    buf=abcd[0]+l[0]+abcd[1]+l[1]+abcd[2]+l[2]+abcd[3]
    if 7==eval(buf):
        print(buf+"=7")
        break

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

for i in range(2**3):
  tmp=A[:]
  for j in range(3):
    if (i>>j)&1:
      tmp[j]+="-"
    else:
      tmp[j]+="+"
  if eval("".join(tmp)) == 7:
    tmp[-1]+="=7"
    for s in tmp:
      print(s,end="")
    exit()

Solution (Python):
ABCD = input()

for i in range(2**(len(ABCD)-1)):
    n = int(ABCD[0])
    ans = ABCD[0]
    for j, c in enumerate(format(i, '0' + str(len(ABCD)-1) + 'b')):
        if c == '0':
            n += int(ABCD[j+1])
            ans += '+'
        else:
            n -= int(ABCD[j+1])
            ans += '-'
        ans += ABCD[j+1]
    if n == 7:
        print(ans + '=7')
        exit(0)

Solution (Python):
S = input()
if int(S[0])+int(S[1])+int(S[2])+int(S[3])==7:
  print(S[0]+"+"+S[1]+"+"+S[2]+"+"+S[3]+"=7")
elif int(S[0])+int(S[1])+int(S[2])-int(S[3])==7:
  print(S[0]+"+"+S[1]+"+"+S[2]+"-"+S[3]+"=7")
elif int(S[0])+int(S[1])-int(S[2])-int(S[3])==7:
  print(S[0]+"+"+S[1]+"-"+S[2]+"-"+S[3]+"=7")
elif int(S[0])-int(S[1])-int(S[2])-int(S[3])==7:
  print(S[0]+"-"+S[1]+"-"+S[2]+"-"+S[3]+"=7")
elif int(S[0])-int(S[1])+int(S[2])-int(S[3])==7:
  print(S[0]+"-"+S[1]+"+"+S[2]+"-"+S[3]+"=7")
elif int(S[0])+int(S[1])-int(S[2])+int(S[3])==7:
  print(S[0]+"+"+S[1]+"-"+S[2]+"+"+S[3]+"=7")
elif int(S[0])-int(S[1])-int(S[2])+int(S[3])==7:
  print(S[0]+"-"+S[1]+"-"+S[2]+"+"+S[3]+"=7")
else:
  print(S[0]+"-"+S[1]+"+"+S[2]+"+"+S[3]+"=7")

Solution (Python):
a,b,c,d=input()
lst_1=[]
lst_2= ["+","-"]
for i in lst_2:
  for j in lst_2:
    for k in lst_2:
      lst_1.append(a+i+b+j+c+k+d)
for l in lst_1:
  if eval(l)==7:
    print(l+"=7")
    break

Solution (Python):
from itertools import product

abcd = input()

pn = ["+","-",""]
for aa,bb,cc in product(pn,repeat=3):
    res = abcd[0]+aa+abcd[1]+bb+abcd[2]+cc+abcd[3]
    if eval(res) == 7:
        print(res+"=7")
        break

Solution (Python):
import sys
S = input()

for i in range(2 ** 3):
    s = S[0]
    for j in range(3):
        if i >> j & 1:
            s += "+"
        else:
            s += "-"
        s += S[j + 1]
    if eval(s) == 7:
        print(s + "=7")
        sys.exit(0)

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

sign_list = ["+","-"]
ans_str = ""
for i in range(2):
  new_sign_list = []
  for sign in sign_list:
    new_sign_list.append(sign+"+")
    new_sign_list.append(sign+"-")
  sign_list = new_sign_list

for signs in sign_list:
  tmp_num = int(ABCD[0])
  for i in range(len(signs)):
    if signs[i] == "+":
      tmp_num += int(ABCD[i+1])
    elif signs[i] == "-":
      tmp_num -= int(ABCD[i+1])

  if tmp_num == 7:
    ans_str = signs
    break

ans = ABCD[0]
for i in range(len(ans_str)):
  ans += ans_str[i]
  ans += ABCD[i+1]

ans += "=7"

print(ans)

Solution (Python):
s = input()

for i in range(2**3):
    b = bin(i)[2:].zfill(3)
    op = ["+" if int(b[j]) else "-" for j in range(3)]
    f = "".join([s[j//2] if j%2==0 else op[(j-1)//2] for j in range(7)])
    if eval(f) == 7:
        print("%s=7" % f)
        quit()

Solution (Python):
s = input()
li = [-1,1]
a = '+'
b = '+'
c = '+'
for i in li:
	for j in li:
		for k in li:
			if int(s[0])+(i*int(s[1]))+(j*int(s[2]))+(k*int(s[3])) == 7:
				if i == -1:
					a = '-'
				if j == -1:
					b = '-'
				if k == -1:
					c = '-'
				print(s[0] + a + s[1] + b + s[2] + c + s[3] + '=7')
				break
		else:
			continue
		break
	else:
		continue
	break

Solution (Python):

K=input()
keta=len(K)


for i in range(1<<(keta-1)):
  ANS=K[0]
  for j in range(keta-1):
    if (i>>j) &1 == 1:
      ANS+="+"
    else:
      ANS+="-"
    ANS+=K[j+1]

  if eval(ANS)==7:
    print(ANS+"=7")
    break

Solution (Python):

abcd = list(input())
ans = 7
n = len(abcd) - 1
pm = ["+", "-"]
for i in range(2**n):
    tmp = abcd[:]
    for j in range(n):
        if (i >> j) & 1 == 1:
            tmp[j] += pm[0]
        else:
            tmp[j] += pm[1]
    v = eval("".join(tmp))
    if v == ans:
        print("".join(tmp)+"={}".format(ans))
        exit()

Solution (Python):


A, B, C, D = map(int, 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):
import sys

sign = '+-'

def main():
    a, b, c, d = list(sys.stdin.readline().rstrip())

    for i in sign:
        for j in sign:
            for k in sign:
                left = a + i + b + j + c + k + d
                if eval(left) == 7:
                    print(left+'=7')
                    sys.exit()

if __name__ == "__main__":
    main()

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    *S,=ST()
    *S,=map(int,S)
    for i in range(2):
        for j in range(2):
            for k in range(2):
                res = S[0]
                ope = [i,j,k]
                for idx,s in enumerate(S[1:]):
                    if ope[idx]:
                        res += s
                    else:
                        res -= s
                if res == 7:
                    *S,=map(str,S)
                    for idx in range(3):
                        if ope[idx]:
                            ope[idx] = "+"
                        else:
                            ope[idx] = "-"
                    ans = S[0]+ope[0]+S[1]+ope[1]+S[2]+ope[2]+S[3]+"=7"
                    print(ans)
                    exit()


if __name__ == '__main__':
    main()

Solution (Python):
def main():

    S = input()
    d = [int(S[i]) for i in range(4)]
    cur = [[d[0], S[0]]]
    for i in range(1, 4):
        temp = []
        for v, s in cur:
            temp.append([v + d[i], s + "+" + S[i]])
            temp.append([v - d[i], s + "-" + S[i]])
        cur = temp

    

    for v, s in cur:
        if v == 7: return s + "=7"
    return ""

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

Solution (Python):
import sys
if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline

N = [int(x) for x in input().rstrip()]
n = len(N)-1

for i in range(2**n):
	op = ['+'] * n
	for j in range(n):
		if (i>>j & 1) == 1:
			op[n-j-1] = '-'
	
	op.append('')
	formula = ""
	for num,o in zip(N, op):
		formula += str(num)+o
	if eval(formula) == 7:
		print("{}=7".format(formula))
		sys.exit()

Solution (Python):
import copy

calc = ""


def dfs(nums, ret, data):
    if len(nums) == 0 and ret == 7:
        global calc
        calc = data
        return True
    if len(nums) == 0:
        return False
    cp = copy.copy(nums)
    v = cp.pop(0)
    if dfs(cp, ret+v, data+"+"):
        return True
    if dfs(cp, ret-v, data+"-"):
        return True


N = list(map(int, list(input())))
n_cp = copy.copy(N)
v = N.pop(0)
dfs(N, v, "")

ans = ""
for i in range(len(n_cp)):
    ans += str(n_cp[i])
    if i != 3:
        ans += str(calc[i])
ans += "=7"
print(ans)

Solution (Python):
B = [0,0,0]
S = str(input())
n = len(S)
for i in range(2**(n-1)):
    A = int(S[0])
    total = A
    B_str = S[0]
    for j in range(n-1):
        if(i>>j)&1:
            B[j] = -int(S[j+1])
            B_str+= "-"+S[j+1]
        else:
            B[j] = int(S[j+1])
            B_str += "+" + S[j + 1]
        total += B[j]

    if total == 7:
        B_str+="=7"
        print(B_str)
        exit()
    total = 0

Solution (Python):
A, B, C, D = list(input())
op = ['+', '-']

for i in range(len(op)):
    for j in range(len(op)):
        for k in range(len(op)):
            op1 = op[i]
            op2 = op[j]
            op3 = op[k]
            state = A + op1 + B + op2 + C + op3 + D
            if eval(state) == 7:
                print(state + '=7')
                exit()

Solution (Python):
"""bit全探索"""

ticket = tuple(map(int, input()))
res = []

for i in range(8, 16):
    s = ticket[0]
    equation = str(s)
    for j in range(1, 4):
        if int(bin(i)[-j]):
            s += ticket[j]
            equation += "+" + str(ticket[j])
        else:
            s -= ticket[j]
            equation += "-" + str(ticket[j])

    if s == 7:
        equation += "=7"
        res.append(equation)

print(res[0])

Solution (Python):
"""bit全探索"""

ticket = tuple(map(int, input()))
res = []

for i in range(8, 16):
    s = ticket[0]
    equation = str(s)
    for j in range(1, 4):
        if int(bin(i)[-j]):
            s += ticket[j]
            equation += "+" + str(ticket[j])
        else:
            s -= ticket[j]
            equation += "-" + str(ticket[j])

    if s == 7:
        equation += "=7"
        res.append(equation)

print(res[0])

Solution (Python):
import itertools

input_ = input()
A, B, C, D = [int(input_[i]) for i in range(4)]

ops_str = ["+", "-"]
find_flag = 0
for ops in itertools.product((0, 1), repeat=3):
    equation = A
    if ops[0] == 0:
        equation += B
    else:
        equation -= B
       
    if ops[1] == 0:
        equation += C
    else:
        equation -= C
        
    if ops[2] == 0:
        equation += D
    else:
        equation -= D
    
    if equation == 7:
        find_flag = 1
        print(str(A)+ops_str[ops[0]], end="")
        print(str(B)+ops_str[ops[1]], end="")
        print(str(C)+ops_str[ops[2]], end="")
        print(str(D), end="=7")
        break

Solution (Python):
J=list(input())
n=len(J)

def dfs(i,f,sum_num):
    if i==n-1:
        if sum_num==7:
            print(f+"=7")
            exit()
    else:
        dfs(i+1,f+"+"+J[i+1],sum_num+int(J[i+1]))
        dfs(i+1,f+"-"+J[i+1],sum_num-int(J[i+1]))
dfs(0,J[0],int(J[0]))

Solution (Python):
n=input()
op_cnt=len(n)-1
for i in range(2**op_cnt):
    s=n[0]
    for j in range(op_cnt):
        if ((i>>j)&1):
            s+="+"
        else:
            s+="-"
        s+=n[j+1]
    if eval(s)==7:
        print(s+"=7")
        exit()

Solution (Python):
n=input()
op_cnt=len(n)-1
for i in range(2**op_cnt):
    s=n[0]
    for j in range(op_cnt):
        if ((i>>j)&1):
            s+="+"
        else:
            s+="-"
        s+=n[j+1]
    if eval(s)==7:
        print(s+"=7")
        exit()

Solution (Python):
l = [int(i) for i in list(input())]
a=l[0]
b=l[1]
c=l[2]
d=l[3]
a_=str(a)
b_=str(b)
c_=str(c)
d_=str(d)
if a+b+c+d == 7:
    print(a_+'+'+b_+'+'+c_+'+'+d_+'=7')
elif a+b+c-d == 7:
    print(a_+'+'+b_+'+'+c_+'-'+d_+'=7')
elif a+b-c+d == 7:
    print(a_+'+'+b_+'-'+c_+'+'+d_+'=7')
elif a+b-c-d == 7:
    print(a_+'+'+b_+'-'+c_+'-'+d_+'=7')
elif a-b+c+d == 7:
    print(a_+'-'+b_+'+'+c_+'+'+d_+'=7')
elif a-b-c+d == 7:
    print(a_+'-'+b_+'-'+c_+'+'+d_+'=7')
elif a-b+c-d == 7:
    print(a_+'-'+b_+'+'+c_+'-'+d_+'=7')
elif a-b-c-d == 7:
    print(a_+'-'+b_+'-'+c_+'-'+d_+'=7')

Solution (Python):
ABCD = input()


a,b,c,d = [int(s) for s in ABCD]

def f():
    for i in [-1,1]:
        for j in [-1,1]:
            for k in [-1,1]:
                if a + i*b + j*c + k*d == 7:
                    return i,j,k
i,j,k = f()

def conv(v):
    if v == 1:
        return "+"
    else:
        return "-"

print("{}{}{}{}{}{}{}=7".format(a,conv(i),b,conv(j),c,conv(k),d))

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    otos=lambda x:"+" if x==1 else "-"
    abcd=int(input())
    abc,d=divmod(abcd,10)
    ab,c=divmod(abc,10)
    a,b=divmod(ab,10)
    for o1 in [1,-1]:
        for o2 in [1, -1]:
            for o3 in [1, -1]:
                s=a+o1*b+o2*c+o3*d
                if s==7:
                    ans=str(a)+otos(o1)+str(b)+otos(o2)+str(c)+otos(o3)+str(d)+"=7"
                    print(ans)
                    exit()

main()

Solution (Python):
s = input()
x = {1:'+', -1:'-'}

for i in x:
    for j in x:
        for k in x:
            ans = [int(s[0]), i*int(s[1]), j*int(s[2]), k*int(s[3])]
            if sum(ans) == 7:
                print('{}{}{}{}{}{}{}=7'.format(s[0], x[i], s[1], x[j], s[2], x[k], s[3]))
                break
        else:
            continue
        break
    else:
        continue
    break

Solution (Python):
n=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")
else:
  print(n[0]+"-"+n[1]+"-"+n[2]+"-"+n[3]+"="+"7")

Solution (Python):
n = str(input())
N = []
Y = []
for m in n:
    N.append(m)

for i in range(1<<3):
    Y = []
    tot = int(N[0])
    for j in range(3):
        if (i>>j)&1 == 1:
            tot += int(N[j+1])
            Y.append('+')
        else:
            tot -= int(N[j+1])
            Y.append('-')
    if tot == 7:
        ans = N[0]+Y[0]+N[1]+Y[1]+N[2]+Y[2]+N[3]+'=7'
        break
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    a,b,c,d=input()
    from itertools import product
    for i,j,k in product(['+','-'],repeat=3):
        s=a+i+b+j+c+k+d
        if(eval(s)==7):
            print(s+'=7')
            return
resolve()

Solution (Python):
n = input()
op_cnt = len(n) - 1
for i in range(2 ** op_cnt):
    op = ["-"] * op_cnt
    for j in range(op_cnt):
        if ((i >> j) & 1) :
            op[op_cnt - j - 1] = "+"
    
    ans = n[0]
    for l in range(op_cnt):
        ans += op[l] + n[l + 1]
    if eval(ans) == 7:
        print(ans + "=7")
        exit(0)

Solution (Python):

S = input()

for i in range(2**3):
    now_sum = int(S[0])
    for j in range(3):
        if (i >> j) & 1:
            now_sum += int(S[j+1])
        else:
            now_sum -= int(S[j+1])
    if now_sum == 7:
        ans = i
        break
fugo = ""
for j in range(3):
    if (ans >> j) & 1:
        fugo += "+"
    else:
        fugo += "-"

print("{}{}{}{}{}{}{}=7".format(S[0], fugo[0], S[1], fugo[1], S[2], fugo[2], S[3]))

Solution (Python):
from sys import stdin
from itertools import product

s = stdin.readline().rstrip()

li = ["+","-"]
for i in range(8):
    lin = list(product(li, repeat=3))

def game(a,b,c):
    if c == "-":
        return(a-b)
    else:
        return(a+b)

for j in lin:
    a = game(int(s[0]),int(s[1]),j[0])
    a = game(a,int(s[2]),j[1])
    a = game(a,int(s[3]),j[2])
    if a == 7:
        print(s[0]+j[0]+s[1]+j[1]+s[2]+j[2]+s[3]+str("=7"))
        exit()

Solution (Python):
n = input()
b_l = []
for i in range(8):
  b = bin(i)[2:]
  le = len(b)
  b_l.append((3 - le)*"0" + b)


    

s_l = [int(n[i]) for i in range(4)]
    
for b in b_l:
  ans = s_l[0]
  f = 0
  b_s_l = ["+" if b[i] == "0" else "-" for i in range(3)]
  for i in range(3):
    if b_s_l[i] == "+":
      ans += s_l[i+1]
    else:
      ans -= s_l[i+1]
  if ans == 7:
    print(str(s_l[0]) + b_s_l[0] + str(s_l[1]) + b_s_l[1] + str(s_l[2]) + 
          b_s_l[2] + str(s_l[3]) + "=7") 
    break

Solution (Python):
a, b, c, d = map(int, input())
op = "+-"
for i in range(2):
  for j in range(2):
    for k in range(2):
      if a + b*(-1)**i + c*(-1)**j + d*(-1)**k == 7:
        print(str(a) + op[i] + str(b) + op[j] + str(c) + op[k] + str(d) + "=7")
        exit()

Solution (Python):
A,B,C,D = [int(i) for i in str(input())]
if A+B+C+D==7:
    print("{0}+{1}+{2}+{3}=7".format(A,B,C,D))
elif A+B+C-D==7:
    print("{0}+{1}+{2}-{3}=7".format(A,B,C,D))
elif A+B-C+D==7:
    print("{0}+{1}-{2}+{3}=7".format(A,B,C,D))
elif A+B-C-D==7:
    print("{0}+{1}-{2}-{3}=7".format(A,B,C,D))
elif A-B+C+D==7:
    print("{0}-{1}+{2}+{3}=7".format(A,B,C,D))
elif A-B+C-D==7:
    print("{0}-{1}+{2}-{3}=7".format(A,B,C,D))
elif A-B-C+D==7:
    print("{0}-{1}-{2}+{3}=7".format(A,B,C,D))
elif A-B-C-D==7:
    print("{0}-{1}-{2}-{3}=7".format(A,B,C,D))

Solution (Python):
S = input()
l = len(S)
for i in range(1 << (l-1)):
    a = int(S[0])
    sum_t = int(S[0])
    st = S[0]
    for j in range(l-1):
        if ((i >> j) & 1):
            st += "+"
            st += S[j+1]
            sum_t += int(S[j+1])
        else:
            st += "-"
            st += S[j+1]
            sum_t -= int(S[j+1])
    if sum_t == 7:
        print("{}=7".format(st))
        break

Solution (Python):
from itertools import product

abcd = input()

ops = ["+", "-"]

for pat in product(ops, repeat=3):
    eq = ""
    for num, op in zip(abcd, pat):
        eq += num + op
    eq += abcd[-1]
    ev = eval(eq)
    if ev == 7:
        break

ans = eq + "=7"
print(ans)

Solution (Python):
num = list(map(int,input()))
l = len(num)
for i in range(2**(l-1)):
    ans = num[0]
    cur = bin(i)[2:]
    cur = '0' * (l-1-len(cur)) + cur
    s = str(num[0])
    for j in range(l-1):
        if cur[j] == '1':
            s += "-"
            s += str(num[j+1])
            ans -= num[j+1]
        else:
            s += "+"
            s += str(num[j+1])
            ans += num[j+1]
    if ans == 7:
        break
s += "=7"
print(s)

Solution (Python):
a,b,c,d=input()
a,b,c,d=int(a),int(b),int(c),int(d)
for op1 in ['+','-']:
    for op2 in ['+', '-']:
        for op3 in ['+', '-']:
            if op1=='+':
                if op2=='+':
                    if op3=='+':
                        num = a+b+c+d
                        if num==7:
                            print(str(a)+op1+str(b)+op2+str(c)+op3+str(d)+'='+'7')
                            exit()
                    else:
                        num = a+b+c-d
                        if num==7:
                            print(str(a)+op1+str(b)+op2+str(c)+op3+str(d)+'='+'7')
                            exit()
                else:
                    if op3=='+':
                        num = a+b-c+d
                        if num==7:
                            print(str(a)+op1+str(b)+op2+str(c)+op3+str(d)+'='+'7')
                            exit()
                    else:
                        num = a+b-c-d
                        if num==7:
                            print(str(a)+op1+str(b)+op2+str(c)+op3+str(d)+'='+'7')
                            exit()
            else:
                if op2=='+':
                    if op3=='+':
                        num = a-b+c+d
                        if num==7:
                            print(str(a)+op1+str(b)+op2+str(c)+op3+str(d)+'='+'7')
                            exit()
                    else:
                        num = a-b+c-d
                        if num==7:
                            print(str(a)+op1+str(b)+op2+str(c)+op3+str(d)+'='+'7')
                            exit()
                else:
                    if op3=='+':
                        num = a-b-c+d
                        if num==7:
                            print(str(a)+op1+str(b)+op2+str(c)+op3+str(d)+'='+'7')
                            exit()
                    else:
                        num = a-b-c-d
                        if num==7:
                            print(str(a)+op1+str(b)+op2+str(c)+op3+str(d)+'='+'7')
                            exit()

Solution (Python):
import operator
s = [int(i) for i in list(input())]

op = []
op.append( operator.add )
op.append( operator.sub )


for i in range(2) :
  for j in range(2) :
    for k in range(2) :

      r = op[i](s[0],s[1])

      r = op[j](r,s[2])

      r = op[k](r,s[3])

      if r == 7 :
        op1 = "+" if i == 0 else "-"
        op2 = "+" if j == 0 else "-"
        op3 = "+" if k == 0 else "-"
        print(str(s[0])+op1+str(s[1])+op2+str(s[2])+op3+str(s[3])+"=7")
        exit()

Solution (Python):
s = input()
v = list("+".join(s))
plus_index = [i for i, x in enumerate(v) if x == '+']
n = len(plus_index)

m = v.copy()
if not eval("".join(v)) == 7:
    for i in range(1 << n):
        m = v.copy()
        for j in range(n):
            if i & (1 << j):
                m[plus_index[j]] = "-"
        if eval("".join(m)) == 7:
            break
print("".join(m) + "=7")

Solution (Python):
n=input()
l=[None]*7
for i in range(4):
    l[i*2]=n[i]
for i in range(2**3):
    for j in range(3):
        if (i>>j)&1:
            l[j*2+1]="+"
        else:
            l[j*2+1]="-"
    a="".join(l)
    if eval(a)==7:
        print(a+"=7")
        exit()