You are Tom Sawyer and you have to paint a fence of 102400 m long. Luckily, your friends decided to help you in exchange of various things. Each friend will paint L meters, starting from S with color C. S, L are integer amount of meters and 1 ≤ C ≤ 97. Getting bored you decide to find out how many meters of each color you have.
Input
Input is read from standard input. Each line contains three numbers S, L, C as described above.
Ouput
Output is written to standard output. For each color that appears on the final fence print the color number and the number of times it appears. Order by colors.
Examples
Input 0
..............
0 3 1 111...........
2 4 2 112222........
1 2 3 133222........
0 4 1 111122........
7 3 5 111122.555....
Output 0
1 4
2 2
5 3
Input 1
0 100 1
50 150 2
Output 1
1 50
2 150
Input 2
500 1000 1
0 2000 2
Output 2
2 2000
More examples
Here is a small generator:
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
/* From http://en.wikipedia.org/wiki/Random_number_generation */
unsigned m_w;
unsigned m_z;
unsigned get_random()
{
m_z = 36969 * (m_z & 65535) + (m_z >> 16);
m_w = 18000 * (m_w & 65535) + (m_w >> 16);
return (m_z << 16) + m_w; /* 32-bit result */
}
int main(int argc, char **argv)
{
int i;
assert(argc == 2);
m_w = 0xbabecafe;
m_z = atoi(argv[1]);
i = 10;
while (i--);
get_random();
i = atoi(argv[1]);
while (i--) {
int s = (int) ((get_random() << 8) % 102397);
int l = (int) ((get_random() << 8) % (102397 - s));
int c = (int) ((get_random() << 8) % 97 + 1);
printf("%d %d %d\n", s, l, c);
}
return 0;
}
Running examples:
$ ./gen 1 | ./paint
6 535
$ ./gen 10 | ./paint
28 82343
36 3476
41 1802
49 4102
82 1656
$ ./gen 100 | ./paint
2 2379
22 17357
24 4097
25 1051
34 55429
42 9028
45 9716
66 1495
71 196
85 640
97 706
$ ./gen 1000 | ./paint
16 719
26 29
28 24
33 1616
55 371
65 35
69 644
74 16
84 10891
86 36896
87 50832
89 19
$ ./gen 10000 | ./paint
3 800
6 5712
14 3022
17 16
26 1
29 18770
31 65372
37 387
44 40
49 37
50 93
55 11
68 278
70 19
71 64
72 170
77 119
78 6509
89 960
97 15
$ ./gen 100000 | ./paint
2 6
8 26
12 272
24 38576
26 1
34 1553
35 8
36 19505
43 2
45 11
46 2
47 9
49 27339
50 139
53 3109
69 11744
92 89
$ ./gen 1000000 | ./paint
1 1
3 4854
6 523
13 1
16 11
18 416
22 7
24 3920
25 96
31 10249
32 241
37 1135
45 10
57 758
62 2348
65 11
66 7422
78 6
85 13361
87 3833
88 187
91 46
93 7524
96 45436
Your program must run in reasonable time. My solution runs in a few seconds on the last example.
Shortest code wins.
Include running time and your output for the last test.
EDIT: This problem is not intended to be brute-forced, so a trivial solution is not acceptable.