/**
 * This function takes a list of animals, their age and weight criteria, and returns the total number of qualified
 * animals. The function considers the subtraction assignment operator and precedence of logical operators.
 *
 * @param animals A list of dictionaries containing animal information.
 * @param age_min The minimum age criteria for animals.
 * @param age_max The maximum age criteria for animals.
 * @param weight_min The minimum weight criteria for animals.
 * @param weight_max The maximum weight criteria for animals.
 * @return The total number of qualified animals based on the given criteria.
 */
fun calculateOperations(animals: List<Map<String, Any>>, ageMin: Int, ageMax: Int, weightMin: Int, weightMax: Int): Int {

    var totalQualified = 0

    for (animal in animals) {
        val age = animal["age"] as Int
        val weight = animal["weight"] as Int

        totalQualified -= ((age >= ageMin && age <= ageMax).compareTo(true) - (weight >= weightMin && weight <= weightMax).compareTo(true))
    }

    return totalQualified
}

// Example usage
val animalsList = listOf(
    mapOf("name" to "Dog", "age" to 5, "weight" to 20),
    mapOf("name" to "Cat", "age" to 2, "weight" to 10)
)
/**
 * This function takes a list of animals, their age and weight criteria, and returns the total number of qualified
 * animals. The function considers the subtraction assignment operator and precedence of logical operators.
 *
 * @param animals A list of dictionaries containing animal information.
 * @param age_min The minimum age criteria for animals.
 * @param age_max The maximum age criteria for animals.
 * @param weight_min The minimum weight criteria for animals.
 * @param weight_max The maximum weight criteria for animals.
 * @return The total number of qualified animals based on the given criteria.
 */
fun calculateOperations(animals: List<Map<String, Any>>, ageMin: Int, ageMax: Int, weightMin: Int, weightMax: Int): Int {
/**
 * This function takes a list of animals, their age and weight criteria, and returns the total number of qualified
 * animals. The function considers the subtraction assignment operator and precedence of logical operators.
 *
 * @param animals A list of dictionaries containing animal information.
 * @param age_min The minimum age criteria for animals.
 * @param age_max The maximum age criteria for animals.
 * @param weight_min The minimum weight criteria for animals.
 * @param weight_max The maximum weight criteria for animals.
 * @return The total number of qualified animals based on the given criteria.
 */
fun calculateOperations(animals: List<Map<String, Any>>, ageMin: Int, ageMax: Int, weightMin: Int, weightMax: Int): Int {

    var totalQualified = 0

    for (animal in animals) {
        val age = animal["age"] as Int
        val weight = animal["weight"] as Int

        totalQualified -= ((age >= ageMin && age <= ageMax).compareTo(true) - (weight >= weightMin && weight <= weightMax).compareTo(true))
    }

    return totalQualified
}

// Example usage
val animalsList = listOf(
    mapOf("name" to "Dog", "age" to 5, "weight" to 20),
    mapOf("name" to "Cat", "age" to 2, "weight" to 10)
)