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

plusminus = ['+', '-']

def calc(a, b, op):
    if op == '+':
        return a + b
    elif op == '-':
        return a - b
    else:
        ValueError

def cnt_calc(a, op1, op2, op3):
    return calc(
                int(a[3]),
                calc(
                    int(a[2]),
                    calc(
                        int(a[0]), int(a[1]), op1
                    ),
                    op2
                ),
                op3
            )


for i in plusminus:
    for j in plusminus:
        for k in plusminus:
            if eval(a[0] + i + a[1] + j + a[2] + k + a[3]) == 7:
            # if cnt_calc(a, i, j, k) == 7:
                print(a[0] + i + a[1] + j + a[2] + k + a[3] + '=7')
                exit(0)

Submission status: Accepted

Solution code:
def main():
    a = input()
    n = 3
    op = ['']*n
    for i in range(1 << n):
        total = int(a[0])
        for j in range(n):
            if 1 & (i >> j):
                total += int(a[j+1])
                op[j] = '+'
            else:
                total -= int(a[j+1])
                op[j] = '-'
        if total == 7:
            break
    ans = a[0]
    for i in range(n):
        ans += op[i]+a[i+1]
    ans += '=7'
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools

S = input()

in_list = list(S)
a, b, c, d = list(S)

op_list = list(itertools.product(['+', '-'], repeat=3))

for o in op_list:
    f = []
    for i, v in enumerate(in_list):
        f += v
        if i >= len(in_list) - 1: break
        f += o[int(i)]
    f_str = ''.join(f)
    total = eval(f_str)
    if total == 7:
        f_str += '=7'
        break
print(f_str)

Submission status: Accepted

Solution code:
import sys

S=input()
N=len(S)-1
op = ['']*N
for i in range(1<<N):
    ans = int(S[0])
    for j in range(N):
        if 1&(i>>j):
            ans -= int(S[j+1])
            op[j] = '-'
        else:
            ans += int(S[j+1])
            op[j] = '+'
    if ans == 7:
        break

output = S[0]
for i in range(N):
    output = output + op[i] + S[i+1]
output = output + '=7'

print(output)

Submission status: Accepted

Solution code:
s = input()

n = 3
sum = 0

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

Submission status: Accepted

Solution code:
a, b, c, d = [int(x) for x in list(input())]
# a, b, c, d = 1, 2, 2, 2
# ans = a


# op1, op2, op3 = '', '', ''
# for i in range(2):
#     for j in range(2):
#         for k in range(2):
#             if i:
#                 ans -= b
#             else:
#                 ans += b
#             if j:
#                 ans -= c
#             else:
#                 ans += c
#             if k:
#                 ans -= d
#             else:
#                 ans += d

#             if ans == 7:
#                 # OK
#                 op1 = '-' if i else '+'
#                 op2 = '-' if j else '+'
#                 op3 = '-' if k else '+'

# print(f'{a}{op1}{b}{op2}{c}{op3}{d}')

# 調べた。bit全探索
# op = [[None] * 3 for _ in range(2 ** 3)]
nums = (b, c, d)
for i in range(2 ** 3):
    ans = a
    op = []
    for shift in range(3):
        if i >> shift & 1:
            op.append('+')
            ans += nums[shift]
        else:
            op.append('-')
            ans -= nums[shift]
    if ans == 7:
        print(a, op[0], b, op[1], c, op[2], d, '=7', sep='')
        break

Submission status: Accepted

Solution code:
from itertools import product
s = input()
for bit in product(['-', '+'], repeat=len(s)-1):
    q = ''
    for i in range(len(s)*2-1):
        if i % 2 == 0:
            q += s[i//2]
        else:
            q += bit[(i-1)//2]
    ans = eval(q)
    if ans == 7:
        print(q+'=7')
        exit()

Submission status: Accepted

Solution code:
abcd = input()
int_abcd = list(map(int, abcd))
for i in range(1 << 3):    
    op = ['-'] * 3 + ['=7']
    sum_abcd = int_abcd[0]
    for j in range(3):
        if (i >> j) & 1:
            op[2 - j] = '+'
        sum_abcd += (-1)**(((i >> j) & 1) + 1) * int_abcd[3 - j]
    if sum_abcd == 7:
        break

for num, pm in zip(abcd, op):
    print(num, pm, sep='', end='')

Submission status: Accepted

Solution code:
n = [x for x in input()]
l=len(n)-1
for i in range(2**l):
    op=["-"]*l
    for j in range(l):
        if ((i>>j)&1):
            op[l-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:
import itertools
abcd = list(map(int, input()))

case = ["+", "-"]
set_combination = list(itertools.product(case, repeat=3))

for x in set_combination:
    if x[0] == "+":
        sum_abcd = abcd[0] + abcd[1]
    else:
        sum_abcd = abcd[0] - abcd[1]
    if x[1] == "+":
        sum_abcd = sum_abcd + abcd[2]
    else:
        sum_abcd = sum_abcd - abcd[2]
    if x[2] == "+":
        sum_abcd = sum_abcd + abcd[3]
    else:
        sum_abcd = sum_abcd - abcd[3]

    if sum_abcd == 7:
        print("%d%s%d%s%d%s%d=7" % (abcd[0], x[0],
                                    abcd[1], x[1], abcd[2], x[2], abcd[3]))
        break

Submission status: Accepted

Solution code:
import itertools

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

#print(a)

for i in itertools.product([0,1], repeat=3):
    r=list(i)
    sump=a[0]
    for ii in range(3):
        if r[ii]==0:
            sump=sump-a[ii+1]
        else:
            sump=sump+a[ii+1]
#    print(sump,r) 
    if sump==7:
        stra=str(a[0])
        for ii in range(3):
            if r[ii]==0:
                stra=stra+"-"+str(a[ii+1])
            else :
                stra=stra+"+"+str(a[ii+1])
        stra=stra+"=7"        
        print(stra)
        break

Submission status: Accepted

Solution code:
ABCD = int(input())
a = int(ABCD//10e2)
b = int((ABCD-a*10e2)//10e1)
c = int((ABCD-a*10e2-b*10e1)//10)
d = int(ABCD-a*10e2-b*10e1-c*10)
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:
n = input()
s_num = len(n) -1 
all_p_m = []
for i in range(2**s_num):
  p_m_list = [False for i in range(s_num)]
  for j in range(s_num):
    if ((i >>j) & 1):
      p_m_list[j] = True
  all_p_m.append(p_m_list)
  
for p_m in all_p_m:
  result = int(n[0])
  for i in range(len(p_m)):
    if p_m[i] == True:
      result += int(n[i + 1])
    else:
      result -= int(n[i + 1])
  if result == 7:
    ans_p_m = p_m

ans = ["0" for i in range(7)]
for _ in range(7):
  if _ %2 ==0:
    ans[_] = n[_//2]
  else:
    if ans_p_m[_//2] == True:
    	ans[_] = "+"
    else:
      ans[_] = "-"
ans.append("=7")    
print("".join(ans))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	S = IS()
	S = list(map(int, "".join(S)))
	a = []
	def dfs(i, res, ans):
		if i==len(S)-1:
			if res==7:
				ans += "=7"
				a.append(ans)
		else:
			dfs(i+1, res + S[i+1], ans+"+"+str(S[i+1]))
			dfs(i+1, res - S[i+1], ans+"-"+str(S[i+1]))
	dfs(0,S[0],str(S[0]))
	print(a[0])

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
import operator

a, b, c, d = [int(s) for s in input()]

operators = {"+": operator.add, "-": operator.sub}

for ope_key1, ope1 in operators.items():
    for ope_key2, ope2 in operators.items():
        for ope_key3, ope3 in operators.items():
            if ope3(ope2(ope1(a, b), c), d) == 7:
                print("{0}{1}{2}{3}{4}{5}{6}=7".format(a, ope_key1, b, ope_key2, c, ope_key3, d))
                break
        else:
            continue
        break
    else:
        continue
    break

Submission status: Accepted

Solution code:
nums = input()
op_cnt = len(nums) - 1

for i in range(2 ** op_cnt):
    op = ["-"] * op_cnt
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt - 1 - j] = "+"
    formula = ""
    for p_n, p_o in zip(nums, op + [""]):
        formula += (p_n + p_o)
    if eval(formula) == 7:
        print(formula + "=7")
        break

Submission status: Accepted

Solution code:

a,b,c,d = input()
s = "+-"

for p in s:
    for q in s:
        for r in s:
            f = a+p+b+q+c+r+d
            if eval(f) == 7:
                print(f+"=7")
                exit()

Submission status: Accepted

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

ops = []
for i in range(1 << 3):
    ops = []
    for j in range(3):
        if (i >> j & 1) == 1:
            ops.append("+")
        else:
            ops.append("-")
    ans = nums[0]
    for j in range(3):
        if ops[j] == "+":
            ans += nums[j+1]
        else:
            ans -= nums[j+1]
    if ans == 7:
        print(nums[0], end="")
        for j in range(3):
            print(ops[j] + str(nums[j+1]), end="")
        print("=7")
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,c,d=input()
for f in [a+p+b+q+c+r+d for p in'+-'for q in'+-'for r in'+-']:
 if eval(f)==7:print(f+'=7');break

Submission status: Accepted

Solution code:
a,b,c,d=input()
import itertools as it
for p,q,r in it.product('+-',repeat=3):
  f=a+p+b+q+c+r+d
  if eval(f)==7: print(f+'=7'); break

Submission status: Accepted

Solution code:
S = input()
l = ['+', '-']
flg = False
for i in range(2):
  if flg:
    break
  for j in range(2):
    if flg:
      break
    for k in range(2):
      exp = S[0] + l[i] + S[1] + l[j] + S[2] + l[k] + S[3]
      if eval(exp) == 7:
        print(exp + '=7')
        flg = True
        break

Submission status: Accepted

Solution code:
N=input()
A=int(N[0])
E=7-A
for i in range(8):
 F=["-","-","-"]
 B=int(N[1])
 C=int(N[2])
 D=int(N[3])
 for j in range(3):
  if ((i >> j) & 1):
   F[j]="+"
 if F[0]=="-":
  B*=-1
 if F[1]=="-":
  C*=-1
 if F[2]=="-":
  D*=-1
 if B+C+D==E:
  print(str(A)+str(F[0])+str(abs(B))+str(F[1])+str(abs(C))+str(F[2])+str(abs(D))+"=7")
  break

Submission status: Accepted

Solution code:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
from fractions import gcd
from copy import deepcopy
import math
import queue
import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys
sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main(): #startline-------------------------------------------
    s = input()
    op = ["+","+","+"]
    for i in range(1 << 3):
        for j in range(3):
            if i >> j & 1:
                op[j] = "-"
        tmp = s[0]+op[0]+s[1]+op[1]+s[2]+op[2]+s[3]
        if eval(tmp) == 7:
            print(tmp+"=7")
            exit()
        op = ["+","+","+"]
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Accepted

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

class Op(int):
  def __str__(self):
     return '-' if self < 0 else '+'
    
pm = (Op(1), Op(-1))    

def solve():
  for op1 in pm:
    for op2 in pm:
      for op3 in pm:
        if A + op1 * B + op2 * C + op3 * D == 7:
          print(''.join(str(x) for x in [A, op1, B, op2, C, op3, D]) + '=7')
          return

solve()

Submission status: Accepted

Solution code:
s=list(input())
for i in range(4):
  s[i]=int(s[i])
op=['+','-']
for i in range(2):
  for j in range(2):
    for k in range(2):
      cnt=s[0]
      if i==0:
        cnt+=s[1]
      else:
        cnt-=s[1]
      if j==0:
        cnt+=s[2]
      else:
        cnt-=s[2]
      if k==0:
        cnt+=s[3]
      else:
        cnt-=s[3]
      if cnt==7:
        print(str(s[0])+op[i]+str(s[1])+op[j]+str(s[2])+op[k]+str(s[3])+'=7')
        exit()

Submission status: Accepted

Solution code:
s = input()
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])
while True:
    if a + b + c + d == 7:
        print('%d+%d+%d+%d=7'%(a,b,c,d))
        break
    if a + b + c - d == 7:
        print('%d+%d+%d-%d=7'%(a,b,c,d))
        break
    if a + b - c + d == 7:
        print('%d+%d-%d+%d=7'%(a,b,c,d))
        break
    if a + b - c - d == 7:
        print('%d+%d-%d-%d=7'%(a,b,c,d))
        break
    if a - b - c - d == 7:
        print('%d-%d-%d-%d=7'%(a,b,c,d))
        break
    if a - b + c + d == 7:
        print('%d-%d+%d+%d=7'%(a,b,c,d))
        break
    if a - b + c - d == 7:
        print('%d-%d+%d-%d=7'%(a,b,c,d))
        break
    if a - b - c + d == 7:
        print('%d-%d-%d+%d=7'%(a,b,c,d))
        break

Submission status: Accepted

Solution code:
## coding: UTF-8
from itertools import permutations, combinations,combinations_with_replacement,product
N = input()
#print(N)
#print(N[0])
#print(N[1])
A = int(N[0])
B = int(N[1])
C = int(N[2])
D = int(N[3])


a=list(product(['-','+'],repeat=3)) #組み合わせを全パターン出してくれる ['', '+', '', '', '+']みたいなのを2^nケース出してくれる。

for i in a:
    ans = N[0]+i[0]+N[1]+i[1]+N[2]+i[2]+N[3]
    #print(ans)
    if(eval(ans)==7):
        print(ans+'=7')
        break
'''
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:
## coding: UTF-8
N = input()
#print(N)
#print(N[0])
#print(N[1])
A = int(N[0])
B = int(N[1])
C = int(N[2])
D = int(N[3])


if(A+B+C+D == 7):
    print('{}+{}+{}+{}=7'.format(A,B,C,D))
elif(A+B+C-D == 7):
    print('{}+{}+{}-{}=7'.format(A,B,C,D))
elif(A+B-C+D == 7):
    print('{}+{}-{}+{}=7'.format(A,B,C,D))
elif(A+B-C-D == 7):
    print('{}+{}-{}-{}=7'.format(A,B,C,D))
elif(A-B+C+D == 7):
    print('{}-{}+{}+{}=7'.format(A,B,C,D))
elif(A-B+C-D == 7):
    print('{}-{}+{}-{}=7'.format(A,B,C,D))
elif(A-B-C+D == 7):
    print('{}-{}-{}+{}=7'.format(A,B,C,D))
elif(A-B-C-D == 7):
    print('{}-{}-{}-{}=7'.format(A,B,C,D))

Submission status: Accepted

Solution code:
N = str(input())
S=[int(c) for c in N]

eq_1=0 # siki
for num in range(1<<(len(S)-1)):
    eq_1 = S[0]
    list_1=[]
    for i in range(len(S)-1):
        if num & (1 << i):
            eq_1+=S[i+1]
            list_1.append("+")
        else:
            eq_1-=S[i+1]
            list_1.append("-")
    if eq_1==7:
        print("{}{}{}{}{}{}{}=7".format(S[0],list_1[0],S[1],list_1[1],S[2],list_1[2],S[3]))
        break

Submission status: Accepted

Solution code:
N = str(input())
num=N
S=[int(c) for c in N]

#while int(num) > 0:
#    S.append(int(num) % 10)
#    num = int(int(num) / 10)
#S.reverse()

hako=[]
eq_1=0 # siki
eq_2=0
ans=0


for num in range(1<<(len(S)-1)):
    eq_1 = S[0]
    eq_2 = S[0]
    list_1=[]
    for i in range(len(S)-1):
        if num & (1 << i):
            eq_1+=S[i+1]
            list_1.append("+")
        else:
            eq_1-=S[i+1]
            list_1.append("-")
    if eq_1==7:
        print("{}{}{}{}{}{}{}=7".format(S[0],list_1[0],S[1],list_1[1],S[2],list_1[2],S[3]))
        break

Submission status: Accepted

Solution code:
s = input()

def op(i):
    if i == 0:
        return "+"
    else:
        return "-"

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

Submission status: Accepted

Solution code:
import itertools
status = [(0, 1) for _ in range(3)]
state = list(itertools.product(*status))
num = [int(i) for i in input()]
for ptn in state:
  ans = num[0]
  ans_str = str(num[0])
  for i,ope in enumerate(ptn):
    if ope == 0:
      ans += num[i+1]
      ans_str += ("+" + str(num[i+1]))
    else:
      ans -= num[i+1]
      ans_str += ("-" + str(num[i+1]))
  if ans == 7:
    break
print(ans_str+"=7")

Submission status: Accepted

Solution code:
a = list(input())

for bit in range(2**3):
    ans = a[0]
    
    for i in range(3):
        if ((bit >> i) & 1):
            ans += "+"
        else:
            ans += "-"
        ans += a[i + 1]
    if eval(ans) == 7:
        print(ans+"=7")
        break

Submission status: Accepted

Solution code:
N = input()

def dfs(string, value, i):
    if len(string) ==2*len(N) -1:
        if value == 7:
            print(string + "=7")
            exit()
        return
    else:
        dfs(string + "+" + N[i+1], value + int(N[i+1]), i+1), dfs(string + "-"+ N[i+1], value - int(N[i+1]), i+1)
dfs(N[0], int(N[0]), 0)

Submission status: Accepted

Solution code:
def dfs(num, string, place):
    if len(string) == 0:
        return dfs(num, num[0], place+1)
    
    if len(string) == 7:
        if eval(string) == 7:
            print(string + "=7")
            exit()
        return 
    else:
        return dfs(num, string + "+" + num[place], place + 1), dfs(num, string + "-" + num[place], place + 1)

ABCD = input()
dfs(ABCD, "", 0)

Submission status: Accepted

Solution code:
#!/usr/bin/env python

def main():
    S = input()

    for i in range(1 << 3):
        operator = ["-", "-", "-"] 
        for j in range(3):
            if ((i >> j) & 1):
                operator[j] = "+"
        formula = ""
        for s, op in zip(S, operator + [""]):
            formula += s + op
        if eval(formula) == 7:
            print(formula + "=7")
            break

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools
def solve():
    S = list(input())
    products = itertools.product(('+','-'),repeat=3)

    ans = ""
    for p in products:
        equation = ""
        for i in range(3):
            equation += S[i] + p[i]
        equation += S[3]

        if eval(equation) == 7:
            ans = equation
            break
    
    print(equation + "=7")

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
def solve():
    S = list(input())
    print(dfs(S,0,"")+ "=7")

def dfs(S,idx,res):
    res += S[idx]
    if idx == len(S) - 1:
        return res
    
    res1 = dfs(S,idx+1,res+'+')
    res2 = dfs(S,idx+1,res+'-')

    if eval(res1) == 7:
        return res1
    else:
        return res2
    
if __name__ == '__main__':
    solve()

Submission status: Accepted

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

def A(x):
    if x == 1:
        x = "+"
    else:
        x = "-"
    return x




for i in [1, -1]:
    for j in [1, -1]:
        for k in [1, -1]:
            if a + (i * b) + (j * c) + (k * d) == 7:
                print(str(a) + A(i) + str(b) + A(j) + str(c) + A(k) + str(d) + '=7')
                exit()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def main():
    S = input()
    for i in range(2**3):
        tmp = ""
        for n in range(len(S)-1):
            tmp += S[n]
            if (i >> n) & 1:
                tmp += "+"
            else:
                tmp += "-"
        tmp += S[-1]
        if eval(tmp) == 7:
            tmp += "=7"
            print(tmp)
            return

if __name__ == "__main__":
    main()

Submission status: Accepted

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



l=[str(a),'+',str(b),'+',str(c),'+',str(d)]
for i in range(1):
    #+++
    seven=''.join(l)
    if eval(seven)==7:
        print(seven+'=7')
        break

    l[1]='-'
    #-++
    seven=''.join(l)
    if eval(seven)==7:
        print(seven+'=7')
        break

    l[3]='-'
    #--+
    seven=''.join(l)
    if eval(seven)==7:
        print(seven+'=7')
        break
    
    l[5]='-'
    #---
    seven=''.join(l)
    if eval(seven)==7:
        print(seven+'=7')
        break

    l[1]='+'
    #+--
    seven=''.join(l)
    if eval(seven)==7:
        print(seven+'=7')
        break

    l[3]='+'
    #++-
    seven=''.join(l)
    if eval(seven)==7:
        print(seven+'=7')
        break

    l[3]='-'
    l[5]='+'
    #+-+
    seven=''.join(l)
    if eval(seven)==7:
        print(seven+'=7')
        break

    l[1]='-'
    l[3]='+'
    l[5]='-'
    #-+-
    seven=''.join(l)
    if eval(seven)==7:
        print(seven+'=7')
        break

Submission status: Accepted

Solution code:
#/usr/bin/env python

def main():
    s = input()
    op_cnt = len(s) -1
    for i in range(1<<op_cnt):
        op = ["-"] * op_cnt
        for j in range(op_cnt):
            if ((i >> j) & 1):
                op[op_cnt -1 -j] = "+"

        formula = ""
        for p_n, p_o in zip(s, op+[""]):
            formula += (p_n + p_o)
        if eval(formula) == 7:
            print(formula + "=7")
            break

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    s = input()

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

    for i in range(2):
        tmp = 0
        if i % 2 == 0:
            tmp = a + b 
        else:
            tmp = a - b
        for j in range(2):
            if j % 2 == 0:
                hoge1 = tmp
                tmp += c
            else:
                tmp = hoge1
                tmp -= c
            for k in range(2):
                if k % 2 == 0:
                    hoge = tmp
                    tmp += d
                else:
                    tmp = hoge
                    tmp -= d
                if tmp == 7:
                    op1 = '+' if i % 2 == 0 else '-'
                    op2 = '+' if j % 2 == 0 else '-'
                    op3 = '+' if k % 2 == 0 else '-'
                    print(str(a)+op1+str(b)+op2+str(c)+op3+str(d)+'=7')
                    exit()
            

    # print(i,j,k,tmp)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=input()
L=len(n)-1
for i in range(2**L):
    tmp=["-"]*L
    for j in range(L):
        if((i>>j)&1):
            tmp[j]="+"
    F=""
    for num,sig in zip(n,tmp+[""]):
        F+=(num+sig)
    if eval(F)==7:
        print(F+"=7")
        break

Submission status: Accepted

Solution code:
x=input()
w,x,y,z=list(map(int, x))

if w+x+y+z==7:
	print(w,'+',x,'+',y,'+',z,'=7',sep=(''))
elif w+x+y-z==7:
	print(w,'+',x,'+',y,'-',z,'=7',sep=(''))
elif w+x-y+z==7:
	print(w,'+',x,'-',y,'+',z,'=7',sep=(''))
elif w-x+y+z==7:
	print(w,'-',x,'+',y,'+',z,'=7',sep=(''))
elif w+x-y-z==7:
	print(w,'+',x,'-',y,'-',z,'=7',sep=(''))
elif w-x+y-z==7:
	print(w,'-',x,'+',y,'-',z,'=7',sep=(''))
elif w-x-y+z==7:
	print(w,'-',x,'-',y,'+',z,'=7',sep=(''))
elif w-x-y-z==7:
	print(w,'-',x,'-',y,'-',z,'=7',sep=(''))

Submission status: Accepted

Solution code:
li = list(input())

for i in range(len(li)): li[i] = int(li[i])
p = ('-','+')
tail = '=7'

if li[0] + li[1] + li[2] + li[3] == 7:
    print(str(li[0]) + '+' + str(li[1]) + '+' + str(li[2]) + '+' + str(li[3]) + tail)

elif li[0] + li[1] - li[2] + li[3] == 7:
    print(str(li[0]) + '+' + str(li[1]) + '-' + str(li[2]) + '+' + str(li[3]) + tail)

elif li[0] + li[1] - li[2] - li[3] == 7:
    print(str(li[0]) + '+' + str(li[1]) + '-' + str(li[2]) + '-' + str(li[3]) + tail)

elif li[0] + li[1] + li[2] - li[3] == 7:
    print(str(li[0]) + '+' + str(li[1]) + '+' + str(li[2]) + '-' + str(li[3]) + tail)

elif li[0] - li[1] + li[2] + li[3] == 7:
    print(str(li[0]) + '-' + str(li[1]) + '+' + str(li[2]) + '+' + str(li[3]) + tail)

elif li[0] - li[1] - li[2] + li[3] == 7:
    print(str(li[0]) + '-' + str(li[1]) + '-' + str(li[2]) + '+' + str(li[3]) + tail)

elif li[0] - li[1] - li[2] - li[3] == 7:
    print(str(li[0]) + '-' + str(li[1]) + '-' + str(li[2]) + '-' + str(li[3]) + tail)

elif li[0] - li[1] + li[2] - li[3] == 7:
    print(str(li[0]) + '-' + str(li[1]) + '+' + str(li[2]) + '-' + str(li[3]) + tail)

Submission status: Accepted

Solution code:
import sys
s = [int(x) for x in input()]
n = len(s)-1
for i in range(2**n):
    op = ["-"]*n
    for j in range(n):
        if (i>>j)&1 == 1:
            op[n-1-j] = "+"
    ans = s[0]
    for j in range(n):
        if op[j] == '-':
            ans -= s[j+1]
        else:
            ans += s[j+1]
    if ans == 7:
        ans2 = str(s[0])
        for j in range(n):
            ans2 += op[j]
            ans2 += str(s[j+1])
        print(ans2+"=7")
        sys.exit()

Submission status: Accepted

Solution code:
import sys, itertools

[a, b, c, d] = sys.stdin.readline().rstrip()

ops = ['+', '-']

for exp in ['%s%s%s%s%s%s%s' % (a, op1, b, op2, c, op3, d) for op1, op2, op3 in list(itertools.product(ops, ops, ops))]:
    if eval(exp) == 7:
        print '%s=7' % exp
        break

Submission status: Accepted

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

def calcurate(list,opn):
    ans = 0
    if opn[0]=="+":
        ans = list[0] + list[1]
    else:
        ans = list[0] - list[1]
    if opn[1]=="+":
        ans = ans + list[2]
    else:
        ans = ans - list[2]
    if opn[2]=="+":
        ans = ans + list[3]
    else:
        ans = ans - list[3]
    return ans


for i in range(8):
    opn = ["-","-","-"]
    for j in range(3):
        if ((i>>j)&1):
            opn[j] = "+"
    ans = calcurate(list,opn)
    if ans==7:
        print("".join([a,opn[0],b,opn[1],c,opn[2],d,"=7"]))
        break

Submission status: Accepted

Solution code:
s = str(input())
for b in range(1 << (len(s)-1)):
    ops = []
    for i in range(len(s)-1):
        op = "+" if b & 1 << i else "-"
        ops.append(op)
    siki = ""
    ls = list(s)
    ops.append("")
    for i in range(len(ops)):
        siki += ls[i]+ops[i]
    e = eval(siki)
    if e == 7:
        print("{}{}{}".format(siki, "=", e))
        exit()

Submission status: Accepted

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

A = [S[0]]
B = [S[1], -S[1]]
C = [S[2], -S[2]]
D = [S[3], -S[3]]

E = []
for i in A:
    for j in B:
        for k in C:
            for l in D:
                if i + j + k + l == 7:
                    E = [i, j, k, l]
                    break
s = ""
for i in range(4):
    if i == 0:
        s += str(E[i])
    else:
        if E[i] < 0:
            s += str(E[i])
        else:
            s += "+" + str(E[i])
print(s + "=7")

Submission status: Accepted

Solution code:
import itertools
s=input()

moji = []
for i in s:
    moji.append(int(i))
ans = []
for j in itertools.product([1,-1], repeat=4):
    if moji[0]*j[0]+moji[1]*j[1]+moji[2]*j[2]+moji[3]*j[3] == 7:
        if j[0] == 1:
            ans.append(moji[0])
        else:
            ans.append('-')
            ans.append(moji[0])
        if j[1] == 1:
            ans.append('+')
            ans.append(moji[1])
        else:
            ans.append('-')
            ans.append(moji[1])
        if j[2] == 1:
            ans.append('+')
            ans.append(moji[2])
        else:
            ans.append('-')
            ans.append(moji[2])
        if j[3] == 1:
            ans.append('+')
            ans.append(moji[3])
        else:
            ans.append('-')
            ans.append(moji[3])
        ans.append('=7')
        print(''.join(map(str,ans)))
        exit()

Submission status: Accepted

Solution code:
n = input()
n1 = int(n[0])
n2 = int(n[1])
n3 = int(n[2])
n4 = int(n[3])
flag = False

for op1 in ['+', '-']:
    for op2 in ['+', '-']:
        for op3 in ['+', '-']:
            if op1 == '+':
                n12 = n1 + n2
            else:
                n12 = n1 - n2

            if op2 == '+':
                n23 = n12 + n3
            else:
                n23 = n12 - n3

            if op3 == '+':
                n34 = n23 + n4
            else:
                n34 = n23 - n4

            if n34 == 7:
                flag = True
                break
        if flag:
            break
    if flag:
        break

print(n1, op1, n2, op2, n3, op3, n4, '=7', sep='')

Submission status: Accepted

Solution code:
import itertools
N = input()

for i in list(itertools.product(["+","-"],repeat=3)):
    cnt = 0
    X = N[cnt]
    for j in i:
        X += j
        cnt += 1
        X += N[cnt]
        
    Y = eval(X)
    if Y == 7:
        X += "=7"
        print(X)
        quit()