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:
listA = list(input())
listA = list(map(int,listA))
A,B,C,D = listA
s1,s2,s3 = 0,0,0
for i in range(2):
    for j in range(2):
        for k in range(2):
            total = 0
            if i == 0:
                s1 = "-"
                total = A - B
            else:
                s1 = "+"
                total = A + B
            if j == 0:
                s2 = "-"
                total = total - C
            else:
                s2 = "+"
                total = total + C
            if k == 0:
                s3 = "-"
                total = total - D
            else:
                s3 = "+"
                total = total + D
            if total == 7:
                print(str(A)+s1+str(B)+s2+str(C)+s3+str(D)+"=7")
                exit()

Submission status: Accepted

Solution code:
a, b, c, d = list(input())
for op1 in ['+', '-']:
    for op2 in ['+', '-']:
        for op3 in ['+', '-']:
            tmp = a + op1 + b + op2 + c + op3 + d
            if eval(tmp) == 7:
                print(tmp+'=7')
                exit()

Submission status: Accepted

Solution code:
A,B,C,D=map(int, list(input()))
L=["+","-"]

for i in L:
    for j in L:
        for k in L:
            now=A
            if i=="+":
                now+=B
            else:
                now-=B
            if j=="+":
                now+=C
            else:
                now-=C
            if k=="+":
                now+=D
            else:
                now-=D
            if now==7:
                print(str(A)+i+str(B)+j+str(C)+k+str(D)+"=7")
                exit()

Submission status: Accepted

Solution code:
def main():
    from itertools import product, zip_longest

    s = input()

    for prod in product('+-', repeat=3):
        formula = ''
        for x, op in zip_longest(s, prod, fillvalue=''):
            formula += x + op
        if eval(formula) == 7:
            print('{}=7'.format(formula))
            return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    from itertools import product, zip_longest

    s = input()

    for prod in product(['+', '-'], repeat=3):
        formula = ''
        for x, op in zip_longest(s, prod, fillvalue=''):
            formula += x + op
        if eval(formula) == 7:
            print('{}=7'.format(formula))
            return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    from itertools import product, zip_longest

    s = input()

    for prod in product(['+', '-'], repeat=3):
        formula = ''
        for x, op in zip_longest(s, prod, fillvalue=''):
            formula += x + op
        if eval(formula) == 7:
            print(formula + '=7')
            return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
ABCD = list(map(int, list(input())))
ans = ['']*9
for i in range(4):
    ans[i*2] = str(ABCD[i])
for i in range(2**3):
    ret = ABCD[0]
    for j in range(3):
        if (i >> j) % 2 == 1:
            ret += ABCD[j+1]
            ans[j*2 + 1] = '+'
        else:
            ret -= ABCD[j+1]
            ans[j*2 + 1] = '-'
    if ret == 7:
        ans[7] = '='
        ans[8] = '7'
        print(''.join(ans))
        exit(0)

Submission status: Accepted

Solution code:
def calc(a,b,f):
    a=int(a)
    b=int(b)
    if f==0:
        return a+b
    else:
        return a-b

s=input()
op=[0]*3
for i in range(2):
    a=calc(s[0],s[1],i)
    for j in range(2):
        b=calc(a,s[2],j)
        for k in range(2):
            c=calc(b,s[3],k)
            if c==7:
                ret=[i,j,k]               
for i in range(3):
    if ret[i]==0:
        ret[i]="+"
    else:
        ret[i]="-"
for i in range(3):
    print(s[i]+ret[i],sep="",end="")
print(s[3]+"=7")

Submission status: Accepted

Solution code:
ABCD=input()
answer=[ABCD[0],"-",ABCD[1],"-",ABCD[2],"-",ABCD[3]]
for i in range(8):
    pat=str(bin(i))[2:].rjust(3,"0")
    sum=int(ABCD[0])
    for j in range(3):
        if pat[j]=="0":
            sum-=int(ABCD[j+1])
            answer[2*j+1]="-"
        else:
            sum+=int(ABCD[j+1])
            answer[2*j+1]="+"
    if sum==7:
        print("".join(map(str,answer))+"=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(s[0]+"+"+s[1]+"+"+s[2]+"+"+s[3]+"=7")

elif a+b+c-d == 7:
    print(s[0]+"+"+s[1]+"+"+s[2]+"-"+s[3]+"=7")
elif a+b-c+d == 7:
    print(s[0]+"+"+s[1]+"-"+s[2]+"+"+s[3]+"=7")
elif a+b-c-d == 7:
    print(s[0]+"+"+s[1]+"-"+s[2]+"-"+s[3]+"=7")
elif a-b+c+d == 7:
    print(s[0]+"-"+s[1]+"+"+s[2]+"+"+s[3]+"=7")
elif a-b+c-d == 7:
    print(s[0]+"-"+s[1]+"+"+s[2]+"-"+s[3]+"=7")
elif a-b-c+d == 7:
    print(s[0]+"-"+s[1]+"-"+s[2]+"+"+s[3]+"=7")
elif a-b-c-d == 7:
    print(s[0]+"-"+s[1]+"-"+s[2]+"-"+s[3]+"=7")

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc079/tasks/abc079_c
q, w, e, r = map(int, list(input()))
# 全探索
op = [1, -1]
ansls = ['+', '-']
for a, b, c in product(range(2), repeat=3):
    if q + op[a] * w + op[b] * e + op[c] * r == 7:
        ans = str(q) + ansls[a] + str(w) + \
            ansls[b] + str(e) + ansls[c] + str(r) + '=7'
        print(ans)
        exit()

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:
ABCD = list(input())
for i in range(len(ABCD)):
  ABCD[i] = int(ABCD[i])

r1 = ABCD[0] + ABCD[1] + ABCD[2] + ABCD[3]
r2 = ABCD[0] + ABCD[1] + ABCD[2] - ABCD[3]
r3 = ABCD[0] + ABCD[1] - ABCD[2] + ABCD[3]
r4 = ABCD[0] - ABCD[1] + ABCD[2] + ABCD[3]
r5 = ABCD[0] + ABCD[1] - ABCD[2] - ABCD[3]
r6 = ABCD[0] - ABCD[1] + ABCD[2] - ABCD[3]
r7 = ABCD[0] - ABCD[1] - ABCD[2] + ABCD[3]
r8 = ABCD[0] - ABCD[1] - ABCD[2] - ABCD[3]

if r1 == 7:
  a = str(ABCD[0]) + '+' + str(ABCD[1]) + '+' + str(ABCD[2]) + '+' + str(ABCD[3]) + '=7'
  print(a)
elif r2 == 7:
  a = str(ABCD[0]) + '+' + str(ABCD[1]) + '+' + str(ABCD[2]) + '-' + str(ABCD[3]) + '=7'
  print(a)
elif r3 == 7:
  a = str(ABCD[0]) + '+' + str(ABCD[1]) + '-' + str(ABCD[2]) + '+' + str(ABCD[3]) + '=7'
  print(a)
elif r4 == 7:
  a = str(ABCD[0]) + '-' + str(ABCD[1]) + '+' + str(ABCD[2]) + '+' + str(ABCD[3]) + '=7'
  print(a)
elif r5 == 7:
  a = str(ABCD[0]) + '+' + str(ABCD[1]) + '-' + str(ABCD[2]) + '-' + str(ABCD[3]) + '=7'
  print(a)
elif r6 == 7:
  a = str(ABCD[0]) + '-' + str(ABCD[1]) + '+' + str(ABCD[2]) + '-' + str(ABCD[3]) + '=7'
  print(a)
elif r7 == 7:
  a = str(ABCD[0]) + '-' + str(ABCD[1]) + '-' + str(ABCD[2]) + '+' + str(ABCD[3]) + '=7'
  print(a)
elif r8 == 7:
  a = str(ABCD[0]) + '-' + str(ABCD[1]) + '-' + str(ABCD[2]) + '-' + str(ABCD[3]) + '=7'
  print(a)

Submission status: Accepted

Solution code:
def convert(s): 
  
    # initialization of string to "" 
    new = "" 
  
    # traverse in the string  
    for x in s: 
        new += x  
  
    # return string  
    return new 
s=input()
a=int(s[0])
b=int(s[1])
c=int(s[2])
d=int(s[3])
ans=[]
if a+b+c+d==7:
  ans.append(str(a))
  ans.append('+')
  ans.append(str(b))
  ans.append('+')
  ans.append(str(c))
  ans.append('+')
  ans.append(str(d))
  ans.append('=7')
  print(convert(ans))
elif a+b+c-d==7:
  ans.append(str(a))
  ans.append('+')
  ans.append(str(b))
  ans.append('+')
  ans.append(str(c))
  ans.append('-')
  ans.append(str(d))
  ans.append('=7')
  print(convert(ans))
elif a+b-c+d==7:
  ans.append(str(a))
  ans.append('+')
  ans.append(str(b))
  ans.append('-')
  ans.append(str(c))
  ans.append('+')
  ans.append(str(d))
  ans.append('=7')
  print(convert(ans))
elif a+b-c-d==7:
  ans.append(str(a))
  ans.append('+')
  ans.append(str(b))
  ans.append('-')
  ans.append(str(c))
  ans.append('-')
  ans.append(str(d))
  ans.append('=7')
  print(convert(ans))
elif a-b+c+d==7:
  ans.append(str(a))
  ans.append('-')
  ans.append(str(b))
  ans.append('+')
  ans.append(str(c))
  ans.append('+')
  ans.append(str(d))
  ans.append('=7')
  print(convert(ans))
elif a-b+c-d==7:
  ans.append(str(a))
  ans.append('-')
  ans.append(str(b))
  ans.append('+')
  ans.append(str(c))
  ans.append('-')
  ans.append(str(d))
  ans.append('=7')
  print(convert(ans))
elif a-b-c+d==7:
  ans.append(str(a))
  ans.append('-')
  ans.append(str(b))
  ans.append('-')
  ans.append(str(c))
  ans.append('+')
  ans.append(str(d))
  ans.append('=7')
  print(convert(ans))
elif a-b-c-d==7:
  ans.append(str(a))
  ans.append('-')
  ans.append(str(b))
  ans.append('-')
  ans.append(str(c))
  ans.append('-')
  ans.append(str(d))
  ans.append('=7')
  print(convert(ans))

Submission status: Accepted

Solution code:
def resolve():
  a, b, c, d = input()
  for i in range(8):
    q = str(a)
    if (i>>0) & 1:
      q += '+'
    else:
      q += '-'
    q += str(b)
    if (i>>1) & 1:
      q += '+'
    else:
      q += '-'
    q += str(c)
    if (i>>2) & 1:
      q += '+'
    else:
      q += '-'
    q += str(d)

    if eval(q) == 7:
      q += '=7'
      print(q)
      return

  return

if __name__ == "__main__":
  resolve()

Submission status: Accepted

Solution code:
from itertools import product
x = list(input())
for v in list(product(["+","-"], repeat=3)):
    ans = x[0]+v[0]+x[1]+v[1]+x[2]+v[2]+x[3]
    if eval(ans) == 7:break
print("".join(ans)+"=7")

Submission status: Accepted

Solution code:
def main():
    abcd = list(input())
    can_break = False
    for i in range(8):
        if can_break:
            break
        p = [""] * 3
        for j in range(3):
            if (i >> j) & 1:
                p[j] = "+"
            else:
                p[j] = "-"
        now = abcd[0] + p[0] + abcd[1] + p[1] + abcd[2] + p[2] + abcd[3]
        if eval(now) == 7:
            print(now + "=7")
            can_break = True
            break


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a, b, c, d = map(int, tuple(input()))
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:
a, b, c, d = list(input())
op = ['+', '-']
 
for i in op:
  for j in op:
    for k in op:
      formula = a+i+b+j+c+k+d
      if eval(formula) == 7:
        print(formula + '=7')
        exit()

Submission status: Accepted

Solution code:
from itertools import product
S = list(input())
T = list(map(int, S))

for p in product([-1, 1], repeat=3):
    tmp = T[0]
    for i, s in zip(p, T[1:]):
        tmp += i * s
    if tmp == 7:
        break

ans = S[0]
for i, s in zip(p, S[1:]):
    q = "+" if i == 1 else "-"
    ans += q
    ans += s
ans += "=7"
print(ans)

Submission status: Accepted

Solution code:
s = list(input())

for i in range(2 ** 3):
    cal = int(s[0])
    temp_s = s[0]
    for j in range(3):
        if (i >> j)&1:
            cal += int(s[j + 1])
            temp_s += '+' + s[j + 1]
        else:
            cal -= int(s[j + 1])
            temp_s += '-' + s[j + 1]

    if cal == 7:
        print(temp_s + '=7')
        exit()

Submission status: Accepted

Solution code:
def dfs(i,f):
    if i == 3:
        if eval(f) == 7:
            print(f + "=7")
            exit()
    else:
        dfs(i+1,f+"-"+s[i+1])
        dfs(i+1,f+"+"+s[i+1])
s = input()
dfs(0,s[0])

Submission status: Accepted

Solution code:
A = input()
a, b, c, d = A[0], A[1], A[2], A[3]
op = '+-'
for i in op:
    for j in op:
        for k in op:
            s = a + i + b + j + c + k + d
            if eval(s) == 7:
                print(s+'=7')
                exit()

Submission status: Accepted

Solution code:
from itertools import product
A,B,C,D = list(input().strip())
for x in product(("+","-"),repeat=3):
    a1,a2,a3 = x
    if eval(A+a1+B+a2+C+a3+D)==7:
        print(A+a1+B+a2+C+a3+D+"=7")
        break

Submission status: Accepted

Solution code:
s = input()
op = ['+', '-']
for i in range(2):
    for j in range(2):
        for k in range(2):
            t = ''.join([s[0], op[i], s[1], op[j], s[2], op[k], s[3]])
            if eval(t) == 7:
                print(t + '=7')
                quit()

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S=ST()
    for i in range(1<<3):
        now = int(S[0])
        ans = S[0]
        for j in range(3):
            if(i>>j&1):
                now -= int(S[j+1])
                ans+="-"
            else:
                now += int(S[j+1])
                ans+="+"
            ans += S[j+1] 
        if(now==7):
            print(ans+"=7")
            return
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    S = input()
    for bit in range(1 << 3):
        ans = int(S[0])
        T = S[0]
        for i in range(3):
            if bit & (1 << i):
                ans += int(S[i+1])
                T += "+"+S[i+1]
            else:
                ans -= int(S[i+1])
                T += "-"+S[i+1]
        if ans == 7:
            return print(T+"=7")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
inf = 10**15
mod = 10**9+7
s = input()
n = len(s)-1
for i in range(2**n):
    ans = int(s[0])
    acc = ans
    a = [s[0]]
    for j in range(n):
        if ((i >> j) & 1):  # 1だったら(オンだったら)
            acc = int(s[j + 1])
            ans+=acc
            a.append('+')
            a.append(s[j+1])
        else:
            acc = int(s[j + 1])
            ans-=acc
            a.append('-')
            a.append(s[j+1])
    if ans == 7:
        a.append('=7')
        print(''.join(a))
        sys.exit()

Submission status: Accepted

Solution code:
def resolve():
    def main():
        s=input()
        for i in ['+','-']:
            for m in ['+','-']:
                for n in ['+','-']:
                    a=s[0]+i+s[1]+m+s[2]+n+s[3]
                    if eval(a)==7:
                        return a
    print(main(), '=7',sep='')
resolve()

Submission status: Accepted

Solution code:
def resolve():
    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')
    else:
        print(str(a) + '-' + str(b) + '-' + str(c) + '-' + str(d) + '=7')

resolve()

Submission status: Accepted

Solution code:
import sys
def resolve():
    s=input()
    ans=0
    for i in ['+','-']:
        for m in ['+','-']:
            for n in ['+','-']:
                if eval(s[0]+i+s[1]+m+s[2]+n+s[3])==7:
                    ans=s[0]+i+s[1]+m+s[2]+n+s[3]+'=7'
                    print(ans)
                    sys.exit()
resolve()

Submission status: Accepted

Solution code:
def resolve():
    s=input()
    ans=0
    for i in ['+','-']:
        for m in ['+','-']:
            for n in ['+','-']:
                if eval(s[0]+i+s[1]+m+s[2]+n+s[3])==7:
                    ans=s[0]+i+s[1]+m+s[2]+n+s[3]+'=7'
    print(ans)
resolve()

Submission status: Accepted

Solution code:
# ABC079C

s = input()
ok = False
for i in ['-', '+']:
    for j in ['-', '+']:
        for k in ['-', '+']:
            expr = s[0]+i+s[1]+j+s[2]+k+s[3]
            if eval(expr) == 7:
                print(expr, '=7', sep="")
                ok = True
                break
        if ok: break
    if ok: break

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    S = input()
    hugo = ['+', '-']
    for a in hugo:
        for b in hugo:
            for c in hugo:
                N = eval(S[0]+a+S[1]+b+S[2]+c+S[3])
                if N == 7:
                    ans = S[0]+a+S[1]+b+S[2]+c+S[3]+'=7'
                    break
    print(ans)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = ["+","-"]
t = input()
for i in range(2**3):
    a = ""
    for j in range(3):
        a +=s[i>>j&1]

    ans = t[0]+a[0]+t[1]+a[1]+t[2]+a[2]+t[3]
    if eval(ans) == 7:
        print(ans + "=7")
        exit()

Submission status: Accepted

Solution code:
s = ["+","-"]
t = input()
a = ""
from itertools import product
for v in product(s,repeat = 3):
    a = t[0] + v[0] + t[1] + v[1] + t[2] + v[2] + t[3]
    if eval(a) == 7:
        break
print(a + "=7")

Submission status: Accepted

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


def to_char(op):
    if op == 1:
        return '+'
    else:
        return '-'


for op1 in [1, -1]:
    for op2 in [1, -1]:
        for op3 in [1, -1]:
            val = a + op1 * b + op2 * c + op3 * d
            if val == 7:
                print('{}{}{}{}{}{}{}=7'.format(
                    a, to_char(op1), b, to_char(op2), c, to_char(op3), d))
                exit(0)

Submission status: Accepted

Solution code:
a, *bcd = map(int, input())

for bits in range(1 << 3):
    value = a
    formula = [a]
    for op, num in enumerate(bcd):
        if bits & 1 << op:
            value += num
            formula.append('+')
        else:
            value -= num
            formula.append('-')
        formula.append(num)
    if value == 7:
        formula.append('=7')
        print(*map(str, formula), sep='')
        break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
abcd = input()
n = len(abcd)-1
for i in range(3**n):
    t = abcd[0]
    for j in range(n):
        if (i >> j & 1):
            t += '+'
        else:
            t += '-'
        t += abcd[j+1]
    if eval(t) == 7:
        t += '=7'
        print(t)
        sys.exit()

Submission status: Accepted

Solution code:
n = input()
op = len(n) - 1  # すきまの数
result = ""
for i in range(2**op):
    op_list = ['-']*op  # -で初期化しておく
    for j in range(op):
        if (i >> j) & 1:
            op_list[2-j] = '+'  # フラグが立ってるところだけ＋にする
    result = n[0] + op_list[0] + n[1] + op_list[1] + n[2] + op_list[2] + n[3]
    if eval(result) == 7:
        print(result + "=7")
        break

Submission status: Accepted

Solution code:
import itertools

X = str(input())
for op in list(itertools.product(['+', '-'], repeat=3)):
    eq = X[0] + op[0] + X[1] + op[1] + X[2] + op[2] + X[3]
    result = eval(eq)
    if result == 7:
        break

print(eq + '=7')

Submission status: Accepted

Solution code:
import numpy as np

S = input()
X = list(int(x) for x in S)


def test(Z):
    a = X[0]
    b = X[1] if Z[0] else -X[1]
    c = X[2] if Z[1] else -X[2]
    d = X[3] if Z[2] else -X[3]
    return a + b + c + d == 7


Y = [None] * (2 * len(X) - 1)
Y[::2] = X
for i in range(8):
    Z = [i & 1, i & 2, i & 4]
    if test(Z):
        Y[1::2] = ['+' if z else '-' for z in Z]
        break
print(*Y, sep='', end='=7\n')

Submission status: Accepted

Solution code:
s = input()
a, b, c, d = int(s[0]), int(s[1]), int(s[2]), int(s[3])
if a+b+c+d == 7:
  print(str(a)+'+'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
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()


def f(index, cur):
    if index == 4:
        if eval(cur) == 7:
            print(cur + '=7')
            return True
        return False

    for a in ['-', '+']:
        if f(index + 1, cur + a + S[index]):
            return True
    return False


f(1, S[0])

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

S = input()

def solve(S):
    for op1 in range(-1, 2, 2):
        for op2 in range(-1, 2, 2):
            for op3 in range(-1, 2, 2):
                if int(S[0]) + op1 * int(S[1]) + op2 * int(S[2]) + op3 * int(S[3]) == 7:
                    return S[0] + ("+" if op1 == 1 else "-") + S[1] + ("+" if op2 == 1 else "-") + S[2] + ("+" if op3 == 1 else "-") + S[3] + "=7"

print(solve(S))

Submission status: Accepted

Solution code:
def dfs(i,Str,res):
    if i==num-1:
        if res==7:
            print(Str+"=7")
            exit()
        return
    dfs(i+1,Str+"+"+S[i+1],res+int(S[i+1]))
    dfs(i+1,Str+"-"+S[i+1],res-int(S[i+1]))    

S=input()
num=len(S)
dfs(0,S[0],int(S[0]))

Submission status: Accepted

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

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

    formula=""
    for l_num, l_m in zip(n,l+[""]):
        formula += l_num + l_m
    
    if eval(formula)==7:
        print(formula+"=7")
        break

Submission status: Accepted

Solution code:
import itertools

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

ans=0
for i in itertools.product([0,1], repeat=3):
    asum=a[0]
    astr=str(a[0])
    for ii in range(len(i)):
        if i[ii]==0:
            asum+=a[ii+1]
            astr=astr +"+" + str(a[ii+1])
        else:
            asum-=a[ii+1]
            astr=astr +"-" + str(a[ii+1])
    if asum==7:
        break
        
print(astr+"=7")

Submission status: Accepted

Solution code:
A = input()
for i in range(8):
  B = format(i, '03b').replace('0','+').replace('1','-')
  ans = ''.join([a+b for b,a in zip(B,A)]) + A[-1]
  if eval(ans) == 7:
    print(ans+'=7')
    exit()

Submission status: Accepted

Solution code:
A = input()
for i in range(8):
  B = format(i, '03b').replace('0','-').replace('1','+')
  ans = ''.join([a+b for b,a in zip(B,A)]) + A[-1]
  if eval(ans) == 7:
    print(ans+'=7')
    exit()

Submission status: Accepted

Solution code:
*A, = map(int, list(input()))
op = {
  '1': lambda x,y: x+y,
  '0': lambda x,y: x-y
}

for i in range(8):
  B = format(i, '03b')
  result = A[0]
  for j,bi in enumerate(B,1):
    result = op[bi](result,A[j])
  if result == 7:
    ope = B.replace('0','-').replace('1','+')+'='
    print(''.join([str(a)+o for a,o in zip(A,ope)])+'7')
    exit()

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()
n = len(s)

def dfs(i, f):
  if i == n - 1:
#    print(f)
    total = sum(list(map(int, f.split('+'))))
    if total == 7:
      print((f + '=7').replace('+-', '-'))
      exit()
    return total
    # 式 f の末尾に "+" を追加するかしないかして次の数字を追加
  return dfs(i + 1, f + '+' + s[i + 1]) + dfs(i + 1, f + '+-' + s[i + 1])

dfs(0, s[0])

Submission status: Accepted

Solution code:
n = list(input())

op_count= len(n)-1
for i in range(2**op_count):
    op = ["-"]*op_count
    for j in range(op_count):
        if ((i>>j)&1):
            op[j]="+"
    formula = n[0]+op[0]+n[1]+op[1]+n[2]+op[2]+n[3]
    if eval(formula)==7:
        print(formula+"=7")
        break

Submission status: Accepted

Solution code:
abcd = [int(i) for i in input()]
for i in range(2):
    for j in range(2):
        for k in range(2):
            ans = abcd[0]
            res = "" + str(abcd[0])
            if i:
                ans += abcd[1]
                res += "+" + str(abcd[1])
            else:
                ans -= abcd[1]
                res += "-" + str(abcd[1])
            if j:
                ans +=  abcd[2]
                res += "+" + str(abcd[2])
            else:
                ans -=  abcd[2]
                res += "-" + str(abcd[2])
            if k:
                ans +=  abcd[3]
                res += "+" + str(abcd[3])
            else:
                ans -=  abcd[3]
                res += "-" + str(abcd[3])
            if ans == 7:
                print(res+"=7" )
                exit()

Submission status: Accepted

Solution code:
n = input()

def dfs(i, f, s):
    if i == 3:
        return f+"=7" if s == 7 else ''
    return dfs(i+1, f+"+"+n[i+1], s+int(n[i+1])) or dfs(i+1, f+"-"+n[i+1], s-int(n[i+1]))

print(dfs(0, n[0], int(n[0])))

Submission status: Accepted

Solution code:
n = input()

def dfs(i, f, s):
    if i == 3:
        if s==7:
            return f+"=7"
        else:
            return ''
    return dfs(i+1, f+"+"+n[i+1], s+int(n[i+1])) or dfs(i+1, f+"-"+n[i+1], s-int(n[i+1]))

print(dfs(0, n[0], int(n[0])))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 25 19:47:38 2020

@author: Kanaru Sato
"""

_ = str(input())
nums = []
for i in range(len(_)):
    nums.append(int(_[i]))

for ops in range(1<<3):
    count = nums[0]
    formula = [str(nums[0])]
    
    for shift in range(3):
        shift = 2-shift
        if ops & (1<<shift):
            count += nums[3-shift]
            formula += ["+",str(nums[3-shift])]
        else:
            count -= nums[3-shift]
            formula += ["-",str(nums[3-shift])]

    if count == 7:
        formula.append("=")
        print("".join(formula)+"7")
        break

Submission status: Accepted

Solution code:
def dfs(i,s,res):
    if i==3:
        if res == 7:
            print(s+"=7")
            exit()
        return
    dfs(i+1,s+'+'+S[i+1],res+int(S[i+1]))
    dfs(i+1,s+'-'+S[i+1],res-int(S[i+1]))
 
S=input()
dfs(0,S[0],int(S[0]))