Polish version    English version  
  History of OI -> XIII OI 2005/2006 -> Problems


 News
 About Olympic
 History of OI
XVII OI 2009/2010
XVI OI 2008/2009
XV OI 2007/2008
XIV OI 2006/2007
XIII OI 2005/2006
Schedule
Problems
Stage III - results
Stage II - results
Stage I - results
Stage II
Stage III
Regulations
For contestants
Helpful resources
XII OI 2004/2005
XI OI 2003/2004
X OI 2002/2003
IX OI 2001/2002
VIII OI 2000/2001
VII OI 1999/2000
VI OI 1998/1999
V OI 1997/1998
IV OI 1996/1997
III OI 1995/1996
II OI 1994/1995
I OI 1993/1994
 OI books
 National team
 Olympic camps
 Photo gallery
 Links
 SIO
 MAIN

Task: Frogs

Available memory: 64 MB

A scourge of frogs destroying all the crop has started in Byteotia. A farmer named Byteasar has decided to fight the vermin with peculiar "scarefrogs", that he has set up at certain points of his field. While moving from one place to another, every frog tries to keep as far of them as possible, i.e. maximizes the distance to the closest scarefrog.

The field that belongs to Byteasar has rectangular shape. The frogs leap in directions parallel to the field's sides and their leaps are unitary (of length 1). The scarefrogs-distance, for a given frog's route, is the minimum of all distances from all scarefrogs at all inter-leap-points of the route.

Byteasar already knows the most common starting and destination points of the frogs' routes, therefore he experiments with various deployments of the scarefrogs. He asks you for help, namely he would like you to write a programme that calculates the maximum (over all routes) scarefrogs-distance for a given deployment of scarefrogs -- which we call in short the frogshold distance.

Task

Write a programme that:
  • reads from the standard input the size of the field, the coordinates of the screfrogs and the source and target position of a frog,
  • determines the frogshold distance (the maximum scarefrogs-distance a frog may achieve while still being able to reach the target point)
  • writes the square of this number to the standard output.

Input

The first line of the input contains two integers: wx and wy separated by a single space -- the breadth and length of the field ( 2 $ \leq$% WIDTH=16 HEIGHT=30 wx, wy $ \leq$% WIDTH=16 HEIGHT=30 1 000). The second line of the input contains four integers: px, py, kx and ky separated by single spaces; (px, py) is the initial position of the frog, (kx, ky) is the target (final) position of the frog ( 1 $ \leq$% WIDTH=16 HEIGHT=30 px, kx $ \leq$% WIDTH=16 HEIGHT=30 wx, 1 $ \leq$% WIDTH=16 HEIGHT=30 py, ky $ \leq$% WIDTH=16 HEIGHT=30 wy). The third line of the stanard input contains one integer n -- the number of scarefrogs deployed on the field ( 1 $ \leq$% WIDTH=16 HEIGHT=30 n $ \leq$% WIDTH=16 HEIGHT=30 wx . wy). The following n lines contain the coordinates of subsequent scarefrogs. The line no. i + 3 for 1 $ \leq$% WIDTH=16 HEIGHT=30 i $ \leq$% WIDTH=16 HEIGHT=30 n contains two integers xi and yi separated by a single space -- these are the coordinates of the ith scarefrog ( 1 $ \leq$% WIDTH=16 HEIGHT=30 xi $ \leq$% WIDTH=16 HEIGHT=30 wx, 1 $ \leq$% WIDTH=16 HEIGHT=30 yi $ \leq$% WIDTH=16 HEIGHT=30 wy). No two scarefrogs occupy the same position and none of them is at the point (px, py) nor (kx, ky).

Output

In the first and only line of the standard output one integer should be written, namely the square of the frogshold distance. If the frog cannot avoid leaping directly on some scarefrog the result is 0.

Example

For the following input data:
5 5
1 1 5 5
2
3 3
4 2
the correct answer is:
4
Optimal route of the frog
Optimal route of the frog.



Print friendly version