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

format = []
for i in range(2 ** (len(s) - 1)):
    pat = ""
    for j in range(len(s) - 1):
        pat += s[j]
        if i >> j & 1:
            pat += "+"
        else:
            pat += "-"

    pat += s[-1]    
    format.append(pat)

for i in range(len(format)):
    if eval(format[i]) == 7:
        print(format[i] + "=7")
        exit()

Submission status: Accepted

Solution code:
s = input()

l = []
for i in range(2**(len(s)-1)):
  pat = ''
  for j in range(len(s)-1):
    pat += s[j]
    if i >> j & 1:
      pat += '+'
    else:
      pat += '-'
  l.append(pat+s[-1])

for i in range(len(l)):
  if eval(l[i]) == 7:
    print(l[i] + '=7')
    break

Submission status: Accepted

Solution code:
import copy
S = list(input())
s = copy.copy(S)

for i in range(9):
    s = copy.copy(S)
    for j in range(3):
        if (i >> j) & 1 :
            s.insert(3-j,"+")
        else:
            s.insert(3-j,"-")

        tmp = "".join(s)

    if eval(tmp) == 7 :
        for k in s:
            print(k,end="")
        else:
            print("=7")
            quit()

Submission status: Accepted

Solution code:
n = input()
a = int(n[0])
b = int(n[1])
c = int(n[2])
d = int(n[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 = input()
for i in range(2**3):
    f = s[0]
    for j in range(3):
        if i>>j & 1:
            f += '+'
        else:
            f += '-'
        f += s[j+1]
    if eval(f) == 7:
        print(f+'=7')
        exit()

Submission status: Accepted

Solution code:
s=str(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))
else:
  print('{}+{}+{}-{}=7'.format(a,b,c,d))

Submission status: Accepted

Solution code:
ABCD=input()
digits=3
ops=[""]*(digits+1)
for i in range(1<<digits):
    for j in range(digits):
        if (i>>j)&1:
            ops[j]="+"
        else:
            ops[j]="-"
    evals=""
    for num,op in zip(ABCD,ops):
        evals+=num+op
    if eval(evals)==7:
        print(evals+"=7")
        break

Submission status: Accepted

Solution code:
A,B,C,D=input()
digits=3
op=[""]*digits
for i in range(1<<digits):
    for j in range(digits):
        if (i>>j)&1:
            op[j]="+"
        else:
            op[j]="-"
    if eval(A+op[0]+B+op[1]+C+op[2]+D)==7:
        print(A+op[0]+B+op[1]+C+op[2]+D+"=7")
        break

Submission status: Accepted

Solution code:
import sys
from itertools import product

s = sys.stdin.readline().rstrip()

def main():
    for ops in product('+-', repeat=3):
        res = s[0]
        for i in range(3):
            res += ops[i] + s[i+1]
        if eval(res) == 7:
            print(res + '=7')
            return 

if __name__ ==  '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()
str_list = list(S)
p = len(S) - 1

for i in range(2 ** p):
  ans = int(str_list[0])
  sentence = S[0]
  for j in range(p):
    if (i >> j) & 1:
      ans += int(str_list[j+1])
      sentence += "+"+S[j+1]
    else:
      ans -= int(S[j+1])
      sentence += "-"+S[j+1]
  if ans ==7:
    print(sentence+"=7")
    break

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
n = input()
a,b,c,d = map(str,(n[0],n[1],n[2],n[3]))
x = []
for i in range(8):  
  for j in range(3):
    if (i>>j)&1:
      x.append("+")
    else:
      x.append("-")
  line = a + x[0] + b + x[1] + c + x[2] + d
  if eval(line) == 7:
    print(line + "=7")
    break
  x = []

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(2**3):
  tmp = A[0]
  for j in range(3):
    if (i >> j) & 1:
      tmp += A[j+1]
    else:
      tmp -= A[j+1]
  if tmp == 7:
    ops = [S[j] + ['-','+'][(i >> j) & 1] for j in range(3)]
    print(''.join(ops) + S[3] + '=7')
    exit()

Submission status: Accepted

Solution code:
a,b,c,d=input()
p = True
for i in ('+','-'):
    for j in ('+','-'):
        for k in ('+','-'):
            if eval(a+i+b+j+c+k+d)==7:
                print(a+i+b+j+c+k+d+'=7')
                p = False
                break
        else:
            continue
        break
    else:
        continue
    break
if p:
    print(u'バーカ')

Submission status: Accepted

Solution code:
s = input()

ops = ["-", "-", "-"]
n = 3

for i in range(n**3):
    ops = ["-", "-", "-"]
    for j in range(n):
        if i >> j & 1:
            ops[j] = "+"
    f = s[0] + ops[0] + s[1] + ops[1] + s[2] + ops[2] + s[3]
    if eval(f) == 7:
        print(f + "=7")
        break

Submission status: Accepted

Solution code:
s = input()

EQS = []
n = 3
for i in range(2**n):
  eq = ""
  for j in range(len(s)):
    eq += s[j]
    if((i>>j)&1):
      eq += "+"
    else:
      eq += "-"
  eq = eq[:-1]
  EQS.append(eq)

def clc(eq):
  total = int(eq[0])
  for i in range(1,len(eq),2):
    if eq[i]!=eq[-1]:
      if eq[i]=="+":
        total+=int(eq[i+1])
      else:
        total-=int(eq[i+1])
  
  return total

for i in EQS:
  total = clc(i)
  if total ==7:
    i +="=7"
    print(i)
    exit()

Submission status: Accepted

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

lead = S.pop(0)
n = len(S)
k = 7-lead
l = ['=7']

def dfs(i, sum):
    if i == n:
        return sum == k
    if dfs(i + 1, sum + S[i]):
        l.insert(0, '+')
        return True
    if dfs(i + 1, sum - S[i]):
        l.insert(0, '-')
        return True
    return False

if dfs(0, 0):
    S.insert(0, lead)
    for i in range(n+1):
        print(S[i], end='')
        print(l[i], end='')
    print('')

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(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:
def dfs(i,f,ans):
  if i<3:
    dfs(i+1,f+"+"+s[i+1],ans+int(s[i+1]))
    dfs(i+1,f+"-"+s[i+1],ans-int(s[i+1]))
  elif ans==7:
    print(f+"=7")
    exit()
s=input()
dfs(0,s[0],int(s[0]))

Submission status: Accepted

Solution code:
def dfs(array: list, index: int, calc: str, result: int):
    if index == len(array):
        if result == 7:
            return "{}=7".format(calc)
        else:
            return ""

    if index == 0:
        return dfs(array, index + 1, array[index], int(array[index]))
    elif index < len(array):
        return dfs(array, index + 1, calc + "-" + array[index], result - int(array[index])) + dfs(array, index + 1, calc + "+" + array[index], result + int(array[index]))

array = list(input())
S = dfs(array, 0, "", 0)
print(S[:9])

Submission status: Accepted

Solution code:
s = input()
ls = [int(i) for i in s]
n = len(ls)
i = 1
ans = ls[0]

def dfs(i, s, ans):
    if i==n:
        #print(i, 'floor', s, ans)
        return ans==7, s, ans
    else:
        #print(i, 'left', s, ans)
        p = i + s.count('+') + s.count('-')
        s_temp = s[:p]+'-'+s[p:]
        ans_temp = ans - ls[i]
        tf, s_temp, ans_temp = dfs(i+1, s_temp, ans_temp)
        if tf:
            return True, s_temp, ans_temp
        else:
            #print(i, 'right', s, ans)
            p = i + s.count('+') + s.count('-')
            s_temp = s[:p]+'+'+s[p:]
            ans_temp = ans + ls[i]
            tf, s_temp, ans_temp = dfs(i+1, s_temp, ans_temp)
            return tf, s_temp, ans_temp
            

tf, s, ans = dfs(1, s, ans)
print(s+'=7')

Submission status: Accepted

Solution code:
def dfs(array: list, index: int, calc: str, result: int):
    if index == len(array):
        if result == 7:
            print("{}=7".format(calc))
            exit(0)

    if index == 0:
        dfs(array, index + 1, array[index], int(array[index]))
    elif index < len(array):
        dfs(array, index + 1, calc + "-" + array[index], result - int(array[index]))
        dfs(array, index + 1, calc + "+" + array[index], result + int(array[index]))

array = list(input())
dfs(array, 0, "", 0)

Submission status: Accepted

Solution code:
def dfs(i: int, t: int, op: str):
  if i == 3:
    if t == 7:
      return op
    else:
      return ""

  return dfs(i + 1, t + s[i + 1], op + "+") + dfs(i + 1, t - s[i + 1], op + "-")

s = list(map(int, list(input())))
op = ""

op = dfs(0, s[0], op)
ans = str(s[0]) + op[0] + str(s[1]) + op[1] + str(s[2]) + op[2] + str(s[3]) + "=7"
print(ans)

Submission status: Accepted

Solution code:
a = input()

for i in range(2**3):
    total = int(a[0])
    ans = a[0]
    for j in range(3):
        if i & (1<<j):
            total += int(a[j+1])
            ans += '+' + a[j+1]
        else:
            total -= int(a[j+1])
            ans += '-' + a[j+1]
    if total == 7:
        print(ans+'=7')
        exit(0)

Submission status: Accepted

Solution code:
def test(array: list, index: int, calc: str, result: int):
    # print("index:{}".format(index))
    # print("calc:{}".format(calc))
    # 配列の最後までチェックしたら終了
    if index == len(array):
        if result == 7:
            print("{}=7".format(calc))
            exit(0)
    if index == 0:
        test(array,
             index + 1,
             array[index],
             int(array[index]))
    elif index <= len(array) - 1:
        test(array,
             index + 1,
             calc + "-" + array[index],
             result - int(array[index]))
        test(array,
             index + 1,
             calc + "+" + array[index],
             result + int(array[index]))


array = list(input())
test(array, 0, "", 0)

Submission status: Accepted

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

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

    formula = ""
    for num, op in zip(S, OP + [""]):
        formula += str(num) + op
    if eval(formula) == 7:
        print(formula + "=7")
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin 

ABCD = stdin.readline().rstrip()
A = int(ABCD[0])
B = int(ABCD[1])
C = int(ABCD[2])
D = int(ABCD[3])

def func1(ABCD,k):
    if k==len(ABCD)-1:
        return [[ABCD[k]],["-"+ABCD[k]]]
    prev_output = func1(ABCD,k+1)
    output = []
    if k==0:
        for ele in prev_output:
            temp = [ABCD[k]]
            temp.extend(ele)
            output.append(temp)
        return output

    for ele in prev_output:
        temp = [ABCD[k]]
        temp.extend(ele)
        output.append(temp)

        temp = ["-"+ABCD[k]]
        temp.extend(ele)
        output.append(temp)
    return output

def search_combi(combinations):
    for combi in combinations:
        tot_sum = 0
        for ele in combi:
            tot_sum+=int(ele)
        if tot_sum==7:
            return combi

combinations = func1(ABCD,0)
#print("search_copmbi:",search_combi(combinations))
def make_answer(numbers):
    output_string=""
    for i,num in enumerate(numbers):
        num_int = int(num)
        if i==0:
            output_string += num
        else:
            if num_int<0:
                output_string += "-"+num[1]
            else:
                output_string += "+"+num
    return output_string+"=7"


print(make_answer(search_combi(combinations)))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = input()
m = len(n)-1
for i in range(2 ** m):
    ops = []
    N = [int(n[0]), int(n[1]), int(n[2]), int(n[3])]
    for j in range(m):
        if (i >> j) & 1:
            ops.append("+")
        else:
            N[j + 1] *= -1
            ops.append("-")
    if sum(N) == 7:
        print(n[0]+ops[0]+n[1]+ops[1]+n[2]+ops[2]+n[3]+"=7")
        break

Submission status: Accepted

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

Submission status: Accepted

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

for bit in range(1 << (n-1)):
    f = s[0]

    for i in range(n - 1):
        if bit & (1 << i):
            f += "+"
        else:
            f += "-"
        f += s[i + 1]

    ans = eval(f)
    if ans == 7:
        res = f + "=7"
        break

print(res)

Submission status: Accepted

Solution code:
n = [x for x in input()]
op_cnt = len(n) - 1
for i in range(2 ** op_cnt):
    op = ["-"] * op_cnt
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt - 1 - j] = "+"
    fomula = list(sum(zip(n,op),()))
    fomula.append(n[-1]) 

    if eval(''.join(fomula))== 7:
    	print(''.join(fomula) +'=7')
    	break

Submission status: Accepted

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

s = ''
f = lambda i, op: abcdStr[0] + ("+" if i < 2 else "-") + abcdStr[1] + ("+" if i % 2 == 0 else "-") + abcdStr[2] + op + abcdStr[3] + "=7"
for i in range(4):
    n = abcd[0]
    n = n + abcd[1] if i < 2 else n - abcd[1]
    n = n + abcd[2] if i % 2 == 0 else n - abcd[2]
    if n + abcd[3] == 7:
        s = f(i, "+")
        break
    elif n - abcd[3] == 7:
        s = f(i, "-")
        break
print(s)

Submission status: Accepted

Solution code:
s = input()
for i in range(8):
    op = list("-".join(list(s)))
    for j in range(3):
        if i & (1 << j):
            op[j + j + 1] = '+'
    op = "".join(op)
    if eval(op) == 7:
        print(op + "=7")
        break

Submission status: Accepted

Solution code:
s = input()
ans = []
def pm(i,h,k):
  if i == 3:
    if k == 7:
      ans.append(s[0]+h[0]+s[1]+h[1]+s[2]+h[2]+s[3]+'='+'7')

      
  else:
    pm(i+1,h + ['+'],k+int(s[i+1]))
    pm(i+1,h + ['-'],k-int(s[i+1]))
pm(0,[],int(s[0]))
print(ans[0])

Submission status: Accepted

Solution code:
from itertools import product

abcd = input()

for pattern in product(["-", "+"],repeat=3):
    pattern = list(pattern)
    res = int(abcd[0])
    f = [abcd[0]]
    for v, op in zip(abcd[1:], pattern):
        f.append(op)
        f.append(v)
        if op == "+":
            res += int(v)
        elif op == "-":
            res -= int(v)
    if res == 7:
        f.append("=7")
        print("".join(f))
        break

Submission status: Accepted

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

a,b,c,d=list(input())
op=['+','-']

def calc():
    for op1 in op:
        for op2 in op:
            for op3 in op:
                res=a+op1+b+op2+c+op3+d
                if eval(res)==7:
                    return res

print(calc()+'=7')

Submission status: Accepted

Solution code:
s = list(str(input()))

for i in range(2**3):
    t = ['']
    ans = int(s[0])
    for j in range(3):
        if (i >> j) & 1:
            t.append('+')
            ans += int(s[j+1])
        else:
            t.append('-')
            ans -= int(s[j+1])
    if ans == 7:
        siki = ''
        for i in range(4):
            siki += t[i]+s[i]
        siki += '=7'
        print(siki)
        exit()

Submission status: Accepted

Solution code:
*A, = list(input())
s = ['+', '-']
for i in range(2**3):
    formula = A[0]
    for j in range(3):
        if i >> j & 1:
            formula += s[0]
        else:
            formula += s[1]
        formula += A[j+1]
    if eval(formula) == 7:
        print(formula+'=7')
        exit()

Submission status: Accepted

Solution code:
s=input()

for i in range(2**3):
    S=s[0]
    tot=int(s[0])
    for j in range(3):
        if (i>>j)&1:
            S+='+'+s[j+1]
            tot+=int(s[j+1])
        else:
            S+='-'+s[j+1]
            tot-=int(s[j+1])
    if tot==7:
        print(S+'=7')
        exit(0)

Submission status: Accepted

Solution code:
n = list(input())
a = int(n[0])
b = int(n[1])
c = int(n[2])
d = int(n[3])
tmp = 0
ans = ''
for i in range(8):
    j = i

    if bin(j & 1) == bin(1):
        tmp = a + b
        ans = str(a) + '+' + str(b)
    else:
        tmp = a - b
        ans = str(a) + '-' + str(b)
    if bin(j>>1 & 1) == bin(1):
        tmp += c
        ans += '+' + str(c)
    else:
        tmp -= c
        ans += '-' + str(c)
    if bin(j>>2 & 1) == bin(1):
        tmp += d
        ans += '+' + str(d)
    else:
        tmp -= d
        ans += '-' + str(d)
    # print(i,bin(j & 1),bin(j>>1),bin(j>>2),ans)

    if tmp == 7:
        print(ans + '=7')
        break

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    Num = list(map(int, list(input().strip("\n"))))
    for i in range(8): #0: +; 1: -
        ans = Num[0]
        d = i
        toPrint = str(Num[0])
        for k in range(3):
            if d % 2 == 0: 
                ans += Num[k + 1]
                toPrint += "+" + str(Num[k + 1])
            else: 
                ans -= Num[k + 1]
                toPrint += "-" + str(Num[k + 1])
            d //= 2
        if ans == 7:
            toPrint += "=7"
            print(toPrint)
            break


    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
a = list(input())
a = [int(i) for i in a]
for bit in range(1<<3):
    ans = a[0]
    ans1 = []
    for i in  range(3):
        mask = 1<<i
        if mask&bit:
            ans = (ans+a[i+1])
            ans1.append('+')
        else:
            ans = (ans-a[i+1])
            ans1.append('-')
    
    if ans==7:
        ans2 = ans1
ans3 = []
for i in range(3):
    ans3.append(str(a[i]))
    ans3.append(ans2[i])
ans3.append(str(a[3]))
ans3.append('=7')
ans4 =''.join(ans3)
print(ans4)

Submission status: Accepted

Solution code:
x = input()
p = ['+','-']
def cal(a,b,c,x):
    res = int(x[0])
    if a:res-=int(x[1])
    else:res+=int(x[1])
    if b:res-=int(x[2])
    else:res+=int(x[2])
    if c:res-=int(x[3])
    else:res+=int(x[3])
    if res == 7:
        return True
    else:return False
    
        
for i in range(2):
    for j in range(2):
        for k in range(2):
            if cal(i,j,k,x):
                print(x[0]+p[i]+x[1]+p[j]+x[2]+p[k]+x[3]+'=7')
                exit(0)

Submission status: Accepted

Solution code:
# Problem C - Train Ticket

# input
ABCD = input()
A = ABCD[0]
B = ABCD[1]
C = ABCD[2]
D = ABCD[3]

# initialization
pattern_list = []
for i in range(2**3):
    p = ['-']*3
    for j in range(3):
        if (i>>j)&1:
            p[j] = '+'
    pattern_list.append(p)

# check loop
for p in pattern_list:
    calc_str = A + p[0] + B + p[1] + C + p[2] + D
    if eval(calc_str)==7:
        calc_str += '=7'
        print(calc_str)
        break

Submission status: Accepted

Solution code:
S = list(input())
opt = ['-', '+']
for i in range(8):
    now = S[0]
    for j in range(3):
        if i >> j & 1:
            now += opt[1]
        else:
            now += opt[0]
        now += S[j + 1]
    if eval(now) == 7:
        print(now + "=7")
        exit()

Submission status: Accepted

Solution code:
def kipp(i,f):
    if i == 3:
        if eval(f) == 7:
            print(f+"=7")
            exit()
    else:
        kipp(i+1,f+"+"+s[i+1])
        kipp(i+1,f+"-"+s[i+1])

s = input()
kipp(0,s[0])

Submission status: Accepted

Solution code:
s=input()

for i in range(2**3):
    S=s[0]
    Sum=int(s[0])
    for j in range(3):
        if (i>>j)&1:
            S+='+'+s[j+1]
            Sum+=int(s[j+1])
        else:
            S+='-'+s[j+1]
            Sum-=int(s[j+1])
    if Sum == 7:
        print(S+'=7')
        exit()

Submission status: Accepted

Solution code:
string = input()
a, b, c, d = [int(string[i]) for i in range(4)]
op_dict = {"1": "+", "0": "-"}

for i in range(8):
    ops = bin(i)[2:].zfill(3)
    res = a
    if op_dict[ops[0]] == "+":
        res += b
    else:
        res -= b
    if op_dict[ops[1]] == "+":
        res += c
    else:
        res -= c
    if op_dict[ops[2]] == "+":
        res += d
    else:
        res -= d

    if res == 7:
        print("".join([str(a), op_dict[ops[0]], str(b), op_dict[ops[1]], str(c), op_dict[ops[2]], str(d), "=7"]))
        exit()

Submission status: Accepted

Solution code:
S = input()
a, b, c, d = int(S[0]), int(S[1]), int(S[2]), int(S[3])
if a+b+c+d == 7:
    print(str(a)+'+'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
elif a+b+c-d == 7:
    print(str(a)+'+'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
elif a+b-c+d == 7:
    print(str(a)+'+'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
elif a+b-c-d == 7:
    print(str(a)+'+'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
elif a-b+c+d == 7:
    print(str(a)+'-'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
elif a-b+c-d == 7:
    print(str(a)+'-'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
elif a-b-c+d == 7:
    print(str(a)+'-'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
elif a-b-c-d == 7:
    print(str(a)+'-'+str(b)+'-'+str(c)+'-'+str(d)+'=7')

Submission status: Accepted

Solution code:
n = input()
op = [bin(i)[2:].zfill(3) for i in range(8)]
for i in range(8):
    cnt = int(n[0])
    ans = [n[0]]
    for j in range(3):
        if op[i][j] == "0":
            cnt += int(n[j+1])
            ans.append("+")
        else:
            cnt -= int(n[j+1])
            ans.append("-")
        ans.append(n[j+1])
    if cnt == 7:
        ans += ["=", "7"]
        print("".join(ans))
        exit()

Submission status: Accepted

Solution code:
s=input()
N=list(map(int,s))
for p in range(1<<3):
    t = N[0]
    ans = str(t)
    for i in range(1,4):
        if p&1:
            t+=N[i]
            ans+='+'+str(N[i])
        else:
            t-=N[i]
            ans+='-'+str(N[i])
        p>>=1
    if t==7:
        print(ans+'=7')
        exit()

Submission status: Accepted

Solution code:
S = input()
k = []
for i in range(4):
    k.append(S[i])
flag = 0
a = k[0]
b = k[1]
c = k[2]
d = k[3]
A = int(a)
B = int(b)
C = int(c)
D = int(d)
if A+B+C+D == 7:
    print(a+"+"+b+"+"+c+"+"+d+"="+"7")
    flag += 1
elif A+B+C-D == 7:
    if flag == 0:
        print(a+"+"+b+"+"+c+"-"+d+"="+"7")
        flag += 1
elif A+B-C+D == 7:
    if flag == 0:
        print(a+"+"+b+"-"+c+"+"+d+"="+"7")
        flag += 1
elif A+B-C-D == 7:
    if flag == 0:
        print(a+"+"+b+"-"+c+"-"+d+"="+"7")
        flag += 1
elif A-B-C+D == 7:
    if flag == 0:
        print(a+"-"+b+"-"+c+"+"+d+"="+"7")
        flag += 1
elif A-B+C-D == 7:
    if flag == 0:
        print(a+"-"+b+"+"+c+"-"+d+"="+"7")
        flag += 1
elif A-B+C+D == 7:
    if flag == 0:
        print(a+"-"+b+"+"+c+"+"+d+"="+"7")
        flag += 1
elif A-B-C-D == 7:
    if flag == 0:
        print(a+"-"+b+"-"+c+"-"+d+"="+"7")
        flag += 1

Submission status: Accepted

Solution code:
from itertools import product
A, B, C, D = list(input())
l = len(A)

for ops in 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:
from itertools import product


def main():
    op = ['+', '-']
    numbers = list(map(int, list(input())))
    for now_op in product(op, repeat=3):
        now = numbers[0]
        for i in range(3):
            if now_op[i] == '+':
                now += numbers[i + 1]
            else:
                now -= numbers[i + 1]
        if now == 7:
            answer = ""
            for i in range(3):
                answer += str(numbers[i]) + now_op[i]
            answer += str(numbers[3]) + "=7"
            print(answer)
            break


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

a = [int(i) for i in STR()]

op = ['+', '-']
ops = ['', '', '']
for ops[0] in op:
    for ops[1] in op:
        for ops[2] in op:
            tmp = a[0]
            for i in range(3):
                if ops[i] == '+':
                    tmp += a[i + 1]
                else:
                    tmp -= a[i + 1]
            if tmp == 7:
                ans = str(a[0])
                for i in range(3):
                    ans += ops[i] + str(a[i + 1])
                ans += '=7'
                print(ans)
                exit()

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
A,B,C,D = input()
for a in '+-':
    for b in '+-':
        for c in '+-':
            f = "{0}{1}{2}{3}{4}{5}{6}".format(A,a,B,b,C,c,D)
            if eval(f)==7:
                print(f + '=7')
                exit()

Submission status: Accepted

Solution code:
a = input()

for i in range(8):
    l = []
    for j in range(3):
        if i & (1 << j):
            l.append('+')
        else:
            l.append('-')
    s = ''
    l.append(' ')
    for p, q in zip(list(a), l):
        s += p + q
    if eval(s) == 7:
        print(s[:-1] + '=7')
        exit(0)

Submission status: Accepted

Solution code:
s = input()

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

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

Submission status: Accepted

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

def calc(x, y, sym):
    if sym == 0:
        return x + y
    else:
        return x - y

def symbol(sym):
    if sym == 0:
        return '+'
    else:
        return '-'

for i in range(2):
    for j in range(2):
        for k in range(2):
            tmp = calc(a[0], a[1], i)
            tmp = calc(tmp, a[2], j)
            tmp = calc(tmp, a[3], k)
            if tmp == 7:
                b = list(map(symbol, [i, j, k]))
                print("{}{}{}{}{}{}{}=7".format(a[0], b[0], a[1], b[1], a[2], b[2], a[3]))
                break
        else:
            continue
        break
    else:
        continue
    break

Submission status: Accepted

Solution code:
a = list(input())
op = [bin(i)[2:].zfill(3) for i in range(8)]
for i in range(8):
    ans = int(a[0])
    ans_ar = [a[0]]
    for j in range(3):
        if op[i][j] == "0":
            ans += int(a[j+1])
            ans_ar.append("+")
        else:
            ans -= int(a[j+1])
            ans_ar.append("-")
        ans_ar.append(a[j+1])
    if ans == 7:
        ans_ar = ans_ar + ["=", "7"]
        print("".join(ans_ar))
        exit()

Submission status: Accepted

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

for i in range(1<<n):
    sum=0
    st=''
    for j in range(n):

        # if i & (1 <<j):sum +=int(a[j]); st+= '+' + a[j] 
        # else: sum -=int(a[j]); st+= '-' + a[j]
        if i & (1 <<j):st+= '+' + a[j] 
        else:  st+= '-' + a[j]

    # if sum==7:break
    if eval(st[1:]) == 7:break

print(st[1:] + '=7')

Submission status: Accepted

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

for i in range(1<<n):
    sum=0
    st=''
    for j in range(n):

        if i & (1 <<j):sum +=int(a[j]); st+= '+' + a[j] 
        else: sum -=int(a[j]); st+= '-' + a[j]

    if sum==7:break

print(st[1:] + '=7')

Submission status: Accepted

Solution code:
s = str(input())
a = ["+","-"]
for i in a:
    for j in a:
        for k in a:
            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")
                exit()