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

Arith_list = ["+", "-", "*", "//"]

def func(a ,b, arith):
    if arith == 0:
        return a + b
    elif arith == 1:
        return a - b

ans = 0
op1 = 0
op2 = 0
op3 = 0
for i in range(2):
    for j in range(2):
        for k in range(2):
            ans = func(func(func(a, b, i), c, j), d, k)
            if ans == 7:
                op1 = i
                op2 = j
                op3 = k
                print(str(a)+Arith_list[op1]+str(b)+ Arith_list[op2]+str(c)+ Arith_list[op3]+str(d)+ "=7")
                sys.exit()

Submission status: Accepted

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

if A + B + C + D == 7:
    print(A, '+', B, '+', C, '+', D, '=', 7, sep='')
elif A + B + C - D == 7:
    print(A, '+', B, '+', C, '-', D, '=', 7, sep='')
elif A + B - C + D == 7:
    print(A, '+', B, '-', C, '+', D, '=', 7, sep='')
elif A + B - C - D == 7:
    print(A, '+', B, '-', C, '-', D, '=', 7, sep='')
elif A - B + C + D == 7:
    print(A, '-', B, '+', C, '+', D, '=', 7, sep='')
elif A - B + C - D == 7:
    print(A, '-', B, '+', C, '-', D, '=', 7, sep='')
elif A - B - C + D == 7:
    print(A, '-', B, '-', C, '+', D, '=', 7, sep='')
elif A - B - C - D == 7:
    print(A, '-', B, '-', C, '-', D, '=', 7, sep='')

Submission status: Accepted

Solution code:
from itertools import product
A, B, C, D = input()
for op in product(['+', '-'], repeat=3):
    formula = A + op[0] + B + op[1] + C + op[2] + D
    if eval(formula) == 7:
        print(formula + '=7')
        break

Submission status: Accepted

Solution code:
import sys
A,B,C,D = map(int, list(input()))
if A+B+C+D==7:
    print("{}+{}+{}+{}=7".format(A,B,C,D))
    sys.exit()
if A+B-C+D==7:
    print("{}+{}-{}+{}=7".format(A,B,C,D))
    sys.exit()
if A+B+C-D==7:
    print("{}+{}+{}-{}=7".format(A,B,C,D))
    sys.exit()
if A+B-C-D==7:
    print("{}+{}-{}-{}=7".format(A,B,C,D))
    sys.exit()
if A-B+C+D==7:
    print("{}-{}+{}+{}=7".format(A,B,C,D))
    sys.exit()
if A-B-C+D==7:
    print("{}-{}-{}+{}=7".format(A,B,C,D))
    sys.exit()
if A-B+C-D==7:
    print("{}-{}+{}-{}=7".format(A,B,C,D))
    sys.exit()
if A-B-C-D==7:
    print("{}-{}-{}-{}=7".format(A,B,C,D))
    sys.exit()

Submission status: Accepted

Solution code:
a, b, c, d = [int(x) for x in list(str(input()))]
op = ['+', '-']
for op1 in op:
  for op2 in op:
    for op3 in op:
      if op1 == '+':
        result = a + b
      else:
        result = a - b
      if op2 == '+':
        result += c
      else:
        result -= c
      if op3 == '+':
        result += d
      else:
        result -= d
      if result == 7:
        print("{}{}{}{}{}{}{}=7".format(a, op1, b, op2, c, op3, d))
        exit()

Submission status: Accepted

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

r = 7-num[0]

for i in range(2):
  for j in range(2):
    for k in range(2):
      l = (-1)**i * num[1] + (-1)**j * num[2] + (-1)**k * num[3]
      if l == r:
        if i == 0:
          first = '+'
        else:
          first = '-'
        if j == 0:
          second = '+'
        else:
          second = '-'
        if k == 0:
          third = '+'
        else:
          third = '-'
        print('{}{}{}{}{}{}{}=7'.format(num[0],first,num[1],second,num[2],third,num[3]))
        exit()

Submission status: Accepted

Solution code:
ABCD = input()
for i in range(2 ** (len(ABCD)-1)):
    bit = format(i, "b").zfill(len(ABCD))[::-1]
    t = ""
    for j, s in enumerate(ABCD):
        t += s
        if bit[j] == "0":
            t += "+"
        if bit[j] == "1":
            t += "-"
    if len(t) == 8:
        t = t[:-1]
    if eval(t) == 7:
        print(t + "=7")
        break

Submission status: Accepted

Solution code:
ABCD=list(map(int,list(input())))
#bit全探索の練習
 #0はマイナス1はプラス
for i in range(1<<3):#普通に16って書いてもいいんだけどね
    ans=ABCD[0]
    plus=["+","+","+"]
    for j in range(3):#右からj+1個目のプラス(j+2コメの数)について
        if (i>>j & 1)==1:#1なら
            ans+=ABCD[3-j]
        else:
            ans-=ABCD[3-j]
            plus[2-j]="-"
    if ans==7:
        [A,B,C,D]=[str(i) for i in ABCD]
        print(A+plus[0]+B+plus[1]+C+plus[2]+D+"=7")
        break

Submission status: Accepted

Solution code:
""" AtCoder """

ABCD = input()

l = ['+', '-']

for i in range(8):
    ans = ABCD[0] + l[(i >> 0) & 1] + ABCD[1] + l[(i >> 1) & 1] + ABCD[2] + l[(i >> 2) & 1] + ABCD[3]
    if eval(ans) == 7:
        print(ans+"=7")
        exit()

Submission status: Accepted

Solution code:
S = input()

N = len(S)-1

for i in range(2**N):
    binary = bin(i)
    binary = binary[2:].zfill(N)
    
    sumsum = int(S[0])
    for j in range(N):
        if binary[j] == '0':
            sumsum -= int(S[j+1])
        else:
            sumsum += int(S[j+1])
        
            
    if sumsum == 7:
        ans = S[0]
        for j in range(N):
            if binary[j] == '0':
                ans += '-'
            else:
                ans += '+'
            ans += S[j+1]
        
        ans += '=7'
        break
    
print(ans)

Submission status: Accepted

Solution code:
N=list(str(input()))
F=[N[0]+'+-'[i%2]+N[1]+'+-'[(i//2)%2]+N[2]+'+-'[(i//4)%2]+N[3] for i in range(8)]
for f in F:
    if eval(f)==7:
        print(f+'=7')
        break
    else:
        continue

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
x = list(map(int, list(input())))
op = ["-","+"]
for i in range(8):
    t = x[0]
    for j in range(3):
        if i>>j&1 == 1:
            t += x[j+1]
        else:
            t -= x[j+1]
    if t==7:
        print("{}{}{}{}{}{}{}=7".format(
            x[0],op[i>>0&1],x[1],op[i>>1&1],x[2],op[i>>2&1],x[3]
        ))
        break

Submission status: Accepted

Solution code:
num = str(input())

op=['+', '-']
siki=[]
for op1 in op:
    for op2 in op:
        for op3 in op:
            siki.append(num[0] + op1 + num[1] + op2 + num[2] + op3 + num[3])

for s in siki:
    if eval(s) ==7:
        print(s+"=7")
        break

Submission status: Accepted

Solution code:
num=list(str(input()))
num=[int(n) for n in num]
cnt=len(num)-1
for i in range(2**cnt):
    ln=["-"]*cnt
    tl=num[:]
    for j in range(cnt):
        if ((i>>j)&1):
            ln[cnt-j-1]="+"
    ans=tl[0]
    for k in range(cnt):
        tl.insert(k*2+1,ln[k])
        if ln[k]=="+":
            ans+=tl[k*2+2]       
        else:
            ans-=tl[k*2+2]
    if ans==7:
        print("".join(map(str,tl))+"=7")
        break

Submission status: Accepted

Solution code:
S = str(input())

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

op = [1, -1]

for i in op:
    for j in op:
        for k in op:
            if a + i*b + j*c + k*d == 7:
                op1 = '+' if i == 1 else '-'
                op2 = '+' if j == 1 else '-'
                op3 = '+' if k == 1 else '-'
                print('{}{}{}{}{}{}{}=7'.format(a, op1, b, op2, c, op3, d))
                exit()

Submission status: Accepted

Solution code:
def main():
    nums = [int(n) for n in list(input())]

    for i in range(2**3):
        val = nums[0]
        exp = "{}".format(val)

        for j in range(3):
            if 1 & (i >> j) == 1:
                val -= nums[j+1]
                exp += "-{}".format(nums[j+1])
            else:
                val += nums[j+1]
                exp += "+{}".format(nums[j+1])

        if val == 7:
            print(exp+"=7")
            break


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def dfs(expression, val, rest_nums):
#    print(expression, val, rest_nums)
    if len(rest_nums) == 0:
        if val == 7:
            return expression+"=7"
        else:
            return False

    new_num = rest_nums[0]
    # +
    result = dfs(expression+"+{}".format(new_num), val+new_num, rest_nums[1:])
    if result:
        return result

    # -
    result = dfs(expression+"-{}".format(new_num), val-new_num, rest_nums[1:])
    if result:
        return result
    return False


def main():
    A, B, C, D = [int(n) for n in list(input())]

    result = dfs(str(A), A, [B,C,D])
    print(result)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def op(i):
    return '+' if i == 1 else '-'

def solve():
    x = [int(i) for i in input()]
    for op1 in [-1, 1]:
        for op2 in [-1, 1]:
            for op3 in [-1, 1]:
                if x[0] + op1 * x[1] + op2 * x[2] + op3 * x[3] == 7:
                    return '{}{}{}{}{}{}{}=7'.format(x[0], op(op1), x[1], op(op2), x[2], op(op3), x[3])

print(solve())

Submission status: Accepted

Solution code:
import sys

def func(s, i):
    if i == 7:
        if eval(s) == 7:
            print(s + '=7')
            sys.exit()
        return
    s = s[:i] + '+' + s[i + 1:]
    func(s, i + 2)
    s = s[:i] + '-' + s[i + 1:]
    func(s, i + 2)

s = input()

a = s[0]
b = s[1]
c = s[2]
d = s[3]
s = a + '#' + b + '#' + c + '#' + d

func(s, 1)

Submission status: Accepted

Solution code:
abcd = input()

a = int(abcd[0])
b = int(abcd[1])
c = int(abcd[2])
d = int(abcd[3])
for X in range(1, 3):
    for Y in range(1, 3):
        for Z in range(1, 3):
            if b * ((-1) ** X) + c * ((-1) ** Y) + d * ((-1) ** Z) == (7 - a):
                op1 = '-' if X == 1 else '+'
                op2 = '-' if Y == 1 else '+'
                op3 = '-' if Z == 1 else '+'
                print("{}{}{}{}{}{}{}=7".format(a, op1, b, op2, c, op3, d))
                exit(0)

Submission status: Accepted

Solution code:
from itertools import product
e = (1,-1)
a,b,c,d = map(int, list(input()))
for i,j,k in product(e,repeat=3):
  if a+b*i+c*j+d*k == 7:
    break
dic = {1:"+",-1:"-"}
l = [a,dic[i],b,dic[j],c,dic[k],d]
print("".join(map(str,l))+"=7")

Submission status: Accepted

Solution code:
num = [int(i) for i in str(input())]
for i in range(1<<3):
    bin_i = format(i, '03b')
    count = num[0]
    ans = str(num[0])
    for j in range(3):
        if bin_i[j]=='1':
            count+= num[j+1]
            ans += '+'+str(num[j+1])
        else:
            count+= -num[j+1]
            ans += '-'+str(num[j+1])
    if count==7:
        print(ans+'=7')
        break

Submission status: Accepted

Solution code:
import itertools

A, B, C, D = list(input())
OP = ['+', '-']

for op1, op2, op3 in itertools.product(OP, OP, OP):
    s = A + op1 + B + op2 + C + op3 + D
    if eval(s) == 7:
        print(s + "=7")
        break

Submission status: Accepted

Solution code:
from itertools import product

MAX_ITEM = 4
NUM = 7
OPS = ("+", "-")

ABCD = input()


def main():
    for p in product(OPS, repeat=3):
        eq = ABCD[0]

        for o, abcd in zip(p, ABCD[1:]):
            eq += o
            eq += abcd

        if eval(eq) == NUM:
            print(eq + "=" + str(NUM))
            break

    return


main()

Submission status: Accepted

Solution code:
from itertools import product

MAX_ITEM = 4
NUM = 7
OPS = ("+", "-")

ABCD = list(input())


def main():
    for p in product(OPS, repeat=3):
        eq = ABCD[0]

        for o, abcd in zip(p, ABCD[1:]):
            eq += o
            eq += abcd

        if eval(eq) == NUM:
            print(eq + "=" + str(NUM))
            break

    return


main()

Submission status: Accepted

Solution code:
from itertools import product

MAX_ITEM = 4
NUM = 7

ABCD = [i for i in list(input())]


def main():
    ops = ("+", "-")

    for p in product(ops, repeat=3):
        eq = ABCD[0]

        for o, abcd in zip(p, ABCD[1:]):
            eq += o
            eq += abcd

        if eval(eq) == NUM:
            print(eq + "=" + str(NUM))
            break

    return


main()

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[j] = '+'
            
    formula = ''
    for a, b in zip(n, op + ['']):
        formula += (a + b)
    if eval(formula) == 7:
        print(formula + '=7')
        break

Submission status: Accepted

Solution code:
MAX_ITEM = 4
NUM = 7

ABCD = [int(i) for i in list(input())]


def main():
    for i in range(2 ** (MAX_ITEM - 1)):
        ans = ABCD[0]

        for j in range(MAX_ITEM - 2, -1, -1):
            if i >> j & 1:
                ans += ABCD[j + 1]

            else:
                ans -= ABCD[j + 1]

        if NUM == ans:
            print("".join(
                ["+" if k % 2 and i >> k // 2 & 1 else
                 "-" if k % 2 else
                 str(ABCD[k // 2]) for k in range(2 * MAX_ITEM - 1)])
                + "=" + str(NUM))

            break

    return


main()

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    a,b,c,d = list(map(int, S()))
    s = ["-","+"]
    for i in range(2):
        for j in range(2):
            for k in range(2):
                if eval(str(a)+s[i]+str(b)+s[j]+str(c)+s[k]+str(d)) == 7:
                    print(str(a)+s[i]+str(b)+s[j]+str(c)+s[k]+str(d)+"=7")
                    quit()
#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    C()

Submission status: Accepted

Solution code:
A, B, C, D = list(map(int, list(input())))
if A + B + C + D == 7:
	print(str(A) + "+" + str(B)+ "+" + str(C) + "+" + str(D) + "=7")
elif A + B + C - D == 7:
	print(str(A) + "+" + str(B)+ "+" + str(C) + "-" + str(D) + "=7")
elif A + B - C + D == 7:
	print(str(A) + "+" + str(B)+ "-" + str(C) + "+" + str(D) + "=7")
elif A + B - C - D == 7:
	print(str(A) + "+" + str(B)+ "-" + str(C) + "-" + str(D) + "=7")
elif A - B + C + D == 7:
	print(str(A) + "-" + str(B)+ "+" + str(C) + "+" + str(D) + "=7")
elif A - B + C - D == 7:
	print(str(A) + "-" + str(B)+ "+" + str(C) + "-" + str(D) + "=7")
elif A - B - C + D == 7:
	print(str(A) + "-" + str(B)+ "-" + str(C) + "+" + str(D) + "=7")
else:
	print(str(A) + "-" + str(B)+ "-" + str(C) + "-" + str(D) + "=7")

Submission status: Accepted

Solution code:
s = input()
nums = []
for i in s:
    nums.append(int(i))

for i in range(1 << (len(nums) - 1)):
    sum = nums[0]
    opes = []
    for j in range(3):
        if (i >> j) & 1:
            sum += nums[j+1]
            opes.append('+')
        else:
            sum -= nums[j+1]
            opes.append('-')
    if sum == 7:
        break

print('{0}{1}{2}{3}{4}{5}{6}=7'.format(nums[0], opes[0], nums[1], opes[1], nums[2], opes[2], nums[3]))

Submission status: Accepted

Solution code:
A = list(input())
op = ["-", "+"]
for op1 in op:
    for op2 in op:
        for op3 in op:
            left = A[0]+op1+A[1]+op2+A[2]+op3+A[3]
            if eval(left) == 7:
                print(left+"=7")
                exit()

Submission status: Accepted

Solution code:
na = lambda: input()

text = na()
num = []

for t in text:
    num.append(int(t))

ans = 0
pm = []
for a in [1,-1]:
    for b in [1,-1]:
        for c in [1,-1]:
            pm_tmp = [1]
            pm_tmp.append(a)
            pm_tmp.append(b)
            pm_tmp.append(c)
            pm.append(pm_tmp)

for p in pm:
    ans_num = 0
    for q in range(4):
        ans_num += num[q]*p[q]
        if q == 0:
            ans_txt = str(num[q])
        else:
            if p[q] == -1:
                ans_txt += "-"
            elif p[q] == 1:
                ans_txt += "+"  
            ans_txt += str(num[q]) 
    if ans_num == 7:
        ans_txt += "=7"
        ans = ans_txt
            
print(ans)

Submission status: Accepted

Solution code:
list=list(input())
for i in range(4):
    list[i]=int(list[i])
for x in range(2):
    for y in range(2):
        for z in range(2):
            if x==0:
                p=list[1]
                P="+"+str(list[1])
            else:
                p=-list[1]
                P="-"+str(list[1])
            if y==0:
                q=list[2]
                Q="+"+str(list[2])
            else:
                q=-list[2]
                Q="-"+str(list[2])
            if z==0:
                r=list[3]
                R="+"+str(list[3])
            else:
                r=-list[3]
                R="-"+str(list[3])
            if list[0]+p+q+r==7:
                print(str(list[0])+P+Q+R+"=7")
                exit()

Submission status: Accepted

Solution code:
s=input()

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

op=['+','-']

for i in op:
    for j in op:
        for k in op:
            if eval(str(a)+i+str(b)+j+str(c)+k+str(d))==7:
                ans=str(a)+i+str(b)+j+str(c)+k+str(d)+'=7'

print(ans)

Submission status: Accepted

Solution code:
def train_ticket(A: int, B: int, C: int, D: int) -> str:
    # 演算子の組み合わせは高々 2^3 = 8 通りしかないので
    # 全探索で OK
    nums = [B, C, D]
    for i in range(1 << 3):
        s = A
        ans = str(A)
        for j in range(3):
            if i & 1 == 1:
                s += nums[j]
                ans += '+' + str(nums[j])
            else:
                s -= nums[j]
                ans += '-' + str(nums[j])
            i >>= 1

        if s == 7:
            return ans + '=7'
    return 'invalid test case'


if __name__ == "__main__":
    A, B, C, D = map(int, input())
    ans = train_ticket(A, B, C, D)
    print(ans)

Submission status: Accepted

Solution code:
n=input()
global ans
def saiki(s,a,m):
    if m==len(n):
#        print(s)
        if 7==eval(s):
            global ans
            ans=s+'=7'
    else:
        for x in a:
            t=s
            s=s+x+n[m]
            saiki(s,a,m+1)
            s=t 

saiki(n[0],['-','+'],1)
print(ans)

Submission status: Accepted

Solution code:
import sys
s = input()
op = '+-'
for i in op:
    for j in op:
        for k in op:
            if eval(s[0]+i+s[1]+j+s[2]+k+s[3]) == 7:
                print(str(s[0]+i+s[1]+j+s[2]+k+s[3]+'=7'))
                sys.exit()

Submission status: Accepted

Solution code:
import itertools
a, b, c, d = input()
op = ["+", "-"]
for op1, op2, op3 in itertools.product(op, repeat=3):
    s = a+op1+b+op2+c+op3+d
    if eval(s) == 7:
        print(s+"=7")
        break

Submission status: Accepted

Solution code:
A, B, C, D = map(int, list(input()))
for i in range(2):
    for j in range(2):
        for k in range(2):
            x = A
            ans = str(A)
            if i:
                x += B
                ans += "+"
            else:
                x -= B
                ans += "-"
            ans += str(B)
            if j:
                x += C
                ans += "+"
            else:
                x -= C
                ans += "-"
            ans += str(C)
            if k:
                x += D
                ans += "+"
            else:
                x -= D
                ans += "-"
            ans += str(D)
            ans += "=7"
            if x == 7:
                print(ans)
                import sys
                sys.exit()

Submission status: Accepted

Solution code:
import itertools
s=input()
op=list(itertools.product([1,-1], repeat=3))
ans=[int(s[0])]*8
for i in range(8):
    for j in range(3):
        ans[i]+=op[i][j]*int(s[j+1])
newop=['+']*3
for i in range(3):
    if op[ans.index(7)][i]!=1:
        newop[i]='-'
print(s[0]+newop[0]+s[1]+newop[1]+s[2]+newop[2]+s[3]+'=7')

Submission status: Accepted

Solution code:
ABCD = input()
A = int(ABCD[0])
B = int(ABCD[1])
C = int(ABCD[2])
D = int(ABCD[3])
op = ['+','-']

for op1 in op:
    for op2 in op:
        for op3 in op:
            ans = 0
            ans = A+B if op1 == '+' else A-B
            ans = ans+C if op2 == '+' else ans-C
            ans = ans+D if op3 == '+' else ans-D
            if ans == 7:
                print(str(A)+op1+str(B)+op2+str(C)+op3+str(D)+'=7')
                exit()

Submission status: Accepted

Solution code:
import sys
from itertools import product

def main():
    input = sys.stdin.readline
    N = [int(c) for c in input().strip()]

    op = list(product([1, -1], repeat=3))
    for o in op:
        if N[0] + N[1] * o[0] + N[2] * o[1] + N[3] * o[2] == 7:
            ans = str(N[0])
            for i in range(3):
                if o[i] == 1:
                    ans += '+' + str(N[i+1])
                else:
                    ans += '-' + str(N[i+1])
            ans += '=7'
            break

    print(ans)
    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
ABCD = input()
def DP(x , i):
    if i == 4:
        if eval(x) == 7:
            print(x + '=7')
            exit()
        else:
            return
    else:
        DP(x + '+' + ABCD[i] , i + 1)
        DP(x + '-' + ABCD[i] , i + 1)
        return

DP(ABCD[0],1)

Submission status: Accepted

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

def f(idx):
    return "+" if idx==0 else "-"
for i in range(2):
    for j in range(2):
        for k in range(2):
            num = a
            num += b if i == 0 else -b
            num += c if j == 0 else -c
            num += d if k == 0 else -d

            if num == 7:
                result = str(a) + f(i) + str(b) + f(j) + str(c) + f(k) + str(d) + "=7"
                print(result)
                exit()

Submission status: Accepted

Solution code:
l = list(input())
n = len(l) - 1

for i in range(2**n):
    op = ["-"] * n
    for j in range(n):
        if i>>j & 1 :
            op[j] = "+"
    formula = ""
    for p, q in zip(l, op + [""]):
        formula += p + q
    if eval(formula) == 7:
        print(formula + "=7")
        break

Submission status: Accepted

Solution code:
S=input()
for i in range(1<<3):
  tmp=S[0]
  for j in range(3):
    if i>>j&1==1:
      tmp+='+'
    else:
      tmp+='-'
    tmp+=S[j+1]
  if eval(tmp)==7:
    break
print(tmp+'=7')

Submission status: Accepted

Solution code:
A = list(input())
intA = list(map(int, A))
if intA[0]+intA[1]+intA[2]+intA[3]==7:
    print(A[0]+"+"+A[1]+"+"+A[2]+"+"+A[3]+"=7")
elif intA[0]+intA[1]+intA[2]-intA[3]==7:
    print(A[0]+"+"+A[1]+"+"+A[2]+"-"+A[3]+"=7")
elif intA[0]+intA[1]-intA[2]+intA[3]==7:
    print(A[0]+"+"+A[1]+"-"+A[2]+"+"+A[3]+"=7")
elif intA[0]+intA[1]-intA[2]-intA[3]==7:
    print(A[0]+"+"+A[1]+"-"+A[2]+"-"+A[3]+"=7")
elif intA[0]-intA[1]+intA[2]+intA[3]==7:
    print(A[0]+"-"+A[1]+"+"+A[2]+"+"+A[3]+"=7")
elif intA[0]-intA[1]+intA[2]-intA[3]==7:
    print(A[0]+"-"+A[1]+"+"+A[2]+"-"+A[3]+"=7")
elif intA[0]-intA[1]-intA[2]+intA[3]==7:
    print(A[0]+"-"+A[1]+"-"+A[2]+"+"+A[3]+"=7")
elif intA[0]-intA[1]-intA[2]-intA[3]==7:
    print(A[0]+"-"+A[1]+"-"+A[2]+"-"+A[3]+"=7")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
def main(S):
    for i in range(1 << len(S)):
        st = str(S[0])
        num = int(S[0])
        for j in range(len(S)-1):
            if((i >> j) & 1):
                st = st + "+" + str(S[j+1])
                num += int(S[j+1])
            else:
                st = st + "-" + str(S[j+1])
                num -= int(S[j+1])
        if(num == 7):
            print(st + "=7")
            break
    
if(__name__ == "__main__"):
    S = list(input())
    
    main(S)

Submission status: Accepted

Solution code:
def change(num):
    if num<0:
        return str(num)
    else:
        return "+"+str(num)

a,b,c,d=[int(i) for i in input()]
for i in range(10):
    for j in range(-9,10):
        for k in range(-9,10):
            if 9>=7-(i+j+k)>=-9:
                if i==a and abs(j)==b and abs(k)==c and abs(7-(i+j+k))==d:
                    print(str(i)+change(j)+change(k)+change(7-(i+j+k))+"=7")
                    exit()

Submission status: Accepted

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

op_set = [[op1, op2, op3, ""] for op1 in ["+", "-"] for op2 in ["+", "-"] for op3 in ["+", "-"]]

for i in range(8):
    string = "".join([s1 + s2 for s1, s2 in zip([A, B, C, D], op_set[i])])
    if eval(string) == 7:
        print(string + "=7")
        break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from itertools import product
import sys
 
def main(A, B, C, D):
    for op1, op2, op3 in product(("+", "-"), repeat=3):
        e = A + op1 + B + op2 + C + op3 + D
        x = eval(e)
        if x == 7:
            print(e + "=7")
            sys.exit()
    
if(__name__ == "__main__"):
    A, B, C, D = list(input())
    
    main(A, B, C, D)

Submission status: Accepted

Solution code:
a, b, c, d = map(int, list(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:
from itertools import product
A, B, C, D = list(input())
for op1, op2, op3 in product(("+", "-"), repeat=3):
    e = A + op1 + B + op2 + C + op3 + D
    x = eval(e)
    if x == 7:
        print(e + "=7")
        break

Submission status: Accepted

Solution code:
def bit_all(s,n):
    for i in range(2**n):
        c = []
        for j in range(n):
            if i>>j & 1:
                c.append("+")
            else:
                c.append("-")
        if eval(s[0] + c[0] + s[1] + c[1] + s[2] + c[2] + s[3]) == 7:
            print(s[0] + c[0] + s[1] + c[1] + s[2] + c[2] + s[3] + "=7")
            exit()
                
                
a = list(input())
bit_all(a,len(a)-1)

Submission status: Accepted

Solution code:
def n_ary1(l,d): # リストl中の文字でd桁を全列挙(sorted)
    if d == 1:
        return(l)
    ll = n_ary1(l,d-1)
    lll = []
    for i in l:
        for j in ll:
            lll.append(i+j)
            #lll.append(int(i+j)) ## n進数の場合
    return(lll)
In = list(input())
In = [int(i) for i in In]
op = n_ary1([[0],[1]],3)

for i in op:
    s = In[0]
    for j in range(3):
        if i[j]:
            s += In[j+1]
        else:
            s -= In[j+1]
    if s == 7:
        ansl = i
        break


ans = str(In[0])
for i in range(3):
    if ansl[i] :
        ans = ans + '+' + str(In[i+1])
    else:
        ans = ans + '-' + str(In[i+1])
ans = ans + '=7'
print(ans)

Submission status: Accepted

Solution code:
S = input()

def dfs(op):
    if len(op) == 3:
        res = int(S[0])
        for i in range(3):
            if op[i] == "+":
                res += int(S[i+1])
            elif op[i] == "-":
                res -= int(S[i+1])
        if res == 7:
            formula = S[0]
            for i in range(3):
                formula += op[i] + S[i+1]
            formula += "=7"
            return formula
        else:
            return ""
    
    s1 = dfs(op + "+")
    s2 = dfs(op + "-")
    if len(s1) > len(s2):
        return s1
    else:
        return s2

print(dfs(""))

Submission status: Accepted

Solution code:
s= str(input())
op = ["+","-"]
for op1 in op:
  for op2 in op:
    for op3 in op:
       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")
         exit()

Submission status: Accepted

Solution code:
In = [int(x) for x in input()]
BREAK = False
for i in range(2):
  for j in range(2):
    for k in range(2):
      s = In[0]
      if i == 0:
        s += In[1]
      else:
        s -= In[1]
      if j == 0:
        s += In[2]
      else:
        s -= In[2]
      if k == 0:
        s += In[3]
      else:
        s -= In[3]
      if s == 7:
        BREAK = True
        break
    if BREAK:
      break
  if BREAK:
    break
Out = str(In[0])
m = 1
for l in [i, j, k]:
  if l % 2:
    Out += "-" + str(In[m])
  else:
    Out += "+" + str(In[m])
  m += 1
print(Out + "=7")

Submission status: Accepted

Solution code:
def main():
    digits = [int(c) for c in input()]
    print(solve(digits))

def solve(digits):
    s = rec(str(digits[0]), digits[0], digits[1:])
    return '%s=7' % s

def rec(s, n, digits):
    if len(digits) == 0:
        if n == 7:
            return s
        else:
            return None
    
    x = rec('%s+%d' % (s, digits[0]), n + digits[0], digits[1:])
    if x is not None:
        return x
    y = rec('%s-%d' % (s, digits[0]), n - digits[0], digits[1:])
    if y is not None:
        return y

    return None

main()

Submission status: Accepted

Solution code:
def main():
  set = ("-", "+")
  d = [int(x) for x in input()]
  for i in range(1 << 3):
    op = []
    total = d[0]
    for j in range(3):
      x = (i >> j) & 1
      op.append(set[x])
      if x == 1:
        total += d[j+1]
      else:
        total -= d[j+1]
    #print(i, total)
    if total == 7:
      print('{}{}{}{}{}{}{}=7'.format(d[0], op[0], d[1], op[1], d[2], op[2], d[3]))
      return 0
  print("error")
  return 0

main()

Submission status: Accepted

Solution code:
S = input()

ans = [S[0]]
for i in range(1,4):
    can = []
    for a in ans:
        can.append(a+'+'+S[i])
        can.append(a+'-'+S[i])
        ans = can

for j in ans:
    if eval(j) == 7:
        print(j+"=7")
        exit()

Submission status: Accepted

Solution code:
s = input()
ans = []
for i in range(1 << (len(s)-1)):
    a = ''
    for j in range(len(s)):
        a += s[j]
        if j == 3:
            break
        if 1 & (i >> j) == 1:
            a += '+'
        if 1 & (i >>j) == 0:
            a += '-'
    if eval(a) == 7:
        a += '=7'
        ans.append(a)
print(ans[0])

Submission status: Accepted

Solution code:
s=input()

for i in range(2**3):
    st=s[0]
    cost=int(s[0])
    for j in range(3):
        if (i>>j)&1:
            cost=cost+int(s[j+1])
            st=st+"+"+s[j+1]
        else:
            cost=cost-int(s[j+1])
            st=st+"-"+s[j+1]
    if cost==7:
        print(st+"=7")
        break