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:
s = input()
l = len(s)

for i in range(2**(l-1)):
    f = ""
    for j in range(l-1):
        f += s[j]
        if i & (1 << j):
            f += "+"
        else:
            f += "-"
        if j == l-2:
             f += s[l-1]
    if eval(f)==7:
        print(f+"=7")
        break

Submission status: Accepted

Solution code:
l = list(input())

from itertools import product
t = list(product('+-', repeat=3))

for i in range(len(t)):
    temp = l[0]+t[i][0]+l[1]+t[i][1]+l[2]+t[i][2]+l[3]
    if eval(temp) == 7:
        print(temp + '=7')
        break

Submission status: Accepted

Solution code:
from itertools import product
S = input()
l = ["+", "-"]
for k in list(product(l, repeat=3)):
  ans = S[0] + k[0] + S[1] + k[1] + S[2] + k[2] + S[3]
  if eval(ans) == 7:
    print(ans+"=7")
    exit()

Submission status: Accepted

Solution code:
s = input()
l = len(s)
ans = 0
for i in range(2**(l-1)):
    e = ""
    for j in range(l):
        if ((i >> j) & 1):
            e += s[j] + "+"
        else:
            e += s[j] + "-"
    if eval(e[:-1]) == 7:
        print(e[:-1]+'=7')
        break

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(2 ** 3):
    ans = N[0]
    ans_final = list(Nset[0])
    for j in range(3):
        if (i >> j) & 1:
            ans += N[j + 1]
            ans_final.append('+')
            ans_final.append(Nset[j+1])
        else:
            ans -= N[j + 1]
            ans_final.append('-')
            ans_final.append(Nset[j+1])
    if ans == 7:
        ans_final.append('=7')
        print(''.join(ans_final))
        break

Submission status: Accepted

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

f = [1,1,1,-1,-1,-1]
def m(n):
    if n == -1:
        return "-"
    else:
        return "+"

for v in itertools.permutations(f,3):
    if int(n[0]) + (v[0] * int(n[1])) + (v[1] * int(n[2])) + (v[2] * int(n[3])) == 7:
        print(n[0],m(v[0]),n[1],m(v[1]),n[2],m(v[2]),n[3],"=7", sep="")
        break

Submission status: Accepted

Solution code:
import itertools
ABCD=list(input())
calc=["+","-"]*3
conb=set(itertools.permutations(calc, 3))

for c in conb:
    total=int(ABCD[0])
    for n,i in enumerate(c):
        if(i=='+'):
            total+= int(ABCD[n+1])
        else:
            total-=int(ABCD[n+1])
    if(total==7):
        print("{0}{1}{2}{3}{4}{5}{6}=7".format(ABCD[0],c[0],ABCD[1],c[1],ABCD[2],c[2],ABCD[3]))
        break

Submission status: Accepted

Solution code:
def resolve():
    S = list(map(int, input()))
    a, b, c, d = S[0], S[1], S[2], S[3]
    op = ['+', '-']
    for i in op:
        moji_i = str(a)
        sum_i = a
        sum_i += b if i == '+' else -b
        moji_i += i + str(b)
        for j in op:
            sum_j = sum_i + c if j == '+' else sum_i-c
            moji_j = moji_i + j + str(c)
            for k in op:
                sum = sum_j + d if k == '+' else sum_j-d
                moji = moji_j + k + str(d)
                if sum == 7:
                    moji += '=7'
                    return print(moji)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import sys
def saiki(s, siki, n):
  if n == 4 and eval(siki) == 7:
    print(siki+'=7')
    sys.exit(0)
  elif n == 4:
    return

  saiki(s, siki + '+' + s[n], n+1)
  saiki(s, siki + '-' + s[n], n+1)
  

  
s = input()

siki = s[0]

saiki(s, siki, 1)

Submission status: Accepted

Solution code:
ABCD = input()
n = len(ABCD)
for i in range(1<<(n-1)):
  s = int(ABCD[0])
  for j in range(n-1):
    if i>>j & 1:  # T: +, F: -
      s += int(ABCD[j+1])
    else:
      s -= int(ABCD[j+1])
  if s == 7:
    break
r = [ABCD[0]]
for k in range(n-1):
  if i>>k & 1:
    r.append('+')
  else:
    r.append('-')
  r.append(ABCD[k+1])
print('{}=7'.format(''.join(r)))

Submission status: Accepted

Solution code:
li = list(input())
pm = []
for i in range(8):
    l = []
    for j in range(3):
        if ((i>>j) & 1):
            l.append('+')
        else:
            l.append('-')
    pm.append(l)
lia = [0]*4
lisans =[0]
for i in range(4):
    lia[i] = int(li[i])
def search(lis):
    k = lia[0]
    for i in range(3):
        if lis[i] == '+':
            k += lia[i+1]
        if lis[i] == '-':
            k -=lia[i+1]
    return k
for i in range(8):
    lis = pm[i]
    ans = search(lis)
    if ans == 7:
        lisans = lis
        break
vic = [li[0]]
for i in range(3):
    vic.append(lisans[i])
    vic.append(li[i+1])
vic.append('=')
vic.append('7')
print(''.join(vic))

Submission status: Accepted

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

nums = list(map(int, list(input().rstrip('\r\n'))))
ans_op = [''] * 3
for bit in range(2**3):
    total = 0
    tmp = [''] * 3
    for i in range(3):
        if i == 0:
            total += nums[i]
        if (bit >> i) & 1:
            total += nums[i+1]
            tmp[i] = '+'
        else:
            total -= nums[i+1]
            tmp[i] = '-'
    if total == 7:
       ans_op = tmp
       break
ans = ''
for i in range(3):
    if i == 0:
        ans += (str(nums[i]))
    ans += (ans_op[i] + str(nums[i+1]))
ans += '=7'
print(ans)

Submission status: Accepted

Solution code:
a,b,c,d = tuple(input())
import itertools
n = 3
for i in itertools.product(['-','+'], repeat=n):
    ans = a + i[0] + b + i[1] + c + i[2] + d
    if eval(ans) == 7:
        print(ans+'=7')
        exit()

Submission status: Accepted

Solution code:
a,b,c,d = [int(i) for i in input()]
if a+b+c+d == 7:
  ans = [str(a),'+',str(b),'+',str(c),'+',str(d),'=','7']
  print(''.join(ans))
  exit()
if a+b+c-d == 7:
  ans = [str(a),'+',str(b),'+',str(c),'-',str(d),'=','7']
  print(''.join(ans))
  exit()
if a+b-c-d == 7:
  ans = [str(a),'+',str(b),'-',str(c),'-',str(d),'=','7']
  print(''.join(ans))
  exit()
if a-b-c-d == 7:
  ans = [str(a),'-',str(b),'-',str(c),'-',str(d),'=','7']
  print(''.join(ans))
  exit()
if a-b+c-d == 7:
  ans = [str(a),'-',str(b),'+',str(c),'-',str(d),'=','7']
  print(''.join(ans))
  exit()
if a+b-c+d == 7:
  ans = [str(a),'+',str(b),'-',str(c),'+',str(d),'=','7']
  print(''.join(ans))
  exit()
if a-b+c+d == 7:
  ans = [str(a),'-',str(b),'+',str(c),'+',str(d),'=','7']
  print(''.join(ans))
  exit()
if a-b-c+d == 7:
  ans = [str(a),'-',str(b),'-',str(c),'+',str(d),'=','7']
  print(''.join(ans))
  exit()

Submission status: Accepted

Solution code:
A=input()
n=[int(a) for a in A]
if n[0]+n[1]+n[2]+n[3]==7:
    print(str(n[0])+'+'+str(n[1])+'+'+str(n[2])+'+'+str(n[3])+'=7')
elif n[0]+n[1]+n[2]-n[3]==7:
    print(str(n[0]) + '+' + str(n[1]) + '+' + str(n[2]) + '-' + str(n[3]) + '=7')
elif n[0] + n[1] - n[2] + n[3] == 7:
    print(str(n[0]) + '+' + str(n[1]) + '-' + str(n[2]) + '+' + str(n[3]) + '=7')
elif n[0] + n[1] - n[2] - n[3] == 7:
    print(str(n[0]) + '+' + str(n[1]) + '-' + str(n[2]) + '-' + str(n[3]) + '=7')
elif n[0] - n[1] + n[2] + n[3] == 7:
    print(str(n[0]) + '-' + str(n[1]) + '+' + str(n[2]) + '+' + str(n[3]) + '=7')
elif n[0] - n[1] + n[2] - n[3] == 7:
    print(str(n[0]) + '-' + str(n[1]) + '+' + str(n[2]) + '-' + str(n[3]) + '=7')
elif n[0] - n[1] - n[2] + n[3] == 7:
    print(str(n[0]) + '-' + str(n[1]) + '-' + str(n[2]) + '+' + str(n[3]) + '=7')
elif n[0] - n[1] - n[2] - n[3] == 7:
    print(str(n[0]) + '-' + str(n[1]) + '-' + str(n[2]) + '-' + str(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("{}+{}+{}+{}=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 = map(int, list(input()))
for i in (-1,1):
  for j in (-1,1):
    for k in (-1,1):
      if a + i * b + j * c + k * d == 7:
        op1 = '+' * ((1+i)//2) + '-' * ((1-i)//2)
        op2 = '+' * ((1+j)//2) + '-' * ((1-j)//2)
        op3 = '+' * ((1+k)//2) + '-' * ((1-k)//2)
        print(str(a)+op1+str(b)+op2+str(c)+op3+str(d)+'=7')
        exit()

Submission status: Accepted

Solution code:
a = [str(i) for i in input()]
op = ["+", "+", "+"]

for bit in range(2 ** len(op)):
	v = op.copy()
	for i in range(len(op)):
		if (bit >> i) & 1:
			v[i] = "-"
			
	if eval(a[0] + v[0] + a[1] + v[1] + a[2] + v[2] + a[3]) == 7:
		print(a[0] + v[0] + a[1] + v[1] + a[2] + v[2] + a[3] + "=7")
		exit()

Submission status: Accepted

Solution code:
#abc079 c
s=input()


def dfs(i,num,ans):
    #print(i,num,ans)
    if i==3:
        if num==7:
            global memo
            memo=ans
        return 0
    dfs(i+1,num+int(s[i+1]),ans+"+"+str(s[i+1]))
    dfs(i+1,num-int(s[i+1]),ans+"-"+str(s[i+1]))
    return 0

memo=""
dfs(0,int(s[0]),s[0])
memo+="=7"
print(memo)

Submission status: Accepted

Solution code:
a,b,c,d = map(int,list(input()))
bb,cc,dd = '','',''
op = [1,-1]

for i in op:
	for j in op:
		for k in op:
			bb,cc,dd = i*b,j*c,k*d
			if a+bb+cc+dd == 7:
				if bb >= 0:
					bb = '+'+ str(b)
				if cc >= 0:
					cc = '+'+ str(c)
				if dd >= 0:
					dd = '+'+ str(d)
				ans = str(a)+str(bb)+str(cc)+str(dd)+'=7'

print(ans)

Submission status: Accepted

Solution code:
# Author: cr4zjh0bp
# Created: Thu Mar 12 15:41:39 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

from itertools import permutations

s = ns()

for op in range(2 ** 3):
    res = int(s[0])
    for i in range(3):
        if op >> i & 1:
            res += int(s[i + 1])
        else:
            res -= int(s[i + 1])
    if res == 7:
        print(s[0], end="")
        for i in range(3):
            print('+' if op >> i & 1 else '-', end="")
            print(s[i + 1], end="")
        print("=7")
        break

Submission status: Accepted

Solution code:
s = input()
l = len(s)
ans = ""

for bit in range(2**(l-1)):
  formula = ""
  for i in range(l):
    formula += s[i]
    if ((bit>>i) & 1) > 0:
      formula += "+"
    else:
      formula += "-"
  formula = formula[:len(formula)-1]
  if eval(formula) == 7:
    ans = formula+"=7"
    break
print(ans)

Submission status: Accepted

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

op1 = "+"
op2 = "+"
op3 = "+"

wa = sum(n)

if wa == 7:
    print(str(n[0])+op1+str(n[1])+op2+str(n[2])+op3+str(n[3])+"=7")
else:
    if wa - n[1]*2 == 7:
        op1 = "-"
    elif wa - n[2]*2 == 7:
        op2 = "-"
    elif wa -n[3]*2 == 7:
        op3 = "-"
    elif wa - n[1]*2 - n[2]*2 == 7:
        op1 = "-"
        op2 = "-"
    elif wa - n[1]*2 - n[3]*2 == 7:
        op1 = "-"
        op3 = "-"
    elif wa - n[2]*2 - n[3]*2 == 7:
        op2 = "-"
        op3 = "-"
    else:
        op1 = "-"
        op2 = "-"
        op3 = "-"

    print(str(n[0])+op1+str(n[1])+op2+str(n[2])+op3+str(n[3])+"=7")

Submission status: Accepted

Solution code:
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:
    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:
moji = list(input())
x = len(moji) -1
for i in range(2**x):
    ope = ['-'] * 3
    formula = ''
    for j in range(x):
        if (i>>j)&1:
            ope[j] = '+'
    for mo,op in zip(moji, ope+['']):
        formula += (mo+op)
    if eval(formula) == 7:
        print(formula, '=7', sep='')
        break

Submission status: Accepted

Solution code:
abcd = input()
l = len(abcd)

ans = ''
for i in range(2**(l-1)):
    s = int(abcd[0])
    tasi = abcd[0]
    for j in range(l-1):
        if i & 1<<j > 0:
            s += int(abcd[j+1])
            tasi += '+' + abcd[j+1]
        else:
            s -= int(abcd[j+1])
            tasi += '-' + abcd[j+1]
    if s == 7:
        ans = tasi + '=7'
print(ans)

Submission status: Accepted

Solution code:
n = input()

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

e = [1, -1]

ans = [0] * 3
for i in e:
  for j in e:
    for k in e:
      if a + b*i + c*j + d*k == 7:
        ans[0] = i
        ans[1] = j
        ans[2] = k

fugo = []
for i in ans:
  if i == 1:
    fugo.append("+")
  else:
    fugo.append("-")

print(str(a) + fugo[0] + str(b) + fugo[1] + str(c) + fugo[2] + str(d) + "=7")

Submission status: Accepted

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

for op1 in range(2):
    for op2 in range(2):
        for op3 in range(2):
            sum = A + (-1)**op1*B + (-1)**op2*C + (-1)**op3*D
            if sum == 7:
                ans = str(A)+oper[op1]+str(B)+oper[op2]+str(C)+oper[op3]+str(D)+'=7'
                break
print(ans)

Submission status: Accepted

Solution code:
s = list(map(int, input()))
ans = 0
for i in range(2):
    for j in range(2):
        for k in range(2):
            if i == 0:
                c = s[0] + s[1]
            else:
                c = s[0] - s[1]
            if j == 0:
                c += s[2]
            else:
                c -= s[2]
            if k == 0:
                c += s[3]
            else:
                c -= s[3]    
            if c == 7:
                ans = [i, j, k]
                
for i in range(3):
    print(str(s[i]), end = "")
    if ans[i] == 0:
        print("+", end = "")
    else:
        print("-", end = "")
print(str(s[3]) + "=7")

Submission status: Accepted

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

sign = '+-'
for i in range(2):
    for j in range(2):
        for k in range(2):
            siki = a+sign[i]+b+sign[j]+c+sign[k]+d
            ans = eval(siki)
            if ans == 7 :
                print(siki + '=7')
                sys.exit()

Submission status: Accepted

Solution code:
a,b,c,d = list(input())
sign = '+-'
for i in range(2):
    for j in range(2):
        for k in range(2):
            if eval(a+sign[i]+b+sign[j]+c+sign[k]+d) == 7:
                print(str(a+sign[i]+b+sign[j]+c+sign[k]+d) + '=7')
                exit()

Submission status: Accepted

Solution code:
str_input = list(input())
for i in range(2**3):
    ope = ['-'] * 3
    siki = ''
    for j in range(3):
        if(i>>j)&1:
            ope[j] = '+'
    for moji, op in zip(str_input, ope+['']):
        siki +=(moji+op)
    ans = eval(siki)
    if ans == 7:
        print(siki + '=7')
        break

Submission status: Accepted

Solution code:
a,b,c,d = list(input())
n = 2 ** 3
bit_pattern = []
for i in range(n):
    bit_flg = ["+"] * 3
    for j in range(n):
        if(i >> j & 1) == 1:
            bit_flg[j] = "-"
    bit_pattern.append(bit_flg)
for k in range(len(bit_pattern)):
    if eval(a + bit_pattern[k][0] + b + bit_pattern[k][1] + c + bit_pattern[k][2] + d) == 7:
        print(a+bit_pattern[k][0]+b+bit_pattern[k][1]+c+bit_pattern[k][2]+d+"=7")
        break

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def print_matrix(mat):
    for i in range(len(mat)):
        print(*mat[i])


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
# sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


# show_flg = True
show_flg = False


def main():
    s = S()
    N = len(s)

    for i in range(2):
        for j in range(2):
            for k in range(2):
                A = int(s[0])
                B = int(s[1])
                C = int(s[2])
                D = int(s[3])
                ans = A
                op1 = '+' if i == 0 else '-'
                op2 = '+' if j == 0 else '-'
                op3 = '+' if k == 0 else '-'
                ans = ans + B if i == 0 else ans - B
                ans = ans + C if j == 0 else ans - C
                ans = ans + D if k == 0 else ans - D
                if ans == 7:
                    print(s[0] + op1 + s[1] + op2 + s[2] + op3 + s[3] + '=7')
                    return

    print(-1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools
L = list(input())
sm = ['+','-']
SM = list(itertools.product(sm,repeat=3))

for i,j,k in SM:
    if eval(L[0]+i+L[1]+j+L[2]+k+L[3])==7:
        print(L[0]+i+L[1]+j+L[2]+k+L[3]+'=7')
        exit()

Submission status: Accepted

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

for i in range(2**op_cnt):
    op = ['-'] * op_cnt
    siki = ''
    for j in range(op_cnt):
        if ((i>>j)&1):
            op[op_cnt-1-j] = '+'
    for moji, ope in zip(n, op+['']):
        siki += (moji+ope)
    if eval(siki) == 7:
        print(siki + '=7')
        break

Submission status: Accepted

Solution code:
a,b,c,d=input()
for i in range(2**3):
    ls=['+','+','+']
    for j in range(len(ls)):
        if (i>>j)&1:
            ls[j]='-'
    if eval(a+ls[0]+b+ls[1]+c+ls[2]+d) == 7:
        print(a+ls[0]+b+ls[1]+c+ls[2]+d+"=7")
        break

Submission status: Accepted

Solution code:
a, b, c, d = [int(x) for x in input()]
ops = '+-'
for op1 in ops:
    for op2 in ops:
        for op3 in ops:
            tmp = a
            tmp = tmp + b if op1 == '+' else tmp - b
            tmp = tmp + c if op2 == '+' else tmp - c
            tmp = tmp + d if op3 == '+' else tmp - d
            if tmp == 7:
                print(str(a) + op1 + str(b) + op2 + str(c) + op3 + str(d) + "=7")
                exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
s = [int(c) for c in S]
def to_s(a):
  if a>=0:
    return "+"+str(a)
  return str(a)

for b in [-s[1],s[1]]:
  for c in [-s[2],s[2]]:
    for d in [-s[3],s[3]]:
      if s[0]+b+c+d == 7:
        print(S[0]+to_s(b)+to_s(c)+to_s(d)+"=7")
        exit()

Submission status: Accepted

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

def pm_hantei(n,l_pm):
  return "+"*(l_pm[n]==0)+"-"*(l_pm[n]==1)


j=2**(4-1)
for k in range(j):
  b_str = format(k,"0{}b".format(4-1))
  l_pm = [ int(b_str[i]) for i in range(len(b_str)) ]
  wa = a + b*(-1)**(l_pm[0]) + c*(-1)**(l_pm[1]) + d*(-1)**(l_pm[2])
  

  if wa == 7:
    print("{}{}{}{}{}{}{}=7".format(a,pm_hantei(0,l_pm),b,pm_hantei(1,l_pm),c,pm_hantei(2,l_pm),d ) )
    break
  else:
    continue

Submission status: Accepted

Solution code:
s=list(input())
a=["+"]*3
d=[]
for ss,aa in zip(s,a):
    d.append(ss)
    d.append(aa)
d.append(s[-1])
import copy
for i in range(2**3):
    dd=copy.deepcopy(d)
    for j in range(3):
        if ((i>>j)&1):
            dd[2*j+1]="-"
    st="".join(dd)
    if eval(st)==7:
        print("{}{}".format(st,"=7"))
        exit()

Submission status: Accepted

Solution code:
# Problem C - Train Ticket ビット全探索の問題

# input process
Num = input()
ABCD = [Num[0], Num[1], Num[2], Num[3]]

# initialization
opt_list = []
for i in range(8):
    opt = [0, 0, 0]
    for j in range(3):
        if ((i>>j)&1):
            opt[3-j-1] = 1
    opt_list.append(opt)

# bit search start
for opt in opt_list:
    math_formula = ""
    for i in range(3):
        if opt[i]==1:
            math_formula += ABCD[i] + "+"
        else:
            math_formula += ABCD[i] + "-"
    math_formula += ABCD[3]
    if eval(math_formula)==7:
        print(math_formula+"=7")
        break

Submission status: Accepted

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

def dfs(i,s,sum):
    if i==3:
        if sum==7:
            print(s+'=7')
            exit()
    else:
        dfs(i+1,s+'-'+str(l[i+1]),sum-l[i+1])
        dfs(i+1,s+'+'+str(l[i+1]),sum+l[i+1])
    return -1

dfs(0,str(l[0]),l[0])

Submission status: Accepted

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

n=3
for i in range(2**n):
    s = str(l[0])
    sum_s = l[0]
    for j in range(n):
        #j桁目が1の時
        if (i>>j)&1:
            s+='+'+str(l[j+1])
            sum_s+=l[j+1]
        #ｊ桁目が0の時
        else:
            s+='-'+str(l[j+1])
            sum_s-=l[j+1]

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

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())
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:
nums=[int(i) for i in input()]
ops=[1,-1]
ans=-1
for op1 in ops:
  for op2 in ops:
    for op3 in ops:
      if nums[0]+op1*nums[1]+op2*nums[2]+op3*nums[3]==7:
        ans=''+str(nums[0])
        ans+='+' if op1==1 else '-'
        ans+=str(nums[1])
        ans+='+' if op2==1 else '-'
        ans+=str(nums[2])
        ans+='+' if op3==1 else '-'
        ans+=str(nums[3])
        ans+='=7'
print(ans)

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    s = input()

    op = ['+1', '-1']

    for i in op:
        for j in op:
            for k in op:
                if int(s[0]) + int(s[1])*int(i) + int(s[2])*int(j) + int(s[3])*int(k) == 7:
                    print(s[0] + i[0] + s[1] + j[0] +
                          s[2] + k[0] + s[3] + '=7')
                    exit()

Submission status: Accepted

Solution code:
def solve():
    n = list(input())
    n = [ord(c) - ord('0') for c in n]
    sign = ['-', '+']

    for i in range(2):
        for j in range(2):
            for k in range(2):
                t = n[0]
                t += n[1] * (i * 2 - 1)
                t += n[2] * (j * 2 - 1)
                t += n[3] * (k * 2 - 1)
                if t == 7:
                    print('{}{}{}{}{}{}{}=7'.format(n[0], sign[i], n[1], sign[j], n[2], sign[k], n[3]))
                    return


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
A, B, C, D = list(input())
import itertools

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

print(eq + "=7")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
tmp = list(input())

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

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:

num = list(map(int, list(input())))
for bit in range(1 << 3):
    res = num[0]
    ans = str(num[0])
    for i in range(3):
        res += (-1)**(bit >> i & 1) * num[i+1]
        ans += ('-' if bit >> i & 1 else '+') + str(num[i+1])
    if res == 7:
        print(ans + '=7')
        exit()

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

abcd = list(STR())
for i in range(4):
    abcd[i] = int(abcd[i])
op = ['+', '-']
ops = ['+', '+', '+']
for ops[0] in op:
    for ops[1] in op:
        for ops[2] in op:
            tmp = abcd[0]
            for i in range(3):
                if ops[i] == '+':
                    tmp += abcd[i+1]
                else:
                    tmp -= abcd[i+1]
                if tmp == 7:
                    ans = str(abcd[0])
                    for i in range(3):
                        ans += ops[i] + str(abcd[i+1])
                    ans += '=7'
                    print(ans)
                    exit()

Submission status: Accepted

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

flag = False
for i in range(2**4):
    state = []
    for j in range(4):
        state.append((i >> j) & 1)
    
    ans = 0
    for i,s in enumerate(state):
        if s:
            ans += ABCD[i]
        else:
            ans -= ABCD[i]
    
    if ans == 7:
        ans = ""
        for i,s in enumerate(state):
            if s:
                ans += "+"
            else:
                ans += "-"
            ans += str(ABCD[i])
        if ans[0] == "+" or ans[:2] == "-0":
            ans = ans[1:]
        print(ans+"=7")
        exit()

Submission status: Accepted

Solution code:
def main():
    S = input()
    op = ['+', '-']

    def calc(cur):
        ret = int(S[0])
        for i in range(3):
            if cur[i] == "+":
                ret += int(S[i+1])
            else:
                ret -= int(S[i+1])
        return ret
    for i in range(1 << 3):
        cur = []
        for j in range(3):
            if i & (1 << j):
                cur.append(op[0])
            else:
                cur.append(op[1])
        if calc(cur) == 7:
            print("".join(S[i]+cur[i] for i in range(3)) + S[3] + "=7")
            return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = [''] * 3
for p in range(1<<3):
    t = l[0]
    for i in range(1,4):
        if p & 1:
            t += l[i]
            ans[i-1] = '+'
        else:
            t -= l[i]
            ans[i-1] = '-'
        p >>= 1
    if t == 7:
        break

print(str(l[0])+ans[0]+str(l[1])+ans[1]+str(l[2])+ans[2]+str(l[3])+'=7')