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:
N = input()
H = [int(N[0]), int(N[1]), int(N[2]), int(N[3])]
A = H[0]
B = H[1]
C = H[2]
D = H[3]
# A = N[0], B = N[1], C = N[2], D = N[3]
# a = N[0], b = N[1], c = N[2], d = N[3]
# A = int(a), B = int(b), C = int(c), D = int(d)
c1 = {'op1':'+', 'op2':'+', 'op3':'+'}
c2 = {'op1':'+', 'op2':'+', 'op3':'-'}
c3 = {'op1':'+', 'op2':'-', 'op3':'+'}
c4 = {'op1':'+', 'op2':'-', 'op3':'-'}
c5 = {'op1':'-', 'op2':'+', 'op3':'+'}
c6 = {'op1':'-', 'op2':'+', 'op3':'-'}
c7 = {'op1':'-', 'op2':'-', 'op3':'+'}
c8 = {'op1':'-', 'op2':'+', 'op3':'+'}

if A+B+C+D == 7:
    print(str(A) + c1['op1'] + str(B) + c1['op2'] + str(C) + c1['op3'] + str(D) + '=7')
elif A+B+C-D == 7:
    print(str(A) + c2['op1'] + str(B) + c2['op2'] + str(C) + c2['op3'] + str(D) + '=7')
elif A+B-C+D == 7:
    print(str(A) + c3['op1'] + str(B) + c3['op2'] + str(C) + c3['op3'] + str(D) + '=7')
elif A+B-C-D == 7:
    print(str(A) + c4['op1'] + str(B) + c4['op2'] + str(C) + c4['op3'] + str(D) + '=7')
elif A-B+C+D == 7:
    print(str(A) + c5['op1'] + str(B) + c5['op2'] + str(C) + c5['op3'] + str(D) + '=7')
elif A-B+C-D == 7:
    print(str(A) + c6['op1'] + str(B) + c6['op2'] + str(C) + c6['op3'] + str(D) + '=7')
elif A-B-C+D == 7:
    print(str(A) + c7['op1'] + str(B) + c7['op2'] + str(C) + c7['op3'] + str(D) + '=7')
elif A-B-C-D == 7:
    print(str(A) + c8['op1'] + str(B) + c8['op2'] + str(C) + c8['op3'] + str(D) + '=7')

Submission status: Accepted

Solution code:
lis = map(int,list(raw_input()))
outop = []
out = ""
for i in xrange(8):
	n2 = format(i,"03b")
	oplis = map(int,list(str(n2)))
	sum = lis[0]
	for num in xrange(3):
		if oplis[num] == 1:
			sum += lis[num+1]
		else:
			sum -= lis[num+1]
	if sum == 7:
		for op in oplis:
			if op == 1:
				outop.append("+")
			else:
				outop.append("-")
		print  "{0[0]}{1[0]}{0[1]}{1[1]}{0[2]}{1[2]}{0[3]}=7".format(lis,outop)
		break

Submission status: Accepted

Solution code:
N=input();a=int(N[0]);b=int(N[1]);c=int(N[2]);d=int(N[3]);A=""
if a+b+c+d == 7:
    A = N[0]+"+"+N[1]+"+"+N[2]+"+"+N[3]+"=7"
elif a+b+c-d == 7:
    A = N[0]+"+"+N[1]+"+"+N[2]+"-"+N[3]+"=7"
elif a+b-c+d == 7:
    A = N[0]+"+"+N[1]+"-"+N[2]+"+"+N[3]+"=7"
elif a-b+c+d == 7:
    A = N[0]+"-"+N[1]+"+"+N[2]+"+"+N[3]+"=7"
elif a-b-c+d == 7:
    A = N[0]+"-"+N[1]+"-"+N[2]+"+"+N[3]+"=7"
elif a+b-c-d == 7:
    A = N[0]+"+"+N[1]+"-"+N[2]+"-"+N[3]+"=7"
elif a-b+c-d == 7:
    A = N[0]+"-"+N[1]+"+"+N[2]+"-"+N[3]+"=7"
else:
    A = N[0]+"-"+N[1]+"-"+N[2]+"-"+N[3]+"=7"
print(A)

Submission status: Accepted

Solution code:
def main():
    s=input()
    a=int(s[0])
    b=int(s[1])
    c=int(s[2])
    d=int(s[3])
    ansst=""
    def rec3(ans):
        if ans+d==7:
            ansst="+"+str(d)+"=7"
            return ansst
        if ans-d==7:
            ansst="-"+str(d)+"=7"
            return ansst
        return ""
    def rec2(ans):
        ansst=rec3(ans+c)
        if ansst:
            ansst="+"+str(c)+ansst
            return ansst
        ansst=rec3(ans-c)
        if ansst:
            ansst="-"+str(c)+ansst
            return ansst
        return ""

    def rec(ans):
        ansst=rec2(ans+b)
        if ansst:
            ansst=str(a)+"+"+str(b)+ansst
            return ansst
        ansst=rec2(ans-b)
        if rec2(ans-b):
            ansst=str(a)+"-"+str(b)+ansst
            return ansst
        return False
    print(rec(a))
    
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
s = raw_input()
A = int(s[0])
B = int(s[1])
C = int(s[2])
D = int(s[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 = 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")
elif a-b+c+d == 7:
    print(str(a) + "-" + str(b) + "+" + str(c) + "+" + str(d) + "=" + "7")

Submission status: Accepted

Solution code:
ABCD = input()
ABCD_list = [int(num_str) for num_str in str(ABCD)]

pm_pairs = ["+++", "++-", "+-+", "+--", "-++", "-+-", "--+", "---"]

for pm in pm_pairs:
    sum = ABCD_list[0]
    if pm[0] == "+":
        sum += ABCD_list[1]
    else:
        sum -= ABCD_list[1]

    if pm[1] == "+":
        sum += ABCD_list[2]
    else:
        sum -= ABCD_list[2]

    if pm[2] == "+":
        sum += ABCD_list[3]
    else:
        sum -= ABCD_list[3]

    if sum == 7:
        print(str(ABCD_list[0]) + pm[0] + str(ABCD_list[1]) + pm[1] +
              str(ABCD_list[2]) + pm[2] + str(ABCD_list[3]) + "=7")
        exit()

Submission status: Accepted

Solution code:
N=int(input())
a=N//1000
b=N//100 - 10*a
c=N//10 - 100*a -10*b
d=N%10
dic={0:"+",1:"-"}

s=a+b+c+d
for i in range(2):
    for j in range(2):
        for k in range(2):
            l=i*b+j*c+k*d
            if(s-2*l==7):
                ans=str(a)+dic[i]+str(b)+dic[j]+str(c)+dic[k]+str(d)+"=7"
print(ans)

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('{}+{}+{}+{}=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:
s=list(input())
op=['+','-']
for i in op:
    for j in op:
        for k in op:
            expr=s[0]+i+s[1]+j+s[2]+k+s[3]
            if eval(expr)==7:
                print(expr+'=7')
                exit()

Submission status: Accepted

Solution code:
abcd = list(input())

o = [1, 1, 1]
o2 = []
# print(abcd)
for i in range(2):
    o[0] *= -1
    for j in range(2):
        o[1] *= -1
        for k in range(3):
            o[2] *= -1
            ans = int(abcd[0]) + int(abcd[1])*o[0] + int(abcd[2])*o[1] + int(abcd[3])*o[2]
            # print(ans, i, j, k)
            if ans == 7:
                for l in o:
                    if l > 0:
                        o2.append('+')
                    else:
                        o2.append('-')
                print(abcd[0] + o2[0] + abcd[1] + o2[1] + abcd[2] + o2[2] + abcd[3] + '=7')
                quit()

Submission status: Accepted

Solution code:
x = int(input())
a=b=c=0

for i in range(1,5):
    if i==1:
        d=x%10
    elif i==2:
        c=x%10
    elif i==3:
        b=x%10
    else:
        a=x%10

    x/=10
    x = int(x)


#apply 8 combinations

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:
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc079/tasks/abc079_c

"""
import sys
from sys import stdin
from itertools import product
input = stdin.readline


def main(args):
    temp = input().strip()
    A = int(temp[0])
    B = int(temp[1])
    C = int(temp[2])
    D = int(temp[3])

    op1, op2, op3 = None, None, None
    exp = None
    for op1, op2, op3 in product('+-', repeat=3):
        exp = '{}{}{}{}{}{}{}'.format(A, op1, B, op2, C, op3, D)
        if eval(exp) == 7:
            break
    print(exp + '=7')


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

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


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:
s=input()
listA=[0,0,0,0]
i=0
for x in s:
    listA[i]=int(x)
    i+=1
a=listA[0]
b=listA[1]
c=listA[2]
d=listA[3]
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:
#!/usr/bin/env python

Num =list(input())
ope = ["+", "-"]

for i in range(8):
    key = list(str(("{0:03b}".format(i,'b'))))
    formula = Num[0] + ope[int(key[0])] + Num[1] + ope[int(key[1])] + Num[2] + ope[int(key[2])] + Num[3]
    result = eval(formula)
    if(result == 7):
        print("".join([formula,"=7"]))
        break

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:
s = input()
for i in range(2):
    for j in range(2):
        for k in range(2):
            a = int(s[0])
            if i == 0:
                a += int(s[1])
            else:
                a -= int(s[1])
            if j == 0:
                a += int(s[2])
            else:
                a -= int(s[2])
            if k == 0:
                a += int(s[3])
            else:
                a -= int(s[3])
            if a == 7:
                print("{0}{4}{1}{5}{2}{6}{3}=7".format(s[0],s[1],s[2],s[3],"-" if i else "+","-" if j else "+","-" if k else "+"))
                exit()

Submission status: Accepted

Solution code:
ABCD = input()
# ABCD = "3242"

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

from operator import add, sub
import sys


def f(x):
    return "+" if x == add else "-"


# 2^3
# naive
for op1 in [add, sub]:
    for op2 in [add, sub]:
        for op3 in [add, sub]:
            s = op3(op2(op1(ABCD[0], ABCD[1]), ABCD[2]), ABCD[3])
            if s == 7:
                print("{}{}{}{}{}{}{}=7".format(
                    ABCD[0], f(op1), ABCD[1], f(op2), ABCD[2], f(op3), ABCD[3]))
                sys.exit(0)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    a = [int(c) for c in S()]
    for i in range(8):
        c = a[0]
        r = [a[0]]
        for j in range(3):
            if i&(2**j):
                c += a[j+1]
                r.append('+')
            else:
                c -= a[j+1]
                r.append('-')
            r.append(a[j+1])
        if c == 7:
            return ''.join(map(str,r)) + '=7'

    return -1



print(main())

Submission status: Accepted

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

print(find_eq(input()))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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):
#     print("1;",i,method)
    goukei1 = method(a,b)
    for j,method2 in enumerate(pm_list):
#         print("2;",j,method2)
        goukei2 = method2(goukei1,c)
        for k,method3 in enumerate(pm_list):
#             print("3;",k,method3)
            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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    if 7 + N[2] + N[3] == N[0] + N[1]: #A+B
        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]: #A - B
        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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

# 4近傍（右, 下, 左, 上）
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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:


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

Submission status: Accepted

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

Submission status: Accepted

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