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:
ABCD = input()
A,B,C,D = [int(ABCD[i]) for i in range(4)]

for op1 in range(2):
    for op2 in range(2):
        for op3 in range(2):
            if A + ((-1)**op1)*B + ((-1)**op2)*C + ((-1)**op3)*D == 7:
                ans = str(A)
                if op1 == 0:
                    ans += "+"
                else:
                    ans += "-"
                ans += str(B)
                if op2 == 0:
                    ans += "+"
                else:
                    ans += "-"
                ans += str(C)
                if op3 == 0:
                    ans += "+"
                else:
                    ans += "-"
                ans += str(D)
                ans += "=7"
                print(ans)
                break
        else:
            continue
        break
    else:
        continue
    break

Submission status: Accepted

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

def show(s, i):
  str_ = str(s[0])
  for j in range(3):
    if ((i >> (2-j)) & 1):
      str_ += '+' + str(s[j+1])
    else:
      str_ += '-' + str(s[j+1])
  str_ += '=7'
  print(str_)

for i in range(2 ** 3):
  t = bin(i)
  sum = s[0]
  for j in range(3):
    if ((i >> (2-j)) & 1):
      sum += s[j+1]
    else:
      sum -= s[j+1]
    
    if sum == 7:
      show(s, i)
      exit()

Submission status: Accepted

Solution code:
ABCD = input()
for i in range(2**3):
    bi = bin(i)[2:].zfill(3)
    tmp = int(ABCD[0])
    ops = []
    for j in range(3):
        if bi[j]=='1':
            tmp += int(ABCD[j+1])
            ops.append('+')
        else:
            tmp -= int(ABCD[j+1])
            ops.append('-')
    if tmp==7:
        print(ABCD[0]+ops[0]+ABCD[1]+ops[1]+ABCD[2]+ops[2]+ABCD[3] + '=7')
        break

Submission status: Accepted

Solution code:
ticket = input()
a = [int(t) for t in ticket]
op = ["" for i in range(3)]
for i in range(8):
    ans = a[0]
    for j in range(3):
        if format(i, "03b")[j] == "1":
            op[j] = "+"
            ans = ans + a[j+1]
        else:
            op[j] = "-"
            ans = ans - a[j+1]
    if ans == 7:
        for k in range(3):
            print(str(a[k])+op[k], end="")
        print(str(a[3])+"=7")
        break

Submission status: Accepted

Solution code:
s = input()
a,b,c,d = int(s[0]), int(s[1]), int(s[2]), int(s[3])
if a+b+c+d == 7:
    print("{0}+{1}+{2}+{3}=7".format(str(a),str(b),str(c),str(d)))
elif a+b+c-d == 7:
    print("{0}+{1}+{2}-{3}=7".format(str(a),str(b),str(c),str(d)))
elif a+b-c+d == 7:
    print("{0}+{1}-{2}+{3}=7".format(str(a),str(b),str(c),str(d)))
elif a-b+c+d == 7:
    print("{0}-{1}+{2}+{3}=7".format(str(a),str(b),str(c),str(d)))
elif a+b-c-d == 7:
    print("{0}+{1}-{2}-{3}=7".format(str(a),str(b),str(c),str(d)))
elif a - b + c - d == 7:
    print("{0}-{1}+{2}-{3}=7".format(str(a), str(b), str(c), str(d)))
elif a-b-c+d == 7:
    print("{0}-{1}-{2}+{3}=7".format(str(a),str(b),str(c),str(d)))
elif a-b-c-d == 7:
    print("{0}-{1}-{2}-{3}=7".format(str(a),str(b),str(c),str(d)))

Submission status: Accepted

Solution code:
abcd = input()
A,B,C,D = int(abcd[0]),int(abcd[1]),int(abcd[2]),int(abcd[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))
else:
  print('{}-{}-{}-{}=7'.format(A, B, C, D))

Submission status: Accepted

Solution code:
import sys

S=sys.stdin.readline()
A=int(S[0])
B=int(S[1])
C=int(S[2])
D=int(S[3])

for i in range(8):
  candidate=A
  opeList=[]
  if i & (1 << 2) != 0:
    candidate = candidate+B
    opeList.append("+")
  else:
    candidate = candidate-B
    opeList.append("-")
  
  if i & (1 << 1) != 0:
    candidate = candidate+C
    opeList.append("+")
  else:
    candidate = candidate-C
    opeList.append("-")
    
  if i & 1 != 0:
    candidate = candidate+D
    opeList.append("+")
  else:
    candidate = candidate-D
    opeList.append("-")
    
  if candidate == 7:
    print(str(A)+opeList[0]+str(B)+opeList[1]+str(C)+opeList[2]+str(D)+"=7")
    break

Submission status: Accepted

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

for i in range(2**k):
    x=['-']*k
    for j in range(k):
        if (i >> j) & 1:
            x[j]='+'
    
    ans=""
    for a,b in zip(n,x+[""]):
        ans+=(a+b)
    if eval(ans)==7:
        print(ans+"=7")
        break

Submission status: Accepted

Solution code:
s = input()
n = len(s)
for i in range(2**n):

  total = 0
  ans = s[0]
  val = int(s[0])
  for j in range(1, n):
    if (i >> j) & 1:
      ans = ans + "+" + s[j]
      val = val + int(s[j])
    else:
      ans = ans + "-" + s[j]
      val = val - int(s[j])
  
  if val == 7:
    print(ans + "=7")
    exit()

Submission status: Accepted

Solution code:
S = input()
A,B,C,D = int(S[0]),int(S[1]),int(S[2]),int(S[3])
#adhoc
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])

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 = list(input())

for i in range(2**3):
    cnt = int(s[0])
    ls = []
    for j in range(3):    
        if ((i>>j)&1):
            ls.append("+")
            cnt += int(s[j+1])
        else:
            ls.append("-")
            cnt -= int(s[j+1])
    if cnt==7:
        eq = [s[0],ls[0],s[1],ls[1],s[2],ls[2],s[3],"=7"]
        print("".join(eq))
        break

Submission status: Accepted

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

for i in range(2**n):
    ans=int(s[0])
    p=str(s[0])

    for j in range(n):
        if((i>>j)&1):
            ans += int(s[j+1])
            p=p+'+'+s[j+1]
        else:
            ans -= int(s[j+1])
            p=p+'-'+s[j+1]
    if ans==7:
        print(p+'=7')
        break

Submission status: Accepted

Solution code:
n = input()
m = len(n)
l = list(n)


for i in range(2 **(m-1)):
    op = ["-"]*(m-1) + [""]
    for j in range(m-1):
        if ((i>>j)&1):
            op[j] = "+"
    formula = ""
    for p_n, p_o in zip(l,op):
        formula += (p_n + p_o)
    if eval(formula) == 7:
        print("{}=7".format(formula))
        exit()

Submission status: Accepted

Solution code:
l = input().split()
ABCD = l[0]

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

#print(A, B, C, D)

def op(code, x, y):
    if code == 0:
        return x + y
    return x - y

def to_op(code):
    if code == 0:
        return '+'
    return '-'

for i in range(8):
    code1 = i % 2
    ans = op(code1, A, B)
    code2 = (i // 2) % 2
    ans = op(code2, ans, C)
    code3 = (i // 4) % 2
    ans = op(code3, ans, D)
    if ans == 7:
        print('{}{}{}{}{}{}{}=7'.format(
            A, to_op(code1),
            B, to_op(code2),
            C, to_op(code3),
            D
        ))
        break

Submission status: Accepted

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

for i in range(2 ** 3):
    tmp = [(i >> t) & 1 for t in range(3)]
    sign = ['+' if t == 1 else '-' for t in tmp]
    string = A + sign[0] + B + sign[1] + C + sign[2] + D
    y = eval(string)
    if y == 7:
        print(string+'=7')
        sys.exit()

Submission status: Accepted

Solution code:
#coding: utf-8

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

for i in range(2):
    for j in range(2):
        for k in range(2):
            A = int(S[0])
            B = int(S[1])
            C = int(S[2])
            D = int(S[3])

            B *= (-1) ** i
            C *= (-1) ** j
            D *= (-1) ** k
            if(A + B + C + D == 7):
                shiki = ''
                shiki += str(A)
                if(B<0):
                    shiki += str(B)
                else:
                    shiki += '+' + str(B)

                if(C<0):
                    shiki += str(C)
                else:
                    shiki += '+' + str(C)

                if(D<0):
                    shiki += str(D)
                else:
                    shiki += '+' + str(D)
                shiki += '=7'
                print(shiki)
                exit()

Submission status: Accepted

Solution code:
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect
import sys
import random
import time
inf = 10**9


def main():
    abcd = input()
    bits = []

    for i in range(2 ** 3):
        eq = []
        for j in range(4):
            eq.append(abcd[j])
            if j > 2:
                break
            if (i >> j) & 1:
                eq.append('+')
            else:
                eq.append('-')
        eveq = ''.join(eq)
        if eval(eveq) == 7:
            print(eveq + '=7')
            return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for op1 in [-1, 1]:
    for op2 in [-1, 1]:
        for op3 in [-1, 1]:
            if A + (op1 * B) + (op2 * C) + (op3 * D) == 7:
                print('{}{}{}{}{}{}{}=7'.format(A, "+" if op1 == 1 else "-", B, "+" if op2 == 1 else "-", C, "+" if op3 == 1 else "-", D))
                exit()

Submission status: Accepted

Solution code:
#input
S = list(input())
for i in range(len(S)):
    S[i] = int(S[i])
#print(S)
L = len(S)
fugou = []

#bit zentansaku
for i in range(2**(L-1)):
    total = S[0]
    #bin_i = bin(i)
    moji = format(i,'b').zfill(4)
    #print(moji)
    for k in range(1,L):
        #print(moji[k])
        if int(moji[k]) == 1:
            total = total + S[k]
        else:
            total = total - S[k]
        #print(total)
    if total == 7:
        moji_answer = moji
#print(moji_answer)
#print
for i in range(1,L):
    if int(moji_answer[i]) == 1:
        fugou_tandoku = "+"
    else:
        fugou_tandoku = "-"
    fugou.append(fugou_tandoku)
print(S[0],fugou[0],S[1],fugou[1],S[2],fugou[2],S[3],'=7',sep='')

Submission status: Accepted

Solution code:
E = input()
N = len(E)

for n in range(2**(N-1)):
    s = 0
    ans = []
    B = bin(n)[2:]
    while len(B) < N - 1:
        B = "0" + B
    ans += "{:s}".format(E[0])
    s += int(E[0])
    for i, e in enumerate(E[1:]):
        if B[i] == "0":
            ans += "{:s}".format("-")
            s -= int(e)
        else:
            ans += "{:s}".format("+")
            s += int(e)
        ans += "{:s}".format(e)
    if s == 7:
        ans += "=7"
        print(*ans, sep="")
        break

Submission status: Accepted

Solution code:
import itertools
def rec (nums,st,step,cot,hugo):
    if step==4:
        if cot == 7:
            print(st+"=7")
            exit()
    else:

        if hugo > 0:
            temp = "+" + str(nums[step])
            cot += nums[step]
        else:
            temp = "-" + str(nums[step])
            cot -= nums[step]
        rec(nums,st+temp,step+1,cot,1)
        rec(nums, st+temp, step + 1, cot, -1)


def do():
    nums = list(map(int,list(input())))
    rec(nums,str(nums[0]),1,nums[0],1)
    rec(nums,str(nums[0]),1,nums[0],-1)


if __name__ == "__main__":
    do()

Submission status: Accepted

Solution code:
from itertools import zip_longest

abcd = input()

n = 3
op_li = [0] * 2**n

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

for i in op_li:
  siki = ""
  for j, k in zip_longest(i, abcd, fillvalue=""):
    siki += k+j
  if eval(siki) == 7:
    print(siki + "=7")
    exit()

Submission status: Accepted

Solution code:
lst = list(map(str, input()))
n = len(lst) - 1
op_lst = ["+", "-"]
for i in range(2**n):
    op = ["-"] * 3
    for j in range(n):
        if ((i >> j) & 1):
            op[n-j-1] = op_lst[0]
    formula = ""
    for num,opp in zip(lst, op + [""]):
        formula += (num + opp)
    if eval(formula) == 7:
        print(formula + "=7")
        break

Submission status: Accepted

Solution code:
P = input()
A = int(P[0])
B = int(P[1])
C = int(P[2])
D = int(P[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))
else:
    print("{}-{}-{}-{}=7".format(A, B, C, D))

Submission status: Accepted

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

finish = False
if not finish:
    for i in range(2):
        if not finish:
            for j in range(2):
                if not finish:
                    for k in range(2):
                        if a + b*(-1)**i + c*(-1)**j + d*(-1)**k == 7:
                            A = [i,j,k]
                            finish = True 

ans = []
for l in A:
    if l == 0:
        ans.append('+')
    else:
        ans.append('-')
print(str(a)+ans[0]+str(b)+ans[1]+str(c)+ans[2]+str(d)+'=7')

Submission status: Accepted

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

for n in range(2 ** 3):
	identity = ""
	identity += A + ["+", "-"][(n >> 0 & 1)]
	identity += B + ["+", "-"][(n >> 1 & 1)]
	identity += C + ["+", "-"][(n >> 2 & 1)]
	identity += D
	if 7 == eval(identity):
		print(identity + "=7")
		break

Submission status: Accepted

Solution code:
n=int(input())
a=n//1000
b=n//100%10
c=n//10%10
d=n%10
op=range(2)
def calc(i,a,b):
    if i==0:
        return a+b
    else:
        return a-b

def opdef(i):
    if i==0:
        return '+'
    else:
        return '-'
flg=False
for i in op:
    if flg:
        break
    for j in op:
        if flg:
            break
        for k in op:
            if flg:
                break
            ans=calc(k,calc(j,calc(i,a,b),c),d)
            if ans==7:
                flg=True
                print(str(a)+opdef(i)+str(b)+opdef(j)+str(c)+opdef(k)+str(d)+'=7')

Submission status: Accepted

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

op = ["+", "-"]
for op1 in op:
    for op2 in op:
        for op3 in op:
            val = a
            if op1 == "+":
                val += b
            else:
                val -= b
 
            if op2 == "+":
                val += c
            else:
                val -= c
 
            if op3 == "+":
                val += d
            else:
                val -= d
            
            if val==7:
                print("{}{}{}{}{}{}{}=7".format(a,op1,b,op2,c,op3,d))
                exit(0)

Submission status: Accepted

Solution code:
 
def func(a,b,c,d,s):
    if a+b+c+d==7:
        s[1],s[3],s[5]="+","+","+"
    elif a+b+c-d==7:
        s[1],s[3],s[5]="+","+","-"
    elif a+b-c+d==7:
        s[1],s[3],s[5]="+","-","+"
    elif a+b-c-d==7:
        s[1],s[3],s[5]="+","-","-"
    elif a-b+c+d==7:
        s[1],s[3],s[5]="-","+","+"
    elif a-b+c-d==7:
        s[1],s[3],s[5]="-","+","-"
    elif a-b-c+d==7:
        s[1],s[3],s[5]="-","-","+"
    elif a-b-c-d==7:
        s[1],s[3],s[5]="-","-","-"
 
x=str(input())
ans=''
 
a=int(x[0])
b=int(x[1])
c=int(x[2])
d=int(x[3])
 
s=[a,"",b,"",c,"",d]
 
func(a,b,c,d,s)
 
for x in s:
    ans+=str(x)
 
print(ans+"=7")

Submission status: Accepted

Solution code:
"""
Bit全探索していく
"""
s = list(input())


for i in range(2**3):
    para = ["+","+","+"]
    ans = []
    for j in range(3):
        if (i >> j) & 1 :
            pass
        else : para[j] = "-"
    for i in range(4):
        ans.append(s[i])
        if i <=2 :
            ans.append(para[i])
    a = "".join(ans)
    if eval(a) == 7 :
        print(a+"=7")
        break
    else : pass

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:
            val = a
            if op1 == "+":
                val += b
            else:
                val -= b

            if op2 == "+":
                val += c
            else:
                val -= c

            if op3 == "+":
                val += d
            else:
                val -= d
            
            if val==7:
                print("{}{}{}{}{}{}{}=7".format(a,op1,b,op2,c,op3,d))
                exit(0)

Submission status: Accepted

Solution code:
from itertools import product

ipt = input()
A, B, C, D = int(ipt[0]), int(ipt[1]), int(ipt[2]), int(ipt[3])
for b, c, d in product([1, -1], repeat=3):
    if A + b*B + c*C + d*D == 7:
        ans = str(A) + ('+' if b > 0 else '-') + str(B) + ('+' if c > 0 else '-') + str(C) + ('+' if d > 0 else '-') + str(D) + '=7'
        print(ans)
        break

Submission status: Accepted

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


def exec(x, y, op):
    if op == '+':
        return x + y
    else:
        return x - y

for op1 in ['+', '-']:
    for op2 in ['+', '-']:
        for op3 in ['+', '-']:
            if exec(exec(exec(A, B, op1), C, op2), D, op3) == 7:
                print('{A}{op1}{B}{op2}{C}{op3}{D}=7'.format(
                    A=A,
                    B=B,
                    C=C,
                    D=D,
                    op1=op1,
                    op2=op2,
                    op3=op3
                ))
                exit()

Submission status: Accepted

Solution code:
a,b,c,d = input()
op_list = ['-', '+']
for i in range(8):
    op = format(i, '03b')
    formula = a+op_list[int(op[0])]+b + op_list[int(op[1])]+c + op_list[int(op[2])] +d
    if eval(formula) == 7:
        print(formula + '=7')
        break

Submission status: Accepted

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

op = ['+', '-']
for i in range(2):
    for j in range(2):
        for k in range(2):
            s = A + op[i] + B + op[j] + C + op[k] + D
            if eval(s) == 7:
                print(s + '=7')
                exit()

Submission status: Accepted

Solution code:
A, B, C, D = (int(i) for i in input())


def print_ans(op1, op2, op3):
    print('{}{}{}{}{}{}{}=7'.format(A, op1, B, op2, C, op3, D))


# +++
if A + B + C + D == 7:
    print_ans('+', '+', '+')
# ++-
elif A + B + C - D == 7:
    print_ans('+', '+', '-')
# +-+
elif A + B - C + D == 7:
    print_ans('+', '-', '+')
# +--
elif A + B - C - D == 7:
    print_ans('+', '-', '-')
# -++
elif A - B + C + D == 7:
    print_ans('-', '+', '+')
# -+-
elif A - B + C - D == 7:
    print_ans('-', '+', '-')
# --+
elif A - B - C + D == 7:
    print_ans('-', '-', '+')
# ---
else:
    print_ans('-', '-', '-')

Submission status: Accepted

Solution code:
s = input()

for bit in range(1 << 3):
    ans = int(s[0])
    f = s[0]

    for i in range(3):
        # フラグが立っていれば "+" 、なければ "-"
        if bit & (1 << i):
            ans += int(s[i + 1])
            f += "+"
        else:
            ans -= int(s[i + 1])
            f += "-"
        f += s[i + 1]

    if ans == 7:
        print(f + "=7")
        exit()

Submission status: Accepted

Solution code:
def dfs(i, f, sum):
    if i == 3:
        if sum == 7:
            # 答えは1つ出力すれば良いので =7 になれば終了
            print(f + "=7")
            exit()

    else:
        # 式 f の末尾に符号と次の数字を追加し、その分 sum に加減する
        dfs(i + 1, f + "+" + s[i + 1], sum + int(s[i + 1]))
        dfs(i + 1, f + "-" + s[i + 1], sum - int(s[i + 1]))

s = input()

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

Submission status: Accepted

Solution code:
s = list(input())

op_cnt = len(s)-1
sum = 0
for i in range(2**op_cnt):
    op = ['+']*op_cnt
    for j in range(op_cnt):
        if (i>>j) & 1:
            op[j] = '-' 

    fomula = s[0]
    for j in range(op_cnt):
        fomula += op[j]
        fomula += s[j+1]
    
    if eval(fomula) == 7:
        print('{}=7'.format(fomula))
        break

Submission status: Accepted

Solution code:
from itertools import product


def find_eq():
    a, b, c, d = input()
    for x, y, z in product(("+", "-"), repeat=3):
        eq = a + x + b + y + c + z + d
        if eval(eq) == 7:
            return eq + "=7"


print(find_eq())

Submission status: Accepted

Solution code:
# ABC079C - Train Ticket
A, B, C, D = list(map(int, list(input())))
for b in (+B, -B):
    for c in (+C, -C):
        for d in (+D, -D):
            if A + b + c + d == 7:
                ans = str(A)
                ans += str(b) if b < 0 else "+" + str(b)
                ans += str(c) if c < 0 else "+" + str(c)
                ans += str(d) if d < 0 else "+" + str(d)
                ans += "=7"
                print(ans)
                break
        else:
            continue
        break
    else:
        continue
    break

Submission status: Accepted

Solution code:
s = input()

def compute(state,s):
	value = int(s[0])
	for i,e in enumerate(state):
		if e == '0':
			value -= int(s[i+1])
		else:
			value += int(s[i+1])
	if value == 7:
		return True
	else:
		return False

def output(state,s):
	string = ''
	for i in range(3):
		string += s[i]
		if state[i] == '0':
			string += '-'
		else:
			string += '+'
	string += s[-1]
	string += '=7'
	return string


for i in range(2**3):
	state = format(i,'03b')
	if compute(state,s):
		print(output(state,s))
		exit()

Submission status: Accepted

Solution code:
abcd = input()
for i in range(8):
    bit = format(i,"03b")
    ans = int(abcd[0])
    for j in range(3):
        if bit[j] == "1":
            ans += int(abcd[j+1])
        else:
            ans -= int(abcd[j+1])
    if ans == 7:
        Ans = bit
        break
temp = abcd[0]

for i in range(3):
    if Ans[i] == "1":
        temp += "+"+abcd[i+1]
    else:
        temp += "-"+abcd[i+1]
temp += "=7"
print(temp)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

for i in range(2 ** (len(s) - 1)):
    fml = ''
    for j in range(len(s) - 1):
        fml += s[j]
        fml += '+-'[int('{:0>10b}'.format(i)[::-1][j]) & 1]
    fml += s[-1]

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

Submission status: Accepted

Solution code:
def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    nums = list(map(lambda x: int(x), inputs[0]))
    OPS = ["+", "-"]
    for temp_op1 in OPS:
        for temp_op2 in OPS:
            for temp_op3 in OPS:
                sum = nums[0]
                if temp_op1 == "+":
                    sum += nums[1]
                else:
                    sum -= nums[1]

                if temp_op2 == "+":
                    sum += nums[2]
                else:
                    sum -= nums[2]

                if temp_op3 == "+":
                    sum += nums[3]
                else:
                    sum -= nums[3]

                if sum == 7:
                    return "%d%s%d%s%d%s%d=7" % (
                        nums[0],
                        temp_op1,
                        nums[1],
                        temp_op2,
                        nums[2],
                        temp_op3,
                        nums[3],
                    )
    return ""


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)

Submission status: Accepted

Solution code:
n = [int(i) for i in input()]
sukimanokazu = len(n) - 1
for i in range(2 ** sukimanokazu):
    op = ["-"] * sukimanokazu #予め作っておくリスト
    for j in range(sukimanokazu):
        if (i >> j) & 1:
            op[sukimanokazu - 1 - j] = "+"  #フラグの場所を＋で上書き

    m = [str(k) for k in n]
    siki = m[0] + op[0] + m[1] + op[1] + m[2] + op[2] + m[3]
    if eval(siki) == 7:
        print(siki+"=7")
        exit()

Submission status: Accepted

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

pattern1 = A + B + C + D
pattern2 = A + B + C - D
pattern3 = A + B - C + D
pattern4 = A + B - C - D
pattern5 = A - B - C + D
pattern6 = A - B - C - D
pattern7 = A - B + C + D
pattern8 = A - B + C - D

if pattern1 == 7:
    print(str(A)+'+'+str(B)+'+'+str(C)+'+'+str(D)+'='+str(pattern1))
    exit()

if pattern2 == 7:
    print(str(A)+'+'+str(B)+'+'+str(C)+'-'+str(D)+'='+str(pattern2))
    exit()

if pattern3 == 7:
    print(str(A)+'+'+str(B)+'-'+str(C)+'+'+str(D)+'='+str(pattern3))
    exit()

if pattern4 == 7:
    print(str(A)+'+'+str(B)+'-'+str(C)+'-'+str(D)+'='+str(pattern4))
    exit()

if pattern5 == 7:
    print(str(A)+'-'+str(B)+'-'+str(C)+'+'+str(D)+'='+str(pattern5))
    exit()

if pattern6 == 7:
    print(str(A)+'-'+str(B)+'-'+str(C)+'-'+str(D)+'='+str(pattern6))
    exit()

if pattern7 == 7:
    print(str(A)+'-'+str(B)+'+'+str(C)+'+'+str(D)+'='+str(pattern7))
    exit()

if pattern8 == 7:
    print(str(A)+'-'+str(B)+'+'+str(C)+'-'+str(D)+'='+str(pattern8))
    exit()

Submission status: Accepted

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

for op1 in "+-":
  for op2 in "+-":
    for op3 in "+-":
      ab = a + b if op1 == "+" else a - b
      abc = ab + c if op2 == "+" else ab - c
      abcd = abc + d if op3 == "+" else abc - d
      if abcd == 7:
        print(str(a) + op1 + str(b) + op2 + str(c) + op3 + str(d) + "=7")
        exit()

Submission status: Accepted

Solution code:
import sys
def calc(a,d):
    K=list(format(d,'04b'))
    ans=0
    t=[]
    for i in range(4):
        if K[i]=='0':
            ans+=a[i]
            t.append('+')
        else:
            ans-=a[i]
            t.append('-')
    return ans,t
s=list(input())
for i in range(4):
    s[i]=int(s[i])
for i in range(1<<3+1):
    r,f=calc(s,i)
    if r==7:
        print(str(s[0])+f[1]+str(s[1])+f[2]+str(s[2])+f[3]+str(s[3])+'=7')
        sys.exit()

Submission status: Accepted

Solution code:

import math

def main():
    a, b, c, d = list(map(int, list(input())))
    if a + b + c + d == 7:
        print('{}+{}+{}+{}=7'.format(a, b, c, d))
    elif a + b + c - d == 7:
        print('{}+{}+{}-{}=7'.format(a, b, c, d))
    elif a + b - c + d == 7:
        print('{}+{}-{}+{}=7'.format(a, b, c, d))
    elif a + b - c - d == 7:
        print('{}+{}-{}-{}=7'.format(a, b, c, d))
    elif a - b + c + d == 7:
        print('{}-{}+{}+{}=7'.format(a, b, c, d))
    elif a - b + c - d == 7:
        print('{}-{}+{}-{}=7'.format(a, b, c, d))
    elif a - b - c + d == 7:
        print('{}-{}-{}+{}=7'.format(a, b, c, d))
    elif a - b - c - d == 7:
        print('{}-{}-{}-{}=7'.format(a, b, c, d))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import types
#import copy

# Input
abcd = input()
n = len(abcd) - 1 # 閾の数

# Print
for i in range( 2**n ):
    op = n * ["-"]

    # Create operation list
    # example: ['+', '-', '+']
    for j in range(n):
        if ( i >> j ) & 1:
            op[n-1 -j] = "+"
            
    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:
S0=input()

for i in range(1<<3):
  S=S0
  for j in range(3):
    if ((i>>j)&1)==1:
      S=S[:3-j]+'+'+S[3-j:]
    else:
      S=S[:3-j]+'-'+S[3-j:]
  if eval(S)==7:
    print(S+'=7')
    exit()

Submission status: Accepted

Solution code:
s=input()
a,b,c,d=list(map(int,s))
for ope1 in [-1,1]:
    for ope2 in [-1,1]:
        for ope3 in [-1,1]:
            if a+ b*ope1 + c*ope2 + d*ope3 == 7:
                print(str(a)+("+" if ope1==1 else "-")+str(b)+("+" if ope2==1 else "-")+str(c)+("+" if ope3==1 else "-")+str(d)+"=7")
                exit()

Submission status: Accepted

Solution code:
n=str(input())
flag=0
for iii in range(8):
  bincalc='{:03b}'.format(iii)
  siki=n[0]
  for jjj in range(3):
    if bincalc[jjj]=="0":
      siki+="+"+n[jjj+1]
    else:
      siki+="-"+n[jjj+1]
  if eval(siki)==7:
    print(siki+"=7")
    break

Submission status: Accepted

Solution code:
import sys

S = input()
c = 0


op = len(S) - 1  # すき間の個数

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

Submission status: Accepted

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

op_choice = ["+", "-"]

for op1 in op_choice:
    for op2 in op_choice:
        for op3 in op_choice:
            check = a + op1 + b + op2 + c + op3 + d
            if eval(check) == 7:
                print(check + "=7")
                exit()