You are given an integer sequence A of length N and an integer K.
You will perform the following operation on this sequence Q times:
 - Choose a contiguous subsequence of length K, then remove the smallest element among the K elements contained in the chosen subsequence (if there are multiple such elements, choose one of them as you like).
Let X and Y be the values of the largest and smallest element removed in the Q operations. You would like X-Y to be as small as possible.
Find the smallest possible value of X-Y when the Q operations are performed optimally.

-----Constraints-----
 - 1 \leq N \leq 2000
 - 1 \leq K \leq N
 - 1 \leq Q \leq N-K+1
 - 1 \leq A_i \leq 10^9
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
N K Q
A_1 A_2 ... A_N

-----Output-----
Print the smallest possible value of X-Y.

-----Sample Input-----
5 3 2
4 3 1 5 2

-----Sample Output-----
1

In the first operation, whichever contiguous subsequence of length 3 we choose, the minimum element in it is 1.
Thus, the first operation removes A_3=1 and now we have A=(4,3,5,2).
In the second operation, it is optimal to choose (A_2,A_3,A_4)=(3,5,2) as the contiguous subsequence of length 3 and remove A_4=2.
In this case, the largest element removed is 2, and the smallest is 1, so their difference is 2-1=1.

Difficulty: competition

Starter code:

Solutions:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,k,q = LI()
    a = LI()
    b = [[a[i],i] for i in range(n)]
    b.sort()
    ans = b[q-1][0]-b[0][0]
    l = [-1,n]
    for i in range(1,n):
        l.append(b[i-1][1])
        l.sort()
        if b[i-1][0] == b[i][0]:
            continue
        s = [a[l[i]+1:l[i+1]] for i in range(i+1)]
        c = []
        for si in s:
            si.sort()
            for j in range(len(si)-k+1):
                c.append(si[j])
        if len(c) < q:
            continue
        c.sort()
        m = c[q-1]-c[0]
        if m < ans:
            ans = m
    print(ans)
    return

#Solve
def __starting_point():
    solve()

__starting_point()

def main(n,k,q,x):
    ret=float('inf')
    for xi in x:
        c=[]
        tmp=[]
        for y in x:
            if y<xi:
                if len(tmp)>=k:
                    tmp.sort()
                    for j in range(len(tmp)-k+1):
                        c.append(tmp[j])
                tmp=[]
            else:
                tmp.append(y)
        if len(tmp)>=k:
            tmp.sort()
            for j in range(len(tmp)-k+1):
                c.append(tmp[j])
        if len(c)>=q:
            c.sort()
            ret=min(ret,c[q-1]-xi)
    return ret

#n=int(input())
#a=list(input())
#a=list(map(int,input().split()))
#b=list(map(int,input().split()))
#ab=[list(map(int,input().split())) for _ in range(n)]
n,k,q=list(map(int,input().split()))
x=list(map(int,input().split()))
print((main(n,k,q,x)))


N,K,Q=map(int,input().split())
alist=list(map(int,input().split()))

def div_by_a(border,dlist):
  divided_list=[]
  div=[]
  for d in dlist:
    if d<border:
      if len(div)>0:
        div.sort()
        divided_list.append(div)
        div=[]
    else:
      div.append(d)
  else:
    if len(div)>0:
      div.sort()
      divided_list.append(div)
      
  return divided_list

answer=10**9
for a in alist:
  divlist=div_by_a(a,alist)
  #print(divlist)
  
  cand_list=[]
  for div in divlist:
    cand_num=max(0,len(div)-K+1)
    cand_list.extend(div[:cand_num])
    
  cand_list.sort()
  #print(cand_list)
  if len(cand_list)>=Q:
    answer=min(answer,cand_list[Q-1]-a)   
    
print(answer)

from itertools import*
N,K,Q,*A=map(int,open(0).read().split())
s=sorted
print(min((s(sum((v[:max(0,len(v)-K+1)]for v in(k*s(v)for k,v in groupby(A,lambda a:a>=Y))),[]))[Q-1:]+[2e9])[0]-Y for Y in A))

import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from itertools import groupby
from heapq import heappop, heappush, heapify
def resolve():
    n, k, q = map(int, input().split())
    A = list(map(int, input().split()))

    ans = INF
    for m in sorted(A):
        C = []
        for key, it in groupby(A, key = lambda a : a >= m):
            if key is False:
                continue
            D = list(it)
            if len(D) >= k:
                D.sort()
                C.append(D[:len(D) - k + 1][::-1])

        if sum(len(a) for a in C) < q:
            continue
        heap = [(C[i].pop(), i) for i in range(len(C))]
        heapify(heap)
        for _ in range(q):
            M, i = heappop(heap)
            if C[i]:
                heappush(heap, (C[i].pop(), i))
        ans = min(ans, M - m)

    print(ans)
resolve()

import sys
input = sys.stdin.readline
N, K, Q = list(map(int, input().split()))
a = list(map(int, input().split()))
ta = a + []
res = pow(10, 10)
bs = pow(10, 10)
for x in sorted(set(a)):
  t = [[]]
  for i in range(N):
    if ta[i] == bs:
      if t[-1] != []:
        t.append([])
    else: t[-1].append(a[i])
  tt = []
  for i in range(len(t)):
    t[i].sort()
    for j in range(len(t[i]) - K + 1):
      tt.append(t[i][j])
  #print(tt, t, x)
  if len(tt) < Q: break
  tt.sort()
  res = min(res, tt[Q - 1] - tt[0])
  #print(res, tt, t)
  for i in range(N):
    if a[i] == x:
      ta[i] = bs
  #print(ta, t)
print(res)


N, K, Q = map(int, input().split())
A = list(map(int, input().split()))
ans = 10**18

for Y in set(A):
    L = []
    l = []
    
    for i in range(N):
        if A[i]<Y:
            L.append(l)
            l = []
        else:
            l.append(A[i])
    
    L.append(l)
    l2 = []
    
    for l in L:
        if len(l)<=K-1:
            continue
        
        l.sort()
        
        for i in range(len(l)-K+1):
            l2.append(l[i])
    
    if len(l2)<Q:
        continue
    
    l2.sort()
    X = l2[Q-1]
    ans = min(ans, X-Y)

print(ans)

# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n,k,Q = map(int,readline().split())
*a, = map(int,readline().split())
*sa, = sorted(a)
a.append(-1)
ans = 10**9
for i in sa:
    q = []
    v = []
    for j in a:
        if j < i:
            if len(v) >= k:
                v.sort()
                q += v[:len(v)-k+1]
            v.clear()
        else:
            v.append(j)

    if len(q) < Q: break
    q.sort()
    ans = min(ans, q[Q-1] - q[0])

print(ans)

from collections import defaultdict
import heapq

n, k, q = map(int, input().split())
a = list(map(int, input().split()))
ok = [0] * n
d = defaultdict(lambda : set())
h = []
for i in range(k - 1):
    heapq.heappush(h, [a[i], i])
    d[a[i]].add(i)
for i in range(k - 1, n):
    heapq.heappush(h, [a[i], i])
    d[a[i]].add(i)
    while h:
        if h[0][1] >= i - k + 1:
            break
        heapq.heappop(h)
    m = list(d[h[0][0]])
    for j in m:
        if j >= i - k + 1:
            ok[j] = 1
        d[h[0][0]].remove(j)
ans = 1145141919810
for i in range(n):
    if ok[i]:
        s, t = [], []
        for j in range(n):
            if a[i] > a[j]:
                s.sort()
                for l in range(max(0, len(s) - k + 1)):
                    t.append(s[l])
                s = []
            else:
                s.append(a[j])
        s.sort()
        for l in range(max(0, len(s) - k + 1)):
            t.append(s[l])
        t.sort()
        if len(t) >= q:
            ans = min(ans, t[q - 1] - t[0])
print(ans)

import sys
input = sys.stdin.readline

def main():
    n, k, q = list(map(int, input().split()))
    a = list(map(int, input().split()))

    b = [[v, i]for i, v in enumerate(a)]
    b.sort()
    index = [0]*n
    for i in range(n):
        index[i] = b[i][1]

    judge = [[] for i in range(n)]
    already = [-1, n]

    for i in range(n):
        
        for j in range(len(already)-1):
            key = a[already[j]+1:already[j+1]]
            if len(key) >= k:
                judge[i].append(key)
        already.append(index[i])
        already.sort()

    ans = 1e9
    for i in range(n):
        if not judge[i]:
            break
        m = b[i][0]
        sub = []
        for values in judge[i]:
            values.sort()
            for j in range(len(values)-k+1):
                sub.append(values[j])
        sub.sort()
        if len(sub) < q:
            break
        M = sub[q-1]
        ans = min(ans, M-m)

    print(ans)


    
def __starting_point():
    main()


__starting_point()

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

def sol(y):
    B = [[]]
    for a in A:
        if a < y and len(B[-1]) > 0:
            B.append([])
        if a >= y:
            B[-1].append(a)

    C = []
    for grp in B:
        grp.sort()
        C += grp[:max(0, len(grp) - K + 1)]
    C.sort()

    return C[Q - 1] - y if len(C) >= Q and C[0] == y else 10**18

ans = 10**18
for y in A:
    ans = min(ans, sol(y))

print(ans)


n,k,q = map(int, input().split())
a = list(map(int, input().split()))

def parse(b):
    ret = []
    tmp = []
    for ai in a:
        if ai >= b:
            tmp.append(ai)
        else:
            if len(tmp) >= k:
                tmp.sort(reverse=True)
                for i in range(k-1,len(tmp)):
                    ret.append(tmp[i])
            tmp = []
    else:
        if len(tmp) >= k:
            tmp.sort(reverse=True)
            for i in range(k-1,len(tmp)):
                ret.append(tmp[i])
            tmp = []
    return ret

ans = 10**10

for b in set(a):
    lis = parse(b)
    if len(lis) < q:
        continue
    lis.sort()
    ans_tmp = lis[q-1] - lis[0]
    ans = min(ans, ans_tmp)

print(ans)

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,k,q = list(map(int, input().split()))
a = list(map(int, input().split()))
arg = [(num,i) for i,num in enumerate(a)]
arg.sort()
def sub(x):
    """0,1,...,x-1番目は使わない場合において、X-Yの値
    """
    index = [item[1] for item in arg[:x]]
    index.sort()
    index.append(n)
    vals = []
    prv = 0
    for ind in index:
        if ind-prv>=k:
            vals.extend(sorted(a[prv:ind])[:(ind-prv)-k+1])
        prv = ind+1
        if prv>=n:
            break
    if len(vals)<q:
        return None
    else:
        vals.sort()
        return vals[q-1] - arg[x][0]
ans = float("inf")
for i in range(n):
    res = sub(i)
    if res is not None:
        ans = min(ans, res)
print(ans)

n,k,q = list(map(int, input().split()))
a = list(map(int, input().split()))
num_set = set(a)

def parse(b):
    ret = []
    tmp = []
    for ai in a:
        if ai >= b:
            tmp.append(ai)
        else:
            if len(tmp) >= k:
                tmp.sort(reverse=True)
                for i in range(k-1,len(tmp)):
                    ret.append(tmp[i])
            tmp = []
    else:
        if len(tmp) >= k:
            tmp.sort(reverse=True)
            for i in range(k-1,len(tmp)):
                ret.append(tmp[i])
            tmp = []
    return ret

ans = 10**10

for b in num_set:
    lis = parse(b)
    if len(lis) < q:
        continue
    ans_tmp = sorted(lis)[q-1] - min(lis)
    ans = min(ans, ans_tmp)

print(ans)


from collections import defaultdict, deque, Counter
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)


sys.setrecursionlimit(1000000000)
mod = 998244353

#############
# Main Code #
#############

"""
数列A
長さKの連続する部分列を1つ選ぶ　
その中の最小のものを取り除く　infにすれば？
取り除いた要素の最大値 - 最小値をマイナスにしたい　二分探索とかできる?
最終形をイメージする

一番望ましいのは
Q個について最小区間のQ個を取ること
それより小さい要素を取らずに都合のいいとこだけ取りたい
小さい順に仕切りを立てていく
まず小さい順に1 2 3 4...これは必ず取れる　（1 2 3 5...とかは1234より大きくなる）
次に2 3 4 5を取れるか
N個目の数って難しくない？

5 3 2
4 3 1 5 2 の場合
4 3 [1 5 2]
4 [3 5 2]

N <= 2000なので 1, 2, 3, 4で区切っていくのはできそう
Qの中に1を入れる場合、求める値はAq - A1

1 1 3 5 6 7 の場合
1番目の1以降を使うと 1 1 3 5
2番目の1以降を使うと 1 3 5 6
3以降を使うと       3 5 6 7
なので3以降を使う方がいい
Q = 4の時、候補となるのは
[小さい方から1番目、2番目、3番目...] or
[小さい方から2番目、3番目、4番目...] or...

ただし、[小さい方から2番目、3番目、4番目...]を作るには選択範囲に小さい方から1番目を含めないことが必要
4 3 1 5 2 の場合
　　 ×     1は障害物になる
ブロック1:[4, 3]
ブロック2:[5, 2] の中でしかKを回せない
[小さい方から3番目、4番目、5番目...]の場合
ブロック1:[4, 3]
ブロック2:[5]
"""

N, K, Q = getNM()
A = getList()
A = [[A[i], i] for i in range(N)]

flag = [0] * N
# 区切り0
l = deepcopy(sorted(A))
opt = []
l.sort()
for i in range(Q):
    opt.append(l[i][0])
ans = opt[-1] - opt[0]

# 区切り1個以上
for i in range(N):
    # indexの位置はlを再利用
    flag[l[i][1]] = 1 # A[i][1]はindex
    parent = []
    child = []
    # フラグの立っているところで区切る
    # 要素の探索はAを使う
    for j in range(N):
        if flag[j] == 0:
            child.append(A[j][0])
        else:
            child.sort()
            parent.append(child)
            child = []
    if len(child):
        child.sort()
        parent.append(child)

    # 値を求める
    # 各childから取れるだけ取る(配列操作を行う)
    opt = []
    for array in parent:
        for j in range(len(array) - K + 1): # childの長さ - K + 1だけ値を取れる
            opt.append(array[j])
    # Q個取れたなら
    if len(opt) >= Q:
        opt.sort()
        ans = min(ans, opt[Q - 1] - opt[0])

print(ans)

# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K, Q = MAP()
A = LIST()

ans = INF
# 使う要素の最小値とする値xを全探索
for x in A:
    # 数列Aをx未満の値で区切った数列Bを作る
    B = []
    tmp = []
    for i in range(N):
        if A[i] >= x:
            tmp.append(A[i])
        else:
            B.append(tmp)
            tmp = []
    B.append(tmp)
    # 数列B内の各数列から、使える要素を集める
    C =  []
    for li in B:
        m = len(li)
        if m-K+1 >= 1:
            li.sort()
            C += li[:m-K+1]
    # 集めた要素からQ個をクエリで使うので、小さい方からQ番目が使う要素の最大値y
    C.sort()
    if len(C) < Q:
        continue
    y = C[Q-1]
    ans = min(ans, y - x)
print(ans)


from itertools import*
N,K,Q,*A=map(int,open(0).read().split())
l=len
s=sorted
print(min(c[Q-1]-Y for c,Y in zip((s(sum((v[:l(v)-K+1]for v in(s(v)for k,v in groupby(A,lambda a:a>=Y)if k)if l(v)>=K),[]))for Y in A),A)if l(c)>=Q))

n,k,q=map(int,input().split())
l=list(map(int,input().split()))
ans=10**10
for i in range(n):
    x=l[i]
    tmp=[]
    z=[]
    for j in range(n):
        if l[j]>=x:
            tmp.append(l[j])
        if l[j]<x or j==n-1:
            tmp.sort()
            if len(tmp)-k+1>0:
                z+=tmp[:len(tmp)-k+1]
            tmp=[]
    z.sort()
    if len(z)>=q:
        ans=min(ans,z[q-1]-x)
print(ans)

# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K, Q = MAP()
A = LIST()

ans = INF
# 使う要素の最小値とする値xを全探索
for x in A:
    # 数列Aをx未満の値で区切った数列Bを作る
    B = []
    tmp = []
    for i in range(N):
        if A[i] >= x:
            tmp.append(A[i])
        else:
            B.append(tmp)
            tmp = []
    B.append(tmp)
    # 数列B内の各数列から、使える要素を集める
    C =  []
    for li in B:
        m = len(li)
        li.sort()
        C += li[:max(m-K+1, 0)]
    # 集めた要素からQ個をクエリで使うので、小さい方からQ番目が使う要素の最大値y
    C.sort()
    if len(C) < Q:
        continue
    y = C[Q-1]
    ans = min(ans, y - x)
print(ans)


n,k,q=map(int,input().split())
a=list(map(int,input().split()))
ans=10**10
for x in a:
  b=[[]]
  can=0
  for i in a:
    if i<x:
      if len(b[-1]):b.append([])
    else:b[-1].append(i)
  if len(b[-1])==0:del b[-1]
  for i in range(len(b)):b[i].sort()
  c=[]
  for i in b:
    i.sort()
    if len(i)>=k:c+=i[:len(i)-k+1]
  if len(c)<q:continue
  c.sort()
  ans=min(ans,c[q-1]-c[0])
print(ans)

from itertools import*
N,K,Q,*A=map(int,open(0).read().split())
s=sorted
print(min((s(sum((v[:1-K or None]for v in(k*s(v)for k,v in groupby(A,lambda a:a>=Y))),[]))[Q-1:]+[2e9])[0]-Y for Y in A))

import sys
input = sys.stdin.readline

n, k, q = map(int, input().split())
A = list(map(int, input().split())) + [-1]
ans = float("inf")
for a in A:
  L = []
  K = []
  for t in A:
    if t >= a:
      L.append(t)
    else:
      L.sort()
      for c in range(len(L)-k+1):
        K.append(L[c])
      L = []
  K.sort()
  if len(K) < q:
    continue
  else:
    y = K[q-1]
    ans = min(ans, y-a)
print(ans)

import sys
input = sys.stdin.readline

def main():
    n, k, q = list(map(int, input().split()))
    a = list(map(int, input().split()))

    b = [[v, i]for i, v in enumerate(a)]
    b.sort()
    index = [0]*n
    for i in range(n):
        index[i] = b[i][1]

    judge = [[] for i in range(n)]
    already = [-1, n]

    for i in range(n):
        
        for j in range(len(already)-1):
            key = a[already[j]+1:already[j+1]]
            if len(key) >= k:
                judge[i].append(key)
        already.append(index[i])
        already.sort()

    ans = 1e9
    for i in range(n):
        if not judge[i]:
            break
        m = b[i][0]
        sub = []
        for values in judge[i]:
            values.sort()
            for j in range(len(values)-k+1):
                sub.append(values[j])
        sub.sort()
        if len(sub) < q:
            break
        M = sub[q-1]
        ans = min(ans, M-m)

    print(ans)


    
def __starting_point():
    main()


__starting_point()

n,k,q = map(int, input().split())
a = list(map(int, input().split()))

def parse(b):
    ret = []
    tmp = []
    for ai in a:
        if ai >= b:
            tmp.append(ai)
        else:
            if len(tmp) >= k:
                tmp.sort(reverse=True)
                for i in range(k-1,len(tmp)):
                    ret.append(tmp[i])
            tmp = []
    else:
        if len(tmp) >= k:
            tmp.sort(reverse=True)
            for i in range(k-1,len(tmp)):
                ret.append(tmp[i])
    return ret

ans = 10**10

for b in set(a):
    lis = parse(b)
    if len(lis) < q:
        continue
    lis.sort()
    ans_tmp = lis[q-1] - lis[0]
    ans = min(ans, ans_tmp)

print(ans)


"""
Writer: SPD_9X2
https://atcoder.jp/contests/arc098/tasks/arc098_c

Nの制約が小さい→O(N**2) ?

小さい方からQこの集合にするのは簡単→最小を含むように範囲を選んでけば良い
重要なのは最小の奴を飛ばして範囲がちぢめられるとき。

→最小値を全探索するのか？

最小値を決め、それ以下の数字を含まないようにできるだけ小さい方からとっていく？

k以下の数字のindexで配列を切る。O(N)
各数字がどこに属しているかを二分探索で小さい方からとっていく？
O(NlogN)

→O(N**2logN)で解ける(ちょっときつくないですか)
各数字が領域差しておくか前処理して置けばO(N**2)で解けるかな

"""

N,K,Q = list(map(int,input().split()))
a = list(map(int,input().split()))

ai = []
for i in range(N):
    ai.append([a[i],i])
ai.sort()

ans = ai[Q-1][0]-ai[0][0]

for cant in range(N-Q):

    #0 ~ cantまでのai[i]を取ってはいけない

    rannum = [-1] * (cant+2)
    rannum[0] = 0
    indlis = [0] * N #rannumのindexを指し示す

    for i in range(cant+1):

        na,nind = ai[i]
        indlis[nind] += 1


    for i in range(N):

        if i != N-1:
            indlis[i+1] += indlis[i]

        rannum[indlis[i]] += 1

    #print (rannum , indlis)

    ncat = []
    for i in range(cant+1,N):

        na,nind = ai[i]

        if rannum[indlis[nind]] >= K:
            ncat.append(na)
            rannum[indlis[nind]] -= 1

        if len(ncat) == Q:
            ans = min(ans , ncat[-1] - ncat[0])
            break

    #print (ncat)
    
print (ans)

    

   

    


N, K, Q = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = 10 ** 10

for a in A:
    candidates = []
    tmp = []
    for b in A:
        if a <= b:
            tmp.append(b)
        else:
            if K > 1:
                for i in sorted(tmp)[:-K+1]:
                    candidates.append(i)
            else:
                for i in sorted(tmp):
                    candidates.append(i)
            tmp = []
    if K > 1:
        for i in sorted(tmp)[:-K+1]:
            candidates.append(i)
    else:
        for i in sorted(tmp):
            candidates.append(i)
    candidates.sort()
    if len(candidates) >= Q:
        ans = min(ans, candidates[Q-1] - a)
print(ans)


n,k,q=map(int,input().split())
a=list(map(int,input().split()))
ans=10**10
for y in a:
	t=[[]]
	for i in a:
		if i<y:
			if len(t[-1]):t.append([])
		else:
			t[-1].append(i)
	if len(t[-1])==0:del t[-1]
	m=[]
	for i in t:
		if len(i)<k:continue
		m+=sorted(i)[:len(i)-k+1]
	if len(m)<q:continue
	m.sort()
	ans=min(ans,m[q-1]-y)
print(ans)

n, k, q = list(map(int, input().split()))
a = list(map(int, input().split()))

ans = 10 ** 10
for i, y in enumerate(a):
    li = []
    l = 0
    cnd = []
    l_cnd = 0
    for j, x in enumerate(a + [-1]):
        if x < y:
            if l - k + 1 >= 0:
                li.sort()
                cnd += li[:l-k+1]
                l_cnd += l - k + 1
            li = []
            l = 0
        else:
            li.append(x)
            l += 1

    if l_cnd >= q:
        cnd.sort()
        sub = cnd[q-1] - y
        ans = min(ans, sub)

print(ans)


import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

n,k,q=MI()
aa=LI()
pp=list(sorted(set(aa)))

# 最大-最小を返す
def diff(p):
    can=[]
    cur=[]
    for a in aa+[-1]:
        if a<p:
            if len(cur)==n:
                can=cur
                break
            if len(cur)>=k:
                cur.sort()
                if k==1:can+=cur
                else:can+=cur[:-(k-1)]
            cur=[]
        else:
            cur.append(a)
    if len(can)<q:
        return -1
    can.sort()
    res=can[q-1]-can[0]
    return res

#print(pp)
ans=10**16
for p in pp:
    ret=diff(p)
    if ret==-1:break
    #print(p,ret)
    ans=min(ans,ret)

print(ans)


n,k,q = list(map(int, input().split()))
A = list(map(int, input().split()))

ans = 10**18
for x in A:
    B = []
    C = []
    for a in A:
        if a >= x:
            C.append(a)
        else:
            if len(C) >= k:
                C.sort()
                B += C[0:len(C)-k+1]
            C = []
    else:
        if len(C) >= k:
            C.sort()
            B += C[0:len(C)-k+1]
    if len(B) >= q:
        B.sort()
        ans = min(ans, B[q-1]-x)
print(ans)


import sys
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))


N,K,Q = MI()
A = LI()

ans = 10**18
for i in range(N):  # 取り出す要素の最小値はA[i]
    a = A[i]
    left,right = 0,0
    X = []  # 取り出す数の候補
    while right < N:
        if A[right] >= a:
            right += 1
        else:
            if right-left >= K:
                Y = A[left:right]
                Y.sort()
                for j in range(right-left-K+1):
                    X.append(Y[j])
            right += 1
            left = right
    if right-left >= K:
        Y = A[left:right]
        Y.sort()
        for j in range(right-left-K+1):
            X.append(Y[j])
    if len(X) < Q or min(X) != a:
        continue
    X.sort()
    ans = min(ans,X[Q-1]-a)

print(ans)


from itertools import*
N,K,Q,*A=map(int,open(0).read().split())
l=len
s=sorted
print(min(c[Q-1]-Y for c,Y in zip((s(sum((v[:l(v)-K+1]for v in(s(v)for k,v in groupby(A,lambda a:a>=Y)if k)if l(v)>=K),[]))for Y in A),A)if l(c)>=Q))

N, K, Q = list(map(int, input().split()))
A = [int(i) for i in input().split()]

def solve() :
    if Q == 1 : return 0
        
    ret = float('inf')
    for i in range(N) :
        l = -1
        for j in range(i, max(-1, i - K), -1) :
            if A[j] < A[i] :
                l = j
                break
        r = N      
        for j in range(i, min(N, i + K)) :
            if A[j] < A[i] :
                r = j
                break
                
        if r - l - 1 < K :
            continue
            
        B = A[::]
        B.pop(i)
        
        C = [-1]
        for j in range(N - 1) :
            if B[j] < A[i] :
                C.append(j)
        C.append(N - 1)
        
        D = []
        for j in range(len(C) - 1) :
            if C[j+1] - C[j] >= K :
                D += sorted(B[C[j]+1:C[j+1]])[:C[j+1] - C[j] - K]
        
        if len(D) >= Q - 1 :
            D.sort()
            ret = min(ret, D[Q-2] - A[i])

    return ret
    
print((solve()))


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

def calc(x):
    grp = [[]]
    for a in A:
        if a < x and len(grp[-1]) > 0:
            grp.append([])
        if a >= x:
            grp[-1].append(a)
    L = []
    for g in grp:
        g.sort()
        L += g[:max(0, len(g) - K + 1)]
    L.sort()

    if len(L) < Q or L[0] != x:
        return 10**18
    return L[Q - 1] - x

ans = 10**18
for a in A:
    ans = min(ans, calc(a))
print(ans)


n,k,q,*a=map(int,open(0).read().split())
ans=10**18
for y in set(a):
  c=[]
  tmp=[]
  for aa in a:
    if aa>=y:
      tmp.append(aa)
    else:
      if len(tmp)>=k:
        c+=sorted(tmp)[:len(tmp)-k+1]
      tmp=[]
  if len(tmp)>=k:
    c+=sorted(tmp)[:len(tmp)-k+1]
  if len(c)>=q:
    c.sort()
    x=c[q-1]
    ans=min(ans,x-y)
print(ans)

N,K,Q,*A = map(int, open(0).read().split())
ans = 10**10
for i in range(N-K+1):
  c = min(A[i:i+K])
  ls = []
  x = []
  for d in A:
    if d>=c:
      x.append(d)
    else:
      ls.append(x)
      x = []
  ls.append(x)
  m = []
  for x in ls:
    x.sort()
    m += x[:max(len(x)-K+1,0)]
  if len(m)<Q:
    continue
  m.sort()
  y = m[Q-1]
  ans = min(ans,y-c)
print(ans)

import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N,K,Q = LI()
A = LI()

# 最小値を決め打ちすると区間を分割できる

Aval = set(A)
ans = float('inf')
for a in Aval:
    now = []
    mins = []
    num = 0
    for i in range(N):
        if A[i] >= a:
            now.append(A[i])
        else:
            if len(now) >= K:
                now.sort()
                mins.extend(now[:len(now)-K+1])
                num += len(now)-K+1
            now = []
    if len(now) >= K:
        now.sort()
        mins.extend(now[:len(now)-K+1])
        num += len(now)-K+1
    if num >= Q:
        mins.sort()
        if mins[Q-1]-a < ans:
            ans = mins[Q-1]-a

print(ans)

n,k,q = list(map(int, input().split()))
A = list(map(int, input().split()))

ans = 10**18
for x in A:
    B = []
    C = []
    for a in A:
        if a >= x:
            C.append(a)
        else:
            if len(C) >= k:
                C.sort()
                B += C[0:len(C)-k+1]
            C = []
    else:
        if len(C) >= k:
            C.sort()
            B += C[0:len(C)-k+1]
    if len(B) >= q:
        B.sort()
        ans = min(ans, B[q-1]-x)
print(ans)


n,k,q=list(map(int,input().split()))
a=list(map(int,input().split()))
ans=10**9
for i in a:
    A=[]
    l=[]
    ln=0
    for j in a+[-1]:
      if i>j:
        if ln-k+1>=0:
          l.sort()
          A+=l[:ln-k+1]
        l=[]
        ln=0
      else:
        l.append(j)
        ln+=1
    if len(A)<q:
      continue
    else:
      A.sort()
      ans=min(ans,A[q-1]-i)
print(ans)

from collections import defaultdict
from bisect import bisect_left

n,k,q = map(int,input().split())
a = list(map(int,input().split()))
s = sorted(list(set(a)))
dic = defaultdict(list)
for i,j in enumerate(a):
    dic[j].append(i)

ans = 10**20
use = [-1,n]

for i in range(len(s)):
    l = []
    for j in range(len(use)-1):
        x,y = use[j],use[j+1]
        if y-x-1 >= k:
            l2 = []
            for t in range(x+1,y):
                l2.append(a[t])
            l2.sort()
            for t in range(y-x-k):
                l.append(l2[t])
    if len(l) >= q:
        l.sort()
        ans = min(ans,l[q-1]-l[0])
    for j in dic[s[i]]:
        use.insert(bisect_left(use,j),j)
print(ans)

n, k, q = list(map(int, input().split()))
a = list(map(int, input().split()))

ans = 10 ** 10
for y in a:
    li = []
    l = 0
    cnd = []
    l_cnd = 0
    for x in a + [-1]:
        if x < y:
            if l - k + 1 >= 0:
                li.sort()
                cnd += li[:l-k+1]
                l_cnd += l - k + 1
            li = []
            l = 0
        else:
            li.append(x)
            l += 1

    if l_cnd >= q:
        cnd.sort()
        sub = cnd[q-1] - y
        ans = min(ans, sub)

print(ans)


import bisect
n,k,q = map(int,input().split())
a = list(map(int,input().split()))
if q == 1:
  print(0)
  return()
ls = [-1,n]
b = sorted(((a[i],i) for i in range(n)))
ansls = [b[q-1][0]-b[0][0]]
space = [n]
qc = q
for i,x in enumerate(b):
  for j in range(i,n):
    idx = bisect.bisect_left(ls,b[j][1])
    if space[idx-1] < k:
      continue
    qc -= 1
    space[idx-1] -= 1
    if qc == 0:
      ansls.append(b[j][0]-x[0])
      break
  ins = bisect.bisect_left(ls,x[1])
  ls.insert(ins,x[1])
  space = []
  qc = q
  for j in range(1,i+3):
    space.append(ls[j]-ls[j-1]-1)
print(min(ansls))

# 解説AC
N,K,Q = map(int, input().split())
A = [int(i) for i in input().split()]

def main():
    ans = float("inf")

    # A[i]: 最小値X
    for i in range(N):
        # 最大値Yの候補
        can = []

        # A[left:right]: A[i]以上の連続部分列
        left = 0
        while left < N:
            right = left
            while right < N and A[i] <= A[right]:
                right += 1

            # 連続部分列長
            L = right - left

            tmp = sorted([A[j] for j in range(left, right)])
            can += tmp[:max(0, L - K + 1)]

            left = right + 1
        
        # Q番目に小さいものがYの最小値
        can.sort()
        if len(can) >= Q:
            ans = min(ans, can[Q - 1] - A[i])

    print(ans)

def __starting_point():
    main()
__starting_point()

#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True  and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

import heapq
n,k,q = inm()
a = inl()
mn = BIG
for i in range(n):
    #ddprint(f"{i=}")
    lo = a[i]
    gr = []
    bg = -1
    for j in range(n):
        #ddprint(f"  {j=} {lo=} {bg=} {a[j]=}")
        if lo<=a[j]:
            if bg<0:
                bg = j
        else:
            if bg>=0:
                if j>=bg+k:
                    gr.append((bg,j))
                bg = -1
    if bg>=0 and n>=bg+k:
        gr.append((bg,n))
    ddprint(gr)
    h = []
    for bg,ed in gr:
        b = a[bg:ed]
        b.sort()
        #ddprint(f"{bg=} {ed=} {b=}")
        for j in range(len(b)-k+1):
            heapq.heappush(h,b[j])
    ddprint(h)
    if len(h)<q:
        continue
    mn0 = BIG
    mx = -1
    for j in range(q):
        v = heapq.heappop(h)
        mx = max(mx,v)
        mn0 = min(mn0,v)
    mn = min(mn,mx-mn0)
print(mn)


from collections import defaultdict
from bisect import bisect_left

n,k,q = map(int,input().split())
a = list(map(int,input().split()))
s = sorted(list(set(a)))
dic = defaultdict(list)
for i,j in enumerate(a):
    dic[j].append(i)

ans = 10**20
use = [-1,n]

for i in range(len(s)):
    l = []
    for j in range(len(use)-1):
        x,y = use[j],use[j+1]
        if y-x-1 >= k:
            l2 = []
            for t in range(x+1,y):
                l2.append(a[t])
            l2.sort()
            for t in range(y-x-k):
                l.append(l2[t])
    if len(l) >= q:
        l.sort()
        ans = min(ans,l[q-1]-l[0])
    for j in dic[s[i]]:
        use.insert(bisect_left(use,j),j)
print(ans)

import sys
from heapq import *

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
res = 0


def resolve():
    n, k, q = list(map(int, input().split()))
    A = list(map(int, input().split()))

    res = f_inf
    for i in range(n):
        section = []
        pick = []
        for j in range(n):
            if A[j] < A[i]:
                l = len(section) - k + 1
                for _ in range(l):
                    pick.append(heappop(section))
                section.clear()
            else:
                heappush(section, A[j])
        l = len(section) - k + 1
        for _ in range(l):
            pick.append(heappop(section))

        if len(pick) >= q:
            pick.sort()
            res = min(res, pick[q - 1] - pick[0])
    print(res)


def __starting_point():
    resolve()

__starting_point()

import sys
input = sys.stdin.readline
N, K, Q = map(int, input().split())
a = list(map(int, input().split()))
tt = a[: ]
inf = 10 ** 10
res = inf + 0
for mn in sorted(set(a)):
  t = [[]]
  for i in range(N):
    if tt[i] == inf:
      if t[-1] != []: t.append([])
    else: t[-1].append(a[i])
  ttt = []
  for i in range(len(t)):
    t[i].sort()
    for j in range(len(t[i]) - K + 1):
      ttt.append(t[i][j])
  if len(ttt) < Q: break
  ttt.sort()
  res = min(res, ttt[Q - 1] - ttt[0])
  for i in range(N):
    if a[i] == mn: tt[i] = inf
print(res)

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

Ac = [(a, i) for i, a in enumerate(A)]
Ac.sort()
#print(Ac)
ans = Ac[Q-1][0] - Ac[0][0]
imps = [N]
for j in range(N):
  a, i = Ac[j]
  imps.append(i)
  imps.sort()
  kp = 0
  possibles = []
  for k in imps:
    if k - kp >= K:
      Ak = A[kp:k]
      Ak.sort()
      #print(Ak)
      possibles += Ak[:len(Ak)-K+1]
    kp = k+1
  
  if len(possibles) < Q: break
  possibles.sort()
  #print(possibles, imps, possibles[Q-1] - possibles[0])
  ans = min(ans, possibles[Q-1] - possibles[0])
  
print(ans)


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

def calc(x):
    grp = [[]]
    for a in A:
        if a < x and len(grp[-1]) > 0:
            grp.append([])
        if a >= x:
            grp[-1].append(a)
    L = []
    for g in grp:
        g.sort()
        L.extend(g[:max(0, len(g) - K + 1)])
    L.sort()

    if len(L) < Q or L[0] != x:
        return 10**18
    return L[Q - 1] - x

ans = 10**18
for a in A:
    ans = min(ans, calc(a))
print(ans)


N, K, Q = map(int, input().split())
A = [int(a) for a in input().split()]
S = set(A)
I = sorted(list(S))
m = len(I)
D = {a: i for i, a in enumerate(I)}
ans = 1 << 30
for i in range(m):
    l = I[i]
    LL = []
    L = []
    for a in A:
        if a < l:
            if L:
                if len(L) >= K:
                    LL += sorted(L)[:len(L) - K + 1]
                L = []
        else:
            L.append(a)
    if L:
        if len(L) >= K:
            LL += sorted(L)[:len(L) - K + 1]
    if len(LL) >= Q:
        ans = min(ans, sorted(LL)[Q-1] - l)
print(ans)

import sys
def main():
    input = sys.stdin.readline
    N,K,Q=map(int, input().split())
    *A,=map(int, input().split())

    ans=10**10
    from heapq import heappop, heappush
    A.append(-1)
    for y in A:
        if y==-1: break
        c=[]
        t=[]
        for a in A:
            if a >= y:
                heappush(t, a)
            else:
                for _ in range(len(t)-(K-1)):
                    heappush(c, heappop(t))
                t=[]
        if len(c) < Q: continue
        x=[heappop(c) for _ in range(Q)][-1]
        ans = min(ans, x-y)
    print(ans)

def __starting_point():
    main()
__starting_point()

from itertools import*
N,K,Q,*A=map(int,open(0).read().split())
s=sorted
print(min((s(sum((v[:1-K or N]for v in(k*s(v)for k,v in groupby(A,lambda a:a>=Y))),[]))[Q-1:]+[2e9])[0]-Y for Y in A))

def main():
    from collections import Counter as ct
    n, k, q = map(int, input().split())
    a = list(map(int, input().split()))
    c = ct(a).keys()
    a += [0]
    ans = []
    for i in c:
        temp = []
        temp2 = []
        for j in a:
            if j >= i:
                temp2.append(j)
            else:
                if temp2:
                    temp2.sort()
                    if len(temp2) >= k:
                        for l in temp2[:len(temp2)-k+1]:
                            temp.append(l)
                    temp2 = []
        if len(temp) >= q:
            temp.sort()
            ans.append(temp[q-1]-i)
    print(min(ans))


main()

from itertools import*
N,K,Q,*A=map(int,open(0).read().split())
s=sorted
print(min((s(sum((v[:max(0,-~(len(v)-K))]for v in(k*s(v)for k,v in groupby(A,lambda a:a>=Y))),[]))[Q-1:]or[2e9])[0]-Y for Y in A))

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

def find_maximum(y):
  C = [[]]
  for a in A:
    if a < y:
      if len(C[-1]) > 0:
        C.append([])
    else:
      C[-1].append(a)
  cand_x = []
  for Ci in C:
    m = len(Ci)
    if m >= K:
      Ci.sort()
      cand_x += Ci[:m-K+1]
  if len(cand_x) >= Q:
    cand_x.sort()
    return cand_x[Q-1], cand_x[0]
  else:
    return 10**18, 0

ans = 10**18
for a in A:
  x, y = find_maximum(a)
  ans = min(ans, x-y)

print(ans)

import sys
input = sys.stdin.readline

N, K, Q = map(int, input().split())
A = list(map(int, input().split()))
ans = float('inf')
for lb in sorted(A):
    tmp = []
    use = []
    for a in A + [-1]:
        if a >= lb:
            tmp.append(a)
        else:
            if len(tmp) >= K:
                use += sorted(tmp)[:len(tmp)-K+1]
            tmp = []
    if len(use) < Q:
        break
    ans = min(ans, sorted(use)[Q-1] - lb)
print(ans)

from collections import defaultdict
import heapq

n, k, q = map(int, input().split())
a = list(map(int, input().split()))
ok = [0] * n
d = defaultdict(lambda : set())
h = []
for i in range(k - 1):
    heapq.heappush(h, [a[i], i])
    d[a[i]].add(i)
for i in range(k - 1, n):
    heapq.heappush(h, [a[i], i])
    d[a[i]].add(i)
    while h:
        if h[0][1] >= i - k + 1:
            break
        heapq.heappop(h)
    m = list(d[h[0][0]])
    for j in m:
        if j >= i - k + 1:
            ok[j] = 1
        d[h[0][0]].remove(j)
ans = 1145141919810
for i in range(n):
    if ok[i]:
        s, t = [], []
        for j in range(n):
            if a[i] > a[j]:
                s.sort()
                for l in range(max(0, len(s) - k + 1)):
                    t.append(s[l])
                s = []
            else:
                s.append(a[j])
        s.sort()
        for l in range(max(0, len(s) - k + 1)):
            t.append(s[l])
        t.sort()
        if len(t) >= q:
            ans = min(ans, t[q - 1] - t[0])
print(ans)

from collections import defaultdict, deque, Counter
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

#############
# Main Code #
#############

"""
数列A
長さKの連続する部分列を1つ選ぶ　
その中の最小のものを取り除く　infにすれば？
取り除いた要素の最大値 - 最小値をマイナスにしたい　二分探索とかできる?
最終形をイメージする

一番望ましいのは
Q個について最小区間のQ個を取ること
それより小さい要素を取らずに都合のいいとこだけ取りたい
小さい順に仕切りを立てていく
まず小さい順に1 2 3 4...これは必ず取れる　（1 2 3 5...とかは1234より大きくなる）
次に2 3 4 5を取れるか
N個目の数って難しくない？

5 3 2
4 3 1 5 2 の場合
4 3 [1 5 2]
4 [3 5 2]

N <= 2000なので 1, 2, 3, 4で区切っていくのはできそう
Qの中に1を入れる場合、求める値はAq - A1

1 1 3 5 6 7 の場合
1番目の1以降を使うと 1 1 3 5
2番目の1以降を使うと 1 3 5 6
3以降を使うと       3 5 6 7
なので3以降を使う方がいい
Q = 4の時、候補となるのは
[小さい方から1番目、2番目、3番目...] or
[小さい方から2番目、3番目、4番目...] or...

ただし、[小さい方から2番目、3番目、4番目...]を作るには選択範囲に小さい方から1番目を含めないことが必要
4 3 1 5 2 の場合
　　 ×     1は障害物になる
ブロック1:[4, 3]
ブロック2:[5, 2] の中でしかKを回せない
[小さい方から3番目、4番目、5番目...]の場合
ブロック1:[4, 3]
ブロック2:[5]
"""

N, K, Q = getNM()
A = getList()
point = sorted([[A[i], i] for i in range(N)])

flag = [0] * N
ans = float('inf')

for i in range(N):
    s = []
    opt = []
    for j in range(N):
        if flag[j] == 1: # しきりあれば　
            s = []
        else: # しきりなければ
            heappush(s, A[j])
            if len(s) >= K:
                opt.append(heappop(s))

    opt.sort()
    if len(opt) >= Q:
        ans = min(ans, opt[Q - 1] - opt[0])
    # 仕切りを立てる
    flag[point[i][1]] = 1

print(ans)

import sys
input = sys.stdin.readline

n, k, q = map(int, input().split())
A = list(map(int, input().split())) + [-1]
ans = float("inf")
for a in A:
  L = []
  K = []
  for t in A:
    if t >= a:
      L.append(t)
    else:
      L.sort()
      for c in range(len(L)-k+1):
        K.append(L[c])
      L = []
  K.sort()
  if len(K) < q:
    continue
  else:
    y = K[q-1]
    ans = min(ans, y-a)
print(ans)

n, k, q = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 10000000000000
for m in a:
    res = []
    l = []
    for x in a:
        if x < m and l:
            if len(l) >= k:
                l.sort()
                for p in l[:len(l) - k + 1]:
                    res.append(p)
            l = []
        elif x >= m:
            l.append(x)
    if l:
        if len(l) >= k:
            l.sort()
            for p in l[:len(l) - k + 1]:
                res.append(p)
    res.sort()
    if len(res) >= q:
        ans = min(ans, res[q - 1] - m)
if ans == 10000000000000:
    print((-1))
else:
    print(ans)


import sys
input = sys.stdin.readline

import heapq as hp


def main():
    N, K, Q = map(int, input().split())
    A = list(map(int, input().split()))

    NUM = sorted(list(set(A)))

    ans = 10**10
    for n in NUM:
        Qs = []
        q = []
        for i in range(N):
            if A[i] < n:
                if q:
                    Qs.append(q)
                    q = []
                continue
            if not q:
                q = [A[i]]
            else:
                hp.heappush(q, A[i])
        if q:
            Qs.append(q)
        P = []
        for q in Qs:
            l = len(q)
            if l < K: continue
            for _ in range(min(Q, l-K+1)):
                v = hp.heappop(q)
                P.append(v)
        if len(P) < Q:
            break
        P.sort()
        ans = min(ans, P[Q-1]-P[0])
    print(ans)


def __starting_point():
    main()
__starting_point()

import sys
input = sys.stdin.readline

N, K, Q = map(int, input().split())
A = list(map(int, input().split()))
cannot_use = set([-1])
ans = float('inf')
for i in sorted(A):
    tmp = []
    use = []
    for a in A + [-1]:
        if a not in cannot_use:
            tmp.append(a)
        else:
            if len(tmp) >= K:
                tmp.sort()
                use += tmp[:len(tmp)-K+1]
            tmp = []
    use.sort()
    if len(use) < Q:
        break
    ans = min(ans, use[Q-1] - i)
    cannot_use.add(i)
print(ans)

# 解説AC
N,K,Q = map(int, input().split())
A = [int(i) for i in input().split()]

ans = float("inf")

# A[i]: 最小値X
for i in range(N):
    # 最大値Yの候補
    can = []

    # A[left:right]: A[i]以上の連続部分列
    left = 0
    while left < N:
        right = left
        while right < N and A[i] <= A[right]:
            right += 1

        # 連続部分列長
        L = right - left

        tmp = sorted([A[j] for j in range(left, right)])
        can += tmp[:max(0, L - K + 1)]

        left = right + 1
    
    # Q番目に小さいものがYの最小値
    can.sort()
    if len(can) >= Q:
        ans = min(ans, can[Q - 1] - A[i])

print(ans)

def main():
    N, K, Q, *A = map(int, open(0).read().split())

    ans = float("inf")
    for Y in set(A):
        C = []
        tmp = []
        for a in A:
            if a >= Y:
                tmp.append(a)
            else:
                if len(tmp) >= K:
                    C += sorted(tmp)[:len(tmp) - K + 1]
                tmp = []
        if len(tmp) >= K:
            C += sorted(tmp)[:len(tmp) - K + 1]

        if len(C) >= Q:
            C.sort()
            X = C[Q - 1]
            ans = min(ans, X - Y)

    print(ans)

main()

n,k,q = map(int, input().split())
a = list(map(int, input().split()))

ans=10**15
for i in range(n):
    x=a[i]
    y_cand=[]
    lis=[]

    for j in range(n):
        if a[j] < x:
            if len(lis)-k+1 >= 0:
                lis.sort()
                y_cand.extend(lis[:len(lis)-k+1])
            lis=[]
        else:
            lis.append(a[j])

    if len(lis)-k+1 >= 0:
        lis.sort()
        y_cand.extend(lis[:len(lis)-k+1])

    if len(y_cand) >= q:
        y_cand.sort()
        y = y_cand[q-1]
        ans = min(ans,abs(x-y))

print(ans)

import sys
input = sys.stdin.readline
import heapq as hp

N, K, Q = list(map(int, input().split()))
A = list(map(int, input().split()))
Xs = sorted(list(set(A)))

ans = 10**14
for x in Xs:
    Ps = []
    tmp = []
    for a in A:
        if a >= x:
            tmp.append(a)
        else:
            if len(tmp) >= K:
                Ps.append(tmp)
            tmp = []
    if len(tmp) >= K:
        Ps.append(tmp)
    q = []
    for P in Ps:
        P.sort()
        for i, p in enumerate(P):
            q.append(p)
            if len(P)-K-i == 0: break
    if len(q) < Q:
        break
    q.sort()
    ans = min(ans, q[Q-1]-x)

print(ans)


N,K,Q=map(int, input().split())
*A,=map(int, input().split())

import heapq
ans = 10**10
A.append(-1)
for y in A:
    if y==-1: break
    p,q=[],[]
    for a in A:
        if a >= y:
            heapq.heappush(p, a)
        else:
            for i in range(max(0,len(p)-(K-1))):
                heapq.heappush(q, heapq.heappop(p))
            p=[]
    if len(q) < Q: continue
    x = -1
    for i in range(Q):
        x = heapq.heappop(q)
    ans = min(ans, x-y)
print(ans)

# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N,K,Q=map(int,input().split())
A=list(map(int,input().split()))
if Q==1:
    print(0)
    return()
ans=INF
for i,Y in enumerate(A):
    seqs=[]
    tmp=[]
    for j,x in enumerate(A):
        if i==j:
            continue
        if x>=Y:
            tmp.append(x)
        else:
            if tmp:
                tmp.sort()
                seqs.append(tmp)
                tmp=[]
    if tmp:
        tmp.sort()
        seqs.append(tmp)
    l=[]
    for seq in seqs:
        if len(seq)>=K:
            l.extend(seq[:(len(seq)-K+1)])
    l.sort()
    if len(l)>=Q-1:
        X=l[Q-2]
        ans=min(ans,X-Y)
print(ans)

n,k,q=map(int, input().split())
if q==1:
    print(0)
    return()
*a,=map(int, input().split())
a+=[-1]
ans=10**10
for i in range(n):
    ai=a[i]
    tmp=[10**11]##15行目でtmp[:0]になるから
    tmp2=[ai]
    for j in range(n+1):
        if i==j:
            continue
        if a[j]<ai:
            tmp.sort()
            if len(tmp)>=k+1:
                tmp2+=tmp[:-k]
            tmp=[10**11]###
        else:
            tmp.append(a[j])
            #print("test",tmp)
    tmp2.sort()
#    print(tmp,tmp2)
    if len(tmp2)>=q:    
#        print("test2")
        ans=min(ans,tmp2[q-1]-ai)
print(ans)

from itertools import*
N,K,Q,*A=map(int,open(0).read().split())
s=sorted
print(min((s(sum((v[:max(0,len(v)-K+1)]for v in(k*s(v)for k,v in groupby(A,lambda a:a>=Y))),[]))[Q-1:]or[2e9])[0]-Y for Y in A))

import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))


"""
各Aiについて「その数を選ばないで，何回の行動ができますか」がわかればいけるかも?
いや，なんか違いそう．

メモ:一応，小さいものがいいわけではない，K=1,Q=2で1,10,100,101とかなら後ろ二つを取りたい

強制的に使う必要があるものがある場合，それ付近で考える?うーん
入力例2とかを見ると「強制で取らないといけないものがない場合は自由に取れる」みたいに見えるけど，部分的にお此れを撮る前にアレを取らなきゃみたいな前提条件みたいなのは出てくる

順番があるので有向グラフを作るか．
入力例1では，1を取らないと2,3は取れないので1から2,3に辺を貼る
グラフができてもどうするんだこれ，i番目から始めた場合jまでいく必要がある，みたいなのを求めていくか-,
N<=2000ならそれでいける?
これ，最小費用流で解けるかも?
s→all→tをつける．頂点間はcap1，コストが差の値で辺を．
いや，これ入力例3みたいなパターンに弱そう．

そもそも有向グラフをどう作るか．
区間DPぽくいけるか?1つ消した後にK個見て最小を探す，というのはK+1個見て下から2番目を探すのと同じよな
泥沼な気がする．一旦リセット

i番目から始めた場合にどこまでいくか，みたいな発想は良さそう．
Xを決め打てばYを最大化する問題
Yを決め打てばXを最小化する問題
Yを決め打てば，Y未満は選べなくなるのでいけそう．

使えないと数字が出てくるので，いくつかの区間に分かれる．逆にその区間ないは全て使える．
いや，全てじゃないや．上位(K-1)個以外は全部使える．
Xを最小化したいので，使える数字をしたから選んでいく

"""
def main():
    mod=10**9+7
    N,K,Q=MI()
    A=LI()
    inf=10**10
    
    if Q==1:
        print((0))
        return()
    
    def calc(Y):
        # Yを決め打つ
        L=[]#消せる数字
        temp=[]#今見ている区間
        for a in A:
            if a>=Y:
                temp.append(a)
            else:
                if len(temp)>=K:
                    temp.sort()
                    #消せる=上位勢を除いた数字を追加
                    if K>1:
                        L+=temp[:-(K-1)]
                    else:
                        L+=temp
                    
                    
                temp=[]
        
        # 最後の方に小さい数字がない場合の処理
        if len(temp)>=K:
            temp.sort()
            # print(temp[:-(K-1)])
            if K>1:
                L+=temp[:-(K-1)]
            else:
                L+=temp
        L.sort()
        
        # print(Y,L)
        # print("---")
        if len(L)>=Q:
            return L[Q-1]
        else:
            return inf
        
    ans=inf
    
    for b in A:
        y=b
        x=calc(y)
        temp=x-y
        ans=min(ans,temp)
        
    print(ans)
    
        
            

main()


from heapq import heappush,heappop
N,K,Q=map(int,input().split())
A=list(map(int,input().split()))
ans=float("inf")
for x in A:
    data=[]
    h=[]
    for i in range(N):
        if A[i]>=x:
            heappush(h,A[i])
        else:
            if h:
                data.append(h)
                h=[]
    if h:
        data.append(h)
    lsls=[]
    for h in data:
        for j in range(max(0,len(h)-K+1)):
            lsls.append(heappop(h))
    lsls.sort()
    if len(lsls)>=Q:
        ans=min(ans,lsls[Q-1]-lsls[0])
print(ans)

n, k, q = list(map(int, input().split()))
A = list(map(int, input().split()))

ans = 10 ** 18
for x in A:
    B = []
    C = []
    for a in A:
        if a >= x:
            C.append(a)
        else:
            if len(C) >= k:
                C.sort()
                B += C[0:len(C) - k + 1]
            C = []
    if len(C) >= k:
        C.sort()
        B += C[0:len(C) - k + 1]
    if len(B) >= q:
        B.sort()
        ans = min(ans, B[q - 1] - x)
print(ans)


import sys
input = sys.stdin.readline

import heapq as hp


def main():
    N, K, Q = map(int, input().split())
    A = list(map(int, input().split()))

    NUM = sorted(list(set(A)))

    ans = 10**10
    for n in NUM:
        Qs = []
        q = []
        for i in range(N):
            if A[i] < n:
                if q:
                    Qs.append(q)
                    q = []
                continue
            if not q:
                q = [A[i]]
            else:
                hp.heappush(q, A[i])
        if q:
            Qs.append(q)
        P = []
        for q in Qs:
            l = len(q)
            if l < K: continue
            for _ in range(min(Q, l-K+1)):
                v = hp.heappop(q)
                P.append(v)
        if len(P) < Q:
            break
        P.sort()
        ans = min(ans, P[Q-1]-P[0])
    print(ans)


def __starting_point():
    main()
__starting_point()

N, K, Q = list(map(int, input().split()))
X = list(map(int, input().split()))

r = 10**18
for y in X:
    tmp = []
    tmp2 = []
    for x in X:
        if x < y:
            tmp.sort()
            tn = len(tmp)
            if len(tmp) > K-1:
                tmp2 += tmp[:tn-K+1]
            tmp = []
            continue
        tmp.append(x)
    tmp.sort()
    tn = len(tmp)
    if tn-K+1 > 0:
        tmp2 += tmp[:tn-K+1]
    tmp2.sort()
    if len(tmp2) >= Q:
        r = min(r, tmp2[Q-1] - y)
print(r)


from heapq import heappop,heappush

n,k,q = map(int,input().split())
a = list(map(int,input().split()))

if(q==1):
    print(0)
    return()

ans = max(a)
rem = [0] * n
while(True):
    nums = [[]]
    i = 0
    while(i<n):
        if(rem[i]==0):
            heappush(nums[-1],a[i])
        else:
            if(nums[-1]):
                nums.append([])
        i += 1

    mins = []
    for hq in nums:
        while(len(hq) >= k):
            mins.append( heappop(hq) )

    if(len(mins) < q):
        print(ans)
        return()

    mins.sort()
    y = mins[0]
    x = mins[q-1]
    ans = min(ans, x-y)
    for i,ai in enumerate(a):
        if(ai==y):
            rem[i] = 1

def search(x, K, Q, A):
    cand = []
    i = 0
    while i < len(A):
        tmp = []
        while i < len(A):
            if A[i] >= x:
                tmp.append(A[i])
                i += 1
            else:
                i += 1
                break
        if len(tmp) >= K:
            tmp.sort()
            L = len(tmp) - K + 1
            cand.extend(tmp[:L])

    if len(cand) < Q:
        return - 1
    else:
        return sorted(cand)[Q-1]


def main():
    N, K, Q = map(int, input().split())
    A = list(map(int, input().split()))

    if Q == 1:
        return 0

    res = 10**18
    for i, x in enumerate(A):
        rest = A[:i] + A[i + 1:]
        y = search(x, K, Q - 1, rest)
        if y == -1:
            continue
        res = min(res, y - x)
    return res


def __starting_point():
    print(main())
__starting_point()

from itertools import*
N,K,Q,*A=map(int,open(0).read().split())
s=sorted
print(min((s(sum((v[:max(0,len(v)-K+1)]for v in(k*s(v)for k,v in groupby(A,lambda a:a>=Y))),[]))[Q-1:]or[1e10])[0]-Y for Y in A))

def main():
    def calc_x_y(mi):
        """取り除いた要素の最小値がmiとなるように
        操作をQ回行えるか
        行える -> Q回の操作で取り除いた要素の最大値 - mi
        行えない -> -1
        """

        cont = 0
        removed = []
        for i, x in enumerate(a):
            if x < mi:
                if cont >= K:
                    removed += sorted(a[i - cont:i])[:cont - K + 1]
                cont = 0
                continue
            cont += 1
        else:
            if cont >= K:
                removed += sorted(a[-cont:])[:cont - K + 1]

        if len(removed) >= Q:
            removed.sort()
            return removed[Q - 1] - mi
        else:
            return -1

    N, K, Q = list(map(int, input().split()))
    *a, = list(map(int, input().split()))

    mi_cands = sorted(set(a))

    ans = 10 ** 9
    for mi in mi_cands:
        res = calc_x_y(mi)
        if ~res:
            ans = min(ans, res)

    print(ans)


def __starting_point():
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())

__starting_point()

from collections import defaultdict, deque, Counter
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

sys.setrecursionlimit(1000000000)
mod = 998244353

#############
# Main Code #
#############

"""
数列A
長さKの連続する部分列を1つ選ぶ　
その中の最小のものを取り除く　infにすれば？
取り除いた要素の最大値 - 最小値をマイナスにしたい　二分探索とかできる?
最終形をイメージする

一番望ましいのは
Q個について最小区間のQ個を取ること
それより小さい要素を取らずに都合のいいとこだけ取りたい
小さい順に仕切りを立てていく
まず小さい順に1 2 3 4...これは必ず取れる　（1 2 3 5...とかは1234より大きくなる）
次に2 3 4 5を取れるか
N個目の数って難しくない？

5 3 2
4 3 1 5 2 の場合
4 3 [1 5 2]
4 [3 5 2]

N <= 2000なので 1, 2, 3, 4で区切っていくのはできそう
Qの中に1を入れる場合、求める値はAq - A1

1 1 3 5 6 7 の場合
1番目の1以降を使うと 1 1 3 5
2番目の1以降を使うと 1 3 5 6
3以降を使うと       3 5 6 7
なので3以降を使う方がいい
"""

N, K, Q = getNM()
A = getList()
A = [[A[i], i] for i in range(N)]

flag = [0] * N
# 区切り0
l = deepcopy(sorted(A))
opt = []
l.sort()
for i in range(Q):
    opt.append(l[i][0])
ans = opt[-1] - opt[0]

# 区切り1個以上
for i in range(N):
    # indexの位置はlを再利用
    flag[l[i][1]] = 1 # A[i][1]はindex
    parent = []
    child = []
    # フラグの立っているところで区切る
    # 要素の探索はAを使う
    for j in range(N):
        if flag[j] == 0:
            child.append(A[j][0])
        else:
            child.sort()
            parent.append(child)
            child = []
    if len(child):
        child.sort()
        parent.append(child)

    # 値を求める
    # 各childから取れるだけ取る
    opt = []
    for array in parent:
        for j in range(len(array) - K + 1): # childの長さ - K + 1だけ値を取れる
            opt.append(array[j])
    # Q個取れたなら
    if len(opt) >= Q:
        opt.sort()
        ans = min(ans, opt[Q - 1] - opt[0])

print(ans)

n, k, q = list(map(int, input().split()))
a = list(map(int, input().split()))

if q == 1:
    print((0))
    return()

ans = 10 ** 10
for i, y in enumerate(a):
    li = []
    l = 0
    cnd = []
    for j, x in enumerate(a + [-1]):
        if i == j:
            continue
        if x < y:
            if l - k + 1 >= 0:
                li.sort()
                cnd += li[:l-k+1]
            li = []
            l = 0
        else:
            li.append(x)
            l += 1

    if len(cnd) >= q - 1:
        cnd.sort()
        sub = cnd[q-2] - y
        ans = min(ans, sub)

print(ans)


n,k,q=map(int,input().split())
l=list(map(int,input().split()))
ans=10**10
for i in range(n):
    x=l[i]
    tmp=[]
    z=[]
    for j in range(n):
        if l[j]>=x:
            tmp.append(l[j])
        if l[j]<x or j==n-1:
            tmp.sort()
            if len(tmp)-k+1>0:
                z+=tmp[:len(tmp)-k+1]
            tmp=[]
    z.sort()
    if len(z)>=q:
        ans=min(ans,z[q-1]-x)
print(ans)

import sys
from heapq import *

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k, q = list(map(int, input().split()))
    A = list(map(int, input().split()))

    res = f_inf
    for a in A:
        section = []
        tmp = []
        for b in A:
            if b < a:
                if len(tmp) >= k:
                    section.append(tmp)
                tmp = []
            else:
                heappush(tmp, b)
        if len(tmp) >= k:
            section.append(tmp)

        kouho = []
        for sec in section:
            while len(sec) >= k:
                kouho.append(heappop(sec))

        if len(kouho) >= q:
            kouho.sort()
            x = kouho[q - 1]
            y = kouho[0]
            res = min(res, x - y)

    print(res)


def __starting_point():
    resolve()

__starting_point()

n,k,q = map(int, input().split())
A = list(map(int, input().split()))
 
ans = 10**18
for x in A:
    B = []
    C = []
    for a in A:
        if a >= x:
            C.append(a)
        else:
            if len(C) >= k:
                C.sort()
                B += C[0:len(C)-k+1]
            C = []
    else:
        if len(C) >= k:
            C.sort()
            B += C[0:len(C)-k+1]
    if len(B) >= q:
        B.sort()
        ans = min(ans, B[q-1]-x)
print(ans)