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):
s = input()


def recursion(n,sum,l):
    

    if n == len(s):
        if sum == 7:
            print(s[0]+l[1]+s[1]+l[2]+s[2]+l[3]+s[3]+"=7")
            exit()
        return sum

    '''プラスの場合'''
    l[n] = "+"
    recursion(n+1, sum + int(s[n]),l)

    '''マイナスの場合'''
    l[n] = "-"
    recursion(n+1, sum - int(s[n]),l)



l = [[] for i in range(len(s))]
recursion(0,0,l)

Solution (Python):

S=input()
num = len(S) - 1

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

    formula=""
    for l_num,l_m in zip(S,l+[""]):
        formula += l_num + l_m 

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

Solution (Python):
s = str(input())
nl = [s[0],s[1],s[2],s[3]]
nl = list(map(int,nl))

dic = {'+':1, '-':-1}
end = False
for op1 in ['+','-']:
    for op2 in ['+','-']:
        for op3 in ['+','-']:
            num = nl[0] + nl[1]*dic[op1] + nl[2]*dic[op2] + nl[3]*dic[op3]
            if num == 7 and not end:
                print('{}{}{}{}{}{}{}=7'.format(s[0],op1,s[1],op2,s[2],op3,s[3]))
                end = True

Solution (Python):
li = [int(n) for n in list(input())]
Ops = []

def func(i, x, li, ops):
  if i==0:
    if x+li[0]==7:
      return True
    if x-li[0]==7:
      return True
  else:
    if func(i-1, x-li[i], li, ops):
      ops.append('-')
      return True
    if func(i-1, x+li[i], li, ops):
      ops.append('+')
      return True
    
func(3, 0, li, Ops)
Ops.append('=7')
for i in range(4):
  print(li[i], Ops[i], sep='', end='')

Solution (Python):
import sys

S = input()

def ticket_sum(i, s, num, memo):
    if i == len(S):
        if num == 7:
            memo.append(s+"=7")
            return memo
        else:
            return
    
    
    pos = i - len(S)

    
    ticket_sum(i+1, s[:pos]+"+"+s[pos:], num+int(s[pos]), memo)
    
    ticket_sum(i+1, s[:pos]+"-"+s[pos:], num-int(s[pos]), memo)

    return memo

memo = []
print(ticket_sum(1, S, int(S[0]), memo)[0])

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


if a+b+c+d==7:print('{}+{}+{}+{}=7'.format(a,b,c,d));exit()
if a-b+c+d==7:print('{}-{}+{}+{}=7'.format(a,b,c,d));exit()
if a+b-c+d==7:print('{}+{}-{}+{}=7'.format(a,b,c,d));exit()
if a+b+c-d==7:print('{}+{}+{}-{}=7'.format(a,b,c,d));exit()
if a-b-c+d==7:print('{}-{}-{}+{}=7'.format(a,b,c,d));exit()
if a+b-c-d==7:print('{}+{}-{}-{}=7'.format(a,b,c,d));exit()
if a-b+c-d==7:print('{}-{}+{}-{}=7'.format(a,b,c,d));exit()
if a-b-c-d==7:print('{}-{}-{}-{}=7'.format(a,b,c,d));exit()

Solution (Python):
S = list(input())
ops = []
lst = []

for i in range(8):
    ops.append(bin(i))
    ops[i] = ops[i][2:].zfill(3)

for i in range(8):
    res = S[0]
    for j in range(3):
        if ops[i][j] == "0":
            res = res + "+" + S[j+1]
        else:
            res = res + "-" + S[j+1]
    if eval(res) == 7:
        res = res + "=7"
        lst.append(res)
        break

print(lst[0])

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]




def dfs(ind, l):
    if ind == 4:
        if sum(l) ==7:
            for i, num in enumerate(l):
                if num >= 0 and i != 0:
                    print('+', end='')
                print(num, end='')
        else:
            return
        print('=7')
        exit()
    dfs(ind+1, l+[A[ind]])
    dfs(ind+1, l+[(-1)*A[ind]])

A = list(map(int, list(input())))
dfs(1, [A[0]])

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

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

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

Solution (Python):
n = [int(x) for x in input()]
k=len(n)-1
for i in range(2**k):
    op=["-"]*(k)
    for j in range(k):
        if ((i>>j)&1):
            op[k-1-j]="+"
    formula = ""
    for p_n, p_o in zip(n, op + [""]):  
        formula += (str(p_n) + p_o)
    if eval(formula) == 7:
        print(formula + "=7")
        break

Solution (Python):
import sys
S=input()
n=len(S)
for i in range(2**(n-1)):
  s=int(S[0])
  L=[S[0]]
  for j in range(n-1):
    if (i>>j) & 1:
      s+=int(S[j+1])
      L+=["+"]+[S[j+1]]
    else:
      s-=int(S[j+1])
      L+=["-"]+[S[j+1]]
  if s==7:
    L+=["=7"]
    print(*L,sep="")
    sys.exit()

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

ops = None
for i in range((n-1)**2):
  tmp = int(s[0])
  for j in range(0, n-1):

    if (i>>j)&1:
      tmp += int(s[j+1])
    else:
      tmp -= int(s[j+1])

  if tmp == 7:
    ops = i
    break

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

print(res+"=7")

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

correct_ops = None
def helper(cur, i, ops=[]):
  global correct_ops
  if i == n and cur == 7: 
    correct_ops = ops
    return ops
  if i == n and cur != 7: return []

  if helper(cur+int(s[i]), i+1, ops+["+"]): return ops

  if helper(cur-int(s[i]), i+1, ops+["-"]): return ops

helper(int(s[0]), 1)

res = ""
for i in range(n):
  if i == n-1:
    res += s[i]
  else:
    res += s[i]+correct_ops[i]

print(res+"=7")

Solution (Python):
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    A,B,C,D = list(map(int,list(_in[0])))  
    
    for a in [1,-1]:
        for b in [1,-1]:
            for c in [1,-1]:
                if A+a*B+b*C+c*D == 7:
                    s = str(A)+("+" if a==1 else "-")+str(B)+("+" if b==1 else "-")+str(C)+("+" if c==1 else "-")+str(D)+'=7'
                    break
    
    print(s)

Solution (Python):

a,b,c,d=list(input())
s="+-"

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n = input()
    aida = len(n) - 1
    for i in range(2 ** aida):
        kigo = ['-'] * aida
        for j in range(aida):
            if ((i >> j) & 1):
                kigo[-1 - j] = '+'
    
        kigo.append('')
     
        siki = ''
        for kazu, seifu in zip(n, kigo):
            siki += (kazu + seifu)
      
        if eval(siki) == 7:
            print(siki + '=7')
            break

resolve()

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

Solution (Python):
ABCD = input()
if int(ABCD[0]) + int(ABCD[1]) + int(ABCD[2]) + int(ABCD[3]) == 7: print(ABCD[0] + "+" + ABCD[1] + "+" + ABCD[2] + "+" + ABCD[3] + "=7")
elif int(ABCD[0]) + int(ABCD[1]) + int(ABCD[2]) - int(ABCD[3]) == 7: print(ABCD[0] + "+" + ABCD[1] + "+" + ABCD[2] + "-" + ABCD[3] + "=7")
elif int(ABCD[0]) + int(ABCD[1]) - int(ABCD[2]) + int(ABCD[3]) == 7: print(ABCD[0] + "+" + ABCD[1] + "-" + ABCD[2] + "+" + ABCD[3] + "=7")
elif int(ABCD[0]) + int(ABCD[1]) - int(ABCD[2]) - int(ABCD[3]) == 7: print(ABCD[0] + "+" + ABCD[1] + "-" + ABCD[2] + "-" + ABCD[3] + "=7")
elif int(ABCD[0]) - int(ABCD[1]) + int(ABCD[2]) + int(ABCD[3]) == 7: print(ABCD[0] + "-" + ABCD[1] + "+" + ABCD[2] + "+" + ABCD[3] + "=7")
elif int(ABCD[0]) - int(ABCD[1]) + int(ABCD[2]) - int(ABCD[3]) == 7: print(ABCD[0] + "-" + ABCD[1] + "+" + ABCD[2] + "-" + ABCD[3] + "=7")
elif int(ABCD[0]) - int(ABCD[1]) - int(ABCD[2]) + int(ABCD[3]) == 7: print(ABCD[0] + "-" + ABCD[1] + "-" + ABCD[2] + "+" + ABCD[3] + "=7")
elif int(ABCD[0]) - int(ABCD[1]) - int(ABCD[2]) - int(ABCD[3]) == 7: print(ABCD[0] + "-" + ABCD[1] + "-" + ABCD[2] + "-" + ABCD[3] + "=7")

Solution (Python):
n = [int(x) for x in 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 += (str(p_n) + p_o)
  if eval(formula) == 7:
    print(formula + "=7")
    exit()

Solution (Python):
S = list(input())
for i in range(2 ** 3):
    pm = ['-'] * 3
    for j in range(3):
        if i >> j & 1:
            pm[j] = '+'
    ans = [None] * 7
    ans[::2] = S
    ans[1::2] = pm
    ans = ''.join(ans)
    if eval(ans) == 7:
        print(ans + '=7')
        break

Solution (Python):
import sys
sys.setrecursionlimit(1000000) 

def main():
    ticket = input()
    N = 4
    num_list = []
    for num in ticket:
        num_list.append(int(num))

    for bit in range(1 << (N-1)):
        sum_value = num_list[0]
        op_list = [None] * N

        for i in range(N-1):
            if bit & (1 << i):
                
                op_list[i] = "+"
                sum_value += num_list[i+1]
            else:
                
                op_list[i] = "-"
                sum_value -= num_list[i+1]

        if sum_value == 7:
            op_list[3] = "="
            for num, op, in zip(num_list, op_list):
                print(num, op, sep="", end="")
            print(7)
            exit()

if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(1000000) 

def main():
    input = sys.stdin.readline  
    ticket = input().rstrip()
    N = 4
    num_list = []
    for num in ticket:
        num_list.append(int(num))

    for bit in range(1 << (N-1)):
        sum_value = num_list[0]
        op_list = [None] * N

        for i in range(N-1):
            if bit & (1 << i):
                
                op_list[i] = "+"
                sum_value += num_list[i+1]
            else:
                
                op_list[i] = "-"
                sum_value -= num_list[i+1]

        if sum_value == 7:
            op_list[3] = "="
            for num, op, in zip(num_list, op_list):
                print(num, op, sep="", end="")
            print(7)
            exit()

if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(1000000) 

def main():
    input = sys.stdin.readline  
    ticket = input().rstrip()
    N = 4
    num_list = []
    for num in ticket:
        num_list.append(int(num))

    for bit in range(1 << (N-1)):
        sum_value = num_list[0]
        op_list = []

        for i in range(N-1):
            if bit & (1 << i):
                
                op_list.append("+")
                sum_value += num_list[i+1]
            else:
                
                op_list.append("-")
                sum_value -= num_list[i+1]

        if sum_value == 7:
            op_list.append("=")
            for num, op, in zip(num_list, op_list):
                print(num, op, sep="", end="")
            print(7)
            exit()

if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
import sys
import math

s=input()
t=[]
for i in range(4):
    t.append(int(s[i]))
temp=0
for i in range(2):
    temp+=(t[0]+t[1] if i==0 else t[0]-t[1])
    for j in range(2):
        temp+=(t[2] if j==0 else -t[2])
        for k in range(2):
            temp+=(t[3] if k==0 else -t[3])
            if temp==7:
                print(s[0]+('+' if i==0 else '-')+s[1]+('+' if j==0 else '-')+s[2]+('+' if k==0 else '-')+s[3]+'=7')
                sys.exit()
            else:
                temp-=(t[3] if k==0 else -t[3])
        temp-=(t[2] if j==0 else -t[2])
    temp=0

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

if a + b + c + d == 7:
    print('%d+%d+%d+%d=7' % (a, b, c, d))
elif a + b + c - d == 7:
    print('%d+%d+%d-%d=7' % (a, b, c, d))
elif a + b - c + d == 7:
    print('%d+%d-%d+%d=7' % (a, b, c, d))
elif a + b - c - d == 7:
    print('%d+%d-%d-%d=7' % (a, b, c, d))
elif a - b + c + d == 7:
    print('%d-%d+%d+%d=7' % (a, b, c, d))
elif a - b + c - d == 7:
    print('%d-%d+%d-%d=7' % (a, b, c, d))
elif a - b - c + d == 7:
    print('%d-%d-%d+%d=7' % (a, b, c, d))
else:
    print('%d-%d-%d-%d=7' % (a, b, c, d))

Solution (Python):
A, B, C, D = map(str, input())

for op1 in '+-':
    for op2 in '+-':
        for op3 in '+-':
            if eval(A+op1+B+op2+C+op3+D) == 7:
                print(A+op1+B+op2+C+op3+D+'=7')
                exit()

Solution (Python):

import sys


def solve(num_str: str):
    N = len(num_str) - 1

    for bit in range(2 ** N):
        ans = num_str[0]
        for i in range(N):
            if bit & 1 << i:
                ans += "+"
            else:
                ans += "-"
            ans += num_str[i + 1]

        if eval(ans) == 7:
            print(ans + "=7")
            return

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    ABCD = next(tokens)
    solve(ABCD)

if __name__ == '__main__':
    main()

Solution (Python):

import sys


def solve(ABCD: str):
    num_str = ABCD
    N = len(num_str) - 1

    for bit in range(2 ** N):
        tmp = num_str[0]
        for i in range(N):
            if bit & 1 << i:
                tmp += "+"
            else:
                tmp += "-"
            tmp += num_str[i + 1]
        res = eval(tmp)

        if res == 7:
            print(tmp + "=7")
            return

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    ABCD = next(tokens)
    solve(ABCD)

if __name__ == '__main__':
    main()

Solution (Python):
li = []
s = input()
li2 = []
for i in range(4):
  li.append(int(s[i]))
n1 = 4
def func(n, t):
  if n == 1:
    if t == li[0]:
      return True
    else:
      return False
  if func(n-1, t+li[n-1]):
    li2.append('-')
    return True
  elif func(n-1, t-li[n-1]):
    li2.append('+')
    return True
  else:
    return False
if func(n1, 7):
  print("{0}{4}{1}{5}{2}{6}{3}=7".format(li[0], li[1], li[2], li[3], li2[0], li2[1], li2[2]))

Solution (Python):
s = input()
pat = []
for i in range(2**3):
    tmp = ['']
    for j in range(3):
        if i >> j & 1:
            tmp.append('+')
        else:
            tmp.append('-')
    pat.append(tmp)

for p in pat:
    tmp = ''
    for i, j in zip(p, s):
        tmp += i+j
    if eval(tmp) == 7:
        print(tmp + '=7')
        exit()

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):
n = [int(x) for x in 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] = "+"
  
  ans = ""
  for x, y in zip(n, op+[""]): 
    ans += str(x)+y
  if eval(ans)==7:
    print(ans+"=7")
    break

Solution (Python):
s = input()

def func(i, s_temp): 
    
    
    
    if i == 3:
        
        if eval(s_temp) == 7:
            print("{}=7".format(s_temp))
            exit()
    
    
    else:
        func(i+1, s_temp+"+"+s[i+1])
        func(i+1, s_temp+"-"+s[i+1])

func(0, s[0])

Solution (Python):
s = input()

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

Solution (Python):

import sys
import itertools


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


def ir(): return int(sr())


def lr(): return list(map(int, sr().split()))


S = sr()
ans = 0


def dfs(depth, p_list):
    global ans

    if depth == 4:
        sum_list = []
        T = S
        text = ''
        for j, p in enumerate(p_list):
            if p == 1:
                sum_list.append(int(T[:1]))
            elif p == -1:
                sum_list.append(int(T[:1]) * -1)

            if len(text) == 0:
                text += T[:1]
            else:
                if p == 1:
                    text += '+' + T[:1]
                elif p == -1:
                    text += '-' + T[:1]
            T = T[1:]
        
        ans = sum(sum_list)
        if ans == 7:
            text += '=7'
            print(text)
            exit()

        return

    for i in [1, -1]:
        p_list[depth] = i
        dfs(depth + 1, p_list)


def main():

    p_list = [0] * (4)
    dfs(0, p_list)


main()

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
opr = ["+++", "++-", "+--", "---", "-++", "--+", "-+-", "+-+"]

ABCD = list(input())

for op in opr:
	ans = []
	ABCD_ = ABCD.copy()
	op = list(op)
	ans.append(ABCD_.pop(0))
	while ABCD_ != []:
		ans.append(op.pop(0))
		ans.append(ABCD_.pop(0))
	if eval("".join(ans)) == 7:
		print("".join(ans), "=7", sep="")
		exit()

Solution (Python):
s = str(input())
l = list(s)

for i in range(1 << len(s)-1):
    li = ''
    
    for j in range(len(s)):
        li += l[j]
        if j == len(s)-1:
            continue
        if i & (1 << j):
            li += '+'
        else:
            li += '-'

    r = eval(li)
    if r == 7:
        break
        
print(li+'=7')

Solution (Python):
def ans(i, j, k):
    if i == 3:
        if j == 7:
            print(k + '=7')
            exit()
        return
    ans(i+1, j-int(n[i+1]), k+'-'+n[i+1]), 
    ans(i+1, j+int(n[i+1]), k+'+'+n[i+1])

n = input()

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

Solution (Python):
def ans(i, j, k):
    if i == 3:
        if j == 7:
            print(k + '=7')
            exit()
    else:      
        ans(i+1, j-int(n[i+1]), k+'-'+n[i+1]),
        ans(i+1, j+int(n[i+1]), k+'+'+n[i+1])

n = input()

print(ans(0, int(n[0]), n[0]))

Solution (Python):
A, B, C, D = list(input())
for n in range(8):
    formula = "{}{}{}{}{}{}{}".format(A, ["+", "-"][n & 1], B, ["+", "-"][(n >> 1) & 1], C, ["+", "-"][(n >> 2) & 1], D)
    if eval(formula) == 7:
        print(formula + "=7")
        quit()

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

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
S = list(input())

ans = []

for i in range(1 << 3):
	i = list("{:b}".format(i).zfill(3))
	shiki = []
	S_ = S.copy()
	shiki.append(S_.pop(0))
	while S_ != []:
		if i.pop(0) == "0":
			shiki.append("+")
		else:
			shiki.append("-")

		shiki.append(S_.pop(0))

	if eval("".join(shiki)) == 7:
		print("".join(shiki) + "=7")
		exit()

Solution (Python):
def ans(i, j, k):
    if i == 3:
        if j == 7:
            print(k + '=7')
            exit()
    else:      
        ans(i+1, j-int(n[i+1]), k+'-'+n[i+1]),
        ans(i+1, j+int(n[i+1]), k+'+'+n[i+1])

n = input()

print(ans(0, int(n[0]), n[0]))

Solution (Python):
num = [int(i) for i in input()]
a, b, c, d = num[0], num[1], num[2], num[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))

Solution (Python):
import numpy as np

nyuryoku=input()

s=[int(i) for i in nyuryoku]

s_array=np.array(s)

if np.sum(s_array)==7:
    Ans=['+'+str(i) for i in s]
    Ans[0]=str(s[0])
    print(''.join(Ans)+'=7')
    
else:
    for i in range(3):
        if np.sum(s_array)-2*s_array[i+1]==7:
            Ans=['+'+str(i) for i in s]
            Ans[0]=str(s[0])
            Ans[i+1]='-'+str(s[i+1])
            print(''.join(Ans)+'=7')
            break
            
        elif np.sum(s_array)-2*s_array[1]-2*s_array[2]==7:
            Ans=['+'+str(i) for i in s]
            Ans[0]=str(s[0])
            Ans[1]='-'+str(s[1])
            Ans[2]='-'+str(s[2])
            print(''.join(Ans)+'=7')
            break
            
        elif np.sum(s_array)-2*s_array[2]-2*s_array[3]==7:
            Ans=['+'+str(i) for i in s]
            Ans[0]=str(s[0])
            Ans[2]='-'+str(s[2])
            Ans[3]='-'+str(s[3])
            print(''.join(Ans)+'=7')
            break
        
        elif np.sum(s_array)-2*s_array[1]-2*s_array[3]==7:
            Ans=['+'+str(i) for i in s]
            Ans[0]=str(s[0])
            Ans[1]='-'+str(s[1])
            Ans[3]='-'+str(s[3])
            print(''.join(Ans)+'=7')
            break
            
        elif np.sum(s_array)-2*s_array[1]-2*s_array[2]-2*s_array[3]==7:
            Ans=['+'+str(i) for i in s]
            Ans[0]=str(s[0])
            Ans[1]='-'+str(s[1])
            Ans[2]='-'+str(s[2])
            Ans[3]='-'+str(s[3])
            print(''.join(Ans)+'=7')
            break

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

if a+b+c+d==7:print('{}+{}+{}+{}=7'.format(a,b,c,d));exit()
if a-b+c+d==7:print('{}-{}+{}+{}=7'.format(a,b,c,d));exit()
if a+b-c+d==7:print('{}+{}-{}+{}=7'.format(a,b,c,d));exit()
if a+b+c-d==7:print('{}+{}+{}-{}=7'.format(a,b,c,d));exit()
if a-b-c+d==7:print('{}-{}-{}+{}=7'.format(a,b,c,d));exit()
if a-b+c-d==7:print('{}-{}+{}-{}=7'.format(a,b,c,d));exit()
if a+b-c-d==7:print('{}+{}-{}-{}=7'.format(a,b,c,d));exit()
if a-b-c-d==7:print('{}-{}-{}-{}=7'.format(a,b,c,d));exit()

Solution (Python):
a,b,c,d = input()
for i in range(2**3):
    ls = ["+","+","+"]
    for j in range(len(ls)):
        if (i >> j) & 1:
            ls[j] = "-"
    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

Solution (Python):
A = input()
op_cnt = len(A) - 1
result = 0
for i in range(2 ** op_cnt):
    f = ""
    bag = []
    for j in range(op_cnt):
        if (i >> j) & 1:
            bag.append("+")
        else:
            bag.append("-")
    for p_n, p_o in zip(A, bag + [""]):
        f += (p_n + p_o)
    if eval(f) == 7:
        print(f+'=7')
        break

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

Solution (Python):
from sys import stdin
import math
import fractions
import heapq

r = stdin.readline().rstrip()

for i in range(2 ** 3):
    op = ["-"] * 3
    for j in range(3):
        if ((i >> j) & 1):
            op[2 - j] = "+"
    ss = r[0] + op[0] + r[1] + op[1] + r[2] + op[2] + r[3]
    if eval(ss) == 7:
        print(ss + "=7")
        break

Solution (Python):
import sys

S = input()
for b_op in range(2):
    for c_op in range(2):
        for d_op in range(2):
            ans = S[0]
            total = int(S[0])
            if bool(b_op):
                total += int(S[1])
                ans += "+" + S[1]
            else:
                total -= int(S[1])
                ans += "-" + S[1]

            if bool(c_op):
                total += int(S[2])
                ans += "+" + S[2]
            else:
                total -= int(S[2])
                ans += "-" + S[2]

            if bool(d_op):
                total += int(S[3])
                ans += "+" + S[3]
            else:
                total -= int(S[3])
                ans += "-" + S[3]

            if total == 7:
                print(ans + "=7")
                sys.exit()

Solution (Python):

def inputlist(): return [int(k) for k in input().split()]
def base10to(n, b):
    if (int(n/b)):
        return base10to(int(n/b), b) + str(n%b)
    return str(n%b)

S = input()
for i in range(8):
    k = base10to(i,2)
    if len(k) < 3:
        for j in range(3-len(k)):
            k = '0'+k
    tmp = int(S[0])
    for j in range(1,4):
        if k[j-1] == '0':
            tmp += int(S[j])
        else:
            tmp -= int(S[j])
    if tmp == 7:
        li = []
        for t in range(4):
            if t == 3:
                li.append(S[t])
            else:
                li.append(S[t])
                if k[t] == '0':
                    li.append('+')
                else:
                    li.append('-')
        li += ['=','7']
        print(''.join(li))
        exit()

Solution (Python):
import itertools
import sys
import numpy as np
import collections
s=input()
a,b,c,d=s[0],s[1],s[2],s[3]
ia,ib,ic,id=int(a),int(b),int(c),int(d)
l=[ia,ib,ic,id]
if sum(l) == 7:
    print('{0}+{1}+{2}+{3}=7'.format(a,b,c,d))
    exit(0)
elif ia+ib+ic-id ==7:
    print('{0}+{1}+{2}-{3}=7'.format(a, b, c, d))
elif ia+ib-ic+id ==7:
    print('{0}+{1}-{2}+{3}=7'.format(a, b, c, d))
elif ia+ib-ic-id ==7:
    print('{0}+{1}-{2}-{3}=7'.format(a, b, c, d))
elif ia-ib+ic+id ==7:
    print('{0}-{1}+{2}+{3}=7'.format(a, b, c, d))
elif ia-ib+ic-id ==7:
    print('{0}-{1}+{2}-{3}=7'.format(a, b, c, d))
elif ia-ib-ic+id ==7:
    print('{0}-{1}-{2}+{3}=7'.format(a, b, c, d))
else:
    print('{0}-{1}-{2}-{3}=7'.format(a, b, c, d))

Solution (Python):

SUM = 7

def get_Operator(i):
    if i == 1: return "+"
    else: return "-"
def solve(S):
    n = [int(c) for c in S]
    operators = [1, -1]
    for i in operators:
        for j in operators:
            for k in operators:
                if(n[0] + i * n[1] + j * n[2] + k * n[3] == SUM):
                    foamula = (str(n[0]) + get_Operator(i) + str(n[1]) + get_Operator(j) + str(n[2]) + get_Operator(k) + str(n[3]) + "=7")
                    return foamula
def main():
    S = input()
    print(solve(S))
    
main()

Solution (Python):
S = input()
A,B,C,D = [S[i] for i in range(4)]
signal = ['+', '-']
flag = False
for op1 in signal:
    for op2 in signal:
        for op3 in signal:
            formula = '{}{}{}{}{}{}{}'.format(A,op1,B,op2,C,op3,D)
            if eval(formula) == 7:
                print(formula+'=7')
                flag = True
                break
        if flag:
            break
    if flag:
        break

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

for i in range(2**3): 
    fomula = ref_num[0]
    for j in range(3):
        if i >> j & 1:
            fomula += "+" + ref_num[j+1]
        else:
            fomula += "-" + ref_num[j+1]
    if eval(fomula) == 7:
        print(fomula+"=7")
        break

Solution (Python):
A = [int(i) for i in list(input())]
n = 3
for i in range(1 << n):
    a, b, c, d = A
    o = ["", "", ""]
    p = [1, 1, 1]
    ans = 0
    for j in range(n):
        if i >> j & 1:
            o[j] = "+"
            p[j] = 1
        else:
            o[j] = "-"
            p[j] = -1

    if a + (b*p[0]) + (c*p[1]) + (d*p[2]) == 7:
        print("{}{}{}{}{}{}{}=7".format(a, o[0], b, o[1], c, o[2], d))
        break

Solution (Python):
a,b,c,d = input()
for i in range(2**3):
  ls = ["+","+","+"]
  for j in range(len(ls)):
    if (i>>j) & 1:
      ls[j]="-"
  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

Solution (Python):
s = input()
f = lambda x: '+' if x>0 else '-'
for i in range(-1, 3, 2):
    for j in range(-1, 3, 2):
        for k in range(-1, 3, 2):
            if int(s[0])+i*int(s[1])+j*int(s[2])+k*int(s[3])==7:
                print(s[0]+f(i)+s[1]+f(j)+s[2]+f(k)+s[3]+'=7')
                break
        else:
            continue
        break
    else:
        continue
    break

Solution (Python):
s = input()
n = len(s)
count = 0

def rec(int_num, num, count):
    if count >= n - 1:
        if int_num == 7:
            print('{}={}'.format(num, int_num))
            exit()
        else:
            return
    else:
        rec(int_num + int(s[count + 1]), num + '+' + s[count + 1], count + 1)
        rec(int_num - int(s[count + 1]), num + '-' + s[count + 1], count + 1)

rec(int(s[0]),s[0],count)