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):
arr = str(input())
arr = list(arr)
arr = list(map(int,arr))
a = arr[0]
b = arr[1]
c = arr[2]
d = arr[3]
a1 = str(arr[0])
b1 = str(arr[1])
c1 = str(arr[2])
d1 = str(arr[3])

if a+b+c+d == 7:
    print(a1+'+'+b1+'+'+c1+'+'+d1+'=7')
elif a+b+c-d == 7:
    print(a1+'+'+b1+'+'+c1+'-'+d1+'=7')
elif a+b-c+d == 7:
    print(a1+'+'+b1+'-'+c1+'+'+d1+'=7')
elif a-b+c+d == 7:
    print(a1+'-'+b1+'+'+c1+'+'+d1+'=7')
elif a+b-c-d == 7:
    print(a1+'+'+b1+'-'+c1+'-'+d1+'=7')
elif a-b+c-d == 7:
    print(a1+'-'+b1+'+'+c1+'-'+d1+'=7')
elif a-b-c+d == 7:
    print(a1+'-'+b1+'-'+c1+'+'+d1+'=7')
elif a-b-c-d == 7:
    print(a1+'-'+b1+'-'+c1+'-'+d1+'=7')

Solution (Python):
def calc(x, y, op):
    if op == "+":
        res = x + y
    elif op == "-":
        res = x - y
    return res


s = input()

a, b, c, d = map(int, s)
operand = ["+", "-"]
ans = ""

for op1 in operand:
    res1 = calc(a, b, op1)
    for op2 in operand:
        res2 = calc(res1, c, op2)
        for op3 in operand:
            res3 = calc(res2, d, op3)
            if res3 == 7:
                ans = "{}{}{}{}{}{}{}=7".format(a, op1, b, op2, c, op3, d)
                break
        else:
            continue
        break
    else:
        continue
    break

print(ans)

Solution (Python):
s = input()
N = 1<<(len(s)-1)

for one in range(N):
    c = int(s[0])
    tmp = s[0]
    for i in range(0,len(s)-1):
        if (one>>i & 1)==1:
            c+=int(s[i+1])
            tmp+='+'
        else:
            c-=int(s[i+1])
            tmp+='-'
        tmp+=s[i+1]
    tmp+='=7'
    if c==7:
        print(tmp)
        break

Solution (Python):
s=input()
for x in '+-':
    for y in '+-':
        for z in '+-':
            sum=s[0]+x+s[1]+y+s[2]+z+s[3]
            if eval(sum)==7:
                print(sum+'=7')
                exit()

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


def calc(a, b, c, d):
    ops = ['+', '-']
    for i in ops:
        for j in ops:
            for k in ops:
                ans = a
                ans += b if i == '+' else -b
                ans += c if j == '+' else -c
                ans += d if k == '+' else -d
                if ans == 7:
                    return i, j, k


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

Solution (Python):
a, b, c, d = [x for x in input()]
for x in "+-":
    for y in "+-":
        for z in "+-":
            s = a + x + b + y + c + z + d
            if eval(s) == 7:
                print(s + "=7")
                exit()

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

A, B, C, D = map(int, list(input()[:-1]))

n = 3
ops = []
for bit in range(0, 1<<n):
    op = ["-"]*n
    for j in range(n):
        if bit>>j & 1:
            op[j] = "+"
    ops.append(op)

for op in ops:
    a, b, c, d = A, B, C, D
    if op[0] == "-":
        b = -B
    if op[1] == "-":
        c = -C
    if op[2] == "-":
        d = -D
    if a + b + c + d == 7:
        ans = op
        break
ans = str(a)
for num in (b, c, d):
    if num >= 0:
        ans += "+"
        ans += str(num)
    else:
        ans += str(num)
ans += "=7"
print(ans)

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


def dfs(i, s_str, sum):
    if i == n - 1:
        if sum == 7:
            print(s_str + '=7')
            exit()

    else:
        dfs(i+1, s_str + '+' + s[i+1], sum + int(s[i+1]))
        dfs(i+1, s_str + '-' + s[i+1], sum - int(s[i+1]))


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

Solution (Python):
s = input()

op = [['+', '+', '+'],
      ['+', '+', '-'], ['+', '-', '+'], ['-', '+', '+'],
      ['+', '-', '-'], ['-', '+', '-'], ['-', '-', '+'],
      ['-', '-', '-']]

for p in op:
   ans = int(s[0])
   for i in range(3):
      if (p[i] == '+'):
         ans += int(s[i+1])
      else:
         ans -= int(s[i+1])
   if (ans == 7):
      print(s[0]+p[0]+s[1]+p[1]+s[2]+p[2]+s[3]+'=7')
      exit()

Solution (Python):

N = input()
L = len(N) - 1  


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

    formula = ""
    for p_n, p_o in zip(N, op + [""]):
        formula += (p_n + p_o)
    if eval(formula) == 7:
        print(formula + "=7")
        break

Solution (Python):
S = input()

import sys


for op1 in ["+","-"]:
    for op2 in ["+","-"]:
        for op3 in ["+","-"]:

            sm=int(S[0])

            if op1=="+":
                sm+=int(S[1])
            else:
                sm-=int(S[1])

            if op2=="+":
                sm+=int(S[2])
            else:
                sm-=int(S[2])

            if op3=="+":
                sm+=int(S[3])
            else:
                sm-=int(S[3])

            if sm == 7:
                result=S[0]+op1+S[1]+op2+S[2]+op3+S[3]+"=7"
                print(result)
                sys.exit()

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

pm = ["+", "-"]

for op_1 in pm:
    for op_2 in pm:
        for op_3 in pm:
            formula = s[0]+op_1+s[1]+op_2+s[2]+op_3+s[3]
            if eval(formula) == 7:
                print(formula+"=7")
                exit()

Solution (Python):
import sys
ABCD = input() 
base_liste = [] 
for i in range(2**3):
    sous_liste = []
    for j in range(3):
        if ((i>>j) & 1):
            sous_liste.append('+')
        else: 
            sous_liste.append('-')
    base_liste.append(sous_liste)
for sous_liste in base_liste:
    sum = 0
    Candidate = ABCD[0] 
    for i in range(3):
        if sous_liste[i] == '+':
            sum += int(ABCD[i+1])
            Candidate += '+' + ABCD[i+1]
        else:
            sum -= int(ABCD[i+1])
            Candidate += '-' + ABCD[i+1]
    if sum == 7-int(ABCD[0]):
        print(Candidate + '=7')
        sys.exit(0)

Solution (Python):
s = [int(x) for x in input()]
insert_operator_number = len(s) - 1

for iter_op in range(1 << insert_operator_number):
  result_sum = s[0]
  result_string = ""
  for i in range(insert_operator_number):
    if (iter_op & (1 << i)):
      result_sum += s[i+1]
      result_string += "{}+".format(s[i])
    else:
      result_sum -= s[i+1]
      result_string += "{}-".format(s[i])
    
  if result_sum == 7:
    break

print("{}{}=7".format(result_string,s[-1]))

Solution (Python):
A = input()
B=["".join(sum(list(map(list, zip(A,"".join("+-"[int(s)] for s in "{:03b}".format(i))+"="))),[]))[:-1] for i in range(8)]
for b in B:
    if eval(b)==7:
        print(b+"=7")
        break

Solution (Python):
import sys
b=list(input())
a=list(map(int,(list(b))))

def dfs(m,sum,op):
    if m ==3:
        if sum == 7:
            print(op+"=7")
            sys.exit()
        return()

    dfs(m+1,sum+a[m+1],op+"+"+str(a[m+1]))
    dfs(m+1,sum-a[m+1],op+"-"+str(a[m+1]))

dfs(0,a[0],str(a[0])) 
print("ng")

Solution (Python):

s=input()

def dfs(i,f,f_cal):
    n = len(s) - 1

    if i==n:
        if f_cal==7:
            print(f+'=7')
            exit()
    else:
        dfs(i+1,f+'+'+s[i+1],f_cal+int(s[i+1]))
        dfs(i+1,f+'-'+s[i+1],f_cal-int(s[i+1]))

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

Solution (Python):

l = [int(x) for x in list(input())]

ans=0
n1=n2=n3=0

for i in range(2):
    if ans==7:
        break
    for j in range(2):
        if ans==7:
            break
        for k in range(2):
            if ans==7:
                break
            ans=l[0]+l[1]*(-1)**i+l[2]*(-1)**j+l[3]*(-1)**k
            n1=i
            n2=j
            n3=k


print(l[0],end="")
print(str(n1).replace("0", '+').replace("1", '-'),end="")
print(l[1],end="")
print(str(n2).replace("0", '+').replace("1", '-'),end="")
print(l[2],end="")
print(str(n3).replace("0", '+').replace("1", '-'),end="")
print(l[3],end="")

print("="+str(ans))

Solution (Python):
a,b,c,d = list(input())
s = ["+", "-"]

for op1 in s:
    for op2 in s:
        for op3 in s:
            ans = a + op1 + b + op2 + c + op3 + d
            if eval(ans) == 7:
                print(ans + "=7")
                exit()

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

for i in range(2 ** n):
    op = ["-"] * n
    for j in range(n):
        if (i >> j) & 1:
            op[j] = "+"
    f = ""
    for fs, fn in zip(s, op + [""]):
        f += fs + fn
    if eval(f) == 7:
        print(f + "=7")
        exit()

Solution (Python):


def dfs(i,f,f_sum):
    if i==3:
        if f_sum==7:
            print(f+'=7')
            exit()
    else:
        dfs(i+1,f+'+'+s[i+1],f_sum+int(s[i+1]))
        dfs(i+1,f+'-'+s[i+1],f_sum-int(s[i+1]))

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

Solution (Python):
import operator
import sys
A, B, C, D = [int(x) for x in input()]
ops = ((operator.add, "+"), (operator.sub, "-"),)
for op1, op1s in ops:
    for op2, op2s in ops:
        for op3, op3s in ops:
            s = op3(op2(op1(A, B), C), D)
            if s == 7:
                result = "".join(map(str, (A, op1s, B, op2s, C, op3s, D, "=7")))
                print(result)
                sys.exit()

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

for i in range(2):
    for j in range(2):
        for k in range(2):
            if i == 0:
                op1 = "+"
            else:
                op1 = "-"
            if j == 0:
                op2 = "+"
            else:
                op2 = "-"
            if k == 0:
                op3 = "+"
            else:
                op3 = "-"
            if eval(A+op1+B+op2+C+op3+D) == 7:
                print((A+op1+B+op2+C+op3+D)+"="+"7")
                exit()

Solution (Python):
import sys
import copy
 
def main():
    ABCD = list(map(str, input()))
    b_digit = len(ABCD)-1
 
    for i in range(2 ** b_digit):
        signs = ["+"] * b_digit
        for j in range(b_digit):
            if ((i >> j ) & 1):
                signs[b_digit - 1 - j] = "-"
 
        ABCD_tmp = copy.deepcopy(ABCD)
        for k in range(len(signs)):
            ABCD_tmp.insert(1+k*2,signs[k])
        if(eval("".join(ABCD_tmp))==7):
            print("{}=7".format("".join(ABCD_tmp)))
            sys.exit()
 
main()

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

n = len(s) - 1

for i in range(1 << n):
    f = ""
    f += s[0]

    for j in range(n):

        if 1 & (i >> j):

            f += "+"
            f += s[j + 1]
        else :

            f += "-"
            f += s[j + 1]

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

Solution (Python):
abcd = input()
for i in range(2**3):
    res = int(abcd[0])
    formula = abcd[0]
    for j in range(3):
        if (i >> j) & 1:
            res += int(abcd[j+1])
            formula += '+'
        else:
            res -= int(abcd[j+1])
            formula += '-'
        formula += abcd[j+1]
    if res == 7:
        print(formula + '=7')
        exit(0)

Solution (Python):
ABCD = input()
A = int(ABCD[0])
B = int(ABCD[1])
C = int(ABCD[2])
D = int(ABCD[3])
Result = False
op = ["+", "-"]

def func(sign, num1, num2):
    if sign == "+":
        result = num1 + num2
    else:
        result = num1 - num2
    return result

for i in range(2):
    op1 = op[i]
    r1 = func(op1, A, B)
    for j in range(2):
        op2 = op[j]
        r2 = func(op2, r1, C)
        for k in range(2):
            op3 = op[k]
            r3 = func(op3, r2, D)
            if r3 == 7:
                Result = True
            if Result:
                break
        if Result:
            break
    if Result:
        break

print("{}{}{}{}{}{}{}=7".format(A, op1, B, op2, C, op3, D))

Solution (Python):
t = input()
a = int(t)
d = ['+','-']
for i in range(2**3):
	S = a//1000
	ans = t[0]
	for j in range(3):
		S += int(d[(i>>j&1)]+t[j+1])
		ans+= d[(i>>j&1)]+t[j+1]
	
	if S == 7:
		print(ans+'=7')
		exit()

Solution (Python):


s = list(input())
n = len(s) - 1

for bit in range(2 ** n):
    tmp = s[:]
    total = 0
    for i in range(n):
        if (bit & (1 << i)):
            tmp[i] += '+'
        else:
            tmp[i] += '-'
    total = eval(''.join(tmp))
    if total == 7:
      print(''.join(tmp) + '=7')
      break

Solution (Python):
s = input()
nums = []
for n in s:
  nums.append(int(n))
a = nums[0]
b = nums[1]
c = nums[2]
d = nums[3]
while True:
  if a + b + c + d == 7:
    od1 = "+"
    od2 = "+"
    od3 = "+"
    break
  if a + b + c - d == 7:
    od1 = "+"
    od2 = "+"
    od3 = "-"
    break
  if a + b - c + d == 7:
    od1 = "+"
    od2 = "-"
    od3 = "+"
    break
  if a + b - c - d == 7:
    od1 = "+"
    od2 = "-"
    od3 = "-"
    break
  if a - b + c + d == 7:
    od1 = "-"
    od2 = "+"
    od3 = "+"
    break
  if a - b - c + d == 7:
    od1 = "-"
    od2 = "-"
    od3 = "+"
    break
  if a - b - c - d == 7:
    od1 = "-"
    od2 = "-"
    od3 = "-"
    break
  if a - b + c - d == 7:
    od1 = "-"
    od2 = "+"
    od3 = "-"
    break
print("{}{}{}{}{}{}{}=7".format(a, od1, b, od2, c, od3, d))

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

ans = 0

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

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

  if eval(f) == 7:
    ans = f + '=7'

print(ans)

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

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

def main():
    s = input()

    dfs(0, s[0], int(s[0]), s)
    
if __name__ == '__main__':
    main()

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

for a in range(2):
  for b in range(2):
    for c in range(2):

      if a == 0:
        op1 = '+'
      else:
        op1 = '-'

      if b == 0:
        op2 = '+'
      else:
        op2 = '-'

      if c == 0:
        op3 = '+'
      else:
        op3 = '-'

      if eval(str(A) + op1 + str(B) + op2 + str(C) + op3 + str(D)) == 7:
        g = str(A) + op1 + str(B) + op2 + str(C) + op3 + str(D) + '=7'

print(g)

Solution (Python):
s = input()
n = []
op = []

def calc(lst,n,op):
  if lst:
    op.append('+')
    p = calc(lst[:-1],n+lst[-1],op)
    if p:
      return p
    op.pop()
    op.append('-')
    n = calc(lst[:-1],n-lst[-1],op)
    if n:
      return n
    op.pop()
  else:
    if n == 7:
      return op
    else:
      return None
  
    

for i in range(3):
  n.append(int(s[3-i]))
op = calc(n,int(s[0]),op)
print('{}{}{}{}{}{}{}=7'.format(s[0],op[0],s[1],op[1],s[2],op[2],s[3]))

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

if a+b+c+d == 7:
    print('+'.join(map(str,[a,b,c,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 itertools import product
s = input()
ans = "0"

for op in product(["-", "+"], repeat=len(s)-1):
    
    op = list(op)
    op.append("")
    
    if eval(''.join( a + b for a, b in zip(s, op))) ==7:
        print(''.join( a + b for a, b in zip(s, op))+"=7")
        exit()

Solution (Python):

a,b,c,d = list(input())

for op1 in ["+","-"]:
    for op2 in ["+","-"]:
        for op3 in ["+","-"]:
            s = a+op1+b+op2+c+op3+d
            r = eval(s)
            if r==7:
                print(s+"=7")
                exit()

Solution (Python):
import itertools
S = input()
for x in itertools.product(["+", "-"],repeat=3):
    res = ""
    for s, p in zip(S, x):
        res += s + p
    res += S[-1]
    if eval(res) == 7:
        ans = res + "=7"
        print(ans)
        exit(0)

Solution (Python):
s=input()

for bit in range(2**3):
    ans=int(s[0])
    sign=[]
    for g in range(3):
        if (bit>>g)&1:
            sign.append("+")
        else:
            sign.append("-")
    for l in range(3):
        if sign[l]=="+":
            ans+=int(s[l+1])
        else:
            ans-=int(s[l+1])
    if ans==7:
        break

str_ans=s[0]
for i in range(3):
    str_ans+=sign[i]
    str_ans+=s[i+1]
str_ans+="=7"
print(str_ans)

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

Solution (Python):
import itertools
S = input()
combs = list(itertools.product(["+", "-"], repeat = 3))
res = ""
for comb in combs:
    temp = S[0] + comb[0] + S[1] + comb[1] + S[2] + comb[2] + S[3]
    if eval(temp) == 7:
        res = temp + "=7"
print(res)

Solution (Python):
ABCD = input()
A,B,C,D = int(ABCD[0]), int(ABCD[1]), int(ABCD[2]), int(ABCD[3])
ans = ''
if A+B+C+D == 7:
  ans = str(A)+'+'+str(B)+'+'+str(C)+'+'+str(D)
elif A+B+C-D == 7:
  ans = str(A)+'+'+str(B)+'+'+str(C)+'-'+str(D)
elif A+B-C+D == 7:
  ans = str(A)+'+'+str(B)+'-'+str(C)+'+'+str(D)
elif A+B-C-D == 7:
  ans = str(A)+'+'+str(B)+'-'+str(C)+'-'+str(D)
elif A-B+C+D == 7:
  ans = str(A)+'-'+str(B)+'+'+str(C)+'+'+str(D)
elif A-B+C-D == 7:
  ans = str(A)+'-'+str(B)+'+'+str(C)+'-'+str(D)
elif A-B-C+D == 7:
  ans = str(A)+'-'+str(B)+'-'+str(C)+'+'+str(D)
elif A-B-C-D == 7:
  ans = str(A)+'-'+str(B)+'-'+str(C)+'-'+str(D)
print(ans+'=7')

Solution (Python):
A,B,C,D = [int(i) for i in input()]
op = ["+","-"]
for i in op:
    if i == "+":
        AopB = A + B
    else:
        AopB = A - B
    for j in op:
        if j == "+":
            AopBopC = AopB + C
        else:
            AopBopC = AopB - C
        for k in op:
            if k == "+":
                AopBopCopD = AopBopC + D
            else:
                AopBopCopD = AopBopC -D
            if AopBopCopD == 7:
                print(str(A)+i+str(B)+j+str(C)+k+str(D)+"=7")
                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):
Z = []
for s in input():
  Z.append(int(s))

def dfs(index, value, ops):
  if index == 4:
    if value == 7:
      print("{}{}{}{}{}{}{}=7".format(Z[0],ops[0],Z[1],ops[1],Z[2],ops[2],Z[3]))
      
      exit()
    return
  dfs(index + 1, value + Z[index], ops + ["+"])
  dfs(index + 1, value - Z[index], ops + ["-"])

dfs(1, Z[0], [])

Solution (Python):
buz = [int(x) for x in list(input())]
bit = 8
for i in range(bit):
    buf = buz[0]
    ans = str(buz[0])
    for j in range(3):
        if i & 1 << j:
            buf += buz[1+j]
            ans += "+" + str(buz[1+j])
        else:
            buf -= buz[1+j]
            ans += "-" + str(buz[1 + j])
    if buf == 7:
        print(ans + "=7")
        break

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

ans = 0
S = input()
n = len(S)
for bit in range(1<<(n-1)):
    val = int(S[0])
    ans_string = S[0]
    for i in range(n-1):
        if (bit>>i)&1:
            val += int(S[i+1])
            ans_string += "+"+S[i+1]
        else:
            val -= int(S[i+1])
            ans_string += "-"+S[i+1]
    if val == 7:
        ans_string += "=7"
        break

print(ans_string)

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

ans = 0
S = input()
n = len(S)
def dfs(i, ans_string, tot):
    if i == n-1:
        if tot == 7: 
            print(ans_string+"=7") 
            return True 
        else: return False
    return dfs(i+1, ans_string +"+" + S[i+1], tot + int(S[i+1])) \
     or dfs(i+1, ans_string + "-" + S[i+1], tot-int(S[i+1]))

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

Solution (Python):
a, b, c, d = list(map(int, list(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()
A = [int(S[i]) for i in range(4)]
for i in range(8):
  p = A[0]
  s = []
  for j in range(3):
    if i % 2 == 0:
      p += A[j+1]
      s.append('+')
    else:
      p -= A[j+1]
      s.append('-')
    i //= 2
  if p == 7:
    print('{}{}{}{}{}{}{}=7'.format(A[0], s[0], A[1], s[1], A[2], s[2], A[3]))
    break

Solution (Python):
a=input()
for i in range(1<<3):
    num=int(a[0])
    ans=a[0]
    for j in range(3):
        if 1& i>>j:
            num+=int(a[j+1])
            ans+="+"
            ans+=a[j+1]
        else:
            num-=int(a[j+1])
            ans+="-"
            ans+=a[j+1]
    
    if num==7:
        ans+="=7"
        print(ans)
        exit()

Solution (Python):
nums = list(map(int, list(input())))
ans = 0
ansStrGrobal = ''
def culc(ope, count, summation, ansStr):
    global ansStrGrobal
    tmp = nums[count]
    if ope == 1:
        summation += tmp
        ansStr += '+'
    else:
        summation -= tmp
        ansStr += '-'

    count += 1
    if count == 4:
        if summation == 7:
            ansStrGrobal = ansStr
        return
    
    culc(1, count, summation, ansStr)
    culc(0, count, summation, ansStr)
    
    
culc(1, 0, 0, '')

print(str(nums[0]) + ansStrGrobal[1] + str(nums[1]) + ansStrGrobal[2] + str(nums[2]) + ansStrGrobal[3] + str(nums[3]) + '=7')

Solution (Python):
import itertools

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

opsgen = itertools.product((1, -1), repeat=3)

for op1, op2, op3 in opsgen:
    res = A + op1 * B + op2 * C + op3 * D
    if res == 7:
        print(
            '{A}{op1}{B}{op2}{C}{op3}{D}=7'.format(
                A=A, B=B, C=C, D=D,
                op1= '+' if op1 == 1 else '-',
                op2= '+' if op2 == 1 else '-',
                op3= '+' if op3 == 1 else '-',
            )
        )
        break

Solution (Python):
import sys


N=str(input())
a=list(N)


    
for i in range(2**4):
    Sum=0
    tmp=''
    for j in range(4):
        if (i>>j) & 1:
            Sum+=int(a[j])
            tmp+='+'+str(a[j])
        else:
            Sum-=int(a[j])
            tmp+='-'+str(a[j])
    if Sum==7:
        
        tmp=tmp[1:]
        print(tmp+'=7')
        sys.exit()
print('No')

Solution (Python):
s=input()
for i in range(8):
    sum=int(s[0])
    ans=s[0]
    for j in range(3):
        if (i>>j)&1:
            sum+=int(s[j+1])
            ans+="+"+s[j+1]
        else:
            sum-=int(s[j+1])
            ans+="-"+s[j+1]
    if sum==7:
        ans+="=7"
        print(ans)
        exit()

Solution (Python):
s=input()
for i in range(8):
    ans=s[0]
    cnt=int(s[0])
    for j in range(3):
        if (i>>j) & 1:
            ans+="+"+s[j+1]
            cnt+=int(s[j+1])
        else:
            ans+="-"+s[j+1]
            cnt-=int(s[j+1])
    if cnt==7:
        print(ans+"=7")
        exit()

Solution (Python):


a=list(input())
for i in range(4):
    a[i]=int(a[i])
cnt=[]

for i in range(2**3):
    su=a[0]
    cnt=[]
    for j in range(3):
        if (i>>j)&1==1:
            su+=a[j+1]
            cnt.append('+')
        elif (i>>j)&1==0:
            su-=a[j+1]
            cnt.append('-')
        
    if su==7:
        print(str(a[0])+cnt[0]+str(a[1])+cnt[1]+str(a[2])+cnt[2]+str(a[3])+'='+'7')
        exit()

Solution (Python):
n=input()
for i in range(2**4):
    res=0
    b=[]
    
    for j in range(4):
        if (i>>j)&1:
            b.append("+")
            res+=int(n[j])
        else:
            b.append("-")
            res-=int(n[j])
    if res==7:
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        print(n[0]+b[1]+n[1]+b[2]+n[2]+b[3]+n[3]+"=7")
        
        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))
else:
    print("{}-{}-{}-{}=7".format(a,b,c,d))

Solution (Python):
a,b,c,d=[int(i) for i in input()]
l=7-a
f=[-1,-1,-1]
for i in range(2):
    for j in range(2):
        for k in range(2):
            l_sub=l
            if i==0:
                l_sub-=(b)
            else:
                l_sub-=(-b)
            if j==0:
                l_sub-=(c)
            else:
                l_sub-=(-c)
            if k==0:
                l_sub-=(d)
            else:
                l_sub-=(-d)
            if l_sub==0:
                f=[i,j,k]
        if f!=[-1,-1,-1]:
            break
    if f!=[-1,-1,-1]:
        break
s=str(a)
if f[0]==0:
    s+="+"
else:
    s+="-"
s+=str(b)
if f[1]==0:
    s+="+"
else:
    s+="-"
s+=str(c)
if f[2]==0:
    s+="+"
else:
    s+="-"
s+=str(d)
s+="=7"

print(s)

Solution (Python):
import itertools as its
A,B,C,D = input()
for p in its.product(['-','+'], repeat=3):
    ans = eval(A+p[0]+B+p[1]+C+p[2]+D)
    if ans == 7:
        print(A+p[0]+B+p[1]+C+p[2]+D+'=7')
        break

Solution (Python):
l = input()

for i in range(1<<3):
    s = ""
    for k in range(3):
        if (i & (1<<k)):
            s += '+'
        else:
            s += '-'
    e = ""
    for i in range (3):
        e += l[i]
        e += s[i]

    e += l[3]

    if ( eval(e) == 7 ):
        e += "=7"
        print(e)
        break;

Solution (Python):
import itertools
num = str(input())
sign = ("+", "-")
for s1, s2, s3 in itertools.product(sign, repeat=3):
    result = num[0] + s1 + num[1] + s2 + num[2] + s3 + num[3]
    if eval(result) == 7:
        print(result+"=7")
        break

Solution (Python):
import sys
input = sys.stdin.readline
S = str(input())
N = 3
goal = 7
for i in range(2**N):
    result = int(S[0])
    for j in range(N):
        if i & 2**(N-j-1):
            result += int(S[j+1])
        else:
            result -= int(S[j+1])
    if result != goal:
        continue
    print(S[0], end="")
    for j in range(N):
        if i & 2**(N-j-1):
            print('+', end="")
        else:
            print('-', end="")
        print(S[j+1], end="")
    print("=7")
    break

Solution (Python):
S = str(input())
N = 3
goal = 7
for i in range(2**N):
    result = int(S[0])
    for j in range(N):
        if i & 2**(N-j-1):
            result += int(S[j+1])
        else:
            result -= int(S[j+1])
    if result != goal:
        continue
    print(S[0], end="")
    for j in range(N):
        if i & 2**(N-j-1):
            print('+', end="")
        else:
            print('-', end="")
        print(S[j+1], end="")
    print("=7")
    break

Solution (Python):
s = [int(i) for i in input()]
for i in range(8):
    a = s[0]
    lst = []
    for j in range(3):
        if i>>j & 1 == 1:
            a += s[j+1]
            lst.append("+")
        else:
            a -= s[j+1]
            lst.append("-")
    if a == 7:
        lst.append("=7")
        break

for i,j in zip(s,lst):
    print(i,j,sep="",end="")
else:
    print("")

Solution (Python):
S = input()
len_S = 4 

for i in range(1 << (len_S-1)):
  tmp = int(S[0])
  ans = S[0]
  for j in range(len_S-1):    
    if (i>>j)&1:
      tmp += int(S[j+1])
      ans += "+"
    else:
      tmp -= int(S[j+1])
      ans += "-"
    ans += S[j+1]
  if tmp == 7:
    ans += "=7"
    print(ans)
    exit()

Solution (Python):
S = input()
len_S = 4 

for i in range(1 << (len_S-1)):
  ops_list = ["+"]*(len_S-1)
  for j in range(len_S-1):
    
    if (i>>j)&1:
      ops_list[j] = "-"
  eq = ""
  for j in range(len_S-1):
    eq = eq + S[j] + ops_list[j]
    
  eq = eq + S[len_S-1]
  if eval(eq) == 7:
    print(eq + "=7")
    exit()

Solution (Python):
from itertools import product

A,B,C,D = list(input())
eq = ""
for ops in product(["+", "-"], repeat=3):
  eq = A+ops[0]+B+ops[1]+C+ops[2]+D
  x = eval(eq)
  if x == 7:
    break
print(eq + "=7")

Solution (Python):
a=list(input())
import copy
for i in range(2**3):
    b=[]
    c=copy.deepcopy(a)
    for j in range(3):
        if (i>>j)&1:
            b.append("+")
        else:
            b.append('-')
    c.insert(1,b[0])
    c.insert(3,b[1])
    c.insert(5,b[2])
    c=''.join(c)
    if eval(c)==7:
        print(c+"=7")
        exit()

Solution (Python):
s = input()
a=int(s[0])
b=int(s[1])
c=int(s[2])
d=int(s[3]) 
operations = ["+", "-"]
for op1 in operations:
    if op1 == "+":
        ab = a+b
    else:
        ab = a-b
    for op2 in operations:
        if op2 == "+":
            abc = ab+c
        else:
            abc = ab-c
        for op3 in operations:
            if op3 == "+":
                ans = abc+d
            else:
                ans = abc-d
            if ans == 7:
                print('{}{}{}{}{}{}{}=7'.format(a,op1,b,op2,c,op3,d))
                exit()

Solution (Python):
s=input()
n = 2**(len(s)-1)
ans=""

for i in range(n):
    t = ""
    a = str(bin(i))[2:].zfill(len(s)-1)
    for j in range(len(a)):
        if a[j] == "1":
            t += s[j] + "+"
        else:
            t += s[j] + "-"
    t += s[-1]
    if eval(t)==7:
        ans = t + "=7"
        break
print(ans)

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