|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|1 초||128 MB||0||0||0||0.000%|
A disk consists of N sectors numbered successively from 1 to N. Any nonempty sequence of sectors having consecutive numbers is called a block. A length of a block is the number of sectors in the block. Blocks are separate if they have no common sector.
There are files written on a disk. A single file may be written on many sectors, which need not form a single block. To reconstruct a file correctly one needs to read those sectors in right order. This sequence of sectors determines a sequence of separate blocks - each of them contains one or more sectors. Sectors inside each block are read in order of their numbers.
A description of a file distribution on a disk is a sequence of pairs of positive integers. Each of these pairs comprises the number of the starting sector of a block and the length of the block.
The sequence of pairs:
7 3 2 1 5 2
informs that the contents of the file ought to be read successively from the sectors numbered: 7, 8, 9, next: 2, and next: 5, 6.
Each sector on a disk may be either free or there may be written a part of only one file (or one whole file).
Each file has a unique ID - a positive integer in the range of 1 to P, where P is the number of files on the disk.
A disk is optimized when:
One may perform the following operations on a disk:
Copying a block of length t lasts t microseconds. Swapping contents of two blocks of length t lasts 2 · t microseconds.
The instruction to copy a block has the form:
K start new_start length
The instruction to swap blocks has the form:
Z start1 start2 length
K and Z are short forms of "kopiowanie" ("copying") and "zamiana" ("swapping"), and start is the number of the first sector of a block.
Write a program that:
In the first line of the standard input there are written two positive integers: the number of sectors on the disk N, not greater than 10,000, and the number of files P.
Next in the successive lines there are descriptions of file distributions on the disk.
Each file description contains two numbers in the first line: the file's ID from the range of 1 to P and a positive number denoting the number of separate blocks the file is written in. In the next lines there is the description of the file distribution in a form of an appropriate sequence of pairs of positive integers, one pair per line.
The numbers in lines are separated by single spaces.
The data in the standard input are written correctly and your program need not verify that.
The standard output is to contain:
200 2 2 2 51 10 41 10 1 2 71 20 11 20
K 21 31 10 K 11 21 10 K 71 1 20 Z 41 51 10