import sys readline=sys.stdin.readline def Tonelli_Shanks(N,p): if pow(N,p>>1,p)==p-1: retu=None elif p%4==3: retu=pow(N,(p+1)//4,p) else: for nonresidue in range(1,p): if pow(nonresidue,p>>1,p)==p-1: break pp=p-1 cnt=0 while pp%2==0: pp//=2 cnt+=1 s=pow(N,pp,p) retu=pow(N,(pp+1)//2,p) for i in range(cnt-2,-1,-1): if pow(s,1<>1+i,p) s%=p retu*=pow(nonresidue,p>>2+i,p) retu%=p return retu def Extended_Euclid(n,m): stack=[] while m: stack.append((n,m)) n,m=m,n%m if n>=0: x,y=1,0 else: x,y=-1,0 for i in range(len(stack)-1,-1,-1): n,m=stack[i] x,y=y,x-(n//m)*y return x,y class MOD: def __init__(self,p,e=None): self.p=p self.e=e if self.e==None: mod=self.p else: mod=self.p**self.e def Pow(self,a,n): a%=mod if n>=0: return pow(a,n,mod) else: #assert math.gcd(a,mod)==1 x=Extended_Euclid(a,mod)[0] return pow(x,-n,mod) def Build_Fact(self,N): assert N>=0 self.factorial=[1] if self.e==None: for i in range(1,N+1): self.factorial.append(self.factorial[-1]*i%mod) else: self.cnt=[0]*(N+1) for i in range(1,N+1): self.cnt[i]=self.cnt[i-1] ii=i while ii%self.p==0: ii//=self.p self.cnt[i]+=1 self.factorial.append(self.factorial[-1]*ii%mod) self.factorial_inve=[None]*(N+1) self.factorial_inve[-1]=self.Pow(self.factorial[-1],-1) for i in range(N-1,-1,-1): ii=i+1 while ii%self.p==0: ii//=self.p self.factorial_inve[i]=(self.factorial_inve[i+1]*ii)%mod def Build_Inverse(self,N): self.inverse=[None]*(N+1) assert self.p>N self.inverse[1]=1 for n in range(2,N+1): if n%self.p==0: continue a,b=divmod(mod,n) self.inverse[n]=(-a*self.inverse[b])%mod def Inverse(self,n): return self.inverse[n] def Fact(self,N): if N<0: return 0 retu=self.factorial[N] if self.e!=None and self.cnt[N]: retu*=pow(self.p,self.cnt[N],mod)%mod retu%=mod return retu def Fact_Inve(self,N): if self.e!=None and self.cnt[N]: return None return self.factorial_inve[N] def Comb(self,N,K,divisible_count=False): if K<0 or K>N: return 0 retu=self.factorial[N]*self.factorial_inve[K]%mod*self.factorial_inve[N-K]%mod if self.e!=None: cnt=self.cnt[N]-self.cnt[N-K]-self.cnt[K] if divisible_count: return retu,cnt else: retu*=pow(self.p,cnt,mod) retu%=mod return retu class Polynomial: def __init__(self,polynomial,max_degree=-1,eps=0,mod=0): self.max_degree=max_degree if self.max_degree!=-1 and len(polynomial)>self.max_degree+1: self.polynomial=polynomial[:self.max_degree+1] else: self.polynomial=polynomial mod=mod self.eps=eps def __eq__(self,other): if type(other)!=Polynomial: return False if len(self.polynomial)!=len(other.polynomial): return False for i in range(len(self.polynomial)): if self.epsself.max_degree+1: prod=prod[:self.max_degree+1] while prod and abs(prod[-1])<=self.eps: prod.pop() prod=Polynomial(prod,max_degree=self.max_degree,eps=self.eps,mod=mod) return prod def __pow__(self,other): if other==0: prod=Polynomial([1],max_degree=self.max_degree,eps=self.eps,mod=mod) elif other==1: prod=Polynomial([x for x in self.polynomial],max_degree=self.max_degree,eps=self.eps,mod=mod) else: prod=[1] doub=self.polynomial if mod: convolve=NTT convolve_Pow=NTT_Pow else: convolve=FFT convolve_Pow=FFT_Pow while other>=2: if other&1: prod=convolve(prod,doub) if self.max_degree!=-1: prod=prod[:self.max_degree+1] doub=convolve_Pow(doub,2) if self.max_degree!=-1: doub=doub[:self.max_degree+1] other>>=1 prod=convolve(prod,doub) if self.max_degree!=-1: prod=prod[:self.max_degree+1] prod=Polynomial(prod,max_degree=self.max_degree,eps=self.eps,mod=mod) return prod def __truediv__(self,other): if type(other)==Polynomial: assert other.polynomial for n in range(len(other.polynomial)): if self.epsn for i in range(n): assert abs(self.polynomial[i])<=self.eps self_polynomial=self.polynomial[n:] other_polynomial=other.polynomial[n:] if mod: inve=MOD(mod).Pow(other_polynomial[0],-1) else: inve=1/other_polynomial[0] quot=[] for i in range(len(self_polynomial)-len(other_polynomial)+1): if mod: quot.append(self_polynomial[i]*inve%mod) else: quot.append(self_polynomial[i]*inve) for j in range(len(other_polynomial)): self_polynomial[i+j]-=other_polynomial[j]*quot[-1] if mod: self_polynomial[i+j]%=mod for i in range(max(0,len(self_polynomial)-len(other_polynomial)+1),len(self_polynomial)): if self.eps>bit,mod) U=[1] for _ in range(a): U.append(U[-1]*x%mod) for i in range(1<>bit,mod) U=[1] for _ in range(a): U.append(U[-1]*x%mod) for i in range(1<=self.eps: n0=self.polynomial[cnt0]**.5 if n0==None: sqrt=None else: def f(prev): if mod: return NTT_Pow(prev,2)+[0] else: return FFT_Pow(prev,2)+[0] def differentiated_f(prev): retu=[0]*(2*len(prev)-1) for i in range(len(prev)): retu[i]+=2*prev[i] if mod: retu[i]%mod return retu sqrt=[0]*(cnt0//2)+Polynomial(self.polynomial[cnt0:],max_degree=self.max_degree-cnt0//2,mod=mod).Newton(n0,f,differentiated_f).polynomial sqrt=Polynomial(sqrt,max_degree=self.max_degree,eps=self.eps,mod=mod) else: sqrt=Polynomial([],max_degree=self.max_degree,eps=self.eps,mod=mod) return sqrt def exp(self): assert not self.polynomial or abs(self.polynomial[0])<=self.eps def f(prev,poly): newton=Polynomial(prev,max_degree=2*len(prev)-1,eps=self.eps,mod=mod).log().polynomial newton+=[0]*(2*len(prev)-len(newton)) for i in range(min(len(poly),len(newton))): newton[i]-=poly[i] if mod: for i in range(len(newton)): newton[i]%=mod if mod: return NTT(prev,newton)[:2*len(prev)] else: return FFT(prev,newton)[:2*len(prev)] return Polynomial(self.polynomial,max_degree=self.max_degree,mod=mod).Newton(1,f) def Degree(self): return len(self.polynomial)-1 def Hadamard(polynomial,n,mod=0,inverse=False): polynomial_=[x for x in polynomial]+[0]*((1<ii: continue polynomial_[i],polynomial_[ii]=polynomial_[i]+polynomial_[ii],polynomial_[i]-polynomial_[ii] if mod: polynomial_[i]%=mod polynomial_[ii]%=mod if inverse: if mod: inve_2=pow((mod+1)//2,n) for i in range(1< 0 a.pop() a.insert(0, 0) inv = [1, 1] for i in range(2, n): inv.append(-inv[mod%i] * (mod//i) % mod) a[i] = a[i] * inv[i] % mod return a def differentiate(a): n = len(a) assert n > 0 for i in range(2, n): a[i] = a[i] * i % mod a.pop(0) a.append(0) return a def convolution_naive(a, b): n = len(a) m = len(b) ans = [0] * (n + m - 1) if n < m: for j in range(m): for i in range(n): ans[i + j] = (ans[i + j] + a[i] * b[j]) % mod else: for i in range(n): for j in range(m): ans[i + j] = (ans[i + j] + a[i] * b[j]) % mod return ans def convolution_ntt(a, b): a = a.copy() b = b.copy() n = len(a) m = len(b) z = 1 << (n + m - 2).bit_length() a += [0] * (z - n) butterfly(a) b += [0] * (z - m) butterfly(b) for i in range(z): a[i] = a[i] * b[i] % mod butterfly_inv(a) a = a[:n + m - 1] iz = pow(z, mod - 2, mod) for i in range(n + m - 1): a[i] = a[i] * iz % mod return a def convolution_square(a): a = a.copy() n = len(a) z = 1 << (2 * n - 2).bit_length() a += [0] * (z - n) butterfly(a) for i in range(z): a[i] = a[i] * a[i] % mod butterfly_inv(a) a = a[:2 * n - 1] iz = pow(z, mod - 2, mod) for i in range(2 * n - 1): a[i] = a[i] * iz % mod return a def convolution(a, b): """It calculates (+, x) convolution in mod 998244353. Given two arrays a[0], a[1], ..., a[n - 1] and b[0], b[1], ..., b[m - 1], it calculates the array c of length n + m - 1, defined by > c[i] = sum(a[j] * b[i - j] for j in range(i + 1)) % 998244353. It returns an empty list if at least one of a and b are empty. Complexity ---------- > O(n log n), where n = len(a) + len(b). """ n = len(a) m = len(b) if n == 0 or m == 0: return [] if min(n, m) <= 60: return convolution_naive(a, b) if a is b: return convolution_square(a) return convolution_ntt(a, b) def inverse(a): n = len(a) assert n > 0 and a[0] != 0 res = [pow(a[0], mod - 2, mod)] m = 1 while m < n: f = a[:min(n,2*m)] + [0]*(2*m-min(n,2*m)) g = res + [0]*m butterfly(f) butterfly(g) for i in range(2*m): f[i] = f[i] * g[i] % mod butterfly_inv(f) f = f[m:] + [0]*m butterfly(f) for i in range(2*m): f[i] = f[i] * g[i] % mod butterfly_inv(f) iz = pow(2*m, mod-2, mod) iz = (-iz*iz) % mod for i in range(m): f[i] = f[i] * iz % mod res += f[:m] m <<= 1 return res[:n] def log(a): a = a.copy() n = len(a) assert n > 0 and a[0] == 1 a_inv = inverse(a) a=differentiate(a) a = convolution(a, a_inv)[:n] a=integrate(a) return a def exp(a): a = a.copy() n = len(a) assert n > 0 and a[0] == 0 g = [1] a[0] = 1 h_drv = a.copy() h_drv=differentiate(h_drv) m = 1 while m < n: f_fft = a[:m] + [0] * m butterfly(f_fft) if m > 1: _f = [f_fft[i] * g_fft[i] % mod for i in range(m)] butterfly_inv(_f) _f = _f[m // 2:] + [0] * (m // 2) butterfly(_f) for i in range(m): _f[i] = _f[i] * g_fft[i] % mod butterfly_inv(_f) _f = _f[:m//2] iz = pow(m, mod - 2, mod) iz *= -iz iz %= mod for i in range(m//2): _f[i] = _f[i] * iz % mod g.extend(_f) t = a[:m] t=differentiate(t) r = h_drv[:m - 1] r.append(0) butterfly(r) for i in range(m): r[i] = r[i] * f_fft[i] % mod butterfly_inv(r) im = pow(-m, mod - 2, mod) for i in range(m): r[i] = r[i] * im % mod for i in range(m): t[i] = (t[i] + r[i]) % mod t = [t[-1]] + t[:-1] t += [0] * m butterfly(t) g_fft = g + [0] * (2 * m - len(g)) butterfly(g_fft) for i in range(2 * m): t[i] = t[i] * g_fft[i] % mod butterfly_inv(t) t = t[:m] i2m = pow(2 * m, mod - 2, mod) for i in range(m): t[i] = t[i] * i2m % mod v = a[m:min(n, 2 * m)] v += [0] * (m - len(v)) t = [0] * (m - 1) + t + [0] t=integrate(t) for i in range(m): v[i] = (v[i] - t[m + i]) % mod v += [0] * m butterfly(v) for i in range(2 * m): v[i] = v[i] * f_fft[i] % mod butterfly_inv(v) v = v[:m] i2m = pow(2 * m, mod - 2, mod) for i in range(m): v[i] = v[i] * i2m % mod for i in range(min(n - m, m)): a[m + i] = v[i] m *= 2 return a def power(a,k): n = len(a) assert n>0 if k==0: return [1]+[0]*(n-1) l = 0 while l < len(a) and not a[l]: l += 1 if l * k >= n: return [0] * n ic = pow(a[l], mod - 2, mod) pc = pow(a[l], k, mod) a = log([a[i] * ic % mod for i in range(l, len(a))]) for i in range(len(a)): a[i] = a[i] * k % mod a = exp(a) for i in range(len(a)): a[i] = a[i] * pc % mod a = [0] * (l * k) + a[:n - l * k] return a def sqrt(a): if len(a) == 0: return [] if a[0] == 0: for d in range(1, len(a)): if a[d]: if d & 1: return None if len(a) - 1 < d // 2: break res=sqrt(a[d:]+[0]*(d//2)) if res == None: return None res = [0]*(d//2)+res return res return [0]*len(a) sqr = Tonelli_Shanks(a[0],mod) if sqr == None: return None T = [0] * (len(a)) T[0] = sqr res = T.copy() T[0] = pow(sqr,mod-2,mod) #T:res^{-1} m = 1 two_inv = (mod + 1) // 2 F = [sqr] while m <= len(a) - 1: for i in range(m): F[i] *= F[i] F[i] %= mod butterfly_inv(F) iz = pow(m, mod-2, mod) for i in range(m): F[i] = F[i] * iz % mod delta = [0] * (2 * m) for i in range(m): delta[i + m] = F[i] - a[i] - (a[i + m] if i+m len(a) - 1: break F = res[:2 * m] butterfly(F) eps = [F[i] * G[i] % mod for i in range(2 * m)] butterfly_inv(eps) for i in range(m): eps[i] = 0 iz = pow(2*m, mod-2, mod) for i in range(m,2*m): eps[i] = eps[i] * iz % mod butterfly(eps) for i in range(2 * m): eps[i] *= G[i] eps[i] %= mod butterfly_inv(eps) for i in range(m, 2 * m): T[i] = -eps[i]*iz T[i]%=mod iz = iz*iz % mod m <<= 1 return res def taylor_shift(a,c): a=a.copy() n=len(a) MD=MOD(mod) MD.Build_Fact(n-1) for i in range(n): a[i]*=MD.Fact(i) a[i]%=mod C=[1] for i in range(1,n): C.append(C[-1]*c%mod) for i in range(n): C[i]*=MD.Fact_Inve(i) C[i]%=mod a=convolution(a,C[::-1])[n-1:] for i in range(n): a[i]*=MD.Fact_Inve(i) a[i]%=mod return a def division_modulus(f,g): n=len(f) m=len(g) while m and g[m-1]==0: m-=1 assert m if n>=m: fR=f[::-1][:n-m+1] gR=g[:m][::-1][:n-m+1]+[0]*max(0,n-m+1-m) qR=convolution(fR,inverse(gR))[:n-m+1] q=qR[::-1] r=[(f[i]-x)%mod for i,x in enumerate(convolution(g,q)[:m-1])] while r and r[-1]==0: r.pop() else: q,r=[],f.copy() return q,r def multipoint_evaluation(f, x): n = len(x) sz = 1 << (n - 1).bit_length() g = [[1] for _ in range(2 * sz)] for i in range(n): g[i + sz] = [-x[i], 1] for i in range(1, sz)[::-1]: g[i] = convolution(g[2 * i],g[2 * i + 1]) g[1] =division_modulus(f,g[1])[1] for i in range(2, 2 * sz): g[i]=division_modulus(g[i>>1],g[i])[1] res = [g[i + sz][0] if g[i+sz] else 0 for i in range(n)] return res class Lagrange_Interpolation: def __init__(self,X=None,Y=None,x0=None,xd=None,mod=0): self.degree=len(Y)-1 mod=mod assert mod==0 or self.degree0 if mod: self.X=[(x0+i*xd)%mod for i in range(self.degree+1)] fact_inve=1 for i in range(1,self.degree+1): fact_inve*=i*xd fact_inve%=mod fact_inve=MOD(mod).Pow(fact_inve,-1) self.coefficient=[y for y in Y] for i in range(self.degree-1,-1,-2): self.coefficient[i]*=-1 for i in range(self.degree,-1,-1): self.coefficient[i]*=fact_inve self.coefficient[i]%=mod self.coefficient[self.degree-i]*=fact_inve self.coefficient[self.degree-i]%=mod fact_inve*=i*xd fact_inve%=mod else: self.X=[x0+i*xd for i in range(self.degree+1)] self.coefficient=[y for y in Y] for i in range(self.degree-1,-1,-2): self.coefficient[i]*=-1 fact=1 for i in range(1,self.degree+2): self.coefficient[i-1]/=fact self.coefficient[self.degree-i+1]/=fact fact*=i*xd else: self.X=X assert len(self.X)==self.degree+1 self.coefficient=[1]*(self.degree+1) for i in range(self.degree+1): for j in range(self.degree+1): if i==j: continue self.coefficient[i]*=X[i]-X[j] self.coefficient[i]%=mod for i in range(self.degree+1): self.coefficient[i]=MD.Pow(self.coefficient[i],-1)*Y[i]%mod def __call__(self,N): if mod: N%=mod XX=[N-x for x in self.X] XX_left=[1]*(self.degree+2) for i in range(1,self.degree+2): XX_left[i]=XX_left[i-1]*XX[i-1] if mod: XX_left[i]%=mod XX_right=[1]*(self.degree+2) for i in range(self.degree,-1,-1): XX_right[i]=XX_right[i+1]*XX[i] if mod: XX_right[i]%=mod if mod: return sum(XX_left[i]*XX_right[i+1]%mod*self.coefficient[i]%mod for i in range(self.degree+1))%mod else: return sum(XX_left[i]*XX_right[i+1]*self.coefficient[i] for i in range(self.degree+1)) N,a=map(int,readline().split()) X,Y=[],[] for _ in range(N): x,y=map(int,readline().split()) X.append(x) Y.append(y) mod=998244353 MD=MOD(mod) if a in X: i=X.index(a) LI=Lagrange_Interpolation([X[j] for j in range(N) if i!=j],[Y[j] for j in range(N) if i!=j],mod=mod) ans=(LI(a)+Y[i]*(N-1))%mod else: XX=[1]*N for i in range(N): for j in range(N): if i==j: continue XX[i]*=X[i]-X[j] XX[i]%=mod XX[i]=MD.Pow(XX[i],-1) A=1 for x in X: A*=a-x A%=mod inverse=[MD.Pow(a-x,-1) for x in X] ans=0 for i in range(N): for j in range(N): if i==j: continue ans+=A*inverse[i]%mod*inverse[j]%mod*Y[j]%mod*XX[j]%mod*(X[j]-X[i])%mod ans%=mod print(ans)