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 = input()

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

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

Submission status: Accepted

Solution code:
abcd = input()
bit = 0b1000
ans=int(abcd[0])
op = [-1,-1,-1]
str_bit = bin(bit)

while bit<16:
  for i in range(3,6):
    if str_bit[i]=="1":
      op[i-3]=1
      ans+=int(abcd[i-2])
    else:
      op[i-3]=0
      ans-=int(abcd[i-2])
  
  if ans==7:
    for i in range(len(op)):
      if op[i]==1:
        op[i]="+"
      else:
        op[i]="-"
    print(abcd[0],op[0],abcd[1],op[1],abcd[2],op[2],abcd[3],"=7",sep='')
    exit()
  
  ans=int(abcd[0])
  bit+=1
  str_bit=bin(bit)

Submission status: Accepted

Solution code:
abcd = input()
bit = 0b1000
ans=int(abcd[0])
op = [-1,-1,-1]
str_bit = bin(bit)

while bit<16:
  for i in range(3,6):
    if str_bit[i]=="1":op[i-3]=1
    else:op[i-3]=0

  for i in range(0,3):
    if op[i]==1:
      ans+=int(abcd[i+1])
    else:
      ans-=int(abcd[i+1])
  
  if ans==7:
    for i in range(len(op)):
      if op[i]==1:
        op[i]="+"
      else:
        op[i]="-"
    print(abcd[0],op[0],abcd[1],op[1],abcd[2],op[2],abcd[3],"=7",sep='')
    exit()
  
  ans=int(abcd[0])
  bit+=1
  str_bit=bin(bit)

Submission status: Accepted

Solution code:
iS = input()
kigou = ['+','-']

for i in range(len(kigou)):
  for j in range(len(kigou)):
    for k in range(len(kigou)):
      result = iS[0]+kigou[i]+iS[1]+kigou[j]+iS[2]+kigou[k]+iS[3]
      if eval(result) == 7:
        print(result+'=7')
        exit(0)

Submission status: Accepted

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


if a + b + c + d == 7:
    print('{}+{}+{}+{}=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 sys

def cal(a,b,c):
	if a==0:
		bc=b+c
	else:
		bc=b-c
	return bc

n=input()
list=[]
for i in range(4):
	list.append(int(n[i]))
for a in range(2):
	ab=cal(a,list[0],list[1])
	for b in range(2):
		abc=cal(b,ab,list[2])
		for c in range(2):
			abcd=cal(c,abc,list[3])
			if abcd==7:
				if a==0:
					op1='+'
				else:
					op1='-'
				if b==0:
					op2='+'
				else:
					op2='-'
				if c==0:
					op3='+'
				else:
					op3='-'
				print(str(n[0])+str(op1)+str(n[1])+str(op2)+str(n[2])+str(op3)+str(n[3])+str('=')+str(7))
				sys.exit()

Submission status: Accepted

Solution code:
s=input()
a=int(s[0])
b=int(s[1])
c=int(s[2])
d=int(s[3])
if a+b+c+d==7:
    print(a,"+",b,"+",c,"+",d,"=",7,sep="")
elif a+b+c-d==7:
    print(a,"+",b,"+",c,"-",d,"=",7,sep="")
elif a+b-c+d==7:
    print(a,"+",b,"-",c,"+",d,"=",7,sep="")
elif a+b-c-d==7:
    print(a,"+",b,"-",c,"-",d,"=",7,sep="")
elif a-b+c+d==7:
    print(a,"-",b,"+",c,"+",d,"=",7,sep="")
elif a-b+c-d==7:
    print(a,"-",b,"+",c,"-",d,"=",7,sep="")
elif a-b-c+d==7:
    print(a,"-",b,"-",c,"+",d,"=",7,sep="")
else:
    print(a,"-",b,"-",c,"-",d,"=",7,sep="")

Submission status: Accepted

Solution code:
a,b,c,d=list(input())
op=lambda i,a:"+" if i&a else "-"
for i in range(8):
  s=a+op(i,1)+b+op(i,2)+c+op(i,4)+d
  if eval(s)==7:print(s+"=7");exit()

Submission status: Accepted

Solution code:
s = input()
for i in range(1, 8):
  y = int(s[0])
  z = ""
  for j in range(3):
    if ((i >> j) & 1):
      y += int(s[j+1])
      z += "+"
    else: 
      y -= int(s[j+1])
      z += "-"
  if y == 7:
    print(s[0]+z[0]+s[1]+z[1]+s[2]+z[2]+s[3]+"=7", sep="")
    break

Submission status: Accepted

Solution code:
s=input()
ans=""
import sys
for i in range(2**3):
    tmp=s[0]
    tmp_sum=(int(s[0]))
    for j in range(len(s)-1):
        
        if (i >> j) & 1:
            tmp+="+"
            tmp_sum+=int(s[j+1])
        else:
            tmp+="-"
            tmp_sum-=int(s[j+1])
        tmp+=s[j+1]
    # print(tmp,tmp_sum)
    if tmp_sum==7:
        print(tmp+"=7")
        sys.exit()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
s = input()
a = [int(s[i]) for i in range(4) ]
total = sum(a)
operand = "+-"
for i in range(8):
    k = i
    is_7 = total
    digit = 1
    while digit <= 3:
        if k % 2: is_7 -= 2*a[digit]
        digit += 1
        k = k // 2
    if is_7 == 7:
        print(s[0]+ operand[i%2] + s[1] + operand[(i//2)%2] + s[2] + operand[(i//4)%2] + s[3]+ "=7")
        break

Submission status: Accepted

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

#print(a)

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

Submission status: Accepted

Solution code:
s = input()
n = 3
l = ["+", "-"]
# bit全探索
for i in range(2 ** n):
    pm = []
    tmp = ""
    ans = int(s[0])
    for j in range(n):
        if ((i >> j) & 1):
            pm.append(l[0])
        else:
            pm.append(l[1])
    for k in range(n):
        if pm[k] == "+":
            ans += int(s[k + 1])
        else:
            ans -= int(s[k + 1])
    if ans == 7:
        print(s[0]+pm[0]+s[1]+pm[1]+s[2]+pm[2]+s[3]+"=7")
        break

Submission status: Accepted

Solution code:
a = list(input())

for i in range(2 ** 3):
    switch = [0] * 3
    for j in range(3):
        if ((i >> j) & 1):
            switch[j] = 1

    sum = int(a[0])
    for k in range(3):
        if switch[k] == 0:
            sum -= int(a[k + 1])
        else:
            sum += int(a[k + 1])
    if sum == 7:
        for k in range(3):
            print(a[k], end="")
            if switch[k] == 1:
                print("+", end="")
            else:
                print("-", end="")
        print(a[3], end="")
        print("=7")
        break

Submission status: Accepted

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

check = False
for i in range(2):
    if check:
        i = 0
        break
    for j in range(2):
        if check:
            j = 0
            break
        for k in range(2):
            ans = A
            if i==0:
                ans += B
            else:
                ans -= B
            
            if j==0:
                ans += C
            else:
                ans -= C
            
            if k==0:
                ans += D
            else:
                ans -= D
            
            if ans == 7:
                check = True
                break

if i==0:
    i = "+"
else:
    i = "-"

if j==0:
    j = "+"
else:
    j = "-"

if k==0:
    k = "+"
else:
    k = "-"

print("{}{}{}{}{}{}{}=7".format(A, i, B, j, C, k, D))

Submission status: Accepted

Solution code:
nums = input()
n = 4


def calc(i, f, sum):
    if i == n-1:
        if sum == 7:
            print(f+'=7')
            exit()

    else:
        calc(i+1, f + '-' + nums[i+1], sum - int(nums[i+1]))
        calc(i+1, f + '+' + nums[i+1], sum + int(nums[i+1]))


calc(0, nums[0], int(nums[0]))

Submission status: Accepted

Solution code:
import sys

S = input()
op_cnt = len(S) - 1

for i in range(2 ** op_cnt):
    op = ["-"] * op_cnt
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt - j - 1] = "+"
    formula = ""
    for p_n, p_o in zip(S, op + [""]):
        formula += (p_n + p_o)
    if eval(formula) == 7:
        print(formula + "=7")
        sys.exit()

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

print(eq + "=7")

Submission status: Accepted

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

for i in range(2**n):
  t = ''
  for j in range(n):
    t += abcd[j]
    if (i >> j)&1:
      t += "+"
    else:
      t += "-"
  else:
    t += abcd[n]
  if eval(t)==7:
    print('{}=7'.format(t))
    exit(0)

Submission status: Accepted

Solution code:
import itertools

N=input()
OP=['+','-']
for op in itertools.product(OP, repeat=3):
  str=N[0]+op[0]+N[1]+op[1]+N[2]+op[2]+N[3]
  ans = eval(str)
  if ans==7:
    print(str + "=7")
    break

Submission status: Accepted

Solution code:
N=input()
OP=[['+','+','+'],['-','+','+'],['+','-','+'],['+','+','-'],
    ['+','-','-'],['-','+','-'],['-','-','+'],['-','-','-']]
for op in OP:
  str=N[0]+op[0]+N[1]+op[1]+N[2]+op[2]+N[3]
  ans = eval(str)
  if ans==7:
    print(str + "=7")
    break

Submission status: Accepted

Solution code:
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] = "+"#bit探索の手法はここ

    formula = ""
    for x,y in zip(n, op + [""]):   #謎。
        formula += (x+y)
    if eval(formula) == 7:          #すごい
        print(formula + "=7")
        break                       #見つかったので爆破

Submission status: Accepted

Solution code:
import sys
import itertools
a,b,c,d=[i for i in input()]
op=["+","-"]
for i in itertools.product(op,repeat=3):
  ev=a+i[0]+b+i[1]+c+i[2]+d
  if eval(ev)==7:
    print(ev+"=7")
    sys.exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a=input()

def dfs(i,f):
    if i==3:
        if eval(f)==7:
            print(f+'=7')
            exit()
    else:
        dfs(i+1,f+'+'+a[i+1])
        dfs(i+1,f+'-'+a[i+1])

print(dfs(0,a[0]))

Submission status: Accepted

Solution code:
s = input()
length = len(s)
for i in range((length-1)**2-1):
  t = ['-']*(length-1)
  for j in range(length-1):
    if (i>>j)&1:
      t[j] = '+'
  a = ''
  for se,te in zip(s,t+['']):
    a += se + te
  if eval(a)==7:
    print(a+'=7')
    break

Submission status: Accepted

Solution code:
plus = lambda a,b:a+b
minus = lambda a,b:a-b

bit = 0

nums = [int(c) for c in input()]

for bit in range(8):
  op_lst = [(plus if bit >> i & 1 else minus) for i in [2,1,0]]
  temp = nums[0]
  for i in range(len(op_lst)):
    temp = op_lst[i](temp,nums[i+1])
  if temp == 7:
    break

op_strings = {plus:"+",minus:"-"}

s = str(nums[0]) + op_strings[op_lst[0]] + str(nums[1]) + op_strings[op_lst[1]] + str(nums[2]) + op_strings[op_lst[2]] + str(nums[3])

print(s+"=7")

Submission status: Accepted

Solution code:
*abcd, = map(str, input())

a = [""]*len(abcd)
ans = []

def rec(i: int, a: list) -> None:
    if i == len(abcd)-1:
        statement = "".join(_abcd+_a for _abcd, _a in zip(abcd, a))
        if eval(statement) == 7:
            global ans
            ans.append(statement)

        return

    a[i] = "-"
    rec(i+1, a)
    a[i] = "+"
    rec(i+1, a)

rec(0, a)
print(ans[0]+"=7")

Submission status: Accepted

Solution code:
import sys
x = [int(c) for c in input()]

d = {
    1: "+",
    -1: "-"
}
for op1 in [1, -1]:
    for op2 in [1, -1]:
        for op3 in [1, -1]:
            if x[0] + op1 * x[1] + op2 * x[2] + op3 * x[3] == 7:
                print(str(x[0]) + d[op1]+str(x[1]) +d[op2]+str(x[2])+d[op3]+str(x[3])+"=7")
                sys.exit()

Submission status: Accepted

Solution code:
s = input()
opl = ['+', '-']

flag = [0,0,0]
for i in range(0, 0b111+1):
    for j in range(3):
        #print(i)
        flag[j] = (i>>(j) & 1)
        ans = s[0] + opl[flag[0]] + s[1] + opl[flag[1]] + s[2] + opl[flag[2]] + s[3]
        if(eval(ans) == 7):
            print(ans + '=7')
            break
    else:
        continue
    break

Submission status: Accepted

Solution code:
ABCD = [int(s) for s in list(input())]
operators = ["-", "+"]
for bit in range(1 << 3):
    ops = [(bit >> i) & 1 for i in range(3)]
    tmp = ABCD[0]
    for op, val in zip(ops, ABCD[1:]):
        if op:
            tmp += val
        else:
            tmp -= val
    if tmp == 7:
        print(ABCD[0], end="")
        for op, val in zip(ops, ABCD[1:]):
            print(operators[op], val, sep="", end="")
        print("=7")
        exit()

Submission status: Accepted

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

op = ['', '+', '-']

for i in [1, -1]:
    for j in [1, -1]:
        for k in [1, -1]:
            if a + b*i + c*j + d*k == 7:
                print(str(a)+op[i]+str(b)+op[j]+str(c)+op[k]+str(d)+'=7')
                exit(0)

Submission status: Accepted

Solution code:
s=input()
n = len(s)
op_list = ['-'] *(n-1)
for bit in range(1 << (n-1)):
  op_list = ['-'] *(n-1)
  for i in range(n-1):
    if bit & (1 << i):
      op_list[i] = '+'
  op=s[0]+op_list[0]+s[1]+op_list[1]+s[2]+op_list[2]+s[3]
  if eval(op)==7:
    break
text = op+"=7"
print(text)

Submission status: Accepted

Solution code:
N = input()
for i in range(2):
    for j in range(2):
        for k in range(2):
            A = int(N[0])
            B = int(N[1])
            C = int(N[2])
            D = int(N[3])
            op1 = '+'
            op2 = '+'
            op3 = '+'
            if i == 0:
                B *= -1
                op1 = '-'
            if j == 0:
                C *= -1
                op2 = '-'
            if k == 0:
                D *= -1
                op3 = '-'
            if A + B + C + D == 7:
                print(str(abs(A)) + op1 + str(abs(B)) + op2 + str(abs(C)) + op3 + str(abs(D)) + '=7')
                exit()

Submission status: Accepted

Solution code:
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('{}+{}+{}+{}=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(8):
    x = s[0]
    for j in range(3):
        if i>>j & 1:
            x += '+'
            x += s[j+1]
        else:
            x += '-'
            x += s[j+1]
    ans = eval(x)
    if  ans == 7:
      print(x+'=7')
      exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,C,D = list(input())
def check(S):
    if eval(S)==7:
        print(S + "=7")
        quit()
check("%s%s%s%s%s%s%s" % (A,"+",B,"-",C,"-",D))
check("%s%s%s%s%s%s%s" % (A,"-",B,"+",C,"-",D))
check("%s%s%s%s%s%s%s" % (A,"-",B,"-",C,"+",D))
check("%s%s%s%s%s%s%s" % (A,"+",B,"+",C,"-",D))
check("%s%s%s%s%s%s%s" % (A,"+",B,"-",C,"+",D))
check("%s%s%s%s%s%s%s" % (A,"-",B,"+",C,"+",D))
check("%s%s%s%s%s%s%s" % (A,"+",B,"+",C,"+",D))
check("%s%s%s%s%s%s%s" % (A,"-",B,"-",C,"-",D))

Submission status: Accepted

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

for i in range(2**3):
    a = [1&(i>>j) for j in range(3)]
    ind = set([i for i,x in enumerate(a) if x==1])
    
    sign = 1
    tmp=0
    nums=[]
    ans = ""
    for j in range(4):
        tmp = sign * int(S[j])
        ans += S[j]
        if j in ind:
            sign = -1
            ans+="-"
        else:
            sign = 1
            ans+="+"
        nums += [tmp]

    if sum(nums)==7:
        print(ans[:-1] + "=7")
        break

Submission status: Accepted

Solution code:
num = input()

for pattern in range(8):
    base = int(num[0])
    formula = num[0]
    for bit in range(3):
        if (pattern >> bit) & 1:
            base += int(num[bit+1])
            formula = formula + '+' + num[bit+1]
        else:
            base -= int(num[bit+1])
            formula = formula + '-' + num[bit+1]

    if base == 7:
        print(formula + '=7')
        exit()

Submission status: Accepted

Solution code:
s=input()
for i in range(2**3-1):
  x=''
  x=s[0]
  for j in range(3):
    if (i>>j)&1:
      x+='+-'
    else:
      x+='+'
    x+=s[j+1]
  ans=list(map(int,x.split('+')))
  if sum(ans)==7:
    break
p=str(ans[0])
for i in range(1,4):
  if ans[i]<0:
    p+=str(ans[i])
  else:
    p+='+'+str(ans[i])
print(p+'=7')

Submission status: Accepted

Solution code:
s = input()
operator_count = len(s) - 1
operands = list(map(int, s))

# 適当にEnumを作る
add = 0
sub = 1

for bit in range(1 << operator_count):
  result = operands[0]
  operators = []
  for i in range(operator_count):
    if bit & (1 << i):
      # +を挿入
      result += operands[i+1]
      operators.append(add)
    else:
      # -を挿入
      result -= operands[i+1]
      operators.append(sub)
  if result == 7:
    break

for idx,op in enumerate(operators):
  if op == add:
    print("{}+".format(operands[idx]),end='')
  else:
    print("{}-".format(operands[idx]),end='')
print("{}=7".format(operands[-1]))

Submission status: Accepted

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

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
 
print(eq+'=7')

Submission status: Accepted

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

n = len(s) - 1


for i in range(1 << n):
  operators = ['-'] * n
  for j in range(n):
    if (1 << j) & i:
      operators[n - 1 - j] = '+'

  formula = ''
  for (num, op) in zip(s, operators + [""]):
    formula += str(num) + op
  if (eval(formula) == 7):
    print('{}=7'.format(formula))
    break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

p = []
for i in range(2**3):
    t = format(i, 'b').zfill(3)
    p.append(t)

for pi in p:
    st = S[0]
    for i in range(3):
        if pi[i] == '1':
            st += '+'
        else:
            st += '-'
        st += S[i+1]
    if eval(st) == 7:
        break
else:
    raise Exception()

print(st + '=7')

Submission status: Accepted

Solution code:

array = list(map(int, input()))

for i in range(2 ** 3):

    ans = array[0]
    mark = []

    for j in range(3):

        if (i >> j) & 1:
            mark.append('+')
            ans += array[j+1]
        
        else:
            mark.append('-')
            ans -= array[j+1]

    if ans == 7:
        print('{}{}{}{}{}{}{}=7'.format(array[0],mark[0],array[1],mark[1],array[2],mark[2],array[3]))
        exit()

Submission status: Accepted

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

op = ["+", "-"]
for i in op:
  for j in op:
    for k in op:
      if eval(A+i+B+j+C+k+D) == 7:
        print(A+i+B+j+C+k+D+"=7")
        exit()

Submission status: Accepted

Solution code:
s = input()
for i in range(2**(len(s)-1)):
    total = int(s[0])
    ope = s[0]
    for j in range(len(s)-1):
        if ((i >> j) & 1):
            total += int(s[1+j])
            ope = ope + "+" + s[1+j]
        else:
            total -= int(s[1+j])
            ope = ope + "-" + s[1+j]
    if total == 7:
        print(ope+"=7")
        break

Submission status: Accepted

Solution code:
s = input()
len_s = len(s)
sum_dict = {}

for i in range(2 ** (len_s)):
    total_sum = 0
    position = 0
    eq = ""
    for j in range(len_s):
        if position == 0:
            total_sum += int(s[position:position+1])
            eq += s[position:position+1]
        elif (i >> j) & 1:
            total_sum += int(s[position:position+1])
            eq += "+" + s[position:position+1]
        else:
            total_sum -= int(s[position:position+1])
            eq += "-" + s[position:position+1]
        position += 1
    if total_sum == 7:
        print(eq + "=7")
        break

Submission status: Accepted

Solution code:
S = input()
A = S[0]
B = S[1]
C = S[2]
D = S[3]
for i in range(2 ** 3):
    op1 = "+" if i & (2 ** 0) else "-"
    op2 = "+" if i & (2 ** 1) else "-"
    op3 = "+" if i & (2 ** 2) else "-"
    formula = "{}{}{}{}{}{}{}".format(A, op1, B, op2, C, op3, D)
    ans = eval(formula)
    if ans == 7:
        print("{}=7".format(formula))
        break

Submission status: Accepted

Solution code:
S = input()
listS=[]
for i in range(len(S)):
    listS.append(int(S[i]))

n = len(S)
def dfs(i, total, formular):
    if i == n-1:
        if total == 7:
            print( formular+'=7')
            exit()

    else:
        next = S[i+1]
        dfs(i+1, total + int(next), formular + "+"+next)
        dfs(i+1, total-int(next), formular + '-' + next)




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

Submission status: Accepted

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

def dfs( i : int, total : int, formular : str  ):
    if i == n - 1:
        if total == 7:
            print( formular+"=7" )
            exit()
    else:
        next = s[ i + 1]
        dfs( i + 1, total + int( next ), formular + "+" + next )
        dfs( i + 1, total -  int( next ), formular + "-" + next )

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

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
S = input()
list = [int(S[i]) for i in range(4)]
ans=str(S[0])

for bit in range(1 << 3):
    for i in range(3):
        if bit & (1 << i):
            list[i+1] = list[i+1] * -1
        
        if sum(list) == 7:
            for j in range(1,4):
                if list[j] < 0:
                    ans = ans + "-" + S[j]
                else:
                    ans = ans + "+" + S[j]
            
            print(ans+"=7")
            sys.exit()

Submission status: Accepted

Solution code:
nums = [n for n in input()]
ope = ["+", "-"]
for b in range(2 ** 3):
    temp = nums[0]
    for i in range(3):
        temp += ope[bool(b & (1 << i))] + nums[i + 1]
    if eval(temp) == 7:
        print(temp+"=7")
        break

Submission status: Accepted

Solution code:
N=input()
a=0
for i in range(8):
    t=list(format(i,"b"))
    a=[-1]*3
    for j in range(len(t)):
        if(int(t[len(t)-j-1])==1):
            a[j]=1
    
    if((int(N[0])+int(N[1])*a[0]+int(N[2])*a[1]+int(N[3])*a[2])==7):
        print(N[0],end="")
        if(a[0]==1):
            print("+",end="")
        else:
            print("-",end="")
        print(N[1],end="")
        if(a[1]==1):
            print("+",end="")
        else:
            print("-",end="")
        print(N[2],end="")
        if(a[2]==1):
            print("+",end="")
        else:
            print("-",end="")
        print(N[3],end="")    
        print("=7")
        exit()

Submission status: Accepted

Solution code:
import itertools
A,B,C,D = map(int,list(input()))
op = ['+', '-']

operators = list(itertools.product(op, repeat=3))

for ops in operators:
    tmp = A
    if ops[0] == '+':
        tmp += B
    if ops[0] == '-':
        tmp -= B

    if ops[1] == '+':
        tmp += C
    if ops[1] == '-':
        tmp -= C

    if ops[2] == '+':
        tmp += D
    if ops[2] == '-':
        tmp -= D

    if tmp == 7:
        res = str(A) + ops[0] + str(B) + ops[1] + str(C) + ops[2] + str(D) + '=7'
        print(res)
        exit()

Submission status: Accepted

Solution code:
class Number:
  value = '0'
  negative = False
  
  def __init__(self, value, negative):
    self.value = value
    self.negative = negative
    
  def __int__(self):
    x = int(self.value)
    return -x if self.negative else x
  
  def __str__(self):
    x = str(self.value)
    return '-' + x if self.negative else '+' + x
  
correct = []  

def solve(numbers, k):
  global correct
  if k >= len(numbers):
    if sum([int(x) for x in numbers]) == 7:
      correct.append(numbers)      
    return
  
  negative = []
  for i, x in enumerate(numbers):
    if i == k:
      negative.append(Number(x.value, True))
    else:
      negative.append(x)
  
  solve(numbers, k + 1)
  solve(negative, k + 1)
  
numbers = [Number(x, False) for x in input()] 

solve(numbers, 1)

print(''.join([str(x) for x in correct[0]])[1:] + '=7')

Submission status: Accepted

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

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

print(eq+'=7')

Submission status: Accepted

Solution code:
A = list(map(int,input()))
def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

ops =''
for n in range(8):
	b = Base_10_to_n(n,2).rjust(3,'0')
	s = A[0]
	for i in range(3):
		if b[i] == '0':
			s -= A[i+1]
		else:
			s += A[i+1]

	if s == 7:
		ops = b
		break

ans = []
for i in range(3):
	ans.append(str(A[i]))
	if ops[i] == '0':
		ans.append('-')
	else:
		ans.append('+')

ans.append(str(A[3])+'=7')

print(''.join(ans))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
S = str(input())
a = int(S[0])
b = int(S[1])
c = int(S[2])
d = int(S[3])

for i in range(2) :
  for j in range(2) :
    for k in range(2) :
      sum = a
      ans = str(a)
      if i == 0 :
        sum += b
        ans += "+" + str(b)
      else :
        sum -= b
        ans += "-" + str(b)
      if j == 0 :
        sum += c
        ans += "+" + str(c)
      else :
        sum -= c
        ans += "-" + str(c)
      if k == 0 :
        sum += d
        ans += "+" + str(d)
      else :
        sum -= d
        ans += "-" + str(d)
        
      if sum == 7 :
        print(ans+"=7")
        exit()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    S = input()

    for i in range(2 ** 3):
        ans = 0
        ans += int(S[0])
        for j in range(3):
            if i >> j & 1:
                ans += int(S[j + 1])
            else:
                ans -= int(S[j + 1])

        if ans == 7:
            print(S[0], end="")
            for j in range(3):
                if i >> j & 1:
                    print("+" + S[j + 1], end="")
                else:
                    print("-" + S[j + 1], end="")
            print("=7")
            break


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
arr = str(input())
arr = list(arr)
arr = list(map(int,arr))
a = arr[0]
b = arr[1]
c = arr[2]
d = arr[3]
a1 = str(arr[0])
b1 = str(arr[1])
c1 = str(arr[2])
d1 = str(arr[3])

if a+b+c+d == 7:
    print(a1+'+'+b1+'+'+c1+'+'+d1+'=7')
elif a+b+c-d == 7:
    print(a1+'+'+b1+'+'+c1+'-'+d1+'=7')
elif a+b-c+d == 7:
    print(a1+'+'+b1+'-'+c1+'+'+d1+'=7')
elif a-b+c+d == 7:
    print(a1+'-'+b1+'+'+c1+'+'+d1+'=7')
elif a+b-c-d == 7:
    print(a1+'+'+b1+'-'+c1+'-'+d1+'=7')
elif a-b+c-d == 7:
    print(a1+'-'+b1+'+'+c1+'-'+d1+'=7')
elif a-b-c+d == 7:
    print(a1+'-'+b1+'-'+c1+'+'+d1+'=7')
elif a-b-c-d == 7:
    print(a1+'-'+b1+'-'+c1+'-'+d1+'=7')

Submission status: Accepted

Solution code:
def calc(x, y, op):
    if op == "+":
        res = x + y
    elif op == "-":
        res = x - y
    return res


s = input()

a, b, c, d = map(int, s)
operand = ["+", "-"]
ans = ""

for op1 in operand:
    res1 = calc(a, b, op1)
    for op2 in operand:
        res2 = calc(res1, c, op2)
        for op3 in operand:
            res3 = calc(res2, d, op3)
            if res3 == 7:
                ans = "{}{}{}{}{}{}{}=7".format(a, op1, b, op2, c, op3, d)
                break
        else:
            continue
        break
    else:
        continue
    break

print(ans)

Submission status: Accepted

Solution code:
s = input()
N = 1<<(len(s)-1)

for one in range(N):
    c = int(s[0])
    tmp = s[0]
    for i in range(0,len(s)-1):
        if (one>>i & 1)==1:
            c+=int(s[i+1])
            tmp+='+'
        else:
            c-=int(s[i+1])
            tmp+='-'
        tmp+=s[i+1]
    tmp+='=7'
    if c==7:
        print(tmp)
        break

Submission status: Accepted

Solution code:
s=input()
for x in '+-':
    for y in '+-':
        for z in '+-':
            sum=s[0]+x+s[1]+y+s[2]+z+s[3]
            if eval(sum)==7:
                print(sum+'=7')
                exit()