{"raw_statement":[{"iden":"problem statement","content":"You are given positive integers $N, K$ and a permutation $P = (P_{1}, P_{2}, \\dots, P_{NK})$ of $(1, 2, \\dots, NK)$.\nAlice repeatedly performs the following operation to sort $P$ in ascending order.\n\n*   Choose integers $i$ and $j$ $(i\\neq j)$ where $1 \\leq i, j \\leq NK$, and swap $P_{i}$ and $P_{j}$. If $|i - j|$ is a multiple of $N$, Alice gets $1$ point.\n\nAlice sorts $P$ in ascending order with the minimum number of operations, and under that condition, she maximizes the sum of points she gets.\nOutput the sum of points Alice gets."},{"iden":"constraints","content":"*   $1\\leq N\\leq 500$\n*   $1\\leq K\\leq 10$\n*   $(P_{1}, P_{2}, \\dots , P_{NK})$ is a permutation of $(1, 2, \\dots, NK)$\n*   All input values are integers."},{"iden":"input","content":"The input is given from Standard Input in the following format:\n\n$N$ $K$\n$P_{1}$ $P_{2}$ $\\dots$ $P_{NK}$"},{"iden":"sample input 1","content":"3 2\n1 6 5 3 2 4"},{"iden":"sample output 1","content":"2\n\nFor example, $P$ can be sorted in ascending order with four operations as follows.\n\n*   Perform the operation with $(i, j) = (2, 5)$. After the operation, $P = (1, 2, 5, 3, 6, 4)$.\n*   Perform the operation with $(i, j) = (4, 6)$. After the operation, $P = (1, 2, 5, 4, 6, 3)$.\n*   Perform the operation with $(i, j) = (3, 5)$. After the operation, $P = (1, 2, 6, 4, 5, 3)$.\n*   Perform the operation with $(i, j) = (3, 6)$. After the operation, $P = (1, 2, 3, 4, 5, 6)$.\n\nAmong the above four operations, Alice gets $1$ point from each of the $1$st and $4$th operations, so Alice gets a total of $2$ points.\nThis sequence of operations is one of the ways to sort $P$ in ascending order with the minimum number of operations and maximize the sum of points under that condition, so output $2$."},{"iden":"sample input 2","content":"1 1\n1"},{"iden":"sample output 2","content":"0"},{"iden":"sample input 3","content":"4 6\n10 24 3 4 8 14 5 2 22 9 21 1 15 6 13 23 18 12 7 17 19 16 20 11"},{"iden":"sample output 3","content":"7"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}