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:
import sys
a,b,c,d = map(int,input())
ans = 7 - a
li = ['+','-']
for i in li:
    for j in li:
        for k in li:
            bb = b if i=='+' else -b
            cc = c if j=='+' else -c
            dd = d if k=='+' else -d
            if bb+cc+dd == ans:
                print(str(a)+i+str(b)+j+str(c)+k+str(d)+'=7')
                sys.exit()

Submission status: Accepted

Solution code:
a,b,c,d=map(int,list(input()))
l=("+","-")
for q in range(2):
  for w in range(2):
    for e in range(2):
      if a+((-1)**q)*b+((-1)**w)*c+((-1)**e)*d==7:
        print(str(a)+l[q]+str(b)+l[w]+str(c)+l[e]+str(d)+"=7")
        exit()

Submission status: Accepted

Solution code:
# ABC079C - Train Ticket
from itertools import product


def main():
    a, b, c, d = input()
    for x, y, z in product(("+", "-"), repeat=3):
        eq = a + x + b + y + c + z + d
        if eval(eq) == 7:
            print(eq + "=7")
            break


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S=input()
A=[]
B=[0]*4
for i in range(len(S)):
    A.append(int(S[i]))

122

for i in range(2):
    for j in range(2):
        for k in range(2):
            total=A[0]
            if i==0:
                total+=A[1]
                B[0]='+'
            if i==1:
                total-=A[1]
                B[0] = '-'
            if j==0:
                total+=A[2]
                B[1] = '+'
            if j==1:
                total-=A[2]
                B[1] = '-'
            if k==0:
                total+=A[3]
                B[2] = '+'
            if k==1:
                total-=A[3]
                B[2] = '-'
            if total==7:
                print(S[0]+B[0]+S[1]+B[1]+S[2]+B[2]+S[3]+'=7')
                exit(0)

Submission status: Accepted

Solution code:
def main():
    ary = [str(i) for i in input()]
    make(ary)



def make(ary):
    moto = ['+','-']

    for i in moto:
        for j in moto:
            for k in moto:
                    pat = ary[0] + i + ary[1] + j + ary[2] + k + ary[3]
                    result = eval(pat)
                    if result == 7:
                        print(pat + '=' + str(result))
                        return 



if __name__ == '__main__':
    main()

Submission status: Accepted

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


def s(sign):
    return "+" if sign == 1 else "-"


for i in (1, -1):
    for j in (1, -1):
        for k in (1, -1):
            if A + i * B + j * C + k * D == 7:
                print("{}{}{}{}{}{}{}=7".format(A, s(i), B, s(j), C, s(k), D))
                exit()

Submission status: Accepted

Solution code:
N = input()
n = list(map(int,list(N)))
for i in range(1<<3):
    cal = n[0]
    s = []
    for j in range(3):
        if i%2 == 0:
            cal += n[j+1]
            s.append("+")
        else:
            cal -= n[j+1]
            s.append("-")
        i = i//2
    if cal == 7:
        print(N[0]+s[0]+N[1]+s[1]+N[2]+s[2]+N[3]+"=7")
        break

Submission status: Accepted

Solution code:
ABCD = input()
result = 0

output=[]
#+を加えていく代入する
for i in range(4):
    output += "+"
    output += ABCD[i]
output = ''.join(output)

#4*4ループ
for i in range(4**2): 
    result = output 
    for j in range (4):
        if( (i>>j) & 1 ):
            result = list(result)
            result[j*2] = "-"
            result = ''.join(result)
    # print("-------")
    # print(result)
    if eval(result)==7:
        if(result[0]=="+"):
            print(result[1:]+"=7")
            exit()

Submission status: Accepted

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

l={'+++':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}

for key,value in l.items():
    if value==7:
        print(str(A)+key[0]+str(B)+key[1]+str(C)+key[2]+str(D)+'=7')
        break

Submission status: Accepted

Solution code:
A = [int(v) for v in input()]

flag = False
for i in range(2):
  if flag:
    break
  total = A[0]
  if i == 0:
    total += A[1]
  else:
    total -= A[1]
  for j in range(2):
    if flag:
      break
    total2 = total
    if j == 0:
      total2 += A[2]
    else:
      total2 -= A[2]
    for k in range(2):
      total3 = total2
      if k == 0:
        total3 += A[3]
      else:
        total3 -= A[3]
      if total3 == 7:
        print(A[0], end='')
        if i == 0:
          print('+{}'.format(A[1]), end='')
        else:
          print('-{}'.format(A[1]), end='')
        if j == 0:
          print('+{}'.format(A[2]), end='')
        else:
          print('-{}'.format(A[2]), end='')
        if k == 0:
          print('+{}=7'.format(A[3]))
        else:
          print('-{}=7'.format(A[3]))
        flag = True
        break

Submission status: Accepted

Solution code:
ABCD = list(input())
p_m = []
for i in range(2 ** 3):
    tmp = bin(i)[2::]
    while len(tmp) < 3:
        tmp = "0" + tmp
    p_m.append(tmp)

for i in p_m:
    sum = int(ABCD[0])
    cnt = 1
    plusminus = []
    for j in i:
        # print(j, sum, cnt)
        if j == "1":
            sum += int(ABCD[cnt])
            plusminus.append("+")
        else:
            sum -= int(ABCD[cnt])
            plusminus.append("-")
        cnt += 1
    if sum == 7:
        for i in range(3):
            print(ABCD[i], end = "")
            print(plusminus[i], end = "")
        print(ABCD[3] + "=7")
        break

Submission status: Accepted

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

output = False

def calc_abcd(s):
    global output
    global abcd
    sum = abcd[0]
    for i in range(3):
        if s[i] == "+":
            sum += abcd[i+1]
        else:
            sum -= abcd[i+1]
    if sum == 7:
        result = str(abcd[0])+s[0]+str(abcd[1])+s[1]+str(abcd[2])+s[2]+str(abcd[3])+"=7"
        print(result)
        output = True


def dfs(s):
    global output
    if len(s) == 3:
        if not output:
            calc_abcd(s)
            return 0
        else:
            return 0
    dfs(s+"+")
    dfs(s+"-")
    return 0

dfs("")

Submission status: Accepted

Solution code:
def fnc(i, num):
    if i == 4:
        if num == 7:
            return True
        else:
            return False
    
    if fnc(i+1, num + n[i]):
        st.insert(1, "+" + str(n[i]))
        return True
    
    if fnc(i+1, num - n[i]):
        st.insert(1, "-" + str(n[i]))
        return True

n = list(map(int, input()))
st = [str(n[0]), "=7"]
fnc(1, n[0])
print(''.join(st))

Submission status: Accepted

Solution code:
import sys
s=input()
opt = ["+","-"]
for opt1 in opt:
    for opt2 in opt:
        for opt3 in opt:
            equation = s[0]+opt1+s[1]+opt2+s[2]+opt3+s[3]
            if  eval(equation) == 7:
                print(equation+"=7")
                sys.exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
nums = list(input())
def dfs(res, depth, path, S):
    if depth >= len(S) - 1:
        res.append(path)
        return 
    for char in ['+', '-']:
        dfs(res, depth+1, path+[char], S)

res = []
dfs(res, 0, [], nums)

for comb in res:
    calc = int(nums[0]) 
    string = nums[0]
    for i, func in enumerate(comb):
        if func == '+':
            string += '+' + nums[i+1]
            calc += int(nums[i+1])
        elif func == '-':
            string += '-' + nums[i+1]
            calc -= int(nums[i+1])
    if calc == 7:
        break

print(string+'=7')

Submission status: Accepted

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

# op1
for i in range(2):
  for j in range(2):
    for k in range(2):
      total = int(A) + (-1) ** i * int(B) + (-1) ** j * int(C) + (-1) ** k * int(D)
      if total == 7:
        op1 = "+" if i == 0 else "-"          
        op2 = "+" if j == 0 else "-"          
        op3 = "+" if k == 0 else "-"          

ans = A + op1 + B + op2 + C + op3 + D + "=7"

print(ans)

Submission status: Accepted

Solution code:
ABCD = input()

for i in range(1,2**3):
    X = ABCD[0]
    for j in range(3):
        if 1 << j & i:
            X += '+'
        else:
            X += '-'
        X += ABCD[j+1]
    # print('eval: ',X)
    if eval(X) == 7:
        print(X+'=7')
        break

Submission status: Accepted

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

op = ['-', '+']

for i in range(2 ** 3):
    s = A + op[i & 1] + B + op[(i >> 1) & 1] + C + op[(i >> 2) & 1] + D
    if eval(s) == 7:
        print(s+'=7')
        exit()

Submission status: Accepted

Solution code:
#きっぷの問題
num=input()
for i in range(0,8):
    t=[]
    k=i
    for j in range(0,3):
        if k>=2**(2-j):
            k=k-2**(2-j)
            t.append("+")
        else:
            t.append("-")
    a=int(num[0])
    for j in range(0,3):
        if t[j]=="+":
            a+=int(num[j+1])
        else:
            a-=int(num[j+1])
    if a==7:
        print(num[0]+t[0]+num[1]+t[1]+num[2]+t[2]+num[3]+"=7")
        break

Submission status: Accepted

Solution code:
s=input()
a=int(s[0])
b=int(s[1])
c=int(s[2])
d=int(s[3])
for i in range(8):
	if bin(i)[-1]=="1":
		x="+"
		p=a+b
	else: 
		x="-"
		p=a-b
	if bin(i)[-2]=="1":
		y="+"
		p+=c
	else:
		y="-"
		p-=c
	if bin(i)[-3]=="1":
		z="+"
		p+=d
	else:
		z="-"
		p-=d
	if p==7:
		print(str(a)+x+str(b)+y+\
			str(c)+z+str(d)+"="+str(7))
		break

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline

s = input().strip()
op = ["+","-"]
for i in op:
    for j in op:
        for k in op:
            x = s[0]+i+s[1]+j+s[2]+k+s[3]
            if eval(x) == 7:
                print(x+"=7")
                exit()

Submission status: Accepted

Solution code:
S = input()

ans = ''
def dfs(i, s):
    val = sum([int(s[i*2:i*2+2]) for i in range(len(s)//2)])
    if (i == 4) and (val==7):
        global ans
        ans = s
        return True
    
    if (i==4) and (val!=7):
        return False
    
    if dfs(i+1, s + '+' + S[i]):
        return True
    
    if dfs(i+1, s + '-' + S[i]):
        return True

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

Submission status: Accepted

Solution code:
ABCD = input()

A = int(ABCD[0])
B = int(ABCD[1])
C = int(ABCD[2])
D = int(ABCD[3])

o1 = '+'
o2 = '+'
o3 = '+'
flag = False
for j in range(2) :
    if j % 2 == 0 :
        B2 = -B
        o2 = '-'
    else :
        B2 = B
        o2 = '+'
    for k in range(2) :
        if k % 2 == 0 :
            C2 = -C
            o3 = '-'
        else :
            C2 = C
            o3 = '+'
        for l in range(2) :
            if l % 2 == 0 :
                D2 = -D
                o4 = '-'
            else :
                D2 = D
                o4 = '+'
            if A+B2+C2+D2 == 7 :
                #print(B2, C2, D2 , o2, o3 ,o4)
                flag = True
                break
        if flag :
            break
    if flag :
        break
ans = str(A) + o2 + str(B) + o3 + str(C) + o4 + str(D) + '=7'
print(ans)

Submission status: Accepted

Solution code:
L = list(raw_input())
for bit in range(1 << 3):
    P = [""] * 4
    for k in range(3):
        if bit & (1 << k):
            P[k] = "+"
        else:
            P[k] = "-"
    calc = ""
    for i in range(4):
        calc += L[i] + P[i]
    if eval(calc) == 7:
        ans = calc + "=7"
        break
print(ans)

Submission status: Accepted

Solution code:
import itertools
op = ["+", "-"]
s = input()
for i in itertools.product(op, repeat=3):
    sm = int(s[0])
    st = s[0]
    for j, v in enumerate(i):
        if v == "+":
            sm += int(s[j+1])
            st += v
            st += s[j+1]
        else:
            sm -= int(s[j+1])
            st += v
            st += s[j+1]
    if sm == 7:
        print(st + "=7")
        exit()

Submission status: Accepted

Solution code:
L = list(input())
for bit in range(1 << 3) :
    P = [""]*4
    for k in range(3) :
        if bit & (1 << k) :
            P[k] = "+"
        else :
            P[k] = "-"
    calc = ""
    for i in range(4) :
        calc += L[i] + P[i]
    if eval(calc) == 7 :
        ans = calc + "=7"
        break
print(ans)

Submission status: Accepted

Solution code:
n = list(raw_input())
operators = ["+", "-"]
total = None
for op1 in operators:
    for op2 in operators:
        for op3 in operators:
            total = n[0] + op1 + n[1] + op2 + n[2] + op3 + n[3]
            if eval(total) == 7:
                total = total + "=7"
                print(total)
                exit(0)

Submission status: Accepted

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

count = a
for i in range(8):
    a = int(s[0])
    for j in range(3):
        if i>>j&1 == 1:
            a += int(s[j+1])
        else:
            a -= int(s[j+1])
    if a == 7:
        ans = (str(bin(i))[2:]).zfill(3)
        ans = ans.replace("0","-")
        ans = ans.replace("1","+")
        print(str(s[0])+ans[2]+str(b)+ans[1]+str(c)+ans[0]+str(d)+"=7")
        break

Submission status: Accepted

Solution code:
A = input()
for i in range(0,2**3):
	X = [0]*3
	for k in range(3):
		if (i>>k)&1:
			X[k] = "+"
		else:
			X[k] = "-"
	if eval(A[0]+X[0]+A[1]+X[1]+A[2]+X[2]+A[3]) == 7:
		print(A[0]+X[0]+A[1]+X[1]+A[2]+X[2]+A[3]+"=7")
		break

Submission status: Accepted

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

operators = ["+", "-"]

for op1 in operators:
    for op2 in operators:
        for op3 in operators:
            equation = a+op1+b+op2+c+op3+d
            if eval(equation) == 7:
                print(equation+"=7")
                exit()

Submission status: Accepted

Solution code:
n = list(map(int,input().rstrip()))
for i in range(2**3):
  ope = ["-"] * 3
  ans = n[0]
  for j in range(3):
    if (i >> j) & 1:
      ope[j] = "+"
      ans += n[j+1]
    else:
      ans -= n[j+1]
  if ans == 7:
    res = [ope[i]+str(n[1+i]) for i in range(3)]
    res = "".join(res)
    res = str(n[0]) + res + "=7"
    print(res)
    break

Submission status: Accepted

Solution code:
n = list(map(int,input().rstrip()))
for i in range(2**3):
  ope = []
  ans = n[0]
  for j in range(3):
    if (i >> j) & 1:
      ope.append("+")
      ans += n[j+1]
    else:
      ope.append("-")
      ans -= n[j+1]
  if ans == 7:
    res = [ope[i]+str(n[1+i]) for i in range(3)]
    res = "".join(res)
    res = str(n[0]) + res + "=7"
    print(res)
    break

Submission status: Accepted

Solution code:
nums = input()
for i in range(2**3):
  binary=format(i, 'b').zfill(5)[2:]
  val = int(nums[0])
  val_str = nums[0]
  for j in range(1,len(nums)):
    if binary[j-1] == '1':
      val += int(nums[j])
      val_str += '+'+nums[j]
    else:
      val -= int(nums[j])
      val_str += '-'+nums[j]
  if val==7:
    print(val_str,'=7',sep='')
    break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
m = [1,-1]
def solve():
    a,b,c,d = list(map(int,list(input())))
    for i in m:
        for j in m:
            for k in m:
                if a + b * i + c * j + d * k == 7:
                    a,b,c,d = list(map(str,(a,b,c,d)))
                    i,j,k = list(map(lambda x:"+" if x==1 else "-",(i,j,k)))
                    print(a+i+b+j+c+k+d+"=7")
                    return
solve()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
S = input()
bin_list = [0, 0, 0]
for i in range(8):
    bin_list = [0, 0, 0]
    now = i
    # bitmapに変換
    for x in range(3):
        amari = now % 2
        now = now // 2
        if amari == 1:
            bin_list[x] = "+"
        else:
            bin_list[x] = "-"
    formula = S[0] + bin_list[0] + S[1] + bin_list[1] + S[2] + bin_list[2] + S[3]
    if eval(formula) == 7:
        print(formula + "=7")
        break

Submission status: Accepted

Solution code:
s = input()
s8=[]

def cal(p,n):
	if n==0:
		s8.append(p)
	else:
		cal(p[:n] + '+' + p[n:],n-1)
		cal(p[:n] + '-' + p[n:],n-1)

cal(s,len(s)-1)
for ss in s8:
	if eval(ss)==7:
		print(ss+'=7')
		exit()

Submission status: Accepted

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

def ope(i):
    if i == 0:
        return "+"
    else:
        return "-"

for i in range(2):
    if output != "":
        break
    for j in range(2):
        if output != "":
            break
        for k in range(2):
            result = a
            if i == 0:
                result += b
            else:
                result -= b
            if j == 0:
                result += c
            else:
                result -= c
            if k == 0:
                result += d
            else:
                result -= d
            if result == 7:
                output = "{}{}{}{}{}{}{}=7".format(a, ope(i), b, ope(j), c, ope(k), d)
                break

print(output)

Submission status: Accepted

Solution code:
i = input()

a=int(i[0])
b=int(i[1])
c=int(i[2])
d=int(i[3])
sa=i[0]
sb=i[1]
sc=i[2]
sd=i[3]

if(a+b+c+d==7):
    print(sa+"+"+sb+"+"+sc+"+"+sd+"=7")
elif (a+b+c-d==7):
    print(sa+"+"+sb+"+"+sc+"-"+sd+"=7")
elif (a+b-c+d==7):
    print(sa+"+"+sb+"-"+sc+"+"+sd+"=7")
elif(a-b+c+d==7):
    print(sa+"-"+sb+"+"+sc+"+"+sd+"=7")
elif(a-b-c+d==7):
    print(sa+"-"+sb+"-"+sc+"+"+sd+"=7")
elif(a-b+c-d==7):
    print(sa+"-"+sb+"+"+sc+"-"+sd+"=7")
elif(a+b-c-d==7):
    print(sa+"+"+sb+"-"+sc+"-"+sd+"=7")
elif(a-b-c-d==7):
    print(sa+"-"+sb+"-"+sc+"-"+sd+"=7")

Submission status: Accepted

Solution code:
z=input()
sa,sb,sc,sd=z[0],z[1],z[2],z[3]
a,b,c,d=int(z[0]),int(z[1]),int(z[2]),int(z[3])
if a+b+c+d==7:
    print(sa+'+'+sb+'+'+sc+'+'+sd+'=7')
elif a+b+c-d==7:
    print(sa+'+'+sb+'+'+sc+'-'+sd+'=7')
elif a+b-c+d==7:
    print(sa+'+'+sb+'-'+sc+'+'+sd+'=7')
elif a+b-c-d==7:
    print(sa+'+'+sb+'-'+sc+'-'+sd+'=7')
elif a-b+c+d==7:
    print(sa+'-'+sb+'+'+sc+'+'+sd+'=7')
elif a-b+c-d==7:
    print(sa+'-'+sb+'+'+sc+'-'+sd+'=7')
elif a-b-c+d==7:
    print(sa+'-'+sb+'-'+sc+'+'+sd+'=7')
else:
    print(sa+'-'+sb+'-'+sc+'-'+sd+'=7')

Submission status: Accepted

Solution code:
S = input()
sumS = int(S[0]) + int(S[1]) + int(S[2]) + int(S[3])
def minus(a, sumS):
    sS = sumS
    ba = bin(a)
    for ia,aa in enumerate(ba[::-1]):
        if aa == 'b':
            break
        elif aa == '1':
            sS -=  2 * int(S[ia+1:ia+2])
    if sS == 7:
        T = ['+', '+', '+', '=7']
        for ia,aa in enumerate(ba[::-1]):
            if aa == '1':
                T[ia] = '-'

        result = ''
        for i in range(len(S)):
            result += S[i] + T[i]
        return result
    else:

        return minus(a+1,sumS)
print(minus(0,sumS))

Submission status: Accepted

Solution code:
n = input()
a = int(n[0])
b = int(n[1])
c = int(n[2])
d = int(n[3])
e = [b,c,d]
l = [[0,0,0],[0,0,1],[0,1,0],[0,1,1],[1,0,0],[1,0,1],[1,1,0],[1,1,1]]
for i in range(8):
  ll = l[i]
  now = a
  for j in range(3):
    if ll[j] == 0:
      now += e[j]
    else:
      now -= e[j]
  if now == 7:
    f = []
    for j in range(3):
      if ll[j] == 0:
        f.append('+')
      else:
        f.append('-')
    print( str(a) + f[0] + str(b) + f[1] + str(c) + f[2] + str(d) + '=7' )
    break

Submission status: Accepted

Solution code:
a,b,c,d=[x for x in input()]
op='+-'
for op1 in op:
  for op2 in op:
    for op3 in op:
      ans=a+op1+b+op2+c+op3+d
      if eval(ans)==7:
        print('{}=7'.format(ans))
        exit()
      else:
        pass

Submission status: Accepted

Solution code:
import sys
a,b,c,d=[x for x in input()]
op='+-'
for op1 in op:
  for op2 in op:
    for op3 in op:
      ans=a+op1+b+op2+c+op3+d
      if eval(ans)==7:
        print('{}=7'.format(ans))
        sys.exit()
      else:
        pass

Submission status: Accepted

Solution code:
Number = list(input())

#while Number > 0:
#    list.append(Number % 10)
#    Number //= 10
#    list.reverse()

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

    temp = Number[0] + op[0] + Number[1] + op[1] + Number[2] + op[2] + Number[3]
    if eval(temp) == 7:
        print(temp + "=7")
        break

Submission status: Accepted

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

op1 = '-'
op2 = '-'
op3 = '-'
if A + B + C + D == 7:
  op1 = '+'
  op2 = '+'
  op3 = '+'
elif A + B + C - D == 7:
  op1 = '+'
  op2 = '+'
elif A + B - C + D == 7:
  op1 = '+'
  op3 = '+'
elif A + B - C - D == 7:
  op1 = '+'
elif A - B + C + D == 7:
  op2 = '+'
  op3 = '+'
elif A - B + C - D == 7:
  op2 = '+'
elif A - B - C + D == 7:
  op3 = '+'

print('{}{}{}{}{}{}{}=7'.format(A, op1, B, op2, C, op3, D))

Submission status: Accepted

Solution code:
s = input()
N = len(s)
sum = 0
for i in range(2**(N-1)):
	sum = int(s[0])
	for n in range(N-1):
		if (i >> n) & 1:
			sum += int(s[n+1])
		else:
			sum -= int(s[n+1])
	if sum == 7:
		print(s[0],end = "")
		for n in range(N-1):
			if (i >> n) & 1:
				print("+",end = "")
			else:
				print("-",end = "")
			print(s[n+1],end = "")
		print("=7")
		exit()

Submission status: Accepted

Solution code:
s_in = input()

def rec(s,n):
  if n==0:
    if eval(s)==7:
      return s+'=7'
    else:
      return ''
  else:    
    ret_p = rec(s[:n]+'+'+s[n:] ,n-1)
    ret_m = rec(s[:n]+'-'+s[n:] ,n-1)
  if ret_p:
    return ret_p
  if ret_m:
    return ret_m
  else:
    return ''

print(rec(s_in,len(s_in)-1))

Submission status: Accepted

Solution code:
S =list(input())
A,B,C,D = map(int,S)
a = str(A)
b = str(B)
c = str(C)
d = str(D)

for i in range(2):
    for j in range(2):
        for k in range(2):
            if i == 0 and j ==0 and k ==0:
                if A + B + C + D ==7:
                    print(a+"+"+b+"+"+c+"+"+d+"=7")
                    exit()
            elif i == 0 and j ==0 and k ==1:
                if A + B + C - D ==7:
                    print(a + "+" + b + "+" + c + "-" + d + "=7")
                    exit()
            elif i == 0 and j ==1 and k ==0:
                if A + B - C + D ==7:
                    print(a + "+" + b + "-" + c + "+" + d + "=7")
                    exit()
            elif i == 0 and j  ==1 and k ==1:
                if A+B-C-D ==7:
                    print(a + "+" + b + "-" + c + "-" + d + "=7")
                    exit()
            elif i == 1 and j == 0 and k == 0:
                if A-B+C+D ==7:
                    print(a + "-" + b + "+" + c + "+" + d + "=7")
                    exit()
            elif i == 1 and j == 0 and k == 1:
                if A-B+C-D ==7:
                    print(a + "-" + b + "+" + c + "-" + d + "=7")
                    exit()
            elif i == 1 and j == 1 and k ==0:
                if A-B-C+D ==7:
                    print(a + "-" + b + "-" + c + "+" + d + "=7")
                    exit()
            elif i == 1 and j == 1 and k ==1:
                if A-B-C-D==7:
                    print(a + "-" + b + "-" + c + "-" + d + "=7")
                    exit()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


def main():
    abcd = [int(x) for x in list(input().strip())]

    for i in range(8):
        s = abcd[0]
        bs = [int(x) for x in list('{0:03b}'.format(i))]

        for j, b in enumerate(bs, 1):
            if b == 0:
                s -= abcd[j]
            else:
                s += abcd[j]

        if s == 7:
            ans = str(abcd[0])
            for j, b in enumerate(bs, 1):
                ans += '+' if b == 1 else '-'
                ans += str(abcd[j])
            ans += '=7'
            print(ans)
            return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = input()

for i in range(2 ** (len(S) - 1)):
    op = ['-' for _ in range(len(S)-1)]
    for j in range(len(S)-1):
        if ((i >> j) & 1):
            op[j] = '+'
    
    formula = [f for i in [[n,op_] for n, op_ in zip(S, op + [''])] for f in i] 
    if eval(''.join(formula)) == 7:
        print(''.join(formula)+'=7')
        break

Submission status: Accepted

Solution code:
s = input()
lst = []
for c in s:
    lst.append(int(c))

for i in range(2**3):
    x = lst[0]
    s = format(i,'b').rjust(3,'0')
    
    for j in range(3):
        if s[j] == '1':
            x += lst[j+1]
        else:
            x -= lst[j+1]
    
    if x==7:
        ss = s
        break

ans = ''
for i in range(3):
    ans += str(lst[i])
    if ss[i] == '1':
        ans += '+'
    else:
        ans += '-'
else:
    ans += str(lst[3]) + '=7'
print(ans)

Submission status: Accepted

Solution code:
import sys
N=list(input())
A=N[0]
B=N[1]
C=N[2]
D=N[3]
op='+-'
for op1 in op:
  for op2 in op:
    for op3 in op:
      ans=A+op1+B+op2+C+op3+D
      if eval(ans)==7:
        print('{}=7'.format(ans))
        sys.exit()
      else:
        pass

Submission status: Accepted

Solution code:
a, b, c, d = list(input())
op = '+-'
for op1 in op:
    for op2 in op:
        for op3 in op:
            ans = a + op1 + b + op2 + c + op3 + d
            if eval(ans) == 7:
                print('{}=7'.format(ans))
                break
        else:
            continue
        break
    else:
        continue
    break

Submission status: Accepted

Solution code:
a, b, c, d = list(input())
op = '+-'
for op1 in op:
    for op2 in op:
        for op3 in op:
            ans = a + op1 + b + op2 + c + op3 + d
            # print(eval(ans))
            if eval(ans) == 7:
                print('{}=7'.format(ans))
                break
        else:
            continue
        break
    else:
        continue
    break

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

a,b,c,d = map(int,list(input())[:4])


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

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

def printans(a,b,c,d,op):
    ansstr = str(a)
    ansstr += '+' if op[0] == 0 else '-'
    ansstr += str(b)
    ansstr += '+' if op[1] == 0 else '-'
    ansstr += str(c)
    ansstr += '+' if op[2] == 0 else '-'
    ansstr += str(d)
    ansstr += '=7'

    print(ansstr)

ops = []
for i in range(2):
    for j in range(2):
        for k in range(2):
            ops.append((i, j, k))


for op in ops:
    ans = a
    for i,x in enumerate(op):
        if x == 0:
            if i == 0:
                ans = add(ans, b)
            if i == 1:
                ans = add(ans, c)
            if i == 2:
                ans = add(ans, d)
        else:
            if i == 0:
                ans = sub(ans, b)
            if i == 1:
                ans = sub(ans, c)
            if i == 2:
                ans = sub(ans, d)
    

    if ans == 7:
        printans(a,b,c,d,op)
        break

Submission status: Accepted

Solution code:
abcd = input()
a, b, c, d = abcd
# 0 = -, 1 = + bit探索

for i in range(2**3):
    sum = int(a)
    for j in range(3):
        if (i >> j) & 1:
            sum += int(abcd[3-j])
        else:
            sum -= int(abcd[3-j])

    if sum == 7:
        formula = str(format(i, '03b')).translate(str.maketrans('10', '+-'))
        print(a + formula[0] + b + formula[1] + c + formula[2] + d + '=7')
        break

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)
for i in range(2 ** (n - 1)):
    ans = int(s[0])
    for j in reversed(range(n - 1)):
        if (i >> j) & 1:
            ans += int(s[j + 1])
        else:
            ans -= int(s[j + 1])
    if ans == 7:
        for j in reversed(range(n - 1)):
            if (i >> j) & 1:
                s.insert(j + 1, '+')
            else:
                s.insert(j + 1, '-')
        print(''.join(s) + '=7')
        exit()

Submission status: Accepted

Solution code:


def mitsukeru(numlist):
	for i in range(2**3):
		listsum=numlist[0]
		outputstring='{}'.format(numlist[0])
		for j in range(3):
			if ((i >> j) & 1):
				listsum +=numlist[j+1]
				outputstring += '+{}'.format(numlist[j+1])
			else:
				listsum -=numlist[j+1]
				outputstring += '-{}'.format(numlist[j+1])
		if listsum == 7:
			return outputstring + '=7'
	return listsum

listnum= [int(x) for x in list(input())]
print(mitsukeru(listnum))

Submission status: Accepted

Solution code:
def solve():
    cs = [c for c in input()]
    for i in range(2 ** 3):
        symbols = ["+" if b == "0" else "-" for b in list('{:03b}'.format(i))] + [""]
        formula = "".join([x[0] + x[1] for x in zip(cs, symbols)])
        result = eval(formula)
        if result == 7:
            return formula + "=7"


if __name__ == "__main__":
    print(solve())

Submission status: Accepted

Solution code:
def solve():
    a, b, c, d = [c for c in input()]
    conversion = {"0": "+", "1": "-"}
    for i in range(2 ** 3):
        b3, b2, b1 = list('{:03b}'.format(i))
        formula = str(a) + conversion[b3] + str(b) + conversion[b2] + str(c) + conversion[b1] + str(d)
        result = eval(formula)
        if result == 7:
            return formula + "=7"


if __name__ == "__main__":
    print(solve())

Submission status: Accepted

Solution code:
A,B,C,D=list(input())
import itertools
for i in itertools.product(["+","-"],repeat=3):
  F=A+i[0]+B+i[1]+C+i[2]+D
  x=eval(F)
  if x==7:
    break  
print(F+"=7")

Submission status: Accepted

Solution code:

abcd = input()
num = [int(i) for i in abcd]
anslist = []
def solve(i,a,seven,ans):
    if i == 3:
        if seven == 7:
            return ans+'=7'
            
            
        else:
            return False

    if solve(i+1,a,seven+a[i+1],ans+'+'+str(a[i+1])):
        return solve(i+1,a,seven+a[i+1],ans+'+'+str(a[i+1]))
    
    if solve(i+1,a,seven-a[i+1],ans+'-'+str(a[i+1])):
        return solve(i+1,a,seven-a[i+1],ans+'-'+str(a[i+1]))

print(solve(0,num,num[0],str(num[0])))

Submission status: Accepted

Solution code:
N = input()
operation_cnt = len(N) - 1

for i in range(1 << operation_cnt):
    operation = ["-"] * operation_cnt
    for j in range(operation_cnt):
        if ((i >> j) & 1):
            operation[j] = "+"

    formula = ""
    for num,operator in zip(N, operation + [""]):
        formula += (num + operator)
    if eval(formula) == 7:
        print(formula + "=7")
        exit()

Submission status: Accepted

Solution code:
op = [['+', '+', '+'], ['+', '+', '-'], ['+', '-', '+'], ['-', '+', '+'], ['+', '-', '-'], ['-', '+', '-'],
      ['-', '-', '+'], ['+', '-', '-']]

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

for i in range(8):
    s = a[0]
    for j in range(3):
        if op[i][j] == '+':
            s += a[j + 1]
        else:
            s -= a[j + 1]
    if s == 7:
        for k in range(3):
            print(a[k], end='')
            print(op[i][k], end='')
        print(str(a[-1])+'=7')
        exit()