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:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

S = input().strip()
res = 7
num = list()
for i in range(len(S)):
    num.append(int(S[i]))

for b in range(2**(3)):
    b_str = format(b, 'b').zfill(len(S)-1)
    sum = num[0]
    for i in range(len(num) - 1):
        if b_str[i] == '0':
            sum -= num[i+1]
        else:
            sum += num[i+1]
    if sum == res:
        break

plus_or_minus = list()
for i in range(3):
    if b_str[i] == '0':
        plus_or_minus.append('-')
    else:
        plus_or_minus.append('+')
print('{}{}{}{}{}{}{}=7'.format(num[0], plus_or_minus[0], num[1], plus_or_minus[1], num[2], plus_or_minus[2], num[3]))

Submission status: Accepted

Solution code:
import itertools
s = input()
ans=0
for i in list(itertools.product([0,1], repeat=len(s)-1)):
    b = 0
    a = int(s[0])
    l = [a]+[0]*(2*(len(s)-1))
    for j in range(len(s)-1):
        if i[j] == 0:
            a += int(s[j+1])
            l[2*j+1] = '+'
            l[2*j+2] = str(s[j+1])
        else:
            a -= int(s[j+1])
            l[2*j+1] = '-'
            l[2*j+2] = str(s[j+1])
    if a == 7:
        l[0] = str(s[0])
        l += '=7'
        l = ''.join(l)
        print(l)
        break

Submission status: Accepted

Solution code:
A,B,C,D = (int(T) for T in list(input()))
ABCD = [A+B+C+D,A+B+C-D,A+B-C+D,A+B-C-D,A-B+C+D,A-B+C-D,A-B-C+D,A-B-C-D]
Op   = ['+++','++-','+-+','+--','-++','-+-','--+','---']
Disp = list(Op[ABCD.index(7)])
print('{}{}{}{}{}{}{}=7'.format(A,Disp[0],B,Disp[1],C,Disp[2],D))

Submission status: Accepted

Solution code:
import sys
a = list(str(input()))
#print(a)


for i in range(1 << 3):
    op = ['+']*3
    #range 3 because we need to look at all the bits
    for j in range(3):
        if (i >> j)&1:
            #starting from the right
            op[j] = "-"
    op.append('')        
    res = ''
    
    for x,y in zip(a,op):
        res += x+y
        
    if eval(res) == 7:
        print(res+'=7')
        sys.exit()

Submission status: Accepted

Solution code:
s = input()
a = s[0]
b = s[1]
c = s[2]
d = s[3]
op = ['+','-']

for v in op:
    for w in op:
        for x in op:
            l = str(a+v+b+w+c+x+d)
            if eval (l) == 7:
                print (l+"=7")
                exit ()

Submission status: Accepted

Solution code:
import itertools
a, b, c, d = map(int, list(input()))
l1 = [1, -1]
l2 = [1, -1]
l3 = [1, -1]

for op1, op2, op3 in itertools.product(l1, l2, l3):
    tmp = a + b*op1 + c*op2 + d*op3
    if tmp == 7:
        break

op1, op2, op3 = map(lambda x: "+" if x==1 else "-", [op1, op2, op3])

print(str(a)+op1+str(b)+op2+str(c)+op3+str(d)+"=7")

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import product
def main():
    a, b, c, d = list(input())
    ops = tuple(product(('+', '-'), repeat=3))
    for opse in ops:
        o = a + opse[0] + b + opse[1] + c + opse[2] + d
        s = eval(o)
        if s == 7:
            r = o + '=7'
            print(r)
            sys.exit()

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

X=input()

N=len(X)
n=N-1
A=0
num=0
total=0

for i in range(2**n):
    A=X[0]
    for j in range(n):
        if (i>>j)&1:
            A+=".+"+X[j+1]
        else:
            A+=".-"+X[j+1]

    num=list(map(int,A.split(".")))
    total=sum(num)

    if total==7:
        break

print(A.replace(".","")+"=7")

Submission status: Accepted

Solution code:
abcd = list(input())

for bit in range(1 << 3):
    answer = 0
    op = ["-", "-", "-"]
    for i in range(3):
        if (bit >> i) & 1:
            op[i] = "+"
    if eval(abcd[0] + op[0] + abcd[1] + op[1] + abcd[2] + op[2] + abcd[3]) == 7:
        answer = abcd[0] + op[0] + abcd[1] + op[1] + abcd[2] + op[2] + abcd[3] + "=7"
        break
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
num_li = list(input())
for i in range(2**3):
    li = ['+']*3
    q = num_li[0]
    for j in range(3):
        if ((i>>j) & 1):
            li[j] = '-'
        q += li[j] + num_li[j+1]
    if eval(q) == 7:
        print('{}=7'.format(q))
        break

Submission status: Accepted

Solution code:
from itertools import product
A,B,C,D = list(input())
for k in list(product(['+','-'],repeat=3)):
    k = A + k[0] + B + k[1] + C + k[2] + D
    if eval(k) == 7:
        print('{}=7'.format(k))
        break

Submission status: Accepted

Solution code:
n = input()
for i in range(2**3):
    op =[]
    for j in range(3):
        if i >> j & 1:
            op.append('+')
        else:
            op.append('-')
    formula = n[0] + op[0] + n[1] + op[1] + n[2] + op[2] + n[3]
    if eval(formula) == 7:
        print(formula + '=7')
        exit()

Submission status: Accepted

Solution code:
S = input()
N = len(S)

for i in range(2**(N-1)):
    tmp = int(S[0])
    sentence = S[0]

    for j in range(N-1):
        flag = (i >> j) & 1

        if flag: # +の場合
            tmp += int(S[j+1])
            sentence += "+" + S[j+1]
        else:
            tmp -= int(S[j+1])
            sentence += "-" + S[j+1]

    if tmp == 7:
        print(sentence + "=7")
        exit()

Submission status: Accepted

Solution code:
s=input()
n=4-1
for i in range(1<<n):
    lst=list(s)
    for j in range(n):
        if ((i>>j)&1):
            lst.insert(2*j+1,"+")
            # print(lst)
        else:
            lst.insert(2*j+1,"-")
    if(eval("".join(lst))==7):
        print(("".join(lst))+"=7")
        break

Submission status: Accepted

Solution code:
num = input()

for bit in range(2**3):
    op = ["+", "+", "+"]
    for i in range(3):
        if (bit >> i) & 1:
            op[i] = "-"
    if eval(num[0]+op[0]+num[1]+op[1]+num[2]+op[2]+num[3]) == 7:
        print("{}=7".format(num[0]+op[0]+num[1]+op[1]+num[2]+op[2]+num[3]))
        break

Submission status: Accepted

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

for i in range(2**3):
  ans = a
  temp=[]
  for j in range(3):#1=+,0=-
    if i >> j & 1:
      temp.append("+")
    else:
      temp.append("-")
  for i,j in zip([b,c,d],temp):
    if j == "+":
      ans+=i
    else:
      ans-=i
  if ans == 7:
    print(str(a) + temp[0] + str(b) + temp[1] + str(c) + temp[2] +str(d) + "=7")
    break

Submission status: Accepted

Solution code:
s = input()

def recursum(count, f, sum):
    if count == 3:
        if sum == 7:
            print(f+"=7")
            exit()
    else:
        recursum(count+1, f+"-"+s[count+1], sum-int(s[count+1]))
        recursum(count+1, f+"+"+s[count+1], sum+int(s[count+1]))

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

Submission status: Accepted

Solution code:
def GSB(x):
	counter=0
	while x!=0:
		counter+=1
		x=x>>1
	return counter


N=[int(x) for x in (list(input()))]
combinations=[int(x) for x in range((2**4))]
for i in combinations:
	checker=[x for x in N]
	j=0
	z=GSB(i)
	while j!=z and i!=0:
		if i&1==1:
			checker[j]*=-1
		i=i>>1
		j+=1
	if sum(checker)==7 and checker[0]>=0:
		checker=checker + [-1]
		for i in range(4):
			if checker[i+1]>=0:
				print(checker[i],end="+")
			else:
				print(checker[i],end="")
		print("=7")
		exit()

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().strip()


def main():
    A = list(map(int, list(input())))
    for op in range(1 << 3):
        ans = A[0]
        for i in range(3):
            if op & (1 << i):
                ans += A[i + 1]
            else:
                ans -= A[i + 1]
        if ans != 7: continue
        out = [str(A[0]), None, str(A[1]), None, str(A[2]), None, str(A[3]), "=7"]
        for i in range(3):
            if op & (1 << i):
                out[2 * i + 1] = "+"
            else:
                out[2 * i + 1] = "-"
        print("".join(out))
        return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s=input()
def dfs(i, f, sum):
    if i == 3:
        if sum == 7:
            # 答えは1つ出力すれば良いので =7 になれば終了
            print(f + "=7")
            exit()
    else:
        # 式 f の末尾に符号と次の数字を追加し、その分 sum に加減する
        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]))

Submission status: Accepted

Solution code:
# n=int(input())
# a,b=map(int,input().split())
# l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
s = list(input())
l = [int(s[0]), int(s[1]), int(s[2]), int(s[3])]

for i in range(2**3):
    opt = ['+', '+', '+']
    for j in range(3):
        if ((i >> j) & 1):
            opt[j] = '-'
    test = l[0]
    for k in range(3):
        if opt[k] == '+':
            test += l[k+1]
        else:
            test -= l[k+1]
    if test == 7 :
        break
printstr=str(l[0])
for i in range(3):
    printstr+=opt[i]+str(l[i+1])
print(printstr+'=7')

Submission status: Accepted

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

ans = A
for x in range(2):
    for y in range(2):
        for z in range(2):
            if x == 0: ans += B; o = "+"
            else:ans -= B; o = "-"
            if y == 0:ans += C; oo = "+"
            else:ans -= C; oo = "-"
            if z == 0:ans += D; ooo = "+"
            else:ans -= D; ooo = "-"
            #print(x,y,z,str(ans).rjust(2),A,o,B,oo,C,ooo,D)
            if ans == 7: print("".join(list(map(str,[A,o,B,oo,C,ooo,D,"=7"])))); exit()
            ans = A

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    nums = [int(i) for i in input()]
    #1なら+,0なら-
    for i in range(1<<3):
        s = nums[0]
        ans = str(nums[0])
        for j in range(3):
            if (i>>j) & 1:
                s += nums[j+1]
                ans += '+' + str(nums[j+1])
            else:
                s -= nums[j+1]
                ans += '-' + str(nums[j+1])
        if s == 7:
            print(ans+'=7')
            return
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import product
a,b,c,d=map(int,input())
for op1,op2,op3 in product((1,-1),repeat=3):
    if a+op1*b+op2*c+op3*d==7:
        x='+'if op1==1else'-'
        y='+'if op2==1else'-'
        z='+'if op3==1else'-'
        print('{}{}{}{}{}{}{}=7'.format(a,x,b,y,c,z,d))
        exit()

Submission status: Accepted

Solution code:
num=open(0).read()
A=int(num[0])
B=int(num[1])
C=int(num[2])
D=int(num[3])
for i in range(2):
    for j in range(2):
        for k in range(2):
            b=B*(-1)**i
            c=C*(-1)**j
            d=D*(-1)**k
            ans=A+b+c+d
            if ans==7:
                sgn=[i,j,k]
                for l in range(3):
                    if sgn[l]%2==0:
                        sgn[l]='+'
                    else:
                        sgn[l]='-'
print(str(A)+sgn[0]+str(B)+sgn[1]+str(C)+sgn[2]+str(D)+'=7')

Submission status: Accepted

Solution code:
import sys
s = input()
n = len(s)
ans = 7
for bit in range(2**(n - 1)):
    f = s[0]
    for i in range(n - 1):
        if bit & (1 << i):#i番目の数が1なら以下の処理を行う
            f += "+"
            f += s[i + 1]
        else:#i番目の数が0なら以下の処理を行う
            f += "-"
            f += s[i + 1]
    if eval(f)==7:
        print(f+"=7")
        sys.exit()

Submission status: Accepted

Solution code:
a,b,c,d = input()
op=['+','-']
ans=''
for i in range(2):
  for j in range(2):
    for k in range(2):
      if eval(a+op[i]+b+op[j]+c+op[k]+d) == 7:
        ans=a+op[i]+b+op[j]+c+op[k]+d+"=7"
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import itertools
def main():
    number = input()
    for prod in list(itertools.product([0, 1], repeat=3)):
        ans = number[0]
        sum = int(ans)
        for i, p in enumerate(prod):
            if p == 0:
                sum += int(number[i+1])
                ans += '+' + number[i+1]
            else:
                sum -= int(number[i+1])
                ans += '-' + number[i+1]
        if sum == 7:
            print(ans + '=7')
            return
                
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
s = input()
p = itertools.product(['+','-'], repeat = 3)
for i in p:
    ev = '{}{}{}{}{}{}{}'.format(s[0],i[0],s[1],i[1],s[2],i[2],s[3])
    if eval(ev) == 7:
        print(ev+'=7')
        break

Submission status: Accepted

Solution code:
A,B,C,D = input()
op = ["+","-"]

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

Submission status: Accepted

Solution code:
import sys
num = list(input())
op1 = "+"
for x in range(2):
  op2 = "+"
  for y in range(2):
    op3 = "+"
    for z in range(2):
      fml = (num[0]+op1+num[1]+op2+num[2]+op3+num[3])
      if eval(fml) == 7:
        print(num[0]+op1+num[1]+op2+num[2]+op3+num[3]+"=7")
        sys.exit()
      op3 = "-"
    op2 = "-"
  op1 = "-"

Submission status: Accepted

Solution code:
tic=list(input())

b=int(tic[1])
c=int(tic[2])
d=int(tic[3])

a=int(tic[0])
B=[b,-b]
C=[c,-c]
D=[d,-d]

ans=0
ans2=tic[0]

for i in range(2):
  for j in range(2):
    for k in range(2):
      ans=a+B[i]+C[j]+D[k]
      if ans==7:
        b=B[i]
        c=C[j]
        d=D[k]
ans=[b,c,d]

for an in ans:
  if an >= 0:
    ans2 += '+'+str(an)
  else:
    ans2 += str(an)
    
ans2 += '=7'

print(ans2)

Submission status: Accepted

Solution code:
a,b,c,d=[int(i) for i in 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))
else:
    print("{}-{}-{}-{}=7".format(a,b,c,d))

Submission status: Accepted

Solution code:
s = list(input())

a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])
if a + b + c + d ==7:
    print("{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()
A = [int(s) for s in S]
for i in range(8):
    ii = i
    Sum = A[0]
    for j in range(3):
        if (i >> j) & 1:
            Sum += A[j+1]
        else:
            Sum -= A[j+1]
    if Sum == 7:
        Ans = str(A[0])
        for j in range(3):
            if (i >> j) & 1:
                Ans += "+"
            else:
                Ans += "-"
            Ans += str(A[j+1])
        Ans += "=7"
        print(Ans)
        break

Submission status: Accepted

Solution code:
n_str = list(input())
n = [int(i) for i in n_str]
l = len(n)-1
for i in range(2 ** l):
    sum = n[0]
    op_list = []
    for j in range(l):
        if (i >> j) & 1:
            sum += n[j+1]
            op_list.append('+')
        else:
            sum -= n[j+1]
            op_list.append('-')
    #print(sum, op_list)
    if sum == 7:
        print(n_str[0]+op_list[0]+n_str[1]+op_list[1]+n_str[2]+op_list[2]+n_str[3]+'=7')
        exit()

Submission status: Accepted

Solution code:
a, b, c, d = map(int, list(input()))
if a-b-c-d==7 :
    print(f"{a}-{b}-{c}-{d}=7")
elif a-b-c+d==7 :
    print(f"{a}-{b}-{c}+{d}=7")
elif a-b+c-d==7 :
    print(f"{a}-{b}+{c}-{d}=7")
elif a-b+c+d==7 :
    print(f"{a}-{b}+{c}+{d}=7")
elif a+b-c-d==7 :
    print(f"{a}+{b}-{c}-{d}=7")
elif a+b-c+d==7 :
    print(f"{a}+{b}-{c}+{d}=7")
elif a+b+c-d==7 :
    print(f"{a}+{b}+{c}-{d}=7")
elif a+b+c+d==7 :
    print(f"{a}+{b}+{c}+{d}=7")

Submission status: Accepted

Solution code:
a = list(map(int, input()))

for i in range(8):
    k = a[0]
    b = []
    for j in range(3):
        if ((i >> j) & 1):
            k += a[j+1]
            b.append("+")
        else:
            k -= a[j+1]
            b.append("-")
    if k == 7:
        break

ans = ""
for i in range(3):
    ans += str(a[i]) + b[i]
ans += str(a[3]) + "=7"

print(ans)

Submission status: Accepted

Solution code:
from itertools import product
ABCD = input()
for op in product('+-',repeat=len(ABCD)-1):
  n = int(ABCD[0])
  for i in range(1,len(ABCD)):
    if op[i-1] == '+':
      n += int(ABCD[i])
    else:
      n -= int(ABCD[i])
  if n == 7:
    print(ABCD[0],end='')
    for i in range(1,len(ABCD)):
      print(op[i-1]+ABCD[i],end='')
    print('=7')
    break

Submission status: Accepted

Solution code:
S = input()
ans = ""
for i in range(2**(len(S)-1)):
    total = int(S[0])
    for j in range(1, len(S)):
        if (i >> j-1) & 1:
            total += int(S[j])
        else:
            total -= int(S[j])
    if total == 7:
        for j in range(len(S)-1):
            ans += S[j]
            if i >> j & 1:
                ans += "+"
            else:
                ans += "-"
        ans += S[-1]
        break
print(ans + "=7")

Submission status: Accepted

Solution code:
# バイナリーサーチ
ABCD=list(map(int,input()))
for i in range(2**4):
    sm = ABCD[0]
    ans = [str(sm)]
    for j in range(1,4):
        bit = i & 1
        if bit:
            sm += ABCD[j]
            ans.append('+')
            ans.append(str(ABCD[j]))
        else:
            sm -= ABCD[j]
            ans.append('-')
            ans.append(str(ABCD[j]))
        i = i >> 1
    ans.append('=7')
    if sm == 7:
        print(''.join(ans))
        exit()

Submission status: Accepted

Solution code:
n=list(input())
for i in range(len(n)):
    n[i]=int(n[i])

ans=""
for i in range(1<<3):
    num=n[0]
    num += n[1] if (i>>0)&1 else -n[1]
    num += n[2] if (i>>1)&1 else -n[2]
    num += n[3] if (i>>2)&1 else -n[3]
    if num==7:
        ans=str(n[0])
        ans+= "+" if (i>>0)&1 else "-"
        ans+= str(n[1])
        ans+= "+" if (i>>1)&1 else "-"
        ans+= str(n[2])
        ans+= "+" if (i>>2)&1 else "-"
        ans+=str(n[3])+"=7"

print(ans)

Submission status: Accepted

Solution code:
ABCD = input()

for bit in range(1<<3):
    f = ABCD[0]
    ans = int(ABCD[0])
    for i in range(3):
        if bit & (1<<i):
            f += '+'
            ans += int(ABCD[i+1])
        else :
            f += '-'
            ans -= int(ABCD[i+1])
        f += ABCD[i+1]
    if ans == 7:
        break
print(f+'=7')

Submission status: Accepted

Solution code:
import sys
import math
# -*- coding: utf-8 -*-

def calc(operation,target,src):
    if operation == 0:
        return target - src
    return target + src

def operation(int_operation):
    if int_operation == 0:
        return "-"
    return "+"

nums=list(input())

#答え
answer=7

# 0:- 1:+
for i in [0,1]:
    for j in [0,1]:
        for k in [0,1]:
            chalange = int(nums[0])
            chalange = calc(i,chalange,int(nums[1]))
            chalange = calc(j,chalange,int(nums[2]))
            chalange = calc(k,chalange,int(nums[3]))
            if chalange == answer:
                print(nums[0] + operation(i) + nums[1] + operation(j) + nums[2] + operation(k) + nums[3] + "=7" )
                break
        else:
            continue
        break
    else:
        continue
    break

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
s = input()
a = [int(c) for c in s]

for i in range(2 ** 3):
    ptn = []
    num = a[0]

    for j in range(3):
        if (i >> j) & 1:
            ptn.append("+")
            num += a[j + 1]

        else:
            ptn.append("-")
            num -= a[j + 1]
    
    if num == 7:
        print("{}{}{}{}{}{}{}=7".format(a[0], ptn[0], a[1], ptn[1], a[2], ptn[2], a[3]))
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# C - Train Ticket
ABCD = input()

for i in range(8):
	binary = format(i, 'b').zfill(3)
	sum = int(ABCD[0])
	ans = ABCD[0]
	
	for j in range(3):
		s = ABCD[j + 1]
		
		if binary[j] == '1':
			sum += int(s)
			ans += '+' + s
		else:
			sum -= int(s)
			ans += '-' + s
	
	if sum == 7:
		ans += '=7'
		print(ans)
		break

Submission status: Accepted

Solution code:
import sys
N = list(input())
for bit in range(2 ** 3):
    op = ['-'] * 3
    for i in range(3):
        if (bit & (1 << i)):
            op[i] = '+'
    E = N[0] + op[0] + N[1] + op[1] + N[2] + op[2] + N[3]
    if eval(E) == 7:
        print(E + '=7')
        sys.exit()

Submission status: Accepted

Solution code:
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] = "+"
    op += [""]
            
    formura = ""
    for i,j in zip(n,op):
        formura += i+j
    if eval(formura) == 7:
        print(formura + "=7")
        break

Submission status: Accepted

Solution code:
ABCD = list(i for i in input())

for i in range(2**3):
    box = []
    for k in range(3):
        if ((i>>k) & 1):
            box.append("+")
        else:
            box.append("-")
    if eval("{0}{4}{1}{5}{2}{6}{3}".format(*ABCD,*box)) == 7:
        print("{0}{4}{1}{5}{2}{6}{3}=7".format(*ABCD,*box))
        break

Submission status: Accepted

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

Submission status: Accepted

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

import itertools

A=(1,-1)

def e(x):
	if x==1:
		return '+'
	else:
		return '-'

for v in itertools.product(A,repeat=3):
	s=a+b*v[0]+c*v[1]+d*v[2]
	if s==7:
		print(L[0]+e(v[0])+L[1]+e(v[1])+L[2]+e(v[2])+L[3]+'=7')
		exit()

Submission status: Accepted

Solution code:
import itertools
L = input()
L = [int(x) for x in list(str(L))]
P = [0]*3
sum = L[0]
A = (1,-1)
for a in itertools.product(A,repeat=3):
	for i in range(3): 
		sum += a[i]*L[i+1]
		if a[i] == 1:
			P[i] = '+'
		else:
			P[i] = '-'
	if sum == 7:
		print(L[0],P[0],L[1],P[1],L[2],P[2],L[3],'=7',sep = '')
		break
	sum = L[0]

Submission status: Accepted

Solution code:
from itertools import product 

T = input()

for pm in product(["+", "-"], repeat = 3):
  if eval(T[0]+pm[0]+T[1]+pm[1]+T[2]+pm[2]+T[3]) == 7:
    print(T[0]+pm[0]+T[1]+pm[1]+T[2]+pm[2]+T[3]+"=7")
    exit()

Submission status: Accepted

Solution code:
#A,B,C,D = map(int,input().split())
num = list(input())
A=int(num[0])
B=int(num[1])
C=int(num[2])
D=int(num[3])
ans=0
for i in range(1<<3):
    if( (i>>2) & 1 == 1):
        ans = A+B
        op1 = "+"
    else:
        ans = A-B
        op1 = "-"
    if((i>>1)&1 == 1):
        ans += C
        op2 = "+"
    else:
        ans -= C
        op2 = "-"
    if((i>>0) & 1 == 1):
        ans += D
        op3 = "+"
    else:
        ans -= D
        op3 = "-"
    if(ans == 7):
        print(str(A)+op1+str(B)+op2+str(C)+op3+str(D)+"=7")
        break

Submission status: Accepted

Solution code:
t = list(map(int,input()))

for i in range(8):
    log = []
    x = t[0]
    for s in range(3):
        if i>>s&1:
            x += t[s+1]
            log.append("+")
        else:
            x -= t[s+1]
            log.append("-")
    if x == 7:
        print(str(t[0])+log[0]+str(t[1])+log[1]+str(t[2])+log[2]+str(t[3])+"=7")
        break

Submission status: Accepted

Solution code:
s = list(input())

for i in range(1<<3):
    form = ""
    for j in range(3):
        form += s[j]
        if i & 1<<j:
            form += "+"
        else:
            form += "-"
    form += s[-1]
    if eval(form) == 7:
        print(form + "=7")
        exit()

Submission status: Accepted

Solution code:
import sys
import numpy as np
import math
import collections
import copy
from collections import deque 
from functools import reduce
from itertools import product

# input = sys.stdin.readline
ABCD = input()
for p in product((0, 1), repeat=3):
    A, B, C, D = int(ABCD[0]), int(ABCD[1]), int(ABCD[2]), int(ABCD[3])
    total = 0
    if (p[0] == 0):
        total = A + B
    else:
        total = A - B
    if (p[1] == 0):
        total += C
    else:
        total -= C
    if (p[2] == 0):
        total += D
    else:
        total -= D
    if total == 7:
        break
if p[0] == 0:
    op1 = "+"
else:
    op1 = '-'
if p[1] == 0:
    op2 = "+"
else:
    op2 = '-'
if p[2] == 0:
    op3 = "+"
else:
    op3 = '-'
print("{}{}{}{}{}{}{}=7".format(A, op1, B, op2, C, op3, D))

Submission status: Accepted

Solution code:
s = input()

for i in range(2**3):
    op = ["-", "-", "-"]
    for j in range(len(op)):
        if (i>>j) &1:
            op[len(op)-j-1] = "+"
    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:
x = input()
a = int(x[0])
bcd = list(map(int, [x[1], x[2], x[3]]))

for j in range(8):
    n = []
    op = []
    for i in range(3):
        if (j >> i) & 1:
            n.append(bcd[i])
            op.append("+")
        else:
            n.append(-bcd[i])
            op.append("-") if bcd[i] == 0 else op.append("")
    if a + sum(n) == 7:
        print(f"{a}{op[0]}{n[0]}{op[1]}{n[1]}{op[2]}{n[2]}=7")
        break

Submission status: Accepted

Solution code:
#変数: S, num, formula
    
s = input()
num = len(s) - 1

for i in range(2**num):
    op = ['-']*num
    
    for j in range(num):
        if(i>>j)&1:
            op[num-j - 1] = '+'
    formula = ''
    for op_n, op_m in zip(s,op+['']):
        formula += op_n + op_m
    if eval(formula)==7:
        print(formula+ '=7')
        break

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
digits = input()
op_cnt = len(digits) - 1
for i in range(op_cnt ** 2):
    op = ["-"] * 3
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[-j] = "+"
    
    formula = ""
    for p_n, p_o in zip(digits, op + [""]):
        formula += (p_n + p_o)
    if eval(formula) == 7:
        print(formula + "=7")
        break

Submission status: Accepted

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





if __name__ == "__main__":
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
import itertools

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

def minus(x, y):
    return x-y

def plus(x, y):
    return x + y

def eval(opt, x, y):
    if opt == "-":
        return x - y
    else:
        return x + y


for opt1, opt2, opt3 in itertools.product(["-", "+"], repeat=3):
    if eval(opt3, eval(opt2, eval(opt1, A, B), C), D) == 7:
        print("{}{}{}{}{}{}{}=7".format(str(A), opt1, str(B), opt2, str(C), opt3, str(D)))
        exit(0)

Submission status: Accepted

Solution code:
s = input()

n = 3
for i in range(2**n):
    ans = s[0]
    sum = int(s[0])
    for j in range(3):
        if 1 & (i >> j):
            ans += f'+{s[j+1]}'
            sum += int(s[j+1])
        else:
            ans += f'-{s[j+1]}'
            sum -= int(s[j+1])
    if sum == 7:
        print(f'{ans}=7')
        exit()

Submission status: Accepted

Solution code:
def solve():
    s = [int(x) for x in input()]

    def dfs(i, x, a):
        if i == 4:
            if x == 7:
                return a + "=7"
            else:
                return False
        res1 = dfs(i + 1, x + s[i], a + "+" + str(s[i]))
        res2 = dfs(i + 1, x - s[i], a + "-" + str(s[i]))
        return res1 or res2

    res = dfs(1, s[0], str(s[0]))
    print(res)


solve()

Submission status: Accepted

Solution code:
S = input()

op = ['+','+','+']

for bit in range(2**3):
  sum = int(S[0])
  for i in range(3):
    if (bit >> i) & 1:
      sum += int(S[i+1])
      op[i] = '+'
    else:
      sum -= int(S[i+1])
      op[i] = '-'

  if sum == 7:
    print(f'{S[0]}{op[0]}{S[1]}{op[1]}{S[2]}{op[2]}{S[3]}=7')
    break