Your code has the same bug mine has - not correctly accounting for the possibility of exactly 3 carts crashing together at an intersection.