#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <limits>

using namespace std;

using i64 = long long int;
using u64 = std::uint_fast64_t;
using P = pair<i64, i64>;

struct edge {
    i64 from, to, cost;
    edge(i64 from, i64 to) : from(from), to(to), cost(1) {}
    edge(i64 from, i64 to, i64 cost) : from(from), to(to), cost(cost) {}
};
using Graph = vector<vector<edge>>;

constexpr i64 SINF = std::numeric_limits<i64>::max() / 10;
const i64 MOD = 1000000007;
const i64 dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };
//const i64 dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//const i64 dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//const i64 dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
    for (auto& e : t) fill_v(e, v);
}

struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

template<std::uint_fast64_t mod = 1000000007>
class Modint {
    using u64 = std::uint_fast64_t;
public:
    u64 a;
    constexpr Modint(u64 x = 0) {
        a = x % mod;
    }
    constexpr Modint(const Modint& rhs) {
        a = rhs.a;
    }
    constexpr u64& value() noexcept {
        return a;
    }
    constexpr const u64& value() const noexcept {
        return a;
    }
    constexpr Modint& operator =(const Modint& rhs) {
        a = rhs.a;
        return *this;
    }
    constexpr Modint operator +(const Modint& rhs) const noexcept {
        return Modint(*this) += rhs;
    }
    constexpr Modint operator +(const u64& rhs) const noexcept {
        return Modint(*this) += Modint<mod>(rhs);
    }
    constexpr Modint operator -(const Modint& rhs) const noexcept {
        return Modint(*this) -= rhs;
    }
    constexpr Modint operator -(const u64& rhs) const noexcept {
        return Modint(*this) -= Modint<mod>(rhs);
    }
    constexpr Modint operator *(const Modint& rhs) const noexcept {
        return Modint(*this) *= rhs;
    }
    constexpr Modint operator *(const u64& rhs) const noexcept {
        return Modint(*this) *= Modint<mod>(rhs);
    }
    constexpr Modint operator /(const Modint& rhs) const noexcept {
        return Modint(*this) /= rhs;
    }
    constexpr Modint operator /(const u64& rhs) const noexcept {
        return Modint(*this) /= Modint<mod>(rhs);
    }
    constexpr bool operator ==(const Modint& rhs) const noexcept {
        return a == rhs.a;
    }
    constexpr bool operator !=(const Modint& rhs) const noexcept {
        return a != rhs.a;
    }
    constexpr Modint& operator +=(const Modint& rhs) noexcept {
        a += rhs.a;
        if (a >= mod) a -= mod;
        return *this;
    }
    constexpr Modint& operator -=(const Modint & rhs) noexcept {
        if (a < rhs.a) a += mod;
        a -= rhs.a;
        return *this;
    }
    constexpr Modint& operator *=(const Modint & rhs) noexcept {
        a = a * rhs.a % mod;
        return *this;
    }
    constexpr Modint& operator/=(Modint rhs) noexcept {
        a = (Modint(*this) * rhs.inv()).a;
        return *this;
    }
    constexpr Modint& operator++() noexcept {
        *this += 1;
        return *this;
    }
    constexpr Modint& operator--() noexcept {
        *this -= 1;
        return *this;
    }
    constexpr Modint pow(u64 n) noexcept {
        Modint<mod> r = 1;
        while (n > 0) {
            if (n & 1) {
                r *= *this;
            }
            *this *= *this;
            n >>= 1;
        }
        return r;
    }
    constexpr Modint inv() noexcept {
        return Modint(*this).pow(mod - 2);
    }
};

using mint = Modint<>;

istream& operator>>(istream & os, mint & x) {
    u64 a;
    os >> a;
    x = mint(a);
    return os;
}

ostream& operator<<(ostream & os, const mint & m) noexcept {
    return os << m.a;
}

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    for(int i = 0; i < n; ++i) cin >> d[i];
    sort(d.begin(), d.end());
    int ans = 0;
    int k = 0, idx = 0;
    while (1) {
        if(idx >= n / 2) break;
        if(k >= 1000000) break;
        if(k >= d[idx] && idx + 1 < n && d[idx + 1] <= k){
            ++idx;
        }
        else if (n / 2 == idx + 1) {
            ans = d[idx+1] - d[idx];
            break;
        }
        else {
            ++k;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640