SPOJ GLASS BEADS

Can anyone explain me how to do this problem using suffix array?
Please.