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:
from itertools import product
def calc_appropriate_op(a, b, c, d):
  """
  calc op1, op2, op3 that satisfies 'a(op1)b(op2)c(op3)d = 7'
  Args:
    a, b, c, d (str)
  Returns:
    list (str) 
  """
  for pattern in product(['+', '-'], repeat=3):
    if eval(a+pattern[0]+b+pattern[1]+c+pattern[2]+d) == 7:
      return pattern
  



s = input()
a, b, c, d = s
op_list = calc_appropriate_op(a, b, c, d)
print("{}{}{}{}{}{}{}=7".format(a, op_list[0], b, op_list[1], c, op_list[2], d))

Submission status: Accepted

Solution code:
s=input()
n=len(s)
l=[]
for i in s:
  l.append(int(i))
for i in range(2 ** n):
    check = []
    for j in range(n):
      if ((i >> j) & 1):  
        check.append(l[j]) 
      else:
        check.append(-l[j])         
    if sum(check)==7:
      print(str(check[0]), end="")           
      for i in range(1, n):
        if check[i]>=0:
          print("+"+str(check[i]), end="")
        else:
          print(str(check[i]), end="")
      print("=7")
      exit()

Submission status: Accepted

Solution code:
s = input()
n = len(s) - 1
for i in range(2**n):
    tmp = []
    for j in range(n):
        tmp.append(s[j])
        if i >> j & 1:
            tmp.append("+")
        else:
            tmp.append("-")
    tmp.append(s[-1])
    if eval("".join(tmp)) == 7:
        print("".join(tmp) + "=7")
        exit()

Submission status: Accepted

Solution code:
s = input()
n = len(s)
for i in range(2**(n-1)):
    op = ["-"] * (n-1)
    for j in range(n-1):
        if (i >> j) & 1:
            op[n - 2 -j] = "+"
    #print(op)
    chk = ""
    for p_n, p_o in zip(s, op + [""]):
        chk += (p_n + p_o)
    if eval(chk) == 7:
        print(chk + "=7")
        exit()

Submission status: Accepted

Solution code:
s = list(map(int,list(input())))
a = s.pop(0)

bit_n = 3
for i in range(2**bit_n):
    sign = ['+']*3
    tmp = a
    for j in range(bit_n):
        if ((i>>j)&1):
            tmp+=s[j]
        else:
            tmp-=s[j]
            sign[j]='-'
    if tmp==7:
        print("{0}{1[0]}{2[0]}{1[1]}{2[1]}{1[2]}{2[2]}=7".format(a,sign,s));exit()

Submission status: Accepted

Solution code:
s = input()
res_list = ['-', '-', '-']
for i in range(8):
    res = s[0]
    for j in range(3):
        if (i >> j) &1:
            res += '+'
        else:
            res += '-'
        res += s[j+1]
    if eval(res) == 7:
        print(res + '=7')
        exit()

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')
elif A - B - C - D == 7:
  print(S[0] + '-' + S[1] + '-' + S[2] + '-' + S[3] + '=' + '7')
elif A + B - C - D == 7:
  print(S[0] + '+' + S[1] + '-' + S[2] + '-' + S[3] + '=' + '7')
elif A - B + C + D == 7:
  print(S[0] + '-' + S[1] + '+' + S[2] + '+' + S[3] + '=' + '7')
elif A - B - C + D == 7:
  print(S[0] + '-' + S[1] + '-' + S[2] + '+' + S[3] + '=' + '7')
elif A - B + C - D == 7:
  print(S[0] + '-' + S[1] + '+' + S[2] + '-' + S[3] + '=' + '7')
elif A + B - C + D == 7:
  print(S[0] + '+' + S[1] + '-' + S[2] + '+' + S[3] + '=' + '7')
elif A + B + C - D == 7:
  print(S[0] + '+' + S[1] + '+' + S[2] + '-' + S[3] + '=' + '7')

Submission status: Accepted

Solution code:
n = list(input())
op = ['+', '-']
for i in range(8):
    bin_i = bin(i).replace('0b', '').zfill(3)
    
    tmp = int(n[0])
    for j in range(3):
        if bin_i[j] == '0':
            tmp = tmp + int(n[j+1])
        else:
            tmp = tmp - int(n[j+1])
    if tmp == 7:
        ans = n[0] + op[int(bin_i[0])] + n[1] + op[int(bin_i[1])] + n[2] + op[int(bin_i[2])] + n[3]
        print(ans+'=7')
        break

Submission status: Accepted

Solution code:
c,*s=input()
n=len(s)
for b in range(1<<n):
    t = c + ""
    for i in range(n):
        t += ["-","+"][b>>i & 1] + s[i]
    if eval(t) == 7:
        print(t+"=7")
        exit()

Submission status: Accepted

Solution code:
A, B, C, D = list(map(int, list(input())))
ops = ['+', '-']
for i in range(2):
  for j in range(2):
    for k in range(2):
      if A + ((-1)**i)*B + ((-1)**j)*C + ((-1)**k)*D == 7:
        ans = str(A) + ops[i] + str(B) + ops[j] + str(C) + ops[k] + str(D) + '=7'
        print(ans)
        quit()

Submission status: Accepted

Solution code:
def Ans(x, y, z, w):
  if(x+ y+ z+ w == 7):
    return "{}+{}+{}+{}=7".format(x, y, z, w)
  elif(x- y+ z+ w == 7):
    return "{}-{}+{}+{}=7".format(x, y, z, w)
  elif(x- y- z+ w == 7):
    return "{}-{}-{}+{}=7".format(x, y, z, w)
  elif(x- y+ z- w == 7):
    return "{}-{}+{}-{}=7".format(x, y, z, w)
  elif(x+ y- z- w == 7):
    return "{}+{}-{}-{}=7".format(x, y, z, w)
  elif(x+ y- z+ w == 7):
    return "{}+{}-{}+{}=7".format(x, y, z, w)
  elif(x+ y+ z- w == 7):
    return "{}+{}+{}-{}=7".format(x, y, z, w)
  elif(x- y- z- w == 7):
    return "{}-{}-{}-{}=7".format(x, y, z, w)


ABCD = input()
N = list(ABCD)

x = int(N.pop(0))
y = int(N.pop(0))
z = int(N.pop(0))
w = int(N.pop(0))

ans = Ans(x, y, z, w)
print(ans)

Submission status: Accepted

Solution code:
lst = list(input())
n = len(lst)

for i in range(2 ** (n - 1)):
    l = [lst[0]]
    for j in range(n - 1):
        if i >> j & 1:
            l.append("+")
        else:
            l.append("-")
        l.append(lst[j + 1])

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

Submission status: Accepted

Solution code:

ns=input()

for i in range(2**(len(ns))):
    ops=["+"]*(len(ns)-1)
    for j in range(len(ops)):
        if((i>>j)&1):
            ops[j]="-"
            
    siki=""
    for x,y in zip(ns,ops+[""]):
        siki+=x+y
        
    if eval(siki)==7:
        print(siki+"=7")
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:

inp = int(input())


a = int(inp / 1000)
b = int((inp % 1000)/100)
c = int((inp % 100)/10)
d = int((inp % 10))
'''

d = inp % 10
inp //= 10

c = inp % 10
inp //= 10

b = inp % 10
inp //= 10

a = inp % 10
inp //= 10
'''

pm = 8
total = a


for i in range(8):
    total = a
    siki = str(a)
    if(i & 1):
        total += b
        siki += '+' +str(b)
    elif((i&1) != 1):
        total -= b
        siki += '-' +str(b)

    if((i>>1) &1 ):
        total += c
        siki += '+' +str(c)
    else:
        total -= c
        siki += '-' +str(c)

    if((i>>2) &1):
        total += d
        siki += '+' +str(d)
    else:
        total -= d
        siki += '-' +str(d)

    if (total == 7):
        siki += "=7"
        print(siki)
        quit()

Submission status: Accepted

Solution code:
n = input()

for i in range(2 ** 3):
    l = n[0]
    for j in range(3):
        if (i >> j) & 1 == 1:
            l += '+'
        else:
            l += '-'
        l += n[j + 1]
    if eval(l) == 7:
        print(l, '=7', sep = '')
        exit()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a, b, c, d = list(input())
pm = ['+', '-']
s = []
for i in pm:
    for j in pm:
        for k in pm:
            s.append(a + i + b + j + c + k + d)

for i in s:
  if eval(i) == 7:
    print(i + '=7')
    exit()

Submission status: Accepted

Solution code:
import itertools,sys
def S(): return sys.stdin.readline().rstrip()
A,B,C,D = [x for x in S()]
for op1,op2,op3 in itertools.product(['+','-'],repeat=3):
    ans = A+op1+B+op2+C+op3+D
    if eval(ans)==7:
        print(ans+'=7')
        break

Submission status: Accepted

Solution code:
import itertools,sys
def S(): return sys.stdin.readline().rstrip()
A,B,C,D = [x for x in S()]
for op1,op2,op3 in itertools.product(['+','-'],repeat=3):
    ans = A+op1+B+op2+C+op3+D
    if eval(ans)==7:
        print(*[ans,'=7'],sep='')
        break

Submission status: Accepted

Solution code:
import itertools,sys
def S(): return sys.stdin.readline().rstrip()
A,B,C,D = [x for x in S()]
for op1,op2,op3 in itertools.product(['+','-'],repeat=3):
    if eval('{}{}{}{}{}{}{}'.format(A,op1,B,op2,C,op3,D))==7:
        print(*[A,op1,B,op2,C,op3,D,'=7'],sep='')
        break

Submission status: Accepted

Solution code:
N = list(int(i) for i in input())
A = []
for i in range(2):
    for j in range(2):
        for k in range(2):
            x = N[0]
            if i == 0:
                x += N[1]
            else:
                x -= N[1]

            if j == 0:
                x += N[2]
            else:
                x -= N[2]

            if k == 0:
                x += N[3]
            else:
                x -= N[3]
            if x == 7:
                A.append(i)
                A.append(j)
                A.append(k)
                break
ans = str(N[0])
for l in range(3):
    if A[l] == 0:
        ans += "+"
    else:
        ans += "-"
    ans += str(N[l+1])
ans += "=7"
print(ans)

Submission status: Accepted

Solution code:
s = input()
abcd = []
op = []
for i in range(2**3):
  tmp = ['-'] * 3
  for j in range(3):
    if i >> j & 1:
      tmp[j] = "+"
  op.append(tmp)
#print(op)
s_ = []
for i in range(4):
  if(i == 3):
    s_.append(s[i])
    break
  s_.append(s[i])
  s_.append(" ")

for i in range(len(op)):
  tmp = s_
  tmp[1::2] = op[i]
  temp = ''.join(tmp)
  ans = eval(temp)
  #print(ans)
  if(ans == 7):
    ss = temp + "=7"
    print(ss)
    break

Submission status: Accepted

Solution code:
a,b,c,d=map(int,list(input()))
 
lis=[[i,-i] for i in [b,c,d]]
#print(lis)
for i in range(8):
    sam=[a]
    #print(sam)
    for j in range(3):
        boolen=((i>>j)&1)
        sam.append(lis[j][int(boolen)])
    #print(sam)
    if sum(sam)==7:
        #print(sam)
        dis=[str(sam[0])]
        for num in sam[1:]:
            if num>=0:
                dis.append('+'+str(num))
            else:
                dis.append(str(num))
        print('%s%s%s%s=7'%(dis[0],dis[1],dis[2],dis[3]))
        break

Submission status: Accepted

Solution code:
a, b, c, d = input()
for x in "+-":
	for y in "+-":
		for z in "+-":
			f = a + x + b + y + c + z + d
			if eval(f) == 7:
				print(f + "=7")
				exit()

Submission status: Accepted

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

for i in range(2):
	for j in range(2):
		for k in range(2):
			x = a + b*(-1)**i + c*(-1)**j + d*(-1)**k
			if x == 7:
				print(a, end='')
				print('-' if i else '+', end='')
				print(b, end='')
				print('-' if j else '+', end='')
				print(c, end='')
				print('-' if k else '+', end='')
				print(d, end='')
				print("=7")
				exit()

Submission status: Accepted

Solution code:
n=list(input())
for i in range(1<<3):
    cnt=int(n[0])
    l=[n[0]]
    for j in range(3):
        if (i>>j)%2==1:
            cnt+=int(n[j+1])
            l+="+"+n[j+1]
        else:
            cnt-=int(n[j+1])
            l+="-"+n[j+1]
    if cnt==7:
        print("".join(l)+"=7")
        break

Submission status: Accepted

Solution code:
from itertools import product
 
S = input()
 
patterns = list(product(["-","+"],repeat=len(S)-1))
 
ans = []

for pattern in patterns:
    cnt = 0
    num = ""
    for i in range(len(pattern)+1):
        if i == 0:
            cnt += int(S[i])
            num = num + S[i]
        else:
            if pattern[i-1] == "+":
                cnt += int(S[i])
                num = num + pattern[i-1] + S[i]
            else:
                cnt -= int(S[i])
                num = num + pattern[i-1] + S[i]
    if cnt == 7:
        print(num+"=7")
        break;

Submission status: Accepted

Solution code:
s=input()
s=list(s)
for i in range(2**3):
  temp=[0]*3
  for j in range(3):
    if ((i >> j) & 1):
      temp[j]="+"
    else:
      temp[j]="-"
  a=[s[0],temp[0],s[1],temp[1],s[2],temp[2],s[3]]
  if eval("".join(a))==7:
    print("".join(a)+"=7")
    break

Submission status: Accepted

Solution code:
n = input()
op_cnt = len(n) - 1  
for i in range(2 ** op_cnt):
    op = ["-"] * op_cnt 
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt - 1 - j] = "+"  
    formula = ""
    for p_n, p_o in zip(n, op + [""]): 
        formula += (p_n + p_o)
    if eval(formula) == 7:
        print(formula + "=7")
        break

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc079/tasks/abc079_c

num = list(input())

for i in range(2 ** 3):
    t = int(num[0])
    op = []
    for j in range(3):
        if (i >> j) & 1:
            t += int(num[j + 1])
            op.append('+')
        else:
            t -= int(num[j + 1])
            op.append('-')
    op.append('=')
    if t == 7:
        ans = []
        for i, j in zip(num, op):
            ans.append(i)
            ans.append(j)
        print(''.join(ans) + '7')
        break

Submission status: Accepted

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

n = 3
pt = []
for i in range(2 ** n):
  tmp = ["+"] * n
  for j in range(n):
    if i >> j & 1:
      tmp[j] = "-"
  pt.append(tmp)
for x in pt:
  fr = a + x[0] + b + x[1] + c+ x[2] + d 
  if eval(fr) == 7 :
    print(fr+"=7")
    exit()

Submission status: Accepted

Solution code:
import sys
s = input()
def bfs(exp,idx):
    if idx == 3:
        ev = eval(exp+s[idx])
        if ev == 7:
            print(exp+s[idx]+"=7")
            sys.exit(0)
        return False
    exp += s[idx]
    for op in ["+", "-"]:
        bfs(exp+op, idx+1)
bfs("",0)

Submission status: Accepted

Solution code:
def main():
    from itertools import product

    a, b, c, d = input()

    for prd in product('+-', repeat=3):
        op1, op2, op3 = prd
        f = a + op1 + b + op2 + c + op3 + d
        if eval(f) == 7:
            print('{}=7'.format(f))
            return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for op1 in PM:
  if op1 == '-':
    b = -B
  else:b = B
  for op2 in PM:
    if op2 == '-':
      c = -C
    else:c = C
    for op3 in PM:
      if op3 == '-':
        d = -D
      else:d = D
      if A+b+c+d==7:
        print(S[0]+op1+S[1]+op2+S[2]+op3+S[3]+'=7')
        exit()

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

S = input()
op = ["+", "-"]

def exec():
    for a in op:
        for b in op:
            for c in op:
                exp = S[0:1] + a + S[1:2] + b + S[2:3] + c + S[3:4]
                if eval(exp) == 7:
                    return exp + "=7"

print(exec())

Submission status: Accepted

Solution code:
import sys
s = input()
for bit in range(1 << len(s)-1):
  res = s[0]
  for i in range(len(s)-1):
    if bit & (1<<i):
      res += '+'
    else:
      res += '-'
    res += s[i+1]
  if eval(res) == 7:
    print(res+'=7')
    sys.exit()

Submission status: Accepted

Solution code:
n = input()

op_cnt = len(n) -1
for i in range(2**op_cnt):
    op = ["-"] * op_cnt
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt -1 -j] = "+"
    
            
    formula = ""
    for p_n,p_o in zip(n, op + [""]):
        formula += (p_n + p_o)
    if eval(formula) == 7:
        s = formula+"=7"
        print(s)
        break

Submission status: Accepted

Solution code:
S = input()

for n in range(1 << 3):
    s = S
    for i in range(3):
        if (n >> i) & 1 == 1:
            op = "+"
        else:
            op = "-"
        s = s[:2*i+1] + op + s[2*i+1:]
    if eval(s) == 7:
        ans = s + "=7"
        break

print(ans)

Submission status: Accepted

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

m = ["+","-"]

for i in m:
    for j in m:
        for k in m:
            a = eval(A+i+B+j+C+k+D)
            if a == 7:
                print(A+i+B+j+C+k+D+"=7")
                exit()

print()

Submission status: Accepted

Solution code:
A=input()
n=3

for i in range(2**n):
    result=A[0]
    result_sum=int(A[0])
    for j in range(n):
        if (i>>j)&1:
            result=result+"-"+A[j+1]
            result_sum-=int(A[j+1])
        else:
            result=result+"+"+A[j+1]
            result_sum+=int(A[j+1])
    if result_sum==7:
        print(result+"=7")
        exit()

Submission status: Accepted

Solution code:
s = list(input())
l = len(s)

for bit in range((l-1)**2):
    ans_sum = int(s[0])
    ans_str = s[0]
    for i in range(l-1):
        if (bit >> i) & 1:
            ans_sum += int(s[i+1])
            ans_str += '+'
        else:
            ans_sum -= int(s[i+1])
            ans_str += '-'
        ans_str += s[i+1]
    if ans_sum == 7:
        print(ans_str+'=7')
        exit(0)

Submission status: Accepted

Solution code:
S=input()
for i in range(8):
  formula=S[0]
  q="{:0>4b}".format(i)[::-1]
  for j in range(1,4):
    if int(q[j-1])&1:
      formula+="+"
    else:
      formula+="-"
    formula+=S[j]
  if eval(formula)==7:
    print(formula+"=7")
    exit()

Submission status: Accepted

Solution code:
_ = '_'

arr = []

def solve(s):
    if _ in s:
        solve(s.replace(_, "+", 1))
        solve(s.replace(_, "-", 1))

    else:
        if eval(s) == 7:
            print(s + '=7')
            exit()


solve(_.join(list(input())))

Submission status: Accepted

Solution code:
n = input()
op_cnt = len(n) - 1  # 隙間の個数
for i in range(2 ** op_cnt):
    op = ["-"] * op_cnt  # 予め、["-", "-", "-"]というリストを作っておく
    for j in range(op_cnt):
        if (i >> j) & 1:  # 順に右シフトさせ、最下位bitが1かどうか確認
            op[op_cnt - 1 - j] = "+"  # フラグが立っていた箇所を"+"で上書き
    formula = ""
    for p_n, p_o in zip(n, op + [""]):
        formula += (p_n + p_o)
    if eval(formula) == 7:
        print(formula + "=7")
        break

Submission status: Accepted

Solution code:
n = [i for i in input()]
length = len(n) -1

for i in range(2 ** length):
    ops = ['-'] * length
    for j in range(length):
        if (i >> j) & 1:
            ops[length - 1 - j] = '+'
    
    formula = str()
    for num , op in zip(n, ops + ['']):
        formula += (num + op)
    
    if eval(formula) == 7:
        print(formula+'=7')
        break

Submission status: Accepted

Solution code:
# C - Train Ticket
from itertools import product
S = input()
n = len(S)-1
total =0
for i in list(product(["-","+"],repeat=n)):
    bag=""
    for ind,val in enumerate(S):
        if ind ==0:
            bag+=val
        else:
            bag+=i[ind-1]+val
    if eval(bag)==7:
        print(bag+"=7")
        exit()

Submission status: Accepted

Solution code:
s = input()
num = 2 ** (len(s) - 1)
for i in range(num):
  x = ''
  for index, value in enumerate(s):
    x += value
    if index == (len(s) - 1):
      break
    if (i>>index) & 1:
      x += '+'
    elif ~((i>>index) & 1):
      x += '-'
      
  if eval(x) == 7:
    break
x += '=7'
print(x)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from itertools import product

def main():
    abcd = input()
    a = abcd[0]
    b = abcd[1]
    c = abcd[2]
    d = abcd[3]

    p = product(('+','-'), repeat = 3)
    for ep in p:
        siki = "".join([a,ep[0],b,ep[1],c,ep[2],d])
        if eval(siki) == 7:
            r = siki + "=7"
            print(r)
            sys.exit()

if __name__ == '__main__':
    main()

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 = str(input())
n = [int(i) for i in ABCD]
#ABCD = '0290'
#n = [0,2,9,0]

ans = ''

for i in range(2**3):

  x = format(i,'b').zfill(3)
  c = n[0]

  for j in range(1,4):
    if x[j-1] == '0':
      c += n[j]
    else :
      c -= n[j]
 
  if c == 7:
    ans = x
    break

ans = ans.replace('0','+')
ans = ans.replace('1','-')

out = ABCD[0]+ans[0]+ABCD[1]+ans[1]+ABCD[2]+ans[2]+ABCD[3]+'=7'
print(out)

Submission status: Accepted

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

r = A + B + C + D
if r == 7:
    print('{}+{}+{}+{}=7'.format(A, B, C, D))
    exit()
while True:
    if A + B + C - D == 7:
        print('{}+{}+{}-{}=7'.format(A, B, C, D))
        exit()
    elif A + B - C - D == 7:
        print('{}+{}-{}-{}=7'.format(A, B, C, D))
        exit()
    elif A - B - C - D == 7:
        print('{}-{}-{}-{}=7'.format(A, B, C, D))
        exit()
    elif A - B + C - D == 7:
        print('{}-{}+{}-{}=7'.format(A, B, C, D))
        exit()
    elif A - B - C + D == 7:
        print('{}-{}-{}+{}=7'.format(A, B, C, D))
        exit()
    elif A + B - C + D == 7:
        print('{}+{}-{}+{}=7'.format(A, B, C, D))
        exit()
    elif A - B + C + D == 7:
        print('{}-{}+{}+{}=7'.format(A, B, C, D))
        exit()
    exit()

Submission status: Accepted

Solution code:
num = list(input())
n = len(num) - 1

for i in range(2**n):
    temp = [0]*(len(num)+n)
    lst = ["-"]*n
    for j in range(n):
        if i&(1<<j):
            lst[j] = "+"
    temp[::2] = num
    temp[1::2] = lst
    wa = eval("".join(temp[:]))
    if wa == 7:
        print("".join(temp[:]) + "=7")
        exit()

Submission status: Accepted

Solution code:
s = input()

f = 0

for bit in range(1 << 3):
    ans = s[0]
    f = int(s[0])
    for i in range(3):
        if bit&(1 << i):
            f += int(s[i+1])
            ans += "+"
        else:
            f -= int(s[i+1])
            ans += "-"
        ans += s[i+1]
        
    if f == 7:
        ans += "=7"
        print(ans)
        break

Submission status: Accepted

Solution code:
def resolve():
    # 整数 1 つ
    n = str(input())
    # 整数複数個
    # a, b = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    N = [int(n[i]) for i in range(len(n))]
    Dic = {1:"+", -1:"-"}

    flag = False
    for i in [-1, 1]:
        for j in [-1, 1]:
            for k in [-1, 1]:
                if N[0] + (i * N[1]) + (j * N[2]) + (k * N[3]) == 7:
                    print(str(N[0]) + Dic[i] + str(N[1]) + Dic[j] + str(N[2]) + Dic[k] + str(N[3]) + "=7")
                    flag = True
                    break
            if flag == True:
                break
        if flag == True:
            break

resolve()

Submission status: Accepted

Solution code:
N = int(input())
A = N//1000
B = (N%1000)//100
C = (N%100)//10
D = N%10
opdict = {-1:'-', 1:'+'}
for op1 in (-1, 1):
  for op2 in (-1, 1):
    for op3 in (-1, 1):
      if op1*B + op2*C + op3*D == 7 - A:
        print(str(A)+opdict[op1]+str(B)+opdict[op2]+str(C)+opdict[op3]+str(D)+'=7')
        exit()

Submission status: Accepted

Solution code:
x = str(input())
l = [x[0], x[1], x[2], x[3]]
m = [int(s) for s in l]
N = 2 ** 3
for i in range(N):
  n = [m[0], 0, 0, 0]
  o = [] # +か-かを記憶
  for j in range(3):
    if (i >> j) & 1:
      n[-j-1] = -m[-j-1]
      o.append('-')
    else:
      n[-j-1] = m[-j-1]
      o.append('+')
  if sum(n) == 7:
    print(str(m[0]) + o[2] + str(m[1]) + o[1] + str(m[2]) + o[0] + str(m[3]) + '=7')
    exit()

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

for i in range(8):
    op=['-']*3
    for j in range(3):
        if (i>>j)&1:
            op[j]='+'
    if eval(abcd[0]+op[0]+abcd[1]+op[1]+abcd[2]+op[2]+abcd[3])==7:
        print(abcd[0]+op[0]+abcd[1]+op[1]+abcd[2]+op[2]+abcd[3]+'=7')
        break

Submission status: Accepted

Solution code:
a=input()
List=list(a)
n=len(List)

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

    formula=''

    for num,sign in zip(List,s):
        formula += (num + sign)
    formula += List[n-1]

    if eval(formula)==7:
        print(formula+'=7')
        break

Submission status: Accepted

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

import copy

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

for i in range(2 ** (len(abcd)-1)):
    abcd_c = copy.deepcopy(abcd)
    for j in range(len(abcd)-1):
        if (i >> j) & 1:
            abcd_c[j+1]*=-1
    if sum(abcd_c) == 7:
        break

for i, v in enumerate(abcd_c):
    if i > 0 and v >= 0:
        print('+', end='')
    print(v, end='')
print('=7')

Submission status: Accepted

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-

S = input()
ABCD = [int(S[0])]
ABCD.append(int(S[1]))
ABCD.append(int(S[2]))
ABCD.append(int(S[3]))

item = ["+","-"]

for i in range(2**3):

    ans = ABCD[0]
    op = []

    for j in range(0,3):
        if ((i >> j) & 1):
            ans += ABCD[j+1]
            op.append("+")
        else:
            ans -= ABCD[j+1]
            op.append("-")

    if ans == 7:
        print(str(ABCD[0])+op[0]+str(ABCD[1])+op[1]+str(ABCD[2])+op[2]+str(ABCD[3])+"=7")
        break

Submission status: Accepted

Solution code:
s = list(input())
op = ['+', '-']
for op1 in op:
    for op2 in op:
        for op3 in op:
            ans = s[0]+op1+s[1]+op2+s[2]+op3+s[3]
            if eval(ans) ==7:
                print(ans + '=7')
                exit()

Submission status: Accepted

Solution code:
# AtCoder
s = list(map(str, input()))
n = len(s)

for i in range(2**3):  # 2の選ぶものの個数乗
    ops = []
    for j in range(3):
        if ((i >> j) & 1):
            ops.append('+')
        else:
            ops.append('-')
    if eval(s[0]+ops[0]+s[1]+ops[1]+s[2]+ops[2]+s[3]) == 7:
        print(s[0]+ops[0]+s[1]+ops[1]+s[2]+ops[2]+s[3] + '=7')
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = input()
for i in range(2 ** 3):
    result = int(n[0])
    formura = n[0]
    for j in range(3):  
        if ((i >> j) & 1): 
            result -= int(n[j+1])
            formura += "-"+n[j+1]
        else:
            result += int(n[j+1])
            formura += "+"+n[j+1]
    
    if result == 7:
        print(formura+"=7")
        break

Submission status: Accepted

Solution code:
a = list(input())

for i in range(8):
    cou = int(a[0])
    ans = a[0]
    for j in range(3):
        if i >> j & 1 == 1:
            cou += int(a[j+1])
            ans += "+" + a[j+1]
        elif i >> j & 1 != 1:
            cou -= int(a[j+1])
            ans += "-" + a[j+1]
    if cou == 7:
        print(ans + "=7")
        exit()

Submission status: Accepted

Solution code:
s_list = str(input())
A, B, C, D = [int(s) for s in s_list ]
for x in range(2):
    if x==0:
        X = A + B
        px = '+'
    else:
        X = A - B
        px = '-'
    for y in range(2):
        if y==0:
            Y = X + C
            py = '+'
        else:
            Y = X - C
            py = '-'
        for z in range(2):
            if z==0:
                Z = Y + D
                pz = '+'
            else:
                Z = Y - D
                pz = '-'
                
            if Z==7:
                print(A, px, B, py, C, pz, D, '=7', sep='')
                exit()

Submission status: Accepted

Solution code:
s = input()


def dfs(i, f):
    if i == 3:
        if eval(f) == 7:
            print(f+'=7')
            exit()
    else:
        dfs(i+1, f+'+' + s[i+1])
        dfs(i+1, f+'-' + s[i+1])


dfs(0, s[0])