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:
s = list(input())
for i in range(2 ** (len(s) - 1)):
  st = str(s[0])
  num = int(s[0])
  for j in range(len(s) - 1):
    if (i >> j) & 1:
      st = st + "+" + str(s[j+1])
      num += int(s[j+1])
    else:
      st = st + "-" + str(s[j+1])
      num -= int(s[j+1])
  
  if num == 7:
    print(st + "=7")
    break

Submission status: Accepted

Solution code:
A, B, C, D = list(input())
operations = [
    ("+", "+", "+"), ("+", "+", "-"), ("+", "-", "+"),
    ("-", "+", "+"), ("-", "-", "+"), ("-", "+", "-"),
    ("+", "-", "-"), ("-", "-", "-")
]

for ope in operations:
    fomula = "{}{}{}{}{}{}{}".format(A, ope[0], B, ope[1], C, ope[2], D)
    result = eval(fomula)
    if result == 7:
        print(fomula+"=7")
        break

Submission status: Accepted

Solution code:
N=int(input())
A=N//1000
N-=A*1000
B=N//100
N-=B*100
C=N//10
N-=C*10
D=N
if A+B+C+D==7:
    print('%d+%d+%d+%d=7' %(A,B,C,D))
elif A-B+C+D==7:
    print('%d-%d+%d+%d=7' %(A,B,C,D))
elif A+B+C-D==7:
    print('%d+%d+%d-%d=7' %(A,B,C,D))
elif A+B-C+D==7:
    print('%d+%d-%d+%d=7' %(A,B,C,D))
elif A-B-C+D==7:
    print('%d-%d-%d+%d=7' %(A,B,C,D))
elif A+B-C-D==7:
    print('%d+%d-%d-%d=7' %(A,B,C,D))
elif A-B+C-D==7:
    print('%d-%d+%d-%d=7' %(A,B,C,D))
elif A-B-C-D==7:
    print('%d-%d-%d-%d=7' %(A,B,C,D))

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc079/tasks/abc079_c
n = 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 + [""]):  # 少々モヤッとする
        formula += (p_n + p_o)
    if eval(formula) == 7:
        print(formula + "=7")
        break

Submission status: Accepted

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

def main():
	tmp = input()
	tmp2 = list(tmp)
	num = [int(s) for s in tmp2]
	
	op1 = ""
	op2 = ""
	op3 = ""
	if num[0] + num[1] + num[2] + num[3] == 7:
		op1 = "+"
		op2 = "+"
		op3 = "+"
	if num[0] + num[1] + num[2] - num[3] == 7:
		op1 = "+"
		op2 = "+"
		op3 = "-"
	if num[0] + num[1] - num[2] - num[3] == 7:
		op1 = "+"
		op2 = "-"
		op3 = "-"
	if num[0] - num[1] + num[2] - num[3] == 7:
		op1 = "-"
		op2 = "+"
		op3 = "-"
	if num[0] - num[1] - num[2] + num[3] == 7:
		op1 = "-"
		op2 = "-"
		op3 = "+"
	if num[0] - num[1] - num[2] - num[3] == 7:
		op1 = "-"
		op2 = "-"
		op3 = "-"
	if num[0] + num[1] - num[2] + num[3] == 7:
		op1 = "+"
		op2 = "-"
		op3 = "+"
	if num[0] - num[1] + num[2] + num[3] == 7:
		op1 = "-"
		op2 = "+"
		op3 = "+"
	print("{}{}{}{}{}{}{}=7".format(num[0], op1, num[1], op2, num[2], op3, num[3]))
		
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
S = input()
bits = ["---","--+","-+-","-++",
       "+--","+-+","++-","+++"]
flg = False
for bit in bits:
    eq = S[0]+bit[0]+S[1]+bit[1]+S[2]+bit[2]+S[3]
    val = eval(eq)
    if val == 7:
        print(eq+"=7")
        flg=True
        break
if not flg:
    print("nothing")

Submission status: Accepted

Solution code:
def search(N, i, result, state=""):
    if i == 3:
        if result == 7:
            return state + N[3]
        else:
            return ""
    ret = search(N, i+1, result + int(N[i+1]), state + N[i] + "+")
    if ret:
        return ret
    else:
        return search(N, i+1, result - int(N[i+1]), state + N[i] + "-")


def main():
    N = input()
    print(search(N, 0, int(N[0])) + "=7")


if __name__ == "__main__":
    main()

Submission status: Accepted

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

ops = ["+","-"]
for op1 in ops:
  for op2 in ops:
    for op3 in ops:
      x = a+op1+b+op2+c+op3+d
      if(eval(x) == 7):
        print(x+"=7")
        exit()

Submission status: Accepted

Solution code:
abcd = [int(i) for i in input()]
a = abcd.pop(0)
op = ''
check = 0
for i in range(1 << len(abcd)):
  check = a
  op = ''
  for j in range(len(abcd)):
    if ((i >> j) & 1) == 1:
      check += abcd[j]
      op += '+'
    else:
      check -= abcd[j]
      op += '-'
  if check == 7:
    print(str(a)+op[0]+str(abcd[0])+op[1]+str(abcd[1])+op[2]+str(abcd[2])+'=7')
    break

Submission status: Accepted

Solution code:
def trainticket(a):
    op = ['+','-']
    for i in op:
        for p in op:
            for o in op:
                f = a[0] + i + a[1] + p + a[2] + o + a[3]
                if eval(f) == 7:
                    return f + '=7'
A = input()
print(trainticket(A))

Submission status: Accepted

Solution code:
p = list(map(int, list(input())))
def add(x,y,s):
    if s == 0: return x+y
    else: return x-y
def bittolist(x):
    ret = []
    for _ in range(3):
        ret.append(x%2)
        x //= 2
    return ret
def pm(s):
    if s == 0:
        return '+'
    else: return '-'
for i in range(8):
    s = bittolist(i)
    res = p[0]
    for j in range(3):
        res = add(res, p[j+1], s[j])
    if res == 7:
        print(p[0], end = '')
        print(pm(s[0]), end = '')
        print(p[1], end = '')
        print(pm(s[1]), end = '')
        print(p[2], end = '')
        print(pm(s[2]), end = '')
        print(p[3], end = '')
        print('=7')
        exit()

Submission status: Accepted

Solution code:
n = list(map(int,input()))
su = n[0]
for i in range(2):
    if i == 0:
        suu = n[0]+n[1]
        a = '+'
    else:
        suu = n[0]-n[1]
        a = '-'
    for j in range(2):
        if j == 0:
            suuu = suu + n[2]
            aa = '+'
        else:
            suuu = suu - n[2]
            aa = '-'
        for k in range(2):
            if k == 0:
                suuuu = suuu + n[3]
                aaa = '+'
            else:
                suuuu = suuu - n[3]
                aaa = '-'
            if suuuu == 7:
                break
        if suuuu == 7:
            break
    if suuuu == 7:
        break
print(str(n[0])+a+str(n[1])+aa+str(n[2])+aaa+str(n[3])+"=7")

Submission status: Accepted

Solution code:
#078-C 
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=S()
for i in range(4):
    n[i]=int(n[i])
if n[0]+n[1]+n[2]+n[3]==7:
    print(str(n[0])+"+"+str(n[1])+"+"+str(n[2])+"+"+str(n[3])+"=7")
elif n[0]+n[1]+n[2]-n[3]==7:
    print(str(n[0])+"+"+str(n[1])+"+"+str(n[2])+"-"+str(n[3])+"=7")
elif n[0]+n[1]-n[2]+n[3]==7:
    print(str(n[0])+"+"+str(n[1])+"-"+str(n[2])+"+"+str(n[3])+"=7")
elif n[0]+n[1]-n[2]-n[3]==7:
    print(str(n[0])+"+"+str(n[1])+"-"+str(n[2])+"-"+str(n[3])+"=7")
elif n[0]-n[1]+n[2]+n[3]==7:
    print(str(n[0])+"-"+str(n[1])+"+"+str(n[2])+"+"+str(n[3])+"=7")
elif n[0]-n[1]+n[2]-n[3]==7:
    print(str(n[0])+"-"+str(n[1])+"+"+str(n[2])+"-"+str(n[3])+"=7")
elif n[0]-n[1]-n[2]+n[3]==7:
    print(str(n[0])+"-"+str(n[1])+"-"+str(n[2])+"+"+str(n[3])+"=7")
elif n[0]-n[1]-n[2]-n[3]==7:
    print(str(n[0])+"-"+str(n[1])+"-"+str(n[2])+"-"+str(n[3])+"=7")

Submission status: Accepted

Solution code:
abcd = list(input())
operator = ['+','-']
for i in operator:
    for p in operator:
        for o in operator:
            seven = eval(abcd[0]+i+abcd[1]+p+abcd[2]+o+abcd[3])
            if seven == 7:
                ans = abcd[0]+i+abcd[1]+p+abcd[2]+o+abcd[3]+'='+str(seven)
print(ans)

Submission status: Accepted

Solution code:
import numpy

def main():
    a = int(input())
    a = str(a).zfill(4)
    
    A = int(a[0])
    B = int(a[1])
    C = int(a[2])
    D = int(a[3])
    
    op1 = ""
    op2 = ""
    op3 = ""
    
    for i in range(2):
        for j in range(2):
            for k in range(2):
                if A + (-1) ** (i+1) * B + (-1) ** (j+1) * C + (-1) ** (k+1) * D == 7:
                    op1 = "-" if i == 0 else "+"
                    op2 = "-" if j == 0 else "+"
                    op3 = "-" if k == 0 else "+"
                    print(str(A)+op1+str(B)+op2+str(C)+op3+str(D)+"=7")
                    exit()
    
main()

Submission status: Accepted

Solution code:
abcd = input()

for i in range(1 << len(abcd) - 1):  
  sentence = "".join([abcd[j] + ('+' if (i >> j) % 2 else '-') for j in range(len(abcd) - 1)]) + abcd[-1]
  if eval(sentence) == 7:
    print(sentence + '=7')
    break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(input())


def dfs(count, string):
    if count == 4:
        if eval(string) == 7:
            return string + '=7'
        else:
            return ''
    plus = dfs(count + 1, string + '+' + S[count])
    minus = dfs(count + 1, string + '-' + S[count])
    return plus + minus


print(dfs(1, S[0])[:9])

Submission status: Accepted

Solution code:
# ABC079

s = input()

def cal_pm(s, is_plus):
    result = int(s[0])
    for p_idx, p in enumerate(is_plus):
        if p == '1':
            result += int(s[p_idx+1])
        else:
            result -= int(s[p_idx+1])
    return result

res = 0
for i in range(2**(len(s)-1)):
    is_plus ='{i:0={width}b}'.format(i=i, width=len(s)-1) 
    result = cal_pm(s, is_plus)
    if result == 7:
        for idx, n in enumerate(s):
            print(n, end='')
            if idx != len(s) - 1:
                print('+' if is_plus[idx] == '1' else '-', end='')
            else:
                print('=7')
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
import itertools
import numpy as np
import sys
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

A,B,C,D = [i for i in S()]
s = A
l = [B,C,D]
for i in range(1 << len(l)):
	num = int(A)
	data = []
	for j in range(len(l)):
		if ((i >> j) & 1) == 1:
			num += int(l[j])
		else:
			num -= int(l[j])
	if num == 7:
		for j in range(len(l)):
			if ((i >> j) & 1) == 1:
				s += "+"+l[j]
			else:
				s += "-"+l[j]
		else:
			print(s+"=7")
			exit()

Submission status: Accepted

Solution code:
from copy import copy
S=input()
S+="A"
lst1=[]
lst2=[]
lst3=[]
lst1.append(int(S[0]))
lst2.append(0)
def confirm(l1,l2):
    s=0
    for i in range(len(l1)):
        if l2[i]==0:
            s+=l1[i]
        else:
            s-=l1[i]
    return s
def draw(l1,l2,l3):
    s=""
    for i in range(len(l1)):
        if l2[i]==0:
            s=s+"+"+str(l1[i])
        else:
            s=s+"-"+str(l1[i])
    s=s+"=7"
    l3.append(s[1:])
    return 0
def func(S,l1,l2,l3):
    if S=="A":
        if confirm(l1,l2)==7:
            draw(l1,l2,l3)
            return 0
        return 0
    x=copy(l1)
    x.append(int(S[0]))
    y1=copy(l2)
    y1.append(0)
    y2=copy(l2)
    y2.append(1)
    return func(S[1:],x,y1,l3),func(S[1:],x,y2,l3)
func(S[1:],lst1,lst2,lst3)
print(lst3[0])

Submission status: Accepted

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

s = input()
f = 1
A,B,C,D = [int(c) for c in s]
for i in ['-','+']:
    for j in ['-','+']:
        for k in ['-','+']:
            if calc(calc(calc(A,B,i),C,j),D,k) == 7 and f == 1:
                print(str(A)+i+str(B)+j+str(C)+k+str(D)+'=7')
                f = 0

Submission status: Accepted

Solution code:
def func(nums, oprs, x):
    if len(nums) == 0:
        return [oprs, x]
    oprs1, x1 = func(nums[1:], oprs+'+', x+int(nums[0]))
    if x1 == 7:
        return [oprs1, x1]
    oprs2, x2 = func(nums[1:], oprs+'-', x-int(nums[0]))
    return [oprs2, x2]


S = input()
oprs, x = func(S[1:], '', int(S[0]))
print('{}{}{}{}{}{}{}=7'.format(S[0], oprs[0], S[1], oprs[1], S[2], oprs[2], S[3]))

Submission status: Accepted

Solution code:
A = input()
op = ["+", "-"]
for bit in range(1 << 3):
    ans = A[0]
    for i in range(3):
        ans += op[(bit >> i) & 1]+A[i+1]
    if eval(ans) == 7:
        print(ans+"=7")
        break

Submission status: Accepted

Solution code:
A = input()
for bit in range(1 << 4):
    ans = int(A[0])
    res = [A[0]]
    for i in range(3):
        if bit & (1 << i):
            ans += int(A[i + 1])
            res.append("+")
            res.append(A[i+1])
        else:
            ans -= int(A[i + 1])
            res.append("-")
            res.append(A[i+1])
    if ans == 7:
        for i in range(7):
            print(res[i], end='')
        print("=7")
        break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def func(S):
	for i in range(1 << 3):
		v = S[0]
		for j in range(3):
			v += ("+" if i >> j & 0x01 else "-") + S[j + 1]
		if eval(v) == 7:
			return v + "=7"

def main():
	print(func(input()))
	#print(func("1222"))
	#print(func("0290"))
	#print(func("3242"))
	return

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
import sys
write = sys.stdout.write

def chooseop(a, b, cmd):
    if cmd == 0:
        return a+b
    elif cmd == 1:
        return a-b

def calc(nums, ops):
    ans = nums[0]
    for i in range(1, 4):
        ans = chooseop(ans, nums[i], ops[i-1])
    return ans

def printresult(n, ops):
    op = ["+", "-", "*", "/"]
    write(n[0] + op[ops[0]] + n[1] + op[ops[1]] + n[2] + op[ops[2]] + n[3] + "=7\n")

n = input()
nums = []
if len(n) != 4:
    write("error\n")
    sys.exit()
for i in range(4):
    nums.append(int(n[i]))

zenbu = 2**3
for i in range(zenbu):
    ops = []
    bit = i
    for j in range(3):
        ops.append(bit % 2)
        bit //= 2
    res = calc(nums, ops)
    if res == 7:
        printresult(n, ops)
        break

Submission status: Accepted

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

    plus = lambda a, b: a + b
    minus = lambda a, b: a - b
    ops = [plus, minus]
    for op1 in ops:
        for op2 in ops:
            for op3 in ops:
                t = op1(a, b)
                t = op2(t, c)
                t = op3(t, d)
                if t == 7:
                    s1 = "+" if op1 is plus else "-"
                    s2 = "+" if op2 is plus else "-"
                    s3 = "+" if op3 is plus else "-"
                    print("{}{}{}{}{}{}{}=7".format(a, s1, b, s2, c, s3, d))
                    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = input()
n = [int(n[i:i + 1]) for i in range(4)]
for i in range(1 << 3):
  sum = n[0]
  for j in range(3):
    if ((i >> j) & 1) == 1:
      sum += n[j +  1]
    else:
      sum -= n[j + 1]
  if sum == 7:
    print(n[0], end = '')
    for j in range(3):
      if((i >> j) & 1) == 1:
        print('+', end = '')
      else:
        print('-', end = '')
      print(n[j + 1], end = '')
    print('=7')
    exit()

Submission status: Accepted

Solution code:
S = str(input())
sign = "+-"
for i in range(2**3):
    t = "".join([S[0]] + [(sign[i>>k&1]+s) for k, s in enumerate(S[1:])])
    if eval(t) == 7:
        print(t + "=7")
        exit()

Submission status: Accepted

Solution code:
import sys
a,b,c,d = [int(x) for x in list(input())]
if a+b+c+d ==7:
    print("{}+{}+{}+{}=7".format(a,b,c,d))
    sys.exit()
if a+b+c-d ==7:
    print("{}+{}+{}-{}=7".format(a,b,c,d))
    sys.exit()
if a+b-c+d ==7:
    print("{}+{}-{}+{}=7".format(a,b,c,d))
    sys.exit()
if a+b-c-d ==7:
    print("{}+{}-{}-{}=7".format(a,b,c,d))
    sys.exit()
if a-b+c+d ==7:
    print("{}-{}+{}+{}=7".format(a,b,c,d))
    sys.exit()
if a-b+c-d ==7:
    print("{}-{}+{}-{}=7".format(a,b,c,d))
    sys.exit()
if a-b-c+d ==7:
    print("{}-{}-{}+{}=7".format(a,b,c,d))
    sys.exit()
if a-b-c-d ==7:
    print("{}-{}-{}-{}=7".format(a,b,c,d))
    sys.exit()

Submission status: Accepted

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

def alsum(tmp,count,strs):
  if count == 4:
    
    if tmp ==7:
      print(strs+'=7')
      exit()
    else:
      return
    
  plus = alsum(tmp+abcd[count],count+1,strs+'+'+str(abcd[count]))
  minus = alsum(tmp-abcd[count],count+1,strs+'-'+str(abcd[count]))
  
alsum(abcd[0],1,str(abcd[0]))

Submission status: Accepted

Solution code:
from itertools import product
digits = list(map(int, list(input())))


for x in product('+-', repeat=3):

    result = digits[0]
    output = str(digits[0])

    for pm, digit in zip(x, digits[1:]):

        if pm == '+':
            result += digit
            output += '+'+str(digit)
        else:
            result -= digit
            output += '-{}'.format(digit)
    if result == 7:
        print(output+'=7')
        break

Submission status: Accepted

Solution code:
x=input()
a=int(x[0])
b=int(x[1])
c=int(x[2])
d=int(x[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()

if int(S[0]) + int(S[1]) + int(S[2]) + int(S[3]) == 7:
    print( S[0] + '+' + S[1] + '+' + S[2] + '+' + S[3] + '=7' )
elif int(S[0]) + int(S[1]) + int(S[2]) - int(S[3]) == 7:
    print( S[0] + '+' + S[1] + '+' + S[2] + '-' + S[3] + '=7' )
elif int(S[0]) + int(S[1]) - int(S[2]) + int(S[3]) == 7:
    print( S[0] + '+' + S[1] + '-' + S[2] + '+' + S[3] + '=7' )
elif int(S[0]) + int(S[1]) - int(S[2]) - int(S[3]) == 7:
    print( S[0] + '+' + S[1] + '-' + S[2] + '-' + S[3] + '=7' )
elif int(S[0]) - int(S[1]) + int(S[2]) + int(S[3]) == 7:
    print( S[0] + '-' + S[1] + '+' + S[2] + '+' + S[3] + '=7' )
elif int(S[0]) - int(S[1]) + int(S[2]) - int(S[3]) == 7:
    print( S[0] + '-' + S[1] + '+' + S[2] + '-' + S[3] + '=7' )
elif int(S[0]) - int(S[1]) - int(S[2]) + int(S[3]) == 7:
    print( S[0] + '-' + S[1] + '-' + S[2] + '+' + S[3] + '=7' )
elif int(S[0]) - int(S[1]) - int(S[2]) - int(S[3]) == 7:
    print( S[0] + '-' + S[1] + '-' + S[2] + '-' + S[3] + '=7' )

Submission status: Accepted

Solution code:
n = int(input())
a = n // 1000
b = n // 100 - a * 10
c = n // 10 - a * 100 - b * 10
d = n - a * 1000 - b * 100 - c * 10
yet = True
if a+b+c+d==7 and yet:
    print(str(a)+'+'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
    yet = False
if a+b+c-d==7 and yet:
    print(str(a)+'+'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
    yet = False
if a+b-c+d==7 and yet:
    print(str(a)+'+'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
    yet = False
if a+b-c-d==7 and yet:
    print(str(a)+'+'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
    yet = False
if a-b+c+d==7 and yet:
    print(str(a)+'-'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
    yet = False
if a-b+c-d==7 and yet:
    print(str(a)+'-'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
    yet = False
if a-b-c+d==7 and yet:
    print(str(a)+'-'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
    yet = False
if a-b-c-d==7 and yet:
    print(str(a)+'-'+str(b)+'-'+str(c)+'-'+str(d)+'=7')    
    yet = False

Submission status: Accepted

Solution code:
n = input()
a,b,c,d = map(int,list(n))
op =[1,1,1]
v = ["?","+","-"]
ans = 0
for i in range(-1,2,2):
    for j in range(-1,2,2):
        for k in range(-1,2,2):
            op[0] = i
            op[1] = j
            op[2] = k
            if a+b*op[0]+c*op[1]+d*op[2] == 7:
                print("{}{}{}{}{}{}{}=7".format(a,v[op[0]],b,v[op[1]],c,v[op[2]],d))
                break
        else:
            continue
        break
    else:continue
    break

Submission status: Accepted

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

def dfs(tmp,cur,strs):
  if cur==n:
    if tmp==7:
      print("".join(strs)+"=7")
      exit()
    else:
      return
  ret0=dfs(tmp+a[cur],cur+1,strs+["+"]+[str(a[cur])])
  ret1=dfs(tmp-a[cur],cur+1,strs+["-"]+[str(a[cur])])
dfs(a[0],1,[str(a[0])])

Submission status: Accepted

Solution code:
a=list(map(int,input()))
n=len(a)
for i in range(1<<n-1):
  tmp=a[0]
  string=str(a[0])
  # print(bin(i))
  for j in range(1,n):
    if (i>>j-1)&1==0:
      tmp-=a[j]
      string+="-"
      string+=str(a[j])
    else:
      tmp+=a[j]
      string+="+"
      string+=str(a[j])
    # print("",tmp)
  if tmp==7:
    print(string+"=7")
    exit()

Submission status: Accepted

Solution code:
n = input()
A = []
for i in range(4) :
    A.append(int(n[i]))

aa = ""
for i in range(8) :
    t = format(i,"03b")
    an = ""
    ans = A[0]
    for j in range(3) :

        if t[j] == "0" :
            ans += A[j+1]
            an += "+"
        else :
            ans -= A[j+1]
            an += "-"
    #print(ans)
    if ans == 7 :
        aa = an[:]
        #print(aa)

#print(aa)
res = ""
for i in range(3) :
    res += str(A[i]) + aa[i]
res += str(A[3]) + "=7"

print(res)

Submission status: Accepted

Solution code:
l=list(input())
a=int(l[0])
b=int(l[1])
c=int(l[2])
d=int(l[3])
x=y=z=2
for i in range(2):
  for j in range(2):
    for k in range(2):
      if i==1:
        _b=-b
      else:
        _b=b
      if j==1:
        _c=-c
      else:
        _c=c
      if k==1:
        _d=-d
      else:
        _d=d
      if sum([a,_b,_c,_d])==7:
        x=i
        y=j
        z=k
if x==1:
  x='-'
else:
  x='+'
if y==1:
  y='-'
else:
  y='+'
if z==1:
  z='-'
else:
  z='+'
print(str(a)+x+str(b)+y+str(c)+z+str(d)+'=7')

Submission status: Accepted

Solution code:
S = input()
op = ['+', '-']
for i in range(2 ** 3):
    T = S[0]
    for j in range(3):
        if i % 2 == 0:
            T += op[0]
        else:
            T += op[1]
        i //= 2
        T += S[j + 1]
    if eval(T) == 7:
        print(T + '=7')
        break

Submission status: Accepted

Solution code:
S = list(map(int, input()))
length = len(S) - 1
for bit in range(2 ** length):
    ans = S[0]
    ope = ['+' if bit & (2 ** i) else '-' for i in range(length)]
    for i in range(1, length + 1):
        if ope[i-1] == '+':
            ans += S[i]
        else:
            ans -= S[i]
    if ans == 7:
        print('{}{}{}{}{}{}{}=7'.format(
            S[0], ope[0],
            S[1], ope[1],
            S[2], ope[2],
            S[3]))
        break

Submission status: Accepted

Solution code:
#ABC079C
I=input()
A,B,C,D=map(int,I)
K=['-','+','=']
for s in range(8):
	ans=A
	F=format(s,'b').zfill(3)
	for n,f in zip([B,C,D],F):
		if f=='1':
			ans+=n
		else:
			ans-=n
	if ans==7:
		F+='2'
		a=''
		for i,f in zip(I,F):
			a+=i+K[int(f)]
		a+='7'
		print(a)
		exit()

Submission status: Accepted

Solution code:
s = input()

for i in ['+', '-']:
    for j in ['+', '-']:
        for k in ['+', '-']:
            if eval(s[0] + i + s[1] + j + s[2] + k + s[3]) == 7:
                print(s[0] + i + s[1] + j + s[2] + k + s[3] + '=7')
                quit()

Submission status: Accepted

Solution code:
def func():
  ABCD = list(input())
  A = int(ABCD[0])
  B = int(ABCD[1])
  C = int(ABCD[2])
  D = int(ABCD[3])
  for a in range(2):
    for b in range(2):
      for c in range(2):
        sum_ = A
        text = str(A)

        if a == 0:
          sum_ += B
          text = text + "+"
        else:
          sum_ -= B
          text = text + "-"
        text = text + str(B)

        if b == 0:
          sum_ += C
          text = text + "+"
        else:
          sum_ -= C
          text = text + "-"
        text = text + str(C)

        if c == 0:
          sum_ += D
          text = text + "+"
        else:
          sum_ -= D
          text = text + "-"
        text = text + str(D)

        if sum_ == 7:
          return text + "=7"
print(func())

Submission status: Accepted

Solution code:
target = input()
length = len(target)
binary = length - 1
target_list = []
for i in range(length):
    if i:
        target_list.append("")
    target_list.append(target[i])
for bit in range(binary ** 2):
    temp = target_list.copy()
    for i in range(binary):
        if bit & (1 << i):
            temp[1 + 2 * i] = "+"
        else:
            temp[1 + 2 * i] = "-"
    temp = "".join(temp)
    if eval(temp) == 7:
        print(temp + "=7")
        break

Submission status: Accepted

Solution code:
N = int(input())
A = N // 1000
B = (N // 100) - (A * 10)
C = (N // 10) - (A * 100) - (B * 10)
D = N - (A * 1000) - (B * 100) - (C * 10)

op_1 = 0
op_2 = 0
op_3 = 0

def printplus_minus(i):
	if i == 0:
		return"-"
	elif i == 1:
		return"+"
	else:
		return"Bug"
		
for i in range(2):
	for j in range(2):
		for k in range(2):
			NUM = A + B*((-1) ** (i + 1)) + C * ((-1) ** (j+1)) + D*((-1) ** (k + 1))
			if NUM == 7:
				op_1 = i
				op_2 = j
				op_3 = k
		
				

		
print(str(A)+printplus_minus(op_1)+str(B)+printplus_minus(op_2)+str(C)+printplus_minus(op_3)+str(D)+"=7")

Submission status: Accepted

Solution code:
import itertools

N = [i for i in str(input())]
op = ['+', '-']

def isTen(sets):
    num = sets[0]
    op = sets[1]
    formular = '{n1}{op1}{n2}{op2}{n3}{op3}{n4}'.format(
        n1=num[0],
        n2=num[1],
        n3=num[2],
        n4=num[3],
        op1=op[0],
        op2=op[1],
        op3=op[2]
    )
    if eval(formular) == 7:
        return formular + '=7'
    return ''

all_nums = list(itertools.permutations(N))
all_ops = list(itertools.product(op, repeat=3))
all = list(itertools.product(all_nums, all_ops))
for a in all:
    ans = isTen(a)
    if ans != '':
        print(ans)
        exit()

Submission status: Accepted

Solution code:
import sys
a = input().strip()

b = ['+', '-']

for i in b:
    for j in b:
        for k in b:
            c = a[0] + i + a[1] + j + a[2] + k + a[3]
            ans = eval(c)
            if ans == 7:
                print(c+'=7')
                sys.exit()

Submission status: Accepted

Solution code:
import sys
a = input().strip()

b = ['+', '-']

for i in b:
    for j in b:
        for k in b:
            c = a[0] + i + a[1] + j + a[2] + k + a[3]
            ans = int(c[0])
            if c[1] == '+':
                ans += int(c[2])
            else:
                ans -= int(c[2])
            if c[3] == '+':
                ans += int(c[4])
            else:
                ans -= int(c[4])
            if c[5] == '+':
                ans += int(c[6])
            else:
                ans -= int(c[6])
            if ans == 7:
                print(c+'=7')
                sys.exit()

Submission status: Accepted

Solution code:
s = str(input())
for bits in range(1 << 3):
    op1 = '+'
    op2 = '+'
    op3 = '+'
    for i in range(3):
        if (bits >> i & 1) == 1:
            if i == 0:
                op1 = '-'
            if i == 1:
                op2 = '-'
            if i == 2:
                op3 = '-'
    if eval(s[0]+op1+s[1]+op2+s[2]+op3+s[3]) == 7:
        print(s[0]+op1+s[1]+op2+s[2]+op3+s[3]+'=7')
        break

Submission status: Accepted

Solution code:
ABCD = input()

for i in range(1<<3):
    t = ABCD[0]
    for j in range(3):
        t += "+-"[(i>>j)%2]
        t += ABCD[j+1]
    if eval(t) == 7:
        print(t+"=7")
        exit()

Submission status: Accepted

Solution code:
a,b,c,d = [x for x in input()]
op = ["+","-"]
for op1 in op:
    for op2 in op:
        for op3 in op:
            if eval(a + op1 + b + op2 + c + op3 + d) == 7:
                print(a + op1 + b + op2 + c + op3 + d + "=7")
                exit()

Submission status: Accepted

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

S = inp().replace('\n', '')
a, b, c, d = S[0], S[1], S[2], S[3]

ops = ['+', '-']
for op1 in ops:
  for op2 in ops:
    for op3 in ops:
      tmp = a + op1 + b + op2 + c + op3 + d
      if(eval(tmp) == 7):
        print(tmp + '=7')
        exit()

Submission status: Accepted

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

ops = ['-', '+']
for op1 in ops:
    for op2 in ops:
        for op3 in ops:
            if eval(a+op1+b+op2+c+op3+d) == 7:
                print(a+op1+b+op2+c+op3+d+'=7')
                exit()

Submission status: Accepted

Solution code:
abcd = input()

def train_ticket(flg,sum,op):
    if flg == 0:
        if train_ticket(flg + 1, sum, op + "+"):
            return True
        elif train_ticket(flg + 1, sum, op + "-"):
            return True
    if flg >= len(abcd):
        if operation(sum, op[-1], flg) == 7:
            print("".join([abcd[i] + op[i+1] for i in range(len(op) - 1)]) + abcd[-1] + "=7")
            return True
        else:
            return False
    if train_ticket(flg + 1, operation(sum, op[-1], flg), op+"+"):
        return True
    elif train_ticket(flg + 1, operation(sum, op[-1], flg), op+"-"):
        return True

def operation(sum, op, flg):
    if op == "+":
        return sum + int(abcd[flg - 1])
    else:
        return sum - int(abcd[flg - 1])

train_ticket(0, 0, "")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    s = input()
    a, b, c, d = s
    ops = ["+", "-"]
    for op1 in ops:
        for op2 in ops:
            for op3 in ops:
                expr = a + op1 + b + op2 + c + op3 + d
                if eval(expr) == 7:
                    print(expr + "=7")
                    return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def dfs(i, f, sum):
    if i == 3:
        if sum == 7:
            print(f + "=7")
            exit()
        return
    dfs(i + 1, f + "-" + s[i + 1], sum - int(s[i + 1]))
    dfs(i + 1, f + "+" + s[i + 1], sum + int(s[i + 1]))

s = input()

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

Submission status: Accepted

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