import collections


class Solution(object):
    def numPairsDivisibleBy60(self, time):
        """
        :type time: List[int]
        :rtype: int
        """
        m_dict, cnt = collections.defaultdict(int), 0

        for t in time:
            r = t % 60
            # don't forget special case 0
            if r == 0:
                cnt += m_dict[0]
            else:
                cnt += m_dict[60 - r]
            m_dict[r] += 1

        return cnt


if __name__ == '__main__':
    print Solution().numPairsDivisibleBy60([60, 60, 60])
    print Solution().numPairsDivisibleBy60([30, 20, 150, 100, 40])
