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

while True:
    if int(val[0]) + int(val[1]) + int(val[2]) + int(val[3]) == 7:
        print("{0}+{1}+{2}+{3}=7".format(int(val[0]), int(val[1]), int(val[2]), int(val[3])))
        break
    elif int(val[0]) - int(val[1]) - int(val[2]) - int(val[3]) == 7:
        print("{0}-{1}-{2}-{3}=7".format(int(val[0]), int(val[1]), int(val[2]), int(val[3])))
        break
    elif int(val[0]) - int(val[1]) + int(val[2]) + int(val[3]) == 7:
        print("{0}-{1}+{2}+{3}=7".format(int(val[0]), int(val[1]), int(val[2]), int(val[3])))
        break
    elif int(val[0]) + int(val[1]) - int(val[2]) + int(val[3]) == 7:
        print("{0}+{1}-{2}+{3}=7".format(int(val[0]), int(val[1]), int(val[2]), int(val[3])))
        break
    elif int(val[0]) + int(val[1]) + int(val[2]) - int(val[3]) == 7:
        print("{0}+{1}+{2}-{3}=7".format(int(val[0]), int(val[1]), int(val[2]), int(val[3])))
        break
    elif int(val[0]) - int(val[1]) - int(val[2]) + int(val[3]) == 7:
        print("{0}-{1}-{2}+{3}=7".format(int(val[0]), int(val[1]), int(val[2]), int(val[3])))
        break
    elif int(val[0]) - int(val[1]) + int(val[2]) - int(val[3]) == 7:
        print("{0}-{1}+{2}-{3}=7".format(int(val[0]), int(val[1]), int(val[2]), int(val[3])))
        break
    elif int(val[0]) + int(val[1]) - int(val[2]) - int(val[3]) == 7:
        print("{0}+{1}-{2}-{3}=7".format(int(val[0]), int(val[1]), int(val[2]), int(val[3])))
        break

Submission status: Accepted

Solution code:
import itertools
S = input()

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

Submission status: Accepted

Solution code:
t=list(input())
for i in range(1<<3):
    ans=""
    ans+=t[0]
    for j in range(3):
        if i&(1<<j):
            ans+="+"
            ans+=t[j+1]
        else:
            ans+="-"
            ans+=t[j+1]
    if eval(ans)==7:
        print(ans+"=7")
        exit()

Submission status: Accepted

Solution code:
s = str(input())  #
n = len(s) -1 # 
for i in range(1<<n):#0-2**nまで
    equ = s[0]
    for j in range(n):
        if i & (1<<j):#iの2進数展開のj+1桁目が０でない
            equ = equ + '+' + s[j+1]
        else:
            equ = equ + '-' + s[j+1]
    if (eval(equ) == 7):
        print(equ + '=7')
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
line = list(map(int, list(input())))
l = len(line)-1
beki_list = [[0]*(l) for i in range(2**l)]

for i in range(2**l):
	i_2 = format(i, 'b')[::-1]
	for j in range(len(i_2)):
		beki_list[i][j] = int(i_2[j])

for i in beki_list:
	num = line[::1]
	pm_l = [num.pop(0)]
	for j in i:
		if j:
			pm_l += [num.pop(0)]
		else:
			pm_l += [-num.pop(0)]
	if (sum(pm_l) == 7):
		for n, k in enumerate(pm_l):
			if n == 0:
				print(str(k), end='')
			else:
				if k >= 0:
					print('+{}'.format(k), end='')
				else:
					print(str(k), end='')
		print('=7')
		exit()

Submission status: Accepted

Solution code:
s = input()
a = int(s[0])
b = [int(s[1]), - int(s[1])]
c = [int(s[2]), - int(s[2])]
d = [int(s[3]), - int(s[3])]
e = 0
f = 0
g = 0
sign = ["+", "-"]
for i in range(2):
    for j in range(2):
        for k in range(2):
            if a+b[i]+c[j]+d[k] == 7:
                e = i
                f = j
                g = k
print(str(a)+sign[e]+str(b[0])+sign[f]+str(c[0])+sign[g]+str(d[0])+"=7")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import operator
from itertools import product

A, B, C, D = list(map(int, list(input())))
map_operator = {0: operator.sub, 1: operator.add}
map_string = {0: '-', 1: '+'}

for i, j, k in product((0, 1), repeat=3):
    sum = map_operator[k](map_operator[j](map_operator[i](A, B), C), D)
    if sum == 7:
        break

print(str(A) + map_string[i] + str(B) + map_string[j] \
    + str(C) + map_string[k] + str(D) + "=7")

Submission status: Accepted

Solution code:
n = input()
a = [int(x) for x in n]
if a[0]+a[1]+a[2]+a[3]==7:
    print(str(a[0])+'+'+str(a[1])+'+'+str(a[2])+'+'+str(a[3])+'=7')
elif a[0]+a[1]+a[2]-a[3]==7:
    print(str(a[0])+'+'+str(a[1])+'+'+str(a[2])+'-'+str(a[3])+'=7')
elif a[0]+a[1]-a[2]+a[3]==7:
    print(str(a[0])+'+'+str(a[1])+'-'+str(a[2])+'+'+str(a[3])+'=7')
elif a[0]+a[1]-a[2]-a[3]==7:
    print(str(a[0])+'+'+str(a[1])+'-'+str(a[2])+'-'+str(a[3])+'=7')
elif a[0]-a[1]+a[2]+a[3]==7:
    print(str(a[0])+'-'+str(a[1])+'+'+str(a[2])+'+'+str(a[3])+'=7')
elif a[0]-a[1]+a[2]-a[3]==7:
    print(str(a[0])+'-'+str(a[1])+'+'+str(a[2])+'-'+str(a[3])+'=7')
elif a[0]-a[1]-a[2]+a[3]==7:
    print(str(a[0])+'-'+str(a[1])+'-'+str(a[2])+'+'+str(a[3])+'=7')
elif a[0]-a[1]-a[2]-a[3]==7:
    print(str(a[0])+'-'+str(a[1])+'-'+str(a[2])+'-'+str(a[3])+'=7')

Submission status: Accepted

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

op = ['+', '-']

for i in range(7):
    formula = A + op[(i >> 0) & 1] + B + op[(i >> 1) & 1] + C + op[(i >> 2) & 1] + D
    if eval(formula) == 7:
        print(formula + '=7')
        break

Submission status: Accepted

Solution code:
s = input()
if int(s[0])+int(s[1])+int(s[2])+int(s[3]) == 7:
    op1, op2, op3 = "+", "+", "+"
if int(s[0])+int(s[1])+int(s[2])-int(s[3]) == 7:
    op1, op2, op3 = "+", "+", "-"
if int(s[0])+int(s[1])-int(s[2])+int(s[3]) == 7:
    op1, op2, op3 = "+", "-", "+"
if int(s[0])+int(s[1])-int(s[2])-int(s[3]) == 7:
    op1, op2, op3 = "+", "-", "-"
if int(s[0])-int(s[1])+int(s[2])+int(s[3]) == 7:
    op1, op2, op3 = "-", "+", "+"
if int(s[0])-int(s[1])+int(s[2])-int(s[3]) == 7:
    op1, op2, op3 = "-", "+", "-"
if int(s[0])-int(s[1])-int(s[2])+int(s[3]) == 7:
    op1, op2, op3 = "-", "-", "+"
if int(s[0])-int(s[1])-int(s[2])-int(s[3]) == 7:
    op1, op2, op3 = "-", "-", "-"
print(s[0]+op1+s[1]+op2+s[2]+op3+s[3]+"=7")

Submission status: Accepted

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

S = raw_input()
length = len(S)
N = 7

def dfs(depth, S):

    if depth == length - 1:
        if eval(S) == N:
            print S + "=" + str(N)
            return True

        else:
            return False

    # 「-」を入れる場合
    if dfs(depth + 1, insert_minus(S, depth)):
        return True

    # 「+」を入れる場合
    if dfs(depth + 1, insert_plus(S, depth)):
        return True

    return False

def insert_plus(S, depth):
    d = depth + S.count("+") + S.count("-") + 1
    return "{0}{1}{2}".format(S[:d],"+",S[d:])

def insert_minus(S, depth):
    d = depth + S.count("+") + S.count("-") + 1
    return "{0}{1}{2}".format(S[:d],"-",S[d:])

dfs(0,S)

Submission status: Accepted

Solution code:
def m():
    S = input()
    a, b, c, d = map(int, S)
    ope = [1, -1]
    sig_ope = ['+', '-']
    for w in range(2):
        for x in range(2):
            for y in range(2):
                ans = a + (b * ope[w]) + (c * ope[x]) + (d * ope[y])
                if ans == 7:
                    return "{0}{1}{2}{3}{4}{5}{6}=7".format(
                        a, sig_ope[w], b, sig_ope[x], c, sig_ope[y], d
                    )


print(m())

Submission status: Accepted

Solution code:
s = input()

for i in range(1<<len(s)-1):
    t = list(s)
    for j in reversed(range(1,len(s))):
        if i & (1<<(j-1)):
            t = t[:j]+["+"]+t[j:]
        else:
            t = t[:j]+["-"]+t[j:]
    ans = eval("".join(t))
    if ans == 7:
        break

print("".join(t)+"=7")

Submission status: Accepted

Solution code:
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()
    array_result.append(data.split(" "))

    flg = 1

    try:
        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result

arr_data = getinputdata()

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

#print(a, b, c, d)

#+++
if a + b + c + d == 7:
  
    print(str(a) + "+" + str(b) + "+" + str(c) + "+" + str(d) + "=7") 

#+-+    
elif a + b - c + d == 7:

    print(str(a) + "+" + str(b) + "-" + str(c) + "+" + str(d) + "=7") 
  
#++-    
elif a + b + c -d == 7:

    print(str(a) + "+" + str(b) + "+" + str(c) + "-" + str(d) + "=7") 
  
#+--
elif a + b - c - d == 7:
  
    print(str(a) + "+" + str(b) + "-" + str(c) + "-" + str(d) + "=7") 
  

#-++   
elif a - b + c + d == 7:

    print(str(a) + "-" + str(b) + "+" + str(c) + "+" + str(d) + "=7") 
  
#-+-
elif a - b + c - d == 7:

    print(str(a) + "-" + str(b) + "+" + str(c) + "-" + str(d) + "=7") 
  
#--+
elif a - b - c + d == 7:
    
    print(str(a) + "-" + str(b) + "-" + str(c) + "+" + str(d) + "=7") 
  
#---
elif a - b - c - d == 7:

    print(str(a) + "-" + str(b) + "-" + str(c) + "-" + str(d) + "=7")

Submission status: Accepted

Solution code:
def kippu():
    N = input()

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

    op = ["+","-"]

    for one in op:
        for two in op:
            for three in op:
                ANS = A
                ANS = ANS + B if one=="+" else ANS - B
                ANS = ANS + C if two=="+" else ANS - C
                ANS = ANS + D if three=="+" else ANS - D
                if ANS==7:
                    print("{}{}{}{}{}{}{}=7".format(A,one,B,two,C,three,D))
                    return 0

kippu()

Submission status: Accepted

Solution code:
a, b, c, d = [i for i in input()]
op = ['+', '-']

for i in op:
    for j in op:
        for k in op:
            if eval(a+i+b+j+c+k+d) == 7:
                print("{}=7".format(a+i+b+j+c+k+d))
                break

        else:
            continue
        break

    else:
        continue
    break

Submission status: Accepted

Solution code:
import itertools
N = list(input())
M = list(map(int, N))


def sign(a):
    if a == 0:
        return '+'
    else:
        return '-'


flag = 0
for b, c, d in itertools.product(range(2), range(2), range(2)):
    if M[1]*(-1)**b+M[2]*(-1)**c+M[3]*(-1)**d == 7-M[0]:
        b = sign(b)
        c = sign(c)
        d = sign(d)
        break

print(str(M[0])+b+str(M[1])+c+str(M[2])+d+str(M[3])+'=7')

Submission status: Accepted

Solution code:
S = input()
a = S[0]
b = S[1]
c = S[2]
d = S[3]
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

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

Submission status: Accepted

Solution code:
p = str(input())

q =list(str(p))
r = []

for i in range(len(q)):
    r.append(int(q[i]))

a = r[0]
b = [-r[1],r[1]]
c = [-r[2],r[2]]
d = [-r[3],r[3]]

e = []
for i in range(2):
    for j in range(2):
        for k in range(2):
            if a + b[i] + c[j] + d[k] == 7:
                e.append(a)
                e.append(b[i])
                e.append(c[j])
                e.append(d[k])

for i in range(len(e)):
    if e[i] < 0 or i == 0:
        e[i] = str(e[i])
    else:
        e[i] = '+' + str(e[i])
        
print(e[0] + e[1] + e[2] + e[3] + '=7')

Submission status: Accepted

Solution code:
import sys



def plus_or_minus(opr1, opr2, op):
    if op == '+':
        return opr1 + opr2
    else:
        return opr1 - opr2


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

op = ['+', '-']

for i in range(2):
    for j in range(2):
        for k in range(2):
            o2 = plus_or_minus(A, B, op[i])
            o3 = plus_or_minus(o2, C, op[j])
            o4 = plus_or_minus(o3, D, op[k])
            if o4 == 7:
                print('{}{}{}{}{}{}{}=7'.format(A, op[i], B, op[j], C, op[k], D))
                sys.exit()

Submission status: Accepted

Solution code:
S = input()
OPs =["+++","++-","+-+","+--","-++","-+-","--+","---"]
for op in OPs:
    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:
from itertools import product

def solve(a, b, c, d):
    for ops in product('+-', repeat=3):
        op = a + ops[0] + b + ops[1] + c + ops[2] + d
        if eval(op) == 7:
            return op + '=7'


if __name__ == '__main__':
    a, b, c, d = input()
    print(solve(a, b, c, d))

Submission status: Accepted

Solution code:
flag = False
s = list(input())
candidate = []
op = '+-'
for i in op:
    for j in op:
        for k in op:
            candidate = s[0]+i+s[1]+j+s[2]+k+s[3]
            if eval(candidate)==7:
                print(candidate+'=7')
                exit()

Submission status: Accepted

Solution code:
flag = False
s = list(input())
candidate = []
op = '+-'
for i in op:
    for j in op:
        for k in op:
            candidate = s[0]+i+s[1]+j+s[2]+k+s[3]
            if eval(candidate)==7:
                print(candidate+'=7')
                flag = True
                break
        if flag:
            break
    if flag:
        break

Submission status: Accepted

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

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    numbers = list(input())
    a = numbers[0]
    b = numbers[1]
    c = numbers[2]
    d = numbers[3]
    
    # See:
    # https://abc079.contest.atcoder.jp/submissions/1917934
    ops = ['+', '-']

    for op1 in ops:
        for op2 in ops:
            for op3 in ops:
                expression = a + op1 + b + op2 + c + op3 + d
                
                if eval(expression) == 7:
                    print(expression + '=7')
                    exit()

Submission status: Accepted

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

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    numbers = list(map(int, list(input())))
    result = '=7'
    a = numbers[0]
    b = numbers[1]
    c = numbers[2]
    d = numbers[3]
    total = 7

    # FIME: More smartly.
    if a + b + c + d == total:
        print(str(a) + '+' + str(b) + '+' + str(c) + '+' + str(d) + result)
    elif a + b + c - d == total:
        print(str(a) + '+' + str(b) + '+' + str(c) + '-' + str(d) + result)
    elif a + b - c + d == total:
        print(str(a) + '+' + str(b) + '-' + str(c) + '+' + str(d) + result)
    elif a + b - c - d == total:
        print(str(a) + '+' + str(b) + '-' + str(c) + '-' + str(d) + result)
    elif a - b + c + d == total:
        print(str(a) + '-' + str(b) + '+' + str(c) + '+' + str(d) + result)
    elif a - b + c - d == total:
        print(str(a) + '-' + str(b) + '+' + str(c) + '-' + str(d) + result)
    elif a - b - c + d == total:
        print(str(a) + '-' + str(b) + '-' + str(c) + '+' + str(d) + result)
    elif a - b - c - d == total:
        print(str(a) + '-' + str(b) + '-' + str(c) + '-' + str(d) + result)

Submission status: Accepted

Solution code:
abcd = list(input())
a,b,c,d = int(abcd[0]),int(abcd[1]),int(abcd[2]),int(abcd[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:
# -*- coding: utf-8 -*-

s = input()
bitlist = []
for i in range(2**(len(s)-1)):
    bitlist.append([int(x) for x in list(bin(i)[2::].zfill(len(s)-1))])
for bit in bitlist:
    formula = s[0]
    ans = int(s[0])
    for i, sign in enumerate(bit):
        if sign == 0:#プラスとする
            formula += '+'
            ans += int(s[i+1])
        else:#マイナスとする
            formula += '-'
            ans -= int(s[i+1])
        formula += s[i+1]
    #print(formula)
    #print(ans)
    if ans == 7:
        print(formula + '=7')
        break

Submission status: Accepted

Solution code:
def c_train_ticket(N):
    A, B, C, D = map(int, N)
    # 各演算子の決定。本問では高々8通りなので愚直にやる
    # オペランド数が増えた場合は、バイナリを演算子の並びとみなせばよい
    operator = ['---', '--+', '-+-', '-++', '+--', '+-+', '++-', '+++']

    ans = ''
    for i, op in enumerate(operator):
        code = 'A {0} B {1} C {2} D'.format(op[0], op[1], op[2])
        if eval(code) == 7:
            ans = '{0}{1}{2}{3}{4}{5}{6}=7'.format(
                A, op[0], B, op[1], C, op[2], D)
            break  # 1つ見つければいい
    return ans

N = input()
print(c_train_ticket(N))

Submission status: Accepted

Solution code:
n = input()
a = []
for i in n:
    a.append(int(i))

if a[0]+a[1]+a[2]+a[3] == 7 :
    print('{}+{}+{}+{}=7'.format(a[0],a[1],a[2],a[3]))
elif a[0]+a[1]+a[2]-a[3] == 7 :
    print('{}+{}+{}-{}=7'.format(a[0],a[1],a[2],a[3]))
elif a[0]+a[1]-a[2]+a[3] == 7 :
    print('{}+{}-{}+{}=7'.format(a[0],a[1],a[2],a[3]))
elif a[0]+a[1]-a[2]-a[3] == 7 :
    print('{}+{}-{}-{}=7'.format(a[0],a[1],a[2],a[3]))
elif a[0]-a[1]+a[2]+a[3] == 7 :
    print('{}-{}+{}+{}=7'.format(a[0],a[1],a[2],a[3]))
elif a[0]-a[1]+a[2]-a[3] == 7 :
    print('{}-{}+{}-{}=7'.format(a[0],a[1],a[2],a[3]))
elif a[0]-a[1]-a[2]+a[3] == 7 :
    print('{}-{}-{}+{}=7'.format(a[0],a[1],a[2],a[3]))
elif a[0]-a[1]-a[2]-a[3] == 7 :
    print('{}-{}-{}-{}=7'.format(a[0],a[1],a[2],a[3]))

Submission status: Accepted

Solution code:
S = input()
ans = 0
for i in range(8):
    tmp = S[0]
    for j in range(3):
        if i & (1<<j):
            tmp += "-"
        else:
            tmp += "+"
        tmp += S[j+1]
    if eval(tmp) == 7:
        print(tmp+"=7")
        break

Submission status: Accepted

Solution code:
a, b, c, d = map(int, 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))
elif a - b - c - d == 7: print('{}-{}-{}-{}=7'.format(a, b, c, d))

Submission status: Accepted

Solution code:
a=list(input())
for i in range(8):
    s=a[0]
    for j in range(3):
        if i&(1<<j):
            s+="+"
        else:
            s+="-"
        s+=a[j+1]
    if eval(s)==7:
        print(s+"=7")
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
abcd = list(input())
for x in range(2):
    for y in range(2):
        for z in range(2):
            op1 = '+'
            if x == 0:
                op1 = '-'
            op2 = '+'
            if y == 0:
                op2 = '-'
            op3 = '+'
            if z == 0:
                op3 = '-'
            s = str(abcd[0]) + op1 + str(abcd[1]) + op2 + str(abcd[2]) + op3 + str(abcd[3])
            if eval(s) == 7:
                print(s + '=7')
                break
        else:
            continue
        break
    else:
        continue
    break

Submission status: Accepted

Solution code:
# ABC 079 C

A, B, C, D = map(int, input())
for f in [('{}'*7).format(A, x, B, y, C, z, D)
          for x in '+-'
          for y in '+-'
          for z in '+-']:
    if eval(f) == 7:
        print('{}=7'.format(f))
        break

Submission status: Accepted

Solution code:
a,b,c,d=map(str,list(input()))
x,y,z=" "," "," "
cou=0
for i in range(1<<3):
    
    if i&1: x="+"
    else: x="-"
    if i&2: y="+"
    else: y="-"
    if i&4: z="+"
    else: z="-"
    
    if eval(a+x+b+y+c+z+d)==7:
        print(a+x+b+y+c+z+d+"=7")
        break
    cou+=1
if cou==8:
    print("No")

Submission status: Accepted

Solution code:
def f(x):
    if x == -1:
        return '-'
    else:
        return '+'
a, b, c, d = [int(i) for i in list(input())]
list = [-1, 1]
ans = []
for i in list:
    for j in list:
        for k in list:
                if a + i*b + j*c + k*d == 7:
                    print('{}{}{}{}{}{}{}=7'.format(a, f(i), b, f(j), c, f(k), d))
                    exit()

Submission status: Accepted

Solution code:
S=input()
a=int(S[0])
b=int(S[1])
c=int(S[2])
d=int(S[3])
def operation(a,b,t):    
    if t==0:return a+b
    else:return a-b
def converter(t):
    if t==0:return "+"
    else:return "-"
e=0
f=0
g=0
for x in range(2):
    for y in range(2):
        for z in range(2):
            e=operation(a,b,x)
            f=operation(e,c,y)
            g=operation(f,d,z)
            if g==7:
                print(str(a)+converter(x)+str(b)+converter(y)+str(c)+converter(z)+str(d)+"=7")
                exit()

Submission status: Accepted

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


def find_combination(a):
    for indices in itertools.product(range(2), repeat=3):
        count = a[0]
        for i in range(3):
            if indices[i] == 0:
                count += a[i+1]
            else:
                count -= a[i+1]
            if count == 7:
                return indices
    return None


if __name__ == '__main__':
    a = [int(i) for i in input()]
    indices = find_combination(a)
    result = str(a[0])
    for i in range(3):
        if indices[i] == 0:
            result += '+'
        else:
            result += '-'
        result += str(a[i+1])
    print(result + '=7')

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

a = list(ns())
s = []
for i in ["+", "-"]:
    for j in ["+", "-"]:
        for k in ["+", "-"]:
            s.append(a[0] + i + a[1] + j + a[2] + k + a[3])

ans = 0
for i in range(len(s)):
    if s[i][1] == "+" and s[i][3] == "+" and s[i][5] == "+":
        ans = int(s[i][0]) + int(s[i][2]) + int(s[i][4]) + int(s[i][6])
        if ans == 7:
            print(str(s[i][0]) + "+" +str(s[i][2]) + "+" +str(s[i][4]) + "+" +str(s[i][6]) + "=7")
            break
    if s[i][1] == "+" and s[i][3] == "+" and s[i][5] == "-":
        ans = int(s[i][0]) + int(s[i][2]) + int(s[i][4]) - int(s[i][6])
        if ans == 7:
            print(str(s[i][0]) + "+" +str(s[i][2]) + "+" +str(s[i][4]) + "-" +str(s[i][6]) + "=7")
            break
    if s[i][1] == "+" and s[i][3] == "-" and s[i][5] == "+":
        ans = int(s[i][0]) + int(s[i][2]) - int(s[i][4]) + int(s[i][6])
        if ans == 7:
            print(str(s[i][0]) + "+" +str(s[i][2]) + "-" +str(s[i][4]) + "+" +str(s[i][6]) + "=7")
            break
    if s[i][1] == "+" and s[i][3] == "-" and s[i][5] == "-":
        ans = int(s[i][0]) + int(s[i][2]) - int(s[i][4]) - int(s[i][6])
        if ans == 7:
            print(str(s[i][0]) + "+" +str(s[i][2]) + "-" +str(s[i][4]) + "-" +str(s[i][6]) + "=7")
            break
    if s[i][1] == "-" and s[i][3] == "+" and s[i][5] == "+":
        ans = int(s[i][0]) - int(s[i][2]) + int(s[i][4]) + int(s[i][6])
        if ans == 7:
            print(str(s[i][0]) + "-" +str(s[i][2]) + "+" +str(s[i][4]) + "+" +str(s[i][6]) + "=7")
            break
    if s[i][1] == "-" and s[i][3] == "+" and s[i][5] == "-":
        ans = int(s[i][0]) - int(s[i][2]) + int(s[i][4]) - int(s[i][6])
        if ans == 7:
            print(str(s[i][0]) + "-" +str(s[i][2]) + "+" +str(s[i][4]) + "-" +str(s[i][6]) + "=7")
            break
    if s[i][1] == "-" and s[i][3] == "-" and s[i][5] == "+":
        ans = int(s[i][0]) - int(s[i][2]) - int(s[i][4]) + int(s[i][6])
        if ans == 7:
            print(str(s[i][0]) + "-" +str(s[i][2]) + "-" +str(s[i][4]) + "+" +str(s[i][6]) + "=7")
            break
    if s[i][1] == "-" and s[i][3] == "-" and s[i][5] == "-":
        ans = int(s[i][0]) - int(s[i][2]) - int(s[i][4]) - int(s[i][6])
        if ans == 7:
            print(str(s[i][0]) + "-" +str(s[i][2]) + "-" +str(s[i][4]) + "-" +str(s[i][6]) + "=7")
            break

Submission status: Accepted

Solution code:
import sys
S = list(input())
op = ['+', '-']
for i in range(1<<len(S)-1):
    f = S[0]
    for j in range(len(S)-1):
        if i&(1<<j):
            f += '+'
        else:
            f += '-'
        f += S[j+1]
    if eval(f)==7:
        break
print(f+'=7')

Submission status: Accepted

Solution code:
import itertools
n = input()
x, pm, a = [], [1,-1], 7-int(n[0])
for i in range(1,4):
	x.append(int(n[i]))
for j in itertools.product(pm,repeat=3):
	if x[0]*j[0]+x[1]*j[1]+x[2]*j[2]==a:
		y = list(j)
		break
for k in range(3):
	if y[k]==1:
		y[k] = "+"
	else:
		y[k] = "-"
print(n[0]+y[0]+n[1]+y[1]+n[2]+y[2]+n[3]+"=7")

Submission status: Accepted

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]

s=input()
ss=""
for i in range(1<<3):
 x=s[0]
 y=int(s[0])
 for j in range(3):
   if i>>j&1:
      x+="+"+s[j+1]
      y+=int(s[j+1])
   else:
      x+="-"+s[j+1]
      y-=int(s[j+1])
 if y==7:ss=x+"=7"
print(ss)

Submission status: Accepted

Solution code:
A, B, C, D = map(int, list(input()))
op = ['+', '-']

for p in range(2):
    for q in range(2):
        for r in range(2):
            s = '{}{}{}{}{}{}{}'.format(A, op[p], B, op[q], C, op[r], D)
            if eval(s) == 7:
                print(s + '=7')
                exit()

Submission status: Accepted

Solution code:
n = list(raw_input())
op = ['+', '-']

for o1 in op:
	for o2 in op:
		for o3 in op:
			s = n[0] + o1 + n[1] + o2 + n[2] + o3 + n[3]
			if eval(s) == 7:
				print s + '=7'
				exit(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()
T=[0]*4
for i in range(4):
    T[i]=int(S[i])

if T[0]+T[1]+T[2]+T[3]==7: print(S[0]+"+"+S[1]+"+"+S[2]+"+"+S[3]+"=7")
elif T[0]+T[1]+T[2]-T[3]==7: print(S[0]+"+"+S[1]+"+"+S[2]+"-"+S[3]+"=7")
elif T[0]+T[1]-T[2]-T[3]==7: print(S[0]+"+"+S[1]+"-"+S[2]+"-"+S[3]+"=7")
elif T[0]+T[1]-T[2]+T[3]==7: print(S[0]+"+"+S[1]+"-"+S[2]+"+"+S[3]+"=7")
elif T[0]-T[1]-T[2]-T[3]==7: print(S[0]+"-"+S[1]+"-"+S[2]+"-"+S[3]+"=7")
elif T[0]-T[1]-T[2]+T[3]==7: print(S[0]+"-"+S[1]+"-"+S[2]+"+"+S[3]+"=7")
elif T[0]-T[1]+T[2]+T[3]==7: print(S[0]+"-"+S[1]+"+"+S[2]+"+"+S[3]+"=7")
elif T[0]-T[1]+T[2]-T[3]==7: print(S[0]+"-"+S[1]+"+"+S[2]+"-"+S[3]+"=7")

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    S = input()
    recur_num = (len(S) - 1) ** 2

    for i in range(recur_num):
        ope = []
        for j in range(len(S) - 1):
            if i & (2 ** j):
                ope.append("+")
            else:
                ope.append("-")

        if eval(S[0] + ope[0] + S[1] + ope[1] + S[2] + ope[2] + S[3]) == 7:
            print(S[0] + ope[0] + S[1] + ope[1] + S[2] + ope[2] + S[3] + "=7")
            break

Submission status: Accepted

Solution code:
n = list(map(int,input()))
if(n[0]+n[1]+n[2]+n[3] == 7):
    print(str(n[0])+"+"+str(n[1])+"+"+str(n[2])+"+"+str(n[3])+"=7")
elif(n[0]+n[1]+n[2]-n[3] == 7):
    print(str(n[0])+"+"+str(n[1])+"+"+str(n[2])+"-"+str(n[3])+"=7")
elif(n[0]+n[1]-n[2]+n[3] == 7):
    print(str(n[0])+"+"+str(n[1])+"-"+str(n[2])+"+"+str(n[3])+"=7")
elif(n[0]+n[1]-n[2]-n[3] == 7):
    print(str(n[0])+"+"+str(n[1])+"-"+str(n[2])+"-"+str(n[3])+"=7")
elif(n[0]-n[1]+n[2]+n[3] == 7):
    print(str(n[0])+"-"+str(n[1])+"+"+str(n[2])+"+"+str(n[3])+"=7")
elif(n[0]-n[1]+n[2]-n[3] == 7):
    print(str(n[0])+"-"+str(n[1])+"+"+str(n[2])+"-"+str(n[3])+"=7")
elif(n[0]-n[1]-n[2]+n[3] == 7):
    print(str(n[0])+"-"+str(n[1])+"-"+str(n[2])+"+"+str(n[3])+"=7")
elif(n[0]-n[1]-n[2]-n[3] == 7):
    print(str(n[0])+"-"+str(n[1])+"-"+str(n[2])+"-"+str(n[3])+"=7")

Submission status: Accepted

Solution code:
ABCD = input()
A = int(ABCD[0])
B = int(ABCD[1])
C = int(ABCD[2])
D = int(ABCD[3])
pattern = [[1,1,1],[1,1,-1],[1,-1,1],[1,-1,-1],[-1,1,1],[-1,1,-1],[-1,-1,1],[-1,-1,-1]]
ans = []
for i in pattern:
    if A + B*i[0] + C*i[1] + D*i[2] == 7:
        for j in range(3):
            if i[j] == 1:
                ans.append("+")
            else:
                ans.append("-")
        print(str(A)+ans[0]+str(B)+ans[1]+str(C)+ans[2]+str(D)+"=7")
        exit()

Submission status: Accepted

Solution code:
s = input()
t = ["+", "-"]

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

Submission status: Accepted

Solution code:
from itertools import permutations, chain
number = input()

for v in permutations("+++---", 3):
    string = "".join(chain(*zip(number, v))) + number[-1]
    if eval(string) == 7:
        print("{}=7".format(string))
        break