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:
def dfs(i,s,res):
    if i==3:
        if res == 7:
            print(s+"=7")
            exit()
        return
 
    dfs(i+1,s+'+'+S[i+1],res+int(S[i+1]))
    dfs(i+1,s+'-'+S[i+1],res-int(S[i+1]))
 
S=input()
dfs(0,S[0],int(S[0]))

Submission status: Accepted

Solution code:
def dfs(i,St,res):
    if i==3:
        if res == 7:
            print(St+"=7")
            exit()
        return

    dfs(i+1,St+'+'+S[i+1],res+int(S[i+1]))
    dfs(i+1,St+'-'+S[i+1],res-int(S[i+1]))

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

Submission status: Accepted

Solution code:
def dfs(i,Str,res):
    if i==3:
        if res == 7:
            print(Str+"=7")
            exit()
        return

    dfs(i+1,Str+'+'+S[i+1],res+int(S[i+1]))
    dfs(i+1,Str+'-'+S[i+1],res-int(S[i+1]))

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

Submission status: Accepted

Solution code:
def dfs(i, Str, res):
    if i==3:
        if res==7:
            print(Str+"=7")
            exit()
        return
    
    dfs(i+1,Str+"+"+s[i+1],res+int(s[i+1]))
    dfs(i+1,Str+"-"+s[i+1],res-int(s[i+1]))

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

Submission status: Accepted

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

plmi=["+","-"]

def plus(a,b,i):
    if i==0:
        return a+b
    else:
        return a-b
    
ans=[]
def plusminus(a,b,c,d,i,j,k):
    global ans
    res1=plus(a,b,i)
    res2=plus(res1,c,j)
    res3=plus(res2,d,k)
    if res3==7:
        ans.append([i,j,k])
    
    
    
    
    
    


for i in range(2):
    for j in range(2):
        for k in range(2):
            plusminus(a,b,c,d,i,j,k)

kotae=ans[0]
hugou1=plmi[kotae[0]]
hugou2=plmi[kotae[1]]
hugou3=plmi[kotae[2]]
a=str(a)
b=str(b)
c=str(c)
d=str(d)

print(a+hugou1+b+hugou2+c+hugou3+d+"=7")

Submission status: Accepted

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

if a+b+c+d == 7:
    print(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:
n = input()

def dfs(i, f, s):
    if i == 3:
        if s == 7:
            print(f+"=7")
            exit()
    else:
        dfs(i+1, f+"+"+n[i+1], s+int(n[i+1]))
        dfs(i+1, f+"-"+n[i+1], s-int(n[i+1]))

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

Submission status: Accepted

Solution code:
n = input()

def dfs(i, l):
    if i == 3:
        return l+'=7' if eval(l) == 7 else ''
    return dfs(i+1, l+"+"+n[i+1]) or dfs(i+1, l+"-"+n[i+1])

print(dfs(0, n[0]))

Submission status: Accepted

Solution code:
n = input()

def dfs(i, l):
    if i == 3:
        return l+'=7' if sum(list(map(int, l.split("+")))) == 7 else ''
    return dfs(i+1, l+"+"+n[i+1]) or dfs(i+1, l+"+"+"-"+n[i+1])

print(dfs(0, n[0]).replace('+-', '-'))

Submission status: Accepted

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

    op_n = len(N)-1
    for i in range(2**op_n):
        op = ['-'] * op_n
        for j in range(op_n):
            if ((i >> j) & 1):
                op[op_n - 1 - j] = '+'
        ans = 0
        formula = N[0]+op[0]+N[1]+op[1]+N[2]+op[2]+N[3]
        ans = eval(formula)
        if ans == 7:
            print(formula+'=7')
            break


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
X = list(input())

for i in range(2**3):
    W = ["+"]*3
    for j in range(3):
        if (i >> j) & 1:
            W[j] = "-"
    formula = ""
    for k,l in zip(X,W+[""]):
        formula += k+l
    if eval(formula) == 7:
        print(formula+"=7")
        break

Submission status: Accepted

Solution code:
ticket = [int(i) for i in input()]
sum_list = [[] for i in range(len(ticket))]
sum_list[0] = [ticket[0]]
sign_list = [[] for i in range(len(ticket))]
sign_list[0] = [""]

for i in range(len(ticket)-1):
    for j in range(len(sum_list[i])):
        sum_list[i+1].append(sum_list[i][j] + ticket[i+1])
        sign_list[i+1].append(sign_list[i][j] + "+")
        sum_list[i+1].append(sum_list[i][j] - ticket[i+1])
        sign_list[i+1].append(sign_list[i][j] + "-")

for i in range(2**len(ticket)):
    if sum_list[len(ticket)-1][i] == 7:
        sign = sign_list[len(ticket)-1][i]
        break

for i in range(len(ticket)-1):
    print(str(ticket[i]) + sign[i], end="")
print(str(ticket[-1]) + "=7")

Submission status: Accepted

Solution code:
# coding: utf-8

def main():
	# ４つの整数を入力
	A, B, C, D = map(int, input())

	# 計算結果が７になるよう計算します。
	for op in range(0x7):
		a = A
		if ((op & 0x1) == 0):
			a += B
		else:
			a -= B
		if ((op & 0x2) == 0):
			a += C
		else:
			a -= C
		if ((op & 0x4) == 0):
			a += D
		else:
			a -= D
		if a == 7:
			print(
				'%d%s%d%s%d%s%d=7' % (
					A,
					'+' if ((op & 0x1) == 0) else '-',
					B,
					'+' if ((op & 0x2) == 0) else '-',
					C,
					'+' if ((op & 0x4) == 0) else '-',
					D
				)
			)
			break


if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
ABCD = input()

for i in range(2 ** 3):
    s = ABCD[0]
    for j in range(3):
        s += ['-', '+'][(i >> j) & 1] + ABCD[j+1]
    x = eval(s)
    if x == 7:
        print(s+'=7')
        break
    continue

Submission status: Accepted

Solution code:
import sys
tmp = input()
a = int(tmp[0])
b = int(tmp[1])
c = int(tmp[2])
d = int(tmp[3])
def tonum(a, n):
    if (a == 0):
        return n
    else:
        return - 1 * n
def operand(n):
    if (n == 0):
        return '+'
    else:
        return '-'

def format(a, b, c, d, ab, bc, cd):
    string = str(a) + operand(ab) + str(b) + operand(bc) + str(c) + operand(cd) + str(d)+'=7'
    return string
tmp=0
for i in range(2):
    for j in range(2):
        for k in range(2):
                tmp = a+tonum(i, b)+tonum(j, c)+tonum(k,d)
                if (tmp == 7):
                    print(format(a, b, c, d, i, j, k))
                    sys.exit()

Submission status: Accepted

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

A = X[0]
B = X[1]
C = X[2]
D = X[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, input())
p, m='+', '-'
def f(x):
  s=a
  out=str(a)
  if x&1:
    s+=b
    out+=p
  else:
    s-=b
    out+=m
  out+=str(b)
  if (x>>1)&1:
    s+=c
    out+=p
  else:
    s-=c
    out+=m
  out+=str(c)
  if (x>>2)&1:
    s+=d
    out+=p
  else:
    s-=d
    out+=m
  out+=str(d)+'=7'
  return [s, out]

for i in range(8):
  if f(i)[0]==7:
    print(f(i)[1])
    break

Submission status: Accepted

Solution code:
def dfs(pos, Str, res):
    #print(pos, Str, res)
    if pos == 4:
        if res == 7:
            print(Str + "=7")
            exit()
        return
    dfs(pos+1, Str + "+" + s[pos], res + int(s[pos]))
    dfs(pos+1, Str + "-" + s[pos], res - int(s[pos]))

s = input()
dfs(1, s[0], int(s[0]))

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
n = str(input())

a = int(n[0])
b = int(n[1])
c = int(n[2])
d = int(n[3])
l = [b,c,d]
s = a+b+c+d
ans = 1

if s == 7:
  h_1,h_2,h_3 = "+","+","+"
elif s-b*2 == 7:
  h_1,h_2,h_3 = "-","+","+"
elif s-c*2 == 7:
  h_1,h_2,h_3 = "+","-","+"
elif s-d*2 == 7:
  h_1,h_2,h_3 = "+","+","-"
elif s-b*2-c*2 == 7:
  h_1,h_2,h_3 = "-","-","+"
elif s-b*2-d*2 == 7:
  h_1,h_2,h_3 = "-","+","-"
elif s-c*2-d*2 == 7:
  h_1,h_2,h_3 = "+","-","-"
elif s-b*2-c*2-d*2 == 7:
  h_1,h_2,h_3 = "-","-","-"
else:
  ans = 0

if ans == 0:
  print("")
else:
  ans = "{0}{1}{2}{3}{4}{5}{6}{7}{8}".format(a,h_1,b,h_2,c,h_3,d,"=",7)
  print(ans)

Submission status: Accepted

Solution code:
import itertools

A, B, C, D = map(int, input())

for op1, op2, op3 in itertools.product([1, -1], [1, -1], [1, -1]):
  if A + op1 * B + op2 * C + op3 * D == 7:
    print('{}{:+}{:+}{:+}=7'.format(A, op1 * B, op2 * C, op3 * D))
    break

Submission status: Accepted

Solution code:
S = list(input())

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

def fomula(S, op):
    s = list(S)
    count = 1
    for i in range(len(s) - 1):
        s.insert(i+count, op[i])
        count += 1
    fomula = ""
    for k in range(len(s)):
        fomula += s[k]

    return fomula


for i in range(2 ** (len(S) -1)):
    fomul = fomula(S, ops[i])
    if eval(fomul) == 7:
        print(fomul+"=7")
        exit()

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    s = input()
    slen = len(s)-1
    for bit in range(1 << slen): # 中に入るもの
        sum_ = int(s[0])
        ans = s[0]
        for i in range(3):
            if bit & (1 << i):#フラグが立ってたら足す
                sum_ += int(s[i+1])
                ans += "+" + s[i+1]
            else:
                sum_ -= int(s[i+1])
                ans += "-" + s[i+1]
        if sum_ == 7:
            print(ans + "=7")
            exit()
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
num = input()
a = int(num[0])
b = int(num[1])
c = int(num[2])
d = int(num[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:
import sys

a, b, c, d = input()

for i in range(2**3):
    op = ['','','']
    for j in range(3):
        if (i >> j) & 1:
            op[j] = '+'
        else:
            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:
s=input()
l=list(s)

a=[[] for _ in range(1<<len(s)-1)]   
for i in range(1<<len(s)-1):
    w=i
    for j in range(len(s)-1):
        b=w%2
        a[i].append(b)
        w//=2
#print(a)
for h in range(1<<len(s)-1):
    y=l[0]+"".join(("+" if a[h][i] else "-")+l[i+1] for i in range(len(a[h])))
    if eval(y)==7:
        print(y+"=7")
        break

Submission status: Accepted

Solution code:
s=input()
l=list(s)
for k in range(1 << (len(s)-1)):
    x=l[0]+"".join(("+" if (k>>i & 1) else "-")+j for i,j in enumerate(l[1:]))
    if eval(x)==7:
        print(x+"=7")
        break

Submission status: Accepted

Solution code:
li = list(map(int, input()))
for bit in range(1 << 3):
    ans = li[0]
    op = ["-"] * 3
    for i in range(3):
        if bit & (1 << i):
            ans += li[i+1]
            op[i] = "+"
        else:
            ans -= li[i+1]
    if ans == 7:
        print("{}{}{}{}{}{}{}=7".format(li[0],op[0],li[1],op[1],li[2],op[2],li[3]))
        exit()

Submission status: Accepted

Solution code:
def dfs(i, f):
    
    if i==3:
        if(eval(f)==7):
            print(f + '=7')
            exit()
    
    else:
        # operand がプラス
        dfs( i + 1, f + '+' + s[i+1] ) 
    
        # operand がマイナス
        dfs( i + 1, f + '-' + s[i+1] ) 
        
s = list(input())
dfs(0, s[0])

Submission status: Accepted

Solution code:
S = [int(x) for x in input()]
for i in range(1 << len(S)-1):
    s = S[0]
    ans = str(S[0])
    for j in range(len(S)-1):
        if ((i >> j) & 1):
            s += S[j+1]
            ans += "+" + str(S[j+1])
        else:
            s -= S[j+1]
            ans += "-" + str(S[j+1])
    if s == 7:
        print(ans + "=7")
        break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
INF=10**9
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()

def main():
    l=list(input())+['7']
    ans=[l[i//2] for i in range(10)]
    ans[-2]=ans[-3]='='
    for i in range(8):
        for j in range(3):
            if (i>>j)&1:
                ans[j*2+1]='+'
            else:
                ans[j*2+1]='-'
        if eval(''.join(ans)):
            del ans[-2]
            print(''.join(ans))
            exit()

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
INF=10**9
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()

def main():
    l=list(map(int,list(input())))
    for i in range(8):
        tmp=l[:]
        for j in range(3):
            if (i>>j)&1:
                tmp[j+1]*=-1
        if sum(tmp)==7:
            print(tmp[0],end='')
            for x in tmp[1:]:
                if x<0:
                    print(x,end='')
                else:
                    print('+',x,sep='',end='')
            print('=7')
            exit()

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#https://atcoder.jp/contests/abc079/tasks/abc079_c
# -*- coding: utf-8 -*-
A = input()
numbers = []
for i in range(len(A)):
  numbers.append(int(A[i]))
n = len(A)-1 #オペレータの数
for i in range(2**n):
  tmp = numbers[0]
  ans = str(numbers[0])
  for j in range(n):
    if (i >> j) & 1:
      tmp += numbers[j+1]
      ans += "+"
      ans += str(numbers[j+1])
    else:
      tmp -= numbers[j+1]
      ans += "-"
      ans += str(numbers[j+1])
  if tmp == 7: 
    print(ans+"=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])
ans=0

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

Submission status: Accepted

Solution code:
a,b,c,d=input()
for i,j,k in map(lambda x:format(x,"03b").translate(str.maketrans("01","-+")),range(8)):
 h=a+i+b+j+c+k+d
 if eval(h)==7:print(h+"=7");break

Submission status: Accepted

Solution code:
s="".join;*i,l=input()
for t in map(lambda x: format(x,"03b").translate(str.maketrans("01","-+")),range(8)):
 h=s(map(s,zip(i,t)))+l
 if eval(h)==7:print(h+"=7");break

Submission status: Accepted

Solution code:
s = "".join
*i, l = input()
for t in map(lambda x: format(x, "03b").translate(str.maketrans("01","-+")), range(8)):
    h = s(map(s, zip(i, t))) + l
    if eval(h) == 7:
        print(h+"=7")
        break

Submission status: Accepted

Solution code:
S=input()
N=len(S)
A=[int(i) for i in S]
D=["+" for i in range(N-1)]
output=S[0]
for i in range(2**N):
  C=A
  B=D
  for j in range(N-1):
    if ((i>>j)&1):
      C[j+1]= -1*int(str(S[j+1]))
      B[j]=  "-"
    else:
      C[j+1]= int(str(S[j+1]))
      B[j]=  "+"
  #print(C,B,sum(C))
  if sum(C) ==7:
    for i in range(1,N):
      output += B[i-1] + str(S[i])
    print(output+"=7")
    break

Submission status: Accepted

Solution code:
# C
# 2020/04/21  16:18-16:27
l = list(map(str, input()))

n = len(l)
for i in range(2**(n-1)):
    op = ['+']*(n-1)
    for j in range(n):
        if i >> j & 1:
            op[j] = '-'
    if eval(l[0] + op[0] + l[1] + op[1] + l[2] + op[2] + l[3]) == 7:
        print(l[0] + op[0] + l[1] + op[1] + l[2] + op[2] + l[3], '=7', sep='')
        break

Submission status: Accepted

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
S = input()
A,B,C,D = map(int,list(S))
numlis = [B,C,D]

for bitlines in range(0,1<<3):
    ans = [A]
    num = A
    for target in range(3):
        if bitlines>>target & 1:
            num += numlis[target]
            ans = ans+["+",numlis[target]]
        else:
            num -= numlis[target]
            ans = ans+["-",numlis[target]]
    if num ==7:
        ans.append("=7")
        print(*ans,sep="")
        exit()

# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Accepted

Solution code:
import itertools

def solve(S):
    bit_list = list(itertools.product([0, 1], repeat=3))
    
    for pattern in bit_list:
        count = int(S[0])
        ans = S[0]
        for i in range(3):
            if pattern[i] == 0:
                count += int(S[i+1])
                ans += "+" + S[i+1]
            else:
                count -= int(S[i+1])
                ans += "-" + S[i+1]
        
        if count == 7:
            print(ans + "=7")
            break
    

if __name__ == '__main__':
    S = input()
    solve(S)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc079/tasks/abc079_c

a,b,c,d=list(input())
op=['+','-']

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

Submission status: Accepted

Solution code:
import itertools

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

for i in itertools.product(["+", "-"], repeat = 3):
    #repeatの数字は項数 i[n]で指定。
    x = a + i[0] + b + i[1] + c + i[2] + d
    if eval(x) == 7:
        break

print(x + "=7")

Submission status: Accepted

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

if sumn == 7:
    print(n[0]+"+"+n[1]+"+"+n[2]+"+"+n[3]+"=7")
elif sumn - 2*d == 7:
    print(n[0]+"+"+n[1]+"+"+n[2]+"-"+n[3]+"=7")
elif sumn - 2*c == 7:
    print(n[0]+"+"+n[1]+"-"+n[2]+"+"+n[3]+"=7")
elif sumn - 2*b == 7:
    print(n[0]+"-"+n[1]+"+"+n[2]+"+"+n[3]+"=7")
elif sumn - 2*b - 2*c == 7:
    print(n[0]+"-"+n[1]+"-"+n[2]+"+"+n[3]+"=7")
elif sumn - 2*b - 2*d == 7:
    print(n[0]+"-"+n[1]+"+"+n[2]+"-"+n[3]+"=7")
elif sumn - 2*c - 2*d == 7:
    print(n[0]+"+"+n[1]+"-"+n[2]+"-"+n[3]+"=7")
elif sumn - 2*b - 2*c - 2*d == 7:
    print(n[0]+"-"+n[1]+"-"+n[2]+"-"+n[3]+"=7")

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict(list)
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    s = input()
    slen = len(s) - 1
    a = s[0]
    for bit in range(1 << slen): # 間に入る数だけ求めたい
        sum = int(a) # 最初におるやつ
        ans = a # 最初
        # - だったらひいて + だったら足せばいい?
        for i in range(3):
            if bit & (1 << i):
                sum += int(s[i+1])
                ans += "+" + s[i+1]
            else:
                sum -= int(s[i+1])
                ans += "-" + s[i+1]
        if sum == 7:
            print(ans+"=7")
            exit()


if __name__ == '__main__':
  main()

Submission status: Accepted

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

for i in range(2):
  for j in range(2):
    for k in range(2):
      f= a + op[i] + b + op[j] +c + op[k] +d
      if eval(f) == 7:
        print(f + "=7")
        exit()

Submission status: Accepted

Solution code:
import sys


def dfs(i, s, val, formula):
    if (i == len(s) - 1):
        if val == 7:
            print(formula + "=7")
            sys.exit()
            return formula
        else:
            return None

    dfs(i + 1, s, val + int(s[i + 1]), formula + "+" + s[i + 1])
    dfs(i + 1, s, val - int(s[i + 1]), formula + "-" + s[i + 1])
    return None


s = input()
ans = dfs(0, s, int(s[0]), s[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ABCD = list(input())

for bit in range(1 << 3):
    SUM = int(ABCD[0])
    for i in range(3):
        if (bit >> i) & 1:
            SUM += int(ABCD[i + 1])
        else:
            SUM -= int(ABCD[i + 1])
    if SUM != 7: continue
    ans = ABCD[0]
    for i in range(3):
        ans += "+" if (bit >> i) & 1 else "-"
        ans += ABCD[i + 1]
    print(ans + "=7")
    exit()

Submission status: Accepted

Solution code:
A,B,C,D=map(int, list(input()))
L=["+","-"]

for a in L:
  for b in L:
    for c in L:
      now=A
      if a=="+":
        now+=B
      else:
        now-=B
      if b=="+":
        now+=C
      else:
        now-=C
      if c=="+":
        now+=D
      else:
        now-=D
      #print(now)
      if now==7:
        print(str(A)+a+str(B)+b+str(C)+c+str(D)+"=7")
        exit()

Submission status: Accepted

Solution code:
L = [int(x) for x in input()]
A, B, C, D = L[0], L[1], L[2], L[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:
from itertools import product

A, B, C, D = map(int, input())

for p in product((1, -1), repeat=3):
    cnt = A
    for s, i in zip(p, (B, C, D)):
        cnt += s * i
    if cnt == 7:
        ans = str(A)
        for s, i in zip(p, (B, C, D)):
            ans += ('+' if s > 0 else '-') + str(i)
        ans += '=7'
        print(ans)
        exit()

print('-1')

Submission status: Accepted

Solution code:
a=list(input().rstrip())

for i in range(8):
    s = list("-".join(a))

    for j in range(0, 3):
        if i&(1<<j):
            s[1+j+j]="+"
    if eval(''.join(s))==7:
        print(''.join(s)+"=7")
        exit()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

    # bit全探索
    # https://qiita.com/gogotealove/items/11f9e83218926211083a#%E4%BE%8B%E9%A1%8C-1
    L = input()
    L = [int(c) for c in L]



    n = len(L)-1
    # 昇順での探索だよ
    for i in range(2 ** n):
        ans=L[0]
        cnt=L[0]
        s=''

        """        
        10進数表記　2進数表記
        0           000
        1           001
        2           010
        3           011
        4           100
        5           101
        6           110
        7           111
        """

        for j in range(n):  # このループが一番のポイント
            if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
                cnt+=L[-j-1]
                s='+'+str(L[-j-1])+s
            else:
                cnt-=L[-j-1]
                s='-'+str(L[-j-1])+s

        if cnt==7:
            print(str(L[0])+s+'=7')
            break



resolve()

Submission status: Accepted

Solution code:
L=input()
if int(L[0])+int(L[1])+int(L[2])+int(L[3])==7:
	print(L[0],end="")
	print("+",end="")
	print(L[1],end="")
	print("+",end="")
	print(L[2],end="")
	print("+",end="")
	print(L[3],end="")
	print("=",end="")
	print(7)
elif int(L[0])+int(L[1])+int(L[2])-int(L[3])==7:
	print(L[0],end="")
	print("+",end="")
	print(L[1],end="")
	print("+",end="")
	print(L[2],end="")
	print("-",end="")
	print(L[3],end="")
	print("=",end="")
	print(7)
elif int(L[0])+int(L[1])-int(L[2])+int(L[3])==7:
	print(L[0],end="")
	print("+",end="")
	print(L[1],end="")
	print("-",end="")
	print(L[2],end="")
	print("+",end="")
	print(L[3],end="")
	print("=",end="")
	print(7)
elif int(L[0])+int(L[1])-int(L[2])-int(L[3])==7:
	print(L[0],end="")
	print("+",end="")
	print(L[1],end="")
	print("-",end="")
	print(L[2],end="")
	print("-",end="")
	print(L[3],end="")
	print("=",end="")
	print(7)
elif int(L[0])-int(L[1])+int(L[2])+int(L[3])==7:
	print(L[0],end="")
	print("-",end="")
	print(L[1],end="")
	print("+",end="")
	print(L[2],end="")
	print("+",end="")
	print(L[3],end="")
	print("=",end="")
	print(7)
elif int(L[0])-int(L[1])+int(L[2])-int(L[3])==7:
	print(L[0],end="")
	print("-",end="")
	print(L[1],end="")
	print("+",end="")
	print(L[2],end="")
	print("-",end="")
	print(L[3],end="")
	print("=",end="")
	print(7)
elif int(L[0])-int(L[1])-int(L[2])+int(L[3])==7:
	print(L[0],end="")
	print("-",end="")
	print(L[1],end="")
	print("-",end="")
	print(L[2],end="")
	print("+",end="")
	print(L[3],end="")
	print("=",end="")
	print(7)
elif int(L[0])-int(L[1])-int(L[2])-int(L[3])==7:
	print(L[0],end="")
	print("-",end="")
	print(L[1],end="")
	print("-",end="")
	print(L[2],end="")
	print("-",end="")
	print(L[3],end="")
	print("=",end="")
	print(7)

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 heapq import heapify, heappop, heappush

def input(): return sys.stdin.readline().strip()
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

M = list(input())

S = [int(s) for s in M]
L = [0, 1] #生成する数字
num = 3 #生成するビット数
bit_list = list(product(["+", "-"], repeat=num))

tmp = 0
for b in bit_list:
    ans = 0
    # print(b)
    for i, o in enumerate(b):
        # print("I", o)
        if o == "+":
            if i == 0:
                ans = S[i] + S[i+1]
            else:
                ans += S[i+1]
        else:
            if i == 0:
                ans = S[i] - S[i+1]
            else:
                ans -= S[i+1]
    # print(ans)
    if ans == 7:
        tmp = b
        break
ans = ""
for i, c in enumerate(tmp):
    ans += M[i]
    ans += c
ans += M[-1] + "=7"
print(ans)

Submission status: Accepted

Solution code:
def kipp(i,f):
    if i == 3:
        if eval(f) == 7:
            print(f+"=7")
            exit()
    else:
        kipp(i+1,f+"+"+a[i+1])
        kipp(i+1,f+"-"+a[i+1])

a = list(input())
kipp(0,a[0])

Submission status: Accepted

Solution code:
import itertools
a,b,c,d = list(input())
for i in itertools.product(["+", "-"], repeat=3):
  x = a + i[0] + b + i[1] + c + i[2] + d
  if eval(x) == 7:break
print(x+"=7")

Submission status: Accepted

Solution code:
def resolve():
  x = input()
  a = int(x[0])
  b = int(x[1])
  c = int(x[2])
  d = int(x[3])
  for i in range(2):
    ans1 = str(a)
    sum1 = a
    if i == 0:
      sum1 -= b
      ans1 += "-" + str(b)
    else:
      sum1 += b
      ans1 += "+" + str(b)
    for j in range(2):
      ans2 = ans1
      sum2 = sum1
      if j == 0:
        sum2 -= c
        ans2 += '-' + str(c)
      else:
        sum2 += c
        ans2 += '+' + str(c)
      for k in range(2):
        sum3 = sum2
        ans3 = ans2
        if k == 0:
          sum3 -= d
          ans3 += '-' + str(d)
        else:
          sum3 += d
          ans3 += '+' + str(d)
        if sum3 == 7:
          print(ans3 + "=7")
          return
  return

if __name__ == "__main__":
  resolve()

Submission status: Accepted

Solution code:
a = input()
for bit in range(1<<3):
    ans1 = int(a[0])
    ans = []
    for i in range(3):
        mask = 1<<i
        if mask&bit:
            ans.append('+')
            ans1 += int(a[i+1])
        else:
            ans.append('-')
            ans1 -= int(a[i+1])
            
    if ans1==7:
        break
ans.append('=7')
d = []
for i in range(4):
    d.append(a[i])
    d.append(ans[i])
print(''.join(d))

Submission status: Accepted

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

ans_c=[['+','+','+'],['+','+','-'],['+','-','+'],['-','+','+'],['+','-','-'],['-','+','-'],['-','-','+'],['-','-','-'],]

for i in ans_c:
  num=l[0]
  for j in range(3):
    if i[j]=='+':
      num+=l[j+1]
    else:
      num-=l[j+1]
  if num==7:
    print(str(l[0])+i[0]+str(l[1])+i[1]+str(l[2])+i[2]+str(l[3])+'=7')
    exit()