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:
s = list(map(int, list(input())))
res = 7 - s[0]
if (s[1] + s[2] + s[3] == res):
  print(str(s[0]) + '+' + str(s[1]) + '+' + str(s[2]) + '+' + str(s[3]) + '=' + '7')
elif (s[1] + s[2] - s[3] == res):
  print(str(s[0]) + '+' + str(s[1]) + '+' + str(s[2]) + '-' + str(s[3]) + '=' + '7')
elif (s[1] - s[2] + s[3] == res):
  print(str(s[0]) + '+' + str(s[1]) + '-' + str(s[2]) + '+' + str(s[3]) + '=' + '7')
elif (s[1] - s[2] - s[3] == res):
  print(str(s[0]) + '+' + str(s[1]) + '-' + str(s[2]) + '-' + str(s[3]) + '=' + '7')
elif (-s[1] + s[2] + s[3] == res):
  print(str(-s[0]) + '-' + str(s[1]) + '+' + str(s[2]) + '+' + str(s[3]) + '=' + '7')
elif (-s[1] + s[2] - s[3] == res):
  print(str(s[0]) + '-' + str(s[1]) + '+' + str(s[2]) + '-' + str(s[3]) + '=' + '7')
elif (-s[1] - s[2] + s[3] == res):
  print(str(s[0]) + '-' + str(s[1]) + '-' + str(s[2]) + '+' + str(s[3]) + '=' + '7')
elif (-s[1] - s[2] - s[3] == res):
  print(str(s[0]) + '-' + str(s[1]) + '-' + str(s[2]) + '-' + str(s[3]) + '=' + '7')

Submission status: Accepted

Solution code:
a = input()
array = []

for i in range(2**3):
    a2 = a[0]
    for j in range(3):
        if (i >> j) & 1 == 1:
            a2 += '+'
        else:
            a2 += '-'
        a2 += a[j+1]
    if eval(a2) == 7:
        c = 1
        break

print(a2+'=7')

Submission status: Accepted

Solution code:
INF = float("inf") #const

def main():
    s = input()
    n = len(s) - 1
    ans = 0

    for i in range(2**n):
        op = ["-"]*n
        for j in range(n):
            if (i>>j)&1:
                op[j] = "+"
        tmp = ""
        for a,b in zip(s,op+[""]):
            tmp += a + b
        if eval(tmp) == 7:
            print(tmp+"=7")
            return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = list(input())
num = list(map(lambda x: int(x) , N))
for i in range(8):
    sum_val = num[0]
    for j in range(3):
        if i >> j & 1:
            sum_val += num[j + 1]
        else:
            sum_val -= num[j + 1]
    if sum_val == 7:
        print(num[0] , end = '')
        for j in range(3):
            if i >> j & 1:
                print("+" , end = '')
            else:
                print("-",end = '')
            print(num[j + 1] , end = '')
        print('=7')
        exit()

Submission status: Accepted

Solution code:
def vary_for_flag(a, b, flag):
    if flag == False:
        return a-b
    else:
        return a+b
def str_for_num(num):
    if num == 0:
        return "+"
    else:
        return "-"
A = input()
a = []
for i in range(4):
    b = int(A[i])
    a.append(b)
for i in range(2):
    if i == 0:
        first_flag = True
    else:
        first_flag = False
    for j in range(2):
        if j == 0:
            second_flag = True
        else:
            second_flag = False
        for k in range(2):
            if k == 0:
                third_flag = True
            else:
                third_flag = False
            temp = vary_for_flag(vary_for_flag(vary_for_flag(a[0], a[1], first_flag), a[2], second_flag), a[3], third_flag)
            if temp == 7:
                break
        else:
            continue
        break
    else:
        continue
    break
print("{}{}{}{}{}{}{}=7".format(a[0],str_for_num(i),a[1],str_for_num(j),a[2],str_for_num(k),a[3]))

Submission status: Accepted

Solution code:
import sys
import copy

def main():
    ABCD = list(map(str, input()))
    b_digit = len(ABCD)-1

    for i in range(2 ** b_digit):
        signs = ["+"] * b_digit
        for j in range(b_digit):
            if ((i >> j ) & 1):
                signs[b_digit - 1 - j] = "-"

        ABCD_tmp = copy.deepcopy(ABCD)
        for k in range(len(signs)):
            ABCD_tmp.insert(1+k*2,signs[k])
        if(eval("".join(ABCD_tmp))==7):
            print("{}=7".format("".join(ABCD_tmp)))
            sys.exit()

main()

Submission status: Accepted

Solution code:
ABCD = input()

N = len(ABCD)


for i in range(2**(N-1)):
    temp_res = ''
    for j in range(N-1):
        temp_res += ABCD[j]
        if ((i >> j) & 1):
            temp_res += '+'
        else:
            temp_res += '-'
    temp_res += ABCD[-1]

    if eval(temp_res) == 7:
        res = temp_res + '=7'
        break

print(res)

Submission status: Accepted

Solution code:
s = list(input())

def calc(i, a, b):
  a ,b = int(a), int(b)
  if i==0:
    c = a+b
  elif i==1:
    c = a-b
  return c
 
def tag(t_list):
  t = []
  for p in t_list:
    if p==0:
        t.append('+')
    else:
        t.append('-')
  return(t)
    
for i in range(2):
  c = calc(i,s[0],s[1])
  for j in range(2):
    d = calc(j,c,s[2])
    for k in range(2):
      e = calc(k,d,s[3])
      if e == 7:
        t_list = [i,j,k]
        t = tag(t_list)
        print(s[0]+t[0]+s[1]+t[1]+s[2]+t[2]+s[3]+'=7')
        exit()

Submission status: Accepted

Solution code:
import random as rng
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)


def dump_impl(*objects):
    print(*objects, file=sys.stderr)


def dump_dummy(*objects):
    pass


dump = dump_impl if "DEBUG" in sys.argv else dump_dummy


S = input()
A, B, C, D = map(int, [S[0], S[1], S[2], S[3]])
dump(A, B, C, D)
for op1, op2, op3 in it.product(['+', '-'], repeat=3):
    dump(op1, op2, op3)

    def f(op, a): return a * (1 if op == '+' else -1)
    ans = A + f(op1, B) + f(op2, C) + f(op3, D)
    dump(A, f(op1, B), f(op2, C), f(op3, D))
    if(ans == 7):
        print(str(A)+op1+str(B)+op2+str(C)+op3+str(D)+"=7")
        exit(0)
print("")

Submission status: Accepted

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

idx = [0, 1, 2]
output = []
for i in range(1 << len(idx)):
    ops = ['+', '+', '+']
    if A+B+C+D == 7: 
        print(A,ops[0],B,ops[1],C,ops[2],D,'=7',sep='')
        exit()
    
    ans = A
    for j in range(len(idx)):
        if ((i >> j) & 1) == 1:
            ops[j] = '-'
    
    if ops[0] == '+' : ans += B
    else : ans -= B
    
    if ops[1] == '+' : ans += C
    else : ans -= C
    
    if ops[2] == '+' : ans += D
    else : ans -= D
    
    if ans == 7:
        print(A,ops[0],B,ops[1],C,ops[2],D,'=7',sep='')
        exit()

Submission status: Accepted

Solution code:
# atcoder : python3 (3.4.3)
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
mod = 10**9+7

# main
ABCD = input().rstrip()

from itertools import product
ops = list(product(["+","-"],repeat=3))

x = [0]*7
for op in ops:
    x[0::2] = ABCD
    x[1::2] = op
    exp = "".join(x)
    if eval(exp)==7:
        print(exp+"=7")
        sys.exit()

Submission status: Accepted

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

import pdb
import sys
F = sys.stdin

S = F.readline().rstrip()
A = int(S[:1])
B = int(S[1:2])
C = int(S[2:3])
D = int(S[3:4])

sum = A
nums = [B, C, D]
N = 3
l = [0, 0, 0]
ans = str(A)

# pdb.set_trace()
for bit in range(1<<N):
    for i in range(N):
        if bit & (1<<i):
            sum -= nums[i]
            l[i] = 1
            continue
        sum += nums[i]

    if sum == 7:
        for j in range(N):
            if l[j] == 0:
                ans += ('+' + str(nums[j]))
                continue
            ans += ('-' + str(nums[j]))

        ans += '=7'

        print(ans)
        sys.exit()
    l = [0,0,0]
    sum = A

print('NO_ANSWER')

Submission status: Accepted

Solution code:
S = input()
str_list = list(S)

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

Submission status: Accepted

Solution code:
def solve():
    A, B, C, D = input()
    op = '+-'
    
    for op1 in op:
        for op2 in op:
            for op3 in op:
                left_hand = A + op1 + B + op2 + C + op3 + D
                if eval(left_hand) == 7:
                    return left_hand + '=7'

print(solve())

Submission status: Accepted

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

for i in range(2 ** 3):
    eq = a + ("+" if i % 2 else "-") + b + ("+" if (i >> 1) % 2 else "-") + c + ("+" if (i >> 2) % 2 else "-") + d
    if eval(eq) == 7:
        print(eq + "=7")
        break

Submission status: Accepted

Solution code:
s = input()
s = [s[_] for _ in range(len(s))]
l = ['-']*len(s)
answers = []
for i in range(8):
    l = ['-']*len(s)
    for j in range(3):
        if ((i>>j) & 1):
            l[j] = '+'
    ans = []
    for j, k in zip(s, l):
        ans.append(j)
        ans.append(k)
    ans = ans[:-1]
    ans1 = ''.join(ans)
    ans2 = 0
    for _, j in enumerate(s):
        if _ == 0:
            ans2 += int(j)
        else:
            if l[_-1] == '-':
                ans2 -= int(j)
            else:
                ans2 += int(j)
    answers.append([ans1, ans2])
for i in answers:
    if i[1] == 7:
        print(''.join(i[0]) + '=7')
        break

Submission status: Accepted

Solution code:
S = input()
ans = 0
f = ""
for i in range(1 << len(S)-1):
    f = S[0]
    for j in range(len(S)-1):
        if ((i >> j) & 1) == 1:
            f += "+"
        else:
            f += "-"
        f += S[j+1]
    if eval(f) == 7:
        print(f+"=7")
        exit()

Submission status: Accepted

Solution code:

S = input()

def solve(n, S, idx):

    if len(n) == 7:
        if eval(n) == 7:
            n+="=7"
            print(n)
            exit()
        return

    solve(n+"+"+S[idx], S,idx+1)
    solve(n+"-"+S[idx], S,idx+1)

solve(S[0], S, 1)

Submission status: Accepted

Solution code:
import sys


def main():
    ticket = list(input())

    op = [""] * 3

    for i in range(2):
        if i == 0:
            op[0] = "+"
        else:
            op[0] = "-"
        for j in range(2):
            if j == 0:
                op[1] = "+"
            else:
                op[1] = "-"
            for k in range(2):
                if k == 0:
                    op[2] = "+"
                else:
                    op[2] = "-"

                eq = ""
                for n in range(3):
                    eq += ticket[n] + op[n]
                eq += ticket[-1]

                if eval(eq) == 7:
                    print(eq + "=7")
                    sys.exit()


main()

Submission status: Accepted

Solution code:
n = [int(x) for x in input()]
op = len(n) - 1
for i in range(2**op):
    op_list = ["-"]*op
    for j in range(op):
        if (i>>j)&1:
            op_list[op-1-j] = "+"
    formula = ""
    for p_n,p_o in zip(n,op_list+[""]):
        formula += str(p_n) + p_o
    if eval(formula) == 7:
        print(formula+"=7")
        break

Submission status: Accepted

Solution code:
s = input()
print(filter(lambda x : eval(x) == 7, [''.join(sum(zip(s, ['+' if ((bit >> i) & 1) == 1 else '-' for i in range(4)]), ()))[:-1] for bit in range(1 << 3)]).__next__()+'=7')

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from itertools import product
X = list(map(int, input()))
op = {'+':1, '-':-1}

for ops  in product(op, repeat=3):
    v = X[0] + sum([x*op[o] for x,o in zip(X[1:], ops)])
    if v==7:
        print('{X[0]}{ops[0]}{X[1]}{ops[1]}{X[2]}{ops[2]}{X[3]}=7'.format(X=X, ops=ops))
        exit()

Submission status: Accepted

Solution code:
s = input()

def dfs(i, f, sum):
    if i == 3:
        if sum == 7:
            print(f + '=7')
            exit()
    else:
        dfs(i + 1, f + "-" + s[i + 1], sum - int(s[i + 1]))
        dfs(i + 1, f + "+" + s[i + 1], sum + int(s[i + 1]))

dfs(0, s[0], int(s[0]))

Submission status: Accepted

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

if a + b + c + d == 7:
    print('{}+{}+{}+{}=7'.format(a,b,c,d))
elif a + b + c - d == 7:
    print('{}+{}+{}-{}=7'.format(a,b,c,d))
elif a + b - c + d == 7:
    print('{}+{}-{}+{}=7'.format(a,b,c,d))
elif a - b + c + d == 7:
    print('{}-{}+{}+{}=7'.format(a,b,c,d))
elif a - b + c - d == 7:
    print('{}-{}+{}-{}=7'.format(a,b,c,d))
elif a + b - c - d == 7:
    print('{}+{}-{}-{}=7'.format(a,b,c,d))
elif a - b - c + d == 7:
    print('{}-{}-{}+{}=7'.format(a,b,c,d))
else:
    print('{}-{}-{}-{}=7'.format(a,b,c,d))

Submission status: Accepted

Solution code:
num = input()

for i in range(2**3):
    formula = num[0]
    for j in range(3):
        if (i>>j) & 1:
            formula += '+'
        else:
            formula += '-'
        formula += num[j+1]
    if eval(formula) == 7:
        print(formula + '=7')
        break

Submission status: Accepted

Solution code:
import sys

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

K = [1, -1]

for i in K:
    for j in K:
        for k in K:
            if i*b + j*c + k*d == 7 - a:
                if i*b >= 0:stb = "+{}".format(b)
                else:stb = "-{}".format(b)
                if j*c >= 0:stc = "+{}".format(c)
                else:stc = "-{}".format(c)
                if k*d >= 0:std = "+{}".format(d)
                else:std = "-{}".format(d)
                print(str(a)+stb+stc+std+"=7")
                sys.exit()

Submission status: Accepted

Solution code:
abcd=list(input())
lst=["+","-"]
lst_2=[]
lst_buf=[]
for x in lst:
    for y in lst:
        for z in lst:
            lst_buf=[x,y,z]
            lst_2.append(lst_buf)
buf=''
for l in lst_2:
    buf=abcd[0]+l[0]+abcd[1]+l[1]+abcd[2]+l[2]+abcd[3]
    if 7==eval(buf):
        print(buf+"=7")
        break

Submission status: Accepted

Solution code:
A = list(input())

for i in range(2**3):
  tmp=A[:]
  for j in range(3):
    if (i>>j)&1:
      tmp[j]+="-"
    else:
      tmp[j]+="+"
  if eval("".join(tmp)) == 7:
    tmp[-1]+="=7"
    for s in tmp:
      print(s,end="")
    exit()

Submission status: Accepted

Solution code:
ABCD = input()

for i in range(2**(len(ABCD)-1)):
    n = int(ABCD[0])
    ans = ABCD[0]
    for j, c in enumerate(format(i, '0' + str(len(ABCD)-1) + 'b')):
        if c == '0':
            n += int(ABCD[j+1])
            ans += '+'
        else:
            n -= int(ABCD[j+1])
            ans += '-'
        ans += ABCD[j+1]
    if n == 7:
        print(ans + '=7')
        exit(0)

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:
a,b,c,d=input()
lst_1=[]
lst_2= ["+","-"]
for i in lst_2:
  for j in lst_2:
    for k in lst_2:
      lst_1.append(a+i+b+j+c+k+d)
for l in lst_1:
  if eval(l)==7:
    print(l+"=7")
    break

Submission status: Accepted

Solution code:
from itertools import product

abcd = input()

pn = ["+","-",""]
for aa,bb,cc in product(pn,repeat=3):
    res = abcd[0]+aa+abcd[1]+bb+abcd[2]+cc+abcd[3]
    if eval(res) == 7:
        print(res+"=7")
        break

Submission status: Accepted

Solution code:
import sys
S = input()

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

Submission status: Accepted

Solution code:
ABCD= str(input())

sign_list = ["+","-"]
ans_str = ""
for i in range(2):
  new_sign_list = []
  for sign in sign_list:
    new_sign_list.append(sign+"+")
    new_sign_list.append(sign+"-")
  sign_list = new_sign_list

for signs in sign_list:
  tmp_num = int(ABCD[0])
  for i in range(len(signs)):
    if signs[i] == "+":
      tmp_num += int(ABCD[i+1])
    elif signs[i] == "-":
      tmp_num -= int(ABCD[i+1])

  if tmp_num == 7:
    ans_str = signs
    break

ans = ABCD[0]
for i in range(len(ans_str)):
  ans += ans_str[i]
  ans += ABCD[i+1]

ans += "=7"

print(ans)

Submission status: Accepted

Solution code:
s = input()

for i in range(2**3):
    b = bin(i)[2:].zfill(3)
    op = ["+" if int(b[j]) else "-" for j in range(3)]
    f = "".join([s[j//2] if j%2==0 else op[(j-1)//2] for j in range(7)])
    if eval(f) == 7:
        print("%s=7" % f)
        quit()

Submission status: Accepted

Solution code:
s = input()
li = [-1,1]
a = '+'
b = '+'
c = '+'
for i in li:
	for j in li:
		for k in li:
			if int(s[0])+(i*int(s[1]))+(j*int(s[2]))+(k*int(s[3])) == 7:
				if i == -1:
					a = '-'
				if j == -1:
					b = '-'
				if k == -1:
					c = '-'
				print(s[0] + a + s[1] + b + s[2] + c + s[3] + '=7')
				break
		else:
			continue
		break
	else:
		continue
	break

Submission status: Accepted

Solution code:
#1+2+2+2=7
K=input()
keta=len(K)
#print(K,keta)

for i in range(1<<(keta-1)):#探索数
  ANS=K[0]
  for j in range(keta-1):#調査桁数
    if (i>>j) &1 == 1:#bitがある、つまりプラスが入る場合
      ANS+="+"
    else:
      ANS+="-"
    ANS+=K[j+1]
#  print(ANS)
  if eval(ANS)==7:
    print(ANS+"=7")
    break

Submission status: Accepted

Solution code:
#coding: utf-8
abcd = list(input())
ans = 7
n = len(abcd) - 1
pm = ["+", "-"]
for i in range(2**n):
    tmp = abcd[:]
    for j in range(n):
        if (i >> j) & 1 == 1:
            tmp[j] += pm[0]
        else:
            tmp[j] += pm[1]
    v = eval("".join(tmp))
    if v == ans:
        print("".join(tmp)+"={}".format(ans))
        exit()

Submission status: Accepted

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

A, B, C, D = map(int, 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:
import sys

sign = '+-'

def main():
    a, b, c, d = list(sys.stdin.readline().rstrip())

    for i in sign:
        for j in sign:
            for k in sign:
                left = a + i + b + j + c + k + d
                if eval(left) == 7:
                    print(left+'=7')
                    sys.exit()

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    *S,=ST()
    *S,=map(int,S)
    for i in range(2):
        for j in range(2):
            for k in range(2):
                res = S[0]
                ope = [i,j,k]
                for idx,s in enumerate(S[1:]):
                    if ope[idx]:
                        res += s
                    else:
                        res -= s
                if res == 7:
                    *S,=map(str,S)
                    for idx in range(3):
                        if ope[idx]:
                            ope[idx] = "+"
                        else:
                            ope[idx] = "-"
                    ans = S[0]+ope[0]+S[1]+ope[1]+S[2]+ope[2]+S[3]+"=7"
                    print(ans)
                    exit()


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():

    S = input()
    d = [int(S[i]) for i in range(4)]
    cur = [[d[0], S[0]]]
    for i in range(1, 4):
        temp = []
        for v, s in cur:
            temp.append([v + d[i], s + "+" + S[i]])
            temp.append([v - d[i], s + "-" + S[i]])
        cur = temp

    # print(cur)

    for v, s in cur:
        if v == 7: return s + "=7"
    return ""

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

Submission status: Accepted

Solution code:
import sys
if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline

N = [int(x) for x in input().rstrip()]
n = len(N)-1

for i in range(2**n):
	op = ['+'] * n
	for j in range(n):
		if (i>>j & 1) == 1:
			op[n-j-1] = '-'
	
	op.append('')
	formula = ""
	for num,o in zip(N, op):
		formula += str(num)+o
	if eval(formula) == 7:
		print("{}=7".format(formula))
		sys.exit()

Submission status: Accepted

Solution code:
import copy

calc = ""


def dfs(nums, ret, data):
    if len(nums) == 0 and ret == 7:
        global calc
        calc = data
        return True
    if len(nums) == 0:
        return False
    cp = copy.copy(nums)
    v = cp.pop(0)
    if dfs(cp, ret+v, data+"+"):
        return True
    if dfs(cp, ret-v, data+"-"):
        return True


N = list(map(int, list(input())))
n_cp = copy.copy(N)
v = N.pop(0)
dfs(N, v, "")

ans = ""
for i in range(len(n_cp)):
    ans += str(n_cp[i])
    if i != 3:
        ans += str(calc[i])
ans += "=7"
print(ans)

Submission status: Accepted

Solution code:
B = [0,0,0]
S = str(input())
n = len(S)
for i in range(2**(n-1)):
    A = int(S[0])
    total = A
    B_str = S[0]
    for j in range(n-1):
        if(i>>j)&1:
            B[j] = -int(S[j+1])
            B_str+= "-"+S[j+1]
        else:
            B[j] = int(S[j+1])
            B_str += "+" + S[j + 1]
        total += B[j]
#        print(total,B)
    if total == 7:
        B_str+="=7"
        print(B_str)
        exit()
    total = 0

Submission status: Accepted

Solution code:
A, B, C, D = list(input())
op = ['+', '-']

for i in range(len(op)):
    for j in range(len(op)):
        for k in range(len(op)):
            op1 = op[i]
            op2 = op[j]
            op3 = op[k]
            state = A + op1 + B + op2 + C + op3 + D
            if eval(state) == 7:
                print(state + '=7')
                exit()

Submission status: Accepted

Solution code:
"""bit全探索"""

ticket = tuple(map(int, input()))
res = []

for i in range(8, 16):
    s = ticket[0]
    equation = str(s)
    for j in range(1, 4):
        if int(bin(i)[-j]):
            s += ticket[j]
            equation += "+" + str(ticket[j])
        else:
            s -= ticket[j]
            equation += "-" + str(ticket[j])

    if s == 7:
        equation += "=7"
        res.append(equation)

print(res[0])

Submission status: Accepted

Solution code:
import itertools

input_ = input()
A, B, C, D = [int(input_[i]) for i in range(4)]

ops_str = ["+", "-"]
find_flag = 0
for ops in itertools.product((0, 1), repeat=3):
    equation = A
    if ops[0] == 0:
        equation += B
    else:
        equation -= B
       
    if ops[1] == 0:
        equation += C
    else:
        equation -= C
        
    if ops[2] == 0:
        equation += D
    else:
        equation -= D
    
    if equation == 7:
        find_flag = 1
        print(str(A)+ops_str[ops[0]], end="")
        print(str(B)+ops_str[ops[1]], end="")
        print(str(C)+ops_str[ops[2]], end="")
        print(str(D), end="=7")
        break

Submission status: Accepted

Solution code:
J=list(input())
n=len(J)

def dfs(i,f,sum_num):
    if i==n-1:
        if sum_num==7:
            print(f+"=7")
            exit()
    else:
        dfs(i+1,f+"+"+J[i+1],sum_num+int(J[i+1]))
        dfs(i+1,f+"-"+J[i+1],sum_num-int(J[i+1]))
dfs(0,J[0],int(J[0]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
l = [int(i) for i in list(input())]
a=l[0]
b=l[1]
c=l[2]
d=l[3]
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,b,c,d = [int(s) for s in ABCD]

def f():
    for i in [-1,1]:
        for j in [-1,1]:
            for k in [-1,1]:
                if a + i*b + j*c + k*d == 7:
                    return i,j,k
i,j,k = f()

def conv(v):
    if v == 1:
        return "+"
    else:
        return "-"

print("{}{}{}{}{}{}{}=7".format(a,conv(i),b,conv(j),c,conv(k),d))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    otos=lambda x:"+" if x==1 else "-"
    abcd=int(input())
    abc,d=divmod(abcd,10)
    ab,c=divmod(abc,10)
    a,b=divmod(ab,10)
    for o1 in [1,-1]:
        for o2 in [1, -1]:
            for o3 in [1, -1]:
                s=a+o1*b+o2*c+o3*d
                if s==7:
                    ans=str(a)+otos(o1)+str(b)+otos(o2)+str(c)+otos(o3)+str(d)+"=7"
                    print(ans)
                    exit()

main()

Submission status: Accepted

Solution code:
s = input()
x = {1:'+', -1:'-'}

for i in x:
    for j in x:
        for k in x:
            ans = [int(s[0]), i*int(s[1]), j*int(s[2]), k*int(s[3])]
            if sum(ans) == 7:
                print('{}{}{}{}{}{}{}=7'.format(s[0], x[i], s[1], x[j], s[2], x[k], s[3]))
                break
        else:
            continue
        break
    else:
        continue
    break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = str(input())
N = []
Y = []
for m in n:
    N.append(m)

for i in range(1<<3):
    Y = []
    tot = int(N[0])
    for j in range(3):
        if (i>>j)&1 == 1:
            tot += int(N[j+1])
            Y.append('+')
        else:
            tot -= int(N[j+1])
            Y.append('-')
    if tot == 7:
        ans = N[0]+Y[0]+N[1]+Y[1]+N[2]+Y[2]+N[3]+'=7'
        break
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    a,b,c,d=input()
    from itertools import product
    for i,j,k in product(['+','-'],repeat=3):
        s=a+i+b+j+c+k+d
        if(eval(s)==7):
            print(s+'=7')
            return
resolve()

Submission status: Accepted

Solution code:
n = input()
op_cnt = len(n) - 1
for i in range(2 ** op_cnt):
    op = ["-"] * op_cnt
    for j in range(op_cnt):
        if ((i >> j) & 1) :
            op[op_cnt - j - 1] = "+"
    # print(op)
    ans = n[0]
    for l in range(op_cnt):
        ans += op[l] + n[l + 1]
    if eval(ans) == 7:
        print(ans + "=7")
        exit(0)

Submission status: Accepted

Solution code:
# ABC079C
S = input()
# +を挿入するか-を挿入するかで全部で2 ** 3通り
for i in range(2**3):
    now_sum = int(S[0])
    for j in range(3):
        if (i >> j) & 1:
            now_sum += int(S[j+1])
        else:
            now_sum -= int(S[j+1])
    if now_sum == 7:
        ans = i
        break
fugo = ""
for j in range(3):
    if (ans >> j) & 1:
        fugo += "+"
    else:
        fugo += "-"

print("{}{}{}{}{}{}{}=7".format(S[0], fugo[0], S[1], fugo[1], S[2], fugo[2], S[3]))

Submission status: Accepted

Solution code:
from sys import stdin
from itertools import product

s = stdin.readline().rstrip()

li = ["+","-"]
for i in range(8):
    lin = list(product(li, repeat=3))

def game(a,b,c):
    if c == "-":
        return(a-b)
    else:
        return(a+b)

for j in lin:
    a = game(int(s[0]),int(s[1]),j[0])
    a = game(a,int(s[2]),j[1])
    a = game(a,int(s[3]),j[2])
    if a == 7:
        print(s[0]+j[0]+s[1]+j[1]+s[2]+j[2]+s[3]+str("=7"))
        exit()