#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifdef OJ
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define all(x) (x).begin(), (x).end()
#define rsort(x) sort((x).rbegin(), (x).rend())
#define sz(x) ((int)x.size())
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n, e) for (int i = (int)(n); i >= (int)(e); --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << (x) << '\n'; return 0;}while(0)

const char en = '\n';
const int MOD = 0;
const int MAXN = 0;
const int INF = 1e9+1;

int solve() {
    int n; cin >> n;
    vector<int> a(n);
    fori(i,n) cin >> a[i];
    vector<vector<LL>> dp(n, vector<LL>(n,INF));
    vector<vector<int>> b(n, vector<int>(n));

    vector<vector<pii>> mn(n, vector<pii>(n));
    fori(i,n) {
        pii cur{INF,0};
        fore(j,i,n-1) {
            if(a[j] < cur.fi) {
                cur = {a[j],1};
            } else if(a[j] == cur.fi) {
                cur.se++;
            }
            mn[i][j] = cur;
        }
    }

    function<LL(int,int)> solve = [&](int i, int j) {
        if(b[i][j]) return dp[i][j];
        b[i][j] = 1;
        LL &ret = dp[i][j];
        ret = j-i+1;

        auto p = mn[i][j];
        int v = p.fi;
        int cnt = p.se;

        mmin(ret, (1LL)*j-i+1-cnt+v);

        fore(k,i,j-1) {
            mmin(ret, solve(i,k) + solve(k+1,j));
        }

        debug(i,j,ret);
        return ret;
    };

    int i = 0;
    LL ans = 0;
    while(i < n) {
        while(i < n && a[i] == 0) i++;
        if(i == n) break;
        int j = i;
        while(j+1 < n && a[j+1] != 0) j++;

        ans += solve(i,j);

        i = j+1;
    }

    cout << ans << en;
    return 0;
}

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    int ntest = 1;
    //cin >> ntest;
    fori(test, ntest) {
        //cout << "Case #" << test+1 << ": ";
        solve();
    }

    return 0;
}


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

typedef long long LL;
#define MAXN 5000
#define MOD 761238923
#define INF 10000000

int N;
LL A[MAXN];

LL dp(int l, int r, LL toreduce) {
    int i, j;
    LL mn = 1000000005;
    for (i = l; i < r; i++)
        mn = min(mn, A[i] - toreduce);

    LL res = 0;
    for (i = l; i < r && A[i] - toreduce == mn; i++);
    while (i != r) {
        for (j = i; j < r && A[j] - toreduce > mn; j++);

        res += dp(i, j, toreduce + mn);

        for (i = j; i < r && A[i] - toreduce == mn; i++);
    }

    return min((LL) (r - l), mn + res);
}

int main() {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //    freopen("output.txt", "wt", stdout);
#endif
    std::ios_base::sync_with_stdio(false);
    scanf("%d", &N);
    for (int i = 0; i < N; i++)
        scanf("%lld", &A[i]);

    printf("%lld\n", dp(0, N, 0));
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifdef OJ
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define all(x) (x).begin(), (x).end()
#define rsort(x) sort((x).rbegin(), (x).rend())
#define sz(x) ((int)x.size())
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n, e) for (int i = (int)(n); i >= (int)(e); --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << (x) << '\n'; return 0;}while(0)

const char en = '\n';
const int MOD = 0;
const int MAXN = 0;
const int INF = 1e9+1;

int solve() {
    int n; cin >> n;
    vector<int> a(n);
    fori(i,n) cin >> a[i];
    vector<vector<LL>> dp(n, vector<LL>(n,INF));

    vector<vector<pii>> mn(n, vector<pii>(n));
    fori(i,n) {
        pii cur{INF,0};
        fore(j,i,n-1) {
            if(a[j] < cur.fi) {
                cur = {a[j],1};
            } else if(a[j] == cur.fi) {
                cur.se++;
            }
            mn[i][j] = cur;
        }
    }

    function<LL(int,int)> solve = [&](int i, int j) {
        if(dp[i][j] != INF) return dp[i][j];
        LL &ret = dp[i][j];
        ret = j-i+1;

        auto p = mn[i][j];
        int v = p.fi;
        int cnt = p.se;

        mmin(ret, (1LL)*j-i+1-cnt+v);

        fore(k,i,j-1) {
            mmin(ret, solve(i,k) + solve(k+1,j));
        }

        debug(i,j,ret);
        return ret;
    };

    int i = 0;
    LL ans = 0;
    while(i < n) {
        while(i < n && a[i] == 0) i++;
        if(i == n) break;
        int j = i;
        while(j+1 < n && a[j+1] != 0) j++;

        ans += solve(i,j);

        i = j+1;
    }

    cout << ans << en;
    return 0;
}

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    int ntest = 1;
    //cin >> ntest;
    fori(test, ntest) {
        //cout << "Case #" << test+1 << ": ";
        solve();
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifdef OJ
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define all(x) (x).begin(), (x).end()
#define rsort(x) sort((x).rbegin(), (x).rend())
#define sz(x) ((int)x.size())
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n, e) for (int i = (int)(n); i >= (int)(e); --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << (x) << '\n'; return 0;}while(0)

const char en = '\n';
const int MOD = 0;
const int MAXN = 0;
const int INF = 1e9+1;

int solve() {
    int n; cin >> n;
    vector<int> a(n);
    fori(i,n) cin >> a[i];
    vector<LL> dp(n,INF);

    fori(i,n) {
        if(a[i] == 0) {
            if(i) dp[i] = dp[i-1];
            else dp[i] = 0;
        } else {
            pii cur{INF,0};
            ford(j,i,0) {
                if(a[j] < cur.fi) {
                    cur = {a[j],1};
                } else if(a[j] == cur.fi) {
                    cur.se++;
                }
                LL tmp = min((LL)i-j+1, (LL)i-j+1-cur.se+cur.fi);
                if(j) tmp += dp[j-1];
                mmin(dp[i],tmp);
            }
        }
    }
    cout << dp[n-1] << en;
    return 0;
}

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    int ntest = 1;
    //cin >> ntest;
    fori(test, ntest) {
        //cout << "Case #" << test+1 << ": ";
        solve();
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifdef OJ
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define all(x) (x).begin(), (x).end()
#define rsort(x) sort((x).rbegin(), (x).rend())
#define sz(x) ((int)x.size())
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n, e) for (int i = (int)(n); i >= (int)(e); --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << (x) << '\n'; return 0;}while(0)

const char en = '\n';
const int MOD = 0;
const int MAXN = 0;
const int INF = 1e9+1;

int solve() {
    int n; cin >> n;
    vector<int> a(n);
    fori(i,n) cin >> a[i];
    vector<vector<int>> dp(n, vector<int>(n,INF));

    vector<vector<pii>> mn(n, vector<pii>(n));
    fori(i,n) {
        pii cur{INF,0};
        fore(j,i,n-1) {
            if(a[j] < cur.fi) {
                cur = {a[j],1};
            } else if(a[j] == cur.fi) {
                cur.se++;
            }
            mn[i][j] = cur;
        }
    }

    function<int(int,int)> solve = [&](int i, int j) {
        if(dp[i][j] != INF) return dp[i][j];
        int &ret = dp[i][j];
        ret = j-i+1;

        auto p = mn[i][j];
        int v = p.fi;
        int cnt = p.se;

        if(1LL*ret > (1LL)*j-i+1-cnt+v) {
            ret = j-i+1-cnt+v;
        }

        fore(k,i,j-1) {
            mmin(ret, solve(i,k) + solve(k+1,j));
        }

        debug(i,j,ret);
        return ret;
    };

    int i = 0;
    LL ans = 0;
    while(i < n) {
        while(i < n && a[i] == 0) i++;
        if(i == n) break;
        int j = i;
        while(j+1 < n && a[j+1] != 0) j++;

        ans += solve(i,j);

        i = j+1;
    }

    cout << ans << en;
    return 0;
}

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    int ntest = 1;
    //cin >> ntest;
    fori(test, ntest) {
        //cout << "Case #" << test+1 << ": ";
        solve();
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifdef OJ
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define all(x) (x).begin(), (x).end()
#define rsort(x) sort((x).rbegin(), (x).rend())
#define sz(x) ((int)x.size())
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n, e) for (int i = (int)(n); i >= (int)(e); --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << (x) << '\n'; return 0;}while(0)

const char en = '\n';
const int MOD = 0;
const int MAXN = 0;
const int INF = 1e9+1;

struct stInfo {
    int mn, cnt, zero;
    stInfo() {
        mn = INF;
        cnt = 0;
        zero = 0;
    }
};

int solve() {
    int n; cin >> n;
    vector<int> a(n);
    fori(i,n) cin >> a[i];
    vector<LL> dp(n,INF);

    fori(i,n) {
        if(a[i] == 0) {
            if(i) dp[i] = dp[i-1];
            else dp[i] = 0;
        } else {
            stInfo cur;
            int flag = 1;
            ford(j,i,0) {
                if(a[j]) {
                    if(a[j] < cur.mn) {
                        cur.mn = a[j];
                        cur.cnt = 1;
                    } else if(a[j] == cur.mn) {
                        cur.cnt++;
                    }
                } else {
                    flag = 0;
                    cur.zero++;
                }

                LL tmp = i-j+1-cur.zero;
                if(flag) mmin(tmp, (LL)i-j+1-cur.cnt+cur.mn);
                if(j) tmp += dp[j-1];
                mmin(dp[i],tmp);
            }
        }
    }
    cout << dp[n-1] << en;
    return 0;
}

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    int ntest = 1;
    //cin >> ntest;
    fori(test, ntest) {
        //cout << "Case #" << test+1 << ": ";
        solve();
    }

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=5005;
int dp[N][2*N];
int n,a[N];
int func(int i,int prev){
    // cout<<i<<" "<<prev<<"\n";
    if(i==n)    return 0;
    if(dp[i][prev]!=-1) return dp[i][prev];

    int ans=5001;
    ans=min(ans,1+func(i+1,min(prev,a[i])));

    int mi=(((i+1)<n)?min(a[i+1],10):10);
    for(int k=0;k<=min(a[i],mi);k++){
        if((k+prev)>=min(a[i],5000)){
            ans=min(ans,k+func(i+1,min(k+prev,a[i])));
            break;
        }else{
            ans=min(ans,k+1+func(i+1,k+prev));
        }
    }
    // cout<<i<<" "<<prev<<" "<<ans<<"\n";
    return dp[i][prev]=ans;
}

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

    ios_base::sync_with_stdio(false);cin.tie(NULL);

    memset(dp,-1,sizeof(dp));
    cin>>n;
    for(int i=0;i<n;i++)    cin>>a[i];
    cout<<func(0,0)<<"\n";
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=5005;
int dp[N][2*N];
int n,a[N];
int func(int i,int prev){
    // cout<<i<<" "<<prev<<"\n";
    if(i==n)    return 0;
    if(dp[i][prev]!=-1) return dp[i][prev];

    int ans=5001;
    ans=min(ans,1+func(i+1,min(prev,a[i])));

    int mi=(((i+1)<n)?min(a[i+1],50):50);
    for(int k=0;k<=min(a[i],mi);k++){
        if((k+prev)>=min(a[i],5000)){
            ans=min(ans,k+func(i+1,min(k+prev,a[i])));
            break;
        }else{
            ans=min(ans,k+1+func(i+1,k+prev));
        }
    }
    // cout<<i<<" "<<prev<<" "<<ans<<"\n";
    return dp[i][prev]=ans;
}

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

    ios_base::sync_with_stdio(false);cin.tie(NULL);

    memset(dp,-1,sizeof(dp));
    cin>>n;
    for(int i=0;i<n;i++)    cin>>a[i];
    cout<<func(0,0)<<"\n";
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=5005;
int dp[N][2*N];
int n,a[N];
int func(int i,int prev){
    // cout<<i<<" "<<prev<<"\n";
    if(i==n)    return 0;
    if(dp[i][prev]!=-1) return dp[i][prev];

    int ans=5001;
    ans=min(ans,1+func(i+1,min(prev,a[i])));

    int mi=(((i+1)<n)?min(a[i+1],20):20);
    for(int k=0;k<=min(a[i],mi);k++){
        if((k+prev)>=min(a[i],5000)){
            ans=min(ans,k+func(i+1,min(k+prev,a[i])));
            break;
        }else{
            ans=min(ans,k+1+func(i+1,k+prev));
        }
    }
    // cout<<i<<" "<<prev<<" "<<ans<<"\n";
    return dp[i][prev]=ans;
}

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

    ios_base::sync_with_stdio(false);cin.tie(NULL);

    memset(dp,-1,sizeof(dp));
    cin>>n;
    for(int i=0;i<n;i++)    cin>>a[i];
    cout<<func(0,0)<<"\n";
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=5005;
int dp[N][2*N];
int n,a[N];
int func(int i,int prev){
    // cout<<i<<" "<<prev<<"\n";
    if(i==n)    return 0;
    if(dp[i][prev]!=-1) return dp[i][prev];

    int ans=5001;
    ans=min(ans,1+func(i+1,min(prev,a[i])));

    int mi=(((i+1)<n)?min(a[i+1],100):100);
    for(int k=0;k<=min(a[i],mi);k++){
        if((k+prev)>=a[i]){
            ans=min(ans,k+func(i+1,min(k+prev,a[i])));
            break;
        }else{
            ans=min(ans,k+1+func(i+1,k+prev));
        }
    }
    // cout<<i<<" "<<prev<<" "<<ans<<"\n";
    return dp[i][prev]=ans;
}

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

    ios_base::sync_with_stdio(false);cin.tie(NULL);

    memset(dp,-1,sizeof(dp));
    cin>>n;
    for(int i=0;i<n;i++)    cin>>a[i];
    cout<<func(0,0)<<"\n";
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=5005;
int dp[N][2*N];
int n,a[N];
int func(int i,int prev){
    // cout<<i<<" "<<prev<<"\n";
    if(i==n)    return 0;
    if(dp[i][prev]!=-1) return dp[i][prev];

    int ans=5001;
    ans=min(ans,1+func(i+1,min(prev,a[i])));

    int mi=(((i+1)<n)?min(a[i+1],25):25);
    for(int k=0;k<=min(a[i],mi);k++){
        if((k+prev)>=min(a[i],5000)){
            ans=min(ans,k+func(i+1,min(k+prev,a[i])));
            break;
        }else{
            ans=min(ans,k+1+func(i+1,k+prev));
        }
    }
    // cout<<i<<" "<<prev<<" "<<ans<<"\n";
    return dp[i][prev]=ans;
}

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

    ios_base::sync_with_stdio(false);cin.tie(NULL);

    memset(dp,-1,sizeof(dp));
    cin>>n;
    for(int i=0;i<n;i++)    cin>>a[i];
    cout<<func(0,0)<<"\n";
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=5005;
int dp[N][2*N];
int n,a[N];
int func(int i,int prev){
    // cout<<i<<" "<<prev<<"\n";
    if(i==n)    return 0;
    if(dp[i][prev]!=-1) return dp[i][prev];

    int ans=5001;
    ans=min(ans,1+func(i+1,min(prev,a[i])));

    int mi=(((i+1)<n)?min(a[i+1],30):30);
    for(int k=0;k<=min(a[i],mi);k++){
        if((k+prev)>=min(a[i],5000)){
            ans=min(ans,k+func(i+1,min(k+prev,a[i])));
            break;
        }else{
            ans=min(ans,k+1+func(i+1,k+prev));
        }
    }
    // cout<<i<<" "<<prev<<" "<<ans<<"\n";
    return dp[i][prev]=ans;
}

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

    ios_base::sync_with_stdio(false);cin.tie(NULL);

    memset(dp,-1,sizeof(dp));
    cin>>n;
    for(int i=0;i<n;i++)    cin>>a[i];
    cout<<func(0,0)<<"\n";
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=5005;
int dp[N][2*N];
int n,a[N];
int func(int i,int prev){
    // cout<<i<<" "<<prev<<"\n";
    if(i==n)    return 0;
    if(dp[i][prev]!=-1) return dp[i][prev];

    int ans=5001;
    ans=min(ans,1+func(i+1,min(prev,a[i])));

    int mi=(((i+1)<n)?min(a[i+1],5):5);
    for(int k=0;k<=min(a[i],mi);k++){
        if((k+prev)>=min(a[i],5000)){
            ans=min(ans,k+func(i+1,min(k+prev,a[i])));
            break;
        }else{
            ans=min(ans,k+1+func(i+1,k+prev));
        }
    }
    // cout<<i<<" "<<prev<<" "<<ans<<"\n";
    return dp[i][prev]=ans;
}

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

    ios_base::sync_with_stdio(false);cin.tie(NULL);

    memset(dp,-1,sizeof(dp));
    cin>>n;
    for(int i=0;i<n;i++)    cin>>a[i];
    cout<<func(0,0)<<"\n";
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=5005;
int dp[N][2*N];
int n,a[N];
int func(int i,int prev){
    // cout<<i<<" "<<prev<<"\n";
    if(i==n)    return 0;
    if(dp[i][prev]!=-1) return dp[i][prev];

    int ans=5001;
    ans=min(ans,1+func(i+1,min(prev,a[i])));

    int mi=(((i+1)<n)?min(a[i+1],5000):5000);
    for(int k=0;k<=min(a[i],mi);k++){
        if((k+prev)>=a[i]){
            ans=min(ans,k+func(i+1,min(k+prev,a[i])));
            break;
        }else{
            ans=min(ans,k+1+func(i+1,k+prev));
        }
    }
    // cout<<i<<" "<<prev<<" "<<ans<<"\n";
    return dp[i][prev]=ans;
}

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

    ios_base::sync_with_stdio(false);cin.tie(NULL);

    memset(dp,-1,sizeof(dp));
    cin>>n;
    for(int i=0;i<n;i++)    cin>>a[i];
    cout<<func(0,0)<<"\n";
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=5005;
int dp[N][2*N];
int n,a[N];
int func(int i,int prev){
    // cout<<i<<" "<<prev<<"\n";
    if(i==n)    return 0;
    if(dp[i][prev]!=-1) return dp[i][prev];

    int ans=5001;
    ans=min(ans,1+func(i+1,min(prev,a[i])));

    int mi=(((i+1)<n)?min(a[i+1],100):100);
    for(int k=0;k<=min(a[i],mi);k++){
        if((k+prev)>=min(a[i],5000)){
            ans=min(ans,k+func(i+1,min(k+prev,a[i])));
            break;
        }else{
            ans=min(ans,k+1+func(i+1,k+prev));
        }
    }
    // cout<<i<<" "<<prev<<" "<<ans<<"\n";
    return dp[i][prev]=ans;
}

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

    ios_base::sync_with_stdio(false);cin.tie(NULL);

    memset(dp,-1,sizeof(dp));
    cin>>n;
    for(int i=0;i<n;i++)    cin>>a[i];
    cout<<func(0,0)<<"\n";
}


#include<bits/stdc++.h>
using namespace std;
int n,a[6010],now[6010][6010],res=0;
int calc(int x,int y,int tot){
	if(x==y)return min(a[i],1);
	if(x>y)return 0;
	int mn=1e9,cnt;
	for(int i=x;i<=y;i++){
		if(mn>a[i])cnt=1,now[tot][1]=i,mn=a[i];
		if(mn==a[i])now[tot][++cnt]=i;
	}
	for(int i=x;i<=y;i++)a[i]-=mn;
	for(int i=2;i<=cnt;i++)mn+=calc(now[tot][i-1]+1,now[tot][i]-1,++res);
	return min(mn+calc(x,now[tot][1]-1,++res)+calc(now[tot][cnt]+1,y,++res),y-x+1);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	printf("%d",calc(1,n,0));
}


#include<bits/stdc++.h>
using namespace std;
int n,a[5010];
int calc(int x,int y){
	if(x>y)return 0;
	int mn=0x3f,now[5010],cnt=0;
	for(int i=x;i<=y;i++){
		if(mn>a[i])cnt=1,now[1]=i,mn=a[i];
		if(mn==a[i])now[++cnt]=i;
	}
	for(int i=x;i<=y;i++)a[i]-=mn;
	for(int i=2;i<=cnt;i++)mn+=calc(now[i-1]+1,now[i]-1);
	return min(mn+calc(x,now[0]-1)+calc(now[cnt]+1,y),y-x+1);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	printf("%d",calc(1,n));
}


#include<bits/stdc++.h>
using namespace std;
int n,a[5010],now[5010][5010],res=0;
int calc(int x,int y,int tot){
	if(x>y)return 0;
	int mn=1e9,cnt=0;
	for(int i=x;i<=y;i++){
		if(mn>a[i])cnt=1,now[tot][1]=i,mn=a[i];
		if(mn==a[i])now[tot][++cnt]=i;
	}
	for(int i=x;i<=y;i++)a[i]-=mn;
	for(int i=2;i<=cnt;i++)mn+=calc(now[tot][i-1]+1,now[tot][i]-1,++res);
	return min(mn+calc(x,now[tot][1]-1,++res)+calc(now[tot][cnt]+1,y,++res),y-x+1);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	printf("%d",calc(1,n,0));
}


#include<bits/stdc++.h>
using namespace std;
int read(){
	int x=0; char ch=getchar();
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x;
}
int a[50005];
int solve(int l,int r)
{
    if(l>r) return 0;
	if(l==r)
	{
		if(a[l]==0) return 0;
		return 1;
	}
	int pos=l,ans,minn=a[l];
	for(int i=l+1;i<=r;++i)
		if(minn>a[i]) minn=a[i];
	for(int i=l;i<=r;++i)
		a[i]-=minn;
	ans=minn;
	for(int i=l;i<=r;++i)
		if(a[i]==0)
		{
			ans+=solve(pos,i-1);
			pos=i+1;
		}
	if(pos<=r) ans+=solve(pos,r);
	return min(ans,r-l+1);
}
int main(){
	int n;
	n=read();
	for(int i=1;i<=n;++i)
		a[i]=read();
	int ans=solve(1,n);
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,a[5010],now[5010][5010],res=0;
int calc(int x,int y,int tot){
	if(x>y)return 0;
	int mn=2e9,cnt;
	for(int i=x;i<=y;i++){
		if(mn>a[i])cnt=1,now[tot][1]=i,mn=a[i];
		if(mn==a[i])now[tot][++cnt]=i;
	}
	for(int i=x;i<=y;i++)a[i]-=mn;
	for(int i=2;i<=cnt;i++)mn+=calc(now[tot][i-1]+1,now[tot][i]-1,++res);
	return min(y-x+1,mn+calc(x,now[tot][1]-1,++res)+calc(now[tot][cnt]+1,y,++res));
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	printf("%d",calc(1,n,0));
}


#include<bits/stdc++.h>
using namespace std;
int n,a[5010],now[5010][5010],res=0;
int calc(int x,int y,int tot){
	if(x>y)return 0;
	int mn=1e9,cnt;
	for(int i=x;i<=y;i++){
		if(mn>a[i])cnt=1,now[tot][1]=i,mn=a[i];
		if(mn==a[i])now[tot][++cnt]=i;
	}
	for(int i=x;i<=y;i++)a[i]-=mn;
	for(int i=2;i<=cnt;i++)mn+=calc(now[tot][i-1]+1,now[tot][i]-1,++res);
	return min(y-x+1,mn+calc(x,now[tot][1]-1,++res)+calc(now[tot][cnt]+1,y,++res));
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	printf("%d",calc(1,n,0));
}


#include<bits/stdc++.h>
using namespace std;
int n,a[5010],now[5010][5010],res=0;
int calc(int x,int y,int tot){
	if(x>y){
		res--;
		return 0;
	}
	int mn=2e9,cnt;
	for(int i=x;i<=y;i++){
		if(mn>a[i])cnt=1,now[tot][1]=i,mn=a[i];
		if(mn==a[i])now[tot][++cnt]=i;
	}
	for(int i=x;i<=y;i++)a[i]-=mn;
	for(int i=2;i<=cnt;i++)mn+=calc(now[tot][i-1]+1,now[tot][i]-1,++res);
	return min(y-x+1,mn+calc(x,now[tot][1]-1,++res)+calc(now[tot][cnt]+1,y,++res));
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	printf("%d",calc(1,n,0));
}


#include<bits/stdc++.h>
using namespace std;
int n,a[5010];
int calc(int x,int y){
	if(x>y)return 0;
	int mn=0x3f,ans=0;
	vector<int>vec;
	for(int i=x;i<=y;i++){
		if(mn>a[i])vec.clear(),vec.push_back(i),mn=a[i];
		if(mn==a[i])vec.push_back(i);
	}
	for(int i=x;i<=y;i++)a[i]-=mn;
	for(int i=1;i<vec.size();i++)ans+=calc(vec[i-1]+1,vec[i]-1);
	return min(ans+mn+calc(x,vec[0]-1)+calc(vec[vec.size()-1]+1,y),y-x+1);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	printf("%d",calc(1,n));
}


#include<bits/stdc++.h>
using namespace std;
int n,a[5010],now[5010][5010],res=0;
int calc(int x,int y,int tot){
	if(x==y)return min(a[i],1);
	if(x>y)return 0;
	int mn=1e9,cnt;
	for(int i=x;i<=y;i++){
		if(mn>a[i])cnt=1,now[tot][1]=i,mn=a[i];
		if(mn==a[i])now[tot][++cnt]=i;
	}
	for(int i=x;i<=y;i++)a[i]-=mn;
	for(int i=2;i<=cnt;i++)mn+=calc(now[tot][i-1]+1,now[tot][i]-1,++res);
	return min(mn+calc(x,now[tot][1]-1,++res)+calc(now[tot][cnt]+1,y,++res),y-x+1);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	printf("%d",calc(1,n,0));
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5010;
int mx[N<<2],n,a[N];
void build(int l,int r,int rt){
    if(l==r){scanf("%d",&a[l]),mx[rt]=l;return;}
    int mid=l+r>>1;
    build(l,mid,rt<<1);build(mid+1,r,rt<<1|1);
    if(a[mx[rt<<1]]>a[mx[rt<<1|1]])mx[rt]=mx[rt<<1|1];
    else mx[rt]=mx[rt<<1];
}
int query(int l,int r,int L,int R,int rt){
    if(L<=l&&r<=R)return mx[rt];
    int mid=l+r>>1,ans=-1;
    if(L<=mid)ans=query(l,mid,L,R,rt<<1);
    if(mid<R){
        int x=query(mid+1,r,L,R,rt<<1|1);
        if(ans==-1)ans=x;
        else if(a[ans]>a[x])ans=x;
    }
    return ans;
}
ll solve(int l,int r,int val){
    if(l>r)return 0;
    if(l==r)return min(a[l]-val,1);
    int x=query(1,n,l,r,1);
    return min(solve(l,x-1,a[x])+solve(x+1,r,a[x])+a[x]-val,r-l+1ll);
}
int main() {
    scanf("%d",&n);
    build(1,n,1);
    printf("%lld\n",solve(1,n,0));
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
const int N = 1e6+10;;
const int mod=1e9+7;
int main()
{
    int n;scanf("%d",&n);
    stack<int>st;
    ll ans=0;
    for(int i=1;i<=n;i++){
        ll a;scanf("%lld",&a);
        while(!st.empty()&&st.top()>a){
            ans++;
            st.pop();
        }
        while(!st.empty()&&st.top()>=a)st.pop();
        st.push(a);
    }
    ll l=0,d=0;
    while(!st.empty()){
        if(st.top()==0)break;
        ans++;
        st.pop();
    }
    ans+=min(l,d);
    printf("%lld\n",ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
const int N = 1e6+10;;
const int mod=1e9+7;
int main()
{
    int n;scanf("%d",&n);
    stack<pii>st;
    ll ans=0;
    for(int i=1;i<=n;i++){
        ll a;scanf("%lld",&a);
        ll d=0,l=0;
        while(!st.empty()&&st.top().first>a){
            d+=st.top().second;
            l=max(l,st.top().first-a);
            st.pop();
        }
        ans+=min(l,d);
        st.push({a,d+1});
    }
    ll l=0,d=0;
    while(!st.empty()){
        d+=st.top().second;
        l=max(st.top().first,l);
        st.pop();
    }
    ans+=min(l,d);
    printf("%lld\n",ans);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 5e3 + 10;

int n, a[N];
vector<int>v[N];

int l[N], r[N], qu[N], tot;
void get_array_lr(int n, int ht[])
{
	ht[0] = ht[n + 1] = -1;
	tot = 0; qu[++tot] = 0;
	for (int i = 1; i <= n; i++)
	{
		while (tot && ht[i] <= ht[qu[tot]]) tot--;
		l[i] = qu[tot] + 1;
		qu[++tot] = i;
	}

	tot = 0; qu[++tot] = n + 1;
	for (int i = n; i >= 1; i--)
	{
		while (tot && ht[i] <= ht[qu[tot]]) tot--;
		r[i] = qu[tot] - 1;
		qu[++tot] = i;
	}

	ht[0] = ht[n + 1] = 0;
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);

	vector<int>p;
	p.push_back(0);
	for (int i = 1; i <= n; i++) p.push_back(a[i]);
	stable_sort(p.begin(), p.end());
	p.erase(unique(p.begin(),p.end()),p.end());
	for(int i=1;i<=n;i++)
	a[i]=lower_bound(p.begin(),p.end(),a[i])-p.begin();

	get_array_lr(n, a);

	int ans = 0;
	for (int i = 1; i <= n; i++) v[a[i]].push_back(i);
	for (int i = n; i >= 1; i--)
	{
		int rborder = 0;
		for (int j = 0; j < v[i].size(); j++)
		{
			if (r[v[i][j]] <= rborder) continue;
			rborder = r[v[i][j]];
			ans++;
		}
	}
	printf("%d\n", ans);

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

template<typename TH>
void _dbg(const char* sdbg, TH h)
{
	cerr << sdbg << " = " << h << "\n";
}

template<typename TH, typename... TA>
void _dbg(const char* sdbg, TH h, TA... t)
{
	while (*sdbg != ',') cerr << *sdbg++;
	cerr << " = " << h << ",";
	_dbg(sdbg + 1, t...);
}

#define db(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define chkpt cerr << "--- Checkpoint here ---\n";

const int N=3e5+5;
const int64_t LINF=4e18;

int n,k;
pair<int64_t,int> a[N];
int64_t s[N];

int main()
{
//    freopen("371E.INP","r",stdin);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	for(int i=1;i<=n;++i){
        cin>>a[i].first;
        a[i].second=i;
	}
	cin>>k;
	sort(a+1,a+1+n);
	for(int i=1;i<=n;++i){
        s[i]=s[i-1]+a[i].first;
	}
	int64_t len=0,sum=0,ans=LINF;
	int bestPos=0;
	auto AddTail=[&len,&sum,&s](int i){
        sum+=len*a[i].first-(s[i-1]-s[i-len-1]);
        len++;
	};
	auto RemoveHead=[&len,&sum](int i){
        sum-=(s[i+len-1]-s[i])-(len-1)*a[i].first;
        len--;
	};
	auto Update=[&sum,&ans,&bestPos](int i){
        if(ans>sum){
            ans=sum;
            bestPos=i;
        }
	};
	for(int i=1;i<=k;++i){
	    AddTail(i);
	}
	Update(1);
	for(int i=2;i<=n-k+1;++i){
        RemoveHead(i-1);
        AddTail(i+k-1);
        Update(i);
	}
	assert(bestPos>=1);
	for(int i=bestPos;i<=bestPos+k-1;++i){
        cout<<a[i].second<<' ';
	}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

template<typename TH>
void _dbg(const char* sdbg, TH h)
{
	cerr << sdbg << " = " << h << "\n";
}

template<typename TH, typename... TA>
void _dbg(const char* sdbg, TH h, TA... t)
{
	while (*sdbg != ',') cerr << *sdbg++;
	cerr << " = " << h << ",";
	_dbg(sdbg + 1, t...);
}

#define db(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define chkpt cerr << "--- Checkpoint here ---\n";

const int N=3e5+5;
const int64_t LINF=1e18;

int n,k;
pair<int64_t,int> a[N];
int64_t s[N];

int main()
{
//    freopen("371E.INP","r",stdin);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	for(int i=1;i<=n;++i){
        cin>>a[i].first;
        a[i].second=i;
	}
	cin>>k;
	sort(a+1,a+1+n);
	for(int i=1;i<=n;++i){
        s[i]=s[i-1]+a[i].first;
	}
	int64_t len=0,sum=0,ans=LINF;
	int bestPos=0;
	auto AddTail=[&len,&sum,&s](int i){
        sum+=len*a[i].first-(s[i-1]-s[i-len-1]);
        len++;
	};
	auto RemoveHead=[&len,&sum](int i){
        sum-=(s[i+len-1]-s[i])-(len-1)*a[i].first;
        len--;
	};
	auto Update=[&sum,&ans,&bestPos](int i){
        if(ans>sum){
            ans=sum;
            bestPos=i;
        }
	};
	for(int i=1;i<=k;++i){
	    AddTail(i);
	}
	Update(1);
	for(int i=2;i<=n-k+1;++i){
        RemoveHead(i-1);
        AddTail(i+k-1);
        Update(i);
	}
	for(int i=bestPos;i<=bestPos+k-1;++i){
        assert(i>=1);
        cout<<a[i].second<<' ';
	}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

template<typename TH>
void _dbg(const char* sdbg, TH h)
{
	cerr << sdbg << " = " << h << "\n";
}

template<typename TH, typename... TA>
void _dbg(const char* sdbg, TH h, TA... t)
{
	while (*sdbg != ',') cerr << *sdbg++;
	cerr << " = " << h << ",";
	_dbg(sdbg + 1, t...);
}

#define db(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define chkpt cerr << "--- Checkpoint here ---\n";

const int N=3e5+5;
const int64_t LINF=LLONG_MAX;

int n,k;
pair<int64_t,int> a[N];
int64_t s[N];

int main()
{
//    freopen("371E.INP","r",stdin);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	for(int i=1;i<=n;++i){
        cin>>a[i].first;
        a[i].second=i;
	}
	cin>>k;
	sort(a+1,a+1+n);
	for(int i=1;i<=n;++i){
        s[i]=s[i-1]+a[i].first;
	}
	int64_t len=0,sum=0,ans=LINF;
	int bestPos=0;
	auto AddTail=[&len,&sum,&s](int i){
        sum+=len*a[i].first-(s[i-1]-s[i-len-1]);
        len++;
	};
	auto RemoveHead=[&len,&sum](int i){
        sum-=(s[i+len-1]-s[i])-(len-1)*a[i].first;
        len--;
	};
	auto Update=[&sum,&ans,&bestPos](int i){
        if(ans>sum){
            ans=sum;
            bestPos=i;
        }
	};
	for(int i=1;i<=k;++i){
	    AddTail(i);
	}
	Update(1);
	for(int i=2;i<=n-k+1;++i){
        RemoveHead(i-1);
        AddTail(i+k-1);
        Update(i);
	}
	assert(bestPos>=1);
	for(int i=bestPos;i<=bestPos+k-1;++i){
        cout<<a[i].second<<' ';
	}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

template<typename TH>
void _dbg(const char* sdbg, TH h)
{
	cerr << sdbg << " = " << h << "\n";
}

template<typename TH, typename... TA>
void _dbg(const char* sdbg, TH h, TA... t)
{
	while (*sdbg != ',') cerr << *sdbg++;
	cerr << " = " << h << ",";
	_dbg(sdbg + 1, t...);
}

#define db(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define chkpt cerr << "--- Checkpoint here ---\n";

const int N=3e5+5;
const int64_t LINF=1e18;

int n,k;
pair<int64_t,int> a[N];
int64_t s[N];

int main()
{
//    freopen("371E.INP","r",stdin);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	for(int i=1;i<=n;++i){
        cin>>a[i].first;
        a[i].second=i;
	}
	cin>>k;
	sort(a+1,a+1+n);
	for(int i=1;i<=n;++i){
        s[i]=s[i-1]+a[i].first;
	}
	int64_t len=0,sum=0,ans=LINF;
	int bestPos=0;
	auto AddTail=[&len,&sum,&s](int i){
        sum+=len*a[i].first-(s[i-1]-s[i-len-1]);
        len++;
	};
	auto RemoveHead=[&len,&sum](int i){
        sum-=(s[i+len-1]-s[i])-(len-1)*a[i].first;
        len--;
	};
	auto Update=[&sum,&ans,&bestPos](int i){
        if(ans>sum){
            ans=sum;
            bestPos=i;
        }
	};
	for(int i=1;i<=k;++i){
	    AddTail(i);
	}
	Update(1);
	for(int i=2;i<=n-k+1;++i){
        RemoveHead(i-1);
        AddTail(i+k-1);
        Update(i);
	}
	assert(bestPos>=1);
	for(int i=bestPos;i<=bestPos+k-1;++i){
        cout<<a[i].second<<' ';
	}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

template<typename TH>
void _dbg(const char* sdbg, TH h)
{
	cerr << sdbg << " = " << h << "\n";
}

template<typename TH, typename... TA>
void _dbg(const char* sdbg, TH h, TA... t)
{
	while (*sdbg != ',') cerr << *sdbg++;
	cerr << " = " << h << ",";
	_dbg(sdbg + 1, t...);
}

#define db(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define chkpt cerr << "--- Checkpoint here ---\n";

const int N=3e5+5;
const int64_t LINF=1e18;

int n,k;
pair<int64_t,int> a[N];
int64_t s[N];

int main()
{
//    freopen("371E.INP","r",stdin);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	for(int i=1;i<=n;++i){
        cin>>a[i].first;
        a[i].second=i;
	}
	cin>>k;
	sort(a+1,a+1+n);
	for(int i=1;i<=n;++i){
        s[i]=s[i-1]+a[i].first;
	}
	int64_t len=0,sum=0,ans=LINF;
	int bestPos=0;
	auto AddTail=[&len,&sum,&s](int i){
        sum+=len*a[i].first-(s[i-1]-s[i-len-1]);
        len++;
	};
	auto RemoveHead=[&len,&sum](int i){
        sum-=(s[i+len-1]-s[i])-(len-1)*a[i].first;
        len--;
	};
	auto Update=[&sum,&ans,&bestPos](int i){
        if(ans>sum){
            ans=sum;
            bestPos=i;
        }
	};
	for(int i=1;i<=k;++i){
	    AddTail(i);
	}
	Update(1);
	if(n==300000){
        cout<<sum<<'\n';
	}
	for(int i=2;i<=n-k+1;++i){
        RemoveHead(i-1);
        AddTail(i+k-1);
        Update(i);
	}
//	assert(bestPos>=1);
	for(int i=bestPos;i<=bestPos+k-1;++i){
        cout<<a[i].second<<' ';
	}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

template<typename TH>
void _dbg(const char* sdbg, TH h)
{
	cerr << sdbg << " = " << h << "\n";
}

template<typename TH, typename... TA>
void _dbg(const char* sdbg, TH h, TA... t)
{
	while (*sdbg != ',') cerr << *sdbg++;
	cerr << " = " << h << ",";
	_dbg(sdbg + 1, t...);
}

#define db(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define chkpt cerr << "--- Checkpoint here ---\n";

const int N=3e5+5;
const int64_t LINF=1e18;

int n,k;
pair<int64_t,int> a[N];
int64_t s[N];

int main()
{
//    freopen("371E.INP","r",stdin);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	for(int i=1;i<=n;++i){
        cin>>a[i].first;
        a[i].second=i;
	}
	cin>>k;
	sort(a+1,a+1+n);
	for(int i=1;i<=n;++i){
        s[i]=s[i-1]+a[i].first;
	}
	int64_t len=0,sum=0,ans=LINF;
	int bestPos=0;
	auto AddTail=[&len,&sum,&s](int i){
        sum+=len*a[i].first-(s[i-1]-s[i-len-1]);
        len++;
	};
	auto RemoveHead=[&len,&sum](int i){
        sum-=(s[i+len-1]-s[i])-(len-1)*a[i].first;
        len--;
	};
	auto Update=[&sum,&ans,&bestPos](int i){
        if(ans>sum){
            ans=sum;
            bestPos=i;
        }
	};
	for(int i=1;i<=k;++i){
	    AddTail(i);
	}
	Update(1);
	for(int i=2;i<=n-k+1;++i){
        RemoveHead(i-1);
        AddTail(i+k-1);
        Update(i);
	}
	for(int i=bestPos;i<=bestPos+k-1;++i){
        cout<<a[i].second<<' ';
	}
    return 0;
}


/*
    Ujjawal Pabreja
*/
#include <bits/stdc++.h>
#include <functional>
using namespace std;
using ll = long long;
using ld = long double;
#define speed_cubing    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(i,a)        for(ll i = 0 ; i < a ; i++)
#define repe(i,a,b)     for(ll i = a ; i < b ; i++)
#define bac(i,a)        for(ll i = a ; i >= 0 ; i--)
#define bace(i,a,b)     for(ll i = a ; i >= b ; i--)
#define pb              push_back
#define mp              make_pair
#define in              insert
#define ff              first
#define ss              second
#define vv              vector
#define vll             vector <ll>
#define pll             pair <ll,ll>
#define vpll            vector <pll>
#define umap            unordered_map
#define uset            unordered_set
#define mset            multiset
#define pqueue          priority_queue
#define setbit(x)       __builtin_popcountll(x)
#define init(c,a)       memset(c,a,sizeof(c))
#define all(c)          c.begin(),c.end()
#define sz(c)           (ll)c.size()
#define lb              lower_bound
#define ub              upper_bound
#define maxe            *max_element
#define mine            *min_element
#define gcd(a,b)        __gcd(a,b)
#define rev             reverse
#define Y               "YES"
#define N               "NO"
#define nl              "\n"
#define debug(x)        cout << #x << " : " << x << nl;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll MOD = 998244353;
const ll MAX = 2e5 + 1;

// ====== int_1024t begins ======
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// ====== int_1024t ends ======

// ====== pbds begins ======
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag,
//         tree_order_statistics_node_update>
//         pbds;
// ====== pbds ends ======

// ====== Useful functions begin ======
inline ll add(ll a,ll b) {return ((a%mod)+(b%mod))%mod;}
inline ll sub(ll a,ll b) {return ((a%mod)-(b%mod)+mod)%mod;}
inline ll mul(ll a,ll b) {return ((a%mod)*(b%mod))%mod;}
ll pwr(ll x,ll n){
    if(!n) return 1;
    if(n&1) return mul(x, pwr(mul(x,x),(n-1)/2));
    else return pwr(mul(x,x),n/2);
}
ll modinv(ll n){
    return pwr(n,mod - 2);
}
// ====== Useful functions end ======

// ====== Variables begin ======

// ====== Variables end ======
void speed_solve(){
    ll n;
    cin >> n;
    pll a[n];
    rep(i,n){
        cin >> a[i].ff;
        a[i].ss = i + 1;
    }
    ll k;
    cin >> k;
    sort(a,a + n);
    ll mn = inf, idx = -1;
    ll pre[n];
    pre[0] = a[0].ff;
    repe(i,1,n){
        pre[i] = pre[i - 1] + a[i].ff;
    }
    ll sum = 0;
    repe(i,1,k){
        sum += (a[i].ff * i) - pre[i - 1];
    }
    idx = 0, mn = sum;
    set <ll> s;
    repe(i,k,n){
        sum = sum - 2 * (pre[i - 1] - pre[i - k]) + (k - 1) * (a[i].ff + a[i - k].ff);
        if(sum <= mn){
            mn = sum;
            idx = i - k + 1;
        }
    }
    repe(i,idx,idx + k){
        s.in(a[i].ss);
    }
    for(auto it : s){
        cout << it << " ";
    }
}
int main()
{
    speed_cubing;
    ll test_cases = 1;
    // cin >> test_cases;
    rep(i,test_cases){
        // cout << "Case #" << i + 1 << ": ";
        speed_solve();
    }
    return 0;
}


#include <bits/stdc++.h>

#define int long long

using namespace std;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int t[n];
    vector<int> v;
    for (int i = 0; i < n; i++) {
        cin >> t[i];
        v.push_back(t[i]);
    }
    sort(v.begin(), v.end());
    int k;
    cin >> k;
    int cur = 0;
    int sumDist = 0;
    for (int i = 0; i < k; i++) {
        cur += i*v[i] - sumDist;
        sumDist += v[i];
    }
    int best = cur;
    int l = v[0];
    int r = v[k-1];
    for (int i = k; i < n; i++) {
        sumDist -= v[i-k];
        cur += (k-1)*v[i-k] - sumDist;
        cur += (k-1)*v[i] - sumDist;
        sumDist += v[i];
        if (cur < best) {
            best = cur;
            l = v[i-k+1];
            r = v[i];
        }
    }
    for (int i = 0; i < n; i++) if (t[i] >= l && t[i] <= r) cout << (i+1) << ' ';
    cout << '\n';
}
/*

 */


#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, k;
	cin >> n;
	vector<long long> a(n), s(n, 0);
	for(int i = 0; i < n; ++i) cin >> a[i];
	cin >> k;

	sort(a.begin(), a.end());
	for(int i = 0; i < n; ++i) s[i] = a[i] + (i ? s[i - 1] : 0);

	long long suma = 0, ans;
	int lo = 1, hi = k;
	for(int i = 0, vz = k - 1; i < k; ++i, vz--){
		long long sumo = a[i]*i;
		long long resto = a[i]*vz;
		suma+= (sumo - resto);
	}
	ans = suma;
	for(int i = k; i < n; ++i){

		suma+=( (k-1)*a[i - k] );
		long long rango = (s[i - 1] - s[i - k])*2;
		suma-= rango;

		suma+= (a[i]*(k - 1));

		if(suma < ans){
			ans = suma;
			lo = i - k + 2, hi = i + 1;
		}
	}
	cout << lo << ' ' << hi << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, k;
	cin >> n;
	vector<long long> s(n, 0);
	vector<pair<long long, int>> a(n);
	for(int i = 0; i < n; ++i){
		cin >> a[i].first;
		a[i].second = i + 1;
	}
	cin >> k;

	sort(a.begin(), a.end());
	for(int i = 0; i < n; ++i) s[i] = a[i].first + (i ? s[i - 1] : 0);

	long long suma = 0, ans;
	int lo = 0, hi = k - 1;
	for(int i = 0, vz = k - 1; i < k; ++i, vz--){
		long long sumo = a[i].first*i;
		long long resto = a[i].first*vz;
		suma+= (sumo - resto);
	}
	ans = suma;
	for(int i = k; i < n; ++i){

		suma+=( (k-1)*a[i - k].first );
		long long rango = (s[i - 1] - s[i - k])*2;
		suma-= rango;

		suma+= (a[i].first*(k - 1));

		if(suma < ans){
			ans = suma;
			lo = i - k + 1, hi = i;
		}
	}
	for(int i = lo; i <= hi; ++i) cout << a[i].second << ' ';

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, k;
	cin >> n;
	vector<long long> a(n), s(n, 0);
	for(int i = 0; i < n; ++i) cin >> a[i];
	cin >> k;

	sort(a.begin(), a.end());
	for(int i = 0; i < n; ++i) s[i] = a[i] + (i ? s[i - 1] : 0);

	long long suma = 0, ans;
	int lo = 1, hi = k;
	for(int i = 0, vz = k - 1; i < k; ++i, vz--){
		long long sumo = a[i]*i;
		long long resto = a[i]*vz;
		suma+= (sumo - resto);
	}
	ans = suma;
	for(int i = k; i < n; ++i){

		suma+=( (k-1)*a[i - k] );
		long long rango = (s[i - 1] - s[i - k])*2;
		suma-= rango;

		suma+= (a[i]*(k - 1));

		if(suma < ans){
			ans = suma;
			lo = i - k + 2, hi = i + 1;
		}
	}
	for(int i = lo; i <= hi; ++i) cout << i << ' ';

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ll n,k;
    cin>>n;
    ll arr[n],pre[n+1]={0};
    for(ll i=0;i<n;i++)
    cin>>arr[i];
    cin>>k;
    sort(arr,arr+n);
    for(ll i=0;i<n;i++)
    pre[i+1]=pre[i]+arr[i];
    ll sum=(k-1)*(arr[k-1]-arr[0]);
    for(ll i=1;i<k-1;i++)
    sum+=arr[i]*(2*(i+1)-k+1);
    ll res=sum,temp=1;
    for(ll i=0;i<n-k+1;i++){
        if(res>sum){
            res=sum;
            temp=i+1;
        }
        sum+=(k-1)*(arr[i+k]+arr[i])-2*(pre[i+k]-pre[i+1]);
    }
    for(ll i=temp;i<temp+k;i++)
    cout<<i<<" ";
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ll n,k;
    cin>>n;
    ll arr[n],pre[n+1]={0};
    for(ll i=0;i<n;i++)
    cin>>arr[i];
    cin>>k;
    sort(arr,arr+n);
    for(ll i=0;i<n;i++)
    pre[i+1]=pre[i]+arr[i];
    ll sum=(k-1)*(arr[k-1]-arr[0]);
    for(ll i=1;i<k-1;i++)
    sum+=arr[i]*(2*(i+1)-k+1);
    ll res=sum,temp=1;
    for(ll i=0;i<n-k+1;i++){
        if(res>sum){
            res=sum;
            temp=i+1;
        }
        sum+=(k-1)*(arr[i+k]+arr[i])-2*(pre[i+k]-pre[i+1]);
    }
    cout<<temp<<" "<<temp+k-1;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ll n,k;
    cin>>n;
    ll arr[n],pre[n+1]={0};
    map<ll,ll> m;
    for(ll i=0;i<n;i++){
        cin>>arr[i];
        m.insert({arr[i],i+1});
    }
    cin>>k;
    sort(arr,arr+n);
    for(ll i=0;i<n;i++)
    pre[i+1]=pre[i]+arr[i];
    ll sum=(k-1)*(arr[k-1]-arr[0]);
    for(ll i=1;i<k-1;i++)
    sum+=arr[i]*(2*(i+1)-k+1);
    ll res=sum,temp=0;
    for(ll i=0;i<n-k+1;i++){
        if(res>sum){
            res=sum;
            temp=i;
        }
        sum+=(k-1)*(arr[i+k]+arr[i])-2*(pre[i+k]-pre[i+1]);
    }
    for(ll i=temp;i<temp+k;i++)
    cout<<m[arr[i]]<<" ";
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>

#define pb push_back
#define int long long
#define ld long double
using namespace std;
const int M = 1000000007;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    vector<pair<int, int>> X(n);
    for (int i = 0; i < n; i++) {
        cin >> X[i].first;
        X[i].second = i;
    }
    int k;
    cin >> k;
    sort(X.begin(), X.end());
    int answ = 0;
    int justxsum = 0;
    for (int i = 0; i < k; i++) {
        justxsum += X[i].first;
        answ += X[i].first * (2 * i - k + 1);
    }
    int suum = answ;
    int ind = 0;
    for (int i = 0; i < n - k; i++) {
        suum -= X[i].first * (-k + 1);
        justxsum -= X[i].first;
        suum -= justxsum * 2;
        suum += X[i + k].first * (k - 1);
        justxsum += X[i + k].first;
        if (suum < answ) {
            answ = suum;
            ind = i+1;
        }
    }
    for (int i = ind; i < ind + k; i++) {
        cout << X[i].second + 1 << ' ';
    }
}


#include <bits/stdc++.h>
#include <chrono>

using namespace std;
using namespace std::chrono;

// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
// #pragma optimization_level 3
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define f0r(a, b) for (long long a = 0; a < (b); ++a)
#define f1r(a, b, c) for (long long a = (b); a < (c); ++a)
#define f0rd(a, b) for (long long a = (b); a >= 0; --a)
#define f1rd(a, b, c) for (long long a = (b); a >= (c); --a)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define pb push_back
#define send {ios_base::sync_with_stdio(false);}
#define help {cin.tie(NULL); cout.tie(NULL);}
#define fix(prec) {cout << setprecision(prec) << fixed;}
#define mp make_pair
#define f first
#define s second
#define presum(p, a, n) {p[0] = a[0]; for (int i = 1; i < (n); i++) p[i] = a[i] + p[i-1];}
#define all(v) v.begin(), v.end()
#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}
#define readgraph(list, edges) for (int i = 0; i < edges; i++) {int a, b; cin >> a >> b; a--; b--; list[a].pb(b); list[b].pb(a);}
#define ai(a, n) for (int ele = 0; ele < n; ele++) cin >> a[ele];
#define ain(a, lb, rb) for (int ele = lb; ele <= rb; ele++) cin >> a[ele];
#define ao(a, n) {for (int ele = 0; ele < (n); ele++) { if (ele) cout << " "; cout << a[ele]; } cout << '\n';}
#define aout(a, lb, rb) {for (int ele = (lb); ele <= (rb); ele++) { if (ele > (lb)) cout << " "; cout << a[ele]; } cout << '\n';}
#define bl __int128
typedef long long ll;
typedef double ld;
typedef long double lld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
  cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
  cin >> p.first;
  return cin >> p.second;
}

// template<typename A, typename B> ll max(A x, B y) {
//   return x > y ? x : y;
// }
// template<typename A, typename B> ll min(A x, B y) {
//   return x < y ? x : y;
// }

// mt19937 rng(steady_clock::now().time_since_epoch().count());
mt19937 rng(61378913);
/* usage - just do rng() */

void usaco(string filename) {
  // #pragma message("be careful, freopen may be wrong")
	freopen((filename + ".in").c_str(), "r", stdin);
	freopen((filename + ".out").c_str(), "w", stdout);
}

const lld pi = 3.14159265358979323846;
const ll mod = 1000000007;
// const ll mod = 998244353;
// ll mod;

ll n, m, k, q, l, r, x, y, z;
ll a[1000005];
ll b[1000005];
ll c[1000005];
string s, t;
ll ans = 0;

pair<ll, int> locs[300005];

void solve(int tc) {
  cin >> n;
  f0r(i, n) {
    cin >> x;
    locs[i].f = x;
    locs[i].s = i + 1;
  }
  sort(locs, locs + n);
  cin >> k;

  bl s = 0, run = 0, loc = 0, best = 0;

  f0r(i, k) {
    best += locs[i].f * i - s;
    s += locs[i].f;
  }
  run = best;

  f0r(i, n - k) {
    run += locs[i + k].f * k - s;
    s += locs[i + k].f;
    run -= s - locs[i].f * (k + 1);
    s -= locs[i].f;
    if (run < best) {
      best = run;
      loc = i + 1;
    }
  }

  f1r(i, loc, loc + k) cout << locs[i].s << " ";
  cout << '\n';
}

int main() {
  send help

  // usaco("file");

  int tc;
  tc = 1;
  // cin >> tc;
  for (int t = 0; t < tc; t++) solve(t);
}


#include<iostream>
#include<set>
#include<map>
#include<functional>
#include<queue>
#include<string.h>
#include<stdio.h>
#include<iomanip>
#include<stdlib.h>
#include<math.h>
#include<cstdlib>
#include<vector>
#include<random>
#include<algorithm>
#include<string>
#include<stack>
#include<queue>
#include<list>
#include<bitset>
#include<assert.h>
#include<fstream>
typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
#define rep(i,a,b) for (int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define sz(a) (int)a.size()
#define sqr(x) ((x) * (x))
#define pi pair<ll, ll>
#define mk(a, b) make_pair(a, b)
#define nextI nextInt()
#define nextD nextDouble()
#define nextL nextLong()
#define nextC nextChar()
#define line newLine()
#define lf(x) (2 * x + 1)
#define ri(x) (2 * x + 2)
int nextInt(){ int x; scanf("%d", &x); return x; }
double nextDouble(){ double x; scanf("%lf", &x); return x; }
ll nextLong(){ ll x; scanf("%I64d", &x); return x; }
char nextChar(){ char x; scanf("%c", &x); return x; }
void newLine(){ printf("\n"); }
ll gcd(ll a, ll b){ return b == 0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b){ return (a*b) / gcd(a, b); }
ll powM(ll a, ll b, ll MOD){ ll x = 1, y = a; while (b > 0){ if (b % 2 == 1){ x = (x*y); if (x>MOD) x %= MOD; }y = (y*y); if (y>MOD) y %= MOD; b /= 2; }return x; }
ll ModExp(ll n, ll k, ll MOD){ ll ans = 1; while (k > 0){ if (k & 1) ans = (ans * n) % MOD; n = (n * n) % MOD; k /= 2; } return ans; }
ll Exp(ll n, ll k){ ll ans = 1; while (k > 0){ if (k & 1) ans = (ans * n); n = (n * n); k /= 2; } return ans; }
int countSetBits(ll n){ int ans = 0;  while (n != 0){ n -= (n & -n); ++ans; } return ans; }
ll mod = ll(1e9 + 7);
ll mod2 = ll(1e9 + 9);
const int N = 300100;
const int M = 100100;
const ll INF = 4e18;
const double EPS = 1e-9;
const LD PI = 2 * acos(0);
using namespace std;
const int LOG = 18;
ll a[N];
int n, k;
vector<pair<ll, int> > v;
ll ans = INF, current = 0, sub = 0;
int l = 0;

void add(int i) {
	ll sz = 1ll * (i - l);
	ll sum = (a[i] - a[0]) * sz;
	sum -= sub;
	current += sum;
	sub += (a[i] - a[0]);
}

void remove(int i, int j) {
	ll sz = 1ll * (i - j);
	sub -= (a[j] - a[0]);
	ll sum = sub - (sz * (a[j] - a[0]));
	current -= sum;
	l++;
}
int start;
int main(){
#ifdef HOME
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 0; i < n; i++) {
		ll x;
		cin >> x;
		v.push_back(mk(x, i));
	}
	sort(all(v));
	for (int i = 0; i < n; i++) {
		a[i] = v[i].first;
	}
	cin >> k;
	sort(a, a + n);
	for (int i = 0; i < n; i++) {
		add(i);
		if (i - l  + 1> k) {
			remove(i, l);
		}

		if (i - l + 1 == k) {
			if (ans > current) {
				ans = current;
				start = l;
			}
		}
	}

	for (int i = 0; i < k; i++) {
		cout << v[i + start].second + 1 << " ";
	}
	cout << endl;
	return 0;
}


#include<iostream>
#include<set>
#include<map>
#include<functional>
#include<queue>
#include<string.h>
#include<stdio.h>
#include<iomanip>
#include<stdlib.h>
#include<math.h>
#include<cstdlib>
#include<vector>
#include<random>
#include<algorithm>
#include<string>
#include<stack>
#include<queue>
#include<list>
#include<bitset>
#include<assert.h>
#include<fstream>
typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
#define rep(i,a,b) for (int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define sz(a) (int)a.size()
#define sqr(x) ((x) * (x))
#define pi pair<ll, ll>
#define mk(a, b) make_pair(a, b)
#define nextI nextInt()
#define nextD nextDouble()
#define nextL nextLong()
#define nextC nextChar()
#define line newLine()
#define lf(x) (2 * x + 1)
#define ri(x) (2 * x + 2)
int nextInt(){ int x; scanf("%d", &x); return x; }
double nextDouble(){ double x; scanf("%lf", &x); return x; }
ll nextLong(){ ll x; scanf("%I64d", &x); return x; }
char nextChar(){ char x; scanf("%c", &x); return x; }
void newLine(){ printf("\n"); }
ll gcd(ll a, ll b){ return b == 0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b){ return (a*b) / gcd(a, b); }
ll powM(ll a, ll b, ll MOD){ ll x = 1, y = a; while (b > 0){ if (b % 2 == 1){ x = (x*y); if (x>MOD) x %= MOD; }y = (y*y); if (y>MOD) y %= MOD; b /= 2; }return x; }
ll ModExp(ll n, ll k, ll MOD){ ll ans = 1; while (k > 0){ if (k & 1) ans = (ans * n) % MOD; n = (n * n) % MOD; k /= 2; } return ans; }
ll Exp(ll n, ll k){ ll ans = 1; while (k > 0){ if (k & 1) ans = (ans * n); n = (n * n); k /= 2; } return ans; }
int countSetBits(ll n){ int ans = 0;  while (n != 0){ n -= (n & -n); ++ans; } return ans; }
ll mod = ll(1e9 + 7);
ll mod2 = ll(1e9 + 9);
const int N = 300100;
const int M = 100100;
const ll INF = 1e18;
const double EPS = 1e-9;
const LD PI = 2 * acos(0);
using namespace std;
const int LOG = 18;
ll a[N];
int n, k;
vector<pair<ll, int> > v;
ll ans = INF, current = 0, sub = 0;
int l = 0;

void add(int i) {
	ll sz = 1ll * (i - l);
	ll sum = (a[i] - a[0]) * sz;
	sum -= sub;
	current += sum;
	sub += (a[i] - a[0]);
}

void remove(int i, int j) {
	ll sz = 1ll * (i - j);
	sub -= (a[j] - a[0]);
	ll sum = sub - (sz * (a[j] - a[0]));
	current -= sum;
	l++;
}
int start;
int main(){
#ifdef HOME
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 0; i < n; i++) {
		ll x;
		cin >> x;
		v.push_back(mk(x, i));
	}
	sort(all(v));
	for (int i = 0; i < n; i++) {
		a[i] = v[i].first;
	}
	cin >> k;
	sort(a, a + n);
	for (int i = 0; i < n; i++) {
		add(i);
		if (i - l  + 1> k) {
			remove(i, l);
		}

		if (i - l + 1 == k) {
			if (ans > current) {
				ans = current;
				start = l;
			}
		}
	}

	for (int i = 0; i < k; i++) {
		cout << v[i + start].second + 1 << " ";
	}
	cout << endl;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>
#include <cctype>
#include <list>
#include <assert.h>
#include <random>
typedef long long ll;
#define MAX 300105
using namespace std;
#define INF 2147483647
#define infL (1LL<<60)
#define inf (1<<30)
#define MOD 1000000007
#define EPS 1e-9
#define Gr 9.8
#define PI acos(-1)
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REQ(i,n) for(int (i)=1;(i)<=(int)(n);(i)++)
#define lch (rt<<1)
#define rch (rt<<1|1)
bool debug = 1;
int n,m, k;
//int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
ll ln, lk, lm;

pair<int, int> x[MAX];
ll l[MAX],r[MAX], sl[MAX], sr[MAX];
int main(){
    scanf("%d", &n);
    REQ(i,n) {
        scanf("%d", &x[i].first); x[i].second=i;
    }
    scanf("%d", &k);
    sort(x+1,x+1+n);
//    REQ(i,n) sx[i] = sx[i-1] + x[i].first;

    REQ(i,k) {
        l[i] = (ll)(i-1) * (x[i].first - x[i-1].first) + l[i-1];
    }
    for(int i=k+1;i<=n;i++) {
        ll tmp = l[i-1] - (x[i-1].first - x[i-1 - k+1].first);
        l[i] = (ll)(k-1) * (x[i].first - x[i-1].first) + tmp;
    }

    for(int i=n-1;i>n-k;i--) {
        r[i] = (ll)(n-i) * (x[i+1].first - x[i].first) + r[i+1];
    }
    for(int i=n-k;i>0;i--) {
        ll tmp = r[i+1] - (x[i+k].first - x[i+1].first);
        r[i] = (ll)(k-1) * (x[i+1].first - x[i].first) + tmp;
    }

    int st=1; ll tt=0;
    for(int i=2;i<=k;i++) tt+=l[i];
    ll minT = tt;
    for(int i=2;i+k-1<=n;i++) {
        tt = tt - r[i-1] + l[i+k-1];
        //cout<<tt<<" "<<r[i-1]<<" "<<l[i+k-1]<<" "<<tmp<<endl;
        assert(tt>0);
        if (tt < minT) {
            minT = tt; st=i;
        }
    }
    for(int i=st,j=0;j<k;i++,j++) printf("%d ", x[i].second);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>
#include <cctype>
#include <list>
#include <assert.h>
#include <random>
typedef long long ll;
#define MAX 300105
using namespace std;
#define INF 2147483647
#define infL (1LL<<60)
#define inf (1<<30)
#define MOD 1000000007
#define EPS 1e-9
#define Gr 9.8
#define PI acos(-1)
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REQ(i,n) for(int (i)=1;(i)<=(int)(n);(i)++)
#define lch (rt<<1)
#define rch (rt<<1|1)
bool debug = 1;
int n,m, k;
//int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
ll ln, lk, lm;

pair<int, int> x[MAX];
ll l[MAX],r[MAX], sl[MAX], sr[MAX];
int main(){
    scanf("%d", &n);
    REQ(i,n) {
        scanf("%d", &x[i].first); x[i].second=i;
    }
    scanf("%d", &k);
    sort(x+1,x+1+n);
    REQ(i,n) {
        l[i] = (ll)(i-1) * (x[i].first - x[i-1].first) + l[i-1];
    }
    for(int i=n-1;i;i--) {
        r[i] = (ll)(n-i) * (x[i+1].first - x[i].first) + r[i+1];
    }
    REQ(i,n) sl[i] = sl[i-1] + r[i]+l[i];
    for(int i=n;i;i--) {
        sr[i] = sr[i+1]+ r[i]+l[i];
    }
    int st=0; ll tt=0;
    for(int i=0;i+k<=n;i++) {
        ll tmp = sl[i] + sr[i+k+1];
        if (tmp > tt) {
            tt = tmp; st=i+1;
        }
    }
    for(int i=st,j=0;j<k;i++,j++) printf("%d ", x[i].second);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>
#include <cctype>
#include <list>
#include <assert.h>
#include <random>
typedef long long ll;
#define MAX 300105
using namespace std;
#define INF 2147483647
#define infL (1LL<<60)
#define inf (1<<30)
#define MOD 1000000007
#define EPS 1e-9
#define Gr 9.8
#define PI acos(-1)
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REQ(i,n) for(int (i)=1;(i)<=(int)(n);(i)++)
#define lch (rt<<1)
#define rch (rt<<1|1)
bool debug = 1;
int n,m, k;
//int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
ll ln, lk, lm;

pair<int, int> x[MAX];
ll l[MAX],r[MAX], sl[MAX], sr[MAX];
int main(){
    scanf("%d", &n);
    REQ(i,n) {
        scanf("%d", &x[i].first); x[i].second=i;
    }
    scanf("%d", &k);
    sort(x+1,x+1+n);
//    REQ(i,n) sx[i] = sx[i-1] + x[i].first;

    REQ(i,k) {
        l[i] = (ll)(i-1) * (x[i].first - x[i-1].first) + l[i-1];
    }
    for(int i=k+1;i<=n;i++) {
        ll tmp = l[i-1] - (x[i-1].first - x[i-1 - k+1].first);
        l[i] = (ll)(k-1) * (x[i].first - x[i-1].first) + tmp;
    }

    for(int i=n-1;i>n-k;i--) {
        r[i] = (ll)(n-i) * (x[i+1].first - x[i].first) + r[i+1];
    }
    for(int i=n-k;i>0;i--) {
        ll tmp = r[i+1] - (x[i+k].first - x[i+1].first);
        r[i] = (ll)(k-1) * (x[i+1].first - x[i].first) + tmp;
    }

    int st=1; ll tt=0;
    for(int i=2;i<=k;i++) tt+=l[i];
    for(int i=2;i+k-1<=n;i++) {
        ll tmp = tt - r[i-1] + l[i+k-1];
        if (tmp < tt) {
            tt = tmp; st=i;
        }
    }
    for(int i=st,j=0;j<k;i++,j++) printf("%d ", x[i].second);
    return 0;
}


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

#define INF 1000000000000000000
typedef long long int ll;
int main(){

    ll n;
    cin>>n;
    vector <pair<ll ,ll>> arr(n);
    ll a[n];
    for(ll i=0;i<n;++i) {ll tmp1;
        cin>>tmp1;
        arr[i]={tmp1,i+1};
    }
    ll k; cin>>k;

    sort(arr.begin(),arr.end());
    ll l=0,r=1,sum=0;
    pair<ll,ll> ans={INF,INF};
    while(l<n-k+1){
        while(r-l+1<=k){
           // cout<<arr[r].first<<"))";
            sum=sum+(arr[r].first-arr[r-1].first)*(k-1);
             //     cout<<sum<<"%%";
            r++;
        }

       // cout<<sum<<"**";
        ans.first=min(ans.first,sum);
        if(ans.first==sum) ans.second=l;
     //  a[l]=sum;

        sum-=(arr[l+1].first-arr[l].first)*(k-1);
        l++;

    }

   // cout<<ans.second<<"^^";
    ll i=0;
    for(vector<pair<ll,ll>> ::iterator it=arr.begin()+ans.second;i<k;++it,++i)
       cout<<it->second<<" ";//<<it->first<<"((";

return 0;}


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

int n, k;
pair<int64_t, int> arr[3 * 100000 + 5];
int64_t cum[3 * 100000 + 5];

void read_input()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> arr[i].first;
		arr[i].second = i;
	}
	cin >> k;

	sort(arr + 1, arr + n + 1, [](const auto &a, const auto &b) {
		return a.first < b.first;
	});

	cum[0] = 0;
	for (int i = 1; i <= n; i++)
		cum[i] = arr[i].first + cum[i - 1];
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cerr.tie(0);
	read_input();

	int64_t sum = 0;
	int l = 1, r = 2;
	while (r <= k)
	{
		sum += arr[r].first * (r - l) - (cum[r - 1] - cum[l - 1]);
		r++;
	}

	int64_t ans = sum;
	int start = l, end = r - 1;

	while (r <= n)
	{
		sum -= (cum[r - 1] - cum[l] - arr[l].first * (r - 1 - l));
		l++;
		sum += (arr[r].first * (r - l) - (cum[r - 1] - cum[l - 1]));

		if (sum < ans)
		{
			ans = sum;
			start = l;
			end = r;
		}

		r++;
	}

	for (int i = start; i <= end; i++)
		cout << arr[i].second << " ";
	cout << "\n";

	return 0;
}


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

#define INF 1000000000000000000
typedef long long int ll;
int main(){

    ll n;
    cin>>n;
    vector <pair<ll ,ll>> arr(n);
    ll a[n];
    for(ll i=0;i<n;++i) {ll tmp1;
        cin>>tmp1;
        arr[i]={tmp1,i+1};
    }
    ll k; cin>>k;

    sort(arr.begin(),arr.end());
    ll l=0,r=1,sum=0;
    pair<ll,ll> ans={INF,INF};
    while(l<n-k+1){
        while(r-l+1<=k){
           // cout<<arr[r].first<<"))";
            sum=sum+arr[r].first-arr[r-1].first;
             //     cout<<sum<<"%%";
            r++;
        }

        sum=sum*(k-1);

        ans.first=min(ans.first,sum);
        if(ans.first==sum) ans.second=l;
     //  a[l]=sum;

        sum-=arr[l+1].first-arr[l].first;
        l++;

    }

   // cout<<ans.second<<"^^";
    ll i=0;
    for(vector<pair<ll,ll>> ::iterator it=arr.begin()+ans.second;i<k;++it,++i)
       cout<<it->second<<" ";//<<it->first<<"((";

return 0;}


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

#define INF 1000000000000000000
typedef long long int ll;
int main(){

    ll n;
    cin>>n;
    vector <pair<ll ,ll>> arr(n+1);
    ll a[n];
    for(ll i=0;i<n;++i) {ll tmp1;
        cin>>tmp1;
        arr[i+1]={tmp1,i+1};
    }
    ll k; cin>>k;

    sort(arr.begin()+1,arr.end());
   // for(vector<pair<ll,ll>> ::iterator it=arr.begin();it!=arr.end();++it) cout<<it->first;
    a[0]=0;
    for(ll j=1;j<=n;++j) a[j]=a[j-1]+arr[j].first;

    ll l=1,r=2,sum=0;
    pair<ll,ll> ans={INF,INF};
   while(l<=n-k+1){
       while(r-l+1<=k&&r<=n){
        //   cout<<arr[r].first<<"(("<<a[r-1]-a[l-1]<<"))";
           sum=sum+arr[r].first*(r-l)-(a[r-1]-a[l-1]);
           r++;
          //   cout<<sum<<"**";
       }

       ans.first=min(ans.first,sum);
       if(ans.first==sum) ans.second=l;
       sum+=(arr[l].first*(r-l-1)-(a[r-1]-a[l]));
    //   cout<<sum<<"&&";
       l++;

   }

  //cout<<ans.second<<"^^";
    ll i=0;
    for(vector<pair<ll,ll>> ::iterator it=arr.begin()+ans.second;i<k;++it,++i)
       cout<<it->second<<" ";//<<it->first<<"((";

return 0;}


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

#define INF 1000000000000000000
typedef int64_t ll;
int main(){

    ll n;
    cin>>n;
    vector <pair<ll ,ll>> arr(n+1);
    ll a[n];
    for(ll i=0;i<n;++i) {ll tmp1;
        cin>>tmp1;
        arr[i+1]={tmp1,i+1};
    }
    ll k; cin>>k;

    sort(arr.begin()+1,arr.end());
   // for(vector<pair<ll,ll>> ::iterator it=arr.begin();it!=arr.end();++it) cout<<it->first;
    a[0]=0;
    for(ll j=1;j<=n;++j) a[j]=a[j-1]+arr[j].first;

    ll l=1,r=2,sum=0;
    pair<ll,ll> ans={INF,INF};
   while(l<=n-k+1){
       while(r-l+1<=k&&r<=n){
        //   cout<<arr[r].first<<"(("<<a[r-1]-a[l-1]<<"))";
           sum=sum+arr[r].first*(r-l)-(a[r-1]-a[l-1]);
           r++;
          //   cout<<sum<<"**";
       }

       ans.first=min(ans.first,sum);
       if(ans.first==sum) ans.second=l;
       sum+=(arr[l].first*(r-l-1)-(a[r-1]-a[l]));
    //   cout<<sum<<"&&";
       l++;

   }

  //cout<<ans.second<<"^^";
    ll i=0;
    for(vector<pair<ll,ll>> ::iterator it=arr.begin()+ans.second;i<k;++it,++i)
       cout<<it->second<<" ";//<<it->first<<"((";

return 0;}


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

#define INF 1000000000000000000
typedef long long int ll;
int main(){

    ll n;
    cin>>n;
    vector <pair<ll ,ll>> arr(n+1);
    ll a[n];
    for(ll i=0;i<n;++i) {ll tmp1;
        cin>>tmp1;
        arr[i+1]={tmp1,i+1};
    }
    ll k; cin>>k;

    sort(arr.begin()+1,arr.end());
   // for(vector<pair<ll,ll>> ::iterator it=arr.begin();it!=arr.end();++it) cout<<it->first;
    a[0]=0;
    for(ll j=1;j<=n;++j) a[j]=a[j-1]+arr[j].first;

    double sum=0;
    ll l=1,r=2;
    pair<double,ll> ans={INF,INF};
   while(l<=n-k+1){
       while(r-l+1<=k&&r<=n){
        //   cout<<arr[r].first<<"(("<<a[r-1]-a[l-1]<<"))";
           sum=sum+arr[r].first*(r-l)-(a[r-1]-a[l-1]);
           r++;
          //   cout<<sum<<"**";
       }
       sum=2*sum/((k)*(k-1));
       ans.first=min(ans.first,sum);
       if(ans.first==sum) ans.second=l;
       sum+=(arr[l].first*(r-l-1)-(a[r-1]-a[l]));
    //   cout<<sum<<"&&";
       l++;

   }

  //cout<<ans.second<<"^^";
    ll i=0;
    for(vector<pair<ll,ll>> ::iterator it=arr.begin()+ans.second;i<k;++it,++i)
       cout<<it->second<<" ";//<<it->first<<"((";

return 0;}


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

#define INF 1000000000000000000
typedef long long int ll;
int main(){

    ll n;
    cin>>n;
    vector <pair<ll ,ll>> arr(n+1);
    ll a[n];
    for(ll i=0;i<n;++i) {ll tmp1;
        cin>>tmp1;
        arr[i]={tmp1,i+1};
    }
    ll k; cin>>k;

    sort(arr.begin(),arr.end());
    a[0]=0;
    for(ll j=1;j<=n;++j) a[j]=a[j-1]+arr[j].first;

    ll l=1,r=2,sum=0;
    pair<ll,ll> ans={INF,INF};
   while(l<=n-k+1){
       while(r-l+1<=k&&r<=n){
           sum+=arr[r].first*(r-l)-(a[r-1]-a[l-1]);
           r++;

       }
    //   cout<<sum<<"**";
       ans.first=min(ans.first,sum);
       if(ans.first==sum) ans.second=l;
       sum+=(arr[l].first*(r-l-1)-(a[r-1]-a[l]));
     //  cout<<sum<<"&&";
       l++;

   }

 //  cout<<ans.second<<"^^";
    ll i=0;
    for(vector<pair<ll,ll>> ::iterator it=arr.begin()+ans.second;i<k;++it,++i)
       cout<<it->second<<" ";//<<it->first<<"((";

return 0;}


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

#define INF 1000000000000000000
typedef long long int ll;
int main(){

    ll n;
    cin>>n;
    vector <pair<ll ,ll>> arr(n+1);
  unsigned long long int a[n];
    for(ll i=0;i<n;++i) {ll tmp1;
        cin>>tmp1;
        arr[i]={tmp1,i+1};
    }
    ll k; cin>>k;

    sort(arr.begin(),arr.end());
    a[0]=0;
    for(ll j=1;j<=n;++j) a[j]=a[j-1]+arr[j].first;

    unsigned long long int  l=1,r=2,sum=0;
    pair<unsigned long long int,unsigned long long int> ans={INF,INF};
   while(l<n-k+1){
       while(r<=k&&r<=n){
           sum+=arr[r].first*(r-l)-(a[r-1]-a[l-1]);
           r++;

       }
       ans.first=min(ans.first,sum);
       if(ans.first==sum) ans.second=l;
       sum+=(arr[l].first*(r-l)-(a[r]-a[l]));
       l++;

   }

  // cout<<ans.first<<"^^";
    ll i=0;
    for(vector<pair<ll,ll>> ::iterator it=arr.begin()+ans.second+1;i<k;++it,++i)
       cout<<it->second<<" ";//<<it->first<<"((";

return 0;}


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

#define INF 1000000000000000000
typedef long long int ll;
int main(){

    ll n;
    cin>>n;
    vector <pair<ll ,ll>> arr(n+1);
    ll a[n];
    for(ll i=0;i<n;++i) {ll tmp1;
        cin>>tmp1;
        arr[i]={tmp1,i+1};
    }
    ll k; cin>>k;

    sort(arr.begin(),arr.end());
    a[0]=0;
    for(ll j=1;j<=n;++j) a[j]=a[j-1]+arr[j].first;

    ll l=1,r=2,sum=0;
    pair<ll,ll> ans={INF,INF};
   while(l<n-k+1){
       while(r<=k&&r<=n){
           sum+=arr[r].first*(r-l)-(a[r-1]-a[l-1]);
           r++;

       }
       ans.first=min(ans.first,sum);
       if(ans.first==sum) ans.second=l;
       sum+=(arr[l].first*(r-l)-(a[r]-a[l]));
       l++;

   }

  // cout<<ans.first<<"^^";
    ll i=0;
    for(vector<pair<ll,ll>> ::iterator it=arr.begin()+ans.second+1;i<k;++it,++i)
       cout<<it->second<<" ";//<<it->first<<"((";

return 0;}


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

#define INF 1000000000000000000
typedef long long int ll;
int main(){

    ll n;
    cin>>n;
    vector <pair<ll ,ll>> arr(n+1);
    ll a[n];
    for(ll i=0;i<n;++i) {ll tmp1;
        cin>>tmp1;
        arr[i]={tmp1,i+1};
    }
    ll k; cin>>k;

    sort(arr.begin()+1,arr.end());
    a[0]=0;
    for(ll j=1;j<=n;++j) a[j]=a[j-1]+arr[j].first;

    ll l=1,r=2,sum=0;
    pair<ll,ll> ans={INF,INF};
   while(l<=n-k+1){
       while(r-l+1<=k&&r<=n){

           sum=sum+arr[r].first*(r-l)-(a[r-1]-a[l-1]);
           r++;
            // cout<<sum<<"**";
       }

       ans.first=min(ans.first,sum);
       if(ans.first==sum) ans.second=l;
       sum+=(arr[l].first*(r-l-1)-(a[r-1]-a[l]));
       //cout<<sum<<"&&";
       l++;

   }

  //cout<<ans.second<<"^^";
    ll i=0;
    for(vector<pair<ll,ll>> ::iterator it=arr.begin()+ans.second;i<k;++it,++i)
       cout<<it->second<<" ";//<<it->first<<"((";

return 0;}


/*
tarun360
IIT Indore
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ll_s long
#define mod 1000000007
#define forn(i,start,lim) for(ll i=start;i<lim;i++)
#define forn_d(i,start,lim) for(ll i=start;i>=lim;i--)
#define forn_s(i,start,lim) for(ll_s i=start;i<lim;i++)
#define forn_d_s(i,start,lim) for(ll_s i=start;i>=lim;i--)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define debug1(a) cout<<a<<endl
#define debug2(a,b) cout<<a<<" "<<b<<endl
#define debug3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define debug4(a) cout<<"chu "<<a<<endl
#define endl "\n"

pair <ll,ll> p[300005];
ll cumsum[300005],ans[300005];
vector <ll> v;

int main()
{
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  ll mx,n,k;
  cin>>n;
  forn(i,1,n+1){cin>>p[i].f;p[i].s=i;}
  cin>>k;
  sort(p+1,p+n+1);
  forn(i,1,n+1) cumsum[i]=cumsum[i-1]+p[i].f;
  ll l=1,r=2;
  while(r<=k){
    ans[r]+=ans[r-1]+(r-1)*p[r].f-cumsum[r-1];
    r++;
  }
  mx=ans[r];
  r++;l++;
  while(r<=n){
    ans[r]=ans[r-1] - (cumsum[r-1]-cumsum[l-1]-(r-l+1)*p[l-1].f) + ((r-l+1)*p[r].f-(cumsum[r-1]-cumsum[l-1]));
    mx=max(mx,ans[r]);
    r++;
    l++;
  }
  ll index;
  forn(i,k,n+1){
    if(mx==ans[i]) {index=i;break;}
  }
  forn_d(i,index,index-k+1){
    v.pb(i);
  }
  sort(v.begin(),v.end());
  forn(i,0,v.size()) cout<<v[i]<<" ";
  cout<<endl;
  return 0;
}


/*
tarun360
IIT Indore
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ll_s long
#define mod 1000000007
#define forn(i,start,lim) for(ll i=start;i<lim;i++)
#define forn_d(i,start,lim) for(ll i=start;i>=lim;i--)
#define forn_s(i,start,lim) for(ll_s i=start;i<lim;i++)
#define forn_d_s(i,start,lim) for(ll_s i=start;i>=lim;i--)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define debug1(a) cout<<a<<endl
#define debug2(a,b) cout<<a<<" "<<b<<endl
#define debug3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define debug4(a) cout<<"chu "<<a<<endl
#define endl "\n"

pair <ll,ll> p[300005];
ll cumsum[300005],ans[300005];
vector <ll> v;

int main()
{
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  ll mx,n,k;
  cin>>n;
  forn(i,1,n+1){cin>>p[i].f;p[i].s=i;}
  cin>>k;
  sort(p+1,p+n+1);
  forn(i,1,n+1) cumsum[i]=cumsum[i-1]+p[i].f;
  ll l=1,r=2;
  while(r<=k){
    ans[r]+=ans[r-1]+(r-1)*p[r].f-cumsum[r-1];
    r++;
  }
  mx=ans[r-1];
  l++;
  while(r<=n){
    ans[r]=ans[r-1] - (cumsum[r-1]-cumsum[l-1]-(r-l)*p[l-1].f) + ((r-l)*p[r].f-(cumsum[r-1]-cumsum[l-1]));
    mx=min(mx,ans[r]);
    r++;
    l++;
  }
  /*forn(i,1,n+1) cout<<ans[i]<<" ";
  cout<<endl;*/
  ll index;
  forn(i,k,n+1){
    if(mx==ans[i]) {index=i;break;}
  }
  forn_d(i,index,index-k+1){
    v.pb(p[i].s);
  }
  sort(v.begin(),v.end());
  forn(i,0,v.size()) cout<<v[i]<<" ";
  cout<<endl;
  return 0;
}


// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define pb          push_back
#define PI          3.1415926535897932384626433832795l
#define F           first
#define S           second
#define mp          make_pair
#define INF         1000000000
#define MOD         1000000007
//#define find_by_order fbo //indexing of set
//#define order_of_key ook //no. of elements less than  x
//#define int ll
// bit turn off (n & ~(1 << (k - 1)));
const int dx4[] =       {-1, 0, 1, 0};
const int dy4[] =       { 0, 1, 0,-1};
const int dxdig[] =       {-1, 1, -1, 1};
const int dydig[] =       { 1, 1, -1,-1};
const int dx8[] =       {-1, 0, 1, 0, -1,-1, 1, 1};
const int dy8[] =       { 0, 1, 0,-1, -1, 1,-1, 1};
const int dxhorse[] =   {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] =   {1,  -1, 2 , -2, 2,-2, 1,-1};
const int dx6[] =       {1, -1, 0, 0, 0, 0};
const int dy6[] =       {0, 0, 1, -1, 0, 0};
const int dz6[] =       {0, 0, 0, 0, 1, -1};

typedef long long                           ll;
typedef vector < int >                      vi;
typedef vector < ll >                       vll;
typedef vector < pair < ll, ll > >          vpll;
typedef pair < ll, ll >                     pll;
typedef vector < pair < int, int > >        vpii;
typedef pair < int, int >                   pii;
typedef pair < int , pair < int, int > >    pipii;
typedef pair < pair < int, int >, int >     ppiii;
typedef vector < string >                   vs;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void fdcalc(vll &fd, vpll &a, int n, int k)
{
    for(ll i = 1; i < k; i++)
    {
        fd[i] = fd[i - 1];
        fd[i] += (i * (a[i].F - a[i - 1].F));
    }

    for(ll i = k; i < n; i++)
    {
        fd[i] = fd[i - 1] - (a[i - 1].F - a[i - k].F);
        fd[i] += ((k - 1) * (a[i].F - a[i - 1].F));
    }
}

void bdcalc(vll &bd, vpll &a, int n, int k)
{
    for(ll i = (n - 2); i >= (n - k); i--)
    {
        bd[i] = bd[i + 1];
        bd[i] += ((n - 1) - i) * (a[i + 1].F - a[i].F);
    }

    for(ll i = (n - (k + 1)); i >= 0; i--)
    {
        bd[i] = bd[i + 1] - (a[i + k].F - a[i + 1].F);
        bd[i] += ((k - 1) * (a[i + 1].F - a[i].F));
    }
}

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

    for(int i = 0; i < n; i++)
    {
        cin >> a[i].F;
        a[i].S = i + 1;
    }

    sort(a.begin(), a.end());
    cin >> k;
    vll fd(n, 0), bd(n, 0);
    fdcalc(fd, a, n, k);
    bdcalc(bd, a, n, k);
    ll cans = 0;

    for(int i = 0; i < k; i++)
    {
        cans += fd[i];
    }

    pll ans = {cans, 0};

    for(int i = k, j = 0; i < n; i++, j++)
    {
        cans += fd[i];
        cans -= bd[j];
        ans = min(ans, {cans, j + 1});
    }

    for(int i = ans.S; i < (ans.S + k); i++)
    {
        cout << a[i].S <<" ";
    }

    return 0;
}


// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define pb          push_back
#define PI          3.1415926535897932384626433832795l
#define F           first
#define S           second
#define mp          make_pair
#define INF         1000000000
#define MOD         1000000007
//#define find_by_order fbo //indexing of set
//#define order_of_key ook //no. of elements less than  x
//#define int ll
// bit turn off (n & ~(1 << (k - 1)));
const int dx4[] =       {-1, 0, 1, 0};
const int dy4[] =       { 0, 1, 0,-1};
const int dxdig[] =       {-1, 1, -1, 1};
const int dydig[] =       { 1, 1, -1,-1};
const int dx8[] =       {-1, 0, 1, 0, -1,-1, 1, 1};
const int dy8[] =       { 0, 1, 0,-1, -1, 1,-1, 1};
const int dxhorse[] =   {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] =   {1,  -1, 2 , -2, 2,-2, 1,-1};
const int dx6[] =       {1, -1, 0, 0, 0, 0};
const int dy6[] =       {0, 0, 1, -1, 0, 0};
const int dz6[] =       {0, 0, 0, 0, 1, -1};

typedef long long                           ll;
typedef vector < int >                      vi;
typedef vector < ll >                       vll;
typedef vector < pair < ll, ll > >          vpll;
typedef pair < ll, ll >                     pll;
typedef vector < pair < int, int > >        vpii;
typedef pair < int, int >                   pii;
typedef pair < int , pair < int, int > >    pipii;
typedef pair < pair < int, int >, int >     ppiii;
typedef vector < string >                   vs;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void calcadd(vll& b, vpll &in, ll n, ll k)
{
    vll a(n, 0);

    for(ll i = 1; i < n; i++)
    {
        a[i] = a[i - 1];
        a[i] += (i * (in[i].F - in[i - 1].F));
    }

    b = a;

    for(ll i = k; i < n; i++)
    {
        b[i] -= a[i - k];
        b[i] -= (in[i].F - in[i - k].F) * ((i - k) + 1);
    }
}

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

    for(int i = 0; i < n; i++)
    {
        cin >> a[i].F;
        a[i].S = i + 1;
    }

    sort(a.begin(), a.end());
    cin >> k;
    vll addarr(n, 0);
    calcadd(addarr, a, n, k);

    pll ans = {addarr[k - 1], 0};

    for(int i = k, j = 0; i < n; i++, j++)
    {
        ans = min(ans, {addarr[i], j + 1});
    }

    for(int i = ans.S; i < (ans.S + k); i++)
        cout << a[i].S <<" ";

    return 0;
}


#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#include <bits/stdc++.h>
using namespace std;
#define sqr 400
//#define mp make_pair
#define mid (l+r)/2
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define era erase
#define C continue
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define mset multiset
#define all(x) x.begin(), x.end()
#define gc getchar_unlocked
typedef long long ll;
typedef short int si;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const ll inf=6*1e18;
const ll Mod=1e9+7;
const ld pai=acos(-1);
ll N , K ;
pll Points [300009] ;
ll Sum [300009] ;
ll Calc ( ll l , ll r ) {
	ll Ans = Sum [r] ;
	if ( l ) Ans -= Sum [l-1] ;
	return Ans ;
}
int main () {
	cin >> N ;
	for ( ll i = 0 ; i < N ; i ++ ){
		cin >> Points [i].fi ;
		Points [i] .se = i ;
	}
	sort ( Points , Points + N ) ;
	for ( ll i = 0 ; i < N ; i ++ ) {
		Sum [i] = Points [i] .fi ;
                if ( i ) Sum [i] += Sum [i-1] ;
	}
	cin >> K ;
       	ll Crnt = 0 , l = 0 ;
	pair < ll , pll > Best = { inf , { inf , inf } } ;
	for ( ll r = 1 ; r < K ; r ++ ) {
		Crnt += ( r - l ) * Points [r] .fi - Calc ( l , r - 1 ) ;
	}
	Best = min ( Best , { Crnt , { 0 , K - 1 } } ) ;
	for ( ll r = K ; r < N ; r ++ ) {
		Crnt -= Calc ( l + 1 , r - 1 ) - ( r - l - 1 ) * Points [l] .fi ;
		l ++ ;
		Crnt += ( r - l ) * Points [r] .fi - Calc ( l , r - 1 ) ;
		Best = min ( Best , { Crnt , { l , r } } );
	}
	for ( int i = Best .se.fi ; i <= Best .se.se ; i ++ ) cout << Points [i] .se + 1 << " " ;
	cout << endl ;
}


#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#include <bits/stdc++.h>
using namespace std;
#define sqr 400
//#define mp make_pair
#define mid (l+r)/2
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define era erase
#define C continue
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define mset multiset
#define all(x) x.begin(), x.end()
#define gc getchar_unlocked
typedef long long ll;
typedef short int si;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const ll inf=1e18;
const ll Mod=1e9+7;
const ld pai=acos(-1);
ll N , K ;
pll Points [300009] ;
ll Sum [300009] ;
ll Calc ( ll l , ll r ) {
	ll Ans = Sum [r] ;
	if ( l ) Ans -= Sum [l-1] ;
	return Ans ;
}
int main () {
	cin >> N ;
	for ( ll i = 0 ; i < N ; i ++ ){
		cin >> Points [i].fi ;
		Points [i] .se = i ;
	}
	sort ( Points , Points + N ) ;
	for ( ll i = 0 ; i < N ; i ++ ) {
		Sum [i] = Points [i] .fi ;
                if ( i ) Sum [i] += Sum [i-1] ;
	}
	cin >> K ;
       	ll Crnt = 0 , l = 0 ;
	pair < ll , pi > Best = { inf , { inf , inf } } ;
	for ( ll r = 1 ; r < K ; r ++ ) {
		Crnt += ( r - l ) * Points [r] .fi - Calc ( l , r - 1 ) ;
	}
	Best = min ( Best , { Crnt , { 0 , K - 1 } } ) ;
	for ( ll r = K ; r < N ; r ++ ) {
		Crnt -= Calc ( l + 1 , r - 1 ) - ( r - l - 1 ) * Points [l] .fi ;
		l ++ ;
		Crnt += ( r - l ) * Points [r] .fi - Calc ( l , r - 1 ) ;
		Best = min ( Best , { Crnt , { l , r } } );
	}
	for ( int i = Best .se.fi ; i <= Best .se.se ; i ++ ) cout << Points [i] .se + 1 << " " ;
	cout << endl ;
}


#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#include <bits/stdc++.h>
using namespace std;
#define sqr 400
//#define mp make_pair
#define mid (l+r)/2
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define era erase
#define C continue
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define mset multiset
#define all(x) x.begin(), x.end()
#define gc getchar_unlocked
typedef long long ll;
typedef short int si;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const ll inf=1e18;
const ll Mod=1e9+7;
const ld pai=acos(-1);
ll N , K ;
pll Points [300009] ;
ll Sum [300009] ;
ll Calc ( ll l , ll r ) {
	ll Ans = Sum [r] ;
	if ( l ) Ans -= Sum [l-1] ;
	return Ans ;
}
int main () {
	cin >> N ;
	for ( ll i = 0 ; i < N ; i ++ ){
		cin >> Points [i].fi ;
		Points [i] .se = i ;
	}
	sort ( Points , Points + N ) ;
	for ( ll i = 0 ; i < N ; i ++ ) {
		Sum [i] = Points [i] .fi ;
                if ( i ) Sum [i] += Sum [i-1] ;
	}
	cin >> K ;
       	ll Crnt = 0 , l = 0 ;
	pair < ll , pi > Best = { inf , { inf , inf } } ;
	for ( ll r = 1 ; r < K ; r ++ ) {
		Crnt += ( ( r - l ) * Points [r] .fi - Calc ( l , r - 1 ) ) / ( r - l ) ;
	}
	Best = min ( Best , { Crnt , { 0 , K - 1 } } ) ;
	for ( ll r = K ; r < N ; r ++ ) {
		Crnt -= ( Calc ( l + 1 , r - 1 ) - ( r - l - 1 ) * Points [l] .fi ) / ( r - l - 1 ) ;
		l ++ ;
		Crnt += ( ( r - l ) * Points [r] .fi - Calc ( l , r - 1 ) ) / ( r - l ) ;
		Best = min ( Best , { Crnt , { l , r } } );
	}
	for ( int i = Best .se.fi ; i <= Best .se.se ; i ++ ) cout << Points [i] .se + 1 << " " ;
	cout << endl ;
}


#include <vector>
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <cassert>
#include <string>
#include <cstring>
#include <unordered_map>
#include <unordered_set>

using namespace std;

int main(int argc, char **argv) {
    int n;
    scanf("%d", &n);
    vector<pair<int, int> > v(n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &v[i].first);
        v[i].second = i;
    }
    int k;
    scanf("%d", &k);
    sort(v.begin(), v.end());
    long long sum = 0;
    long long distances = 0;
    for (int i = 0; i < k; ++i) {
        distances += 1LL * v[i].first * i - sum;
        sum += v[i].first;
    }
    long long best = distances;
    int from = 0;
    for (int i = k; i < n; ++i) {
        distances -= sum - 1LL * v[i - k].first * k;
        sum -= v[i - k].first;
        sum += v[i].first;
        distances += 1LL * v[i].first * k - sum;
        if (distances < best) {
            best = distances;
            from = i - k + 1;
        }
    }
    for (int i = 0; i < k; ++i)
        printf("%s%d", i ? " " : "", v[from + i].second + 1);
    puts("");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int MAXN = 312345;
int v[MAXN], n, soma = 0, marc[MAXN], k;
void twop(){
	int ini, fim, cont = 0;
	while(ini <= fim){
		cont++;
		if(soma - n * v[ini] <= n * v[fim] - soma)	marc[fim] = 1, fim--, soma -= v[fim];
		else	marc[ini] = 1, ini++, soma -= v[ini];
		if(cont >= n - k)	return;
	}
}
int main(){
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		scanf("%d",&v[i]);
		soma += v[i];
	}
	sort(v, v + n);
	scanf("%d",&k);
	twop();
	for(int i = 0; i < n; i++){
		if(marc[i] != 1)	printf("%d ",i + 1);
	}
}


#include <bits/stdc++.h>
using namespace std;
vector <int> v, o;
map <int, int> comp;
int n, k, S, D, minD, resp;
int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		int aux;
		cin >> aux;
		v.push_back(aux);
		comp[aux] = i + 1;
	}
	cin >> k;
	sort(v.begin(), v.end());
	for(int i = 0; i < n; i++){
		if(i < k)	S += v[i];
		else{
			minD = min(D, minD);
			S -= v[i - k];
			D += (k - 1) * (v[i - k] + v[i]) - 2*S;
			S += v[i];
		}
	}
	D = 0, S = 0;
	for(int i = 0; i < n; i++){
		if(i < k)	S += v[i];
		else{
			if(D == minD)	resp = i - 1;
			S -= v[i - k];
			D += (k - 1) * (v[i - k] + v[i]) - 2*S;
			S += v[i];
			minD = min(minD, D);
			if(D == minD)	resp = i;
		}
	}
	for(int i = resp; i > resp - k; i--){
		cout << comp[v[i]] << " ";
	}
	cout << endl;
}


#include <bits/stdc++.h>
using namespace std;
vector <int> v, o;
map <int, int> comp;
int n, k, resp;
long long int D, S;
int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		int aux;
		cin >> aux;
		v.push_back(aux);
		comp[aux] = i + 1;
	}
	cin >> k;
	sort(v.begin(), v.end());
	for(int i = 0; i < n; i++){
		if(i < k)	S += v[i];
		else{
			minD = min(D, minD);
			S -= v[i - k];
			D += (k - 1) * (v[i - k] + v[i]) - 2*S;
			S += v[i];
		}
	}
	D = 0, S = 0;
	for(int i = 0; i < n; i++){
		if(i < k)	S += v[i];
		else{
			if(D == minD)	resp = i - 1;
			S -= v[i - k];
			D += (k - 1) * (v[i - k] + v[i]) - 2*S;
			S += v[i];
			minD = min(minD, D);
			if(D == minD)	resp = i;
		}
	}
	for(int i = resp; i > resp - k; i--){
		cout << comp[v[i]] << " ";
	}
	cout << endl;
}


#include <bits/stdc++.h>
using namespace std;
vector <long long int> v, o;
map <long long int,long long int> comp;
long long int n, k, resp;
long long int D, S, minD;
int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		long long int aux;
		cin >> aux;
		v.push_back(aux);
		comp[aux] = i + 1;
	}
	cin >> k;
	sort(v.begin(), v.end());
	for(int i = 0; i < n; i++){
		if(i < k)	S += v[i];
		else{
			minD = min(D, minD);
			S -= v[i - k];
			D += (k - 1) * (v[i - k] + v[i]) - 2*S;
			S += v[i];
		}
	}
	D = 0, S = 0;
	for(int i = 0; i < n; i++){
		if(i < k)	S += v[i];
		else{
			if(D == minD)	resp = i - 1;
			S -= v[i - k];
			D += (k - 1) * (v[i - k] + v[i]) - 2*S;
			S += v[i];
			minD = min(minD, D);
			if(D == minD)	resp = i;
		}
	}
	for(int i = resp; i > resp - k; i--){
		cout << comp[v[i]] << " ";
	}
	cout << endl;
}


#include <bits/stdc++.h>
using namespace std;
vector <int> v, o;
map <int, int> comp;
int n, k, S, D, minD, resp;
int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		int aux;
		cin >> aux;
		v.push_back(aux);
		comp[aux] = i + 1;
	}
	cin >> k;
	sort(v.begin(), v.end());
	for(int i = 0; i < n; i++){
		if(i < k)	S += v[i];
		else{
			minD = min(D, minD);
			S -= v[i - k];
			D += (k - 1) * (v[i - k] + v[i]) - 2*S;
			S += v[i];
		}
	}
	D = 0, S = 0;
	for(int i = 0; i < n; i++){
		if(i < k)	S += v[i];
		else{
			if(D == minD)	resp = i;
			S -= v[i - k];
			D += (k - 1) * (v[i - k] + v[i]) - 2*S;
			S += v[i];
		}
	}
	for(int i = resp; i > resp - k; i--){
		cout << comp[v[i]] << " ";
	}
	cout << endl;
}


#include <bits/stdc++.h>
using namespace std;
const int MAXN = 312345;
int v[MAXN], n, soma = 0, marc[MAXN], k;
void twop(){
	int ini = 0 , fim = n - 1, cont = 0;
	while(ini <= fim){
		cont++;
		if(soma - n * v[ini] <= n * v[fim] - soma)	marc[fim] = 1, fim--, soma -= v[fim];
		else	marc[ini] = 1, ini++, soma -= v[ini];
		if(cont >= n - k)	return;
	}
}
int main(){
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		scanf("%d",&v[i]);
		soma += v[i];
	}
	sort(v, v + n);
	scanf("%d",&k);
	twop();
	for(int i = 0; i < n; i++){
		if(marc[i] != 1)	printf("%d ",i + 1);
	}
}


#include <bits/stdc++.h>
using namespace std;
vector <int> v, o;
map <int, int> comp;
int n, k, resp;
long long int D, S, minD;
int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		int aux;
		cin >> aux;
		v.push_back(aux);
		comp[aux] = i + 1;
	}
	cin >> k;
	sort(v.begin(), v.end());
	for(int i = 0; i < n; i++){
		if(i < k)	S += v[i];
		else{
			minD = min(D, minD);
			S -= v[i - k];
			D += (k - 1) * (v[i - k] + v[i]) - 2*S;
			S += v[i];
		}
	}
	D = 0, S = 0;
	for(int i = 0; i < n; i++){
		if(i < k)	S += v[i];
		else{
			if(D == minD)	resp = i - 1;
			S -= v[i - k];
			D += (k - 1) * (v[i - k] + v[i]) - 2*S;
			S += v[i];
			minD = min(minD, D);
			if(D == minD)	resp = i;
		}
	}
	for(int i = resp; i > resp - k; i--){
		cout << comp[v[i]] << " ";
	}
	cout << endl;
}


#include <bits/stdc++.h>
using namespace std;
/*    freopen("k.in", "r", stdin);
    freopen("k.out", "w", stdout); */
// clock_t c1 = clock();
// std::cerr << "Time:" << clock() - c1 <<"ms" << std::endl;
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define de(a) cout << #a << " = " << a << endl
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = n; i >= a; i--)
#define ls ((x) << 1)
#define rs ((x) << 1 | 1)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef pair<ll, ll> PLL;
typedef vector<int, int> VII;
#define inf 0x3f3f3f3f
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll MAXN = 3e5 + 7;
const ll MAXM = 1e5 + 7;
const ll MOD = 1e9 + 7;
const double eps = 1e-6;
const double pi = acos(-1.0);
int n;
struct node
{
    ll v, pos;
    friend bool operator<(const node a, const node b) { return a.v < b.v; }
} x[MAXN];
ll sum[MAXN];
int main()
{
    scanf("%d", &n);
    sum[0] = 0;
    for (int i = 1; i <= n; i++)
        scanf("%lld", &x[i].v), x[i].pos = i, sum[i] = sum[i - 1] + x[i].v;
    sort(x + 1, x + 1 + n);
    int k;
    scanf("%d", &k);
    int st = 1;
    ll now = 0;
    ll minn = 0;
    for (int i = 2; i <= n - k + 1; i++)
    {
        now += ((k - 1) * x[i + k - 1].v - (sum[i + k - 2] - sum[i - 1])) - (sum[i + k - 2] - sum[i - 1] - (k - 1) * x[i - 1].v);
        if (now < minn)
            st = i, minn = now;
    }
    for (int i = 0; i < k; i++)
        printf("%d ", x[st + i].pos);
    printf("\n");
    return 0;
}
/*
5
11 21 30 40 50
3
1 2 3
 */