Buggy python submission (verdict: Time Limit Exceeded):
import sys

input=sys.stdin.readline

N=int(input())
p=[]
for i in range(N):
    x,y=map(int,input().split())
    p.append([x,y])
mod=998244353

pow=[1]
for i in range(N):
    pow.append((pow[-1]*2)%mod)

p.sort(key=lambda x:x[1])
for i in range(N):
    p[i][1]=i+1


data=[[0 for i in range(4)] for i in range(N)]
#A1 ... AnのBIT(1-indexed)
n=N
BIT = [0]*(n+1)

#A1 ~ Aiまでの和 O(logN)
def BIT_query(idx):
    if idx==0:
        return 0
    res_sum = 0
    while idx > 0:
        res_sum += BIT[idx]
        idx -= idx&(-idx)
    return res_sum

#Ai += x O(logN)
def BIT_update(idx,x):
    while idx <= n:
        BIT[idx] += x
        idx += idx&(-idx)
    return

p.sort()
for i in range(N):
    x,y=p[i]
    data[i][0]=BIT_query(N)-BIT_query(y)
    data[i][3]=BIT_query(y-1)
    BIT_update(y,1)

BIT=[0]*(n+1)
for i in range(N-1,-1,-1):
    x,y=p[i]
    data[i][1]=BIT_query(N)-BIT_query(y)
    data[i][2]=BIT_query(y-1)
    BIT_update(y,1)

ans=0
for i in range(N):
    ban=0
    for j in range(4):
        ban+=(pow[data[i][j]]-1)*pow[data[i][j-1]]
        ban%=mod
    ans+=pow[N]-ban-1
    ans%=mod
print(ans)


Fixed submission:
import sys

input=sys.stdin.readline

N=int(input())
p=[]
for i in range(N):
    x,y=map(int,input().split())
    p.append([x,y])
mod=998244353

pow=[1]
for i in range(N):
    pow.append((pow[-1]*2)%mod)

p.sort(key=lambda x:x[1])
for i in range(N):
    p[i][1]=i+1


data=[[0 for i in range(4)] for i in range(N)]
#A1 ... AnのBIT(1-indexed)
n=N
BIT = [0]*(n+1)

#A1 ~ Aiまでの和 O(logN)
def BIT_query(idx):
    if idx==0:
        return 0
    res_sum = 0
    while idx > 0:
        res_sum += BIT[idx]
        idx -= idx&(-idx)
    return res_sum

#Ai += x O(logN)
def BIT_update(idx,x):
    while idx <= n:
        BIT[idx] += x
        idx += idx&(-idx)
    return

p.sort()
for i in range(N):
    x,y=p[i]
    a,b=i,BIT_query(y)
    data[i][0]=a-b
    data[i][3]=b
    BIT_update(y,1)

BIT=[0]*(n+1)
for i in range(N-1,-1,-1):
    x,y=p[i]
    a,b=N-1-i,BIT_query(y)
    data[i][1]=a-b
    data[i][2]=b
    BIT_update(y,1)

ans=0
for i in range(N):
    ban=0
    for j in range(4):
        ban+=(pow[data[i][j]]-1)*pow[data[i][j-1]]
        ban%=mod
    ans+=pow[N]-ban-1
    ans%=mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

input=sys.stdin.readline

N=int(input())
p=[]
for i in range(N):
    x,y=map(int,input().split())
    p.append([x,y])

p.sort()
for i in range(N):
    p[i][0]=i+1

p.sort(key=lambda x:x[1])
for i in range(N):
    p[i][1]=i+1


data=[[0 for i in range(4)] for i in range(N)]
#A1 ... AnのBIT(1-indexed)
n=N
BIT = [0]*(n+1)

#A1 ~ Aiまでの和 O(logN)
def BIT_query(idx):
    res_sum = 0
    while idx > 0:
        res_sum += BIT[idx]
        idx -= idx&(-idx)
    return res_sum

#Ai += x O(logN)
def BIT_update(idx,x):
    while idx <= n:
        BIT[idx] += x
        idx += idx&(-idx)
    return

p.sort()
for i in range(N):
    x,y=p[i]
    data[i][0]=BIT_query(N)-BIT_query(y)
    if y==1:
        data[i][1]=0
    else:
        data[i][1]=BIT_query(y-1)
    BIT_update(y,1)

BIT=[0]*(n+1)
for i in range(N-1,-1,-1):
    x,y=p[i]
    data[i][2]=BIT_query(N)-BIT_query(y)
    if y==1:
        data[i][3]=0
    else:
        data[i][3]=BIT_query(y-1)
    BIT_update(y,1)

ans=0
mod=998244353
for i in range(N):
    ban=0
    for j in range(4):
        ban+=pow(2,data[i][j],mod)-1
        ban%=mod
    ban+=(pow(2,data[i][0],mod)-1)*(pow(2,data[i][2],mod)-1)
    ban+=(pow(2,data[i][2],mod)-1)*(pow(2,data[i][3],mod)-1)
    ban+=(pow(2,data[i][3],mod)-1)*(pow(2,data[i][1],mod)-1)
    ban+=(pow(2,data[i][1],mod)-1)*(pow(2,data[i][0],mod)-1)
    ban%=mod
    ans+=pow(2,N,mod)-ban-1
    ans%=mod
print(ans)

Fixed submission:
import sys

input=sys.stdin.readline

N=int(input())
p=[]
for i in range(N):
    x,y=map(int,input().split())
    p.append([x,y])
mod=998244353

pow=[1]
for i in range(N):
    pow.append((pow[-1]*2)%mod)

p.sort(key=lambda x:x[1])
for i in range(N):
    p[i][1]=i+1


data=[[0 for i in range(4)] for i in range(N)]
#A1 ... AnのBIT(1-indexed)
n=N
BIT = [0]*(n+1)

#A1 ~ Aiまでの和 O(logN)
def BIT_query(idx):
    if idx==0:
        return 0
    res_sum = 0
    while idx > 0:
        res_sum += BIT[idx]
        idx -= idx&(-idx)
    return res_sum

#Ai += x O(logN)
def BIT_update(idx,x):
    while idx <= n:
        BIT[idx] += x
        idx += idx&(-idx)
    return

p.sort()
for i in range(N):
    x,y=p[i]
    a,b=i,BIT_query(y)
    data[i][0]=a-b
    data[i][3]=b
    BIT_update(y,1)

BIT=[0]*(n+1)
for i in range(N-1,-1,-1):
    x,y=p[i]
    a,b=N-1-i,BIT_query(y)
    data[i][1]=a-b
    data[i][2]=b
    BIT_update(y,1)

ans=0
for i in range(N):
    ban=0
    for j in range(4):
        ban+=(pow[data[i][j]]-1)*pow[data[i][j-1]]
        ban%=mod
    ans+=pow[N]-ban-1
    ans%=mod
print(ans)