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
n=int(input())
a=(n-n%1000)//1000
b=(n%1000-n%100)//100
c=(n%100-n%10)//10
d=(n%10)
k=[a,b,c,d]
for i in range(8):
  s='{0:03b}'.format(i)
  ans=a
  for j in range(3):
    if s[j]=='1':
      ans+=k[j+1]
    else:
      ans-=k[j+1]
  if ans==7:
    ans=[str(a)]
    for j in range(3):
      if s[j]=='1':
        ans.append('+')
      else:
        ans.append('-')
      ans.append(str(k[j+1]))
    ans.append('=')
    ans.append('7')
    print(''.join(ans))
    sys.exit()

Submission status: Accepted

Solution code:
import itertools

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

for bb, cc, dd in itertools.product([1, -1], repeat=3):
    if a + bb*b + cc*c + dd*d == 7:
        ans = ''
        ans += str(a)
        if bb == 1:
            ans += '+'
        else:
            ans += '-'
        ans += str(b)
        if cc == 1:
            ans += '+'
        else:
            ans += '-'
        ans += str(c)
        if dd == 1:
            ans += '+'
        else:
            ans += '-'
        ans += str(d)
        ans += '=7'
        print(ans)
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import *

A, B, C, D = map(int, list(input()[:-1]))
l = [B, C, D]

for S in range(8):
    now = A
    ans = [str(A)]
    
    for i in range(3):
        if (S>>i)&1:
            now += l[i]
            ans.append('+')
        else:
            now -= l[i]
            ans.append('-')
        
        ans.append(str(l[i]))
    
    ans.append('=7')
    
    if now==7:
        print(''.join(ans))
        exit()

Submission status: Accepted

Solution code:
import itertools
n = input()
for v in itertools.product(["+","-"], repeat=3):
    x = n[0] + v[0] + n[1] + v[1] + n[2] + v[2] + n[3]
    if eval(x) == 7: break
print(x + "=7")

Submission status: Accepted

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

s = input()
nums = list(map(int, list(s)))
operators = ['+', '+', '+']

def exec(nums, operators):
    num = 0
    num += nums[0]        
    i = 1
    for op in operators:
        if op == '+':
            num += nums[i]
        elif op == '-':
            num -= nums[i]

        i += 1

    return num

def output(nums, operators):
    string = ''
    i = 0
    for n in nums:
        string += str(n)
        if i < len(operators):
            string += operators[i]

        i += 1

    string += '=7'
    print(string)


length = len(operators)

for i in range(2 ** length):
    _operators = operators
    for j in range(length):
        if ((i >> j) & 1):
            _operators[length - 1 - j] = '+'
        else: 
            _operators[length - 1 - j] = '-'

    if exec(nums, _operators) == 7:
        output(nums, _operators)
        break

Submission status: Accepted

Solution code:
N = int(input())
nums = []

for i in range(4):
    tmp = N % 10
    nums.append(tmp)
    N = N // 10

nums = nums[::-1]

for i in range(8):
    ans = nums[0]
    
    judge = []
    
    for j in range(3):
        bitts = (i >> j) & 1
        if (bitts):
            ans += nums[j + 1]
            judge.append('+')
            
        else:
            ans -= nums[j + 1]
            judge.append('-')
    
    if (ans == 7):
        siki = ''
        
        for i in range(3):
            siki += str(nums[i])
            siki += judge[i]
        
        siki += (str(nums[3]) + '=7')
        
        print(siki)
        break

Submission status: Accepted

Solution code:
S = list(input())
for i in range(2 ** 3):
  op = ['+'] * 3
  for j in range(3):
    if ((i >> j) & 1):
      op[j] = '-'
  ans = ''
  for s, p in zip(S, op+['']):
    ans += (s + p)
  if eval(ans) == 7:
    print(ans + '=7')
    break

Submission status: Accepted

Solution code:
def main():

  # S = list(map(int, input().split()))
  S = list(map(int, list(input())))

  for bit in range(1 << len(S)-1):
    ans = S[0]
    list_ = [str(S[0])]
    for i in range(len(S)-1):
      mask = (1 << i)
      if bit & mask:
        ans += S[i+1]
        list_.append('+')
        list_.append(str(S[i+1]))
      else:
        ans -= S[i+1]
        list_.append('-')
        list_.append(str(S[i+1]))
      # print(f'bit:{bit}, mask:{mask}, list_:{list_}')

    if (ans == 7):
      list_.append('=7')
      print("".join(list_))
      return


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

Submission status: Accepted

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

for i in range(2**3):
    op = bin(i)[2:].zfill(3).replace("0", "-").replace("1", "+")
    equation = a + op[0] + b + op[1] + c + op[2] + d
    if eval(equation) == 7:
        print(equation + '=7')
        break

Submission status: Accepted

Solution code:
def a(s,i):
    if i == l-1:
        if eval(s)==7:
            print(s+"=7")
            exit()
        return
    a(s+"+"+N[i+1],i+1)
    a(s+"-"+N[i+1],i+1)

N = input()
l = len(N)

a(N[0],0)

Submission status: Accepted

Solution code:
nums = list(map(int, list(input())))
size = len(nums)-1
for b in range(2**size):
    total = nums[0]
    outputs = [str(nums[0])]
    for i in range(size):
        if ( b & (1 << i) ):
            total = total + nums[1+i]
            outputs.append("+"+str(nums[1+i]))
        else:
            total = total - nums[1+i]
            outputs.append("-"+str(nums[1+i]))
    if(total == 7):
        outputs.append("=7")
        print(''.join(outputs))
        break

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,q in zip(n,op+[""]):
        formula += (p+q)
    if eval(formula) == 7:
        print(formula + "=7")
        break

Submission status: Accepted

Solution code:
nums = input()

N = 3
for i in range(2**N):
    equation = ''
    for j in range(N):
        equation += nums[j]
        if ((i >> j) & 1):
            equation += '+'
        else:
            equation += '-'
    equation += nums[-1]
    if eval(equation) == 7:
        print(equation + '=7')
        exit()

Submission status: Accepted

Solution code:
import operator

vals = input()
nums = list(map(int, tuple(vals)))

def dump(a,b,c):
    if a == operator.add:
        a = '+'
    else:
        a = '-'
    if b == operator.add:
        b = '+'
    else:
        b = '-'
    if c == operator.add:
        c = '+'
    else:
        c = '-'
    print(vals[0] + a + vals[1] + b + vals[2] + c + vals[3] + '=7')

for a in (operator.add, operator.sub):
    for b in (operator.add, operator.sub):
        for c in (operator.add, operator.sub):
            if c(b(a(nums[0], nums[1]), nums[2]), nums[3]) == 7:
                dump(a, b, c)
                exit(0)

Submission status: Accepted

Solution code:
s = list(map(int,list(input())))
op_num = len(s)-1
for i in range(2**op_num):
  ans = ['-']*op_num
  total = s[0]
  for j in range(op_num):
    if (i>>j) & 1:
      total += s[j+1]
      ans[j]='+'
    else:
      total -= s[j+1]
  if total == 7:
    print(str(s[0])+ans[0]+str(s[1])+ans[1]+str(s[2])+ans[2]+str(s[3])+'=7')
    exit()

Submission status: Accepted

Solution code:
def main():
    A, B, C, D = input()
    for i in range(2**3):
        op = ['+', '+', '+']
        for j in range(len(op)):
            if (i >> j) & 1:
                op[j] = '-'
        if eval(A + op[0] + B + op[1] + C + op[2] + D) == 7:
            print(A + op[0] + B + op[1] + C + op[2] + D + '=7')
            break
if __name__  == '__main__':
    main()

Submission status: Accepted

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

A,B,C,D = readline().rstrip()

import itertools
for cal in itertools.product(["+","-"],repeat = 3):
  f = A + cal[0] + B + cal[1] + C + cal[2] + D
  if eval(f) == 7:
    print(f + "=7")
    break

Submission status: Accepted

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

A,B,C,D = readline().rstrip()

for i in range(2 ** 3):
  cal = bin(i)[2:].zfill(3).replace("0","-").replace("1","+")
  f = A + cal[0] + B + cal[1] + C + cal[2] + D
  if eval(f) == 7:
    print(f + "=7")
    break

Submission status: Accepted

Solution code:
def main():
  a, b, c, d = list(input())
  sign = "+-"
  for i in range(2):
    for j in range(2):
      for k in range(2):
        if eval(a+sign[i]+b+sign[j]+c+sign[k]+d)==7:
          print(str(a+sign[i]+b+sign[j]+c+sign[k]+d)+"=7")
          exit()
if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
lst = [int(a) for a in input()]
for bit in range(1 << len(lst)):
    sum = 0
    op_lst = []
    for i in range(len(lst)):
        if bit & (1 << i):
            sum += lst[i]
            op_lst.append('+')
        else:
            sum -= lst[i]
            op_lst.append('-')
    if sum == 7:
        print(lst[0], op_lst[1], lst[1], op_lst[2], lst[2], op_lst[3], lst[3], '=7', sep='')
        break

Submission status: Accepted

Solution code:
def dfs(i, f, sum):
  if i == 3:
    if sum == 7:
      print(f + '=7')
      exit()
      
  else:
    dfs(i+1, f + '-' + n[i+1], sum-int(n[i+1]))
    dfs(i+1, f + '+' + n[i+1], sum+int(n[i+1]))
    
n = input()
dfs(0, n[0], int(n[0]))

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 sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

S = list(s())
A = [int(S[i]) for i in range(4)]
for bit in range(1<<3):
    B = [(bit>>i)&1 for i in range(3)]
    C = []
    ans = A[0]
    for j in range(3):
        if B[j] == 0:
            ans += A[j+1]
            C.append('+')
        else:
            ans -= A[j+1]
            C.append('-')
    if ans == 7:
        print(''.join(str(A[0])+C[0]+str(A[1])+C[1]+str(A[2])+C[2]+str(A[3])+'=7'))
        exit()

Submission status: Accepted

Solution code:
N=list(input())

plus_minus=["+","-"]
for i in range(len(N)-2):
    a=[]
    for j in plus_minus:
        a.append(j+"+")
        a.append(j+"-")
    plus_minus=a

for i in plus_minus:
    sign=list(i)
    sumation=int(N[0])
    for j in range(len(N)-1):
        if(sign[j]=="+"):
            sumation+=int(N[j+1])
        elif(sign[j]=="-"):
            sumation-=int(N[j+1])
        else:
            print("sdfds")
    if(sumation==7):
        answer_sign=i
        break
dis=""
for i in range(len(answer_sign)):
    dis+=N[i]
    dis+=answer_sign[i]
dis+=N[-1]+"=7"
print(dis)

Submission status: Accepted

Solution code:
import sys
a,b,c,d = input()
for i in ["+","-"]:
  for j in ["+","-"]:
    for k in ["+","-"]:
      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:
import sys
a,b,c,d = input()
for i in ["+","-"]:
    for j in ["+","-"]:
        for k in ["+","-"]:
                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:
tmp = input()
x = []
for i in range(4):
    x.append(int(tmp[i]))

for i in range(8):
    s = x[0]
    op = []
    for j in range(3):
        if i >> j & 1:
            s += x[j+1]
            op.append("+")
        else:
            s -= x[j+1]
            op.append("-")
    if s == 7:
        ans = tmp[0] + op[0] + tmp[1] + op[1] + tmp[2] + op[2] + tmp[3] + "=7"
        break
print(ans)

Submission status: Accepted

Solution code:
a, b, c, d = list(input())
for q in range(1, 3):
    ao = ("+" if q % 2 else "-")
    for w in range(1, 3):
        bo = ("+" if w % 2 else "-")
        for e in range(1, 3):
            if eval(a + ao + b + bo + c + ("+" if e % 2 else "-") + d) == 7:
                print(a + ao + b + bo + c + ("+" if e%2else"-") + d + "=7")
                exit(0)

Submission status: Accepted

Solution code:
s = int(input())  
a = s // 1000      #千の位 a
b = s // 100 % 10  #百の位 b
c = s // 10 % 10   #十の位 c
d = s % 10         #一の位 d

def p_mark(j):      #プラスかマイナスかを返す
    if j % 2 == 0:  #余りなしでプラス、ありでマイナス
        return '+'  
    else:  
        return '-'  

for i in range(2 ** 3):  #2の3乗探索
    j = i  #iをjに格納
    p = a  #pに値を格納していく

    x = p_mark(j)  #x = a ? b

    if x == '+': 
        p += b  
    else:  
        p -= b  

    j = j // 2  #jを1bit右へ

    y = p_mark(j)  #y = b ? c

    if y == '+': 
        p += c  
    else:  
        p -= c  

    j = j // 2  #jを1bit右へ

    z = p_mark(j)  #z = c ? d

    if z == '+':
        p += d  
    else:  
        p -= d  

    if p == 7: #pは7か？
        print(str(a) + x + str(b) + y + str(c) + z + str(d) + '=7')  
        break

Submission status: Accepted

Solution code:
n = [int(x) for x in input()]
op_cnt = len(n) - 1
for i in range(2**op_cnt):
  op = ["-"] * op_cnt #for文の中にあるよ！
  for j in range(op_cnt):
    if((i>>j) & 1): #もしフラグが立ってたら、"+"になるようにする。つまり、1="+", 0="-"
      op[op_cnt -1 -j] = "+"  #j桁目が１だったら、j桁目(要素番号は全体-1-j)を"+"に変更
  formula = ""
  for z_n, z_op in zip(n,op + [""]):
    formula += (str(z_n) + z_op)
  if eval(formula) == 7:
    print(formula + "=7")
    break

Submission status: Accepted

Solution code:
ABCD = input()


def dfs(total=0, level=0, ans=0):
    level += 1
    if level >= 4:
        if total == 7:
            return ans
        return -1
    plus_ans = dfs(total + int(ABCD[level]), level, ans + (1 << (level - 1)))
    if plus_ans >= 0:
        return plus_ans
    minus_ans = dfs(total - int(ABCD[level]), level, ans)
    if minus_ans:
        return minus_ans
    return -1


ans = dfs(int(ABCD[0]), 0, 0)
op1 = "+" if ans & 1 != 0 else "-"
op2 = "+" if ans & (1 << 1) != 0 else "-"
op3 = "+" if ans & (1 << 2) != 0 else "-"
print(ABCD[0] + op1 + ABCD[1] + op2 + ABCD[2] + op3 + ABCD[3] + "=7")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import product
a=list(input())

for b in product(["+","-"],repeat=3):
  if(eval(a[0]+b[0]+a[1]+b[1]+a[2]+b[2]+a[3])==7):
    print(str(a[0]+b[0]+a[1]+b[1]+a[2]+b[2]+a[3]+"=7"))
    break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
s = input()
l = len(s)-1

for i in range(1 << l):
    op = [s[0], '', s[1], '', s[2], '', s[3]]
    for j in range(l):
        if ((i >> j) & 1) == 1:
            op[2*j+1] = '+'
        else:
            op[2*j+1] = '-'
    if eval(''.join(op)) == 7:
        print(''.join(op) + '=7')
        break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# ABCD
S = list(map(int, list(input())))

for bit in range(2**3):
    formula_sum = S[0]
    formula = str(S[0])
    for shift in range(3):
        # 1だったら+
        if (bit >> shift)&1:
            formula_sum += S[shift+1]
            formula += '+{}'.format(S[shift+1])
        else:
            formula_sum -= S[shift+1]
            formula += '-{}'.format(S[shift+1])
    
    if formula_sum == 7:
        print(formula+'=7')
        exit(0)

Submission status: Accepted

Solution code:
A, *BCD = map(int, input())
for bit in range(1 << 3):
    f = [A]
    s = A
    for i, n in enumerate(BCD):
        if bit >> i & 1:
            f += ['+', n]
            s += n
        else:
            f += ['-', n]
            s -= n
    if s == 7:
        f += ['=7']
        print(''.join(map(str, f)))
        break

Submission status: Accepted

Solution code:
n = [int(c) for c in input()]
for i in range(2 ** 3):
    os = format(i, "03b").replace("1", "+").replace("0", "-")
    temp = n[0]
    for i, c in enumerate(os):
        num = n[i + 1]
        temp += num if c == "+" else -num
    if temp == 7:
        ans = "{}{}{}{}{}{}{}=7".format(n[0], os[0], n[1], os[1], n[2], os[2], n[3])
        break
print(ans)

Submission status: Accepted

Solution code:
n = [int(c) for c in input()]
template_list = [
    "{}+{}+{}+{}",
    "{}+{}+{}-{}",
    "{}+{}-{}+{}",
    "{}+{}-{}-{}",
    "{}-{}+{}+{}",
    "{}-{}+{}-{}",
    "{}-{}-{}+{}",
    "{}-{}-{}-{}",
]
for template in template_list:
    temp = template.format(*n)
    if eval(temp) == 7:
        ans = "{}=7".format(temp)
        break
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
s = input()
l = [int(i) for i in s]
for i in range(2**3):
    ans = l[0]
    siki = s[0]
    for j in range(3):
        if i>>j & 1:
            ans += l[j+1]
            siki += "+"+s[j+1]
        else:
            ans -= l[j+1]
            siki += "-"+s[j+1]
    if ans == 7:
        print(siki+"=7")
        exit()

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:
a,b,c,d=[int(s) for s in list(str(input()))]
x=(a+b+c+d-7)/2
op=["+","+","+"]
for i in range(3):
    if [b,c,d][i]==x:
        op[i]="-"
        break
    elif [b,c,d][i]==b+c+d-x:
        op=["-","-","+","-","-"][2-i:5-i]
        break
print(str(a)+op[0]+str(b)+op[1]+str(c)+op[2]+str(d)+"=7")

Submission status: Accepted

Solution code:
a,b,c,d=[int(s) for s in list(str(input()))]
x=(a+b+c+d-7)/2
op=["+","+","+"]
for i in range(3):
    if [b,c,d][i]==x:
        op[i]="-"
        break
    elif [b,c,d][i]==b+c+d-x:
        op=["-","-","-"] 
        op[i]="+"
        break
print(str(a)+op[0]+str(b)+op[1]+str(c)+op[2]+str(d)+"=7")

Submission status: Accepted

Solution code:
a, b, c, d = map(int, input())
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:
n = [int(x) for x in input()]


for i in range(8):
    ans = n[0]
    strs = [str(n[0])]
    for j in range(3):
        if (i >> j) & 1:
            ans += n[j + 1]
            strs += '+' + str(n[j + 1])
        else:
            ans -= n[j + 1]
            strs += '-' + str(n[j + 1])
    if ans == 7:
        break
print(''.join(strs) + '=7')

Submission status: Accepted

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

import os
import sys


# ac_py.main
# Date: 2020/06/15
# Filename: main 
# Author: acto_mini

def main():
    S = input()
    num0 = int(S[0])
    num1 = int(S[1])
    num2 = int(S[2])
    num3 = int(S[3])

    for i in range(2):
        for j in range(2):
            for k in range(2):
                ans = 0
                op1 = i == 1
                op2 = j == 1
                op3 = k == 1

                if op1:
                    ans = num0 - num1
                else:
                    ans = num0 + num1

                if op2:
                    ans -= num2
                else:
                    ans += num2

                if op3:
                    ans -= num3
                else:
                    ans += num3

                if ans == 7:
                    print(str(num0) + conv(op1) + str(num1) + conv(op2) + str(num2) + conv(op3) + str(num3) + "=7")
                    exit()

    return


def conv(s):
    if s:
        return "-"
    else:
        return "+"


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
A, *BCD = map(int, input())
for bit in range(1 << 3):
    tmp = A
    formula = [A]
    for op, n in enumerate(BCD):
        if bit >> op & 1:
            tmp += n
            formula.append('+')
        else:
            tmp -= n
            formula.append('-')
        formula.append(n)
    if tmp == 7:
        formula.append('=7')
        print(*map(str, formula), sep='')
        break

Submission status: Accepted

Solution code:
l=list(input())
n=2**3
for i in range(n):
    sum=int(l[0])
    buf=l[0]
    for j in range(3):
        if i>>j & 1:
            buf+='+'+l[j+1]
            sum+=int(l[j+1])
        else:
            buf+='-'+l[j+1]
            sum-=int(l[j+1])
    if sum==7:
        print(buf+'=7')
        exit()

Submission status: Accepted

Solution code:
a, b, c, d = list(input())
for i in range(2 ** 3):
    ls = ['+'] * 3
    for j in range(len(ls)):
        if (i >> j) & 1:
            ls[j] = '-'
    if eval(a + ls[0] + b + ls[1] + c + ls[2] + d) == 7:
        print(a+ls[0]+b+ls[1]+c+ls[2]+d + '=7')
        break

Submission status: Accepted

Solution code:
S_str = input()
S = [int(i) for i in S_str]
N = len(S)

ans = 0
for bit in range(1 << (N-1)):
  f = S[0]
  g = S_str[0]
  for i in range(N-1):
    if bit & (1 << i):
      f += S[i+1]
      g += "+"+S_str[i+1]
    else:
      f -= S[i+1]
      g += "-"+S_str[i+1]
  if f == 7:
    print(g+"=7")
    exit()

Submission status: Accepted

Solution code:
import math

abcd = int(input())

a = abcd // 1000
b = (abcd - a * 1000) // 100
c = (abcd - a * 1000 - b * 100) // 10
d = abcd % 10

for i in range(2**3):
    siki = []
    for j in range(3):
        if(i >> j & 1):
            siki.append("+")
        else:
            siki.append("-")
    siki2 = str(a) + siki[0] + str(b) + siki[1] + str(c) + siki[2] + str(d)
    if(eval(siki2) == 7):
        print(siki2+"=7")
        break

Submission status: Accepted

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


for ops in itertools.product(['+','-'],repeat=3):
  eq = a+ops[0]+b+ops[1]+c+ops[2]+d
  x = eval(eq)
  
  if x==7:
    break

answer = eq+'=7'
print(answer)

Submission status: Accepted

Solution code:
a,b,c,d = (int(i) for i in input())
 
if a+b+c+d == 7:
  print('{}+{}+{}+{}=7'.format(a,b,c,d))
elif a+b+c-d == 7:
  print('{}+{}+{}-{}=7'.format(a,b,c,d))
elif a+b-c+d == 7:
  print('{}+{}-{}+{}=7'.format(a,b,c,d))
elif a+b-c-d == 7:
  print('{}+{}-{}-{}=7'.format(a,b,c,d))
  
elif a-b+c+d == 7:
  print('{}-{}+{}+{}=7'.format(a,b,c,d))
elif a-b+c-d == 7:
  print('{}-{}+{}-{}=7'.format(a,b,c,d))
elif a-b-c+d == 7:
  print('{}-{}-{}+{}=7'.format(a,b,c,d))
elif a-b-c-d == 7:
  print('{}-{}-{}-{}=7'.format(a,b,c,d))

Submission status: Accepted

Solution code:
import itertools
import sys

s=input()
a,b,c,d=s

op=("+","-")
for op1,op2,op3 in itertools.product(op,repeat=3):
    if eval(a + op1 + b + op2 + c + op3 + d)==7:
        print(a + op1 + b + op2 + c + op3 + d+"=7")
        sys.exit()

Submission status: Accepted

Solution code:
def solve(operands):
    for i in range(pow(2, len(operands) - 1)):
        tmp_equation = operands[0]
        for j in range(len(operands) - 1):
            tmp_equation += '+' if i >> j & 1 else '-'
            tmp_equation += operands[j + 1]
        if eval(tmp_equation) == 7:
            print(tmp_equation + '=7')
            return

if __name__ == "__main__":
    operands = list(input())
    solve(operands)

Submission status: Accepted

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

for i in range(2 ** (l - 1)):
    line = s[0]
    for j in range(l - 1):
        if (i>>j)&1:
            line += '+'
        else:
            line += '-'
        line += s[j + 1]
    if eval(line) == 7:
        print('{}=7'.format(line))
        exit()

Submission status: Accepted

Solution code:
A, B, C, D = map(int, input())
if A+B+C+D==7:
    a = "+"
    b = "+"
    c = "+"
elif A+B+C-D==7:
    a = "+"
    b = "+"
    c = "-"
elif A+B-C+D==7:
    a = "+"
    b = "-"
    c = "+"
elif A+B-C-D==7:
    a = "+"
    b = "-"
    c = "-"
elif A-B+C+D==7:
    a = "-"
    b = "+"
    c = "+"
elif A-B+C-D==7:
    a = "-"
    b = "+"
    c = "-"
elif A-B-C+D==7:
    a = "-"
    b = "-"
    c = "+"
elif A-B-C-D==7:
    a = "-"
    b = "-"
    c = "-"

print(str(A)+a+str(B)+b+str(C)+c+str(D)+"=7")

Submission status: Accepted

Solution code:
from itertools import permutations, combinations,combinations_with_replacement,product
s = input()
t = product(["+","-"],repeat=3)

for i in t:
    calc = s[0]+i[0]+s[1]+i[1]+s[2]+i[2]+s[3]
    sum = eval(calc)
    if(sum==7):
        print(calc+"=7")
        break

Submission status: Accepted

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

# In[8]:


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


# In[9]:


if abcd[0] + abcd[1] + abcd[2] + abcd[3] == 7:
    print(str(abcd[0])+"+"+str(abcd[1])+"+"+str(abcd[2])+"+"+str(abcd[3])+"=7")
elif abcd[0] + abcd[1] + abcd[2] - abcd[3] == 7:
    print(str(abcd[0])+"+"+str(abcd[1])+"+"+str(abcd[2])+"-"+str(abcd[3])+"=7")
elif abcd[0] + abcd[1] - abcd[2] + abcd[3] == 7:
    print(str(abcd[0])+"+"+str(abcd[1])+"-"+str(abcd[2])+"+"+str(abcd[3])+"=7")
elif abcd[0] + abcd[1] - abcd[2] - abcd[3] == 7:
    print(str(abcd[0])+"+"+str(abcd[1])+"-"+str(abcd[2])+"-"+str(abcd[3])+"=7")
elif abcd[0] - abcd[1] + abcd[2] + abcd[3] == 7:
    print(str(abcd[0])+"-"+str(abcd[1])+"+"+str(abcd[2])+"+"+str(abcd[3])+"=7")
elif abcd[0] - abcd[1] + abcd[2] - abcd[3] == 7:
    print(str(abcd[0])+"-"+str(abcd[1])+"+"+str(abcd[2])+"-"+str(abcd[3])+"=7")
elif abcd[0] - abcd[1] - abcd[2] + abcd[3] == 7:
    print(str(abcd[0])+"-"+str(abcd[1])+"-"+str(abcd[2])+"+"+str(abcd[3])+"=7")
elif abcd[0] - abcd[1] - abcd[2] - abcd[3] == 7:
    print(str(abcd[0])+"-"+str(abcd[1])+"-"+str(abcd[2])+"-"+str(abcd[3])+"=7")


# In[ ]:

Submission status: Accepted

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

def iter_p_adic(p, n):
    from itertools import product
    tmp = [range(p)] * n
    return product(*tmp)

operator = ['+', '-']

iterator = iter_p_adic(2, 3)
for idxs in iterator:
    fomula = A + operator[idxs[0]] + B + operator[idxs[1]] + C + operator[idxs[2]] + D
    if eval(fomula) == 7:
        print(fomula + '=7')
        sys.exit()

Submission status: Accepted

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

for i in range(2**3):
  bag=["+"]*3
  #print("pattern {}: ".format(i), end="")
  for j in range(3):
    if ((i>>j) & 1):
      bag[j]="-"
  #print(bag)
  s=abcd[0]
  for ii in range(len(bag)):
    if bag[ii] == "+":
      s+=abcd[ii+1]
    else:
      s-=abcd[ii+1]
    #print(s)
    
  if s == 7:
    print("{}{}{}{}{}{}{}={}".format(abcd[0],bag[0],abcd[1],bag[1],abcd[2],bag[2],abcd[3],s))
    exit()

Submission status: Accepted

Solution code:
abcd = list(map(int, list(input())))
res = abcd[0]
op = -1
for i in range(8):
    res = abcd[0]
    op_temp = i
    if op_temp%2:
        res += abcd[1]
    else:
        res -= abcd[1]
    op_temp = op_temp >> 1
    if op_temp%2:
        res += abcd[2]
    else:
        res -= abcd[2]
    op_temp = op_temp >> 1
    if op_temp%2:
        res += abcd[3]
    else:
        res -= abcd[3]
    if res == 7:
        op = i
        break

ans = str(abcd[0])
for j in range(3):
    if (op >> (j))%2:
        ans += '+'
    else:
        ans += '-'
    ans += str(abcd[j+1])
ans += '=7'

print(ans)

Submission status: Accepted

Solution code:
s = input()
for i in range(8):
    total = int(s[0])
    str = s[0]
    for j in range(1, 4):
        if i >> (j - 1) & 1:
            total += int(s[j])
            str += '+' + s[j]
        else:
            total -= int(s[j])
            str += '-' + s[j]
    if total == 7:
        print(str + '=7')
        exit()

Submission status: Accepted

Solution code:
s = input()
ans = 'inf'
for i in range(8):
    total = int(s[0])
    str = s[0]
    for j in range(3):
        if i>>j&1:
            total += int(s[j+1])
            str += '+' + s[j+1]
        else:
            total -= int(s[j+1])
            str += '-' + s[j+1]
    if total == 7:
        print(str + '=7')
        exit()

Submission status: Accepted

Solution code:
import math
import sys
from collections import deque
a=input()
for i in range(8):
  c=int(a[0])
  l=[a[0]]
  for j in range(3):
    if i>>j & 1:
      c+=int(a[j+1])
      l+=["+",a[j+1]]
    else:
      c-=int(a[j+1])
      l+=["-",a[j+1]]
  if c==7:
    for i in l:
      print(i,end="")
    print("=7")
    sys.exit()

Submission status: Accepted

Solution code:
import math
import sys
from collections import deque
a=input()
for i in range(8):
  c=int(a[0])
  l=[a[0]]
  for j in range(3):
    if i>>j & 1:
      c+=int(a[j+1])
      l+=["+",a[j+1]]
    else:
      c-=int(a[j+1])
      l+=["-",a[j+1]]
  if c==7:
    for i in l:
      print(i,end="")
    print("=7")
    sys.exit()