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

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

    total_sum = 0
    for a in range(2, limit + 1):
        b = sum_proper_divisors(a)
        if b != a and sum_proper_divisors(b) == a:
            total_sum += a
    return total_sum