Buggy python submission (verdict: Time Limit Exceeded):
from bisect import *
from heapq import *

def f(n):
    hp = []
    for _ in range(n):
        heappush(hp, list(map(int, input().split())))
    cy = [[0] * 4 for _ in range(n)]
    xy = []
    ys = []
    for i in range(n):
        x, y = heappop(hp)
        s = bisect(ys, y)
        cy[i][3] = pow(2, s, md)
        cy[i][2] = pow(2, i - s, md)
        ys.insert(s, y)
        xy.append([x, y])
    ys = []
    for i in range(n - 1, -1, -1):
        x, y = xy[i]
        s = bisect(ys, y)
        cy[i][0] = pow(2, s, md)
        cy[i][1] = pow(2, n - 1 - i - s, md)
        ys.insert(s, y)
    ans = pow(2, n - 1, md) * n % md
    for i in range(n):
        c0, c1, c2, c3 = cy[i]
        ans = (ans + (c0 - 1) * (c2 - 1) * c1 * c3 + (c1 - 1) * (c3 - 1) * c0 * c2
               - (c0 - 1) * (c1 - 1) * (c2 - 1) * (c3 - 1)) % md
    print(ans)

md = 998244353
n = int(input())
f(n)


Fixed submission:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

class BitSum:
    def __init__(self, n):
        self.n = n + 1
        self.table = [0] * self.n

    def add(self, i, x):
        i += 1
        while i < self.n:
            self.table[i] += x
            i += i & -i

    def sum(self, i):
        i += 1
        res = 0
        while i > 0:
            res += self.table[i]
            i -= i & -i
        return res

def main():
    md=998244353
    n=II()
    xy=LLI(n)
    yy=set()
    for x,y in xy:yy.add(y)
    ytoj={y:j for j,y in enumerate(sorted(yy))}

    ans=n*(pow(2,n,md)-1)-4*(pow(2,n,md)-1-n)
    ans%=md

    xy.sort()
    bit=BitSum(200005)
    for i,[x,y] in enumerate(xy):
        j=ytoj[y]
        c=bit.sum(j-1)
        ans+=pow(2,c,md)-1
        ans+=pow(2,i-c,md)-1
        ans%=md
        bit.add(j,1)

    bit=BitSum(200005)
    for i,[x,y] in enumerate(xy[::-1]):
        j=ytoj[y]
        c=bit.sum(j-1)
        ans+=pow(2,c,md)-1
        ans+=pow(2,i-c,md)-1
        ans%=md
        bit.add(j,1)

    print(ans)

main()

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import *
from heapq import *

def f(n):
    hp = []
    for _ in range(n):
        heappush(hp, list(map(int, input().split())))
    cy = [[0] * 4 for _ in range(n)]
    xy = []
    ys = []
    for i in range(n):
        x, y = heappop(hp)
        s = bisect(ys, y)
        cy[i][3] = pow(2, s, md)
        cy[i][2] = pow(2, i - s, md)
        ys.insert(s, y)
        xy.append([x, y])
    ys = []
    for i in range(n - 1, -1, -1):
        x, y = xy[i]
        s = bisect(ys, y)
        cy[i][0] = pow(2, s, md)
        cy[i][1] = pow(2, n - 1 - i - s, md)
        ys.insert(s, y)
    ans = pow(2, n - 1, md) * n % md
    for i in range(n):
        c0, c1, c2, c3 = cy[i]
        ans = (ans + (c0 - 1) * (c2 - 1) * c1 * c3 + (c1 - 1) * (c3 - 1) * c0 * c2
               - (c0 - 1) * (c1 - 1) * (c2 - 1) * (c3 - 1)) % md
    print(ans)

md = 998244353
n = int(input())
f(n)


Fixed submission:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

class BitSum:
    def __init__(self, n):
        self.n = n + 1
        self.table = [0] * self.n

    def add(self, i, x):
        i += 1
        while i < self.n:
            self.table[i] += x
            i += i & -i

    def sum(self, i):
        i += 1
        res = 0
        while i > 0:
            res += self.table[i]
            i -= i & -i
        return res

def main():
    md=998244353
    n=II()
    xy=LLI(n)
    yy=set()
    for x,y in xy:yy.add(y)
    ytoj={y:j for j,y in enumerate(sorted(yy))}

    ans=n*(pow(2,n,md)-1)-4*(pow(2,n,md)-1-n)
    ans%=md

    xy.sort()
    bit=BitSum(200005)
    for i,[x,y] in enumerate(xy):
        j=ytoj[y]
        c=bit.sum(j-1)
        ans+=pow(2,c,md)-1
        ans+=pow(2,i-c,md)-1
        ans%=md
        bit.add(j,1)

    bit=BitSum(200005)
    for i,[x,y] in enumerate(xy[::-1]):
        j=ytoj[y]
        c=bit.sum(j-1)
        ans+=pow(2,c,md)-1
        ans+=pow(2,i-c,md)-1
        ans%=md
        bit.add(j,1)

    print(ans)

main()

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import *
from heapq import *

md = 998244353
n = int(input())
hp = []
for _ in range(n):
    heappush(hp, list(map(int, input().split())))
cy = [[0] * 4 for _ in range(n)]
xy = []
ys = []
for i in range(n):
    x, y = heappop(hp)
    s = bisect(ys, y)
    cy[i][3] = pow(2, s, md)
    cy[i][2] = pow(2, i - s, md)
    ys.insert(s, y)
    xy.append([x, y])
ys = []
for i in range(n - 1, -1, -1):
    x, y = xy[i]
    s = bisect(ys, y)
    cy[i][0] = pow(2, s, md)
    cy[i][1] = pow(2, n - 1 - i - s, md)
    ys.insert(s, y)
ans = pow(2, n - 1, md) * n % md
for i in range(n):
    c0, c1, c2, c3 = cy[i]
    ans = (ans + (c0 - 1) * (c2 - 1) * c1 * c3 + (c1 - 1) * (c3 - 1) * c0 * c2
           - (c0 - 1) * (c1 - 1) * (c2 - 1) * (c3 - 1)) % md
print(ans)


Fixed submission:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

class BitSum:
    def __init__(self, n):
        self.n = n + 1
        self.table = [0] * self.n

    def add(self, i, x):
        i += 1
        while i < self.n:
            self.table[i] += x
            i += i & -i

    def sum(self, i):
        i += 1
        res = 0
        while i > 0:
            res += self.table[i]
            i -= i & -i
        return res

def main():
    md=998244353
    n=II()
    xy=LLI(n)
    yy=set()
    for x,y in xy:yy.add(y)
    ytoj={y:j for j,y in enumerate(sorted(yy))}

    ans=n*(pow(2,n,md)-1)-4*(pow(2,n,md)-1-n)
    ans%=md

    xy.sort()
    bit=BitSum(200005)
    for i,[x,y] in enumerate(xy):
        j=ytoj[y]
        c=bit.sum(j-1)
        ans+=pow(2,c,md)-1
        ans+=pow(2,i-c,md)-1
        ans%=md
        bit.add(j,1)

    bit=BitSum(200005)
    for i,[x,y] in enumerate(xy[::-1]):
        j=ytoj[y]
        c=bit.sum(j-1)
        ans+=pow(2,c,md)-1
        ans+=pow(2,i-c,md)-1
        ans%=md
        bit.add(j,1)

    print(ans)

main()

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import *
from heapq import *

md = 998244353
n = int(input())
hp = []
for _ in range(n):
    heappush(hp, list(map(int, input().split())))
cy = [[0] * 4 for _ in range(n)]
xy = []
ys = []
for i in range(n):
    x, y = heappop(hp)
    s = bisect(ys, y)
    cy[i][3] = pow(2, s, md)
    cy[i][2] = pow(2, i - s, md)
    ys.insert(s, y)
    xy.append([x, y])
ys = []
for i in range(n - 1, -1, -1):
    x, y = xy[i]
    s = bisect(ys, y)
    cy[i][0] = pow(2, s, md)
    cy[i][1] = pow(2, n - 1 - i - s, md)
    ys.insert(s, y)
ans = pow(2, n - 1, md) * n % md
for i in range(n):
    c0, c1, c2, c3 = cy[i]
    ans = (ans + (c0 - 1) * (c2 - 1) * c1 * c3 + (c1 - 1) * (c3 - 1) * c0 * c2
           - (c0 - 1) * (c1 - 1) * (c2 - 1) * (c3 - 1)) % md
print(ans)


Fixed submission:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

class BitSum:
    def __init__(self, n):
        self.n = n + 1
        self.table = [0] * self.n

    def add(self, i, x):
        i += 1
        while i < self.n:
            self.table[i] += x
            i += i & -i

    def sum(self, i):
        i += 1
        res = 0
        while i > 0:
            res += self.table[i]
            i -= i & -i
        return res

def main():
    md=998244353
    n=II()
    xy=LLI(n)
    yy=set()
    for x,y in xy:yy.add(y)
    ytoj={y:j for j,y in enumerate(sorted(yy))}

    ans=n*(pow(2,n,md)-1)-4*(pow(2,n,md)-1-n)
    ans%=md

    xy.sort()
    bit=BitSum(200005)
    for i,[x,y] in enumerate(xy):
        j=ytoj[y]
        c=bit.sum(j-1)
        ans+=pow(2,c,md)-1
        ans+=pow(2,i-c,md)-1
        ans%=md
        bit.add(j,1)

    bit=BitSum(200005)
    for i,[x,y] in enumerate(xy[::-1]):
        j=ytoj[y]
        c=bit.sum(j-1)
        ans+=pow(2,c,md)-1
        ans+=pow(2,i-c,md)-1
        ans%=md
        bit.add(j,1)

    print(ans)

main()

Buggy python submission (verdict: Time Limit Exceeded):
# YouTubeの通り
from operator import itemgetter

def f(n, xy):
    def update(i, x):
        i += 1
        while i < n + 1:
            bit[i] += x
            i += i & -i

    def get_sum(i):
        i += 1
        s = 0
        while i > 0:
            s += bit[i]
            i -= i & -i
        return s

    # yの座標圧縮
    xy.sort(key=itemgetter(1))
    for i in range(n):
        xy[i][1] = i

    xy.sort()
    cy = [[0] * 4 for _ in range(n)]
    bit = [0] * (n + 1)
    for i in range(n):
        x, y = xy[i]
        s = get_sum(y)
        cy[i][3] = pow(2, s, md)
        cy[i][2] = pow(2, i - s, md)
        update(y, 1)
    bit = [0] * (n + 1)
    for i in range(n - 1, -1, -1):
        x, y = xy[i]
        s = get_sum(y)
        cy[i][0] = pow(2, s, md)
        cy[i][1] = pow(2, n - 1 - i - s, md)
        update(y, 1)
    ans = pow(2, n - 1, md) * n % md
    for i in range(n):
        c0, c1, c2, c3 = cy[i]
        ans = (ans + (c0 - 1) * (c2 - 1) * c1 * c3 + (c1 - 1) * (c3 - 1) * c0 * c2
               - (c0 - 1) * (c1 - 1) * (c2 - 1) * (c3 - 1)) % md
    print(ans)

md = 998244353
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
f(n, xy)


Fixed submission:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

class BitSum:
    def __init__(self, n):
        self.n = n + 1
        self.table = [0] * self.n

    def add(self, i, x):
        i += 1
        while i < self.n:
            self.table[i] += x
            i += i & -i

    def sum(self, i):
        i += 1
        res = 0
        while i > 0:
            res += self.table[i]
            i -= i & -i
        return res

def main():
    md=998244353
    n=II()
    xy=LLI(n)
    yy=set()
    for x,y in xy:yy.add(y)
    ytoj={y:j for j,y in enumerate(sorted(yy))}

    ans=n*(pow(2,n,md)-1)-4*(pow(2,n,md)-1-n)
    ans%=md

    xy.sort()
    bit=BitSum(200005)
    for i,[x,y] in enumerate(xy):
        j=ytoj[y]
        c=bit.sum(j-1)
        ans+=pow(2,c,md)-1
        ans+=pow(2,i-c,md)-1
        ans%=md
        bit.add(j,1)

    bit=BitSum(200005)
    for i,[x,y] in enumerate(xy[::-1]):
        j=ytoj[y]
        c=bit.sum(j-1)
        ans+=pow(2,c,md)-1
        ans+=pow(2,i-c,md)-1
        ans%=md
        bit.add(j,1)

    print(ans)

main()

Buggy python submission (verdict: Time Limit Exceeded):
# YouTubeの通り
from operator import itemgetter

def f(n, xy):
    def update(i, x):
        i += 1
        while i < n + 1:
            bit[i] += x
            i += i & -i

    def get_sum(i):
        i += 1
        s = 0
        while i > 0:
            s += bit[i]
            i -= i & -i
        return s

    # yの座標圧縮
    xy.sort(key=itemgetter(1))
    for i in range(n):
        xy[i][1] = i

    xy.sort()
    cy = [[0] * 4 for _ in range(n)]
    bit = [0] * (n + 1)
    for i in range(n):
        x, y = xy[i]
        s = get_sum(y)
        cy[i][3] = pow(2, s, md)
        cy[i][2] = pow(2, i - s, md)
        update(y, 1)
    bit = [0] * (n + 1)
    for i in range(n - 1, -1, -1):
        x, y = xy[i]
        s = get_sum(y)
        cy[i][0] = pow(2, s, md)
        cy[i][1] = pow(2, n - 1 - i - s, md)
        update(y, 1)
    ans = pow(2, n - 1, md) * n % md
    for i in range(n):
        c0, c1, c2, c3 = cy[i]
        ans = (ans + (c0 - 1) * (c2 - 1) * c1 * c3 + (c1 - 1) * (c3 - 1) * c0 * c2
               - (c0 - 1) * (c1 - 1) * (c2 - 1) * (c3 - 1)) % md
    print(ans)

md = 998244353
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
f(n, xy)


Fixed submission:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

class BitSum:
    def __init__(self, n):
        self.n = n + 1
        self.table = [0] * self.n

    def add(self, i, x):
        i += 1
        while i < self.n:
            self.table[i] += x
            i += i & -i

    def sum(self, i):
        i += 1
        res = 0
        while i > 0:
            res += self.table[i]
            i -= i & -i
        return res

def main():
    md=998244353
    n=II()
    xy=LLI(n)
    yy=set()
    for x,y in xy:yy.add(y)
    ytoj={y:j for j,y in enumerate(sorted(yy))}

    ans=n*(pow(2,n,md)-1)-4*(pow(2,n,md)-1-n)
    ans%=md

    xy.sort()
    bit=BitSum(200005)
    for i,[x,y] in enumerate(xy):
        j=ytoj[y]
        c=bit.sum(j-1)
        ans+=pow(2,c,md)-1
        ans+=pow(2,i-c,md)-1
        ans%=md
        bit.add(j,1)

    bit=BitSum(200005)
    for i,[x,y] in enumerate(xy[::-1]):
        j=ytoj[y]
        c=bit.sum(j-1)
        ans+=pow(2,c,md)-1
        ans+=pow(2,i-c,md)-1
        ans%=md
        bit.add(j,1)

    print(ans)

main()

Buggy python submission (verdict: Time Limit Exceeded):
# YouTubeの通り
from operator import itemgetter

def update(i, x):
    i += 1
    while i < n + 1:
        bit[i] += x
        i += i & -i

def get_sum(i):
    i += 1
    s = 0
    while i > 0:
        s += bit[i]
        i -= i & -i
    return s

md = 998244353
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
# yの座標圧縮
xy.sort(key=itemgetter(1))
for i in range(n):
    xy[i][1] = i

xy.sort()
cy = [[0] * 4 for _ in range(n)]
bit = [0] * (n + 1)
for i in range(n):
    x, y = xy[i]
    s = get_sum(y)
    cy[i][3] = pow(2, s, md)
    cy[i][2] = pow(2, i - s, md)
    update(y, 1)
bit = [0] * (n + 1)
for i in range(n - 1, -1, -1):
    x, y = xy[i]
    s = get_sum(y)
    cy[i][0] = pow(2, s, md)
    cy[i][1] = pow(2, n - 1 - i - s, md)
    update(y, 1)
ans = pow(2, n - 1, md) * n % md
for i in range(n):
    c0, c1, c2, c3 = cy[i]
    ans = (ans + (c0 - 1) * (c2 - 1) * c1 * c3 + (c1 - 1) * (c3 - 1) * c0 * c2
           - (c0 - 1) * (c1 - 1) * (c2 - 1) * (c3 - 1)) % md
print(ans)


Fixed submission:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

class BitSum:
    def __init__(self, n):
        self.n = n + 1
        self.table = [0] * self.n

    def add(self, i, x):
        i += 1
        while i < self.n:
            self.table[i] += x
            i += i & -i

    def sum(self, i):
        i += 1
        res = 0
        while i > 0:
            res += self.table[i]
            i -= i & -i
        return res

def main():
    md=998244353
    n=II()
    xy=LLI(n)
    yy=set()
    for x,y in xy:yy.add(y)
    ytoj={y:j for j,y in enumerate(sorted(yy))}

    ans=n*(pow(2,n,md)-1)-4*(pow(2,n,md)-1-n)
    ans%=md

    xy.sort()
    bit=BitSum(200005)
    for i,[x,y] in enumerate(xy):
        j=ytoj[y]
        c=bit.sum(j-1)
        ans+=pow(2,c,md)-1
        ans+=pow(2,i-c,md)-1
        ans%=md
        bit.add(j,1)

    bit=BitSum(200005)
    for i,[x,y] in enumerate(xy[::-1]):
        j=ytoj[y]
        c=bit.sum(j-1)
        ans+=pow(2,c,md)-1
        ans+=pow(2,i-c,md)-1
        ans%=md
        bit.add(j,1)

    print(ans)

main()

Buggy python submission (verdict: Time Limit Exceeded):
# YouTubeの通り
from operator import itemgetter

def update(i, x):
    i += 1
    while i < n + 1:
        bit[i] += x
        i += i & -i

def get_sum(i):
    i += 1
    s = 0
    while i > 0:
        s += bit[i]
        i -= i & -i
    return s

md = 998244353
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
# yの座標圧縮
xy.sort(key=itemgetter(1))
for i in range(n):
    xy[i][1] = i

xy.sort()
cy = [[0] * 4 for _ in range(n)]
bit = [0] * (n + 1)
for i in range(n):
    x, y = xy[i]
    s = get_sum(y)
    cy[i][3] = pow(2, s, md)
    cy[i][2] = pow(2, i - s, md)
    update(y, 1)
bit = [0] * (n + 1)
for i in range(n - 1, -1, -1):
    x, y = xy[i]
    s = get_sum(y)
    cy[i][0] = pow(2, s, md)
    cy[i][1] = pow(2, n - 1 - i - s, md)
    update(y, 1)
ans = pow(2, n - 1, md) * n % md
for i in range(n):
    c0, c1, c2, c3 = cy[i]
    ans = (ans + (c0 - 1) * (c2 - 1) * c1 * c3 + (c1 - 1) * (c3 - 1) * c0 * c2
           - (c0 - 1) * (c1 - 1) * (c2 - 1) * (c3 - 1)) % md
print(ans)


Fixed submission:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

class BitSum:
    def __init__(self, n):
        self.n = n + 1
        self.table = [0] * self.n

    def add(self, i, x):
        i += 1
        while i < self.n:
            self.table[i] += x
            i += i & -i

    def sum(self, i):
        i += 1
        res = 0
        while i > 0:
            res += self.table[i]
            i -= i & -i
        return res

def main():
    md=998244353
    n=II()
    xy=LLI(n)
    yy=set()
    for x,y in xy:yy.add(y)
    ytoj={y:j for j,y in enumerate(sorted(yy))}

    ans=n*(pow(2,n,md)-1)-4*(pow(2,n,md)-1-n)
    ans%=md

    xy.sort()
    bit=BitSum(200005)
    for i,[x,y] in enumerate(xy):
        j=ytoj[y]
        c=bit.sum(j-1)
        ans+=pow(2,c,md)-1
        ans+=pow(2,i-c,md)-1
        ans%=md
        bit.add(j,1)

    bit=BitSum(200005)
    for i,[x,y] in enumerate(xy[::-1]):
        j=ytoj[y]
        c=bit.sum(j-1)
        ans+=pow(2,c,md)-1
        ans+=pow(2,i-c,md)-1
        ans%=md
        bit.add(j,1)

    print(ans)

main()