#include using namespace std; using ll = long long; template using pq = priority_queue, greater>; vector dijkstra(vector>> &E, ll start){ ll N = E.size(); ll from, alt, d; pq> que; vector dist(N, 1e18); vector vst(N); dist[start] = 0; que.push({0, start}); while(!que.empty()){ tie(d, from) = que.top(); que.pop(); if (vst[from]) continue; vst[from] = 1; for (auto [to, C] : E[from]){ alt = d + C; if (alt < dist[to]){ dist[to] = alt; que.push({dist[to], to}); } } } return dist; } int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); ll H, K, W, N, cnt=0; cin >> H >> W >> N; vector a(N), b(N), c(N), d(N), h(N*2+2), w(N*2+2); for (int i=0; i> a[i] >> b[i] >> c[i] >> d[i]; for (int i=0; i>> E(N*2+2); for (int i=0; i<2*N+2; i++){ for (int j=0; j<2*N+2; j++){ if (i==j) continue; E[i].push_back({j, abs(h[i]-h[j])+abs(w[i]-w[j])}); } } for (int i=0; i dist = dijkstra(E, 0); cout << dist[2*N+1] << endl; return 0; }