#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b, i, c, m, v, f, cnt1 = 0, cnt = 0;
  cin >> a >> b >> c;
  long long int ar[a];
  long long int x[a];
  long long int y[a];
  long long int j = 0, s = 0, l = 0, k;
  for (i = 0; i < a; i++) cin >> ar[i];
  sort(ar, ar + a);
  reverse(ar, ar + a);
  if (b == 1 && c == 1)
    cout << ar[0] - ar[1];
  else {
    if (ar[b - 1] > ar[b])
      cout << ar[b - 1] - ar[b];
    else
      cout << "0";
  }
}
