You are the King of Byteland, which now consists of K rival states. The national day of Byteland is approaching, and it is a day of great merriment. Each of the K states is throwing its own party. Fortunately your kingdom also has N rich and famous entertainers, numbered from 0 to N-1. Its your job to allocate to each state, some non empty set of entertainers. Note that the same entertainer cannot be allocated to two different states. Some entertainers may be unallocated. Also to each allocated entertainer, you must pay C coins to hire him.

The trouble is, some of the entertainers are fond of some others, and refuse to spend the national day without their friends, meaning they insist on being allocated to the same state if they are allocated). Under this constraint, you find out that allocating entertainers to the states becomes impossible. So you appeal to them to relax their requirements, and they ask you to donate more money to the entertainment industry. More formally, you will be provided with a 2-dimensional array R. If the total amount of money you donate is less than R[u][v], for u not equal to v, then entertainer #u will NOT agree to spend the national day without the company of entertainer #v. Note that if you do not allocate entertainer #u, then you can safely ignore his restrictions. R[u][v] need not be equal to R[v][u].