QOJ.ac

QOJ

Límite de tiempo: 3.0 s Límite de memoria: 1024 MB Puntuación total: 100 Hackeable ✓

#23645. Captain Thrawn

Estadísticas

Captain Thrawn of the Chiss Ascendancy is stranded on the Paataatus homeworld! He has a crucial piece of information that he needs to get to Admiral Ar'alani, but he can't wait for a friendly starship to pick him up. Instead, he needs to establish a communications triad to transmit that information to her. The triad consists of 3 parts, which all need to be placed at equal non-zero Euclidean distance from each other (i.e. in the vertices of an equilateral triangle) to successfully transmit data.

However, the political relationship between the Chiss and the Paataatus is tense, so the Paataatus government won't allow Thrawn to put parts of the triad anywhere. The Paataatus capital has a shape of a regular hexagon with the side $l$. It has $2l + 1$ equally spaced parallel streets going from west to east, numbered from $-l$ to $l$ from south to north, with the street $-l$ going along the southernmost side of the hexagon, the street $l$ going along the northernmost side of the hexagon, and the street $0$ going through the center of the hexagon.

Similarly, there are $2l + 1$ equally spaced parallel avenues going from north-west to south-east, numbered from $-l$ to $l$ from south-west to north-east, with the avenue $-l$ going along the south-westernmost side of the hexagon, the avenue $l$ going along the north-easternmost side of the hexagon, and the avenue $0$ going through the center of the hexagon.

And there are $2l + 1$ equally spaced parallel boulevards going from south-west to north-east, numbered from $-l$ to $l$ from south-east to north-west, with the boulevard $-l$ going along the south-easternmost side of the hexagon, the boulevard $l$ going along the north-westernmost side of the hexagon, and the boulevard $0$ going through the center of the hexagon.

Here is an example of the capital's layout for $l = 2$:

problem_23645_61db380b8da2c2f06c4fa47d141b47f1.png

At each intersection of a street, an avenue, and a boulevard, there is a tower. If the street number is $x$, the avenue number is $y$, and the boulevard number is $z$, then the tower has coordinates $(x, y, z)$. Each tower is owned by some Paataatus official.

Luckily for Thrawn, during his career, he has helped several Paataatus officials, and now they are willing to help him back and allow him to set up a part of his triad in one of their towers. In total, they own $n$ towers, so Thrawn needs to select 3 of them that are equal distance from each other to establish a triad. Before making his choice, Thrawn wants to know all of his options or at least how many there are. Help him count the number of ways to choose 3 towers where a communications triad can be established.

Input

The first line contains two integers $l$ and $n$ — the side length of the capital and the number of towers willing to help Thrawn ($1 \le l \le 500$; $1 \le n \le 3 \cdot l \cdot (l + 1) + 1$).

Each of the next $n$ lines contains 3 integers $x_i, y_i, z_i$ — the coordinates of the $i$-th tower ($-l \le x_i, y_i, z_i \le l$). It is guaranteed that every set of coordinates represents some tower and that all the towers in the input are distinct.

Output

Output a single integer — the number of ways to choose the required 3 towers.

Examples

Input 1

2 6
-1 -2 1
2 2 0
-1 1 -2
-1 0 -1
1 1 0
0 1 -1

Output 1

1

Input 2

1 7
0 1 -1
1 1 0
0 -1 1
1 0 1
-1 -1 0
-1 0 -1
0 0 0

Output 2

8

Note

A triangular grid for your convenience:

problem_23645_cd9cbf58f065d9a594a7e17a785b57df.png

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.