import sys from collections import defaultdict MOD = 998244353 def main(): N = int(sys.stdin.readline()) points = [] for _ in range(N): x, y = map(int, sys.stdin.readline().split()) points.append((x, y)) x1, y1 = points[0] xN, yN = points[-1] dx = abs(x1 - xN) dy = abs(y1 - yN) d = max(dx, dy) valid = [] for i in range(N): x, y = points[i] a = max(abs(x - x1), abs(y - y1)) b = max(abs(x - xN), abs(y - yN)) if a + b == d: valid.append((a, x, y, i)) valid.sort(key=lambda t: t[0]) groups = defaultdict(list) for a, x, y, idx in valid: groups[a].append((x, y, idx)) dp = defaultdict(int) node_map = {} for a, x, y, idx in valid: node_map[(x, y)] = idx if idx == 0: dp[(x, y)] = 1 for current_a, x, y, idx in valid: if idx == 0: continue total = 0 delta_possible = [] for a_prev in groups: if a_prev < current_a: delta = current_a - a_prev delta_possible.append((a_prev, delta)) for a_prev, delta in delta_possible: x_list = groups[a_prev] for xv, yv, _ in x_list: if max(abs(xv - x), abs(yv - y)) == delta: total += dp.get((xv, yv), 0) total %= MOD dp[(x, y)] = total % MOD xN, yN = points[-1] print(dp.get((xN, yN), 0) % MOD) if __name__ == "__main__": main()