Harryxun/stf_run huggingface dataset:
import heapq
n,m = map(int,input().split())
al = [[] for i in range(10)]
ans = 0
h = []
for i in range(n):
    a,b = map(int,input().split())
    al[a-1] += [-b]
for i in range(m):
    for j in al[i]:
        heapq.heappush(h,j)
    if h:
        ans -= heapq.heappop(h)
print(ans)

### FIXED CODE ###

import heapq
n,m = map(int,input().split())
al = [[] for i in range(10**5)]
ans = 0
h = []
for i in range(n):
    a,b = map(int,input().split())
    al[a-1] += [-b]
for i in range(m):
    for j in al[i]:
        heapq.heappush(h,j)
    if h:
        ans -= heapq.heappop(h)
print(ans)
k, s = map(int, input().split())
n = 0
for i in range(k + 1):
    if (s-i)/2 > k:
        continue
    elif i > s:
        break
    for j in range(s-i+1):
        if s-i-j > k:
            continue
        elif j > k:
            break
        z = s - i - j
        if 0<= z <= k
print(n)


### FIXED CODE ###

k, s = map(int, input().split())
n = 0
for i in range(k + 1):
    if (s-i)/2 > k:
        continue
    elif i > s:
        break
    for j in range(k+1):
        z = s - i - j
        if 0<= z <= k:
            n += 1
print(n)
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()

n %= 1000
if n==0:
    print(0)
else:
    print(1000-n)

### FIXED CODE ###

import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()

ans = N // 1000
ans2 = N - (ans*1000)

if ans2 == 0:
    print(0)
else:
    print(1000-ans2)
s = input()
a = 0
b = 0
c = 0
for c in s:
  if c == 'a': a += 1
  if c == 'b': b += 1
  if c == 'c': c += 1

if a == b == c:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

s = input()
na = 0
nb = 0
nc = 0

for c in s:
  if c == 'a': na += 1
  if c == 'b': nb += 1
  if c == 'c': nc += 1

if na == nb == nc:
  print('Yes')
else:
  print('No')
import math
r=int().input()
c = r * r *math.pi
cf = r *2 *math.pi
print("{0:.5f} {1:.5f}".format(c,cf))

### FIXED CODE ###

import math
r = float(input())
s=r**2*math.pi
l=2*r*math.pi
print('{:.6f} {:.6f}'.format(s,l))
#coding:utf-8



def main():
    
    def dbg(*something):
        if DEBUG:
            print(*something)


    #正の宝石を戻すことはない
    #負の宝石を戻すのは後半
    from sys import stdin
    from math import ceil,floor
    DEBUG = True
    N,K = list(map(int,stdin.readline().split()))
    V = list(map(int,stdin.readline().split()))
    
    max_value = 0
    for getnum in range(1,K+1):  #取る宝石の総数
        for a in range(getnum + 1):  #左から石を取る回数
            J = [0] * getnum #石
            b = getnum - a #右から石を取る回数
            for i in range(a):
                J[i] = V[i]
            for i in range(b):
                J[a+i] = V[-i]
            J.sort()
            #dbg(J[K-getnum:])
            tmpmax = sum(J[K-getnum:])
            max_value = max(max_value,tmpmax)
    print(max_value)



if __name__ == '__main__':
    main()


### FIXED CODE ###

#coding:utf-8



def main():
    
    def dbg(*something):
        if DEBUG:
            print(*something)


    #正の宝石を戻すことはない
    #負の宝石を戻すのは後半
    from sys import stdin
    from math import ceil,floor
    DEBUG = False
    N,K = list(map(int,stdin.readline().split()))
    V = list(map(int,stdin.readline().split()))
    
    max_value = 0
    dbg([i for i in range(3,-1,-1)])
    for getnum in range(1,min(N+1,K+1)):  #取る宝石の総数
        for a in range(getnum + 1):  #左から石を取る回数
            J = [0] * getnum #石
            b = getnum - a #右から石を取る回数
            for i in range(a):
                J[i] = V[i]
            for i in range(b):
                J[a+i] = V[-i-1]
            J.sort()
            #dbg(J,a,b)
            t = min(K-getnum,getnum) #捨てる石
           
            for i in range(t): 
                if J[i] >= 0:
                    t = i
                    break
            #dbg(J,i,t,a,b,J[t:])
            tmp_max = sum(J[t:])

            max_value = max(max_value,tmp_max)
    print(max_value)



if __name__ == '__main__':
    main()
print(input().count(1))


### FIXED CODE ###

print(input().count("1"))
import numpy as np

n,m = map(int,input().split())
h = np.array(list(map(int,input().split())))

base = np.zeros(n)
seen = np.zeros((n,n))

#for i in range(m):
#  a,b = map(int,input().split())
#  seen[a-1,b-1] = 1
#  seen[b-1,a-1] = 1
  
ans = 0
#for i in range(n):
#  temp = np.multiply(seen[i],h)
#  temp_1 = np.max(temp)
#  if (h[i] > temp_1) and (temp_1 != 0):
#    ans += 1
#  elif temp_1 == 0:
#    ans += 1
    
print(ans)

### FIXED CODE ###

import numpy as np
n,m = map(int,input().split())
h = list(map(int,input().split()))

base = np.ones(n)

for i in range(m):
  a,b =  map(int,input().split())
  if h[a-1] > h[b-1]:
    base[b-1] = 0
  elif h[a-1] < h[b-1]:
    base[a-1] = 0
  elif h[a-1] == h[b-1]:
    base[a-1] = 0
    base[b-1] = 0
    
print(int(np.sum(base)))
n = int(input())
lst = map(int, input().split())
ans = [0]*n
ans[0] = lst[0]
for i in range(1, n):
  ans[i] = min(ans[i - 1], lst[i])
print(len(set(ans))

### FIXED CODE ###

n = int(input())
lst = list(map(int, input().split()))
ans = [0]*n
ans[0] = lst[0]
for i in range(1, n):
  ans[i] = min(ans[i - 1], lst[i])
print(len(set(ans)))
import numpy as np
n,m = map(int,input().split())
A = np.zeros((n,n),dtype=np.int8)
for i in range(m):
    a,b = map(int,input().split())
    A[a-1,b-1] = 1
    
if 1 in A[A[0] == 1,n-1]:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

### FIXED CODE ###

import numpy as np
n,m = map(int,input().split())
A1 = np.zeros(n,dtype=bool)
Ai = np.zeros(n,dtype=bool)
for i in range(m):
    a,b = map(int,input().split())
    if a == 1:
        A1[b-1] = True
    if b == n:
        Ai[a-1] = True
if np.any(Ai[A1]):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')
a,b=map(int,input().split())
print(max(2a-1,a+b,2b-1)

### FIXED CODE ###

a,b=map(int,input().split())
print(max(2*a-1,a+b,2*b-1))
from networkx import *
print(max(*map(len,connected_components(Graph([*map(str,open(0))][1:])))))

### FIXED CODE ###

from networkx import *
print(max(*map(len,connected_components(Graph([*map(str.split,open(0))][1:]))),1,0))
if "7" in str(input()):
  print("Yes")
else:
  print("No)

### FIXED CODE ###

if "7" in str(input()):
    print("Yes")
else:
    print("No")
n = int(input())
a =  [int(input()) for i in range(n)]

for i in range(n):
  print(max(a[:i], a[i+1:]))

### FIXED CODE ###

import numpy as np
n = int(input())
a =  [int(input()) for i in range(n)]
max_a_num = a.count(max(a))
b = sorted(a, reverse=True)
m1, m2 = b[0], b[1]
for i in range(n):
  if max_a_num == 1:
    if a[i] == m1:
      print(m2)
    else:
      print(m1)
  else:
    print(m2)
import math
import queue
from collections import deque,defaultdict
import heapq
from sys import stdin,setrecursionlimit
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
input = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(input())
    a = [0]+list(map(int,input().split()))+[0]
    lc = [0 for i in range(n)]
    sum = abs(a[0]-a[1])
    for i in range(n):
        lc[i] = abs(a[i]-a[i+1])+abs(a[i+1]-a[i+2])-abs(a[i]-a[i+2])
        sum += abs(a[i+1]-a[i+2])
    for i in range(n):
        print(sum-lc[i])



if __name__ == '__main__':
    main()


### FIXED CODE ###

import math
import queue
from collections import deque,defaultdict
import heapq
from sys import stdin,setrecursionlimit
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
input = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(input())
    a = [0]+list(map(int,input().split()))+[0]
    lc = [0 for i in range(n)]
    sum = abs(a[0]-a[1])
    for i in range(n):
        lc[i] = abs(a[i]-a[i+1])+abs(a[i+1]-a[i+2])-abs(a[i]-a[i+2])
        sum += abs(a[i+1]-a[i+2])
    for i in range(n):
        print(sum-lc[i])



if __name__ == '__main__':
    main()
S=str(input())

if S.count('R')==0
  print(0)
if S.count('R')==1
  print(1)
if S.count('R')==2 and not moji.count('RR') ==1
  print(1)
if S.count('RR')==1
  print(2)
if S.count('RRR')==1
  print(3)
  

### FIXED CODE ###

S=str(input())
 
if S.count('R')==0:
  print(0)
if S.count('R')==1 :
  print(1)
if S.count('R')==2 and not S.count('RR') ==1:
  print(1)
if S.count('RR')==1 and not S.count('RRR')==1:
  print(2)
if S.count('RRR')==1:
  print(3)
n=int(input())
a=list(map(int, input().split()))
pos=[]
nega=[]
for i in range(n):
    if a[i]>=0:
        pos.append(a[i])
    else:
        nega.append(a[i])
if len(nega)%2==0:
    print(sum(pos)-sum(nega))
else:
    if min(pos)>-max(nega):
        print(sum(pos)-sum(nega)+max(nega)*2)
    else:
        print(sum(pos)-sum(nega)-min(pos)*2)
        

### FIXED CODE ###

n=int(input())
a=list(map(int, input().split()))
pos=[]
nega=[]

for i in range(n):
    if a[i]>=0:
        pos.append(a[i])
    else:
        nega.append(a[i])
if len(pos)==0:
    if len(nega)%2==0:
        print(abs(sum(a)))
    else:
        print(abs(sum(a))+max(a)*2)
elif len(nega)==0:
    print(sum(a))
elif len(nega)%2==0:
    print(sum(pos)-sum(nega))
else:
    if min(pos)>-max(nega):
        print(sum(pos)-sum(nega)+max(nega)*2)
    else:
        print(sum(pos)-sum(nega)-min(pos)*2)
N=int(input())
A=[]
for i in range(N):
    A.append(int(input()))

a=A.copy()
A.sort()
dic={}
for i in range(0,N):
    dic[a[i]]=0
    dic[a[i]]=i

ans=0
for i in range(0,N):
    if i%2==1:
        if dic[A[i]]%2==0:
            ans+=1

print(ans)

### FIXED CODE ###

import copy

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

a=copy.copy(A)
A.sort()
dic={}
for i in range(0,N):
    dic[a[i]]=0
    dic[a[i]]=i

ans=0
for i in range(0,N):
    if i%2==1:
        if dic[A[i]]%2==0:
            ans+=1

print(ans)
s = input()
if s == 'A':
    ans = 'T'
elif s== 'T':
    ans = 'A'
elif s == G:
    ans = 'C'
elif s == C:
    ans = 'G'
else:
    print("error")
    
print(ans)

### FIXED CODE ###

s = input()
if s == 'A':
    ans = 'T'
elif s== 'T':
    ans = 'A'
elif s == 'G':
    ans = 'C'
elif s == 'C':
    ans = 'G'
else:
    print("error")
    
print(ans)
s = input()
if s == 'AAA' or s == 'BBB':
  print(No)
else:
  print(Yes)

### FIXED CODE ###

s = input()
if s == 'AAA' or s == 'BBB':
  print('No')
else:
  print('Yes')
r, g, b = map(int, raw_input().split())
num = r * 100 + g * 10 + b
if(num % 4 == 0):
    print("Yes")
else:
    print("No")


### FIXED CODE ###

r, g, b = map(int, input().split())
num = r * 100 + g * 10 + b
if(num % 4 == 0):
    print("YES")
else:
    print("NO")
n = int(input())
s = [int(input()) for _ in range(n)]

sumNum = sum(s)
if sumNum % 10 != 0:
  print(sumNum)
  exit()

t = 0
for i in s:
  if (sumNum - i)%10 != 0:
    t = max(t, sum-i)
print(t)

### FIXED CODE ###

n = int(input())
s = [int(input()) for _ in range(n)]

sumNum = sum(s)
if sumNum % 10 != 0:
  print(sumNum)
  exit()

t = 0
for i in s:
  if (sumNum - i)%10 != 0:
    t = max(t, sumNum-i)
print(t)
def htemp(t, x):
        return float(t - 0.006 * x)
     
    input()
    lt, la = [int(x) for x in input().split()]
    h_ary = [int(x) for x in input().split()]
     
    maxdiff = float('inf')
    goodpoint = 0
    for i, h in enumerate(h_ary):
        diff = abs(la - htemp(lt, h))
        if diff < maxdiff:
            maxdiff = diff
            goodpoint = i
    print(goodpoint+1)

### FIXED CODE ###

def htemp(t, x):
    return float(t - 0.006 * x)
    
input()
lt, la = [int(x) for x in input().split()]
h_ary = [int(x) for x in input().split()]
    
maxdiff = float('inf')
goodpoint = 0
for i, h in enumerate(h_ary):
    diff = abs(la - htemp(lt, h))
    if diff < maxdiff:
        maxdiff = diff
        goodpoint = i
print(goodpoint+1)
n = int(input())
a = input().split()
b = 0
c = 0
while True:
    b = min(a) / 2
    if b <= 1:
        break
    c = c + 1
print()

### FIXED CODE ###

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

def count(A, n):
    for i in range(n):
        if (A[i] % 2 == 1) or (A[i] == 0):
            return False
        A[i] = A[i] // 2
    return True

while True:
    if count(A, n):
        s += 1
    else:
        break
    
print(s)
import math
import sys
def lcm(a, b):
    return a*b // math.gcd(a, b)

input = sys.stdin.readline
N = int(input())
print(lcm(2, N))

### FIXED CODE ###

from fractions import gcd
#最小公倍数
def lcm(a, b):
    return a*b // gcd(a, b)

import sys
input = sys.stdin.readline
N = int(input())
print(lcm(2, N))
a, b, c = list(map(int, input().split))
 
if a + b >= c:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

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

if a + b >= c:
    print('Yes')
else:
    print('No')
N = int(input())
A = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[2],reverse=True)
for x in range(101):
    for y in range(101):
        a,b,h = A[0]
        H = h+abs(x-a)+abs(y-b)
        flag = 1
        for i in range(1,N):
            a,b,h = A[i]
            if H==h+abs(x-a)+abs(y-b):continue
            else:
                flag = 0
                break
        if flag==1:
            cx = x
            cy = y
            break
    if flag==1:break
print(cx,cy,H)

### FIXED CODE ###

N = int(input())
D = [tuple(map(int,input().split())) for _ in range(N)]
D = sorted(D,key=lambda x:x[2], reverse=True)
for cx in range(101):
    for cy in range(101):
        ind = 1
        x,y,h = D[0]
        H = abs(x-cx)+abs(y-cy)+h
        for i in range(1,N):
            x,y,h = D[i]
            if h>0 and abs(x-cx)+abs(y-cy)+h!=H:
                ind = 0
                break
            elif h==0 and abs(x-cx)+abs(y-cy)<H:
                ind = 0
                break
        if ind==1:
            CX = cx
            CY = cy
            break
    if ind==1:break
print(CX,CY,H)
N, X = map(int, input().split())
X_list = list(map(int, input().split()))
X_list.append(X)
X_list.sort()
kyori_list = []
for i, x in enumerate(X_list):
    if i == len(X_list) - 1:
        break
    kyori_list.append(X_list[i + 1] - x)

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)


print(gcd(*kyori_list))
# print(X_list)

### FIXED CODE ###

N, X = map(int, input().split())
X_list = list(map(int, input().split()))
X_list.append(X)
X_list.sort()
kyori_list = []
for i, x in enumerate(X_list):
    if i == len(X_list) - 1:
        break
    kyori_list.append(X_list[i + 1] - x)

import fractions
from functools import reduce


def gcd_list(*numbers):
    return reduce(fractions.gcd, numbers)


print(gcd_list(*kyori_list))
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=[int(input()) for i in range(n)]
    light=0
    cnt=0
    while True:
        if l[light]==2:
            cnt+=1
            print(cnt)
            break
        else:
            if cnt>n:
                print(-1)
                break
            else:
                light=l[light]-1
                cnt+=1
            
resolve()


### FIXED CODE ###

def resolve():
    x,a,b=map(int, input().split())
    if b-a>=x+1:
        print('dangerous')
    elif b-a<=0:
        print('delicious')
    else:
        print('safe')
resolve()
a, b = map(int, input().split())
if(1 <= a <= 9 and 1 <= b <= 9):
  print(a * b)
else
print(-1)

### FIXED CODE ###

a, b = map(int, input().split())
if(1 <= a <= 9 and 1 <= b <= 9):
  print(a * b)
else:
  print(-1)
from collections import Counter

n=int(input())
s=[Counter(input()) for _ in range(n)]

c = counter[0]
#各アルファベット(a,b,c,...,z)に対して，使用回数の最小値を求める
c = s[0]
for i in range(1,n):
    for k,v in c.items():
        c[k] = min(s[i][k], c[k])
        
c = sorted(c.items())
ans = ''
for k,v in c:
    ans += k*v
print(ans)


### FIXED CODE ###

from collections import Counter
n=int(input())
s=Counter(input())
for i in range(n-1):
    s&=Counter(input())
print(''.join(sorted(s.elements())))
x = input()

y = x**3

print int(y)

### FIXED CODE ###

x = input()

y = x**3

print int(y)
def main():
    x, y = map(int, input().split())
    print(min(max(x+y, y-x+2), abs(x+y)+1)
if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    x, y = map(int, input().split())
    print(min(abs(x+y), abs(~x+y))+1)
if __name__ == '__main__':
    main()
print((int(input()-2)*180)

### FIXED CODE ###

print((int(input())-2)*180)
import math
from functools import reduce


def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)


def lcm(numbers):
    return reduce(lcm_base, numbers, 1)


n = int(input())
a_list = list(map(int, input().split(" ")))

max_iter = lcm(a_list)
# print(max_iter)

max_val = -1

for i in range(max_iter + 1):
    # print("===============")
    # print("Max val = {}, i = {}".format(max_val, i))
    val = sum([i % a for a in a_list])
    max_val = max(max_val, val)

print(max_val)


### FIXED CODE ###

n = int(input())
a_list = list(map(int, input().split(" ")))
a_list = [ a - 1 for a in a_list]
print(sum(a_list))
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
import numpy as np
from heapq import heappop, heappush
 
H,W = map(int,readline().split())
grid = np.full((H+2,W+2),b'#',dtype='S1')
grid[1:-1,1:-1] = np.frombuffer(read(),'S1').reshape(H,-1)[:,:W]
INF = 400
def shortest(grid, start, cost=0):
    dist = np.array([[INF for _ in range(W+2)] for _ in range(H+2)])
    dx = [-1, 0, 1, 0]
    dy = [0, 1, 0, -1]
    st = [(cost, start)]
    dist[start[0]][start[1]]=0
    while(st):
        c, [sx, sy] = heappop(st)
        for a, b in zip(dx, dy):
            x = sx + a
            y = sy + b
            if grid[x][y]==b'#':
              continue
            dxy = dist[sx][sy] + 1
            if dist[x][y] <= dxy:
                continue
            dist[x][y] = dxy
            heappush(st, (dist[x][y], [x, y]))
    return dist

m=0
for i in range(1,H+1):
  for j in range(1,W+1):
    if grid[i,j]==b'#':
      continue
    res=shortest(grid, [3,1], cost=0)[1:-1,1:-1]
    res[res==400]=0
    tm=np.max(res)
    if m < tm:
      m=tm
print(m)

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
import numpy as np
from heapq import heappop, heappush
 
H,W = map(int,readline().split())
grid = np.full((H+2,W+2),b'#',dtype='S1')
grid[1:-1,1:-1] = np.frombuffer(read(),'S1').reshape(H,-1)[:,:W]
INF = 400
def shortest(grid, start, cost=0):
    dist = np.array([[INF for _ in range(W+2)] for _ in range(H+2)])
    dx = [-1, 0, 1, 0]
    dy = [0, 1, 0, -1]
    st = [(cost, start)]
    dist[start[0]][start[1]]=0
    while(st):
        c, [sx, sy] = heappop(st)
        for a, b in zip(dx, dy):
            x = sx + a
            y = sy + b
            if grid[x][y]==b'#':
              continue
            dxy = dist[sx][sy] + 1
            if dist[x][y] <= dxy:
                continue
            dist[x][y] = dxy
            heappush(st, (dist[x][y], [x, y]))
    return dist

m=0
for i in range(1,H+1):
  for j in range(1,W+1):
    if grid[i,j]==b'#':
      continue
    res=shortest(grid, [i,j], cost=0)[1:-1,1:-1]
    res[res==400]=0
    tm=np.max(res)
    if m < tm:
      m=tm
print(m)
dp=[0]+[1<<20]*10000
n=int(input())
for i in range(1,n):
    a=int(input())
    for j in range(i//2+1):
        dp[j],dp[i-j]=map(min,[(dp[j],dp[i-j]+a),(dp[i-j],dp[j]+a)])
print(dp[n//2])
exit()

### FIXED CODE ###

dp=[0]+[1<<20]*10000
n=int(input())
for i in range(1,n):
    a=int(input())
    for j in range(i//2+1):
        if dp[j]>dp[i-j]+a:dp[j]=dp[i-j]+a
        if dp[i-j]>dp[j]+a:dp[i-j]=dp[j]+a
print(dp[n//2])
from operator import itemgetter
from collections import Counter


def solve(string):
    n, k, *td = map(int, string.split())
    dic = {i: [] for i in range(1, n + 1)}
    td = sorted([(t, d) for t, d in zip(td[::2], td[1::2])], key=itemgetter(1), reverse=True)
    for t, d in td:
        dic[t].append(d)
    base = td[:k]
    counts = Counter([_b[0] for _b in base])
    v = set(counts.keys())
    start_v = len(v)
    max_v = min(len(set(td[::2])), k)

    candidates = []
    for _td in td[k:]:
        if _td[0] not in v:
            candidates.append(_td)
            v.add(_td[0])

    ans = sum([_b[1] for _b in base]) + start_v**2
    index = -1
    tmp = ans
    for i in range(max_v - start_v):
        while counts[base[index][0]] == 1:
            index -= 1
        _t, _d = base[index]
        counts[_t] -= 1
        tmp = tmp - _d + candidates[i][1] + 2 * (start_v + i + 1) - 1
        ans = max(tmp, ans)

    return str(ans)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))


### FIXED CODE ###

def solve(string):
    n, k, *td = map(int, string.split())
    td = sorted([(t, d) for t, d in zip(td[::2], td[1::2])], key=lambda x: x[1], reverse=True)
    max_variety = len(set([c[0] for c in td]))
    choice = td[:k]
    count = [0] * n
    r = []
    for _c in choice:
        if count[_c[0] - 1] > 0:
            r.append(_c[1])
        count[_c[0] - 1] += 1
    variety = set([c[0] for c in choice])
    ans = [len(variety)**2 + sum([c[1] for c in choice])]
    i_append = k
    while len(variety) < min(max_variety, k):
        while td[i_append][0] in variety:
            i_append += 1
        variety.add(td[i_append][0])
        ans.append(ans[-1] - r.pop() + td[i_append][1] + 2 * len(variety) - 1)
    return str(max(ans))


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))
n,k = map(int,input().split())
print(min(n%k,abs(k-n%k)))

### FIXED CODE ###

#ab,ac
a,b,c = map(int,input().split())
a,b = b,a
a,c = c,a
print(a,b,c)
result = x**3
return result

### FIXED CODE ###

x = raw_input()
print int(x)**3
n = int(input())
k = int(input())
if n>=10:
    print("k")
else:
    print("k+(100*(10-n))")

### FIXED CODE ###

n,k = map(int,input().split())
if n >= 10:
    print(k)
else:
    print(k+(100*(10-n)))
stk = []
for c in input().split():
    if c in "+-*":
        a = stk.pop()
        b = stk.pop()
        stk.append(str(eval(b + c + a)))
    else:
        stk.append(c)
print(stk.pop(


### FIXED CODE ###

stak = []
for i in input().split():
    if i in "+-*":
        x = stak.pop()
        y = stak.pop()
        stak.append(str(eval(y + i + x)))
    else:
        stak.append(i)
print(stak.pop())
def fib(x):
  if x==0:
    return 0
  elif x==1 or x==2:
  	return 1
  else:
  	return fib(x-2)+fib(x-1)

N,M=(int(x) for xin input().split())
a=[int(input()) for i in range(M)]
x=1
for i in range(1,M):
  x*=fib(a[i]-a[i-1])

print (a%((10e+9)+7))

### FIXED CODE ###

N,M=(int(x) for x in input().split())
a=[int(input()) for i in range(M)]

x=[0]*(N+1)
j=0
if N!=0:
    x[0]=1
if N>1 and M!= 0 and a[0]==1:
    j+=1
else:
    x[1]=1

for i in range(2,N+1): 
    if j==M or i!=a[j]:
        x[i]=x[i-1]+x[i-2]
    else:
        x[i]=0
        j+=1
print(int(x[N]%(1000000007)))
mod = 998244353
S = input()
N = len(S)
Sum = [0]*(N+1)
for i in range(1, N+1):
    Sum[i] = Sum[i-1]+int(S[i-1])
from functools import lru_cache

@lru_cache(maxsize=1000)
def dp(i, j):
    n = min(i+j+1, N)
    if i+j == N*2:
        return 1
    res = 0
    s = Sum[n]
    if i<s:
        res+=dp(i+1, j)
    if j<2*n-s:
        res+=dp(i, j+1)
    return res%mod
print(dp(0, 0))

### FIXED CODE ###

mod = 998244353
import sys
sys.setrecursionlimit(10**9)
S = input()
N = len(S)
Sum = [0]*(N+1)
for i in range(1, N+1):
    Sum[i] = Sum[i-1]+int(S[i-1])
dp = [[0]*(N*2+1) for _ in range(N*2+1)]
for i in range(N*2+1)[::-1]:
    for j in range(N*2+1)[::-1]:
        if i+j == N*2:
            dp[i][j] = 1
            continue
        n = min(i+j+1, N)
        s = Sum[n]
        if i<s:
            dp[i][j]+=dp[i+1][j]
        if 2*n-s>j:
            dp[i][j]+=dp[i][j+1]
        dp[i][j]%=mod
print(dp[0][0])