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()
a,b,c,d=int(s[0]),int(s[1]),int(s[2]),int(s[3])
if a+b+c+d==7:print(a,'+',b,'+',c,'+',d,'=',7, sep='')
elif a+b+c-d==7:print(a,'+',b,'+',c,'-',d,'=',7, sep='')
elif a+b-c+d==7:print(a,'+',b,'-',c,'+',d,'=',7, sep='')
elif a-b+c+d==7:print(a,'-',b,'+',c,'+',d,'=',7, sep='')
elif a+b-c-d==7:print(a,'+',b,'-',c,'-',d,'=',7, sep='')
elif a-b-c+d==7:print(a,'-',b,'-',c,'+',d,'=',7, sep='')
elif a-b+c-d==7:print(a,'-',b,'+',c,'-',d,'=',7, sep='')
elif a-b-c-d==7:print(a,'-',b,'-',c,'-',d,'=',7, sep='')

Solution (Python):
a=input()
op=list("+-")
flag = False
for i in op:
    for j in op:
        for k in op:
            s = a[0]+i+a[1]+j+a[2]+k+a[3]
            if eval(s) == 7:
                flag = True
                break
        if flag:
            break
    if flag:
        break
print(s+"=7")

Solution (Python):
S=input()

for i in range(2**3):
    p=['-']*3
    ans=''
    for j in range(3):
        if((i>>j)&1):
            p[j]='+'
    for j,k in zip(S,p+['']):
        ans+=j+k
    if(eval(ans)==7):
        print(ans+'=7')
        exit()

Solution (Python):
n=input()
a=int(n[0])
b=int(n[1])
c=int(n[2])
d=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):
n=input()
num=[]
for i in range(4):
    num.append(int(n[i]))
o=["+","+","+"]
op=[1,1,1]
def ans():
    return num[0]+op[0]*num[1]+op[1]*num[2]+op[2]*num[3]
if ans()!=7:
    for i in range(3):
        op[i]=-1
        if ans()==7:
            break
        op[i]=1
if ans()!=7:  
    for i in range(-1,2):
        op[i]=-1
        op[i+1]=-1
        if ans()==7:
            break
        op[i]=1
        op[i+1]=1
if ans()!=7:
    for i in range(3):
        op[i]=-1
for i in range(3):
    if op[i]==-1:
        o[i]="-"
print(n[0]+o[0]+n[1]+o[1]+n[2]+o[2]+n[3]+"=7")

Solution (Python):
S=input()
A=int(S[0])
B=int(S[1])
C=int(S[2])
D=int(S[3])
if A+B+C+D==7:
    print(S[0]+'+'+S[1]+'+'+S[2]+'+'+S[3]+'=7')
elif A+B+C-D==7:
    print(S[0]+'+'+S[1]+'+'+S[2]+'-'+S[3]+'=7')
elif A+B-C+D==7:
    print(S[0]+'+'+S[1]+'-'+S[2]+'+'+S[3]+'=7')
elif A+B-C-D==7:
    print(S[0]+'+'+S[1]+'-'+S[2]+'-'+S[3]+'=7')
elif A-B+C+D==7:
    print(S[0]+'-'+S[1]+'+'+S[2]+'+'+S[3]+'=7')
elif A-B+C-D==7:
    print(S[0]+'-'+S[1]+'+'+S[2]+'-'+S[3]+'=7')
elif A-B-C+D==7:
    print(S[0]+'-'+S[1]+'-'+S[2]+'+'+S[3]+'=7')
else :
    print(S[0]+'-'+S[1]+'-'+S[2]+'-'+S[3]+'=7')

Solution (Python):
import itertools
s=list(input())
for x,y,z in list(itertools.product(["+","-"],repeat=3)):
    if int(s[0])+int(x+s[1])+int(y+s[2])+int(z+s[3])==7:
        print(s[0]+x+s[1]+y+s[2]+z+s[3]+"=7")
        break

Solution (Python):
import sys
x = input()
for i in ['+','-']:
    for j in ['+','-']:
        for k in ['+','-']:
            ans_str = x[0]+i+x[1]+j+x[2]+k+x[3]
            ans = eval(ans_str)
            if ans == 7:
                print(ans_str+'=7')
                sys.exit()

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

for i in range(1<<(n-1)):
    sum = int(S[0])
    eq = S[0]
    for j in range(n-1):
        if (i>>j) & 1:
            sum += int(S[j+1])
            eq += "+"
            eq += S[j+1]
        else:
            sum -= int(S[j+1])
            eq += "-"
            eq += S[j+1]
    if sum==7:
        print(eq+"=7")
        break

Solution (Python):
def get_operator(n):
    if n == -1:
        return "-"
    return "+"


def main():
    ticket_num = input()
    numbers = [int(ticket_num[i]) for i in range(len(ticket_num))]
    operator = [1, -1]
    flag = True
    for op1 in operator:
        for op2 in operator:
            for op3 in operator:
                if numbers[0] + op1 * numbers[1] + op2 * numbers[2] + op3 * numbers[3] == 7 and flag:
                    print(ticket_num[0] + get_operator(op1) + ticket_num[1] + get_operator(op2) + ticket_num[2] +
                          get_operator(op3) + ticket_num[3] + "=7")
                    flag = False


if __name__ == '__main__':
    main()

Solution (Python):
S = input()

for bit in range(2 ** 3):
    ans = int(S[0])
    for i in range(3):
        if bit & (1 << i):
            ans += int(S[i+1])
        else:
            ans -= int(S[i+1])

    if ans == 7:
        print(S[0], end='')
        for i in range(3):
            if bit & (1 << i):
                print('+' + S[i+1], end='')
            else:
                print('-' + S[i+1], end='')
        print('=7', end='')
        exit()

Solution (Python):



s = list(input())
for i in range(8):
    siki = s[0]
    for j in range(3):
        if i&(1<<j):
            siki+='+'+s[j+1]
        else:
            siki+='-'+s[j+1]
    g=int(siki[0])
    for j in range(1,6,2):
        if siki[j]=='+':
            g+=int(siki[j+1])
        else:
            g-=int(siki[j+1])
    if g==7:
        siki+="=7"
        print(*siki,sep="")
        break

Solution (Python):
s = list(input())
for i in range(8):
    siki = s[0]
    for j in range(3):
        if i&(1<<j):
            siki+='+'+s[j+1]
        else:
            siki+='-'+s[j+1]
    g=int(siki[0])
    for j in range(1,6,2):
        if siki[j]=='+':
            g+=int(siki[j+1])
        else:
            g-=int(siki[j+1])
    if g==7:
        print(*siki,sep="",end="")
        print("=7")
        break

Solution (Python):
a, b, c, d = list(input())
ll = ["+", "-"]
for x in ll:
    for y in ll:
        for z in ll:
            if eval(a+x+b+y+c+z+d) == 7:
                print(a+x+b+y+c+z+d+"=7")
                exit()

Solution (Python):
math = input()
for i in range(2**3):
  op = format(i,"03b")
  op = op.replace('1', '+').replace('0', '-')
  ans = math[0]+op[0]+math[1]+op[1]+math[2]+op[2]+math[3]
  if eval(ans) == 7:
    print(ans+"=7")
    break

Solution (Python):
import sys
num = list(map(int, list(input())))
p, m = "+", "-"
for op1 in [p, m]:
    for op2 in [p, m]:
        for op3 in [p, m]:
            x = num[0]
            if op1 == p:
                x += num[1]
            else:
                x -= num[1]
            if op2 == p:
                x += num[2]
            else:
                x -= num[2]
            if op3 == p:
                x += num[3]
            else:
                x -= num[3]

            if x == 7:
                print(
                    "{}{}{}{}{}{}{}=7".format(
                        num[0], op1, num[1], op2, num[2], op3, num[3]
                    )
                )
                sys.exit()
            else:
                pass

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 l.index(7) == 0:
    print(a, '+', b, '+', c, '+', d, '=7', sep='')
elif l.index(7) == 1:
    print(a, '+', b, '+', c, '-', d, '=7', sep='')
elif l.index(7) == 2:
    print(a, '+', b, '-', c, '+', d, '=7', sep='')
elif l.index(7) == 3:
    print(a, '+', b, '-', c, '-', d, '=7', sep='')
elif l.index(7) == 4:
    print(a, '-', b, '+', c, '+', d, '=7', sep='')
elif l.index(7) == 5:
    print(a, '-', b, '+', c, '-', d, '=7', sep='')
elif l.index(7) == 6:
    print(a, '-', b, '-', c, '+', d, '=7', sep='')
elif l.index(7) == 7:
    print(a, '-', b, '-', c, '-', d, '=7', sep='')

Solution (Python):
s=input()

for bit in range(1<<3):
    sum=int(s[0])
    op=list("+++")
    for i in range(3):
        if bit & (1<<i):
            sum+=int(s[i+1])
        else:
            sum-=int(s[i+1])
            op[i]='-'
    if sum==7:
        print(s[0]+op[0]+s[1]+op[1]+s[2]+op[2]+s[3]+"=7")
        break

Solution (Python):
number=input()
list(number)
number=list(map(int,number))
a=[]
def f(i,s):
    if i==len(number):
        return s==7
    if f(i+1,s+number[i]):
        a.append("+")
        return True  
    if f(i+1,s-number[i]):
        a.append("-")
        return True

if f(1,number[0]):
    print(str(number[0])+a[2]+str(number[1])+a[1]+str(number[2])+a[0]+str(number[3])+"=7")
else:
    print("no")

Solution (Python):
N = [int(i) for i in list(input())]
for i in range(8):
    ans = [str(N[0])]
    s = N[0]
    for b, n in enumerate(N[1:]):
        if i & (1 << b):
            s += n
            ans.append("+")
        else:
            s -= n
            ans.append("-")
        ans.append(str(n))
    if s == 7:
        ans.append("=7")
        print(''.join(ans))
        exit()

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

if A-B-C-D == 7:
    print('{}{}{}{}{}{}{}{}'.format(A, '-', B, '-', C, '-', D, '=7'))
elif A-B-C+D == 7:
    print('{}{}{}{}{}{}{}{}'.format(A, '-', B, '-', C, '+', D, '=7'))
elif A-B+C-D == 7:
    print('{}{}{}{}{}{}{}{}'.format(A, '-', B, '+', C, '-', D, '=7'))
elif A-B+C+D == 7:
    print('{}{}{}{}{}{}{}{}'.format(A, '-', B, '+', C, '+', D, '=7'))
elif A+B-C-D == 7:
    print('{}{}{}{}{}{}{}{}'.format(A, '+', B, '-', C, '-', D, '=7'))
elif A+B-C+D == 7:
    print('{}{}{}{}{}{}{}{}'.format(A, '+', B, '-', C, '+', D, '=7'))
elif A+B+C-D == 7:
    print('{}{}{}{}{}{}{}{}'.format(A, '+', B, '+', C, '-', D, '=7'))
elif A+B+C+D == 7:
    print('{}{}{}{}{}{}{}{}'.format(A, '+', B, '+', C, '+', D, '=7'))

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

for bit in range(1 << n):
  buf = s[0]
  result = 0
  for i in range(n):
    if bit & (1 << i):
      buf += "+{}".format(s[i+1])
    else:
      buf += "-{}".format(s[i+1])
  if eval(buf) == 7:
    print("{}=7".format(buf))
    break

Solution (Python):
li = [int(i) for i in input()]

for i in range(2**3):
    ans = str(li[0])
    tmp = li[0]
    for j in range(3):
        if (i>>j)&1:
            tmp += li[j+1]
            ans += '+'+str(li[j+1])
        else:
            tmp -= li[j+1]
            ans += '-'+str(li[j+1])
    if tmp == 7:
        ans += '=7'
        print(ans)
        exit()

Solution (Python):
tex = input()
num = [int(i) for i in tex]

n = 3
pos = []

for i in range(2 ** n):
    tes = num[0]
    shiki = ""
    sep = [0] * n
    for j in range(n):
        if (i >> j) & 1:
            sep[j] = 1
    for ind, su in enumerate(num):
        shiki += str(num[ind])
        if ind < len(sep):
            if sep[ind] == 1:
                tes += num[ind + 1]
                shiki += "+"
            if sep[ind] == 0:
                tes -= num[ind + 1]
                shiki += "-"
    shiki += "=7"
    if tes == 7:
        print(shiki)
        break

Solution (Python):
from itertools import product

l = list(input())
f = lambda x: '+' if x == 1 else '-'

for o in product(range(2), repeat=3):
    ret = l[0] + f(o[0]) + l[1] + f(o[1]) + l[2] + f(o[2]) + l[3]
    if eval(ret) == 7:
        print(ret + '=7')
        break

Solution (Python):
n = input()
a = [int(n[i]) for i in range(4)]

li = [(0,0,0), (0,0,1), (0,1,0), (0,1,1), (1,0,0), (1,0,1), (1,1,0), (1,1,1)]

for i in li:
    sum1 = a[0]
    for j in range(3):
        if i[j] == 0:
            sum1 += a[j+1]
        else:
            sum1 -= a[j+1]
    if sum1 == 7:
        ans = ''
        for j in range(3):
            ans += str(a[j])
            if i[j] == 0:
                ans += '+'
            else:
                ans += '-'
        ans += str(a[3]) + '=7'
        print(ans)
        exit()

Solution (Python):
def main():
  import itertools
  s=list(input())
  n=len(s)

  for pm in itertools.product("+-", repeat=3):
    tmp=""
    for i,j in zip(s,pm):
      tmp+=i+j
    else:
      tmp+=s[-1]
    if eval(tmp)==7:
      print(tmp+"=7")
      exit()
  
  
if __name__=="__main__":
  main()

Solution (Python):
def main():
  import itertools
  s=list(input())
  n=len(s)
  t=[ s[i//2] if i%2==0 else None for i in range(2*n-1)]

  for i in itertools.product("+-", repeat=3):
    k=t
    for j in [0,1,2]:
      k[2*j+1]=i[j]
    l="".join(k)
    if eval(l)==7:
      print(l+"=7")
      exit()
  
if __name__=="__main__":
  main()

Solution (Python):
abcd = input()
for i in range(1 << 3):
    total = int(abcd[0])
    ans = abcd[0]
    b = format(i, "b").zfill(3)
    
    for j in range(len(b)):
        if b[j] == "1":
            total += int(abcd[j + 1])
            ans += "+" + abcd[j + 1]
        else:
            total -= int(abcd[j + 1])
            ans += "-" + abcd[j + 1]
    
    
    if total == 7:
        ans += "=7"
        print(ans)
        break

Solution (Python):
s = input()
OPE_CNT = 3
ANS = 7

def solve(sum, cnt, ope_s):
    if cnt == OPE_CNT:
        if sum == ANS:
            print(ope_s + '=7')
            return True
        else:
            return False
    if solve(sum + int(s[cnt + 1]), cnt + 1, ope_s + '+' + s[cnt + 1]):
        return True
    if solve(sum - int(s[cnt + 1]), cnt + 1, ope_s + '-' + s[cnt + 1]):
        return True
    return False

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

Solution (Python):
lst=[int(c) for c in input()]

for i in range(8):
    s=str(lst[0])
    cnt=lst[0]
    idx=1
    while idx<4:
        res=i%2
        if res==0:
            s+='+'+str(lst[idx])
            cnt+=lst[idx]
        else:
            s+='-'+str(lst[idx])
            cnt-=lst[idx]
        i//=2
        idx+=1
    if cnt==7:
        s+='=7'
        print(s)
        break

Solution (Python):
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue


Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)


class Dijkstra:
 
    def __init__(self, rote_map, start_point, goal_point=None):
        self.rote_map = rote_map
        self.start_point = start_point
        self.goal_point = goal_point
 
    def execute(self):
        num_of_city = len(self.rote_map)
        dist = [float("inf") for _ in range(num_of_city)]
        prev = [float("inf") for _ in range(num_of_city)]
 
        dist[self.start_point] = 0
        heap_q = []
        heapq.heappush(heap_q, (0, self.start_point))
        route_count = [0 for _ in range(num_of_city)]
        route_count[self.start_point] = 1
        while len(heap_q) != 0:
            prev_cost, src = heapq.heappop(heap_q)
 
            if dist[src] < prev_cost:
                continue
 
            for dest, cost in self.rote_map[src].items():
                if cost != float("inf") and dist[dest] > dist[src] + cost:
                    dist[dest] = dist[src] + cost
                    heapq.heappush(heap_q, (dist[dest], dest))
                    prev[dest] = src
                if dist[dest] == dist[src] + cost:
                    route_count[dest] += route_count[src]
 
        if self.goal_point is not None:
            return self._get_path(self.goal_point, prev)
        else:
            return dist, route_count
 
    def _get_path(self, goal, prev):
        path = [goal]
        dest = goal
 
        while prev[dest] != float("inf"):
            path.append(prev[dest])
            dest = prev[dest]
 
        return list(reversed(path))

        
def main(): 
    s = input()
    abcd = [i for i in s]
    op = ["-","-","-"]
    for i in range(1<<3):
        for j in range(3):
            if (i>>j)&1:
                op[j] = "+"
        if eval(abcd[0]+op[0]+abcd[1]+op[1]+abcd[2]+op[2]+abcd[3]) == 7:
            print(abcd[0]+op[0]+abcd[1]+op[1]+abcd[2]+op[2]+abcd[3]+"=7")
            exit()
        op = ["-","-","-"]
if __name__ == "__main__":
    main()

Solution (Python):
s = list(map(int,input()))
n = len(s)
for i in range(2**(n-1)):
    bag = []
    for j in range(n-1):
        if ((i>>j)&1):
            bag.append(s[j])
            bag.append('+')
        else:
            bag.append(s[j])
            bag.append('-')
    bag.append(s[n-1])
    bag = list(map(str,bag))
    
    
    total = int(bag[0])
    for m,sss in enumerate(bag):
        if(sss == '+'):
            total += int(bag[m+1])
        elif(sss == '-'):
            total -= int(bag[m+1])
    if(total==7):
        print(''.join(bag)+'=7')
        exit()

Solution (Python):
ABCD = input()

for i in range(2 ** 3):
    op = format(i, '03b')
    op = op.replace('1', '+').replace('0', '-')
    formula = ABCD[0] + op[0] + ABCD[1] + op[1] + ABCD[2] + op[2] + ABCD[3]
    if eval(formula) == 7:
        print(formula + '=7')
        break

Solution (Python):
a = list(input())
i = int(a[0])
j = int(a[1])
k = int(a[2])
l = int(a[3])
if i+j+k+l == 7:
    print("%s+%s+%s+%s=7" % (i,j,k,l))
elif i+j+k-l == 7:
    print("%s+%s+%s-%s=7" % (i,j,k,l))
elif i+j-k+l == 7:
    print("%s+%s-%s+%s=7" % (i,j,k,l))
elif i+j-k-l == 7:
    print("%s+%s-%s-%s=7" % (i,j,k,l))
elif i-j+k+l == 7:
    print("%s-%s+%s+%s=7" % (i,j,k,l))
elif i-j+k-l == 7:
    print("%s-%s+%s-%s=7" % (i,j,k,l))
elif i-j-k+l == 7:
    print("%s-%s-%s+%s=7" % (i,j,k,l))
elif i-j-k-l == 7:
    print("%s-%s-%s-%s=7" % (i,j,k,l))

Solution (Python):
import sys
num = input()

for bit in range(2**(len(num)-1)):
    lis = [num[0]]
    for i in range(len(num)-1):
        
        if ((bit>>i) & 1):
            lis.append("+")
        else:
            lis.append("-")
        
        lis.append(num[i+1])
    
    ans = "".join(lis)
    if eval(ans) == 7:
        print(ans+"=7")
        sys.exit()

Solution (Python):

a, b, c, d = map(int, input())

def i_to_sign(n):
    if n > 0:
        return "+"
    else:
        return "-"

for bits in range(2**3):
    plus = [1] * 3
    for i in range(3):
        if (1 << i & bits) == 0:
            plus[i] = -1
    
    result = a + (b * plus[0]) + (c * plus[1]) + (d * plus[2])

    if result == 7:
        print("{}{}{}{}{}{}{}=7".format(
            a, i_to_sign(plus[0]),
            b, i_to_sign(plus[1]),
            c, i_to_sign(plus[2]),
            d
        ))
        exit()

Solution (Python):
ABCD = input()

A = int(ABCD[0])
B = int(ABCD[1])
C = int(ABCD[2])
D = int(ABCD[3])


def get_op(num):
  if num == -1:
    _ = '-'
  else:
    _ = '+'

  return _
  

for x in [-1,1]:
  for y in [-1,1]:
    for z in [-1,1]:
      _ = A+x*B+y*C+z*D
      if _ == 7:
        op1 = get_op(x)
        op2 = get_op(y)
        op3 = get_op(z)        
        ans = str(A)+op1+str(B)+op2+str(C)+op3+str(D)+'=7'

print(ans)

Solution (Python):
def func(i, x, a):
    global ans
    ans = a[0]
    if i == 1:
        if x == 7:
            return True
        else:
            return False

    if func(i-1, x+int(a[i-1]), a):
        ans += '+' + a[i-1]
        return True

    if func(i-1, x-int(a[i-1]), a):
        ans += '-' + a[i-1]
        return True

    else:
        return False

if __name__ == '__main__':
    a = input()
    n = len(a)
    x = int(a[0])
    if func(n, x, a):
        print(ans + '=7')
    else:
        pass

Solution (Python):
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue


Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): 
    s = input()
    abcd = [i for i in s]
    op = ["-","-","-"]
    for i in range(1<<3):
        for j in range(3):
            if (i>>j)&1:
                op[j] = "+"
        if eval(abcd[0]+op[0]+abcd[1]+op[1]+abcd[2]+op[2]+abcd[3]) == 7:
            print(abcd[0]+op[0]+abcd[1]+op[1]+abcd[2]+op[2]+abcd[3]+"=7")
            exit()
        op = ["-","-","-"]
if __name__ == "__main__":
    main()

Solution (Python):
a, b, c, d = (int(s_i) for s_i in input())
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))
else: print("{}-{}-{}-{}=7".format(a, b, c, d))

Solution (Python):
a=input()

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

Solution (Python):
a=input()
for i in range(8):
  b=bin(i)[2:]
  b="q"+"0"*(3-len(b))+b
  b=b.replace("0","-").replace("1","+")
  xv="".join([d+s for s,d in zip(a,b)])
  xv=xv[1:]
  if eval(xv)==7:
    print(xv,"=7",sep="");break

Solution (Python):
s=input()
for i in range(2**3):
  op=format(i,'03b')
  op=op.replace('1','+').replace('0','-')
  st=s[0]+op[0]+s[1]+op[1]+s[2]+op[2]+s[3]
  if eval(st)==7:
    print(st+"=7")
    break

Solution (Python):
def test():
    nums = list(map(int, list(input())))
    end = False
    for i in range(2 ** 3):
        ans = nums[0]
        res = '{}'.format(nums[0])
        for j in range(3):
            if (i >> j) & 1:
                ans += nums[j+1]
                res += '+{}'.format(nums[j+1])
            else:
                ans -= nums[j+1]
                res += '-{}'.format(nums[j+1])
        if ans == 7:
            end = True
            break
    print('{}=7'.format(res))

if __name__ == '__main__':
    test()

Solution (Python):
import sys
a = input()

for bit in range(2**3):
    p_m = ["-","-","-"]
    b = []
    for i in range(len(p_m)):
        if ((bit>>i) & 1):
            p_m[i] = "+"
        b.append(a[i] + p_m[i])
    b.append(a[3])
    c = "".join(b)
    if eval(c) == 7:
        print(c+"=7")
        sys.exit()

Solution (Python):
import sys
stdin = sys.stdin
from itertools import product

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

s = ns()

for plus in product([0,1], repeat=3):
    ans = s[0]
    a = int(s[0])
    for i, flag in enumerate(plus):
        if flag == 0:
            a = a + int(s[i+1])
            ans = ans + "+" + s[i+1]
        else:
            a = a - int(s[i+1])
            ans = ans + "-" + s[i+1]
    
    if a == 7:
        print(ans + "=7")
        break

Solution (Python):
abcd=list(input())
for i in range(2**3):
    if i//4==0:
        op1="+"
    else:
        op1="-"
    i=i%4
    if i//2==0:
        op2="+"
    else:
        op2="-"
    i=i%2
    if i==0:
        op3="+"
    else:
        op3="-"
    siki=abcd[0]+op1+abcd[1]+op2+abcd[2]+op3+abcd[3]
    if eval(siki)==7:
        siki+="=7"
        break
print(siki)

Solution (Python):
n=int(input())
a=[0]*4
for i in range(3,-1,-1):
    a[i]=n%10
    n=n//10
if a[0]+a[1]+a[2]+a[3]==7:
    print("{0}+{1}+{2}+{3}=7".format(a[0],a[1],a[2],a[3]))
elif a[0]+a[1]+a[2]-a[3]==7:
    print("{0}+{1}+{2}-{3}=7".format(a[0],a[1],a[2],a[3]))
elif a[0]+a[1]-a[2]+a[3]==7:
    print("{0}+{1}-{2}+{3}=7".format(a[0],a[1],a[2],a[3]))
elif a[0]-a[1]+a[2]+a[3]==7:
    print("{0}-{1}+{2}+{3}=7".format(a[0],a[1],a[2],a[3]))
elif a[0]+a[1]-a[2]-a[3]==7:
    print("{0}+{1}-{2}-{3}=7".format(a[0],a[1],a[2],a[3]))
elif a[0]-a[1]-a[2]+a[3]==7:
    print("{0}-{1}-{2}+{3}=7".format(a[0],a[1],a[2],a[3]))
elif a[0]-a[1]+a[2]-a[3]==7:
    print("{0}-{1}+{2}-{3}=7".format(a[0],a[1],a[2],a[3]))
else:
    print("{0}+{1}+{2}+{3}=7".format(a[0],a[1],a[2],a[3]))

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

ans = []
for i in range(2**3):
    result = int(a[0])
    for j in range(3):
        if (i >> j) & 1:
            result += int(a[j+1])
            ans.append('+')
        else:
            result -= int(a[j+1])
            ans.append('-')
    if result == 7:
        break
    else:
        ans = []

if len(ans) == 0:
    print(-1)
else:
    print(a[0]+ans[0]+a[1]+ans[1]+a[2]+ans[2]+a[3]+'=7')

Solution (Python):
inp = list(input())
a = inp[0]
b = inp[1]
c = inp[2]
d = inp[3]
for i in range(8):
    temp = format(i, '03b')
    templist = list(temp)
    if templist[0] == "0":
        op1 = "+"
    else:
        op1 = "-"
    if templist[1] == "0":
        op2 = "+"
    else:
        op2 = "-"
    if templist[2] == "0":
        op3 = "+"
    else:
        op3 = "-"
    ans = eval(a+op1+b+op2+c+op3+d)
    if ans == 7:
        print(a+op1+b+op2+c+op3+d+"=7")
        exit()

Solution (Python):
S = input()
def two(n):
    A = []
    x = n
    for i in range(3):
        A.append(x%2)
        x//=2
    return A
for i in range(2**3):
    a = S[0]
    T = two(i)
    for j in range(3):
        a+="+" if T[j] else "-"
        a+=S[j+1]
    if eval(a)==7:
        print(a+"=7")
        break

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

for bit in range(2**(n-1)):
    f = ["-"]*(n-1)
    for i in range(n-1):
        if ((bit>>i) & 1):
            f[i] = "+"
    formula = ""
    for pn,po in zip(s, f + [""]):
        formula += (pn + po)
    if eval(formula) == 7:
        print(formula + "=7")
        sys.exit()

Solution (Python):
N=input()
for i in range(2**(len(N)-1)):
    OP=["-","-","-"]
    for j in range(len(N)-1):
        if ((i>>j)&1):
            OP[3-j-1]="+"
    formula=""
    for n,op in zip(N,OP+[""]):
        formula+=n+op
    if eval(formula)==7:
        print(formula+"=7")
        break

Solution (Python):
import itertools
s = input()
a,b,c,d = s
op = ["+","-"]

for op1,op2,op3 in itertools.product(op,repeat = 3):
    ans = a + op1 + b + op2 + c + op3 + d
    if eval(ans) == 7:
        print(ans + "=7")
        break
    else:
        pass

Solution (Python):
values = [int(c) for c in input()]
for i in range(8):
  if values[0] + sum([[1, -1][(i >> j) & 1] * values[j + 1] for j in range(3)]) == 7:
    print(str(values[0]) + ''.join([['+', '-'][(i >> j) & 1] + str(values[j + 1]) for j in range(3)]) + '=7')
    break

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

for i in bitlst:
    ans = int(s[0])
    for j in range(3):
        if i[j] == "+":
            ans +=  int(s[j+1])
        else:
            ans -= int(s[j+1])

    if ans == 7:
        print(s[0]+i[0]+s[1]+i[1]+s[2]+i[2]+s[3]+"=7")
        exit()

Solution (Python):
import sys

abcd = input()

a, b, c ,d = int(abcd[0]), int(abcd[1]), int(abcd[2]), int(abcd[3])

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

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

Solution (Python):
import numpy as np
num=np.array(list(input()))

for bit in  range(1<<3):
  op=np.array(['-']*3)
  for i in range(3):
    if (bit>>i)&1:
      op[i]='+'
  formula=np.insert(num,[1,2,3],op)
  
  if eval(''.join(formula))==7:
    flag=True
    print(''.join(formula)+'=7')
    break

Solution (Python):
s = input()
for i in range(2**3):
    check = [0]*3
    op = []
    tmp = int(s[0])
    ans = s[0]
    for j in range(3):
        if (i>>j)&1:
            check[j] = 1
    for k in range(3):
        if check[k] == 1:
            op.append("+")
        else:
            op.append("-")
    for k in range(1,4):

        if op[k-1] == "+":
            tmp += int(s[k])
            ans = ans+op[k-1]
            ans = ans+s[k]
        else:
            tmp -= int(s[k])
            ans = ans+op[k-1]
            ans = ans+s[k]

    if tmp == 7:
        ans = ans + "=7"
        print(ans)
        exit()