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:
N=list(input())
A=[]
for i in range(2**3):
   B=[0]*3
   for j in range(3):
      if i>>j&1:
         B[j]=1
   A.append(B)


for i in range(8):
   s=int(N[0])
   for j in range(3):
      if A[i][j]==0:
         s+=int(N[j+1])
      else:
         s-=int(N[j+1])
   if s==7:
      ans=[]
      for k in range(4):
         ans.append(N[k])
         if k<3:
            if A[i][k]==0:
               ans.append("+")
            else:
               ans.append("-")   
      print(''.join(ans)+'=7')   
      exit()

Submission status: Accepted

Solution code:
INF = float("inf") #const
MOD = 10**9+7 #const
MAX = 510000 #const

import fractions
import itertools

def main():
    s = input()
    n = len(s) - 1 #隙間の数
    ans = 0

    for i in range(2**n):
        op = ["-"] * n
        for j in range(n):
            if (i>>j)&1:
                op[j] = "+"
            tmp = ""
            for a,b in zip(s,op+[""]):
                tmp += a + b
            if eval(tmp) == 7:
                print(tmp + "=7")
                return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#079_C
S=input()
x=[int(s) for s in S]
for i in range(2**3):
    op=[]
    res=x[0]
    for j in range(3):
        if (i>>j)&1:
            op.append('+')
            res+=x[j+1]
        else:
            op.append('-')
            res-=x[j+1]
    if res==7:
        print(S[0]+op[0]+S[1]+op[1]+S[2]+op[2]+S[3]+'=7')
        exit()

Submission status: Accepted

Solution code:
num = [s.split()[0] for s in open(0)]
num = list(map(int, list(num[0])))


for i in range(len(num)**2):
    comb = ""
    sum_num = 0
    for k in range(len(num)):
        if (i  >> k) & 1:
            sum_num += num[k]
            if k == 0:
                comb += str(num[k])
            else:
                comb += "+" + str(num[k])  
        else:
            sum_num -= num[k]
            if k == 0:
                comb += str(num[k])
            else:
                comb += "-" + str(num[k])  
        
    if sum_num == 7:
        break
        
print(comb + "=7")

Submission status: Accepted

Solution code:
abcd = input()
a, b, c, d = int(abcd[0]), int(abcd[1]), int(abcd[2]), int(abcd[3])
ptn = []
for i in range(8):
    state = [0] * 3
    for j in range(3):
        state[j] = (i >> j) & 1
    ptn.append(state)

for op in ptn:
    val = a
    if op[0] == 0:
        val += b
        c1 = '+'
    else:
        val -= b
        c1 = '-'
    if op[1] == 0:
        val += c
        c2 = '+'
    else:
        val -= c
        c2 = '-'
    if op[2] == 0:
        val += d
        c3 = '+'
    else:
        val -= d
        c3 = '-'
    if val == 7:
        print(str(a) + c1 + str(b) + c2 + str(c) + c3 + str(d) + '=7')
        exit()

Submission status: Accepted

Solution code:
#!/usr/bin/env pypy3
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
import itertools


def main():
    S=input()
    
    def calc(L):
        temp=int(S[0])
        for i in range(3):
            a=1
            if L[i]==0:
                a=-1
            temp+=int(S[i+1])*a
        return temp
    
    ans=S[0]
    for ite in itertools.product([0,1], repeat=3):
        if calc(ite)==7:
            for i in range(3):
                if ite[i]==1:
                    ans+="+"
                else:
                    ans+="-"
                ans+=S[i+1]
            break
    print(ans+"=7")
    
            
        
    

main()

Submission status: Accepted

Solution code:
from sys import stdin
s = stdin.readline().rstrip()
for i in range(8):
    point = int(s[0])
    sin = s[0]
    for j in range(3):
        if ((i >> j) & 1):
            point += int(s[j+1])
            sin += "+"+s[j+1]
        else:
            point -= int(s[j+1])
            sin += "-"+s[j+1]
    if point == 7:
        print(sin+"=7")
        exit()

Submission status: Accepted

Solution code:
def main():
    abcd = input()

    for b in [format(i, '03b') for i in range(8)]:
        s = int(abcd[0])
        expr = abcd[0]
        for i in range(3):
            if b[i] == '0':
                s += int(abcd[i + 1])
                expr += '+'
            else:
                s -= int(abcd[i + 1])
                expr += '-'
            expr += abcd[i + 1]

        if s == 7:
            print(expr + '=7')
            exit()

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A, B, C, D = list(readline().decode('utf8').strip())
for ops in itertools.product(['+', '-'], repeat=3):
    eq = A + ops[0] + B + ops[1] + C + ops[2] + D
    x = eval(eq)
    if x == 7:
        break
ans = eq + '=7'
print(ans)

Submission status: Accepted

Solution code:
import sys
import itertools
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A, B, C, D = list(readline().decode('utf8').strip())
for ops in itertools.product(['+', '-'], repeat=3):
    eq = A + ops[0] + B + ops[1] + C + ops[2] + D
    x = eval(eq)
    if x == 7:
        break
ans = eq + '=7'
print(ans)

Submission status: Accepted

Solution code:
import sys
import itertools
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = readline().decode('utf8').strip()
A = int(N[0])
B = int(N[1])
C = int(N[2])
D = int(N[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))
else:
    print('{}-{}-{}-{}=7'.format(A, B, C, D))

Submission status: Accepted

Solution code:
S = input()
exp = len(S)-1

res = 0
for i in range(2**exp):
    eS = list("+".join(S))
    for j in range(exp):
        if (i >> j) & 1:
            eS[2*j+1] = "-"
    ans = "".join(eS)
    if eval(ans) == 7:
        res = ans + "=7"
        break

print(res)

Submission status: Accepted

Solution code:
s = list(map(int, input()))
n = 7 - s[0]
b, c, d = s[1], s[2], s[3]

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

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 main():
    a, b, c, d = input()
    for i in range(2**3):
        ls = ["+", "+", "+"]
        for j in range(len(ls)):
            if (i >> j) & 1:
                ls[j] = "-"
        sentence = a + ls[0] + b + ls[1] + c + ls[2] + d
        if eval(sentence) == 7:
            print(sentence + "=7")
            break


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
a = input()

for bit in range(2**3):
    x = a[0]
    for i in range(3):
        if ((bit>>i) & 1):
            x += "+"
        else:
            x += "-"
        x += a[i+1]
    if eval(x) == 7:
        print(str(x)+"=7")
        sys.exit()

Submission status: Accepted

Solution code:
def main():
    def plus(x, y):
        return x + y
    def minus(x, y):
        return x - y

    ans = ""
    func = {"+": plus, "-": minus}
    A, B, C, D = [int(v) for v in list(input())]
    for sym1 in ["+", "-"]:
        for sym2 in ["+", "-"]:
            for sym3 in ["+", "-"]:
                if func[sym3](func[sym2](func[sym1](A, B), C), D) == 7:
                    ans = str(A) + sym1 + str(B) + sym2 + str(C) + sym3 + str(D) + "=7"
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

def main():
    s = input()

    for i in {"+","-"}:
        for j in {"+","-"}:
            for k in {"+","-"}:
                eq = s[0]+i+s[1]+j+s[2]+k+s[3]
                if eval(eq) == 7:
                    print(eq + "=7")
                    exit()

import itertools
def main2():
    s = list(input())
    sign = ["+", "-"]
    ops = itertools.product(sign, repeat=3)

    for op in ops:
        tmp = ""
        for i in range(3):
            tmp += s[i]
            tmp += op[i]
        tmp += s[3]
        
        if eval(tmp) == 7:
            print(tmp + "=7")
            exit()

if __name__ == "__main__":
    main2()

Submission status: Accepted

Solution code:
X = input()
flag = ['+','-']
check = 0
for i in flag:
    if check == 1:
        break
    for j in flag:
        if check == 1:
            break
        for k in flag:
            ans = 0
            if i == '+':
                ans = int(X[0]) + int(X[1])
            else:
                ans = int(X[0]) - int(X[1])
            if i == '+':
                ans = int(X[0]) + int(X[1])
            else:
                ans = int(X[0]) - int(X[1])
            if j == '+':
                ans += int(X[2])
            else:
                ans -= int(X[2])
            if k == '+':
                ans += int(X[3])
            else:               
                ans -= int(X[3])
            if ans == 7:
                anslist = [X[0],i,X[1],j,X[2],k,X[3],'=','7']
                check = 1
print(''.join(anslist))

Submission status: Accepted

Solution code:
a, b, c, d = list( input())
 
op = ['+','-']
 
for i in op :
  for j  in op :
    for k in op :
      if eval( a+ i + b + j + c + k +d) == 7 :
        print('{}{}{}{}{}{}{}=7'.format( a,i, b,j,c,k,d))
        exit()

Submission status: Accepted

Solution code:
import copy
import sys
a = [int(i) for i in list(input())]

op = ['+', '-']
cmb = [[]]
for i in range(3): #op1-3
    tmp = len(cmb)
    for i in range(tmp):
        cmb.append(copy.deepcopy(cmb[i]))
    for j in range(2):
        for k in range(j * tmp, (j + 1) * tmp):
            cmb[k].append(op[j])

#print(cmb)

for i in range(len(cmb)):
    _sum = a[0]
    for j in range(1, 4):
        if cmb[i][j-1] == '+':
            _sum += a[j]
        else:
            _sum -= a[j]
    #print(cmb[i], _sum)
    if _sum == 7:
        ans = str(a[0])
        for j in range(1, 4):
            ans += cmb[i][j-1] + str(a[j])
        ans += '=7'
        print(ans)
        sys.exit()

Submission status: Accepted

Solution code:
A = input()

def bfs(i, f):
    if i == 3:
        if eval(f) == 7:
            print(f+'=7')
            exit()
        else:
            return None
    bfs(i+1, f+'+'+A[i+1])
    bfs(i+1, f+'-'+A[i+1])
    return None

print(bfs(0, A[0]))

Submission status: Accepted

Solution code:
a_list = input()

for i in range(8):
    ans = int(a_list[0])
    z = format(i, '03b')

    if z[0] == "0":
      ans = ans + int(a_list[1])
      op1 = "+"
    else:
      ans = ans - int(a_list[1])
      op1 = "-"

    if z[1] == "0":
      ans = ans + int(a_list[2])
      op2 = "+"
    else:
      ans = ans - int(a_list[2])
      op2 = "-"

    if z[2] == "0":
      ans = ans + int(a_list[3])
      op3 = "+"
    else:
      ans = ans - int(a_list[3])
      op3 = "-"
    
    if ans == 7:
      print("{}{}{}{}{}{}{}=7".format(
        a_list[0], op1, a_list[1], op2, a_list[2], op3, a_list[3]
        ))
      break

Submission status: Accepted

Solution code:
S = input()
num = list(S)

for i in range(2**3) :
    pat = str(format(i, '03b'))
    ans = int(num[0])
    op = ["0", "0", "0"]
    for j in range(3) :
        if pat[j] == "1" :
            ans += int(num[j+1])
            op[j] = "+"
        else :
            ans -= int(num[j+1])
            op[j] = "-"
    if ans == 7 :
        print("{}{}{}{}{}{}{}=7".format(num[0],op[0],num[1],op[1],num[2],op[2],num[3]))
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce
import sys
sys.setrecursionlimit(4100000)
from functools import lru_cache

#ここから書き始める
s = input()

def dfs(index, ret, op1, op2, op3):
    if index == 4:
        if ret == 7:
            print(s[0] + op1 + s[1] + op2 + s[2] + op3 + s[3] + "=7")
            sys.exit()
    if index == 1:
        dfs(index + 1, ret + int(s[index]), "+", op2, op3) or dfs(index + 1, ret - int(s[index]), "-", op2, op3)
    if index == 2:
        dfs(index + 1, ret + int(s[index]), op1, "+", op3) or dfs(index + 1, ret - int(s[index]), op1, "-", op3)
    if index == 3:
        dfs(index + 1, ret + int(s[index]), op1, op2, "+") or dfs(index + 1, ret - int(s[index]), op1, op2, "-")

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

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(a, end='')
	print('+', end='')
	print(b, end='')
	print('+', end='')
	print(c, end='')
	print('+', end='')
	print(d, end='')
	print('=7')
    
elif a+b+c-d == 7:
	print(a, end='')
	print('+', end='')
	print(b, end='')
	print('+', end='')
	print(c, end='')
	print('-', end='')
	print(d, end='')
	print('=7')
    
elif a+b-c+d == 7:
	print(a, end='')
	print('+', end='')
	print(b, end='')
	print('-', end='')
	print(c, end='')
	print('+', end='')
	print(d, end='')
	print('=7')
    
elif a-b+c+d == 7:
	print(a, end='')
	print('-', end='')
	print(b, end='')
	print('+', end='')
	print(c, end='')
	print('+', end='')
	print(d, end='')
	print('=7')
    
elif a+b-c-d == 7:
	print(a, end='')
	print('+', end='')
	print(b, end='')
	print('-', end='')
	print(c, end='')
	print('-', end='')
	print(d, end='')
	print('=7')
    
elif a-b-c+d == 7:
	print(a, end='')
	print('-', end='')
	print(b, end='')
	print('-', end='')
	print(c, end='')
	print('+', end='')
	print(d, end='')
	print('=7')
    
elif a-b+c-d == 7:
	print(a, end='')
	print('-', end='')
	print(b, end='')
	print('+', end='')
	print(c, end='')
	print('-', end='')
	print(d, end='')
	print('=7')
    
elif a-b-c-d == 7:
	print(a, end='')
	print('-', end='')
	print(b, end='')
	print('-', end='')
	print(c, end='')
	print('-', end='')
	print(d, end='')
	print('=7')

Submission status: Accepted

Solution code:
def solve():
    N = list(input().split())[0]
    a,b,c,d = int(N[0]),int(N[1]),int(N[2]),int(N[3])

    if a+b+c+d == 7:
        print('{0}+{1}+{2}+{3}=7'.format(a,b,c,d))
        return 

    if a+b+c-d == 7:
        print('{0}+{1}+{2}-{3}=7'.format(a,b,c,d))
        return 

    if a+b-c+d == 7:
        print('{0}+{1}-{2}+{3}=7'.format(a,b,c,d))
        return 

    if a-b+c+d == 7:
        print('{0}-{1}+{2}+{3}=7'.format(a,b,c,d))
        return 

    if a+b-c-d == 7:
        print('{0}+{1}-{2}-{3}=7'.format(a,b,c,d))
        return 

    if a-b+c-d == 7:
        print('{0}-{1}+{2}-{3}=7'.format(a,b,c,d))
        return 

    if a-b-c+d == 7:
        print('{0}-{1}-{2}+{3}=7'.format(a,b,c,d))
        return 

    if a-b-c-d == 7:
        print('{0}-{1}-{2}-{3}=7'.format(a,b,c,d))
        return 

# print(solve())

# テスト用

solve()

Submission status: Accepted

Solution code:
from itertools import product

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

formula = ''
for x,y,z in product(('+','-'), repeat=3):
    formula = '{}{}{}{}{}{}{}'.format(a,x,b,y,c,z,d)
    if eval(formula) == 7:
        break

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

Submission status: Accepted

Solution code:
s = list(input())

ops = ["-", "+"]

for i in range(0, 2**3):
    dig = (bin(i)[2:]).zfill(3)
    #print(dig)
    sum = int(s[0])
    for j in range(0, 3):
        x = -1 if int(dig[j]) == 0 else 1
        sum += int(s[j + 1]) * x
    if (sum == 7):
        print(s[0] + ops[int(dig[0])] + s[1] + ops[int(dig[1])] + s[2] +
              ops[int(dig[2])] + s[3] + "=7")
        break
    #print(sum)

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('{}+{}+{}+{}=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:
a, b, c, d = (int(i) for i in input())
op = ["+", "-"]
for op_1 in op:
    ans_1 = eval("{}{}{}".format(a, op_1, b))
    for op_2 in op:
        ans_2 = eval("{}{}{}".format(ans_1, op_2, c))
        for op_3 in op:
            if eval("{}{}{}".format(ans_2, op_3, d)) == 7:
                print("{}{}{}{}{}{}{}=7".format(a, op_1, b, op_2, c, op_3, d))
                exit()

Submission status: Accepted

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

op = ["+", "-"]

def calculate(n_1, n_2, op):
    if op == 0:
        return n_1 + n_2
    else:
        return n_1 - n_2

for i in range(2):
    ans_1 = calculate(a, b, i)
    for j in range(2):
        ans_2 = calculate(ans_1, c, j)
        for k in range(2):
            if calculate(ans_2, d, k) == 7:
                print("{}{}{}{}{}{}{}=7".format(a, op[i], b, op[j], c, op[k], d))
                exit()

Submission status: Accepted

Solution code:
a=list(input())

for i in range(2**3):
    status=[0]*3
    s=""
    for j in range(3):
        if ((i>>j)&1):
            status[j]="+"
        else:
            status[j]="-"
    for x,y in zip(a,status):
        s+=x
        s+=y
    s+=a[-1]
    if eval(s)==7:
        print(s+"=7")
        exit()

Submission status: Accepted

Solution code:
s = input()



for i in range(8):
    ans = int(s[0])
    f = s[0]
    for j in range(3):
        if i >> j & 1:
            ans += int(s[j + 1])
            f = f + "+" + s[j + 1]
        else:
            ans -= int(s[j + 1])
            f = f + "-" + s[j + 1]
    #print(bin(i), ans, f)
    if ans == 7:
        print(f + "=7")
        break

Submission status: Accepted

Solution code:
abcd = input()
ans_word = []

for i in range(2**3):
    ans = int(abcd[0])
    for j in range(3):
        #print(str(i) + ' ' + str(j))
        if((i>>j)&1 == 1):
            ans += int(abcd[j+1])
        else:
            ans -= int(abcd[j+1])
    #print(ans)
    if(ans == 7):
        for k in range(4):
            ans_word.append(abcd[k])
            if((i>>k)&1 == 1):
                ans_word.append('+')
            else:
                if(k < 3):
                    ans_word.append('-')
        ans_word.append("=7")
        print("".join(ans_word))
        break

Submission status: Accepted

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

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

elif ABCD[0] + ABCD[1] + ABCD[2] - ABCD[3] == 7:
    print(str(ABCD[0]) + "+" + str(ABCD[1]) + "+" +
          str(ABCD[2]) + "-" + str(ABCD[3]) + "="+"7")

elif ABCD[0] + ABCD[1] - ABCD[2] + ABCD[3] == 7:
    print(str(ABCD[0]) + "+" + str(ABCD[1]) + "-" +
          str(ABCD[2]) + "+" + str(ABCD[3]) + "="+"7")

elif ABCD[0] + ABCD[1] - ABCD[2] - ABCD[3] == 7:
    print(str(ABCD[0]) + "+" + str(ABCD[1]) + "-" +
          str(ABCD[2]) + "-" + str(ABCD[3]) + "="+"7")

elif ABCD[0] - ABCD[1] + ABCD[2] + ABCD[3] == 7:
    print(str(ABCD[0]) + "-" + str(ABCD[1]) + "+" +
          str(ABCD[2]) + "+" + str(ABCD[3]) + "="+"7")

elif ABCD[0] - ABCD[1] - ABCD[2] + ABCD[3] == 7:
    print(str(ABCD[0]) + "-" + str(ABCD[1]) + "-" +
          str(ABCD[2]) + "+" + str(ABCD[3]) + "="+"7")

elif ABCD[0] - ABCD[1] + ABCD[2] - ABCD[3] == 7:
    print(str(ABCD[0]) + "-" + str(ABCD[1]) + "+" +
          str(ABCD[2]) + "-" + str(ABCD[3]) + "="+"7")

elif ABCD[0] - ABCD[1] - ABCD[2] - ABCD[3] == 7:
    print(str(ABCD[0]) + "-" + str(ABCD[1]) + "-" +
          str(ABCD[2]) + "-" + str(ABCD[3]) + "="+"7")

Submission status: Accepted

Solution code:
from itertools import product
a,b,c,d = input()
for op1,op2,op3 in product(["+","-"],repeat=3):
    eq = a+op1+b+op2+c+op3+d
    if eval(eq) == 7:
        print(eq + "=7")
        break

Submission status: Accepted

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

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

def check(A,B,C,D):
    for i in [-1,1]:
        for j in [-1,1]:
            for k in [-1,1]:
                sum = A + (-1)*i*B + (-1)*j*C + (-1)*k*D
                
                if sum == 7:
                    return A,(-1)*i*B,(-1)*j*C,(-1)*k*D

a,b,c,d = check(A,B,C,D)
print('{}{:+}{:+}{:+}=7'.format(a,b,c,d))

Submission status: Accepted

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

for bit in range(8):
  flag=["+","+","+"]
  for i in range(3):
    if not bit>>(2-i) & 1 :
      A[i+1]=-A[i+1]
      flag[i]="-"
  if sum(A)==7:
    print("{}{}{}{}{}{}{}=7".format(A[0],flag[0],abs(A[1]),flag[1],abs(A[2]),flag[2],abs(A[3])))
    exit()
  for i in range(4):
    A[i]=abs(A[i])

Submission status: Accepted

Solution code:
s=input()
for i in range(2):
    for j in range(2):
        for k in range(2):
            sum=int(s[0])
            if i==0:
                sum+=int(s[1])
            else:
                sum-=int(s[1])
            if j==0:
                sum+=int(s[2])
            else:
                sum-=int(s[2])
            if k==0:
                sum+=int(s[3])
            else:
                sum-=int(s[3])
            if sum==7:
                a="-"
                b="-"
                c="-"
                if i==0:
                    a="+"
                if j==0:
                    b="+"
                if k==0:
                    c="+"
                print(s[0]+a+s[1]+b+s[2]+c+s[3]+"=7")
                exit()

Submission status: Accepted

Solution code:
ABCD = list(map(int, list(input())))
op_cnt = len(ABCD) -1
for i in range(2 ** op_cnt):
  ans_str = str(ABCD[0]) 
  ans = ABCD[0]
  op = ["-"]* op_cnt
  for j in range(op_cnt):
    if ((i >> j) & 1):
      op[op_cnt- j - 1] = "+"
  for i, f in enumerate(op):
    if f == "+":
      ans += ABCD[i+1]
      ans_str += "+" + str(ABCD[i+1])
    else:
      ans -= ABCD[i+1]
      ans_str += "-" + str(ABCD[i+1])
  if ans == 7:
    print(ans_str + "=7")
    break

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s = input()
op = ["-","+"]
for i in range(2):
    for j in range(2):
        for k in range(2):
            com = s[0]+op[i]+s[1]+op[j]+s[2]+op[k]+s[3]
            if eval(com) ==7:
                print(com + "=7")
                exit(0)

Submission status: Accepted

Solution code:
s=input()
a,b,c,d=int(s[0]),int(s[1]),int(s[2]),int(s[3])
if a+b+c+d==7:print(a,'+',b,'+',c,'+',d,'=',7, sep='')
elif a+b+c-d==7:print(a,'+',b,'+',c,'-',d,'=',7, sep='')
elif a+b-c+d==7:print(a,'+',b,'-',c,'+',d,'=',7, sep='')
elif a-b+c+d==7:print(a,'-',b,'+',c,'+',d,'=',7, sep='')
elif a+b-c-d==7:print(a,'+',b,'-',c,'-',d,'=',7, sep='')
elif a-b-c+d==7:print(a,'-',b,'-',c,'+',d,'=',7, sep='')
elif a-b+c-d==7:print(a,'-',b,'+',c,'-',d,'=',7, sep='')
elif a-b-c-d==7:print(a,'-',b,'-',c,'-',d,'=',7, sep='')

Submission status: Accepted

Solution code:
a=input()
op=list("+-")
flag = False
for i in op:
    for j in op:
        for k in op:
            s = a[0]+i+a[1]+j+a[2]+k+a[3]
            if eval(s) == 7:
                flag = True
                break
        if flag:
            break
    if flag:
        break
print(s+"=7")

Submission status: Accepted

Solution code:
S=input()

for i in range(2**3):
    p=['-']*3
    ans=''
    for j in range(3):
        if((i>>j)&1):
            p[j]='+'
    for j,k in zip(S,p+['']):
        ans+=j+k
    if(eval(ans)==7):
        print(ans+'=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("%d+%d+%d+%d=7"%(a,b,c,d))
elif a+b+c-d==7:
    print("%d+%d+%d-%d=7"%(a,b,c,d))
elif a+b-c+d==7:
    print("%d+%d-%d+%d=7"%(a,b,c,d))
elif a+b-c-d==7:
    print("%d+%d-%d-%d=7"%(a,b,c,d))
elif a-b+c+d==7:
    print("%d-%d+%d+%d=7"%(a,b,c,d))
elif a-b+c-d==7:
    print("%d-%d+%d-%d=7"%(a,b,c,d))
elif a-b-c+d==7:
    print("%d-%d-%d+%d=7"%(a,b,c,d))
else:
    print("%d-%d-%d-%d=7"%(a,b,c,d))

Submission status: Accepted

Solution code:
n=input()
num=[]
for i in range(4):
    num.append(int(n[i]))
o=["+","+","+"]
op=[1,1,1]
def ans():
    return num[0]+op[0]*num[1]+op[1]*num[2]+op[2]*num[3]
if ans()!=7:
    for i in range(3):
        op[i]=-1
        if ans()==7:
            break
        op[i]=1
if ans()!=7:  
    for i in range(-1,2):
        op[i]=-1
        op[i+1]=-1
        if ans()==7:
            break
        op[i]=1
        op[i+1]=1
if ans()!=7:
    for i in range(3):
        op[i]=-1
for i in range(3):
    if op[i]==-1:
        o[i]="-"
print(n[0]+o[0]+n[1]+o[1]+n[2]+o[2]+n[3]+"=7")

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')
else :
    print(S[0]+'-'+S[1]+'-'+S[2]+'-'+S[3]+'=7')

Submission status: Accepted

Solution code:
import itertools
s=list(input())
for x,y,z in list(itertools.product(["+","-"],repeat=3)):
    if int(s[0])+int(x+s[1])+int(y+s[2])+int(z+s[3])==7:
        print(s[0]+x+s[1]+y+s[2]+z+s[3]+"=7")
        break

Submission status: Accepted

Solution code:
import sys
x = input()
for i in ['+','-']:
    for j in ['+','-']:
        for k in ['+','-']:
            ans_str = x[0]+i+x[1]+j+x[2]+k+x[3]
            ans = eval(ans_str)
            if ans == 7:
                print(ans_str+'=7')
                sys.exit()

Submission status: Accepted

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

for i in range(1<<(n-1)):
    sum = int(S[0])
    eq = S[0]
    for j in range(n-1):
        if (i>>j) & 1:
            sum += int(S[j+1])
            eq += "+"
            eq += S[j+1]
        else:
            sum -= int(S[j+1])
            eq += "-"
            eq += S[j+1]
    if sum==7:
        print(eq+"=7")
        break

Submission status: Accepted

Solution code:
def get_operator(n):
    if n == -1:
        return "-"
    return "+"


def main():
    ticket_num = input()
    numbers = [int(ticket_num[i]) for i in range(len(ticket_num))]
    operator = [1, -1]
    flag = True
    for op1 in operator:
        for op2 in operator:
            for op3 in operator:
                if numbers[0] + op1 * numbers[1] + op2 * numbers[2] + op3 * numbers[3] == 7 and flag:
                    print(ticket_num[0] + get_operator(op1) + ticket_num[1] + get_operator(op2) + ticket_num[2] +
                          get_operator(op3) + ticket_num[3] + "=7")
                    flag = False


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()

for bit in range(2 ** 3):
    ans = int(S[0])
    for i in range(3):
        if bit & (1 << i):
            ans += int(S[i+1])
        else:
            ans -= int(S[i+1])

    if ans == 7:
        print(S[0], end='')
        for i in range(3):
            if bit & (1 << i):
                print('+' + S[i+1], end='')
            else:
                print('-' + S[i+1], end='')
        print('=7', end='')
        exit()

Submission status: Accepted

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

s = list(input())
for i in range(8):
    siki = s[0]
    for j in range(3):
        if i&(1<<j):
            siki+='+'+s[j+1]
        else:
            siki+='-'+s[j+1]
    g=int(siki[0])
    for j in range(1,6,2):
        if siki[j]=='+':
            g+=int(siki[j+1])
        else:
            g-=int(siki[j+1])
    if g==7:
        siki+="=7"
        print(*siki,sep="")
        break

Submission status: Accepted

Solution code:
s = list(input())
for i in range(8):
    siki = s[0]
    for j in range(3):
        if i&(1<<j):
            siki+='+'+s[j+1]
        else:
            siki+='-'+s[j+1]
    g=int(siki[0])
    for j in range(1,6,2):
        if siki[j]=='+':
            g+=int(siki[j+1])
        else:
            g-=int(siki[j+1])
    if g==7:
        print(*siki,sep="",end="")
        print("=7")
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
math = input()
for i in range(2**3):
  op = format(i,"03b")
  op = op.replace('1', '+').replace('0', '-')
  ans = math[0]+op[0]+math[1]+op[1]+math[2]+op[2]+math[3]
  if eval(ans) == 7:
    print(ans+"=7")
    break