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

n,k = map(int,input().split())
li = [i for i in range(0,n+1)]
#print(li)
#[0,1, 2, 3]
tmp = 0
def exc(n):
    return (1+n)*n//2

for i in range(k,n+2):
    #print(i,li[n-i+1:],li[:i],sum(li[n-i+1:]) - sum(li[:i]))
    tmp += sum(li[n-i+1:]) - sum(li[:i]) + 1
print(tmp)

### FIXED CODE ###

n,k = map(int,input().split())
li = [i for i in range(0,n+1)]
#print(li)
#[0,1, 2, 3]
tmp = 0
def exc(n):
    return (n)*(n+1)//2

for i in range(k,n+2):
    #print(i,li[n-i+1:],li[:i],sum(li[n-i+1:]) - sum(li[:i]))
    #tmp += sum(li[n-i+1:]) - sum(li[:i]) + 1
    mi = exc(i-1)
    ma = exc(n) - exc(n-i)
    #print(i,mi,ma,ma - mi + 1)
    tmp += ma - mi + 1
print(tmp%(10**9+7))
### BUGGY CODE ###

n,m=map(int,input().split())
a=sorted(list(map(int,input().split())))
for i in range(m):
  a[-1]=a[-1]//2
  a=sorted(a)
print(sum(a))

### FIXED CODE ###

import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,m=mp()
a=lmp()
l=[]
heapq.heapify(l)
for i in a:
    heapq.heappush(l,(-1)*i)
for i in range(m):
    j=heapq.heappop(l)
    heapq.heappush(l,-(-j//2))
print(-sum(l))
### BUGGY CODE ###

def solve():
    from sys import stdin
    f_i = stdin
    
    H, W = map(int, f_i.readline().split())
    A = tuple(tuple(map(int, f_i.readline().split())) for i in range(H))
    B = tuple(tuple(map(int, f_i.readline().split())) for i in range(H))
    
    dp1 = [set() for i in range(W)]
    dp1[0].add(0)
    for A_i, B_i in zip(A, B):
        dp2 = [set() for i in range(W)]
        diff = A_i[0] - B_i[0]
        for pre_bias in dp1[0]:
            dp2[0].add(pre_bias + diff)
            dp2[0].add(pre_bias - diff)
        for j, t in enumerate(zip(A_i[1:], B_i[1:]), start=1):
            A_ij, B_ij = t
            diff = A_ij - B_ij
            for pre_bias in dp1[j]:
                dp2[j].add(pre_bias + diff)
                dp2[j].add(pre_bias - diff)
            for pre_bias in dp2[j-1]:
                dp2[j].add(pre_bias + diff)
                dp2[j].add(pre_bias - diff)
        dp1 = dp2
    
    ans = min(abs(x) for x in dp2[-1])
    print(ans)

solve()

### FIXED CODE ###

def solve():
    from sys import stdin
    f_i = stdin
    
    H, W = map(int, f_i.readline().split())
    A = tuple(tuple(map(int, f_i.readline().split())) for i in range(H))
    B = tuple(tuple(map(int, f_i.readline().split())) for i in range(H))
    
    dp1 = [0] * W
    bit_width = 80 * (H + W - 2)
    dp1[0] = 1 << (bit_width)
    for A_i, B_i in zip(A, B):
        dp2 = [0] * W
        
        diff = abs(A_i[0] - B_i[0])
        dp2[0] = (dp1[0] << diff) | (dp1[0] >> diff)
        
        for j, t in enumerate(zip(A_i[1:], B_i[1:]), start=1):
            A_ij, B_ij = t
            diff = abs(A_ij - B_ij)
            b = dp1[j] | dp2[j-1]
            dp2[j] = (b << diff) | (b >> diff)
        
        dp1 = dp2
    
    b = bin(dp2[-1])
    b = b[-bit_width-1:]
    print(b.index('1'))
 
solve()
### BUGGY CODE ###

from sys import stdin,stdout


def convert(x):
    if x == 'R': return 0
    if x == 'G': return 1
    if x == 'B': return 2
    

def solve(S,N):
    presum = [[0 for _ in range(3)] for _ in range(N + 1)]
    
    for i in range(N):
        for j in range(3): 
            presum[i + 1][j] += presum[i][j]
        presum[i + 1][S[i]] += 1

    #Exclusion 

    
    sumall = 0
    for i in range(N - 2):
        for k in range(i + 2,N):
            if S[i] != S[k]:
                c = 3 - S[i] - S[k] 
                sumall += presum[k][c] - presum[i + 1][c]
                
                if (i + k) % 2 == 0:
                    j = (i + k)//2
                    if S[j] == c: sumall -= 1
    return str(sumall)


if __name__ == "__main__": 
    #Input 
    N = int(stdin.readline().rstrip())
    S = stdin.readline().rstrip()
    S = [convert(x) for x in S]
    
    stdout.write(solve(S,N))
    





### FIXED CODE ###

from sys import stdin,stdout


def solve(S,N):
    color = [[] for _ in range(3)]

    for i in range(N):
        if S[i] == 'R': color[0].append(i)
        elif S[i] == 'G': color[1].append(i)
        else: color[2].append(i)
    
    
    #Exclusion 
    total = len(color[0])*len(color[1])*len(color[2])

    remain = 0
    for i in range(N - 2):
        for j in range(i + 1,N - 1):
            k = j + j - i
            if k >= N: break
            
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                remain += 1
    return total - remain


    


if __name__ == "__main__": 
    #Input 
    N = int(stdin.readline().rstrip())
    S = stdin.readline().rstrip()
    stdout.write(str(solve(S,N)))
### BUGGY CODE ###

def dfs(n):
    global b,check,d
    #ttfは235、chaはabc
    for ttf,cha in zip([2,3,5],b):
        #-1ずつしていく場合
        check[0]=min(check[n]+n*d,check[0])

        #最寄りまで-してく場合
        x1,x2=n//ttf,n%ttf
        if x1 in check:
            if check[x1]>check[n]+x2*d+cha:
                check[x1]=check[n]+x2*d+cha
                dfs(x1)
        else:
            check[x1]=check[n]+x2*d+cha
            dfs(x1)

        #最寄りまで+1してく場合
        x1,x2=n//ttf+1,ttf-n%ttf
        if x1 in check:
            if check[x1]>check[n]+x2*d+cha:
                check[x1]=check[n]+x2*d+cha
                dfs(x1)
        else:
            check[x1]=check[n]+x2*d+cha
            dfs(x1)

t=int(input())
for i in range(t):
    N,*b,d=map(int,input().split())
    check={N:0,0:N*d}
    dfs(N)
    print(check[0])


### FIXED CODE ###

import sys
check=dict()
N,a,b,c,d=0,0,0,0,0
#ttfは235、chaはabc
def dfs_sub(n,ttf,cha):
    global check,d
    if 0 in check:
        check[0]=min(check[n]+n*d,check[0])
    else:
        check[0]=check[n]+n*d
    if n//ttf==0:
        if n//ttf in check:
            if check[n//ttf]>check[n]+(n%ttf)*d:
                check[n//ttf]=check[n]+(n%ttf)*d
        else:
            check[n//ttf]=check[n]+(n%ttf)*d
    else:
        if n//ttf in check:
            if check[n//ttf]>check[n]+(n%ttf)*d+cha:
                check[n//ttf]=check[n]+(n%ttf)*d+cha
                dfs(n//ttf)
        else:
            check[n//ttf]=check[n]+(n%ttf)*d+cha
            dfs(n//ttf)
    if 1+n//ttf in check:
        if check[1+n//ttf]>check[n]+(ttf-n%ttf)*d+cha:
            check[1+n//ttf]=check[n]+(ttf-n%ttf)*d+cha
            dfs(1+n//ttf)
    else:
        check[1+n//ttf]=check[n]+(ttf-n%ttf)*d+cha
        dfs(1+n//ttf)


def dfs(n):
    global check,a,b,c,d
    dfs_sub(n,2,a)
    dfs_sub(n,3,b)
    dfs_sub(n,5,c)

t=int(input())
ans=[0]*t
for i in range(t):
    N,a,b,c,d=map(int,input().split())
    check={N:0}
    dfs(N)
    ans[i]=check[0]
for i in range(t):
    print(ans[i])
### BUGGY CODE ###

import math
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

saidai = math.gcd(a,b)


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 ###

#D-XXOR

n,k=map(int,input().split())
lists=list(map(int,input().split()))
a=format(k,"b")
length=len(a)

for some in lists:
    check=format(some,"b")
    length=max(length,len(check))

uselists=[0]*length
for some in lists:
    check=format(some,"0%ib"%length)

    for i in range(length):
        if check[i]=="1":
            uselists[length-1-i]+=1
if k>=1:
    for i in range(length):
        if  2**i<=k<2**(i+1):
            order=i
            break    
    ans2=0
    ans1=0
    for j in range(order):
        ans1+=(2**j)*max(uselists[j],n-uselists[j])
    #k<2**orderにおける最大の値はこれでOK
    #k>=2**iの時
    for j in range(order+1,length):
        ans2+=(2**j)*uselists[j]
    
    ans2+=(2**order)*(n-uselists[order])
####
    bigger=0
    for g in range(0,k-2**order+1):
        checker=0
        some=format(g,"0%ib"%order)
        for i in range(order):
            if some[i]=="1":
                checker+=(2**(order-1-i))*(n-uselists[i])
            else:
                checker+=(2**(order-1-i))*uselists[i]
        bigger=max(bigger,checker)
    ans2=ans2+bigger
    print(max(ans1,ans2))
    
elif k==0:
    ans=0
    for i in range(length):
        if uselists[i]=="1":
            ans+=(2**i)*(n-uselists[i])
        else:
            ans+=(2**i)*uselists[i]
            
    print(ans)
        

### FIXED CODE ###

n,k=map(int,input().split())
k2=format(k+1,"0%ib"%40)
lists=list(map(int,input().split()))
countlist=[0]*40
for j in lists:
    c=format(j,"0%ib"%40)
    for i in range(40):
        if c[i]=="1":
            countlist[i]+=1

emptylist=[]
for i in range(40):
    if k2[i]=="1":
        emptylist.append(i)
if k>=1:
    ans=0
    for i in emptylist:
        subing=0
        for j in range(40):
            if j<i:
                if k2[j]=="1":
                    subing+=(2**(39-j))*(n-countlist[j])
                elif k2[j]=="0":
                    subing+=(2**(39-j))*countlist[j]
            if j==i:
                subing+=(2**(39-i))*countlist[i]
            
            if j>i:
                subing+=(2**(39-j))*max(countlist[j],n-countlist[j])
        ans=max(ans,subing)
    print(ans)
elif k==0:
    ans=0
    for i in range(40):
        ans+=(2**(39-i))*countlist[i]
    print(ans)
### BUGGY CODE ###

A, B = map(int, input().split())

def gcd(a, b):
	if b == 0:
		return(a)
	else :
		return gcd(b, a % b)
		
a = gcd(A, B)
ctr = 1

for i in range(2, a + 1):
	do = 0
	while a % i == 0:
		a /= i
		do = 1
		if a == 1:
			break
	if do:
		ctr += 1
	if a == 1:
		break
		
print(ctr)

### FIXED CODE ###

import math
A, B = map(int, input().split())

def gcd(a, b):
	if b == 0: return(a)
	else : return gcd(b, a % b)
		
G = gcd(A, B)
ctr = 1
for i in range(2, int(math.sqrt(G)) + 1):
    if G == 1: 
        break
    if G % i == 0: 
        ctr += 1
    while G % i == 0:
        G /= i
        
if G == 1:        
    print(ctr)
else:
    print(ctr + 1)
### BUGGY CODE ###

import math
import sys
readline = sys.stdin.readline


def main():
    a, b, n = map(int, readline().rstrip().split())
    maxt = 0
    for x in range(n):
        maxt = max(maxt, math.floor(a * (x + 1) / b) -
                   a * math.floor((x+1) / b))
    print(maxt)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import math
import sys
import collections
import bisect


def main():
    a, b, n = map(int, input().split())
    i = max(b - 1 if n >= b else n, 1)
    print(math.floor(a * i / b) - a * math.floor(i / b))


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

N=int(input())
S=input()
minimum=3*pow(10, 5)
for i in range(N):
    X=S[:i]
    Y=S[i+1:]
    if S[i]=='E':
        candidate = (len(X)-X.count(S[i]))+Y.count(S[i])
    else:
        candidate = X.count(S[i])+(len(Y)-Y.count(S[i]))
    minimum = min(candidate, minimum)
print(minimum)

### FIXED CODE ###

N=int(input())
S=input()
minimum=3*pow(10, 5)
east=[0]
for i in range(1,N+1):
    if S[i-1]=='E':
        east.append(east[i-1]+1)
    else:
        east.append(east[i-1])
for i in range(N):
    candidate = i-east[i]+(east[N]-east[i+1])
    minimum = min(candidate, minimum)
print(minimum)
### BUGGY CODE ###

N, S = map(int,input().split())
A = [int(s) for s in input().split()]
DP = [[0 for j in range(S + 1)] for i in range(N + 1)]
mod = 998244353
DP[0][0] = 1

for i in range(N):
  for j in range(S + 1):
    DP[i + 1][j] += 2 * DP[i][j]
    DP[i + 1][j] %= mod
    if j + A[i] <= S:
      DP[i + 1][j + A[i]] += DP[i][j]
      DP[i + 1][j] %= mod

print(DP[N][S])

### FIXED CODE ###

N, S = map(int,input().split())
A = [int(s) for s in input().split()]
DP = [[0 for j in range(S + 1)] for i in range(N + 1)]
mod = 998244353
DP[0][0] = 1

for i in range(N):
  for j in range(S + 1):
    DP[i + 1][j] += 2 * DP[i][j]
    DP[i + 1][j] %= mod
    if j + A[i] <= S:
      DP[i + 1][j + A[i]] += DP[i][j]
      DP[i + 1][j + A[i]] %= mod

print(DP[N][S])
### BUGGY CODE ###

from collections import deque
H, W = map(int, input().split())
sheet = [[0]*(W+2) for i in range(H+2)]
for i in range(H):
  s = input()
  for j in range(W):
    if s[j]=='.':
      sheet[i+1][j+1] = 1

m = -1
for i in range(1, H+1):
  for j in range(1, W+1):
    for a in range(1, H+1):
      for b in range(1, W+1):
        if sheet[i][j]==0 or sheet[a][b]==0:
          continue
        stuck = deque([(j, i, 0)])
        while stuck:
          x, y, c = stuck.popleft()
          if x==b and y==a:
            if m<c:
              m=c
            break
          for dx, dy in [(0,1), (0,-1), (1,0), (-1,0)]:
              if sheet[y+dy][x+dx]==1:
                stuck += [(x+dx, y+dy, c+1)]
print(m)

### FIXED CODE ###

from collections import deque
H, W = map(int, input().split())
sheet = [[0]*(W+2) for i in range(H+2)]
for i in range(H):
  s = input()
  for j in range(W):
    if s[j]=='.':
      sheet[i+1][j+1] = 1

ans = -1
for i in range(1, H+1):
  for j in range(1, W+1):
    m = -1
    if sheet[i][j]==0:
      continue
    stuck = deque([(j, i, 0)])
    log = [[10**5]*(W+2) for i in range(H+2)]
    log[i][j] = 0
    while stuck:
      x, y, c = stuck.popleft()
      if c>m:
        m = c
      for dx, dy in [(0,1), (0,-1), (1,0), (-1,0)]:
        if sheet[y+dy][x+dx]==1 and log[y+dy][x+dx]>c+1:
          log[y+dy][x+dx] = c+1
          stuck += [(x+dx, y+dy, c+1)]
    if ans<m:
      ans = m
print(ans)
### BUGGY CODE ###

def fibonacci(n):
    if n==0:
        return 1
    elif n==1:
        return 1
    else:
        return fibonacci(n-1) + fibonacci(n-2)

n = int(input())
print(fibonacci(n))

### FIXED CODE ###

def fibonacci(n, memo=None):
    if memo==None:
        memo = [None]*n
    if n<=1:
        return 1 
    else:
        if memo[n-2]==None:
            memo[n-2] = fibonacci(n-2, memo)
        if memo[n-1]==None:
            memo[n-1] = fibonacci(n-1, memo)
    return memo[n-1] + memo[n-2]

n = int(input())
print(fibonacci(n))
### BUGGY CODE ###

def iread():
    return int(input())


def sread():
    return input()


def aread_int():
    tmp = input().split()
    ret = [int(i) for i in tmp]
    return ret


def aread_str():
    return input().split()

if __name__ == '__main__':
    n, m = map(int, input().split())
    
    x = aread_int()
    x = sorted(x)
    x_dist = [0] * (m - 1)
    for i in range(m - 1) :
        x_dist[i] += abs(x[i] - x[i + 1])
    
    if n > m :
        print(0)
        exit()
    
    cost = sum(x_dist)
    for i in range(n - 1) :
        max_idx = x_dist.index(max(x_dist))
        cost -= x_dist[max_idx]
        # print(x_dist[max_idx])
        x_dist[max_idx] = 0

    print(cost)

### FIXED CODE ###

def iread():
    return int(input())


def sread():
    return input()


def aread_int():
    tmp = input().split()
    ret = [int(i) for i in tmp]
    return ret


def aread_str():
    return input().split()

if __name__ == '__main__':
    n, m = map(int, input().split())
    
    x = aread_int()
    x = sorted(x)
    x_dist = [0] * (m - 1)
    for i in range(m - 1) :
        x_dist[i] += abs(x[i] - x[i + 1])
    
    if n > m :
        print(0)
        exit()
    
    x_dist = sorted(x_dist)
    idx = len(x_dist) - 1
    cost = sum(x_dist)
    for i in range(n - 1) :
        cost -= x_dist[idx]
        x_dist[idx] = 0
        idx -= 1

    print(cost)
### BUGGY CODE ###

# Problem A - ><

# input
S = input()

# initialization
part_str = []
tmp = S
last_i = 0
for i in range(len(S)-1):
    if S[i]=='>' and S[i+1]=='<':
        part_str.append(S[last_i:i+1])
        last_i = i + 1
        tmp = S[last_i:]
if len(tmp)>=1:
    part_str.append(tmp)

ans = 0

# count
for p in part_str:
    left_count = 0
    right_count = 0
    for c in p:
        if c=='<':
            left_count += 1
        elif c=='>':
            right_count += 1
    tmp_max = max(left_count, right_count)
    if left_count-1>0:
        left_count -= 1
        left_count = (left_count * (1 + left_count)) / 2
    else:
        left_count = 0

    if right_count-1>0:
        right_count -= 1
        right_count = (right_count * (1 + right_count)) / 2
    else:
        right_count = 0
    ans += tmp_max + left_count + right_count

# output
print("%d"%(ans))


### FIXED CODE ###

# Problem A - ><

S = input()
N = len(S) + 1

num_list = [0]*N
ans_sum = 0

# < process
for i in range(len(S)):
    s = S[i]
    if s=="<":
        num_list[i+1] = num_list[i] + 1

# > process
for i in range(len(S)-1, -1, -1):
    s = S[i]
    if s==">":
        num_list[i] = max(num_list[i], num_list[i+1]+1)

# sum process
for i in range(N):
    ans_sum = ans_sum + num_list[i]

print(ans_sum)
### BUGGY CODE ###

N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
def binary_search(list,target): 

	result = -1
	left = 0
	right = len(list) - 1

	while left <= right:
		center = (left + right)//2
		if list[center] == target:
			result = center
			break
		elif list[center] < target:
			right = center - 1
		elif list[center] > target:
			left = center + 1
	if result == -1:
		return left
	else:
		return result

if N>1:
  for i in range(M):
    A[0]=A[0]//2
    if A[0]<A[1]:
      j=binary_search(A[1:],A[0])
      A=A[1:j+1]+[A[0]]+A[j+1:]
else:
  A[0]=A[0]//(2**M)
print(sum(A))

### FIXED CODE ###

from collections import deque
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
q1=deque(A)
q2=deque([])
for i in range(M):
  if len(q1)!=0 and (len(q2)==0 or q1[0]>=q2[0]):
    x=q1.popleft()
  else:
    x=q2.popleft()
  q2.append(x//2)
print(int(sum(q1)+sum(q2)))
### BUGGY CODE ###

r, g, b, n = map(int, input().split())

ans = 0
for i in range(1+n//r):
  for j in range(1+n//g):
    div = (n - g*j - r*i)//b
    mod = (n - g*j - r*i)%b
    if div >= 0 and mod == 0:
      ans += 1
        
print(ans)

### FIXED CODE ###

r, g, b, n = map(int, input().split())

ans = 0
for i in range(1+n//r):
  tmp = n - r*i
  for j in range(1+tmp//g):
    mod = (n - g*j - r*i)%b
    if mod == 0:
      ans += 1
        
print(ans)
### BUGGY CODE ###

import bisect
n = int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))
al.sort()
bl.sort()
cl.sort()
ans = 0
for i in range(n):
    # リストAに値xを入れ、xが複数になるとき、一番右の値xのインデックスを返す
    j = bisect.bisect_right(bl, al[i])
    for k in range(j, n):
        l = bisect.bisect_right(cl, bl[k])
        ans += (n-l)
print(ans)


### FIXED CODE ###

import bisect
n = int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))
al.sort()
bl.sort()
cl.sort()
ans = 0
tmp1 = [n]*n
tmp2 = [n]*n
for i in range(n):
    j = bisect.bisect_left(al, bl[i])
    tmp1[i] = j
for i in range(n):
    j = bisect.bisect_right(cl, bl[i])
    tmp2[i] = n-j
for i in range(n):
    ans += tmp1[i]*tmp2[i]
print(ans)
### BUGGY CODE ###

s=int(input())

#0<= x,y <=10**9
#s/2

if s<=10**9:
    print(0,0,1,0,0,s)
    exit()

hoge=int(s**0.5)

for i in range(hoge):
    ss=hoge-i
    #print(ss)
    if s%ss==0:
        print(0,0,ss,0,0,s//ss)
        exit()



### FIXED CODE ###

import sys
input=sys.stdin.readline

s=int(input())

#0<= x,y <=10**9
#s/2

if s<=10**9:
    print(0,0,1,0,0,s)
    exit()

y=(-1*s//(10**9))*(-1)
x=10**9*y-s

print(0,0,10**9,1,x,y)
### BUGGY CODE ###

import heapq
n,m = map(int,input().split())
l = []
for i in range(n):
  a,b = map(int,input().split())
  l.append([a,b])
l = sorted(l, key=lambda x: (x[0],x[1]))
b = []
heapq.heapify(l)
j = 0
q = 0
for i in range(m):
  key = i+1
  if j >= n+1:
    break
  while j < n:
    if l[j][0] != key:
      break
    heapq.heappush(b,-l[j][1])
    j += 1
  if b != []:
    heapq.heapify(b)
    k = -heapq.heappop(b)
    q += k
print(q)

### FIXED CODE ###

from heapq import *
n,m = map(int,input().split())
l = [[] for i in range(m+1)]
for i in range(n):
  a,b = map(int,input().split())
  if a < m+1:
    l[a].append(b)

ans = 0
a = []
for i in range(1,m+1):
  for j in l[i]:
    heappush(a,-j)
  if a:
    ans -= heappop(a)
print(ans)
### BUGGY CODE ###

N = int(input())
li = [x for x in range(1,N+1)]
ans = 0
for i in range(N):
    if i != N-1:
        ans += li[i] % li[i+1]
print(ans)

### FIXED CODE ###

N = int(input())
ans = N*(N-1)//2
print(ans)
### BUGGY CODE ###

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
list = [list(map(int, input().split())) for x in range(m)]


for i in list:
    for j in range(i[0]):
        if i[1]>min(a):
            a[a.index(min(a))] = i[1]

print(sum(a))

### FIXED CODE ###

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
list = [list(map(int, input().split())) for x in range(m)]
list.sort(key=lambda x: x[1], reverse=True) # １番の要素で降順ソート

app_count = 0
for i in list:
    a += [i[1]]*i[0]
    app_count += i[0]
    if app_count>n:
        break

a.sort(reverse=True)

print(sum(a[:n]))
### BUGGY CODE ###

import sys
def solve(S):
    dp = [0] * 2019
    ans = 0
    for c in S:
        dp2 = [0] * 2019
        dp2[c] = 1
        for i in range(2019):
            if dp[i] == 0: continue
            v = i*10+c
            dp2[v if v<2019 else v%2019] += dp[i]
        dp = dp2
        ans += dp[0]
    return ans
S = [x-ord('0') for x in sys.stdin.buffer.read().rstrip()]
print(solve(S))

### FIXED CODE ###

S = input()
r = 1
arr = [0]
for c in S[::-1]:
    arr.append((arr[-1] + int(c) * r) % 2019)
    r *= 10
    r %= 2019
from collections import Counter
ctr = Counter(arr)
ans = 0
for v in ctr.values():
    ans += v*(v-1)//2
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)
def rec(i):
    if C[i] != INFTY:
        return C[i]
    if i == 0:
        C[i] = 0
        return C[i]
    elif i == 1:
        C[i] = rec(i-1)+abs(H[i]-H[i-1])
        return C[i]
    C[i] = min([rec(i-k)+abs(H[i]-H[i-k]) for k in range(1, min(i+1, K+1))])
    return C[i]

INFTY = 10**13
N, K = map(int, input().split())
H = list(map(int, input().split()))
C = [INFTY for i in range(N)]
print(rec(N-1))

### FIXED CODE ###

N, K = map(int, input().split())
H = list(map(int, input().split()))
C = [10**13 for i in range(N)]
C[0] = 0
for i in range(N):
    for j in range(1, K+1):
        if i+j < N:
            C[i+j] = min(C[i] + abs(H[i+j]-H[i]), C[i+j])
print(C[-1])
### BUGGY CODE ###

N = int(input())
S = input()

S = "1234" * 3000
from itertools import product
from re import search

ans = 0
for i in product(map(str, range(10)), repeat=3):
    res = search(".*?".join(i), S)
    if res:
        ans += 1

print(ans)


### FIXED CODE ###

from itertools import product

N = int(input())
S = input()

one = set()
two = set()
three = set()
for s in S:
    for tw in two:
        three.add(tw + s)
    for on in one:
        two.add(on + s)
    one.add(s)
print(len(three))
### BUGGY CODE ###

k=int(input())
import fractions
x=0
c=0
d=0
for i in range(1,k+1):
  for j in range(i,k+1):
    for k in range(j,k+1):
      d=fractions.gcd(i,j)
      c=fractions.gcd(d,k)
      if i!=j and j!=k and k!=i:
        x+=6*c
      elif (i!=j and j==k) or (j!=k and k==i) or (k!=i and i==j):
        x+=3*c
      else:
        x+=c
print(x)

### FIXED CODE ###

k=int(input())
import math
x=0
c=0
d=0
for i in range(1,k+1):
  for j in range(i,k+1):
    for k in range(j,k+1):
      d=math.gcd(i,j)
      c=math.gcd(d,k)
      if i!=j and j!=k:
        x+=6*c
      elif i==j==k:
        x+=c
      else:
        x+=3*c
print(x)