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 <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <assert.h>
#include <math.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp make_pair
#define pb push_back
#define mes(a,b) memset(a,b,sizeof(a))
#define mes0(a) memset(a,0,sizeof(a))
#define lson l,mid,pos<<1
#define rson mid+1,r,pos<<1|1
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define fi first
#define se second
#define sss(a) a::iterator
#define all(a) a.begin(),a.end()

using namespace std;

typedef double DB;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<long long ,int> pli;
typedef pair<int,long long > pil;
typedef pair<string,int> psi;
typedef pair<long long ,long long > pll;

const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const double pi = acos(-1.0);
const int maxn = 100000+10;
const int mod = 1e9+7;
int tree[212345*4];
int y[223456];
pair<int,int> que[223456];
void push_up(int pos)
{
    tree[pos]=max(tree[pos<<1],tree[pos<<1|1]);
}
void upd(int l,int r,int pos,int x,int v)
{
    if (l==r){
        tree[pos]=v;
        return ;
    }
    int mid=(l+r)>>1;
    if (mid>=x)upd(lson,x,v);
    else upd(rson,x,v);
    push_up(pos);
}
int query(int l,int r,int pos,int l1,int r1)
{
    if (l1<=l&&r1>=r){
        return tree[pos];
    }
    int mid=(l+r)>>1;
    int ret=0;
    if (mid>=l1)ret=query(lson,l1,r1);
    if (mid+1<=r1)ret=max(ret,query(rson,l1,r1));
    return ret;
}
int main()
{

    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    if (x1==x2&&y1>y2)swap(y1,y2);
    if (x1>x2)swap(x1,x2),swap(y1,y2);
    int n;
    scanf("%d",&n);
    int tot=2;
    if (y1<=y2)
    y[0]=y1,y[1]=y2;
    else
    y[0]=y1-y2,y[1]=0;
    int xx,yy;
    for (int i=0;i<n;i++){
        scanf("%d%d",&xx,&yy);
        if (xx>=min(x1,x2)&&xx<=max(x1,x2)&&yy>=min(y1,y2)&&yy<=max(y1,y2)){
            if (y1<=y2){
                que[tot-2].fi=xx;
                que[tot-2].se=yy;
                y[tot++]=yy;
            }else {
                que[tot-2].fi=xx;
                que[tot-2].se=y1-yy;
                y[tot++]=y1-yy;
            }
        }
    }
    sort(y,y+tot);
    sort(que,que+tot-2);
    for (int i=0;i<tot-2;i++){
        int p=upper_bound(y,y+tot,que[i].se)-y;
        upd(1,tot,1,p,query(1,tot,1,1,p)+1);
    }
    int t=tree[1];
    int xxx=min(abs(y1-y2),abs(x1-x2));
    double ans=(abs(x1-x2))*100+abs(y1-y2)*100;
    if (t>min(abs(y1-y2),abs(x1-x2)))ans+=xxx*pi*10/2-xxx*20+(t-xxx)*pi*10-(t-xxx)*20;
    else ans+=t*pi*10/2-t*20;
    printf("%.15f",ans);
    return 0;
}