Andrew writes portable mailer KittenMail for FTN technology networks. This mailer uses text-mode windowed interface like well-known Norton-style shells do.
Now Andrew wants to write a version of his mailer for the new famous operating system Mycrowslowed Widows Not-tested 0.4. It's easy because there is no so much system-dependent code in the mailer. But the windowing subsystem is based on the module providing system-independent interface to the screen buffer functions.
Andrew wrote the trivial code for Mycrowslowed Widows displaying the contents of the window buffer on the screen. It was easy because the functions are the same as in other operating systems. But he was so surprised when he ran the mailer! Clearing the screen took about a second! Oops. . . What's wrong?
Andrew started to investigate this problem. Few minutes later, he discovered that any Mycrowslowed Widows system call accessing the screen buffer works a huge amount of time --- 1/6000 second or more. It's so awful! What can he do?
After hours of thinking, Andrew decided to make some improvements to his code. Now he wants to use Widows-specific function that draws a rectangle of characters instead of subsequent calls that display only one character. They perfectly work under other operating systems but are very slow under Mycrowslowed Widows. The evident task has arisen. The procedure which redraws window must display its visible parts using the minimal possible number of non-overlapping operations.
It is your task to write the corresponding code for one visible part of the window. Given the part of the rectangular window, write a program which determines the minimal number of non-overlapping rectangles covering this part and finds the optimal way of covering.