import collections


class Solution(object):
    def canReorderDoubled(self, A):
        """
        :type A: List[int]
        :rtype: bool
        """
        counter = collections.Counter(A)
        mDict = counter

        for k in sorted(counter.keys()):
            if mDict[k] > 0:
                if k >= 0:
                    if 2 * k in mDict:
                        if k == 0:
                            mDict[k] -= mDict[k] / 2 * 2
                            if mDict[k] == 0:
                                del mDict[k]
                        else:
                            n = min(mDict[k], mDict[2 * k])
                            mDict[k] -= n
                            if mDict[k] == 0:
                                del mDict[k]
                            mDict[2 * k] -= n
                            if mDict[2 * k] == 0:
                                del mDict[2 * k]
                    else:
                        return False
                else:
                    if k / 2 in mDict:
                        n = min(mDict[k], mDict[k / 2])
                        mDict[k] -= n
                        if mDict[k] == 0:
                            del mDict[k]
                        mDict[k / 2] -= n
                        if mDict[k / 2] == 0:
                            del mDict[k / 2]
                    else:
                        return False

        return not mDict


if __name__ == '__main__':
    # print Solution().canReorderDoubled([3,1,3,6])
    # print Solution().canReorderDoubled([2,1,2,6])
    # print Solution().canReorderDoubled([4,-2,2,-4])
    # print Solution().canReorderDoubled([1,2,4,16,8,4])
    # print Solution().canReorderDoubled([1,2,4,8,8,4])
    print Solution().canReorderDoubled([0, 0])
    print Solution().canReorderDoubled([0, 0, 0, 0])
