using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[] NMi => ReadLine().Split().Select(c => int.Parse(c) - 1).ToArray(); static int[][] NMap(int n) => Enumerable.Repeat(0, n).Select(_ => NMi).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (n, k) = (c[0], c[1]); var a = NList; var q = new Deque(n); for (var i = 0; i < n; ++i) q.Enqueue(i + 1); var cnt = 1; var pos = -1; for (var i = 0; i + 1 < n; ++i) { if (pos >= 0) break; if (a[i] == a[i + 1]) { ++cnt; } else if (a[i] > a[i + 1]) { for (var j = 0; j < cnt; ++j) { if (q.Dequeue() == k) { pos = i; break; } } cnt = 1; } else { for (var j = 0; j < cnt; ++j) { if (q.Pop() == k) { pos = i; break; } } cnt = 1; } } if (pos < 0) pos = n - 1; WriteLine(string.Join(" ", a.Take(pos).Concat(a.Skip(pos + 1)))); } /// 前後から出し入れ可能なキュー class Deque { int _s = 0; int _t = 0; T[] _arr; public Deque() : this(4) { } public Deque(int size) { _arr = new T[size]; } public Deque(IEnumerable init) { var list = init.ToArray(); var size = 4; while (size <= list.Length) size <<= 1; _arr = new T[size]; for (var i = 0; i < list.Length; ++i) _arr[i] = list[i]; _t = _arr.Length; } public int Count { get { return (_t + _arr.Length - _s) % _arr.Length; } } public void Enqueue(T item) { if (Count + 1 == _arr.Length) Expand(); if (_t == _arr.Length) _t = 0; _arr[_t++] = item; } public T Dequeue() { var ret = _arr[_s++]; if (_s == _arr.Length) _s = 0; return ret; } public void Push(T item) { Enqueue(item); } public void PushFront(T item) { if (Count + 1 == _arr.Length) Expand(); if (_s == 0) _s = _arr.Length; _arr[--_s] = item; } public T Pop() { var ret = _arr[--_t]; if (_t == 0) _t = _arr.Length; return ret; } public T Peek() { if (Count == 0) throw new InvalidOperationException("deque is empty"); return _arr[_s]; } void Expand() { var count = Count; var na = new T[_arr.Length * 2]; var cur = 0; if (_s <= _t) { for (var i = _s; i < _t; ++i) na[cur++] = _arr[i]; } else { for (var i = _s; i < _arr.Length; ++i) na[cur++] = _arr[i]; for (var i = 0; i < _t; ++i) na[cur++] = _arr[i]; } _s = 0; _t = count; _arr = na; } } }