Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

# coding: utf-8
from sys import setrecursionlimit


def dfs(node: int):
    if node in checked:
        return

    checked.add(node)
    chain.add(node)
    for n in friends[node]-checked:
        dfs(n)


def solve(*args: str) -> str:
    setrecursionlimit(2 * 10 ** 9)
    n, m, k = map(int, args[0].split())
    AB = [tuple(map(int, ab)) for ab in map(str.split, args[1:1+m])]
    CD = [tuple(map(int, cd)) for cd in map(str.split, args[1+m:1+m+k])]

    global checked
    checked = set()

    global friends
    friends = [set() for _ in range(n+1)]
    blocked = [set() for _ in range(n+1)]

    for a, b in AB:
        friends[a].add(b)
        friends[b].add(a)

    for c, d in CD:
        blocked[c].add(d)
        blocked[d].add(c)

    ret = [0]*(n+1)
    for a in range(1, n+1):
        if a in checked:
            continue

        global chain
        chain = set()
        dfs(a)
        for i in chain:
            ret[i] += len(chain-friends[i]-blocked[i]) - 1

    return ' '.join(map(str, ret[1:]))


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


### FIXED CODE ###

# coding: utf-8
from sys import setrecursionlimit


def dfs(node: int):
    if checked[node]:
        return

    checked[node] = True
    chain.add(node)
    for n in friends[node]:
        dfs(n)


def solve(*args: str) -> str:
    setrecursionlimit(2 * 10 ** 9)
    n, m, k = map(int, args[0].split())

    global friends
    friends = {i: set() for i in range(n+1)}
    blocked = {i: set() for i in range(n+1)}

    for a, b in map(str.split, args[1:1+m]):
        friends[int(a)].add(int(b))
        friends[int(b)].add(int(a))

    for c, d in map(str.split, args[1+m:1+m+k]):
        blocked[int(c)].add(int(d))
        blocked[int(d)].add(int(c))

    global checked
    checked = [False]*(n+1)

    ret = [0]*(n+1)
    for a in range(1, n+1):
        if checked[a]:
            continue

        global chain
        chain = set()
        dfs(a)
        count = len(chain) - 1
        for i in chain:
            ret[i] += count - len(chain & (friends[i] | blocked[i]))

    return ' '.join(map(str, ret[1:]))


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))
### BUGGY CODE ###

#入力値処理
n = int(input())
data = [int(s) for s in input().split()]

bindata = []

for value in data:
  tmp = format(value,'b').zfill(60)  
  bindata.append(tmp)

#各桁の1の個数を格納
numlist = [0] * 60

for rowdata in bindata:
  for j in range(60):
    if rowdata[j] == '1':
      numlist[59-j] += 1
ans = 0

#各桁の1の個数と0の個数の積の和を求める
for i in range(60):
  ans += numlist[i] * (n-numlist[i]) * (2 ** i)
ans = ans % (10**9 + 7)
print(ans)






"""
ans = 0

for i in range(n-1):
  for j in range(i,n):
    ans = ans +  int(bin(data[i] ^ data[j]),0)
ans = ans % (10 ** 9 + 7)

print(int(ans))
"""

### FIXED CODE ###

#入力値処理
n = int(input())
data = [int(s) for s in input().split()]

bindata = []

for value in data:
  tmp = format(value,'b').zfill(60)  
  bindata.append(tmp)

#各桁の1の個数を格納
numlist = []
for i in range(60):
  numlist.append([row[i] for row in bindata])
#print(numlist)

binnum = [0] * 60
for i in range(60):
  binnum[59-i] = numlist[i].count('1')
#print(binnum)

"""
for rowdata in bindata:
  for j in range(60):
    if rowdata[j] == '1':
      numlist[59-j] += 1
"""
ans = 0

#各桁の1の個数と0の個数の積の和を求める
for i in range(60):
  ans += binnum[i] * (n-binnum[i]) * (2 ** i)
ans = ans % (10**9 + 7)
print(ans)






"""
ans = 0

for i in range(n-1):
  for j in range(i,n):
    ans = ans +  int(bin(data[i] ^ data[j]),0)
ans = ans % (10 ** 9 + 7)

print(int(ans))
"""
### BUGGY CODE ###

k, s = map(int, input().split())

count = 0
for x in range(0, k+1):
   for y in range(0, k+1):
      for z in range(0, k+1):
         check = x + y + z
         if (check == s):
            count += 1
print(count)


### FIXED CODE ###

k, s = map(int, input().split())

count = 0
for x in range(0, k+1):
   for y in range(0, k+1):
         z = s - (x + y)
         if (z >= 0 and z <= k):
            count += 1
print(count)
### BUGGY CODE ###

input_from = input()
info = input_from.split(' ')
a = int(info[0])
b = int(info[1])
k = int(info[2])
for i in range(k):
    if a > 0:
        a -= 1
    elif b > 0:
        b -= 1
print("{0} {1}".format(a, b))

### FIXED CODE ###

input_from = input()
info = input_from.split(' ')
a = int(info[0])
b = int(info[1])
k = int(info[2])
a -= k
if a < 0:
    b += a
    a = 0
    if b < 0:
        b = 0
print("{0} {1}".format(a, b))
### BUGGY CODE ###

# ABC139
from collections import deque


def main():
    N, *A = map(int, open(0).read().split())
    B = {}
    for i in range(N):
        x = i * (N - 1)
        B[i + 1] = deque(A[x : x + N - 1])
    ans, flg, matched = 0, 0, set()
    while B:
        for i in list(B.keys()):
            if i in B and i not in matched:
                x = B[i][0]
                if x in B and x not in matched and B[x][0] == i:
                    B[i].popleft(), B[x].popleft()
                    matched |= {i, x}
                    flg = 1
                    if not B[i]:
                        del B[i]
                    if not B[x]:
                        del B[x]
        if flg:
            ans += 1
            flg, matched = 0, set()
        else:
            print(-1)
            return
    print(ans)


if __name__ == "__main__":
    main()

### FIXED CODE ###

# ABC139E - League
from collections import deque


def main():
    N, *A = map(int, open(0).read().split())
    B = {}
    for i in range(N):
        x = i * (N - 1)
        B[i + 1] = deque(A[x : x + N - 1])
    ans, cnt, matched = 0, 0, set()
    q = [i for i in range(1, N + 1)]
    while q:
        ans += 1
        next_q = []
        for i in q:
            if i in B and i not in matched:
                x = B[i][0]
                if x in B and x not in matched and B[x][0] == i:
                    B[i].popleft(), B[x].popleft()
                    matched |= {i, x}
                    cnt += 1
                    if not B[i]:
                        del B[i]
                    else:
                        next_q += [i]
                    if not B[x]:
                        del B[x]
                    else:
                        next_q += [x]
        q = next_q
        matched = set()
    flg = cnt == N * (N - 1) // 2
    print(ans if flg else -1)


if __name__ == "__main__":
    main()
### BUGGY CODE ###

from collections import deque

N,M,K=map(int,input().split())

F=[[] for i in range(N)] #友達関係の隣接行列
B=[[] for i in range(N)] #ブロック関係の隣接行列

for i in range(M):
    a,b=map(int,input().split())
    F[a-1].append(b-1)
    F[b-1].append(a-1)

for i in range(K):
    a,b=map(int,input().split())
    B[a-1].append(b-1)
    B[b-1].append(a-1)

q=deque([])
cnt=[0]*N

for i in range(N):
    visited=[0]*N
    visited[i]=1
    for j in F[i]:
        if visited[j]==0:
            visited[j]=1
            q.append(j)
    while q:
        c=q.popleft()
        if c in F[i]: #友達候補が友達だったら友達の友達を候補としてqに加える
            for j in F[c]:
                if visited[j]==0:
                    visited[j]=1
                    q.append(j)
            continue
        if c not in B[i]: #友達候補がブロックされていなければカウントする
            cnt[i]+=1
        for j in F[c]:
            if visited[j] == 0:
                visited[j]=1
                q.append(j)



for i in cnt:
    print(str(i),end=" ")


### FIXED CODE ###

from collections import deque

N,M,K=map(int,input().split())

F=[[] for _ in range(N)]
B=[[] for _ in range(N)]


for i in range(M):
    a,b=map(int,input().split())
    F[a-1].append(b-1)
    F[b-1].append(a-1)

for i in range(K):
    a,b=map(int,input().split())
    B[a-1].append(b-1)
    B[b-1].append(a-1)

q=deque([])
G=[]
visited=[0]*N
group=[-1]*N
idx=0
for i in range(N):
    if visited[i]==1:continue
    visited[i]=1
    group[i]=idx
    q.append([i,[i]])
    while q:
        n,c=q.pop()
        for j in F[n]:
            if visited[j]==0:
                c.append(j)
                visited[j]=1
                group[j]=idx
                q.append([j,c])
    G.append(c)
    idx+=1

cnt=[0]*N
for g in G:
    for i in g:
        for b in B[i]:
            if  group[i]==group[b]:
                cnt[i]+=1

ans=[0]*N

for g in G:
    for i in g:
        ans[i]=len(g)-len(F[i])-cnt[i]-1

for i in ans:
    print(str(i),end=" ")
### BUGGY CODE ###

N = input()
N = int(N)
k = []
x = []
for i in range(0, N):
    a = input()
    k.append(a)
for i in k:
    if i not in x:
        x.append(i)
print (len(x))

### FIXED CODE ###

N = int(input())
k = set()
for _ in range(N):
    k.add(input())
print (len(k))
### BUGGY CODE ###

import queue
N,M=map(int,input().split())
ans=[0] * N
q=queue.Queue()
q.put(1)

import sys
s = sys.stdin.readlines()
G=[[] for _ in range(N)]

for e in s:
  a, b = map(int, e.split())
  G[a-1].append(b)
  G[b-1].append(a)
  
c=0

while 0 in ans[1:N]:
  r=q.get()
  for i in G[r-1]:
    if ans[i-1]==0:
      ans[i-1]=r
      q.put(i)

print("Yes")
for i in range(N-1):
  print(ans[i+1])

### FIXED CODE ###

import queue
N,M=map(int,input().split())
ans=[0] * N
q=queue.Queue()
q.put(1)

import sys
s = sys.stdin.readlines()
G=[[] for _ in range(N)]

for e in s:
  a, b = map(int, e.split())
  G[a-1].append(b)
  G[b-1].append(a)
  
c=0

while c!=N-1:
  r=q.get()
  for i in G[r-1]:
    if ans[i-1]==0 and i!=1:
      ans[i-1]=r
      q.put(i)
      c+=1

print("Yes")
for i in range(N-1):
  print(ans[i+1])
### BUGGY CODE ###

N = int(input())
HP_list = [int(i) for i in input().split()]
while len(set(HP_list))>1:
    for i in range(0, len(set(HP_list))):
        min_HP = min(HP_list)
        if HP_list[i] > min_HP:
            HP_list[i] = HP_list[i]%min_HP
            if HP_list[i]==0:
                HP_list[i] += min_HP
print(list(set(HP_list))[0])

### FIXED CODE ###

import numpy as np
N = int(input())
HPs = np.array([int(i) for i in input().split()])
np.sort(HPs)
while len(HPs) > 1:
    HPs[1:] %= HPs[0]
    HPs[HPs==0] = HPs[0]
    HPs=np.unique(HPs)
print(HPs[0])
### BUGGY CODE ###

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def IS(): return sys.stdin.readline()[:-1]
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 LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N = II()
	A = LI()
	order = [0]*N
	for i,a in enumerate(A):
		order[a-1] = i+1
	ans = ""
	for a in order:
		ans += (str(a)+" ")

	print(ans[:-1])

main()

### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def IS(): return sys.stdin.readline()[:-1]
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 LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N = II()
	A = LI()
	order = [0]*N
	for i,a in enumerate(A):
		order[a-1] = i+1
	order = list(map(str,order))
	print(" ".join(order))

main()
### BUGGY CODE ###

A,B,N=map(int,input().split())
p=(N+1)//B
result=0
if p!=0:
	for a in range(1,p+1):
		x=a*B-1
		s=(A*x)//B - A*(a-1)
		if result < s:
			result=s
else:
	result=A*N//B -A*(N//B)
print(result)

### FIXED CODE ###

A,B,N=map(int,input().split())
if B!=1:
	p=(N+1)//B
	result=0
	if p!=0:
		for a in range(1,p+1):
			x=a*B-1
			s=(A*x)//B - A*(a-1)
			if result < s:
				result=s
	else:
		result=A*N//B -A*(N//B)
	print(result)
else:
	print(0)
### BUGGY CODE ###

K = int(input())
S = list(input())
total = 0

for a in range(0,K-2):
  for b in range(a+1,K-1):
    if S[a] != S[b]:
      for c in range(b+1,K):
        if S[c] != S[b] and S[c] != S[a] and b-a != c-b:
          total += 1
print(total)

### FIXED CODE ###

K = int(input())
S = list(input())
total = 0
R,G,B = 0,0,0

for a in range(0,K):
  if S[a]=="R":
    R += 1
  elif S[a]=="G":
    G += 1
  else :
    B += 1
    
total = R*G*B

for i in range(0,K):
  for j in range(i,K):
    k = 2*j-i
    if k<K:
      if S[i] != S[k] and S[i] != S[j] and S[j] != S[k]:
        total -= 1
print(total)
### BUGGY CODE ###

N=int(input())

if N%2==1:
    print(0)
    exit()

cnt=0

for i in range(1,19):
    cnt+=N//(10**i)

cnt+=N//100

for i in range(250,N+1,500):
    temp=i//10
    while temp:
        if temp%5==0:
            cnt+=1
        else:
            break
        temp=temp//5

print(cnt)

### FIXED CODE ###

N=int(input())

if N%2==1:
    print(0)
    exit()

k=5
ans=0
while k*2<=N:
    ans+=N//(k*2)
    k=k*5

print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
# import numpy as np

MOD = 1000000007  # type: int


def solve(S: str):
    # dp = np.zeros((len(S) + 1, 13))
    dp = [[0 for j in range(13)] for i in range(len(S) + 1)]
    dp[0][0] = 1
    for i in range(len(S)):
        if S[i] == '?':
            for j in range(10):
                for k in range(13):
                    dp[i + 1][(k * 10 + j) % 13] += dp[i][k] % MOD
        else:
            j = int(S[i])
            for k in range(13):
                dp[i + 1][(k * 10 + j) % 13] += dp[i][k] % MOD
    print(int(dp[-1][5]) % MOD)

    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
# import numpy as np

MOD = 1000000007  # type: int


def solve(S: str):
    # dp = np.zeros((len(S) + 1, 13))
    dp = [[0 for j in range(13)] for i in range(len(S) + 1)]
    dp[0][0] = 1
    for i in range(len(S)):
        if S[i] == '?':
            for j in range(10):
                for k in range(13):
                    dp[i + 1][(k * 10 + j) % 13] += dp[i][k] % MOD
        else:
            j = int(S[i])
            for k in range(13):
                dp[i + 1][(k * 10 + j) % 13] += dp[i][k] % MOD
    print(int(dp[-1][5]) % MOD)

    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

from bisect import bisect_left as bl, bisect_right as br
n,q = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

def sub(x, i):
    # i番目を取れるかどうか
    v = a[i]
    target = x - (v-x)
    num = i - bl(a, target-0.1)
    return num+1 >= n - i

anss = [None] * q
for j in range(q):
    x = int(input())
    l = 0
    r = n-1
    while l<r-1:
        m = (r+l)//2
        if sub(x, m):
            r = m
        else:
            l = m
    # rまではxより大きくて取れる
#     print("r",  r)
    ans = sum(a[r:])
    ii = r-2 - (n-r-1)
    while ii>=0:
        ans += a[ii]
        ii -= 2
    anss[j] = ans
write("\n".join(map(str, anss)))

### FIXED CODE ###

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


from bisect import bisect_left as bl, bisect_right as br
n,q = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

def sub(x, i):
    # i番目を取れるかどうか
    v = a[i]
    target = x - (v-x)
    num = i - bl(a, target-0.1)
    return num+1 >= n - i

anss = [None] * q
cumsum1 = [0] * n
cumsum0 = [0] * n
cumsum = [0] * n
for i in range(n):
    if i%2:
        cumsum1[i] = cumsum1[i-1] + a[i]
        cumsum0[i] = cumsum0[i-1]
    else:
        cumsum0[i] = cumsum0[i-1] + a[i]
        cumsum1[i] = cumsum1[i-1]
    cumsum[i] = cumsum[i-1] + a[i]

for j in range(q):
    x = int(input())
    l = 0
    r = n-1
    while l<r-1:
        m = (r+l)//2
        if sub(x, m):
            r = m
        else:
            l = m
    # rまではxより大きくて取れる
#     ans = sum(a[r:])
    ans = cumsum[-1] - cumsum[r-1]
    ii = r-2 - (n-r-1)
    if ii>=0:
        if ii%2:
            ans += cumsum1[ii]
        else:
            ans += cumsum0[ii]
    anss[j] = ans
write("\n".join(map(str, anss)))
### BUGGY CODE ###

import math

n = int(input())
a_array = list(map(int, input().split()))

def get_primenumber(number):#エラトステネスの篩
    prime_list = []
    search_list = list(range(2,number+1))
    #search_listの先頭の値が√nの値を超えたら終了
    while search_list[0] <= math.sqrt(number):
        #search_listの先頭の値が√nの値を超えたら終了
        #search_listの先頭をprime_listに入れて、先頭をリストに追加して削除
        head_num = search_list.pop(0)
        prime_list.append(head_num)
        #head_numの倍数を除去
        for i in range(number // head_num):
            index = head_num * (i + 1)
            if D[index] == index:
                D[index] = head_num
        search_list = [num for num in search_list if num % head_num != 0]
    #prime_listにsearch_listを結合
    prime_list.extend(search_list)
    return prime_list


def factrization_prime(number):
    div = D[number]
    s = math.sqrt(number)
    while div <= s:
        div_cnt = 0
        while number % div == 0:
            div_cnt += 1
            number //= div
        ans_array[div] += 1
        if number == 1:
            break
        div = D[number]
    if number > 1:
        ans_array[number] += 1

# thre = pow(10, 6) + 1
thre = max(a_array) + 1
ans_array = [0] * thre
D = list(range(thre + 1))

prime_list = get_primenumber(thre)
# print(D[:10])
for a in a_array:
    factrization_prime(a)

max_ans_array = max(ans_array)
if max_ans_array == 1:
    print('pairwise coprime')
elif max_ans_array < n:
    print('setwise coprime')
else:
    print('not coprime')

### FIXED CODE ###

import math

n = int(input())
a_array = list(map(int, input().split()))

def get_primenumber(number):#エラトステネスの篩
    prime_list = []
    search_list = list(range(2,number+1))
    #search_listの先頭の値が√nの値を超えたら終了
    while search_list[0] <= math.sqrt(number):
        #search_listの先頭の値が√nの値を超えたら終了
        #search_listの先頭をprime_listに入れて、先頭をリストに追加して削除
        head_num = search_list.pop(0)
        prime_list.append(head_num)
        #head_numの倍数を除去
        for i in range(number // head_num):
            index = head_num * (i + 1)
            if D[index] == index:
                D[index] = head_num
        search_list = [num for num in search_list if num % head_num != 0]
    #prime_listにsearch_listを結合
    prime_list.extend(search_list)
    return prime_list


def factrization_prime(number):
    div = D[number]
    s = math.sqrt(number)
    div_set = set()
    while number > 1:
        number //= div
        div_set.add(div)
        div = D[number]
    if number > 1:
        div_set.add(div)
    for div in div_set:
        ans_array[div] += 1


# thre = pow(10, 6) + 1
thre = max(a_array) + 1
ans_array = [0] * thre
D = list(range(thre + 1))

prime_list = get_primenumber(thre)
# print(D[-10:])
for a in a_array:
    factrization_prime(a)
# print(ans_array)

max_ans_array = max(ans_array)
if max_ans_array <= 1:
    print('pairwise coprime')
elif max_ans_array < n:
    print('setwise coprime')
else:
    print('not coprime')
### BUGGY CODE ###

import sys
input=sys.stdin.readline
a=list(map(int,input().split()))
n,q,b,c=a[0]-1,a[1],[],[]
s=input()
for i in range(q):
    b.append(list(map(int,input().split())))
for i in range(n):
    if s[i]=='A' and s[i+1]=='C':
        c.append(1)
    else:
        c.append(0)
for i in range(q):
    print(sum(c[b[i][0]-1:b[i][1]-1]))


### FIXED CODE ###

def Csum(a):
    b,c=[0],0
    for i in range(len(a)-1):
        c+=(a[i]=='A' and a[i+1]=='C')
        b.append(c)
    return b
n,q=map(int,input().split())
s=Csum(input())
for i in range(q):
    a,b=map(int,input().split())
    print(s[b-1]-s[a-1])
### BUGGY CODE ###

n,k=map(int,input().split())
A=list(map(int,input().split()))
ave=[0 for i in range(n-k+1)]

for i in range(n-k+1):
    temp=1
    for s in range(i,i+k):
        temp*=A[s]
    ave[i]=temp

for i in range(n-k):
    if ave[i+1]>ave[i]:
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

n,k=map(int,input().split())
A=list(map(int,input().split()))
ave=[0 for i in range(n-k+1)]


for i in range(n-k):
    if A[i+k]>A[i]:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

# M日後に最大の値
N, M = map(int, input().split())
# [0] -> 日数, [1] -> お金
Data = [list(map(int, input().split())) for _ in range(N)]

ans = 0
for i in range(1, M+1):
    temp = 0
    index = -1
    for j in range(len(Data)):
        if (Data[j][0] <= i) and (temp < Data[j][1]):
            temp = Data[j][1]
            index = j
    if index != -1:
        ans += temp
        Data[index][1] = -1
print(ans)


### FIXED CODE ###

from heapq import heappush, heappop
N, M = map(int, input().split())

Data = [list(map(int, input().split())) for _ in range(N)]
Data.sort(reverse = True)

heap = [0] * M
ans = 0
for i in range(1, M+1):
    N = len(Data)
    for j in range(N-1, -1, -1):
        if Data[j][0] > i:
            break
        if (Data[j][0] <= i):
            heappush(heap, -(Data.pop(j)[1]))

    ans += -(heappop(heap))

print(ans)