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:
if __name__=="__main__":
    n = input()
    s = list(n)
    a = int(s[0])
    b = int(s[1])
    c = int(s[2])
    d = int(s[3])

    if a+b+c+d==7:
        print(s[0]+"+"+s[1]+"+"+s[2]+"+"+s[3]+"=7")
    elif a-b-c-d==7:
        print(s[0] + "-" + s[1] + "-" + s[2] + "-" + s[3] + "=7")
    elif a-b+c+d==7:
        print(s[0] + "-" + s[1] + "+" + s[2] + "+" + s[3] + "=7")
    elif a-b-c+d==7:
        print(s[0] + "-" + s[1] + "-" + s[2] + "+" + s[3] + "=7")
    elif a+b-c-d==7:
        print(s[0]+"+"+s[1]+"-"+s[2]+"-"+s[3]+"=7")
    elif a+b+c-d==7:
        print(s[0] + "+" + s[1] + "+" + s[2] + "-" + s[3] + "=7")
    elif a+b-c+d==7:
        print(s[0] + "+" + s[1] + "-" + s[2] + "+" + s[3] + "=7")
    elif a-b+c-d==7:
        print(s[0] + "-" + s[1] + "+" + s[2] + "-" + s[3] + "=7")

Submission status: Accepted

Solution code:
input_str = input()
A = int(input_str[0])
B = int(input_str[1])
C = int(input_str[2])
D = int(input_str[3])

list = []
list.append(A + B + C + D)
list.append(A + B + C - D)
list.append(A + B - C + D)
list.append(A + B - C - D)
list.append(A - B + C + D)
list.append(A - B + C - D)
list.append(A - B - C + D)
list.append(A - B - C - D)

num = list.index(7)

if num <= 3:
    op1 = '+'
else:
    op1 = '-'

if num == 0 or num == 1 or num == 4 or num == 5:
    op2 = '+'
else:
    op2 = '-'

if num % 2 == 0:
    op3 = '+'
else:
    op3 = '-'

print('{}{}{}{}{}{}{}=7'.format(A,op1,B,op2,C,op3,D))

Submission status: Accepted

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

"""abc079_c"""

import sys
import pprint
import re

import copy
from itertools import tee

import itertools
pp = pprint.PrettyPrinter(indent=2)

def main():
    """Main function."""
    d = list(map(int, list(input())))

    sentinel = object()
    def solve(v, it, s):
        n = next(it, sentinel)
        if v == 7 and n == sentinel:
            print(s[1:]+'=7')
            sys.exit(0)
        if n == sentinel:
            return
        solve(v+n, copy.copy(it), s+'+'+n.__str__())
        solve(v-n, copy.copy(it), s+'-'+n.__str__())

    solve(0, iter(d), '')

if __name__ == '__main__':
    sys.exit(main())

Submission status: Accepted

Solution code:
import sys

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

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

ans_list = [[0 for _ in range(8)] for __ in range(3)]

ans_list[0][0] = a + b
ans_list[0][1] = a - b
for i in range(2):
    ans_list[1][i * 2] = ans_list[0][i] + c
    ans_list[1][i * 2 + 1] = ans_list[0][i] - c
for i in range(4):
    ans_list[2][i * 2] = ans_list[1][i] + d
    ans_list[2][i * 2 + 1] = ans_list[1][i] - d

for n in range(8):
    if ans_list[2][n] == 7:
        ans = ""
        ans += abcd[0]
        if n > 3:
            ans += "-"
        else:
            ans += "+"
        ans += abcd[1]
        if n == 0 or n == 1 or n == 4 or n == 5:
            ans += "+"
        else:
            ans += "-"
        ans += abcd[2]
        if n % 2 == 0:
            ans += "+"
        else:
            ans += "-"
        ans += abcd[3]
        ans += "=7"
        print(ans)
        break

Submission status: Accepted

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

def add(a,b):
    return a+b
def sub(a,b):
    return a-b
lis = [0,0,0]
count = 0
while True:
    sum = 0
    if lis[0] == 0:
        sum = add(a,b)
    else:
        sum = sub(a,b)
    if lis[1] == 0:
        sum = add(sum,c)
    else:
        sum = sub(sum,c)
    if lis[2] == 0:
        sum = add(sum, d)
    else:
        sum = sub(sum, d)
    if sum == 7:
        break
    count += 1
    lis[0] = count % 2
    lis[1] = (count // 2) % 2
    lis[2] = (count// 4) % 2

if lis[0] == 0:
    x = '+'
else:
    x = '-'
if lis[1] == 0:
    y = '+'
else:
    y = '-'
if lis[2] == 0:
    z = '+'
else:
    z = '-'
print('{}{}{}{}{}{}{}=7'.format(a,x,b,y,c,z,d))

Submission status: Accepted

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

import itertools, sys

def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

s, = read_line(str)

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

for p in itertools.product((1, -1), (1, -1), (1, -1)):
    n = a + p[0] * b + p[1] * c + p[2] * d
    if n == 7:
        print('%d%+d%+d%+d=7' % (a, p[0] * b, p[1] * c, p[2] * d))
        sys.exit(0)

Submission status: Accepted

Solution code:
from itertools import chain, combinations
import sys

def all_subsets(ss):
    return chain(*map(lambda x: combinations(ss, x), range(0, len(ss) + 1)))

array=raw_input()

for subset in all_subsets([0,1,2]):
    suma=sum(map(int,str(array)))
    signs=list("+++")

    for ind in subset:
        suma=suma-2*int(array[ind+1])
        signs[ind]='-'

    if suma == 7:
        print array[0],
        for i in range(0,3):
            sys.stdout.write(signs[i])
            sys.stdout.write(array[i+1])
        break

sys.stdout.write("=7")

Submission status: Accepted

Solution code:
# coding: utf-8

A,B,C,D = (int(x) for x in input())
OP = ['-', '+']

op_list = []
for op1 in (True, False):
    for op2 in (True, False):
        for op3 in (True, False):
            op_list.append((op1,op2,op3))

for ops in op_list:
    ans = A
    for num, op in zip([B,C,D], ops):
        if(op):
            ans += num
        else:
            ans -= num
    if ans == 7:
        print("%d%s%d%s%d%s%d=7" % (A, OP[ops[0]], B, OP[ops[1]], C, OP[ops[2]], D))
        break

Submission status: Accepted

Solution code:
import numpy as np

C = list(map(int,input()))
op1 = np.array([1,-1,1,1])
op2 = np.array([1,1,-1,1])
op3 = np.array([1,1,1,-1])
C = np.array(C)

if(sum(C) == 7):
    print("{}+{}+{}+{}=7".format(C[0],C[1],C[2],C[3]))
elif(sum(C*op1) == 7):
    print("{}-{}+{}+{}=7".format(C[0],C[1],C[2],C[3]))
elif(sum(C*op2) == 7):
    print("{}+{}-{}+{}=7".format(C[0],C[1],C[2],C[3]))
elif(sum(C*op3) == 7):
    print("{}+{}+{}-{}=7".format(C[0],C[1],C[2],C[3]))
elif(sum(C*op1*op2) == 7):
    print("{}-{}-{}+{}=7".format(C[0],C[1],C[2],C[3]))
elif(sum(C*op1*op3) == 7):
    print("{}-{}+{}-{}=7".format(C[0],C[1],C[2],C[3]))
elif(sum(C*op1*op2*op3) == 7):
    print("{}-{}-{}-{}=7".format(C[0],C[1],C[2],C[3]))
elif(sum(C*op2*op3) == 7):
    print("{}+{}-{}-{}=7".format(C[0],C[1],C[2],C[3]))

Submission status: Accepted

Solution code:
n = 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:
abcd = str(input())

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

if a + b + c + d == 7:
    print("%s+%s+%s+%s=7" % (a, b, c, d))
elif a + b + c - d == 7:
    print("%s+%s+%s-%s=7" % (a, b, c, d))
elif a + b - c + d == 7:
    print("%s+%s-%s+%s=7" % (a, b, c, d))
elif a + b - c - d == 7:
    print("%s+%s-%s-%s=7" % (a, b, c, d))
elif a - b + c + d == 7:
    print("%s-%s+%s+%s=7" % (a, b, c, d))
elif a - b + c - d == 7:
    print("%s-%s+%s-%s=7" % (a, b, c, d))
elif a - b - c + d == 7:
    print("%s-%s-%s+%s=7" % (a, b, c, d))
elif a - b - c - d == 7:
    print("%s-%s-%s-%s=7" % (a, b, c, d))

Submission status: Accepted

Solution code:
a,b,c,d = [int(i) for i in 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))
else:
    print("該当なし")

Submission status: Accepted

Solution code:
N = input()
a = int(N[0])
b = int(N[1])
c = int(N[2])
d = int(N[3])
x = d+7
y = -d+7
while True:
    if a+b+c == x:
        print(str(a)+"+"+str(b)+"+"+str(c)+"-"+str(d)+"=7")
        break
    if a+b+c == y:
        print(str(a)+"+"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
        break
    if a-b+c == x:
        print(str(a)+"-"+str(b)+"+"+str(c)+"-"+str(d)+"=7")
        break
    if a-b+c == y:
        print(str(a)+"-"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
        break
    if a+b-c == x:
        print(str(a)+"+"+str(b)+"-"+str(c)+"-"+str(d)+"=7")
        break
    if a+b-c == y:
        print(str(a)+"+"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
        break
    if a-b-c == x:
        print(str(a)+"-"+str(b)+"-"+str(c)+"-"+str(d)+"=7")
        break
    if a-b-c == y:
        print(str(a)+"-"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
        break

Submission status: Accepted

Solution code:
n = input()
q = n[0]
w = n[1]
e = n[2]
r = n[3]
a = int(q)
b = int(w)
c = int(e)
d = int(r)

if a + b + c + d == 7:
    print(q+"+"+w+"+"+e+"+"+r+"="+"7")
elif a + b + c - d == 7:
    print(q+"+"+w+"+"+e+"-"+r+"="+"7")
elif a + b - c - d == 7:
    print(q+"+"+w+"-"+e+"-"+r+"="+"7")
elif a - b - c - d == 7:
    print(q+"-"+w+"-"+e+"-"+r+"="+"7")
elif a - b + c - d == 7:
    print(q+"-"+w+"+"+e+"-"+r+"="+"7")
elif a - b - c + d == 7:
    print(q+"-"+w+"-"+e+"+"+r+"="+"7")
elif a + b - c + d == 7:
    print(q+"+"+w+"-"+e+"+"+r+"="+"7")
elif a - b + c + d == 7:
    print(q+"-"+w+"+"+e+"+"+r+"="+"7")

Submission status: Accepted

Solution code:
S = input()
L = []
for i in range(4): L.append(int(S[i]))


if L[0]+L[1]+L[2]+L[3] == 7:
    print(S[0] +'+'+ S[1] +'+'+ S[2] +'+'+ S[3] +'=7')
elif L[0]+L[1]+L[2]-L[3] == 7:
    print(S[0] +'+'+ S[1] +'+'+ S[2] +'-'+ S[3] +'=7')
elif L[0]+L[1]-L[2]+L[3] == 7:
    print(S[0] +'+'+ S[1] +'-'+ S[2] +'+'+ S[3] +'=7')
elif L[0]+L[1]-L[2]-L[3] == 7:
    print(S[0] +'+'+ S[1] +'-'+ S[2] +'-'+ S[3] +'=7')
elif L[0]-L[1]+L[2]+L[3] == 7:
    print(S[0] +'-'+ S[1] +'+'+ S[2] +'+'+ S[3] +'=7')
elif L[0]-L[1]+L[2]-L[3] == 7:
    print(S[0] +'-'+ S[1] +'+'+ S[2] +'-'+ S[3] +'=7')
elif L[0]-L[1]-L[2]+L[3] == 7:
    print(S[0] +'-'+ S[1] +'-'+ S[2] +'+'+ S[3] +'=7')
elif L[0]-L[1]-L[2]-L[3] == 7:
    print(S[0] +'-'+ S[1] +'-'+ S[2] +'-'+ S[3] +'=7')

Submission status: Accepted

Solution code:
a = input()
c = map(int,list(a))
b = []
for i in c:
    b.append(i)
if(b[0] + b[1] + b[2] + b[3]==7):
    print(a[0]+"+"+a[1]+"+"+a[2]+"+"+a[3]+"=7")
elif(b[0] + b[1] + b[2] - b[3]==7):
    print(a[0]+"+"+a[1]+"+"+a[2]+"-"+a[3]+"=7")
elif(b[0] + b[1] - b[2] + b[3]==7):
    print(a[0]+"+"+a[1]+"-"+a[2]+"+"+a[3]+"=7")
elif(b[0] + b[1] - b[2] - b[3]==7):
    print(a[0]+"+"+a[1]+"-"+a[2]+"-"+a[3]+"=7")
elif(b[0] - b[1] + b[2] + b[3]==7):
    print(a[0]+"-"+a[1]+"+"+a[2]+"+"+a[3]+"=7")
elif(b[0] - b[1] + b[2] - b[3]==7):
    print(a[0]+"-"+a[1]+"+"+a[2]+"-"+a[3]+"=7")
elif(b[0] - b[1] - b[2] + b[3]==7):
    print(a[0]+"-"+a[1]+"-"+a[2]+"+"+a[3]+"=7")
elif(b[0] - b[1] - b[2] - b[3]==7):
    print(a[0]+"-"+a[1]+"-"+a[2]+"-"+a[3]+"=7")

Submission status: Accepted

Solution code:
# coding: utf-8

A = map(int, list(raw_input()))

if A[0] + A[1] + A[2] + A[3] == 7:
    print str(A[0]) + "+" + str(A[1]) + "+" + str(A[2]) + "+" + str(A[3]) + "=7"

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

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

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

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

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
A,B,C,D = str(input())
ops = ['+', '-']

for op1 in ops:
    for op2 in ops:
        for op3 in ops:
            a = A+op1+B+op2+C+op3+D
            if eval(a) == 7:
                print(a+'=7')
                sys.exit()

Submission status: Accepted

Solution code:
import itertools

def train_ticket(n):
	sum_n = n[0]
	A = ["+", "-"]
	for i in itertools.product(A, repeat=3):
		for idx,j in enumerate(i):
			if j == "+":
				sum_n += n[idx+1]
			else:
				sum_n -= n[idx+1]
		if sum_n == 7:
			print("{0}{1}{2}{3}{4}{5}{6}=7".format(n[0], i[0],n[1],i[1],n[2],i[2],n[3]))
			break
		else:
			sum_n = n[0]



n_ticket = list(map(int, input()))
train_ticket(n_ticket)

Submission status: Accepted

Solution code:

a,b,c,d = [int(x) for x in input()]
op = [[i,j,k] for i in ['+','-'] for j in ['+','-'] for k in ['+','-']]

for x,y,z in op:
    f = "%d%s%d%s%d%s%d" % (a,x,b,y,c,z,d)
    if eval(f) == 7:
        print(f+'=7')
        break

Submission status: Accepted

Solution code:
def c_train_ticket(N):
    A, B, C, D = int(N[0]), int(N[1]), int(N[2]), int(N[3])
    op = ['---', '--+', '-+-', '-++', '+--', '+-+', '++-', '+++']
    ans = 0
    for i, j in enumerate(op):
        code = 'A {0} B {1} C {2} D'.format(j[0], j[1], j[2])
        if eval(code) == 7:
            ans = i
    return '{0}{1}{2}{3}{4}{5}{6}=7'.format(A, op[ans][0], B, op[ans][1], C, op[ans][2], D)
  
N = input()
print(c_train_ticket(N))

Submission status: Accepted

Solution code:
S = input()
A,B,C,D = int(S[0]),int(S[1]),int(S[2]),int(S[3])
for i in [B,-1*B]:
    for j in [C,-1*C]:
        for k in [D,-1*D]:
            if A + i + j + k == 7:
                print("{:d}{:+d}{:+d}{:+d}=7".format(A,i,j,k),end="")
                exit()

Submission status: Accepted

Solution code:
b = list(map(int, input().split()))
mozi = str(b)
A = b[0]//1000
B = (b[0]-A*1000)//100
C = (b[0]-A*1000-B*100)//10
D = b[0]%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:
istr = raw_input()
lis = [int(istr[0]),int(istr[1]),int(istr[2]),int(istr[3])]
if   lis[0] + lis[1] + lis[2] + lis[3] == 7:
    print (istr[0]+"+"+istr[1]+"+"+istr[2]+"+"+istr[3]+"=7")
elif lis[0] + lis[1] + lis[2] - lis[3] == 7:
    print (istr[0]+"+"+istr[1]+"+"+istr[2]+"-"+istr[3]+"=7")
elif lis[0] + lis[1] - lis[2] + lis[3] == 7:
    print (istr[0]+"+"+istr[1]+"-"+istr[2]+"+"+istr[3]+"=7")
elif lis[0] + lis[1] - lis[2] - lis[3] == 7:
    print (istr[0]+"+"+istr[1]+"-"+istr[2]+"-"+istr[3]+"=7")
elif lis[0] - lis[1] + lis[2] + lis[3] == 7:
    print (istr[0]+"-"+istr[1]+"+"+istr[2]+"+"+istr[3]+"=7")
elif lis[0] - lis[1] + lis[2] - lis[3] == 7:
    print (istr[0]+"-"+istr[1]+"+"+istr[2]+"-"+istr[3]+"=7")
elif lis[0] - lis[1] - lis[2] + lis[3] == 7:
    print (istr[0]+"-"+istr[1]+"-"+istr[2]+"+"+istr[3]+"=7")
elif lis[0] - lis[1] - lis[2] - lis[3] == 7:
    print (istr[0]+"-"+istr[1]+"-"+istr[2]+"-"+istr[3]+"=7")

Submission status: Accepted

Solution code:
S = input()
A = S[0]
B = S[1]
C = S[2]
D = S[3]

mark = ["+", "-"]

for m1 in mark:
  for m2 in mark:
    for m3 in mark:
      if eval("{0} {1} {2} {3} {4} {5} {6}".format(A,m1,B,m2,C,m3,D)) == 7:
        print("{0}{1}{2}{3}{4}{5}{6}=7".format(A,m1,B,m2,C,m3,D))
        exit()

Submission status: Accepted

Solution code:
N = list(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")

Submission status: Accepted

Solution code:
N = list(input())

if int(N[0]) + int(N[1]) + int(N[2]) + int(N[3]) == 7:
    print(N[0]+"+"+N[1]+"+"+N[2]+"+"+N[3]+"=7")
elif int(N[0]) - int(N[1]) + int(N[2]) + int(N[3]) == 7:
    print(N[0]+"-"+N[1]+"+"+N[2]+"+"+N[3]+"=7")
elif int(N[0]) + int(N[1]) - int(N[2]) + int(N[3]) == 7:
    print(N[0]+"+"+N[1]+"-"+N[2]+"+"+N[3]+"=7")
elif int(N[0]) + int(N[1]) + int(N[2]) - int(N[3]) == 7:
    print(N[0]+"+"+N[1]+"+"+N[2]+"-"+N[3]+"=7")
elif int(N[0]) - int(N[1]) - int(N[2]) + int(N[3]) == 7:
    print(N[0]+"-"+N[1]+"-"+N[2]+"+"+N[3]+"=7")
elif int(N[0]) - int(N[1]) + int(N[2]) - int(N[3]) == 7:
    print(N[0]+"-"+N[1]+"+"+N[2]+"-"+N[3]+"=7")
elif int(N[0]) + int(N[1]) - int(N[2]) - int(N[3]) == 7:
    print(N[0]+"+"+N[1]+"-"+N[2]+"-"+N[3]+"=7")
elif int(N[0]) - int(N[1]) - int(N[2]) - int(N[3]) == 7:
    print(N[0]+"-"+N[1]+"-"+N[2]+"-"+N[3]+"=7")
else:
    pass

Submission status: Accepted

Solution code:
from itertools import product


def main():
    """
    A op1 B op2 C op3 D = 7
    op: +, -
    """

    _input = input()
    op1, op2, op3 = f(_input)
    A, B, C, D = list(_input)
    print(A + op1 + B + op2 + C + op3 + D + "=7")


def f(_input):
    A, B, C, D = map(int, list(_input))
    ans = 7 - A

    op = ("+", "-")
    op_p = product(op, op, op)
    bcd_p = product((B, -B), (C, -C), (D, -D))
    for ops, bcd in zip(op_p, bcd_p):
        if sum(bcd) == ans:
            return ops

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
e=input()
a=e[0]
b=e[1]
c=e[2]
d=e[3]
t=0

for x1 in ["+","-"]:
    for x2 in ["+","-"]:
        for x3 in ["+","-"]:
            if eval(a+x1+b+x2+c+x3+d)==7:
                t=1
            if t==1:
                break
        if t==1:
            break  
    if t==1:
        break
        
print(a+x1+b+x2+c+x3+d+"=7")

Submission status: Accepted

Solution code:
N = input()
n = []
for i in N:
    n.append(int(i))
if n[0] + n[1] + n[2] + n[3] == 7:
    print(N[0] + "+" + N[1] + "+" + N[2] + "+" + N[3] + "=7")
elif n[0] - n[1] + n[2] + n[3] == 7:
    print(N[0] + "-" + N[1] + "+" + N[2] + "+" + N[3] + "=7")
elif n[0] + n[1] - n[2] + n[3] == 7:
    print(N[0] + "+" + N[1] + "-" + N[2] + "+" + N[3] + "=7")
elif n[0] - n[1] - n[2] + n[3] == 7:
    print(N[0] + "-" + N[1] + "-" + N[2] + "+" + N[3] + "=7")
elif n[0] + n[1] + n[2] - n[3] == 7:
    print(N[0] + "+" + N[1] + "+" + N[2] + "-" + N[3] + "=7")
elif n[0] - n[1] + n[2] - n[3] == 7:
    print(N[0] + "-" + N[1] + "+" + N[2] + "-" + N[3] + "=7")
elif n[0] + n[1] - n[2] - n[3] == 7:
    print(N[0] + "+" + N[1] + "-" + N[2] + "-" + N[3] + "=7")
elif n[0] - n[1] - n[2] - n[3] == 7:
    print(N[0] + "-" + N[1] + "-" + N[2] + "-" + N[3] + "=7")

Submission status: Accepted

Solution code:
N=raw_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"

Submission status: Accepted

Solution code:
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

s = input()

n = []
for i in s:
    n.append(int(i))

for i in range(2):
    for j in range(2):
        for k in range(2):
            if i % 2 == 1:
                n1 = n[0] + n[1]
                o1 = '+'
            else:
                n1 = n[0] - n[1]
                o1 = '-'
            if j % 2 == 1:
                n2 = n1 + n[2]
                o2 = '+'
            else:
                n2 = n1 - n[2]
                o2 = '-'
            if k % 2 == 1:
                n3 = n2 + n[3]
                o3 = '+'
            else:
                n3 = n2 - n[3]
                o3 = '-'
            if n3 == 7:
                print(n[0], o1, n[1], o2, n[2], o3, n[3], '=7', sep='')
                exit()

Submission status: Accepted

Solution code:

def cal(arr, idx, res):

    if idx == 4 and res == 7:
        return True, ''

    if idx < 4:
        flg, op = cal(arr, idx+1, res+int(arr[idx]))
        if flg:
            return True, '+'+op

        flg, op = cal(arr, idx+1, res-int(arr[idx]))
        if flg:
            return True, '-'+op

    return False, ''

def main():
    n = input()
    _, op = cal(n, 0, 0)
    res = ''
    for i in range(3):
        res += n[i] + op[i+1]

    res += n[3] + '=7'
    print(res)
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
z = [0, 0, 0, 0]
inp = input()
for i in range(4):
    z[i] = int(inp[i])
res = 0
out = ""
for i in range(2):
    for j in range(2):
        for k in range(2):
            if(res == 7):
                break
            res = 0
            if(i == 0):
                out = str(z[0]) + "+" + str(z[1])
                res = z[0] + z[1]
            else:
                out = str(z[0]) + "-" + str(z[1])
                res = z[0] - z[1]

            if(j == 0):
                out += "+" + str(z[2])
                res += z[2]
            else:
                out += "-" + str(z[2])
                res -= z[2]

            if(k == 0):
                out += "+" + str(z[3])
                res += z[3]
            else:
                out += "-" + str(z[3])
                res -= z[3]
print(out + "=7")

Submission status: Accepted

Solution code:
a = ['+', '-']
b = [lambda x,y: x+y, lambda x,y: x-y]

A, B, C, D = map(int, input())

end = False
for q, w in zip(a, b):
    for t, y in zip(a, b):
        for o, p in zip(a, b):
            if p(y(w(A,B), C), D) == 7:
                print('{0}{1}{2}{3}{4}{5}{6}=7'.format(A,q,B,t,C,o,D))
                exit()

Submission status: Accepted

Solution code:
A,B,C,D = [int(i) for i in 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))

Submission status: Accepted

Solution code:
def main():
    ABCD = input()

    total = 0
    mask = 0
    n = len(ABCD)
    while mask < (1<<(n-1)):
        i = 0
        s = list(ABCD)
        while i < n-1:
            if mask & (1<<i):
                s[i] = s[i] + '+'
            else:
                s[i] = s[i] + '-'
            i += 1
        total = eval(''.join(s))
        if total == 7:
            break
        mask += 1

    print(*s, sep='', end='')
    print('=' + str(total))

main()

Submission status: Accepted

Solution code:
ABCD = list(input())

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

ops = [["+","+","+"], ["+","+","-"], ["+","-","+"], ["-","+","+"],
       ["-","-","+"], ["-","+","-"], ["+","-","-"], ["-","-","-"]]

for op1, op2, op3 in ops:
    AB = Calc(ABCD[0],ABCD[1],op1)
    ABC = Calc(AB, ABCD[2], op2)
    ans = Calc(ABC, ABCD[3], op3)

    if ans == 7:
        print(ABCD[0]+op1+ABCD[1]+op2+ABCD[2]+op3+ABCD[3] + "=7")
        break

Submission status: Accepted

Solution code:
x=list(map(int,list(input())))
a=x[0]
b=x[1]
c=x[2]
d=x[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")

Submission status: Accepted

Solution code:
from sys import stdin

def Int_all(): return list(map(int, stdin))
def IL():return list(map(int, stdin.readline().split()))


def dfs(i,s):

	if i == 4:
		return s==7

	if dfs(i+1,s+a[i]):
		if i != 0:
			ans[i] = "+"+str(a[i])
		else:
			ans[i] = str(a[i])
		return True
	if dfs(i+1, s-a[i]):
		if i != 0:
			ans[i] = "-"+str(a[i])
		else:
			ans[i] = str(a[i])
		
		return True

	return False



a = list(map(int,list(input())))
ans = [0 for i in range(4)]

def main():
	dfs(0,0)
	print("{}=7".format(''.join(ans)))

if __name__ == "__main__": main()

Submission status: Accepted

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

def calc(ind, x):
    if ind == 0:
        return x
    else:
        return -x

flag = 0
for j in range(2):
    ans1 = a
    if flag:
        break
    ans2 = ans1 + calc(j, b)
    for k in range(2):
        if flag:
            break
        ans3 = ans2 + calc(k, c)
        for l in range(2):
            ans4 = ans3 + calc(l, d)
            if ans4 == 7:
                flag = 1
                result = ['+' if x == 0 else '-' for x in [j, k, l]]
                break
answer = str(a) + result[0] + str(b) + result[1] + str(c) + result[2] + str(d) + '=7'
print (answer)

Submission status: Accepted

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

N = int(input())

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

tmp = [0 for i in range(8)]
tmp2 = ['{}+{}+{}+{}'.format(a, b, c, d), '{}+{}+{}-{}'.format(a, b, c, d),
        '{}+{}-{}+{}'.format(a, b, c, d), '{}+{}-{}-{}'.format(a, b, c, d),
        '{}-{}+{}+{}'.format(a, b, c, d), '{}-{}+{}-{}'.format(a, b, c, d),
        '{}-{}-{}+{}'.format(a, b, c, d), '{}-{}-{}-{}'.format(a, b, c, d)]

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

for i in range(8):
    if(tmp[i] == 7):
        x = i
        break

print(str(tmp2[i])+'=7')

Submission status: Accepted

Solution code:
a,b,c,d = map(int,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")
else:
    print(str(a)+ "-" +str(b) +"-"+ str(c) +"-"+ str(d)+ "=7")

Submission status: Accepted

Solution code:
s = input()
ops = "+-"

for op1 in ops :
    for op2 in ops :
        for op3 in ops :
            exp = s[0]+op1+s[1]+op2+s[2]+op3+s[3]
            val = eval(exp)
            if val == 7 :
                print(exp + '=7')
                exit(0)

Submission status: Accepted

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

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