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

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

for i in range(8):
    bit = bin(i)[2:].zfill(3)
    string = s[0]
    flag = int(s[0])

    for j,k in enumerate(bit):
        if k == '0':
            string += '+' + s[j+1]
            flag += int(s[j+1])
        else:
            string += '-' + s[j+1]
            flag -= int(s[j+1])

    if flag == 7:
        print(string + '=7')
        sys.exit()

Solution (Python):
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)


def resolve():
    ABCD = [x for x in sys.stdin.readline().split()][0]
    A, B, C, D = [int(x) for x in ABCD]
    logger.debug('{}'.format([A, B, C, D]))

    op_list = ["+", "-"]
    for op1 in op_list:
        if op1 == "+":
            s1 = A + B
        else:
            s1 = A - B
        for op2 in op_list:
            if op2 == "+":
                s2 = s1 + C
            else:
                s2 = s1 - C
            for op3 in op_list:
                if op3 == "+":
                    s3 = s2 + D
                else:
                    s3 = s2 - D

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


if __name__ == "__main__":
    resolve()





import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """1222"""
        output = """1+2+2+2=7"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """0290"""
        output = """0-2+9+0=7"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """3242"""
        output = """3+2+4-2=7"""
        self.assertIO(input, output)

Solution (Python):
n = []
s = input()
def culc(cur, op_c,ans):
    if op_c == 3:
        if cur == 7:
            print(ans + "=7")
            exit()
    else:
        culc(cur+int(s[op_c+1]), op_c+1, ans + "+" + s[op_c+1])
        culc(cur-int(s[op_c+1]), op_c+1, ans + "-" + s[op_c+1])
culc(int(s[0]), 0, s[0])

Solution (Python):


A_B_C_D = input()
plus = '+'
minus = '-'
right_side = '=7'
ans = ''

def dfs(i, formula, sum):
    
    if i == 7:
        if sum == 7:
            
            global ans 
            ans = formula + right_side        
        return
    
    
    dfs(i+2, formula[:i] + plus + formula[i:], sum + int(formula[i]))

    
    dfs(i+2, formula[:i] + minus + formula[i:], sum - int(formula[i]))

dfs(1, A_B_C_D, int(A_B_C_D[0]))

print(ans)

Solution (Python):
a,b,c,d = list(str(input()))
op = ('+', '-')
for i in range(2):
  for j in range(2):
    for k in range(2):
      result = eval(a + op[i] + b + op[j] + c + op[k] + d)
      if result == 7:
        print(a + op[i] + b + op[j] + c + op[k] + d + '=7')
        exit()

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

s = input()
n = len(s)

def exec(i,num,f):
    if i == n-1:
        pass
        if num == 7:
            print(f+"=7")
            exit(0)
        else:
            return

    exec(i+1,int(num)+int(s[i+1]),f+"+"+s[i+1])
    exec(i+1,int(num)-int(s[i+1]),f+"-"+s[i+1])


exec(0,s[0],s[0])

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

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

Solution (Python):
n=input()

calc=[]
calc.append(int(n[0])+int(n[1])+int(n[2])+int(n[3]))
calc.append(int(n[0])+int(n[1])+int(n[2])-int(n[3]))
calc.append(int(n[0])+int(n[1])-int(n[2])+int(n[3]))
calc.append(int(n[0])+int(n[1])-int(n[2])-int(n[3]))
calc.append(int(n[0])-int(n[1])+int(n[2])+int(n[3]))
calc.append(int(n[0])-int(n[1])+int(n[2])-int(n[3]))
calc.append(int(n[0])-int(n[1])-int(n[2])+int(n[3]))
calc.append(int(n[0])-int(n[1])-int(n[2])-int(n[3]))

if 7 in calc:
    idx=calc.index(7)
if idx==0:
    print(n[0]+"+"+n[1]+"+"+n[2]+"+"+n[3]+"=7")
elif idx==1:
    print(n[0]+"+"+n[1]+"+"+n[2]+"-"+n[3]+"=7")
elif idx==2:
    print(n[0]+"+"+n[1]+"-"+n[2]+"+"+n[3]+"=7")
elif idx==3:
    print(n[0]+"+"+n[1]+"-"+n[2]+"-"+n[3]+"=7")
elif idx==4:
    print(n[0]+"-"+n[1]+"+"+n[2]+"+"+n[3]+"=7")
elif idx==5:
    print(n[0]+"-"+n[1]+"+"+n[2]+"-"+n[3]+"=7")
elif idx==6:
    print(n[0]+"-"+n[1]+"-"+n[2]+"+"+n[3]+"=7")
else:
    print(n[0]+"-"+n[1]+"-"+n[2]+"-"+n[3]+"=7")

Solution (Python):
a,b,c,d = list(input())
sign = '+-'
for i in range(2):
  for j in range(2):
    for k in range(2):
      if eval( a+ sign[i] + b +sign[j]+ c + sign[k]+ d) ==7:
        print(str(a+sign[i]+b+sign[j]+c+sign[k]+d)+ '=7')
        exit()

Solution (Python):
import itertools


s = [int(i) for i in input()]
for bs in itertools.product((0, 1), repeat=3):
    res = s[0]
    expr = [str(s[0])]
    for b, n in zip(bs, s[1:]):
        if b:
            res += n
            expr.append("+")
            expr.append(str(n))
        else:
            res -= n
            expr.append("-")
            expr.append(str(n))
    if res == 7:
        print("".join(expr) + "=7")
        break

Solution (Python):

n = [int(x) for x in 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 - 1 -  j] = "+"
 

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

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


for i in ["+","-"]:
    if i !="/" or i =="/" and int(b)!=0:
        for j in ["+","-"]:
            if j=="/" and int(c)==0:
                break
            for k in ["+","-"]:
                if k=="/" and int(d)==0:
                    break
                if eval(a+i+b+j+c+k+d)==7:
                    print(a+i+b+j+c+k+d+e)
                    exit()

Solution (Python):
def dfs(i, s, ex):
    if i == 4:
        if s == 7:
            return ex + "=7"
        else:
            return ""

    if i == 0:
        return dfs(i + 1, int(S[i]), S[i])

    return dfs(i + 1, s + int(S[i]), ex + "+" + S[i]) or dfs(
        i + 1, s - int(S[i]), ex + "-" + S[i]
    )


S = input()
print(dfs(0, 0, ""))

Solution (Python):
L=list(map(int,input()))
for i in range(2):
    for j in range(2):
        for k in range(2):
            if L[0]+(-1)**i*L[1]+(-1)**j*L[2]+(-1)**k*L[3]==7:
                if i==0:
                    o1="+"
                else:
                    o1="-"
                if j==0:
                    o2="+"
                else:
                    o2="-"
                if k==0:
                    o3="+"
                else:
                    o3="-"
                print(str(L[0])+o1+str(L[1])+o2+str(L[2])+o3+str(L[3])+"=7")
                exit()

Solution (Python):
s=input()

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

Solution (Python):
N = str(input())
L = [int(x) for x in list(N)]

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

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

for bit in range(8):
    f = [A, '', B, '', C, '', D]
    for i, j in enumerate([1, 3, 5]):
        if bit & (2**i): f[j] = '+'
        else: f[j] = '-'
    f = ''.join(f)
    if eval(f)==7:
        print('%s=7' % f)
        quit()

Solution (Python):
a , b, c, d=list(input())
sign = '+-'
for i in range(2):
    for j in range(2):
        for k in range(2):
            if eval(a+sign[i]+b+sign[j]+c+sign[k]+d) == 7:
                print(str(a+sign[i]+b+sign[j]+c+sign[k]+d)+'=7')
                exit()

Solution (Python):
import re
a = input()
n = len(a)
ans = []
for i in range(1<<(n-1)):
    f = a[0]
    g = int(a[0])
    for j in range(n-1):
        if (i>>j)&1:
            f += '+'
            g += int(a[j+1])
        else:
            f += '-'
            g -= int(a[j+1])
        f += a[j+1]
    if g == 7:
        print(f+'=7')
        break

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

op_num = len(n) - 1

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

    op.append('')
    formula = ''
    for x, o in zip(n, op):
        formula += str(x) + o
    if eval(formula) == 7:
        print(formula + '=7')
        break

Solution (Python):
S=input()
N=8

for i in range(1<<3):
   output=[S[0]]
   count=int(S[0])
   for j in range(3):
      if((i>>j)&1)==1:
         output.append("+")
         output.append(S[j+1])
         count+=int(S[j+1])

      else:
         output.append("-")
         output.append(S[j+1])
         count-=int(S[j+1])
   
   if count==7:
      T="".join(output)
      T+="=7"
      print(T)
      break

Solution (Python):
s = input()

for b in range(1<<(len(s)-1)):
    f = s[0]
    for i in range(len(s)-1):
        if b & (1<<i):
            f += '+' + s[i+1]
        else:
            f += '-' + s[i+1]
    if eval(f) == 7:
        print(f+'=7')
        exit(0)

Solution (Python):
def dfs(i, f, sum):
    if i == n-1:
        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()
n = len(s)

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

Solution (Python):
s = input()
nbits = 1 << len(s) - 1
for bit in range(nbits):
    for i in range(len(s)):
        if i == 0:
            anss = s[0]
            ans = int(s[0])
            continue

        if bit & 1 << i - 1:
            anss += "+" + s[i]
            ans += int(s[i])
        else:
            anss += "-" + s[i]
            ans -= int(s[i])
    if ans == 7:
        print(anss + "=7")
        exit(0)

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 - 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):
import sys
S = input()
A = S[0]
B = S[1]
C = S[2]
D = S[3]


for i in range(2**(len(S)-1)):
    op_list = ['+']*(len(S)-1)
    for j in range(len(S)-1):

        if (i>>j)&1:
            op_list[j]='-'
    s = ""
    for j in range(len(S)-1):
        s = s + S[j] + op_list[j]

    s = s + S[len(S)-1]

    if 7==eval(s):
        print(s,"=7", sep="")
        sys.exit()

Solution (Python):
a = str(input())
a = list(a)
for i in range(len(a)):
    a[i] = int(a[i])



for i in range(8):
    ans = a[0]
    for j in range(1,4):
        if (i >> (j-1)) & 1:
            ans += a[j]
        else:
            ans -= a[j]
    
    if ans == 7:
        print(a[0], end="")
        for j in range(1,4):
            if (i >> (j-1)) & 1:
                print("+", end="")
            else:
                print("-",end="")
            print(a[j], end="")
        print("=7")
        exit(0)

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


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

Solution (Python):





s = list(map(int,list(input())))
li = [1,-1]

for i in range(1<<3):
    ans = s[0]
    for j in range(1,4):
        if i>>(j-1)&1:
            ans += s[j]
        else:
            ans -= s[j]
    
    if ans == 7:
        print(s[0],end="")
        for j in range(1,4):
            if i>>(j-1)&1:
                print("+",end="")
                print(s[j],end="")
            else:
                print("-",end="")
                print(s[j],end="")
        print("=7")
        break

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


import operator, itertools, sys

ops = {
    '+': operator.add,
    '-': operator.sub
}
ans = ops['-'](ops['+'](ops['-'](A, B), C), D)

for keys in itertools.product(ops, repeat=3):
    total = ops[keys[2]](ops[keys[1]](ops[keys[0]](A, B), C), D)
    if total == 7:
        ans = '{a}{op1}{b}{op2}{c}{op3}{d}=7'.format(a=A, op1=keys[0], b=B, op2=keys[1], c=C, op3=keys[2], d=D)
        print(ans)
        sys.exit(0)

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:
    print("{}=7".format(f))
    exit()

Solution (Python):
s = input()

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

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

    if ans == 7:
        print(f + '=7')
        break

Solution (Python):



def printFormula(x):
    print(nums[0], end = "")
    for i in range(len(nums) - 1):
        if x & (1 << i):
            print("+", end = "")
        else:
            print("-", end = "")
        print(nums[i + 1], end = "")
    print("=7")
        


str1 = input()
nums = []
for i in range(len(str1)):
    nums.append(int(str1[i]))
    
ope = []
for i in range(1 << (len(str1) - 1)):
    sum_num = nums[0]
    
    for j in range(len(str1) - 1):
        if i & (1 << j):
            sum_num += nums[1 + j]
        else:
            sum_num -= nums[1 + j]
        
    if sum_num == 7:
        printFormula(i)
        exit()

Solution (Python):





def printStr(i):
    for j in range(3):
        print(nums[j], end = "")
        print(lst[-1][i][j], end = "")
    print(nums[3], end = "")
    print("=7")

str=list(input())
nums = []
for i in range(4):
    nums.append(int(str[i]))

lst = []
tmp = []


for i in range(3):
    if len(lst) == 0:
        tmp = ['+', '-']
        lst.append(tmp)
    else:
        tmp = []
        for j in range(len(lst[-1])):
            tmp.append(lst[-1][j] + "+")
            tmp.append(lst[-1][j] + "-")
        lst.append(tmp)

for i in range(len(lst[-1])):
    result = nums[0]
    for j in range(len(lst[-1][i])):
        
        if lst[-1][i][j] == "+":
            result += nums[j + 1]
        else:
            result -= nums[j + 1]
            
        if j == 2 and result == 7:
            printStr(i)
            exit()

Solution (Python):
import sys
from itertools import product

ops = '+-'

s = sys.stdin.readline().rstrip()

def main():
    formula = [None] * 7
    formula[::2] = list(s)
    
    for op in product(ops, repeat=3):
        f = formula.copy()
        f[1::2] = list(op)
        f = ''.join(f)
        if eval(f) == 7:
            return f + '=7'

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

Solution (Python):
S = input()
n = 3

A,B,C,D = list(S)
import itertools
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
ans = eq+"=7"
print(ans)

Solution (Python):
S = input()
n = 3

for i in range(1<<n):
    tmp = int(S[0])
    ans = S[0]
    for j in range(n):
        if i & (1<<j):
            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):
x = int(input())

a = x//1000
b = (x%1000)//100
c = ((x%1000)%100)//10
d = ((x%1000)%100)%10
     
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):
N=input()
n=len(N)-1

for i in range(1<<n):
    ans=N[0]
    for j in range(n):
        if ((i>>j)&1) == 1:
            ans +='+'
            ans +=N[j+1]
        elif ((i>>j)&1) ==0:
            ans+='-'
            ans+=N[j+1]

    if eval(ans)==7:
        temp = ans

temp += '=7'
print(temp)

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

for bit in range(2**3):
  tmp = []
  for i in range(3):
    if bit & (1 << i):
      tmp.append(i)

  ops = ['-', '-', '-']
  for p in tmp:
    ops[p] = '+'
  eq = a + ops[0] + b + ops[1] + c + ops[2] + d
  if eval(eq) == 7:
    break
print(eq + '=7')

Solution (Python):
s = input()

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

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

    if ans == 7:
        print(f + '=7')
        break

Solution (Python):
s = str(input())
n = len(s)
lists = []
ans_list = []
Sum = 0
for i in range(2**n):
    lists = []
    ans_list = []
    Sum = int(s[0])
    for j in range(n-1):
        if ((i >> j) & 1):
            lists.append(1)
        else:
            lists.append(0)
    for k in range(n-1):
        ans_list.append(s[k])
        if lists[k] == 1:
            ans_list.append("+")
        else:
            ans_list.append("-")
    ans_list.append(s[-1])
    for l in range(1,len(ans_list) -1 ):
        if ans_list[l] == "+":
            Sum += int(ans_list[l+1])
        elif ans_list[l] == "-":
            Sum -= int(ans_list[l+1])
    if Sum == 7:
        ans_list.append("=7")
        ans = "".join(ans_list)
        print(ans)
        exit()

Solution (Python):
import sys

E = list(input())

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

sum = 0
for i in range(2**3):

    op_list = ['-', '-', '-']
    sum1 = 0
    for j in range(len(E)):
        if (i>>j) & 1:
            op_list[j]  = '+'
    sum = eval(E[0]+op_list[0]+E[1]+op_list[1]+E[2]+op_list[2]+E[3])

    if sum==7:
        print(A,op_list[0],B,op_list[1],C,op_list[2],D,"=7", sep="")
        sys.exit()

Solution (Python):
n = input()
op = [-1, 1]
op_c = ['-', '+']
for i in range(8):
  if int(n[0]) + op[i&1]*int(n[1]) + op[i>>1&1]*int(n[2]) + op[i>>2&1]*int(n[3]) == 7:
    print('{}{}{}{}{}{}{}=7'.format(n[0], op_c[i&1], n[1], op_c[i>>1&1], n[2], op_c[i>>2&1], n[3]))
    exit()

Solution (Python):
l=input()
a=int(l[0])
b=int(l[1])
c=int(l[2])
d=int(l[3])
for i in range(2**3):
  s=0
  lis=[]
  for j in range(3):
    if (i>>(2-j)&1)!=1:
      if j==0:
        s+=a-b
        x='-'
      elif j==1:
        s-=c
        y='-'
      else:
        s-=d
        z='-'
    else:
      if j==0:
        s+=a+b
        x='+'
      elif j==1:
        s+=c
        y='+'
      else:
        s+=d
        z='+'
  if s==7:
    print(str(a)+x+str(b)+y+str(c)+z+str(d)+'=7')
    exit()

Solution (Python):
from itertools import zip_longest
import sys
input = sys.stdin.readline


def main():
    ABCD = list(input().rstrip())
    n = len(ABCD) - 1

    for i in range(2**n):
        op = ['+' if ((i >> j) & 1) else '-' for j in range(n)]
        cal = ''.join([i + j for i, j in zip_longest(ABCD, op, fillvalue='')])
        if eval(cal) == 7:
            print(cal + '=7')
            break


if __name__ == "__main__":
    main()

Solution (Python):


ABCD = input()



N = len(ABCD) -1

for i in range( 2 ** N ):
    
    op = ["-"] * N
    for j in range(N):
        if (i >> j) & 1:
            op[N - 1 - j] = "+"
    
    
    siki = ''
    for k in range(N):
        siki += ABCD[k]
        siki += op[k]
    
    siki += ABCD[3]
    if eval(siki) == 7:
        print(siki+"=7")
        break

Solution (Python):
def dfs(i, f, Sum):
    if i == n-1:
        if Sum == 7:
            print(f+"=7")
            exit()
    else:
        dfs(i+1, f+"+"+a[i+1], Sum + int(a[i+1]))
        dfs(i+1, f+"-"+a[i+1], Sum - int(a[i+1]))
        

a = input()
n = len(a)

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

Solution (Python):
from itertools import zip_longest
ABCD = list(input())
n = len(ABCD) - 1
for i in range(2 ** n):  
  op = ["+" if ((i >> j) & 1) else "-" for j in range(n)]
  cal = "".join([i + j for i, j in zip_longest(ABCD, op, fillvalue="")])
  if eval(cal) == 7:
    print(cal + "=7")
    exit()

Solution (Python):
t=input()
a=int(t[0])
b=int(t[1])
c=int(t[2])
d=int(t[3])
if a+b+c+d==7:
  print(t[0]+"+"+t[1]+"+"+t[2]+"+"+t[3]+"=7")
elif a+b+c-d==7:
  print(t[0]+"+"+t[1]+"+"+t[2]+"-"+t[3]+"=7")
elif a+b-c+d==7:
  print(t[0]+"+"+t[1]+"-"+t[2]+"+"+t[3]+"=7")
elif a+b-c-d==7:
  print(t[0]+"+"+t[1]+"-"+t[2]+"-"+t[3]+"=7")
elif a-b+c+d==7:
  print(t[0]+"-"+t[1]+"+"+t[2]+"+"+t[3]+"=7")
elif a-b-c+d==7:
  print(t[0]+"-"+t[1]+"-"+t[2]+"+"+t[3]+"=7")
elif a-b-c-d==7:
  print(t[0]+"-"+t[1]+"-"+t[2]+"-"+t[3]+"=7")
elif a-b+c-d==7:
  print(t[0]+"-"+t[1]+"+"+t[2]+"-"+t[3]+"=7")

Solution (Python):
import sys
from itertools import accumulate

def resolve():
        input = sys.stdin.readline
        S=list(input().rstrip())
        n=3
        for i in range(2**n):
            sum=int(S[0])
            for j in range(n):
                if((i>>j)&1):
                    sum+=int(S[j+1])
                else:
                    sum-=int(S[j+1])
            if(sum==7):
                ans=(S[0]+str((i>>0)&1).replace("1","+").replace("0","-")+S[1]
                +str((i>>1)&1).replace("1","+").replace("0","-")+S[2]+str((i>>2)&1).replace("1","+").replace("0","-")+S[3]
                +"="+str(sum))
                print(ans)
                return
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """1222"""
        output = """1+2+2+2=7"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """0290"""
        output = """0-2+9+0=7"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """3242"""
        output = """3+2+4-2=7"""
        self.assertIO(input, output)

if __name__ == "__main__":
    
    resolve()

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

Solution (Python):
A,B,C,D=map(int,list(input()))
if A+B+C+D==7:
  print('%d+%d+%d+%d=7'%(A,B,C,D))
  exit()
elif A+B+C-D==7:
  print('%d+%d+%d-%d=7'%(A,B,C,D))
  exit()
elif A+B-C+D==7:
  print('%d+%d-%d+%d=7'%(A,B,C,D))
  exit()
elif A-B+C+D==7:
  print('%d-%d+%d+%d=7'%(A,B,C,D))
  exit()
elif A+B-C-D==7:
  print('%d+%d-%d-%d=7'%(A,B,C,D))
  exit()
elif A-B+C-D==7:
  print('%d-%d+%d-%d=7'%(A,B,C,D))
  exit()
elif A-B-C+D==7:
  print('%d-%d-%d+%d=7'%(A,B,C,D))
  exit()

Solution (Python):
A,B,C,D=map(int,list(input()))
if A+B+C+D==7:
  print('%d+%d+%d+%d=7'%(A,B,C,D))
  exit()
elif A+B+C-D==7:
  print('%d+%d+%d-%d=7'%(A,B,C,D))
  exit()
elif A+B-C+D==7:
  print('%d+%d-%d+%d=7'%(A,B,C,D))
  exit()
elif A-B+C+D==7:
  print('%d-%d+%d+%d=7'%(A,B,C,D))
  exit()
elif A+B-C-D==7:
  print('%d+%d-%d-%d=7'%(A,B,C,D))
  exit()
elif A-B+C-D==7:
  print('%d-%d+%d-%d=7'%(A,B,C,D))
  exit()
elif A-B-C+D==7:
  print('%d-%d-%d+%d=7'%(A,B,C,D))
  exit()

Solution (Python):
ABCD = input()
for i in range(8):
        s = ""
        for j in range(3):
                s += ABCD[j] 
                if (i >> j) & 1:
                        s += "+" 
                else:
                        s += "-" 
        s += ABCD[3]
        if eval(s) == 7:
                print(s + "=7")
                break

Solution (Python):
ABCD = input()
for i in range(8):
        op = format(i, '03b')
        s = ""
        for j in range(3):
                s += ABCD[j] 
                if op[j] == "1":
                        s += "+" 
                else:
                        s += "-" 
        s += ABCD[3]
        if eval(s) == 7:
                print(s + "=7")
                break

Solution (Python):
s = input()

case = []
for i in range(2):
    for j in range(2):
        for k in range(2):
            if i ==0:
                a = '+'
            else:
                a = '-'
            if j ==0:
                b = '+'
            else:
                b = '-'
            if k ==0:
                c = '+'
            else:
                c = '-'
            case.append('%s%s%s' % (a,b,c))

for case_i in case:
    print
    if 7 == eval('%s%s%s%s%s%s%s' % (s[0],case_i[0],s[1],case_i[1],s[2],case_i[2],s[3])):
        break

print('%s%s%s%s%s%s%s=7' % (s[0],case_i[0],s[1],case_i[1],s[2],case_i[2],s[3]))

Solution (Python):
a,b,c,d = input()
for i in range(2**3):
    ls = ["+","+","+"]
    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 = input()

import sys
N = 3
for i in range(2**N):
    L = ["-", "-", "-"]
    ZZ = []
    for j in range(N):
        if ((i>>j) & 1):
            L[j] = "+"
            ZZ = [S[0], L[0], S[1], L[1], S[2], L[2], S[3]]
            if eval("".join(ZZ)) == 7:
                print("".join(ZZ) + "=7")
                sys.exit()

Solution (Python):
S = input()

n = len(S) -1 

for i in range(2**n):
    loc = []
    S2 = []
    for j in range(n):
        if (i>>j) & 1:
            loc.append('+')
        else:
            loc.append('-')
    loc.reverse()
    
    for k in range(n):
        S2.append(S[k])
        S2.append(loc[k])
    S2.append(S[-1])
    St = ''.join(S2)
    if eval(St) == 7:
        print(St+'=7')
        break

Solution (Python):
import sys
s = (input())
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])
ls = ["+","-"]
ans = a+b+c+d
if ans == 7:
    print(s[0]+"+"+s[1]+"+"+s[2]+"+"+s[3]+"=7")
    sys.exit()
ans = a+b+c-d
if ans == 7:
    print(s[0]+"+"+s[1]+"+"+s[2]+"-"+s[3]+"=7")
    sys.exit()
ans = a+b-c+d
if ans == 7:
    print(s[0]+"+"+s[1]+"-"+s[2]+"+"+s[3]+"=7")
    sys.exit()
ans = a-b+c+d
if ans == 7:
    print(s[0]+"-"+s[1]+"+"+s[2]+"+"+s[3]+"=7")
    sys.exit()
ans = a-b-c+d
if ans == 7:
    print(s[0]+"-"+s[1]+"-"+s[2]+"+"+s[3]+"=7")
    sys.exit()
ans = a+b-c-d
if ans == 7:
    print(s[0]+"+"+s[1]+"-"+s[2]+"-"+s[3]+"=7")
    sys.exit()
ans = a-b+c-d
if ans == 7:
    print(s[0]+"-"+s[1]+"+"+s[2]+"-"+s[3]+"=7")
    sys.exit()
ans = a-b-c-d
if ans == 7:
    print(s[0]+"-"+s[1]+"-"+s[2]+"-"+s[3]+"=7")
    sys.exit()