ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

1505. Oil Transfer

Time limit: 2.0 second
Memory limit: 64 MB
A New Russian Kolyan wants an oil delivery to foreign partners to become his main source of income. His company owns a number of pumping stations with network of pipelines connecting them. First, Kolyan wants to increase the amount of the transferred oil by 1 million barrels per day. Help Kolyan to achieve this goal spending the minimal amount of money.

Input

The first line contains an integer N, which is the number of pumping stations between which there are pipelines (1 ≤ N ≤ 10000). The stations are numbered from 1 to N. The next N lines describe the stations.
The ith line contains quadruples of integers a b c d (1 ≤ aN; 0 ≤ cb ≤ 10000; 0 ≤ d ≤ 106), where
a is the number of a station to which a pipeline from the station i exists,
b is the flow capacity of the pipeline from i to a in millions of barrels per day,
c is the present oil flow from i to a in millions of barrels per day,
d is the amount of money (in roubles) necessary for the increase in the flow capacity of the pipeline from i to a by 1 million barrels per day. There can be at most 1 pipeline from station i to station a and no pipeline connects a station with itself.
These quadruples in the line are separated with commas, and there is a period after the last quadruple. If oil is not transported anywhere from the ith station, then the corresponding line contains only one symbol ".". It is guaranteed that there are no more than 100000 quadruples describing pipelines in the input.
Oil is transferred to foreign partners at only one pumping station with the number N. The cross-border oil flow is equal to the incoming flow at this station. From this station, oil is not transported to other pumping stations in the described pipeline network. Pumping stations with numbers less than N are transit stations. It is known that for each transit station the incoming oil flow is not more than the outgoing flow. If the incoming flow is less than the outgoing flow, then there is an oil-producing well nearby, whose oil production can easily be increased by 1 million barrels per day.

Output

In the first line output the minimal cost K of reconstructing the pipeline network in such a way that the oil transfer to foreign partners is increased by 1 million barrels per day. Then output N lines describing the oil flow in the pipelines after the reconstruction, in the following format: the ith of these lines must contain a list of pairs a b separated with commas; a is the number of a station to which oil is transported from the station i, and b is the number of the transported oil in millions of barrels per day. Each of these lines must end with a period.
If it's impossible to reach Kolyan's goal then output single word "Impossible".

Sample

inputoutput
4
2 1 1 1, 3 1 1 3.
3 1 0 2, 4 1 1 2.
4 1 1 1.
.
2
2 2, 3 1.
3 1, 4 1.
4 2.
.
Problem Author: Magaz Asanov, Evgeny Krokhalev
Problem Source: Quarter-Final of XXXI ACM ICPC - Yekaterinburg - 2006