题目
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int n = sc.nextInt();sc.nextLine();Map<Integer,Integer> map = new HashMap<>();for(int i=0;i<n;i++) {int x = sc.nextInt();map.put(x, map.getOrDefault(x, 0)+1);}int res = 0;for(Entry<Integer,Integer> entry:map.entrySet()) {if(entry.getKey()!=entry.getValue()) {if(entry.getKey()<entry.getValue()) {res+=(entry.getValue()-entry.getKey());}if(entry.getKey()>entry.getValue()) {res+=entry.getValue();}}}System.out.println(res);sc.close();}
}