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

Solution (Python):
A, B, C, D = input()
op = ['+', '-']
for op1 in op:
  for op2 in op:
    for op3 in op:
      s = A + op1 + B + op2 + C + op3 + D
      if eval(s) == 7:
        print(s + '=7')
        exit()

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

for i in range(2**n):
    S = s[0]
    for j in range(n):
        if ((i >> j) & 1):
            S += '+'
        else:
            S += '-'
        S += s[j+1]
        if len(S) == 7 and eval(S) == 7:
            print(S+'=7')
            exit()

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

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

Solution (Python):
x = input()
s = [int(i) for i in list(str(x))]
a, b, c, d = s

sm = 0
for i in range(2):
	for j in range(2):
		for k in range(2):
			a, b, c, d = s
			if(i == 0):
				b *= -1
			if(j == 0):
				c *= -1
			if(k == 0):
				d *= -1
			sm = a + b + c + d
			if(sm == 7):
				if(b >= 0):
					b = "+" + str(b)
				if(c >= 0):
					c = "+" + str(c)
				if(d >= 0):
					d = "+" + str(d)
				break
		else:
			continue
		break
	else:
		continue
	break
print (str(a) + str(b) + str(c) + str(d) + "=7")

Solution (Python):
nums = list(str(input()))
l = len(nums) - 1
for i in range(2**l):
    op = [""] * l
    res = ""
    for j in range(l):
        if (i >> j) & 1:
            op[j] = "+"
        else:
            op[j] = "-"
    for n, k in zip(nums, op+[""]):
        res += n + k
    ans = eval(res)
    if ans == 7:
        print(res + "=7")
        break

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

ops=['+', '-']
for o1 in ops:
   for o2 in ops:
       for o3 in ops:
           if eval(s[0] + o1 + s[1] + o2 + s[2] + o3 + s[3]) == 7:
                print(s[0] + o1 + s[1] + o2 + s[2] + o3 + s[3] + '=7')
                exit()

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[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


def main():
    ticket = list(input())

    op = [""] * 3

    for i in range(2):
        if i == 0:
            op[0] = "+"
        else:
            op[0] = "-"
        for j in range(2):
            if j == 0:
                op[1] = "+"
            else:
                op[1] = "-"
            for k in range(2):
                if k == 0:
                    op[2] = "+"
                else:
                    op[2] = "-"

                eq = ticket[0] + op[0] + ticket[1] + op[1] + ticket[2] + op[2] + ticket[3]
                
                
                

                if eval(eq) == 7:
                    print(eq+"=7")
                    sys.exit()


main()

Solution (Python):
import sys


ticket = list(input())

op = [0] * 3

for i in range(2):
    if i == 0:
        op[0] = "+"
    else:
        op[0] = "-"
    for j in range(2):
        if j == 0:
            op[1] = "+"
        else:
            op[1] = "-"
        for k in range(2):
            if k == 0:
                op[2] = "+"
            else:
                op[2] = "-"

            eq = ""
            for n in range(3):
                eq += ticket[n] + op[n]
            eq += ticket[-1]

            if eval(eq) == 7:
                print(eq+"=7")
                sys.exit()

Solution (Python):
from operator import add, sub
a, b, c, d = [int(n) for n in input().rstrip("\n")]

for i in range(2**3):
    if [add, sub][(i // 4) % 2]([add, sub][(i // 2) % 2]([add, sub][i % 2](a, b), c), d) == 7:
        print(str(a) + "+-"[i % 2] + str(b) + "+-"[(i // 2) % 2] + str(c) + "+-"[(i // 4) % 2] + str(d) + "=7")
        break

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

def dfs(i, f):

    if i == n-1:
        if eval(f)==7: 
            print(f+"=7")
            exit()
        else: 
            return False
    else:
        dfs(i+1,f + "+" + s[i+1])
        dfs(i+1,f + "-" + s[i+1])
    
def main():
    if dfs(0,s[0]):
        exit()

if __name__ == '__main__':
    main()

Solution (Python):
S = str(input())
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):
tmp = int(input())
d = tmp % 10
tmp //= 10
c = tmp % 10
tmp //= 10
b = tmp % 10
tmp //= 10
a = tmp


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

Solution (Python):
def main():
    S = input()
    x = []
    op = ['+', '-']
    for i in range(2):
        for j in range(2):
            for k in range(2):
                s = op[i] + op[j] + op[k]
                x.append(s)
    
    for xi in x:
        st = S[0] + xi[0] + S[1] + xi[1] + S[2] + xi[2] + S[3]
        ans = eval(st)
        
        if ans == 7:
            print(st+'=7')
            break

if __name__ == "__main__":
    main()

Solution (Python):
ABCD=list(map(int,list(str(input()))))
for i in range(2**3):
    value=ABCD[0]
    for s,m in enumerate("0"*(3-len(bin(i)[2:]))+(bin(i)[2:])):
        if m=="0":value+=ABCD[s+1]
        else:value-=ABCD[s+1]
    if value==7:
        printdata=""
        for s,m in zip(ABCD,"0"*(3-len(bin(i)[2:]))+(bin(i)[2:])):
            printdata+=str(s)
            printdata+="+" if m=="0" else "-"
        printdata+=str(ABCD[-1])+"=7"
        print(printdata)
        break

Solution (Python):
abcd = input()
symbol = ["+", "-"]
list_cand = [(i, j, k) for i in symbol for j in symbol for k in symbol]
for cand in list_cand:
  temp_str = abcd[0] + cand[0] + abcd[1] + cand[1] + abcd[2] + cand[2] + abcd[3]
  if eval(temp_str) == 7:
    print(temp_str + "=7")
    exit()

Solution (Python):
import itertools
abcd = input()
symbol = ["+", "-"]
list_cand = [(i, j, k) for i in symbol for j in symbol for k in symbol]
for cand in list_cand:
  temp_str = abcd[0] + cand[0] + abcd[1] + cand[1] + abcd[2] + cand[2] + abcd[3]
  if eval(temp_str) == 7:
    print(temp_str + "=7")
    exit()

Solution (Python):
import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    a,b,c,d=map(int,list(input()))
    for i in range(2):
        ans=str(a)
        if i: ans+='-'
        else: ans+='+'
        ans+=str(b)
        for j in range(2):
            if j: 
                ans=ans[:-2]
                ans+='-'
            else: ans+='+'
            ans+=str(c)
            for k in range(2):
                if k: ans+='-'
                else: ans+='+'
                ans+=str(d)
                if eval(ans)==7:
                    print(ans+'=7')
                    exit()
                else: ans=ans[:-2]


if __name__ == "__main__":
    main()

Solution (Python):
N=str(input())
a=int(N[0])
b=int(N[1])
c=int(N[2])
d=int(N[3])
for i in range(2):
  for j in range(2):
    for k in range(2):
      t=a
      if i==0:
        t+=b
      else:
        t-=b
        
      if j==0:
        t+=c
      else:
        t-=c
        
      if k==0:
        t+=d
      else:
        t-=d
        
      if t==7:
        print("{}{}{}{}{}{}{}=7".format(a,"+-"[i],b,"+-"[j],c,"+-"[k],d))
        exit()

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


for i in range(1 << 3):
    info = [abcd[0]]
    for j in range(3):
        if (i >> j) & 1:
            info.append(-1*(abcd[j + 1]))
        else:
            info.append((abcd[j + 1]))
    if sum(info) == 7:
        p = str(abcd[0])
        for m in range(1, 4):
            if info[m] >= 0:
                p += ("+"+str(info[m]))
            else:
                p += (str(info[m]))
        print(p+"=7")
        exit()

Solution (Python):
a = list(input())
b = ['+', '-']

for x in range(2):
    if x % 2 == 0:
        q = int(a[1])
    else:
        q = -int(a[1])
    for y in range(2):
        if y % 2 == 0:
            w = int(a[2])
        else:
            w = -int(a[2])
        for z in range(2):
            if z % 2 == 0:
                e = int(a[3])
            else:
                e = -int(a[3])
            if int(a[0]) + q + w + e == 7:
                print(a[0],b[x],a[1],b[y],a[2],b[z],a[3],'=7', sep='')
                exit()

Solution (Python):
s = input()
total = int(s[0])

op = ['+', '-']
for i in op:
    for j in op:
        for k in op:
            cmd = s[0] + i + s[1] + j + s[2] + k + s[3]
            if eval(cmd) == 7:
                print(cmd + "=7")
                exit()

Solution (Python):
*x, = map(int, list(input()))
digit = 3
for i in range(2**digit):
    res = x[0]
    arr = str(x[0])
    for j in range(digit):
        if (i>>j) & 1:
            res += x[j + 1]
            arr += '+' + str(x[j + 1])
        else:
            res -= x[j + 1]
            arr += '-' + str(x[j + 1])
    if res == 7:
        print(arr + '=7')
        break

Solution (Python):
import sys
import math

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

Solution (Python):
a, b, c, d = map(str, list(input()))
op = ['+', '-']
eval_ary = []
for i in range(2):
    for j in range(2):
        for k in range(2):
            eval_ary.append(a+op[i]+b+op[j]+c+op[k]+d)
for test in eval_ary:
    if eval(test) == 7:
        print(test+'=7')
        break

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

        if eval(sum) == k:
            print(sum+"=7")
        return eval(sum) == k
    
    if dfs(i + 1, sum + "-" +  s[i+1],n,s,k):
        return True
    
    
    if dfs(i + 1, sum + "+" + s[i+1],n,s,k):
        return True

    return False

def main():
    s = input()
    n = len(s)
    k = 7

    if dfs(0, s[0], n, s,k):
        pass
    else:
        pass
if __name__ == '__main__':
    main()

Solution (Python):
from itertools import product

n = input()
ops = product('+-', repeat=3)

for op in ops:
    fm = n[0] + op[0] + n[1] + op[1] + n[2] + op[2] + n[3]
    if eval(fm) == 7:
        print(fm + '=7')
        break

Solution (Python):
s = input()
for i1 in ["+","-"]:
  for i2 in ["+","-"]:
    for i3 in ["+","-"]:
      text = s[0] + i1 + s[1] + i2 + s[2] + i3 + s[3]
      if(eval(text) == 7):
        print(text+"=7")
        exit()

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

Solution (Python):

import sys
s = input()
a = []

for i in range(len(s)):
    num = int(s[i])
    a.append(num)


op = ['+', '-']

for i in range(2):
    for j in range(2):
        for k in range(2):
            temp = 0
            if op[i] == '+':
                temp = a[0] + a[1]
            else:
                temp = a[0] - a[1]
            if op[j] == '+':
                temp += a[2]
            else:
                temp -= a[2]
            if op[k] == '+':
                temp += a[3]
            else:
                temp -= a[3]

            if temp == 7:
                n1, n2, n3, n4 = map(str, [a[0], a[1], a[2], a[3]])
                
                print(n1 + op[i] + n2 + op[j] + n3 + op[k] + n4 + '=7')
                sys.exit()

Solution (Python):
s = input()
op1 = ['+', '-']
op2 = ['+', '-']
op3 = ['+', '-']

for o1 in op1:
    for o2 in op2:
        for o3 in op3:
            f = s[0] + o1 + s[1] + o2 + s[2] + o3 + s[3]
            if eval(f) == 7:
                print(f+"=7")
                exit()

Solution (Python):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

ABCD = [int(_) for _ in ns().strip()]

for i in range(8):
    t = ABCD[0]
    
    for j in range(3):
        if i>>j&1:
            t += ABCD[j+1]
        else:
            t -= ABCD[j+1]
  
    if t == 7:
        print("{}{}{}{}{}{}{}=7".format(
            ABCD[0], "+" if i>>0&1 else "-",
            ABCD[1], "+" if i >> 1 & 1 else "-",
            ABCD[2], "+" if i >> 2 & 1 else "-",
            ABCD[3],         
        ))
        break

Solution (Python):
A,B,C,D=input()
op=['+++','++-','+-+','-++','+--','-+-','--+','---']
for op1,op2,op3 in op:
    ex=A+op1+B+op2+C+op3+D
    if eval(ex)==7:
        break
print(ex+'=7')

Solution (Python):
def test():
    s = list(input())
    a = len(s) - 1
    for i in range(2**a):
        op = ["-"]*a
        for j in range(a):
            if (i>>j)&1:
                op[j] = "+"
        ans = ""
        for n,k in zip(s,op+[""]):
            ans += n + k
        if eval(ans) == 7:
            print(ans+"=7")
            return


if __name__ == "__main__":
    test()

Solution (Python):
def op(bit):
    if bit:
        return '+'
    else:
        return '-'


def main():
    string = input()
    nbs = list(string)

    for i in range(2**3):
        temp_string = nbs[0] + op(i % 2) + nbs[1] + op((i >> 1) % 2) \
                    + nbs[2] + op((i >> 2) % 2) + nbs[3]
        result = eval(temp_string)
        if result == 7:
            print(temp_string + '=7')
            return


if __name__ == '__main__':
    main()

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


import itertools
li = list(itertools.product({0, 1}, repeat=n))
for i in range(len(li)):
    total = int(s[0])
    shiki = s[0]
    for j in range(n):
        if li[i][j] == 0:
            total += int(s[j+1])
            shiki += "+"+s[j+1]
        else:
            total -= int(s[j+1])
            shiki += "-"+s[j+1]
    if total == 7:
        shiki += "="+str(7)
        print(shiki)
        break
    else:
        pass

Solution (Python):
S = input()
for i in range(2 ** len(S) - 1):
    work = S
    for j in range(1 ,len(S)):
        if i >> (j - 1) & 1:
            work = work[:2 * j - 1] + "+" + work[2 * j - 1:]
        else:
            work = work[:2 * j - 1] + "-" + work[2 * j - 1:]
    if eval(work) == 7:
        print("{0}=7".format(work))
        exit()

Solution (Python):
E = input()
N = len(E)
ans = ""

for i in range(2**(N-1)):
    bi = bin(i)[2:].zfill(N-1)
    op = ["-"] * (N-1)
    for j, b in enumerate(bi):
        if b == "1":
            op[j] = "+"
    su = E[0]
    for o, e in zip(op, E[1:]):
        su += o + e
    if eval(su) == 7:
        ans = su + "=7"
        break

print(ans)

Solution (Python):
A,B,C,D = map(str,input())
op = ["+","-"]
for i in op:
    for j in op:
        for k in op:
            S = A + i + B + j + C + k + D
            if eval(S) == 7:
                print(S + "=7")
                exit()

Solution (Python):
S = input()
ans = 0
for i in range(2 ** 3):
    tmp = int(S[0])
    tmp2 = ''
    for k in range(3):
        if 1 & i>>k:
            tmp += int(S[k+1])
            tmp2 += '+' + S[k+1]
        else:
            tmp -= int(S[k+1])
            tmp2 += '-' + S[k+1]
    tmp2 = S[0] + tmp2 + '=7'
    if tmp == 7:
        print(tmp2)
        exit()

Solution (Python):
N = list(input())
N = [int(i) for i in N]
for i in range(2**3):
    cur = bin(i)[2::].zfill(3)
    c = N[0]
    n = []
    for i in range(3):
        if cur[i]=='0':
            n.append('+')
            c += N[i+1]
        else:
            n.append('-')
            c -= N[i+1]
    if c==7:
        m = '='
        print(N[0],n[0],N[1],n[1],N[2],n[2],N[3],m,c,sep=(''))
        break

Solution (Python):
abcd = input()

op = ['+', '-']

for op1 in op:
    for op2 in op:
        for op3 in op:
            tmp_ans = abcd[0] + op1 + abcd[1] + op2 + abcd[2] + op3 + abcd[3]
            if eval(tmp_ans) == 7:
                print(tmp_ans+'=7')
                exit()

Solution (Python):

import sys
import itertools

def solve(ABCD: str):
    A, B, C, D = map(int,ABCD)
    bit_list = list(itertools.product(["+","-"], repeat=3))
    for bit in bit_list:
        a=A
        if bit[0] == "+":
            a+=B
        else:
            a-=B        
        if bit[1] == "+":
            a+=C
        else:
            a-=C        
        if bit[2] == "+":
            a+=D
        else:
            a-=D    
        if a == 7:
            print("{}{}{}{}{}{}{}=7".format(A,bit[0],B,bit[1],C,bit[2],D))
            break 

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    ABCD = next(tokens)  
    solve(ABCD)

if __name__ == '__main__':
    main()

Solution (Python):
s=input()
n=4
for i in range(2 ** (n-1)):
  x=str(format(i,'b').zfill(3))
  a=[]
  res=int(s[0])
  for j in range(n-1):
    if x[j]=='1':
      res+=int(s[j+1])
      a.append('+')
    else:
      res-=int(s[j+1])
      a.append('-')
  if res==7:
    ans=s[0]+a[0]+s[1]+a[1]+s[2]+a[2]+s[3]+'=7'
    break
print(ans)

Solution (Python):


def C_pre():
    t = input()
    a,b,c,d = list(map(int,[t[0],t[1],t[2],t[3]]))
    for j in (1,-1):
        for k in (1,-1):
            for l in (1,-1):
                if a+j*b+k*c+l*d == 7:
                    r = "".join(list(map(str,[j,k,l]))).replace("-1","-").replace("1","+")
                    return a,b,c,d,r
def C():
    a,b,c,d,r = C_pre()
    print(str(a)+r[0]+str(b)+r[1]+str(c)+r[2]+str(d)+"=7")
if __name__ == '__main__':
    C()

Solution (Python):
import numpy as np
import itertools

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

for item in list(itertools.product((1,-1),repeat=3)):
  if l[0]+np.dot(item,l[1:])==7:
    break
olist=["+" if o==1 else "-" for o in item]

result = [None]*(len(l)+len(olist))
result[::2] = list(map(str,l))
result[1::2] = olist
print("".join(result)+"=7")

Solution (Python):
n = input()
a = int(n[0])
b = int(n[1])
c = int(n[2])
d = int(n[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")
else:
  print(str(a)+"-"+str(b)+"-"+str(c)+"-"+str(d)+"=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')
        exit()

Solution (Python):
N = 3
x = []

S = str(input())

def loop(x):
	if x == []: 
		return [[0],[1]]
	
	li = []
	for i in range(len(x)):
		li.append(x[i] + [0])
		li.append(x[i] + [1])
	return li
		
		
		
for i in range(N):
	x = loop(x)

for i in x:
	total = int(S[0])
	for j in range(len(i)):
		if i[j] == 0:
			total += int(S[j+1])
		else:
			total -= int(S[j+1])
	
	
	if total == 7:
		sentence = ''
		for j in range(len(S)-1):
			sentence += S[j] 
			
			if i[j] == 0:
				sentence += '+'
			else:
				sentence += '-'
		
		
		sentence += S[3] + '=7'
		print(sentence)
		break

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

for i in range(8):
  bi=bin(i)[2:].zfill(3)
  temp=[]
  for j in range(3):
    if bi[j]=="0":
      temp.append("-")
    else:
      temp.append("+")
  ans=""
  for j,k in zip(x,temp):
    ans+=j+k
  ans+=d
  if eval(ans)==7:
    print(ans+"=7")
    exit()

Solution (Python):
s_ori = input()
s = [int(c) for c in s_ori]
n = len(s) - 1
for bit in range(2**n):
    total = s[0]
    for i in range(n):
        if (1 << i) & bit:
            total += s[i+1]
        else:
            total -= s[i+1]
    if total == 7:
        break

ans = ''
for i in range(n):
    if bit & (1<<i):
        ans += s_ori[i] + '+'
    else:
        ans += s_ori[i] + '-'

ans += s_ori[-1] + '=7'

print(ans)

Solution (Python):
s = input()

num = [0,0,0,0]
num[0], num[1], num[2], num[3] = map(int,(s[0], s[1], s[2], s[3]))

def ope(x):
	if x == 1:
		return '+'
	elif x == 0:
		return '-'
for i in range(8):
	tmp = num[0]
	for j in range(3):
		if (i>>j) & 1:
			tmp += num[j+1]
		else:
			tmp -= num[j+1]
	if tmp == 7:
		print(s[0]+ope(i&1)+s[1]+ope((i>>1)&1)+s[2]+ope((i>>2)&1)+s[3]+'=7')
		break

Solution (Python):
s = input()
li = list(map(int,list(s)))

for i in range(8):
  tmp = list(map(int,list(format(i,"03b"))))
  tmp7 = li[0]
  for j in range(3):
    if tmp[j] == 0:
      tmp7 += li[j+1]
    else:
      tmp7 -= li[j+1]
  if tmp7 == 7:
    ans = str(li[0])
    if tmp[0] == 0:
      ans += "+"
    else:
      ans += "-"
    ans += str(li[1])
    if tmp[1] == 0:
      ans += "+"
    else:
      ans += "-"
    ans += str(li[2])
    if tmp[2] == 0:
      ans += "+"
    else:
      ans += "-"
    ans += str(li[3])
    ans += "=7"
    print(ans)
    exit()

Solution (Python):

def search7(i, ticket, equation):
    if i == len(ticket) - 1:
        if eval(equation) == 7:
            return True, equation
        else:
            return False, '_'
    else:
        check_param, new_equation = search7(i + 1, ticket, equation + '+' + ticket[i + 1])
        if check_param:
            return True, new_equation
        check_param, new_equation = search7(i + 1, ticket, equation + '-' + ticket[i + 1])
        if check_param:
            return True, new_equation
        
        return False, '_'


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


def main():
    import math
    import collections
    import itertools

    ticket = list(input())

    _, equation = search7(0, ticket, ticket[0])
    print(equation+'=7')


if __name__ == '__main__':
    main()

Solution (Python):
s = input()
 
for bit in range(1 << 3):
  answer = int(s[0])
  f = s[0] 
  
  for i in range(3):
    if bit & (1 << i):
      f+='+'
      answer+=int(s[i+1])
    else:
      f+='-'
      answer-=int(s[i+1])
    f+=s[i+1]
 
  if answer==7:
    print(f + '=7')
    exit()

Solution (Python):
num = list(str(input()))
n = len(num)
for i in range(1 << 3):
    li = [int(num[0])]
    pri = [num[0]]
    for j in range(n - 1):
        if (i >> j) & 1:
            li.append(int(num[j + 1]))
            pri.append("+"+num[j + 1])
        else:
            li.append(-1 * int(num[j + 1]))
            pri.append("-"+num[j + 1])
    if sum(li) == 7:
        print("{}{}{}{}=7".format(pri[0], pri[1], pri[2], pri[3]))
        quit()

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")
        exit()

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

elif A+B-C-D==7:
  print(li[0]+'+'+li[1]+'-'+li[2]+'-'+li[3]+'=7')

elif A-B+C+D==7:
  print(li[0]+'-'+li[1]+'+'+li[2]+'+'+li[3]+'=7')
  
elif A-B+C-D==7:
  print(li[0]+'-'+li[1]+'+'+li[2]+'-'+li[3]+'=7')
  
elif A-B-C+D==7:
  print(li[0]+'-'+li[1]+'-'+li[2]+'+'+li[3]+'=7')

elif A-B-C-D==7:
  print(li[0]+'-'+li[1]+'-'+li[2]+'-'+li[3]+'=7')

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

elif A+B-C-D==7:
  print(li[0]+'+'+li[1]+'-'+li[2]+'-'+li[3]+'=7')

elif A-B+C+D==7:
  print(li[0]+'-'+li[1]+'+'+li[2]+'+'+li[3]+'=7')
  
elif A-B+C-D==7:
  print(li[0]+'-'+li[1]+'+'+li[2]+'-'+li[3]+'=7')
  
elif A-B-C+D==7:
  print(li[0]+'-'+li[1]+'-'+li[2]+'+'+li[3]+'=7')

elif A-B-C-D==7:
  print(li[0]+'-'+li[1]+'-'+li[2]+'-'+li[3]+'=7')

Solution (Python):
a, b, c, d = map(int, list(input()))
for i in range(8):
    ans = a
    tb = b
    tc = c
    td = d
    op = format(i, "b").zfill(3)
    if op[0] == "1":
        tb = -tb
    if op[1] == "1":
        tc = -tc
    if op[2] == "1":
        td = -td
    ans += tb + tc + td
    if ans == 7:
        break
op = op.replace("0", "+").replace("1", "-") + "_"
s = ""
for n, o in zip([a, b, c, d], op):
    s += str(n) + o
print(s[:-1] + "=7")

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 = list(str(input()))

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

Solution (Python):

S=input()
sign="+-"
for i in range(2):
  for j in range(2):
    for n in range(2):
      if eval(S[0]+sign[i]+S[1]+sign[j]+S[2]+sign[n]+S[3])==7:
        print(str(S[0]+sign[i]+S[1]+sign[j]+S[2]+sign[n]+S[3])+'=7')
        exit()

Solution (Python):

X=list(input())
A,B,C,D=map(int,X)
if A+B+C+D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+'+'+B+'+'+C+'+'+D+'=7')
  exit()
elif A+B+C-D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+'+'+B+'+'+C+'-'+D+'=7')
  exit()
elif A+B-C+D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+'+'+B+'-'+C+'+'+D+'=7')
  exit()
elif A-B+C+D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+'-'+B+'+'+C+'+'+D+'=7')
  exit()
elif A-B-C+D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+'-'+B+'-'+C+'+'+D+'=7')
  exit()
elif A+B-C-D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+'+'+B+'-'+C+'-'+D+'=7')
  exit()
elif A-B+C-D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+'-'+B+'+'+C+'-'+D+'=7')
  exit()
elif A-B-C-D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+'-'+B+'-'+C+'-'+D+'=7')
  exit()
else:
  print('None')

Solution (Python):
def c():
    li = list(input())
    syms = ['+', '-']
    calc = li[0]
    for i in range(2):
        i_calc = calc
        calc += syms[i] + li[1]
        for j in range(2):
            j_calc = calc
            calc += syms[j] + li[2]
            for k in range(2):
                k_calc = calc
                calc += syms[k] + li[3]
                res = eval(calc)
                if res == 7:
                    print(calc+"=7")
                    return
                calc = k_calc
            calc = j_calc
        calc = i_calc


if __name__ == '__main__':
    c()

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

if A + B + C + D == 7:
    print("{}+{}+{}+{}=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()
val_l = [int(S[0]),int(S[1]),int(S[2]),int(S[3])]
l = len(S)

def main():
  for i in range(1<<l-1):
    ans = 0
    opp=""
    ans_l =[0,0,0,0]
    for j in range(l):
      if j==l-1:
        ans += val_l[l-j-1]
        opp = "+"+opp
      elif (i>>j)&1:
        ans += val_l[l-j-1]
        opp = "+"+opp
      else:
        ans -= val_l[l-j-1]
        opp = "-"+opp
      ans_l[l-j-1] = S[l-j-1]
    if ans == 7:
      print(S[0]+opp[1]+S[1]+opp[2]+S[2]+opp[3]+S[3]+"=7")
      return
if __name__ == "__main__":
  main()

Solution (Python):
S = input()
s = []
for i in range(4):
    s.append(int(S[i]))
op0 = '+'
op1 = '-'
if s[0] + s[1] + s[2] + s[3] == 7:
    print('{}{}{}{}{}{}{}=7'.format(s[0], op0, s[1], op0, s[2], op0, s[3]))
elif s[0] + s[1] + s[2] - s[3] == 7:
    print('{}{}{}{}{}{}{}=7'.format(s[0], op0, s[1], op0, s[2], op1, s[3]))
elif s[0] + s[1] - s[2] + s[3] == 7:
    print('{}{}{}{}{}{}{}=7'.format(s[0], op0, s[1], op1, s[2], op0, s[3]))
elif s[0] + s[1] - s[2] - s[3] == 7:
    print('{}{}{}{}{}{}{}=7'.format(s[0], op0, s[1], op1, s[2], op1, s[3]))
elif s[0] - s[1] + s[2] + s[3] == 7:
    print('{}{}{}{}{}{}{}=7'.format(s[0], op1, s[1], op0, s[2], op0, s[3]))
elif s[0] - s[1] + s[2] - s[3] == 7:
    print('{}{}{}{}{}{}{}=7'.format(s[0], op1, s[1], op0, s[2], op1, s[3]))
elif s[0] - s[1] - s[2] + s[3] == 7:
    print('{}{}{}{}{}{}{}=7'.format(s[0], op1, s[1], op1, s[2], op0, s[3]))
elif s[0] - s[1] - s[2] - s[3] == 7:
    print('{}{}{}{}{}{}{}=7'.format(s[0], op1, s[1], op1, s[2], op1, s[3]))