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

from operator import itemgetter

def main():



	input = sys.stdin.readline


	md = 998244353
	n = int(input())
	tl=n+1
	
#	ft=[0]*tl
	ft=array.array('I', [0 for _ in range(tl)])
	xy = [[0]*2 for _ in range(n)]
	for i in range(n):
		xy[i] = [int(item) for item in input().split()]
	xy.sort(key=itemgetter(0))
	yxi = [y for x, y in xy]

	*YS, = set(yxi)
	YS.sort()
	yxi= list(map({e: i for i, e in enumerate(YS)}.__getitem__, yxi))

	ct=[0]*(n+1)
	ct[0]=1
	for i in range(1,n+1):
		ct[i]=ct[i-1]*2%md

	cnt=tuple(ct)

	def upd(i):
		i+=1
		while(i<=n):
			ft[i]+=1
			i+=i&-i

	def get(i):
		i+=1
		ret=0
		while(i!=0):
		    ret+=ft[i]
		    i-=i&-i
		return ret

	def calc(get,upd):
		for i, y in enumerate(yxi):
			v = get(y); upd(y)
			p1 = cnt[v]; p0 = cnt[y - v]
			q1 = cnt[i - v]; q0 = cnt[(n - y - 1) - (i - v)]
			yield (p0 + p1 + q0 + q1 - (p0 + q1) * (p1 + q0)) % md


	print((sum(calc(get,upd))+n*cnt[n] - n)%md)

main()


Fixed submission:
import sys
import array

from operator import itemgetter

def main():



	input = sys.stdin.readline


	md = 998244353
	n = int(input())
	tl=n+1
	
	ft=[0]*tl

	xy = [[0]*2 for _ in range(n)]
	for i in range(n):
		xy[i] = [int(item) for item in input().split()]
	xy.sort(key=itemgetter(0))
	yxi = [y for x, y in xy]

	*YS, = set(yxi)
	YS.sort()
	yxi= list(map({e: i for i, e in enumerate(YS)}.__getitem__, yxi))

	ct=[0]*(n+1)
	ct[0]=1
	for i in range(1,n+1):
		ct[i]=ct[i-1]*2%md

	cnt=tuple(ct)

	def upd(i):
		i+=1
		while(i<=n):
			ft[i]+=1
			i+=i&-i

	def get(i):
		i+=1
		ret=0
		while(i!=0):
		    ret+=ft[i]
		    i-=i&-i
		return ret

	def calc(get,upd):
		for i, y in enumerate(yxi):
			v = get(y); upd(y)
			p1 = cnt[v]; p0 = cnt[y - v]
			q1 = cnt[i - v]; q0 = cnt[(n - y - 1) - (i - v)]
			yield (p0 + p1 + q0 + q1 - (p0 + q1) * (p1 + q0)) % md


	print((sum(calc(get,upd))+n*cnt[n] - n)%md)

main()

Buggy python submission (verdict: Runtime Error):
import sys
import array

from operator import itemgetter

def main():



	input = sys.stdin.readline


	md = 998244353
	n = int(input())
	tl=n+1
	
	ft=[0]*tl

	xy = [[0]*2 for _ in range(n)]
	for i in range(n):
		xy[i] = [int(item) for item in input().split()]
	xy.sort(key=itemgetter(0))
	yxi = [y for x, y in xy]

	*YS, = set(yxi)
	YS.sort()
	yxi= list(map({e: i for i, e in enumerate(YS)}.__getitem__, yxi))

	ct=[0]*(n+1)
	ct[0]=1
	for i in range(1,n+1):
		ct[i]=ct[i-1]*2%md

	cnt=tuple(ct)

	def upd(i):
		i+=1
		while(i<=len(ft)):
			ft[i]+=1
			i+=i&-i

	def get(i):
		i+=1
		ret=0
		while(i!=0):
		    ret+=ft[i]
		    i-=i&-i
		return ret

	def calc(get,upd):
		for i, y in enumerate(yxi):
			v = get(y); upd(y)
			p1 = cnt[v]; p0 = cnt[y - v]
			q1 = cnt[i - v]; q0 = cnt[(n - y - 1) - (i - v)]
			yield (p0 + p1 + q0 + q1 - (p0 + q1) * (p1 + q0)) % md


	print((sum(calc(get,upd))+n*cnt[n] - n)%md)

main()


Fixed submission:
import sys
import array

from operator import itemgetter

def main():



	input = sys.stdin.readline


	md = 998244353
	n = int(input())
	tl=n+1
	
	ft=[0]*tl

	xy = [[0]*2 for _ in range(n)]
	for i in range(n):
		xy[i] = [int(item) for item in input().split()]
	xy.sort(key=itemgetter(0))
	yxi = [y for x, y in xy]

	*YS, = set(yxi)
	YS.sort()
	yxi= list(map({e: i for i, e in enumerate(YS)}.__getitem__, yxi))

	ct=[0]*(n+1)
	ct[0]=1
	for i in range(1,n+1):
		ct[i]=ct[i-1]*2%md

	cnt=tuple(ct)

	def upd(i):
		i+=1
		while(i<=n):
			ft[i]+=1
			i+=i&-i

	def get(i):
		i+=1
		ret=0
		while(i!=0):
		    ret+=ft[i]
		    i-=i&-i
		return ret

	def calc(get,upd):
		for i, y in enumerate(yxi):
			v = get(y); upd(y)
			p1 = cnt[v]; p0 = cnt[y - v]
			q1 = cnt[i - v]; q0 = cnt[(n - y - 1) - (i - v)]
			yield (p0 + p1 + q0 + q1 - (p0 + q1) * (p1 + q0)) % md


	print((sum(calc(get,upd))+n*cnt[n] - n)%md)

main()

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

from operator import itemgetter

def upd(ft,i):
	i+=1
	while(i<=len(ft)):
		ft[i]+=1
		i+=i&-i

def get(ft,i):
	i+=1
	ret=0
	while(i!=0):
	    ret+=ft[i]
	    i-=i&-i
	return ret


def comb(cnt,x):
	return cnt[x]-1;

def main():

	input = sys.stdin.readline
	tl=200100

	ft=[0]*tl


	md = 998244353
	n = int(input())
	xy = [[0]*2 for _ in range(n)]
	ys = []
	hp = []
	for i in range(n):
		xy[i] = [int(item) for item in input().split()]
	xy.sort(key=itemgetter(0))
	yxi = [y for x, y in xy]

	*YS, = set(yxi)
	YS.sort()
	yxi= list(map({e: i for i, e in enumerate(YS)}.__getitem__, yxi))

	ct=[0]*(n+1)
	ct[0]=1
	for i in range(1,n+1):
		ct[i]=ct[i-1]*2%md

	cnt=tuple(ct)

	def calc(ft,get,upd,cnt):
		for i, y in enumerate(yxi):
			v = get(ft,y+1); upd(ft,y+1)
			p1 = cnt[v]; p0 = cnt[y - v]
			q1 = cnt[i - v]; q0 = cnt[(n - y - 1) - (i - v)]
			yield (p0 + p1 + q0 + q1 - (p0 + q1) * (p1 + q0)) % md


	print((sum(calc(ft,get,upd,cnt))+n*cnt[n] - n)%md)

main()


Fixed submission:
import sys
import array

from operator import itemgetter

def main():



	input = sys.stdin.readline


	md = 998244353
	n = int(input())
	tl=n+1
	
	ft=[0]*tl

	xy = [[0]*2 for _ in range(n)]
	for i in range(n):
		xy[i] = [int(item) for item in input().split()]
	xy.sort(key=itemgetter(0))
	yxi = [y for x, y in xy]

	*YS, = set(yxi)
	YS.sort()
	yxi= list(map({e: i for i, e in enumerate(YS)}.__getitem__, yxi))

	ct=[0]*(n+1)
	ct[0]=1
	for i in range(1,n+1):
		ct[i]=ct[i-1]*2%md

	cnt=tuple(ct)

	def upd(i):
		i+=1
		while(i<=n):
			ft[i]+=1
			i+=i&-i

	def get(i):
		i+=1
		ret=0
		while(i!=0):
		    ret+=ft[i]
		    i-=i&-i
		return ret

	def calc(get,upd):
		for i, y in enumerate(yxi):
			v = get(y); upd(y)
			p1 = cnt[v]; p0 = cnt[y - v]
			q1 = cnt[i - v]; q0 = cnt[(n - y - 1) - (i - v)]
			yield (p0 + p1 + q0 + q1 - (p0 + q1) * (p1 + q0)) % md


	print((sum(calc(get,upd))+n*cnt[n] - n)%md)

main()

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

from operator import itemgetter

def upd(ft,i):
	i+=1
	while(i<len(ft)):
		ft[i]+=1
		i+=i&-i

def get(ft,i):
	i+=1
	ret=0
	while(i!=0):
	    ret+=ft[i]
	    i-=i&-i
	return ret


def comb(cnt,x):
	return cnt[x]-1;

def main():

	input = sys.stdin.readline
	tl=200100

	ft=[0]*tl


	md = 998244353
	n = int(input())
	xy = [[0]*2 for _ in range(n)]
	yxi = [[0]*3 for _ in range(n)]
	ys = []
	hp = []
	for i in range(n):
		xy[i] = [int(item) for item in input().split()]
	xy.sort(key=itemgetter(0))

	for i in range(n):
		yxi[i]=[xy[i][1],xy[i][0],i]
	yxi.sort(key=itemgetter(0))

	ct=[0]*(n+1)
	ct[0]=1
	for i in range(1,n+1):
		ct[i]=ct[i-1]*2%md

	cnt=tuple(ct)

	def calc(ft,get,upd,cnt):
		for aa in yxi:
			ix=aa[2]
			a=get(ft,ix)
			b=get(ft,n)-a
			upd(ft,ix)
			c=ix-a
			d=n-ix-1-b
		#	exc=(comb(a+b)+comb(a+c)+comb(b+d)+comb(c+d)-comb(a)-comb(b)-comb(c)-comb(d))%md
		#	cur=(comb(n)-exc)%md
		#	ans=(ans+cur)%md
		#	ans=(ans+comb(cnt,n)-comb(cnt,a+b)-comb(cnt,a+c)-comb(cnt,b+d)-comb(cnt,c+d)+comb(cnt,a)+comb(cnt,b)+comb(cnt,c)+comb(cnt,d))%md
			yield(comb(cnt,n)-comb(cnt,a+b)-comb(cnt,a+c)-comb(cnt,b+d)-comb(cnt,c+d)+comb(cnt,a)+comb(cnt,b)+comb(cnt,c)+comb(cnt,d))%md

	print((sum(calc(ft,get,upd,cnt)))%md)

main()


Fixed submission:
import sys
import array

from operator import itemgetter

def main():



	input = sys.stdin.readline


	md = 998244353
	n = int(input())
	tl=n+1
	
	ft=[0]*tl

	xy = [[0]*2 for _ in range(n)]
	for i in range(n):
		xy[i] = [int(item) for item in input().split()]
	xy.sort(key=itemgetter(0))
	yxi = [y for x, y in xy]

	*YS, = set(yxi)
	YS.sort()
	yxi= list(map({e: i for i, e in enumerate(YS)}.__getitem__, yxi))

	ct=[0]*(n+1)
	ct[0]=1
	for i in range(1,n+1):
		ct[i]=ct[i-1]*2%md

	cnt=tuple(ct)

	def upd(i):
		i+=1
		while(i<=n):
			ft[i]+=1
			i+=i&-i

	def get(i):
		i+=1
		ret=0
		while(i!=0):
		    ret+=ft[i]
		    i-=i&-i
		return ret

	def calc(get,upd):
		for i, y in enumerate(yxi):
			v = get(y); upd(y)
			p1 = cnt[v]; p0 = cnt[y - v]
			q1 = cnt[i - v]; q0 = cnt[(n - y - 1) - (i - v)]
			yield (p0 + p1 + q0 + q1 - (p0 + q1) * (p1 + q0)) % md


	print((sum(calc(get,upd))+n*cnt[n] - n)%md)

main()

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

from operator import itemgetter

def upd(ft,i):
	i+=1
	while(i<len(ft)):
		ft[i]+=1
		i+=i&-i

def get(ft,i):
	i+=1
	ret=0
	while(i!=0):
	    ret+=ft[i]
	    i-=i&-i
	return ret


def comb(cnt,x):
	return cnt[x]-1;

def main():

	tl=200100

	ft=[0]*tl


	md = 998244353
	n = int(input())
	xy = [[0]*2 for _ in range(n)]
	yxi = [[0]*3 for _ in range(n)]
	ys = []
	hp = []
	for i in range(n):
		xy[i] = [int(item) for item in input().split()]
	xy.sort(key=itemgetter(0))

	for i in range(n):
		yxi[i]=[xy[i][1],xy[i][0],i]
	yxi.sort(key=itemgetter(0))

	ct=[0]*(n+1)
	ct[0]=1
	for i in range(1,n+1):
		ct[i]=ct[i-1]*2%md

	cnt=tuple(ct)

	ans=0

	for i in range(n):
		ix=yxi[i][2]
		a=get(ft,ix)
		b=get(ft,n)-a
		c=ix-a
		d=n-ix-1-b
	#	exc=(comb(a+b)+comb(a+c)+comb(b+d)+comb(c+d)-comb(a)-comb(b)-comb(c)-comb(d))%md
	#	cur=(comb(n)-exc)%md
	#	ans=(ans+cur)%md
		ans=(ans+comb(cnt,n)-comb(cnt,a+b)-comb(cnt,a+c)-comb(cnt,b+d)-comb(cnt,c+d)+comb(cnt,a)+comb(cnt,b)+comb(cnt,c)+comb(cnt,d))%md
		upd(ft,ix)

	if(ans<0):ans+=md

	print(ans)

main()


Fixed submission:
import sys
import array

from operator import itemgetter

def main():



	input = sys.stdin.readline


	md = 998244353
	n = int(input())
	tl=n+1
	
	ft=[0]*tl

	xy = [[0]*2 for _ in range(n)]
	for i in range(n):
		xy[i] = [int(item) for item in input().split()]
	xy.sort(key=itemgetter(0))
	yxi = [y for x, y in xy]

	*YS, = set(yxi)
	YS.sort()
	yxi= list(map({e: i for i, e in enumerate(YS)}.__getitem__, yxi))

	ct=[0]*(n+1)
	ct[0]=1
	for i in range(1,n+1):
		ct[i]=ct[i-1]*2%md

	cnt=tuple(ct)

	def upd(i):
		i+=1
		while(i<=n):
			ft[i]+=1
			i+=i&-i

	def get(i):
		i+=1
		ret=0
		while(i!=0):
		    ret+=ft[i]
		    i-=i&-i
		return ret

	def calc(get,upd):
		for i, y in enumerate(yxi):
			v = get(y); upd(y)
			p1 = cnt[v]; p0 = cnt[y - v]
			q1 = cnt[i - v]; q0 = cnt[(n - y - 1) - (i - v)]
			yield (p0 + p1 + q0 + q1 - (p0 + q1) * (p1 + q0)) % md


	print((sum(calc(get,upd))+n*cnt[n] - n)%md)

main()

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

from operator import itemgetter

input = sys.stdin.readline

tl=200100

ft=array.array('I', [0 for _ in range(tl)])

def upd(i):
	global ft
	i+=1
	while(i<tl):
		ft[i]+=1
		i+=i&-i

def get(i):
	global ft
	i+=1
	ret=0
	while(i!=0):
	    ret+=ft[i]
	    i-=i&-i
	return ret

md = 998244353
n = int(input())

xyi = [[0]*3 for _ in range(n)]
for i in range(n):
	xyi[i][0],xyi[i][1] = [int(item) for item in input().split()]
xyi.sort(key=itemgetter(0))

for i in range(n):
	xyi[i][2]=i
xyi.sort(key=itemgetter(1))

ct=[0]*(n+1)

ct[0]=1
for i in range(1,n+1):
	ct[i]=ct[i-1]*2%md

cnt=tuple(ct)

def comb(x):
	return cnt[x]-1;

ans=0

for aa in xyi:
	ix=aa[2]
	a=get(ix)
	b=get(n)-a
	c=ix-a
	d=n-ix-1-b
#	exc=(comb(a+b)+comb(a+c)+comb(b+d)+comb(c+d)-comb(a)-comb(b)-comb(c)-comb(d))%md
#	cur=(comb(n)-exc)%md
#	ans=(ans+cur)%md
	ans=(ans+comb(n)-comb(a+b)-comb(a+c)-comb(b+d)-comb(c+d)+comb(a)+comb(b)+comb(c)+comb(d))%md
	upd(ix)

if(ans<0):ans+=md

print(ans)


Fixed submission:
import sys
import array

from operator import itemgetter

def main():



	input = sys.stdin.readline


	md = 998244353
	n = int(input())
	tl=n+1
	
	ft=[0]*tl

	xy = [[0]*2 for _ in range(n)]
	for i in range(n):
		xy[i] = [int(item) for item in input().split()]
	xy.sort(key=itemgetter(0))
	yxi = [y for x, y in xy]

	*YS, = set(yxi)
	YS.sort()
	yxi= list(map({e: i for i, e in enumerate(YS)}.__getitem__, yxi))

	ct=[0]*(n+1)
	ct[0]=1
	for i in range(1,n+1):
		ct[i]=ct[i-1]*2%md

	cnt=tuple(ct)

	def upd(i):
		i+=1
		while(i<=n):
			ft[i]+=1
			i+=i&-i

	def get(i):
		i+=1
		ret=0
		while(i!=0):
		    ret+=ft[i]
		    i-=i&-i
		return ret

	def calc(get,upd):
		for i, y in enumerate(yxi):
			v = get(y); upd(y)
			p1 = cnt[v]; p0 = cnt[y - v]
			q1 = cnt[i - v]; q0 = cnt[(n - y - 1) - (i - v)]
			yield (p0 + p1 + q0 + q1 - (p0 + q1) * (p1 + q0)) % md


	print((sum(calc(get,upd))+n*cnt[n] - n)%md)

main()

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

from operator import itemgetter

input = sys.stdin.readline

tl=200100

ft=array.array('I', [0 for _ in range(tl)])

def upd(i):
	global ft
	i+=1
	while(i<tl):
		ft[i]+=1
		i+=i&-i

def get(i):
	global ft
	i+=1
	ret=0
	while(i!=0):
	    ret+=ft[i]
	    i-=i&-i
	return ret

md = 998244353
n = int(input())

xyi = [[0]*3 for _ in range(n)]
for i in range(n):
	xyi[i][0],xyi[i][1] = [int(item) for item in input().split()]
xyi.sort(key=itemgetter(0))

for i in range(n):
	xyi[i][2]=i
xyi.sort(key=itemgetter(1))

cnt=array.array('I', [0 for _ in range(n+1)])

cnt[0]=1
for i in range(1,n+1):
	cnt[i]=cnt[i-1]*2%md

def comb(x):
	return cnt[x]-1;

ans=0

for aa in xyi:
	ix=aa[2]
	a=get(ix)
	b=get(n)-get(ix)
	c=ix-a
	d=n-ix-1-b
	exc=(comb(a+b)+comb(a+c)+comb(b+d)+comb(c+d)-comb(a)-comb(b)-comb(c)-comb(d))%md
	cur=(comb(n)-exc)%md
	ans=(ans+cur)%md
	upd(ix)

if(ans<0):ans+=md

print(ans)


Fixed submission:
import sys
import array

from operator import itemgetter

def main():



	input = sys.stdin.readline


	md = 998244353
	n = int(input())
	tl=n+1
	
	ft=[0]*tl

	xy = [[0]*2 for _ in range(n)]
	for i in range(n):
		xy[i] = [int(item) for item in input().split()]
	xy.sort(key=itemgetter(0))
	yxi = [y for x, y in xy]

	*YS, = set(yxi)
	YS.sort()
	yxi= list(map({e: i for i, e in enumerate(YS)}.__getitem__, yxi))

	ct=[0]*(n+1)
	ct[0]=1
	for i in range(1,n+1):
		ct[i]=ct[i-1]*2%md

	cnt=tuple(ct)

	def upd(i):
		i+=1
		while(i<=n):
			ft[i]+=1
			i+=i&-i

	def get(i):
		i+=1
		ret=0
		while(i!=0):
		    ret+=ft[i]
		    i-=i&-i
		return ret

	def calc(get,upd):
		for i, y in enumerate(yxi):
			v = get(y); upd(y)
			p1 = cnt[v]; p0 = cnt[y - v]
			q1 = cnt[i - v]; q0 = cnt[(n - y - 1) - (i - v)]
			yield (p0 + p1 + q0 + q1 - (p0 + q1) * (p1 + q0)) % md


	print((sum(calc(get,upd))+n*cnt[n] - n)%md)

main()

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import sys
from operator import itemgetter

input = sys.stdin.readline

tl=200100

ft=np.zeros(tl,dtype=int)

def upd(i):
	global ft
	i+=1
	while(i<tl):
		ft[i]+=1
		i+=i&-i

def get(i):
	global ft
	i+=1
	ret=0
	while(i!=0):
	    ret+=ft[i]
	    i-=i&-i
	return ret

md = 998244353
n = int(input())

xyi = [[0]*3 for _ in range(n)]
for i in range(n):
	xyi[i][0],xyi[i][1] = [int(item) for item in input().split()]
xyi.sort(key=itemgetter(0))

for i in range(n):
	xyi[i][2]=i
xyi.sort(key=itemgetter(1))

cnt=np.zeros(n+1,dtype=int)

cnt[0]=1
for i in range(1,n+1):
	cnt[i]=cnt[i-1]*2%md

def comb(x):
	return cnt[x]-1;

ans=0

for aa in xyi:
	ix=aa[2]
	a=get(ix)
	b=get(n)-get(ix)
	c=ix-a
	d=n-ix-1-b
	exc=(comb(a+b)+comb(a+c)+comb(b+d)+comb(c+d)-comb(a)-comb(b)-comb(c)-comb(d))%md
	cur=(comb(n)-exc)%md
	ans=(ans+cur)%md
	upd(ix)

if(ans<0):ans+=md

print(ans)


Fixed submission:
import sys
import array

from operator import itemgetter

def main():



	input = sys.stdin.readline


	md = 998244353
	n = int(input())
	tl=n+1
	
	ft=[0]*tl

	xy = [[0]*2 for _ in range(n)]
	for i in range(n):
		xy[i] = [int(item) for item in input().split()]
	xy.sort(key=itemgetter(0))
	yxi = [y for x, y in xy]

	*YS, = set(yxi)
	YS.sort()
	yxi= list(map({e: i for i, e in enumerate(YS)}.__getitem__, yxi))

	ct=[0]*(n+1)
	ct[0]=1
	for i in range(1,n+1):
		ct[i]=ct[i-1]*2%md

	cnt=tuple(ct)

	def upd(i):
		i+=1
		while(i<=n):
			ft[i]+=1
			i+=i&-i

	def get(i):
		i+=1
		ret=0
		while(i!=0):
		    ret+=ft[i]
		    i-=i&-i
		return ret

	def calc(get,upd):
		for i, y in enumerate(yxi):
			v = get(y); upd(y)
			p1 = cnt[v]; p0 = cnt[y - v]
			q1 = cnt[i - v]; q0 = cnt[(n - y - 1) - (i - v)]
			yield (p0 + p1 + q0 + q1 - (p0 + q1) * (p1 + q0)) % md


	print((sum(calc(get,upd))+n*cnt[n] - n)%md)

main()

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

input = sys.stdin.readline

tl=200100

ft=[0]*tl

def upd(i):
	global ft
	i+=1
	while(i<tl):
		ft[i]+=1
		i+=i&-i

def get(i):
	global ft
	i+=1
	ret=0
	while(i!=0):
	    ret+=ft[i]
	    i-=i&-i
	return ret

md = 998244353
n = int(input())

xy = [[None]*2 for _ in range(n)]
yi = [[None]*2 for _ in range(n)]
for i in range(n):
	xy[i] = [int(item) for item in input().split()]
xy.sort(key=itemgetter(0))

for i in range(n):
	yi[i]=[xy[i][1],i]
yi.sort(key=itemgetter(0))

cnt=[0]*(n+1)
cnt[0]=1
for i in range(1,n+1):
	cnt[i]=cnt[i-1]*2%md

def comb(x):
	return cnt[x]-1;

ans=0

for aa in yi:
	ix=aa[1]
	a=get(ix)
	b=get(n)-get(ix)
	c=ix-a
	d=n-ix-1-b
	exc=(comb(a+b)+comb(a+c)+comb(b+d)+comb(c+d)-comb(a)-comb(b)-comb(c)-comb(d))%md
	cur=(comb(n)-exc)%md
	ans=(ans+cur)%md
	upd(ix)

if(ans<0):ans+=md

print(ans)


Fixed submission:
import sys
import array

from operator import itemgetter

def main():



	input = sys.stdin.readline


	md = 998244353
	n = int(input())
	tl=n+1
	
	ft=[0]*tl

	xy = [[0]*2 for _ in range(n)]
	for i in range(n):
		xy[i] = [int(item) for item in input().split()]
	xy.sort(key=itemgetter(0))
	yxi = [y for x, y in xy]

	*YS, = set(yxi)
	YS.sort()
	yxi= list(map({e: i for i, e in enumerate(YS)}.__getitem__, yxi))

	ct=[0]*(n+1)
	ct[0]=1
	for i in range(1,n+1):
		ct[i]=ct[i-1]*2%md

	cnt=tuple(ct)

	def upd(i):
		i+=1
		while(i<=n):
			ft[i]+=1
			i+=i&-i

	def get(i):
		i+=1
		ret=0
		while(i!=0):
		    ret+=ft[i]
		    i-=i&-i
		return ret

	def calc(get,upd):
		for i, y in enumerate(yxi):
			v = get(y); upd(y)
			p1 = cnt[v]; p0 = cnt[y - v]
			q1 = cnt[i - v]; q0 = cnt[(n - y - 1) - (i - v)]
			yield (p0 + p1 + q0 + q1 - (p0 + q1) * (p1 + q0)) % md


	print((sum(calc(get,upd))+n*cnt[n] - n)%md)

main()

Buggy python submission (verdict: Time Limit Exceeded):
tl=200100

ft=[0]*tl

def upd(i):
	global ft
	i+=1
	while(i<tl):
		ft[i]+=1
		i+=i&-i

def get(i):
	global ft
	i+=1
	ret=0
	while(i!=0):
	    ret+=ft[i]
	    i-=i&-i
	return ret

md = 998244353
n = int(input())
cy = [[0] * 4 for _ in range(n)]
xy = [[0]*2 for _ in range(n)]
yxi = [[0]*3 for _ in range(n)]
ys = []
hp = []
for i in range(n):
	xy[i] = [int(item) for item in input().split()]
xy.sort()

for i in range(n):
	yxi[i]=[xy[i][1],xy[i][0],i]
yxi.sort()

cnt=[0]*(n+1)
cnt[0]=1
for i in range(1,n+1):
	cnt[i]=cnt[i-1]*2%md

def comb(x):
	return cnt[x]-1;

ans=0

for i in range(n):
	ix=yxi[i][2]
	a=get(ix)
	b=get(n)-get(ix)
	c=ix-a
	d=n-ix-1-b
	exc=(comb(a+b)+comb(a+c)+comb(b+d)+comb(c+d)-comb(a)-comb(b)-comb(c)-comb(d))%md
	cur=(comb(n)-exc)%md
	ans=(ans+cur)%md
	upd(ix)

if(ans<0):ans+=md

print(ans)


Fixed submission:
import sys
import array

from operator import itemgetter

def main():



	input = sys.stdin.readline


	md = 998244353
	n = int(input())
	tl=n+1
	
	ft=[0]*tl

	xy = [[0]*2 for _ in range(n)]
	for i in range(n):
		xy[i] = [int(item) for item in input().split()]
	xy.sort(key=itemgetter(0))
	yxi = [y for x, y in xy]

	*YS, = set(yxi)
	YS.sort()
	yxi= list(map({e: i for i, e in enumerate(YS)}.__getitem__, yxi))

	ct=[0]*(n+1)
	ct[0]=1
	for i in range(1,n+1):
		ct[i]=ct[i-1]*2%md

	cnt=tuple(ct)

	def upd(i):
		i+=1
		while(i<=n):
			ft[i]+=1
			i+=i&-i

	def get(i):
		i+=1
		ret=0
		while(i!=0):
		    ret+=ft[i]
		    i-=i&-i
		return ret

	def calc(get,upd):
		for i, y in enumerate(yxi):
			v = get(y); upd(y)
			p1 = cnt[v]; p0 = cnt[y - v]
			q1 = cnt[i - v]; q0 = cnt[(n - y - 1) - (i - v)]
			yield (p0 + p1 + q0 + q1 - (p0 + q1) * (p1 + q0)) % md


	print((sum(calc(get,upd))+n*cnt[n] - n)%md)

main()

Buggy python submission (verdict: Time Limit Exceeded):
#Modified from #6728952
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 = []

cnt=[0]*n

for i in range(n):
	cnt[i]=pow(2,i,md)

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)
    cy[i][3] = cnt[s]
    cy[i][2] = cnt[i - s]
    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)
    cy[i][0] = cnt[s]
    cy[i][1] = cnt[n - 1 - i - s]
    ys.insert(s, y)
#ans = pow(2, n - 1, md) * n % md
ans = cnt[n - 1]* 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
    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
import array

from operator import itemgetter

def main():



	input = sys.stdin.readline


	md = 998244353
	n = int(input())
	tl=n+1
	
	ft=[0]*tl

	xy = [[0]*2 for _ in range(n)]
	for i in range(n):
		xy[i] = [int(item) for item in input().split()]
	xy.sort(key=itemgetter(0))
	yxi = [y for x, y in xy]

	*YS, = set(yxi)
	YS.sort()
	yxi= list(map({e: i for i, e in enumerate(YS)}.__getitem__, yxi))

	ct=[0]*(n+1)
	ct[0]=1
	for i in range(1,n+1):
		ct[i]=ct[i-1]*2%md

	cnt=tuple(ct)

	def upd(i):
		i+=1
		while(i<=n):
			ft[i]+=1
			i+=i&-i

	def get(i):
		i+=1
		ret=0
		while(i!=0):
		    ret+=ft[i]
		    i-=i&-i
		return ret

	def calc(get,upd):
		for i, y in enumerate(yxi):
			v = get(y); upd(y)
			p1 = cnt[v]; p0 = cnt[y - v]
			q1 = cnt[i - v]; q0 = cnt[(n - y - 1) - (i - v)]
			yield (p0 + p1 + q0 + q1 - (p0 + q1) * (p1 + q0)) % md


	print((sum(calc(get,upd))+n*cnt[n] - n)%md)

main()