Nice solution in C.