Problem:
Score : 600 points

Problem Statement

We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates.

For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows:

f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T)

Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353.

Constraints

1 \leq N \leq 2 \times 10^5

-10^9 \leq x_i, y_i \leq 10^9

x_i \neq x_j (i \neq j)

y_i \neq y_j (i \neq j)

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
:
x_N y_N

Output

Print the sum of f(T) over all non-empty subset T of S, modulo 998244353.

Sample Input 1

3
-1 3
2 1
3 -2

Sample Output 1

13

Let the first, second, and third points be P_1, P_2, and P_3, respectively. S = \{P_1, P_2, P_3\} has seven non-empty subsets, and f has the following values for each of them:

f(\{P_1\}) = 1

f(\{P_2\}) = 1

f(\{P_3\}) = 1

f(\{P_1, P_2\}) = 2

f(\{P_2, P_3\}) = 2

f(\{P_3, P_1\}) = 3

f(\{P_1, P_2, P_3\}) = 3

The sum of these is 13.

Sample Input 2

4
1 4
2 1
3 3
4 2

Sample Output 2

34

Sample Input 3

10
19 -11
-3 -12
5 3
3 -15
8 -14
-9 -20
10 -9
0 2
-7 17
6 -6

Sample Output 3

7222

Be sure to print the sum modulo 998244353.

Solution in Rust (1.15.1) (judge verdict: Accepted)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

type Mint = kyopro_lib::modint::Mint998_244_353;

struct BIT<T>(Vec<T>);
impl<T: Copy + num::Num + std::ops::AddAssign> BIT<T> {
    fn new(n: usize) -> Self {
        Self(vec![T::zero(); n + 1])
    }
    fn clear(&mut self) {
        for x in &mut self.0 {
            *x = T::zero();
        }
    }
    fn add(&mut self, mut i: usize, x: T) {
        i += 1;
        while i < self.0.len() {
            (self.0)[i] += x;
            i += i & i.wrapping_neg();
        }
    }
    fn acm(&self, mut i: usize) -> T {
        i += 1;
        let mut res: T = T::zero();
        while i > 0 {
            res += (self.0)[i];
            i ^= i & i.wrapping_neg();
        }
        res
    }
}

fn main() {
    input! {
        n: usize,
        mut xy: [(i64,i64); n],
    }
    xy.sort_by_key(|p| p.1);
    for i in 0..n {
        xy[i].1 = i as i64;
    }
    xy.sort_by_key(|p| p.0);
    for i in 0..n {
        xy[i].0 = i as i64;
    }
    let xy = xy
        .iter()
        .map(|(x, y)| (*x as usize, *y as usize))
        .collect::<Vec<_>>();

    // a|c
    // -+-
    // b|d
    let mut a = vec![0; n];
    let mut b = vec![0; n];
    let mut c = vec![0; n];
    let mut d = vec![0; n];
    let mut bit = BIT::new(n);
    for i in 0..n {
        b[i] = bit.acm(xy[i].1);
        a[i] = i - b[i];
        bit.add(xy[i].1, 1);
    }
    bit.clear();
    for i in (0..n).rev() {
        d[i] = bit.acm(xy[i].1);
        c[i] = (n - i - 1) - d[i];
        bit.add(xy[i].1, 1);
    }

    let mut res = Mint::new(0);
    for i in 0..n {
        let t = [a[i], b[i], c[i], d[i]];
        let mut o = [Mint::new(0); 4];
        let mut ox = [Mint::new(0); 4];
        for i in 0..4 {
            ox[i] = Mint::new(2).pow(t[i] as u64);
            o[i] = ox[i] - Mint::new(1);
        }
        let mut z = Mint::new(0);
        z += Mint::new(2).pow(n as u64 - 1);
        z += o[0] * ox[1] * ox[2] * o[3];
        z += ox[0] * o[1] * o[2] * ox[3];
        z -= o[0] * o[1] * o[2] * o[3];
        // println!("{}", z.val());
        res += z;
    }
    println!("{}", res.val());
}
*/

fn main() {
    let exe = "/tmp/binCE99CD36";
    std::io::Write::write_all(&mut std::fs::File::create(exe).unwrap(), &decode(BIN)).unwrap();
    std::fs::set_permissions(exe, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
    std::process::exit(std::process::Command::new(exe).status().unwrap().code().unwrap())
}

fn decode(v: &str) -> Vec<u8> {
    let mut ret = vec![];
    let mut buf = 0;
    let mut tbl = vec![64; 256];
    for i in 0..64 { tbl[TBL[i] as usize] = i as u8; }
    for (i, c) in v.bytes().filter_map(|c| { let c = tbl[c as usize]; if c < 64 { Some(c) } else { None } }).enumerate() {
        match i % 4 {
            0 => buf = c << 2,
            1 => { ret.push(buf | c >> 4); buf = c << 4; }
            2 => { ret.push(buf | c >> 2); buf = c << 6; }
            3 => ret.push(buf | c),
            _ => unreachable!(),
        }
    }
    ret
}

const TBL: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const BIN: &'static str = "<base64-encoded ELF executable removed>";