It's often happens in programming that one has to test and debug an existing program code. Imagine that your colleague has passed you fragment of program code of his because he is to work at another program.
Here follows the fragment of the program code — a function with two input-output parameters:
procedure P(var x, y: longint);
i, j: longint;
if (x>0) and (y>0) then
for i := 1 to x+y do
y := x*x+y;
x := x*x+y;
y := round(sqrt(x+(y/abs(y))*(-abs(y))));
for j := 1 to 2*y do
x := x-y;
void P(long& x, long& y)
int i, j;
if (x>0 && y>0)
for (i = 1; i <= x+y; i++)
y = x*x+y;
x = x*x+y;
y = sqrt(x+(y/labs(y))*(-labs(y)));
for (j = 1; j <= 2*y; j++)
x = x-y;
Your task is unusual: in order to debug the function it's necessary to
work out a program that would restore input parameters given output data
of the function. It's guaranteed that no variable has left its type during
the processing of the function.
contains two numbers x and y separated with a space — those are output parameters of the function.
should contain two numbers x and y separated
with a space that were given to the function as input parameters.
Problem Author: Anatoly Uglov
Problem Source: USU Open Collegiate Programming Contest October'2002 Junior Session