• + 0 comments

    Scanner s = new Scanner(System.in); int t = s.nextInt();

        // Stream to read and process input pairs
        Set<String> uniquePairs = new HashSet<>();
    
        // We use a Stream to process the input and maintain uniqueness
        IntStream.range(0, t).forEach(i -> {
            String left = s.next();
            String right = s.next();
    
            // Create the two possible pair strings
            String pair1 = left + " " + right;
            String pair2 = right + " " + left;
    
            // Add the lexicographically smaller of the two pairs to the set
            uniquePairs.add(Stream.of(pair1, pair2)
                                  .min(String::compareTo) // Get the lexicographically smaller string
                                  .get());
    
            // Print the current number of unique pairs
            System.out.println(uniquePairs.size());
        });