Buggy python submission (verdict: Time Limit Exceeded):
N,K,Q = map(int,input().split())
A = list(map(int,input().split()))

R = sorted(set(A))
ans = 10**9
for i in range(len(R)):
    temp = []
    temp2 = []
    l = 0
    for j in range(N):
        if A[j] < R[i]:
            temp += sorted(temp2)[:min(l,max(0,l - K + 1))]
            temp2 = []
            l = 0
        else:
            temp2.append(A[j])
            l += 1
    temp += sorted(temp2)[:min(l,max(0,l - K + 1))]

    if len(temp) > Q - 1:
        temp = sorted(temp)
        ans = min(ans,temp[Q - 1] - R[i])
    else:
        break
        
print(ans)
    


Fixed submission:
N,K,Q = map(int,input().split())
A = list(map(int,input().split()))

R = sorted(set(A))
ans = 10**9
for i in range(len(R)):
    temp = []
    temp2 = []
    l = 0
    for j in range(N):
        if A[j] < R[i]:
            if l >= K:
                temp += sorted(temp2)[:min(l,max(0,l - K + 1))]
            temp2 = []
            l = 0
        else:
            temp2.append(A[j])
            l += 1
    if l >= K:
        temp += sorted(temp2)[:min(l,max(0,l - K + 1))]

    if len(temp) > Q - 1:
        temp = sorted(temp)
        ans = min(ans,temp[Q - 1] - R[i])
    else:
        break
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K,Q = map(int,input().split())
A = list(map(int,input().split()))

R = sorted(set(A))
ans = 10**9
for i in range(len(R)):
    temp = []
    temp2 = []
    l = 0
    for j in range(N):
        if A[j] < R[i]:
            temp += sorted(temp2)[:min(l,max(0,l - K + 1))]
            temp2 = []
            l = 0
        else:
            temp2.append(A[j])
            l += 1
    temp += sorted(temp2)[:min(l,max(0,l - K + 1))]

    temp = sorted(temp)
    if len(temp) > Q - 1:
        ans = min(ans,temp[Q - 1] - R[i])
    else:
        break
        
print(ans)

Fixed submission:
N,K,Q = map(int,input().split())
A = list(map(int,input().split()))

R = sorted(set(A))
ans = 10**9
for i in range(len(R)):
    temp = []
    temp2 = []
    l = 0
    for j in range(N):
        if A[j] < R[i]:
            if l >= K:
                temp += sorted(temp2)[:min(l,max(0,l - K + 1))]
            temp2 = []
            l = 0
        else:
            temp2.append(A[j])
            l += 1
    if l >= K:
        temp += sorted(temp2)[:min(l,max(0,l - K + 1))]

    if len(temp) > Q - 1:
        temp = sorted(temp)
        ans = min(ans,temp[Q - 1] - R[i])
    else:
        break
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K,Q = map(int,input().split())
A = list(map(int,input().split()))
R = sorted(set(A))

ans = 10**9
for i in range(len(R)):
    temp = []
    temp2 = []
    for j in range(N):
        if A[j] < R[i]:
            temp += sorted(temp2)[:min(len(temp2),max(0,len(temp2) - K + 1))]
            temp2 = []
        else:
            temp2.append(A[j])
    temp += sorted(temp2)[:min(len(temp2),max(0,len(temp2) - K + 1))]

    temp = sorted(temp)
    if len(temp) > Q - 1:
        ans = min(ans,temp[Q - 1] - R[i])
    else:
        break
        
print(ans)
    


Fixed submission:
N,K,Q = map(int,input().split())
A = list(map(int,input().split()))

R = sorted(set(A))
ans = 10**9
for i in range(len(R)):
    temp = []
    temp2 = []
    l = 0
    for j in range(N):
        if A[j] < R[i]:
            if l >= K:
                temp += sorted(temp2)[:min(l,max(0,l - K + 1))]
            temp2 = []
            l = 0
        else:
            temp2.append(A[j])
            l += 1
    if l >= K:
        temp += sorted(temp2)[:min(l,max(0,l - K + 1))]

    if len(temp) > Q - 1:
        temp = sorted(temp)
        ans = min(ans,temp[Q - 1] - R[i])
    else:
        break
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K,Q = map(int,input().split())
A = list(map(int,input().split()))

ans = 10**9
for i in range(N):
    temp = []
    temp2 = []
    for j in range(N):
        if A[j] < A[i]:
            temp += sorted(temp2)[:min(len(temp2),max(0,len(temp2) - K + 1))]
            temp2 = []
        else:
            temp2.append(A[j])
    temp += sorted(temp2)[:min(len(temp2),max(0,len(temp2) - K + 1))]
    temp = sorted(temp)

    if len(temp) > Q - 1:
        ans = min(ans,temp[Q - 1] - A[i])
        
print(ans)
    


Fixed submission:
N,K,Q = map(int,input().split())
A = list(map(int,input().split()))

R = sorted(set(A))
ans = 10**9
for i in range(len(R)):
    temp = []
    temp2 = []
    l = 0
    for j in range(N):
        if A[j] < R[i]:
            if l >= K:
                temp += sorted(temp2)[:min(l,max(0,l - K + 1))]
            temp2 = []
            l = 0
        else:
            temp2.append(A[j])
            l += 1
    if l >= K:
        temp += sorted(temp2)[:min(l,max(0,l - K + 1))]

    if len(temp) > Q - 1:
        temp = sorted(temp)
        ans = min(ans,temp[Q - 1] - R[i])
    else:
        break
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K,Q = map(int,input().split())
A = [int(x) for x in input().split()]

ans = 10**9
for i in range(N):
    temp = []
    temp2 = []
    for j in range(N):
        if A[j] < A[i]:
            temp.append(temp2)
            temp2 = []
        else:
            temp2.append(A[j])
    temp.append(temp2)

    temp2 = temp
    temp = []
    for j in range(len(temp2)):
        temp += sorted(temp2[j])[:min(len(temp2[j]),max(0,len(temp2[j]) - K + 1))]
    temp = sorted(temp)

    if len(temp) > Q - 1:
        ans = min(ans,temp[Q - 1] - A[i])
        
print(ans)
    


Fixed submission:
N,K,Q = map(int,input().split())
A = list(map(int,input().split()))

R = sorted(set(A))
ans = 10**9
for i in range(len(R)):
    temp = []
    temp2 = []
    l = 0
    for j in range(N):
        if A[j] < R[i]:
            if l >= K:
                temp += sorted(temp2)[:min(l,max(0,l - K + 1))]
            temp2 = []
            l = 0
        else:
            temp2.append(A[j])
            l += 1
    if l >= K:
        temp += sorted(temp2)[:min(l,max(0,l - K + 1))]

    if len(temp) > Q - 1:
        temp = sorted(temp)
        ans = min(ans,temp[Q - 1] - R[i])
    else:
        break
        
print(ans)