Language: Java


public class Main {


    private void solve(InputReader in, PrintWriter out) {
        int n = in.nextInt();
        long[] arr = new long[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextLong();
        }
        long res = Long.MAX_VALUE;
        long sum = 0;
        for (int i = -n; i <= 0; i++) {
            for (int j = 0; j < n; j++) {
                sum += Math.abs(arr[j] - (i +(j + 1)));
            }
            res = Math.min(res, sum);
            sum = 0;
        }
        out.println(res);

    }


    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        try (
                InputReader in = new InputReader(System.in);
                PrintWriter out = new PrintWriter(System.out)) {
            solve(in, out);
        }
    }


    static class InputReader implements AutoCloseable {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        @Override
        public void close() {

        }
    }

}

Compiler output:
Main.java:5: error: cannot find symbol
    private void solve(InputReader in, PrintWriter out) {
                                       ^
  symbol:   class PrintWriter
  location: class Main
Main.java:39: error: cannot find symbol
        private BufferedReader reader;
                ^
  symbol:   class BufferedReader
  location: class InputReader
Main.java:40: error: cannot find symbol
        private StringTokenizer tokenizer;
                ^
  symbol:   class StringTokenizer
  location: class InputReader
Main.java:42: error: cannot find symbol
        public InputReader(InputStream stream) {
                           ^
  symbol:   class InputStream
  location: class InputReader
Main.java:32: error: cannot find symbol
                PrintWriter out = new PrintWriter(System.out)) {
                ^
  symbol:   class PrintWriter
  location: class Main
Main.java:32: error: cannot find symbol
                PrintWriter out = new PrintWriter(System.out)) {
                                      ^
  symbol:   class PrintWriter
  location: class Main
Main.java:43: error: cannot find symbol
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
                         ^
  symbol:   class BufferedReader
  location: class InputReader
Main.java:43: error: cannot find symbol
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
                                            ^
  symbol:   class InputStreamReader
  location: class InputReader
Main.java:50: error: cannot find symbol
                    tokenizer = new StringTokenizer(reader.readLine());
                                    ^
  symbol:   class StringTokenizer
  location: class InputReader
Main.java:51: error: cannot find symbol
                } catch (IOException e) {
                         ^
  symbol:   class IOException
  location: class InputReader
10 errors