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:
def BitArrFromInt(i):
    arr = []
    quotient = i
    for ind in range(3):
        arr.append(quotient % 2)
        quotient /= 2
    return arr

def OpeStrFromBit(i):
    return '+' if i == 0 else '-'

# ABC 079 C -- Train Ticket
def solve():
    S = raw_input()
    # A, B, C, D = [int(S[i]) for i in range(len(S))]
    for i in range (2**3):
        bit_arr = BitArrFromInt(i)
        sum = int(S[0])
        for j in range (3):
            sum += (int(S[j+1]) if bit_arr[j] == 0 else -int(S[j+1]))
            # print sum
        if sum == 7:
            print S[0] + OpeStrFromBit(bit_arr[0]) + S[1] + \
                OpeStrFromBit(bit_arr[1]) + S[2] + OpeStrFromBit(bit_arr[2]) + S[3]+ '=7'
            break

if __name__ == '__main__':
    solve()

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 - j - 1] = "-"
    formula = ""
    for p_n, p_o in zip(n, op + [""]):
        formula += (p_n+p_o)
    if eval(formula) == 7:
        break

print(formula + "=7")

Submission status: Accepted

Solution code:
from itertools import product


def main():
    abcd = input()

    for op in product(["+", "-"], repeat=3):
        op = list(op)
        op.append("")
        expr = ''.join(a + b for a, b in zip(abcd, op))
        if eval(expr) == 7:
            print(expr, '=7', sep='')
            break


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
A,B,C,D = map(int,list(input()))
def main(A,B,C,D):
    for i in range(2):
        ans1 =0
        if i == 0:
            ans1 = A + B
            s1 ='+'
        else:
            ans1 = A - B
            s1 ='-'
        for j in range(2):
            ans2 = 0
            if j == 0:
                ans2 = ans1 + C
                s2 ='+'
            else:
                ans2 = ans1 - C
                s2 ='-'
            for k in range(2):
                ans3 = 0
                if k == 0:
                    ans3 = ans2 + D
                    s3 ='+'
                else:
                    ans3 = ans2 - D
                    s3 ='-'
                if ans3 == 7:
                    print(str(A)+s1+str(B)+s2+str(C)+s3+str(D)+"=7")
                    return
main(A,B,C,D)

Submission status: Accepted

Solution code:
S = input()

s = []
for c in S:
    s.append(c)

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

    operator.append(op)

F = []
for op in operator:
    f = "".join(a+b for a, b in zip(s,op))
    F.append(f)


for fm in F:
    if eval(fm)==7:
        print(fm + '=7')
        break

Submission status: Accepted

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

#print (lst)

def judge(x):
    if lst[0]+lst[1]+lst[2]+lst[3]==7:
        return '+ + +'
    elif lst[0]+lst[1]+lst[2]-lst[3]==7:
        return '+ + -'
    elif lst[0]+lst[1]-lst[2]+lst[3]==7:
        return '+ - +'
    elif lst[0]+lst[1]-lst[2]-lst[3]==7:
        return '+ - -'
    elif lst[0]-lst[1]+lst[2]+lst[3]==7:
        return '- + +'
    elif lst[0]-lst[1]+lst[2]-lst[3]==7:
        return '- + -'
    elif lst[0]-lst[1]-lst[2]+lst[3]==7:
        return '- - +'
    elif lst[0]+lst[1]-lst[2]-lst[3]==7:
        return '- - -'

#print(judge(lst))
lst2 = list(judge(lst).split())
#print (lst2)
ans = str(lst[0])+lst2[0]+str(lst[1])+lst2[1]+str(lst[2])+lst2[2]+str(lst[3])+'=7'

print (ans)

Submission status: Accepted

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

if A + B + C + D == 7:
    print(str(A) + "+" + str(B) + "+" + str(C) + "+" + str(D) + "=7")
    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:
ABCD = input()

def calc(calc_str):
    tmp = ""
    x, y = 0, 0
    calc_str = "0+" + calc_str
    for i in calc_str:
        if i == "+":
            tmp = i
        elif i == "-":
            tmp = i
        else:
            y = int(i)
            if tmp == "+":
                x = x + y
            elif tmp == "-":
                x = x - y
    return x

def create(A):
    for i in ("+", "-"):
        for t in ("+", "-"):
            for k in ("+", "-"):
                calc_str = A[0] + i + A[1] + t + A[2] + k + A[3]
                if calc(calc_str) == 7:
                    print(calc_str+"=7")
                    return

create(ABCD)

Submission status: Accepted

Solution code:
S = input()
for i in range(8) :
    a = []
    b = int(S[0])
    c = 0
    for j in range(3) :
        if (i>>j) & 1 :
            b += int(S[j+1])
            a.append('+')
        else :
            b -= int(S[j+1])
            a.append('-')
    if b == 7 :
        print(S[0]+a[0]+S[1]+a[1]+S[2]+a[2]+S[3]+'=7')
        break

Submission status: Accepted

Solution code:
#coding utf-8
X = input() 
n = 8
op =[0 for i in range(3)]
for i in range(n):
  p = bin(i)[2:]
  p = "0"*(3-len(p))+p
  Y =""
  for j,k in enumerate(X):
    Y +=k
    if j < 3:
      if p[j:j+1] =="0":
        Y +="+"
      else:
        Y +="-"
  ans = eval(Y)
  if ans ==7:
    print(Y+"=7")
    break

Submission status: Accepted

Solution code:
k = list(map(int,input()))
jsum = 0
ans = str(k[0])
for i in range(2 ** 3):
    for j in range(3):
        bit = (i >> j) & 1
        jsum += (-1) ** bit * k[j + 1]
        if bit == 1:
            ans += "-"+str(k[j+1])
        else:
            ans += "+"+str(k[j+1])
    if k[0] + jsum == 7:
        print(ans+'=7')
        break
    jsum =0
    ans= str(k[0])

Submission status: Accepted

Solution code:
# /usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math


S = list(str(input()))


def calc(en):
  if len(en) != 3:
    return 0
  else:
    ret = int(S[0])
    for i in range(len(en)):
      if en[i] == "+":
        ret += int(S[i+1])
      else:
        ret -= int(S[i+1])
    return ret


def solve(i, en):
  if i == 4:
    if calc(en) == 7:
      return en
    else:
      return ""

  ret = max("", solve(i+1, en+"+"), solve(i+1, en+"-"))
  return ret


if __name__ == "__main__":
  en = solve(1, "")
  print(S[0]+en[0]+S[1]+en[1]+S[2]+en[2]+S[3]+"=7")

Submission status: Accepted

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

for i in range(1 << 3):
    check = int(S[0])
    for j in range(3):
        if i & (1<<j):
            check += int(S[j+1])
        else:
            check -= int(S[j+1])
    if check == 7:
        ans = S[0]
        for j in range(3):
            if i & (1<<j):
                ans += '+' + S[j+1]
            else:
                ans += '-' + S[j+1]
        break

ans += '=7'

print(ans)

Submission status: Accepted

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

MINUS = '-'
PLUS = '+'

def cal(a,b, what):
    if what == MINUS:
        return a - b
    else:
        return a+b


def print_ans(v):
    print('{}{}{}{}{}{}{}=7'.format(A,v[0],B,v[1],C,v[2],D))
    
    
li = []
for i in range(2):
    for j in range(2):
        for k in range(2):
            op1 = PLUS if i %2==0 else MINUS
            op2 = PLUS if j %2==0 else MINUS
            op3 = PLUS if k %2==0 else MINUS
            li.append([op1, op2, op3])

for v in li:
    t = cal(A, B, v[0])
    t = cal(t, C, v[1])
    t = cal(t, D, v[2])
    if t == 7:
        print_ans(v)
        break

Submission status: Accepted

Solution code:
import operator
S = input()
nums = []
for s in S:
    nums.append(int(s))

ope = {'+': operator.add, '-': operator.sub}
idx = {0:'+', 1:'-'}
for i in range(2):
    ans1 = ope[idx[i]](nums[0], nums[1])
    for j in range(2):
        ans2 = ope[idx[j]](ans1, nums[2])
        for k in range(2):
            if ope[idx[k]](ans2, nums[3]) == 7:
                print(str(nums[0])+idx[i]+str(nums[1])+idx[j]+str(nums[2])+idx[k]+str(nums[3])+'=7')
                quit()

Submission status: Accepted

Solution code:
def find(abcd):
    a, b, c, d = abcd
    ops = ['{}{}{}'.format(i, j, k)
           for i in [1, 2] for j in [1, 2] for k in [1, 2]]
    opr = {'1': '+', '2': '-'}

    for op in ops:
        expression = a + opr[op[0]] + b + opr[op[1]] + c + opr[op[2]] + d
        try:
            if eval(expression) == 7:
                return(expression)
        except SyntaxError:
            pass


def main():
    abcd = input()
    print('{}=7'.format(find(abcd)))


main()

Submission status: Accepted

Solution code:
ABCD = input()

for i in range(2 ** 3):
    ans = int(ABCD[0])
    pm = []
    for j in range(3):
        if (i >> j) & 1:
            ans += int(ABCD[j+1])
            pm.append("+")
        else:
            ans -= int(ABCD[j+1])
            pm.append("-")
    if ans == 7:
        print("{}{}{}{}{}{}{}=7".format(ABCD[0], pm[0], ABCD[1], pm[1], ABCD[2], pm[2], ABCD[3]))
        break

Submission status: Accepted

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

x = list(input())
del(x[4])
x = [int(i) for i in x]

if x[0]+x[1]+x[2]+x[3]==7:
    print(str(x[0]) + '+' + str(x[1]) + '+' + str(x[2]) + '+' + str(x[3]) + '=7')
    exit()
elif x[0]-x[1]+x[2]+x[3]==7:
    print(str(x[0]) + '-' + str(x[1]) + '+' + str(x[2]) + '+' + str(x[3]) + '=7')
    exit()
elif x[0]+x[1]-x[2]+x[3]==7:
    print(str(x[0]) + '+' + str(x[1]) + '-' + str(x[2]) + '+' + str(x[3]) + '=7')
    exit()
elif x[0]+x[1]+x[2]-x[3]==7:
    print(str(x[0]) + '+' + str(x[1]) + '+' + str(x[2]) + '-' + str(x[3]) + '=7')
    exit()
elif x[0]-x[1]-x[2]+x[3]==7:
    print(str(x[0]) + '-' + str(x[1]) + '-' + str(x[2]) + '+' + str(x[3]) + '=7')
    exit()
elif x[0]+x[1]-x[2]-x[3]==7:
    print(str(x[0]) + '+' + str(x[1]) + '-' + str(x[2]) + '-' + str(x[3]) + '=7')
    exit()
elif x[0]-x[1]+x[2]-x[3]==7:
    print(str(x[0]) + '-' + str(x[1]) + '+' + str(x[2]) + '-' + str(x[3]) + '=7')
    exit()
elif x[0]-x[1]-x[2]-x[3]==7:
    print(str(x[0]) + '-' + str(x[1]) + '-' + str(x[2]) + '-' + str(x[3]) + '=7')
    exit()

Submission status: Accepted

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

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

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
    result = eval(formula)
    if result == 7:
        print(formula + '=7')
        break

Submission status: Accepted

Solution code:
I = input()
for param in range(2**(len(I)-1)):
    ans = ""
    for i in range(len(I)):
        ans += I[i] + ["+","-",""][((param >> i) & 1) if i != len(I) - 1 else 2]
    if eval(ans) == 7:
        print(ans+"=7")
        break

Submission status: Accepted

Solution code:
i=input()
b=True
while b==True:
  if int(i[0])+int(i[1])+int(i[2])+int(i[3])==7:
    print(i[0]+"+"+i[1]+"+"+i[2]+"+"+i[3]+"="+"7")
    exit
    b=False
  elif int(i[0])+int(i[1])+int(i[2])-int(i[3])==7:
    print(i[0]+"+"+i[1]+"+"+i[2]+"-"+i[3]+"="+"7")
    exit
    b=False
  elif int(i[0])+int(i[1])-int(i[2])-int(i[3])==7:
    print(i[0]+"+"+i[1]+"-"+i[2]+"-"+i[3]+"="+"7")
    exit
    b=False
  elif int(i[0])-int(i[1])+int(i[2])-int(i[3])==7:
    print(i[0]+"-"+i[1]+"+"+i[2]+"-"+i[3]+"="+"7")
    exit
    b=False
  elif int(i[0])-int(i[1])-int(i[2])-int(i[3])==7:
    print(i[0]+"-"+i[1]+"-"+i[2]+"-"+i[3]+"="+"7")
    exit
    b=False
  elif int(i[0])+int(i[1])-int(i[2])+int(i[3])==7:
    print(i[0]+"+"+i[1]+"-"+i[2]+"+"+i[3]+"="+"7")
    exit
    b=False
  elif int(i[0])-int(i[1])+int(i[2])+int(i[3])==7:
    print(i[0]+"-"+i[1]+"+"+i[2]+"+"+i[3]+"="+"7")
    exit
    b=False
  elif int(i[0])-int(i[1])-int(i[2])+int(i[3])==7:
    print(i[0]+"-"+i[1]+"-"+i[2]+"+"+i[3]+"="+"7")
    exit
    b=False

Submission status: Accepted

Solution code:
s = input()
space = len(s) - 1
ans = 0

for i in range(2 ** space):
    formula = s[0]
    for j in range(space):
        if (i >> j) & 1:
            formula += "+"
        else:
            formula += "-"
        formula += s[j + 1]
    if eval(formula) == 7:
        print("{}=7".format(formula))
        break

Submission status: Accepted

Solution code:
a,b,c,d=[int(i) for i in input()]
#ans=a
p=["+","+","+","+","-","-","-","-"]
q=["+","+","-","-","+","+","-","-"]
r=["+","-","+","-","+","-","+","-"]
for i,j,k in zip(p,q,r):
    ans=a
    if i=="+":
        ans+=b
    else:
        ans-=b
    if j=="+":
        ans+=c
    else:
        ans-=c
    if k=="+":
        ans+=d
    else:
        ans-=d
    if ans==7:
        print("{}{}{}{}{}{}{}=7".format(str(a),i,str(b),j,str(c),k,str(d)))
        break

Submission status: Accepted

Solution code:
s=input()
m=["+","-"]
for i in m:
    for j in m:
        for k in m:
            a=s[0]+i+s[1]+j+s[2]+k+s[3]
            if eval(a)==7:
                print(a+"=7")
                break
        else:continue
        break
    else:continue
    break

Submission status: Accepted

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

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

for i in range(2**t):
    p = bin(i)[2:]
    p = "0"*(t - len(p))+p  # 桁数 t

    x = ""
    for j, k in enumerate(S):
        x += k
        if j != t and p[j] == "1":
            x += "+"
        elif j != t and p[j] == "0":
            x += "-"

    if eval(x) == 7:
        print("{0}=7".format(x))
        exit()

Submission status: Accepted

Solution code:
import sys, ast

def dfs(str_input,count = 1):
    if count == 7:
        if ast.literal_eval(str_input) == 7:
            print(str_input + "=7")
            sys.exit(0)
        else:
            return 0
    for i in ["+","-"]:
        dfs(str_input[:count] + i + str_input[count:], count = count + 2)

x = input()

dfs(x)

Submission status: Accepted

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

for i in range(2 ** space):
    f = s[0]
    for j in range(space):
        f += "+" if (i >> j) & 1 else "-"
        f += s[j + 1]

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

Submission status: Accepted

Solution code:
from itertools import product
ABCD = list(input())
ops = ['+', '-']

for op in list(product(ops, ops, ops)) :
    if eval(ABCD[0] + op[0] + ABCD[1] + op[1] + ABCD[2] + op[2] + ABCD[3]) == 7 :
        print(str(ABCD[0] + op[0] + ABCD[1] + op[1] + ABCD[2] + op[2] + ABCD[3])+'=7')
        break

Submission status: Accepted

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


def D2NC(D: int, N: int) -> list:
    res = []
    while D > 0:
        res.insert(0, D % N)
        D //= N
    if not res:
        res.append(0)
    res = [str(i) for i in res]
    return res


for i in range(2**3):
    pattern = ''.join(D2NC(i, 2)).zfill(3)
    ans = ABCD[0]
    idx = 0
    op = []
    for j in pattern:
        if j == '0':
            ans += ABCD[idx+1]
            op.append('+')
        else:
            ans -= ABCD[idx+1]
            op.append('-')
        idx += 1
    if ans == 7:
        break

A, B, C, D = ABCD
op_1, op_2, op_3 = op
print('{}{}{}{}{}{}{}=7'.format(A, op_1, B, op_2, C, op_3, D))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
 
abc = input()
 
OP = ['+','-']
ans = 0
for op1 in OP:
    for op2 in OP:
        for op3 in OP:
            if eval(abc[0]+op1+abc[1]+op2+abc[2]+op3+abc[3]) == 7:
                ans = abc[0]+op1+abc[1]+op2+abc[2]+op3+abc[3]
print(ans+'=7')

Submission status: Accepted

Solution code:
s=input()
for i in range(8):
    y="".join([s[k]+"+-"[i>>k&1]for k in range(3)]+[s[-1]])
    if eval(y)==7:
        print(y+"=7")
        exit()

Submission status: Accepted

Solution code:
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    S = list(_ for _ in input())
    e= ''
    for i in range(2**3):
        e=S[0]
        for j in range(0,3):
            if 1<<j & i:
                e+='+'
            else:
                e+='-'
            e+=S[j+1]
        if eval(e) == 7:
            e+='=7'
            break
    print(e)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# ABC 079 C Train Ticket
S = [i for i in list(input())]

for i in range(2**(len(S)-1)):
  ops = [S[0]]
  for j in range(len(S)-1):
    if (i >> j) & 1:
      ops.append("+")
      ops.append(S[j+1])
    else:
      ops.append("-")
      ops.append(S[j+1])
      
  expr = "".join(ops)
  if eval(expr) == 7:
    print(expr + "=7")
    break

Submission status: Accepted

Solution code:
A, B, C, D = [int(i) for i in input()]
for i in "+-":
    for j in "+-":
        for k in "+-":
            ans = A + B if i == "+" else A - B
            ans = ans + C if j == "+" else ans - C
            ans = ans + D if k == "+" else ans - D
            if ans == 7:
                print(str(A) + i + str(B) + j + str(C) + k + str(D) + "=7")
                exit()

Submission status: Accepted

Solution code:
abcd = input()

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

counter = 0
if a - b - c - d == 7 and counter == 0:
    print(str(a)+'-'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
    counter += 1

if a - b - c + d == 7 and counter == 0:
    print(str(a)+'-'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
    counter += 1

if a - b + c - d == 7 and counter == 0:
    print(str(a)+'-'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
    counter += 1

if a - b + c + d == 7 and counter == 0:
    print(str(a)+'-'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
    counter += 1

if a + b - c - d == 7 and counter == 0:
    print(str(a)+'+'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
    counter += 1

if a + b - c + d == 7 and counter == 0:
    print(str(a)+'+'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
    counter += 1

if a + b + c - d == 7 and counter == 0:
    print(str(a)+'+'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
    counter += 1

if a + b + c + d == 7 and counter == 0:
    print(str(a)+'+'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
    counter += 1

Submission status: Accepted

Solution code:
s = input()
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])
ans = []
for i in [1,-1]:
    for j in [1,-1]:
        for k in [1,-1]:
            if a + b * i + c * j + d * k == 7:
                ans = [i,j,k]
                break
print(a,end="")
print('+' if ans[0] == 1 else '-',end="")
print(b,end="")
print('+' if ans[1] == 1 else '-',end="")
print(c,end="")
print('+' if ans[2] == 1 else '-',end="")
print(d,end="=7\n")

Submission status: Accepted

Solution code:
Astr = input()
Aint = [0]*4
for i in range(4):
  Aint[i] = int(Astr[i])
q = [1,1,1]
ans = 7-Aint[0]

while sum(q) != -3:
  a = [0]*3
  for i in range(3):
    a[i] = Aint[i+1]*q[i]
  if sum(a) == ans:
    print(str(Aint[0])+"{:+}{:+}{:+}".format(a[0],a[1],a[2])+"=7")
    break
  elif q[2] == 1:
    q[2] = -1
  elif q[1] == 1:
    q[1] = -1
    q[2] = 1
  else:
    q[0] = -1
    q[1] = 1
    q[2] = 1

Submission status: Accepted

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

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

  formula = ''
  op = op + ['']
  for s_, p_ in zip(list(s), op):
      formula += s_ + p_
  if eval(formula) == 7:
      print(formula+'=7')
      exit()

Submission status: Accepted

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

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

  formula = ''
  op = op + ['']
  for s_, p_ in zip(list(s), op):
      formula += s_ + p_
  if eval(formula) == 7:
      print(formula+'=7')
      exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def dfs(s,plus,i):

    i += 1

    if i == 4:
        ans = int(s[0])
        for j in range(1,4):
            ans += int(s[j])*plus[j-1]
        if ans == 7:
            ret = s[0]
            for k in range(1,4):
                if plus[k-1] == 1:
                    ret += '+'
                else:
                    ret += '-'
                ret += s[k]
            ret += '=7'
            print(ret)
            exit()
        return

    plus[i-1] = 1
    dfs(s, plus, i)

    plus[i-1] = -1
    dfs(s, plus, i)

    return


dfs(input(), [0,0,0], 0)

Submission status: Accepted

Solution code:
s=input()
for i in range(2**3):
  b=bin(i)[2:].zfill(3)
  a=s[0]
  for i in range(3):a+=("+"if b[i]=="0"else"-")+s[i+1]
  if eval(a)==7:print(a+"=7");exit()

Submission status: Accepted

Solution code:
import itertools

num_list = input()
rule = '+-'

for ops in itertools.product(rule, repeat=3):
    ans = '{}{}{}{}{}{}{}'.format(num_list[0], ops[0], num_list[1], ops[1], num_list[2], ops[2], num_list[3])
    res = eval(ans)
    if res == 7:
        print('{}=7'.format(ans))
        break

Submission status: Accepted

Solution code:
s=str(input())
n1=int(s[0])
n2=int(s[1])
n3=int(s[2])
n4=int(s[3])
sum1=0
sum2=0
sum3=0
ans=''
op=['+','-']
for i in range(2):
  if i == 0:
    sum1 = n1+n2
  else:
    sum1 = n1-n2
  for j in range(2):
    if j == 0:
      sum2 = sum1+n3
    else:
      sum2 = sum1-n3
    for k in range(2):
      if k == 0:
        sum3=sum2+n4
      else:
        sum3=sum2-n4
      if sum3==7:
        ans=str(n1)+op[i]+str(n2)+op[j]+str(n3)+op[k]+str(n4)+'=7'
print(ans)

Submission status: Accepted

Solution code:
N = input()
A, B, C, D = int(N[0]), int(N[1]), int(N[2]), int(N[3])
OP = ["+", "-"]

ANS = 0
flg = False


for op1 in OP:
    if flg is True:
        break
    ANS = A
    if op1 == "+":
        ANS = ANS + B
    else:
        ANS = ANS - B
    for op2 in OP:
        if flg is True:
            break
        ANS2 = ANS
        if op2 == "+":
            ANS2 = ANS + C
        else:
            ANS2 = ANS - C
        for op3 in OP:
            ANS3 = ANS2
            if op3 == "+":
                ANS3 = ANS2 + D
            else:
                ANS3 = ANS2 - D
            if ANS3 == 7:
                print("%d%s%d%s%d%s%d=7" % (A, op1, B, op2, C, op3, D))
                flg = True
                break

Submission status: Accepted

Solution code:
from collections import deque
A,B,C,D = list(input())

dq = deque()
dq.append("")
while dq:
    op = dq.pop()
    if len(op) == 3:
        res = A + op[0] + B + op[1] + C + op[2] + D
        if eval(res) == 7:
            ans = res + "=7"
            print(ans)
            break
    else:
        dq.append(op+"+")
        dq.append(op+"-")

Submission status: Accepted

Solution code:
from collections import deque
A,B,C,D = list(input())

dq = deque()
dq.append("")
while dq:
    op = dq.popleft()
    if len(op) == 3:
        res = A + op[0] + B + op[1] + C + op[2] + D
        if eval(res) == 7:
            ans = res + "=7"
            print(ans)
            break
    else:
        dq.append(op+"+")
        dq.append(op+"-")

Submission status: Accepted

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

def dfs(depth=0,op=""):
    if depth == 3:
        res = A + op[0] + B + op[1] + C + op[2] + D
        if eval(res) == 7:
            ans = res + "=7"
            print(ans)
            exit()
        return
    dfs(depth+1,op+"+")
    dfs(depth+1,op+"-")

dfs()

Submission status: Accepted

Solution code:
a = input()
x,  y,  z,  b=int(a[0]),  int(a[1]),  int(a[2]),  int(a[3])
if x+y+z+b==7:
    print("{}+{}+{}+{}=7".format(x, y, z, b))
elif x-y-z-b==7:
    print("{}-{}-{}-{}=7".format(x, y, z, b))
elif x+y+z-b==7:
    print("{}+{}+{}-{}=7".format(x, y, z, b))
elif x+y-z+b==7:
    print("{}+{}-{}+{}=7".format(x, y, z, b))
elif x-y+z+b==7:
    print("{}-{}+{}+{}=7".format(x, y, z, b))
elif x+y-z-b==7:
    print("{}+{}-{}-{}=7".format(x, y, z, b))
elif x-y-z+b==7:
    print("{}-{}-{}+{}=7".format(x, y, z, b))
else:
    print("{}-{}+{}-{}=7".format(x, y, z, b))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
S = input()
ans = 0
for i in range(1 << len(S)): # 階乗(1,2,4,8...)
    string = str(0)
    tmp = 0
    enzan = []
    for j in range(len(S)):
        if ((i >> j) & 1) == 1:
            tmp+=int(S[j])
            enzan.append("+")
        else:
            tmp -= int(S[j])
            enzan.append("-")
    #print(tmp)
    if tmp == 7:
        #print(enzan)
        print(S[0]+enzan[1]+S[1]+enzan[2]+S[2]+enzan[3]+S[3]+"=7")
        exit()

Submission status: Accepted

Solution code:
import sys
from sys import stdin
abcd = [int(c) for c in list(stdin.readline().rstrip())]
op = ['+', '-']
for i in op:
    for j in op:
        for k in op:
            result=abcd[0]
            if i == '+':
                result+=abcd[1]
            else:
                result-=abcd[1]
            if j == '+':
                result+=abcd[2]
            else:
                result-=abcd[2]
            if k == '+':
                result+=abcd[3]
            else:
                result-=abcd[3]
            if result == 7:
                print(abcd[0], end='')
                print(i, end='')
                print(abcd[1], end='')
                print(j, end='')
                print(abcd[2], end='')
                print(k, end='')
                print(abcd[3], end='')
                print('=7')
                sys.exit()

Submission status: Accepted

Solution code:
lst = ['+', '-']
S = raw_input()
oplst = []
for i in range(0, 8):
	op = []
	n = i
	for i in range(0, 3):
		op.append(n%2)
		n = n/2
	oplst.append(op)
for i in range(0, 8):
	sum = int(S[0])
	for j in range(0, 3):
		if oplst[i][j] == 0:
			sum += int(S[j+1])
		else:
			sum -= int(S[j+1])
	if sum == 7:
		ans = S[0]
		for j in range(0, 3):
			ans = ans + lst[oplst[i][j]] + S[j+1]
		ans = ans + '=7'
		print ans
		break

Submission status: Accepted

Solution code:
import sys
A,B,C,D=input()
for a in ("-","+"):
    for b in ("-","+"):
        for c in ("-","+"):
            if eval(A+a+B+b+C+c+D)==7:
                print(A+a+B+b+C+c+D+"=7")
                sys.exit()

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(a, '+', b, '+', c, '+', d, '=7', sep='')
elif a + b + c - d == 7:
    print(a, '+', b, '+', c, '-', d, '=7', sep='')
elif a + b - c + d == 7:
    print(a, '+', b, '-', c, '+', d, '=7', sep='')
elif a + b - c - d == 7:
    print(a, '+', b, '-', c, '-', d, '=7', sep='')
elif a - b + c + d == 7:
    print(a, '-', b, '+', c, '+', d, '=7', sep='')
elif a - b + c - d == 7:
    print(a, '-', b, '+', c, '-', d, '=7', sep='')
elif a - b - c + d == 7:
    print(a, '-', b, '-', c, '+', d, '=7', sep='')
elif a - b - c - d == 7:
    print(a, '-', b, '-', c, '-', d, '=7', sep='')

Submission status: Accepted

Solution code:
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
import collections
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yay!")
    else:print(":(")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
#n = ip()                                     #入力整数1つ
#n,q= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
b = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(5)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
a = []
for i in range(4):
    a.append(int(b[i]))
if a[0] + a[1] + a[2] + a[3] == 7: c = [b[0],'+',b[1],'+',b[2],'+',b[3],'=7']
if a[0] + a[1] + a[2] - a[3] == 7: c = [b[0],'+',b[1],'+',b[2],'-',b[3],'=7']
if a[0] + a[1] - a[2] + a[3] == 7: c = [b[0],'+',b[1],'-',b[2],'+',b[3],'=7']
if a[0] + a[1] - a[2] - a[3] == 7: c = [b[0],'+',b[1],'-',b[2],'-',b[3],'=7']
if a[0] - a[1] + a[2] + a[3] == 7: c = [b[0],'-',b[1],'+',b[2],'+',b[3],'=7']
if a[0] - a[1] + a[2] - a[3] == 7: c = [b[0],'-',b[1],'+',b[2],'-',b[3],'=7']
if a[0] - a[1] - a[2] + a[3] == 7: c = [b[0],'-',b[1],'-',b[2],'+',b[3],'=7']
if a[0] - a[1] - a[2] - a[3] == 7: c = [b[0],'-',b[1],'-',b[2],'-',b[3],'=7']
print(''.join(c))

Submission status: Accepted

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

for state in range(1 << (len(ticket)-1)):
    fomula = ticket[0] + ''.join(('+' if state >> i & 1 else '-') + x for i, x in enumerate(ticket[1:]))
    if eval(fomula) == 7:
        print(fomula + ''.join('=7'))
        exit()