Necklace stones puzzle Given a necklace with color stones (yellow, white, brown, etc.) of at least two different colors, we describe that necklace using letters that correspond to each color, choosing an arbitrary starting point.

We try to answer these questions:


How many distinct colors does the necklace have?
What's the length of the longest segment of contiguous stones of the same color?
If necklace can be cut at any position, removing all contiguous stones of the same color immediately to the left and to the right of the cutting point, what's the biggest amount of stones which could be taken?


Note that the necklace is considered cyclical. Therefore, letters at the start and end of the given input string can form a single sequence (see second test case below).

Test cases

aaaab -&gt; 2 4 5
aabaa -&gt; 2 4 5
uamaaauumaummuauamumummmmua -&gt; 3 4 5


What's the shortest code to achieve this? Any language is welcome.
CJam, 28 bytes

r__&amp;,a\2*e`0f=_2ew::+]::e&gt;S*


Try it online.

How it works

r    e# Read a whitespace-separated token from STDIN.
__   e# Push two copies.
&amp;    e# Intersect two of the copies (removes duplicates).
,a   e# Calculate the length and wrap it in an array.
\    e# Swap the array with the input string.
2*   e# Repeat the input string two times.
e`   e# Perform run-length encoding.
0f=  e# Keep only the repetitions.
_2ew e# Copy and push the overlapping slices of length two.
::+  e# Add the integers in the resulting slices.
]    e# Wrap the entire stack in an array.
::e&gt; e# Compute the maximum of each of the three arrays.
S*   e# Join, separating by spaces.