One more line
Time limit1sMemory limit1024 MB
Given a grid of lines x=0..n and y=0..n plus one segment between two cell centers, count the axis-parallel rectangles whose sides lie on those lines.
- Level
Medium6 of 10
- Topics
- Math, Geometry, Combinatorics
- Solved
- No attempts yet
Problem
A coordinate plane has lines drawn on it. The lines are and . Bsil was counting the rectangles that can be formed from this figure.

Then a segment connecting the points and was added. Bsil, who likes solving every problem with a single formula, now faces a very hard problem. To help him, count the rectangles with sides parallel to the coordinate axes whose sides can be formed from the intersections of lines with lines or lines with the segment.
Input
The first line contains an integer . ()
The second line contains two integers and . ()
The third line contains two integers and . ()
It is guaranteed that and are different points.
Output
Print the answer to the problem.