Algorithm


B. Help Chef Gerasim
time limit per test
0.5 second
memory limit per test
256 megabytes
input
standard input
output
standard output

In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that the pages have played a prank again: they had poured the juice from one cup to another. Now Gerasim wants to check his hypothesis. The good thing is that chef Gerasim always pour the same number of milliliters of juice to all cups in the royal kitchen. Having thoroughly measured the juice in each cup, Gerasim asked you to write a program that will determine from which cup juice was poured to which one; otherwise, the program should determine that this time the pages set the table diligently.

To simplify your task we shall consider the cups to be bottomless so that the juice never overfills a cup and pours out, however much it can be. Besides, by some strange reason in a far away kingdom one can only pour to a cup or from one cup to another an integer number of milliliters of juice.

Input

The first line contains integer n — the number of cups on the royal table (1 ≤ n ≤ 1000). Next n lines contain volumes of juice in each cup — non-negative integers, not exceeding 104.

Output

If the pages didn't pour the juice, print "Exemplary pages." (without the quotes). If you can determine the volume of juice poured during exactly one juice pouring, print "v ml. from cup #a to cup #b." (without the quotes), where v represents the volume of poured juice, a represents the number of the cup from which the juice was poured (the cups are numbered with consecutive positive integers starting from one in the order in which the cups are described in the input data), b represents the number of the cup into which the juice was poured. Finally, if the given juice's volumes cannot be obtained using no more than one pouring (for example, the pages poured the juice from one cup to another more than once or the royal kitchen maids poured the juice into the cups incorrectly), print "Unrecoverable configuration." (without the quotes).

Examples
input
Copy
5
270
250
250
230
250
output
Copy
20 ml. from cup #4 to cup #1.
input
Copy
5
250
250
250
250
250
output
Copy
Exemplary pages.
input
Copy
5
270
250
249
230
250
output
Copy
Unrecoverable configuration.



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <iostream>
#include <vector>

int main(){

    std::ios_base::sync_with_stdio(false);
    long n; std::cin >> n;
    std::vector<long> a(n); 
    long total(0);
    for(long p = 0; p < n; p++){
        std::cin >> a[p];
        total += a[p];
    }

    int res(0), diff(0), from(0), to(0);
    if(total % n != 0){res = 0;}
    else{
        long vol = total / n;
        long good(0);
        for(long p = 0; p < n; p++){
            if(a[p] > vol){to = p;}
            else if(a[p] < vol){from = p;}
            else{++good;}
        }

        if(good == n){res = 1;}
        else if(good != n - 2){res = 0;}
        else{diff = a[to] - vol; ++from; ++to; res = 2;}
    }

    if(res == 0){std::cout << "Unrecoverable configuration." << std::endl;}
    else if(res == 1){std::cout << "Exemplary pages." << std::endl;}
    else if(res == 2){std::cout << diff << " ml. from cup #" << from << " to cup #" << to << "." << std::endl;}

    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
5
270
250
250
230
250

Output

x
+
cmd
20 ml. from cup #4 to cup #1.
Advertisements

Demonstration


Codeforces Solution-B. Help Chef Gerasim-Solution in C, C++, Java, Python

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+