from Crypto.Util.number import inverse
#--------Functions--------#
def point_addition(P, Q):
# If P = O, then P + Q = Q
# If Q = O, then P + Q = P
# Otherwise, write P = (x1, y1) and Q = (x2, y2)
# If x1 = x2 and y1 = -y2, then P + Q = O
if x1 == x2 and y1 == -y2:
# Otherwise, if P ≠ Q: λ = (y2 - y1) / (x2 - x1)
lam = ((y2 - y1) * inverse(x2 - x1, p)) % p
# If P = Q: λ = (3 * x1**2 + a) / 2 * y1
lam = ((3 * x1**2 + a) * inverse(2 * y1, p)) % p
# x3 = λ**2 - x1 - x2, y3 = λ *( x1 - x3) - y1
x3 = (lam**2 - x1 - x2) % p
y3 = (lam * (x1 - x3) - y1) % p
def scalar_multiplication(n, P):
# If n ≡ 1 mod 2, set R = R + Q
# Set Q = 2 Q and n = ⌊n/2⌋.
#--------Testing--------#
# print(scalar_multiplication(1337, X))
print(scalar_multiplication(7863, P))