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:
import sys
import  math
from statistics import *
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

a, b, c, d = input()
li = ["+", "-"]
def calc(a, b, c, d):
    for i in range(2):
        if i == 0:
            e = a + b
        else:
            e = a - b
        for j in range(2):
            if j == 0:
                f = e + c
            else:
                f = e - c
            for k in range(2):
                if k == 0:
                    g = f + d
                else:
                    g = f - d
                if g == 7:
                    print(str(a) + li[i] + str(b) + li[j] + str(c) + li[k] + str(d) + "=7")
                    return
calc(int(a),int(b), int(c), int(d))

Submission status: Accepted

Solution code:
S = input()
for op1 in [1, -1]:
    for op2 in [1, -1]:
        for op3 in [1, -1]:
            num = int(S[0]) + op1 * int(S[1]) + op2 * int(S[2]) + op3 * int(S[3])
            if num == 7:
                ans = S[0]
                ans += '+' if op1 == 1 else '-'
                ans += S[1]
                ans += '+' if op2 == 1 else '-'
                ans += S[2]
                ans += '+' if op3 == 1 else '-'
                ans += S[3]
                ans += '=7'
                print(ans)
                exit(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC 79 C

def resolve():
    ops = ['+', '-']
    s = input()

    for i in ops:
        for j in ops:
            for k in ops:
                eq = s[0] + i + s[1] + j + s[2] + k + s[3]
                if eval(eq) == 7:
                    print(eq + '=7')
                    return

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
import itertools
li = list(map(int,input()))

# 0- 1+
for i in itertools.product([0,1], repeat=3): 
    tmp = li[0]
    for j,k in enumerate(i):
        if k:
            tmp += li[j+1]
        else:
            tmp -= li[j+1]
    if tmp == 7:
        L = str(li[0])
        for _ in range(3):
            if i[_]:
                L += '+' + str(li[_+1])
            else:
                L += '-' + str(li[_+1])
        print(L+'=7')
        break

Submission status: Accepted

Solution code:
ABCD = input()

A = int(ABCD[0])
B = int(ABCD[1])
C = int(ABCD[2])
D = int(ABCD[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 = list(input())
num = [0]*4
num[0] = int(s[0])
for i in range(1,4):
  num[i] = [0]*2
  num[i][0] = int(s[i])
  num[i][1] = -(int(s[i]))
  
patern = [0] * 8

p = ['+', '-']

count = 0
for i in range(2):
  for j in range(2):
    for k in range(2):
      temp = num[0] + num[1][i] + num[2][j] + num[3][k]
      patern[count] = [p[i], p[j], p[k]]
      if temp == 7:
        ans_count = count
      count += 1

print(s[0] + patern[ans_count][0] + s[1] + patern[ans_count][1] + s[2] + patern[ans_count][2] + s[3] + '=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])
E = ["-", "+"]
ans = []
for i in range(0, 2):
    for j in range(0, 2):
        for k in range(0, 2):
            tmp = A
            if i & 1:
                tmp += B
            else:
                tmp -= B
            if j & 1:
                tmp += C
            else:
                tmp -= C
            if k & 1:
                tmp += D
            else:
                tmp -= D
            if tmp == 7:
                ans.append(i)
                ans.append(j)
                ans.append(k)
print("{0}{1}{2}{3}{4}{5}{6}=7".format(
    A, E[ans[0]], B, E[ans[1]], C, E[ans[2]], D))

Submission status: Accepted

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

flag = False

for i in range(2):
	for j in range(2):
		for k in range(2):
			B = (N[1] if i == 0 else -N[1])
			C = (N[2] if j == 0 else -N[2])
			D = (N[3] if k == 0 else -N[3])
			if sum([N[0], B, C, D]) == 7:
				print(N[0],end='')
				if i == 0:
					print('+',end='')
				else:
					print('-',end='')
				print(N[1],end='')
				if j == 0:
					print('+',end='')
				else:
					print('-',end='')
				print(N[2],end='')
				if k == 0:
					print('+',end='')
				else:
					print('-',end='')
				print(N[3],end='')
				print('=7')
				flag = True
				break
		if flag:
			break
	if flag:
		break

Submission status: Accepted

Solution code:
s=input()

for i in range(8):
	li=[]
	for j in range(3):
		if i>>j &1:
			li += '+'
		else:
			li += '-'
	ans=s[0] +li[0] +s[1]+li[1]+s[2]+li[2]+s[3]
	val=eval(ans)
	if val == 7:
		print( ''.join(ans)+'=7')
		break

Submission status: Accepted

Solution code:
import sys
from pprint import pprint
from operator import add, sub

from collections import deque

s =[int(s_i) for s_i in sys.stdin.readline().strip()] 
# pprint(s)

for op1 in (add, sub):
    for op2 in (add, sub):
        for op3 in (add, sub):
             if op3 ( op2 ( op1 (s[0], s[1]), s[2]), s[3]) == 7:
                 tmp1 = "+" if op1 == add else "-"
                 tmp2 = "+" if op2 == add else "-"
                 tmp3 = "+" if op3 == add else "-"
                 print(str(s[0]) + tmp1 + str(s[1]) + tmp2 + str(s[2]) + tmp3 + str(s[3]) + "=7")
                 sys.exit()

Submission status: Accepted

Solution code:
def make_fomula(s, ops):
    f = ''
    for v, op in zip(s, ops):
        f += v + op
    else:
        f += s[-1]
    return f


s = input()
n = len(s) - 1
bit = 0
while bit < (1 << n):
    ops = ['-'] * n
    for i in range(n):
        if bit & 1 << i:
            ops[i] = '+'

    fomula = make_fomula(s, ops)
    if eval(fomula) == 7:
        print(fomula+'=7')
        break

    bit += 1

Submission status: Accepted

Solution code:
A,B,C,D=input()
op='+-'
for a in op:
    for b in op:
        for c in op:
            _ = A+a+B+b+C+c+D
            if eval(_)==7:
                print(_+'=7')
                exit()

Submission status: Accepted

Solution code:
ABCD=input()
A,B,C,D=[ABCD[_] for _ in range(4)]
a,b,c,d=int(A),int(B),int(C),int(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:
l = list(input())

for i in range(1<<(len(l)-1)):
  s = l[0]
  for j in range(len(l)-1):
    if (i>>j) & 1:
      s += "+"
    else:
      s += "-"
    s += l[j+1]
  if eval(s) == 7:
    print(s+"=7")
    quit()

print("wrong input.")

Submission status: Accepted

Solution code:
A, B, C, D = list(input())
op = {'+': 1, '-': -1}
for op1 in op:
    for op2 in op:
        for op3 in op:
            tmp = A + op1 + B + op2 + C + op3 + D
            if eval(tmp) == 7:
                print(tmp + '=7')
                exit()

Submission status: Accepted

Solution code:
A, B, C, D = map(int, list(input()))
op = {'+': 1, '-': -1}
for op1 in op:
    for op2 in op:
        for op3 in op:
            tmp = A + B * op[op1] + C * op[op2] + D * op[op3]
            if tmp == 7:
                A, B, C, D = map(str, [A, B, C, D])
                print(A + op1 + B + op2 + C + op3 + D + '=7')
                exit()

Submission status: Accepted

Solution code:
l = list(map(str, input()))
n = len(l)
for i in range(2 ** (n-1)):
    bag = ['' for _ in range(n-1)]
    m = l[:]
    idx = n
    for j in range(n-1):
        if (i>>j) & 1:
            bag[j] = '+'
        else:
            bag[j] = '-'        
    for op in bag[::-1]:
        m.insert(idx-1, op)
        idx -= 1

    if eval(''.join(m)) == 7:
        print(''.join(m), "=7", sep="")
        break

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    n = list(map(int,list(input())))
    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")
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

kotae=''

if a+b+c+d==7:
    kotae+=str(a)
    kotae+='+'
    kotae+=str(b)
    kotae+='+'
    kotae+=str(c)
    kotae+='+'
    kotae+=str(d)
    kotae+='='
    kotae+=str(7)
elif a+b+c-d==7:
    kotae+=str(a)
    kotae+='+'
    kotae+=str(b)
    kotae+='+'
    kotae+=str(c)
    kotae+='-'
    kotae+=str(d)
    kotae+='='
    kotae+=str(7)
elif a+b-c+d==7:
    kotae+=str(a)
    kotae+='+'
    kotae+=str(b)
    kotae+='-'
    kotae+=str(c)
    kotae+='+'
    kotae+=str(d)
    kotae+='='
    kotae+=str(7)
elif a+b-c-d==7:
    kotae+=str(a)
    kotae+='+'
    kotae+=str(b)
    kotae+='-'
    kotae+=str(c)
    kotae+='-'
    kotae+=str(d)
    kotae+='='
    kotae+=str(7)
elif a-b+c+d==7:
    kotae+=str(a)
    kotae+='-'
    kotae+=str(b)
    kotae+='+'
    kotae+=str(c)
    kotae+='+'
    kotae+=str(d)
    kotae+='='
    kotae+=str(7)
elif a-b+c-d==7:
    kotae+=str(a)
    kotae+='-'
    kotae+=str(b)
    kotae+='+'
    kotae+=str(c)
    kotae+='-'
    kotae+=str(d)
    kotae+='='
    kotae+=str(7)
elif a-b-c+d==7:
    kotae+=str(a)
    kotae+='-'
    kotae+=str(b)
    kotae+='-'
    kotae+=str(c)
    kotae+='+'
    kotae+=str(d)
    kotae+='='
    kotae+=str(7)
elif a-b-c-d==7:
    kotae+=str(a)
    kotae+='-'
    kotae+=str(b)
    kotae+='-'
    kotae+=str(c)
    kotae+='-'
    kotae+=str(d)
    kotae+='='
    kotae+=str(7)
print(kotae)

Submission status: Accepted

Solution code:
def calc(s, n):
    if n == 0:
        ans = int(s[0])
        for i in range(2, len(s), 2):
            if s[i-1] == "+":
                ans += int(s[i])
            else:
                ans -= int(s[i])
        if ans == 7:
            global answer
            answer = s[0:len(s)-1] + "=7"
    if(n != 0): calc(s[0:n]+"+"+s[n:], n-1)
    if(n != 0): calc(s[0:n]+"-"+s[n:], n-1)

s = input()
answer = ""
calc(s, len(s))
print(answer)

Submission status: Accepted

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

if n[0] + n[1] + n[2] + n[3] == 7:
    print("{}+{}+{}+{}=7".format(n[0],n[1],n[2],n[3]))
elif n[0] + n[1] + n[2] - n[3] == 7:
    print("{}+{}+{}-{}=7".format(n[0],n[1],n[2],n[3]))
elif n[0] + n[1] - n[2] + n[3] == 7:
    print("{}+{}-{}+{}=7".format(n[0],n[1],n[2],n[3]))
elif n[0] + n[1] - n[2] - n[3] == 7:
    print("{}+{}-{}-{}=7".format(n[0],n[1],n[2],n[3]))
elif n[0] - n[1] + n[2] + n[3] == 7:
    print("{}-{}+{}+{}=7".format(n[0],n[1],n[2],n[3]))
elif n[0] - n[1] + n[2] - n[3] == 7:
    print("{}-{}+{}-{}=7".format(n[0],n[1],n[2],n[3]))
elif n[0] - n[1] - n[2] + n[3] == 7:
    print("{}-{}-{}+{}=7".format(n[0],n[1],n[2],n[3]))
elif n[0] - n[1] - n[2] - n[3] == 7:
    print("{}-{}-{}-{}=7".format(n[0],n[1],n[2],n[3]))
else:
    print("error")

Submission status: Accepted

Solution code:
A, B, C, D = map(int, list(input()))
for i in range(1<<3):
  r = A
  if i&(1<<2) == 0:
    r += B
  else:
    r -= B
  if i&(1<<1) == 0:
    r += C
  else:
    r -= C
  if i&(1<<0) == 0:
    r += D
  else:
    r -= D
  if r == 7:
    s = str(A)+("+" if i&(1<<2) == 0 else "-")+str(B)+("+" if i&(1<<1) == 0 else "-")+str(C)+("+" if i&(1<<0) == 0 else "-")+str(D)+"=7"
    print(s)
    exit()
print()

Submission status: Accepted

Solution code:
x=input()


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

    formula=""
    for k in range(3):
        formula += x[k]+op[k]

    formula+=x[3]
    if eval(formula) == 7:
        print(formula+"=7")
        exit()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
s = list(input())
n = len(s)
v = 7

# 全bit探査:
for i in range((n-1)*(n-1)):
    summation = int(s[0])
    str_equation = [s[0]]
    for j in range(n-1):
        # bitが1なら+演算子として扱う
        if (i >> j) & 1:
            summation += int(s[j+1])
            str_equation.append("+")
            str_equation.append(s[j+1])
        # bitが0なら-演算子として扱う
        else:
            summation -= int(s[j+1])
            str_equation.append("-")
            str_equation.append(s[j+1])

    if summation == v:
        str_equation.append("=")
        str_equation.append(str(v))
        print("".join(str_equation))
        break

Submission status: Accepted

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

import sys
ops = '+-'
for op1 in ops:
    for op2 in ops:
        for op3 in ops:
            s = '{}{}{}{}{}{}{}'.format(a, op1, b, op2, c, op3, d)
            if eval(s) == 7:
                print('{}=7'.format(s))
                sys.exit(0)

Submission status: Accepted

Solution code:
A = input()
a = [int(c) for c in A]
for i in range(2**3):
    tmp = a[0]
    op = []
    for j in range(3):
        if (i >> j) & 1:
            op.append("+")
            tmp += a[j+1]
        else:
            op.append("-")
            tmp -= a[j+1]
    if tmp == 7:
        a = A
        print(a[0]+op[0]+a[1]+op[1]+a[2]+op[2]+a[3]+"=7")
        exit(0)

Submission status: Accepted

Solution code:
x = input()
x = [int(i) for i in x]
xCount = len(x)

aaa = 0
for i in range(2**(xCount -1)):
    binaryNumber = format(i,'b')
    binaryNumber = binaryNumber.zfill(xCount-1)
    binaryNumber = list(binaryNumber)
    binaryNumber = [int(i) for i in binaryNumber]
    
    for i in range(xCount-1):
        if binaryNumber[i] == 1 :
            binaryNumber[i] = '+' 
        
        if binaryNumber[i] == 0 :
            binaryNumber[i] = '-'
            
    
    result = []
    for i in range(xCount):
        result.append(x[i])
        if i < (xCount -1):
            result.append(binaryNumber[i])
    
    #result = [None]*(len(x)+len(binaryNumber))
    #result[::2] = x
    #result[1::2] = binaryNumber
    
    result = map(str, result)
    resultStr = ''.join(result)
    a = eval(resultStr)    
    #print(resultStr)
    #print(a)
    if (a == 7) :
        print(str(resultStr) + '=7')
        break

Submission status: Accepted

Solution code:
x = input()
x = [int(i) for i in x]
xCount = len(x)

aaa = 0
for i in range(2**(xCount -1)):
    binaryNumber = format(i,'b')
    binaryNumber = binaryNumber.zfill(xCount-1)
    binaryNumber = list(binaryNumber)
    binaryNumber = [int(i) for i in binaryNumber]
    
    for i in range(xCount-1):
        if binaryNumber[i] == 1 :
            binaryNumber[i] = '+' 
        
        if binaryNumber[i] == 0 :
            binaryNumber[i] = '-'
            
    
    result = [None]*(len(x)+len(binaryNumber))
    result[::2] = x
    result[1::2] = binaryNumber
    
    result = map(str, result)
    resultStr = ''.join(result)
    a = eval(resultStr)    
    #print(resultStr)
    #print(a)
    if (a == 7) :
        print(str(resultStr) + '=7')
        break

Submission status: Accepted

Solution code:
import itertools
op = ["+", "-"]
s = input()
for i in itertools.product(op, repeat=3):
    t = 0
    t += int(s[0])
    t += int(s[1]) * (1 if i[0] == "+" else -1)
    t += int(s[2]) * (1 if i[1] == "+" else -1)
    t += int(s[3]) * (1 if i[2] == "+" else -1)
    if t == 7:
        print(s[0] + i[0] + s[1] + i[1] + s[2] + i[2] + s[3] + "=7")
        exit()

Submission status: Accepted

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

for bit in range(1<<n-1):
    t = ""
    for i in range(n-1):
        if bit & (1<<i):
            t += "+"
        else:
            t += "-"
        t += abcd[i+1]
    t = abcd[0] + t

    ans = 0
    if t[1] == "+":
        ans = int(t[0]) + int(t[2])
    else:
        ans = int(t[0]) - int(t[2])
    for j in range(3,len(t),2):
        if t[j] == "+":
            ans += int(t[j+1])
        else:
            ans -= int(t[j+1])
    if ans == 7:
        print(t+"=7")
        exit()

Submission status: Accepted

Solution code:
###
#Train_Ticket
###

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(str(a+i+b+j+c+k+d)+'=7') 
                exit()

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(str(a+i+b+j+c+k+d)+'=7')
                exit()

Submission status: Accepted

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

for i in range(2<<3):
    ans = a[0]
    st = str(a[0])
    for j in range(3):
        if (i>>j)&1 == 1:
            ans += a[j+1]
            st += "+"+str(a[j+1])
        else:
            ans += -a[j+1]
            st += "-"+str(a[j+1])
    if ans == 7:
        print(st+"=7")
        break

Submission status: Accepted

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

for i in range(2<<3):
    ans = a[0]
    st = str(a[0])
    for j in range(3):
        if (i>>j)&1 == 1:
            ans += a[j+1]
            st += "+"+str(a[j+1])
        else:
            ans += -a[j+1]
            st += "-"+str(a[j+1])
    if ans == 7:
        print(st+"=7")
        break

Submission status: Accepted

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

a,b,c,d = list(str(input()))

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

Submission status: Accepted

Solution code:
s = input()
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])
b2 = -b
c2 = -c
list_b = [b,b2]
list_c = [c,c2]
def op (n):
    if n >= 0:
        return '+'
    else:
        return '-'

for i in list_b:
    for j in list_c:
        d2 = 7 - a - i - j
        if a + i + j + d2 == 7 and abs(d2) == d:
            b_ans = i
            c_ans = j
            d_ans = d2
            print(str(a)+op(b_ans)+str(b)+op(c_ans)+str(c)+op(d_ans)+str(d)+'=7' )
            exit()

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((a+i+b+j+c+k+d)+'=7')
        exit()

Submission status: Accepted

Solution code:
def main():
    S = input()
    cur = [[int(S[0]), S[0]]]
    for i in range(1, len(S)):
        temp = []
        for v, s in cur:
            temp.append([v+int(S[i]), s+"+"+S[i]])
            temp.append([v-int(S[i]), s+"-"+S[i]])
        cur = temp
    for v, s in cur:
        if v == 7:
            return s + "=7"

if __name__ == '__main__':
    print(main())

Submission status: Accepted

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

def calc(n, op, m):
  if(type(n) is not int):
    return False
  if(op == "+"):
    return n + m
  elif(op == "-"):
    return n - m
  elif(op == "*"):
    return n * m
  elif(m != 0):
    return n / m
  else:
    return False

ops1 = ["/", "+", "-", "*"]
ops2 = ["/", "+", "-", "*" ]
ops3 = ["/", "+", "-", "*" ]
for op1 in ops1:
  for op2 in ops2:
    for op3 in ops3:
      if(calc(calc(calc(a,op1,b),op2,c),op3,d) == 7):
        print(a,op1,b,op2,c,op3,d,"=7", sep="")
        exit()

Submission status: Accepted

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

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('=',end=''),print(7)
  exit()
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('=',end=''),print(7)
  exit()
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('=',end=''),print(7)
  exit()
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('=',end=''),print(7)
  exit()
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('=',end=''),print(7)
  exit()
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('=',end=''),print(7)
  exit()
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('=',end=''),print(7)
  exit()
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('=',end=''),print(7)
  exit()

Submission status: Accepted

Solution code:
from itertools import product
l=input()
a,b,c,d=int(l[0]),int(l[1]),int(l[2]),int(l[3])
p=list(product(range(2),repeat=3))
for i in range(8):
    t=a
    if p[i][0]==1:
        t+=b
    else:
        t-=b
    if p[i][1]==1:
        t+=c
    else:
        t-=c
    if p[i][2]==1:
        t+=d
    else:
        t-=d
    if t==7:
        A=p[i]
        break
print("{}{}{}{}{}{}{}=7".format(a,"+" if A[0]==1 else "-",b,"+" if A[1]==1 else "-",c,"+" if A[2]==1 else "-",d))

Submission status: Accepted

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

for i in range(8):
    calc=a
    B=bin(i)[2:].zfill(3)
    calc=calc+b if B[0]=="0" else calc-b
    calc=calc+c if B[1]=="0" else calc-c
    calc=calc+d if B[2]=="0" else calc-d
    if calc==7:
        break

Operator=["+" if i=="0" else "-" for i in B]
Operator.append("=7")
ans=""
for num, op in zip(inp, Operator):
    ans+=num
    ans+=op
print(ans)

Submission status: Accepted

Solution code:
abcd = input()

def dfs(i, s, sum):
    if i == 3:
        if sum == 7:
            print(s + "=7")
            exit()

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

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

Submission status: Accepted

Solution code:
import itertools


def main():
    s = list(input())
    op = list(itertools.product(['+', '-'], repeat=3))
    for i in op:
        formula = s[0]
        for index, j in enumerate(i):
            formula += j
            formula += s[index + 1]
        if eval(formula) == 7:
            print(formula + "=7")
            return
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
num = []
for c in s:
    num.append(int(c))

ans = ["","","","="]
for i in range(8):
    temp = format(i,"b").zfill(3)
    su = num[0]
    # print(temp)
    for j in range(3):
        if temp[j] == "1":
            su += num[j+1]
            ans[j] = "+"
        else:
            su-=num[j+1]
            ans[j] = "-"
    if su == 7:
        break

buf=str(num[0])
for i in range(3):
    buf+=ans[i]
    buf+=str(num[i+1])
buf+=ans[-1]
buf+="7"
print(buf)

Submission status: Accepted

Solution code:

A, B, C, D = list(input())
op = ['+', '-']

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

Submission status: Accepted

Solution code:
x=input()
y=[[int(x[i]),-int(x[i])] for i in range(4)]
for a in range(2):
    for b in range(2):
        for c in range(2):
            if y[0][0]+y[1][a]+y[2][b]+y[3][c]==7:
                ans=[x[0],"-" if a else "+",x[1],"-" if b else "+",x[2],"-" if c else "+",x[3]]
                break
print("".join(ans)+"=7")

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc079/tasks/abc079_c
# C - Train Ticket

a, b, c, d = list(input().split()[0])
a, b, c, d = [int(x) for x in [a, b, c, d]]

# 2 ** 3通りなので全探索でいけそう
is_ok = False

for op1 in [True, False]:
    work_1 = a + b if op1 else a - b
    for op2 in [True, False]:
        work_2 = work_1 + c if op2 else work_1 - c
        for op3 in [True, False]:
            work_3 = work_2 + d if op3 else work_2 - d
            if work_3 == 7:
                is_ok = True
                op_list = [op1, op2, op3]
                break
        if is_ok:
            break
    if is_ok:
        break

op_list = ['+' if op else '-' for op in op_list]
ans = str(a) + op_list[0] + str(b) + op_list[1] + str(c) + op_list[2] + str(d) + '=7'
print(ans)

Submission status: Accepted

Solution code:
s = input()

for bit in range(1 << 3):
    ans = int(s[0])
    f = s[0]

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

    if ans == 7:
        print(f + "=7")
        exit()

Submission status: Accepted

Solution code:
li = input()
for bit in range(1 << 3):
    f = li[0]

    for i in range(3):
        if bit & (1 << i):
            f += "+"
        else:
            f += "-"
        f += li[i+1]

        if i == 2:
            ans = int(f[0])
            for i in range(6):
                if f[i] == "+":
                    ans += int(f[i+1])
                elif f[i] == "-":
                    ans -= int(f[i+1])
            if ans == 7:
                print(f + "=7")
                exit()

Submission status: Accepted

Solution code:
S = input().rstrip()
op = ['+', '-']
for op1 in op:
    for op2 in op:
        for op3 in op:
            func = S[0] + op1 + S[1] + op2 + S[2] + op3 + S[3]
            if eval(func) == 7:
                print(func + '=7')
                exit()

Submission status: Accepted

Solution code:
S = input().rstrip()
op = ['+', '-']
for op1 in op:
    for op2 in op:
        for op3 in op:
            res = 0
            try:
                func = S[0] + op1 + S[1] + op2 + S[2] + op3 + S[3]
                res = eval(func)
            except:
                pass
            if res == 7:
                print(func + '=7')
                exit()

Submission status: Accepted

Solution code:
def dfs(i,SUM):
	if i == 3:
		return SUM == 7
	if dfs(i+1,SUM+L[i+1]):
		ops[i] = "+"
		return True
	if dfs(i+1,SUM-L[i+1]):
		ops[i] = "-"
		return True

	return False

L = list(map(int, input()))
k = 7

ops= [0]*3

dfs(0,L[0])

ans = []
for i in range(4):
	if i <= 2:
		ans.append(str(L[i]))
		ans.append(ops[i])
	if i == 3:
		ans.append(str(L[i]))
		ans.append("=7")

print("".join(ans))

Submission status: Accepted

Solution code:
import sys
INPUT = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 9)


def main():
    S = INPUT()
    l = len(S)

    for i in range(2 ** (l - 1)):
        tmp = S[0]
        for j in range(l - 1):
            if (i >> j) & 1: tmp += "+"
            else: tmp += "-"
            tmp += S[j + 1]

        if eval(tmp) == 7:
            print(tmp + "=7")
            break


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a,b,c,d=input();e="+-"
for i in e:
	for j in e:
		for k in e:
			s=a+i+b+j+c+k+d
			if eval(s)==7:
				print(s+"=7")
				exit()

Submission status: Accepted

Solution code:
a,b,c,d=input()
for i in "+-":
	for j in "+-":
		for k in "+-":
			s=a+i+b+j+c+k+d
			if eval(s)==7:
				print(s+"=7")
				exit()

Submission status: Accepted

Solution code:
s=input()
a=[]
count=0
minus=0
for i in range(len(s)):
  if(minus==1):
    minus=0
    continue

  if(s[i]=="-"):
    a.append(int("-"+s[i+1]))
    minus=1
  else:
    a.append(int(s[i]))

for i in [1,-1]:
  for j in [1,-1]:
    for k in [1,-1]:
      if(a[0] + a[1]*i + a[2]*j + a[3]*k == 7):
        if(i==1):
          i_2="+"
        else:
          i_2="-"
        if(j==1):
          j_2="+"
        else:
          j_2="-"
        if(k==1):
          k_2="+"
        else:
          k_2="-"

        print(str(a[0])+i_2+str(a[1])+j_2+str(a[2])+k_2+str(a[3])+"=7")
        exit()

Submission status: Accepted

Solution code:
import sys

s = input()

reslt_sum = 0

for bit in range(1<<len(s)-1):
    temp_sum = ''
    for i in range(len(s)):
        temp_sum += s[i]
        if bit & (1<<i):
            temp_sum += '-'
        elif i != len(s)-1:
            temp_sum += '+'
    if eval(temp_sum) == 7:
        print(temp_sum,'=7',sep='')
        sys.exit()

Submission status: Accepted

Solution code:
numbers =input()
total = 0
for i in range(2**3):
    total = int(numbers[0])
    string = '{0}'.format(numbers[0])
    for j in range(3):
        if i & 2**j:
            total += int(numbers[j+1])
            string += '+{0}'.format(numbers[j+1])
        else:
            total -= int(numbers[j+1])
            string += '-{0}'.format(numbers[j+1])
    if total == 7:
        string += '=7'
        print(string)
        exit(0)