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: Runtime Error

Solution code:
S=input()
N=len(S)
A=[int(i) for i in S]
B=["+" for i in range(N-1)]
output=S[0]
for i in range(2**N):
  for j in range(1,N):
    if (i>>j)&1:
      A[j]= -1*int(str(S[j]))
      B[j]=  "-"
  #print(A,B,sum(A))
  if sum(A) ==7:
    for i in range(1,N):
      output += B[i-1] + str(S[i])
    print(output+"=7")
    break

Submission status: Runtime Error

Solution code:
from typing import Optional
import sys


def dfs(i: int, s: str, val: int, formula: str) -> Optional[str]:
    if (i == len(s) - 1):
        if val == 7:
            print(formula + "=7")
            sys.exit()
            return formula
        else:
            return None

    dfs(i + 1, s, val + int(s[i + 1]), formula + "+" + s[i + 1])
    dfs(i + 1, s, val - int(s[i + 1]), formula + "-" + s[i + 1])
    return None


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

Submission status: Runtime Error

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

for a in L:
  for b in L:
    for c in L:
      #now=A
      if a=="+":
        now+=B
      else:
        now-=B
      if b=="+":
        now+=C
      else:
        now-=C
      if c=="+":
        now+=D
      else:
        now-=D
      print(now)
      if now==7:
        print(str(A)+a+str(B)+b+str(C)+c+str(D)+"=7")
        exit()

Submission status: Runtime Error

Solution code:
def main():
    A, B, C, D = input()
    for i in range(2):
        ans = int(A)
        if i == 0:
            ans += int(B)
        else:
            ans -= int(B)
        for j in range(2):
            if j == 0:
                ans += int(C)
            else:
                ans -= int(C)
            for k in range(2):
                if k == 0:
                    ans += int(D)
                else:
                    ans -= int(D)
                
                if ans == 7:
                    l = [i, j, k]
        
    op = []
    for ele in l:
        if ele == 0:
            op.append('+')
        else:
            op.append('-')
    print(A + op[0] + B + op[1] + C + op[2] + D + '=7')
                    
                
                
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
s = list(input())
ans = 0

for c in s:
    ans += int(c)

if ans == 7:
    print(s[0]+"+"+s[1]+"+"+s[2]+"+"+s[3]+"=7")

else:
    x = str((ans-7)//2)
    a = s.index(x)
    
    for i in range(4):
        print(s[i], end="")
        if i == 3:
            print("=7")
            exit()
        if i == a-1:
            print("-", end="")
            a = 100
        else:
            print("+", end="")

Submission status: Runtime Error

Solution code:
s = list(input())
ans = 0

for c in s:
    ans += int(c)

if ans == 7:
    print(s[0]+"+"+s[1]+"+"+s[2]+"+"+s[3]+"=7")

else:
    x = str((ans-7)//2)
    a = s.index(x)
    
    for i in range(4):
        print(s[i], end="")
        if i == 3:
            print("=7")
        if i == a-1:
            print("-", end="")
            a = 100
        else:
            print("+", end="")

Submission status: Runtime Error

Solution code:
s = list(input())
ans = 0

for c in s:
    ans += int(c)
print(ans)

if ans == 7:
    print(s[0]+"+"+s[1]+"+"+s[2]+"+"+s[3]+"=7")

else:
    x = str((ans-7)//2)
    a = s.index(x)
    
    for i in range(4):
        print(s[i], end="")
        if i == 3:
            print("=7")
        if i == a-1:
            print("-", end="")
            a = 100
        else:
            print("+", end="")

Submission status: Runtime Error

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

for i in range(2):
    s = A
    op1 = '+' if i == 0 else '-'
    s += B if op1 == '+' else -1 * B
    for j in range(2):
        op2 = '+' if j == 0 else '-'
        s += C if op2 == '+' else -1 * C
        for k in range(2):
            op3 = '+' if k == 0 else '-'
            s += D if op3 == '+' else -1 * D
            if s == 7:
                ans = str(A)+op1+str(B)+op2+str(C)+op3+str(D)+'=7'

print(ans)

Submission status: Runtime Error

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

for i in range(2):
    s = A
    op1 = '+' if i == 0 else '-'
    s += B if op1 == '+' else -1 * B
    for j in range(2):
        op2 = '+' if j == 0 else '-'
        s += C if op2 == '+' else -1 * C
        for k in range(2):
            op3 = '+' if k == 0 else '-'
            s += D if op3 == '+' else -1 * D
            if s == 7:
                ans = str(A)+op1+str(B)+op2+str(C)+op3+str(D)+'=7'

print(ans)

Submission status: Runtime Error

Solution code:
A = input()
n = len(a)
i = 1
ans = ''

def check(i, a, ans):
    if i == n:
        if eval(a) == 7:
            ans = a
        return ans
    
    else:
        a = a[:2*i-2] + A[i-1:]
        p = i + a.count('+') + a.count('-')
        a = a[:p] + '+' + a[p:]
        ans = check(i+1, a, ans)
        
        a = a[:2*i-2] + A[i-1:]
        p = i + a.count('+') + a.count('-')
        a = a[:p] + '-' + a[p:]
        ans = check(i+1, a, ans)
    return ans

ans = check(i, A, ans) 
print(ans+'=7')

Submission status: Runtime Error

Solution code:
A = input()
n = len(a)
i = 1
ans = ''

def check(i, a, ans):
    if i == n:
#         print(i, 'bottom', a)
        if eval(a) == 7:
            ans = a
        return ans
    
    else:
        a = a[:2*i-2] + A[i-1:]
#         print(i, 'left', a)
        p = i + a.count('+') + a.count('-')
        a = a[:p] + '+' + a[p:]
        ans = check(i+1, a, ans)
        
        a = a[:2*i-2] + A[i-1:]
#         print(i, 'right', a)
        p = i + a.count('+') + a.count('-')
        a = a[:p] + '-' + a[p:]
        ans = check(i+1, a, ans)
    return ans

ans = check(i, A, ans) 
print(ans+'=7')

Submission status: Runtime Error

Solution code:
A = input()
n = len(a)
i = 1
ans = ''

def check(i, a, ans):
    if i == n:
        print(i, 'bottom', a)
        if eval(a) == 7:
            ans = a
        return ans
    
    else:
        a = a[:2*i-2] + A[i-1:]
        print(i, 'left', a)
        p = i + a.count('+') + a.count('-')
        a = a[:p] + '+' + a[p:]
        ans = check(i+1, a, ans)
        
        a = a[:2*i-2] + A[i-1:]
        print(i, 'right', a)
        p = i + a.count('+') + a.count('-')
        a = a[:p] + '-' + a[p:]
        ans = check(i+1, a, ans)
    return ans

ans = check(i, A, ans) 
print(ans+'=7')

Submission status: Runtime Error

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

if a+b+c+d==7:
  print('a+b+c+d=7')
elif a-b+c+d==7:
  print('a-b+c+d=7')
elif a-b-c+d==7:
  print('a-b-c+d=7')
elif a-b+c-d==7:
  print('a-b+c-d=7')
elif a-b-c-d==7:
  print('a-b-c-d=7')
elif a+b-c+d==7:
  print('a+b-c+d=7')
elif a+b-c-d==7:
  print('a+b-c-d=7')
else:
  print('a+b+c-d=7')

Submission status: Runtime Error

Solution code:
def dfs(i,f,ans):
  if i<3:
    return dfs(i+1,f+"+"+s[i+1],ans+int(s[i+1]),dfs(i+1,f+"-"+s[i+1],ans-int(s[i+1])
  elif ans==7:
    print(f+"=7")
a=input()
dfs(0,a[0],0)

Submission status: Runtime Error

Solution code:
def dfs(array: list, index: int, calc: str, result: int):
    if index == len(array):
        if result == 7:
            print("{}=7".format(calc))
            exit(0)

    if index == 0:
        test(array, index + 1, array[index], int(array[index]))
    elif index < len(array):
        test(array, index + 1, calc + "-" + array[index], result - int(array[index]))
        test(array, index + 1, calc + "+" + array[index], result + int(array[index]))

array = list(input())
test(array, 0, "", 0)

Submission status: Runtime Error

Solution code:
def dfs(i: int, t: int, op: str):
  if i == 3:
    if t == 7:
      return op
    else:
      return ""

  return dfs(i + 1, t + s[i + 1], op + "+") + dfs(i + 1, t - s[i + 1], op + "-")

s = list(map(int, list(input())))
ans = 0
op = ""

op = dfs(0, s[0], op)
print(f"{s[0]}{op[0]}{s[1]}{op[1]}{s[2]}{op[2]}{s[3]}=7")

Submission status: Runtime Error

Solution code:
S = input()

sum = int(S[0])
l = [0,0,0]

for i in range(1 << 3):
    for j in range(3):
        if i & 1 << j:
            sum += int(S[3-j])
            l[3-j] = "+"
        else:
            sum -= int(S[3-j])
            l[3-j] = "-"
    if sum == 7:
        print(S[0]+l[0]+S[1]+l[1]+S[2]+l[2]+S[3]+"=7")
        break

Submission status: Runtime Error

Solution code:
S = input()

sum = int(S[0])
l = [0,0,0]

for i in range(1 << 3):
    for j in range(3):
        if i & 1 << j:
            sum += int(S[3-j])
            l[3-j] = "+"
        else:
            sum -= int([3-j])
            l[3-j] = "-"
    if sum == 7:
        print(S[0]+l[0]+S[1]+l[1]+S[2]+l[2]+S[3]+"=7")
        break

Submission status: Runtime Error

Solution code:
S = input()

sum = S[0]
l = [0,0,0]

for i in range(1 << 3):
    for j in range(3):
        if i & 1 << j:
            sum += S[3-j]
            l[3-j] = "+"
        else:
            sum -= S[3-j]
            l[3-j] = "-"
    if sum == 7:
        print(S[0]+l[0]+S[1]+l[1]+S[2]+l[2]+S[3]+"=7")
        break

Submission status: Runtime Error

Solution code:
a = list(input())
a = [int(i) for i in a]
for bit in range(1<<3):
    ans = a[0]
    ans1 = []
    for i in  range(3):
        mask = 1<<i
        if mask&bit:
            ans = (ans+a[i+1])
            ans1.append('+')
        else:
            ans += (ans-a[i+1])
            ans1.append('-')
    
    if ans==7:
        ans2 = ans1
ans3 = []
for i in range(3):
    ans3.append(str(a[i]))
    ans3.append(ans2[i])
ans3.append(str(a[3]))
ans3.append('=7')
ans4 =''.join(ans3)
print(ans4)

Submission status: Runtime Error

Solution code:
a=int(k[0])
b=int(k[1])
c=int(k[2])
d=int(k[3])
if (a+b+c+d)==7:print(k[0]+'+'+k[1]+'+'+k[2]+'+'+k[3]+'='+'7')
elif (a-b+c+d)==7:print(k[0]+'-'+k[1]+'+'+k[2]+'+'+k[3]+'='+'7')
elif (a+b-c+d)==7:print(k[0]+'+'+k[1]+'-'+k[2]+'+'+k[3]+'='+'7')
elif (a+b+c-d)==7:print(k[0]+'+'+k[1]+'+'+k[2]+'-'+k[3]+'='+'7')
elif (a-b-c+d)==7:print(k[0]+'-'+k[1]+'-'+k[2]+'+'+k[3]+'='+'7')
elif (a+b-c-d)==7:print(k[0]+'+'+k[1]+'-'+k[2]+'-'+k[3]+'='+'7')
elif (a-b+c-d)==7:print(k[0]+'-'+k[1]+'+'+k[2]+'-'+k[3]+'='+'7')
elif (a-b-c-d)==7:print(k[0]+'-'+k[1]+'-'+k[2]+'-'+k[3]+'='+'7')

Submission status: Runtime Error

Solution code:
 s=input()

for bit in range(1 << 3):#
    ans=int(s[0])
    f=s[0]
    
    for j in range(3):
        if bit & (1 << j):
            ans+=int(s[j+1])
            f+='+'
            
        else:
            ans-=int(s[j+1])
            f+='-'
        
        f+=s[j+1]
    
    if ans == 7:
        print(f + "=7")
        exit()

Submission status: Runtime Error

Solution code:
N = input()
a = []
for i in range(len(N)):
    a.append(int(N[i]))

X = [0]*(n-1)
flag = False

for i in range(2**(n-1)):
    if flag:
        break
    S = a[0]
    for j in range(n-1):
        if (i >> j) & 1 == 1:
            X[j] = 1
            S += a[j+1]
        else:
            X[j] = 0
            S -= a[j+1]
    if S == k:
        flag = True
        break
print(a[0], end="")
for i in range(3):
    if X[i] == 1:
        print('+', end='')
    else:
        print('-', end='')
    print(a[i+1], end="")
print('=', end='')
print(k)

Submission status: Runtime Error

Solution code:
abcd = input()
bin_pattern_digit = len(abcd) - 1

for i in range(1 << bin_pattern_digit):
    # 初期値:一番左の桁の値。
    result = int(abcd[0:1])
    for j in range(bin_pattern_digit):
        # +を入れた場合
        # 例：1234のパターン1「+」2の場合：i=0の時に+2(abcd[1:2])する必要がある。
        #                 3「-」4の場合：i=2の時に-4(abcd[3:4])する必要がある。
        if i & 1 << j:
            result += int(abcd[j + 1:j + 2])
        # -を入れた場合
        else:
            result -= int(abcd[j + 1:j + 2])

    # 合計が7なら終了
    if result == 7:
        break

# 注意：
# bit変数(i)の結果を確認する場合、文字列とスライスの併用(str(bit(i[0:1])))は使えない。
# 数値と同じで、先頭0は消される = 桁数が可変であるため。
# i & 1 << 0  # 1桁目が真か確認。
# i & 1 << 1  # 2桁目が真か確認。
# -dev-
print(abcd[0:1] + conv_bin(i, 2) + abcd[1:2] + conv_bin(i, 1) + abcd[2:3] + conv_bin(i, 0) + abcd[3:4] + "=7")


def conv_bin(i, digit):
    if i & 1 << digit:
        return "+"
    else:
        return "-"

Submission status: Runtime Error

Solution code:
abcd = input()
bin_pattern_digit = len(abcd) - 1

for i in range(1 << bin_pattern_digit):
    # 初期値:一番左の桁の値。
    result = int(abcd[0:1])
    for j in range(bin_pattern_digit):
        # +を入れた場合
        # 例：1234のパターン1「+」2の場合：i=0の時に+2(abcd[1:2])する必要がある。
        #                 3「-」4の場合：i=2の時に-4(abcd[3:4])する必要がある。
        if i & 1 << j:
            result += int(abcd[j + 1:j + 2])
        # -を入れた場合
        else:
            result -= int(abcd[j + 1:j + 2])

    # 合計が7なら終了
    if result == 7:
        break

# 注意：
# bit変数(i)の結果を確認する場合、文字列とスライスの併用(str(bit(i[0:1])))は使えない。
# 数値と同じで、先頭0は消される = 桁数が可変であるため。
# i & 1 << 0  # 1桁目が真か確認。
# i & 1 << 1  # 2桁目が真か確認。
# -dev-
print(abcd[0:1] + conv_bin(i, 2) + abcd[1:2] + conv_bin(i, 1) + abcd[2:3] + conv_bin(i, 0) + abcd[3:4] + "=7")

Submission status: Runtime Error

Solution code:
import sys
s=input()
a,b,c,d=int(s[0]),int(s[1]),int(s[2]),int(s[3])
if a+b+c+d==7:
  a,b,c,d=str(a),str(b),str(c),str(d)
  print(a+'+'+b+'+'+c'+'+d+'=7')
  sys.exit()
if a+b+c-d==7:
  a,b,c,d=str(a),str(b),str(c),str(d)
  print(a+'+'+b+'+'+c'-'+d+'=7')
  sys.exit()
if a+b-c+d==7:
   a,b,c,d=str(a),str(b),str(c),str(d)
  print(a+'+'+b+'-'+c'+'+d+'=7')
  sys.exit()
if a-b+c+d==7:
  a,b,c,d=str(a),str(b),str(c),str(d)
  print(a+'-'+b+'+'+c'+'+d+'=7')
  sys.exit()
if a+b-c-d==7:
  a,b,c,d=str(a),str(b),str(c),str(d)
  print(a+'+'+b+'-'+c'-'+d+'=7')
  sys.exit()
if a-b-c+d==7:
  a,b,c,d=str(a),str(b),str(c),str(d)
  print(a+'-'+b+'-'+c'+'+d+'=7')
  sys.exit()
if a-b+c-d==7:
  a,b,c,d=str(a),str(b),str(c),str(d)
  print(a+'-'+b+'+'+c'-'+d+'=7')
  sys.exit()
if a-b-c-d==7:
  a,b,c,d=str(a),str(b),str(c),str(d)
  print(a+'-'+b+'-'+c'-'+d+'=7')
  sys.exit()

Submission status: Runtime Error

Solution code:
import sys
s=input()
a,b,c,d=s[0],s[1],s[2],s[3]
if a+b+c+d==7:
  print('a+b+c+d=7')
  sys.exit()
if a+b+c-d==7:
  print('a+b+c-d=7')
  sys.exit()
if a+b-c+d==7:
  print('a+b-c+d=7')
  sys.exit()      
if a-b+c+d==7:
  print('a-b+c+d=7')
  sys.exit()
if a+b-c-d==7:
  print('a+b-c-d=7')
  sys.exit()
if a-b-c+d==7:
  print('a-b-c+d=7')
  sys.exit()
if a-b+c-d==7:
  print('a-b+c-d=7')
  sys.exit()
if a-b-c-d==7:
  print('a-b-c-d=7')
  sys.exit()

Submission status: Runtime Error

Solution code:
import sys
a,b,c,d=map(int,input().split())
if a+b+c+d==7:
  print('a+b+c+d=7')
  sys.exit()
if a+b+c-d==7:
  print('a+b+c-d=7')
  sys.exit()
if a+b-c+d==7:
  print('a+b-c+d=7')
  sys.exit()      
if a-b+c+d==7:
  print('a-b+c+d=7')
  sys.exit()
if a+b-c-d==7:
  print('a+b-c-d=7')
  sys.exit()
if a-b-c+d==7:
  print('a-b-c+d=7')
  sys.exit()
if a-b+c-d==7:
  print('a-b+c-d=7')
  sys.exit()
if a-b-c-d==7:
  print('a-b-c-d=7')
  sys.exit()

Submission status: Runtime Error

Solution code:
import sys
a,b,c,d=int,input().split()
if a+b+c+d==7:
  print('a+b+c+d=7')
  sys.exit()
if a+b+c-d==7:
  print('a+b+c-d=7')
  sys.exit()
if a+b-c+d==7:
  print('a+b-c+d=7')
  sys.exit()      
if a-b+c+d==7:
  print('a-b+c+d=7')
  sys.exit()
if a+b-c-d==7:
  print('a+b-c-d=7')
  sys.exit()
if a-b-c+d==7:
  print('a-b-c+d=7')
  sys.exit()
if a-b+c-d==7:
  print('a-b+c-d=7')
  sys.exit()
if a-b-c-d==7:
  print('a-b-c-d=7')
  sys.exit()

Submission status: Runtime Error

Solution code:
s = input()
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])
ans1 = '+'
ans2 = '+'
ans3 = '+'
m=7-a
for B in[b,-b]:
    for C in[c,-c]:
        for D in[d,-d]:
            if B+C+D==m:
                if B==-b:
                    ans1="-"
                if C==-c:
                    ans2="-"
                if D==-d:
                    ans3="-"
                break
print(a+ans1+b+ans2+c+ans3+d)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000)
a,b,c,d=list(map(str,input()))
def solve(m,n):
    if eval(m)==7:
        print(m+"=7")
        exit(0)
    else:
        solve(m,n+2)
        solve(m[:n]+"-"+m[n+1:],n+2)
solve(a+"+"+b+"+"+c+"+"+d,1)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000)
a,b,c,d=list(map(str,input()))
def solve(m,n):
    if eval(m)==7:
        print(m+"=7")
        exit(0)
    else:
        solve(m[:n]+"-"+m[n+1:],n+2)
solve(a+"+"+b+"+"+c+"+"+d,1)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000)
a,b,c,d=list(input())
def solve(m,n):
    if eval(m)==7:
        print(m+"=7")
        exit(0)
    else:
        m[n]="-"
        solve(n,n+2)
solve(a+"+"+b+"+"+c+"+"+d,1)

Submission status: Runtime Error

Solution code:
a,b,c,d=list(input())
def solve(m,n):
    if eval(m)==7:
        print(m+"=7")
        exit(0)
    else:
        m[n]="-"
        solve(n,n+2)
solve(a+"+"+b+"+"+c+"+"+d,1)

Submission status: Runtime Error

Solution code:
n = [int(x) for ix in input()]
l=len(n)-1
for i in range(2**l):
    op=["-"]*l
    for j in range(l):
        if ((i>>j)&1):
            op[l-1-j]="+"
    formula=""
    for p,q in zip(n,op + [""]):
        formula+=(p+q)
    if eval(formula)==7:
        print(formula + "=7" )
        break

Submission status: Runtime Error

Solution code:
ABCD = int(input())
a = int(ABCD//10e2)
b = int((ABCD-a*10e2)//10e1)
c = int((ABCD-a*10e2-b*10e1)//10)
d = int(ABCD-a*10e2-b*10e1-c*10)
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: Runtime Error

Solution code:
for i in range(2**(l-1)):
    f = ""
    for j in range(l-1):
        f += s[j]
        if i & (1 << j):
            f += "+"
        else:
            f += "-"
        if j == l-2:
             f += s[l-1]
    if eval(f)==7:
        print(f+"=7")
        break

Submission status: Runtime Error

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

nums = list(map(int, list(input().rstrip('\r'))))
ans_op = [''] * 3
for bit in range(2**3):
    total = 0
    tmp = [''] * 3
    for i in range(3):
        if i == 0:
            total += nums[i]
        if (bit >> i) & 1:
            total += nums[i+1]
            tmp[i] = '+'
        else:
            total -= nums[i+1]
            tmp[i] = '-'
    if total == 7:
       ans_op = tmp
       break
ans = ''
for i in range(3):
    if i == 0:
        ans += (str(nums[i]))
    ans += (ans_op[i] + str(nums[i+1]))
ans += '=7'
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
l = len(s)
ans = 0
for i in range(2**(l-1)):
    e = ""
    for j in range(l):
        if ((i >> j) & 1):
            e += s[j] + "+"
        else:
            e += s[j] + "-"
    if eval(e) == 7:
        print('{}=7'.format(e))
        break

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
ABCD = input()
A, B, C, D = int(ABCD[0]), int(ABCD[1]), int(ABCD[2]), int(ABCD[3])
oper = ['+', '-']
for op1 in range(2):
    for op2 in range(2):
        for op3 in range(2):
            sum = A + (-1)**op1*B + (-1)**op2*C + (-1)**op3*D
            if sum == 7:
                return str(A)+oper[op1]+str(B)+oper[op2]+str(C)+oper[op3]+str(D)+'=7'

Submission status: Runtime Error

Solution code:
nums=[int(i) for i in input()]
ops=[1,-1]
for op1 in ops:
  for op2 in ops:
    for op3 in ops:
      if nums[0]+op1*nums[1]+op2*nums[2]+op3*nums[3]==7:
        ans=''+str(nums[0])
        ans+='+' if op1==1 else '-'
        ans+=str(nums[1])
        ans+='+' if op2==1 else '-'
        ans+=str(nums[2])
        ans+='+' if op3==1 else '-'
        ans+=nums[3]
print(ans)

Submission status: Runtime Error

Solution code:
def solve():
    n = list(input())
    n = [ord(c) - ord('0') for c in n]
    sign = ['-', '+']

    for i in range(2):
        for j in range(2):
            for k in range(2):
                t = n[0]
                t += n[1] * (i * 2 - 1)
                t += n[2] * (j * 2 - 1)
                t += n[3] * (k * 2 - 1)
                if t == 7:
                    print(f'{n[0]}{sign[i]}{n[1]}{sign[j]}{n[2]}{sign[k]}{n[3]}=7')
                    return


if __name__ == "__main__":
    solve()

Submission status: Runtime Error

Solution code:
N=input()
a=int(N[0])
b=int(N[1])
c=int(N[2])
d=int(N[3])
if a+b+c+d==7:
  print(a+"+"+b+"+"+c+"+"+d+"="+7)
  exit()
if a-b+c+d==7:
  print(a+"-"+b+"+"+c+"+"+d+"="+7)
  exit()
if a+b-c+d==7:
  print(a+"+"+b+"-"+c+"+"+d+"="+7)
  exit()
if a+b+c-d==7:
  print(a+"+"+b+"+"+c+"-"+d+"="+7)
  exit()
if a-b-c+d==7:
  print(a+"-"+b+"-"+c+"+"+d+"="+7)
  exit()
if a-b+c-d==7:
  print(a+"-"+b+"+"+c+"-"+d+"="+7)
  exit()
if a+b-c-d==7:
  print(a+"+"+b+"-"+c+"-"+d+"="+7)
  exit()
if a-b-c-d==7:
  print(a+"-"+b+"-"+c+"-"+d+"="+7)
  exit()

Submission status: Runtime Error

Solution code:
X = input()
flag = ['+','-']
check = 0
for i in flag:
    if i == '+':
        ans = int(X[0]) + int(X[1])
    else:
        ans = int(X[0]) - int(X[1])
    if check == 1:
        break
    for j in flag:
        if j == '+':
            ans += int(X[2])
        else:
            ans -= int(X[2])
        if check == 1:
            break
        for k in flag:
            if k == '+':
                ans += int(X[3])
            else:
                ans -= int(X[3])
            if ans == 7:
                anslist = [X[0],i,X[1],j,X[2],k,X[3],'=','7']
                check = 1
            if check == 1:
                break
print(''.join(anslist))

Submission status: Runtime Error

Solution code:
X = input()
flag = ['+','-']
for i in flag:
    if i == '+':
        ans = int(X[0]) + int(X[1])
    else:
        ans = int(X[0]) - int(X[1])
    for j in flag:
        if j == '+':
            ans += int(X[2])
        else:
            ans -= int(X[2])
        for k in flag:
            if k == '+':
                ans += int(X[3])
            else:
                ans -= int(X[3])
            if ans == 7:
                anslist = [X[0],i,X[1],j,X[2],k,X[3],'=','7']
print(''.join(anslist))

Submission status: Runtime Error

Solution code:
X = input()
flag = ['+','-']
for i in flag:
    if i == '+':
        ans = int(X[0]) + int(X[1])
    else:
        ans = int(X[0]) - int(X[1])
    for j in flag:
        if j == '+':
            ans += int(X[2])
        else:
            ans -= int(X[2])
        for k in flag:
            if k == '+':
                ans += int(X[3])
            else:
                ans -= int(X[3])
            if ans == 7:
                anslist = [X[0],i,X[1],j,X[2],k,X[3]]
print(''.join(anslist))

Submission status: Runtime Error

Solution code:
qq

Submission status: Runtime Error

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

    if a+b+c+d == 7:
        print(f'{a}+{b}+{c}+{d}=7')
        return 

    if a+b+c-d == 7:
        print(f'{a}+{b}+{c}-{d}=7')
        return 

    if a+b-c+d == 7:
        print(f'{a}+{b}-{c}+{d}=7')
        return 

    if a-b+c+d == 7:
        print(f'{a}-{b}+{c}+{d}=7')
        return 

    if a+b-c-d == 7:
        print(f'{a}+{b}-{c}-{d}=7')
        return 

    if a-b+c-d == 7:
        print(f'{a}-{b}+{c}-{d}=7')
        return 

    if a-b-c+d == 7:
        print(f'{a}-{b}-{c}+{d}=7')
        return 

    if a-b-c-d == 7:
        print(f'{a}-{b}-{c}-{d}=7')
        return 
      
solve()

Submission status: Runtime Error

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

if a+b+c+d==7:
    print(f'{a}+{b}+{c}+{d}=7')
    exit()
if a+b+c-d==7:
    print(f'{a}+{b}+{c}-{d}=7')
    exit()
if a+b-c+d==7:
    print(f'{a}+{b}-{c}+{d}=7')
    exit()
if a-b+c+d==7:
    print(f'{a}-{b}+{c}+{d}=7')
    exit()
if a-b-c+d==7:
    print(f'{a}-{b}-{c}+{d}=7')
    exit()
if a-b+c-d==7:
    print(f'{a}-{b}+{c}-{d}=7')
    exit()
if a+b-c-d==7:
    print(f'{a}+{b}-{c}-{d}=7')
    exit()
if a-b-c-d==7:
    print(f'{a}-{b}-{c}-{d}=7')
    exit()

Submission status: Runtime Error

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

if a + b + c + d == 7:
    print(a, '+', b, '+', c, '+', d, sep='')
elif a + b + c - d == 7:
    print(a, '+', b, '+', c, '-', d, sep='')
elif a + b - c + d == 7:
    print(a, '+', b, '-', c, '+', d, sep='')
elif a + b - c - d == 7:
    print(a, '+', b, '-', c, '-', d, sep='')
elif a - b + c + d == 7:
    print(a, '-', b, '+', c, '+', d, sep='')
elif a - b + c - d == 7:
    print(a, '-', b, '+', c, '-', d, sep='')
elif a - b - c + d == 7:
    print(a, '-', b, '-', c, '+', d, sep='')
elif a - b - c - d == 7:
    print(a, '-', b, '-', c, '-', d, sep='')

Submission status: Runtime Error

Solution code:
a=input()
op=list("+-")
flag = False
for i in range(op):
    for j in range(op):
        for k in range(op):
            s = a[0]+i+a[1]+j+a[2]+k+a[3]
            flag = True
            if eval(s) == 7:
                break
        if flag:
            break
    if flag:
        break
print(s+"=7")

Submission status: Runtime Error

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

op_choice = ["+", "-"]

for op1 in op_choice:
    for op2 in op_choice:
        for op3 in op_choice:
            check = a + op1 + b + op2 + c + op3 + d
            if eval(check) == 7:
                print(check + "=7")
                exit()
​lily

Submission status: Runtime Error

Solution code:
math = input()
for i in range(2**3):
  op = format(i,"03b")
  op = op.replace('1', '+').replace('0', '-')
  ans = math[0]+op[0]+math[1]+op[1]+math[2]+op[3]+math[3]
  if eval(ans) == 7:
    print(ans+"=7")
    break

Submission status: Runtime Error

Solution code:
ABCD = input()

for i in range(2 ** 3):
    op = format(i, '03b')
    op = op.replace('1', '+').replace('0', '-')
    formula = ABCD[0] + op[0] + ABCD[1] + op[1] + ABCD[2] + op[2]
    if eval(formula) == 7:
        print(formula + '=7')
        break

Submission status: Runtime Error

Solution code:
ABCD = input()

A = int(ABCD[0])
B = int(ABCD[1])
C = int(ABCD[2])
D = int(ABCD[3])


for x in range(2):
  if x == 0:
    _ = A+B
    op1 = '+'
  else:
    _ = A-B
    op1 = '-'
  for y in range(2):
    if y == 0:
      _ += C
      op2 = '+'
    else:
      _ -= C
      op2 = '-'      
    for z in range(2):
      if z == 0:
        _ += D
        op3 = '+'
      else:
        _ -= D
        op3 = '-'      
      if _ == 7:
        ans = str(A)+op1+str(B)+op2+str(C)+op3+str(D)+'=7'

print(ans)

Submission status: Runtime Error

Solution code:
def test():
    nums = list(map(int, list(input())))
    for i in range(2 ** 3):
        ans = nums[0]
        res = '{}'.format(nums[0])
        for j in range(3):
            if (i >> j) & 1:
                ans += nums[j+1]
                res += '+{}'.format(nums[j+1])
            else:
                ans -= nums[j+1]
                res += '-{}'.format(nums[j+1])
        if ans == 7:
            print('{}=7'.format(res))
            exit(1)

if __name__ == '__main__':
    test()

Submission status: Runtime Error

Solution code:
def test():
    nums = list(map(int, list(input())))
    for i in range(2 ** 3):
        ans = nums[0]
        res = f'{nums[0]}'
        for j in range(3):
            if (i >> j) & 1:
                ans += nums[j+1]
                res += f'+{nums[j+1]}'
            else:
                ans -= nums[j+1]
                res += f'-{nums[j+1]}'
        if ans == 7:
            print(f'{res}=7')
            exit(1)

if __name__ == '__main__':
    test()

Submission status: Runtime Error

Solution code:
S = input()

total = 0
n = len(S)
ans = 0

for i in range(2**(n-1)):
    form = S
    bit = []
    for _ in range(n-1):
        bit.append(i%2)
        i =  i // 2
    eq = ""
    for i, b in enumerate(bit):
        eq += (form[i])
        if b == 1:
            eq += ('+')
    eq += form[-1]

    ans += eval(eq)

print(ans)

Submission status: Runtime Error

Solution code:
s = input()

def func(ac,s,op):
  next = s[0]
  if len(s) ==1:
    if ac + next == 7:
      print(str+'+'+s[0]+'=7')
      exit(0)
    if ac - next == 7:
      print(str+'-'+s[0]+'=7')
      exit(0)
  else:
    func(ac+next,s[1:],op+'+'+str(next))
    func(ac-next,s[1:],op+'-'+str(next))
  
func(int(s[0]),s[1:],s[0])

Submission status: Runtime Error

Solution code:


def main():
    s = input()
    n = len(s)
    l = ["+", "-"]

    for i in range(2 ** n):
        pm = []
        ans = int(s[0])
        for j in range(n):
            if ((i >> j) & 1):
                pm.append(l[0])
            else:
                pm.append(l[1])

        for k in range(n):
            if pm[k] == "+":
                ans += int(s[k + 1])
            else:
                ans -= int(s[k + 1])

        if ans == 7:
            print(s[0]+pm[0]+s[1]+pm[1]+s[2]+pm[2]+s[3]+"=7")
            break
    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:


def main():
    s = [int(i) for i in input()]
    n = len(s)
    l = ["+", "-"]

    for i in range(2 ** n):
        pm = []
        ans = int(s[0])
        for j in range(n):
            if ((i >> j) & 1):
                pm.append(l[0])
            else:
                pm.append(l[1])

        for k in range(n):
            if pm[k] == "+":
                ans += int(s[k + 1])
            else:
                ans -= int(s[k + 1])

        if ans == 7:
            print(s[0]+pm[0]+s[1]+pm[1]+s[2]+pm[2]+s[3]+"=7")
            break
    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
S = input()
l = list(map(int, S))
s = l[0]
p = S[0]

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

    for i in range(2):
        if a[i] == "+":
            s += l[i]
        else:
            s += (l[i])*-1
    
    for i in range(2):
        p += a[i]
        p += S[i+1]
        
    if s == 7:
        print("{}=7".format(p))