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):
a, b, c, d = map(int, list(raw_input()))

ppp = lambda a,b,c,d: (a+b+c+d == 7, "%d+%d+%d+%d=7" % (a,b,c,d))
pps = lambda a,b,c,d: (a+b+c-d == 7, "%d+%d+%d-%d=7" % (a,b,c,d))
psp = lambda a,b,c,d: (a+b-c+d == 7, "%d+%d-%d+%d=7" % (a,b,c,d))
pss = lambda a,b,c,d: (a+b-c-d == 7, "%d+%d-%d-%d=7" % (a,b,c,d))
spp = lambda a,b,c,d: (a-b+c+d == 7, "%d-%d+%d+%d=7" % (a,b,c,d))
sps = lambda a,b,c,d: (a-b+c-d == 7, "%d-%d+%d-%d=7" % (a,b,c,d))
ssp = lambda a,b,c,d: (a-b-c+d == 7, "%d-%d-%d+%d=7" % (a,b,c,d))
sss = lambda a,b,c,d: (a-b-c-d == 7, "%d-%d-%d-%d=7" % (a,b,c,d))

li = [ppp, pps, psp, pss, spp, sps, ssp, sss]
for l in li:
    if l(a, b, c, d)[0]:
        print l(a,b,c,d)[1]
        break

Solution (Python):

from itertools import product
A, B, C, D = map(int, input())
pm = {1: "+", -1: "-"}

for op1, op2, op3 in product([1, -1], repeat=3):
    if A + op1*B + op2*C + op3*D == 7:
        print("".join(map(str, [A, pm[op1], B, pm[op2], C, pm[op3], D, "=7"])))
        break

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

def create_ops():
    """
    create operations.
    """
    pn = (-1, 1)
    ops = [(op_1, op_2, op_3) \
            for op_1 in pn \
            for op_2 in pn \
            for op_3 in pn]
    return ops

def sign(num):
    """
    get signed string of number.
    """
    return "+" + str(num) if num >= 0 else str(num)

def ans(a, b, c, d):
    """
    answer.
    """
    print("{0}{1}{2}{3}=7".format(a, sign(b), sign(c), sign(d)))

def main():
    """
    main.
    """
    a = A
    expected = 7 - a

    nums = (B, C, D)
    ops = create_ops()
    is_found = False

    for op in ops:
        els = [(n, pn) for n, pn in zip(nums, op)]
        els_map = map(lambda el: el[0] * el[1], els)
        els_list = list(els_map)
        total = sum(els_list)
        if total == expected:
            is_found = True
            break

    if is_found:
        b, c, d = els_list
        ans(a, b, c, d)

if __name__ == '__main__':
    main()

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

def plus(x,y):
    return x+y

def minus(x,y):
    return x-y

pm_list = [plus,minus]
print_list = ["+","-"]

for i,method in enumerate(pm_list):

    goukei1 = method(a,b)
    for j,method2 in enumerate(pm_list):

        goukei2 = method2(goukei1,c)
        for k,method3 in enumerate(pm_list):

            goukei3 = method3(goukei2,d)
            
            if goukei3 == 7:
                kw = str(a)+print_list[i]+str(b)+print_list[j]+str(c)+print_list[k]+str(d)+"=7"
                print(kw)
                break
        if goukei3 ==7:
            break
            
    if goukei3 ==7:
        break

Solution (Python):

import itertools
a = list(map(int, list(input())))
factor = list(itertools.product(['+', '-'], repeat=3))
for tmp in factor:
    op1 = tmp[0]
    op2 = tmp[1]
    op3 = tmp[2]
    if op1 == '+':
        ans = a[0]+a[1]
    else:
        ans = a[0]-a[1]
    if op2 == '+':
        ans += a[2]
    else:
        ans -= a[2]
    if op3  == '+':
        ans += a[3]
    else:
        ans -= a[3]
    if ans == 7:
        print(str(a[0])+op1+str(a[1])+op2+str(a[2])+op3+str(a[3])+'=7')
        break
    else:
        pass

Solution (Python):
def main():
    num = input()
    a, b, c, d = [int(i) for i in num]
    num_list = [a, b, c, d]
    if (a-b-c-d == 7): print('{}-{}-{}-{}=7'.format(*num_list))
    elif (a-b-c+d == 7): print('{}-{}-{}+{}=7'.format(*num_list))
    elif (a-b+c-d == 7): print('{}-{}+{}-{}=7'.format(*num_list))
    elif (a+b-c-d == 7): print('{}+{}-{}-{}=7'.format(*num_list))
    elif (a-b+c+d == 7): print('{}-{}+{}+{}=7'.format(*num_list))
    elif (a+b+c-d == 7): print('{}+{}+{}-{}=7'.format(*num_list))
    elif (a+b-c+d == 7): print('{}+{}-{}+{}=7'.format(*num_list))
    elif (a+b+c+d == 7): print('{}+{}+{}+{}=7'.format(*num_list))
                    

if __name__ == '__main__':
    main()

Solution (Python):
d = int(raw_input())

a = d/1000
d -= a*1000
b = d/100
d -= b*100
c = d/10
d -= c*10

sumt = range(8)
op = ["+", "-"]

sumt[0] = a+b+c+d
sumt[1] = a+b+c-d
sumt[2] = a+b-c+d
sumt[3] = a+b-c-d
sumt[4] = a-b+c+d
sumt[5] = a-b+c-d
sumt[6] = a-b-c+d
sumt[7] = a-b-c-d

for i,s in enumerate(sumt):
    if s == 7:
        x = op[i/4]
        i -= (i/4)*4
        y = op[i/2]
        i -= (i/2)*2
        z = op[i]



print '%s%s%s%s%s%s%s=7' %(a,x,b,y,c,z,d)

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

Solution (Python):
def solve():
    N = [int(x) for x in list(input())]

    if 7 + N[2] + N[3] == N[0] + N[1]: 
        N = [str(x) for x in N]
        operators = ["+", "-", "-"]
        ans = []
        ans.append(N[0])
        del N[0]
        for n, op in zip(N, operators):
            ans.append(op)
            ans.append(n)
        ans.append("=")
        ans.append(str(7))
        print("".join(ans))
    elif 7 + N[2] - N[3] == N[0] + N[1]:
        N = [str(x) for x in N]
        operators = ["+", "-", "+"]
        ans = []
        ans.append(N[0])
        del N[0]
        for n, op in zip(N, operators):
            ans.append(op)
            ans.append(n)
        ans.append("=")
        ans.append(str(7))
        print("".join(ans))
    elif 7 - N[2] + N[3] == N[0] + N[1]:
        N = [str(x) for x in N]
        operators = ["+", "+", "-"]
        ans = []
        ans.append(N[0])
        del N[0]
        for n, op in zip(N, operators):
            ans.append(op)
            ans.append(n)
        ans.append("=")
        ans.append(str(7))
        print("".join(ans))
    elif 7 - N[2] - N[3] == N[0] + N[1]:
        N = [str(x) for x in N]
        operators = ["+", "+", "+"]
        ans = []
        ans.append(N[0])
        del N[0]
        for n, op in zip(N, operators):
            ans.append(op)
            ans.append(n)
        ans.append("=")
        ans.append(str(7))
        print("".join(ans))
    elif 7 + N[2] + N[3] == N[0] - N[1]: 
        N = [str(x) for x in N]
        operators = ["-", "-", "-"]
        ans = []
        ans.append(N[0])
        del N[0]
        for n, op in zip(N, operators):
            ans.append(op)
            ans.append(n)
        ans.append("=")
        ans.append(str(7))
        print("".join(ans))
    elif 7 + N[2] - N[3] == N[0] - N[1]:
        N = [str(x) for x in N]
        operators = ["-", "-", "+"]
        ans = []
        ans.append(N[0])
        del N[0]
        for n, op in zip(N, operators):
            ans.append(op)
            ans.append(n)
        ans.append("=")
        ans.append(str(7))
        print("".join(ans))
    elif 7 - N[2] + N[3] == N[0] - N[1]:
        N = [str(x) for x in N]
        operators = ["-", "+", "-"]
        ans = []
        ans.append(N[0])
        del N[0]
        for n, op in zip(N, operators):
            ans.append(op)
            ans.append(n)
        ans.append("=")
        ans.append(str(7))
        print("".join(ans))
    elif 7 - N[2] - N[3] == N[0] - N[1]:
        N = [str(x) for x in N]
        operators = ["-", "+", "+"]
        ans = []
        ans.append(N[0])
        del N[0]
        for n, op in zip(N, operators):
            ans.append(op)
            ans.append(n)
        ans.append("=")
        ans.append(str(7))
        print("".join(ans))


solve()

Solution (Python):
import sys
s=input()
for op1 in '+-':
  for op2 in '+-':
    for op3 in '+-':
      if eval(s[0]+op1+s[1]+op2+s[2]+op3+s[3]) == 7:
        print(s[0]+op1+s[1]+op2+s[2]+op3+s[3]+'=7')
        sys.exit(0)

Solution (Python):

import itertools
s='%d%s%d%s%d%s%d'
a,b,c,d=map(int,input())
for n in itertools.permutations(('+++---'),3):
    ans=s%(a,n[0],b,n[1],c,n[2],d)
    if eval(ans)==7:
        print(ans+'=7')
        break

Solution (Python):

N = input()

for i in range(1 << 3):
    s = N[0]
    for j in range(3):
        s += '+-'[i >> j & 1] + N[j + 1]
    if eval(s) == 7:
        print(s + '=7')
        break

Solution (Python):

N = input()

for i in range(8):
    num = [int(i) for i in N]
    for j in range(3):
        if (i >> j) % 2 == 1:
            num[-j - 1] *= -1
    if sum(num) == 7:
        print('{:d}{:+d}{:+d}{:+d}=7'.format(num[0], num[1], num[2], num[3]))
        break

Solution (Python):
def calc(a,b,c,d,p,q,r):
  value = a
  list=[(p,b),(q,c),(r,d)]
  
  for el in list:
    op,x = el
    if op == 0:
      value += x
    elif op == 1:
      value -= x
    else:
      raise Exception("invalid argument")
  
  return value
  
def op(p):
  if p == 0:
    return '+'
  elif p == 1:
    return '-'
  else:
    raise Exception("invalid argument")
  
  

def solve(inputstr):
  a=int(inputstr[0])
  b=int(inputstr[1])
  c=int(inputstr[2])
  d=int(inputstr[3])
  
  ops=[0,1]
  for p in ops:
    for q in ops:
      for r in ops:
        if 7 == calc(a,b,c,d,p,q,r):
          return (inputstr[0] + op(p) + inputstr[1] + op(q) + inputstr[2] + op(r) + inputstr[3] + "=7")
    

  raise Exception("invalid argument")



if __name__ == '__main__':
  inputstr = input()
  ans = solve(inputstr)
  print(ans, flush=True)

Solution (Python):
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
INF = float("inf")
sys.setrecursionlimit(10**7)


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


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


def main():
    A, B, C, D = input()
    for a in ["+", "-"]:
        for b in ["+", "-"]:
            for c in ["+", "-"]:
                s = A + a + B + b + C + c + D
                if eval(s) == 7:
                    print(s + "=7")
                    return


if __name__ == '__main__':
    main()

Solution (Python):
s = raw_input()
[a,b,c,d] = [int(t) for t in s]
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):
s=list(str(input()))

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

elif int(s[0])+int(s[1])+int(s[2])-int(s[3])==7:
    ans=s[0]+'+'+s[1]+'+'+s[2]+'-'+s[3]+'=7'
    print(ans)
    exit()

elif int(s[0])+int(s[1])-int(s[2])+int(s[3])==7:
    ans=s[0]+'+'+s[1]+'-'+s[2]+'+'+s[3]+'=7'
    print(ans)
    exit()

elif int(s[0])+int(s[1])-int(s[2])-int(s[3])==7:
    ans=s[0]+'+'+s[1]+'-'+s[2]+'-'+s[3]+'=7'
    print(ans)
    exit()

elif int(s[0])-int(s[1])+int(s[2])+int(s[3])==7:
    ans=s[0]+'-'+s[1]+'+'+s[2]+'+'+s[3]+'=7'
    print(ans)
    exit()

elif int(s[0])-int(s[1])+int(s[2])-int(s[3])==7:
    ans=s[0]+'-'+s[1]+'+'+s[2]+'-'+s[3]+'=7'
    print(ans)
    exit()

elif int(s[0])-int(s[1])-int(s[2])+int(s[3])==7:
    ans=s[0]+'-'+s[1]+'-'+s[2]+'+'+s[3]+'=7'
    print(ans)
    exit()

elif int(s[0])-int(s[1])-int(s[2])-int(s[3])==7:
    ans=s[0]+'-'+s[1]+'-'+s[2]+'-'+s[3]+'=7'
    print(ans)
    exit()

Solution (Python):



def f(ABCD):
    vals = list(map(int, ABCD))

    a = vals.pop(0)
    exps = {a:str(a)}

    for val in vals:
        nextExps = {}
        for x, exp in exps.items():
            nextExps[x + val] = exp + '+' + str(val)
            nextExps[x - val] = exp + '-' + str(val)

        exps = nextExps

    return exps[7] + '=7'
            
            
def test():
    print("test mode")
    print(f('1222'))
    print(f('0290'))
    print(f('3242'))


def main():
    ABCD = input()
    print(f(ABCD))
    
if __name__ == '__main__':
    main()

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

k = [
[1, 1, 1],
[1, 1, -1],
[1, -1, 1],
[1, -1, -1],
[-1, 1, 1],
[-1, 1, -1],
[-1, -1, 1],
[-1, -1, -1]]

p = ""

for i in k:
  if (a + b * i[0] + c * i[1] + d * i[2]) == 7:
    p += str(a)
    p += "+" if i[0] == 1 else "-"
    p += str(b)
    p += "+" if i[1] == 1 else "-"
    p += str(c)
    p += "+" if i[2] == 1 else "-"
    p += str(d)
    p += "=7"
    print(p)
    break

Solution (Python):
import sys

def dfs(n, ans, op, idx):
    if idx == 3 and ans == 7:
        tmp = ""
        for i in range(3):
            tmp += n[i] + op[i]
        tmp += n[3] + '=7'
        print tmp
        sys.exit()
    elif idx < 3:
        
        op[idx] = '+'
        tmp = ans + int(n[idx + 1])
        dfs(n, tmp, op, idx + 1)
        
        op[idx] = '-'
        tmp = ans - int(n[idx + 1])
        dfs(n, tmp, op, idx + 1)
    else:
        return 

if __name__ == '__main__':
    n = raw_input()
    op = ['' for i in range(3)]
    dfs(n, int(n[0]), op, 0)

Solution (Python):


def func(a,b,c,d,s):
    if a+b+c+d==7:
        s[1],s[3],s[5]="+","+","+"
    elif a+b+c-d==7:
        s[1],s[3],s[5]="+","+","-"
    elif a+b-c+d==7:
        s[1],s[3],s[5]="+","-","+"
    elif a+b-c-d==7:
        s[1],s[3],s[5]="+","-","-"
    elif a-b+c+d==7:
        s[1],s[3],s[5]="-","+","+"
    elif a-b+c-d==7:
        s[1],s[3],s[5]="-","+","-"
    elif a-b-c+d==7:
        s[1],s[3],s[5]="-","-","+"
    elif a-b-c-d==7:
        s[1],s[3],s[5]="-","-","-"

x=str(input())
ans=''

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

s=[a,"",b,"",c,"",d]

func(a,b,c,d,s)

for x in s:
    ans+=str(x)

print(ans+"=7")

Solution (Python):
s = input()

n = list(map(int,s))

c = 0

if n[0] +n[1]+n[2]+n[3]==7:
    if c==0: 
        print(s[0]+'+'+s[1]+'+'+s[2]+'+'+s[3]+'=7')
        c += 1
    
if n[0] +n[1]+n[2]-n[3]==7:
    if c==0:
        print(s[0]+'+'+s[1]+'+'+s[2]+'-'+s[3]+'=7')
        c += 1
    
if n[0] +n[1]-n[2]-n[3]==7:
    if c==0:
        print(s[0]+'+'+s[1]+'-'+s[2]+'-'+s[3]+'=7')
        c += 1
    
if n[0] +n[1]-n[2]+n[3]==7:
    if c==0:
        print(s[0]+'+'+s[1]+'-'+s[2]+'+'+s[3]+'=7')
        c += 1
    
if n[0] -n[1]-n[2]-n[3]==7:
    if c==0:
        print(s[0]+'-'+s[1]+'-'+s[2]+'-'+s[3]+'=7')
        c += 1
    
if n[0] -n[1]-n[2]+n[3]==7:
    if c==0:
        print(s[0]+'-'+s[1]+'-'+s[2]+'+'+s[3]+'=7')
        c += 1
    
if n[0] -n[1]+n[2]+n[3]==7:
    if c==0:
        print(s[0]+'-'+s[1]+'+'+s[2]+'+'+s[3]+'=7')
        c += 1

if n[0] -n[1]+n[2]-n[3]==7:
    if c==0:
        print(s[0]+'-'+s[1]+'+'+s[2]+'-'+s[3]+'=7')
        c += 1

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

for x in range(8):
    su = numbers[0]
    s = (str(numbers[0]))

    for i in range(3):
        if x & (1 << i):
            su += numbers[i+1]
            s += '+'
            s += str(numbers[i+1])
        else:
            su -= numbers[i+1]
            s += '-'
            s += str(numbers[i+1])

    if su == 7:
        print(s + '=7')
        break

Solution (Python):
N = input()
A, B, C, D = [int(i) for i in N]

def judge(a, b, c, d):
  if a + b + c + d == 7:
    return '{}+{}+{}+{}=7'.format(a, b, c, d)
  elif a - b - c - d == 7:
    return '{}-{}-{}-{}=7'.format(a, b, c, d)
  elif a + b - c - d == 7:
    return '{}+{}-{}-{}=7'.format(a, b, c, d)
  elif a - b + c - d == 7:
    return '{}-{}+{}-{}=7'.format(a, b, c, d)
  elif a - b - c + d == 7:
    return '{}-{}-{}+{}=7'.format(a, b, c, d)
  elif a - b + c + d == 7:
    return '{}-{}+{}+{}=7'.format(a, b, c, d)
  elif a + b + c - d == 7:
    return '{}+{}+{}-{}=7'.format(a, b, c, d)
  elif a + b - c + d == 7:
    return '{}+{}-{}+{}=7'.format(a, b, c, d)

print(judge(A, B, C, D))

Solution (Python):
s = input()
exp = []

def dfs(pos, tot):
    global exp
    if pos == 3:
        return tot == 7

    exp.append("+")
    if dfs(pos + 1, tot + int(s[pos+1])):
        return True
    exp.pop()
    exp.append("-")
    if dfs(pos + 1, tot - int(s[pos+1])):
        return True
    exp.pop()

def main():
    ok = 0
    if dfs(0, int(s[0])):
        for c, i in zip(s, exp):
            print(c, end="")
            print(i, end="")
        print(s[3] + "=7")

if __name__ == "__main__":
    main()

Solution (Python):
ABCD = [int(x) for x in list(input())]

calc_seq = [ABCD[0]]
op_seq = []

for i in range(1,4):
    for h in calc_seq[(2**(i-1))-1:(2**(i))-1]:
        calc_seq.append(h - ABCD[i])
        calc_seq.append(h + ABCD[i])

for i in range(7,16):
    if calc_seq[i] == 7:
        while i != 0:
            if i % 2 == 0:
                op_seq.append("+")
            else:
                op_seq.append("-")
            i = (i - 1) // 2
        break

op_seq = op_seq[::-1]
print(str(ABCD[0]) + op_seq[0] + str(ABCD[1]) + op_seq[1] + str(ABCD[2]) + op_seq[2] + str(ABCD[3]) + "=7")

Solution (Python):
s = raw_input()
for e in [s[0] + x + s[1] + y + s[2] + z + s[3] for x in '+-' for y in '+-' for z in '+-']:
    if eval(e) == 7:
        print e + '=7'
        exit()

Solution (Python):
A,B,C,D=map(int,list(input()))
o=["+","-"]
if A+B+C+D==7:
    strings="A{}B{}C{}D=7".format(o[0],o[0],o[0])
elif A+B+C-D==7:
    strings="A{}B{}C{}D=7".format(o[0],o[0],o[1])
elif A+B-C+D==7:
    strings="A{}B{}C{}D=7".format(o[0],o[1],o[0])
elif A+B-C-D==7:
    strings="A{}B{}C{}D=7".format(o[0],o[1],o[1])
elif A-B+C+D==7:
    strings="A{}B{}C{}D=7".format(o[1],o[0],o[0])
elif A-B+C-D==7:
    strings="A{}B{}C{}D=7".format(o[1],o[0],o[1])
elif A-B-C+D==7:
    strings="A{}B{}C{}D=7".format(o[1],o[1],o[0])
elif A-B-C-D==7:
    strings="A{}B{}C{}D=7".format(o[1],o[1],o[1])
strings=list(strings)
strings[0]=str(A)
strings[2]=str(B)
strings[4]=str(C)
strings[6]=str(D)
print("".join(strings))

Solution (Python):


a,b,c,d=map(int,raw_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):
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(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):


s = raw_input()

for op1 in "+-":
    for op2 in "+-":
        for op3 in "+-":
            e = s[0] + op1 + s[1] + op2 + s[2] + op3 + s[3]
            if eval(e) == 7:
                print e + "=7"
                exit(0)

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

def search(ops, p):
    if p < 3:
        ops[p] = 1
        ret_ops = search(ops, p+1)
        if T[p+1] == 0 or sum(T[0:1] + [t * op for (t, op) in zip(T[1:], ret_ops)]) == 7:
            return ret_ops
        else:
            ops[p] = -1
            return search(ops, p+1)
    else:
        return ops

ops = search([None, None, None], 0)

T = list(map(str, T))
ops = ["+" if op == 1 else "-" for op in ops]
print("{}{}=7".format(T[0], "".join(map(lambda x: "".join(x), zip(ops, T[1:])))))

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('{0}+{1}+{2}+{3}=7'.format(a, b, c, d))
elif a-b+c+d == 7:
    print('{0}-{1}+{2}+{3}=7'.format(a, b, c, d))
elif a+b-c+d == 7:
    print('{0}+{1}-{2}+{3}=7'.format(a, b, c, d))
elif a+b+c-d == 7:
    print('{0}+{1}+{2}-{3}=7'.format(a, b, c, d))
elif a-b-c+d == 7:
    print('{0}-{1}-{2}+{3}=7'.format(a, b, c, d))
elif a-b+c-d == 7:
    print('{0}-{1}+{2}-{3}=7'.format(a, b, c, d))
elif a+b-c-d == 7:
    print('{0}+{1}-{2}-{3}=7'.format(a, b, c, d))
elif a-b-c-d == 7:
    print('{0}-{1}-{2}-{3}=7'.format(a, b, c, d))

Solution (Python):
l = list(input()) 
for i in range(8):
    p = ["+"if i&j else"-" for j in[1, 2, 4]]
    line = "".join([v+o for v,o in zip(l,p)]) + l[3]
    if eval(line) == 7:
        print(line + "=7")
        break

Solution (Python):
l = list(input()) 
for i in range(8):
    p = ["+"if i&j else"-" for j in[1, 2, 4]]
    line = "".join([v+o for v,o in zip(l,p)])
    line += l[3]
    if eval(line) == 7:
        print(line + "=7")
        break

Solution (Python):
from itertools import zip_longest

l = list(input()) 
for i in range(8):
    p = ["+"if i & j else"-" for j in[1, 2, 4]]
    p.append("")
    line = "".join([v+o for v,o in zip_longest(l,p)])
    if eval(line) == 7:
        print(line + "=7")
        break

Solution (Python):
a, b, c, d = [int(i) for i in input()]
for i in range(8):
    p = ["+"if i & j else"-" for j in[1, 2, 4]]
    line = "{0}{1}{2}{3}{4}{5}{6}".format(a, p[0], b, p[1], c, p[2], d)
    if eval(line) == 7:
        print(line + "=7")
        break

Solution (Python):
a,b,c,d = [int(i) for i in input()]
for i in range(8):
  pattern = []
  for j in [1,2,4]:
    pattern.append("+"if i&j else"-")
  line = "{0}{1}{2}{3}{4}{5}{6}".format(a,pattern[0],b,pattern[1],c,pattern[2],d)
  if eval(line) == 7:
    print(line + "=7")
    break

Solution (Python):
n=list(input())
op="+----"
for i in range(8):
    s=n[0]+op[i&4]+n[1]+op[i&2]+n[2]+op[i&1]+n[3]
    if eval(s)==7:
        print(s+"=7")
        break;

Solution (Python):
import sys

N = input()

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

def myprint(lst):
	s=str(A)+lst[0]+str(B)+lst[1]+str(C)+lst[2]+str(D)+"=7"
	print(s)


def calc2(a,b,op):
	if(op=="-"):
		return a-b
	else:
		return a+b

def calc(lst):
	sum=calc2(calc2(calc2(A,B,lst[0]),C,lst[1]),D,lst[2])
	return sum


lst=["+","+","+"]

lst2=0
while(True):
	if(calc(lst)==7):
		myprint(lst)
		break
	lst2+=1
	temp=format(lst2,"03b")
	for i in range(3):
		if(temp[i]=="0"):
			lst[2-i]="-"
		else:
			lst[2-i]="+"

Solution (Python):
a=list(raw_input())
b=[]
for i in a:
    b.append(int(i))
for i in range(1):
    if b[0]+b[1]+b[2]+b[3]==7:
        c=[0,0,0]
        break
    elif b[0]+b[1]+b[2]-b[3]==7:
        c=[0,0,1]
        break
    elif b[0]+b[1]-b[2]+b[3]==7:
        c=[0,1,0]
        break
    elif b[0]+b[1]-b[2]-b[3]==7:
        c=[0,1,1]
        break
    elif b[0]-b[1]+b[2]+b[3]==7:
        c=[1,0,0]
        break
    elif b[0]-b[1]+b[2]-b[3]==7:
        c=[1,0,1]
        break
    elif b[0]-b[1]-b[2]+b[3]==7:
        c=[1,1,0]
        break
    elif b[0]-b[1]-b[2]-b[3]==7:
        c=[1,1,1]
        break
ans=""
c.append("=7")
for i in range(4):
    ans+=a[i]
    if c[i]==0:
        ans+="+"
    elif c[i]==1:
        ans+="-"
    else:
        ans+=c[i]
print ans

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(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):
N = input()
a = int(N[0])
b = int(N[1])
c = int(N[2])
d = int(N[3])
A = N[0]
B = N[1]
C = N[2]
D = N[3]

if a + b + c + d == 7:
    print(A + "+" + B + "+" + C + "+" + D + "=" + "7")
elif a + b + c - d == 7:
    print(A + "+" + B + "+" + C + "-" + D + "=" + "7")
elif a + b - c + d == 7:
    print(A + "+" + B + "-" + C + "+" + D + "=" + "7")
elif a - b + c + d == 7:
    print(A + "-" + B + "+" + C + "+" + D + "=" + "7")
elif a + b - c - d == 7:
    print(A + "+" + B + "-" + C + "-" + D + "=" + "7")
elif a - b + c - d == 7:
    print(A + "-" + B + "+" + C + "-" + D + "=" + "7")
elif a - b - c + d == 7:
    print(A + "-" + B + "-" + C + "+" + D + "=" + "7")
elif a - b - c - d == 7:
    print(A + "-" + B + "-" + C + "-" + D + "=" + "7")

Solution (Python):
import itertools

s = input()

for op in itertools.product("+-", repeat=3) :
    exp = "".join(i+j for i,j in zip(s,list(op)+['=']))
    val = eval(exp[0:-1])
    if val == 7 :
        print(exp + '7')
        exit(0)

Solution (Python):
import itertools

s = input()

for op in itertools.product("+-", repeat=3) :
    exp = s[0]+op[0]+s[1]+op[1]+s[2]+op[2]+s[3]
    val = eval(exp)
    if val == 7 :
        print(exp + '=7')
        exit(0)

Solution (Python):
s = list(raw_input())
for op1 in '+-':
    for op2 in '+-':
        for op3 in '+-':
            exec 'ans=%s%s%s%s%s%s%s' % (s[0], op1, s[1], op2, s[2], op3, s[3])
            if ans == 7:
                print '%s%s%s%s%s%s%s=7' % (s[0], op1, s[1], op2, s[2], op3, s[3])
                exit()

Solution (Python):
def main():
    ABCD = list(input())
    A = int(ABCD[0])
    B = int(ABCD[1])
    C = int(ABCD[2])
    D = int(ABCD[3])

    flag = True
    for i in ['+', '-']:
        if flag:
            sumAB = A + B if i == '+' else A - B
            for j in ['+', '-']:
                if flag:
                    sumABC = sumAB + C if j == '+' else sumAB - C
                    for k in ['+', '-']:
                        if flag:
                            sumABCD = sumABC + D if k == '+' else sumABC - D
                            if sumABCD == 7:
                                print(str(A) + i + str(B) + j + str(C) + k + str(D) + "=7")
                                flag = False

if __name__ == '__main__':
    main()

Solution (Python):

ABCD = str, input()
ABCD_list = list(ABCD[1])
A = int(ABCD_list[0])
B = int(ABCD_list[1])
C = int(ABCD_list[2])
D = int(ABCD_list[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):
def solve():
    N = [int(x) for x in list(input())]

    if 7 + N[2] + N[3] == N[0] + N[1]: 
        N = [str(x) for x in N]
        operators = ["+", "-", "-"]
        ans = []
        ans.append(N[0])
        del N[0]
        for n, op in zip(N, operators):
            ans.append(op)
            ans.append(n)
        ans.append("=")
        ans.append(str(7))
        print("".join(ans))
    elif 7 + N[2] - N[3] == N[0] + N[1]:
        N = [str(x) for x in N]
        operators = ["+", "-", "+"]
        ans = []
        ans.append(N[0])
        del N[0]
        for n, op in zip(N, operators):
            ans.append(op)
            ans.append(n)
        ans.append("=")
        ans.append(str(7))
        print("".join(ans))
    elif 7 - N[2] + N[3] == N[0] + N[1]:
        N = [str(x) for x in N]
        operators = ["+", "+", "-"]
        ans = []
        ans.append(N[0])
        del N[0]
        for n, op in zip(N, operators):
            ans.append(op)
            ans.append(n)
        ans.append("=")
        ans.append(str(7))
        print("".join(ans))
    elif 7 - N[2] - N[3] == N[0] + N[1]:
        N = [str(x) for x in N]
        operators = ["+", "+", "+"]
        ans = []
        ans.append(N[0])
        del N[0]
        for n, op in zip(N, operators):
            ans.append(op)
            ans.append(n)
        ans.append("=")
        ans.append(str(7))
        print("".join(ans))
    elif 7 + N[2] + N[3] == N[0] - N[1]: 
        N = [str(x) for x in N]
        operators = ["-", "-", "-"]
        ans = []
        ans.append(N[0])
        del N[0]
        for n, op in zip(N, operators):
            ans.append(op)
            ans.append(n)
        ans.append("=")
        ans.append(str(7))
        print("".join(ans))
    elif 7 + N[2] - N[3] == N[0] - N[1]:
        N = [str(x) for x in N]
        operators = ["-", "-", "+"]
        ans = []
        ans.append(N[0])
        del N[0]
        for n, op in zip(N, operators):
            ans.append(op)
            ans.append(n)
        ans.append("=")
        ans.append(str(7))
        print("".join(ans))
    elif 7 - N[2] + N[3] == N[0] - N[1]:
        N = [str(x) for x in N]
        operators = ["-", "+", "-"]
        ans = []
        ans.append(N[0])
        del N[0]
        for n, op in zip(N, operators):
            ans.append(op)
            ans.append(n)
        ans.append("=")
        ans.append(str(7))
        print("".join(ans))
    elif 7 - N[2] - N[3] == N[0] - N[1]:
        N = [str(x) for x in N]
        operators = ["-", "+", "+"]
        ans = []
        ans.append(N[0])
        del N[0]
        for n, op in zip(N, operators):
            ans.append(op)
            ans.append(n)
        ans.append("=")
        ans.append(str(7))
        print("".join(ans))


solve()