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):
def calc(summation, step, operation):
    if step < len(line):
        
        calc(summation+line[step], step+1, operation+"+")
        
        calc(summation - line[step], step + 1, operation+"-")
    if step == len(line):
        if summation == 7:
            ans = str(line[0])+operation[0]+str(line[1])+operation[1] + \
                str(line[2])+operation[2]+str(line[3])+"=7"
            print(ans)
            exit()


line = [int(i) for i in input()]
calc(line[0], 1, "")

Solution (Python):
from itertools import product

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

for bit in product([0,1], repeat = 3):
    if bit[0] == 0:
        E = A + B
        op1 = "+"
    else:
        E = A - B
        op1 = "-"
    
    if bit[1] == 0:
        F = E + C
        op2 = "+"
    else:
        F = E - C
        op2 = "-"

    if bit[2] == 0:
        G = F + D
        op3 = "+"
    else:
        G = F - D
        op3 = "-"

    if G == 7:
        ans = str(A) + op1 + str(B) + op2 + str(C) + op3 + str(D)
        ans = ans + "=7"
        print(ans)
        break

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

Solution (Python):
abcd = input()
a, b, c, d = list(map(int, [x for x in abcd]))
A = a + b + c + d
B = a - b + c + d
C = a + b - c + d
D = a + b + c - d
E = a - b - c + d
F = a - b + c - d
G = a + b - c - d
H = a - b - c - d
if A == 7:
  ans = f"{a}+{b}+{c}+{d}=7"
elif B == 7:
  ans = f"{a}-{b}+{c}+{d}=7"
elif C == 7:
  ans = f"{a}+{b}-{c}+{d}=7"
elif D == 7:
  ans = f"{a}+{b}+{c}-{d}=7"
elif E == 7:
  ans = f"{a}-{b}-{c}+{d}=7"
elif F == 7:
  ans = f"{a}-{b}+{c}-{d}=7"
elif G == 7:
  ans = f"{a}+{b}-{c}-{d}=7"
elif H == 7:
  ans = f"{a}-{b}-{c}-{d}=7"
print(ans)

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(f"{A}+{B}+{C}+{D}=7")
elif A - B + C + D == 7:
    print(f"{A}-{B}+{C}+{D}=7")
elif A + B - C + D == 7:
    print(f"{A}+{B}-{C}+{D}=7")
elif A + B + C - D == 7:
    print(f"{A}+{B}+{C}-{D}=7")
elif A - B - C + D == 7:
    print(f"{A}-{B}-{C}+{D}=7")
elif A - B + C - D == 7:
    print(f"{A}-{B}+{C}-{D}=7")
elif A + B - C - D == 7:
    print(f"{A}+{B}-{C}-{D}=7")
elif A - B - C - D == 7:
    print(f"{A}-{B}-{C}-{D}=7")

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

cnt = len(n) - 1
for i in range(2**cnt):
  op = ['-'] * cnt
  for j in range(cnt):
    if((i>>j) & 1):
      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 = list(input())
A = [int(i) for i in A]

if sum(A) == 7:
    print("{}+{}+{}+{}=7".format(A[0],A[1],A[2],A[3]))
elif A[0]+A[1]+A[2]-A[3] == 7:
    print("{}+{}+{}-{}=7".format(A[0],A[1],A[2],A[3]))
elif A[0]+A[1]-A[2]+A[3] == 7:
    print("{}+{}-{}+{}=7".format(A[0],A[1],A[2],A[3]))
elif A[0]-A[1]+A[2]+A[3] == 7:
    print("{}-{}+{}+{}=7".format(A[0],A[1],A[2],A[3]))
elif A[0]+A[1]-A[2]-A[3] == 7:
    print("{}+{}-{}-{}=7".format(A[0],A[1],A[2],A[3]))
elif A[0]-A[1]+A[2]-A[3] == 7:
    print("{}-{}+{}-{}=7".format(A[0],A[1],A[2],A[3]))
elif A[0]-A[1]-A[2]+A[3] == 7:
    print("{}-{}-{}+{}=7".format(A[0],A[1],A[2],A[3]))
else:
    print("{}-{}-{}-{}=7".format(A[0],A[1],A[2],A[3]))

Solution (Python):
nums = input()
 
N = 3
for i in range(2**N):
    equation = ''
    for j in range(N):
        equation += nums[j]
        if ((i >> j) & 1):
            equation += '+'
        else:
            equation += '-'
    equation += nums[-1]
    if eval(equation) == 7:
        print(equation + '=7')
        exit()

Solution (Python):
def MI():
    return map(int, input().split())

def LI():
    return list(map(int, input().split()))

ABCD = list(map(int, input()))

for i in range(2**3):
    operand = []
    tmp = ["+", "-"]
    
    for j in range(3):
        if (i >> j) & 1:
            operand.append(tmp[0])
        else:
            operand.append(tmp[1])
    
    flg = ABCD[0]
    ans = str(ABCD[0]) 
    
    for k in range(3):
        if operand[k] == "+":
            flg += ABCD[k + 1]
            ans += operand[k]
            ans += str(ABCD[k + 1])
        
        else:
            flg -= ABCD[k + 1]
            ans += operand[k]
            ans += str(ABCD[k + 1])
    
    if flg == 7:
        print(ans + "=7")
        break

Solution (Python):
ticket = input()
A,B,C,D = [n for n in ticket]
for i in range(2**3):
  answer = int(ticket[0])
  op = ["-","-","-"]
  for j in range(3):
    if (i>>j)&1 == 1:
      answer += int(ticket[j+1])
      op[j] = "+"
    else:
      answer -= int(ticket[j+1])
  if answer == 7:
    result = A + op[0] + B + op[1] + C + op[2] + D + "=7"
    break
print(result)

Solution (Python):
ticket = input()
A,B,C,D = [n for n in ticket]
for i in range(2**3):
  answer = int(ticket[0])
  for j in range(3):
    if (i>>j)&1 == 1:
      answer += int(ticket[j+1])
    else:
      answer -= int(ticket[j+1])
  if answer == 7:
    op = bin(i)[2:]
    if len(op) == 1:
      op = "00"+op
    elif len(op) == 2:
      op = "0"+op
    op = op.replace("1","+").replace("0","-")
    result = A + op[2] + B + op[1] + C + op[0] + D + "=7"
    break
print(result)

Solution (Python):
from itertools import product
abcd = list(map(int, list(input())))


for ops in product(['+', '-'], repeat=3):
    temp = abcd[0]
    ans = str(abcd[0])
    for i, op in enumerate(ops):
        if op=='+':
            temp+=abcd[i+1]
            ans+='+'+str(abcd[i+1])
        else:
            temp-=abcd[i+1]
            ans+='-'+str(abcd[i+1])
    if temp==7:
        ans+='=7'
        break
print(ans)

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

for i in range(2):
    for j in range(2):
        for k in range(2):
            if i%2==0 and j%2==0 and k%2==0:
                ans = a+b+c+d
                ans_s = f"{a}+{b}+{c}+{d}"
            elif i%2==0 and j%2==0 and k%2==1:
                ans = a+b+c-d
                ans_s = f"{a}+{b}+{c}-{d}"
            elif i%2== 0 and j%2==1 and k%2==1:
                ans = a+b-c-d
                ans_s = f"{a}+{b}-{c}-{d}"
            elif i%2== 1 and j%2==1 and k%2==1:
                ans = a-b-c-d
                ans_s = f"{a}-{b}-{c}-{d}"
            elif i%2==1 and j%2==1 and k%2==0:
                ans = a-b-c+d
                ans_s = f"{a}-{b}-{c}+{d}"
            elif i%2==1 and j%2==0 and k%2==0:
                ans = a-b+c+d
                ans_s = f"{a}-{b}+{c}+{d}"
            elif i%2==1 and j%2==0 and k%2==1:
                ans = a+b-c+d
                ans_s = f"{a}+{b}-{c}+{d}"
            else:
                ans = a-b+c-d
                ans_s = f"{a}-{b}+{c}-{d}"
            
            if ans == 7:
                print(ans_s+"=7")
                exit()

Solution (Python):
N=list(map(str,input()))
ketasu=len(N)
def dfs(siki,sitei):
    if sitei == ketasu-1 :    
        if eval(siki)==7:
            print(siki+"=7")
            exit()
            return
    else:
        dfs(siki+"+"+N[sitei+1],sitei+1)
        dfs(siki+"-"+N[sitei+1],sitei+1)

dfs(N[0],0)

Solution (Python):
N=list(map(str,input()))
ketasu=len(N)
def dfs(siki,sitei):
    if sitei == ketasu-1 :    
        if eval(siki)==7:
            print(siki+"=7")
            exit()
            return
    else:
        dfs(siki+"+"+N[sitei+1],sitei+1)
        dfs(siki+"-"+N[sitei+1],sitei+1)

dfs(N[0],0)

Solution (Python):
def a(s,i):
    if i == l-1:
        if eval(s) == 7:
            print(s+"=7")
            exit()
        return
    a(s+"+"+N[i+1],i+1)
    a(s+"-"+N[i+1],i+1)

N = input()
l = len(N)
a(N[0],0)

Solution (Python):



from fractions import gcd
from itertools import combinations,permutations,accumulate 

from collections import deque,defaultdict,Counter











import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
S = input()
for bit in range(1 << 3):
    start = S[0]
    sumS = int(S[0])
    for i in range(3):
        if bit & (1 << i):
            sumS += int(S[i+1])
            start += "+"
            start += S[i+1]
        else:
            sumS -= int(S[i+1])
            start += "-"
            start += S[i+1]
    if sumS == 7:
        start += "=7"
        print(start)
        exit()

Solution (Python):
*A, = map(int, input())
a = A[0]
b = [A[1], -A[1]]
c = [A[2], -A[2]]
d = [A[3], -A[3]]

def f(n):
    if n>=0:
        return '+'+str(n)
    else:
        return str(n)

for bb in b:
    for cc in c:
        for dd in d:
            if a+bb+cc+dd == 7:
                print(a, end='')
                print(f(bb), end='')
                print(f(cc), end='')
                print(f(dd), end='')
                print('=7')
                exit()

Solution (Python):
from copy import deepcopy
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions
from operator import itemgetter
import itertools
import copy


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor



dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

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

if s[0]+s[1]+s[2]+s[3] == 7:
    print(str(s[0]), '+', str(s[1]), '+',
          str(s[2]), '+', str(s[3]), '=', 7, sep='')
    exit()
if s[0]+s[1]-s[2]+s[3] == 7:
    print(str(s[0]), '+', str(s[1]), '-', str(s[2]),
          '+', str(s[3]),  '=', 7, sep='')
    exit()
if s[0]-s[1]+s[2]+s[3] == 7:
    print(str(s[0]), '-', str(s[1]), '+', str(s[2]),
          '+', str(s[3]),  '=', 7, sep='')
    exit()
if s[0]-s[1]-s[2]+s[3] == 7:
    print(str(s[0]), '-', str(s[1]), '-', str(s[2]),
          '+', str(s[3]),  '=', 7, sep='')
    exit()
if s[0]+s[1]+s[2]-s[3] == 7:
    print(str(s[0]), '+', str(s[1]), '+', str(s[2]),
          '-', str(s[3]),  '=', 7, sep='')
    exit()
if s[0]-s[1]-s[2]-s[3] == 7:
    print(str(s[0]), '-', str(s[1]), '-', str(s[2]),
          '-', str(s[3]),  '=', 7, sep='')
    exit()
if s[0]-s[1]+s[2]-s[3] == 7:
    print(str(s[0]), '-', str(s[1]), '+', str(s[2]),
          '-', str(s[3]),  '=', 7, sep='')
    exit()
if s[0]+s[1]-s[2]-s[3] == 7:
    print(str(s[0]), '+', str(s[1]), '-', str(s[2]),
          '-', str(s[3]),  '=', 7, sep='')
    exit()

Solution (Python):


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

s=list(SI())
a=int(s[0])
ops=["+","-"]
for i in product(ops,repeat=3):
    ans=a
    for j in range(3):
        if i[j]=="+":
            ans+=int(s[j+1])
        else:
            ans-=int(s[j+1])
    if ans==7:
        u=i
        
        break
print(s[0],end="")
for i in range(3):
    print(u[i]+s[i+1],end="")
print("=7")

Solution (Python):
import sys
n=int(input())
a=(n-n%1000)//1000
b=(n%1000-n%100)//100
c=(n%100-n%10)//10
d=(n%10)
k=[a,b,c,d]
for i in range(8):
  s='{0:03b}'.format(i)
  ans=a
  for j in range(3):
    if s[j]=='1':
      ans+=k[j+1]
    else:
      ans-=k[j+1]
  if ans==7:
    ans=[str(a)]
    for j in range(3):
      if s[j]=='1':
        ans.append('+')
      else:
        ans.append('-')
      ans.append(str(k[j+1]))
    ans.append('=')
    ans.append('7')
    print(''.join(ans))
    sys.exit()

Solution (Python):
import itertools

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

for bb, cc, dd in itertools.product([1, -1], repeat=3):
    if a + bb*b + cc*c + dd*d == 7:
        ans = ''
        ans += str(a)
        if bb == 1:
            ans += '+'
        else:
            ans += '-'
        ans += str(b)
        if cc == 1:
            ans += '+'
        else:
            ans += '-'
        ans += str(c)
        if dd == 1:
            ans += '+'
        else:
            ans += '-'
        ans += str(d)
        ans += '=7'
        print(ans)
        exit()

Solution (Python):
from itertools import product
A,B,C,D = list(input().strip())
for x in product(("+","-"),repeat=3):
    if eval(A+x[0]+B+x[1]+C+x[2]+D)==7:
        print(A+x[0]+B+x[1]+C+x[2]+D+"=7")
        break

Solution (Python):
import sys
input = sys.stdin.readline
from collections import *

A, B, C, D = map(int, list(input()[:-1]))
l = [B, C, D]

for S in range(8):
    now = A
    ans = [str(A)]
    
    for i in range(3):
        if (S>>i)&1:
            now += l[i]
            ans.append('+')
        else:
            now -= l[i]
            ans.append('-')
        
        ans.append(str(l[i]))
    
    ans.append('=7')
    
    if now==7:
        print(''.join(ans))
        exit()

Solution (Python):
import itertools
n = input()
for v in itertools.product(["+","-"], repeat=3):
    x = n[0] + v[0] + n[1] + v[1] + n[2] + v[2] + n[3]
    if eval(x) == 7: break
print(x + "=7")

Solution (Python):


s = input()
nums = list(map(int, list(s)))
operators = ['+', '+', '+']

def exec(nums, operators):
    num = 0
    num += nums[0]        
    i = 1
    for op in operators:
        if op == '+':
            num += nums[i]
        elif op == '-':
            num -= nums[i]

        i += 1

    return num

def output(nums, operators):
    string = ''
    i = 0
    for n in nums:
        string += str(n)
        if i < len(operators):
            string += operators[i]

        i += 1

    string += '=7'
    print(string)


length = len(operators)

for i in range(2 ** length):
    _operators = operators
    for j in range(length):
        if ((i >> j) & 1):
            _operators[length - 1 - j] = '+'
        else: 
            _operators[length - 1 - j] = '-'

    if exec(nums, _operators) == 7:
        output(nums, _operators)
        break

Solution (Python):
N = int(input())
nums = []

for i in range(4):
    tmp = N % 10
    nums.append(tmp)
    N = N // 10

nums = nums[::-1]

for i in range(8):
    ans = nums[0]
    
    judge = []
    
    for j in range(3):
        bitts = (i >> j) & 1
        if (bitts):
            ans += nums[j + 1]
            judge.append('+')
            
        else:
            ans -= nums[j + 1]
            judge.append('-')
    
    if (ans == 7):
        siki = ''
        
        for i in range(3):
            siki += str(nums[i])
            siki += judge[i]
        
        siki += (str(nums[3]) + '=7')
        
        print(siki)
        break

Solution (Python):
S = list(input())
for i in range(2 ** 3):
  op = ['+'] * 3
  for j in range(3):
    if ((i >> j) & 1):
      op[j] = '-'
  ans = ''
  for s, p in zip(S, op+['']):
    ans += (s + p)
  if eval(ans) == 7:
    print(ans + '=7')
    break

Solution (Python):
def main():

  
  S = list(map(int, list(input())))

  for bit in range(1 << len(S)-1):
    ans = S[0]
    list_ = [str(S[0])]
    for i in range(len(S)-1):
      mask = (1 << i)
      if bit & mask:
        ans += S[i+1]
        list_.append('+')
        list_.append(str(S[i+1]))
      else:
        ans -= S[i+1]
        list_.append('-')
        list_.append(str(S[i+1]))
      

    if (ans == 7):
      list_.append('=7')
      print("".join(list_))
      return


if(__name__ == '__main__'):
  main()

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

for i in range(2**3):
    op = bin(i)[2:].zfill(3).replace("0", "-").replace("1", "+")
    equation = a + op[0] + b + op[1] + c + op[2] + d
    if eval(equation) == 7:
        print(equation + '=7')
        break

Solution (Python):
def a(s,i):
    if i == l-1:
        if eval(s)==7:
            print(s+"=7")
            exit()
        return
    a(s+"+"+N[i+1],i+1)
    a(s+"-"+N[i+1],i+1)

N = input()
l = len(N)

a(N[0],0)

Solution (Python):
nums = list(map(int, list(input())))
size = len(nums)-1
for b in range(2**size):
    total = nums[0]
    outputs = [str(nums[0])]
    for i in range(size):
        if ( b & (1 << i) ):
            total = total + nums[1+i]
            outputs.append("+"+str(nums[1+i]))
        else:
            total = total - nums[1+i]
            outputs.append("-"+str(nums[1+i]))
    if(total == 7):
        outputs.append("=7")
        print(''.join(outputs))
        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,q in zip(n,op+[""]):
        formula += (p+q)
    if eval(formula) == 7:
        print(formula + "=7")
        break

Solution (Python):
nums = input()

N = 3
for i in range(2**N):
    equation = ''
    for j in range(N):
        equation += nums[j]
        if ((i >> j) & 1):
            equation += '+'
        else:
            equation += '-'
    equation += nums[-1]
    if eval(equation) == 7:
        print(equation + '=7')
        exit()

Solution (Python):
import operator

vals = input()
nums = list(map(int, tuple(vals)))

def dump(a,b,c):
    if a == operator.add:
        a = '+'
    else:
        a = '-'
    if b == operator.add:
        b = '+'
    else:
        b = '-'
    if c == operator.add:
        c = '+'
    else:
        c = '-'
    print(vals[0] + a + vals[1] + b + vals[2] + c + vals[3] + '=7')

for a in (operator.add, operator.sub):
    for b in (operator.add, operator.sub):
        for c in (operator.add, operator.sub):
            if c(b(a(nums[0], nums[1]), nums[2]), nums[3]) == 7:
                dump(a, b, c)
                exit(0)

Solution (Python):
s = list(map(int,list(input())))
op_num = len(s)-1
for i in range(2**op_num):
  ans = ['-']*op_num
  total = s[0]
  for j in range(op_num):
    if (i>>j) & 1:
      total += s[j+1]
      ans[j]='+'
    else:
      total -= s[j+1]
  if total == 7:
    print(str(s[0])+ans[0]+str(s[1])+ans[1]+str(s[2])+ans[2]+str(s[3])+'=7')
    exit()

Solution (Python):
def main():
    A, B, C, D = input()
    for i in range(2**3):
        op = ['+', '+', '+']
        for j in range(len(op)):
            if (i >> j) & 1:
                op[j] = '-'
        if eval(A + op[0] + B + op[1] + C + op[2] + D) == 7:
            print(A + op[0] + B + op[1] + C + op[2] + D + '=7')
            break
if __name__  == '__main__':
    main()

Solution (Python):
import sys
readline = sys.stdin.readline

A,B,C,D = readline().rstrip()

import itertools
for cal in itertools.product(["+","-"],repeat = 3):
  f = A + cal[0] + B + cal[1] + C + cal[2] + D
  if eval(f) == 7:
    print(f + "=7")
    break

Solution (Python):
import sys
readline = sys.stdin.readline

A,B,C,D = readline().rstrip()

for i in range(2 ** 3):
  cal = bin(i)[2:].zfill(3).replace("0","-").replace("1","+")
  f = A + cal[0] + B + cal[1] + C + cal[2] + D
  if eval(f) == 7:
    print(f + "=7")
    break

Solution (Python):
def main():
  a, b, c, d = list(input())
  sign = "+-"
  for i in range(2):
    for j in range(2):
      for k in range(2):
        if eval(a+sign[i]+b+sign[j]+c+sign[k]+d)==7:
          print(str(a+sign[i]+b+sign[j]+c+sign[k]+d)+"=7")
          exit()
if __name__ == "__main__":
  main()

Solution (Python):
lst = [int(a) for a in input()]
for bit in range(1 << len(lst)):
    sum = 0
    op_lst = []
    for i in range(len(lst)):
        if bit & (1 << i):
            sum += lst[i]
            op_lst.append('+')
        else:
            sum -= lst[i]
            op_lst.append('-')
    if sum == 7:
        print(lst[0], op_lst[1], lst[1], op_lst[2], lst[2], op_lst[3], lst[3], '=7', sep='')
        break

Solution (Python):
def dfs(i, f, sum):
  if i == 3:
    if sum == 7:
      print(f + '=7')
      exit()
      
  else:
    dfs(i+1, f + '-' + n[i+1], sum-int(n[i+1]))
    dfs(i+1, f + '+' + n[i+1], sum+int(n[i+1]))
    
n = input()
dfs(0, n[0], int(n[0]))

Solution (Python):
ABCD = input()

def dfs(i, f, sum):
    if i==3:
        if sum==7:
            print(f + '=7')
            exit()
    else:
        dfs(i+1, f + "-" + ABCD[i+1], sum - int(ABCD[i+1]))
        dfs(i+1, f + "+" + ABCD[i+1], sum + int(ABCD[i+1]))

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

Solution (Python):
def main():
    A, B, C, D = input()
    for i in range(2**3):
        op = ['+', '+', '+']
        for j in range(len(op)):
            if (i >> j) & 1:
                op[j] = '-'
        if eval(A + op[0] + B + op[1] + C + op[2] + D) == 7:
            print(A + op[0] + B + op[1] + C + op[2] + D + '=7')
            break
if __name__  == '__main__':
    main()

Solution (Python):
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

S = list(s())
A = [int(S[i]) for i in range(4)]
for bit in range(1<<3):
    B = [(bit>>i)&1 for i in range(3)]
    C = []
    ans = A[0]
    for j in range(3):
        if B[j] == 0:
            ans += A[j+1]
            C.append('+')
        else:
            ans -= A[j+1]
            C.append('-')
    if ans == 7:
        print(''.join(str(A[0])+C[0]+str(A[1])+C[1]+str(A[2])+C[2]+str(A[3])+'=7'))
        exit()

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

plus_minus=["+","-"]
for i in range(len(N)-2):
    a=[]
    for j in plus_minus:
        a.append(j+"+")
        a.append(j+"-")
    plus_minus=a

for i in plus_minus:
    sign=list(i)
    sumation=int(N[0])
    for j in range(len(N)-1):
        if(sign[j]=="+"):
            sumation+=int(N[j+1])
        elif(sign[j]=="-"):
            sumation-=int(N[j+1])
        else:
            print("sdfds")
    if(sumation==7):
        answer_sign=i
        break
dis=""
for i in range(len(answer_sign)):
    dis+=N[i]
    dis+=answer_sign[i]
dis+=N[-1]+"=7"
print(dis)

Solution (Python):
import sys
a,b,c,d = input()
for i in ["+","-"]:
  for j in ["+","-"]:
    for k in ["+","-"]:
      if eval(a+i+b+j+c+k+d) == 7:
        print(a+i+b+j+c+k+d+"=7")
        sys.exit()

Solution (Python):
import sys
a,b,c,d = input()
for i in ["+","-"]:
    for j in ["+","-"]:
        for k in ["+","-"]:
                if eval(a+i+b+j+c+k+d) == 7:
                    print(a+i+b+j+c+k+d+ "=7")
                    sys.exit()

Solution (Python):
tmp = input()
x = []
for i in range(4):
    x.append(int(tmp[i]))

for i in range(8):
    s = x[0]
    op = []
    for j in range(3):
        if i >> j & 1:
            s += x[j+1]
            op.append("+")
        else:
            s -= x[j+1]
            op.append("-")
    if s == 7:
        ans = tmp[0] + op[0] + tmp[1] + op[1] + tmp[2] + op[2] + tmp[3] + "=7"
        break
print(ans)

Solution (Python):
a, b, c, d = list(input())
for q in range(1, 3):
    ao = ("+" if q % 2 else "-")
    for w in range(1, 3):
        bo = ("+" if w % 2 else "-")
        for e in range(1, 3):
            if eval(a + ao + b + bo + c + ("+" if e % 2 else "-") + d) == 7:
                print(a + ao + b + bo + c + ("+" if e%2else"-") + d + "=7")
                exit(0)

Solution (Python):
s = int(input())  
a = s // 1000      
b = s // 100 % 10  
c = s // 10 % 10   
d = s % 10         

def p_mark(j):      
    if j % 2 == 0:  
        return '+'  
    else:  
        return '-'  

for i in range(2 ** 3):  
    j = i  
    p = a  

    x = p_mark(j)  

    if x == '+': 
        p += b  
    else:  
        p -= b  

    j = j // 2  

    y = p_mark(j)  

    if y == '+': 
        p += c  
    else:  
        p -= c  

    j = j // 2  

    z = p_mark(j)  

    if z == '+':
        p += d  
    else:  
        p -= d  

    if p == 7: 
        print(str(a) + x + str(b) + y + str(c) + z + str(d) + '=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] = "+"  
  formula = ""
  for z_n, z_op in zip(n,op + [""]):
    formula += (str(z_n) + z_op)
  if eval(formula) == 7:
    print(formula + "=7")
    break

Solution (Python):
ABCD = input()


def dfs(total=0, level=0, ans=0):
    level += 1
    if level >= 4:
        if total == 7:
            return ans
        return -1
    plus_ans = dfs(total + int(ABCD[level]), level, ans + (1 << (level - 1)))
    if plus_ans >= 0:
        return plus_ans
    minus_ans = dfs(total - int(ABCD[level]), level, ans)
    if minus_ans:
        return minus_ans
    return -1


ans = dfs(int(ABCD[0]), 0, 0)
op1 = "+" if ans & 1 != 0 else "-"
op2 = "+" if ans & (1 << 1) != 0 else "-"
op3 = "+" if ans & (1 << 2) != 0 else "-"
print(ABCD[0] + op1 + ABCD[1] + op2 + ABCD[2] + op3 + ABCD[3] + "=7")

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

Solution (Python):
from itertools import product
a=list(input())

for b in product(["+","-"],repeat=3):
  if(eval(a[0]+b[0]+a[1]+b[1]+a[2]+b[2]+a[3])==7):
    print(str(a[0]+b[0]+a[1]+b[1]+a[2]+b[2]+a[3]+"=7"))
    break

Solution (Python):

s = input()
l = len(s)-1

for i in range(1 << l):
    op = [s[0], '', s[1], '', s[2], '', s[3]]
    for j in range(l):
        if ((i >> j) & 1) == 1:
            op[2*j+1] = '+'
        else:
            op[2*j+1] = '-'
    if eval(''.join(op)) == 7:
        print(''.join(op) + '=7')
        break

Solution (Python):


S = list(map(int, list(input())))

for bit in range(2**3):
    formula_sum = S[0]
    formula = str(S[0])
    for shift in range(3):
        
        if (bit >> shift)&1:
            formula_sum += S[shift+1]
            formula += '+{}'.format(S[shift+1])
        else:
            formula_sum -= S[shift+1]
            formula += '-{}'.format(S[shift+1])
    
    if formula_sum == 7:
        print(formula+'=7')
        exit(0)

Solution (Python):
A, *BCD = map(int, input())
for bit in range(1 << 3):
    f = [A]
    s = A
    for i, n in enumerate(BCD):
        if bit >> i & 1:
            f += ['+', n]
            s += n
        else:
            f += ['-', n]
            s -= n
    if s == 7:
        f += ['=7']
        print(''.join(map(str, f)))
        break

Solution (Python):
n = [int(c) for c in input()]
for i in range(2 ** 3):
    os = format(i, "03b").replace("1", "+").replace("0", "-")
    temp = n[0]
    for i, c in enumerate(os):
        num = n[i + 1]
        temp += num if c == "+" else -num
    if temp == 7:
        ans = "{}{}{}{}{}{}{}=7".format(n[0], os[0], n[1], os[1], n[2], os[2], n[3])
        break
print(ans)

Solution (Python):
n = [int(c) for c in input()]
template_list = [
    "{}+{}+{}+{}",
    "{}+{}+{}-{}",
    "{}+{}-{}+{}",
    "{}+{}-{}-{}",
    "{}-{}+{}+{}",
    "{}-{}+{}-{}",
    "{}-{}-{}+{}",
    "{}-{}-{}-{}",
]
for template in template_list:
    temp = template.format(*n)
    if eval(temp) == 7:
        ans = "{}=7".format(temp)
        break
print(ans)

Solution (Python):

s = input()
l = [int(i) for i in s]
for i in range(2**3):
    ans = l[0]
    siki = s[0]
    for j in range(3):
        if i>>j & 1:
            ans += l[j+1]
            siki += "+"+s[j+1]
        else:
            ans -= l[j+1]
            siki += "-"+s[j+1]
    if ans == 7:
        print(siki+"=7")
        exit()

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

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

Solution (Python):
a,b,c,d=[int(s) for s in list(str(input()))]
x=(a+b+c+d-7)/2
op=["+","+","+"]
for i in range(3):
    if [b,c,d][i]==x:
        op[i]="-"
        break
    elif [b,c,d][i]==b+c+d-x:
        op=["-","-","+","-","-"][2-i:5-i]
        break
print(str(a)+op[0]+str(b)+op[1]+str(c)+op[2]+str(d)+"=7")

Solution (Python):
a,b,c,d=[int(s) for s in list(str(input()))]
x=(a+b+c+d-7)/2
op=["+","+","+"]
for i in range(3):
    if [b,c,d][i]==x:
        op[i]="-"
        break
    elif [b,c,d][i]==b+c+d-x:
        op=["-","-","-"] 
        op[i]="+"
        break
print(str(a)+op[0]+str(b)+op[1]+str(c)+op[2]+str(d)+"=7")