Hide

Problem A
Elliptic Curve Addition

Languages en is

Let p be a prime and a,bFp such that 4a3+27b20(modp). Let P=(x1,y1) and Q=(x2,y2) be two points on the elliptic curve E:y2=x3+ax+b. Calcuate PQ given p,a,b,x1,y1,x2 and y2.

Input

First line consists of three integers, 0<p<2311, 0a<p and 0b<p, where p is a prime. Second line consist of two integers 1x1,y1<2311 where (x1,y1)=(1,1) is the point at infinity. Third line consists of two integers 1x2,y2<2311 where (x2,y2)=(1,1) is the point at infinity.

Output

Output one line with the coordinates of PQ seperated by space. Both coordinates should be 1 if the result is the point at infinity.

Sample Input 1 Sample Output 1
13 0 1
5 3
2 3
6 10
Sample Input 2 Sample Output 2
17 1 0
11 13
11 4
-1 -1
Hide

Please log in to submit a solution to this problem

Log in