NWERC 2021 Open Contest


2021-11-27 00:00 AKST

NWERC 2021 Open Contest


2021-11-27 05:00 AKST
The end is near!
Contest is over.
Not yet started.
Contest is starting in -50 days 19:22:33

Time elapsed


Time remaining


Problem F
Flatland Olympics

2008 Beijing Olympics by PhotoBobil
It is the day after Olympia, and you—as the organizer—are happy that everything worked well in these troublesome times. Well, not everything….

Since this morning e-mails have been filling up your inbox, containing complaints about obscured views during the most important race: the $100$-meter dash. They demand their money back, or threaten exposing you on social media. To make things worse, spectators have not just complained once, but they have sent you a separate e-mail for every person that blocked their view at some point during the race! They even wrote multiple e-mails when two or more people blocked their view at the same time. And not only that, some visitors complained to the main sponsor Dy & Son who in turn has urged you to improve the situation.

Since you expect that a greater number of visitors will be allowed to spectate at the next Olympic games, you assume that there will be even more complaints if you do not address this issue. If the situation will be too bad, you may even lose your sponsor Dy & Son. Therefore, you decide to count the number of complaints beforehand. To do this, you model the running track as a straight line segment, and count the maximal number of complaints you could get based on the seating of the visitors. Depending on the number of complaints you expect, you will determine if you need to rework the seating or just reconfigure your spam blocker and try to find a new sponsor.


The input consists of:

  • One line containing four integers $x_ s$, $y_ s$, $x_ e$ and $y_ e$ $(|x_ s|, |y_ s|, |x_ e|, |y_ e| \leq 10^{9})$, where $s=(x_ s, y_ s)$ is the starting point of the running track and $e=(x_ e, y_ e)$ is the end point of the running track. Both $s$ and $e$ belong to the running track.

  • One line containing an integer $n$ $(1 \leq n \leq 10^{5})$, the number of visitors.

  • $n$ lines, each containing two integers $x$ and $y$ $(|x|,|y|\leq 10^{9})$, where $(x,y)$ is the location of the seat of a visitor.

It is guaranteed that the track has a positive length, i.e. $s\neq e$. Further, you can assume that all visitors are seated at distinct locations and that no visitor is seated on the track.


Output the total number of complaints that you would receive for the given seating.

\includegraphics[width=0.7\textwidth ]{sample2}
Figure 1: Illustration of Sample Input 2. The running track is drawn as a red line and the seats of the visitors are highlighted in blue. The second visitor will complain about the first visitor and the fourth visitor will complain about the third visitor.
Sample Input 1 Sample Output 1
0 0 100 0
50 20
50 30
50 50
120 0
Sample Input 2 Sample Output 2
0 0 100 0
50 20
50 30
50 -20
50 -30
100 30