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



Sample input:
1222


Sample output:
1+2+2+2=7

Submission status: Accepted

Solution code:
a = input()
b = [int(x) for x in a]
c = []
d = " +-"

for x in [1,-1]:
    for y in [1,-1]:
        for z in [1,-1]:
            if b[0]+x*b[1]+y*b[2]+z*b[3] == 7:
                c.append(""+str(b[0])+d[x]+str(b[1])+d[y]+str(b[2])+d[z]+str(b[3])+"=7")
print(c[0])

Submission status: Accepted

Solution code:

import sys
N = input()
a, b, c, d = int(N[0]),int(N[1]), int(N[2]), int(N[3])
n = a + b + c + d
if n == 7:
    print("{}+{}+{}+{}=7".format(a, b, c, d))
    sys.exit()
n = a - b + c + d
if n == 7:
    print("{}-{}+{}+{}=7".format(a, b, c, d))
    sys.exit()
n = a + b - c + d
if n == 7:
    print("{}+{}-{}+{}=7".format(a, b, c, d))
    sys.exit()
n = a + b - c + d
if n == 7:
    print("{}+{}-{}+{}=7".format(a, b, c, d))
    sys.exit()
n = a + b + c - d
if n == 7:
    print("{}+{}+{}-{}=7".format(a, b, c, d))
    sys.exit()
n = a - b - c + d
if n == 7:
    print("{}-{}-{}+{}=7".format(a, b, c, d))
    sys.exit()
n = a + b - c - d
if n == 7:
    print("{}+{}-{}-{}=7".format(a, b, c, d))
    sys.exit()
n = a - b + c - d
if n == 7:
    print("{}-{}+{}-{}=7".format(a, b, c, d))
    sys.exit()
n = a - b - c - d
if n == 7:
    print("{}-{}-{}-{}=7".format(a, b, c, d))
    sys.exit()

Submission status: Accepted

Solution code:
def main():
    A = list(map(int,str(input())))

    s1 = "+"
    s2 = "+"
    s3 = "+"    

    if A[0] + A[1] + A[2] + A[3] == 7:
        s1 = "+"
        s2 = "+"
        s3 = "+"
    elif A[0] + A[1] + A[2] - A[3] == 7:
        s1 = "+"
        s2 = "+"
        s3 = "-"
    elif A[0] + A[1] - A[2] + A[3] == 7:
        s1 = "+"
        s2 = "-"
        s3 = "+"
    elif A[0] - A[1] + A[2] + A[3] == 7:   
        s1 = "-"
        s2 = "+"
        s3 = "+"
    elif A[0] + A[1] - A[2] - A[3] == 7:   
        s1 = "+"
        s2 = "-"
        s3 = "-"
    elif A[0] - A[1] + A[2] - A[3] == 7:   
        s1 = "-"
        s2 = "+"
        s3 = "-"
    elif A[0] - A[1] - A[2] + A[3] == 7:   
        s1 = "-"
        s2 = "-"
        s3 = "+"
    elif A[0] - A[1] - A[2] - A[3] == 7:   
        s1 = "-"
        s2 = "-"
        s3 = "-"

    print(str(A[0]) + s1 + str(A[1]) + s2 + str(A[2]) + s3 + str(A[3]) + "=7")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import itertools

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

for ops in itertools.product('+-', '+-', '+-'):
    ans = ABCD[0]
    for i, op in enumerate(ops, 1):
        if op == '+':
            ans += ABCD[i]
        else:
            ans -= ABCD[i]

    if ans == 7:
        ss = str(ABCD[0])
        for i, op in enumerate(ops, 1):
            ss += op + str(ABCD[i])
        ss += '=7'
        print(ss)
        exit()

Submission status: Accepted

Solution code:
q = [int(x) for x in input()]

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

Submission status: Accepted

Solution code:
A,B,C,D = list(input())

ops = ["+","-"]

ans = []
for op1 in ops:
    for op2 in ops:
        for op3 in ops:
            tmp = 0
            if op1 == "+":
                tmp = int(A)+int(B)
            else:
                tmp = int(A)-int(B)

            if op2 == "+":
                tmp = tmp + int(C)
            else:
                tmp = tmp - int(C)

            if op3 == "+":
                tmp = tmp + int(D)
            else:
                tmp = tmp - int(D)

            if tmp == 7:
                ans.append(str(A) + op1 + str(B) + op2 + str(C) + op3 + str(D) + "=7")

print(ans[0])

Submission status: Accepted

Solution code:
import sys

N = int(sys.stdin.readline().strip())

a = int(N / 1000)
b = int(N / 100) - a * 10
c = int(N / 10) - b * 10 - a * 100
d = N % 10

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def main():
    A, B, C, D = [int(i) for i in input()]
    B, C, D = [[i, -i] for i in [B, C, D]]
    pm = ["+", ""]
    for i in range(2):
        for j in range(2):
            for k in range(2):
                if A + B[i] + C[j] + D[k] == 7:
                    ans = [A, pm[i], B[i], pm[j], C[j], pm[k], D[k], "=7"]
                    return("".join(map(str,ans)))

if __name__ == "__main__":
    print(main())

Submission status: Accepted

Solution code:
import sys
A, B, C, D = map(int, input())
ops = ['+', '-']
for op1 in ops:
    for op2 in ops:
        for op3 in ops:
            tmp = A
            if op1 == '+':
                tmp += B
            else:
                tmp -= B
            if op2 == '+':
                tmp += C
            else:
                tmp -= C
            if op3 == '+':
                tmp += D
            else:
                tmp -= D
            if tmp == 7:
                print("{}{}{}{}{}{}{}=7".format(A,op1,B,op2,C,op3,D))
                sys.exit()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
import itertools
input_str = input()
A = input_str[0]
B = input_str[1]
C = input_str[2]
D = input_str[3]

ops = ['+', '-']
all_ops = list(itertools.product(A, ops, B, ops, C, ops, D))
for tmp in all_ops:
    result = eval(''.join(tmp))
    if result == 7:
        print(''.join(tmp) + "=7")
        break

Submission status: Accepted

Solution code:
# cook your dish here
# from math import * 
#for _ in range(int(input().strip())):

order=['+++','++-','+-+','+--','-++','-+-','--+','---']

s=input()
flag=-1
for i in range(8):
    ans=int(s[0])
    for j in range(1,len(s)):
        if order[i][j-1]=='+':
            ans+=(int(s[j]))
        else:
            ans-=(int(s[j]))
    if ans==7:
        flag=i
#print(flag)
if flag>-1:
    for i in range(3):
        print(s[i],order[flag][i],sep="",end="")
    print(s[3],"=7",sep="")

Submission status: Accepted

Solution code:
A,B,C,D = list(input())
for op1 in ['+','-']:
    for op2 in ['+','-']:
        for op3 in ['+','-']:
            k = A + op1 + B + op2 + C + op3 + D
            if eval(k) == 7:
                print(k+'=7')
                exit()

Submission status: Accepted

Solution code:
A,B,C,D = list(map(int,input().rstrip()))


for i in range(8):
    op1=1 if i%2 ==0 else -1
    op2=1 if (i//2)%2==0 else -1
    op3=1 if (i//4)%2==0 else -1
    #print(op1,op2,op3)
    if A + op1*B + op2*C + op3*D == 7:
        print(str(A)+ ("+" if op1==1 else "-")
              +str(B)+ ("+" if op2==1 else "-")
               + str(C) +( "+" if op3==1 else "-")
              +str(D)+"=7"
                )
        exit()

Submission status: Accepted

Solution code:
def ope(f):
    if f:
        return "+"
    return "-"

flag = False
A, B, C, D = map(int, list(input()))
for a in [1, 0]:
    for b in [1, 0]:
        for c in [1, 0]:
            for d in [1, 0]:
                result = eval("{} {} {} {} {} {} {}".format(A, ope(a), B, ope(b), C, ope(c), D))
                if result == 7:
                    print("{}{}{}{}{}{}{}=7".format(A, ope(a), B, ope(b), C, ope(c), D))
                    flag = True
                    break
            if flag:
                break
        if flag:
            break
    if flag:
        break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

if __name__ == '__main__':
    N = raw_input()
    if int(N[0])+int(N[1])+int(N[2])+int(N[3]) == 7:
        print('{0}+{1}+{2}+{3}=7'.format(N[0],N[1],N[2],N[3]))
    elif int(N[0])+int(N[1])+int(N[2])-int(N[3]) == 7:
        print('{0}+{1}+{2}-{3}=7'.format(N[0],N[1],N[2],N[3]))
    elif int(N[0])+int(N[1])-int(N[2])+int(N[3]) == 7:
        print('{0}+{1}-{2}+{3}=7'.format(N[0],N[1],N[2],N[3]))
    elif int(N[0])+int(N[1])-int(N[2])-int(N[3]) == 7:
        print('{0}+{1}-{2}-{3}=7'.format(N[0],N[1],N[2],N[3]))
    elif int(N[0])-int(N[1])+int(N[2])+int(N[3]) == 7:
        print('{0}-{1}+{2}+{3}=7'.format(N[0],N[1],N[2],N[3]))
    elif int(N[0])-int(N[1])+int(N[2])-int(N[3]) == 7:
        print('{0}-{1}+{2}-{3}=7'.format(N[0],N[1],N[2],N[3]))
    elif int(N[0])-int(N[1])-int(N[2])+int(N[3]) == 7:
        print('{0}-{1}-{2}+{3}=7'.format(N[0],N[1],N[2],N[3]))
    elif int(N[0])-int(N[1])-int(N[2])-int(N[3]) == 7:
        print('{0}-{1}-{2}-{3}=7'.format(N[0],N[1],N[2],N[3]))

Submission status: Accepted

Solution code:
s=input()

for i in range(7):
    op=bin(i)[2:].zfill(3).replace('0','+').replace('1','-')
    v=s[0]+op[0]+s[1]+op[1]+s[2]+op[2]+s[3]+'==7'
    if eval(v):
        print(v.replace('==','='))
        exit(0)

Submission status: Accepted

Solution code:
#!usr/bim/python
#! -*- coding: utf-8 -*-

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

op1 = "+"
op2 = "+"
op3 = "+"

if a+b+c+d==7:
    pass
elif a+b+c-d==7:
    op3 = "-"
elif a+b-c+d==7:
    op2 = "-"
elif a+b-c-d==7:
    op2 = "-"
    op3 = "-"
elif a-b+c+d==7:
    op1 = "-"
elif a-b+c-d==7:
    op1 = "-"
    op3 = "-"
elif a-b-c+d==7:
    op1 = "-"
    op2 = "-"
else:
    op1 = "-"
    op2 = "-"
    op2 = "-"

ans = abcd[0]+op1+abcd[1]+op2+abcd[2]+op3+abcd[3]+"=7"

print ans

Submission status: Accepted

Solution code:
import sys

line = sys.stdin.readline().strip()

for i in range(8):
    siki = line[0] + "+-"[(i >> 2) & 1] + line[1] + "+-"[(i >> 1) & 1] + line[2] + "+-"[(i >> 0) & 1] + line[3]
    r = eval(siki)
    if r == 7:
        print("%s=%d" % (siki, r))
        break

Submission status: Accepted

Solution code:
import sys

str_n = input()
N = [int(i) for i in str_n]

OPS = ['+', '-']

for op1 in OPS:
    for op2 in OPS:
        for op3 in OPS:
            ans = N[0]
            if op1 == '+':
                ans += N[1]
            else:
                ans -= N[1]
            if op2 == '+':
                ans += N[2]
            else:
                ans -= N[2]
            if op3 == '+':
                ans += N[3]
            else:
                ans -= N[3]
            if ans == 7:
                print(str_n[0] + op1 + str_n[1] + op2 + str_n[2] + op3 + str_n[3] + '=7')
                sys.exit()

Submission status: Accepted

Solution code:
n = raw_input()
a = int(n[0])
b = int(n[1])
c = int(n[2])
d = int(n[3])

q = ["+","-"]

now = a
for x2 in range(2):
  now2 = now + b * pow(-1,x2)
  for x3 in range(2):
    now3 = now2 + c * pow(-1,x3)
    for x4 in range(2):
      now4 = now3 + d * pow(-1,x4)
      if now4 == 7:
        print "%d%s%d%s%d%s%d=7" % (a,q[x2],b,q[x3],c,q[x4],d)
        exit(0)

Submission status: Accepted

Solution code:
import sys

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

for i in range(2):
    s0 = A
    if i == 0:
        s1 = s0 + B
    else:
        s1 = s0 - B

    for j in range(2):
        if j == 0:
            s2 = s1 + C
        else:
            s2 = s1 - C

        for k in range(2):
            if k == 0:
                s3 = s2 + D
            else:
                s3 = s2 - D

            if s3 == 7:
                ans = str(A)
                if i == 0:
                    ans += '+'
                else:
                    ans += '-'
                ans += str(B)
                if j == 0:
                    ans += '+'
                else:
                    ans += '-'
                ans += str(C)
                if k == 0:
                    ans += '+'
                else:
                    ans += '-'
                ans += str(D)
                ans += '=7'
                print(ans)
                sys.exit()

Submission status: Accepted

Solution code:
#python3
# utf-8

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

Submission status: Accepted

Solution code:
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)
    #print i
    ans = ''
    for x in j:
     #   print x
        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'

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-       
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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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='')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
# C
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

Submission status: Accepted

Solution code:
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())))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#http://abc079.contest.atcoder.jp/
# -*- coding: utf-8 -*-
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()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env 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()

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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]
# print(a)
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

Submission status: Accepted

Solution code:
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()

Submission status: Runtime Error

Solution code:
ABCD = input().strip()
for i in range(8):
    ope = [{0:'+', 1:'-'}[i & (1<<j)] for j in range(3)]
    fomula = ABCD[0] + ope[0] + ABCD[1] + ope[1] + ABCD[2] + ope[2] + ABCD[3]
    if eval(fomula) == 7:
        print(f'{fomula}=7')
        break

Submission status: Runtime Error

Solution code:
ABCD = input()
for i in range(8):
    ope = [{0:'+', 1:'-'}[i & (1<<j)] for j in range(3)]
    fomula = ABCD[0] + ope[0] + ABCD[1] + ope[1] + ABCD[2] + ope[2] + ABCD[3]
    if eval(fomula) == 7:
        print(f'{fomula}=7')
        break

Submission status: Runtime Error

Solution code:
ope = {0:'+', 1:'-'}
ABCD = input()
for i in range(8):
    i = [i & (1<<j) for j in range(3)]
    fomula = ABCD[0] + ope[i[0]] + ABCD[1] + ope[i[1]] + ABCD[2] + ope[i[2]] + ABCD[3]
    if eval(fomula) == 7:
        print(f'{fomula}=7')
        break

Submission status: Runtime Error

Solution code:
a,b,c,d = input().split()
pm = '+-'
for i in pm:
  for j in pm:
    for k in pm:
      total = a+i+b+j+c+k+d
      if eval(total) == 7:
        print(total+'=7')
        exit()

Submission status: Runtime Error

Solution code:
S = [a for a in input()]
N = [int(a) for a in S]
M = [N[i] for i in range(1,4)]
S.insert(1, '+')
S.insert(3, '+')
S.insert(5, '+')

if sum(N) == 7:
    S = S
    print(''.join(S) + '=7')
    exit()

for i in range(1, 4):
    N[i] = -N[i]

    if sum(N) == 7:
        S[2 * i - 1] = '-'
        print(''.join(S) + '=7')
        exit()

for i in range(1, 4):
    S[1], S[3], S[5] == '-', '-', '-'
    M[i] = -M[i]
    if sum(M) == 7:
        S[2 * i - 1] = '+'
        print(''.join(S) + '=7')
        exit()

Submission status: Runtime Error

Solution code:
S = [a for a in input()]
N = [int(a) for a in S]
M = [-N[i] for i in range(1,4)]
S.insert(1, '+')
S.insert(3, '+')
S.insert(5, '+')

if sum(N) == 7:
    S = S
    print(''.join(S) + '=7')
    exit()

for i in range(1, 4):
    N[i] = -N[i]

    if sum(N) == 7:
        S[2 * i - 1] = '-'
        print(''.join(S) + '=7')
        exit()

for i in range(1, 4):
    M[i] = -M[i]
    if sum(M) == 7:
        S[2 * i - 1] = '+'
        print(''.join(S) + '=7')
        exit()

if N[0] + N[1] - N[2] - N[3] == 7:
    S[3] = '-'
    S[5] = '-'
elif N[0] - N[1] + N[2] - N[3] == 7:
    S[1] = '-'
    S[5] = '-'
elif N[0] - N[1] - N[2] + N[3] == 7:
    S[1] = '-'
    S[5] = '-'
print(''.join(S) + '=7')

Submission status: Runtime Error

Solution code:
lsnum = list(input())
lsnum1 = [int(i) for i in lsnum]
ls = ['+','-']
for i in ls:
    if i == '+':
        ans7 = lsnum1[0] + lsnum1[1]
    else:
        ans7 = lsnum1[0] - lsnum1[1]
    for j in ls:
        if j == '+':
            ans7 += lsnum1[2]
        else:
            ans7 -= lsnum1[2]
        for k in ls:
            if k == '+':
                ans7 += lsnum1[3]
            else:
                ans7 -= lsnum1[3]
            if ans7 == 7:
                ans = lsnum[0]+i+lsnum[1]+j+lsnum[2]+k+lsnum[3]+'=7'
                break
print(ans)

Submission status: Runtime Error

Solution code:
S = input()
l = len(S)
ans = 0

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

Submission status: Runtime Error

Solution code:
from itertools import product

s=input()

for op in product(["+","-"],repeat=len(s)-1):
  formula =""
  for i in range(len(s-1)):
    formula+=s[i]+op[i]
  formula+=s[-1]
  if eval(formula)==7:
    print(formula+"=7")
    exit()

Submission status: Runtime Error

Solution code:
from itertools import product

s=input()

for op in product(["+","-"],repeat=len(s)-1):
  formula =""
  for i in range(len(s-1)):
    formula+=s[i]+op[i]
  formula+=s[1]
  if eval(formula)==7:
    print(formula+"=7")
    exit()

Submission status: Runtime Error

Solution code:
n = input()

for i in range(2**3):
    ss =""
    for j in range(3):
        ss +=n[j]
        if((i >> j )&1==True):
            ss += "+"
        else:
            ss += "-"
    ans = eval(ss)
    if (ans == 7):
        ss += "=7"
        print(ss)

Submission status: Runtime Error

Solution code:
s=input()
ans=[]

for i in range(2**3):
  a=int(s[0])
  for j in range(3):
    if ((i>>j)&1):
      a+=int(s[j+1])
    elif ((i>>j)&0):
      a-=int(s[j+1])
      
  if a==7:
    ans.append(i)
    
u=ans[0]
ans1=[]
for j in range(3):
  if ((i>>j)&1):
      ans1.append('+')
  elif ((i>>j)&0):
      ans1.append('-')
      
print(s[0]+ans1[0]+s[1]+ans1[1]+s[2]+ans1[2]+s[3]+'=7')

Submission status: Runtime Error

Solution code:
s=input()
ans=[]

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