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:
row = input()
row = list(row)
row = list(map(int, row))
Flag = False
for i in range(2):
    for j in range(2):
        for k in range(2):
            sum = row[0]
            if i == 0:
                op1 = "+"
                sum += row[1]
            else:
                op1 = "-"
                sum -= row[1]
            if j == 0:
                op2 = "+"
                sum += row[2]
            else:
                op2 = "-"
                sum -= row[2]   
            if k == 0:
                op3 = "+"
                sum += row[3]
            else:
                op3 = "-"
                sum -= row[3]  
            if sum == 7:
                Flag = True
                break
        if Flag:
            break
    if Flag:
        break

print(row[0],op1,row[1],op2,row[2],op3,row[3],"=7", sep="")

Submission status: Accepted

Solution code:
A, B, C, D = [int(c) for c in input()]

expressions = [
    "{}+{}+{}+{}",
    "{}+{}+{}-{}",
    "{}+{}-{}+{}",
    "{}-{}+{}+{}",
    "{}-{}-{}+{}",
    "{}-{}+{}-{}",
    "{}+{}-{}-{}",
    "{}-{}-{}-{}",
]

for exp in expressions:
    exp = exp.format(A, B, C, D)
    if eval(exp) == 7:
        print(exp + "=7")
        break

Submission status: Accepted

Solution code:
[a,b,c,d]=list(input())
l='+-'
for i in l:
    for j in l:
        for k in l:
            t=a+i+b+j+c+k+d
            if eval(t) == 7:
                print(t+'=7')
                exit(0)

Submission status: Accepted

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

def sol() :
    for i in range(8) :
        s = S[0]
        ret = [-1] * 3
        for j in range(1,4) :
            mask = 2**(j - 1)
            op = i & mask
            if op == 0 :
                s += S[-j]
                ret[-j] = '+'
            else :
                s -= S[-j]
                ret[-j] = '-'
        if s == 7 :
            return ret
    return -1

ans = sol()

print(S[0], end='')
for i in range(3) :
    print(ans[i], end='')
    print(S[i+1], end='')
print('=7')

Submission status: Accepted

Solution code:
abcd = input()

plmi = ['+', '-']
ABCD = []
for s in abcd:
    ABCD.append(int(s))
# print(ABCD)

ans = 0
ans_l = ''
def dfs(buff, i, buff2):
    global ans
    global ans_l

    if buff == 7 and i == 4:
        ans += 1
        ans_l = buff2

    if i == 4:
        return

    dfs(buff+ABCD[i],i+1, buff2+'+')
    dfs(buff-ABCD[i],i+1, buff2+'-')


buff_l = []
dfs(ABCD[0], 1, '')
# print(ans_l)
# print(ans)
ans = ''
ans_l = list(ans_l)
for i in range(4):
    ans += str(ABCD[i])
    if i < 3:
        ans += str(ans_l[i])


print(ans+'=7')

Submission status: Accepted

Solution code:
S = input()

for i in range(1 << len(S)-1):
    f = ''
    for j in range(len(S)-1):
        f += S[j]
        if (i >> j) & 1:
            f += '+'
        else:
            f += '-'
    f += S[-1]
    if eval(f) == 7:
        ans = f + '=7'
        print(ans)
        break

Submission status: Accepted

Solution code:
S = input()

for i in range(1 << len(S)-1):
    f = ''
    for j in range(len(S)-1):
        f += S[j]
        if ((i >> j) & 1):
            f += '+'
        else:
            f += '-'
    f += S[-1]
    if eval(f) == 7:
        ans = f + '=7'
        print(ans)
        break

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
I = list(input())
I.pop()
A, B, C, D = list(map(int, I))

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:
S = input()
#文字列Sの隙間の2乗
#bit表記で0なら-,1なら+を挿入
for i in range(2**(len(S)-1)):
  x = ''
  for j in range(len(S)-1):
    x += S[j]
    if ((i>>j)&1):
      x += "+"
    else:
      x += "-"
  x += S[-1]
  if eval(x)==7:
    print(x + "=7")
    break

Submission status: Accepted

Solution code:
a=list(map(str,input()))
n=len(a)
b=[[] for i in range(2**(n-1))]
for i in range(2**(n-1)):
    for j in range(n-1):
        if ((i >> j) & 1) ==1:
            b[i].append("+")
        else:
            b[i].append("-")

for j in range(2**(n-1)):
    result = [None]*(n+n-1)
    result[::2]=a
    result[1::2]=b[j]
    ans=eval(''.join(result))
    if ans==7:
        aa=[''.join(result),"=",str(ans)]
        print(''.join(aa))
        exit()

Submission status: Accepted

Solution code:
n = input()
for i in range(2**3):
    sign = ["-"] * 3
    for j in range(3):
        if ((i >> j) & 1):
            sign[j] = "+"

    formula = n[0] + sign[0] + n[1] + sign[1] + n[2] + sign[2] + n[3]
    if eval(formula) == 7:
        print(formula+'=7')
        break

Submission status: Accepted

Solution code:
ABCD = list(map(int, input()))
a, b, c, d = ABCD[0], ABCD[1], ABCD[2], ABCD[3]
op = ['+', '-']
flag = False
for i in range(2):
    for j in range(2):
        for k in range(2):
            ans = 0
            if i == 0:
                ans = a + b
            else:
                ans = a - b
            if j == 0:
                ans += c
            else:
                ans -= c
            if k == 0:
                ans += d
            else:
                ans -= d
            if ans == 7:
                print('{}{}{}{}{}{}{}={}'.format(a,op[i],b,op[j],c,op[k],d,ans))
                flag = True
                break
        if flag:
            break
    if flag:
        break

Submission status: Accepted

Solution code:
s=input()
a=int(s[0])
b=int(s[1])
c=int(s[2])
d=int(s[3])
import sys
for i in range(8):
    j_list=[]
    op=(i>>0)&1
    if op:
        ans=a+b
        j_list.append('+')
    else:
        ans=a-b
        j_list.append('-')
    op=(i>>1)&1
    if op:
        ans+=c
        j_list.append('+')
    else:
        ans-=c
        j_list.append('-')
    op=(i>>2)&1
    if op:
        ans+=d
        j_list.append('+')
    else:
        ans-=d
        j_list.append('-')
    if ans==7:
        print(s[0]+j_list[0]+s[1]+j_list[1]+s[2]+j_list[2]+s[3]+'=7')
        sys.exit()

Submission status: Accepted

Solution code:
import itertools
l = [int(i) for i in list(str(input()))]
pm=[1,-1]
l_i=list(itertools.product(pm,repeat=3))
for i in l_i:
    tmp=l[0]
    for j in range(3):
        tmp+=i[j]*l[j+1]
    if tmp==7:
        ans=[str(l[0]),"a",str(l[1]),"a",str(l[2]),"a",str(l[3]),"=7"]
        if i[0]==1:ans[1]="+"
        else:ans[1]="-"
        if i[1]==1:ans[3]="+"
        else:ans[3]="-"
        if i[2]==1:ans[5]="+"
        else:ans[5]="-"
        print("".join(ans))
        exit()

Submission status: Accepted

Solution code:
I = input()
A, B, C, D = int(I[0]), int(I[1]), int(I[2]), int(I[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:
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

# 23:39

S = list(sys.stdin.readline().rstrip())

ans = None
for op in itertools.product('+-', repeat=len(S) - 1):
    f = S[0] + op[0] + S[1] + op[1] + S[2] + op[2] + S[3]
    if eval(f) == 7:
        ans = f + '=7'
        break
print(ans)

Submission status: Accepted

Solution code:
N = [int(el) for el in list(input())]

def result(N):
    if N[0]+N[1]+N[2]+N[3] ==7:
        print('{}+{}+{}+{}=7'.format(N[0],N[1],N[2],N[3]))
        return
    if N[0]-N[1]+N[2]+N[3]==7:
        print('{}-{}+{}+{}=7'.format(N[0],N[1],N[2],N[3]))
        return
    if N[0]+N[1]-N[2]+N[3]==7:
        print('{}+{}-{}+{}=7'.format(N[0],N[1],N[2],N[3]))
        return
    if N[0]+N[1]+N[2]-N[3]==7:
        print('{}+{}+{}-{}=7'.format(N[0],N[1],N[2],N[3]))
        return
    if N[0]-N[1]-N[2]+N[3]==7:
        print('{}-{}-{}+{}=7'.format(N[0],N[1],N[2],N[3]))
        return
    if N[0]-N[1]+N[2]-N[3]==7:
        print('{}-{}+{}-{}=7'.format(N[0],N[1],N[2],N[3]))
        return
    if N[0]+N[1]-N[2]-N[3]==7:
        print('{}+{}-{}-{}=7'.format(N[0],N[1],N[2],N[3]))
        return
    if N[0]-N[1]-N[2]-N[3]==7:
        print('{}-{}-{}-{}=7'.format(N[0],N[1],N[2],N[3]))
        return
result(N)

Submission status: Accepted

Solution code:
a=input()
for i in range(2**(len(a)-1)):
    tmp=a[0]+"".join(["+-"[i>>j&1]+k for j,k in enumerate(a[1:])])
    if eval(tmp)==7:
        print(tmp+"=7")
        break

Submission status: Accepted

Solution code:
def dfs(i, total):
    global ans
    if i == len(s):
        if eval(total) == 7:
            ans = total + "=7"
            return ans
        return 0
    dfs(i + 1, total + "+" + s[i])
    dfs(i + 1, total + "-" + s[i])

s = input()
ans = 0
dfs(1, s[0])
print(ans)

Submission status: Accepted

Solution code:
import sys

S = input()

operators = ['+', '-']

for op1 in operators:
    for op2 in operators:
        for op3 in operators:
            exp = S[0] + op1 + S[1] + op2 + S[2] + op3 + S[3]
            if eval(exp) == 7:
                print("{}{}{}{}{}{}{}=7".format(S[0], op1, S[1], op2, S[2], op3, S[3]))
                sys.exit(0)

Submission status: Accepted

Solution code:
serial = list(input())
numbers = [int(s) for s in serial]
ak = "0"
bk = "0"
ck = "0"
for ai in range(2):
    for bi in range(2):
        for ci in range(2):
            kotae = 0
            if ai == 0:
                kotae = numbers[0] + numbers[1]
            else:
                kotae = numbers[0] - numbers[1]
            if bi == 0:
                kotae = kotae + numbers[2]
            else:
                kotae = kotae - numbers[2]
            if ci == 0:
                kotae = kotae + numbers[3]
            else:
                kotae = kotae - numbers[3]

            if kotae == 7:
                ak = "+" if ai == 0 else "-"
                bk = "+" if bi == 0 else "-"
                ck = "+" if ci == 0 else "-"
print(serial[0] + ak + serial[1] + bk + serial[2] + ck + serial[3] + "=7")

Submission status: Accepted

Solution code:
def generateit(s, n):
	m = n
	ans = s[0]
	for i in range(0, 3):
		if m % 2 == 1:
			ans = ans + '+' + s[i+1]
		else:
			ans = ans + '-' + s[i+1]
		m //= 2
	return ans

S = input()
for i in range(0, 8):
	n = i
	sum = int(S[0])
	for j in range(0, 3):
		if n % 2 == 1:
			sum += int(S[j+1])
		else:
			sum -= int(S[j+1])
		n //= 2
	if sum == 7:
		print(generateit(S, i)+'=7')
		break

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    x = list(input())

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

Submission status: Accepted

Solution code:
s = input()
for i in range(1 << 3):
    S = list(s)
    total = int(s[0])
    for j in range(len(s)-1):
        if (i >> j) & 1:
            total += int(s[j+1])
            S.insert(2*j+1,"+")
        else:
            total -= int(s[j+1])
            S.insert(2*j+1,"-")
    if total == 7:
        print("".join(map(str,S))+"=7")
        break

Submission status: Accepted

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


for i in range(2**3):
    count=int(ABCD[0])
    ans=ABCD[0]
    for j in range(3):
        if i&(1<<j):
            count+=int(ABCD[j+1])
            ans+="+"
        else:
            count-=int(ABCD[j+1])
            ans+="-"
        ans+=ABCD[j+1]
    if count==7:
        ans+="=7"
        print(ans)
        quit()

Submission status: Accepted

Solution code:
from itertools import product, accumulate
S = input()

def eval_(s, pat):
    s = list(map(int, s))
    ans = s[0]
    for i in range(3):
        if pat[i] == '+':
            ans += s[i+1]
        else:
            ans -= s[i+1]
    return ans

eq = ''
for pat in product(('+', '-'), repeat=3):
    if eval_(S, pat) == 7:
        eq = S[0]
        for i in range(3):
            eq += pat[i] + S[i+1]
        break

print(eq+'=7')

Submission status: Accepted

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

a, b, c, d = map(str, input())

sign = "+-"
for i in range(2):
    for j in range(2):
        for k in range(2):
            if int(eval(a+sign[i]+b+sign[j]+c+sign[k]+d)) == 7:
                print(str(a+sign[i]+b+sign[j]+c+sign[k]+d) + "=7")
                exit()

Submission status: Accepted

Solution code:
from itertools import product
s = input()
options = product(["+", "-"], repeat=3)
for op in options:
    v = s[0]
    for i in range(3):
        v += op[i] + s[i+1]
    if eval(v) == 7:
        break
print(v+"=7")

Submission status: Accepted

Solution code:
def dfs(i, f):
    global ans
    if i == len(s) - 1:
        if eval(f) == 7:
            ans = f + "=7"
            return ans
        return 0
    dfs(i + 1, f + "+" + s[i+1])
    dfs(i + 1, f + "-" + s[i+1])
    
s = input()
ans = ""
dfs(0, s[0])
print(ans)

Submission status: Accepted

Solution code:
def calc(expression):
    result = int(expression[0])
    i = 1
    while i < len(expression):
        c = expression[i]
        if c == "+":
            i+=1
            result+=int(expression[i])
        elif c == "-":
            i+=1
            result-=int(expression[i])
        i+=1
    return result

S=input()
ex=[S[0]]

for s in S[1:]:
    tmp=ex
    ex=[]
    for e in tmp:
        ex.append(e + "+" + s)
        ex.append(e + "-" + s)

for e in ex:
    if calc(e) == 7:
        print(e+"=7")
        break

Submission status: Accepted

Solution code:
ABCD = input()
A, B, C, D = (int(ABCD[i]) for i in range(4))
op = ['+', '-']
for i in range(2):
    if i == 0:
        W = A + B
    else:
        W = A - B
    for j in range(2):
        if j == 0:
            X = W + C
        else:
            X = W - C
        for k in range(2):
            if k == 0:
                Y = X + D
            else:
                Y = X - D
            if Y == 7:
                print(A, op[i], B, op[j], C, op[k], D, '=7', sep='')
                exit()

Submission status: Accepted

Solution code:

N = input()

for i in range(2 ** 3):

    ops = format(i,"b")
    ops = ops.zfill(3)

    op_lis = []

    for j in ops:

        if j == "0":
            op_lis.append(1)
        else:
            op_lis.append(-1)

    if int(N[0]) + op_lis[0] * int(N[1]) +op_lis[1] * int(N[2]) + op_lis[2] * int(N[3]) == 7:

        ans = N[0]

        for k in range(len(op_lis)):
            if op_lis[k] == 1:
                ans += "+"
            else:
                ans += "-"

            ans += N[k+1]

        ans += "=7"

        print (ans)
        break

Submission status: Accepted

Solution code:
s = input()
abcd = [int(s[0]),int(s[1]),int(s[2]),int(s[3])]
mark = ['-','+']
for i in range(1 << 3):
    alla = abcd[0]
    i2 = format(i,'03b')
    for j in range(3):
        if i2[2 - j] == '0':#0 = -
            alla -= abcd[3 - j]
        else:
            alla += abcd[3 - j]
    if alla == 7:
        print(s[0] + mark[int(i2[0])] + s[1] + mark[int(i2[1])] + s[2] + mark[int(i2[2])] + s[3] + '=7')
        exit()

Submission status: Accepted

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

op_cnt = 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] = "+"
    ans = A + op[0] + B + op[1] + C + op[2] + D
    if eval(ans) == 7:
        print(ans + "=7")
        break

Submission status: Accepted

Solution code:
import sys
def solve(l, r):
	if r == "":
		if eval(l) == 7:
			print(l + "=7")
			sys.exit()
	else:
		solve(l + "+" + r[0], r[1:])
		solve(l + "-" + r[0], r[1:])

s = input()
solve(s[0], s[1:])

Submission status: Accepted

Solution code:
import itertools
s = list(input())

for x in itertools.product(["-", "+"], repeat = 3):
	ans = s[0] + x[0] + s[1] + x[1] + s[2] + x[2] + s[3]
	if eval(ans) == 7:
		print(ans + "=7")
		break

Submission status: Accepted

Solution code:
import itertools

A, B, C, D = input()
for p in itertools.product(['+', '-'], repeat = 3):
    equ = A + p[0] + B + p[1] + C + p[2] + D
    
    if(eval(equ) == 7):
        print(equ + '=7')
        break

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

ABCD = S()

for i in range(1<<3):
    tmp = 0
    bit = i

    for j in range(3):
        if (bit & 1):
            tmp += int(ABCD[-j-1])
        else:
            tmp -= int(ABCD[-j-1])
        bit >>= 1
        
    tmp += int(ABCD[0])
    if (tmp == 7):
        ans = i
        break


operands = []
for i in range(3):
    if (ans & 1):
        operands.append("+")
    else:
        operands.append("-")
    ans >>= 1

for i, ope in enumerate(operands[::-1]):
    print(ABCD[i], end="")
    print(ope, end="")
print(ABCD[3], end="")
print("=7")

Submission status: Accepted

Solution code:
from sys import stdin
input=stdin.readline().rstrip()
input_list=list(input)
n=len(input_list)-1

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

Submission status: Accepted

Solution code:
s = input();
count1 = 0;
for i in range(8) :
	if i < 4 :
		op1 = '+';
	else :
		op1 = '-';
	
	if count1 % 2 == 0 :
		op2 = '+';
	else :
		op2 = '-';
	
	if i % 2 == 0 :
		op3 = '+';
	else :
		op3 = '-';
		count1 += 1;
	
	ans = s[0] + op1 + s[1] + op2 + s[2] + op3 + s[3];
	if eval(ans) == 7 :
		print(ans+'=7');
		break;

Submission status: Accepted

Solution code:
# bit全探索ver
s=list(input())
n=len(s)-1

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

Submission status: Accepted

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

pm=['-','+']

def calc():
    for i in pm :
        for j in pm:
            for k in pm:
                s=a+i+b+j+c+k+d
                total=eval(s)
                if total==7:
                    return s+'='+str(total)

print(calc())

Submission status: Accepted

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

# パターン数
for i in range(2**(n-1)):
    
    exp = s[0]

    # 右シフトする
    for j in range(1, n):
        if (i >> j-1) & 1:
            exp += '+'
        else:
            exp += '-'
        
        exp += s[j]

    if eval(exp) == 7:
        print('{}=7'.format(exp))
        exit()

Submission status: Accepted

Solution code:
# うまいことやる せいぜいopは2^3なので愚直にやってもいいけど
# evalを使ってもいいけどevilなので使わない方針

a, b, c, d = list(map(int, list(input())))
op1, op2, op3 = [True, False], [True, False], [True, False]
for o1 in op1:
    for o2 in op2:
        for o3 in op3:
            ab = a + b if o1 else a - b
            abc = ab + c if o2 else ab - c
            abcd = abc + d if o3 else abc - d
            if abcd == 7:
                opr1 = "+" if o1 else "-"
                opr2 = "+" if o2 else "-"
                opr3 = "+" if o3 else "-"
                print("{}{}{}{}{}{}{}=7".format(a, opr1, b, opr2, c, opr3, d))
                exit()

Submission status: Accepted

Solution code:
A = list(map(int, input()))
signs = [None] * 3
for b in range(1 << 3):
    sum = A[0]
    for i in range(3):
        if (b & (1 << i)) != 0:
            signs[i] = '+'
            sum += A[i + 1]
        else:
            signs[i] = '-'
            sum -= A[i + 1]
    if sum == 7:
        break
result = [None] * (4 + 3 + 2)
result[:4*2:2] = map(str, A)
result[1:1+3*2:2] = signs
result[-2:] = "=7"
print("".join(result))

Submission status: Accepted

Solution code:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

A, B, C, D = [int(v) for v in list(s())]

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:
s = str(input())
for i in range(0,8):
    if i//4%2==0:
        x = "+"
    else:
        x = "-"
    if i//2%2==0:
        y = "+"
    else:
        y = "-"
    if i%2==0:
        z = "+"
    else:
        z = "-"
    ans = s[0]+x+s[1]+y+s[2]+z+s[3]
    if eval(ans)==7:
        print(ans+"=7")
        exit()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

s = 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()
n = 3
t=[]
for i in range(1<<n):
    ans = int(s[0])
    k=1
    for j in range(n):
        if 1&(i>>j):
            ans += int(s[k:(j+2)])
            t.append("+")
        else: 
            ans -= int(s[k:(j+2)]) 
            t.append("-")
        k=j+2
    if ans==7:
        print(s[0]+t[0]+s[1]+t[1]+s[2]+t[2]+s[3]+"=7")
        break;
    ans = int(s[0])
    t=[]

Submission status: Accepted

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

Submission status: Accepted

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

def op(op_str):
    funcs = {
            "+":operator.add,
            "-":operator.sub
            }
    return funcs[op_str]

def solve(A,B,C,D):
    for o in itertools.product(["+","-"], repeat = 3):
        ret = op(o[0])(A,B)
        ret = op(o[1])(ret,C)
        ret = op(o[2])(ret,D)
        if ret == 7:
            print("{0}{1}{2}{3}{4}{5}{6}=7".format(A,o[0],B,o[1],C,o[2],D))
            return


    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    S = input()
    L = [int(c) for c in S]
    
    solve(*L)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
ABCD  = list(input())
n = len(ABCD)
ans = 0

for i in range(2 ** (n-1)):

    list = ABCD[0]

    # iをj-1ビット右シフトして1だったら+を入れるのを繰り返す
    # 1の数が+の数になる
    for j in range(1, n):

        if (i >> (j - 1)) & 1:

            list = list + "+" + ABCD[j]
            # print(i >> (j-1))

        else:
            list = list + "-" + ABCD[j]


    if eval(list) == 7:
        print(list,"=7",sep='')
        exit()

Submission status: Accepted

Solution code:
a = [int(x) for x in list(input())]
op = 3
ops = [0] * op
for i in range(2 ** op):
    result = a[0]
    bry = list(format(i, "0{}b".format(op)))
    for index, value in enumerate(bry):
        if value == "1":
            result += a[index + 1]
            ops[index] = "+"
        else:
            result -= a[index + 1]
            ops[index] = "-"
    if result == 7:
        ans = str(a[0])
        for j in range(3):
            ans += "{}{}".format(ops[j], a[j+1])
        ans += "=7"
        print(ans)
        break

Submission status: Accepted

Solution code:
s = input()
a, b, c, d = s[0], s[1], s[2], s[3]
for op1 in "+-":
  for op2 in "+-":
    for op3 in "+-":
      f = a+op1+b+op2+c+op3+d
      if eval(f)==7:
        print(f+"=7")
        exit()

Submission status: Accepted

Solution code:
ABCD=input()
A,B,C,D=int(ABCD[0]),int(ABCD[1]),int(ABCD[2]),int(ABCD[3])
a,b,c,d,e,f,g,h=A+B+C+D,A+B+C-D,A+B-C+D,A-B+C+D,A+B-C-D,A-B+C-D,A-B-C+D,A-B-C-D
if a==7:print(str(A)+"+"+str(B)+"+"+str(C)+"+"+str(D)+"=7")
elif b==7:print(str(A)+"+"+str(B)+"+"+str(C)+"-"+str(D)+"=7")
elif c==7:print(str(A)+"+"+str(B)+"-"+str(C)+"+"+str(D)+"=7")
elif d==7:print(str(A)+"-"+str(B)+"+"+str(C)+"+"+str(D)+"=7")
elif e==7:print(str(A)+"+"+str(B)+"-"+str(C)+"-"+str(D)+"=7")
elif f==7:print(str(A)+"-"+str(B)+"+"+str(C)+"-"+str(D)+"=7")
elif g==7:print(str(A)+"-"+str(B)+"-"+str(C)+"+"+str(D)+"=7")
else:print(str(A)+"-"+str(B)+"-"+str(C)+"-"+str(D)+"=7")

Submission status: Accepted

Solution code:
s=input()
for i in range(2):
    for j in range(2):
        for k in range(2):
            t=int(s[0])
            ans=s[0]
            if i:
                t+=int(s[1])
                ans+='+'+s[1]
            else:
                t-=int(s[1])
                ans+='-'+s[1]
            if j:
                t+=int(s[2])
                ans+='+'+s[2]
            else:
                t-=int(s[2])
                ans+='-'+s[2]
            if k:
                t+=int(s[3])
                ans+='+'+s[3]
            else:
                t-=int(s[3])
                ans+='-'+s[3]
            if t==7:
                print(ans+'=7')
                exit()

Submission status: Accepted

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

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

for l in Bit:
    seven = In[0]
    for i, bit in enumerate(l):
        if bit == '+':
            seven += In[i+1]
        else:
            seven -= In[i+1]
    if seven == 7:
        print("{}{}{}{}{}{}{}=7".format(In[0],l[0],In[1],l[1],In[2],l[2],In[3]))
        break

Submission status: Accepted

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

if int(a)+int(b)+int(c)+int(d) is 7:
  print(a+"+"+b+"+"+c+"+"+d+"=7")
elif int(a)+int(b)+int(c)-int(d) is 7:
  print(a+"+"+b+"+"+c+"-"+d+"=7")
elif int(a)+int(b)-int(c)+int(d) is 7:
  print(a+"+"+b+"-"+c+"+"+d+"=7")
elif int(a)+int(b)-int(c)-int(d) is 7:
  print(a+"+"+b+"-"+c+"-"+d+"=7")
elif int(a)-int(b)+int(c)+int(d) is 7:
  print(a+"-"+b+"+"+c+"+"+d+"=7")
elif int(a)-int(b)+int(c)-int(d) is 7:
  print(a+"-"+b+"+"+c+"-"+d+"=7")
elif int(a)-int(b)-int(c)+int(d) is 7:
  print(a+"-"+b+"-"+c+"+"+d+"=7")
elif int(a)-int(b)-int(c)-int(d) is 7:
  print(a+"-"+b+"-"+c+"-"+d+"=7")

Submission status: Accepted

Solution code:
# coding: utf-8
ll = list(map(int, list(input())))
pm = ["+", "-"]
for i in range(2):
    for j in range(2):
        for k in range(2):
            ans = ll[0] + ll[1]*(-1)**i + ll[2]*(-1)**j + ll[3]*(-1)**k
            # print(ans)
            # print(ll[0], pm[i], ll[1], pm[j], ll[2], pm[k], ll[3])
            if ans == 7:
                print("{}{}{}{}{}{}{}=7".format(ll[0], pm[i], ll[1], pm[j], ll[2], pm[k], ll[3]))
                exit()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
a,b,c,d=map(int,input())
flg=0
p=[1,-1]

for i in range(2):
    for j in range(2):
        for k in range(2):
            if a+p[i]*b+p[j]*c+p[k]*d==7:
                if p[i]>0:
                    p1="+"
                else:
                    p1="-"
                    
                if p[j]>0:
                    p2="+"
                else:
                    p2="-"
                    
                if p[k]>0:
                    p3="+"
                else:
                    p3="-"
                
                
                print("%d%s%d%s%d%s%d=7"%(a,p1,b,p2,c,p3,d))
                exit()

Submission status: Accepted

Solution code:
#ABC79-C
box=input()
l=len(box)
for i in range(pow(2,(l-1))):
    num=box[0]
    for j in range(1,l): #1～(l-1)
        if (i>>(j-1))&1:
            num+="+"+box[j]
        else:
            num+="-"+box[j]
    if eval(num)==7:
        print(num+"=7")
        break