Comments

Great question! Causing collisions for dicts since Python 3.3+ is very challenging. You can see in the note of https://docs.python.org/3/reference/datamodel.html#object.__hash__ that the seeding of the hash function (used by dict) are not predictable since they are "“salted” with an unpredictable random value", unless you set the PYTHONHASHSEED.

I think it is because of s.count( {cx,cy} ), that is not O(1) but O(count_of({cx,cy}) + log(N)), so worst case in an array with all ones and x=2, you get O(N^2) time complexity. I think in C++ you should be going for a unordered_map<pair<int,int>, int> in which the values are the count so you can do the addition in O(1).