import math,bisect,itertools
n=2000000
infty=10**8
p={}
a=b=1
for i in range(n):
a=(a*1248)%32323
b=(b*8421)%30103
x=a-16161
y=b-15051
d=math.gcd(x,y)
x//=d
y//=d
p[(x,y)]=p.get((x,y),0)+1
tick=len(p)*2//100
res=0
step=0
for r in range(4):
s,t=zip(*sorted((-infty if x==0 else -(y/x), c) for (x,y),c in p.items() if x>0 or (x==0 and y>0)))
s=[-infty]+list(s)+[infty]
t=[0]+list(t)+[0]
v=[0]+list(itertools.accumulate(t))
for (x,y),c in p.items():
if x < 0:
f=-(y/x)
i=bisect.bisect_left(s,f)
res+=v[i]*(v[-1]-v[i]-(s[i]==f)*t[i])*c
step+=1
if step%tick==0:
print(step//tick,"percent completed, current sum:", res)
if r < 3:
p={(-y,x):c for (x,y),c in p.items()}
else:
print(res//2)