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

USU Personal Contest 2002

About     Problems     Submit solution     Judge status     Standings
Contest is over

A. Strange Sequence

Time limit: 1.0 second
Memory limit: 2 MB
You have been asked to discover some important properties of one strange sequences set. Each sequence of the parameterized set is given by a recurrent formula:
Xn+1 = F(Xn-1, Xn),
where n > 1, and the value of F(X,Y) is evaluated by the following algorithm:
  1. find H = (A1*X*Y + A2*X + A3*Y + A4);
  2. if H > B1 then H is decreased by C until H ≤ B2;
  3. the resulting value of H is the value of function F.
The sequence is completely defined by nonnegative constants A1, A2, A3, A4, B1, B2 and C.
One may easily verify that such sequence possess a property that Xp+n = Xp+q+n for appropriate large enough positive integers p and q and for all n ≥ 0. You task is to find the minimal p and q for the property above to hold. Pay attention that numbers p and q are well defined and do not depend on way minimization is done.

Input

The first line contains seven integers: A1, A2, A3, A4, B1, B2 and C. The first two members of sequence (X1 and X2) are placed at the second line. You may assume that all intermediate values of H and all values of F fit in range [0..100000].

Output

An output should consist of two integers (p and q) separated by a space.

Sample

inputoutput
0 0 2 3 20 5 7
0 1
2 3
Problem Author: Alexander Klepinin
Problem Source: Third USU personal programming contest, Ekaterinburg, Russia, February 16, 2002
To submit the solution for this problem go to the Problem set: 1175. Strange Sequence