신재권 2021. 12. 17. 21:05
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main2012 {

	public static void main(String[] args) throws IOException {
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int N = Integer.parseInt(br.readLine()); 
		int[] arr = new int[N];
		
		for(int i=0; i<N; i++) {
			arr[i] = Integer.parseInt(br.readLine());
		}
		
		Arrays.sort(arr);
		
		long ans = 0;
		for(int i=1; i<=N; i++) {
			ans += Math.abs(arr[i-1] - i);
		}
		
		System.out.println(ans);

	}
}

// 1 1 2 3 5
// 1 2 3 4 5

정렬하는것이 최적의 합