625C.md (1821B)
1 Source: https://codeforces.com/problemset/problem/625/C 2 3 C. K-special Tables 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 standard input 16 17 output 18 19 standard output 20 21 People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects. 22 23 Alis is among these collectors. Right now she wants to get one of *k*-special tables. In case you forget, the table *n* × *n* is called *k*-special if the following three conditions are satisfied: 24 25 * every integer from 1 to *n*2 appears in the table exactly once; 26 * in each row numbers are situated in increasing order; 27 * the sum of numbers in the *k*-th column is maximum possible. 28 29 Your goal is to help Alice and find at least one *k*-special table of size *n* × *n*. Both rows and columns are numbered from 1 to *n*, with rows numbered from top to bottom and columns numbered from left to right. 30 31 Input 32 33 The first line of the input contains two integers *n* and *k* (1 ≤ *n* ≤ 500, 1 ≤ *k* ≤ *n*) — the size of the table Alice is looking for and the column that should have maximum possible sum. 34 35 Output 36 37 First print the sum of the integers in the *k*-th column of the required table. 38 39 Next *n* lines should contain the description of the table itself: first line should contains *n* elements of the first row, second line should contain *n* elements of the second row and so on. 40 41 If there are multiple suitable table, you are allowed to print any. 42 43 Examples 44 45 Input 46 47 ``` 48 4 1 49 ``` 50 51 Output 52 53 ``` 54 28 55 1 2 3 4 56 5 6 7 8 57 9 10 11 12 58 13 14 15 16 59 ``` 60 61 Input 62 63 ``` 64 5 3 65 ``` 66 67 Output 68 69 ``` 70 85 71 5 6 17 18 19 72 9 10 23 24 25 73 7 8 20 21 22 74 3 4 14 15 16 75 1 2 11 12 13 76 ```