Harryxun/stf_run huggingface dataset:
#!/usr/bin/env python3

import heapq
import sys
input=sys.stdin.readline

t=int(input())
for _ in range(t):
    n=int(input())
    arr=[list(map(int,input().split())) for _ in range(n)]
    head=[]
    tail=[]
    for k,l,r in arr:
        if l>=r or k==n:
            head.append((k,l,r))
        else:
            tail.append((k,l,r))
    head=sorted(head,key=lambda x:x[0])
    q=[]
    cnt=0
    ans=[]
    for k,l,r in head:
        heapq.heappush(q,(l-r,l))
        cnt+=1
        while cnt>k:
            tmp,val=heapq.heappop()
            ans.append((tmp,val-tmp))
            cnt-=1
    ans+=list(q)
    cnt=len(ans)
    tail2=[]
    for k,l,r in tail:
        if k<=cnt:
            ans.append((l-r,r))
        else:
            tail2.append((k,l,r))
    tail2=sorted(tail2,reverse=True,key=lambda x:x[0])
    q2=[]
    cnt2=0
    for k,l,r in tail2:
        heapq.heappush(q2,(r-l,r))
        cnt2+=1
        while cnt2>(n-k+1):
            tmp,val=heapq.heappop()
            ans.append((tmp,val-tmp))
            cnt-=1
    ans+=list(q2)
    ret=0
    for _,val in ans:
        ret+=val
    print(ret)

### FIXED CODE ###

#!/usr/bin/env python3

import heapq
import sys
input=sys.stdin.readline

t=int(input())
for _ in range(t):
    n=int(input())
    arr=[list(map(int,input().split())) for _ in range(n)]
    q=[]
    ans=0
    camels1=[[] for _ in range(n+1)]
    camels2=[[] for _ in range(n+1)]
    for k,l,r in arr:
        ans+=min(l,r)
        if l>=r:
            camels1[k].append((l,r))
        else:
            camels2[k].append((l,r))
    for i in range(1,n+1):
        for l,r in camels1[i]:
            heapq.heappush(q,l-r)
        while len(q)>i:
            heapq.heappop(q)
    while len(q)!=0:
        ans+=heapq.heappop(q)
    for i in range(n,0,-1):
        for l,r in camels2[i]:
            heapq.heappush(q,r-l)
        while len(q)>(n-i):
            heapq.heappop(q)
    while len(q)!=0:
        ans+=heapq.heappop(q)
    print(ans)
N = int(input())
a = list(map(int, input().split()))

def gcd(a, b):
  if b == 0:
    return a
  return gcd(b, a%b)

def lcm(a, b):
  return a*b/gcd(a,b)

alcm = a[0]
for i in a[1:]:
  alcm = lcm(alcm, i) 

res = 0

for i in range(N):
  res += (alcm-1) % a[i]

print(int(res))

### FIXED CODE ###

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

def gcd(a, b):
  if b == 0:
    return a
  return gcd(b, a%b)

def lcm(a, b):
  return a*b//gcd(a,b)

alcm = a[0]
for i in a[1:]:
  alcm = lcm(alcm, i)

res = 0

for i in range(N):
  res += (alcm-1) % a[i]

print(int(res))
while True:
    try:
        line = input()
    except:
        break
    a, b, c = map(int, line.strip().split())
    print('YES' if a**2 + b**2 == c**2 else 'NO')

### FIXED CODE ###

n = int(input())
for i in range(n):
    a, b, c = sorted(map(int, input().strip().split()))
    print('YES' if a**2 + b**2 == c**2 else 'NO')
import numpy as np

r,c = map(int,input().split())
table = [[0]*c for i in range(r)]




### FIXED CODE ###

r,c = map(int,input().split())
table = [[0]*(c+1) for i in range(r+1)]

for i in range(r):
    table[i] = list(map(int,input().split()))
    table[i].append(sum(table[i]))
    for j in range(c+1):
        table[r][j] += table[i][j]

for i in range(r+1):
    for j in range(c+1):
        if(j == c):
            print("%d" %(table[i][j]),end="")
        else:
            print("%d " %(table[i][j]),end="")
    print()
K,N = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

c = A[0]+(K-A[N-1])

for i in range(1,N+1):
    d = max(c,A[i]-A[i-1])

print(K-d)


### FIXED CODE ###

k,n = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
c = a[0] + (k - a[n-1])
for i in range(1,n):
  c = max(c,a[i] - a[i-1])
print(k-c)
if input()==1:
  print("Hello World")
else:
  print(int(input()) + int(input()))

### FIXED CODE ###

if input()=="1":
  print("Hello World")
else:
  print(int(input()) + int(input()))
import math
print(math.ceil(math.log(int(input()), int(input()))))

### FIXED CODE ###

n, k = map(int,input().split())
ans = 0
while (n > 0):
    ans += 1
    n //= k
print(ans + n%k)
n,q=map(int,input().split())
g=[[] for i in range(n)]

for i in range(n-1):
  a,b=map(int,input().split())
  g[a-1].append(b-1)
  g[b-1].append(a-1)
  
add=[0]*n

for i in range(q):
  p,x=map(int,input().split())
  add[p-1]+=x
  
ans=[0]*n
def dfs(v,p,value):
  value+=add[v]
  ans[v]=value
  for j in g[v]: 
    if j==p: continue
    dfs(j,v,value)
      
      
dfs(0,-1,0)

print(*ans)




### FIXED CODE ###

import collections

n,q=map(int,input().split())
cnt=[0]*(n+1)
g=[[] for i in range(n+1)]
for i in range(n-1):
  a,b=map(int,input().split())
  g[a].append(b)
  g[b].append(a)
for i in range(q):
  v,val=map(int,input().split())
  cnt[v]+=val
q=collections.deque()
q.append(1)
checked=[0]*(n+1)
while q:
  v=q.pop()
  checked[v]=1
  for i in g[v]:
    if checked[i]==1:
      continue
    cnt[i]+=cnt[v]
    q.append(i)
print(*cnt[1:])
A,P=map(int,input().split())
print((3A+P)//2)


### FIXED CODE ###

A,P=map(int,input().split())
print((3*A+P)//2)
S = input()

def AGCT(S,i):
    if S[i] == "A" or S[i] == "T" or S[i] == "G" or S[i] == "C":
        return 0
    else:
        return 1

c = 0
ANS = []
for i in range(len(S)):
    if AGCT(S,i) == 0:
        c += 1
    else:
        ANS.append(c)
        c = 0
print(max(ANS))

### FIXED CODE ###

S = input()

def AGCT(S,i):
    if S[i] == "A" or S[i] == "T" or S[i] == "G" or S[i] == "C":
        return 0
    else:
        return 1

c = 0
ANS = []
for i in range(len(S)):
    if AGCT(S,i) == 0:
        c += 1
    else:
        ANS.append(c)
        c = 0
ANS.append(c)
print(max(ANS))
import collections  

n = int(input())

s = []
for i in range(n):
s.append(str(sorted(input())))

def f(a):
  if a == 0:
    return 1
  else:
    return a * f(a - 1)
  
cnt = 0
for (c, m) in collections.Counter(s):
	combi = f(m - 1)
    if combi != 1:
      cnt += combi
    
print(cnt)

### FIXED CODE ###

import collections  

n = int(input())

s = []
for i in range(n):
    s.append(str(sorted(input())))

cnt = 0
for (c, m) in collections.Counter(s).items():
    cnt += m * (m - 1) // 2
    
print(cnt)
s = str(input())[::-1]

tmp_amari = [0]*2019

#amari = 0
num = 0
order = 1
for i in s:
    num += int(i)*order
    num %= 2019
    #print(num)
    tmp_amari[num] += 1
    order *= 10

#tmp_print = [i for i in tmp_amari if i > 0]
#print(tmp_print)

ans = 0
ans += tmp_amari[0]

for i in tmp_print:
    ans += (i*(i-1))//2

print(ans)


### FIXED CODE ###


s = input()[::-1]
from collections import defaultdict
amari = defaultdict(int)
keta_ = defaultdict(int)

cur = 0
keta = 1

for i in range(len(s)):
    cur += int(s[i]) * keta
    cur %= 2019

    keta *= 10
    keta %= 2019
    
    amari[cur] += 1
    keta_[keta] += 1

#print('%')
#print(2114%2019)
#print(181712114%2019)

#print(81712114%2019)
#print(1817181712114%2019)

#print('%')

#print(amari)
#print(keta_)
ans = 0
if 0 in amari:
    ans += amari[0]

for n in amari.values():
    ans += (n * (n-1)) // 2
  
print(ans)
n=int(ibput())
 
r=0
 
for i in range(1,n+1):
	if len(str(i))%2==1:
		r+=1
print(r)

### FIXED CODE ###

n=int(input())
 
r=0
 
for i in range(1,n+1):
	if len(str(i))%2==1:
		r+=1
print(r)
_, k = input().split()
 
prices = input().split().map(lambda x : int(x))
 
prices.sort()
 
sum = 0
for i in range(k):
	sum += prices[i]
print(sum)

### FIXED CODE ###

_, k = input().split()
 
prices = list(map(lambda x : int(x), input().split()))
 
prices.sort()
 
sum = 0
for i in range(int(k)):
	sum += prices[i]
print(sum)
import numpy as np
K,N = map(int,input().split())
li = np.array(list(map(int,input().split())))
maxd=(K-li[N-1])+li[0]
for i in range(N-1):#i番目の家を出発地にした時の最小距離を順に求めていく
  maxd=max(maxd, li[i+1]-li[i]) 
print(K-maxd)

### FIXED CODE ###

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

result = A[0] - A[N - 1] + K
for i in range(N - 1):
    result = max(result, A[i + 1] - A[i])
print(K - result)
N = int(input())
graph = [[] for _ in range(N+1)] #木構造を入れておく
long = [0] * (N+1) #Kから任意のノードまでの距離

for i in range(N-1):
  x, y, z = map(int, input().split())
  graph[x].append([y, z])
  graph[y].append([x, z])
  
Q, K = map(int, input().split())
x = list()
y = list()

for i in range(Q):
  x_i, y_i = map(int, input().split())
  x.append(x_i)
  y.append(y_i)

       
def dfs(n, np):
    for nc in graph[n]:
        if nc[0] == np:
            continue
        else:
            long[nc[0]] = long[n] + nc[1]
            dfs(nc[0], n)
 
 
dfs(K, 0)

for i in range(Q):
  ans = long[x[i]] + long[y[i]]
  print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(500000)
 
N = int(input())
ABC = [list(map(int, input().split())) for i in range(N-1)]
Q, K = map(int, input().split())
D = [0] * (N+1)
L = [[] for i in range(N+1)]
for a, b, c in ABC:
    L[a].append([b, c])
    L[b].append([a, c])
 
 
def dfs(n, np):
    for nc in L[n]:
        if nc[0] == np:
            continue
        else:
            D[nc[0]] = D[n] + nc[1]
            dfs(nc[0], n)
 
 
dfs(K, 0)
for i in range(Q):
    x, y = map(int, input().split())
    print(D[x] + D[y])
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

n, k = map(int, input().split())
p = [int(x) - 1 for x in input().split()]
c = [int(x) for x in input().split()]

ans = -float('inf')
for i in range(n):
    now = i
    cnt = 0
    c_sum = [0]
    s = set()
    while True:
        s.add(now)
        c_sum.append(c_sum[-1] + c[now])
        now = p[now]
        cnt += 1
        if now in s:
            break
    if k <= cnt:
        ans = max(ans, max(c_sum[1: min(k + 1, len(c_sum))]))
    else:
        temp = c_sum[-1]
        if cnt == 0:
            continue
        q = k // cnt
        temp *= q
        q = k - q*cnt
        temp += max(c_sum[1:min(q + 1, len(c_sum))])
        ans = max(ans, temp, max(c_sum[1:]))
print(ans)




    

### FIXED CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

n, k = map(int, input().split())
p = [int(x) - 1 for x in input().split()]
c = [int(x) for x in input().split()]

ans = -float('inf')
for i in range(n):
    now = i
    c_sum = [0]
    s = set()
    cnt = 0
    while True:
        s.add(now)
        c_sum.append(c_sum[-1] + c[now])
        cnt += 1
        now = p[now]
        if now in s:
            break
    c_sum = c_sum[1:]
    if k < cnt:
        ans = max(ans, max(c_sum[: k]))
    else:
        score = c_sum[-1]
        count = k // cnt
        k_ = k - count*cnt
        score *= count
        score_2 = score - c_sum[-1]
        score_2 += max(c_sum)
        if k_ > 0:
            score += max(0, max(c_sum[:k_]))
        ans = max(ans, score, max(c_sum), score_2)
print(ans)
n, m, l = [int(i) for i in input().split()]

A = []
B = []
C = []

for ni in range(n):
    A.append([int(i) for i in input().split()])

for mi in range(m):
    B.append([int(i) for i in input().split()])

for i in range(n):
    C.append([int(i) for i in input().split()])
    for j in range(l):
        C[i].append(0)
        for k in range(m):
            C[i][j] += A[i][k] * B[k][j]
            
for li in range(l):
    print(" ".join([str(s) for s in C[li]]))
    

### FIXED CODE ###

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

A = []
B = []
C = []

for ni in range(n):
    A.append([int(i) for i in input().split()])

for mi in range(m):
    B.append([int(i) for i in input().split()])

for i in range(n):
    C.append([])
    for j in range(l):
        C[i].append(0)
        for k in range(m):
            C[i][j] += A[i][k] * B[k][j]

for ni in range(n):
    print(" ".join([str(s) for s in C[ni]]))
import sys


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

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

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


class UnionFindPathCompression():
    def __init__(self, n):
        self.parents = list(range(n))

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

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

        if x == y:
            return

        self.parents[y] = x

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}


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

for i in range(M):
    A, B = map(int, input().split())
    uf.union(A - 1, B - 1)

hoge = [uf.find(i) for i in range(N)]

from collections import defaultdict
d = defaultdict(int)
for key in hoge:
    d[key] += 1

#print(d.values())
print(max(d.values()))

	          #ソート
"""
hoge = list(uf.all_group_members().values())
Max = 0
for i in range(len(hoge)):
    Max = max(Max, len(hoge[i]))

print(Max)
"""

### FIXED CODE ###

import sys
from collections import defaultdict
import collections

sys.setrecursionlimit(1000000)

class UnionFindPathCompression():
    def __init__(self, n):
        self.parents = list(range(n))

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

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

        if x == y:
            return

        self.parents[y] = x


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

for i in range(M):
    A, B = map(int, input().split())
    uf.union(A - 1, B - 1)

hoge = [uf.find(i) for i in range(N)]

#print(hoge)
hogehoge = collections.Counter(hoge).most_common()

print(hogehoge[0][1])
a,b = [int(i) for i in input().split]

if a > b:
    print("a > b")
elif a < b:
    print("a < b")
else:
    print("a == b")

### FIXED CODE ###

a,b = [int(i) for i in input().split()]

if a > b:
    print("a > b")
elif a < b:
    print("a < b")
else:
    print("a == b")
NL = ["3", "3"]
N = int(NL[0])
L = int(NL[1])

st = []
for i in range(N):
    a = input()
    st.append(a)
s_st = sorted(st)
dic = ""
for j in range(len(s_st)):
    dic += s_st[j]
print(dic)
  

### FIXED CODE ###

NL = input().split()
N = int(NL[0])
L = int(NL[1])

st = []
for i in range(N):
    a = input()
    st.append(a)
s_st = sorted(st)
dic = ""
for j in range(len(s_st)):
    dic += s_st[j]
print(dic)
N, M = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)

# xを作るために使うマッチの本数
h = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

# dp[i] = i 本のマッチ棒を使って、条件を満たす整数を作るときの最大桁数
dp = [-1] * (N + 1)
dp[0] = 0

for i in range(N + 1):
    for a in A:
        if i - h[a] < 0: continue
        dp[i] = max(dp[i-h[a]] + 1, dp[i])

digit = dp[N]
ans = ''

n = N
for d in range(digit):
    for a in A:
        if dp[n - h[a]] == digit - 1:
            ans += str(a)
            n -= h[a]
            digit -= 1
            break
print(ans)

### FIXED CODE ###

N, M = map(int, input().split())
A = [int(i) for i in input().split()]

# dp[i] = i本使ってできる最大の数

# xを作るために使うマッチの本数
h = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

dp = [-1] * (N + 1)
dp[0] = 0

for i in range(N + 1):
    for a in A:
        if i - h[a] < 0: continue
        dp[i] = max(10*dp[i-h[a]] + a, dp[i])

print(dp[N])
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 2*10**6+10
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

r1, c1, r2, c2 = map(int, input().split())

def g(r, c):
  return cmb(r+c+2,c+1,mod)-1

ans = g(r2,c2)-g(r2,c1-1)-g(r1-1,c2)+g(r1-1,c1-1)
print(ans%MOD)


### FIXED CODE ###

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 2*10**6+10
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

r1, c1, r2, c2 = map(int, input().split())

def g(r, c):
  return cmb(r+c+2,c+1,mod)-1

ans = g(r2,c2)-g(r2,c1-1)-g(r1-1,c2)+g(r1-1,c1-1)
print(ans%mod)
t = int(input())
lst = map(int,raw_split())
sum = 0
for i in range(t):
  sum *= lst[i]
if(sum <= 10000000000000000000000000000000000000000000):
  print(sum)
else:
  print(-1)
  

### FIXED CODE ###

import sys
inp = int(input())
lst = list(map(int,input().split()))
sum = 1
if 0 in lst:
    print(0)
    sys.exit(0)
else:
    num = 1;
    for i in range(inp):
        num *= lst[i]
        if num > 10 ** 18:
            print("-1")
            sys.exit()
    print(num)
def L(n):
    a = 2
    b = 1
    for i in range(n - 1):
        res = 0
        res += a + b
        a = b
        b = res
    return res
print(L(int(input())))

### FIXED CODE ###

def L(n):
    a = 2
    b = 1
    res = 1
    for i in range(n - 1):
        res = 0
        res += a + b
        a = b
        b = res
    return res
print(L(int(input())))
N, K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))

A_itta = [None] * N
A_cycle = '1'

i = 0
while True:
    # print('stay', i)

    # 訪問フラグ
    A_itta[i] = 1

    # 訪問リスト
    A_cycle = A_cycle + str(A[i])

    # 次の番号
    i = A[i] - 1

    # print('next', i)

    # 行ったことある
    if A_itta[i]:
        # print('loop at=', i)
        break

# 最初の町からループする場合
if i == 0:
    cycle = A_cycle[0:-1]
    ans = cycle[K % len(cycle)]

else:
    cycle = A_cycle[i + 1:-1]
    ans = cycle[(K - (i + 1)) % len(cycle)]

print(ans)


### FIXED CODE ###

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

visited = [False for _ in range(N)]
now = 0

cycle = []

while True:
    cycle.append(now)
    visited[now] = True
    now = A[now] - 1

    if visited[now]:
        break

total_len = len(cycle)

cycle_start = 0

for i in range(total_len):
    if cycle[i] == now:
        cycle_start = i
        break

cycle_len = total_len - cycle_start

if K < cycle_start:
    print(cycle[K] + 1)
else:
    print(cycle[cycle_start + (K - cycle_start) % cycle_len] + 1)
import heapq

if __name__ == "__main__":
    K,T = map(int, input().split())
    data = list(map(int, input().split()))
    cake = []
    for i,x in enumerate(data):
        cake.append([x, i])
    heapq._heapify_max(cake)
    while (len(cake) > 1):
        p = heapq._heappop_max(cake)
        q = heapq._heappop_max(cake)
        p[0] -= 1
        q[0] -= 1
        if p[0] > 0:
            heapq.heappush(cake, p)
        if q[0] > 0:
            heapq.heappush(cake, q)
    result = 0
    if len(cake) > 0:
        t = heapq._heappop_max(cake)
        result = t[0]
    print (max(0, result - 1))


### FIXED CODE ###

import heapq

if __name__ == "__main__":
    K,T = map(int, input().split())
    data = list(map(int, input().split()))
    cake = []
    for i,x in enumerate(data):
        cake.append([x, i])
    heapq._heapify_max(cake)
    while (len(cake) > 1):
        heapq._heapify_max(cake)
        p = heapq.heappop(cake)
        q = heapq.heappop(cake)
        # print (p,q)
        p[0] -= 1
        q[0] -= 1
        if p[0] > 0:
            heapq.heappush(cake, p)
        if q[0] > 0:
            heapq.heappush(cake, q)
    result = 0
    if len(cake) > 0:
        t = heapq.heappop(cake)
        result = t[0]
    print (max(0, result - 1))
import sys
a,b=map(int,input().split())
c=list(map(int,input().split()))
d=0
c.sort()
e=-1
f=0
for i in range(a):
  d+=c[i]

for i in range(b):
   if b>0:
      b-=1
      f+=1
      
      d-=c[e]
      e-=1
    if d<0:
      print(f)
      sys.exit()
while 1:
  d-=c[e]
  f+=1
  if d<0:
    print(f)
  else:
    pass

### FIXED CODE ###

N, K = map(int, input().split())
H = list(map(int, input().split()))
H.sort()

if N - K < 0:
  print(0)
else:
  print(sum(H[:N-K]))
import fractions as frac
a, b, c, d, e, f = map(int, input().split())
memo=[[(-1, -1)]*10000 for i in range(1000)]
func = lambda t: frac.Fraction(t[0], t[1]) if t[1]>0 else -10
def dp(s, w):
    if w*e<s or w*100+s>f:
        return (-1, -1)
    m=memo[s][w]
    if m[0]>0:
        return memo[s][w]
    p0=(s,w) 
    p1=dp(s, w+a)
    p2=dp(s, w+b)
    p3=dp(s+c, w)
    p4=dp(s+d, w)
    memo[s][w]=max(p0, p1, p2, p3, p4, key = func) if w>0 else max(p1, p2, key = func)
    return memo[s][w]
    
ans=dp(0,0)
print(ans[0]+ans[1]*100, ans[0])

### FIXED CODE ###

import fractions as frac
a, b, c, d, e, f = map(int, input().split())
memo=[[(-1, -1)]*1000 for i in range(10000)]
func = lambda t: frac.Fraction(t[0], t[1]) if t[1]>0 else -10
def dp(s, w):
    if w*e<s or w*100+s>f:
        return (-1, -1)
    m=memo[s][w]
    if m[0]>0:
        return m
    p0=(s,w) 
    p1=dp(s, w+a)
    p2=dp(s, w+b)
    p3=dp(s+c, w)
    p4=dp(s+d, w)
    memo[s][w]=max(p0, p1, p2, p3, p4, key = func) if w>0 else max(p1, p2, key = func)
    return memo[s][w]
    
ans=dp(0,0)
print(ans[0]+ans[1]*100, ans[0])