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: Time Limit Exceeded)

using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;

namespace ABC136F
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = ReadInt;
            long mod = 998244353;

            int[] x = new int[N];
            int[] y = new int[N];
            for (int i = 0; i < N; i++)
            {
                x[i] = ReadInt;
                y[i] = ReadInt;
            }

            //座標圧縮
            var toValueX = x.Distinct().OrderBy(v => v).ToArray();
            var toValueY = y.Distinct().OrderBy(v => v).ToArray();

            var indexFromValueTableX = toValueX.Select((value, index) => new { value, index }).ToDictionary(p => p.value, p => p.index);
            var indexFromValueTableY = toValueY.Select((value, index) => new { value, index }).ToDictionary(p => p.value, p => p.index);

            int countX = indexFromValueTableX.Count;
            int countY = indexFromValueTableY.Count;

            x = x.Select(v => indexFromValueTableX[v]).ToArray();
            y = y.Select(v => indexFromValueTableY[v]).ToArray();

            //x順にソート
            Point[] points = new Point[N];
            for (int i = 0; i < N; i++)
            {
                points[i] = new Point() { x = x[i], y = y[i] };
            }
            points = points.OrderBy(a => a.x).ToArray();
            for (int i = 0; i < N; i++)
            {
                x[i] = points[i].x;
                y[i] = points[i].y;
            }

            //1次元bit二つ
            BIT bitL = new BIT(N);
            BIT bitR = new BIT(N);
            for (int i = 0; i < N; i++)
            {
                bitR.Add(y[i] + 1, y[i] + 1, 1);
            }

            //各星について総数を求める.
            long ans = 0;
            long all = ModPow(2, N, mod);
            for (int i = 0; i < N; i++)
            {

                //スライド式
                long c1 = bitR.Sum(y[i] + 2, N);
                long c2 = bitL.Sum(y[i] + 2, N);
                long c3 = bitL.Sum(1, y[i]);
                long c4 = bitR.Sum(1, y[i]);

                long powRU = ModPow(2, c1, mod);
                long powLU = ModPow(2, c2, mod);
                long powLD = ModPow(2, c3, mod);
                long powRD = ModPow(2, c4, mod);

                long powU = ModPow(2, c1 + c2, mod);
                long powL = ModPow(2, c2 + c3, mod);
                long powD = ModPow(2, c3 + c4, mod);
                long powR = ModPow(2, c4 + c1, mod);

                long sum = (all + powRU + powLU + powLD + powRD - powU - powL - powD - powR - 1 + mod) % mod;

                ans = (ans + sum) % mod;

                bitL.Add(y[i] + 1, y[i] + 1, 1);
                bitR.Add(y[i] + 1, y[i] + 1, -1);
            }

            Console.WriteLine(ans);
        }

        struct Point
        {
            public int x;
            public int y;
        }

        /// <summary>
        /// a^n (mod p)
        /// nが非常に大きい時に有効
        /// </summary>
        /// <param name="a"></param>
        /// <param name="n"></param>
        /// <param name="mod"></param>
        /// <returns></returns>
        public static long ModPow(long a, long n, long p)
        {
            if (n == 0) return 1;
            if (n == 1) return a % p;
            if (n % 2 == 1) return (a * ModPow(a, n - 1, p)) % p;

            long t = ModPow(a, n / 2, p);
            return (t * t) % p;
        }
    }

    class BIT
    {
        long[] bit0, bit1;  //1-indexed
        int n;
        public BIT(int n)
        {
            bit0 = new long[n + 1];
            bit1 = new long[n + 1];
            this.n = n;
        }

        public long Sum(int l, int r)
        {
            long ret = 0;
            ret += Sum(bit0, r) + Sum(bit1, r) * r;
            ret -= Sum(bit0, l - 1) + Sum(bit1, l - 1) * (l - 1);
            return ret;
        }

        long Sum(long[] bit, int i)
        {
            long s = 0;
            while (i > 0)
            {
                s += bit[i];
                i -= i & -i;
            }
            return s;
        }

        public void Add(int l, int r, int a)
        {
            Add(bit0, l, -a * (l - 1));
            Add(bit1, l, a);
            Add(bit0, r + 1, a * r);
            Add(bit1, r + 1, -a);
        }

        void Add(long[] bit, int i, int a)
        {
            while (i <= n)
            {
                bit[i] += a;
                i += i & -i;
            }
        }
    }
}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String ReadNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int ReadInt => int.Parse(ReadNext());
        public static long ReadLong => long.Parse(ReadNext());
        public static int[] ReadInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] NextLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

    static class Debug
    {

    }
}