#include using namespace std; using Int = long long; const char newl = '\n'; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a void drop(const T &x){cout< vector read(size_t n){ vector ts(n); for(size_t i=0;i>ts[i]; return ts; } template struct Dijkstra{ struct Edge{ int to; T cost; Edge(int to,T cost):to(to),cost(cost){} bool operator<(const Edge &o)const{return cost>o.cost;} }; vector< vector > G; vector ds; vector bs; Dijkstra(int n):G(n){} void add_edge(int u,int v,T c){ G[u].emplace_back(v,c); } void build(int s){ int n=G.size(); ds.assign(n,numeric_limits::max()); bs.assign(n,-1); priority_queue pq; ds[s]=0; pq.emplace(s,ds[s]); while(!pq.empty()){ auto p=pq.top();pq.pop(); int v=p.to; if(ds[v]ds[v]+e.cost){ ds[e.to]=ds[v]+e.cost; bs[e.to]=v; pq.emplace(e.to,ds[e.to]); } } } } T operator[](int k){return ds[k];} vector restore(int to){ vector res; if(bs[to]<0) return res; while(~to) res.emplace_back(to),to=bs[to]; reverse(res.begin(),res.end()); return res; } }; //INSERT ABOVE HERE using P = pair; P pos(int x){ int r=0,c=0; while(x%2==0) r++,x/=2; while(x%5==0) c++,x/=5; return P(r,c); } int dr[]={0,0,1,-1}; int dc[]={1,-1,0,0}; int in(int r,int c){ return 0<=r and r<10 and 0<=c and c<10; } int idx(int k,int r1,int c1,int r2,int c2){ return (((k*10+r1)*10+c1)*10+r2)*10+c2; } int val(int r,int c){ int x=1; for(int i=0;i>x1>>x2; Dijkstra G(20001); int S=20000; vector ss; for(int r1=0;r1<10;r1++){ for(int c1=0;c1<10;c1++){ G.add_edge(S,idx(0,r1,c1,r1,c1),0); G.add_edge(S,idx(1,r1,c1,r1,c1),0); for(int r2=0;r2<10;r2++){ for(int c2=0;c2<10;c2++){ G.add_edge(idx(0,r1,c1,r2,c2),idx(1,r1,c1,r2,c2),1); for(int k=0;k<4;k++){ int nr=r1+dr[k],nc=c1+dc[k]; if(!in(nr,nc)) continue; G.add_edge(idx(1,nr,nc,r2,c2),idx(0,r1,c1,r2,c2),1); } for(int k=0;k<4;k++){ int nr=r2+dr[k],nc=c2+dc[k]; if(!in(nr,nc)) continue; G.add_edge(idx(1,r1,c1,r2,c2),idx(0,r1,c1,nr,nc),0); } } } } } G.build(S); while(1){ auto [r1,c1]=pos(x1); auto [r2,c2]=pos(x2); cout<>x2; if(x1==x2) return 0; } return 0; }