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: Accepted)

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
#define y1 yyy1
#define y2 yyy2
int x1,y1,x2,y2,n;
pii ps[SZ];
ld pi=acos(-1);
int bs[SZ];
void upd(int x,int y)
{
	for(;x<=n;x+=x&-x) bs[x]=max(bs[x],y);
}
int qmax(int x)
{
	int ans=-1e9;
	for(;x>=1;x-=x&-x) ans=max(ans,bs[x]);
	return ans;
}
#define yn yyn
int ys[SZ],yn=0;
int lis[SZ];
int main()
{
	memset(bs,-127/3,sizeof bs);
	scanf("%d%d%d%d%d",&x1,&y1,&x2,&y2,&n);
	for(int i=1;i<=n;++i)
		scanf("%d%d",&ps[i].fi,&ps[i].se);
	if(x1>x2)
	{
		x1*=-1; x2*=-1;
		for(int i=1;i<=n;++i)
			ps[i].fi*=-1;
	}
	if(y1>y2)
	{
		y1*=-1; y2*=-1;
		for(int i=1;i<=n;++i)
			ps[i].se*=-1;
	}
	ps[++n]=pii(x1,y1);
	ps[++n]=pii(x2,y2);
	sort(ps+1,ps+1+n);
	for(int i=1;i<=n;++i)
		ys[++yn]=ps[i].se;
	sort(ys+1,ys+1+yn);
	int yy1=lower_bound(ys+1,ys+1+yn,y1)-ys;
	int yy2=lower_bound(ys+1,ys+1+yn,y2)-ys;
	for(int i=1;i<=n;++i)
		ps[i].se=lower_bound(ys+1,ys+1+yn,ps[i].se)-ys;
	int rr=0;
	for(int i=1;i<=n;++i)
	{
		lis[i]=qmax(ps[i].se)+1;
		if(ps[i]==pii(x1,yy1)) lis[i]=0;
		else if(ps[i]==pii(x2,yy2)) rr=lis[i]-1;
		upd(ps[i].se,lis[i]);
	}
	ld ans=(x2-x1)+(y2-y1);
	ans*=100.0;
	ans+=(pi-4)*5*rr;
	if(rr==min(x2-x1+1,y2-y1+1)&&rr)
		ans+=pi*5;
	printf("%.20lf\n",ans);
}