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:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


s = S()

L = [s[1], s[2], s[3] + '==7']
for i in range(8):
    ret = s[0]
    for j in range(3):
        if i & (1 << j):
            ret += '+'
        else:
            ret += '-'
        ret += L[j]
    if eval(ret):
        print(ret.replace('==', '='))
        break

Submission status: Accepted

Solution code:
import itertools

N = list(input().strip())

for p in itertools.product(['+','-'], repeat=3):
  s = N[0]+p[0]+N[1]+p[1]+N[2]+p[2]+N[3]
  if eval(s) == 7:
    print(s+'=7')
    exit()

Submission status: Accepted

Solution code:
import sys


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


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

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

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


def main():
    s = input()

    bitall(s)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys


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


def main():
    s = input()
    n = len(s) - 1

    for bit in range(1 << n):
        f = s[0]

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=list(input())
hs=[0]*4
for i in range(4):
    s[i]=int(s[i])
    hs[i]=s[i]

op=[[0],[1]]

for i in range(3):
    tmp=[]
    for j in op:
        tmp.append(j+[0])
        tmp.append(j+[1])
    op=tmp

for i in op:
    s=hs
    for j in range(3):
        if i[j]==0:
            s[j+1]=-s[j+1]
    if sum(s)==7:
        break

ans=str(s[0])
for i in range(3):
    if s[i+1]<0:
        ans+="-"
    else:
        ans+="+"
    ans+=str(abs(s[i+1]))
print(ans+"=7")

Submission status: Accepted

Solution code:
S = input()


for i in range(2**3):
    formula = ""

    for j in range(3):
        formula += S[j]
        if (i >> j) & 1:
            formula += "+"
        else:
            formula += "-"
    formula += S[-1]

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

Submission status: Accepted

Solution code:
num=int(input())

a=num//1000
b=(num-a*1000)//100
c=(num-a*1000-b*100)//10
d=(num-a*1000-b*100-c*10)

op=["+","-"]
flg = 0


for i in range(2):
    if flg == 1:break
    for j in range(2):
        if flg == 1:break
        for k in range(2):
            if flg == 1:break
            out = str(a)+op[i]+str(b)+op[j]+str(c)+op[k]+str(d)
            if eval(out) == 7:
                out += "=7"
                flg = 1

print(out)

Submission status: Accepted

Solution code:
ABCD = input()
f = ""
for i in range(2 ** (len(ABCD) - 1)):
    f = ""
    for j in range(len(ABCD)):
        f += ABCD[j]
        if j != len(ABCD)-1:
            if (i >> (len(ABCD)-1-1-j)) & 1:
                f += "+"
            else:
                f += "-"
    if eval(f) == 7:
        print(f + "=7")
        exit()

Submission status: Accepted

Solution code:
x = input()
#print(x)
y = [int(c) for c in x]
#print(y)
a = y[0]
b = y[1]
c = y[2]
d = y[3]
if a+b+c+d == 7:
  print(a,"+",b,"+",c,"+",d,"=",a+b+c+d, sep='')
  exit()
if a+b+c-d == 7:
  print(a,"+",b,"+",c,"-",d,"=",a+b+c-d, sep='')
  exit()
if a+b-c+d == 7:
  print(a,"+",b,"-",c,"+",d,"=",a+b-c+d, sep='')
  exit()
if a-b+c+d == 7:
  print(a,"-",b,"+",c,"+",d,"=",a-b+c+d, sep='')
  exit()
if a-b-c+d == 7:
  print(a,"-",b,"-",c,"+",d,"=",a-b-c+d, sep='')
  exit()
if a-b+c-d == 7:
  print(a,"-",b,"+",c,"-",d,"=",a-b+c-d, sep='')
  exit()
if a-b-c-d == 7:
  print(a,"-",b,"-",c,"-",d,"=",a-b-c-d, sep='')
  exit()
if a+b-c-d == 7:
  print(a,"+",b,"-",c,"-",d,"=",a+b-c-d, sep='')
  exit()

Submission status: Accepted

Solution code:
s=input()
op=["+","-"]
for i in range(2):
    for j in range(2):
        for k in range(2):
            formula=s[0]+op[i]+s[1]+op[j]+s[2]+op[k]+s[3]
            if eval(formula)==7:
                print(formula+"=7")
                exit(0)

Submission status: Accepted

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

def f(a,b,op):
	if op:return a+b
	else:return a-b

t=False
for i in range(2):
	for j in range(2):
		for k in range(2):
			if f(f(f(a,b,i),c,j),d,k) == 7:
				t=True
				break
		if t:break
	if t:break

dic={0:'-', 1:'+'}
for u,v in zip([a,b,c],[i,j,k]):
	print(u,dic[v],sep='',end='')
print(d,'=7',sep='')

Submission status: Accepted

Solution code:
A,B,C,D=input()
a = int(A)
b = int(B)
c = int(C)
d = 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")
else:
         print(A+"-"+B +"-"+C +"-"+D+"=7")

Submission status: Accepted

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

def dfs(i, f, total):
    if i == 3:
        if total == 7:
            global ans
            ans.append(f + '=7')

    else:
        dfs(i+1, f + '-' + s[i+1], total - int(s[i+1]))
        dfs(i+1, f + '+' + s[i+1], total + int(s[i+1]))
        
dfs(0, s[0], int(s[0]))
print(ans[0])

Submission status: Accepted

Solution code:
"""
<<全探索問題//ABC079C>>
1. itertools,evalsを用いた方法
2. bit全探索を用いた方法
"""

#1. itertoolsを用いた方法
"""
import itertools
s=input()
A,B,C,D=s
for i in itertools.product(['+','-'],repeat=len(s)-1):
    formula=''
    formula=A+i[0]+B+i[1]+C+i[2]+D
    if eval(formula)==7:
        print(formula+'=7')
        break
"""

#2. bit全探索を用いた方法
s=input()
N=len(s)-1
for i in range(2**N):
    list=['+']*N
    formula=''
    for j in range(N):
        if ((i>>j)&1):
            list[N-1-j]='-'
    for num,operator in zip(s,list+['']):
        formula+=(num+operator)
    if eval(formula)==7:
        print(formula+'=7')
        break

Submission status: Accepted

Solution code:
"""
<<全探索問題//ABC079C>>

1. itertoolsを用いた方法
2. bit全探索を用いた方法
"""

#1. itertoolsを用いた方法
import itertools
A,B,C,D=input()
for i in itertools.product(['+','-'],repeat=3):
    formula=''
    formula=A+i[0]+B+i[1]+C+i[2]+D
    if eval(formula)==7:
        print(formula+'=7')
        break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
s = input()
abcd = [c for c in s]

OP = ["+", "-"]

for op1 in OP:
    for op2 in OP:
        for op3 in OP:
            fomula_tmp = abcd[0] + op1 + abcd[1] + op2 + abcd[2] + op3 + abcd[3]
            if eval(fomula_tmp) == 7:
                print(fomula_tmp + "=7")
                exit()

Submission status: Accepted

Solution code:
S = input()
S = [S[0],None,S[1],None,S[2],None,S[3]]

for i in range(2**3):
  tmp = S
  for j in range(3):
    if ((i >> j) & 1):
      tmp[j*2+1] = "+"
    else:
      tmp[j*2+1] = "-"
  if eval("".join(tmp)) == 7:
    print("".join(tmp),end = "")
    print("=7")
    break

Submission status: Accepted

Solution code:
S=input()
h=[1,-1]
e=[0,1]
f=["+","-"]
x=""
a=0
for i in e:
  for j in e:
    for k in e:
      a=int(S[0])+int(S[1])*h[i]+int(S[2])*h[j]+int(S[3])*h[k]
      if a==7:
        x=S[0]+f[i]+S[1]+f[j]+S[2]+f[k]+S[3]+"=7"
print(x)

Submission status: Accepted

Solution code:
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] = "+"  

    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:
a, b, c, d = list(input())

import itertools

for ops in itertools.product(["+", "-"], repeat=3):
    eq = a + ops[0] + b + ops[1] + c + ops[2] + d
    sol = eval(eq)
    if sol == 7:
        break

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

Submission status: Accepted

Solution code:
abcd = input()

import itertools

for op in itertools.product(["+", "-"], repeat=3):
    sm = int(abcd[0])
    for i in range(3):
        if op[i] == "+":
            sm += int(abcd[i+1])
        else:
            sm -= int(abcd[i+1])
    if sm == 7:
        break

ans = str(abcd[0])
for i in range(3):
    ans += op[i] + abcd[i+1]
ans += "=7"
print(ans)

Submission status: Accepted

Solution code:
n = input()
a=[]
for  i in range(4):
  a.append(int(n[i]))
out=[]
pi=[]
for i in range(2):
  for j in range(2):
    for k in range(2):
      
      if a[0]+(i*2-1)*a[1]+(j*2-1)*a[2]+(k*2-1)*a[3] ==7:

        if i*2-1 ==1:
          pi.append('+')
        else:
          pi.append('-')
        if j*2-1 ==1:
          pi.append('+')
        else:
          pi.append('-')
        if k*2-1 ==1:
          pi.append('+')
        else:
          pi.append('-')
              
        for h in range(3):
          print(a[h],end="")
          print(pi[h],end="")
        print(a[3],end="")
        print('=7')
        exit()  
      else:
        f=0

Submission status: Accepted

Solution code:
from itertools import*
A,B,C,D=input()
for i,j,k in product(["+","-"],repeat=3):
 s=A+i+B+j+C+k+D
 if eval(s)==7:print(s+"=7");break

Submission status: Accepted

Solution code:
ABCD = input()

def dfs(i, expression, res):
    if i == 4:
        if res == 7:
            return expression
        else:
            return []
    else:
        ans = dfs(i + 1, expression + '+' + ABCD[i], res + int(ABCD[i])) or dfs(i + 1, expression + '-' + ABCD[i], res - int(ABCD[i]))
    return ans

ans = dfs(1, ABCD[0], int(ABCD[0]))
print(ans + '=7')

Submission status: Accepted

Solution code:
# C - Train Ticket 桁ごとにリスト格納
A = str(input())
l = [int(x) for x in list(str(A))]
if l[0]+l[1]+l[2]+l[3] == 7 :
    print('{0}+{1}+{2}+{3}=7'.format(l[0],l[1],l[2],l[3]))
elif l[0]-l[1]+l[2]+l[3] == 7 :
    print('{0}-{1}+{2}+{3}=7'.format(l[0], l[1], l[2], l[3]))
elif l[0]+l[1]-l[2]+l[3] == 7 :
    print('{0}+{1}-{2}+{3}=7'.format(l[0], l[1], l[2], l[3]))
elif l[0]+l[1]+l[2]-l[3] == 7:
    print('{0}+{1}+{2}-{3}=7'.format(l[0], l[1], l[2], l[3]))
elif l[0]-l[1]-l[2]+l[3] == 7:
    print('{0}-{1}-{2}+{3}=7'.format(l[0], l[1], l[2], l[3]))
elif l[0]+l[1]-l[2]-l[3] == 7:
    print('{0}+{1}-{2}-{3}=7'.format(l[0], l[1], l[2], l[3]))
elif l[0]-l[1]+l[2]-l[3] == 7:
    print('{0}-{1}+{2}-{3}=7'.format(l[0], l[1], l[2], l[3]))
elif l[0]-l[1]-l[2]-l[3] == 7:
    print('{0}-{1}-{2}-{3}=7'.format(l[0], l[1], l[2], l[3]))

Submission status: Accepted

Solution code:
l=input()
a,b,c,d=[int(l[i]) for i in range(4)]
plmi=[1,-1]
x=[None,'+','-']
for i in plmi:
	for j in plmi:
		for k in plmi:
			if a+b*i+c*j+d*k==7:
				print(str(a)+x[i]+str(b)+x[j]+str(c)+x[k]+str(d)+'=7')
				exit()

Submission status: Accepted

Solution code:
abcd=[int(i) for i in input()]
a=abcd[0]
b=abcd[1]
c=abcd[2]
d=abcd[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))
else:
  pass

Submission status: Accepted

Solution code:
n=input()
l=[1,-1]
l1=[0,"+","-"]
s=""
for i in l:
  for j in l:
    for k in l:
      if int(n[0])+i*int(n[1])+j*int(n[2])+k*int(n[3])==7:
        s=n[0]+l1[i]+n[1]+l1[j]+n[2]+l1[k]+n[3]+"=7"
print(s)

Submission status: Accepted

Solution code:
A, B, C, D = list(map(int, input()))
for i in range(8):
  if i & 1 == 0:
    tb = B
  else:
    tb = -B
  if i & 2 == 0:
    tc = C
  else:
    tc = -C
  if i & 4 == 0:
    td = D
  else:
    td = -D
  if sum([A, tb, tc, td]) == 7:
    break
print("%d%+d%+d%+d=7" % (A, tb, tc, td))

Submission status: Accepted

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

op = [[1, -1],[1, -1],[1, -1]]
dic = {0:"+",1:"-"}

for i in range(2):
  for j in range(2):
    for k in range(2):
      ans = a + op[0][i] * b + op[1][j] * c + op[2][k] *d
      if ans == 7:
        fml = str(a) + dic[i] + str(b) + dic[j] + str(c) + dic[k] + str(d) +"=7"
        print(fml)
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
s = list(input())
for op in itertools.product(range(2), repeat=3):
    ans = int(s[0])
    for i in range(3):
        if op[i] == 1:
            ans += int(s[i+1])
        else:
            ans -= int(s[i+1])
    if ans == 7:
        break

for i,j in zip(s,op):
    if j == 1:
        j = '+'
    else:
        j = '-'
    print(str(i)+j,end='')
print(s[-1]+'=7')

Submission status: Accepted

Solution code:
a,b,c,d=map(int,input())
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 func(ABCD, n, acc, output):
    if n == 0:
        if int(ABCD) + acc == 7:
            print(ABCD + output + '=7')
            exit()
    else:
        func(ABCD[:-1], n-1, acc + int(ABCD[-1]), '+' + ABCD[-1] + output)
        func(ABCD[:-1], n-1, acc - int(ABCD[-1]), '-' + ABCD[-1] + output)
S = input()
func(S, len(S)-1, 0, '')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=list(input())
n=len(s)
insert=0
ans=0
for i in range(2**(3)):
    f=(s[0])
    for j in range(3):
        if i&(1<<j):
            f=f+"+"
        else:
            f=f+"-"
        f=f+s[j+1]
      
   
    if eval(f)==7:
        print(f+"=7")
        exit()

Submission status: Accepted

Solution code:
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
import numpy as np

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    S = list(input().rstrip())
    N = len(S)

    for bit in range(1<<N-1):
        total = int(S[0])
        res = S[0]
        for i in range(N-1):
            if bit & 1<<i:
                total += int(S[i+1])
                res += '+'
                res += S[i+1]
            else:
                total -= int(S[i+1])
                res += '-'
                res += S[i+1]
        if total == 7:
            res += '=7'
            print(res)
            return 0


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(7):  
  if i==0 and a+b+c+d==7:
    print('%d+%d+%d+%d=7' %(a,b,c,d))
    exit()
  elif i==1 and a+b+c-d==7:
    print('%d+%d+%d-%d=7' %(a,b,c,d))
    exit()
  elif i==2 and a+b-c+d==7:
    print('%d+%d-%d+%d=7' %(a,b,c,d))
    exit()
  elif i==3 and a+b-c-d==7:
    print('%d+%d-%d-%d=7' %(a,b,c,d))
    exit()
  elif i==4 and a-b+c+d==7:
    print('%d-%d+%d+%d=7' %(a,b,c,d))
    exit()
  elif i==5 and a-b+c-d==7:
    print('%d-%d+%d-%d=7' %(a,b,c,d))
    exit()
  elif i==6 and a-b-c+d==7:
    print('%d-%d-%d+%d=7' %(a,b,c,d))
    exit()
  elif i==7 and a-b-c-d==7:
    print('%d-%d-%d-%d=7' %(a,b,c,d))
    exit()

Submission status: Accepted

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

for i in range(8) :
    ret = ABCD[0]
    for j in range(3) :
        if (i >> j) & 1 :
            ret += ABCD[j+1]
        else :
            ret -= ABCD[j+1]
    
    if ret == 7 :
        op1 = '+' if (i >> 0) & 1 else '-'
        op2 = '+' if (i >> 1) & 1 else '-'
        op3 = '+' if (i >> 2) & 1 else '-'
        print('{}{}{}{}{}{}{}=7'.format(ABCD[0], op1, ABCD[1], op2, ABCD[2], op3, ABCD[3]))
        break

Submission status: Accepted

Solution code:
def dfs(i, now,  count):
    if count == len(s):
        if i == 7:
            print(str(s[0]),end="")
            for j in range(len(s)-1):
                print(now[j+1] + str(s[j+1]), end="")
            print('=7')
            exit()
    else:
        dfs(i + s[count], now + '+', count + 1)
        dfs(i - s[count], now + '-', count + 1)


s = list(map(int, input().strip()))

dfs(0, '', 0)

Submission status: Accepted

Solution code:
def resolve():
    import copy
    s = list(input())
    t = list(map(int, s))
    for i in range(8):
        tmp = copy.deepcopy(s)
        d = 0
        ans = t[0]
        for j in range(3):
            if (i // 2**j)%2 == 1:
                tmp.insert(j+d+1, '+')
                ans += t[j+1]
            else:
                tmp.insert(j+d+1, '-')
                ans -= t[j+1]
            d += 1
        if ans == 7:
            print(''.join(tmp)+'=7')
            return
resolve()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu Sep  5 15:21:54 2019

@author: Owner
"""

S = input()

A = [int(S[0]), int(S[1]), int(S[2]), int(S[3])]

flg = [True, True, True]

def dfs(n, flg, goal):
    if goal == True:
        return True
    
    if n == 3:
        ops = ["+", "+", "+"]
        tot = A[0]
        for i in range(len(flg)):
            if flg[i]:
                tot += A[i+1]
            else:
                tot -= A[i+1]
                ops[i] = "-" 
        #print("Layer: "+str(n)+", Flags: "+str(flg)+", Total: "+str(tot))
                
        if tot == 7:
            print(str(A[0])+ops[0]+str(A[1])+ops[1]+str(A[2])+ops[2]+str(A[3])+"=7")
            return True
        else:
            return False
    #print("Layer: "+str(n)+", Flags: ", flg)
    flg1 = flg.copy()
    flg1[n] = True
    flg2 = flg.copy()
    flg2[n] = False
    
    goal = dfs(n+1, flg1, goal) or dfs(n+1, flg2, goal)
    
    return goal
    
dfs(0, flg, False)

Submission status: Accepted

Solution code:
#総当たり
def calc(a, b, plus_minus):
  if plus_minus == 0:
    return a + b
  elif plus_minus == 1:
    return a - b

import itertools as it
list_prm = it.product([0, 1], repeat=3)
list_prm = list(list_prm)

list_abcd = [int(num) for num in input()]

def calc4(list_abcd, list_pm):
  ans = calc(list_abcd[0], list_abcd[1], list_pm[0])
  ans = calc(ans, list_abcd[2], list_pm[1])
  ans = calc(ans, list_abcd[3], list_pm[2])
  return ans

def serch_7(list_abcd, list_prm):
  for list_pm in list_prm:
    if calc4(list_abcd, list_pm) == 7:
      return list_pm

    
def convert(num):
  if num == 0:
    return "+"
  else:
    return "-"

sol = serch_7(list_abcd, list_prm)

s = str(list_abcd[0])
s += convert(sol[0])
s += str(list_abcd[1])
s += convert(sol[1])
s += str(list_abcd[2])
s += convert(sol[2])
s += str(list_abcd[3])
s += "=7"

print(s)

Submission status: Accepted

Solution code:
def main():
    abcd = list(input())
    flag = False
    for op1 in ['+', '-']:
        for op2 in ['+', '-']:
            for op3 in ['+', '-']:
                ans = abcd[0]+op1+abcd[1]+op2+abcd[2]+op3+abcd[3]
                if eval(ans) == 7:
                    flag = True
                    print(ans+'=7')
                    break
            if flag:
                break
        if flag:
            break

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=input()
for i in '+-':
  for j in '+-':
    for k in '+-':
      a=n[0]+i+n[1]+j+n[2]+k+n[3]
      if eval(a)==7:
        print(a+'=7')
        exit()

Submission status: Accepted

Solution code:
lis = list(input())

n = len(lis) - 1
for i in range(2**n):
    a = ["-", "-", "-"]
    for j in range(n):
        if (i >> j & 1):
            a[j] = "+"
    ans = "".join(["{}{}".format(k, kk) for (k, kk) in zip(lis, a+[''])])
    if (eval(ans)) == 7:
        print(ans + "=7")
        break

Submission status: Accepted

Solution code:
n=input()

n1=int(n[0])
n2=int(n[1])
n3=int(n[2])
n4=int(n[3])

if n1+n2+n3+n4==7:
    print ("{}+{}+{}+{}=7".format(n1,n2,n3,n4))
    exit()
elif n1+n2+n3-n4==7:
    print ("{}+{}+{}-{}=7".format(n1,n2,n3,n4))
    exit()
elif n1+n2-n3+n4==7:
    print ("{}+{}-{}+{}=7".format(n1,n2,n3,n4))
    exit()    
elif n1+n2-n3-n4==7:
    print ("{}+{}-{}-{}=7".format(n1,n2,n3,n4))
    exit() 
elif n1-n2-n3-n4==7:
    print ("{}-{}-{}-{}=7".format(n1,n2,n3,n4))
    exit()
elif n1-n2-n3+n4==7:
    print ("{}-{}-{}+{}=7".format(n1,n2,n3,n4))
    exit()
elif n1-n2+n3-n4==7:
    print ("{}-{}+{}-{}=7".format(n1,n2,n3,n4))
    exit()
elif n1-n2+n3+n4==7:
    print ("{}-{}+{}+{}=7".format(n1,n2,n3,n4))
    exit()

Submission status: Accepted

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


def dfs(list, ops, index, sum):
    if len(list) <= index:
        if sum == 7:
            return "{}{}{}{}{}{}{}=7".format(list[0], ops[0], list[1], ops[1], list[2], ops[2], list[3])
        else:
            return None
    candidate = dfs(list, ops + ['+'], index + 1, sum + list[index])
    if candidate:
        return candidate
    candidate = dfs(list, ops + ['-'], index + 1, sum - list[index])
    if candidate:
        return candidate
    return None


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

Submission status: Accepted

Solution code:
a, b, c, d = map(int, input())
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:
# ABC 

s = input()

for bit in range(1<<(len(s)-1)):
    sum_ = int(s[0])
    ops_str = []
    for i in range(len(s)-1):
        if (bit & (1<<i)):
            sum_ += int(s[i+1])
            ops_str.append("+")
        else:
            sum_ -= int(s[i+1])
            ops_str.append("-")
    if sum_ == 7:
        ans_str = s[0]
        for k in range(len(ops_str)):
            ans_str += (ops_str[k] + s[k+1])
        print(ans_str+"=7")
        break

Submission status: Accepted

Solution code:
Input = list(input())
for i in range(4):
    Input[i] = int(Input[i])
Kouho = [[0,0,0],[0,0,1],[0,1,0],[0,1,1],[1,0,0],[1,0,1],[1,1,0],[1,1,1]]
flag = 0
for i in range(8):
    tmp = Input[0]
    if Kouho[i][0] == 0:
        tmp -= Input[1]
    else:
        tmp += Input[1]
    if Kouho[i][1] == 0:
        tmp -= Input[2]
    else:
        tmp += Input[2]
    if Kouho[i][2] == 0:
        tmp -= Input[3]
    else:
        tmp += Input[3]
    if tmp == 7:
        for j in range(4):
            Input[j] = str(Input[j])
        for j in range(3):
            if Kouho[i][j] == 0:
                Kouho[i][j] = '-'
            else:
                Kouho[i][j] ='+'
        Input.insert(1,Kouho[i][0])
        Input.insert(3,Kouho[i][1])
        Input.insert(5,Kouho[i][2])
        Input.insert(7,'=7')
        ans = ''.join(Input)
        print(ans)

        break

Submission status: Accepted

Solution code:
#ABC 079 C

#頭を使わず8通り試す

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

#---=000,+--=100みたいにすればいいのでは説

puramai = []
for i in range(8):
    bs = format(i,'03b')
    for j in range(3):
#        print(bs[j])
        if bs[j] == "0":
            ans = ans - int(s[j+1])
            puramai.append("-")
        if bs[j] == "1":
            ans = ans + int(s[j+1])
            puramai.append("+")
#    print(ans)
    if ans == 7:
        print(s[0] + puramai[0] + s[1] + puramai[1] + s[2] + puramai[2] + s[3] + "=7")
        break
    else:
        ans = a
        puramai = []
else:
    print("NO")

Submission status: Accepted

Solution code:
a=input()
flag=False
for i in ["+","-"]:
    for j in ["+","-"]:
        for k in ["+","-"]:
            cnt=int(a[0])
            if i=="+":
                cnt+=int(a[1])
            else:
                cnt-=int(a[1])
            if j=="+":
                cnt+=int(a[2])
            else:
                cnt-=int(a[2])
            if k=="+":
                cnt+=int(a[3])
            else:
                cnt-=int(a[3])
            if cnt==7:
                print(a[0]+i+a[1]+j+a[2]+k+a[3]+"=7")
                flag=True
                break
        if flag==True:
            break
    if flag==True:
        break

Submission status: Accepted

Solution code:
abcd = input()

for i in range(2 ** 3):
    check = int(abcd[0])
    op_list = []
    for j in range(3):
        if i >> j & 1:
            check += int(abcd[j+1])
            op_list.append('+')
        else:
            check -= int(abcd[j+1])
            op_list.append('-')
    if check == 7:
        m = abcd[0] + op_list[0] + abcd[1] + op_list[1] + abcd[2] + op_list[2] + abcd[3] + '=7'
        print(m)
        break

Submission status: Accepted

Solution code:
import sys
S = input()
length = 4

for i in range(1 << (length - 1)):
    s = S[0]
    for j in range(length - 1):
        if i & (1 << j):
            s += "+"
        else:
            s += "-"
        s += S[j + 1]
    if eval(s) == 7:
        print(s + "=7")
        sys.exit(0)

Submission status: Accepted

Solution code:
s=input()

for bit in range(1 << 3):
    f=int(s[0])
    for i in range(0,3):
        if bit & (1 << i):
            f=f+int(s[i+1])
        else:
            f=f-int(s[i+1])
    if f==7:
        break

F=s[0]
for i in range(0,3):
    if bit & (1 << i):
        F=F+"+"+s[i+1]
    else:
        F=F+"-"+s[i+1]

print(F+"=7")

Submission status: Accepted

Solution code:
import itertools as it

s = input()
l = [i for i in s]
ans = 7
op = 3

for (a, b, c) in it.product([0,1],repeat=op):
  eq = l[0]
  w = int(l[0])
  for i,x in enumerate((a, b, c)):
    if x == 0:
      eq += "+" + l[i+1]
      w += int(l[i+1])
    else:
      eq += "-" + l[i+1]
      w -= int(l[i+1])
  if w == ans:
    print(eq+"=7")
    break

Submission status: Accepted

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

def f(i,cnt):
	if i == 3:
		if cnt == 7:
			return True
		else:
			return False

	if f(i+1, cnt+K[i+1]):
		ans.append("+")
		return True
	if f(i+1, cnt-K[i+1]):
		ans.append("-")
		return True
	
	

ans = []

f(0,K[0])

ans = ans[::-1]

for i in range(4):
	if i == 3:
		print(str(K[-1])+"=7")

	else:
		print(K[i], end="")
		print(ans[i], end="")

Submission status: Accepted

Solution code:
s = input()
if int(s[0])+int(s[1])+int(s[2])+int(s[3])==7:
    print(s[0]+'+'+s[1]+'+'+s[2]+'+'+s[3]+'=7')
elif int(s[0])+int(s[1])+int(s[2])-int(s[3])==7:
    print(s[0]+'+'+s[1]+'+'+s[2]+'-'+s[3]+'=7')
elif int(s[0])+int(s[1])-int(s[2])+int(s[3])==7:
    print(s[0]+'+'+s[1]+'-'+s[2]+'+'+s[3]+'=7')
elif int(s[0])+int(s[1])-int(s[2])-int(s[3])==7:
    print(s[0]+'+'+s[1]+'-'+s[2]+'-'+s[3]+'=7')
elif int(s[0])-int(s[1])+int(s[2])+int(s[3])==7:
    print(s[0]+'-'+s[1]+'+'+s[2]+'+'+s[3]+'=7')
elif int(s[0])-int(s[1])+int(s[2])-int(s[3])==7:
    print(s[0]+'-'+s[1]+'+'+s[2]+'-'+s[3]+'=7')
elif int(s[0])-int(s[1])-int(s[2])+int(s[3])==7:
    print(s[0]+'-'+s[1]+'-'+s[2]+'+'+s[3]+'=7')
elif int(s[0])-int(s[1])-int(s[2])-int(s[3])==7:
    print(s[0]+'-'+s[1]+'-'+s[2]+'-'+s[3]+'=7')

Submission status: Accepted

Solution code:
s = str(input())

for l in range(2 ** (len(s)-1)):
    s3 = list(s)
    h = 0
    for i in range(len(s)-1):
        if (l >> i) & 1:
            s3.insert(i+h+1,'+')
            h += 1
        else:
            s3.insert(i+h+1,'-')
            h += 1
    e = ''.join(s3)
    if eval(e) == 7:
        print(str(e)+'=7')
        break

Submission status: Accepted

Solution code:
l=tuple(input())
for i in range(8):
    c=1
    s=list(l)
    for j in range(3):
        s.insert(j+c,"+-"[(i>>j)&1::2])
        c+=1
    a="".join(s)
    if eval(a)==7:
        print(a+"=7")
        exit()

Submission status: Accepted

Solution code:
a, b, c, d = map(int, list(input()))
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="")
else: print(a,"-", b, "-", c, "-", d, "=7", sep="")