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 math
import sys
input = sys.stdin.readline

abcd = int(input())
for i in range(int(4-math.log10(abcd))):
    abcd = '0'+str(abcd)
a, b, c, d = str(abcd)
a = int(a);b = int(b);c = int(c);d = int(d)
if a+b+c+d == 7:
    a = str(a);b = str(b);c = str(c);d = str(d)
    ans = a+'+'+b+'+'+c+'+'+d+'=7'
elif a+b+c-d == 7:
    a = str(a);b = str(b);c = str(c);d = str(d)
    ans = a+'+'+b+'+'+c+'-'+d+'=7'
elif a+b-c-d == 7:
    a = str(a);b = str(b);c = str(c);d = str(d)
    ans = a+'+'+b+'-'+c+'-'+d+'=7'
elif a+b-c+d == 7:
    a = str(a);b = str(b);c = str(c);d = str(d)
    ans = a+'+'+b+'-'+c+'+'+d+'=7'
elif a-b+c+d == 7:
    a = str(a);b = str(b);c = str(c);d = str(d)
    ans = a+'-'+b+'+'+c+'+'+d+'=7'
elif a-b+c-d == 7:
    a = str(a);b = str(b);c = str(c);d = str(d)
    ans = a+'-'+b+'+'+c+'-'+d+'=7'
elif a-b-c+d == 7:
    a = str(a);b = str(b);c = str(c);d = str(d)
    ans = a+'-'+b+'-'+c+'+'+d+'=7'
else:
    a = str(a);b = str(b);c = str(c);d = str(d)
    ans = a+'-'+b+'-'+c+'-'+d+'=7'
print(ans)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

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

  for i in range(2):
    for j in range(2):
      for k in range(2):
        a=b=c=''
        if i==0:
          a='+'
        else:
          a='-'
        if j==0:
          b='+'
        else:
          b='-'
        if k==0:
          c='+'
        else:
          c='-'
        x=l[0]+a+l[1]+b+l[2]+c+l[3]
        ans=eval(x)

        if ans==7:
          return x+'=7'

print(main())

Submission status: Accepted

Solution code:
numbers=list(map(int,list(input())))
ansLst=[]
def count(i,opes,sum):
    if i == 4:
        if sum == 7:
            ansLst.append(str(numbers[0])+opes[0]+str(numbers[1])+opes[1]+str(numbers[2])+opes[2]+str(numbers[3])+"=7")
    else:
        count(i+1,opes+["+"],sum+numbers[i])
        count(i+1,opes+["-"],sum-numbers[i])
count(1,[],numbers[0])
print(ansLst[0])

Submission status: Accepted

Solution code:
s = input()

for i in range(8):
	if i % 2 == 0:
		ope1 = "+"
	else:
		ope1 = "-"
	i //= 2
	if i % 2 == 0:
		ope2 = "+"
	else:
		ope2 = "-"
	i //= 2
	if i % 2 == 0:
		ope3 = "+"
	else:
		ope3 = "-"
	
	ans = s[0]+ope1+s[1]+ope2+s[2]+ope3+s[3]

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

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
inp = list(input())

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

for i in range(2**3):
    sum = A
    ans = str(A)

    op1 = (i >> 2) & 1
    if op1 == 1:
        sum += B
        ans += '+'+str(B)
    else:
        sum -= B
        ans += '-'+str(B)

    op2 = (i >> 1) & 1
    if op2 == 1:
        sum += C
        ans += '+'+str(C)
    else:
        sum -= C
        ans += '-'+str(C)

    op3 = i & 1
    if op3 == 1:
        sum += D
        ans += '+'+str(D)
    else:
        sum -= D
        ans += '-'+str(D)

    if sum == 7:
        print(ans + '=7')
        exit()

Submission status: Accepted

Solution code:
ABCDpre = input()
ABCD = [i for i in ABCDpre]
op = ["-","-","-"]
for i in range(1 << 3):
    for j in range(3):
        if ((i >> j) & 1) == 1:
            op[j] = "+"
    if eval(ABCD[0]+op[0]+ABCD[1]+op[1]+ABCD[2]+op[2]+ABCD[3]) == 7.0:
        print(ABCD[0]+op[0]+ABCD[1]+op[1]+ABCD[2]+op[2]+ABCD[3]+"=7")
        exit()
    op = ["-","-","-"]

Submission status: Accepted

Solution code:
ABCD = list(input())
OP = (('+', '-'), ('+', '-'), ('+', '-'))
N = len(OP)
ans = 0

for i in range(2 ** N):
    op123 = ['+'] * 3
    for j in range(N):
        if ((i >> j) & 1):
            op123[j] = OP[j][1]
    ans = ABCD[0]+op123[0]+ABCD[1]+op123[1]+ABCD[2]+op123[2]+ABCD[3]
    if eval(ans) == 7:
        ans += '=7'
        break

print(ans)

Submission status: Accepted

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

op = []
for i in range(2**o):
    op = ["-", "-", "-"]
    for j in range(o):
        if (i >> j) & 1:
            op[o - 1 - j] = "+"
    
    sum = n[0]
    for m, s in zip(n[1:], op):
        if s == "+":
            sum += m
        else:
            sum -= m

    if sum == 7:
        break

ns = [str(x) for x in n]
res = ns[0]
for x,y in zip(op, ns[1:]):
    res += x + y

print(res + "=7")

Submission status: Accepted

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

for op1 in ["+", "-"]:
    for op2 in ["+", "-"]:
        for op3 in ["+", "-"]:
            sum_ = a
            if op1 == "+":
                sum_ += b
            else:
                sum_ -= b
            if op2 == "+":
                sum_ += c
            else:
                sum_ -= c
            if op3 == "+":
                sum_ += d
            else:
                sum_ -= d
            if sum_ == 7:
                ans = "{}{}{}{}{}{}{}=7".format(a, op1, b, op2, c, op3, d)
        if sum_ == 7:
            break
    if sum_ == 7:
        break
print(ans)

Submission status: Accepted

Solution code:
nums = input()

for i in range(8):
    sum = int(nums[0])
    S = nums[0]
    for j in range(3):
        if ((i>>j) & 1):
            sum += int(nums[j+1])
            S += '+' + nums[j+1]
        else:
            sum -= int(nums[j+1])
            S += '-' + nums[j+1]
    if sum == 7:
        print(S+'=7')
        break

Submission status: Accepted

Solution code:
ABCD = input()

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

Submission status: Accepted

Solution code:
A,B,C,D = list(input())
import itertools
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
    
answer = eq + '=7'
print(answer)

Submission status: Accepted

Solution code:
abcd = input()
n = 3

for i in range(2**n):
    num = []
    bi = format(i, '03b')
    for j in range(n):
        num.append(abcd[j])
        if bi[j] == '0':
            num.append('+')
        else:
            num.append('-')
    num.append(abcd[-1])
    calc = ''.join(num)
    if eval(calc) == 7:
        break

print(str(calc)+'=7')

Submission status: Accepted

Solution code:
from sys import stdin
s = stdin.readline().rstrip()
A, B, C, D = int(s[0]), int(s[1]), int(s[2]), int(s[3])
if A + B + C + D == 7:
    print('{}+{}+{}+{}=7'.format(A, B, C, D))
    exit()
elif A + B + C - D == 7:
    print('{}+{}+{}-{}=7'.format(A, B, C, D))
    exit()
elif A + B - C + D == 7:
    print('{}+{}-{}+{}=7'.format(A, B, C, D))
    exit()
elif A + B - C - D == 7:
    print('{}+{}-{}-{}=7'.format(A, B, C, D))
    exit()
elif A - B - C + D == 7:
    print('{}-{}-{}+{}=7'.format(A, B, C, D))
    exit()
elif A - B - C - D == 7:
    print('{}-{}-{}-{}=7'.format(A, B, C, D))
    exit()
elif A - B + C + D == 7:
    print('{}-{}+{}+{}=7'.format(A, B, C, D))
    exit()
elif A - B + C - D == 7:
    print('{}-{}+{}-{}=7'.format(A, B, C, D))
    exit()

Submission status: Accepted

Solution code:
import itertools
p=list(input())#HYF#MXwxNTY2OTA1OTN8eyJjaGFubmVsSWQiOiJ3YXAwMDIifQ==
s=[int(x) for x in p]
for x in itertools.product(['+','-'],repeat=3):
	t=s[0]
	for i in range(3):
		t=t+s[i+1] if x[i]=='+' else t-s[i+1]
	if t==7:
		ans=x
		break
for i in range(3):
	p.insert(2*i+1,ans[i])
print(''.join(p)+'=7')

Submission status: Accepted

Solution code:
S = input()

pn = ['-', '+']
for i in range(2 ** (len(S) - 1)):
#    print(bin(i))
    tmp = int(S[0])
    for j in range(len(S) - 1):
        if i >> j & 1 == 1:
            tmp += int(S[j+1])
        else:
            tmp -= int(S[j+1])
#    print(tmp)
    if tmp == 7:
        ans = S[0]
        for j in range(len(S)-1):
            ans += pn[i>>j&1] + S[j+1]
        print(ans + '=7')
        quit()

Submission status: Accepted

Solution code:
import numpy as np

s = [w for w in input()]
length = len(s)

for i in range(2 ** (length-1)):
    b = format(i, 'b')
    b_len = len(b)
    pad_width = ((length-1) - b_len, 0)
    b_pad = np.pad([int(n) for n in b], pad_width, 'constant')
    score = int(s[0])
    result = s[0]
    for flag, num in zip(b_pad, s[1:]):
        if flag == 1:
            score += int(num)
            result += '+' + num
        else:
            score -= int(num)
            result += '-' + num

    if score == 7:
        print(result+'=7')
        break

Submission status: Accepted

Solution code:
def bi(x, length):
    ret = "".join(["0" for _ in range(length)])
    return (ret + str(bin(x))[2:])[-length:]


def solve(inp):
    l = len(inp) - 1
    for i in range(2 ** l):
        binary = bi(i, l)
        tot = int(inp[0])
        for j in range(l):
            if binary[j] == "1":
                tot += int(inp[j+1])
            else:
                tot -= int(inp[j+1])
        if tot == 7:
            return ''.join([inp[j] + "+" if binary[j] == "1" else inp[j] + "-" for j in range(l)] + [inp[-1] + "=7"])

inp = input()

print(solve(str(inp)))

Submission status: Accepted

Solution code:
S = input()
A, B, C, D = S[0], S[1], S[2], S[3]
ope = ["+++", "+-+", "++-", "+--", "-++", "--+", "-+-", "---"]


for i in range(8):
    ope1 = ope[i][0]
    ope2 = ope[i][1]
    ope3 = ope[i][2]
    val = A + ope1 + B + ope2 + C + ope3 + D
    if eval(val) == 7:
        ans = val + "=7"
        break


print(ans)

Submission status: Accepted

Solution code:
s = input()
A, B, C, D = s[0], s[1], s[2], s[3]
op = ["+++", "+-+", "++-", "+--", "-++", "--+", "-+-", "---"]


for i in range(8):
    op1 = op[i][0]
    op2 = op[i][1]
    op3 = op[i][2]
    e = A + op1 + B + op2 + C + op3 + D
    if eval(e) == 7:
        ans = e + "=7"
        break


print(ans)

Submission status: Accepted

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

for i in range(2**3):
  ans = tick[0]
  op = []
  for j in range(3):
    if (i >> j) & 1:
      op.append("+")
      ans += tick[j+1]
    else:
      op.append("-")
      ans -= tick[j+1]
  if ans == 7:
    print(tick[0], op[0], tick[1], op[1], tick[2], op[2], tick[3], "=7", sep="")
    exit()

Submission status: Accepted

Solution code:
def main():
    A, B, C, D = input()
    for ab in ['+', '-']:
        for bc in ['+', '-']:
            for cd in ['+', '-']:
                if eval(A + ab + B + bc + C + cd + D) == 7:
                    print(A + ab + B + bc + C + cd + D + '=7')
                    return


main()

Submission status: Accepted

Solution code:
strs = list(input())

nums = list(map(int, strs))

op_patterns = []

ops = ['+', '-']

for op1 in ops:
    for op2 in ops:
        for op3 in ops:
            op_patterns.append((op1, op2, op3))


for pat in op_patterns:
    express = '{}{}{}{}{}{}{}'.format(nums[0], pat[0], nums[1], pat[1], nums[2], pat[2], nums[3])
    result = eval(express)

    if result == 7:
        print(express + '=7')
        exit()

Submission status: Accepted

Solution code:
from itertools import product
x=[a for a in input()]
a=('+','-')
s=list(product(a,repeat=3))
for op in s:
     ops=x[0]+op[0]+x[1]+op[1]+x[2]+op[2]+x[3]
     if eval(ops)==7:
          print(ops+'=7')
          break

Submission status: Accepted

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

d = []
for i in range(0,8):
  x = str(format(i,'b'))
  x = x.zfill(3) #1が”＋”とする
  d.append(x)
#print(a,d)
ans = 0
for i in d:
  c = a[0] #チェッカー
  for j in range(3):
    if i[j] == "0":
      c -= a[j+1]
    elif i[j] == "1":
      c += a[j+1]
  if c == 7:
    ans = i
    break
b = [0]*3    
for i in range(3):
  if ans[i] == "0":
    b[i] = "-"
  else:
    b[i] = "+"
print("{}{}{}{}{}{}{}=7".format(a[0],b[0],a[1],b[1],a[2],b[2],a[3]))

Submission status: Accepted

Solution code:
from itertools import product

A, B, C, D = [x for x in input().strip()]

for x in ["".join(x) for x in product(A, '+-', B, '+-', C, '+-', D)]:
    if eval(x) == 7:
        print(x+"=7")
        break

Submission status: Accepted

Solution code:
a,b,c,d=input()
o='+-- -'
for i in range(8):
 s=a+o[i&1]+b+o[i&2]+c+o[i&4]+d
 if eval(s)==7:print(s+'=7');break

Submission status: Accepted

Solution code:
a,b,c,d=input()
o='+-- -'
for i in range(8):
 s=a+o[i&1]+b+o[i&2]+c+o[i&4]+d
 if eval(s)==7:print(s+'=7');exit()

Submission status: Accepted

Solution code:
a,b,c,d=input()
o='+-'
for i in range(8):
 s=a+o[i&1]+b+o[i&2>0]+c+o[i&4>0]+d
 if eval(s)==7:print(s+'=7');exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(ABCD: str):
    A, B, C, D = map(int, ABCD)
    for op1 in [1, -1]:
        for op2 in [1, -1]:
            for op3 in [1, -1]:
                if A+op1*B+op2*C+op3*D == 7:
                    op1 = "+" if op1 == 1 else "-"
                    op2 = "+" if op2 == 1 else "-"
                    op3 = "+" if op3 == 1 else "-"
                    print("{}{}{}{}{}{}{}=7".format(A, op1, B, op2, C, op3, D))
                    return
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    ABCD = str(next(tokens))  # type: int
    solve(ABCD)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools
S = input()
op = ['+','-']

for o1,o2,o3 in itertools.product(op,repeat=3):
    formula = S[0]+o1+S[1]+o2+S[2]+o3+S[3]
    result = eval(formula)
    if result == 7:
        print(formula+"=7")
        break

Submission status: Accepted

Solution code:
MAX_DIGIT = 4

N = int(input())
num = []

n = N
for i in range(MAX_DIGIT)[::-1]:
    num.append(int(n % 10))
    n /= 10
num.reverse()

for i in range(1 << (MAX_DIGIT - 1)):
    s = num[0]
    ans = str(num[0])
    for j in range(MAX_DIGIT - 1):
        if i >> j & 1 == 1:
            s += num[j + 1]
            ans = ans + "+" + str(num[j + 1])
        else:
            s -= num[j + 1]
            ans = ans + "-" + str(num[j + 1])
    if s == 7:
        print(ans + "=7")
        exit()

Submission status: Accepted

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

s = [(ABCD[0], str(ABCD[0]), ABCD[1:])]
while s:
	acc, exp, nums = s.pop()
	if acc == 7 and len(nums) == 0:
		print(exp + "=7")
		break
	elif len(nums) == 0:
		continue
		

	if len(nums) == 1:
		next_nums = []
	else:
		next_nums = nums[1:]
	s.append((acc + nums[0], exp+"+"+str(nums[0]), next_nums))
	s.append((acc - nums[0], exp+"-"+str(nums[0]), next_nums))

Submission status: Accepted

Solution code:
# 蟻本2-1-1相当
# 今回は再帰で解く

import sys
s = input()
def answer(value, formula, remain):
  if len(remain) == 1:
    if value + int(remain) == 7:
      print(formula + "+" + remain + "=7")
      sys.exit(0)
    elif value - int(remain) == 7:
      print(formula + "-" + remain + "=7")
      sys.exit(0)
  else:
    answer(value + int(remain[0]), formula + "+" + remain[0], remain[1:])
    answer(value - int(remain[0]), formula + "-" + remain[0], remain[1:])

answer(int(s[0]), s[0], s[1:])

Submission status: Accepted

Solution code:
s = input()
num = [ int(i) for i in s]

for i in range(2):
    for j in range(2):
        for k in range(2):
            ans = str(num[0])
            val = num[0]
            if i == 0:
                ans += "+"
                val += num[1]
            else:
                ans += "-"
                val -= num[1]
            ans += str(num[1])
            if j == 0:
                ans += "+"
                val += num[2]
            else:
                ans += "-"
                val -= num[2]
            ans += str(num[2])
            if k == 0:
                ans += "+"
                val += num[3]
            else:
                ans += "-"
                val -= num[3]
            ans += str(num[3])
            if val == 7:
                print(ans + "=7")
                exit(0)

Submission status: Accepted

Solution code:
def calculate(A,B,C,D):
    if A+B+C+D == 7:
        return (str(A)+"+"+str(B)+"+"+str(C)+"+"+str(D)+"=7")
    if A+B+C-D == 7:
        return (str(A)+"+"+str(B)+"+"+str(C)+"-"+str(D)+"=7")
    if A+B-C+D == 7:
        return (str(A)+"+"+str(B)+"-"+str(C)+"+"+str(D)+"=7")
    if A-B+C+D == 7:
        return (str(A)+"-"+str(B)+"+"+str(C)+"+"+str(D)+"=7")
    if A+B-C-D == 7:
        return (str(A)+"+"+str(B)+"-"+str(C)+"-"+str(D)+"=7")
    if A-B-C+D == 7:
        return (str(A)+"-"+str(B)+"-"+str(C)+"+"+str(D)+"=7")
    if A-B+C-D == 7:
        return (str(A)+"-"+str(B)+"+"+str(C)+"-"+str(D)+"=7")
    if A-B-C-D == 7:
        return (str(A)+"-"+str(B)+"-"+str(C)+"-"+str(D)+"=7")
    
ABCD = input()
A = int(ABCD[0])
B = int(ABCD[1])
C = int(ABCD[2])
D = int(ABCD[3])

ans = calculate(A,B,C,D)
print(ans)

Submission status: Accepted

Solution code:
num = list(map(int,list(input())))
for i in range(2**3):
    ans = num[0]
    siki = str(num[0])
    for h in range(3):
        if ((i>>h)&1):
            ans += num[h+1]
            siki += ('+'+str(num[h+1]))
        else:
            ans -= num[h+1]
            siki += ('-'+str(num[h+1]))
    if ans == 7:
        print(siki+'=7')
        break

Submission status: Accepted

Solution code:
N=input()
for i in range(8):
    S = ([["+","-"][(i>>j)&1] for j in range(3)])
    seq=N[0]+S[0]+N[1]+S[1]+N[2]+S[2]+N[3]
    if eval(seq)==7:
        print(seq+"=7")
        break

Submission status: Accepted

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


def solve(ABCD: str):
    l = list(str(ABCD))
    ope =('+', '-')

    import itertools
    for i in itertools.product(ope, repeat=3):
        t = int(l[0])
        tl = []
        tl.append(l[0])
        for j,x in enumerate(i):
            tl.append(x)
            tl.append(l[j+1])
            if(i[j] == '+'):
                t += int(l[j+1])
            else:
                t -= int(l[j+1])

        # print(tl)
        if(t == 7):
            tl.append('=7')
            # print(tl)
            print(''.join(map(str,tl)))
            sys.exit()

    l = list(map(int, l))
    print('%d+%d+%d+%d=7' % (l[0], l[1], l[2], l[3]))

    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():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    ABCD = str(next(tokens))  # type: int
    solve(ABCD)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    s = input()
    abcd = [int(s[i:i+1]) for i in range(len(s))]
    op_n = len(abcd) - 1

    for i in range(2 ** op_n):
        operator = ["-"] * op_n
        for j in range(op_n):
            if ((i >> j) & 1):
                operator[(op_n - 1) -j ] = "+"

        ans = [0] * (len(abcd) + 1)
        formula = "{}+".format(ans[0])
        for k in range(len(abcd)):
            if k == 0:
                ans[k+1] = (ans[k] + abcd[k])
                formula += str(abcd[k])
            else:
                ans[k+1] = add_or_sub(ans[k], abcd[k], operator[k-1])
                formula += (operator[k-1] + str(abcd[k]))

        if ans[len(abcd)] == 7:
            print(formula[2:] + "=7")
            break

def add_or_sub(num1, num2, op):
    if op == "+":
        return num1 + num2
    else:
        return num1 - num2

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = input()
a = [int(c) for c in s]

for i in range(2**3):
    op = [0,0,0]
    sum = a[0]
    for j in range(3):
        if ((i >> j) & 1):
            op[-1-j] = 1
            sum += a[-1-j]
        else:
            sum -= a[-1-j]
    #print(sum)
    if sum == 7:
        string = str(a[0])
        for idx, k in enumerate(op):
            if k == 1:
                string += '+'
            else:
                string += '-'
            string += str(a[idx+1])
        string += '=7'

print(string)

Submission status: Accepted

Solution code:
s = input()
for i in range(8):
    y = ''.join([s[k] + '+-'[i >> k & 1] for k in range(3)] + [s[-1]])
    if eval(y) == 7:
        print(y+'=7')
        break

Submission status: Accepted

Solution code:
a, b, c, d = map(int, input())
ans = ''
if a + b + c + d == 7:
    ans = '{}+{}+{}+{}=7'
elif a - b + c + d == 7:
    ans = '{}-{}+{}+{}=7'
elif a + b - c + d == 7:
    ans = '{}+{}-{}+{}=7'
elif a + b + c - d == 7:
    ans = '{}+{}+{}-{}=7'
elif a - b - c + d == 7:
    ans = '{}-{}-{}+{}=7'
elif a + b - c - d == 7:
    ans = '{}+{}-{}-{}=7'
elif a - b + c - d == 7:
    ans = '{}-{}+{}-{}=7'
elif a - b - c - d == 7:
    ans = '{}-{}-{}-{}=7'
    
print(ans.format(a, b, c, d))

Submission status: Accepted

Solution code:
import itertools

s = input()

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

comb = []

for i in itertools.product([1,0],repeat=3):
    comb.append(i)
    
for i in range(8):
    if comb[i][0] == 1:
        x = a+b
    
    if comb[i][0] == 0:
        x = a-b
    
    if comb[i][1] == 1:
        x += c
    
    if comb[i][1] == 0:
        x -= c
    
    if comb[i][2] == 1:
        x += d
    
    if comb[i][2] == 0:
        x -= d
    
    if x == 7:
        ans_comb = comb[i]
        break

if ans_comb[0] == 1:
    x_1 = '+'

if ans_comb[0] == 0:
    x_1 = '-'
    
if ans_comb[1] == 1:
    x_2 = '+'

if ans_comb[1] == 0:
    x_2 = '-'

if ans_comb[2] == 1:
    x_3 = '+'

if ans_comb[2] == 0:
    x_3 = '-'
    
print(str(a)+x_1+str(b)+x_2+str(c)+x_3+str(d)+'=7')

Submission status: Accepted

Solution code:
S = input()

length = len(S) - 1
ans = 0

for i in range(2 ** length):
    bit = bin(i)[2:].zfill(length)
    T = ""
    for j in range(len(S)):
        if j == 0:
            T += S[j]
            continue
        else:
            b = bit[j-1]
            if b == "1":
                T += "+"
            else:
                T += "-"
            T += S[j]
    if eval(T) == 7:
        print(T+"=7")
        exit()

Submission status: Accepted

Solution code:
N=list(input())
l=len(N)-1
for n in range(2**l):
    lis=list(format(n,'b'))
    list(map(int,lis))
    nagasa=len(lis)
    if nagasa<l:
        for _ in range(l-nagasa):
            lis.insert(0,0)
    S=int(N[0])
    ans=[]
    for ll in range(l):
        if lis[ll]=='1':
            S=S+int(N[ll+1])
            ans.append('+')
        else:
            S=S-int(N[ll+1])
            ans.append('-')
    if S==7:
        kotae=[N[0]]
        for x in range(l):
            kotae.append(ans[x])
            kotae.append(N[x+1])
        kotae.append('=7')
        last=''.join(kotae)
        print(last)
        break

Submission status: Accepted

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

A, B, C, D = list(input())
OP = ['+', '-']

for op1 in OP:
    for op2 in OP:
        for op3 in OP:
            ans = A + op1 + B + op2 + C + op3 + D
            if eval(ans) == 7:
                ans = ans+"=7"
                break
        else:
            continue
        break
    else:
        continue
    break

print(ans)

Submission status: Accepted

Solution code:
S = input()
n = 4

def f(S, n):
    for i in range( 1 << n-1 ):
        cand_str = ""
        cand_str += S[0]

        # loop for 0th, 1th, ..., n-2th digits
        for j in range(n-1):

            # get n-2th bit when j=0 
            t = i & (1 << n-2-j)
            if t:
                cand_str += "+"
            else:
                cand_str += "-"
            cand_str += S[j+1]
            
        if eval(cand_str) == 7:
            return cand_str + "=7"

print(f(S, n))

Submission status: Accepted

Solution code:
from sys import stdin
N=(stdin.readline().rstrip())
N=list(N)
ans=""
for j in ["+","-"]:
    for k in ["+","-"]:
        for l in ["+","-"]:
            equ = N[0] + j + N[1] + k + N[2] + l + N[3]
            if eval(equ) == 7:
                ans = equ
print(ans+"=7")

Submission status: Accepted

Solution code:
T = int(input())
a = T//1000
b = (T % 1000)//100
c = (T % 100)//10
d = T % 10
if a + b + c + d == 7:
    print(str(a) + "+" + str(b) + "+" + str(c) + "+" + str(d) + "=7")
elif a + b + c - d == 7:
    print(str(a) + "+" + str(b) + "+" + str(c) + "-" + str(d) + "=7")
elif a + b - c + d == 7:
    print(str(a) + "+" + str(b) + "-" + str(c) + "+" + str(d) + "=7")
elif a - b + c + d == 7:
    print(str(a) + "-" + str(b) + "+" + str(c) + "+" + str(d) + "=7")
elif a + b - c - d == 7:
    print(str(a) + "+" + str(b) + "-" + str(c) + "-" + str(d) + "=7")
elif a - b + c - d == 7:
    print(str(a) + "-" + str(b) + "+" + str(c) + "-" + str(d) + "=7")
elif a - b - c + d == 7:
    print(str(a) + "-" + str(b) + "-" + str(c) + "+" + str(d) + "=7")
else:
    print(str(a) + "-" + str(b) + "-" + str(c) + "-" + str(d) + "=7")

Submission status: Accepted

Solution code:
n = input()

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

    f = ""
    for pn, po in zip(n, ops + [""]):
        f += (pn + po)
    if eval(f) == 7:
        print(f + "=7")
        break

Submission status: Accepted

Solution code:
n = input()

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

    f = ""
    for pn, po in zip(n, ops + [""]):
        f += (pn + po)
    if eval(f) == 7:
        print(f + "=7")
        break

Submission status: Accepted

Solution code:
ABCD = input()
op ="+-"
for i in range(pow(2, 3)):
  v = i
  f = str(ABCD[0])
  for j in range(1,4):
    f += op[v%2] + ABCD[j]
    v //= 2
  if eval(f) == 7:
    print("{}=7".format(f))
    break

Submission status: Accepted

Solution code:
from itertools import product
import bisect
import sys


def input():
    return sys.stdin.readline()[:-1]

# N = int(input())
# A = [int(x) for x in input().split()]
# a, b, c = map(int, input().split())
# name1 = str(input())
# alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}
# b = list(map(lambda x: math.ceil(x/10)*10, a))


S = input()
for p in product(range(2), repeat=len(S)-1):
    tmp = ''
    for i in range(len(S)-1):
        if p[i] == 1:
            tmp += S[i]+'+'
        else:
            tmp += S[i]+'-'
    if eval(tmp+S[-1]) == 7:
        print(tmp+S[-1]+'=7')
        break

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input().rstrip()
plus_minus = [1, -1]
A = int(S[0])
for i in plus_minus:
    B = i*int(S[1])
    for j in plus_minus:
        C = j*int(S[2])
        for k in plus_minus:
            D = k*int(S[3])
            total = A+B+C+D
            if total == 7:
                if B >= 0:
                    B = "+" + str(B)
                if C >= 0:
                    C = "+" + str(C)
                if D >= 0:
                    D = "+" + str(D)
                answer = str(A) + str(B) + str(C) + str(D) + "=7"
                print(answer)
                exit()

Submission status: Accepted

Solution code:
# 2019/05/23
# AtCoder Beginner Contest 079 - C

# Function
def calcChar(in_abcd, in_sum, in_idx):
    if in_idx < len(in_abcd):
        wsum = in_sum + in_abcd[in_idx]
        fnans = calcChar(in_abcd, wsum, in_idx + 1)
        
        if fnans[0] == 7:
            wans = list()
            wans.append(7)
            wans.append("+" + str(in_abcd[in_idx]) + fnans[1])
            return wans
        else:
            wsum = in_sum + in_abcd[in_idx] * (-1)
            fnans = calcChar(in_abcd, wsum, in_idx + 1)
            if fnans[0] == 7:
                wans = list()
                wans.append(7)
                wans.append("-" + str(in_abcd[in_idx]) + fnans[1])
                return wans
            else:
                return [-1, ""]
    else:
        wans = list()
        wans.append(in_sum)
        wans.append("=7")
        return wans

# Input
str_abcd = input()
abcd = list()
for i in range(4):
    abcd.append(int(str_abcd[i]))

# Call Func
ansl = calcChar(abcd, abcd[0], 1)
ans = str(abcd[0]) + ansl[1]

# Output
print(ans)

Submission status: Accepted

Solution code:
import sys
a = b = c = d = ""
def f(ab, bc, cd):
    return str(a) + ab + str(b) + bc + str(c) + cd + str(d)
if __name__ == '__main__':
    s = list(input())
    a, b, c, d = s[0], s[1], s[2], s[3]
    lst = [f('+', '+', '+'), f('+', '+', '-'), f('+', '-', '+'), f('-', '+', '+'), f('+', '-', '-'), f('-', '+', '-'), f('-', '-', '+'), f('-', '-', '-')]
    for expr in lst:
        if eval(expr) == 7:
            print(expr + "=7")
            sys.exit(0)

Submission status: Accepted

Solution code:
#https://atcoder.jp/contests/abc079/tasks/abc079_c
ABCD = input()
A = int(ABCD[0])
B = int(ABCD[1])
C = int(ABCD[2])
D = int(ABCD[3])
ans  = str(A)
for ab in range(2):
    for bc in range(2):
        for cd in range(2):
            sum = A
            if ab:
                sum +=B
            else:
                sum -=B
            if bc:
                sum +=C
            else:
                sum -=C
            if cd:
                sum +=D
            else:
                sum -=D
            if sum == 7:
                A_B_C_D = ABCD[0] + str(ab) +ABCD[1]+ str(bc) +ABCD[2]+ str(cd) +ABCD[3]
                for i in range(1,6,2):
                    if int(A_B_C_D[i]):
                        ans += "+"
                    else:
                        ans += "-"
                    ans += A_B_C_D[i+1]
                break
        else:
            continue
        break
    else:
        continue
    break
    
print(ans + "=7")