qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import sys
import  math
from statistics import *
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

a, b, c, d = input()
li = ["+", "-"]
def calc(a, b, c, d):
    s = 0
    for i in range(2):
        if i == 0:
            s = a + b
        else:
            s = a - b
        for j in range(2):
            if j == 0:
                s += c
            else:
                s -= c
            for k in range(2):
                if k == 0:
                    s += d
                else:
                    s -= d
                if s == 7:
                    print(str(a) + li[i] + str(b) + li[j] + str(c) + li[k] + str(d) + "=7")
                    return
calc(int(a),int(b), int(c), int(d))


Fixed code:
import sys
import  math
from statistics import *
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

a, b, c, d = input()
li = ["+", "-"]
def calc(a, b, c, d):
    for i in range(2):
        if i == 0:
            e = a + b
        else:
            e = a - b
        for j in range(2):
            if j == 0:
                f = e + c
            else:
                f = e - c
            for k in range(2):
                if k == 0:
                    g = f + d
                else:
                    g = f - d
                if g == 7:
                    print(str(a) + li[i] + str(b) + li[j] + str(c) + li[k] + str(d) + "=7")
                    return
calc(int(a),int(b), int(c), int(d))
Buggy code:
#!/usr/bin/env python
import itertools
input_str = input()
print(input_str)
A = input_str[0]
B = input_str[1]
C = input_str[2]
D = input_str[3]

ops = ['+', '-']
all_ops = list(itertools.product(A, ops, B, ops, C, ops, D))
for tmp in all_ops:
    result = eval(''.join(tmp))
    if result == 7:
        print(''.join(tmp) + "=7")
        break


Fixed code:
#!/usr/bin/env python
import itertools
input_str = input()
A = input_str[0]
B = input_str[1]
C = input_str[2]
D = input_str[3]

ops = ['+', '-']
all_ops = list(itertools.product(A, ops, B, ops, C, ops, D))
for tmp in all_ops:
    result = eval(''.join(tmp))
    if result == 7:
        print(''.join(tmp) + "=7")
        break
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:
                break
print(ans + "=7")

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:
import itertools

S=input()

for i in itertools.product(["+","-"],repeat=3):
    ans=""
    for j in range(len(i)):
        if i[j]=="+":
            ans+=S[j]+i[j]
        elif i[j]=="-":
            ans+=S[j]+i[j]
    ans+=S[-1]
    sum_num=eval(ans)
    if sum_num==7:
        print(ans+"=0")
        break


Fixed code:
import itertools

S=input()

for i in itertools.product(["+","-"],repeat=3):
    ans=""
    for j in range(len(i)):
        if i[j]=="+":
            ans+=S[j]+i[j]
        elif i[j]=="-":
            ans+=S[j]+i[j]
    ans+=S[-1]
    sum_num=eval(ans)
    if sum_num==7:
        print(ans+"=7")
        break
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:
    ans = A+B if op1 == '+' else A-B
    for op2 in op:
        ans = ans+C if op2 == '+' else ans-C
        for op3 in op:
            ans = ans+D if op3 == '+' else ans-D
            if ans == 7:
                print(str(A)+op1+str(B)+op2+str(C)+op3+str(D)+'=7')
                exit()

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:
            ans = 0
            ans = A+B if op1 == '+' else A-B
            ans = ans+C if op2 == '+' else ans-C
            ans = ans+D if op3 == '+' else ans-D
            if ans == 7:
                print(str(A)+op1+str(B)+op2+str(C)+op3+str(D)+'=7')
                exit()
Buggy code:
import numpy as np
import sys
import math

s=input()
t=[]
for i in range(4):
    t.append(int(s[i]))
temp=0
for i in range(2):
    temp+=(t[0]+t[1] if i==0 else t[0]-t[1])
    for j in range(2):
        temp+=(t[2] if j==0 else -t[2])
        for k in range(2):
            temp+=(t[3] if k==0 else -t[3])
            if temp==7:
                print(s[0]+('+' if i==0 else '-')+s[1]+('+' if j==0 else '-')+s[2]+('+' if k==0 else '-')+s[3]+'=7')
                sys.exit()
            else:
                temp=0

Fixed code:
import numpy as np
import sys
import math

s=input()
t=[]
for i in range(4):
    t.append(int(s[i]))
temp=0
for i in range(2):
    temp+=(t[0]+t[1] if i==0 else t[0]-t[1])
    for j in range(2):
        temp+=(t[2] if j==0 else -t[2])
        for k in range(2):
            temp+=(t[3] if k==0 else -t[3])
            if temp==7:
                print(s[0]+('+' if i==0 else '-')+s[1]+('+' if j==0 else '-')+s[2]+('+' if k==0 else '-')+s[3]+'=7')
                sys.exit()
            else:
                temp-=(t[3] if k==0 else -t[3])
        temp-=(t[2] if j==0 else -t[2])
    temp=0
Buggy code:
In = [int(x) for x in input()]
BREAK = False
for i in range(2):
  for j in range(2):
    for k in range(2):
      s = In[0]
      if i == 0:
        s += In[1]
      else:
        s -= In[1]
      if j == 0:
        s += In[2]
      else:
        s -= In[2]
      if k == 0:
        s += In[3]
      else:
        s -= In[3]
      if s == 7:
        BREAK = True
        break
    if BREAK:
      break
  if BREAK:
    break
Out = str(In[0])
m = 1
for l in [i, j, k]:
  if l % 2:
    Out += "+" + str(In[m])
  else:
    Out += "-" + str(In[m])
  m += 1
print(Out)
                       


Fixed code:
In = [int(x) for x in input()]
BREAK = False
for i in range(2):
  for j in range(2):
    for k in range(2):
      s = In[0]
      if i == 0:
        s += In[1]
      else:
        s -= In[1]
      if j == 0:
        s += In[2]
      else:
        s -= In[2]
      if k == 0:
        s += In[3]
      else:
        s -= In[3]
      if s == 7:
        BREAK = True
        break
    if BREAK:
      break
  if BREAK:
    break
Out = str(In[0])
m = 1
for l in [i, j, k]:
  if l % 2:
    Out += "-" + str(In[m])
  else:
    Out += "+" + str(In[m])
  m += 1
print(Out + "=7")
Buggy code:
#!/usr/bin/env python3

s = input()

def dfs(i, n, ns):
    if i == 3:
        if n == 7:
            print(ns + '=7')
            return
        else:
            return

    dfs(i+1, n + int(s[i+1]), ns + '+' + s[i+1])
    dfs(i+1, n - int(s[i+1]), ns + '-' + s[i+1]) 


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

Fixed code:
#!/usr/bin/env python3

s = input()
ans = []

def dfs(i, n, ns):
    if i == 3:
        if n == 7:
            ans.append(ns + '=7')
            return 
        else:
            return

    dfs(i+1, n + int(s[i+1]), ns + '+' + s[i+1])
    dfs(i+1, n - int(s[i+1]), ns + '-' + s[i+1]) 


dfs(0, int(s[0]), s[0])
print(ans[0])
Buggy code:
import sys

n = input()

code_1 = ['+', '-']
code_2 = ['+', '-']
code_3 = ['+', '-']

answer = ''
flag = False
for i in range(2):
    for j in range(2):
        for k in range(2):
            sum_num = 0
            if code_1[i] == '+':
                sum_num += int(n[0]) + int(n[1])
            else:
                sum_num += int(n[0]) - int(n[1])
            if code_2[j] == '+':
                sum_num += int(n[2])
            else:
                sum_num -= int(n[2])
            if code_3[k] == '+':
                sum_num += int(n[3])
            else:
                sum_num -= int(n[3])
            if sum_num == 7:
                answer = n[0] + code_1[i] + n[1] + code_2[j] + n[2] + code_3[k] + n[3]
                flag = True
            if flag:
                break

        if flag:
            break
    
    if flag:
        break


print(answer)



Fixed code:
import sys

n = input()

code_1 = ['+', '-']
code_2 = ['+', '-']
code_3 = ['+', '-']

answer = ''
flag = False
for i in range(2):
    for j in range(2):
        for k in range(2):
            sum_num = 0
            if code_1[i] == '+':
                sum_num += int(n[0]) + int(n[1])
            else:
                sum_num += int(n[0]) - int(n[1])
            if code_2[j] == '+':
                sum_num += int(n[2])
            else:
                sum_num -= int(n[2])
            if code_3[k] == '+':
                sum_num += int(n[3])
            else:
                sum_num -= int(n[3])
            if sum_num == 7:
                answer = n[0] + code_1[i] + n[1] + code_2[j] + n[2] + code_3[k] + n[3] + '=7'
                flag = True
            if flag:
                break

        if flag:
            break
    
    if flag:
        break


print(answer)
Buggy code:
inp=input()
a,b,c,d=[int(i) for i in inp]

for i in range(8):
    calc=a
    B=bin(i)[2:].zfill(3)
    print(B)
    calc=calc+b if B[0]=="0" else calc-b
    calc=calc+c if B[1]=="0" else calc-c
    calc=calc+d if B[2]=="0" else calc-d
    if calc==7:
        break

Operator=["+" if i=="0" else "-" for i in B]
Operator.append("=7")
ans=""
for num, op in zip([a,b,c,d], Operator):
    ans+=str(num)
    ans+=op
print(ans)


Fixed code:
inp=input()
a,b,c,d=[int(i) for i in inp]

for i in range(8):
    calc=a
    B=bin(i)[2:].zfill(3)
    calc=calc+b if B[0]=="0" else calc-b
    calc=calc+c if B[1]=="0" else calc-c
    calc=calc+d if B[2]=="0" else calc-d
    if calc==7:
        break

Operator=["+" if i=="0" else "-" for i in B]
Operator.append("=7")
ans=""
for num, op in zip(inp, Operator):
    ans+=num
    ans+=op
print(ans)
Buggy code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

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

for i in ('+', '-'):
    val = A
    for j in ('+', '-'):
        for k in ('+', '-'):
            if i=='+':
                val += B
            else:
                val -= B
            if j=='+':
                val += C
            else:
                val -= C
            if k=='+':
                val += D
            else:
                val -= D
            
            if val==7:
                print('{}{}{}{}{}{}{}=7'.format(A, i, B, j, C, k, D))
                exit()

Fixed code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

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

for i in ('+', '-'):
    for j in ('+', '-'):
        for k in ('+', '-'):
            val = A
            if i=='+':
                val += B
            else:
                val -= B

            if j=='+':
                val += C
            else:
                val -= C

            if k=='+':
                val += D
            else:
                val -= D
            
            if val==7:
                print('{}{}{}{}{}{}{}=7'.format(A, i, B, j, C, k, D))
                exit()
Buggy code:
s = input()

def dfs(i,sen,num):
    if i == 3:
        if num == 7:
            print(sen+"=7")
            quit()
    else:
        dfs(i+1,sen+"+"+s[i+1],num+int(s[i+1]))
        dfs(i+1,sen+"-"+s[i+1],num-int(s[i-1]))

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


Fixed code:
s = input()

def dfs(i,sen,num):
    if i == 3:
        if num == 7:
            print(sen+"=7")
            quit()
    else:
        dfs(i+1,sen+"+"+s[i+1],num+int(s[i+1]))
        dfs(i+1,sen+"-"+s[i+1],num-int(s[i+1]))

dfs(0,s[0],int(s[0]))
Buggy 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()


Fixed 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()
Buggy code:
# -*- coding: utf-8 -*-
from itertools import product
import sys
 
def main(A, B, C, D):
    for op1, op2, op3 in product(("+", "-"), repeat=3):
        e = A + op1 + B + op2 + C + op3 + D
        print(e)
        x = eval(e)
        if x == 7:
            print(e + "=7")
            sys.exit()
    
if(__name__ == "__main__"):
    A, B, C, D = list(input())
    
    main(A, B, C, D)

Fixed code:
# -*- coding: utf-8 -*-
from itertools import product
import sys
 
def main(A, B, C, D):
    for op1, op2, op3 in product(("+", "-"), repeat=3):
        e = A + op1 + B + op2 + C + op3 + D
        x = eval(e)
        if x == 7:
            print(e + "=7")
            sys.exit()
    
if(__name__ == "__main__"):
    A, B, C, D = list(input())
    
    main(A, B, C, D)
Buggy code:
l = list(input())
for i in range(8):
  s = int(l[0])
  b = bin(i)[2:].zfill(3)
  op = ["", "", ""]
  for j in range(len(b)):
    if b[j] == "0":
      s += int(l[j+1])
      op[j] = "+"
    else:
      s -= int(l[j+1])
      op[j] = "-"
  if s == 7:
    print(l[0]+op[0]+l[1]+op[1]+l[2]+op[2]+l[3]+"=7")
  
  
  

Fixed code:
l = list(input())
for i in range(8):
  s = int(l[0])
  b = bin(i)[2:].zfill(3)
  op = ["", "", ""]
  for j in range(len(b)):
    if b[j] == "0":
      s += int(l[j+1])
      op[j] = "+"
    else:
      s -= int(l[j+1])
      op[j] = "-"
  if s == 7:
    print(l[0]+op[0]+l[1]+op[1]+l[2]+op[2]+l[3]+"=7")
    break
Buggy 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))

Fixed code:
abcd = input()
A,B,C,D = int(abcd[0]),int(abcd[1]),int(abcd[2]),int(abcd[3])    
if A + B + C + D == 7:
  print('{}+{}+{}+{}=7'.format(A, B, C, D))
elif A + B + C - D == 7:
  print('{}+{}+{}-{}=7'.format(A, B, C, D))
elif A + B - C + D == 7:
  print('{}+{}-{}+{}=7'.format(A, B, C, D))
elif A + B - C - D == 7:
  print('{}+{}-{}-{}=7'.format(A, B, C, D))
elif A - B + C + D == 7:
  print('{}-{}+{}+{}=7'.format(A, B, C, D))
elif A - B + C - D == 7:
  print('{}-{}+{}-{}=7'.format(A, B, C, D))
elif A - B - C + D == 7:
  print('{}-{}-{}+{}=7'.format(A, B, C, D))
else:
  print('{}-{}-{}-{}=7'.format(A, B, C, D))
Buggy code:
l = ["" for i in range(7)]
ll = list(input())

for i in range(4):
    l[i*2] = ll[i]

flag = False
for i in range(2):
    if i==0:
        l[1] = '+'
    else:
        l[1] = '-'
    for ii in range(2):
        if ii==0:
            l[3] = '+'
        else:
            l[3] = '-'
        for iii in range(2):
            if iii==0:
                l[5] = '+'
            else:
                l[5] = '-'
            t = "".join(l)
            ans = eval(t)
            if ans==7:
                print(t+'=7')
                flag = True
        if flag:
            break
    if flag:
        break

Fixed code:
l = ["" for i in range(7)]
ll = list(input())

for i in range(4):
    l[i*2] = ll[i]

flag = False
for i in range(2):
    if i==0:
        l[1] = '+'
    else:
        l[1] = '-'
    for ii in range(2):
        if ii==0:
            l[3] = '+'
        else:
            l[3] = '-'
        for iii in range(2):
            if iii==0:
                l[5] = '+'
            else:
                l[5] = '-'
            t = "".join(l)
            ans = eval(t)
            if ans==7:
                print(t+'=7')
                flag = True
                break
        if flag:
            break
    if flag:
        break
Buggy code:
s_list = str(input())
A, B, C, D = [int(s) for s in s_list ]
for x in range(2):
    if x==0:
        X = A + B
        px = '+'
    else:
        X = A - B
        px = '-'
    for y in range(2):
        if y==0:
            Y = X + C
            py = '+'
        else:
            Y = X - C
            py = '-'
        for z in range(2):
            if z==0:
                Z = Y + D
                pz = '+'
            else:
                Z = Y - D
                pz = '-'
                
            if Z==7:
                print(A, px, B, py, C, pz, D, sep='')

Fixed code:
s_list = str(input())
A, B, C, D = [int(s) for s in s_list ]
for x in range(2):
    if x==0:
        X = A + B
        px = '+'
    else:
        X = A - B
        px = '-'
    for y in range(2):
        if y==0:
            Y = X + C
            py = '+'
        else:
            Y = X - C
            py = '-'
        for z in range(2):
            if z==0:
                Z = Y + D
                pz = '+'
            else:
                Z = Y - D
                pz = '-'
                
            if Z==7:
                print(A, px, B, py, C, pz, D, '=7', sep='')
                exit()
Buggy code:
a, b, c, d = list(input())
en = ["+", "-"]
for x in en:
  for y in en:
    for z in en:
      s = a + x + b + y + c + z + d
      if eval(s) == 7:
        print(s)
        break

Fixed code:
a, b, c, d = list(input())
en = ["+", "-"]
for x in en:
  for y in en:
    for z in en:
      s = a + x + b + y + c + z + d
      if eval(s) == 7:
        print(s + "=7")
        exit()
Buggy code:
n=input()

for i in range(2 ** 3):
    ans=[]

    co=["-","-","-"]

    for j in range(3):
        if ((i>>j)&1):
            co[j]="+"

        eq=n[0]+co[0]+n[1]+co[1]+n[2]+co[2]+n[3]

        if eval(eq)==7:
            ans=[].append(eq)

print(eq+"=7")


Fixed code:
n=input()

for i in range(2 ** 3):
    

    co=["-","-","-"]

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

    eq=n[0]+co[0]+n[1]+co[1]+n[2]+co[2]+n[3]


    if eval(eq)==7:
            ans=eq

print(ans,end="")
print("=7")
Buggy code:
s= input()
n = len(s) - 1


import itertools
li = list(itertools.product({0, 1}, repeat=n))
for i in range(len(li)):
    total = int(s[0])
    shiki = s[0]
    for j in range(n):
        if li[i][j] == 0:
            total += int(s[j+1])
            shiki += "+"+s[j+1]
        else:
            total -= int(s[j+1])
            shiki += "-"+s[j+1]
    if total == 7:
        print(shiki)
    else:
        pass

Fixed code:
s= input()
n = len(s) - 1


import itertools
li = list(itertools.product({0, 1}, repeat=n))
for i in range(len(li)):
    total = int(s[0])
    shiki = s[0]
    for j in range(n):
        if li[i][j] == 0:
            total += int(s[j+1])
            shiki += "+"+s[j+1]
        else:
            total -= int(s[j+1])
            shiki += "-"+s[j+1]
    if total == 7:
        shiki += "="+str(7)
        print(shiki)
        break
    else:
        pass
Buggy code:
x = input()
p = ['+','-']
def cal(a,b,c,x):
    res = int(x[0])
    if a:res-=int(x[1])
    else:res+=int(x[1])
    if b:res-=int(x[2])
    else:res+=int(x[2])
    if c:res-=int(x[3])
    else:res+=int(x[3])
    if res == 7:
        return True
    else:return False
    
        
for i in range(2):
    for j in range(2):
        for k in range(2):
            if cal(i,j,k,x):
                print(x[0]+p[i]+x[1]+p[j]+x[2]+p[k]+x[3]+'=7')
                break

            

Fixed code:
x = input()
p = ['+','-']
def cal(a,b,c,x):
    res = int(x[0])
    if a:res-=int(x[1])
    else:res+=int(x[1])
    if b:res-=int(x[2])
    else:res+=int(x[2])
    if c:res-=int(x[3])
    else:res+=int(x[3])
    if res == 7:
        return True
    else:return False
    
        
for i in range(2):
    for j in range(2):
        for k in range(2):
            if cal(i,j,k,x):
                print(x[0]+p[i]+x[1]+p[j]+x[2]+p[k]+x[3]+'=7')
                exit(0)
Buggy code:
abcd = list(input())
a, b, c, d = (int(abcd[i]) for i in range(4))

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

for k in [1, -1]:
    for l in [1, -1]:
        for m in [1, -1]:
            if a + (k * b) + (l * c) + (m * d) == 7:
                print("{}{}{}{}{}{}{}=7".format(a, dict[k], b, dict[l], c, dict[m], d))

Fixed code:
abcd = list(input())
a, b, c, d = (int(abcd[i]) for i in range(4))

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

for k in [1, -1]:
    for l in [1, -1]:
        for m in [1, -1]:
            if a + (k * b) + (l * c) + (m * d) == 7:
                print("{}{}{}{}{}{}{}=7".format(a, dict[k], b, dict[l], c, dict[m], d))
                exit()
Buggy code:
s = input()
n = len( s )

def dfs( i : int, total : int, formular : str  ):
    if i == n - 1:
        if total == 7:
            print( formular+"=7" )
            exit
    else:
        next = s[ i + 1]
        dfs( i + 1, total + int( next ), formular + "+" + next )
        dfs( i + 1, total -  int( next ), formular + "-" + next )

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

Fixed code:
s = input()
n = len( s )

def dfs( i : int, total : int, formular : str  ):
    if i == n - 1:
        if total == 7:
            print( formular+"=7" )
            exit()
    else:
        next = s[ i + 1]
        dfs( i + 1, total + int( next ), formular + "+" + next )
        dfs( i + 1, total -  int( next ), formular + "-" + next )

dfs( 0, int( s[0]),  s[0] )
Buggy code:
A, B, C, D = list(input())

oplist = ['+', '-']

for op1 in oplist:
    for op2 in oplist:
        for op3 in oplist:
            f = A + op1 + B + op2 + C + op3 + D
            ans = eval(f)
            if ans == 7:
                print(f)
                quit()

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

oplist = ['+', '-']

for op1 in oplist:
    for op2 in oplist:
        for op3 in oplist:
            f = A + op1 + B + op2 + C + op3 + D
            ans = eval(f)
            if ans == 7:
                print(f + "=7")
                quit()
Buggy code:
import itertools
s = input()
ans=0
for i in list(itertools.product([0,1], repeat=len(s)-1)):
    b = 0
    a = int(s[0])
    l = [a]+[0]*(2*(len(s)-1))
    for j in range(len(s)-1):
        if i[j] == 0:
            a += int(s[j+1])
            l[2*j+1] = '+'
            l[2*j+2] = s[j+1]
        else:
            a -= int(s[j+1])
            l[2*j+1] = '-'
            l[2*j+2] = s[j+1]
    if a == 7:
        print(*l,'=7')
        break

Fixed code:
import itertools
s = input()
ans=0
for i in list(itertools.product([0,1], repeat=len(s)-1)):
    b = 0
    a = int(s[0])
    l = [a]+[0]*(2*(len(s)-1))
    for j in range(len(s)-1):
        if i[j] == 0:
            a += int(s[j+1])
            l[2*j+1] = '+'
            l[2*j+2] = str(s[j+1])
        else:
            a -= int(s[j+1])
            l[2*j+1] = '-'
            l[2*j+2] = str(s[j+1])
    if a == 7:
        l[0] = str(s[0])
        l += '=7'
        l = ''.join(l)
        print(l)
        break
Buggy code:
S = input()

def saiki(i,s = S[0]):
    if i == 3:
        if eval(s) == 7:
            print(str(s) + "=7")
            exit()
            
    saiki(i + 1, s + "+" + S[i+1])
    saiki(i + 1, s + "-" + S[i+1])

Fixed code:
S = input()

def saiki(i,s = S[0]):
    if i == 3:
        if eval(s) == 7:
            print(str(s) + "=7")
            exit()
        else:
            return            
    saiki(i + 1, s + "+" + S[i+1])
    saiki(i + 1, s + "-" + S[i+1])

saiki(0)
Buggy code:
import sys
a,b,c,d=[i for i in 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+i+b+j+c+k+d)
        sys.exit()

Fixed code:
import sys
a,b,c,d=[i for i in 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+i+b+j+c+k+d+"=7")
        sys.exit()