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:
import sys
t = list(map(int, list(input())))
t.append(7)
op = []

def dfs(x, i):
    if i == 4 or len(op) == 3:
        if x == 7:
            op.append('=')
            ans = ''
            for j in range(5):
                if j == 4:
                    ans += str(t[j])
                else:
                    ans += str(t[j]) + op[j]
            print(ans)
            sys.exit(0)
        return

    i += 1
    op.append('+')
    dfs(x + t[i], i)
    op.pop()

    op.append('-')
    dfs(x - t[i], i)
    op.pop()
    i -= 1

    return

dfs(t[0], 0)

Submission status: Accepted

Solution code:
a=list(input())
for i in range(1<<3):
    ans=""
    ans+=a[0]
    for j in range(3):
        if i&(1<<j):
            ans+="+"
        else:
            ans+="-"
        ans+=a[j+1]
    temp=eval(ans)
    if temp==7:
        print(ans+"=7")
        exit()

Submission status: Accepted

Solution code:
import sys

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

signs = ['+' , '-']

for i in range(2):
    for j in range(2):
        for k in range(2):
            ans = A+signs[i]+B+signs[j] + C + signs[k] + D
            if eval(ans) == 7:
                print(ans + '=7')
                sys.exit()

Submission status: Accepted

Solution code:
from itertools import product
input_int_list = list(map(int, input()))

for operator_comb in product(range(2), repeat = len(input_int_list)-1):
    sum_value = input_int_list[0]
    formula_str = str(input_int_list[0])
    for i, operator in enumerate(operator_comb):
        if operator == 0:
            sum_value += input_int_list[i+1]
            formula_str += '+' + str(input_int_list[i+1])
        else:
            sum_value -= input_int_list[i+1] 
            formula_str += '-' + str(input_int_list[i+1])
    if sum_value == 7:
        print(formula_str + '=7')
        break

Submission status: Accepted

Solution code:
input_list = [int(data) for data in list(input())]
for i in [1, -1]:
    op1 = ''
    if i == 1:
        op1 = '+'
    else:
        op1 = '-'
    for j in [1, -1]:
        op2 = ''
        if j == 1:
            op2 = '+'
        else:
            op2 = '-'
        for k in [1, -1]:
            op3 = ''
            if k == 1:
                op3 = '+'
            else:
                op3 = '-'
            if input_list[0] + i * input_list[1] + j * input_list[2] + k * input_list[3] == 7:
                print(str(input_list[0]) + op1 + str(input_list[1]) + op2 + str(input_list[2]) + op3 + str(input_list[3]) + '=7')
                exit()

Submission status: Accepted

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

def cal(a, b, opx):
    if opx == "+":
        return a + b
    else:
        return a - b

op = ["+", "-"]
result = ""
for op1 in op:
    for op2 in op:
        for op3 in op:
            if cal(cal(cal(A, B, op1),C,  op2), D, op3) == 7:
                print(str(A) + op1 + str(B) + op2 + str(C) + op3 + str(D) + "=7")
                exit()

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

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

for flag in itertools.product([0,1], repeat=3):
	tmp = li[0]
	for i,fl in enumerate(flag):
		if fl:
			tmp += li[i+1]
		else:
			tmp -= li[i+1]

	if tmp == 7:
		ans = ''
		for i in range(3):
			ans = ans + str(li[i])
			if flag[i]:
				ans = ans + '+'
			else:
				ans = ans + '-'
		ans = ans + str(li[3]) + '=7'
		break

print(ans)

Submission status: Accepted

Solution code:
import sys
A, B, C, D = map(int, input())

for i in range(2):
  for j in range(2):
    for k in range(2):
      answer = A
      answer = answer + B if i == 0 else answer - B
      answer = answer + C if j == 0 else answer - C
      answer = answer + D if k == 0 else answer - D
      if answer == 7:
        o1 = '+' if i == 0 else '-'
        o2 = '+' if j == 0 else '-'
        o3 = '+' if k == 0 else '-'
        print('{}{}{}{}{}{}{}=7'.format(A,o1,B,o2,C,o3,D))
        sys.exit()

Submission status: Accepted

Solution code:
a, b, c, d = [int(_) for _ in 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:
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 10 03:26:19 2018

@author: Yuki
"""

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

def calc(num1, num2, op):
    if op=='+':
        return num1 + num2
    else:
        return num1 - num2
flag = False
for op1 in ['+', '-']:
    for op2 in ['+', '-']:
        for op3 in ['+', '-']:
            if calc(calc(calc(A, B, op1), C, op2), D, op3)==7:
                flag = True
            if flag:
                break
        if flag:
            break
    if flag:
        break
print(s[0]+op1+s[1]+op2+s[2]+op3+s[3]+'=7')

Submission status: Accepted

Solution code:
l = list(input())
for a in ["+", "-"]:
    for b in ["+", "-"]:
        for c in ["+", "-"]:
            if eval(l[0]+a+l[1]+b+l[2]+c+l[3]) == 7:
                print(l[0]+a+l[1]+b+l[2]+c+l[3]+"=7")
                exit()

Submission status: Accepted

Solution code:
d = input()
for a in '+-':
    for b in '+-':
        for c in '+-':
            s = d[0] + a + d[1] + b + d[2] + c + d[3]
            if eval(s)==7:
                print(s+'=7')
                break
        else:
            continue
        break
    else:
        continue
    break

Submission status: Accepted

Solution code:
n = input()


for i in range(1<<(len(n)-1)):
    num = int(n[0])
    ope =[]
    for j in range(0,len(n)-1):
        if i & (1 << j):
            num += int(n[j+1])
            ope.append('+')
        else:
            num -= int(n[j+1])
            ope.append('-')
    if num == 7:
        for k in range(len(n)):
            if k == len(n) -1:
                print(n[k],"=7",sep="",end="")
            else:
                print(n[k],end="")
                print(ope[k],end="")

        break

Submission status: Accepted

Solution code:
a, b, c, d = input()
op = ["+", "-"]
for i in op:
  for j in op:
    for k in op:
      result = a + i + b + j + c + k + d
      if eval(result) == 7:
        print(result + "=7")
        exit()

Submission status: Accepted

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

line = list(input())
a = int(line[0])
b = int(line[1])
c = int(line[2])
d = int(line[3])

op = ["+", "-"]

for op1 in op:
    for op2 in op:
        for op3 in op:
            ret = a
            if op1=="+":
                ret += b
            else:
                ret -= b
            if op2=="+":
                ret += c
            else:
                ret -= c
            if op3=="+":
                ret += d
            else:
                ret -= d
            if ret==7:
                print(a,op1,b,op2,c,op3,d,"=7",sep="")
                exit()

Submission status: Accepted

Solution code:
# bit 全探索
# https://beta.atcoder.jp/contests/abc079/tasks/abc079_c

if __name__ == '__main__':
    v = input()
    d = len(v) - 1

    for bit in range(1 << d):
        expr_i = v[0]
        sum_i = int(v[0])
        for i in range(d):
            if bit & (1 << i) != 0:
                expr_i += '+' + v[i + 1]
                sum_i += int(v[i + 1])
            else:
                expr_i += '-' + v[i + 1]
                sum_i -= int(v[i + 1])

        if sum_i == 7:
            expr_i += '=7'
            print(expr_i)
            exit(0)

Submission status: Accepted

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

l = [a]
l2 = []
for x in l:
    
    l2.append(x+b)
    l2.append(x-b)
l = l2
l2 = []
for x in l:
    
    l2.append(x+c)
    l2.append(x-c)
l = l2

l2 = []
for x in l:
    
    l2.append(x+d)
    l2.append(x-d)
l = l2

k = l.index(7)
if k <= 3:
    w1 = '+'
else:
    w1 = '-'

if k == 0 or k == 1 or k == 4 or k == 5:
    w2 = '+'
else:
    w2 = '-'
    
if k%2 == 0:
    w3 = '+'
else:
    w3 = '-'
    
print(s[0] + w1 + s[1] + w2 + s[2] + w3+ s[3] +'=7')

Submission status: Accepted

Solution code:
N = list(input())
op = ['+','-']

for i in range(2):
    for j in range(2):
        for k in range(2):
                ans = 0
                if (op[i] == '+'):
                    ans = int(N[0]) + int(N[1])
                else:
                    ans = int(N[0]) - int(N[1])
                if (op[j] == '+'):
                    ans += int(N[2])
                else:
                    ans -= int(N[2])
                if (op[k] == '+'):
                    ans += int(N[3])
                else:
                    ans -= int(N[3])
                if (ans == 7):
                    print(N[0]+op[i]+N[1]+op[j]+N[2]+op[k]+N[3]+"=7")
                    quit()

Submission status: Accepted

Solution code:
a, b, c, d = input()

for x in "+-":
	for y in "+-":
		for z in "+-":
			formula = a +x+ b +y+ c +z+ d
			if eval(formula) == 7:
				print(formula + "=7")
				exit()

Submission status: Accepted

Solution code:
inp = input()

for i in range(1<<4):
    ans = ''
    for j in range(len(inp)-1):
        if i & (1<<j):
            ans = ans+inp[j]+'+'
        else:
            ans = ans+inp[j]+'-'
    ans = ans+inp[-1]

    if eval(ans) == 7:
        print(ans+'=7')
        break

Submission status: Accepted

Solution code:

S=input()
list1=[]
for i in range(4):
    list1.append(int(S[i]))
#print(list1)

list2=[]
for j in range(8):
    k=j
    list2.append(int(k/4))
    k=j%4
    list2.append(int(k/2))
    k=j%2
    list2.append(int(k/1))
    #print(list2)
    
    if list2[0]==1:
        A=list1[0]+list1[1]
    else:
        A=list1[0]-list1[1]
    if list2[1]==1:
        A=A+list1[2]
    else:
        A=A-list1[2]
    if list2[2]==1:
        A=A+list1[3]
    else:
        A=A-list1[3]
    if A==7:
        list3=[]
        for a in range(3):
            if list2[a]==0:
                list3.append("-")
            else:
                list3.append("+")
        print(str(list1[0])+list3[0]+str(list1[1])+list3[1]+str(list1[2])+list3[2]+str(list1[3])+"=7")
        ans=1
        break
    list2=[]

Submission status: Accepted

Solution code:
def main():
    s=input()
    for i in ["+","-"]:
        for j in ["+","-"]:
            for k in ["+","-"]:
                b=s[0]+i+s[1]+j+s[2]+k+s[3]
                if eval(b)==7:
                    print(b+"=7")
                    return

main()

Submission status: Accepted

Solution code:

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

def fn(op1, op2, op3):
    msg = A + op1 + B + op2 + C + op3 + D
    if eval(msg) == 7:
        print(msg + "=7")
        exit()


for op1 in ("+","-"):
    for op2 in ("+","-"):
        for op3 in ("+","-"):
            fn(op1, op2, op3)

Submission status: Accepted

Solution code:
s = [int(x) for x in input()]
 
def f(c, n):
    if n == 4:
        if eval(c) == 7:
            return c + "=7"
        else:
            return None
    v = s[n]
    for o in ['+', '-']:
        ret = f('%s%s%d' % (c,o,v), n + 1)
        if ret:
            return ret
print(f(str(s[0]), 1))

Submission status: Accepted

Solution code:
N = list(map(int, list(input())))

s = sum(N)
op = ["+", "+", "+"]
def print_result(numbers, ops):
    print("{}{}{}{}{}{}{}=7".format(numbers[0], ops[0],
                                 numbers[1], ops[1],
                                 numbers[2], ops[2],
                                 numbers[3]))
        
if s == 7:
    print_result(N, op)
elif (N[0] - N[1] - N[2] - N[3]) == 7:
    print_result(N, ["-", "-", "-"])
else:
    d = (s - 7) / 2
    indexes = [i for i, x in enumerate(N) if x == d]
    if len(indexes) > 1:
        op[indexes[-1] - 1] = "-"
        print_result(N, op)
        exit()
    elif len(indexes) > 0 and (not indexes[0] == 0):
        op[indexes[0] - 1] = "-"
        print_result(N, op)
    else:
        if (N[0] - N[1] - N[2] + N[3]) == 7:
            print_result(N, ["-", "-", "+"])
        elif (N[0] - N[1] +  N[2] - N[3]) == 7:
            print_result(N, ["-", "+", "-"])
        else:
            print_result(N, ["+", "-", "-"])

Submission status: Accepted

Solution code:
N = input()
A, B, C, D = N[0], N[1], N[2], N[3]
def fn(op1, op2, op3):
    msg = A + op1 + B + op2 + C + op3 + D
    if eval(msg) == 7:
        print(msg + "=7")
        exit()

for op1 in ('+', '-'):
    for op2 in ('+', '-'):
        for op3 in ('+', '-'):
            fn(op1, op2, op3)

Submission status: Accepted

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

import functools
@functools.lru_cache(maxsize=None)
def f(c, n):
    if n == 4:
        if c == 7:
            return []
        else:
            return None
    v = s[n]
    for o in ['+', '-']:
        ret = f(eval('%d%s%d'% (c,o,v)), n + 1)
        if ret is not None:
            return [o, v] + ret
print(''.join([str(x) for x in ([s[0]] + f(s[0], 1))]) + '=7')

Submission status: Accepted

Solution code:
a, b, c, d = [int(s) for s in input()]
ans = [str(a), '+', str(b), '+', str(c), '+', str(d), '=7']
for i in range(-1, 2, 2):
  for j in range(-1, 2, 2):
    for k in range(-1, 2, 2):
      if a + b * i + c * j + d * k == 7:
        ans[1] = '+' if i > 0 else '-'
        ans[3] = '+' if j > 0 else '-'
        ans[5] = '+' if k > 0 else '-'
print(''.join(ans))

Submission status: Accepted

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

def main():
    a, b, c, d = [int(i) for i in list(input())]
    lists = [b, c, d]

    for i in range(2 ** 3):
        s = a
        ops = list('{:03b}'.format(i))
        for op, j in zip(ops, lists):
            if op == '0':
                s += j
            else:
                s -= j
        if s == 7:
            sen = str(a)
            for j, k in zip(lists, ops):
                if k == '0':
                    op1 = '+'
                else:
                    op1 = '-'
                sen = sen + op1 + str(j)
            print(sen + '=7')
            break

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()

def do_eval(s) :
    res = 0
    am_flg = 1
    
    for i in list(s): 
        if i == '+' :
            am_flg = 1
        elif i == '-' :
            am_flg = -1
        else :
            res += int(i) * am_flg
            
    return res    

A, B, C, D = list(S)[0], list(S)[1], list(S)[2], list(S)[3]
evaled = False 

for i in list('+-') :
    for j in list('+-') :
        for k in list('+-') :
            toeval = A + i + B + j + C + k + D
            
            if do_eval(toeval) == 7 :
                print(toeval + "=7")
                evaled = True
                break
        if evaled == True :
            break
    if evaled == True :
        break

Submission status: Accepted

Solution code:
from itertools import product
S = list(input())
S = [int(x) for x in S]
z = [0 for _ in range(3)]
for x in product(range(2), repeat = 3):
    y = S[0]
    for i in range(1,4):
        if x[i-1] == 0:
            y += S[i]
        else:
            y -= S[i]
    if y == 7:
        z = x
        break
ans = str(S[0])
for i in range(1,4):
    if z[i-1] == 0:
        ans += '+'
    else:
        ans += '-'
    ans += str(S[i])
ans += '=7'
print(ans)

Submission status: Accepted

Solution code:
ary = list(map(int, input()))

# それぞれ数ごと
for i in range(1 << 3):
    tmp = ary[0]
    ans = str(ary[0])
    for j in range(3):
        if i & (1 << j):
            tmp += ary[j + 1]
            ans += "+" + str(ary[j + 1])
        else:
            tmp -= ary[j + 1]
            ans += "-" + str(ary[j + 1])

    if tmp == 7:
        print(ans + '=7')
        break

Submission status: Accepted

Solution code:
abcd = input()
hugou = ["+","-"]
a,b,c,d = list(abcd)
for i in hugou:
    for j in hugou:
        for k in hugou:
            wa = a + i + b + j + c + k + d
            if eval(wa) == 7:
                print(str(wa)+'=7')
                exit()

Submission status: Accepted

Solution code:
siki = list(input())

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



if A+B+C+D ==7:
    ans = str(A),'+',str(B),'+',str(C),'+',str(D),'=7'
    print(''.join(map(str, ans)))
elif A+B-C+D ==7:
    ans = str(A),'+',str(B),'-',str(C),'+',str(D),'=7'
    print(''.join(map(str, ans)))
elif A+B+C-D ==7:
    ans = str(A),'+',str(B),'+',str(C),'-',str(D),'=7'
    print(''.join(map(str, ans)))
elif A-B+C+D ==7:
    ans = str(A),'-',str(B),'+',str(C),'+',str(D),'=7'
    print(''.join(map(str, ans)))
elif A-B-C+D ==7:
    ans = str(A),'-',str(B),'-',str(C),'+',str(D),'=7'
    print(''.join(map(str, ans)))
elif A-B+C-D ==7:
    ans = str(A),'-',str(B),'+',str(C),'-',str(D),'=7'
    print(''.join(map(str, ans)))
elif A+B-C-D ==7:
    ans = str(A),'+',str(B),'-',str(C),'-',str(D),'=7'
    print(''.join(map(str, ans)))
elif A-B-C-D ==7:
    ans = str(A),'-',str(B),'-',str(C),'-',str(D),'=7'
    print(''.join(map(str, ans)))

Submission status: Accepted

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

tot=A
S=''
for bits in range(1<<3):
    if bits & 1:
        tot += B
        S += '+'
    else:
        tot -= B
        S += '-'
    if bits & 1<<1:
        tot += C
        S += '+'
    else:
        tot -= C
        S += '-'
    if bits & 1<<2:
        tot += D
        S += '+'
    else:
        tot -= D
        S += '-'
    if tot==7:
        print(str(A)+S[0]+str(B)+S[1]+str(C)+S[2]+str(D)+'=7')
        quit()
    else:
        S=''
        tot=A
        pass

Submission status: Accepted

Solution code:
flag = 1

def search(num, digit, res, op):
    global flag
    if digit == 4:
        if res == 7:
            op += "="
            ans = "".join(n+o for n,o in zip(num, op))
            if flag:
                print(ans + "7")
                flag = 0

    else:
        search(num, digit+1, res+int(num[digit]), op+"+")
        search(num, digit+1, res-int(num[digit]), op+"-")
        
num = input()
search(num,1,int(num)//1000,"")

Submission status: Accepted

Solution code:
e = input()
op = ("+", "-")
for i in range(8):
  t = ""
  for j in range(4):
    k = i>>j&1
    t += e[j]+op[k]
  t = t[:-1:]
  if eval(t)==7:
    print(t+"=7")
    break

Submission status: Accepted

Solution code:
o=["+","-"]
a,b,c,d=list(input())
for i in o:
    for j in o:
        for k in o:
            t=a+i+b+j+c+k+d
            if eval(t)==7:
                print(t+"=7")
                exit()

Submission status: Accepted

Solution code:
s = input()
a,b,c,d = [int(s[i]) for i in range(len(s))]

op1 = '+'
op2 = '+'
op3 = '+'

if a+b+c-d==7:
    op3 = '-'
elif a+b-c+d==7:
    op2 = '-'
elif a-b+c+d==7:
    op1 = '-'
elif a+b-c-d==7:
    op3 = '-'
    op2 = '-'
elif a-b+c-d==7:
    op3 = '-'
    op1 = '-'
elif a-b-c+d==7:
    op1 = '-'
    op2 = '-'
elif a-b-c-d==7:
    op3 = '-'
    op2 = '-'
    op1 = '-'

print(a,op1,b,op2,c,op3,d,"=7",sep='')

Submission status: Accepted

Solution code:
s = input()

n = 4

for i in range(2 ** (n-1)):
    formula = s[0]
    for j in range(n-1):
        if i >> j & 1 == 1:
            formula += '+{}'.format(s[j+1])
        else:
            formula += '-{}'.format(s[j+1])

    if eval(formula) == 7:
        print(formula+'=7')
        exit()

Submission status: Accepted

Solution code:
A, B, C, D = map(int, input())
for i in range(8):
    sum = 0
    op1 = "+" if i // 4 % 2 == 0 else "-"
    op2 = "+" if i // 2 % 2 == 0 else "-"
    op3 = "+" if i % 2 == 0 else "-"
    if op1 == "+":
        sum = A + B
    else:
        sum = A - B
    if op2 == "+":
        sum += C
    else:
        sum -= C
    if op3 == "+":
        sum += D
    else:
        sum -= D
    if sum == 7:
        print(str(A) + op1 + str(B) + op2 + str(C) + op3 + str(D) + "=7")
        break

Submission status: Accepted

Solution code:
s = input()

max = 2 ** 3

for i in range(max):
    b = bin(i)[2:].zfill(3)
    op = []
    test = int(s[0])
    for j, flag in enumerate(b):
        if flag == '1':
            test += int(s[j+1])
            op.append('+')
        else:
            test -= int(s[j+1])
            op.append('-')
    if test == 7:
        break

print(s[0]+op[0]+s[1]+op[1]+s[2]+op[2]+s[3]+'=7')

Submission status: Accepted

Solution code:
S=input()
for i in range(8):
    s=S[0]+''.join('+-'[i>>j&1]+c for j,c in enumerate(S[1:]))
    if eval(s)==7:
        print(s+'=7')
        break

Submission status: Accepted

Solution code:
S=input()
for i in range(8):
    s=S[0:1]+''.join('+-'[i>>j&1]+c for j,c in enumerate(S[1:]))
    if eval(s)==7:
        print(s+'=7')
        break

Submission status: Accepted

Solution code:
S = input()

op = [0]*3
tmp = [0]*4
for i in range(2):
    tmp[0] = int(S[0])
    if i == 0:
        tmp[1] = int(S[1])
        op[0] = '+'
    else:
        tmp[1] = -int(S[1])
        op[0] = '-'
    for j in range(2):
        if j == 0:
            tmp[2] = int(S[2])
            op[1] = '+'
        else:
            tmp[2] = -int(S[2])
            op[1] = '-'
        for k in range(2):
            if k == 0:
                tmp[3] = int(S[3])
                op[2] = '+'
            else:
                tmp[3] = -int(S[3])
                op[2] = '-'
            if sum(tmp) == 7:
                print(S[0] + op[0] + S[1] + op[1] + S[2] + op[2] + S[3] + '=7')

                exit()

Submission status: Accepted

Solution code:
import itertools as it
s = input()
for p in it.product('+-',repeat=3):
    formula = ''.join([a+(b if b else '') for a,b in it.zip_longest(s,p)])
    if eval(formula) == 7:
        print(formula + '=7')
        exit()

Submission status: Accepted

Solution code:
import itertools
s = input()
for p in itertools.product('+-',repeat=3):
    formula = s[0]+p[0]+s[1]+p[1]+s[2]+p[2]+s[3]
    if eval(formula) == 7:
        print(formula + '=7')
        exit()

Submission status: Accepted

Solution code:
n = input()

a = ['+','-']
b = ''
for i in a:
    for j in a:
        for k in a:
            if eval(n[0]+i+n[1]+j+n[2]+k+n[3]) == 7:
                b =n[0]+i+n[1]+j+n[2]+k+n[3]+'=7'
                break
print(b)

Submission status: Accepted

Solution code:
s = list(map(int, input()))

ans = []

for i in range(8):
        isseven = 0
        ans = []
        if i < 4:
            isseven += (s[0] + s[1])
            ans.append('+')
        else:
            isseven += (s[0] - s[1])
            ans.append('-')
        if i % 4 == 0 or i % 4 == 1:
            isseven += s[2]
            ans.append('+')
        else:
            isseven -= s[2]
            ans.append('-')
        if i % 2 == 0:
            isseven += s[3]
            ans.append('+')
        else:
            isseven -= s[3]
            ans.append('-')
        if isseven == 7:
            break

for i in range(3):
    print(str(s[i]) + ans[i], end = '')

print(str(s[3]) + "=7")

Submission status: Accepted

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

def ope(i,a,b):
    if i == 0:
        return a + b
    elif i == 1:
        return a - b

def convert(i):
    if i == 0:
        return "+"
    elif i == 1:
        return "-"


def search(a,b,c,d):
    for i in range(2):
        for j in range(2):
            for k in range(2):
                if ope(k,ope(j,ope(i,a,b),c),d) == 7:
                    return str(a) + convert(i) + str(b) + convert(j) + str(c) + convert(k) + str(d)

print(search(a,b,c,d)+"=7")

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    num = input()
    num_list = [int(i) for i in str(num)]

    A = num_list[0]
    B = num_list[1]
    C = num_list[2]
    D = num_list[3]

    if A + B + C + D == 7:
        print("{0}+{1}+{2}+{3}=7".format(A, B, C, D))
    elif A + B + C - D == 7:
        print("{0}+{1}+{2}-{3}=7".format(A, B, C, D))
    elif A + B - C + D == 7:
        print("{0}+{1}-{2}+{3}=7".format(A, B, C, D))
    elif A + B - C - D == 7:
        print("{0}+{1}-{2}-{3}=7".format(A, B, C, D))
    elif A - B + C + D == 7:
        print("{0}-{1}+{2}+{3}=7".format(A, B, C, D))
    elif A - B + C - D == 7:
        print("{0}-{1}+{2}-{3}=7".format(A, B, C, D))
    elif A - B - C + D == 7:
        print("{0}-{1}-{2}+{3}=7".format(A, B, C, D))
    elif A - B - C - D == 7:
        print("{0}-{1}-{2}-{3}=7".format(A, B, C, D))

Submission status: Accepted

Solution code:
def main():
	s = input()
	ans = ''
	ans = solve(s[0], s[1:])
	print(ans)

def solve(left, right):
	if len(right) == 0:
		if eval(left) == 7:
			print(left + '=7')
			exit()
	else:
		solve(left + '-' + right[0], right[1:])
		solve(left + '+' + right[0], right[1:])

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
inp = str(input())

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

a = "%d+%d+%d+%d=7" % (A, B, C, D)
b = "%d+%d+%d-%d=7" % (A, B, C, D)
c = "%d+%d-%d+%d=7" % (A, B, C, D)
d = "%d-%d+%d+%d=7" % (A, B, C, D)
e = "%d+%d-%d-%d=7" % (A, B, C, D)
f = "%d-%d+%d-%d=7" % (A, B, C, D)
g = "%d-%d-%d+%d=7" % (A, B, C, D)
h = "%d-%d-%d-%d=7" % (A, B, C, D)

if A + B + C + D == 7:
    print(a)
elif A + B + C - D == 7:
    print(b)
elif A + B - C + D == 7:
    print(c)
elif A - B + C + D == 7:
    print(d)
elif A + B - C - D == 7:
    print(e)
elif A - B + C - D == 7:
    print(f)
elif A - B - C + D == 7:
    print(g)
elif A - B - C - D == 7:
    print(h)

Submission status: Accepted

Solution code:
X=int(input())

A = X//1000
X%=1000
B= X//100
X%=100
C = X//10
X%=10
D = X
a=str(A)
b=str(B)
c=str(C)
d=str(D)

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

Submission status: Accepted

Solution code:
ABCD = input()

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

ans = ""
if (a + b + c + d) == 7:
    ans = "+++"
elif (a - b + c + d) == 7:
    ans = "-++"
elif (a + b - c + d) == 7:
    ans = "+-+"
elif (a + b + c - d) == 7:
    ans = "++-"
elif (a + b - c - d) == 7:
    ans = "+--"
elif (a - b + c - d) == 7:
    ans = "-+-"
elif (a - b - c + d) == 7:
    ans = "--+"
elif (a - b - c - d) == 7:
    ans = "---"

print(str(a)+ans[0]+str(b)+ans[1]+str(c)+ans[2]+str(d)+"=7")

Submission status: Accepted

Solution code:
N=int(input())

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

ope=[-1,1]

for i in ope:
    for j in ope:
        for k in ope:
            if a+i*b+j*c+k*d==7:
                ans=[i,j,k]

l=[0]*3

for i in range(3):
    if ans[i]>0:
        l[i]="+"
    else:
        l[i]="-"

   

#all_ans=[str(a),l[0],str(b),l[1],str(c),l[2],str(d)]
all_ans=str(a)+l[0]+str(b)+l[1]+str(c)+l[2]+str(d)+"=7"
print(all_ans)

Submission status: Accepted

Solution code:
S = input()

def calcfunc(s) :
    total = 0
    cond = 1

    for c in s :
        if c == "+" :
            cond = 1
        elif c == "-" :
            cond = -1
        else :
            total += cond * int(c)
            
    return total

res = "Nil"
def addinput(s, i) :
    global res
    # do eval
    if len(s) == 7 : 
        if calcfunc(s) == 7:
            res = s

    else :
        str_plus = s[:i] + "+" + s[i:]
        str_minus = s[:i] + "-" + s[i:]

        addinput(str_plus, i + 2)
        addinput(str_minus, i + 2)
    
addinput(S, 1)
print(res + "=7")

Submission status: Accepted

Solution code:
from itertools import product

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


def sign(x):
    if x == -1:
        return '-'
    else:
        return '+'


for i, j, k in product([-1, 1], [-1, 1], [-1, 1]):
    x = A + i * B + j * C + k * D
    if x == 7:
        print('{}{}{}{}{}{}{}=7'.format(A, sign(i), B, sign(j), C, sign(k), D))
        break

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:
    line = str(A)+"+"+str(B)+"+"+str(C)+"+"+str(D)+"=7"
elif A+B+C-D == 7:
    line = str(A)+"+"+str(B)+"+"+str(C)+"-"+str(D)+"=7"
elif A+B-C+D == 7:
    line = str(A)+"+"+str(B)+"-"+str(C)+"+"+str(D)+"=7"
elif A-B+C+D == 7:
    line = str(A)+"-"+str(B)+"+"+str(C)+"+"+str(D)+"=7"
elif A+B-C-D == 7:
    line = str(A)+"+"+str(B)+"-"+str(C)+"-"+str(D)+"=7"
elif A-B-C+D == 7:
    line = str(A)+"-"+str(B)+"-"+str(C)+"+"+str(D)+"=7"
elif A-B+C-D == 7:
    line = str(A)+"-"+str(B)+"+"+str(C)+"-"+str(D)+"=7"
elif A-B-C-D == 7:
    line = str(A)+"-"+str(B)+"-"+str(C)+"-"+str(D)+"=7"

print(line)

Submission status: Accepted

Solution code:
I = input()
N = len(I)
ans = ""
for n in range(1 << (N-1)):
  A = I[0]
  for i in range(N-1):
    if n & (1 << i):
      A += "+" + I[i+1]
    else:
      A += "-" + I[i+1]
  if eval(A) == 7:
    ans = A + "=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(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:
i=int(input())
d=i%10
c=(i//10)%10
b=(i//100)%10
a=i//1000
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="")
else:
    print(a,"-",b,"-",c,"-",d,"=7",sep="")