from gmpy2 import *
from math import *
from libnum import *
from pwn import *
from Crypto.Util.number import *
from tqdm import *
p = 9259018534502783714631247560818133078409930397939705162361230465031580254504264713899169170790687716589100652406132800533397486109926387016562663961524649
a = 0
b = 6235467631650349040636525320446729529985562949423449382969614887116983248527693872546808737512375916974084741892428681798937790855872528526403738040908493
c = 4165903654767429195543540819098180314477702137507994424192636596518008877139978822038616746899053449640020812062736993008962585578921635697413459959685760
d = 1889382340373247565387211782596794283852946561870564309251998196824383297786878212641581641540685106266683503654620956037368416192796434147249748216284648
e = 3015564788819504594313842562882781366361783108618226049128986996153057550014499326419988348165744003693083108924831219996703133056523468396967900376388617
G = (1244884551970947614719458919805713649754289814760243366205012699871413235954279930743612403791919112394457579170253990713250052822262255880036254772609156, 4579639528751113977115209571728128585569082149696598770106934145500742785077382446292613925719404433141749168427443122707253164477493499731016883616496009)
P = (9039120379228240875764080238389949393433230267005269099421166553853462484353350917730468887801035670710981414900285176863179650428412616144755102163764906, 6266065680737729548475090556806928225106996606788926050268440244885398464756877886842570309216095272026404453765198968208595242208306240371310555394416694)
A=(d-(b**2)*inverse(3,p))%p
e1=(e+(c**2)*inverse(4,p))%p
B=(e1+2*(b**3)*inverse(27,p)-b*d*inverse(3,p))%p
de=(4*(A**3)+27*(B**2))%p
r=(-b*inverse(3,p))%p
print(r)
phip=((P[0]-r)*inverse(P[1]+c*inverse(2,p),p))%p
phig=((G[0]-r)*inverse(G[1]+c*inverse(2,p),p))%p
k=(phip*inverse(phig,p))%p
print(k)
print(f"flag={long_to_bytes(k)}")