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# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        long x1 = int.Parse(str[0]);
        long y1 = int.Parse(str[1]);
        long x2 = int.Parse(str[2]);
        long y2 = int.Parse(str[3]);
        int N = int.Parse(Console.ReadLine());
        double count;
        if(x1 == x2){
            bool b = false;
            for(int i=0;i<N;i++){
                str = Console.ReadLine().Split(' ');
                long X = int.Parse(str[0]);
                if(x1 == X){
                    long Y = int.Parse(str[1]);
                    if(Math.Min(y1,y2) < Y && Y < Math.Max(y1,y2)){
                        b = true;
                    }
                    break;
                }
            }
            count = (Math.Max(y1,y2) - Math.Min(y1,y2)) * 100 + (b ? (20*(Math.PI/2-1)) : 0);
        }
        else if(y1 == y2){
            bool b = false;
            for(int i=0;i<N;i++){
                str = Console.ReadLine().Split(' ');
                long Y = int.Parse(str[1]);
                if(y1 == Y){
                    long X = int.Parse(str[0]);
                    if(Math.Min(x1,x2) < X && X < Math.Max(x1,x2)){
                        b = true;
                    }
                    break;
                }
            }
            count = (Math.Max(x1,x2) - Math.Min(x1,x2)) * 100 + (b ? (20*(Math.PI/2-1)) : 0);
        }
        else{
            long[] xp = new long[N];
            long[] yp = new long[N];
            for(int i=0;i<N;i++){
                str = Console.ReadLine().Split(' ');
                long X = int.Parse(str[0]);
                if(x1 > x2){
                    X = 100000000-1-X;
                }
                long Y = int.Parse(str[1]);
                if(y1 > y2){
                    Y = 100000000-1-Y;
                }
                xp[i] = X;
                yp[i] = Y;
            }
            if(x1 > x2){
                x1 = 100000000-1-x1;
                x2 = 100000000-1-x2;
            }
            if(y1 > y2){
                y1 = 100000000-1-y1;
                y2 = 100000000-1-y2;
            }
            long[] DX;
            long[] DY;
            Compression YC;
            {
                List<long> LX = new List<long>();
                List<long> LY = new List<long>();
                for(int i=0;i<N;i++){
                    if(x1 <= xp[i] && xp[i] <= x2 && y1 <= yp[i] && yp[i] <= y2){
                        LX.Add(xp[i]);
                        LY.Add(yp[i]);
                    }
                }
                DX = LX.ToArray();
                DY = LY.ToArray();
                YC = new Compression(LY.ToArray());
            }
            Array.Sort(DX,DY);
            if(DY.Length != 0){
                SegTree Seg = new SegTree(YC.size,this);
                for(int i=0;i<DY.Length;i++){
                    int YP = YC.ToPoint(DY[i]);
                    Seg.Add(YP,Seg.Max(0,YP)+1);
                }
                count = (y2-y1+x2-x1) * 100 - (20 - 5*Math.PI) * Seg.Max(0,YC.size-1);
            }
            else{
                count = (y2-y1+x2-x1) * 100;
            }
        }
        sb.Append(count+"\n");
    }
}
struct SegTree{
    Solve Sol;
    public int[] X;
    int C;
    //葉の最初の場所
    public int segf;
    //segfのbit
    public int segfb;
    //葉の深さの内浅い方
    public int depth;
    //浅い葉の内座標が最大のもの
    public int borderP;
    //はみ出すものの数
    public int border;
    public SegTree(int N,Solve So){
        Sol = So;
        X = new int[2*N-1];
        C = 0;
        for(depth = 1;(1 << depth) <= N;depth++){
            ;
        }
        segf = N-1;
        borderP = (1 << depth) - 2;
        border = 2*N - borderP - 2;
        segfb = border/2;
    }
    public int ToBit(int p){
        if(p >= border){
            return segfb + p - border;
        }
        else{
            return p;
        }
    }
    //葉のある場所
    public int ToLeaf(int p){
        if(p >= border){
            return segf + p - border;
        }
        else{
            return borderP + p + 1;
        }
    }
    //葉の示す頂点
    public int ToPoint(int leaf){
        if(leaf > borderP){
            return leaf - borderP - 1;
        }
        else{
            return leaf - segf + border;
        }
    }
    public void Add(int p,int C0){
        //葉の作業
        X[ToLeaf(p)] = C0;
        //親の作業
        for(int v=ToLeaf(p);v!=0;v=(v-1)/2){
            int spa = (v-1)/2;
            X[spa] = Math.Max(X[spa],C0);
        }
    }
    //vの子の内bより大きいものに(bは子孫,bはToBitしたもの)
    void More(int b,int v,int depth){
        if((b & (1 << depth)) == 0){
            //右の子は全てbより大きい
            if(((b+1) % (1 << depth)) != 0){
                More(b,v*2+1,depth-1);
                Act(v*2+2);
            }
            else{
                Act(v*2+2);
            }
        }
        else{
            //左の子は全てb未満
            More(b,v*2+2,depth-1);
        }
    }
    //vの子の内bより小さなものに(bは子孫,bはToBitしたもの)
    void Less(int b,int v,int depth){
        if((b & (1 << depth)) == 0){
            //右の子は全てbより大きい
            Less(b,v*2+1,depth-1);
        }
        else{
            //左の子は全てb未満
            if(b % (1 << depth) != 0){
                Act(v*2+1);
                Less(b,v*2+2,depth-1);
            }
            else{
                //右の子は全てb以上
                Act(v*2+1);
            }
        }
    }
    void Section(int bl,int br,int v,int dl,int dr){
        if(v >= segf){
            //葉
            Act(v);
        }
        else{
            if((bl & (1 << dl)) == 0 && (br & (1 << dr)) == 0){
                //両方左
                Section(bl,br,v*2+1,dl-1,dr-1);
            }
            else if((bl & (1 << dl)) != 0 && (br & (1 << dr)) != 0){
                //両方右
                Section(bl,br,v*2+2,dl-1,dr-1);
            }
            else{
                //左と右に分かれた
                if(bl % (1 << dl) != 0){
                    More(bl-1,v*2+1,dl-1);
                }
                else{
                    //左は全て含まれる
                    Act(v*2+1);
                }
                if((br + 1) % (1 << dl) != 0){
                    Less(br+1,v*2+2,dr-1);
                }
                else{
                    //右は全て含まれる
                    Act(v*2+2);
                }
            }
        }
    }
    void Act(int v){
        C = Math.Max(C,X[v]);
    }
    public int Max(int l0,int r0){
        C = 0;
        int bl = ToBit(l0);
        int br = ToBit(r0);
        int dl = l0 >= border ? depth - 2 : depth - 1;
        int dr = r0 >= border ? depth - 2 : depth - 1;
        Section(bl,br,0,dl,dr);
        return C;
    }
}
class Compression{
    public int size;
    public long[] A;
    public Compression(long[] a){
        if(a.Length == 0){
            size = 0;
            return;
        }
        Array.Sort(a);
        List<long> AL = new List<long>();
        AL.Add(a[0]);
        for(int i=1;i<a.Length;i++){
            if(a[i] != a[i-1]){
                AL.Add(a[i]);
            }
        }
        A = AL.ToArray();
        size = A.Length;
    }
    public int ToPoint(long X){
        int bf = 0;
        int bl = size-1;
        while(bf != bl){
            int bc = (bf+bl)/2;
            if(A[bc] >= X){
                bl = bc;
            }
            else{
                bf = bc+1;
            }
        }
        return bf;
    }
    public long Value(int i){
        return A[i];
    }
}