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

Solution (Python):
a, b, c, d = map(int, input())
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):
n = [int(x) for x in input()]


for i in range(8):
    ans = n[0]
    strs = [str(n[0])]
    for j in range(3):
        if (i >> j) & 1:
            ans += n[j + 1]
            strs += '+' + str(n[j + 1])
        else:
            ans -= n[j + 1]
            strs += '-' + str(n[j + 1])
    if ans == 7:
        break
print(''.join(strs) + '=7')

Solution (Python):



import os
import sys







def main():
    S = input()
    num0 = int(S[0])
    num1 = int(S[1])
    num2 = int(S[2])
    num3 = int(S[3])

    for i in range(2):
        for j in range(2):
            for k in range(2):
                ans = 0
                op1 = i == 1
                op2 = j == 1
                op3 = k == 1

                if op1:
                    ans = num0 - num1
                else:
                    ans = num0 + num1

                if op2:
                    ans -= num2
                else:
                    ans += num2

                if op3:
                    ans -= num3
                else:
                    ans += num3

                if ans == 7:
                    print(str(num0) + conv(op1) + str(num1) + conv(op2) + str(num2) + conv(op3) + str(num3) + "=7")
                    exit()

    return


def conv(s):
    if s:
        return "-"
    else:
        return "+"


if __name__ == '__main__':
    main()

Solution (Python):
A, *BCD = map(int, input())
for bit in range(1 << 3):
    tmp = A
    formula = [A]
    for op, n in enumerate(BCD):
        if bit >> op & 1:
            tmp += n
            formula.append('+')
        else:
            tmp -= n
            formula.append('-')
        formula.append(n)
    if tmp == 7:
        formula.append('=7')
        print(*map(str, formula), sep='')
        break

Solution (Python):
l=list(input())
n=2**3
for i in range(n):
    sum=int(l[0])
    buf=l[0]
    for j in range(3):
        if i>>j & 1:
            buf+='+'+l[j+1]
            sum+=int(l[j+1])
        else:
            buf+='-'+l[j+1]
            sum-=int(l[j+1])
    if sum==7:
        print(buf+'=7')
        exit()

Solution (Python):
a, b, c, d = list(input())
for i in range(2 ** 3):
    ls = ['+'] * 3
    for j in range(len(ls)):
        if (i >> j) & 1:
            ls[j] = '-'
    if eval(a + ls[0] + b + ls[1] + c + ls[2] + d) == 7:
        print(a+ls[0]+b+ls[1]+c+ls[2]+d + '=7')
        break

Solution (Python):
S_str = input()
S = [int(i) for i in S_str]
N = len(S)

ans = 0
for bit in range(1 << (N-1)):
  f = S[0]
  g = S_str[0]
  for i in range(N-1):
    if bit & (1 << i):
      f += S[i+1]
      g += "+"+S_str[i+1]
    else:
      f -= S[i+1]
      g += "-"+S_str[i+1]
  if f == 7:
    print(g+"=7")
    exit()

Solution (Python):
import math

abcd = int(input())

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

for i in range(2**3):
    siki = []
    for j in range(3):
        if(i >> j & 1):
            siki.append("+")
        else:
            siki.append("-")
    siki2 = str(a) + siki[0] + str(b) + siki[1] + str(c) + siki[2] + str(d)
    if(eval(siki2) == 7):
        print(siki2+"=7")
        break

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


for ops in itertools.product(['+','-'],repeat=3):
  eq = a+ops[0]+b+ops[1]+c+ops[2]+d
  x = eval(eq)
  
  if x==7:
    break

answer = eq+'=7'
print(answer)

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):
import itertools
import sys

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

op=("+","-")
for op1,op2,op3 in itertools.product(op,repeat=3):
    if eval(a + op1 + b + op2 + c + op3 + d)==7:
        print(a + op1 + b + op2 + c + op3 + d+"=7")
        sys.exit()

Solution (Python):
def solve(operands):
    for i in range(pow(2, len(operands) - 1)):
        tmp_equation = operands[0]
        for j in range(len(operands) - 1):
            tmp_equation += '+' if i >> j & 1 else '-'
            tmp_equation += operands[j + 1]
        if eval(tmp_equation) == 7:
            print(tmp_equation + '=7')
            return

if __name__ == "__main__":
    operands = list(input())
    solve(operands)

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

for i in range(2 ** (l - 1)):
    line = s[0]
    for j in range(l - 1):
        if (i>>j)&1:
            line += '+'
        else:
            line += '-'
        line += s[j + 1]
    if eval(line) == 7:
        print('{}=7'.format(line))
        exit()

Solution (Python):
A, B, C, D = map(int, input())
if A+B+C+D==7:
    a = "+"
    b = "+"
    c = "+"
elif A+B+C-D==7:
    a = "+"
    b = "+"
    c = "-"
elif A+B-C+D==7:
    a = "+"
    b = "-"
    c = "+"
elif A+B-C-D==7:
    a = "+"
    b = "-"
    c = "-"
elif A-B+C+D==7:
    a = "-"
    b = "+"
    c = "+"
elif A-B+C-D==7:
    a = "-"
    b = "+"
    c = "-"
elif A-B-C+D==7:
    a = "-"
    b = "-"
    c = "+"
elif A-B-C-D==7:
    a = "-"
    b = "-"
    c = "-"

print(str(A)+a+str(B)+b+str(C)+c+str(D)+"=7")

Solution (Python):
from itertools import permutations, combinations,combinations_with_replacement,product
s = input()
t = product(["+","-"],repeat=3)

for i in t:
    calc = s[0]+i[0]+s[1]+i[1]+s[2]+i[2]+s[3]
    sum = eval(calc)
    if(sum==7):
        print(calc+"=7")
        break

Solution (Python):






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





if abcd[0] + abcd[1] + abcd[2] + abcd[3] == 7:
    print(str(abcd[0])+"+"+str(abcd[1])+"+"+str(abcd[2])+"+"+str(abcd[3])+"=7")
elif abcd[0] + abcd[1] + abcd[2] - abcd[3] == 7:
    print(str(abcd[0])+"+"+str(abcd[1])+"+"+str(abcd[2])+"-"+str(abcd[3])+"=7")
elif abcd[0] + abcd[1] - abcd[2] + abcd[3] == 7:
    print(str(abcd[0])+"+"+str(abcd[1])+"-"+str(abcd[2])+"+"+str(abcd[3])+"=7")
elif abcd[0] + abcd[1] - abcd[2] - abcd[3] == 7:
    print(str(abcd[0])+"+"+str(abcd[1])+"-"+str(abcd[2])+"-"+str(abcd[3])+"=7")
elif abcd[0] - abcd[1] + abcd[2] + abcd[3] == 7:
    print(str(abcd[0])+"-"+str(abcd[1])+"+"+str(abcd[2])+"+"+str(abcd[3])+"=7")
elif abcd[0] - abcd[1] + abcd[2] - abcd[3] == 7:
    print(str(abcd[0])+"-"+str(abcd[1])+"+"+str(abcd[2])+"-"+str(abcd[3])+"=7")
elif abcd[0] - abcd[1] - abcd[2] + abcd[3] == 7:
    print(str(abcd[0])+"-"+str(abcd[1])+"-"+str(abcd[2])+"+"+str(abcd[3])+"=7")
elif abcd[0] - abcd[1] - abcd[2] - abcd[3] == 7:
    print(str(abcd[0])+"-"+str(abcd[1])+"-"+str(abcd[2])+"-"+str(abcd[3])+"=7")

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

def iter_p_adic(p, n):
    from itertools import product
    tmp = [range(p)] * n
    return product(*tmp)

operator = ['+', '-']

iterator = iter_p_adic(2, 3)
for idxs in iterator:
    fomula = A + operator[idxs[0]] + B + operator[idxs[1]] + C + operator[idxs[2]] + D
    if eval(fomula) == 7:
        print(fomula + '=7')
        sys.exit()

Solution (Python):
abcd = list(input())
abcd = [int(i) for i in abcd]

for i in range(2**3):
  bag=["+"]*3
  
  for j in range(3):
    if ((i>>j) & 1):
      bag[j]="-"
  
  s=abcd[0]
  for ii in range(len(bag)):
    if bag[ii] == "+":
      s+=abcd[ii+1]
    else:
      s-=abcd[ii+1]
    
    
  if s == 7:
    print("{}{}{}{}{}{}{}={}".format(abcd[0],bag[0],abcd[1],bag[1],abcd[2],bag[2],abcd[3],s))
    exit()

Solution (Python):
abcd = list(map(int, list(input())))
res = abcd[0]
op = -1
for i in range(8):
    res = abcd[0]
    op_temp = i
    if op_temp%2:
        res += abcd[1]
    else:
        res -= abcd[1]
    op_temp = op_temp >> 1
    if op_temp%2:
        res += abcd[2]
    else:
        res -= abcd[2]
    op_temp = op_temp >> 1
    if op_temp%2:
        res += abcd[3]
    else:
        res -= abcd[3]
    if res == 7:
        op = i
        break

ans = str(abcd[0])
for j in range(3):
    if (op >> (j))%2:
        ans += '+'
    else:
        ans += '-'
    ans += str(abcd[j+1])
ans += '=7'

print(ans)

Solution (Python):
s = input()
for i in range(8):
    total = int(s[0])
    str = s[0]
    for j in range(1, 4):
        if i >> (j - 1) & 1:
            total += int(s[j])
            str += '+' + s[j]
        else:
            total -= int(s[j])
            str += '-' + s[j]
    if total == 7:
        print(str + '=7')
        exit()

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

Solution (Python):
import math
import sys
from collections import deque
a=input()
for i in range(8):
  c=int(a[0])
  l=[a[0]]
  for j in range(3):
    if i>>j & 1:
      c+=int(a[j+1])
      l+=["+",a[j+1]]
    else:
      c-=int(a[j+1])
      l+=["-",a[j+1]]
  if c==7:
    for i in l:
      print(i,end="")
    print("=7")
    sys.exit()

Solution (Python):
import math
import sys
from collections import deque
a=input()
for i in range(8):
  c=int(a[0])
  l=[a[0]]
  for j in range(3):
    if i>>j & 1:
      c+=int(a[j+1])
      l+=["+",a[j+1]]
    else:
      c-=int(a[j+1])
      l+=["-",a[j+1]]
  if c==7:
    for i in l:
      print(i,end="")
    print("=7")
    sys.exit()

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

if nums[0]+nums[1]+nums[2]+nums[3]==7:
    print('{}+{}+{}+{}=7'.format(nums[0], nums[1], nums[2], nums[3]))

elif nums[0]+nums[1]+nums[2]-nums[3]==7:
    print('{}+{}+{}-{}=7'.format(nums[0], nums[1], nums[2], nums[3]))

elif nums[0]+nums[1]-nums[2]+nums[3]==7:
    print('{}+{}-{}+{}=7'.format(nums[0], nums[1], nums[2], nums[3]))

elif nums[0]+nums[1]-nums[2]-nums[3]==7:
    print('{}+{}-{}-{}=7'.format(nums[0], nums[1], nums[2], nums[3]))

elif nums[0]-nums[1]+nums[2]+nums[3]==7:
    print('{}-{}+{}+{}=7'.format(nums[0], nums[1], nums[2], nums[3]))

elif nums[0]-nums[1]+nums[2]-nums[3]==7:
    print('{}-{}+{}-{}=7'.format(nums[0], nums[1], nums[2], nums[3]))

elif nums[0]-nums[1]-nums[2]+nums[3]==7:
    print('{}-{}-{}+{}=7'.format(nums[0], nums[1], nums[2], nums[3]))

elif nums[0]-nums[1]-nums[2]-nums[3]==7:
    print('{}-{}-{}-{}=7'.format(nums[0], nums[1], nums[2], nums[3]))

Solution (Python):
l=[int(i) for i in input()]

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

  num=l[0]
  for j in range(3):
    if op[j]=='+':
      num+=l[j+1]
    else:
      num-=l[j+1]

  if num==7:
    print(str(l[0])+op[0]+str(l[1])+op[1]+str(l[2])+op[2]+str(l[3])+'=7')
    exit()

Solution (Python):
s = input()

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:
        f += "=7"
        print(f)
        exit()

Solution (Python):
from sys import stdin
l = list(stdin.readline().rstrip())
s = [int(i) for i in l]
def dfs(i, f, sum):
    if i == 3:
        if sum == 7:
            print(f + '=7')
            exit()
    else:
        dfs(i+1, f + '+' + str(s[i+1]), sum + s[i+1])
        dfs(i+1, f + '-' + str(s[i+1]), sum - s[i+1])
dfs(0, str(s[0]), s[0])

Solution (Python):
a,b,c,d=map(int,list(input()))
n=3
ans=''
for i in range(n**2):
  op=[]
  for j in range(n):
    if (i>>j & 1):
      op.append(True)
    else:
      op.append(False)
  tmp=a
  tmp=tmp+b if op[0] else tmp-b
  tmp=tmp+c if op[1] else tmp-c
  tmp=tmp+d if op[2] else tmp-d
  if tmp==7:
    ans=str(a)
    ans+='+' if op[0] else '-'
    ans+=str(b)
    ans+='+' if op[1] else '-'
    ans+=str(c)
    ans+='+' if op[2] else '-'
    ans+=str(d)
    break
print(ans+'=7')

Solution (Python):
s=input()
li=[]
for i in s:
  li.append(int(i))

for i in range(2**3):
  op=[]
  ans=li[0]
  for j in range(3):
    if((i>>j)&1):
      op.append("+")
      ans+=li[j+1]
    else:
      op.append("-")
      ans-=li[j+1]
  if ans==7:
    op.append("=7")
    break
for (x,y) in zip(li,op):
  print(str(x)+y,end="")

Solution (Python):
l=list(input())
n=2**3
for i in range(n):
    sum=int(l[0])
    buf=l[0]
    for j in range(3):
        if i>>j & 1:
            buf+='+'+l[j+1]
            sum+=int(l[j+1])
        else:
            buf+='-'+l[j+1]
            sum-=int(l[j+1])
    if sum==7:
        print(buf+'=7')
        exit()

Solution (Python):
def dfs(i, f, sum):
  if i == 3:
    if sum == 7:
      print(f + "=7")
      exit()
  else:
    dfs(i+1, f+"-"+s[i+1], sum-int(s[i+1]))
    dfs(i+1, f+"+"+s[i+1], sum+int(s[i+1]))
    
s = input()
dfs(0, s[0], int(s[0]))

Solution (Python):
import itertools
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def op(n):
    return '+' if n == 0 else '-'

a, b, c, d = list(readline().decode().rstrip())

for l in list(itertools.product([0, 1], repeat=3)):
    s = str(a + op(l[0]) + b + op(l[1]) + c + op(l[2]) + d)
    if eval(s) == 7:
        print(s+'=7')
        exit()

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("{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[0])
B = int(s[1])
C = int(s[2])
D = int(s[3])

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



nums = list(input().rstrip())
nums = list(map(int,nums))

def proc(nums):
    op_h = []
    n = nums.pop(0)
    fl,op_h = find_operator(nums.copy(), 7-n, op_h)
    print(n,end="")
    for i,num in enumerate(nums):
        if op_h[i] == 1:
            print("+",end="")
        else:
            print("-",end="")
        print(num,end="")
    print("=7")

def find_operator(nums, to_be, operation_history):
    ope = [-1,1]

    n = nums.pop(0)
    if len(nums) == 0:
        for op in ope:
            if to_be - op*n == 0:
                operation_history.append(op)
                return True, operation_history
        return False, operation_history    
    
    for op in ope:
        op_h = operation_history.copy()
        op_h.append(op)
        fl, h = find_operator(nums.copy(), to_be-op*n, op_h)
        if fl == True:
            return True,h
    return False,h
        
proc(nums)

Solution (Python):
S = input()
for i in range(8):
    s = S[0]
    for j in range(3):
        s += list("+-")[i>>j&1]+S[j+1]
    if eval(s) == 7:
        ans = s
print(ans+'=7')

Solution (Python):
S = list(input())
for a in range(8):
  p = [""]*4
  ans = ""
  for b in range(3):
    if(a>>b & 1):
      p[b] = "+"
    else:
      p[b] = "-"
      
  for c in range(4):
    ans += str(S[c]) + str(p[c])
    
  if eval(ans) == 7:
    print(ans + "=7")
    break

Solution (Python):
def resolve():
    s = input()

    def dfs(i, f):
        if i == 3:
            return f.split(",")
        return dfs(i+1, f + "+" + s[i+1]) + dfs(i+1, f + "-" + s[i+1])
    for i in dfs(0, s[0]):
        if eval(i) == 7:
            print(i + "=7")
            exit()
resolve()

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

    for i in range(8):
        op1 = "+" if i>>0 & 1 else "-"
        op2 = "+" if i>>1 & 1 else "-"
        op3 = "+" if i>>2 & 1 else "-"
        test = a + op1 + b + op2 + c + op3 + d
        if eval(test) == 7:
            print(test + "=7")
            exit()
resolve()

Solution (Python):
def solve(A,n):
    x=2**n
    for i in range(x):
        count=A[0]
        for j in range(n):
            if (i>>j) & 1:
                count+=A[j+1]
            else:
                count-=A[j+1]
        if count==7:
            return i

n=3
A=list(map(int,input()))
i=solve(A,n)
ans=str(A[0])
for j in range(n):
    if (i>>j) & 1:
        ans+="+"+str(A[j+1])
    else:
        ans+="-"+str(A[j+1])
ans+="=7"
print(ans)

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

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

if l[0] == 7:
  print('{}+{}+{}+{}=7'.format(a, b, c, d))
elif l[1] == 7:
  print('{}+{}+{}-{}=7'.format(a, b, c, d))
elif l[2] == 7:
  print('{}+{}-{}+{}=7'.format(a, b, c, d))
elif l[3] == 7:
  print('{}+{}-{}-{}=7'.format(a, b, c, d))
elif l[4] == 7:
  print('{}-{}+{}+{}=7'.format(a, b, c, d))
elif l[5] == 7:
  print('{}-{}+{}-{}=7'.format(a, b, c, d))
elif l[6] == 7:
  print('{}-{}-{}+{}=7'.format(a, b, c, d))
elif l[7] == 7:
  print('{}-{}-{}-{}=7'.format(a, b, c, d))

Solution (Python):
a = list(map(int,input()))
h = []

for i in range(1,2**3):
    total = a[0]
    h.clear()
    for j in range(3):
        if ((i >> j) & 1):
            total += a[j+1]
            h.append('+')
        else:
            total -= a[j+1]
            h.append('-')
    if total == 7:
        break
for i in range(3):
    print(str(a[i])+h[i],end="")
print(str(a[3])+"=7")

Solution (Python):
s = str(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",sep = "")
elif (int(s[0])+int(s[1])+int(s[2])-int(s[3]) == 7):
    print(s[0],"+",s[1],"+",s[2],"-",s[3],"=7",sep = "")
elif (int(s[0])+int(s[1])-int(s[2])+int(s[3]) == 7):
    print(s[0],"+",s[1],"-",s[2],"+",s[3],"=7",sep = "")
elif (int(s[0])+int(s[1])-int(s[2])-int(s[3]) == 7):
    print(s[0],"+",s[1],"-",s[2],"-",s[3],"=7",sep = "")
elif (int(s[0])-int(s[1])+int(s[2])+int(s[3]) == 7):
    print(s[0],"-",s[1],"+",s[2],"+",s[3],"=7",sep = "")
elif (int(s[0])-int(s[1])+int(s[2])-int(s[3]) == 7):
    print(s[0],"-",s[1],"+",s[2],"-",s[3],"=7",sep = "")
elif (int(s[0])-int(s[1])-int(s[2])+int(s[3]) == 7):
    print(s[0],"-",s[1],"-",s[2],"+",s[3],"=7",sep = "")
else:
    print(s[0],"-",s[1],"-",s[2],"-",s[3],"=7",sep = "")

Solution (Python):
a = list(map(int, input()))
b = [a[1], -a[1]]
c = [a[2], -a[2]]
d = [a[3], -a[3]]
flag = 0 
for i in b:
    if(i>=0):
        b_ = '+'
    else: b_ = '-'
    for j in c:
        if(j>=0):
            c_ = '+'
        else: c_ = '-'
        for k in d:
            if(k>=0):
                d_ = '+'
            else: d_ = '-'            
            ans = a[0] + i + j + k
            if ans==7:
                print('{}{}{}{}{}{}{}=7'.format(a[0], b_, a[1], c_, a[2], d_, a[3]))
                flag = 1
                break
        if(flag==1): break
    if(flag==1): break

Solution (Python):
import sys
a,b,c,d=input()
op=["-","+"]

for i in op:
  for j in op:
    for k in op:
      o=a+i+b+j+c+k+d
      ans=eval(o)
      if ans==7:
        print(o+"=7")
        sys.exit()

Solution (Python):
a = str(input())
apple = []
orange = []
for i in a:
    apple.append(int(i))
x = apple[0]
y = apple[1]
z = apple[2]
w = apple[3]
if apple[0] + apple[1] + apple[2] + apple[3] == 7:
    print("{o}+{p}+{q}+{r}=7".format(o=x, p=y, q=z, r=w))
elif apple[0] - apple[1] + apple[2] + apple[3] == 7:
    print("{o}-{p}+{q}+{r}=7".format(o=x, p=y, q=z, r=w))
elif apple[0] - apple[1] - apple[2] + apple[3] == 7:
    print("{o}-{p}-{q}+{r}=7".format(o=x, p=y, q=z, r=w))
elif apple[0] - apple[1] - apple[2] - apple[3] == 7:
    print("{o}-{p}-{q}-{r}=7".format(o=x, p=y, q=z, r=w))
elif apple[0] + apple[1] - apple[2] + apple[3] == 7:
    print("{o}+{p}-{q}+{r}=7".format(o=x, p=y, q=z, r=w))
elif apple[0] + apple[1] - apple[2] - apple[3] == 7:
    print("{o}+{p}-{q}-{r}=7".format(o=x, p=y, q=z, r=w))
elif apple[0] + apple[1] + apple[2] - apple[3] == 7:
    print("{o}+{p}+{q}-{r}=7".format(o=x, p=y, q=z, r=w))
elif apple[0] - apple[1] + apple[2] - apple[3] == 7:
    print("{o}-{p}+{q}-{r}=7".format(o=x, p=y, q=z, r=w))
else:
    pass

Solution (Python):
x = input()
a = int(x[0])
b = int(x[1])
c = int(x[2])
d = int(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):
abcd=input()
for i in range(1 << 3):
    l=[]
    for j in range(3):
        l.append(abcd[j])
        if (i>>j)&1==1:
            l.append('+')
        else:
            l.append('-')
    l.append(abcd[3])
    if eval("".join(l))==7:
        ans="".join(l)
        break
print(ans+"=7")

Solution (Python):


s=list(input())
a=s[0]
b=s[1]
c=s[2]
e=s[3]

for i in range(8):
    d=0
    x=[a,b,c,e]
    for j in range(3):
        if (i >> j)&1:
            x.insert(-j-1-d,'+')
            d+=1
        else:
            x.insert(-1-j-d,'-')
            d+=1
    q="".join(x)
    f=int(a)
    g=int(b)
    h=int(c)
    k=int(e)
    if q[1]=="-":
        g=-g
    if q[3]=="-":
        h=-h
    if q[5]=="-":
        k=-k
    if f+g+h+k==7:
        ans=q+"=7"
        print(ans)
        exit()

Solution (Python):
import sys

s=list(input())
a=s[0]
b=s[1]
c=s[2]
e=s[3]

for i in range(8):
    d=0
    x=[a,b,c,e]
    for j in range(3):
        if (i >> j)&1:
            x.insert(-j-1-d,'+')
            d+=1
        else:
            x.insert(-1-j-d,'-')
            d+=1
    q="".join(x)
    f=int(a)
    g=int(b)
    h=int(c)
    k=int(e)
    if q[1]=="-":
        g=-g
    if q[3]=="-":
        h=-h
    if q[5]=="-":
        k=-k
    if f+g+h+k==7:
        ans=q+"=7"
        print(ans)
        sys.exit()

Solution (Python):
import sys
import math
from collections import deque
from itertools import product

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    S = input()
    for op1, op2, op3 in product("+-", repeat=3):
        q = S[0]+op1+S[1]+op2+S[2]+op3+S[3]
        if eval(q) == 7:
            print(q + "=7")
            exit()


if __name__ == "__main__":
    main()

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

for bit in range(3 ** 2):
    array = ['-','-','-']
    for i in range(3):
        if bit >> i & 1:
            array[i] = '+'
    tmp = int(n[0])
    ans = n[0]
    for i in range(len(array)):
        if array[i] == '+':
            tmp += int(n[i+1])
            ans+='+'+n[i+1]
        else:
            tmp -= int(n[i+1])
            ans+='-'+n[i+1]
    if tmp == 7:
        print(ans+'=7')
        exit(0)

Solution (Python):

A,B,C,D = input()
for i in range(2):
    op1 = 1 if i == 0 else -1
    for j in range(2):
        op2 = 1 if j == 0 else -1
        for k in range(2):
            op3 = 1 if k == 0 else -1
            if(int(A) + int(B) * op1 + int(C) * op2 + int(D) * op3 == 7):
                op1t = '+' if op1 == 1 else '-'
                op2t = '+' if op2 == 1 else '-'
                op3t = '+' if op3 == 1 else '-'
                print(str(A) + op1t + str(B) + op2t + str(C) + op3t + str(D) + '=7')
                break
        else:
            continue
        break
    else:
        continue
    break

Solution (Python):

import sys
import itertools
input = sys.stdin.readline
mylist = ["+", "-"]

num = input().rstrip()
num = [int(num[i]) for i in range(len(num))]
first = num[0]
num = num[1:]

for i in itertools.product(mylist, repeat = len(num)):
    temp = first
    for j, k in zip(i, num):
        if j == "+":
            temp += k
        else:
            temp -= k
    if temp == 7:
        print(first, end = '')
        for j, k in zip(i, num):
            print(j+str(k), end = '')
        print("=7")
        break

Solution (Python):
s=input()

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

Solution (Python):
num=input()
a=int(num[0])
b=int(num[1])
c=int(num[2])
d=int(num[3])
yn=0
for i in range(2):
    for j in range(2):
        for k in range(2):
            num2=a
            if i==0:
                num2+=b
            else:
                num2-=b
            if j==0:
                num2+=c
            else:
                num2-=c
            if k==0:
                num2+=d
            else:
                num2-=d
            if num2==7:
                yn=1
                break
        if yn==1:
            break
    if yn==1:
        break
ans=""
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)

Solution (Python):
def main():
    s = input()
    n = len(s) - 1
    f = s[0]
    for i in range(2**n):
        for j in range(n):
            if (i >> j) & 1:
                f += '+'
            else:
                f += '-'
            f += s[j+1]
        
        if eval(f) == 7:
            print(f + '=7')
            break
        f = s[0]

if __name__ == '__main__':
    main()

Solution (Python):
x = input()
l = []
for i in range(4):
  l.append(int(x[i]))
  
ans_l = []  
for i in range(8):
  x = l[0]+l[1]*(-1)**(i//4)+l[2]*(-1)**((i//2)%2)+l[3]*(-1)**(i%2)
  if x==7:
    ans_l.append(i)
    
if min(ans_l)//4==0:
  op1 = '+'
else:
  op1 = '-'
if (min(ans_l)//2)%2==0:
  op2 = '+'
else:
  op2 = '-'
if min(ans_l)%2==0:
  op3 = '+'
else:
  op3 = '-'
  
print(str(l[0])+op1+str(l[1])+op2+str(l[2])+op3+str(l[3])+'=7')

Solution (Python):

ticket = input()

ans = 0
if int(ticket[0]) + int(ticket[1]) + int(ticket[2]) + int(ticket[3]) == 7:
    print(ticket[0] + '+' + ticket[1] + '+' + ticket[2] + '+' + ticket[3] + '=7')
elif int(ticket[0]) + int(ticket[1]) + int(ticket[2]) - int(ticket[3]) == 7:
    print(ticket[0] + '+' + ticket[1] + '+' + ticket[2] + '-' + ticket[3] + '=7')
elif int(ticket[0]) + int(ticket[1]) - int(ticket[2]) + int(ticket[3]) == 7:
    print(ticket[0] + '+' + ticket[1] + '-' + ticket[2] + '+' + ticket[3] + '=7')
elif int(ticket[0]) + int(ticket[1]) - int(ticket[2]) - int(ticket[3]) == 7:
    print(ticket[0] + '+' + ticket[1] + '-' + ticket[2] + '-' + ticket[3] + '=7')
elif int(ticket[0]) - int(ticket[1]) + int(ticket[2]) + int(ticket[3]) == 7:
    print(ticket[0] + '-' + ticket[1] + '+' + ticket[2] + '+' + ticket[3] + '=7')
elif int(ticket[0]) - int(ticket[1]) + int(ticket[2]) - int(ticket[3]) == 7:
    print(ticket[0] + '-' + ticket[1] + '+' + ticket[2] + '-' + ticket[3] + '=7')
elif int(ticket[0]) - int(ticket[1]) - int(ticket[2]) + int(ticket[3]) == 7:
    print(ticket[0] + '-' + ticket[1] + '-' + ticket[2] + '+' + ticket[3] + '=7')
elif int(ticket[0]) - int(ticket[1]) - int(ticket[2]) - int(ticket[3]) == 7:
    print(ticket[0] + '-' + ticket[1] + '-' + ticket[2] + '-' + ticket[3] + '=7')

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

for bit in range(2 ** 3):
    N = ABCD[0]
    for i in range(3):
        if bit & (1 << i):
            N += '+'
        else:
            N += '-'
        N += ABCD[i + 1]
    if eval(N) == 7:
        print(N + '=7')
        sys.exit()

Solution (Python):
import sys
ls = list(str(input()))
a =ls[0]
b =ls[1]
c =ls[2]
d =ls[3]
for i in range(2):
    for j in range(2):
        for k in range(2):
            if i == 1:
                s1 = "-"
            if j == 1:
                s2 = "-"
            if k == 1:
                s3 = "-"
            if i == 0:
                s1 = "+"
            if j == 0:
                s2 = "+"
            if k == 0:
                s3 = "+"
            e = eval(a+s1+b+s2+c+s3+d)
            if e == 7:
                print(a+s1+b+s2+c+s3+d + "=7")
                sys.exit()

Solution (Python):
import sys
a,b,c,d=input()
k=["+","-"]
lst=[]
for i in k:
    for j in k:
        for l in k:
            o=a+i+b+j+c+l+d
            if eval(o)==7:
                print(o+"=7")
                sys.exit()