Harryxun/stf_run huggingface dataset:
import sys,heapq,time
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False
def ddprint(x):
  if DBG:
    print(x)

n,x = inm()
blu = []
pt = 0
for i in range(n):
    b,l,u = inm()
    s = u*(x-b) + l*b
    v = s/x
    t = x
    heapq.heappush(blu, (-v,s,t,b,l,u))
    pt -= l*b

sum = 0
while len(blu)>0:
    mv,s,t,b,l,u = heapq.heappop(blu)
    nxtpt = pt + s
    ddprint("v {} b {} l {} u {} pt {} nx {} sum {}".format(v,b,l,u,pt,nxtpt,sum))
    if nxtpt < 0:
        pt = nxtpt
        sum += t
        continue
    elif nxtpt == 0:
        print(sum+t)
        exit()
    else:  # nxtpt > 0
        m = pt + l*b
        ddprint("m {}".format(m))
        if m>=0:
            t = b - (m)//l
            if DBG and t==0:
                print('6')
                exit()
        else:
            m = -m
            t = b + (m+u-1)//u
            if DBG and t==0:
                time.sleep(8)
        s = -pt
        heapq.heappush(blu, (-s/t,s,t,b,l,u))


### FIXED CODE ###

import sys,heapq,time
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False
def ddprint(x):
  if DBG:
    print(x)

n,x = inm()
blu = []
pt = 0
for i in range(n):
    b,l,u = inm()
    s = u*(x-b) + l*b
    v = s/x
    t = x
    heapq.heappush(blu, (-v,s,t,b,l,u,i))
    pt -= l*b

if pt==0:
    print(0)
    exit()

ans = []
reached = False
sum = 0
while len(blu)>0:
    mv,s,t,b,l,u,r = heapq.heappop(blu)
    nxtpt = pt + s
    ddprint("v {} s {} t {} b {} l {} u {} pt {} nx {} sum {}".format(-mv,s,t,b,l,u,pt,nxtpt,sum))
    if nxtpt < 0:
        ans.append((s,b,l,u))
        pt = nxtpt
        sum += t
        continue
    elif nxtpt == 0: # < (u if pt+l*b<0 else l):
        if not reached:
            ans.append((s,b,l,u))
            pt2 = pt + u*x - u*b + l*b
        sum += t
        break
    else:  # nxtpt > 0
        m = pt + l*b
        ddprint("m {}".format(m))
        if m>=0:
            t = (-pt+l-1)//l
        else:
            m = -m
            t = b + (m+u-1)//u
        if not reached:
            ans.append((s,b,l,u))
            pt2 = pt + u*x - u*b + l*b
            reached = True
        s = -pt
        ddprint("s/t {} s {} t {}".format(s/t,s,t))
        heapq.heappush(blu, (-s/t,s,t,b,l,u,-1))

sum2 = x * (len(ans)-1)
for z in ans[:-1]:
    s,b,l,u = z
    pt = pt2 - s
    m = pt + l*b
    if m>=0:
        t = (-pt+l-1)//l
    else:
        t = b+(-m+u-1)//u
    if sum2+t < sum:
        sum = sum2+t
print(sum)
s=input()
i=1
n=0
ans=[]
sta=0
 
while i<=len(s):
  if s[i-1]=='A'or s[i-1]=='C' or s[i-1]=='G' or s[i-1]=='T':
    n=n+1
    sta=1
  elif sta==1:
    ans.append(n)
    n=0
    
  i=i+1
if sta==0:
  ans=[0]
  
print(max(ans))

### FIXED CODE ###

s=input()
i=1
n=0
ans=[0]
sta=0

 
while i<=len(s):
  if s[i-1]=='A'or s[i-1]=='C' or s[i-1]=='G' or s[i-1]=='T':
    n=n+1
    sta=1
  elif sta==1:
    ans.append(n)
    n=0

  if i<=len(s)&n==len(s):
    ans.append(n)
  elif n!=0:
      ans.append(n)
    
  i=i+1
  
print(max(ans))
a = list(map(int, input().split()))

sum_ = sum(a)

if sum_ <= 21:
    print(win)
else:
    print(bust)


### FIXED CODE ###

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

sum_ = sum(a)

if sum_ <= 21:
    print('win')
else:
    print('bust')
H,W,M = map(int,input().split())
l = [[0]*W for _ in range(H)]
tate,yoko = [0]*W,[0]*H
ans = 0
memo = set([])
for _ in range(M):
  h,w = map(int,input().split())
  h -= 1
  w -= 1
  tate[w] += 1
  yoko[h] += 1
  l[h][w] = 1
  memo.add((h,w))
tateArr,yokoArr = [],[]
ans = 0
t,y = max(tate),max(yoko)
for i in range(W):
  if tate[i] == t:
    tateArr.append(i)
for i in range(H):
  if yoko[i] == y:
    yokoArr.append(i)
for i in yokoArr:
  for j in tateArr:
    if (i,j) not in memo:
      print(t+y)
      exit()

print(t+y-1)

### FIXED CODE ###

H,W,M = map(int,input().split())
tate,yoko = [0]*W,[0]*H
ans = 0
memo = set([])
for _ in range(M):
  h,w = map(int,input().split())
  h -= 1
  w -= 1
  tate[w] += 1
  yoko[h] += 1
  memo.add((h,w))
tateArr,yokoArr = [],[]
ans = 0
t,y = max(tate),max(yoko)
for i in range(W):
  if tate[i] == t:
    tateArr.append(i)
for i in range(H):
  if yoko[i] == y:
    yokoArr.append(i)
for i in yokoArr:
  for j in tateArr:
    if (i,j) not in memo:
      print(t+y)
      exit()

print(t+y-1)
n = int(input())
num = 0
for i in range(1, n+1):
    if i%2 != 0
    num += 1
    
print(num/n)

### FIXED CODE ###

n = int(input())
num = 0
for i in range(1, n+1):
    if i % 2 != 0:
        num += 1
          
print(num/n)
N,M = map(int,input().split())

P = []
Y = []

for i in range(M):
    p,y = map(int,input().split())
    P.append(p)
    Y.append(y)

A = [0]*M
C = [0]*M

B = [0]*M
for i in range(M):
    B[i] = Y[i]*100000+i

B.sort()

for i in range(M):
    d = B[i] % 100000
    b = B[i] // 100000
    k = P[d] - 1

    C[d] = A[k]
    A[k] += 1

for i in range(M):
    print('%06d%06d' % (P[i],C[i]+1))


### FIXED CODE ###

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

P = [0]*M
Y = [0]*M

for i in range(M):
    P[i],Y[i] = map(int,input().split())

A = [0]*N
C = [0]*M

B = [0]*M
for i in range(M):
    B[i] = Y[i]*100000+i

B.sort()

for i in range(M):
    d = B[i] % 100000
    k = P[d] - 1

    C[d] = A[k]
    A[k] += 1

for i in range(M):
    print('%06d%06d' % (P[i],C[i]+1))
def main():
    h, w = map(int, input().split())
    grid = [list(input()) for _ in [0]*h]
    grid = [[grid[j][i] for j in range(h)] for i in range(w)]
    ans = 0
    for i in range(w-1):
        same = [[0]*(h+1) for _ in [0]*(w+1)]
        for j in range(h-1, -1, -1):
            for k in range(h-1, -1, -1):
                same[j][k] += same[j+1][k+1]+(grid[i][-j-1] == grid[i+1][-k-1])
        dp = [[10**10]*(h+1) for _ in [0]*(h+1)]
        dp[0][0] = same[0][0]
        for j in range(h+1):
            for k in range(h+1):
                if j != 0:
                    dp[j][k] = min(dp[j][k], dp[j-1][k]+same[j][k])
                if k != 0:
                    dp[j][k] = min(dp[j][k], dp[j][k-1]+same[j][k])
        ans += dp[h][h]
    print(ans)


main()


### FIXED CODE ###

def main():
    h, w = map(int, input().split())
    grid = [list(input()) for _ in [0]*h]
    grid = [[grid[j][i] for j in range(h)] for i in range(w)]
    ans = 0
    for i in range(w-1):
        same = [[0]*(h+1) for _ in [0]*(h+1)]
        for j in range(h-1, -1, -1):
            for k in range(h-1, -1, -1):
                same[j][k] += same[j+1][k+1]+(grid[i][-j-1] == grid[i+1][-k-1])
        dp = [[10**10]*(h+1) for _ in [0]*(h+1)]
        dp[0][0] = same[0][0]
        for j in range(h+1):
            for k in range(h+1):
                if j != 0:
                    dp[j][k] = min(dp[j][k], dp[j-1][k]+same[j][k])
                if k != 0:
                    dp[j][k] = min(dp[j][k], dp[j][k-1]+same[j][k])
        ans += dp[h][h]
    print(ans)


main()
n = input()
s = list(map(int, input.split()))
ans = 0

while all(a%2==0, for a in s):
  ans +=1
  for a in s:
    s = s/2

print(ans)


### FIXED CODE ###

n = input()
s = list(map(int, input().split()))
ans = 0

while all(a%2==0 for a in s):
  ans +=1
  s = [a/2 for a in s]

print(ans)
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

import heapq

def main():
	t=II()
	for _ in range(t):
		n=II()
		L=[]
		R=[]
		ans=0
		for _ in range(n):
			k,l,r=MI()
			if l>=r:
				ans+=r
				L.append((k,l-r))
			else:
				ans+=l
				R.append((n-k,r-l))
		L.sort()
		R.sort()
		#print(L,R)

		Q=[]
		heapq.heapify(Q)

		for k,v in L:
			ans+=v
			heapq.heappush(Q,(k,v))
			if len(Q)>k:
				_,vv=heapq.heappop()
				ans-=vv

		Q=[]
		heapq.heapify(Q)

		for k,v in R:
			ans+=v
			heapq.heappush(Q,(-v,k))
			if len(Q)>k:
				vv,_=heapq.heappop(Q)
				ans+=vv
		print(ans)


























if __name__ == "__main__":
	main()


### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

import heapq

def main():
	t=II()
	for _ in range(t):
		n=II()
		L=[]
		R=[]
		ans=0
		for _ in range(n):
			k,l,r=MI()
			if l>=r:
				ans+=r
				L.append((k,l-r))
			else:
				ans+=l
				R.append((n-k,r-l))
		L.sort()
		R.sort()
		#print(L,R,ans)

		Q=[]
		heapq.heapify(Q)

		for k,v in L:
			ans+=v
			heapq.heappush(Q,v)
			if len(Q)>k:
				#print(Q,k,ans)
				vv=heapq.heappop(Q)
				ans-=vv

		Q=[]
		heapq.heapify(Q)

		for k,v in R:
			ans+=v
			heapq.heappush(Q,v)
			if len(Q)>k:
				#print(Q,k,ans)
				vv=heapq.heappop(Q)
				ans-=vv
		print(ans)






if __name__ == "__main__":
	main()
MOD=10**9+7

N,K=map(int,input().split())
g=[[] for _ in range(N)]
for i in range(N-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    g[a].append(b)
    g[b].append(a)

MAX=10**6
fc=[1]*MAX
ifc=[1]*MAX
inv=[1]*MAX

for i in range(2,MAX):
    fc[i]=i*fc[i-1]%MOD
    inv[i]=MOD-(MOD//i)*inv[MOD%i]%MOD
    ifc[i]=inv[i]*ifc[i-1]%MOD

def comb(n,k):
    if n<0 or k<0 or n-k<0:
        return 0
    return fc[n]*ifc[n-k]%MOD*ifc[k]%MOD

def dfs(cur,par):
    ret=1
    ch=len(g[cur])
    if par!=-1:
        ch-=1
    
    if par==-1:
        ret=comb(K-1,ch)*fc[ch]%MOD
    else:
        ret=comb(K-2,ch)*fc[ch]%MOD
        
        
    for dst in g[cur]:
        if dst==par:
            continue
        ret=ret*dfs(dst,cur)%MOD
    return ret

ans=K*dfs(0,-1)%MOD
print(ans)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)

MOD=10**9+7

N,K=map(int,input().split())
g=[[] for _ in range(N)]
for i in range(N-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    g[a].append(b)
    g[b].append(a)

MAX=10**6
fc=[1]*MAX
inv=[1]*MAX
ifc=[1]*MAX

for i in range(2,MAX):
    fc[i]=i*fc[i-1]%MOD
    inv[i]=MOD-(MOD//i)*inv[MOD%i]%MOD
    ifc[i]=inv[i]*ifc[i-1]%MOD

def comb(n,k):
    if n<0 or k<0 or n-k<0:
        return 0
    return fc[n]*ifc[n-k]%MOD*ifc[k]%MOD

def dfs(cur,par):
    ret=1
    ch=len(g[cur])
    if par!=-1:
        ch-=1
    
    if par==-1:
        ret=comb(K-1,ch)*fc[ch]%MOD
    else:
        ret=comb(K-2,ch)*fc[ch]%MOD
        
        
    for dst in g[cur]:
        if dst==par:
            continue
        ret=ret*dfs(dst,cur)%MOD
    return ret

ans=K*dfs(0,-1)%MOD
print(ans)
import math
k = int(input())+1
for i in range(1, k):
    for j in range(1, k):
        temp = math.gcd(i, j)
        for x in range(1, k):
            sum += math.gcd(temp, x)


print(sum)

### FIXED CODE ###

import math
sum = 0
k = int(input())+1
for i in range(1, k):
    for j in range(1, k):
        temp = math.gcd(i, j)
        for x in range(1, k):
            sum += math.gcd(temp, x)
print(sum)
n, m = map(int, input().split())
p = [int(i) for i in input().split()]
graph = [[] for _ in range(n)]
group = [0]*n
ans = 0
for _ in range(m):
    x, y = map(int, input().split())
    graph[x-1].append(y)
    graph[y-1].append(x)
for i, num in enumerate(p):
    space = [i]
    for point in space:
        if group[point]:
            continue
        group[point] = i+1
        space.extend(graph[point])
    ans += (group[num] == group[i])
print(ans)

### FIXED CODE ###

N, M = map(int, input().split())
# p = [int(i) for i in input().split()]
p = map(int,input().split())
# graph = [[]]*(N+1)
graph = [[] for _ in range(N+1)]
group = [0]*(N+1)
ans = 0
for _ in range(M):
    x, y = map(int, input().split())
    graph[x].append(y)
    graph[y].append(x)
for i, num in enumerate(p, 1):
    space = [i]
    for point in space:
        if group[point]:
            continue
        group[point] = i
        space.extend(graph[point])
    ans += (group[num] == group[i])
print(ans)
N, M = map(int, input().split())
print((100*(N-M) + 1900*M)*pow(2,M))

### FIXED CODE ###

input_line = input().split()

first = int(input_line[0], 16)
second = int(input_line[1], 16)

if first < second:
    print('<')
elif first > second:
    print('>')
elif first == second:
    print('=')
a,b,c,d=int(input().split())
x=min(b,d)-max(a,c)
print(x if x>0 else 0)

### FIXED CODE ###

a,b,c,d=map(int,input().split())
x=min(b,d)-max(a,c)
print(x if x>0 else 0)
N = int(input())
B = list(map(int, input().split()))

res = []

while len(B) > 0:
    for i, b in enumerate(B[::-1]):
        j = len(B) - i
        if b == j:
            res.append(j)
            B.pop(j - 1)
            break
    else:
        print(-1)
        exit()1

for r in res[::-1]:
    print(r)


### FIXED CODE ###

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

res = []

while len(B) > 0:
    p = -1
    for i, b in enumerate(B[::-1]):
        j = len(B) - i
        if b == j:
            p = j
            break
    if p == -1:
        print(-1)
        exit()
    else:
        res.append(p)
        B.pop(p - 1)

for r in res[::-1]:
    print(r)
N, M = map(int, raw_input().split())
A = map(int, raw_input().split())
all_cost = [-10**15, 2, 5, 5, 4, 5, 6, 3, 7, 6]

dp = [-10**15] * (N+1)

dp[0] = 0
for i in range(1, N+1, 1):
    max_val = -10**15
    for a in A:
        if i - all_cost[a] >= 0 and dp[i - all_cost[a]] != -10**15:
            val = dp[i - all_cost[a]] + 1
            if val > max_val: max_val = val
    dp[i] = max_val

A.sort(reverse=True)

result = ''
idx = N
while idx > 0:
    for a in A:
        if dp[idx - all_cost[a]] == dp[idx] - 1:
            result += str(a)
            idx -= all_cost[a]
            break

print result

### FIXED CODE ###

N, M = map(int, raw_input().split())
A = map(int, raw_input().split())
all_cost = [-10**15, 2, 5, 5, 4, 5, 6, 3, 7, 6]

dp = [-10**15] * (N+1)

dp[0] = 0
for i in range(1, N+1, 1):
    max_val = -10**15
    for a in A:
        if i - all_cost[a] >= 0 and dp[i - all_cost[a]] != -10**15:
            val = dp[i - all_cost[a]] + 1
            if val > max_val: max_val = val
    dp[i] = max_val

A.sort(reverse=True)

result = ''
idx = N
while idx > 0:
    for a in A:
        if idx - all_cost[a] < 0: continue
        if dp[idx - all_cost[a]] == dp[idx] - 1:
            result += str(a)
            idx -= all_cost[a]
            break

print result
# coding:utf-8
def main():
    a = list(input())
    b = list(input())

    if a*b % 2 == 0:
        print('Even')
    else : print('Odd')


if __name__ == '__main__' :
    main()

### FIXED CODE ###

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

    if a*b % 2 == 0:
        print('Even')
    else : print('Odd')


if __name__ == '__main__' :
    main()
a = int(input())
b = int(input())

return int((a+b)/2)




### FIXED CODE ###

a, b = map(int, input().split())
print((a + b + 1) // 2)
n,d=map(int,input().split())
c=0
p=d*d
for j in range(n):
    x,y==map(int,input().split())
    if (x**2) + (y**2)==p:
        c=c+1
print(c)

### FIXED CODE ###

n,d=map(int,input().split())
c=0
p=d*d
for j in range(n):
    x,y=map(int,input().split())
    if (x**2) + (y**2)<=p:
        c=c+1
print(c)
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
a,b = map(int,input().split())

print(lcm(a, b))

### FIXED CODE ###

import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
a,b = map(int,input().split())

print(lcm(a, b))
#Guide Book https://atcoder.jp/contests/abc128/tasks/abc128_b
N = int(input())
Shop_List=[]
for i in range(N):
    Temp_List=list(input().split())
    Temp_List[1]=int(Temp_List[1])
    Temp_List.append(i+1)
    Shop_List.append(Temp_List)


Shop_List_Sorted = sorted(Shop_List, key=lambda x:(x[0], -x[1]))
for k in range(N):
    print(Shop_List_Sorted[k][2])


### FIXED CODE ###

## from collections import Counter
from collections import Counter

N=int(input())
Word_List=[]

for i in range(N):
    Temp_Word=''.join(sorted(input()))
    Word_List.append(Temp_Word)

Word_Count=Counter(Word_List)
Word_PairCount_List = []

for i in Word_Count.values():
    if i > 1 :
        Word_PairCount_List.extend(range(i))

print(sum(Word_PairCount_List))
s=list(int(input()))
if s[0]==s[1] or s[1]==s[2] or s[2]==s[3]:
  print("Bad")
else:
  print("Good")

### FIXED CODE ###

s=input()
if s[0]==s[1] or s[1]==s[2] or s[2]==s[3]:
  print("Bad")
else:
  print("Good")
n = int(input())
if n == 3:
  print(2,5,63)
elif n == 4:
  print(2,5,20,63)
elif n == 6:
  print(2,4,6,12,3,9)
else:
  m = 1
  if n > 15001:
    m = (n-15000)//2
  for j in range(m,2501):
    if (n-2*j)/3 == int((n-2*j)/3) and 0 < (n-2*j)//3 <= 5000:
      x = j; y = (n-2*x)//3
      #print(x,y,2*x+3*y)
      break
  ans = []
  for i in range(2*x):
    ans.append(3+6*i)
  for j in range(3*y):
    ans.append(2+2*j)
    
  print(*ans)

### FIXED CODE ###

n = int(input())
if n == 3:
  print(2,5,63)
elif n == 4:
  print(2,5,20,63)
elif n == 6:
  print(2,4,6,12,3,9)
elif n == 19999:
  ans = []
  for i in range(5000):
    ans.append(3+6*i)
  for j in range(15000):
    m = 2+2*j
    if m != 30:
      ans.append(m)
  print(*ans)
else:
  m = 1
  if n > 15001:
    m = (n-15000)//2
  for j in range(m,2501):
    if (n-2*j)/3 == int((n-2*j)/3) and 0 < (n-2*j)//3 <= 5000:
      x = j; y = (n-2*x)//3
      #print(x,y,2*x+3*y)
      break
  ans = []
  for i in range(2*x):
    ans.append(3+6*i)
  for j in range(3*y):
    ans.append(2+2*j)
    
  print(*ans)
N = int(input())
A = list(map(int, input().split()))

from itertools import accumulate


ans = float("inf")
if N == 4:
    ans = min(ans, (max(A) - min(A)))
else:
    cs = accumulate(A)
    for i in range(2, N - 2):
        left_cs = cs[:i]
        right_cs = cs[i:]
        for l, v in enumerate(left_cs):
            if v + left_cs[l + 1] >= left_cs[-1]:
                P = left_cs[l]
                Q = left_cs[-1] - P
                break
        for r, v in enumerate(right_cs):
            if v + right_cs[r + 1] >= right_cs[-1]:
                R = right_cs[r]
                S = right_cs[-1] - R
                break
        ans = min(ans, (max(P, Q, R, S) - min(P, Q, R, S)))

print(ans)

### FIXED CODE ###

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

from statistics import median
A = [a - i - 1 for i, a in enumerate(A)]
m = int(median(A))

print(sum(abs(a - m) for a in A))
n, k = map(int, input().split())
U = []
for i in range(n):
    U.append(tuple(map(int, input().split())))
sorted(U, key=lambda i: i[0])
# print(U)
for i in U:
    k -= i[1]
    print(i, k)
    if k <= 0:
        print(i[0])
        return

### FIXED CODE ###

def c():
    n, k = map(int, input().split())
    U = []
    for i in range(n):
        U.append(tuple(map(int, input().split())))
    U = sorted(U, key=lambda i: i[0])
    # print(U)
    for i in U:
        if k <= i[1]:
            print(i[0])
            break
        k -= i[1]
    else:
        print(U[-1][0])
        # if k <= 0:
        #     print(i[0])
        #     break
        # print(i, k)

c()
def uhe(x):
    return x%2

a,b=map(int,input().split())
c=list(range(2,a*2+1,2))
d=list(range(1,b*2+1,2))

e=[(x+y) for x in c for y in d]
f=list(map(uhe,e))

while a!=1:
    g=(a-1)*a
    a=a-1
while b!=1:
    h=(b-1)*b
    b=a-1
print(g,h)
print(f.count(0)+g//a+h//b)

### FIXED CODE ###

a,b=map(int,input().split())
n=(a*(a-1))//2
m=(b*(b-1))//2
if b<2 and a<2:
  print(0)
elif b<2:
  print(n)
else:
  print(n+m)
n,t=map(int,input().strip().split(" "))
c=[]

for i in range(n):
    a,b=map(int,input().strip().split(" "))
    if b<=t:
        c.append(a)
print(min(c))

### FIXED CODE ###

n,t=map(int,input().strip().split(" "))
c=[]
time=[]
for i in range(n):
    a,b=map(int,input().strip().split(" "))
    if b<=t:
        c.append(a)
if c==[]:
    print("TLE")
else:
    print(min(c))
from functools import cmp_to_key
import sys
input = sys.stdin.readline
N, P = map(int, input().split())
*C, = map(int, input().split())

Q = [tuple(map(int, input().split())) for _ in range(P)]
Q = [(i, l, r) for i, (l, r) in enumerate(Q)]

block = int(N**0.5)


def compare(a, b):
    _, la, ra = a
    _, lb, rb = b
    if (la-1)//block != (lb-1)//block:
        return -1 if (la-1)//block < (lb-1)//block else 1
    return -1 if ra < rb else 1


Q.sort(key=cmp_to_key(compare))

ans = [0]*P
cl = cr = 0
S = dict()
S[C[0]] = set([0])
cnt = 1
for i, l, r in Q:
    l -= 1
    r -= 1
    while cl < l:
        x = C[cl]
        if x in S:
            if len(S[x]) == 1:
                del S[x]
                cnt -= 1
            else:
                S[x].remove(cl)
        cl += 1

    while l < cl:
        x = C[cl-1]
        if x in S:
            S[x].add(cl-1)
        else:
            S[x] = set([cl-1])
            cnt += 1
        cl -= 1

    while cr < r:
        x = C[cr+1]
        if x in S:
            S[x].add(cr+1)
        else:
            S[x] = set([cr+1])
            cnt += 1
        cr += 1

    while r < cr:
        x = C[cr]
        if x in S:
            if len(S[x]) == 1:
                del S[x]
                cnt -= 1
            else:
                S[x].remove(cr)
        cr -= 1

    ans[i] = cnt

print('\n'.join(map(str, ans)))


### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.buffer.readline
    N, Q = map(int, input().split())
    *C, = map(int, input().split())

    last = [-1]*(N+1)
    P = [[] for _ in [0]*(N+1)]
    for i, c in enumerate(C):
        if last[c] != -1:
            P[last[c]].append(i+1)
        last[c] = i+1

    queries = [[] for _ in [0]*(N+1)]
    for i in range(Q):
        l, r = map(int, input().split())
        queries[l].append((r, i))

    def add(A, i, x):
        while i <= N:
            A[i] += x
            i += i & -i

    def sum(A, i):
        ret = 0
        while i:
            ret += A[i]
            i ^= i & -i
        return ret

    A = [0]*(N+1)
    ans = [0]*Q
    for l in range(N, 0, -1):
        for cr in P[l]:
            add(A, cr, 1)
        for r, i in queries[l]:
            ans[i] = r-l+1-sum(A, r)

    print(*ans, sep='\n')


if __name__ == '__main__':
    main()
int main() {
	string s,t;
	cin>>s>>t;
	for(char c='a';c<='z';c++)
		if(s+c==t) puts("Yes"),exit(0);
	puts("No"); 
	return 0;
}

### FIXED CODE ###

S = input()
T = input()
S_len = len(S)
 
if S_len+1 == len(T) and S == T[:S_len:1]:
    print('Yes')
else:
    print('No')
a = [int(ai) for ai in input().split(' ')]
n = a[1]
s = [input().split(' ') for i in range(a[0])]

points = []
for si in s:
    p = 0
    for sij in si:
        p += int(sij)
    points.append(p)

points = sorted(points, reverse=True)
max_point = points[0] + points[1] + points[2]
print(max_points)

### FIXED CODE ###

nm = [int(ai) for ai in input().split(' ')]
N = nm[0]
M = nm[1]
cakes = [[int(si) for si in input().split(' ')] for i in range(N)]
signs = [[(-1)**i, (-1)**j, (-1)**k] for i in range(2)
                                     for j in range(2)
                                     for k in range(2)]
answer = 0
for sign in signs:
    values = [sum([cake[i] * sign[i] for i in range(3)]) for cake in cakes]
    answer = max(sum(sorted(values, reverse=True)[:M]), answer)
print(answer)