qyliang/CodeNanoFix huggingface dataset:
Buggy code:
A, B, C, D = input()

op = ['+', '-']

for i in op:
    tmp = A + i + B
    for j in op:
        tmp += j + C
        for k in op:
            tmp += k + D
            if eval(tmp) == 7:
                print(tmp + '=7')
                exit()

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

op = ['+', '-']

for i in op:
    for j in op:
        for k in op:
            f = A + i + B + j + C + k + D
            if eval(f) == 7:
                print(f + '=7')
                exit()
Buggy code:
a=input()
def dfs(i,s,l):
    if i==3:
        if s==7:
            print(l+'=7')
    else:
        dfs(i+1,s+int(a[i+1]),l+'+'+a[i+1])
        dfs(i+1,s-int(a[i+1]),l+'-'+a[i+1])

dfs(dfs(0,int(a[0]),a[0]))

Fixed code:
a=input()
def dfs(i,s,l):
    if i==3:
        if s==7:
            print(l+'=7')
            exit()
    else:
        dfs(i+1,s+int(a[i+1]),l+'+'+a[i+1])
        dfs(i+1,s-int(a[i+1]),l+'-'+a[i+1])

dfs(dfs(0,int(a[0]),a[0]))
Buggy code:
A, B, C, D = map(int, input())
for i in range(8):
    sum = 0
    op1 = "+" if i // 4 % 2 == 0 else "-"
    op2 = "+" if i // 2 % 2 == 0 else "-"
    op3 = "+" if i % 2 == 0 else "-"
    if op1 == "+":
        sum = A + B
    else:
        sum = A - B
    if op2 == "+":
        sum += C
    else:
        sum -= C
    if op3 == "+":
        sum += D
    else:
        sum -= D
    if sum == 7:
        print(str(A) + op1 + str(B) + op2 + str(C) + op3 + str(D))
        break

Fixed code:
A, B, C, D = map(int, input())
for i in range(8):
    sum = 0
    op1 = "+" if i // 4 % 2 == 0 else "-"
    op2 = "+" if i // 2 % 2 == 0 else "-"
    op3 = "+" if i % 2 == 0 else "-"
    if op1 == "+":
        sum = A + B
    else:
        sum = A - B
    if op2 == "+":
        sum += C
    else:
        sum -= C
    if op3 == "+":
        sum += D
    else:
        sum -= D
    if sum == 7:
        print(str(A) + op1 + str(B) + op2 + str(C) + op3 + str(D) + "=7")
        break
Buggy code:
import itertools
n = input()
x, pm, a = [], [1,-1], 7-int(n[0])
for i in range(1,4):
	x.append(int(n[i]))
for j in itertools.product(pm,repeat=3):
	if x[0]*j[0]+x[1]*j[1]+x[2]*j[2]==a:
		y = j
		break
for k in range(3):
	if y[k]==1: y[k] = "+"
	else: y[k] = "-"
print(n[0]+y[0]+n[1]+y[1]+n[2]+y[2]+n[3]+"=7")

Fixed code:
import itertools
n = input()
x, pm, a = [], [1,-1], 7-int(n[0])
for i in range(1,4):
	x.append(int(n[i]))
for j in itertools.product(pm,repeat=3):
	if x[0]*j[0]+x[1]*j[1]+x[2]*j[2]==a:
		y = list(j)
		break
for k in range(3):
	if y[k]==1:
		y[k] = "+"
	else:
		y[k] = "-"
print(n[0]+y[0]+n[1]+y[1]+n[2]+y[2]+n[3]+"=7")
Buggy code:
s=list(input())

from itertools import product as pr

p = list(pr(['+','-'],repeat=3))

for ope in p:
    f = s[0] + ope[0] + s[1] + ope[2] + s[2] + ope[2] + s[3]

    if eval(f)==7:
        print(f+'=7')
        exit(0)



Fixed code:
s=list(input())

from itertools import product as pr

p = list(pr(['+','-'],repeat=3))

for ope in p:
    f = s[0] + ope[0] + s[1] + ope[1] + s[2] + ope[2] + s[3]

    if eval(f)==7:
        print(f+'=7')
        exit(0)
Buggy code:
A = list(input())
A = [int(i) for i in A]

if sum(A) == 7:
    print("{}+{}+{}+{}=7".format(A[0],A[1],A[2],A[3]))
elif A[0]+A[1]+A[1]-A[2] == 7:
    print("{}+{}+{}-{}=7".format(A[0],A[1],A[2],A[3]))
elif A[0]+A[1]-A[1]+A[2] == 7:
    print("{}+{}-{}+{}=7".format(A[0],A[1],A[2],A[3]))
elif A[0]-A[1]+A[1]+A[2] == 7:
    print("{}-{}+{}+{}=7".format(A[0],A[1],A[2],A[3]))
elif A[0]+A[1]-A[1]-A[2] == 7:
    print("{}+{}-{}-{}=7".format(A[0],A[1],A[2],A[3]))
elif A[0]-A[1]+A[1]-A[2] == 7:
    print("{}-{}+{}-{}=7".format(A[0],A[1],A[2],A[3]))
elif A[0]-A[1]-A[1]+A[2] == 7:
    print("{}-{}-{}+{}=7".format(A[0],A[1],A[2],A[3]))
else:
    print("{}-{}-{}-{}=7".format(A[0],A[1],A[2],A[3]))


Fixed code:
A = list(input())
A = [int(i) for i in A]

if sum(A) == 7:
    print("{}+{}+{}+{}=7".format(A[0],A[1],A[2],A[3]))
elif A[0]+A[1]+A[2]-A[3] == 7:
    print("{}+{}+{}-{}=7".format(A[0],A[1],A[2],A[3]))
elif A[0]+A[1]-A[2]+A[3] == 7:
    print("{}+{}-{}+{}=7".format(A[0],A[1],A[2],A[3]))
elif A[0]-A[1]+A[2]+A[3] == 7:
    print("{}-{}+{}+{}=7".format(A[0],A[1],A[2],A[3]))
elif A[0]+A[1]-A[2]-A[3] == 7:
    print("{}+{}-{}-{}=7".format(A[0],A[1],A[2],A[3]))
elif A[0]-A[1]+A[2]-A[3] == 7:
    print("{}-{}+{}-{}=7".format(A[0],A[1],A[2],A[3]))
elif A[0]-A[1]-A[2]+A[3] == 7:
    print("{}-{}-{}+{}=7".format(A[0],A[1],A[2],A[3]))
else:
    print("{}-{}-{}-{}=7".format(A[0],A[1],A[2],A[3]))
Buggy code:
def dfs(i, f, Sum):
    if i == n-1:
        if Sum == 7:
            print(f+"=7")
    else:
        dfs(i+1, f+"+"+a[i+1], Sum + int(a[i+1]))
        dfs(i+1, f+"-"+a[i+1], Sum - int(a[i+1]))
        

a = input()
n = len(a)

dfs(0, a[0], int(a[0]))

Fixed code:
def dfs(i, f, Sum):
    if i == n-1:
        if Sum == 7:
            print(f+"=7")
            exit()
    else:
        dfs(i+1, f+"+"+a[i+1], Sum + int(a[i+1]))
        dfs(i+1, f+"-"+a[i+1], Sum - int(a[i+1]))
        

a = input()
n = len(a)

dfs(0, a[0], int(a[0]))
Buggy code:
s = input()
def dfs(i,f,sum):
  if i == 3:
    if sum == 7:
      print(f + "=7")
      exit()
  dfs(i+1,f + "+" + s[i+1],sum+int(s[i+1]))
  dfs(i+1,f + "-" + s[i+1],sum-int(s[i+1]))
dfs(0,s[0],int(s[0]))

Fixed code:
s = input()
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]))
dfs(0,s[0],int(s[0]))
Buggy code:
import sys
s=input()
opt = ["+","-"]
for opt1 in opt:
    for opt2 in opt:
        for opt3 in opt:
            equation = s[0]+opt1+s[1]+opt2+s[2]+opt3+s[3]
            if  eval(equation) == 7:
                print(equation)
                sys.exit()

Fixed code:
import sys
s=input()
opt = ["+","-"]
for opt1 in opt:
    for opt2 in opt:
        for opt3 in opt:
            equation = s[0]+opt1+s[1]+opt2+s[2]+opt3+s[3]
            if  eval(equation) == 7:
                print(equation+"=7")
                sys.exit()
Buggy code:
#input
S = list(input())
for i in range(len(S)):
    S[i] = int(S[i])
#print(S)
L = len(S)
fugou = []

#bit zentansaku
for i in range(2**(L-1)):
    total = S[0]
    #bin_i = bin(i)
    moji = format(i,'b').zfill(4)
    #print(moji)
    for k in range(1,L):
        #print(moji[k])
        if int(moji[k]) == 1:
            total = total + S[k]
        else:
            total = total - S[k]
        #print(total)
    if total == 7:
        moji_answer = moji
print(moji_answer)
#print
for i in range(1,L):
    if int(moji_answer[i]) == 1:
        fugou_tandoku = "+"
    else:
        fugou_tandoku = "-"
    fugou.append(fugou_tandoku)
print(S[0],fugou[0],S[1],fugou[1],S[2],fugou[2],S[3],'=7',sep='')

Fixed code:
#input
S = list(input())
for i in range(len(S)):
    S[i] = int(S[i])
#print(S)
L = len(S)
fugou = []

#bit zentansaku
for i in range(2**(L-1)):
    total = S[0]
    #bin_i = bin(i)
    moji = format(i,'b').zfill(4)
    #print(moji)
    for k in range(1,L):
        #print(moji[k])
        if int(moji[k]) == 1:
            total = total + S[k]
        else:
            total = total - S[k]
        #print(total)
    if total == 7:
        moji_answer = moji
#print(moji_answer)
#print
for i in range(1,L):
    if int(moji_answer[i]) == 1:
        fugou_tandoku = "+"
    else:
        fugou_tandoku = "-"
    fugou.append(fugou_tandoku)
print(S[0],fugou[0],S[1],fugou[1],S[2],fugou[2],S[3],'=7',sep='')
Buggy code:
from itertools import product
S = input()

for string in product(["+","-"],repeat = 3):
    string = list(string)
    string.append("")
    sum_ = [a + b for a,b in zip(S,string)]
    if eval("".join(sum_)) == 7:
        print("".join(sum_),"=7")
        break

Fixed code:
from itertools import product
S = input()

for string in product(["+","-"],repeat = 3):
    string = list(string)
    string.append("")
    sum_ = [a + b for a,b in zip(S,string)]
    if eval("".join(sum_)) == 7:
        print("".join(sum_)+"=7")
        break
Buggy code:
a,b,c,d = map(int,list(input()))
for i in range(2):
    if i==0:
        ans=a+b
    else:
        ans=a-b
    for j in range(2):
        if j==0:
            ans+=c
        else:
            ans-=c
        for k in range(2):
            if k==0:
                ans+=d
            else:
                ans-=d
            if ans==7:
                ret=[i,j,k]
for i in range(len(ret)):
    if ret[i]==0:
        ret[i]='+'
    else:
        ret[i]='-'
print('{}{}{}{}{}{}{}=7'.format(a,ret[0],b,ret[1],c,ret[2],d))


Fixed code:
a,b,c,d = map(int,list(input()))
for i in range(2):
    if i==0:
        ans=a+b
    else:
        ans=a-b
    r1=ans
    for j in range(2):
        ans=r1
        if j==0:
            ans+=c
        else:
            ans-=c
        r2=ans
        for k in range(2):
            ans=r2
            if k==0:
                ans+=d
            else:
                ans-=d
            if ans==7:
                ret=[i,j,k]
                for i in range(len(ret)):
                    if ret[i]==0:
                        ret[i]='+'
                    else:
                        ret[i]='-'
                print('{}{}{}{}{}{}{}=7'.format(a,ret[0],b,ret[1],c,ret[2],d))
                exit()
Buggy code:
a,b,c,d = list(map(int,list(input())))

def myprint(c1,c2,c3):
    return print(str(a)+c1+str(b)+c2+str(c)+c3+str(d)+'=7')

if a+b+c+d==7:
    myprint('+','+','+')
if a+b+c-d==7:
    myprint('+','+','-')
if a+b-c+d==7:
    myprint('+','-','+')
if a+b-c-d==7:
    myprint('+','-','-')
if a-b+c+d==7:
    myprint('-','+','+')
if a-b+c-d==7:
    myprint('-','+','-')
if a-b-c+d==7:
    myprint('-','-','+')
if a-b-c-d==7:
    myprint('-','-','-')

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

def myprint(c1,c2,c3):
    return print(str(a)+c1+str(b)+c2+str(c)+c3+str(d)+'=7')

if a+b+c+d==7:
    myprint('+','+','+')
elif a+b+c-d==7:
    myprint('+','+','-')
elif a+b-c+d==7:
    myprint('+','-','+')
elif a+b-c-d==7:
    myprint('+','-','-')
elif a-b+c+d==7:
    myprint('-','+','+')
elif a-b+c-d==7:
    myprint('-','+','-')
elif a-b-c+d==7:
    myprint('-','-','+')
elif a-b-c-d==7:
    myprint('-','-','-')
Buggy code:
a, b, c, d = input()
a = int(a)
b = int(b)
c = int(c)
d = int(d)

result = a
output = ""

def ope(i):
    if i == 0:
        return "+"
    else:
        return "-"

for i in range(2):
    if output != "":
        break
    for j in range(2):
        if output != "":
            break
        for k in range(2):
            if i == 0:
                result += b
            else:
                result -= b
            if j == 0:
                result += c
            else:
                result -= c
            if k == 0:
                result += d
            else:
                result -= d
            if result == 7:
                output = "{}{}{}{}{}{}{}=7".format(a, ope(i), b, ope(j), c, ope(k), d)
                break

print(output)


Fixed code:
a, b, c, d = input()
a = int(a)
b = int(b)
c = int(c)
d = int(d)
output = ""

def ope(i):
    if i == 0:
        return "+"
    else:
        return "-"

for i in range(2):
    if output != "":
        break
    for j in range(2):
        if output != "":
            break
        for k in range(2):
            result = a
            if i == 0:
                result += b
            else:
                result -= b
            if j == 0:
                result += c
            else:
                result -= c
            if k == 0:
                result += d
            else:
                result -= d
            if result == 7:
                output = "{}{}{}{}{}{}{}=7".format(a, ope(i), b, ope(j), c, ope(k), d)
                break

print(output)
Buggy code:
# coding: utf-8
# Your code here!

import numpy as np
li=np.array(list(map(int,list(input()))))
wa=[
   [1,1,1,1],
   [1,1,1,-1],
   [1,1,-1,1],
   [1,1,-1,-1],
   [1,-1,1,1],
   [1,-1,1,-1],
   [1,-1,-1,1],
   [1,-1,-1,-1],
   [-1,1,1,1],
   [-1,1,1,-1],
   [-1,1,-1,1],
   [-1,1,-1,-1],
   [-1,-1,1,1],
   [-1,-1,1,-1],
   [-1,-1,-1,1],
   [-1,-1,-1,-1],
  ]
wa=np.array(wa)
for w in wa:
  if np.dot(w,li)==7:
    isfirst=True
    for p,i in zip(w,range(4)):
        if isfirst:
            print(li[0],end='')
            isfirst=False
            continue
        if p >0:
            print('+',end=str(li[i]))
        else:
            print('+',end=str(li[i]))
    print('=7')
    quit()


Fixed code:
# coding: utf-8
# Your code here!

import numpy as np
li=np.array(list(map(int,list(input()))))
wa=[
   [1,1,1,1],
   [1,1,1,-1],
   [1,1,-1,1],
   [1,1,-1,-1],
   [1,-1,1,1],
   [1,-1,1,-1],
   [1,-1,-1,1],
   [1,-1,-1,-1],
   [-1,1,1,1],
   [-1,1,1,-1],
   [-1,1,-1,1],
   [-1,1,-1,-1],
   [-1,-1,1,1],
   [-1,-1,1,-1],
   [-1,-1,-1,1],
   [-1,-1,-1,-1],
  ]
wa=np.array(wa)
for w in wa:
  if np.dot(w,li)==7:
    isfirst=True
    for p,i in zip(w,range(4)):
        if isfirst:
            print(li[0],end='')
            isfirst=False
            continue
        if p >0:
            print('+',end=str(li[i]))
        else:
            print('-',end=str(li[i]))
    print('=7')
    quit()
Buggy code:
a,b,c,d = list(input())
sign = '+-'
for i in range(2):
    for j in range(2):
        for k in range(2):
            if eval(a+sign[i]+b+sign[j]+c+sign[k]+d) == 7:
                print(a+sign[i]+b+sign[j]+c+sign[k]+d + '==7')

Fixed code:
a,b,c,d = list(input())
sign = '+-'
for i in range(2):
    for j in range(2):
        for k in range(2):
            if eval(a+sign[i]+b+sign[j]+c+sign[k]+d) == 7:
                print(str(a+sign[i]+b+sign[j]+c+sign[k]+d) + '=7')
                exit()
Buggy code:
a, b, c, d = list( input())

op = ['+','-']

for i in op :
  for j  in op :
    for k in op :
      if eval( a+ i + b + j + c + k +d) == 7 :
        print('a{}b{}c{}d == 7'.format( i, j, k))
        exit()

Fixed code:
a, b, c, d = list( input())
 
op = ['+','-']
 
for i in op :
  for j  in op :
    for k in op :
      if eval( a+ i + b + j + c + k +d) == 7 :
        print('{}{}{}{}{}{}{}=7'.format( a,i, b,j,c,k,d))
        exit()
Buggy code:
B=input()
A=[]
for i in B:
    A.append(i)



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

Fixed code:
B=input()
A=[]
for i in B:
    A.append(i)



for i in ["+","-"]:
    for j in ["+","-"]:
        for k in ["+","-"]:
            if(eval(A[0]+i+A[1]+j+A[2]+k+A[3])==7):
                print(A[0]+i+A[1]+j+A[2]+k+A[3]+"=7")
                exit()
Buggy code:
# -*- coding: utf-8 -*-
A,B,C,D = list(map(int, list(input())))

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')
elif A-B-C-D == 7:
    print('A-B-C-D=7')



Fixed code:
# -*- coding: utf-8 -*-
A,B,C,D = list(map(int, list(input())))

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')
Buggy code:
def main():
    (A,B,C,D) = map(int, input())
    operation = ['+','-']
    for op1 in operation:
        sum = A
        if op1=='+':
            sum+=B
        else:
            sum-=B
        for op2 in operation:
            if op1=='+':
                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()


Fixed 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()
Buggy code:
array = [int(i) for i in list(input())]
flag = False
fugou = ['+', '-']

for i in fugou:
	if i == '+':
		tmp = array[0] + array[1]
	else:
		tmp = array[0] - array[1]
	for j in fugou:
		if j == '+':
			tmp2 = tmp + array[2]
		else:
			tmp2 = tmp - array[2]
		for k in fugou:
			if k == '+':
				if tmp2 + array[3] == 7:
					print(str(array[0])
							+ i + str(array[1])
							+ j + str(array[2])
							+ k + str(array[3]))
					flag = True
					break
			else:
				if tmp2 - array[3] == 7:
					print(str(array[0])
							+ i + str(array[1])
							+ j + str(array[2])
							+ k + str(array[3]))
					flag = True
					break
		if flag: break
	if flag: break

Fixed code:
array = [int(i) for i in list(input())]
flag = False
fugou = ['+', '-']

for i in fugou:
	if i == '+':
		tmp = array[0] + array[1]
	else:
		tmp = array[0] - array[1]
	for j in fugou:
		if j == '+':
			tmp2 = tmp + array[2]
		else:
			tmp2 = tmp - array[2]
		for k in fugou:
			if k == '+':
				if tmp2 + array[3] == 7:
					print(str(array[0])
							+ i + str(array[1])
							+ j + str(array[2])
							+ k + str(array[3])
							+ '=7')
					flag = True
					break
			else:
				if tmp2 - array[3] == 7:
					print(str(array[0])
							+ i + str(array[1])
							+ j + str(array[2])
							+ k + str(array[3])
							+ '=7')
					flag = True
					break
		if flag: break
	if flag: break
Buggy code:
S = str(input())
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])


for i in range(0,2):
    for j in range(0,2):
        for k in range(0,2):
            ans = ''
            if i == 0:
                AB = A + B
                ans += str(A) + '+' + str(B)
            elif i == 1:
                AB = A - B
                ans += str(A) + '-' + str(B)
            if j == 0:
                ABC = AB + C
                ans += '+' + str(C)
            elif j == 1:
                ABC = AB - C
                ans += '-' + str(C)
            if k == 0:
                ABCD = ABC + D
                ans += '+' + str(D)
            elif j == 1:
                ABCD = ABC - D
                ans += '-' + str(D)
            if ABCD == 7:
                ans += '=7'
                print(ans)
                quit()

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


for i in range(0, 2):
    for j in range(0, 2):
        for k in range(0, 2):
            ans = ''
            if i == 0:
                AB = A + B
                ans += str(A) + '+' + str(B)
            else:
                AB = A - B
                ans += str(A) + '-' + str(B)
            if j == 0:
                ABC = AB + C
                ans += '+' + str(C)
            else:
                ABC = AB - C
                ans += '-' + str(C)
            if k == 0:
                ABCD = ABC + D
                ans += '+' + str(D)
            else:
                ABCD = ABC - D
                ans += '-' + str(D)
            if ABCD == 7:
                ans += '=7'
                print(ans)
                quit()
Buggy code:
s = input()

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

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

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

Fixed code:
s = input()

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

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

print(dfs(0,s[0],int(s[0])))
Buggy code:
A,B,C,D = input()
op = ["+","-"]

for i in op:
  for j in op:
    for k in op:
      ans = A+i+B+j+C+k+D
      if eval(ans)==7:
        print(ans+"=7")
        break

Fixed code:
A,B,C,D = input()
op = ["+","-"]

for i in op:
  for j in op:
    for k in op:
      ans = A+i+B+j+C+k+D
      if eval(ans)==7:
        print(ans+"=7")
        exit()
Buggy code:
A,B,C,D =input();
E ="+-"

for i in E:
  for j in E:
    for k in E:
      s=A+i+B+j+C+k+D
      if eval(s)==7:
        print(s+"=7")
		exit()

Fixed code:
A,B,C,D =input()
E ="+-"

for i in E:
  for j in E:
    for k in E:
      s=A+i+B+j+C+k+D
      if eval(s)==7:
        print(s+"=7")
        exit()
Buggy code:
D = input()

ops = []
for i in range(1 << 3):
    op = ""
    xx = bin(i)[2::].zfill(3)
    for x in xx:
        if x=="0":
            op += "+"
        else:
            op += "-"
    ops.append(op)

for op in ops:
    res = D[0]
    for i in range(3):
        res += op[i]+D[i+1]
    if eval(res)==7:
        print(res)
        break


Fixed code:
D = input()

ops = []
for i in range(1 << 3):
    op = ""
    xx = bin(i)[2::].zfill(3)
    for x in xx:
        if x=="0":
            op += "+"
        else:
            op += "-"
    ops.append(op)

for op in ops:
    res = D[0]
    for i in range(3):
        res += op[i]+D[i+1]
    if eval(res)==7:
        print(res + "=7")
        break
Buggy code:
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    *S, = iss()
    print(S)
    E = ['+', '-']
    tmp = [0] * 7
    for e in E:
        tmp[0] = S[0]
        tmp[1] = e
        for e in E:
            tmp[2] = S[1]
            tmp[3] = e
            for e in E:
                tmp[4] = S[2]
                tmp[5] = e
                tmp[6] = S[3]
                ans = ''.join(map(str, tmp))
                if eval(ans) == 7:
                    print(ans + '=7')
                    exit()


if __name__ == '__main__':
    main()


Fixed code:
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    *S, = iss()
    E = ['+', '-']
    tmp = [0] * 7
    for e in E:
        tmp[0] = S[0]
        tmp[1] = e
        for e in E:
            tmp[2] = S[1]
            tmp[3] = e
            for e in E:
                tmp[4] = S[2]
                tmp[5] = e
                tmp[6] = S[3]
                ans = ''.join(map(str, tmp))
                if eval(ans) == 7:
                    print(ans + '=7')
                    exit()


if __name__ == '__main__':
    main()