Problem:
Score : 900 points

Problem Statement

In the city of Nevermore, there are 10^8 streets and 10^8 avenues, both numbered from 0 to 10^8-1.
All streets run straight from west to east, and all avenues run straight from south to north.
The distance between neighboring streets and between neighboring avenues is exactly 100 meters.

Every street intersects every avenue. Every intersection can be described by pair (x, y), where x is avenue ID and y is street ID.

There are N fountains in the city, situated at intersections (X_i, Y_i).
Unlike normal intersections, there's a circle with radius 10 meters centered at the intersection, and there are no road parts inside this circle.

The picture below shows an example of how a part of the city with roads and fountains may look like.

City governors don't like encountering more than one fountain while moving along the same road.
Therefore, every street contains at most one fountain on it, as well as every avenue.

Citizens can move along streets, avenues and fountain perimeters.
What is the shortest distance one needs to cover in order to get from intersection (x_1, y_1) to intersection (x_2, y_2)?

Constraints

0 \leq x_1, y_1, x_2, y_2 < 10^8

1 \leq N \leq 200,000

0 \leq X_i, Y_i < 10^8

X_i \neq X_j for i \neq j

Y_i \neq Y_j for i \neq j

Intersections (x_1, y_1) and (x_2, y_2) are different and don't contain fountains.

All input values are integers.

Input

Input is given from Standard Input in the following format:

x_1 y_1 x_2 y_2
N
X_1 Y_1
X_2 Y_2
:
X_N Y_N

Output

Print the shortest possible distance one needs to cover in order to get from intersection (x_1, y_1) to intersection (x_2, y_2), in meters.
Your answer will be considered correct if its absolute or relative error doesn't exceed 10^{-11}.

Sample Input 1

1 1 6 5
3
3 2
5 3
2 4

Sample Output 1

891.415926535897938

One possible shortest path is shown on the picture below. The path starts at the blue point, finishes at the purple point and follows along the red line.

Sample Input 2

3 5 6 4
3
3 2
5 3
2 4

Sample Output 2

400.000000000000000

Sample Input 3

4 2 2 2
3
3 2
5 3
2 4

Sample Output 3

211.415926535897938

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

#if MYDEBUG
#include "lib/cp_debug.h"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;
struct RangeMin{
    using T = long double;
    T operator()(const T &a, const T &b){return min(a,b);}
    static constexpr T id(){return T(LINF);};
};

struct RangeSetmin{
    using T = long double;
    T operator()(const T &a, const T &b){return min(a,b);};
    static constexpr T id(){return T(LINF);};
};

struct Min_Setmin{
    using V = RangeMin;
    using A = RangeSetmin;
    V::T operator()(const V::T &a, const A::T &b, const int &h){return min(a,b);};
};

template<typename M>
struct LazySegmentTree{
    using Val = typename M::V::T;
    using Del = typename M::A::T;
    typename M::V calc;
    typename M::A composite;
    M act;
    vector<Val> val;
    vector<Del> delay;

    int n,height;
    explicit LazySegmentTree(int size) : n(1),height(0){
        while(n<size){n<<=1;++height;}
        val=vector<Val>(n<<1,calc.id());
        delay=vector<Del>(n<<1,composite.id());
    }
    explicit LazySegmentTree(vector<Val> &v):n(1),height(0){
        while(n < v.size()) {n <<=1;++height;}
        val = vector<Val> (n<<1,calc.id());
        delay=vector<Del>(n<<1,composite.id());
        copy(v.begin(),v.end(),val.begin()+n);
        for(int i=n-1; i>0; --i){val[i]=calc(val[i*2],val[i*2+1]);}
    }
    void propagate(int k,int h){
        val[k]=act(val[k],delay[k],h);
        if(h>0){
            delay[2*k]=composite(delay[2*k], delay[k]);
            delay[2*k+1]=composite(delay[2*k+1], delay[k]);
        }
        delay[k]=composite.id();
    }
    inline void update(int l, int r, Del v){update(l,r,v,1,0,n,height);}
    void update(int l, int r, Del v, int k, int a, int b, int h){
        if(l<=a && b<=r){
            delay[k]=composite(delay[k],v);
            propagate(k,h);
            return;
        }
        propagate(k,h);
        if(b<=l || r<=a){return ;}//
        update(l,r,v,2*k,a,(a+b)/2,h-1);
        update(l,r,v,2*k+1,(a+b)/2,b,h-1);
        val[k]=calc(val[2*k],val[2*k+1]);
    }
    inline Val query(int l,int r){return query(l,r,1,0,n,height);}
    Val query(int l, int r, int k, int a, int b, int h){
        if(b<=l || r<=a){return calc.id();}//
        propagate(k,h);
        if(l<=a && b<=r){
            return val[k];
        }
        Val vall=query(l,r,2*k,a,(a+b)/2,h-1);
        Val valr=query(l,r,2*k+1,(a+b)/2,b,h-1);
        return calc(vall,valr);
    }
};

struct Problem{
    LL a,b,c,d,n;
    vector<pair<LL,LL>> xy,yx;
    Problem(LL a, LL b, LL c, LL d,LL n):a(a),b(b),c(c),d(d),n(n){};
    void solve(){
        long double pi=acos(-1.0);
        long double sub=pi*5.0-20.0;
        long double add=pi*10.0-20.0;
        for(int i=0; i<n; ++i){
            LL tmpx,tmpy;
            cin >> tmpx >> tmpy;
            xy.emplace_back(tmpx,tmpy);
            yx.emplace_back(tmpy,tmpx);
        }
        if(a==c){
            auto it = lower_bound(xy.begin(),xy.end(),make_pair(a,0ll));
            if(it<xy.end() and it->first == a and (b-it->second)*(d-it->second)<0){
                cout << 100.0*abs(b-d)-20.0+10.0*pi <<"\n";
            }
            else cout << 100.0*abs(b-d)<<"\n";
            return;
        }
        if(b==d){
            auto it = lower_bound(yx.begin(),yx.end(),make_pair(b,0ll));
            if(it< yx.end() and it->first == b and (a-it->second)*(c-it->second)<0){
                cout << 100.0*abs(a-c)-20.0+10.0*pi <<"\n";
            }
            else cout << 100.0*abs(a-c)<<"\n";
            return;
        }
        if(a>c){swap(a,c);swap(b,d);}
        if(b>d){
            b=1e8-1-b;
            d=1e8-1-d;
            for(int i=0; i<n; ++i){
                xy[i].second=1e8-1-xy[i].second;
                yx[i].first=1e8-1-yx[i].first;
            }
        }
        //a<c,b<d
        sort(xy.begin(),xy.end());
        sort(yx.begin(),yx.end());
        auto it = lower_bound(yx.begin(),yx.end(),make_pair(b,a));
        vector<LL> tmp;
        tmp.push_back(b);
        while(it<yx.end() and it->first<d){
            if(a<=it->second and it->second<=c){
                tmp.push_back(it->first);
                tmp.push_back(it->first+1);
            }
            it++;
        }
        tmp.push_back(d);
        sort(tmp.begin(),tmp.end());
        tmp.erase(unique(tmp.begin(),tmp.end()),tmp.end());
        LazySegmentTree<Min_Setmin> seg(tmp.size());
        for(int i=0; i<(int)tmp.size(); ++i){
            seg.update(i,i+1,0);
        }
        auto it2=lower_bound(xy.begin(),xy.end(),make_pair(a,b));
        vector<LL> used(1,-2);
        if(it2<xy.end() and it2->first== a and it2->second<=d){
            LL ty=it2->second;
            LL pos=lower_bound(tmp.begin(),tmp.end(),ty)-tmp.begin();
            seg.update(pos,pos+1,sub);
            seg.update(pos+1,(int)tmp.size(),add);
            it2++;
            used.push_back(a);
        }
        while(it2< xy.end() and it2->first<=c){
            LL ty=it2->second;
            LL pos=lower_bound(tmp.begin(),tmp.end(),ty)-tmp.begin();
            if(ty<b or ty>d){it2++; continue;}
            if(it2->first-used.back()>1){
                auto dd=seg.query(0,pos+1)+sub;
                seg.update(pos+1,(int)tmp.size(),dd);
                auto dist=seg.query(0,pos)+sub;
                dist=min(dist,seg.query(pos,pos+1)+add);
                seg.update(pos,pos+1,dist);
            }else{
                auto dist=seg.query(0,pos);
                auto dh = seg.query(pos,pos+1);
                auto dd = min(dist+add,dh+sub);
                seg.update(pos+1,(int)tmp.size(),dd);
                dist=min(dist+sub,dh+add);
                seg.update(pos,pos+1,dist);
            }
            used.push_back(it2->first);
            it2++;
        }
        it2--;
        long double ans;
        if(it2->first==c){
            ans=seg.query((int)tmp.size()-1,(int)tmp.size());
        }else{
            ans=seg.query(0,(int)tmp.size());
        }
        cout << 100.0*(abs(d-b)+abs(c-a))+ans<<"\n";
    }
};

int main(){
    cin.tie(0);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(20);
    ios_base::sync_with_stdio(false);
    long long a,b,c,d,n=0;
    cin >> a >>b >> c >> d >> n;
    Problem p(a,b,c,d,n);
    p.solve();
    return 0;
}