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:
N=input()
L=[]

for c in N:
    L.append(int(c))

bb=16
b=bin(bb)
for i in range(16):
    b=bin(bb)
    B=str(b)
    n=L[0]
    for p in range(1,4):
        n+=2*(int(B[-1*p])*L[p])
        n-=L[p]
    if n==7:
        break
    bb+=1
    #print(n,B)


def plmi(n):
    if n=="1":
        return "+"
    else:
        return "-"

ans=""

ans+=N[0]
ans+=plmi(B[-1])
ans+=N[1]
ans+=plmi(B[-2])
ans+=N[2]
ans+=plmi(B[-3])
ans+=N[3]
ans+="=7"

print(ans)

Submission status: Accepted

Solution code:
s = input()
op = ["+","-"]
for i in range(2**(len(s)-1)):
    t = s[0]
    for j in range(len(s)-1):
        t += op[(i>>j)&1] + s[j+1]
    if eval(t) == 7:
        ans = t+"=7"
print(ans)

Submission status: Accepted

Solution code:
S = input()
p = ["+", "-"]

for i in range(2**3):
  t = S[0]
  for j in range(3):
    t += p[i>>j&1] + S[j+1]
  judge = eval(t)
  if judge == 7:
    print(t + "=7")
    break

Submission status: Accepted

Solution code:
S=input()
n=len(S)-1
for i in range(1<<n):
    op=["-"]*n
    for j in range(n):
        if i&(1<<j):
            op[j]="+"
    f="".join([S[i//2] if i%2==0 else op[i//2] for i in range(2*(n+1)-1)])
    if eval(f)==7:
        print("%s=7"%f)
        quit()

Submission status: Accepted

Solution code:
def solve():
    s_abcd = read()
    result = think(s_abcd)
    write(result)


def read():
    return read_line(n=4)


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(s_abcd):
    list_int_abcd = list(map(lambda x: int(x), list(s_abcd)))
    max_patterns = 2 ** 3
    expected_answer = 7

    for _ in range(max_patterns):
        formula_string = generate_formula_string_with(list_int_abcd, _)
        if eval(formula_string) == expected_answer:
            return format_formula_string(formula_string, expected_answer)
    raise RuntimeError()


def generate_formula_string_with(list_int_abcd, bit):
    shift = 3
    operator = ['+', '-']
    formula_string = ''
    for i, elem in enumerate(list_int_abcd):
        formula_string += str(elem)
        if i == len(list_int_abcd) - 1:
            continue
        if bit >> (shift - i - 1) & 1:
            formula_string += operator[0]
        else:
            formula_string += operator[1]
    return formula_string


def format_formula_string(formula_string, expected_answer):
    return '{0:s}={1:s}'.format(formula_string, str(expected_answer))


def write(result):
    print(result)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
S = input()
length = len(S) - 1
S = list(S)
for i in range(2**length):
	sum=int(S[0])
	MP = []
	if i & 2**0:
		sum += int(S[1])
		MP.append("+")
	else:
		sum -= int(S[1])
		MP.append("-")
	if i & 2**1:
		sum += int(S[2])
		MP.append("+")
	else:
		sum -= int(S[2])
		MP.append("-")
	if i & 2**2:
		sum += int(S[3])
		MP.append("+")
	else:
		sum -= int(S[3])
		MP.append("-")
	if sum == 7:
		print("{0}{1}{2}{3}{4}{5}{6}=7".format(S[0], MP[0], S[1], MP[1], S[2], MP[2], S[3]))
		break

Submission status: Accepted

Solution code:
a,b,c,d=map(str,input())
l=['+','-']
for i in l:
    for j in l:
        for k in l:
            if eval(a+i+b+j+c+k+d)==7:print(a+i+b+j+c+k+d+'=7');exit()

Submission status: Accepted

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

import sys

sys.setrecursionlimit(10**7)

# Override `input` function because `stdin.readline()` is 10x faster than built-in `input()`
input = sys.stdin.readline


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h(typ) if m > 1 else typ(input()) for _ in range(n)]


def main():
    S, = read_h(typ=str)
    ints = [int(i) for i in S]

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

        #  print(ints)
        #  print(ops)

        s = ints[0]
        for op, i in zip(ops, ints[1:]):
            if op == '+':
                s += i
            else:
                s -= i

        if s == 7:
            ans = ''.join([str(i) + op for i, op in zip(ints, ops + [''])] + ['=7'])
            print(ans)
            return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
li = [i for i in s]
global ans
def cal(left, count, remaining):
    global ans
    if len(remaining) > 0:
        cal(left + "+" + remaining[0], count + int(remaining[0]), remaining[1:])
        cal(left + "-" + remaining[0], count - int(remaining[0]), remaining[1:])
    elif count == 7:
        ans = left

cal(li[0], int(li[0]), li[1:])
print(ans+"=7")

Submission status: Accepted

Solution code:
num = input()
n = len(num) - 1

for i in range(2 ** n):
    calc = ["-"] * n
    for j in range(n):
        if ((i >> j) & 1):
            calc[- 1 - j] = "+"
    formula = ""
    for number, c in zip(num, calc):
        formula += number+c
    formula += num[-1]
    if eval(formula) == 7:
        formula += "=7"
        break

print(formula)

Submission status: Accepted

Solution code:
ABCD = input()

for i in range(2 ** 3):
    res = ABCD[0]
    c = int(ABCD[0])
    for j in range(1, 4):
        if (i >> (j - 1)) & 1:
            c += int(ABCD[j])
            res += "+" + ABCD[j]
        else:
            c -= int(ABCD[j])
            res += "-" + ABCD[j]
    if c == 7:
        print(res + "=7")
        exit()

Submission status: Accepted

Solution code:

import sys

abcd = input()

n = len(abcd)-1
xx = abcd
for x in range(2**n):
    j = 0
    abcd = list(abcd)
    for i in range(n):
        if (x>>i)&1:
            abcd.insert(i+j+1, "+")
            j += 1

        else:
            abcd.insert(i+j+1, "-")
            j += 1

    abcd = "".join(abcd)
    sum = eval(abcd)
    if sum==7:
        print(abcd+"=7")
        sys.exit()

    abcd = xx

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import operator

n = input()
operator_list = [operator.add, operator.sub]
operator_list2 = ["+", "-"]
flag = False
for i in range(2):
    for j in range(2):
        for k in range(2):
            if operator_list[i](operator_list[j](operator_list[k](int(n[0]), int(n[1])), int(n[2])), int(n[3])) == 7:
                flag = True
                break
        if flag == True:
            break
    if flag == True:
        break
print(n[0] + operator_list2[k] + n[1] + operator_list2[j] + n[2] + operator_list2[i] + n[3] + "=7")

Submission status: Accepted

Solution code:
def s(total, que, p_m, ans_str, in_list):
    if que == 0:
        total += in_list[que]
        ans_str += str(in_list[que])
    else:
        total += in_list[que] if p_m else -in_list[que]
        ans_str += ("+" + str(in_list[que])) if p_m else ("-" + str(in_list[que]))
    if que == 3:
        if total == 7:
            print(ans_str + "=7")
            exit()
    else:
        s(total, que + 1, True, ans_str, in_list)
        s(total, que + 1, False, ans_str, in_list)


a = list(map(int, list(input())))
print(s(0, 0, True, "", a))

Submission status: Accepted

Solution code:
S = input()


for i in range(8):
    f = ""
    B = ["-"]*3

    for j in range(3):
        if ((i>>j)&1):
            B[j] = "+"
    for a,b in zip(S, B+[""]):
        f += (a+b)
    
        
    if eval(f) == 7:
        print(f+"=7")
        break

Submission status: Accepted

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

op_list = []

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

  op_list.append(op)

f_list = []

for op in op_list:
  f = s[0]
  for i in range(n):
    f += op[i]
    f += s[i+1]
  f_list.append(f)

for f in f_list:
  if eval(f) == 7:
    print(f+"=7")
    exit()

Submission status: Accepted

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

opl = []

for i in range(2 ** n):
  op = ["-"] * n
  for j in range(n):
    if (i >> j) & 1:
      op[2-j] = "+"
  opl.append(op)

fl = []

for i in opl:
  f = s[0]
  for j in range(n):
    f += i[j]
    f += s[j+1]
  fl.append(f)

for f in fl:
  if eval(f) == 7:
    print(f+"=7")
    exit()

Submission status: Accepted

Solution code:
N = input()
A, B, C, D = int(N[0]), int(N[1]), int(N[2]), int(N[3])
opes = ['-', '+']
for op1 in opes:
  for op2 in opes:
    for op3 in opes:
      result = 0
      if op1 == '-':
        result += A-B
      else:
        result += A+B
      if op2 == '-':
        result -= C
      else:
        result += C
      if op3 == '-':
        result -= D
      else:
        result += D
      if result == 7:
        print(str(A)+op1+str(B)+op2+str(C)+op3+str(D)+'=7')
        exit()

Submission status: Accepted

Solution code:
# ABC 079 C Train Ticket
S = input()

N = []; M=[];
for i in range(4):
    N.append(int(S[i]))
    N.append(-1 * int(S[i]))
    M.append("+")
    M.append("-")
    
def solve(M,N):
    for i in range(2):
        for j in range(2):
            for k in range(2):
                total = N[0]+N[2+i]+N[4+j]+N[6+k]
                if (total == 7):
                    ans = str(N[0])+M[2+i]+str(N[2])+M[4+j]+str(N[4])+M[6+k]+str(N[6])
                    return ans+"=7"

print(solve(M,N))

Submission status: Accepted

Solution code:
n=input()
a=int(n[0])
b=int(n[1])
c=int(n[2])
d=int(n[3])
for i in [b,-b]:
  for j in [c,-c]:
    for k in [d,-d]:
      if a+i+j+k==7:
        ii='+'
        jj='+'
        kk='+'
        if i==-b:
          ii='-'
        if j==-c:
          jj='-'
        if k==-d:
          kk='-'
        print(str(a)+ii+str(b)+jj+str(c)+kk+str(d)+'=7')
        exit()

Submission status: Accepted

Solution code:
import sys

n = [int(i) for i in list(input())]
ops = ['+', '-']
for a in ops:
    for b in ops:
        for c in ops:
            e = '{}{}{}{}{}{}{}'.format(n[0], a, n[1], b, n[2], c, n[3])
            if eval(e) == 7:
                print('{}=7'.format(e))
                sys.exit(0)

Submission status: Accepted

Solution code:
"Train Ticket"
# numbers = list(map(int, list(str(input()))))
#
# print(numbers)

numbers = list(input())

# '+' or '-'を挿入する箇所は桁数-1

for mask in range(1 << (len(numbers)-1)):
    fomula = ""
    for i in range(len(numbers)):
        if (mask >> i) & 1:  # 1のビットが立つなら
            fomula += numbers[i] + "+"
        else:
            fomula += numbers[i] + "-"

    # print(fomula[:-1])

    if eval(fomula[:-1]) == 7:
        print(fomula[:-1]+"="+"7")
        break

Submission status: Accepted

Solution code:
N = list(input())
op = "+-"
for i in op:
    for j in op:
        for k in op:
            tmp = N[0]+i+N[1]+j+N[2]+k+N[3]
            if eval(tmp) == 7:
                print(tmp+"=7")
                exit(0)

Submission status: Accepted

Solution code:
import sys
N = list(map(int, input()))
op = ['+','-']
for i in op:
    tmp = 0 
    ans = []
    for j in op:
        for k in op:
            if i == '+':
                tmp = N[0] + N[1]
                ans.append('+')
            else:
                tmp = N[0] - N[1]
                ans.append('-')

            if j == '+':
                tmp += N[2]
                ans.append('+')
            else:
                tmp -= N[2]    
                ans.append('-')

            if k == '+':
                tmp += N[3]
                ans.append('+')
            else:
                tmp -= N[3]
                ans.append('-')

            if tmp == 7:
                print(str(N[0])+ans[0]+str(N[1])+ans[1]+str(N[2])+ans[2]+str(N[3])+"=7")
                sys.exit()
            else:
                tmp = 0
                ans = []

Submission status: Accepted

Solution code:
def plus_minus_seq(n):
    if n == 0:
        return ['']
    else:
        seqs = plus_minus_seq(n-1)
        posi = ['+' + seq for seq in seqs]
        nega = ['-' + seq for seq in seqs]
    return posi + nega

A, B, C, D = input()

for op1, op2, op3 in plus_minus_seq(3):
    seq = A+op1+B+op2+C+op3+D
    if eval(seq) == 7:
        print(seq + '=7')
        break

Submission status: Accepted

Solution code:
import sys

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

def calc(index, result, operation):
    
    if index == 4 and result == 7:
        print(operation + "=7")
        sys.exit()
    elif (index == 4):
        return
        
    calc(index + 1, result + A[index], operation + "+" + str(A[index]))
    calc(index + 1, result - A[index], operation + "-" + str(A[index]))
    
calc(1,A[0],str(A[0]))

Submission status: Accepted

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


def solve(S):
    for a in ['+', '-']:
        for b in ['+', '-']:
            for c in ['+', '-']:
                if eval('{}{}{}{}{}{}{}'.format(
                        S[0], a, S[1], b, S[2], c, S[3]
                )) == 7:
                    return '{}{}{}{}{}{}{}=7'.format(
                        S[0], a, S[1], b, S[2], c, S[3]
                    )


if __name__ == '__main__':
    S = input()
    print(solve(S))

Submission status: Accepted

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

num = []
def make(B):
    if len(B) == 3:
        num.append(B)
        return
    B1 = B[:]
    B2 = B[:]
    B1.append(1)
    B2.append(-1)
    make(B1)
    make(B2)

make([])

for A in num:
    k = S[0] + S[1]*A[0] + S[2]*A[1] + S[3]*A[2]
    if k == 7:
        break

ans = []
for a in A:
    if a == 1:
        ans.append('+')
    else:
        ans.append('-')

print(str(S[0])+ans[0]+str(S[1])+ans[1]+str(S[2])+ans[2]+str(S[3])+'=7')

Submission status: Accepted

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

for op1 in a:
  fml_1 = ''
  fml_1 += (op1 + B)
  for op2 in a:
    fml_2 = fml_1
    fml_2 += (op2 + C)
    for op3 in a:
      fml_3 = fml_2
      fml_3 += (op3 + D)
      if eval(fml_3) == 7 - int(A):
        print(A + fml_3 + '=7')
        exit()

Submission status: Accepted

Solution code:
a,b,c,d=list(input())
for i in range(8):
  op=list(str(bin(i)[2:].zfill(3)).replace('0','-').replace('1','+'))
  siki=a+op[0]+b+op[1]+c+op[2]+d
  ans=eval(siki)
  if ans == 7:
    print(siki+'=7')
    break

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    s = S()
    for i in range(2):
        if s[i] == s[i + 1] == s[i + 2]:
            print("Yes")
            return
    print("No")
    return

#B
def B():
    return

#C
def C():
    abcd = list(map(int, S()))
    op = itertools.product(range(2), repeat=3)
    for opx in op:
        ans = abcd[0]
        for num, opi in enumerate(opx):
            if opi:
                ans += abcd[num + 1]
            else:
                ans -= abcd[num + 1]
        if ans == 7:
            print(abcd[0],end="")
            for num, opi in enumerate(opx):
                print(["-", "+"][opi] + str(abcd[num + 1]), end="")
            print("=7")
            return
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Accepted

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

ans = 0
ans = "{0}+{1}+{2}+{3}=7".format(A, B, C, D) if A+B+C+D==7 else ans
ans = "{0}+{1}+{2}-{3}=7".format(A, B, C, D) if A+B+C-D==7 else ans
ans = "{0}+{1}-{2}+{3}=7".format(A, B, C, D) if A+B-C+D==7 else ans
ans = "{0}+{1}-{2}-{3}=7".format(A, B, C, D) if A+B-C-D==7 else ans
ans = "{0}-{1}+{2}+{3}=7".format(A, B, C, D) if A-B+C+D==7 else ans
ans = "{0}-{1}+{2}-{3}=7".format(A, B, C, D) if A-B+C-D==7 else ans
ans = "{0}-{1}-{2}+{3}=7".format(A, B, C, D) if A-B-C+D==7 else ans
ans = "{0}-{1}-{2}-{3}=7".format(A, B, C, D) if A-B-C-D==7 else ans

print(ans)

Submission status: Accepted

Solution code:
def op(x):
    return '+' if x == 1 else '-'
a, b, c, d = map(int, input())

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

Submission status: Accepted

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

n = int(input())

tmp=[]
tmp.append(n//1000)
n=n%1000
tmp.append(n//100)
n=n%100
tmp.append(n//10)
n=n%10
tmp.append(n)

for i in range(-1,2,2):
	for j in range(-1,2,2):
		for k in range(-1,2,2):
			sum= tmp[0]+i*tmp[1]+j*tmp[2]+k*tmp[3]
			if(sum == 7):
				break
#			print("{} {} {}:{}".format(i,j,k,sum))
		else:
			continue
		break
	else:
		continue
	break

res=""
res+=str(tmp[0])
if(i==-1):res+="-"
else:res+="+"
res+=str(tmp[1])
if(j==-1):res+="-"
else:res+="+"
res+=str(tmp[2])
if(k==-1):res+="-"
else:res+="+"
res+=str(tmp[3])
res+="=7"


print(res)

Submission status: Accepted

Solution code:
def main():
	n = [int(i) for i in input()]
	for i in range(7):
		x2 = base_10_to_n(i,2)
		for _ in range(3-len(x2)):	
			x2 = '0' + x2
		ans = n[0]
		for j in range(3):
			if(x2[j] == '0'):
				ans += n[j+1]
			else:
				ans -= n[j+1]
		if(ans == 7):
			text = str(n[0])
			for j in range(3):
				if(x2[j] == '0'):
					text = text + '+' + str(n[j+1])
				else:
					text = text + '-' + str(n[j+1])
			print(text+'=7')
			return 0

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

main()

Submission status: Accepted

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

operator = ['+', '-']

for i in range(2 ** 3):
    result = a + operator[int(format(i, 'b').zfill(3)[0])] \
        + b + operator[int(format(i, 'b').zfill(3)[1])] \
        + c + operator[int(format(i, 'b').zfill(3)[2])] \
        + d

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

Submission status: Accepted

Solution code:
inputs = input()

length = len(inputs) - 1
for i in range(2 ** length):
    formula = ''
    operator = format(i, 'b').zfill(length)
    for index in range(length):
        formula += inputs[index] + ('+' if operator[index] == '0' else '-')
    formula += inputs[-1]
    if eval(formula) == 7:
        print(formula + '=7')
        break

Submission status: Accepted

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

def op(i,j,p):
    if p == 0:
        return i + j
    elif p == 1:
        return i - j
def sign(p):
    if p == 1:
        return "-"
    elif p == 0:
        return "+"
for p in range(2):
    x = op(a,b,p)
    for q in range(2):
        y = op(x,c,q)
        for r in range(2):
            if op(y,d,r) == 7:
                break
        else:
            continue
        break
    else:
        continue
    break
print(str(a)+sign(p)+str(b)+sign(q)+str(c)+sign(r)+str(d)+"=7")

Submission status: Accepted

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

op = ["+","-"]

for i in op:
  for j in op:
    for k in op:
      if eval("A {} B {} C {} D".format(i, j, k)) == 7:
        print("{}{}{}{}{}{}{}=7".format(A, i, B, j, C, k, D))
        exit()

Submission status: Accepted

Solution code:
nums = list(input())
A = [0, 1]
B = [0, 1]
C = [0, 1]
ops = {
  0: "+",
  1: "-"
}
total = 0
res = ''
for a in range(2):
    for b in range(2):
        for c in range(2):
            if a == 0:
                total = int(nums[0]) + int(nums[1])
            else:
                total = int(nums[0]) - int(nums[1])
            if b == 0:
                total = total + int(nums[2])
            else:
                total = total - int(nums[2])
            if c == 0:
                total = total + int(nums[3])
            else:
                total = total - int(nums[3])
            if total == 7:
                res = nums[0] + ops[a] + nums[1] + ops[b] + nums[2] + ops[c] + nums[3] + "=7"
print(res)

Submission status: Accepted

Solution code:
s=input()
l=2**3

for i in range(l):
    j=i
    c=int(s[0])
    n=1
    for x in range(3):
        if i & 1 ==1:
            c+=int(s[n])
        else:
            c-=int(s[n])
        i=i>>1
        n+=1
    #print(c,j)
    if c==7:
        break

ss=[s[0]]
for i in range(3):
    if j & 1 ==1:
        ss.append('+')
    else:
        ss.append('-')
    ss.append(s[i+1])
    j=j>>1
print(''.join(ss)+'=7')

Submission status: Accepted

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

op = ["+","-"]

for i in op:
    for j in op:
        for k in op:
            if eval("A {} B {} C {} D".format(i, j, k)) == 7:
                print("{}{}{}{}{}{}{}=7".format(A, i, B, j, C, k, D))
                exit()

Submission status: Accepted

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

for i in range(2):
    op1="+"*(1-i)+"-"*i
    for j in range(2):
        op2="+"*(1-j)+"-"*j
        for k in range(2):
            op3="+"*(1-k)+"-"*k
            sum=a+b*(-1)**i+c*(-1)**j+d*(-1)**k
            if sum==7:
                print(a,op1,b,op2,c,op3,d,"=7",sep="")
                sys.exit(0)

Submission status: Accepted

Solution code:
S = input()
S_list = list(S)
n = len(S) 
a = []

list_0or1 = [0] * (n-1)
check = []

def f(i):
    if i == n-1 :
        check.append(list_0or1.copy())
    if i != n-1:
        list_0or1[i] = 0
        f(i+1)
    if i != n-1:
        list_0or1[i] = 1
        f(i+1)
f(0)

sum_list = []
s_list = []
for i in range(len(check)):
    S_list_copy = S_list.copy()
    for j in range(n-1) :
        if check[i][j] == 1 :
            S_list_copy[j+1] = '+' + S_list_copy[j+1]
        if check[i][j] == 0 :
            S_list_copy[j+1] = '-' + S_list_copy[j+1]
    S_list_copy = ''.join(S_list_copy)
    sum_list.append(S_list_copy)
    S_list_copy = [int(S_list_copy[0]), int(S_list_copy[2]), int(S_list_copy[4]), int(S_list_copy[6])]
    s = S_list_copy[0]
    for j in range(n-1) :
        if check[i][j] == 1 :
            s = s + S_list_copy[j+1]
        if check[i][j] == 0 :
            s = s - S_list_copy[j+1]
    s_list.append(s) 
if 7 in s_list:
    print(sum_list[s_list.index(7)]+'=7')

Submission status: Accepted

Solution code:
A, B, C, D = [int(e) for e in input()]
for b in [[+B, "+"+str(B)], [-B, "-"+str(B)]]:
  for c in [[+C, "+"+str(C)], [-C, "-"+str(C)]]:
    for d in [[+D, "+"+str(D)], [-D, "-"+str(D)]]:
      if A+b[0]+c[0]+d[0] == 7:
        ans = str(A) + b[1] + c[1] + d[1] + "=7"
        print(ans)
        break
    else:
      continue
    break
  else:
    continue
  break

Submission status: Accepted

Solution code:
T = list(map(int,list(input())))
for i in range(2**3):
  ans = T[0]
  op = ["+"]*3
  for j in range(3):
    if (i>>j) & 1:
      ans += T[j+1]
    else:
      ans -= T[j+1]
      op[j] = "-"
  if ans == 7:
    print(T[0],op[0],T[1],op[1],T[2],op[2],T[3],"=7",sep="")
    exit()

Submission status: Accepted

Solution code:
# ABC079C - Train Ticket.py
abcd = tuple(map(int, input()))
ans = []

for i in range(8, 16):
    s = abcd[0]
    eq = [str(s)]
    for j in range(1, 4):
        if int(bin(i)[-j]):
            s += abcd[j]
            eq.append("+" + str(abcd[j]))
        else:
            s -= abcd[j]
            eq.append("-" + str(abcd[j]))

    if s == 7:
        eq.append("=7")
        ans.append("".join(eq))

print(ans[0])

Submission status: Accepted

Solution code:
import sys

num = str(input())
nums = [int(i) for i in num]

for i in range(2**3):
    res = nums[0]
    # ビットが立っていたら、+ を与える
    for pos_i in range(0, 3):
        if (i >> pos_i) & 1:
            res += nums[pos_i + 1]
        else:
            res -= nums[pos_i + 1]
    
    # 条件を満たしていれば、出力してEND
    pos = ["-"]*3
    if i >> 0 & 1:
        pos[0] = "+"
    if i >> 1 & 1:
        pos[1] = "+"
    if i >> 2 & 1:
        pos[2] = "+"
            
    res_msg = "{}{}{}{}{}{}{}={}".format(nums[0], pos[0], nums[1], pos[1], nums[2], pos[2], nums[3], res)

#    print(res_msg)
    if res == 7:
        print(res_msg)
        sys.exit()

Submission status: Accepted

Solution code:
n = [int(x) for x in input()]
op_cnt= len(n)-1 #3
for bit in range(2**op_cnt):
    op = ["-"] * op_cnt
    for i in range(op_cnt):
        if ((bit>>i) & 1):
            op[op_cnt-1-i] = "+"
    lis = []
    lis.append(str(n[0]))
    lis.append(op[0])
    lis.append(str(n[1]))
    lis.append(op[1])
    lis.append(str(n[2]))
    lis.append(op[2])
    lis.append(str(n[3]))
    calc = ""
    for item in lis:
        calc += item
    if eval(calc) == 7:
        print(calc+ "=7")
        break

Submission status: Accepted

Solution code:
num = list(input())
ans = 7
for i in range(2 ** len(num)):
    total = 0
    ans_num = []
    ans_op = []
    for j in range(len(num)):
        if((i >> j) & 1):
            ans_num.append(num[j])
            if(j >= 1):
                ans_op.append('+')
            total += int(num[j])
        else:
            ans_num.append(num[j])
            if (j >= 1):
                ans_op.append('-')
            total -= int(num[j])
    if(total == ans):
        print(ans_num[0]+ans_op[0]+ans_num[1]+ans_op[1]+ans_num[2]+ans_op[2]+ans_num[3]+'=7')
        break

Submission status: Accepted

Solution code:
a,b,c,d=input()
a=int(a)
b=int(b)
c=int(c)
d=int(d)
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 = list(input())
ans = 7
for i in range(2 ** len(num)):
    total = 0
    ans_num = []
    ans_op = []
    for j in range(len(num)):
        if((i >> j) & 1):
            ans_num.append(num[j])
            if(j >= 1):
                ans_op.append('+')
            total += int(num[j])
        else:
            ans_num.append(num[j])
            if (j >= 1):
                ans_op.append('-')
            total -= int(num[j])
    if(total == ans):
        print(ans_num[0]+ans_op[0]+ans_num[1]+ans_op[1]+ans_num[2]+ans_op[2]+ans_num[3]+'=7')
        break

Submission status: Accepted

Solution code:
*ABCD, = map(int, list(input()))
N = 3
op = []
for bit in range(0, 1<<N):
    tmp = []
    for i in range(N):
        if (bit>>i) & 1:
            tmp.append("+")
        else:
            tmp.append("-")
    
    ans = ABCD[0]
    for i in range(N):
        if tmp[i] == "+":
            ans += ABCD[i+1]
        else:
            ans -= ABCD[i+1]
    if ans == 7:
        break

A = str(ABCD[0])
for i in range(N):
    A += str(tmp[i])
    A += str(ABCD[i+1])
A += "=7"
print(A)

Submission status: Accepted

Solution code:
S = input()
count = len(S)-1
for i in range(2**count):
  sign=['-']*count
  for j in range(count):
    if ((i>>j)&1):
      sign[j]='+'
  formula=''
  for k in range(count):
    formula += S[k] + sign[k]
  formula += S[count]
  if eval(formula)==7:
    print(formula+'=7')
    break

Submission status: Accepted

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

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

for i in range(2**3):
    bit = [0]*3
    for j in range(3):
        if (i >> j) & 1:
            bit[j] = 1
    s = a
    ans = [a,None,b,None,c,None,d,'=',7]
    k = 0
    for j in range(3):
        if bit[j] == 1:
            if j == 0:
                s += b
            elif j == 1:
                s += c
            elif j == 2:
                s += d
            ans[2*k+1] = '+'
        else:
            if j == 0:
                s -= b
            elif j == 1:
                s -= c
            elif j == 2:
                s -= d
            ans[2*k+1] = '-'
        k += 1
    if s == 7:
        print(''.join(map(str,ans)))
        break

Submission status: Accepted

Solution code:
S = input()

op_cnt = len(S) - 1#数字の間の数

for i in range(2 ** op_cnt):
  sign = ["+"] * op_cnt
  for j in range(op_cnt):
    if ((i>>j)&1):
      sign[j] = "-"
       
  formula = ""      
  for k in range(op_cnt):
    formula += S[k] + sign[k]
  formula += S[op_cnt]
  if eval(formula) == 7:
    print(formula + "=7")
    break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 整理番号を入力する
num = input()
# 整理番号の各桁の値を取り出す
A, B, C, D = [int(num[i]) for i in range(4)]
# 演算子のリストを作成する
list_op = ["+", "-"]
# 等式のリストを初期化する
list_equation = []
# op1
for i in range(2):
    # op2
    for j in range(2):
        # op3
        for k in range(2):
            # 計算する
            ans = A + (-1)**i * B + (-1)**j * C + (-1)**k * D
            # 計算結果が7になった場合
            if ans == 7:
                # 等式の文字列を作成する
                equation = str(A) + list_op[i] + str(B) + list_op[j] + str(C) + list_op[k] + str(D) + "=7"
                # 等式のリストに格納する
                list_equation.append(equation)
# 等式のリストの先頭の要素を出力する                
print(list_equation[0])