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


def op(n):
    if n == 0:
        return '+'
    else:
        return '-'

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

Submission status: Accepted

Solution code:
import sys
pm = ["+", "-"]
# table1 = [0007,0016,0025,0034,0043,0052,0061,0070,0106,0115,0124,0133,0142,0151,0160,
# 0205,0214,0223,0232,0241,0250,0304,0313,0322,0331,0340,0403,0412,0421,0430,0502,
# 0511,0520,0601,0610,0700,1006,1015,1024,1033,1042,1051,1060,1105,1114,1123,1132,1141,1150,1204,1213,
# 1222,1231,1240,1303,1312,1321,1330,1402,1411,1420,1501,1510,1600,2005,2014,2023,
# 2032,2041,2050,2104,2113,2122,2131,2140,2203,2212,2221,2230,2302,2311,2320,2401,
# 2410,2500,3004,3013,3022,3031,3040,3103,3112,3121,3130,3202,3211,3220,3301,3310,
# 3400,4003,4012,4021,4030,4102,4111,4120,4201,4210,4300,5002,5011,5020,5101,5110,
# 5200,6001,6010,6100,7000]
ABCD = str(input())
for s0 in pm:
    for s1 in pm:
        for s2 in pm:
            if(eval(ABCD[0] + s0 + ABCD[1] + s1 + ABCD[2] + s2 + ABCD[3] ) == 7):
                print(ABCD[0] + s0 + ABCD[1] + s1 + ABCD[2] + s2 + ABCD[3] + "=7")
                sys.exit()

Submission status: Accepted

Solution code:
D = input()

ops = []
for i in range(1 << 3):
    op = ""
    xx = bin(i)[2::].zfill(3)
    for x in xx:
        if x=="0":
            op += "+"
        else:
            op += "-"
    ops.append(op)

for op in ops:
    res = D[0]
    for i in range(3):
        res += op[i]+D[i+1]
    if eval(res)==7:
        print(res + "=7")
        break

Submission status: Accepted

Solution code:
def solve():
    a, b, c, d = input()
    for bit in range(2 ** 3):
        o1, o2, o3 = ['+' if bit & (1 << i) == 0 else '-' for i in range(3)]
        stmt = ''.join([a,o1,b,o2,c,o3,d])
        if eval(stmt) == 7:
            return stmt + "=7"

print(solve())

Submission status: Accepted

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

#デカルト積
OP = list(itertools.product(op,repeat = 3))
def can_seven(li,op):
    m = len(op)
    n = len(op[0])
    for j in range(m):
        res = li[0]
        for i in range(n):
            if op[j][i] == "+": res += li[i+1]
            else: res -= li[i+1]
        if res == 7:
            return ("{0}"+op[j][0]+"{1}"+op[j][1]+"{2}"+op[j][2]+"{3}=7").format(li[0],li[1],li[2],li[3])
    return "Fail"

print(can_seven(ABCD,OP))

Submission status: Accepted

Solution code:
from itertools import product
number = list(input())

for c in product(range(2),repeat=3):
    formula = number[0]
    for i in range(3):
        if c[i] == 1:
            formula += '+' + number[i+1]
            
        else:
            formula += '-' + number[i+1]
    if eval(formula) == 7:
        print(formula + '=7')
        break

Submission status: Accepted

Solution code:
a, b, c, d = input()
for i in ['+', '-']:
    for j in ['+', '-']:
        for k in ['+', '-']:
            s = a + i + b + j + c + k + d
            if eval(s) == 7:
                print(s + '=7')
                exit()

Submission status: Accepted

Solution code:
s = list(map(int,list(input())))
check = [[0 for i in range(3)] for j in range(1 << 3)]

for i in range(1 << 3):

    for j in range(3):
        if ((i >> j) & 1) == 1:
            check[i][j] = '+'
        else:
            check[i][j] = '-'

for i in check:
    sum = s[0]
    ans = str(s[0])
    for j in range(3):
        if i[j] == '+':
            sum += s[j+1]
            ans += '+'+str(s[j+1])
        else:
            sum -= s[j+1]
            ans += '-'+str(s[j+1])

    if sum == 7:
        print(ans + '=7')
        exit()

Submission status: Accepted

Solution code:
a=input()
x,y,z,b=int(a[0]),int(a[1]),int(a[2]),int(a[3])
if x+y+z+b==7:
    print("{}+{}+{}+{}=7".format(x,y,z,b))
elif x-y-z-b==7:
    print("{}-{}-{}-{}=7".format(x,y,z,b))
elif x+y+z-b==7:
    print("{}+{}+{}-{}=7".format(x,y,z,b))
elif x+y-z+b==7:
    print("{}+{}-{}+{}=7".format(x,y,z,b))
elif x-y+z+b==7:
    print("{}-{}+{}+{}=7".format(x,y,z,b))
elif x+y-z-b==7:
    print("{}+{}-{}-{}=7".format(x,y,z,b))
elif x-y-z+b==7:
    print("{}-{}-{}+{}=7".format(x,y,z,b))
else:
    print("{}-{}+{}-{}=7".format(x,y,z,b))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
abcd = input()
ans=''
for i in range(8):
    op1 = '+' if (1 & i) != 0 else '-'
    op2 = '+' if (2 & i) != 0 else '-'
    op3 = '+' if (4 & i) != 0 else '-'
    s = abcd[0] + op1 + abcd[1] + op2 + abcd[2] + op3 + abcd[3]
    if eval(s) == 7: ans = s + '=7'
print(ans)

Submission status: Accepted

Solution code:
from itertools import product

S = input()
op = list(product(["+","-"],repeat=3))

for i in range(len(op)) :
    calc = S[0]+op[i][0]+S[1]+op[i][1]+S[2]+op[i][2]+S[3]
    if eval(calc) == 7 :
        print(calc+"=7")
        break

Submission status: Accepted

Solution code:
abcd = input()

a = abcd[0]
b = abcd[1]
c = abcd[2]
d = abcd[3]

for i in range(2**(4-1)):
    f = "{a}".format(a=a)
    if i>>0 & 1 == 1:
        f += "+{b}".format(b=b)
    else:
        f += "-{b}".format(b=b)
    
    if i>>1 & 1 == 1:
        f += "+{c}".format(c=c)
    else:
        f += "-{c}".format(c=c)

    if i>>2 & 1 == 1:
        f += "+{d}".format(d=d)
    else:
        f += "-{d}".format(d=d)

    result = eval(f)
    if result == 7:
        print(f + "=7")
        break

Submission status: Accepted

Solution code:
A = input()

for i in range(1 << len(A) - 1):
    ans_number = int(A[0])
    ans_sentense = A[0]
    for j in range(len(A) - 1):
        if ((i >> j)& 1) == 1:
            ans_number += int(A[j + 1])
            ans_sentense += "+" + A[j + 1]
        else:
            ans_number -= int(A[j + 1])
            ans_sentense += "-" + A[j + 1]
    if ans_number == 7:
        break
print(ans_sentense + "=7")

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(4):
    a.append(n%10)
    n //= 10
a.reverse()
#print(a)#
OP = [['+', '-'] for i in range(3)]
PM = ['+', '-']
OP = []
for op1 in PM:
    for op2 in PM:
        for op3 in PM:
            OP.append([op1,op2,op3])
#print(OP)#
for op in OP:
    #print(op)#
    result = a[0]
    for i in range(len(op)):
        if op[i]=='+': result += a[i+1]
        else: result -= a[i+1]
    if result==7: break
        
print(a[0],end='')
for n in range(3):
    print('%s%d' % (op[n], a[n+1]), end='')
print('=7')

Submission status: Accepted

Solution code:
a, b, c, d = list(input())
O = ['+', '-']

for op1 in O:
    for op2 in O:
        for op3 in O:
            f = a + op1 + b + op2 + c + op3 + d
            if eval(f) == 7:
                ans = f + '=7'
                break

print(ans)

Submission status: Accepted

Solution code:
A = input()

def f(x):
    if x % 2 == 0:
        return 1
    else:
        return -1

B = []
for i in range(8):
    if int(A[0]) + f(i//4) * int(A[1]) + f(i//2) * int(A[2]) + f(i) * int(A[3]) == 7:
        if f(i//4) == 1:
            B.append('+')
        else:
            B.append('-')
        if f(i//2) == 1:
            B.append('+')
        else:
            B.append('-')
        if f(i) == 1:
            B.append('+')
        else:
            B.append('-')
        flag = 1
        break
        
if flag == 1:
    print(A[0]+B[0]+A[1]+B[1]+A[2]+B[2]+A[3]+'=7')

Submission status: Accepted

Solution code:
a, b, c, d = list(input())
opt = ['+', '-']

for i in opt:
    for j in opt:
        for k in opt:
            f = a + i + b + j + c + k + d
            if eval(f) == 7:
                ans = f
                break
                
print(ans + '=7')

Submission status: Accepted

Solution code:
A = input()

def f(x):
    if x % 2 == 0:
        return 1
    else:
        return -1

B = []
for i in range(8):
    if int(A[0]) + f(i//4) * int(A[1]) + f(i//2) * int(A[2]) + f(i) * int(A[3]) == 7:
        if f(i//4) == 1:
            B.append('+')
        else:
            B.append('-')
        if f(i//2) == 1:
            B.append('+')
        else:
            B.append('-')
        if f(i) == 1:
            B.append('+')
        else:
            B.append('-')
        flag = 1
        break
        
if flag == 1:
    print('{}{}{}{}{}{}{}{}'.format(A[0], B[0], A[1], B[1], A[2], B[2], A[3], '=7'))

Submission status: Accepted

Solution code:
import itertools
S=input()
TT=itertools.product(["+","-"],repeat=3)
for T in TT:
    A=S[0]+T[0]+S[1]+T[1]+S[2]+T[2]+S[3]
    if eval(A)==7:
        print(A+"=7")
        exit()

Submission status: Accepted

Solution code:
a = input()
ar = []
for i in range(len(a)):
    ar.append(a[i])
n = len(ar)
ret = 0
for i in range(2**(n-1)):
    p = "+"
    m = "-"
    tmp = ""
    flag = -1
    ret = int(ar[0])
    for j in range(n):
        if flag == 0:
            ret += int(ar[j])
        if flag == 1:
            ret -= int(ar[j])
        if (1 & (i >> j)) == 1:
            tmp += ar[j]
            tmp += p
            flag = 0
        else:
            tmp += ar[j]
            tmp += m
            flag = 1
    tmp = tmp[:-1]
    if ret == 7:
        break
print(tmp + "=7")

Submission status: Accepted

Solution code:
import itertools
import commands
num=raw_input()
num=list(num)

a=["+","-"]

for i in itertools.product(a,a,a):
    a=commands.getoutput("echo $(("+num[0]+i[0]+num[1]+i[1]+num[2]+i[2]+num[3]+"))")
    if(a=="7"):
        print(num[0]+i[0]+num[1]+i[1]+num[2]+i[2]+num[3]+"=7")
        break

Submission status: Accepted

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

A = int(A)
B = int(B)
C = int(C)
D = int(D)

def calc(a, b, c, d, s):
  for _b in [b, -b]:
    for _c in [c, -c]:
      for _d in [d, -d]:
        if a + _b + _c + _d == s:
          return a, _b, _c, _d
  return False


print('{}{:=+}{:=+}{:=+}=7'.format(*calc(A, B, C, D, 7)))

Submission status: Accepted

Solution code:
s = str(input())
a = int(s[0])
b = int(s[1])    
c = int(s[2])
d = int(s[3])
if a+b+c+d==7:
    print('{}+{}+{}+{}=7'.format(a,b,c,d))
elif a+b+c-d==7:
    print('{}+{}+{}-{}=7'.format(a,b,c,d))
elif a+b-c+d==7:
    print('{}+{}-{}+{}=7'.format(a,b,c,d))
elif a+b-c-d==7:
    print('{}+{}-{}-{}=7'.format(a,b,c,d))
elif a-b+c+d==7:
    print('{}-{}+{}+{}=7'.format(a,b,c,d))
elif a-b+c-d==7:
    print('{}-{}+{}-{}=7'.format(a,b,c,d))
elif a-b-c+d==7:
    print('{}-{}-{}+{}=7'.format(a,b,c,d))
elif a-b-c-d==7:
    print('{}-{}-{}-{}=7'.format(a,b,c,d))

Submission status: Accepted

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

oplist = ['+', '-']

for op1 in oplist:
    for op2 in oplist:
        for op3 in oplist:
            f = A + op1 + B + op2 + C + op3 + D
            ans = eval(f)
            if ans == 7:
                print(f + "=7")
                quit()

Submission status: Accepted

Solution code:
S = input()
op = ["+","-"]
for bit in range(1 << 3) :
    L = []
    for k in range(3) :
        if bit & (1 << k) :
            L.append(op[0])
        else :
            L.append(op[1])
    f = S[0]+L[0]+S[1]+L[1]+S[2]+L[2]+S[3]
    if eval(f) == 7 :
        ans = f + "=7"
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

a = list(input())
for i in range(2):
    for j in range(2):
        for k in range(2):
            if i % 2 == 0:
                sym1 = '+'
            else:
                sym1 = '-'
            if j % 2 == 0:
                sym2 = '+'
            else:
                sym2 = '-'
            if k % 2 == 0:
                sym3 = '+'
            else:
                sym3 = '-'
            word = a[0] + sym1 + a[1] + sym2 + a[2] + sym3 + a[3]

            ans = eval(word)
            if ans == 7:
                print(word+'=7')
                sys.exit()

Submission status: Accepted

Solution code:
S = list(input())

patarn = -1

for i in range(1 << 3):
    summation = int(S[0])
    for j in range(3):
        if (i >> j) % 2 == 1:
            summation += int(S[j+1])
        else:
            summation -= int(S[j+1])
    if summation == 7:
        patarn = i

ans_equ = S[0]

for i in range(3):
    if (patarn >> i) % 2 == 1:
        ans_equ += '+' + S[i+1]
    else:
        ans_equ += '-' + S[i+1]

ans_equ += '=7'
print(ans_equ)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a  = input()
x = int(a[0])
y = int(a[1])
z = int(a[2])
w = int(a[3])
o = ["+","-"]
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 x + y + z + w == 7: p = [i,j,k]
            elif i == 0 and j == 0 and k == 1:
                if x + y + z - w == 7: p = [i,j,k]
            elif i == 0 and j == 1 and k == 0:
                if x + y - z + w == 7: p = [i,j,k]
            elif i == 1 and j == 0 and k == 0:
                if x - y + z + w == 7: p = [i,j,k]
            elif i == 1 and j == 1 and k == 0:
                if x - y - z + w == 7: p = [i,j,k]
            elif i == 0 and j == 1 and k == 1:
                if x + y - z - w == 7: p = [i,j,k]
            elif i == 1 and j == 0 and k == 1:
                if x - y + z - w == 7: p = [i,j,k]
            elif i == 1 and j == 1 and k == 1:
                if x - y - z - w == 7: p = [i,j,k]
print(str(x)+o[p[0]]+str(y)+o[p[1]]+str(z)+str(o[p[2]])+str(w)+"=7")

Submission status: Accepted

Solution code:
def func(i):
    S = format(i, "b")
    S = (3-len(S)) * "0" + S
    ret = [""] * 3
    for i in range(3):
        ret[i] = "+" if S[i] == "1" else "-"
    return ret


def calc(n, op):
    ret = int(n[0])
    for i in range(3):
        if op[i] == "+":
            ret += int(n[i+1])
        else:
            ret -= int(n[i+1])
    return ret


n = list(input())


for i in range(8):
    op = func(i)
    if calc(n, op) == 7:
        print(n[0]+op[0]+n[1]+op[1]+n[2]+op[2]+n[3]+"=7")
        break

Submission status: Accepted

Solution code:
import sys

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

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

A, B, C, D = map(int, raw_input())
for f1, c1 in ([p, '+'], [m, '-']):
    for f2, c2 in ([p, '+'], [m, '-']):
        for f3, c3 in ([p, '+'], [m, '-']):
            if f3(f2(f1(A, B), C), D) == 7:
                print "%d%s%d%s%d%s%d=7" % (A, c1, B, c2, C, c3, D)
                sys.exit()

Submission status: Accepted

Solution code:
a = list(map(int, input()))
for bs in range(8):
    sm = a[0]
    ret = str(a[0])
    for i in range(3):
        num = a[i + 1]
        if bs & 1 << i:
            sm += num
            ret += str("+")
        else:
            sm -= num
            ret += str("-")
        ret += str(num)
    if sm == 7:
        ret += "=7"
        break
print(ret)

Submission status: Accepted

Solution code:
a, b, c, d = list(map(int, input()))
flag = False
als = a + b + c + d
ret = ""
for i in range(2):
    for j in range(2):
        for k in range(2):
            if als - (2 * i * b + 2 * j * c + 2 * k * d) == 7:
                ret += str(a)
                if i:
                    ret += "-"
                else:
                    ret += "+"
                ret += str(b)
                if j:
                    ret += "-"
                else:
                    ret += "+"
                ret += str(c)
                if k:
                    ret += "-"
                else:
                    ret += "+"
                ret += str(d)
                ret += "=7"
                flag = True
                break
        if flag:
            break
    if flag:
        break
print(ret)

Submission status: Accepted

Solution code:
import itertools


S = list(input())
signs = [',+'] * 3 + [',-'] * 3
three_signs = list(itertools.permutations(signs, 3))
for i in three_signs:
    tmp = [_ for _ in S]
    for j in range(len(i)):
        tmp.insert(3-j, i[j])
    tmp = ''.join(tmp)
    tmp = tmp.split(',')
    temp = ''.join(tmp)
    tmp = map(int, tmp)
    ans = sum(tmp)
    if ans == 7:
        print(temp+'=7')
        exit()

Submission status: Accepted

Solution code:
s = input()
flag = False
ans = ""
def f(temp, index):
  global ans
  if ans:
    return
  
  if len(temp) == 7:
    if eval(temp) == 7:
      ans = temp+"=7"
    return 
  
  f(temp + "+" + s[index], index+1)
  f(temp + "-" + s[index], index+1)

f(s[0], 1)

print(ans)

Submission status: Accepted

Solution code:
s = list(map(int,list(input())))
def search(i,current,signs):
    if i == 4:
        if current == 7:
            return signs
        else: return []
    return search(i+1,current+s[i],signs+['+']) + search(i+1,current-s[i],signs+['-'])
signs = search(1,s[0],[])
for i in range(4):
    if i == 3:
        print(s[i], end='')
    else:
        print(s[i], end='')
        print(signs[i], end='')
print('=7')

Submission status: Accepted

Solution code:
A = input()
a,b,c,d = A[0],A[1],A[2],A[3]
e1 = a+'+'+b+'+'+c+'+'+d
e2 = a+'+'+b+'+'+c+'-'+d
e3 = a+'+'+b+'-'+c+'+'+d
e4 = a+'+'+b+'-'+c+'-'+d
e5 = a+'-'+b+'+'+c+'+'+d
e6 = a+'-'+b+'+'+c+'-'+d
e7 = a+'-'+b+'-'+c+'+'+d
e8 = a+'-'+b+'+'+c+'-'+d
if eval(e1) == 7:
    print(e1+'=7')
elif eval(e2) == 7:
    print(e2+'=7')
elif eval(e3) == 7:
    print(e3+'=7')
elif eval(e4) == 7:
    print(e4+'=7')
elif eval(e5) == 7:
    print(e5+'=7')
elif eval(e6) == 7:
    print(e6+'=7')
elif eval(e7) == 7:
    print(e7+'=7')
elif eval(e8) == 7:
    print(e8+'=7')

Submission status: Accepted

Solution code:
ops = ["+", "-"]

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

def solve(a, b, c, d):
    for op1 in ops:
        for op2 in ops:
            for op3 in ops:
                if calc(op3, calc(op2, calc(op1, a, b), c), d) == 7:
                    print("{}{}{}{}{}{}{}=7".format(a,op1,b,op2,c,op3,d))
                    return

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

Submission status: Accepted

Solution code:
S = input()

for i in range(1 << (len(S)-1)):
    temp = int(S[0])
    ans = str(S[0])
    for j in range(len(S)-1):
        if ((i >> j) & 1) == 1:
            temp -= int(S[j+1])
            ans = ans + '-' + str(S[j+1])
        else:
            temp += int(S[j+1])
            ans = ans + '+' + str(S[j+1])
    if temp == 7:
        break
print(ans+'=7')

Submission status: Accepted

Solution code:
S = input()

for i in range(1<<(4-1)+1):
    eq = S[0:1]
    for j in range(1,len(S)):
        if i & 1 << j:
            eq += '+' + S[j:j+1]
        else:
            eq += '-' + S[j:j+1]
    if eval(eq) == 7:
        print(eq+'=7')
        break

Submission status: Accepted

Solution code:
N=int(input())

def digitSum(s):
    x1 = s//10**4
    x2 = (s-x1*10**4)//10**3
    x3 = (s-x2*10**3-x1*10**4)//10**2
    x4 = (s-x3*10**2-x2*10**3-x1*10**4)//10
    x5 = (s-x4*10-x3*10**2-x2*10**3-x1*10**4)
    # print(x1,x2,x3,x4,x5)
    return x2,x3,x4,x5

a,b,c,d=digitSum(N)

suzi=[b,c,d]

puramai=[0,0,0]
i=0
answer=[0,0,0]
def tansaku(i,puramai,sum,answer):
    if i==3:
        if sum+a==7:
            answer[0]=puramai[0]
            answer[1]=puramai[1]
            answer[2]=puramai[2]
            return 
        else:
            return            
    sum+=suzi[i]
    puramai[i]='+'
    tansaku(i+1,puramai,sum,answer)

    sum=sum-2*suzi[i]
    puramai[i]='-'
    tansaku(i+1,puramai,sum,answer)
    

tansaku(0,puramai,0,answer)  

    
m=str(a)+answer[0]+str(b)+answer[1]+str(c)+answer[2]+str(d)+'=7'
print(m)

Submission status: Accepted

Solution code:
s = input()
a = []
for i in range(4):
    a.append(int(s[i]))
ans= 7- a[0]
for op in range(1<<3):
    sans = [str(a[0])]
    tmp = ans
    for i in range(3):
        if (op//2**i)%2 == 0:
            tmp -= a[i+1]
            sans.append('+')
            sans.append(str(a[i+1]))
        else:
            tmp += a[i+1]
            sans.append('-')
            sans.append(str(a[i+1]))
    if tmp == 0:
        break
for i in range(len(sans)):
    print(sans[i],end="")
print('=7')

Submission status: Accepted

Solution code:
def create_equ(eq, index):
    global L
    if index == 4:
        L.append(eq)
    else:
        create_equ(eq + "+" + S[index], index + 1)
        create_equ(eq + "-" + S[index], index + 1)


if __name__ == "__main__":
    S = list(input())
    index = 1
    eq = S[0]
    L = []
    create_equ(eq, index)
    for l in L:
        if eval(l) == 7:
            print(l + '=7')
            break

Submission status: Accepted

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

op = ['+','-']

for op1,op2,op3 in itertools.product(op,op,op):
  x = A + op1 + B + op2 + C + op3 + D
  if(eval(x) == 7):
    print(x + "=7")
    break

Submission status: Accepted

Solution code:
def abc079_c():
    n = list(map(int, input()))
    a = n[0]
    for b in [n[1], -n[1]]:
        for c in [n[2], -n[2]]:
            for d in [n[3], -n[3]]:
                if a + b + c + d == 7:
                    op1 = ["+", "-"][b < 0]
                    op2 = ["+", "-"][c < 0]
                    op3 = ["+", "-"][d < 0]
                    print(a, op1, abs(b), op2, abs(c), op3, abs(d), "=7", sep="")
                    return 0


abc079_c()

Submission status: Accepted

Solution code:
s = list(input())
d = 3
def operate1(string):
  string += "-"
  return string
def operate2(string):
  string += "+"
  return string
def bfs(list_hoge = [s[0]],depth = 0,deepest = d):
    queue = []
    for e in list_hoge:
        for b in [0,1]:
            if b == 0:
                operated = operate1(e)
                operated += s[depth + 1]
                queue.append(operated)
            elif b == 1:
                operated = operate2(e)
                operated += s[depth + 1]
                queue.append(operated)
    list_hoge = queue[:]
    depth += 1
    if depth == deepest:
        return list_hoge
    else:
        return bfs(list_hoge,depth)
for e in bfs():
  if eval(e) == 7:
    print(e + "=7")
    break

Submission status: Accepted

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

ops = ['+', '-']

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

Submission status: Accepted

Solution code:
S = input()
l = []
for i in S:
    l.append(int(i))


for i in range(1 << 3):
    output = l[0]
    res = '{}'.format(l[0])
    for j in range(3):
        if ((i >> j) & 1) == 1:
            output += l[j+1]
            res += '+{}'.format(l[j+1])
        else:
            output -= l[j+1]
            res += '-{}'.format(l[j+1])
    if output ==7:
        res += '=7'
        print(res)
        exit()

Submission status: Accepted

Solution code:
def main():
    a, b, c, d = list(input())
    ops = ['+', '-']
    for op1 in ops:
        for op2 in ops:
            for op3 in ops:
                s = a + op1 + b + op2 + c + op3 + d
                if eval(s) == 7:
                    print(s + '=7')
                    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
abcd = str(input())
n = 3
for bits in range(1 << n):
    x1 = '+'
    x2 = '+'
    x3 = '+'
    for i in range(n):
        if (bits >> i & 1) == 1:
            if i == 0:
                x1 = '-'
            if i == 1:
                x2 = '-'
            if i == 2:
                x3 = '-'
    check1 = abcd[0] + x1 + abcd[1] + x2 + abcd[2] + x3 + abcd[3]
    check2 = eval(abcd[0] + x1 + abcd[1] + x2 + abcd[2] + x3 + abcd[3])
    if check2 == 7:
        ans = check1
print(ans+'=7')

Submission status: Accepted

Solution code:
import itertools
L = input()
s = ['+','-']
for a, b, c in itertools.product(s, s, s):
   f = L[0] + a + L[1] + b + L[2] + c + L[3] 
   if eval(f) == 7:
       print(f+'=7')
       exit(0)

Submission status: Accepted

Solution code:
import itertools
L = input()
s = ['+','-']
t = ['+','-']
u = ['+','-']
for a, b, c in itertools.product(s, t, u):
   f = L[0] + a + L[1] + b + L[2] + c + L[3] 
   if eval(f) == 7:
       print(f+'=7')
       exit(0)

Submission status: Accepted

Solution code:
L = input()
s = ['+','-']
for a in s:
    for b in s:
        for c in s:
            f = L[0] + a + L[1] + b + L[2] + c + L[3]
            if eval(f) == 7:
                print(f+'=7')
                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])
if a+b+c+d == 7:
    print(s[0]+'+'+s[1]+'+'+s[2]+'+'+s[3]+'=7')
    exit()
if a+b+c-d == 7:
    print(s[0]+'+'+s[1]+'+'+s[2]+'-'+s[3]+'=7')
    exit()
if a+b-c+d == 7:
    print(s[0]+'+'+s[1]+'-'+s[2]+'+'+s[3]+'=7')
    exit()
if a+b-c-d == 7:
    print(s[0]+'+'+s[1]+'-'+s[2]+'-'+s[3]+'=7')
    exit()
if a-b+c+d == 7:
    print(s[0]+'-'+s[1]+'+'+s[2]+'+'+s[3]+'=7')
    exit()
if a-b+c-d == 7:
    print(s[0]+'-'+s[1]+'+'+s[2]+'-'+s[3]+'=7')
    exit()
if a-b-c+d == 7:
    print(s[0]+'-'+s[1]+'-'+s[2]+'+'+s[3]+'=7')
    exit()
if a-b-c-d == 7:
    print(s[0]+'-'+s[1]+'-'+s[2]+'-'+s[3]+'=7')
    exit()

Submission status: Accepted

Solution code:
n = input()
sign = ["+", "-"]
for op1 in sign:
    for op2 in sign:
        for op3 in sign:
            f = n[0]+op1+n[1]+op2+n[2]+op3+n[3]
            if eval(n[0]+op1+n[1]+op2+n[2]+op3+n[3]) == 7:
                print(f + "=7")
                exit()

Submission status: Accepted

Solution code:
A, B, C, D = map(int, input())
for i in range(2):
	for j in range(2):
		for k in range(2):
			if A + B * (i * 2 - 1) + C * (j * 2 - 1) + D * (k * 2 - 1) == 7:
				print (A, "-+"[i], B, "-+"[j], C, "-+"[k], D, "=7", sep='')
				break
		else:
			continue
		break
	else:
		continue
	break

Submission status: Accepted

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


def operation(x):
    pattern = 2 ** len(x)
    for i in range(pattern):
        ops = '{:04b}'.format(i)
        s = 0
        for t, op in zip(x, ops):
            if op == '0':
                s += t
            else:
                s -= t
        if s == 7:
            return ops


ops = operation(x).replace('0', '+').replace('1', '-')
print(''.join([ops[i] + str(x[i]) for i in range(len(x))])[1:] + '=7')

Submission status: Accepted

Solution code:
def cal(sgn, n1, n2):
    return n1 + n2 if sgn == '+' else n1 - n2


A, B, C, D = map(int, list(input()))
sgns = []
for bit in range(1<<3):
    tmp = ['+'] * 3
    for i in range(3):
        if ((bit>>i) & 1) == 1:
            tmp[i] = '-'
    sgns.append(tmp)

for sgn in sgns:
    if cal(sgn[2], cal(sgn[1], cal(sgn[0], A, B), C), D) == 7:
        print('{0}{1}{2}{3}{4}{5}{6}=7'.format(A, sgn[0], B, sgn[1], C, sgn[2], D))
        exit()

Submission status: Accepted

Solution code:
L = input()
N = [int(i) for i in list(L)]
def check(n):
  if n == -1:
    return '-'
  else:
    return '+'
for i in range(2):
  for j in range(2):
    for k in range(2):
      if N[0] + N[1] * pow(-1, i) + N[2] * pow(-1, j) + N[3] * pow(-1, k) == 7:
        ii = check(pow(-1, i))
        jj = check(pow(-1, j))
        kk = check(pow(-1, k))
        print(str(N[0]) + ii + str(N[1]) + jj + str(N[2]) + kk + str(N[3]) + "=7")
        exit(0)

Submission status: Accepted

Solution code:
n = list(map(int,list(input())))
limit = 7
d = [ [] for i in range(len(n))]
op = [ [] for i in range(len(n))]

for i,val in enumerate(n):
	if i == 0:
		d[0].append(n[0])
		op[0].append("")
	else:
		for j in d[i-1]:
			d[i].append(j+val)
			d[i].append(j-val)
		for j in op[i-1]:
			op[i].append(j + "+")
			op[i].append(j + "-")


_op = op[len(n)-1][d[len(n)-1].index(limit)]

s = ""
for i,val in enumerate(n):
	s += str(val)
	if i == len(n)-1:
		break
	else:
		s += _op[i]
s += "="+str(limit)
print(s)

Submission status: Accepted

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

for i in range(2**(size-1)):
    op = [(i >> j) & 1 for j in range(size)][::-1]
    tmp = [k * (-1)**j for j, k in zip(op, a)]
    if sum(tmp) == 7:
        s = ''.join([('-' if j == 1 else '+') + str(k) for j, k in zip(op, a)])
        print(s[1:] + '=7')
        break

Submission status: Accepted

Solution code:
def add(x, y, op):
    if op == '+':
        return x + y
    else:
        return x - y



def main():
    ops = ('+', '-')
    A, B, C, D = [int(i) for i in input()]

    for i in ops:
        for j in ops:
            for k in ops:
                s = 0
                s = add(A, B, i)
                s = add(s, C, j)
                s = add(s, D, k)
                if s == 7:
                    print('{}{}{}{}{}{}{}=7'.format(A, i, B, j, C, k, D))
                    return 0

if __name__ == "__main__":
    main()

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("%d+%d+%d+%d=7"%(a,b,c,d))
elif a+b+c-d==7:
    print("%d+%d+%d-%d=7"%(a,b,c,d))
elif a+b-c+d==7:
    print("%d+%d-%d+%d=7"%(a,b,c,d))
elif a-b+c+d==7:
    print("%d-%d+%d+%d=7"%(a,b,c,d))
elif a-b+c-d==7:
    print("%d-%d+%d-%d=7"%(a,b,c,d))
elif a+b-c-d==7:
    print("%d+%d-%d-%d=7"%(a,b,c,d))
elif a-b-c+d==7:
    print("%d-%d-%d+%d=7"%(a,b,c,d))
elif a-b-c-d==7:
    print("%d-%d-%d-%d=7"%(a,b,c,d))