Harryxun/stf_run huggingface dataset:
import numpy as np
from operator import itemgetter

N = int(input())

list = []
for i in range(N):
    a,b=input().split()
    list.append([a, int(b),i+1])
sort1 = sorted(list, key=itemgetter(0))
ans = []
kari = []
end = 1
k = 1
for i in range(0,N-1):
    if end == 1:
    	kari.append(sort1[i])
    else:
      	k = 0
    if sort1[i][0] == sort1[i+1][0]:  
        kari.append(sort1[i+1])
        if i+1 > N-2:
        	kari.sort(key=itemgetter(1),reverse=True)
        	ans.extend(kari)
        end = 0
    else:
        kari.sort(key=itemgetter(1),reverse=True)
        ans.extend(kari)
        if i+1 > N-2:
        	ans.extend(sort1[i+1])
        kari = []
        end = 1

for i in range(0,len(ans)):
	print(ans[i][2])

### FIXED CODE ###

import numpy as np
from operator import itemgetter
 
N = int(input())
 
list = []
for i in range(N):
    a,b=input().split()
    list.append([a, int(b),i+1])
sort1 = sorted(list, key=itemgetter(0))
if N == 1:
  	print(1)
else:
    ans = []
    kari = []
    end = 1
    k = 1
    for i in range(0,N-1):
        if end == 1:
            kari.append(sort1[i])
        else:
            k = 0
        if sort1[i][0] == sort1[i+1][0]:  
            kari.append(sort1[i+1])
            end = 0
            if i+1 > N-2:
            	kari.sort(key=itemgetter(1),reverse=True)
            	ans.extend(kari)

        else:
            kari.sort(key=itemgetter(1),reverse=True)
            ans.extend(kari)
            if i+1 > N-2:
            	ans.append(sort1[i+1])
            kari = []
            end = 1
    
    for i in range(0,len(ans)):
        print(ans[i][2])
import math
N = int(input())
xy = [[0,0] for _ in range(N)]
for a in xy:
    a[0], a[1] = map(int, input().split())
x=xy[:,0]
y=xy[:,1]
at = []
for i in range(N):
    for j in range(N):
        ea = math.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)
        at.append(ea)
da = 0
for ag in at:
    da += ag
avg = da * math.factorial(N - 1) / math.factorial(N)
print(avg)

### FIXED CODE ###

import math
N = int(input())
x = [0]*N
y = [0]*N
for i in range(N):
    x[i],y[i] = map(int,input().split())
at=[]
for i in range(N):
    for j in range(N):
        ea = math.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)
        at.append(ea)
da = 0
for ag in at:
    da += ag
avg = da * math.factorial(N - 1) / math.factorial(N)
print(avg)
n=int(input())
a=[int(i) in input().split()]
a=sorted(a)[::-1]
print(sum[1:2*n:2])

### FIXED CODE ###

n=int(input())
a=sorted([int(i) for i in input().split()])[::-1]
print(sum(a[1:2*n:2]))
#dfs
import sys
sys.setrecursionlimit(10 ** 7)

#dfs
M = int(input())
L = []
for i in range(M):
    d, c = map(int, input().split())
    L.extend([d] * c)

answer = 15

def dfs(count, l):
    global answer
    if len(l) == 1:
        #print(count)
        answer = min(answer, count)
    else:
        for i in range(len(l)-1):
            sum = l[i] + l[i+1]
            result = l[:i] + [int(x) for x in list(str(sum))] + l[i+2:]
            #print(result)
            dfs(count+1, result)

dfs(0, L)
print(answer)


### FIXED CODE ###

import sys
import numpy as np

stdin = sys.stdin
 
ni = lambda:int(ns())
na = lambda:list(map(int,stdin.readline().split()))
ns = lambda:stdin.readline().rstrip()  # ignore trailing spaces

M = ni()
D = [] ; C = []

for i in range(M):
    d, c = na()
    D.append(d)
    C.append(c)

D = np.array(D) ; C = np.array(C)
#桁数の9倍とそれぞれの数字の総和をx
x = C.sum() * 9 + (C * D).sum()
# 18以下で終了
answer = (x + 8) // 9 - 2
print(answer)
[print(len(list(i.groupby(input())))-1)for i in[__import__('itertools')]][print(len(list(i.groupby(input())))-1)for i in[__import__('itertools')]]

### FIXED CODE ###

from sys import stdin, stderr, setrecursionlimit, exit
setrecursionlimit(2147483647)
def debug(*args, **kwargs):
    print(*args, file=stderr, **kwargs)

ans = 0
s = input()

for i in range(1, len(s)):
    if s[i-1] != s[i]:
        ans += 1

print(ans)
n=int(input())
numbb=input().split(' ')
numb=[]
for i in numbb:
    numb.append(int(i))
numb=sorted(numb)
#print(numb)
if(n==len(numb)):
    if(n%2!=0):
        temp=[]
        temp.append(0)
        strt=2
        for i in range(0,int(n/2)):
            temp.append(strt)
            temp.append(strt)
            strt+=2
        if(temp==numb):
            #print(temp,numb)
            print(((pow(2,len(set(numb))-1)%((10**9)+7))))
        else:
            print(0)
    if(n%2==0):
        temp=[]
        strt=1
        for i in range(0,int(n/2)):
            temp.append(strt)
            temp.append(strt)
            strt+=2
        if(temp==numb):
            #print(temp,numb)
            #print(pow(2,len(set(numb))))
            print(((pow(2,len(set(numb)))%((10**9)+7))))
        else:
            print(0)
    

### FIXED CODE ###

st=input()
print(eval(st))
n = int(input())
l = list(map(int, input().split()))

cnt = 0
while all(a % 2 == 0 for a in l):
	l = [a / 2 for a in l]
    cnt += 1
print(cnt)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
count = 0
while all(a % 2 == 0 for a in A):
    A = [a / 2 for a in A]
    count += 1
print(count)
l=raw_input().split()
for i in range(l):
 print(f"Case{i}: {l[i]}")

### FIXED CODE ###

import sys
i=1
for e in sys.stdin:
 if'0\n'==e:break
 print(f'Case {i}: {e[:-1]}');i+=1
n,m=map(int,input().split())
cities=[[] for i in range(n)]
for i in range(1,m+1):
  p,y=map(int,input().split())
  cities[p-1].append(y)
  print(format(str(p),"0>6")+format(str(len(cities[p-1],"0>6"))))
  

### FIXED CODE ###

import sys
n,m=map(int,input().split())
if m==1:
  a,b=map(int,input().split())
  print(str(a).zfill(6)+str(m).zfill(6));sys.exit()
cities=[None]*m
for i in range(m):
  p,y=map(int,input().split())
  cities[i]=[p,y,i]
cities.sort(key=lambda x:x[1]);cities.sort(key=lambda x:x[0])
i=0
c=1
while True:
  cities[i].append(c)
  c+=1
  if i!=m-1 and cities[i][0]!=cities[i+1][0]:c=1
  elif i==m-1:break
  i+=1
cities.sort(key=lambda x:x[2])
for i in cities:
  print(str(i[0]).zfill(6)+str(i[3]).zfill(6))
n, m = map(int, input().split())
d = dict()

for _ in range(m):
  a, b = map(int,input().split())
  d[a] = d.get(a, 0) + 1
  d[b] = d.get(b, 0) + 1

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

### FIXED CODE ###

n, m = map(int, input().split())
c  = [0] * n

for _ in range(m):
  a, b = map(int, input().split())
  c[a-1] += 1
  c[b-1] += 1

for r in c:
  print(r)
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
 
print(a[map(int, input())-1])

### FIXED CODE ###

a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
b = int(input())
print(a[b-1])
a=int(input(""))
b=int(input(""))
if a%2==1 and b%2==1:
    print("Odd\n")
else:
    print("Even\n")

### FIXED CODE ###

s=raw_input().split()
a=int(s[0]);
b=int(s[1]);
if a*b%2==0:
   print "Even"
else:
   print "Odd"
return int(r**2)

### FIXED CODE ###

print(int(input())**2)
if __name__ == '__main__':
	a, b = map(int, raw_input().split())
	area = a * b
	circumference = 2*a + 2*b
	print(area + ' ' + circumference)

### FIXED CODE ###

if __name__ == '__main__':
	a, b = map(int, input().split())
	area = a * b
	circumference = 2*a + 2*b
	print(area, circumference)
n=int(input())
l=list(map(int,input().split()))
count=0
for i in range(1,n+1)
    if l[i-1]!=i:
        count+=1
print("YES" if count==0 or count==2 else "NO")

### FIXED CODE ###

a,b=map(int,input().split())
print((a+b)//2 if (a+b)%2==0 else "IMPOSSIBLE")
# -*- coding: utf-8 -*-
qS = input()


def replace(s, count):
    fi = s.find('ABC')
    if fi >= 0:
        newS = 'A' + s[fi+3:]
        return replace(newS, count + 1)
    else:
        return count


print(replace(qS, 0))


### FIXED CODE ###

# -*- coding: utf-8 -*-
s = input()

a_num = 0
bc_num = 0
ans = 0
i = 0
while i < len(s):
    if s[i] == 'A':
        a_num += 1
        i += 1
    elif s[i:i+2] == 'BC':
        ans += a_num
        i += 2
    else:
        a_num = 0
        b_num = 0
        i += 1

print(ans)
n,start=map(int,input().split())
town=list(map(int,input().split()))

kyori=[]

for item in town:
    kyori.append(abs(item-start))

import math
temp=kyori[0]

for item in kyori:
    temp=math.gcd(item, temp)

print(temp)


### FIXED CODE ###

n,start=map(int,input().split())
town=list(map(int,input().split()))

kyori=[]

for item in town:
    kyori.append(abs(item-start))
import fractions
temp=kyori[0]

for item in kyori:
    temp=fractions.gcd(item, temp)

print(temp)
X, Y, A, B, C = list(map(int,input().split()))
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

Z = 0
whlie True:
  if max(p[X - 1], q[Y - 1], r[Z]) == r[Z]:
    if p[X - 1] < q[Y - 1]:
      X -= 1
      Z += 1
    else:
      Y -= 1
      Z += 1
  else:
    break

print(sum(p[:X]) + sum(q[:Y]) + sum(r[:Z]))
    

### FIXED CODE ###

X, Y, A, B, C = list(map(int,input().split()))
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
 
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
 
p.append(float("inf"))
q.append(float("inf")) 

Z = 0
while Z < C:
  if min(p[X - 1], q[Y - 1]) < r[Z]:
    if p[X - 1] < q[Y - 1]:
      X -= 1
      Z += 1
    else:
      Y -= 1
      Z += 1
    continue
  break
 
print(sum(p[:X]) + sum(q[:Y]) + sum(r[:Z]))
A,B = map(int,input())

print(A*B)

### FIXED CODE ###

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

print(A*B)
l = map(int, raw_input().split())
print(l[0])
print(l[1])
print(l[2])
if (l[2] - l[1]) <= 0:
    print("delicious")
elif (l[2] - l[1]) <= l[0]:
    print("safe")
else:
    print("dangerous")

### FIXED CODE ###

l = list(map(int, input().split()))
border = l[1] - l[2]
if border < 0:
    if l[0] >= abs(border):
        print("safe")
    else:
        print("dangerous")
else:
    print("delicious")
A,B=input().split
if A < B:
  print("<")
elif A > B:
  print(">")
else:
  print("=")


### FIXED CODE ###

A,B=input().split()
if A < B:
  print("<")
elif A > B:
  print(">")
else:
  print("=")
#coding:utf-8
N,K=map(int,input().split())
print(K*(K-1)**(N-1))


### FIXED CODE ###

#coding:utf-8
a,b,c=list(map(int,input().split()))

if a==b and b==c:
    print(1)
elif a==b or b==c or c==a:
    print(2)
else:
    print(3)
n = int(input())

#約数
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

list_n = make_divisors(n)

a = len(list_n)
ans = []
for i in range(0, a, 2):
    ans.append(list_n[i]+list_n[i+1])

ans.sort()

print(ans[0]-2)

### FIXED CODE ###

n = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            divisors.append(n//i)

    # divisors.sort()
    return divisors

n_list = make_divisors(n)
n_ans = []

for i in range(0, len(n_list)-1, 2):
    n_ans.append(n_list[i]+n_list[i+1])

n_ans.sort()

print(n_ans[0]-2)
import itertools

N,M,Q = map(int,(input().split()))
a = [0]*Q
b = [0]*Q
c = [0]*Q
d = [0]*Q
for i in range(Q):
    a[i],b[i],c[i],d[i] = map(int,(input().split()))

l = list(itertools.combinations_with_areplacement(range(1,M+1), N))

nax = 0
for x in l:
    score = 0
    for i in range(Q):
        if int(x[b[i]-1]) - int(x[a[i]-1]) == c[i]:
            score += d[i]
    nax = max(nax,score)

print(nax)

### FIXED CODE ###

N,M,Q = map(int,(input().split()))
a = [0]*Q
b = [0]*Q
c = [0]*Q
d = [0]*Q
for i in range(Q):
    a[i],b[i],c[i],d[i] = map(int,(input().split()))

lun = [0]*N
l = []

def make(n):
    if len(n) > N:
        return 0
    if int(n) > 3234566667:
        return 0
    else:

        p = []
        for i in range(int(n[-1]),M):
            p.append(str(i))

        lun.append(n)
        for i in p:
            lun.append(n)
            if len(n) == N:
                l.append(n)
            make(n+i)
        return 0
for i in range(M):
    make(str(i))

l = list(set(l))

nax = 0
for x in l:
    score = 0
    for i in range(Q):
        if int(x[b[i]-1]) - int(x[a[i]-1]) == c[i]:
            score += d[i]
    nax = max(nax,score)

print(nax)
from sympy import divisors, isprime
S=int(input())
x_1=10**9
y_1=10**9
x_2=10**9
y_3=10**9

m = S
sqrt_m = int(m**(1/2))

if isprime(m):
    x=[1,m]
elif m % sqrt_m:
    a = divisors(m)
    x=a[len(a)//2 - 1:len(a)//2  + 1]
else:
    x=[sqrt_m,sqrt_m]

print(x_1,y_1,x_2,(10**9)-x[0],(10**9)-x[1],y_3)


### FIXED CODE ###

S=int(input())
x_1=0
y_1=0
x_2=10**9
y_2=1

if S%10**9==0:
    x_3=0
    y_3=S//10**9
else:
    x_3=10**9-S%10**9
    y_3=1+S//10**9

print(x_1,y_1,x_2,y_2,x_3,y_3)
n = int(input())
a = []
a = list(map(int, input().strip().split()))

all_sum = 0

for i in range(n):
  all_sum += 1/a[i]

ans = 1 / all_sum

print(ans)


### FIXED CODE ###

a = int(input())
s = input()

if a >= 3200:
  print(s)

else:
  print("red")
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = -float("inf")
for i in range(1, 2 ** 10):
    b, s = i, 0
    cnt = [0 for _ in range(N)]
    while b > 0:
        if b & 1:
            for j in range(N):
                cnt[j] += F[j][s]
        s += 1
        b >>= 1
    sub_ans = 0
    for j in range(N):
        sub_ans += P[j][cnt[j]]
    ans = max(ans, sub_ans)
print(ans)


### FIXED CODE ###

import sys

def main():
    input = sys.stdin.readline
    N, C = map(int, input().split())
    dic = [[] for _ in range(C + 1)]
    for _ in range(N):
        s, t, c = input().split()
        dic[int(c)].append([int(s), int(t)])
    for c in range(C + 1):
        l = len(dic[c])
        if l == 1:
            continue
        dic[c] = sorted(dic[c])
        i = 0
        while i < l - 1:
            if i < l - 1 and dic[c][i][1] == dic[c][i + 1][0]:
                dic[c][i + 1][0] += 1
            else:
                i += 1
    f = [0 for _ in range(100002)]
    for c in range(C + 1):
        for t in dic[c]:
            f[t[0]] += 1
            f[t[1] + 1] -= 1
    ans = 0
    for i in range(1, 100001):
        f[i] += f[i - 1]
        if ans < f[i]:
            ans = f[i]
    print(ans)

if __name__ == "__main__":
    main()
n,k = map(int,input().split())
s = list(input())
s[k] = s[k].lower()
st = "".join(s)
print(st)


### FIXED CODE ###

n,k = map(int,input().split())
s = list(input())
s[k-1] = s[k-1].lower()
st = "".join(s)
print(st)
#17:09
n,k = map(int,input().split())
v = list(map(int,input().split()))
'''
左からa個
右からb個
k-a-b個以内捨てて良し
'''
can = []
x = []
for a in range(k):
  if a != 0:
    x.append(v[a-1])
  y = []
  for b in range(k):
    if b != 0:
      y.append(v[-b])
    if a + b <= min(n,k):
      z = x + y
      z.sort()
      r = k - a - b
      tmp = 0
      if r < a+b:
        if z[r] < 0:
          for i in range(r,a+b):
            tmp += z[i]
        else:
          for i in range(a+b):
            if z[i] > 0:
              tmp += z[i]
      else:
        for i in range(r,a+b):
          if z[i] > 0:
            tmp += z[i]
      can.append(tmp)
print(max(can))

### FIXED CODE ###

#17:09
n,k = map(int,input().split())
v = list(map(int,input().split()))
'''
左からa個
右からb個
k-a-b個以内捨てて良し
'''
can = []
nk = min(n,k)
for a in range(nk+1):
  if a != 0:
    x.append(v[a-1])
  else:
    x = []
  for b in range(nk+1-a):
    if b != 0:
      y.append(v[-b])
    else:
      y = []
    z = x + y
    z.sort()
    r = k - a - b
    tmp = 0
    if r < a+b:
      if z[r] < 0:
        for i in range(r,a+b):
          tmp += z[i]
      else:
        for i in range(a+b):
          if z[i] >= 0:
            tmp += z[i]
    else:
      for i in range(a+b):
        if z[i] >= 0:
          tmp += z[i]
    can.append(tmp)
print(max(can))
import sys


def parallelism(x1, y1, x2, y2, x3, y3, x4, y4):
    if x1 - x2 == 0.0 or x3 - x4 == 0.0:
        return x1 - x2 == 0.0 and x3 - x4 == 0.0
#    elif y1 == y2 or y3 == y4:
#        return y1 == y2 and y3 == y4
    else:
        return ((y2 - y1) / (x2 - x1)) == ((y4 - y3) / (x4 - x3))


lines = sys.stdin.readlines()
lines.pop(0)

for line in lines:
    x1, y1, x2, y2, x3, y3, x4, y4 = tuple(map(float, line.split(' ')))
    if parallelism(x1, y1, x2, y2, x3, y3, x4, y4):
        print "YES"
    else:
        print "NO"

### FIXED CODE ###


import sys


def parallelism(x1, y1, x2, y2, x3, y3, x4, y4):
    if x2 - x1 == 0.0 or x4 - x3 == 0.0:
        return x2 - x1 == 0.0 and x4 - x3 == 0.0
    else:
        return ((y2 - y1) / (x2 - x1)) == ((y4 - y3) / (x4 - x3))


#lines = sys.stdin.readlines()
#lines.pop(0)

for i in range(input()):
    x1, y1, x2, y2, x3, y3, x4, y4 = tuple(map(float, raw_input().split(' ')))
    if parallelism(x1, y1, x2, y2, x3, y3, x4, y4):
        print "YES"
    else:
        print "NO"
n,m = map(int, input().split( ))
a = [] 
mod = 10**9+7
for _ in range(m):
    a.append(int(input()))

dp = [0]*(n+1)
dp[0] = 1
if a[0]!=1:
    dp[1] = 1

A = set(a)
 
for i in range(2,n+1):
    if i not in A:
        dp[i] = (dp[i-1]+dp[i-2])%mod
print(dp[n])




### FIXED CODE ###

import sys
n,m = map(int, input().split( ))
a = [] 

mod = 10**9+7
for _ in range(m):
    a.append(int(input()))

dp = [0]*(n+1)
dp[0] = 1
dp[1] = 1
if a:
    if a[0]==1:
        dp[1] = 0

A = set(a)
 
for i in range(2,n+1):
    if i not in A:
        dp[i] = (dp[i-1]+dp[i-2])%mod
print(dp[n])
import numpy as np
N, M, *L = map(int, open('0').read().split())
L = [np.array(m) for m in zip(*[iter(L)]*3)]
ans = 0
for i in range(8):
  X = []
  c = []
  for j in range(3):
    if i%2==1:
      c.append(-1)
    else:
      c.append(1)
    i >>= 1
  c = np.array(c)
  X = list(map(lambda x:sum(x*c), L))
  X.sort(reverse=True)
  ans = max(ans, sum(X[:M]))
print(ans)

### FIXED CODE ###

from collections import defaultdict
from heapq import heappush, heappop
N, M = map(int, input().split())
dic = defaultdict(list)
for i in range(N):
  x, y, z = map(int, input().split())
  ls = (x,y,z)
  for j in range(8):
    m = 0
    n = j
    for h in range(3):
      a = ls[h]
      if n%2==1:
        a = -a
      m += a
      n >>= 1
    heappush(dic[j], -m)
#print(dic)
ans = 0
for i in range(8):
  m = 0
  for j in range(M):
    m -= heappop(dic[i])
  if m>ans:
    ans = m
print(ans)
li = list(map(int,input().split()))
a = li[0]
e = li[4]
k = li[5]

if e - a <= k:
    print("Yay!")
else:
    print(":(")

### FIXED CODE ###

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

if e - a <= k:
    print("Yay!")
else:
    print(":(")
t = [0]
x = [0]
y = [0]
N = int(input())
for i in range(N):
  ti, xi, yi = map(int,input().split())
  t.append(ti)
  x.append(xi)
  y.append(yi)
  
flg = True 
for i in range(1,N+1):
  if (t[i]-t[i-1] <　x[i]-x[i-1] + y[i]-y[i-1]):
    flg = False
  elif ((t[i]-t[i-1])%2 != (x[i]-x[i-1]+y[i]-y[i-1])%2):
    flg = False
if(flg):
  print("Yes")
else:
  print("No")


### FIXED CODE ###

a,b = map(int, input().split())
if a*b % 2 == 0:
  print("Even")
else:
  print("Odd")
n, x = map(int, input().split())


a = list(map(int,input().split()))
  
a.sort()

total=0
ans=0
for i in range(n):
  total += a[i]
 
  if total > x:
    ans = i
    break
  else if total ==x:
    ans = i+1
    break
  else:
    ans=i
  
print(ans)

### FIXED CODE ###

n, x = map(int, input().split())


a = list(map(int,input().split()))
  
a.sort()

total=0
ans=0
for i in range(n):
  total += a[i]
 
  if total > x:
    ans = i
    break
  elif total ==x:
    ans = i+1
    break
  else:
    ans=i
  
print(ans)
def manzoku(s):
    return sum([d for (t, d) in s]) + len(set([t for (t, d) in s]))**2

N, K = map(int, input().split())
menu = []

for i in range(N):
    t, d = map(int, input().split())
    menu.append((t, d))
    
#Sort with value d
sorted(menu, key = lambda x:x[1], reverse=True)
#print(menu)

menu_ = menu[:K]
#x = len(set([t for (t, d) in menu_]))
_menu = menu[K:]

def sushi():
    for (t, d) in reversed(menu_):
        if [i for (i, v) in menu_].count(t) != 1:
            menu_.remove((t, d))
            #print(menu_)
            for (ii, vv) in _menu:
                if ii != t:
                    menu_.append((ii, vv))
                    #print(menu_)
                    _menu.remove((ii, vv))
                    #print(_menu)
                    return False
    return True        

#print(menu_)
g = []
for idx in range(K, N):
    g.append(manzoku(menu_))

    if sushi():
        break

print(max(g))    
    

### FIXED CODE ###

N, K = map(int, input().split())
menu_ = []

for i in range(N):
    t, d = map(int, input().split())
    menu_.append((t, d))

menu = sorted(menu_, key = lambda x:x[1], reverse=True)
neta = set()
duplicates = []

for m in menu[:K]:
    if m[0] in neta:
        duplicates.append(m[1])
    else:
        neta.add(m[0])

p = sum([d for (t, d) in menu[:K]]) + len(neta)**2
ans = p

for m in menu[K:]:
    if m[0] not in neta and duplicates:
        neta.add(m[0])
        duplicate = duplicates.pop()
        
        p += (m[1] - duplicate) + 2 * len(neta) - 1 
        #print(ans, p)
        ans = max(ans, p)

print(ans)
S = input()
while True:
  S = S[:-1]
  mid = len(S)//2
  if S[:mid] == S[mid:]:
    print(len(S))
    break
  elif S = "":
    break

### FIXED CODE ###

S = input()
while len(S) > 0:
  S = S[:-1]
  mid = len(S)//2
  if S[:mid] == S[mid:]:
    print(len(S))
    break
from sys import stdin
import numpy as np

N = int(stdin.readline().rstrip().split()[0])
A = [int(x) for x in stdin.readline().rstrip().split()]
# N, X = [int(x) for x in stdin.readline().rstrip().split()]

def G(_a, _b):
  if _a>=_b:
    a, b = _a, _b
  else:
    a, b = _b, _a
  
  while True:
    c = a%b
    if c == 0:
      break
    a,b = b,c
  
  return b

def func(L):
  unique_L = list(set(L))
  if len(unique_L)==1:
    return unique_L[0]
  else:
    g = G(unique_L[0], unique_L[-1])
    unique_L[0] = g
    unique_L[-1] = g
    return func(unique_L)
print(func(A))
    

### FIXED CODE ###

from sys import stdin
import numpy as np

N = int(stdin.readline().rstrip().split()[0])
A = [int(x) for x in stdin.readline().rstrip().split()]
# N, X = [int(x) for x in stdin.readline().rstrip().split()]

def G(_a, _b):
  if _a>=_b:
    a, b = _a, _b
  else:
    a, b = _b, _a
  
  while True:
    c = a%b
    if c == 0:
      break
    a,b = b,c
  
  return b

L = np.array(list(set(A)))
mini = np.min(L)
yaku = [1]
i=2
r_mini = np.sqrt(mini)
while i<=r_mini:
  if mini%i==0:
    yaku.append(i)
  i+=1
yaku2 = list(map(lambda x: int(mini/x), yaku))
yaku = yaku[::-1]
yaku2.extend(yaku)
for y in yaku2:
  if np.sum(L%y)==0:
    ans = y
    break

print(ans)