Problem:


Score : 300 points

Problem Statement

Sitting in a station waiting room, Joisino is gazing at her train ticket.

The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive).

In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with + or - so that the formula holds.

The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.

Constraints

0≤A,B,C,D≤9

All input values are integers.

It is guaranteed that there is a solution.

Input

Input is given from Standard Input in the following format:

ABCD

Output

Print the formula you made, including the part =7.

Use the signs + and -.

Do not print a space between a digit and a sign.

Sample Input 1

1222

Sample Output 1

1+2+2+2=7

This is the only valid solution.

Sample Input 2

0290

Sample Output 2

0-2+9+0=7

0 - 2 + 9 - 0 = 7 is also a valid solution.

Sample Input 3

3242

Sample Output 3

3+2+4-2=7



Sample input:
1222


Sample output:
1+2+2+2=7

Submission status: Accepted

Solution code:
S = input()
ans = "-1"
def dfs(n,S,s):
    global ans
    if n == 0:
        s_0 = S[0]
        dfs(n+1,S,s_0)
    else:
        s_1 = s + "+" + S[n]
        s_2 = s + "-" + S[n]
        if n != len(S) - 1:
            dfs(n+1,S,s_1)
            dfs(n+1,S,s_2)
        elif eval(s_1) == 7:
            ans = s_1 + "=7"
        elif eval(s_2) == 7:
            ans = s_2 + "=7"
dfs(0,S,0)
print(ans)

Submission status: Accepted

Solution code:
S = input()
ans = "-1"
def dfs(n,S,s):
    global ans
    if n == 0:
        s_0 = S[0]
        dfs(n+1,S,s_0)
    else:
        s_1 = s + "+" + S[n]
        s_2 = s + "-" + S[n]
        if n != len(S) - 1:
            dfs(n+1,S,s_1)
            dfs(n+1,S,s_2)
        elif eval(s_1) == 7:
            ans = s_1 + "=7"
        elif eval(s_2) == 7:
            ans = s_2 + "=7"
dfs(0,S,0)
print(ans)

Submission status: Accepted

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

for bit in range(1 << n):
    f=x[0]
    for i in range(n):
        if bit & (1 << i):
            f+='+'
        else:
            f+='-'
        f += x[i + 1]
    if eval(f) == 7:
        print(f+"=7")
        break

Submission status: Accepted

Solution code:
N= input()
list=[ int(N[i]) for i in range(4)]

tmp = list[0]+list[1]+list[2]+list[3]
if tmp == 7:
    print("%d+%d+%d+%d=7"%(list[0],list[1],list[2],list[3]))
else:
    tmp = tmp - 2*list[3]
    if tmp == 7:
        print("%d+%d+%d-%d=7"%(list[0],list[1],list[2],list[3]))
    else:
       tmp = tmp - 2*list[2]
       if tmp == 7:
            print("%d+%d-%d-%d=7"%(list[0],list[1],list[2],list[3]))
       else:
           tmp = tmp + 2*list[3]
           if tmp == 7:
                print("%d+%d-%d+%d=7"%(list[0],list[1],list[2],list[3]))
           else:
              tmp = tmp - 2*list[1]
              if tmp == 7:
                  print("%d-%d-%d+%d=7"%(list[0],list[1],list[2],list[3]))
              else:
                 tmp = tmp + 2*list[2]
                 if tmp == 7:
                     print("%d-%d+%d+%d=7"%(list[0],list[1],list[2],list[3]))
                 else:
                    tmp = tmp - 2*list[3]
                    if tmp == 7:
                        print("%d-%d+%d-%d=7"%(list[0],list[1],list[2],list[3]))
                    else:
                            print("%d-%d-%d-%d=7"%(list[0],list[1],list[2],list[3]))

Submission status: Accepted

Solution code:
nums = input()
for i in range(2**3):
  case = bin(i)[2:].zfill(3).replace('0', '+').replace('1','-')
  str_eq = nums[0] + case[0] + nums[1] + case[1] + nums[2] + case[2] + nums[3]
  if eval(str_eq) == 7:
    print(str_eq + '=7')
    exit()

Submission status: Accepted

Solution code:
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics

def main():
    a, b, c, d = (int(x) for x in list(sys.stdin.readline().rstrip()))
    s = 7 - a
    if sum([b, c, d]) == s: res = '+++'
    elif sum([-b, c, d]) == s: res = '-++'
    elif sum([b, -c, d]) == s: res = '+-+'
    elif sum([b, c, -d]) == s: res = '++-'
    elif sum([-b, -c, d]) == s: res = '--+'
    elif sum([-b, c, -d]) == s: res = '-+-' 
    elif sum([b, -c, -d]) == s: res = '+--'
    if res[0] == '-': b = -b
    if res[1] == '-': c = -c
    if res[2] == '-': d = -d
    ans = [str(a)]
    for x in [b, c, d]:
        if x >= 0 : x = '+' + str(x)
        else: x = str(x)
        ans.append(x)
    print(''.join(ans) + '=7')


if __name__ == "__main__":
    # execute only if run as a script
    main()

Submission status: Accepted

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

def answer(count, total, formula):
  if count == 3:
    if total==7:
      print(formula + '=7')
      exit()
    return
  answer(count+1, total + s[count+1], formula+'+'+str(s[count+1]))
  answer(count+1, total - s[count+1], formula+'-'+str(s[count+1]))
  return

answer(0, s[0], str(s[0]))

Submission status: Accepted

Solution code:
ABCD = input()

def bit_cal(n):
    return_list = [''] * (2**n)
    for i in range(2**n):
        for j in range(n):
            if ((i >> j) & 1):
                return_list[i] = return_list[i] + '1'
            else:
                return_list[i] = return_list[i] + '0'
    return return_list

ope_candidates = bit_cal(3)

flag = False
for ope in ope_candidates:
    tmp_ans = int(ABCD[0])
    tmp_str = ABCD[0]
    for i in range(3):
        if ope[i] == '0':
            tmp_ans += int(ABCD[i+1])
            tmp_str = tmp_str + '+' + str(ABCD[i+1])
        else:
            tmp_ans -= int(ABCD[i+1])
            tmp_str = tmp_str + '-' + str(ABCD[i+1])
    if tmp_ans == 7:
        break
print(tmp_str + '=7')

Submission status: Accepted

Solution code:
import sys
S = input()

ans = 0

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

Submission status: Accepted

Solution code:
A=str(input())
if int(A[0])+int(A[1])+int(A[2])+int(A[3])==7:#+++
  print('{}+{}+{}+{}=7'.format(A[0],A[1],A[2],A[3]))
elif int(A[0])+int(A[1])+int(A[2])-int(A[3])==7:#++-
  print('{}+{}+{}-{}=7'.format(A[0],A[1],A[2],A[3]))
elif int(A[0])+int(A[1])-int(A[2])+int(A[3])==7:#+-+
  print('{}+{}-{}+{}=7'.format(A[0],A[1],A[2],A[3]))
elif int(A[0])+int(A[1])-int(A[2])-int(A[3])==7:#+--
  print('{}+{}-{}-{}=7'.format(A[0],A[1],A[2],A[3]))
elif int(A[0])-int(A[1])+int(A[2])+int(A[3])==7:#-++
  print('{}-{}+{}+{}=7'.format(A[0],A[1],A[2],A[3]))
elif int(A[0])-int(A[1])+int(A[2])-int(A[3])==7:#-+-
  print('{}-{}+{}-{}=7'.format(A[0],A[1],A[2],A[3]))
elif int(A[0])-int(A[1])-int(A[2])+int(A[3])==7:#--+
  print('{}-{}-{}+{}=7'.format(A[0],A[1],A[2],A[3]))
elif int(A[0])-int(A[1])-int(A[2])-int(A[3])==7:#---
  print('{}-{}-{}-{}=7'.format(A[0],A[1],A[2],A[3]))

Submission status: Accepted

Solution code:
A,B,C,D=list(input())
op=["+", "-"]
for op1 in op:
  for op2 in op:
    for op3 in op:
      s="{}{}{}{}{}{}{}".format(A,op1,B,op2,C,op3,D)
      if eval(s)==7:
        print("{}=7".format(s))
        exit()

Submission status: Accepted

Solution code:
abcd = input()
for i in range(2**3):
  s = ""
  for j in range(3):
    if (i >> j) & 1 == 1:
      s += abcd[j] + "+"
    else:
      s += abcd[j] + "-"
  s += abcd[3]
  if eval(s) == 7:
    print(s + "=7")
    break

Submission status: Accepted

Solution code:
s=input()
a,b,c,d=s[0],s[1],s[2],s[3]
e=int(a)
o=['+','-']
p=[1,int(-1)]
x,y,z='','',''
ans,f,g,h=0,0,0,0
for i in range(2):
  f=int(b)*((-1)**i)
  x=o[i]
  for j in range(2):
    g=int(c)*((-1)**j)
    y=o[j]
    for k in range(2):
      h=int(d)*((-1)**k)
      z=o[k]
      ans=e+f+g+h
      #print(a+x+b+y+c+z+d+'='+str(ans),e+f+g+h)
      if ans==7:
        print(a+x+b+y+c+z+d+'=7')
        exit()
      ans=0

Submission status: Accepted

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

Submission status: Accepted

Solution code:
abcd = input()


for i in range(2**3):
    t = ""
    for j in range(3):
        if((i>>j)&1):
            t += abcd[j]+"+"
        else:
            t += abcd[j]+"-"

    t += abcd[3]

    if eval(t) == 7:
        print(t+"=7")
        break

Submission status: Accepted

Solution code:
from itertools import product

n = input()
ops = product('+-', repeat=3)

for op in ops:
    fm = n[0] + op[0] + n[1] + op[1] + n[2] + op[2] + n[3]
    if eval(fm) == 7:
        print(fm + '=7')
        break

Submission status: Accepted

Solution code:
s=input()
for bit in range(2**3):
  c=s[0]
  for i in range(3):
    if (bit>>i)&1:c+='+'
    else:c+='-'
    c+=s[i+1]
  if eval(c)==7:
    print(c+'=7')
    exit()

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(2**n):
    S = s[0]
    for j in range(n):
        if ((i >> j) & 1):
            S += '+'
        else:
            S += '-'
        S += s[j+1]
        if len(S) == 7 and eval(S) == 7:
            print(S+'=7')
            exit()

Submission status: Accepted

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

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

Submission status: Accepted

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

sm = 0
for i in range(2):
	for j in range(2):
		for k in range(2):
			a, b, c, d = s
			if(i == 0):
				b *= -1
			if(j == 0):
				c *= -1
			if(k == 0):
				d *= -1
			sm = a + b + c + d
			if(sm == 7):
				if(b >= 0):
					b = "+" + str(b)
				if(c >= 0):
					c = "+" + str(c)
				if(d >= 0):
					d = "+" + str(d)
				break
		else:
			continue
		break
	else:
		continue
	break
print (str(a) + str(b) + str(c) + str(d) + "=7")

Submission status: Accepted

Solution code:
nums = list(str(input()))
l = len(nums) - 1
for i in range(2**l):
    op = [""] * l
    res = ""
    for j in range(l):
        if (i >> j) & 1:
            op[j] = "+"
        else:
            op[j] = "-"
    for n, k in zip(nums, op+[""]):
        res += n + k
    ans = eval(res)
    if ans == 7:
        print(res + "=7")
        break

Submission status: Accepted

Solution code:
s = list(input())

ops=['+', '-']
for o1 in ops:
   for o2 in ops:
       for o3 in ops:
           if eval(s[0] + o1 + s[1] + o2 + s[2] + o3 + s[3]) == 7:
                print(s[0] + o1 + s[1] + o2 + s[2] + o3 + s[3] + '=7')
                exit()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

n = input()
op_cnt = len(n) - 1  # すき間の個数
for i in range(2 ** op_cnt):
    op = ["-"] * op_cnt  # あらかじめ ["-", "-", "-"] というリストを作っておく
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[j] = "+"  # フラグが立っていた箇所を "+" で上書き

    formula = ""
    for p_n, p_o in zip(n, op + [""]):  # 少々モヤッとする
        formula += (p_n + p_o)
    if eval(formula) == 7:
        print(formula + "=7")
        break

Submission status: Accepted

Solution code:
import sys


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

    op = [""] * 3

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

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

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


main()

Submission status: Accepted

Solution code:
import sys


ticket = list(input())

op = [0] * 3

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

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

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

Submission status: Accepted

Solution code:
from operator import add, sub
a, b, c, d = [int(n) for n in input().rstrip("\n")]

for i in range(2**3):
    if [add, sub][(i // 4) % 2]([add, sub][(i // 2) % 2]([add, sub][i % 2](a, b), c), d) == 7:
        print(str(a) + "+-"[i % 2] + str(b) + "+-"[(i // 2) % 2] + str(c) + "+-"[(i // 4) % 2] + str(d) + "=7")
        break

Submission status: Accepted

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

def dfs(i, f):

    if i == n-1:
        if eval(f)==7: 
            print(f+"=7")
            exit()
        else: 
            return False
    else:
        dfs(i+1,f + "+" + s[i+1])
        dfs(i+1,f + "-" + s[i+1])
    
def main():
    if dfs(0,s[0]):
        exit()

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = str(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:
tmp = int(input())
d = tmp % 10
tmp //= 10
c = tmp % 10
tmp //= 10
b = tmp % 10
tmp //= 10
a = tmp


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

Submission status: Accepted

Solution code:
def main():
    S = input()
    x = []
    op = ['+', '-']
    for i in range(2):
        for j in range(2):
            for k in range(2):
                s = op[i] + op[j] + op[k]
                x.append(s)
    # print(x)
    for xi in x:
        st = S[0] + xi[0] + S[1] + xi[1] + S[2] + xi[2] + S[3]
        ans = eval(st)
        # print(ans)
        if ans == 7:
            print(st+'=7')
            break

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
ABCD=list(map(int,list(str(input()))))
for i in range(2**3):
    value=ABCD[0]
    for s,m in enumerate("0"*(3-len(bin(i)[2:]))+(bin(i)[2:])):
        if m=="0":value+=ABCD[s+1]
        else:value-=ABCD[s+1]
    if value==7:
        printdata=""
        for s,m in zip(ABCD,"0"*(3-len(bin(i)[2:]))+(bin(i)[2:])):
            printdata+=str(s)
            printdata+="+" if m=="0" else "-"
        printdata+=str(ABCD[-1])+"=7"
        print(printdata)
        break

Submission status: Accepted

Solution code:
abcd = input()
symbol = ["+", "-"]
list_cand = [(i, j, k) for i in symbol for j in symbol for k in symbol]
for cand in list_cand:
  temp_str = abcd[0] + cand[0] + abcd[1] + cand[1] + abcd[2] + cand[2] + abcd[3]
  if eval(temp_str) == 7:
    print(temp_str + "=7")
    exit()

Submission status: Accepted

Solution code:
import itertools
abcd = input()
symbol = ["+", "-"]
list_cand = [(i, j, k) for i in symbol for j in symbol for k in symbol]
for cand in list_cand:
  temp_str = abcd[0] + cand[0] + abcd[1] + cand[1] + abcd[2] + cand[2] + abcd[3]
  if eval(temp_str) == 7:
    print(temp_str + "=7")
    exit()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    a,b,c,d=map(int,list(input()))
    for i in range(2):
        ans=str(a)
        if i: ans+='-'
        else: ans+='+'
        ans+=str(b)
        for j in range(2):
            if j: 
                ans=ans[:-2]
                ans+='-'
            else: ans+='+'
            ans+=str(c)
            for k in range(2):
                if k: ans+='-'
                else: ans+='+'
                ans+=str(d)
                if eval(ans)==7:
                    print(ans+'=7')
                    exit()
                else: ans=ans[:-2]


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N=str(input())
a=int(N[0])
b=int(N[1])
c=int(N[2])
d=int(N[3])
for i in range(2):
  for j in range(2):
    for k in range(2):
      t=a
      if i==0:
        t+=b
      else:
        t-=b
        
      if j==0:
        t+=c
      else:
        t-=c
        
      if k==0:
        t+=d
      else:
        t-=d
        
      if t==7:
        print("{}{}{}{}{}{}{}=7".format(a,"+-"[i],b,"+-"[j],c,"+-"[k],d))
        exit()

Submission status: Accepted

Solution code:
abcd = list(str(input()))
for k in range(4):
    abcd[k] = int(abcd[k])
#print(abcd)

for i in range(1 << 3):
    info = [abcd[0]]
    for j in range(3):
        if (i >> j) & 1:
            info.append(-1*(abcd[j + 1]))
        else:
            info.append((abcd[j + 1]))
    if sum(info) == 7:
        p = str(abcd[0])
        for m in range(1, 4):
            if info[m] >= 0:
                p += ("+"+str(info[m]))
            else:
                p += (str(info[m]))
        print(p+"=7")
        exit()

Submission status: Accepted

Solution code:
a = list(input())
b = ['+', '-']

for x in range(2):
    if x % 2 == 0:
        q = int(a[1])
    else:
        q = -int(a[1])
    for y in range(2):
        if y % 2 == 0:
            w = int(a[2])
        else:
            w = -int(a[2])
        for z in range(2):
            if z % 2 == 0:
                e = int(a[3])
            else:
                e = -int(a[3])
            if int(a[0]) + q + w + e == 7:
                print(a[0],b[x],a[1],b[y],a[2],b[z],a[3],'=7', sep='')
                exit()

Submission status: Accepted

Solution code:
s = input()
total = int(s[0])

op = ['+', '-']
for i in op:
    for j in op:
        for k in op:
            cmd = s[0] + i + s[1] + j + s[2] + k + s[3]
            if eval(cmd) == 7:
                print(cmd + "=7")
                exit()

Submission status: Accepted

Solution code:
*x, = map(int, list(input()))
digit = 3
for i in range(2**digit):
    res = x[0]
    arr = str(x[0])
    for j in range(digit):
        if (i>>j) & 1:
            res += x[j + 1]
            arr += '+' + str(x[j + 1])
        else:
            res -= x[j + 1]
            arr += '-' + str(x[j + 1])
    if res == 7:
        print(arr + '=7')
        break

Submission status: Accepted

Solution code:
import sys
import math

S = input()
N = 3
ans = 0
for i in range(2 ** N):
    s = S[0]
    for j in range(N):
        if ((i >> j) & 1):
            s += "+"
        else:
            s += "-"
        s += S[j+1]
    if eval(s) == 7:
        print(s+'=7')
        break

Submission status: Accepted

Solution code:
a, b, c, d = map(str, list(input()))
op = ['+', '-']
eval_ary = []
for i in range(2):
    for j in range(2):
        for k in range(2):
            eval_ary.append(a+op[i]+b+op[j]+c+op[k]+d)
for test in eval_ary:
    if eval(test) == 7:
        print(test+'=7')
        break

Submission status: Accepted

Solution code:
def dfs(i, sum, n, s, k):
    # n 個決め終わったら、今までの和 sum が k と等しいかを返す
    if i == n  - 1:
#         print(sum)
        if eval(sum) == k:
            print(sum+"=7")
        return eval(sum) == k
    # + を使う
    if dfs(i + 1, sum + "-" +  s[i+1],n,s,k):
        return True
    
    # - を使う
    if dfs(i + 1, sum + "+" + s[i+1],n,s,k):
        return True
#     print(sum)
    return False

def main():
    s = input()
    n = len(s)
    k = 7

    if dfs(0, s[0], n, s,k):
        pass
    else:
        pass
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
for i1 in ["+","-"]:
  for i2 in ["+","-"]:
    for i3 in ["+","-"]:
      text = s[0] + i1 + s[1] + i2 + s[2] + i3 + s[3]
      if(eval(text) == 7):
        print(text+"=7")
        exit()

Submission status: Accepted

Solution code:
s=input()
for i in range(2**3):
    tmp=int(s[0])
    tmp+=int(s[1]) if i&1==1 else -1*int(s[1])
    tmp+=int(s[2]) if i&2==2 else -1*int(s[2])
    tmp+=int(s[3]) if i&4==4 else -1*int(s[3])
    if tmp==7:
        ans=s[0]
        ans+='+' if i&1==1 else '-'
        ans+=s[1]
        ans+='+' if i&2==2 else '-'
        ans+=s[2]
        ans+='+' if i&4==4 else '-'
        ans+=s[3]+'=7'
        print(ans)
        break

Submission status: Accepted

Solution code:

import sys
s = input()
a = []

for i in range(len(s)):
    num = int(s[i])
    a.append(num)


op = ['+', '-']

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

            if temp == 7:
                n1, n2, n3, n4 = map(str, [a[0], a[1], a[2], a[3]])
                #n1, n2, n3, n4 = a[0], a[1], a[2], a[3]
                print(n1 + op[i] + n2 + op[j] + n3 + op[k] + n4 + '=7')
                sys.exit()

Submission status: Accepted

Solution code:
s = input()
op1 = ['+', '-']
op2 = ['+', '-']
op3 = ['+', '-']

for o1 in op1:
    for o2 in op2:
        for o3 in op3:
            f = s[0] + o1 + s[1] + o2 + s[2] + o3 + s[3]
            if eval(f) == 7:
                print(f+"=7")
                exit()

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

ABCD = [int(_) for _ in ns().strip()]

for i in range(8):
    t = ABCD[0]
    
    for j in range(3):
        if i>>j&1:
            t += ABCD[j+1]
        else:
            t -= ABCD[j+1]
  
    if t == 7:
        print("{}{}{}{}{}{}{}=7".format(
            ABCD[0], "+" if i>>0&1 else "-",
            ABCD[1], "+" if i >> 1 & 1 else "-",
            ABCD[2], "+" if i >> 2 & 1 else "-",
            ABCD[3],         
        ))
        break

Submission status: Accepted

Solution code:
A,B,C,D=input()
op=['+++','++-','+-+','-++','+--','-+-','--+','---']
for op1,op2,op3 in op:
    ex=A+op1+B+op2+C+op3+D
    if eval(ex)==7:
        break
print(ex+'=7')

Submission status: Accepted

Solution code:
def test():
    s = list(input())
    a = len(s) - 1
    for i in range(2**a):
        op = ["-"]*a
        for j in range(a):
            if (i>>j)&1:
                op[j] = "+"
        ans = ""
        for n,k in zip(s,op+[""]):
            ans += n + k
        if eval(ans) == 7:
            print(ans+"=7")
            return


if __name__ == "__main__":
    test()

Submission status: Accepted

Solution code:
def op(bit):
    if bit:
        return '+'
    else:
        return '-'


def main():
    string = input()
    nbs = list(string)

    for i in range(2**3):
        temp_string = nbs[0] + op(i % 2) + nbs[1] + op((i >> 1) % 2) \
                    + nbs[2] + op((i >> 2) % 2) + nbs[3]
        result = eval(temp_string)
        if result == 7:
            print(temp_string + '=7')
            return


if __name__ == '__main__':
    main()

Submission status: Accepted

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


import itertools
li = list(itertools.product({0, 1}, repeat=n))
for i in range(len(li)):
    total = int(s[0])
    shiki = s[0]
    for j in range(n):
        if li[i][j] == 0:
            total += int(s[j+1])
            shiki += "+"+s[j+1]
        else:
            total -= int(s[j+1])
            shiki += "-"+s[j+1]
    if total == 7:
        shiki += "="+str(7)
        print(shiki)
        break
    else:
        pass

Submission status: Accepted

Solution code:
S = input()
for i in range(2 ** len(S) - 1):
    work = S
    for j in range(1 ,len(S)):
        if i >> (j - 1) & 1:
            work = work[:2 * j - 1] + "+" + work[2 * j - 1:]
        else:
            work = work[:2 * j - 1] + "-" + work[2 * j - 1:]
    if eval(work) == 7:
        print("{0}=7".format(work))
        exit()

Submission status: Accepted

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

for i in range(2**(N-1)):
    bi = bin(i)[2:].zfill(N-1)
    op = ["-"] * (N-1)
    for j, b in enumerate(bi):
        if b == "1":
            op[j] = "+"
    su = E[0]
    for o, e in zip(op, E[1:]):
        su += o + e
    if eval(su) == 7:
        ans = su + "=7"
        break

print(ans)





























# 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:
A,B,C,D = map(str,input())
op = ["+","-"]
for i in op:
    for j in op:
        for k in op:
            S = A + i + B + j + C + k + D
            if eval(S) == 7:
                print(S + "=7")
                exit()

Submission status: Accepted

Solution code:
S = input()
ans = 0
for i in range(2 ** 3):
    tmp = int(S[0])
    tmp2 = ''
    for k in range(3):
        if 1 & i>>k:
            tmp += int(S[k+1])
            tmp2 += '+' + S[k+1]
        else:
            tmp -= int(S[k+1])
            tmp2 += '-' + S[k+1]
    tmp2 = S[0] + tmp2 + '=7'
    if tmp == 7:
        print(tmp2)
        exit()

Submission status: Accepted

Solution code:
N = list(input())
N = [int(i) for i in N]
for i in range(2**3):
    cur = bin(i)[2::].zfill(3)
    c = N[0]
    n = []
    for i in range(3):
        if cur[i]=='0':
            n.append('+')
            c += N[i+1]
        else:
            n.append('-')
            c -= N[i+1]
    if c==7:
        m = '='
        print(N[0],n[0],N[1],n[1],N[2],n[2],N[3],m,c,sep=(''))
        break

Submission status: Accepted

Solution code:
abcd = input()

op = ['+', '-']

for op1 in op:
    for op2 in op:
        for op3 in op:
            tmp_ans = abcd[0] + op1 + abcd[1] + op2 + abcd[2] + op3 + abcd[3]
            if eval(tmp_ans) == 7:
                print(tmp_ans+'=7')
                exit()

Submission status: Accepted

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

def solve(ABCD: str):
    A, B, C, D = map(int,ABCD)
    bit_list = list(itertools.product(["+","-"], repeat=3))
    for bit in bit_list:
        a=A
        if bit[0] == "+":
            a+=B
        else:
            a-=B        
        if bit[1] == "+":
            a+=C
        else:
            a-=C        
        if bit[2] == "+":
            a+=D
        else:
            a-=D    
        if a == 7:
            print("{}{}{}{}{}{}{}=7".format(A,bit[0],B,bit[1],C,bit[2],D))
            break 

    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: int
    solve(ABCD)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=input()
n=4
for i in range(2 ** (n-1)):
  x=str(format(i,'b').zfill(3))
  a=[]
  res=int(s[0])
  for j in range(n-1):
    if x[j]=='1':
      res+=int(s[j+1])
      a.append('+')
    else:
      res-=int(s[j+1])
      a.append('-')
  if res==7:
    ans=s[0]+a[0]+s[1]+a[1]+s[2]+a[2]+s[3]+'=7'
    break
print(ans)

Submission status: Accepted

Solution code:


def C_pre():
    t = input()
    a,b,c,d = list(map(int,[t[0],t[1],t[2],t[3]]))
    for j in (1,-1):
        for k in (1,-1):
            for l in (1,-1):
                if a+j*b+k*c+l*d == 7:
                    r = "".join(list(map(str,[j,k,l]))).replace("-1","-").replace("1","+")
                    return a,b,c,d,r
def C():
    a,b,c,d,r = C_pre()
    print(str(a)+r[0]+str(b)+r[1]+str(c)+r[2]+str(d)+"=7")
if __name__ == '__main__':
    C()

Submission status: Accepted

Solution code:
import numpy as np
import itertools

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

for item in list(itertools.product((1,-1),repeat=3)):
  if l[0]+np.dot(item,l[1:])==7:
    break
olist=["+" if o==1 else "-" for o in item]

result = [None]*(len(l)+len(olist))
result[::2] = list(map(str,l))
result[1::2] = olist
print("".join(result)+"=7")

Submission status: Accepted

Solution code:
n = input()
a = int(n[0])
b = int(n[1])
c = int(n[2])
d = int(n[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")
else:
  print(str(a)+"-"+str(b)+"-"+str(c)+"-"+str(d)+"=7")

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:
N = 3
x = []

S = str(input())

def loop(x):
	if x == []: 
		return [[0],[1]]
	
	li = []
	for i in range(len(x)):
		li.append(x[i] + [0])
		li.append(x[i] + [1])
	return li
		
		
		
for i in range(N):
	x = loop(x)

for i in x:
	total = int(S[0])
	for j in range(len(i)):
		if i[j] == 0:
			total += int(S[j+1])
		else:
			total -= int(S[j+1])
	
	
	if total == 7:
		sentence = ''
		for j in range(len(S)-1):
			sentence += S[j] 
			
			if i[j] == 0:
				sentence += '+'
			else:
				sentence += '-'
		
		
		sentence += S[3] + '=7'
		print(sentence)
		break