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.Linq;
using System.Collections.Generic;

namespace Contest
{
    class Program
    {
        static void Main(string[] args)
        {
            ABC136.F();
        }
        class ABC136
        {
            public static void A()
            {
                var A = Read.Int();
                var B = Read.Int();
                var C = Read.Int();
                Console.WriteLine(Math.Max(0, C - (A - B)));
            }
            public static void B()
            {
                var N = Read.Int();
                int count = 0;
                Func<int, int> keta = x =>
                {
                    int c = 0;
                    while (x > 0)
                    {
                        c++;
                        x /= 10;
                    }
                    return c;
                };
                for (int i = 1; i <= N; ++i)
                {
                    if (keta(i) % 2 == 1) { count++; }
                }
                Console.WriteLine(count);
            }
            public static void C()
            {
                var N = Read.Int();
                var H = Read.IntN();
                var min = H[0] - 1;
                for(int i = 1; i < N; ++i)
                {
                    if (H[i] < min) { Console.WriteLine("No"); return; }
                    if (H[i] > min)
                    {
                        min = H[i] - 1;
                    }
                }
                Console.WriteLine("Yes");
            }
            public static void D()
            {
                var S = Read.Str();
                var N = S.Length;
                int[] count = new int[N];
                var idx = 0;
                for (int i = 0; i < N; ++i)
                {
                    if (S[i] == 'L')
                    {
                        for (int j = idx; j < i; ++j)
                        {
                            if (S[j] == 'R')
                            {
                                if ((i - j) % 2 == 0)
                                {
                                    count[i]++;
                                }
                                else
                                {
                                    count[i - 1]++;
                                }
                            }
                        }
                        idx = i;
                    }
                }
                idx = N - 1;
                for (int i = N - 1; i >= 0; --i)
                {
                    if (S[i] == 'R')
                    {
                        for (int j = idx; j > i; --j)
                        {
                            if (S[j] == 'L')
                            {
                                if ((j - i) % 2 == 0)
                                {
                                    count[i]++;
                                }
                                else
                                {
                                    count[i + 1]++;
                                }
                            }
                        }
                        idx = i;
                    }
                }
                Console.WriteLine(String.Join(" ", count));
            }
            public static void E()
            {
                var N = Read.Int();
                var K = Read.Long();
                var A = Read.LongN();
                foreach(var d in Util.Divisor(A.Sum()).OrderBy(x => -x))
                {
                    var X = A.Select(x => x % d).OrderBy(x => x).ToArray();
                    if (X.Take((int)(N - X.Sum() / d)).Sum() <= K) { Console.WriteLine(d); return; }
                }
            }
            public static void F()
            {
                var N = Read.Int();
                var XY = Read.TupleInt(N).OrderBy(x => x.Item1).ToArray();
                var Y = XY.Select(x => x.Item2).OrderBy(x => x).ToArray();
                var YComp = new Dictionary<int, int>();
                for(int i = 0; i < N; ++i)
                {
                    YComp.Add(Y[i], i + 1);
                }
                var P2 = new MOD[N + 1];
                P2[0] = 0;
                for(int i = 0; i < N; ++i) { P2[i + 1] = P2[i] * 2 + 1; }
                var XLYDs = new int[N];
                {
                    var bitL = new Util.BIT(N);
                    for (int i = 0; i < N; ++i)
                    {
                        var y = YComp[XY[i].Item2];
                        XLYDs[i] = (int)bitL.Sum(y);
                        bitL.Add(y, 1);
                    }
                }
                var XRYDs = new int[N];
                {
                    var bitR = new Util.BIT(N);
                    for (int i = N - 1; i >= 0; --i)
                    {
                        var y = YComp[XY[i].Item2];
                        XRYDs[i] = (int)bitR.Sum(y);
                        bitR.Add(y, 1);
                    }
                }
                MOD total = 0;
                for(int i = 0; i < N; ++i)
                {
                    var XL = i;
                    var XR = N - i - 1;
                    var y = XY[i].Item2;
                    var XLYD = XLYDs[i];
                    var XLYU = XL - XLYD;
                    var XRYD = XRYDs[i];
                    var XRYU = XR - XRYD;
                    var YU = XLYU + XRYU;
                    var YD = XLYD + XRYD;
                    total += P2[N] - P2[XL] - P2[XR] - P2[YU] - P2[YD] + P2[XLYU] + P2[XLYD] + P2[XRYU] + P2[XRYD];
                }
                Console.WriteLine(total.V);
            }
        }



        class Util
        {
            public static HashSet<long> Divisor(long x)
            {
                var div = new HashSet<long>(); for (long p = 1; p * p <= x; ++p) { if (x % p == 0) { div.Add(p); } }
                foreach (var d in div.ToArray())
                {
                    if (!div.Contains(x / d)) { div.Add(x / d); }
                }
                return div;
            }
            public class BIT
            {
                int N; long[] array;
                public BIT(int m) { for (int n = 1; ; n *= 2) { if (n >= m) { N = n; array = new long[N + 1]; break; } } }
                public void Add(int idx, int v) { for (int x = idx; x <= N; x += x & -x) { array[x] += v; } }
                public long Sum(int idx) { long ret = 0; for (int x = idx; x > 0; x -= x & -x) { ret += array[x]; } return ret; }
            }
        }
        struct MOD
        {
            public static long P = 998244353;
            public readonly long V;

            public MOD(long a) { this.V = a; }
            public static implicit operator MOD(long a) { return new MOD(a); }
            public static MOD operator +(MOD a, MOD b) { return new MOD((a.V + b.V) % P); }
            public static MOD operator -(MOD a, MOD b) { return new MOD((a.V - b.V + P) % P); }
            public static MOD operator *(MOD a, MOD b) { return new MOD((a.V * b.V) % P); }
            public static MOD operator /(MOD a, MOD b) { return new MOD((a.V * b.Inverse().V) % P); }
            //public MOD Inverse() { return Util.Inverse(V, P); }
            public MOD Inverse()
            {
                long a = V, p = P;
                long b = p, c = 1, d = 0, e = 0, f = 0;
                while (b != 0)
                {
                    e = a / b;
                    f = b; b = a - e * b; a = f;
                    f = d; d = c - e * d; c = f;
                }
                c %= p;
                return c + (c < 0 ? p : 0);
            }
            //public MOD Power(long n) { return Util.Power(V, n, P); }
            public MOD Power(long n)
            {
                long a = V, p = P;
                long res = 1;
                long mult = a;
                for (int i = 0; i < 40; ++i)
                {
                    if ((n & ((long)1 << i)) > 0)
                    {
                        res = (res * mult) % p;
                    }
                    mult = (mult * mult) % p;
                }
                return res;
            }

            public override string ToString() { return V.ToString(); }
        }


        static class Read
        {
            static Queue<string> queue = new Queue<string>();
            static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } }
            public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); }
            public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); }
            public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); }
            public static int[] IntN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray(); }
            public static long[] LongN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray(); }
            public static string[] StrN() { return Console.ReadLine().Split(' '); }
            public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); }
            public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); }
            public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); }
            public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); }
            public static long[,] LongMatrix(int r, int c)
            {
                var mat = new long[r, c];
                for (int i = 0; i < r; ++i)
                {
                    var x = Read.LongN();
                    for (int j = 0; j < c; ++j)
                    {
                        mat[i, j] = x[j];
                    }
                }
                return mat;
            }
            public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M, bool isDirectional = false)
            {
                Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>();
                for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); }
                for (int i = 0; i < M; ++i)
                {
                    var ab = Read.IntN(); dict[ab[0]].Add(ab[1]);
                    if (!isDirectional) { dict[ab[1]].Add(ab[0]); }
                }
                return dict;
            }
            public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M)
            {
                Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>();
                for (int i = 0; i <= N; ++i)
                {
                    dict.Add(i, new Dictionary<int, long>());
                }
                for (int i = 0; i < M; ++i)
                {
                    var ab = Read.IntN();
                    dict[ab[0]].Add(ab[1], ab[2]);
                    dict[ab[1]].Add(ab[0], ab[2]);
                }
                return dict;
            }
        }
    }
}