qyliang/CodeNanoFix huggingface dataset:
Buggy code:
# sys.stdin.readline
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N, C, K = map(int, input().split())
        T = [int(input()) for _ in range(N)]

        T.sort()
        bus = 1
        p = 1
        start = T[0]
        for i in range(1, N):
            p += 1
            if T[i] - start >= K or p >= C:
                bus += 1
                p = 1
                start = T[i]

        print(bus)


# Run main
if __name__ == '__main__':
    AtCoder().main()

Fixed code:
# sys.stdin.readline
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N, C, K = map(int, input().split())
        T = [int(input()) for _ in range(N)]

        T.sort()
        bus = 1
        p = 1
        start = T[0]
        for i in range(1, N):
            p += 1
            if T[i] > K + start or p > C:
                bus += 1
                p = 1
                start = T[i]

        print(bus)


# Run main
if __name__ == '__main__':
    AtCoder().main()
Buggy code:
nums ,limit ,wait = map(int, input().split())
nums_ary = [0 for i in range(nums)]

for i in range(nums):
    nums_ary[i] = int(input())

nums_ary.sort()
nums_ary.append(10000000000000)
count = 0
i = 0
while i < nums:
    time = nums_ary[i]
    for x in range(limit):
        print(i,count,nums_ary[i])
        if not time <= nums_ary[i] <= time + wait:
            count += 1
            break
        i += 1
    else:
        count += 1
print(count)

Fixed code:
nums ,limit ,wait = map(int, input().split())
nums_ary = [0 for i in range(nums)]

for i in range(nums):
    nums_ary[i] = int(input())

nums_ary.sort()
nums_ary.append(10000000000000)
count = 0
i = 0
while i < nums:
    time = nums_ary[i]
    for x in range(limit):
        if not time <= nums_ary[i] <= time + wait:
            count += 1
            break
        i += 1
    else:
        count += 1
print(count)
Buggy code:
from collections import deque
n,c,k=map(int,input().split())
l=sorted([int(input()) for _ in range(n)],reverse=True)
ans=0
d=deque(l)
while len(d)!=0:
    ans+=1
    t=d.popleft()
    cnt=1
    while d[0]>=t-k and cnt<c:
        d.popleft()
        cnt+=1
print(ans)

Fixed code:
from collections import deque
n,c,k=map(int,input().split())
l=sorted([int(input()) for _ in range(n)],reverse=True)
ans=0
d=deque(l)
while len(d)!=0:
    ans+=1
    t=d.popleft()
    cnt=1
    while len(d)!=0 and d[0]>=t-k and cnt<c:
        d.popleft()
        cnt+=1
print(ans)
Buggy code:
n, c, k = map(int, input().split())
t_list = [int(input()) for i in range(n)]

t_sorted = sorted(t_list)

ans = 1
bus = 0
timer = 0
for i in range(1, len(t_sorted)):
    bus += 1
    timer += t_sorted[i] - t_sorted[i - 1]
    if bus >= c or timer >= k:
        ans += 1
        bus = 1
        timer = 0

print(ans)

Fixed code:
n, c, k = map(int, input().split())
t_list = [int(input()) for i in range(n)]

t_sorted = sorted(t_list)

ans = 1
bus = 1
timer = 0
for i in range(1, len(t_sorted)):
    bus += 1
    timer += t_sorted[i] - t_sorted[i - 1]
    if bus > c or timer > k:
        ans += 1
        bus = 1
        timer = 0

print(ans)
Buggy code:
N,C,K=map(int,input().split())
T=sorted([int(input()) for _ in range(N)])

ans=0
c=0
t=0

for i in range(N):
    if c==C or T[i]>t+K:
        ans+=1
        c=0

    if c==0:
        t=T[i]

    c+=1

if c>=2:
    print(ans+1)
else:
    print(ans)


Fixed code:
N,C,K=map(int,input().split())
T=sorted([int(input()) for _ in range(N)]) + [10000000]

ans=0
c=0
t=0

for i in range(N):
    if c==0:
        ans+=1
        t=T[i]

    c+=1

    if c==C or T[i+1]>t+K:
        c=0

print(ans)
Buggy code:
N,C,K=map(int,input().split())
T=[int(input()) for _ in range(N)]

T.sort()

bus=-10**9
cnt=0
ans=0
for t in T:
    if t>bus or cnt>C:
        bus=t+K
        cnt=1
        ans+=1
    else:
        cnt+=1

print(ans)

Fixed code:
N,C,K=map(int,input().split())
T=[int(input()) for _ in range(N)]

T.sort()

bus=-10**9
cnt=0
ans=0
for t in T:
    if t>bus or cnt>=C:
        bus=t+K
        cnt=1
        ans+=1
    else:
        cnt+=1

print(ans)
Buggy code:
n, c, k = map(int, input().split())
l = [int(input()) for i in range(n)]
count = 0
first = l[0]
people = 1
count = 1
for i in range(1, n):
    if people < c and l[i] - first <= k:
        people += 1
    else:
        first = l[i]
        people = 1
        count += 1
print(count)

Fixed code:
n, c, k = map(int, input().split())
l = [int(input()) for i in range(n)]
l.sort()
count = 0
first = l[0]
people = 1
count = 1
for i in range(1, n):
    if people < c and l[i] - first <= k:
        people += 1
    else:
        first = l[i]
        people = 1
        count += 1
print(count)
Buggy code:
passengers, bus_size, time_lim = map(int, input().split())
pass_list = [int(input()) for passenger in range(passengers)]
pass_list.sort()
front = 0
now = 0
cnt = 0
ans = 0
for psngr_lst in pass_list:
    if cnt == 0:
        front = i
        now = i
        cnt += 1
    elif cnt == bus_size:
        front = i
        now = i
        cnt = 1
        ans += 1
    elif now - front <= time_lim:
        if i - front <= time_lim:
            now = i
            cnt += 1
        else:
            front = i
            now = i
            cnt = 1
            ans += 1
if cnt:
    ans += 1
print(ans)
        

Fixed code:
passengers, bus_size, time_lim = map(int, input().split())
pass_list = [int(input()) for passenger in range(passengers)]
pass_list.sort()
front = 0
now = 0
cnt = 0
ans = 0
for psngr_lst in pass_list:
    if cnt == 0:
        front = psngr_lst
        now = psngr_lst
        cnt += 1
    elif cnt == bus_size:
        front = psngr_lst
        now = psngr_lst
        cnt = 1
        ans += 1
    elif now - front <= time_lim:
        if psngr_lst - front <= time_lim:
            now = psngr_lst
            cnt += 1
        else:
            front = psngr_lst
            now = psngr_lst
            cnt = 1
            ans += 1
if cnt:
    ans += 1
print(ans)
Buggy code:
n,c,k=map(int,input().split())
t=sorted([int(input()) for i in range(n)])
print(t)
a,x,y=1,1,t[0]
for i in t[1:]:
    if x==c or i>y+k:
        a+=1
        x=0
        y=i
    x+=1
print(a)

Fixed code:
n,c,k=map(int,input().split())
t=sorted([int(input()) for i in range(n)])
a,x,y=1,1,t[0]
for i in t[1:]:
    if x==c or i>y+k:
        a+=1
        x=0
        y=i
    x+=1
print(a)
Buggy code:
N,C,K=map(int,input().split())
T=[int(input()) for _ in range(N)]
flag=0
bus_cnt=0
First=T[i]
bus_rider=1
bus_cnt=1
for i in range(N):
    if bus_rider<C and T[i]-First<=K:
        bus_rider+=1
    else:
        First=T[i]
        bus_rider=1
        bus_cnt+=1
print(bus_cnt)

Fixed code:
N,C,K=map(int,input().split())
T=sorted([int(input()) for _ in range(N)])
First=T[0]
bus_rider=1
bus_cnt=1
for i in range(1,N):
    if bus_rider<C and T[i]-First<=K:
        bus_rider+=1
    else:
        First=T[i]
        bus_rider=1
        bus_cnt+=1
print(bus_cnt)
Buggy code:
if __name__ == '__main__':
    [N, C, K] = [int(i) for i in input().split()]

    T = []
    for i in range(K):
        T.append(int(input()))
    T.sort()

    counter = 1

    num_people = 0

    flag = False

    for num in T:
        print(num)
        print(flag)
        num_people += 1
        if flag:
            if num - first_time <= K and num_people <= C:
                continue
            else:
                counter += 1
                num_people = 1
                flag = False
                print('inc')
        else:
            first_time = num
            flag = True
        

    print(counter)


Fixed code:
if __name__ == '__main__':
    [N, C, K] = [int(i) for i in input().split()]

    T = []
    for i in range(N):
        T.append(int(input()))
    T.sort()

    counter = 1

    num_people = 0

    flag = False

    for num in T:
        num_people += 1
        if flag:
            if num - first_time <= K and num_people <= C:
                continue
            else:
                counter += 1
                num_people = 1
                first_time = num

        else:
            first_time = num
            flag = True

    print(counter)
Buggy code:
N,C,K = [int(s) for s in input().split()]
T = []
for i in range(N):
    T.append(int(input()))
T.sort()

pas = 0
leave = T[0]
ans = 1

for t in T:
    if pas == C and K < t - leave:
        pas += 1
    else:
        leave = t
        ans += 1
        pas = 0
print(ans)

Fixed code:
N,C,K = [int(s) for s in input().split()]
T = []
for i in range(N):
    T.append(int(input()))
T.sort()
 
pas = 0
leave = T[0]
ans = 1
 
for t in T:
    if pas == C or K < t - leave:
        leave = t
        ans += 1
        pas = 0
    pas += 1
print(ans)
Buggy code:
n, c, k = map(int, input().split())
t = []
for i in range(n):
  t.append(int(input()))
t.sort()
person = 0
firsttime = 0
ans = 0
for i in range(n):
  if person == 0:
    firsttime = t[i]
    person += 1
  elif person <= c and (firsttime + k) <= t[i]:
    person += 1
  else:
    person = 0
    ans += 1
    
if person != 0:
  ans += 1
print(ans)
  
  
  
           

Fixed code:
n, c, k = map(int, input().split())
t = []
for i in range(n):
  t.append(int(input()))
t.sort()
person = 0
firsttime = 0
ans = 0
for i in range(n):
  if person == 0:
    firsttime = t[i]
    person += 1
  elif person <= c-1 and (firsttime + k) >= t[i]:
    person += 1
  else:
    person = 1
    firsttime = t[i]
    ans += 1
    
if person != 0:
  ans += 1
print(ans)
Buggy code:
N,C,K = list(map(int, input().split()))
T = [int(input()) for _ in range(N)]

i = 0
n_b = 0
n_passenger_on_waiting_bus = 0
departure_limit=-1

for i in range(N):
  if T[i] > departure_limit or n_passenger_on_waiting_bus == C:
    n_b +=1
    n_passenger_on_waiting_bus = 1
    departure_limit = T[i] + K
  else:
    n_passenger_on_waiting_bus += 1
    
print(n_b)

Fixed code:
N,C,K = list(map(int, input().split()))
T = [int(input()) for _ in range(N)]
T.sort()

i = 0
n_b = 0
n_passenger_on_waiting_bus = 0
departure_limit=-1

while i < N:
  if T[i] > departure_limit or n_passenger_on_waiting_bus == C:
    n_b +=1
    n_passenger_on_waiting_bus = 1
    departure_limit = T[i] + K
  else:
    n_passenger_on_waiting_bus += 1
  i += 1
    
print(n_b)
Buggy code:
N, C, K = map(int,input().split())
T = []
for _ in range(N):
  T.append(int(input()))
sorted(T)
cnt=1
s=0
for i in range(N):
  if (T[i] > T[s]+K) or (i==s+C):
    cnt += 0
    s=i
print(cnt)


Fixed code:
N, C, K = map(int,input().split())
T = []
for _ in range(N):
  T.append(int(input()))
T.sort()
cnt=1
s=0
for i in range(1,N):
  if (T[i] > T[s]+K) or (i==s+C):
    cnt += 1
    s=i
print(cnt)
Buggy code:
N,C,K = map(int,input().split())
T = [int(input()) for i in range(N)]
s = 0
e = 0
p = 0
ans = 0
for i in range(N):
    if p == C or e < T[i]:
        ans += 1
        s = T[i]
        e = T[i]+K
        p = 0
    s = max(s,T[i])
    e = min(e,T[i]+K)
    p += 1
if p > 0:
    ans += 1
print(ans)


Fixed code:
N,C,K = map(int,input().split())
T = [int(input()) for i in range(N)]
T.sort()
s = 0
e = T[0]+K
p = 0
ans = 0
for i in range(N):
    if p == C or e < T[i]:
        ans += 1
        s = T[i]
        e = T[i]+K
        p = 0
    s = max(s,T[i])
    e = min(e,T[i]+K)
    p += 1
print(ans+1)
Buggy code:
n, c, k = map(int, input().split())
t = []
for i in range(n):
  t.append(int(input()))
t.sort()
result = 1
j = 0

for i in range(n):
  if (t[j] - t[0]) > k or c == count:
    result += 1
    t = t[j:]
    j = 1
  else:
    j += 1
print(result)

Fixed code:
n, c, k = map(int, input().split())
t = [int(input()) for i in range(n)]
t.sort()

result = 1
count = 0
f = 0

for i in range(n):
  if (t[i] - t[f]) > k or c == count:
    result += 1
    count = 1
    f = i
  else:
    count += 1
print(result)
Buggy code:
N, C, K = map(int, input().split())
T = [int(input()) for i in range(N)]
T.sort()
answer = 0
while len(T) >0:
    limit = T[0] + K
    counter = 0
    while counter < C:
        if len(T) == 0:
            break
        t = T.pop(0)
        if t > limit:
            break
        counter += 1
    answer += 1
print(answer)


Fixed code:
N, C, K = map(int, input().split())
T = [int(input()) for i in range(N)]
T.sort()
answer = 0
while len(T) > 0:
    limit = T[0] + K
    counter = 0
    while counter < C:
        if len(T) == 0:
            break
        if T[0] > limit:
            break
        del T[0]
        counter += 1
    answer += 1
print(answer)
Buggy code:
N,C,K = map(int,input().split())
T = [int(input()) for _ in range(N)].sort()

time=T[0]
count = 1
ans = 0

for i in range(1,N):
  if T[i]-time>K or count==C:
    time = T[i]
    count = 1
    ans += 1
  else:
    count += 1
if count>0:
  ans += 1
print(ans)
  


Fixed code:
N,C,K = map(int,input().split())
T = [int(input()) for _ in range(N)]
T.sort()

time=T[0]
count = 1
ans = 0

for i in range(1,N):
  if T[i]-time>K or count==C:
    time = T[i]
    count = 1
    ans += 1
  else:
    count += 1
if count>0:
  ans += 1
print(ans)
Buggy code:
N,C,K = map(int,input().split())
Ts = sorted([int(input()) for _ in range(N)])

#print(Ts)

ans = 0
firstFlag = True
passenger = []	#firstTime lastNum
for i in range(N):
	if firstFlag:
		passenger = [Ts[i],C-1]
		firstFlag = False
		#print("first",str(passenger),Ts[i],ans)
	elif i < N-1:
		if passenger[0] + K <= Ts[i+1]:
			#print("time over",str(passenger),Ts[i],ans)
			ans += 1
			firstFlag = True
	elif passenger[1] == 1:
		#print("full",str(passenger),Ts[i],ans)
		ans += 1
		firstFlag = True
	else:
		#print("other",str(passenger),Ts[i],ans)
		passenger[1] -= 1
else:
	#print("close",str(passenger),ans)
	if not firstFlag:
		ans += 1

print(ans)

Fixed code:
N,C,K = map(int,input().split())
Ts = sorted([int(input()) for _ in range(N)])

#print(Ts)

ans = 0
firstFlag = True
passenger = []	#limit lastNum
for i in range(N):
	if firstFlag:
		passenger = [Ts[i] + K,C-1]
		firstFlag = False
		ans += 1
		#print("first",str(passenger),Ts[i],ans)
	
	if passenger[1] <= 0:
		#print("full",str(passenger),Ts[i],ans)
		firstFlag = True
	elif i+1 < N and passenger[0] < Ts[i+1]:
		#print("time over",str(passenger),Ts[i],ans)
		firstFlag = True
	else:
		#print("other",str(passenger),Ts[i],ans)
		passenger[1] -= 1

print(ans)
Buggy code:
n,c,k=map(int,input().split())
t=[]
for i in range(n):
  t.append(int(input()))
t.sort()

bus=0
arr=0
que=0
for i in range(n):
  tt=t[i]
  if que==0:
    print('que=0,i,bus,arr,que,t[i]',i,bus,arr,que,t[i])
    arr=tt
    que+=1
    bus+=1
  else:
    if que==c:
      #print('q==c,i,bus,arr,que,t[i]',i,bus,arr,que,t[i])
      bus+=1
      arr=tt
      que=1
    else:
      if arr+k<tt:
        #print('dep,i,bus,arr,que,t[i]',i,bus,arr,que,t[i])
        bus+=1
        arr=tt
        que=1
      else:
        #print('waiting,i,bus,arr,que,t[i]',i,bus,arr,que,t[i])
        que+=1

print(bus)

Fixed code:
n,c,k=map(int,input().split())
t=[]
for i in range(n):
  t.append(int(input()))
t.sort()

bus=0
arr=0
que=0
for i in range(n):
  tt=t[i]
  if que==0:
    #print('que=0,i,bus,arr,que,t[i]',i,bus,arr,que,t[i])
    arr=tt
    que+=1
    bus+=1
  else:
    if que==c:
      #print('q==c,i,bus,arr,que,t[i]',i,bus,arr,que,t[i])
      bus+=1
      arr=tt
      que=1
    else:
      if arr+k<tt:
        #print('dep,i,bus,arr,que,t[i]',i,bus,arr,que,t[i])
        bus+=1
        arr=tt
        que=1
      else:
        #print('waiting,i,bus,arr,que,t[i]',i,bus,arr,que,t[i])
        que+=1

print(bus)
Buggy code:
n, c, k = map(int, input().split())
t = [int(input()) for _ in range(n)]
t.sort()
f = 0
count = 0
for i in range(1, n):
    if t[i] > t[f] + k:
        count += 1
        f = i
else:
    count += 1
print(count)

Fixed code:
n, c, k = map(int, input().split())
t = [int(input()) for _ in range(n)]
t.sort()
f = 0
count = 0
for i in range(1, n):
    if t[i] > t[f] + k or c == i - f:
        count += 1
        f = i
else:
    count += 1
print(count)
Buggy code:
n,c,k=map(int,input().split())

x=[]
for i in range(n):
    x.append(int(input()))
        
    
x.sort()

count=1

bus_count=0

for j in range(n-1):
    bus_count+=1
    if(x[j]+k<x[j+1] or bus_count==c):
        count+=1
        bus_count=0
        

Fixed code:
n,c,k=map(int,input().split())

x=[]
for i in range(n):
    x.append(int(input()))
        
    
x.sort()

count=1

bus_count=0

for j in range(n-1):
    bus_count+=1
    if(x[j+1-bus_count]+k<x[j+1] or bus_count==c):
        count+=1
        bus_count=0
        
print(count)
Buggy code:
n,c,k=map(int,input().split())
t=[int(input()) for _ in [0]*n]
t.sort()
t=t+[0]
b=1
h=0
d=t[0]
for i in range(n):
  if(h<=0 and t[i]-d<=k):
    h+=1
  else:
    b+=1
    h=0
    d=t[i+1]
print(b)

Fixed code:
n,c,k=map(int,input().split())
t=[int(input()) for _ in [0]*n]
t.sort()
t=t+[0]
b=1
h=0
d=t[0]
for i in range(n):
  if(h<c and t[i]-d<=k):
    h+=1
  else:
    b+=1
    h=1
    d=t[i]
print(b)
Buggy code:
N,C,K = map(int,input().split())
T = []
for i in range(N):
  L.append(int(input()))
  
ans = 1
T = sorted(T)
ind = 0

for i in range(T):
    if T[i] > T[ind]+K:
        ans += 1
        ind = i
    elif i >= ind + C:
        ans += 1
        ind = i
    
print(ans)

Fixed code:
N,C,K=map(int,input().split())
T=[]
for i in range(N):
    p=int(input())
    T.append(p)
  
ans = 1
T = sorted(T)
ind = 0
 
for i in range(len(T)):
    if T[i] > T[ind]+K:
        ans += 1
        ind = i
    elif i >= ind + C:
        ans += 1
        ind = i
print(ans)
Buggy code:
N,C,K=map(int,input().split())
A=[]
for i in range(N):
    a=int(input())
    A.append(a)
A.sort()
k=K
a=0
c=C
j=1
while j<N:
    k-=A[j]-A[j-1]
    n-=1
    if k>0 and c>0:    
        j+=1
    else:     
        a+=1
        c=C
        k=K
        j+=1
print(a+1)   

Fixed code:
N,C,K=map(int,input().split())
A=[]
for i in range(N):
    a=int(input())
    A.append(a)
A.sort()
k=K
a=0
c=C-1
j=1
while j<N:
    k-=A[j]-A[j-1]
    c-=1
    if k>=0 and c>=0:    
        j+=1
    else:     
        a+=1
        c=C-1
        k=K
        j+=1
print(a+1)
Buggy code:
N,C,K = map(int, input().split())
T = [int(input()) for _ in range(N)]
T.sort()
tmp = T[0]
ans = 0
cnt = 1
for i in range(1, N):
    cnt += 1
    if T[i]-tmp>K:
        ans += 1
        cnt = 1
        tmp = T[i]
    elif cnt>C:
        ans += 1
        cnt = 1
        tmp = T[i]
print(ans)

Fixed code:
N,C,K = map(int, input().split())
T = [int(input()) for _ in range(N)]
T.sort()
tmp = T[0]
ans = 0
cnt = 1
for i in range(1, N):
    cnt += 1
    if T[i]-tmp>K:
        ans += 1
        cnt = 1
        tmp = T[i]
    elif cnt>C:
        ans += 1
        cnt = 1
        tmp = T[i]
print(ans+1)
Buggy code:
# -*- coding: utf-8 -*-


def main():
    n, c, k = list(map(int, input().split()))
    t = [0] * n

    for i in range(n):
        ti = int(input())
        t[i] = (ti, ti + k)

    sorted_t = sorted(t, key=lambda x: x[1])
    current_pos = sorted_t[0][1]
    remain = c - 1
    bus_count = 1

    for i in range(1, n):
        if remain >= 1 and current_pos <= sorted_t[i][1]:
            remain -= 1
        else:
            bus_count += 1
            current_pos = sorted_t[i][1]
            remain = c - 1

    print(bus_count)


if __name__ == '__main__':
    main()


Fixed code:
# -*- coding: utf-8 -*-


def main():
    n, c, k = list(map(int, input().split()))
    t = [0] * n

    for i in range(n):
        ti = int(input())
        t[i] = (ti, ti + k)

    sorted_t = sorted(t, key=lambda x: x[1])
    pos = sorted_t[0][1]
    remain = c - 1
    bus_count = 1

    for i in range(1, n):
        if remain >= 1 and sorted_t[i][0] <= pos:
            remain -= 1
        else:
            bus_count += 1
            pos = sorted_t[i][1]
            remain = c - 1

    print(bus_count)


if __name__ == '__main__':
    main()
Buggy code:
n,c,k = list(map(int,input().split()))

t = []
for i in range(n):
    t.append(int(input()))

a = t[0]
b = 1
ans = 0
for i in range(1,n):
    if t[i] <= a+k and b < c:
        a = t[i]
        b += 1
    else:
        ans += 1
        if i < n-1:
            a = t[i+1]
        
print(ans)


Fixed code:
n,c,k = list(map(int,input().split()))

t = []
for i in range(n):
    t.append(int(input()))
t.sort()
a = t[0]
b = 1
ans = 1
for i in range(1,n):
    if t[i]-a <= k and b < c:
        b += 1
    else:
        ans += 1
        a = t[i]
        b = 1
print(ans)
Buggy code:
n, c, k = map(int, input().split())
t = []
for i in range(n):
    t.append(int(input()))
t.sort()

bus = 1
new_bus = False
start_time = 0
capacity = 0

while t:
    if new_bus:
        new_bus = False
        bus += 1
        capacity = 0

    time = t.pop(0)
    if capacity == 0:
        start_time = time
    wait_time = time - start_time
    capacity += 1

    if capacity == c:
        new_bus = True
        continue
    if wait_time > k:
        if (t == []) or (t[0] - wait_time <= k):
            new_bus = True
            continue

print(bus)

Fixed code:
n, c, k = map(int, input().split())
t = []
for i in range(n):
    t.append(int(input()))
t.sort()

bus = 0
new_bus = True
start_time = 0
capacity = 0

while t:
    time = t[0]
    if new_bus:
        new_bus = False
        capacity = 0
        start_time = time
        bus += 1

    wait_time = time - start_time
    if wait_time > k:
        if t:
            new_bus = True
            continue
        else:
            bus += 1
            break

    t.pop(0)
    capacity += 1

    if capacity == c:
        new_bus = True
        continue

print(bus)
Buggy code:
def main():
    N, C, K = map(int, input().split())
    i = 0
    T = []
    while i < N:
        T.append(int(input()))
        i += 1
    T.sort()
    T.reverse()

    c = 1
    i = 1
    bus = 0
    time = T[0]
    while i < N:
        if time - T[i] <= K:
            c += 1
        if time - T[i] > K or c == C:
            bus += 1
            c = 1
            time = T[i]
        i += 1

    print(str(bus))

main()

Fixed code:
def main():
    N, C, K = map(int, input().split())
    i = 0
    T = []
    while i < N:
        T.append(int(input()))
        i += 1
    T.sort()
    T.reverse()

    c = 1
    i = 1
    bus = 1
    time = T[0]
    while i < N:
        if time - T[i] > K or c == C:
            bus += 1
            c = 1
            time = T[i]
        elif time - T[i] <= K:
            c += 1
        i += 1

    print(str(bus))

main()
Buggy code:
import sys

INF = 10**9+7

stdin = sys.stdin
def na(): return map(int, stdin.readline().split())
def nal(): return list(map(int, stdin.readline().split()))
def ns(): return stdin.readline().strip()
def nsl(): return list(stdin.readline().strip())
def ni(): return int(stdin.readline())


n, c, k = nal()

t = []
for i in range(n):
    t.append(ni())
t.sort()

ans = 0
cnt = 0
tmp = t[0] + k
for i in range(1, n):
    cnt += 1
    en = 0
    if(tmp < t[i] or cnt == c):
        ans += 1
        cnt = 0
        tmp = t[i] + k
        en = 1

print(ans + en)




Fixed code:
import sys

INF = 10**9+7

stdin = sys.stdin
def na(): return map(int, stdin.readline().split())
def nal(): return list(map(int, stdin.readline().split()))
def ns(): return stdin.readline().strip()
def nsl(): return list(stdin.readline().strip())
def ni(): return int(stdin.readline())


n, c, k = nal()

t = []
for i in range(n):
    t.append(ni())
t.sort()

ans = 0
cnt = 0
tmp = t[0] + k
for i in range(1, n):
    cnt += 1
    if(tmp < t[i] or cnt == c):
        ans += 1
        cnt = 0
        tmp = t[i] + k

print(ans + 1)
Buggy code:
N, C, K = map(int, input().rstrip().split())
TT = sorted(map(int, [input() for _ in range(N)]))
startT = TT[0]
bus_count = 1
p = 1
for T in TT[1:]:
    if T - startT > K or p > C:
        bus_count += 1
        startT = T
        p = 1
    else:
        p += 1
print(bus_count)


Fixed code:
N, C, K = map(int, input().rstrip().split())
TT = sorted(map(int, [input() for _ in range(N)]))
startT = TT[0]
bus_count = 1
p = 1
for T in TT[1:]:
    if T - startT > K or p >= C:
        bus_count += 1
        startT = T
        p = 1
    else:
        p += 1
print(bus_count)