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:
nums = [int(num) for num in input()]

target = 7

if sum(nums) == target:
    symbols = '+++'
elif nums[0] + nums[1] + nums[2] - nums[3] == target:
    symbols = '++-'
elif nums[0] + nums[1] - nums[2] + nums[3] == target:
    symbols = '+-+'
elif nums[0] + nums[1] - nums[2] - nums[3] == target:
    symbols = '+--'
elif nums[0] - nums[1] + nums[2] + nums[3] == target:
    symbols = '-++'
elif nums[0] - nums[1] + nums[2] - nums[3] == target:
    symbols = '-+-'
elif nums[0] - nums[1] - nums[2] + nums[3] == target:
    symbols = '--+'
elif nums[0] - nums[1] - nums[2] - nums[3] == target:
    symbols = '---'

result = ''
for i in range(len(symbols)):
    result += str(nums[i])
    result += symbols[i]
result += str(nums[-1])

print('{}=7'.format(result))

Submission status: Accepted

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

def myprint(c1,c2,c3):
    return print(str(a)+c1+str(b)+c2+str(c)+c3+str(d)+'=7')

if a+b+c+d==7:
    myprint('+','+','+')
elif a+b+c-d==7:
    myprint('+','+','-')
elif a+b-c+d==7:
    myprint('+','-','+')
elif a+b-c-d==7:
    myprint('+','-','-')
elif a-b+c+d==7:
    myprint('-','+','+')
elif a-b+c-d==7:
    myprint('-','+','-')
elif a-b-c+d==7:
    myprint('-','-','+')
elif a-b-c-d==7:
    myprint('-','-','-')

Submission status: Accepted

Solution code:
import itertools

A, B, C, D = [int(s) for s in list(input())]

symbols = ['+', '-']
for s1, s2, s3 in itertools.product(symbols, symbols, symbols):
    N = 0
    N = A + B if s1 == '+' else A - B
    N = N + C if s2 == '+' else N - C
    N = N + D if s3 == '+' else N - D
    if N == 7:
        print('{}{}{}{}{}{}{}={}'.format(A, s1, B, s2, C, s3, D, N))
        break

Submission status: Accepted

Solution code:
a=input()
op=['+','-']

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=list(input().strip())

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

Submission status: Accepted

Solution code:
def dfs(N, ops, nums, Sum):
    if N == 3:
        if Sum == 7:
            print(str(nums[0])+ops[0]+str(nums[1])+ops[1]+str(nums[2])+ops[2]+str(nums[3])+"=7")
            return True
        else:
            return False
    else:
        ops[N]="+"
        if dfs(N+1, ops, nums, Sum+nums[N+1]):
            return True
        ops[N]="-"
        if dfs(N+1, ops, nums, Sum-nums[N+1]):
            return True

nums=[int(i) for i in input()]
ops=["" for i in range(3)]
dfs(0, ops, nums, nums[0])

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# Set 2 dimension list
def dim2input(N):
    li = []
    for _ in range(N):
        li.append(list(map(int, input())))
    return li

# --------------------------------------------

dp = None

def main():
    N = input()
    op = ["+", "-"]

    for op1 in op:
        for op2 in op:
            for op3 in op:
                if eval(N[0] + op1 + N[1] + op2 + N[2] + op3 + N[3]) == 7:
                    print(N[0] + op1 + N[1] + op2 + N[2] + op3 + N[3] + "=7")
                    return

main()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
n = input()
a = int(n[0])
b = int(n[1])
c = int(n[2])
d = int(n[3])
# op = ["+++", "++-", "+-+", "+--", "-++", "-+-", "--+", "---"]
if a + b + c + d == 7:
    print("{0}+{1}+{2}+{3}=7".format(str(a), str(b), str(c), str(d)))
elif a + b + c - d == 7:
    print("{0}+{1}+{2}-{3}=7".format(str(a), str(b), str(c), str(d)))
elif a + b - c + d == 7:
    print("{0}+{1}-{2}+{3}=7".format(str(a), str(b), str(c), str(d)))
elif a + b - c - d == 7:
    print("{0}+{1}-{2}-{3}=7".format(str(a), str(b), str(c), str(d)))
elif a - b + c + d == 7:
    print("{0}-{1}+{2}+{3}=7".format(str(a), str(b), str(c), str(d)))
elif a - b + c - d == 7:
    print("{0}-{1}+{2}-{3}=7".format(str(a), str(b), str(c), str(d)))
elif a - b - c + d == 7:
    print("{0}-{1}-{2}+{3}=7".format(str(a), str(b), str(c), str(d)))
elif a - b - c - d == 7:
    print("{0}-{1}-{2}-{3}=7".format(str(a), str(b), str(c), str(d)))

Submission status: Accepted

Solution code:
li=list(map(int,list(input())))
for i in range(2**3):
  val=li[0]
  outp=str(val)
  for j in range(3):
    if((i>>j)&0b1):
      val+=li[j+1]
      outp+="+"+str(li[j+1])
    else:
      val-=li[j+1]
      outp+="-"+str(li[j+1])
  if(val==7):break
print(outp+"=7")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = str(input())
n = len(S)
ans = 0

for i in range(1 << n-1):
    ins = S[0]
    for j in range(n-1):
        if i & (1 << j):
            ins += "+" + S[j+1]
        else:
            ins += "-" + S[j+1]

    if eval(ins) == 7:
        print(ins + "=7")
        break

Submission status: Accepted

Solution code:
n=input()
a=[c for c in n]
li=['+','-']

def ans(a,li):
    for p in li:
        for q in li:
            for r in li:
                ans=a[0]+p+a[1]+q+a[2]+r+a[3]
                if eval(ans)==7:
                    return ans+'=7'

print(ans(a,li))

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(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:
fig = input()
a = int(fig[0])
b = int(fig[1])
c = int(fig[2])
d = int(fig[3])

if a + b + c + d == 7:
    op1 = "+"
    op2 = "+"
    op3 = "+"
elif a - b + c + d == 7:
    op1 = "-"
    op2 = "+"
    op3 = "+"
elif a - b - c + d == 7:
    op1 = "-"
    op2 = "-"
    op3 = "+"
elif a - b + c - d == 7:
    op1 = "-"
    op2 = "+"
    op3 = "-"    
elif a + b - c + d == 7:
    op1 = "+"
    op2 = "-"
    op3 = "+"
elif a + b - c - d == 7:
    op1 = "+"
    op2 = "-"
    op3 = "-"
elif a + b + c - d == 7:
    op1 = "+"
    op2 = "+"
    op3 = "-"

print("{0}{1}{2}{3}{4}{5}{6}=7".format(a,op1,b,op2,c,op3,d))

Submission status: Accepted

Solution code:
from itertools import product

s = tuple(map(int, tuple(input())))

options = (-1, 1)

for op1, op2, op3 in product(options, repeat=3):
    if (s[0] + s[1] * op1 + s[2] * op2 + s[3] * op3) == 7:
        _op1 = "+" if op1 == 1 else "-"
        _op2 = "+" if op2 == 1 else "-"
        _op3 = "+" if op3 == 1 else "-"
        print(s[0], _op1, s[1], _op2, s[2], _op3, s[3], "=7", sep="")
        exit()

Submission status: Accepted

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

#0 →  +  1→-
pm=[1,-1]
hugou=["+","-"]
for i in range(2):
    for j in range(2):
        for k in range(2):
            if a+pm[i]*b+pm[j]*c+pm[k]*d==7:
                print(str(a)+hugou[i]+str(b)+hugou[j]+str(c)+hugou[k]+str(d)+"=7")
                exit()

Submission status: Accepted

Solution code:
import itertools
 
 
def find_eq(abcd):
    a, b, c, d = abcd
    ops = ("+", "-")
    for op1, op2, op3 in itertools.product(ops, repeat=3):
        eq = a + op1 + b + op2 + c + op3 + d
        if eval(eq) == 7:
            return eq + "=7"
 
 
def main():
    print(find_eq(input()))
 
 
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools
b=[]
for a in itertools.product((0, 1), repeat=3):
    b.append(a)

A=input()
c=int(A[0])
for i in range(len(b)):
    c=int(A[0])
    for j in range(3):
        if b[i][j]==0:
                c=c+int(A[j+1])
        else:
                c=c-int(A[j+1])
    if c==7:
        print(A[0],end="")
        for j in range(3):
            if b[i][j]==0:
                print("+",end="")
            else:
                print("-",end="")
            print(A[j+1],end="")
        print("=7")
        break

Submission status: Accepted

Solution code:
S=input()
a=int(S[0])
b=int(S[1])
c=int(S[2])
d=int(S[3])
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:
S = input()

for op1 in "+-":
    for op2 in "+-":
        for op3 in "+-":
            s = S[0] + op1
            s += S[1] + op2
            s += S[2] + op3
            s += S[3]

            if eval(s) == 7:
                print(s + "=7")
                exit()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
A,B,C,D = list(map(int, list(input())))

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 make_st(s, xs):
    if not s:
        return xs

    y = s[-1]
    ys = []
    for x in xs:
        ys.append(y + "+" + x)
        ys.append(y + "-" + x)
    return make_st(s[:-1], ys)

s = input()

for x in make_st(s[:-1], [s[-1]]):
    if eval(x) == 7:
        print(x+"=7")
        break

Submission status: Accepted

Solution code:


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

for op1 in "-+":
    for op2 in "-+":
        for op3 in "-+":
            e = 0
            e += a + b if op1 == '+' else a - b
            e += c if op2 == '+' else -c
            e += d if op3 == '+' else -d
            if e == 7:
                s = str(a) + op1 + str(b) + op2 + str(c) + op3 + str(d)
                print(s + "=7")
                exit(0)

Submission status: Accepted

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

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

pr = itertools.product([a], [b, -1 * b], [c, -1 * c], [d, -1 * d])

for li in pr:
    if sum(li) == 7:
        print('%d%+d%+d%+d=7' % li)
        break

Submission status: Accepted

Solution code:
import sys
def search(ans, i=0):
    if i == 3:
        if ans == 7:
            print('{0[0]}{1[0]}{0[1]}{1[1]}{0[2]}{1[2]}{0[3]}=7'.format(value,opr))
            sys.exit()
        return
    for j in range(3):
        ans -= int(value[i+1])
        opr.append('-')
        search(ans, i+1)
        ans += int(value[i+1])
        opr.pop(i)

        opr.append('+')
        ans += int(value[i+1])
        search(ans, i+1)
        ans -= int(value[i+1])
        opr.pop(i)
    return

value = input()
ans = int(value[0])
opr = []
search(ans)

Submission status: Accepted

Solution code:
s = list(raw_input())
n = len(s) - 1
for i in range(2**n):
    cmd = s[0]
    for j in range(n):
        if (i & (2**j)):
            cmd += "+"
        else:
            cmd += "-"
        cmd += s[j+1]
    if eval(cmd) == 7:
        print(cmd+"=7")
        break

Submission status: Accepted

Solution code:
mum = input()
a = int(mum[0])
b = int(mum[1])
c = int(mum[2])
d = int(mum[3])
ans = []
ans.append(a+b+c+d)
ans.append(a-b+c+d)
ans.append(a+b-c+d)
ans.append(a-b-c+d)
ans.append(a+b+c-d)
ans.append(a-b+c-d)
ans.append(a+b-c-d)
ans.append(a-b-c-d)

if ans[0] == 7:
	print('{}+{}+{}+{}=7'.format(a,b,c,d))
elif ans[1] == 7:
	print('{}-{}+{}+{}=7'.format(a,b,c,d))
elif ans[2] == 7:
	print('{}+{}-{}+{}=7'.format(a,b,c,d))
elif ans[3] == 7:
	print('{}-{}-{}+{}=7'.format(a,b,c,d))
elif ans[4] == 7:
	print('{}+{}+{}-{}=7'.format(a,b,c,d))
elif ans[5] == 7:
	print('{}-{}+{}-{}=7'.format(a,b,c,d))
elif ans[6] == 7:
	print('{}+{}-{}-{}=7'.format(a,b,c,d))
elif ans[7] == 7:
	print('{}-{}-{}-{}=7'.format(a,b,c,d))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

for i in range(8):
    ops = list(format(i, "03b"))
    ret = int(S[0])
    ans = S[0]
    for j, op in enumerate(ops):
        if op == "0":
            ret += int(S[j + 1])
            ans += "+" + S[j + 1]
        else:
            ret -= int(S[j + 1])
            ans += "-" + S[j + 1]
    # print(ops, ret)

    if ret == 7:
        print(ans + "=7")
        exit()

Submission status: Accepted

Solution code:
import sys

ABCD = raw_input()

for op1 in "+-":
    for op2 in "+-":
        for op3 in "+-":
            e = ABCD[0] + op1 + ABCD[1] + op2 + ABCD[2] + op3 + ABCD[3]
            if eval(e) == 7:
                print e + "=7"
                sys.exit(0)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

import numpy as np
li=np.array(list(map(int,list(input()))))
wa=[
   [1,1,1,1],
   [1,1,1,-1],
   [1,1,-1,1],
   [1,1,-1,-1],
   [1,-1,1,1],
   [1,-1,1,-1],
   [1,-1,-1,1],
   [1,-1,-1,-1],
   [-1,1,1,1],
   [-1,1,1,-1],
   [-1,1,-1,1],
   [-1,1,-1,-1],
   [-1,-1,1,1],
   [-1,-1,1,-1],
   [-1,-1,-1,1],
   [-1,-1,-1,-1],
  ]
wa=np.array(wa)
for w in wa:
  if np.dot(w,li)==7:
    isfirst=True
    for p,i in zip(w,range(4)):
        if isfirst:
            print(li[0],end='')
            isfirst=False
            continue
        if p >0:
            print('+',end=str(li[i]))
        else:
            print('-',end=str(li[i]))
    print('=7')
    quit()

Submission status: Accepted

Solution code:
op = ['+', '-']
s = input()

for i in op:
    for j in op:
        for k in op:
            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:
def solve():
    _ABCD = input()
    ABCD = []
    for i in _ABCD:
        ABCD.append(int(i))
    if ABCD[0] + ABCD[1] + ABCD[2] + ABCD[3] == 7:
        print(_ABCD[0]+"+"+_ABCD[1]+"+"+_ABCD[2]+"+"+_ABCD[3]+"=7")
    elif ABCD[0] + ABCD[1] + ABCD[2] - ABCD[3] == 7:
        print(_ABCD[0]+"+"+_ABCD[1]+"+"+_ABCD[2]+"-"+_ABCD[3]+"=7")
    elif ABCD[0] + ABCD[1] - ABCD[2] + ABCD[3] == 7:
        print(_ABCD[0]+"+"+_ABCD[1]+"-"+_ABCD[2]+"+"+_ABCD[3]+"=7")
    elif ABCD[0] + ABCD[1] - ABCD[2] - ABCD[3] == 7:
        print(_ABCD[0]+"+"+_ABCD[1]+"-"+_ABCD[2]+"-"+_ABCD[3]+"=7")
    elif ABCD[0] - ABCD[1] + ABCD[2] + ABCD[3] == 7:
        print(_ABCD[0]+"-"+_ABCD[1]+"+"+_ABCD[2]+"+"+_ABCD[3]+"=7")
    elif ABCD[0] - ABCD[1] + ABCD[2] - ABCD[3] == 7:
        print(_ABCD[0]+"-"+_ABCD[1]+"+"+_ABCD[2]+"-"+_ABCD[3]+"=7")
    elif ABCD[0] - ABCD[1] - ABCD[2] + ABCD[3] == 7:
        print(_ABCD[0]+"-"+_ABCD[1]+"-"+_ABCD[2]+"+"+_ABCD[3]+"=7")
    elif ABCD[0] - ABCD[1] - ABCD[2] - ABCD[3] == 7:
        print(_ABCD[0]+"-"+_ABCD[1]+"-"+_ABCD[2]+"-"+_ABCD[3]+"=7")

solve()

Submission status: Accepted

Solution code:
# coding: utf-8
# 整数の入力
a, b, c, d = [int(i) for i in input()]
# 計算
if a+b+c+d == 7:
    s = "{}+{}+{}+{}=7"
elif a+b+c-d == 7:
    s = "{}+{}+{}-{}=7"
elif a+b-c+d == 7:
    s = "{}+{}-{}+{}=7"
elif a+b-c-d == 7:
    s = "{}+{}-{}-{}=7"
elif a-b+c+d == 7:
    s = "{}-{}+{}+{}=7"
elif a-b+c-d == 7:
    s = "{}-{}+{}-{}=7"
elif a-b-c+d == 7:
    s = "{}-{}-{}+{}=7"
elif a-b-c-d == 7:
    s = "{}-{}-{}-{}=7"
# 出力
print(s.format(a, b, c, d))

Submission status: Accepted

Solution code:
import itertools
N=[int(x) for x in input()]
op=['+','-']
for op1 in op:
  for op2 in op:
    for op3 in op:
      if op1=='+': ans=N[0]+N[1]
      else: ans=N[0]-N[1]
      if op2=='+': ans+=N[2]
      else: ans-=N[2]
      if op3=='+': ans+=N[3]
      else: ans-=N[3]
      if ans==7:
        print(N[0],end="")
        print(op1,end="")
        print(N[1],end="")
        print(op2,end="")
        print(N[2],end="")
        print(op3,end="")
        print(N[3],end="")
        print("=7")
        exit()

Submission status: Accepted

Solution code:

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

result = None

for i in [0,1]:
    tmp = A + B if i == 0 else A - B
    for j in [0,1]:
        tmp2 = tmp + C if j == 0 else tmp - C
        for k in [0,1]:
            tmp3 = tmp2 + D if k == 0 else tmp2 - D
            if tmp3 == 7:
                result = [i, j, k]



def f(i):
    if i == 0:
        return '+'
    else:
        return '-'


result = [f(x) for x in result]

print(str(A) + result[0] + str(B) + result[1] + str(C) + result[2] + str(D) + '=7')

Submission status: Accepted

Solution code:
import sys

x = input()

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

work = A
op1,op2,op3 = "","",""
for i in range(2):
    for j in range(2):
        for k in range(2):
            if i == 1:
                op1 = "+"
                work += B
            else:
                op1 = "-"
                work -= B
            if j == 1:
                op2 = "+"
                work += C
            else:
                op2 = "-"
                work -= C
            if k == 1:
                op3 = "+"
                work += D
            else:
                op3 = "-"
                work -= D
            if work ==7:
                print(x[0]+op1+x[1]+op2+x[2]+op3+x[3]+"=7")
                sys.exit()
            else:
                work = A

Submission status: Accepted

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

if int(A)+int(B)+int(C)+int(D) == 7:
	ans=A+'+'+B+'+'+C+'+'+D+'=7'
	print(ans)

elif int(A)+int(B)+int(C)-int(D) == 7:
	ans=A+'+'+B+'+'+C+'-'+D+'=7'
	print(ans)
	
elif int(A)+int(B)-int(C)+int(D) == 7:
	ans=A+'+'+B+'-'+C+'+'+D+'=7'
	print(ans)

elif int(A)+int(B)-int(C)-int(D) == 7:
	ans=A+'+'+B+'-'+C+'-'+D+'=7'
	print(ans)

elif int(A)-int(B)+int(C)+int(D) == 7:
	ans=A+'-'+B+'+'+C+'+'+D+'=7'
	print(ans)
	
elif int(A)-int(B)+int(C)-int(D) == 7:
	ans=A+'-'+B+'+'+C+'-'+D+'=7'
	print(ans)
	
elif int(A)-int(B)-int(C)+int(D) == 7:
	ans=A+'-'+B+'-'+C+'+'+D+'=7'
	print(ans)
	
elif int(A)-int(B)-int(C)-int(D) == 7:
	ans=A+'-'+B+'-'+C+'-'+D+'=7'
	print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import itertools

A,B,C,D = [int(i) for i in input()]
for ops in range(8):
    ops2 = []
    val = 0
    if ops%2 == 0:
        val = A+B
        ops2.append('+')
    else:
        val = A-B
        ops2.append('-')

    if (ops//2)%2 == 0:
        val += C
        ops2.append('+')
    else:
        val -= C
        ops2.append('-')

    if (ops//4)%2 == 0:
        val += D
        ops2.append('+')
    else:
        val -= D
        ops2.append('-')
    if val == 7:
        print(str(A)+ops2[0]+str(B)+ops2[1]+str(C)+ops2[2]+str(D)+'='+str(7))
        break

Submission status: Accepted

Solution code:
in_data = input().rstrip()
dic = {0:int(in_data[0])}
for i in range(3):
    n_dic = {}
    for item in dic.items():
        n_dic[item[0] + 2**i] = item[1] + int(in_data[i+1])
        n_dic[item[0]] = item[1] - int(in_data[i+1])
    dic = n_dic
    
for item in dic.items():
    if item[1] == 7:
        print(in_data[0], end='')
        num = item[0]
        for i in in_data[1:]:
            num, sign = num // 2, num % 2
            print("%s%s" % ("+" if sign==1 else "-", i), end="")
        break
print("=7")

Submission status: Accepted

Solution code:
p = input()
a = int(p[0])
b = int(p[1])
c = int(p[2])
d = int(p[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                                                                   

inp = list(raw_input())

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

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

Submission status: Accepted

Solution code:
from itertools import chain
op_list = ["+","-"]
s = input()

res=""
for i in range(8):
	op1 = op_list[i%2]
	op2 = op_list[i // 2 % 2]
	op3 = op_list[i // 4]
	expr = "".join(chain.from_iterable(zip(s,[op1, op2, op3, ""])))
	if eval(expr) == 7:
		res = expr + "=7"
		break

print(res)

Submission status: Accepted

Solution code:
S = input()
S_list=list(S)
A,B,C,D = int(S_list[0]),int(S_list[1]),int(S_list[2]),int(S_list[3])
res = ""

for i in range(8):
	ans = str(A)
	val = A
	if i & 1 == 1:
		ans += '+'
		val += B
	else:
		ans += '-'
		val -= B
	ans += str(B)
	if i & 2 == 2:
		ans += '+'
		val += C
	else:
		ans += '-'
		val -= C
	ans += str(C)
	if i & 4 == 4:
		ans += '+'
		val += D
	else:
		ans += '-'
		val -= D
	ans += str(D)
	ans += "=7"
	if val == 7:
		res = ans
		break;

print(res)

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')

Submission status: Accepted

Solution code:
from itertools import chain
op_list = ["+", "-"]
s = input()
for i in range(8):
	op1 = op_list[i % 2]
	op2 = op_list[i // 2 % 2]
	op3 = op_list[i // 4]
	expr = "".join(chain.from_iterable(zip(s, [op1, op2, op3, ""])))
	if eval(expr) == 7:
		print(expr + "=7")
		quit()

Submission status: Accepted

Solution code:
n = input()

for i in range(0, 0b1000):
    num = int(n[0])
    op = []
    for j in range(3):
        if (i & 1 << j):
            num += int(n[j+1])
            op.append("+")
        else:
            num -= int(n[j+1])
            op.append("-")
    if num == 7:
        for k in range(3):
            print("{0}{1}".format(n[k], op[k]), end="")
        print("{0}=7".format(n[3]))
        break

Submission status: Accepted

Solution code:
#!/usr/bin/env python

N=int(input())
Num=[0]*4
A=N//1000
B=N//100%10
C=N//10%10
D=N%10

'''
for i in range(0, len(Num)):
    print(Num[i])
'''

Num.sort()
mul=[-1,1]

def ope(sym):
    if(sym==-1):
        return "-" 
    elif(sym==1):
        return "+"

def cal():
    for j in mul:
        for k in mul:
            for m in mul:
                if( A + B*j + C*k + D*m == 7 ):
                    # print("j, k, m", j, k, m)
                    print(str(A)+ope(j)+str(B)+ope(k)+str(C)+ope(m)+str(D)+"=7")
                    return

cal()

Submission status: Accepted

Solution code:
N = input()

A = N[0]
B = N[1]
C = N[2]
D = N[3]

OP = ['+', '-']

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

Submission status: Accepted

Solution code:
inp = raw_input()
for i in xrange(8):
    ans = int(inp[0])
    ansStr = inp[0]
    a = bin(i)[2:].zfill(3)
    for j in xrange(3):
        buff = int(inp[j + 1]) * (-1 if(a[j] == "1")else 1)
        ans += buff
        ansStr += ("-"if(buff < 0)else "+") + inp[j + 1]
    #print ans
    if(ans == 7):
        print ansStr+"=7"
        break

Submission status: Accepted

Solution code:
A,B,C,D=map(int,list(input()))
o=["+","-"]
if A+B+C+D==7:
    strings="A{}B{}C{}D=7".format(o[0],o[0],o[0])
elif A+B+C-D==7:
    strings="A{}B{}C{}D=7".format(o[0],o[0],o[1])
elif A+B-C+D==7:
    strings="A{}B{}C{}D=7".format(o[0],o[1],o[0])
elif A+B-C-D==7:
    strings="A{}B{}C{}D=7".format(o[0],o[1],o[1])
elif A-B+C+D==7:
    strings="A{}B{}C{}D=7".format(o[1],o[0],o[0])
elif A-B+C-D==7:
    strings="A{}B{}C{}D=7".format(o[1],o[0],o[1])
elif A-B-C+D==7:
    strings="A{}B{}C{}D=7".format(o[1],o[1],o[0])
elif A-B-C-D==7:
    strings="A{}B{}C{}D=7".format(o[1],o[1],o[1])
strings=list(strings)
strings[0]=str(A)
strings[2]=str(B)
strings[4]=str(C)
strings[6]=str(D)
print("".join(strings))

Submission status: Accepted

Solution code:

def main():
    el = list(input())
    oplist = ["+", "-"]

    for op1 in oplist:
        for op2 in oplist:
            for op3 in oplist:
                q = "{}".join(el)
                q = q.format(op1, op2, op3)
                if eval(q) == 7:
                    print(q + "=7")
                    return 0

if __name__ == '__main__':
    main()