Math behind three of a kind