Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n, m = map(int, input().split())
x, y, z = [0]*n, [0]*n, [0]*n
for i in range(n):
  x[i], y[i], z[i] = map(int, input().split())
output = 0
for i in list(itertools.combinations(range(n), m)):
  r = abs(sum([x[s] for s in i])) + abs(sum([y[s] for s in i])) + \
      abs(sum([z[s] for s in i]))
  if output <= r:
    output = r
print(output)

Fixed submission:
import sys

def main():
  input = sys.stdin.readline
  N, M = map(int, input().split())
  ppp = []
  ppm = []
  pmp = []
  pmm = []
  mpp = []
  mpm = []
  mmp = []
  mmm = []
  for _ in range(N):
    x, y, z = map(int, input().split())
    ppp.append(x+y+z)
    ppm.append(x+y-z)
    pmp.append(x-y+z)
    pmm.append(x-y-z)
    mpp.append(-x+y+z)
    mpm.append(-x+y-z)
    mmp.append(-x-y+z)
    mmm.append(-x-y-z)
  ppp = sorted(ppp, key=lambda x:-x)
  ppm = sorted(ppm, key=lambda x:-x)
  pmp = sorted(pmp, key=lambda x:-x)
  pmm = sorted(pmm, key=lambda x:-x)
  mpp = sorted(mpp, key=lambda x:-x)
  mpm = sorted(mpm, key=lambda x:-x)
  mmp = sorted(mmp, key=lambda x:-x)
  mmm = sorted(mmm, key=lambda x:-x)

  ans = max(sum(ppp[:M]), sum(ppm[:M]), sum(pmp[:M]), sum(pmm[:M]),
            sum(mpp[:M]), sum(mpm[:M]), sum(mmp[:M]), sum(mmm[:M]))
  print(ans)


if __name__ == '__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n, m = map(int, input().split())
x, y, z = [0]*n, [0]*n, [0]*n
for i in range(n):
  x[i], y[i], z[i] = map(int, input().split())
output = 0
for i in list(itertools.combinations(range(n), m)):
  r = abs(sum([x[s] for s in i])) + abs(sum([y[s] for s in i])) + \
      abs(sum([z[s] for s in i]))
  if output <= r:
    output = r
print(output)

Fixed submission:
import sys

def main():
  input = sys.stdin.readline
  N, M = map(int, input().split())
  ppp = []
  ppm = []
  pmp = []
  pmm = []
  mpp = []
  mpm = []
  mmp = []
  mmm = []
  for _ in range(N):
    x, y, z = map(int, input().split())
    ppp.append(x+y+z)
    ppm.append(x+y-z)
    pmp.append(x-y+z)
    pmm.append(x-y-z)
    mpp.append(-x+y+z)
    mpm.append(-x+y-z)
    mmp.append(-x-y+z)
    mmm.append(-x-y-z)
  ppp = sorted(ppp, key=lambda x:-x)
  ppm = sorted(ppm, key=lambda x:-x)
  pmp = sorted(pmp, key=lambda x:-x)
  pmm = sorted(pmm, key=lambda x:-x)
  mpp = sorted(mpp, key=lambda x:-x)
  mpm = sorted(mpm, key=lambda x:-x)
  mmp = sorted(mmp, key=lambda x:-x)
  mmm = sorted(mmm, key=lambda x:-x)

  ans = max(sum(ppp[:M]), sum(ppm[:M]), sum(pmp[:M]), sum(pmm[:M]),
            sum(mpp[:M]), sum(mpm[:M]), sum(mmp[:M]), sum(mmm[:M]))
  print(ans)


if __name__ == '__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n, m = map(int, input().split())
x, y, z = [0]*n, [0]*n, [0]*n
for i in range(n):
  x[i], y[i], z[i] = map(int, input().split())
output = 0
for i in list(itertools.combinations(range(n), m)):
  sum_x = abs(sum([x[s] for s in i]))
  sum_y = abs(sum([y[s] for s in i]))
  sum_z = abs(sum([z[s] for s in i]))
  if output <= abs(sum_x)+abs(sum_y)+abs(sum_z):
    output = abs(sum_x)+abs(sum_y)+abs(sum_z)
print(output)

Fixed submission:
import sys

def main():
  input = sys.stdin.readline
  N, M = map(int, input().split())
  ppp = []
  ppm = []
  pmp = []
  pmm = []
  mpp = []
  mpm = []
  mmp = []
  mmm = []
  for _ in range(N):
    x, y, z = map(int, input().split())
    ppp.append(x+y+z)
    ppm.append(x+y-z)
    pmp.append(x-y+z)
    pmm.append(x-y-z)
    mpp.append(-x+y+z)
    mpm.append(-x+y-z)
    mmp.append(-x-y+z)
    mmm.append(-x-y-z)
  ppp = sorted(ppp, key=lambda x:-x)
  ppm = sorted(ppm, key=lambda x:-x)
  pmp = sorted(pmp, key=lambda x:-x)
  pmm = sorted(pmm, key=lambda x:-x)
  mpp = sorted(mpp, key=lambda x:-x)
  mpm = sorted(mpm, key=lambda x:-x)
  mmp = sorted(mmp, key=lambda x:-x)
  mmm = sorted(mmm, key=lambda x:-x)

  ans = max(sum(ppp[:M]), sum(ppm[:M]), sum(pmp[:M]), sum(pmm[:M]),
            sum(mpp[:M]), sum(mpm[:M]), sum(mmp[:M]), sum(mmm[:M]))
  print(ans)


if __name__ == '__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n, m = map(int, input().split())
x, y, z, s = [0]*n, [0]*n, [0]*n, [0]*n
for i in range(n):
  x[i], y[i], z[i] = map(int, input().split())
output = 0
for i in list(itertools.combinations(range(n), m)):
  sum_x = 0
  sum_y = 0
  sum_z = 0
  for j in range(m):
    sum_x += x[i[j]]
    sum_y += y[i[j]]
    sum_z += z[i[j]]
  if output <= abs(sum_x)+abs(sum_y)+abs(sum_z):
    output = abs(sum_x)+abs(sum_y)+abs(sum_z)
print(output)

Fixed submission:
import sys

def main():
  input = sys.stdin.readline
  N, M = map(int, input().split())
  ppp = []
  ppm = []
  pmp = []
  pmm = []
  mpp = []
  mpm = []
  mmp = []
  mmm = []
  for _ in range(N):
    x, y, z = map(int, input().split())
    ppp.append(x+y+z)
    ppm.append(x+y-z)
    pmp.append(x-y+z)
    pmm.append(x-y-z)
    mpp.append(-x+y+z)
    mpm.append(-x+y-z)
    mmp.append(-x-y+z)
    mmm.append(-x-y-z)
  ppp = sorted(ppp, key=lambda x:-x)
  ppm = sorted(ppm, key=lambda x:-x)
  pmp = sorted(pmp, key=lambda x:-x)
  pmm = sorted(pmm, key=lambda x:-x)
  mpp = sorted(mpp, key=lambda x:-x)
  mpm = sorted(mpm, key=lambda x:-x)
  mmp = sorted(mmp, key=lambda x:-x)
  mmm = sorted(mmm, key=lambda x:-x)

  ans = max(sum(ppp[:M]), sum(ppm[:M]), sum(pmp[:M]), sum(pmm[:M]),
            sum(mpp[:M]), sum(mpm[:M]), sum(mmp[:M]), sum(mmm[:M]))
  print(ans)


if __name__ == '__main__':
  main()