#include using namespace std; typedef long long ll; #define fst first #define sec second ll dist[1024][1024]; ll lr[1024][1024],ud[1024][1024]; int main(){ ll w,h,n; cin>>w>>h>>n; for(ll i=0;i>m; vector> b; for(ll j=0;j>num; b.push_back(make_pair(num/w,num%w));//y,x } for(ll j=1;j<=m;j++){ if(b[j].fst==b[j-1].fst){//横方向の移動 ll sml=min(b[j].sec,b[j-1].sec); ll big=max(b[j].sec,b[j-1].sec); lr[b[j].fst][sml]++; lr[b[j].fst][big]--; } else{ ll sml=min(b[j].fst,b[j-1].fst); ll big=max(b[j].fst,b[j-1].fst); ud[sml][b[j].sec]++; ud[big][b[j].sec]--; } } } for(ll i=0;i> pq; pq.push(make_tuple(-0,0,0)); while(!pq.empty()){ auto it=pq.top(); pq.pop(); ll cost=-get<0>(it); ll y=get<1>(it),x=get<2>(it); if(cost>dist[y][x]) continue; if(y==h-1&&x==w-1){ cout<cost){ dist[y][x+1]=cost; pq.push(make_tuple(-cost,y,x+1)); } if(x>0&&lr[y][x-1]&&dist[y][x-1]>cost){ dist[y][x+1]=cost; pq.push(make_tuple(-cost,y,x-1)); } if(ud[y][x]&&dist[y+1][x]>cost){ dist[y+1][x]=cost; pq.push(make_tuple(-cost,y+1,x)); } if(y>0&&ud[y-1][x]&&dist[y-1][x]>cost){ dist[y-1][x]=cost; pq.push(make_tuple(-cost,y-1,x)); } } cout<<"Odekakedekinai.."<