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

Solution (Python):
I = input()
A = I[0:1]
B = I[1:2]
C = I[2:3]
D = I[3:4]

op_dict = {}
for i in range(2**3):
    
    if ((i >> 0) & 1):
        op3 = "+"
    else:
        op3 = "-"
    
    if ((i >> 1) & 1):
        op2 = "+"
    else:
        op2 = "-"
        
    if ((i >> 2) & 1):
        op1 = "+"
    else:
        op1 = "-"
    op_dict[i] = [op1, op2, op3]

for k in op_dict:
    op1 = op_dict[k][0]
    op2 = op_dict[k][1]
    op3 = op_dict[k][2]
    siki_str = A + op1 + B + op2 + C + op3 + D
    
    if eval(siki_str) == 7:
        print('{}={}'.format(siki_str, eval(siki_str)))
        break;

Solution (Python):
a = input()
input_list = []
for k in a:
    input_list.append(int(k))
n=3
fomul_list = []
for i in range(2 ** n):
    fomul = str(input_list[0])
    for j in range(3):
        if (i >> j)&1:
            fomul = fomul + "+" + str(input_list[j+1])
        else:
            fomul = fomul + "-" + str(input_list[j+1])
    if eval(fomul) == 7:
        print(fomul + "=7")
        exit()

Solution (Python):
a = input()
input_list = []
for k in a:
    input_list.append(int(k))
n=3
bag = []
fomul_list = []
for i in range(2 ** n):
    sum = input_list[0]
    fomul = str(input_list[0])
    for j in range(3):
        if (i >> j)&1:
            sum += input_list[j+1]
            fomul = fomul + "+" + str(input_list[j+1])
        else:
            sum -= input_list[j+1]
            fomul = fomul + "-" + str(input_list[j+1])
    bag.append(sum)
    fomul_list.append(fomul)
print(fomul_list[bag.index(7)] + "=7")

Solution (Python):
S = input()

op = ["+","-"]

for a in op:
  for b in op:
    for c in op:
      shiki = S[0]+a+S[1]+b+S[2]+c+S[3]
      if eval(shiki)==7:
        print(shiki+"=7")
        exit()

Solution (Python):
s=input()
n=len(s)
for i in range(2**(n-1)):
    sum=int(s[0])
    op = []
    for j in range(n-1):
      if ((i>>j)&1):
          sum+=int(s[j+1])
          op.append('+')
      else:
          sum-=int(s[j+1])
          op.append('-')
    if sum == 7:
        ans = s[0]
        for i in range(n-1):
            ans += op[i]
            ans += s[i+1]
        ans += '=7'
        print(ans)
        break

Solution (Python):

import sys
S = list(map(int, sys.stdin.readline().strip()))
L=[]
def saiki(i, score, ans):
    if i+1==4:
        if score ==7:
            ans+='=7'
            L.append(ans)
    else:
        saiki(i+1, score+S[i+1], ans+'+'+str(S[i+1]))
        saiki(i+1, score-S[i+1], ans+'-'+str(S[i+1]))


saiki(0, S[0], str(S[0]))
    
print(L[0])

Solution (Python):
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import time

def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase


input=lambda: sys.stdin.readline().rstrip()

show_flg=False


s=input()
f=list(map(int,list(s)))
show(s,f)

for i in range(2**3):
    t=s[0]
    for j in range(3):
        if i>>j&1:
            t+='+'+s[j+1]
        else:
            t+='-'+s[j+1]
    show(eval(t),t)
    if eval(t)==7:
        print(t+'=7')
        exit()

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

if sum([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))

Solution (Python):
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

Solution (Python):
abcd=list(input())
abcd=list(map(int,abcd))
for i in range(2**3):
  ret=abcd[0]
  for j in range(3):
    if (i>>j)%2==1:
      ret-=abcd[j+1]
    else:
      ret+=abcd[j+1]
  if ret==7:
    ans=[str(abcd[0])]
    for j in range(3):
      if (i>>j)%2==1:
        ans.append("-")
      else:
        ans.append("+")
      ans.append(str(abcd[j+1]))
    ans.append("=")
    ans.append("7")
    print("".join(ans))
    exit(0)

Solution (Python):
n=[int(i) for i in list(input())]
op=[1,-1]
ans=[]
for op1 in op:
	for op2 in op:
		for op3 in op:
			if n[0]+op1*n[1]+op2*n[2]+op3*n[3]==7:
				ans=[op1,op2,op3]
out=''
for i in range(3):
	out+=str(n[i])
	out+='+' if ans[i]==1 else '-'
print(out+str(n[3])+'=7')

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

Solution (Python):
A = list(input())

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

Solution (Python):
N = list(map(str,input()))
n = 3

for i in range(8):
    PlusMinus = ["-"] * 3
    for j in range(3):
        if ((i >> j) & 1):
            PlusMinus[n - j - 1] = "+"
    if eval(N[0] + PlusMinus[0] + N[1] + PlusMinus[1] + N[2] + PlusMinus[2] + N[3]) == 7:
        print(N[0] + PlusMinus[0] + N[1] + PlusMinus[1] + N[2] + PlusMinus[2] + N[3] + "=7")
        break

Solution (Python):
check = 7
l = list(input())
n = len(l)-1

for i in range(2**n):
    v = ['+']*n
    for j in range(n):
        if (i >> j) & 1 == 1:
            v[j] = '-'
    
    working = l[0]
    for k in range(n):
        if v[k] == '+':
            working += ('+'+str(l[k+1]))
        else:
            working += ('-'+str(l[k+1]))
    ans = eval(working)
    if ans == check:
        print(working+'=7')
        exit()

Solution (Python):
import sys
num = [int(x) for x in input()]
sign = ["-","+"]
ans = str(num[0])
for x in range(2 ** (len(num)-1)):
  sum = num[0]
  for i in range(len(num) - 1):
    if ((x >> (2-i)) & 1) == 1:
      sum += num[i+1]
    else:
      sum -= num[i+1]
  if sum == 7:
    for i in range(len(num) - 1):
      ans = "{}{}{}".format(ans,sign[(x >> (2 - i)) & 1],num[i+1])
    print(ans+"=7")
    sys.exit()

Solution (Python):
num = list(map(int,list(input())))

for i in range(len(num) ** 2):
  op = []
  for j in range(len(num)):
    if (i >> j) & 1:
      op.append("+")
    else:
      op.append("-")
  sum = num[0]
  for k in range(len(num)-1):
    if op[k] == "+":
      sum += num[k+1]
    elif op[k] == "-":
      sum -= num[k+1]
  if sum == 7:
    print("{}{}{}{}{}{}{}=7".format(num[0],op[0],num[1],op[1],num[2],op[2],num[3]))
    break

Solution (Python):
def func(i,x,op):
    
    if i == 4:
        if x == 7: return op
        else: return ""

    
    opP = func(i+1, x + int(S[i]),op+"+")
    if opP != "": return opP

    
    opM = func(i+1, x - int(S[i]),op+"-")
    if opM != "": return opM

    return ""

S = input()

op = func(1,int(S[0]),"")
if len(op) == 3:
    print(S[0]+op[0]+S[1]+op[1]+S[2]+op[2]+S[3]+"=7")

Solution (Python):
n=list(input())

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

    w=n[0]
    for k in range(3):
        w+=(v[k]+n[k+1])


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

Solution (Python):
def dfs(formula, index, sum_number):
    if index + 1 == max_index:
        if sum_number == 7:
            print(formula + "=7")
            exit()

    else:
        dfs(formula + "+" + S[index + 1], index + 1, sum_number + int(S[index + 1]))
        dfs(formula + "-" + S[index + 1], index + 1, sum_number - int(S[index + 1]))


S = input()
max_index = len(S)
print(dfs(S[0], 0, int(S[0])))

Solution (Python):
import itertools

S = input()

for op1, op2, op3 in itertools.product('+-', repeat=3):
    if eval(S[0] + op1 + S[1] + op2 + S[2] + op3 + S[3]) == 7:
        print(S[0] + op1 + S[1] + op2 + S[2] + op3 + S[3] + "=7")
        exit()

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

Solution (Python):



def solve(*args: str) -> str:
    abcd = tuple(map(int, args[0]))
    ret = str(abcd[0])
    for p in range(2**3):
        tmp = abcd[0]
        for i in range(3):
            if p >> i & 1:
                tmp += abcd[i+1]
            else:
                tmp -= abcd[i+1]
        if tmp == 7:
            op = '{:03b}'.format(p).replace('0', '-').replace('1', '+')[::-1]
            for i in range(3):
                ret += '{}{}'.format(op[i], abcd[i+1])
            ret += '=7'
            break
    return ret


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Solution (Python):
S = input()
N = 3


for x in range(1<<N):
    ans = S[0]
    sum = int(S[0])
    for i in range(N):
        if x & (1 << i):
            ans += "+" + S[i+1]
            sum += int(S[i+1])
        else:
            ans += "-" + S[i+1]
            sum -= int(S[i+1])
    if sum == 7:
        break

print(ans + "=7")

Solution (Python):
import math

def dig(x,d):
  return (x%(10**(d+1)))//(10**d)

def main():
  N=int(input())
  D=3
  ans=0
  s=['']*D
  for bits in range(2*N):
    ans=dig(N,D)
    for i in range(1,D+1):
      if (bits>>(D-i))&1:
        ans+=dig(N,D-i)
        s[i-1]='+'
      else:
        ans-=dig(N,D-i)
        s[i-1]='-'
    if ans==7:
      print(dig(N,3),end="")
      for i in range(3):
        print(s[i],end="")
        print(dig(N,2-i),end="")
      print('=7')
      return
main()

Solution (Python):
x = ['+++', '++-', '+-+', '+--', '-++', '-+-', '--+', '---']
a = input()
for i in range(8):
    ans = a[0] + x[i][0] + a[1] + x[i][1] + a[2] + x[i][2] + a[3]
    if eval(ans) == 7:
        print(ans + '=7')
        break

Solution (Python):
a = list(input())
for i in range(8):
    b = []
    for j in range(4):
        b.append(a[j])
        if j == 3:
            pass
        else:
            if((i>>j)&1):
                b.append('+')
            else:
                b.append('-')
    c = ''.join(b)
    if eval(c) == 7:
        break
    else:
        pass
print(c+'=7')

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

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

Solution (Python):
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

Solution (Python):

def calc(x,y,op):
    if op=="+":
        return x+y
    else:
        return x-y

if __name__ == '__main__':
    ABCD=input()
    A=int(ABCD[0])
    B=int(ABCD[1])
    C=int(ABCD[2])
    D=int(ABCD[3])
    operators=["+","-"]
    ans=[A,B,C,D,"=7"]
    import itertools

    for ops in itertools.product(operators,repeat=3):
        temp=calc(A,B,ops[0])
        temp=calc(temp,C,ops[1])
        temp=calc(temp,D,ops[2])
        if temp==7:
            print("{}{}{}{}{}{}{}=7".format(A,ops[0],B,ops[1],C,ops[2],D))
            break

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

if a + b + c + d == 7:
  print("{0}+{1}+{2}+{3}=7".format(a,b,c,d))
  exit(0)

if a + b + c - d == 7:
  print("{0}+{1}+{2}-{3}=7".format(a,b,c,d))
  exit(0)

if a + b - c - d == 7:
  print("{0}+{1}-{2}-{3}=7".format(a,b,c,d))
  exit(0)
  
if a - b - c - d == 7:
  print("{0}-{1}-{2}-{3}=7".format(a,b,c,d))
  exit(0)

if a + b - c + d == 7:
  print("{0}+{1}-{2}+{3}=7".format(a,b,c,d))
  exit(0)
  
if a - b + c + d == 7:
  print("{0}-{1}+{2}+{3}=7".format(a,b,c,d))
  exit(0)

if a - b - c + d == 7:
  print("{0}-{1}-{2}+{3}=7".format(a,b,c,d))
  exit(0)

if a - b + c - d == 7:
  print("{0}-{1}+{2}-{3}=7".format(a,b,c,d))
  exit(0)

Solution (Python):
import itertools
S=[int(s) for s in list(input())]
op=['+','-']
for (op1, op2, op3) in itertools.product([0,1],[0,1],[0,1]):
  x=S[0]+(1-2*op1)*S[1]+(1-2*op2)*S[2]+(1-2*op3)*S[3]
  if x==7:
    ls=[S[0],op[op1],S[1],op[op2],S[2],op[op3],S[3],'=7']
    print(*ls,sep="")
    break

Solution (Python):
N = [int(i) for i in str(input())]
output = list()
num_op = 3

for i in range(2**num_op):
  ans = '{}'.format(str(N[0]))
  res = N[0]
  for j in range(num_op):
    if (i>>j) & 1:
      res += N[j+1]
      ans += '+{}'.format(str(N[j+1]))
    else:
      res -= N[j+1]
      ans += '-{}'.format(str(N[j+1]))
  if res == 7:
    print(ans+'=7')
    exit()

Solution (Python):
N = list(str(input()))
A = int(N[0])
B = int(N[1])
C = int(N[2])
D = int(N[3])

if A + B + C + D == 7:
    print(A, end="+")
    print(B, end="+")
    print(C, end="+")
    print(D, end="=7")
elif A - B + C + D == 7:
    print(A, end="-")
    print(B, end="+")
    print(C, end="+")
    print(D, end="=7")
elif A + B - C + D == 7:
    print(A, end="+")
    print(B, end="-")
    print(C, end="+")
    print(D, end="=7")
elif A + B + C - D == 7:
    print(A, end="+")
    print(B, end="+")
    print(C, end="-")
    print(D, end="=7")
elif A - B - C + D == 7:
    print(A, end="-")
    print(B, end="-")
    print(C, end="+")
    print(D, end="=7")
elif A + B - C - D == 7:
    print(A, end="+")
    print(B, end="-")
    print(C, end="-")
    print(D, end="=7")
elif A - B + C - D == 7:
    print(A, end="-")
    print(B, end="+")
    print(C, end="-")
    print(D, end="=7")
elif A - B - C - D == 7:
    print(A, end="-")
    print(B, end="-")
    print(C, end="-")
    print(D, end="=7")

Solution (Python):
A = input()
n = len(A)
ans = ''
for i in range(2**(n-1)):
    tmp = ''
    for j in range(n-1):
        tmp += A[j]
        if i & (1 << j):
            tmp += '+'
        else:
            tmp += '-'
    tmp += A[-1]
    if eval(tmp) == 7:
        ans = tmp
        break

print(tmp + '=7')

Solution (Python):
a = list(input())


for x in range(8):
    s = ""
    sum = int(a[0])
    s += a[0]
    for i in range(3):
        if ( x & ( 1 << i)):
            sum += int(a[i+1])
            s += "+"
            s += a[i+1]
        else:
            sum -=int(a[i+1])
            s += "-"
            s += a[i+1]

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

Solution (Python):
s = input()
lst = [int(i) for i in s]
f1 = lambda x: '+' if x else '-'
f2 = lambda x: 1 if x else - 1
for i in range(16):
  tmp1 = [f1(i >> x & 1) for x in range(3)]
  tmp2 = [f2(i >> x & 1) * lst[x + 1] for x in range(3)]
  if lst[0] + sum(tmp2) == 7:
    print(''.join([s[i] + tmp1[i] for i in range(3)] + [s[3] + '=7']))
    break

Solution (Python):
s = input()
lst = [int(i) for i in s]
f1 = lambda x: '+' if x else '-'
f2 = lambda x: 1 if x else - 1
for i in range(16):
  tmp1 = [f1(i >> x & 1) for x in range(3)]
  tmp1.reverse()
  tmp2 = [f2(i >> x & 1) * lst[ - x - 1] for x in range(3)]
  if lst[0] + sum(tmp2) == 7:
    print(''.join([s[i] + tmp1[i] for i in range(3)] + [s[3] + '=7']))
    break

Solution (Python):
s = input()

a = 0
b = 0
c = 0

for i in range(2):
	for j in range(2):
		for k in range(2):
			
			check = int(s[0])+int(s[1])*(2*i-1)+int(s[2])*(2*j-1)+int(s[3])*(2*k-1)
			if check ==7:
				a = (2*i-1)
				b = (2*j-1)
				c = (2*k-1)



if a == 1:
	stra = '+'
else:
	stra = '-'
	
if b == 1:
	strb = '+'
else:
	strb = '-'

if c == 1:
	strc = '+'
else:
	strc = '-'

print(s[0]+stra+s[1]+strb+s[2]+strc+s[3]+'=7')

Solution (Python):
import sys
a,b,c,d = map(int, list(input()))
x = [1,-1]
for i in x:
  for j in x:
    for k in x:
      if a+i*b+j*c+k*d==7:
        ans = str(a)
        ans += "+" if i==1 else "-"
        ans += str(b)
        ans += "+" if j==1 else "-"
        ans += str(c)
        ans += "+" if k==1 else "-"
        ans += str(d)
        ans += "=7"
        print(ans)
        sys.exit()

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

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

    formula=''
    for x,y in zip(s,op+['']):
        formula+=(x+y)
    if eval(formula)==7:
        print(formula+'=7')
        break

Solution (Python):
n=input()

c=len(n)-1
for i in range(2**c):
      L=['-']*c
      for j in range(c):
            if ((i>>j)&1):
                  L[c-1-j]="+"
      L+=['']
      f=""
      for a,b in zip(n,L):
            f+=a+b
      if eval(f)==7:
            print(f + '=7')
            break

Solution (Python):
inp = input()
a = int(inp[0])
b = int(inp[1])
c = int(inp[2])
d = int(inp[3])
o= ['-','+'] 
def cal(n,i,x,y):
	    if check(n,i):
	    	    return x+y
	    if not check(n,i):
	    	    return x-y

def check(i,j):
	return  (i>>j)%2
for i in range(8):
	    p = cal(i,0,a,b)
	    q = cal(i,1,p,c)
	    r = cal(i,2,q,d)
	    if r == 7:
	    	    s = str(o[check(i,0)])
	    	    t = str(o[check(i,1)])
	    	    u = str(o[check(i,2)])
	    	    print(str(a)+s+str(b)+t+str(c)+u+str(d)+'=7')
	    	    exit(0)
	 
print(-1)

Solution (Python):
x = ['+++', '++-', '+-+', '+--', '-++', '-+-', '--+', '---']
a = input()
for i in range(8):
    ans = a[0] + x[i][0] + a[1] + x[i][1] + a[2] + x[i][2] + a[3]
    if eval(ans) == 7:
        print(ans + '=7')
        break

Solution (Python):
L = input()
INT = [int(L[i]) for i in range(len(L))]

for i in range(2**3):
    ans=[INT[0], L[0]]
    for j in range(3):
        if(i>>j)&1:
            ans[0]+=INT[j+1]
            ans[1]+='+'
            ans[1]+=L[j+1]
        else:
            ans[0]-=INT[j+1]
            ans[1]+='-'
            ans[1]+=L[j+1]
    if ans[0]==7:
        print(ans[1]+'=7')
        break

Solution (Python):
from collections import defaultdict
import sys
import math
from datetime import datetime

def sol(a, b, c, d):
    S = [a, b, c, d]
    for i in range(1<<3):
        ttl = a
        ans = "%s" % a
        for j in range(3):
            if i & (1 << j): 
                ttl += S[j+1]
                ans += "+%s" % S[j+1]
            else:
                ttl -= S[j+1]
                ans += "-%s" % S[j+1]
        if ttl == 7:
            return ans+"=7"
        else:
            assert(True)


do_submit = True


def input_parse(input_str):
    lines = [x.strip() for x in input_str.split("\n") if x.strip()]
    parsed_lines = [list(map(str, line.split())) for line in lines]
    print(parsed_lines)
    n = int(parsed_lines[0][0])
    k = int(parsed_lines[0][1])
    S = parsed_lines[1][0]
    return n, k, S


if not do_submit:
    a, b, c = input_parse("""
    3 1
    ABC
    """)
    print(sol(a, b, c))

    a, b, c = input_parse("""
    4 3
    CABA
    """)
    print(sol(a, b, c))

else:
    
    S = input()
    a = int(S[0])
    b = int(S[1])
    c = int(S[2])
    d = int(S[3])
    
    
    print(sol(a, b, c, d))

Solution (Python):
import sys

s = input()
n = 3

for i in range(2**(n)):
	op = ["-"]*3
	for j in range(n):
		if i & (1<<j):
			op[j] = "+"

	res = ""
	for a,b in zip(s,op+[""]):
		res += a+b
	if eval(res) == 7:
		print(res+'=7')
		sys.exit()

Solution (Python):
n =  input()
for i in range(2 ** 3):
    op = ["-"] * 3
    for j in range(3):
        if((i >> j) & 1):
            op[2 - j] = "+"

    fomula = ""
    for value, operator in zip(n, op + [""]):
        fomula += (value + operator)

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

Solution (Python):
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

Solution (Python):
a,b,c,d=map(int,input())
l=[a+b+c+d,a-b+c+d,
   a+b+c-d,a-b+c-d,
   a+b-c+d,a-b-c+d,
   a+b-c-d,a-b-c-d]
if a+b+c+d==7:
  print(str(a)+"+"+str(b)+"+"+str(c)+"+"+str(d)+"=7");exit()
if a+b+c-d==7:
  print(str(a)+"+"+str(b)+"+"+str(c)+"-"+str(d)+"=7");exit()
if a+b-c+d==7:
  print(str(a)+"+"+str(b)+"-"+str(c)+"+"+str(d)+"=7");exit()
if a-b+c+d==7:
  print(str(a)+"-"+str(b)+"+"+str(c)+"+"+str(d)+"=7");exit()
if a+b-c-d==7:
  print(str(a)+"+"+str(b)+"-"+str(c)+"-"+str(d)+"=7");exit()
if a-b+c-d==7:
  print(str(a)+"-"+str(b)+"+"+str(c)+"-"+str(d)+"=7");exit()
if a-b-c+d==7:
  print(str(a)+"-"+str(b)+"-"+str(c)+"+"+str(d)+"=7");exit()
if a-b-c-d==7:
  print(str(a)+"-"+str(b)+"-"+str(c)+"-"+str(d)+"=7");exit()

Solution (Python):
import re

S = list(input())

for i in range(2**3):
    bits = [(i>>j)&1 for j in range(3)]
    bits.append("")

    expr = ""
    for b, s in zip(bits, S):
        expr += s
        if b == 0:
            expr += "+"
        elif b == 1:
            expr += "-"
    expr_sum = eval(expr)
    if expr_sum == 7:
        print(expr + "=7")
        break

Solution (Python):
S = list(input())
n = len(S)-1
for i in range(2**n):
    op = ['-']*n
    f = S.copy()
    for j in range(n):
        if ((i >> j) & 1):
            op[j] = '+'
    
    for j, k in zip(range(n), [1,3,5]):
        f.insert(k, op[j])
    f = ''.join(f)
    if eval(f) == 7:
        print(f + '=7')
        exit()

Solution (Python):
n=input()
a,b,c,d=int(n[0]),int(n[1]),int(n[2]),int(n[3])
l=0
for i in range(2):
    x=a
    if i==0:
        x+=b
    else:
        x-=b
    for j in range(2):
        if j==0:
            x+=c
        else:
            x-=c
        for k in range(2):
            if k==0:
                x+=d
            else:
                x-=d
            if x==7:
                l=1
                m=[i,j,k]
                break
            if k==0:
                x-=d
            else:
                x+=d
        if j==0:
            x-=c
        else:
            x+=c
    if i==0:
        x-=b
    else:
        x+=b

        if l==1:
            break
    if l==1:
        break

ans=""
ans+=str(a)
if m[0]==0:
    ans+="+"
else:
    ans+="-"
ans+=str(b)
if m[1]==0:
    ans+="+"
else:
    ans+="-"
ans+=str(c)
if m[2]==0:
    ans+="+"
else:
    ans+="-"
ans+=str(d)
ans+="=7"
print(ans)

Solution (Python):
from __future__ import print_function


import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return
















































def main():
    
    l_abcd = list(map(int,input().strip()))
    eprint("l_abcd ",end=": ")
    eprint(l_abcd)
    for case in range(2 ** 3):     
        l_op_bin = list(map(int,(format(case,'b').zfill(3))))
        
        
        
        
        sum_x=l_abcd[0]
        l_op=[]
        for index_location in range(3):      
            if l_op_bin[index_location]==1:                   
               sum_x += l_abcd[1+index_location]
               l_op.append("+")
            else:                                 
               sum_x -= l_abcd[1+index_location]
               l_op.append("-")
        if sum_x==7:
            print(l_abcd[0], end="")
            print(l_op[0],end="")
            print(l_abcd[1], end="")    
            print(l_op[1],end="")
            print(l_abcd[2], end="")    
            print(l_op[2],end="")
            print(l_abcd[3], end="=7\n")
            return
if __name__ == '__main__':
    main()

Solution (Python):
abcd = list(input())
n = len(abcd) - 1 
for i in range(2**n):
    ans = abcd[0]
    for j in range(n):     
        if ((i >> j) & 1):
            ans = ans + "+" + abcd[j+1]
        else:
            ans = ans + "-" + abcd[j+1]
    if eval(ans) == 7:
        print(ans + "=7")
        quit()

Solution (Python):
a,b,c,d=[x for x in input()]
op='+-'
for op1 in op:
  for op2 in op:
    for op3 in op:
      ans=a+op1+b+op2+c+op3+d
      if eval(ans)==7:
        print('{}=7'.format(ans))
        exit()
      else:
        pass

Solution (Python):
import itertools
S=[int(s) for s in list(input())]
op=['+','-']
for (op1, op2, op3) in itertools.product([0,1],[0,1],[0,1]):
  x=S[0]+(1-2*op1)*S[1]+(1-2*op2)*S[2]+(1-2*op3)*S[3]
  if x==7:
    ls=[S[0],op[op1],S[1],op[op2],S[2],op[op3],S[3],'=7']
    print(*ls,sep="")
    break

Solution (Python):
s=input()
n=3
for i in range(2**n):
    tmp=[]
    for k in range(n):
        tmp.append(s[k])
        if i>>k & 1:
            tmp.append("+")
        else:
            tmp.append("-")
    tmp.append(s[-1])
    if eval("".join(tmp))==7:
        print("".join(tmp)+"=7")
        exit()

Solution (Python):
l=list(input())
a,b,c,d=map(str,l)
x=0
y=0
z=0
for i in range(2**3):
    if (i>>0)&1:
        x="+"
    else:
        x="-"
    if (i>>1)&1:
        y="+"
    else:
        y="-"
    if (i>>2)&1:
        z="+"
    else:
        z="-"
    ans=a+x+b+y+c+z+d
    if eval(ans)==7:
        print(ans+"=7")
        exit()

Solution (Python):
from itertools import product

def main():
    s = input() 
    ans = ""
    for p in product(["+", "-"], repeat=3):
        res = ""
        for a,b in zip(s,p):
            res += a+b
        res += s[-1]
        if eval(res) == 7:
            ans = res
            break
    print(ans+"=7")


if __name__ == "__main__":
    main()

Solution (Python):
s = list(map(int, list(input())))
res = 7 - s[0]
if (s[1] + s[2] + s[3] == res):
  print(str(s[0]) + '+' + str(s[1]) + '+' + str(s[2]) + '+' + str(s[3]) + '=' + '7')
elif (s[1] + s[2] - s[3] == res):
  print(str(s[0]) + '+' + str(s[1]) + '+' + str(s[2]) + '-' + str(s[3]) + '=' + '7')
elif (s[1] - s[2] + s[3] == res):
  print(str(s[0]) + '+' + str(s[1]) + '-' + str(s[2]) + '+' + str(s[3]) + '=' + '7')
elif (s[1] - s[2] - s[3] == res):
  print(str(s[0]) + '+' + str(s[1]) + '-' + str(s[2]) + '-' + str(s[3]) + '=' + '7')
elif (-s[1] + s[2] + s[3] == res):
  print(str(-s[0]) + '-' + str(s[1]) + '+' + str(s[2]) + '+' + str(s[3]) + '=' + '7')
elif (-s[1] + s[2] - s[3] == res):
  print(str(s[0]) + '-' + str(s[1]) + '+' + str(s[2]) + '-' + str(s[3]) + '=' + '7')
elif (-s[1] - s[2] + s[3] == res):
  print(str(s[0]) + '-' + str(s[1]) + '-' + str(s[2]) + '+' + str(s[3]) + '=' + '7')
elif (-s[1] - s[2] - s[3] == res):
  print(str(s[0]) + '-' + str(s[1]) + '-' + str(s[2]) + '-' + str(s[3]) + '=' + '7')

Solution (Python):
a = input()
array = []

for i in range(2**3):
    a2 = a[0]
    for j in range(3):
        if (i >> j) & 1 == 1:
            a2 += '+'
        else:
            a2 += '-'
        a2 += a[j+1]
    if eval(a2) == 7:
        c = 1
        break

print(a2+'=7')

Solution (Python):
INF = float("inf") 

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

    for i in range(2**n):
        op = ["-"]*n
        for j in range(n):
            if (i>>j)&1:
                op[j] = "+"
        tmp = ""
        for a,b in zip(s,op+[""]):
            tmp += a + b
        if eval(tmp) == 7:
            print(tmp+"=7")
            return


if __name__ == "__main__":
    main()

Solution (Python):
N = list(input())
num = list(map(lambda x: int(x) , N))
for i in range(8):
    sum_val = num[0]
    for j in range(3):
        if i >> j & 1:
            sum_val += num[j + 1]
        else:
            sum_val -= num[j + 1]
    if sum_val == 7:
        print(num[0] , end = '')
        for j in range(3):
            if i >> j & 1:
                print("+" , end = '')
            else:
                print("-",end = '')
            print(num[j + 1] , end = '')
        print('=7')
        exit()

Solution (Python):
def vary_for_flag(a, b, flag):
    if flag == False:
        return a-b
    else:
        return a+b
def str_for_num(num):
    if num == 0:
        return "+"
    else:
        return "-"
A = input()
a = []
for i in range(4):
    b = int(A[i])
    a.append(b)
for i in range(2):
    if i == 0:
        first_flag = True
    else:
        first_flag = False
    for j in range(2):
        if j == 0:
            second_flag = True
        else:
            second_flag = False
        for k in range(2):
            if k == 0:
                third_flag = True
            else:
                third_flag = False
            temp = vary_for_flag(vary_for_flag(vary_for_flag(a[0], a[1], first_flag), a[2], second_flag), a[3], third_flag)
            if temp == 7:
                break
        else:
            continue
        break
    else:
        continue
    break
print("{}{}{}{}{}{}{}=7".format(a[0],str_for_num(i),a[1],str_for_num(j),a[2],str_for_num(k),a[3]))

Solution (Python):
import sys
import copy

def main():
    ABCD = list(map(str, input()))
    b_digit = len(ABCD)-1

    for i in range(2 ** b_digit):
        signs = ["+"] * b_digit
        for j in range(b_digit):
            if ((i >> j ) & 1):
                signs[b_digit - 1 - j] = "-"

        ABCD_tmp = copy.deepcopy(ABCD)
        for k in range(len(signs)):
            ABCD_tmp.insert(1+k*2,signs[k])
        if(eval("".join(ABCD_tmp))==7):
            print("{}=7".format("".join(ABCD_tmp)))
            sys.exit()

main()

Solution (Python):
ABCD = input()

N = len(ABCD)


for i in range(2**(N-1)):
    temp_res = ''
    for j in range(N-1):
        temp_res += ABCD[j]
        if ((i >> j) & 1):
            temp_res += '+'
        else:
            temp_res += '-'
    temp_res += ABCD[-1]

    if eval(temp_res) == 7:
        res = temp_res + '=7'
        break

print(res)