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

N = int(input())
arr = list(map(int, input().split()))
min_delta = sum(arr)
for i in range(1, N):
    min_delta = min(abs(sum(arr[:i]) - sum(arr[i:])), min_delta)

print(min_delta)


### FIXED CODE ###

N = int(input())
arr = list(map(int, input().split()))
first = 0
second = sum(arr)
min_delta = second - first
for i in range(N):
    first += arr[i]
    second -= arr[i]
    min_delta = min(abs(second - first), min_delta)

print(min_delta)
### BUGGY CODE ###

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

result = 1
for number in A:
  result = result * number
  
if result > 10**18:
  print(-1)  
  
else:
  print(result)
  

### FIXED CODE ###

tukawan = int(input())
A = list(map(int, input().split())) 
result = 1

if 0 in A:
    print(0)

else:
  for number in A:
    result = result * number
    
    if result > 1000000000000000000:
      result = -1
      break
    
  print(result)
### BUGGY CODE ###

n,k=map(int,input().split())
dp=[0 for i in range(n)]
num=set()
dp[0]=1
for i in range(k):
    l,r=map(int,input().split())
    for j in range(l,r+1):
        num.add(j)
for i in range(n):
    for j in num:
        if i+j<=n-1:
            dp[i+j]+=dp[i]
print(dp[n-1]%998244353)

### FIXED CODE ###

n,k=map(int,input().split())
dp=[0 for i in range(n+1)]
acc=[0 for i in range(n+1)]
dp[1]=1
mod=998244353
acc[1]=1
l,r=[],[]
for i in range(k):
    a,b=map(int,input().split())
    l.append(a)
    r.append(b)
for i in range(2,n+1):
    for j in range(k):
        if i-l[j]<0:
            continue
        dp[i]+=(acc[i-l[j]]-acc[max(0,i-r[j]-1)])
        dp[i]%=mod
    acc[i]=(acc[i-1]+dp[i])%mod
print(dp[-1])
### BUGGY CODE ###

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

ans = 0
for i, a in enumerate(A):
    for j in range(i + 1, N):
        if j - i == a + A[j]:
            ans += 1
            
print(ans)


### FIXED CODE ###

N = int(input())
A = list((i, j) for i, j in enumerate(map(int, input().split())))
dictL = {}
dictR = {}

ans = 0
for i in range(N):
    l, r = A[i][1] + A[i][0], A[i][0] - A[i][1]
    if l not in dictL:
        dictL[l] = 1
    else:
        dictL[l] += 1
    if r not in dictR:
        dictR[r] = 1
    else:
        dictR[r] += 1

for i in dictL.keys():
    if i in dictR.keys():
        ans += dictL[i] * dictR[i]
        
print(ans)
### BUGGY CODE ###

n, m = map(int, input().split())
city = [[0] for _ in range(n)]
buffer = []

for i in range(m):
    p, y = map(int, input().split())
    buffer.append(list([p, y]))
    city[p - 1].append(y)

for i in range(n):
    city[i].sort()

for i in range(m):
    p, y = buffer[i]
    print(str(p).zfill(6) + str(city[p - 1].index(y)).zfill(6))


### FIXED CODE ###

import sys
input = sys.stdin.readline

n, m = map(int, input().split())
l = []
num = [0] * n
ans = [""] * m

for i in range(m):
    p, y = map(int, input().split())
    l.append(list([p, y, i]))

l.sort()


for p, y, i in l:
    num[p - 1] += 1
    ans[i] = str(p).zfill(6) + str(num[p - 1]).zfill(6)

for a in ans:
    print(a)
### BUGGY CODE ###

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

N = int(input())
facts = prime_factorize(N)
ans = float('inf')
for i in range(2**len(facts)):
  x1 = 1
  for idx1, flag in enumerate(bin(i)[2:]):
    if flag == '0':
      x1 *= facts[idx1]
  ans = min(ans, x1+N//x1-2)
print(ans)

### FIXED CODE ###

def make_divisors(n):
    ans = float('inf')
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            ans = min(ans, i+N//i-2)
            if i != n // i:
                ans = min(ans, n//i+N//(n//i)-2)

    return ans

N = int(input())
print(make_divisors(N))
### BUGGY CODE ###

a,b = (int(x) for x in input().split())
saidai = 1
c = []
def yakusuu(x,y):
    return(y,x % y)

def cont(z):
    n = 0
    while True:
        if n - int(z ** (1/2)) + 1 == 0:
            c.append(z)
            break
                
        for j in range(2,int(z ** (1/2)) + 1):
            if z % j == 0:
                z = z // j
                c.append(j)
                n = 0
                break
        else:
            n = n + 1

if a > b:
   while True:
      if a % b == 0:
         saidai = b
         break
      a,b = yakusuu(a,b)

else:
   while True:
     if b % a == 0:
       saidai = a
       break
     b,a = yakusuu(b,a)


cont(saidai)
if max(c) == 1:
   print(1)
   exit()
print(len(set(c)) + 1)

### FIXED CODE ###

import math
a,b = (int(x) for x in input().split())
saidai = 1

def yakusuu(x,y):
    return(y,x % y)

def cont(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr

saidai = math.gcd(a,b)


d = cont(saidai)
if d[0] == [1,1]:
    print(1)
    exit()
print(len(d) + 1)
### BUGGY CODE ###

import re

N,Q = map(int, input().split())
S = input()

# ゴリ押し実装
sj = '92'.join(S.split('AC'))
sj = re.sub('[A-Z]', '0', sj)
sj = [-1 if s == '9' else int(s) for s in list(sj)]

for i in range(Q):
  l, r = map(int, input().split())
  ret = sj[(l-1):r]
  if ret[0] == 2:
    ret[0] = 0
  if ret[-1] == -1:
    ret[-1] = 0
  print(sum(ret))


### FIXED CODE ###

N,Q = map(int, input().split())
S = input()

lu = [0]*N
cnt = 0

for i in range(1, N):
  if S[(i-1):(i+1)] == 'AC':
    cnt += 1
  lu[i] = cnt

for i in range(Q):
  l, r = map(int, input().split())
  print(lu[r-1] - lu[l-1])
### BUGGY CODE ###

n=input()
list1=list(map(int,input().split()))
if 0 in list1:
    print(0)
else:
    ans=1
    for i in list1:
        ans*=i
    print(ans) if ans<=1e18 else print(-1)

### FIXED CODE ###

n=input()
list1=list(map(int,input().split()))
if 0 in list1:
    print(0)
else:
    ans=1
    for i in list1:
        ans*=i
        if ans>1e18:
            ans=-1
            break
    print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
for i in range(n):
    print(a.count(i+1))

### FIXED CODE ###

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

import sys
sys.setrecursionlimit(10**7)

def xor(x):
  if x == 0:
    return 0
  if x == 1:
    return 1
  if x == 2:
    return 3
  if x == 3:
    return 0
  t = 2 ** (len(bin(x))-3)
  if x==t:
    return t
  return t*((x-t)%2^1) + xor(x-t)
a, b = map(int, input().split())
print(xor(b) ^ xor(a-1))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)

def xor(x):
  if x <= 0:
    return 0
  if x == 1:
    return 1
  if x == 2:
    return 3
  if x == 3:
    return 0
  t = 2 ** (len(bin(x))-3)
  if x==t:
    return t
  return t*((x-t)%2^1) + xor(x-t)
a, b = map(int, input().split())
print(xor(b) ^ xor(a-1))
### BUGGY CODE ###

import numpy as np
a,b = map(int,input().split())
def cf(x1,x2):
    cf = []
    for i in range(1,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf

def prime(num):
  for p in range(2, int(np.sqrt(num)+1)):
    if num % p == 0:
      return False
  return True

lis = cf(a,b)
for k,l in enumerate(lis):
  if prime(l) == False:
    lis[k] = -1
s = set(lis) - set([-1])
print(len(s))

### FIXED CODE ###

import numpy as np


a,b = map(int,input().split())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

lisa = prime_factorize(a)
lisb = prime_factorize(b)
lis = set(lisa) & set(lisb)
lis.add(1)
lis = sorted(list(lis))
devil = (max(a,b)/lis[-1])
if len(prime_factorize(devil)) == 1:
  if min(a,b) % devil == 0:
    lis.append(devil)
print(len(set(lis)))
### BUGGY CODE ###

def binary_search(l, item):

    if len(l) == 0 or l[0] <= item:
        return -1

    if item < l[-1]:
        return len(l) - 1

    list2 = [1001] + l + [0]

    low = 0
    high = len(list2) - 1

    while low <= high:
        mid = (low + high) // 2

        bigger = list2[mid]
        smaller = list2[mid+1]

        if smaller <= item and item < bigger:

            return mid - 1

        if smaller > item:
            low = mid + 1

        else:
            high = mid - 1

    return -1


import heapq


N = int(input())
L = []
for l in map(int, input().split(' ')):
    heapq.heappush(L, l*(-1))

L = [heapq.heappop(L)*(-1) for _ in range(N)]
# L = sorted(L, reverse=True)


result = 0
for i, a in enumerate(L):
    for j, b in enumerate(L[i+1::]):
        k = binary_search(L[i+j+2::], a-b)
        if k == -1:
            break
        result += k + 1


print(result)


### FIXED CODE ###

from bisect import bisect_left

N = int(input())
L = list(map(lambda l: int(l)*(-1), input().split()))
L.sort()

result = 0
for i, a in enumerate(L[:-2:]):
    for ii, b in enumerate(L[i+1:-1:]):
        c_list = L[i+ii+2::]
        c_index = bisect_left(c_list, a-b)
        result += c_index

print(result)
### BUGGY CODE ###

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

cnt=0
while s>0 and c>1:
    s-=1
    c-=2
    cnt+=1

if c<2:
    print(cnt)
    
else:
    while c>3:
        c-=4
        cnt+=1
    print(cnt)
        

### FIXED CODE ###

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

cnt=0
p=min(s,c//2)
s-=p
c-=2*p
cnt+=p
q=0
if c<2:
    print(cnt)

else:
    q=c//4
    cnt+=q
    print(cnt)
### BUGGY CODE ###

N = int(input())
X = list(map(int,input().split()))
mid = []
for i in range(N):
  s = X[:i]+X[i+1:]
  s.sort()
  mid.append(s[(N-1)//2])
for m in mid:
  print(m)

### FIXED CODE ###

N = int(input())
X = list(map(int,input().split()))
sort_X = sorted(X)
l, r = sort_X[N//2-1], sort_X[N//2]
for x in X:
  if(x <= l):
    print(r)
  else:
    print(l)
### BUGGY CODE ###

N, M = list(map(int, input().split()))
tmp=0

for i in range(M-N):
  k = i + N
  if M % k == 0:
    print(int(M/k))
    tmp=1
    break

if tmp==0:
  print(1)

### FIXED CODE ###

N, M = list(map(int, input().split()))
tmp=0

if N==1:
  print(M)
  tmp=1
else:
  for i in range(int(M**0.8)+1):
    k = i + N
    if M % k == 0:
      print(int(M/k))
      tmp=1
      break

if tmp==0:
  print(1)
### BUGGY CODE ###

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

### FIXED CODE ###

import collections

N = int(input())
h = list(input() for x in range(N))
c = collections.Counter(h)
print(len(c))
### BUGGY CODE ###

from fractions import gcd
n = int(input())
a = [int(i) for i in input().split()]

mx = 0
for i in range(n):
    l = 0
    r = 0
    for j in range(i): l = gcd(l, a[j])
    for j in range(i+1, n): r = gcd(r, a[j])
    mx = max(mx, gcd(l, r))

print(mx)


### FIXED CODE ###

from fractions import gcd
n = int(input())
a = [int(i) for i in input().split()]

b = [0] * n
c = [0] * n

j = 0
for i, k in enumerate(a):
    b[i] = j
    j = gcd(j, k)

j = 0
for i, k in reversed(list(enumerate(a))):
    c[i] = j
    j = gcd(j, k)

ma = 0
for i in range(n):
    ma = max(ma, gcd(b[i], c[i]))
print(ma)
### BUGGY CODE ###

N = int(input())
for a in range(N // 100 + 1):
  for b in range(N // 101 + 1):
    for c in range(N // 102 + 1):
      for d in range(N // 103 + 1):
        for e in range(N // 104 + 1):
          for f in range(N // 105 + 1):
            if a * 100 + b * 101 + c * 102 + d * 103 + e * 104 + f * 105 == N:
              print(1)
              exit()
print(0)

### FIXED CODE ###

N = int(input())


for a in range(N // 100 + 1):
  for b in range(N // 101 + 1):
    for c in range(N // 102 + 1):
      for d in range(N // 103 + 1):
        for e in range(N // 104 + 1):
          for f in range(N // 105 + 1):
            if a * 100 + b * 101 + c * 102 + d * 103 + e * 104 + f * 105 == N:
              print(1)
              exit()
print(0)
### BUGGY CODE ###

#!/usr/bin/env python3

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A = sorted(A)
B = sorted(B)
C = sorted(C)
# print(f"N: {N}")
# print(f"A, B, C: {A}, {B}, {C}")

def binary_search_lower_bound(arr, value):
    left = -1
    right = len(arr)
    while right - left > 1:
        mid = left + int((right - left) / 2)
        if value > arr[mid]:
            left = mid
        elif value < arr[mid]:
            right = mid

    return right

count = 0
B_bin = []
C_bin = []
for top in A:
    # print(f"\ntop: {top}")
    index_B = binary_search_lower_bound(B, top)
    B_bin = B[index_B:]
    # print(f"B_bin: {B_bin}")
    for mid in B_bin:
        # print(f"mid: {mid}")
        index_C = binary_search_lower_bound(C, mid)
        C_bin = C[index_C:]
        count += len(C_bin)

print(count)


### FIXED CODE ###

#!/usr/bin/env python3

import bisect

N = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
# print(f"N: {N}")
# print(f"A, B, C: {A}, {B}, {C}")

def binary_search_more_than(arr, value):
    left = 0
    right = len(arr) - 1
    if value < arr[left]:
        return left
    if value > arr[right]:
        return None
    while left <= right:
        mid = int((left + right) / 2)
        if value > arr[mid]:
            left = mid + 1
        elif value < arr[mid]:
            right = mid - 1
        else:
            return mid + 1
    # left == right + 1, so arr[right] < value < arr[left]
    return left

def binary_search_less_than(arr, value):
    left = 0
    right = len(arr) - 1
    if value < arr[left]:
        return None
    if value > arr[right]:
        return right
    while left <= right:
        mid = int((left + right) / 2)
        if value > arr[mid]:
            left = mid + 1
        elif value < arr[mid]:
            right = mid - 1
        else:
            return mid - 1
    # left == right + 1, so arr[right] < value < arr[left]
    return right

# count = 0
# if N == 1:
#     if A[0] < B[0] < C[0]:
#         count += 1
# else:
#     for bot in B:
#         index_A = binary_search_less_than(A, bot)
#         index_C = binary_search_more_than(C, bot)
#         # print(f"index_A: {index_A}")
#         # print(f"index_C: {index_C}")
#         if index_A != None and index_C != None:
#             count += (index_A + 1) * (N - index_C)

# print(count)

count = 0
for bot in B:
    i_A = bisect.bisect_left(A, bot)
    i_C = bisect.bisect_right(C, bot)
    count += i_A * (N - i_C)
print(count)
### BUGGY CODE ###

N=int(input())
*A,=map(int,input().split())

J=[0]*N
j=0
while j<N:
    J[j]=j-A[j]
    j+=1

ans=0
i=0
while i<N:
    ans+=J.count(i+A[i])
    i+=1

print(ans)

### FIXED CODE ###

N=int(input())
*A,=map(int,input().split())

J=[0]*N
j=0
while j<N:
    J[j]=j-A[j]
    j+=1

import collections
C = collections.Counter(J)

ans=0
i=0
while i<N:
    ans+=C[i+A[i]]
    i+=1

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

N,x = map(int,input().split())
A = list(map(int,input().split()))
A_org = sum(A)
if A[0]>x:
	A[0]=x
for i in range(N-1):
	while A[i]+A[i+1]>x:
		A[i+1]-= 1

print(A_org-sum(A))

### FIXED CODE ###

N,x = map(int,input().split())
A = list(map(int,input().split()))
A_org = sum(A)
if A[0]>x:
	A[0]=x
for i in range(N-1):
	if A[i]+A[i+1]>x:
		A[i+1] = x-A[i]

print(A_org-sum(A))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**8)
from collections import defaultdict,Counter
def saiki(S):
  hitomozi = []
  d = defaultdict(lambda: [])
  cnts = defaultdict(lambda: 0)
  for s in S:
    if len(s)==1:
      hitomozi.append(s)
    else:
      d[s[0]].append(s[1:])
      c = Counter(s)
      for k in c.keys():
        cnts[k] += 1
  for h in hitomozi:
    ans[0] += cnts[h]
  for k,v in d.items():
    saiki(v)

N = int(input())
S = [input()[::-1] for _ in range(N)]
ans = [0]
saiki(S)
print(ans[0])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**8)
from collections import defaultdict,Counter
def saiki(cnts):
  hitomozi = []
  d = defaultdict(lambda: [])
  heads = defaultdict(lambda: 0)
  for s,c in cnts:
    if len(s)==1:
      hitomozi.append(s[0])
    else:
      for k,v in c.items():
        if v>0:
          heads[k] += 1
      t = s[-1]
      c[t] -= 1
      s.pop(-1)
      d[t].append([s,c])
  for h in hitomozi:
    ans[0] += heads[h]
  for v in d.values():
    if len(v)<=1:
      continue
    saiki(v)
  return 

N = int(input())
S = [list(input()) for _ in range(N)]
ans = [0]
cnts = []
for s in S:
  cnts.append([s,Counter(s)])
saiki(cnts)
print(ans[0])
### BUGGY CODE ###

N, X, Y = map(int, input().split())

L = []
for i in range(1, N+1):
    for j in range(i+1, N+1):
        L.append(min(j-i, abs(X-i)+abs(Y-j)+1))

for i in range(1, N):
    print(L.count(i))

### FIXED CODE ###

import collections

N, X, Y = map(int, input().split())

L = []
for i in range(1, N+1):
    for j in range(i+1, N+1):
        L.append(min(j-i, abs(X-i)+abs(Y-j)+1))

c = collections.Counter(L)

for i in range(1, N):
    print(c[i])
### BUGGY CODE ###

import sys
from itertools import combinations

input = sys.stdin.readline


def main():
    # 種類
    N = int(input())
    S = input().strip()
    print(len(set(combinations(S, 3))))


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
from itertools import combinations

input = sys.stdin.readline


def check_num(text):
    cnt = 0
    for i in range(10):
        index = text.find(str(i))
        if index != -1:
            cnt += 1
    return cnt


def main():
    # 種類
    # N = int(input())
    # S = input().strip()
    S = sum(str(i) for i in range(10))
    for i in range(10):
        index = S.find(str(i))
        if index != -1:
            a = check_num(S[index:])
    # 10個の数字
    # 最大1000件
    # 0-9:0-9:0-9
    # print(len(set(combinations(S, 3))))


def hoge():
    N = int(input())
    S = input().strip()
    count = 0
    for x in range(10):
        xindex = S.find(str(x))
        if xindex == -1:
            continue
        for y in range(10):
            yindex = S[xindex + 1 :].find(str(y))
            if yindex == -1:
                continue
            for z in range(10):
                zindex = S[xindex + 1 :][yindex + 1 :].find(str(z))
                if zindex == -1:
                    continue
                count += 1
    print(count)


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

N = int(input())
A = list(int(x) for x in input().split())
ans = [None] * N
for i in range(N):
    b = A.index(i + 1)
    ans[i] = b + 1
for i in range(N):
    print(ans[i])

### FIXED CODE ###

N = int(input())
A = list(int(x) for x in input().split())
ans = [None] * N
for i in range(N):
    ans[A[i] - 1] = i + 1
for i in range(N):
    print(ans[i])
### BUGGY CODE ###

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

num = 0
now = 0
been = set()
been.add(0)

while now != 1:
    now = a[now] - 1
    if now in been:
        num = -1
        break
    else:
        num += 1

print(num)

### FIXED CODE ###

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

num = 0
now = 0
been = set()
been.add(0)

while now != 1:
    now = a[now] - 1
    if now in been:
        num = -1
        break
    else:
        been.add(now)
        num += 1

print(num)
### BUGGY CODE ###

# abc169_b.py
N = int(input())
A = list(map(int,input().split()))
ans =1
for i in A:
    ans *= i 
if ans >10**18:
    print(-1)
    exit()
print(ans)


### FIXED CODE ###

# abc169_b.py
N = int(input())
A = list(map(int,input().split()))
ans =1
A.sort()
for i in A:
    if i == 0 :
        ans = 0
        break
    ans *= i 
    if ans >10**18:
        print(-1)
        exit()
print(ans)
### BUGGY CODE ###

a, b = map(int, input().split())
def gcd(a, b):
    while b > 0:
        a, b = b, a%b
    return a
n = gcd(a, b)
def get_primenumber(N):
    #素数リスト
    prime_list = [2]
    #3からNまでの数字を一つずつ取り出す
    for num in range(3,N+1,2):
      #取り出した数字が素数リストの要素で割れなければ素数リストに追加する
      if all( num % prime != 0 for prime in prime_list):
        prime_list.append(num)

    return prime_list
l = get_primenumber(n)
count = 1
for p in l:
    if a % p == 0 and b % p == 0:
        count += 1
print(count)

### FIXED CODE ###

a, b = map(int, input().split())

def gcd(a, b):
    while b > 0:
        a, b = b, a%b
    return a
n = gcd(a, b)

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

ans = set(prime_factorize(n))
print(len(ans)+1)
### BUGGY CODE ###

N, M = map(int, input().split())
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())

import numpy as np
A = np.array(A)
B = np.array(B)

C = np.array([A, B])
C.sort(1)
C = C[:, ::-1]

point = [0] * M
for j in range(M):
    C.sort(1)
    C = C[:, ::-1]
    for i in range(N):
        if C[0][i] + j <= M:
            point[j] += C[1][i]
            C[:, :1] = 0
            break

print(sum(point))

### FIXED CODE ###

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

jobs = {}
for _ in range(N):
    A, B = map(int, input().split())
    if A > M :
        continue
    if A in jobs:
        jobs[A].append(B)
    else:
        jobs[A] = [B]

#output
import heapq

#点数配列の用意
point = 0
hq = []
#M-i日目(1 <= i <= M)に働ける仕事の中で、Bが最大のものを選ぶ
for A in range(1, M+1):
    if A in jobs:
        for B in jobs[A]:
            heapq.heappush(hq, -B)
    else:
        if len(hq) == 0:
            continue
    point += -heapq.heappop(hq)

print(point)
### BUGGY CODE ###

S = list(input())
T = list(input())

new_S = ""
new_T = ""


def change_word(a,b,S):
    for i in range(len(S)):
        if S[i] == a:
            S[i] = b
        elif S[i] == b:
            S[i] = a
        else:
            S[i] == S[i]
    return S



tmp = []
for i in range(len(S)):
    if S[i] != T[i]:
        #tmp.append([S[i], T[i]])
        S = change_word(S[i], T[i], S)
        #T = change_word(S[i], T[i], T)


#for i in tmp:


if S == T:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

S = list(input())
T = list(input())
 
test = [-1] * 26
test2 = [-1] * 26

for i in range(len(S)):
    a = ord(S[i]) - ord('a')
    b = ord(T[i]) - ord('a')

    if (test[a] != -1) or test2[b] != -1:
        if test[a] != b or test2[b] != a:
           print("No")
           exit()

    else:
        test[a] = b
        test2[b] = a


print("Yes")
### BUGGY CODE ###

n = int(input())
s = input()
high = n//2
low = 1
ans = 0

while low <= high:
    i = (high+low)//2
    for j in range(n-i*2+1):
        if s[j:i+j] in s[i+j:]:
            if ans < i:
                ans = i
                low = i+1
                break
    if ans < i:
        high = i-1
print(ans)

### FIXED CODE ###

n = int(input())
s = input()
high = n//2
low = 1
ans = 0

while low <= high:
    t = set()
    i = (high+low)//2
    for j in range(n-i*2+1):
        t.add(s[j:i+j])
        if s[i+j:j+2*i] in t:
            if ans < i:
                ans = i
                low = i+1
                break
    if ans < i:
        high = i-1
print(ans)
### BUGGY CODE ###

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

count = 0

for i in range(k + 1):
    for j in range(k + 1):
        for k in range(k + 1):
            if i + j + k == s:
                count += 1
            else:
                pass

print(count)

### FIXED CODE ###

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

count = 0

for i in range(k + 1):
    for j in range(k + 1):
        if 0 <= s - i - j <= k:
            count += 1

print(count)