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 C# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	class Pair{
		public int X,Y;
		public Pair(int x, int y){
			X = x; Y = y;
		}
	}
	public void Solve(){
		
		var h = new HashSet<int>();
		for(int i=0;i<N;i++){
			h.Add(X[i]);
			h.Add(Y[i]);
		}
		var hl = h.ToList();
		hl.Sort();
		var di = new Dictionary<int,int>();
		for(int i=0;i<hl.Count;i++){
			di.Add(hl[i], i);
		}
		for(int i=0;i<N;i++){
			X[i] = di[X[i]];
			Y[i] = di[Y[i]];
		}
		
		mlong[] Pow2 = new mlong[N + 1];
		Pow2[0] = 1;
		for(int i=1;i<=N;i++) Pow2[i] = Pow2[i-1] * 2;
		
		
		Pair[] P = new Pair[N];
		for(int i=0;i<N;i++){
			P[i] = new Pair(X[i], Y[i]);
		}
		
		Array.Sort(P, (p, q) => p.X.CompareTo(q.X));
		
		int M = di.Count + 10;
		var BT0 = new BIT(M + 10);
		var BT1 = new BIT(M + 10);
		for(int i=0;i<N;i++) BT1.Add(P[i].Y + 1, 1);
		
		mlong prob = 0;
		for(int i=0;i<N;i++){
			BT1.Add(P[i].Y + 1, -1);
			mlong p0 = Pow2[N-1];
			
			
			int[] cc = new int[4];
			cc[0] = BT0.Sum(P[i].Y);
			cc[1] = BT0.Sum(M) - cc[0];
			cc[2] = BT1.Sum(P[i].Y);
			cc[3] = BT1.Sum(M) - cc[2];
//Console.WriteLine(String.Join(" ",cc));
			for(int t=0;t<(1<<4);t++){
				if(((t & 0x9) == 0x9) || ((t & 0x6) == 0x6)){
					mlong cnt = 1;
					for(int j=0;j<4;j++){
						if((t >> j) % 2 == 0) continue;
						cnt *= (Pow2[cc[j]] - 1);
					}
//Console.WriteLine("t;{0}, cnt:{1}",t,cnt);				
					p0 += cnt;
				}
			}
			prob += p0;
//Console.WriteLine(p0);
			BT0.Add(P[i].Y + 1, 1);
		}
		
		Console.WriteLine(prob);
		
		
		
	}
	int N;
	int[] X,Y;
	public Sol(){
		N = ri();
		X = new int[N];
		Y = new int[N];
		for(int i=0;i<N;i++){
			var d = ria();
			X[i] = d[0];
			Y[i] = d[1];
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


class BIT{
	int MM;
	int n;
	int[] bit;
	public BIT(int n_){
		n = n_;
		MM = 1 << 2;
		while(MM < n * 2) MM <<= 1;
		bit = new int[MM + 1];
	}
	//1-origin!! [0, i);
	public void Add(int i, int x){
		while(i <= n){
			bit[i] += x;
			i += (i&-i);
		}
	}
	
	// i=>sum(a_1,...,a_i)
	// i=0 -> return 0;
	public int Sum(int i){
		int s = 0;
		while(i > 0){
			s += bit[i];
			i -= (i&-i);
		}
		return s;
	}
}


struct mlong {
	const long mod = (long) 998244353;
	public const long Mod = mod;
	long V;
	
	public mlong(long _v = 0){
		V = _v;
	}
	
	public static mlong operator+(mlong a, mlong b){
		var v0 = a.V + b.V; if(v0 >= mod) v0 -= mod;
		return new mlong(v0);
	}
	public static mlong operator-(mlong a, mlong b){
		var v0 = mod + a.V - b.V; if(v0 >= mod) v0 -= mod;
		return new mlong(v0);
	}
	public static mlong operator*(mlong a, mlong b){
		var v0 = a.V * b.V; if(v0 >= mod) v0 %= mod;
		return new mlong(v0);
	}
	public static mlong operator/(mlong a, mlong b){
		var v0 = a.V * inv(b.V).V; if(v0 >= mod) v0 %= mod;
		return new mlong(v0);
	}
	
	
	public static mlong inv(long x){
		long a = 0, b = 0, c = 0;
		ExtGCD(x, mod, ref a, ref b, ref c);
		return (mlong)((a + mod) % mod);
	}
	
	public static void ExtGCD(long x, long y, ref long a, ref long b, ref long c){
		long r0 = x; long r1 = y;
		long a0 = 1; long a1 = 0;
		long b0 = 0; long b1 = 1;
		long q1, r2, a2, b2;
		while(r1 > 0){
			q1 = r0 / r1;
			r2 = r0 % r1;
			a2 = a0 - q1 * a1;
			b2 = b0 - q1 * b1;
			r0 = r1; r1 = r2;
			a0 = a1; a1 = a2;
			b0 = b1; b1 = b2;
		}
		c = r0;
		a = a0;
		b = b0;
	}
	
	public static mlong ModPow(mlong a, long k){
		if(k == 0) return (mlong) 1;
		if(a == 0) return (mlong) 0;
		mlong x = a;
		mlong ret = 1;
		while(k > 0){
			if(k % 2 == 1) ret *= x;
			x *= x;
			k >>= 1;
		}
		return ret;
	}
	
	
	public static bool operator == (mlong a, mlong b){
		 return a.Equals(b);
	}
	public static bool operator != (mlong a, mlong b){
		 return !(a == b);
	}
	
	public override bool Equals(System.Object obj){
		if(obj  ==  null) return false;
		mlong p  =  (mlong) obj;
		if((System.Object) p  ==  null) return false;
		return p.V  ==  V;
	}
	public override int GetHashCode(){
		return V.GetHashCode();
	}
	
	public static implicit operator mlong(long n){
		long v = n % mod; if(v < 0) v += mod;
		return new mlong(v);
	}
	public static implicit operator mlong(int n){
		long v = n % mod; if(v < 0) v += mod;
		return new mlong(v);
	}
	public static explicit operator long(mlong n){
		return n.V;
	}
	
	public override String ToString(){
		return V.ToString();
	}
	
	
}