Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    li = []
    for _ in range(n):
        xi, yi, pi = map(int, input().split())
        li.append([xi, yi, pi])
    li.sort(key=lambda x: x[2],reverse=True)
    xx=[[abs(li[j][0]) for j in range(n)] for i in range(2**n)]
    yy=[[abs(li[j][1]) for j in range(n)] for i in range(2**n)]
 
    for i in range(2**n):
        X=[0]
        rest=[]
        for j in range(n):
            if i>>j&1==1:
                X.append(li[j][0])
                xx[i][j]=0
            else:
                rest.append(j)
        for j in rest:
            res=10**15
            for k in X:
                res=min(res,abs(li[j][0]-k))
            xx[i][j]=res
    
    for i in range(2**n):
        Y=[0]
        rest=[]
        for j in range(n):
            if i>>j&1==1:
                Y.append(li[j][1])
                yy[i][j]=0
            else:
                rest.append(j)
        for j in rest:
            res=10**15
            for k in Y:
                res=min(res,abs(li[j][1]-k))
            yy[i][j]=res

    index_list=[2**q for q in range(n)]
    klist = [10**15]*(n+1)
    klist[n]=0 
    
    for xyr2 in range(3**n):
        xyr = xyr2
        k,xopen,yopen=0,0,0
        for index in range(n):            
            num = xyr%3
            k+= (num+1)//2
            xopen += (num%2)*index_list[index]
            yopen += (num//2)*index_list[index]
            xyr//=3 

        cost = 0
        for w in range(n):
            cost += min(xx[xopen][w], yy[yopen][w])*li[w][2]

        klist[k] = min(klist[k], cost)

    for g in range(n+1):
        print(klist[g])


if __name__ == '__main__':
    main()

Fixed submission:
import sys
def input(): return sys.stdin.readline().rstrip()


def main():
    n = int(input())
    li = []
    for _ in range(n):
        xi, yi, pi = map(int, input().split())
        li.append([xi, yi, pi])
    li.sort(key=lambda x: x[2], reverse=True)
    xx = [[abs(li[j][0]) for j in range(n)] for i in range(2**n)]
    yy = [[abs(li[j][1]) for j in range(n)] for i in range(2**n)]

    for i in range(2**n):
        X = [0]
        rest = []
        for j in range(n):
            if i >> j & 1 == 1:
                X.append(li[j][0])
                xx[i][j] = 0
            else:
                rest.append(j)
        for j in rest:
            res = 10**15
            for k in X:
                res = min(res, abs(li[j][0]-k))
            xx[i][j] = res

    for i in range(2**n):
        Y = [0]
        rest = []
        for j in range(n):
            if i >> j & 1 == 1:
                Y.append(li[j][1])
                yy[i][j] = 0
            else:
                rest.append(j)
        for j in rest:
            res = 10**15
            for k in Y:
                res = min(res, abs(li[j][1]-k))
            yy[i][j] = res

    index_list = [2**q for q in range(n)]
    klist = [10**15]*(n+1)
    klist[n] = 0
    xx=tuple(xx)
    yy=tuple(yy)

    for xyr2 in range(3**(n-1)):
        xyr = xyr2
        k, xopen, yopen = 0, 0, 0
        for index in range(n-1):
            xyr, num = divmod(xyr, 3)
            k += (num+1)//2
            xopen += (num % 2)*index_list[index]
            yopen += (num//2)*index_list[index]
        for app in range(3):
            k2, xopen2, yopen2 = k, xopen, yopen
            k2 += (app+1)//2
            xopen2 += (app % 2)*index_list[n-1]
            yopen2 += (app//2)*index_list[n-1]

            cost = 0
            for w in range(n):
                cost += min(xx[xopen2][w], yy[yopen2][w])*li[w][2]

            klist[k2] = min(klist[k2], cost)

    for g in range(n+1):
        print(klist[g])


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from itertools import product
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    li = []
    for _ in range(n):
        xi, yi, pi = map(int, input().split())
        li.append([xi, yi, pi])
    xx=[[abs(li[j][0]) for j in range(n)] for i in range(2**n)]
    yy=[[abs(li[j][1]) for j in range(n)] for i in range(2**n)]
 
    for i in range(2**n):
        X=[0]
        rest=[]
        for j in range(n):
            if i>>j&1==1:
                X.append(li[j][0])
                xx[i][j]=0
            else:
                rest.append(j)
        for j in rest:
            res=10**15
            for k in X:
                res=min(res,abs(li[j][0]-k))
            xx[i][j]=res
    
    for i in range(2**n):
        Y=[0]
        rest=[]
        for j in range(n):
            if i>>j&1==1:
                Y.append(li[j][1])
                yy[i][j]=0
            else:
                rest.append(j)
        for j in rest:
            res=10**15
            for k in Y:
                res=min(res,abs(li[j][1]-k))
            yy[i][j]=res

    klist = [10**15]*(n+1)
    for xyr in list(product([0, 1, 2], repeat=n)):
        xopen = 0
        yopen = 0
        k = 0
        for index, num in enumerate(xyr):
            xopen += num*(2-num)*2**index
            yopen += (num*(num-1)*2**index)//2
            k += ((num-1)*(2-num)+2)//2
        if klist[k] == 0:
            continue
        cost = 0
        for w in range(n):
            cost += min(xx[xopen][w], yy[yopen][w])*li[w][2]

        klist[k] = min(klist[k], cost)

    for g in range(n+1):
        print(klist[g])


if __name__ == '__main__':
    main()


Fixed submission:
import sys
def input(): return sys.stdin.readline().rstrip()


def main():
    n = int(input())
    li = []
    for _ in range(n):
        xi, yi, pi = map(int, input().split())
        li.append([xi, yi, pi])
    li.sort(key=lambda x: x[2], reverse=True)
    xx = [[abs(li[j][0]) for j in range(n)] for i in range(2**n)]
    yy = [[abs(li[j][1]) for j in range(n)] for i in range(2**n)]

    for i in range(2**n):
        X = [0]
        rest = []
        for j in range(n):
            if i >> j & 1 == 1:
                X.append(li[j][0])
                xx[i][j] = 0
            else:
                rest.append(j)
        for j in rest:
            res = 10**15
            for k in X:
                res = min(res, abs(li[j][0]-k))
            xx[i][j] = res

    for i in range(2**n):
        Y = [0]
        rest = []
        for j in range(n):
            if i >> j & 1 == 1:
                Y.append(li[j][1])
                yy[i][j] = 0
            else:
                rest.append(j)
        for j in rest:
            res = 10**15
            for k in Y:
                res = min(res, abs(li[j][1]-k))
            yy[i][j] = res

    index_list = [2**q for q in range(n)]
    klist = [10**15]*(n+1)
    klist[n] = 0
    xx=tuple(xx)
    yy=tuple(yy)

    for xyr2 in range(3**(n-1)):
        xyr = xyr2
        k, xopen, yopen = 0, 0, 0
        for index in range(n-1):
            xyr, num = divmod(xyr, 3)
            k += (num+1)//2
            xopen += (num % 2)*index_list[index]
            yopen += (num//2)*index_list[index]
        for app in range(3):
            k2, xopen2, yopen2 = k, xopen, yopen
            k2 += (app+1)//2
            xopen2 += (app % 2)*index_list[n-1]
            yopen2 += (app//2)*index_list[n-1]

            cost = 0
            for w in range(n):
                cost += min(xx[xopen2][w], yy[yopen2][w])*li[w][2]

            klist[k2] = min(klist[k2], cost)

    for g in range(n+1):
        print(klist[g])


if __name__ == '__main__':
    main()