Problem:


Score : 300 points

Problem Statement

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

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

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

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

Constraints

0≤A,B,C,D≤9

All input values are integers.

It is guaranteed that there is a solution.

Input

Input is given from Standard Input in the following format:

ABCD

Output

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

Use the signs + and -.

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

Sample Input 1

1222

Sample Output 1

1+2+2+2=7

This is the only valid solution.

Sample Input 2

0290

Sample Output 2

0-2+9+0=7

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

Sample Input 3

3242

Sample Output 3

3+2+4-2=7



Sample input:
1222


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

Submission status: Accepted

Solution code:
import itertools
N = list(map(int, list(str(input()))))

def f():
    for pm in itertools.product(range(2), repeat = 3):
        ans = N[0]
        lst = []
        for i in range(3):
            if pm[i] == 1:
                ans += N[i + 1]
                lst.append("+")
            else:
                ans -= N[i + 1]
                lst.append("-")
        if ans == 7:
            for i in range(3):
                print(N[i], end = "")
                print(lst[i], end = "")
            print(N[-1], end = "")
            print("=7")
            return 0

f()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

def solve(n,S,idx):
    if len(n) == 7:
        if eval(n) == 7:
            n += "=7"
            print(n)
            exit()
        return

    solve(n+"+"+S[idx], S,idx+1)
    solve(n+"-"+S[idx], S,idx+1)

solve(S[0], S, 1)

Submission status: Accepted

Solution code:
ABCD=input()
a=list(ABCD)

for p in range(1<<3):
    t = int(a[0])
    ans = a[0]
    for i in range(1,4):
        if p&(1<<(i-1)):
            t+=int(a[i])
            ans += '+' + a[i]
        else:
            t-=int(a[i])
            ans += '-' + a[i]
    if t==7:
        print(ans+'=7')
        break

Submission status: Accepted

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

for case in range(8):
    ans = str(S[0])
    ans_val = S[0]
    case_tmp = case
    for i in range(3):
        if case_tmp % 2 > 0:
            ans_val += S[i + 1]
            ans += '+{}'.format(S[i + 1])
        else:
            ans_val -= S[i + 1]
            ans += '-{}'.format(S[i + 1])
        case_tmp >>= 1
    #
    if ans_val == 7: break
    else: continue
else:
    ans = 'kanipanman'

print(ans + '=7')

Submission status: Accepted

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

    a = int(abcd[0])
    b = int(abcd[1])
    c = int(abcd[2])
    d = int(abcd[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')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    S = input()
    for bit in range(1 << 3):
        calc_v = int(S[0])
        ans = [S[0]]
        for i in range(3):
            if bit & (1 << i):
                calc_v += int(S[i+1])
                ans.append("+")
                ans.append(S[i+1])
            else:
                calc_v -= int(S[i+1])
                ans.append("-")
                ans.append(S[i+1])
        if calc_v == 7:
            return print("".join(ans)+"=7")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    a,b,c,d = map(int,input())
    l = [b,c,d]
    for k in range(1<<3):
        s = a
        ans = []
        for i in range(3):
            if k&(1<<i):
                ans.append("+")
                s += l[i]
            else:
                ans.append("-")
                s -= l[i]
        if s == 7:
            k = [a]
            for i in range(3):
                k.append(ans[i])
                k.append(l[i])
            k.append("=7")
            print(*k,sep="")
            return
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
a,b,c,d = input()
for x in '-+':
    for y in '-+':
        for z in '-+':
            f = a+x+b+y+c+z+d
            v = eval(f)
            if v==7:
                print(f+'=7')
                exit()

Submission status: Accepted

Solution code:
n = [int(x) for x in input()]
op_cnt = len(n) - 1

tmp = 0
for i in range(2**op_cnt):
    tmp = n[0]
    for j in range(op_cnt):
        if (i >> j) & 1:
            tmp += n[j+1]
        else:
            tmp -= n[j+1]
    if tmp == 7:
        print(
            "{}{}{}{}{}{}{}=7".format(
                n[0], "+" if (i >> 0) & 1 else "-",
                n[1], "+" if (i >> 1) & 1 else "-",
                n[2], "+" if (i >> 2) & 1 else "-",
                n[3]
            )
        )
        exit()

Submission status: Accepted

Solution code:
import io
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

import itertools

A, B, C, D = list(read().rstrip().decode('utf-8'))

for operators in itertools.product(['+', '-'], repeat=3):
    op1, op2, op3 = operators
    eq = A + op1 + B + op2 + C + op3 + D
    x = eval(eq)
    if x == 7:
        break

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

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = input()
    num = [0] * 4
    for i in range(4):
        num[i] = int(s[i])

    for bit in range(1 << 3):
        x = num[0]
        for i in range(3):
            if bit >> i & 1:
                x += num[i + 1]
            else:
                x -= num[i + 1]
        if x == 7:
            res = ""
            for j in range(3):
                res += str(num[j])
                if bit >> j & 1:
                    res += "+"
                else:
                    res += "-"
            res += str(num[3])
            res += "=7"
            print(res)
            sys.exit()


if __name__ == '__main__':
    main()

Submission status: Accepted

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

sym = ["+", "-"]

for op1 in range(2):
    for op2 in range(2):
        for op3 in range(2):
            S = A + B * (-1) ** op1 + C * (-1) ** op2 + D * (-1) ** op3
            if S == 7:
                print("".join(map(str, [A, sym[op1], B, sym[op2], C, sym[op3], D, "=", 7])))
                exit()

Submission status: Accepted

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

def main():
    num = list(readline())
    op = ['+', '-']
    for op1 in op:
        for op2 in op:
            for op3 in op:
                f = num[0] + op1 + num[1] + op2 + num[2] + op3 + num[3]
                if eval(f) == 7:
                    print(f + '=7')
                    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

def main():
    num = list(map(int, list(readline().rstrip())))
    for op1 in ['+', '-']:
        for op2 in ['+', '-']:
            for op3 in ['+', '-']:
                v = num[0]
                if op1 == '+':
                    v += num[1]
                else:
                    v -= num[1]
                if op2 == '+':
                    v += num[2]
                else:
                    v -= num[2]
                if op3 == '+':
                    v += num[3]
                else:
                    v -= num[3]
                if v == 7:
                    print(str(num[0])+op1+str(num[1])+op2+str(num[2])+op3+str(num[3])+'=7')
                    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(2 ** 3):
    op = ['+', '+', '+']
    ans = a
    for j in range(3):
        if ((i >> j) & 1):
            op[j] = '-'
            ans -= int(abcd[j + 1])
        else:
            ans += int(abcd[j + 1])
    if ans == 7:
        print(str(a) + str(op[0]) + str(b) + str(op[1]) + str(c) + str(op[2]) + str(d) + '=7')
        exit()

Submission status: Accepted

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

N = 3
for i in range(2**N):
    op123 = ['+', '+', '+']
    for j in range(N):
        if((i >> j) & 1):
            op123[j] = '-'

    if eval(A+op123[0]+B+op123[1]+C+op123[2]+D) == 7:
        print((A+op123[0]+B+op123[1]+C+op123[2]+D+'=7'))
        exit(0)

Submission status: Accepted

Solution code:
from itertools import permutations
def myAnswer(ABCD:list) -> str:
   ans = ""
   l = ["+","+","+","-","-","-"]
   # l = ["+","-"]
   for c in permutations(l,3):
      total = int(ABCD[0])
      ans = ABCD[0]
      for n,i in enumerate(c):
         if(i=="+"):
            total += int(ABCD[n+1])
            ans += "+" + ABCD[n+1]
         else:
            total -= int(ABCD[n+1])
            ans += "-" + ABCD[n+1]
      if(total == 7):
         return ans + "=7"




def modelAnswer():
   tmp=1
def main():
   ABCD = list(input())
   print(myAnswer(ABCD[:]))

if __name__ == '__main__':
   main()

Submission status: Accepted

Solution code:
L = list(map(int,list(input())))
for i in range(8):
    Str = '{:03b}'.format(i)
    cnt = L[0]
    for j in range(3):
        if Str[j] == '0':
            cnt -= L[j+1]
        else:
            cnt += L[j+1]
    if cnt == 7:
        ans = str(L[0])
        for j in range(3):
            if Str[j] == '0':
                ans += '-'
            else:
                ans += '+'
            ans += str(L[j+1])
        ans += '=7'
        print(ans)
        break

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc079/tasks/abc079_c
import random
import sys

str = input()


def retop():
    if(random.uniform(0, 1) > 0.5):
        return "+"
    return "-"


for i in range(100):
    formula = (str[0] + retop() + str[1] + retop() + str[2] + retop() + str[3])
    if eval(formula) == 7:
        print(formula + "=7")
        sys.exit()

Submission status: Accepted

Solution code:
def main():
    ABCD = input()
    A = int(ABCD[0])
    B = int(ABCD[1])
    C = int(ABCD[2])
    D = int(ABCD[3])
    for i in range(2):
        for j in range(2):
            for k in range(2):
                ans = 0
                op1 = ""
                op2 = ""
                op3 = ""
                if i % 2 == 0:
                    ans = A + B
                    op1 = "+"
                else:
                    ans = A - B
                    op1 = "-"
                
                if j % 2 == 0:
                    ans = ans + C
                    op2 = "+"
                else:
                    ans = ans - C
                    op2 = "-"
                
                if k % 2 == 0:
                    ans = ans + D
                    op3 = "+"
                else:
                    ans = ans - D
                    op3 = "-"

                if ans == 7:
                    print("{}{}{}{}{}{}{}=7".format(A, op1, B, op2, C, op3, D))
                    exit()
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
a,b,c,d = map(int,input())
if a + b + c + d == 7:
    print(str(a)+'+'+str(b)+'+'+str(c)+'+'+str(d)+'='+'7')
elif a + b + c - d == 7:
    print(str(a)+'+'+str(b)+'+'+str(c)+'-'+str(d)+'='+'7')
elif a + b - c - d == 7:
    print(str(a)+'+'+str(b)+'-'+str(c)+'-'+str(d)+'='+'7')
elif a - b - c - d == 7:
    print(str(a)+'-'+str(b)+'-'+str(c)+'-'+str(d)+'='+'7')
elif a  + b - c + d == 7:
    print(str(a)+'+'+str(b)+'-'+str(c)+'+'+str(d)+'='+'7')
elif a - b - c + d == 7:
    print(str(a)+'-'+str(b)+'-'+str(c)+'+'+str(d)+'='+'7')
elif a - b + c + d == 7:
    print(str(a)+'-'+str(b)+'+'+str(c)+'+'+str(d)+'='+'7')
else:
    print(str(a)+'-'+str(b)+'+'+str(c)+'-'+str(d)+'='+'7')

Submission status: Accepted

Solution code:
def resolve():
    A, B, C, D = list(map(int, input()))
    for op1 in ["+", "-"]:
        AB = A+B if op1 == "+" else A-B
        for op2 in ["+", "-"]:
            ABC = AB+C if op2 == "+" else AB-C
            for op3 in ["+", "-"]:
                ABCD = ABC+D if op3 == "+" else ABC-D
                if ABCD == 7:
                    print("{A}{op1}{B}{op2}{C}{op3}{D}=7".format(A=A,
                                                                 op1=op1,
                                                                 B=B,
                                                                 op2=op2,
                                                                 C=C,
                                                                 op3=op3,
                                                                 D=D))
                    return
    raise Exception("Not found")

    




if '__main__' == __name__:
    resolve()

Submission status: Accepted

Solution code:
I = str(input())
A = int(I[0])
B = int(I[1])
C = int(I[2])
D = int(I[3])
flag = False
for i in range(2):
    for j in range(2):
        for k in range(2):
            S = A
            a = b = c = '+' 
            if i == 0:
                S += B
                a = '+'
            else:
                S -= B
                a = '-'
            if j == 0:
                S += C
                b = '+'
            else:
                S -= C
                b = '-'
            if k == 0:
                S += D
                c = '+'
            else:
                S -= D
                c = '-'
            if S == 7:
                print(str(A)+a+str(B)+b+str(C)+c+str(D)+'=7')
                flag = True
                break
        if flag:
            break
    if flag:
        break

Submission status: Accepted

Solution code:
import itertools
a, *bcd = input()
for operater in itertools.product(['+', '-'], repeat=3):
    formula = a
    formula += "".join(op+num for op, num in zip(operater, bcd))
    if eval(formula) == 7:
        print(formula+'=7')
        exit()

Submission status: Accepted

Solution code:
from itertools import product
from operator import add, sub


def op_to_str(op):
  if op == add:
    return "+"
  else:
    return "-"


def main():
  a, b, c, d = map(int, input())
  
  op = (add, sub)
  for op1, op2, op3 in product(op, op, op):
    if op3(op2(op1(a, b), c), d) == 7:
      answer = (
        str(a) + op_to_str(op1)
      	+ str(b) + op_to_str(op2) 
        + str(c) + op_to_str(op3)
        + str(d) + "=7"
      )
      print(answer)
      break
      

if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
s = input()
#import sys
#s = '1222'
n = len(s)
for i in range(2**(n-1)):
  #print(i)
  f = ''
  b = format(i, 'b').zfill(n-1) + '0'
  #print(b)
  for j in range(n):
    f += s[j]
    if b[j] == '0':
      f += '-'
    else:
      f += '+'
  f = f[:len(f)-1]
  #print(f)
  if eval(f) == 7:
    print(f+'=7')
    break

Submission status: Accepted

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

for i in range(2**n):
    ope = ['-']*n
    for j in range(n):
        if (i >> j & 1):
            ope[j] = '+'
    formula = ''
    for i, o in zip(abcd, ope+['']):
        formula += i+o
    if eval(formula) == 7:
        print(formula+'=7')
        break

Submission status: Accepted

Solution code:
abcd = list(map(int, input()))
n = len(abcd)-1


for i in range(2**n):
    ans = 0
    formula = []
    for j in range(n):
        if (i >> j & 1):
            formula.append('+')
        else:
            formula.append('-')
    ans += abcd[0]
    for k in range(n):
        if formula[k] == '+':
            ans += abcd[k+1]
        elif formula[k] == '-':
            ans -= abcd[k+1]
    if ans == 7:
        print(abcd[0], formula[0], abcd[1], formula[1],
              abcd[2], formula[2], abcd[3], '=', 7, sep='')
        break

Submission status: Accepted

Solution code:
INF = 10 ** 9
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  heapq import heappop,heapify,heappush
from bisect import bisect_left

def main():
    s = input()
    for bit in range(8):
        op = []
        for i in range(3):
            if (bit>>i)&1:
                op.append('+')
            else:
                op.append('-')
        
        tmp = s[0]
        for i in range(3):
            tmp += op[i]
            tmp += s[i + 1]

        if eval(tmp) == 7:
            ans = tmp + '=7'
            break
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()

equations_str = [S[0]]

def add_str(s:str, op:str):
    return s+op

for i in S[1:]:
    tmp_plus = list(map(lambda x: x+'+'+i, equations_str))
    tmp_minus = list(map(lambda x: x+'-'+i, equations_str))
    equations_str = tmp_plus
    equations_str.extend(tmp_minus)

for eq in equations_str:
    if eval(eq) == 7:
        print(eq+'=7')
        break

Submission status: Accepted

Solution code:

s = input()

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

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

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

Submission status: Accepted

Solution code:
s = input()

def dfs(i,sen,num):
    if i == 3:
        if num == 7:
            print(sen+"=7")
            quit()
    else:
        dfs(i+1,sen+"+"+s[i+1],num+int(s[i+1]))
        dfs(i+1,sen+"-"+s[i+1],num-int(s[i+1]))

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

Submission status: Accepted

Solution code:

n = [int(x) for x in input()]
op_cnt = len(n) - 1  # すき間の個数

for i in range(2 ** op_cnt):
    op = ["-"] * op_cnt  # あらかじめ ["-", "-", "-"] というリストを作っておく

    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt - 1 - j] = "+"  # フラグが立っていた箇所を "+" で上書き

    formula = ""

    for p_n, p_o in zip(n, op + [""]):  # 少々モヤッとする
        sum = str(p_n) + p_o
        formula += sum

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

Submission status: Accepted

Solution code:
import sys

S = list(input())

N = len(S)-1

#bit全探索
for i in range(2**N):
    op = ["+"]*N
    for j in range(N):
        if (i>>j)&1:
            op[j] = "-"
    ans = ""
    for j in range(N):
        ans = ans + S[j] + op[j]

    ans = ans + S[j+1]

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

Submission status: Accepted

Solution code:
s = input()
n_op = len(s) - 1
for i in range(2**n_op):
  op = ['-'] * n_op
  for j in range(n_op):
    if i>>j & 1:
      op[n_op - 1 - j] = '+'
    
  formula = ''
  for p_s, p_op in zip(s, op+['']):
    formula += p_s + p_op
  if eval(formula) == 7:
    print(formula + '=7')
    break

Submission status: Accepted

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

OP = ('+', '-')

def solve():
  for op1 in OP:
    for op2 in OP:
      for op3 in OP:
        formula = A + op1 + B + op2 + C + op3 + D
        if eval(formula) == 7:
          return formula + '=7'

print(solve())

Submission status: Accepted

Solution code:
a,b,c,d=list(input())
import itertools
#長さ3の+と-の組み合わせができる　イテレータ
for ops in itertools.product(["+","-"],repeat=3):
    eq = a+ops[0]+b+ops[1]+c+ops[2]+d
    x = eval(eq)
    if x == 7:
        break

ans = eq + "=7"
print(ans)

Submission status: Accepted

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

for i in range(2**(n-1)):
    x = [s[0]]
    for j in range(n-1):
        if (i>>j)&1:
            y ='+'
        else:
            y = '-'
        x.append(y)
        y = 0
        x.append(s[j+1])
    z = ''.join(x)
    if eval(z) == 7:
        print(z + '=7')
        break

Submission status: Accepted

Solution code:
x = input()

for i in ["+","-"]:
    for j in ["+","-"]:
        for k in ["+","-"]:
            y = x[0]+i+x[1]+j+x[2]+k+x[3]
            if eval(y) == 7:
                ans = y
                
print(ans+"=7")

Submission status: Accepted

Solution code:
import sys
A = input()
A = list(A[0]+"F"+A[1]+"G"+A[2]+"H"+A[3])
B=["+", "-"]

for i in range(2):
    for j in range(2):
        for k in range(2):
            A[1] = B[i]
            A[3] = B[j]
            A[5] = B[k]
            C = "".join(A)
            if 7 == eval(C):
                print(C+"=7")
                sys.exit()

Submission status: Accepted

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

for i in range(8):
    output = []
    for j in range(3):
        if ((i >> j) & 1) == 1:
            output.append('+')
        else:
            output.append('-')
    ans = 0
    ansstr = ''
    for i in range(4):
        if i == 0:
            ans += int(s[i])
            ansstr += s[i]
        elif output[i-1] == '+':
            ans += int(s[i])
            ansstr += output[i-1]
            ansstr += s[i]
        else:
            ans -= int(s[i])
            ansstr += output[i-1]
            ansstr += s[i]
    if ans == 7:
        print(ansstr+'=7')
        exit()

Submission status: Accepted

Solution code:
nums=[int(n) for n in input()]

n=1
A=[nums[0]]

while n<=3:
    B=[]
    for a in A:
        B+=[a+nums[n],a-nums[n]]
    A=B
    n+=1

ans=str(nums[3])+'=7'
C=B.index(7)

for n in reversed(range(3)):
    if C%2==0:
        ans='+'+ans
    else:
        ans='-'+ans
    ans=str(nums[n])+ans
    C//=2

print(ans)

Submission status: Accepted

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

op = ['+', '-']

def check(A, B, C, D):
    for i in range(2):
        for j in range(2):
            for k in range(2):
                x = A+op[i]+B+op[j]+C+op[k]+D
                if eval(x) == 7:
                    return x

print(check(A, B, C, D)+'=7')

Submission status: Accepted

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

for i in range(2**3):
    a = S[0]
    for j in range(3):
        if (i >> j) & 1:
            a += S[j+1]
        else:
            a -= S[j+1]
    if a != 7:
        continue
    else:
        ans = str(S[0])
        for j in range(3):
            if (i >> j) & 1:
                ans += '+' + str(S[j+1])
            else:
                ans += '-' + str(S[j+1])
        print(ans + '=7')
        break

Submission status: Accepted

Solution code:
def resolve():
    s = input()
    for bit in range(2 ** 3):
        _str = "".join(
            s[i] if i == 3 else s[i] + "+" if 1 << i & bit else s[i] + "-"
            for i in range(4)
        )
        if eval(_str) == 7:
            print(_str + "=7")
            return


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
a=input()
op1,op2,op3="+","+","+"

if int(a[0])+int(a[1])+int(a[2])+int(a[3])==7:
    op1,op2,op3="+","+","+"
elif int(a[0])-int(a[1])+int(a[2])+int(a[3])==7:
    op1,op2,op3="-","+","+"
elif int(a[0])+int(a[1])-int(a[2])+int(a[3])==7:
    op1,op2,op3="+","-","+"
elif int(a[0])+int(a[1])+int(a[2])-int(a[3])==7:
    op1,op2,op3="+","+","-"
elif int(a[0])+int(a[1])-int(a[2])-int(a[3])==7:
    op1,op2,op3="+","-","-"
elif int(a[0])-int(a[1])-int(a[2])-int(a[3])==7:
    op1,op2,op3="-","-","-"
elif int(a[0])-int(a[1])+int(a[2])-int(a[3])==7:
     op1,op2,op3="-","+","-"
elif int(a[0])-int(a[1])-int(a[2])+int(a[3])==7:
    op1,op2,op3="-","-","+"

print((a[0])+op1+str(a[1])+op2+str(a[2])+op3+str(a[3])+"=7")

Submission status: Accepted

Solution code:
A = input()
f = ['+', '-']

def check(A):
    for i in range(2):
        for j in range(2):
            for k in range(2):
                x  = A[0]+f[i]+A[1]+f[j]+A[2]+f[k]+A[3]
                if eval(x) == 7:
                    return x

print(check(A)+'=7')

Submission status: Accepted

Solution code:
A = input()
n = len(A)
i = 1
ans = ''

def check(i, a, ans):
    if i == n:
        if eval(a) == 7:
            ans = a
        return ans
    
    else:
        a = a[:2*i-2] + A[i-1:]
        p = i + a.count('+') + a.count('-')
        a = a[:p] + '+' + a[p:]
        ans = check(i+1, a, ans)
        
        a = a[:2*i-2] + A[i-1:]
        p = i + a.count('+') + a.count('-')
        a = a[:p] + '-' + a[p:]
        ans = check(i+1, a, ans)
    return ans

ans = check(i, A, ans) 
print(ans+'=7')

Submission status: Accepted

Solution code:
N = 4
A = list(input())
total = 0

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

Submission status: Accepted

Solution code:
k=input()
a=int(k[0])
b=int(k[1])
c=int(k[2])
d=int(k[3])
op1=["+","-"]
op2=["+","-"]
op3=["+","-"]
flag=0
for i in range(2):
  for j in range(2):
    for l in range(2):
      siki=k[0]+op1[i]+k[1]+op2[j]+k[2]+op3[l]+k[3]
      if (eval(siki)==7):
        print(siki+"=7")
        flag=1
      if (flag==1):
        break
    if (flag==1):
      break
  if (flag==1):
    break

Submission status: Accepted

Solution code:

s = input()
n = len(s)
for i in range(1,2**n):
  ans = [s[0]]
  for j in range(1,n):
    if (i>>j) & 1:
      ans.append("+")
    else:
      ans.append("-")
    ans.append(s[j])
  if eval("".join(ans)) == 7:
    ans.append("=7")
    print("".join(ans))
    exit()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
s = input().strip()

op = ('+', '-')

for bit in range(8):
    ops = [op[bool(bit & (0x01 << d))] for d in range(3)]
    eq = ''.join(sum(zip(s, ops + ['']), ()))
    if eval(eq) == 7:
        print(eq+'=7')
        exit()

Submission status: Accepted

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

Submission status: Accepted

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

for bit in range(1<<(n-1)):
    f=int(s[0])
    g=s[0]
    for i in range(n-1):
        if bit&(1<<i):
            f+=int(s[i+1])
            g+='+'+s[i+1]
        else:
            f-=int(s[i+1])
            g+='-'+s[i+1]
    if f==7:
        ans=g
    
print(ans+'=7')

Submission status: Accepted

Solution code:
from itertools import product
a, b, c, d = input().strip()
for e, f, g in product(['+', '-'], repeat=3):
  s = a+e+b+f+c+g+d
  if eval(s+'==7'):
    print(s+'=7')
    exit()

Submission status: Accepted

Solution code:
from operator import add, sub
from itertools import product
a, b, c, d = map(int, input().strip())
e = {add:'+', sub:'-'}
for X in product([add, sub], repeat=3):
  if X[2](X[1](X[0](a, b), c), d) == 7:
    print('{}{}{}{}{}{}{}=7'.format(a, e[X[0]], b, e[X[1]], c, e[X[2]], d))
    exit()

Submission status: Accepted

Solution code:
p,q,r,s=map(int,input())
flag=False
if p+q+r+s==7:
    print(str(p)+'+'+str(q)+'+'+str(r)+'+'+str(s)+'=7')
    flag=True
elif p+q+r-s==7 and flag==False:
    print(str(p)+'+'+str(q)+'+'+str(r)+'-'+str(s)+'=7')
    flag=True
elif p+q-r+s==7 and flag==False:
    print(str(p)+'+'+str(q)+'-'+str(r)+'+'+str(s)+'=7')
    flag=True
elif p+q-r-s==7 and flag==False:
    print(str(p)+'+'+str(q)+'-'+str(r)+'-'+str(s)+'=7')
    flag=True
elif p-q+r+s==7 and flag==False:
    print(str(p)+'-'+str(q)+'+'+str(r)+'+'+str(s)+'=7')
    flag=True    
elif p-q+r-s==7 and flag==False:
    print(str(p)+'-'+str(q)+'+'+str(r)+'-'+str(s)+'=7')
    flag=True
elif p-q-r+s==7 and flag==False:
    print(str(p)+'-'+str(q)+'-'+str(r)+'+'+str(s)+'=7')
    flag=True
elif p-q-r-s==7 and flag==False:
    print(str(p)+'-'+str(q)+'-'+str(r)+'-'+str(s)+'=7')
    flag=True

Submission status: Accepted

Solution code:
a, b, c, d = map(int, ','.join(input()).split(','))

for i in range(2):
    for j in range(2):
        for k in range(2):
            ans = 0
            lists = []
            if i % 2 == 0:
                ans = a + b
                lists.append('+')
            else:
                ans = a - b
                lists.append('-')
            if j % 2 == 0:
                ans += c
                lists.append('+')
            else:
                ans -= c
                lists.append('-')
            if k % 2 == 0:
                lists.append('+')
                ans += d
            else:
                ans -= d
                lists.append('-')
            if ans == 7:
                print(str(a) + lists[0] + str(b) + lists[1] + str(c) + lists[2] + str(d) + '=7')
                exit()

Submission status: Accepted

Solution code:
import sys
import itertools

n = str(input())

fugo =["+","-"]
p = list(itertools.product(fugo,repeat=3))

for i in p:
  shiki = n[0]+i[0]+n[1]+i[1]+n[2]+i[2]+n[3]
  if eval(shiki) == 7:
    print(shiki+"=7")
    sys.exit()

Submission status: Accepted

Solution code:
def main():
    nums = [int(num) for num in input()]

    for bit in range(1<<3):
        result = nums[0]
        ans = str(nums[0])
        
        for i in range(3):
            if (bit>>i) & 1:
                result += nums[i+1]
                ans += "+" + str(nums[i+1])
            else:
                result -= nums[i+1]
                ans += "-" + str(nums[i+1])

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

if __name__ == "__main__":
    main()