Solution in C.

C is fast.