# Good Subsets

You are given $n$ segments on the $Ox$ axis. The $i$-th segment is given as a pair $l_i, r_i$, where $l_i$ is the position of the left end of the $i$-th segment and $r_i$ is the position of the right end of the $i$-th segment. Segments may intersect, overlap, or even coincide. A segment is a set of numbers (including floating-point numbers) lying between the segment ends or coinciding with them. Formally, the segment $[l, r]=\{x~|~x \in \Bbb{R},~l \le x \le r\}$.

Let the union of segments be the set of all axis points covered by the set of segments. Let’s call a subset of the given segments good if its union equals the union of all $n$ segments.

Your task is to calculate the number of good subsets of the given $n$ segments. Since the answer may be very large, print it modulo $998244353$.

Input

The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of segments.

The next $n$ lines contain segments. The $i$-th segment is given as a pair $l_i, r_i$ ($1 \le l_i \le r_i \le 10^9$), where $l_i$ is the left border of the segment and $r_i$ is the right border of the segment. Segments may intersect, overlap, or even coincide.

Output

Print the number of good subsets of the given set of segments. Since the answer may be very large, print it modulo $998244353$.

Examples

input

3
1 1
2 6
1 6


output

4


input

2
3 4
2 5


output

2


input

4
1 2
5 5
2 3
1 3


output

5

Solution:

val md = 998244353

fun add(a: Int, b: Int) = (a + b) % md
fun mul(a: Int, b: Int) = ((a.toLong() * b) % md).toInt()

var sum = IntArray(0)
var push = IntArray(0)

fun modify(x: Int, l: Int, r: Int, ll: Int, rr: Int, v: Int) {
if (r < ll || rr < l) {
return
}
if (ll <= l && r <= rr) {
if (v >= 0) {
} else {
sum[x] = mul(sum[x], 2)
push[x] = mul(push[x], 2)
}
return
}
if (push[x] != 1) {
push[x + x] = mul(push[x + x], push[x])
sum[x + x] = mul(sum[x + x], push[x])
push[x + x + 1] = mul(push[x + x + 1], push[x])
sum[x + x + 1] = mul(sum[x + x + 1], push[x])
push[x] = 1
}
val y = (l + r) shr 1
if (ll <= y) {
modify(x + x, l, y, ll, rr, v)
}
if (rr > y) {
modify(x + x + 1, y + 1, r, ll, rr, v)
}
sum[x] = add(sum[x + x], sum[x + x + 1])
}

fun getSum(x: Int, l: Int, r: Int, ll: Int, rr: Int) : Int {
if (r < ll || rr < l) {
return 0
}
if (ll <= l && r <= rr) {
return sum[x]
}
if (push[x] != 1) {
push[x + x] = mul(push[x + x], push[x])
sum[x + x] = mul(sum[x + x], push[x])
push[x + x + 1] = mul(push[x + x + 1], push[x])
sum[x + x + 1] = mul(sum[x + x + 1], push[x])
push[x] = 1
}
val y = (l + r) shr 1
var res = 0
if (ll <= y) {
res = add(res, getSum(x + x, l, y, ll, rr))
}
if (rr > y) {
res = add(res, getSum(x + x + 1, y + 1, r, ll, rr))
}
sum[x] = add(sum[x + x], sum[x + x + 1])
return res
}

fun main(args: Array<String>) {
val from = IntArray(n)
val to = IntArray(n)
for (i in 0 until n) {
val (foo, bar) = readLine()!!.split(" ").map { it.toInt() }
from[i] = foo
to[i] = bar
}
val coords = Array<Pair<Int, Int>>(2 * n, {i -> if (i < n) Pair(from[i], i) else Pair(to[i - n], i)})
coords.sortBy({x -> x.first})
var last = -1
var t = -1
for (c in coords) {
if (c.first > last) {
last = c.first
++t
}
if (c.second < n) {
from[c.second] = 2 * t
} else {
to[c.second - n] = 2 * t
}
}
t = 2 * t + 1
var balance = IntArray(t + 1)
for (i in 0 until n) {
balance[from[i]]++
balance[to[i] + 1]--
}
for (i in 0 until t) {
balance[i + 1] += balance[i]
}
var mapReal = IntArray(t + 1)
var iReal = -1
for (i in 0 until t) {
if (balance[i] != 0) {
iReal++
mapReal[i] = iReal
}
}
t = iReal + 1
for (i in 0 until n) {
from[i] = mapReal[from[i]]
to[i] = mapReal[to[i]]
}
var iOrder = IntArray(n)
for (i in 0 until n) {
iOrder[i] = i
}
var order = iOrder.sortedBy({i -> from[i]})
var p2 = IntArray(n + 1)
p2[0] = 1
for (i in 1..n) {
p2[i] = mul(p2[i - 1], 2)
}
var dp = IntArray(n)
sum = IntArray(4 * t + 10)
push = IntArray(4 * t + 10)
for (i in 0 until 4 * t + 10) {
push[i] = 1
}
modify(1, 0, t - 1, 0, 0, 1)
var left = n
var ans = 0
for (i in order) {
left--
dp[i] = getSum(1, 0, t - 1, from[i], to[i])
if (to[i] == t - 1) {