Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
from itertools import product
n, m = list(map(int, input().split()))
xyz = [list(map(int, input().split())) for i in range(n)]

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


# eval
# eval_list = ["+xyz[i-1][0]+xyz[i-1][1]+xyz[i-1][2]",
#              "+xyz[i-1][0]+xyz[i-1][1]-xyz[i-1][2]",
#              "+xyz[i-1][0]-xyz[i-1][1]+xyz[i-1][2]",
#              "+xyz[i-1][0]-xyz[i-1][1]-xyz[i-1][2]",
#              "-xyz[i-1][0]+xyz[i-1][1]+xyz[i-1][2]",
#              "-xyz[i-1][0]+xyz[i-1][1]-xyz[i-1][2]",
#              "-xyz[i-1][0]-xyz[i-1][1]+xyz[i-1][2]",
#              "-xyz[i-1][0]-xyz[i-1][1]-xyz[i-1][2]", ]

ans = []
for a, b, c in product([1, -1], repeat=3):
    for i in range(1, n+1):
        for j in range(1, min(i+1, m+1)):
            tmp = xyz[i-1][0]*a + xyz[i-1][1]*b + xyz[i-1][2]*c
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-1] + tmp)

    ans.append(dp[-1][-1])
print(max(ans))


Fixed submission:
#!/usr/bin/env python3
from itertools import product
n, m = list(map(int, input().split()))
xyz = [list(map(int, input().split())) for i in range(n)]

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


# eval
# eval_list = ["+xyz[i-1][0]+xyz[i-1][1]+xyz[i-1][2]",
#              "+xyz[i-1][0]+xyz[i-1][1]-xyz[i-1][2]",
#              "+xyz[i-1][0]-xyz[i-1][1]+xyz[i-1][2]",
#              "+xyz[i-1][0]-xyz[i-1][1]-xyz[i-1][2]",
#              "-xyz[i-1][0]+xyz[i-1][1]+xyz[i-1][2]",
#              "-xyz[i-1][0]+xyz[i-1][1]-xyz[i-1][2]",
#              "-xyz[i-1][0]-xyz[i-1][1]+xyz[i-1][2]",
#              "-xyz[i-1][0]-xyz[i-1][1]-xyz[i-1][2]", ]

ans = 0
for a, b, c in product([1, -1], repeat=3):
    total = []
    for x, y, z in xyz:
        s = x*a+y*b+z*c
        total.append(s)
    total.sort(reverse=True)
    ans = max(ans, sum(total[:m]))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

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

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


# eval
eval_list = ["+xyz[i-1][0]+xyz[i-1][1]+xyz[i-1][2]",
             "+xyz[i-1][0]+xyz[i-1][1]-xyz[i-1][2]",
             "+xyz[i-1][0]-xyz[i-1][1]+xyz[i-1][2]",
             "+xyz[i-1][0]-xyz[i-1][1]-xyz[i-1][2]",
             "-xyz[i-1][0]+xyz[i-1][1]+xyz[i-1][2]",
             "-xyz[i-1][0]+xyz[i-1][1]-xyz[i-1][2]",
             "-xyz[i-1][0]-xyz[i-1][1]+xyz[i-1][2]",
             "-xyz[i-1][0]-xyz[i-1][1]-xyz[i-1][2]", ]

ans = []
for k in range(len(eval_list)):
    for i in range(1, n+1):
        for j in range(1, min(i+1, m+1)):
            tmp = eval(eval_list[k])
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-1] + tmp)

    ans.append(dp[-1][-1])
print(max(ans))


Fixed submission:
#!/usr/bin/env python3
from itertools import product
n, m = list(map(int, input().split()))
xyz = [list(map(int, input().split())) for i in range(n)]

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


# eval
# eval_list = ["+xyz[i-1][0]+xyz[i-1][1]+xyz[i-1][2]",
#              "+xyz[i-1][0]+xyz[i-1][1]-xyz[i-1][2]",
#              "+xyz[i-1][0]-xyz[i-1][1]+xyz[i-1][2]",
#              "+xyz[i-1][0]-xyz[i-1][1]-xyz[i-1][2]",
#              "-xyz[i-1][0]+xyz[i-1][1]+xyz[i-1][2]",
#              "-xyz[i-1][0]+xyz[i-1][1]-xyz[i-1][2]",
#              "-xyz[i-1][0]-xyz[i-1][1]+xyz[i-1][2]",
#              "-xyz[i-1][0]-xyz[i-1][1]-xyz[i-1][2]", ]

ans = 0
for a, b, c in product([1, -1], repeat=3):
    total = []
    for x, y, z in xyz:
        s = x*a+y*b+z*c
        total.append(s)
    total.sort(reverse=True)
    ans = max(ans, sum(total[:m]))
print(ans)