def amicable_numbers_sum(limit):
    if limit <= 1:
        return 0

    def sum_of_proper_divisors(n):
        if n == 1:
            return 0
        total = 1
        divisor = 2
        while divisor * divisor <= n:
            if n % divisor == 0:
                total += divisor
                other = n // divisor
                if other != divisor:
                    total += other
            divisor += 1
        return total

    divisor_sums = {}
    total_amicable = 0

    for a in range(2, limit):
        if a not in divisor_sums:
            divisor_sums[a] = sum_of_proper_divisors(a)

        b = divisor_sums[a]
        if b != a:
            if b not in divisor_sums:
                divisor_sums[b] = sum_of_proper_divisors(b)
            if divisor_sums[b] == a:
                total_amicable += a

    return total_amicable