This page is still under construction.

Parts of this page are still being built. What you see may change.

Umbral Decoding

Time limit2sMemory limit512 MB

Summary
Given up to 100 safe points (x, y, b), count lattice points (p, q) in the square [0, n]^2 that are not covered by any region |x-p|^3 + |y-q|^3 <= b.
Level

Hard8 of 10

Topics
Geometry, Math, Implementation
Solved
No attempts yet

Problem

You are planning an attack on a new encryption algorithm. To succeed you must find the key, which is a pair of integers (p,q)(p, q). Think of the key as a point on the two dimensional integer lattice whose position is unknown. For a given nn you do know that (p,q)(p, q) lies in the square spanned by the lattice points (0,0)(0, 0) and (n,n)(n, n), that is, 0≤p,q≤n0 \le p, q \le n.

The attack has three stages.

  1. Identify the safe points and their bounds.
  2. Eliminate from the key candidates every point that lies in the umbra of some safe point.
  3. Test the remaining points to see which one is the key.

Stage 1 is already done, and several safe points of the form (x,y,b)(x, y, b) are given as input.

In stage 2 you eliminate a point (p,q)(p, q) when it lies in the umbra of some safe point. Point (p,q)(p, q) is in the umbra of safe point (x,y,b)(x, y, b) if and only if

∣x−p∣3+∣y−q∣3≤b|x - p|^3 + |y - q|^3 \le b

Count how many points are left for stage 3, so that the amount of work still needed to finish the attack is known.

Safe points, their umbra, and the remaining points

Figure 1. Safe points and their umbra (red) and the remaining points (blue), for one example.

Input

The first line holds two integers nn and kk separated by a space, with 2≤n≤1082 \le n \le 10^8 and 0≤k≤1000 \le k \le 100.

Each of the next kk lines holds three integers xx, yy, bb separated by spaces, describing one safe point. Both xx and yy are in the range [0,n][0, n], and the bound bb is also in the range [0,n][0, n].

Output

Print the number of points (p,q)(p, q) with 0≤p,q≤n0 \le p, q \le n that do not lie in the umbra of any safe point.

Examples2

  1. Example 1

    Input
    4 1
    2 2 2
    
    Expected output
    16
    
  2. Example 2

    Input
    30 2
    20 20 30
    25 22 30
    
    Expected output
    891