CodeEff/ECCO huggingface dataset:
# Original solution
*a,=list(map(int,open(0).read().split()));print(('YNeos'[all(t-set(map(a.index,a[10:]))for t in({0,1,2},{0,3,6},{0,4,8},{1,4,7},{2,4,6},{2,5,8},{3,4,5},{6,7,8}))::2]))

# Optimized solution
a=open(0).read().split();print(('YNeos'[all(t-set(map(a.index,a[10:]))for t in({0,1,2},{0,3,6},{0,4,8},{1,4,7},{2,4,6},{2,5,8},{3,4,5},{6,7,8}))::2]))
# Original solution
a=open(0).read().split();print(('YNeos'[all(t-set(map(a.index,a[10:]))for t in({0,3,6},{0,4,8},{1,4,7},{2,4,6},{2,5,8},{3,4,5},{6,7,8}))::2]))

# Optimized solution
a=open(0).read().split();print(('YNeos'[all(t-set(map(a.index,a[10:]))for t in({0,3,6},{0,4,8},{2,4,6},{2,5,8},{3,4,5},{6,7,8}))::2]))
# Original solution
A1=list(map(int, input().split()))
A2=list(map(int, input().split()))
A3=list(map(int, input().split()))
A=A1+A2+A3
N=int(eval(input()))
s=set()
for _ in range(N):
  b=int(eval(input()))
  if b in A:
    s|={A.index(b)}
bingo=[{0,1,2},{0,3,6},{0,4,8},{1,4,7},{2,4,6},{2,5,8},{3,4,5},{6,7,8}]
print((["No","Yes"][any(s>=b for b in bingo)]))



# Optimized solution
A1=list(map(int, input().split()))
A2=list(map(int, input().split()))
A3=list(map(int, input().split()))
A=A1+A2+A3
N=int(eval(input()))
s=set()
for _ in range(N):
  b=int(eval(input()))
  if b in A:
    s|={A.index(b)}
bingo=[{0,1,2},{0,3,6},{0,4,8},{1,4,7},{2,5,8},{2,4,6},{3,4,5},{6,7,8}]
print((['No','Yes'][any(s>=b for b in bingo)]))
# Original solution
a = []
for i in range(3):
    a1, a2, a3 = list(map(int, input().split()))
    a.append(a1)
    a.append(a2)
    a.append(a3)

l = [0]*9
n = int(eval(input()))

for i in range(n):
    b = int(eval(input()))
    if b in a:
        l[a.index(b)] += 1

if l[0] == 1 and l[1] == 1 and l[2] == 1:
    print('Yes')
elif l[3] == 1 and l[4] == 1 and l[5] == 1:
    print('Yes')
elif l[6] == 1 and l[7] == 1 and l[8] == 1:
    print('Yes')
elif l[0] == 1 and l[3] == 1 and l[6] == 1:
    print('Yes')
elif l[1] == 1 and l[4] == 1 and l[7] == 1:
    print('Yes')
elif l[2] == 1 and l[5] == 1 and l[8] == 1:
    print('Yes')
elif l[0] == 1 and l[4] == 1 and l[8] == 1:
    print('Yes')
elif l[2] == 1 and l[4] == 1 and l[6] == 1:
    print('Yes')
else:
    print('No')

# Optimized solution
a = []
for i in range(3):
    a1, a2, a3 = list(map(int, input().split()))
    a.append(a1)
    a.append(a2)
    a.append(a3)

l = [0]*9
n = int(eval(input()))

for i in range(n):
    b = int(eval(input()))
    for k in range(9):
        if a[k] == b:
            l[k] += 1
 
if l[0] == 1 and l[1] == 1 and l[2] == 1:
    print('Yes')
elif l[3] == 1 and l[4] == 1 and l[5] == 1:
    print('Yes')
elif l[6] == 1 and l[7] == 1 and l[8] == 1:
    print('Yes')
elif l[0] == 1 and l[3] == 1 and l[6] == 1:
    print('Yes')
elif l[1] == 1 and l[4] == 1 and l[7] == 1:
    print('Yes')
elif l[2] == 1 and l[5] == 1 and l[8] == 1:
    print('Yes')
elif l[0] == 1 and l[4] == 1 and l[8] == 1:
    print('Yes')
elif l[2] == 1 and l[4] == 1 and l[6] == 1:
    print('Yes')
else:
    print('No')
# Original solution
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
A3 = list(map(int,input().split()))
n = int(eval(input()))

A = [[0,0,0],[0,0,0],[0,0,0]]

for _ in range(n):
    b = int(eval(input()))
    if b in A1:
        tmp = A1.index(b)
        A[0][tmp] = 1
    elif b in A2:
        tmp = A2.index(b)
        A[1][tmp] = 1
    elif b in A3:
        tmp = A3.index(b)
        A[2][tmp] = 1

if A[0][0] + A[0][1] + A[0][2] == 3 or A[1][0] + A[1][1] + A[1][2] == 3 or A[2][0] + A[2][1] + A[2][2] == 3:
    print('Yes')
elif A[0][0] + A[1][0] + A[2][0] == 3 or A[0][1] + A[1][1] + A[2][1] == 3 or A[0][2] + A[1][2] + A[2][2] == 3:
    print('Yes')
elif A[0][0] + A[1][1] + A[2][2] == 3 or A[0][2] + A[1][1] + A[2][0] == 3:
    print('Yes')
else:
    print('No')

# Optimized solution
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
A3 = list(map(int,input().split()))
n = int(eval(input()))

A = [[0,0,0],[0,0,0],[0,0,0]]

for _ in range(n):
    b = int(eval(input()))
    if b in A1:
        tmp = A1.index(b)
        A[0][tmp] = 1
    elif b in A2:
        tmp = A2.index(b)
        A[1][tmp] = 1
    elif b in A3:
        tmp = A3.index(b)
        A[2][tmp] = 1
'''
if A[0][0] + A[0][1] + A[0][2] == 3 or A[1][0] + A[1][1] + A[1][2] == 3 or A[2][0] + A[2][1] + A[2][2] == 3:
    print('Yes')
elif A[0][0] + A[1][0] + A[2][0] == 3 or A[0][1] + A[1][1] + A[2][1] == 3 or A[0][2] + A[1][2] + A[2][2] == 3:
    print('Yes')
'''
ans = 'No'

for i in range(3):
    if A[0][i] == A[1][i] == A[2][i] == 1:
        ans = 'Yes'
    elif A[i][0] == A[i][1] == A[i][2]== 1:
        ans = 'Yes'
if A[0][0] + A[1][1] + A[2][2] == 3 or A[0][2] + A[1][1] + A[2][0] == 3:
    ans = 'Yes'

print(ans)
# Original solution
import sys

def input():
    return sys.stdin.readline().strip()

def main():
    
    a = [[0]*3 for i in range(3)]
    for i in range(3):
        a[i] = list(map(int, input().split()))
    n = int(eval(input()))
    b = [0]*n
    bingo = "No"
    for i in range(n):
        b[i] = int(eval(input()))
        for k in range(3):
            if a[k][0] == b[i]:
                a[k][0] = 0
            if a[k][1] == b[i]:
                a[k][1] = 0
            if a[k][2] == b[i]:
                a[k][2] = 0
    for i in range(3):
        if a[i][0]+a[i][1]+a[i][2] == 0:
            bingo = "Yes"
    for i in range(3):
        if a[0][i]+a[1][i]+a[2][i] == 0:
            bingo = "Yes"
    if a[0][0]+a[1][1]+a[2][2] == 0:
        bingo = "Yes"
    if a[2][0]+a[1][1]+a[0][2] == 0:
        bingo = "Yes"
     
    print(bingo)
main()

# Optimized solution
import sys

def input():
    return sys.stdin.readline().strip()


    
a = [[0]*3 for i in range(3)]
for i in range(3):
    a[i] = list(map(int, input().split()))
n = int(eval(input()))
b = [0]*n
bingo = "No"
for i in range(n):
    b[i] = int(eval(input()))
    for k in range(3):
        if a[k][0] == b[i]:
            a[k][0] = 0
        if a[k][1] == b[i]:
            a[k][1] = 0
        if a[k][2] == b[i]:
            a[k][2] = 0
for i in range(3):
    if a[i][0]+a[i][1]+a[i][2] == 0:
        bingo = "Yes"
for i in range(3):
    if a[0][i]+a[1][i]+a[2][i] == 0:
        bingo = "Yes"
if a[0][0]+a[1][1]+a[2][2] == 0:
    bingo = "Yes"
if a[2][0]+a[1][1]+a[0][2] == 0:
    bingo = "Yes"
 
print(bingo)
# Original solution
A = [[]]*3
for T in range(0,3):
    A[T] = [int(x) for x in input().split()]
A   = sum(A,[])
ATF = [False]*9

N = int(eval(input()))
for TT in range(0,N):
    B = int(eval(input()))
    if B in A:
        ATF[A.index(B)] = True

Flag = 0
if   (all(ATF[:3])) or (all(ATF[3:6])) or (all(ATF[6:])):
    Flag = 1
elif (all(ATF[::3])) or (all(ATF[1::3])) or (all(ATF[2::3])):
    Flag = 1
elif (all(ATF[::4])) or (all(ATF[2:7:2])):
    Flag = 1

if Flag:
    print('Yes')
else:
    print('No')

# Optimized solution
A = [[]]*3
for T in range(0,3):
    A[T] = [int(x) for x in input().split()]
A   = sum(A,[])
ATF = [False]*9
 
N = int(eval(input()))
for TT in range(0,N):
    B = int(eval(input()))
    if B in A:
        ATF[A.index(B)] = True

Flag = False
if   (all(ATF[:3])) or (all(ATF[3:6])) or (all(ATF[6:])):
    Flag = True
elif (all(ATF[::3])) or (all(ATF[1::3])) or (all(ATF[2::3])):
    Flag = True
elif (all(ATF[::4])) or (all(ATF[2:7:2])):
    Flag = True
    
if Flag:
    print('Yes')
else:
    print('No')
# Original solution
def resolve():
    A1 = list(map(int, input().split()))
    A2 = list(map(int, input().split()))
    A3 = list(map(int, input().split()))
    N = int(eval(input()))
    b = [int(eval(input())) for i in range(N)]

    A = A1 + A2 + A3
    checkA = [0]*9
    for i in range(N):
        if b[i] in A:
            checkA[A.index(b[i])] = 1
    if checkA[0] + A[1] + A[2] == 3:
        print('Yes')
    elif checkA[3] + checkA[4] + checkA[5] == 3:
        print('Yes')
    elif checkA[6] + checkA[7] + checkA[8] == 3:
        print('Yes')
    elif checkA[0] + checkA[3] + checkA[6] == 3:
        print('Yes')
    elif checkA[1] + checkA[4] + checkA[7] == 3:
        print('Yes')
    elif checkA[2] + checkA[5] + checkA[8] == 3:
        print('Yes')
    elif checkA[0] + checkA[4] + checkA[8] == 3:
        print('Yes')
    elif checkA[2] + checkA[4] + checkA[6] == 3:
        print('Yes')
    else:
        print('No')
resolve()

# Optimized solution
def resolve():
    A1 = list(map(int, input().split()))
    A2 = list(map(int, input().split()))
    A3 = list(map(int, input().split()))
    N = int(eval(input()))
    b = [int(eval(input())) for i in range(N)]
 
    A = A1 + A2 + A3
    checkA = [0]*9
    for i in range(N):
        if b[i] in A:
            checkA[A.index(b[i])] = 1
    if checkA[0] + checkA[1] + checkA[2] == 3:
        print('Yes')
    elif checkA[3] + checkA[4] + checkA[5] == 3:
        print('Yes')
    elif checkA[6] + checkA[7] + checkA[8] == 3:
        print('Yes')
    elif checkA[0] + checkA[3] + checkA[6] == 3:
        print('Yes')
    elif checkA[1] + checkA[4] + checkA[7] == 3:
        print('Yes')
    elif checkA[2] + checkA[5] + checkA[8] == 3:
        print('Yes')
    elif checkA[0] + checkA[4] + checkA[8] == 3:
        print('Yes')
    elif checkA[2] + checkA[4] + checkA[6] == 3:
        print('Yes')
    else:
        print('No')
resolve()
# Original solution
def B():
    a = [list(map(int,input().split())) for i in range(3)]
    n = int(eval(input()))
    #b = [list(map(int,input().split())) for i in range(n)]
    for bingo in  (int(eval(input())) for _ in range(n)):
        for i in range(3):
            for j in range(3):
                if a[i][j] == bingo:
                    a[i][j] = 0
    if (a[0][0] == a[1][1] == a[2][2] == 0) or (a[0][2] == a[1][1] == a[2][0] == 0):
        print("Yes")
        return
    for i in range(3):
        if (a[i][0] == a[i][1] == a[i][2] == 0) or (a[0][i] == a[1][i] == a[2][i] == 0):
            print("Yes")
            return
    print("No")
B()

# Optimized solution
def B():
    a = [list(map(int,input().split())) for i in range(3)]
    n = int(eval(input()))
    #b = [list(map(int,input().split())) for i in range(n)]
    for bingo in  (int(eval(input())) for _ in range(n)):
        for i in range(3):
            for j in range(3):
                if a[i][j] == bingo:
                    a[i][j] = 0
    if (a[0][0] == a[1][1] == a[2][2] == 0) or (a[0][2] == a[1][1] == a[2][0] == 0):
        print("Yes")
        return
    for i in range(3):
        if all(a[i][j] == 0 for j in range(3)) or all(a[j][i] == 0 for j in range(3)):
            print("Yes")
            return
    print("No")
B()
# Original solution
#!/usr/bin/env python3
import sys

# input
a = [['' for _ in range(3)] for _ in range(3)]
a[0] = list(map(int, input().split()))
a[1] = list(map(int, input().split()))
a[2] = list(map(int, input().split()))
n = int(eval(input()))
b = []
for _ in range(n):
    tmp = int(eval(input()))
    b.append(tmp)

# calc
f = [['' for _ in range(3)] for _ in range(3)]
for i in range(3):
    for j in range(3): f[i][j] = 0

for i in range(3):
    for j in range(3):
        for k in range(n):
            if a[i][j] == b[k]:
                f[i][j] = 1

for i in range(3):
    s = 0
    for j in range(3):
        s += f[i][j]
    if s == 3:
        print('Yes')
        sys.exit()

for i in range(3):
    s = 0
    for j in range(3):
        s += f[j][i]
    if s == 3:
        print('Yes')
        sys.exit()

if f[0][0] + f[1][1] + f[2][2] == 3:
    print('Yes')
    sys.exit()
if f[0][2] + f[1][1] + f[2][0] == 3:
    print('Yes')
    sys.exit()

print('No')

# Optimized solution
#!/usr/bin/env python3
import sys 

# input
a = [list(map(int, input().split())) for _ in range(3)]
n = int(eval(input()))
b = [int(eval(input())) for _ in range(n)]

# calc
f = [[0 for _ in range(3)] for _ in range(3)]
for i in range(3):
    for j in range(3):
        if a[i][j] in b:
            f[i][j] = 1 

for i in range(3):
    s = 0 
    u = 0 
    for j in range(3):
        s += f[i][j]
        u += f[j][i]
    if s == 3 or u == 3:
        print('Yes')
        sys.exit()

if f[0][0] + f[1][1] + f[2][2] == 3 or f[0][2] + f[1][1] + f[2][0] == 3:
    print('Yes')
    sys.exit()

print('No')
# Original solution
N,M = list(map(int, input().split()))
xyz = [tuple(map(int, input().split())) for _ in range(N)]

constraint = []
for x,y,z in xyz:
    ci = []
    for b in range(8):
        v = 0
        if (b>>0)&1==1: v += x 
        else: v -= x
        if (b>>1)&1==1: v += y
        else: v -= y
        if (b>>2)&1==1: v += z 
        else: v -= z
        ci.append(v)
    #print(ci)
    constraint.append(ci)

ans = 0
for c in zip(*constraint):
    cond = sorted(c, reverse=True)[:M]
    ans = max(ans, sum(cond))
print(ans)

# Optimized solution
if __name__ == '__main__':
    N,M = list(map(int, input().split()))
    xyz = [tuple(map(int, input().split())) for _ in range(N)]

    constraint = []
    for x,y,z in xyz:
        ci = []
        for b in range(8):
            v = 0
            if (b>>0)&1==1: v += x 
            else: v -= x
            if (b>>1)&1==1: v += y
            else: v -= y
            if (b>>2)&1==1: v += z 
            else: v -= z
            ci.append(v)
        #print(ci)
        constraint.append(ci)

    ans = 0
    for c in zip(*constraint):
        cond = sorted(c, reverse=True)[:M]
        ans = max(ans, sum(cond))
    print(ans)
# Original solution
import itertools
N,M = [int(i) for i in input().split(' ')]

x = []

for i in range(N):
    x.append([int(i) for i in input().split(' ')])

ans = 0
p = list(itertools.permutations(x,M));
for i in p:
    A=0
    B =0
    C=0
    for j in range(M):
        A += i[j][0]
        B += i[j][1]
        C += i[j][2]
    if A<0:
        A = -A
    if B<0:
        B = -B
    if C<0:
        C = -C
    a = A+B+C
    if a > ans:
        ans = a

#print(p)
print(ans)
   


# Optimized solution
import itertools
N,M = [int(i) for i in input().split(' ')]

x = []

for i in range(N):
    x.append([int(i) for i in input().split(' ')])
tab = [0]*N
ans = 0
#p = list(itertools.permutations(x,M));
for S in [[1,1,1],[1,1,-1],[1,-1,1],[1,-1,-1],[-1,1,1],[-1,1,-1],[-1,-1,1],[-1,-1,-1]]:
    for j in range(N):
        a = 0
        a += x[j][0]*S[0]
        a += x[j][1]*S[1]
        a += x[j][2]*S[2]
        tab[j] = a
    tab.sort()
#    print(tab)
    a =0
    for j in range(M):
        a += tab[N-j-1]
 #   print(a)
    if a > ans:
        ans = a

#print(p)
print(ans)
# Original solution
[N, M] = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(N)]
def value(xyz, sign):
	return sum([xyz[i]*(1 - 2*((sign & (1 << i)) >> i)) for i in range(3)])
print((0 if M == 0 else max([sum([value(a[j], sign) for j in sorted([i for i in range(N)], key = lambda index : value(a[index], sign))[-M:]]) for sign in range(8)])))

# Optimized solution
[N, M] = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(N)]
def v(x, s):
	return sum([x[i]*(1 - 2*((s & (1 << i)) >> i)) for i in range(3)])
print((0 if M == 0 else max([sum([v(a[j], s) for j in sorted([i for i in range(N)], key = lambda i : v(a[i], s))[-M:]]) for s in range(8)])))
# Original solution
[N, M] = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(N)]
def v(x, s):
	return sum([x[i]*(1 - 2*((s & (1 << i)) >> i)) for i in range(3)])
print((0 if M == 0 else max([sum([v(a[j], s) for j in sorted([i for i in range(N)], key = lambda i : v(a[i], s))[-M:]]) for s in range(8)])))

# Optimized solution
[N, M] = list(map(int, input().split()))
a = eval('input().split(),'*N)
print((0 if M==0 else max([sum(sorted([sum([int(x[b])*(s>>b&1or-1)for b in range(3)]) for x in a])[-M:])for s in range(8)])))
# Original solution
n,m = list(map(int, input().split()))
a=[]
for i in range(n):
    a.append(tuple(map(int, input().split())))

dp = []
for i in range(m+1):
    dp.append([0 for j in range(n+1)])

def f(fn):
    global dp, a
    for i in range(1,m+1):
        for j in range(1,n+1):
            dp[i][j] = max(dp[i][j-1], dp[i-1][j-1] + fn(a[j-1]))

ans = []
f(lambda x: x[0]+x[1]+x[2])
ans.append(dp[m][n])
f(lambda x: x[0]+x[1]-x[2])
ans.append(dp[m][n])
f(lambda x: x[0]-x[1]+x[2])
ans.append(dp[m][n])
f(lambda x: x[0]-x[1]-x[2])
ans.append(dp[m][n])
f(lambda x: -x[0]+x[1]+x[2])
ans.append(dp[m][n])
f(lambda x: -x[0]+x[1]-x[2])
ans.append(dp[m][n])
f(lambda x: -x[0]-x[1]+x[2])
ans.append(dp[m][n])
f(lambda x: -x[0]-x[1]-x[2])
ans.append(dp[m][n])

print((max(ans)))


# Optimized solution
n,m = list(map(int, input().split()))
a=[]
for i in range(n):
    a.append(tuple(map(int, input().split())))

dp = []
for i in range(m+1):
    dp.append([0 for j in range(n+1)])

def f(fn):
    global dp, a
    for i in range(1,m+1):
        for j in range(i,n+1):
            if j == i:
                dp[i][j] = sum(map(fn, a[:j]))
            else:
                dp[i][j] = max(dp[i][j-1], dp[i-1][j-1] + fn(a[j-1]))

ans = []
f(lambda x: x[0]+x[1]+x[2])
ans.append(dp[m][n])
f(lambda x: x[0]+x[1]-x[2])
ans.append(dp[m][n])
f(lambda x: x[0]-x[1]+x[2])
ans.append(dp[m][n])
f(lambda x: x[0]-x[1]-x[2])
ans.append(dp[m][n])
f(lambda x: -x[0]+x[1]+x[2])
ans.append(dp[m][n])
f(lambda x: -x[0]+x[1]-x[2])
ans.append(dp[m][n])
f(lambda x: -x[0]-x[1]+x[2])
ans.append(dp[m][n])
f(lambda x: -x[0]-x[1]-x[2])
ans.append(dp[m][n])

print((max(ans)))
# Original solution
N,M = list(map(int,input().split()))
cake = [list(map(int,input().split())) for _ in range(N)]

ans = 0
for i in range(8):
    sign = [0,0,0]
    for j in range(3):
        sign[j] = (i>>j & 1)
    cake_i = []
    for k in range(N):
        s = 0
        for j in range(3):
            s += cake[k][j]*(1-2*sign[j])
        cake_i.append(s)
    cake_i.sort(reverse = True)
    ans = max(ans,sum(cake_i[:M]))
    
print(ans)

# Optimized solution
N, M = list(map(int, input().split()))
C = [tuple(map(int, input().split())) for _ in range(N)]

res = 0

for i in range(8):
    D = [0 for _ in range(N)]
    for j in range(N):
        x, y, z = C[j]
        if (i >> 0) & 1:
            D[j] += x
        else:
            D[j] -= x
        if (i >> 1) & 1:
            D[j] += y
        else:
            D[j] -= y
        if (i >> 2) & 1:
            D[j] += z
        else:
            D[j] -= z
    D.sort(reverse=True)
    res = max(res, sum(D[:M]))

print(res)
# Original solution
# ABC100D - Patisserie ABC
def calc(func: "func") -> int:
    cakes = [func(x, y, z) for x, y, z in zip(*[iter(XYZ)] * 3)]
    cakes.sort(reverse=1)
    return sum(cakes[:M])


def main():
    global M, XYZ
    N, M, *XYZ = list(map(int, open(0).read().split()))
    ans = max(
        calc(lambda x, y, z: x + y + z),
        calc(lambda x, y, z: x + y - z),
        calc(lambda x, y, z: x - y + z),
        calc(lambda x, y, z: x - y - z),
        calc(lambda x, y, z: -x + y + z),
        calc(lambda x, y, z: -x + y - z),
        calc(lambda x, y, z: -x - y + z),
        calc(lambda x, y, z: -x - y - z),
    )
    print(ans)


if __name__ == "__main__":
    main()

# Optimized solution
# ABC100D - Patisserie ABC
def calc(func: "func") -> int:
    cakes = [func(x, y, z) for x, y, z in zip(*[iter(XYZ)] * 3)]
    cakes.sort(reverse=1)
    return max(sum(cakes[:M]), -sum(cakes[-M:]))


def main():
    global M, XYZ
    N, M, *XYZ = list(map(int, open(0).read().split()))
    if M == 0:
        print((0))
        return
    ans = max(
        calc(lambda x, y, z: x + y + z),
        calc(lambda x, y, z: x + y - z),
        calc(lambda x, y, z: x - y + z),
        calc(lambda x, y, z: x - y - z),
    )
    print(ans)


if __name__ == "__main__":
    main()
# Original solution
n,m=list(map(int,input().split()))
x,y,z=[],[],[]
for i in range(n):
  xi,yi,zi=list(map(int,input().split()))
  x.append(xi)
  y.append(yi)
  z.append(zi)

ans=0
for i in range(2**3):
  op=['-','-','-']
  for j in range(3):
    if (i>>j)&1:
      op[j]='+'

  tx=x[::]
  ty=y[::]
  tz=z[::]

  if op[0]=='-':
    tx=list([-1*a for a in tx])
  if op[1]=='-':
    ty=list([-1*a for a in ty])
  if op[2]=='-':
    tz=list([-1*a for a in tz])

  xyz_l=[tx[i]+ty[i]+tz[i] for i in range(n)]
  xyz_l.sort(reverse=True)

  ans=max(ans,sum(xyz_l[:m]))

print(ans)

# Optimized solution
n,m=list(map(int,input().split()))
xyz=[list(map(int,input().split())) for i in range(n)]

ans=0
for i in [-1,1]:
  for j in [-1,1]:
    for k in [-1,1]:
      l=[i*xyz[z][0]+j*xyz[z][1]+k*xyz[z][2] for z in range(n)]
      l.sort(reverse=True)
      ans=max(ans,sum(l[:m]))
print(ans)
# Original solution
from sys import stdin
nii=lambda:list(map(int,stdin.readline().split()))
lnii=lambda:list(map(int,stdin.readline().split()))

n,m=nii()
l=[lnii() for i in range(n)]

ans=0
for i in range(2**3):
  t_l=[]
  for j in l:
    t_num=0
    for k in range(3):
      if (i>>k)&1:
        t_num+=j[k]
      else:
        t_num-=j[k]
    t_l.append(t_num)

  t_l.sort(reverse=True)
  ans=max(ans,sum(t_l[:m]))

print(ans)

# Optimized solution
from sys import stdin
nii=lambda:list(map(int,stdin.readline().split()))
lnii=lambda:list(map(int,stdin.readline().split()))

n,m=nii()
l=[lnii() for i in range(n)]

ans=0
for i in [1,-1]:
  for j in [1,-1]:
    for k in [1,-1]:
      t_num=0
      t_l=[]
      for x,y,z in l:
        t_num=x*i+y*j+z*k
        t_l.append(t_num)
      t_l.sort(reverse=True)
      ans=max(ans,sum(t_l[:m]))

print(ans)
# Original solution
import sys
def input(): return sys.stdin.readline().strip()


def main():
    N, M = list(map(int, input().split()))
    cakes = [(0, 0, 0)]
    for _ in range(N):
        x, y, z = list(map(int, input().split()))
        cakes.append((x, y, z))

    """
    dp[n][m][t] = (1~n番目までのケーキからm個のケーキをタイプtで選んだ時の合計の最大値)
    と定める。ここでタイプとは
        t=0 -> val = x + y + z
        t=1 -> val = x + y - z
        t=2 -> val = x - y + z
        t=3 -> val = x - y - z
        t=4 -> val = -x + y + z
        t=5 -> val = -x + y - z
        t=6 -> val = -x - y + z
        t=7 -> val = -x - y - z
    どのタイプにせよ更新式は同じで、dp[n][m] = max(dp[n-1][m], dp[n-1][m-1] + (n番目のdp = [0]aaa))
    """

    dp = [[[0] * 8 for _ in range(M + 1)] for _ in range(N + 1)]
    for n in range(1, N + 1):
        x, y, z = cakes[n]
        for m in range(1, min(M + 1, n + 1)):
            if n == m:
                dp[n][m][0] = dp[n - 1][m - 1][0] + (x + y + z)
                dp[n][m][1] = dp[n - 1][m - 1][1] + (x + y - z)
                dp[n][m][2] = dp[n - 1][m - 1][2] + (x - y + z)
                dp[n][m][3] = dp[n - 1][m - 1][3] + (x - y - z)
                dp[n][m][4] = dp[n - 1][m - 1][4] + (-x + y + z)
                dp[n][m][5] = dp[n - 1][m - 1][5] + (-x + y - z)
                dp[n][m][6] = dp[n - 1][m - 1][6] + (-x - y + z)
                dp[n][m][7] = dp[n - 1][m - 1][7] + (-x - y - z)
            else:
                dp[n][m][0] = max(dp[n - 1][m][0], dp[n - 1][m - 1][0] + (x + y + z))
                dp[n][m][1] = max(dp[n - 1][m][1], dp[n - 1][m - 1][1] + (x + y - z))
                dp[n][m][2] = max(dp[n - 1][m][2], dp[n - 1][m - 1][2] + (x - y + z))
                dp[n][m][3] = max(dp[n - 1][m][3], dp[n - 1][m - 1][3] + (x - y - z))
                dp[n][m][4] = max(dp[n - 1][m][4], dp[n - 1][m - 1][4] + (-x + y + z))
                dp[n][m][5] = max(dp[n - 1][m][5], dp[n - 1][m - 1][5] + (-x + y - z))
                dp[n][m][6] = max(dp[n - 1][m][6], dp[n - 1][m - 1][6] + (-x - y + z))
                dp[n][m][7] = max(dp[n - 1][m][7], dp[n - 1][m - 1][7] + (-x - y - z))
    print((max(dp[N][M])))

if __name__ == "__main__":
    main()


# Optimized solution
import sys
def input(): return sys.stdin.readline().strip()


def main():
    N, M = list(map(int, input().split()))
    cakes = [(0, 0, 0)]
    for _ in range(N):
        x, y, z = list(map(int, input().split()))
        cakes.append((x, y, z))

    """
    これはdpするべきではなかった。O(NlogN)で解ける。
    単純にx+y+zやx-y-z等のそれぞれに対してcakesをソートして大きい値から取れば良い。
    """

    ans = 0
    for i in range(8):
        sorted_cakes = []
        for j in range(1, N + 1):
            S = 0
            for k in range(3): # iの立っているビットでx, y, zの符号を管理している！！
                if i & (1 << k):
                    S += cakes[j][k]
                else:
                    S -= cakes[j][k]
            sorted_cakes.append(S)
        sorted_cakes.sort()
        ans = max(ans, sum(sorted_cakes[N - M:]))
    print(ans)


if __name__ == "__main__":
    main()