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 bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
s = S()
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[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):
ans=0
a=input()
def dfs(i,s=''):
  global ans
  if i==len(a)-1:
    if eval(s+a[-1])==7:
      ans=s+a[-1] + '=7'
      return 

    else:
      return
  dfs(i+1,s+a[i]+'-')
  dfs(i+1,s+a[i]+'+')

dfs(0)
print(ans)

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

A = int(ABCD[0])
B = int(ABCD[1])
C = int(ABCD[2])
D = int(ABCD[3])

AA = ABCD[0]
BB = ABCD[1]
CC = ABCD[2]
DD = ABCD[3]

if A+B+C+D==7:
    print(AA+'+'+BB+'+'+CC+'+'+DD+'=7')
elif A+B+C-D==7:
    print(AA+'+'+BB+'+'+CC+'-'+DD+'=7')
elif A+B-C+D==7:
    print(AA+'+'+BB+'-'+CC+'+'+DD+'=7')
elif A+B-C-D==7:
    print(AA+'+'+BB+'-'+CC+'-'+DD+'=7')
elif A-B+C+D==7:
    print(AA+'-'+BB+'+'+CC+'+'+DD+'=7')
elif A-B+C-D==7:
    print(AA+'-'+BB+'+'+CC+'-'+DD+'=7')
elif A-B-C+D==7:
    print(AA+'-'+BB+'-'+CC+'+'+DD+'=7')
elif A-B-C-D==7:
    print(AA+'-'+BB+'-'+CC+'-'+DD+'=7')

Solution (Python):
listi = list(input())
a=listi[0]
b=listi[1]
c=listi[2]
d=listi[3]

 

res = ""


def hugou(i):
    if i=="0":
        return "+"
    else:
        return "-"
    

for x in range(2 ** 3):

    z = str(format(x, '03b')) 
    ans = 0
    ans += int(a)
    if z[0]=="0":
        ans += int(b)
    else:
        ans += int(b) * -1
    if z[1]=="0":
        ans += int(c)
    else:
        ans += int(c) * -1   
    if z[2]=="0":
        ans += int(d)
    else:
        ans += int(d) * -1        
        
    
    
    if ans == 7:
        res += a
        res += hugou(z[0])
        res += b
        res += hugou(z[1]) 
        res += c
        res += hugou(z[2])
        res += d 
        
        res += "=7"
        print(res)
        break

Solution (Python):
def op(x):
    return '+' if x==0 else '-'

N = int(input())
a=N//1000
b=N%1000//100
c=N%100//10
d=N%10
for i in range(2**3):
    total=0
    for j,num in zip(range(3),[b,c,d]):
        if (i>>j)&1==0:
            total+=num
        else:
            total-=num
    if a+total==7:
        print('{}{}{}{}{}{}{}=7'.format(a,op(i>>0&1),b,op(i>>1&1),c,op(i>>2&1),d))
        break

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

for i in range(2):
    for j in range(2):
        for k in range(2):
            ans = 0
            if i == 0:
                ans += list_s[0] + list_s[1]
            else:
                ans += list_s[0] - list_s[1]
            if j == 0:
                ans += list_s[2]
            else:
                ans -= list_s[2]
            if k == 0:
                ans += list_s[3]
            else:
                ans -= list_s[3]
            if ans == 7:
                break
        else:
            continue
        break
    else:
        continue
    break
list_sgn = ["+","-"]
print(str(list_s[0]) + list_sgn[i] + str(list_s[1]) + list_sgn[j] + str(list_s[2]) + list_sgn[k] + str(list_s[3]) + "=7")

Solution (Python):
n = input()
for i in range(2 ** 3):
    op = ['+'] * 3
    for j in range(3):
        if i >> j & 1:
            op[j] = '-'
    f = [0] * 7
    f[::2] = n
    f[1::2] = op
    f = ''.join(f)
    if eval(f) == 7:
        print(''.join([f, '=7']))
        exit()

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

for i in range(2**3):
    count=l[0]
    s=str(l[0])
    for j in range(3):
        if i&(2**j):
            count+=l[j+1]
            s=s+'+'+str(l[j+1])
        else:
            count-=l[j+1]
            s=s+'-'+str(l[j+1])
    if count==7:
        print(s+'=7')
        exit()

Solution (Python):
nums = list(input())
calc_cnt = len(nums) - 1

def vaule_check():
    for i in range(2**calc_cnt):
        formation = str(nums[0])
        for j in range(calc_cnt):
            if ((i >> j) & 1):
                formation+='+' + nums[j+1]
            else:
                formation+='-' + nums[j+1]
        
        if eval(formation) == 7:
            return formation + '=7'

print(vaule_check())

Solution (Python):
from itertools import product

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

for operators in product(('+', '-'), repeat=3):
    a = A
    b = B
    c = C
    d = D
    if operators[0] == '-':
        b *= -1
    if operators[1] == '-':
        c *= -1
    if operators[2] == '-':
        d *= -1

    if a + b + c + d == 7:
        print('{}{}{}{}{}{}{}=7'.format(A, operators[0], B, operators[1], C, operators[2], D))
        break

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


def add(n, s):
    if n == 0:
        
        if eval(s) == 7:
            results.append(s)
        return 1
    else:
        sp = s[:n] + '+' + s[n:]
        sm = s[:n] + '-' + s[n:]
        return add(n-1, sp) + add(n-1, sm)

results = []
_ = add(N, S)
print(results[0]+'=7')

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

Solution (Python):
s=input()
op=['+', '-']
for op1 in op:
    for op2 in op:
        for op3 in op:
            tmp=s[0]+op1+s[1]+op2+s[2]+op3+s[3]
            if eval(tmp)==7:
                ans=tmp
print(ans+'=7')

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] = '+'
    f = ''
    for j in range(op_cnt):
        f += n[j] + op[j]
    f += n[-1]
    if eval(f) == 7:
        print(f + '=7')
        break

Solution (Python):
import itertools

l = list(input())

for i in itertools.product('+-', repeat=3):
    s = l[0] + i[0] + l[1] + i[1] + l[2] + i[2] + l[3]
    m = eval(s)
    if m == 7:
        print(s + '=7')
        break

Solution (Python):
A, B, C, D = [int(x) for x in input()]
tmp = []

def dfs(P):
    global tmp
    if len(P)==3:
        tmp.append(P[:])
        return
    
    for op in ['+', '-']:
        P.append(op)
        dfs(P)
        P.pop()
        
dfs([])
for ops in tmp:
    ans = A
    for op, i in zip(ops, [B,C,D]):
        if op=='+':
            ans += i
        else:
            ans -= i
    if ans==7:
        print('{}{}{}{}{}{}{}=7'.format(A, ops[0], B, ops[1], C, ops[2], D))
        break

Solution (Python):
import itertools
s = list(input())
for ops in itertools.product(['+','-'],repeat=3):
  s_i = []
  for i in range(3):
    s_i.append(s[i])
    s_i.append(ops[i])
  s_i.append(s[-1])
  s_i = "".join(s_i)
  if eval(s_i)==7:
    print(s_i+"=7")
    exit()

Solution (Python):
S = input()
S_str = str(S)
S_list = []
for i in range(len(S_str)):
    S_list.append(int(S_str[i]))
ans = ''

for i in range(2**3):
    tmp = S_list[0]
    for j in range(1,4):
        if i & (1 << 3-j):
            tmp -= S_list[j]
        else:
            tmp += S_list[j]
    if tmp == 7:
        break
for n in range(3):
    ans += S_str[n]
    if i & (1 << 2-n):
        ans += '-'
    else:
        ans += '+'
ans += S_str[-1] + '=7'
print(ans)

Solution (Python):
abcd = list(input())
a = int(abcd[0])
b = int(abcd[1])
c = int(abcd[2])
d = int(abcd[3])
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):
numbers = [int(_) for _ in input()]
n = len(numbers) - 1

for i in range(2 ** n):
    ans = numbers[0]
    ops = []
    for j in range(n):
        if i >> j & 1:
            ans += numbers[j+1]
            ops.append("+")
        else:
            ans -= numbers[j+1]
            ops.append("-")
    if ans == 7:
        break

print("{0}{4}{1}{5}{2}{6}{3}=7".format(numbers[0], numbers[1], numbers[2], numbers[3], ops[0], ops[1], ops[2]))

Solution (Python):
numbers = list(map(int, list(str(input()))))
n = len(numbers) - 1

for i in range(2 ** n):
    ans = numbers[0]
    ops = []
    for j in range(n):
        if i >> j & 1:
            ans += numbers[j+1]
            ops.append("+")
        else:
            ans -= numbers[j+1]
            ops.append("-")
    if ans == 7:
        break

print("{0}{4}{1}{5}{2}{6}{3}=7".format(numbers[0], numbers[1], numbers[2], numbers[3], ops[0], ops[1], ops[2]))

Solution (Python):
N = input()
for i in range(2**(len(N)-1)):
    new = N[0]
    ans = int(N[0])
    for j in range(len(N)-1):
        if((i>>j) & 1):
            ans += int(N[j+1])
            new = new + '+' + N[j+1]
        else:
            ans -= int(N[j+1])
            new = new + '-' + N[j+1]
    if(ans == 7):
        new += '=7'
        print(new)
        break

Solution (Python):
S = input()

def func(i, x, op):
    if i == 4:
        if x == 7:
            return op
        else:
            return ''
    opP = func(i + 1, x + int(S[i]), op+'+'+str(S[i]))
    if opP != '':
        return opP
    opM = func(i + 1, x - int(S[i]), op+'-'+str(S[i]))
    if opM != '':
        return opM
    return ''

print(func(1, int(S[0]), str(S[0])) + '=7')

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

Solution (Python):
A=input()

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

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

for i in range(2**a):
    c = ["-"]*a
    t = ""
    for j in range(a):
        if ((i >> j) & 1):
            c[a-1-j] = "+"
        t = c[a-1-j] + s[a-j] + t
    t = s[0] + t
    
    if eval(t) == 7:
        t = t + "=7"
        print(t)
        break

Solution (Python):
def main():
    abcd = input()
    s = list(map(int, list(abcd)))
    n = 3
    for i in range(2 ** n):
        total = s[0]
        sign = []
        for j in range(n):
            if ((i >> j) & 1):
                total += s[j + 1]
                sign += ['+']
            else:
                total -= s[j + 1]
                sign += ['-']
        if total == 7:
            print(str(s[0]) + sign[0] + str(s[1]) +
                  sign[1] + str(s[2]) + sign[2] + str(s[3]) + '=7')
            return


if __name__ == '__main__':
    main()

Solution (Python):
import sys
S = input()
A = S[0]
B = S[1]
C = S[2]
D = S[3]
if int(A) + int(B) + int(C) + int(D) == 7:
    print(A + '+' + B + '+' + C + '+' + D + '=7')
    sys.exit()
if int(A) - int(B) + int(C) + int(D) == 7:
    print(A + '-' + B + '+' + C + '+' + D + '=7')
    sys.exit()
if int(A) + int(B) - int(C) + int(D) == 7:
    print(A + '+' + B + '-' + C + '+' + D + '=7')
    sys.exit()
if int(A) - int(B) - int(C) + int(D) == 7:
    print(A + '-' + B + '-' + C + '+' + D + '=7')
    sys.exit()
if int(A) + int(B) + int(C) - int(D) == 7:
    print(A + '+' + B + '+' + C + '-' + D + '=7')
    sys.exit()
if int(A) - int(B) + int(C) - int(D) == 7:
    print(A + '-' + B + '+' + C + '-' + D + '=7')
    sys.exit()
if int(A) + int(B) - int(C) - int(D) == 7:
    print(A + '+' + B + '-' + C + '-' + D + '=7')
    sys.exit()
if int(A) - int(B) - int(C) - int(D) == 7:
    print(A + '-' + B + '-' + C + '-' + D + '=7')
    sys.exit()

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

a = input().rstrip()
b = []
for i in a:
    b.append(int(i))

op = [""] * 3
for i in range(2 ** 3):
    cnt = b[0]
    for j in range(3):
        if ((i >> j) & 1):
            op[2-j] = "+"
        else:
            op[2-j] = "-"
    for j in range(3):
        if op[j] == "+":
            cnt += b[j+1]
        else:
            cnt -= b[j+1] 
    if cnt == 7:
        print(b[0], op[0], b[1], op[1], b[2], op[2], b[3], "="+str(cnt),sep="")
        break

Solution (Python):
def pad(b,N):
    b = "0"*(N-len(b)) + b
    return b

def cal(A):
    N = len(A)
    for i in range(2**(N-1)):
        b = list(pad(bin(i)[2:],N-1))
        for j in range(N-1):
            if b[j] == "1":
                b[j] = "+"
            else:
                b[j] = "-"
        s = A[0]
        for j in range(N-1):
            if b[j] == "+":
                s += A[j+1]
            else:
                s -= A[j+1]
        if s == 7:
            output = str(A[0])
            for j in range(N-1):
                output += b[j]
                output += str(A[j+1])
            output += "=7"
            return output

def main():
    A = list(map(int,input()))
    print(cal(A))

if __name__ == "__main__":
    main()

Solution (Python):

A = list(input())
for i in range(2 ** 3):
    op = ["-"] * 3
    for j in range(3):
        if ((i >> j) & 1):
            op[3 - 1 - j] = "+"
    ans = ""
    for m, n in zip(A, op):
        ans += m + n
    ans += A[3]
    if eval(ans) == 7:
        print(ans + "=7")
        exit()

Solution (Python):



import sys


def input():
    return sys.stdin.readline()

def dfs_four_number(s_num, i, op_list:list):
    
    if i == 3:
        ans_num = int(s_num[0])
        for j, op in enumerate(op_list):
            if op == "+":
                ans_num += int(s_num[j+1])
            elif op == "-":
                ans_num -= int(s_num[j+1])

        if ans_num == 7:
            return op_list
        else:
            return False

    op_list.append("+")
    if dfs_four_number(s_num, i+1, op_list):
        return op_list

    op_list.pop()
    op_list.append("-")
    if dfs_four_number(s_num, i+1, op_list):
        return op_list
    op_list.pop()



def resolve():
    s_num = input().rstrip()

    op_list = []
    ans_op_list = dfs_four_number(s_num, 0, op_list)

    ans_str = ""
    for s, op in zip(s_num, ans_op_list):
        ans_str += s
        ans_str += op

    ans_str += s_num[3] + "=7"
    print(ans_str)

if __name__ == "__main__":
    resolve()

Solution (Python):
N = list(map(int, input()))
a,b,c,d = N[0], N[1], N[2], N[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))
else:
    pass

Solution (Python):
s = input()
n = list(map(int, [int(s[i]) for i in range(len(s))]))

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

Solution (Python):
abcd=list(input())
enzanshi=[['+','-'],['+','-'],['+','-']]
for i in range(2**3):
  l=[]
  for j in range(3):
    if (i>>j)&1:
      l.append(enzanshi[j][0])
    else:
      l.append(enzanshi[j][1])


  keisan=""
  for i,j in zip(abcd,l+['']):
    keisan+=i+j

  if eval(keisan)==7:
    print(keisan + '=7')
    break

Solution (Python):
num = input()
for bit in range(2 ** 3):
    tmp = int(num[0])
    ans = str(num[0])
    for i in range(3):
        if bit >> i & 1 == 0:
            tmp += int(num[i + 1])
            ans += '+' + num[i + 1]
        else:
            tmp -= int(num[i + 1])
            ans += '-' + num[i + 1]
    if tmp == 7:
        ans += '=7'
        print(ans)
        break

Solution (Python):
S=input()

new=""
ans=""

def func(s,new,i=0):
    
    if i==3:
        global ans
        ans=""
        new+=s[i]
        if eval(new)==7:
            ans=new+"=7"
            return True
        else:
            return False
   
    if func(s,new+s[i]+"+",i+1):
        return True
    
    if func(s,new+s[i]+"-",i+1):
        return True

if func(S,new):
    print(ans)

Solution (Python):

N=input()
A,B,C,D =int(N[0]),int(N[1]),int(N[2]),int(N[3])
def f_add(a,b):
    return a+b
def f_minus(a,b):
    return a-b
def jug_f(f):
    if f ==f_add:
        return '+'
    else:
        return '-'
ans =''
for f1 in [f_add,f_minus]:
    for f2 in [f_add,f_minus]:
        for f3 in [f_add,f_minus]:
            if f3(f2(f1(A,B),C),D)==7:
                ans +=str(A)+jug_f(f1)+str(B)+jug_f(f2)+str(C)+jug_f(f3)+str(D)+"=7"
                print(ans)
                exit()

Solution (Python):
import sys
A, B, C, D = list(map(int, input().rstrip()))

if A+B+C+D==7:
    print("{}+{}+{}+{}=7".format(A, B, C, D))
    sys.exit()
elif A+B+C-D==7:
    print("{}+{}+{}-{}=7".format(A, B, C, D))
    sys.exit()
elif A+B-C+D==7:
    print("{}+{}-{}+{}=7".format(A, B, C, D))
    sys.exit()
elif A+B-C-D==7:
    print("{}+{}-{}-{}=7".format(A, B, C, D))
    sys.exit()
elif A-B+C+D==7:
    print("{}-{}+{}+{}=7".format(A, B, C, D))
    sys.exit()
elif A-B+C-D==7:
    print("{}-{}+{}-{}=7".format(A, B, C, D))
    sys.exit()
elif A-B-C+D==7:
    print("{}-{}-{}+{}=7".format(A, B, C, D))
    sys.exit()
elif A-BC-D==7:
    print("{}-{}-{}-{}=7".format(A, B, C, D))
    sys.exit()
else:
    pass

Solution (Python):



import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

s=SI()
a=int(s[0])
b=int(s[1])
c=int(s[2])
d=int(s[3])
def porm(x):
    if x==1:
        return "+"
    else:
        return "-"
def vec(x):
    if x==1:
        return 1
    else:
        return -1
for i in range(8):
    j=(i>>0) %2
    k=(i>>1) %2
    l=(i>>2) %2
    if a+b*vec(j)+c*vec(k)+d*vec(l)==7:
        print(a,end="")
        print(porm(j),end="")
        print(b,end="")
        print(porm(k),end="")
        print(c,end="")
        print(porm(l),end="")
        print(d,end="")
        print("=7")
        sys.exit()

Solution (Python):
import math
import copy

s = input()
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])
e = a + b
f = a - b
g = c + d
h = c - d
if e + g == 7:
    a,b,c,d = map(str,(a,b,c,d))
    print(a+'+'+b+"+"+c+"+"+d+"=7")
elif e + c-d == 7:
    a,b,c,d = map(str,(a,b,c,d))
    print(a+'+'+b+"+"+c+"-"+d+"=7")
elif e + d-c == 7:
    a,b,c,d = map(str,(a,b,c,d))
    print(a+'+'+b+"-"+c+"+"+d+"=7")
elif e - c-d == 7:
    a,b,c,d = map(str,(a,b,c,d))
    print(a+'+'+b+"-"+c+"-"+d+"=7")
elif f + g == 7:
    a,b,c,d = map(str,(a,b,c,d))
    print(a+'-'+b+"+"+c+"+"+d+"=7")
elif f + c-d == 7:
    a,b,c,d = map(str,(a,b,c,d))
    print(a+'-'+b+"+"+c+"-"+d+"=7")
elif f + d-c == 7:
    a,b,c,d = map(str,(a,b,c,d))
    print(a+'-'+b+"-"+c+"+"+d+"=7")
elif f - c-d == 7:
    a,b,c,d = map(str,(a,b,c,d))
    print(a+'-'+b+"-"+c+"-"+d+"=7")

Solution (Python):
def main():
    s = input()
    for i in range(1<<3):
        t = int(s[0])
        op = []
        for j in range(3):
            if 1 & (i>>j):
                t += int(s[j+1])
                op.append('+')
            else:
                t -= int(s[j+1])
                op.append('-')
        if t == 7:
            x = ['{}{}'.format(a,b) for a,b in zip(s, op)]
            print("".join(x) + s[-1] + '=7')
            break

if __name__ == '__main__':
    main()

Solution (Python):
S = input()
for bit in range(1 << len(S)-1):
    ans = [0,0,0]
    f = int(S[0])
    for i in range(0,len(S)-1):
        if bit & (1 << i):
            f -= int(S[i+1])
            ans[i] = "-"
        else:
            f += int(S[i+1])
            ans[i] = "+"
    if f == 7: break
for i in range(len(S)):
    if i == len(ans):
        print(S[i] + "=",end="")
    else:
        print(S[i] + ans[i],end="")
print(7)

Solution (Python):
a, b, c, d = input()
n = 4
answer = ''

for i in range(2 ** (n - 1)):
    ops = ['+', '+', '+']
    for j in range(n - 1):
        if (i >> j) & 1:
            ops[j] = '-'
    if eval(a + ops[0] + b + ops[1] + c + ops[2] + d) == 7:
        print(a+ops[0]+b+ops[1]+c+ops[2]+d+'=7')
        break

Solution (Python):
import copy

def calc_bits(nums, bits):
    nums = copy.deepcopy(nums)
    num0 = nums.pop(0)
    result = num0
    formula = str(num0)
    for num, bit in zip(nums, bits):
        if bit == 0:
            result -= num
            formula += '-' + str(num)
        else:
            result += num
            formula += '+' + str(num)
    formula += '=' + str(result)
    if result == 7:
        return formula
    return None

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

bits_list = []
for i in range(8):
    bits = []
    for j in range(2, -1, -1):
        bit = (i >> j) & 1
        bits.append(bit)
    bits_list.append(bits)

for bits in bits_list:
    result = calc_bits(nums, bits)
    if result:
        print(result)
        break

Solution (Python):
from itertools import product
a,b,c,d=list(input())
for o,p,q in product("-+",repeat=3):
    if eval(a+o+b+p+c+q+d)==7:
        print(a+o+b+p+c+q+d+"=7")
        break

Solution (Python):
from operator import sub, add
from itertools import product

a, b, c, d = map(int, input())

for op1, op2, op3 in product([sub, add], repeat=3):
    if op3(op2(op1(a, b), c), d) == 7:
        o, p, q = map(lambda op: "+" if op == add else "-", [op1, op2, op3])
        print(a, o, b, p, c, q, d, "=7", sep="")
        exit()

Solution (Python):
from operator import sub, add
from itertools import product

a, b, c, d = map(int, input())

for op1, op2, op3 in product([sub, add], repeat=3):
    if op3(op2(op1(a, b), c), d) == 7:
        mark = lambda op: "+" if op == add else "-" 
        print(a, mark(op1), b, mark(op2), c, mark(op3), d, "=7", sep="")
        exit()

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

for op1 in ["+", "-"]:
    for op2 in ["+", "-"]:
        for op3 in ["+", "-"]:
            tmp = 0
            if op1 == "+":
                tmp = ABCD[0] + ABCD[1]
            else:
                tmp = ABCD[0] - ABCD[1]
            if op2 == "+":
                tmp += ABCD[2]
            else:
                tmp -= ABCD[2]
            if op3 == "+":
                tmp += ABCD[3]
            else:
                tmp -= ABCD[3]

            if tmp == 7:
                print(str(ABCD[0])+op1+str(ABCD[1])+op2+str(ABCD[2])+op3+str(ABCD[3])+"=7")
                quit()

Solution (Python):
import sys
from math import sqrt
from collections import Counter, defaultdict, deque

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


def LIN(n: int):
    return [I() for _ in range(n)]


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    abcd = input().rstrip()

    op = [""] * 3
    for i in range(2 ** 3):
        r = int(abcd[0])
        for j in range(3):
            if (i >> j) & 1:
                r += int(abcd[j + 1])
                op[j] = "+"
            else:
                r -= int(abcd[j + 1])
                op[j] = "-"
        if r == 7:
            ans = abcd[0]
            for j in range(3):
                ans += op[j] + abcd[j + 1]
            ans += "=7"
            print(ans)
            exit()


if __name__ == "__main__":
    main()

Solution (Python):
A,B,C,D = input('')
for i in range(2**3):
  op = [0] * 3
  for j in range(3):
    if (i >> j) & 1:
      op[j]='+'
    else:
      op[j]='-'
  if eval(A+op[0]+B+op[1]+C+op[2]+D)==7:
    print(A+op[0]+B+op[1]+C+op[2]+D+'=7')
    exit()

Solution (Python):
L = [int(i) for i in str(input())]
for i in range(2 ** 3):
    l = ['+'] * 3
    for j in range(3):
        if ((i >> j) & 1):
            l[j] = '-'
    s = L[0]
    for k in range(3):
        if l[k] == '+':
            s += L[k + 1]
        else:
            s -= L[k + 1]
    if s == 7:
        for m in range(3):
            print(str(L[m]) + str(l[m]), end='')
        print(str(L[3]) + '=7')
        exit()

Solution (Python):
s = input()

for i in range(2**3):
    t = int(s[0])
    for j in range(3):
        if (i>>j)&1:
            t += int(s[j+1])
        else:
            t -= int(s[j+1])
    if t == 7:
        x = i
        break
print(s[0],end="")
for k in range(3):
    if (x>>k)&1:
        print("+",end="")
    else:
        print("-",end="")
    print(s[k+1],end="")
print("=7")

Solution (Python):
s = list(input())
a = s[0]
b = s[1]
c = s[2]
d = s[3]
e = int(a)+int(b)+int(c)+int(d)
f = e - 7
if e == 7:
  print(a+'+'+b+'+'+c+'+'+d+'=7')
else:
  if int(b)*2 == f:
    print(a+'-'+b+'+'+c+'+'+d+'=7')
  elif int(c)*2 == f:
    print(a+'+'+b+'-'+c+'+'+d+'=7')
  elif int(d)*2 == f:
    print(a+'+'+b+'+'+c+'-'+d+'=7')
  elif (int(b)+int(c))*2 == f:
    print(a+'-'+b+'-'+c+'+'+d+'=7')
  elif (int(b)+int(d))*2 == f:
    print(a+'-'+b+'+'+c+'-'+d+'=7')
  elif (int(c)+int(d))*2 == f:
    print(a+'+'+b+'-'+c+'-'+d+'=7')
  elif (int(b)+int(c)+int(d))*2 == f:
    print(a+'-'+b+'-'+c+'-'+d+'=7')

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MAX = 10**18
MIN = -10**18
MOD = 998244353


def judge(li):
    c = int(s[0])
    for i in range(len(li)):
        if li[i] == "-":
            c -= int(s[i+1])
        else:
            c += int(s[i+1])
    return c
s = input()

n = len(s)-1
for i in range(2**n):
    li = ["+"]*n
    for j in range(n):
        if (i>>j)&1:
            li[n-j-1] = "-"
    if judge(li) == 7:
        ans = s[0]
        for i in range(len(li)):
            ans += li[i] + s[i+1]
        print(ans+"=7")
        sys.exit()

Solution (Python):
a,b,c,d=input()
for i in range(2**3):
    ls = ["+","+","+"]
    for j in range(3):
        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 = list(input())
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

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))
else:
  print('none')

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

for i in range(2**sukima):
  l = ['-']*sukima
  for j in range(sukima):
    if ((i >> j)&1):
      l[sukima-j-1] = '+'
  if eval(str(s[0]) + l[0] + str(s[1]) + l[1] +str(s[2]) + l[2] +str(s[3])) ==7:
    print(str(s[0]) + l[0] + str(s[1]) + l[1] +str(s[2]) + l[2] +str(s[3]) + '=7')
    exit()

Solution (Python):
from itertools import product

from operator import add, sub

numbers = tuple(int(c) for c in input())

operators = product((add, sub), repeat=3)


def opstr(op):
    if op == add:
        return '+'
    elif op == sub:
        return '-'


for op1, op2, op3 in operators:
    result = numbers[0]
    result = op1(result, numbers[1])
    result = op2(result, numbers[2])
    result = op3(result, numbers[3])

    if result == 7:
        print(str(numbers[0]) + opstr(op1) + str(numbers[1]) + opstr(op2) + str(numbers[2]) + opstr(op3) + str(numbers[3]) + '=7')
        break

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(str(A) + "+" + str(B) + "+" + str(C) + "+" + str(D) + "=7")
  exit()
if(A-B+C+D == 7):
  print(str(A) + "-" + str(B) + "+" + str(C) + "+" + str(D) + "=7")
  exit()
if(A+B-C+D == 7):
  print(str(A) + "+" + str(B) + "-" + str(C) + "+" + str(D) + "=7")
  exit()
if(A+B+C-D == 7):
  print(str(A) + "+" + str(B) + "+" + str(C) + "-" + str(D) + "=7")
  exit()
if(A-B-C+D == 7):
  print(str(A) + "-" + str(B) + "-" + str(C) + "+" + str(D) + "=7")
  exit()
if(A+B-C-D == 7):
  print(str(A) + "+" + str(B) + "-" + str(C) + "-" + str(D) + "=7")
  exit()
if(A-B+C-D == 7):
  print(str(A) + "-" + str(B) + "+" + str(C) + "-" + str(D) + "=7")
  exit()
if(A-B-C-D == 7):
  print(str(A) + "-" + str(B) + "-" + str(C) + "-" + str(D) + "=7")
  exit()

Solution (Python):


abcd=input()
n=[]
for i in range(4):
    n.append(int(abcd[i]))

for i in range(2**3):
    num=n[0]
    symbol=[]
    for j in range(3):
        if (i>>j)&1:
            num+=n[j+1]
            symbol.append("+")
        else:
            num-=n[j+1]
            symbol.append("-")
    if num==7:
        print("{0}{1}{2}{3}{4}{5}{6}=7".format(n[0],symbol[0],n[1],symbol[1],n[2],symbol[2],n[3]))
        exit()