SP15432 UCV2013D - Distributing V-Energy

Description

As you probably know there is a new kind of energy called V-energy which is more afordable than electricity, and has some really interesting properties. The Universal Company on V-Energy has just reached your city and is currently planning the location of the distribution centers. You are given a map of the city, the list of the location of the distribution centers, and they need you to report which is the minimum ammount of energy that would reach a building of the city, and how many buildings share that ammount of energy V-Energy has the following properties: - If a buiding has K units of V-Energy it will consume C units and distribute K - C to every building it is connected to. If K < C the building will consume K units and will not distribute any units of energy - If a building receives V-Energy from different sources it will only consume and distribute the energy with maximum value. For example, if a building receives K = 8 units of energy,and C = 3 it will consume 3 and distribute 5. But, if later the same building receives K = 6 units of energy, it will not consume or distribute this energy since previously it received a larger ammount of energy. If later on the same building receives K = 15 units of energy, it will consume 3 units, and distribute 12 units to its neighbors As you know, your city is a grid, with buildings on every intersection of the streets. Since V-Energy propagates only through streets, the streets map of the city is perfect for your job. Avenues run horizontally while streets run vertically. Note that sometimes a street or avenue can be blocked. The next figure shows a possible view of a city where street 1 is blocked between avenues 1 and 2, and avenue 2 is blocked between streets 0 and 1. ![Streets and avenues sample](https://cdn.luogu.com.cn/upload/vjudge_pic/SP15432/b1d743a39ed5d749a6ccdc4dd070ed266d4a19a7.png)

Input Format

The input contains several test cases. Each case starts with a line containing the values K and C (ammount of V-energy each distribution center has and ammount of V-energy each building consumes). (0

Output Format

For each test cases you have to print a line containing two numbers Q and P indicating the minimum amount of energy that reaches a building on the city, and the number of building with that amount of energy.