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:
A = list(map(int, list(input())))

for i in range(2 ** 3):
    ans = A[0]
    op = []
    for j in range(3):
        if ((i >> j) & 1):
            ans += A[j + 1] 
            op.append("+")
        else:
            ans -= A[j + 1]
            op.append("-")
    if ans == 7:
        break
A = list(map(str, A))
print(A[0], end="")
for c in range(3):
    print(op[c], end="")
    print(A[c + 1], end="")
print("=7")

Submission status: Accepted

Solution code:
s = input()
n = len(s)

for i in range(2**(n-1)):
  f = s[0]
  ans = int(s[0])
  for j in range(n-1):
    if i & (1<<j):
      f += '+'
      ans += int(s[j+1])
    else:
      f += '-'
      ans -= int(s[j+1])
    f += s[j+1]
      
  if ans == 7:
    print(f + '=7')
    exit()

Submission status: Accepted

Solution code:
def main():
    A, B, C, D = list(input())
    for i in ['+','-']: 
        for j in ['+','-']:
            for k in ['+','-']:
                tmp = A + i + B + j + C + k + D
                if eval(tmp) == 7:
                    print(tmp+'=7')
                    exit()

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
if __name__ == '__main__':
    s = input()
    o = []
    n = len(s)
    
    for i in range(1 << n - 1):
        tmp = 0
        tmp += int(s[0])
        o.clear()
        for j in range(n - 1):
            if 1 << j & i == 0:
                tmp += int(s[j + 1])
                o.append('+')
            else:
                tmp -= int(s[j + 1])
                o.append('-')
        if tmp == 7:
            print(s[0]+o[0]+s[1]+o[1]+s[2]+o[2]+s[3]+'=7')
            sys.exit()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
S = input()
space_cnt = 3
for i in range(2 ** space_cnt):
    ops = ["-"] * space_cnt
    for j in range(space_cnt):
        if (i >> j) & 1:
            ops[j] = "+"
    formula = ""
    for j in range(space_cnt):
        formula += S[j]+ops[j]
    formula += S[-1]
    if eval(formula)==7:
        break
print(formula+"=7")

Submission status: Accepted

Solution code:
a = input()

for i in range(1 << 3):
  ans = int(a[0])
  f = a[0]
  
  for j in range(3):
    if i & (1 << j):
      ans += int(a[j+1])
      f += '+'
    else:
      ans -= int(a[j+1])
      f += '-'
    f += a[j+1]
    
  if ans == 7:
    print(f + '=7')
    exit()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
s = input()
n = len(s)-1

def calc(s, op):
    ret = int(s[0])
    for i in range(len(op)):
        if op[i] == '+':
            ret += int(s[i+1])
        else:
            ret -= int(s[i+1])
    
    return ret

for i in range(2**n):
    op =''
    for j in range(n):
        if (i >> j)&1:
            op += '+'
        else:
            op += '-'
    
    if calc(s,op) == 7:
        #print(op)
        ans = ''
        for a in range(len(op)):
            ans += s[a]
            ans += op[a]
        ans += s[-1]
        ans += '=7'
        print(ans)
        exit(0)

Submission status: Accepted

Solution code:
import itertools as itr

A=list(map(int,input()))
b=list(itr.product(range(2),repeat=3))

for i in b:
    i=['+' if j==1 else '-' for j in i]
    ans=A[0]

    for j in range(3):
        if i[j]=='+':
            ans+=A[j+1]
        else:
            ans-=A[j+1]

    if ans==7:
        C=[]
        for j in range(3):
            C.append(A[j])
            C.append(i[j])
        C.append(A[3])
        C.append('=7')
        print(''.join(map(str,C)))
        exit(0)   

print(-1)

Submission status: Accepted

Solution code:
import itertools as itr

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

b=list(itr.product(range(2),repeat=3))


for i in b:
    i=['+' if j==1 else '-' for j in i]
    ans=A[0]
    if i[0]=='+':
        ans+=A[1]
    else:
        ans-=A[1]

    if i[1]=='+':
        ans+=A[2]
    else:
        ans-=A[2]    

    if i[2]=='+':
        ans+=A[3]
    else:
        ans-=A[3] 

    if ans==7:
        C=[]
        C.append(A[0])
        C.append(i[0])
        C.append(A[1])
        C.append(i[1])
        C.append(A[2])
        C.append(i[2])
        C.append(A[3])
        C.append('=7')
        print(''.join(map(str,C)))
        exit(0)   


print(-1)

Submission status: Accepted

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

bit = 4

for i in range(8):
  calc_list = []
  for j in range(3):
    if((i >> j) & 1):
      calc_list.append("+")
    else:
      calc_list.append("-")
  calc_str = a + calc_list[0] + b + calc_list[1] + c + calc_list[2] + d
  if eval(calc_str) == 7:
    print(calc_str + "=7")
    sys.exit()

Submission status: Accepted

Solution code:
a, b, c, d = [int(x) for x in input().strip()]
if a + b + c + d == 7:
    print(f"{a}+{b}+{c}+{d}=7")
elif a + b + c - d == 7:
    print(f"{a}+{b}+{c}-{d}=7")
elif a + b - c + d == 7:
    print(f"{a}+{b}-{c}+{d}=7")
elif a - b + c + d == 7:
    print(f"{a}-{b}+{c}+{d}=7")
elif a - b - c + d == 7:
    print(f"{a}-{b}-{c}+{d}=7")
elif a + b - c - d == 7:
    print(f"{a}+{b}-{c}-{d}=7")
elif a - b + c - d == 7:
    print(f"{a}-{b}+{c}-{d}=7")
elif a - b - c - d == 7:
    print(f"{a}-{b}-{c}-{d}=7")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,C,D = list(input().strip())
if int(A)+int(B)+int(C)+int(D) == 7:
    print(A+"+"+B+"+"+C+"+"+D+"=7")
elif int(A)+int(B)+int(C)-int(D) == 7:
    print(A+"+"+B+"+"+C+"-"+D+"=7")
elif int(A)+int(B)-int(C)+int(D) == 7:
    print(A+"+"+B+"-"+C+"+"+D+"=7")
elif int(A)+int(B)-int(C)-int(D) == 7:
    print(A+"+"+B+"-"+C+"-"+D+"=7")
elif int(A)-int(B)+int(C)+int(D) == 7:
    print(A+"-"+B+"+"+C+"+"+D+"=7")
elif int(A)-int(B)+int(C)-int(D) == 7:
    print(A+"-"+B+"+"+C+"-"+D+"=7")
elif int(A)-int(B)-int(C)+int(D) == 7:
    print(A+"-"+B+"-"+C+"+"+D+"=7")
elif int(A)-int(B)-int(C)-int(D) == 7:
    print(A+"-"+B+"-"+C+"-"+D+"=7")

Submission status: Accepted

Solution code:
from itertools import product

a,b,c,d=map(int,list(input()))
op = ['+','-']
for p in product(range(2),repeat=3):
  txt=f'{a}{op[p[0]]}{b}{op[p[1]]}{c}{op[p[2]]}{d}'
  if eval(txt)==7:
    print(txt+'=7')
    exit()

Submission status: Accepted

Solution code:
S=input()

o=['-','+']
for h in o:
    for i in o:
        for j in o:
            if 7 == eval(S[0]+h+S[1]+i+S[2]+j+S[3]):
                print(S[0]+h+S[1]+i+S[2]+j+S[3]+"=7")
                exit()

Submission status: Accepted

Solution code:
from itertools import product

a, b, c, d = [int(i) for i in list(input())]
for i, j in zip(product([1, -1], repeat=3), product(["+", "-"], repeat=3)):
    if a + b * i[0] + c * i[1] + d * i[2] == 7:
        print(f"{a}{j[0]}{b}{j[1]}{c}{j[2]}{d}=7")
        break

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
a, b, c, d = [int(i) for i in list(input())]

for j in range(8):
    op = [[1, "+"]] * 3
    for i in range(3):
        if (j >> i) & 1:
            op[i] = [-1, "-"]
    if a + b * op[0][0] + c * op[1][0] + d * op[2][0] == 7:
        print(f"{a}{op[0][1]}{b}{op[1][1]}{c}{op[2][1]}{d}=7")
        exit()

Submission status: Accepted

Solution code:
def myfunc(op):
    if op:
        return "+"
    else:
        return "-"


a, b, c, d = [int(i) for i in list(input())]

for j in range(8):
    op = [[1, "+"]] * 3
    for i in range(3):
        if (j >> i) & 1:
            op[i] = [-1, "-"]
    if a + b * op[0][0] + c * op[1][0] + d * op[2][0] == 7:
        print(f"{a}{op[0][1]}{b}{op[1][1]}{c}{op[2][1]}{d}=7")
        exit()

Submission status: Accepted

Solution code:
def myfunc(op):
    if op == 1:
        return "+"
    else:
        return "-"


a, b, c, d = [int(i) for i in list(input())]

for j in range(8):
    op = [1, 1, 1]
    for i in range(3):
        if (j >> i) & 1:
            op[i] = -1
    if a + b * op[0] + c * op[1] + d * op[2] == 7:
        x = myfunc(op[0])
        y = myfunc(op[1])
        z = myfunc(op[2])
        print(f"{a}{x}{b}{y}{c}{z}{d}=7")
        exit()

Submission status: Accepted

Solution code:
def myfunc(op):
    if op == 1:
        return "+"
    else:
        return "-"


a, b, c, d = [int(i) for i in list(input())]

for k in [0, 1]:
    for j in [0, 1]:
        for i in [0, 1]:
            op = [-1, -1, -1]
            if k == 0:
                op[0] = 1
            if j == 0:
                op[1] = 1
            if i == 0:
                op[2] = 1
            if a + b * op[0] + c * op[1] + d * op[2] == 7:
                x = myfunc(op[0])
                y = myfunc(op[1])
                z = myfunc(op[2])
                print(f"{a}{x}{b}{y}{c}{z}{d}=7")
                exit()

Submission status: Accepted

Solution code:
n = input()
l = len(n) - 1

for i in range(2 ** l):
    ans: int = int(n[0])
    num = n[0]
    for j in range(l):
        if (i >> j) & 1:
            num += "+"
            num += n[j + 1]
        else:
            num += "-"
            num += n[j + 1]
    for k in range(1, len(num), 2):
        if num[k] == "-":
            ans -= int(num[k+1])
        else:
            ans += int(num[k+1])
    if ans == 7:
        print(num + "=7")
        break

Submission status: Accepted

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

dic = {1: "+", 0: "-"}

for i in range(2 ** 3):
    t = A[0]
    s = str(A[0])
    for j in range(3):
        if (i >> j) & 1:
            t += A[j + 1]
            s += dic[1] + str(A[j + 1])
        else:
            t -= A[j + 1]
            s += dic[0] + str(A[j + 1])
            
    if t == 7:
        print(s + "=7")
        exit()

Submission status: Accepted

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

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

else:
    print("{0}-{1}-{2}-{3}=7".format(A, B, C, D))

Submission status: Accepted

Solution code:
s=input()
ans=0
def dfs(i,stri,sum): #i個土入れてstriを作ってる、和は？
    global ans
    #print(i,stri,sum)
    if i==3 and sum==7:
        #print("ore")
        ans=stri+"=7"
        
    
    if i<=2:
        dfs(i+1, stri+ f"+{s[i+1]}" , sum+int(s[i+1]))
        dfs(i+1, stri+ f"-{s[i+1]}", sum-int(s[i+1]))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
correct = []
def dfs(i, s, stack):
	if i == 4:

		if eval(''.join(stack)) == 7:
			correct.append(''.join(stack) + '=7')
			return True
		else:
			return False

	if dfs(i+1, s,stack + ['+', s[i]]): return True
	if dfs(i+1, s,stack + ['-', s[i]]): return True
	return False
s = raw_input()
dfs(1, s, [s[0]])
print correct[0]

Submission status: Accepted

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

dic = { 1:"+" , -1:"-"}

import itertools
for AB,BC,CD in itertools.product([1,-1],repeat=3):
    tmp = A + B*AB + C*BC + D*CD

    if tmp ==7:
        ans = str(A)+dic[AB]+str(B)+dic[BC]+str(C)+dic[CD]+str(D)+"=7"
        print(ans)
        exit()

Submission status: Accepted

Solution code:
s = input()
a = [int(c) for c in s]
mark = ['+', '-']
sum = 0
ans = 0
for i in range(2**3):
    sum = int(a[0])
    for j in range(3):
        k = (i >> j)
        sum += int(a[j+1])*(-1)**k
    if sum == 7:
        ans = i
        break
# print(i)
# 下からn桁目のビットが1:-
# 下からn桁目のビットが0:+
b = []
m = []
formula = ''
for l in range(3):
    b.append(str(a[l+1]))
    c = (ans >> l & 1)
    m.append(mark[c])
    formula += (m[l] + b[l])
print(str(a[0]) + formula + '=7')

Submission status: Accepted

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

for i in range(2 ** (n - 1)):
    num = int(s[0])
    num_list = [str(s[0])]
    for j in range(n - 1):
        if (i >> j) & 1:
            num += int(s[j + 1])
            num_list.append("+" + str(s[j + 1]))
        else:
            num -= int(s[j + 1])
            num_list.append("-" + str(s[j + 1]))
    if num == 7:
        [print(t, end="") for t in num_list]
        print("=7")
        break

Submission status: Accepted

Solution code:
s = str(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:
abcd = str(input())
ans = ''

for i in range(2**(len(abcd)-1)):
  total = int(abcd[0])
  ans = abcd[0]
  for j in range(len(abcd)-1):
    if (i >> j) & 1:
      total += int(abcd[j+1])
      ans = ans + '+' + abcd[j+1]
    else:
      total -= int(abcd[j+1])
      ans = ans + '-' + abcd[j+1]
  if total == 7:
    ans = ans + '=7'
    break
print(ans)

Submission status: Accepted

Solution code:
from itertools import product
S = input()
n = len(S)
bit = list(product([0, 1], repeat = n - 1))
for state in bit:
    ans = int(S[0])
    s = S[0]
    for i in range(len(state)):
        if state[i] == 1:
            s += '+' + S[i + 1]
            ans += int(S[i + 1])
        else:
            s += '-' + S[i + 1]
            ans -= int(S[i + 1])
    if ans == 7:
        print(s + '=7')
        break

Submission status: Accepted

Solution code:
tn=list(map(int,list(input())))
for i in range(0,16,2):
  if sum(x*[1,-1][i>>k&1] for k,x in enumerate(tn))==7:
    s=''.join(list(['+','-'][i>>k&1]+str(tn[k]) for k in range(1,4)))
    print(str(tn[0])+s+'=7')
    break

Submission status: Accepted

Solution code:
import sys
S=list(input())
A=int(S[0])
B=int(S[1])
C=int(S[2])
D=int(S[3])
if A+B+C+D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+"+"+B+"+"+C+"+"+D+"=7")
  sys.exit()
elif A+B+C-D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+"+"+B+"+"+C+"-"+D+"=7")
  sys.exit()
elif A+B-C+D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+"+"+B+"-"+C+"+"+D+"=7")
  sys.exit()
elif A-B+C+D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+"-"+B+"+"+C+"+"+D+"=7")
  sys.exit()
elif A+B-C-D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+"+"+B+"-"+C+"-"+D+"=7")
  sys.exit()
elif A-B-C+D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+"-"+B+"-"+C+"+"+D+"=7")
  sys.exit()
elif A-B+C-D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+"-"+B+"+"+C+"-"+D+"=7")
  sys.exit()
elif A-B-C-D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+"-"+B+"-"+C+"-"+D+"=7")
  sys.exit()

Submission status: Accepted

Solution code:
abcd_origin = list(input())

for i in range(8):
    abcd = abcd_origin.copy()
    temp = []
    temp.append(abcd.pop(0))
    for j in range(3):
        if (i >> j) & 1:
            temp.append('+')
            temp.append(abcd.pop(0))
        else:
            temp.append('-')
            temp.append(abcd.pop(0))

    result = int(temp[0])

    for k in range(3):
        if temp[2 * k + 1] == '+':
            result += int(temp[2 * k + 2])
        else:
            result -= int(temp[2 * k + 2])

    if result == 7:
        equ = ''.join(temp) + '=7'
        print(equ)
        exit()

Submission status: Accepted

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


S = input()
n = len(S)

make7(0, S[0], int(S[0]))

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 + "-" + s[i + 1], sum - int(s[i + 1]))
        dfs(i + 1, f + "+" + s[i + 1], sum + int(s[i + 1]))
s = input()
dfs(0, s[0], int(s[0]))

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[-1-j] = '+'
  formula = ''
  for p_n, p_o in zip(n, op + ['']):#(1,+),(2,+),(3,+),(4,'')
    formula += (p_n + p_o)
  if eval(formula) == 7:#'1+2+3+4'
    print(formula + '=7')
    break

Submission status: Accepted

Solution code:
s=input()
a=int(s[0])
b=int(s[1])
c=int(s[2])
d=int(s[3])
arr=[b,c,d]
for i in range(8):
    x=i
    m=a
    k=''
    for j in range(3):
        if x&1:
            m+=arr[j]
            k+='+'
        else:
            m-=arr[j]
            k+='-'
        x=x>>1
    if m==7:
        print (s[0]+k[0]+s[1]+k[1]+s[2]+k[2]+s[3]+'='+'7')
        break

Submission status: Accepted

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

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

for i in range(2):
    for j in range(2):
        for k in range(2):
            ops = ['-'] * 3
            r = a
            if i % 2 == 0:
                r += b
                ops[0] = '+'
            else:
                r -= b

            if j % 2 == 0:
                r += c
                ops[1] = '+'
            else:
                r -= c

            if k % 2 == 0:
                r += d
                ops[2] = '+'
            else:
                r -= d
            
            if r == 7:
                print(str(a) + ops[0] + str(b) + ops[1] + str(c) + ops[2] + str(d) + '=7')
                exit()

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 + '-' + s[i+1], sum - int(s[i+1]))
        dfs(i+1, f + '+' + s[i+1], sum + int(s[i+1]))
        
s = input()
dfs(0, s[0], int(s[0]))

Submission status: Accepted

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

    else:
        # 式 f の末尾に符号と次の数字を追加し、その分 sum に加減する
        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 = input()

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

Submission status: Accepted

Solution code:
num = input()

op_count = 3

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

    equ = ""

    for n_i,o_i in zip(num,op + [""]):
        equ += n_i + o_i
    if(eval(equ) == 7):
        print(equ + "=7") 
        break

Submission status: Accepted

Solution code:
ABCD = input()
operations = []
def culc(num, ope):
    if len(ope) == 4:
        if num == 7:
            return operations.append(ope)
        else:
            return
    
    if len(ope) != 0 and ope[-1] == '+':
        num += int(ABCD[len(ope)])
    elif len(ope) != 0 and ope[-1] == '-':
        num -= int(ABCD[len(ope)])
    
    culc(num, ope+'+')
    culc(num, ope+'-')
        
culc(int(ABCD[0]), '')
ans = ''
for i in range(len(ABCD)):
    ans += ABCD[i] + operations[0][i]
print(ans[:7] + '=7')

Submission status: Accepted

Solution code:
n=[int(x) for x in input()]
op_cnt=len(n)-1
for i in range(2**op_cnt):
    ops=['-']*op_cnt
    for j in range(op_cnt):
        if ((i>>j)&1):
            ops[op_cnt-1-j]='+'
    num=n[0]
    for i,op in enumerate(ops):
        if op=='-':
            num-=n[i+1]
        else:
            num+=n[i+1]
    if num==7:
        print(str(n[0])+ops[0]+str(n[1])+ops[1]+str(n[2])+ops[2]+str(n[3])+'=7')
        exit()

Submission status: Accepted

Solution code:
ABCD = input()

for i in range(2 ** 3):
    eq = ''
    for j in range(3):
        eq += ABCD[j]
        if (i >> j) & 1:
            eq += '+'
        else:
            eq += '-'
    else:
        eq += ABCD[3]
    if eval(eq) == 7:
        print(eq + '=7')
        exit()

Submission status: Accepted

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

for i in range(1 << 3):
    x = A[0]
    ans = str(A[0])
    for j in range(3):
        if i & 1 << j > 0:
            x += A[j + 1]
            ans += '+' + str(A[j + 1])
        else:
            x -= A[j + 1]
            ans += '-' + str(A[j + 1])
    if x == 7:
        print(ans + "=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 = ""*(2+len(n)-1)
    formula+=n[0]
    for w in range(len(n)-1):
        formula+=op[w]+n[w+1]
    if eval(formula) == 7:
        print(formula + "=7")
        break

Submission status: Accepted

Solution code:
n=int(input())
d=n%10
c=(n//10)%10
b=(n//100)%10
a=n//1000

for i in range(8):
    k=[1,1,1]
    for j in range(3):
        if ((i>>j)&1):
            k[j]=-1
    if a+k[0]*b+k[1]*c+k[2]*d==7:
        for j in range(3):
            if k[j]==1:
                k[j]="+"
            else:
                k[j]="-"
        print(str(a)+k[0]+str(b)+k[1]+str(c)+k[2]+str(d)+"=7")
        break

Submission status: Accepted

Solution code:
A = list(input())
sign = ['+','-']
for i in range(2):
    for j in range(2):
        for k in range(2):
            if eval(A[0]+sign[i]+A[1]+sign[j]+A[2]+sign[k]+A[3]) == 7:
                print('{}{}{}{}{}{}{}=7'.format(A[0],sign[i],A[1],sign[j],A[2],sign[k],A[3]))
                exit()

Submission status: Accepted

Solution code:
a, b, c, d = [int(c) for c in input()]

done = False
ops = ['+', '-']
for op1 in ops:
    for op2 in ops:
        for op3 in ops:
            left = a
            left += b if op1 == '+' else -b
            left += c if op2 == '+' else -c
            left += d if op3 == '+' else -d
            if left == 7:
                done = True
                break
        if done:
            break
    if done:
        break
print('{a}{op1}{b}{op2}{c}{op3}{d}=7'.format(a=a, b=b, c=c, d=d, op1=op1, op2=op2, op3=op3))

Submission status: Accepted

Solution code:
import sys
S = input()
A = [int(a) for a in list(S)]
N = 4
crt = 7

for i in range(2**(N-1)):
  i_ = i
  j = 1
  tmp = A[0]
  while j < N:
    if i_ % 2 == 0:
      tmp += A[j]
    else:
      tmp -= A[j]
    i_ = i_>>1
    j += 1
  #print(tmp, i) 
  if tmp == crt:
    T = str(A[0])
    i_ = i
    j = 1
    while j < N:
      if i_ % 2 == 0:
        T += "+"
      else:
        T += "-"
      T += str(A[j])
      i_ = i_>>1
      j += 1
    T += "=7"
    print(T)
    sys.exit()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    num = list(map(int, readline().strip()))

    for bits in range(1 << 3):
        tmp = num[0]
        for i in range(3):
            if bits & (1 << i):
                tmp += num[i + 1]
            else:
                tmp -= num[i + 1]
        if tmp == 7:
            ans = [str(num[0])]
            for i in range(3):
                if bits & (1 << i):
                    ans.append('+')
                else:
                    ans.append('-')
                ans.append(str(num[i + 1]))
            ans.append('=7')
            ans = ''.join(ans)
            break

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools

S=input()

for i in itertools.product(["+","-"],repeat=3):
    ans=""
    for j in range(len(i)):
        if i[j]=="+":
            ans+=S[j]+i[j]
        elif i[j]=="-":
            ans+=S[j]+i[j]
    ans+=S[-1]
    sum_num=eval(ans)
    if sum_num==7:
        print(ans+"=7")
        break

Submission status: Accepted

Solution code:
S = list(input())

for i in range(2**3):
  ans = int(S[0])
  res = ["-","-","-"]
  for j in range(3):
    if ((i >> j) & 1):
      ans += int(S[j+1])
      res[j] = "+"
    else:
      ans -= int(S[j+1])
  if ans == 7:
    print(S[0]+res[0]+S[1]+res[1]+S[2]+res[2]+S[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])
ans=""
for x in [1,-1]:
  for y in [1,-1]:
    for z in [1,-1]:
      if A+B*x+C*y+D*z==7:
        if x==1:
          sx="+"
        else:
          sx="-"
        if y==1:
          sy="+"
        else:
          sy="-"
        if z==1:
          sz="+"
        else:
          sz="-"
        ans=str(A)+sx+str(B)+sy+str(C)+sz+str(D)+"=7"
print(ans)

Submission status: Accepted

Solution code:
import itertools
x=list(input())

for lst in itertools.product(['+','-'],repeat=3):
  sum=int(x[0])
  for i in range(3):
    if lst[i]=='+':
      sum+=int(x[i+1])
    else:
      sum-=int(x[i+1])
  if sum==7:
    print(x[0]+lst[0]+x[1]+lst[1]+x[2]+lst[2]+x[3]+'=7')
    break

Submission status: Accepted

Solution code:
op=["+","-"]
a,b,c,d=map(str,input())

for o1 in op:
  for o2 in op:
    for o3 in op:
      form= a+o1+b+o2+c+o3+d
      if eval(form)==7:
        print(form+"=7")
        exit()

Submission status: Accepted

Solution code:
ABCD = input()
A = int(ABCD[0])
B = int(ABCD[1])
C = int(ABCD[2])
D = int(ABCD[3])
for i in range(1):
    if A + B + C + D == 7:
        print(str(A) + "+" + str(B) + "+" + str(C) + "+" + str(D) + "=7")
        exit()
    if A - B + C + D == 7:
        print(str(A) + "-" + str(B) + "+" + str(C) + "+" + str(D) + "=7")
        exit()
    if A + B - C + D == 7:
        print(str(A) + "+" + str(B) + "-" + str(C) + "+" + str(D) + "=7")
        exit()
    if A + B + C - D == 7:
        print(str(A) + "+" + str(B) + "+" + str(C) + "-" + str(D) + "=7")
        exit()
    if A - B - C + D == 7:
        print(str(A) + "-" + str(B) + "-" + str(C) + "+" + str(D) + "=7")
        exit()
    if A - B + C - D == 7:
        print(str(A) + "-" + str(B) + "+" + str(C) + "-" + str(D) + "=7")
        exit()
    if A + B - C - D == 7:
        print(str(A) + "+" + str(B) + "-" + str(C) + "-" + str(D) + "=7")
        exit()
    if A - B - C - D == 7:
        print(str(A) + "-" + str(B) + "-" + str(C) + "-" + str(D) + "=7")
        exit()

Submission status: Accepted

Solution code:

ABCD = str(input())
A = ABCD[0]
B = ABCD[1]
C = ABCD[2]
D = ABCD[3]

for i in range(1):
    if int(A) + int(B) + int(C) + int(D) == 7:
        print(A + "+" + B + "+" + C + "+" + D +"=7")
        break
    if int(A) - int(B) + int(C) + int(D) == 7:
        print(A + "-" + B + "+" + C + "+" + D +"=7")
        break
    if int(A) + int(B) - int(C) + int(D) == 7:
        print(A + "+" + B + "-" + C + "+" + D +"=7")
        break
    if int(A) - int(B) - int(C) + int(D) == 7:
        print(A + "-" + B + "-" + C + "+" + D +"=7")
        break
    if int(A) + int(B) + int(C) - int(D) == 7:
        print(A + "+" + B + "+" + C + "-" + D +"=7")
        break
    if int(A) - int(B) + int(C) - int(D) == 7:
        print(A + "-" + B + "+" + C + "-" + D +"=7")
        break
    if int(A) + int(B) - int(C) - int(D) == 7:
        print(A + "+" + B + "-" + C + "-" + D +"=7")
        break
    if int(A) - int(B) - int(C) - int(D) == 7:
        print(A + "-" + B + "-" + C + "-" + D +"=7")
        break

Submission status: Accepted

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

import sys

def debug(*a):
    print(*a, file=sys.stderr)

s = input().strip()
v = [int(s[i]) for i in range(4)]
for x in range(8):
    a = v[0]
    for i in range(3):
        if (x >> i) & 1:
            a += v[i+1]
        else:
            a -= v[i+1]
    debug(f'x = {x}, a = {a}')
    if a == 7:
        s = ''
        for i in range(3):
            s += str(v[i])
            if (x >> i) & 1:
                s += '+'
            else:
                s += '-'
        s += str(v[3]) + '=7'
        print(s)
        sys.exit(0)

Submission status: Accepted

Solution code:
def dfs(i, f):
    if i == len(s) - 1:
        if eval(f) == 7:
            print(f + '=7')
            exit()
    else:
        dfs(i+1, f + '+' + s[i+1])
        dfs(i+1, f + '-' + s[i+1])
s = list(input())
dfs(0, s[0])

Submission status: Accepted

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

flag = [0]*3
tmp = 0
for i in range(8):
  flag[0]=(i>>2)&1
  flag[1]=(i>>1)&1
  flag[2]=(i)&1
  
  tmp = A +(-1)**flag[0]*B +(-1)**flag[1]*C +(-1)**flag[2]*D
  if tmp==7:
    ans=s[0]
    for j in range(3):
      if flag[j]:
        ans+="-"+s[j+1]
      else:
        ans+="+"+s[j+1]
    ans+="=7"
    print(ans)
    break

Submission status: Accepted

Solution code:
D = input()
A = [int(D[0]),int(D[1]),int(D[2]),int(D[3])]
for i in range(2**3):
    B = A[::1]
    C = ["+"]*3
    for j in range(3):
        if (i >> j) & 1:
            B[j+1] *= -1
            C[j] = "-"
    if sum(B) == 7:
        print(f"{A[0]}{C[0]}{A[1]}{C[1]}{A[2]}{C[2]}{A[3]}=7")
        exit()

Submission status: Accepted

Solution code:
a=list(map(int,list(input())))
s=[]
for i in range(2**3):
    calc=a[0]
    s=[str(a[0])]
    for j in range(3):
        if i>>j&1:
            calc+=a[j+1]
            s.append('+')
        else:
            calc-=a[j+1]
            s.append('-')
        s.append(str(a[j+1]))
    if calc==7:
        break
print(''.join(s)+'=7')

Submission status: Accepted

Solution code:
s = str(input())
n = 4
for bit in range(1 << (n-1)):
    f = s[0]
    for i in range(0,(n-1)):
        if bit & (1 << i):
            f += '+-' + s[i+1]
        else:
            f += '+' + s[i+1]
    #print(f)
    ans = sum(map(int,f.split('+')))
    if ans == 7:
        break
print(f.replace('+-','-')+'=7')