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

ans=int(s[0])
a=ans
for i in range(2):
    ans=a
    if i==0:
        ans+=int(s[1])
        i='+'
    else:
        ans-=int(s[1])
        i='-'
    b=ans
    for j in range(2):
        ans=b
        if j==0:
            ans+=int(s[2])
            j='+'
        else:
            ans-=int(s[2])
            j='-'
        c=ans
        for k in range(2):
            ans=c
            if k==0:
                ans+=int(s[3])
                k='+'
            else:
                ans-=int(s[3])
                k='-'
            if ans==int(7):
                print(s[0]+str(i)+s[1]+str(j)+s[2]+str(k)+s[3]+'=7')
                break
        else:
            continue
        break
    else:
        continue
    break

Solution (Python):
abcd=input()

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

Solution (Python):
s = list(input())
a = len(s)-1
for i in range(2 ** a):
    b = ["-"] * a
    for j in range(a):
        if i>>j & 1:
            b[j] = "+"
    S = s[0]
    for x in range(a):
        S += b[x]
        S += s[x+1]
    if eval(S) == 7:
        print(S+"=7")
        exit()

Solution (Python):
import sys
s = input()
a = int(s[0])
b=[]
for i in range(3):
    b.append(int(s[i+1]))

for i in range(8):
    tmp = a
    for j in range(3):
        if (i>>j) & 1 == 0:
            tmp += b[j]
            
        else:
            tmp -= b[j]
    if tmp == 7:
        ans = [str(a)]
        for k in range(3):
            if (i>>k) & 1 == 0:
                ans.append("+")
            else:
                ans.append("-")
            ans.append(str(b[k]))
        print(''.join(ans),end="")
        print("=7")
        sys.exit()

Solution (Python):
n_str = input()

op_count = len(n_str) - 1  
for i in range(2 ** op_count):
    op_list = ["-"] * op_count    
    for j in range(op_count):    
        if ((i >> j) & 1):
            op_list[len(op_list) - 1 -j] = "+"

    op_list.append("")
    formula = ""
    for i in range(len(n_str)):
        formula += (n_str[i] + op_list[i])
    if eval(formula) == 7:
        print(formula + "=7")
        break

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


def main():
    A = list(map(int, list(input()[:-1])))
    for i in range(2**3):
        f = str(A[0])
        ans = A[0]
        for j in range(3):
            if (i>>j) & 1:
                f += '+' + str(A[j+1])
                ans += A[j+1]
            else:
                f += '-' + str(A[j+1])
                ans -= A[j+1]
        if ans==7:
            f += '=7'
            print(f)
            return


if __name__ == '__main__':
    main()

Solution (Python):
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()
 
abcd = ns()
a = int(abcd[0])
b = int(abcd[1])
c = int(abcd[2])
d = int(abcd[3])

l = [
  [1, 1, 1],
  [-1, 1, 1],
  [1, -1, 1],
  [1, 1, -1],
  [-1, -1, 1],
  [-1, 1, -1],
  [1, -1, -1],
  [-1, -1, -1],
]

counter = 0
for i in range(8):
  if a + l[i][0] * b + l[i][1] * c + l[i][2] * d == 7:
    break
  counter += 1

out = []
out.append(str(a))
if l[counter][0] == 1:
  out.append('+')
else:
  out.append('-')
out.append(str(b))
if l[counter][1] == 1:
  out.append('+')
else:
  out.append('-')
out.append(str(c))
if l[counter][2] == 1:
  out.append('+')
else:
  out.append('-')
out.append(str(d))
out.append('=7')
print(''.join(out))

Solution (Python):
L = [int(i) for i in input()]
A = L[0]
B = L[1]
C = L[2]
D = L[3]
x="-"
y="-"
z="-"
if A+B+C+D==7:
    x="+"
    y="+"
    z="+"
elif A+B+C-D==7:
    x="+"
    y="+"
elif A+B-C+D==7:
    x="+"
    z="+"
elif A+B-C-D==7:
    x="+"
elif A-B+C+D==7:
    y="+"
    z="+"
elif A-B+C-D==7:
    y="+"
elif A-B-C+D==7:
    z="+"
print("{}{}{}{}{}{}{}{}".format(A,x,B,y,C,z,D,"=7"))

Solution (Python):
ABCD = input()
S = list(ABCD)
op_cnt = len(S) - 1

ans = None
for i in range(2**op_cnt):
    op = ["+"] * op_cnt
    for j in range(op_cnt):
        if i >> j & 1:
            op[op_cnt - j - 1] = "-"
    expr = S[0] + "".join(o+s for s,o in zip(S[1:], op))
    if eval(expr) == 7:
        ans = expr + "=7"
        break
print(ans)

Solution (Python):
S = input()
op_cnt = len(S) -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 a, b in zip(S, op + ['']):
        formula += a + b
    if eval(formula) == 7:
        print(formula + '=7')
        break

Solution (Python):
a=[int(i) for i in input()]
for i in range(2**3):
    op=['-','-','-']
    for j in range(len(op)):
        if (i>>j)&1:
            op[j]='+'
    sum=a[0]
    for k in range(3):
        if op[k]=='+':
            sum+=a[k+1]
        else:
            sum-=a[k+1]
    if sum==7:
        print(str(a[0])+op[0]+str(a[1])+op[1]+str(a[2])+op[2]+str(a[3])+'=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('{}+{}+{}+{}=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):
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):

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

n = input()[:-1]


def dfs(pos, formula):
    if (pos > 3):
        
        return formula if eval(formula) == 7 else False
    
    f = dfs(pos + 1, formula + '+'+n[pos])
    if (not f):
        return dfs(pos + 1, formula + '-'+n[pos])
    else:
        return f


print(dfs(1, n[0])+'=7')

Solution (Python):
A,B,C,D=map(str,list(input()))
nana = False
for i in range(8):
    op1,op2,op3='-','-','-'
    if (i & 0b1) == 1:
        op1='+'
    if ((i>>1) & 0b1) == 1:
        op2='+'
    if ((i>>2) & 0b1) == 1:
        op3='+'
    if eval(A+op1+B+op2+C+op3+D) == 7:
        nana=True
        siki7=A+op1+B+op2+C+op3+D
if nana == True:
    print(siki7+'=7')

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

Solution (Python):
a, b, c, d = map(int, input())
ops = ['+', '-']
for op1 in ops:
    for op2 in ops:
        for op3 in ops:
            formula = "{}{}{}{}{}{}{}".format(a, op1, b, op2, c, op3, d)
            if eval(formula) == 7:
                print("{}=7".format(formula))
                exit()

Solution (Python):

S = str(input())

for i in range(2**(len(S)-1)):
    bit_array = str(bin(i)[2:]).zfill((len(S)-1))
    
    stored = int(S[0])
    
    for j in range(len(bit_array)):
        
        if bit_array[j]=="0":
            stored = stored + int(S[j+1])
        elif bit_array[j]=="1":
            stored =  stored - int(S[j+1])
    
    if stored == 7:
        print(int(S[0]),end="")
        for k in range(3):
            if bit_array[k]=="0":
                print("+",end="")
            elif bit_array[k]=="1":
                print("-",end="")
            
            print(S[k+1],end="")
        print("=7")
        break

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

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

Solution (Python):
A=input()
N=len(A)

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

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

for op1 in ['+', '-']:
    for op2 in ['+', '-']:
        for op3 in ['+', '-']:
            s = numbers[0]+op1+numbers[1]+op2+numbers[2]+op3+numbers[3]
            if eval(s) == 7:
                print('{}=7'.format(s))
                exit()

Solution (Python):
from itertools import permutations

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

def solve():
    '''bit全探索で解く'''
    candidates = []
    for i in range(2**3):
        
        candidates.append(bin(i)[2:].zfill(3))
    
    for candidate in candidates:
        s = numbers[0]
        
        for i, c in enumerate(list(candidate)):
            if c == '1':
                s += numbers[i+1]
            else:
                s -= numbers[i+1]
            
        if s == 7:
            candidate = ''.join(candidate)
            candidate = candidate.replace('1', '+')
            candidate = candidate.replace('0', '-')
            for i in range(3):
                print(numbers[i], end='')
                print(candidate[i], end='')
                
            print(numbers[-1], end='')
            print('=7') 
            return

if __name__ == '__main__':
    solve()

Solution (Python):
n=list(input())
pm=["+","-"]

for op1 in pm:
    for op2 in pm:
        for op3 in pm:
            s = n[0] + op1 + n[1] + op2 + n[2] + op3 + n[3]
            if eval(s) == 7:
                print(s + "=7")
                exit()

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

for b in [B, -B]:
  for c in [C, -C]:
    for d in [D, -D]:
      if A+b+c+d==7:
        output=str(A)
        
        if b<0:
          output+=str(b)
        else:
          output+='+'+str(b)
          
        if c<0:
          output+=str(c)
        else:
          output+='+'+str(c)
          
        if d<0:
          output+=str(d)
        else:
          output+='+'+str(d)
          
print(output+'=7')

Solution (Python):
s = list(input())
pm = ['+', '-']

for i in pm:
    for j in pm:
        for k in pm:
            t = s[0] + i + s[1] + j + s[2] + k + s[3]
            if eval(t) == 7:
                print(t + '=7')
                exit()

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

plus_minus = ["+", "-"]
for op1 in plus_minus:
    for op2 in plus_minus:
        for op3 in plus_minus:
            formula = ABCD[0] + op1 + ABCD[1] + op2 + ABCD[2] + op3 + ABCD[3]
            if eval(formula) == 7:
                print(formula + "=7")
                exit()

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

plus_minus = ["+", "-"]
for op1 in plus_minus:
    for op2 in plus_minus:
        for op3 in plus_minus:
            formula = str(ABCD[0]) + op1 + str(ABCD[1]) + op2 + str(ABCD[2]) + op3 + str(ABCD[3])
            if eval(formula) == 7:
                print(formula + "=7")
                exit()

Solution (Python):
s = input()
for i in range(8):
  e = bin(i)[2:]
  e = '0' * (3-len(e)) + e
  su = int(s[0])
  for i in range(3):
    if e[i] == '0':
      su -= int(s[i+1])
    else:
      su += int(s[i+1])
  if su == 7:
    a = s[0]
    for i in range(3):
      if e[i] == '0':
        a += '-'
      else:
        a += '+'
      a += s[i+1]
    a += '=7'
    print(a)
    exit()

Solution (Python):






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





import sys





cs_a = a
for i in range(2):
    if i:
        cs_b = cs_a + b
        op1 = '+'
    else:
        cs_b = cs_a - b
        op1 = '-'
        
    for j in range(2):
        if j:
            cs_c = cs_b + c
            op2 = '+'
        else:
            cs_c = cs_b - c
            op2 = '-'
        
        for k in range(2):
            if k:
                cs_d = cs_c + d
                op3 = '+'
            else:
                cs_d = cs_c - d
                op3 = '-'
                
            if cs_d == 7:
                print('{}{}{}{}{}{}{}=7'.format(a, op1, b, op2, c, op3, d))
                sys.exit()

Solution (Python):
l = list(input().rstrip())
ops = ['+', '-']
for a in ops:
    for b in ops:
        for c in ops:
            s = l[0] + a + l[1] + b + l[2] + c + l[3]
            if eval(s) == 7:
                print(s + '=7')
                exit()

Solution (Python):
ABCD = input()
A, B, C, D = [int(x) for x in ABCD]
ops = ["+", "-"]
for op1 in ops:
    for op2 in ops:
        for op3 in ops:
            if op1 == "+":
                ans = A + B
            else:
                ans = A - B
            if op2 == "+":
                ans += C
            else:
                ans -= C
            if op3 == "+":
                ans += D
            else:
                ans -= D
            if ans == 7:
                print(str(A) + op1 + str(B) + op2 + str(C) + op3 + str(D) + "=" + str(ans))
                exit()

Solution (Python):
import itertools

N = list(input().strip())

for p in itertools.product(['+', '-'], repeat=3):
    s = N[0] + p[0] + N[1] + p[1] + N[2] + p[2] + N[3]
    if eval(s) == 7:
        print(s + '=7')
        exit()

Solution (Python):
l_a  = list(input())
l_b = [l_a[0],0,l_a[1],0,l_a[2],0,l_a[3]]
l_c = []
for i in range (2**3):
    for k in range(3):
        if i & (1<<k):
            l_b[2*k+1] = '+'
        else:
            l_b[2*k+1] = '-'
    d =''.join(l_b)
    if eval(d) == 7:
        print(d + '=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(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
S = list(map(int,list(input())))
for i in range(2**3):
    n = i
    pat = []
    sum = S[0]
    for j in range(1,4):
        if n % 2 == 0:
            pat.append('+')
            sum += S[j]
        else:
            pat.append('-')
            sum -= S[j]
        n = n // 2
    if sum == 7:
        print( '{}{}{}{}{}{}{}=7'.format(S[0],pat[0],S[1],pat[1],S[2],pat[2],S[3]))
        sys.exit()

Solution (Python):
def run():
  num_list = [int(i) for i in list(input())]
  ans_list = [(str(num_list[0]), num_list[0])]
  for num in num_list[1:]:
    new_list = []
    for ans in ans_list:
      ans_str = ans[0]
      ans_num = ans[1]
      new_list.append((ans_str+'+'+str(num), ans_num+num))
      new_list.append((ans_str+'-'+str(num), ans_num-num))
    ans_list = new_list
  for ans in ans_list:
    if ans[1] == 7:
      print(ans[0]+'=7')
      break
                       
if __name__ == '__main__':  
  run()

Solution (Python):
S = input()
A = [0]*4
for i in range(4):
    A[i] = int(S[i])
zero = [0,1]

import itertools
for i in itertools.product(zero,repeat=3):
    tmp = A[0]
    for j in range(3):
        if i[j] == 0:
            tmp += A[j+1]
        else:
            tmp -= A[j+1]
    if tmp == 7:
        break
ans = S[0]
op = i
for i in range(3):
    if op[i] == 0:
        ans += "+"
    else:
        ans += "-"
    ans += S[i+1]
ans += "=7"
print(ans)

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")
else:
    print(str(a)+"+"+str(b)+"-"+str(c)+"+"+str(d)+"=7")

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


s = S()

L = [s[1], s[2], s[3] + '==7']
for i in range(8):
    ret = s[0]
    for j in range(3):
        if i & (1 << j):
            ret += '+'
        else:
            ret += '-'
        ret += L[j]
    if eval(ret):
        print(ret.replace('==', '='))
        break

Solution (Python):
import itertools

N = list(input().strip())

for p in itertools.product(['+','-'], repeat=3):
  s = N[0]+p[0]+N[1]+p[1]+N[2]+p[2]+N[3]
  if eval(s) == 7:
    print(s+'=7')
    exit()

Solution (Python):
import sys


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


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

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

        if eval(f) == 7:
            print(f + "=7")
            exit()


def main():
    s = input()

    bitall(s)


if __name__ == '__main__':
    main()

Solution (Python):
import sys


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


def main():
    s = input()
    n = len(s) - 1

    for bit in range(1 << n):
        f = s[0]

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

        if eval(f) == 7:
            print(f + "=7")
            exit()


if __name__ == '__main__':
    main()

Solution (Python):
s=list(input())
hs=[0]*4
for i in range(4):
    s[i]=int(s[i])
    hs[i]=s[i]

op=[[0],[1]]

for i in range(3):
    tmp=[]
    for j in op:
        tmp.append(j+[0])
        tmp.append(j+[1])
    op=tmp

for i in op:
    s=hs
    for j in range(3):
        if i[j]==0:
            s[j+1]=-s[j+1]
    if sum(s)==7:
        break

ans=str(s[0])
for i in range(3):
    if s[i+1]<0:
        ans+="-"
    else:
        ans+="+"
    ans+=str(abs(s[i+1]))
print(ans+"=7")

Solution (Python):
S = input()


for i in range(2**3):
    formula = ""

    for j in range(3):
        formula += S[j]
        if (i >> j) & 1:
            formula += "+"
        else:
            formula += "-"
    formula += S[-1]

    if eval(formula) == 7:
        print(formula + "=7")
        break

Solution (Python):
num=int(input())

a=num//1000
b=(num-a*1000)//100
c=(num-a*1000-b*100)//10
d=(num-a*1000-b*100-c*10)

op=["+","-"]
flg = 0


for i in range(2):
    if flg == 1:break
    for j in range(2):
        if flg == 1:break
        for k in range(2):
            if flg == 1:break
            out = str(a)+op[i]+str(b)+op[j]+str(c)+op[k]+str(d)
            if eval(out) == 7:
                out += "=7"
                flg = 1

print(out)

Solution (Python):
ABCD = input()
f = ""
for i in range(2 ** (len(ABCD) - 1)):
    f = ""
    for j in range(len(ABCD)):
        f += ABCD[j]
        if j != len(ABCD)-1:
            if (i >> (len(ABCD)-1-1-j)) & 1:
                f += "+"
            else:
                f += "-"
    if eval(f) == 7:
        print(f + "=7")
        exit()

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):
x = input()

y = [int(c) for c in x]

a = y[0]
b = y[1]
c = y[2]
d = y[3]
if a+b+c+d == 7:
  print(a,"+",b,"+",c,"+",d,"=",a+b+c+d, sep='')
  exit()
if a+b+c-d == 7:
  print(a,"+",b,"+",c,"-",d,"=",a+b+c-d, sep='')
  exit()
if a+b-c+d == 7:
  print(a,"+",b,"-",c,"+",d,"=",a+b-c+d, sep='')
  exit()
if a-b+c+d == 7:
  print(a,"-",b,"+",c,"+",d,"=",a-b+c+d, sep='')
  exit()
if a-b-c+d == 7:
  print(a,"-",b,"-",c,"+",d,"=",a-b-c+d, sep='')
  exit()
if a-b+c-d == 7:
  print(a,"-",b,"+",c,"-",d,"=",a-b+c-d, sep='')
  exit()
if a-b-c-d == 7:
  print(a,"-",b,"-",c,"-",d,"=",a-b-c-d, sep='')
  exit()
if a+b-c-d == 7:
  print(a,"+",b,"-",c,"-",d,"=",a+b-c-d, sep='')
  exit()

Solution (Python):
s=input()
op=["+","-"]
for i in range(2):
    for j in range(2):
        for k in range(2):
            formula=s[0]+op[i]+s[1]+op[j]+s[2]+op[k]+s[3]
            if eval(formula)==7:
                print(formula+"=7")
                exit(0)

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

def f(a,b,op):
	if op:return a+b
	else:return a-b

t=False
for i in range(2):
	for j in range(2):
		for k in range(2):
			if f(f(f(a,b,i),c,j),d,k) == 7:
				t=True
				break
		if t:break
	if t:break

dic={0:'-', 1:'+'}
for u,v in zip([a,b,c],[i,j,k]):
	print(u,dic[v],sep='',end='')
print(d,'=7',sep='')

Solution (Python):
A,B,C,D=input()
a = int(A)
b = int(B)
c = int(C)
d = int(D)
if (a+b+c+d) == 7:
         print(A+"+"+B+"+"+C+"+"+D+"=7")
elif (a-b+c+d) == 7:
         print(A+"-"+B +"+"+C +"+"+D+"=7")
elif (a+b-c+d) == 7:
         print(A+"+"+B +"-"+C +"+"+D+"=7")
elif (a+b+c-d) == 7:
         print(A+"+"+B +"+"+C +"-"+D+"=7")
elif (a-b-c+d) == 7:
         print(A+"-"+B +"-"+C +"+"+D+"=7")
elif (a-b+c-d) == 7:
         print(A+"-"+B +"+"+C +"-"+D+"=7")
elif (a+b-c-d) == 7:
         print(A+"+"+B +"-"+C +"-"+D+"=7")
else:
         print(A+"-"+B +"-"+C +"-"+D+"=7")

Solution (Python):
s = input()
n = len(s)
ans = []

def dfs(i, f, total):
    if i == 3:
        if total == 7:
            global ans
            ans.append(f + '=7')

    else:
        dfs(i+1, f + '-' + s[i+1], total - int(s[i+1]))
        dfs(i+1, f + '+' + s[i+1], total + int(s[i+1]))
        
dfs(0, s[0], int(s[0]))
print(ans[0])

Solution (Python):
"""
<<全探索問題//ABC079C>>
1. itertools,evalsを用いた方法
2. bit全探索を用いた方法
"""


"""
import itertools
s=input()
A,B,C,D=s
for i in itertools.product(['+','-'],repeat=len(s)-1):
    formula=''
    formula=A+i[0]+B+i[1]+C+i[2]+D
    if eval(formula)==7:
        print(formula+'=7')
        break
"""


s=input()
N=len(s)-1
for i in range(2**N):
    list=['+']*N
    formula=''
    for j in range(N):
        if ((i>>j)&1):
            list[N-1-j]='-'
    for num,operator in zip(s,list+['']):
        formula+=(num+operator)
    if eval(formula)==7:
        print(formula+'=7')
        break

Solution (Python):
"""
<<全探索問題//ABC079C>>

1. itertoolsを用いた方法
2. bit全探索を用いた方法
"""


import itertools
A,B,C,D=input()
for i in itertools.product(['+','-'],repeat=3):
    formula=''
    formula=A+i[0]+B+i[1]+C+i[2]+D
    if eval(formula)==7:
        print(formula+'=7')
        break

Solution (Python):

s = input()
abcd = [c for c in s]

OP = ["+", "-"]

for op1 in OP:
    for op2 in OP:
        for op3 in OP:
            fomula_tmp = abcd[0] + op1 + abcd[1] + op2 + abcd[2] + op3 + abcd[3]
            if eval(fomula_tmp) == 7:
                print(fomula_tmp + "=7")
                exit()

Solution (Python):
S = input()
S = [S[0],None,S[1],None,S[2],None,S[3]]

for i in range(2**3):
  tmp = S
  for j in range(3):
    if ((i >> j) & 1):
      tmp[j*2+1] = "+"
    else:
      tmp[j*2+1] = "-"
  if eval("".join(tmp)) == 7:
    print("".join(tmp),end = "")
    print("=7")
    break

Solution (Python):
S=input()
h=[1,-1]
e=[0,1]
f=["+","-"]
x=""
a=0
for i in e:
  for j in e:
    for k in e:
      a=int(S[0])+int(S[1])*h[i]+int(S[2])*h[j]+int(S[3])*h[k]
      if a==7:
        x=S[0]+f[i]+S[1]+f[j]+S[2]+f[k]+S[3]+"=7"
print(x)

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):
a, b, c, d = list(input())

import itertools

for ops in itertools.product(["+", "-"], repeat=3):
    eq = a + ops[0] + b + ops[1] + c + ops[2] + d
    sol = eval(eq)
    if sol == 7:
        break

ans = eq + "=7"
print(ans)

Solution (Python):
abcd = input()

import itertools

for op in itertools.product(["+", "-"], repeat=3):
    sm = int(abcd[0])
    for i in range(3):
        if op[i] == "+":
            sm += int(abcd[i+1])
        else:
            sm -= int(abcd[i+1])
    if sm == 7:
        break

ans = str(abcd[0])
for i in range(3):
    ans += op[i] + abcd[i+1]
ans += "=7"
print(ans)

Solution (Python):
n = input()
a=[]
for  i in range(4):
  a.append(int(n[i]))
out=[]
pi=[]
for i in range(2):
  for j in range(2):
    for k in range(2):
      
      if a[0]+(i*2-1)*a[1]+(j*2-1)*a[2]+(k*2-1)*a[3] ==7:

        if i*2-1 ==1:
          pi.append('+')
        else:
          pi.append('-')
        if j*2-1 ==1:
          pi.append('+')
        else:
          pi.append('-')
        if k*2-1 ==1:
          pi.append('+')
        else:
          pi.append('-')
              
        for h in range(3):
          print(a[h],end="")
          print(pi[h],end="")
        print(a[3],end="")
        print('=7')
        exit()  
      else:
        f=0

Solution (Python):
from itertools import*
A,B,C,D=input()
for i,j,k in product(["+","-"],repeat=3):
 s=A+i+B+j+C+k+D
 if eval(s)==7:print(s+"=7");break

Solution (Python):
ABCD = input()

def dfs(i, expression, res):
    if i == 4:
        if res == 7:
            return expression
        else:
            return []
    else:
        ans = dfs(i + 1, expression + '+' + ABCD[i], res + int(ABCD[i])) or dfs(i + 1, expression + '-' + ABCD[i], res - int(ABCD[i]))
    return ans

ans = dfs(1, ABCD[0], int(ABCD[0]))
print(ans + '=7')

Solution (Python):

A = str(input())
l = [int(x) for x in list(str(A))]
if l[0]+l[1]+l[2]+l[3] == 7 :
    print('{0}+{1}+{2}+{3}=7'.format(l[0],l[1],l[2],l[3]))
elif l[0]-l[1]+l[2]+l[3] == 7 :
    print('{0}-{1}+{2}+{3}=7'.format(l[0], l[1], l[2], l[3]))
elif l[0]+l[1]-l[2]+l[3] == 7 :
    print('{0}+{1}-{2}+{3}=7'.format(l[0], l[1], l[2], l[3]))
elif l[0]+l[1]+l[2]-l[3] == 7:
    print('{0}+{1}+{2}-{3}=7'.format(l[0], l[1], l[2], l[3]))
elif l[0]-l[1]-l[2]+l[3] == 7:
    print('{0}-{1}-{2}+{3}=7'.format(l[0], l[1], l[2], l[3]))
elif l[0]+l[1]-l[2]-l[3] == 7:
    print('{0}+{1}-{2}-{3}=7'.format(l[0], l[1], l[2], l[3]))
elif l[0]-l[1]+l[2]-l[3] == 7:
    print('{0}-{1}+{2}-{3}=7'.format(l[0], l[1], l[2], l[3]))
elif l[0]-l[1]-l[2]-l[3] == 7:
    print('{0}-{1}-{2}-{3}=7'.format(l[0], l[1], l[2], l[3]))

Solution (Python):
l=input()
a,b,c,d=[int(l[i]) for i in range(4)]
plmi=[1,-1]
x=[None,'+','-']
for i in plmi:
	for j in plmi:
		for k in plmi:
			if a+b*i+c*j+d*k==7:
				print(str(a)+x[i]+str(b)+x[j]+str(c)+x[k]+str(d)+'=7')
				exit()

Solution (Python):
abcd=[int(i) for i in input()]
a=abcd[0]
b=abcd[1]
c=abcd[2]
d=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))
else:
  pass

Solution (Python):
n=input()
l=[1,-1]
l1=[0,"+","-"]
s=""
for i in l:
  for j in l:
    for k in l:
      if int(n[0])+i*int(n[1])+j*int(n[2])+k*int(n[3])==7:
        s=n[0]+l1[i]+n[1]+l1[j]+n[2]+l1[k]+n[3]+"=7"
print(s)

Solution (Python):
A, B, C, D = list(map(int, input()))
for i in range(8):
  if i & 1 == 0:
    tb = B
  else:
    tb = -B
  if i & 2 == 0:
    tc = C
  else:
    tc = -C
  if i & 4 == 0:
    td = D
  else:
    td = -D
  if sum([A, tb, tc, td]) == 7:
    break
print("%d%+d%+d%+d=7" % (A, tb, tc, td))

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

op = [[1, -1],[1, -1],[1, -1]]
dic = {0:"+",1:"-"}

for i in range(2):
  for j in range(2):
    for k in range(2):
      ans = a + op[0][i] * b + op[1][j] * c + op[2][k] *d
      if ans == 7:
        fml = str(a) + dic[i] + str(b) + dic[j] + str(c) + dic[k] + str(d) +"=7"
        print(fml)
        exit()

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

Solution (Python):
import itertools
s = list(input())
for op in itertools.product(range(2), repeat=3):
    ans = int(s[0])
    for i in range(3):
        if op[i] == 1:
            ans += int(s[i+1])
        else:
            ans -= int(s[i+1])
    if ans == 7:
        break

for i,j in zip(s,op):
    if j == 1:
        j = '+'
    else:
        j = '-'
    print(str(i)+j,end='')
print(s[-1]+'=7')