Socks problem

Question

Hints

Answer