Harryxun/stf_run huggingface dataset:
N, K = map(int, input().split())
menu = []

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

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:
        neta.add(m[0])
        duplicate = duplicates.pop()
        
        p += (m[1] - duplicate) + 2 * len(neta) + 1 
        #print(ans, p)
        ans = max(ans, p)

print(ans) 

### 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)
class coordinates:
  def __init__(self, x, y):
    self.x = x
    self.y = y

def koch(n, a, b):
  if n == 0:
    return
  s = coordinates((2*a.x + b.x)/3, (2*a.y + b.y)/3)
  t = coordinates((a.x + 2*b.x)/3, (a.y + 2*b.y)/3)
  ux = (t.x - s.x)*cos(pi/3) - (t.y - s.y)*sin(pi/3) + s.x
  uy = (t.x - s.y)*sin(pi/3) + (t.y - s.y)*cos(pi/3) + s.y
  u = coordinates(ux, uy)
 
  koch(n-1, a, s)
  print  s.x, s.y
  koch(n-1, s, u)
  print  u.x, u.y
  koch(n-1, u, t)
  print  t.x, t.y
  koch(n-1, t, b)
 
n = input()
 
p1 = coordinates(0.0, 0.0)
p2 = coordinates(100.0, 0.0)
 
print p1.x, p1.y
koch(n, p1, p2)
print p2.x, p2.y

### FIXED CODE ###

import math

rad = math.radians(60)

class coordinates:
  def __init__(self, x, y):
    self.x = x
    self.y = y
 
def koch(n, a, b):
  if n == 0:
    return
  s = coordinates((2.0*a.x + b.x)/3.0, (2.0*a.y + b.y)/3.0)
  t = coordinates((a.x + 2.0*b.x)/3.0, (a.y + 2.0*b.y)/3.0)
  ux = (t.x - s.x)*math.cos(rad) - (t.y - s.y)*math.sin(rad) + s.x
  uy = (t.x - s.x)*math.sin(rad) + (t.y - s.y)*math.cos(rad) + s.y
  u = coordinates(ux, uy)
  
  koch(n-1, a, s)
  print  s.x, s.y
  koch(n-1, s, u)
  print  u.x, u.y
  koch(n-1, u, t)
  print  t.x, t.y
  koch(n-1, t, b)
  
n = input()
  
p1 = coordinates(0.0, 0.0)
p2 = coordinates(100.0, 0.0)
  
print p1.x, p1.y
koch(n, p1, p2)
print p2.x, p2.y
n = int(input())
a = list(map(int, input().split()))
for i in range(len(a)):
  a[i] -= 1
b = list(map(int, input().split()))
c = list(map(int, input().split()))
m = 0
bef = -1
for i in range(n):
  m += b[a[i]]
  if(bef + 1 == a[i]):
    m += c[bef]
  bef = a[i]
print(m)

### FIXED CODE ###

n = int(input())

print(n**3)
ans = 1
for a in A:
    if 0 in A:
        ans = 0
        break
    ans *= a
    if ans > 10**18:
        ans = -1
        break
print(ans)

### FIXED CODE ###

def main():
    N =int(input())
    A =list(map(int,input().split()))
    if 0 in A:
        print(0)
        return
    prod = 1
    for a in A:
        prod *= a
        if prod > 1000000000000000000:
            print(-1)
            return
    print(prod)
main()
n = int(input())
x = sorted(map(int,input().split()))
x.reverse()
a = 0
b = 0
for i in range(n):
    if i%2==0:
        a+=x[i]
    else:
        b+=x[i]
print(a-b)

### FIXED CODE ###

n = int(input())
x = set(input().split())
if len(x)==3:
    print('Three')
else:
    print('Four')
import math
A, B = [int(A) for A in input().split()]  
if float(B) >= 1:
    print(math.trunc(A * B))
elif 1 > float(B) > 0:
    print(0)
else:
    print(A * B)

### FIXED CODE ###

import decimal
s = input().split()
a = int(s[0])
b = round(decimal.Decimal(s[1]), 2)
print(int(a * b))
i = list(map(int, input().split()))
A = i[0]
B = i[1]
N = i[2]
a = -10 ** 20
for x in range(1, N+1):
  s = A * x // B
  t_0 = x // B
  t = A * t
  u = s - t
  if u > a:
    a = u
print(a)    

### FIXED CODE ###

i = list(map(int, input().split()))
A = i[0]
B = i[1]
N = i[2]
if N < B-1:
    print(A * N // B)
else:
    print(A * (B-1) // B)
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect
import numpy as np

def ln():
    return map(int, input().split())

N,M = ln()

AA = list(ln())
A = np.array(AA)

SUM = np.zeros(N+1,dtype = int)
for i in range(N):
    SUM[i+1] = (SUM[i] + A[i]) % M

ans = 0
dic = dict()
for i in range(N):
    dic[SUM[i]] = 1
for i in range(N+1):
    ans += dic[SUM[i]] -1
    dic[SUM[i]] += 1

print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect
import numpy as np

def ln():
    return map(int, input().split())

N,M = ln()

AA = list(ln())
A = np.array(AA)

SUM = np.zeros(N+1,dtype = int)
for i in range(N):
    SUM[i+1] = (SUM[i] + A[i]) % M

ans = 0
dic = dict()
# for i in range(N):
#     dic[SUM[i]] = 1
for i in range(N+1):
    if SUM[i] in dic:
        dic[SUM[i]] += 1
    else:
        dic[SUM[i]] = 1
    ans += dic[SUM[i]] -1


print(ans)
n = int(input())
numlist = [int(_) for _ in input().split()]
setnum = set(numlist)
nsum = 0

for i in setnum:
    dicnum[i] = numlist.count(i)
    if dicnum[i] >= 2:
        nsum += dicnum[i]*(dicnum[i]-1)//2
    else:
        del dicnum[i]

for j in range(n):
    ans = nsum
    if numlist[j] in dicnum:
        ans = ans - dicnum[numlist[j]] + 1
    print(ans)

### FIXED CODE ###

n = int(input())
numlist = [int(_) for _ in input().split()]
numdic = {}
nsum = 0

for i in range(n):
    if numlist[i] in numdic:
        numdic[numlist[i]] += 1
    else:
        numdic[numlist[i]] = 1

for k in numdic:
    nsum += numdic[k] * (numdic[k] - 1) // 2

for j in range(n):
    ans = nsum
    cal = numdic[numlist[j]]
    if cal >= 2:
        ans = ans - (cal-1)
    print(ans)
import math

N,M = map(int,input().split())

ans = 1
for i in range(1,int(math.sqrt(M)+1)+1):
  if M % i != 0:#約数ではないとき
    continue
  B = M / i
  
  if (A * N <= M):
    ans = max(ans,A)
  if (B * N <= M):
    ans = max(ans,B)

print(ans)
  

### FIXED CODE ###

import math
 
N,M = map(int,input().split())
 
ans = 1
for i in range(1,int(math.sqrt(M))+1+1):
  if M % i != 0:#約数ではないとき
    continue
  B = int(M / i)#intとらないと，N = 1 , M = 100 のとき　ans = 100.0になってエラー？
  
  if (i * N <= M):
    ans = max(ans,i)
  if (B * N <= M):
    ans = max(ans,B)

print(ans)
h a = map(int, input().split())
print(h//a + 1)

### FIXED CODE ###

h, a = map(int, input().split())
if h%a == 0:
  print(int(h/a))
else:
  print(int((h//a) + 1))
def get_caps(a):
  dic = dict()

  for ai in a:
    dic.setdefault(ai, 0)
    dic[ai] += 1

  return dic


def is_match(caps):
  global N

  if 0 in caps.keys():
    if caps[0] == N:
      return True
  
  if N % 3 == 0:
    if 0 in caps.keys() and len(caps) == 2:
      if caps[0] == N//3:
        return True
    elif len(caps) == 3:
      x, y, z = caps.keys()
    
      if x ^ y ^ z == 0:
        if caps[x] == caps[y] == caps[z] == N//3:
        return True


# A - XOR Circle
N = int(input())
a = list(map(int, input().split()))

# 帽子の情報をdictに入れる
caps = get_caps(a)

if is_match(caps):
  print('Yes')
else:
  print('No')

### FIXED CODE ###

def get_caps(a):
  dic = dict()

  for ai in a:
    dic.setdefault(ai, 0)
    dic[ai] += 1

  return dic


def is_match(caps):
  global N

  if 0 in caps.keys():
    if caps[0] == N:
      return True
  
  if N % 3 == 0:
    if 0 in caps.keys() and len(caps) == 2:
      if caps[0] == N//3:
        return True
    elif len(caps) == 3:
      x, y, z = caps.keys()
    
      if x ^ y ^ z == 0:
        if caps[x] == caps[y] == caps[z] == N//3:
          return True


# A - XOR Circle
N = int(input())
a = list(map(int, input().split()))

# 帽子の情報をdictに入れる
caps = get_caps(a)

if is_match(caps):
  print('Yes')
else:
  print('No')
""" AtCoder """

N = int(input())
ans_list = [2, 4, 8, 16, 32, 64]
ans_list = ans_list[::-1]

if N == 1:
    print(1)

for i in range(7):
    if N > ans_list[i]:
        print(ans_list[i])
        break


### FIXED CODE ###

""" AtCoder """

N = int(input())
ans_list = [2, 4, 8, 16, 32, 64]
ans_list = ans_list[::-1]

if N == 1:
    print(1)
    exit()

for i in range(7):
    if N >= ans_list[i]:
        print(ans_list[i])
        break
import sys
input=sys.stdin.readline
n=int(input())
c=[int(input()) for _ in range(n)]
#g=[[]for _ in range(2*(10**5)+1)]
g=[[] for _ in range(10)]


for i in range(n):
    g[c[i]].append(i)

ans=1
for i in range(len(g)):
    if not g[i]:
        continue
    new=[]
    now=g[i][0]
    cnt=1
    m=1
    for j in range(1,len(g[i])):
        m+=1
        if now+1==g[i][j]:
            cnt+=1
            now+=1
        else:
            now=g[i][j]
            new.append(cnt)
            cnt=1
    new.append(cnt)
    ans2=m*(m-1)//2
    for k in new:
        ans2-=k*(k-1)//2
    ans+=ans2

print(ans)


### FIXED CODE ###

nn=int(input())
import sys
input=sys.stdin.readline
cc=[int(input()) for _ in range(nn)]
c=[cc[0]]
for i in range(1,nn):
    if cc[i]!=c[-1]:
        c.append(cc[i])
n=len(c)
mod=10**9+7
dp=[0]*(n+1)
sm=[0]*(max(c)+1)
dp[0]=1
for i in range(n):
    x=c[i]
    dp[i+1]+=sm[x]+dp[i]
    sm[x]+=dp[i]
    dp[i]%=mod
    dp[i+1]%=mod
print(dp[n])
n=int(input())
d=list(map(int,input().split()))
for i in range(n):
  for j in range(n):
    if i!=j:
      sum+=d[i]*d[j]
print(sum//2)


### FIXED CODE ###

n=int(input())
d=list(map(int,input().split()))
sum=0
for i in range(n):
  for j in range(n):
    if i!=j:
      sum+=d[i]*d[j]
print(sum//2)
n=int(input())
c=input().split();d=c[:]
for i in range(n-1):
 for j in range(0,n-i-1):
  if c[j][1]>c[j+1][1]:c[j],c[j+1]=c[j+1],c[j]
 m=i
 for j in range(i,n):
  if b[m][1]>b[j][1]:m=j
 d[i],d[m]=d[m],d[i]
print(*c);print("Stable")
print(*d)
print(['Not s','S'][b==s]+'table')


### FIXED CODE ###

n=int(input())
c=input().split();d=c[:]
for i in range(n-1):
 for j in range(n-i-1):
  if c[j][1]>c[j+1][1]:c[j:j+2]=c[j+1],c[j]
 m=i
 for j in range(i,n):
  if d[m][1]>d[j][1]:m=j
 d[i],d[m]=d[m],d[i]
print(*c);print("Stable")
print(*d);print(['Not s','S'][c==d]+'table')
s=int(split(input()))
a=s[0]
b=s[1]
x=a*b
y=2*a+2*b
print(x,y)

### FIXED CODE ###

a,b=input().split()
a=int(a)
b=int(b)
print(a*b,2*a+2*b)
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**7)

n,MOD = [int(i) for i in input().split()]

to = [[] for _ in [0]*n]
for _ in range(n-1):
    x,y = [int(i)-1 for i in input().split()]
    to[x].append(y)
    to[y].append(x)


dp = [[0]*len(to_i) for to_i in to]
parent_index = [-1]*n 
ans = [0]*n

def dfs(v, p):
    res = 1
    for i, vc in enumerate(to[v]):
        if vc == p:
            parent_index[vc] = i
            continue
        """子供から情報をもらって処理する"""
        dp[v][i] = dfs(vc, v)
        res *= dp[v][i]+1
        res %= MOD
        """処理ここまで"""
    return res

def bfs(v, res_p, p):
    deg = len(to[v])
    if p >= 0:
        dp[v][parent_index[v]] = res_p

    accl = [1]*(deg+1)
    for i, dpvi in enumerate(dp[v]):
        accl[i+1] = accl[i]*(dpvi+1)%MOD

    accr = [1]*(deg+1)
    for i, dpvir in enumerate(reversed(dp[v])):
        accr[-i-2] = accr[-i-1]*(dpvir+1)%MOD

    ans[v] = accr[0]
    for i,vc in enumerate(to[v]):
        if vc == p: continue
        bfs(vc, accl[i]*accr[i+1]%MOD, v)

dfs(0,-1)
#print(dp)
bfs(0,0,-1)
#print(dp)
for i in ans:
    print(i)

### FIXED CODE ###

# coding: utf-8
# Your code here!
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

n,MOD = [int(i) for i in input().split()]

to = [[] for _ in [0]*n]
for _ in range(n-1):
    x,y = [int(i)-1 for i in input().split()]
    to[x].append(y)
    to[y].append(x)


dp = [[0]*len(to_i) for to_i in to]
parent_index = [-9999]*n 
ans = [0]*n

def dfs(v, p):
    res = 1
    for i, vc in enumerate(to[v]):
        if vc == p:
            parent_index[v] = i
            continue
        dp[v][i] = dfs(vc, v)
        res *= dp[v][i]+1
        res %= MOD
    return res

def dfs2(v, res_p, p):
    deg = len(to[v])
    if p >= 0:
        dp[v][parent_index[v]] = res_p

    accl = [1]*(deg+1)
    accr = [1]*(deg+1)

    for i in range(1, deg+1):
        accl[i] = accl[i-1] * (dp[v][i-1] + 1) % MOD
        accr[-i-1] = accr[-i] * (dp[v][-i] + 1) % MOD

    ans[v] = accr[0]
    for i,vc in enumerate(to[v]):
        if vc == p: continue
        dfs2(vc, accl[i]*accr[i+1]%MOD, v)

dfs(0,-1)
#print(dp)
dfs2(0,0,-1)
#print(dp)
for i in ans:
    print(i)
A, B, C, X = [for i in range(4) int(input())]
count = 0
if 500*a + 100*b + 50*c == X for a in range(A+1) for b in range(B+1) for c in range(C+1):
  count += 1
print(count)

### FIXED CODE ###

A = int(input())
B = int(input())
C = int(input())
X = int(input())
print(sum(500*a+100*b+50*c==X for a in range(A+1) for b in range(B+1) for c in range(C+1)))
import sys
def input():
    return sys.stdin.readline().strip()
 
def main():
    nk=list(map(int,input().split()))
    h=list(map(int,input().split()))
    n=nk[0]
    k=nk[1]
    dp=[10**9]*n
    dp[0]=0
    dp[1]=abs(h[1]-h[0])
    for i in range(2,n):
        dp[i]=min(dp[j]+abs(h[i]-h[j]) for j in range(max(0,i-k),i))
    print (dp[-1])
 if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
def input():
    return sys.stdin.readline().strip()
 
def main():
    nk=list(map(int,input().split()))
    h=list(map(int,input().split()))
    n=nk[0]
    k=nk[1]
    dp=[10**9]*n
    dp[0]=0
    dp[1]=abs(h[1]-h[0])
    for i in range(2,n):
        dp[i]=min(dp[j]+abs(h[i]-h[j]) for j in range(max(0,i-k),i))
        # for j in range(max(0,i-k),i):
        #     dp[i]=min(dp[j]+abs(h[i]-h[j]),dp[i])
 
    print (dp[-1])
 
if __name__ == "__main__":
    main()
n = int(input())
a = list(map(int, input().split()))

hu = []
sei = []
for i in a:
	if i < 0:
		hu.append(i)
	else:
		sei.append(i)
hu.sort()
sei.sort()
if len(hu)%2 == 0:
	ans = sum(sei) + (-1)*sum(hu)
else:
	b = sei.pop(0)
	b *= -1
	c = hu.pop(-1)
	c *= -1
	ans = sum(sei) + (-1)*sum(hu)
	ans += (b+c)
print (ans)


### FIXED CODE ###

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

hu = []
sei = []
for i in a:
	if i < 0:
		hu.append(i)
	else:
		sei.append(i)
hu.sort()
sei.sort()
if len(hu)%2 == 0:
	ans = sum(sei) + (-1)*sum(hu)
else:
	if len(sei) == 0:
		ans = (-1)*sum(hu[:-1]) + hu[-1]
		print (ans)
		exit()
	else:
		b = sei[0]
	if len(hu) == 0:
		ans = sum(sei[1:] + sei[-1])
		print (ans)
		exit()
	else:
		c = hu[-1]
	if abs(b) <= abs(c):
		b *= -1
		c *= -1
	ans = sum(sei[1:]) + (-1)*sum(hu[:-1])
	ans += (b+c)
print (ans)
if __name__ == '__main__':
    A, B, Q = map(int, input().split())

    s_list = [int(input()) for i in range(A)]
    t_list = [int(input()) for i in range(B)]
    x_list = [int(input()) for i in range(Q)]

    for xi in x_list:
        distance_ti_right_xi = [ti-xi for ti in t_list if ti >= xi]
        distance_ti_left_xi = [xi-ti for ti in t_list if ti <= xi]
        distance_si_right_xi = [si-xi for si in s_list if si >= xi]
        distance_si_left_xi = [xi-si for si in s_list if si <= xi]
        
        first_move = min(distance_si_left_xi, distance_si_right_xi, distance_ti_left_xi, distance_ti_right_xi)
        if first_move == distance_ti_left_xi or first_move == distance_si_left_xi:
            first_move = -1 * first_move
        xi += first_move

        if abs(first_move) == distance_si_left_xi or abs(first_move) == distance_si_right_xi:
            distance_ti_right_xi = [ti-xi for ti in t_list if ti >= xi]
            distance_ti_left_xi = [xi-ti for ti in t_list if ti <= xi]
            second_move = min(distance_ti_left_xi, distance_ti_right_xi)

        if abs(first_move) == distance_ti_left_xi or abs(first_move) == distance_ti_right_xi:
            distance_si_right_xi = [si-xi for si in s_list if si >= xi]
            distance_si_left_xi = [xi-si for si in s_list if si <= xi]
            second_move = min(distance_si_left_xi, distance_si_right_xi)
        answer = abs(first_move) + abs(second_move)
        print(answer)

### FIXED CODE ###

import bisect
import itertools
import sys


def most_simRL(ds, x):
    index = bisect.bisect_left(ds, x)
    if index == 0:
        return [ds[0]]
    elif index == len(ds):
        return [ds[-1]]
    return ds[index-1:index+1]

if __name__ == '__main__':
    A, B, Q = map(int, input().split())


    s_list = [-sys.maxsize] + [int(input()) for i in range(A)] + [sys.maxsize]
    t_list = [-sys.maxsize] + [int(input()) for i in range(B)] + [sys.maxsize]
    x_list = [int(input()) for i in range(Q)]


    for xi in x_list:
        s_RL = most_simRL(s_list, xi)
        t_RL = most_simRL(t_list, xi)

        answer = sys.maxsize

        for a, b in itertools.product(s_RL, t_RL):
            answer = min(answer, min(abs(xi-a), abs(xi-b)) + abs(a-b))

        print(answer)
x = input().split()
s = input()
n = int(x[0])
a = int(x[1])
b = int(x[2])
c = int(x[3])
d = int(x[4])


kome_flag = False
santen_flag = False

b_s = s[a:]

if '...' in b_s:
  santen_flag = True
if not '##' in b_s:
  kome_flag = True
    
if not '#' in b_s:
  print('Yes')
else:
  if c < d:
  	if kome_flag:
    	print('Yes')
  	else:
    	print('No')

	if d < c:
  		if kome_flag and santen_flag:
    		print('Yes')
  		else:
    		print('No')
    
if not '#' in b_s:
  

### FIXED CODE ###

x = input().split()
s = input()
n = int(x[0])
a = int(x[1])
b = int(x[2])
c = int(x[3])
d = int(x[4])
 
 
kome_flag = False # ##がないとTrue
santen_flag = False # ... があればTrue
 
a_s = s[a:c]
b_s = s[b:d]
 
 
if d < c:
  if '...' in s[b-2:d+1]:
    santen_flag = True
kome_flag = True
if '##' in a_s or '##' in b_s:
  kome_flag = False
    

if True:
	if c < d:
		if kome_flag:
			print('Yes')
		else:
			print('No')
 
	if d < c:
		if kome_flag and santen_flag:
			print('Yes')
		else:
			print('No')
#106 A

A=int(input())
B=int(input())
print(A*B - (A+B-1))

### FIXED CODE ###

#106 A

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

print(A*B - (A+B-1))
N = int(input())

lis = []

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

first = []*N

for i in range(N):
  num = lis[i]
  first[num] = i
  
for i in range(N):
  print(first[i],end=' ')

### FIXED CODE ###


N = int(input())
lis = []
lis = list(map(int,input().split()))
first = [0]*N

for i in range(N):
    num = lis[i] - 1
    first[num] = i

for i in range(N):
    print(first[i]+1,end=' ')
print()
import math
x1, y1, x2, y2 = map(int, input().split())
print(((y2-y1)**2 + (x2-x1)**2)**(1/2))



### FIXED CODE ###

x1, y1, x2, y2 = map(float, input().split())
print(((y2-y1)**2 + (x2-x1)**2)**(1/2))
n,m = map(int,input().split())

s = [0]*n

for i in range(m):
    keta, num = map(int,input().split())
    if s[keta-1] == 0 or s[keta-1] == num:
        s[keta-1] = num
    else:
        pirnt(-1)
        exit()

if s[0] != 0:
    print(*s, sep ="")
else:
    print(-1)

### FIXED CODE ###

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

s = [0]*n

for i in range(m):
    keta, num = map(int,input().split())
    if keta == 1 and num == 0 and n != 1:
        print(-1)
        exit()
    if s[keta-1] == 0 or s[keta-1] == num:
        s[keta-1] = num
    else:
        print(-1)
        exit()

if s[0] != 0:
    print(*s, sep ="")
elif s[0] == 0 and n == 1:
    print(0)
elif s[0] == 0 and n != 1:
    s[0] = 1
    print(*s, sep ="")
else:
    print(-1)
A, B, C, D, E, F = map(int, input().split())
A, B = 100 * A, 100 * B
W = set()
S = set()

for i in range(F // A+1):
    for j in range(F // B+1):
        w = A * i + B * j
        if w <= F:
            W.add(w)

for i in range(F // C+1):
    for j in range(F // D+1):
        s = C * i + D * j
        if s <= F:
            S.add(s)

S.remove(0)
W.remove(0)
max_rat = -24
for w in W:
    for s in S:
        if w + s <= F and s <= w / 100 * E:
            rat = s / (s + w)
            if rat > max_rat:
                x, y, max_rat = w, s, rat

print(x + y, y)


### FIXED CODE ###

A, B, C, D, E, F = map(int, input().split())
A, B = 100 * A, 100 * B
W = set()
S = set()

for i in range(F // A+1):
    for j in range(F // B+1):
        w = A * i + B * j
        if w <= F:
            W.add(w)

for i in range(F // C+1):
    for j in range(F // D+1):
        s = C * i + D * j
        if s <= F:
            S.add(s)

max_rat = -24
for w in W:
    for s in S:
        if w + s <= F and s <= w / 100 * E and s+w!=0:
            rat = s / (s + w)
            if rat > max_rat:
                x, y, max_rat = w, s, rat

print(x + y, y)
import math
L = [input() for _ in range(5)]
lm = 10
v = 0
for l in L:
  if int(l[-1])<lm and l[-1]!='0':
    lm = int(l[-1])
    v = int(l)
t = 0
L.remove(str(v))
for l in L:
  t += math.ceil(int(l)/10)*10
print(t + v)

### FIXED CODE ###

import math
L = [input() for _ in range(5)]
lm = int(L[0][-1])
v = int(L[0])
for l in L:
  if int(l[-1])<lm and l[-1]!='0':
    lm = int(l[-1])
    v = int(l)
t = 0
L.remove(str(v))
for l in L:
  t += math.ceil(int(l)/10)*10
print(t + v)
n = int(input())
a = int(input())

if a<=(n%500):
    print("Yes")
else:
    prit("No")


### FIXED CODE ###

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

if a>=(n%500):
    print("Yes")
else:
    print("No")
from fractions import gcd

N=int(input())
a_list = list(map(int, input().split()))
MOD = 10**9+7


def cal_lcm(a, b):
  return int(a*b/gcd(a,b))


lcm = 1
ans = 0
for i in range(N):
  lcm_ = cal_lcm(lcm, a_list[i])
  ans = ans*int(lcm_/lcm) % MOD
  ans = (ans + int(lcm_/a_list[i])) % MOD
  lcm = lcm_

print(ans)

### FIXED CODE ###

from fractions import gcd
 
N=int(input())
a_list = tuple(int(i) for i in input().split())
MOD = 10**9+7

def cal_lcm(a, b):
  return int(a*b//gcd(a,b))

lcm = 1
for i in range(N):
  lcm = cal_lcm(lcm, a_list[i])
  
ans = 0
for i in range(N):
  ans += lcm//a_list[i]
print(ans%MOD)
#"""
import sys
input = sys.stdin.readline
#"""

N=int(input())
A = [list(map(int,input().split())) for _ in [0]*N]

V = {(i,j):0 for i in range(N) for j in range(i+1,N)}
Ef = {(i,j):[] for i in range(N) for j in range(i+1,N)}
for i,B in enumerate(A):
    k1 = (0,B[0]-1)
    for j in range(N-2):
        a1 = B[j+1]-1
        k0 = k1
        k1 = (j,a1) if j<a1 else (a1,j)
        Ef[k0].append(k1)
        V[k1] += 1

q = [k for k in V if V[k] == 0]
ans = 0
rmv = 0
while q:
    qq = []
    for k in q:
        for k2 in Ef[k]:
            V[k2] -= 1
            rmv += 1
            if V[k2] == 0 : qq.append(k2)
    ans += 1
    q = qq
if rmv != N*(N-2) : ans = -1
print(ans)

### FIXED CODE ###

#"""
import sys
input = sys.stdin.readline
#"""
def main():
    def get_key(i,j):
        if i<j: i,j = j,i
        return i*N+j
    N=int(input())
    A = [list(map(int,input().split())) for _ in [0]*N]
    V = [-1]*(N*N)
    for i in range(N):
        for j in range(i+1,N):
            V[get_key(i,j)] = 0
    Ef = [[] for _ in V]

    for i,B in enumerate(A):
        a0 = B[0]-1
        k1 = (i,a0)
        for a1 in B[1:]:
            a1 -= 1
            k0 = k1
            k1 = (i,a1)
            Ef[get_key(*k0)].append(get_key(*k1))
            V[get_key(*k1)] += 1

    q = [i for i,v in enumerate(V) if v == 0]
    ans = 0
    rmv = 0
    while q:
        qq = []
        for i in q:
            for j in Ef[i]:
                V[j] -= 1
                rmv += 1
                if V[j] == 0 : qq.append(j)
        ans += 1
        q = qq
    if rmv != N*(N-2) : ans = -1
    print(ans)
main()
s = input()

if s == 'A':
  print('T')
elfi s == 'T':
  print('A')
elif s == 'C':
  print('G')
else:
  print('C')

### FIXED CODE ###

b = input()

if b == 'A': print('T')
elif b == 'T': print('A')
elif b == 'G': print('C')
else: print('G')
'''input
3 81
33 105 57
'''
from fractions import gcd
n,x = map(int,raw_input().split())
arr = map(int,raw_input().split())
arr.append(x)
arr.sort()
diff = []
for i in range(1,n):
	diff.append(arr[i]-arr[i-1])
gc = diff[0]
for i in range(1,len(diff)):
	gc = gcd(gc,diff[i])
print gc


### FIXED CODE ###

'''input
2 1
555 556
'''
from fractions import gcd
n,x = map(int,raw_input().split())
arr = map(int,raw_input().split())
arr.append(x)
arr.sort()
diff = []
for i in range(1,n+1):
	diff.append(arr[i]-arr[i-1])
gc = diff[0]
for i in range(1,len(diff)):
	gc = gcd(gc,diff[i])
print gc