Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n=int(input())
    xyp=[list(map(int,input().split()))for _ in range(n)]
    ans=[10**20]*(n+1)
    ans[0]=sum(min(abs(x),abs(y))*p for x,y,p in xyp)
    ans[-1]=0
    xx=[[]]
    yy=[[]]
    for bitt in range(1,1<<n):
        xs=[(10**20,0)]
        ys=[(10**20,0)]
        for i in range(n):
            if bitt&(1<<i):
                xs.append((xyp[i][0],i))
                ys.append((xyp[i][1],i))
        xs.sort()
        ys.sort()
        xx.append(xs)
        yy.append(ys)
    for trit in range(1,3**n):
        z=0
        xbit=0
        ybit=0
        for i in range(n):
            if trit%3==0:z+=1
            if trit%3==1:xbit+=1<<i
            if trit%3==2:ybit+=1<<i
            trit//=3
        if z==0:continue
        anss=[min(abs(x),abs(y))*p for x,y,p in xyp]
        if xbit:
            xs=xx[xbit]
            i=0
            notx=[1]*n
            for x,j in xx[-xbit-1][:-1]:
                while abs(xs[i][0]-x)>abs(xs[i+1][0]-x):i+=1
                anss[j]=min(anss[j],abs(xs[i][0]-x)*xyp[j][2])
                notx[j]=0
            for j in range(n):
                if notx[j]:anss[j]=0
        if ybit:
            ys=yy[ybit]
            i=0
            noty=[1]*n
            for y,j in yy[-ybit-1][:-1]:
                while abs(ys[i][0]-y)>abs(ys[i+1][0]-y):i+=1
                anss[j]=min(anss[j],abs(ys[i][0]-y)*xyp[j][2])
                noty[j]=0
            for j in range(n):
                if noty[j]:anss[j]=0
        ans[n-z]=min(ans[n-z],sum(anss))
    print(*ans)

if __name__ == "__main__":
    main()

Fixed submission:
n=int(input())
xyp=[list(map(int,input().split())) for i in range(n)]
cost=[10**20]*(1<<n)
cost[0]=0
for bitt in range(1,1<<n):
  xx=[]
  yy=[]
  pp=[]
  m=0
  for i in range(n):
    x,y,p=xyp[i]
    if (1<<i)&bitt:
      xx.append(x)
      yy.append(y)
      pp.append(p)
      m+=1
  for i in range(m):
    sx=xx[i]
    anss=0
    for x,y,p in zip(xx,yy,pp):
      anss+=min(abs(y),abs(x),abs(sx-x))*p
    cost[bitt]=min(cost[bitt],anss)
  for j in range(m):
    sy=yy[j]
    anss=0
    for x,y,p in zip(xx,yy,pp):
      anss+=min(abs(y),abs(x),abs(sy-y))*p
    cost[bitt]=min(cost[bitt],anss)
dp=[sum(min(abs(xyp[i][0]),abs(xyp[i][1]))*xyp[i][2] for i in range(n) if (1<<i)&j) for j in range(1<<n)]
print(dp[-1])
for j in range(n):
  for i in range((1<<n)-1,0,-1):
    x=i
    while x>=0:
      x&=i
      dp[i]=min(dp[i],dp[i-x]+cost[x])
      x-=1
  print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
xyp=[list(map(int,input().split()))for _ in range(n)]
ans=[10**20]*(n+1)
ans[0]=sum(min(abs(x),abs(y))*p for x,y,p in xyp)
ans[-1]=0
xx=[[]]
yy=[[]]
for bitt in range(1,1<<n):
    xs=[(10**20,0)]
    ys=[(10**20,0)]
    for i in range(n):
        if bitt&(1<<i):
            xs.append((xyp[i][0],i))
            ys.append((xyp[i][1],i))
    xs.sort()
    ys.sort()
    xx.append(xs)
    yy.append(ys)
for trit in range(3**n):
    z=0
    xbit=0
    ybit=0
    for i in range(n):
        if trit%3==0:z+=1
        if trit%3==1:xbit+=1<<i
        if trit%3==2:ybit+=1<<i
        trit//=3
    anss=[min(abs(x),abs(y))*p for x,y,p in xyp]
    if xbit:
        xs=xx[xbit]
        i=0
        notx=[1]*n
        for x,j in xx[-xbit-1][:-1]:
            while abs(xs[i][0]-x)>abs(xs[i+1][0]-x):i+=1
            anss[j]=min(anss[j],abs(xs[i][0]-x)*xyp[j][2])
            notx[j]=0
        for j in range(n):
            if notx[j]:anss[j]=0
    if ybit:
        ys=yy[ybit]
        i=0
        noty=[1]*n
        for y,j in yy[-ybit-1][:-1]:
            while abs(ys[i][0]-y)>abs(ys[i+1][0]-y):i+=1
            anss[j]=min(anss[j],abs(ys[i][0]-y)*xyp[j][2])
            noty[j]=0
        for j in range(n):
            if noty[j]:anss[j]=0
    ans[n-z]=min(ans[n-z],sum(anss))
print(*ans)


Fixed submission:
n=int(input())
xyp=[list(map(int,input().split())) for i in range(n)]
cost=[10**20]*(1<<n)
cost[0]=0
for bitt in range(1,1<<n):
  xx=[]
  yy=[]
  pp=[]
  m=0
  for i in range(n):
    x,y,p=xyp[i]
    if (1<<i)&bitt:
      xx.append(x)
      yy.append(y)
      pp.append(p)
      m+=1
  for i in range(m):
    sx=xx[i]
    anss=0
    for x,y,p in zip(xx,yy,pp):
      anss+=min(abs(y),abs(x),abs(sx-x))*p
    cost[bitt]=min(cost[bitt],anss)
  for j in range(m):
    sy=yy[j]
    anss=0
    for x,y,p in zip(xx,yy,pp):
      anss+=min(abs(y),abs(x),abs(sy-y))*p
    cost[bitt]=min(cost[bitt],anss)
dp=[sum(min(abs(xyp[i][0]),abs(xyp[i][1]))*xyp[i][2] for i in range(n) if (1<<i)&j) for j in range(1<<n)]
print(dp[-1])
for j in range(n):
  for i in range((1<<n)-1,0,-1):
    x=i
    while x>=0:
      x&=i
      dp[i]=min(dp[i],dp[i-x]+cost[x])
      x-=1
  print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
xyp=[list(map(int,input().split()))for _ in range(n)]
ans=[10**20]*(n+1)
ans[0]=sum(min(abs(x),abs(y))*p for x,y,p in xyp)
ans[-1]=0
xx=[[]]
yy=[[]]
for bitt in range(1,1<<n):
    xs=[(10**20,0)]
    ys=[(10**20,0)]
    for i in range(n):
        if bitt&(1<<i):
            xs.append((xyp[i][0],i))
            ys.append((xyp[i][1],i))
    xs.sort()
    ys.sort()
    xx.append(xs)
    yy.append(ys)
for trit in range(3**n):
    z=0
    xbit=0
    ybit=0
    for i in range(n):
        if trit%3==0:z+=1
        if trit%3==1:xbit+=1<<i
        if trit%3==2:ybit+=1<<i
        trit//=3
    anss=[min(abs(x),abs(y))*p for x,y,p in xyp]
    if xbit:
        xs=xx[xbit]
        i=0
        notx=[1]*n
        for x,j in xx[-xbit-1][:-1]:
            while abs(xs[i][0]-x)>abs(xs[i+1][0]-x):i+=1
            anss[j]=min(anss[j],abs(xs[i][0]-x)*xyp[j][2])
            notx[j]=0
        for j in range(n):
            if notx[j]:anss[j]=0
    if ybit:
        ys=yy[ybit]
        i=0
        noty=[1]*n
        for y,j in yy[-ybit-1][:-1]:
            while abs(ys[i][0]-y)>abs(ys[i+1][0]-y):i+=1
            anss[j]=min(anss[j],abs(ys[i][0]-y)*xyp[j][2])
            noty[j]=0
        for j in range(n):
            if noty[j]:anss[j]=0
    ans[n-z]=min(ans[n-z],sum(anss))
print(*ans)


Fixed submission:
n=int(input())
xyp=[list(map(int,input().split())) for i in range(n)]
cost=[10**20]*(1<<n)
cost[0]=0
for bitt in range(1,1<<n):
  xx=[]
  yy=[]
  pp=[]
  m=0
  for i in range(n):
    x,y,p=xyp[i]
    if (1<<i)&bitt:
      xx.append(x)
      yy.append(y)
      pp.append(p)
      m+=1
  for i in range(m):
    sx=xx[i]
    anss=0
    for x,y,p in zip(xx,yy,pp):
      anss+=min(abs(y),abs(x),abs(sx-x))*p
    cost[bitt]=min(cost[bitt],anss)
  for j in range(m):
    sy=yy[j]
    anss=0
    for x,y,p in zip(xx,yy,pp):
      anss+=min(abs(y),abs(x),abs(sy-y))*p
    cost[bitt]=min(cost[bitt],anss)
dp=[sum(min(abs(xyp[i][0]),abs(xyp[i][1]))*xyp[i][2] for i in range(n) if (1<<i)&j) for j in range(1<<n)]
print(dp[-1])
for j in range(n):
  for i in range((1<<n)-1,0,-1):
    x=i
    while x>=0:
      x&=i
      dp[i]=min(dp[i],dp[i-x]+cost[x])
      x-=1
  print(dp[-1])