import sugar, system, strutils, sequtils, tables, algorithm const MOD = 998244353 # mod 998244353のFenwickTree type FenwickTreeMod = object n: int data: seq[int] proc init(self: typedesc[FenwickTreeMod], n: int): FenwickTreeMod = return self(n: n, data: newSeq[int](n + 1)) proc add(self: var FenwickTreeMod, k, x: int): void = var p = k p.inc while p <= self.n: self.data[p] = (self.data[p] + x) mod MOD p += p and -p proc sum(self: FenwickTreeMod, k: int): int = var p = k res = 0 while p != 0: res = (res + self.data[p]) mod MOD p -= p and -p return res # 座標圧縮 proc compress(a: seq[int]): Table[int, int] = var mem: Table[int, int] for idx, elm in a.sorted.deduplicate(isSorted = true): mem[elm] = idx return mem # 入力 var N = stdin.readline.parseInt var X, Y = newSeq[int](N) for i in 0.. X[N - 1]: X.applyIt(-it) if Y[0] > Y[N - 1]: Y.applyIt(-it) # y座標を圧縮 var mem = compress(Y) Y.applyIt(mem[it]) # x, y座標が範囲内の点のみソート var points = collect newSeq: for (i, j) in zip(X, Y): if X[0] <= i and i <= X[N - 1] and Y[0] <= j and j <= Y[N - 1]: (x:i, y:j) points.sort # DP var ft = FenwickTreeMod.init(mem.len) ft.add(Y[0], 1) for i in 1..