'''
keys: 
Solutions:
Similar: 
T:
S:
'''
from typing import List


class Solution:
    # O(1) for S and T
    def getSum(self, a: int, b: int) -> int:
        x, y = abs(a), abs(b)
        # ensure that abs(a) >= abs(b)
        if x < y:
            return self.getSum(b, a)
        
        # abs(a) >= abs(b) --> 
        # a determines the sign
        sign = 1 if a > 0 else -1
        
        if a * b >= 0:
            # sum of two positive integers x + y
            # where x > y
            while y:
                answer = x ^ y
                carry = (x & y) << 1
                x, y = answer, carry
        else:
            # difference of two integers x - y
            # where x > y
            while y:
                answer = x ^ y
                borrow = ((~x) & y) << 1
                x, y = answer, borrow
        
        return x * sign
    
    
    # python specific
    def getSum1(self, a: int, b: int) -> int:
        # 32 bits integer max
        MAX = 0x7FFFFFFF
        # mask to get last 32 bits
        mask = 0xFFFFFFFF
        while b != 0:
            # ^ get different bits and & gets double 1s, << moves carry
            a, b = (a ^ b) & mask, ((a & b) << 1) & mask
        # if a is negative, get a's 32 bits complement positive first
        # then get 32-bit positive's Python complement negative
        return a if a <= MAX else ~(a ^ mask)
    
    
    
    
477c8225230c383b6eb9e583f437280b4fff536d
<mask token>


class Solution:
    <mask token>
    <mask token>

<mask token>


class Solution:
    <mask token>

    def getSum1(self, a: int, b: int) ->int:
        MAX = 2147483647
        mask = 4294967295
        while b != 0:
            a, b = (a ^ b) & mask, (a & b) << 1 & mask
        return a if a <= MAX else ~(a ^ mask)

<mask token>


class Solution:

    def getSum(self, a: int, b: int) ->int:
        x, y = abs(a), abs(b)
        if x < y:
            return self.getSum(b, a)
        sign = 1 if a > 0 else -1
        if a * b >= 0:
            while y:
                answer = x ^ y
                carry = (x & y) << 1
                x, y = answer, carry
        else:
            while y:
                answer = x ^ y
                borrow = (~x & y) << 1
                x, y = answer, borrow
        return x * sign

    def getSum1(self, a: int, b: int) ->int:
        MAX = 2147483647
        mask = 4294967295
        while b != 0:
            a, b = (a ^ b) & mask, (a & b) << 1 & mask
        return a if a <= MAX else ~(a ^ mask)

<mask token>
from typing import List


class Solution:

    def getSum(self, a: int, b: int) ->int:
        x, y = abs(a), abs(b)
        if x < y:
            return self.getSum(b, a)
        sign = 1 if a > 0 else -1
        if a * b >= 0:
            while y:
                answer = x ^ y
                carry = (x & y) << 1
                x, y = answer, carry
        else:
            while y:
                answer = x ^ y
                borrow = (~x & y) << 1
                x, y = answer, borrow
        return x * sign

    def getSum1(self, a: int, b: int) ->int:
        MAX = 2147483647
        mask = 4294967295
        while b != 0:
            a, b = (a ^ b) & mask, (a & b) << 1 & mask
        return a if a <= MAX else ~(a ^ mask)

'''
keys: 
Solutions:
Similar: 
T:
S:
'''
from typing import List


class Solution:
    # O(1) for S and T
    def getSum(self, a: int, b: int) -> int:
        x, y = abs(a), abs(b)
        # ensure that abs(a) >= abs(b)
        if x < y:
            return self.getSum(b, a)
        
        # abs(a) >= abs(b) --> 
        # a determines the sign
        sign = 1 if a > 0 else -1
        
        if a * b >= 0:
            # sum of two positive integers x + y
            # where x > y
            while y:
                answer = x ^ y
                carry = (x & y) << 1
                x, y = answer, carry
        else:
            # difference of two integers x - y
            # where x > y
            while y:
                answer = x ^ y
                borrow = ((~x) & y) << 1
                x, y = answer, borrow
        
        return x * sign
    
    
    # python specific
    def getSum1(self, a: int, b: int) -> int:
        # 32 bits integer max
        MAX = 0x7FFFFFFF
        # mask to get last 32 bits
        mask = 0xFFFFFFFF
        while b != 0:
            # ^ get different bits and & gets double 1s, << moves carry
            a, b = (a ^ b) & mask, ((a & b) << 1) & mask
        # if a is negative, get a's 32 bits complement positive first
        # then get 32-bit positive's Python complement negative
        return a if a <= MAX else ~(a ^ mask)
    
    
    
    