Sales by Match

  • + 0 comments
    public static void main(String[] args) {
            try (var br = new BufferedReader(new InputStreamReader(System.in));
                 var bw = new BufferedWriter(new OutputStreamWriter(System.out))) {
                int n = Integer.parseInt(br.readLine().trim());
                String[] socks = br.readLine().trim().split(" ");
                int[] sockCounts = new int[101];
                for (String sock : socks) {
                    int color = Integer.parseInt(sock);
                    sockCounts[color]++;
                }
                int pairs = 0;
                for (int count : sockCounts) {
                    pairs += count >> 1;
                }
                bw.write(String.valueOf(pairs));
                bw.newLine();
                bw.flush();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }