defaultdict is faster, not sure why I wasted time with the other implementations. This may introduce a slight overhead of 120 bytes, may switch the lambda function with (bool).