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:

if __name__ == '__main__':

	s = input()
	s_len = len(s) -1
	A = ""
	for i in range(2**s_len):
		A = s[0]
		for j in range(s_len):
			if i & (1 << j):
				A += "+" + s[j+1]
			else:
				A += "-" + s[j+1]
		if eval(A) == 7:
			break

	print(A + "=7")

Submission status: Accepted

Solution code:
l=input()
num=[int(l[i]) for i in range(4)]
pm=['+','-']
for i in pm:
  a,b,c,d=num[0],num[1],num[2],num[3]
  for j in pm:
    for k in pm:
      if i=='-':
        b=b*(-1)
      if j=='-':
        c=c*(-1)
      if k=='-':
        d=d*(-1)
      if a+b+c+d==7:
        print(str(a)+i+str(abs(b))+j+str(abs(c))+k+str(abs(d))+'='+'7')
        exit()
      a,b,c,d=num[0],num[1],num[2],num[3]

Submission status: Accepted

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

for i in range(8):
    sum=s[0]
    marks=[]
    for k in range(3):
        if 1&(i>>k):
            sum+=s[k+1]
            marks.append('+')
        else:
            sum-=s[k+1]
            marks.append('-')
    if sum==7:
        for l in range(3):
            print('{}{}'.format(s[l],marks[l]),end='')
        print('{}=7'.format(s[3]))
        exit()

Submission status: Accepted

Solution code:
#ABC079-C-Train Ticket
s = input()

n = len(s) - 1

for i in range(n**2):
    tmp = ""
    for j in range(n+1):
        tmp += s[j]
        
        if (i >> j)&1 :
            tmp += '+'
        else:
            tmp += '-'
            
    tmp = tmp[:-1]
    
    if eval(tmp) == 7:
        print(tmp+'=7')
        break

Submission status: Accepted

Solution code:
s = list(input())
import sys
def bitlist(n, a, b):
  res = []
  for i in range(2**n):
    pattern = []
    for j in range(n):
      if (i >> j) & 1:
        pattern.insert(0, a)
      else:
        pattern.insert(0, b)
    res.append(pattern)
  return res

n = len(s)
lst = bitlist(n-1, "+", "-")
for i in range(2**(n-1)):
  calc = s[0]
  for j in range(n-1):
    calc += lst[i][j] + s[j+1]
  if eval(calc) == 7:
    calc += "=7"
    print(calc)
    sys.exit()

Submission status: Accepted

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

    for i in range(1<<n-1):
        t = ''
        for j in range(n-1):
            t += S[j]
            if i & (1<<j):
                t += '+'
            else:
                t += '-'
        t += S[n-1]
        if eval(t) == 7:
            print(t+'=7')
            break


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = list(input())
import sys
def bitlist(n, a, b):
  res = []
  for i in range(2**n):
    pattern = []
    for j in range(n):
      if (i >> j) & 1:
        pattern.insert(0, a)
      else:
        pattern.insert(0, b)
    res.append(pattern)
  return res

n = len(s)
lst = bitlist(n-1, "+", "-")
for i in range(2**n):
  calc = int(s[0])
  for j in range(n-1):
    if lst[i][j] == "+":
      calc += int(s[j+1])
    else:
      calc -= int(s[j+1])
  if calc == 7:
    res = s[0]
    for k in range(n-1):
      res += lst[i][k] + s[k+1]
    res += "=7"
    print(res)
    sys.exit()

Submission status: Accepted

Solution code:
ABCD = input()
res = 0
for i in range(1 << 3):
    l = []
    for j in range(3):
        if i >> j & 1 == 1:
            l.append(ABCD[j])
            l.append("+")
        else:
            l.append(ABCD[j])
            l.append("-")
    l.append(ABCD[-1])
    l = ''.join(l)
    res = eval(l)
    if res == 7:
        print(l + "=7")
        exit()

Submission status: Accepted

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

v = [1, -1]
ans = 0
for j in v:
    for k in v:
        for l in v:
            if a + j*b + k*c + l*d == 7:
                if j == 1:
                    lb = "+"
                else:
                    lb = "-"
                if k == 1:
                    lk = "+"
                else:
                    lk = "-"
                if l == 1:
                    ll = "+"
                else:
                    ll = "-"
                print(str(a)+lb+str(b)+lk+str(c)+ll+str(d)+"=7")
                exit()

Submission status: Accepted

Solution code:
s = input()

num_cases = 2 ** 3
patterns = [0] * num_cases
for i in range(num_cases):
    patterns[i] = [0] * 3
    for j in range(3):
        if ((i>>j) & 1):
            patterns[i][j] = '+'
        else:
            patterns[i][j] = '-'
for pattern in patterns:
    res = int(s[0])
    for i in range(3):
        op = pattern[i]
        if op == '+':
            res += int(s[i+1])
        else:
            res -= int(s[i+1])
    if res == 7:
        ans_p = pattern
        break

ans = s[0] + ans_p[0] + s[1] + ans_p[1] + s[2] + ans_p[2] + s[3] + '=7'

print(ans)

Submission status: Accepted

Solution code:
A = input()

num = [int(A[0])]
hugou = ['']*3
ans = [0]*4
ans[0] = int(A[0])

for i in range(1,len(A)):
    num.append(A[i])

for i in range(2**3):
    tmp = format(i,'03b')
    for j in range(len(tmp)):
        if tmp[j] == "0":
            ans[j+1] = -int(num[j+1])
            hugou[j] = '-'
        else:
            ans[j+1] = int(num[j+1])
            hugou[j] = '+'
    if sum(ans) == 7:
        print(str(ans[0]) + hugou[0] \
              + str(abs(ans[1])) + hugou[1] \
              + str(abs(ans[2])) + hugou[2] \
              + str(abs(ans[3]))+"=7")
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=input()
for i in range(2**3):
    ans=''
    for j in range(4):
        ans+=n[j]
        if j==3:
            continue
        if (i>>j)&1:
            ans+='+'
        else:
            ans+='-'
    if eval(ans)==7:
        print(ans+'=7')
        break

Submission status: Accepted

Solution code:
s = input()

for bit in range(1<<len(s)):
  f = s[0]
  ans = int(s[0])
  for i in range(1,len(s)):
    if bit & 1<<i:
      f = f + '+' + s[i]
      ans += int(s[i])
    else:
      f = f + '-' + s[i]
      ans -= int(s[i])
  
  if ans == 7:
    print(f + '=7')
    exit()

Submission status: Accepted

Solution code:
s = input()

def dfs(i,f,ans):
  
  if i == len(s)-1:
    
    if ans == 7:
      print(f + '=7')
      exit()
    
  else:
    dfs(i+1, f + '+' + s[i+1], ans+int(s[i+1]))
    dfs(i+1, f + '-' + s[i+1], ans-int(s[i+1]))
      
dfs(0,s[0], int(s[0]))

Submission status: Accepted

Solution code:
x = list(input())
for i in range(2**3):
  a = []
  for j in range(3):
    if (i >> j) & 1:
      a.append('+')
    else:
      a.append('-')
  b = x[0]+a[0]+x[1]+a[1]+x[2]+a[2]+x[3]
  if eval(b) == 7:
    print(b+'=7')
    break

Submission status: Accepted

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

#print(A,B,C,D)

for i in range(2**3):
    ls=["+","+","+"]
    for j in range(3):
        if (i>>j)&1:
            ls[j]="-"
    #print(ls)
        
    if eval(A+ls[0]+B+ls[1]+C+ls[2]+D)==7:
        print(A+ls[0]+B+ls[1]+C+ls[2]+D+"=7")
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

for i in range(8):
    ans = int(S[0])
    ops = []
    for j in range(3):
        if i & (1 << j):
            ans += int(S[j + 1])
            ops.append("+")
        else:
            ans -= int(S[j + 1])
            ops.append("-")

    if ans == 7:
        print(S[0], ops[0], S[1], ops[1], S[2], ops[2], S[3], "=7", sep="")
        break

Submission status: Accepted

Solution code:
# coding: utf-8
n = input()
total=0
op_cnt = len(n) - 1 
for i in range(2 ** op_cnt):
    op = ["+"] * op_cnt  
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt - 1 - j] = "-" 
    formula = ""
    for p_n, p_o in zip(n, op + [""]):  
        formula += (p_n + p_o)
    if eval(formula)==7:
        print(formula+"=7")
        break

Submission status: Accepted

Solution code:
s = input()
A, B, C, D = s[0], s[1], s[2], s[3]
ans = 7
siki = [[] for _ in range(2**3)]
for i in range(2 ** 3):
    for j in range(3):
        if (i >> j) & 1:
            siki[i].append("+")
        else:
            siki[i].append("-")

for o1, o2, o3 in siki:
    temp = A + o1 + B + o2 + C + o3 + D
    if eval(temp) == ans:
        print(temp + "=7")
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

s=list(input())

def f(i,tmp,func):
  if i==4:
    if tmp == 7:
      print(func+"=7")
      sys.exit()
  else:
    f(i+1,tmp+int(s[i]),func+"+"+s[i])
    f(i+1,tmp-int(s[i]),func+"-"+s[i])
    
f(1,int(s[0]),s[0])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = input()
#隙間の数
a = len(n)-1
for i in range(2**a):
  l = ["-"]*a
  for j in range(a):
    if ((i>>j)&1):
      l[a-1-j] = "+"
#上記で全てのパターンできた。
  f = ""
  for aa,bb in zip(n,l+[""]):
    f  += (aa+bb)
  if eval(f)==7:
    print(f+'=7')
    break

#qiitaのbit全探索見ながらやった

Submission status: Accepted

Solution code:
s = 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 = input()
for i in range(2**3):
  a = int(s[0])
  ans = s[0]
  for j in range(3):
    a += ((-1)**((i >> j & 1) == 1))*int(s[j+1])
    ans += "+"*((i >> j & 1) == 0)
    ans += "-"*((i >> j & 1) == 1)
    ans += s[j+1]
  if a == 7:
    print(ans+"=7")
    quit()

Submission status: Accepted

Solution code:
abcd = list(map(int, input()))
op = {'0':'+', '1':'-'}
for i in range(8):
    result = abcd[0]
    code = str(abcd[0])
    pointer = 1
    for k in bin(i)[2:].zfill(3):
        if op[k] == '+':
            code += '+'
            result += abcd[pointer]
        else:
            code += '-'
            result -= abcd[pointer]
        code += str(abcd[pointer])
        pointer += 1
    if result == 7:
        code += "=7"
        break
print(code)

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:
s = input()
A, B, C, D = int(s[0]), int(s[1]), int(s[2]), int(s[3])
N = 3


for i in range(2**N):
    sum = int(s[0])
    f = s[0]
    for j in range(N):
        if i>>j & 1:
            sum += int(s[j+1])
            f += "+" + s[j+1]
        else:
            sum -= int(s[j+1])
            f += "-" + s[j+1]

    if sum == 7:
        print(f + "=7")
        break

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
S=input()
A=[int(s) for s in S]
for i in range(2):
    for j in range(2):
        for k in range(2):
            if A[0]+A[1]*(-1)**i+A[2]*(-1)**j+A[3]*(-1)**k==7:
                temp=[i,j,k]
                break
ans=S[0]
for l in range(3):
    if temp[l]==0:
        ans+="+"
    else:
        ans+="-"
    ans+=S[l+1]
print(ans+"=7")

Submission status: Accepted

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

for n in range(2**3):
    sum_N=N[0]
    l=[]
    for i in range(3):
        if (n>>i)&1==1:
            sum_N+=N[i+1]
            l.append("+")
        else:
            sum_N-=N[i+1]
            l.append("-")
    if sum_N==7:
        break
print("{}{}{}{}{}{}{}".format(N[0],l[0],N[1],l[1],N[2],l[2],N[3])+"=7")

Submission status: Accepted

Solution code:
s=input()
item=["+","-"]
 
last = ""
for op1 in item:
  for op2 in item:
    for op3 in item:
      ans = s[0] + op1 + s[1] + op2 + s[2] + op3 +s[3]
      if eval(ans)==7:
        last = ans+"=7"
print(last)

Submission status: Accepted

Solution code:
def ans(s, c):
	d, *n = map(str, s)
	for j in range(len(n)):
		if ((c >> j) & 1):
			d = d + '+' + n[j]
		else:
			d = d + '-' + n[j]
	print(d + '=' + '7')

def resolve():
	s = [int(i) for i in input()]
	c = 0

	for i in range(1 << len(s) - 1):
		ts = s[1:]
		k = s[0]
		for j in range(len(s)-1):
			if ((i >> j) & 1):
				k += ts[0]
			else:
				k -= ts[0]
			ts = ts[1:]
		if k == 7:
			c = i
	ans(s, c)

resolve()

Submission status: Accepted

Solution code:
from itertools import product


ABCD = list(input())

OPERATIONS = list(product("+-", repeat = 3))

for operation in OPERATIONS:
    for i in range(3):
        ABCD.insert(2 * i + 1, operation[i])
    if eval("".join(ABCD)) == 7:
        print("".join(ABCD) + "=7")
        exit()
    for i in range(3)[::-1]:
        ABCD.pop(2 * i + 1)

Submission status: Accepted

Solution code:
s = str(input())
length = len(s)

bins = []
for i in range(2**(length-1)):
    bins.append(list(str(format(i,'b')).zfill(length-1)))

for i in range(2**(length-1)):
    tmp_str=s[0]
    tmp_ans=int(s[0])
    for j in range(length-1):
        if(bins[i][j]=='0'):
            tmp_str += '+'+s[j+1]
            tmp_ans += int(s[j+1])
        else:
            tmp_str += '-'+s[j+1]
            tmp_ans -= int(s[j+1])
    if(tmp_ans == 7):
        ans = tmp_str

print(ans+'=7')

Submission status: Accepted

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

ans = 0
for i in range(2 ** (N - 1)):
    signs = bin(i)[2:].zfill(N - 1).replace('0', '+').replace('1', '-')

    tmp_s = S[0]
    for j, sign in enumerate(signs):
        tmp_s += sign + S[j + 1]

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

Submission status: Accepted

Solution code:
s=input()
s=list(map(str,str(s)))
l=len(s)-1

for i in range(2**l):
    listA=['+']*len(s)
    for j in range(l):
        if ((i>>j)&1):
            listA[j]='-'
    listB=[]
    for o,p in zip(s,listA):
        listB.append(o)
        listB.append(p)
    del listB[-1]
    listC=''.join(listB)
    ans=eval(listC)
    if ans==7:
        print('{}=7'.format(listC))
        break

Submission status: Accepted

Solution code:
n = int(input())
t=0
A=n//1000
B=(n-A*1000)//100
C=(n-A*1000-B*100)//10
D=n%10

for i in range(8):
    k=A
    if i%2==0:
        k+=B
        p="+"
    else:
        k-=B
        p="-"
    if (i//2)%2==0:
        k += C
        q="+"
    else:
        k -= C
        q="-"
    if (i//4)%2==0:
        k += D
        r="+"
    else:
        k -= D
        r="-"
    if k==7:
        a=p
        b=q
        c=r
        t=1
if t>0:
    x=str(A)+a+str(B)+b+str(C)+c+str(D)+"=7"
    print(x)

Submission status: Accepted

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

for op1 in ["+", "-"]:
    for op2 in ["+", "-"]:
        for op3 in ["+", "-"]:
            total = a
            if op1 == "+":
                total += b
            else:
                total -= b
            if op2 == "+":
                total += c
            else:
                total -= c
            if op3 == "+":
                total += d
            else:
                total -= d
            if total == 7:
                print(a, op1, b, op2, c, op3, d, "=7", sep="")
                quit()

Submission status: Accepted

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


for i in range(2):
    for j in range(2):
        for k in range(2):
            ans = a
            if i==0:
                ans += b
                X="+"
            else:
                ans -= b
                X="-"
            if j==0:
                ans += c
                Y="+"
            else:
                ans -= c
                Y="-"
            if k==0:
                ans += d
                Z="+"
            else:
                ans -= d
                Z="-"
            if ans==7:
                print(str(a)+X+str(b)+Y+str(c)+Z+str(d)+"=7")
                exit()

Submission status: Accepted

Solution code:
import sys
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")
    sys.exit
elif (a+b+c-d == 7):
    print(str(a) + "+" + str(b) + "+" + str(c) + "-" + str(d) + "=" + "7")
    sys.exit    
elif (a+b-c+d == 7):
    print(str(a) + "+" + str(b) + "-" + str(c) + "+" + str(d) + "=" + "7")
    sys.exit  
elif (a+b-c-d == 7):
    print(str(a) + "+" + str(b) + "-" + str(c) + "-" + str(d) + "=" + "7")
    sys.exit      
elif (a-b+c+d == 7):
    print(str(a) + "-" + str(b) + "+" + str(c) + "+" + str(d) + "=" + "7")
    sys.exit  
elif (a-b+c-d == 7):
    print(str(a) + "-" + str(b) + "+" + str(c) + "-" + str(d) + "=" + "7")
    sys.exit  
elif (a-b-c+d == 7):
    print(str(a) + "-" + str(b) + "-" + str(c) + "+" + str(d) + "=" + "7")
    sys.exit  
elif (a-b-c-d == 7):
    print(str(a) + "-" + str(b) + "-" + str(c) + "-" + str(d) + "=" + "7")
    sys.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 + "+" + abcd[i + 1], sum + int(abcd[i + 1]))
        dfs(i + 1, f + "-" + abcd[i + 1], sum - int(abcd[i + 1]))
abcd = input()
dfs(0, abcd[0], int(abcd[0]))

Submission status: Accepted

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


def f(ans, i, shift, operand):
    if int(bin(i >> shift)[-1]):
        ans += operand
        ops.append('+')
    else:
        ans -= operand
        ops.append('-')
    return ans, ops


for i in range(8):
    ops = []
    ans = a
    ans, ops = f(ans, i, 2, b)
    ans, ops = f(ans, i, 1, c)
    ans, ops = f(ans, i, 0, d)
    if ans == 7:
        print(a, ops[0], b, ops[1], c, ops[2], d, '=7', sep='')
        break

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

import itertools

A, B, C, D = list(read().rstrip().decode('utf-8'))

for operators in itertools.product(['+', '-'], repeat=3):
    op1, op2, op3 = operators
    eq = A + op1 + B + op2 + C + op3 + D
    x = eval(eq)
    if x == 7:
        break

answer = eq + "=7"
print(answer)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

A, B, C, D = list(read().rstrip().decode('utf-8'))

def F(op, v1, v2):
    if op == "1":
        return v1 + v2
    else:
        return v1 - v2

for operators in [list(format(i, "03b")) for i in range(2**3)]:
    op1, op2, op3 = operators
    op1 = "+" if op1 == "1" else "-"
    op2 = "+" if op2 == "1" else "-"
    op3 = "+" if op3 == "1" else "-"

    eq = A + op1 + B + op2 + C + op3 + D
    x = eval(eq)
    if x == 7:
        break

answer = eq + "=7"
print(answer)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

A, B, C, D = map(int, list(read().rstrip().decode('utf-8')))

def F(op, v1, v2):
    if op == "1":
        return v1 + v2
    else:
        return v1 - v2

for operators in [list(format(i, "03b")) for i in range(2**3)]:
    op1, op2, op3 = operators
    tmp = F(op1, A, B)
    tmp = F(op2, tmp, C)
    tmp = F(op3, tmp, D)

    if tmp == 7:
        op1 = "+" if op1 == "1" else "-"
        op2 = "+" if op2 == "1" else "-"
        op3 = "+" if op3 == "1" else "-"
        answer = str(A) + op1 + str(B) + op2 + str(C) + op3 + str(D) + "=7"
        print(answer)
        quit()

Submission status: Accepted

Solution code:
abcd = list(map(int,list(input())))
bins = []

for i in range(2**3):
    bins.append(list(str(format(i,'b').zfill(3))))

for i in range(8):
    res=abcd[0]
    ans = str(abcd[0])
    for j in range(3):
        if bins[i][j] == '0':
            res += (abcd[j+1])
            ans += '+'
            ans += str(abcd[j+1])
        
        else:
            res -= (abcd[j+1])
            ans += '-'
            ans += str(abcd[j+1])
    
    if res == 7:
        print(ans+'=7')
        break

Submission status: Accepted

Solution code:
# インプットをリストで用意
abcd = list(map(int, list(input())))

s = ''
# 全体で2*2*2通りある
for i in range(8):
    s = str(abcd[0])    #文字でのストック
    tmp = abcd[0]       #合計値のストック
    for j in range(3):
        # １を左にｊビットずらして、iと論理積を取る
        # つまり、iの左からj番目のビットが0かを調べてる
        if (1 << j) & i == 0:
            s += '+'
            tmp += abcd[j + 1]
        else:
            s += '-'
            tmp -= abcd[j + 1]
        s += str(abcd[j + 1])
    s += '=7'
    if tmp == 7:
        break
print(s)

Submission status: Accepted

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

bins = []

for i in range(2**3):
    bins.append(list(str(format(i,'b').zfill(3))))


for i in range(8):
    res = a
    
    for j in range(3):
        if j == 0 and bins[i][j] == '0':
            res += b
        
        if j == 0 and bins[i][j] == '1':
            res -= b
        
        if j == 1 and bins[i][j] == '0':
            res += c
        
        if j == 1 and bins[i][j] == '1':
            res -= c
        
        if j == 2 and bins[i][j] == '0':
            res += d
        
        if j == 2 and bins[i][j] == '1':
            res -= d
    
    if res == 7:
        ans = str(a)
        for k in range(3):
            if bins[i][k] == '0':
                ans += '+'
            
            else:
                ans += '-'
            
            ans += str([a,b,c,d][k+1])

print(ans+'=7')

Submission status: Accepted

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

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

# def solve(m,n):
#     if eval(m)==7:
#         print(m+"=7")
#         exit(0)
#     elif n<7:
#         solve(m,n+2)
#         solve(m[:n]+"-"+m[n+1:],n+2)

# solve(a+"+"+b+"+"+c+"+"+d,1)

Submission status: Accepted

Solution code:
#数字同士のすき間の個数分、二択（+ or −）が存在し、それらを全探索したい
n = input()
op_cnt = len(n) - 1 #隙間の個数
for i in range(2**op_cnt):
    op = ["-"]*op_cnt #あらかじめ["-","-","-"] というリストを作っておく
    for j in range(op_cnt):
        if((i>>j)&1):
            op[op_cnt -1 -j] = "+" 
    #print(op)
    formula = ""
    for p_n,p_o in zip(n, op+[""]):
        formula += (p_n + p_o)
    if eval(formula) == 7:
        print(formula + "=7")
        break

Submission status: Accepted

Solution code:
S = list(map(int, list(input())))
for pattern in range(1 << 3):
    this_sum = S[0]
    for i in [1, 2, 3]:
        if pattern & 1 << i-1:
            this_sum += S[i]
        else:
            this_sum -= S[i]
    if this_sum == 7:
        break
output = str(S[0]) + "".join(["-+"[bool(pattern & 1 << i-1)] + str(S[i]) for i in [1, 2, 3]]) + "=7"
print(output)

Submission status: Accepted

Solution code:
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    *S, = iss()
    E = ['+', '-']
    tmp = [0] * 7
    for e in E:
        tmp[0] = S[0]
        tmp[1] = e
        for e in E:
            tmp[2] = S[1]
            tmp[3] = e
            for e in E:
                tmp[4] = S[2]
                tmp[5] = e
                tmp[6] = S[3]
                ans = ''.join(map(str, tmp))
                if eval(ans) == 7:
                    print(ans + '=7')
                    exit()


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()

for a in '+-':
  for b in '+-':
    for c in '+-':
      ans = S[0] + a + S[1] + b + S[2] + c + S[3]
      if eval(ans) == 7:
        print(ans + '=7')
        exit()

Submission status: Accepted

Solution code:
s = input()
n = len(s)
a = [i for i in s]
for i in range(2**(n-1)):
  b = []
  for j in range(n):
    b.append(a[j])
    if j > 2:
      break
    if (i >> j) & 1:
      b.append("+")
    else:
      b.append("-")
  if eval("".join(b)) == 7:
    b.append("=7")
    print("".join(b))
    exit()

Submission status: Accepted

Solution code:
S = input()
n = len(S)
# create ptn
ptn = []
for bit in range(2**(n-1)):
    p = []
    for i in range(n-1):
        if ((bit>>i)&1):
            p.append('+')
        else:
            p.append('-')
    ptn.append(p)
# calc
for p in ptn:
    for i, s in enumerate(S):
        if i == 0:
            result = int(s)
            continue
        if p[i-1]=='+':
            result += int(s)
        else:
            result -= int(s)
    if result == 7:
        print('{}{}{}{}{}{}{}=7'.format(S[0],p[0],S[1],p[1],S[2],p[2],S[3]))
        break

Submission status: Accepted

Solution code:
a = list(input())
a,b,c,d = int(a[0]), int(a[1]), int(a[2]), int(a[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:
def pm(S,a,i):
	if i == 0:
		S += a
	else:
		S -= a

	return S

def ch(i):
	if i == 0:
		return '+'
	else:
		return '-'


if __name__ == '__main__':
	S = input()
	A = int(S[0])
	B = int(S[1])
	C = int(S[2])
	D = int(S[3])

	ans = ''

	for a in range(2):
		for b in range(2):
			for c in range(2):	
				goukei = A
				goukei = pm(goukei,B,a)
				goukei = pm(goukei,C,b)
				goukei = pm(goukei,D,c)

				if goukei == 7:

					ans = S[0] + ch(a) + S[1] + ch(b) + S[2] + ch(c) + S[3] + '=7'
					break
					break
					break

	print(ans)

Submission status: Accepted

Solution code:
import sys

n = input()

code_1 = ['+', '-']
code_2 = ['+', '-']
code_3 = ['+', '-']

answer = ''
flag = False
for i in range(2):
    for j in range(2):
        for k in range(2):
            sum_num = 0
            if code_1[i] == '+':
                sum_num += int(n[0]) + int(n[1])
            else:
                sum_num += int(n[0]) - int(n[1])
            if code_2[j] == '+':
                sum_num += int(n[2])
            else:
                sum_num -= int(n[2])
            if code_3[k] == '+':
                sum_num += int(n[3])
            else:
                sum_num -= int(n[3])
            if sum_num == 7:
                answer = n[0] + code_1[i] + n[1] + code_2[j] + n[2] + code_3[k] + n[3] + '=7'
                flag = True
            if flag:
                break

        if flag:
            break
    
    if flag:
        break


print(answer)

Submission status: Accepted

Solution code:
N = input()
a = []
n = len(N)
k = 7

for i in range(len(N)):
    a.append(int(N[i]))

X = [0]*(n-1)
flag = False

for i in range(2**(n-1)):
    if flag:
        break
    S = a[0]
    for j in range(n-1):
        if (i >> j) & 1 == 1:
            X[j] = 1
            S += a[j+1]
        else:
            X[j] = 0
            S -= a[j+1]
    if S == k:
        flag = True
        break
print(a[0], end="")
for i in range(3):
    if X[i] == 1:
        print('+', end='')
    else:
        print('-', end='')
    print(a[i+1], end="")
print('=', end='')
print(k)

Submission status: Accepted

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

for i in range(1 << n):
    aa = ["-"] * n
    for j in range(n):
        if (i >> j) % 2 == 1:
            aa[n - 1 -j] = "+"
    sum = 0
    for index, x in enumerate(list):
        if index == 0:
            sum = int(x)
        else:
            if aa[index-1] == "+":
                sum = sum + int(x)
            elif aa[index-1] == "-":
                sum = sum - int(x)

    if sum == 7:
        print("{0}{1}{2}{3}{4}{5}{6}=7".format(list[0], aa[0], list[1],
                                               aa[1], list[2], aa[2],
                                               list[3]))
        exit()

Submission status: Accepted

Solution code:
S = input()
 
n = len(S)
S_list = [int(S[0]), int(S[1]), int(S[2]), int(S[3])]
 
#1... -  0...+
def bit_to_notation(bit):
  bitlist = [0 for i in range(n-1)] 
  for i in range(n-1):
    if ((bit >> i) & 1):
      bitlist[n-2-i] = "+"
    else:
      bitlist[n-2-i] = "-"
  return bitlist
 
notation = 2 ** (n-1)
for bit in range(notation):
  sum4 = S_list[0]
  for j in range(n-1):
    if((bit >> j) & 1):
      sum4 += S_list[n-1-j]
    else:
      sum4 -= S_list[n-1-j]
      
  if(sum4 == 7):
    
    bitlist = bit_to_notation(bit)
    print(str(S_list[0]) + bitlist[0] + str(S_list[1]) + bitlist[1] 
          + str(S_list[2]) + bitlist[2] + str(S_list[3]) + "=7")
    break