In the event of technical difficulties with Szkopuł, please contact us via email at [email protected].
If you are familiar with IRC chat, the support team is also reachable on PIRC network (
#szkopul channel. If you are not, just use email.
Please do not ask us things like "how to solve task XYZ?".
Please remember that the support team has to sleep sometimes or go to work in real life.
In the rectangular coordinate system every point with integer coordinates is called p-point. Any segment with different ends being p-points, parallel to one of the axis of coordinates, is called p-segment. Only closed segments (with end points belonging to the segment) are taken into consideration. A broken line built from p-segments, in which every two consecutive ones are perpendicular, we call p-broken-line of degree .
Write a program which:
Description of a p-point consists of two non-negative integers, being being coordinates and adequately of this p-point, separated by a single space, These numbers are from range . The first line of the standard input contains only the description of the p-point . The second line contains only the description of the p-point . The third line consists exactly of one non-negative integer n being the number of p-segments, . Each of next lines consists of descriptions of exactly two p-points, separated by a single space. These are coordinates of the ends of one p-segment.
The first and the the only line of standrd output should contain either one number being minimum degree of p-broken-line connecting points and and not crossing any of given p-segments, or the word "BRAK", if a p-broken-line having above-mentioned properties does not exist.
For the input data:
1 2 3 4 5 0 0 7 0 0 5 7 5 2 2 2 7 4 0 4 3 3 2 6 2
the correct result is:
Task author: Grzegorz Jakacki.