#t284. 垃圾炸弹

垃圾炸弹

Garbage Bomb

Problem Background

Special for beginners, ^_^

Problem Description

The 2118 FIFA World Cup has kicked off! To let fans watch the matches conveniently, many intersections in the streets of Moscow have large live-screen displays. But after the crowds disperse, a pile of garbage is always left at these intersections. To deal with this, the Russian government decided to use a newly invented "garbage bomb". Using the most advanced quantum physics technology, the shockwave after the explosion can completely clear all garbage within its affected area, without any other side effects. The shockwave spreads in a square shape; the bomb's power (spread distance) is given by dd, meaning it can travel dd blocks.

For example, the figure below shows the affected area of a "garbage bomb" with d=1d = 1.

garbage.png

Suppose Moscow's layout is a strict 1025×10251025 \times 1025 grid. Because of financial constraints the city can only afford one "garbage bomb". They hope you can help them find a suitable drop location so that the total amount of garbage cleared in one shot is maximized (the garbage amount at an intersection is represented by a non-negative integer not exceeding 2020, and there is no garbage anywhere except at the intersections with screens).

Input Format

The first line gives the bomb's power d (1≤d≤20)d\ (1 \le d \le 20).

The second line gives an integer n (1≤n≤50)n\ (1 \le n \le 50), the number of intersections with screens (and thus with garbage).

The next nn lines each give three numbers x,y,ix, y, i, representing the intersection's coordinates (x,y)(x, y) and the amount of garbage ii.

The point coordinates (x,y)(x, y) are guaranteed to be valid (in the range 00 to 10241024), and the same coordinate is given at most once.

Output Format

Output the number of drop points that clear the most garbage, and the total amount of garbage that can be cleared.

Sample Input

1
2
4 4 10
6 6 20

Sample Output

1 30

Constraints

1s, 1024KiB for each test case.