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: Wrong Answer

Solution code:
# C
ABCD = input()
A = ABCD[0]
B = ABCD[1]
C = ABCD[2]
D = ABCD[3]


for i in range(8):
    res = A
    if i in [0, 2, 4, 6]:
        res = res + '+' + B
    else:
        res = res + '-' + B
    if i in [0, 1, 4, 5]:
        res = res + '+' + C
    else:
        res = res + '-' + C
    if i in [0, 1, 2, 3]:
        res = res + '+' + D
    else:
        res = res + '-' + D
        
    if eval(res) == 7:
        print(res)
        break

Submission status: Wrong Answer

Solution code:
s = input()
op = ['-', '+']
for i in range(2):
    for j in range(2):
        for k in range(2):
            com = s[0] + op[i] + s[1] + op[j] + s[2] + op[k] + s[3]
            if eval(com) == 7:
                print(com + '=7')

Submission status: Wrong Answer

Solution code:
import sys

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

for i in range(2):
    s = A
    if i == 0:
        s += B
    else:
        s -= B

    for j in range(2):
        if j == 0:
            s += C
        else:
            s -= C

        for k in range(2):
            if k == 0:
                s += D
            else:
                s -= D

            if s == 7:
                ans = str(A)
                if i == 0:
                    ans += '+'
                else:
                    ans += '-'
                ans += str(B)
                if j == 0:
                    ans += '+'
                else:
                    ans += '-'
                ans += str(C)
                if k == 0:
                    ans += '+'
                else:
                    ans += '-'
                ans += str(D)
                ans += '=7'
                print(ans)
                sys.exit()

Submission status: Time Limit Exceeded

Solution code:
i=input()
while True:
  if int(i[0])+int(i[1])+int(i[2])+int(i[3])==7:
    print(i[0]+"+"+i[1]+"+"+i[2]+"+"+i[3]+"="+"7")
    exit
  elif int(i[0])+int(i[1])+int(i[2])-int(i[3])==7:
    print(i[0]+"+"+i[1]+"+"+i[2]+"-"+i[3]+"="+"7")
    exit
  elif int(i[0])+int(i[1])-int(i[2])-int(i[3])==7:
    print(i[0]+"+"+i[1]+"-"+i[2]+"-"+i[3]+"="+"7")
    exit
  elif int(i[0])-int(i[1])+int(i[2])-int(i[3])==7:
    print(i[0]+"-"+i[1]+"+"+i[2]+"-"+i[3]+"="+"7")
    exit
  elif int(i[0])-int(i[1])-int(i[2])-int(i[3])==7:
    print(i[0]+"-"+i[1]+"-"+i[2]+"-"+i[3]+"="+"7")
    exit
  elif int(i[0])+int(i[1])-int(i[2])+int(i[3])==7:
    print(i[0]+"+"+i[1]+"-"+i[2]+"+"+i[3]+"="+"7")
    exit
  elif int(i[0])-int(i[1])+int(i[2])+int(i[3])==7:
    print(i[0]+"-"+i[1]+"+"+i[2]+"+"+i[3]+"="+"7")
    exit
  elif int(i[0])-int(i[1])-int(i[2])+int(i[3])==7:
    print(i[0]+"-"+i[1]+"-"+i[2]+"+"+i[3]+"="+"7")
    exit

Submission status: Time Limit Exceeded

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

def add(a,b):
    return a+b
def sub(a,b):
    return a-b
lis = [0,0,0]
count = 0
while True:
    sum = 0
    if lis[0] == 0:
        sum = add(a,b)
    else:
        sum = sub(a,b)
    if lis[1] == 0:
        sum = add(sum,c)
    else:
        sum = sub(sum,c)
    if lis[2] == 0:
        sum = add(sum, d)
    else:
        sum = sub(sum, d)
    if sum == 7:
        break
    count += 1
    lis[0] = count % 2
    lis[1] = count // 2
    lis[2] = count// 4

if lis[0] == 0:
    x = '+'
else:
    x = '-'
if lis[1] == 0:
    y = '+'
else:
    y = '-'
if lis[2] == 0:
    z = '+'
else:
    z = '-'
print('{}{}{}{}{}{}{}=7'.format(a,x,b,y,c,z,d))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import itertools
import sys
sys.setrecursionlimit(10**6)

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

for i, j, k in itertools.product([1, -1], repeat=3):
    if a+b*i+c*j+d*k == 7:
        break

if i == 1:
    i = "+"
else:
    i = "-"
if j == 1:
    j = "+"
else:
    j = "-"
if k == 1:
    k = "+"
else:
    k = "-"

print("{}{}{}{}{}{}{}=7".format(a, i, b, j, c, k, d))

Submission status: Accepted

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



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


op_l = ['+','-']
for op1 in op_l:
    for op2 in op_l:
        for op3 in op_l:
            x = calc(calc(calc(a,b,op1),c,op2),d, op3)
            if x == 7:
                ans = str(a)+op1+str(b)+op2+str(c)+op3+str(d)+"=7"
                break
print(ans)

Submission status: Accepted

Solution code:
s = input()

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

    for i in range(3):
        if bit & (1 << i):
            ans += int(s[i + 1])
            f += "+"
        else:
            ans -= int(s[i + 1])
            f += "-"
        f += s[i + 1]
    if ans == 7:
        print(f + "=7")
        exit()

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
a, b ,c, d = input()
S = '+-'
for i in S:
    for j in S:
        for k in S:
            left = a + i + b + j + c + k + d
            if eval(left) == 7:
                print(left + '=7')
                exit()

Submission status: Accepted

Solution code:
# 解き直し
def add(i, b):
    if i:
        return "-" + str(b)
    else:
        return "+" + str(b)
def main():
    S = input()
    a, b, c, d = int(S[0]), int(S[1]), int(S[2]), int(S[3])
    ans = ""
    for i in range(2):
        for j in range(2):
            for k in range(2):
                if a + (-1)**i * b + (-1)**j * c + (-1)**k * d == 7:
                    ans += str(a)
                    ans += add(i, b)
                    ans += add(j, c)
                    ans += add(k, d)
                    ans += "=7"
                    print(ans)
                    return
main()

Submission status: Accepted

Solution code:
S = list(map(int, list(input())))
ans = ""
for bit in range(2**3):
    temp = S[0]

    for i in range(3):

        if bit & (1<<i):
            temp +=S[i+1]
        else:
            temp -= S[i+1]

    if temp == 7:
        for i in range(3):
            ans += str(S[i])

            if bit & (1 << i):
                ans += "+"
            else:
                ans += "-"
        ans += str(S[3]) + "=7"
        print(ans)
        break

Submission status: Accepted

Solution code:
# coding: utf-8

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

    for i in range(8):
        s = S[0]
        tmp = int(s)

        for j in range(3, 0, -1):
            t = S[4-j]
            if i & 1 << j - 1:
                tmp += int(t)
                s += '+' + t
            else:
                tmp -= int(t)
                s += '-' + t

        if tmp == 7:
            print(s, '=7', sep='')
            break

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
a,b,c,d=list(input())
a,b,c,d=int(a),int(b),int(c),int(d)
op=["+","-"]
for i in range(2):
  for j in range(2):
    for k in range(2):
      if i == 0:
        if j == 0:
          if k == 0:
            ans = a+b+c+d
          else:
            ans = a+b+c-d
        else:
          if k == 0:
            ans = a+b-c+d
          else:
            ans = a+b-c-d
      else:
        if j == 0:
          if k == 0:
            ans = a-b+c+d
          else:
            ans = a-b+c-d
        else:
          if k == 0:
            ans = a-b-c+d
          else:
            ans = a-b-c-d
      if ans == 7:
        print(str(a)+op[i]+str(b)+op[j]+str(c)+op[k]+str(d)+"=7")
        quit()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-09-26 23:24:58 +0900
# LastModified: 2020-09-26 23:33:37 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    L = input()
    if int(L[0]) + int(L[1]) + int(L[2]) + int(L[3]) == 7:
        print("{}+{}+{}+{}=7".format(L[0], L[1], L[2], L[3]))

    elif int(L[0]) + int(L[1]) + int(L[2]) - int(L[3]) == 7:
        print("{}+{}+{}-{}=7".format(L[0], L[1], L[2], L[3]))

    elif int(L[0]) + int(L[1]) - int(L[2]) + int(L[3]) == 7:
        print("{}+{}-{}+{}=7".format(L[0], L[1], L[2], L[3]))

    elif int(L[0]) - int(L[1]) + int(L[2]) + int(L[3]) == 7:
        print("{}-{}+{}+{}=7".format(L[0], L[1], L[2], L[3]))

    elif int(L[0]) + int(L[1]) - int(L[2]) - int(L[3]) == 7:
        print("{}+{}-{}-{}=7".format(L[0], L[1], L[2], L[3]))

    elif int(L[0]) - int(L[1]) + int(L[2]) - int(L[3]) == 7:
        print("{}-{}+{}-{}=7".format(L[0], L[1], L[2], L[3]))

    elif int(L[0]) - int(L[1]) - int(L[2]) + int(L[3]) == 7:
        print("{}-{}-{}+{}=7".format(L[0], L[1], L[2], L[3]))

    elif int(L[0]) - int(L[1]) - int(L[2]) - int(L[3]) == 7:
        print("{}-{}-{}-{}=7".format(L[0], L[1], L[2], L[3]))




if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = input()
for bit in range(1 << 3):
    f = s[0]
    ans = int(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:
        f += "=7"
        print(f)
        break

Submission status: Accepted

Solution code:
s=list(input())

for i in range(2**(len(s)-1)):
    f =['']*(len(s)-1)
    siki=''
    for j in range(len(s)-1):
        if(i>>j & 1):
            f[j] = '+'
        else:
            f[j] = '-'
    for k in range(len(s)-1):
        siki += s[k] + f[k]
    siki += s[-1]
    if eval(siki)==7:
        siki += '=7'
        print(siki)
        break

Submission status: Accepted

Solution code:
li=list(input())

def Calc(a,b,s):
  if s=='+':
    return a+b
  else:
    return a-b

for i in range(2**3):
    b=['+','+','+']
    for j in range(3):
        if (i >> j) & 1:
            b[j]='-'
    aplusb=Calc(int(li[0]),int(li[1]),b[0])
    abplusc=Calc(aplusb,int(li[2]),b[1])
    calc=Calc(abplusc,int(li[3]),b[2])
    
    if calc==7:
      print(str(li[0])+b[0]+str(li[1])+b[1]+str(li[2])+b[2]+str(li[3])+'=7')
      break

Submission status: Accepted

Solution code:
a, b, c, d = input()
op = [0] * 3

for i in range(2 ** 3):
    for j in range(3):
        if (i >> j) & 1 == 1:
            op[j] = '+'
        else:
            op[j] = '-'
    expression = a + op[0] + b + op[1] + c + op[2] + d
    if eval(expression) == 7:
        print(expression+'=7')
        break

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
import sys
a,b,c,d = input()
a,b,c,d = int(a),int(b),int(c),int(d)
op=["-","+"]
for i in op:
  for j in op:
    for k in op:
      if i=="-":
        now=a-b
      else:
        now=a+b
      
      if j=="-":
        now=now-c
      else:
        now=now+c
      
      if k=="-":
        now=now-d
      else:
        now=now+d
      
      if now==7:
        print(str(a)+i+str(b)+j+str(c)+k+str(d)+"="+"7")
        sys.exit()
      else:
        now=0

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+'-'+s[i+1], sum-int(s[i+1]))
        dfs(i+1, f+'+'+s[i+1], sum+int(s[i+1]))

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

Submission status: Accepted

Solution code:
s = input()
ans1=s[0]

def solve(i,tmp,ans):
  global ans1
  if i==3:
    if tmp==7:
      ans1=ans
      return True
    else:
      return False
  
  if solve(i+1,tmp+int(s[i+1]),ans+"+"+s[i+1]): return True
  if solve(i+1,tmp-int(s[i+1]),ans+"-"+s[i+1]): return True

if solve(0,int(s[0]),ans1):
  print(ans1+"=7")

Submission status: Accepted

Solution code:
lst = list(input())
for i,num in enumerate(lst):
    lst[i] = int(num)

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

Submission status: Accepted

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

def calc(n, a, b):
  if n == 0:
    return a + b
  else:
    return a - b

pm = "+-"
for i in range(2):
  num = calc(i, a, b)
  for j in range(2):
    num2 = calc(j, num, c)
    for k in range(2):
      num3 = calc(k, num2, d)
      if num3 == 7:
        ans = str(a) + pm[i] + str(b) + pm[j] + str(c) + pm[k] + str(d) + "=7"
        print(ans)
        exit()

Submission status: Accepted

Solution code:
S = input()
N = len(S)
for i in range(2**(N-1)):
    sum = int(S[0])
    f = S[0]
    for j in range(N-1):
        if (i >> j) & 1:
            f += '+'
            sum += int(S[j+1])
        else:
            f += '-'
            sum -= int(S[j+1])
        f += S[j+1]
    # calc
    if sum == 7:
        print('{}=7'.format(f))
        break

Submission status: Accepted

Solution code:
n = input()
N = [int(i) for i in n]
for i in range(8):
  n = format(i, '03b')
  ans = N[0]
  msg = str(N[0])
  for j in range(3):
    if n[j] == '0':
      ans += N[j+1]
      msg += '+' + str(N[j+1])
    else:
      ans -= N[j+1]
      msg += '-' + str(N[j+1])
  if ans == 7:
    print(msg + "=7")
    break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 21 23:12:36 2020

@author: liang
"""

"""
eval関数
入力 :　式
    eval("2+3")
出力 : 値
    5
"""
S = input()

ans = S[0]
for i in range(8):
    tmp = S[0]
    
    for j in range(3):
        if i>>j&1 == 1:
            tmp += "+" + S[j+1]
        else:
            tmp += "-" + S[j+1]
    #print(tmp)
    #print(eval(tmp))
    if eval(tmp) == 7:
        #print("ok")
        ans = tmp
        ans += "=7"
        #print(ans)
        break
print(ans)

Submission status: Accepted

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

num = list(input())

op = ['+','-']

for op1 in op:
    if op1 == '+':
        res1 = int(num[0]) + int(num[1])
    else:
        res1 = int(num[0]) - int(num[1])
    for op2 in op:
        if op2 == '+':
            res2 = res1 + int(num[2])
        else:
            res2 = res1 - int(num[2])
        for op3 in op:
            if op3 == '+':
                res3 = res2 + int(num[3])
            else:
                res3 = res2 - int(num[3])

            if res3 == 7:
                ans = num[0]+op1+num[1]+op2+num[2]+op3+num[3]+"=7"
                print(ans)
                exit()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 21 22:53:14 2020

@author: liang
"""

S = input()

ans = S[0]

for i in range(8):
    tmp = int(S[0])
    lis = list()
    for j in range(3):
        lis.append(i>>j&1)
    for i in range(3):
        if lis[i] == 1:
            tmp += int(S[i+1])
        else:
            tmp -= int(S[i+1])
    #print(tmp)
    if tmp == 7:
        for i in range(3):
            if lis[i] == 1:
                ans += "+" + S[i+1]
            else:
                ans += "-" + S[i+1]
        ans += "=7"
        break
    #print(lis)
else:
    print("err")
print(ans)

Submission status: Accepted

Solution code:
ABCD = input()

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

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

Submission status: Accepted

Solution code:
def main():
	S = list(str(input()))
	LenP = 3
	ans = 0
	for i in range(2**LenP):
		P = ["-"]*LenP
		for j in range(LenP):
			if i >> j & 1:
				P[j] = "+"
		Res = [None] * (len(S)+len(P))
		Res[1::2],Res[::2] = P,S
		ResEval = "".join(Res)
		if eval(ResEval) == 7:
			ans = ResEval+"=7"
			print(ans)
			break

if __name__ == '__main__':
	main()

Submission status: Accepted

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


for i in range(2**(n-1)):
    val = l[0]
    for j in range(n - 1):
        if (i >> j)&1 == 0:
            val += '-'
        elif (i >> j)&1 == 1:
            val += '+'
        
        val += l[j + 1]
    
    num = eval(val)
    if num == 7:
        print(val + '=7')
        break

Submission status: Accepted

Solution code:
from itertools import permutations, combinations_with_replacement

def calc(op, x, y):
    if op == "+":
        return x + y
    else:
        return x - y

def solve():
    A, B, C, D = map(int, list(input()))
    OP = combinations_with_replacement(["+", "-"], 3)
    for op in OP:
        O = permutations(op)
        s = set(O)
        for o in s:
            op1, op2, op3 = o
            tmp = calc(op3, calc(op2, calc(op1, A, B), C), D)
            if tmp == 7:
                print(f"{A}{op1}{B}{op2}{C}{op3}{D}=7")
                exit()

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
n=input()

for i in range(2 ** 3):
    

    co=["-","-","-"]

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

    eq=n[0]+co[0]+n[1]+co[1]+n[2]+co[2]+n[3]


    if eval(eq)==7:
            ans=eq

print(ans,end="")
print("=7")

Submission status: Accepted

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

for i in range(2**3+1):
  ans =[X[0]]
  for j in range(3):
    d = X[j+1]*(-1)**((i >>j)&1)
    ans.append(d)
  if sum(ans) == 7:
    for i,a in enumerate(ans):
      if a>=0 and i>0:
        print("+",end="")
      print(a,end="")
    print("=7")
    exit()

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
abcd = input()
for bit in range(1 << 3):
    first = int(abcd[0])
    ans = abcd[0]
    for i in range(3):
        if bit & (1 << i):
            first += int(abcd[i+1])
            ans += '+'
            ans += abcd[i+1]
        else:
            first -= int(abcd[i+1])
            ans += '-'
            ans += abcd[i+1]
    if first == 7:
        print(ans + '=7')
        exit()

Submission status: Accepted

Solution code:
from itertools import product


A, B, C, D = list(input())
for x, y, z in product(["+", "-"], repeat=3):
    eqn = A + x + B + y + C + z + D
    if eval(eqn) == 7:
        print(f"{eqn}=7")
        break

Submission status: Accepted

Solution code:
x = list(map(str, input()))
for i in range(2**3):
  op = ["-","-","-"]
  for j in range(3):
    if (i & 1<<j):
      op[j] = "+"
  if eval(x[0]+op[0]+x[1]+op[1]+x[2]+op[2]+x[3]) == 7:
    print(x[0]+op[0]+x[1]+op[1]+x[2]+op[2]+x[3]+"=7")
    break

Submission status: Accepted

Solution code:
num = str(input())
op = ['+', '-']

for i in range(2**3):
    ans = int(num[0])
    t_op = []
    for j in range(3):
        if (i >> j)&1:
            ans -= int(num[j+1])
            t_op.append('-')
        else:
            ans += int(num[j+1])
            t_op.append('+')
    if ans == 7:
        ans_l = [num[0], t_op[0], num[1], t_op[1], num[2], t_op[2], num[3], '=7']
        print(*ans_l,sep='')
        break

Submission status: Accepted

Solution code:
ABCD = input()
for p in range(1 << 3):
    v = int(ABCD[0])
    ans = ABCD[0]
    for i in range(3):
        if p & (1 << i):
            v -= int(ABCD[i + 1])
            ans += '-' + ABCD[i + 1]
        else:
            v += int(ABCD[i + 1])
            ans += '+' + ABCD[i + 1]
    if v == 7:
        print(ans + '=7')
        exit()

Submission status: Accepted

Solution code:
from itertools import product
A,B,C,D = list(input())
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:
s = list(input())
A = int(s[0])
B = int(s[1])
C = int(s[2])
D = int(s[3])
if A + B + C + D == 7:
    print(str(A) + "+" + str(B) + "+" + str(C) + "+" + str(D) + "=7")
elif A + B + C - D == 7:
    print(str(A) + "+" + str(B) + "+" + str(C) + "-" + str(D) + "=7")
elif A + B - C + D == 7:
    print(str(A) + "+" + str(B) + "-" + str(C) + "+" + str(D) + "=7")
elif A + B - C - D == 7:
    print(str(A) + "+" + str(B) + "-" + str(C) + "-" + str(D) + "=7")
elif A - B + C + D == 7:
    print(str(A) + "-" + str(B) + "+" + str(C) + "+" + str(D) + "=7")
elif A - B + C - D == 7:
    print(str(A) + "-" + str(B) + "+" + str(C) + "-" + str(D) + "=7")
elif A - B - C + D == 7:
    print(str(A) + "-" + str(B) + "-" + str(C) + "+" + str(D) + "=7")
elif A - B - C - D == 7:
    print(str(A) + "-" + str(B) + "-" + str(C) + "-" + str(D) + "=7")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(str(input()))
import itertools
for p in itertools.product(('+', '-'), repeat=3):
    temp = [0]*7
    for i in range(4):
        temp[2*i] = s[i]
    for i in range(3):
        temp[2*i+1] = p[i]
    #print(temp)
    temp = ''.join(temp)
    if eval(temp) == 7:
        print(temp+'=7')
        exit()

Submission status: Accepted

Solution code:

s=list(input())
a=s[0]
b=s[1]
c=s[2]
e=s[3]

for i in range(8):
    d=0
    x=[a,b,c,e]
    for j in range(3):
        if (i >> j)&1:
            x.insert(-j-1-d,'+')
            d+=1
        else:
            x.insert(-1-j-d,'-')
            d+=1
    q="".join(x)
    f=int(a)
    g=int(b)
    h=int(c)
    k=int(e)
    if q[1]=="-":
        g=-g
    if q[3]=="-":
        h=-h
    if q[5]=="-":
        k=-k
    if f+g+h+k==7:
        ans=q+"=7"
        print(ans)
        exit()

Submission status: Accepted

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

n = len(S)-1
for i in range(2 ** n):
    out = S[0]
    op = []
    for j in range(n):
        if (i>>j) & 1:
            out += S[j+1]
            op.append("+")
        else:
            out -= S[j+1]
            op.append("-")
    if out == 7:
        print(S[0], end='')
        for i in range(n):
            print(op[i], end='')
            print(S[i+1], end='')
        print("=7")
        exit()

Submission status: Accepted

Solution code:
# C - Train Ticket
import sys
num = input()

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

Submission status: Accepted

Solution code:
#A,B,C,D=map(int, list(input()))
numbers = list(map(int, list(input())))
seven="=7"

for i in range(1<<3):
    pms = []
    for j in range(3):
        if (i>>j)&1:
            pms.append(1)
        else:
            pms.append(0)
    result = numbers[0]
    result_str = str(numbers[0])
    for j, pm in enumerate(pms):
        j+=1
        if pm:
            result+=numbers[j]
            result_str+="+%d"%(numbers[j])
        else:
            result-=numbers[j]
            result_str+="-%d"%(numbers[j])
    if result==7:
        print(result_str+seven)
        break

Submission status: Accepted

Solution code:
S = input()
l = len(S) - 1
for i in range(2 ** l):
    op = ["-"] * l
    for j in range(l):
        if ((i >> j) & 1):
            op[l - 1 - j] = "+"
    formula = ""
    for j in range(l):
        formula+=S[j]
        if op[j]=="+":
            formula+="+"
        else:
            formula+="-"
    formula+=S[l]
    if eval(formula)==7:
        print(formula+"=7")
        break

Submission status: Accepted

Solution code:
a, b, c, d = 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(a+sign[i]+b+sign[j]+c+sign[k]+d + "=7")
                                exit()

Submission status: Accepted

Solution code:
# ABC079 C
abcd = input()
ABCD = []
for i in range(len(abcd)):
    ABCD.append(abcd[i])

# print(ABCD)

# 全通り検査する
for i in range(2**3):
    op = []

    # 各ビットのチェック
    for j in range(3):
        # 最下位ビットが１なら"+"
        if ((i >> j) & 1):
            op.append("+")
        else:
            op.append("-")
    # 全パターン網羅できていること確認
    # print(op)

    # ans = 0
    # for k in range(len(op)):
    #     if op[k] == "+":
    #         ans = ABCD[k]+ABCD[k+1]
    #         ABCD[k+1] = ans
    #         print(ans)
    #     else:
    #         ans = ABCD[k]-ABCD[k+1]
    #         ABCD[k+1] = ans
    # if ans == 7:
    #     print(op)

    # 数値の配列と演算子の配列の結合
    tmp = [None] * (len(ABCD)+len(op))
    # 最初から最後まで1個飛ばしで代入
    tmp[::2] = ABCD
    tmp[1::2] = op
    # print(tmp) # 色の配列完成
    
    # 計算
    ans = ""
    for i in tmp:
        ans += i
    # evalは文字列をpythonのコードとして実行してくれる関数，つまり文字列で表現された数式を計算してくれる
    if eval(ans) == 7:
        print(ans + "=7")
        exit()

Submission status: Accepted

Solution code:
X = str(input())

# 文字列を4つのintに分裂
# 二分検索でヒットしたらタス、そうでなければ引く、listに履歴を残しておく

for i in range(2**3):
  ans = int(X[0])
  list = []
  for j in range(3):
    if (i>>j & 1) == 1:
      ans += int(X[j+1])
      list.append("+")
    else:
      ans -= int(X[j+1])
      list.append("-")
  if ans == 7:
    break

ans = X[0]
for i in range(3):
  ans += list[i]
  ans += X[i+1]
print(ans+"=7")

Submission status: Accepted

Solution code:
a, b, c, d = [c for c in input()]
candids = []
for i in range(8):
    candid = []
    for k in range(3):
        if i >> k & 1 > 0:
            candid.append("+")
        else:
            candid.append("-")
        
    candids.append(candid)
#print(candids)
for op1, op2, op3 in candids:
    if eval(a+op1+b+op2+c+op3+d) == 7:
        print (a+op1+b+op2+c+op3+d+"=7")
        break

Submission status: Accepted

Solution code:
S = input()
A,B,C,D = int(S[0]),int(S[1]),int(S[2]),int(S[3])

if A+B+C+D == 7:
  print(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:
#他の人の回答例　後から見返す用

A = input()
n = len(A)-1
for i in range(2**n):
  pn = ['-']*n
  for j in range(n):
    if ((i>>j)&1):
      pn[n-1-j] = '+'
  ans = A[0]+pn[0]+A[1]+pn[1]+A[2]+pn[2]+A[3]
  
  if eval(ans) == 7:
    print(ans+'=7')
    break

Submission status: Accepted

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

for x in range(2**3):
    ans = p[0]
    for y in range(3):
        if (x>>y)&1:
            ans += p[y+1]
        else:
            ans -= p[y+1]
    if ans == 7:
        kotae = format(x,"#05b")

kotae = kotae[2:]
for z in range(3):
    print(str(p[z]),end="")
    if kotae[-z-1] == str(1):
        print("+",end="")
    else:
        print("-",end="")

print(str(p[3]) + "=7" )

Submission status: Accepted

Solution code:
ABCD = input().strip()
for i in range(8):
    ope = [{0:'+', 1:'-'}[(i>>j) & 1] for j in range(3)]
    fomula = ABCD[0] + ope[0] + ABCD[1] + ope[1] + ABCD[2] + ope[2] + ABCD[3]
    if eval(fomula) == 7:
        print(f'{fomula}=7')
        break

Submission status: Accepted

Solution code:
s = input()


for i in range(1 << 3):
    count = int(s[0])
    for j in range(1, 4):
        if i & (1 << j-1):
            count+=int(s[j])
        else:
            count-=int(s[j])
    
    if count == 7:
        ans = s[0] 
        for j in range(1, 4):
            if i & (1 << j-1):
                ans += '+'+s[j]
            else:
                ans += '-'+s[j]

        ans += '=7'
        print(ans)
        exit()