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()
a,b,c,d=int(N[0]),int(N[1]),int(N[2]),int(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))

Solution (Python):
ABCD = list(map(int, list(input())))
ans = ['']*9
for i in range(4):
    ans[i*2] = str(ABCD[i])
for i in range(2**3):
    ret = ABCD[0]
    for j in range(3):
        if (i >> j) % 2 == 1:
            ret += ABCD[j+1]
            ans[j*2 + 1] = '+'
        else:
            ret -= ABCD[j+1]
            ans[j*2 + 1] = '-'
    if ret == 7:
        ans[7] = '='
        ans[8] = '7'
        print(''.join(ans))
        exit(0)

Solution (Python):
def calc(a,b,f):
    a=int(a)
    b=int(b)
    if f==0:
        return a+b
    else:
        return a-b

s=input()
op=[0]*3
for i in range(2):
    a=calc(s[0],s[1],i)
    for j in range(2):
        b=calc(a,s[2],j)
        for k in range(2):
            c=calc(b,s[3],k)
            if c==7:
                ret=[i,j,k]               
for i in range(3):
    if ret[i]==0:
        ret[i]="+"
    else:
        ret[i]="-"
for i in range(3):
    print(s[i]+ret[i],sep="",end="")
print(s[3]+"=7")

Solution (Python):
ABCD=input()
answer=[ABCD[0],"-",ABCD[1],"-",ABCD[2],"-",ABCD[3]]
for i in range(8):
    pat=str(bin(i))[2:].rjust(3,"0")
    sum=int(ABCD[0])
    for j in range(3):
        if pat[j]=="0":
            sum-=int(ABCD[j+1])
            answer[2*j+1]="-"
        else:
            sum+=int(ABCD[j+1])
            answer[2*j+1]="+"
    if sum==7:
        print("".join(map(str,answer))+"=7")
        break

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(s[0]+"+"+s[1]+"+"+s[2]+"+"+s[3]+"=7")

elif a+b+c-d == 7:
    print(s[0]+"+"+s[1]+"+"+s[2]+"-"+s[3]+"=7")
elif a+b-c+d == 7:
    print(s[0]+"+"+s[1]+"-"+s[2]+"+"+s[3]+"=7")
elif a+b-c-d == 7:
    print(s[0]+"+"+s[1]+"-"+s[2]+"-"+s[3]+"=7")
elif a-b+c+d == 7:
    print(s[0]+"-"+s[1]+"+"+s[2]+"+"+s[3]+"=7")
elif a-b+c-d == 7:
    print(s[0]+"-"+s[1]+"+"+s[2]+"-"+s[3]+"=7")
elif a-b-c+d == 7:
    print(s[0]+"-"+s[1]+"-"+s[2]+"+"+s[3]+"=7")
elif a-b-c-d == 7:
    print(s[0]+"-"+s[1]+"-"+s[2]+"-"+s[3]+"=7")

Solution (Python):
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) 
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    


MOD = 10**9 + 7
INF = 2**31  

from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  


q, w, e, r = map(int, list(input()))

op = [1, -1]
ansls = ['+', '-']
for a, b, c in product(range(2), repeat=3):
    if q + op[a] * w + op[b] * e + op[c] * r == 7:
        ans = str(q) + ansls[a] + str(w) + \
            ansls[b] + str(e) + ansls[c] + str(r) + '=7'
        print(ans)
        exit()

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

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

r1 = ABCD[0] + ABCD[1] + ABCD[2] + ABCD[3]
r2 = ABCD[0] + ABCD[1] + ABCD[2] - ABCD[3]
r3 = ABCD[0] + ABCD[1] - ABCD[2] + ABCD[3]
r4 = ABCD[0] - ABCD[1] + ABCD[2] + ABCD[3]
r5 = ABCD[0] + ABCD[1] - ABCD[2] - ABCD[3]
r6 = ABCD[0] - ABCD[1] + ABCD[2] - ABCD[3]
r7 = ABCD[0] - ABCD[1] - ABCD[2] + ABCD[3]
r8 = ABCD[0] - ABCD[1] - ABCD[2] - ABCD[3]

if r1 == 7:
  a = str(ABCD[0]) + '+' + str(ABCD[1]) + '+' + str(ABCD[2]) + '+' + str(ABCD[3]) + '=7'
  print(a)
elif r2 == 7:
  a = str(ABCD[0]) + '+' + str(ABCD[1]) + '+' + str(ABCD[2]) + '-' + str(ABCD[3]) + '=7'
  print(a)
elif r3 == 7:
  a = str(ABCD[0]) + '+' + str(ABCD[1]) + '-' + str(ABCD[2]) + '+' + str(ABCD[3]) + '=7'
  print(a)
elif r4 == 7:
  a = str(ABCD[0]) + '-' + str(ABCD[1]) + '+' + str(ABCD[2]) + '+' + str(ABCD[3]) + '=7'
  print(a)
elif r5 == 7:
  a = str(ABCD[0]) + '+' + str(ABCD[1]) + '-' + str(ABCD[2]) + '-' + str(ABCD[3]) + '=7'
  print(a)
elif r6 == 7:
  a = str(ABCD[0]) + '-' + str(ABCD[1]) + '+' + str(ABCD[2]) + '-' + str(ABCD[3]) + '=7'
  print(a)
elif r7 == 7:
  a = str(ABCD[0]) + '-' + str(ABCD[1]) + '-' + str(ABCD[2]) + '+' + str(ABCD[3]) + '=7'
  print(a)
elif r8 == 7:
  a = str(ABCD[0]) + '-' + str(ABCD[1]) + '-' + str(ABCD[2]) + '-' + str(ABCD[3]) + '=7'
  print(a)

Solution (Python):
def convert(s): 
  
    
    new = "" 
  
    
    for x in s: 
        new += x  
  
    
    return new 
s=input()
a=int(s[0])
b=int(s[1])
c=int(s[2])
d=int(s[3])
ans=[]
if a+b+c+d==7:
  ans.append(str(a))
  ans.append('+')
  ans.append(str(b))
  ans.append('+')
  ans.append(str(c))
  ans.append('+')
  ans.append(str(d))
  ans.append('=7')
  print(convert(ans))
elif a+b+c-d==7:
  ans.append(str(a))
  ans.append('+')
  ans.append(str(b))
  ans.append('+')
  ans.append(str(c))
  ans.append('-')
  ans.append(str(d))
  ans.append('=7')
  print(convert(ans))
elif a+b-c+d==7:
  ans.append(str(a))
  ans.append('+')
  ans.append(str(b))
  ans.append('-')
  ans.append(str(c))
  ans.append('+')
  ans.append(str(d))
  ans.append('=7')
  print(convert(ans))
elif a+b-c-d==7:
  ans.append(str(a))
  ans.append('+')
  ans.append(str(b))
  ans.append('-')
  ans.append(str(c))
  ans.append('-')
  ans.append(str(d))
  ans.append('=7')
  print(convert(ans))
elif a-b+c+d==7:
  ans.append(str(a))
  ans.append('-')
  ans.append(str(b))
  ans.append('+')
  ans.append(str(c))
  ans.append('+')
  ans.append(str(d))
  ans.append('=7')
  print(convert(ans))
elif a-b+c-d==7:
  ans.append(str(a))
  ans.append('-')
  ans.append(str(b))
  ans.append('+')
  ans.append(str(c))
  ans.append('-')
  ans.append(str(d))
  ans.append('=7')
  print(convert(ans))
elif a-b-c+d==7:
  ans.append(str(a))
  ans.append('-')
  ans.append(str(b))
  ans.append('-')
  ans.append(str(c))
  ans.append('+')
  ans.append(str(d))
  ans.append('=7')
  print(convert(ans))
elif a-b-c-d==7:
  ans.append(str(a))
  ans.append('-')
  ans.append(str(b))
  ans.append('-')
  ans.append(str(c))
  ans.append('-')
  ans.append(str(d))
  ans.append('=7')
  print(convert(ans))

Solution (Python):
def resolve():
  a, b, c, d = input()
  for i in range(8):
    q = str(a)
    if (i>>0) & 1:
      q += '+'
    else:
      q += '-'
    q += str(b)
    if (i>>1) & 1:
      q += '+'
    else:
      q += '-'
    q += str(c)
    if (i>>2) & 1:
      q += '+'
    else:
      q += '-'
    q += str(d)

    if eval(q) == 7:
      q += '=7'
      print(q)
      return

  return

if __name__ == "__main__":
  resolve()

Solution (Python):
from itertools import product
x = list(input())
for v in list(product(["+","-"], repeat=3)):
    ans = x[0]+v[0]+x[1]+v[1]+x[2]+v[2]+x[3]
    if eval(ans) == 7:break
print("".join(ans)+"=7")

Solution (Python):
def main():
    abcd = list(input())
    can_break = False
    for i in range(8):
        if can_break:
            break
        p = [""] * 3
        for j in range(3):
            if (i >> j) & 1:
                p[j] = "+"
            else:
                p[j] = "-"
        now = abcd[0] + p[0] + abcd[1] + p[1] + abcd[2] + p[2] + abcd[3]
        if eval(now) == 7:
            print(now + "=7")
            can_break = True
            break


if __name__ == '__main__':
    main()

Solution (Python):
a, b, c, d = map(int, tuple(input()))
if a+b+c+d == 7:
    print('{}+{}+{}+{}=7'.format(a, b, c, d))
elif a+b+c-d == 7:
    print('{}+{}+{}-{}=7'.format(a, b, c, d))
elif a+b-c+d == 7:
    print('{}+{}-{}+{}=7'.format(a, b, c, d))
elif a+b-c-d == 7:
    print('{}+{}-{}-{}=7'.format(a, b, c, d))
elif a-b+c+d == 7:
    print('{}-{}+{}+{}=7'.format(a, b, c, d))
elif a-b+c-d == 7:
    print('{}-{}+{}-{}=7'.format(a, b, c, d))
elif a-b-c+d == 7:
    print('{}-{}-{}+{}=7'.format(a, b, c, d))
elif a-b-c-d == 7:
    print('{}-{}-{}-{}=7'.format(a, b, c, d))

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

Solution (Python):
from itertools import product
S = list(input())
T = list(map(int, S))

for p in product([-1, 1], repeat=3):
    tmp = T[0]
    for i, s in zip(p, T[1:]):
        tmp += i * s
    if tmp == 7:
        break

ans = S[0]
for i, s in zip(p, S[1:]):
    q = "+" if i == 1 else "-"
    ans += q
    ans += s
ans += "=7"
print(ans)

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

for i in range(2 ** 3):
    cal = int(s[0])
    temp_s = s[0]
    for j in range(3):
        if (i >> j)&1:
            cal += int(s[j + 1])
            temp_s += '+' + s[j + 1]
        else:
            cal -= int(s[j + 1])
            temp_s += '-' + s[j + 1]

    if cal == 7:
        print(temp_s + '=7')
        exit()

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

Solution (Python):
A = input()
a, b, c, d = A[0], A[1], A[2], A[3]
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):
from itertools import product
A,B,C,D = list(input().strip())
for x in product(("+","-"),repeat=3):
    a1,a2,a3 = x
    if eval(A+a1+B+a2+C+a3+D)==7:
        print(A+a1+B+a2+C+a3+D+"=7")
        break

Solution (Python):
s = input()
op = ['+', '-']
for i in range(2):
    for j in range(2):
        for k in range(2):
            t = ''.join([s[0], op[i], s[1], op[j], s[2], op[k], s[3]])
            if eval(t) == 7:
                print(t + '=7')
                quit()

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S=ST()
    for i in range(1<<3):
        now = int(S[0])
        ans = S[0]
        for j in range(3):
            if(i>>j&1):
                now -= int(S[j+1])
                ans+="-"
            else:
                now += int(S[j+1])
                ans+="+"
            ans += S[j+1] 
        if(now==7):
            print(ans+"=7")
            return
if __name__ == '__main__':
    main()

Solution (Python):
def main():
    S = input()
    for bit in range(1 << 3):
        ans = int(S[0])
        T = S[0]
        for i in range(3):
            if bit & (1 << i):
                ans += int(S[i+1])
                T += "+"+S[i+1]
            else:
                ans -= int(S[i+1])
                T += "-"+S[i+1]
        if ans == 7:
            return print(T+"=7")


if __name__ == '__main__':
    main()

Solution (Python):
import sys
inf = 10**15
mod = 10**9+7
s = input()
n = len(s)-1
for i in range(2**n):
    ans = int(s[0])
    acc = ans
    a = [s[0]]
    for j in range(n):
        if ((i >> j) & 1):  
            acc = int(s[j + 1])
            ans+=acc
            a.append('+')
            a.append(s[j+1])
        else:
            acc = int(s[j + 1])
            ans-=acc
            a.append('-')
            a.append(s[j+1])
    if ans == 7:
        a.append('=7')
        print(''.join(a))
        sys.exit()

Solution (Python):
def resolve():
    def main():
        s=input()
        for i in ['+','-']:
            for m in ['+','-']:
                for n in ['+','-']:
                    a=s[0]+i+s[1]+m+s[2]+n+s[3]
                    if eval(a)==7:
                        return a
    print(main(), '=7',sep='')
resolve()

Solution (Python):
def resolve():
    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(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')

resolve()

Solution (Python):
import sys
def resolve():
    s=input()
    ans=0
    for i in ['+','-']:
        for m in ['+','-']:
            for n in ['+','-']:
                if eval(s[0]+i+s[1]+m+s[2]+n+s[3])==7:
                    ans=s[0]+i+s[1]+m+s[2]+n+s[3]+'=7'
                    print(ans)
                    sys.exit()
resolve()

Solution (Python):
def resolve():
    s=input()
    ans=0
    for i in ['+','-']:
        for m in ['+','-']:
            for n in ['+','-']:
                if eval(s[0]+i+s[1]+m+s[2]+n+s[3])==7:
                    ans=s[0]+i+s[1]+m+s[2]+n+s[3]+'=7'
    print(ans)
resolve()

Solution (Python):


s = input()
ok = False
for i in ['-', '+']:
    for j in ['-', '+']:
        for k in ['-', '+']:
            expr = s[0]+i+s[1]+j+s[2]+k+s[3]
            if eval(expr) == 7:
                print(expr, '=7', sep="")
                ok = True
                break
        if ok: break
    if ok: break

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    S = input()
    hugo = ['+', '-']
    for a in hugo:
        for b in hugo:
            for c in hugo:
                N = eval(S[0]+a+S[1]+b+S[2]+c+S[3])
                if N == 7:
                    ans = S[0]+a+S[1]+b+S[2]+c+S[3]+'=7'
                    break
    print(ans)



if __name__ == '__main__':
    main()

Solution (Python):
s = ["+","-"]
t = input()
for i in range(2**3):
    a = ""
    for j in range(3):
        a +=s[i>>j&1]

    ans = t[0]+a[0]+t[1]+a[1]+t[2]+a[2]+t[3]
    if eval(ans) == 7:
        print(ans + "=7")
        exit()

Solution (Python):
s = ["+","-"]
t = input()
a = ""
from itertools import product
for v in product(s,repeat = 3):
    a = t[0] + v[0] + t[1] + v[1] + t[2] + v[2] + t[3]
    if eval(a) == 7:
        break
print(a + "=7")

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


def to_char(op):
    if op == 1:
        return '+'
    else:
        return '-'


for op1 in [1, -1]:
    for op2 in [1, -1]:
        for op3 in [1, -1]:
            val = a + op1 * b + op2 * c + op3 * d
            if val == 7:
                print('{}{}{}{}{}{}{}=7'.format(
                    a, to_char(op1), b, to_char(op2), c, to_char(op3), d))
                exit(0)

Solution (Python):
a, *bcd = map(int, input())

for bits in range(1 << 3):
    value = a
    formula = [a]
    for op, num in enumerate(bcd):
        if bits & 1 << op:
            value += num
            formula.append('+')
        else:
            value -= num
            formula.append('-')
        formula.append(num)
    if value == 7:
        formula.append('=7')
        print(*map(str, formula), sep='')
        break

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

Solution (Python):

import sys
abcd = input()
n = len(abcd)-1
for i in range(3**n):
    t = abcd[0]
    for j in range(n):
        if (i >> j & 1):
            t += '+'
        else:
            t += '-'
        t += abcd[j+1]
    if eval(t) == 7:
        t += '=7'
        print(t)
        sys.exit()

Solution (Python):
n = input()
op = len(n) - 1  
result = ""
for i in range(2**op):
    op_list = ['-']*op  
    for j in range(op):
        if (i >> j) & 1:
            op_list[2-j] = '+'  
    result = n[0] + op_list[0] + n[1] + op_list[1] + n[2] + op_list[2] + n[3]
    if eval(result) == 7:
        print(result + "=7")
        break

Solution (Python):
import itertools

X = str(input())
for op in list(itertools.product(['+', '-'], repeat=3)):
    eq = X[0] + op[0] + X[1] + op[1] + X[2] + op[2] + X[3]
    result = eval(eq)
    if result == 7:
        break

print(eq + '=7')

Solution (Python):
import numpy as np

S = input()
X = list(int(x) for x in S)


def test(Z):
    a = X[0]
    b = X[1] if Z[0] else -X[1]
    c = X[2] if Z[1] else -X[2]
    d = X[3] if Z[2] else -X[3]
    return a + b + c + d == 7


Y = [None] * (2 * len(X) - 1)
Y[::2] = X
for i in range(8):
    Z = [i & 1, i & 2, i & 4]
    if test(Z):
        Y[1::2] = ['+' if z else '-' for z in Z]
        break
print(*Y, sep='', end='=7\n')

Solution (Python):
s = input()
a, b, c, d = int(s[0]), int(s[1]), int(s[2]), 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):
S = input()


def f(index, cur):
    if index == 4:
        if eval(cur) == 7:
            print(cur + '=7')
            return True
        return False

    for a in ['-', '+']:
        if f(index + 1, cur + a + S[index]):
            return True
    return False


f(1, S[0])

Solution (Python):
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

S = input()

def solve(S):
    for op1 in range(-1, 2, 2):
        for op2 in range(-1, 2, 2):
            for op3 in range(-1, 2, 2):
                if int(S[0]) + op1 * int(S[1]) + op2 * int(S[2]) + op3 * int(S[3]) == 7:
                    return S[0] + ("+" if op1 == 1 else "-") + S[1] + ("+" if op2 == 1 else "-") + S[2] + ("+" if op3 == 1 else "-") + S[3] + "=7"

print(solve(S))

Solution (Python):
def dfs(i,Str,res):
    if i==num-1:
        if res==7:
            print(Str+"=7")
            exit()
        return
    dfs(i+1,Str+"+"+S[i+1],res+int(S[i+1]))
    dfs(i+1,Str+"-"+S[i+1],res-int(S[i+1]))    

S=input()
num=len(S)
dfs(0,S[0],int(S[0]))

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

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

    formula=""
    for l_num, l_m in zip(n,l+[""]):
        formula += l_num + l_m
    
    if eval(formula)==7:
        print(formula+"=7")
        break

Solution (Python):
import itertools

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

ans=0
for i in itertools.product([0,1], repeat=3):
    asum=a[0]
    astr=str(a[0])
    for ii in range(len(i)):
        if i[ii]==0:
            asum+=a[ii+1]
            astr=astr +"+" + str(a[ii+1])
        else:
            asum-=a[ii+1]
            astr=astr +"-" + str(a[ii+1])
    if asum==7:
        break
        
print(astr+"=7")

Solution (Python):
A = input()
for i in range(8):
  B = format(i, '03b').replace('0','+').replace('1','-')
  ans = ''.join([a+b for b,a in zip(B,A)]) + A[-1]
  if eval(ans) == 7:
    print(ans+'=7')
    exit()

Solution (Python):
A = input()
for i in range(8):
  B = format(i, '03b').replace('0','-').replace('1','+')
  ans = ''.join([a+b for b,a in zip(B,A)]) + A[-1]
  if eval(ans) == 7:
    print(ans+'=7')
    exit()

Solution (Python):
*A, = map(int, list(input()))
op = {
  '1': lambda x,y: x+y,
  '0': lambda x,y: x-y
}

for i in range(8):
  B = format(i, '03b')
  result = A[0]
  for j,bi in enumerate(B,1):
    result = op[bi](result,A[j])
  if result == 7:
    ope = B.replace('0','-').replace('1','+')+'='
    print(''.join([str(a)+o for a,o in zip(A,ope)])+'7')
    exit()

Solution (Python):
S = input()
a = int(S[0])
b = int(S[1])
c = int(S[2])
d = int(S[3])
if a+b+c+d==7:
    print(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):
s = input()
n = len(s)

def dfs(i, f):
  if i == n - 1:

    total = sum(list(map(int, f.split('+'))))
    if total == 7:
      print((f + '=7').replace('+-', '-'))
      exit()
    return total
    
  return dfs(i + 1, f + '+' + s[i + 1]) + dfs(i + 1, f + '+-' + s[i + 1])

dfs(0, s[0])

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

op_count= len(n)-1
for i in range(2**op_count):
    op = ["-"]*op_count
    for j in range(op_count):
        if ((i>>j)&1):
            op[j]="+"
    formula = n[0]+op[0]+n[1]+op[1]+n[2]+op[2]+n[3]
    if eval(formula)==7:
        print(formula+"=7")
        break

Solution (Python):
abcd = [int(i) for i in input()]
for i in range(2):
    for j in range(2):
        for k in range(2):
            ans = abcd[0]
            res = "" + str(abcd[0])
            if i:
                ans += abcd[1]
                res += "+" + str(abcd[1])
            else:
                ans -= abcd[1]
                res += "-" + str(abcd[1])
            if j:
                ans +=  abcd[2]
                res += "+" + str(abcd[2])
            else:
                ans -=  abcd[2]
                res += "-" + str(abcd[2])
            if k:
                ans +=  abcd[3]
                res += "+" + str(abcd[3])
            else:
                ans -=  abcd[3]
                res += "-" + str(abcd[3])
            if ans == 7:
                print(res+"=7" )
                exit()

Solution (Python):
n = input()

def dfs(i, f, s):
    if i == 3:
        return f+"=7" if s == 7 else ''
    return dfs(i+1, f+"+"+n[i+1], s+int(n[i+1])) or dfs(i+1, f+"-"+n[i+1], s-int(n[i+1]))

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

Solution (Python):
n = input()

def dfs(i, f, s):
    if i == 3:
        if s==7:
            return f+"=7"
        else:
            return ''
    return dfs(i+1, f+"+"+n[i+1], s+int(n[i+1])) or dfs(i+1, f+"-"+n[i+1], s-int(n[i+1]))

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

Solution (Python):

"""
Created on Sat Apr 25 19:47:38 2020

@author: Kanaru Sato
"""

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

for ops in range(1<<3):
    count = nums[0]
    formula = [str(nums[0])]
    
    for shift in range(3):
        shift = 2-shift
        if ops & (1<<shift):
            count += nums[3-shift]
            formula += ["+",str(nums[3-shift])]
        else:
            count -= nums[3-shift]
            formula += ["-",str(nums[3-shift])]

    if count == 7:
        formula.append("=")
        print("".join(formula)+"7")
        break

Solution (Python):
def dfs(i,s,res):
    if i==3:
        if res == 7:
            print(s+"=7")
            exit()
        return
    dfs(i+1,s+'+'+S[i+1],res+int(S[i+1]))
    dfs(i+1,s+'-'+S[i+1],res-int(S[i+1]))
 
S=input()
dfs(0,S[0],int(S[0]))

Solution (Python):
def dfs(i,s,res):
    if i==3:
        if res == 7:
            print(s+"=7")
            exit()
        return
 
    dfs(i+1,s+'+'+S[i+1],res+int(S[i+1]))
    dfs(i+1,s+'-'+S[i+1],res-int(S[i+1]))
 
S=input()
dfs(0,S[0],int(S[0]))

Solution (Python):
def dfs(i,St,res):
    if i==3:
        if res == 7:
            print(St+"=7")
            exit()
        return

    dfs(i+1,St+'+'+S[i+1],res+int(S[i+1]))
    dfs(i+1,St+'-'+S[i+1],res-int(S[i+1]))

S=input()
dfs(0,S[0],int(S[0]))

Solution (Python):
def dfs(i,Str,res):
    if i==3:
        if res == 7:
            print(Str+"=7")
            exit()
        return

    dfs(i+1,Str+'+'+S[i+1],res+int(S[i+1]))
    dfs(i+1,Str+'-'+S[i+1],res-int(S[i+1]))

S=input()
dfs(0,S[0],int(S[0]))

Solution (Python):
def dfs(i, Str, res):
    if i==3:
        if res==7:
            print(Str+"=7")
            exit()
        return
    
    dfs(i+1,Str+"+"+s[i+1],res+int(s[i+1]))
    dfs(i+1,Str+"-"+s[i+1],res-int(s[i+1]))

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

Solution (Python):
def dfs(i, Str, res):
    if i==3:
        if res==7:
            print(Str+"=7")
            exit()
        return
    
    dfs(i+1,Str+"+"+s[i+1],res+int(s[i+1]))
    dfs(i+1,Str+"-"+s[i+1],res-int(s[i+1]))

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

Solution (Python):
s=list(input())
a=int(s[0])
b=int(s[1])
c=int(s[2])
d=int(s[3])
number=[a,b,c,d]

plmi=["+","-"]

def plus(a,b,i):
    if i==0:
        return a+b
    else:
        return a-b
    
ans=[]
def plusminus(a,b,c,d,i,j,k):
    global ans
    res1=plus(a,b,i)
    res2=plus(res1,c,j)
    res3=plus(res2,d,k)
    if res3==7:
        ans.append([i,j,k])
    
    
    
    
    
    


for i in range(2):
    for j in range(2):
        for k in range(2):
            plusminus(a,b,c,d,i,j,k)

kotae=ans[0]
hugou1=plmi[kotae[0]]
hugou2=plmi[kotae[1]]
hugou3=plmi[kotae[2]]
a=str(a)
b=str(b)
c=str(c)
d=str(d)

print(a+hugou1+b+hugou2+c+hugou3+d+"=7")

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

if a+b+c+d == 7:
    print(s[0]+"+"+s[1]+"+"+s[2]+"+"+s[3]+"=7")
elif a+b-c+d == 7:
    print(s[0]+"+"+s[1]+"-"+s[2]+"+"+s[3]+"=7")
elif a+b+c-d == 7:
    print(s[0]+"+"+s[1]+"+"+s[2]+"-"+s[3]+"=7")
elif a+b-c-d == 7:
    print(s[0]+"+"+s[1]+"-"+s[2]+"-"+s[3]+"=7")
elif a-b+c+d == 7:
    print(s[0]+"-"+s[1]+"+"+s[2]+"+"+s[3]+"=7")
elif a-b-c+d == 7:
    print(s[0]+"-"+s[1]+"-"+s[2]+"+"+s[3]+"=7")
elif a-b+c-d == 7:
    print(s[0]+"-"+s[1]+"+"+s[2]+"-"+s[3]+"=7")
elif a-b-c-d == 7:
    print(s[0]+"-"+s[1]+"-"+s[2]+"-"+s[3]+"=7")

Solution (Python):
n = input()

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

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

Solution (Python):
n = input()

def dfs(i, l):
    if i == 3:
        return l+'=7' if eval(l) == 7 else ''
    return dfs(i+1, l+"+"+n[i+1]) or dfs(i+1, l+"-"+n[i+1])

print(dfs(0, n[0]))

Solution (Python):
n = input()

def dfs(i, l):
    if i == 3:
        return l+'=7' if sum(list(map(int, l.split("+")))) == 7 else ''
    return dfs(i+1, l+"+"+n[i+1]) or dfs(i+1, l+"+"+"-"+n[i+1])

print(dfs(0, n[0]).replace('+-', '-'))

Solution (Python):
n = input()

def dfs(i, l):
    if i == 3:
        return l+'=7' if eval(l) == 7 else ''
    return dfs(i+1, l+"+"+n[i+1]) or dfs(i+1, l+"-"+n[i+1])

print(dfs(0, n[0]))

Solution (Python):
def main():
    N = input()

    op_n = len(N)-1
    for i in range(2**op_n):
        op = ['-'] * op_n
        for j in range(op_n):
            if ((i >> j) & 1):
                op[op_n - 1 - j] = '+'
        ans = 0
        formula = N[0]+op[0]+N[1]+op[1]+N[2]+op[2]+N[3]
        ans = eval(formula)
        if ans == 7:
            print(formula+'=7')
            break


if __name__ == '__main__':
    main()

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):
def dfs(i, Str, res):
    if i==3:
        if res==7:
            print(Str+"=7")
            exit()
        return
    
    dfs(i+1,Str+"+"+s[i+1],res+int(s[i+1]))
    dfs(i+1,Str+"-"+s[i+1],res-int(s[i+1]))

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