AtCoder Grand Contest 019 - Fountain Walk

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.

1f931bf0c98ec6f07e612b0282cdb094.png

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}.

Examples

Input

1 1 6 5
3
3 2
5 3
2 4


Output

891.415926535897938


Input

3 5 6 4
3
3 2
5 3
2 4


Output

400.000000000000000


Input

4 2 2 2
3
3 2
5 3
2 4


Output

211.415926535897938

Difficulty: UNKNOWN_DIFFICULTY

Starter code:

Solutions:
import bisect
import sys
from math import atan

def lis(L):
	if not L:
		return 0
	seq = [L[0]]
	for i in L[1:]:
		if seq[-1] < i:
			seq.append(i)
		else:
			seq[bisect.bisect_left(seq, i)] = i
	return len(seq)

def mhd(x, y):
	return abs(x) + abs(y)
(x1, y1, x2, y2) = map(int, sys.stdin.readline().split())
N = int(sys.stdin.readline())
if x1 == x2 or y1 == y2:
	if x1 == x2:
		if y1 > y2:
			(y1, y2) = (y2, y1)
		for _ in range(N):
			(X, Y) = map(int, sys.stdin.readline().split())
			if X != x1:
				continue
			elif y1 <= Y <= y2:
				print(100 * mhd(0, y1 - y2) - 20 + 40 * atan(1))
				sys.exit()
			else:
				print(100 * mhd(0, y1 - y2))
				sys.exit()
	else:
		if x1 > x2:
			(x1, x2) = (x2, x1)
		for _ in range(N):
			(X, Y) = map(int, sys.stdin.readline().split())
			if Y != y1:
				continue
			elif x1 <= X <= x2:
				print(100 * mhd(x1 - x2, 0) - 20 + 40 * atan(1))
				sys.exit()
			else:
				print(100 * mhd(x1 - x2, 0))
				sys.exit()
if x1 > x2:
	(x1, x2) = (x2, x1)
	(y1, y2) = (y2, y1)
geta = 10 ** 9 + 7
B = []
if y1 < y2:
	for _ in range(N):
		(X, Y) = map(int, sys.stdin.readline().split())
		if x1 <= X <= x2 and y1 <= Y <= y2:
			B.append(X * geta + Y)
	B.sort()
	B = [b % geta for b in B]
	lb = lis(B)
	if lb == min(abs(x1 - x2), abs(y1 - y2)) + 1:
		print(100 * mhd(x1 - x2, y1 - y2) + (lb - 1) * (20 * atan(1) - 20) + 40 * atan(1) - 20)
	else:
		print(100 * mhd(x1 - x2, y1 - y2) + lb * (20 * atan(1) - 20))
else:
	for _ in range(N):
		(X, Y) = map(int, sys.stdin.readline().split())
		if x1 <= X <= x2 and y2 <= Y <= y1:
			B.append(X * geta - Y)
	B.sort()
	B = [b % geta for b in B]
	lb = lis(B)
	if lb == min(abs(x1 - x2), abs(y1 - y2)) + 1:
		print(100 * mhd(x1 - x2, y1 - y2) + (lb - 1) * (20 * atan(1) - 20) + 40 * atan(1) - 20)
	else:
		print(100 * mhd(x1 - x2, y1 - y2) + lb * (20 * atan(1) - 20))


import sys
pi = 3.141592653589793

def input():
	return sys.stdin.buffer.readline()[:-1]

class Rmax:

	def __init__(self, size):
		self.n = 1
		while self.n < size:
			self.n *= 2
		self.node = [0] * (2 * self.n - 1)

	def Access(self, x):
		return self.node[x + self.n - 1]

	def Update(self, x, val):
		x += self.n - 1
		self.node[x] = val
		while x > 0:
			x = (x - 1) // 2
			self.node[x] = max(self.node[2 * x + 1], self.node[2 * x + 2])
		return

	def Get(self, l, r):
		(L, R) = (l + self.n, r + self.n)
		s = 0
		while L < R:
			if R & 1:
				R -= 1
				s = max(s, self.node[R - 1])
			if L & 1:
				s = max(s, self.node[L - 1])
				L += 1
			L >>= 1
			R >>= 1
		return s
(x1, y1, x2, y2) = map(int, input().split())
n = int(input())
f = [tuple(map(int, input().split())) for _ in range(n)]
if x1 == x2:
	flg = False
	for (x, y) in f:
		if x == x1 and min(y1, y2) <= y <= max(y1, y2):
			flg = True
	if flg:
		print(abs(y1 - y2) * 100 + 10 * pi - 20)
	else:
		print(abs(y1 - y2) * 100)
elif y1 == y2:
	flg = False
	for (x, y) in f:
		if y == y1 and min(x1, x2) <= x <= max(x1, x2):
			flg = True
	if flg:
		print(abs(x1 - x2) * 100 + 10 * pi - 20)
	else:
		print(abs(x1 - x2) * 100)
else:
	if x1 > x2 and y1 > y2:
		(x1, x2, y1, y2) = (x2, x1, y2, y1)
		f = [[x[0], x[1], i] for (i, x) in enumerate(f) if min(x1, x2) <= x[0] <= max(x1, x2) and min(y1, y2) <= x[1] <= max(y1, y2)]
	elif x1 > x2:
		(x1, x2) = (10 ** 8 - x1, 10 ** 8 - x2)
		f = [[10 ** 8 - x[0], x[1], i] for (i, x) in enumerate(f) if min(x1, x2) <= 10 ** 8 - x[0] <= max(x1, x2) and min(y1, y2) <= x[1] <= max(y1, y2)]
	elif y1 > y2:
		(y1, y2) = (10 ** 8 - y1, 10 ** 8 - y2)
		f = [[x[0], 10 ** 8 - x[1], i] for (i, x) in enumerate(f) if min(x1, x2) <= x[0] <= max(x1, x2) and min(y1, y2) <= 10 ** 8 - x[1] <= max(y1, y2)]
	else:
		f = [[x[0], x[1], i] for (i, x) in enumerate(f) if min(x1, x2) <= x[0] <= max(x1, x2) and min(y1, y2) <= x[1] <= max(y1, y2)]
	n = len(f)
	if n == 0:
		print((abs(x1 - x2) + abs(y1 - y2)) * 100)
		sys.exit()
	f.sort(key=lambda x: x[1])
	f = [[x[0], i] for (i, x) in enumerate(f)]
	f.sort(reverse=True)
	st = Rmax(n)
	for (x, y) in f:
		st.Update(y, st.Get(y, n) + 1)
	num = st.Get(0, n)
	ans = (abs(x1 - x2) + abs(y1 - y2)) * 100 + num * 5 * pi - num * 20
	if num == min(abs(x1 - x2), abs(y1 - y2)) + 1:
		ans += 5 * pi
	print('{0:.15f}'.format(ans))


from bisect import bisect
import math
(x1, y1, x2, y2) = map(int, input().split())
N = int(input())
xL = min(x1, x2)
xR = max(x1, x2)
yL = min(y1, y2)
yR = max(y1, y2)
xyl = []
if x1 < x2 and y1 > y2:
	direction = 'rightdown'
elif x1 > x2 and y1 < y2:
	direction = 'rightdown'
else:
	direction = 'rightup'
if direction == 'rightup':
	for _ in range(N):
		(x, y) = map(int, input().split())
		if xL <= x and x <= xR and (yL <= y) and (y <= yR):
			xyl.append((x, y - yL))
else:
	for _ in range(N):
		(x, y) = map(int, input().split())
		if xL <= x and x <= xR and (yL <= y) and (y <= yR):
			xyl.append((x, yR - y))
ind = len(xyl)
xyl.sort()
dp = [yR - yL + 1] * ind
for i in range(ind):
	(_, y) = xyl[i]
	dp[bisect(dp, y)] = y
count_ = bisect(dp, yR - yL)
diff = 5 * math.pi - 20
diff2 = 10 * math.pi - 20
if count_ == min(xR - xL, yR - yL) + 1:
	print(100 * (xR - xL + (yR - yL)) + (count_ - 1) * diff + diff2)
else:
	print(100 * (xR - xL + (yR - yL)) + count_ * diff)


def LIS(L):
	from bisect import bisect
	seq = []
	for i in L:
		pos = bisect(seq, i)
		if len(seq) <= pos:
			seq.append(i)
		else:
			seq[pos] = i
	return len(seq)
import math
(x1, y1, x2, y2) = map(int, input().split())
N = int(input())
W = abs(x2 - x1)
H = abs(y2 - y1)
xsgn = 2 * (x2 > x1) - 1
ysgn = 2 * (y2 > y1) - 1
XY = []
for i in range(N):
	(x, y) = map(int, input().split())
	if (x - x1) * (x - x2) <= 0 and (y - y1) * (y - y2) <= 0:
		XY += [[xsgn * (x - x1), ysgn * (y - y1)]]
short = 20 - 5 * math.pi
long = 10 * math.pi - 20
straight = 100 * (W + H)
XY.sort()
Y = [y for (x, y) in XY]
fountain = LIS(Y)
if fountain < min(W, H) + 1:
	print(straight - short * fountain)
else:
	print(straight - short * (fountain - 1) + long)


from math import pi
from bisect import bisect_left as bl

def LIS(p):
	route = []
	for y in p:
		pos = bl(route, y)
		if len(route) <= pos:
			route.append(y)
		else:
			route[pos] = y
	return len(route)

def main():
	(x1, y1, x2, y2) = map(int, input().split())
	xfilp = 1
	yflip = 1
	if x1 > x2:
		xfilp = -1
		(x1, x2) = (x2, x1)
	if y1 > y2:
		yflip = -1
		(y1, y2) = (y2, y1)
	n = int(input())
	p = []
	for i in range(n):
		(x, y) = map(int, input().split())
		if x1 <= x <= x2 and y1 <= y <= y2:
			p.append((x * xfilp, y * yflip))
	p = [y for (x, y) in sorted(p, key=lambda t: t[0])]
	foun = LIS(p)
	ans = 100 * (x2 - x1 + y2 - y1) - (20 - pi * 5) * foun
	if foun == min(x2 - x1 + 1, y2 - y1 + 1):
		ans += pi * 5
	print(ans)
main()


def lis(A: list):
	from bisect import bisect_left
	L = [A[0]]
	for a in A[1:]:
		if a > L[-1]:
			L.append(a)
		else:
			L[bisect_left(L, a)] = a
	return len(L)
from math import pi
from operator import itemgetter
(x1, y1, x2, y2) = map(int, input().split())
if x1 > x2:
	(x1, x2) = (x2, x1)
	(y1, y2) = (y2, y1)
(xmin, xmax) = sorted([x1, x2])
(ymin, ymax) = sorted([y1, y2])
N = int(input())
XY = []
for _ in range(N):
	(X, Y) = map(int, input().split())
	if xmin <= X <= xmax and ymin <= Y <= ymax:
		XY.append([X, Y])
if len(XY) == 0:
	print(100 * (xmax - xmin + ymax - ymin))
else:
	XY.sort()
	Y = list(map(itemgetter(1), XY))
	if y1 > y2:
		Y = Y[::-1]
	lis_ = lis(Y)
	if lis_ == ymax - ymin + 1 or lis_ == xmax - xmin + 1:
		lis_ -= 1
		print(100 * (xmax - xmin + ymax - ymin) + (5 * pi - 20) * lis_ + (10 * pi - 20))
	else:
		print(100 * (xmax - xmin + ymax - ymin) + (5 * pi - 20) * lis_)


import sys
input = sys.stdin.readline
from bisect import bisect_left
from math import pi
(sx, sy, gx, gy) = map(int, input().split())
N = int(input())
XY = [tuple((int(x) for x in input().split())) for _ in range(N)]
if sx > gx:
	(sx, gx) = (gx, sx)
	(sy, gy) = (gy, sy)
gx -= sx
gy -= sy
XY = [(x - sx, y - sy) for (x, y) in XY if 0 <= x - sx <= gx]
if gy >= 0:
	XY = [(x, y) for (x, y) in XY if 0 <= y <= gy]
else:
	gy = -gy
	XY = [(x, -y) for (x, y) in XY if 0 <= -y <= gy]
XY.sort()
Y = [y for (x, y) in XY]
INF = 10 ** 18
dp = [INF] * (len(Y) + 1)
for y in Y:
	idx = bisect_left(dp, y)
	dp[idx] = y
L = bisect_left(dp, INF)
if L <= min(gx, gy):
	answer = 100 * (gx + gy) + (10 * pi / 2 - 20) * L
else:
	answer = 100 * (gx + gy) + (10 * pi / 2 - 20) * (L - 1) + (10 * pi - 20)
print(answer)


import operator
from bisect import bisect_left
from math import pi
import decimal

def lis(A):
	L = [A[0]]
	for a in A[1:]:
		if a > L[-1]:
			L.append(a)
		else:
			L[bisect_left(L, a)] = a
	return len(L)

def solve():
	(x1, y1, x2, y2) = map(int, input().split())
	if x1 > x2:
		(x1, y1, x2, y2) = (x2, y2, x1, y1)
	is_down = y1 > y2
	if is_down:
		(y1, y2) = (-y1, -y2)
	base = decimal.Decimal(100) * (x2 - x1 + y2 - y1)
	n = int(input())
	fountains = []
	for _ in range(n):
		(x, y) = map(int, input().split())
		if is_down:
			y = -y
		if x < x1 or x2 < x or y < y1 or (y2 < y):
			continue
		fountains.append((x, y))
	if not fountains:
		return str(base)
	dpi = decimal.Decimal(pi)
	fountains.sort()
	fountains_y = list(map(operator.itemgetter(1), fountains))
	mc = lis(fountains_y)
	if mc == min(x2 - x1, y2 - y1) + 1:
		dist = base + (dpi * 5 - 20) * (mc - 1) + dpi * 10 - 20
	else:
		dist = base + (dpi * 5 - 20) * mc
	return str(dist)
print(solve())


(x1, y1, x2, y2) = map(int, input().split())
fx = 1
fy = 1
if x1 > x2:
	(x1, x2) = (x2, x1)
	fx = -1
if y1 > y2:
	(y1, y2) = (y2, y1)
	fy = -1
n = int(input())
p = []
for i in range(n):
	(x, y) = map(int, input().split())
	if x1 <= x <= x2 and y1 <= y <= y2:
		p.append((fx * x, fy * y))
p = [y for (x, y) in sorted(p)]
from bisect import bisect_left as bl
b = []
for y in p:
	pos = bl(b, y)
	if len(b) <= pos:
		b.append(y)
	else:
		b[pos] = y
from math import pi
l = len(b)
if l == min(x2 - x1, y2 - y1) + 1:
	print(100 * (x2 - x1 + y2 - y1) + (5 * pi - 20) * (l - 1) + (10 * pi - 20))
else:
	print(100 * (x2 - x1 + y2 - y1) + (5 * pi - 20) * l)


(x1, y1, x2, y2) = map(int, input().split())
(W, H) = (abs(x1 - x2), abs(y1 - y2))
flip_x = x1 > x2
flip_y = y1 > y2
xo = min(x1, x2)
yo = min(y1, y2)
N = int(input())
F = []
for i in range(N):
	(x, y) = map(int, input().split())
	x -= xo
	y -= yo
	if 0 <= x <= W and 0 <= y <= H:
		if flip_x:
			x = W - x
		if flip_y:
			y = H - y
		F.append((x, y))
N = len(F)
from math import pi
from bisect import bisect
L = (W + H) * 100
if (W == 0 or H == 0) and F:
	L += pi * 10 - 20
elif N > 0:
	F.sort()
	F = [y for (x, y) in F]
	dp = [H + 1] * len(F)
	for (i, f) in enumerate(F):
		dp[bisect(dp, f)] = f
	n = bisect(dp, H)
	L -= (20 - pi * 5) * n
	if n == min(W, H) + 1:
		L += pi * 5
print(L)


import math
from bisect import bisect
(x1, y1, x2, y2) = map(int, input().split())
N = int(input())
src = [tuple(map(int, input().split())) for i in range(N)]
src.sort()
if x1 > x2:
	(x1, x2) = (x2, x1)
	(y1, y2) = (y2, y1)
arc = 5 * math.pi
if x1 == x2:
	if y1 > y2:
		(y1, y2) = (y2, y1)
	ans = 100 * (y2 - y1)
	for (x, y) in src:
		if x == x1 and y1 < y < y2:
			ans += arc * 2 - 20
			break
	print(ans)
	exit()
if y1 == y2:
	if x1 > x2:
		(x1, x2) = (x2, x1)
	ans = 100 * (x2 - x1)
	for (x, y) in src:
		if y == y1 and x1 < x < x2:
			ans += arc * 2 - 20
			break
	print(ans)
	exit()
if y1 < y2:
	lis = []
	for (x, y) in src:
		if x < x1:
			continue
		if x > x2:
			break
		if not y1 <= y <= y2:
			continue
		i = bisect(lis, y)
		if i == len(lis):
			lis.append(y)
		else:
			lis[i] = y
	ans = 100 * (x2 - x1 + y2 - y1)
	if len(lis) in (x2 - x1 + 1, y2 - y1 + 1):
		ans += (len(lis) - 1) * (arc - 20)
		ans += arc * 2 - 20
	else:
		ans += len(lis) * (arc - 20)
	print(ans)
else:
	lds = []
	for (x, y) in src:
		if x < x1:
			continue
		if x > x2:
			break
		if not y2 <= y <= y1:
			continue
		i = bisect(lds, -y)
		if i == len(lds):
			lds.append(-y)
		else:
			lds[i] = -y
	ans = 100 * (x2 - x1 + y1 - y2)
	if len(lds) in (x2 - x1 + 1, y1 - y2 + 1):
		ans += (len(lds) - 1) * (arc - 20)
		ans += arc * 2 - 20
	else:
		ans += len(lds) * (arc - 20)
	print(ans)


from sys import stdin
input = stdin.readline
from decimal import Decimal as D
from bisect import bisect_left as bl

def LIS(L):
	best = []
	for i in L:
		pos = bl(best, i)
		if len(best) <= pos:
			best.append(i)
		else:
			best[pos] = i
	return len(best)
xflip = 1
yflip = 1
(x1, y1, x2, y2) = map(int, input().split())
if x1 > x2:
	xflip = -1
	(x1, x2) = (x2, x1)
if y1 > y2:
	yflip = -1
	(y1, y2) = (y2, y1)
points = []
n = int(input())
for i in range(n):
	(x, y) = map(int, input().split())
	if x1 <= x <= x2 and y1 <= y <= y2:
		points.append((x * xflip, y * yflip))
points = [y for (x, y) in sorted(points)]
foun = LIS(points)
dist = D(100) * (x2 - x1 + y2 - y1)
dx = D('-4.2920367320510338076867835') * foun
if foun == min(x2 - x1 + 1, y2 - y1 + 1):
	dx += D('15.7079632679489661923132165')
print(dist + dx)


from bisect import bisect_left as bl
from math import pi
fx = 1
fy = 1
(x1, y1, x2, y2) = map(int, input().split())
if x1 > x2:
	fx = -1
if y1 > y2:
	fy = -1
N = int(input())
inf = 10 ** 9
f = [list(map(int, input().split())) for _ in range(N)]
f = [[p[0] * fx, p[1] * fy] for p in f if min(x1, x2) <= p[0] <= max(x1, x2) and min(y1, y2) <= p[1] <= max(y1, y2)]
f.sort(key=lambda x: (x[0], -x[1]))
lis = [inf] * N
lislen = 0
for i in range(len(f)):
	t = f[i][1]
	ind = bl(lis, t)
	lis[ind] = t
	lislen = max(lislen, ind + 1)
if lislen == min(abs(x2 - x1), abs(y2 - y1)) + 1:
	print((abs(x2 - x1) + abs(y2 - y1)) * 100 - 20 * lislen + 10 * pi + 5 * pi * max(lislen - 1, 0))
else:
	print((abs(x2 - x1) + abs(y2 - y1)) * 100 - 20 * lislen + 5 * pi * lislen)


import math
import bisect

def get_lis(S):
	dp = [float('inf')] * len(S)
	for (i, (x, y)) in enumerate(S):
		a = S[i][1]
		j = bisect.bisect_right(dp, a)
		dp[j] = a
	return bisect.bisect_left(dp, float('inf'))
(x_1, y_1, x_2, y_2) = map(int, input().split())
N = int(input())
if x_1 <= x_2:
	x_s = x_1
	y_s = y_1
	x_t = x_2
	y_t = y_2
else:
	x_s = x_2
	y_s = y_2
	x_t = x_1
	y_t = y_1
x_min = min(x_1, x_2)
x_max = max(x_1, x_2)
y_min = min(y_1, y_2)
y_max = max(y_1, y_2)
S = []
for i in range(N):
	(X, Y) = map(int, input().split())
	if X < x_min or X > x_max or Y < y_min or (Y > y_max):
		continue
	S.append((X, Y))
dist = 0
s_num = len(S)
S.sort()
if y_s > y_t:
	S.reverse()
	start_y = y_t
	end_y = y_s
else:
	start_y = y_s
	end_y = y_t
round_count = get_lis(S)
dist = (abs(x_t - x_s) + abs(y_t - y_s)) * 100 + (math.pi * 20 / 4 - 20) * round_count
if min(abs(x_t - x_s), abs(y_t - y_s)) + 1 == round_count:
	dist += math.pi * 5
print(dist)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 15
mod = 10 ** 9 + 7

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

class Seg:

	def __init__(self, na, default, func):
		if isinstance(na, list):
			n = len(na)
		else:
			n = na
		i = 1
		while 2 ** i <= n:
			i += 1
		self.D = default
		self.H = i
		self.N = 2 ** i
		if isinstance(na, list):
			self.A = [default] * self.N + na + [default] * (self.N - n)
			for i in range(self.N - 1, 0, -1):
				self.A[i] = func(self.A[i * 2], self.A[i * 2 + 1])
		else:
			self.A = [default] * (self.N * 2)
		self.F = func

	def find(self, i):
		return self.A[i + self.N]

	def update(self, i, x):
		i += self.N
		self.A[i] = x
		while i > 1:
			i = i // 2
			self.A[i] = self.merge(self.A[i * 2], self.A[i * 2 + 1])

	def merge(self, a, b):
		return self.F(a, b)

	def total(self):
		return self.A[1]

	def query(self, a, b):
		A = self.A
		l = a + self.N
		r = b + self.N
		res = self.D
		while l < r:
			if l % 2 == 1:
				res = self.merge(res, A[l])
				l += 1
			if r % 2 == 1:
				r -= 1
				res = self.merge(res, A[r])
			l >>= 1
			r >>= 1
		return res

def main():
	txy = LI()
	(x1, y1, x2, y2) = txy
	n = I()
	a = [LI() for _ in range(n)]
	im = 10 ** 8
	xs = set([x1, x2])
	ys = set([y1, y2])
	for (x, y) in a:
		xs.add(x)
		ys.add(y)
	xd = {}
	yd = {}
	i = 0
	for x in sorted(list(xs)):
		xd[x] = i
		i += 1
	i = 0
	for y in sorted(list(ys)):
		yd[y] = i
		i += 1
	x1 = xd[x1]
	x2 = xd[x2]
	y1 = yd[y1]
	y2 = yd[y2]
	a = [[xd[x], yd[y]] for (x, y) in a]
	if x1 > x2:
		(x2, y2, x1, y1) = (x1, y1, x2, y2)
	if y1 > y2:
		y1 = im - y1
		y2 = im - y2 - y1
		for i in range(n):
			a[i][1] = im - a[i][1] - y1
	else:
		y2 -= y1
		for i in range(n):
			a[i][1] -= y1
	y1 = 0
	x2 -= x1
	for i in range(n):
		a[i][0] -= x1
	x1 = 0

	def f(a, b):
		if a > b:
			return a
		return b
	seg = Seg(y2, 0, f)
	for (x, y) in sorted(a):
		if x < 0 or y < 0 or y > y2 or (x > x2):
			continue
		t = seg.query(0, y)
		if seg.find(y) > t:
			continue
		seg.update(y, t + 1)
	t = seg.total()
	kx = abs(txy[0] - txy[2])
	ky = abs(txy[1] - txy[3])
	r = (kx + ky) * 100
	if t == min(kx, ky) + 1:
		return r - t * 20 + math.pi * 5 * (t - 1) + math.pi * 10
	return r - t * 20 + math.pi * 5 * t
print(main())


import sys
sys.setrecursionlimit(2147483647)
INF = float('inf')
MOD = 10 ** 9 + 7
input = lambda : sys.stdin.readline().rstrip()
from math import pi
from bisect import bisect_left

def resolve():
	(x1, y1, x2, y2) = map(int, input().split())
	if x1 > x2:
		(x1, y1, x2, y2) = (x2, y2, x1, y1)
	trans = False
	if y1 > y2:
		(y1, y2) = (-y1, -y2)
		trans = True
	n = int(input())
	XY = []
	for i in range(n):
		(x, y) = map(int, input().split())
		if trans:
			y = -y
		if x1 <= x <= x2 and y1 <= y <= y2:
			XY.append((x, y))
	d = x2 - x1 + (y2 - y1)
	d *= 100
	l = min(x2 - x1, y2 - y1)
	XY.sort()
	C = [INF] * (n + 1)
	for (x, y) in XY:
		i = bisect_left(C, y)
		C[i] = y
	k = C.index(INF)
	if k > l:
		d -= (k - 1) * (20 - 5 * pi)
		d += 10 * pi - 20
	else:
		d -= k * (20 - 5 * pi)
	print(d)
resolve()


from bisect import bisect_left, insort
from math import pi

def inpl():
	return tuple(map(int, input().split()))
(sx, sy, gx, gy) = inpl()
yrev = False
if sx > gx:
	(sx, sy, gx, gy) = (gx, gy, sx, sy)
if sy > gy:
	(sy, gy) = (10 ** 8 - 1 - sy, 10 ** 8 - 1 - gy)
	yrev = True
N = int(input())
fountains = []
for _ in range(N):
	(x, y) = inpl()
	if yrev:
		y = 10 ** 8 - 1 - y
	if (sx <= x <= gx) & (sy <= y <= gy):
		fountains.append([x, y])
fountains.sort()
L = []
if len(fountains):
	L.append(fountains[0][1])
for f in fountains:
	(x, y) = f
	if L[-1] < y:
		L.append(y)
	else:
		L[bisect_left(L, y)] = y
if min(gx - sx, gy - sy) + 1 == len(L):
	print((gx - sx + (gy - sy)) * 100 - (20 - 5 * pi) * (len(L) - 1) + (10 * pi - 20))
else:
	print((gx - sx + (gy - sy)) * 100 - (20 - 5 * pi) * len(L))


import sys
import bisect
input = sys.stdin.readline
pi = 3.141592653589794
(x1, y1, x2, y2) = [int(v) for v in input().split()]
if x1 > x2:
	(x1, x2) = (x2, x1)
	(y1, y2) = (y2, y1)
ans = 100 * (abs(x2 - x1) + abs(y2 - y1))
d = -1 if y1 > y2 else 1
(xmax, xmin) = (max(x1, x2), min(x1, x2))
(ymax, ymin) = (max(y1, y2), min(y1, y2))
n = int(input())
fountains = []
for i in range(n):
	(x, y) = [int(v) for v in input().split()]
	if xmin <= x <= xmax and ymin <= y <= ymax:
		fountains.append([x, y])
if x1 == x2 or y1 == y2:
	if len(fountains) == 1:
		ans += 10 * pi - 20
else:
	fountains.sort()
	fountains = [-10 ** 9] + [i[1] * d for i in fountains]
	m = len(fountains)
	lis_list = [10 ** 9 for i in range(m)]
	for i in fountains:
		a = bisect.bisect_left(lis_list, i)
		lis_list[a] = i
	k = -1
	for i in lis_list:
		if i != 10 ** 9:
			k += 1
	if xmax - xmin + 1 == k or ymax - ymin + 1 == k:
		ans -= (k - 1) * (20 - 5 * pi)
		ans += 10 * pi - 20
	else:
		ans -= k * (20 - 5 * pi)
print(ans)


def LIS(N, a):
	res = 0
	dp = [1] * N
	for i in range(N):
		for j in range(i):
			if XY[j][0] < XY[i][0] and XY[j][1] < XY[i][1]:
				dp[i] = max(dp[i], dp[j] + 1)
		res = max(res, dp[i])
	return res
import math
(x1, y1, x2, y2) = map(int, input().split())
N = int(input())
W = abs(x2 - x1)
H = abs(y2 - y1)
xsgn = 2 * (x2 > x1) - 1
ysgn = 2 * (y2 > y1) - 1
XY = []
for i in range(N):
	(x, y) = map(int, input().split())
	if (x - x1) * (x - x2) <= 0 and (y - y1) * (y - y2) <= 0:
		XY += [[xsgn * (x - x1), ysgn * (y - y1)]]
N = len(XY)
short = 20 - 5 * math.pi
long = 10 * math.pi - 20
straight = 100 * (W + H)
from bisect import bisect
XY.sort()
XY = [y for (x, y) in XY]
dp = [H + 1] * len(XY)
for (i, f) in enumerate(XY):
	dp[bisect(dp, f)] = f
fountain = bisect(dp, H)
if fountain < min(W, H) + 1:
	print(straight - short * fountain)
else:
	print(straight - short * (fountain - 1) + long)