Harryxun/stf_run huggingface dataset:
import sys
x = sys.stdin.readlines()
a = list(map(int, x[1].strip()))
min_num = min(a)
max_num = max(a)
sum_num = sum(a)
print("{} {} {}".format(min_num, max_num, sum_num))

### FIXED CODE ###

input()
a = list(map(int, input().split()))
print(min(a) ,max(a) ,sum(a))
# -*- coding: utf-8 -*-

n = int(input(n))
a = int(input(a))

print(n*n-a)


### FIXED CODE ###

# -*- coding: utf-8 -*-

n = int(input())
a = int(input())

print(n*n-a)
import sys

input = map(lambda x:x[:-1], sys.stdin.readlines())


n = int(input[0])

input = input[1:]

input = map(lambda x:x.split(' '), input)

for i in range(len(input)):
    input[i] = map(lambda x:int(x), input[i])

print input
A = []
B = []

def a_can_add(e):
    if ((len(A) != 0) and (A[-1] < e)) or len(A) == 0:
        return True    

def b_can_add(e):
    if ((len(B) != 0) and (B[-1] < e)) or len(B) == 0:
        return True

def a_add(e):
    if (len(A) != 0) and (A[-1] < e):
        A.append(e)
    elif len(A) == 0:
        A.append(e)
    else: return False

def b_add(e):
    if len(B) != 0 and (B[-1] < e):
        B.append(e)
    elif len(B) == 0:
        B.append(e)
    else: return False


for i in range(len(input)):
    for j in range(10):
        if a_can_add(input[i][j]):
            a_add(input[i][j])
        elif b_can_add(input[i][j]):
            b_add(input[i][j])
            
    if len(A) + len(B) == 10:
        print "YES"
    else:
        print "NO"

### FIXED CODE ###

N = int(raw_input())

def dfs(depth, l, r):
    if depth == 10:
        return True

    if l < A[depth] and dfs(depth+1, A[depth], r):
        return True
    if r < A[depth] and dfs(depth+1, l, A[depth]):
        return True

    return False

for c in range(N):
    A = map(int, raw_input().split(" "))
    if dfs(0, 0, 0):
        print "YES"
    else:
        print "NO"
import math
a,b,k= [int(i) for i in input().split()]

g=math.gcd(a,b)

cd=list()
i=1
while i<=g:
    if g%i==0:
        cd.append(i)
    i+=1
print (cd[-1*k])




### FIXED CODE ###

import math
import fractions
a,b,k= [int(i) for i in input().split()]

g=fractions.gcd(a,b)

cd=list()
i=1
while i<=g:
    if g % i == 0:
        cd.append(i)
    i+=1
print (cd[ -1 * k ])
n, m, x, y = [ int(v) for v in input().split() ]
xmax = sorted([ int(v) for v in input().split() ] + [x])
ymin = sorted([ int(v) for v in input().split() ] + [y])
ans = "War
if xmax < ymin:
  ans = "No War"
print(ans)

### FIXED CODE ###

n, m, x, y = [ int(v) for v in input().split() ]
xmax = max(sorted([ int(v) for v in input().split() ] + [x]))
ymin = min(sorted([ int(v) for v in input().split() ] + [y]))
ans = "War"
if xmax < ymin:
  ans = "No War"
print(ans)
K, X = map(int, input().split(' '))
  print(*(range((X + 1) - K, (X + K))))

### FIXED CODE ###

# B - One Clue
def main():
  K, X = map(int, input().split(' '))
  print(*(range((X + 1) - K, (X + K))))

if __name__ == "__main__":
    main()
a = list(map(int,input().split()))
a.sort()
print(a[-1])
print(a[-2])
print(a[-3])

### FIXED CODE ###

a = []
for i in range(10):
    a.append(int(input()))
a.sort()
for j in range(3):
    print(a[-(j+1)])
n = int(input())
print(0 if a%1000 == 0 else 1000-a%1000)

### FIXED CODE ###

n = int(input())
print(0 if n%1000 == 0 else 1000-n%1000)
N,K=map(int,input().split())
 
A=[int(i) for i in input().split()]
if K > N or K>30:
    output=""
    for i in range(N):
         output+=(str(N)+" ")
    print(output)
else:
    for _ in range(K):
        A_next =[1 for i in range(N)]
        for i in range(N):
            for j in range(A[i]):
                if (i+j+1) < N:
                    A_next[i+j+1]+=1
                if (i-j-1) >= 0:
                    A_next[i-j-1]+=1
        A=A_next
    output=""
    for i in A_next:
        output+=(str(i)+" ")
    print(output)
        
    
N,K=map(int,input().split())

A=[int(i) for i in input().split()]
if K > N or K>40:
    output=""
    for i in range(N):
         output+=(str(N)+" ")
    print(output)
else:
    for _ in range(K):
        A_next =[1 for i in range(N)]
        for i in range(N):
            for j in range(A[i]):
                if (i+j+1) < N:
                    A_next[i+j+1]+=1
                if (i-j-1) >= 0:
                    A_next[i-j-1]+=1
        A=A_next
    output=""
    for i in A_next:
        output+=(str(i)+" ")
    print(output)
        



### FIXED CODE ###

name = input()
name = name[:3]
print(name)
a,b,c=map(int,input().split())
if a%2==0 or b%2==0:
  print('No')
else:
  print('Yes')

### FIXED CODE ###

a,b=map(int,input().split())
if a%2==0 or b%2==0:
  print('No')
else:
  print('Yes')
pyenv shell 3.8.0
dyld: Library not loaded: /usr/local/opt/libevent/lib/libevent-2.1.6.dylib
  Referenced from: /usr/local/bin/tmux
  Reason: image not found
[2]    51266 abort      tmux
% pyenv shell 3.8.0                                                   ~/Documents/sub-programming/atcoder
pyenv: shell integration not enabled. Run `pyenv init' for instructions.
% python 170a.py                                                      ~/Documents/sub-programming/atcoder
0 2 3 4 5
Traceback (most recent call last):
  File "170a.py", line 3, in <module>
    if h[i] == 0:
IndexError: list index out of range
% python 170a.py                                                      ~/Documents/sub-programming/atcoder
0 2 3 4 5
1
% python                                                              ~/Documents/sub-programming/atcoder
Python 3.8.0 (default, Dec  6 2019, 13:22:27) 
[Clang 8.0.0 (tags/RELEASE_800/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> int(2,1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: int() base must be >= 2 and <= 36, or 0
>>> int(2.1)
2
>>> int(2.4)
2
>>> type(2.1)
<class 'float'>
>>> math.ceil(2.1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'math' is not defined
>>> 1.ceil()
  File "<stdin>", line 1
    1.ceil()
      ^
SyntaxError: invalid syntax
>>> 
KeyboardInterrupt
>>> eix
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'eix' is not defined
>>> exit
Use exit() or Ctrl-D (i.e. EOF) to exit
>>> 
% python 170b.py                                                      ~/Documents/sub-programming/atcoder
  File "170b.py", line 5
    print('Yes'):
                ^
SyntaxError: invalid syntax
% python 170b.py                                                      ~/Documents/sub-programming/atcoder
3 8
Yes
%                                                                     ~/Documents/sub-programming/atcoder

### FIXED CODE ###

import math
x, y = map(int, input().split())
a = (4 * x - y) / 2
if a >= 0 and a <= x and a == math.ceil(a):
    print('Yes')
else:
    print('No')
import sys,collections as cl
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[i]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a

n = int(input())

a = l()

ans = 0
l = 0
r = 0
su = 0
for i in range(N):
	while(r < N and (su^a[r]) == (su + a[r])):
		su += a[r]
		r += 1
	ans += r -i
	if r == i:
		r += 1
	else:
		su -= a[l]
print(ans)

### FIXED CODE ###

import sys,collections as cl
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[i]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a

n = int(input())

a = l()

ans = 0
l = 0
r = 0
su = 0
for i in range(n):
	while(r < n and (su^a[r]) == (su + a[r])):
		su += a[r]
		r += 1
	ans += r - i
	if r == i:
		r += 1
	else:
		su -= a[i]
print(ans)
import math
t = input().split()
t = [int(i) for i in t]
r = math.sqrt(t[0]*t[0]+ t[1]*t[1])
h = t[2]
m = t[3]
if (h == 12):
    h = 0
if (m == 60):
    m = 0
hour_angle = 0.5 * (h * 60 + m) 
minute_angle = 6 * m 
angle = abs(hour_angle - minute_angle) 
angle = min(360 - angle, angle)
print(math.sqrt(r*r - 2*t[0]t[1]*math.cos(angle(2*math.pi/360))))


### FIXED CODE ###

import math
t = input().split()
t = [int(i) for i in t]
r = math.sqrt(t[0]*t[0]+ t[1]*t[1])
h = t[2]
m = t[3]
if (h == 12):
    h = 0
if (m == 60):
    m = 0
hour_angle = 0.5 * (h * 60 + m) 
minute_angle = 6 * m 
angle = abs(hour_angle - minute_angle) 
angle = min(360 - angle, angle)
print(math.sqrt(r*r - 2*t[0]*t[1]*math.cos(angle*(2*math.pi/360))))
a, b = map(int,input().split())
c for i in range(3)

if (a+b)+ i == 0:
  print("No")
else:
  print("Yes")

### FIXED CODE ###

a, b = map(int,input().split())
if (a == 1 and b == 2) or (a == 2 and b == 1) or (a == 2 and b == 2) or (a == 3 and b == 2) or (a == 2 and b == 3):
  print("No")
else:
  print("Yes")
h = int(input())

sum = [0] * (h+1)

#print(sum)

for i in range(1, h+1) :
    sum[i] = 2*sum[i//2] + 1

print(sum[h])

### FIXED CODE ###

h = int(input())

count = 0
while h > 1 :
    h = h // 2
    count += 1

sum = 0
for i in range(count+1) :
    sum = sum + 2**i

print(sum)
class Node:
    def __init__(self, i):
        self.index = i
        self.val = -1
        self.links = 0
        self.nodes = []

def depth_search(node):
    if node.val == -1:
        node.val = c.pop(0)
        for child in node.nodes:
            if child != node:
                depth_search(child)

N = int(input())

nodes = [Node(i) for i in range(N)]
count = [0 for i in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    node_a = nodes[a-1]
    node_b = nodes[b-1]
    node_b.nodes.append(node_a)
    node_a.links += 1
    node_a.nodes.append(node_b)
    node_b.links += 1

c = list(map(int, input().split()))
c = sorted(c, reverse=True)
max_c = max(c)

print(sum(c) - max_c)

depth_search(nodes[0])

for i in range(N-1):
    print(nodes[i].val, end=" ")
print(nodes[-1].val)


### FIXED CODE ###

from collections import deque

class Node:
    def __init__(self):
        self.val = -1
        self.link = []

def main():
    N = int(input())
    nodes = [Node() for i in range(N)]
    for i in range(N-1):
        a, b = map(int, input().split())
        a -= 1; b -= 1;
        nodes[a].link.append(nodes[b])
        nodes[b].link.append(nodes[a])
    c = list(map(int, input().split()))
    c = sorted(c, reverse=True)
    count = 0
    q = deque()
    q.append(nodes[0])
    while len(q) > 0:
        node = q.popleft()
        node.val = c[count]
        count += 1
        for next in node.link:
            if next.val == -1:
                q.append(next)
    print(sum(c) - c[0])
    for i in range(N):
        print(nodes[i].val, end="")
        if i != N-1:
            print(" ",end="")
        else:
            print()

if __name__ == "__main__":
    main()
While True:
    array = input().split(" ")
    a = int(array[0])
    op = array[1]
    b = int(input())

    if op == "?":
        break
    elif op == "+":
        print(a + b)
    elif op == "-":
        print(a - b)
    elif op == "*":
        print(a * b)
    elif op == "/"
        print(a / b)
    

### FIXED CODE ###

while True:
    a, op, b = input().split(" ")
    if op == "?":
        break
    elif op == "+":
        print( int(a) + int(b) )
    elif op == "-":
        print( int(a) - int(b) )
    elif op == "*":
        print( int(a) * int(b) )
    elif op == "/":
        print( int(a) // int(b) )
A,op,B = input().split
A = int(A)
B = int(B)
if op=="+":
    print(A+B)
else:
    print(A-B)


### FIXED CODE ###

A,op,B = input().split()
A = int(A)
B = int(B)
if op=="+":
    print(A+B)
else:
    print(A-B)
X,Y=map(int,input().split())
mod=10**9+7
"""2a+b=X "2b+a=Yを満たすabの並び替え"""
###a+b=(X+Y)/3,a-b=X-Y
###a,b>=0 かつ X+Y(mod3)==0
if (X+Y)%3!=0:
    print("0")##immposible
else:
    a=((X+Y)//3+(X-Y))/2
    b=((X+Y)//3-(X-Y))/2
    ###(a+b)combination a!
    a=min(a,b)
    b=max(a,b)
    c=1
    d=1
    if a>0 and b>=0:
        for i in range(a):
            c*=(a+b-i)
            c=c%mod
            d*=(i+1)
            d=d%mod
        print((c*pow(d,mod-2,mod))%mod)
    elif a==0 and b>0:
        for i in range(b):
            c*=(b-i)
            c=c%mod
            print(c)
    else:
        print("0")

### FIXED CODE ###

X,Y=map(int,input().split())
mod=10**9+7
"""2a+b=X 2b+a=Yを満たすabの並び替え"""
###a+b=(X+Y)/3,a-b=X-Y
###a,b>=0 かつ X+Y(mod3)==0
if (X+Y)%3!=0:
    print("0")##immposible
else:
    a=min(((X+Y)//3+(X-Y))//2,((X+Y)//3-(X-Y))//2)
    b=max(((X+Y)//3+(X-Y))//2,((X+Y)//3-(X-Y))//2)
    ###(a+b)combination a
    c=1
    d=1
    if a>0 and b>=0:
        for i in range(a):
            c*=(a+b-i)
            c=c%mod
            d*=(i+1)
            d=d%mod
        print((c*pow(d,mod-2,mod))%mod)
    elif a==0 and b>0:
        print("1")
    else:
        print("0")
l=[]
t=int(input())
b=0
c=0
for i in range(t):
    a=int(input())
    if(a>b):
        b=a
    else if(b>a and a>c):
        c=a
    l.append(a)
for i in range(0,t):
    if(l[i]!=b):
        print(b)
    else:
        print(c)

### FIXED CODE ###

t=int(input())
l=[]
b=0
c=0
for j in range(t):
    a=int(input())
    l.append(a)
    if(a>b):
        b=a
    elif(a>c):
        c=a
for i in l:
    if(i!=b):
        print(b)
    else:
        print(c)
while True :
    (x,y) = int(i) for i in input().split()
    if y < x :
        print(y,x)
    elif x <= y :
        print(x,y)
    else :
        break

### FIXED CODE ###

while True:
    (x, y) = [int(i) for i in input().split()]
    
    if x == y == 0 :
        break

    if x <= y :
        print(x, y)
    else :
        print(y, x)
import numpy as np
H,W,K = map(int,input().split())
c = [input().split() for l in range(H)]

def count_mat():
  c1 = c.count("#")
  return c1
 
num = 0
while c1 > K:
  for i in range(H)
  for j in range(W)
  c = np.delete(c, i, j)
  num += 1
  
  print(num)

### FIXED CODE ###

H, W, K = list(map(int, input().split()))
 
c = [list(input()) for i in range(H)]
 
cnt = 0
for i in range(2**H):
    for j in range(2**W):
        cnt_black = 0
        for k in range(H):
            if (i >> k) & 1:
                continue
            for l in range(W):
                if (j >> l) & 1:
                    continue
                if c[k][l] == '#':
                    cnt_black += 1
        if cnt_black == K:
            cnt += 1
 
print(cnt)
import sys
from collections import Counter
from operator import itemgetter, attrgetter
n=0
 
n = input()
d_list= list(map(int, input().split()))
cou=sorted(Counter(d_list).most_common())
total=len(d_list)
# print(n)
# print(cou)
# print(total)
index=0
before=0
after=0
first=True
t=0
if n == 0:
    print(0)
for c in cou:
#     print(c)
    if first:
        before = c
        first=False
    before = after
    after = c
    t+=c[1]
    if t > total/2:
        break
    index+=1
# print(before)
# print(after)
# print(len(cou[index:]))
if not(len(cou[index:]) == total/2):
    print(0)
else:
    print(after[0]-before[0])

### FIXED CODE ###

import sys
from collections import Counter
from operator import itemgetter, attrgetter
n=0
 
n = input()
d_list= list(map(int, input().split()))
cou=sorted(Counter(d_list).most_common())
total=len(d_list)
# print(n)
# print(cou)
# print(total)
index=0
before=0
after=0
first=True
t=0
for c in cou:
#     print(c)
    if first:
        before = c
        first=False
    else:
        before = cou[index-1]
    after = c
    t+=c[1]
    if t > total/2:
        break
    index+=1
# print(before)
# print(after)
# print(len(cou[index:]))
if not(sum(n for _, n in cou[index:]) == sum(n for _, n in cou[:index])):
    print(0)
else:
    print(after[0]-before[0])
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N,M=mi()
    A=list(mi())

    v = [0] * 2*10**5
    seen = set()
    for i in range(N):
        v[i+1] = A[i] + v[i]
        v[i+1] %= M
        seen.add(v[i+1])
    
    counts = {x:0 for x in seen}
    for i in range(N+1):
        counts[v[i]] += 1
    
    ans = 0
    for _,count in counts.items():
        ans += count * (count-1) // 2
    
    print(ans)
    





if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N,M=mi()
    A=list(mi())

    v = [0] * 2*10**5
    seen = set([0])
    for i in range(N):
        v[i+1] = A[i] + v[i]
        v[i+1] %= M
        seen.add(v[i+1])
    
    counts = {x:0 for x in seen}
    for i in range(N+1):
        counts[v[i]] += 1
    
    ans = 0
    for _,count in counts.items():
        ans += count * (count-1) // 2
    
    print(ans)
    





if __name__ == "__main__":
    main()
import sys
stdin=sys.stdin

ns=lambda:stdin.readline().rstrip()
ni=lambda:int(stdin.readline().rstrip())
nm=lambda:map(int,stdin.readline().rstrip())
nl=lambda:list(map(int,stdin,readline().rstrip()))

K,X=nm()
print('Yes' if X<=500*K else 'No')

### FIXED CODE ###

import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

K,X=nm()
print('Yes' if X<=500*K else 'No')
n,m=int(input().split())
li=[int(k) for k in input().split()]
dp=[0]*n
dp[0]=0
dp[1]=li[1]-li[0]
for i in range(2,n):
  ans=10**9
  for j in range(1,m+1):
    ans=min(ans,abs(li[i]-li[i-j])+dp[i-j])
  dp[i]=ans
print(dp[n-1])  


### FIXED CODE ###

n,m=input().split()
n=int(n)
m=int(m)
li=[int(k) for k in input().split()]
dp=[0]*n
dp[0]=0
dp[1]=abs(li[1]-li[0])
for i in range(2,n):
  ans=10**9
  for j in range(1,m+1):
    if i-j<0:
      break
    ans=min(ans,abs(li[i]-li[i-j])+dp[i-j])
  dp[i]=ans
#print(dp)  
print(dp[n-1])
# ABCB - Digit Sums
n = int(input())
sn = 0
for i in range(len(str(n))):
    sn += n % 10
print("Yes" if n % sn == 0 else "No")

### FIXED CODE ###

# ABCB - Digit Sums
n = int(input())
sn = sum(list(map(int, list(str(n)))))
print("Yes" if n % sn == 0 else "No")
#!/usr/bin/env python3
import sys
                                                                                                                                                                                                                                                                      def solve(N: int):                                                                                                                     ans=0
    for i in range(N):
        ans+=i if i%3!=0 and i%5!=0 else 0
    print(ans)                                                                                                                         return                                                                                                                                                                                                                                                                                                                                                                                               # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():                                                                                                                  for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main() 

### FIXED CODE ###

#!/usr/bin/env python3
import sys

def solve(N: int):
    ans=0
    for i in range(1,N+1):
        ans+=i if i%3!=0 and i%5!=0 else 0
    print(ans)
    return

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()
a,b=map(int,input().split)
print(a*b-(a+b-1))


### FIXED CODE ###

a,b=map(int,input().split())
print(a*b-(a+b-1))
N,K=map(input().split())
S=str.input()
S[K-1] = S[K-1].lower()



### FIXED CODE ###

N, K = map(int, input().split())
S = list(input())
S[K-1] = S[K-1].lower()
print("".join(S))
n=int(input())
a=[int(input()) for i in range(n)]
count=0
for i in range(0,n):
  if a[i]%2==0:
    if a[i]%3==0 or a[i]%5==0:
      count=count+1
  else:
    count=count+1
if count==n
  print("APPROVED")
else:
  print("DENIED")

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
count=0
for i in range(0,n):
  if a[i]%2==0:
    if a[i]%3==0 or a[i]%5==0:
      count=count+1
  else:
    count=count+1
if count==n:
  print("APPROVED")
else:
  print("DENIED")
n,q=map(int,input().split())
s=input()
cnt=[0]*n
for i in range(n-1):
    if s[i:i+1]=="AC":
      cnt[i+1]=cnt[i]+1
#    else:
#      cnt[i+1]=cnt[i]

for i in range(q):
    li,ri=map(int,input().split())
#    print(s[li-1:ri].count("AC"))
#    print(sum(cnt[li-1:ri-1]))
    print(cnt[ri]-cnt[li])

### FIXED CODE ###

n,q=map(int,input().split())
s=input()
cnt=[0]*n
icnt=0
for i in range(n-1):
#    print(s[i:i+2])
    if s[i:i+2]=="AC":
      icnt=icnt+1
      cnt[i+1]=cnt[i]+1
    else:
      cnt[i+1]=cnt[i]
#print(cnt,s)
for i in range(q):
    li,ri=map(int,input().split())
#    print(s[li-1:ri].count("AC"))
#    print(sum(cnt[li-1:ri-1]))
    print(cnt[ri-1]-cnt[li-1])
n, m, x = map(int, input().split())
lst = [0] * (n + 1)
for i in map(int,input().split()):
  lst[i] = 1

print(min(sum(lst[:x+1]), sum(lst[x+1:]))

### FIXED CODE ###

n, m, x = map(int, input().split())
a = map(int, input().split())
count = 0
for i in a:
  if i < x:
    count += 1
print(min(count, m - count))
N, K = map(int, input().split())
dic = {}
ans = []
uniq = []
etc = []
def calc_ans(ans):
    x = 0
    tmp = 0
    for i in range(K):
      tmp += ans[i][0]
      x += ans[i][1]
    return tmp + (x * x)

for i in range(N):
    l = list(map(int, input().split()))
    if dic.get(l[0]):
        dic[l[0]].append(l[1])
    else:
        dic[l[0]] = [l[1]]
if N <= K:
    ans = 0
    for i in dic.keys():
        ans += sum(dic[i])
    ans += len(dic.keys()) * len(dic.keys())
    print(ans)
    exit()
for t in dic.keys():
    dic[t].sort(reverse=True)
    uniq.append((dic[t][0], t))
uniq.sort(reverse=True)
for i in range(K):
  ans.append((uniq[i][0], 1))
  for n in dic[uniq[i][1]][1:]:
      if n <= uniq[K-1][0]:
          break
      etc.append((n, 0))
ans_res = calc_ans(ans)
all_ans = ans_res
for i, n in enumerate(etc):
    ans.sort(reverse=True)
    ans[-1] = n
    tmp_res = calc_ans(ans)
    if all_ans < tmp_res:
        all_ans = tmp_res
    ans_res = tmp_res
print(all_ans)

### FIXED CODE ###

N,K = map(int,input().split())
td = [[int(i) for i in input().split()] for _ in range(N)]
td.sort(key=lambda x:x[1],reverse=True)
ans = 0
ls = set()
dl = []
for i in range(K):
    ans += td[i][1]
    if not td[i][0] in ls:
        ls.add(td[i][0])
    else:
        dl.append(td[i][1])
ans = ans + len(ls)**2
res = ans
for i in range(K,N):
    if not dl:
        break
    if td[i][0] in ls:
        continue
    ans += len(ls)*2+1
    ans += td[i][1]
    ans -= dl[-1]
    del dl[-1]
    res = max(res,ans)
    ls.add(td[i][0])
print(res)