Buggy python submission (verdict: Time Limit Exceeded):
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)
   


Fixed submission:
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)

Buggy python submission (verdict: Time Limit Exceeded):
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)
   


Fixed submission:
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)

Buggy python submission (verdict: Time Limit Exceeded):
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]

    a = abs(A) + abs(B) + abs(C)
    ans = max(a,ans)

#print(p)
print(ans)
   


Fixed submission:
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)