/* -*- coding: utf-8 -*- * * 1864.cc: No.1864 Shortest Paths Counting - yukicoder */ #include #include #include using namespace std; /* constant */ const int MAX_N = 200000; const int MOD = 998244353; /* typedef */ typedef long long ll; typedef pair pii; template struct BIT { int n; vector bits; BIT() {} BIT(int _n) { init(_n); } void init(int _n) { n = _n; bits.resize(n + 1, 0); } T sum(int x) { x = min(x, n); T s = 0; while (x > 0) { s = (s + bits[x]) % MOD; x -= (x & -x); } return s; } void add(int x, T v) { if (x <= 0) return; while (x <= n) { bits[x] = (bits[x] + v) % MOD; x += (x & -x); } } }; /* global variables */ int xs[MAX_N], ys[MAX_N], uys[MAX_N]; pii ps[MAX_N]; BIT bit; /* subroutines */ bool cmppii(const pii &a, const pii &b) { return a.first < b.first || (a.first == b.first && a.second > b.second); } /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { int xi, yi; scanf("%d%d", &xi, &yi); xs[i] = xi + yi, ys[i] = xi - yi; } bool xrv = (xs[0] > xs[n - 1]); bool yrv = (ys[0] > ys[n - 1]); for (int i = 0; i < n; i++) { if (xrv) xs[i] = -xs[i]; if (yrv) ys[i] = -ys[i]; } int x0 = xs[0], y0 = ys[0]; int gx = xs[n - 1] - x0, gy = ys[n - 1] - y0; int m = 0; for (int i = 0; i < n; i++) { int xi = xs[i] - x0, yi = ys[i] - y0; if (0 <= xi && xi <= gx && 0 <= yi && yi <= gy) ps[m++] = pii(xi, yi); } if (m > 2) sort(ps + 1, ps + m - 1); //for (int i = 0; i < m; i++) printf("%d,%d ", ps[i].first, ps[i].second); //putchar('\n'); for (int i = 0; i < m; i++) uys[i] = ps[i].second; sort(uys, uys + m); int k = unique(uys, uys + m) - uys; bit.init(k); bit.add(1, 1); for (int i = 1; i < m - 1; i++) { int yi = lower_bound(uys, uys + k, ps[i].second) - uys; int di = bit.sum(yi + 1); bit.add(yi + 1, di); } int sum = bit.sum(k); printf("%d\n", sum); return 0; }