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:
nums=input()
nums=list(map(int, list(nums)))

if nums[0]+nums[1]+nums[2]+nums[3]==7:
    print('{}+{}+{}+{}=7'.format(nums[0], nums[1], nums[2], nums[3]))

elif nums[0]+nums[1]+nums[2]-nums[3]==7:
    print('{}+{}+{}-{}=7'.format(nums[0], nums[1], nums[2], nums[3]))

elif nums[0]+nums[1]-nums[2]+nums[3]==7:
    print('{}+{}-{}+{}=7'.format(nums[0], nums[1], nums[2], nums[3]))

elif nums[0]+nums[1]-nums[2]-nums[3]==7:
    print('{}+{}-{}-{}=7'.format(nums[0], nums[1], nums[2], nums[3]))

elif nums[0]-nums[1]+nums[2]+nums[3]==7:
    print('{}-{}+{}+{}=7'.format(nums[0], nums[1], nums[2], nums[3]))

elif nums[0]-nums[1]+nums[2]-nums[3]==7:
    print('{}-{}+{}-{}=7'.format(nums[0], nums[1], nums[2], nums[3]))

elif nums[0]-nums[1]-nums[2]+nums[3]==7:
    print('{}-{}-{}+{}=7'.format(nums[0], nums[1], nums[2], nums[3]))

elif nums[0]-nums[1]-nums[2]-nums[3]==7:
    print('{}-{}-{}-{}=7'.format(nums[0], nums[1], nums[2], nums[3]))

Submission status: Accepted

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

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

  num=l[0]
  for j in range(3):
    if op[j]=='+':
      num+=l[j+1]
    else:
      num-=l[j+1]

  if num==7:
    print(str(l[0])+op[0]+str(l[1])+op[1]+str(l[2])+op[2]+str(l[3])+'=7')
    exit()

Submission status: Accepted

Solution code:
s = input()

for bit in range(1 << (3)):
    f = s[0]
    
    for i in range(3):
        # if bit & (1 << i)で、bitにiが含まれているか（フラグが立っているか）を判定してくれるらしい
        if bit & (1 << i):
            f += '+'
        else:
            f += '-'
        f += s[i+1]    
    if eval(f)  == 7:
        f += "=7"
        print(f)
        exit()

Submission status: Accepted

Solution code:
from sys import stdin
l = list(stdin.readline().rstrip())
s = [int(i) for i in l]
def dfs(i, f, sum):
    if i == 3:
        if sum == 7:
            print(f + '=7')
            exit()
    else:
        dfs(i+1, f + '+' + str(s[i+1]), sum + s[i+1])
        dfs(i+1, f + '-' + str(s[i+1]), sum - s[i+1])
dfs(0, str(s[0]), s[0])

Submission status: Accepted

Solution code:
a,b,c,d=map(int,list(input()))
n=3
ans=''
for i in range(n**2):
  op=[]
  for j in range(n):
    if (i>>j & 1):
      op.append(True)
    else:
      op.append(False)
  tmp=a
  tmp=tmp+b if op[0] else tmp-b
  tmp=tmp+c if op[1] else tmp-c
  tmp=tmp+d if op[2] else tmp-d
  if tmp==7:
    ans=str(a)
    ans+='+' if op[0] else '-'
    ans+=str(b)
    ans+='+' if op[1] else '-'
    ans+=str(c)
    ans+='+' if op[2] else '-'
    ans+=str(d)
    break
print(ans+'=7')

Submission status: Accepted

Solution code:
s=input()
li=[]
for i in s:
  li.append(int(i))

for i in range(2**3):
  op=[]
  ans=li[0]
  for j in range(3):
    if((i>>j)&1):
      op.append("+")
      ans+=li[j+1]
    else:
      op.append("-")
      ans-=li[j+1]
  if ans==7:
    op.append("=7")
    break
for (x,y) in zip(li,op):
  print(str(x)+y,end="")

Submission status: Accepted

Solution code:
l=list(input())
n=2**3
for i in range(n):
    sum=int(l[0])
    buf=l[0]
    for j in range(3):
        if i>>j & 1:
            buf+='+'+l[j+1]
            sum+=int(l[j+1])
        else:
            buf+='-'+l[j+1]
            sum-=int(l[j+1])
    if sum==7:
        print(buf+'=7')
        exit()

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:
import itertools
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def op(n):
    return '+' if n == 0 else '-'

a, b, c, d = list(readline().decode().rstrip())

for l in list(itertools.product([0, 1], repeat=3)):
    s = str(a + op(l[0]) + b + op(l[1]) + c + op(l[2]) + d)
    if eval(s) == 7:
        print(s+'=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("{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:
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("{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:
# coding: utf-8
# Your code here!

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

def proc(nums):
    op_h = []
    n = nums.pop(0)
    fl,op_h = find_operator(nums.copy(), 7-n, op_h)
    print(n,end="")
    for i,num in enumerate(nums):
        if op_h[i] == 1:
            print("+",end="")
        else:
            print("-",end="")
        print(num,end="")
    print("=7")

def find_operator(nums, to_be, operation_history):
    ope = [-1,1]

    n = nums.pop(0)
    if len(nums) == 0:
        for op in ope:
            if to_be - op*n == 0:
                operation_history.append(op)
                return True, operation_history
        return False, operation_history    
    
    for op in ope:
        op_h = operation_history.copy()
        op_h.append(op)
        fl, h = find_operator(nums.copy(), to_be-op*n, op_h)
        if fl == True:
            return True,h
    return False,h
        
proc(nums)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(input())
for a in range(8):
  p = [""]*4
  ans = ""
  for b in range(3):
    if(a>>b & 1):
      p[b] = "+"
    else:
      p[b] = "-"
      
  for c in range(4):
    ans += str(S[c]) + str(p[c])
    
  if eval(ans) == 7:
    print(ans + "=7")
    break

Submission status: Accepted

Solution code:
def resolve():
    s = input()

    def dfs(i, f):
        if i == 3:
            return f.split(",")
        return dfs(i+1, f + "+" + s[i+1]) + dfs(i+1, f + "-" + s[i+1])
    for i in dfs(0, s[0]):
        if eval(i) == 7:
            print(i + "=7")
            exit()
resolve()

Submission status: Accepted

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

    for i in range(8):
        op1 = "+" if i>>0 & 1 else "-"
        op2 = "+" if i>>1 & 1 else "-"
        op3 = "+" if i>>2 & 1 else "-"
        test = a + op1 + b + op2 + c + op3 + d
        if eval(test) == 7:
            print(test + "=7")
            exit()
resolve()

Submission status: Accepted

Solution code:
def solve(A,n):
    x=2**n
    for i in range(x):
        count=A[0]
        for j in range(n):
            if (i>>j) & 1:
                count+=A[j+1]
            else:
                count-=A[j+1]
        if count==7:
            return i

n=3
A=list(map(int,input()))
i=solve(A,n)
ans=str(A[0])
for j in range(n):
    if (i>>j) & 1:
        ans+="+"+str(A[j+1])
    else:
        ans+="-"+str(A[j+1])
ans+="=7"
print(ans)

Submission status: Accepted

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

l = [0] * 8
l[0] = a + b + c + d
l[1] = a + b + c - d
l[2] = a + b - c + d
l[3] = a + b - c - d
l[4] = a - b + c + d
l[5] = a - b + c - d
l[6] = a - b - c + d
l[7] = a - b - c - d

if l[0] == 7:
  print('{}+{}+{}+{}=7'.format(a, b, c, d))
elif l[1] == 7:
  print('{}+{}+{}-{}=7'.format(a, b, c, d))
elif l[2] == 7:
  print('{}+{}-{}+{}=7'.format(a, b, c, d))
elif l[3] == 7:
  print('{}+{}-{}-{}=7'.format(a, b, c, d))
elif l[4] == 7:
  print('{}-{}+{}+{}=7'.format(a, b, c, d))
elif l[5] == 7:
  print('{}-{}+{}-{}=7'.format(a, b, c, d))
elif l[6] == 7:
  print('{}-{}-{}+{}=7'.format(a, b, c, d))
elif l[7] == 7:
  print('{}-{}-{}-{}=7'.format(a, b, c, d))

Submission status: Accepted

Solution code:
a = list(map(int,input()))
h = []

for i in range(1,2**3):
    total = a[0]
    h.clear()
    for j in range(3):
        if ((i >> j) & 1):
            total += a[j+1]
            h.append('+')
        else:
            total -= a[j+1]
            h.append('-')
    if total == 7:
        break
for i in range(3):
    print(str(a[i])+h[i],end="")
print(str(a[3])+"=7")

Submission status: Accepted

Solution code:
s = str(input())
if (int(s[0])+int(s[1])+int(s[2])+int(s[3]) == 7):
    print(s[0],"+",s[1],"+",s[2],"+",s[3],"=7",sep = "")
elif (int(s[0])+int(s[1])+int(s[2])-int(s[3]) == 7):
    print(s[0],"+",s[1],"+",s[2],"-",s[3],"=7",sep = "")
elif (int(s[0])+int(s[1])-int(s[2])+int(s[3]) == 7):
    print(s[0],"+",s[1],"-",s[2],"+",s[3],"=7",sep = "")
elif (int(s[0])+int(s[1])-int(s[2])-int(s[3]) == 7):
    print(s[0],"+",s[1],"-",s[2],"-",s[3],"=7",sep = "")
elif (int(s[0])-int(s[1])+int(s[2])+int(s[3]) == 7):
    print(s[0],"-",s[1],"+",s[2],"+",s[3],"=7",sep = "")
elif (int(s[0])-int(s[1])+int(s[2])-int(s[3]) == 7):
    print(s[0],"-",s[1],"+",s[2],"-",s[3],"=7",sep = "")
elif (int(s[0])-int(s[1])-int(s[2])+int(s[3]) == 7):
    print(s[0],"-",s[1],"-",s[2],"+",s[3],"=7",sep = "")
else:
    print(s[0],"-",s[1],"-",s[2],"-",s[3],"=7",sep = "")

Submission status: Accepted

Solution code:
a = list(map(int, input()))
b = [a[1], -a[1]]
c = [a[2], -a[2]]
d = [a[3], -a[3]]
flag = 0 
for i in b:
    if(i>=0):
        b_ = '+'
    else: b_ = '-'
    for j in c:
        if(j>=0):
            c_ = '+'
        else: c_ = '-'
        for k in d:
            if(k>=0):
                d_ = '+'
            else: d_ = '-'            
            ans = a[0] + i + j + k
            if ans==7:
                print('{}{}{}{}{}{}{}=7'.format(a[0], b_, a[1], c_, a[2], d_, a[3]))
                flag = 1
                break
        if(flag==1): break
    if(flag==1): break

Submission status: Accepted

Solution code:
import sys
a,b,c,d=input()
op=["-","+"]

for i in op:
  for j in op:
    for k in op:
      o=a+i+b+j+c+k+d
      ans=eval(o)
      if ans==7:
        print(o+"=7")
        sys.exit()

Submission status: Accepted

Solution code:
a = str(input())
apple = []
orange = []
for i in a:
    apple.append(int(i))
x = apple[0]
y = apple[1]
z = apple[2]
w = apple[3]
if apple[0] + apple[1] + apple[2] + apple[3] == 7:
    print("{o}+{p}+{q}+{r}=7".format(o=x, p=y, q=z, r=w))
elif apple[0] - apple[1] + apple[2] + apple[3] == 7:
    print("{o}-{p}+{q}+{r}=7".format(o=x, p=y, q=z, r=w))
elif apple[0] - apple[1] - apple[2] + apple[3] == 7:
    print("{o}-{p}-{q}+{r}=7".format(o=x, p=y, q=z, r=w))
elif apple[0] - apple[1] - apple[2] - apple[3] == 7:
    print("{o}-{p}-{q}-{r}=7".format(o=x, p=y, q=z, r=w))
elif apple[0] + apple[1] - apple[2] + apple[3] == 7:
    print("{o}+{p}-{q}+{r}=7".format(o=x, p=y, q=z, r=w))
elif apple[0] + apple[1] - apple[2] - apple[3] == 7:
    print("{o}+{p}-{q}-{r}=7".format(o=x, p=y, q=z, r=w))
elif apple[0] + apple[1] + apple[2] - apple[3] == 7:
    print("{o}+{p}+{q}-{r}=7".format(o=x, p=y, q=z, r=w))
elif apple[0] - apple[1] + apple[2] - apple[3] == 7:
    print("{o}-{p}+{q}-{r}=7".format(o=x, p=y, q=z, r=w))
else:
    pass

Submission status: Accepted

Solution code:
x = input()
a = int(x[0])
b = int(x[1])
c = int(x[2])
d = int(x[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=input()
for i in range(1 << 3):
    l=[]
    for j in range(3):
        l.append(abcd[j])
        if (i>>j)&1==1:
            l.append('+')
        else:
            l.append('-')
    l.append(abcd[3])
    if eval("".join(l))==7:
        ans="".join(l)
        break
print(ans+"=7")

Submission status: Accepted

Solution code:


s=list(input())
a=s[0]
b=s[1]
c=s[2]
e=s[3]

for i in range(8):
    d=0
    x=[a,b,c,e]
    for j in range(3):
        if (i >> j)&1:
            x.insert(-j-1-d,'+')
            d+=1
        else:
            x.insert(-1-j-d,'-')
            d+=1
    q="".join(x)
    f=int(a)
    g=int(b)
    h=int(c)
    k=int(e)
    if q[1]=="-":
        g=-g
    if q[3]=="-":
        h=-h
    if q[5]=="-":
        k=-k
    if f+g+h+k==7:
        ans=q+"=7"
        print(ans)
        exit()

Submission status: Accepted

Solution code:
import sys

s=list(input())
a=s[0]
b=s[1]
c=s[2]
e=s[3]

for i in range(8):
    d=0
    x=[a,b,c,e]
    for j in range(3):
        if (i >> j)&1:
            x.insert(-j-1-d,'+')
            d+=1
        else:
            x.insert(-1-j-d,'-')
            d+=1
    q="".join(x)
    f=int(a)
    g=int(b)
    h=int(c)
    k=int(e)
    if q[1]=="-":
        g=-g
    if q[3]=="-":
        h=-h
    if q[5]=="-":
        k=-k
    if f+g+h+k==7:
        ans=q+"=7"
        print(ans)
        sys.exit()

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque
from itertools import product

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    S = input()
    for op1, op2, op3 in product("+-", repeat=3):
        q = S[0]+op1+S[1]+op2+S[2]+op3+S[3]
        if eval(q) == 7:
            print(q + "=7")
            exit()


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = list(input())

for bit in range(3 ** 2):
    array = ['-','-','-']
    for i in range(3):
        if bit >> i & 1:
            array[i] = '+'
    tmp = int(n[0])
    ans = n[0]
    for i in range(len(array)):
        if array[i] == '+':
            tmp += int(n[i+1])
            ans+='+'+n[i+1]
        else:
            tmp -= int(n[i+1])
            ans+='-'+n[i+1]
    if tmp == 7:
        print(ans+'=7')
        exit(0)

Submission status: Accepted

Solution code:
## C - Train Ticket
A,B,C,D = input()
for i in range(2):
    op1 = 1 if i == 0 else -1
    for j in range(2):
        op2 = 1 if j == 0 else -1
        for k in range(2):
            op3 = 1 if k == 0 else -1
            if(int(A) + int(B) * op1 + int(C) * op2 + int(D) * op3 == 7):
                op1t = '+' if op1 == 1 else '-'
                op2t = '+' if op2 == 1 else '-'
                op3t = '+' if op3 == 1 else '-'
                print(str(A) + op1t + str(B) + op2t + str(C) + op3t + str(D) + '=7')
                break
        else:
            continue
        break
    else:
        continue
    break

Submission status: Accepted

Solution code:
#関数リスト
import sys
import itertools
input = sys.stdin.readline
mylist = ["+", "-"]

num = input().rstrip()
num = [int(num[i]) for i in range(len(num))]
first = num[0]
num = num[1:]

for i in itertools.product(mylist, repeat = len(num)):
    temp = first
    for j, k in zip(i, num):
        if j == "+":
            temp += k
        else:
            temp -= k
    if temp == 7:
        print(first, end = '')
        for j, k in zip(i, num):
            print(j+str(k), end = '')
        print("=7")
        break

Submission status: Accepted

Solution code:
s=input()

for i in range(8):
    ans=int(s[0])
    op=[0]*3
    for j in range(3):
        if (i>>j)&1:
            ans+=int(s[j+1])
            op[j]='+'
        else:
            ans-=int(s[j+1])
            op[j]='-'
    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:
num=input()
a=int(num[0])
b=int(num[1])
c=int(num[2])
d=int(num[3])
yn=0
for i in range(2):
    for j in range(2):
        for k in range(2):
            num2=a
            if i==0:
                num2+=b
            else:
                num2-=b
            if j==0:
                num2+=c
            else:
                num2-=c
            if k==0:
                num2+=d
            else:
                num2-=d
            if num2==7:
                yn=1
                break
        if yn==1:
            break
    if yn==1:
        break
ans=""
ans+=str(a)
if i==0:
    ans+="+"
else:
    ans+="-"
ans+=str(b)
if j==0:
    ans+="+"
else:
    ans+="-"
ans+=str(c)
if k==0:
    ans+="+"
else:
    ans+="-"
ans+=str(d)
ans+="=7"
print(ans)

Submission status: Accepted

Solution code:
def main():
    s = input()
    n = len(s) - 1
    f = s[0]
    for i in range(2**n):
        for j in range(n):
            if (i >> j) & 1:
                f += '+'
            else:
                f += '-'
            f += s[j+1]
        # print(f)
        if eval(f) == 7:
            print(f + '=7')
            break
        f = s[0]

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x = input()
l = []
for i in range(4):
  l.append(int(x[i]))
  
ans_l = []  
for i in range(8):
  x = l[0]+l[1]*(-1)**(i//4)+l[2]*(-1)**((i//2)%2)+l[3]*(-1)**(i%2)
  if x==7:
    ans_l.append(i)
    
if min(ans_l)//4==0:
  op1 = '+'
else:
  op1 = '-'
if (min(ans_l)//2)%2==0:
  op2 = '+'
else:
  op2 = '-'
if min(ans_l)%2==0:
  op3 = '+'
else:
  op3 = '-'
  
print(str(l[0])+op1+str(l[1])+op2+str(l[2])+op3+str(l[3])+'=7')

Submission status: Accepted

Solution code:

ticket = input()

ans = 0
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:
import sys
ABCD = input()

for bit in range(2 ** 3):
    N = ABCD[0]
    for i in range(3):
        if bit & (1 << i):
            N += '+'
        else:
            N += '-'
        N += ABCD[i + 1]
    if eval(N) == 7:
        print(N + '=7')
        sys.exit()

Submission status: Accepted

Solution code:
import sys
ls = list(str(input()))
a =ls[0]
b =ls[1]
c =ls[2]
d =ls[3]
for i in range(2):
    for j in range(2):
        for k in range(2):
            if i == 1:
                s1 = "-"
            if j == 1:
                s2 = "-"
            if k == 1:
                s3 = "-"
            if i == 0:
                s1 = "+"
            if j == 0:
                s2 = "+"
            if k == 0:
                s3 = "+"
            e = eval(a+s1+b+s2+c+s3+d)
            if e == 7:
                print(a+s1+b+s2+c+s3+d + "=7")
                sys.exit()

Submission status: Accepted

Solution code:
import sys
a,b,c,d=input()
k=["+","-"]
lst=[]
for i in k:
    for j in k:
        for l in k:
            o=a+i+b+j+c+l+d
            if eval(o)==7:
                print(o+"=7")
                sys.exit()

Submission status: Accepted

Solution code:

A,B,C,D = input()
A = int(A)
B = int(B)
C = int(C)
D = int(D)
sum = 0
ope = ["", "",""]
for i in range(2):

    for j in range(2):

        for k in range(2):
            if (i == 0):
                sum += A + B
                ope[0] = "+"
            if (i == 1):
                sum += A - B
                ope[0] = "-"
            if (j == 0):
                sum += C
                ope[1] = "+"
            if (j == 1):
                sum -= C
                ope[1] = "-"
            if (k == 0):
                sum += D
                ope[2] = "+"
                if (sum == 7):
                    break
                else:
                    sum = 0
            if(k==1):
                sum -= D
                ope[2] = "-"
                if (sum == 7):
                    break
                else:
                    sum = 0
        if (sum == 7):
            break

    if (sum == 7):
        break
print("{}{}{}{}{}{}{}=7".format(A,ope[0],B,ope[1],C,ope[2],D))

Submission status: Accepted

Solution code:
from itertools import *

ABCD = input()

n = len(ABCD) - 1 # opの入力数

plumi_list = list(product(["+", "-"], repeat=n))

for bit in range(1 << n):
    formula = ABCD[0]
    for num, op in zip(ABCD[1:], plumi_list[bit]):
        formula += op + num
        ans = eval(formula)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n= list(map(int, input()))
if sum(n) == 7:
    print(str(n[0]) + '+' +  str(n[1]) + '+' + str(n[2]) + '+' + str(n[3]) + '=' + str(7))
    exit()
if n[0] + n[1] + n[2] - n[3] == 7:
    print(str(n[0]) + '+' +  str(n[1]) + '+' + str(n[2]) + '-' + str(n[3]) + '=' + str(7))
    exit()
if n[0] + n[1] - n[2] - n[3] == 7:
    print(str(n[0]) + '+' +  str(n[1]) + '-' + str(n[2]) + '-' + str(n[3]) + '=' + str(7))
    exit()
if n[0] - n[1] - n[2] - n[3] == 7:
    print(str(n[0]) + '-' +  str(n[1]) + '-' + str(n[2]) + '-' + str(n[3]) + '=' + str(7))
    exit()
if n[0] - n[1] - n[2] + n[3] == 7:
    print(str(n[0]) + '-' +  str(n[1]) + '-' + str(n[2]) + '+' + str(n[3]) + '=' + str(7))
    exit()
if n[0] - n[1] + n[2] + n[3] == 7:
    print(str(n[0]) + '-' +  str(n[1]) + '+' + str(n[2]) + '+' + str(n[3]) + '=' + str(7))
    exit()
if n[0] - n[1] + n[2] - n[3] == 7:
    print(str(n[0]) + '-' +  str(n[1]) + '+' + str(n[2]) + '-' + str(n[3]) + '=' + str(7))
    exit()
if n[0] + n[1] - n[2] + n[3] == 7:
    print(str(n[0]) + '+' +  str(n[1]) + '-' + str(n[2]) + '+' + str(n[3]) + '=' + str(7))
    exit()

Submission status: Accepted

Solution code:
import itertools
a, b, c, d = input()
ops = ("+", "-")
for op1, op2, op3 in itertools.product(ops, repeat=3):
    eq = a + op1 + b + op2 + c + op3 + d
    if eval(eq) == 7:
        print(eq + "=7")
        break

Submission status: Accepted

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

nl = [a,b,c,d]

import itertools
op =["+","-"]
opl = list(itertools.product(op, repeat=3))

for i in range(8): #加減パターン
    res = nl[0]
    opp = opl[i]
    for j in range(3):
        if opp[j]=="+":
            res += nl[j+1]
        else:
            res -= nl[j+1]
    if res ==7:
        print(str(nl[0])+opp[0]+str(nl[1])+opp[1]+str(nl[2])+opp[2]+str(nl[3])+"=7")
        exit()

Submission status: Accepted

Solution code:
import itertools

def f(bin, x):
    if bin == 0:
        return x
    else:
        return -x

def g(x):
    r = str(n[-1])
    for i in range(ketasu - 1):
        if x[i] == 0:
            r += "+"
        else:
            r += "-"
        r += str(n[-i - 2])
    r+="=7"
    return r

abcd = input()
ketasu = len(abcd)
abcd = int(abcd)
n = [None] * ketasu
for i in range(ketasu):
    n[i] = abcd % 10
    abcd //= 10

for i in itertools.product([0, 1], repeat=ketasu - 1):
    ans = n[-1]
    for j in range(ketasu-1):
        ans += f(i[j], n[-j-2])
    if ans == 7:
        ans = g(i)
        break
print(ans)

Submission status: Accepted

Solution code:
# For taking integer inputs.
import math
from decimal import Decimal
from itertools import permutations


def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


a = instr()
res = ""
for i in range(8):
    s = '{0:03b}'.format(i)
    temp = a[0]
    total = int(a[0])
    j = 0
    for i in range(1, 4):

        if s[j] == '0':
            total += int(a[i])
            temp += "+" + a[i]
        else:
            total -= int(a[i])
            temp += "-" + a[i]

        j += 1

    if total == 7:
        res = temp
        break
print(res+"=7")

Submission status: Accepted

Solution code:
ABCD = input()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy
import numpy as np

s = input()
n = 3
ans = 0

for i in range(1,3 ** n):
    x = copy.deepcopy(s)
    y = str(np.base_repr(i,3)).rjust(3,'0') #3進数に変換
    if (y[0] == "0" and s[0] == "0") or (y[1] == "0" and s[1] == "0") or (y[2] == "0" and s[2] == "0"):
        continue
    z = 1
    for j in range(3):
        if y[j] == "1": #フラグが立っていたら
            x = x[:j+z] + "+" + x[j+z:]
            z += 1
        if y[j] == "2": #フラグが立っていたら
            x = x[:j+z] + "-" + x[j+z:]
            z += 1
    if eval(x) == 7:
        print(x +"=7")
        exit()

Submission status: Accepted

Solution code:
A=input()
OP=["+++","-++","+-+","++-","--+","-+-","+--","---"]
for op in OP:
    if eval(A[0]+op[0]+A[1]+op[1]+A[2]+op[2]+A[3])==7:
        print(A[0]+op[0]+A[1]+op[1]+A[2]+op[2]+A[3]+"=7")
        break

Submission status: Accepted

Solution code:
def main():
    (A,B,C,D) = map(int, input())
    operation = ['+','-']
    sumA = A
    for op1 in operation:
        sum = sumA
        if op1=='+':
            sum+=B
        else:
            sum-=B
        sumAB = sum
        for op2 in operation:
            sum = sumAB
            if op2=='+':
                sum+=C
            else:
                sum-=C
            if 7-sum==D:
                op3 = '+'
                print(str(A)+op1+str(B)+op2+str(C)+op3+str(D)+'=7')
                return
            elif sum-7==D:
                op3 = '-'
                print(str(A)+op1+str(B)+op2+str(C)+op3+str(D)+'=7')
                return

main()

Submission status: Accepted

Solution code:
n = input()
gap =len(n) -1
for i in range(2 ** gap):
  f = ""
  for j in range(gap):
    f += str(n[j])
    if ((i>>j)&1):
      f += "+"
    else:
      f += "-"
  f += n[-1]
  if eval(f) == 7 :
    print(f +"=7")
    break

Submission status: Accepted

Solution code:
n = list(str(x) for x in input())
l = len(n)
op_cnt = l - 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 j in range(op_cnt):
    formula += n[j] + op[j]
  formula += n[op_cnt]
  if eval(formula) == 7:
    print(formula + '=7')
    break

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split(''))
nl = lambda: list(map(int, readline().split()))
prl = lambda x: print(*x ,sep='\n')

a = ns()
for i in range(2**3):
    ans = '{}'.format(a[-1])
    for j in range(3):
        if (i >> j) & 1:
            ans = a[-1-(j+1)] + '+' + ans
        else:
            ans = a[-1-(j+1)] + '-' + ans
    if eval(ans) == 7:
        print(ans+'=7')
        break

Submission status: Accepted

Solution code:
In = [int(i) for i in input()]
flag = 0
for op1 in ["+","-"]:
    for op2 in ["+","-"]:
        for op3 in ["+","-"]:
            if eval("{}".format(In[0])+op1+"{}".format(In[1])+op2+"{}".format(In[2])+op3+"{}".format(In[3]))==7:
                print("{}".format(In[0])+op1+"{}".format(In[1])+op2+"{}".format(In[2])+op3+"{}=7".format(In[3]))
                exit()

Submission status: Accepted

Solution code:
In = [int(i) for i in input()]
flag = 0
for op1 in ["+","-"]:
    for op2 in ["+","-"]:
        for op3 in ["+","-"]:
            if eval("{}".format(In[0])+op1+"{}".format(In[1])+op2+"{}".format(In[2])+op3+"{}".format(In[3]))==7:
                print("{}".format(In[0])+op1+"{}".format(In[1])+op2+"{}".format(In[2])+op3+"{}=7".format(In[3]))
                flag = 1
                break
        if flag:
            break
    if flag:
        break