#include <iostream>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <vector>
#include <utility>

#define inf 1000000007ll
#define int long long int
using namespace std;

char sir[10000005];
int poz;
int lung;

inline void cit () {
    cin.get();
    cin.get(sir + 1, 10000005);

    poz = 1;
    lung = strlen(sir + 1);
}

inline int gett () {
    int ans = 0;
    while (poz <= lung && sir[poz] == ' ')
        poz ++;

    if (sir[poz] == '?') {
        poz ++;
        return (inf + 1);
    }

    int semn = 1;
    if (sir[poz] == '-') {
        poz ++;
        semn = -1;
    }

    while (poz <= lung && isdigit(sir[poz])) {
        ans *= 10;
        ans += sir[poz] - '0';
        poz ++;
    }

    return semn * ans;
}

int gauss (int n) {
    return (n * (n + 1ll) / 2);
}

int suma (int st, int dr) {
    if (st >= 0) {
        return gauss(dr) - gauss(st - 1);
    }
    else if (dr <= 0) {
        st *= -1;
        dr *= -1;

        swap(st, dr);

        return gauss(dr) - gauss(st - 1);
    }
    else {
        return suma(st, 0) + suma(0, dr);
    }
}

int best (int lung, int st, int dr) {
    //cout << "apel si aici " << st << ' ' << dr << endl;

    if (dr - st + 1 < lung)
        return inf + 7;

    int st_best = st;
    int ans_best = suma(st, st + lung - 1);

    if (suma(dr - lung + 1, dr) < ans_best) {
        st_best = dr - lung + 1;
        ans_best = suma(dr - lung + 1, dr);
    }

    int st_aux = - (lung - 1) / 2;
    int dr_aux = lung / 2;

    if (st_aux >= st && dr_aux <= dr) {
        if (suma(st_aux, dr_aux) < ans_best) {
            st_best = st_aux;
            ans_best = suma(st_aux, dr_aux);
        }
    }

    return st_best;
}

int v[100005];

vector <int> vects[100005];
vector <int> spec[100005];

inline bool create (vector<int> &v, vector<int> &spec) {
    for (int i = 0; i < v.size(); i++)
        if (v[i] != inf + 1)
            spec.push_back(i);

    for (int i = 1; i < spec.size(); i++)
        if (v[spec[i - 1]] >= v[spec[i]])
            return false;

    int y;
    int j, k;
    for (int i = 1; i < spec.size(); i++) {
        if (spec[i] - spec[i - 1] - 1 > 0) {
            y = best(spec[i] - spec[i - 1] - 1, v[spec[i - 1]] + 1, v[spec[i]] - 1);
            //cout << "apel " << spec[i] - spec[i - 1] - 1 << ' ' << v[spec[i - 1]] << ' ' << v[spec[i]] << endl;

            if (y == inf + 7)
                return false;

           // cout << "initial " << y << endl;
            for (j = spec[i - 1] + 1, k = y; j <= spec[i] - 1; j++, k++)
                v[j] = k;
        }
    }

    return true;
}

signed main()
{
    ios_base::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;

    cit();

    for (int i = 1; i <= n; i++) {
        v[i] = gett();
        //cout << v[i] << endl;
    }

    for (int i = 0; i < k; i++)
        vects[i].push_back(-inf);

    for (int i = 1; i <= n; i++)
        vects[i % k].push_back(v[i]);

    for (int i = 0; i < k; i++)
        vects[i].push_back(inf);

    for (int i = 0; i < k; i++)
        if (!create(vects[i], spec[i])) {
            cout << "Incorrect sequence\n";
            return 0;
        }

    for (int i = 1; i <= n; i++) {
        v[i] = vects[i % k][(i - 1) / k + 1];
    }

    for (int i = 1; i <= n; i++)
        cout << v[i] << ' ';
    cout << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <vector>
#include <utility>

#define inf 100000000000000007ll
#define int long long int
using namespace std;

char sir[10000005];
int poz;
int lung;

inline void cit () {
    cin.get();
    cin.get(sir + 1, 10000005);

    poz = 1;
    lung = strlen(sir + 1);
}

inline int gett () {
    int ans = 0;
    while (poz <= lung && sir[poz] == ' ')
        poz ++;

    if (sir[poz] == '?') {
        poz ++;
        return (inf + 1);
    }

    int semn = 1;
    if (sir[poz] == '-') {
        poz ++;
        semn = -1;
    }

    while (poz <= lung && isdigit(sir[poz])) {
        ans *= 10;
        ans += sir[poz] - '0';
        poz ++;
    }

    return semn * ans;
}

int gauss (int n) {
    return (n * (n + 1ll) / 2);
}

int suma (int st, int dr) {
    if (st >= 0) {
        return gauss(dr) - gauss(st - 1);
    }
    else if (dr <= 0) {
        st *= -1;
        dr *= -1;

        swap(st, dr);

        return gauss(dr) - gauss(st - 1);
    }
    else {
        return suma(st, 0) + suma(0, dr);
    }
}

int best (int lung, int st, int dr) {
    if (dr - st + 1 < lung)
        return inf + 7;

    int st_best = st;
    int ans_best = suma(st, st + lung - 1);

    if (suma(dr - lung + 1, dr) < ans_best) {
        st_best = dr - lung + 1;
        ans_best = suma(dr - lung + 1, dr);
    }

    int st_aux = - (lung - 1) / 2;
    int dr_aux = lung / 2;

    if (st_aux >= st && dr_aux <= dr) {
        if (suma(st_aux, dr_aux) < ans_best) {
            st_best = st_aux;
            ans_best = suma(st_aux, dr_aux);
        }
    }

    return st_best;
}

int v[100005];

vector <int> vects[100005];
vector <int> spec[100005];

inline bool create (vector<int> &v, vector<int> &spec) {
    for (int i = 0; i < v.size(); i++)
        if (v[i] != inf + 1)
            spec.push_back(i);

    for (int i = 1; i < spec.size(); i++)
        if (v[spec[i - 1]] >= v[spec[i]])
            return false;

    int y;
    int j, k;
    for (int i = 1; i < spec.size(); i++) {
        if (spec[i] - spec[i - 1] - 1 > 0) {
            y = best(spec[i] - spec[i - 1] - 1, v[spec[i - 1]] + 1, v[spec[i]] - 1);
            if (y == inf + 7)
                return false;

            for (j = spec[i - 1] + 1, k = y; j <= spec[i] - 1; j++, k++)
                v[j] = k;
        }
    }

    return true;
}

signed main()
{
    ios_base::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;

    cit();

    for (int i = 1; i <= n; i++) {
        v[i] = gett();
        //cout << v[i] << endl;
    }

    for (int i = 0; i < k; i++)
        vects[i].push_back(-inf);

    for (int i = 1; i <= n; i++)
        vects[i % k].push_back(v[i]);

    for (int i = 0; i < k; i++)
        vects[i].push_back(inf);

    for (int i = 0; i < k; i++)
        if (!create(vects[i], spec[i])) {
            cout << "Incorrect sequence\n";
            return 0;
        }

    for (int i = 1; i <= n; i++) {
        v[i] = vects[i % k][(i - 1) / k + 1];
    }

    for (int i = 1; i <= n; i++)
        cout << v[i] << ' ';
    cout << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <vector>
#include <utility>

#define inf 1000000007
#define lint long long int
#define int long long int
using namespace std;

 char sir[4000005];
int poz;
int lung;

inline void cit () {
    cin.get();
    cin.get(sir + 1, 4000005);

    poz = 1;
    lung = strlen(sir + 1);
}

inline int gett () {
    int ans = 0;
    while (poz <= lung && sir[poz] == ' ')
        poz ++;

    if (sir[poz] == '?') {
        poz ++;
        return (inf + 1);
    }

    int semn = 1;
    if (sir[poz] == '-') {
        poz ++;
        semn = -1;
    }

    while (poz <= lung && isdigit(sir[poz])) {
        ans *= 10;
        ans += sir[poz] - '0';
        poz ++;
    }

    return semn * ans;
}

int gauss (int n) {
    return (n * (n + 1ll) / 2);
}

int suma (int st, int dr) {
    if (st >= 0) {
        return gauss(dr) - gauss(st - 1);
    }
    else if (dr <= 0) {
        st *= -1;
        dr *= -1;

        swap(st, dr);

        return gauss(dr) - gauss(st - 1);
    }
    else {
        return suma(st, 0) + suma(0, dr);
    }
}

int best (int lung, int st, int dr) {
    if (dr - st + 1 < lung)
        return inf + 7;

    int st_best = st;
    int ans_best = suma(st, st + lung - 1);

    if (suma(dr - lung + 1, dr) < ans_best) {
        st_best = dr - lung + 1;
        ans_best = suma(dr - lung + 1, dr);
    }

    int st_aux = - (lung - 1) / 2;
    int dr_aux = lung / 2;

    if (st_aux >= st && dr_aux <= dr) {
        if (suma(st_aux, dr_aux) < ans_best) {
            st_best = st_aux;
            ans_best = suma(st_aux, dr_aux);
        }
    }

    return st_best;
}

int v[100005];

vector <int> vects[100005];
vector <int> spec[100005];

inline bool create (vector<int> &v, vector<int> &spec) {
    for (int i = 0; i < v.size(); i++)
        if (v[i] != inf + 1)
            spec.push_back(i);

    for (int i = 1; i < spec.size(); i++)
        if (v[spec[i - 1]] >= v[spec[i]])
            return false;

    int y;
    int j, k;
    for (int i = 1; i < spec.size(); i++) {
        if (spec[i] - spec[i - 1] - 1 > 0) {
            y = best(spec[i] - spec[i - 1] - 1, v[spec[i - 1]] + 1, v[spec[i]] - 1);
            if (y == inf + 7)
                return false;

            for (j = spec[i - 1] + 1, k = y; j <= spec[i] - 1; j++, k++)
                v[j] = k;
        }
    }

    return true;
}

signed main()
{
    ios_base::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;

    cit();

    for (int i = 1; i <= n; i++) {
        v[i] = gett();
        //cout << v[i] << endl;
    }

    for (int i = 0; i < k; i++)
        vects[i].push_back(-inf);

    for (int i = 1; i <= n; i++)
        vects[i % k].push_back(v[i]);

    for (int i = 0; i < k; i++)
        vects[i].push_back(inf);

    for (int i = 0; i < k; i++)
        if (!create(vects[i], spec[i])) {
            cout << "Incorrect sequence\n";
            return 0;
        }

    for (int i = 1; i <= n; i++) {
        v[i] = vects[i % k][(i - 1) / k + 1];
    }

    for (int i = 1; i <= n; i++)
        cout << v[i] << ' ';
    cout << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <vector>
#include <utility>

#define inf 1000000007
#define lint long long int
using namespace std;

 char sir[4000005];
int poz;
int lung;

inline void cit () {
    cin.get();
    cin.get(sir + 1, 4000005);

    poz = 1;
    lung = strlen(sir + 1);
}

inline int gett () {
    int ans = 0;
    while (poz <= lung && sir[poz] == ' ')
        poz ++;

    if (sir[poz] == '?') {
        poz ++;
        return (inf + 1);
    }

    int semn = 1;
    if (sir[poz] == '-') {
        poz ++;
        semn = -1;
    }

    while (poz <= lung && isdigit(sir[poz])) {
        ans *= 10;
        ans += sir[poz] - '0';
        poz ++;
    }

    return semn * ans;
}

lint gauss (int n) {
    return (n * (n + 1ll) / 2);
}

lint suma (int st, int dr) {
    if (st >= 0) {
        return gauss(dr) - gauss(st - 1);
    }
    else if (dr <= 0) {
        st *= -1;
        dr *= -1;

        swap(st, dr);

        return gauss(dr) - gauss(st - 1);
    }
    else {
        return suma(st, 0) + suma(0, dr);
    }
}

int best (int lung, int st, int dr) {
    if (dr - st + 1 < lung)
        return -1;

    int st_best = st;
    lint ans_best = suma(st, st + lung - 1);

    if (suma(dr - lung + 1, dr) < ans_best) {
        st_best = dr - lung + 1;
        ans_best = suma(dr - lung + 1, dr);
    }

    int st_aux = - (lung - 1) / 2;
    int dr_aux = lung / 2;

    if (st_aux >= st && dr_aux <= dr) {
        if (suma(st_aux, dr_aux) < ans_best) {
            st_best = st_aux;
            ans_best = suma(st_aux, dr_aux);
        }
    }

    return st_best;
}

int v[100005];

vector <int> vects[100005];
vector <int> spec[100005];

inline bool create (vector<int> &v, vector<int> &spec) {
    for (int i = 0; i < v.size(); i++)
        if (v[i] != inf + 1)
            spec.push_back(i);

    for (int i = 1; i < spec.size(); i++)
        if (v[spec[i - 1]] >= v[spec[i]])
            return false;

    int y;
    int j, k;
    for (int i = 1; i < spec.size(); i++) {

        if (spec[i] - spec[i - 1] - 1 > 0) {
            y = best(spec[i] - spec[i - 1] - 1, v[spec[i - 1]] + 1, v[spec[i]] - 1);
            if (y == -1)
                return false;

            for (j = spec[i - 1] + 1, k = y; j <= spec[i] - 1; j++)
                v[j] = k;
        }
    }

    return true;
}

int main()
{
    ios_base::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;

    cit();

    for (int i = 1; i <= n; i++) {
        v[i] = gett();
        //cout << v[i] << endl;
    }

    for (int i = 0; i < k; i++)
        vects[i].push_back(-inf);

    for (int i = 1; i <= n; i++)
        vects[i % k].push_back(v[i]);

    for (int i = 0; i < k; i++)
        vects[i].push_back(inf);

    for (int i = 0; i < k; i++)
        if (!create(vects[i], spec[i])) {
            cout << "Incorrect sequence\n";
            return 0;
        }

    for (int i = 1; i <= n; i++) {
        v[i] = vects[i % k][(i - 1) / k + 1];
    }

    for (int i = 1; i <= n; i++)
        cout << v[i] << ' ';
    cout << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <vector>
#include <utility>

#define inf 1100000007ll
#define int long long int
using namespace std;

char sir[4000005];
int poz;
int lung;

inline void cit () {
    cin.get();
    cin.get(sir + 1, 4000005);

    poz = 1;
    lung = strlen(sir + 1);
}

inline int gett () {
    int ans = 0;
    while (poz <= lung && sir[poz] == ' ')
        poz ++;

    if (sir[poz] == '?') {
        poz ++;
        return (inf + 1);
    }

    int semn = 1;
    if (sir[poz] == '-') {
        poz ++;
        semn = -1;
    }

    while (poz <= lung && isdigit(sir[poz])) {
        ans *= 10;
        ans += sir[poz] - '0';
        poz ++;
    }

    return semn * ans;
}

int gauss (int n) {
    return (n * (n + 1ll) / 2);
}

int suma (int st, int dr) {
    if (st >= 0) {
        return gauss(dr) - gauss(st - 1);
    }
    else if (dr <= 0) {
        st *= -1;
        dr *= -1;

        swap(st, dr);

        return gauss(dr) - gauss(st - 1);
    }
    else {
        return suma(st, 0) + suma(0, dr);
    }
}

int best (int lung, int st, int dr) {
    if (dr - st + 1 < lung)
        return inf + 7;

    int st_best = st;
    int ans_best = suma(st, st + lung - 1);

    if (suma(dr - lung + 1, dr) < ans_best) {
        st_best = dr - lung + 1;
        ans_best = suma(dr - lung + 1, dr);
    }

    int st_aux = - (lung - 1) / 2;
    int dr_aux = lung / 2;

    if (st_aux >= st && dr_aux <= dr) {
        if (suma(st_aux, dr_aux) < ans_best) {
            st_best = st_aux;
            ans_best = suma(st_aux, dr_aux);
        }
    }

    return st_best;
}

int v[100005];

vector <int> vects[100005];
vector <int> spec[100005];

inline bool create (vector<int> &v, vector<int> &spec) {
    for (int i = 0; i < v.size(); i++)
        if (v[i] != inf + 1)
            spec.push_back(i);

    for (int i = 1; i < spec.size(); i++)
        if (v[spec[i - 1]] >= v[spec[i]])
            return false;

    int y;
    int j, k;
    for (int i = 1; i < spec.size(); i++) {
        if (spec[i] - spec[i - 1] - 1 > 0) {
            y = best(spec[i] - spec[i - 1] - 1, v[spec[i - 1]] + 1, v[spec[i]] - 1);

            if (y == inf + 7)
                return false;

            for (j = spec[i - 1] + 1, k = y; j <= spec[i] - 1; j++, k++)
                v[j] = k;
        }
    }

    return true;
}

signed main()
{
    ios_base::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;

    cit();
    for (int i = 1; i <= n; i++)
        v[i] = gett();

    for (int i = 0; i < k; i++)
        vects[i].push_back(-inf);

    for (int i = 1; i <= n; i++)
        vects[i % k].push_back(v[i]);

    for (int i = 0; i < k; i++)
        vects[i].push_back(inf);

    for (int i = 0; i < k; i++)
        if (!create(vects[i], spec[i])) {
            cout << "Incorrect sequence\n";
            return 0;
        }

    for (int i = 1; i <= n; i++) {
        v[i] = vects[i % k][(i - 1) / k + 1];
    }

    for (int i = 1; i <= n; i++)
        cout << v[i] << ' ';
    cout << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <vector>
#include <utility>

#define inf 1000000007
#define lint long long int
#define int long long int
using namespace std;

 char sir[4000005];
int poz;
int lung;

inline void cit () {
    cin.get();
    cin.get(sir + 1, 4000005);

    poz = 1;
    lung = strlen(sir + 1);
}

inline int gett () {
    int ans = 0;
    while (poz <= lung && sir[poz] == ' ')
        poz ++;

    if (sir[poz] == '?') {
        poz ++;
        return (inf + 1);
    }

    int semn = 1;
    if (sir[poz] == '-') {
        poz ++;
        semn = -1;
    }

    while (poz <= lung && isdigit(sir[poz])) {
        ans *= 10;
        ans += sir[poz] - '0';
        poz ++;
    }

    return semn * ans;
}

lint gauss (int n) {
    return (n * (n + 1ll) / 2);
}

lint suma (int st, int dr) {
    if (st >= 0) {
        return gauss(dr) - gauss(st - 1);
    }
    else if (dr <= 0) {
        st *= -1;
        dr *= -1;

        swap(st, dr);

        return gauss(dr) - gauss(st - 1);
    }
    else {
        return suma(st, 0) + suma(0, dr);
    }
}

int best (int lung, int st, int dr) {
    if (dr - st + 1 < lung)
        return -1;

    int st_best = st;
    lint ans_best = suma(st, st + lung - 1);

    if (suma(dr - lung + 1, dr) < ans_best) {
        st_best = dr - lung + 1;
        ans_best = suma(dr - lung + 1, dr);
    }

    int st_aux = - (lung - 1) / 2;
    int dr_aux = lung / 2;

    if (st_aux >= st && dr_aux <= dr) {
        if (suma(st_aux, dr_aux) < ans_best) {
            st_best = st_aux;
            ans_best = suma(st_aux, dr_aux);
        }
    }

    return st_best;
}

int v[100005];

vector <int> vects[100005];
vector <int> spec[100005];

inline bool create (vector<int> &v, vector<int> &spec) {
    for (int i = 0; i < v.size(); i++)
        if (v[i] != inf + 1)
            spec.push_back(i);

    for (int i = 1; i < spec.size(); i++)
        if (v[spec[i - 1]] >= v[spec[i]])
            return false;

    int y;
    int j, k;
    for (int i = 1; i < spec.size(); i++) {

        if (spec[i] - spec[i - 1] - 1 > 0) {
            y = best(spec[i] - spec[i - 1] - 1, v[spec[i - 1]] + 1, v[spec[i]] - 1);
            if (y == -1)
                return false;

            for (j = spec[i - 1] + 1, k = y; j <= spec[i] - 1; j++)
                v[j] = k;
        }
    }

    return true;
}

signed main()
{
    ios_base::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;

    cit();

    for (int i = 1; i <= n; i++) {
        v[i] = gett();
        //cout << v[i] << endl;
    }

    for (int i = 0; i < k; i++)
        vects[i].push_back(-inf);

    for (int i = 1; i <= n; i++)
        vects[i % k].push_back(v[i]);

    for (int i = 0; i < k; i++)
        vects[i].push_back(inf);

    for (int i = 0; i < k; i++)
        if (!create(vects[i], spec[i])) {
            cout << "Incorrect sequence\n";
            return 0;
        }

    for (int i = 1; i <= n; i++) {
        v[i] = vects[i % k][(i - 1) / k + 1];
    }

    for (int i = 1; i <= n; i++)
        cout << v[i] << ' ';
    cout << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <vector>
#include <utility>

#define inf 1000000007
#define lint long long int
using namespace std;

 char sir[4000005];
int poz;
int lung;

inline void cit () {
    cin.get();
    cin.get(sir + 1, 4000005);

    poz = 1;
    lung = strlen(sir + 1);
}

inline int gett () {
    int ans = 0;
    while (poz <= lung && sir[poz] == ' ')
        poz ++;

    if (sir[poz] == '?') {
        poz ++;
        return (inf + 1);
    }

    int semn = 1;
    if (sir[poz] == '-') {
        poz ++;
        semn = -1;
    }

    while (poz <= lung && isdigit(sir[poz])) {
        ans *= 10;
        ans += sir[poz] - '0';
        poz ++;
    }

    return semn * ans;
}

lint gauss (int n) {
    return (n * (n + 1ll) / 2);
}

lint suma (int st, int dr) {
    if (st >= 0) {
        return gauss(dr) - gauss(st - 1);
    }
    else if (dr <= 0) {
        st *= -1;
        dr *= -1;

        swap(st, dr);

        return gauss(dr) - gauss(st - 1);
    }
    else {
        return suma(st, 0) + suma(0, dr);
    }
}

int best (int lung, int st, int dr) {
    if (dr - st + 1 < lung)
        return -1;

    int st_best = st, ans_best = suma(st, st + lung - 1);

    if (suma(dr - lung + 1, dr) < ans_best) {
        st_best = dr - lung + 1;
        ans_best = suma(dr - lung + 1, dr);
    }

    int st_aux = - (lung - 1) / 2;
    int dr_aux = lung / 2;

    if (st_aux >= st && dr_aux <= dr) {
        if (suma(st_aux, dr_aux) < ans_best) {
            st_best = st_aux;
            ans_best = suma(st_aux, dr_aux);
        }
    }

    return st_best;
}

int v[100005];

vector <int> vects[100005];
vector <int> spec[100005];

inline bool create (vector<int> &v, vector<int> &spec) {
    for (int i = 0; i < v.size(); i++)
        if (v[i] != inf + 1)
            spec.push_back(i);

    for (int i = 1; i < spec.size(); i++)
        if (v[spec[i - 1]] >= v[spec[i]])
            return false;

    int y;
    int j, k;
    for (int i = 1; i < spec.size(); i++) {

        if (spec[i] - spec[i - 1] - 1 > 0) {
            y = best(spec[i] - spec[i - 1] - 1, v[spec[i - 1]] + 1, v[spec[i]] - 1);
            if (y == -1)
                return false;

            for (j = spec[i - 1] + 1, k = y; j <= spec[i] - 1; j++)
                v[j] = k;
        }
    }

    return true;
}

int main()
{
    ios_base::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;

    cit();

    for (int i = 1; i <= n; i++) {
        v[i] = gett();
        //cout << v[i] << endl;
    }

    for (int i = 0; i < k; i++)
        vects[i].push_back(-inf);

    for (int i = 1; i <= n; i++)
        vects[i % k].push_back(v[i]);

    for (int i = 0; i < k; i++)
        vects[i].push_back(inf);

    for (int i = 0; i < k; i++)
        if (!create(vects[i], spec[i])) {
            cout << "Incorrect sequence\n";
            return 0;
        }

    for (int i = 1; i <= n; i++) {
        v[i] = vects[i % k][(i - 1) / k + 1];
    }

    for (int i = 1; i <= n; i++)
        cout << v[i] << ' ';
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(a) int(a.size())
#define reset(a, x) memset(a, x, sizeof(a))

#define FOR(i, a, b)   for(int i = a; i <= b; ++i)
#define FORD(i, a, b)  for(int i = a; i >= b; --i)
#define REP(i, n)      for(int i = 0, _n = n; i < _n; ++i)
#define REPD(i, n)     for(int i = n - 1; i >= 0; --i)
#define FORSZ(i, x)    for(int i = 0; i < sz(x); ++i)

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pii> vii;

#define oo 1000100000
#define eps 1E-9

const int MAXN = 1E5 + 5;

int n, k, a[MAXN];

bool mark[MAXN];

int main() {
    #ifdef LOCAL_JUDGE
        freopen("input.txt", "r", stdin);
    #endif
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; ++i) {
        string buf;
        cin >> buf;
        if (buf == "?")
            a[i] = 0, mark[i] = 1;
        else
            a[i] = atoi(buf.c_str()), mark[i] = 0;
//        a[i] += a[i - 1];
    }

    for (int st = 1; st <= k; ++st) {
        for (int i = st; i + k <= n; i += k)
            if (!mark[i] && !mark[i + k] && a[i] >= a[i + k]) {
                puts("Incorrect sequence");
                return 0;
            }
        int x, y = st;
        while (1) {
            for (x = y; x <= n && !mark[x]; x += k);
            if (!mark[x]) break;
            int cnt = 0;
            for (y = x; y <= n && mark[y]; y += k)
                ++cnt;

            int v1, v2;
            if (x - k < 1)
                v1 = -oo;
            else
                v1 = a[x - k];
            if (y > n)
                v2 = oo;
            else
                v2 = a[y];
//            cout << x <<" "<<y <<" "<<cnt <<" "<<v2 - v1 - 1<< endl;
            if (cnt > v2 - v1 - 1) {
                puts("Incorrect sequence");
                return 0;
            }

            if (v1 < 0 && v2 > 0) {
                cnt = - (cnt / 2);
            }
            else if (v1 > 0 && v2 > 0) {
                cnt = v1 + 1;
            }
            else {
                cnt = v2 - cnt;
            }
            for (int i = x; i < y; i += k)
                a[i] = cnt++;
        }
    }
    for (int i = 1; i <= n; ++i)
        printf("%d ", a[i]);
}


#include <bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(a) int(a.size())
#define reset(a, x) memset(a, x, sizeof(a))

#define FOR(i, a, b)   for(int i = a; i <= b; ++i)
#define FORD(i, a, b)  for(int i = a; i >= b; --i)
#define REP(i, n)      for(int i = 0, _n = n; i < _n; ++i)
#define REPD(i, n)     for(int i = n - 1; i >= 0; --i)
#define FORSZ(i, x)    for(int i = 0; i < sz(x); ++i)

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pii> vii;

#define oo 1000000001
#define eps 1E-9

const int MAXN = 1E5 + 5;

int n, k, a[MAXN];

bool mark[MAXN];

int main() {
    #ifdef LOCAL_JUDGE
        freopen("input.txt", "r", stdin);
    #endif
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; ++i) {
        string buf;
        cin >> buf;
        if (buf == "?")
            a[i] = 0, mark[i] = 1;
        else
            a[i] = atoi(buf.c_str()), mark[i] = 0;
//        a[i] += a[i - 1];
    }
    a[0] = -oo;
    for (int i = 1; i <= k; ++i)
        a[n + i] = oo;

    for (int st = 1; st <= k; ++st) {
        for (int i = st; i + k <= n; i += k)
            if (!mark[i] && !mark[i + k] && a[i] >= a[i + k]) {
                puts("Incorrect sequence");
                return 0;
            }
        int x, y = st;
        while (1) {
            for (x = y; x <= n && !mark[x]; x += k);
            if (!mark[x]) break;
            int cnt = 0;
            for (y = x; y <= n && mark[y]; y += k)
                ++cnt;
//            cout << x <<" "<<y <<" "<<cnt <<" "<<a[y] - a[x - 1] - 1<< endl;
            if (cnt > a[y] - a[x - 1] - 1) {
                puts("Incorrect sequence");
                return 0;
            }

            if (a[x - 1] < 0 && a[y] > 0) {
                cnt = - (cnt / 2);
            }
            else if (a[x - 1] > 0 && a[y] > 0) {
                cnt = a[x - 1] + 1;
            }
            else {
                cnt = a[y] - cnt;
            }
            for (int i = x; i < y; i += k)
                a[i] = cnt++;
        }
    }
    for (int i = 1; i <= n; ++i)
        printf("%d ", a[i]);
}


#include <bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(a) int(a.size())
#define reset(a, x) memset(a, x, sizeof(a))

#define FOR(i, a, b)   for(int i = a; i <= b; ++i)
#define FORD(i, a, b)  for(int i = a; i >= b; --i)
#define REP(i, n)      for(int i = 0, _n = n; i < _n; ++i)
#define REPD(i, n)     for(int i = n - 1; i >= 0; --i)
#define FORSZ(i, x)    for(int i = 0; i < sz(x); ++i)

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pii> vii;

#define oo 1000000001
#define eps 1E-9

const int MAXN = 1E5 + 5;

int n, k, a[MAXN];

bool mark[MAXN];

int main() {
    #ifdef LOCAL_JUDGE
        freopen("input.txt", "r", stdin);
    #endif
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; ++i) {
        string buf;
        cin >> buf;
        if (buf == "?")
            a[i] = 0, mark[i] = 1;
        else
            a[i] = atoi(buf.c_str()), mark[i] = 0;
//        a[i] += a[i - 1];
    }
    a[0] = -oo;
    a[n + 1] = oo;

    for (int st = 1; st <= k; ++st) {
        for (int i = st; i + k <= n; i += k)
            if (!mark[i] && !mark[i + k] && a[i] >= a[i + k]) {
                puts("Incorrect sequence");
                return 0;
            }
        int x, y = st;
        while (1) {
            for (x = y; x <= n && !mark[x]; x += k);
            if (!mark[x]) break;
            int cnt = 0;
            for (y = x; y <= n && mark[y]; y += k)
                ++cnt;
//            cout << x <<" "<<y <<" "<<cnt <<" "<<a[y] - a[x - 1] - 1<< endl;
            if (cnt > a[y] - a[x - 1] - 1) {
                puts("Incorrect sequence");
                return 0;
            }

            if (a[x - 1] < 0 && a[y] > 0) {
                cnt = - (cnt / 2);
            }
            else if (a[x - 1] > 0 && a[y] > 0) {
                cnt = a[x - 1] + 1;
            }
            else {
                cnt = a[y] - cnt;
            }
            for (int i = x; i < y; i += k)
                a[i] = cnt++;
        }
    }
    for (int i = 1; i <= n; ++i)
        printf("%d ", a[i]);
}


#include <bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(a) int(a.size())
#define reset(a, x) memset(a, x, sizeof(a))

#define FOR(i, a, b)   for(int i = a; i <= b; ++i)
#define FORD(i, a, b)  for(int i = a; i >= b; --i)
#define REP(i, n)      for(int i = 0, _n = n; i < _n; ++i)
#define REPD(i, n)     for(int i = n - 1; i >= 0; --i)
#define FORSZ(i, x)    for(int i = 0; i < sz(x); ++i)

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pii> vii;

#define oo 1000100000
#define eps 1E-9

const int MAXN = 1E5 + 5;

int n, k, a[MAXN];

bool mark[MAXN];

int main() {
    #ifdef LOCAL_JUDGE
        freopen("input.txt", "r", stdin);
    #endif
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; ++i) {
        string buf;
        cin >> buf;
        if (buf == "?")
            a[i] = 0, mark[i] = 1;
        else
            a[i] = atoi(buf.c_str()), mark[i] = 0;
//        a[i] += a[i - 1];
    }

    for (int st = 1; st <= k; ++st) {
        for (int i = st; i + k <= n; i += k)
            if (!mark[i] && !mark[i + k] && a[i] >= a[i + k]) {
                puts("Incorrect sequence");
                return 0;
            }
        int x, y = st;
        while (1) {
            for (x = y; x <= n && !mark[x]; x += k);
            if (x > n) break;
            int cnt = 0;
            for (y = x; y <= n && mark[y]; y += k)
                ++cnt;

            int v1, v2;
            if (x - k < 1)
                v1 = -oo;
            else
                v1 = a[x - k];
            if (y > n)
                v2 = oo;
            else
                v2 = a[y];
//            cout << x <<" "<<y <<" "<<cnt <<" "<<v2 - v1 - 1<< endl;
            if (cnt > v2 - v1 - 1) {
                puts("Incorrect sequence");
                return 0;
            }

            if (v1 < 0 && v2 > 0) {
                int v = - (cnt / 2);
                while (v <= v1) ++v;
                while (v + cnt - 1 >= v2) --v;
            }
            else if (v1 >= 0 && v2 >= 0) {
                cnt = v1 + 1;
            }
            else {
                cnt = v2 - cnt;
            }
            for (int i = x; i < y; i += k)
                a[i] = cnt++;
        }
    }
    for (int i = 1; i <= n; ++i)
        printf("%d ", a[i]);
}


#include <bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(a) int(a.size())
#define reset(a, x) memset(a, x, sizeof(a))

#define FOR(i, a, b)   for(int i = a; i <= b; ++i)
#define FORD(i, a, b)  for(int i = a; i >= b; --i)
#define REP(i, n)      for(int i = 0, _n = n; i < _n; ++i)
#define REPD(i, n)     for(int i = n - 1; i >= 0; --i)
#define FORSZ(i, x)    for(int i = 0; i < sz(x); ++i)

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pii> vii;

#define oo 1000000001
#define eps 1E-9

const int MAXN = 1E5 + 5;

int n, k, a[MAXN];

bool mark[MAXN];

int main() {
    #ifdef LOCAL_JUDGE
        freopen("input.txt", "r", stdin);
    #endif
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; ++i) {
        string buf;
        cin >> buf;
        if (buf == "?")
            a[i] = 0, mark[i] = 1;
        else
            a[i] = atoi(buf.c_str()), mark[i] = 0;
//        a[i] += a[i - 1];
    }
    a[0] = -oo;
    a[n + 1] = oo;

    for (int st = 1; st <= k; ++st) {
        for (int i = st; i + k <= n; i += k)
            if (!mark[i] && !mark[i + k] && a[i] >= a[i + k]) {
                puts("Incorrect sequence");
                return 0;
            }
        int x, y = st;
        while (1) {
            for (x = y; x <= n && !mark[x]; x += k);
            if (!mark[x]) break;
            int cnt = 0;
            for (y = x; y <= n && mark[y]; y += k)
                ++cnt;
//            cout << x <<" "<<y <<" "<<cnt <<" "<<a[y] - a[x - 1] - 1<< endl;
            if (cnt > a[y] - a[x - 1] - 1) {
                puts("Incorrect sequence");
                return 0;
            }

            cnt = a[x - 1];
            for (int i = x; i < y; i += k)
                a[i] = ++cnt;
        }
    }
    for (int i = 1; i <= n; ++i)
        printf("%d ", a[i]);
}


#include <bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(a) int(a.size())
#define reset(a, x) memset(a, x, sizeof(a))

#define FOR(i, a, b)   for(int i = a; i <= b; ++i)
#define FORD(i, a, b)  for(int i = a; i >= b; --i)
#define REP(i, n)      for(int i = 0, _n = n; i < _n; ++i)
#define REPD(i, n)     for(int i = n - 1; i >= 0; --i)
#define FORSZ(i, x)    for(int i = 0; i < sz(x); ++i)

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pii> vii;

#define oo 1000000001
#define eps 1E-9

const int MAXN = 1E5 + 5;

int n, k, a[MAXN];

bool mark[MAXN];

int main() {
    #ifdef LOCAL_JUDGE
        freopen("input.txt", "r", stdin);
    #endif
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; ++i) {
        string buf;
        cin >> buf;
        if (buf == "?")
            a[i] = 0, mark[i] = 1;
        else
            a[i] = atoi(buf.c_str()), mark[i] = 0;
//        a[i] += a[i - 1];
    }
    a[0] = -oo;
    a[n + 1] = oo;

    for (int st = 1; st <= k; ++st) {
        for (int i = st; i + k <= n; i <= k)
            if (!mark[i] && !mark[i + k] && a[i] >= a[i + k]) {
                puts("Incorrect sequence");
                return 0;
            }
        int x, y = st;
        while (1) {
            for (x = y; x <= n && !mark[x]; x += k);
            if (!mark[x]) break;
            int cnt = 0;
            for (y = x; y <= n && mark[y]; y += k)
                ++cnt;
//            cout << x <<" "<<y <<" "<<cnt <<" "<<a[y] - a[x - 1] - 1<< endl;
            if (cnt > a[y] - a[x - 1] - 1) {
                puts("Incorrect sequence");
                return 0;
            }

            cnt = a[x - 1];
            for (int i = x; i < y; i += k)
                a[i] = ++cnt;
        }
    }
    for (int i = 1; i <= n; ++i)
        printf("%d ", a[i]);
}


#include <bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(a) int(a.size())
#define reset(a, x) memset(a, x, sizeof(a))

#define FOR(i, a, b)   for(int i = a; i <= b; ++i)
#define FORD(i, a, b)  for(int i = a; i >= b; --i)
#define REP(i, n)      for(int i = 0, _n = n; i < _n; ++i)
#define REPD(i, n)     for(int i = n - 1; i >= 0; --i)
#define FORSZ(i, x)    for(int i = 0; i < sz(x); ++i)

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pii> vii;

#define oo 1000100000
#define eps 1E-9

const int MAXN = 1E5 + 5;

int n, k, a[MAXN];

bool mark[MAXN];

int main() {
    #ifdef LOCAL_JUDGE
        freopen("input.txt", "r", stdin);
    #endif
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; ++i) {
        string buf;
        cin >> buf;
        if (buf == "?")
            a[i] = 0, mark[i] = 1;
        else
            a[i] = atoi(buf.c_str()), mark[i] = 0;
//        a[i] += a[i - 1];
    }
    a[0] = -oo;
    for (int i = 1; i <= k; ++i)
        a[n + i] = oo;

    for (int st = 1; st <= k; ++st) {
        for (int i = st; i + k <= n; i += k)
            if (!mark[i] && !mark[i + k] && a[i] >= a[i + k]) {
                puts("Incorrect sequence");
                return 0;
            }
        int x, y = st;
        while (1) {
            for (x = y; x <= n && !mark[x]; x += k);
            if (!mark[x]) break;
            int cnt = 0;
            for (y = x; y <= n && mark[y]; y += k)
                ++cnt;
//            cout << x <<" "<<y <<" "<<cnt <<" "<<a[y] - a[x - 1] - 1<< endl;
            if (cnt > a[y] - a[x - 1] - 1) {
                puts("Incorrect sequence");
                return 0;
            }

            if (a[x - 1] < 0 && a[y] > 0) {
                cnt = - (cnt / 2);
            }
            else if (a[x - 1] > 0 && a[y] > 0) {
                cnt = a[x - 1] + 1;
            }
            else {
                cnt = a[y] - cnt;
            }
            for (int i = x; i < y; i += k)
                a[i] = cnt++;
        }
    }
    for (int i = 1; i <= n; ++i)
        printf("%d ", a[i]);
}


#include <bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(a) int(a.size())
#define reset(a, x) memset(a, x, sizeof(a))

#define FOR(i, a, b)   for(int i = a; i <= b; ++i)
#define FORD(i, a, b)  for(int i = a; i >= b; --i)
#define REP(i, n)      for(int i = 0, _n = n; i < _n; ++i)
#define REPD(i, n)     for(int i = n - 1; i >= 0; --i)
#define FORSZ(i, x)    for(int i = 0; i < sz(x); ++i)

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pii> vii;

#define oo 1000100000
#define eps 1E-9

const int MAXN = 1E5 + 5;

int n, k, a[MAXN];

bool mark[MAXN];

int main() {
    #ifdef LOCAL_JUDGE
        freopen("input.txt", "r", stdin);
    #endif
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; ++i) {
        string buf;
        cin >> buf;
        if (buf == "?")
            a[i] = 0, mark[i] = 1;
        else
            a[i] = atoi(buf.c_str()), mark[i] = 0;
//        a[i] += a[i - 1];
    }

    for (int st = 1; st <= k; ++st) {
        for (int i = st; i + k <= n; i += k)
            if (!mark[i] && !mark[i + k] && a[i] >= a[i + k]) {
                puts("Incorrect sequence");
                return 0;
            }
        int x, y = st;
        while (1) {
            for (x = y; x <= n && !mark[x]; x += k);
            if (x > n) break;
            int cnt = 0;
            for (y = x; y <= n && mark[y]; y += k)
                ++cnt;

            int v1, v2;
            if (x - k < 1)
                v1 = -oo;
            else
                v1 = a[x - k];
            if (y > n)
                v2 = oo;
            else
                v2 = a[y];
//            cout << x <<" "<<y <<" "<<cnt <<" "<<v2 - v1 - 1<< endl;
            if (cnt > v2 - v1 - 1) {
                puts("Incorrect sequence");
                return 0;
            }

//            cout << v1 <<" "<<v2 << endl;
            if (v1 < 0 && v2 > 0) {
                int v = - (cnt / 2);
                while (v <= v1) ++v;
                while (v + cnt - 1 >= v2) --v;
                cnt = v;
            }
            else if (v1 >= 0 && v2 >= 0) {
                cnt = v1 + 1;
            }
            else {
                cnt = v2 - cnt;
            }
            for (int i = x; i < y; i += k)
                a[i] = cnt++;
        }
    }
    for (int i = 1; i <= n; ++i)
        printf("%d ", a[i]);
}


#include <bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(a) int(a.size())
#define reset(a, x) memset(a, x, sizeof(a))

#define FOR(i, a, b)   for(int i = a; i <= b; ++i)
#define FORD(i, a, b)  for(int i = a; i >= b; --i)
#define REP(i, n)      for(int i = 0, _n = n; i < _n; ++i)
#define REPD(i, n)     for(int i = n - 1; i >= 0; --i)
#define FORSZ(i, x)    for(int i = 0; i < sz(x); ++i)

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pii> vii;

#define oo 1000100000
#define eps 1E-9

const int MAXN = 1E5 + 5;

int n, k, a[MAXN];

bool mark[MAXN];

int main() {
    #ifdef LOCAL_JUDGE
        freopen("input.txt", "r", stdin);
    #endif
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; ++i) {
        string buf;
        cin >> buf;
        if (buf == "?")
            a[i] = 0, mark[i] = 1;
        else
            a[i] = atoi(buf.c_str()), mark[i] = 0;
//        a[i] += a[i - 1];
    }

    for (int st = 1; st <= k; ++st) {
        for (int i = st; i + k <= n; i += k)
            if (!mark[i] && !mark[i + k] && a[i] >= a[i + k]) {
                puts("Incorrect sequence");
                return 0;
            }
        int x, y = st;
        while (1) {
            for (x = y; x <= n && !mark[x]; x += k);
            if (x > n) break;
            int cnt = 0;
            for (y = x; y <= n && mark[y]; y += k)
                ++cnt;

            int v1, v2;
            if (x - k < 1)
                v1 = -oo;
            else
                v1 = a[x - k];
            if (y > n)
                v2 = oo;
            else
                v2 = a[y];
//            cout << x <<" "<<y <<" "<<cnt <<" "<<v2 - v1 - 1<< endl;
            if (cnt > v2 - v1 - 1) {
                puts("Incorrect sequence");
                return 0;
            }

            if (v1 < 0 && v2 > 0) {
                cnt = - (cnt / 2);
            }
            else if (v1 > 0 && v2 > 0) {
                cnt = v1 + 1;
            }
            else {
                cnt = v2 - cnt;
            }
            for (int i = x; i < y; i += k)
                a[i] = cnt++;
        }
    }
    for (int i = 1; i <= n; ++i)
        printf("%d ", a[i]);
}


/* In the name of Allah */
#include <bits/stdc++.h>

using namespace std;

#define sz(x) (((int) x.size()))
typedef long long ll;

const int maxN = 1000*100 + 10;
int mark[maxN];
int a[maxN];
int n,k;

void doJob( int i , int j , int mn , int mx ) {
//	cout << i << ' ' << j << ' ' << mn << ' ' << mx << endl;
	int cnt = ( j - i  ) ;
	if( mx - mn - 1 <  cnt ) {
		cout << "Incorrect sequence" << endl;
		exit(0);
	}
	if( mn >=  - ( cnt / 2 ) - 1 ) {
		int val = mn + 1;
		for( int x = i ; x != j ; x += k )
			a[x] = val++;
	} else if( mx <=  (cnt / 2) + 1 ) {
		int val = mx - cnt;
		for( int x = i ; x != j ; x += k )
			a[x] = val++;
	} else {
		int val = - (cnt/2);
		for( int x = i ; x != j ; x += k )
			a[x] = val++;
	}
}

int main() {
	cin >> n >> k;

	for( int i =0 ; i < n ;i ++ )  {
		string s;
		cin >> s;
		if( s == "?" )
			mark[i] = 1;
		else
			a[i] = stoi( s ) ;
	}

	for( int i = 0 ; i < k ; i++ ) {
		int mn = -1e9 - 100;
		int last = 0;
		for( int j = i ; j < n ; j += k )
			if( !mark[j] ) {
				if( last != mark[j] )
					doJob( last , j , mn , a[j] ) ;
				last = j + k;
				mn = a[j];
			}
		int x = i + ( n - i ) / k * k ;
//		cerr << last << ' ' << i << ' ' << x << endl;
		if( x != last )
			doJob( last , x + k , mn , int( 1e9 + 100 ) ) ;
	}

	for( int i = 0 ; i < n ; i++ )
		cout << a[i] << ' ';
	cout << endl;
}


/* In the name of Allah */
#include <bits/stdc++.h>

using namespace std;

#define sz(x) (((int) x.size()))
typedef long long ll;

const int maxN = 3000*100 + 10;
int mark[maxN];
int a[maxN];
int n,k;

void doJob( int i , int j , int mn , int mx ) {
//	cout << i << ' ' << j << ' ' << mn << ' ' << mx << endl;
	int cnt = ( j - i  ) / k ;
	if( mx - mn - 1 <  cnt ) {
		cout << "Incorrect sequence" << endl;
		exit(0);
	}
	if( mn >=  - ( cnt / 2 ) - 1 ) {
		int val = mn + 1;
		for( int x = i ; x != j ; x += k )
			a[x] = val++;
	} else if( mx <=  (cnt / 2) + 1 ) {
		int val = mx - cnt;
		for( int x = i ; x != j ; x += k )
			a[x] = val++;
	} else {
		int val = - (cnt/2);
//		cout << "BAGHALI " << cnt << endl;
		for( int x = i ; x != j ; x += k )
			a[x] = val++;
	}
}

int main() {
	cin >> n >> k;

	for( int i =0 ; i < n ;i ++ )  {
		string s;
		cin >> s;
		if( s == "?" )
			mark[i] = 1;
		else
			a[i] = atoi( s.c_str() ) ;
		//cout <<i << ' '<<  mark[i] << endl;
	}

	for( int i = 0 ; i < k ; i++ ) {
		int mn = -1e9 - maxN;
		int last = i;
		for( int j = i ; j < n ; j += k )
			if( !mark[j] ) {
				if( last != j )
					doJob( last , j , mn , a[j] ) ;
				last = j + k;
				mn = a[j];
			}
		int x = i + ( n - 1 - i ) / k * k ;
//		cerr << last << ' ' << i << ' ' << x << endl;
		if( x != last )
			doJob( last , x + k , mn , int( 1e9 + maxN ) ) ;
	}

	for( int i = 0 ; i < n - k ; i++ )
		if( a[i] >= a[i+k] ) {
			cout << "Incorrect sequence" << endl;
			return 0;
		}

	for( int i = 0 ; i < n ; i++ )
		cout << a[i] << ' ';
	cout << endl;
}


/* In the name of Allah */
#include <bits/stdc++.h>

using namespace std;

#define sz(x) (((int) x.size()))
typedef long long ll;

const int maxN = 3000*100 + 10;
int mark[maxN];
int a[maxN];
int n,k;

void doJob( int i , int j , int mn , int mx ) {
//	cout << i << ' ' << j << ' ' << mn << ' ' << mx << endl;
	int cnt = ( j - i  ) / k ;
	if( mx - mn - 1 <  cnt ) {
		cout << "Incorrect sequence" << endl;
		exit(0);
	}
	if( mn >=  - ( cnt / 2 ) - 1 ) {
		int val = mn + 1;
		for( int x = i ; x != j ; x += k )
			a[x] = val++;
	} else if( mx <=  (cnt / 2) + 1 ) {
		int val = mx - cnt;
		for( int x = i ; x != j ; x += k )
			a[x] = val++;
	} else {
		int val = - (cnt/2);
//		cout << "BAGHALI " << cnt << endl;
		for( int x = i ; x != j ; x += k )
			a[x] = val++;
	}
}

int main() {
	cin >> n >> k;

	for( int i =0 ; i < n ;i ++ )  {
		string s;
		cin >> s;
		if( s == "?" )
			mark[i] = 1;
		else
			a[i] = atoi( s.c_str() ) ;
	}

	for( int i = 0 ; i < k ; i++ ) {
		int mn = -1e9 - 100;
		int last = i;
		for( int j = i ; j < n ; j += k )
			if( !mark[j] ) {
				if( last != mark[j] )
					doJob( last , j , mn , a[j] ) ;
				last = j + k;
				mn = a[j];
			}
		int x = i + ( n - 1 - i ) / k * k ;
//		cerr << last << ' ' << i << ' ' << x << endl;
		if( x != last )
			doJob( last , x + k , mn , int( 1e9 + 100 ) ) ;
	}

	for( int i = 0 ; i < n ; i++ )
		cout << a[i] << ' ';
	cout << endl;
}


/* In the name of Allah */
#include <bits/stdc++.h>

using namespace std;

#define sz(x) (((int) x.size()))
typedef long long ll;

const int maxN = 3000*100 + 10;
int mark[maxN];
int a[maxN];
int n,k;

void doJob( int i , int j , int mn , int mx ) {
	//cout << i << ' ' << j << ' ' << mn << ' ' << mx << endl;
	int cnt = ( j - i  ) / k ;
	if( mx - mn - 1 <  cnt ) {
		cout << "Incorrect sequence" << endl;
		exit(0);
	}
	if( mn >=  - ( cnt / 2 ) - 1 ) {
		int val = mn + 1;
		for( int x = i ; x != j ; x += k )
			a[x] = val++;
	} else if( mx <=  (cnt / 2) + 1 ) {
		int val = mx - cnt;
		for( int x = i ; x != j ; x += k )
			a[x] = val++;
	} else {
		int val = - (cnt/2);
	//	cout << "BAGHALI " << val << endl;
		for( int x = i ; x != j ; x += k )
			a[x] = val++;
	}
}

int main() {
	cin >> n >> k;

	for( int i =0 ; i < n ;i ++ )  {
		string s;
		cin >> s;
		if( s == "?" )
			mark[i] = 1;
		else
			a[i] = atoi( s.c_str() ) ;
	}

	for( int i = 0 ; i < k ; i++ ) {
		int mn = -1e9 - 100;
		int last = i;
		for( int j = i ; j < n ; j += k )
			if( !mark[j] ) {
				if( last != mark[j] )
					doJob( last , j , mn , a[j] ) ;
				last = j + k;
				mn = a[j];
			}
		int x = i + ( n - i ) / k * k ;
		//cerr << last << ' ' << i << ' ' << x << endl;
		if( x != last )
			doJob( last , x + k , mn , int( 1e9 + 100 ) ) ;
	}

	for( int i = 0 ; i < n ; i++ )
		cout << a[i] << ' ';
	cout << endl;
}


/* In the name of Allah */
#include <bits/stdc++.h>

using namespace std;

#define sz(x) (((int) x.size()))
typedef long long ll;

const int maxN = 3000*100 + 10;
int mark[maxN];
int a[maxN];
int n,k;

void doJob( int i , int j , int mn , int mx ) {
//	cout << i << ' ' << j << ' ' << mn << ' ' << mx << endl;
	int cnt = ( j - i  ) / k ;
	if( mx - mn - 1 <  cnt ) {
		cout << "Incorrect sequence" << endl;
		exit(0);
	}
	if( mn >=  - ( cnt / 2 ) - 1 ) {
		int val = mn + 1;
		for( int x = i ; x != j ; x += k )
			a[x] = val++;
	} else if( mx <=  (cnt / 2) + 1 ) {
		int val = mx - cnt;
		for( int x = i ; x != j ; x += k )
			a[x] = val++;
	} else {
		int val = - (cnt/2);
//		cout << "BAGHALI " << cnt << endl;
		for( int x = i ; x != j ; x += k )
			a[x] = val++;
	}
}

int main() {
	cin >> n >> k;

	for( int i =0 ; i < n ;i ++ )  {
		string s;
		cin >> s;
		if( s == "?" )
			mark[i] = 1;
		else
			a[i] = atoi( s.c_str() ) ;
		//cout <<i << ' '<<  mark[i] << endl;
	}

	for( int i = 0 ; i < k ; i++ ) {
		int mn = -1e9 - 100;
		int last = i;
		for( int j = i ; j < n ; j += k )
			if( !mark[j] ) {
				if( last != j )
					doJob( last , j , mn , a[j] ) ;
				last = j + k;
				mn = a[j];
			}
		int x = i + ( n - 1 - i ) / k * k ;
//		cerr << last << ' ' << i << ' ' << x << endl;
		if( x != last )
			doJob( last , x + k , mn , int( 1e9 + 100 ) ) ;
	}

	for( int i = 0 ; i < n ; i++ )
		cout << a[i] << ' ';
	cout << endl;
}


/* In the name of Allah */
#include <bits/stdc++.h>

using namespace std;

#define sz(x) (((int) x.size()))
typedef long long ll;

const int maxN = 3000*100 + 10;
int mark[maxN];
int a[maxN];
int n,k;

void doJob( int i , int j , int mn , int mx ) {
//	cout << i << ' ' << j << ' ' << mn << ' ' << mx << endl;
	int cnt = ( j - i  ) / k ;
	if( mx - mn - 1 <  cnt ) {
		cout << "Incorrect sequence" << endl;
		exit(0);
	}
	if( mn >=  - ( cnt / 2 ) - 1 ) {
		int val = mn + 1;
		for( int x = i ; x != j ; x += k )
			a[x] = val++;
	} else if( mx <=  (cnt / 2) + 1 ) {
		int val = mx - cnt;
		for( int x = i ; x != j ; x += k )
			a[x] = val++;
	} else {
		int val = - (cnt/2);
//		cout << "BAGHALI " << cnt << endl;
		for( int x = i ; x != j ; x += k )
			a[x] = val++;
	}
}

int main() {
	cin >> n >> k;

	for( int i =0 ; i < n ;i ++ )  {
		string s;
		cin >> s;
		if( s == "?" )
			mark[i] = 1;
		else
			a[i] = atoi( s.c_str() ) ;
		//cout <<i << ' '<<  mark[i] << endl;
	}

	for( int i = 0 ; i < k ; i++ ) {
		int mn = -1e9 - maxN;
		int last = i;
		int x = i;
		for( int j = i ; j < n ; j += k )  {
			if( !mark[j] ) {
				if( last != j )
					doJob( last , j , mn , a[j] ) ;
				last = j + k;
				mn = a[j];
			}
			x = j;
		}
//		cerr << last << ' ' << i << ' ' << x << endl;
		if( x + k != last )
			doJob( last , x + k , mn , int( 1e9 + maxN ) ) ;
	}

	for( int i = 0 ; i < n - k ; i++ )
		if( a[i] >= a[i+k] ) {
			cout << "Incorrect sequence" << endl;
			return 0;
		}

	for( int i = 0 ; i < n ; i++ )
		cout << a[i] << ' ';
	cout << endl;
}


/* In the name of Allah */
#include <bits/stdc++.h>

using namespace std;

#define sz(x) (((int) x.size()))
typedef long long ll;

const int maxN = 3000*100 + 10;
int mark[maxN];
int a[maxN];
int n,k;

void doJob( int i , int j , int mn , int mx ) {
//	cout << i << ' ' << j << ' ' << mn << ' ' << mx << endl;
	int cnt = ( j - i  ) ;
	if( mx - mn - 1 <  cnt ) {
		cout << "Incorrect sequence" << endl;
		exit(0);
	}
	if( mn >=  - ( cnt / 2 ) - 1 ) {
		int val = mn + 1;
		for( int x = i ; x != j ; x += k )
			a[x] = val++;
	} else if( mx <=  (cnt / 2) + 1 ) {
		int val = mx - cnt;
		for( int x = i ; x != j ; x += k )
			a[x] = val++;
	} else {
		int val = - (cnt/2);
		for( int x = i ; x != j ; x += k )
			a[x] = val++;
	}
}

int main() {
	cin >> n >> k;

	for( int i =0 ; i < n ;i ++ )  {
		string s;
		cin >> s;
		if( s == "?" )
			mark[i] = 1;
		else
			a[i] = atoi( s.c_str() ) ;
	}

	for( int i = 0 ; i < k ; i++ ) {
		int mn = -1e9 - 100;
		int last = i;
		for( int j = i ; j < n ; j += k )
			if( !mark[j] ) {
				if( last != mark[j] )
					doJob( last , j , mn , a[j] ) ;
				last = j + k;
				mn = a[j];
			}
		int x = i + ( n - i ) / k * k ;
		//cerr << last << ' ' << i << ' ' << x << endl;
		if( x != last )
			doJob( last , x + k , mn , int( 1e9 + 100 ) ) ;
	}

	for( int i = 0 ; i < n ; i++ )
		cout << a[i] << ' ';
	cout << endl;
}


/* In the name of Allah */
#include <bits/stdc++.h>

using namespace std;

#define sz(x) (((int) x.size()))
typedef long long ll;

const int maxN = 3000*100 + 10;
int mark[maxN];
int a[maxN];
int n,k;

void doJob( int i , int j , int mn , int mx ) {
//	cout << i << ' ' << j << ' ' << mn << ' ' << mx << endl;
	int cnt = ( j - i  ) / k ;
	if( mx - mn - 1 <  cnt ) {
		cout << "Incorrect sequence" << endl;
		exit(0);
	}
	if( mn >=  - ( cnt / 2 ) - 1 ) {
		int val = mn + 1;
		for( int x = i ; x != j ; x += k )
			a[x] = val++;
	} else if( mx <=  (cnt / 2) + 1 ) {
		int val = mx - cnt;
		for( int x = i ; x != j ; x += k )
			a[x] = val++;
	} else {
		int val = - (cnt/2);
//		cout << "BAGHALI " << cnt << endl;
		for( int x = i ; x != j ; x += k )
			a[x] = val++;
	}
}

int main() {
	cin >> n >> k;

	for( int i =0 ; i < n ;i ++ )  {
		string s;
		cin >> s;
		if( s == "?" )
			mark[i] = 1;
		else
			a[i] = atoi( s.c_str() ) ;
		//cout <<i << ' '<<  mark[i] << endl;
	}

	for( int i = 0 ; i < k ; i++ ) {
		int mn = -1e9 - 100;
		int last = i;
		for( int j = i ; j < n ; j += k )
			if( !mark[j] ) {
				if( last != j )
					doJob( last , j , mn , a[j] ) ;
				last = j + k;
				mn = a[j];
			}
		int x = i + ( n - 1 - i ) / k * k ;
//		cerr << last << ' ' << i << ' ' << x << endl;
		if( x != last )
			doJob( last , x + k , mn , int( 1e9 + 100 ) ) ;
	}

	for( int i = 0 ; i < n - k ; i++ )
		if( a[i] >= a[i+k] ) {
			cout << "Incorrect sequence" << endl;
			return 0;
		}

	for( int i = 0 ; i < n ; i++ )
		cout << a[i] << ' ';
	cout << endl;
}


/* In the name of Allah */
#include <bits/stdc++.h>

using namespace std;

#define sz(x) (((int) x.size()))
typedef long long ll;

const int maxN = 3000*100 + 10;
int mark[maxN];
int a[maxN];
int n,k;

void doJob( int i , int j , int mn , int mx ) {
//	cout << i << ' ' << j << ' ' << mn << ' ' << mx << endl;
	int cnt = ( j - i  ) ;
	if( mx - mn - 1 <  cnt ) {
		cout << "Incorrect sequence" << endl;
		exit(0);
	}
	if( mn >=  - ( cnt / 2 ) - 1 ) {
		int val = mn + 1;
		for( int x = i ; x != j ; x += k )
			a[x] = val++;
	} else if( mx <=  (cnt / 2) + 1 ) {
		int val = mx - cnt;
		for( int x = i ; x != j ; x += k )
			a[x] = val++;
	} else {
		int val = - (cnt/2);
		for( int x = i ; x != j ; x += k )
			a[x] = val++;
	}
}

int main() {
	cin >> n >> k;

	for( int i =0 ; i < n ;i ++ )  {
		string s;
		cin >> s;
		if( s == "?" )
			mark[i] = 1;
		else
			a[i] = atoi( s.c_str() ) ;
	}

	for( int i = 0 ; i < k ; i++ ) {
		int mn = -1e9 - 100;
		int last = 0;
		for( int j = i ; j < n ; j += k )
			if( !mark[j] ) {
				if( last != mark[j] )
					doJob( last , j , mn , a[j] ) ;
				last = j + k;
				mn = a[j];
			}
		int x = i + ( n - i ) / k * k ;
//		cerr << last << ' ' << i << ' ' << x << endl;
		if( x != last )
			doJob( last , x + k , mn , int( 1e9 + 100 ) ) ;
	}

	for( int i = 0 ; i < n ; i++ )
		cout << a[i] << ' ';
	cout << endl;
}


/* In the name of Allah */
#include <bits/stdc++.h>

using namespace std;

#define sz(x) (((int) x.size()))
typedef long long ll;

const int maxN = 1000*100 + 10;
int mark[maxN];
int a[maxN];
int n,k;

void doJob( int i , int j , int mn , int mx ) {
//	cout << i << ' ' << j << ' ' << mn << ' ' << mx << endl;
	int cnt = ( j - i  ) ;
	if( mx - mn - 1 <  cnt ) {
		cout << "Incorrect sequence" << endl;
		exit(0);
	}
	if( mn >=  - ( cnt / 2 ) - 1 ) {
		int val = mn + 1;
		for( int x = i ; x != j ; x += k )
			a[x] = val++;
	} else if( mx <=  (cnt / 2) + 1 ) {
		int val = mx - cnt;
		for( int x = i ; x != j ; x += k )
			a[x] = val++;
	} else {
		int val = - (cnt/2);
		for( int x = i ; x != j ; x += k )
			a[x] = val++;
	}
}

int main() {
	cin >> n >> k;

	for( int i =0 ; i < n ;i ++ )  {
		string s;
		cin >> s;
		if( s == "?" )
			mark[i] = 1;
		else
			a[i] = atoi( s.c_str() ) ;
	}

	for( int i = 0 ; i < k ; i++ ) {
		int mn = -1e9 - 100;
		int last = 0;
		for( int j = i ; j < n ; j += k )
			if( !mark[j] ) {
				if( last != mark[j] )
					doJob( last , j , mn , a[j] ) ;
				last = j + k;
				mn = a[j];
			}
		int x = i + ( n - i ) / k * k ;
//		cerr << last << ' ' << i << ' ' << x << endl;
		if( x != last )
			doJob( last , x + k , mn , int( 1e9 + 100 ) ) ;
	}

	for( int i = 0 ; i < n ; i++ )
		cout << a[i] << ' ';
	cout << endl;
}


#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcount(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

int n, k;
int arr[100005];
string tmp;

int toInt() {
	int siz = SZ(tmp), idx = 0;
	bool neg = 0;
	int res = 0;
	if (tmp[idx] == '-')
		idx++, neg = 1;
	while (idx < siz)
		res *= 10, res += tmp[idx++] - '0';
	if (neg)
		res *= -1;
	return res;
}

ll abssum(ll st, ll cnt) {
	if (st > 0)
		return cnt * (2 * st + cnt - 1) / 2;
	else if (st + cnt - 1 < 0)
		return abs(cnt * (2 * st + cnt - 1) / 2);
	ll a = abs(st);
	ll b = cnt - a - 1;
	return a * (a + 1) / 2 + b * (b + 1) / 2;
}

int get(ll st, ll en, ll cnt) {
	if (en - st + 1 < cnt)
		return OO;
	en -= cnt - 1; // A7A 3la deh BUG -_-
	while (st < en) {
		ll mid = st + (en - st) / 2;
		if (abssum(mid, cnt) > abssum(mid + 1, cnt))
			st = mid + 1;
		else
			en = mid;
	}
	return st;
}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		if (tmp == "?")
			arr[i] = OO;
		else
			arr[i] = toInt();
	}
	for (int i = 0; i < k; i++) {
		int idx = i;
		int st = -OO, en = OO;
		while (idx < n) {
			int r = 0, j = idx + k;
			if (arr[idx] != OO)
				st = arr[idx] + 1;
			else
				r++;
			while (j < n) {
				if (arr[j] != OO) {
					en = arr[j] - 1;
					break;
				}
				r++;
				j += k;
			}
			int c = get(st, en, r);
			if (c == OO) {
				puts("Incorrect sequence");
				return 0;
			}
			while (idx < j) {
				if (arr[idx] == OO)
					arr[idx] = c++;
				idx += k;
			}
			en = OO;
		}
	}
	for (int i = 0; i < n; i++)
		cout << arr[i] << " \n"[i == n - 1];
	return 0;
}


#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcount(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

int n, k, cnt, st;
int arr[100005];
string tmp;

int toInt() {
    int siz = SZ(tmp), idx = 0;
    bool neg = 0;
    int res = 0;
    if (tmp[idx] == '-')
        idx++, neg = 1;
    while (idx < siz)
        res *= 10, res += tmp[idx++] - '0';
    if (neg)
        res *= -1;
    return res;
}

int main() {
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
//  freopen("in.txt", "rt", stdin);
//  freopen("out.txt", "wt", stdout);
#endif
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> tmp;
        if (tmp == "?")
            arr[i] = OO, cnt++;
        else
            arr[i] = toInt();
    }
    for (int i = 0; i < n; i++) {
        if (arr[i] != OO) {
            int idx = i - k, r = 0;
            while (idx >= 0) {
                if (arr[idx] != OO) {
                    if (arr[idx] >= arr[idx + k]) {
                        puts("Incorrect sequence");
                        return 0;
                    }
                    break;
                }
                r++;
                arr[idx] = arr[idx + k] - 1, idx -= k, cnt--;
            }
            r = -(r / 2);
            idx += k;
            while (idx < i)
                arr[idx] = r++, idx += k;
            idx = i + k;
            while (idx < n) {
                if (arr[idx] != OO) {
                    if (arr[idx] <= arr[idx - k]) {
                        puts("Incorrect sequence");
                        return 0;
                    }
                    break;
                }
                arr[idx] = arr[idx - k] + 1, idx += k, cnt--;
            }
        }
    }
    st = -(cnt / 2);
    for (int i = 0; i < n; i++) {
        if (arr[i] == OO)
            arr[i] = st++;
    }
    for (int i = 0; i < n; i++)
        cout << arr[i] << " \n"[i == n - 1];
    return 0;
}


#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcount(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

int n, k, cnt, st;
int arr[100005];
string tmp;

int toInt() {
    int siz = SZ(tmp), idx = 0;
    bool neg = 0;
    int res = 0;
    if (tmp[idx] == '-')
        idx++, neg = 1;
    while (idx < siz)
        res *= 10, res += tmp[idx++] - '0';
    if (neg)
        res *= -1;
    return res;
}

int main() {
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
//  freopen("in.txt", "rt", stdin);
//  freopen("out.txt", "wt", stdout);
#endif
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> tmp;
        if (tmp == "?")
            arr[i] = OO, cnt++;
        else
            arr[i] = toInt();
    }
    for (int i = 0; i < n; i++) {
        if (arr[i] != OO) {
            int idx = i - k, r = 0;
            while (idx >= 0) {
                if (arr[idx] != OO) {
                    if (arr[idx] >= arr[idx + k]) {
                        puts("Incorrect sequence");
                        return 0;
                    }
                    break;
                }
                r++;
                arr[idx] = arr[idx + k] - 1, idx -= k;
            }
            r = -(r / 2);
            idx += k;
            while (idx < i)
                arr[idx] = r++, idx += k;
            idx = i + k;
            while (idx < n) {
                if (arr[idx] != OO) {
                    if (arr[idx] <= arr[idx - k]) {
                        puts("Incorrect sequence");
                        return 0;
                    }
                    break;
                }
                arr[idx] = arr[idx - k] + 1, idx += k;
            }
        }
    }

    for (int i = 0; i < n; i++) {
        if (arr[i] == OO) {
            cnt = 0;
            for (int j = i; j < n && arr[j] == OO; j += k)
                cnt++;
            st = -(cnt / 2);
            for (int j = i; j < n && arr[j] == OO; j += k)
                arr[j] = st++;
        }
    }
    for (int i = 0; i < n; i++)
        cout << arr[i] << " \n"[i == n - 1];
    return 0;
}


#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcount(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

int n, k, cnt, st;
int arr[100005];
string tmp;

int toInt() {
	int siz = SZ(tmp), idx = 0;
	bool neg = 0;
	int res = 0;
	if (tmp[idx] == '-')
		idx++, neg = 1;
	while (idx < siz)
		res *= 10, res += tmp[idx++] - '0';
	if (neg)
		res *= -1;
	return res;
}

ll abssum(ll st, ll cnt) {
	if (st > 0)
		return cnt * (2 * st + cnt - 1) / 2;
	else if (st + cnt - 1 < 0)
		return abs(cnt * (2 * st + cnt - 1) / 2);
	int a = abs(st);
	int b = cnt - a - 1;
	return a * (a + 1) / 2 + b * (b + 1) / 2;
}

int get(ll st, ll en, ll cnt) {
	if (en - st + 1 < cnt)
		return OO;
	while (st < en) {
		ll mid = st + (en - st) / 2;
		if (abssum(mid, cnt) > abssum(mid + 1, cnt))
			st = mid + 1;
		else
			en = mid;
	}
	return st;
}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		if (tmp == "?")
			arr[i] = OO, cnt++;
		else
			arr[i] = toInt();
	}
	for (int i = 0; i < k; i++) {
		int idx = i;
		int st = -OO, en = OO;
		while (idx < n) {
			int r = 0, j = idx + k;
			if (arr[idx] != OO)
				st = arr[i] + 1;
			else
				r++;
			while (j < n) {
				if (arr[j] != OO) {
					en = arr[j] - 1;
					break;
				}
				r++;
				j += k;
			}

			int c = get(st, en, r);
			if (c == OO) {
				puts("Incorrect sequence");
				return 0;
			}
			while (idx <= j) {
				if (arr[idx] == OO)
					arr[idx] = c++;
				idx += k;
			}
			st = en;
		}
	}
	for (int i = 0; i < n; i++)
		cout << arr[i] << " \n"[i == n - 1];
	return 0;
}


#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcount(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

int n, k, cnt, st;
int arr[100005];
string tmp;

int toInt() {
	int siz = SZ(tmp), idx = 0;
	bool neg = 0;
	int res = 0;
	if (tmp[idx] == '-')
		idx++, neg = 1;
	while (idx < siz)
		res *= 10, res += tmp[idx++] - '0';
	if (neg)
		res *= -1;
	return res;
}

ll abssum(ll st, ll cnt) {
	if (st > 0)
		return cnt * (2 * st + cnt - 1) / 2;
	else if (st + cnt - 1 < 0)
		return abs(cnt * (2 * st + cnt - 1) / 2);
	ll a = abs(st);
	ll b = cnt - a - 1;
	return a * (a + 1) / 2 + b * (b + 1) / 2;
}

int get(ll st, ll en, ll cnt) {
	if (en - st + 1 < cnt)
		return OO;
	while (st < en) {
		ll mid = st + (en - st) / 2;
		if (abssum(mid, cnt) > abssum(mid + 1, cnt))
			st = mid + 1;
		else
			en = mid;
	}
	return st;
}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		if (tmp == "?")
			arr[i] = OO, cnt++;
		else
			arr[i] = toInt();
	}
	for (int i = 0; i < k; i++) {
		int idx = i;
		int st = -OO, en = OO;
		while (idx < n) {
			int r = 0, j = idx + k;
			if (arr[idx] != OO)
				st = arr[i] + 1;
			else
				r++;
			while (j < n) {
				if (arr[j] != OO) {
					en = arr[j] - 1;
					break;
				}
				r++;
				j += k;
			}

			int c = get(st, en, r);
			if (c == OO) {
				puts("Incorrect sequence");
				return 0;
			}
			while (idx <= j) {
				if (arr[idx] == OO)
					arr[idx] = c++;
				idx += k;
			}
			st = en;
		}
	}
	for (int i = 0; i < n; i++)
		cout << arr[i] << " \n"[i == n - 1];
	return 0;
}


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

typedef long long ll;

vector<int> a, b;

inline void init(){
	a.clear();
	b.clear();
}

bool cmp(ll x, ll y){
	return x > y;
}

int main(){
	ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

	init();
	int n, d, m;
	cin >> n >> d >> m;

	for(int i = 0; i < n; ++ i){
		ll x;
		cin >> x;
		if(x <= m){
			a.push_back(x);
		}
		else b.push_back(x);
	}

	sort(a.begin(), a.end(), cmp);
	sort(b.begin(), b.end(), cmp);

	ll ans = 0;

	if(!b.size()){
		int siz = (int)a.size();
		for(int i = 0; i < siz; ++ i){
			ans += a[i];
		}
		cout << ans;
		return 0;
	}

	for(int i = 1; i <= b.size(); ++ i) { // 取几个b
		int days = (i - 1) * (d + 1) + 1;
		if(n < days) break;

		ll tmp = 0ll;
		for(int j = 0; j < i; ++ j){
			tmp += b[j];
		}

		int siz = min(n - days, (int)a.size());

		for(int j = 0; j < siz; ++ j){
			tmp += a[j];
		}
		ans = max(ans ,tmp);
	}

	cout << ans;

	return 0;
}


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

typedef long long ll;

const int maxn = 1e5 + 10;

vector<ll> a, b;

ll prea[maxn], preb[maxn];

inline void init(){
	a.clear();
	b.clear();
}

bool cmp(ll x, ll y){
	return x > y;
}

int main(){
	ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

	init();
	int n, d, m;
	cin >> n >> d >> m;

	for(int i = 0; i < n; ++ i){
		ll x;
		cin >> x;
		if(x <= m){
			a.push_back(x);
		}
		else b.push_back(x);
	}

	sort(a.begin(), a.end(), cmp);
	sort(b.begin(), b.end(), cmp);

	int asz = a.size() , bsz = b.size();

	for(int i = 0; i < asz; ++ i){
		prea[i+1] = prea[i] + a[i];
	}
	for(int i = 0; i < bsz; ++ i){
		preb[i+1] = preb[i] + b[i];
	}

	ll ans = 0;

	if(!bsz){
		cout << prea[asz];
		return 0;
	}

	for(int i = 1; i <= bsz; ++ i) { // 取几个b
		int days = (i - 1) * (d + 1) + 1;
		if(n < days) break;

		ll tmp = 0ll;
		tmp += preb[i];
		int siz = min(n - days, asz);
		tmp += prea[siz];
		ans = max(ans ,tmp);
	}

	cout << ans;

	return 0;
}


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

typedef long long ll;

priority_queue<ll, vector <ll>, greater<ll> > a;
priority_queue<ll, vector <ll>, less<ll> > b;

inline void init(){
	while(!a.empty()) a.pop();
	while(!b.empty()) b.pop();
}

bool cmp1(ll x, ll y){
	return x < y;
}

bool cmp2(ll x, ll y){
	return x > y;
}

int main(){
	init();
	int n, d, m;
	cin >> n >> d >> m;

	for(int i = 0; i < n; ++ i){
		ll x;
		cin >> x;
		if(x <= m){
			a.push(x);
		}
		else b.push(x);
	}

	ll ans = 0;

	if(!b.empty()){
		ans += b.top();
		b.pop();
	}

	int cntb = 0;

	while(!b.empty()){
		ll tmp = b.top(); b.pop();
		if(a.size() >= d){
			ll x = 0ll;
			for(int k = 0; k < d; ++ k){
				x += a.top(); a.pop();
			}
			if(x < tmp){
				ans += tmp;
			}
			else {
				ans += x;
				if(b.size()- cntb * d >= d){
					cntb ++;
					ans += tmp;
				}
			}
		}
		else {
			if(b.size() - cntb * d >= d){
				cntb ++;
				ans += tmp;
			}
		}
	}

	while(!a.empty()){
		ll tmp = a.top(); a.pop();
		ans += tmp;
	}

	cout << ans;

	return 0;
}


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

typedef long long ll;

vector<int> a, b;

inline void init(){
	a.clear();
	b.clear();
}

bool cmp(ll x, ll y){
	return x > y;
}

int main(){
	init();
	int n, d, m;
	cin >> n >> d >> m;

	for(int i = 0; i < n; ++ i){
		ll x;
		cin >> x;
		if(x <= m){
			a.push_back(x);
		}
		else b.push_back(x);
	}

	sort(a.begin(), a.end(), cmp);
	sort(b.begin(), b.end(), cmp);

	ll ans = 0;

	if(!b.size()){
		int siz = (int)a.size();
		for(int i = 0; i < siz; ++ i){
			ans += a[i];
		}
		cout << ans;
		return 0;
	}

	for(int i = 1; i <= b.size(); ++ i) { // 取几个b
		int days = (i - 1) * (d + 1) + 1;
		if(n < days) break;

		ll tmp = 0ll;
		for(int j = 0; j < i; ++ j){
			tmp += b[j];
		}

		int siz = min(n - days, (int)a.size());

		for(int j = 0; j < siz; ++ j){
			tmp += a[j];
		}
		ans = max(ans ,tmp);
	}

	cout << ans;

	return 0;
}


#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
using namespace std;

typedef long long ll;
const int N = 1e5 + 10;
ll n, d, m, a[N], pre[N], ans;
vector<ll> b, c;

int main() {
    cin >> n >> d >> m;
    rep(i, 1, n) {
        scanf("%lld", &a[i]);
        if (a[i] <= m) c.push_back(a[i]);
        else b.push_back(a[i]);
    }
    sort(b.begin(), b.end(), greater<ll>());
    sort(c.begin(), c.end(), greater<ll>());
    for (int i = 0; i < c.size(); i++) pre[i + 1] = pre[i] + c[i];
    ll sum = 0;
    ans = pre[(int)c.size()];
    for (int i = 1; i <= b.size(); i++) {
        if (n < (i - 1) * (d + 1) + 1) break;
        sum += b[i - 1];
        ans = max(ans, sum + pre[n - ((i - 1) * (d + 1) + 1)]);
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
using namespace std;

typedef long long ll;
const int N = 1e5 + 10;
ll n, d, m, a[N], pre[N], ans;
vector<ll> b, c;

int main() {
    cin >> n >> d >> m;
    rep(i, 1, n) {
        scanf("%lld", &a[i]);
        if (a[i] <= m) c.push_back(a[i]);
        else b.push_back(a[i]);
    }
    sort(b.begin(), b.end(), greater<ll>());
    sort(c.begin(), c.end(), greater<ll>());
    for (int i = 0; i < c.size(); i++) pre[i + 1] = pre[i] + c[i];
    ll sum = 0;
    ans = pre[(int)c.size()];
    for (int i = 1; i <= b.size(); i++) {
        if (n < (i - 1) * (d + 1) + 1 || n > i * d + (int)c.size()) break;
        sum += b[i - 1];
        ans = max(ans, sum + pre[min(n - ((i - 1) * (d + 1) + 1), (int)c.size())]);
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
using namespace std;

typedef long long ll;
const int N = 1e5 + 10;
ll n, d, m, a[N], pre[N], ans;
vector<ll> b, c;

int main() {
    cin >> n >> d >> m;
    rep(i, 1, n) {
        scanf("%lld", &a[i]);
        if (a[i] <= m) c.push_back(a[i]);
        else b.push_back(a[i]);
    }
    sort(b.begin(), b.end(), greater<ll>());
    sort(c.begin(), c.end(), greater<ll>());
    for (int i = 0; i < c.size(); i++) pre[i + 1] = pre[i] + c[i];
    ll sum = 0;
    ans = pre[(int)c.size()];
    for (int i = 1; i <= b.size(); i++) {
        if (n < (i - 1) * (d + 1) + 1) break;
        sum += b[i - 1];
        ans = max(ans, sum + pre[min(n - ((i - 1) * (d + 1) + 1), (ll)c.size())]);
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
using namespace std;

typedef long long ll;
const int N = 1e5 + 10;
ll n, d, m, a[N], pre[N], ans;
vector<ll> b, c;

int main() {
    cin >> n >> d >> m;
    rep(i, 1, n) {
        scanf("%lld", &a[i]);
        if (a[i] <= m) c.push_back(a[i]);
        else b.push_back(a[i]);
    }
    sort(b.begin(), b.end(), greater<ll>());
    sort(c.begin(), c.end(), greater<ll>());
    for (int i = 0; i < c.size(); i++) pre[i + 1] = pre[i] + c[i];
    ll sum = 0;
    for (int i = 1; i <= b.size(); i++) {
        if (n < (i - 1) * (d + 1) + 1) break;
        sum += b[i - 1];
        ans = max(ans, sum + pre[n - ((i - 1) * (d + 1) + 1)]);
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
using namespace std;

typedef long long ll;
const int N = 1e5 + 10;
ll n, d, m, a[N], pre[N], ans;
vector<ll> b, c;

int main() {
    cin >> n >> d >> m;
    rep(i, 1, n) {
        scanf("%lld", &a[i]);
        if (a[i] <= m) c.push_back(a[i]);
        else b.push_back(a[i]);
    }
    sort(b.begin(), b.end(), greater<ll>());
    sort(c.begin(), c.end(), greater<ll>());
    for (int i = 0; i < c.size(); i++) pre[i + 1] = pre[i] + c[i];
    ll sum = 0;
    for (int i = 0; i < b.size(); i++) {
        if (n < i + 1 + i * d) break;
        sum += b[i];
        ans = max(ans, sum + pre[n - i - 1 - i * d]);
    }
    printf("%lld\n", ans);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#define ll long long
#define maxn 100005
using namespace std;
long long n,d,a[maxn],sum[maxn],ans,m;
int main()
{
	scanf("%lld%lld%lld",&n,&d,&m);
	for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	int cnt=0,cut=n;
	for(ll i=1;i<=n;i++)
	{
		sum[i]=sum[i-1]+a[i];
	}
	for(ll i=1;i<=n;i++)
	{
		if(a[i]>m)
		{
			cnt=n-i+1;
			cut=i;
			break;
		}
	}
	cnt--;
	n--;
	//printf("%d ",cnt);
	for(ll i=0;i<=cnt;i++)
	{
		if(i==cnt&&d==100000) printf("%d  ",(cnt+1-i-1)*d);
		if((cnt+1-i-1)*d<i)
		{
			if(i==cnt&&d==100000) printf("!");
			ans=max(ans,sum[n+1]-(sum[cut+i-1]-sum[cut-1]));
		}
		if(i==cnt) break;
		if((cnt-i)*d-i<0||(cnt-i)*d-i>=n) continue;
//		if((cnt-i)*d-i>=cut)
//		{
//			ans=max(ans,sum[n]-sum[(cnt-i)*d]+a[n+1]);
//		}
//		else
		ans=max(ans,sum[n]-sum[(cnt-i)*d-i]-(sum[cut+i-1]-sum[cut-1])+a[n+1]);
		//if(ans==15) printf("%d ",i);
	}
	printf("%lld",ans);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#define ll long long
#define maxn 100005
using namespace std;
long long n,d,a[maxn],sum[maxn],ans,m;
int main()
{
	scanf("%lld%lld%lld",&n,&d,&m);
	for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	int cnt=0,cut=n;
	for(ll i=1;i<=n;i++)
	{
		sum[i]=sum[i-1]+a[i];
	}
	for(ll i=1;i<=n;i++)
	{
		if(a[i]>m)
		{
			cnt=n-i+1;
			cut=i;
			break;
		}
	}
	cnt--;
	n--;
	//printf("%d ",cnt);
	for(ll i=0;i<=cnt;i++)
	{
		if((cnt+1-i-1)*d<i)
		{
			if(i==cnt&&d==100000) printf("!");
			ans=max(ans,sum[n+1]-(sum[cut+i-1]-sum[cut-1]));
		}
		if(i==cnt) break;
		if((cnt-i)*d-i<0||(cnt-i)*d-i>=n) continue;
//		if((cnt-i)*d-i>=cut)
//		{
//			ans=max(ans,sum[n]-sum[(cnt-i)*d]+a[n+1]);
//		}
//		else
		ans=max(ans,sum[n]-sum[(cnt-i)*d-i]-(sum[cut+i-1]-sum[cut-1])+a[n+1]);
		//if(ans==15) printf("%d ",i);
	}
	printf("%lld",ans);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#define ll long long
#define maxn 100005
using namespace std;
long long n,d,a[maxn],sum[maxn],ans,m;
int main()
{
	scanf("%lld%lld%lld",&n,&d,&m);
	for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	long long cnt=0,cut=n;
	for(ll i=1;i<=n;i++)
	{
		sum[i]=sum[i-1]+a[i];
	}
	for(ll i=1;i<=n;i++)
	{
		if(a[i]>m)
		{
			cnt=n-i+1;
			cut=i;
			break;
		}
	}
	cnt--;
	n--;
	if(d==100000) printf("!");
	for(ll i=0;i<=cnt;i++)
	{
		if(d==100000&&i==1) printf("!");
		if(i==cnt&&d==100000) printf("%d  ",cnt);
		if((cnt+1-i-1)*d<i)
		{
			ans=max(ans,sum[n+1]-(sum[cut+i-1]-sum[cut-1]));
		}
		if(i==cnt) break;
		if((cnt-i)*d-i<0||(cnt-i)*d-i>=n) continue;
//		if((cnt-i)*d-i>=cut)
//		{
//			ans=max(ans,sum[n]-sum[(cnt-i)*d]+a[n+1]);
//		}
//		else
		ans=max(ans,sum[n]-sum[(cnt-i)*d-i]-(sum[cut+i-1]-sum[cut-1])+a[n+1]);
		//if(ans==15) printf("%d ",i);
	}
	printf("%lld",ans);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#define ll long long
#define maxn 100005
using namespace std;
long long n,d,a[maxn],sum[maxn],ans,m;
int main()
{
	scanf("%lld%lld%lld",&n,&d,&m);
	for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	long long cnt=0,cut=n;
	for(ll i=1;i<=n;i++)
	{
		sum[i]=sum[i-1]+a[i];
	}
	for(ll i=1;i<=n;i++)
	{
		if(a[i]>m)
		{
			cnt=n-i+1;
			cut=i;
			break;
		}
	}
	if(cnt==0)
	{
		printf("%lld",sum[n]);
		return 0;
	}
	cnt--;
	n--;
	//if(d==100000) printf("%d",cnt);
	for(ll i=0;i<=cnt;i++)
	{
		//if(d==100000&&i==1) printf("!");
		//if(i==cnt&&d==100000) printf("%d  ",cnt);
		if((cnt+1-i-1)*d<i)
		{
			ans=max(ans,sum[n+1]-(sum[cut+i-1]-sum[cut-1]));
		}
		if(i==cnt) break;
		if((cnt-i)*d-i<0||(cnt-i)*d-i>=n) continue;
//		if((cnt-i)*d-i>=cut)
//		{
//			ans=max(ans,sum[n]-sum[(cnt-i)*d]+a[n+1]);
//		}
//		else
		ans=max(ans,sum[n]-sum[(cnt-i)*d-i]-(sum[cut+i-1]-sum[cut-1])+a[n+1]);
		//if(ans==15) printf("%d ",i);
	}
	printf("%lld",ans);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#define ll long long
#define maxn 100005
using namespace std;
long long n,d,a[maxn],sum[maxn],ans,m;
int main()
{
	scanf("%lld%lld%lld",&n,&d,&m);
	for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	int cnt=0,cut=n;
	for(ll i=1;i<=n;i++)
	{
		sum[i]=sum[i-1]+a[i];
	}
	n--;
	for(ll i=1;i<=n;i++)
	{
		if(a[i]>m)
		{
			cnt=n-i+1;
			cut=i;
			break;
		}
	}
	for(ll i=0;i<cnt;i++)
	{
		if((cnt-i)*d-i<0) continue;
		if((cnt-i)*d-i>=cut)
		{
			ans=max(ans,sum[n]-sum[(cnt-i)*d]);
		}
		else ans=max(ans,sum[n]-sum[(cnt-i)*d-i]-(sum[cut+i-1]-sum[cut-1]));
	}
	printf("%lld",ans+a[n+1]);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#define ll long long
#define maxn 100005
using namespace std;
long long n,d,a[maxn],sum[maxn],ans,m;
int main()
{
	scanf("%lld%lld%lld",&n,&d,&m);
	for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	long long cnt=0,cut=n;
	for(ll i=1;i<=n;i++)
	{
		sum[i]=sum[i-1]+a[i];
	}
	for(ll i=1;i<=n;i++)
	{
		if(a[i]>m)
		{
			cnt=n-i+1;
			cut=i;
			break;
		}
	}
	for(ll i=0;i<=cnt;i++)
	{
		if((cnt-i-1)*d-i>=cut) continue;
		if((cnt-i-1)*d-i<0)
		{
			ans=max(ans,sum[n]-(sum[cut+i-1]-sum[cut-1]));
		}
		else ans=max(ans,sum[n]-sum[(cnt-i-1)*d-i]-(sum[cut+i-1]-sum[cut-1]));
	}
	printf("%lld",ans);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#define ll long long
#define maxn 100005
using namespace std;
long long n,d,a[maxn],sum[maxn],ans,m;
int main()
{
	scanf("%lld%lld%lld",&n,&d,&m);
	for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	int cnt=0,cut=n;
	for(ll i=1;i<=n;i++)
	{
		sum[i]=sum[i-1]+a[i];
	}
	for(ll i=1;i<=n;i++)
	{
		if(a[i]>m)
		{
			cnt=n-i+1;
			cut=i;
			break;
		}
	}
	cnt--;
	n--;
	//printf("%d ",cnt);
	for(ll i=0;i<=cnt;i++)
	{
		if((cnt+1-i-1)*d<i)
		{
			//printf("%d ",i);
			ans=max(ans,sum[n+1]-(sum[cut+i-1]-sum[cut-1]));
		}
		if(i==cnt) break;
		if((cnt-i)*d-i<0||(cnt-i)*d-i>=n) continue;
		if((cnt-i)*d-i>=cut)
		{
			ans=max(ans,sum[n]-sum[(cnt-i)*d]+a[n+1]);
		}
		else ans=max(ans,sum[n]-sum[(cnt-i)*d-i]-(sum[cut+i-1]-sum[cut-1])+a[n+1]);
		//if(ans==15) printf("%d ",i);
	}
	printf("%lld",ans);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#define ll long long
#define maxn 100005
using namespace std;
long long n,d,a[maxn],sum[maxn],ans,m;
int main()
{
	scanf("%lld%lld%lld",&n,&d,&m);
	for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	int cnt=0,cut=n;
	for(ll i=1;i<=n;i++)
	{
		sum[i]=sum[i-1]+a[i];
	}
	for(ll i=1;i<=n;i++)
	{
		if(a[i]>m)
		{
			cnt=n-i+1;
			cut=i;
			break;
		}
	}
	n--;
	for(ll i=0;i<cnt;i++)
	{
		if((cnt-i)*d-i<0||(cnt-i)*d-i>=n) continue;
		if((cnt-i)*d-i>=cut)
		{
			ans=max(ans,sum[n]-sum[(cnt-i)*d]+a[n+1]);
		}
		else ans=max(ans,sum[n]-sum[(cnt-i)*d-i]-(sum[cut+i-1]-sum[cut-1])+a[n+1]);
		if((cnt-i-1)*d<i) ans=max(ans,sum[n+1]-(sum[cut+i-1]-sum[cut-1]));
		if(ans==15) printf("%d ",i);
	}
	printf("%lld",ans);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#define ll long long
#define maxn 100005
using namespace std;
long long n,d,a[maxn],sum[maxn],ans,m;
int main()
{
	scanf("%lld%lld%lld",&n,&d,&m);
	for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	int cnt=0,cut=n;
	for(ll i=1;i<=n;i++)
	{
		sum[i]=sum[i-1]+a[i];
	}
	for(ll i=1;i<=n;i++)
	{
		if(a[i]>m)
		{
			cnt=n-i+1;
			cut=i;
			break;
		}
	}
	cnt--;
	n--;
	//printf("%d ",cnt);
	for(ll i=0;i<=cnt;i++)
	{
		if(d==100000&&i==cnt-1) printf("!");
		if(i==cnt&&d==100000) printf("%d  ",cnt);
		if((cnt+1-i-1)*d<i)
		{
			ans=max(ans,sum[n+1]-(sum[cut+i-1]-sum[cut-1]));
		}
		if(i==cnt) break;
		if((cnt-i)*d-i<0||(cnt-i)*d-i>=n) continue;
//		if((cnt-i)*d-i>=cut)
//		{
//			ans=max(ans,sum[n]-sum[(cnt-i)*d]+a[n+1]);
//		}
//		else
		ans=max(ans,sum[n]-sum[(cnt-i)*d-i]-(sum[cut+i-1]-sum[cut-1])+a[n+1]);
		//if(ans==15) printf("%d ",i);
	}
	printf("%lld",ans);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#define ll long long
#define maxn 100005
using namespace std;
long long n,d,a[maxn],sum[maxn],ans,m;
int main()
{
	scanf("%lld%lld%lld",&n,&d,&m);
	for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	int cnt=0,cut=n;
	for(ll i=1;i<=n;i++)
	{
		sum[i]=sum[i-1]+a[i];
	}
	n--;
	for(ll i=1;i<=n;i++)
	{
		if(a[i]>m)
		{
			cnt=n-i+1;
			cut=i;
			break;
		}
	}
	for(ll i=0;i<cnt;i++)
	{
		if((cnt-i)*d-i<0||(cnt-i)*d-i>=cut) continue;
		ans=max(ans,sum[n]-sum[(cnt-i)*d-i]-(sum[cut+i-1]-sum[cut-1]));
	}
	printf("%lld",ans+a[n+1]);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#define ll long long
#define maxn 100005
using namespace std;
long long n,d,a[maxn],sum[maxn],ans,m;
int main()
{
	scanf("%lld%lld%lld",&n,&d,&m);
	for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	long long cnt=0,cut=n;
	for(ll i=1;i<=n;i++)
	{
		sum[i]=sum[i-1]+a[i];
	}
	for(ll i=1;i<=n;i++)
	{
		if(a[i]>m)
		{
			cnt=n-i+1;
			cut=i;
			break;
		}
	}
	cnt--;
	n--;
	//printf("%d ",cnt);
	for(ll i=0;i<=cnt;i++)
	{
		if(d==100000&&i==1) printf("!");
		if(i==cnt&&d==100000) printf("%d  ",cnt);
		if((cnt+1-i-1)*d<i)
		{
			ans=max(ans,sum[n+1]-(sum[cut+i-1]-sum[cut-1]));
		}
		if(i==cnt) break;
		if((cnt-i)*d-i<0||(cnt-i)*d-i>=n) continue;
//		if((cnt-i)*d-i>=cut)
//		{
//			ans=max(ans,sum[n]-sum[(cnt-i)*d]+a[n+1]);
//		}
//		else
		ans=max(ans,sum[n]-sum[(cnt-i)*d-i]-(sum[cut+i-1]-sum[cut-1])+a[n+1]);
		//if(ans==15) printf("%d ",i);
	}
	printf("%lld",ans);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#define maxn 100005
using namespace std;
int n,d;
long long a[maxn],sum[maxn],ans,m;
int main()
{
	scanf("%d%d%lld",&n,&d,&m);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	int cnt=0,cut=n;
	for(int i=1;i<=n;i++)
	{
		printf("%lld",a[i]);
		sum[i]=sum[i-1]+a[i];
	}
	n--;
	for(int i=1;i<=n;i++)
	{
		if(a[i]>m)
		{
			cnt=n-i+1;
			cut=i;
			break;
		}
	}
	//printf("%d %d %d %d\n",cnt,cut,sum[n]);
	for(int i=0;i<cnt;i++)
	{
		if((cnt-i)*d-i<0||(cnt-i)*d-i>n) continue;
		ans=max(ans,sum[n]-sum[(cnt-i)*d-i]-(sum[cut+i-1]-sum[cut-1]));
	}
	printf("%lld",ans+a[n+1]);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#define ll long long
#define maxn 100005
using namespace std;
long long n,d,a[maxn],sum[maxn],ans,m;
int main()
{
	scanf("%lld%lld%lld",&n,&d,&m);
	for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	int cnt=0,cut=n;
	for(ll i=1;i<=n;i++)
	{
		sum[i]=sum[i-1]+a[i];
	}
	n--;
	for(ll i=1;i<=n;i++)
	{
		if(a[i]>m)
		{
			cnt=n-i+1;
			cut=i;
			break;
		}
	}
	//printf("%d %d %d %d\n",cnt,cut,sum[n]);
	for(ll i=0;i<cnt;i++)
	{
		if((cnt-i)*d-i<0||(cnt-i)*d-i>n) continue;
		ans=max(ans,sum[n]-sum[(cnt-i)*d-i]-(sum[cut+i-1]-sum[cut-1]));
	}
	printf("%lld",ans+a[n+1]);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#define maxn 100005
using namespace std;
int n,d,m,a[maxn],sum[maxn],ans;
int main()
{
	scanf("%d%d%d",&n,&d,&m);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	int cnt=0,cut=n;
	for(int i=1;i<=n;i++)
	{
		printf("%d ",a[i]);
		sum[i]=sum[i-1]+a[i];
	}
	n--;
	for(int i=1;i<=n;i++)
	{
		if(a[i]>m)
		{
			cnt=n-i+1;
			cut=i;
			break;
		}
	}
	//printf("%d %d %d %d\n",cnt,cut,sum[n]);
	for(int i=0;i<cnt;i++)
	{
		ans=max(ans,sum[n]-sum[(cnt-i)*d-i]-(sum[cut+i-1]-sum[cut-1]));
		//if(i==5) printf("%d %d\n",sum[n]-sum[(cnt-i)*d-i],(sum[cut+i-1]-sum[cut-1]));
	}
	printf("%d",ans+a[n+1]);
	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5+5;
int n,d,m;
int a[N];
int q1[N],r1,sumq1[N];
int q2[N],r2,sumq2[N];
int ans;
inline bool cmp(int a,int b)
{
	return a>b;
}
signed main()
{
	scanf("%lld%lld%lld",&n,&d,&m);
	for(int i=1;i<=n;++i)
	{
		scanf("%lld",&a[i]);
		if(a[i]>m)
		{
			q1[++r1]=a[i];
		}
		else
		{
			q2[++r2]=a[i];
		}
	}
	sort(q1+1,q1+r1+1,cmp);
	sort(q2+1,q2+r2+1,cmp);
	for(int i=1;i<=r1;++i) sumq1[i]=sumq1[i-1]+q1[i];
	for(int i=1;i<=r2;++i) sumq2[i]=sumq2[i-1]+q2[i];
	for(int i=r2+1;i<=200000;++i) sumq2[i]=sumq2[r2];
	for(int i=0;i<=r1&&(i-1)*(d+1)+1<=n;++i)
	{
		int anss=0;
		anss=sumq1[i];
		int em=n-((i-1)*(d+1)+1);
		anss+=sumq2[em];
		ans=max(ans,anss);
	}
	printf("%lld",ans);
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <map>
using namespace std;
typedef long long LL;
const LL N = 1000000007;

LL n,d,m,ans = 0,a[500005];

LL lm[500005],pl[500005],cnl = 0;
LL rm[500005],pr[500005],cnr = 0;

bool cmp(LL x,LL y){ return x > y; }

int main(){
	ios::sync_with_stdio(false);
	cin >> n >> d >> m; d ++;
	for(LL i = 1;i <= n;i ++){
		cin >> a[i];
		if(a[i] > m) rm[++ cnr] = a[i];
		else lm[++ cnl] = a[i];
	}
	sort(lm + 1,lm + 1 + cnl,cmp);
	sort(rm + 1,rm + 1 + cnr,cmp);
	for(LL i = 1;i <= cnl;i ++) pl[i] = pl[i - 1] + lm[i];
	for(LL i = 1;i <= cnr;i ++) pr[i] = pr[i - 1] + rm[i];

	for(LL i = 0;i <= cnl;i ++) ans = max(ans,pl[i] + pr[(n - i - 1) / d + 1]);

	cout << ans << '\n';
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int ac[100001],wa[100001],x,n1,n2,n,m,k;
long long qz1[100001],qz2[100001];
long long ans;
bool cmp(long long a,long long b){return a>b;}
long long min(long long a,long long b){
	return a<b?a:b;
}
int main(){
	cin>>n>>k>>m;
	for(int i=1;i<=n;i++){
		cin>>x;
		if(x<=m)ac[++n1]=x;
		else wa[++n2]=x;
	}
	sort(ac+1,ac+1+n1,cmp);
	sort(wa+1,wa+1+n2,cmp);
	for(int i=1;i<=n;i++)qz1[i]=qz1[i-1]+ac[i];
	for(int i=1;i<=n;i++)qz2[i]=qz2[i-1]+wa[i];
	ans=qz1[n1];
	for(int i=1;i<=n2;i++)
	{
		int pos=(i-1)*(k+1)+1;
		if(pos>n)break;
		ans=max(ans,qz2[i]+qz1[n-min(n,pos)]);
	}
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=int(b);++i)

using namespace std;

typedef long long ll;

const int maxn=1e5+5;
int n,d,m,k,l;
ll a[maxn],b[maxn];

inline int max(int a,int b) { return a>b?a:b; }

void solve(ll a[],int n) {
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	rep(i,1,n)
    	a[i]+=a[i-1];
    return ;
}

int main() {
	scanf("%d%d%d",&n,&d,&m);
	for (int i=0,x;i<n;++i) {
		scanf("%d",&x);
		if (x>m)
        	a[++k]=x;
		else
        	b[++l]=x;
	}
	if(!k) {
		ll s=0;
		rep(i,1,n)
        	s+=b[i];
		printf("%lld\n",s);
		exit(0);
	}
	solve(a,k);
	solve(b,l);
	fill(b+l+1,b+n+1,b[l]);
	ll res=0;
	rep(i,(k + d)/(1+d),k)
    	if(1ll*(i-1)*(d+1)+1<=n)
		res=max(res,a[i]+b[n-1ll*(i-1)*(d+1)-1]);
	printf("%lld\n",res);
	return 0;
}


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

const int MAXN = 100000+5;
long long n,d,m,ans=-1,joke1len,joke2len;
long long joke1[MAXN],joke2[MAXN],sumjoke1[MAXN],sumjoke2[MAXN];

bool compare(int a,int b)
{
	return a>b;
}

int main()
{
	long long x,t1=0,t2=0;
	cin>>n>>d>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		if(x>m) joke1[++t1]=x;
		else joke2[++t2]=x;
	}

	sort(joke1+1,joke1+t1+1,compare);
	sort(joke2+1,joke2+t2+1,compare);

	for(int i=1;i<=t1;i++)
		sumjoke1[i]=sumjoke1[i-1]+joke1[i];
	for(int i=1;i<=t2;i++)
		sumjoke2[i]=sumjoke2[i-1]+joke2[i];

	ans=sumjoke1[t2];
	for(int i=1;i<=t1;i++)
	{
		joke1len=(i-1)*(d+1)+1;
		if(joke1len<=n)
		{
			joke2len=min(n-joke1len,t2);
			ans=max(ans,sumjoke1[i]+sumjoke2[joke2len]);
		}
		else break;
	}
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define int long long
using namespace std;
typedef double DB;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<PII> VPII;
//head
const int N=1e5+5;
int s[N],n,m,d;
VI a,b;
signed main() {
	scanf("%lld%lld%lld",&n,&d,&m);
	for(int i=1;i<=n;i++) {
		int x;
		scanf("%lld",&x);
		if(x<=m) a.PB(x);
		else b.PB(x);
	}
	sort(ALL(a));
	reverse(ALL(a));
	sort(ALL(b));
	reverse(ALL(b));
	for(int i=0;i<SZ(a);i++) s[i]=s[i-1>=0?i-1:0]+a[i];
	int res=s[min(SZ(a),n)-1];
	int t=min(SZ(a),n);
	int l=0,r=min(SZ(a),n)-1;
	for(int i=0;i<SZ(b);i++) {
		if(t<n) res+=b[i],t+=d+1;
		else if(r-l>=t-n&&s[r]-s[r-(t-n+1)]<=b[i]) res+=b[i]-s[r]+s[r-(t-n+1)],r-=t-n+1,t=n+d;
	}
	printf("%lld\n",res);
    return 0;
}
/*
10 3 10
17 17 17 8 7 6 5 4 1 1
*/


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,d,pos=-1;
ll ans,a[100005],m,p[100005],res;
int main() {
	scanf("%d%d%lld",&n,&d,&m);
	for(int i=1; i<=n; i++) scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	for(int i=1; i<=n; i++) {
		if(a[i]>m) {
			pos=i-1;
			break;
		}
	}
	if(pos==-1) pos=n;
	for(int i=1; i<=n; i++) p[i]=p[i-1]+a[i];
	for(int x=0; x<=pos; x++) {
		res=0;
		int k=(n-x)/(d+1);
		int y=n-x-(d+1)*k;
		if(k+(y>0)>n-pos) continue;
		res=p[n]-p[n-k-(y>0)]+p[pos]-p[pos-x];
		ans=max(res,ans);
	}
	printf("%lld\n",ans);
	return 0;
}


#include <bits/stdc++.h>

#define int long long

using namespace std;
const int N = 100010;
int a[N],b[N],pre[N];
int n,d,m;

signed main()
{
    scanf("%lld%lld%lld",&n,&d,&m);
    int cnt1 = 0, cnt2 = 0;
    for(int i = 1; i <= n; i ++){
        int x; cin >> x;
        if(x > m)a[++cnt1] = x;
        else b[ ++cnt2] =  x;
    }
    sort(a + 1, a + cnt1 + 1, greater<int>());
    sort(b + 1, b + cnt2 + 1, greater<int>());
    int sum = 0,ans = 0;
    for(int i = 1; i <= n; i ++) pre[i] = pre[i - 1] + b[i];
    for(int i = 1 ;i <= cnt1 ; i ++){
        sum += a[i];
        int t = (i - 1) * (d + 1) + 1;
        if(t > n) break;
        t = n - t;
        ans = max(ans,sum + pre[t]);
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define repp(i,a,b) for(int i=(a);i<(b);++i)
#define perr(i,a,b) for(int i=(b);i>(a);--i)

using namespace std;

typedef long long ll;

const int maxn = 100010;
int a[maxn];
ll s[maxn];

int main() {
    int n, d, m;
    cin >> n >> d >> m;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    sort(a + 1, a + n + 1);
    ll ans = 0, tmp = 0;
    if(a[n] <= m) {
        for(int i = 1; i <= n; ++i) ans += a[i];
        cout << ans << endl;
        return 0;
    }
    s[1] = a[1]; for(int i = 2; i <= n; ++i) s[i] = s[i - 1] + a[i];
    int t = upper_bound(a + 1, a + n + 1, m) - a;
	ans = s[t - 1];
    int ed = n / (d + 1) + ((n % (d + 1)) ? 1 : 0);
    for(int k = 1; k <= ed && k <= n - t + 1; ++k) {
        tmp = s[n] - s[n - k];
        int lft = (n - 1) - (k - 1) * (d + 1);
        if(lft > 0) tmp += s[t - 1] - s[max(t - lft - 1, 0)];
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}