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 Kotlin (1.0.0) (judge verdict: Wrong Answer)

import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.StreamTokenizer
import java.util.HashMap

fun main(args: Array<String>) {
    val st = StreamTokenizer( BufferedReader( InputStreamReader( System.`in` ) ) )
    var x1 = st.nextInt()
    var y1 = st.nextInt()
    var x2 = st.nextInt()
    var y2 = st.nextInt()
    val n = st.nextInt()
    val x = IntArray( n )
    val y = IntArray( n )
    for ( i in 0 until n ) {
        x[i] = st.nextInt() * if ( x1 <= x2 ) 1 else -1
        y[i] = st.nextInt() * if ( y1 <= y2 ) 1 else -1
    }
    if ( x1 > x2 ) {
        x1 = -x1
        x2 = -x2
    }
    if ( y1 > y2 ) {
        y1 = -y1
        y2 = -y2
    }
    val inside = x.indices.filter { i -> x[i] in x1 .. x2 && y[i] in y1 .. y2 }
    val byX = inside.indices.sortedBy { x[inside[it]] }
    val Y = byX.map { y[inside[it]] }
    val byY = Y.indices.sortedBy { Y[it] }
    val yToPos = HashMap<Int, Int>()
    for ( i in byY.indices ) {
        yToPos[Y[i]] = i
    }
    val segTree = SegmentTree( Y.size )
    for ( i in Y.indices ) {
        val value = segTree.max( yToPos[Y[byY[i]]]!! ) + 1
        segTree.put( yToPos[Y[byY[i]]]!!, value )
    }
    println( ( Math.abs( x2 - x1 ) + Math.abs( y2 - y1 ) ) * 100.0 +
            segTree.max( Y.size + 1 ) * 10.0 * ( Math.PI / 2 - 2 ) +
            if ( x2 - x1 + 1 == inside.size || y2 - y1 + 1 == inside.size ) 10 * Math.PI / 2 else 0.0
    )
}

class SegmentTree( size: Int ) {

    val s: Int
    val a: IntArray

    init {
        s = size.closest2Pow()
        a = IntArray( 2 * s )
    }

    fun put( p: Int, value: Int ) {
        var c = s + p
        a[c] = value
        while ( c > 1 ) {
            c /= 2
            a[c] = Math.max( a[c * 2], a[c * 2 + 1] )
        }
    }

    fun max( until: Int ): Int {
        if ( until >= s ) return a[1]
        var m = 0
        var c = 1
        var l = 0
        var r = s
        while ( c * 2 < a.size ) {
            if ( l >= until ) break
            c *= 2
            val mid = ( l + r ) / 2
            if ( mid > until ) {
                r = mid
            } else {
                m = Math.max( m, a[c] )
                l = mid
                c ++
            }
        }
        return m
    }
}

private fun Int.closest2Pow(): Int {
    var r = 1
    while ( r < this ) r *= 2
    return r
}

private fun StreamTokenizer.nextInt(): Int {
    nextToken()
    return nval.toInt()
}