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: Wrong Answer)

using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
    long mod = 998244353;
    long answer = 0;
		long n = long.Parse(Console.ReadLine());
    long[][] vertexes = new long[n][];
    long[] twoPows = new long[200001];//2のk乗
    long twoPowMemo = 1;
    for(long i = 0; i <= 200000; i++)
    {
      twoPows[i] = twoPowMemo;
      twoPowMemo *= 2;//2のk乗を先にメモ
      twoPowMemo %= mod;
    }
    
    for(long i = 0; i < n; i++)
    {
      vertexes[i] = new long[2];
      long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
      vertexes[i][0] = nums[0];
      vertexes[i][1] = nums[1];
    }
    Array.Sort(vertexes, (a, b) => a[0].CompareTo(b[0]));

    long[,] yPositions = new long[n,2];
    for(long i = 0; i < n; i++)
    {
      yPositions[i,0] = vertexes[i][1];
      yPositions[i,1] = i;
    }
    yPositions = CoordinateCompression(yPositions);

    long[] leftUnder = new long[n];//左にある小さい数
    long[] rightUnder = new long[n];//右にある小さい数
    long[] leftMore = new long[n];
    long[] rightMore = new long[n];
    long[] bitsLeft = new long[n+1];
    long[] bitsRight = new long[n+1];

    for(long i = 0; i < n; i++)
    {
      BitAdd(bitsLeft, yPositions[i,2]+1, 1);
      leftUnder[i] = BitSum(bitsLeft, yPositions[i,2]);
      leftMore[i] = i-leftUnder[i];
    }

    for(long i = n-1; i >= 0; i--)
    {
      BitAdd(bitsRight, yPositions[i,2]+1, 1);
      rightUnder[i] = BitSum(bitsRight, yPositions[i,2]);
      rightMore[i] = (n-1-i)-rightUnder[i];
    }

    answer += twoPows[n-1]*n;
    answer %= mod;

    for(long i = 0; i < n; i++)
    {
      long answerMemoLeft = 0;
      long answerMemoRight = 0;
      
      if(leftUnder[i] * rightMore[i] != 0)
      {
        answerMemoLeft += twoPows[i];
        answerMemoLeft -= twoPows[i-leftUnder[i]];
        answerMemoLeft %= mod;
        if(answerMemoLeft < 0) answerMemoLeft += mod;

        answerMemoRight += twoPows[n-1-i];
        answerMemoRight -= twoPows[n-1-i-rightMore[i]];
        answerMemoRight %= mod;
        if(answerMemoRight < 0) answerMemoRight += mod;

        answer += answerMemoLeft*answerMemoRight;
        answer %= mod;
      }

      answerMemoLeft = 0;
      answerMemoRight = 0;

      if(leftMore[i] * rightUnder[i] != 0)
      {
        answerMemoLeft += twoPows[i];
        answerMemoLeft -= twoPows[i-leftMore[i]];
        answerMemoLeft %= mod;
        if(answerMemoLeft < 0) answerMemoLeft += mod;

        answerMemoRight += twoPows[n-1-i];
        answerMemoRight -= twoPows[n-1-i-rightUnder[i]];
        answerMemoRight %= mod;
        if(answerMemoRight < 0) answerMemoRight += mod;

        answer += answerMemoLeft*answerMemoRight;
        answer %= mod;
      }
    }
    
		Console.WriteLine(answer);
	}

  static long[,] CoordinateCompression(long[,] vertexesOriginal)
    //1次元の座標圧縮。配列は0-indexで引数[x,順番]から[x,順番,圧縮x]を返す。
    //例えば、{2,4,4,3}は{0,2,2,1}を返す。
  {
    long n = vertexesOriginal.GetLength(0);//多次元配列の長さの取得
    long xCount = 1;//圧縮後のxの個数
    long[] compressedXmemo = new long[n];
    long[][] vertexes = new long[n][];
    for(long i = 0; i < n; i++)
    {
      vertexes[i] = new long[3];
      for(long j = 0; j < 2; j++)
      {
        vertexes[i][j] = vertexesOriginal[i,j];//配列をジャグ配列に置換
      }
    }

    Array.Sort(vertexes, (a, b) => a[0].CompareTo(b[0]));//x座標でソート
    vertexes[0][2] = 0;
    compressedXmemo[0] = vertexes[0][0];
    for(long i = 1; i < n; i++)
    {
      if(vertexes[i][0] == vertexes[i-1][0])//x座標が同じ
      {
        vertexes[i][2] = xCount - 1;
      }else
      {
        xCount++;
        vertexes[i][2] = xCount - 1;
        compressedXmemo[xCount-1] = vertexes[i][0];
      }
    }
    long[] compressedX = new long[xCount];
    for(long i = 0; i < xCount; i++) compressedX[i] = compressedXmemo[i];

    Array.Sort(vertexes, (a, b) => a[1].CompareTo(b[1]));//もとの番号順でソート

    long[,] answer = new long[n,3];
    for(long i = 0; i < n; i++)
    {
      for(long j = 0; j < 3; j++)
      {
        answer[i,j] = vertexes[i][j];//ジャグ配列から戻す
      }
    }

    return answer;//[x,順番,圧縮x]を返す。
  }

  static long[] BitAdd(long[] bits, long i, long x)//BITでiだけにx加算。O(logn)
  {
    long n = bits.Length-1;
    while(i <= n)
    {
      bits[i] += x;
      i += i&-i;
    }
    return bits;
  }

  static long BitSum(long[] bits, long i)//BITでi以下の総和を計算。O(logn)
  {
    long sum = 0;
    while(i > 0)
    {
      sum += bits[i];
      i -= i&-i;
    }
    return sum;
  }
  
}