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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define PI acos(-1.0)
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1e9+100;
const ll MOD = 1e9;
const double EPS = 1e-10;
const bool debug = 0;
//------------------------------//

template <typename T>
struct SegTree {
	T init_val;
	int n;
	vector<T> dat;
	
	SegTree(int _n, T init_val) : init_val(init_val) {
		n = 1;
		while (n < _n) n *= 2;
		dat.resize(n * 2 - 1, init_val);
	}
	
	void update(int i, T x) {
		i += n - 1;
		dat[i] = max(dat[i], x);
		while (i > 0) {
			i = (i - 1) / 2;
			dat[i] = max(dat[i * 2 + 1], dat[i * 2 + 2]);
		}
	}
	
	T query(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		
		if (r <= a || b <= l) return init_val;
		if (a <= l && r <= b) return dat[k];
		return max( query(a, b, k * 2 + 1, l, (l + r) / 2), query(a, b, k * 2 + 2, (l + r) / 2, r) );
	}
};

int stx, sty, edx, edy;
int N;
int X[212345], Y[212345];
vector<int> cx, cy;

int main() {
	cin >> stx >> sty >> edx >> edy;
	cin >> N;
	REP(i, N) scanf("%d %d", X + i, Y + i);
	
	// 座標の変換 (右上に進むようにし、stからの相対座標に変換する)
	if (stx > edx) {
		REP(i, N) X[i] = -X[i];
		stx = -stx; edx = -edx;
	}
	if (sty > edy) {
		REP(i, N) Y[i] = -Y[i];
		sty = -sty; edy = -edy;
	}
	
	REP(i, N) {
		X[i] -= stx; cx.push_back(X[i]);
		Y[i] -= sty; cy.push_back(Y[i]);
	}
	edx -= stx; edy -= sty;
	
	cx.push_back(stx); cx.push_back(edx);
	cy.push_back(sty); cy.push_back(edy);
	
	sort(ALL(cx)); cx.erase(unique(ALL(cx)), cx.end());
	sort(ALL(cy)); cy.erase(unique(ALL(cy)), cy.end());
	
	REP(i, N) {
		X[i] = lower_bound(ALL(cx), X[i]) - cx.begin();
		Y[i] = lower_bound(ALL(cy), Y[i]) - cy.begin();
	}
	////
	
	vector<pii> p(N);
	REP(i, N) p[i] = pii(X[i], Y[i]);
	sort(ALL(p));
	
	SegTree<int> seg(212345, 0);
	
	int info = -1; // 0-x=0 1-y=0
	int cnt = 0;
	
	REP(i, N) {
		if (cx[p[i].fi] < 0 || cx[p[i].fi] > edx || cy[p[i].se] < 0 || cy[p[i].se] > edy) continue;
		
		seg.update(p[i].se, seg.query(0, p[i].se) + 1);
	}
	
	int ma = seg.query(0, lower_bound(ALL(cy), edy) - cy.begin() + 1);
	
	double ans = (edx + edy) * 100.0;
	ans -= ma * (20 - 5*PI);
	if (ma == min(edx, edy) + 1) ans += 5 * PI;
	
	printf("%.15lf\n", ans);
	
	return 0;
}