Taking into account period(length of period equals to count of colors) of states.