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

import sys

def 解():
    input = sys.stdin.readline
    H,W = [int(_) for _ in input().split()]
    aM = [""]*H
    for i in range(H):
        aM[i] = input().rstrip()

    adxy=[(0,1),(1,0),(-1,0),(0,-1)]

    def bfsM(i,j):
        aS = [(i,j)]
        dsV = set()
        iC = 0
        while aS:
            th,tw = aS[0]
            del aS[0]
            if aM[th][tw] == ".":
                iC += 1
                for dh,dw in adxy:
                    nh,nw=dh+th,dw+tw
                    nP = (nh,nw)
                    if 0 <= nh < H and 0 <= nw < W:
                        if aM[nh][nw] == "#" and nP not in dsV:
                            aS.append(nP)
                            dsV.add(nP)
            else:
                for dh,dw in adxy:
                    nh,nw=dh+th,dw+tw
                    nP = (nh,nw)
                    if 0 <= nh < H and 0 <= nw < W:
                        if aM[nh][nw] == "." and nP not in dsV:
                            aS.append(nP)
                            dsV.add(nP)
        return iC

    iAns = 0
    for i in range(H):
        for j in range(W):
            if aM[i][j] == "#":
                iAns += bfsM(i,j)
    print(iAns)
解()



### FIXED CODE ###

import sys

def 解():
    input = sys.stdin.readline
    H,W = [int(_) for _ in input().split()]
    aM = [""]*H
    for i in range(H):
        aM[i] = input().rstrip()

    adxy=[(0,1),(1,0),(-1,0),(0,-1)]
    dsVBs=set()

    def bfsM(i,j):
        aS = [(i,j)]
        dsV = set()
        dsVB = set()
        iC = 0
        while aS:
            th,tw = aS[0]
            del aS[0]
            if aM[th][tw] == ".":
                iC += 1
                for dh,dw in adxy:
                    nh,nw=dh+th,dw+tw
                    nP = (nh,nw)
                    if 0 <= nh < H and 0 <= nw < W:
                        if aM[nh][nw] == "#" and nP not in dsV:
                            aS.append(nP)
                            dsV.add(nP)
                            dsVB.add(nP)
            else:
                for dh,dw in adxy:
                    nh,nw=dh+th,dw+tw
                    nP = (nh,nw)
                    if 0 <= nh < H and 0 <= nw < W:
                        if aM[nh][nw] == "." and nP not in dsV:
                            aS.append(nP)
                            dsV.add(nP)
        iB = len(dsVB)
        for nP in dsVB:
            dsVBs.add(nP)
        return iC*iB

    iAns = 0
    for i in range(H):
        for j in range(W):
            if aM[i][j] == "#" and (i,j) not in dsVBs:
                iAns += bfsM(i,j)
    print(iAns)
解()
### BUGGY CODE ###

a = int(input())
modl = [i for i in range(1,a+1)]
numl = [i for i in range(2,a+1)] + [1]
ans = 0
for i in range(a):
    ans += modl[i] % numl[i]
print(ans)

### FIXED CODE ###

a = int(input())
print(a*(a-1)//2)
### BUGGY CODE ###

from collections import defaultdict
from bisect import bisect_right

s = input()
t = input()

for ch in t:
    if ch not in s:
        print("-1")
        exit()

indices = defaultdict(list)
for i, v in enumerate(s):
    indices[v].append(i)

cnt = 0
cur = -1
mod = len(s)
for v in t:

    i = bisect_right(indices[v], cur)
    if i == len(indices[v]):
        j = indices[v][0]
    else:
        j = indices[v][i]

    if cur >= j:
        cnt += 1
    cur = j
print(cnt * mod + cur + 1)

### FIXED CODE ###

# https://atcoder.jp/contests/abc138/tasks/abc138_e

from collections import defaultdict
from bisect import bisect_right

S = input()
T = input()

# Sの中での位置
iS = defaultdict(list)
for (idx, ch) in enumerate(S):
    iS[ch].append(idx)

# Tの文字はSに出ていないといけない
for v in T:
    if v not in iS:
        print(-1)
        exit()

# 探索
cnt = 0
cur = -1
for v in T:
    i = bisect_right(iS[v], cur)
    if i == len(iS[v]):
        j = iS[v][0]
    else:
        j = iS[v][i]

    if cur >= j:
        cnt += 1
    cur = j

print(cnt * len(S) + cur + 1)
### BUGGY CODE ###

A, B = map(int, input().split())
while B != 0:
  A, B = B, A % B
i, j = 2, 1
while i <= A and A != 1:
  if A % i == 0:
    j += 1
    while A % i == 0:
      A //= i
  i += 1
print(j)

### FIXED CODE ###

A, B = map(int, input().split())
a, b = A, B
while b != 0:
  a, b = b, a % b
prod = 1
s = 1
p = 2
g = a
while a != 1:
  i = 0
  while a % p == 0:
    i += 1
    a //= p
    prod *= p
  if i != 0:
    s += 1
  p += 1
  if p > int(g**(1/2)) and prod != g:
    s += 1
    break
print(s)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

import numpy as np

N,M,R = map(int, input().split())
r = list(map(int, input().split()))
ds = np.zeros([N,N])
neighbors = [[]]*N
for _ in range(M):
    a,b,c = map(int, input().split())
    ds[a-1][b-1] = c
    ds[b-1][a-1] = c
    neighbors[a-1].append(b-1)
    neighbors[b-1].append(a-1)
visitedls = []
totalds = 0
minds = 1e9+7

def dfs(a, prev):
    global visitedls, totalds, ds, minds, neighbors, r
    visitedls.append(a+1)
    totalds += ds[a][prev]
    if set(r) & set(visitedls) == set(r):
        if minds > totalds:
                minds = totalds  
    for nxt in neighbors[a]:
        if nxt+1 not in visitedls:
            dfs(nxt, a)
    del visitedls[-1]
    totalds -= ds[a][prev]

for a in r:
    dfs(a-1, a-1)
print(int(minds))
    

### FIXED CODE ###

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

adj = [[] for i in range(N)]
for i in range(M):
    A, B, C = map(int, input().split())
    adj[-A].append((B, C))
    adj[-B].append((A, C))

import heapq

def Dijkstra(N, v_st, v_go):
    cost = [float('inf') for i in range(N)]

    pq = []
    heapq.heappush(pq, (0, v_st))

    while pq:
        c, v_now = heapq.heappop(pq)

        if v_now == v_go:
            return c

        if cost[-v_now] < c:
            continue

        cost[-v_now] = c

        for v, c2 in adj[-v_now]:
            if cost[-v_now] + c2 < cost[-v]:
                cost[-v] = cost[-v_now] + c2
                heapq.heappush(pq, (cost[-v], v))

cost_min = [[float('inf') for i in range(R)] for j in range(R)]

for i in range(R):
    for j in range(i, R):
        cost_min[i][j] = Dijkstra(N, r[i], r[j])
        cost_min[j][i] = cost_min[i][j]

import itertools
p = list(itertools.permutations(range(R)))

ans = float('inf')
for pp in p:
    c = 0
    for i in range(R - 1):
        c += cost_min[pp[i]][pp[i + 1]]

    ans = min(ans, c)
    
print(ans)
### BUGGY CODE ###

def main():
  h, w = map(int, input().split())
  s = [input() + '#' for _ in range(h)]
  s.append('#' * w)
  
  yoko = [[0] * w for _ in range(h)]
  for i in range(h):
    si = s[i]
    start = -1
    for j in range(w + 1):
      if si[j] == '#':
        if start != -1:
          for k in range(start, j):
            yoko[i][k] = j - start
          start = -1
      else:
        if start == -1:
          start = j
  
  tate = [[0] * w for _ in range(h)]
  for i in range(w):
    start = -1
    for j in range(h + 1):
      if s[j][i] == '#':
        if start != -1:
          for k in range(start, j):
            tate[k][i] = j - start
          start = -1
      else:
        if start == -1:
          start = j
  
  result = 0
  for i in range(h):
    yokoi = yoko[i]
    tatei = tate[i]
    for j in range(w):
      t = yokoi[j] + tatei[j] - 1
      if t > result:
        result = t
  
  print(result)

main()

### FIXED CODE ###

h, w = map(int, input().split())
s = [input() + '#' for _ in range(h)]
s.append('#' * w)

yoko = [[0] * w for _ in range(h)]
for i in range(h):
  if s[i][0] == '.':
    start = 0
  else:
    start = -1
  for j in range(1, w + 1):
    if s[i][j] == '#':
      if start != -1:
        for k in range(start, j):
          yoko[i][k] = j - start
        start = -1
    else:
      if start == -1:
        start = j

tate = [[0] * w for _ in range(h)]
for i in range(w):
  if s[0][i] == '.':
    start = 0
  else:
    start = -1
  for j in range(1, h + 1):
    if s[j][i] == '#':
      if start != -1:
        for k in range(start, j):
          tate[k][i] = j - start
        start = -1
    else:
      if start == -1:
        start = j
result = 0
for i in range(h):
  for j in range(w):
    t = yoko[i][j] + tate[i][j] - 1
    if t > result:
      result = t

print(result)
### BUGGY CODE ###

from collections import deque
import sys
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    L = [[0] for _ in range(n)]
    for _ in range(m):
        a, b = map(int, input().split())
        L[a-1].append(b-1)
        L[b-1].append(a-1)
    L[0][0] = 1
    d = [0] * n
    ans = [0] * n
    dq = deque([0])
    while len(dq) > 0:
        t = dq.popleft()
        for i in range(1, len(L[t])):
            if d[L[t][i]] == 0:
                d[L[t][i]] = d[t] + 1
                ans[L[t][i]] = t + 1
            else:
                if d[L[t][i]] > d[t] + 1:
                    d[L[t][i]] = d[t] + 1
                    ans[L[t][i]] = t + 1
            if L[L[t][i]][0] == 0:
                dq.append(L[t][i])
        else:
            L[t][0] = 1
    print('Yes')
    print(*ans[1:], sep='\n')

main()


### FIXED CODE ###

from collections import deque
import sys
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    L = [[0] for _ in range(n)]
    for _ in [0] * m:
        a, b = map(int, input().split())
        L[a-1].append(b-1)
        L[b-1].append(a-1)
    L[0][0] = 1
    ans = [0] * n
    dq = deque([0])
    while dq:
        t = dq.popleft()
        for i in range(1, len(L[t])):
            next = L[t][i]
            if ans[next] != 0:
                continue
            ans[next] = t + 1
            dq.append(next)
        else:
            L[t][0] = 1
    print('Yes')
    print(*ans[1:], sep='\n')

main()
### BUGGY CODE ###

import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=998244353
    N=I()
    A=LI()
    MA=max(A)
    x=[0]*(MA+1)
    
    #数列x[i]はi*(iの個数)
    for i in range(N):
        x[A[i]]+=A[i]
        
    #print(x)
    
    #上位集合のゼータ変換
    for k in range(1,MA+1):
        for s in range(k*2,MA+1,k):#sが2kからkずつ増える=>sはkの倍数(自分自身を数えないため，2kから)
            x[k]=(x[k]+x[s])%mod
    
    #print(x)
    #この段階でx[i]はiを約数に持つやつの和(個数も加味している)
    
    #積演算
    for i in range(MA+1):
        x[i]=(x[i]*x[i])%mod
        
    #print(x)
    
    
    #メビウス変換で戻す
    for k in range(MA,0,-1):
        for s in range(k*2,MA+1,k):
            x[k]=(x[k]-x[s])%mod
            
    #この段階でx[i]はiをgcdに持つもの同士をかけたものの和
    #print(x)
    
    #gcdでわる
    for i in range(2,MA+1):
        x[i]=(x[i]*pow(i,mod-2,mod))%mod
        
    #この段階でx[i]はiをgcdに持つもの同士のlcaの和
    #print(x)
    
    """
    for i in range(MA+1):
        if x[i]!=0:
            print(i,x[i])"""
    
    
    ans=0
    for i in range(1,MA+1):
        ans=(ans+x[i])%mod
        #xの和を取る
        
    for i in range(N):
        ans=(ans-A[i])%mod
        #A[i],A[i]の組を除去する．A[i]動詞のくみはlcaがA[i]になる
        
    ans=(ans*pow(2,mod-2,mod))%mod#A[i]*A[j] と　A[j]*A[i]の被り除去
    
    print(ans)
        
    
    

main()


### FIXED CODE ###

import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=998244353
    N=I()
    A=LI()
    MA=max(A)
    x=[0]*(MA+1)
    
    #数列x[i]はi*(iの個数)
    for i in range(N):
        x[A[i]]+=A[i]
        
    #print(x)
    
    #上位集合のゼータ変換
    for k in range(1,MA+1):
        for s in range(k*2,MA+1,k):#sが2kからkずつ増える=>sはkの倍数(自分自身を数えないため，2kから)
            x[k]=(x[k]+x[s])%mod
    
    #print(x)
    #この段階でx[i]はiを約数に持つやつの和(個数も加味している)
    
    #積演算
    for i in range(MA+1):
        x[i]=(x[i]*x[i])%mod
        
    #print(x)
    
    
    #メビウス変換で戻す
    for k in range(MA,0,-1):
        for s in range(k*2,MA+1,k):
            x[k]=(x[k]-x[s])%mod
            
    #この段階でx[i]はiをgcdに持つもの同士をかけたものの和
    #print(x)
    
    #gcdでわる
    ans=0
    for i in range(1,MA+1):
        if x[i]!=0:
            x[i]=(x[i]*pow(i,mod-2,mod))%mod
            ans=(ans+x[i])%mod
        
    #この段階でx[i]はiをgcdに持つもの同士のlcaの和
    #print(x)
        
    ans=(ans-sum(A))%mod
    #A[i],A[i]の組を除去する．A[i]動詞のくみはlcaがA[i]になる
       
    """ 
    ans=(ans*pow(2,mod-2,mod))%mod#A[i]*A[j] と　A[j]*A[i]の被り除去
    print(pow(2,mod-2,mod))=499122177
    """
    ans=(ans*499122177)%mod
    
    print(ans)
        
    
    

main()
### BUGGY CODE ###

H, W, D = list(map(int, input().split()))
A = []
for i in range(H):
    A.append(list(map(int, input().split())))
Q = int(input())
LR = []
for i in range(Q):
    LR.append(list(map(int, input().split())))

sA = [0 for i in range(H*W+1)]

for i in range(len(A)):
        for j in range(len(A[i])):
            sA[A[i][j]] = [i, j]

for lr in LR:
    mp = 0
    l, r = lr[0], lr[1]
    li, lj = sA[l]
    while l != r:
        nextLi, nextLj = sA[l+D]
        mp += abs(nextLi-li) + abs(nextLj-lj)
        l += D
        li, lj = nextLi, nextLj
    print(mp)


### FIXED CODE ###

H, W, D = list(map(int, input().split()))
A = []
for i in range(H):
    A.append(list(map(int, input().split())))
Q = int(input())
LR = []
for i in range(Q):
    LR.append(list(map(int, input().split())))

d = [0 for i in range(H*W+1)]
sA = [0 for i in range(H*W+1)]

for i in range(len(A)):
        for j in range(len(A[i])):
            sA[A[i][j]] = [i, j]

for i in range(D+1, H*W+1):
    d[i] = d[i-D] + abs(sA[i][0]-sA[i-D][0]) + abs(sA[i][1]-sA[i-D][1])

for lr in LR:
    l, r = lr[0], lr[1]
    print(d[r] - d[l])
### BUGGY CODE ###

s=input()
S=list(s)
count=1
a=[]
a.append(S[0])
S.remove(S[0])
while 0<len(S):
        x=S[0]
        if a[len(a)-1]!=x:
            a.append(x)
            S.remove(S[0])
        else:
            S.remove(S[0])
            while x==a[len(a)-1] and len(S)>0:
                x+=S[0]
                S.remove(S[0])
            if x!=a[len(a)-1]:
                a.append(x)
#print(a)
print(len(a))

### FIXED CODE ###

s=input()
S=list(s)
count=1
a=[]
a.append(S[0])
S.remove(S[0])
x=''
for i in range(len(S)):
    x+=S[i]
    if a[len(a)-1]!=x:
        a.append(x)
        x=''
        count+=1
    else:
        continue
print(len(a))
### BUGGY CODE ###

N, K = map(int, input().split())
xys = []
for i in range(N):
  x, y = map(int, input().split())
  xys.append((x, y))
xs = sorted(map(lambda xy: xy[0], xys))
ys = sorted(map(lambda xy: xy[1], xys))
rs = []
for i in range(N):
  for j in range(i+1, N):
    x1 = xs[i]
    x2 = xs[j]
    for k in range(N):
      for l in range(k+1, N):
        y1 = ys[k]
        y2 = ys[l]
        n = len([(x, y) for x, y in xys if x1 <= x <= x2 and y1 <= y <= y2])
        #xys2 = filter(lambda xy: x1 <= xy[0] <= x2 and y1 <= xy[1] <= y2, xys)
        if n >= K:
          r = (x2-x1)*(y2-y1)
          rs.append(r)
r = min(rs)
print(r)


### FIXED CODE ###

N, K = map(int, input().split())
xys = []
for i in range(N):
  x, y = map(int, input().split())
  xys.append((x, y))
xs = sorted(map(lambda xy: xy[0], xys))
ys = sorted(map(lambda xy: xy[1], xys))
rs = []
for i in range(N):
  for j in range(i+1, N):
    x1 = xs[i]
    x2 = xs[j]
    for k in range(N):
      for l in range(k+1, N):
        y1 = ys[k]
        y2 = ys[l]
        n = len([(x, y) for x, y in xys if x1 <= x <= x2 and y1 <= y <= y2])
        #xys2 = filter(lambda xy: x1 <= xy[0] <= x2 and y1 <= xy[1] <= y2, xys)
        if n >= K:
          r = (x2-x1)*(y2-y1)
          rs.append(r)
r = min(rs)
print(r)
### BUGGY CODE ###


S = input()
T = input()
dp = [[ "" ] * (len(S) + 1 ) for _ in range(len(T) + 1)]

for i in range(1,len(dp)):
    for j in range(1,len(dp[0])):
        if T[i - 1] == S[j-1]:
            dp[i ][j ] = dp[i-1][j-1] + S[j-1]
        else:
            res1 = dp[i - 1][j]
            res2 = dp[i][j - 1]
            l1 = len(res1)
            l2 = len(res2)
            if l1 > l2:
                dp[i ][j] = res1
            else:
                dp[i ][j] = res2
print(dp[-1][-1])


### FIXED CODE ###

S = input()
T = input()
dp = [[ 0] * (len(S) + 1 ) for _ in range(len(T) + 1)]
ma = 0
for i in range(len(dp)-1):
    for j in range(len(dp[0])-1):
        if T[i ] == S[j]:
            dp[i + 1][j + 1] = dp[i][j] + 1
        else:
             dp[i + 1][j + 1]  = max(dp[i][j + 1],dp[i +1][j])
i = len(T) - 1
j = len(S) - 1 
ans = ""
while i >=0 and j >= 0:
    if dp[i][j+1] == dp[i + 1][j + 1]:
        i-=1
    elif dp[i + 1][j] == dp[i + 1][j + 1]:
        j-=1
    else:
        #print(j,i)
        ans = S[j] + ans
        i-=1
        j-=1
print(ans)
### BUGGY CODE ###

N = int(input())
l = [input() for _ in range(N)]

num = 0
for i in l:
   num = max(num,l.count(i)) 
ans = []
for i in l:
    if num == l.count(i):
        ans.append(i)

l= list(set(ans))
l.sort()
for i in l:
    print(i)


### FIXED CODE ###

N = int(input())
l = [input() for _ in range(N)]

ans = []
l.sort()
num = 1
max_num = 0

for i in range(1,N):
    if l[i] == l[i-1]:
        num += 1
    else:
        if num > max_num:
            max_num = num
            ans = [l[i-1]]
        elif num == max_num:
            ans.append(l[i-1])
        num = 1
if num > max_num:
        max_num = num
        ans = [l[i]]
elif num == max_num:
    ans.append(l[i])

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

s = input()
count = 0
while True:
    if "01" in s:
        s = s.replace("01", "", 1)
        count += 2
    elif "10" in s:
        s = s.replace("10", "", 1)
        count += 2
    else:
        break
print(count)

### FIXED CODE ###

s = input()
print(min(s.count("0"), s.count("1"))*2)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
def chmin(a, b):
    if a > b:
        return b
    else:
        return a
import numpy as np  
n,k = map(int,input().split())
h = np.array([int(i) for i in input().split()],dtype = np.int32)
# dpの最小値を変更する関数

# 無限大の値
f_inf = 10 ** 9 
# DP テーブルを初期化　(最小化問題なので INF に初期化)
dp = np.array([f_inf] * (10**5+10), dtype =np.int32)
# 初期条件
dp[0] = 0
# 足場 i-1 から足場 i へ移動する。コストは|h[i]−h[i-1]|
# 足場 i-2 から足場 i へと移動する コストは |h[i]−h[i-2]|
for i in range(1, n):
    for j in range(1,k+1):
        if i-j < 0 :
            continue
        else:
            dp[i] = chmin(dp[i], dp[i - j] + abs(h[i] - h[i-j]))
print(dp[n-1])

### FIXED CODE ###

import sys
input = sys.stdin.readline
def chmin(a, b):
    if a > b:
        return b
    else:
        return a
  
n,k = map(int,input().split())
h = [int(i) for i in input().split()]
# dpの最小値を変更する関数

# 無限大の値
f_inf = 10 ** 9 
# DP テーブルを初期化　(最小化問題なので INF に初期化)
dp = [f_inf] * (10**5+10)
# 初期条件
dp[0] = 0
# 足場 i-1 から足場 i へ移動する。コストは|h[i]−h[i-1]|
# 足場 i-2 から足場 i へと移動する コストは |h[i]−h[i-2]|
for i in range(1, n):
    for j in range(1,k+1):
        if i-j < 0 :
            continue
        else:
            dp[i] = chmin(dp[i], dp[i - j] + abs(h[i] - h[i-j]))
print(dp[n-1])
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = A[0]
S = [A[0], A[1]]
for i in range(2, len(A)):
    m = min(A[0], A[-1])
    cnt = -1
    for j in range(len(A)-1):
        if min(A[j], A[j+1]) > m:
            m = min(A[j], A[j+1])
            cnt = j
    S = S[:cnt] + [A[i]] + S[cnt:]
    ans += m
print(ans)




### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = A[0]
N -= 2
for i in range(1, N):
    if N >= 2:
        ans += A[i]*2
        N -= 2
    elif N  == 1:
        ans += A[i]
        N -= 1
    else:
        break
print(ans)
### BUGGY CODE ###

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

divs = {}
for A_i in A:
    for i in range(1, int(A_i ** 0.5) + 1):
        if A_i % i == 0:
            if i in divs:
                divs[i] += 1
            else:
                divs[i] = 1
            if i != A_i // i:
                if A_i // i in divs:
                    divs[A_i // i] += 1
                else:
                    divs[A_i // i] = 1
divs = sorted(divs.items(), key=lambda x: x[0], reverse=True)

for divs_i in divs:
    if divs_i[1] == N or divs_i[1] == N - 1:
        print(divs_i[0])
        break


### FIXED CODE ###

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

    divisors.sort(reverse=True)
    return divisors


N = int(input())
A = sorted([int(x) for x in input().split()])

ans = 1
for i in range(2):
    div_list = make_divisors(A[i])

    for div_i in div_list:
        wrong_count = 0

        for A_i in A:
            if A_i % div_i != 0:
                wrong_count += 1

        if wrong_count <= 1 and div_i > ans:
            ans = div_i

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

import itertools


N, M = map(int, input().split())
lst = [list(map(int, input().rstrip().split())) for n in range(N)]
maximum = -float("inf")
for pickup in itertools.combinations(lst, M):
    m = sum(abs(sum([pickup[n][i] for n in range(M)])) for i in range(3))
    maximum = max(maximum, m)

print(maximum)


### FIXED CODE ###

N, M = map(int, input().split())
lst = [list(map(int, input().rstrip().split())) for n in range(N)]
maximum = -float("inf")
for i in [-1, 1]:
    for j in [-1, 1]:
        for k in [-1, 1]:
            sum_lst = []
            for n in range(N):
                num = lst[n][0] * i + lst[n][1] * j + lst[n][2] * k
                sum_lst.append(num)
            maximum = max(abs(sum(sorted(sum_lst)[:M])), maximum)
            
print(maximum)
### BUGGY CODE ###

from collections import defaultdict
import queue

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

class Graph(object):

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, a, b):
        self.graph[a].append(b)


class breadth(object):
    def __init__(self, graph, s):
        self.g = graph.graph
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[s] = 0
        self.visit = ["no" for i in range(len(graph) + 1)]
        self.visit[s] = "yes"

        self.Q = queue.Queue()
        self.Q.put([self.dist[s], s])

        while not self.Q.empty():
            dist_u, u = self.Q.get()
            for v in self.g[u]:
                if self.visit[v] == "yes":
                    continue
                else:
                    self.dist[v] = dist_u + 1
                    self.visit[v] = "yes"
                    self.Q.put([self.dist[v], v])


N = int(input())
if N == 1:
	print("First")
else:
	g_a = Graph()
	for i in range(N - 1):
		a, b = getlist()
		g_a.add_edge(a, b)
		g_a.add_edge(b, a)
	
	s = 1
	E = breadth(g_a, s)
	x = 0
	for i in E.dist:
		if E.dist[i] > x:
			x = E.dist[i]
			y = i
	F = breadth(g_a, y)
	x = 0
	for i in F.dist:
		if F.dist[i] > x:
			x = F.dist[i]
			y = i

	if x % 3 == 0 or x % 3 == 2:
		print("First")
	else:
		print("Second")


### FIXED CODE ###

from collections import defaultdict
from collections import deque

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

class Graph(object):

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, a, b):
        self.graph[a].append(b)


class breadth(object):
    def __init__(self, graph, s):
        self.g = graph.graph
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[s] = 0
        self.visit = ["no" for i in range(len(graph) + 1)]
        self.visit[s] = "yes"

        self.Q = deque()
        self.Q.append([self.dist[s], s])

        while self.Q:
            dist_u, u = self.Q.popleft()
            for v in self.g[u]:
                if self.visit[v] == "yes":
                    continue
                else:
                    self.dist[v] = dist_u + 1
                    self.visit[v] = "yes"
                    self.Q.append([self.dist[v], v])


N = int(input())
if N == 1:
	print("First")
else:
	g_a = Graph()
	for i in range(N - 1):
		a, b = getlist()
		g_a.add_edge(a, b)
		g_a.add_edge(b, a)
	
	s = 1
	E = breadth(g_a, s)
	x = 0
	for i in E.dist:
		if E.dist[i] > x:
			x = E.dist[i]
			y = i
	F = breadth(g_a, y)
	x = 0
	for i in F.dist:
		if F.dist[i] > x:
			x = F.dist[i]
			y = i

	if x % 3 == 0 or x % 3 == 2:
		print("First")
	else:
		print("Second")