CodeEff/ECCO huggingface dataset:
# Original solution
n = int(eval(input()))
A = sorted(list(map(int, input().split())))
print((sum(A[-2:-2 * n - 1:-2])))

# Optimized solution
n = int(eval(input()))
print((sum(sorted(list(map(int, input().split())))[n::2])))
# Original solution
n=int(eval(input()))
a=sorted(map(int,input().split()),reverse=True)
b=[]
while len(a):
    for i in range(n):
        a.remove(max(a))
        b.append(max(a))
        a.remove(max(a))
        a.remove(min(a))
print((sum(b)))

# Optimized solution
n=int(eval(input()))
a=sorted(map(int,input().split()))
print((sum(a[n::2])))
# Original solution
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()
    a = LI()
    a.sort(key = lambda x:-x)
    ans = 0
    for i in range(n):
        ans += a[2*i+1]
    print(ans)
    return

#B
def B():
    def dfs(d,x,c):
        if d <= dp[x]:
            return
        dp[x] = d
        if not f[x]:
            f[x] = c
        for y in v[x]:
            dfs(d-1,y,c)
    n,m = LI()
    f = [0]*n
    v = [[] for i in range(n)]
    for i in range(m):
        a,b = LI()
        a -= 1
        b -= 1
        v[a].append(b)
        v[b].append(a)
    dp = defaultdict(lambda : -1)
    q = I()
    l = LIR(q)
    l = l[::-1]
    for x,d,c in l:
        x -= 1
        dfs(d,x,c)
    for i in f:
        print(i)
    return

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    A()


# Optimized solution
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    a.sort(reverse=True)
    print((sum(a[1:2*n:2])))
    return

#Solve
if __name__ == "__main__":
    solve()
# Original solution
N = int(eval(input()))
A = [int(a) for a in input().split()]
A.sort()
A = A[N:]
ans = 0
for i in range(N):
    ans += A[2*i]
print(ans)

# Optimized solution
import sys

def solve():
    input = sys.stdin.readline
    N = int(eval(input()))
    A = [int(a) for a in input().split()]
    A.sort(reverse = True)
    ans = 0
    for i in range(N):
        ans += A[2 * i + 1]
    print(ans)
    return 0

if __name__ == "__main__":
    solve()
# Original solution
N = int(eval(input()))
participants = sorted([ int(v) for v in input().split(" ") ], reverse=True)

# 1 2 4 5 5 5 7 8 9 
# 1 2 5 5 5 8

sum = 0
for i in range(N):
  #print(participants)
  c_max = participants.pop(0)
  n_max = participants.pop(0)
  c_min = participants.pop(-1)
  sum += n_max

print(sum)

# Optimized solution
N = int(eval(input()))
participants = sorted([ int(v) for v in input().split(" ") ], reverse=True)

# 1 2 4 5 5 5 7 8 9 
# 1 2 5 5 5 8

sum = 0
for i in range(0, N):
  #print(participants)
  #c_max = participants.pop(0)
  #n_max = participants.pop(0)
  #c_min = participants.pop(-1)
  sum += participants[2*i+1]

print(sum)
# Original solution
N = int(eval(input()))
l = list(map(int,input().split()))
l.sort(reverse=True)
ans = 0
teams = []
for i in range(N):
    teams.append([l[0],l[1],l[-1]])
    l.remove(l[0])
    l.remove(l[1])
    l.remove(l[-1])

print((sum([i[1] for i in teams])))

# Optimized solution
N = int(eval(input()))
l = list(map(int,input().split()))
l.sort(reverse=True)
ans = l[1::2]

print((sum(ans[:N])))
# Original solution
n = int(eval(input()))
players_powers = sorted(list(map(int, input().rstrip("\n").split())), reverse=True)

print((sum(players_powers[1::2][:n])))


# Optimized solution
n = int(eval(input())); print((sum(sorted(map(int, input().split()), reverse=True)[1:2*n + 1:2])))
# Original solution
from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue
from heapq import heappop, heappush
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
a.sort()
res = 0
ind = n
for i in range(n):
    if i == 0:
        res += a[ind]
        continue
    ind += 2
    res += a[ind]
print(res)

# Optimized solution
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
a.sort(reverse = True)
cnt = n
ind = 0
res = 0
while cnt:
    if ind % 2:
        res += a[ind]
        cnt -= 1
    ind += 1
print(res)
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))
a.sort()
print((sum(a[n::2])))

# Optimized solution
def solve():
    n = int(eval(input()))
    a= list(map(int,input().split()))
    a = sorted(a,reverse=True)
    res = sum(a[1:2*n:2])
    print(res)
if __name__=='__main__':
    solve()
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
a.reverse()
ans = 0
for i in a[1:-n:2]:
    ans += i
print(ans)


# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
a.reverse()
print((sum(a[1:-n:2])))
# Original solution
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    a.sort(reverse=True)
    print((sum(a[1:n*2:2])))


if __name__ == '__main__':
    slove()


# Optimized solution
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    a.sort(reverse=True)
    t = 0
    for i in range(1, n * 2, 2):
        t += a[i]
    print(t)


if __name__ == '__main__':
    solve()
# Original solution
N = eval(input())
arr = list(map(int, input().split()))
arr.sort()
sum = 0
for i in range(3*N-2, N-1, -2):
  sum += arr[i]
print(sum)

# Optimized solution
N = int(eval(input()))
src = list(map(int,input().split()))
src.sort(reverse=True)
print((sum(src[1:2*N+1:2])))
# Original solution
n = int(eval(input()))
a = sorted(list(map(int, input().split())), reverse=True)
print((sum(a[1:n * 2:2])))

# Optimized solution
n = int(eval(input()))
a = sorted(list(map(int, input().split())))
print((sum(a[n:3 * n:2])))
# Original solution
N = int(eval(input()))
a = list(map(int,input().split()))
a.sort(reverse = True)
x = 0

for i in range(N):
    x += a[2 * i + 1]
print(x)

# Optimized solution
N = int(eval(input()))
a = sorted(list(map(int, input().split())),reverse=True)
x = 0

for i in range(N):
    x += a[2*i+1]
print(x)
# Original solution
n = int(eval(input()))
k = n // 3
a = list(map(int, input().split()))

a = sorted(a, reverse = True)
ans = 0
for i in range(2*n):
    if i % 2 == 1:
        ans += a[i]
print(ans)

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))

a = sorted(a, reverse=True)

ans = 0
for i in range(n):
    ans += a[2 * i + 1]
print(ans)
# Original solution
N = int(eval(input()))
A = list(sorted(map(int, input().split())))
# N = 10
# A = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]
# A = sorted(A)
# print(A)

total = 0
cnt = 0
for i in range(3 * N - 2, 0, -2):
    cnt += 1
    total += A[i]

    if cnt == N:
        break
print(total)


# Optimized solution
# https://atcoder.jp/contests/agc012/tasks/agc012_a

N = int(eval(input()))
a = list(sorted(map(int, input().split())))
print((sum(a[N::2])))
# Original solution
n=int(eval(input()))
a=[int(i) for i in input().split()]
a.sort(reverse=True)
ans=0
for i in range(n):
  del a[0]
  ans+=a[0]
  del a[0]
print(ans)

# Optimized solution
n=int(eval(input()))
a=[int(i) for i in input().split()]
a.sort(reverse=True)
ans=0
for i in range(n):
  ans+=a[i*2+1]
print(ans)
# Original solution
N = int(eval(input()))
A = list(map(int,input().split()))
A.sort(reverse=True)
print((max(sum(A[N:2*N]),sum(A[1:2*N:2]))))

# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
A.sort(reverse=True)
print((sum(A[1:2*N:2])))
# Original solution
n = int(eval(input()))
l = list(map(int, input().split()))
l.sort()
power = 0
for i in range(len(l)//3):
    power += l[-2]
    l = l[1:-2]
print(power)

# Optimized solution
n = int(eval(input()))
l = list(map(int, input().split()))
l.sort()
power = 0
for i in range(1,len(l)//3+1):
    power += l[-2*i]
print(power)
# Original solution
N = eval(input())
N =int(N)
nums= list(map(int,input().split(" ")))
nums.sort()
ans = 0

for _ in  range(N):
    nums.pop(-1)
    ans += nums.pop(-1)
    nums.pop(0)
print(ans)

# Optimized solution
N = eval(input())
N =int(N)
nums= list(map(int,input().split(" ")))
nums.sort()
ans = 0

for _ in  range(N):
    nums.pop()
    ans += nums.pop()
print(ans)
# Original solution
print(sum(sorted(list([float(None==exec("N=int(input())"))] + list(map(int, input().split()))), reverse=True,key=lambda x: 10 ** 10 if type(x) == float else x)[2:2*N+1:2]))


# Optimized solution
print(sum(sorted(list(map(int,exec("N=int(input())")or input().split())))[-2:-2*N-1:-2]))
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
ans = int(0)
#一番チームで最弱のやつを取り出す
for i in range(n):
   ans = sum(a[n:3*n:2])
print(ans)
    

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
ans = int(0)
#一番チームで最弱のやつを取り出す

ans = sum(a[n:3*n:2])
print(ans)
# Original solution
def a_atCoder_group_contest(N, A):
    A.sort()
    ans = 0
    for k in range(N):
        group = [A[k], A[3 * N - (2 * k + 2)], A[3 * N - (2 * k + 1)]]
        ans += group[1]
    return ans

N = int(eval(input()))
A = [int(i) for i in input().split()]
print((a_atCoder_group_contest(N, A)))

# Optimized solution
def a_atCoder_group_contest(N, A):
    A.sort(reverse=True)
    ans = sum(A[1:2 * N:2])  # Aが0-indexedなので、 1, 3,..., 2N-1 番の和をとる
    return ans

N = int(eval(input()))
A = [int(i) for i in input().split()]
print((a_atCoder_group_contest(N, A)))
# Original solution
n = eval(input())
elem = list(map(int, input().split()))
elem.sort()
ans = 0
while len(elem) > 0:
    elem.pop(0)
    ans = ans + elem.pop(-2)
    elem.pop(-1)
print(ans)

# Optimized solution
n = int(eval(input()))
elem = list(map(int, input().split()))
elem.sort()
ans = sum(elem[n::2])
print(ans)
# Original solution
n = int(eval(input()))
a = sorted(list(map(int, input().split())), reverse=True)
ans = 0

for i in range(n):
    ans += a[i * 2 + 1]

print(ans)

# Optimized solution
n = int(eval(input()))
a = sorted(map(int, input().split()))
print((sum(a[n::2])))
# Original solution
n = int(eval(input()))
a = sorted(list(map(int, input().split())), reverse=True)

ans = 0

for i in range(1, 2*n, 2):
    ans += a[i]

print(ans)

# Optimized solution
n = int(eval(input()))
A = sorted(list(map(int, input().split())), reverse=True)

#print(A)
ans = 0
for i in range(1, 2*n+1, 2):
  ans += A[i]
print(ans)
# Original solution
N = int(eval(input()))
A = list(map(int,input().split()))
A.sort()
ans  = 0
for i in range(N):
    A.pop(-1)
    ans += A.pop(-1)
    A.pop(0)
print(ans)

# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
A.sort()
A.reverse()
ans  = 0
for i in range(1,2*N + 1,2):
    ans += A[i]
print(ans)
# Original solution
n = int(input())
xy = []
idx = [None]*n
ys = [None]*n
ans = [None]*n
accumx = [None]*n
accumn = [None]*n
for i in range(n):
    x, y = map(int, input().split())
    idx[x-1] = i
    ys[x-1] = y-1
accumx[-1] = ys[-1]
for i in range(n-2, -1, -1):
    accumx[i] = max(accumx[i+1], ys[i])
accumn[0] = ys[0]
for i in range(1, n):
    accumn[i] = min(accumn[i-1], ys[i])

def bisect(x):
    ok = 0
    ng = n
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if accumx[mid]>x:
            ok = mid
        else:
            ng = mid
    return ok

nowx = 0
while nowx<n:
    nxtx = nowx
    tmp = bisect(ys[nowx])
    while tmp>nxtx:
        nxtx = tmp
        tmp = bisect(accumn[nxtx])
    if nxtx<nowx:
        nxtx = nowx
    for i in range(nowx, nxtx+1):
        ans[idx[i]] = nxtx-nowx+1
    nowx = nxtx + 1
print(*ans, sep='\n')


# Optimized solution
n = int(input())
xy = []
idx = [None]*n
ys = [None]*n
ans = [None]*n
accumn = [None]*n
for i in range(n):
    x, y = map(int, input().split())
    idx[x-1] = i
    ys[x-1] = y-1
accumn[0] = ys[0]
for i in range(1, n):
    accumn[i] = min(accumn[i-1], ys[i])

b = 0
for i in range(n):
    if accumn[i]==n-i-1:
        for j in range(b, i+1):
            ans[idx[j]] = i-b+1
        b = i+1
print(*ans, sep='\n')
# Original solution
import sys
input = sys.stdin.readline

class Unionfind:
     
    def __init__(self,n):
        self.uf = [-1]*n
 
    def find(self,x):
        if self.uf[x] < 0:
            return x
        else:
            self.uf[x] = self.find(self.uf[x])
            return self.uf[x]
 
    def same(self,x,y):
        return self.find(x) == self.find(y)
 
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.uf[x] > self.uf[y]:
            x,y = y,x
        self.uf[x] += self.uf[y]
        self.uf[y] = x
        return True
 
    def size(self,x):
        x = self.find(x)
        return -self.uf[x]

def main():
    n = int(eval(input()))
    xy = [list(map(int,input().split())) for i in range(n)]
    xy2 = [[x[0],x[1],i] for (i,x) in enumerate(xy)]
    xy2.sort()
    u = Unionfind(n)

    s = set()
    for i,X in enumerate(xy2):
        x,y,ind = X
        check = True
        cand = []
        mi = -1
        count = n+5
        for j in s:
            if y > xy[j][1]:
                check = False
                u.union(ind,j)
                if count > xy[j][1]:
                    count = xy[j][1]
                    mi = j
            
        if check:
            s.add(ind)
        else:
            for j in cand:
                if j == mi:
                    continue
                del s[j]
    for i in range(n):
        print((u.size(i)))

if __name__ == "__main__":
    main()

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

class Unionfind:
     
    def __init__(self,n):
        self.uf = [-1]*n
 
    def find(self,x):
        if self.uf[x] < 0:
            return x
        else:
            self.uf[x] = self.find(self.uf[x])
            return self.uf[x]
 
    def same(self,x,y):
        return self.find(x) == self.find(y)
 
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.uf[x] > self.uf[y]:
            x,y = y,x
        self.uf[x] += self.uf[y]
        self.uf[y] = x
        return True
 
    def size(self,x):
        x = self.find(x)
        return -self.uf[x]

def main():
    n = int(eval(input()))
    xy = [list(map(int,input().split())) for i in range(n)]
    xy2 = [[x[0],x[1],i] for (i,x) in enumerate(xy)]
    xy2.sort()
    u = Unionfind(n)

    l = []
    for x,y,ind in xy2:
        M = y
        le = ind
        while l and xy[l[-1]][1] < y:
            v = l.pop()
            if M > xy[v][1]:
                M = xy[v][1]
                le = v
            u.union(ind,v)
        l.append(le)
    for i in range(n):
        print((u.size(i)))

if __name__ == "__main__":
    main()
# Original solution
class Union:
  def __init__(s, num):
    s.T = [-1 for i in range(num)]
 
  def root(s, x):
    if s.T[x] < 0: return x, -s.T[x]
    t, k = s.root(s.T[x])
    s.T[x] = t
    return t, k
 
  def merge(s, x, y):
    an, am = s.root(x)
    bn, bm = s.root(y)
    if an == bn: return False
    if am < bm: an, bn  = bn, an
    s.T[an] += s.T[bn]
    s.T[bn] = an
    return True
 
  def size(s, x):
    return s.root(x)[1]

  def same(s, x, y):
    return s.root(x)[0] == s.root(y)[0]

import heapq
pop = heapq.heappop
push = heapq.heappush
q  = []

N = int(eval(input()))
xy = [list(map(int, input().split())) for _ in range(N)]

uni = Union(N)

xyn = [[0] * 3 for _ in range(N)]
for i in range(N):
  x, y = xy[i]
  xyn[i] = [x, y, i]

xyn.sort()

push(q, [xyn[0][1], xyn[0][2]])
for i in range(1, N):
  x, y, n = xyn[i]
  m = pop(q)
  yy, nn = m
  if yy < y:
    uni.merge(nn, n)
    while q:
      yy, nn = pop(q)
      if yy < y:
        uni.merge(nn, n)
      else:
        push(q, [yy, nn])
        break
  else:
    push(q, [y, n])
  push(q, m)

for i in range(N):
  print((uni.root(i)[1]))


# Optimized solution
class Union:
  def __init__(s, num):
    s.T = [-1 for i in range(num)]
 
  def root(s, x):
    if s.T[x] < 0: return x, -s.T[x]
    t, k = s.root(s.T[x])
    s.T[x] = t
    return t, k
 
  def merge(s, x, y):
    an, am = s.root(x)
    bn, bm = s.root(y)
    if an == bn: return False
    if am < bm: an, bn  = bn, an
    s.T[an] += s.T[bn]
    s.T[bn] = an
    return True
 
  def size(s, x):
    return s.root(x)[1]

  def same(s, x, y):
    return s.root(x)[0] == s.root(y)[0]

import heapq
pop = heapq.heappop
push = heapq.heappush
q  = []

N = int(eval(input()))
xy = [list(map(int, input().split())) for _ in range(N)]

uni = Union(N)

xyn = [[0] * 3 for _ in range(N)]
for i in range(N):
  x, y = xy[i]
  xyn[i] = [x, y, i]

xyn.sort()
x, y, n = xyn[0]
push(q, (y << 20) + n)
for i in range(1, N):
  x, y, n = xyn[i]
  m = pop(q)
  yy, nn = m >> 20, m % (1 << 20)
  if yy < y:
    uni.merge(nn, n)
    while q:
      p = pop(q)
      yy, nn = p >> 20, p % (1 << 20)
      if yy < y:
        uni.merge(nn, n)
      else:
        push(q, (yy << 20) + nn)
        break
  else:
    push(q, (y << 20) + n)
  push(q, m)

for i in range(N):
  print((uni.root(i)[1]))
# Original solution
import heapq
from collections import deque

def bfs(i, c):
    color[i] = c
    cnt[c] += 1
    q = deque()
    q.append(i)
    while q:
        j = q.popleft()
        for k in G[j]:
            if color[k] == -1:
                color[k] = c
                cnt[c] += 1
                q.append(k)
    return

n = int(eval(input()))
xy = []
for i in range(n):
    x, y = list(map(int, input().split()))
    xy.append([x, y, i])
xy.sort()
cnt = [0] * n
h = [[n + 1, n + 1]]
G = []
for _ in range(n):
    G.append([])
for i in range(n):
    c = 0
    while h[0][0] < xy[i][1]:
        p = heapq.heappop(h)
        if c == 0:
            minv = p
        c = 1
        G[p[1]].append(xy[i][2])
        G[xy[i][2]].append(p[1])
    heapq.heappush(h, [xy[i][1], xy[i][2]])
    if c:
        heapq.heappush(h, minv)
color = [-1] * n
c = 0
for i in range(n):
    if color[i] == -1:
        bfs(i, c)
        c += 1
for i in range(n):
    ans = cnt[color[i]]
    print(ans)

# Optimized solution
import heapq
from collections import deque

def bfs(i, c):
    color[i] = c
    cnt[c] += 1
    q = deque()
    q.append(i)
    while q:
        j = q.popleft()
        for k in G[j]:
            if color[k] == -1:
                color[k] = c
                cnt[c] += 1
                q.append(k)
    return

n = int(eval(input()))
xy = []
for i in range(n):
    x, y = list(map(int, input().split()))
    xy.append([x, y, i])
xy.sort()
cnt = [0] * n
h = [[n + 1, n + 1]]
G = []
for _ in range(n):
    G.append([])
for i in range(n):
    c = 0
    while h[0][0] < xy[i][1]:
        p = heapq.heappop(h)
        if c == 0:
            minv = p
        c = 1
        G[p[1]].append(xy[i][2])
        G[xy[i][2]].append(p[1])
    #heapq.heappush(h, [xy[i][1], xy[i][2]])
    if c:
        heapq.heappush(h, minv)
    else:
        heapq.heappush(h, [xy[i][1], xy[i][2]])
color = [-1] * n
c = 0
for i in range(n):
    if color[i] == -1:
        bfs(i, c)
        c += 1
for i in range(n):
    ans = cnt[color[i]]
    print(ans)
# Original solution
import heapq
from collections import deque

def bfs(i, c):
    color[i] = c
    cnt[c] += 1
    q = deque()
    q.append(i)
    while q:
        j = q.popleft()
        for k in G[j]:
            if color[k] == -1:
                color[k] = c
                cnt[c] += 1
                q.append(k)
    return

n = int(eval(input()))
xy = []
for i in range(n):
    x, y = list(map(int, input().split()))
    xy.append([x, y, i])
xy.sort()
cnt = [0] * n
h = [[n + 1, n + 1]]
G = []
for _ in range(n):
    G.append([])
for i in range(n):
    c = 0
    while h[0][0] < xy[i][1]:
        p = heapq.heappop(h)
        if c == 0:
            minv = p
        c = 1
        G[p[1]].append(xy[i][2])
        G[xy[i][2]].append(p[1])
    #heapq.heappush(h, [xy[i][1], xy[i][2]])
    if c:
        heapq.heappush(h, minv)
    else:
        heapq.heappush(h, [xy[i][1], xy[i][2]])
color = [-1] * n
c = 0
for i in range(n):
    if color[i] == -1:
        bfs(i, c)
        c += 1
for i in range(n):
    ans = cnt[color[i]]
    print(ans)

# Optimized solution
import heapq
from collections import deque

def bfs(i, c):
    color[i] = c
    cnt[c] += 1
    q = deque()
    q.append(i)
    while q:
        j = q.popleft()
        for k in G[j]:
            if color[k] == -1:
                color[k] = c
                cnt[c] += 1
                q.append(k)
    return

n = int(eval(input()))
xy = [0] * n
for i in range(n):
    x, y = list(map(int, input().split()))
    xy[x - 1] = [x, y, i]
cnt = [0] * n
h = [[n + 1, n + 1]]
G = []
for _ in range(n):
    G.append([])
for i in range(n):
    c = 0
    while h[0][0] < xy[i][1]:
        p = heapq.heappop(h)
        if c == 0:
            minv = p
        c = 1
        G[p[1]].append(xy[i][2])
        G[xy[i][2]].append(p[1])
    #heapq.heappush(h, [xy[i][1], xy[i][2]])
    if c:
        heapq.heappush(h, minv)
    else:
        heapq.heappush(h, [xy[i][1], xy[i][2]])
color = [-1] * n
c = 0
for i in range(n):
    if color[i] == -1:
        bfs(i, c)
        c += 1
for i in range(n):
    ans = cnt[color[i]]
    print(ans)