Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###


A, B, C, D, E, F = map(int, input().split())

density = 0
ans = (0, 0)

for a in range(31):
  for b in range(31):
    for c in range(100):
      for d in range(100):
        water = 100*a*A + 100*b*B
        suger = c*C + d*D
         
        if water + suger > F or water == 0:
          continue

        if suger > 0 and (suger / water * 100)  > E:
          continue
        
        tmp = (100 * suger)  / (water + suger)

        if tmp >= density:
          density = tmp
          ans = (water+suger, suger)

print(*ans)

### FIXED CODE ###


def solve():
    
    A, B, C, D, E, F = map(int, input().split())
    memo = {}
    
    for a in range(31):
        for b in range(31):
            for c in range(101):
                for d in range(101):
                    w = (100*A)*a + (100*B)*b
                    s = C*c + D*d
                    if w ==0:
                        break
                    if w+s > F:
                        break
                    else:
                        if w/100 * E >= s:
                            density = 100*s/(w+s)
                            memo[a,b,c,d] = density
    
    max_v = max(memo.values())
    
    for k, v in memo.items():
        if v == max_v:
            print((100*A)*k[0] + (100*B)*k[1] + C*k[2] + D*k[3], C*k[2] + D*k[3] )
            break
solve()
### BUGGY CODE ###

import sys
input = sys.stdin.readline
import numpy as np

n, k = map(int, input().split())
AA =[]
c =False
for a in input().strip().split():
    a = int(a)
    if not c:
        AA+= [a]
        if len(AA) == k:
            c = True
    else:
        base = AA[0]
        if a - base > 0:
            print("Yes")
        else:
            print("No")
        AA = AA[1:]+[a]


### FIXED CODE ###

n, k = map(int, input().split())
AA =[int(a) for a in input().split()]


for b, t in zip(AA, AA[k:]):
    if t > b:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

from math import floor
from fractions import gcd
N,M = map(int,input().split())

def prime_decomposition(n):
  i = 2
  d = {2:0}
  while i * i <= n:
    while n % i == 0:
      n //= i
      if i not in d:
          d[i] = 0
      d[i] += 1
    i += 1
  if n > 1:
    if n not in d:
        d[n] = 1
  return d
A = list(map(int,input().split()))
for i in range(N):
    A[i] //= 2

l = A[0]
for i in range(1,N):
    l = (l*A[i])//gcd(l,A[i])
ans = floor((M/l+1)/2)
n = prime_decomposition(l)[2]
p2 = 2**n
for i in range(N):
    if A[i]%p2 != 0:
        ans = 0
        break
print(ans)

### FIXED CODE ###

from math import floor
from fractions import gcd
N,M = map(int,input().split())

def prime_decomposition(n):
  i = 2
  d = {2:0}
  while i * i <= n:
    while n % i == 0:
      n //= i
      if i not in d:
          d[i] = 0
      d[i] += 1
    i += 1
  if n > 1:
    if n not in d:
        d[n] = 1
  return d
A = list(map(int,input().split()))
for i in range(N):
    A[i] //= 2

l = A[0]
for i in range(1,N):
    l = (l*A[i])//gcd(l,A[i])
    if l>M:
        break
ans = floor((M/l+1)/2)
n = prime_decomposition(l)[2]
p2 = 2**n
for i in range(N):
    if A[i]%p2 != 0:
        ans = 0
        break
print(ans)
### BUGGY CODE ###

import collections
N=int(input())
A=[int(s) for s in input().split(" ")]

for i in range(1,N+1):
    if A==[]:
        break
    count=A.count(i)
    print(count)

### FIXED CODE ###

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

List = [0] * (n)
for i in range(n-1):
    List[A[i]-1] += 1

for i in List:
    print(i)
### BUGGY CODE ###

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n + 1)]
        self.rank = [0] * (n + 1)
        self.size = [1] * (n + 1)

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.find(self.par[x])

    def sizeCheck(self, x):
        x = self.find(x)
        return self.size[x]

    def sameCheck(self, x, y):
        return self.find(x) == self.find(y)

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
                
n, m = map(int, input().split())
bridge = []
for i in range(m):
  bridge.append(list(map(int, input().split())))
ans = [int(n * (n - 1) / 2)]

uf = UnionFind(n)
index = m - 1
while index > 0:
  li = bridge[index]
  if uf.sameCheck(li[0], li[1]):
    ans = [ans[0]] + ans
    index -= 1
  else:
    s0 = uf.sizeCheck(li[0])
    s1 = uf.sizeCheck(li[1])
    uf.union(li[0], li[1])
    ans = [ans[0] - s0 * s1] + ans
    index -= 1
print(*ans, sep = "\n")
  

### FIXED CODE ###

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n + 1)]
        self.rank = [0] * (n + 1)
        self.size = [1] * (n + 1)

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.find(self.par[x])

    def sizeCheck(self, x):
        x = self.find(x)
        return self.size[x]

    def sameCheck(self, x, y):
        return self.find(x) == self.find(y)

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

n, m = map(int, input().split())
bridge = []
for i in range(m):
  bridge.append(list(map(int, input().split())))
ans = [0] * m
ans[m - 1] = int(n * (n - 1) / 2)

uf = UnionFind(n)
index = m - 1
while index > 0:
  li = bridge[index]
  if uf.sameCheck(li[0], li[1]):
    ans[index - 1] = ans[index]
    index -= 1
  else:
    s0 = uf.sizeCheck(li[0])
    s1 = uf.sizeCheck(li[1])
    uf.union(li[0], li[1])
    ans[index - 1] = ans[index] - s0 * s1
    index -= 1
print(*ans, sep = "\n")
### BUGGY CODE ###

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()))
A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)
ans = []
for i in range(X):
	for j in range(Y):
		for k in range(Z):
			if ((i+1)*(j+1)*(k+1) <= K):
				ans.append(A[i]+B[j]+C[k])

ans.sort(reverse=True)
for i in range(K):
	print(ans[i])

### FIXED CODE ###

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()))
A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)
ans = []
for i in range(X):
	for j in range(min(Y,K//(i+1)+1)):
		for k in range(min(Z,K//((i+1)*(j+1))+1)):
			ans.append(A[i]+B[j]+C[k])

ans.sort(reverse=True)
for i in range(K):
	print(ans[i])
### BUGGY CODE ###

N = int(input())
a =[int(_) for _ in input().split()]
ans = 10**15
cardsum = sum(a)

for i in range(N-1):
    snuke = sum(a[:i+1])
    arai = cardsum - snuke
    diff = abs(snuke - arai)
    if diff < ans:
        ans = diff

print(ans)

### FIXED CODE ###

N = int(input())
a =[int(_) for _ in input().split()]
ans = 10**15
cardsum = sum(a)
ruiseki = [0]

for i in range(N-1):
    ruiseki.append(ruiseki[i]+a[i])
    snuke = ruiseki[i+1]
    arai = cardsum - snuke
    diff = abs(snuke - arai)
    if diff < ans:
        ans = diff

print(ans)
### BUGGY CODE ###

(n, k) = map(int, input().split(" "))

pts = []
for _ in range(n):
    (x, y) = map(int, input().split(" "))
    pts += [(x, y)]

pts.sort()

res = float("inf")
for a in pts:
    for b in pts:
        for c in pts:
            for d in pts:
                l = a[0]
                r = b[0]
                f = c[1]
                t = d[1]
                
                if not l < r or not f < t:
                    continue
        
                num = 0
                for x in pts:
                    if l <= x[0] <= r and f <= x[1] <= t:
                        num += 1
        
                if num >= k:
                    res = min(res, abs(r-l)*abs(t-f))

print(res)

### FIXED CODE ###

(n, k) = map(int, input().split(" "))

xs = []
ys = []
pts = []
for _ in range(n):
    (x, y) = map(int, input().split(" "))
    xs += [x]
    ys += [y]
    pts += [(x, y)]

xs.sort()
ys.sort()

res = float("inf")
for a in xs:
    for b in xs:
        ci = 0
        di = 1
        while di < len(ys):
            num = 0
            c = ys[ci]
            d = ys[di]
            
            for x in pts:
                if a <= x[0] <= b and c <= x[1] <= d:
                    num += 1
        
            if num >= k:
                res = min(res, abs(b-a)*abs(d-c))
                if ci < di:
                    ci += 1
                else:
                    di += 1
            else:
                di += 1

print(res)
### BUGGY CODE ###

N,M = list(map(int,input().split(" ")))
list = list(map(int,input().split(" ")))
for i in range(M):
    list.sort(reverse=True)
    list[0] = list[0] // 2
print(sum(list))

### FIXED CODE ###

N,M=list(map(int,input().split()))
import sys
A= list(map(int,sys.stdin.readline().split()))
A=[i*-1 for i in A]
import heapq
heapq.heapify(A)
for i in range(M):
    X=heapq.heappop(A)
    X=abs(X)//2*-1
    heapq.heappush(A,X)
print(abs(sum(A)))
### BUGGY CODE ###

s = input()
K = int(input())
substrings = set()
for lc in "abcdefghijklmnopqrstuvwxyz":
    if lc not in s:
        continue
    for i in range(len(s)):
        if s[i] != lc:
            continue
        for j in range(i + 1, len(s) + 1):
            substrings.add(s[i:j])
    if len(substrings) >= K:
        break
print(sorted(list(substrings))[K - 1])


### FIXED CODE ###

s = input()
K = int(input())
s_dic = {c: [] for c in "abcdefghijklmnopqrstuvwxyz"}
for i, c in enumerate(s):
    s_dic[c].append(i)
substrings = set()
for indices in s_dic.values():
    for i in indices:
        for j in range(i + 1, i + K + 1):
            substrings.add(s[i:j])
print(sorted(list(substrings))[K - 1])
### BUGGY CODE ###

import sys #追加
sys.setrecursionlimit(10**9)

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

bl = [i//2 for i in al]
from fractions import gcd
ans = 1
for b in bl:
   ans = (ans * b) // gcd(ans, b)

for a in al:
   if ans % a == 0:
      print(0)
      import sys
      sys.exit()

def ceil(a, b):
   return a // b + (a % b > 0)

print(ceil(m // ans, 2))


### FIXED CODE ###

import sys #追加
sys.setrecursionlimit(10**9)
import time
s = time.time()

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

bl = [i//2 for i in al]
from fractions import gcd
ans = 1
for b in bl:
   if time.time() - s > 1.9:
      print(0)
      import sys
      sys.exit()
   ans = (ans * b) // gcd(ans, b)

for a in al:
   if time.time() - s > 1.9:
      print(0)
      import sys
      sys.exit()
   if ans % a == 0:
      print(0)
      import sys
      sys.exit()

def ceil(a, b):
   return a // b + (a % b > 0)

print(ceil(m // ans, 2))
### BUGGY CODE ###



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

def cmp(a,b):
    if a == None:
        return True
    elif b == None:
        return False
    if len(a) > len(b):
        return False
    elif len(a) < len(b):
        return True
    else:
        if int(a) >= int(b):
            return False
        else:
            return True

dp = [None] * (N+10)
l = [0,2,5,5,4,5,6,3,7,6]
dp[0] = ""
for i in range(N+1):
    for s in A:
        if dp[i] == None and i!=0:
            continue
        ss = "".join([dp[i],s])
        if cmp(dp[i + l[int(s)]] , ss):
            dp[i + l[int(s)]] = ss
            

print(dp[N])


                





### FIXED CODE ###

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

dp = [-1 for i in range(N+10)]
l = [0,2,5,5,4,5,6,3,7,6]
dp[0] = 0
for i in range(N-1):
    for s in A:
        if dp[i] == -1 and i!=0:
            continue
        if dp[i + l[s]] < dp[i]*10+s:
            dp[i + l[s]] = dp[i]*10+s
print(dp[N])
### BUGGY CODE ###

n,a,b=map(int,input().split())
mod=10**9+7
ans=pow(2,n,mod)-1+mod*2
def c(x,y):
	p=1
	for i in range(x-y+1,x+1):
		p*=i
		p%=mod
	q=1
	for i in range(2,y+1):
		q*=i
		p%=mod
	return pow(q,mod-2,mod)*p%mod
r=ans-c(n,a)-c(n,b)
print(r%mod)

### FIXED CODE ###

n,a,b=map(int,input().split())
mod=10**9+7
ans=pow(2,n,mod)-1+mod*2
def c(x,y):
	p=1
	for i in range(x-y+1,x+1):
		p*=i
		p%=mod
	for i in range(2,y+1):
		p*=pow(i,mod-2,mod)
		p%=mod
	return p
r=ans-c(n,a)-c(n,b)
print(r%mod)
### BUGGY CODE ###

# -*- coding:utf-8 -*-
import itertools
N, P = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
odd = [ tmp for tmp in a if tmp%2 != 0]
even = [ tmp for tmp in a if tmp%2 == 0]
if P == 0:
    ans += 1
    b = sum([ len(list(itertools.combinations(odd,tmp))) for tmp in range(2, len(odd)+1, 2) ])
else:
    b = sum([ len(list(itertools.combinations(odd,tmp))) for tmp in range(1, len(odd)+1, 2) ])
c = [ len(list(itertools.combinations(even, tmp))) for tmp in range(1, len(even)+1) ]
factor = 0
for tmp in c:
    ans += tmp*b
    factor += tmp
else:
    if P == 0:
        ans += b+factor
    else:
        ans += b
print(ans)

### FIXED CODE ###

# -*- coding:utf-8 -*-
import itertools, math
N, P = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
odd = [ tmp for tmp in a if tmp%2 != 0]
even = [ tmp for tmp in a if tmp%2 == 0]
d = math.factorial(len(odd))
e = math.factorial(len(even))
if P == 0:
    ans += 1
    b = sum([ (d//math.factorial(len(odd)-tmp))//math.factorial(tmp) for tmp in range(2, len(odd)+1, 2) ])
else:
    b = sum([ (d//math.factorial(len(odd)-tmp))//math.factorial(tmp) for tmp in range(1, len(odd)+1, 2) ])
c = [ (e//math.factorial(len(even)-tmp))//math.factorial(tmp) for tmp in range(1, len(even)+1) ]
for tmp in c:
    ans += tmp*b
else:
    if P == 0:
        ans += b+sum(c)
    else:
        ans += b
print(ans)
### BUGGY CODE ###

from collections import deque

h, w = map(int, input().split())

maze = [input() for i in range(h)]

ans = 0
INF = 1e10
for j in range(h):
    for i in range(w):
        if maze[j][i] == ".":
            cnt = [[INF] * w for _ in range(h)] 
            cnt[j][i] = 0
            q = deque([(j,i)])
            while q:
                y,x = q.popleft()
                for by,bx in ((0,1),(0,-1),(1,0),(-1,0)):
                    by += y
                    bx += x 
                    if 0 <= by < h and 0 <= bx < w:
                        if maze[by][bx] == "#": continue
                        ct = cnt[y][x] + 1
                        if ct > cnt[by][bx]: continue 
                        q += [(by,bx)] 
                        cnt[by][bx] = ct
                        ans = max(ans, cnt[by][bx])


print(ans)

### FIXED CODE ###

from collections import deque

h, w = map(int, input().split())

maze = [input() for i in range(h)]

ans = 0
for j in range(h):
    for i in range(w):
        if maze[j][i] == ".":
            cnt = [[0] * w for _ in range(h)] 
            q = deque([(j,i)])
            while q:
                y,x = q.popleft()
                for by,bx in ((0,1),(0,-1),(1,0),(-1,0)):
                    ny = y + by
                    nx = x + bx
                    if 0 <= ny < h and 0 <= nx < w:
                        if maze[ny][nx] == "." and cnt[ny][nx] == 0:
                            q += [(ny,nx)]
                            cnt[ny][nx] += cnt[y][x] + 1
                            ans = max(ans, cnt[ny][nx])
                if y == j and x == i:
                    cnt[y][x] = -1


print(ans)
### BUGGY CODE ###

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

import sys

input = sys.stdin.readline
R = [[]]*n
Sin = [-1]*n
Dis = [-1]*n
Sin[0] = 0
Dis[0] = 0

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

from collections import deque

d = deque()
d.append(0)

while len(d):
  cur = d.popleft()
  for to in R[cur]:
    if Dis[to]<0:
      Dis[to] = Dis[cur] + 1
      Sin[to] = cur + 1
      d.append(to)

if min(Dis)<0:
  print('No')
  sys.exit()
print('Yes')
for i in range(1,n):
  print(Sin[i])


### FIXED CODE ###

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

import sys

input = sys.stdin.readline
R = [[] for _ in range(n)]
Sin = [-1]*n
Dis = [-1]*n
Sin[0] = 0
Dis[0] = 0

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

from collections import deque

d = deque()
d.append(0)

while len(d):
  cur = d.popleft()
  for to in R[cur]:
    if Dis[to]<0:
      Dis[to] = Dis[cur] + 1
      Sin[to] = cur + 1
      d.append(to)

if min(Dis)<0:
  print('No')
  sys.exit()
print('Yes')
for i in range(1,n):
  print(Sin[i])
### BUGGY CODE ###

N,M=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

A=sorted(A)
B=sorted(B)

l=[[0,0] for i in range(N*M+1)]

for a in A:
    if l[a][0]==1:
        print(0)
        exit()
    l[a][0]+=1
for b in B:
    if l[b][1]==1:
        print(0)
        exit()
    l[b][1]+=1

A=0
B=0
ans=1

for i in range(N*M):
    n=N*M-i
    if l[n]==[1,1]:
        A+=1
        B+=1
    elif l[n]==[1,0]:
        A+=1
        ans*=B
    elif l[n]==[0,1]:
        B+=1
        ans*=A
    else:
        ans*=A*B-(N*M-n)

print(ans%(10**9+7))


### FIXED CODE ###

N,M=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

l=[[0,0] for i in range(N*M+1)]

for a in A:
    if l[a][0]==1:
        print(0)
        exit()
    l[a][0]+=1
for b in B:
    if l[b][1]==1:
        print(0)
        exit()
    l[b][1]+=1

A=0
B=0
ans=1

for i in range(N*M):
    n=N*M-i
    if l[n]==[1,1]:
        A+=1
        B+=1
    elif l[n]==[1,0]:
        A+=1
        ans*=B
    elif l[n]==[0,1]:
        B+=1
        ans*=A
    else:
        ans*=A*B-(N*M-n)

    ans%=10**9+7

print(ans)
### BUGGY CODE ###

import sys
input=sys.stdin.readline
def main():
    r,c,k=map(int,input().split())
    v=[[0]*c for _ in range(r)]
    for _ in range(k):
        ri,ci,a=map(int,input().split())
        ri-=1
        ci-=1
        v[ri][ci]=a
    dp=[[[0]*4 for _ in range(c)] for i in range(r)]
    #print(dp)
    if v[0][0]>0:
        dp[0][0][1]=v[0][0]
    for i in range(r):
        for j in range(c):
            if i>0:
                if v[i][j]>0:
                    for k in range(min(3,j+1)+1):
                        dp[i][j][1]=max(dp[i][j][1],dp[i-1][j][k]+v[i][j])
                for k in range(4):
                    dp[i][j][k]=max(dp[i][j][k],dp[i-1][j][k])
            if j>0:
                if v[i][j]>0:
                    for k in range(min(3,j+1)+1):
                        if k>0:
                            dp[i][j][k]=max(dp[i][j][k],dp[i][j-1][k-1]+v[i][j])
                for k in range(4):
                    dp[i][j][k]=max(dp[i][j][k],dp[i][j-1][k])
    #print(dp)
    print(max(dp[r-1][c-1]))
if __name__=="__main__":
    main()

### FIXED CODE ###

import sys
input=sys.stdin.readline
def main():
    r,c,k=map(int,input().split())
    v=[[0]*c for _ in range(r)]
    for _ in range(k):
        ri,ci,a=map(int,input().split())
        ri-=1
        ci-=1
        v[ri][ci]=a
    dp=[[[0]*c for _ in range(r)] for i in range(4)]
    #print(dp)
    if v[0][0]>0:
        dp[1][0][0]=v[0][0]
    for i in range(r):
        for j in range(c):
            for k in range(4):
                if i>0:
                    dp[1][i][j]=max(dp[1][i][j],dp[k][i-1][j]+v[i][j])
                    dp[0][i][j]=max(dp[0][i][j],dp[k][i-1][j])
                if j>0:
                    if k>0:
                        dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j-1]+v[i][j])
                    dp[k][i][j]=max(dp[k][i][j],dp[k][i][j-1])
    #print(dp)
    ans=0
    for i in range(4):
        ans=max(dp[i][r-1][c-1],ans)
    return print(ans)
if __name__=="__main__":
    main()
### BUGGY CODE ###

N, M = list(map(int, input().split()))
ed = []
for _ in range(M):
    ed.append(list(map(int, input().split())))
import networkx as nx
G = nx.Graph()
G.add_edges_from(ed)
ans = 1
for comp in nx.connected_components(G):
    ans = max(ans, len(comp))
print(ans)

### FIXED CODE ###

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

def main():
    #xの根を求める
    def find(x):
        if par[x] < 0:
            return x
        else:
            par[x] = find(par[x])
            return par[x]
    #xとyの属する集合の併合
    def unite(x,y):
        x = find(x)
        y = find(y)

        if x == y:
            return False
        else:
            #sizeの大きいほうがx
            if par[x] > par[y]:
                x,y = y,x
            par[x] += par[y]
            par[y] = x
            return True

    #xとyが同じ集合に属するかの判定
    def same(x,y):
        return find(x) == find(y)

    #xが属する集合の個数
    def size(x):
        return -par[find(x)]

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

    #初期化
    #根なら-size,子なら親の頂点
    par = [-1]*n
    #print(par)
    for i in range(m):
        A,B = map(int, input().split())
        unite(A-1,B-1)
    print(max([size(i) for i in range(n)]))


if __name__ == '__main__':
    main()
### BUGGY CODE ###

D, G = map(int, input().split())
p = [list(map(int, input().split())) for _ in range(D)]
visited = [0] * D
def dfs(s, c):
  temp = 10 ** 3
  for i in range(D):
    if visited[i] == 0:
      visited[i] = 1
      if s >= p[i][0] * (i + 1) * 100 + p[i][1]:
        temp = min(temp, dfs(s - p[i][0] * (i + 1) * 100 - p[i][1], c + p[i][0]))
      else:
        temp = min(temp, -(-s // ((i + 1) * 100)) + c, p[i][0] + c)
      visited[i] = 0
  return temp
print(dfs(G, 0))

### FIXED CODE ###

D, G = map(int, input().split())
p = [list(map(int, input().split())) for _ in range(D)]
visited = [0] * D
def dfs(s, c):
  temp = 10 ** 3
  for i in range(D):
    if visited[i] == 0:
      visited[i] = 1
      if s >= p[i][0] * (i + 1) * 100 + p[i][1]:
        temp = min(temp, dfs(s - p[i][0] * (i + 1) * 100 - p[i][1], c + p[i][0]))
      else:
        temp = min(temp, -(-s // ((i + 1) * 100)) + c, p[i][0] + c)
      visited[i] = 0
  return temp
print(dfs(G, 0))
### BUGGY CODE ###

def getlist():
	return list(map(int, input().split()))

X = []
N = int(input())
for i in range(N):
	A = getlist()
	X.append([0] + A[::-1])

#日数
day = 0
while True:
	j = "No"
	check = [0] * N
	for i in range(N):
		x = X[i][-1] - 1
		if x != -1:
			if check[i] == 0 and check[x] == 0 and X[x][-1] == i + 1:
				check[i] = 1
				check[x] = 1
				X[x].pop(-1)
				X[i].pop(-1)
				j = "Yes"
	day += 1
	if j == "No":
		break

#判定
cc = "Yes"
for i in range(N):
	if X[i] != [0]:
		cc = "No"
		break

if cc == "No":
	print(-1)
else:
	print(day - 1)

### FIXED CODE ###

#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict, deque

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	#入力
	N = int(input())
	outE = defaultdict(list)
	inE = defaultdict(int)
	for i in range(N):
		A = getlist()
		for j in range(N - 2):
			a, b = sorted([A[j] - 1, i])
			c, d = sorted([A[j + 1] - 1, i])
			outE[a * N + b].append(c * N + d)
			inE[c * N + d] += 1

	#キュー初期化
	Q = []
	for i in range(N):
		for j in range(i + 1, N):
			if inE[i * N + j] == 0:
				Q.append(i * N + j)
	#print(Q)
	#計算
	judge = "Yes"
	cnt = 0
	ans = 1
	while True:
		q = []
		for i in Q:
			for j in outE[i]:
				inE[j] -= 1
				cnt += 1
				if inE[j] == 0:
					q.append(j)

		if q == []:
			break
		else:
			Q = q
		ans += 1
	# print(ans)
	# print(cnt)

	if cnt != N * (N - 2):
		print(-1)
	else:
		print(ans)

if __name__ == '__main__':
	main()
### BUGGY CODE ###

N_K = list(map(int,input().split()))
H = list(map(int,input().split()))

N = N_K[0]
K = N_K[1]

dp= [2147483647] * (N)
dp[0] = 0

for i in range(1,len(H)):
    for j in range(1, K+ 1):

        if i < j:
            break
        
        dp[i] = min(dp[i],dp[i-j] + abs(H[i]-H[i-j]))
    
print(dp[N - 1])


### FIXED CODE ###

import numpy as np

N_K = list(map(int,input().split()))
H = np.array(list(map(int,input().split())))

N = N_K[0]
K = N_K[1]

dp= np.zeros(N,dtype=np.int)

for i in range(1,len(H)):

    if i < K:
        dp[i] = np.min(dp[:i] + np.abs(H[i]-H[:i]))
    else:
        dp[i] = np.min(dp[i-K:i] + np.abs(H[i]-H[i-K:i]))
    
print(dp[N - 1])