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:
x=int(input())
dig=[]
for i in range(1,4):
  dig.append(x%(10))
  x=x//10
dig.append(x)

d,c,b,a=dig

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:
import time
import random
import math

def dfs(i, s):
    if (i == 4):
        if (eval(s) == 7): return s
        else: return ""
    
    b = dfs(i + 1, s + "+" + str(a[i]))
    c = dfs(i + 1, s + "-" + str(a[i]))
    if (b != ""): return b
    else: return c

a = input()
print(dfs(1, str(a[0])) + "=7")

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


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

Submission status: Accepted

Solution code:
num = raw_input()
numarray = list(num)
A = int(numarray[0])
B = int(numarray[1])
C = int(numarray[2])
D = int(numarray[3])
for i in range(2):
    for j in range(2):
        for k in range(2):
            ans = 0
            if i == 0:
                ans += A - B
                if j == 0:
                    ans -= C
                    if k == 0:
                        ans -= D
                    else:
                        ans += D
                else:
                    ans += C
                    if k == 0:
                        ans -= D
                    else:
                        ans += D
            else:
                ans += A + B
                if j == 0:
                    ans -= C
                    if k == 0:
                        ans -= D
                    else:
                        ans += D
                else:
                    ans += C
                    if k == 0:
                        ans -= D
                    else:
                        ans += D
            if ans == 7:
                if i == 0:
                    Si = "-"
                else:
                    Si = "+"
                if j == 0:
                    Sj = "-"
                else:
                    Sj = "+"
                if k == 0:
                    Sk = "-"
                else:
                    Sk = "+"
                print str(A) + Si +str(B) + Sj + str(C) + Sk + str(D) + "=7"
                break
        if ans == 7:
            break
    if ans == 7:
            break

Submission status: Accepted

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

import itertools

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

# 重複順列でオペランド組み合わせの全パターンを出す
op_list = list(itertools.product(["+", "-"], repeat=3))

for op in op_list:
    # evalで文字列を式にできる(これが出なかった…)
    if eval(A + op[0] + B + op[1] + C + op[2] + D) == 7:
        print(A + op[0] + B + op[1] + C + op[2] + D + "=7")
        exit()

Submission status: Accepted

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

num_list = list(input())

if int(num_list[0]) + int(num_list[1]) + int(num_list[2]) + int(num_list[3]) == 7:
    print(num_list[0] + "+" + num_list[1] + "+" \
            + num_list[2] + "+" + num_list[3] + "=7")
elif int(num_list[0]) + int(num_list[1]) + int(num_list[2]) - int(num_list[3]) == 7:
    print(num_list[0] + "+" + num_list[1] + "+" \
            + num_list[2] + "-" + num_list[3] + "=7")
elif int(num_list[0]) + int(num_list[1]) - int(num_list[2]) + int(num_list[3]) == 7:
    print(num_list[0] + "+" + num_list[1] + "-" \
            + num_list[2] + "+" + num_list[3] + "=7")
elif int(num_list[0]) + int(num_list[1]) - int(num_list[2]) - int(num_list[3]) == 7:
    print(num_list[0] + "+" + num_list[1] + "-" \
            + num_list[2] + "-" + num_list[3] + "=7")
elif int(num_list[0]) - int(num_list[1]) + int(num_list[2]) + int(num_list[3]) == 7:
    print(num_list[0] + "-" + num_list[1] + "+" \
            + num_list[2] + "+" + num_list[3] + "=7")
elif int(num_list[0]) - int(num_list[1]) + int(num_list[2]) - int(num_list[3]) == 7:
    print(num_list[0] + "-" + num_list[1] + "+" \
            + num_list[2] + "-" + num_list[3] + "=7")
elif int(num_list[0]) - int(num_list[1]) - int(num_list[2]) + int(num_list[3]) == 7:
    print(num_list[0] + "-" + num_list[1] + "-" \
            + num_list[2] + "+" + num_list[3] + "=7")
elif int(num_list[0]) - int(num_list[1]) - int(num_list[2]) - int(num_list[3]) == 7:
    print(num_list[0] + "-" + num_list[1] + "-" \
            + num_list[2] + "-" + num_list[3] + "=7")

Submission status: Accepted

Solution code:
from itertools import product
A,B,C,D=input().strip()
ops="+-"
for op1,op2,op3 in product(ops,ops,ops):
    if eval(A+op1+B+op2+C+op3+D)==7:
        break
print(A+op1+B+op2+C+op3+D+'=7')

Submission status: Accepted

Solution code:
from itertools import product

s = input()
s2 = '{}'.join(s)

opss = product('+-', repeat=3)
lhss = (s2.format(*ops) for ops in opss)
eqs = (lhs+'=7' for lhs in lhss if eval(lhs)==7)
print(next(eqs))

Submission status: Accepted

Solution code:
import itertools

s = input()

for ops in itertools.product('+-', repeat=3):
    stmt = ''.join([s[0]] + [ops[i] + s[i+1] for i in range(3)])
    if eval(stmt) == 7:
        print(stmt+'=7')
        exit()

Submission status: Accepted

Solution code:
abcd = input()
ans = 0
ok = False
for i in range(2 ** 3):
	if not ok:
		p = "0" * (3 - len(bin(i)[2:])) + bin(i)[2:]
		equals = ""
		for index, num in enumerate(abcd):
			equals += num
			if index != (len(abcd) - 1) and p[index] == "1":
				equals += "+"
			if index != (len(abcd) - 1) and p[index] == "0":
				equals += "-"
		if eval(equals) == 7:
			ok = True
			print(equals + "=7")

Submission status: Accepted

Solution code:
s = input()

op = ['+','-']
for i in range(2):
    for j in range(2):
        for k in range(2):
            e = s[0] + op[i] + s[1] + op[j] + s[2] + op[k] + s[3]
            if eval(e) == 7:
                print(e + '=7')
                exit()

Submission status: Accepted

Solution code:
arr = map(int,list(raw_input()))

printed = False

def comb(strs,sums,i):
		global printed
		if i == 3 and sums == 7 and not printed: 
			print str(arr[0]) + strs[0] + str(arr[1]) + strs[1] + str(arr[2]) + strs[2] + str(arr[3]) + "=7"
			printed = True

		elif i < 3:
			comb(strs+'+',sums+arr[i+1],i+1)
			comb(strs+'-',sums-arr[i+1],i+1)



comb('',arr[0],0)

Submission status: Accepted

Solution code:
A,B,C,D = map(int,[num for num in input()])

if A+B+C+D == 7:
    print("%s+%s+%s+%s=7" %(A,B,C,D))
elif A-B+C+D == 7:
    print("%s-%s+%s+%s=7" %(A,B,C,D))
elif A+B-C+D == 7:
    print("%s+%s-%s+%s=7" %(A,B,C,D))
elif A+B+C-D == 7:
    print("%s+%s+%s-%s=7" %(A,B,C,D))
elif A-B-C+D == 7:
    print("%s-%s-%s+%s=7" %(A,B,C,D))
elif A-B+C-D == 7:
    print("%s-%s+%s-%s=7" %(A,B,C,D))
elif A+B-C-D == 7:
    print("%s+%s-%s-%s=7" %(A,B,C,D))
elif A-B-C-D == 7:
    print("%s-%s-%s-%s=7" %(A,B,C,D))
else:
    print("No solution found.")

Submission status: Accepted

Solution code:
import numpy
import re
import math

def main():
	"""
	テストコード実行
	:return:
	"""
	"""
	ビットマスクを用いた解法
	"""
	abcd = input()
	ans = 0
	for i in range(2 ** (len(abcd) - 1)):
		p = "0" * (len(abcd) - 1 - len(bin(i)[2:])) + bin(i)[2:]
		equals = ""
		for index, num in enumerate(abcd):
			equals += num
			if index != (len(abcd) - 1) and p[index] == "1": equals += "+"
			if index != (len(abcd) - 1) and p[index] == "0": equals += "-"
		if eval(equals) == 7:
			print(equals + "=7")
			exit()

if __name__ == '__main__':
	main()

Submission status: Accepted

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

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

fs = [add, sub]

for i in range(2):
    for j in range(2):
        for k in range(2):
            if fs[k](fs[j](fs[i](A, B), C), D) == 7:
                print(A, '+' if i == 0 else '-',
                      B, '+' if j == 0 else '-',
                      C, '+' if k == 0 else '-',
                      D, '=7', sep='')
                exit()

Submission status: Accepted

Solution code:
Nums = list(map(int, input()[:]))
op = ['+', '-']
for i in range(2):
    for j in range(2):
        for k in range(2):
            if Nums[0] + Nums[1] * (-1) ** i\
                    + Nums[2] * (-1) ** j + Nums[3] * (-1) ** k == 7:
                print('%d%s%d%s%d%s%d=7' % (Nums[0], op[i], Nums[1], op[j], Nums[2], op[k], Nums[3]))
                exit()

Submission status: Accepted

Solution code:
import sys
N = int(input())
a = int(N//1000)
N = N-1000*a
b = int(N//100)
N = N-100*b
c = int(N//10)
N = N-10*c
d = int(N)
if a+b+c+d == 7:
  print(str(a)+'+'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
  sys.exit()
if a+b+c-d == 7:
  print(str(a)+'+'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
  sys.exit()
if a+b-c+d == 7:
  print(str(a)+'+'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
  sys.exit()
if a-b+c+d == 7:
  print(str(a)+'-'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
  sys.exit()
if a+b-c-d == 7:
  print(str(a)+'+'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
  sys.exit()
if a-b+c-d == 7:
  print(str(a)+'-'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
  sys.exit()
if a-b-c+d == 7:
  print(str(a)+'-'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
  sys.exit()
if a-b-c-d == 7:
  print(str(a)+'-'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
  sys.exit()

Submission status: Accepted

Solution code:
X = input()
a = int(X[0])
b = int(X[1])
c = int(X[2])
d = int(X[3])
end = 0
res = a
L = ['+', '-']

for i in L:
    if end == 1:
        break
    for j in L:
        if end == 1:
            break
      
        for k in L:
            res = a
            if i == '+':
                res += b
            else:
                res -= b
            
            if j == '+':
                res += c 
            else:
                res -= c
                
            if k == '+':
                res += d
            else:
                res -= d
            
            if res == 7:
                end = 1
                print(str(a) + i + str(b) + j + str(c) +  str(k) + str(d) + '=7')
                break

Submission status: Accepted

Solution code:
import numpy
import re
import math

def main():
	"""
	テストコード実行
	:return:
	"""
	"""
	DP: 動的計画法を用いる
	"""
	a, b, c, d = list(input())
	sign = "+-"
	for i in range(2): #1つ目の記号
		for j in range(2): #2つ目の記号
			for k in range(2): #3つ目の記号
				if eval(a + sign[i] + b + sign[j] + c + sign[k] + d) == 7:
					print(str(a + sign[i] + b + sign[j] + c + sign[k] + d) +"=7")
					exit()

if __name__ == '__main__':
	main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,C,D = input()
op = '+----'
for i in range(8):
    s = A + op[i&4] + B + op[i&2] + C + op[i&1] + D
    if eval(s) == 7:
        print(s + '=7')
        break

Submission status: Accepted

Solution code:
from itertools import product
A, B, C, D = map(int, list(input()))
patterns = list(product(("+", "-"), ("+", "-"), ("+", "-")))
for pattern in patterns:
    temp = str(A) + pattern[0] + str(B) + \
        pattern[1] + str(C) + pattern[2] + str(D)
    if eval(temp) == 7:
        print(temp + "=7")
        break

Submission status: Accepted

Solution code:
from itertools import product
A, B, C, D = map(int, list(input()))
patterns = list(product(("+", "-"), ("+", "-"), ("+", "-")))
for pattern in patterns:
    if pattern[0] == "+":
        temp = A + B
    else:
        temp = A - B
    if pattern[1] == "+":
        temp = temp + C
    else:
        temp = temp - C
    if pattern[2] == "+":
        temp = temp + D
    else:
        temp = temp - D
    if temp == 7:
        print(str(A) + pattern[0] + str(B) +
              pattern[1] + str(C) + pattern[2] + str(D) + "=7")
        break

Submission status: Accepted

Solution code:
N=input()

for i in range(2):
    for j in range(2):
        for k in range(2):
            if int(N[0])+(-1)**i*int(N[1])+(-1)**j*int(N[2])+(-1)**k*int(N[3])==7:
                X=str(i)+str(j)+str(k)

Z=X.replace("0","+")
Z=Z.replace("1","-")

print(N[0]+Z[0]+N[1]+Z[1]+N[2]+Z[2]+N[3]+"=7")

Submission status: Accepted

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

a, b, c, d = list(input())
a = int(a)
b = int(b)
c = int(c)
d = int(d)
if a + b + c + d == 7:
    print('{0}+{1}+{2}+{3}=7'.format(a, b, c, d))
elif a + b + c - d == 7:
    print('{0}+{1}+{2}-{3}=7'.format(a, b, c, d))
elif a + b - c + d == 7:
    print('{0}+{1}-{2}+{3}=7'.format(a, b, c, d))
elif a + b - c - d == 7:
    print('{0}+{1}-{2}-{3}=7'.format(a, b, c, d))
elif a - b + c + d == 7:
    print('{0}-{1}+{2}+{3}=7'.format(a, b, c, d))
elif a - b + c - d == 7:
    print('{0}-{1}+{2}-{3}=7'.format(a, b, c, d))
elif a - b - c + d == 7:
    print('{0}-{1}-{2}+{3}=7'.format(a, b, c, d))
elif a - b - c - d == 7:
    print('{0}-{1}-{2}-{3}=7'.format(a, b, c, d))

Submission status: Accepted

Solution code:
# input
L = [int(x) for x in list(input())]
ans = 0

if L[0] + L[1] + L[2] + L[3] == 7:
    print("%d+%d+%d+%d=7" % (L[0], L[1], L[2], L[3]))
else:
    if L[0] - L[1] + L[2] + L[3] == 7:
        print("%d-%d+%d+%d=7" % (L[0], L[1], L[2], L[3]))
    else:
        if L[0] + L[1] - L[2] + L[3] == 7:
            print("%d+%d-%d+%d=7" % (L[0], L[1], L[2], L[3]))
        else:
            if L[0] + L[1] + L[2] - L[3] == 7:
                print("%d+%d+%d-%d=7" % (L[0], L[1], L[2], L[3]))
            else:
                if L[0] - L[1] - L[2] + L[3] == 7:
                    print("%d-%d-%d+%d=7" % (L[0], L[1], L[2], L[3]))
                else:
                    if L[0] - L[1] + L[2] - L[3] == 7:
                        print("%d-%d+%d-%d=7" % (L[0], L[1], L[2], L[3]))
                    else:
                        if L[0] + L[1] - L[2] - L[3] == 7:
                            print("%d+%d-%d-%d=7" % (L[0], L[1], L[2], L[3]))
                        else:
                            if L[0] - L[1] - L[2] - L[3] == 7:
                                print("%d-%d-%d-%d=7" % (L[0], L[1], L[2], L[3]))

Submission status: Accepted

Solution code:

A, B, C, D = map(int,list(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, b, c, d = [int(x) for x in input()]

for i in ['-1', '+1']:
    for j in ['-1', '+1']:
        for k in ['-1', '+1']:
            if a + int(i)*b + int(j)*c + int(k)*d == 7:
                print(str(a) + i[0] + str(b) + j[0] + str(c) + k[0] + str(d) + '=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])

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

Submission status: Accepted

Solution code:
N = list(input())
A = int(N[0])
B = int(N[1])
C = int(N[2])
D = int(N[3])
def op(x):
    if x == 0:
        return '+'
    if x ==1:
        return '-'

for i in range(2):
    for j in range(2):
        for k in range(2):
            if A+B*(-1)**i+C*(-1)**j+D*(-1)**k == 7:
                print(str(A)+op(i)+str(B)+op(j)+str(C)+op(k)+str(D)+'=7')
                exit()

Submission status: Accepted

Solution code:
N=input()

a=int(N[0:1])
b=int(N[1:2])
c=int(N[2:3])
d=int(N[3:4])
if a+b+c+d==7:
    print(str(a)+"+"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
    exit()
if a-b+c+d==7:
    print(str(a)+"-"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
    exit()
if a+b-c+d==7:
    print(str(a)+"+"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
    exit()
if a+b+c-d==7:
    print(str(a)+"+"+str(b)+"+"+str(c)+"-"+str(d)+"=7")
    exit()
if a-b-c+d==7:
    print(str(a)+"-"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
    exit()
if a-b+c-d==7:
    print(str(a)+"-"+str(b)+"+"+str(c)+"-"+str(d)+"=7")
    exit()
if a+b-c-d==7:
    print(str(a)+"+"+str(b)+"-"+str(c)+"-"+str(d)+"=7")
    exit()
if a-b-c-d==7:
    print(str(a)+"-"+str(b)+"-"+str(c)+"-"+str(d)+"=7")
    exit()

Submission status: Accepted

Solution code:
ABCD = input()

for i in range(1 << 3):
    total = int(ABCD[0])
    equation = ABCD[0]
    for j in range(3):
        if i & (1 << j):
            total += int(ABCD[j+1])
            equation += "+"
        else:
            total -= int(ABCD[j+1])
            equation += "-"    
        equation += ABCD[j+1]
    if total == 7:
        equation += "=7"
        print(equation)
        break

Submission status: Accepted

Solution code:
input_tuple = tuple(map(int,list(input())))

n = 3
c_list = [list(map(int,format(i,"b").zfill(n))) for i in range(2**n)]

for i in c_list:
    input_list = list(input_tuple)
    for j, v in enumerate(i):
        if v == 1:
            input_list[j+1] = input_list[j+1] * -1
    if sum(input_list) == 7:
        break
ans = [str(input_list[0])]
for j in range(3):
    if i[j] == 0:
        ans.append("+")
    ans.append(str(input_list[j+1]))
else:
    ans.append("=7")

print("".join(ans))

Submission status: Accepted

Solution code:
abcd = str(input())

for i in range(1<<3):
    temp = int(abcd[0])
    ans = '{}'.format(abcd[0])

    for j in range(1, 4):
        if i >> (j-1) & 1:
            temp += int(abcd[j])
            ans += '+{}'.format(abcd[j])
        else:
            temp -= int(abcd[j])
            ans += '-{}'.format(abcd[j])
    if temp ==7:
        print(ans + "=7")
        break

Submission status: Accepted

Solution code:
*n, = map(int, list(input()))

def op(x):
    ops = []
    for i in range(3):
        ops.append(x%2)
        x//=2
    return ops

for x in range(2**3):
    ops = op(x)
    y = n[0]
    for i in range(1,4):
        y += n[i]*(1 if ops[i-1]==1 else -1)
    if y == 7:
        break

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

Submission status: Accepted

Solution code:
raw = input()
nums = [] * 4
for i in range(0, 4):
    nums.append(int(raw[i]))

# op = ['+', '-']
# ops = [op] * 3
# print(ops)

for i in range(0, 8):
    sum = nums[0]
    result = str(nums[0])
    for op in range(0,3):
        if (i >> op) & 1:
            sum += nums[op + 1]
            result += '+'
        else:
            sum -= nums[op + 1]
            result += '-'
        result += str(nums[op + 1])

    if sum == 7:
        result += '=7'
        print(result)
        break

Submission status: Accepted

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

if A+B+C+D == 7: print("{0}+{1}+{2}+{3}=7".format(A,B,C,D))
elif A-B+C+D == 7: print("{0}-{1}+{2}+{3}=7".format(A,B,C,D))
elif A-B-C+D == 7: print("{0}-{1}-{2}+{3}=7".format(A,B,C,D))
elif A-B-C-D == 7: print("{0}-{1}-{2}-{3}=7".format(A,B,C,D))
elif A+B-C+D == 7: print("{0}+{1}-{2}+{3}=7".format(A,B,C,D))
elif A+B+C-D == 7: print("{0}+{1}+{2}-{3}=7".format(A,B,C,D))
elif A+B-C-D == 7: print("{0}+{1}-{2}-{3}=7".format(A,B,C,D))
elif A-B+C-D == 7: print("{0}-{1}+{2}-{3}=7".format(A,B,C,D))

Submission status: Accepted

Solution code:
S = input()
a=int(S[0])
b=int(S[1])
c=int(S[2])
d=int(S[3])
op1=[]
op2=[]
op3=[]
func=(('+',lambda x,y:x+y),('-',lambda x,y:x-y))
for f1 in func:
    op1.append((f1[1](a,b),f1[0]))
for o in op1:
    for f2 in func:
        op2.append((f2[1](o[0],c),o[1]+f2[0]))
for o in op2:
    for f3 in func:
        op3.append((f3[1](o[0],d),o[1]+f3[0]))
for o in op3:
    if o[0] == 7:
        print(str(a)+o[1][0]+str(b)+o[1][1]+str(c)+o[1][2]+str(d)+'=7')
        break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
abcd = [int(_) for _ in list(input())]
op = [0, 1]


def cal(ops, abcd):
    if ops:
        op = ops.pop(0)
        _ = abcd.pop(0)
        if op:
            abcd[0] = _ + abcd[0]
            return cal(ops, abcd)
        else:
            abcd[0] = _ - abcd[0]
            return cal(ops, abcd)
    else:
        return abcd[0]


for op1 in op:
    for op2 in op:
        for op3 in op:
            _ = abcd[:]
            __ = [op1, op2, op3]
            if cal(__, _) == 7:
                ops = [op1, op2, op3]

abcd = [str(_) for _ in abcd]
ops = ['+' if op else '-' for op in ops]
tmp = [abcd[i] + _ for i, _ in enumerate(ops)]
tmp.append(abcd[-1])
print(''.join(tmp) + '=7')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X = input()
A = int(X[0])
B = int(X[1])
C = int(X[2])
D = int(X[3])
kai = 0
for i in range(2):
  if kai == 7 : break
  for j in range(2):
    if kai == 7 : break
    for k in range(2):
      if kai == 7 : break
      for h in range(2):
        kai = A + B * ((-1) ** j)  + C * ((-1) ** k) + D * ((-1) ** h)
        if kai == 7:
          if i == 1:
            i = "-"
          else:
            i = "+"
          if j == 1:
            j = "-"
          else:
            j = "+"
          if k == 1:
            k = "-"
          else:
            k = "+"
          if h == 1:
            h = "-"
          else:
            h = "+"
          ans = str(A) + j + str(B) + k + str(C) + h + str(D) +  "=7"
          break
print(ans)

Submission status: Accepted

Solution code:
_ = input()#"3242"
a,b,c,d = [int(_[i]) for i in range(4)]
e = [-1,1]
def f(s):
    if s == 1:
        print("+",end="")
    else:
        print("-",end="")
for i in e:
    for j in e:
        for k in e:
            if a + i*b + j*c + k*d == 7:
                print(a,sep="",end="")
                f(i)
                print(b,end="")
                f(j)
                print(c,end="")
                f(k)
                print(d,"=7",sep="")
                exit()

Submission status: Accepted

Solution code:
n = input()
ns = [int(i) for i in n]
for i in range(-1,2,2):
    for j in range(-1,2,2):
        for k in range(-1,2,2):
            if(ns[0]+i*ns[1]+j*ns[2]+k*ns[3]==7):
                ans = str(ns[0])
                if(i == -1):
                    ans += '-'
                else:
                    ans += '+'
                ans += str(ns[1])
                if(j == -1):
                    ans += '-'
                else:
                    ans += '+'
                ans += str(ns[2])
                if(k == -1):
                    ans += '-'
                else:
                    ans += '+'
                ans += str(ns[3])
                print(ans + '=7')
                exit()

Submission status: Accepted

Solution code:
num=list(map(int,list(input())))
op=[1,-1]
def ope(x):
    if x==1:
        return "+"
    else:
        return "-"

for k in op:
    for j in op:
        for i in op:
            if num[0]+num[1]*k+num[2]*j+num[3]*i==7:
                print("{0}{1}{2}{3}{4}{5}{6}=7".format(num[0],ope(k),num[1],ope(j),num[2],ope(i),num[3]))
                exit()

Submission status: Accepted

Solution code:
ABCD = input()
for i in range(8):
    tmp = bin(i)[2:].zfill(3)
    tmp_num = int(ABCD[0])
    result = ABCD[0]
    for op in range(3):
        if tmp[op] == '1':
            tmp_num += int(ABCD[op+1])
            result = result + '+' + ABCD[op+1]
        else:
            tmp_num -= int(ABCD[op+1])
            result = result + '-' + ABCD[op+1]
    if tmp_num == 7:
        break
print(result+'=7')

Submission status: Accepted

Solution code:
import itertools
A, B, C, D = list(input())
ops = itertools.product('+-', repeat=3)
res = ''
for op1, op2, op3 in ops:
    if eval(A+op1+B+op2+C+op3+D) == 7:
        res = A+op1+B+op2+C+op3+D
if res:
    print(res+'=7')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys
s=input()
for op1 in '+-':
  for op2 in '+-':
    for op3 in '+-':
      if eval(s[0]+op1+s[1]+op2+s[2]+op3+s[3]) == 7:
        print(s[0]+op1+s[1]+op2+s[2]+op3+s[3]+'=7')
        sys.exit(0)

Submission status: Accepted

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

for i in range(0, 8):
	op1 = i / 4
	op2 = (i%4) / 2
	op3 = i % 2
	if a + (1-2*op1)*b + (1-2*op2)*c + (1-2*op3)*d == 7:
		print str(a) + op[op1] + str(b) + op[op2] + str(c) + op[op3] + str(d) + '=7'
		break

Submission status: Accepted

Solution code:
N=input()
if int(N[0])+int(N[1])+int(N[2])+int(N[3])==7:
    print (N[0]+'+'+N[1]+'+'+N[2]+'+'+N[3]+'=7')
elif int(N[0])+int(N[1])+int(N[2])-int(N[3])==7:
    print (N[0]+'+'+N[1]+'+'+N[2]+'-'+N[3]+'=7')
elif int(N[0])+int(N[1])-int(N[2])+int(N[3])==7:
    print (N[0]+'+'+N[1]+'-'+N[2]+'+'+N[3]+'=7')
elif int(N[0])+int(N[1])-int(N[2])-int(N[3])==7:
    print (N[0]+'+'+N[1]+'-'+N[2]+'-'+N[3]+'=7')
elif int(N[0])-int(N[1])+int(N[2])+int(N[3])==7:
    print (N[0]+'-'+N[1]+'+'+N[2]+'+'+N[3]+'=7')
elif int(N[0])-int(N[1])+int(N[2])-int(N[3])==7:
    print (N[0]+'-'+N[1]+'+'+N[2]+'-'+N[3]+'=7')
elif int(N[0])-int(N[1])-int(N[2])+int(N[3])==7:
    print (N[0]+'-'+N[1]+'-'+N[2]+'+'+N[3]+'=7')
elif int(N[0])-int(N[1])-int(N[2])-int(N[3])==7:
    print (N[0]+'-'+N[1]+'-'+N[2]+'-'+N[3]+'=7')

Submission status: Accepted

Solution code:
s = input()
ops = ['+', '-']
post = '=7'
for a in ops:
    for b in ops:
        for c in ops:
            now = s[0] + a + s[1] + b + s[2] + c + s[3]
            if eval(now) == 7:
                ans = now + post
                break
print(ans)

Submission status: Accepted

Solution code:
def op(a, op, b):
    if op == "+":
        return a+b
    else:
        return a-b

def main():
    n = input()
    A,B,C,D = map(int, [n[0],n[1],n[2],n[3]])

    for op1 in ["+","-"]:
        for op2 in ["+","-"]:
            for op3 in ["+","-"]:
                ans = op(A, op1, B)
                ans = op(ans, op2, C)
                ans = op(ans, op3, D)
                if ans == 7:
                    return str(A)+op1+str(B)+op2+str(C)+op3+str(D)+"=7"



print(main())

Submission status: Accepted

Solution code:
from itertools import product
N=list(input())
for i in range(4):
    N[i]=int(N[i])



for op1, op2, op3 in product([1,-1],[1,-1],[1,-1]):
    if N[0] + N[1]*op1 + N[2]*op2 + N[3]*op3 == 7:
        print("{}{}{}{}{}{}{}=7".format(
            N[0],"+" if op1==1 else "-",
            N[1],"+" if op2==1 else "-",
            N[2],"+" if op3==1 else "-",
            N[3]))
        break

Submission status: Accepted

Solution code:
nums = list(input())
comb = []
def f(now):
  if len(now) == 3:
    comb.append(now)
    return
  
  f(now+['+'])
  f(now+['-'])

f([])

for op in comb:
  temp = nums[0]

  for j in range(len(op)):
    temp = temp + op[j] + nums[j+1]

  if eval(temp) == 7:
    print('{}{}{}'.format(temp, '=', '7'))
    break

Submission status: Accepted

Solution code:
I = input()
S = list(I)
temp = []
for i in range(8):
    for j in range(3):
        if i & 2**j > 0:
            temp.append(S[j] + "+")
        else:
            temp.append(S[j] + "-")
    temp.append(S[len(S)-1])
    temp = "".join(temp)
    if eval(temp) == 7:
        temp = temp + "=7"
        break
    temp = []

print(temp)

Submission status: Accepted

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


for mask in range(1<<3):
	val = a
	if 1 & (mask >> 0):
		val += b
	else:
		val -= b

	if 1 & (mask >> 1):
		val += c
	else:
		val -= c
	
	if 1 & (mask >> 2):
		val += d
	else:
		val -= d

	if val == 7:
		if 1 & (mask>>0):
			op1 = "+"
		else:
			op1 = "-"
		if 1 & (mask>>1):
			op2 = "+"
		else:
			op2 = "-"
		if 1 & (mask>>2):
			op3 = "+"
		else:
			op3 = "-"
		print(str(a)+op1+str(b)+op2+str(c)+op3+str(d)+"=7")
		exit(0)