Harryxun/stf_run huggingface dataset:
tmp =input().split()
H,W,D=int(tmp[0]),int(tmp[1]),int(tmp[2])

list = [[0 for x in range(W)] for y in range(H)]
dict = {}
for i in range(H):
    tmp = input().split()
    for d in range(W):
        dict[tmp[d]] = str(i)+' '+str(d)
result ={}
cost ={}

def calcost(L,R,D):
    if int(R)<=D:
        cost[R] = 0
        return 0
    else:
        posi1 = dict[R].split()
        posi2 = dict[str(int(R)-D)].split()
        costs = abs(int(posi2[0])-int(posi1[0])) + abs(int(posi2[1])-int(posi1[1]))
        if str(int(R)-D) in cost:
            cost[R] = costs + cost[str(int(R)-D)]
            return cost[R]
        else:
            cost[R] = costs + calcost(L,str(int(R)-D),D)
            return cost[R]

for n in range(D+1,H*W+1):
    calcost(str(1),str(n),D)

Q = int(input())
for j in range(Q):
    tmpx = input()
    if tmpx in result:
        print(result[tmpx])
    else:
        tmp = tmpx.split()
        result[tmpx] = cost[tmp[1]]-cost[tmp[0]]
        print(result[tmpx])

### FIXED CODE ###

tmp =input().split()
H,W,D=int(tmp[0]),int(tmp[1]),int(tmp[2])

list = [[0 for x in range(W)] for y in range(H)]
dictx ={}
dicty ={}
for i in range(H):
    tmp = input().split()
    for d in range(W):
        dictx[tmp[d]] = i
        dicty[tmp[d]] = d
cost ={}
def calcost(R):
    if int(R)<=D:
        cost[R] = 0
        return 0
    else:
        costs = abs(dictx[R]-dictx[str(int(R)-D)]) + abs(dicty[R]-dicty[str(int(R)-D)])
        cost[R] = costs + cost[str(int(R)-D)]
        return cost[R]

for n in range(1,H*W+1):
    calcost(str(n))
Q = int(input())
for j in range(Q):
    tmp = input().split()
    print(str(cost[tmp[1]]-cost[tmp[0]]))
N,Q=map(int,input().split())
G=[list(map(int,input().split())) for _ in range(N-1)]
P=[list(map(int,input().split())) for _ in range(Q)]

gr=[[]]*N
for i in G:
    v=i[0]
    gr[v-1]=[*gr[v-1],i[1]]

cnt=[0]*N

def dfs(p,x):
    cnt[p-1]+=x
    for n in gr[p-1]:
        dfs(n,x)
    return

for p,x in P:
    dfs(p,x)
print(' '.join(map(str,cnt)))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
 
N, Q = map(int, input().split())
graph = [[] for i in range(N)]
cnt = [0]*N

# 入力しながらグラフを作成
for i in range(N-1):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  graph[a].append(b)
  graph[b].append(a)

# 初期値を設定
for i in range(Q):
  p, x = map(int, input().split())
  cnt[p-1] += x

v = [False]*N

# stack=[]
def dfs(n,prv):
  # stack.append(n)
  if v[n]: return
  cnt[n] += prv
  v[n] = True
  for nv in graph[n]:
    dfs(nv, cnt[n])
   
dfs(0,0)
print(*cnt)
# print(stack)
N = int(input())

if N == 1:
    print(1)
else:
    ans = 1
    i = 1
    while N >= 2 ** i:
        ans += 2 ** i
        i += 1

print(ans)

### FIXED CODE ###

N = int(input())

if N == 1:
    print(1)
else:
    ans = 1
    i = 1
    while N >= 2 ** i:
        ans += 2 ** i
        i += 1
    print(ans)
n, m = map(int, input().split())
h = list(map(int, input().split()))
pairs = [list(map(int, input().split())) for _ in range(m)]

ans = [1] * n

for i in range(m):
    if h[pairs[i][0] - 1] < h[pairs[i][1] - 1]:
        ans[pairs[i][0] - 1] = 0
    elif f h[pairs[i][0] - 1] = h[pairs[i][1] - 1]:
        ans[pairs[i][0] - 1] = 0
        ans[pairs[i][1] - 1] = 0 
    else:
        ans[pairs[i][1] - 1] = 0      

print(sum(ans))

### FIXED CODE ###

n, m = map(int, input().split())
h = list(map(int, input().split()))
pairs = [list(map(int, input().split())) for _ in range(m)]

ans = [1] * n

for i in range(m):
    if h[pairs[i][0] - 1] < h[pairs[i][1] - 1]:
        ans[pairs[i][0] - 1] = 0
    elif h[pairs[i][0] - 1] == h[pairs[i][1] - 1]:
        ans[pairs[i][0] - 1] = 0
        ans[pairs[i][1] - 1] = 0 
    else:
        ans[pairs[i][1] - 1] = 0      

print(sum(ans))
import numpy as np

N, A = map(int,input().split())
X = [int(x) for x in input().split()]
 
dp = np.zeros((N+1,sum(X)+1),dtype=np.int64)
dp[0,0] = 1
 
for x in X:
    dp[1:,x:] += dp[:-1,:-x].copy()
  
ans = 0
for n in range(1,N+1):
    ans += dp[n,n*A]

print(ans)

### FIXED CODE ###

import numpy as np

N, A = map(int,input().split())
X = [int(x) for x in input().split()]
 
dp = np.zeros((N+1,N*A+1),dtype=np.int64)
dp[0,0] = 1
 
for x in X:
    dp[1:,x:] += dp[:-1,:-x].copy()
  
ans = 0
for n in range(1,N+1):
    ans += dp[n,n*A]

print(ans)
x, y, z, k = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))
ab = []
for i in range(len(a)):
    for j in range(len(b)):
        ab.append(a[i]+b[j])
ab.sort(reverse = True)
abc = []
k_1 = min([len(ab), k])
for i in range(k_1):
    for j in range(len(c)):
        abc.append(ab[i]+c[j])
abc.sorat(reverse = True)
for i in range(k):
    print(abc[i])

### FIXED CODE ###

import heapq
import sys
x, y, z, k = map(int, input().split())

a, b, c = (sorted(map(int, sys.stdin.readline().split()), reverse=True) for _ in range(3))

abc = {(0,0,0)}

stu = [[-a[0]-b[0]-c[0], 0,0,0]]
heapq.heapify(stu)
result = []
while k > 0:
    out_p, n, m, l = heapq.heappop(stu)
    if n+1<x and not((n+1,m,l) in abc):
        abc.add((n+1,m,l))
        heapq.heappush(stu, [-a[n+1]-b[m]-c[l], n+1, m, l])
    if m+1<y and not((n,m+1,l) in abc):
        abc.add((n,m+1,l))
        heapq.heappush(stu, [-a[n]-b[m+1]-c[l], n, m+1, l])
    if l+1<z and not((n,m,l+1) in abc):
        abc.add((n,m,l+1))
        heapq.heappush(stu, [-a[n]-b[m]-c[l+1], n, m, l+1])
    result.append(-out_p)
    k -= 1
result.sort(reverse=True)
for i in result:
    print(i)
S = int(input())
h = S // 3600
m = S // 60 -S // 3600
s = S // 60
print(h":"m":"s)
 


### FIXED CODE ###

S = int(input())
h = S//3600
m = (S//60)-60*(S//3600)
s = S%60
print('{}:{}:{}'.format(h,m,s))
import sys
import numpy as np
from fractions import gcd
a, b = [int(i) for i in sys.stdin.readline().split()]
_gcd = gcd(a,b)
memo_ls = np.zeros(_gcd+1)
#memo_set = set()
cnt = 0
if _gcd == 1:
    print(1)
else:
    for i in range(2, _gcd+1):
        if _gcd % i == 0 and memo_ls[i-1] != 1:
            memo_ls[i-1::i] = 1
            cnt += 1
            #memo_set.add(i)
    #print(memo_set)
    print(cnt + 1)

### FIXED CODE ###

import sys
from fractions import gcd
def prime_factorize(n):
    a = set()
    while n % 2 == 0:
        a.add(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.add(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.add(n)
    return a

def main(a, b):
    #a, b = [int(i) for i in sys.stdin.readline().split()]
    _gcd = gcd(a,b)
    #memo_ls = [0 for i in range(_gcd)]
    #memo_set = set()
    cnt = 0
    if _gcd == 1:
        print(1)
    else:
        res = prime_factorize(_gcd)
        print(len(res) + 1)
if __name__ == "__main__":
    a, b = [int(i) for i in sys.stdin.readline().split()]
    main(a, b)
a,b,m=map(int,input().split())
alis=list(map(int,input().split()))
blis=list(map(int,input().split()))
ans=10**18
d=dict()
for i in range(m):
  x,y,c=map(int,input().split())
  x-=1
  y-=1
  d[(x,y)]=c
  ans=min(ans,alis[x]+blis[y]-c)
alis1=[]
blis1=[]
for i in range(a):
  alis1.append((alis[i],i))
for i in range(a):
  blis1.append((blis[i],i))
alis1.sort()
blis1.sort()
if (alis1[0][1],blis1[0][1]) not in d:
  ans=min(ans,alis1[0][0]+blis1[0][0])
print(ans)

### FIXED CODE ###

a,b,m=map(int,input().split())
alis=list(map(int,input().split()))
blis=list(map(int,input().split()))
ans=10**18
d=dict()
for i in range(m):
  x,y,c=map(int,input().split())
  x-=1
  y-=1
  d[(x,y)]=c
  ans=min(ans,alis[x]+blis[y]-c)
alis1=[]
blis1=[]
for i in range(a):
  alis1.append((alis[i],i))
for i in range(b):
  blis1.append((blis[i],i))
alis1.sort()
blis1.sort()
if (alis1[0][1],blis1[0][1]) not in d:
  ans=min(ans,alis1[0][0]+blis1[0][0])
print(ans)
A,P=int(i) for i in input().split()
print((3*A+P)/2)

### FIXED CODE ###

A,P=(int(i) for i in input().split())
print(int((3*A+P)/2))
nums = list(map(int,input().split()))
N = int(nums[0])
K = int(nums[1])
X = int(nums[2])
Y = int(nums[3])

if N > K:
  print(K*X + (N-K)*Y)
else:
  print(N*X)

### FIXED CODE ###

N = int(input())
K = int(input())
X = int(input())
Y = int(input())

if N > K:
  print(K*X + (N-K)*Y)
else:
  print(N*X)
a = list(map(int,input().split()))
if max(a) % sum(a) == 0:
  print((max(a)*3 - sum(a)) // 2)
else:
  print(((max(a)+1)*3 - sum(a)) // 2)

### FIXED CODE ###

a = list(map(int,input().split()))
m = max(a)
s = sum(a)
if (m-s) % 2 == 0:
  print((3*m-s)//2)
else:
  print((3*(m+1)-s)//2)
n = input()
a = list(map(int, input().split()))

min_value=100

for i in a:
    x = 0
    while i % 2 == 0:
        i //= 2
        x += 1
    if min_value > x:
        min_value = x
print(min_value)

### FIXED CODE ###

s = input()
if 'RRR' in s :
    print('3')
elif 'RR' in s :
    print('2')
elif 'R' in s :
    print('1')
else :
    print('0')
import collections
n = int(raw_input())
pts = [map(int , raw_input().split()) for _ in range(n)]
res = -1
def f(pts):
	for cx,cy in [(ii,jj) for ii in range(100+1) for jj in range(100+1)]:	
		H = 10 ** 9 + 1
		cc = collections.Counter()
		H = max([abs(cx - x) + abs(cy - y) for x,y,h in pts if h == 0] or [-float('inf')])
	
		for x,y,h in pts:
			q = abs(cx - x) + abs(cy - y)
			if h:
				Y = h + q
				if Y >= H:
					cc[Y]+=1
		if len(cc) == 1:
			for k in cc:
				return Y,cx,cy

h,x,y = f(pts)

print x,y,h

### FIXED CODE ###

import collections
n = int(raw_input())
pts = [map(int , raw_input().split()) for _ in range(n)]

def f(pts):
	for cx,cy in [(ii,jj) for ii in range(100+1) for jj in range(100+1)]:	
		H = min([abs(cx - x) + abs(cy - y) for x,y,h in pts if h == 0] or [+float('inf')])
		
		cc = collections.Counter()
		for x,y,h in pts:
			q = abs(cx - x) + abs(cy - y)
			if h > 0:
				Y = h + q
				if 1<=Y <= H:
					cc[Y]+=1
				else:
					cc[-1] += 1
		if len(cc) == 1:
			for k in cc:
				if 1<=k <= H:
					return k,cx,cy

h,x,y = f(pts)

print x,y,h
all = list(map(int, input().split()))

N = all[0]
Y = all[1]

check = 0
for i in range(N):
    for j in range(N-i):
        c = (N-(i+j))
        total = 10000*i + 5000*j + 1000*c
        if Y!=total:
            continue
        else:
            yu = i
            hi = j
            no = c
            check += 1
            break
    else:
        continue 
    break

if check==100:
    yu = -2
    hi = -1
    no = -1

print(yu)
print(" ")
print(hi)
print(" ")
print(no)
print(" ")


### FIXED CODE ###

all = list(map(int, input().split()))

N = all[0]
Y = all[1]

yu = -1
hi = -1
no = -1
for i in range(N+1):
    for j in range((N+1)-i):
        c = (N-(i+j))
        total = 10000*i + 5000*j + 1000*c
        if Y==total:
            yu = i
            hi = j
            no = c
            break
        else:
            continue
    else:
        continue 
    break

print(str(yu) + " " + str(hi) + " " + str(no))
S = input()
for i in ['eraser', 'erase', 'dreamer', 'dream']:
    S=S.replace(i, 'R')
print(['NO', 'YES'][len(s) == 1 and 'R' in s])

### FIXED CODE ###

S = input()
for i in ['eraser', 'erase', 'dreamer', 'dream']:
    S=S.replace(i, 'R')
s = set(S)
print(['NO', 'YES'][len(s) == 1 and 'R' in s])
n = int(input())
a = []
sosu = []

def sosuuhantei(x):
    p = x
    if p < 2:
        return false
    elif  n == 2:
        return p
    else:
        for i in range(3,math.floor(math.sqrt(x)) + 1,2):
            if x % i == 0:
                return False
        else:
             return x
            
            
sosulist = []
 
if n < 2:
    None
elif n == 2:
    sosulist.append(2)
else:
    sosulist.append(2)
    for i in range(3,55555+1,2):
        sosulist.append(sosuuhantei(i))
import random
print(random.choices(sosulist,k = 5))
    

### FIXED CODE ###

import math
import random
m = int(input())
n = 10000
def sosuuhantei(x):
    p = x
    if p < 2:
        return false
    elif  n == 2:
        return p
    else:
        for i in range(3,math.floor(math.sqrt(x)) + 1,2):
            if x % i == 0:
                return False
        else:
             return x
sosulist = []
 
if n < 2:
    None
elif n == 2:
    sosulist.append(2)
else:
    sosulist.append(2)
    for i in range(3,n+1,2):
        sosulist.append(sosuuhantei(i))
        
while False in sosulist:
    sosulist.remove(False)

s = []
for i in range(len(sosulist)):
    if sosulist[i] % 5 == 1:
        s.append(sosulist[i])

strs = ''
for i in range(m):
    strs = strs + str(s[i]) + ' '
print(strs)
A, B, C = map(int, input().split())
print(min(A+B, B+C, C+D))

### FIXED CODE ###

A, B, C = map(int, input().split())
print(min(A+B, B+C, C+A))
from collections import deque
a=deque()
b=a.copy()

### FIXED CODE ###

apple,appiece=[int(i) for i in input().split()]
appiece+=3*apple
print(appiece//2)
n = int(input())
s = list(map(int, list(input())))
numbers = [0 for _i in range(1000)]
right, left = [[0 for _j in range(10)] for _i in range(n)], [[0 for _j in range(10)] for _i in range(n)]
for i in range(1, n):
    left[i] = left[i-1].copy()
    left[i][s[i-1]] += 1
for i in range(2, n+1):
    right[-i] = right[-i+1].copy()
    right[-i][s[-i+1]] += 1

for i in range(n):
    for x in range(10):
        for y in range(10):
            if right[i][x]>0 and left[i][y]>0:
                numbers[100*x+10*s[i]+y] = 1
print(sum(numbers))

### FIXED CODE ###

n = int(input())
s = list(input())[::-1]
result = 0
for i in range(1000):
    x = format(i, "03")
    j = 0
    p = 0
    while p < n:
        if s[p]==x[j]:
            j += 1
            if j == 3:
                result += 1
                break
        p += 1

print(result)
from collections import Counter
import math
A,B,C,D= map(int, input().split())
AC = (A-1)//C
AD = (A-1)//D
ACD =(A-1)//(C*D//math.gcd(C,D))
ans1 = A -1-AC -AD + ACD
BC = B//C
BD = B//D
BCD = B//(C*D//math.gcd(C,D))
ans2 = B - BC - BD +BCD
print(ans2-ans1)

### FIXED CODE ###

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
A,B,C,D= map(int, input().split())
AC = (A-1)//C
AD = (A-1)//D
ACD =(A-1)//(C*D//gcd(C,D))
ans1 = A -1-AC -AD + ACD
BC = B//C
BD = B//D
BCD = B//(C*D//gcd(C,D))
ans2 = B - BC - BD +BCD
print(ans2-ans1)
a=input()
m=a.split()
N=int(m[0])
M=int(m[2])
if N==M:
  print 'Yes'
else:
  print 'No'


### FIXED CODE ###

a=raw_input()
m=a.split()
N,M=map(int,m)
if N==M:
  print 'Yes'
else:
  print 'No'
def start_pos():
    for r in range(H):
        for c in range(W):
            if a[r][c] == 'S':
                return r, c
    return -1, -1


def shortest_len(y, x):
    return min(y, H - 1 - y, x, W - 1 - x)


def dfs(y, x, k):
    global need_len
    if not(0 <= y < H and 0 <= x < W): return
    if a[y][x] == '#': return
    need_len = min(need_len, shortest_len(y, x))
    if k == 0: return
    for dy, dx in (-1, 0), (1, 0), (0, -1), (0, 1):
        dfs(y + dy, x + dx, k - 1)


H, W, K = map(int, input().split())
a = [input() for _ in range(H)]
sy, sx = start_pos()
need_len = shortest_len(sy, sx)
dfs(sy, sx, K)

print(1 + (need_len + K - 1) // K)

'''
最初の魔法で、K回移動で到達できる範囲で、最も壁に近い場所まで移動する
以後、魔法を使用する毎に壁までの最短距離をKずつ移動する
壁に到達したら終了
'''


### FIXED CODE ###

# https://beta.atcoder.jp/contests/agc014/submissions/1268295
from collections import deque

dr = (0, 1, 0, -1)
dc = (1, 0, -1, 0)


def solve():
    H, W, K = map(int, input().split())
    a = [[False for _ in range(W)] for _ in range(H)]

    sy, sx = -1, -1
    for r in range(H):
        s = input()
        for c, x in enumerate(s):
            if x == '.':
                a[r][c] = True
            elif x == 'S':
                a[r][c] = True
                sy, sx = r, c

    visited = [[False for _ in range(W)] for _ in range(H)]
    visited[sy][sx] = True

    t = max(H, W)
    q = deque([(sy, sx, 0)])
    while q:
        r, c, k = q.popleft()

        t = min(t, r, H - 1 - r, c, W - 1 - c)
        # print(t)
        if t == 0:
            print(1)
            return

        for d_i in range(4):
            nr, nc = r + dr[d_i], c + dc[d_i]
            if 0 <= nr < H and 0 <= nc < W and a[nr][nc] and not visited[nr][nc] and k + 1 <= K:
                visited[nr][nc] = True
                q.append((nr, nc, k + 1))

    ans = 1 + (t + K - 1) // K

    print(ans)


if __name__ == '__main__':
    solve()
ubkookoookyfyut

### FIXED CODE ###

a = int(input())
print(a+a*a+a*a*a)
a = int(input())
import math
b = math.sqrt(a)
c = math.floor(b)
d = c**2
print(d)

### FIXED CODE ###

a = input()
b = input()
if a[0]==b[2] and a[1]==b[1] and a[2]==b[0]:
  print("YES")
else:
  print("NO")
a = input()
if a = 'AAA' or b = 'BBB':
  print('Yes')
else:
  print('No')

### FIXED CODE ###

a = input()
if a == 'AAA' or a == 'BBB':
  print('No')
else:
  print('Yes')
s = str(input())
a = s.count(a)
b = s.count(b)
c = s.count(c)
if a == b == c == 1:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

s = str(input())
a = s.count('a')
b = s.count('b')
c = s.count('c')
if a == b == c == 1:
  print('Yes')
else:
  print('No')
def main():
    N = int(input())
    A = list(map(int, input().split()))

    A.sort()
    i = 1
    j = N - 1
    x = sum(A)
    while j > 0:
        if (x - A[j]) * 2 >= A[j]:
            i += 1
        else:
            break
        x -= A[j]
        j -= 1
    print(str(i))

main()

### FIXED CODE ###

def main():
    N, C, K = map(int, input().split())
    i = 0
    T = []
    while i < N:
        T.append(int(input()))
        i += 1
    T.sort()
    T.reverse()

    c = 1
    i = 1
    bus = 1
    time = T[0]
    while i < N:
        if time - T[i] > K or c == C:
            bus += 1
            c = 1
            time = T[i]
        elif time - T[i] <= K:
            c += 1
        i += 1

    print(str(bus))

main()
n,m = map (int,input().split())
a = [0] * n
b = [0] * n
box = [0] * n
for i in range(n):
    a[i],b[i] = map(int,input().split())
    box[i] = [a[i],b[i]]
box.sort(key = lambda x:x[0])
s = 0
ans = 0
while m >= 0:
    m -= box[s][1]
    ans += box[s][0] * box[s][1]
    s += 1
    
print(ans - (-m) * box[s - 1][0])


### FIXED CODE ###

import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
#N = I()
#A = [LI() for _ in range(N)]


n,m = map (int,input().split())
a = [0] * n
b = [0] * n
box = [0] * n
for i in range(n):
    a[i],b[i] = map(int,input().split())
    box[i] = [a[i],b[i]]
box.sort(key = lambda x:x[0])
s = 0
ans = 0
while m > 0:
    
    m -= box[s][1]
    ans += box[s][0] * box[s][1]
    s += 1

print(ans - (-m) * box[s - 1][0])
#ABC116D-VariousSushi.py

from sys import stdin
from numpy import sum

input = stdin.readline

N, K = [int(n) for n in input().split()]
INPUT = [[None for i in range(2)] for j in range(N)]
List1, List2 = [], []
kind1 = []
flag1 = 0

for i in range(N):
    INPUT[i][0], INPUT[i][1] = [int(m) for m in input().split()]

INPUT = sorted(INPUT, key = lambda x: x[1], reverse=True)

for i in range(N):
    if INPUT[i][0] not in kind1:
            List1.append([INPUT[i][1], 1])
            kind1.append(INPUT[i][0])
    else: List1.append([INPUT[i][1], 0])

List2 = List1[K:]
List2.sort(key =lambda x : (x[1],x[0]))
del List1[K:]
List1 = sorted(List1, key = lambda x : (x[1], x[0]), reverse=True)

sum = sum(List1, axis = 0)

Score = sum[0] + sum[1]**2
Test = Score
lenList2 = len(List2)
kindnumber = sum[1]

for i in range(lenList2):
    if List2[-1][1] == 0 or List1[-1] == 1:
        break
    Test = Test - List1.pop()[0] + List2.pop()[0] + 2 * kindnumber + 1
    kindnumber = kindnumber + 1
    if Test >= Score:
        Score = Test
    i = i - 1

print(int(Score))


### FIXED CODE ###

#ABC116D-VariousSushi.py

from sys import stdin
#from numpy import sum

input = stdin.readline

N, K = list(map(int, input().split()))
List1= []
kind = set()
point1, point2 = 0, 0

INPUT = [tuple(map(int, input().split())) for _ in range(N)]

INPUT.sort(key = lambda x: -x[1])

for ti, di in INPUT[:K]:
    point1 += di
    if ti in kind:
        List1.append(di)
    kind.add(ti)

point2 = len(kind)

Score = point1 + point2**2
Test = Score

List1POP = List1.pop

for ti, di in INPUT[K:]:
    if 0 >= len(List1):
        break
    if ti in kind:
        continue
    Test = Test - List1POP() + di + 2 * point2 + 1
    point2 += 1
    kind.add(ti)
    Score = max(Score, Test)

print(Score)
D=input()
if D==25:
  print("Christmas")
  elif D==24:
    print("Christmas Eve")
    elif D==23:
      print("Christmas Eve Eve")
      elif D==22:
        print("Christmas Eve Eve Eve")
        

### FIXED CODE ###

D=int(input())
if D==25:
  print("Christmas")
elif D==24:
  print("Christmas Eve")
elif D==23:
  print("Christmas Eve Eve")
elif D==22:
  print("Christmas Eve Eve Eve")
=input().split()
n=[int(i) for i in n]
h=[n[1]]
for i in range(n[0]):
    h[i]=int(input())
h.sort()

q=-1
for i in range(len(h)):
    a=h[i+n[1]-1]-h[i]
    if q==-1 or q>a:
        q=a
    if q==0:
        break
print(q)

### FIXED CODE ###

n=input().split()
n=[int(i) for i in n]
h=[0]*n[0]
for i in range(n[0]):
    h[i]=int(input())
h.sort()
q=-1
for i in range(0,len(h)-n[1]+1):
    a=h[i+n[1]-1]-h[i]
    if q==-1 or q>a:
        q=a
print(q)
n,m=map(int,input().split())
s=input()
t=input()

def gcd(x,y):
  r=x%y
  return gcd(y,r) if r else y
#最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

L=lcm(n,m)
if s[0]==t[0]:
  X=[""]*(10**5+1)
else:
  print(-1)
  exit()
for i in range(1,n):
  X[int(i*L/n)+1]=s[i]
for i in range(1,m):
  if X[int(i*L/m)+1] !="":
    if X[int(i*L/m)+1] !=t[i]:
      print(-1)
      exit()
print(L)


### FIXED CODE ###

n,m=map(int,input().split())
s=input()
t=input()

def gcd(x,y):
  r=x%y
  return gcd(y,r) if r else y
#最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

L=lcm(n,m)
g=gcd(n,m)
for i in range(g):
  if s[int(i*n/g)]!=t[int(i*m/g)]:
    print(-1)
    exit()
print(L)
a, b = map(int, raw_input().split())
print((a * b), 2 * (a + b))

### FIXED CODE ###

a, b = map(int, raw_input().split())
print ("%d %d" % (a * b, 2 * (a + b)))
# A - Parking

N, A, B = map(int, raw_input().split)

print min(N*A, B)

### FIXED CODE ###

# A - Parking

N, A, B = map(int, raw_input().split())

print min(N*A, B)
ans = 0
kukan = []
max_l = 0
min_r = 10**9
n = int(input())
for i in range(n):
    l,r = map(int, input().split())
    l,r = l-1,r-1
    max_l = max(max_l, l)
    min_r = min(min_r, r)
    kukan.append((l,r))
kukan = list(set(kukan))
kukan.sort()

# maxとminが同じ時は？
# 最大区間を取ってくればいいだけ
min_r_l = None
l,r = kukan.pop()
max_l_r = r
for i in range(len(kukan)):
    if kukan[i][1] == min_r:
        min_r_l = kukan[i][0]
        kukan.pop(i)
        break

if min_r_l is None:
    ans = min_r-max_l+1 + max(r-l+1 for l, r in kukan)
    print(ans)
    exit()

# 累積和
# Lが小さい方からK個取ったときに、残りのRの最小値がほしい
cumsum_r = [float("inf")]
for i in reversed(range(len(kukan))):
    cumsum_r.append(min(cumsum_r[-1], kukan[i][1]))
cumsum_r = cumsum_r[::-1]

# 左 : min_r_l, min_r
# 右 : max_l, max_l_r

for i in range(len(kukan)+1):
    # Lに取らない時
    if i == 0:
        left_l = min_r_l
        right_r = min(max_l_r,cumsum_r[i])
    # 1個以上取る時
    else:
        left_l = max(min_r_l, kukan[i-1][0])
        right_r = min(max_l_r,cumsum_r[i])
    tmp = max(0, min_r-left_l+1) + max(0, right_r-max_l+1)
    ans = max(ans, tmp)

print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)

s = input()
n = len(s) + 1
tmp = [0]*n

def rec(i, prev=None):
    if i == n-1:
        if prev == ">":
            tmp[i] = 0
        else:
            tmp[i] = tmp[i-1]+1
        return tmp[i]
    if prev is None:
        if s[i] == "<":
            tmp[i] = 0
            rec(i+1,prev="<")
        else:
            tmp[i] = rec(i+1,prev=">")+1
    else:
        if s[i] == "<":
            if prev == ">":
                tmp[i] = 0
                rec(i+1,prev="<")
            else:
                tmp[i] = tmp[i-1]+1
                rec(i+1,prev="<")
        else:
            if prev == ">":
                tmp[i] = rec(i+1,prev=s[i])+1
            else:
                tmp[i] = max(tmp[i-1], rec(i+1,s[i]))+1
    return tmp[i]

rec(0)
#print(tmp)
print(sum(tmp))
S=int(raw_input())
print S/3600 + ":" + S/60%60 + ":" + S%60

### FIXED CODE ###

S=int(raw_input())
print str(S/3600) + ":" + str(S/60%60) + ":" + str(S%60)