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):



from itertools import product

abcd = input()
a, b, c, d = list(abcd)

for operations in product('+-', repeat=3):
    string = a
    string += operations[0]
    string += b
    string += operations[1]
    string += c
    string += operations[2]
    string += d
    ans = eval(string)
    if ans == 7:
        string += '=7'
        print(string)
        quit()

Solution (Python):
from sys import stdin
import itertools
a = stdin.readline().strip()
n = int(a)
b = list(a)
c = itertools.permutations(b)
ans = ''
j = ['+++','++-','+-+','+--','-++','-+-','--+','---']
for ii in c:
    i = list(ii)
    
    ans = ''
    for x in j:
     
        f = i[0] + x[0] + i[1] + x[1] + i[2] + x[2] + i[3]
        if eval(f)==7:
            ans = f
            break
    if len(ans):
        break
print ans+'=7'

Solution (Python):

import itertools


a = input()
op = ['+','-']
pro = list(itertools.product(op, repeat=3))

for i in pro:
    c = a[0]+i[0]+a[1]+i[1]+a[2]+i[2]+a[3]
    if(eval(c)==7):
        print(c+'=7')
        break

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

op = "-+"
for i1 in range(2):
  for i2 in range(2):
    for i3 in range(2):
      ans = a
      ans += b if i1 else -b
      ans += c if i2 else -c
      ans += d if i3 else -d
      if ans == 7:
        print("%d%s%d%s%d%s%d=7" % (a,op[i1],b,op[i2],c,op[i3],d))
        exit()

Solution (Python):
n = input()
a = int(n[0])
b = int(n[1])
c = int(n[2])
d = int(n[3])
if a+b+c+d == 7:
	print('{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))
else:
	print('{0}-{1}-{2}-{3}=7'.format(a,b,c,d))

Solution (Python):
n = list(input())
ops = ['+', '-']
flag = False
for a in ops:
    for b in ops:
        for c in ops:
            ans = n[0]+a+n[1]+b+n[2]+c+n[3]
            if eval(ans)==7:
                ans=ans+'=7'
                print(ans)
                flag = True
                break
        if flag:
            break
    if flag:
        break

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):
A, B, C, D = map(int, *input().split())

op = 0
while True:
    if A + (B if op & 1 else -B) + (C if op & 2 else -C) + (D if op & 4 else -D) == 7:
        break
    op += 1

print(A, '+' if op & 1 else '-', B, '+' if op & 2 else '-', C, '+' if op & 4 else '-', D, '=7', sep='')

Solution (Python):
S = input()
for i in range(1<<3):
    s = S[0:1]
    for j in range(3):
        s += list("+-")[i>>j&1]+S[j+1:j+2]
    if eval(s) == 7:
        res = s
print(res+'=7')

Solution (Python):

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


for i in range(8):
    res = A
    if i in [0, 2, 4, 6]:
        res = res + '+' + B
    else:
        res = res + '-' + B
    if i in [0, 1, 4, 5]:
        res = res + '+' + C
    else:
        res = res + '-' + C
    if i in [0, 1, 2, 3]:
        res = res + '+' + D
    else:
        res = res + '-' + D
        
    if eval(res) == 7:
        print(res+'=7')
        break

Solution (Python):
import operator


def solve(a, b, c, d):
    op = [operator.add, operator.sub]
    sp = ['+', '-']
    for i in range(8):
        j, k, l = i & 1, (i >> 1) & 1, (i >> 2) & 1
        calc = op[j](a, b)
        calc = op[k](calc, c)
        calc = op[l](calc, d)
        if calc == 7:
            return '{}{}{}{}{}{}{}=7'.format(a, sp[j], b, sp[k], c, sp[l], d)


print(solve(*map(int, input())))

Solution (Python):
n = input()

n1 = int(n[0])
n2 = int(n[1])
n3 = int(n[2])
n4 = int(n[3])

for op2 in [n2,-n2]:
	for op3 in [n3,-n3]:
		for op4 in [n4,-n4]:			
			if n1+op2+op3+op4 == 7:
				a = [op2,op3,op4]
				break

ans = str(n1)
for i in a:
	if i >= 0:
		ans += (('+') + str(i))
	else:
		ans += str(i)

ans += '=7'
print(ans)

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

s = ''
for i in range(8):
    s = str(abcd[0])
    tmp = abcd[0]
    for j in range(3):
        if (1 << j) & i == 0:
            s += '+'
            tmp += abcd[j + 1]
        else:
            s += '-'
            tmp -= abcd[j + 1]
        s += str(abcd[j + 1])
    s += '=7'
    if tmp == 7:
        break
print(s)

Solution (Python):


import sys

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

operator = ['+','-']

for op1 in operator:
    for op2 in operator:
        for op3 in operator:
            tmp = a   + b if op1=='+' else a - b
            tmp = tmp + c if op2=='+' else tmp - c
            tmp = tmp + d if op3=='+' else tmp - d
            if tmp == 7:
                print('{0}{1}{2}{3}{4}{5}{6}=7'.format(a,op1,b,op2,c,op3,d))
                sys.exit()

Solution (Python):
N = int(input())
a = N // 1000
b = (N // 100) - a*10
c = (N // 10) - a*100 - b*10
d = N % 10
if a+b+c+d == 7:
    print("%d+%d+%d+%d=7" % (a,b,c,d))
elif a+b+c-d == 7:
    print("%d+%d+%d-%d=7" % (a,b,c,d))
elif a+b-c+d == 7:
    print("%d+%d-%d+%d=7" % (a,b,c,d))
elif a+b-c-d == 7:
    print("%d+%d-%d-%d=7" % (a,b,c,d))
elif a-b+c+d == 7:
    print("%d-%d+%d+%d=7" % (a,b,c,d))
elif a-b+c-d == 7:
    print("%d-%d+%d-%d=7" % (a,b,c,d))
elif a-b-c+d == 7:
    print("%d-%d-%d+%d=7" % (a,b,c,d))
elif a-b-c-d == 7:
    print("%d-%d-%d-%d=7" % (a,b,c,d))

Solution (Python):
s = input()
a = [int(s[i]) for i in range(4)]
for i in range(8):
    cur = a[0]
    for j in range(3):
        if (i >> j) & 1:
            cur += a[j + 1]
        else:
            cur -= a[j + 1]
    if cur == 7:
        s = str(a[0])
        for j in range(3):
            if (i >> j) & 1:
                s += "+"
            else:
                s += "-"
            s += str(a[j + 1])
        s += "=7"
        print(s)
        break

Solution (Python):
n = list(raw_input())
op = ['+', '-']

for o1 in op:
	for o2 in op:
		for o3 in op:
			s = n[0] + o1 + n[1] + o2 + n[2] + o3 + n[3]
			if eval(s) == 7:
				print s + '=7'
				exit(0)

Solution (Python):
def buildstr(d,mask):
    s = '+'
    for i in xrange(len(mask)):
        s += d[i]
        if mask[i] == '1':
            s += '+'
        else:
            s += '-'
    s += d[-1]
    return s

def eval(s):
    add = True
    tot = 0
    for i in xrange(4):
        if s[2*i] == '-':
            add = False
        else:
            add = True
        if add:
            tot += int(s[2*i+1])
        else:
            tot -= int(s[2*i+1])
    return tot

d = list(raw_input())
for i in xrange(8):
    mask = bin(8+i)[3:]
    temp = buildstr(d,mask)
    if eval(temp) == 7:
        print temp[1:]+"=7"
        break

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

Solution (Python):
import sys
a,b,c,d = [c for c in raw_input()]
for op1 in ('+','-'):
  for op2 in ('+','-'):
    for op3 in ('+','-'):
       t = a + op1 + b + op2 + c + op3 + d
       if eval(t) == 7:
         print t + '=7'
         sys.exit()

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

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

for i in [1, -1]:
    for j in [1, -1]:
        for k in [1, -1]:
            if a + i * b + j * c + k * d == 7:
                def op(x):
                    return '+' if x == 1 else '-'
                print(str(a) + op(i) + str(b) + op(j) + str(c) + op(k) + str(d) + '=7')
                exit()

Solution (Python):
from itertools import product
s = input()
for p in product("+-", repeat=3):
    r = s[0]
    for i in range(3):
        r += p[i] + s[i+1]
    if eval(r) == 7:
        print(r + "=7")
        break

Solution (Python):
t = input()
s = list(map(int,list(t)))

if s[0] + s[1] + s[2] + s[3] == 7:
    print(t[0]+"+"+t[1]+"+"+t[2]+"+"+t[3]+"=7")
elif s[0] + s[1] + s[2] - s[3] == 7:
    print(t[0]+"+"+t[1]+"+"+t[2]+"-"+t[3]+"=7")
elif s[0] + s[1] - s[2] + s[3] == 7:
    print(t[0]+"+"+t[1]+"-"+t[2]+"+"+t[3]+"=7")
elif s[0] + s[1] - s[2] - s[3] == 7:
    print(t[0]+"+"+t[1]+"-"+t[2]+"-"+t[3]+"=7")
elif s[0] - s[1] + s[2] + s[3] == 7:
    print(t[0]+"-"+t[1]+"+"+t[2]+"+"+t[3]+"=7")
elif s[0] - s[1] + s[2] - s[3] == 7:
    print(t[0]+"-"+t[1]+"+"+t[2]+"-"+t[3]+"=7")
elif s[0] - s[1] - s[2] + s[3] == 7:
    print(t[0]+"-"+t[1]+"-"+t[2]+"+"+t[3]+"=7")
elif s[0] - s[1] - s[2] - s[3] == 7: 
    print(t[0]+"-"+t[1]+"-"+t[2]+"-"+t[3]+"=7")

Solution (Python):


import itertools


def find_eq(abcd):
    a, b, c, d = abcd
    ops = ("+", "-")
    for op1, op2, op3 in itertools.product(ops, repeat=3):
        eq = a + op1 + b + op2 + c + op3 + d
        if eval(eq) == 7:
            return eq + "=7"


def main():
    print(find_eq(input()))


if __name__ == '__main__':
    main()

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

Solution (Python):
import sys

stdin = sys.stdin

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

s = ns().strip()
a = [int(_) for _ in s]

for i in range(8):
    t = a[0]
    for j in range(3):
        if i>>j&1:
            t += a[j+1]
        else:
            t -= a[j+1]
    if t == 7:
        print("{}{}{}{}{}{}{}=7".format(
            a[0], "+" if i>>0&1 else "-",
            a[1], "+" if i >> 1 & 1 else "-",
            a[2], "+" if i >> 2 & 1 else "-",
            a[3],
        ))
        break

Solution (Python):
s = raw_input()

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