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 <bits/stdc++.h>
using namespace std;
#define LL long long
#define x1 ahdhasd
#define x2 isdhfisdf
#define y1 osafoijsdgd
#define y2 sjbfdd
#define MAX 100000000

int x1, y1, x2, y2;
int n;
int ax[200005], ay[200005];
double pi;

double ct(int asli, int num){
	double res = (double)asli*100.0;
	res -= (double)num*20;
	res += (double)num*pi*5;
	return res;
}

int bit[400005];
int dp[400005];

void update(int x, int v){
	for(++x; x < 400005; x += x&-x) bit[x] = max(bit[x], v);
}

int query(int x){
	int res = 0;
	for(++x; x > 0; x -= x&-x) res = max(res,bit[x]);
		return res;
}

int get(vector<int> &arr){
	vector<int> v = arr;
	sort(v.begin(),v.end());
	int a = v.size();
	v.erase(unique(v.begin(),v.end()),v.end());
	int b = v.size();
	assert(a==b);
	for(int i = 0; i < arr.size(); i++ ){
		arr[i] = lower_bound(v.begin(),v.end(),arr[i])-v.begin();
	}
	int res = 0;
	for(int i = 0; i < arr.size(); i++ ){
		dp[i] = query(arr[i])+1;
		res = max(res, dp[i]);
		update(arr[i],dp[i]);
	}
	return res;
}

int main(){
	pi = acos((double)-1.0);

	scanf("%d%d%d%d%d",&x1,&y1,&x2,&y2,&n);
	for(int i = 0; i < n; i++ ){
		scanf("%d%d",&ax[i],&ay[i]);
	}

	if(x1 > x2){
		// mirror h
		x1 = MAX-x1;
		x2 = MAX-x2;
		for(int i = 0; i < n; i++ ){
			ax[i] = MAX-ax[i];
		}
	}
	if(y1 > y2){
		// mirror v
		y1 = MAX-y1;
		y2 = MAX-y2;
		for(int i = 0; i < n; i++ ){
			ay[i] = MAX-ay[i];
		}
	}
	assert(x1<=x2 && y1<=y2);
	vector<pair<int,int> > v;
	for(int i = 0; i < n; i++ ){
		if(ax[i]<x1||ax[i]>x2||ay[i]<y1||ay[i]>y2) continue;
		v.emplace_back(ax[i],ay[i]);
	}

	if(x1==x2){
		// vertikal
		if(!v.empty()){
			double res = y2-y1;
			res *= 100.0;
			res -= 20.0;
			res += pi*10;
			printf("%.20lf\n",res);
		}
		else{
			printf("%.20lf\n",(double)((double)y2-y1)*100.0);

		}
		return 0;
	}

	if(y1==y2){
		// horizontal
		if(!v.empty()){
			double res = x2-x1;
			res *= 100.0;
			res -= 20.0;
			res += pi*10;
			printf("%.20lf\n",res);
		}
		else{
			printf("%.20lf\n",(double)((double)x2-x1)*100.0);
		}
		return 0;
	}


	sort(v.begin(),v.end());
	vector<int> arr;
	for(auto i : v){
		arr.push_back(i.second);
	}
	int aa = get(arr);
	if(aa==x2-x1+1 || aa==y2-y1+1){
		aa--;
		double aaa = ct(y2-y1 + x2-x1, aa);
		aaa -= 20.0;
		aaa += pi*10;
		printf("%.20lf\n",aaa);
		return 0;
	}
	printf("%.20lf\n",ct(y2-y1 + x2-x1, aa));

	return 0;
}