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: Wrong Answer

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

abc = input()

OP = ['+','-']
ans = 0
for op1 in OP:
    for op2 in OP:
        for op3 in OP:
            if eval(abc[0]+op1+abc[1]+op2+abc[2]+op3+abc[3]) == 7:
                ans = abc[0]+op1+abc[1]+op2+abc[2]+op3+abc[3]
print(ans)

Submission status: Wrong Answer

Solution code:
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    S = list(_ for _ in input())
    e= ''
    for i in range(2**3):
        e=S[0]
        for j in range(0,3):
            if j**2 & i:
                e+='+'
            else:
                e+='-'
            e+=S[j+1]
        if eval(e) == 7:
            e+='=7'
            break
    print(e)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
abcd = input()

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

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

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

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

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

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

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

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

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

Submission status: Wrong Answer

Solution code:
S=[int(i) for i in input()]
ans=S[0]
q=len(S)-1
li=[]
c=''
i=0
for x in range(1<<q):
    for y in range(q):
        if x>>y & 1:
            ans+=S[y+1]
        else:
            ans-=S[y+1]
    if ans==7:
        li.append(x)
    ans=S[0]
    
one=li[0]
two=bin(one)[2:]
if len(two)==2:
    two='0'+two
elif len(two)==1:
    two='00'+two
for s in two:
    c+=str(S[i])
    if s=='1':
        c+='+'
    elif s=='0':
        c+='-'
    i+=1
c+=str(S[3])+'=7'
print(c)

Submission status: Wrong Answer

Solution code:
s = str(input())
n = len(s)-1

for i in range(2**n):
  op = ['-']*n
  for j in range(n):
    if (i >> j) & 1:
      op[j] = '+'

  formula = ''
  op = op + ['']
  for s_, p_ in zip(list(s), op):
      formula += s_ + p_
  if eval(formula) == 7:
      print(formula+'=7')

Submission status: Wrong Answer

Solution code:
ticket = list(str(input()))

for state in range(1 << (len(ticket)-1)):
    fomula = ticket[0] + ''.join(('+' if state >> i & 1 else '-') + x for i, x in enumerate(ticket[1:]))
    if eval(fomula) == 7:
        print(fomula)
        exit()

Submission status: Wrong Answer

Solution code:
s = input()

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

one = -1
flg = False

for i in range(2):
	for j in range(2):
		for k in range(2):
			if a + b*one**i + c*one**j + d*one**k == 7:
				print(i,j,k)
				flg = True
				break
		if flg:
			break
	if flg:
		break
                
if i == 0 :
	i_flg = "+"
else:
	i_flg = "-"

if j == 0 :
	j_flg = "+"
else:
	j_flg = "-"

if k == 0 :
	k_flg = "+"
else:
	k_flg = "-"

print(a,i_flg,b,j_flg,c,k_flg,d,"=7",sep='')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#dfs実装したい
S=input()
print(S[0])#左最初
show=""
def dfs(op):
    if len(op)==3:#+++とか揃ったらそれで計算する
        count=int(S[0])
        for i in range(3):
            if op[i]=='+':
                count+=int(S[i+1])#b c d
            elif op[i]=='-':
                count-=int(S[i+1])
        if count==7:
            show=S[0]
            for i in range(3):
                show+=op[i]+S[i+1]
            show+="=7"
            return show
        else:
            return ""
    s1=dfs(op+'+')
    s2=dfs(op+'-')
    if len(s1)>len(s2):
        return s1#""とshowの長い方のshowを返すよう選ぶ
    else:
        return s2

print(dfs(""))

Submission status: Wrong Answer

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

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

print(abcd)

ans = ""

def dfs(i, num, s):
    global ans
    if i == len(abcd):
        if num == 7:
            s += "=7"
            ans = s
        return

    dfs(i + 1, num + abcd[i], s + "+" + str(abcd[i]))
    dfs(i + 1, num - abcd[i], s + "-" + str(abcd[i]))

    return

dfs(1,abcd[0],str(abcd[0]))

print(ans)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,list(input()))
if a+b+c+d==7:
  print(a,'+',b,'+',c,'+',d,'=7',sep='')
elif a+b+c-d==7:
  print(a,'+',b,'+',c,'-',d,'=7',sep='')
elif a+b-c+d==7:
  print(a,'+',b,'-',c,'+',d,'=7',sep='')
elif a-b+c+d==7:
  print(a,'-',b,'+',c,'+',d,'=7',sep='')
elif a+b-c-d==7:
  print(a,'+',b,'-',c,'-',d,'=7',sep='')
elif a-b-c+d==7:
  print(a,'-',b,'-',c,'+',d,'=7',sep='')
else:
  print(a,'-',b,'-',c,'-',d,'=7',sep='')

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,list(input()))
if a+b+c+d==7:
  print('a+b+c+d=7')
elif a+b+c-d==7:
  print('a+b+c-d=7')
elif a+b-c+d==7:
  print('a+b-c+d=7')
elif a-b+c+d==7:
  print('a-b+c+d=7')
elif a+b-c-d==7:
  print('a+b-c-d=7')
elif a-b-c+d==7:
  print('a-b-c+d=7')
else:
  print('a-b-c-d=7')

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,list(input()))
if a+b+c+d==7:
  print('a+b+c+d=7')
if a+b+c-d==7:
  print('a+b+c-d=7')
if a+b-c+d==7:
  print('a+b-c+d=7')
if a-b+c+d==7:
  print('a-b+c+d=7')
if a+b-c-d==7:
  print('a+b-c-d=7')
if a-b-c+d==7:
  print('a-b-c+d=7')
else:
  print('a-b-c-d=7')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def calc(a, op, b):
	if op == "+":
		return a + b
	else:
		return a - b
s = input()
A, B, C, D = [int(c) for c in s]
ops = ["+", "-"]
ans = ""
for op1 in ops:
	for op2 in ops:
		for op3 in ops:
			if calc(calc(calc(A, op1, B), op2, C), op3, D) == 7:
				ans = str(A) + op1 + str(B) + op2 + str(C) + op3 + str(D)

print(ans)

Submission status: Wrong Answer

Solution code:
B=input()
A=[]
for i in B:
    A.append(i)



for i in ["+","-"]:
    for j in ["+","-"]:
        for k in ["+","-"]:
            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")

Submission status: Wrong Answer

Solution code:
n = input()
#n = '0007'
ops_list = ['+++', '++-', '+-+', '-++', '+--', '-+-', '+--', '---']

for ops in ops_list:
    expression = '{}{}{}{}{}{}{}'.format(n[0], ops[0], n[1], ops[1], n[2], ops[2], n[3])
    if eval(expression) == 7:
        print('{}=7'.format(expression))
        break

Submission status: Wrong Answer

Solution code:
n = input()
#n = '0007'
ops_list = ['+++', '++-', '+-+', '+--', '-++', '-+-', '---']

for ops in ops_list:
    expression = '{}{}{}{}{}{}{}'.format(n[0], ops[0], n[1], ops[1], n[2], ops[2], n[3])
    if eval(expression) == 7:
        print('{}=7'.format(expression))
        break

Submission status: Wrong Answer

Solution code:
n = input()
ops_list = ['+++', '++-', '+-+', '+--', '-++', '-+-']

for ops in ops_list:
    expression = '{}{}{}{}{}{}{}'.format(n[0], ops[0], n[1], ops[1], n[2], ops[2], n[3])
    if eval(expression) == 7:
        print('{}=7'.format(expression))
        break

Submission status: Wrong Answer

Solution code:
def DepthFirst_search(S,pre):
    global out
    #print(out)
    print('pre = {}'.format(pre))
    if len(S) == 1 :
        if pre + int(S[0]) == 7:
            out = out + '+{}'.format(int(S[0])) + '=7'
            return True
        if pre - int(S[0]) == 7:
            out = out + '-{}'.format(int(S[0])) + '=7'
            return True
        return False

    pre += int(S[0])
    if DepthFirst_search(S[1:len(S)],pre):
        #print(out)
        out = '+' + S[0] + out
        return True
    pre -= 2*int(S[0])
    if DepthFirst_search(S[1:len(S)],pre):
        #print(out)
        out = '-' + S[0] + out
        return True
    return False
out = ''
pre = 0
S = input()
DepthFirst_search(S,pre)

print(out[1:])

Submission status: Wrong Answer

Solution code:
import itertools

s = input()

x = ['+','-']

l = list(itertools.product(x,x,x))

res = int(s[0])
for sign in l:
  res = int(s[0])
  for i in range(3):
    if sign[i] == '+':
      res += int(s[i+1])
    else:
      res -= int(s[i+1])
  if res == 7:
    print(s[0],end="")
    for i in range(3):
      print(sign[i],end="")
      print(s[i+1],end="")
    print("=7")

Submission status: Wrong Answer

Solution code:
import itertools

s = input()

x = ['+','-']

l = list(itertools.product(x,x,x))

res = int(s[0])
for sign in l:
  res = int(s[0])
  for i in range(3):
    if sign[i] == '+':
      res += int(s[i+1])
    else:
      res -= int(s[i+1])
  if res == 7:
    print(s[0],end="")
    for i in range(3):
      print(sign[i],end="")
      print(s[i+1],end="")
    print("")

Submission status: Wrong Answer

Solution code:
s = [int(i) for i in input()]
op = {'+':1, '-':-1}
for a in op:
  for b in op:
    for c in op:
      if s[0] + op[a] * s[1] + op[b] * s[2] + op[c] * s[3] == 7:
        print(str(s[0]) + a + str(s[1]) + b + str(s[2]) + c + str(s[3]) + '=7')

Submission status: Wrong Answer

Solution code:
N = [int(i) for i in input()] 

flag = ["","",""]

for i in range(1 << len(N)-1):
	print("i:", i)
	result = N[0]
	for j in range(len(N)-1):
		print("j:", j)
		if ((i >> j) & 1) == 1:
			result += N[j+1]
			flag[j] = "+"
		else:
			result -= N[j+1]
			flag[j] = "-"

	print("result:", result)

	if result == 7:
		break

print("%d%s%d%s%d%s%d=7" %(N[0],flag[0],N[1],flag[1],N[2],flag[2],N[3]))

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,list(input()))
for i in range(2):
    if i==0:
        ans=a+b
    else:
        ans=a-b
    for j in range(2):
        if j==0:
            ans+=c
        else:
            ans-=c
        for k in range(2):
            if k==0:
                ans+=d
            else:
                ans-=d
            if ans==7:
                ret=[i,j,k]
                for i in range(len(ret)):
                    if ret[i]==0:
                        ret[i]='+'
                    else:
                        ret[i]='-'
                print('{}{}{}{}{}{}{}=7'.format(a,ret[0],b,ret[1],c,ret[2],d))
                exit()

Submission status: Wrong Answer

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

Arith_list = ["+", "-", "*", "//"]

def func(a ,b, arith):
    if arith == 0:
        return a + b
    elif arith == 1:
        return a - b
    elif arith == 2:
        return a * b
    elif arith == 3:
        if b == 0:
            return 6763909007
        else:
            return a // b

ans = 0
op1 = 0
op2 = 0
op3 = 0
for i in range(4):
    for j in range(4):
        for k in range(4):
            if i >= j >= k:
                ans = func(func(func(a, b, i), c, j), d, k)
            elif i >= j and k > j:
                ans = func(func(a,b,i),func(c,d, k), j)
            elif j > i >= k:
                ans = func(func(a, func(b,c, j), i),d, k)
            elif j >= k > i:
                ans = func(a, func(func(b,c, j),d, k), k)
            elif k > i >= j:
                ans = func(func(a,b,i), func(c,d,k), j)
            elif k > j > i:
                ans = func(a, func(b,func(c,d, k), j), i)
            else:
                #print(i,j,k)
                #print("error")
                pass
            if ans == 7:
                op1 = i
                op2 = j
                op3 = k
                print(str(a)+Arith_list[op1]+str(b)+ Arith_list[op2]+str(c)+ Arith_list[op3]+str(d)+ "=7")
                sys.exit()

Submission status: Wrong Answer

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

Arith_list = ["+", "-", "*", "//"]

def func(a ,b, arith):
    if arith == 0:
        return a + b
    elif arith == 1:
        return a - b
    elif arith == 2:
        return a * b
    elif arith == 3:
        if b == 0:
            return 6763
        else:
            return a // b

ans = 0
op1 = 0
op2 = 0
op3 = 0
for i in range(4):
    for j in range(4):
        for k in range(4):
            if i >= j >= k:
                ans = func(func(func(a, b, i), c, j), d, k)
            elif i >= j and k > j:
                ans = func(func(a,b,i),func(c,d, k), j)
            elif j > i >= k:
                ans = func(func(a, func(b,c, j), i),d, k)
            elif j >= k > i:
                ans = func(a, func(func(b,c, j),d, k), k)
            elif k > i >= j:
                ans = func(func(a,b,i), func(c,d,k), j)
            elif k > j > i:
                ans = func(a, func(b,func(c,d, k), j), i)
            else:
                #print(i,j,k)
                #print("error")
                pass
            if ans == 7:
                op1 = i
                op2 = j
                op3 = k
                print(str(a)+Arith_list[op1]+str(b)+ Arith_list[op2]+str(c)+ Arith_list[op3]+str(d)+ "=7")
                sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
A,B,C,D = map(int, list(input()))
if A+B+C+D==7:
    print("{}+{}+{}+{}=7".format(A,B,C,D))
    sys.exit()
if A+B-C+D==7:
    print("{}+{}-{}+{}=7".format(A,B,C,D))
    sys.exit()
if A+B+C-D==7:
    print("{}+{}+{}-{}=7".format(A,B,C,D))
    sys.exit()
if A+B-C-D==7:
    print("{}-{}-{}+{}=7".format(A,B,C,D))
    sys.exit()
if A-B+C+D==7:
    print("{}-{}+{}+{}=7".format(A,B,C,D))
    sys.exit()
if A-B-C+D==7:
    print("{}-{}-{}+{}=7".format(A,B,C,D))
    sys.exit()
if A-B+C-D==7:
    print("{}-{}+{}-{}=7".format(A,B,C,D))
    sys.exit()
if A-B-C-D==7:
    print("{}-{}-{}-{}=7".format(A,B,C,D))
    sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
A,B,C,D = map(int, list(input()))
if A+B+C+D==7:
    print("{}+{}+{}+{}=7".format(A,B,C,D))
    sys.exit()
if A+B-C+D==7:
    print("{}+{}-{}+{}=7".format(A,B,C,D))
    sys.exit()
if A+B+C-D==7:
    print("{}+{}+{}-{}=7".format(A,B,C,D))
    sys.exit()
if A+B-C-D==7:
    print("{}-{}-{}+{}=7".format(A,B,C,D))
if A-B+C+D==7:
    print("{}-{}+{}+{}=7".format(A,B,C,D))
    sys.exit()
if A-B-C+D==7:
    print("{}-{}-{}+{}=7".format(A,B,C,D))
    sys.exit()
if A-B+C-D==7:
    print("{}-{}+{}-{}=7".format(A,B,C,D))
    sys.exit()
    sys.exit()
if A-B-C-D==7:
    print("{}-{}-{}-{}=7".format(A,B,C,D))
    sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
A,B,C,D = map(int, list(input()))
if A+B+C+D==7:
    print("{}+{}+{}+{}=7".format(A,B,C,D))
    sys.exit()
if A-B+C+D==7:
    print("{}-{}+{}+{}=7".format(A,B,C,D))
    sys.exit()
if A+B-C+D==7:
    print("{}+{}-{}+{}=7".format(A,B,C,D))
    sys.exit()
if A+B+C-D==7:
    print("{}+{}+{}-{}=7".format(A,B,C,D))
    sys.exit()
if A-B-C+D==7:
    print("{}-{}-{}+{}=7".format(A,B,C,D))
    sys.exit()
if A-B+C-D==7:
    print("{}-{}+{}-{}=7".format(A,B,C,D))
    sys.exit()
if A-B-C+D==7:
    print("{}-{}-{}+{}=7".format(A,B,C,D))
    sys.exit()
if A-B-C-D==7:
    print("{}-{}-{}-{}=7".format(A,B,C,D))
    sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
A,B,C,D = map(int, list(input()))
if A+B+C+D==7:
    print("{}+{}+{}+{}=7".format(A,B,C,D))
    sys.exit()
if A-B+C+D==7:
    print("{}-{}+{}+{}=7".format(A,B,C,D))
    sys.exit()
if A+B-C+D==7:
    print("{}+{}-{}+{}=7".format(A,B,C,D))
    sys.exit()
if A+B+C-D==7:
    print("{}+{}+{}-{}=7".format(A,B,C,D))
    sys.exit()
if A-B-C+D==7:
    print("{}-{}-{}+{}=7".format(A,B,C,D))
    sys.exit()
if A-B+C-D==7:
    print("{}-{}+{}-{}=7".format(A,B,C,D))
    sys.exit()
if A-B-C+D==7:
    print("{}-{}-{}+{}=7".format(A,B,C,D))
    sys.exit()
if A-B-C-D==7:
    print("{}-{}-{}-{}=7".format(A,B,C,D))
    print("A-B-C-D=7")
    sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
A,B,C,D = map(int, list(input()))
if A+B+C+D==7:
    print("A+B+C+D=7")
    sys.exit()
if A-B+C+D==7:
    print("A-B+C+D=7")
    sys.exit()
if A+B-C+D==7:
    print("A+B-C+D=7")
    sys.exit()
if A+B+C-D==7:
    print("A+B+C-D=7")
    sys.exit()
if A-B-C+D==7:
    print("A-B-C+D=7")
    sys.exit()
if A-B+C-D==7:
    print("A-B+C-D=7")
    sys.exit()
if A-B-C+D==7:
    print("A-B-C+D=7")
    sys.exit()
if A-B-C-D==7:
    print("A-B-C-D=7")
    sys.exit()

Submission status: Wrong Answer

Solution code:
S = input()

N = len(S)-1

for i in range(2**N):
    binary = bin(i)
    binary = binary[2:].zfill(N)
    
    sumsum = int(S[0])
    for j in range(N):
        if binary[j] == '0':
            sumsum -= int(S[j+1])
        else:
            sumsum += int(S[j+1])
        
            
    if sumsum == 7:
        ans = S[0]
        for j in range(N):
            if binary[j] == '0':
                ans += '-'
            else:
                ans += '+'
            ans += S[j+1]
        break
    
print(ans)

Submission status: Wrong Answer

Solution code:
e = (1,-1)
a,b,c,d = map(int, list(input()))
for i in e:
  for j in e:
    for k in e:
      if a+b*i+c*j+d*k == 7:
        break
dic = {1:"+",-1:"-"}
l = [a,dic[i],b,dic[j],c,dic[k],d]
print("".join(map(str,l))+"=7")

Submission status: Wrong Answer

Solution code:
s = input()
nums = []
for i in s:
    nums.append(int(i))

for i in range(1 << (len(nums) - 1)):
    sum = nums[0]
    opes = []
    for j in range(3):
        if (i >> j) & 1:
            sum += nums[j+1]
            opes.append('+')
        else:
            sum -= nums[j+1]
            opes.append('-')
    if sum == 7:
        break

print('{0}{1}{2}{3}{4}{5}{6}=7'.format(nums[0], opes[2], nums[1], opes[1], nums[2], opes[0], nums[3]))

Submission status: Wrong Answer

Solution code:
na = lambda: input()

text = na()
num = []

for t in text:
    num.append(int(t))

ans = 0
pm = []
for a in [1,-1]:
    for b in [1,-1]:
        for c in [1,-1]:
            pm_tmp = [1]
            pm_tmp.append(a)
            pm_tmp.append(b)
            pm_tmp.append(c)
            pm.append(pm_tmp)

for p in pm:
    ans_txt = ""
    ans_num = 0
    for q in range(4):
        ans_num += num[q]*p[q]
        ans_txt += str(num[q])
        if p[q] == -1 and q != 3:
            ans_txt += "-"
        if p[q] == 1 and q != 3:
            ans_txt += "+"   
    if ans_num == 7:
        ans_txt += "=7"
        ans = ans_txt
            
print(ans)

Submission status: Wrong Answer

Solution code:
na = lambda: input()

text = na()
num = []

for t in text:
    num.append(int(t))

ans = 0
pm = []
for a in [1,-1]:
    for b in [1,-1]:
        for c in [1,-1]:
            for d in [1,-1]:
                pm_tmp = []
                pm_tmp.append(a)
                pm_tmp.append(b)
                pm_tmp.append(c)
                pm_tmp.append(d)
                pm.append(pm_tmp)

for p in pm:
    ans_txt = ""
    ans_num = 0
    for q in range(4):
        ans_num += num[q]*p[q]
        ans_txt += str(num[q])
        if p[q] == -1 and q != 3:
            ans_txt += "-"
        if p[q] == 1 and q != 3:
            ans_txt += "+"   
    if ans_num == 7:
        ans_txt += "=7"
        ans = ans_txt
            
print(ans)

Submission status: Wrong Answer

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

for op1 in op:
    ans1 = A+B if op1 == '+' else A-B
    for op2 in op:
        ans2 = ans1+C if op2 == '+' else ans2-C
        for op3 in op:
            ans3 = ans2+D if op3 == '+' else ans2-D
            #print(ans3)
            if ans3 == 7:
                print(str(A)+op1+str(B)+op2+str(C)+op3+str(D)+'=7')
                exit()

Submission status: Wrong Answer

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

for op1 in op:
    ans = A+B if op1 == '+' else A-B
    for op2 in op:
        ans = ans+C if op2 == '+' else ans-C
        for op3 in op:
            ans = ans+D if op3 == '+' else ans-D
            if ans == 7:
                print(str(A)+op1+str(B)+op2+str(C)+op3+str(D)+'=7')
                exit()

Submission status: Wrong Answer

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

def f(idx):
    return "+" if idx==0 else "-"
for i in range(2):
    for j in range(2):
        for k in range(2):
            num = a + b if i == 0 else -b
            num += c if j == 0 else -c
            num += d if k == 0 else -d

            if num == 7:
                result = str(a) + f(i) + str(b) + f(j) + str(c) + f(k) + str(d) + "=7"
                print(result)
                exit()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from itertools import product
import sys
 
def main(A, B, C, D):
    for op1, op2, op3 in product(("+", "-"), repeat=3):
        e = A + op1 + B + op2 + C + op3 + D
        print(e)
        x = eval(e)
        if x == 7:
            print(e + "=7")
            sys.exit()
    
if(__name__ == "__main__"):
    A, B, C, D = list(input())
    
    main(A, B, C, D)

Submission status: Wrong Answer

Solution code:
In = [int(x) for x in input()]
BREAK = False
for i in range(2):
  for j in range(2):
    for k in range(2):
      s = In[0]
      if i == 0:
        s += In[1]
      else:
        s -= In[1]
      if j == 0:
        s += In[2]
      else:
        s -= In[2]
      if k == 0:
        s += In[3]
      else:
        s -= In[3]
      if s == 7:
        BREAK = True
        break
    if BREAK:
      break
  if BREAK:
    break
Out = str(In[0])
m = 1
for l in [i, j, k]:
  if l % 2:
    Out += "-" + str(In[m])
  else:
    Out += "+" + str(In[m])
  m += 1
print(Out)

Submission status: Wrong Answer

Solution code:
In = [int(x) for x in input()]
BREAK = False
for i in range(2):
  for j in range(2):
    for k in range(2):
      s = In[0]
      if i == 0:
        s += In[1]
      else:
        s -= In[1]
      if j == 0:
        s += In[2]
      else:
        s -= In[2]
      if k == 0:
        s += In[3]
      else:
        s -= In[3]
      if s == 7:
        BREAK = True
        break
    if BREAK:
      break
  if BREAK:
    break
Out = str(In[0])
m = 1
for l in [i, j, k]:
  if l % 2:
    Out += "+" + str(In[m])
  else:
    Out += "-" + str(In[m])
  m += 1
print(Out)

Submission status: Wrong Answer

Solution code:
n = list(map(int,input()))
su = n[0]
for i in range(2):
    if i == 0:
        su += n[1]
        a = '+'
    else:
        su -= 2*n[1]
        a = '-'
    for j in range(2):
        if j == 0:
            su += n[2]
            aa = '+'
        else:
            su -= 2*n[2]
            aa = '-'
        for k in range(2):
            if k == 0:
                su += n[3]
                aaa = '+'
            else:
                su -= 2*n[3]
                aaa = '-'
            if su == 7:
                break
        if su == 7:
            break
    if su == 7:
        break
print(str(n[0])+a+str(n[1])+aa+str(n[2])+aaa+str(n[3])+"=7")

Submission status: Wrong Answer

Solution code:
import numpy

def main():
    a = int(input())
    a = str(a).zfill(4)
    
    A = int(a[0])
    B = int(a[1])
    C = int(a[2])
    D = int(a[3])
    
    op1 = ""
    op2 = ""
    op3 = ""
    
    for i in range(2):
        for j in range(2):
            for k in range(2):
                if A + (-1) ** (i+1) * B + (-1) ** (j+1) * C + (-1) ** (k+1) * D == 7:
                    op1 = "-" if i == 0 else "+"
                    op2 = "-" if j == 0 else "+"
                    op3 = "-" if k == 0 else "+"
                    print(str(A)+op1+str(B)+op2+str(C)+op3+str(D))
                    exit()
    
main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def func(S):
	for i in range(1 << 3):
		v = S[0]
		for j in range(3):
			v += ("+" if i >> j & 0x01 else "-") + S[j + 1]
		if eval(v) == 7:
			return v + "=7"

def main():
	print(func("1222"))
	print(func("0290"))
	print(func("3242"))
	return

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
import sys
a,b,c,d = [int(x) for x in list(input())]
if a+b+c+d ==7:
    print("a+b+c+d=7")
    sys.exit()
if a+b+c-d ==7:
    print("a+b+c-d=7")
    sys.exit()
if a+b-c+d ==7:
    print("a+b-c+d=7")
    sys.exit()
if a+b-c-d ==7:
    print("a+b-c-d=7")
    sys.exit()
if a-b+c+d ==7:
    print("a-b+c+d=7")
    sys.exit()
if a-b+c-d ==7:
    print("a-b+c-d=7")
    sys.exit()
if a-b-c+d ==7:
    print("a-b-c+d=7")
    sys.exit()
if a-b-c-d ==7:
    print("a-b-c-d=7")
    sys.exit()

Submission status: Wrong Answer

Solution code:
S = input()

def TrainTicket( S ):
    for i in range(2):
        sum = int( S[0] )
        ans = [''] * 3
        if i == 0:
            sum += int( S[1] )
            ans[0] = '+'
        else:
            sum -= int( S[1] )
            ans[0] = '-'
        for j in range(2):
            if j == 0:
                sum += int( S[2] )
                ans[1] = '+'
            else:
                sum -= int( S[2] )
                ans[1] = '-'
            for k in range(2):
                if k == 0:
                    sum += int( S[3] )
                    ans[2] = '+'
                else:
                    sum -= int( S[3] )
                    ans[2] = '-'
                if sum == 7:
                    print( S[0] + ans[0] + S[1] + ans[1] + S[2] + ans[2] + S[3] + '=7' )
                    return

TrainTicket( S )

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = input()
a,b,c,d = map(int,list(n))
op =[1,1,1]
v = ["?","+","-"]
ans = 0
for i in range(-1,2,2):
    for j in range(-1,2,2):
        for k in range(-1,2,2):
            op[0] = i
            op[1] = j
            op[2] = k
            if a+b*op[0]+c*op[1]+d*op[2] == 7:
                print("{}{}{}{}{}{}{}=7".format(a,v[op[0]],b,v[op[1]],c,v[op[2]],d))
                break

Submission status: Wrong Answer

Solution code:
n = input()
a,b,c,d = map(int,list(n))
op =[1,1,1]
v = ["?","+","-"]
ans = 0
for i in range(-1,2,2):
    for j in range(-1,2,2):
        for k in range(-1,2,2):
            op[0] = i
            op[1] = j
            op[2] = k
            if a+b*op[0]+c*op[1]+d*op[2] == 7:
                print("{}{}{}{}{}{}{}==7".format(a,v[op[0]],b,v[op[1]],c,v[op[2]],d))
                break

Submission status: Wrong Answer

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

ops = ['-', '+']
for op1 in ops:
    for op2 in ops:
        for op3 in ops:
            if eval(a+op1+b+op2+c+op3+d) == 7:
                print(a+op1+b+op2+c+op3+d+'=7')

Submission status: Wrong Answer

Solution code:
abcd = input()

def train_ticket(flg,sum,op):
    if flg == 0:
        if train_ticket(flg + 1, sum, op + "+"):
            return True
        elif train_ticket(flg + 1, sum, op + "-"):
            return True
    if flg >= len(abcd):
        if operation(sum, op[-1], flg) == 7:
            print("".join([abcd[i] + op[i+1] for i in range(len(op) - 1)]) + abcd[-1])
            return True
        else:
            return False
    if train_ticket(flg + 1, operation(sum, op[-1], flg), op+"+"):
        return True
    elif train_ticket(flg + 1, operation(sum, op[-1], flg), op+"-"):
        return True

def operation(sum, op, flg):
    if op == "+":
        return sum + int(abcd[flg - 1])
    else:
        return sum - int(abcd[flg - 1])

train_ticket(0, 0, "")

Submission status: Wrong Answer

Solution code:
ABCD = str(input())
A = int(ABCD[0])
B = int(ABCD[1])
C = int(ABCD[2])
D = int(ABCD[3])
X = ["+","-"]
def func(a,b,c):
  if(a==0):
    return b+c
  else:
    return b-c
  
for i in range(2):
  for j in range(2):
    for k in range(2):
      if(func(k,func(j,func(i,A,B),C),D)==7):
        I = i
        J = j
        K = k
        break;
              
ans = str(A)+X[I]+str(B)+X[J]+str(C)+X[K]+str(D)
print(ans)

Submission status: Wrong Answer

Solution code:
abcd = list(input())

for i in ["+","-"]:
    for j in ["+","-"]:
        for k in ["+","-"]:
            siki = abcd[0] + i + abcd[1] + j + abcd[2] + k + abcd[3]
            if eval(siki) == 7:
                print(siki + "=7")

Submission status: Wrong Answer

Solution code:
line=str(input())
line=list(line)
line=list(map(int,line))
a=line[0]
b=line[1]
c=line[2]
d=line[3]
o1='+'
o2='+'
o3='+'
for x in (a+b,a-b):
  for y in (c,-c):
    for z in (d,-d):
      if x+y+z==7:
        if x==a-b:
          o1='-'
        if y==-c:
          o2='-'
        if z==-d:
          o3='-'
print("{}{}{}{}{}{}{}=7".format(a,o1,b,o2,c,o3,d))