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 = str(input())
n = len(S)

def dfs(i,f,total):
  if i == n - 1:
    if total == 7:
      print(f + '=7')
      exit()
  else:
    dfs(i+1,f + '+' + S[i+1],total + int(S[i+1]))
    dfs(i+1,f + '-' + S[i+1],total - int(S[i+1]))

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

Submission status: Accepted

Solution code:
#C - Train Ticket
A = list(map(int,input()))    

for i in range(1<<3):
    culc = A[0]
    box = []
    for j in range(3):
        mask = 1<<j
        if mask & i != 0:
            culc += A[j+1]
            box.append('+')
        else:
            culc -= A[j+1]
            box.append('-')
    if culc == 7:
        break
ans = [0]*7
ans[::2]=[str(i) for i in A]
ans[1::2]=box
ans.append('=7')
print(''.join(ans))

Submission status: Accepted

Solution code:
A,B,C,D = list(map(int, input()))
flag = 0
for op1 in ["+", "-"]:
    if flag:
        break
    tmp1 = A+B if op1=="+" else A-B
    for op2 in ["+", "-"]:
        if flag:
            break
        tmp2 = tmp1+C if op2=="+" else tmp1-C
        for op3 in ["+", "-"]:
            if flag:
                break
            tmp3 = tmp2+D if op3=="+" else tmp2-D
            if tmp3==7:
                ans = str(A)+op1+str(B)+op2+str(C)+op3+str(D)+"=7"
                print(ans)
                flag = 1
                break

Submission status: Accepted

Solution code:
sstr=list(input())
s=list(map(int,sstr))

op=["" for _ in range(3)]
for i in range(2**3):
    tmp=0
    tmp+=s[0]
    for j in range(3):
        if (i>>j)&1:
            tmp+=s[j+1]
            op[j]="+"
        else:
            tmp-=s[j+1]
            op[j]="-"
    if tmp==7:
        ans=sstr[0]+op[0]+sstr[1]+op[1]+sstr[2]+op[2]+sstr[3]+"=7"
        print(ans)
        break

Submission status: Accepted

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

def ops (i):
    ans = "+" if i == 0 else "-"
    return ans

for i in range(2):
    for j in range(2):
        for k in range(2):
            ans = A + ((-1)**i)*B + ((-1)**j)*C + ((-1)**k)*D

            if ans == 7:
                print("{0}{1}{2}{3}{4}{5}{6}=7" .format(A,ops(i),B,ops(j),C,ops(k),D))
                sys.exit()

Submission status: Accepted

Solution code:
S=input()
A=int(S[0])
B=int(S[1])
C=int(S[2])
D=int(S[3])
if A+B+C+D==7:
    print(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 = list(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:
s = list(input())

for i in range(2**3):
    ans = ""
    ans += s[0]
    tmp = int(s[0])
    for j in range(3):
        if (i >> j)&1:
            ans += "+" + s[j+1]
            tmp += int(s[j+1])
        else:
            ans += "-" + s[j+1]
            tmp -= int(s[j+1])
    if tmp == 7:
        print(ans+"=7")
        exit()

Submission status: Accepted

Solution code:
num = input()
A = int(num[0])
B = int(num[1])
C = int(num[2])
D = int(num[3])
if 7-A==B+C+D:
  op1='+'
  op2='+'
  op3='+'
elif 7-A==B+C-D:
  op1='+'
  op2='+'
  op3='-'
elif 7-A==B-C+D:
  op1='+'
  op2='-'
  op3='+'
elif 7-A==C+D-B:
  op1='-'
  op2='+'
  op3='+'
elif 7-A==B-C-D:
  op1='+'
  op2='-'
  op3='-'
elif 7-A==C-D-B:
  op1='-'
  op2='+'
  op3='-'
elif 7-A==D-C-B:
  op1='-'
  op2='-'
  op3='+'
elif 7-A==-D-C-B:
  op1='-'
  op2='-'
  op3='-'
print(num[0]+op1+num[1]+op2+num[2]+op3+num[3]+"=7")

Submission status: Accepted

Solution code:
s = list(input())

for i in range(3**2):
    number = int(s[0])
    str = s[0]
    for j in range(3):
        if ((i>>j)&1):
            number += int(s[j+1])
            str += '+'+s[j+1]
        else:
            number -= int(s[j+1])
            str += '-'+s[j+1]
    if number == 7:
        print(str + '=7')
        exit(0)

Submission status: Accepted

Solution code:
abcd = input()

l = ["+", "-"]
for i in l:
  for j in l:
    for k in l:
      ans = eval(abcd[0]+i+abcd[1]+j+abcd[2]+k+abcd[3])
      if ans == 7:
        print(abcd[0]+i+abcd[1]+j+abcd[2]+k+abcd[3]+"=7")
        exit()

Submission status: Accepted

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

    for i in range(2 ** 3):
        c = S[0]
        for j in range(3):
            if (i >> j) & 1:
                c += "+"
            else:
                c += "-"
            c += S[j + 1]
        if eval(c) == 7:
            print(c + "=7")
            exit()


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

s = input()
def main():
    for i in range(2**3):
        localsum = s[0]
        for j in range(3):
            if (i >> j) & 1:
                localsum += "+"
            else:
                localsum += "-"
            localsum += s[j+1]
        sum = eval(localsum)
        if sum == 7:
            localsum += "=7"
            print(localsum)
            sys.exit()
main()

Submission status: Accepted

Solution code:
import sys

s = input()

for i in range(2**3):
    localsum = s[0]
    for j in range(3):
        if (i >> j) & 1:
            localsum += "+"
        else:
            localsum += "-"
        localsum += s[j+1]
    sum = eval(localsum)
    if sum == 7:
        localsum += "=7"
        print(localsum)
        sys.exit()

Submission status: Accepted

Solution code:
import sys

s = input()

for i in range(2**3):
    sum = 0
    localsum = s[0]
    for j in range(3):
        if (i >> j) & 1:
            localsum += "+"
        else:
            localsum += "-"
        localsum += s[j+1]
    sum += eval(localsum)
    if sum == 7:
        localsum += "=7"
        print(localsum)
        sys.exit()

Submission status: Accepted

Solution code:
#
# abc079 c
#

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """1222"""
        output = """1+2+2+2=7"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """0290"""
        output = """0-2+9+0=7"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """3242"""
        output = """3+2+4-2=7"""
        self.assertIO(input, output)


def resolve():
    N = input()

    for bit in range(1 << 3):
        S = ""
        for j in range(3):
            S += N[j]
            if bit & (1 << j) == 0:
                op = "+"
            else:
                op = "-"
            S += op
        S += N[3]
        if eval(S) == 7:
            print(S+"=7")
            break


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Accepted

Solution code:
numbers = input()
a,b,c,d = numbers
i = len(numbers)-1

op = ['+','-']

for j in range(2 ** i):
  o = [op[int((j>>k)&1)] for k in range(i)]
  f=f"{a}{o[0]}{b}{o[1]}{c}{o[2]}{d}"
  if eval(f) == 7:
    print(f+'=7')
    break

Submission status: Accepted

Solution code:
s=input()
ans=[]

for i in range(2**3):
  a=int(s[0])
  for j in range(3):
    if ((i>>j)&1):
      a+=int(s[j+1])
    else:
      a-=int(s[j+1])
      
  if a==7:
    ans.append(i)
    
u=ans[0]
ans1=[]
for j in range(3):
  if ((u>>j)&1):
      ans1.append('+')
  else:
      ans1.append('-')
      
print(s[0]+ans1[0]+s[1]+ans1[1]+s[2]+ans1[2]+s[3]+'=7')

Submission status: Accepted

Solution code:
def main():
    s = input()
    op = ["-", "+"]

    for i in range(2 ** 3):
        lst = [0] * 3
        for j in range(3):
            if (i >> j) & 1 == 1:
                lst[2 - j] = 1

        res = int(s[0])
        for j in range(3):
            if lst[j] == 0:
                res -= int(s[j + 1])
            if lst[j] == 1:
                res += int(s[j + 1])
        if res == 7:
            print(f"{s[0]}{op[lst[0]]}{s[1]}{op[lst[1]]}{s[2]}{op[lst[2]]}{s[3]}=7")
            break


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
a, b, c, d = map(int,input())
A = str(a)
B = str(b)
C = str(c)
D = str(d)
if a+b+c+d == 7:
    print(A+'+'+B+'+'+C+'+'+D+'=7')
elif a-b+c+d == 7:
    print(A+'-'+B+'+'+C+'+'+D+'=7')
elif a+b-c+d == 7:
    print(A+'+'+B+'-'+C+'+'+D+'=7')
elif a+b+c-d == 7:
    print(A+'+'+B+'+'+C+'-'+D+'=7')
elif a-b-c+d == 7:
    print(A+'-'+B+'-'+C+'+'+D+'=7')
elif a-b+c-d == 7:
    print(A+'-'+B+'+'+C+'-'+D+'=7')
elif a+b-c-d == 7:
    print(A+'+'+B+'-'+C+'-'+D+'=7')
elif a-b-c-d == 7:
    print(A+'-'+B+'-'+C+'-'+D+'=7')

Submission status: Accepted

Solution code:
A,B,C,D = map(int, input())
ans = list(str(A))
for b in [-B,B]:
    for c in [-C,C]:
        for d in [-D,D]:
            if sum([A,b,c,d]) == 7:
                ans += ["+" + str(x) if x>=0 else str(x) for x in [b,c,d]]
                break
        else:
            continue
        break
    else:
        continue
    break
for i in ans:
    print(i, end = "")
print("=7")

Submission status: Accepted

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

for op1 in op:
    for op2 in op:
        for op3 in op:
            check = a + op1 + b + op2 + c + op3 + d
            if eval(check) == 7:
                print(check + "=7")
                exit()

Submission status: Accepted

Solution code:
#ABC079 C:Train Ticket
import itertools

s = list(input())
num = []
calc = [1, -1]
for i in range(len(s)):
    a = int(s[i])
    num.append(a)

calc_comb = [_ for _ in itertools.product(calc, repeat=3)]

x = 0
while True:
    ans = num[0]
    for i in range(len(num)-1):
        ans += num[i+1] * calc_comb[x][i]

    if ans == 7:
        r = calc_comb[x]
        break
    else:
        x += 1

r_replace = ['+' if i==1 else '-' for i in r]
out = [None] * (len(s)+len(r_replace))
out[::2] = s
out[1::2] = r_replace
out = ''.join(out)
print(out, '=7', sep='')

Submission status: Accepted

Solution code:
s = input()
n = 3
for i in range(2 ** n):
    sign = [False] * n
    for j in range(n):
        if (i >> j) & 1:
            sign[j] = True
    cal = int(s[0])
    for i in range(n):
        if sign[i]:
            cal += int(s[i+1])
        else:
            cal -= int(s[i+1])
    if cal == 7:
        print(s[0], end = '')
        for i in range(n):
            if sign[i]:
                print('+' + s[i+1], end = '')
            else:
                print('-' + s[i+1], end = '')
        print('=7')
        break

Submission status: Accepted

Solution code:
# pro level coding
def main():
	ad = input()
	now = int(ad[0])
	q = []
	n = len(ad)
	q.append([0 , now , ad[0]])
	while len(q)!=0:
		#print(23)
		cur = q.pop(0)
		#print(cur[0] , cur[1] , cur[2])
		if cur[0] ==n-1:
			if cur[1]==7:
				print(cur[2]+'='+'7')
				break
				exit(0)
			continue
		#print(cur[1]+((int)(ad[cur[0]+1])) , cur[0])
		if cur[0]+1<n:
			q.append([cur[0]+1, cur[1]+((int)(ad[cur[0]+1])) , cur[2]+'+'+ad[cur[0]+1]])
			q.append([cur[0]+1, cur[1]-((int)(ad[cur[0]+1])) , cur[2]+'-'+ad[cur[0]+1]])
if __name__=="__main__":
	main()

Submission status: Accepted

Solution code:
def main():
	ad = input()
	now = int(ad[0])
	q = []
	n = len(ad)
	q.append([0 , now , ad[0]])
	while len(q)!=0:
		#print(23)
		cur = q.pop(0)
		#print(cur[0] , cur[1] , cur[2])
		if cur[0] ==n-1:
			if cur[1]==7:
				print(cur[2]+'='+'7')
				break
				exit(0)
			continue
		#print(cur[1]+((int)(ad[cur[0]+1])) , cur[0])
		if cur[0]+1<n:
			q.append([cur[0]+1, cur[1]+((int)(ad[cur[0]+1])) , cur[2]+'+'+ad[cur[0]+1]])
			q.append([cur[0]+1, cur[1]-((int)(ad[cur[0]+1])) , cur[2]+'-'+ad[cur[0]+1]])
if __name__=="__main__":
	main()

Submission status: Accepted

Solution code:
a, b, c, d = map(int, list(input()))
op = ['-', '', '+']
for i in range(0, 3, 2):
  for j in range(0, 3, 2):
    for k in range(0, 3, 2):
      if a + b*(i-1) + c*(j-1) + d*(k-1) == 7:
        print(f'''{a}{op[i]}{b}{op[j]}{c}{op[k]}{d}=7''')
        exit()

Submission status: Accepted

Solution code:

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

if (a+b+c+d == 7):
  print(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:
N = input()
N = [int(n) for n in N]
A,B,C,D = N
op =['+','-']
ops = []
for a in op:
  for b in op:
    for c in op:
        ops.append(a + b + c)
        
for op in ops:
  S = "{}{}{}{}{}{}{}".format(A,op[0],B,op[1],C,op[2],D)
  if eval(S) == 7:
    print("{}=7".format(S))
    break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,C,D = map(int, input())
ans = [str(A)]
for b in [B,-B]:
    for c in [C,-C]:
        for d in [D,-D]:
            if sum([A,b,c,d]) == 7:
                ans += ['+' + str(x) if x >= 0 else str(x) for x in [b,c,d]]
                print(''.join(ans) + '=7')
                exit(0)

Submission status: Accepted

Solution code:
n = input()
num = [int(x) for x in n]

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

Submission status: Accepted

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

for x in lis:
  for y in lis:
    for z in lis:
      p = n[0] + x + n[1] + y + n[2] + z + n[3]
      if eval(p) == 7:
        print(p + "=7")
        exit()

Submission status: Accepted

Solution code:
A,B,C,D = input()
op = ["+","-"]

for op1 in op:
  for op2 in op:
    for op3 in op:
      S = A+op1+B+op2+C+op3+D
      if eval(S)==7:
        print(S+"=7")
        exit()

Submission status: Accepted

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

for x in lis:
  for y in lis:
    for z in lis:
      p = n[0] + x + n[1] + y + n[2] + z + n[3]
      if eval(p) == 7:
        print(p + "=7")
        exit()

Submission status: Accepted

Solution code:
A,B,C,D = input()
for i in range(1<<3):
  S = []
  for j in range(3):
    if 1&(i>>j): 
      S.append("+")
    else: 
      S.append("-")
  if eval(A+S[0]+B+S[1]+C+S[2]+D)==7:
    print(A+S[0]+B+S[1]+C+S[2]+D+"=7")
    exit()

Submission status: Accepted

Solution code:
from itertools import product

m = input()
n = m[0] + 'x' + m[1] + 'y' + m[2] + 'z' + m[3]

for i in product([0,1], repeat=3):
    if i[0] == 0:
        l = n.replace('x', '+')
    elif i[0] == 1:
        l = n.replace('x', '-')

    if i[1] == 0:
        l = l.replace('y', '+')
    elif i[1] == 1:
        l = l.replace('y', '-')

    if i[2] == 0:
        l = l.replace('z', '+')
    elif i[2] == 1:
        l = l.replace('z', '-')

    if eval(l) == 7:
        print(l + '=7')
        exit()

Submission status: Accepted

Solution code:
ABCD = list(input())

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

    formula = ''.join([n + op for n, op in zip(ABCD, ptn + [''])])
    if eval(formula) == 7:
        print(formula + '=7')
        exit()

Submission status: Accepted

Solution code:
from itertools import product as P

a, b, c, d = input()

ops = P(("+", "-"), repeat=3)
for op1, op2, op3 in ops:
    f = f"{a}{op1}{b}{op2}{c}{op3}{d}"
    if eval(f) == 7:
        print(f + "=7")
        break

Submission status: Accepted

Solution code:
abcd = input() #4つの数字をstr型で入力
l = len(abcd)  # l=4

for bit in range(1 << l-1):
    N = abcd[0]
    for i in range(3):
        N += ' '
        if ((bit >> i) & 1):
            N += '-'
        else:
            N += '+'
        N += abcd[i+1]
        N += ' '
    #print(N)
    N_int = sum(map(int, N.split()))
    #print(N_int)
    if N_int == 7:
        #ans = list(map(str, N.split()))
        ans = N.replace(' ', '')
        print('{}=7'.format(ans))
        break

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
def main():
    tmp = input()
    a = int(tmp[0])
    b = int(tmp[1])
    c = int(tmp[2])
    d = int(tmp[3])
    
    for i in range(2 ** 3):
        opt = []
        for j in range(3):
            if (i >> j) & 1:
                opt.append("+")
            else:
                opt.append("-")
        ans = int(tmp[0])
        for j, x in enumerate(tmp[1:]):
            if opt[j] == "+":
                ans += int(x)
            else:
                ans -= int(x)
        if ans == 7:
            print(tmp[0] + opt[0] + tmp[1] + opt[1] + tmp[2] + opt[2] + tmp[3] + "=7")
            break
    
main()

Submission status: Accepted

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

def p_mark(j):
    if j % 2 == 0:
        return '+'
    else:
        return '-'

for i in range(2 ** 3):
    j = i
    p = a
    x = p_mark(j)
    if x == '+':
        p += b
    else:
        p -= b
    j = j // 2
    y = p_mark(j)
    if y == '+':
        p += c
    else:
        p -= c
    j = j // 2
    z = p_mark(j)
    if z == '+':
        p += d
    else:
        p -= d
    if p == 7:
        print(str(a) + x + str(b) + y + str(c) + z + str(d) + '=7')
        break

Submission status: Accepted

Solution code:
A, B, C, D = input()
op = ["+", "-"]

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

Submission status: Accepted

Solution code:
s = [int(x) for x in list(input())]

def joinstring(s, op1, op2, op3):
  return str(s[0]) + op1 + str(s[1]) + op2 + str(s[2]) + op3 + str(s[3]) + "=7"

p = "+"
m = "-"

if s[0] + s[1] + s[2] + s[3] == 7:
  print(joinstring(s, p, p, p))
elif s[0] + s[1] + s[2] - s[3] == 7:
  print(joinstring(s, p, p, m))
elif s[0] + s[1] - s[2] + s[3] == 7:
  print(joinstring(s, p, m, p))
elif s[0] - s[1] + s[2] + s[3] == 7:
  print(joinstring(s, m, p, p))
elif s[0] + s[1] - s[2] - s[3] == 7:
  print(joinstring(s, p, m, m))
elif s[0] - s[1] + s[2] - s[3] == 7:
  print(joinstring(s, m, p, m))
elif s[0] - s[1] - s[2] + s[3] == 7:
  print(joinstring(s, m, m, p))
elif s[0] - s[1] - s[2] - s[3] == 7:
  print(joinstring(s, m, m, m,))

Submission status: Accepted

Solution code:
s = input()

for i in range(2**3):
    op = ["+"]*3
    op.append("")
    fomula = ""
    for j in range(3):
        if(i >> j & 1):
            op[j] = "-"
    for k in range(4):
        fomula += s[k] + op[k]
    if eval(fomula) == 7:
        print(fomula + "=7")
        break

Submission status: Accepted

Solution code:
ABCD = input()

for i in range(2**3):
  f = ABCD[0]
  for j in range(3):
       if ((i >> j) & 1):
        f += "-"
       else:
        f += "+"
       f += ABCD[j+1]

  if eval(f) == 7:
    print(f+"=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()

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

Submission status: Accepted

Solution code:
ABCD = input()
for i in ('-1','+1'):
    for j in ('-1','+1'):
        for k in ('-1','+1'):
            if int(ABCD[0]) + (int(i)) * int(ABCD[1]) + (int(j)) * int(ABCD[2]) + + (int(k)) * int(ABCD[3]) == 7:
                print(ABCD[0]+i[0]+ABCD[1]+j[0]+ABCD[2]+k[0]+ABCD[3]+'=7')
                exit()

Submission status: Accepted

Solution code:
n=input()

def make_seven(n):
    al=[]
    for i in range(4):
        a=int(n[i])
        al.append(a)

    for j in range(-1,2,2):
        for k in range(-1,2,2):
            for l in range(-1,2,2):
                if al[0]+j*al[1]+k*al[2]+l*al[3]==7:
                    if j==-1:
                        o1="-"
                    else:
                        o1="+"
                    if k==-1:
                        o2="-"
                    else:
                        o2="+"
                    if l==-1:
                        o3="-"
                    else:
                        o3="+"
                    print(str(al[0])+o1+str(al[1])+o2+str(al[2])+o3+str(al[3])+"=7")
                    return
make_seven(n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
abcd = str(input())
w = ["+","-"]
s = []
for i in w:
    for h in w:
        for j in w:
            num = int(abcd[0])
            l = [i,h,j]
            for k in range(len(l)):
                if l[k] == "+":
                    num += int(abcd[k+1])
                else:
                    num -= int(abcd[k+1])
            if num == 7:
                s.append(abcd[0]+i+abcd[1]+h+abcd[2]+j+abcd[3]+"="+"7")
print(s[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    S = SI()
    bit_len = len(S)-1
    for i in range(2**bit_len):
        ls = ['-' for _ in range(bit_len)]
        for j in range(bit_len):
            if (i >> j) & 1:
                ls[j] = '+'
        calc = []
        for n in range(len(S)):
            calc.append(S[n])
            if n != len(S)-1:
                calc.append(ls[n])
        if eval("".join(calc)) == 7:
            print("".join(calc)+"=7")
            sys.exit()

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = [int(x) for x in input()]
op_cnt = len(n) - 1
for i in range(1 << op_cnt):
    op = ['-'] * op_cnt
    for j in range(op_cnt):
        if (i >> j) & 1:
            op[op_cnt - 1 - j] = '+'
    formula = "{}{}{}{}{}{}{}".format(n[0], op[0], n[1], op[1], n[2], op[2], n[3])
    if eval(formula) == 7:
        print(formula + '=7')
        break

Submission status: Accepted

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

def calc(n,op):
  tmp = int(n[0])
  for i in range(len(op)):
    if op[i] == '+':
      tmp += int(n[i+1])
    else:
      tmp -= int(n[i+1])
  return tmp
for j in range(2**s):
  op = ''
  for k in range(s):
    if (j>>k)&1:
      op += '+'
    else:
      op += '-'
  if calc(n,op) == 7:
    ret = ''
    for l in range(len(op)):
      ret += n[l]
      ret += op[l]
    ret += n[-1]
    ret +='=7'
    print(ret)
    exit(0)

Submission status: Accepted

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


for i in range(2**s):
  op = ""
  for j in range(s):
    if (i>>j)&1:
      op += "+"
    else:
      op += "-"
  ans =int(n[0])
  for j in range(len(op)):
    if op[j]=="+":
      ans += int(n[j+1])
    else:
      ans -= int(n[j+1])
  if ans == 7:
      ret = ""
      for k in range(len(op)):
        ret += n[k]
        ret += op[k]
      ret += n[-1]
      ret += "=7"
      print(ret)
      exit(0)

Submission status: Accepted

Solution code:
s=input()
A=[]
d=s[0]
for i in range(2**(len(s)-1)):
    v=[]
    for j in range(len(s)-1):
        if ((i>>j)&1):
            v.append('+')
        else:
            v.append('-')
    A.append(v)

for i in range(len(A)):
    c=int(s[0])
    for j in range(3):
        if A[i][j]=='+':
            c+=int(s[j+1])
        else:
            c-=int(s[j+1])
    if c==7:
        for j in range(3):
            d+=A[i][j]+s[j+1]
        print(d+'=7')
        exit()

Submission status: Accepted

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

for i in range(2**3):
    op = ["+"]*3
    for j in range(3):
        if (i >> j) & 1 == 1:
            op[j] = "-"
    if eval(a+op[0]+b+op[1]+c+op[2]+d) == 7:
        print(a+op[0]+b+op[1]+c+op[2]+d+'=7')
        sys.exit()

Submission status: Accepted

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

for op1 in ["+","-"]:
  for op2 in ["+","-"]:
    for op3 in ["+","-"]:
      if eval(A+op1+B+op2+C+op3+D) == 7:
        ans = A+op1+B+op2+C+op3+D+"=7"
        break
print(ans)

Submission status: Accepted

Solution code:
S=input()
a=[0]*7
a[0]=int(S[0])
a[2]=int(S[1])
a[4]=int(S[2])
a[6]=int(S[3])
for i in range(2**3):
    j=bin(int(i))[2:]
    while len(j)<3:
        j="0"+j
    for k in range(3):
        if j[k]=="0":
            a[2*k+1]="+"
        else:
            a[2*k+1]="-"
    ans=a[0]
    if a[1]=="+":
        ans+=a[2]
    else:
        ans-=a[2]
    if a[3]=="+":
        ans+=a[4]
    else:
        ans-=a[4]
    if a[5]=="+":
        ans+=a[6]
    else:
        ans-=a[6]
    if ans==7:
        print(S[0]+a[1]+S[1]+a[3]+S[2]+a[5]+S[3]+"=7")
        break

Submission status: Accepted

Solution code:
s = input()
n = 4

sum_val = 0
for i in range(1 << (n - 1)):
    val = int(s[0])
    expression = s[0]
    for j in range(n - 1):
        if (i >> j) & 1:
            val += int(s[j+1])
            expression += "+" + s[j+1]
        else:
            val -= int(s[j+1])
            expression += "-" + s[j+1]
    if val == 7:
        print(expression + "=7")
        quit()

Submission status: Accepted

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


for i in range(2**(n-1)):
  ans = int(s[0])
  f = 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:
s = input()
op1 = "+"
op2 = "-"

a = [0 for _ in range(8)]
a[0] = int(s[0]) + int(s[1]) + int(s[2]) + int(s[3])
a[1] = int(s[0]) + int(s[1]) + int(s[2]) - int(s[3])
a[2] = int(s[0]) + int(s[1]) - int(s[2]) + int(s[3])
a[3] = int(s[0]) + int(s[1]) - int(s[2]) - int(s[3])
a[4] = int(s[0]) - int(s[1]) + int(s[2]) + int(s[3])
a[5] = int(s[0]) - int(s[1]) + int(s[2]) - int(s[3])
a[6] = int(s[0]) - int(s[1]) - int(s[2]) + int(s[3])
a[7] = int(s[0]) - int(s[1]) - int(s[2]) - int(s[3])

if a[0] == 7:
    print(s[0]+op1+s[1]+op1+s[2]+op1+s[3]+"=7")
    exit()
elif a[1] == 7:
    print(s[0]+op1+s[1]+op1+s[2]+op2+s[3]+"=7")
    exit()
elif a[2] == 7:
    print(s[0]+op1+s[1]+op2+s[2]+op1+s[3]+"=7")
    exit()
elif a[3] == 7:
    print(s[0]+op1+s[1]+op2+s[2]+op2+s[3]+"=7")
    exit()
elif a[4] == 7:
    print(s[0]+op2+s[1]+op1+s[2]+op1+s[3]+"=7")
    exit()
elif a[5] == 7:
    print(s[0]+op2+s[1]+op1+s[2]+op2+s[3]+"=7")
    exit()
elif a[6] == 7:
    print(s[0]+op2+s[1]+op2+s[2]+op1+s[3]+"=7")
    exit()
elif a[7] == 7:
    print(s[0]+op2+s[1]+op2+s[2]+op2+s[3]+"=7")
    exit()

Submission status: Accepted

Solution code:
a,b,c,d = list(map(int,input()))
op = ['plus','minus']
dic = {'plus':'+','minus':'-'}

for op1 in op:
    for op2 in op:
        for op3 in op:
            ans = a
            if op1 == 'plus':
                ans += b
            else:
                ans -= b
            if op2 == 'plus':
                ans += c
            else:
                ans -= c
            if op3 == 'plus':
                ans += d
            else:
                ans -= d
            if ans == 7:
                print(f'{a}{dic[op1]}{b}{dic[op2]}{c}{dic[op3]}{d}=7')
                exit()

Submission status: Accepted

Solution code:
abcd = list(input())
a, b, c, d = abcd
sign = ['+', '-']
for i in range(2**3):
    s = a
    for j in range(3):
        if (i>>j) & 1:
            s += sign[0]
        else:
            s += sign[1]
        s += abcd[j+1]
    if eval(s) == 7:
        print(s + "=7")
        exit()

Submission status: Accepted

Solution code:
# ABC079 C問題 Train Tickets
"""
切符に４つの0以上9以下の整数A,B, C, Dが整理番号として順にかかれている。
Aop1Bop2Cop3D = 7　となるように、op1,2,3,に'+'または'-'を入れて式を作る。
答が存在しない入力は与えられず、また答が複数ある場合はどれを出力してもよい。
＜制約＞
0 <= A,B,C,D<=9
入力は整数
答が存在しない入力は与えられない
"""
n = list(int(x) for x in input())
op_cnt = len(n) - 1 #隙間の数

l = []
for i in range(1 << op_cnt):
    op = ['-'] * op_cnt
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt - j -1] = '+'
            l.append(op)

for operators in l:
    expression = f"{n[0]}{operators[0]}{n[1]}{operators[1]}{n[2]}{operators[2]}{n[3]}"
    if eval(expression) == 7:
        print(f"{expression}=7")
        break