#include #include using namespace std; using Mint = atcoder::modint998244353; int main() { int N, X; scanf("%d%d", &N, &X); vector xx(N), yy(N); vector y(N); for (int i = 0; i < N; i++) scanf("%d%d", &xx[i], &yy[i]); for (int i = 0; i < N; i++) if (xx[i] == X) { Mint ans = yy[i] * (N - 1); for (int j = 0; j < N; j++) if (j != i) { Mint u = yy[j], d = 1; for (int k = 0; k < N; k++) if (k != j && k != i) { u *= X - xx[k]; d *= xx[j] - xx[k]; } ans += u / d; } cout << ans.val() << endl; return 0; } for (int j = 0; j < N; j++) { Mint u = 1; Mint d = 1; for (int i = 0; i < N; i++) if (j != i) { u *= X - xx[i]; d *= xx[j] - xx[i]; } y[j] = Mint(yy[j]) * u / d; } vector Xinv(N); for (int i = 0; i < N; i++) Xinv[i] = Mint(X - xx[i]).inv(); Mint ans = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) if (j != i) { ans += y[j] * (xx[j] - xx[i]) * Xinv[i]; } } printf("%d\n", ans.val()); }