#include <iostream>
#include<vector>
#include <climits>
#include <algorithm>
#include <memory>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>

using namespace std;

bool cmp(const pair<int, int> & a, const pair<int, int> & b) {
    return a.first > b.first;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int k;
    cin >> k;
    map<int, int> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        m[a[i]]++;
    }
    vector<pair<int, int>> often;
    for (auto it = m.begin(); it != m.end(); it++) {
        often.push_back({it -> second, it -> first});
    }
    sort(often.begin(), often.end(), cmp);
    long long l = 1;
    long long r = n + 1;
    vector<int> t;
    while (l + 1 < r) {
        long long mid = (l + r) / 2;
        long long length = 0;
        for (int i = 0; i < often.size(); i++) {
            length += often[i].first / mid;
        }
        // cout << length << endl;
        if (length >= k) {
            t.clear();
            l = mid;
            long long add = 0;
            for (int i = 0; add < k; i++) {
                long long minN = often[i].first / mid;
                if (k - add < minN) {
                    minN = k -add;
                }
                for (int j = 0; j < minN; j++) {
                    t.push_back(often[i].second);
                }
                add += minN;
            }
            if (t.size() != k) {
                return 1;
            }
        }
        else {
            r = mid;
        }
    }
    // cout << l << endl;
    int d = 0;
    for (int i = 0; i < t.size(); i++) {
        cout << t[i] << " ";
    }
    return 0;
}


#include <iostream>
#include<vector>
#include <climits>
#include <algorithm>
#include <memory>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>

using namespace std;

bool cmp(const pair<int, int> & a, const pair<int, int> & b) {
    return a.first > b.first;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int k;
    cin >> k;
    map<int, int> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        m[a[i]]++;
    }
    vector<pair<int, int>> often;
    for (auto it = m.begin(); it != m.end(); it++) {
        often.push_back({it -> second, it -> first});
    }
    sort(often.begin(), often.end(), cmp);
    long long l = 1;
    long long r = n / k + 1;
    vector<pair<int, long long>> t;
    while (l + 1 < r) {
        long long mid = (l + r) / 2;
        long long length = 0;
        for (int i = 0; i < often.size(); i++) {
            length += often[i].first / mid;
        }
        // cout << length << endl;
        if (length >= k) {
            t.clear();
            l = mid;
            int add = 0;
            for (int i = 0; add < k; i++) {
                long long minN = often[i].first / mid;
                if (k - add < minN) {
                    minN = k -add;
                }
                t.push_back({often[i].second, minN});
                add += minN;
            }
        }
        else {
            r = mid;
        }
    }
    // cout << l << endl;
    for (int i = 0; i < t.size(); i++) {
        for (int j = 0; j < t[i].second; j++) {
            cout << t[i].first << " ";
        }
    }
    return 0;
}


#include <iostream>
#include<vector>
#include <climits>
#include <algorithm>
#include <memory>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>

using namespace std;

bool cmp(const pair<int, int> & a, const pair<int, int> & b) {
    return a.first > b.first;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int k;
    cin >> k;
    map<int, int> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        m[a[i]]++;
    }
    vector<pair<int, int>> often;
    for (auto it = m.begin(); it != m.end(); it++) {
        often.push_back({it -> second, it -> first});
    }
    sort(often.begin(), often.end(), cmp);
    long long l = 1;
    long long r = n + 1;
    vector<pair<int, long long>> t;
    while (l + 1 < r) {
        long long mid = (l + r) / 2;
        long long length = 0;
        for (int i = 0; i < often.size(); i++) {
            length += often[i].first / mid;
        }
        // cout << length << endl;
        if (length >= k) {
            t.clear();
            l = mid;
            int add = 0;
            for (int i = 0; add < k; i++) {
                long long minN = often[i].first / mid;
                if (k - add < minN) {
                    minN = k -add;
                }
                t.push_back({often[i].second, minN});
                add += minN;
            }
        }
        else {
            r = mid;
        }
    }
    // cout << l << endl;
    int d = 0;
    for (int i = 0; i < t.size(); i++) {
        for (int j = 0; j < t[i].second; j++) {
            cout << t[i].first << " ";
            d++;
        }
    }
    if (d != k) {
        return 1;
    }
    return 0;
}


#include <iostream>
#include<vector>
#include <climits>
#include <algorithm>
#include <memory>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>

using namespace std;

bool cmp(const pair<int, int> & a, const pair<int, int> & b) {
    return a.first > b.first;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int k;
    cin >> k;
    map<int, int> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        m[a[i]]++;
    }
    vector<pair<int, int>> often;
    for (auto it = m.begin(); it != m.end(); it++) {
        often.push_back({it -> second, it -> first});
    }
    sort(often.begin(), often.end(), cmp);
    long long l = 1;
    long long r = n + 1;
    vector<pair<int, long long>> t;
    while (l + 1 < r) {
        long long mid = (l + r) / 2;
        long long length = 0;
        for (int i = 0; i < often.size(); i++) {
            length += often[i].first / mid;
        }
        // cout << length << endl;
        if (length >= k) {
            t.clear();
            l = mid;
            long long add = 0;
            for (int i = 0; add < k; i++) {
                long long minN = often[i].first / mid;
                if (k - add < minN) {
                    minN = k -add;
                }
                t.push_back({often[i].second, minN});
                add += minN;
            }
        }
        else {
            r = mid;
        }
    }
    // cout << l << endl;
    int d = 0;
    for (int i = 0; i < t.size(); i++) {
        for (int j = 0; j < t[i].second; j++) {
            cout << t[i].first << " ";
            d++;
        }
    }
    if (d > k) {
        return 1;
    }
    return 0;
}


#include <iostream>
#include<vector>
#include <climits>
#include <algorithm>
#include <memory>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>

using namespace std;

bool cmp(const pair<int, int> & a, const pair<int, int> & b) {
    return a.first > b.first;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int k;
    cin >> k;
    map<int, int> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        m[a[i]]++;
    }
    vector<pair<int, int>> often;
    for (auto it = m.begin(); it != m.end(); it++) {
        often.push_back({it -> second, it -> first});
    }
    sort(often.begin(), often.end(), cmp);
    long long l = 1;
    long long r = n + 1;
    vector<int> t;
    while (l + 1 < r) {
        long long mid = (l + r) / 2;
        long long length = 0;
        for (int i = 0; i < often.size(); i++) {
            length += often[i].first / mid;
        }
        // cout << length << endl;
        if (length >= k) {
            t.clear();
            l = mid;
            long long add = 0;
            for (int i = 0; add < k; i++) {
                long long minN = often[i].first / mid;
                if (k - add < minN) {
                    minN = k -add;
                }
                for (int j = 0; j < minN; j++) {
                    t.push_back(often[i].second);
                }
                add += minN;
            }
            if (t.size() != k) {
                return 1;
            }
        }
        else {
            r = mid;
        }
    }
    // cout << l << endl;
    int d = 0;
    for (int i = 0; i < t.size(); i++) {
        cout << t[i] << " ";
        d++;
    }
    if (d != k) {
        return 1;
    }
    return 0;
}


#include <iostream>
#include<vector>
#include <climits>
#include <algorithm>
#include <memory>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>

using namespace std;

bool cmp(const pair<int, int> & a, const pair<int, int> & b) {
    return a.first > b.first;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int k;
    cin >> k;
    map<int, int> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        m[a[i]]++;
    }
    vector<pair<int, int>> often;
    for (auto it = m.begin(); it != m.end(); it++) {
        often.push_back({it -> second, it -> first});
    }
    sort(often.begin(), often.end(), cmp);
    long long l = 1;
    long long r = n / k + 1;
    vector<pair<int, long long>> t;
    while (l + 1 < r) {
        long long mid = (l + r) / 2;
        long long length = 0;
        for (int i = 0; i < often.size(); i++) {
            length += often[i].first / mid;
        }
        // cout << length << endl;
        if (length >= k) {
            t.clear();
            l = mid;
            int add = 0;
            for (int i = 0; add < k; i++) {
                long long minN = often[i].first / mid;
                if (k - add < minN) {
                    minN = k -add;
                }
                t.push_back({often[i].second, minN});
                add += minN;
            }
        }
        else {
            r = mid;
        }
    }
    // cout << l << endl;
    int d = 0;
    for (int i = 0; i < t.size(); i++) {
        for (int j = 0; j < t[i].second; j++) {
            cout << t[i].first << " ";
            d++;
        }
    }
    if (d != k) {
        return 1;
    }
    return 0;
}


#include <iostream>
#include<vector>
#include <climits>
#include <algorithm>
#include <memory>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>

using namespace std;

bool cmp(const pair<int, int> & a, const pair<int, int> & b) {
    return a.first > b.first;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int k;
    cin >> k;
    map<int, int> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        m[a[i]]++;
    }
    vector<pair<int, int>> often;
    for (auto it = m.begin(); it != m.end(); it++) {
        often.push_back({it -> second, it -> first});
    }
    sort(often.begin(), often.end(), cmp);
    long long l = 1;
    long long r = n + 1;
    vector<int> t;
    while (l + 1 < r) {
        long long mid = (l + r) / 2;
        long long length = 0;
        for (int i = 0; i < often.size(); i++) {
            length += often[i].first / mid;
        }
        // cout << length << endl;
        if (length >= k) {
            t.clear();
            l = mid;
            long long add = 0;
            for (int i = 0; add < k; i++) {
                long long minN = often[i].first / mid;
                if (k - add < minN) {
                    minN = k -add;
                }
                for (int j = 0; j < minN; j++) {
                    t.push_back(often[i].second);
                }
                add += minN;
            }
            if (t.size() != k) {
                return 1;
            }
        }
        else {
            r = mid;
        }
    }
    // cout << l << endl;
    int d = 0;
    for (int i = 0; i < t.size(); i++) {
        cout << t[i] << " ";
        d++;
    }
    if (t.size() == 0) {
        return 1;
    }
    return 0;
}


#include <iostream>
#include<vector>
#include <climits>
#include <algorithm>
#include <memory>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>

using namespace std;

bool cmp(const pair<int, int> & a, const pair<int, int> & b) {
    return a.first > b.first;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int k;
    cin >> k;
    map<int, int> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        m[a[i]]++;
    }
    vector<pair<int, int>> often;
    for (auto it = m.begin(); it != m.end(); it++) {
        often.push_back({it -> second, it -> first});
    }
    sort(often.begin(), often.end(), cmp);
    long long l = 1;
    long long r = n + 1;
    vector<pair<int, long long>> t;
    while (l + 1 < r) {
        long long mid = (l + r) / 2;
        long long length = 0;
        for (int i = 0; i < often.size(); i++) {
            length += often[i].first / mid;
        }
        // cout << length << endl;
        if (length >= k) {
            t.clear();
            l = mid;
            long long add = 0;
            for (int i = 0; add < k; i++) {
                long long minN = often[i].first / mid;
                if (k - add < minN) {
                    minN = k -add;
                }
                t.push_back({often[i].second, minN});
                add += minN;
            }
            if (add != k) {
                return 1;
            }
        }
        else {
            r = mid;
        }
    }
    // cout << l << endl;
    int d = 0;
    for (int i = 0; i < t.size(); i++) {
        for (int j = 0; j < t[i].second; j++) {
            cout << t[i].first << " ";
            d++;
        }
    }
    return 0;
}


#include <iostream>
#include<vector>
#include <climits>
#include <algorithm>
#include <memory>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>

using namespace std;

bool cmp(const pair<int, int> & a, const pair<int, int> & b) {
    return a.first > b.first;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int k;
    cin >> k;
    map<int, int> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        m[a[i]]++;
    }
    vector<pair<int, int>> often;
    for (auto it = m.begin(); it != m.end(); it++) {
        often.push_back({it -> second, it -> first});
    }
    sort(often.begin(), often.end(), cmp);
    long long l = 0;
    long long r = n + 1;
    vector<int> t;
    while (l + 1 < r) {
        long long mid = (l + r) / 2;
        long long length = 0;
        for (int i = 0; i < often.size(); i++) {
            length += often[i].first / mid;
        }
        // cout << length << endl;
        if (length >= k) {
            t.clear();
            l = mid;
            long long add = 0;
            for (int i = 0; add < k; i++) {
                long long minN = often[i].first / mid;
                if (k - add < minN) {
                    minN = k -add;
                }
                for (int j = 0; j < minN; j++) {
                    t.push_back(often[i].second);
                }
                add += minN;
            }
            if (t.size() != k) {
                return 1;
            }
        }
        else {
            r = mid;
        }
    }
    // cout << l << endl;
    int d = 0;
    for (int i = 0; i < t.size(); i++) {
        cout << t[i] << " ";
        d++;
    }
    if (t.size() == 0) {
        return 1;
    }
    return 0;
}


#include <iostream>
#include<vector>
#include <climits>
#include <algorithm>
#include <memory>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>

using namespace std;

bool cmp(const pair<int, int> & a, const pair<int, int> & b) {
    return a.first > b.first;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int k;
    cin >> k;
    map<int, int> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        m[a[i]]++;
    }
    vector<pair<int, int>> often;
    for (auto it = m.begin(); it != m.end(); it++) {
        often.push_back({it -> second, it -> first});
    }
    sort(often.begin(), often.end(), cmp);
    long long l = 1;
    long long r = n + 1;
    vector<int> t;
    while (l + 1 < r) {
        long long mid = (l + r) / 2;
        long long length = 0;
        for (int i = 0; i < often.size(); i++) {
            length += often[i].first / mid;
        }
        // cout << length << endl;
        if (length >= k) {
            t.clear();
            l = mid;
            long long add = 0;
            for (int i = 0; add < k; i++) {
                long long minN = often[i].first / mid;
                if (k - add < minN) {
                    minN = k -add;
                }
                for (int j = 0; j < minN; j++) {
                    t.push_back(often[i].second);
                }
                add += minN;
            }
            if (add != k) {
                return 1;
            }
        }
        else {
            r = mid;
        }
    }
    // cout << l << endl;
    int d = 0;
    for (int i = 0; i < t.size(); i++) {
        cout << t[i] << " ";
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

struct num{
    int count = 0;
    int index;
    int used = 0;
}numbers[200010];;
bool acompare(num lhs, num rhs) {
    if(lhs.count == 0) return false;
    if(rhs.count == 0) return true;
    return (float)lhs.count / (lhs.used + 1) > (float)rhs.count / (rhs.used + 1);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k;
    cin >> n >> k;

    // if(n==k){
    //     for(int i=0; i<n; ++i){
    //         int t; cin >> t; cout << t << ' ';
    //     }
    //     return 0;
    // }

    for(int i=0; i<n;++i){
        int t; cin >> t;
        numbers[t].count++;
        numbers[t].index = t;
    }
    sort(numbers, numbers+200010, acompare);

    int next_i = 0;
    vector<int> ans;
    for(int i=0; i<k; next_i++){

        while((float)numbers[next_i].count / (numbers[next_i].used + 1) >= (float)numbers[next_i + 1].count / (numbers[next_i + 1].used + 1) && i < k){
            // cout << numbers[next_i].index << ' ';
            ans.push_back(numbers[next_i].index);
            numbers[next_i].used++;
            i++;
        }
    }

    sort(ans.begin(), ans.end());
    if(n==k){
        for(int i=0; i<k; ++i){
            cout << ans[i] << '-' << numbers[ans[i]].count << ' ';
        }
    }
    else{
        for(int i=0; i<k; ++i){
            cout << ans[i] << ' ';
        }
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

struct num{
    int count = 0;
    int index;
    int used = 0;
};
bool acompare(num lhs, num rhs) { return lhs.count - lhs.used > rhs.count - rhs.used; }

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k;
    cin >> n >> k;
    num numbers[200010];

    for(int i=0; i<n;++i){
        int t; cin >> t;
        numbers[t].count++;
        numbers[t].index = t;
    }

    sort(numbers, numbers+200010, acompare);

    for(int i=0; i<k; ++i){
        cout << numbers[0].index << ' ';
        numbers[0].used++;
        numbers[0].count--;
        sort(numbers, numbers+200010, acompare);
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

struct num{
    int count = 0;
    int index;
    int used = 0;
}numbers[200010];;
bool acompare(num lhs, num rhs) {
    if(lhs.count == 0) return false;
    if(rhs.count == 0) return true;
    return (float)lhs.count / (lhs.used + 1) > (float)rhs.count / (rhs.used + 1);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k;
    cin >> n >> k;

    // if(n==k){
    //     for(int i=0; i<n; ++i){
    //         int t; cin >> t; cout << t << ' ';
    //     }
    //     return 0;
    // }

    for(int i=0; i<n;++i){
        int t; cin >> t;
        numbers[t].count++;
        numbers[t].index = t;
    }
    sort(numbers, numbers+200010, acompare);

    int next_i = 0;
    for(int i=0; i<k; next_i++){

        while((float)numbers[next_i].count / (numbers[next_i].used + 1) >= (float)numbers[next_i + 1].count / (numbers[next_i + 1].used + 1) && i < k){
            cout << numbers[next_i].index << ' ';
            numbers[next_i].used++;
            i++;
        }

        if(!numbers[next_i + 1].count){
            while(i<k){
                cout << numbers[next_i + 1].index << ' ';
                i++;
            }
        }
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

struct num{
    int count = 0;
    int index;
    int used = 0;
}numbers[200010];;
bool acompare(num lhs, num rhs) {
    if(lhs.count == 0) return false;
    if(rhs.count == 0) return true;
    return (float)lhs.count / (lhs.used + 1) > (float)rhs.count / (rhs.used + 1);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k;
    cin >> n >> k;

    // if(n==k){
    //     for(int i=0; i<n; ++i){
    //         int t; cin >> t; cout << t << ' ';
    //     }
    //     return 0;
    // }

    for(int i=0; i<n;++i){
        int t; cin >> t;
        numbers[t].count++;
        numbers[t].index = t;
    }
    sort(numbers, numbers+200010, acompare);

    int next_i = 0;
    vector<int> ans;
    for(int i=0; i<k;){

        if(next_i == 0){
            // cout << "in 0" << endl;
            while((float)numbers[next_i].count / (numbers[next_i].used + 1) >= (float)numbers[next_i + 1].count / (numbers[next_i + 1].used + 1) && i < k){
                ans.push_back(numbers[next_i].index);
                // cout <<  numbers[next_i].index << endl;
                numbers[next_i].used++;
                i++;
            }
            next_i++;
        }
        else{ // next_i > 0
            // cout << "in more" << endl;
            while((float)numbers[next_i].count / (numbers[next_i].used + 1) >= (float)numbers[next_i - 1].count / (numbers[next_i - 1].used + 1) && (float)numbers[next_i].count / (numbers[next_i].used + 1) >= (float)numbers[next_i + 1].count / (numbers[next_i + 1].used + 1) && i < k){
                ans.push_back(numbers[next_i].index);
                // cout <<  numbers[next_i].index << endl;
                numbers[next_i].used++;
                i++;
            }

            if((float)numbers[next_i + 1].count / (numbers[next_i + 1].used + 1) < (float)numbers[next_i - 1].count / (numbers[next_i - 1].used + 1)){
                sort(numbers, numbers+200010, acompare);
                next_i = 0;
            }
            else
                next_i++;
        }
    }

    sort(ans.begin(), ans.end());
    // if(n==k){
    //     for(int i=0; i<k; ++i){
    //         cout << ans[i] << '-' << numbers[ans[i]].count << ' ';
    //     }
    // }
    // else{
        for(int i=0; i<k; ++i){
            cout << ans[i] << ' ';
        }
    // }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

struct num{
    int count = 0;
    int index;
    int used = 0;
}numbers[200010];;
bool acompare(num lhs, num rhs) {
    if(lhs.count == 0) return false;
    if(rhs.count == 0) return true;
    return (float)lhs.count / (lhs.used + 1) > (float)rhs.count / (rhs.used + 1);
}

int next_index(){
    int max_index = 0;
    int max_value = numbers[max_index].count / (numbers[max_index].used + 1);
    for(int i=max_index + 1; i<200010; ++i){
        if(numbers[i].count / (numbers[i].used + 1) > max_value){
            max_value = numbers[i].count / (numbers[i].used + 1);
            max_index = i;
        }
        else if(numbers[i].count == 0)
            return max_index;
    }

    return max_index;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k;
    cin >> n >> k;

    if(n==k){
        for(int i=0; i<n; ++i){
            int t; cin >> t; cout << t << ' ';
        }
        return 0;
    }

    for(int i=0; i<n;++i){
        int t; cin >> t;
        numbers[t].count++;
        numbers[t].index = t;
    }
    sort(numbers, numbers+200010, acompare);

    int next_i = 0;
    for(int i=0; i<k; next_i++){

        while((float)numbers[next_i].count / (numbers[next_i].used + 1) >= (float)numbers[next_i + 1].count / (numbers[next_i + 1].used + 1) && i < k){
            // cout << "* " << numbers[next_i].count / (numbers[next_i].used + 1) << " VS " << numbers[next_i + 1].count / (numbers[next_i + 1].used + 1);
            cout << numbers[next_i].index << ' ';
            numbers[next_i].used++;
            i++;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef pair<int,int> pii;
typedef long long int ll;
typedef tree<pii,null_type,less<pii>,rb_tree_tag, \
tree_order_statistics_node_update> ordered_set;

#define int ll
#define long int
#define pb push_back
#define all int i=0; i<n; i++
#define INF 4*1e18

#define Nirvana ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'

#define T int _;cin>>_;while(_--)

long expo(long base, long exp)
{
    long t = 1L;
    while (exp > 0)
    {
        if (exp % 2 != 0)  t = (t * base);
        base = (base * base);
        exp /= 2;
    }
    return t;
}

#define pow expo

vector<int>a;
vector<int>b;

int sz(vector<int>a){
	return int(a.size());
}
signed main(){
	Nirvana;

	int n,d,m;
	cin>>n>>d>>m;

	int arr[n]; for(all)cin>>arr[i];
	sort(arr, arr+n, greater<int>());

	vector<int>a;
	vector<int>b;

	for(all){
		if(arr[i] > m)a.pb(arr[i]);
		else b.pb(arr[i]);
	}
	int ans = 0;
	int i=0, j = sz(b) - 1;

	for(int k=0; k<sz(a)-1; k++){
		ans+=a[k];
		j-=d;
	}
	while(j >= 0){
		ans+=b[j];
		j--;
	}
	if(sz(a))ans+=a.back();

	cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef pair<int,int> pii;
typedef long long int ll;
typedef tree<pii,null_type,less<pii>,rb_tree_tag, \
tree_order_statistics_node_update> ordered_set;

#define int ll
#define long int
#define pb push_back
#define all int i=0; i<n; i++
#define INF 4*1e18

#define Nirvana ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'

#define T int _;cin>>_;while(_--)

long expo(long base, long exp)
{
    long t = 1L;
    while (exp > 0)
    {
        if (exp % 2 != 0)  t = (t * base);
        base = (base * base);
        exp /= 2;
    }
    return t;
}

#define pow expo

signed main(){
	Nirvana;

	int n,d,m;
	cin>>n>>d>>m;

	int arr[n]; for(all)cin>>arr[i];
	sort(arr, arr+n, greater<int>());

	vector<int>a;
	vector<int>b;

	for(all){
		if(arr[i] > m)a.pb(arr[i]);
		else b.pb(arr[i]);
	}

	int k1 = a.size(), k2 = b.size();

	if(k1==0){
		int idk = 0;
		for(auto i: b)idk+=i;

		cout<<idk<<endl;
		return 0;
	}

	int pref[k1];
	pref[0] = a[0];
	//return 0;

	for(int i=1; i<k1; i++)pref[i] = pref[i-1] + a[i];
	for(int i=1; i<k2; i++)b[i]+=b[i-1];

	int ans = -INF;

	for(int i=1; i<=k1; i++){
		int need = (i-1) * d;
		if(n - i < need)break;

		need -= (k1 - i);

		int ans2 = pref[i-1];

		int z = k2 - need - 1;

		if(z < 0){
			ans2+=0;
		}
		else if(z > k2 - 1){
			if(k2 - 1 >= 0)
			ans2 += b[k2 - 1];
		}
		else ans2+=b[z];

		ans = max(ans, ans2);
	}
	cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define frw(i, a, b) for(int i = a; i < b; i++)
#define fi first
#define se second
#define pb push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) int(a.size())
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define vpii vector<pii>
#define vpiii vector<piii>
#define vpll vector<pll>
#define vplll vector<plll>
#define mod 1000000007

bool comp(ll a, ll b)
{
	return (a>b);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	ll n, d, m;
	cin>>n>>d>>m;

	ll funx;

	vll fun, nofun;
	// fun.pb(0);
	// nofun.pb(0);

	frw(c1,0,n)
	{
		cin>>funx;

		if(funx<=m)
		{
			nofun.pb(funx);
			//fun.pb(0);
		}
		else
		{
			fun.pb(funx);
			//nofun.pb(0);
		}
	}

	sort(all(fun),comp);
	sort(all(nofun),comp);

	frw(c1, 1, max(fun.size(),nofun.size()))
	{
		if(c1<fun.size())
		{
			fun[c1] += fun[c1-1];
		}
		if(c1<nofun.size())
		{
			nofun[c1] += nofun[c1-1];
		}
	}

	ll ans = 0;

	if(((n/(d+1))+(n%(d+1)!=0))<=fun.size())
		ans = fun[((n/(d+1))+(n%(d+1)!=0))-1];
	else if(fun.size()>0)
		ans = fun[fun.size()-1];

	for(int c1=1;c1<=nofun.size();c1++)
	{
		ll tans = nofun[c1-1];
		ll days = n-c1;
		ll pick = (days/(d+1));

		if(days%(d+1)!=0)
			pick++;
		//cout<<tans<<' ';

		if(pick>0 && pick<=fun.size())
			tans += fun[pick-1];

		//cout<<tans<<endl;

		ans = max(tans,ans);
	}

	cout<<ans<<endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define frw(i, a, b) for(int i = a; i < b; i++)
#define fi first
#define se second
#define pb push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) int(a.size())
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define vpii vector<pii>
#define vpiii vector<piii>
#define vpll vector<pll>
#define vplll vector<plll>
#define mod 1000000007

bool comp(ll a, ll b)
{
	return (a>b);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	ll n, d, m;
	cin>>n>>d>>m;

	ll funx;

	vll fun, nofun;
	// fun.pb(0);
	// nofun.pb(0);

	frw(c1,0,n)
	{
		cin>>funx;

		if(funx<=m)
		{
			nofun.pb(funx);
			//fun.pb(0);
		}
		else
		{
			fun.pb(funx);
			//nofun.pb(0);
		}
	}

	sort(all(fun),comp);
	sort(all(nofun),comp);

	frw(c1, 1, max(fun.size(),nofun.size()))
	{
		if(c1<fun.size())
		{
			fun[c1] += fun[c1-1];
		}
		if(c1<nofun.size())
		{
			nofun[c1] += nofun[c1-1];
		}
	}

	ll ans = 0;

	if(((n/(d+1))+(n%(d+1)))<=fun.size())
		ans = fun[((n/(d+1))+(n%(d+1)))-1];
	else
		ans = fun[fun.size()-1];

	for(int c1=1;c1<=nofun.size();c1++)
	{
		ll tans = nofun[c1-1];
		ll days = n-c1;
		ll pick = (days/(d+1));

		if(days%(d+1)!=0)
			pick++;
		//cout<<tans<<' ';

		if(pick>0 && pick<=fun.size())
			tans += fun[pick-1];

		//cout<<tans<<endl;

		ans = max(tans,ans);
	}

	cout<<ans<<endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define frw(i, a, b) for(int i = a; i < b; i++)
#define fi first
#define se second
#define pb push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) int(a.size())
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define vpii vector<pii>
#define vpiii vector<piii>
#define vpll vector<pll>
#define vplll vector<plll>
#define mod 1000000007

bool comp(ll a, ll b)
{
	return (a>b);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	int n, d, m;
	cin>>n>>d>>m;

	ll funx;

	vll nofun, fun;

	frw(c1,0 ,n)
	{
		cin>>funx;

		if(funx<=m)
		{
			nofun.pb(funx);
			fun.pb(0);
		}
		else
		{
			fun.pb(funx);
			nofun.pb(0);
		}
	}

	sort(all(fun),comp);
	sort(all(nofun),comp);

	// frw(c1, 0 ,n)
	// {
	// 	cout<<nofun[c1]<<' '<<fun[c1]<<endl;
	// }

	pair<ll,pair<int,int>> dp[n+d+1][2];

	frw(c1, 0, n+d+1)
	{
		dp[c1][0] = {0,{0,0}};
		dp[c1][1] = {0,{0,0}};
	}

	frw(c1, d+1, n+d+1)
	{
		if(dp[c1-(d+1)][1].fi+nofun[dp[c1-(d+1)][1].se.fi] > dp[c1-1][0].fi+nofun[dp[c1-1][0].se.fi])
		{
			dp[c1][0].fi = dp[c1-(d+1)][1].fi+nofun[dp[c1-(d+1)][1].se.fi];
			dp[c1][0].se.fi = dp[c1-(d+1)][1].se.fi+1;
			dp[c1][0].se.se = dp[c1-(d+1)][1].se.se;
		}
		else
		{
			dp[c1][0].fi = dp[c1-1][0].fi+nofun[dp[c1-1][0].se.fi];
			dp[c1][0].se.fi = dp[c1-1][0].se.fi+1;
			dp[c1][0].se.se = dp[c1-1][0].se.se;
		}

		if(dp[c1-(d+1)][1].fi+fun[dp[c1-(d+1)][1].se.se] > dp[c1-1][0].fi+fun[dp[c1-1][0].se.se])
		{
			dp[c1][1].fi = dp[c1-(d+1)][1].fi+fun[dp[c1-(d+1)][1].se.se];
			dp[c1][1].se.fi = dp[c1-(d+1)][1].se.fi;
			dp[c1][1].se.se = dp[c1-(d+1)][1].se.se+1;
		}
		else
		{
			dp[c1][1].fi = dp[c1-1][0].fi+fun[dp[c1-1][0].se.se];
			dp[c1][1].se.fi = dp[c1-1][0].se.fi;
			dp[c1][1].se.se = dp[c1-1][0].se.se+1;
		}
	}

	// frw(c1, 0, n+d+1)
	// {
	// 	cout<<dp[c1][0].fi<<' '<<dp[c1][0].se.fi<<' '<<dp[c1][0].se.se<<"   ";
	// 	cout<<dp[c1][1].fi<<' '<<dp[c1][1].se.fi<<' '<<dp[c1][1].se.se<<"\n";
	// }

	cout<<max(dp[n+d][0].fi,dp[n+d][1].fi)<<endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define frw(i, a, b) for(int i = a; i < b; i++)
#define fi first
#define se second
#define pb push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) int(a.size())
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define vpii vector<pii>
#define vpiii vector<piii>
#define vpll vector<pll>
#define vplll vector<plll>
#define mod 1000000007

vll nofun, fun;
int p1=0, p2;

bool comp(ll a, ll b)
{
	return (a>b);
}

ll opt(ll in_ans, int d)
{
	//cout<<p1<<' '<<p2<<endl;

	ll pre[nofun.size()+1];
	pre[0] = 0;

	frw(c1, 0, nofun.size())
	{
		pre[c1+1] = pre[c1]+nofun[c1];
		//cout<<pre[c1+1]<<' ';
	}
	//cout<<endl;

	while(p2<fun.size() && p1<nofun.size() && (in_ans-(pre[min((int)nofun.size(),p1+d+1)]-pre[p1])+fun[p2])>in_ans)
	{
		in_ans = in_ans-(pre[min((int)nofun.size(),p1+d+1)]-pre[p1])+fun[p2];
		p2++;
		p1 = min((int)nofun.size(),p1+d+1);
	}

	return in_ans;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	int n, d, m;
	cin>>n>>d>>m;

	ll funx;

	frw(c1,0 ,n)
	{
		cin>>funx;

		if(funx<=m)
		{
			nofun.pb(funx);
			//fun.pb(0);
		}
		else
		{
			fun.pb(funx);
			//nofun.pb(0);
		}
	}

	sort(all(fun),comp);
	sort(all(nofun));

	ll ans = 0;
	int c2 = 0;

	frw(c1, 0, n)
	{
		if(c1<nofun.size())
		{
			ans += nofun[c1];
		}
		else
		{
			ans += fun[c2++];
			p2 = c2;
			c1+=d;
		}
	}

	// frw(c1, 0 ,nofun.size())
	// {
	// 	cout<<nofun[c1]<<' ';
	// }
	// cout<<endl;

	// frw(c1, 0 ,fun.size())
	// {
	// 	cout<<fun[c1]<<' ';
	// }
	// cout<<endl;

	cout<<opt(ans,d)<<endl;

	// pair<ll,pair<int,int>> dp[n+d+1][2];

	// frw(c1, 0, n+d+1)
	// {
	// 	dp[c1][0] = {0,{0,0}};
	// 	dp[c1][1] = {0,{0,0}};
	// }

	// frw(c1, d+1, n+d+1)
	// {
	// 	if(dp[c1-(d+1)][1].fi+nofun[dp[c1-(d+1)][1].se.fi] >= dp[c1-1][0].fi+nofun[dp[c1-1][0].se.fi])
	// 	{
	// 		dp[c1][0].fi = dp[c1-(d+1)][1].fi+nofun[dp[c1-(d+1)][1].se.fi];
	// 		dp[c1][0].se.fi = dp[c1-(d+1)][1].se.fi+1;
	// 		dp[c1][0].se.se = dp[c1-(d+1)][1].se.se;
	// 	}
	// 	else
	// 	{
	// 		dp[c1][0].fi = dp[c1-1][0].fi+nofun[dp[c1-1][0].se.fi];
	// 		dp[c1][0].se.fi = dp[c1-1][0].se.fi+1;
	// 		dp[c1][0].se.se = dp[c1-1][0].se.se;
	// 	}

	// 	if(dp[c1-(d+1)][1].fi+fun[dp[c1-(d+1)][1].se.se] >= dp[c1-1][0].fi+fun[dp[c1-1][0].se.se])
	// 	{
	// 		dp[c1][1].fi = dp[c1-(d+1)][1].fi+fun[dp[c1-(d+1)][1].se.se];
	// 		dp[c1][1].se.fi = dp[c1-(d+1)][1].se.fi;
	// 		dp[c1][1].se.se = dp[c1-(d+1)][1].se.se+1;
	// 	}
	// 	else
	// 	{
	// 		dp[c1][1].fi = dp[c1-1][0].fi+fun[dp[c1-1][0].se.se];
	// 		dp[c1][1].se.fi = dp[c1-1][0].se.fi;
	// 		dp[c1][1].se.se = dp[c1-1][0].se.se+1;
	// 	}
	// }

	// frw(c1, 0, n+d+1)
	// {
	// 	cout<<dp[c1][0].fi<<' '<<dp[c1][0].se.fi<<' '<<dp[c1][0].se.se<<"   ";
	// 	cout<<dp[c1][1].fi<<' '<<dp[c1][1].se.fi<<' '<<dp[c1][1].se.se<<"\n";
	// }

	// cout<<max(dp[n+d][0].fi,dp[n+d][1].fi)<<endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define frw(i, a, b) for(int i = a; i < b; i++)
#define fi first
#define se second
#define pb push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) int(a.size())
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define vpii vector<pii>
#define vpiii vector<piii>
#define vpll vector<pll>
#define vplll vector<plll>
#define mod 1000000007

bool comp(ll a, ll b)
{
	return (a>b);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	ll n, d, m;
	cin>>n>>d>>m;

	ll funx;

	vll fun, nofun;
	// fun.pb(0);
	// nofun.pb(0);

	frw(c1,0,n)
	{
		cin>>funx;

		if(funx<=m)
		{
			nofun.pb(funx);
			//fun.pb(0);
		}
		else
		{
			fun.pb(funx);
			//nofun.pb(0);
		}
	}

	sort(all(fun),comp);
	sort(all(nofun),comp);

	frw(c1, 1, max(fun.size(),nofun.size()))
	{
		if(c1<fun.size())
		{
			fun[c1] += fun[c1-1];
		}
		if(c1<nofun.size())
		{
			nofun[c1] += nofun[c1-1];
		}
	}

	ll ans = 0;

	if(((n/(d+1))+(n%(d+1)))<=fun.size())
		ans = fun[((n/(d+1))+(n%(d+1)))-1];
	else if(fun.size()>0)
		ans = fun[fun.size()-1];

	for(int c1=1;c1<=nofun.size();c1++)
	{
		ll tans = nofun[c1-1];
		ll days = n-c1;
		ll pick = (days/(d+1));

		if(days%(d+1)!=0)
			pick++;
		//cout<<tans<<' ';

		if(pick>0 && pick<=fun.size())
			tans += fun[pick-1];

		//cout<<tans<<endl;

		ans = max(tans,ans);
	}

	cout<<ans<<endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define frw(i, a, b) for(int i = a; i < b; i++)
#define fi first
#define se second
#define pb push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) int(a.size())
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define vpii vector<pii>
#define vpiii vector<piii>
#define vpll vector<pll>
#define vplll vector<plll>
#define mod 1000000007

bool comp(ll a, ll b)
{
	return (a>b);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	ll n, d, m;
	cin>>n>>d>>m;

	ll funx;

	vll fun, nofun;
	// fun.pb(0);
	// nofun.pb(0);

	frw(c1,0,n)
	{
		cin>>funx;

		if(funx<=m)
		{
			nofun.pb(funx);
			//fun.pb(0);
		}
		else
		{
			fun.pb(funx);
			//nofun.pb(0);
		}
	}

	sort(all(fun),comp);
	sort(all(nofun),comp);

	frw(c1, 1, max(fun.size(),nofun.size()))
	{
		if(c1<fun.size())
		{
			fun[c1] += fun[c1-1];
		}
		if(c1<nofun.size())
		{
			nofun[c1] += nofun[c1-1];
		}
	}

	ll ans = 0;

	for(int c1=1;c1<=nofun.size();c1++)
	{
		ll tans = nofun[c1-1];
		ll days = n-c1;
		ll pick = (days/(d+1))+(days%(d+1)!=0);
		//cout<<tans<<' ';

		if(pick>0)
			tans += fun[min((ll)fun.size()-1,pick-1)];

		//cout<<tans<<endl;

		ans = max(tans,ans);
	}

	cout<<ans<<endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define frw(i, a, b) for(int i = a; i < b; i++)
#define fi first
#define se second
#define pb push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) int(a.size())
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define vpii vector<pii>
#define vpiii vector<piii>
#define vpll vector<pll>
#define vplll vector<plll>
#define mod 1000000007

bool comp(ll a, ll b)
{
	return (a>b);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	int n, d, m;
	cin>>n>>d>>m;

	ll funx;

	vll nofun, fun;

	frw(c1,0 ,n)
	{
		cin>>funx;

		if(funx<=m)
		{
			nofun.pb(funx);
			fun.pb(0);
		}
		else
		{
			fun.pb(funx);
			nofun.pb(0);
		}
	}

	sort(all(fun),comp);
	sort(all(nofun),comp);

	// frw(c1, 0 ,n)
	// {
	// 	cout<<nofun[c1]<<' '<<fun[c1]<<endl;
	// }

	pair<ll,pair<int,int>> dp[n+d+1][2];

	frw(c1, 0, n+d+1)
	{
		dp[c1][0] = {0,{0,0}};
		dp[c1][1] = {0,{0,0}};
	}

	frw(c1, d+1, n+d+1)
	{
		if(dp[c1-(d+1)][1].fi+nofun[dp[c1-(d+1)][1].se.fi] >= dp[c1-1][0].fi+nofun[dp[c1-1][0].se.fi])
		{
			dp[c1][0].fi = dp[c1-(d+1)][1].fi+nofun[dp[c1-(d+1)][1].se.fi];
			dp[c1][0].se.fi = dp[c1-(d+1)][1].se.fi+1;
			dp[c1][0].se.se = dp[c1-(d+1)][1].se.se;
		}
		else
		{
			dp[c1][0].fi = dp[c1-1][0].fi+nofun[dp[c1-1][0].se.fi];
			dp[c1][0].se.fi = dp[c1-1][0].se.fi+1;
			dp[c1][0].se.se = dp[c1-1][0].se.se;
		}

		if(dp[c1-(d+1)][1].fi+fun[dp[c1-(d+1)][1].se.se] >= dp[c1-1][0].fi+fun[dp[c1-1][0].se.se])
		{
			dp[c1][1].fi = dp[c1-(d+1)][1].fi+fun[dp[c1-(d+1)][1].se.se];
			dp[c1][1].se.fi = dp[c1-(d+1)][1].se.fi;
			dp[c1][1].se.se = dp[c1-(d+1)][1].se.se+1;
		}
		else
		{
			dp[c1][1].fi = dp[c1-1][0].fi+fun[dp[c1-1][0].se.se];
			dp[c1][1].se.fi = dp[c1-1][0].se.fi;
			dp[c1][1].se.se = dp[c1-1][0].se.se+1;
		}
	}

	frw(c1, 0, n+d+1)
	{
		cout<<dp[c1][0].fi<<' '<<dp[c1][0].se.fi<<' '<<dp[c1][0].se.se<<"   ";
		cout<<dp[c1][1].fi<<' '<<dp[c1][1].se.fi<<' '<<dp[c1][1].se.se<<"\n";
	}

	cout<<max(dp[n+d][0].fi,dp[n+d][1].fi)<<endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define frw(i, a, b) for(int i = a; i < b; i++)
#define fi first
#define se second
#define pb push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) int(a.size())
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define vpii vector<pii>
#define vpiii vector<piii>
#define vpll vector<pll>
#define vplll vector<plll>
#define mod 1000000007

bool comp(ll a, ll b)
{
	return (a>b);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	int n, d, m;
	cin>>n>>d>>m;

	ll funx;

	vll nofun, fun;

	frw(c1,0 ,n)
	{
		cin>>funx;

		if(funx<=m)
		{
			nofun.pb(funx);
			fun.pb(0);
		}
		else
		{
			fun.pb(funx);
			nofun.pb(0);
		}
	}

	sort(all(fun),comp);
	sort(all(nofun),comp);

	// frw(c1, 0 ,n)
	// {
	// 	cout<<nofun[c1]<<' '<<fun[c1]<<endl;
	// }

	pair<ll,pair<int,int>> dp[n+d+1][2];

	frw(c1, 0, n+d+1)
	{
		dp[c1][0] = {0,{0,0}};
		dp[c1][1] = {0,{0,0}};
	}

	frw(c1, d+1, n+d+1)
	{
		if(dp[c1-(d+1)][1].fi+nofun[dp[c1-(d+1)][1].se.fi] >= dp[c1-1][0].fi+nofun[dp[c1-1][0].se.fi])
		{
			dp[c1][0].fi = dp[c1-(d+1)][1].fi+nofun[dp[c1-(d+1)][1].se.fi];
			dp[c1][0].se.fi = dp[c1-(d+1)][1].se.fi+1;
			dp[c1][0].se.se = dp[c1-(d+1)][1].se.se;
		}
		else
		{
			dp[c1][0].fi = dp[c1-1][0].fi+nofun[dp[c1-1][0].se.fi];
			dp[c1][0].se.fi = dp[c1-1][0].se.fi+1;
			dp[c1][0].se.se = dp[c1-1][0].se.se;
		}

		if(dp[c1-(d+1)][1].fi+fun[dp[c1-(d+1)][1].se.se] >= dp[c1-1][0].fi+fun[dp[c1-1][0].se.se])
		{
			dp[c1][1].fi = dp[c1-(d+1)][1].fi+fun[dp[c1-(d+1)][1].se.se];
			dp[c1][1].se.fi = dp[c1-(d+1)][1].se.fi;
			dp[c1][1].se.se = dp[c1-(d+1)][1].se.se+1;
		}
		else
		{
			dp[c1][1].fi = dp[c1-1][0].fi+fun[dp[c1-1][0].se.se];
			dp[c1][1].se.fi = dp[c1-1][0].se.fi;
			dp[c1][1].se.se = dp[c1-1][0].se.se+1;
		}
	}

	// frw(c1, 0, n+d+1)
	// {
	// 	cout<<dp[c1][0].fi<<' '<<dp[c1][0].se.fi<<' '<<dp[c1][0].se.se<<"   ";
	// 	cout<<dp[c1][1].fi<<' '<<dp[c1][1].se.fi<<' '<<dp[c1][1].se.se<<"\n";
	// }

	cout<<max(dp[n+d][0].fi,dp[n+d][1].fi)<<endl;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <cmath>
#include <map>
#include <iomanip>
#define INF 0x3f3f3f3f
#define pi acos(-1)
#define N 1000
typedef long long ll;
using namespace std;

ll q1[N], q2[N];
int n, m ,d;
int cnt1, cnt2;

bool cmp(int tcy, int wyy)
{
    return tcy > wyy;
}

int main()
{
    cnt1 = cnt2 = 0;
    scanf("%d%d%d", &n, &d, &m);
    for(int i = 0; i < n; i++)
    {
        ll x;
        scanf("%lld", &x);
        if(x <= m)
            q1[++cnt1] = x;
        else
            q2[++cnt2] = x;
    }
    sort(q1 + 1, q1 + cnt1 + 1, cmp);
    sort(q2 + 1, q2 + cnt2 + 1, cmp);
    for(int i = 2; i <= cnt1; i++)
        q1[i] += q1[i - 1];
    for(int i = 2; i <= cnt2; i++)
        q2[i] += q2[i - 1];
    ll ans = 0;
    for(int cnt = (cnt2 + d + 1) / (d + 1); cnt <= cnt2 && ((d + 1) * (cnt - 1) + 1 <= n); cnt++) ///大于m的数字个数枚举
    {
        ll sum = q2[cnt] + q1[cnt1 - d * (cnt - 1)];
        //printf("%lld %lld\n", q2[cnt], q1[cnt1 - d * (cnt - 1)]);
        if(sum > ans)
            ans = sum;
    }
    printf("%lld\n", ans);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <cmath>
#include <map>
#include <iomanip>
#define INF 0x3f3f3f3f
#define pi acos(-1)
#define N 100100
typedef long long ll;
using namespace std;

ll q1[N], q2[N];
int n, m ,d;
int cnt1, cnt2;

bool cmp(int tcy, int wyy)
{
    return tcy > wyy;
}

int main()
{
    cnt1 = cnt2 = 0;
    scanf("%d%d%d", &n, &d, &m);
    for(int i = 0; i < n; i++)
    {
        ll x;
        scanf("%lld", &x);
        if(x <= m)
            q1[++cnt1] = x;
        else
            q2[++cnt2] = x;
    }
    sort(q1 + 1, q1 + cnt1 + 1, cmp);
    sort(q2 + 1, q2 + cnt2 + 1, cmp);
    for(int i = 2; i <= n; i++)
        q1[i] += q1[i - 1];
    for(int i = 2; i <= cnt2; i++)
        q2[i] += q2[i - 1];
    ll ans = 0;
    for(int cnt = (cnt2 + d + 1) / (d + 1); cnt <= cnt2 && ((d + 1) * (cnt - 1) + 1 <= n); cnt++) ///大于m的数字个数枚举
    {
        ll sum = q2[cnt] + q1[n - ((d + 1) * (cnt - 1) + 1)];
        //q1[ cnt1 - d * (cnt - 1) ];
        if(sum > ans)
            ans = sum;
    }
    printf("%lld\n", ans);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <cmath>
#include <map>
#include <iomanip>
#define INF 0x3f3f3f3f
#define pi acos(-1)
#define N 100100
typedef long long ll;
using namespace std;

ll q1[N], q2[N];
int n, m ,d;
int cnt1, cnt2;

bool cmp(int tcy, int wyy)
{
    return tcy > wyy;
}

int main()
{
    cnt1 = cnt2 = 0;
    scanf("%d%d%d", &n, &d, &m);
    for(int i = 0; i < n; i++)
    {
        ll x;
        scanf("%lld", &x);
        if(x <= m)
            q1[++cnt1] = x;
        else
            q2[++cnt2] = x;
    }
    sort(q1 + 1, q1 + cnt1 + 1, cmp);
    sort(q2 + 1, q2 + cnt2 + 1, cmp);
    for(int i = 2; i <= cnt1; i++)
        q1[i] += q1[i - 1];
    for(int i = 2; i <= cnt2; i++)
        q2[i] += q2[i - 1];
    ll ans = 0;
    for(int cnt = (cnt2 + d + 1) / (d + 1); cnt <= cnt2 && ((d + 1) * (cnt - 1) + 1 <= n); cnt++) ///大于m的数字个数枚举
    {
        ll sum = q2[cnt] + q1[cnt1 - d * (cnt - 1)];
        //printf("%lld %lld\n", q2[cnt], q1[cnt1 - d * (cnt - 1)]);
        if(sum > ans)
            ans = sum;
    }
    printf("%lld\n", ans);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <cmath>
#include <map>
#include <iomanip>
#define INF 0x3f3f3f3f
#define pi acos(-1)
#define N 100100
typedef long long ll;
using namespace std;

ll q1[N], q2[N];
int n, m ,d;
int cnt1, cnt2;

bool cmp(int tcy, int wyy)
{
    return tcy > wyy;
}

int main()
{
    cnt1 = cnt2 = 0;
    scanf("%d%d%d", &n, &d, &m);
    for(int i = 0; i < n; i++)
    {
        ll x;
        scanf("%lld", &x);
        if(x <= m)
            q1[++cnt1] = x;
        else
            q2[++cnt2] = x;
    }
    sort(q1 + 1, q1 + cnt1 + 1, cmp);
    sort(q2 + 1, q2 + cnt2 + 1, cmp);
    for(int i = 2; i <= n; i++)
        q1[i] += q1[i - 1];
    for(int i = 2; i <= cnt2; i++)
        q2[i] += q2[i - 1];
    ll ans = q1[n];
    for(int cnt = (cnt2 + d + 1) / (d + 1); cnt <= cnt2 && ((d + 1) * (cnt - 1) + 1 <= n); cnt++) ///大于m的数字个数枚举
    {
        ll sum = q2[cnt] + q1[n - ((d + 1) * (cnt - 1) + 1)];
        //q1[ cnt1 - d * (cnt - 1) ];
        if(sum > ans)
            ans = sum;
    }
    printf("%lld\n", ans);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <cmath>
#include <map>
#include <iomanip>
#define INF 0x3f3f3f3f
#define pi acos(-1)
#define N 1000
typedef long long ll;
using namespace std;

ll q1[N], q2[N];
int n, m ,d;
int cnt1, cnt2;

bool cmp(int tcy, int wyy)
{
    return tcy > wyy;
}

int main()
{
    cnt1 = cnt2 = 1;
    scanf("%d%d%d", &n, &d, &m);
    for(int i = 0; i < n; i++)
    {
        ll x;
        scanf("%lld", &x);
        if(x <= m)
            q1[cnt1++] = x;
        else
            q2[cnt2++] = x;
    }
    sort(q1 + 1, q1 + cnt1, cmp);
    sort(q2 + 1, q2 + cnt2, cmp);
    cnt1--;
    cnt2--;
    for(int i = 2; i <= cnt1; i++)
        q1[i] += q1[i - 1];
    for(int i = 2; i <= cnt2; i++)
        q2[i] += q2[i - 1];
    ll ans = 0;
    for(int cnt = (cnt2 + d + 1) / (d + 1); cnt <= cnt2 && ((d + 1) * (cnt - 1) + 1 <= n); cnt++) ///大于m的数字个数枚举
    {
        ll sum = q2[cnt] + q1[cnt1 - d * (cnt - 1)];
        //printf("%lld %lld\n", q2[cnt], q1[cnt1 - d * (cnt - 1)]);
        if(sum > ans)
            ans = sum;
    }
    printf("%lld\n", ans);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <cmath>
#include <map>
#include <iomanip>
#define INF 0x3f3f3f3f
#define pi acos(-1)
#define N 300
typedef long long ll;
using namespace std;

priority_queue <int, vector<int>, greater<int> > q1;
priority_queue <int> q2;
int n, m ,d;

int main()
{
    scanf("%d%d%d", &n, &d, &m);
    for(int i = 0; i < n; i++)
    {
        int x;
        scanf("%d", &x);
        if(x <= m)
            q1.push(x);
        else
            q2.push(x);
    }
    ll ans = 0;
    while((!q1.empty()) && (!q2.empty()))
    {
        ll sum = 0;
        for(int i = 0; i < d; i++)
        {
            sum += q1.top();
            q1.pop();
            if(q1.empty())
                break;
        }
        if(q1.empty())
        {
            ans += sum;
            break;
        }
        if(sum > q2.top())
        {
            ans += sum;
            break;
        }
        ans += q2.top();
        q2.pop();
        if(q2.empty())
            ans += sum;
    }
    while(!q1.empty())
    {
        ans += q1.top();
        q1.pop();
    }
    if(!q2.empty())
    {
        int num = (q2.size() + d + 1) / (d + 1);
        while(num--)
        {
            ans += q2.top();
            q2.pop();
        }
    }
    printf("%lld\n", ans);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <cmath>
#include <map>
#include <iomanip>
#define INF 0x3f3f3f3f
#define pi acos(-1)
#define N 100100
typedef long long ll;
using namespace std;

ll q1[N], q2[N];
int n, m ,d;
int cnt1, cnt2;

bool cmp(int tcy, int wyy)
{
    return tcy > wyy;
}

int main()
{
    cnt1 = cnt2 = 0;
    scanf("%d%d%d", &n, &d, &m);
    for(int i = 0; i < n; i++)
    {
        ll x;
        scanf("%lld", &x);
        if(x <= m)
            q1[++cnt1] = x;
        else
            q2[++cnt2] = x;
    }
    sort(q1 + 1, q1 + cnt1 + 1, cmp);
    sort(q2 + 1, q2 + cnt2 + 1, cmp);
    for(int i = 2; i <= n; i++)
        q1[i] += q1[i - 1];
    for(int i = 2; i <= cnt2; i++)
        q2[i] += q2[i - 1];
    ll ans = 0;
        if(m == 1000000000)
            printf("%d %d\n", cnt1, cnt2);
    for(int cnt = (cnt2 + d + 1) / (d + 1); cnt <= cnt2 && ((d + 1) * (cnt - 1) + 1 <= n); cnt++) ///大于m的数字个数枚举
    {
        ll sum = q2[cnt] + q1[n - ((d + 1) * (cnt - 1) + 1)];
        //q1[ cnt1 - d * (cnt - 1) ];
        if(sum > ans)
            ans = sum;
    }
    printf("%lld\n", ans);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <cmath>
#include <map>
#include <iomanip>
#define INF 0x3f3f3f3f
#define pi acos(-1)
#define N 100100
typedef long long ll;
using namespace std;

ll q1[N], q2[N];
int n, m ,d;
int cnt1, cnt2;

bool cmp(int tcy, int wyy)
{
    return tcy > wyy;
}

int main()
{
    cnt1 = cnt2 = 0;
    scanf("%d%d%d", &n, &d, &m);
    for(int i = 0; i < n; i++)
    {
        ll x;
        scanf("%lld", &x);
        if(x <= m)
            q1[++cnt1] = x;
        else
            q2[++cnt2] = x;
    }
    sort(q1 + 1, q1 + cnt1 + 1, cmp);
    sort(q2 + 1, q2 + cnt2 + 1, cmp);
    for(int i = 2; i <= n; i++)
        q1[i] += q1[i - 1];
    for(int i = 2; i <= cnt2; i++)
        q2[i] += q2[i - 1];
    ll ans = 0;
    for(int cnt = (cnt2 + d + 1) / (d + 1); cnt <= cnt2 && ((d + 1) * (cnt - 1) + 1 <= n); cnt++) ///大于m的数字个数枚举
    {
        ll sum = q2[cnt] + q1[n - ((d + 1) * (cnt - 1) + 1)];
        if(m == 1000000000)
            printf("%lld\n", sum);
        //q1[ cnt1 - d * (cnt - 1) ];
        if(sum > ans)
            ans = sum;
    }
    printf("%lld\n", ans);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <cmath>
#include <map>
#include <iomanip>
#define INF 0x3f3f3f3f
#define pi acos(-1)
#define N 300
typedef long long ll;
using namespace std;

priority_queue <int, vector<int>, greater<int> > q1;
priority_queue <int> q2;
int n, m ,d;

int main()
{
    scanf("%d%d%d", &n, &d, &m);
    for(int i = 0; i < n; i++)
    {
        int x;
        scanf("%d", &x);
        if(x <= m)
            q1.push(x);
        else
            q2.push(x);
    }
    ll ans = 0;
    while((!q1.empty()) && (!q2.empty()))
    {
        ll sum = 0;
        for(int i = 0; i < d; i++)
        {
            sum += q1.top();
            q1.pop();
            if(q1.empty())
                break;
        }
        if(q1.empty())
        {
            ans += sum;
            break;
        }
        if(sum > q2.top())
        {
            ans += sum;
            break;
        }
        ans += q2.top();
        q2.pop();
        if(q2.empty())
            ans += sum;
    }
    while(!q1.empty())
    {
        ans += q1.top();
        q1.pop();
    }
    if(!q2.empty())
    {
        int num = (q2.size() + 3) / 3;
        while(num--)
        {
            ans += q2.top();
            q2.pop();
        }
    }
    printf("%lld\n", ans);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <cmath>
#include <map>
#include <iomanip>
#define INF 0x3f3f3f3f
#define pi acos(-1)
#define N 1000
typedef long long ll;
using namespace std;

ll q1[N], q2[N];
int n, m ,d;
int cnt1, cnt2;

bool cmp(int tcy, int wyy)
{
    return tcy > wyy;
}

int main()
{
    cnt1 = cnt2 = 0;
    scanf("%d%d%d", &n, &d, &m);
    for(int i = 0; i < n; i++)
    {
        ll x;
        scanf("%lld", &x);
        if(x <= m)
            q1[++cnt1] = x;
        else
            q2[++cnt2] = x;
    }
    sort(q1 + 1, q1 + cnt1, cmp);
    sort(q2 + 1, q2 + cnt2, cmp);
    cnt1--;
    cnt2--;
    for(int i = 2; i <= cnt1; i++)
        q1[i] += q1[i - 1];
    for(int i = 2; i <= cnt2; i++)
        q2[i] += q2[i - 1];
    ll ans = 0;
    for(int cnt = (cnt2 + d + 1) / (d + 1); cnt <= cnt2 && ((d + 1) * (cnt - 1) + 1 <= n); cnt++) ///大于m的数字个数枚举
    {
        ll sum = q2[cnt] + q1[cnt1 - d * (cnt - 1)];
        //printf("%lld %lld\n", q2[cnt], q1[cnt1 - d * (cnt - 1)]);
        if(sum > ans)
            ans = sum;
    }
    printf("%lld\n", ans);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <cmath>
#include <map>
#include <iomanip>
#define INF 0x3f3f3f3f
#define pi acos(-1)
#define N 300
typedef long long ll;
using namespace std;

ll q1[N], q2[N];
int n, m ,d;
int cnt1, cnt2;

bool cmp(int tcy, int wyy)
{
    return tcy > wyy;
}

int main()
{
    cnt1 = cnt2 = 1;
    scanf("%d%d%d", &n, &d, &m);
    for(int i = 0; i < n; i++)
    {
        ll x;
        scanf("%lld", &x);
        if(x <= m)
            q1[cnt1++] = x;
        else
            q2[cnt2++] = x;
    }
    sort(q1 + 1, q1 + cnt1, cmp);
    sort(q2 + 1, q2 + cnt2, cmp);
    cnt1--;
    cnt2--;
    for(int i = 2; i <= cnt1; i++)
        q1[i] += q1[i - 1];
    for(int i = 2; i <= cnt2; i++)
        q2[i] += q2[i - 1];
    ll ans = 0;
    for(int cnt = (cnt2 + d + 1) / (d + 1); cnt <= cnt2 && ((d + 1) * (cnt - 1) + 1 <= n); cnt++) ///大于m的数字个数枚举
    {
        ll sum = q2[cnt] + q1[cnt1 - d * (cnt - 1)];
        //printf("%lld %lld\n", q2[cnt], q1[cnt1 - d * (cnt - 1)]);
        if(sum > ans)
            ans = sum;
    }
    printf("%lld\n", ans);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <cmath>
#include <map>
#include <iomanip>
#define INF 0x3f3f3f3f
#define pi acos(-1)
#define N 10010
typedef long long ll;
using namespace std;

ll q1[N], q2[N];
int n, m ,d;
int cnt1, cnt2;

bool cmp(int tcy, int wyy)
{
    return tcy > wyy;
}

int main()
{
    cnt1 = cnt2 = 0;
    scanf("%d%d%d", &n, &d, &m);
    for(int i = 0; i < n; i++)
    {
        ll x;
        scanf("%lld", &x);
        if(x <= m)
            q1[++cnt1] = x;
        else
            q2[++cnt2] = x;
    }
    sort(q1 + 1, q1 + cnt1 + 1, cmp);
    sort(q2 + 1, q2 + cnt2 + 1, cmp);
    for(int i = 2; i <= cnt1; i++)
        q1[i] += q1[i - 1];
    for(int i = 2; i <= cnt2; i++)
        q2[i] += q2[i - 1];
    ll ans = 0;
    for(int cnt = (cnt2 + d + 1) / (d + 1); cnt <= cnt2 && ((d + 1) * (cnt - 1) + 1 <= n); cnt++) ///大于m的数字个数枚举
    {
        ll sum = q2[cnt] + q1[cnt1 - d * (cnt - 1)];
        //printf("%lld %lld\n", q2[cnt], q1[cnt1 - d * (cnt - 1)]);
        if(sum > ans)
            ans = sum;
    }
    printf("%lld\n", ans);
    return 0;
}


#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <string.h>
#include <string>
#include <cmath>
#include <cstdio>
#include <functional>
#include <map>
#include <typeinfo>
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<ll, ll> pl;

int main()
{
    FILE *inF, *outF;
    inF = fopen("in", "r");
    outF = fopen("out", "w");
    inF = stdin;
    outF = stdout;

    int n, d, m;

    fscanf(inF, "%d %d %d", &n, &d, &m);

    vector<int> sv;
    vector<int> bv;

    for (int i = 0; i < n; i++)
    {
        int num;
        fscanf(inF, "%d", &num);

        if (num <= m)
            sv.push_back(num);
        else
            bv.push_back(num);
    }

    sort(sv.begin(), sv.end());
    sort(bv.begin(), bv.end());

    int fp = 0;
    int bp = bv.size() - 1;

    ll res = 0;
    int curd = 0;

    while(bp > 0 && curd < n)
    {
        ll smalls = 0;
        int days = 0;

        for (int i = fp; i < min(fp + min(d, n - curd - 1), (int)sv.size()); i++)
        {
            smalls += sv[i];
            days++;
        }

        if (bv[bp] > smalls)
        {
            res += bv[bp--];
            fp += days;
            curd += days + 1;
        }
        else
        {
            break;
        }
    }

    while (fp < sv.size() && curd < n)
    {
        res += sv[fp++];
        curd++;
    }

    while(bp >= 0 && curd < n)
    {
        res += bv[bp--];
        curd += d + 1;
    }

    fprintf(outF, "%lld", res);

    return 0;
}
//인풋 바꾸기!!!!


#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <string.h>
#include <string>
#include <cmath>
#include <cstdio>
#include <functional>
#include <map>
#include <typeinfo>
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<ll, ll> pl;

int main()
{
    FILE *inF, *outF;
    inF = fopen("in", "r");
    outF = fopen("out", "w");
    inF = stdin;
    outF = stdout;

    int n, d, m;

    fscanf(inF, "%d %d %d", &n, &d, &m);

    vector<int> sv;
    vector<int> bv;

    for (int i = 0; i < n; i++)
    {
        int num;
        fscanf(inF, "%d", &num);

        if (num <= m)
            sv.push_back(num);
        else
            bv.push_back(num);
    }

    sort(sv.begin(), sv.end());
    sort(bv.begin(), bv.end());

    int fp = 0;
    int bp = bv.size() - 1;

    ll res = 0;
    int curd = 0;

    while(bp > 0 && curd < n)
    {
        ll smalls = 0;
        int days = 0;

        for (int i = fp; i < min(fp + min(d, n - curd - 1), (int)sv.size()); i++)
        {
            smalls += sv[i];
            days++;
        }

        if (bv[bp] > smalls)
        {
            res += bv[bp--];
            fp += days;
            curd += days + 1;
        }
        else
        {
            break;
        }
    }

    while (fp < sv.size())
    {
        res += sv[fp++];
        curd++;
    }

    while(bp >= 0 && curd < n)
    {
        res += bv[bp--];
        curd += d + 1;
    }

    fprintf(outF, "%lld", res);

    return 0;
}
//인풋 바꾸기!!!!


#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <string.h>
#include <string>
#include <cmath>
#include <cstdio>
#include <functional>
#include <map>
#include <typeinfo>
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<ll, ll> pl;

int main()
{
    FILE *inF, *outF;
    inF = fopen("in", "r");
    outF = fopen("out", "w");
    inF = stdin;
    outF = stdout;

    int n, d, m;

    fscanf(inF, "%d %d %d", &n, &d, &m);

    vector<int> sv;
    vector<int> bv;

    for (int i = 0; i < n; i++)
    {
        int num;
        fscanf(inF, "%d", &num);

        if (num <= m)
            sv.push_back(num);
        else
            bv.push_back(num);
    }

    sort(sv.begin(), sv.end(), greater<int>());
    sort(bv.begin(), bv.end(), greater<int>());

    ll sumb[100001];
    ll sums[100001];

    sumb[0] = 0;
    sums[0] = 0;

    for (int i = 1; i <= bv.size(); i++)
    {
        sumb[i] = bv[i - 1] + sumb[i - 1];
    }

    for (int i = 1; i <= sv.size(); i++)
    {
        sums[i] = sv[i - 1] + sums[i - 1];
    }

    ll res = 0;

    for (int i = 0; i <= bv.size(); i++)
    {
        ll temp = 0;
        ll curd = 0;

        if (i > 0)
        {
            temp += sumb[i];
            curd = (i - 1) * (d + 1) + 1;
        }

        if (curd <= n)
        {
            temp += sums[min(n - curd, (ll)sv.size())];
            res = max(res, temp);
        }
    }

    fprintf(outF, "%lld", res);

    return 0;
}
//인풋 바꾸기!!!!


#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <string.h>
#include <string>
#include <cmath>
#include <cstdio>
#include <functional>
#include <map>
#include <typeinfo>
#include<bits/stdc++.h>
#define INF 1e9
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<ll, ll> pl;

int main()
{
    FILE *inF, *outF;
    inF = fopen("in", "r");
    outF = fopen("out", "w");
    inF = stdin;
    outF = stdout;

    int n, d, m;
    fscanf(inF, "%d %d %d", &n, &d, &m);

    vector<ll> sv;
    vector<ll> bv;

    bv.clear();
    sv.clear();

    for (int i = 0; i < n; i++)
    {
        int num;
        fscanf(inF,"%d", &num);

        if (num > m)
            bv.push_back(num);
        else
            sv.push_back(num);
    }

    sort(bv.begin(), bv.end(), greater<int>());
    sort(sv.begin(), sv.end(), greater<int>());

    for (int i = 0; i < (int)bv.size() - 1; i++)
    {
        bv[i + 1] += bv[i];
    }

    for (int i = 0; i < (int)sv.size() - 1; i++)
    {
        sv[i + 1] += sv[i];
    }

    ll res = 0;

    for (int i = 0; i <= bv.size(); i++)
    {
        int tn = n;
        ll tr = 0;

        if (i > 0)
        {
            tn -= (i - 1) * (d + 1) + 1;
            tr += bv[i - 1];
        }

        if (!sv.empty() && tn > 0)
            tr += sv[min((int)sv.size(), tn) - 1];

        if (tn >= 0)
            res = max(tr, res);
    }

    fprintf(outF, "%lld\n", res);
    return 0;
}
//인풋 바꾸기!!!!


#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <string.h>
#include <string>
#include <cmath>
#include <cstdio>
#include <functional>
#include <map>
#include <typeinfo>
#include<bits/stdc++.h>
#define INF 1e9
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<ll, ll> pl;

int main()
{
    FILE *inF, *outF;
    inF = fopen("in", "r");
    outF = fopen("out", "w");
    inF = stdin;
    outF = stdout;

    int n, d, m;
    fscanf(inF, "%d %d %d", &n, &d, &m);

    vector<int> sv;
    vector<int> bv;

    for (int i = 0; i < n; i++)
    {
        int num;
        fscanf(inF,"%d", &num);

        if (num > m)
            bv.push_back(num);
        else
            sv.push_back(num);
    }

    sort(bv.begin(), bv.end(), greater<int>());
    sort(sv.begin(), sv.end(), greater<int>());

    for (int i = 0; i < bv.size() - 1; i++)
    {
        bv[i + 1] += bv[i];
    }

    for (int i = 0; i < sv.size() - 1; i++)
    {
        sv[i + 1] += sv[i];
    }

    ll res = 0;

    for (int i = 0; i <= bv.size(); i++)
    {
        int tn = n;
        ll tr = 0;

        if (i > 0)
        {
            tn -= (i - 1) * (d + 1) + 1;
            tr += bv[i - 1];
        }

        if (!sv.empty())
            tr += sv[min((int)sv.size(), tn) - 1];

        res = max(tr, res);
    }

    fprintf(outF, "%lld\n", res);
    return 0;
}
//인풋 바꾸기!!!!


#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <string.h>
#include <string>
#include <cmath>
#include <cstdio>
#include <functional>
#include <map>
#include <typeinfo>
#include<bits/stdc++.h>
#define INF 1e9
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<ll, ll> pl;

int main()
{
    FILE *inF, *outF;
    inF = fopen("in", "r");
    outF = fopen("out", "w");
    inF = stdin;
    outF = stdout;

    int n, d, m;
    fscanf(inF, "%d %d %d", &n, &d, &m);

    vector<int> sv;
    vector<int> bv;

    bv.clear();
    sv.clear();

    for (int i = 0; i < n; i++)
    {
        int num;
        fscanf(inF,"%d", &num);

        if (num > m)
            bv.push_back(num);
        else
            sv.push_back(num);
    }

    sort(bv.begin(), bv.end(), greater<int>());
    sort(sv.begin(), sv.end(), greater<int>());

    for (int i = 0; i < (int)bv.size() - 1; i++)
    {
        bv[i + 1] += bv[i];
    }

    for (int i = 0; i < (int)sv.size() - 1; i++)
    {
        sv[i + 1] += sv[i];
    }

    ll res = 0;

    for (int i = 0; i <= bv.size(); i++)
    {
        int tn = n;
        ll tr = 0;

        if (i > 0)
        {
            tn -= (i - 1) * (d + 1) + 1;
            tr += bv[i - 1];
        }

        if (!sv.empty())
            tr += sv[min((int)sv.size(), tn) - 1];

        res = max(tr, res);
    }

    fprintf(outF, "%lld\n", res);
    return 0;
}
//인풋 바꾸기!!!!


#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <string.h>
#include <string>
#include <cmath>
#include <cstdio>
#include <functional>
#include <map>
#include <typeinfo>
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<ll, ll> pl;

int main()
{
    FILE *inF, *outF;
    inF = fopen("in", "r");
    outF = fopen("out", "w");
    inF = stdin;
    outF = stdout;

    int n, d, m;

    fscanf(inF, "%d %d %d", &n, &d, &m);

    vector<int> sv;
    vector<int> bv;

    for (int i = 0; i < n; i++)
    {
        int num;
        fscanf(inF, "%d", &num);

        if (num <= m)
            sv.push_back(num);
        else
            bv.push_back(num);
    }

    sort(sv.begin(), sv.end(), greater<int>());
    sort(bv.begin(), bv.end(), greater<int>());

    ll sumb[100001];
    ll sums[100001];

    sumb[0] = 0;
    sums[0] = 0;

    for (int i = 1; i <= bv.size(); i++)
    {
        sumb[i] = bv[i - 1] + sumb[i - 1];
    }

    for (int i = 1; i <= sv.size(); i++)
    {
        sums[i] = sv[i - 1] + sums[i - 1];
    }

    ll res = 0;

    for (ll i = 0; i <= bv.size(); i++)
    {
        ll temp = 0;
        ll curd = 0;

        if (i > 0)
        {
            temp += sumb[i];
            curd = (i - 1) * (d + 1) + 1;
        }

        if (curd <= n)
        {
            temp += sums[min(n - curd, (ll)sv.size())];
            res = max(res, temp);
        }
    }

    fprintf(outF, "%lld", res);

    return 0;
}
//인풋 바꾸기!!!!


#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <string.h>
#include <string>
#include <cmath>
#include <cstdio>
#include <functional>
#include <map>
#include <typeinfo>
#include<bits/stdc++.h>
#define INF 1e9
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<ll, ll> pl;

int main()
{
    FILE *inF, *outF;
    inF = fopen("in", "r");
    outF = fopen("out", "w");
    inF = stdin;
    outF = stdout;

    int n, d, m;
    fscanf(inF, "%d %d %d", &n, &d, &m);

    vector<ll> sv;
    vector<ll> bv;

    bv.clear();
    sv.clear();

    for (int i = 0; i < n; i++)
    {
        int num;
        fscanf(inF,"%d", &num);

        if (num > m)
            bv.push_back(num);
        else
            sv.push_back(num);
    }

    sort(bv.begin(), bv.end(), greater<int>());
    sort(sv.begin(), sv.end(), greater<int>());

    for (int i = 0; i < (int)bv.size() - 1; i++)
    {
        bv[i + 1] += bv[i];
    }

    for (int i = 0; i < (int)sv.size() - 1; i++)
    {
        sv[i + 1] += sv[i];
    }

    ll res = 0;

    for (ll i = 0; i <= bv.size(); i++)
    {
        ll tn = n;
        ll tr = 0;

        if (i > 0)
        {
            tn -= (i - 1) * (d + 1) + 1;
            tr += bv[i - 1];
        }

        if (!sv.empty() && tn > 0)
            tr += sv[min((ll)sv.size(), tn) - 1];

        if (tn >= 0)
            res = max(tr, res);
    }

    fprintf(outF, "%lld\n", res);
    return 0;
}
//인풋 바꾸기!!!!


#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <string.h>
#include <string>
#include <cmath>
#include <cstdio>
#include <functional>
#include <map>
#include <typeinfo>
#include<bits/stdc++.h>
#define INF 1e9
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<ll, ll> pl;

int main()
{
    FILE *inF, *outF;
    inF = fopen("in", "r");
    outF = fopen("out", "w");
    inF = stdin;
    outF = stdout;

    int n, d, m;
    fscanf(inF, "%d %d %d", &n, &d, &m);

    vector<ll> sv;
    vector<ll> bv;

    bv.clear();
    sv.clear();

    for (int i = 0; i < n; i++)
    {
        int num;
        fscanf(inF,"%d", &num);

        if (num > m)
            bv.push_back(num);
        else
            sv.push_back(num);
    }

    sort(bv.begin(), bv.end(), greater<int>());
    sort(sv.begin(), sv.end(), greater<int>());

    for (int i = 0; i < (int)bv.size() - 1; i++)
    {
        bv[i + 1] += bv[i];
    }

    for (int i = 0; i < (int)sv.size() - 1; i++)
    {
        sv[i + 1] += sv[i];
    }

    ll res = 0;

    for (int i = 0; i <= bv.size(); i++)
    {
        int tn = n;
        ll tr = 0;

        if (i > 0)
        {
            tn -= ((ll)i - 1) * (d + 1) + 1;
            tr += bv[i - 1];
        }

        if (!sv.empty() && tn > 0)
            tr += sv[min((int)sv.size(), tn) - 1];

        if (tn >= 0)
            res = max(tr, res);
    }

    fprintf(outF, "%lld\n", res);
    return 0;
}
//인풋 바꾸기!!!!


#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <string.h>
#include <string>
#include <cmath>
#include <cstdio>
#include <functional>
#include <map>
#include <typeinfo>
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<ll, ll> pl;

int main()
{
    FILE *inF, *outF;
    inF = fopen("in", "r");
    outF = fopen("out", "w");
    inF = stdin;
    outF = stdout;

    int n, d, m;

    fscanf(inF, "%d %d %d", &n, &d, &m);

    vector<int> sv;
    vector<int> bv;

    for (int i = 0; i < n; i++)
    {
        int num;
        fscanf(inF, "%d", &num);

        if (num <= m)
            sv.push_back(num);
        else
            bv.push_back(num);
    }

    sort(sv.begin(), sv.end(), greater<int>());
    sort(bv.begin(), bv.end(), greater<int>());

    ll sumb[100001];
    ll sums[100001];

    sumb[0] = 0;
    sums[0] = 0;

    for (int i = 1; i <= bv.size(); i++)
    {
        sumb[i] = bv[i - 1] + sumb[i - 1];
    }

    for (int i = 1; i <= sv.size(); i++)
    {
        sums[i] = sv[i - 1] + sums[i - 1];
    }

    ll res = 0;

    for (int i = 0; i <= bv.size(); i++)
    {
        ll temp = 0;
        int curd = 0;

        if (i > 0)
        {
            temp += sumb[i];
            curd = (i - 1) * (d + 1) + 1;
        }

        if (curd <= n)
            temp += sums[min(n - curd, (int)sv.size())];

        res = max(res, temp);
    }

    fprintf(outF, "%lld", res);

    return 0;
}
//인풋 바꾸기!!!!


#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <string.h>
#include <string>
#include <cmath>
#include <cstdio>
#include <functional>
#include <map>
#include <typeinfo>
#include<bits/stdc++.h>
#define INF 1e9
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<ll, ll> pl;

int main()
{
    FILE *inF, *outF;
    inF = fopen("in", "r");
    outF = fopen("out", "w");
    inF = stdin;
    outF = stdout;

    int n, d, m;
    fscanf(inF, "%d %d %d", &n, &d, &m);

    vector<ll> sv;
    vector<ll> bv;

    bv.clear();
    sv.clear();

    for (int i = 0; i < n; i++)
    {
        int num;
        fscanf(inF,"%d", &num);

        if (num > m)
            bv.push_back(num);
        else
            sv.push_back(num);
    }

    sort(bv.begin(), bv.end(), greater<int>());
    sort(sv.begin(), sv.end(), greater<int>());

    for (int i = 0; i < (int)bv.size() - 1; i++)
    {
        bv[i + 1] += bv[i];
    }

    for (int i = 0; i < (int)sv.size() - 1; i++)
    {
        sv[i + 1] += sv[i];
    }

    ll res = 0;

    for (ll i = 0; i <= bv.size(); i++)
    {
        int tn = n;
        ll tr = 0;

        if (i > 0)
        {
            tn -= (i - 1) * (d + 1) + 1;
            tr += bv[i - 1];
        }

        if (!sv.empty() && tn > 0)
            tr += sv[min((int)sv.size(), tn) - 1];

        if (tn >= 0)
            res = max(tr, res);
    }

    fprintf(outF, "%lld\n", res);
    return 0;
}
//인풋 바꾸기!!!!


#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <string.h>
#include <string>
#include <cmath>
#include <cstdio>
#include <functional>
#include <map>
#include <typeinfo>
#include<bits/stdc++.h>
#define INF 1e9
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<ll, ll> pl;

int main()
{
    FILE *inF, *outF;
    inF = fopen("in", "r");
    outF = fopen("out", "w");
    inF = stdin;
    outF = stdout;

    int n, d, m;
    fscanf(inF, "%d %d %d", &n, &d, &m);

    vector<ll> sv;
    vector<ll> bv;

    bv.clear();
    sv.clear();

    for (int i = 0; i < n; i++)
    {
        int num;
        fscanf(inF,"%d", &num);

        if (num > m)
            bv.push_back(num);
        else
            sv.push_back(num);
    }

    sort(bv.begin(), bv.end(), greater<int>());
    sort(sv.begin(), sv.end(), greater<int>());

    for (int i = 0; i < (int)bv.size() - 1; i++)
    {
        bv[i + 1] += bv[i];
    }

    for (int i = 0; i < (int)sv.size() - 1; i++)
    {
        sv[i + 1] += sv[i];
    }

    ll res = 0;

    for (int i = 0; i <= bv.size(); i++)
    {
        int tn = n;
        ll tr = 0;

        if (i > 0)
        {
            tn -= (i - 1) * (d + 1) + 1;
            tr += bv[i - 1];
        }

        if (!sv.empty() && tn > 0)
            tr += sv[min((int)sv.size(), tn) - 1];

        res = max(tr, res);
    }

    fprintf(outF, "%lld\n", res);
    return 0;
}
//인풋 바꾸기!!!!


#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <string.h>
#include <string>
#include <cmath>
#include <cstdio>
#include <functional>
#include <map>
#include <typeinfo>
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<ll, ll> pl;

int main()
{
    FILE *inF, *outF;
    inF = fopen("in", "r");
    outF = fopen("out", "w");
    inF = stdin;
    outF = stdout;

    int n, d, m;

    fscanf(inF, "%d %d %d", &n, &d, &m);

    vector<int> sv;
    vector<int> bv;

    for (int i = 0; i < n; i++)
    {
        int num;
        fscanf(inF, "%d", &num);

        if (num <= m)
            sv.push_back(num);
        else
            bv.push_back(num);
    }

    sort(sv.begin(), sv.end(), greater<int>());
    sort(bv.begin(), bv.end(), greater<int>());

    ll sumb[100001];
    ll sums[100001];

    sumb[0] = 0;
    sums[0] = 0;

    for (int i = 1; i <= bv.size(); i++)
    {
        sumb[i] = bv[i - 1] + sumb[i - 1];
    }

    for (int i = 1; i <= sv.size(); i++)
    {
        sums[i] = sv[i - 1] + sums[i - 1];
    }

    ll res = 0;

    for (int i = 0; i <= bv.size(); i++)
    {
        ll temp = 0;
        int curd = 0;

        if (i > 0)
        {
            temp += sumb[i];
            curd = (i - 1) * (d + 1) + 1;
        }

        temp += sums[min(n - curd, (int)sv.size())];

        res = max(res, temp);
    }

    fprintf(outF, "%lld", res);

    return 0;
}
//인풋 바꾸기!!!!


#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <string.h>
#include <string>
#include <cmath>
#include <cstdio>
#include <functional>
#include <map>
#include <typeinfo>
#include<bits/stdc++.h>
#define INF 1e9
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<ll, ll> pl;

int main()
{
    FILE *inF, *outF;
    inF = fopen("in", "r");
    outF = fopen("out", "w");
    inF = stdin;
    outF = stdout;

    int n, d, m;
    fscanf(inF, "%d %d %d", &n, &d, &m);

    vector<int> sv;
    vector<int> bv;

    for (int i = 0; i < n; i++)
    {
        int num;
        fscanf(inF,"%d", &num);

        if (num > m)
            bv.push_back(num);
        else
            sv.push_back(num);
    }

    sort(bv.begin(), bv.end(), greater<int>());
    sort(sv.begin(), sv.end(), greater<int>());

    for (int i = 0; i < bv.size() - 1; i++)
    {
        bv[i + 1] += bv[i];
    }

    for (int i = 0; i < sv.size() - 1; i++)
    {
        sv[i + 1] += sv[i];
    }

    ll res = 0;

    for (int i = 0; i <= bv.size(); i++)
    {
        int tn = n;
        ll tr = 0;

        if (i > 0)
        {
            tn -= (i - 1) * (d + 1) + 1;
            tr += bv[i - 1];
        }

        tr += sv[min((int)sv.size(), tn) - 1];

        res = max(tr, res);
    }

    fprintf(outF, "%lld\n", res);
    return 0;
}
//인풋 바꾸기!!!!


#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <string.h>
#include <string>
#include <cmath>
#include <cstdio>
#include <functional>
#include <map>
#include <typeinfo>
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<ll, ll> pl;

int main()
{
    FILE *inF, *outF;
    inF = fopen("in", "r");
    outF = fopen("out", "w");
    inF = stdin;
    outF = stdout;

    int n, d, m;

    fscanf(inF, "%d %d %d", &n, &d, &m);

    vector<int> sv;
    vector<int> bv;

    for (int i = 0; i < n; i++)
    {
        int num;
        fscanf(inF, "%d", &num);

        if (num <= m)
            sv.push_back(num);
        else
            bv.push_back(num);
    }

    sort(sv.begin(), sv.end(), greater<int>());
    sort(bv.begin(), bv.end(), greater<int>());

    ll sumb[100001];
    ll sums[100001];

    sumb[0] = 0;
    sums[0] = 0;

    for (int i = 1; i <= bv.size(); i++)
    {
        sumb[i] = bv[i - 1] + sumb[i - 1];
    }

    for (int i = 1; i <= sv.size(); i++)
    {
        sums[i] = sv[i - 1] + sums[i - 1];
    }

    ll res = 0;

    for (int i = 0; i <= bv.size(); i++)
    {
        ll temp = 0;
        int curd = 0;

        if (i > 0)
        {
            temp += sumb[i];
            curd = (i - 1) * (d + 1) + 1;
        }

        if (curd <= n)
        {
            temp += sums[min(n - curd, (int)sv.size())];
            res = max(res, temp);
        }
    }

    fprintf(outF, "%lld", res);

    return 0;
}
//인풋 바꾸기!!!!


#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <string.h>
#include <string>
#include <cmath>
#include <cstdio>
#include <functional>
#include <map>
#include <typeinfo>
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<ll, ll> pl;

int main()
{
    FILE *inF, *outF;
    inF = fopen("in", "r");
    outF = fopen("out", "w");
    inF = stdin;
    outF = stdout;

    int n, d, m;

    fscanf(inF, "%d %d %d", &n, &d, &m);

    vector<int> sv;
    vector<int> bv;

    for (int i = 0; i < n; i++)
    {
        int num;
        fscanf(inF, "%d", &num);

        if (num <= m)
            sv.push_back(num);
        else
            bv.push_back(num);
    }

    sort(sv.begin(), sv.end());
    sort(bv.begin(), bv.end());

    int fp = 0;
    int bp = bv.size() - 1;

    ll res = 0;
    int curd = 0;

    while(bp > 0 && curd < n)
    {
        ll smalls = 0;
        int days = 0;

        for (int i = fp; i < min(fp + min(d, n - curd - 1), (int)sv.size()); i++)
        {
            smalls += sv[i];
            days++;
        }

        if (bv[bp] > smalls)
        {
            res += bv[bp--];
            fp += days;
            curd += d + 1;
        }
        else
        {
            break;
        }
    }

    while (fp < sv.size() && curd < n)
    {
        res += sv[fp++];
        curd++;
    }

    while(bp >= 0 && curd < n)
    {
        res += bv[bp--];
        curd += d + 1;
    }

    fprintf(outF, "%lld", res);

    return 0;
}
//인풋 바꾸기!!!!


#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <string.h>
#include <string>
#include <cmath>
#include <cstdio>
#include <functional>
#include <map>
#include <typeinfo>
#include<bits/stdc++.h>
#define INF 1e9
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<ll, ll> pl;

int main()
{
    FILE *inF, *outF;
    inF = fopen("in", "r");
    outF = fopen("out", "w");
    inF = stdin;
    outF = stdout;

    int n, d, m;
    fscanf(inF, "%d %d %d", &n, &d, &m);

    vector<ll> sv;
    vector<ll> bv;

    bv.clear();
    sv.clear();

    for (int i = 0; i < n; i++)
    {
        int num;
        fscanf(inF,"%d", &num);

        if (num > m)
            bv.push_back(num);
        else
            sv.push_back(num);
    }

    sort(bv.begin(), bv.end(), greater<int>());
    sort(sv.begin(), sv.end(), greater<int>());

    for (int i = 0; i < (int)bv.size() - 1; i++)
    {
        bv[i + 1] += bv[i];
    }

    for (int i = 0; i < (int)sv.size() - 1; i++)
    {
        sv[i + 1] += sv[i];
    }

    ll res = 0;

    for (int i = 0; i <= bv.size(); i++)
    {
        int tn = n;
        ll tr = 0;

        if (i > 0)
        {
            tn -= (i - 1) * (d + 1) + 1;
            tr += bv[i - 1];
        }

        if (!sv.empty())
            tr += sv[min((int)sv.size(), tn) - 1];

        res = max(tr, res);
    }

    fprintf(outF, "%lld\n", res);
    return 0;
}
//인풋 바꾸기!!!!


typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
ll maxl(ll a, ll b){ return ((a<b)?b:a);}
ll minl(ll a, ll b){ return ((a>b)?b:a);}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,d,m;
    cin >> n >> d >> m;
    int arr[n];
    vector<int> great;
    vector<int> less;
    for (int i=0;i<n;i++){
        cin >> arr[i];
        if (arr[i]>m)
            great.push_back(arr[i]);
        else
            less.push_back(arr[i]);
    }
    sort(less.begin(),less.end(),greater<int>());
    sort(great.begin(),great.end(), greater<int>());
    vector<ll> prefix_less;
    vector<ll> prefix_great;
    for (int i=0;i<less.size();i++){
        if (i==0){
            prefix_less.push_back(less[0]);
            continue;
        }
        prefix_less.push_back(prefix_less[i-1] + less[i]);
    }
    for (int i = 0;i<great.size();i++){
        if (i == 0){
            prefix_great.push_back(great[0]);
            continue;
        }
        prefix_great.push_back(prefix_great[i-1] + great[i]);
    }
    ll ans = 0;
    if (prefix_less.size()>0)
        ans = prefix_less[prefix_less.size()-1];
    for (int i=0;i<prefix_great.size();i++){
        ll rem = (ll)n - ((ll)i*(d+1)) - 1;
        if (rem<0 || rem>prefix_less.size())
            continue;
        if (rem == 0){
            ans= maxl(ans,prefix_great[i]);
            continue;
        }
        ans = maxl(prefix_less[rem-1] + prefix_great[i], ans);
    }
    cout << ans << "\n";
}


typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
ll maxl(ll a, ll b){ return ((a<b)?b:a);}
ll minl(ll a, ll b){ return ((a>b)?b:a);}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,d,m;
    cin >> n >> d >> m;
    int arr[n];
    vector<int> great;
    vector<int> less;
    for (int i=0;i<n;i++){
        cin >> arr[i];
        if (arr[i]>m)
            great.push_back(arr[i]);
        else
            less.push_back(arr[i]);
    }
    sort(less.begin(),less.end(),greater<int>());
    sort(great.begin(),great.end(), greater<int>());
    vector<ll> prefix_less;
    vector<ll> prefix_great;
    for (int i=0;i<less.size();i++){
        if (i==0){
            prefix_less.push_back(less[0]);
            continue;
        }
        prefix_less.push_back(prefix_less[i-1] + less[i]);
    }
    for (int i=0;i<great.size();i++){
        if (i==0){
            prefix_great.push_back(great[0]);
            continue;
        }
        prefix_great.push_back(prefix_great[i-1] + great[i]);
    }
    ll ans = 0;
    if (prefix_less.size()>0)
        ans = prefix_less[prefix_less.size()-1];
    for (int i=0;i<prefix_great.size();i++){
        int rem = n - i*(d+1) - 1;
        if (rem<0)
            continue;
        if (rem == 0){
            ans= maxl(ans,prefix_great[i]);
            continue;
        }
        if (rem<=prefix_less.size())
            ans = maxl(prefix_less[rem-1] + prefix_great[i], ans);
    }
    cout << ans << "\n";
}


typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
ll maxl(ll a, ll b){ return ((a<b)?b:a);}
ll minl(ll a, ll b){ return ((a>b)?b:a);}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int a;
    int n,d,m;
    cin >> n >> d >> m;
    int arr[n];
    vector<int> great;
    vector<int> less;
    for (int i=0;i<n;i++){
        cin >> arr[i];
        if (arr[i]>m)
            great.push_back(arr[i]);
        else
            less.push_back(arr[i]);
    }
    sort(less.begin(),less.end(),greater<int>());
    sort(great.begin(),great.end(), greater<int>());
    vector<int> prefix_less;
    vector<int> prefix_great;
    for (int i=0;i<less.size();i++){
        if (i==0){
            prefix_less.push_back(less[0]);
            continue;
        }
        prefix_less.push_back(prefix_less[i-1] + less[i]);
    }
    for (int i=0;i<great.size();i++){
        if (i==0){
            prefix_great.push_back(great[0]);
            continue;
        }
        prefix_great.push_back(prefix_great[i-1] + great[i]);
    }
    int ans = prefix_less[prefix_less.size()-1];
    for (int i=0;i<prefix_great.size();i++){
        int rem = n - i*(d+1) - 1;
        if (rem<0)
            continue;
        if (rem == 0){
            ans= max(ans,prefix_great[i]);
            continue;
        }
        ans = max(prefix_less[rem-1] + prefix_great[i], ans);
    }
    cout << ans << "\n";
}


typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
ll maxl(ll a, ll b){ return ((a<b)?b:a);}
ll minl(ll a, ll b){ return ((a>b)?b:a);}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,d,m;
    cin >> n >> d >> m;
    int arr[n];
    vector<int> great;
    vector<int> less;
    for (int i=0;i<n;i++){
        cin >> arr[i];
        if (arr[i]>m)
            great.push_back(arr[i]);
        else
            less.push_back(arr[i]);
    }
    sort(less.begin(),less.end(),greater<int>());
    sort(great.begin(),great.end(), greater<int>());
    vector<ll> prefix_less;
    vector<ll> prefix_great;
    for (int i=0;i<less.size();i++){
        if (i==0){
            prefix_less.push_back(less[0]);
            continue;
        }
        prefix_less.push_back(prefix_less[i-1] + less[i]);
    }
    for (int i = 0;i<great.size();i++){
        if (i == 0){
            prefix_great.push_back(great[0]);
            continue;
        }
        prefix_great.push_back(prefix_great[i-1] + great[i]);
    }
    ll ans = 0;
    if (prefix_less.size()>0)
        ans = prefix_less[prefix_less.size()-1];
    for (int i=0;i<prefix_great.size();i++){
        ll rem = (ll)n - ((ll)i*(d+1)) - 1;
        if (rem<0)
            continue;
        if (rem == 0 || prefix_less.size()==0){
            ans= maxl(ans,prefix_great[i]);
            continue;
        }
        if (rem<=prefix_less.size())
            ans = maxl(prefix_less[rem-1] + prefix_great[i], ans);
        else
            ans = maxl(prefix_less[prefix_less.size()-1] + prefix_great[i], ans);
    }
    cout << ans << "\n";
}


typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
ll maxl(ll a, ll b){ return ((a<b)?b:a);}
ll minl(ll a, ll b){ return ((a>b)?b:a);}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,d,m;
    cin >> n >> d >> m;
    int arr[n];
    vector<int> great;
    vector<int> less;
    for (int i=0;i<n;i++){
        cin >> arr[i];
        if (arr[i]>m)
            great.push_back(arr[i]);
        else
            less.push_back(arr[i]);
    }
    sort(less.begin(),less.end(),greater<int>());
    sort(great.begin(),great.end(), greater<int>());
    vector<ll> prefix_less;
    vector<ll> prefix_great;
    for (int i=0;i<less.size();i++){
        if (i==0){
            prefix_less.push_back(less[0]);
            continue;
        }
        prefix_less.push_back(prefix_less[i-1] + less[i]);
    }
    for (int i = 0;i<great.size();i++){
        if (i == 0){
            prefix_great.push_back(great[0]);
            continue;
        }
        prefix_great.push_back(prefix_great[i-1] + great[i]);
    }
    ll ans = 0;
    if (prefix_less.size()>0)
        ans = prefix_less[prefix_less.size()-1];
    for (int i=0;i<prefix_great.size();i++){
        ll rem = (ll)n - ((ll)i*(d+1)) - 1;
        if (rem<0)
            continue;
        if (rem == 0){
            ans= maxl(ans,prefix_great[i]);
            continue;
        }
        if (rem<=prefix_less.size())
            ans = maxl(prefix_less[rem-1] + prefix_great[i], ans);
        else
            ans = maxl(prefix_less[prefix_less.size()-1] + prefix_great[i], ans);
    }
    cout << ans << "\n";
}


typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
ll maxl(ll a, ll b){ return ((a<b)?b:a);}
ll minl(ll a, ll b){ return ((a>b)?b:a);}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,d,m;
    cin >> n >> d >> m;
    int arr[n];
    vector<int> great;
    vector<int> less;
    for (int i=0;i<n;i++){
        cin >> arr[i];
        if (arr[i]>m)
            great.push_back(arr[i]);
        else
            less.push_back(arr[i]);
    }
    sort(less.begin(),less.end(),greater<int>());
    sort(great.begin(),great.end(), greater<int>());
    vector<ll> prefix_less;
    vector<ll> prefix_great;
    for (int i=0;i<less.size();i++){
        if (i==0){
            prefix_less.push_back(less[0]);
            continue;
        }
        prefix_less.push_back(prefix_less[i-1] + less[i]);
    }
    for (int i=0;i<great.size();i++){
        if (i==0){
            prefix_great.push_back(great[0]);
            continue;
        }
        prefix_great.push_back(prefix_great[i-1] + great[i]);
    }
    ll ans = 0;
    if (prefix_less.size()>0)
        ans = prefix_less[prefix_less.size()-1];
    for (int i=0;i<prefix_great.size();i++){
        int rem = n - i*(d+1) - 1;
        if (rem<0 || rem>prefix_less.size())
            continue;
        if (rem == 0){
            ans= maxl(ans,prefix_great[i]);
            continue;
        }
        ans = maxl(prefix_less[rem-1] + prefix_great[i], ans);
    }
    cout << ans << "\n";
}


typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
ll maxl(ll a, ll b){ return ((a<b)?b:a);}
ll minl(ll a, ll b){ return ((a>b)?b:a);}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,d,m;
    cin >> n >> d >> m;
    int arr[n];
    vector<int> great;
    vector<int> less;
    for (int i=0;i<n;i++){
        cin >> arr[i];
        if (arr[i]>m)
            great.push_back(arr[i]);
        else
            less.push_back(arr[i]);
    }
    sort(less.begin(),less.end(),greater<int>());
    sort(great.begin(),great.end(), greater<int>());
    vector<ll> prefix_less;
    vector<ll> prefix_great;
    for (int i=0;i<less.size();i++){
        if (i==0){
            prefix_less.push_back(less[0]);
            continue;
        }
        prefix_less.push_back(prefix_less[i-1] + less[i]);
    }
    for (int i = 0;i<great.size();i++){
        if (i == 0){
            prefix_great.push_back(great[0]);
            continue;
        }
        prefix_great.push_back(prefix_great[i-1] + great[i]);
    }
    ll ans = 0;
    if (prefix_less.size()>0)
        ans = prefix_less[prefix_less.size()-1];
    for (int i=0;i<prefix_great.size();i++){
        int rem = (ll)n - (ll)i*(d+1) - 1;
        if (rem<0 || rem>prefix_less.size())
            continue;
        if (rem == 0){
            ans= maxl(ans,prefix_great[i]);
            continue;
        }
        ans = maxl(prefix_less[rem-1] + prefix_great[i], ans);
    }
    cout << ans << "\n";
}


typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
ll maxl(ll a, ll b){ return ((a<b)?b:a);}
ll minl(ll a, ll b){ return ((a>b)?b:a);}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,d,m;
    cin >> n >> d >> m;
    int arr[n];
    vector<int> great;
    vector<int> less;
    for (int i=0;i<n;i++){
        cin >> arr[i];
        if (arr[i]>m)
            great.push_back(arr[i]);
        else
            less.push_back(arr[i]);
    }
    sort(less.begin(),less.end(),greater<int>());
    sort(great.begin(),great.end(), greater<int>());
    vector<int> prefix_less;
    vector<int> prefix_great;
    for (int i=0;i<less.size();i++){
        if (i==0){
            prefix_less.push_back(less[0]);
            continue;
        }
        prefix_less.push_back(prefix_less[i-1] + less[i]);
    }
    for (int i=0;i<great.size();i++){
        if (i==0){
            prefix_great.push_back(great[0]);
            continue;
        }
        prefix_great.push_back(prefix_great[i-1] + great[i]);
    }
    int ans = prefix_less[prefix_less.size()-1];
    for (int i=0;i<prefix_great.size();i++){
        int rem = n - i*(d+1) - 1;
        if (rem<0)
            continue;
        if (rem == 0){
            ans= max(ans,prefix_great[i]);
            continue;
        }
        ans = max(prefix_less[rem-1] + prefix_great[i], ans);
    }
    cout << ans << "\n";
}