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



Sample input:
1222


Sample output:
1+2+2+2=7

Submission status: Accepted

Solution code:
n = input()
b_l = []
for i in range(8):
  b = bin(i)[2:]
  le = len(b)
  b_l.append((3 - le)*"0" + b)


    

s_l = [int(n[i]) for i in range(4)]
    
for b in b_l:
  ans = s_l[0]
  f = 0
  b_s_l = ["+" if b[i] == "0" else "-" for i in range(3)]
  for i in range(3):
    if b_s_l[i] == "+":
      ans += s_l[i+1]
    else:
      ans -= s_l[i+1]
  if ans == 7:
    print(str(s_l[0]) + b_s_l[0] + str(s_l[1]) + b_s_l[1] + str(s_l[2]) + 
          b_s_l[2] + str(s_l[3]) + "=7") 
    break

Submission status: Accepted

Solution code:
a, b, c, d = map(int, input())
op = "+-"
for i in range(2):
  for j in range(2):
    for k in range(2):
      if a + b*(-1)**i + c*(-1)**j + d*(-1)**k == 7:
        print(str(a) + op[i] + str(b) + op[j] + str(c) + op[k] + str(d) + "=7")
        exit()

Submission status: Accepted

Solution code:
A,B,C,D = [int(i) for i in str(input())]
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))

Submission status: Accepted

Solution code:
S = input()
l = len(S)
for i in range(1 << (l-1)):
    a = int(S[0])
    sum_t = int(S[0])
    st = S[0]
    for j in range(l-1):
        if ((i >> j) & 1):
            st += "+"
            st += S[j+1]
            sum_t += int(S[j+1])
        else:
            st += "-"
            st += S[j+1]
            sum_t -= int(S[j+1])
    if sum_t == 7:
        print("{}=7".format(st))
        break

Submission status: Accepted

Solution code:
from itertools import product

abcd = input()

ops = ["+", "-"]

for pat in product(ops, repeat=3):
    eq = ""
    for num, op in zip(abcd, pat):
        eq += num + op
    eq += abcd[-1]
    ev = eval(eq)
    if ev == 7:
        break

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

Submission status: Accepted

Solution code:
num = list(map(int,input()))
l = len(num)
for i in range(2**(l-1)):
    ans = num[0]
    cur = bin(i)[2:]
    cur = '0' * (l-1-len(cur)) + cur
    s = str(num[0])
    for j in range(l-1):
        if cur[j] == '1':
            s += "-"
            s += str(num[j+1])
            ans -= num[j+1]
        else:
            s += "+"
            s += str(num[j+1])
            ans += num[j+1]
    if ans == 7:
        break
s += "=7"
print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import operator
s = [int(i) for i in list(input())]

op = []
op.append( operator.add )
op.append( operator.sub )


for i in range(2) :
  for j in range(2) :
    for k in range(2) :

      r = op[i](s[0],s[1])

      r = op[j](r,s[2])

      r = op[k](r,s[3])

      if r == 7 :
        op1 = "+" if i == 0 else "-"
        op2 = "+" if j == 0 else "-"
        op3 = "+" if k == 0 else "-"
        print(str(s[0])+op1+str(s[1])+op2+str(s[2])+op3+str(s[3])+"=7")
        exit()

Submission status: Accepted

Solution code:
s = input()
v = list("+".join(s))
plus_index = [i for i, x in enumerate(v) if x == '+']
n = len(plus_index)

m = v.copy()
if not eval("".join(v)) == 7:
    for i in range(1 << n):
        m = v.copy()
        for j in range(n):
            if i & (1 << j):
                m[plus_index[j]] = "-"
        if eval("".join(m)) == 7:
            break
print("".join(m) + "=7")

Submission status: Accepted

Solution code:
n=input()
l=[None]*7
for i in range(4):
    l[i*2]=n[i]
for i in range(2**3):
    for j in range(3):
        if (i>>j)&1:
            l[j*2+1]="+"
        else:
            l[j*2+1]="-"
    a="".join(l)
    if eval(a)==7:
        print(a+"=7")
        exit()

Submission status: Accepted

Solution code:
import itertools
a = ["+", "-"]
b = ["+", "-"]
c = ["+", "-"]

#1行で受け取って各桁をリストにする
A = input()
l = [str(c) for c in A]

#4つの計算の間にはいる演算子の組み合わせを求めて
#計算して７になるのか全パターン実施
for v in itertools.product(a, b,c):
    #print ('v',v)
    ans =  l[0] + v[0] + l[1] + v[1] + l[2] + v[2] + l[3]
    #evalで計算
    if eval(ans) == 7:
      print(ans + "=7")
      exit()

Submission status: Accepted

Solution code:
s = input()
num_digits = len(s)


def dfs(index, formula, sum_number):
    if index + 1 == num_digits:
        if sum_number == 7:
            print(formula + "=7")
            exit()
    else:
        dfs(index + 1, formula + "+" + s[index + 1], sum_number + int(s[index + 1]))
        dfs(index + 1, formula + "-" + s[index + 1], sum_number - int(s[index + 1]))


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

Submission status: Accepted

Solution code:
def examC():
    ABCD = S()
    loop = 2**3
    for i in range(loop):
        cur = int(ABCD[0])
        for j in range(3):
            if (i>>j)&1==1:
                cur += int(ABCD[j+1])
            else:
                cur -= int(ABCD[j+1])
        if cur==7:
            cur = i
            break
    ans = str(ABCD[0])
    for i in range(3):
        if (cur>>i)&1 == 1:
            ans += "+"
        else:
            ans += "-"
        ans += str(ABCD[i+1])
    ans += "=7"
    print(ans)

import sys,copy,bisect,itertools
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Submission status: Accepted

Solution code:
n = input()

if ((int(n[0]) + int(n[1])+ int(n[2]) + int(n[3])) ==7):
    print(n[0]+'+'+n[1]+'+'+n[2]+'+'+n[3]+'=7')
elif ((int(n[0]) - int(n[1])+ int(n[2]) + int(n[3])) ==7):
    print(n[0]+'-'+n[1]+'+'+n[2]+'+'+n[3]+'=7')
elif ((int(n[0]) + int(n[1]) - int(n[2]) + int(n[3])) ==7):
    print(n[0]+'+'+n[1]+'-'+n[2]+'+'+n[3]+'=7')
elif ((int(n[0]) + int(n[1]) - int(n[2]) - int(n[3])) ==7):
    print(n[0]+'+'+n[1]+'-'+n[2]+'-'+n[3]+'=7')
elif ((int(n[0]) + int(n[1]) + int(n[2]) - int(n[3])) ==7):
    print(n[0]+'+'+n[1]+'+'+n[2]+'-'+n[3]+'=7')
elif ((int(n[0]) - int(n[1]) - int(n[2]) + int(n[3])) ==7):
    print(n[0]+'-'+n[1]+'-'+n[2]+'+'+n[3]+'=7')
elif ((int(n[0]) - int(n[1]) + int(n[2]) - int(n[3])) ==7):
    print(n[0]+'-'+n[1]+'+'+n[2]+'-'+n[3]+'=7')
elif ((int(n[0]) - int(n[1]) - int(n[2]) - int(n[3])) ==7):
    print(n[0]+'-'+n[1]+'-'+n[2]+'-'+n[3]+'=7')

Submission status: Accepted

Solution code:
a, b, c, d = list(input())
en = ["+", "-"]
for x in en:
  for y in en:
    for z in en:
      s = a + x + b + y + c + z + d
      if eval(s) == 7:
        print(s + "=7")
        exit()

Submission status: Accepted

Solution code:
li = list(input())
op = ["+", "-"]

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

Submission status: Accepted

Solution code:
def output(i):
    symbol = []
    for j in range(n):
        if i>>j & 1:
            symbol.append('+')
        else:
            symbol.append('-')
    out =''
    for k in range(3):
        out += str(a[k]) + symbol[k]
    out += str(a[3])+'=7'
    print(out)

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

n = 3
comb= 2**n

for i in range(comb):
    x = a[0]
    #print('i=', i, '{:03b}'.format(i))
    for j in range(n):
        if i>>j & 1:            
            x += a[j+1]
            #print('+', j, i>>j & 1, a[j+1], x)
        else:
            x -= a[j+1]
            #print('-', j, i>>j & 1, a[j+1], x)
        
    if x ==7:
        #print(str(bin(i)))
        output(i)
        break

Submission status: Accepted

Solution code:
A,B,C,D=list(input())

F=["+","-"]

for x in range(2):
    for y in range(2):
        for z in range(2):
            if eval(A+F[x]+B+F[y]+C+F[z]+D)==7:
                print(A+F[x]+B+F[y]+C+F[z]+D+"=7")
                exit()

Submission status: Accepted

Solution code:
a=input()
import itertools
l=list(itertools.product("+-",repeat=3))
for i in range(8):
    num=a[0]
    for j in range(3):
        num+=l[i][j]
        num+=a[j+1]
    if eval(num)==7:
        print(num+"=7")
        exit()

Submission status: Accepted

Solution code:
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]))
    
    return False
s=input()

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

Submission status: Accepted

Solution code:
S=str(input())
A=int(S[0])
B=int(S[1])
C=int(S[2])
D=int(S[3])
value1=A+B+C+D
value2=A+B+C-D
value3=A+B-C+D
value4=A+B-C-D
value5=A-B+C+D
value6=A-B+C-D
value7=A-B-C+D
value8=A-B-C-D
sum_dict={"{0}+{1}+{2}+{3}".format(A,B,C,D):value1,\
"{0}+{1}+{2}-{3}".format(A,B,C,D):value2,\
"{0}+{1}-{2}+{3}".format(A,B,C,D):value3,\
"{0}+{1}-{2}-{3}".format(A,B,C,D):value4,\
"{0}-{1}+{2}+{3}".format(A,B,C,D):value5,\
"{0}-{1}+{2}-{3}".format(A,B,C,D):value6,\
"{0}-{1}-{2}+{3}".format(A,B,C,D):value7,\
"{0}-{1}-{2}-{3}".format(A,B,C,D):value8}

for k,v in sum_dict.items():
    if v==7:
        print(k+"=7",sep="")
        break

Submission status: Accepted

Solution code:
from operator import sub,add
tmp = input()
A = int(tmp[0])
B = int(tmp[1])
C = int(tmp[2])
D = int(tmp[3])
dic = {0:sub,1:add}
ansdic = {0:"-",1:"+"}
ans = []
for i in [0,1]:
    for j in [0,1]:
        for k in [0,1]:
            tmp1 = dic[i](A,B)
            tmp2 = dic[j](tmp1,C)
            tmp3 = dic[k](tmp2,D)
            if tmp3 == 7:
                ans = [i,j,k]
                break
print(str(A)+ansdic[ans[0]]+str(B)+ansdic[ans[1]]+str(C)+ansdic[ans[2]]+str(D)+"=7")

Submission status: Accepted

Solution code:
a=list(input())
for i in range(4):
    a[i]=int(a[i])
if sum(a)==7:
    print(str(a[0])+'+'+str(a[1])+'+'+str(a[2])+'+'+str(a[3])+'='+'7')
elif a[0]+a[1]+a[2]-a[3]==7:#
    print(str(a[0])+'+'+str(a[1])+'+'+str(a[2])+'-'+str(a[3])+'='+'7')
elif a[0]+a[1]-a[2]+a[3]==7:#
    print(str(a[0])+'+'+str(a[1])+'-'+str(a[2])+'+'+str(a[3])+'='+'7')
elif a[0]-a[1]+a[2]+a[3]==7:#
    print(str(a[0])+'-'+str(a[1])+'+'+str(a[2])+'+'+str(a[3])+'='+'7')
elif a[0]+a[1]-a[2]-a[3]==7:#
    print(str(a[0])+'+'+str(a[1])+'-'+str(a[2])+'-'+str(a[3])+'='+'7')
elif a[0]-a[1]+a[2]-a[3]==7:#
    print(str(a[0])+'-'+str(a[1])+'+'+str(a[2])+'-'+str(a[3])+'='+'7')
elif a[0]-a[1]-a[2]+a[3]==7:#
    print(str(a[0])+'-'+str(a[1])+'-'+str(a[2])+'+'+str(a[3])+'='+'7')
elif a[0]-a[1]-a[2]-a[3]==7:#
    print(str(a[0])+'-'+str(a[1])+'-'+str(a[2])+'-'+str(a[3])+'='+'7')

Submission status: Accepted

Solution code:
a,b,c,d = input()
for i in ('+','-'):
    for j in ('+','-'):
        for k in ('+','-'):
            if eval(a+i+b+j+c+k+d) == 7:
                print(a+i+b+j+c+k+d+'=7')
                exit()

Submission status: Accepted

Solution code:
A,B,C,D = list(map(int,list(input())))
def plus(x):
    if x == 0:
        return '+'
    else:
        return '-'
for i in range(2):
    for j in range(2):
        for k in range(2):
            ans = A+(1-2*i)*B+(1-2*j)*C+(1-2*k)*D
            if ans == 7:
                print(str(A)+plus(i)+str(B)+plus(j)+str(C)+plus(k)+str(D)+'=7')
                break
        else:
            continue
        break
    else:
        continue
    break

Submission status: Accepted

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

def int_to_pm(x):
    if x == 0:
        return '+'
    else:
        return '-'

for i in range(2):
    for j in range(2):
        for k in range(2):
            ans = A + (1-2*i)*B + (1-2*j)*C + (1-2*k)*D
            if ans == 7:
                print(str(A) + int_to_pm(i) + str(B) + int_to_pm(j) + str(C) + int_to_pm(k) + str(D) + '=7')
                break
        else:
            continue
        break
    else:
        continue
    break

Submission status: Accepted

Solution code:
a,b,c,d = input()

for i in range(3**2):
    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

Submission status: Accepted

Solution code:
import sys
s = (input())
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])
ls = ["+","-"]
ans = a+b+c+d
if ans == 7:
    print(str(a)+"+"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
    sys.exit()
ans = a+b+c-d
if ans == 7:
    print(str(a)+"+"+str(b)+"+"+str(c)+"-"+str(d)+"=7")
    sys.exit()
ans = a+b-c+d
if ans == 7:
    print(str(a)+"+"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
    sys.exit()
ans = a-b+c+d
if ans == 7:
    print(str(a)+"-"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
    sys.exit()
ans = a-b-c+d
if ans == 7:
    print(str(a)+"-"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
    sys.exit()
ans = a+b-c-d
if ans == 7:
    print(str(a)+"+"+str(b)+"-"+str(c)+"-"+str(d)+"=7")
    sys.exit()
ans = a-b+c-d
if ans == 7:
    print(str(a)+"-"+str(b)+"+"+str(c)+"-"+str(d)+"=7")
    sys.exit()
ans = a-b-c-d
if ans == 7:
    print(str(a)+"-"+str(b)+"-"+str(c)+"-"+str(d)+"=7")
    sys.exit()

Submission status: Accepted

Solution code:
s=input()
for i in range(2**3):
    op = ['+','+','+']
    for j in range(3):
        if ((i >> j) & 1):
            op[j] = '-'
    if eval(s[0]+op[0]+s[1]+op[1]+s[2]+op[2]+s[3]) == 7:
        print(s[0]+op[0]+s[1]+op[1]+s[2]+op[2]+s[3]+'=7')
        break

Submission status: Accepted

Solution code:
n = input()
a,b,c,d = n[0], n[1], n[2], n[3] 

def calc(arg1, arg2, arg3):
    if arg1 == 0:
        arg2 += "+" + arg3
    else:
        arg2 += "-" + arg3
    return arg2


for op1 in range(2):
    for op2 in range(2):
        for op3 in range(2):
            ans = a
            ans = calc(op1, ans, b)
            ans = calc(op2, ans, c)
            ans = calc(op3, ans, d)
            if eval(ans) == 7:
               break
        else:
            continue
        break
    else:
        continue
    break

print(ans + "=7")

Submission status: Accepted

Solution code:
a,b,c,d = list(map(int, list(input())))
for op1 in range(2):
    for op2 in range(2):
        for op3 in range(2):
            if a + b * [1,-1][op1] + c * [1,-1][op2] + d * [1,-1][op3] == 7:
                print("%d%s%d%s%d%s%d=7" % (a, ["+", "-"][op1], b, ["+", "-"][op2], c, ["+", "-"][op3], d))
                exit()

Submission status: Accepted

Solution code:
from sys import exit
A, B, C, D = map(int, list(input()))
ops = ["+", "-"]
for op1 in ops:
    for op2 in ops:
        for op3 in ops:
            expr = "{0}{1}{2}{3}{4}{5}{6}".format(A, op1, B, op2, C, op3, D)
            if eval(expr) == 7:
                print(expr + "=7")
                exit()

Submission status: Accepted

Solution code:
S = input()
ans = ''


def calc(i, s, num):
    if i == 3:
        if num == 7:
            global ans
            ans = s + '=7'
    else:
        calc(i+1, s+'+'+S[i+1], num+int(S[i+1]))
        calc(i+1, s+'-'+S[i+1], num-int(S[i+1]))


def solve():
    calc(0, S[0], int(S[0]))
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
def dfs(i,e,s):
    if i==n-1:
        if s==7:
            print(e+'=7')
            exit()
    
    else:
        dfs(i+1,e+'+'+a[i+1],s+int(a[i+1]))
        dfs(i+1,e+'-'+a[i+1],s-int(a[i+1]))
    
a=input()
n=len(a)
dfs(0,a[0],int(a[0]))

Submission status: Accepted

Solution code:
#Train Ticket
A, B, C, D = input()
A = int(A)
B = int(B)
C = int(C)
D = int(D)
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")

Submission status: Accepted

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

def int_to_pm(x):
    if x == 0:
        return '+'
    else:
        return '-'

for i in range(2):
    for j in range(2):
        for k in range(2):
            ans = A + (1-2*i)*B + (1-2*j)*C + (1-2*k)*D
            if ans == 7:
                print(str(A) + int_to_pm(i) + str(B) + int_to_pm(j) + str(C) + int_to_pm(k) + str(D) + '=7')
                break
        else:
            continue
        break
    else:
        continue
    break

Submission status: Accepted

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

Submission status: Accepted

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

bcd = [b, c, d]
var = [['+', '+', '+'],['+', '+', '-'], ['+', '-', '+'], ['+', '-', '-'], ['-', '+', '+'], ['-', '+', '-' ], ['-', '-', '+'], ['-', '-', '-']]
for va in var:
    ans = a
    for i, op in zip(bcd, va):
        if op == '+':
            ans += i
        else:
            ans -= i
    if ans == 7:
        print('{}{}{}{}{}{}{}=7'.format(a,va[0],b,va[1],c,va[2],d))
        break

Submission status: Accepted

Solution code:
s=int(input())
A=s//1000
B=s//100%10
C=s//10%10
D=s%10

for k in range(1<<3):
    op1=k&1
    op2=k>>1&1
    op3=k>>2&1
    t=A;ans=str(A)
    if op1:
        t+=B;ans+='+'+str(B)
    else:
        t-=B;ans+='-'+str(B)
    if op2:
        t+=C;ans+='+'+str(C)
    else:
        t-=C;ans+='-'+str(C)
    if op3:
        t+=D;ans+='+'+str(D)+'=7'
    else:
        t-=D;ans+='-'+str(D)+'=7'
    if t==7:
        print(ans)
        break

Submission status: Accepted

Solution code:
ABCD = input()

a = ABCD[0]
f = int(a)

def recur(total,formula,i):
  #=3回足せば
  if i == 4:
    #合計が7であれば
    if total == 7:
      print(formula+"=7")
      exit()
  #ABCD[0]に対してABCD[1~3]まで3回足し算or引き算を実行する
  #足し算引き算の再帰実行に応じて+-の演算子を持っておく
  else:
    recur(total + int(ABCD[i]),formula + "+" + ABCD[i],i + 1),
    recur(total - int(ABCD[i]),formula + "-" + ABCD[i],i + 1)
  
recur(f,a,1)

Submission status: Accepted

Solution code:
S = input()
for i in range(2 ** 3):
    pm = ["-"] * 3
    for j in range(3):
        if ((i >> j) & 1):  # 下から数えてj番目が1かどうか
            pm[3-1 - j] = "+"
    if eval(S[0]+pm[0]+S[1]+pm[1]+S[2]+pm[2]+S[3]) == 7:
        print(S[0]+pm[0]+S[1]+pm[1]+S[2]+pm[2]+S[3]+"=7")
        exit()

Submission status: Accepted

Solution code:
s = list(input())

for i in range(2**3):
	res = int(s[0])
	m = []
	for j in range(3):
		if i>>j&1:
			res += int(s[j+1])
			m.append("+")
		else:
			res -= int(s[j+1])
			m.append("-")
	if res == 7:
		m.append("")
		break
		
for i in range(4):
	print(s[i] + m[i], end = "")
print("=7")

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
ABCD = list(map(int, list(input())[: -1]))
t = [[] for _ in range(4)]
t[0].append((ABCD[0], ""))
for i in range(3):
  for j in range(len(t[i])):
    t[i + 1].append((t[i][j][0] + ABCD[i + 1], t[i][j][1] + "+"))
    t[i + 1].append((t[i][j][0] - ABCD[i + 1], t[i][j][1] + "-"))
#print(t)
for i in range(len(t[-1])):
  if t[-1][i][0] == 7:
    print(str(ABCD[0]) + t[-1][i][1][0] + str(ABCD[1]) + t[-1][i][1][1] + str(ABCD[2]) + t[-1][i][1][2] + str(ABCD[3]) + "=7")
    exit(0)

Submission status: Accepted

Solution code:
ss=input()
s=[0]*4
for i in range(len(ss)):
  s[i]=int(ss[i])
dif=7-s[0]
ans=str(s[0])
found=False

for b in [s[1],-s[1]]:
  for c in [s[2],-s[2]]:
    for d in [s[3],-s[3]]:
      if b+c+d==dif:
        if b==s[1]:
          ans+="+"
        ans+=str(b)
        if c==s[2]:
          ans+="+"
        ans+=str(c)
        if d==s[3]:
          ans+="+"
        ans+=str(d)
        found=True
        break
    if found:
      break
  if found:
    break
print(ans+"=7")

Submission status: Accepted

Solution code:
ss=input()
s=[0]*4
for i in range(len(ss)):
  s[i]=int(ss[i])
dif=7-s[0]
ans=str(s[0])
found=False
for b in [s[1],-s[1]]:
  for c in [s[2],-s[2]]:
    for d in [s[3],-s[3]]:
      if b+c+d==dif:
        if b==s[1]:
          ans+="+"
        else:
          ans+="-"
        ans+=str(s[1])
        if c==s[2]:
          ans+="+"
        else:
          ans+="-"
        ans+=str(s[2])
        if d==s[3]:
          ans+="+"
        else:
          ans+="-"
        ans+=str(s[3])
        found=True
        break
    if found:
      break
  if found:
    break
print(ans+"=7")

Submission status: Accepted

Solution code:
#ABC079C - Train Ticket
import sys
S = list(input())
def dfs(i,f,s):
    if i == len(S)-1:
        if s == 7:
            print(f+"=7")
            sys.exit()
    else:
        return dfs(i+1, f+"+"+S[i+1], s+int(S[i+1])), dfs(i+1, f+"-"+S[i+1], s-int(S[i+1]))
dfs(0,S[0],int(S[0]))

Submission status: Accepted

Solution code:
ABCD = list(map(int,input()))
op=[""]*3
def dfs(opN, ans):
    if opN == 3:
        return ans == 7
    op[opN] = "+"
    if (dfs(opN + 1, ans + ABCD[opN + 1])):
        return True
    op[opN] = "-"
    if (dfs(opN + 1, ans - ABCD[opN + 1])):
        return True
    return False
dfs(0,ABCD[0])
print(str(ABCD[0])+op[0]+str(ABCD[1])+op[1]+str(ABCD[2])+op[2]+str(ABCD[3])+"=7")

Submission status: Accepted

Solution code:
abcd = list(input())

op = ["+", "+", "+", ""]

for i in "+-":
    op[0] = i
    for j in "+-":
        op[1] = j
        for k in "+-":
            op[2] = k
            expression = "".join(l+m for l, m in zip(abcd, op))
            if eval(expression) == 7:
                print(expression+"=7")
                quit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys 
target = list(map(int,input()))

if target[0]+target[1]+target[2]+target[3] == 7:
	print(str(target[0])+'+'+str(target[1])+'+'+str(target[2])+'+'+str(target[3])+'=7')
	sys.exit()
elif target[0]+target[1]+target[2]-target[3] == 7:
	print(str(target[0])+'+'+str(target[1])+'+'+str(target[2])+'-'+str(target[3])+'=7')
	sys.exit()
elif target[0]+target[1]-target[2]+target[3] == 7:
	print(str(target[0])+'+'+str(target[1])+'-'+str(target[2])+'+'+str(target[3])+'=7')
	sys.exit()
elif target[0]+target[1]-target[2]-target[3] == 7:
	print(str(target[0])+'+'+str(target[1])+'-'+str(target[2])+'-'+str(target[3])+'=7')
	sys.exit()
elif target[0]-target[1]+target[2]+target[3] == 7:
	print(str(target[0])+'-'+str(target[1])+'+'+str(target[2])+'+'+str(target[3])+'=7')
	sys.exit()
elif target[0]-target[1]+target[2]-target[3] == 7:
	print(str(target[0])+'-'+str(target[1])+'+'+str(target[2])+'-'+str(target[3])+'=7')
	sys.exit()
elif target[0]-target[1]-target[2]+target[3] == 7:
	print(str(target[0])+'-'+str(target[1])+'-'+str(target[2])+'+'+str(target[3])+'=7')
	sys.exit()
elif target[0]-target[1]-target[2]-target[3] == 7:
	print(str(target[0])+'-'+str(target[1])+'-'+str(target[2])+'-'+str(target[3])+'=7')
	sys.exit()

Submission status: Accepted

Solution code:
a, b, c, d = input()
ops = ['+', '+', '+']
ans = []

def dfs(i, ops):
    ops = ops.copy()
    if eval(a + ops[0] + b + ops[1] + c + ops[2] + d) == 7:
        ans.append(a + ops[0] + b + ops[1] + c + ops[2] + d + '=7')
    elif i == 3:
        pass
    else:
        dfs(i + 1, ops)
        ops[i] = '-'
        dfs(i + 1, ops)

dfs(0, ops)

print(ans[0])

Submission status: Accepted

Solution code:
abcd = list(input())
for i in range(2**3):
    tmp = abcd[:]
    bag = []
    for j in range(2, -1, -1):
        if (i >> j) & 1:
            tmp.insert(j+1, "+")
        else:
            tmp.insert(j+1, "-")
    if (eval(''.join(tmp)) == 7):
        print(''.join(tmp), "=7", sep="")
        exit()

Submission status: Accepted

Solution code:
S = input()

s = S[0]
n = int(s)

def F(ans,total,i):
  if i == 4:
    if total == 7:
      print(ans + "=7")
      exit()

  else:
    return F(ans + "+" + S[i],total + int(S[i]),i + 1),F(ans + "-" + S[i],total - int(S[i]),i + 1)

F(s,n,1)

Submission status: Accepted

Solution code:
s = input()
for i in range(2 ** 3):
    ans = s[0]
    for j in range(3):
        if ((i >> j) & 1):
            ans += "+" + s[j + 1]
        else:
            ans += "-" + s[j + 1]

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

Submission status: Accepted

Solution code:
s = input()
for i in range(2 ** 3):
    res = int(s[0])
    ans = s[0]
    for j in range(3):
        if ((i >> j) & 1):
            res += int(s[j + 1])
            ans += "+" + s[j + 1]
        else:
            res -= int(s[j + 1])
            ans += "-" + s[j + 1]
    if res == 7:
        # print(res)
        print(ans + "=7")
        exit()

Submission status: Accepted

Solution code:
ABCD = list(input())

def dp(i, abcd, s):
  if i == 3:
    s += abcd[3]
    if eval(s) == 7:
      return s, True
    else:
      return s, False
  for c in ['+', '-']:
    d, f = dp(i + 1, abcd, s + abcd[i] + c)
    if f:
      return d, True
  else:
    return d, False

s, f = dp(0, ABCD, '')
print(s + '=7')

Submission status: Accepted

Solution code:
import sys
s = input()
n = 4

for i in range(2**(n-1)):
    e = ""
    for j in range(n-1):
        if (i>>j)& 1 == 1:
            e += s[j] + "+"
        else:
            e += s[j] + "-"
    e += s[-1]
    if eval(e) == 7:
        print(e+"=7")
        sys.exit()

Submission status: Accepted

Solution code:
def f(a,b,i):
  if i==4:
    if b==7:
      print(a+"=7")
      exit()
  else:
    return f(a+"+"+s[i],b+int(s[i]),i+1),f(a+"-"+s[i],b-int(s[i]),i+1)

s=input()
f(s[0],int(s[0]),1)

Submission status: Accepted

Solution code:
S=input()
l=len(S)-1
ans =0
for i in range(1 << l):
    s=S[0]
    for j in range(l):
        if (i >> j)&1:
            s+="+"
        else:
            s+="-"
        s+=S[j+1]
    if eval(s)==7:
        print(s+"=7")
        exit()

Submission status: Accepted

Solution code:
l = list(input())
if int(l[0]) + int(l[1]) + int(l[2]) + int(l[3]) == 7:
  print (l[0]+ "+" +l[1]+ "+" +l[2]+ "+" +l[3]+ "=7");exit()
elif int(l[0]) + int(l[1]) + int(l[2]) - int(l[3]) == 7:
  print (l[0]+ "+" +l[1]+ "+" +l[2]+ "-" +l[3]+ "=7");exit()
elif int(l[0]) + int(l[1]) - int(l[2]) + int(l[3]) == 7:
  print (l[0]+ "+" +l[1]+ "-" +l[2]+ "+" +l[3]+ "=7");exit()
elif int(l[0]) + int(l[1]) - int(l[2]) - int(l[3]) == 7:
  print (l[0]+ "+" +l[1]+ "-" +l[2]+ "-" +l[3]+ "=7");exit()
elif int(l[0]) - int(l[1]) + int(l[2]) + int(l[3]) == 7:
  print (l[0]+ "-" +l[1]+ "+" +l[2]+ "+" +l[3]+ "=7");exit()
elif int(l[0]) - int(l[1]) + int(l[2]) - int(l[3]) == 7:
  print (l[0]+ "-" +l[1]+ "+" +l[2]+ "-" +l[3]+ "=7");exit()
elif int(l[0]) - int(l[1]) - int(l[2]) + int(l[3]) == 7:
  print (l[0]+ "-" +l[1]+ "-" +l[2]+ "+" +l[3]+ "=7");exit()
elif int(l[0]) - int(l[1]) - int(l[2]) - int(l[3]) == 7:
  print (l[0]+ "-" +l[1]+ "-" +l[2]+ "-" +l[3]+ "=7");exit()

Submission status: Accepted

Solution code:
A,B,C,D =input()
E ="+-"

for i in E:
  for j in E:
    for k in E:
      s=A+i+B+j+C+k+D
      if eval(s)==7:
        print(s+"=7")
        exit()

Submission status: Accepted

Solution code:
N = int(input())

for i in range(2**3, 2**4):
    b = bin(i)
    cnt = N//10**3
    for j in range(3):
        if b[j+3] == "1":
            cnt += (N%10**(3-j))//10**(2-j)
        else:
            cnt -= (N%10**(3-j))//10**(2-j)
    if cnt == 7:
        B = b
        break
        
ans = ["0"]*9
ans[0] = str(N//10**3)
ans[2] = str((N%10**3)//10**2)
ans[4] = str((N%10**2)//10)
ans[6] = str(N%10)
for i in range(3):
    if B[i+3] == "1":
        ans[2*i+1] = "+"
    else:
        ans[2*i+1] = "-"
        
ans[7] = "="
ans[8] = "7"
print("".join(ans))