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()
N = 3


def add(n, s):
    if n == 0:
        #print(s)
        if eval(s) == 7:
            results.append(s)
        return 1
    else:
        sp = s[:n] + '+' + s[n:]
        sm = s[:n] + '-' + s[n:]
        return add(n-1, sp) + add(n-1, sm)

results = []
_ = add(N, S)
print(results[0]+'=7')

Submission status: Accepted

Solution code:
import itertools
ABCD = input()
for op in itertools.product(['+','-'], repeat=3):
    s = ABCD[0]+op[0]+ABCD[1]+op[1]+ABCD[2]+op[2]+ABCD[3]
    if eval(s) == 7:
        print(s+'=7')
        exit()

Submission status: Accepted

Solution code:
s=input()
op=['+', '-']
for op1 in op:
    for op2 in op:
        for op3 in op:
            tmp=s[0]+op1+s[1]+op2+s[2]+op3+s[3]
            if eval(tmp)==7:
                ans=tmp
print(ans+'=7')

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] = '+'
    f = ''
    for j in range(op_cnt):
        f += n[j] + op[j]
    f += n[-1]
    if eval(f) == 7:
        print(f + '=7')
        break

Submission status: Accepted

Solution code:
import itertools

l = list(input())

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

Submission status: Accepted

Solution code:
A, B, C, D = [int(x) for x in input()]
tmp = []

def dfs(P):
    global tmp
    if len(P)==3:
        tmp.append(P[:])
        return
    
    for op in ['+', '-']:
        P.append(op)
        dfs(P)
        P.pop()
        
dfs([])
for ops in tmp:
    ans = A
    for op, i in zip(ops, [B,C,D]):
        if op=='+':
            ans += i
        else:
            ans -= i
    if ans==7:
        print('{}{}{}{}{}{}{}=7'.format(A, ops[0], B, ops[1], C, ops[2], D))
        break

Submission status: Accepted

Solution code:
import itertools
s = list(input())
for ops in itertools.product(['+','-'],repeat=3):
  s_i = []
  for i in range(3):
    s_i.append(s[i])
    s_i.append(ops[i])
  s_i.append(s[-1])
  s_i = "".join(s_i)
  if eval(s_i)==7:
    print(s_i+"=7")
    exit()

Submission status: Accepted

Solution code:
S = input()
S_str = str(S)
S_list = []
for i in range(len(S_str)):
    S_list.append(int(S_str[i]))
ans = ''

for i in range(2**3):
    tmp = S_list[0]
    for j in range(1,4):
        if i & (1 << 3-j):
            tmp -= S_list[j]
        else:
            tmp += S_list[j]
    if tmp == 7:
        break
for n in range(3):
    ans += S_str[n]
    if i & (1 << 2-n):
        ans += '-'
    else:
        ans += '+'
ans += S_str[-1] + '=7'
print(ans)

Submission status: Accepted

Solution code:
abcd = list(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:
numbers = [int(_) for _ in input()]
n = len(numbers) - 1

for i in range(2 ** n):
    ans = numbers[0]
    ops = []
    for j in range(n):
        if i >> j & 1:
            ans += numbers[j+1]
            ops.append("+")
        else:
            ans -= numbers[j+1]
            ops.append("-")
    if ans == 7:
        break

print("{0}{4}{1}{5}{2}{6}{3}=7".format(numbers[0], numbers[1], numbers[2], numbers[3], ops[0], ops[1], ops[2]))

Submission status: Accepted

Solution code:
numbers = list(map(int, list(str(input()))))
n = len(numbers) - 1

for i in range(2 ** n):
    ans = numbers[0]
    ops = []
    for j in range(n):
        if i >> j & 1:
            ans += numbers[j+1]
            ops.append("+")
        else:
            ans -= numbers[j+1]
            ops.append("-")
    if ans == 7:
        break

print("{0}{4}{1}{5}{2}{6}{3}=7".format(numbers[0], numbers[1], numbers[2], numbers[3], ops[0], ops[1], ops[2]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

def func(i, x, op):
    if i == 4:
        if x == 7:
            return op
        else:
            return ''
    opP = func(i + 1, x + int(S[i]), op+'+'+str(S[i]))
    if opP != '':
        return opP
    opM = func(i + 1, x - int(S[i]), op+'-'+str(S[i]))
    if opM != '':
        return opM
    return ''

print(func(1, int(S[0]), str(S[0])) + '=7')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A=input()

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

Submission status: Accepted

Solution code:
s = input()
a = len(s)-1

for i in range(2**a):
    c = ["-"]*a
    t = ""
    for j in range(a):
        if ((i >> j) & 1):
            c[a-1-j] = "+"
        t = c[a-1-j] + s[a-j] + t
    t = s[0] + t
    
    if eval(t) == 7:
        t = t + "=7"
        print(t)
        break

Submission status: Accepted

Solution code:
def main():
    abcd = input()
    s = list(map(int, list(abcd)))
    n = 3
    for i in range(2 ** n):
        total = s[0]
        sign = []
        for j in range(n):
            if ((i >> j) & 1):
                total += s[j + 1]
                sign += ['+']
            else:
                total -= s[j + 1]
                sign += ['-']
        if total == 7:
            print(str(s[0]) + sign[0] + str(s[1]) +
                  sign[1] + str(s[2]) + sign[2] + str(s[3]) + '=7')
            return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
S = input()
A = S[0]
B = S[1]
C = S[2]
D = S[3]
if int(A) + int(B) + int(C) + int(D) == 7:
    print(A + '+' + B + '+' + C + '+' + D + '=7')
    sys.exit()
if int(A) - int(B) + int(C) + int(D) == 7:
    print(A + '-' + B + '+' + C + '+' + D + '=7')
    sys.exit()
if int(A) + int(B) - int(C) + int(D) == 7:
    print(A + '+' + B + '-' + C + '+' + D + '=7')
    sys.exit()
if int(A) - int(B) - int(C) + int(D) == 7:
    print(A + '-' + B + '-' + C + '+' + D + '=7')
    sys.exit()
if int(A) + int(B) + int(C) - int(D) == 7:
    print(A + '+' + B + '+' + C + '-' + D + '=7')
    sys.exit()
if int(A) - int(B) + int(C) - int(D) == 7:
    print(A + '-' + B + '+' + C + '-' + D + '=7')
    sys.exit()
if int(A) + int(B) - int(C) - int(D) == 7:
    print(A + '+' + B + '-' + C + '-' + D + '=7')
    sys.exit()
if int(A) - int(B) - int(C) - int(D) == 7:
    print(A + '-' + B + '-' + C + '-' + D + '=7')
    sys.exit()

Submission status: Accepted

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

a = input().rstrip()
b = []
for i in a:
    b.append(int(i))

op = [""] * 3
for i in range(2 ** 3):
    cnt = b[0]
    for j in range(3):
        if ((i >> j) & 1):
            op[2-j] = "+"
        else:
            op[2-j] = "-"
    for j in range(3):
        if op[j] == "+":
            cnt += b[j+1]
        else:
            cnt -= b[j+1] 
    if cnt == 7:
        print(b[0], op[0], b[1], op[1], b[2], op[2], b[3], "="+str(cnt),sep="")
        break

Submission status: Accepted

Solution code:
def pad(b,N):
    b = "0"*(N-len(b)) + b
    return b

def cal(A):
    N = len(A)
    for i in range(2**(N-1)):
        b = list(pad(bin(i)[2:],N-1))
        for j in range(N-1):
            if b[j] == "1":
                b[j] = "+"
            else:
                b[j] = "-"
        s = A[0]
        for j in range(N-1):
            if b[j] == "+":
                s += A[j+1]
            else:
                s -= A[j+1]
        if s == 7:
            output = str(A[0])
            for j in range(N-1):
                output += b[j]
                output += str(A[j+1])
            output += "=7"
            return output

def main():
    A = list(map(int,input()))
    print(cal(A))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
A = list(input())
for i in range(2 ** 3):
    op = ["-"] * 3
    for j in range(3):
        if ((i >> j) & 1):
            op[3 - 1 - j] = "+"
    ans = ""
    for m, n in zip(A, op):
        ans += m + n
    ans += A[3]
    if eval(ans) == 7:
        print(ans + "=7")
        exit()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def input():
    return sys.stdin.readline()

def dfs_four_number(s_num, i, op_list:list):
    # ベースケース
    if i == 3:
        ans_num = int(s_num[0])
        for j, op in enumerate(op_list):
            if op == "+":
                ans_num += int(s_num[j+1])
            elif op == "-":
                ans_num -= int(s_num[j+1])

        if ans_num == 7:
            return op_list
        else:
            return False

    op_list.append("+")
    if dfs_four_number(s_num, i+1, op_list):
        return op_list

    op_list.pop()
    op_list.append("-")
    if dfs_four_number(s_num, i+1, op_list):
        return op_list
    op_list.pop()



def resolve():
    s_num = input().rstrip()

    op_list = []
    ans_op_list = dfs_four_number(s_num, 0, op_list)

    ans_str = ""
    for s, op in zip(s_num, ans_op_list):
        ans_str += s
        ans_str += op

    ans_str += s_num[3] + "=7"
    print(ans_str)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
N = list(map(int, input()))
a,b,c,d = N[0], N[1], N[2], N[3]

if  a+b+c+d==7:
    print("{0}+{1}+{2}+{3}=7".format(a,b,c,d))
elif a+b+c-d==7:
    print("{0}+{1}+{2}-{3}=7".format(a,b,c,d))
elif a+b-c+d==7:
    print("{0}+{1}-{2}+{3}=7".format(a,b,c,d))
elif a+b-c-d==7:
    print("{0}+{1}-{2}-{3}=7".format(a,b,c,d))
elif a-b+c+d==7:
    print("{0}-{1}+{2}+{3}=7".format(a,b,c,d))
elif a-b+c-d==7:
    print("{0}-{1}+{2}-{3}=7".format(a,b,c,d))
elif a-b-c+d==7:
    print("{0}-{1}-{2}+{3}=7".format(a,b,c,d))
elif a-b-c-d==7:
    print("{0}-{1}-{2}-{3}=7".format(a,b,c,d))
else:
    pass

Submission status: Accepted

Solution code:
s = input()
n = list(map(int, [int(s[i]) for i in range(len(s))]))

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

Submission status: Accepted

Solution code:
abcd=list(input())
enzanshi=[['+','-'],['+','-'],['+','-']]
for i in range(2**3):
  l=[]
  for j in range(3):
    if (i>>j)&1:
      l.append(enzanshi[j][0])
    else:
      l.append(enzanshi[j][1])


  keisan=""
  for i,j in zip(abcd,l+['']):
    keisan+=i+j

  if eval(keisan)==7:
    print(keisan + '=7')
    break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()

new=""
ans=""

def func(s,new,i=0):
    
    if i==3:
        global ans
        ans=""
        new+=s[i]
        if eval(new)==7:
            ans=new+"=7"
            return True
        else:
            return False
   
    if func(s,new+s[i]+"+",i+1):
        return True
    
    if func(s,new+s[i]+"-",i+1):
        return True

if func(S,new):
    print(ans)

Submission status: Accepted

Solution code:
# ABC 079
N=input()
A,B,C,D =int(N[0]),int(N[1]),int(N[2]),int(N[3])
def f_add(a,b):
    return a+b
def f_minus(a,b):
    return a-b
def jug_f(f):
    if f ==f_add:
        return '+'
    else:
        return '-'
ans =''
for f1 in [f_add,f_minus]:
    for f2 in [f_add,f_minus]:
        for f3 in [f_add,f_minus]:
            if f3(f2(f1(A,B),C),D)==7:
                ans +=str(A)+jug_f(f1)+str(B)+jug_f(f2)+str(C)+jug_f(f3)+str(D)+"=7"
                print(ans)
                exit()

Submission status: Accepted

Solution code:
import sys
A, B, C, D = list(map(int, input().rstrip()))

if A+B+C+D==7:
    print("{}+{}+{}+{}=7".format(A, B, C, D))
    sys.exit()
elif A+B+C-D==7:
    print("{}+{}+{}-{}=7".format(A, B, C, D))
    sys.exit()
elif A+B-C+D==7:
    print("{}+{}-{}+{}=7".format(A, B, C, D))
    sys.exit()
elif A+B-C-D==7:
    print("{}+{}-{}-{}=7".format(A, B, C, D))
    sys.exit()
elif A-B+C+D==7:
    print("{}-{}+{}+{}=7".format(A, B, C, D))
    sys.exit()
elif A-B+C-D==7:
    print("{}-{}+{}-{}=7".format(A, B, C, D))
    sys.exit()
elif A-B-C+D==7:
    print("{}-{}-{}+{}=7".format(A, B, C, D))
    sys.exit()
elif A-BC-D==7:
    print("{}-{}-{}-{}=7".format(A, B, C, D))
    sys.exit()
else:
    pass

Submission status: Accepted

Solution code:
# coding: utf-8
# hello worldと表示する
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

s=SI()
a=int(s[0])
b=int(s[1])
c=int(s[2])
d=int(s[3])
def porm(x):
    if x==1:
        return "+"
    else:
        return "-"
def vec(x):
    if x==1:
        return 1
    else:
        return -1
for i in range(8):
    j=(i>>0) %2
    k=(i>>1) %2
    l=(i>>2) %2
    if a+b*vec(j)+c*vec(k)+d*vec(l)==7:
        print(a,end="")
        print(porm(j),end="")
        print(b,end="")
        print(porm(k),end="")
        print(c,end="")
        print(porm(l),end="")
        print(d,end="")
        print("=7")
        sys.exit()

Submission status: Accepted

Solution code:
import math
import copy

s = input()
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])
e = a + b
f = a - b
g = c + d
h = c - d
if e + g == 7:
    a,b,c,d = map(str,(a,b,c,d))
    print(a+'+'+b+"+"+c+"+"+d+"=7")
elif e + c-d == 7:
    a,b,c,d = map(str,(a,b,c,d))
    print(a+'+'+b+"+"+c+"-"+d+"=7")
elif e + d-c == 7:
    a,b,c,d = map(str,(a,b,c,d))
    print(a+'+'+b+"-"+c+"+"+d+"=7")
elif e - c-d == 7:
    a,b,c,d = map(str,(a,b,c,d))
    print(a+'+'+b+"-"+c+"-"+d+"=7")
elif f + g == 7:
    a,b,c,d = map(str,(a,b,c,d))
    print(a+'-'+b+"+"+c+"+"+d+"=7")
elif f + c-d == 7:
    a,b,c,d = map(str,(a,b,c,d))
    print(a+'-'+b+"+"+c+"-"+d+"=7")
elif f + d-c == 7:
    a,b,c,d = map(str,(a,b,c,d))
    print(a+'-'+b+"-"+c+"+"+d+"=7")
elif f - c-d == 7:
    a,b,c,d = map(str,(a,b,c,d))
    print(a+'-'+b+"-"+c+"-"+d+"=7")

Submission status: Accepted

Solution code:
def main():
    s = input()
    for i in range(1<<3):
        t = int(s[0])
        op = []
        for j in range(3):
            if 1 & (i>>j):
                t += int(s[j+1])
                op.append('+')
            else:
                t -= int(s[j+1])
                op.append('-')
        if t == 7:
            x = ['{}{}'.format(a,b) for a,b in zip(s, op)]
            print("".join(x) + s[-1] + '=7')
            break

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()
for bit in range(1 << len(S)-1):
    ans = [0,0,0]
    f = int(S[0])
    for i in range(0,len(S)-1):
        if bit & (1 << i):
            f -= int(S[i+1])
            ans[i] = "-"
        else:
            f += int(S[i+1])
            ans[i] = "+"
    if f == 7: break
for i in range(len(S)):
    if i == len(ans):
        print(S[i] + "=",end="")
    else:
        print(S[i] + ans[i],end="")
print(7)

Submission status: Accepted

Solution code:
a, b, c, d = input()
n = 4
answer = ''

for i in range(2 ** (n - 1)):
    ops = ['+', '+', '+']
    for j in range(n - 1):
        if (i >> j) & 1:
            ops[j] = '-'
    if eval(a + ops[0] + b + ops[1] + c + ops[2] + d) == 7:
        print(a+ops[0]+b+ops[1]+c+ops[2]+d+'=7')
        break

Submission status: Accepted

Solution code:
import copy

def calc_bits(nums, bits):
    nums = copy.deepcopy(nums)
    num0 = nums.pop(0)
    result = num0
    formula = str(num0)
    for num, bit in zip(nums, bits):
        if bit == 0:
            result -= num
            formula += '-' + str(num)
        else:
            result += num
            formula += '+' + str(num)
    formula += '=' + str(result)
    if result == 7:
        return formula
    return None

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

bits_list = []
for i in range(8):
    bits = []
    for j in range(2, -1, -1):
        bit = (i >> j) & 1
        bits.append(bit)
    bits_list.append(bits)

for bits in bits_list:
    result = calc_bits(nums, bits)
    if result:
        print(result)
        break

Submission status: Accepted

Solution code:
from itertools import product
a,b,c,d=list(input())
for o,p,q in product("-+",repeat=3):
    if eval(a+o+b+p+c+q+d)==7:
        print(a+o+b+p+c+q+d+"=7")
        break

Submission status: Accepted

Solution code:
from operator import sub, add
from itertools import product

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

for op1, op2, op3 in product([sub, add], repeat=3):
    if op3(op2(op1(a, b), c), d) == 7:
        o, p, q = map(lambda op: "+" if op == add else "-", [op1, op2, op3])
        print(a, o, b, p, c, q, d, "=7", sep="")
        exit()

Submission status: Accepted

Solution code:
from operator import sub, add
from itertools import product

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

for op1, op2, op3 in product([sub, add], repeat=3):
    if op3(op2(op1(a, b), c), d) == 7:
        mark = lambda op: "+" if op == add else "-" 
        print(a, mark(op1), b, mark(op2), c, mark(op3), d, "=7", sep="")
        exit()

Submission status: Accepted

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

for op1 in ["+", "-"]:
    for op2 in ["+", "-"]:
        for op3 in ["+", "-"]:
            tmp = 0
            if op1 == "+":
                tmp = ABCD[0] + ABCD[1]
            else:
                tmp = ABCD[0] - ABCD[1]
            if op2 == "+":
                tmp += ABCD[2]
            else:
                tmp -= ABCD[2]
            if op3 == "+":
                tmp += ABCD[3]
            else:
                tmp -= ABCD[3]

            if tmp == 7:
                print(str(ABCD[0])+op1+str(ABCD[1])+op2+str(ABCD[2])+op3+str(ABCD[3])+"=7")
                quit()

Submission status: Accepted

Solution code:
import sys
from math import sqrt
from collections import Counter, defaultdict, deque

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


def LIN(n: int):
    return [I() for _ in range(n)]


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    abcd = input().rstrip()

    op = [""] * 3
    for i in range(2 ** 3):
        r = int(abcd[0])
        for j in range(3):
            if (i >> j) & 1:
                r += int(abcd[j + 1])
                op[j] = "+"
            else:
                r -= int(abcd[j + 1])
                op[j] = "-"
        if r == 7:
            ans = abcd[0]
            for j in range(3):
                ans += op[j] + abcd[j + 1]
            ans += "=7"
            print(ans)
            exit()


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
A,B,C,D = input('')
for i in range(2**3):
  op = [0] * 3
  for j in range(3):
    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')
    exit()

Submission status: Accepted

Solution code:
L = [int(i) for i in str(input())]
for i in range(2 ** 3):
    l = ['+'] * 3
    for j in range(3):
        if ((i >> j) & 1):
            l[j] = '-'
    s = L[0]
    for k in range(3):
        if l[k] == '+':
            s += L[k + 1]
        else:
            s -= L[k + 1]
    if s == 7:
        for m in range(3):
            print(str(L[m]) + str(l[m]), end='')
        print(str(L[3]) + '=7')
        exit()

Submission status: Accepted

Solution code:
s = input()

for i in range(2**3):
    t = int(s[0])
    for j in range(3):
        if (i>>j)&1:
            t += int(s[j+1])
        else:
            t -= int(s[j+1])
    if t == 7:
        x = i
        break
print(s[0],end="")
for k in range(3):
    if (x>>k)&1:
        print("+",end="")
    else:
        print("-",end="")
    print(s[k+1],end="")
print("=7")

Submission status: Accepted

Solution code:
s = list(input())
a = s[0]
b = s[1]
c = s[2]
d = s[3]
e = int(a)+int(b)+int(c)+int(d)
f = e - 7
if e == 7:
  print(a+'+'+b+'+'+c+'+'+d+'=7')
else:
  if int(b)*2 == f:
    print(a+'-'+b+'+'+c+'+'+d+'=7')
  elif int(c)*2 == f:
    print(a+'+'+b+'-'+c+'+'+d+'=7')
  elif int(d)*2 == f:
    print(a+'+'+b+'+'+c+'-'+d+'=7')
  elif (int(b)+int(c))*2 == f:
    print(a+'-'+b+'-'+c+'+'+d+'=7')
  elif (int(b)+int(d))*2 == f:
    print(a+'-'+b+'+'+c+'-'+d+'=7')
  elif (int(c)+int(d))*2 == f:
    print(a+'+'+b+'-'+c+'-'+d+'=7')
  elif (int(b)+int(c)+int(d))*2 == f:
    print(a+'-'+b+'-'+c+'-'+d+'=7')

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MAX = 10**18
MIN = -10**18
MOD = 998244353


def judge(li):
    c = int(s[0])
    for i in range(len(li)):
        if li[i] == "-":
            c -= int(s[i+1])
        else:
            c += int(s[i+1])
    return c
s = input()

n = len(s)-1
for i in range(2**n):
    li = ["+"]*n
    for j in range(n):
        if (i>>j)&1:
            li[n-j-1] = "-"
    if judge(li) == 7:
        ans = s[0]
        for i in range(len(li)):
            ans += li[i] + s[i+1]
        print(ans+"=7")
        sys.exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(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))
else:
  print('none')

Submission status: Accepted

Solution code:
s = input()
sukima = len(s)-1

for i in range(2**sukima):
  l = ['-']*sukima
  for j in range(sukima):
    if ((i >> j)&1):
      l[sukima-j-1] = '+'
  if eval(str(s[0]) + l[0] + str(s[1]) + l[1] +str(s[2]) + l[2] +str(s[3])) ==7:
    print(str(s[0]) + l[0] + str(s[1]) + l[1] +str(s[2]) + l[2] +str(s[3]) + '=7')
    exit()

Submission status: Accepted

Solution code:
from itertools import product

from operator import add, sub

numbers = tuple(int(c) for c in input())

operators = product((add, sub), repeat=3)


def opstr(op):
    if op == add:
        return '+'
    elif op == sub:
        return '-'


for op1, op2, op3 in operators:
    result = numbers[0]
    result = op1(result, numbers[1])
    result = op2(result, numbers[2])
    result = op3(result, numbers[3])

    if result == 7:
        print(str(numbers[0]) + opstr(op1) + str(numbers[1]) + opstr(op2) + str(numbers[2]) + opstr(op3) + str(numbers[3]) + '=7')
        break

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(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:
#https://atcoder.jp/contests/abc079/tasks/abc079_c

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

for i in range(2**3):
    num=n[0]
    symbol=[]
    for j in range(3):
        if (i>>j)&1:#足し算
            num+=n[j+1]
            symbol.append("+")
        else:
            num-=n[j+1]
            symbol.append("-")
    if num==7:
        print("{0}{1}{2}{3}{4}{5}{6}=7".format(n[0],symbol[0],n[1],symbol[1],n[2],symbol[2],n[3]))
        exit()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

def solve():
    E = list(map(int, list(input())))
    # print(E)

    for i in range(1<<3):
        op = ['-'] * 3
        for j in range(3):
            if i >> j & 1:
                op[j] = '+'

        f = '{}{}{}{}{}{}{}'.format(E[0], op[0], E[1], op[1], E[2], op[2], E[3])
        e = eval(f)
        if e == 7:
            print(f + '=7')
            return



if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
s = S[0]
score = int(S[0])
def rec(n, s, score):
    if n == 1:
        if score == 7:
            print(s + "=7")
            exit()
            
    else:
        rec(n-1, s+"+"+S[-n+1], score+int(S[-n+1]))
        rec(n-1, s+"-"+S[-n+1], score-int(S[-n+1]))
    
print(rec(len(S), s, score))

Submission status: Accepted

Solution code:
ABCD=list(map(int,list(input())))
for i in range(2**3):
    op=[0]*3
    for j in range(3):
        op[j]=i%2
        i//=2
    val=ABCD[0]
    for j in range(3):
        if op[j]==1:
            val+=ABCD[j+1]
        else:
            val-=ABCD[j+1]
    if val==7:
        ans=str(ABCD[0])
        for j in range(3):
            if op[j]==1:
                ans+="+"
            else:
                ans+="-"
            ans+=str(ABCD[j+1])
        print(ans+"=7")
        exit()

Submission status: Accepted

Solution code:
N=int(input())
A=[0,0,0,0]
for i in range(4):
  A[3-i]=N%10
  N=int(N/10)

#3ビットの全探索
for bit in range(2**3+1):
  a=A[0]
  for i in range(3):
    if (bit>>i)&1:
      a-=A[i+1]
    else:
      a+=A[i+1]
  
  if a==7:
    text=str(A[0])
    for i in range(3):
      if (bit>>i)&1:
        text+="-"
      else:
        text+="+"
      text+=str(A[i+1])
    print(text+"=7")
    break

Submission status: Accepted

Solution code:
import copy
Input = [i for i in input()]

for i in range(2**3):
    AltInput=Input.copy()
    formula = AltInput.pop(0)
    for j in range(3):
        if((i >> j) & 1):
            formula += '+'
        else:
            formula += '-'
        formula += AltInput.pop(0)
    if(eval(formula) == 7):
        print(formula + '=7')
        break

Submission status: Accepted

Solution code:
#ABC079C
def main():
    import sys
    import itertools as ite
    nums = list(map(int, list(sys.stdin.readline().rstrip())))
    ope = list(ite.product(['+', '-'], repeat=3))
    #print(ope)
    
    def calc(L):
        ans = L[0]
        for i in range(1, len(L)-1, 2):
            if L[i] =='+':
                ans +=L[i+1]
            elif L[i] =='-':
                ans -=L[i+1]
        if ans ==7:
            L = ''.join(list(map(str, L)))
            print(L+'=7')
            return True
    
    for op in ope:
        L=[]
        for i in range(3):
            L += [nums[i], op[i]]
        L+=[nums[3]]
        #print(L)
        if calc(L) ==True:
            break
        


if __name__=='__main__':
    main()