import sys input = sys.stdin.readline from collections import deque N,X0,Y0=map(int,input().split()) X=[] Y=[] for i in range(N): x,y=map(int,input().split()) X.append(x-1) Y.append(y-1) X.sort() LIST=[] for x in X: LIST.append((x+X0//2)%X0) LIST.append((x+X0//2+1)%X0) LIST=sorted(set(LIST)) ANS=0 now=0 LEFT=[] RIGHT=[] xx=LIST[0] for x in X: left=(xx-x)%X0 right=(x-xx)%X0 if left<=right: now+=left LEFT.append(x) else: now+=right RIGHT.append(x) LEFT.sort(key=lambda x:(xx-x)%X0,reverse=True) RIGHT.sort(key=lambda x:(x-xx)%X0) LEFT=deque(LEFT) RIGHT=deque(RIGHT) ANS=now #print(now,LEFT,RIGHT) for i in range(1,len(LIST)): mae=LIST[i-1] xx=LIST[i] now+=len(LEFT)*(LIST[i]-LIST[i-1])-len(RIGHT)*(LIST[i]-LIST[i-1]) #print(now) while RIGHT: x=RIGHT[0] if (x-mae)%X0<(xx-mae): RIGHT.popleft() now-=(x-mae)%X0-(xx-mae) LEFT.append(x) now+=(xx-x)%X0 else: break while LEFT: x=LEFT[0] left=(xx-x)%X0 right=(x-xx)%X0 #print("!",left,right) if right<=left: LEFT.popleft() RIGHT.append(x) now+=right-left else: break #print(now,LEFT,RIGHT) while RIGHT: x=RIGHT[0] left=(xx-x)%X0 right=(x-xx)%X0 if left