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 Go (1.6) (judge verdict: Accepted)

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	yy := make([]int, n)
	pp := make(Points, n)
	doubling := Doubling{}
	doubling.init()
	for i := 0; i < n; i++ {
		pp[i].x = getNextInt(scanner)
		pp[i].y = getNextInt(scanner)
		yy[i] = pp[i].y
	}

	sort.Sort(pp)
	sort.Ints(yy)

	yr := map[int]int{}
	for i := 0; i < n; i++ {
		yr[yy[i]] = i
	}

	var ans int64
	seg := Segment{}
	seg.init(n)

	wholecnt := doubling.count(n) - 1
	mod := doubling.mod

	for i := 0; i < n; i++ {
		rank := yr[pp[i].y]
		seg.add(rank, 1)
		// 左下にある個数
		ld := seg.rangesum(0, rank)
		// 左上にある個数
		lu := seg.rangesum(rank+1, n)
		// 右下にある個数
		rd := rank - ld
		// 右上にある個数
		ru := n - 1 - rd - ld - lu

		current := int64(0)

		// 左にあるもの加算
		current += doubling.count(ld+lu) - 1
		// 右にあるもの加算
		current += doubling.count(rd+ru) - 1
		// 上にあるもの加算
		current += doubling.count(lu+ru) - 1
		// 下にあるもの加算
		current += doubling.count(ld+rd) - 1
		// 左下にあるもの減算
		current -= doubling.count(ld) - 1
		// 左上にあるもの減算
		current -= doubling.count(lu) - 1
		// 右下にあるもの減算
		current -= doubling.count(rd) - 1
		// 右上にあるもの減算
		current -= doubling.count(ru) - 1

		ans += wholecnt - current
		ans %= mod
		ans = (ans + mod) % mod
	}

	fmt.Fprintln(writer, ans)
	writer.Flush()
}

type Doubling struct {
	d   []int64
	mod int64
}

func (doubling *Doubling) init() {
	doubling.mod = int64(998244353)
	doubling.d = make([]int64, 31)
	doubling.d[0] = 2
	for i := 1; i < 31; i++ {
		doubling.d[i] = doubling.d[i-1] * doubling.d[i-1]
		doubling.d[i] %= doubling.mod
	}
}
func (doubling *Doubling) count(c int) int64 {
	var a int64
	a = 1
	d := doubling.d
	mod := doubling.mod
	for i := 0; i < 31; i++ {
		if c>>uint(i)&1 == 0 {
			continue
		}
		a *= d[i]
		a %= mod
	}
	return a
}

type Point struct {
	x, y int
}

type Points []Point

func (a Points) Len() int           { return len(a) }
func (a Points) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Points) Less(i, j int) bool { return a[i].x < a[j].x }

// Segment ...
type Segment struct {
	n, h, i, chunk int
	unit           []int
	bucket         [][]int
}

func (seg *Segment) init(n int) {
	seg.n = n
	seg.unit = make([]int, 1)
	seg.unit[0] = 1
	seg.bucket = make([][]int, 1)
	seg.bucket[0] = make([]int, n)

	chunk := 8
	for i := 0; n > 1; i++ {
		n = (n-1)/chunk + 1
		seg.bucket = append(seg.bucket, make([]int, n))
		seg.unit = append(seg.unit, seg.unit[i]*chunk)
	}
	seg.h = len(seg.unit)
	seg.chunk = chunk
}
func (seg *Segment) add(index, value int) {
	for i := 0; i < seg.h; i++ {
		seg.bucket[i][index/seg.unit[i]] += value
	}
}
func (seg *Segment) rangeadd(l, r, value int) {
	i := 0
	for index := l; index < r; index += seg.unit[i] {
		for i < seg.h-1 && index%seg.unit[i+1] == 0 {
			i++
		}
		for index+seg.unit[i] > r {
			i--
		}
		ii := index / seg.unit[i]
		seg.bucket[i][ii] += value
	}
}
func (seg *Segment) rangesum(l, r int) int {
	var sum int
	i := 0
	for index := l; index < r; index += seg.unit[i] {
		for i < seg.h-1 && index%seg.unit[i+1] == 0 {
			i++
		}
		for index+seg.unit[i] > r {
			i--
		}
		ii := index / seg.unit[i]
		sum += seg.bucket[i][ii]
	}

	return sum
}