PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SRD0000017. Bãi chứa công-ten-nơ (Shipping Containers)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Bãi chứa công-ten-nơ (Shipping Containers)

Shipping Containers

Source: Szkopuł

Version: Phuoc Hung OJ Extended

Problem Statement

A loading wharf consists of nn consecutive positions, numbered from 11 to nn. Initially, every position contains 00 shipping containers, and any number of containers may be stacked at the same position.

There are kk crane operations. Operation ii is described by (ai,ℓi,di)(a_i,\ell_i,d_i): the crane places exactly one container at each position

$$a_i,\ a_i+d_i,\ a_i+2d_i,\ldots,\ a_i+(\ell_i-1)d_i.$$

Hence the operation places ℓi\ell_i containers. The final selected position is guaranteed not to exceed nn. When ℓi=1\ell_i=1, the input guarantees di=1d_i=1.

After all operations, compute the number of containers at every position 11 through nn. Each selected position receives a constant increment of 1, unlike the increasing increments in Sparse update.

Input

The first line contains n,kn,k. Each of the next kk lines contains positive integers a len d, where len denotes ℓi\ell_i.

Output

Print nn space-separated integers: the number of containers at each position after all operations, in ascending index order.

Subtasks

  • Subtask 1 (15 points): 1≤n≤501\le n\le 50; 1≤k≤601\le k\le 60; 1≤a,ℓ,d≤n1\le a,\ell,d\le n; a+(ℓ−1)d≤na+(\ell-1)d\le n; nếu ℓ=1\ell=1 thì d=1d=1.
  • Subtask 2 (20 points): 1≤n≤20001\le n\le 2000; 1≤k≤20001\le k\le 2000; 1≤a,ℓ,d≤n1\le a,\ell,d\le n; a+(ℓ−1)d≤na+(\ell-1)d\le n; nếu ℓ=1\ell=1 thì d=1d=1.
  • Subtask 3 (25 points): 1≤n≤200001\le n\le 20000; 1≤k≤200001\le k\le 20000; 1≤a,ℓ,d≤n1\le a,\ell,d\le n; a+(ℓ−1)d≤na+(\ell-1)d\le n; nếu ℓ=1\ell=1 thì d=1d=1.
  • Subtask 4 (40 points): 1≤n≤1000001\le n\le 100000; 1≤k≤1000001\le k\le 100000; 1≤a,ℓ,d≤n1\le a,\ell,d\le n; a+(ℓ−1)d≤na+(\ell-1)d\le n; nếu ℓ=1\ell=1 thì d=1d=1.

Examples

Input

8 3
3 4 1
2 3 3
3 2 2

Output

0 1 2 1 3 1 0 1

Explanation

Operation (3,4,1) places containers at 3,4,5,63,4,5,6. Operation (2,3,3) places them at 2,5,82,5,8. Operation (3,2,2) places them at 3,53,5. Counting selections yields [0,1,2,1,3,1,0,1][0,1,2,1,3,1,0,1]; position 55 has three containers.