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:
def pumi(i):
    if i == 0:
        H = '+'
    else:
        H = '-'
    return H
S = input()
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])
flag = 0
for i in range(2):
    for j in range(2):
        for k in range(2):
            if A +(1-2*i)*B +(1-2*j)*C + (1-2*k)*D == 7:
                flag = 1
                break
        if flag == 1:
             break
    if flag == 1:
        break
H = str(A)+pumi(i)+str(B)+pumi(j)+str(C)+pumi(k)+str(D)+'=7'
print(H)

Submission status: Accepted

Solution code:
def Cal(A, B, op):
    if op == "+":
        return A + B
    else:
        return A - B

Num = input()
OP = ["---", "--+", "-+-", "-++", "+--", "+-+", "++-", "+++"]

for o in OP:
    Sum = Cal(int(Num[0]), int(Num[1]), o[0])
    Sum = Cal(Sum, int(Num[2]), o[1])
    Sum = Cal(Sum, int(Num[3]), o[2])
    if Sum == 7:
        print(Num[0]+o[0]+Num[1]+o[1]+Num[2]+o[2]+Num[3]+"=7")
        break

Submission status: Accepted

Solution code:
import sys
from operator import add, sub

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

for i in range(2):
    if i == 0:
        op1 = add
    else:
        op1 = sub
    for j in range(2):
        if j == 0:
            op2 = add
        else:
            op2 = sub
        for k in range(3):
            if k == 0:
                op3 = add
            else:
                op3 = sub

            if op3(op2(op1(A, B), C), D) == 7:
                op1 = "+" if i == 0 else "-"
                op2 = "+" if j == 0 else "-"
                op3 = "+" if k == 0 else "-"
                print(str(A) + op1 + str(B) + op2 + str(C) + op3 + str(D) + "=7")
                sys.exit()

Submission status: Accepted

Solution code:
abcd = list(input())
l = list(map(int,abcd))
ans_list = []
ans_list.append(l[0]+l[1]+l[2]+l[3])
ans_list.append(l[0]+l[1]+l[2]-l[3])
ans_list.append(l[0]+l[1]-l[2]+l[3])
ans_list.append(l[0]+l[1]-l[2]-l[3])
ans_list.append(l[0]-l[1]+l[2]+l[3])
ans_list.append(l[0]-l[1]+l[2]-l[3])
ans_list.append(l[0]-l[1]-l[2]+l[3])
ans_list.append(l[0]-l[1]-l[2]-l[3])

for i in range(7):
	if ans_list[i] == 7:
		if i == 0:
			print(str(l[0])+'+'+str(l[1])+'+'+str(l[2])+'+'+str(l[3])+'=7')
			break
		elif i == 1:
			print(str(l[0])+'+'+str(l[1])+'+'+str(l[2])+'-'+str(l[3])+'=7')
			break
		elif i == 2:
			print(str(l[0])+'+'+str(l[1])+'-'+str(l[2])+'+'+str(l[3])+'=7')
			break
		elif i == 3:
			print(str(l[0])+'+'+str(l[1])+'-'+str(l[2])+'-'+str(l[3])+'=7')
			break
		elif i == 4:
			print(str(l[0])+'-'+str(l[1])+'+'+str(l[2])+'+'+str(l[3])+'=7')
			break
		elif i == 5:
			print(str(l[0])+'-'+str(l[1])+'+'+str(l[2])+'-'+str(l[3])+'=7')
			break
		elif i == 6:
			print(str(l[0])+'-'+str(l[1])+'-'+str(l[2])+'+'+str(l[3])+'=7')
			break
		elif i == 7:
			print(str(l[0])+'-'+str(l[1])+'-'+str(l[2])+'-'+str(l[3])+'=7')
			break

Submission status: Accepted

Solution code:
a, b, c, d = list(input())
ops = ['+', '-']
fin = False
for op1 in ops:
    for op2 in ops:
        for op3 in ops:
            s = a+op1+b+op2+c+op3+d
            res = eval(s)
            if res == 7:
                print(s+'=7')
                fin = True
                break
        if fin == True:
            break
    if fin == True:
        break

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
s = input()
l = [0]*7
pm = [ '+', '-' ]

for i in range(0,len(s)):
  
  l[i*2]=s[i]

exp=""

def opeval(x,op,y):
  res = 0
  if op == '+':
    res = x + y
  else:
    res = x - y
  return res

def walk(l):
  res = int(l[0])
  for i in range(0,len(l)-2,2):
    res = opeval( res, l[i+1], int(l[i+2]))
    
  return res

for i in range(0,2):
  l[1]=pm[i]
  for j in range(0,2):
    l[3]=pm[j]
    for k in range(0,2):
      l[5]=pm[k]
      res=walk(l)
      if res==7:
        exp = ''.join(l)
        exp = exp + '=7'
    


print(exp)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = list(input())

a = [0,0,0,0]
for i in range(4):
    a[i] = int(n[i])

op = [0,0,0]
for i in range(8):
    temp = i
    for j in range(3):
        op[j] = temp % 2
        temp //= 2

    check = 0
    ans = a[0]
    for j in range(3):
        if op[j] == 0:
            ans += a[j + 1]
        else:
            ans -= a[j + 1]
    if ans == 7:
        s = str(a[0])
        for j in range(3):
            if op[j] == 0:
                s = s + "+" + str(a[j + 1])
            else:
                s = s + "-" + str(a[j + 1])
        s += "=7"
        print(s)
        exit()

Submission status: Accepted

Solution code:
import sys
S = input()
n = [int(S[i]) for i in range(4)]

sum = 0
for i in range(4):
    sum = sum + n[i]


if sum == 7:
    print(S[0] + '+' + S[1] + '+' + S[2] + '+' + S[3] + '=' + '7')

else:
    if 4*n[1] == 2 * (sum - 7):
        print(S[0] + '-' + S[1] + '+' + S[2] + '+' + S[3] + '=' + '7')
        sys.exit()

    if 4*n[2] == 2 * (sum - 7):
        print(S[0] + '+' + S[1] + '-' + S[2] + '+' + S[3] + '=' + '7')
        sys.exit()
    if 4*n[3] == 2 * (sum - 7):
        print(S[0] + '+' + S[1] + '+' + S[2] + '-' + S[3] + '=' + '7')
        sys.exit()
    if 4*(n[1] + n[2])  == 2 * (sum - 7):
        print(S[0] + '-' + S[1] + '-' + S[2] + '+' + S[3] + '=' + '7')
        sys.exit()
    if 4*(n[3] + n[2])  == 2 * (sum - 7):
        print(S[0] + '+' + S[1] + '-' + S[2] + '-' + S[3] + '=' + '7')
        sys.exit()
    if 2*n[1] + 2*n[3] == sum - 7:
        print(S[0] + '-' + S[1] + '+' + S[2] + '-' + S[3] + '=' + '7')
        sys.exit()
    if 4*(n[1] + n[2] + n[3])  == 2 * (sum - 7):
        print(S[0] + '-' + S[1] + '-' + S[2] + '-' + S[3] + '=' + '7')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import itertools
ope = ['+','-']
ope_list = itertools.product(ope, repeat=3)

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

# print(In)
# print(list(ope_list))

for op1,op2,op3 in ope_list:
    if op1 == '+':
        tmp1 = In[0] + In[1]
    else:
        tmp1 = In[0] - In[1]

    if op2 == '+':
        tmp2 = tmp1 + In[2]
    else:
        tmp2 = tmp1 - In[2]

    if op3 == '+':
        tmp3 = tmp2 + In[3]
    else:
        tmp3 = tmp2 - In[3]

    if tmp3 == 7:
        print('{0}{1}{2}{3}{4}{5}{6}=7'.format(In[0],op1,In[1],op2,In[2],op3,In[3]))
        exit()

Submission status: Accepted

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

op = ["+", "-"]
for i in op:
    for j in op:
        for k in op:
            cal = a + i + b + j + c + k + d
            if eval(cal) == 7:
                ans = cal + "=7"

print(ans)

Submission status: Accepted

Solution code:
s=input()
l=['+']*3+['']
for k in range(7):
  a=''.join([i+j for i,j in zip(s,l)])
  if eval(a)==7:
    print(a+'=7')
    break
  l=list(bin(k+1)[2:].zfill(3).replace('0','+').replace('1','-'))+['']

Submission status: Accepted

Solution code:
i=input()

a=int(i[0])
b=int(i[1])
c=int(i[2])
d=int(i[3])

if a+b+c+d==7:
    x="+"
    y="+"
    z="+"
elif a+b+c-d==7:
    x="+"
    y="+"
    z="-"
elif a+b-c+d==7:
    x="+"
    y="-"
    z="+"    
elif a-b+c+d==7:
    x="-"
    y="+"
    z="+"
elif a-b-c+d==7:
    x="-"
    y="-"
    z="+"
elif a-b+c-d==7:
    x="-"
    y="+"
    z="-"
elif a+b-c-d==7:
    x="+"
    y="-"
    z="-"
elif a-b-c-d==7:
    x="-"
    y="-"
    z="-"
    
    
print(a,end="")
print(x,end="")
print(b,end="")
print(y,end="")
print(c,end="")
print(z,end="")
print(d,end="")
print("=7")

Submission status: Accepted

Solution code:
a=list(input())
l = ["+","-"]

for p in l:
  for q in l:
    for r in l:
      x = a[0]+p+a[1]+q+a[2]+r+a[3]
      if eval(x) == 7:
        print(x+  '=7')
        exit()

Submission status: Accepted

Solution code:
S = input()
op = ['+', '-']
for i in op:
    for j in op:
        for k in op:
            f = S[0] + i + S[1] + j + S[2] + k + S[3]
            if eval(f) == 7:
                print(f + '=7')
                exit()

Submission status: Accepted

Solution code:
a = list(input())
l = ["+", "-"]
for p in l:
  for q in l:
    for r in l:
      x = a[0]+p+a[1]+q+a[2]+r+a[3]
      if eval(x) == 7:
        print(x + "=7")
        exit()

Submission status: Accepted

Solution code:
n = int(input())
s = []
for i in range(4):
	s.append(n//(10**i)-(n//(10**(i+1)))*10)
s.reverse()

def sgn(i):
	if i==0:
		return 1
	else:
		return -1

x = []
m = 0

for i in range(2):
	for j in range(2):
		for k in range(2):
			m +=1
			x.append(s[0]+s[1]*sgn(i)+s[2]*sgn(j)+s[3]*sgn(k))

z = x.index(7)
u = []
for i in range(3):
	u.append(z//(2**i)-(z//(2**(i+1)))*2)
u.reverse()

def ppp(i):
	if i==0:
		return "+"
	else:
		return "-"
print(s[0],ppp(u[0]),s[1],ppp(u[1]),s[2],ppp(u[2]),s[3],"=7",sep="")

Submission status: Accepted

Solution code:
s = input()
for a in '+-':
    for b in '+-':
        for c in '+-':
            t = s[0]+a+s[1]+b+s[2]+c+s[3]
            if eval(t)==7:
                print(t+'=7')
                exit()

Submission status: Accepted

Solution code:
O = ["+","-"]
I = list(input())
for o1 in O :
    for o2 in O :
        for o3 in O :
            f = I[0]+o1+I[1]+o2+I[2]+o3+I[3]
            if eval(f) == 7 :
                print(f+"=7")
                exit()

Submission status: Accepted

Solution code:
L = list(input())
O = ["+","-"]
for o1 in O :
    for o2 in O :
        for o3 in O :
            f = L[0]+o1+L[1]+o2+L[2]+o3+L[3]
            if eval(f) == 7 :
                print(f+"=7")
                exit()

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = lc()
for i in range(8):
    cur = int(n[0])
    ans = n[0]
    for j in range(2,-1,-1):

        if (i>>j)&1 == 1:
            cur += int(n[3-j])
            ans = ans + "+" + n[3-j]
        else:
            cur -= int(n[3-j])
            ans = ans + "-" + n[3-j]
        
        
    if cur == 7:
        ans = ans + "=" + "7"
        break

print(ans)

Submission status: Accepted

Solution code:
L = list((input()))
A = L[0]
B = L[1]
C = L[2]
D = L[3]
a = int(L[0])
b = int(L[1])
c = int(L[2])
d = int(L[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))
else :
    print("{}-{}-{}-{}=7".format(a,b,c,d))

Submission status: Accepted

Solution code:
w = input()

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

Submission status: Accepted

Solution code:
S = input()
for a in '+-':
    for b in '+-':
        for c in '+-':
            f = S[0]+a+S[1]+b+S[2]+c+S[3]
            if eval(f) == 7:
                print(f + '=7')
                exit()

Submission status: Accepted

Solution code:
input_str = input()

for i in range(8):
    calc_str = input_str[0]
    opmaker = str(format(i, 'b')).zfill(3)
    for j, c in enumerate(opmaker):
        if c == '0':
            calc_str += '-'
        else:
            calc_str += '+'
        calc_str += input_str[j+1]
    if eval(calc_str) == 7:
        print(calc_str + '=7')
        exit()

Submission status: Accepted

Solution code:
#ABC079C
ABCD=str(input())
op='+-'
for i in range(2):
    for j in range(2):
        for k in range(2):
            ans_str=ABCD[0]+op[i]+ABCD[1]+op[j]+ABCD[2]+op[k]+ABCD[3]
            ans=eval(ans_str)
            if ans==7:
                print(ans_str+'=7')
                exit()

Submission status: Accepted

Solution code:
ABCD = list(input())
A = int(ABCD[0])
B = int(ABCD[1])
C = int(ABCD[2])
D = int(ABCD[3])
L = []
L.append(A+B+C+D)
L.append(A+B+C-D)
L.append(A+B-C+D)
L.append(A-B+C+D)
L.append(A+B-C-D)
L.append(A-B+C-D)
L.append(A-B-C+D)
L.append(A-B-C-D)
for i in range(len(L)) :
    if L[i] == 7 :
        if i == 0 or i == 1 or i == 2 or i == 4 :
            p1 = "+"
        else :
            p1 = "-"
        if i == 0 or i == 1 or i == 3 or i == 5 :
            p2 = "+"
        else :
            p2 = "-"
        if i == 0 or i == 2 or i == 3 or i == 6 :
            p3 = "+"
        else :
            p3 = "-"
        break
print("{}{}{}{}{}{}{}=7".format(A,p1,B,p2,C,p3,D))

Submission status: Accepted

Solution code:
import itertools

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

def plusMinus(zeroIchi):
    if zeroIchi ==0:
        return "-"
    else:
        return "+"

listN = [0, 1]
for i in itertools.product(listN, repeat=4):
    sum=a
    if i[0] == 0:
        sum-=b
    else:
        sum+=b
    if i[1] == 0:
        sum-=c
    else:
        sum+=c
    if i[2] == 0:
        sum-=d
    else:
        sum+=d
    if sum == 7:
        print(str(a)+plusMinus(i[0])+str(b)+plusMinus(i[1])+str(c)+plusMinus(i[2])+str(d)+"=7")
        break

Submission status: Accepted

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

def func(m):
    x1 = m[0] + m[1] + m[2] + m[3]
    if x1 == 7:
        return ("{}+{}+{}+{}=7".format(m[0],m[1],m[2],m[3]))
    x2 = m[0] + m[1] + m[2] - m[3]
    if x2 == 7:
        return ("{}+{}+{}-{}=7".format(m[0],m[1],m[2],m[3]))
    x3 = m[0] + m[1] - m[2] - m[3]
    if x3 == 7:
        return ("{}+{}-{}-{}=7".format(m[0],m[1],m[2],m[3]))
    x4 = m[0] + m[1] - m[2] + m[3]
    if x4 == 7:
        return ("{}+{}-{}+{}=7".format(m[0],m[1],m[2],m[3]))
    x5 = m[0] - m[1] - m[2] + m[3]
    if x5 == 7:
        return ("{}-{}-{}+{}=7".format(m[0],m[1],m[2],m[3]))
    x6 = m[0] - m[1] - m[2] - m[3]
    if x6 == 7:
        return ("{}-{}-{}-{}=7".format(m[0],m[1],m[2],m[3]))
    x7 = m[0] - m[1] + m[2] - m[3]
    if x7 == 7:
        return ("{}-{}+{}-{}=7".format(m[0],m[1],m[2],m[3]))
    x8 = m[0] - m[1] + m[2] + m[3]
    if x8 == 7:
        return ("{}-{}+{}+{}=7".format(m[0],m[1],m[2],m[3]))

print(func(n))

Submission status: Accepted

Solution code:
ABCD=int(input())
A=(ABCD//1000)
B=(ABCD//100)-(A*10)
C=(ABCD//10)-(A*100)-(B*10)
D=ABCD-(A*1000)-(B*100)-(C*10)

if (A+B+C+D)==7:
  print('%d+%d+%d+%d=7' %(A,B,C,D))
  exit()
if (A+B+C-D)==7:
  print('%d+%d+%d-%d=7' %(A,B,C,D))
  exit()
if (A+B-C+D)==7:
  print('%d+%d-%d+%d=7' %(A,B,C,D))
  exit()
if (A+B-C-D)==7:
  print('%d+%d-%d-%d=7' %(A,B,C,D))
  exit()
if (A-B+C+D)==7:
  print('%d-%d+%d+%d=7' %(A,B,C,D))
  exit()
if (A-B-C+D)==7:
  print('%d-%d-%d+%d=7' %(A,B,C,D))
  exit()
if (A-B+C-D)==7:
  print('%d-%d+%d-%d=7' %(A,B,C,D))
  exit()
if (A-B-C-D)==7:
  print('%d-%d-%d-%d=7' %(A,B,C,D))
  exit()

Submission status: Accepted

Solution code:
a, b, c, d = [int(i) for i in input()]
ops = ["+++", "++-", "+-+", "+--", "-++", "-+-", "--+", "---"]

for op in ops:
    s = a
    for i, n in enumerate([b, c, d]):
        op = list(op)
        if op[i] == "+":
            s += n
        else:
            s -= n
    if s == 7:
        print(str(a) + op[0] + str(b) + op[1] + str(c) + op[2] + str(d) + "=7")
        break

Submission status: Accepted

Solution code:
S=input()
op=["+","-"]
for a in op:
    for b in op:
        for c in op:
            f=S[0]+a+S[1]+b+S[2]+c+S[3]
            if eval(f)==7:
                print(f+"=7")
                exit()

Submission status: Accepted

Solution code:
A, B, C, D = input()
ops = ('+', '-')

for op1 in ops:
	for op2 in ops:
		for op3 in ops:
			if eval(A+op1+B+op2+C+op3+D+'==7'):
				print(A+op1+B+op2+C+op3+D+'=7')
				exit()

Submission status: Accepted

Solution code:
A,B,C,D = map(int,list(input()))
op = ["+","-"]
def check():
    ans = ""
    for i in range(2):
        for q in range(2):
            for k in range(2):
                op1,op2,op3 = op[i],op[q],op[k]
                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:
                    return "{0}{1}{2}{3}{4}{5}{6}=7".format(A,op1,B,op2,C,op3,D)
print(check())

Submission status: Accepted

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


for i in range(0, 2):
    for j in range(0, 2):
        for k in range(0, 2):
            ans = ''
            if i == 0:
                AB = A + B
                ans += str(A) + '+' + str(B)
            else:
                AB = A - B
                ans += str(A) + '-' + str(B)
            if j == 0:
                ABC = AB + C
                ans += '+' + str(C)
            else:
                ABC = AB - C
                ans += '-' + str(C)
            if k == 0:
                ABCD = ABC + D
                ans += '+' + str(D)
            else:
                ABCD = ABC - D
                ans += '-' + str(D)
            if ABCD == 7:
                ans += '=7'
                print(ans)
                quit()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

def main():
    import itertools
    nums = [int(c) for c in input()]
    ops = itertools.product(["+","-"], repeat=3)
    for op in ops:
        s = "{}{}{}{}{}{}{}".format(nums[0], op[0],
                                    nums[1], op[1],
                                    nums[2], op[2],
                                    nums[3])
        if eval(s) == 7:
            print(s + "=7")
            exit()


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ops = {'+', '-'}

for op1 in ops:
    if op1 == '+': ab = a+b
    else: ab = a-b
    
    for op2 in ops:
        if op2 == '+': abc = ab+c
        else: abc = ab-c
        
        for op3 in ops:
            if op3 == '+': abcd = abc+d
            else: abcd = abc-d

            if abcd == 7:
                a, b, c, d = map(str, [a, b, c, d])
                print(a+op1+b+op2+c+op3+d+'=7')
                exit()

Submission status: Accepted

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

for op1 in ['+', '-']:
    for op2 in ['+', '-']:
        for op3 in ['+', '-']:
            tmp = a
            if op1 == '+':
                tmp += b
            else:
                tmp -= b

            if op2 == '+':
                tmp += c
            else:
                tmp -= c

            if op3 == '+':
                tmp += d
            else:
                tmp -= d

            if tmp == 7:
                ans = '{0}{1}{2}{3}{4}{5}{6}=7'.format(a, op1, b, op2, c, op3, d)

print(ans)

Submission status: Accepted

Solution code:
import itertools
S = input()
opt_list = list(itertools.product([0, 1], repeat=3)) #0:+を入れる, 1:-を入れる
res_opt = ['+', '+', '+']
for opt in opt_list:
    tmp = int(S[0])
    for i in range(3):
        if opt[i] == 0:
            tmp += int(S[i + 1])
            res_opt[i] = '+'
        else:
            tmp -= int(S[i + 1])
            res_opt[i] = '-'
    
    if tmp == 7:
        res = S[0] + res_opt[0] + S[1] + res_opt[1] + S[2] + res_opt[2] + S[3] + '=7'
        
print(res)

Submission status: Accepted

Solution code:
s=input()
op=["+","-"]
tolal=0
for i in op:
    for j in op:
        for k in op:
                total=eval("{}{}{}{}{}{}{}".format(s[0],i,s[1],j,s[2],k,s[3]))
                if total ==7:
                    print("{}{}{}{}{}{}{}=7".format(s[0],i,s[1],j,s[2],k,s[3]))
                    exit()

Submission status: Accepted

Solution code:
t = list(map(int,input()))
p = ['+','+','+']
q = ['','','']
for i in range(8):
    if i & 1:
        c = t[0] + t[1]
        p[0] = '+'
    else:
        c = t[0] - t[1]
        p[0] = '-'
    if i & (1<<1):
        c += t[2]
        p[1] = '+'
    else:
        c -= t[2]
        p[1] = '-'
    if i & (1<<2):
        c += t[3]
        p[2] = '+'
    else:
        c -= t[3]
        p[2] = '-'
    if c == 7:
        q[0] = p[0]
        q[1] = p[1]
        q[2] = p[2]
print(str(t[0]) + q[0] + str(t[1]) + q[1] + str(t[2]) + q[2] + str(t[3]) + '=7')

Submission status: Accepted

Solution code:
from itertools import product

num = list(map(int, list(input())))
flag = False

for i in product(("+", "-"), repeat=3):
    # print(i)
    calc = num[0]
    for j, opt in enumerate(list(i)):
        if opt == "+":
            calc += num[j+1]
        else:
            calc -= num[j+1]

        if calc == 7:
            print("{}{}{}{}{}{}{}=7".format(num[0], i[0], num[1], i[1], num[2], i[2], num[3]))
            flag = True
            break

    if flag:
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    A, B, C, D = input()

    for a in ["+", "-"]:
        for b in ["+", "-"]:
            for c in ["+", "-"]:
                if eval(A + a + B + b + C + c + D) == 7:
                    print(A + a + B + b + C + c + D + "=7")
                    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])
def ope(x,y,n,s):
    if n % 2 == 0:
        return x+y, str(s) + '+' + str(y)
    else:
        return x-y, str(s) + '-' + str(y)
for i in range(8):
    X1, S1 = ope(A,B,i,A)
    j = int(i/2)
    X2, S2 = ope(X1,C,j,S1)
    k = int(j/2)
    X3, S3 = ope(X2,D,k,S2)
    if X3 == 7:
        print(S3 + '=7')
        break

Submission status: Accepted

Solution code:
ABCD=list(map(int, list(input())))
for i in range(1<<3):
    tmp=list(map(int, list(str(bin(i))[2:].zfill(3))))
    a=ABCD[0]
    for j in range(3):
        if tmp[j]:
            a+=ABCD[j+1]
        else:
            a-=ABCD[j+1]
    if a==7:
        print(ABCD[0], end="")
        for j in range(3):
            print("+" if tmp[j] else "-", end="")
            print(ABCD[j+1], end="")
        print("=7")
        exit(0)

Submission status: Accepted

Solution code:
import itertools
S=list(input())
T=list(itertools.product(["+","-"],repeat=3))
for seq in T:
    tmp=""
    for i in range(3):
        tmp+=S[i]+seq[i]
    tmp=tmp+S[3]
    if eval(tmp)==7:
        print(tmp+"=7")
        exit()
print("Baka!")

Submission status: Accepted

Solution code:
abcd=input()

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

Submission status: Accepted

Solution code:
from itertools import product

X = [int(x) for x in input()]

for ptn in product([-1, 1], repeat=3):
    if X[0] + ptn[0] * X[1] + ptn[1] * X[2] + ptn[2] * X[3] == 7:
        ptn = ['+' if s == 1 else '-' for s in ptn]
        print('{}{}{}{}{}{}{}=7'.format(X[0], ptn[0], X[1], ptn[1], X[2],
                                        ptn[2], X[3]))
        break

Submission status: Accepted

Solution code:
abcd = input()
for i in range(1 << 4):
    exp = ''
    for j in range(3):
        op = '+' if i & (1 << j) else '-'
        exp += abcd[j] + op
    exp += abcd[3]
    if eval(exp) == 7:
        print(exp + '=7')
        break

Submission status: Accepted

Solution code:
x = input()
for op1 in ['+', '-']:
    for op2 in ['+', '-']:
        for op3 in ['+', '-']:
            eq = x[0] + op1 + x[1] + op2 + x[2] + op3 + x[3]
            if eval(eq) == 7:
                print(eq + '=7')
                exit()

Submission status: Accepted

Solution code:
n = input()

a = int(n[0])
b = int(n[1])
c = int(n[2])
d = int(n[3])

if (a+b+c+d) == 7:
    print(a, "+" ,b, "+" ,c, "+", d, "=7", sep="")
elif (a+b+c-d) == 7:
    print(a, "+" ,b, "+" ,c, "-", d, "=7", sep="")
elif (a+b-c+d) == 7:
    print(a, "+" ,b, "-" ,c, "+", d, "=7", sep="")
elif (a+b-c-d) == 7:
    print(a, "+" ,b, "-" ,c, "-", d, "=7", sep="")
elif (a-b+c+d) == 7:
    print(a, "-" ,b, "+" ,c, "+", d, "=7", sep="")
elif (a-b+c-d) == 7:
    print(a, "-" ,b, "+" ,c, "-", d, "=7", sep="")
elif (a-b-c+d) == 7:
    print(a, "-" ,b, "-" ,c, "+", d, "=7", sep="")
elif (a-b-c-d) == 7:
    print(a, "-" ,b, "-" ,c, "-", d, "=7", sep="")

Submission status: Accepted

Solution code:
from itertools import product

a, b, c, d = list(map(int, input()))
for s in product('+-', repeat=3):
    f = '{}{}{}{}{}{}{}'.format(a,s[0],b,s[1],c,s[2],d)
    if eval(f)==7:
        print(f+'=7')
        break

Submission status: Accepted

Solution code:
from itertools import permutations, combinations,combinations_with_replacement,product
a=list(product(['+','-'],repeat=3))
s=list(input())
for i in a:
    ans=s[0]+i[0]+s[1]+i[1]+s[2]+i[2]+s[3]
    if eval(ans)==7:
        print(ans+'=7')
        break

Submission status: Accepted

Solution code:
a = b = c = d = 0
[a,b,c,d] = list(map(int,list((input()))))
for i in range(8):
    bin_padded = bin(i)[2:].zfill(3)
    temp = list(bin_padded)
    op = [-1,-1,-1]
    for j in range(3):
        if temp[j] == '1':
            op[j] = 1
    if (a + op[0] * b + op[1] * c +  op[2] * d) == 7:
        opch = ['-', '-', '-']
        for k in range(3):
            if op[k] == 1:
                opch[k] = '+'
        ans = str(a)+opch[0]+str(b)+opch[1]+str(c)+opch[2]+str(d)+'=7'
        print(ans)
        exit()

Submission status: Accepted

Solution code:
from itertools import product
N = input()
X = []

for i in range(4):
  X.append(int(N[i]))

for ops in product((1,-1), repeat=3):
  calc = X[0] + X[1]*ops[0] + X[2]*ops[1] + X[3]*ops[2]
  if calc == 7:
    opstr = [""] * 3
    for i in range(3):
      opstr[i] = '+' if ops[i] == 1 else '-'
    print(N[0] + opstr[0] + N[1] + opstr[1] + N[2] + opstr[2] + N[3] + "=7")
    break

Submission status: Accepted

Solution code:
# coding: utf-8

S = input()
a = list(S)
A = int(a[0])
B = int(a[1])
C = int(a[2])
D = int(a[3])

if A+B+C+D==7:
    print(str(A)+"+"+str(B)+"+"+str(C)+"+"+str(D)+"=7")
elif A-B+C+D==7:
    print(str(A)+"-"+str(B)+"+"+str(C)+"+"+str(D)+"=7")
elif A+B-C+D==7:
    print(str(A)+"+"+str(B)+"-"+str(C)+"+"+str(D)+"=7")
elif A-B-C+D==7:
    print(str(A)+"-"+str(B)+"-"+str(C)+"+"+str(D)+"=7")
elif A+B+C-D==7:
    print(str(A)+"+"+str(B)+"+"+str(C)+"-"+str(D)+"=7")
elif A-B+C-D==7:
    print(str(A)+"-"+str(B)+"+"+str(C)+"-"+str(D)+"=7")
elif A+B-C-D==7:
    print(str(A)+"+"+str(B)+"-"+str(C)+"-"+str(D)+"=7")
elif A-B-C-D==7:
    print(str(A)+"-"+str(B)+"-"+str(C)+"-"+str(D)+"=7")

Submission status: Accepted

Solution code:
from itertools import product

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

for pattern in product('+-', repeat=3):
    f = '{}{}{}{}{}{}{}'.format(A, pattern[0], B, pattern[1], C, pattern[2], D)
    if eval(f) == 7:
        print(f+'=7')
        break

Submission status: Accepted

Solution code:
def sarch(B, C, D):
    return a + B * b + C * c + D * d == 7

def ansprint(B, C, D):
    print(str(a) + B + str(b) + C + str(c) + D + str(d) + "=7")

def figstr(B, C, D):
    BB = "-"
    CC = "-"
    DD = "-"
    if B == 1:
        BB = "+"
    if C == 1:
        CC = "+"
    if D == 1:
        DD = "+"
    ansprint(BB, CC, DD)

S = input()
a = int(S[0])
b = int(S[1])
c = int(S[2])
d = int(S[3])

if sarch(1, 1, 1):
    figstr(1, 1, 1)
elif sarch(1, -1, 1):
    figstr(1, -1, 1)
elif sarch(1, 1, -1):
    figstr(1, 1, -1)
elif sarch(-1, 1, 1):
    figstr(-1, 1, 1)
elif sarch(-1, -1, 1):
    figstr(-1, -1, 1)
elif sarch(1, -1, -1):
    figstr(1, -1, -1)
elif sarch(-1, 1, -1):
    figstr(-1, 1, -1)
elif sarch(-1, -1, -1):
    figstr(-1, -1, -1)

Submission status: Accepted

Solution code:
from itertools import product

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

for pattern in product('+-', '+-', '+-'):
    f = '{}{}{}{}{}{}{}'.format(A, pattern[0], B, pattern[1], C, pattern[2], D)

    if eval(f) == 7:
        print(f+'=7')
        break

Submission status: Accepted

Solution code:
#A_list =list(map(int,input().split()))
A_list = [int(x) for x in list(input())]
OP_list = ["","",""]
answer = ""
#current = 1
#current_sum = A_list[0]

def solve(current, current_sum):
    if current == 4:
        return current_sum == 7
    
    if solve(current + 1 , current_sum + A_list[current]):
        OP_list[current-1] = "+"
        return True
    
    if solve(current + 1 , current_sum - A_list[current]):
        OP_list[current-1] = "-"
        return True
    
    return False

solve(1,A_list[0])
answer = str(A_list[0]) + OP_list[0] + str(A_list[1]) + OP_list[1] + str(A_list[2]) + OP_list[2] + str(A_list[3]) + "=7"
print (answer)

Submission status: Accepted

Solution code:
t = list(map(int, list(input())))
t.append(7)
op = []

def dfs(x, i):
    if i == 4 or len(op) == 3:
        if x == 7:
            op.append('=')
            ans = ''
            for j in range(5):
                if j == 4:
                    ans += str(t[j])
                else:
                    ans += str(t[j]) + op[j]
            print(ans)
            exit()
        return

    i += 1
    op.append('+')
    dfs(x + t[i], i)
    op.pop()

    op.append('-')
    dfs(x - t[i], i)
    op.pop()
    i -= 1
    return

dfs(t[0], 0)