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)

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef long long int64;
typedef unsigned long long uint64;
#define two(X) (1<<(X))
#define twoL(X) (((int64)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)
const double pi=acos(-1.0);
const double eps=1e-11;
template<class T> inline void ckmin(T &a,T b){if(b<a) a=b;}
template<class T> inline void ckmax(T &a,T b){if(b>a) a=b;}
template<class T> inline T sqr(T x){return x*x;}
typedef pair<int,int> ipair;
#define SIZE(A) ((int)A.size())
#define LENGTH(A) ((int)A.length())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,a) for(int i=0;i<(a);++i)
#define ALL(A) A.begin(),A.end()

const int maxn=1000000+16;

struct Point
{
	int x,y;
	void readin()
	{
		cin>>x>>y;
	}
};

int n;
Point p[maxn];
Point src,dst;
int m;

double cost=10.0*pi-10.0*2.0;
double save=10.0*2.0-10.0*pi/2.0;

double w1[maxn],w2[maxn];
int my[maxn];

void update(double w[],int p,double d)
{
	for (;p<=m;p=(p|(p-1))+1) ckmin(w[p],d);
}
double getw(double w[],int p)
{
	double ret=1e100;
	for (;p>0;p&=(p-1)) ckmin(ret,w[p]);
	return ret;
}
double solve()
{
	m=dst.y;
	if (n==0) return 0.0;
	REP(i,m+1) w1[i]=w2[i]=1e100;
	sort(p,p+n,[](const Point& a,const Point& b) { return a.x<b.x; });
	double ret=1e100;
	my[n]=-1;
	for (int i=n-1;i>=0;i--) my[i]=max(my[i+1],p[i].y);
	int cl=0;
	vector<pair<int,pair<int,double>>> q1;
	int gy=1000000000;
	REP(i,n)
	{
		int key=p[i].y;
		ckmin(gy,p[i].y);
		double t1=1e100;
		double t2=1e100;
		if (gy==p[i].y)
		{
			t1=((p[i].y==src.y)?cost:-save);
			t2=((p[i].x==src.x)?cost:-save);
		}
		else
		{
			for (;cl<SIZE(q1) && q1[cl].first<=p[i].x-2;++cl) update(w1,q1[cl].second.first,q1[cl].second.second);
			double t3=min(getw(w1,key),getw(w2,key-1));
			double t4=min(getw(w1,key-1),getw(w2,key-2));
			t1=min(t4-save,t3+cost);
			t2=min(t3-save,t4+cost);
		}
		q1.push_back(MP(p[i].x,MP(key,t1)));
		update(w2,key,t2);
		if (my[i]==p[i].y)
		{
			if (p[i].x<dst.x) ckmin(ret,t1);
			if (p[i].y<dst.y) ckmin(ret,t2);
		}
	}
	return ret;
}

void preprocess()
{
	set<int64> w;
	w.insert(src.x);
	w.insert(dst.x);
	REP(i,n) w.insert(p[i].x);
	vector<int64> w1(ALL(w));
	int cnt=0;
	map<int64,int64> g;
	for (int i=0;i<SIZE(w1);i++) 
	{
		if (i>0 && w1[i]-1>w1[i-1]) g[w1[i]-1]=(++cnt);
		g[w1[i]]=(++cnt);
	}
	src.x=g[src.x];
	dst.x=g[dst.x];
	REP(i,n) p[i].x=g[p[i].x];
}

int main()
{
#ifdef _MSC_VER
	freopen("input.txt","r",stdin);
#endif
	std::ios::sync_with_stdio(false);
	src.readin();
	dst.readin();
	cin>>n;
	REP(i,n) p[i].readin();
	if (src.x>dst.x)
	{
		src.x=-src.x;
		dst.x=-dst.x;
		REP(i,n) p[i].x=-p[i].x;
	}
	if (src.y>dst.y)
	{
		src.y=-src.y;
		dst.y=-dst.y;
		REP(i,n) p[i].y=-p[i].y;
	}
	double edst=fabs(src.x-dst.x)+fabs(src.y-dst.y);
	int old_n=n;
	n=0;
	REP(i,old_n) 
		if (p[i].x>=src.x && p[i].x<=dst.x && p[i].y>=src.y && p[i].y<=dst.y)
			p[n++]=p[i];

	preprocess();
	REP(i,n) swap(p[i].x,p[i].y);
	swap(src.x,src.y);
	swap(dst.x,dst.y);
	preprocess();
	REP(i,n) swap(p[i].x,p[i].y);
	swap(src.x,src.y);
	swap(dst.x,dst.y);

	double ret=solve();
	printf("%.18lf\n",ret+edst*100.0);
	return 0;
}