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

for i1 in range(2):
  for i2 in range(2):
    for i3 in range(2):
      if i1 == 0 and i2 == 0 and i3 == 0:
        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 i1 == 0 and i2 == 0 and i3 == 1:
        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 i1 == 0 and i2 == 1 and i3 == 0:
        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 i1 == 0 and i2 == 1 and i3 == 1:
        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 i1 == 1 and i2 == 0 and i3 == 0:
        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 i1 == 1 and i2 == 0 and i3 == 1:
        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 i1 == 1 and i2 == 1 and i3 == 0:
        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 i1 == 1 and i2 == 1 and i3 == 1:
        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()

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("{0}+{1}+{2}+{3}=7".format(a,b,c,d))
elif a+b+c-d==7:
    print("{0}+{1}+{2}-{3}=7".format(a,b,c,d))
elif a+b-c+d==7:
    print("{0}+{1}-{2}+{3}=7".format(a,b,c,d))
elif a+b-c-d==7:
    print("{0}+{1}-{2}-{3}=7".format(a,b,c,d))
elif a-b+c+d==7:
    print("{0}-{1}+{2}+{3}=7".format(a,b,c,d))
elif a-b+c-d==7:
    print("{0}-{1}+{2}-{3}=7".format(a,b,c,d))
elif a-b-c+d==7:
    print("{0}-{1}-{2}+{3}=7".format(a,b,c,d))
elif a-b-c-d==7:
    print("{0}-{1}-{2}-{3}=7".format(a,b,c,d))

Submission status: Accepted

Solution code:
n = input()
op = ["-", "+"]

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

Submission status: Accepted

Solution code:
from itertools import zip_longest
s = input()
gotResult = False
# 2^n通り探索
for i in range(2**(len(s) - 1)):
  n = ['+'] * (len(s) - 1)
  formula = ""
  for j in range(len(s) - 1):
    if (i>>j)&1:
      n[len(s) - 1 - 1 - j] = '-'
  for num,op in zip_longest(s,n):
      formula += num if op == None else num + op
  if eval(formula) == 7:
    print(formula + '=' + str(eval(formula)))
    gotResult = True
    break
  if gotResult:
    break

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
a = input()
alst = [0, 1]
blst = [0, 1]
clst = [0, 1]
ans = ''
for i in alst:
    for j in blst:
        for k in clst:
            tmp = 0
            ans = ''
            if i == 0:
                tmp = int(a[0]) + int(a[1])
                ans = a[0] + '+' + a[1]
            else:
                tmp = int(a[0]) - int(a[1])
                ans = a[0] + '-' + a[1]
            if j == 0:
                tmp = tmp + int(a[2])
                ans = ans + '+' + a[2]
            else:
                tmp = tmp - int(a[2])
                ans = ans + '-' + a[2]
            if k == 0:
                tmp = tmp + int(a[3])
                ans = ans + '+' + a[3]
            else:
                tmp = tmp - int(a[3])
                ans = ans + '-' + a[3]
            if tmp == 7:
                print(ans + '=7')
                sys.exit()

Submission status: Accepted

Solution code:
a, b, c, d = input()
kigou = ["+", "-"]
for i in range(8):
    bin_str = str(format(i, 'b').rjust(10, '0'))
    soeji_01 = int(bin_str[-1])
    soeji_02 = int(bin_str[-2])
    soeji_03 = int(bin_str[-3])
    shiki = "" + a + kigou[soeji_01] + b + \
        kigou[soeji_02] + c + kigou[soeji_03] + d
    if eval(shiki) == 7:
        print(shiki+"=7")
        exit()

Submission status: Accepted

Solution code:
def conv(c): return '+' if c==1 else '-'
def main():
	num = [int(c) for c in input()]
	choices = [-1,1]
	for a in choices:
		for b in choices:
			for c in choices:
				if num[0]+num[1]*a+num[2]*b+num[3]*c==7:
					print("{}{}{}{}{}{}{}=7".format(num[0],conv(a),num[1],conv(b),num[2],conv(c),num[3]))
					return
main()

Submission status: Accepted

Solution code:
from itertools import product

S = list(input())
a = list(product(['+','-'],repeat=3))

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

Submission status: Accepted

Solution code:
N = input()

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


dfs(0,N[0])

Submission status: Accepted

Solution code:
def main():
    abcd = input()
    n = len(abcd)
    for i in range(2**(n-1)):
        num = ""
        # print(i)
        for j in range(n):
            num += abcd[j]
            if j < n-1:
                if (i >> j) & 1:
                    num += "-"
                else:
                    num += "+"
        if eval(num) == 7:
            print(num+"=7")
            exit()


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
ABCD = input()

for i in range(1<<3):
    t = ABCD[0]
    for j in range(3):
        t += "+" if (i>>j)%2 else "-"
        t += ABCD[j+1]
    if eval(t) == 7:
        print(t+"=7")
        exit()

Submission status: Accepted

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

patterns = ['000', '001', '010', '011', '100', '101', '110', '111']

rem = ''

for pattern in patterns:
    S=A[0]
    for i, s in enumerate(pattern):
        if int(s):S+=A[i+1]
        else:S-=A[i+1]
    if S==7:
        rem = pattern
        break

pattern = pattern.replace('0','-').replace('1', '+')
lst = []
for i, j in zip(A, pattern):
    lst.append(i)
    lst.append(j)
lst.append(A[3])
lst.append('=7')
print(*lst,sep='')

Submission status: Accepted

Solution code:
import sys

a, b, c, d = list(input())
ops = ['+', '-']
for op1 in ops:
    for op2 in ops:
        for op3 in ops:
            expr = ''.join([a, op1, b, op2, c, op3, d])
            if eval(expr) == 7:
                print(expr + '=7')
                sys.exit()

Submission status: Accepted

Solution code:
# ABC079 C - Train Ticket
import itertools
s = input()
a = s[0:1]
b = s[1:2]
c = s[2:3]
d = s[3:4]

OP = ('+','-')

for op in itertools.product(OP,repeat=3):
    op1,op2,op3 = op
    t = int(a)
    if op1 == '+':
        t += int(b)
    elif op1 == '-':
        t -= int(b)

    if op2 == '+':
        t += int(c)
    elif op2 == '-':
        t -= int(c)

    if op3 == '+':
        t += int(d)
    elif op3 == '-':
        t -= int(d)
    if t == 7:
        print(a+op1+b+op2+c+op3+d+'=7')
        break

Submission status: Accepted

Solution code:
import itertools
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        A, B, C, D = map(int, list(input().rstrip()))
        op = ['+', '-']
        for op1, op2, op3 in itertools.product(op, op, op):
            AB = A + B if op1 == '+' else A - B
            ABC = AB + C if op2 == '+' else AB - C
            ABCD = ABC + D if op3 == '+' else ABC - D
            if ABCD == 7:
                print('{a}{op1}{b}{op2}{c}{op3}{d}=7'.format(a=A, b=B, c=C, d=D, op1=op1, op2=op2, op3=op3))
                exit()


# Run main
if __name__ == '__main__':
    AtCoder().main()

Submission status: Accepted

Solution code:
calcNum = [1, -1]
calcSign = ["+", "-"]
n = list(input())
for a in range(2):
    for b in range(2):
        for c in range(2):
            if int(n[0]) + calcNum[a] * int(n[1]) + calcNum[b] * int(n[2]) + calcNum[c] * int(n[3]) == 7:
                string = n[0] + calcSign[a] + n[1] + \
                    calcSign[b] + n[2] + calcSign[c] + n[3] + "=7"

print(string)

Submission status: Accepted

Solution code:
s = input()
N = len(s)
s_num = [int(i) for i in s]
for i in range(2**(N-1)):
    x = []
    value = s_num[0]
    for j in range(N-1):
        if (i >> j) & 1:
            x.append('+')
            value += s_num[j+1]
        else:
            x.append('-')
            value -= s_num[j+1]
    if value == 7:
        fomula = ''
        for k in range(N-1):
            fomula += s[k]
            fomula += x[k]
        fomula += s[N-1]
        fomula += '=7'
        print(fomula)
        break

Submission status: Accepted

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

k=["+","-"]

for k1 in k:
    for k2 in k:
        for k3 in k:
                if eval(a+k1+b+k2+c+k3+d)==7:
                    print("{}=7".format(a+k1+b+k2+c+k3+d))
                    exit()

Submission status: Accepted

Solution code:
def main():
    S = input()
    a, b, c, d = (int(i) for i in S)
    ans = 0
    sign = []
    flag = False
    #op == 0 : plus, op == 1: minus
    for op1 in range(2):
        for op2 in range(2):
            for op3 in range(2):
                ans = 0
                sign = []
                if op1 == 0:
                    ans = a + b
                    sign.append('+')
                else:
                    ans = a - b
                    sign.append('-')
                if op2 == 0:
                    ans += c
                    sign.append('+')
                else:
                    ans -= c
                    sign.append('-')
                if op3 == 0:
                    ans += d
                    sign.append('+')
                else:
                    ans -= d
                    sign.append('-')
                if ans == 7:
                    flag = True
                    break
            if flag:
                break
        if flag:
            break
    for n,op in zip(S,sign):
        print(n+op,end="")
    else:
        print(S[-1]+'=7')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def dfs(i,f,sum):
  if i == 3:
    if sum == 7:
      print(f + "=7")
      exit()
  else:
    dfs(i+1, f+"-"+abcd[i+1], sum-int(abcd[i+1]))
    dfs(i+1, f+"+"+abcd[i+1], sum+int(abcd[i+1]))

abcd = input()
print(dfs(0, abcd[0], int(abcd[0])))

Submission status: Accepted

Solution code:
A, B, C, D = input()
o = ["+", "-"]
for i in range(2):
    for j in range(2):
        for k in range(2):
            s = A + o[i]  + B + o[j] + C + o[k] + D
            if eval(s) == 7:
                print(s + "=7")
                exit()

Submission status: Accepted

Solution code:
n = input()
li = [n[0],n[1],n[2],n[3]]
pm = [[1,1,1],[1,1,0],[1,0,1],[1,0,0],[0,1,1],[0,1,0],[0,0,1],[0,0,0]]
s = ""

for i in range(8):
    for j in range(3):
        if pm[i][j]==1:
            pm[i][j]="+"
        elif pm[i][j]==0:
            pm[i][j]="-"

for j in range(8):
    s = li[0]+pm[j][0]+li[1]+pm[j][1]+li[2]+pm[j][2]+li[3]
    if eval(s)==7:
        break
print(s+"=7")

Submission status: Accepted

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

if a+b+c+d==7:print(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=str(input())

ans=int(s[0])
a=ans
for i in range(2):
    ans=a
    if i==0:
        ans+=int(s[1])
        i='+'
    else:
        ans-=int(s[1])
        i='-'
    b=ans
    for j in range(2):
        ans=b
        if j==0:
            ans+=int(s[2])
            j='+'
        else:
            ans-=int(s[2])
            j='-'
        c=ans
        for k in range(2):
            ans=c
            if k==0:
                ans+=int(s[3])
                k='+'
            else:
                ans-=int(s[3])
                k='-'
            if ans==int(7):
                print(s[0]+str(i)+s[1]+str(j)+s[2]+str(k)+s[3]+'=7')
                break
        else:
            continue
        break
    else:
        continue
    break

Submission status: Accepted

Solution code:
abcd=input()

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

Submission status: Accepted

Solution code:
s = list(input())
a = len(s)-1
for i in range(2 ** a):
    b = ["-"] * a
    for j in range(a):
        if i>>j & 1:
            b[j] = "+"
    S = s[0]
    for x in range(a):
        S += b[x]
        S += s[x+1]
    if eval(S) == 7:
        print(S+"=7")
        exit()

Submission status: Accepted

Solution code:
import sys
s = input()
a = int(s[0])
b=[]
for i in range(3):
    b.append(int(s[i+1]))

for i in range(8):
    tmp = a
    for j in range(3):
        if (i>>j) & 1 == 0:
            tmp += b[j]
            
        else:
            tmp -= b[j]
    if tmp == 7:
        ans = [str(a)]
        for k in range(3):
            if (i>>k) & 1 == 0:
                ans.append("+")
            else:
                ans.append("-")
            ans.append(str(b[k]))
        print(''.join(ans),end="")
        print("=7")
        sys.exit()

Submission status: Accepted

Solution code:
n_str = input()

op_count = len(n_str) - 1  # すき間の個数
for i in range(2 ** op_count):
    op_list = ["-"] * op_count    # あらかじめ ["-", "-", "-"] というリストを作っておく
    for j in range(op_count):    # iの右からj+1番目のbitが1かどうかを確認
        if ((i >> j) & 1):
            op_list[len(op_list) - 1 -j] = "+"

    op_list.append("")
    formula = ""
    for i in range(len(n_str)):
        formula += (n_str[i] + op_list[i])
    if eval(formula) == 7:
        print(formula + "=7")
        break

Submission status: Accepted

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


def main():
    A = list(map(int, list(input()[:-1])))
    for i in range(2**3):
        f = str(A[0])
        ans = A[0]
        for j in range(3):
            if (i>>j) & 1:
                f += '+' + str(A[j+1])
                ans += A[j+1]
            else:
                f += '-' + str(A[j+1])
                ans -= A[j+1]
        if ans==7:
            f += '=7'
            print(f)
            return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()
 
abcd = ns()
a = int(abcd[0])
b = int(abcd[1])
c = int(abcd[2])
d = int(abcd[3])

l = [
  [1, 1, 1],
  [-1, 1, 1],
  [1, -1, 1],
  [1, 1, -1],
  [-1, -1, 1],
  [-1, 1, -1],
  [1, -1, -1],
  [-1, -1, -1],
]

counter = 0
for i in range(8):
  if a + l[i][0] * b + l[i][1] * c + l[i][2] * d == 7:
    break
  counter += 1

out = []
out.append(str(a))
if l[counter][0] == 1:
  out.append('+')
else:
  out.append('-')
out.append(str(b))
if l[counter][1] == 1:
  out.append('+')
else:
  out.append('-')
out.append(str(c))
if l[counter][2] == 1:
  out.append('+')
else:
  out.append('-')
out.append(str(d))
out.append('=7')
print(''.join(out))

Submission status: Accepted

Solution code:
L = [int(i) for i in input()]
A = L[0]
B = L[1]
C = L[2]
D = L[3]
x="-"
y="-"
z="-"
if A+B+C+D==7:
    x="+"
    y="+"
    z="+"
elif A+B+C-D==7:
    x="+"
    y="+"
elif A+B-C+D==7:
    x="+"
    z="+"
elif A+B-C-D==7:
    x="+"
elif A-B+C+D==7:
    y="+"
    z="+"
elif A-B+C-D==7:
    y="+"
elif A-B-C+D==7:
    z="+"
print("{}{}{}{}{}{}{}{}".format(A,x,B,y,C,z,D,"=7"))

Submission status: Accepted

Solution code:
ABCD = input()
S = list(ABCD)
op_cnt = len(S) - 1

ans = None
for i in range(2**op_cnt):
    op = ["+"] * op_cnt
    for j in range(op_cnt):
        if i >> j & 1:
            op[op_cnt - j - 1] = "-"
    expr = S[0] + "".join(o+s for s,o in zip(S[1:], op))
    if eval(expr) == 7:
        ans = expr + "=7"
        break
print(ans)

Submission status: Accepted

Solution code:
S = input()
op_cnt = len(S) -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 a, b in zip(S, op + ['']):
        formula += a + b
    if eval(formula) == 7:
        print(formula + '=7')
        break

Submission status: Accepted

Solution code:
a=[int(i) for i in input()]
for i in range(2**3):
    op=['-','-','-']
    for j in range(len(op)):
        if (i>>j)&1:
            op[j]='+'
    sum=a[0]
    for k in range(3):
        if op[k]=='+':
            sum+=a[k+1]
        else:
            sum-=a[k+1]
    if sum==7:
        print(str(a[0])+op[0]+str(a[1])+op[1]+str(a[2])+op[2]+str(a[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('{}+{}+{}+{}=7'.format(a,b,c,d))
elif a+b+c-d==7:
  print('{}+{}+{}-{}=7'.format(a,b,c,d))
elif a+b-c+d==7:
  print('{}+{}-{}+{}=7'.format(a,b,c,d))
elif a-b+c+d==7:
  print('{}-{}+{}+{}=7'.format(a,b,c,d))
elif a+b-c-d==7:
  print('{}+{}-{}-{}=7'.format(a,b,c,d))
elif a-b+c-d==7:
  print('{}-{}+{}-{}=7'.format(a,b,c,d))
elif a-b-c+d==7:
  print('{}-{}-{}+{}=7'.format(a,b,c,d))
elif a-b-c-d==7:
  print('{}-{}-{}-{}=7'.format(a,b,c,d))

Submission status: Accepted

Solution code:
def dfs(i, f, sum):
    if i == 3:
        if sum == 7:
            # 答えは1つ出力すれば良いので =7 になれば終了
            print(f + "=7")
            exit()

    else:
        dfs(i + 1, f + "-" + s[i + 1], sum - int(s[i + 1]))
        dfs(i + 1, f + "+" + s[i + 1], sum + int(s[i + 1]))

s = list(str(input()))

dfs(0, s[0], int(s[0]))

Submission status: Accepted

Solution code:
# ABC079c
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)

n = input()[:-1]


def dfs(pos, formula):
    if (pos > 3):
        # print(formula)
        return formula if eval(formula) == 7 else False
    #print(pos, n[pos])
    f = dfs(pos + 1, formula + '+'+n[pos])
    if (not f):
        return dfs(pos + 1, formula + '-'+n[pos])
    else:
        return f


print(dfs(1, n[0])+'=7')

Submission status: Accepted

Solution code:
A,B,C,D=map(str,list(input()))
nana = False
for i in range(8):
    op1,op2,op3='-','-','-'
    if (i & 0b1) == 1:
        op1='+'
    if ((i>>1) & 0b1) == 1:
        op2='+'
    if ((i>>2) & 0b1) == 1:
        op3='+'
    if eval(A+op1+B+op2+C+op3+D) == 7:
        nana=True
        siki7=A+op1+B+op2+C+op3+D
if nana == True:
    print(siki7+'=7')

Submission status: Accepted

Solution code:
s = input()
def dfs(i,f,sum):
  if i == 3:
    if sum == 7:
      print(f + "=7")
      exit()
  else:
    dfs(i+1,f + "+" + s[i+1],sum+int(s[i+1]))
    dfs(i+1,f + "-" + s[i+1],sum-int(s[i+1]))
dfs(0,s[0],int(s[0]))

Submission status: Accepted

Solution code:
a, b, c, d = map(int, input())
ops = ['+', '-']
for op1 in ops:
    for op2 in ops:
        for op3 in ops:
            formula = "{}{}{}{}{}{}{}".format(a, op1, b, op2, c, op3, d)
            if eval(formula) == 7:
                print("{}=7".format(formula))
                exit()

Submission status: Accepted

Solution code:
#79c
S = str(input())

for i in range(2**(len(S)-1)):
    bit_array = str(bin(i)[2:]).zfill((len(S)-1))
    
    stored = int(S[0])
    
    for j in range(len(bit_array)):
        
        if bit_array[j]=="0":
            stored = stored + int(S[j+1])
        elif bit_array[j]=="1":
            stored =  stored - int(S[j+1])
    
    if stored == 7:
        print(int(S[0]),end="")
        for k in range(3):
            if bit_array[k]=="0":
                print("+",end="")
            elif bit_array[k]=="1":
                print("-",end="")
            
            print(S[k+1],end="")
        print("=7")
        break

Submission status: Accepted

Solution code:
A, B, C, D = list(input())
ops = ['+', '-']
for op1 in ops:
    for op2 in ops:
        for op3 in ops:
            s = '{}{}{}{}{}{}{}'.format(A, op1, B, op2, C, op3, D)
            if eval(s) == 7:
                print('{}=7'.format(s))
                exit()

Submission status: Accepted

Solution code:
A=input()
N=len(A)

for i in range(2**(N-1)):
  s=A[0]
  for j in range(N-1):
    if (i>>j)&1:
      s+="+"
    else:
      s+="-"
    s+=A[j+1]
  if eval(s)==7:
    print(s+"=7")
    break

Submission status: Accepted

Solution code:
numbers = list(input())

for op1 in ['+', '-']:
    for op2 in ['+', '-']:
        for op3 in ['+', '-']:
            s = numbers[0]+op1+numbers[1]+op2+numbers[2]+op3+numbers[3]
            if eval(s) == 7:
                print('{}=7'.format(s))
                exit()

Submission status: Accepted

Solution code:
from itertools import permutations

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

def solve():
    '''bit全探索で解く'''
    candidates = []
    for i in range(2**3):
        
        candidates.append(bin(i)[2:].zfill(3))
    
    for candidate in candidates:
        s = numbers[0]
        # print('start', list(candidate), s)
        for i, c in enumerate(list(candidate)):
            if c == '1':
                s += numbers[i+1]
            else:
                s -= numbers[i+1]
            # print(i, c, s)
        if s == 7:
            candidate = ''.join(candidate)
            candidate = candidate.replace('1', '+')
            candidate = candidate.replace('0', '-')
            for i in range(3):
                print(numbers[i], end='')
                print(candidate[i], end='')
                
            print(numbers[-1], end='')
            print('=7') 
            return

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
n=list(input())
pm=["+","-"]

for op1 in pm:
    for op2 in pm:
        for op3 in pm:
            s = n[0] + op1 + n[1] + op2 + n[2] + op3 + n[3]
            if eval(s) == 7:
                print(s + "=7")
                exit()

Submission status: Accepted

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

for b in [B, -B]:
  for c in [C, -C]:
    for d in [D, -D]:
      if A+b+c+d==7:
        output=str(A)
        
        if b<0:
          output+=str(b)
        else:
          output+='+'+str(b)
          
        if c<0:
          output+=str(c)
        else:
          output+='+'+str(c)
          
        if d<0:
          output+=str(d)
        else:
          output+='+'+str(d)
          
print(output+'=7')

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
ABCD = list(input())

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

Submission status: Accepted

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

plus_minus = ["+", "-"]
for op1 in plus_minus:
    for op2 in plus_minus:
        for op3 in plus_minus:
            formula = str(ABCD[0]) + op1 + str(ABCD[1]) + op2 + str(ABCD[2]) + op3 + str(ABCD[3])
            if eval(formula) == 7:
                print(formula + "=7")
                exit()

Submission status: Accepted

Solution code:
s = input()
for i in range(8):
  e = bin(i)[2:]
  e = '0' * (3-len(e)) + e
  su = int(s[0])
  for i in range(3):
    if e[i] == '0':
      su -= int(s[i+1])
    else:
      su += int(s[i+1])
  if su == 7:
    a = s[0]
    for i in range(3):
      if e[i] == '0':
        a += '-'
      else:
        a += '+'
      a += s[i+1]
    a += '=7'
    print(a)
    exit()

Submission status: Accepted

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

# In[14]:


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


# In[15]:


import sys


# In[16]:


cs_a = a
for i in range(2):
    if i:
        cs_b = cs_a + b
        op1 = '+'
    else:
        cs_b = cs_a - b
        op1 = '-'
        
    for j in range(2):
        if j:
            cs_c = cs_b + c
            op2 = '+'
        else:
            cs_c = cs_b - c
            op2 = '-'
        
        for k in range(2):
            if k:
                cs_d = cs_c + d
                op3 = '+'
            else:
                cs_d = cs_c - d
                op3 = '-'
                
            if cs_d == 7:
                print('{}{}{}{}{}{}{}=7'.format(a, op1, b, op2, c, op3, d))
                sys.exit()


# In[ ]:

Submission status: Accepted

Solution code:
l = list(input().rstrip())
ops = ['+', '-']
for a in ops:
    for b in ops:
        for c in ops:
            s = l[0] + a + l[1] + b + l[2] + c + l[3]
            if eval(s) == 7:
                print(s + '=7')
                exit()

Submission status: Accepted

Solution code:
ABCD = input()
A, B, C, D = [int(x) for x in ABCD]
ops = ["+", "-"]
for op1 in ops:
    for op2 in ops:
        for op3 in ops:
            if op1 == "+":
                ans = A + B
            else:
                ans = A - B
            if op2 == "+":
                ans += C
            else:
                ans -= C
            if op3 == "+":
                ans += D
            else:
                ans -= D
            if ans == 7:
                print(str(A) + op1 + str(B) + op2 + str(C) + op3 + str(D) + "=" + str(ans))
                exit()

Submission status: Accepted

Solution code:
import itertools

N = list(input().strip())

for p in itertools.product(['+', '-'], repeat=3):
    s = N[0] + p[0] + N[1] + p[1] + N[2] + p[2] + N[3]
    if eval(s) == 7:
        print(s + '=7')
        exit()

Submission status: Accepted

Solution code:
l_a  = list(input())
l_b = [l_a[0],0,l_a[1],0,l_a[2],0,l_a[3]]
l_c = []
for i in range (2**3):
    for k in range(3):
        if i & (1<<k):
            l_b[2*k+1] = '+'
        else:
            l_b[2*k+1] = '-'
    d =''.join(l_b)
    if eval(d) == 7:
        print(d + '=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:
import sys
S = list(map(int,list(input())))
for i in range(2**3):
    n = i
    pat = []
    sum = S[0]
    for j in range(1,4):
        if n % 2 == 0:
            pat.append('+')
            sum += S[j]
        else:
            pat.append('-')
            sum -= S[j]
        n = n // 2
    if sum == 7:
        print( '{}{}{}{}{}{}{}=7'.format(S[0],pat[0],S[1],pat[1],S[2],pat[2],S[3]))
        sys.exit()

Submission status: Accepted

Solution code:
def run():
  num_list = [int(i) for i in list(input())]
  ans_list = [(str(num_list[0]), num_list[0])]
  for num in num_list[1:]:
    new_list = []
    for ans in ans_list:
      ans_str = ans[0]
      ans_num = ans[1]
      new_list.append((ans_str+'+'+str(num), ans_num+num))
      new_list.append((ans_str+'-'+str(num), ans_num-num))
    ans_list = new_list
  for ans in ans_list:
    if ans[1] == 7:
      print(ans[0]+'=7')
      break
                       
if __name__ == '__main__':  
  run()

Submission status: Accepted

Solution code:
S = input()
A = [0]*4
for i in range(4):
    A[i] = int(S[i])
zero = [0,1]

import itertools
for i in itertools.product(zero,repeat=3):
    tmp = A[0]
    for j in range(3):
        if i[j] == 0:
            tmp += A[j+1]
        else:
            tmp -= A[j+1]
    if tmp == 7:
        break
ans = S[0]
op = i
for i in range(3):
    if op[i] == 0:
        ans += "+"
    else:
        ans += "-"
    ans += S[i+1]
ans += "=7"
print(ans)

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")
else:
    print(str(a)+"+"+str(b)+"-"+str(c)+"+"+str(d)+"=7")