Buggy python submission (verdict: Runtime Error):
#!/usr/bin/python3
# -*- coding:utf-8 -*-


def main():
  n, m = map(int, input().split())
  lxyz = [[0]*3 for _ in range(n)]
  for i in range(n):
    lxyz[i] = list(map(int, input().split()))
  
  def binary(x, k, t=1, f=0):
    return [t if (x >> ik)%2 else f for ik in range(k)]
  
  def calc_dp(lxyz):
    dp = [[0] * m for _ in range(n)]

    max_score = -(10 ** 15) 
    for i in range(n):
      max_score = max(lxyz[i], max_score)
      dp[i][0] = max_score
      
    for i in range(1, n):
      for j in range(1, m):
        if i == j == 0: 
          continue
        dp[i][j] = max(dp[i-1][j-1] + lxyz[i], dp[i-1][j])
    return dp[-1][-1]
    
  ans = -1
  for lh in [binary(i, 3, f=-1) for i in range(8)]:
    ans = max(ans, abs(calc_dp([sum(map(lambda x: x[0]*x[1], zip(lh, lxyz[i]))) for i in range(n)]))) 
  print(ans)
  
if __name__=='__main__':
  main()



Fixed submission:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n, m = map(int, input().split())
  lxyz = [[0]*3 for _ in range(n)]
  for i in range(n):
    lxyz[i] = list(map(int, input().split()))
  
  def binary(x, k, t=1, f=0):
    return [t if (x >> ik)%2 else f for ik in range(k)]
  
  ans = -1
  for lh in [binary(i, 3, f=-1) for i in range(8)]:
    ans = max(ans, abs(sum(sorted([sum(map(lambda x: x[0]*x[1], zip(lh, lxyz[i]))) for i in range(n)], reverse=True)[:m]))) 
  print(ans)
  
if __name__=='__main__':
  main()

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/python3
# -*- coding:utf-8 -*-


def main():
  n, m = map(int, input().split())
  lxyz = [[0]*3 for _ in range(n)]
  for i in range(n):
    lxyz[i] = list(map(int, input().split()))
  
  def binary(x, k, t=1, f=0):
    return [t if (x >> ik)%2 else f for ik in range(k)]
  
  def calc_dp(lxyz):
    dp = [
      [
        [0] * 3
        for _ in range(m)]
      for _ in range(n)]

    max_score = -(10 ** 15) 
    max_xyz = lxyz[0]
    for i in range(n):
      score = sum(lxyz[i])
      if score > max_score:
        max_xyz = lxyz[i]
        max_score = score
      dp[i][0] = max_xyz
      
    for i in range(1, n):
      for j in range(1, m):
        if i == j == 0: 
          continue
        use_i = list(map(sum, zip(dp[i-1][j-1], lxyz[i])))
        if sum(use_i) > sum(dp[i-1][j]):
          dp[i][j] = use_i
        else:
          dp[i][j] = dp[i-1][j]
    return sum(dp[-1][-1])
    
  
  ans = -1
  for lh in [binary(i, 3, f=-1) for i in range(8)]:
    _lxyz = [[0]*3 for _ in range(n)]
    for j, h in enumerate(lh):
        for i in range(n):
          _lxyz[i][j] = h * lxyz[i][j]    
    ans = max(ans, abs(calc_dp(_lxyz))) 
  print(ans)
  
if __name__=='__main__':
  main()



Fixed submission:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n, m = map(int, input().split())
  lxyz = [[0]*3 for _ in range(n)]
  for i in range(n):
    lxyz[i] = list(map(int, input().split()))
  
  def binary(x, k, t=1, f=0):
    return [t if (x >> ik)%2 else f for ik in range(k)]
  
  ans = -1
  for lh in [binary(i, 3, f=-1) for i in range(8)]:
    ans = max(ans, abs(sum(sorted([sum(map(lambda x: x[0]*x[1], zip(lh, lxyz[i]))) for i in range(n)], reverse=True)[:m]))) 
  print(ans)
  
if __name__=='__main__':
  main()