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):
N = input()
n = [int(N[i]) for i in range(4)]  

def addd(lista,op):
    cnt = lista[0]


    tmp = [lista[0]]
    for i in range(len(op)):
        if op[i]==0:
            cnt+=lista[i+1]
            tmp.append("+")
            tmp.append(lista[i+1])
        else:
            cnt -=lista[i+1]
            tmp.append("-")
            tmp.append(lista[i+1])
    if cnt ==7:
        tmp.append("=7")
        return tmp
    else:
        return False

for i in range(2):
    for j in range(2):
        for k in range(2):
            ans = addd(n,[i,j,k])
            if ans != False:
                print("".join([str(n) for n in ans]))
                exit()

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

def solve(i, s, suma):
  if i == n-1:
    if suma==7:
      print(s+"=7")
      exit()
  else:
    solve(i+1, s+"-"+S[i+1], suma-int(S[i+1]))
    solve(i+1, s+"+"+S[i+1], suma+int(S[i+1]))
  
  
print(solve(0, S[0], int(S[0])))

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

for i in range(2 ** (n - 1)):
    r = int(S[0])
    for j in range(n - 1):
        if (i >> j) & 1 == 1:
            r -= int(S[j + 1])
        else:
            r += int(S[j + 1])
    if r == 7:
        p = i
        break
    else:
        pass

for i in range(n - 1):
    print(S[i], end = '')
    if (p >> i) & 1 == 1:
        print('-', end = '')
    else:
        print('+', end = '')
print(S[3], end = '') 
print('=7')

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

Solution (Python):
import sys

sys.setrecursionlimit(1000000)


def main():
    s = input()

    op_cnt = 3
    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] = "+"  
        frml = ""
        for j in range(3):
            frml += s[j]
            frml += op[j]
        frml += s[3]

        if eval(frml) == 7:
            print(frml + "=7")
            return


main()

Solution (Python):
abcd = input()
a = []
for i in range(len(abcd)):
    a.append(int(abcd[i]))
for i in range(8):
    sum = a[0]
    s = str(a[0])
    for j in range(3):
        if i & (1<<2-j):
            sum += a[j+1]
            s += '+'
            s += str(a[j+1])
        else:
            sum -= a[j+1]
            s += '-'
            s += str(a[j+1])
    if sum == 7:
        print(s + '=7')
        exit()

Solution (Python):
abcd = input()
a = int(abcd[0])
b = int(abcd[1])
c = int(abcd[2])
d = int(abcd[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))
else:
    print('{0}-{1}+{2}+{3}=7'.format(a, b, c, d))

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

ans_map = {}
for i in range(3):
    if i == 0:
        ans_map['+'] = nums[0] + nums[1]
        ans_map['-'] = nums[0] - nums[1]
        continue

    for operators in dict.fromkeys(ans_map):
        tmp_val = ans_map[operators]
        if i == 2:
            if tmp_val + nums[i + 1] == 7:
                print('{}{}{}{}{}{}{}=7'.format(
                    nums[0],
                    operators[0],
                    nums[1],
                    operators[1],
                    nums[2],
                    '+',
                    nums[3]
                ))
                break

            if tmp_val - nums[i + 1] == 7:
                print('{}{}{}{}{}{}{}=7'.format(
                    nums[0],
                    operators[0],
                    nums[1],
                    operators[1],
                    nums[2],
                    '-',
                    nums[3]
                ))
                break
            continue

        ans_map[operators + '+'] = tmp_val + nums[i + 1]
        ans_map[operators + '-'] = tmp_val - nums[i + 1]
        del ans_map[operators]

Solution (Python):
def seven(s,i):
    if i==l-1:
        if eval(s)==7:
            print(s+"=7")
            exit()
        return
    seven(s+"+"+N[i+1],i+1)
    seven(s+"-"+N[i+1],i+1)
        
N = input()
l=len(N)
seven(N[0],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):
'''
制約
0 ≦ A,B,C,D ≦ 9
入力は整数からなる
答えが存在しない入力は与えられない


'''



import sys
input = sys.stdin.readline

is_debug = False

def main():
    '''メイン処理'''
    
    abcd = str(input()).strip()
    abcd_list = [int(n) for n in abcd]
    if is_debug:
        print(abcd_list)

    
    
    n = len(abcd) - 1
    for i in range(2**n):
        op_list = [0] * n  
        
        
        bin_str = bin(i)[2:].zfill(n)
        
        for j in range(n):
            if bin_str[j] == '1':
                op_list[j] = 1
        
        if is_debug:
            print(i, bin_str)
            print(op_list)
        
        
        calc_result = abcd_list[0]
        for op, num in zip(op_list,abcd_list[1:]):
            if op == 1:
                calc_result += num
            else:
                calc_result -= num
        
        
        if calc_result == 7:
            print(abcd_list[0], end='')
            for op, num in zip(op_list, abcd_list[1:]):
                if op == 1:
                    print('+', end='')
                else:
                    print('-', end='')
                print(num, end='')
            print('=7')
            break


if __name__ == "__main__":
    
    main()

Solution (Python):
s = input()

for i in range(2**len(s)-1):
  f = s[0]
  for j in range(len(s)-1):
    if (i>>j)&1:
      f += "+"
    else:
      f += "-"
    f += s[j+1]
  ans = eval(f)
  
  if ans == 7:
    break

print(f+'=7')

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

def bfs(i,j,a,c):
  if i==3:
    if j+int(L[3])==7:
      c+=[L[0]+a[0]+L[1]+a[1]+L[2]+"+"+L[3]+"=7"]
    elif j-int(L[3])==7:
      c+=[L[0]+a[0]+L[1]+a[1]+L[2]+"-"+L[3]+"=7"]
    return 
    
  else:
    bfs(i+1,j+int(L[i]),a+"+",c)
    bfs(i+1,j-int(L[i]),a+"-",c)
    return c
  

d=[]

ans=bfs(1,int(L[0]),"",d)
print(d[0])

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

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

Solution (Python):
mask = 0b0
num_list = list(map(int,list(input())))
l = len(num_list)
for i in range(1000):
    
    
    sign_list=[]
    for j in range(l-1):
        if(mask & (1<<j)):
            sign_list += ['+']
        else:
            sign_list += ['-']
    
    nsum=num_list[0]
    for j in range(l-1):
        if(sign_list[j]=='+'):
            nsum += num_list[j+1]
        else:
            nsum -= num_list[j+1]

    if(nsum == 7):
        word = ''
        for j in range(l-1):
            word += (str(num_list[j])+sign_list[j])
        word += (str(num_list[-1]) +'=7')
        print(word)
        break

    if(mask > 0b111):
        break
    mask += 1

Solution (Python):
from itertools import product

ABCD = input()

for op in product(("+", "-"), repeat=3):
    ans = ""
    for i in range(len(ABCD)-1):
        ans += ABCD[i] + op[i]
    ans += ABCD[-1]
    if eval(ans) == 7:
        print(ans+"=7")
        exit()

Solution (Python):
A,B,C,D = list(input())
A = int(A)
B = int(B)
C = int(C)
D = int(D)
ans = 0
B_l,C_l,D_l = "","",""
for i in range(2):
    for j in range(2):
        for k in range(2):
            ans=A
            if i == 0:
                ans +=B
                B_l="+"
            else:
                ans -=B
                B_l="-"
            if j == 0:
                ans +=C
                C_l="+"
            else:
                ans-=C
                C_l="-"
            if k == 0:
                ans +=D
                D_l="+"
            else:
                ans-=D
                D_l="-"
            if ans == 7:
                print(str(A)+B_l+str(B)+C_l+str(C)+D_l+str(D)+"=7")
                exit()

Solution (Python):
def Recursion(S):
    list = []
    list.append(S)
    for i in range(len(S)-1):
        left = S[:i+1]
        right = S[i+1:]
        x = left
        for y in Recursion(right):
            list.append(x+"+"+y)
            list.append(x+"-"+y)
    return list

S = input()
for y in Recursion(S):
    if len(y) == len(S)+len(S)-1:
        cand = 0
        for i, x in enumerate(list(y)):
            if i == 0:
                cand += int(x)
            elif x == "+":
                flag = 1
            elif x == "-":
                flag = 0
            elif i % 2 == 0:
                if flag == 0:
                    cand -= int(x)
                else:
                    cand += int(x)
        if cand == 7:
            print(y+"=7")
            break

Solution (Python):
a = list(map(int, input()))
for i in range(8):
    bit = bin(i)[2:len(bin(i))]
    diflen = 3 - len(bit)
    if diflen != 0:
        bit = '0'*diflen + bit
    exp = str(a[0])
    ans = int(a[0])
    for i in range(3):
        if bit[i] == '0':
            exp = exp + '+' + str(a[i+1])
            ans += a[i+1]
        elif bit[i] == '1':
            exp = exp + '-' + str(a[i+1])
            ans -= a[i+1]
    if ans == 7:
        print(exp, '=7', sep='')
        break

Solution (Python):
import itertools

def main() -> None:
    S = input()
    for i in itertools.product(["+","-"], repeat=3):
        ans=""
        for j in range(3):
            ans+=S[j]+i[j]
        ans += S[-1]
        num = eval(ans)
        if num == 7:
            print(ans + "=7")
            exit()

if __name__ == '__main__':
    main()

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

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

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

length = 4 
spaces = length -1

masterlist = []
opelist = ["+"] * spaces

for i in range(2 ** spaces):
    opelist = ["+"] * spaces

    for j in range(spaces):
        if i >> j & 1:
            opelist[j] = "-"
        else:
            opelist[j] = "+"

    masterlist.append(opelist)

for opes in masterlist:
    nls = list(n)
    for k in range(len(opes)):
        nls.insert(2*k+1,opes[k])
        
    nstr = ''.join(nls)
    if eval(nstr) == 7:
        print("{}=7".format(nstr))
        exit()

Solution (Python):
import sys
a = input()
for i in range(8):
    total = int(a[0])
    flag = []
    for j in range(3):
        if ((i >> j) & 1):
            total += int(a[j+1])
            flag.append('+')
        else:
            total -= int(a[j+1])
            flag.append('-')
    if total == 7:
        for k in range(3):
            print(a[k] + flag[k], end = '')
        print(a[3], end = '')
        print('=7')
        sys.exit()

Solution (Python):
import itertools

S=input()

for i in itertools.product(["+","-"],repeat=3):
    ans=""
    for j in range(3):
        if i[j]=="+":
            ans+=S[j]+i[j]
        elif i[j]=="-":
            ans+=S[j]+i[j]
    ans+=S[-1]
    sum1=eval(ans)
    if sum1==7:
        print(ans+"="+str(7))
        exit()

Solution (Python):
import itertools

S=input()
sum1=0


for i in itertools.product(["+","-"],repeat=3):
    ans=""
    for j in range(3):
        if i[j]=="+":
            ans+=S[j]+i[j]
        elif i[j]=="-":
            ans+=S[j]+"-"
    ans+=S[-1]
    sum1=eval(ans)
    if sum1==7:
        print(ans+"="+str(7))
        exit()

Solution (Python):
S=input()

for i in range(2**3):
    sent=''+S[0]

    for j in range(3):
        if (i >> j) & 1:
            sent+='+' + S[j+1]
        else:
            sent+='-' + S[j+1]
    
    if eval(sent) == 7:
        print(sent+'=7')
        exit(0)

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

Solution (Python):
def nyu():
    N = list(map(str,input()))
    return N

def check(LOP1,LOP2,LOP3):  
    global flg1
    ls =  N[0]+LOP1+N[1]+LOP2+N[2]+LOP3+N[3]
    if flg1 == True:
        return
    elif(eval(ls) == 7):
        print(N[0],LOP1,N[1],LOP2,N[2],LOP3,N[3],"=7",sep='')
        flg1 = True
        return



    if LOP1 =='+':
        check('-',LOP2,LOP3)
    if LOP2 == '+':
        check(LOP1,'-',LOP3)
    if LOP3 == '+':
        check(LOP1,LOP2,'-')



N = nyu()
flg1 = False
OP1 = "+"
OP2 = "+"
OP3 = "+"
check(OP1,OP2,OP3)

Solution (Python):
import sys

input = sys.stdin.readline
MOD = 1000000007

op = list('+-')

x = input()[:-1]

res =""
for i in range(len(x)):
    res += str(x[i])
    if i != 3:
        res +="-"
res += "="

for bits in range(0,1<<3):
    y = []
    a = int(x[0])
    for d in range(2,-1,-1):
        if 1 & (bits>>d) :
            a += int(x[3-d])
            y.append("+")
        else:
            a -= int(x[3-d])
            y.append("-")
    
    if a == 7:
        res =""
        for i in range(len(x)):
            res += str(x[i])
            if i != 3:
                res +=str(y[i])
        res += "=7"
        print(res)
        exit()

Solution (Python):
def ope(i, ans, ans_str):
    if i == 3:
        if ans == 7:
            return ans_str+"=7"
        else:
            return None
    else:
        result = ope(i+1, ans+int(S[i+1]), ans_str + "+" + S[i+1])
        if result:
            return result
        result = ope(i+1, ans-int(S[i+1]), ans_str + "-" + S[i+1])
        if result:
            return result
S = list(input())
result = ope(0, int(S[0]), S[0])
print(result)

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

import itertools

for i in itertools.product(['+', '-'], repeat=3):
    ans = int(ABCD[0])
    
    for idx, ii in enumerate(i):
        if ii == '+':
            ans += int(ABCD[idx+1])
        else:
            ans -= int(ABCD[idx+1])
    
    if ans == 7:
        break
print(ABCD[0]+i[0]+ABCD[1]+i[1]+ABCD[2]+i[2]+ABCD[3]+'=7')

Solution (Python):
lst = [int(s) for s in input()]
lst2 = []
search = 7
for i, num in enumerate(lst):
    lst2.append([])
    if i == 0:
        lst2[i].append(num)
    else:
        for num_ in lst2[i-1]:
            lst2[i].append(num_ + num)
            lst2[i].append(num_ - num)
idx = lst2[len(lst2)-1].index(search)
s= str(lst[0])
lst_ = list(lst2[len(lst)-1])
for i in range(1, len(lst)):
    if len(lst_)/2>idx:
        s += '+'
        lst_ = lst_[0:len(lst_)//2]
    else:
        s += '-'
        lst_ = lst_[(len(lst_)//2):len(lst_)]
        idx -= len(lst_)
    s += str(lst[i])
s += '=' + str(search)
print(s)

Solution (Python):
s = input()
a, b, c, d = map(str, s)
for op1 in '+-':
    for op2 in '+-':
        for op3 in '+-':
            if eval(a+op1+b+op2+c+op3+d) == 7:
                print(a+op1+b+op2+c+op3+d+'=7')
                exit()

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

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

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

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

for bit in range(1<<(n-1)):
    f = l[0]
    sum = int(l[0])

    for i in range(n-1):
        if bit & (1<<i):
            f = f + "+" + l[i+1]
            sum = sum + int(l[i+1])
        else:
            f = f + "-" + l[i+1]
            sum = sum - int(l[i+1])
    
    if sum == 7:
        print(f+"=7")
        exit()

Solution (Python):

import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

N = readline().rstrip()
S = list(N)
bnk = len(N)-1
for i in range(2**bnk):
    op = ["-","-","-"]
    for j in range(bnk):
        if ((i>>j)&1):
            op[bnk-j-1] = "+"
    tmp = ""
    for k in range(3):
        tmp += S[k]+op[k]
    tmp = tmp+S[3]
    if eval(tmp)==7:
        print(tmp+"=7")
        break

Solution (Python):
def multi_input():
    return map(int, input().split())

s = input()
l = []
l.append(s[0])

for si in s[1:]:
    t = []
    for li in l:
        t.append(li+'+'+si)
        t.append(li+'-'+si)
    l = t
    
for li in l:
    if eval(li) == 7:
        print(li+'=7')
        break

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

ans = 7
plus = "+"
minus = "-"
equal = "="
func = ""
for i in range(1 << 3):
    op = []
    for j in range(3):
        op.append(plus if i & (1 << j) else minus)
    calc = n[0]
    for j in range(3):
        if op[j] == plus:
            calc += n[j + 1]
        else:
            calc -= n[j + 1]
    if calc == ans:
        func = str(n[0])
        for j in range(3):
            func += op[j] + str(n[j + 1])
        func += equal + str(ans)
        break

print(func)

Solution (Python):


s = input()
ans = []

def dfs(i, n, ns):
    if i == 3:
        if n == 7:
            ans.append(ns + '=7')
            return 
        else:
            return

    dfs(i+1, n + int(s[i+1]), ns + '+' + s[i+1])
    dfs(i+1, n - int(s[i+1]), ns + '-' + s[i+1]) 


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

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

res = ""

if a + b + c + d == 7:
    res = str(a)+"+"+str(b)+"+"+str(c)+"+"+str(d)+"=7"
elif a + b + c - d == 7:
    res = str(a)+"+"+str(b)+"+"+str(c)+"-"+str(d)+"=7"
elif a + b - c + d == 7:
    res = str(a)+"+"+str(b)+"-"+str(c)+"+"+str(d)+"=7"
elif a + b - c - d == 7:
    res = str(a)+"+"+str(b)+"-"+str(c)+"-"+str(d)+"=7"
elif a +- b + c + d == 7:
    res = str(a)+"-"+str(b)+"+"+str(c)+"+"+str(d)+"=7"
elif a - b + c - d == 7:
    res = str(a)+"-"+str(b)+"+"+str(c)+"-"+str(d)+"=7"
elif a - b - c + d == 7:
    res = str(a)+"-"+str(b)+"-"+str(c)+"+"+str(d)+"=7"
elif a - b - c - d == 7:
    res = str(a)+"-"+str(b)+"-"+str(c)+"-"+str(d)+"=7"

print(res)

Solution (Python):
tmp = input()
abcd = [int(t) for t in tmp]

for i in range(2**3):
    total = abcd[0]
    eq = tmp[0]
    for j in range(3):
        if (i >> j) & 1:
            eq += '+' + tmp[j+1]
            total += abcd[j+1]
        else:
            eq += '-' + tmp[j+1]
            total -= abcd[j+1]
    if total == 7:
        eq += '=7'
        break
print(eq)

Solution (Python):
import sys

def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))

def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]

def to_bin(x: int) -> str: return format(x, 'b') 
def to_oct(x: int) -> str: return format(x, 'o') 
def to_hex(x: int) -> str: return format(x, 'x') 
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]

from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left



def main():
    a, *bcd = list(map(int, IS()))
    for bit in range(1<<3):
        sumv = a
        pm = []
        for i in range(3):
            if bit & (1<<i):
                sumv += bcd[i]
                pm.append('+')
            else:
                sumv -= bcd[i]
                pm.append('-')
        if sumv == 7:
            a = str(a)
            b = str(bcd[0])
            c = str(bcd[1])
            d = str(bcd[2])
            print(a+pm[0]+b+pm[1]+c+pm[2]+d+'=7')
            return None

if __name__ == '__main__':
    main()

Solution (Python):
a,b,c,d=map(int,list(input()))
s = [list(map(int,bin(x)[2:].zfill(3))) for x in range(2**3)]
ans = a
op = []
for i in range(2**3):
    if s[i][0]==0:
        ans += b
        op.append('+')
    else:
        ans -= b
        op.append('-')
    if s[i][1]==0:
        ans += c
        op.append('+')
    else:
        ans -= c
        op.append('-')
    if s[i][2]==0:
        ans += d
        op.append('+')
    else:
        ans -= d
        op.append('-')
    if ans ==7:
        break
    ans = a
    op.clear()
t = str(a)+op[0]+str(b)+op[1]+str(c)+op[2]+str(d)+'=7'
print(t)

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):
if __name__=='__main__':
    s = input()

    
    for i in range(1 << (len(s)-1)):
        bina = bin(i).replace('0b', '')
        bina = bina.zfill(len(s)-1)
        ans = int(s[0])
        ans_s = s[0]
        for j in range(len(bina)):
            if bina[j] == '1':
                ans_s += '+' + s[j+1]
                ans += int(s[j+1])
            else:
                ans_s += '-' + s[j+1]
                ans -= int(s[j+1])
        if ans == 7:
            print(ans_s + '=7')
            break

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

Solution (Python):
import sys

num_str = sys.stdin.readline().strip()
for i in range(8):
  tmp_str = list(num_str)
  if i % 2 == 1:
    tmp_str.insert(3, '+')
  else:
    tmp_str.insert(3, '-')
  if (i // 2) % 2 == 1:
    tmp_str.insert(2, '+')
  else:
    tmp_str.insert(2, '-')
  if (i // 4) % 2 == 1:
    tmp_str.insert(1, '+')
  else:
    tmp_str.insert(1, '-')
  tmp_str = ''.join(tmp_str)
  exec_str = 'a=' + tmp_str
  exec(exec_str)
  if a == 7:
    print(tmp_str + '=7')
    break

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

for i in range(2**(n-1)):
    ans = int(s[0])
    formura = s[0]
    for j in range(1,n):
        if (i >> j-1) & 1 == 1:
            ans += int(s[j])
            formura += "+" + s[j]
        else:
            ans -= int(s[j])
            formura += "-" + s[j]
    if ans == 7:
        print(formura + "=7")
        break

Solution (Python):
S = str(input())
ans = []
for i in [int(S[1]),-int(S[1])]:
    for j in [int(S[2]),-int(S[2])]:
        for k in [int(S[3]),-int(S[3])]:
            if int(S[0]) == 7 - (i+j+k):
                ans = [i,j,k]
sg = []
for a in ans:
    if a < 0:
        sg.append('-')
    else:
        sg.append('+')
ek =''.join([S[0],sg[0],S[1],sg[1],S[2],sg[2],S[3]])
print(ek + '=7')

Solution (Python):
a, b, c, d = input()
l = ["+", "-"]
for op1 in l:
    for op2 in l:
        for op3 in l:
            tmp = a + op1 + b + op2 + c + op3 + d
            if eval(tmp) == 7:
                print(tmp + "=7")
                exit()

Solution (Python):
class TrainTicket():
    def calculate(self, S: list):
        for x in range(2):
            for y in range(2):
                for z in range (2):
                    if x == 1:
                        res = S[0] + S[1]
                    else:
                        res = S[0] - S[1]
                    if y ==1:
                        res += S[2]
                    else:
                        res -= S[2]
                    if z == 1:
                        res += S[3]
                    else:
                        res -= S[3]
                    if res == 7:
                        if x == 1:
                            xr = "+"
                        else:
                            xr = "-"
                        if y == 1:
                            yr = "+"
                        else:
                            yr= "-"
                        if z == 1:
                            zr = "+"
                        else:
                            zr = "-"
                        return(str(S[0]) + xr + str(S[1]) + yr + str(S[2]) + zr + str(S[3]))


if __name__ =="__main__":
    S = list(map(int, input()))
    tt = TrainTicket()
    res = tt.calculate(S)
    print(str(res)+"=7")

Solution (Python):
S = input()
binary = '111'
for i in range(2**(len(S)-1)):
  binary = str(format(i,'b')).zfill(3)
  if int(S[0])+int(S[1])*(-1)**(int(binary[0]))+int(S[2])*(-1)**(int(binary[1]))+int(S[3])*(-1)**(int(binary[2]))==7:  
    break
B = binary.replace('0','+').replace('1','-')
print(S[0]+B[0]+S[1]+B[1]+S[2]+B[2]+S[3]+'=7')

Solution (Python):
import sys
import itertools
ABCDlist=list(map(int,list(input())))


for bit in itertools.product(range(2),repeat=3):
  answer=ABCDlist[0]
  answer_list=[str(answer)]
  for i in range(3):
    if bit[i]==0:
      answer+=ABCDlist[i+1]
      answer_list.append("+"+str(ABCDlist[i+1]))
    else:
      answer-=ABCDlist[i+1]
      answer_list.append("-"+str(ABCDlist[i+1]))
      
  if answer==7:
    answer_list.append("=7")
    print("".join(answer_list))
    sys.exit(0)

Solution (Python):
listA = list(input())
listA = list(map(int,listA))
A,B,C,D = listA
s1,s2,s3 = 0,0,0
for i in range(2):
    for j in range(2):
        for k in range(2):
            total = 0
            if i == 0:
                s1 = "-"
                total = A - B
            else:
                s1 = "+"
                total = A + B
            if j == 0:
                s2 = "-"
                total = total - C
            else:
                s2 = "+"
                total = total + C
            if k == 0:
                s3 = "-"
                total = total - D
            else:
                s3 = "+"
                total = total + D
            if total == 7:
                print(str(A)+s1+str(B)+s2+str(C)+s3+str(D)+"=7")
                exit()

Solution (Python):
a, b, c, d = list(input())
for op1 in ['+', '-']:
    for op2 in ['+', '-']:
        for op3 in ['+', '-']:
            tmp = a + op1 + b + op2 + c + op3 + d
            if eval(tmp) == 7:
                print(tmp+'=7')
                exit()

Solution (Python):
A,B,C,D=map(int, list(input()))
L=["+","-"]

for i in L:
    for j in L:
        for k in L:
            now=A
            if i=="+":
                now+=B
            else:
                now-=B
            if j=="+":
                now+=C
            else:
                now-=C
            if k=="+":
                now+=D
            else:
                now-=D
            if now==7:
                print(str(A)+i+str(B)+j+str(C)+k+str(D)+"=7")
                exit()

Solution (Python):
def main():
    from itertools import product, zip_longest

    s = input()

    for prod in product('+-', repeat=3):
        formula = ''
        for x, op in zip_longest(s, prod, fillvalue=''):
            formula += x + op
        if eval(formula) == 7:
            print('{}=7'.format(formula))
            return


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    from itertools import product, zip_longest

    s = input()

    for prod in product(['+', '-'], repeat=3):
        formula = ''
        for x, op in zip_longest(s, prod, fillvalue=''):
            formula += x + op
        if eval(formula) == 7:
            print('{}=7'.format(formula))
            return


if __name__ == '__main__':
    main()

Solution (Python):
a, b, c, d = list(input())
for op1 in ['+', '-']:
    for op2 in ['+', '-']:
        for op3 in ['+', '-']:
            tmp = a + op1 + b + op2 + c + op3 + d
            if eval(tmp) == 7:
                print(tmp+'=7')
                exit()

Solution (Python):
def main():
    from itertools import product, zip_longest

    s = input()

    for prod in product(['+', '-'], repeat=3):
        formula = ''
        for x, op in zip_longest(s, prod, fillvalue=''):
            formula += x + op
        if eval(formula) == 7:
            print(formula + '=7')
            return


if __name__ == '__main__':
    main()