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 compute(state,s):
	value = int(s[0])
	for i,e in enumerate(state):
		if e == '0':
			value -= int(s[i+1])
		else:
			value += int(s[i+1])
	if value == 7:
		return True
	else:
		return False

def output(state,s):
	string = ''
	for i in range(3):
		string += s[i]
		if state[i] == '0':
			string += '-'
		else:
			string += '+'
	string += s[-1]
	string += '=7'
	return string


for i in range(2**3):
	state = format(i,'03b')
	if compute(state,s):
		print(output(state,s))
		exit()

Solution (Python):
abcd = input()
for i in range(8):
    bit = format(i,"03b")
    ans = int(abcd[0])
    for j in range(3):
        if bit[j] == "1":
            ans += int(abcd[j+1])
        else:
            ans -= int(abcd[j+1])
    if ans == 7:
        Ans = bit
        break
temp = abcd[0]

for i in range(3):
    if Ans[i] == "1":
        temp += "+"+abcd[i+1]
    else:
        temp += "-"+abcd[i+1]
temp += "=7"
print(temp)

Solution (Python):
a = input()
for i in (1, -1):
    for j in (1, -1):
        for k in (1, -1):
            if int(a[0])+i*int(a[1])+j*int(a[2])+k*int(a[3]) == 7:
                if i == 1:
                    b = '+'+str(i*int(a[1]))
                else:
                    b = str(i*int(a[1]))
                if j == 1:
                    c = '+'+str(j*int(a[2]))
                else:
                    c = str(j*int(a[2]))
                if k == 1:
                    d = '+'+str(k*int(a[3]))
                else:
                    d = str(k*int(a[3]))
                print(a[0]+b+c+d+'=7')
                exit()

Solution (Python):
s = input()

for i in range(2 ** (len(s) - 1)):
    fml = ''
    for j in range(len(s) - 1):
        fml += s[j]
        fml += '+-'[int('{:0>10b}'.format(i)[::-1][j]) & 1]
    fml += s[-1]

    if eval(fml) == 7:
        fml += '=7'
        break
        
print(fml)

Solution (Python):
def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    nums = list(map(lambda x: int(x), inputs[0]))
    OPS = ["+", "-"]
    for temp_op1 in OPS:
        for temp_op2 in OPS:
            for temp_op3 in OPS:
                sum = nums[0]
                if temp_op1 == "+":
                    sum += nums[1]
                else:
                    sum -= nums[1]

                if temp_op2 == "+":
                    sum += nums[2]
                else:
                    sum -= nums[2]

                if temp_op3 == "+":
                    sum += nums[3]
                else:
                    sum -= nums[3]

                if sum == 7:
                    return "%d%s%d%s%d%s%d=7" % (
                        nums[0],
                        temp_op1,
                        nums[1],
                        temp_op2,
                        nums[2],
                        temp_op3,
                        nums[3],
                    )
    return ""


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)

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

    m = [str(k) for k in n]
    siki = m[0] + op[0] + m[1] + op[1] + m[2] + op[2] + m[3]
    if eval(siki) == 7:
        print(siki+"=7")
        exit()

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

pattern1 = A + B + C + D
pattern2 = A + B + C - D
pattern3 = A + B - C + D
pattern4 = A + B - C - D
pattern5 = A - B - C + D
pattern6 = A - B - C - D
pattern7 = A - B + C + D
pattern8 = A - B + C - D

if pattern1 == 7:
    print(str(A)+'+'+str(B)+'+'+str(C)+'+'+str(D)+'='+str(pattern1))
    exit()

if pattern2 == 7:
    print(str(A)+'+'+str(B)+'+'+str(C)+'-'+str(D)+'='+str(pattern2))
    exit()

if pattern3 == 7:
    print(str(A)+'+'+str(B)+'-'+str(C)+'+'+str(D)+'='+str(pattern3))
    exit()

if pattern4 == 7:
    print(str(A)+'+'+str(B)+'-'+str(C)+'-'+str(D)+'='+str(pattern4))
    exit()

if pattern5 == 7:
    print(str(A)+'-'+str(B)+'-'+str(C)+'+'+str(D)+'='+str(pattern5))
    exit()

if pattern6 == 7:
    print(str(A)+'-'+str(B)+'-'+str(C)+'-'+str(D)+'='+str(pattern6))
    exit()

if pattern7 == 7:
    print(str(A)+'-'+str(B)+'+'+str(C)+'+'+str(D)+'='+str(pattern7))
    exit()

if pattern8 == 7:
    print(str(A)+'-'+str(B)+'+'+str(C)+'-'+str(D)+'='+str(pattern8))
    exit()

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

for op1 in "+-":
  for op2 in "+-":
    for op3 in "+-":
      ab = a + b if op1 == "+" else a - b
      abc = ab + c if op2 == "+" else ab - c
      abcd = abc + d if op3 == "+" else abc - d
      if abcd == 7:
        print(str(a) + op1 + str(b) + op2 + str(c) + op3 + str(d) + "=7")
        exit()

Solution (Python):
import sys
def calc(a,d):
    K=list(format(d,'04b'))
    ans=0
    t=[]
    for i in range(4):
        if K[i]=='0':
            ans+=a[i]
            t.append('+')
        else:
            ans-=a[i]
            t.append('-')
    return ans,t
s=list(input())
for i in range(4):
    s[i]=int(s[i])
for i in range(1<<3+1):
    r,f=calc(s,i)
    if r==7:
        print(str(s[0])+f[1]+str(s[1])+f[2]+str(s[2])+f[3]+str(s[3])+'=7')
        sys.exit()

Solution (Python):

import math

def main():
    a, b, c, d = list(map(int, list(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))
    elif a - b - c - d == 7:
        print('{}-{}-{}-{}=7'.format(a, b, c, d))


if __name__ == '__main__':
    main()

Solution (Python):

import types



abcd = input()
n = len(abcd) - 1 


for i in range( 2**n ):
    op = n * ["-"]

    
    
    for j in range(n):
        if ( i >> j ) & 1:
            op[n-1 -j] = "+"
            
    formula = ""
    for p_n, p_o in zip(abcd, op+[""]):
        formula += (p_n + p_o)

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

Solution (Python):
S0=input()

for i in range(1<<3):
  S=S0
  for j in range(3):
    if ((i>>j)&1)==1:
      S=S[:3-j]+'+'+S[3-j:]
    else:
      S=S[:3-j]+'-'+S[3-j:]
  if eval(S)==7:
    print(S+'=7')
    exit()

Solution (Python):
s=input()
a,b,c,d=list(map(int,s))
for ope1 in [-1,1]:
    for ope2 in [-1,1]:
        for ope3 in [-1,1]:
            if a+ b*ope1 + c*ope2 + d*ope3 == 7:
                print(str(a)+("+" if ope1==1 else "-")+str(b)+("+" if ope2==1 else "-")+str(c)+("+" if ope3==1 else "-")+str(d)+"=7")
                exit()

Solution (Python):
n=str(input())
flag=0
for iii in range(8):
  bincalc='{:03b}'.format(iii)
  siki=n[0]
  for jjj in range(3):
    if bincalc[jjj]=="0":
      siki+="+"+n[jjj+1]
    else:
      siki+="-"+n[jjj+1]
  if eval(siki)==7:
    print(siki+"=7")
    break

Solution (Python):
import sys

S = input()
c = 0


op = len(S) - 1  

for i in range(2 ** op):
  T = ""
  for j in range(op):
    T += S[j]
    if ((i >> j) & 1):
      T += "+"
    else:
      T += "-"
  T += S[op]
  if eval(T) == 7:
    print(T+"=7")
    sys.exit()

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

op_choice = ["+", "-"]

for op1 in op_choice:
    for op2 in op_choice:
        for op3 in op_choice:
            check = a + op1 + b + op2 + c + op3 + d
            if eval(check) == 7:
                print(check + "=7")
                exit()

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

abcd = int(input())
for i in range(int(4-math.log10(abcd))):
    abcd = '0'+str(abcd)
a, b, c, d = str(abcd)
a = int(a);b = int(b);c = int(c);d = int(d)
if a+b+c+d == 7:
    a = str(a);b = str(b);c = str(c);d = str(d)
    ans = a+'+'+b+'+'+c+'+'+d+'=7'
elif a+b+c-d == 7:
    a = str(a);b = str(b);c = str(c);d = str(d)
    ans = a+'+'+b+'+'+c+'-'+d+'=7'
elif a+b-c-d == 7:
    a = str(a);b = str(b);c = str(c);d = str(d)
    ans = a+'+'+b+'-'+c+'-'+d+'=7'
elif a+b-c+d == 7:
    a = str(a);b = str(b);c = str(c);d = str(d)
    ans = a+'+'+b+'-'+c+'+'+d+'=7'
elif a-b+c+d == 7:
    a = str(a);b = str(b);c = str(c);d = str(d)
    ans = a+'-'+b+'+'+c+'+'+d+'=7'
elif a-b+c-d == 7:
    a = str(a);b = str(b);c = str(c);d = str(d)
    ans = a+'-'+b+'+'+c+'-'+d+'=7'
elif a-b-c+d == 7:
    a = str(a);b = str(b);c = str(c);d = str(d)
    ans = a+'-'+b+'-'+c+'+'+d+'=7'
else:
    a = str(a);b = str(b);c = str(c);d = str(d)
    ans = a+'-'+b+'-'+c+'-'+d+'=7'
print(ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

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

def main():
  l=list(S())

  for i in range(2):
    for j in range(2):
      for k in range(2):
        a=b=c=''
        if i==0:
          a='+'
        else:
          a='-'
        if j==0:
          b='+'
        else:
          b='-'
        if k==0:
          c='+'
        else:
          c='-'
        x=l[0]+a+l[1]+b+l[2]+c+l[3]
        ans=eval(x)

        if ans==7:
          return x+'=7'

print(main())

Solution (Python):
numbers=list(map(int,list(input())))
ansLst=[]
def count(i,opes,sum):
    if i == 4:
        if sum == 7:
            ansLst.append(str(numbers[0])+opes[0]+str(numbers[1])+opes[1]+str(numbers[2])+opes[2]+str(numbers[3])+"=7")
    else:
        count(i+1,opes+["+"],sum+numbers[i])
        count(i+1,opes+["-"],sum-numbers[i])
count(1,[],numbers[0])
print(ansLst[0])

Solution (Python):
s = input()

for i in range(8):
	if i % 2 == 0:
		ope1 = "+"
	else:
		ope1 = "-"
	i //= 2
	if i % 2 == 0:
		ope2 = "+"
	else:
		ope2 = "-"
	i //= 2
	if i % 2 == 0:
		ope3 = "+"
	else:
		ope3 = "-"
	
	ans = s[0]+ope1+s[1]+ope2+s[2]+ope3+s[3]

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

Solution (Python):
s = input()

for i in {"+","-"}:
    for j in {"+","-"}:
        for k in {"+","-"}:
            eq = s[0]+i+s[1]+j+s[2]+k+s[3]
            if eval(eq) == 7:
                print(eq + "=7")
                exit()

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

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

for i in range(2**3):
    sum = A
    ans = str(A)

    op1 = (i >> 2) & 1
    if op1 == 1:
        sum += B
        ans += '+'+str(B)
    else:
        sum -= B
        ans += '-'+str(B)

    op2 = (i >> 1) & 1
    if op2 == 1:
        sum += C
        ans += '+'+str(C)
    else:
        sum -= C
        ans += '-'+str(C)

    op3 = i & 1
    if op3 == 1:
        sum += D
        ans += '+'+str(D)
    else:
        sum -= D
        ans += '-'+str(D)

    if sum == 7:
        print(ans + '=7')
        exit()

Solution (Python):
ABCDpre = input()
ABCD = [i for i in ABCDpre]
op = ["-","-","-"]
for i in range(1 << 3):
    for j in range(3):
        if ((i >> j) & 1) == 1:
            op[j] = "+"
    if eval(ABCD[0]+op[0]+ABCD[1]+op[1]+ABCD[2]+op[2]+ABCD[3]) == 7.0:
        print(ABCD[0]+op[0]+ABCD[1]+op[1]+ABCD[2]+op[2]+ABCD[3]+"=7")
        exit()
    op = ["-","-","-"]

Solution (Python):
ABCD = list(input())
OP = (('+', '-'), ('+', '-'), ('+', '-'))
N = len(OP)
ans = 0

for i in range(2 ** N):
    op123 = ['+'] * 3
    for j in range(N):
        if ((i >> j) & 1):
            op123[j] = OP[j][1]
    ans = ABCD[0]+op123[0]+ABCD[1]+op123[1]+ABCD[2]+op123[2]+ABCD[3]
    if eval(ans) == 7:
        ans += '=7'
        break

print(ans)

Solution (Python):
n = [int(x) for x in input()]
o = len(n) - 1

op = []
for i in range(2**o):
    op = ["-", "-", "-"]
    for j in range(o):
        if (i >> j) & 1:
            op[o - 1 - j] = "+"
    
    sum = n[0]
    for m, s in zip(n[1:], op):
        if s == "+":
            sum += m
        else:
            sum -= m

    if sum == 7:
        break

ns = [str(x) for x in n]
res = ns[0]
for x,y in zip(op, ns[1:]):
    res += x + y

print(res + "=7")

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

for op1 in ["+", "-"]:
    for op2 in ["+", "-"]:
        for op3 in ["+", "-"]:
            sum_ = a
            if op1 == "+":
                sum_ += b
            else:
                sum_ -= b
            if op2 == "+":
                sum_ += c
            else:
                sum_ -= c
            if op3 == "+":
                sum_ += d
            else:
                sum_ -= d
            if sum_ == 7:
                ans = "{}{}{}{}{}{}{}=7".format(a, op1, b, op2, c, op3, d)
        if sum_ == 7:
            break
    if sum_ == 7:
        break
print(ans)

Solution (Python):
nums = input()

for i in range(8):
    sum = int(nums[0])
    S = nums[0]
    for j in range(3):
        if ((i>>j) & 1):
            sum += int(nums[j+1])
            S += '+' + nums[j+1]
        else:
            sum -= int(nums[j+1])
            S += '-' + nums[j+1]
    if sum == 7:
        print(S+'=7')
        break

Solution (Python):
ABCD = input()

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

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

Solution (Python):
abcd = input()
n = 3

for i in range(2**n):
    num = []
    bi = format(i, '03b')
    for j in range(n):
        num.append(abcd[j])
        if bi[j] == '0':
            num.append('+')
        else:
            num.append('-')
    num.append(abcd[-1])
    calc = ''.join(num)
    if eval(calc) == 7:
        break

print(str(calc)+'=7')

Solution (Python):
from sys import stdin
s = stdin.readline().rstrip()
A, B, C, D = int(s[0]), int(s[1]), int(s[2]), int(s[3])
if A + B + C + D == 7:
    print('{}+{}+{}+{}=7'.format(A, B, C, D))
    exit()
elif A + B + C - D == 7:
    print('{}+{}+{}-{}=7'.format(A, B, C, D))
    exit()
elif A + B - C + D == 7:
    print('{}+{}-{}+{}=7'.format(A, B, C, D))
    exit()
elif A + B - C - D == 7:
    print('{}+{}-{}-{}=7'.format(A, B, C, D))
    exit()
elif A - B - C + D == 7:
    print('{}-{}-{}+{}=7'.format(A, B, C, D))
    exit()
elif A - B - C - D == 7:
    print('{}-{}-{}-{}=7'.format(A, B, C, D))
    exit()
elif A - B + C + D == 7:
    print('{}-{}+{}+{}=7'.format(A, B, C, D))
    exit()
elif A - B + C - D == 7:
    print('{}-{}+{}-{}=7'.format(A, B, C, D))
    exit()

Solution (Python):
import itertools
p=list(input())
s=[int(x) for x in p]
for x in itertools.product(['+','-'],repeat=3):
	t=s[0]
	for i in range(3):
		t=t+s[i+1] if x[i]=='+' else t-s[i+1]
	if t==7:
		ans=x
		break
for i in range(3):
	p.insert(2*i+1,ans[i])
print(''.join(p)+'=7')

Solution (Python):
S = input()

pn = ['-', '+']
for i in range(2 ** (len(S) - 1)):

    tmp = int(S[0])
    for j in range(len(S) - 1):
        if i >> j & 1 == 1:
            tmp += int(S[j+1])
        else:
            tmp -= int(S[j+1])

    if tmp == 7:
        ans = S[0]
        for j in range(len(S)-1):
            ans += pn[i>>j&1] + S[j+1]
        print(ans + '=7')
        quit()

Solution (Python):
import numpy as np

s = [w for w in input()]
length = len(s)

for i in range(2 ** (length-1)):
    b = format(i, 'b')
    b_len = len(b)
    pad_width = ((length-1) - b_len, 0)
    b_pad = np.pad([int(n) for n in b], pad_width, 'constant')
    score = int(s[0])
    result = s[0]
    for flag, num in zip(b_pad, s[1:]):
        if flag == 1:
            score += int(num)
            result += '+' + num
        else:
            score -= int(num)
            result += '-' + num

    if score == 7:
        print(result+'=7')
        break

Solution (Python):
def bi(x, length):
    ret = "".join(["0" for _ in range(length)])
    return (ret + str(bin(x))[2:])[-length:]


def solve(inp):
    l = len(inp) - 1
    for i in range(2 ** l):
        binary = bi(i, l)
        tot = int(inp[0])
        for j in range(l):
            if binary[j] == "1":
                tot += int(inp[j+1])
            else:
                tot -= int(inp[j+1])
        if tot == 7:
            return ''.join([inp[j] + "+" if binary[j] == "1" else inp[j] + "-" for j in range(l)] + [inp[-1] + "=7"])

inp = input()

print(solve(str(inp)))

Solution (Python):
S = input()
A, B, C, D = S[0], S[1], S[2], S[3]
ope = ["+++", "+-+", "++-", "+--", "-++", "--+", "-+-", "---"]


for i in range(8):
    ope1 = ope[i][0]
    ope2 = ope[i][1]
    ope3 = ope[i][2]
    val = A + ope1 + B + ope2 + C + ope3 + D
    if eval(val) == 7:
        ans = val + "=7"
        break


print(ans)

Solution (Python):
s = input()
A, B, C, D = s[0], s[1], s[2], s[3]
op = ["+++", "+-+", "++-", "+--", "-++", "--+", "-+-", "---"]


for i in range(8):
    op1 = op[i][0]
    op2 = op[i][1]
    op3 = op[i][2]
    e = A + op1 + B + op2 + C + op3 + D
    if eval(e) == 7:
        ans = e + "=7"
        break


print(ans)

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

for i in range(2**3):
  ans = tick[0]
  op = []
  for j in range(3):
    if (i >> j) & 1:
      op.append("+")
      ans += tick[j+1]
    else:
      op.append("-")
      ans -= tick[j+1]
  if ans == 7:
    print(tick[0], op[0], tick[1], op[1], tick[2], op[2], tick[3], "=7", sep="")
    exit()

Solution (Python):
def main():
    A, B, C, D = input()
    for ab in ['+', '-']:
        for bc in ['+', '-']:
            for cd in ['+', '-']:
                if eval(A + ab + B + bc + C + cd + D) == 7:
                    print(A + ab + B + bc + C + cd + D + '=7')
                    return


main()

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

nums = list(map(int, strs))

op_patterns = []

ops = ['+', '-']

for op1 in ops:
    for op2 in ops:
        for op3 in ops:
            op_patterns.append((op1, op2, op3))


for pat in op_patterns:
    express = '{}{}{}{}{}{}{}'.format(nums[0], pat[0], nums[1], pat[1], nums[2], pat[2], nums[3])
    result = eval(express)

    if result == 7:
        print(express + '=7')
        exit()

Solution (Python):
from itertools import product
x=[a for a in input()]
a=('+','-')
s=list(product(a,repeat=3))
for op in s:
     ops=x[0]+op[0]+x[1]+op[1]+x[2]+op[2]+x[3]
     if eval(ops)==7:
          print(ops+'=7')
          break

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

d = []
for i in range(0,8):
  x = str(format(i,'b'))
  x = x.zfill(3) 
  d.append(x)

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

Solution (Python):
from itertools import product

A, B, C, D = [x for x in input().strip()]

for x in ["".join(x) for x in product(A, '+-', B, '+-', C, '+-', D)]:
    if eval(x) == 7:
        print(x+"=7")
        break

Solution (Python):
a,b,c,d=input()
o='+-- -'
for i in range(8):
 s=a+o[i&1]+b+o[i&2]+c+o[i&4]+d
 if eval(s)==7:print(s+'=7');break

Solution (Python):
a,b,c,d=input()
o='+-- -'
for i in range(8):
 s=a+o[i&1]+b+o[i&2]+c+o[i&4]+d
 if eval(s)==7:print(s+'=7');exit()

Solution (Python):
a,b,c,d=input()
o='+-'
for i in range(8):
 s=a+o[i&1]+b+o[i&2>0]+c+o[i&4>0]+d
 if eval(s)==7:print(s+'=7');exit()

Solution (Python):
a,b,c,d=input()
o='+-'
for i in o:
    for j in o:
        for k in o:
            s=a+i+b+j+c+k+d
            if eval(s)==7:
                print(s+'=7')
                exit()

Solution (Python):
a,b,c,d=input()
o='+-'
for i in o:
    for j in o:
        for k in o:
            s=a+i+b+j+c+k+d
            if eval(s)==7:
                print(s+'=7')
                exit()

Solution (Python):

import sys
INF = float("inf")


def solve(ABCD: str):
    A, B, C, D = map(int, ABCD)
    for op1 in [1, -1]:
        for op2 in [1, -1]:
            for op3 in [1, -1]:
                if A+op1*B+op2*C+op3*D == 7:
                    op1 = "+" if op1 == 1 else "-"
                    op2 = "+" if op2 == 1 else "-"
                    op3 = "+" if op3 == 1 else "-"
                    print("{}{}{}{}{}{}{}=7".format(A, op1, B, op2, C, op3, D))
                    return
    return


def main():

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


if __name__ == '__main__':
    main()

Solution (Python):
import itertools
S = input()
op = ['+','-']

for o1,o2,o3 in itertools.product(op,repeat=3):
    formula = S[0]+o1+S[1]+o2+S[2]+o3+S[3]
    result = eval(formula)
    if result == 7:
        print(formula+"=7")
        break

Solution (Python):
MAX_DIGIT = 4

N = int(input())
num = []

n = N
for i in range(MAX_DIGIT)[::-1]:
    num.append(int(n % 10))
    n /= 10
num.reverse()

for i in range(1 << (MAX_DIGIT - 1)):
    s = num[0]
    ans = str(num[0])
    for j in range(MAX_DIGIT - 1):
        if i >> j & 1 == 1:
            s += num[j + 1]
            ans = ans + "+" + str(num[j + 1])
        else:
            s -= num[j + 1]
            ans = ans + "-" + str(num[j + 1])
    if s == 7:
        print(ans + "=7")
        exit()

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

s = [(ABCD[0], str(ABCD[0]), ABCD[1:])]
while s:
	acc, exp, nums = s.pop()
	if acc == 7 and len(nums) == 0:
		print(exp + "=7")
		break
	elif len(nums) == 0:
		continue
		

	if len(nums) == 1:
		next_nums = []
	else:
		next_nums = nums[1:]
	s.append((acc + nums[0], exp+"+"+str(nums[0]), next_nums))
	s.append((acc - nums[0], exp+"-"+str(nums[0]), next_nums))

Solution (Python):



import sys
s = input()
def answer(value, formula, remain):
  if len(remain) == 1:
    if value + int(remain) == 7:
      print(formula + "+" + remain + "=7")
      sys.exit(0)
    elif value - int(remain) == 7:
      print(formula + "-" + remain + "=7")
      sys.exit(0)
  else:
    answer(value + int(remain[0]), formula + "+" + remain[0], remain[1:])
    answer(value - int(remain[0]), formula + "-" + remain[0], remain[1:])

answer(int(s[0]), s[0], s[1:])

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

for i in range(2):
    for j in range(2):
        for k in range(2):
            ans = str(num[0])
            val = num[0]
            if i == 0:
                ans += "+"
                val += num[1]
            else:
                ans += "-"
                val -= num[1]
            ans += str(num[1])
            if j == 0:
                ans += "+"
                val += num[2]
            else:
                ans += "-"
                val -= num[2]
            ans += str(num[2])
            if k == 0:
                ans += "+"
                val += num[3]
            else:
                ans += "-"
                val -= num[3]
            ans += str(num[3])
            if val == 7:
                print(ans + "=7")
                exit(0)

Solution (Python):
def calculate(A,B,C,D):
    if A+B+C+D == 7:
        return (str(A)+"+"+str(B)+"+"+str(C)+"+"+str(D)+"=7")
    if A+B+C-D == 7:
        return (str(A)+"+"+str(B)+"+"+str(C)+"-"+str(D)+"=7")
    if A+B-C+D == 7:
        return (str(A)+"+"+str(B)+"-"+str(C)+"+"+str(D)+"=7")
    if A-B+C+D == 7:
        return (str(A)+"-"+str(B)+"+"+str(C)+"+"+str(D)+"=7")
    if A+B-C-D == 7:
        return (str(A)+"+"+str(B)+"-"+str(C)+"-"+str(D)+"=7")
    if A-B-C+D == 7:
        return (str(A)+"-"+str(B)+"-"+str(C)+"+"+str(D)+"=7")
    if A-B+C-D == 7:
        return (str(A)+"-"+str(B)+"+"+str(C)+"-"+str(D)+"=7")
    if A-B-C-D == 7:
        return (str(A)+"-"+str(B)+"-"+str(C)+"-"+str(D)+"=7")
    
ABCD = input()
A = int(ABCD[0])
B = int(ABCD[1])
C = int(ABCD[2])
D = int(ABCD[3])

ans = calculate(A,B,C,D)
print(ans)

Solution (Python):
num = list(map(int,list(input())))
for i in range(2**3):
    ans = num[0]
    siki = str(num[0])
    for h in range(3):
        if ((i>>h)&1):
            ans += num[h+1]
            siki += ('+'+str(num[h+1]))
        else:
            ans -= num[h+1]
            siki += ('-'+str(num[h+1]))
    if ans == 7:
        print(siki+'=7')
        break

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

Solution (Python):

import sys


def solve(ABCD: str):
    l = list(str(ABCD))
    ope =('+', '-')

    import itertools
    for i in itertools.product(ope, repeat=3):
        t = int(l[0])
        tl = []
        tl.append(l[0])
        for j,x in enumerate(i):
            tl.append(x)
            tl.append(l[j+1])
            if(i[j] == '+'):
                t += int(l[j+1])
            else:
                t -= int(l[j+1])

        
        if(t == 7):
            tl.append('=7')
            
            print(''.join(map(str,tl)))
            sys.exit()

    l = list(map(int, l))
    print('%d+%d+%d+%d=7' % (l[0], l[1], l[2], l[3]))

    return



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

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    s = input()
    abcd = [int(s[i:i+1]) for i in range(len(s))]
    op_n = len(abcd) - 1

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

        ans = [0] * (len(abcd) + 1)
        formula = "{}+".format(ans[0])
        for k in range(len(abcd)):
            if k == 0:
                ans[k+1] = (ans[k] + abcd[k])
                formula += str(abcd[k])
            else:
                ans[k+1] = add_or_sub(ans[k], abcd[k], operator[k-1])
                formula += (operator[k-1] + str(abcd[k]))

        if ans[len(abcd)] == 7:
            print(formula[2:] + "=7")
            break

def add_or_sub(num1, num2, op):
    if op == "+":
        return num1 + num2
    else:
        return num1 - num2

if __name__ == "__main__":
    main()

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

for i in range(2**3):
    op = [0,0,0]
    sum = a[0]
    for j in range(3):
        if ((i >> j) & 1):
            op[-1-j] = 1
            sum += a[-1-j]
        else:
            sum -= a[-1-j]
    
    if sum == 7:
        string = str(a[0])
        for idx, k in enumerate(op):
            if k == 1:
                string += '+'
            else:
                string += '-'
            string += str(a[idx+1])
        string += '=7'

print(string)

Solution (Python):
s = input()
for i in range(8):
    y = ''.join([s[k] + '+-'[i >> k & 1] for k in range(3)] + [s[-1]])
    if eval(y) == 7:
        print(y+'=7')
        break

Solution (Python):
a, b, c, d = map(int, input())
ans = ''
if a + b + c + d == 7:
    ans = '{}+{}+{}+{}=7'
elif a - b + c + d == 7:
    ans = '{}-{}+{}+{}=7'
elif a + b - c + d == 7:
    ans = '{}+{}-{}+{}=7'
elif a + b + c - d == 7:
    ans = '{}+{}+{}-{}=7'
elif a - b - c + d == 7:
    ans = '{}-{}-{}+{}=7'
elif a + b - c - d == 7:
    ans = '{}+{}-{}-{}=7'
elif a - b + c - d == 7:
    ans = '{}-{}+{}-{}=7'
elif a - b - c - d == 7:
    ans = '{}-{}-{}-{}=7'
    
print(ans.format(a, b, c, d))

Solution (Python):
import itertools

s = input()

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

comb = []

for i in itertools.product([1,0],repeat=3):
    comb.append(i)
    
for i in range(8):
    if comb[i][0] == 1:
        x = a+b
    
    if comb[i][0] == 0:
        x = a-b
    
    if comb[i][1] == 1:
        x += c
    
    if comb[i][1] == 0:
        x -= c
    
    if comb[i][2] == 1:
        x += d
    
    if comb[i][2] == 0:
        x -= d
    
    if x == 7:
        ans_comb = comb[i]
        break

if ans_comb[0] == 1:
    x_1 = '+'

if ans_comb[0] == 0:
    x_1 = '-'
    
if ans_comb[1] == 1:
    x_2 = '+'

if ans_comb[1] == 0:
    x_2 = '-'

if ans_comb[2] == 1:
    x_3 = '+'

if ans_comb[2] == 0:
    x_3 = '-'
    
print(str(a)+x_1+str(b)+x_2+str(c)+x_3+str(d)+'=7')

Solution (Python):
S = input()

length = len(S) - 1
ans = 0

for i in range(2 ** length):
    bit = bin(i)[2:].zfill(length)
    T = ""
    for j in range(len(S)):
        if j == 0:
            T += S[j]
            continue
        else:
            b = bit[j-1]
            if b == "1":
                T += "+"
            else:
                T += "-"
            T += S[j]
    if eval(T) == 7:
        print(T+"=7")
        exit()

Solution (Python):
N=list(input())
l=len(N)-1
for n in range(2**l):
    lis=list(format(n,'b'))
    list(map(int,lis))
    nagasa=len(lis)
    if nagasa<l:
        for _ in range(l-nagasa):
            lis.insert(0,0)
    S=int(N[0])
    ans=[]
    for ll in range(l):
        if lis[ll]=='1':
            S=S+int(N[ll+1])
            ans.append('+')
        else:
            S=S-int(N[ll+1])
            ans.append('-')
    if S==7:
        kotae=[N[0]]
        for x in range(l):
            kotae.append(ans[x])
            kotae.append(N[x+1])
        kotae.append('=7')
        last=''.join(kotae)
        print(last)
        break

Solution (Python):


A, B, C, D = list(input())
OP = ['+', '-']

for op1 in OP:
    for op2 in OP:
        for op3 in OP:
            ans = A + op1 + B + op2 + C + op3 + D
            if eval(ans) == 7:
                ans = ans+"=7"
                break
        else:
            continue
        break
    else:
        continue
    break

print(ans)

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

def f(S, n):
    for i in range( 1 << n-1 ):
        cand_str = ""
        cand_str += S[0]

        
        for j in range(n-1):

            
            t = i & (1 << n-2-j)
            if t:
                cand_str += "+"
            else:
                cand_str += "-"
            cand_str += S[j+1]
            
        if eval(cand_str) == 7:
            return cand_str + "=7"

print(f(S, n))