#include #include using namespace std; namespace my{ #define eb emplace_back #define LL(...) ll __VA_ARGS__;lin(__VA_ARGS__) #define VV(n,...) vec__VA_ARGS__;setsize({n},__VA_ARGS__);vin(__VA_ARGS__) #define FO(n) for(ll ij=n;ij-->0;) #define FOR(i,...) for(auto[i,i##stop,i##step]=range(0,__VA_ARGS__);isync_with_stdio(0);cout<r{0,0,1};ll I=0;((r[I++]=a),...);if(!s&&I==1)swap(r[0],r[1]);r[0]-=s;if(s)r[2]*=-1;return r;} constexpr ld ee=1e-12; constexpr ll dx[]{-1,0,1,0,-1,1,1,-1}; constexpr ll dy[]{0,-1,0,1,-1,-1,1,1}; constexpr char newline=10; constexpr char space=32; constexpr auto abs(auto x){return x<0?-x:x;} auto ceil(auto x,auto y){if(y<0)x=-x,y=-y;return x<=0?x/y:(x-1)/y+1;} bool amin(auto&a,const auto&b){return b>{a...});} templatestruct pair{ A a;B b; pair()=default; pair(A a,B b):a(a),b(b){} pair(const std::pair&p):a(p.first),b(p.second){} auto operator<=>(const pair&)const=default; pair operator+(const pair&p)const{return{a+p.a,b+p.b};} friend istream&operator>>(istream&i,pair&p){return i>>p.a>>p.b;} friend ostream&operator<<(ostream&o,const pair&p){return o<ostream&operator<<(ostream&o,const std::pair&p){return o<struct priority_queue:std::priority_queue,F>{ priority_queue(const initializer_list&a={}){fe(a,e)this->emplace(e);} priority_queue(const vector&a){fe(a,e)this->emplace(e);} ll size()const{return std::priority_queue,F>::size();} T pop(){T r=this->top();std::priority_queue,F>::pop();return r;} friend ostream&operator<<(ostream&o,priority_queue q){while(q.size())o<0,space);return o;} }; templateusing min_heap=priority_queue>; templateauto pack_kth(const auto&...a){return get(make_tuple(a...));} templateauto pack_slice_impl(index_sequence, const auto&...a){return array{get(forward_as_tuple(a...))...};} templateauto pack_slice(const auto&...a){return pack_slice_impl(make_index_sequence{},a...);} templateconcept vectorial=is_base_of_v,V>; templatestruct vec_attr{using core_type=T;static constexpr int rank=0;}; templatestruct vec_attr{using core_type=typename vec_attr::core_type;static constexpr int rank=vec_attr::rank+1;}; templateusing core_t=vec_attr::core_type; templateistream&operator>>(istream&i,vector&v){fe(v,e)i>>e;return i;} templateostream&operator<<(ostream&o,const vector&v){fe(v,e)o<?newline:space);return o;} templatestruct vec:vector{ using vector::vector; vec(const vector&v){vector::operator=(v);} templaterequires(sizeof...(A)>=3)vec(A...a){const ll n=sizeof...(a)-1;auto t=pack_slice(a...);ll s[n];fo(i,n)s[i]=t[i];*this=make_vec(s,pack_kth(a...));} templatestatic auto make_vec(const ll(&s)[n],T x){if constexpr(i==n-1)return vec(s[i],x);else{auto X=make_vec(s,x);return vec(s[i],X);}} vec&operator^=(const vec&u){this->insert(this->end(),u.begin(),u.end());return*this;} vec operator^(const vec&u)const{return vec{*this}^=u;} vec&operator+=(const vec&u){vec&v=*this;fo(i,v.size())v[i]+=u[i];return v;} vec&operator-=(const vec&u){vec&v=*this;fo(i,v.size())v[i]-=u[i];return v;} vec operator+(const vec&u)const{return vec{*this}+=u;} vec operator-(const vec&u)const{return vec{*this}-=u;} vec&operator++(){fe(*this,e)++e;return*this;} vec&operator--(){fe(*this,e)--e;return*this;} vec operator-()const{vec v=*this;fe(v,e)e=-e;return v;} ll size()const{return vector::size();} void emplace_front(const V&x={}){this->emplace(this->begin(),x);} auto scan(const auto&f)const{pair,bool>r{};fe(*this,e)if constexpr(!vectorial)r.b?f(r.a,e),r:r={e,1};else if(auto s=e.scan(f);s.b)r.b?f(r.a,s.a),r:r=s;return r;} auto max()const{return scan([](auto&a,const auto&b){astruct tensor_helper{using type=vec::type>;}; templatestruct tensor_helper<0,T>{using type=T;}; templateusing tensor=typename tensor_helper::type; templaterequires(sizeof...(A)>=2)vec(A...a)->vec(declval>()))>>>; vec(ll)->vec; templatevoid setsize(const ll(&l)[n],A&...a){((a=vec::make_vec(l,core_t{})),...);} templatestruct infinity{ templateconstexpr operator T()const{return numeric_limits::max()*(1-is_negative*2);} templateconstexpr operator T()const{return static_cast(*this);} templateconstexpr bool operator==(T x)const{return static_cast(*this)==x;} constexpr auto operator-()const{return infinity();} templateconstexpr operator pair()const{return pair{*this,*this};} templateconstexpr operator tuple()const{return tuple{static_cast(*this)...};} }; constexpr infinity oo; void lin(auto&...a){(cin>>...>>a);} void vin(auto&...a){fo(i,(a.size()&...))(cin>>...>>a[i]);} templatevoid pp(const auto&...a){ll n=sizeof...(a);((cout<0,c)),...);cout<auto binary_search(const auto&f,T o,T x){ if(is_floating_point_v)fo(log2((abs(o-x)/ee))+6)(f((o+x)/2)?o:x)=(o+x)/2; else while(abs(o-x)>1)(f((o+x)/2)?o:x)=(o+x)/2; return o; } auto binary_searchll(auto f,ll o,ll x){return binary_search(f,o,x);} templateauto rotate45_counter_clockwise(T x,T y){return tuple{x-y,x+y};} templateauto rotate45_counter_clockwise(const vec&x,const vec&y){ ll n=x.size(); vecu(n),v(n); fo(i,n){ u[i]=x[i]-y[i]; v[i]=x[i]+y[i]; } return tuple{u,v}; } single_testcase void solve(){ LL(N,K); LL(sx,sy,gx,gy); VV(N,x,y); x.emplace_front(sx); y.emplace_front(sy); x.eb(gx); y.eb(gy); N+=2; tie(x,y)=rotate45_counter_clockwise(x,y); pp(binary_searchll([&](ll P){ auto cost=[&](ll i,ll j){ ll dx=abs(x[i]-x[j]),dy=abs(y[i]-y[j]); return max(ceil(dx,P)-1,ceil(dy,P)-1,0); }; vec dp(N,(ll)oo); dp[0]=0; min_heap>q{{dp[0],0}}; while(q.size()){ auto[du,u]=q.pop(); if(dp[u]