qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n = int(input())
a = n // 1000
b = n // 100 - a * 10
c = n // 10 - a * 100 - b * 10
d = n - a * 1000 - b * 100 - c * 10
yet = True
if a+b+c+d==7 and yet:
    print(str(a)+'+'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
    yet = False
if a+b+c-d==7 and yet:
    print(str(a)+'+'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
    yet = False
if a+b-c+d==7 and yet:
    print(str(a)+'+'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
    yet = False
if a+b-c-d==7 and yet:
    print(str(a)+'+'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
    yet = False
if a-b+c+d==7 and yet:
    print(str(a)+'-'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
    yet = False
if a-b+c-d==7 and yet:
    print(str(a)+'-'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
    yet = False
if a-b-c+d==7 and yet:
    print(str(a)+'-'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
    yet = False
if a-b-c-d==7 and yet:
    print(str(a)+'

Fixed code:
n = int(input())
a = n // 1000
b = n // 100 - a * 10
c = n // 10 - a * 100 - b * 10
d = n - a * 1000 - b * 100 - c * 10
yet = True
if a+b+c+d==7 and yet:
    print(str(a)+'+'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
    yet = False
if a+b+c-d==7 and yet:
    print(str(a)+'+'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
    yet = False
if a+b-c+d==7 and yet:
    print(str(a)+'+'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
    yet = False
if a+b-c-d==7 and yet:
    print(str(a)+'+'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
    yet = False
if a-b+c+d==7 and yet:
    print(str(a)+'-'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
    yet = False
if a-b+c-d==7 and yet:
    print(str(a)+'-'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
    yet = False
if a-b-c+d==7 and yet:
    print(str(a)+'-'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
    yet = False
if a-b-c-d==7 and yet:
    print(str(a)+'-'+str(b)+'-'+str(c)+'-'+str(d)+'=7')    
    yet = False
Buggy code:
abcd = list(input())

for i in ["+","-"]:
    for j in ["+","-"]:
        for k in ["+","-"]:
            siki = abcd[0] + i + abcd[1] + j + abcd[2] + k + abcd[3]
            if eval(siki) == 7:
                print(siki + "=7")

Fixed code:
abcd = list(input())

for i in ["+","-"]:
    for j in ["+","-"]:
        for k in ["+","-"]:
            siki = abcd[0] + i + abcd[1] + j + abcd[2] + k + abcd[3]
            if eval(siki) == 7:
                print(siki + "=7")
                exit()
Buggy code:
input_str = input()
A = int(input_str[0])
B = int(input_str[1])
C = int(input_str[2])
D = int(input_str[3])

list = []
list.append(A + B + C + D)
list.append(A + B + C - D)
list.append(A + B - C + D)
list.append(A + B - C - D)
list.append(A - B + C + D)
list.append(A - B + C - D)
list.append(A - B - C + D)
list.append(A - B - C - D)

num = list.index(7)
print(num)

if num <= 3:
    op1 = '+'
else:
    op1 = '-'

if num == 0 or num == 1 or num == 4 or num == 5:
    op2 = '+'
else:
    op2 = '-'

if num % 2 == 0:
    op3 = '+'
else:
    op3 = '-'

print('{}{}{}{}{}{}{}=7'.format(A,op1,B,op2,C,op3,D))


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

list = []
list.append(A + B + C + D)
list.append(A + B + C - D)
list.append(A + B - C + D)
list.append(A + B - C - D)
list.append(A - B + C + D)
list.append(A - B + C - D)
list.append(A - B - C + D)
list.append(A - B - C - D)

num = list.index(7)

if num <= 3:
    op1 = '+'
else:
    op1 = '-'

if num == 0 or num == 1 or num == 4 or num == 5:
    op2 = '+'
else:
    op2 = '-'

if num % 2 == 0:
    op3 = '+'
else:
    op3 = '-'

print('{}{}{}{}{}{}{}=7'.format(A,op1,B,op2,C,op3,D))
Buggy code:
A,B,C,D = map(int,list(input()))

dic = { 1:"+" , -1:"-"}

import itertools
for AB,BC,CD in itertools.product([1,-1],repeat=3):
    tmp = A + B*AB + C*BC + D*CD

    if tmp ==7:
        ans = str(A)+dic[AB]+str(B)+dic[BC]+str(C)+dic[CD]+str(D)
        print(ans)
        exit()

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

dic = { 1:"+" , -1:"-"}

import itertools
for AB,BC,CD in itertools.product([1,-1],repeat=3):
    tmp = A + B*AB + C*BC + D*CD

    if tmp ==7:
        ans = str(A)+dic[AB]+str(B)+dic[BC]+str(C)+dic[CD]+str(D)+"=7"
        print(ans)
        exit()
Buggy code:
import operator

vals = input()
nums = list(map(int, tuple(vals)))

def dump(a,b,c):
    if a == operator.add:
        a = '+'
    else:
        a = '-'
    if b == operator.add:
        b = '+'
    else:
        b = '-'
    if c == operator.add:
        c = '+'
    else:
        c = '-'
    print(vals[0] + a + vals[1] + b + vals[2] + c + vals[3] + '=7')

for a in (operator.add, operator.sub):
    for b in (operator.add, operator.sub):
        for c in (operator.add, operator.sub):
            if c(b(a(nums[0], nums[1]), nums[2]), nums[3]) == 7:
                print(a, b, c)
                dump(a, b, c)
                break

Fixed code:
import operator

vals = input()
nums = list(map(int, tuple(vals)))

def dump(a,b,c):
    if a == operator.add:
        a = '+'
    else:
        a = '-'
    if b == operator.add:
        b = '+'
    else:
        b = '-'
    if c == operator.add:
        c = '+'
    else:
        c = '-'
    print(vals[0] + a + vals[1] + b + vals[2] + c + vals[3] + '=7')

for a in (operator.add, operator.sub):
    for b in (operator.add, operator.sub):
        for c in (operator.add, operator.sub):
            if c(b(a(nums[0], nums[1]), nums[2]), nums[3]) == 7:
                dump(a, b, c)
                exit(0)
Buggy code:
ABCD=input()
L=list(ABCD)

def bfs(i,j,a,c):#i,hidari,migi
  if i==3:
    if j+int(L[3])==7:
      c+=[L[0]+a[0]+L[1]+a[1]+L[2]+"+"+L[3]+"=7"]
    elif j-int(L[3])==7:
      c+=[L[0]+a[0]+L[1]+a[1]+L[2]+"-"+L[3]+"=7"]
    return 
    
  else:
    bfs(i+1,j+int(L[i]),a+"+",c)
    bfs(i+1,j-int(L[i]),a+"-",c)
    return c[0]
  


print(bfs(1,int(L[0]),"",[]))

Fixed code:
ABCD=input()
L=list(ABCD)

def bfs(i,j,a,c):#i,hidari,migi
  if i==3:
    if j+int(L[3])==7:
      c+=[L[0]+a[0]+L[1]+a[1]+L[2]+"+"+L[3]+"=7"]
    elif j-int(L[3])==7:
      c+=[L[0]+a[0]+L[1]+a[1]+L[2]+"-"+L[3]+"=7"]
    return 
    
  else:
    bfs(i+1,j+int(L[i]),a+"+",c)
    bfs(i+1,j-int(L[i]),a+"-",c)
    return c
  

d=[]

ans=bfs(1,int(L[0]),"",d)
print(d[0])
Buggy code:
ABCD = input()

for i in range(2**(len(ABCD)-1)):
    n = int(ABCD[0])
    ans = ABCD[0]
    for j, c in enumerate(format(i, '0' + str(len(ABCD)-1) + 'b')):
        if c == '0':
            n += int(ABCD[j+1])
            ans += '+'
        else:
            n -= int(ABCD[j+1])
            ans += '-'
        ans += ABCD[j+1]
    if n == 7:
        print(ans)
        exit(0)

Fixed code:
ABCD = input()

for i in range(2**(len(ABCD)-1)):
    n = int(ABCD[0])
    ans = ABCD[0]
    for j, c in enumerate(format(i, '0' + str(len(ABCD)-1) + 'b')):
        if c == '0':
            n += int(ABCD[j+1])
            ans += '+'
        else:
            n -= int(ABCD[j+1])
            ans += '-'
        ans += ABCD[j+1]
    if n == 7:
        print(ans + '=7')
        exit(0)
Buggy code:
# -*- coding:utf-8 -*-
S=input()
sign=[+-]
for i in range(2):
  for j in range(2):
    for n in range(2):
      if eval(S[0]+sign[i]+S[1]+sign[j]+S[2]+sign[n]+S[3])==7:
        print(str(S[0]+sign[i]+S[1]+sign[j]+S[2]+sign[n]+S[3])+'=7')
        exit()

Fixed code:
# -*- coding:utf-8 -*-
S=input()
sign="+-"
for i in range(2):
  for j in range(2):
    for n in range(2):
      if eval(S[0]+sign[i]+S[1]+sign[j]+S[2]+sign[n]+S[3])==7:
        print(str(S[0]+sign[i]+S[1]+sign[j]+S[2]+sign[n]+S[3])+'=7')
        exit()
Buggy code:
x = input()
#print(x)
y = [int(c) for c in x]
#print(y)
a = y[0]
b = y[1]
c = y[2]
d = y[3]
if a+b+c+d == 7:
  print("a+b+c+d=",a+b+c+d,sep='')
  exit()
if a+b+c-d == 7:
  print("a+b+c-d=",a+b+c-d,sep='')
  exit()
if a+b-c+d == 7:
  print("a+b-c+d=",a+b-c+d,sep='')
  exit()
if a-b+c+d == 7:
  print("a-b+c+d=",a-b+c+d,sep='')
  exit()
if a-b-c+d == 7:
  print("a-b-c+d=",a-b-c+d,sep='')
  exit()
if a-b+c-d == 7:
  print("a-b+c-d=",a-b+c-d,sep='')
  exit()
if a-b-c-d == 7:
  print("a-b-c-d=",a-b-c-d,sep='')
  exit()
if a+b-c-d == 7:
  print("a+b-c-d=",a+b-c-d,sep='')
  exit()

Fixed code:
x = input()
#print(x)
y = [int(c) for c in x]
#print(y)
a = y[0]
b = y[1]
c = y[2]
d = y[3]
if a+b+c+d == 7:
  print(a,"+",b,"+",c,"+",d,"=",a+b+c+d, sep='')
  exit()
if a+b+c-d == 7:
  print(a,"+",b,"+",c,"-",d,"=",a+b+c-d, sep='')
  exit()
if a+b-c+d == 7:
  print(a,"+",b,"-",c,"+",d,"=",a+b-c+d, sep='')
  exit()
if a-b+c+d == 7:
  print(a,"-",b,"+",c,"+",d,"=",a-b+c+d, sep='')
  exit()
if a-b-c+d == 7:
  print(a,"-",b,"-",c,"+",d,"=",a-b-c+d, sep='')
  exit()
if a-b+c-d == 7:
  print(a,"-",b,"+",c,"-",d,"=",a-b+c-d, sep='')
  exit()
if a-b-c-d == 7:
  print(a,"-",b,"-",c,"-",d,"=",a-b-c-d, sep='')
  exit()
if a+b-c-d == 7:
  print(a,"+",b,"-",c,"-",d,"=",a+b-c-d, sep='')
  exit()
Buggy code:
row = input()
row = list(row)
row = list(map(int, row))

for i in range(2):
    sum = row[0]
    if i == 0:
        op1 = "+"
        sum += row[1]
    else:
        op1 = "-"
        sum -= row[1]
    for j in range(1):
        if j == 0:
            op2 = "+"
            sum += row[2]
        else:
            op2 = "-"
            sum -= row[2]       
        for k in range(1):
            if j == 0:
                op3 = "+"
                sum += row[3]
            else:
                op3 = "-"
                sum -= row[3]  
            if sum == 7:
                break

print(row[0],op1,row[1],op2,row[2],op3,row[3],"=7", sep="")

Fixed code:
row = input()
row = list(row)
row = list(map(int, row))
Flag = False
for i in range(2):
    for j in range(2):
        for k in range(2):
            sum = row[0]
            if i == 0:
                op1 = "+"
                sum += row[1]
            else:
                op1 = "-"
                sum -= row[1]
            if j == 0:
                op2 = "+"
                sum += row[2]
            else:
                op2 = "-"
                sum -= row[2]   
            if k == 0:
                op3 = "+"
                sum += row[3]
            else:
                op3 = "-"
                sum -= row[3]  
            if sum == 7:
                Flag = True
                break
        if Flag:
            break
    if Flag:
        break

print(row[0],op1,row[1],op2,row[2],op3,row[3],"=7", sep="")
Buggy code:
s = [int(x) for x in input()]

import functools
@functools.lru_cache(maxsize=None)
def f(c, n):
    print("c ", c, n)
    if n == 4:
        if c == 7:
            return []
        else:
            return None
    v = s[n]
    for o in ['+', '-']:
        print("f ", ''.join([str(x) for x in [c, o, v]]), eval('%d%s%d'% (c,o,v)), n + 1)
        ret = f(eval('%d%s%d'% (c,o,v)), n + 1)
        if ret is not None:
            return [o, v] + ret
print(''.join([str(x) for x in ([s[0]] + f(s[0], 1))]) + '=7')

Fixed code:
s = [int(x) for x in input()]

import functools
@functools.lru_cache(maxsize=None)
def f(c, n):
    if n == 4:
        if c == 7:
            return []
        else:
            return None
    v = s[n]
    for o in ['+', '-']:
        ret = f(eval('%d%s%d'% (c,o,v)), n + 1)
        if ret is not None:
            return [o, v] + ret
print(''.join([str(x) for x in ([s[0]] + f(s[0], 1))]) + '=7')
Buggy code:
from itertools import product
s=input()
for b in list(product["+","-"],repeat=3):
    ans=s[0]+b[0]+s[1]+b[1]+s[2]+b[2]+s[3]
    if evel(ans)==7:
        print(ans+"7")
        break

Fixed code:
from itertools import product
s=input()
for b in list(product(["+","-"],repeat=3)):
    ans=s[0]+b[0]+s[1]+b[1]+s[2]+b[2]+s[3]
    if eval(ans)==7:
        print(ans+"=7")
        break
Buggy code:
import sys
import copy

def main():
    ABCD = list(map(str, input()))
    b_digit = len(ABCD)-1

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

        ABCD_tmp = copy.deepcopy(ABCD)
        for k in range(len(signs)):
            ABCD_tmp.insert(1+k*2,signs[k])
        if(eval("".join(ABCD_tmp))==7):
            print("{}=7".format("".join(ABCD_tmp)))
            sys.exit()

main()
~

Fixed code:
import sys
import copy

def main():
    ABCD = list(map(str, input()))
    b_digit = len(ABCD)-1

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

        ABCD_tmp = copy.deepcopy(ABCD)
        for k in range(len(signs)):
            ABCD_tmp.insert(1+k*2,signs[k])
        if(eval("".join(ABCD_tmp))==7):
            print("{}=7".format("".join(ABCD_tmp)))
            sys.exit()

main()
Buggy code:
import operator
s = [int(i) for i in list(input())]

op = []
op.append( operator.add )
op.append( operator.sub )


for i in range(2) :
  for j in range(2) :
    for k in range(2) :

      r = op[i](s[0],s[1])

      r = op[j](r,s[2])

      r = op[k](r,s[3])

      if r == 7 :
        op1 = "+" if i == 0 else "-"
        op2 = "+" if j == 0 else "-"
        op3 = "+" if k == 0 else "-"
        print(str(s[0])+op1+str(s[1])+op2+str(s[2])+op3+str(s[3]))
        exit()
      
      


Fixed code:
import operator
s = [int(i) for i in list(input())]

op = []
op.append( operator.add )
op.append( operator.sub )


for i in range(2) :
  for j in range(2) :
    for k in range(2) :

      r = op[i](s[0],s[1])

      r = op[j](r,s[2])

      r = op[k](r,s[3])

      if r == 7 :
        op1 = "+" if i == 0 else "-"
        op2 = "+" if j == 0 else "-"
        op3 = "+" if k == 0 else "-"
        print(str(s[0])+op1+str(s[1])+op2+str(s[2])+op3+str(s[3])+"=7")
        exit()
Buggy code:
i=input()

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

if a+b+c+d==7:
    x="+"
    y="+"
    z="+"

if a+b+c-d==7:
    x="+"
    y="+"
    z="-"
    
    
if a+b-c+d==7:
    x="+"
    y="-"
    z="+"    

if a-b+c+d==7:
    x="-"
    y="+"
    z="+"
    
if a-b-c+d==7:
    x="-"
    y="-"
    z="+"

if a-b+c-d==7:
    x="-"
    y="+"
    z="-"

if a-b-c+d==7:
    x="-"
    y="-"
    z="+"
    
if a-b-c-d==7:
    x="-"
    y="-"
    z="-"
    
    
print(a,end="")
print(x,end="")
print(b,end="")
print(y,end="")
print(c,end="")
print(z,end="")
print(d,end="")
print("=7")

Fixed code:
i=input()

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

if a+b+c+d==7:
    x="+"
    y="+"
    z="+"
elif a+b+c-d==7:
    x="+"
    y="+"
    z="-"
elif a+b-c+d==7:
    x="+"
    y="-"
    z="+"    
elif a-b+c+d==7:
    x="-"
    y="+"
    z="+"
elif a-b-c+d==7:
    x="-"
    y="-"
    z="+"
elif a-b+c-d==7:
    x="-"
    y="+"
    z="-"
elif a+b-c-d==7:
    x="+"
    y="-"
    z="-"
elif a-b-c-d==7:
    x="-"
    y="-"
    z="-"
    
    
print(a,end="")
print(x,end="")
print(b,end="")
print(y,end="")
print(c,end="")
print(z,end="")
print(d,end="")
print("=7")
Buggy code:
def solve():
    A, B, C, D = input()
    op = '+-'
    
    for op1 in op:
        for op2 in op:
            for op3 in op:
                left_hand = A + op1 + B + op2 + C + op3 + D
                if eval(left_hand) == 7:
                    return left_hand + '=7'

solve()

Fixed code:
def solve():
    A, B, C, D = input()
    op = '+-'
    
    for op1 in op:
        for op2 in op:
            for op3 in op:
                left_hand = A + op1 + B + op2 + C + op3 + D
                if eval(left_hand) == 7:
                    return left_hand + '=7'

print(solve())
Buggy code:
s=input()
a,b,c,d=s[0],s[1],s[2],s[3]
ans=int(a)
o=['+','-']
p=[1,int(-1)]
x,y,z='','',''
e,f,g=0,0,0
for i in range(2):
  e=int(b)*((-1)**i)
  ans+=e
  x=o[i]
  for j in range(2):
    f=int(c)*((-1)**j)
    ans+=f
    y=o[j]
    for k in range(2):
      g=int(d)*((-1)**k)
      ans+=g
      z=o[k]
      #print(a+x+b+y+c+z+d+'='+str(ans),int(a)+e+f+g)
      if ans==7:
        print(a+x+b+y+c+z+d+'=7')
        exit()
      ans=int(a)

Fixed code:
s=input()
a,b,c,d=s[0],s[1],s[2],s[3]
e=int(a)
o=['+','-']
p=[1,int(-1)]
x,y,z='','',''
ans,f,g,h=0,0,0,0
for i in range(2):
  f=int(b)*((-1)**i)
  x=o[i]
  for j in range(2):
    g=int(c)*((-1)**j)
    y=o[j]
    for k in range(2):
      h=int(d)*((-1)**k)
      z=o[k]
      ans=e+f+g+h
      #print(a+x+b+y+c+z+d+'='+str(ans),e+f+g+h)
      if ans==7:
        print(a+x+b+y+c+z+d+'=7')
        exit()
      ans=0
Buggy code:
A, B, C, D = [int(s) for s in input()]


def exec(x, y, op):
    if op == '+':
        return x + y
    else:
        return x - y

for op1 in ['+', '-']:
    for op2 in ['+', '-']:
        for op3 in ['+', '-']:
            if exec(exec(exec(A, B, op1), C, op2), D, op3) == 7:
                print('{A}{op1}{B}{op2}{C}{op3}{D}=7'.format(
                    A=A,
                    B=B,
                    C=C,
                    D=D,
                    op1=op1,
                    op2=op2,
                    op3=op3
                ))
                break


Fixed code:
A, B, C, D = [int(s) for s in input()]


def exec(x, y, op):
    if op == '+':
        return x + y
    else:
        return x - y

for op1 in ['+', '-']:
    for op2 in ['+', '-']:
        for op3 in ['+', '-']:
            if exec(exec(exec(A, B, op1), C, op2), D, op3) == 7:
                print('{A}{op1}{B}{op2}{C}{op3}{D}=7'.format(
                    A=A,
                    B=B,
                    C=C,
                    D=D,
                    op1=op1,
                    op2=op2,
                    op3=op3
                ))
                exit()
Buggy code:
abcd=list(input())
for i in range(2**3):
    if i%8==0:
        op1="+"
    else:
        op1="-"
    if i%4==0:
        op2="+"
    else:
        op2="-"
    if i%2==0:
        op3="+"
    else:
        op3="-"
    siki=abcd[0]+op1+abcd[1]+op2+abcd[2]+op3+abcd[3]
    if eval(siki)==7:
        siki+="=7"
        break
print(siki)


Fixed code:
abcd=list(input())
for i in range(2**3):
    if i//4==0:
        op1="+"
    else:
        op1="-"
    i=i%4
    if i//2==0:
        op2="+"
    else:
        op2="-"
    i=i%2
    if i==0:
        op3="+"
    else:
        op3="-"
    siki=abcd[0]+op1+abcd[1]+op2+abcd[2]+op3+abcd[3]
    if eval(siki)==7:
        siki+="=7"
        break
print(siki)
Buggy code:
abcd = input()
a = int(abcd[0])
b = int(abcd[1])
c = int(abcd[2])
d = int(abcd[3])

op = ["+", "-"]
for op1 in op:
    for op2 in op:
        for op3 in op:
            val = a
            if op1 == "+":
                val += b
            else:
                val -= b

            if op2 == "+":
                val += c
            else:
                val -= c

            if op3 == "+":
                val += d
            else:
                val -= d

            if val==7:
                print("{}{}{}{}{}{}{}=7".format(a,op1,b,op2,c,op3,d))
                return


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

op = ["+", "-"]
for op1 in op:
    for op2 in op:
        for op3 in op:
            val = a
            if op1 == "+":
                val += b
            else:
                val -= b
 
            if op2 == "+":
                val += c
            else:
                val -= c
 
            if op3 == "+":
                val += d
            else:
                val -= d
            
            if val==7:
                print("{}{}{}{}{}{}{}=7".format(a,op1,b,op2,c,op3,d))
                exit(0)
Buggy code:
A, B, C, D = (int(x) for x in input())

class Op(int):
  def __str__(self):
     return '-' if self < 0 else '+'
    
pm = (Op(1), Op(-1))    

for op1 in pm:
  for op2 in pm:
    for op3 in pm:
      if A + op1 * B + op2 * C + op3 * D == 7:
        print(''.join(str(x) for x in [A, op1, B, op2, C, op3, D]) + '=7')
        break
        

Fixed code:
A, B, C, D = (int(x) for x in input())

class Op(int):
  def __str__(self):
     return '-' if self < 0 else '+'
    
pm = (Op(1), Op(-1))    

def solve():
  for op1 in pm:
    for op2 in pm:
      for op3 in pm:
        if A + op1 * B + op2 * C + op3 * D == 7:
          print(''.join(str(x) for x in [A, op1, B, op2, C, op3, D]) + '=7')
          return

solve()
Buggy code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    otos=lambda x:"+" if x==1 else "-"
    abcd=int(input())
    abc,d=divmod(abcd,10)
    ab,c=divmod(abc,10)
    a,b=divmod(ab,10)
    for o1 in [1,-1]:
        for o2 in [1, -1]:
            for o3 in [1, -1]:
                s=a+o1*b+o2*c+o3*d
                if s==7:
                    ans=str(a)+otos(o1)+str(b)+otos(o2)+str(c)+otos(o3)+str(d)+"=7"
                    print(ans)
                    break

main()

Fixed code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    otos=lambda x:"+" if x==1 else "-"
    abcd=int(input())
    abc,d=divmod(abcd,10)
    ab,c=divmod(abc,10)
    a,b=divmod(ab,10)
    for o1 in [1,-1]:
        for o2 in [1, -1]:
            for o3 in [1, -1]:
                s=a+o1*b+o2*c+o3*d
                if s==7:
                    ans=str(a)+otos(o1)+str(b)+otos(o2)+str(c)+otos(o3)+str(d)+"=7"
                    print(ans)
                    exit()

main()
Buggy code:
abcd = input()

def train_ticket(flg,sum,op):
    if flg == 0:
        if train_ticket(flg + 1, sum, op + "+"):
            return True
        elif train_ticket(flg + 1, sum, op + "-"):
            return True
    if flg >= len(abcd):
        if operation(sum, op[-1], flg) == 7:
            print("".join([abcd[i] + op[i+1] for i in range(len(op) - 1)]) + abcd[-1])
            return True
        else:
            return False
    if train_ticket(flg + 1, operation(sum, op[-1], flg), op+"+"):
        return True
    elif train_ticket(flg + 1, operation(sum, op[-1], flg), op+"-"):
        return True

def operation(sum, op, flg):
    if op == "+":
        return sum + int(abcd[flg - 1])
    else:
        return sum - int(abcd[flg - 1])

train_ticket(0, 0, "")

Fixed code:
abcd = input()

def train_ticket(flg,sum,op):
    if flg == 0:
        if train_ticket(flg + 1, sum, op + "+"):
            return True
        elif train_ticket(flg + 1, sum, op + "-"):
            return True
    if flg >= len(abcd):
        if operation(sum, op[-1], flg) == 7:
            print("".join([abcd[i] + op[i+1] for i in range(len(op) - 1)]) + abcd[-1] + "=7")
            return True
        else:
            return False
    if train_ticket(flg + 1, operation(sum, op[-1], flg), op+"+"):
        return True
    elif train_ticket(flg + 1, operation(sum, op[-1], flg), op+"-"):
        return True

def operation(sum, op, flg):
    if op == "+":
        return sum + int(abcd[flg - 1])
    else:
        return sum - int(abcd[flg - 1])

train_ticket(0, 0, "")
Buggy 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)
            exit()
    else:
        dfs(i+1, f + '+' + str(s[i]), sum + s[i])
        dfs(i+1, f + '-' + str(s[i]), sum - s[i])
dfs(0, str(s[0]), s[0])


Fixed 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])
Buggy code:
abcd = str(input())
a = abcd[0]
b = abcd[1]
c = abcd[2]
d = abcd[3]

sign = ['+', '-']
for i in range(2):
    for j in range(2):
        for k in range(2):
            tmp = a + sign[i] + b + sign[j] + c + sign[k] + d  
            if eval(tmp) == 7:
                print(tmp+'=7')

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

sign = ['+', '-']
for i in range(2):
    for j in range(2):
        for k in range(2):
            tmp = a + sign[i] + b + sign[j] + c + sign[k] + d  
            if eval(tmp) == 7:
                print(tmp+'=7')
                exit()