Description
On the forest-filled moon of Endor there is, if we are to believe the Guinness Book of Records, the
longest stick in the whole galaxy. On that stick of L meters in length there are N cheerful chameleons.
Each chameleon is moving along the stick with constant speed of 1 m/s in one of two possible directions(left or right) and is colored in one of the possible K colors.
It is known that the chameleons of Endor worship the ancient ant laws that dictate that the walk
along the stick must be continued until the end of the stick is reached (which means getting off it),and when a collision with another chameleon takes place, you must turn 180 degrees and continue
the walk in the opposite direction. Additionally, after a chameleon colored in a moving to the left
collides with a chameleon colored in b moving to the right, the chameleon moving to the left before the collision takes the color of the chameleon moving to the right before the collision (so, color b), while the chameleon moving to the right before the collision takes a new color (a + b) mod K.
If you are given the initial positions, colors and directions of movement of all the chameleons, for each color determine the total trip taken by the chameleons in that color before getting off the