/**
 * Given two sets, find the sum of their common elements.
 *
 * @param set1 The first set.
 * @param set2 The second set.
 * @return The sum of the common elements.
 *
 * Example:
 * val set1 = setOf(1, 2, 3, 4)
 * val set2 = setOf(3, 4, 5, 6)
 * println(sumOfCommonElements(set1, set2)) // Output: 7
 *
 * val set3 = setOf(10, 20, 30)
 * val set4 = setOf(4, 5, 6)
 * println(sumOfCommonElements(set3, set4)) // Output: 0
 */
fun sumOfCommonElements(set1: Set<Int>, set2: Set<Int>): Int {

    // Find the common elements in both sets
    val commonElements = set1.intersect(set2)

    // Initialize the sum
    var commonSum = 0

    // Iterate through each common element and add it to the sum
    for (element in commonElements) {
        commonSum += element
    }

    // Return the sum of the common elements
    return commonSum
}
/**
 * Given two sets, find the sum of their common elements.
 *
 * @param set1 The first set.
 * @param set2 The second set.
 * @return The sum of the common elements.
 *
 * Example:
 * val set1 = setOf(1, 2, 3, 4)
 * val set2 = setOf(3, 4, 5, 6)
 * println(sumOfCommonElements(set1, set2)) // Output: 7
 *
 * val set3 = setOf(10, 20, 30)
 * val set4 = setOf(4, 5, 6)
 * println(sumOfCommonElements(set3, set4)) // Output: 0
 */
fun sumOfCommonElements(set1: Set<Int>, set2: Set<Int>): Int {
/**
 * Given two sets, find the sum of their common elements.
 *
 * @param set1 The first set.
 * @param set2 The second set.
 * @return The sum of the common elements.
 *
 * Example:
 * val set1 = setOf(1, 2, 3, 4)
 * val set2 = setOf(3, 4, 5, 6)
 * println(sumOfCommonElements(set1, set2)) // Output: 7
 *
 * val set3 = setOf(10, 20, 30)
 * val set4 = setOf(4, 5, 6)
 * println(sumOfCommonElements(set3, set4)) // Output: 0
 */
fun sumOfCommonElements(set1: Set<Int>, set2: Set<Int>): Int {

    // Find the common elements in both sets
    val commonElements = set1.intersect(set2)

    // Initialize the sum
    var commonSum = 0

    // Iterate through each common element and add it to the sum
    for (element in commonElements) {
        commonSum += element
    }

    // Return the sum of the common elements
    return commonSum
}