/**
 * A function to calculate the total tax owed based on income and tax brackets.
 *
 * @param income an integer representing the total income
 * @param brackets a list of tuples representing the tax brackets, where each tuple
 *                 contains the lower and upper bounds of the bracket (inclusive),
 *                 and the corresponding tax rate for that bracket
 * @return total_tax a float representing the total tax owed
 *
 * Example:
 * calculateTax(50000, listOf(Pair(0, 10000, 0.05), Pair(10000, 50000, 0.1), Pair(50000, 100000, 0.2)))
 * Output: 4000.0
 */
fun calculateTax(income: Int, brackets: List<Triple<Int, Int, Double>>): Double {

    var totalTax = 0.0

    for (bracket in brackets) {
        val (lowerBound, upperBound, taxRate) = bracket

        if (lowerBound < income && income <= upperBound) {
            val taxableAmount = income - lowerBound
            totalTax += taxableAmount * taxRate
        } else if (income > upperBound) {
            val taxableAmount = upperBound - lowerBound
            totalTax += taxableAmount * taxRate
        }
    }

    return totalTax
}
/**
 * A function to calculate the total tax owed based on income and tax brackets.
 *
 * @param income an integer representing the total income
 * @param brackets a list of tuples representing the tax brackets, where each tuple
 *                 contains the lower and upper bounds of the bracket (inclusive),
 *                 and the corresponding tax rate for that bracket
 * @return total_tax a float representing the total tax owed
 *
 * Example:
 * calculateTax(50000, listOf(Pair(0, 10000, 0.05), Pair(10000, 50000, 0.1), Pair(50000, 100000, 0.2)))
 * Output: 4000.0
 */
fun calculateTax(income: Int, brackets: List<Triple<Int, Int, Double>>): Double {
/**
 * A function to calculate the total tax owed based on income and tax brackets.
 *
 * @param income an integer representing the total income
 * @param brackets a list of tuples representing the tax brackets, where each tuple
 *                 contains the lower and upper bounds of the bracket (inclusive),
 *                 and the corresponding tax rate for that bracket
 * @return total_tax a float representing the total tax owed
 *
 * Example:
 * calculateTax(50000, listOf(Pair(0, 10000, 0.05), Pair(10000, 50000, 0.1), Pair(50000, 100000, 0.2)))
 * Output: 4000.0
 */
fun calculateTax(income: Int, brackets: List<Triple<Int, Int, Double>>): Double {

    var totalTax = 0.0

    for (bracket in brackets) {
        val (lowerBound, upperBound, taxRate) = bracket

        if (lowerBound < income && income <= upperBound) {
            val taxableAmount = income - lowerBound
            totalTax += taxableAmount * taxRate
        } else if (income > upperBound) {
            val taxableAmount = upperBound - lowerBound
            totalTax += taxableAmount * taxRate
        }
    }

    return totalTax
}