CodeEff/ECCO huggingface dataset:
# Original solution
import sys
from collections import deque

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() # input string
ni = lambda: int(readline().rstrip()) # input int
nm = lambda: list(map(int, readline().split())) # input multiple int 
nl = lambda: list(map(int, readline().split())) # input multiple int to list

ans = []
s = ns()
n = len(s) + 1
now = 0
min_now = 0

ri = deque()
le = deque()

now = 0
for i in range(n-1):
    if s[i] == '<':
        now += 1
    else:
        now = 0
    le.append(now)
now = 0
for i in range(n-1):
    if s[(n-2)-i] == '>':
        now += 1
    else:
        now = 0
    ri.appendleft(now)
le.appendleft(0)
ri.append(0)

for i in range(n):
    ans.append(max(le[i], ri[i]))

print((sum(ans)))

# Optimized solution
import sys
from collections import deque

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() # input string
ni = lambda: int(readline().rstrip()) # input int
nm = lambda: list(map(int, readline().split())) # input multiple int 
nl = lambda: list(map(int, readline().split())) # input multiple int to list

ans = []
s = ns()
n = len(s) + 1
now = 0
min_now = 0

ri = deque()
le = deque()

now = 0
for i in range(n-1):
    if s[i] == '<':
        now += 1
    else:
        now = 0
    le.append(now)
now = 0
for i in range(n-1):
    if s[(n-2)-i] == '>':
        now += 1
    else:
        now = 0
    ri.appendleft(now)
le.appendleft(0)
ri.append(0)

for i in range(n):
    ans.append(max(le.popleft(), ri.popleft()))

print((sum(ans)))
# Original solution
S = input().strip()
N = len(S)+1
A = [0 for _ in range(N)]
B = []
for i in range(N):
    if i==0 and S[i]=="<":
        B.append(0)
    elif i<N-2 and S[i]==">" and S[i+1]=="<":
        B.append(i+1)
    elif i==N-2 and S[i]==">":
        B.append(i+1)
for j in range(len(B)-1):
    ind0 = B[j]
    ind1 = B[j+1]
    c = ind0
    while S[c]=="<":
        A[c+1] = max(A[c+1],A[c]+1)
        c += 1
    c = ind1
    while S[c-1]==">":
        A[c-1] = max(A[c-1],A[c]+1)
        c -= 1
c = B[0]
if c>0:
    for i in range(c-1,-1,-1):
        A[i] = A[i+1]+1
c = B[-1]
if c<N-1:
    for i in range(c+1,N):
        A[i] = A[i-1]+1
print((sum(A)))

# Optimized solution
S = input().strip()
N = len(S)+1
A = [0 for _ in range(N)]
flag = -1
B = []
for i in range(N-1):
    if flag==-1 and S[i]=="<":
        B.append(i)
        flag = 1
    elif flag==1 and S[i]==">":
        flag = -1
if flag==-1:
    B.append(N-1)
for b in B:
    for i in range(b,N-1):
        if S[i]=="<":
            A[i+1] = max(A[i+1],A[i]+1)
        else:break
    for i in range(b-1,-1,-1):
        if S[i]==">":
            A[i] = max(A[i],A[i+1]+1)
        else:break
print((sum(A)))
# Original solution
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    s = str(input().rstrip('\n'))
    s = list(map(str, s.replace("><", ">_<").split("_")))
    cnt = 0
    for v in s:
        a = 0
        b = 0
        for i in range(len(v)):
            if v[i] == "<":
                a += 1
            else:
                b += 1
        if a != 0 and b != 0:
            cnt += (a - 1) * (1 + a - 1) // 2 + (b - 1) * (1 + b - 1) // 2
            cnt += max(a, b)
        elif b != 0:
            cnt += b * (1 + b) // 2
        elif a != 0:
            cnt += a * (1 + a) // 2
    print(cnt)


if __name__ == '__main__':
    solve()


# Optimized solution
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    s = str(readline().rstrip().decode('utf-8'))
    s = s.replace("><", ">_<").split("_")
    cnt = 0
    for sv in s:
        r = l = 0
        for i in range(len(sv)):
            if sv[i] == ">":
                r += 1
            else:
                l += 1
        cnt += r * (0 + r-1) // 2 + l * (0 + l-1) // 2 + max(r, l)
    print(cnt)


if __name__ == '__main__':
    solve()
# Original solution
import sys
input = sys.stdin.readline

S=tuple(input().strip())
N=len(S)+1
x = [0]

for i in range(1,N):
    if S[i-1] == '<':
        x.append(x[i-1] + 1)
    else:
        x.append(0)
        for j in range(i):
            if x[i-1-j] == x[i-j]:
                x[i-1-j] += 1
            else:
                break

print((sum(x)))


# Optimized solution
import sys
input = sys.stdin.readline

S=tuple(input().strip())
N=len(S)+1
sets = []
count = 0

for c in S:
    d = 1 if c == '<' else -1
    if count * d < 0:
        sets.append(count)
        count = d
    else:
        count += d
sets.append(count)

sum = 0
for i in range(len(sets)):
    k=sets[i]
    if k > 0:
        sum += (k*(k+1))//2
    else:
        sum += (k*(k-1))//2
        if i > 0:
            sum -= min(sets[i-1], -k)

print(sum)
# Original solution
m = int(eval(input()))
while m:
    m -= 1
    ax, ay, bx, by = list(map(int, input().split()))
    n = int(eval(input()))
    dx, dy = bx - ax, by - ay
    intersections = set()
    while n:
        n -= 1
        sx, sy, tx, ty, o, l = list(map(int, input().split()))
        tdx, tdy = tx - sx, ty - sy
        asx, asy = sx - ax, sy - ay
        denom = dx * tdy - dy * tdx
        if not denom:
            continue
        r = (tdy * asx - tdx * asy) / denom
        s = (dy * asx - dx * asy) / denom
        if not 0 < r < 1 or not 0 < s < 1:
            continue
        px = ax + r * dx
        intersections.add((px, o == l))

    pl, counter = -1, -1
    for px, l in sorted(intersections):
        counter += pl != l
        pl = l
    print((max(counter, 0)))

# Optimized solution
m = int(eval(input()))
while m:
    m -= 1
    ax, ay, bx, by = list(map(int, input().split()))
    n = int(eval(input()))
    dx, dy = bx - ax, by - ay
    intersections = set()
    while n:
        n -= 1
        sx, sy, tx, ty, o, l = list(map(int, input().split()))
        tdx, tdy = tx - sx, ty - sy
        asx, asy = sx - ax, sy - ay
        denom = dx * tdy - dy * tdx
        if not denom:
            continue
        r = (tdy * asx - tdx * asy) / denom
        s = (dy * asx - dx * asy) / denom
        if not 0 < r < 1 or not 0 < s < 1:
            continue
        intersections.add((r, o == l))

    pl, counter = -1, -1
    for r, l in sorted(intersections):
        counter += pl != l
        pl = l
    print((max(counter, 0)))
# Original solution
import sys
input = sys.stdin.readline

class BaseXor:
    def __init__(self):
        self.size = 0
        self.base = []
    
    def base_calculate(self, x, b):
        return min(x, x ^ b)

    def make_base(self, x):
        for b in self.base:
            x = self.base_calculate(x, b)
        return x
    
    def change_base(self, x):
        for i in range(self.size):
            self.base[i] = self.base_calculate(self.base[i], x)

    def add_base(self, x):
        x = self.make_base(x)
        if x == 0:
            return False
        self.change_base(x)
        self.base.append(x)
        self.base.sort()
        self.size += 1
        return True
    
    def judge_linearly_dependent(self, x):
        for b in self.base:
            x = self.base_calculate(x, b)
        res = True if x else False
        return res

def solve(n, a, s):
    base = BaseXor()
    judge = False
    for i in range(n-1, -1, -1):
        x = s[i]
        if x == "0":
            base.add_base(a[i])
        else:
            judge = base.judge_linearly_dependent(a[i])
            if judge:
                break
    
    res = 1 if judge else 0
    return res

def main():
    t = int(input())
    ans = [0]*t
    for i in range(t):
        n = int(input())
        a = list(map(int, input().split()))
        s = input()
        res = solve(n, a, s)
        ans[i] = res
    print(*ans, sep="\n")
    
if __name__ == "__main__":
    main()


# Optimized solution
import sys
input = sys.stdin.readline

class BaseXor:
    def __init__(self):
        self.size = 0
        self.base = []
    
    def base_calculate(self, x, b):
        return min(x, x ^ b)

    def make_base(self, x):
        for b in self.base:
            x = self.base_calculate(x, b)
        return x
    
    def change_base(self, x):
        for i in range(self.size):
            self.base[i] = self.base_calculate(self.base[i], x)

    def add_base(self, x):
        x = self.make_base(x)
        if x == 0:
            return False
        self.change_base(x)
        self.base.append(x)
        self.size += 1
        return True
    
    def judge_linearly_dependent(self, x):
        for b in self.base:
            x = self.base_calculate(x, b)
        res = True if x else False
        return res

def solve(n, a, s):
    base = BaseXor()
    judge = False
    for i in range(n-1, -1, -1):
        x = s[i]
        if x == "0":
            base.add_base(a[i])
        else:
            judge = base.judge_linearly_dependent(a[i])
            if judge:
                break
    
    res = 1 if judge else 0
    return res

def main():
    t = int(input())
    ans = [0]*t
    for i in range(t):
        n = int(input())
        a = list(map(int, input().split()))
        s = input()
        res = solve(n, a, s)
        ans[i] = res
    print(*ans, sep="\n")
    
if __name__ == "__main__":
    main()
# Original solution
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def f(a, s, n):
    if s[-1] == "1":
        return 1

    st = {0,}
    for i in range(n-1, -1, -1):
        ai, si = a[i], s[i]

        if si == "0":
            tmp = [ai ^x for x in st]
            st.update(tmp)
        else:
            if ai in  st:
                st.remove(ai)
            else:
                return 1
    return 0


def resolve():
    T = int(input())

    ans = []
    for i in range(T):
        N = int(input())
        A = list(iim())
        S  = input()

        ans.append(f(A, S, N))

    print(*ans, sep="\n")

if __name__ == "__main__":
    resolve()


# Optimized solution
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

X = (10**18).bit_length()

def f(a, s, n):
    if s[-1] == "1":
        return 1

    B = [None] * X
    for i in range(n-1, -1, -1):
        ai, si = a[i], s[i]

        if si == "0":
            while True:
                x = ai.bit_length() - 1
                if B[x] == ai: break
                elif B[x] == None:
                    B[x] = ai
                    break
                ai ^= B[x]
        else:
            while True:
                x = ai.bit_length() - 1
                if B[x] == ai: break
                elif B[x] == None:
                    return 1
                ai ^= B[x]
    return 0


def resolve():
    T = int(input())

    ans = []
    for i in range(T):
        N = int(input())
        A = list(iim())
        S  = input()

        ans.append(f(A, S, N))

    print(*ans, sep="\n")

if __name__ == "__main__":
    resolve()
# Original solution
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 逆から、人1が多かったらその時点で駄目、人0が人1の数を覆い尽くす必要がある
T = ir()

def solve():
    N = ir()
    A = lr()
    S = sr()
    dp = [None] * (N+1)
    dp[N] = {0}
    for i in range(N-1, -1, -1):
        if S[i] == '0':
            dp[i] = dp[i+1].copy()
            for element in dp[i+1]:
                dp[i].add(element ^ A[i])
        elif S[i] == '1':
            if A[i] not in dp[i+1]:
                return 1
            else:
                dp[i] = dp[i+1]
    return 0
    
for _ in range(T):
    print((solve()))


# Optimized solution
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 逆から, zero_cardsに数を貯めて行き、bitで0に出来るか
T = ir()
for _ in range(T):
    N = ir()
    A = lr()
    S = sr()
    zero_cards = []
    for a, person in zip(A[::-1], S[::-1]):
        for z in zero_cards:
            a = min(a, a^z)
        if a:
            if person == '1':
                print((1))
                break
            zero_cards.append(a)
    else:
        print((0))
# Original solution
import sys
from copy import deepcopy

def canMake(k, Nums):#Numsにある数でkを作れるか
    L = len(Nums)
    index = 0
    bit = []
    for i in reversed(range(60)):
        flag = 0
        for j in range(index, L):
            if Nums[j] & (1 << i) == (1 << i):
                flag = 1
                Nums[index], Nums[j] = Nums[j], Nums[index]
                bit.append(i)
                break
        if flag == 1:
            for j in range(L):
                if Nums[j] & (1 << i) == (1 << i) and index != j: Nums[j] ^= Nums[index]
        if flag == 1: index += 1
    ans = 0
    for i in range(60):
        if k & (1 << i) == (1 << i):
            if i in bit: ans ^= Nums[bit.index(i)]
    if ans == k: return True
    else: return False


def solve():
    input = sys.stdin.readline
    T = int(input())
    Ans = [0] * T
    for t in range(T):
        N = int(input())
        A = [int(a) for a in input().split()]
        S = input().strip("\n")
        used = []
        for i in reversed(range(N)):
            if S[i] == "0":
                used.append(A[i])
            else:
                compare = deepcopy(used)
                if not canMake(A[i], compare):
                    Ans[t] = 1
                    break
    
    print(*Ans, sep="\n")

    return 0

if __name__ == "__main__":
    solve()


# Optimized solution
import sys
from copy import deepcopy

def canMake(k, Nums):#Numsにある数でkを作れるか
    L = len(Nums)
    index = 0
    bit = dict()
    for i in reversed(range(60)): #掃き出し法
        flag = 0
        tp = (1 << i)
        for j in range(index, L):
            if Nums[j] & tp == tp:
                flag = 1
                Nums[index], Nums[j] = Nums[j], Nums[index]
                bit[i] = index
                break
        if flag == 1:
            for j in range(L):
                if Nums[j] & tp == tp and index != j: Nums[j] ^= Nums[index]
        if flag == 1: index += 1

    #実際にkを作ることができるか
    ans = 0
    for i in range(60):
        if k & (1 << i) == (1 << i):
            if i in bit: ans ^= Nums[bit[i]]
    if ans == k: return True
    else: return False


def solve():
    input = sys.stdin.readline
    T = int(input())
    Ans = [0] * T
    for t in range(T):
        N = int(input())
        A = [int(a) for a in input().split()]
        S = input().strip("\n")
        used = []
        for i in reversed(range(N)):
            if S[i] == "0":
                used.append(A[i])
            else:
                compare = deepcopy(used)
                if not canMake(A[i], compare):
                    Ans[t] = 1
                    break
    
    print(*Ans, sep="\n")

    return 0

if __name__ == "__main__":
    solve()
# Original solution
from collections import defaultdict
from functools import lru_cache
itl = lambda: list(map(int, input().strip().split()))


def solve():
    N = int(eval(input()))
    nums = itl()
    S = input().strip()
    @lru_cache(None)
    def dp(i, target):
        if i == N:
            return (target == 0)
        if S[i] == '0':
            return dp(i + 1, target ^ nums[i]) or dp(i + 1, target)
        else:
            return dp(i + 1, target ^ nums[i]) and dp(i + 1, target)
    return 0 if dp(0, 0) else 1


T = int(eval(input()))
for _ in range(T):
    print((solve()))

# Optimized solution
from collections import defaultdict
itl = lambda: list(map(int, input().strip().split()))


def solve():
    N = int(eval(input()))
    nums = itl()
    S = input().strip()

    basis = []
    for i in range(N - 1, -1, -1):
        v = nums[i]
        for b in basis:
            v = min(v, v ^ b)
        if v:
            if S[i] == '1':
                return 1
            basis.append(v)
    return 0    


T = int(eval(input()))
for _ in range(T):
    print((solve()))
# Original solution
I=input
n=int
for i in range(n(eval(input()))):
  I();t=[];x=0
  for i,j in zip(list(map(n,I().split()[::-1])),I()[::-1]):
    for k in t:i^=k*(i^k<i)
    j=n(j);t+=[i*(j^1)];x|=(i>0)&j
  print(x)

# Optimized solution
I=input
n=int
for i in range(n(eval(input()))):
  I();t=[];x=0
  for i,j in zip(list(map(n,I().split()[::-1])),I()[::-1]):
    [i:=(i^k*(i^k<i))for k in t];j=n(j);t+=[i*(j^1)];x|=(i>0)&j
  print(x)
# Original solution
x,y=input().split()
while (x!='0'or y!='0'):
    if(int(x)>int(y)):print(("{} {}".format(y,x)))
    else:print(("{} {}".format(x,y)))
    x,y=input().split()

# Optimized solution
while 1:
    x,y=map(int,input().split())
    if x==0 and y==0:break
    print(*[y,x] if x>y else [x,y])
# Original solution
while 1:
 n=input()
 if n=='0 0':break
 x,y=map(int,n.split())
 print(y,x) if x>y else print(n)


# Optimized solution
a=[]
while 1:
 n=input()
 if n=='0 0':break
 a.append(n)
for s in a:
 x,y=map(int,s.split())
 print(y,x) if x>y else print(s)
# Original solution
while True:
	x, y = list(map(int, input().split()))
	if (x == 0 and y == 0) :
		break
	if (x < y) :
		print((str(x) + " " + str(y)))
	else :
		print((str(y) + " " + str(x)))

# Optimized solution
while True:
	t = input().split()
	a = int(t[0])
	b = int(t[1])
	if (a == 0) and (b == 0):
			break
	if (a < b):
		print((str(a) + " " + str(b)))
	else:
		print((str(b) + " " + str(a)))
# Original solution
while True:
	a,b = list(map(int, input().split()))
	if (a == 0) and (b == 0):
		break
	elif (a < b):
		print((str(a) + " " + str(b)))
	else :
		print((str(b) + " " + str(a)))

# Optimized solution

while True:
	a,b = list(map(int, input().split()))
	if (a == 0 and b == 0):
		break
	else:
		if (a < b):
			print((str(a) + " " + str(b)))

		else :
			print((str(b) +" "+ str(a)))
# Original solution
import sys

while True:
	xy=sys.stdin.readline()
	nums=xy.split( ' ' )
	for i in range( len( nums) ):
		nums[i] = int( nums[i] )
	if nums[0] == 0 and nums[1] == 0:
		break
	else:
		if nums[1] < nums[0]:
			t=nums[0]
			nums[0]=nums[1]
			nums[1]=t
		print(( "{} {}".format( nums[0], nums[1] ) ))

# Optimized solution
import sys

while True:
	nums = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
	if 0 == nums[0] and 0 == nums[1]:
		break
	else:
		nums.sort()
		print(( "{} {}".format( nums[0], nums[1] ) ))
# Original solution
import sys
for line in sys.stdin:
    a,b = line.split()
    a,b = int(a),int(b)
    if a == 0 and b == 0: break
    if b<a: a,b = b,a
    print('%d %d' %(a, b))

# Optimized solution
while True:
    a, b = sorted(map(int, input().split()))
    if (a, b) == (0, 0): break
    print(a, b)
# Original solution
while 1:
	a,b = list(map(int, input().split()))
	if a == b == 0:
		break
	elif a < b:
		print("%s %s" % (a,b))
	else:
		print("%s %s" % (b,a))

# Optimized solution
while 1:
	a,b = list(map(int, input().split()))
	if a == 0 and b == 0:
		break
	elif a < b:
		print(a, b)
	else:
		print(b, a)
# Original solution
import sys
input = sys.stdin.readline
from collections import *

def compress(l):
    l = list(set(l))
    l.sort()
    idx = defaultdict(int)

    for i in range(len(l)):
        idx[l[i]] = i
    
    return idx
    
class BIT:
    def __init__(self, n):
        self.n = n
        self.bit = [0]*(n+1)
    
    def add(self, i, x):
        i += 1
        
        while i<=self.n:
            self.bit[i] += x
            i += i&(-i)

    def acc(self, i):
        s = 0
        
        while i>0:
            s += self.bit[i]
            i -= i&(-i)
        
        return s

N = int(eval(input()))
xy = [tuple(map(int, input().split())) for _ in range(N)]
xy.sort(key=lambda t: t[0])
idx = compress([xy_i[1] for xy_i in xy])
lbit = BIT(N)
rbit = BIT(N)

for i in range(N):
    rbit.add(i, 1)
    
ans = 0
MOD = 998244353

for i in range(N):
    y = xy[i][1]
    rbit.add(idx[y], -1)
    a = i-lbit.acc(idx[y])
    b = lbit.acc(idx[y])
    c = rbit.acc(idx[y])
    d = N-1-i-rbit.acc(idx[y])
    add = 2*pow(2, N-1, MOD)-1
    add = (add-(pow(2, a, MOD)-1))%MOD
    add = (add-(pow(2, b, MOD)-1))%MOD
    add = (add-(pow(2, c, MOD)-1))%MOD
    add = (add-(pow(2, d, MOD)-1))%MOD
    add = (add-(pow(2, a+b, MOD)-pow(2, a, MOD)-pow(2, b, MOD)+1))%MOD
    add = (add-(pow(2, b+c, MOD)-pow(2, b, MOD)-pow(2, c, MOD)+1))%MOD
    add = (add-(pow(2, c+d, MOD)-pow(2, c, MOD)-pow(2, d, MOD)+1))%MOD
    add = (add-(pow(2, d+a, MOD)-pow(2, d, MOD)-pow(2, a, MOD)+1))%MOD
    ans += add
    ans %= MOD
    lbit.add(idx[y], 1)

print(ans)

# Optimized solution
import sys
input = sys.stdin.readline
from collections import *

def compress(l):
    l = list(set(l))
    l.sort()
    idx = defaultdict(int)

    for i in range(len(l)):
        idx[l[i]] = i
    
    return idx
    
class BIT:
    def __init__(self, n):
        self.n = n
        self.bit = [0]*(n+1)
    
    def add(self, i, x):
        i += 1
        
        while i<=self.n:
            self.bit[i] += x
            i += i&(-i)

    def acc(self, i):
        s = 0
        
        while i>0:
            s += self.bit[i]
            i -= i&(-i)
        
        return s

N = int(eval(input()))
xy = [tuple(map(int, input().split())) for _ in range(N)]
xy.sort(key=lambda t: t[0])
idx = compress([xy_i[1] for xy_i in xy])
lbit = BIT(N)
rbit = BIT(N)

for i in range(N):
    rbit.add(i, 1)
    
ans = 0
MOD = 998244353

for i in range(N):
    y = xy[i][1]
    rbit.add(idx[y], -1)
    a = i-lbit.acc(idx[y])
    b = lbit.acc(idx[y])
    c = rbit.acc(idx[y])
    d = N-1-i-rbit.acc(idx[y])
    add = 2*pow(2, N-1, MOD)-1
    pa = pow(2, a, MOD)
    pb = pow(2, b, MOD)
    pc = pow(2, c, MOD)
    pd = pow(2, d, MOD)
    add = (add-(pa-1))%MOD
    add = (add-(pb-1))%MOD
    add = (add-(pc-1))%MOD
    add = (add-(pd-1))%MOD
    add = (add-(pa*pb-pa-pb+1))%MOD
    add = (add-(pb*pc-pb-pc+1))%MOD
    add = (add-(pc*pd-pc-pd+1))%MOD
    add = (add-(pd*pa-pd-pa+1))%MOD
    ans += add
    ans %= MOD
    lbit.add(idx[y], 1)

print(ans)
# Original solution
n=int(eval(input()))
l=[list(map(int,input().split())) for i in range(n)]
mod=998244353
from operator import itemgetter
l.sort(key=itemgetter(1))
for i in range(n):
    l[i][1]=i
l.sort(key=itemgetter(0))
for i in range(n):
    l[i][0]=i

No=2
while No<=n:
    No*=2
tree=[0]*(2*No)

def add(k,x):
    k+=No-1
    while k>=0:
        tree[k]+=x
        k=(k-1)//2
def query(l,r):
    L=l+No-1
    R=r+No-1
    s=0
    while L<=R:
        if R&1:
            s+=tree[R]
            R-=2
        else:
            R-=1
        if L&1:
            L-=1
        else:
            s+=tree[L]
        L>>=1;R>>=1
    return s
pow2=[1 for i in range(n+2)]
t=2
for i in range(1,n+2):
    pow2[i]=t
    t*=2
    t%=mod
ans=0
for x,y in l:
    lu=query(y,n)
    ld=query(0,y)
    ru=n-1-y-lu
    rd=y-ld
    ans+=pow2[n-1]+(pow2[lu]-1)*(pow2[rd]-1)*(pow2[ru]+pow2[ld]-1+(pow2[ld]-1)*(pow2[ru]-1))%mod+(pow2[ld]-1)*(pow2[ru]-1)*(pow2[rd]+pow2[lu]-1)%mod
    ans%=mod
    add(y,1)
print(ans)

# Optimized solution
import sys
input=sys.stdin.readline
n=int(eval(input()))
l=[list(map(int,input().split())) for i in range(n)]
mod=998244353
from operator import itemgetter
l.sort(key=itemgetter(1))
for i in range(n):
    l[i][1]=i
l.sort(key=itemgetter(0))

No=2
while No<=n:
    No*=2
tree=[0]*(2*No)

def add(k,x):
    k+=No-1
    while k>=0:
        tree[k]+=x
        k=(k-1)//2
def query(l,r):
    L=l+No-1
    R=r+No-1
    s=0
    while L<=R:
        if R&1:
            s+=tree[R]
            R-=2
        else:
            R-=1
        if L&1:
            L-=1
        else:
            s+=tree[L]
        L>>=1;R>>=1
    return s
pow2=[1 for i in range(n+2)]
t=2
for i in range(1,n+2):
    pow2[i]=t
    t*=2
    t%=mod
ans=0
for x,y in l:
    lu=query(y,n)
    ld=query(0,y)
    ru=n-1-y-lu
    rd=y-ld
    ans+=pow2[n-1]+(pow2[lu]-1)*(pow2[rd]-1)%mod*(pow2[ru]+pow2[ld]-1+(pow2[ld]-1)*(pow2[ru]-1))%mod+(pow2[ld]-1)*(pow2[ru]-1)%mod*(pow2[rd]+pow2[lu]-1)%mod
    ans%=mod
    add(y,1)
print(ans)