Hide

Problem A
Elliptic Curve Addition

Languages en is

Let $p$ be a prime and $a,b\in \mathbb {F}_p$ such that $4a^3 + 27b^2 \not\equiv 0 \pmod{p}$. Let $P=(x_1,y_1)$ and $Q=(x_2,y_2)$ be two points on the elliptic curve $E : y^2 = x^3+ax+b$. Calcuate $P \oplus Q$ given $p, a, b, x_1, y_1, x_2$ and $y_2$.

Input

First line consists of three integers, $0 < p < 2^{31}-1$, $0 \leq a < p$ and $0 \leq b < p$, where $p$ is a prime. Second line consist of two integers $-1 \leq x_1, y_1 < 2^{31}-1$ where $(x_1,y_1)=(-1,-1)$ is the point at infinity. Third line consists of two integers $-1 \leq x_2, y_2 < 2^{31}-1$ where $(x_2,y_2)=(-1,-1)$ is the point at infinity.

Output

Output one line with the coordinates of $P \oplus Q$ 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