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


import sys
from operator import attrgetter

def main():
    N,M = [int(i) for i in sys.stdin.readline().strip().split()]
    works = [[] for i in range(10**5+1)]
    ans = 0
    for i in range(N):
        A,B = [int(i) for i in sys.stdin.readline().strip().split()]
        works[A].append(B)
    
    avaiable_works = []
    for i in range(M+1):
        avaiable_works.extend(works[i])
        if len(avaiable_works) > 0:
            revenue = max(avaiable_works)
        else:
            continue
        ans += revenue
        avaiable_works.remove(revenue)
    
    print("%d" % ans)



def solve(N, M, works):
    ans = 0

    return 0



if __name__ == "__main__":
    main()

### FIXED CODE ###


import sys
from operator import attrgetter
import heapq

def main():
    N,M = [int(i) for i in sys.stdin.readline().strip().split()]
    works = [[] for i in range(10**5+1)]
    ans = 0
    for i in range(N):
        A,B = [int(i) for i in sys.stdin.readline().strip().split()]
        heapq.heappush(works[A], -B)
    
    avaiable_works = []
    for i in range(1, M+1):
        for item in works[i]:
            heapq.heappush(avaiable_works, item)
        if len(avaiable_works) > 0:
            revenue = abs(heapq.heappop(avaiable_works))
        else:
            continue
        ans += revenue
    
    print("%d" % ans)

def solve(N, M, works):
    ans = 0

    return 0

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

s=input()
t=input()
n=len(s)
m=len(t)
dp=[["" for _ in range(n+1)] for _ in range(m+1)]
for i in range(m):
    for j in range(n):
        if t[i] == s[j]:
            dp[i+1][j+1] = dp[i][j] + t[i]
        else:
            if len(dp[i+1][j]) >= len(dp[i][j+1]):
                dp[i+1][j+1] = dp[i+1][j]
            else:
                dp[i+1][j+1] = dp[i][j+1]
print(dp[-1][-1])

### FIXED CODE ###


s=input()
t=input()
n=len(s)
m=len(t)
dp=[[0 for _ in range(n+1)] for _ in range(m+1)]
for i in range(m):
    for j in range(n):
        if t[i] == s[j]:
            dp[i+1][j+1] = dp[i][j] + 1
        else:
            dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1])
r=m
c=n
ans=[]
while r !=0 and c!=0:
    #print(r,c,dp[r][c],dp[r-1][c])
    if dp[r][c] != dp[r-1][c]:
        if dp[r][c] != dp[r][c-1]:
            ans.append(s[c-1])
            r-=1
            c-=1
        else:
            c-=1
    else:
        r-=1
print("".join(ans[::-1]))
### BUGGY CODE ###

N, M, K = map(int, input().split())
friend = [[] for _ in range(N+1)]
block = [[] for _ in range(N+1)]

for i in range(M):
  A,B = map(int, input().split())
  friend[A].append(B)
  friend[B].append(A)

for i in range(K):
  C,D = map(int, input().split())
  block[C].append(D)
  block[D].append(C)
#print(friend)
#print(block)

import queue
grouping = [False]*(N+1)
#print(grouping)
grouping[0] = True
groups = []
while False in grouping:
  for i in range(1,N):
    if grouping[i] == False:
      p = i
      break
  #print(p)
  visited = [False]*(N+1)
  group = [p]
  visited[p],grouping[p] =True,True
  q = queue.Queue()
  q.put(p)
  while not q.empty():
    #print('v:',visited)
    p = q.get()
    for f in friend[p]:
      #print(p,f)
      if visited[f]==False:
        q.put(f)
        group.append(f)
        visited[f],grouping[f] =True,True
  groups.append(group)
  #print('g:',grouping)
counts=[0]*(N+1)
for group in groups:
  for g in group:
    for h in group:
      if h not in block[g] and h!=g and h not in friend[g]:
        counts[g] += 1
print(' '.join(map(str,counts[1:])))
  

### FIXED CODE ###

N, M, K = map(int, input().split())
friend = [[] for _ in range(N+1)]
block = [[] for _ in range(N+1)]

for i in range(M):
  A,B = map(int, input().split())
  friend[A].append(B)
  friend[B].append(A)

for i in range(K):
  C,D = map(int, input().split())
  block[C].append(D)
  block[D].append(C)
#print(friend)
#print(block)

#import queue
grouping = [False]*(N+1)
#print(grouping)
grouping[0] = True
group = [0]*(N+1)
g_num = 0
g_cnt = []
for i in range(1,N+1):
  cnt = 0
  if grouping[i] == True:
    continue 
  group[i] = g_num
  grouping[i] = True
  #q = queue.Queue()
  #q.put(i)
  stack = [i]
  #while not q.empty():
  while len(stack)>0:
    #print('v:',visited)
    #p = q.get()
    p = stack.pop()
    for f in friend[p]:
      #print(p,f)
      if grouping[f]==False:
        #q.put(f)
        stack.append(f)
        group[f]=g_num
        grouping[f] =True
        cnt += 1
  g_num += 1
  g_cnt.append(cnt)
  #print('g:',grouping)
ans = []
for i in range(1,N+1):
  c = g_cnt[group[i]]-len(friend[i])
  for b in block[i]:
    if group[b]==group[i]:
      c -= 1
  ans.append(c)
print(*ans)
### BUGGY CODE ###

import collections
n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
dic = collections.Counter(a)
#for i in a:
#    if i in dic:
#        dic[i] += 1
#    else:
#        dic[i] = 1
dic = sorted(dic.items(), key=lambda x: x[1])
while len(dic) > k:
    ans += dic[0][1]    
    del dic[0]
print(ans)

### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
dic = {}
for i in a:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1
dic = sorted(dic.items(), key=lambda x: x[1])
#while len(dic) > k:
#    ans += dic[0][1]    
#    del dic[0]
for i in range(len(dic)-k):
    ans += dic[i][1]
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
#ABC147 E

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

h,w = LI()
a = [LI() for _ in range(h)]
b = [LI() for _ in range(h)]

dp = [[defaultdict(int) for _ in range(w)] for _ in range(h)]
lst = [[0]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        lst[i][j] = abs(a[i][j] - b[i][j])

dp[0][0][lst[0][0]] = 1
for i in range(h):
    for j in range(w):
        for k,_ in dp[i][j].items():
            if i+1 < h:
                dp[i+1][j][k+lst[i+1][j]] = 1
                dp[i+1][j][abs(k-lst[i+1][j])] = 1
            if j+1 < w:
                dp[i][j+1][k+lst[i][j+1]] = 1
                dp[i][j+1][abs(k-lst[i][j+1])] = 1
ans = inf
for i,_ in dp[-1][-1].items():
    ans = min(ans,i)
print(ans)


### FIXED CODE ###

#!/usr/bin/env python3
#ABC147 E

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

h,w = LI()
a = [LI() for _ in range(h)]
b = [LI() for _ in range(h)]

dp = [[0 for _ in range(w)] for _ in range(h)]
lst = [[0]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        lst[i][j] = abs(a[i][j] - b[i][j])

dp[0][0] |= 1 << (6400+lst[0][0])
dp[0][0] |= 1 << (6400-lst[0][0])
for i in range(h):
    for j in range(w):
        t = dp[i][j]
        if i+1 < h:
            dp[i+1][j] |= t << lst[i+1][j]
            dp[i+1][j] |= t >> lst[i+1][j]
        if j+1 < w:
            dp[i][j+1] |= t << lst[i][j+1]
            dp[i][j+1] |= t >> lst[i][j+1]

x = dp[-1][-1]
for i in range(6401)[::-1]:
    if (x >> i) & 1:
        print(6400 - i)
        break
### BUGGY CODE ###

def sub(x):
	global A;	global F;	global K
	s = 0
	for i in range(N):
		s += max(A[i] - x // F[i], 0)
	return s <= K

N, K = map(int,input().split())
A = list(map(int,input().split())); A.sort()
F = list(map(int,input().split())); F.sort(); F.reverse()
# print(A); print(F)

l = -1; r = max(A) * max(F)
while r - l > 1:
	m = (l + r) // 2
	if sub(m):
		r = m
	else:
		l = m

print(r)

### FIXED CODE ###

def p(F,A,s): # スコアをsにするために最小限必要な修行の回数
    res=0
    for i in range(N):
        res+=max(A[i]-s//F[i],0)
    return res

N,K=map(int,input().split())
A=list(map(int,input().split()))
F=list(map(int,input().split()))

F.sort(reverse=True) # 降順で固定
A.sort() # 昇順で固定

l=0
r=max([F[i]*A[i] for i in range(N)])

while r-l>1:
    m=(l+r)//2
    if p(F,A,m)<=K:
        r=m
    else:
        l=m

if r>1 or p(F,A,0)>K:
    ans=r
else:
    ans=0

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

n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
for i in a:
    ans[i - 1] = a.index(i) + 1
for i in ans:
    print(i,end=" ")


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
count = 1
for i in a:
    ans[i - 1] = count
    count+=1
for i in ans:
    print(i,end=" ")
### BUGGY CODE ###

import collections as c

S = input()
N = len(S)
MOD = 2019
dp = [0] * (len(S))
for i in range(N):
    dp[i] = int(S[-(i+1):]) % 2019

D = c.Counter(dp)
ans = 0
for k,v in zip(D.keys(),D.values()):
    if k == 0:
        ans += v
        ans += v * (v - 1) //2
    elif v >= 2:
        ans += v * (v - 1) // 2

print(ans)

### FIXED CODE ###

from collections import defaultdict

S = input()
S = S[::-1]
N = len(S)
MOD = 2019
D = defaultdict(int)
res = 0
p = 1
for i in range(N):
    tmp = res + int(S[i]) * p
    tmp %= MOD
    D[tmp] += 1

    res = tmp
    p *= 10
    p %= 2019 

ans = 0
for k,v in zip(D.keys(), D.values()):
    if k == 0:
        ans += v
        ans += v * (v - 1) //2
    elif v >= 2:
        ans += v * (v - 1) // 2

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

# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N,Q=map(int,input().split())
a=list(map(int1,input().split()))
lr=[]
for i in range(Q):
    l,r=map(int1,input().split())
    lr.append((l,r,i))
lr.sort(key=lambda t: t[1],reverse=1)
class RangeBIT:
    def __init__(self,n):
        self.p=self.BIT(n+1)
        self.q=self.BIT(n+1)
    
    def add(self,s,t,x):
        self.p.add(s,-x*s)
        self.p.add(t,x*t)
        self.q.add(s,x)
        self.q.add(t,-x)
    
    def sum(self,s,t):
        return self.p.sum(t)+self.q.sum(t)*t-self.p.sum(s)-self.q.sum(s)*s
    
    class BIT:
        def __init__(self,n):
            self.num=n
            self.dat=[0]*(self.num+1)
        
        def add(self,i,x):
            i+=1
            while i<=self.num:
                self.dat[i]+=x
                i+=i&-i
        
        def sum(self,i):
            i+=1
            s=0
            while i>0:
                s+=self.dat[i]
                i-=i&-i
            return s
    
b=RangeBIT(N)
lastap=[-1]*N
ans=[-1]*Q
for i in range(N):
    if lastap[a[i]]!=-1:
        b.add(lastap[a[i]],lastap[a[i]]+1,-1)
    b.add(i,i+1,1)
    lastap[a[i]]=i
    while lr and lr[-1][1]==i:
        l,r,j=lr.pop()
        ans[j]=b.sum(l,r+1)
for x in ans:
    print(x)

### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N,Q=map(int,input().split())
a=tuple(map(int1,input().split()))
lr=[[0,0,i] for i in range(Q)]
for i in range(Q):
    lr[i][0],lr[i][1]=map(int1,input().split())
lr.sort(key=lambda t: t[1],reverse=1)
class RangeBIT:
    def __init__(self,n):
        self.p=self.BIT(n+1)
        self.q=self.BIT(n+1)
    
    def add(self,s,t,x):
        self.p.add(s,-x*s)
        self.p.add(t,x*t)
        self.q.add(s,x)
        self.q.add(t,-x)
    
    def sum(self,s,t):
        return self.p.sum(t)+self.q.sum(t)*t-self.p.sum(s)-self.q.sum(s)*s
    
    class BIT:
        def __init__(self,n):
            self.num=n
            self.dat=[0]*(self.num+1)
        
        def add(self,i,x):
            i+=1
            while i<=self.num:
                self.dat[i]+=x
                i+=i&-i
        
        def sum(self,i):
            i+=1
            s=0
            while i>0:
                s+=self.dat[i]
                i-=i&-i
            return s

b=RangeBIT(N)
lastap=[-1]*N
ans=[-1]*Q
l,r,j=lr.pop()
for i,x in enumerate(a):
    if lastap[x]!=-1:
        b.add(lastap[x],lastap[x]+1,-1)
    b.add(i,i+1,1)
    lastap[x]=i
    while r==i:
        ans[j]=b.sum(l,r+1)
        if lr:
            l,r,j=lr.pop()
        else:
            l,r,j=-1,-1,-1
for x in ans:
    print(x)
### BUGGY CODE ###

n=int(input())
s=[sorted(input()) for i in range(n)]
s.sort()
cnt=0
while len(s)>1:
  k=s.count(s[0])
  if k==1:
    continue
  else:
    cnt+=int(k*(k-1)/2)
  del s[:k]
print(cnt)

### FIXED CODE ###

n=int(input())
A={}
for i in range(n):
  s=str(sorted(input()))
  if s in A.keys():
    A[s]+=1
  else:
    A[s]=1
ans=0
for i in list(A.values()):
  ans+=int(i*(i-1)/2)
print(ans)
### BUGGY CODE ###

INF = 10 ** 12
BLACK = '#'
WHITE = '.'
H, W = [int(i) for i in input().split()]
M = [None] * H
D = [[INF] * W for _ in range(H)]

for i in range(H):
    inputs = input()
    for idx, j in enumerate(inputs):
        if j == '#':
            D[i][idx] = 0


def forward_update(i, j):
    up = INF
    if i > 0:
        up = D[i-1][j]
    left = INF
    if j > 0:
        left = D[i][j-1]

    D[i][j] = min(D[i][j], up + 1, left + 1)


def backward_update(i, j):
    down = INF
    if i < H-1:
        down = D[i+1][j]
    right = INF
    if j < W-1:
        right = D[i][j+1]
    D[i][j] = min(D[i][j], down + 1, right + 1)


_ = [forward_update(i, j) for i in range(H) for j in range(W)]
_ = [backward_update(i, j) for i in range(H-1, -1, -1) for j in range(W-1, -1, -1)]

max_value = 0
for i in range(H):
    for j in range(W):
        if D[i][j] > max_value:
            max_value = D[i][j]
print(max_value)


### FIXED CODE ###

INF = 10 ** 11
BLACK = '#'
H, W = [int(i) for i in input().split()]
M = [None] * H
D = [[INF] * W for _ in range(H)]

for i in range(H):
    inputs = input()
    for idx, j in enumerate(inputs):
        if j == BLACK:
            D[i][idx] = 0


def forward_update(i, j):
    up = INF
    if i > 0:
        up = D[i-1][j]
    left = INF
    if j > 0:
        left = D[i][j-1]

    D[i][j] = min(D[i][j], up + 1, left + 1)


def backward_update(i, j):
    down = INF
    if i < H-1:
        down = D[i+1][j]
    right = INF
    if j < W-1:
        right = D[i][j+1]
    D[i][j] = min(D[i][j], down + 1, right + 1)


_ = [forward_update(i, j) for i in range(H) for j in range(W)]
_ = [backward_update(i, j) for i in range(H-1, -1, -1) for j in range(W-1, -1, -1)]

max_value = max([max(x) for x in D])
print(max_value)
### BUGGY CODE ###

N = int(input())
A = [int(input()) for i in range(N)]

for i in range(0,N):
    ans = 0
    for j in range(0,N):
        if i != j and  A[j] > ans :
            ans = A[j]
    print(ans)

### FIXED CODE ###

N = int(input())
A = [int(input()) for i in range(N)]
ans = [0]*N
count = 0
ans_tmp2 = 0
ans_tmp = 0

for i in range(0,N):
    if ans_tmp < A[i]:
        ans_tmp = A[i]

for i in range(0,N):
    if ans_tmp == A[i]:
        count += 1
    if ans_tmp2 < A[i] and ans_tmp > A[i]:
        ans_tmp2 = A[i]

if count > 1:
    for j in range(0,N):
        ans[j] = ans_tmp

else:
    for j in range(0,N):
        if A[j] != ans_tmp:
            ans[j] = ans_tmp
        else:
            ans[j] = ans_tmp2

for i in range(0,N):
    print(ans[i])
### BUGGY CODE ###

N,M = map(int,input().split())
AB = list(list(map(int,input().split()))for i in range(N))
AB.append([0,0])
AB.sort()
p = 0
ans = 0
for i in range(M+1):
    while p<=N and (AB[p][0] <= i) :
        p += 1
    m = AB.index(max(AB[:p],key = lambda x:x[1]))
    ans += AB[m][1]
    AB[m] = [0,0]
print(ans)

### FIXED CODE ###

import heapq
N,M = map(int,input().split())
AB = list(list(map(int,input().split()))for i in range(N))
AB.sort()
can = []
p = 0
ans = 0
for i in range(M+1):
    while p<N and (AB[p][0] <= i) :
        heapq.heappush(can,-AB[p][1])
        p += 1
        
    if can != []:
        ans += heapq.heappop(can)
print(-ans)
### BUGGY CODE ###

import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, W = map(int, input().split())
    dp = [[0] * (W + 1) for _ in range(N + 1)]
    item = [(0, 0)]
    for _ in range(N):
        w, v = map(int, input().split())
        item.append((w, v))

    for i in range(1, N + 1):
        for w in range(W + 1):
            if w - item[i][0] >= 0:
                tmp = dp[i - 1][w - item[i][0]] + item[i][1]
                if tmp > dp[i][w]:
                    dp[i][w] = max(dp[i - 1][w], tmp)
            else:
                dp[i][w] = dp[i - 1][w]

    print(max(dp[-1]))


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys


def main():
    input = sys.stdin.readline

    N, W = map(int, input().split())
    dp = [0] * (W + 1)

    WV = (map(int, input().split()) for _ in range(N))

    for w, v in WV:
        for j in range(W, w - 1, -1):
            tmp = dp[j - w] + v
            if tmp > dp[j]:
                dp[j] = tmp

    print(dp[-1])


main()
### BUGGY CODE ###

N=int(input())
S=[]
cnt = 0
for i in range(N):
    si= input()
    if si not in S:
        cnt += 1
        S.append(si)
print(cnt)


### FIXED CODE ###

N=int(input())
cnt = 0
S=[]
for i in range(N):
    si= input()
    S.append(si)

print(len(list(set(S))))
### BUGGY CODE ###

import sys
import math
import itertools
import bisect
from copy import copy,deepcopy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N = i()
A = l()
ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        ans = (ans+A[i]*A[j])%mod
print(ans)

### FIXED CODE ###

import sys
import math
import itertools
import bisect
from copy import copy,deepcopy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N = i()
A = l()
ans = 0
num = sum(A)
for i in range(N-1):
     num -= A[i]
     ans = (ans+A[i]*num)%mod
print(ans)
### BUGGY CODE ###

n = int(input())
s = [[]]*n
ans = 0

for i in range(n):
    s[i] = list(sorted(input()))

i = 0
j = 1

while i < n-1:
    if i+j < n:
        if s[i] == s[i+j]:
            ans += 1

        if j == n-1-i:
            j = 1
            i += 1
        else:
            j += 1
            
    else:
        break
            

print(ans)


### FIXED CODE ###

n = int(input())
a = {}
ans = 0

for i in range(n):
    s = sorted(input())
    s = ''.join(s)
    if s in a.keys():
        ans += int(a[s])
        a[s] += 1
    else:
        a[s] = 1

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

from collections import deque

n = int(input())
nodes = [[] for _ in range(n)]
edges = []
colors = [0] * (n - 1)
for _ in range(n - 1):
	a, b = map(int, input().split())
	nodes[a - 1].append(b - 1)
	nodes[b - 1].append(a - 1)
	edges.append((a - 1, b - 1))

used = [False] * n
que = deque()
que.append(0)
while len(que) > 0:
	ni = que.pop()
	if used[ni]:
		continue
	color = 1
	used_colors = []
	unused = []
	for e in nodes[ni]:
		[a, b] = sorted([e, ni])
		used_colors.append(colors[edges.index((a, b))])
	unused = [c for c in range(1, n + 1) if not c in used_colors]
	for node in nodes[ni]:
		[a, b] = sorted([ni, node])
		# print(a, b)
		ci = edges.index((a, b))
		if colors[ci] == 0:
			# print(ni, unused)
			color = min(unused)
			colors[ci] = color
			unused = unused[1:]
		que.append(node)

	used[ni] = True

print(max(colors))
print(*colors, sep='\n')

### FIXED CODE ###

from collections import deque

n = int(input())
nodes = [[] for _ in range(n)]
node_list = []
for _ in range(n - 1):
	a, b = map(int, input().split())
	nodes[a - 1].append(b - 1)
	node_list.append(b - 1)
 
que = deque([0])
ans = [0] * n
while len(que) > 0:
	ni = que.pop()
	color = 1
	for node in nodes[ni]:
		if color == ans[ni]:
			color += 1
		ans[node] = color
		color += 1
		que.append(node)
 
print(max(ans))
for node in node_list:
	print(ans[node])
### BUGGY CODE ###

c=0
for i in range(100000000000):
    c+=1

### FIXED CODE ###

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

cnt=0
f=0
for i in l:
    f += i-1
print(f)
### BUGGY CODE ###

N = int(input())
num = list(map(int, input().split()))
count = 0
for i in range(N):
  n = int(num[i])
  if n == min(num[:i+1]):
    count += 1
print(count)    


### FIXED CODE ###

N = int(input())
num = list(map(int, input().split()))
count = 0
min_num = num[0]
for i in range(N):
  n = num[i]
  if n <= min_num:
    count += 1
    min_num = n
    
print(count)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
import operator


def solve(N: int, M: int, a: "List[int]", b: "List[int]"):

    AB = list(zip(a,b))
    AB.sort(key=operator.itemgetter(1))

    db = []
    for a,b in AB:
        bAppend = True
        for i in range(a,b):
            if i in db:
                bAppend = False
                break
        if bAppend:
            db.append(b-1)

    print(len(db))


    return


# Generated by 1.1.4 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()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int()] * (M)  # type: "List[int]" 
    b = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, M, a, b)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
import operator


def solve(N: int, M: int, a: "List[int]", b: "List[int]"):

    AB = list(zip(a,b))
    AB.sort(key=operator.itemgetter(1))

    db = []
    for a,b in AB:
        bAppend = True
        for di in db:
            if a <= di < b:
                bAppend = False
                break
        if bAppend:
            db.append(b-1)

    print(len(db))


    return


# Generated by 1.1.4 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()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int()] * (M)  # type: "List[int]" 
    b = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, M, a, b)

if __name__ == '__main__':
    main()