131E.md (2013B)
1 Source: https://codeforces.com/problemset/problem/131/E 2 3 E. Yet Another Task with Queens 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 stdin 16 17 output 18 19 stdout 20 21 A queen is the strongest chess piece. In modern chess the queen can move any number of squares in any horizontal, vertical or diagonal direction (considering that there're no other pieces on its way). The queen combines the options given to the rook and the bishop. 22 23 There are *m* queens on a square *n* × *n* chessboard. You know each queen's positions, the *i*-th queen is positioned in the square (*r**i*, *c**i*), where *r**i* is the board row number (numbered from the top to the bottom from 1 to *n*), and *c**i* is the board's column number (numbered from the left to the right from 1 to *n*). No two queens share the same position. 24 25 For each queen one can count *w* — the number of other queens that the given queen threatens (attacks). For a fixed attack direction only the first queen in this direction is under attack if there are many queens are on the ray of the attack. Obviously, for any queen *w* is between 0 and 8, inclusive. 26 27 Print the sequence *t*0, *t*1, ..., *t*8, where *t**i* is the number of queens that threaten exactly *i* other queens, i.e. the number of queens that their *w* equals *i*. 28 29 Input 30 31 The first line of the input contains a pair of integers *n*, *m* (1 ≤ *n*, *m* ≤ 105), where *n* is the size of the board and *m* is the number of queens on the board. Then *m* following lines contain positions of the queens, one per line. Each line contains a pair of integers *r**i*, *c**i* (1 ≤ *r**i*, *c**i* ≤ *n*) — the queen's position. No two queens stand on the same square. 32 33 Output 34 35 Print the required sequence *t*0, *t*1, ..., *t*8, separating the numbers with spaces. 36 37 Examples 38 39 Input 40 41 ``` 42 8 4 43 4 3 44 4 8 45 6 5 46 1 6 47 ``` 48 49 Output 50 51 ``` 52 0 3 0 1 0 0 0 0 0 53 ``` 54 55 Input 56 57 ``` 58 10 3 59 1 1 60 1 2 61 1 3 62 ``` 63 64 Output 65 66 ``` 67 0 2 1 0 0 0 0 0 0 68 ```