985A.md (2408B)
1 Source: https://codeforces.com/problemset/problem/985/A 2 3 A. Chess Placing 4 5 time limit per test 6 7 1 second 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 You are given a chessboard of size 1 × *n*. It is guaranteed that *n* is even. The chessboard is painted like this: "BWBW...BW". 22 23 Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known that the total number of pieces equals to . 24 25 In one step you can move one of the pieces one cell to the left or to the right. You cannot move pieces beyond the borders of the board. You also cannot move pieces to the cells that are already occupied. 26 27 Your task is to place all the pieces in the cells of the same color using the minimum number of moves (all the pieces must occupy only the black cells or only the white cells after all the moves are made). 28 29 Input 30 31 The first line of the input contains one integer *n* (2 ≤ *n* ≤ 100, *n* is even) — the size of the chessboard. 32 33 The second line of the input contains  integer numbers  (1 ≤ *p**i* ≤ *n*) — initial positions of the pieces. It is guaranteed that all the positions are distinct. 34 35 Output 36 37 Print one integer — the minimum number of moves you have to make to place all the pieces in the cells of the same color. 38 39 Examples 40 41 Input 42 43 ``` 44 6 45 1 2 6 46 ``` 47 48 Output 49 50 ``` 51 2 52 ``` 53 54 Input 55 56 ``` 57 10 58 1 2 3 4 5 59 ``` 60 61 Output 62 63 ``` 64 10 65 ``` 66 67 Note 68 69 In the first example the only possible strategy is to move the piece at the position 6 to the position 5 and move the piece at the position 2 to the position 3. Notice that if you decide to place the pieces in the white cells the minimum number of moves will be 3. 70 71 In the second example the possible strategy is to move  in 4 moves, then  in 3 moves,  in 2 moves and  in 1 move.