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

for mask in range(1 << 3):
    tmp = int(num[0])
    ans_str = num[0]
    for i in range(3):
        if mask >> i & 1 == 1:
            tmp += int(num[i + 1])
            ans_str += '+' + num[i + 1]
        else:
            tmp -= int(num[i + 1])
            ans_str += '-' + num[i + 1]
    if tmp == 7:
        print(ans_str + '=7')
        exit()

Submission status: Accepted

Solution code:
N = input()
num_list = list(N)
op = ["+", "-"]
flag = False
for i in range(len(op)):
    for j in range(len(op)):
        for k in range(len(op)):
            eq = num_list[0] + op[i] + num_list[1] + \
                op[j] + num_list[2] + op[k] + num_list[3]
            ans = eval(eq)
            if ans == 7:
                flag = True
                break
        if flag == True:
            break
    if flag == True:
        break
print(eq + "=" + str(ans))

Submission status: Accepted

Solution code:
l = list(input())
for i in range(8):
  s = int(l[0])
  b = bin(i)[2:].zfill(3)
  op = ["", "", ""]
  for j in range(len(b)):
    if b[j] == "0":
      s += int(l[j+1])
      op[j] = "+"
    else:
      s -= int(l[j+1])
      op[j] = "-"
  if s == 7:
    print(l[0]+op[0]+l[1]+op[1]+l[2]+op[2]+l[3]+"=7")
    break

Submission status: Accepted

Solution code:
a,*l=input()
for i in range(8):
  f=a
  for j in [0,1,2]: f+='-+'[i>>j&1]+l[j]
  if eval(f)==7: print(f+'=7'); exit()

Submission status: Accepted

Solution code:
a,*l=input()
for i in range(8):
  f=a
  for j in range(3):
    f+='-+'[i>>j&1]+l[j]
  if eval(f)==7: print(f+'=7'); exit()

Submission status: Accepted

Solution code:
# C - Train Ticket
# https://atcoder.jp/contests/abc079/tasks/abc079_c
S = input()
n = len(S) - 1
TOTAL = 7
for i in range(1 << n):
    x = S[0]
    for j in range(n):
        if i & 1 << j:
            x += "+"
        else:
            x += "-"
        x += S[j + 1]
    if eval(x) == TOTAL:
        print(f"{x}={TOTAL}")
        break
    else:
        continue
    break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys,math,collections,itertools
input = sys.stdin.readline

a,b,c,d =list(input().rstrip())
op_lis = itertools.product('+-',repeat=3)
for op in op_lis:
    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')
        exit()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():
    ans,p,m = '','+','-'
    n = input().rstrip('\n')
    for i in range(2**3):
        ans = [n[0], p, n[1], p, n[2], p, n[3]]
        for j in range(3):
            if i>>j&1:
                ans[2*j+1] = m
        if eval(''.join(ans)) == 7:
            break
    ans = ''.join(ans) + '=7'
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():
    ans = ""
    nums = list(map(int, list(input().rstrip("\n"))))
    
    for i in range(2**3):
        ts = sum(nums)
        ops = ['+']*3
        for j in range(3):
            if i>>j&1:
                ts -= nums[j+1]*2
                ops[j]='-'
        if ts == 7:
            for i in range(3):
                ans += str(nums[i])+ops[i]
            ans += str(nums[3])+"=7"
            break
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import product
s = list(input())
n = len(s)

pattern = list(product(['+', '-'], repeat=n-1))

for i in range(2 ** (n-1)):
    formula = s[0]
    for j, k in zip(pattern[i], s[1:]):
        formula += (j + k)
    if eval(formula) == 7:
        print("{}=7".format(formula))
        break

Submission status: Accepted

Solution code:
N = int(input())

A = N // 1000
B = (N - 1000 * A) // 100
C = (N - 1000 * A - 100 * B) // 10
D = N % 10

for i in range(2):
  for j in range(2):
    for k in range(2):
      ans = A
      if i==1:
        op1 = '+'
        ans += B
      else:
        op1 = '-'
        ans -= B
      if j==1:
        op2 = '+'
        ans += C
      else:
        op2 = '-'
        ans -= C
      if k==1:
        op3 = '+'
        ans += D
      else:
        op3 = '-'
        ans -= D
      if ans==7:
        print(str(A)+op1+str(B)+op2+str(C)+op3+str(D)+'=7')
        break
    else:
      continue
    break
  else:
    continue
  break

Submission status: Accepted

Solution code:
A = input()
op_cnt = len(A)-1
for j in range(2**op_cnt):
  op = ['-'] * op_cnt
  for k in range(op_cnt):
    if (j>>k) & 1:
      op[op_cnt - 1 - k] = '+'
      
  formula = ''
  for p_n, p_o in zip(A, op + ['']):
    formula += (p_n + p_o)
  if eval(formula) == 7:
    print(formula + '=7')
    break

Submission status: Accepted

Solution code:
S = input()

for i in range(2**3):
    exp = []
    for j in range(4):
        exp.append(S[j])
        if j == 3:
            None
        elif ((i >> j) & 1):
            exp.append('+')
        else:
            exp.append('-')
    
    a = 0
    neg = False
    for j in range(len(exp)):
        if exp[j] == '-':
            neg = True
        elif exp[j] == '+':
            neg = False
        else:
            if neg:
                a -= int(exp[j])
            else:
                a += int(exp[j])
    
    if a == 7:
        print(''.join(exp)+'=7')
        break

Submission status: Accepted

Solution code:
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline


def F(S, i):
    if i == len(S):
        if eval(''.join(S)) == 7:
            print(''.join(S) + "=7")
            return True
        else:
            return False

    S1 = S.copy()
    S1.insert(i, "+")
    if F(S1, i + 2):
        return True
    S2 = S.copy()
    S2.insert(i, "-")
    if F(S2, i + 2):
        return True
    return False


S = list(input().rstrip('\n'))
F(S, 1)


# def cal(Sn, opt):
#     ans = Sn[0]
#     for i in range(3):
#         if opt[i] == '+':
#             ans += Sn[i+1]
#         else:
#             ans -= Sn[i+1]
#     return ans


# S = list(input().rstrip('\n'))
# Sn = [int(i) for i in S]
# op = ['+', '-']
# opL = [(i, j, k) for i in op for j in op for k in op]

# for opt in opL:
#     if cal(Sn, opt) == 7:
#         break

# ans = ''
# for i in range(3):
#     ans += S[i] + opt[i]
# ans += S[3] + '=7'
# print(ans)

Submission status: Accepted

Solution code:
a,b,c,d = open(0).read().rstrip()

from itertools import product
for o,p,q in product(['-','+'],repeat=3):
    state = a+o+b+p+c+q+d
    if eval(state) == 7:
        print(state+'=7')
        break

Submission status: Accepted

Solution code:
ABCD = input()
a, b, c, d = map(int, list(ABCD))
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()

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

Submission status: Accepted

Solution code:
a, b, c, d = map(str, list(input()))
data = ["+", "-"]
for x in range(2):
    for y in range(2):
        for z in range(2):
            if eval(a + data[x] + b + data[y] + c + data[z] + d) == 7:
                print("{}{}{}{}{}{}{}{}{}".format(a, data[x], b, data[y], c, data[z], d, "=", "7"))
                exit()

Submission status: Accepted

Solution code:
S = input()
if int(S[0])+int(S[1])+int(S[2])+int(S[3])==7:
    print(f'{S[0]}+{S[1]}+{S[2]}+{S[3]}=7')
elif int(S[0])+int(S[1])+int(S[2])-int(S[3])==7:
    print(f'{S[0]}+{S[1]}+{S[2]}-{S[3]}=7')
elif int(S[0])+int(S[1])-int(S[2])+int(S[3])==7:
    print(f'{S[0]}+{S[1]}-{S[2]}+{S[3]}=7')
elif int(S[0])-int(S[1])+int(S[2])+int(S[3])==7:
    print(f'{S[0]}-{S[1]}+{S[2]}+{S[3]}=7')
elif int(S[0])+int(S[1])-int(S[2])-int(S[3])==7:
    print(f'{S[0]}+{S[1]}-{S[2]}-{S[3]}=7')
elif int(S[0])-int(S[1])+int(S[2])-int(S[3])==7:
    print(f'{S[0]}-{S[1]}+{S[2]}-{S[3]}=7')
elif int(S[0])-int(S[1])-int(S[2])+int(S[3])==7:
    print(f'{S[0]}-{S[1]}-{S[2]}+{S[3]}=7')
else:
    print(f'{S[0]}-{S[1]}-{S[2]}-{S[3]}=7')

Submission status: Accepted

Solution code:
a=input()
l=[int(a[0]),int(a[1]),int(a[2]),int(a[3])]

for i in range (2**3):
    op=[]
    for j in range(3):
        if (i>>j) & 1 == 1:
            op.append(+1)
        else:
            op.append(-1)
    # print(op)
    # print('{}{}{}{}{}{}{}'.format(l[0],op[0],l[1],op[1],l[2],op[2],l[3]))
    # print(l)
    # print(op)

    # l[0]+(op[0]*l[1])+(op[1]*l[2])+(op[2]*l[3])==7
    if l[0]+(op[0]*l[1])+(op[1]*l[2])+(op[2]*l[3])==7: 
        options=[]
        for option in op:
            if option ==1:
                options.append('+')
            else:
                options.append("-")
        print('{}{}{}{}{}{}{}=7'.format(l[0],options[0],l[1],options[1],l[2],options[2],l[3]))
        break

Submission status: Accepted

Solution code:
s=input()
a,b,c,d=[int(s[i]) for i in range(4)]
for i in range (2**3):
    res=a
    ans=[str(a)]
    for j in range (3):
        if i >> j &1:
            res+=int(s[j+1])
            ans+=["+",s[j+1]]
        else:
            res-=int(s[j+1])
            ans+=["-",s[j+1]]
    if res==7:
        ans+=["=7"]
        print("".join(ans))
        break

Submission status: Accepted

Solution code:
N = str(input())
A = int(N[0])
B = int(N[1])
C = int(N[2])
D = int(N[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:
num_=input()
op_=len(num_)-1
for i in range(2**op_):
  op=["-"]*op_
  for j in range(op_):
    if ((i>>j)&1):
      op[op_-1-j]="+"
  formula=""
  op.append("")
  for p_num,p_op in zip(num_,op):
    formula+=p_num+p_op
  if eval(formula)==7:
    print(formula+"=7")
    break

Submission status: Accepted

Solution code:
n = input()
m = len(n)-1
for i in range(2**m):
  op = ['-'] * m
  for j in range(m):
    if ((i>>j) & 1):
      op[m -1 - j] = '+'
  formula = ''
  for p, q in zip(n, op+['']):
    formula += (p+q)
  if eval(formula) == 7:
    print(formula + '=7')
    exit()

Submission status: Accepted

Solution code:
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline


def cal(Sn, opt):
    ans = Sn[0]
    for i in range(3):
        if opt[i] == '+':
            ans += Sn[i+1]
        else:
            ans -= Sn[i+1]
    return ans


S = list(input().rstrip('\n'))
Sn = [int(i) for i in S]
op = ['+', '-']
opL = [(i, j, k) for i in op for j in op for k in op]

for opt in opL:
    if cal(Sn, opt) == 7:
        break

ans = ''
for i in range(3):
    ans += S[i] + opt[i]
ans += S[3] + '=7'
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import sys
S = sys.stdin.readline().rstrip()
A,B,C,D = [int(c) for c in S]

def calc(s,i,ops):
    #print(i,s,ops)
    if i == 4:
        if s == 7:
            print(S[0]+ops[0]+S[1]+ops[1]+S[2]+ops[2]+S[3]+"=7")
            exit(0)
        else:
            return
    calc(s+int(S[i]),i+1,ops+["+"])
    calc(s-int(S[i]),i+1,ops+["-"])

calc(int(S[0]),1,[])

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():
    NUM = list(input().rstrip())
    NUM_I = [int(i) for i in NUM]
    ps = [1, 1, 1]

    for i in range(8):
        for j in range(3):
            if (i >> j) & 1:
                ps[j] = -1
                # print(ps)
                # print('IN')
            else:
                ps[j] = 1
            ans = NUM_I[0] + ps[0]*NUM_I[1] + ps[1]*NUM_I[2] + ps[2]*NUM_I[3]
            if ans == 7:
                ps_s = ['+' if i>0 else '-' for i in ps]
                # print(ps_s)
                ans_s = [NUM[0]]
                for i in range(3):
                    ans_s.append(ps_s[i])
                    ans_s.append(NUM[i+1])
                ans_s.append('=7')
                print(''.join(ans_s))
                return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import exit

a, b, c, d = map(int, list(input()))

x = ['+', '-']


def cul(x, y, z):
    if z == 0:
        return x + y
    else:
        return x - y


for i in range(8):
    op = [0, 0, 0]
    for j in range(3):
        op[j] = i >> j & 1
    if cul(cul(cul(a, b, op[0]), c, op[1]), d, op[2]) == 7:
        print(a, x[op[0]], b, x[op[1]], c, x[op[2]], d, '=7', sep='')
        exit()

Submission status: Accepted

Solution code:
def a(t,i):
    if i==l:
        if eval(t)==7:
            print(t+'=7')
            exit()
        return
    a(t+'+'+s[i+1],i+1)
    a(t+'-'+s[i+1],i+1)

s = input()
l = len(s)-1
a(s[0],0)

Submission status: Accepted

Solution code:
#abc079-c
#bit全探索をやっていこうと　思うわよ
abcd = input()
a = abcd[0]
b = abcd[1]
c = abcd[2]
d = abcd[3]

total = 7
#０か１かの、選択肢である記号部分は３つあるわ
n = 3
#全探索すべきは、2^nだわよ
k = 0
for i in range(2 ** n):
  #Aだけ入れた文字列に、”＋” or ”-” を入れて、その次の文字(abcd[j + 1])を続けて入れるわよ
    way = a
    for j in range(n):
        if ((i >> j) & 1):
            way += "+"
            way += (abcd[j + 1])
        else:
            way += "-"
            way += (abcd[j + 1])
    #evalで引数の文字列を、式として計算するわ
    ans = eval(way)
    #あら、７になったわね
    if ans == 7:
      #これで優勝
      print(way + "=7")
      k = 1
      break
if k != 1:
    print("No")

Submission status: Accepted

Solution code:
def main():
    a = list(map(int, list(input())))
    for i in range(2**3):
        cnt = a[0]
        pm = []
        for j in range(3):
            if ((i >> j) & 1):
                cnt += a[j+1]
                pm.append('+')
            else:
                cnt -= a[j+1]
                pm.append('-')
        if cnt == 7:
            print('{}{}{}{}{}{}{}=7'.format(a[0], pm[0], a[1], pm[1], a[2], pm[2], a[3]))
            break

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools
A, B, C, D = input()
for i in itertools.product(['+', '-'], repeat=3):
    if eval(A+i[0]+B+i[1]+C+i[2]+D) ==7:
        print(A+i[0]+B+i[1]+C+i[2]+D+'=7')
        exit()

Submission status: Accepted

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

Submission status: Accepted

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

for bit in range(2 ** 3):
    value = ABCD[0]
    equation = str(ABCD[0])
    for i in range(3):
        if bit & (1 << i):
            value += ABCD[i + 1]
            equation = equation + '+' + str(ABCD[i + 1])
        else:
            value -= ABCD[i + 1]
            equation = equation + '-' + str(ABCD[i + 1])
    if value == 7:
        print(equation + '=7')
        break

Submission status: Accepted

Solution code:
nums = input()
op = [""]*3
for i in range(2**3):
    b = bin(i)[2:]
    b = "0"*(3 - len(b)) + b
    for j in range(len(b)):
        if b[j] == "1":
            op[j] = "+"
        else:
            op[j] = "-"
    string = "".join(nums[i]+op[i] for i in range(3))+nums[-1]
    if eval(string) == 7:
        print(string + "=7")
        break

Submission status: Accepted

Solution code:
import sys
import itertools
a,b,c,d = map(int,list(input()))

def change_pnsign(op):
    if op == 1:
        op = "+"
        return op
    else:
        op = "-"
        return op


list = [1,-1]
for op1,op2,op3 in itertools.product(list,list,list):
    ans = a+op1*b+op2*c+op3*d
    if ans == 7:
        OP1=change_pnsign(op1)
        OP2=change_pnsign(op2)
        OP3=change_pnsign(op3)
        print(f"{a}{OP1}{b}{OP2}{c}{OP3}{d}=7")
        sys.exit()

Submission status: Accepted

Solution code:
from itertools import product

ABCD=input()
for tf in list(product([False,True],repeat=3)):
  sum_=int(ABCD[0])
  str_=ABCD[0]
  for j in range(3):
    if tf[j]==True:
      str_+="+"
      sum_+=int(ABCD[j+1])
    else:
      str_+="-"
      sum_-=int(ABCD[j+1])
    str_+=ABCD[j+1]
  if sum_==7:
    print(str_+"=7")
    exit()
print("No")

Submission status: Accepted

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

for i in range(1<<3):
    num = [a, b, c, d]
    for j in range(3):
        if i>>j & 1 != 1:  # 1桁目==1 がTrueではなかった場合
            num[j+1] *= -1
    ans = sum(num)
    if ans == 7:
        for k, n in enumerate(num):
            if n >= 0 and k > 0:
                print('+', n, sep='', end='')
            else:
                print(n, sep='', end='')
        else:
            print('=7', sep='')
        break

Submission status: Accepted

Solution code:
#abc079 train ticket
s = input()
for bit in range(1<<3):
    a = int(s[0])
    func = s[0]
    for i in range(3):
        if bit & (1<<i):
            func += '+'
            a += int(s[i+1])
        else : #もし1というフラグが立っていなければ、引くというプログラム
            func += '-'
            a -= int(s[i+1])
        func += s[i+1]
    
    if a == 7:
        print(func + '=7')
        exit()
print('No')

Submission status: Accepted

Solution code:
n = input()
for x in range(1 << 3):
    opr = ["-"] * 3
    for i in range(3):
        if x & (1 << i):
            opr[i] = "+"
    shiki = "%s%s%s%s%s%s%s" % (n[0], opr[0], n[1], opr[1], n[2], opr[2], n[3])
    if eval(shiki) == 7:
        print("%s=7" % shiki)
        break

Submission status: Accepted

Solution code:
a,b,c,d = map(lambda x: int(x), list(input()))

def get_str(i):
    if i >= 0:
        s = "+{}".format(i)
    else:
        s = "{}".format(i)
    return s

for i in range(1 << 3):
    ai, bi, ci, di = a, b, c, d
    if (i >> 2) % 2:
        bi = -b
    if (i >> 1) % 2:
        ci = -c
    if (i >> 0) % 2:
        di = -d

    if ai+bi+ci+di == 7:
        s = ""
        s += get_str(ai)
        s += get_str(bi)
        s += get_str(ci)
        s += get_str(di)
        s += "=7"
        print(s[1::])
        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] = '+'
  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:
a,b,c,d = input()
for i in range(2**3):
    x = ['-','-','-']
    for j in range(3):
        if i>>j&1:
            x[j] = '+'
    if eval(a+x[0]+b+x[1]+c+x[2]+d) == 7:
        print(a+x[0]+b+x[1]+c+x[2]+d + '=7')
        break

Submission status: Accepted

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

def m(x):
    re = a
    ls = [str(a)]
    for i in range(3):
        if (x>>i)&1 == 1 :
            re +=int(n[i+1])
            ls.append('+'+n[i+1])
        else:
            re -=int(n[i+1])
            ls.append('-'+n[i+1])
    return re, ls

for j in range(8):
    if m(j)[0]==7:
        print(''.join(m(j)[1])+'=7')
        exit()

Submission status: Accepted

Solution code:
from itertools import product

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

ops = product([1,-1],repeat=3)

for op in ops:
  test = a + b * op[0] + c * op[1] + d * op[2]
  if test == 7:
    _op = [""]*3
    for i in range(3):
      _op[i] = "+" if op[i] == 1 else "-"
    print("{}{}{}{}{}{}{}=7".format(a,_op[0],b,_op[1],c,_op[2],d))
    exit()
print(-1)

Submission status: Accepted

Solution code:
def dfs(i, f, sum):
  if i == 3:
    if sum == 7:
      print(f + '=7')
      exit()
      
  else:
    dfs(i+1, f + '-' + n[i+1], sum-int(n[i+1]))
    dfs(i+1, f + '+' + n[i+1], sum+int(n[i+1]))
    
n = input()
dfs(0, n[0], int(n[0]))

Submission status: Accepted

Solution code:

def abc079_c():
    stlist = input()

    def DFS(i,sum,li):
        if i == len(stlist)-1:
            if sum == 7:
                print(str(stlist[0])+str(li[0])+str(stlist[1])+str(li[1])+str(stlist[2])+str(li[2])+str(stlist[3])+"=7")
                exit()
            return

        #+
        li[i]="+"
        DFS(i+1,sum+int(stlist[i+1]),li)

        #-
        li[i]="-"
        DFS(i+1,sum-int(stlist[i+1]),li)

    DFS(0,int(stlist[0]),[[] for i in range(3)])










abc079_c()

Submission status: Accepted

Solution code:
from itertools import product

A,B,C,D=map(int,input())
O=["+","-"]
X=product(O,repeat=3)

for (p,q,r) in X:
    T="{}{}{}{}{}{}{}".format(A,p,B,q,C,r,D)
    if eval(T)==7:
        print("{}=7".format(T))
        break

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(2**3):
    op = ['+', '+', '+']
    for j in range(3):
        if (i >> j) & 1 == 1:
            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')
        sys.exit()

Submission status: Accepted

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

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

def sign(n):
    if n >= 0:
        return '+' 
    else:
        return '-' 

for i in b:
    for j in c:
        for k in d:
            if 7 == a + i + j + k:
                print('{}{}{}{}{}{}{}=7'.format(a, sign(i), abs(i), sign(j), abs(j), sign(k), abs(k)))
                exit(0)

Submission status: Accepted

Solution code:
import itertools as it
n=[x for x in input()]
In=list(it.product(['+','-'],repeat=3))
for k in range(8):
   ans = eval(n[0]+In[k][0]+n[1]+In[k][1]+n[2]+In[k][2]+n[3])
   if ans==7:
    print(n[0]+In[k][0]+n[1]+In[k][1]+n[2]+In[k][2]+n[3]+"=7")
    exit()

Submission status: Accepted

Solution code:
import sys
a, b, c, d = [n for n in list(input())]
n = 3

for bit in range(1<<n):
    #print(bit)
    op = []
    for i in range(n):
        if bit & (1<<i):
            op.append('+')
        else:
            op.append('-')
    #print(op)

    formula = a + op[2] + b + op[1] + c + op[0] + d
   
    if eval(formula) == 7:
        print(formula+'=7')
        sys.exit(0)

Submission status: Accepted

Solution code:
s = input()
for bit in range(1<<len(s)-1):
  f = s[0]
  
  for i in range(len(s)-1):
    if (bit>>i) & 1:
      f += '+'
    else:
      f += '-'
    f += s[i+1]
  
  if eval(f) == 7:
    print(f+'=7')
    exit()

Submission status: Accepted

Solution code:
S = input()
for i in range(1 << 3):
    op = ['+'] * 3
    for j in range(3):
        if i >> j & 1:
            op[j] = '-'
    res = ''
    for s, p in zip(S, op):
        res += s + p
    res += S[-1]
    if eval(res) == 7:
        res += '=7'
        print(res)
        break

Submission status: Accepted

Solution code:
abcd = input()

n = 2 ** 3
result = ''

for i in range(n):
  bin_n = bin(i)[2:]
  bin_n = '0' * (3 - len(bin_n)) + bin_n

  num = int(abcd[0])
  for j in range(3):
    if bin_n[j] == '0':
      num += int(abcd[j+1])

    else:
      num -= int(abcd[j+1])

  if num == 7:
    result = bin_n

print(abcd[0], end='')
print('+' if result[0] == '0' else '-', end='')
print(abcd[1], end='')
print('+' if result[1] == '0' else '-', end='')
print(abcd[2], end='')
print('+' if result[2] == '0' else '-', end='')
print(abcd[3], end='')
print('=7')

Submission status: Accepted

Solution code:
a,b,c,d=map(int,input())
A,B,C,D=str(a),str(b),str(c),str(d)
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:
import itertools
s = input()
plm = ['+','-']

for i in itertools.product(plm, repeat=3):
    moziretsu =s[0]+i[0]+s[1]+i[1]+s[2]+i[2]+s[3]
    if eval(moziretsu) == 7:
        print(moziretsu+'=7')
        break

Submission status: Accepted

Solution code:
S = input()
ans = 0
signal = ['']*3

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

    if ans == 7:
        print('%s%s%s%s%s%s%s=7' % (S[0], signal[0], S[1], signal[1], S[2], signal[2], S[3]))
        break
    else:
        ans = 0

Submission status: Accepted

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

import sys

def check(a,b,c,d,ans_pattern):
    ans_list=[b,c,d]
    ans=a
    for i in range(3):
        if ans_pattern[i]=="+":
            ans+=ans_list[i]
        else:
            ans-=ans_list[i]
    if ans==7:
        print("{}{}{}{}{}{}{}=7".format(a,ans_pattern[0],b,ans_pattern[1],c,ans_pattern[2],d))
        sys.exit() 

def main2():
    #000なら+++
    #001なら++-
    a,b,c,d=map(int,input())
    for i in range(2**3):
        ans_pattern=["+","+","+"]
        for j in range(3):
            if (i >> j)&1:
                ans_pattern[j]="-"
        check(a,b,c,d,ans_pattern)
 
if __name__=="__main__":
    main2()

Submission status: Accepted

Solution code:
S = input().strip()


for i in range(2**3):
  ans = S[0] ## 数式となる文字列
  _sum = int(S[0]) ## 合計値
  for j in range(3):
    if (i>>j)&1: ## それぞれのビットを右シフトして評価する
      """ビットが1のとき"""
      ans += "+" + S[j+1]
      _sum += int(S[j+1])
    else:
      """ビットが0のとき"""
      ans += "-" + S[j+1]
      _sum -= int(S[j+1])
  if _sum == 7:
    ans += "=7"
    print(ans)
    quit()

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');exit()
if a-b+c+d==7:print(str(a)+'-'+str(b)+'+'+str(c)+'+'+str(d)+'=7');exit()
if a+b-c+d==7:print(str(a)+'+'+str(b)+'-'+str(c)+'+'+str(d)+'=7');exit()
if a+b+c-d==7:print(str(a)+'+'+str(b)+'+'+str(c)+'-'+str(d)+'=7');exit()
if a-b-c+d==7:print(str(a)+'-'+str(b)+'-'+str(c)+'+'+str(d)+'=7');exit()
if a-b+c-d==7:print(str(a)+'-'+str(b)+'+'+str(c)+'-'+str(d)+'=7');exit()
if a-b-c-d==7:print(str(a)+'-'+str(b)+'-'+str(c)+'-'+str(d)+'=7');exit()
if a+b-c-d==7:print(str(a)+'+'+str(b)+'-'+str(c)+'-'+str(d)+'=7');exit()

Submission status: Accepted

Solution code:
import itertools

number = input()
A, B, C, D = (int(number[i]) for i in range(4))
for op1, op2, op3 in itertools.product(['+','-'], repeat=3):
    result = A
    if(op1 == '+'):
        result+=B
    else:
        result-=B
    if(op2 == '+'):
        result+=C
    else:
        result-=C
    if(op3=='+'):
        result+=D
    else:
        result-=D
    if result == 7:
        print(A,op1,B,op2,C,op3,D,'=7',sep='')
        break

Submission status: Accepted

Solution code:
#変数: S, num, formula
    
S = input()
num = len(S) - 1

for i in range(2**num):
    op=["-"]*num
    for j in range(num):
        if (i>>j)&1:
            op[num-j-1]="+"
            
    formula=""
    for op_S,op_num in zip(S,op+[""]):
        formula += op_S + op_num

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

Submission status: Accepted

Solution code:
import sys


S = [s for s in input()]
A = [int(s) for s in S]

for i in range(1 << 3):
    b = format(i, f'03b')[::-1]
    t = A[0]
    u = S[0]
    for j in range(3):
        if b[j] == '1':
            t += A[j + 1]
            u += "+" + S[j + 1]
        else:
            t -= A[j + 1]
            u += "-" + S[j + 1]
    if t == 7:
        print(u + "=7")
        sys.exit()