#include #include #include using namespace std; using ll = long long; void chmin(double& a, double b){a=min(a, b);} int main(void){ ll x0, y0; cin >> x0 >> y0; int n; cin >> n; int mx=(1<<(n+1)); vector x(n+1), y(n+1); vector w(n+1); x[0]=x0, y[0]=y0; for(int i=1; i<=n; i++) cin >> x[i] >> y[i] >> w[i]; vector dp(mx, vector(n+1, 1e18)); dp[1][0]=0; auto dist=[&](int s, int t){ ll ans=abs(x[s]-x[t])+abs(y[s]-y[t]); return ans; }; for(int i=1; i>j&1)) sw+=w[j]; for(int st=0; st<=n; st++)if(i>>st&1){ for(int to=0; to<=n; to++)if(!(i>>to&1)){ chmin(dp[i|(1<