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:
from itertools import product
s = input()
for ops in product('+-', repeat=3):
	t = ''.join([a+b for a, b in zip(s, ops)])
	t += s[-1]
	if eval(t) == 7:
		print(t+'=7');exit()

Submission status: Accepted

Solution code:
from itertools import product
s = input()
for ops in product("+-", repeat=3):
    t = ''.join([a + b for a, b in zip([''] + list(ops), s)])
    if eval(t) == 7:
        print(t+"=7")
        exit()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

opr = ["+++","++-","+--","---","+-+","-++","--+","-+-"]

ABCD = list(input())
for op in opr:
	ans = []
	ABCD_ = ABCD.copy()
	op = list(op)
	ans.append(ABCD_.pop(0))
	while ABCD_ != []:
		ans.append(op.pop(0))
		ans.append(ABCD_.pop(0))
	if eval("".join(ans)) == 7:
		print("".join(ans), "=7", sep="")
		sys.exit(0)

Submission status: Accepted

Solution code:
s=input()
ans=7
for i in range(8):
  func=""
  num=str(bin(i))[2:]
  num=num.zfill(3)
  for j in range(3):
    func+=s[j]
    if num[j]=='1':
      func+="+"
    else:
      func+="-"
  func+=s[-1]
  if eval(func)==7:
    print(func+"=7")
    exit()

Submission status: Accepted

Solution code:
import itertools
n=input()
op=list(itertools.product(['+','-'],repeat=3))
l=list(n)
for i in op:
	tmp=n[0]+i[0]+n[1]+i[1]+n[2]+i[2]+n[3]
	if eval(tmp)==7:
		print(tmp+'=7')
		break

Submission status: Accepted

Solution code:
array = [int(i) for i in list(input())]
flag = False
fugou = ['+', '-']

for i in fugou:
	if i == '+':
		tmp = array[0] + array[1]
	else:
		tmp = array[0] - array[1]
	for j in fugou:
		if j == '+':
			tmp2 = tmp + array[2]
		else:
			tmp2 = tmp - array[2]
		for k in fugou:
			if k == '+':
				if tmp2 + array[3] == 7:
					print(str(array[0])
							+ i + str(array[1])
							+ j + str(array[2])
							+ k + str(array[3])
							+ '=7')
					flag = True
					break
			else:
				if tmp2 - array[3] == 7:
					print(str(array[0])
							+ i + str(array[1])
							+ j + str(array[2])
							+ k + str(array[3])
							+ '=7')
					flag = True
					break
		if flag: break
	if flag: break

Submission status: Accepted

Solution code:
from itertools import product
s = input()
for p in product(range(2),repeat=3):
    tmp = ''
    for i in range(len(s)-1):
        if p[i] == 0:
            tmp += s[i]+'+'
        else:
            tmp += s[i]+'-'
    if eval(tmp+s[-1]) == 7:
        print(tmp+s[-1]+'=7')
        exit()

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:
                b=[i,j,k]
                break
st=S[0]
for l in range(3):
    if b[l]==0:
        st+="+"+S[l+1]
    else:
        st+="-"+S[l+1]
print(st+"=7")

Submission status: Accepted

Solution code:
s = input()

if eval(s[0] + '+' + s[1] + '+' + s[2] + '+' + s[3]) == 7:
    print(s[0] + '+' + s[1] + '+' + s[2] + '+' + s[3] + '=7') 
elif eval(s[0] + '+' + s[1] + '+' + s[2] + '-' + s[3]) == 7:
    print(s[0] + '+' + s[1] + '+' + s[2] + '-' + s[3] + '=7')
elif eval(s[0] + '+' + s[1] + '-' + s[2] + '+' + s[3]) == 7:
    print(s[0] + '+' + s[1] + '-' + s[2] + '+' + s[3] + '=7')
elif eval(s[0] + '+' + s[1] + '-' + s[2] + '-' + s[3]) == 7:
    print(s[0] + '+' + s[1] + '-' + s[2] + '-' + s[3] + '=7')
elif eval(s[0] + '-' + s[1] + '+' + s[2] + '+' + s[3]) == 7:
    print(s[0] + '-' + s[1] + '+' + s[2] + '+' + s[3] + '=7')
elif eval(s[0] + '-' + s[1] + '+' + s[2] + '-' + s[3]) == 7:
    print(s[0] + '-' + s[1] + '+' + s[2] + '-' + s[3] + '=7')
elif eval(s[0] + '-' + s[1] + '-' + s[2] + '+' + s[3]) == 7:
    print(s[0] + '-' + s[1] + '-' + s[2] + '+' + s[3] + '=7')
else:# if ev == 7:
    print(s[0] + '-' + s[1] + '-' + s[2] + '-' + s[3] + '=7')

Submission status: Accepted

Solution code:
## どうせ8種類だから全列挙する

lst = [int(c) for c in input()]


if lst[0]+lst[1]+lst[2]+lst[3] == 7:
  ans = str(lst[0])+'+'+str(lst[1])+'+'+str(lst[2])+'+'+str(lst[3])
elif lst[0]+lst[1]+lst[2]-lst[3] == 7:
  ans = str(lst[0])+'+'+str(lst[1])+'+'+str(lst[2])+'-'+str(lst[3])
elif lst[0]+lst[1]-lst[2]+lst[3] == 7:
  ans = str(lst[0])+'+'+str(lst[1])+'-'+str(lst[2])+'+'+str(lst[3])
elif lst[0]+lst[1]-lst[2]-lst[3] == 7:
  ans = str(lst[0])+'+'+str(lst[1])+'-'+str(lst[2])+'-'+str(lst[3])
elif lst[0]-lst[1]+lst[2]+lst[3] == 7:
  ans = str(lst[0])+'-'+str(lst[1])+'+'+str(lst[2])+'+'+str(lst[3])
elif lst[0]-lst[1]+lst[2]-lst[3] == 7:
  ans = str(lst[0])+'-'+str(lst[1])+'+'+str(lst[2])+'-'+str(lst[3])
elif lst[0]-lst[1]-lst[2]+lst[3] == 7:
  ans = str(lst[0])+'-'+str(lst[1])+'-'+str(lst[2])+'+'+str(lst[3])
elif lst[0]-lst[1]-lst[2]-lst[3] == 7:
  ans = str(lst[0])+'-'+str(lst[1])+'-'+str(lst[2])+'-'+str(lst[3])
  
ans = ans + '=7'
print(ans)

Submission status: Accepted

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

def main():
    I = [e for e in input()]
    N = [int(I[0]), int(I[1]), int(I[2]), int(I[3])]

    for i in range(2):
        for j in range(2):
            for k in range(2):
                sum = N[0]

                if i == 0:
                    sum += N[1]
                else:
                    sum -= N[1]

                if j == 0:
                    sum += N[2]
                else:
                    sum -= N[2]

                if k == 0:
                    sum += N[3]
                else:
                    sum -= N[3]

                if sum == 7:
                    res = "{}{}{}{}{}{}{}=7".format(
                            N[0],
                            "+" if i == 0 else "-",
                            N[1],
                            "+" if j == 0 else "-",
                            N[2],
                            "+" if k == 0 else "-",
                            N[3],
                            )
                    print(res)
                    return

main()

Submission status: Accepted

Solution code:
import sys
a = input()
l = ['+', '-']
for i in l:
  for j in l:
     for k in l:
        eq = a[0] + i + a[1] + j + a[2] + k + a[3] 
        if eval(eq) == 7:
          print(eq, '=7', sep='')
          sys.exit()

Submission status: Accepted

Solution code:
hoge=input()
a=int(hoge[0])
b=int(hoge[1])
c=int(hoge[2])
d=int(hoge[3])
f=0
for i in [-1,1]:
  for j in [-1,1]:
    for k in [-1,1]:
      if(a+i*b+j*c+k*d==7):
        if(i==1):
          x="+"
        else:
          x="-"
        if(j==1):
          y="+"
        else:
          y="-"
        if(k==1):
          z="+"
        else:
          z="-"
        if(f==0):
          print(str(a)+x+str(b)+y+str(c)+z+str(d)+"=7")
          f+=1

Submission status: Accepted

Solution code:
a = int(input())
b = list(str(a))
if len(b) == 3:
    b = b[::-1]
    b.append("0")
    b = b[::-1]
if int(b[0])+int(b[1])+int(b[2])+int(b[3]) == 7:
    print(b[0]+"+"+b[1]+"+"+b[2]+"+"+b[3]+"=7")
elif int(b[0])-int(b[1])+int(b[2])+int(b[3]) == 7:
    print(b[0]+"-"+b[1]+"+"+b[2]+"+"+b[3]+"=7")
elif int(b[0])+int(b[1])-int(b[2])+int(b[3]) == 7:
    print(b[0]+"+"+b[1]+"-"+b[2]+"+"+b[3]+"=7")
elif int(b[0])+int(b[1])+int(b[2])-int(b[3]) == 7:
    print(b[0]+"+"+b[1]+"+"+b[2]+"-"+b[3]+"=7")
elif int(b[0])-int(b[1])-int(b[2])+int(b[3]) == 7:
    print(b[0]+"-"+b[1]+"-"+b[2]+"+"+b[3]+"=7")
elif int(b[0])-int(b[1])-int(b[2])-int(b[3]) == 7:
    print(b[0]+"-"+b[1]+"-"+b[2]+"-"+b[3]+"=7")
elif int(b[0])-int(b[1])+int(b[2])-int(b[3]) == 7:
    print(b[0]+"-"+b[1]+"+"+b[2]+"-"+b[3]+"=7")
elif int(b[0])+int(b[1])-int(b[2])-int(b[3]) == 7:
    print(b[0]+"+"+b[1]+"-"+b[2]+"-"+b[3]+"=7")

Submission status: Accepted

Solution code:
n = input()
a = [int(i) for i in n]
#print(a)
e = []
for i in [-1,1]:
    for j in [-1,1]:
        for k in [-1,1]:
            if a[0] + a[1]*i + a[2]*j + a[3]*k == 7:    
                e.append([i,j,k])
ans = []
for i in e[0]:
    if i == -1:
        ans.append("-")
    else:
        ans.append("+")
print(str(a[0]) + ans[0] + str(a[1]) + ans[1] + str(a[2]) + ans[2] + str(a[3]) + "=7")

Submission status: Accepted

Solution code:
s = input()
if int(s[0]) + int(s[1]) + int(s[2]) + int(s[3]) == 7:
	print(s[0] + "+" + s[1] + "+" + s[2] + "+" + s[3] + "=7")
elif int(s[0]) - int(s[1]) + int(s[2]) + int(s[3]) == 7:
	print(s[0] + "-" + s[1] + "+" + s[2] + "+" + s[3] + "=7")
elif int(s[0]) + int(s[1]) - int(s[2]) + int(s[3]) == 7:
	print(s[0] + "+" + s[1] + "-" + s[2] + "+" + s[3] + "=7")
elif int(s[0]) + int(s[1]) + int(s[2]) - int(s[3]) == 7:
	print(s[0] + "+" + s[1] + "+" + s[2] + "-" + s[3] + "=7")
elif int(s[0]) - int(s[1]) - int(s[2]) + int(s[3]) == 7:
	print(s[0] + "-" + s[1] + "-" + s[2] + "+" + s[3] + "=7")
elif int(s[0]) - int(s[1]) + int(s[2]) - int(s[3]) == 7:
	print(s[0] + "-" + s[1] + "+" + s[2] + "-" + s[3] + "=7")
elif int(s[0]) + int(s[1]) - int(s[2]) - int(s[3]) == 7:
	print(s[0] + "+" + s[1] + "-" + s[2] + "-" + s[3] + "=7")
else:
	print(s[0] + "-" + s[1] + "-" + s[2] + "-" + s[3] + "=7")

Submission status: Accepted

Solution code:
ll = list(input())

for i in range(len(ll)-1):
    ll.insert(i*2+1,"")

for i in range(8):
    for j in range(3):
        ins = "+" if ((i>>j) &1) else "-"
        ll[j*2+1] = ins
    ans = "".join(ll)
    if eval("".join(ll))==7:
        print(ans+"=7")
        break

Submission status: Accepted

Solution code:
S = list(input())
S = [int(i) for i in S]

for i in range(2 ** 3):
    p = S[0]
    for j in range(3):
        if ((i >> j) & 1):
            p -= S[j+1]
        else:
            p += S[j+1]
    if p == 7:
        ans = str(S[0])
        for j in range(3):
            if ((i >> j) & 1):
                ans += '-'+str(S[j+1])
            else:
                ans += '+'+str(S[j+1])
        ans += '=7'
        print(ans)
        break

Submission status: Accepted

Solution code:
import itertools
S=list(input())
l=['-','+']
L=list(itertools.product(l,repeat=len(S)-1))
ans=0
for i in range(2**(len(S)-1)):
    a = S[0]
    for j in range(len(S)-1):
        a+=L[i][j]+S[j+1]
    if eval(a)==7:
        print(a+'=7')
        break

Submission status: Accepted

Solution code:
l = ["" for i in range(7)]
ll = list(input())

for i in range(4):
    l[i*2] = ll[i]

flag = False
for i in range(2):
    if i==0:
        l[1] = '+'
    else:
        l[1] = '-'
    for ii in range(2):
        if ii==0:
            l[3] = '+'
        else:
            l[3] = '-'
        for iii in range(2):
            if iii==0:
                l[5] = '+'
            else:
                l[5] = '-'
            t = "".join(l)
            ans = eval(t)
            if ans==7:
                print(t+'=7')
                flag = True
                break
        if flag:
            break
    if flag:
        break

Submission status: Accepted

Solution code:
A,B,C,D=[int(x) for x in list(input())]

def p_or_m(a,b,op):
    if op==0:
        return a+b
    else:
        return a-b
      
out_list=[]

for op1 in range(2):
    out_1=p_or_m(A,B,op1)
    for op2 in range(2):
        out_2=p_or_m(out_1,C,op2)
        for op3 in range(2):
            out_3=p_or_m(out_2,D,op3)
            if out_3==7:
                out_list.append([op1,op2,op3,out_3])
                
out=out_list[0]

L=[B,C,D]
out_str=str(A)
for i in range(len(out)-1):
    if out[i]==0:
        out_str+='+'
    elif out[i]==1:
        out_str+='-'
    out_str+=str(L[i])
        
out_str+='=7'

print(out_str)

Submission status: Accepted

Solution code:
import itertools
ticket=input()
op=['+','-']
for o1,o2,o3 in itertools.product(op,repeat=3):
  express=ticket[0]+o1+ticket[1]+o2+ticket[2]+o3+ticket[3]
  if eval(express)==7:
    print(express+"=7")
    exit()

Submission status: Accepted

Solution code:
num=input()
for i in range(2**3):
    total=int(num[0])
    ans_str=str(num[0])
    for k in range(0,3):
        if (i>>k)&1:
            total+=int(num[k+1])
            ans_str+='+'+num[k+1]
        else:
            total-=int(num[k+1])
            ans_str+='-'+num[k+1]
    #print(ans_str)
    #print(total)
    if total==7:
        ans_str+='=7'
        print(ans_str)
        break

Submission status: Accepted

Solution code:
OP = ["+++", "++-", "+-+", "+--", "-++", "-+-", "--+", "---"]
N = input()
for operation in OP:
    formula = N[0] + operation[0] + N[1] + operation[1] + N[2] + operation[2] + N[3]
    if eval(formula) == 7:
        print(formula + "=7")
        break

Submission status: Accepted

Solution code:
input_2 = input()
import itertools
n = list(itertools.product([0,1], repeat=3))
for comb in n:
    result = int(input_2[0])
    for i,x in enumerate(comb):
        if x==0:
            result += int(input_2[i+1])
        else:
            result -= int(input_2[i+1])
    if result==7:
        print(input_2[0],str(comb[0]).replace("0","+").replace("1","-"),
              input_2[1],str(comb[1]).replace("0","+").replace("1","-"),
              input_2[2],str(comb[2]).replace("0","+").replace("1","-"),
              input_2[3],"=7",sep="")
        break

Submission status: Accepted

Solution code:
S = input()
ans = False
for bit in range(2**(len(S)-1)):
  s = ""
  for i in range(len(S)):
    s += S[i]
    if i<len(S)-1:
      if (bit>>i) & 1:
        s += "+"
      else:
        s += "-"
  ans = eval(s) == 7
  if ans:
    break
print(s+"=7")

Submission status: Accepted

Solution code:
a,b,c,d = map(int, list(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:
S = input()
ans = False
for bit in range(2**(len(S)-1)):
    s = ""
    for i in range(len(S)):
        s += S[i]
        if i<len(S)-1:
            if (bit>>i) & 1:
                s += "+"
            else:
                s += "-"
    ans = eval(s)==7
    if ans:
        break
print(s+"=7")

Submission status: Accepted

Solution code:
a=list(input())
c=0
def abcd(n,i,s):
    global c
    if i==3:
        if n==7 and c==0:
            print(s+"=7")
            c=1
    else:
        for j in range(2):
            if j==0:
                abcd(n+int(a[i+1]),i+1,s+"+"+a[i+1])
            else:
                abcd(n-int(a[i+1]),i+1,s+"-"+a[i+1])
abcd(int(a[0]),0,a[0])

Submission status: Accepted

Solution code:
S = input()

for i in range(8):
	t = ""
	for j in range(3):
		t += S[j] + ["+", "-"][not (1 & i >> j)]
	t += S[-1]
	if 7 == eval(t):
		print(t + "=7")
		break

Submission status: Accepted

Solution code:
#ABC079C/Train_Ticket
N = input()
n = list(N)
for i in range(len(n)):
    n[i] = int(n[i])

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

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

Solution code:
import itertools
a = list(map(int, list(input())))
for op in itertools.product(["+","-"], repeat=3):
  ans = a[0]
  for i in range(3):
    if op[i] == "+":
      ans += a[i+1]
    else:
      ans -= a[i+1]
  if ans == 7:
    print("{}{}{}{}{}{}{}=7".format(a[0],op[0],a[1],op[1],a[2],op[2],a[3]))
    break

Submission status: Accepted

Solution code:
n = input()

for i in range(2 ** 3):
    i2 = bin(i)[2:].zfill(3)
    i3 = n[0]
    total = int(n[0])
    for j in range(3):
        if i2[j] == '1':
            # plus
            total += int(n[j+1])
            i3 += '+'
        else:
            # minus
            total -= int(n[j+1])
            i3 += '-'
        i3 += n[j+1]

    if total == 7:
        break

print(i3 + '=7')

Submission status: Accepted

Solution code:
a,b,c,d=input()
def solve():
    for i in ["+","-"]:
        for j in ["+","-"]:
            for k in ["+","-"]:
                ans = a+i+b+j+c+k+d
                if eval(ans) == 7:
                    return ans
print(solve()+"=7")

Submission status: Accepted

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

ansStr = ""

for i in ["+","-"]:
    for j in ["+","-"]:
        for k in ["+","-"]:
            ansNum = ABCD[0]
            if i == "+":
                ansNum += ABCD[1]  
            else:
                ansNum -= ABCD[1]
            if j == "+":
                ansNum += ABCD[2]  
            else:
                ansNum -= ABCD[2]
            if k == "+":
                ansNum += ABCD[3]  
            else:
                ansNum -= ABCD[3]
                
            #print(ansNum)
            if ansNum == 7:
                ansStr = str(ABCD[0]) + i + str(ABCD[1]) + j + str(ABCD[2]) + k + str(ABCD[3]) + "=7"
                break
print(ansStr)

Submission status: Accepted

Solution code:
import sys
import itertools
input = sys.stdin.readline

L = [int(v) for v in list(input().strip())]

for v in itertools.product(["+", "-"], repeat = 3):
    s = ""
    for i in range(len(L) - 1):
        s += "{}{}".format(L[i], v[i])
        
    s += str(L[-1])
    if eval(s) == 7:
        print(s + "=7")
        sys.exit()

Submission status: Accepted

Solution code:
A=list(input())
for i in range(8):
  key=str(bin(i))[2:].zfill(3)
  s=A[0]
  for j in range(3):
    if key[j]=="0":
      s+="+"
    else:
      s+="-"
    s+=A[j+1]
  if eval(s)==7:
    print(s+"=7")
    break

Submission status: Accepted

Solution code:
abcd = input()


def dfs(s, idx):
  
  if len(s) == 7:
    if eval(s) == 7:
      s += "=7"
      print(s)
      exit()
    return
    
  #print(s)
  dfs(s + "+" + abcd[idx], idx+1)
  dfs(s + "-" + abcd[idx], idx+1)
  
  
dfs(abcd[0], 1)

Submission status: Accepted

Solution code:
A =input()
pm = "+-"
ans = 0
for i in range(8):
    x = int(A[0])
    for j in range(3):
        if bin(i)[-(1+j)] == "1":
            x+=int(A[j+1])
        else:
            x-=int(A[j+1])
    if x == 7:
        ans = i
seven=A[0]
for j in range(3):
    if bin(ans)[-(1+j)] == "1":
        seven += "+"+A[j+1]
    else:
        seven += "-"+A[j+1]
print(seven+"=7")

Submission status: Accepted

Solution code:
s=[i for i in input()]
t=len(s)-1
tmp=2**t
ans=0
for i in range(tmp):
    p=bin(i)[2:]
    p="0"*(t-len(p))+p
    x=""
    for j,k in enumerate(s):
        x+=k
        if j!=t and p[j]=="1":
            x+="+"
        if j!=t and p[j]=="0":
            x+="-"
    if eval(x)==7:
        print(x+"=7")
        break

Submission status: Accepted

Solution code:
abcd = input()
a,b,c,d = int(abcd[0]),int(abcd[1]),int(abcd[2]),int(abcd[3])
op = ["+","-"]
def calc(op1,op2,op3):
    if op1 == "+":
        tmp = a + b
    else:
        tmp = a - b
    if op2 == "+":
        tmp += c
    else:
        tmp -= c
    if op3 == "+":
        tmp += d
    else:
        tmp -= d
    return tmp
def solve():
    for op1 in op:
        for op2 in op:
            for op3 in op:
                if calc(op1,op2,op3) == 7:
                    print("%d%s%d%s%d%s%d=7"%(a,op1,b,op2,c,op3,d))
                    return
solve()

Submission status: Accepted

Solution code:
S=input()
size = len(S)
pmlist = [format(i,'0'+str(size-1)+'b').replace('0','+').replace('1', '-') for i in range(2**(size-1))]
for pm in pmlist:
    eq = ''.join([S[i]+pm[i] for i in range(size-1)]+[S[size-1]])
    if eval(eq) == 7:
        break
print(eq+'=7')

Submission status: Accepted

Solution code:
a = input()
for i in range(2**3):
    tmp = a[0]
    for j in range(3):
        if (i >> j) & 1:
            tmp += "+"+a[j+1]
        else:
            tmp += "-"+a[j+1]
    if eval(tmp) == 7:
        print(tmp + "=7")
        exit()

Submission status: Accepted

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

try:
	for op1 in "+-":
		for op2 in "+-":
			for op3 in "+-":
				f = A+op1+B+op2+C+op3+D
				if eval(f) == 7:
					raise f
except:
	print(f + "=7")

Submission status: Accepted

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

if A+B+C+D == 7:
    print(str(A)+ "+" + str(B)+ "+" + str(C)+ "+" + str(D) + "=" + str(7))
elif A+B+C-D == 7:
    print(str(A)+ "+" + str(B)+ "+" + str(C)+ "-" + str(D) + "=" + str(7))
elif A+B-C+D == 7:
    print(str(A)+ "+" + str(B)+ "-" + str(C)+ "+" + str(D) + "=" + str(7))
elif A-B+C+D == 7:
    print(str(A)+ "-" + str(B)+ "+" + str(C)+ "+" + str(D) + "=" + str(7))
elif A+B-C-D == 7:
    print(str(A)+ "+" + str(B)+ "-" + str(C)+ "-" + str(D) + "=" + str(7))
elif A-B-C+D == 7:
    print(str(A)+ "-" + str(B)+ "-" + str(C)+ "+" + str(D) + "=" + str(7))
elif A-B+C-D == 7:
    print(str(A)+ "-" + str(B)+ "+" + str(C)+ "-" + str(D) + "=" + str(7))
elif A-B-C-D == 7:
    print(str(A)+ "-" + str(B)+ "-" + str(C)+ "-" + str(D) + "=" + str(7))

Submission status: Accepted

Solution code:
Num_list = list(map(int,list(input())))
ops = 3
Anser = 7


for i in range(2 ** ops):
  sum0 = Num_list[0]
  str0 = str(Num_list[0])
  k = 1

  for j in range(ops-1,-1,-1):
    if((i >> j) & 1):
      sum0 = sum0 + Num_list[k]
      str0 = str0 + '+' + str(Num_list[k])
      k = k + 1
    else:
      sum0 = sum0 - Num_list[k]
      str0 = str0 + '-' + str(Num_list[k])
      k = k + 1
  
#  print(sum0)
#  print(str0)
#  print('===')
  
  if(sum0 == Anser):
    print(str0 + '=7')
    break;

Submission status: Accepted

Solution code:
S = input()
L = [int(c) for c in S]
O = [1,-1]
sum = 0
N = 0

for i in O:
    for j in O:
        for k in O:
            if L[0] + i*L[1] + j*L[2] + k*L[3] == 7:
                print('{:}{:+}{:+}{:+}=7'.format(L[0],i*L[1],j*L[2],k*L[3]))
                exit()

Submission status: Accepted

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

B = [b, -b]
C = [c, -c]
D = [d, -d]

is_7 = False

for i_b in B:
    for i_c in C:
        for i_d in D:
            if a+i_b+i_c+i_d == 7:
                is_7 = True
                break
        if is_7:
            break
    if is_7:
        break
        
signs = []
for i in [i_b,i_c,i_d]:
    if i>=0:
        signs.append('+')
    else:
        signs.append('-')
        
print(str(a)
      +signs[0]
      +str(abs(i_b))
      +signs[1]
      +str(abs(i_c))
      +signs[2]
      +str(abs(i_d))
      +'=7')

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s =input()

    for op1 in ['+', '-']:
        for op2 in ['+', '-']:
            for op3 in ['+', '-']:
                if eval(s[0]+op1+s[1]+op2+s[2]+op3+s[3]) == 7:
                    print(s[0]+op1+s[1]+op2+s[2]+op3+s[3] +'=7')
                    return


solve()

Submission status: Accepted

Solution code:
S = input()

   
ans = 0
for i in range(2 ** (len(S)-1)):
    oparr = []
    for j in range(len(S)-1):
        if (i >> j) & 1:
            oparr.insert(0,"+")
        else:
            oparr.insert(0,"-")
    oparr.append("")
    tmp = ""
    for k in range(len(S)):
        tmp += S[k] + oparr[k]
    if eval(tmp) == 7:
        print(tmp + "=7")
        exit()

Submission status: Accepted

Solution code:
import numpy as np
import itertools

abcd = input()
abcd = np.array([int(i) for i in abcd])

ops = np.array([
    [1, op1, op2, op3] for op1, op2, op3
    in itertools.product([1, -1], [1, -1], [1, -1])])

op_ans = []
for op in ops:
    if np.dot(abcd, op)==7:
        op_ans = op
        
ans = str(abcd[0])
for dig, op in zip(abcd[1:], op_ans[1:]):
    ans += '+' if op>0 else '-'
    ans += str(dig)
ans += '=7'

print(ans)

Submission status: Accepted

Solution code:
S = list(input())
n = [int(s) for s in S]
#print(n)

ans = []

def dfs(a, b, c):
  if c == len(n)-1:
    if b == 7:
      ans.append(a + '=7')
    return
  dfs(a + '+' + S[c+1], b + n[c+1], c+1)
  dfs(a + '-' + S[c+1], b - n[c+1], c+1)
  
dfs(S[0], n[0], 0)

print(ans[0])

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc079/tasks/abc079_c

import sys
import itertools as it
import operator

if __name__ == "__main__":
    xs = [int(c) for c in input().strip()]
    ops = it.product([-1, 1], repeat=3)
    res = next(op for op in ops if 7 == (xs[0] + sum(map(operator.mul, xs[1:], op))))
    symbols = ["+" if i == 1 else "-" for i in res]
    iterable = filter(
        lambda x: x is not None,
        it.chain.from_iterable(
            it.zip_longest(map(str, xs), symbols)
        )
    )
    res = "".join(iterable) + "=7"
    print(res)

Submission status: Accepted

Solution code:
A,B,C,D = map(int,input())
pm = {1:"+",-1:"-"}
breakFlg = False
for i in (1,-1):
    for j in (1,-1):
        for k in (1,-1):
            if A+B*i+C*j+D*k == 7:
                print(str(A)+pm[i]+str(B)+pm[j]+str(C)+pm[k]+str(D)+"=7")
                breakFlg = True
                break
        if breakFlg:
            break
    if breakFlg:
        break

Submission status: Accepted

Solution code:

def read_input():
    s = input()
    a, b, c, d = map(int, [c for c in s])

    return a, b, c, d


def check_formulae(a, b, c, d):
    if a + b + c + d == 7:
        print('{}+{}+{}+{}=7'.format(a,b,c,d))
        return
    if a + b + c - d == 7:
        print('{}+{}+{}-{}=7'.format(a,b,c,d))
        return
    if a + b - c + d == 7:
        print('{}+{}-{}+{}=7'.format(a,b,c,d))
        return
    if a + b - c - d == 7:
        print('{}+{}-{}-{}=7'.format(a,b,c,d))
        return
    if a - b + c + d == 7:
        print('{}-{}+{}+{}=7'.format(a,b,c,d))
        return
    if a - b + c - d == 7:
        print('{}-{}+{}-{}=7'.format(a,b,c,d))
        return
    if a - b - c + d == 7:
        print('{}-{}-{}+{}=7'.format(a,b,c,d))
        return
    if a - b - c - d == 7:
        print('{}-{}-{}-{}=7'.format(a,b,c,d))
        return
    return


def submit():
    a, b, c, d = read_input()
    check_formulae(a, b, c, d)

if __name__ == '__main__':
    submit()

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 = []
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:
A, B, C, D = list(input())

for op1 in "+-":
    for op2 in "+-":
        for op3 in "+-":
            S = A + op1 + B + op2 + C + op3 + D
            if eval(S) == 7:
                print(S + "=7")
                quit()

Submission status: Accepted

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

for i in range(8):
    op1 = "+" if i & 1 else "-"
    op2 = "+" if i & 2 else "-"
    op3 = "+" if i & 4 else "-"
    S = A + op1 + B + op2 + C + op3 + D
    if eval(S) == 7:
        print(S + "=7")
        quit()

Submission status: Accepted

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

for i in range(8):
    op1 = "+" if i & 1 else "-"
    op2 = "+" if i & 2 else "-"
    op3 = "+" if i & 4 else "-"
    S = "{}{}{}{}{}{}{}".format(A, op1, B, op2, C, op3, D)
    if eval(S) == 7:
        print(S + "=7")
        quit()

Submission status: Accepted

Solution code:
# AtCoder Beginner Contest 079 - C
s = input()
op = []
oplist = []
cnt = len(s) - 1

for i in range(2**cnt):
    op = ['+'] * cnt
    for j in range(cnt):
        if (i >> j) & 1:
            op[cnt - 1 - j] = '-'
    oplist.append(op)

for i in range(2**cnt):
    ans = int(s[0:1])
    for j in range(cnt):
        if oplist[i][j] == '+':
            ans += int(s[j+1:j+2])
        else:
            ans -= int(s[j+1:j+2])
    if ans == 7:
        print(s[0], end='')
        for k in range(cnt):
            print(oplist[i][k] + s[k+1:k+2], end='')
        print('=7')
        break

Submission status: Accepted

Solution code:
from itertools import product
S = input()

for string in product(["+","-"],repeat = 3):
    string = list(string)
    string.append("")
    sum_ = [a + b for a,b in zip(S,string)]
    if eval("".join(sum_)) == 7:
        print("".join(sum_)+"=7")
        break