시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB333100.000%

문제

Your task is to build an optimal algorithm for the shared memory switch.

A shared memory switch is one of the simplest nontrivial buffering architectures considered in the field of algorithms for networking. In this problem we consider a shared memory switch with multiple output queues and uniform (identical) packets. Incoming packets in this model are destined to one of the several output queues, which share a common buffer of finite size $B$. At the end of each second all nonempty queues transmit one packet each. When the buffer overflows your algorithm must decide which packet to drop. Your goal is to design an algorithm achieving maximal throughput (equivalently, dropping as few packets as possible).

You will be given $n$ queries in the following format:

  • $-1$: a single second passes.
  • $k$ ($1 \leq k \leq n$): a packet arrives to the $k$-th queue.

You can assume that all packets remaining in the buffer after all queries will be sent as well or, equivalently, that there is an infinite number of $-1$ queries that follow the queries in the input.

입력

The first line contains contains two non-negative integers $n$ and $B$ ($n, B \leq 2 \cdot 10^5$): the number of queries and the amount of memory available to the switch correspondingly.

The second line contains $n$ queries in the format described above.

출력

On the first line, output the only integer: the number of transmitted packets.

On the second line, output the numbers of queries ($1$-based) with arrivals of the packets that were transmitted. You can output these numbers in any order.

예제 입력 1

14 5
1 1 1 2 2 2 -1 1 -1 1 -1 1 -1 1

예제 출력 1

9
3 6 8 5 10 4 12 14 2

예제 입력 2

14 4
1 1 1 2 2 2 -1 1 -1 1 -1 1 -1 1

예제 출력 2

8
3 6 8 5 10 4 12 14