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:
ticket = list(input())
if int(ticket[0])+int(ticket[1])+int(ticket[2])+int(ticket[3])==7:
    print(ticket[0]+"+"+ticket[1]+"+"+ticket[2]+"+"+ticket[3]+"=7")
elif int(ticket[0])-int(ticket[1])+int(ticket[2])+int(ticket[3])==7:
    print(ticket[0]+"-"+ticket[1]+"+"+ticket[2]+"+"+ticket[3]+"=7")
elif int(ticket[0])+int(ticket[1])-int(ticket[2])+int(ticket[3])==7:
    print(ticket[0]+"+"+ticket[1]+"-"+ticket[2]+"+"+ticket[3]+"=7")
elif int(ticket[0])+int(ticket[1])+int(ticket[2])-int(ticket[3])==7:
    print(ticket[0]+"+"+ticket[1]+"+"+ticket[2]+"-"+ticket[3]+"=7")
elif int(ticket[0])-int(ticket[1])-int(ticket[2])+int(ticket[3])==7:
    print(ticket[0]+"-"+ticket[1]+"-"+ticket[2]+"+"+ticket[3]+"=7")
elif int(ticket[0])-int(ticket[1])+int(ticket[2])-int(ticket[3])==7:
    print(ticket[0]+"-"+ticket[1]+"+"+ticket[2]+"-"+ticket[3]+"=7")
elif int(ticket[0])+int(ticket[1])-int(ticket[2])-int(ticket[3])==7:
    print(ticket[0]+"+"+ticket[1]+"-"+ticket[2]+"-"+ticket[3]+"=7")
elif int(ticket[0])-int(ticket[1])-int(ticket[2])-int(ticket[3])==7:
    print(ticket[0]+"-"+ticket[1]+"-"+ticket[2]+"-"+ticket[3]+"=7")

Submission status: Accepted

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

opt1, opt2, opt3 = "","",""
if a+b+c+d==7:
    opt1,opt2,opt3="+", "+", "+"
elif a-b+c+d==7:
    opt1,opt2,opt3="-", "+", "+"
elif a+b-c+d==7:
    opt1,opt2,opt3="+", "-", "+"
elif a+b+c-d==7:
    opt1,opt2,opt3="+", "+", "-"
elif a-b-c+d==7:
    opt1,opt2,opt3="-", "-", "+"
elif a-b+c-d==7:
    opt1,opt2,opt3="-", "+", "-"
elif a+b-c-d==7:
    opt1,opt2,opt3="+", "-", "-"
elif a-b-c-d==7:
    opt1,opt2,opt3="-", "-", "-"
print("%d%s%d%s%d%s%d=7" %(a,opt1,b,opt2,c,opt3,d))

Submission status: Accepted

Solution code:
ticket = list(input())
if int(ticket[0])+int(ticket[1])+int(ticket[2])+int(ticket[3])==7:
    print(ticket[0]+"+"+ticket[1]+"+"+ticket[2]+"+"+ticket[3]+"=7")
elif int(ticket[0])-int(ticket[1])+int(ticket[2])+int(ticket[3])==7:
    print(ticket[0]+"-"+ticket[1]+"+"+ticket[2]+"+"+ticket[3]+"=7")
elif int(ticket[0])+int(ticket[1])-int(ticket[2])+int(ticket[3])==7:
    print(ticket[0]+"+"+ticket[1]+"-"+ticket[2]+"+"+ticket[3]+"=7")
elif int(ticket[0])+int(ticket[1])+int(ticket[2])-int(ticket[3])==7:
    print(ticket[0]+"+"+ticket[1]+"+"+ticket[2]+"-"+ticket[3]+"=7")
elif int(ticket[0])-int(ticket[1])-int(ticket[2])+int(ticket[3])==7:
    print(ticket[0]+"-"+ticket[1]+"-"+ticket[2]+"+"+ticket[3]+"=7")
elif int(ticket[0])-int(ticket[1])+int(ticket[2])-int(ticket[3])==7:
    print(ticket[0]+"-"+ticket[1]+"+"+ticket[2]+"-"+ticket[3]+"=7")
elif int(ticket[0])+int(ticket[1])-int(ticket[2])-int(ticket[3])==7:
    print(ticket[0]+"+"+ticket[1]+"-"+ticket[2]+"-"+ticket[3]+"=7")
elif int(ticket[0])-int(ticket[1])-int(ticket[2])-int(ticket[3])==7:
    print(ticket[0]+"-"+ticket[1]+"-"+ticket[2]+"-"+ticket[3]+"=7")

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import itertools

abcd = input()
for op in itertools.product(['+', '-'], repeat=3):
    formula = abcd[0] + op[0] + abcd[1] + op[1] + abcd[2] + op[2] + abcd[3]
    if eval(formula) == 7:
        print(formula + "=7")
        exit()

Submission status: Accepted

Solution code:
a,b,c,d=input()
for i in range(2**3):
    ls =['+','+','+']
    for j in range(len(ls)):
        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:
a,*x=list(map(int,input()))
for i in range(8):
    k=a
    ans=str(a)
    for j in range(3):
        if i>>j&1:
            k+=x[j]
            ans+="+"+str(x[j])
        else:
            k-=x[j]
            ans+="-"+str(x[j])
    if k==7:
        print(ans+"=7")
        exit()

Submission status: Accepted

Solution code:
S = input()

for i in range(2 ** 3):
  op = ['+','+','+','+']
  ans = int(S[0])
  bit = bin(i)
  bit = bit[2:len(bit)].zfill(3)
  for j in range(len(S)-1):
    if bit[j] == "0":
      ans += int(S[j+1])
      op[j] = '+'
      #S.insert(j+1,'+')
    else:
      ans -= int(S[j+1])
      op[j] = '-'
      #S.insert(j+1,'-')
  if ans == 7:
    print(S[0]+op[0]+S[1]+op[1]+S[2]+op[2]+S[3]+"=7")
    break

Submission status: Accepted

Solution code:
n = input()
cnt = len(n) -1
for i in range(2 ** cnt):
    op = ["-"] * cnt
    for j in range(cnt):
        if ((i >> j) & 1):
            op[cnt - 1 - j] = "+"

    formula = ""
    for p_n,p_o in zip(n,op+[""]):
        formula += (p_n + p_o)
    if eval(formula) == 7:
        print(formula + "=7")
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
for bit in range(1<<3):
  ans=int(s[0])
  f=s[0]
  for i in range(3):
    if bit & (1<<i):
      ans+=int(s[i+1])
      f+="+"
    else:
      ans-=int(s[i+1])
      f+="-"
    f+=s[i+1]
  if ans==7:
    print(f+"=7")
    exit()

Submission status: Accepted

Solution code:
def q3():
    import itertools
    li = [int(i) for i in list(input())]

    ans_op = None
    ops = list(itertools.product(['+','-'], repeat=3))
    for op in ops:
        tmp_sum = li[0]
        for i, o in enumerate(op):
            if o == '+':
                tmp_sum += li[i+1]
            else:
                tmp_sum -= li[i+1]
        if tmp_sum == 7:
            ans_op = op
            break

    return '{}{}{}{}{}{}{}=7'.format(li[0], op[0], li[1], op[1], li[2], op[2], li[3])


if __name__ == "__main__":
    print(q3())

Submission status: Accepted

Solution code:
a,b,c,d = map(int,input())
op1,op2,op3 = "","",""
if a+b+c+d==7:
  op1,op2,op3 = "+","+","+"
elif a+b+c-d==7:
  op1,op2,op3 = "+","+","-"
elif a+b-c+d==7:
  op1,op2,op3 = "+","-","+"
elif a+b-c-d==7:
  op1,op2,op3 = "+","-","-"
elif a-b-c-d==7:
  op1,op2,op3 = "-","-","-"
elif a-b-c+d==7:
  op1,op2,op3 = "-","-","+"
elif a-b+c-d==7:
  op1,op2,op3 = "-","+","-"
elif a-b+c+d==7:
  op1,op2,op3 = "-","+","+"
print("%d%s%d%s%d%s%d=7" % (a,op1,b,op2,c,op3,d))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
def solve(a, b, c, d):

    for operators in itertools.product(["+", "-"], repeat=3):
        ans = str(a)
        tmp = a
        for n, op in zip([b,c,d], operators):
            ans += op + str(n)
            if op == "+":
                tmp += n
            else:
                tmp -= n
        if tmp == 7:
            break

    return ans + "=7"

if __name__ == "__main__":
    a,b,c,d = [int(i) for i in input()]
    print(solve(a, b, c, d))

Submission status: Accepted

Solution code:
# coding:utf-8
number = input()
# ABCD 隙間の数は3
n = 3

for bit in range(2 ** n):
    ope = ['-'] * n
    for i in range(n):
        if ((bit >> i) & 1):
            ope[n - 1 - i] = '+'
    # print(ope)
    ans = ''

    for num, op in zip(number, ope):
        ans += num + op
    ans += number[-1]
    if eval(ans) == 7:
        print(ans + '=7')
        exit()

Submission status: Accepted

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


def solve(ABCD: str):
    from itertools import product
    base = '{}{{}}{}{{}}{}{{}}{}'.format(*ABCD)
    for ops in product('+-', repeat=3):
        exp = base.format(*ops)
        if eval(exp) == 7:
            return exp + '=7'
    raise


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    ABCD = next(tokens)
    print(solve(ABCD))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Submission status: Accepted

Solution code:
ABCD=input()
dic={}
dic[1]="+"
dic[0]="-"
for i in range(8):
  result=int(ABCD[0])
  kigou=[]
  for j in range(3):
    if ((i >> j) & 1):
      kigou+=[dic[1]]
      result+=int(ABCD[3-j])
    else:
      kigou+=[dic[0]]
      result-=int(ABCD[3-j])
  if result==7:
    print(ABCD[0]+kigou[2]+ABCD[1]+kigou[1]+ABCD[2]+kigou[0]+ABCD[3]+"=7")
    break

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:
ABCD = input()
ans = ''
def dfs(i, s):
    global ans
    s += ABCD[i]
    if i == 3:
        if eval(s) == 7:
            ans = s
        return
    i += 1
    dfs(i, s+'+')
    dfs(i, s+'-')
dfs(0, '')
print(ans+'=7')

Submission status: Accepted

Solution code:
import sys
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

n = str(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
#A, B, C = map(int, stdin.readline().rstrip().split())
#numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
#word = [stdin.readline().rstrip() for _ in range(n)]
#number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
#zeros = [[0] * w for i in range(h)]
p = "+"
m = "-"
for i in range(2**3):
    ans = ""
    check = int(n[0])
    for j in range(3):
        ans += n[j]
        if ((i >> j) & 1):
            ans += p
            check += int(n[j+1])
        else:
            ans += m
            check -= int(n[j+1])
    ans += n[3]
    if check == 7:
        ans += "=7"
        print(ans)
        exit()

Submission status: Accepted

Solution code:
nums = list(input())
for i in range(2**3):
    seven = int(nums[0])
    opt = []
    for j in range(3):
        if i >> j & 1:
            seven += int(nums[j+1])
            opt.append("+")
        else:
            seven -= int(nums[j+1])
            opt.append("-")
    if seven == 7:
        print(nums[0]+opt[0]+nums[1]+opt[1]+nums[2]+opt[2]+nums[3]+"=7")
        exit()

Submission status: Accepted

Solution code:
x=[int(k) for k in input()]
for i in range(2**3):
  total=x[0]
  bag=[""]*3
  for j in range(3):
    if (i>>j)&1:
      bag[j]="+"
      total+=x[j+1]
    else:
      bag[j]="-"
      total-=x[j+1]
  if total==7:
    print("{}{}{}{}{}{}{}=7".format(x[0],bag[0],x[1],bag[1],x[2],bag[2],x[3]))
    break

Submission status: Accepted

Solution code:
import numpy as np

abcd = input()
#a,b,c,d = [s for s in abcd]

for i in range(2**3):
    ops = ["-","-","-",""]
    for j in range(3):
        if i>>j&1: ops[j] = "+"
    equa = ""
    for s,op in zip(abcd,ops): equa += s+op
    if eval(equa) == 7 : break

ans = equa + "=7"
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

abcd = input()
#a,b,c,d = [s for s in abcd]

for i in range(2**3):
    ops = ["-","-","-",""]
    for j in range(3):
        if i>>j&1: ops[j] = "+"
    equa = ""
    for s,op in zip(abcd,ops): equa += (s+op)
    if eval(equa) == 7 : break

ans = equa + "=7"
print(ans)

Submission status: Accepted

Solution code:
s = input()
for i in range(2**3):
    l=[]
    for j in range(3):
        if (i>>j)&1:
            l.append("+")
        else:
            l.append("-")
    x = ""
    for k,lp in zip(s,l):
        x+=k
        x+=lp
    x+=s[-1]
    if eval(x)==7:
        print(x+"=7")
        break

Submission status: Accepted

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

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

for s in range(2**3):
    total = num[0]
    op = [""] * 3
    for i in range(3):
        if (s >> i & 1):
            total += num[i+1]
            op[i] = "+"
        else:
            total -= num[i+1]
            op[i] = "-"
    if (total == 7):
        print("{}{}{}{}{}{}{}=7".format(num[0],op[0],num[1],op[1],num[2],op[2],num[3]))
        break

Submission status: Accepted

Solution code:
S = input()
num = [int(S[i]) for i in range(4)]

for i in range(2 ** 3):
    ans = ''
    total = 0
    k = 3
    for j in range(3):
        if (i >> j) & 1:
            total += num[k]
            ans = ('+' + str(num[k])) + ans
        else:
            total -= num[k]
            ans = ('-' + str(num[k])) + ans
        k -= 1
    
    if total + num[0] == 7:
        print(str(num[0]) + ans + '=7')
        break

Submission status: Accepted

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

for x in list(product(["+", "-"], repeat=n)):
    x = list(x)
    x.append("")
    
    strs = [i+j for i, j in zip(s, x)]
    if eval("".join(strs)) == 7:
        print("".join(strs) + "=7")
        break

Submission status: Accepted

Solution code:
n = input()

for i in range(2**3):
    calcu=['-']*3
    for j in range(3):
        if (i>>j)&1:
            calcu[3-1-j]='+'
    formula=''
    for tmp_1,tmp_2 in zip(n,calcu+['']):
        formula+=(tmp_1+tmp_2)
    if eval(formula)==7:
        print(formula+'=7')
        break

Submission status: Accepted

Solution code:
from itertools import product

a = list(str(input()))


for bit in product([0,1],repeat=3): # 01の組み合わせ
    x = ["+","+","+"]
    for i,j in enumerate(bit): 
        #print(bit,i,j)
        if j == 1:
            x[i] = "-"
    if eval(a[0]+x[0]+a[1]+x[1]+a[2]+x[2]+a[3]) == 7:
        print(a[0]+x[0]+a[1]+x[1]+a[2]+x[2]+a[3]+"=7")
        break 


"""       i j
(0, 0, 0) 0 0
(0, 0, 0) 1 0
(0, 0, 0) 2 0

(0, 0, 1) 0 0
(0, 0, 1) 1 0
(0, 0, 1) 2 1

(0, 1, 0) 0 0
(0, 1, 0) 1 1
(0, 1, 0) 2 0

(0, 1, 1) 0 0
(0, 1, 1) 1 1
(0, 1, 1) 2 1

(1, 0, 0) 0 1
(1, 0, 0) 1 0
(1, 0, 0) 2 0

(1, 0, 1) 0 1
(1, 0, 1) 1 0
(1, 0, 1) 2 1

(1, 1, 0) 0 1
(1, 1, 0) 1 1
(1, 1, 0) 2 0

(1, 1, 1) 0 1
(1, 1, 1) 1 1
(1, 1, 1) 2 1
"""

Submission status: Accepted

Solution code:
S = list(input())
L = len(S)

for i in range(0, 1 << L-1):
    f = S[0]
    ans = int(S[0])
    for j in range(L-1):
        if (i >> j) & 1:
            f += "+"
            f += S[j+1]
            ans += int(S[j+1])
        else:
            f += "-"
            f += S[j+1]
            ans -= int(S[j+1])
    if ans == 7:
        print(f, "=7", sep="")
        exit()

Submission status: Accepted

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


for i in range(2**3):
    x = ["+","+","+"]
    for j in range(len(a)):
        if (i >> j) & 1 == 1:
            x[j] = "-"
    if eval(a[0]+x[0]+a[1]+x[1]+a[2]+x[2]+a[3]) == 7:
        print(a[0]+x[0]+a[1]+x[1]+a[2]+x[2]+a[3]+"=7")
        break

Submission status: Accepted

Solution code:
def dfs(i,f,sum):
    if i==3:
        if sum==7:
            print(f+"=7")
            exit()

    else:
        dfs(i+1,f+"+"+s[i+1],sum+int(s[i+1]))
        dfs(i + 1, f + "-" + s[i + 1], sum - int(s[i + 1]))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A = list(input())
S = [-1,1]
res = ["-","+"]
for i in range(2):
    for j in range(2):
        for k in range(2):
            if int(A[0])+int(A[1])*S[i]+int(A[2])*S[j]+int(A[3])*S[k] == 7:
                print(A[0]+res[i]+A[1]+res[j]+A[2]+res[k]+A[3]+"=7")
                exit()

Submission status: Accepted

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

for bit in range(1<<(n-1)):
  f=s[0]
  a=int(s[0])
  for i in range(n-1):
    if bit & (1<<i):
      f+="+"+s[i+1]
      a+=int(s[i+1])
    else:
      f+="-"+s[i+1]
      a-=int(s[i+1])
  if a==7:
    print(f+"=7")
    exit()

Submission status: Accepted

Solution code:
from sys import exit
def dfs(i,f,sum):
  if i == n-1:
    if sum ==7:
      print(f+"=7")
      exit()
      
  else:
    dfs(i + 1, f + "+" + s[i + 1], sum+int(s[i+1]))
    dfs(i + 1, f + "-" + s[i + 1], sum-int(s[i+1]))



s=input()
n=len(s)
dfs(0, s[0],int(s[0]))

Submission status: Accepted

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

ls = ["+"] * 3


for i in range(2**3):
    ls = ["+"] * 3
    for j in range(len(ls)):
        
        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:
import sys
s = input()
n = len(s)

ans = 7

for bit in range(2**(n-1)):
    tmp = s[0]
    for i in range(n-1):
        if (1<<i)&bit:
            tmp += '+'
        else:
            tmp += '-'
        tmp += s[i+1]
    total = eval(tmp)
    if total == ans:
        print(tmp + '=7')
        sys.exit()

Submission status: Accepted

Solution code:
s = input()
for i in range(8):
    fom_lst = []
    for j in range(3):
        if (i >> j) & 1:
            fom_lst.append('+')
        else:
            fom_lst.append('-')
        S = ''
    for num, fom in zip(s, fom_lst):
        S += num + fom
    S += s[-1]
    if eval(S) == 7:
        print(S + '=7')
        break

Submission status: Accepted

Solution code:
#abcd = list(map(int,input().split()))
abcd = input()
ans = ""
#print(abcd[0])

# tmp = int(abcd[0]) + int(abcd[1])
# print(tmp)

if int(abcd[0]) + int(abcd[1]) + int(abcd[2]) + int(abcd[3]) == 7:
    ans = abcd[0] + "+" + abcd[1] + "+" + abcd[2] + "+" + abcd[3] + "=7"
elif int(abcd[0]) + int(abcd[1]) + int(abcd[2]) - int(abcd[3]) == 7:
    ans = abcd[0] + "+" + abcd[1] + "+" + abcd[2] + "-" + abcd[3] + "=7"
elif int(abcd[0]) + int(abcd[1]) - int(abcd[2]) + int(abcd[3]) == 7:
    ans = abcd[0] + "+" + abcd[1] + "-" + abcd[2] + "+" + abcd[3] + "=7"
elif int(abcd[0]) + int(abcd[1]) - int(abcd[2]) - int(abcd[3]) == 7:
    ans = abcd[0] + "+" + abcd[1] + "-" + abcd[2] + "-" + abcd[3] + "=7"
elif int(abcd[0]) - int(abcd[1]) + int(abcd[2]) + int(abcd[3]) == 7:
    ans = abcd[0] + "-" + abcd[1] + "+" + abcd[2] + "+" + abcd[3] + "=7"
elif int(abcd[0]) - int(abcd[1]) + int(abcd[2]) - int(abcd[3]) == 7:
    ans = abcd[0] + "-" + abcd[1] + "+" + abcd[2] + "-" + abcd[3] + "=7"
elif int(abcd[0]) - int(abcd[1]) - int(abcd[2]) + int(abcd[3]) == 7:
    ans = abcd[0] + "-" + abcd[1] + "-" + abcd[2] + "+" + abcd[3] + "=7"
elif int(abcd[0]) - int(abcd[1]) - int(abcd[2]) - int(abcd[3]) == 7:
    ans = abcd[0] + "-" + abcd[1] + "-" + abcd[2] + "-" + abcd[3] + "=7"

print(ans)

Submission status: Accepted

Solution code:
s = input()
length = 4 # fixed

for bit in range(1<<(length-1)):  # for bit in range(2 ** (length-1)):
  ans = 0
  f = s[0]  
  for i in range(length-1): 
    if bit & (1 << i):   # 0はプラス、1はマイナス
      f += "-"
    else:
      f += "+"
    f += s[i + 1]
  # print('d:',f)
  ans = eval(f)
  
  if ans == 7:
    print(f+'=7')
    exit()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
num_list = list(map(int, list(input())))
i = 0
for i in range(2 ** 3):
    result = num_list[0]
    result += num_list[1] * (1 if (i & 0b001) != 0 else -1)
    result += num_list[2] * (1 if (i & 0b010) != 0 else -1)
    result += num_list[3] * (1 if (i & 0b100) != 0 else -1)
    if result == 7:
        break

print("{}{}{}{}{}{}{}=7".format(
    num_list[0],
    '+' if (i & 0b001) != 0 else '-',
    num_list[1],
    '+' if (i & 0b010) != 0 else '-',
    num_list[2],
    '+' if (i & 0b100) != 0 else '-',
    num_list[3]
))

Submission status: Accepted

Solution code:
def main():
    S = input()
    n = len(S)
    bit = 0
    total = 0
    ans = ''
    for bit in range(1<<n-1):
        tmp_total = int(S[0])
        ops = ''
        for i in range(n-1):
            if (1<<i) & bit:
                tmp_total += int(S[i+1])
                ops += '+'
            else:
                tmp_total -= int(S[i+1])
                ops += '-'
        if tmp_total == 7:
            ans = S[0]
            for i,op in enumerate(ops):
                ans += op + S[i+1]
            ans += '=7'
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
line = input()
List = [int(line[x]) for x in range(4)]
A,B,C,D = List
List_ans = []

for i in range(8):
  s = A
  List_mark = []
  for j in range(3):
    if ((i>>j) & 1)== 0:
      s = s - List[-(j+1)]
      x_j = '-'
    else:
      s = s + List[-(j+1)]
      x_j = '+'
    List_mark.append(x_j)
  if s ==7:
    List_ans.append(List_mark)

x = List_ans[0]
print(str(A)+x[-1]+str(B)+x[-2]+str(C)+x[-3]+str(D)+'=7')

Submission status: Accepted

Solution code:
s=input()
ans=''
for i in range(8):
    l=''
    for j in range(4):
        l+=s[j]
        if j!=3:
            l+='+' if (i>>j)&1 else '-'
    if eval(l)==7:
        ans=l
        break
print(l+'=7')

Submission status: Accepted

Solution code:
abcd = input()
answers =[]

for i in range(2**3):
    a = int(abcd[0])
    b = int(abcd[1])
    c = int(abcd[2])
    d = int(abcd[3])
    plus_minus = [1,1,1]
    for j in range(3):
        if (i >> j)& 1:
            plus_minus[j] = -1
    ans = a + b*plus_minus[0] + c*plus_minus[1] + d*plus_minus[2]
    if ans == 7:
        pmw =[]
        for j in range(3):
            if plus_minus[j] == -1:
                pmw.append("-")
            else:
                pmw.append("+")
        print(str(a)+pmw[0]+str(b)+pmw[1]+str(c)+pmw[2]+str(d)+"=7")
        break

Submission status: Accepted

Solution code:
#bit探索
s=input()

for i in range(2**3):
    t=["-"]*3
    for j in range(3):
        if((i>>j)&1)==1:
            t[2-j]="+"
    fomula=s[0]+t[0]+s[1]+t[1]+s[2]+t[2]+s[3]
    if eval(fomula)==7:
        print(fomula+"=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])

if a+b+c+d==7:
    print("{}+{}+{}+{}=7".format(a, b, c, d))
elif a+b+c-d==7:
    print("{}+{}+{}-{}=7".format(a, b, c, d))
elif a+b-c+d==7:
    print("{}+{}-{}+{}=7".format(a, b, c, d))
elif a-b+c+d==7:
    print("{}-{}+{}+{}=7".format(a, b, c, d))
elif a+b-c-d==7:
    print("{}+{}-{}-{}=7".format(a, b, c, d))
elif a-b-c+d==7:
    print("{}-{}-{}+{}=7".format(a, b, c, d))
elif a-b+c-d==7:
    print("{}-{}+{}-{}=7".format(a, b, c, d))
elif a-b-c-d==7:
    print("{}-{}-{}-{}=7".format(a, b, c, d))

Submission status: Accepted

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

if A+B+C+D == 7:
    print(str(A)+"+"+str(B)+"+"+str(C)+"+"+str(D)+"=7")
elif A+B+C-D == 7:
    print(str(A)+"+"+str(B)+"+"+str(C)+"-"+str(D)+"=7")
elif A+B-C+D == 7:
    print(str(A)+"+"+str(B)+"-"+str(C)+"+"+str(D)+"=7")
elif A+B-C-D == 7:
    print(str(A)+"+"+str(B)+"-"+str(C)+"-"+str(D)+"=7")
elif A-B+C+D == 7:
    print(str(A)+"-"+str(B)+"+"+str(C)+"+"+str(D)+"=7")
elif A-B+C-D == 7:
    print(str(A)+"-"+str(B)+"+"+str(C)+"-"+str(D)+"=7")
elif A-B-C+D == 7:
    print(str(A)+"-"+str(B)+"-"+str(C)+"+"+str(D)+"=7")
elif A-B-C-D == 7:
    print(str(A)+"-"+str(B)+"-"+str(C)+"-"+str(D)+"=7")

Submission status: Accepted

Solution code:
s = input()

a=s[0]
b=s[1]
c=s[2]
d=s[3]

ops = ['+','-']
for op1 in ops:
    for op2 in ops:
        for op3 in ops:
            equation = "".join([a,op1,b,op2,c,op3,d])
            solution = eval(equation)
            if solution ==7:
                answer = equation + "=7"

#7にしたい

print(answer)

Submission status: Accepted

Solution code:
import itertools
kouho = list(itertools.product([0,1],repeat=3))

ABCD = str(input())

result = ""

for i in kouho:
    
    cnt=0
    sum =0
    result=""
    
    for j in i:
        
        if j==0:
            
            if cnt==0:
                sum   += int(ABCD[cnt]) +int(ABCD[cnt+1])
                result +=ABCD[cnt] + "+" + ABCD[cnt+1]
            else:
                sum += int(ABCD[cnt+1])
                result += "+" + ABCD[cnt+1]
        else:
            
            if cnt==0:
                sum   +=  int(ABCD[cnt]) - int(ABCD[cnt+1])
                result +=  ABCD[cnt] +  "-" + ABCD[cnt+1]
            else:
                sum = sum - int(ABCD[cnt+1])
                result +="-"+ ABCD[cnt+1]
            
        cnt+=1
        
    if sum==7:
        result += "=7"
        print(result)
        break

Submission status: Accepted

Solution code:
abcd=input()

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

Submission status: Accepted

Solution code:
ABCD = str(input())
n = len(ABCD)-1
ABCD_ = ''
output = ''
for i in range(2**n):
  ABCD_ = ABCD[0]
  for j in range(n):
    if ((i  >> j)&1) == 1:
      ABCD_ = ABCD_ + '+' + ABCD[j+1]
    else:
      ABCD_ = ABCD_ + '-' + ABCD[j+1]
  if eval(ABCD_) == 7:
    output = ABCD_ + '=7'
print(output)

Submission status: Accepted

Solution code:
S = input()

def ticket_sum(i, s, num):
    if i == len(S):
        if num == 7:
            print(s+"=7")
            exit()
        else:
            return False
    
    # 数字を分ける場所
    pos = i - len(S)

    # "+"を入れる場合
    s1 = s[:pos]+"+"+s[pos:]
    num1 = num+int(s[pos])
    # "-"を入れる場合
    s2 = s[:pos]+"-"+s[pos:]
    num2 = num-int(s[pos])
    
    if not(ticket_sum(i+1, s1, num1)):
        if not(ticket_sum(i+1, s2, num2)):
            return False

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

Submission status: Accepted

Solution code:
import sys

S = input()

def ticket_sum(i, s, num):
    if i == len(S):
        if num == 7:
            print(s+"=7")
            sys.exit()
        else:
            return False
    
    # 数字を分ける場所
    pos = i - len(S)

    # "+"を入れる場合
    s1 = s[:pos]+"+"+s[pos:]
    num1 = num+int(s[pos])
    # "-"を入れる場合
    s2 = s[:pos]+"-"+s[pos:]
    num2 = num-int(s[pos])
    
    if ticket_sum(i+1, s1, num1):
        return
    elif ticket_sum(i+1, s2, num2):
        return
    
    return False

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    A, B, C, D = [s for s in input().rstrip()]

    ops = ["+", "-"]
    for op1 in ops:
        for op2 in ops:
            for op3 in ops:
                eq = "".join([A, op1, B, op2, C, op3, D])
                res = eval(eq)
                if res == 7:
                    ans = eq + "=7"

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    A, B, C, D = [s for s in input().rstrip()]

    ops = ["+", "-"]
    for op1 in ops:
        for op2 in ops:
            for op3 in ops:
                eq = "".join([A, op1, B, op2, C, op3, D])
                res = eval(eq)
                if res == 7:
                    ans = eq + "=" + str(res)
                    break

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = input()

def ticket_sum(i, s, num):
    if i == len(S):
        if num == 7:
            print(s+"=7")
            exit()
        else:
            return False
    
    # 数字を分ける場所
    pos = i - len(S)

    # "+"を入れる場合
    s1 = s[:pos]+"+"+s[pos:]
    num1 = num+int(s[pos])
    # "-"を入れる場合
    s2 = s[:pos]+"-"+s[pos:]
    num2 = num-int(s[pos])
    
    if ticket_sum(i+1, s1, num1):
        return
    elif ticket_sum(i+1, s2, num2):
        return
    
    return False

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

Submission status: Accepted

Solution code:
s = input()


def recursion(n,sum,l):
    #print(n,sum,l)

    if n == len(s):
        if sum == 7:
            print(s[0]+l[1]+s[1]+l[2]+s[2]+l[3]+s[3]+"=7")
            exit()
        return sum

    '''プラスの場合'''
    l[n] = "+"
    recursion(n+1, sum + int(s[n]),l)

    '''マイナスの場合'''
    l[n] = "-"
    recursion(n+1, sum - int(s[n]),l)



l = [[] for i in range(len(s))]
recursion(0,0,l)

Submission status: Accepted

Solution code:

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

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

    formula=""
    for l_num,l_m in zip(S,l+[""]):
        formula += l_num + l_m #足していく

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

Submission status: Accepted

Solution code:
s = str(input())
nl = [s[0],s[1],s[2],s[3]]
nl = list(map(int,nl))

dic = {'+':1, '-':-1}
end = False
for op1 in ['+','-']:
    for op2 in ['+','-']:
        for op3 in ['+','-']:
            num = nl[0] + nl[1]*dic[op1] + nl[2]*dic[op2] + nl[3]*dic[op3]
            if num == 7 and not end:
                print('{}{}{}{}{}{}{}=7'.format(s[0],op1,s[1],op2,s[2],op3,s[3]))
                end = True