/**
 * This function takes three lists of farm animals and concatenates them together.
 * If any of the farms is empty, the function repeats the animals in that farm twice.
 *
 * @param farm1 List of farm animals.
 * @param farm2 List of farm animals.
 * @param farm3 List of farm animals.
 * @return A single list containing all the farm animals, with possible repeated elements.
 */
fun farmAnimals(farm1: List<String>?, farm2: List<String>?, farm3: List<String>?): List<String>? {

    var result = mutableListOf<String>()

    if (farm1 == null && farm2 == null && farm3 == null) {
        return null
    } else if (farm1 == null) {
        val repeatedAnimals = farm2.orEmpty() + farm2.orEmpty()
        result.addAll(repeatedAnimals)
        result.addAll(farm3.orEmpty())
    } else if (farm2 == null) {
        val repeatedAnimals = farm1.orEmpty() + farm1.orEmpty()
        result.addAll(farm1.orEmpty())
        result.addAll(repeatedAnimals)
    } else if (farm3 == null) {
        val repeatedAnimals = farm1.orEmpty() + farm1.orEmpty()
        result.addAll(repeatedAnimals)
        result.addAll(farm2.orEmpty())
    } else {
        result = (farm1 + farm2 + farm3).toMutableList()
    }

    return result
}
/**
 * This function takes three lists of farm animals and concatenates them together.
 * If any of the farms is empty, the function repeats the animals in that farm twice.
 *
 * @param farm1 List of farm animals.
 * @param farm2 List of farm animals.
 * @param farm3 List of farm animals.
 * @return A single list containing all the farm animals, with possible repeated elements.
 */
fun farmAnimals(farm1: List<String>?, farm2: List<String>?, farm3: List<String>?): List<String>? {
/**
 * This function takes three lists of farm animals and concatenates them together.
 * If any of the farms is empty, the function repeats the animals in that farm twice.
 *
 * @param farm1 List of farm animals.
 * @param farm2 List of farm animals.
 * @param farm3 List of farm animals.
 * @return A single list containing all the farm animals, with possible repeated elements.
 */
fun farmAnimals(farm1: List<String>?, farm2: List<String>?, farm3: List<String>?): List<String>? {

    var result = mutableListOf<String>()

    if (farm1 == null && farm2 == null && farm3 == null) {
        return null
    } else if (farm1 == null) {
        val repeatedAnimals = farm2.orEmpty() + farm2.orEmpty()
        result.addAll(repeatedAnimals)
        result.addAll(farm3.orEmpty())
    } else if (farm2 == null) {
        val repeatedAnimals = farm1.orEmpty() + farm1.orEmpty()
        result.addAll(farm1.orEmpty())
        result.addAll(repeatedAnimals)
    } else if (farm3 == null) {
        val repeatedAnimals = farm1.orEmpty() + farm1.orEmpty()
        result.addAll(repeatedAnimals)
        result.addAll(farm2.orEmpty())
    } else {
        result = (farm1 + farm2 + farm3).toMutableList()
    }

    return result
}