#include #include using namespace std; using namespace atcoder; typedef long long ll; //using mint = modint998244353; //using mint = modint1000000007; #define all(...) std::begin(__VA_ARGS__), std::end(__VA_ARGS__) #define rall(...) std::rbegin(__VA_ARGS__), std::rend(__VA_ARGS__) #define debug(x) cerr << "\033[33m(line:" << __LINE__ << ") " << #x << ": " << x << "\033[m" << endl; int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; using Graph=vector>; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; templatebool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } templatebool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } int main() { int n,k;cin>>n>>k; vector a(n); for(int i=0;i>a[i]; reverse(all(a)); deque d={a[0]}; deque it={0}; for(int i=1;i=a[i]){ d.push_back(a[i]); it.push_back(i); }else{ d.push_front(a[i]); it.push_front(i); } } k--; vector b; reverse(all(a)); for(int i=0;i