QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 128 MB Puntuación total: 50

#16166. Whac-A-Mole

Estadísticas

Moles are animals that love to dig holes, but every once in a while, they like to poke their heads out of the ground to get some fresh air. Based on this characteristic, A-Niu has created a mole-whacking game: in an $n \times n$ grid, moles will appear in certain grid cells at certain times to get some air. You can control a robot to whack the moles. If a mole appears in a grid cell at time $i$ and the robot is also in the same grid cell, the mole will be whacked. At each time step, the robot can only move one cell or stay in its current position. The robot's movement is defined as moving from its current grid cell to an adjacent grid cell, i.e., from the grid cell at coordinates $(x, y)$ to one of the four grid cells $(x-1, y)$, $(x+1, y)$, $(x, y-1)$, or $(x, y+1)$. The robot cannot move outside the $n \times n$ grid. At the start of the game, you can freely choose the robot's initial position.

Given the times and locations where the moles appear over a period of time, write a program to enable the robot to whack as many moles as possible during this period.

Input

The first line contains $n$ ($n \le 1000$) and $m$ ($m \le 10000$), where $m$ represents the number of moles that appear during this period. The following $m$ lines each contain three data points: time, x, and y, indicating that a mole appears at the grid cell at row $x$ and column $y$ at time units after the game starts. The time values are given in increasing order. Note that multiple moles may appear at the same time, but only one mole can appear at the same location at the same time.

Output

The output contains only a single positive integer, representing the maximum number of moles that can be whacked.

Examples

Input 1

2 2
1 1 1
2 2 2

Output 1

1

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.