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

# https://atcoder.jp/contests/abc078/tasks/arc085_b
# 15:53-


def main():
    a, b, c, d = list(map(int, list(input())))

    def p(x, y):
        return x + y
    
    def m(x, y):
        return x - y
    
    conv = {0: "+", 1: "-"}
    
    for i, op1 in enumerate([p, m]):
        for j, op2 in enumerate([p, m]):
            for k, op3 in enumerate([p, m]):
                if op3(op2(op1(a, b), c), d) == 7:
                    return "{}{}{}{}{}{}{}=7".format(a, conv[i], b, conv[j], c, conv[k], d)


print(main())

Submission status: Accepted

Solution code:
import sys

abcd = input()
a = [int(i) for i in abcd]

for i in range(2**3) :
  bit = i
  v = a[0]
  ans = str(v)
  for j in range(1,4) :
    c = bit%2
    bit = bit//2
    if c == 0 :
      v -= a[j]
      ans += '-' + str(a[j])
    else :
      v += a[j]
      ans += '+' + str(a[j])
  if v == 7 :
    print(ans+'=7')
    sys.exit()

Submission status: Accepted

Solution code:
import sys

abcd=input()

for i in range(8):
	tempsum=int(abcd[0])
	tempmoji=abcd[0]
	
	for j in range(3):
		if(i>>j) & 1:
			tempsum += int(abcd[j+1])
			tempmoji = tempmoji + "+" + abcd[j+1]
		else:
			tempsum -= int(abcd[j+1])
			tempmoji = tempmoji + "-" + abcd[j+1]
	if tempsum == 7:
		print(tempmoji + "=7")
		sys.exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, C, D = map(int, list(str(input())))
ABCD=[A,B,C,D]
#print(ABCD)
for i in range(0, 2**3):
    #print(bin(i))
    answer=A
    shiki='{}'.format(A)
    for j in range(3):
        #print(bin(i), j)
        if ((i >> j) & 1):
            answer+=ABCD[j+1]
            shiki+='+'
        else:
            answer-=ABCD[j+1]
            shiki+='-'
        shiki+='{}'.format(ABCD[j+1])
    #print(answer)
    #print(shiki)
    if answer==7:
        shiki+='=7'
        print(shiki)
        break

Submission status: Accepted

Solution code:
a, b, c, d = map(int, input())
pm = [1, -1]
op = ["+", "-"]
for i in range(2):
  for j in range(2):
    for k in range(2):
      if a + pm[i]*b + pm[j]*c + pm[k]*d == 7:
        ans = [op[i], op[j], op[k]]
        break
print("".join(map(str, [a, ans[0], b, ans[1], c, ans[2], d, "=", 7])))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from itertools import product
import sys


def solve(ABCD: str):
    A, B, C, D = ABCD
    for ops in product(["+", "-"], repeat=3):
        expr = "{1}{0[0]}{2}{0[1]}{3}{0[2]}{4}".format(ops, A, B, C, D)
        if eval(expr) == 7:
            print(expr + "=7")
            return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    ABCD = next(tokens)  # type: str
    solve(ABCD)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
A = list(map(int,input())) #リストにしておけば入力変わっても対応できるので
#print(A)
n = len(A) - 1
for i in range(2**n):
    pattern = ['-']*n #さきにーの配列にしておく＞条件満たしたら＋に
    ans= A[0]
    #print("num {} :".format(i), end = "" )
    for j in range(n):
        if ((i >> j) & 1):
            pattern[j]='+'  #pattern[n-j-1]だと，bit演算子順
            ans+=A[j+1]
        else:
            #pattern.append('-0')
            ans-=A[j+1]

    else:
        if ans == 7:
            print(A[0], end='')
            for k in range(n):
                print(pattern[k],end='')
                print(A[k+1],end='')
            else:
                print('=7')
            break

Submission status: Accepted

Solution code:
s = input()
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])
if a + b + c + d == 7:
  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:
abcd = input()

abcd_list = []

def plus_or_minas(abcd_str, pos, abcd):
    if pos == 4:
        abcd_list.append(abcd_str)
        return

    plus_or_minas(abcd_str+'+'+abcd[pos], pos+1, abcd)
    plus_or_minas(abcd_str+'-'+abcd[pos], pos+1, abcd)
    return

plus_or_minas(abcd[0], 1, abcd)

for i_abcd in abcd_list:
    if eval(i_abcd) == 7:
        print(i_abcd+'=7')
        exit()

Submission status: Accepted

Solution code:
N = input()
A = []
for i in range(len(N)):
    A.append(int(N[i]))

for i in range(2 ** 3):
    List = []
    for j in range(3):
        if (i >> j) & 1 == 1:
            List.append(1)
        elif (i >> j) & 1 == 0:
            List.append(0)
    ans = A[0]
    for k in range(len(List)):
        if (List[k]):
            ans += A[k+1]
        else :
            ans -= A[k+1]

    if ans == 7:
        break

print(A[0], end="")
for i in range(3):
    if List[i]:
        print("+", end="")
    else:
        print("-", end="")
    print(A[i + 1], end="")
print("=7",end="")

Submission status: Accepted

Solution code:
# import sys
# read = sys.stdin.buffer.read
# readline = sys.stdin.buffer.readline
# readlines = sys.stdin.buffer.readlines

# def myinput():
#     return map(int,readline().split())

# abcd = list(map(int,(list(input()))))
# print(abcd)

abcd = input()

for i in range(2**3):
    r = int(abcd[0])
    ans = abcd[0]
    for j in range(3):
        # op="+"の場合
        if i & (2**j):
            ans = ans + "+" + abcd[j+1]
            r += int(abcd[j+1])
        # op="-"の場合
        else: 
            ans = ans + "-" + abcd[j+1]
            r -= int(abcd[j+1])
    if r==7:
        output = ans + "=7"
# print(r)
# print(ans)
print(output)

Submission status: Accepted

Solution code:
import sys
s=input()
a=[int(s[i]) for i in range(4)]
for b in [a[1],-a[1]]:
    for c in[a[2],-a[2]]:
        for d in [a[3],-a[3]]:
            if a[0]+b+c+d==7:
                s=str(a[0])
                for x in [b,c,d]:
                    s+="+"+str(x) if x>=0 else str(x)
                s+="=7"
                print(s)
                sys.exit()

Submission status: Accepted

Solution code:
num = input()

#print(num)
flag = "loop"
op_list = ["+","-"]
for i in op_list:
  if flag == "break":
    break
  for j in op_list:
    if flag == "break":
      break
    for k in op_list:
      if i == "+":
        ans = int(num[0]) + int(num[1])
      else:
        ans = int(num[0]) - int(num[1])
        
      if j == "+":
        ans += int(num[2])
      else:
        ans -= int(num[2])
        
      if k == "+":
        ans += int(num[3])
      else:
        ans -= int(num[3])
      #print(ans)
      if ans == 7:
        print(num[0]+i+num[1]+j+num[2]+k+num[3]+"=7")
        flag = "break"
        break
      ans = 0

Submission status: Accepted

Solution code:
from itertools import product

def main():
    n = [i for i in input()]
    for i in product(('+', '-'), repeat=3):
        formula = n[0]
        for op, num in zip(i, n[1:]):
            formula += op
            formula += num
        if eval(formula) == 7:
            print(formula+'=7')
            exit()

if __name__ == '__main__':
    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[op_cnt - 1 - j] = "+"
            
    formula = ""
    
    for p_n, p_op in zip(n, op + [""]):
        formula += (p_n + p_op)
    if eval(formula) == 7:
        print(formula + "=7")
        break

Submission status: Accepted

Solution code:
abcd = str(input())
a = abcd[0]
b = abcd[1]
c = abcd[2]
d = abcd[3]

sign = ['+', '-']
for i in range(2):
    for j in range(2):
        for k in range(2):
            tmp = a + sign[i] + b + sign[j] + c + sign[k] + d  
            if eval(tmp) == 7:
                print(tmp+'=7')
                exit()

Submission status: Accepted

Solution code:
n = [int(x) for x in input()]
s=len(n)-1

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

    sum=n[0]
    ans=str(n[0])
    
    for i in range(s):
        if op[i] == '+':
            sum+=n[i+1]
            ans += '+'
        else:
            sum-=n[i+1]
            ans += '-'
        ans += str(n[i+1])

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

Submission status: Accepted

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

res = []
for i in range(2**4):
    s = S[0]
    c = []
    for j in range(3):
        m = i >> j & 1
        if m == 0:
            s = s + S[j+1]* -1
            c.append("-")
        else:
            s = s + S[j+1]
            c.append("+")

    if s == 7:
        print(str(S[0])+""+c[0]+""+str(S[1])+""+c[1]+""+str(S[2])+""+c[2]+str(S[3])+"=7")
        break

Submission status: Accepted

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

for i in range(1 << 3):
    op = [None] * 3
    a = A
    b = B if (i >> 0) & 1 else -B
    op[0] = '+' if (i >> 0) & 1 else '-'

    c = C if (i >> 1) & 1 else -C
    op[1] = '+' if (i >> 1) & 1 else '-'

    d = D if (i >> 2) & 1 else -D
    op[2] = '+' if (i >> 2) & 1 else '-'

    if sum([a, b, c, d]) == 7:
        break

print('{}{}{}{}{}{}{}=7'.format(A, op[0], B, op[1], C, op[2], D))

Submission status: Accepted

Solution code:
def conv_bin(i, digit):
    if i & 1 << digit:
        return "+"
    else:
        return "-"

if __name__ == "__main__":
    abcd = input()
    bin_pattern_digit = len(abcd) - 1

    # パターン数分ループ。2進数3桁(1「+」2「+」3「+」4や1「-」2「-」3「+」4)なので8回
    for i in range(1 << bin_pattern_digit):
        # 初期値:一番左の桁の値。
        result = int(abcd[0:1])
        # パターン数(2進数)の桁数ループ。2進数3桁(001や111)なので3回。
        for j in range(bin_pattern_digit):

            # if文の条件「bin_pattern_digit - j -1」について
            # ビット全探索対象の変数「abcd」は文字列だが、ループ変数「j」は数値。なので、
            # 「i % 1 << j」すると、文字列は先頭(一番左)から、数値は末尾(一番右)から数えてしまう。
            # 全網羅的な処理なら問題ないが、本問題の様に順番が大事な問題は想定通りの結果にならない。
            # 対応は以下の2つ。
            #   対応1.ビット演算子を右シフトに反転「i & 1000(対象桁数分0を追加) >> j」
            #   対応2.ビット演算子はそのままで、引数を反転「i & 1 << (MAX - j - i)」
            #   ->対応1は文字列は先頭(一番左)から、数値は末尾(一番右)から数えてしまう。
            #   全網羅的な処理なら問題ないが、本問題の様に順番が大事な問題は想定通りの結果にならない。

            # +の場合
            # if i & 1 << (bin_pattern_digit - j -　1 ):
            if i & 1 << bin_pattern_digit - 1 >> j:
                # 例：パターン1234の1「+」2の場合：i=0の時に+2(abcd[1:2])する必要がある。
                result += int(abcd[j + 1])
            # -の場合
            else:
                # 例：パターン1234の3「-」4の場合：i=2の時に-4(abcd[3:4])する必要がある。
                result -= int(abcd[j + 1])

        # 合計が7なら終了
        if result == 7:
            break

    # 注意：
    # bit変数(i)の結果を確認する場合、文字列とスライスの併用(str(bit(i[0:1])))は使えない。
    # 数値と同じで、先頭0は消される = 桁数が可変であるため。
    # i & 1 << 0  # 1桁目が真か確認。
    # i & 1 << 1  # 2桁目が真か確認。
    # -dev-
    print(abcd[0:1] + conv_bin(i, 2) + abcd[1:2] + conv_bin(i, 1) + abcd[2:3] + conv_bin(i, 0) + abcd[3:4] + "=7")

Submission status: Accepted

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

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()
for i in range(1<<3):
    su=0
    ans=[]
  #  print(i)
    for j in range(3):
        if (i>>j)&1:
            ans.append('+')
        else: 
            ans.append('-')
    ans=ans[::-1]
    ss=[ int(i) for i in s]
    su+=ss[0]
 #   print(ans)
#    print(ss)
  #  continue
    for k in range(1,4):
        if ans[k-1]=='+':
   #         print(ss[k],end=' + \n')
            su+=ss[k]
        else:
    #        print(ss[k],end=' -\n')
            su-=ss[k]
    #print(su)
    if su==7:
        for i in range(0,3):
            print(s[i],end='')
            print(ans[i],end='')
        print(s[3],end='')
        print('=7')
        import sys
        sys.exit()

Submission status: Accepted

Solution code:
import sys
s=input()
a=int(s[0]);b=int(s[1]);c=int(s[2]);d=int(s[3])
if a+b+c+d==7:
  print(str(a)+"+"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
  sys.exit()
elif a+b+c-d==7:
  print(str(a)+"+"+str(b)+"+"+str(c)+"-"+str(d)+"=7")
  sys.exit()
elif a+b-c+d==7:
  print(str(a)+"+"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
  sys.exit()
elif a+b-c-d==7:
  print(str(a)+"+"+str(b)+"-"+str(c)+"-"+str(d)+"=7")
  sys.exit()
elif a-b+c+d==7:
  print(str(a)+"-"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
  sys.exit()
elif a-b+c-d==7:
  print(str(a)+"-"+str(b)+"+"+str(c)+"-"+str(d)+"=7")
  sys.exit()
elif a-b-c+d==7:
  print(str(a)+"-"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
  sys.exit()
elif a-b-c-d==7:
  print(str(a)+"-"+str(b)+"-"+str(c)+"-"+str(d)+"=7")
  sys.exit()

Submission status: Accepted

Solution code:
a = list(input())
# op = []
# for i in ["+", "-"]:
#     for j in ["+", "-"]:
#         for k in ["+", "-"]:
#             op.append([i,j,k])
# print(op)
op = [
    ["+", "+", "+"],
    ["+", "+", "-"],
    ["+", "-", "+"],
    ["+", "-", "-"],
    ["-", "+", "+"],
    ["-", "+", "-"],
    ["-", "-", "+"],
    ["-", "-", "-"],
]

for i in range(2 ** 3):
    for j in op:
        s = a[0] + j[0] + a[1] + j[1] + a[2] + j[2] + a[3]
        if eval(s) == 7:
            print(s + "=7")
            exit()

Submission status: Accepted

Solution code:

def conv_bin(i, digit):
    if i & 1 << digit:
        return "+"
    else:
        return "-"


if __name__ == "__main__":
    abcd = input()
    bin_pattern_digit = len(abcd) - 1

    for i in range(1 << bin_pattern_digit):
        # 初期値:一番左の桁の値。
        result = int(abcd[0:1])
        for j in range(bin_pattern_digit):
            # +を入れた場合
            # 例：1234のパターン1「+」2の場合：i=0の時に+2(abcd[1:2])する必要がある。
            #                 3「-」4の場合：i=2の時に-4(abcd[3:4])する必要がある。
            if i & 1 << (bin_pattern_digit - j -1 ):
                # result += int(abcd[j + 1:j + 2])
                result += int(abcd[j + 1])
            # -を入れた場合
            else:
                # result -= int(abcd[j + 1:j + 2])
                result -= int(abcd[j + 1])

        # 合計が7なら終了
        if result == 7:
            break

    # 注意：
    # bit変数(i)の結果を確認する場合、文字列とスライスの併用(str(bit(i[0:1])))は使えない。
    # 数値と同じで、先頭0は消される = 桁数が可変であるため。
    # i & 1 << 0  # 1桁目が真か確認。
    # i & 1 << 1  # 2桁目が真か確認。
    # -dev-
    print(abcd[0:1] + conv_bin(i, 2) + abcd[1:2] + conv_bin(i, 1) + abcd[2:3] + conv_bin(i, 0) + abcd[3:4] + "=7")

Submission status: Accepted

Solution code:
S=list(input())
for i in range(4):
  S[i]=int(S[i])
for i in range(8):
  ans=S[0]
  s=format(i,"05b")
  A=[]
  for j in range(3):
    if s[-1-j]=="1":
      A.append(j)
  for i in range(3):
    if i in A:
      ans=ans+S[i+1]
    else:
      ans=ans-S[i+1]
  if ans==7:
    print(S[0],end="")
    for i in range(3):
      if i in A:
        print("+",end="")
      else:
        print("-",end="")
      print(S[i+1],end="")
    print("=7")
    break

Submission status: Accepted

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


def main():
    ABCD = input()

    op = ['+', '-']
    result = ''

    for i in range(2**3):
        bins = list(map(int, format(i, '03b')))
        f = ABCD[0] + op[bins[0]] + ABCD[1] + \
            op[bins[1]] + ABCD[2] + op[bins[2]] + ABCD[3]
        if eval(f) == 7:
            result = f + '=7'
    print(result)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

s = input()

ints = [int(s[i]) for i in range(len(s))]

rope = []
o = []
o.append(str(ints[0]))

for i  in range(2**(len(ints)-1)):
	total = ints[0]
	ope = ['-' for i in range(len(ints)-1)]

	for j in range(len(ints)-1):

		if((i>>j) & 1):
			total = total + ints[j+1]
			ope[j] = '+'
		else :
			total = total - ints[j+1]
			ope[j] = '-'

	# print('t',total)
	if total == 7:
		rope = ope
		break


for i in range(len(rope)):
	o.append(rope[i])
	o.append(str(ints[i+1]))


print(''.join(o)+'=7')

Submission status: Accepted

Solution code:
def resolve():
    I = input()
    L = [int(c) for c in I]
    # bit全探索
    # https://qiita.com/gogotealove/items/11f9e83218926211083a#%E4%BE%8B%E9%A1%8C-1
    for i in range(2 ** 3):
        val=L[0]
        ans=[]
        for j in range(3):  # このループが一番のポイント
            if ((i >> j) & 1):
                val+=L[j+1]
                ans.append('+')
            else:
                val-=L[j+1]
                ans.append('-')
                # 順に右にシフトさせ最下位bitのチェックを行う
        if val==7:
            for k in range(3):
                print('{}{}'.format(L[k],ans[k]),end='')
            print('{}=7'.format(L[3]))
            break





resolve()

Submission status: Accepted

Solution code:
abcd = input()


for bit in range(1<<3):
  f = abcd[0]
  sum = int(f)
  for i in range(3):
    if bit & 1<<i:
      f += '+' + abcd[i+1]
      sum += int(abcd[i+1])
    else:
      f += '-' + abcd[i+1]
      sum -= int(abcd[i+1])
  
  if sum == 7:
    print(f + '=7')
    exit()

Submission status: Accepted

Solution code:
abcd = input()


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


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

Submission status: Accepted

Solution code:
import itertools, re

abcd = input()
abcd = [int(x) for x in abcd]
p = list(itertools.product([1,-1], repeat=3))

f = abcd[0]
fs = str(abcd[0])
for i in range(len(p)):
  for j in range(3):
    f += abcd[j+1]*p[i][j]
    if p[i][j] <0:
      fs += '-' + str(abcd[j+1])
    else:
      fs += '+' + str(abcd[j+1])
  if f == 7:
    print(fs + '=7')
    exit()
  else:
    f = abcd[0]
    fs = str(abcd[0])

Submission status: Accepted

Solution code:
import copy

def add_num(li, op):
    ans = li[0]
    ans_str = ''
    for i in range(len(op)):
        if op[i] == 0:
            ans -= li[i + 1]
            op_str = '-'
        else:
            ans += li[i + 1]
            op_str = '+'
        ans_str += (str(li[i]) + op_str)
    if ans == 7:
        ans_str += str(li[-1])
        print(ans_str + '=7')
        exit()
    return ans


if __name__ == '__main__':
    tmp = list(input())
    tmp = [int(v) for v in tmp]
    op = [0,0,0]
    for i in range(0, 3):
        op_w = copy.copy(op)
        op_w[i] = 1
        add_num(tmp, op_w)
    for i in range(0,3):
        op_w = copy.copy(op)
        op_w[i] = 1
        if i + 1 == len(op):
            j = 0
        else:
            j = i + 1
        op_w[j] = 1
        add_num(tmp, op_w)
    add_num(tmp, op)
    add_num(tmp, [1,1,1])

Submission status: Accepted

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

def main():
    s = input().strip()
    a = int(s[0])
    s = s[1:]
    for i in range(2**3):
        tmp = a
        ans = str(a)
        for j in range(3):
            if i&1:
                tmp += int(s[j])
                ans += "+" + s[j]
            else:
                tmp -= int(s[j])
                ans += "-" + s[j]
            i >>= 1
        
        if tmp == 7:
            print(ans + "=7")
            return
            





if __name__ == "__main__":
    main()

Submission status: Accepted

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

for operators in product(["+","-"],repeat=3):
  formula=""
  for i in range(3):
    formula+=s[i]+operators[i]
  formula+=s[-1]
  if eval(formula)==7:
    print(formula+"=7")
    exit()

Submission status: Accepted

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

if a+b+c+d==7:
  print("%d+%d+%d+%d=7"%(a,b,c,d))
  exit()
if a+b+c-d==7:
  print("%d+%d+%d-%d=7"%(a,b,c,d))
  exit()
if a+b-c+d==7:
  print("%d+%d-%d+%d=7"%(a,b,c,d))
  exit()
if a+b-c-d==7:
  print("%d+%d-%d-%d=7"%(a,b,c,d))
  exit()  
if a-b+c+d==7:
  print("%d-%d+%d+%d=7"%(a,b,c,d))
  exit()
if a-b+c-d==7:
  print("%d-%d+%d-%d=7"%(a,b,c,d))
  exit()
if a-b-c+d==7:
  print("%d-%d-%d+%d=7"%(a,b,c,d))
  exit()
if a-b-c-d==7:
  print("%d-%d-%d-%d=7"%(a,b,c,d))
  exit()

Submission status: Accepted

Solution code:
A_D = str(input())
op = ['']*3
l = []
for i in range(4):
  l.append(A_D[i])
for i in range(2**3):
  i = format(i,"03b")
  for j in range(3):
    if i[j] == '0':
      op[j] = '+'
    elif i[j] == '1':
      op[j] = '-'
  if eval(l[0]+op[0]+l[1]+op[1]+l[2]+op[2]+l[3]) == 7:
    break
print(l[0]+op[0]+l[1]+op[1]+l[2]+op[2]+l[3]+'=7')

Submission status: Accepted

Solution code:
A_D = str(input())
op = ['']*3
l = []
for i in range(4):
  l.append(A_D[i])
for i in range(2**3):
  bit_i = bin(i)[-3:]
  i = bit_i.replace('b','0')
  for j in range(3):
    if i[j] == '0':
      op[j] = '+'
    elif i[j] == '1':
      op[j] = '-'
  if eval(l[0]+op[0]+l[1]+op[1]+l[2]+op[2]+l[3]) == 7:
    break
print(l[0]+op[0]+l[1]+op[1]+l[2]+op[2]+l[3]+'=7')

Submission status: Accepted

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

def solve(m,n):
    if eval(m)==7:
        print(m+"=7")
        exit(0)
    elif n<7:
        solve(m,n+2)
        solve(m[:n]+"-"+m[n+1:],n+2)

solve(a+"+"+b+"+"+c+"+"+d,1)

Submission status: Accepted

Solution code:
from itertools import product
nums = list(input())
for operators in product(['+', '-'], repeat=3):
    formula = ''
    for i in range(3):
        formula += nums[i] + operators[i]
    formula += nums[-1]
    if eval(formula) == 7:
        print(formula+'=7')
        break

Submission status: Accepted

Solution code:
import itertools
import sys
a,b,c,d = map(int,input())
#print(a,b,c,d)
ll = list(itertools.product([0,1], repeat=3))
#[(0, 0, 0), (0, 0, 1), (0, 1, 0), (0, 1, 1), (1, 0, 0), (1, 0, 1), (1, 1, 0), (1, 1, 1)]
for l in ll:
    tmp = a
    tmp_st = str(a)
    for i,num in enumerate(l):
        if num == 0:
            if i == 0:
                tmp -= b
                tmp_st += '-' + str(b)
            elif i == 1:
                tmp -= c
                tmp_st += '-' + str(c)
            else:
                tmp -= d
                tmp_st += '-' + str(d)
        if num == 1:
            if i == 0:
                tmp += b
                tmp_st += '+' + str(b)
            elif i == 1:
                tmp += c
                tmp_st += '+' + str(c)
            else:
                tmp += d
                tmp_st += '+' + str(d)
    if tmp == 7:
        tmp_st += '=7'
        print(tmp_st)
        sys.exit()

Submission status: Accepted

Solution code:
import sys

s=list(input())

def f(p,i,F):
  if i == 4 and p == 7:
    print(F+"=7")
    sys.exit()
  elif i==4:
    return ""
  else:
    f(p+int(s[i]),i+1,F+"+"+s[i])
    f(p-int(s[i]),i+1,F+"-"+s[i])
    
f(int(s[0]),1,s[0])

Submission status: Accepted

Solution code:
import sys
S=input()
a,b,c,d=S[0],S[1],S[2],S[3]
lst=['+','-']
for i in lst:
  for j in lst:
    for k in lst:
      if eval(a+i+b+j+c+k+d+'==7'):
        print(a+i+b+j+c+k+d+'=7')
        sys.exit()

Submission status: Accepted

Solution code:
a = list(input())
n = len(a)
def dfs(i, s, sum_):
  if i == n-1:
    if sum_ == 7:
      print(s+"=7")
      exit()
  else:
    dfs(i+1, s+"+"+a[i+1], sum_+int(a[i+1]))
    dfs(i+1, s+"-"+a[i+1], sum_-int(a[i+1]))

print(dfs(0,a[0],int(a[0])))

Submission status: Accepted

Solution code:
a = list(input())
s = "+-"
for i in range(2):
  for j in range(2):
    for k in range(2):
      if eval(a[0]+s[i]+a[1]+s[j]+a[2]+s[k]+a[3]) == 7:
        print(str(a[0]+s[i]+a[1]+s[j]+a[2]+s[k]+a[3])+"=7")
        quit()

Submission status: Accepted

Solution code:
s = input()
a = s[0]
b = s[1]
c = s[2]
d = s[3]
for i in ['+','-']:
  for j in ['+','-']:
    for k in ['+','-']:
      f = a+i+b+j+c+k+d
      if eval(f) == 7:
        print(f+'=7')
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
V = list(input())
N = len(V) - 1
for bit in range(1 << N):
    op = ['+' if bit & (1 << i) else '-' for i in range(N)]
    s = V[0] + op[0] + V[1] + op[1] + V[2] + op[2] + V[3]
    # print(s)
    if eval(s) == 7:
        print(s + '=7')
        exit()

Submission status: Accepted

Solution code:
def main():
  N = input()
  operators = [["+","+","+"],["+","+","-"],["+","-","+"],["-","+","+"],["+","-","-"],["-","+","-"],["-","-","+"],["-","-","-"]]
  for x,y,z in operators:
        tmp = N[0]+x+N[1]+y+N[2]+z+N[3]
        if eval(tmp) == 7:
              print(tmp+"=7")
              break

if __name__ == "__main__":
      main()

Submission status: Accepted

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


if a+b+c+d == 7:
    print(str(a)+'+'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
elif a+b+c-d == 7:
    print(str(a)+'+'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
elif a-b+c+d == 7:
    print(str(a)+'-'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
elif a+b-c+d == 7:
    print(str(a)+'+'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
elif a-b+c-d == 7:
    print(str(a)+'-'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
elif a+b-c-d == 7:
    print(str(a)+'+'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
elif a-b-c+d == 7:
    print(str(a)+'-'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
elif a-b-c-d == 7:
    print(str(a)+'-'+str(b)+'-'+str(c)+'-'+str(d)+'=7')

Submission status: Accepted

Solution code:
s = input()
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])
op1 = '+'
op2 = '+'
op3 = '+'
for B in [b, -b]:
    for C in [c, -c]:
        for D in [d, -d]:
            if a + B + C + D == 7:
                if B < 0:
                    op1 = '-'
                if C < 0:
                    op2 = '-'
                if D < 0:
                    op3 = '-'
                print(str(a)+op1+str(b)+op2+str(c)+op3+str(d)+'=7')
                exit()

Submission status: Accepted

Solution code:
N = input()
import itertools
for p in itertools.product([0, 1], repeat=3):
  res = int(N[0])
  for i in range(3):
    if p[i]==0:
      res += int(N[i+1])
    else:
      res -= int(N[i+1])
  if res==7:
    bit = p
    break

oper = ['+','-']
ans = N[0]
for i in range(3):
  ans += oper[bit[i]]
  ans += N[i+1]
ans += '=7'
print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s)

def dfs(i, f, sum_):
    if i == n-1:
        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]))
        
print(dfs(0, s[0], int(s[0])))

Submission status: Accepted

Solution code:
# bit全探索で解いてみる
# 0~2**d-1の中に全てのパターンを試せるような情報が含まれる
numbers = list(input())

for i in range(1 << (len(numbers)-1)):
    tmp = numbers[0]
    for j in range(len(numbers)-1):  # j番目のbitが立っているかどうかを見る
        if (i >> j) & 1:
            tmp += "+"
        else:
            tmp += "-"
        tmp += numbers[j+1]
    if eval(tmp) == 7:
        print(tmp+"=7")
        break

Submission status: Accepted

Solution code:
# 再帰関数で実装してみる
numbers = list(input())
# print(numbers)


def rec(s, n):
    if n == 3:
        if eval(s) == 7:
            print(s+"=7")
            exit()
        return
    rec(s+"+"+numbers[n+1], n+1)
    rec(s+"-"+numbers[n+1], n+1)


rec(numbers[0], 0)

Submission status: Accepted

Solution code:
a,b,c,d=list(map(str,input()))
def solve(m,n):
    if eval(m)==7:
        print(m+"=7")
        exit(0)
    elif n<7:
        solve(m,n+2)
        solve(m[:n]+"-"+m[n+1:],n+2)
solve(a+"+"+b+"+"+c+"+"+d,1)

Submission status: Accepted

Solution code:
nums = [int(s) for s in input()]
N = 4

ans = [0]*N
for flag in range(1<<N):
    ans = nums[0]
    for i in range(N-1):
        if flag & 1<<i:
            ans += nums[i+1]
        else:
            ans -= nums[i+1]
    if ans == 7:
        ans_str = str(nums[0])
        for i in range(N-1):
            if flag & 1<<i:
                ans_str += "+"
            else:
                ans_str += "-"
            ans_str += str(nums[i+1])
        ans_str += "=7"
        print(ans_str)
        break

Submission status: Accepted

Solution code:
S=input()
ans=0
for i in range(1<<3):
    lst = ['-']*3
    for j in range(3):
        if 1&(i>>j):
            lst[2-j] = '+'
    total = ''
    for n, m in zip(S, lst+['']):
        total += (n+m)
    if eval(total) == 7:
        print(total + '=7')
        break

Submission status: Accepted

Solution code:
A,B,C,D=list(input())
op="+-"
for i in range(2):
    for j in range(2):
        for k in range(2):
            if eval(A+op[i]+B+op[j]+C+op[k]+D) == 7:
                print(str(A+op[i]+B+op[j]+C+op[k]+D)+"=7")
                exit()

Submission status: Accepted

Solution code:
nums = list(map(int, list(input().rstrip())))
    
def dfs(i, f, sum):
    if i == 3:
        if sum == 7:
            print(f+'=7')
            exit()
    else:
        dfs(i+1, f+'+'+str(nums[i+1]), sum+nums[i+1])
        dfs(i+1, f+'-'+str(nums[i+1]), sum-nums[i+1])
        
dfs(0, str(nums[0]), nums[0])

Submission status: Accepted

Solution code:
s = list(input())
ans = 0
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()