QOJ.ac

QOJ

時間限制: 4 s 記憶體限制: 512 MB 總分: 100

#8669. Square Counting

统计

Given a convex polygon with $n$ vertices on a grid. Let $S$ be the set of grid points inside and on the boundary of this convex polygon. Find the number of ways to choose four distinct, unordered points $(x, y, z, w)$ from $S$ such that $x, y, z, w$ form a square.

Input

The first line contains an integer $n$.

The next $n$ lines each contain two non-negative integers $(x_i, y_i)$, representing the vertices of the convex polygon on the grid in clockwise order.

Output

Output a single integer representing the number of ways to choose four distinct, unordered points $(x, y, z, w)$ such that they form a square.

Examples

Input 1

5
0 0
0 2
1 2
2 1
2 0

Output 1

4

Input 2

3
0 0
0 100
100 0

Output 2

1473186

Input 3

4
0 100
100 200
200 100
100 0

Output 3

34001650

Subtasks

Subtask 1 ($10\%$): The input is a rectangle, and the first point is the bottom-left corner (the point with the minimum $x$ and $y$ coordinates).

Subtask 2 ($25\%$): The input is a right-angled triangle, the right angle is at the bottom-left, and the first point is the bottom-left corner (the point with the minimum $x$ and $y$ coordinates).

Subtask 3 ($15\%$): $n \le 8, 0 \le x_i, y_i \le 10$

Subtask 4 ($20\%$): $n \le 8, 0 \le x_i, y_i \le 300$

Subtask 5 ($15\%$): $n \le 8, 0 \le x_i, y_i \le 800$

Subtask 6 ($15\%$): $n \le 8, 0 \le x_i, y_i \le 2000$

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.