[Question]
  [
A [bracelet](https://en.wikipedia.org/wiki/Necklace_(combinatorics) "Wikipedia") consists of a number, \$\mathit{N}\$, of beads connected in a loop. Each bead may be any of \$\mathit{C}\$ colours. Bracelets are invariant under rotation (shifting beads around the loop) and reflection (turning the bracelet over).
Here are all \$11\$ bracelets with exactly two beads of each of three different colours. [Source](https://en.wikipedia.org/wiki/Necklace_(combinatorics)#/media/File:Bracelets222.svg "Wikipedia") ([Tilman Piesk](https://commons.wikimedia.org/wiki/User:Watchduck "Wikipedia:user=Watchduck")).
![2-2-2 Bracelets](https://i.stack.imgur.com/CGdzC.png)
A bracelet has \$\mathit{S}\$ stripes if merging all adjacent beads of identical colour until no longer possible would result in a bracelet with \$\mathit{S}\$ beads. In the above picture, the bracelet in the first column has \$3\$ stripes, while those in the second, third, fourth and fifth columns have \$4\$, \$6\$, \$5\$, and \$6\$ stripes, respectively.
Equivalently a bracelet has \$\mathit{S}\$ stripes if precisely \$\mathit{d}\$ neighbouring pairs of beads have different colours, where
$$\mathit{d} =
\begin{cases}
0, & \text{if $\mathit{S}=1$} \\
S, & \text{if $\mathit{S}>1$}
\end{cases}$$
Note: The above picture does not show all stripey bracelets with six beads as it only shows those with *exactly* two of each of three *different* colours - there are \$92\$ distinct bracelets with six beads when choosing from three colours which may be partitioned into sets of stripey bracelets with \$3\$, \$15\$, \$10\$, \$36\$, \$15\$, and \$13\$ members with \$1\$ to \$6\$ stripes, respectively.
### Challenge
Given \$\mathit{N}\$, \$\mathit{C}\$, and \$\mathit{S}\$ output the number, \$|\mathit{B}\_{\mathit{N},\mathit{C},\mathit{S}}|\$, of different \$\mathit{N}\$-bead bracelets with \$\mathit{S}\$ stripes whose beads may be any of \$\mathit{C}\$ colours.
All three of the inputs are positive integers. You may assume that \$\mathit{S} \le \mathit{N}\$.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so try to make the shortest code possible in your programming language of choice when measured in bytes.
### Examples
###### N = 4 beads, C = 3 colours, S = 4 stripes
\$|\mathit{B}\_{4,3,4}| = 6\$
```
-R--G--R--G-
-R--G--R--Y-
-R--G--Y--G-
-R--Y--R--Y-
-R--Y--G--Y-
-G--Y--G--Y-
```
###### N = 5 beads, C = 2 colours, S = 4 stripes
\$|\mathit{B}\_{5,2,4}| = 2\$:
```
-R--R--G--R--G-
-R--G--R--G--G-
```
###### N = 5 beads, C = 4 colours, S = 1 stripe
\$|\mathit{B}\_{5,4,1}| = 4\$:
```
-R--R--R--R-
-G--G--G--G-
-Y--Y--Y--Y-
-B--B--B--B-
```
###### N = 6 beads, C = 3 colours, S = 4 stripes
\$|\mathit{B}\_{6,3,4}| = 36\$:
```
-R--G--G--R--Y--Y-  ⇦ top of column 2 in the image
-R--R--Y--G--G--Y-  ⇦ middle of column 2 in the image
-R--R--G--Y--Y--G-  ⇦ bottom of column 2 in the image
-R--R--R--G--R--G-    (... the rest don't have exactly two of each colour)
-R--R--R--G--R--Y-
-R--R--R--G--Y--G-
-R--R--R--Y--R--Y-
-R--R--R--Y--G--Y-
-R--R--G--R--R--G-
-R--R--G--R--R--Y-
-R--R--G--R--G--G-
-R--R--G--R--Y--Y-
-R--R--G--G--R--Y-
-R--R--G--G--Y--G-
-R--R--Y--R--R--Y-
-R--R--Y--R--Y--Y-
-R--R--Y--G--Y--Y-
-R--G--R--G--G--G-
-R--G--R--Y--Y--Y-
-R--G--G--R--G--G-
-R--G--G--G--R--Y-
-R--G--G--G--Y--G-
-R--G--G--Y--G--G-
-R--G--G--Y--Y--G-
-R--G--Y--Y--Y--G-
-R--Y--R--Y--Y--Y-
-R--Y--G--G--G--Y-
-R--Y--G--G--Y--Y-
-R--Y--G--Y--Y--Y-
-R--Y--Y--R--Y--Y-
-R--Y--Y--G--Y--Y-
-G--G--G--Y--G--Y-
-G--G--Y--G--G--Y-
-G--G--Y--G--Y--Y-
-G--Y--G--Y--Y--Y-
-G--Y--Y--G--Y--Y-
```
###### N = 6 beads, C = 3 colours, S = 6 stripes
\$|\mathit{B}\_{6,3,6}| = 13\$:
```
-R--G--Y--R--Y--G-  ⇦ top of column 3 in the image
-R--G--Y--G--R--Y-  ⇦ middle of column 3 in the image
-R--G--R--Y--G--Y-  ⇦ bottom of column 3 in the image
-R--G--Y--R--G--Y-  ⇦ only of column 5 in the image
-R--G--R--G--R--G-    (... the rest don't have exactly two of each colour)
-R--G--R--G--R--Y-
-R--G--R--G--Y--G-
-R--G--R--Y--R--Y-
-R--G--Y--G--Y--G-
-R--Y--R--Y--R--Y-
-R--Y--R--Y--G--Y-
-R--Y--G--Y--G--Y-
-G--Y--G--Y--G--Y-
```
### Test cases
```
N, C, S, #
1, 1, 1, 1
1, 3, 1, 3
2, 1, 1, 1
2, 1, 2, 0
2, 2, 1, 2
3, 2, 3, 0
3, 5, 2, 20
4, 2, 4, 1
4, 3, 4, 6  * see above
5, 2, 4, 2  * see above
5, 3, 4, 15
5, 4, 1, 4  * see above
5, 8, 1, 8
5, 8, 2, 112
5, 8, 3, 336
5, 8, 4, 1400
5, 8, 5, 1680
6, 3, 1, 3
6, 3, 2, 15
6, 3, 3, 10
6, 3, 4, 36  * see above
6, 3, 5, 15
6, 3, 6, 13  * see above
6, 4, 3, 40
6, 5, 1, 5
6, 5, 2, 50
6, 5, 3, 100
6, 5, 4, 410
6, 5, 5, 510
6, 5, 6, 430
```
---
Brownie points for matching or beating \$18\$ bytes in [Jelly](https://github.com/DennisMitchell/jelly "GitHub")
  
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), ~~44~~ 42 bytes
A function taking three curried arguments, call as `f[N][C][S]`.
```
(+/=)@+/~-1=':+?{a@*<a,:|'a:(#x)':x,x}'+!#
```
[Try it online!](https://ngn.codeberg.page/k#eJwtzEEKwyAUBNC9p7DJQq0pEv0/FNNQoftueoJscoIshLQ9e3+mQXgO4+CSrQ+TKz58L/1ksr9vcznf5i6/zZxtW53Jtasf40+tUmu2vZYz9jqJEXk3inKPSUwiS0OSSUwiI/ORSZasr4cRJkiQxwH/70aYIMH/6yASesaSseSjIchwcEo1T/3QL902au3MUoJZf6jSMIk=)
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~23~~ 21 (20†) [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
LIãεā._Dí«Σ}н}ÙʒγgQ}g
```
Inputs in the order \$C,N,S\$.
[Try it online](https://tio.run/##ATgAx/9vc2FiaWX//0xJw6POtcSBLl9Ew63Cq86jfdC9fcOZypLOs2dRfWf//zMKNAo0/y0tbm8tbGF6eQ) or [verify halve of the test cases](https://tio.run/##yy9OTMpM/V9WGZSg5Gx7eL@OH4gIBhIKj9omKSjZVyaEhf73iTi8@NzWI4168S6H1x5afW5x7YW9tYdnnpp0bnN6ZGBt@n@d/9HRxjomOiaxOtFGOqZg2gRIGwJpYx0zMB9Em8XqKEQb6hhCJSC0oY4RnDYCGwDhG@kY6xgDaVMgDRE3gRoEsiD2v65uXr5uTmJVJQA) (the test cases with larger \$N\$ time out).
**Explanation:**
Step 1: Get a list of all possible bracelets of size \$N\$ using up to \$C\$ amount of colors:
```
L           # Push a list in the range [1, first (implicit) input C]
 Iã         # Take the cartesian product with the second input N
```
[Try just step 1 online.](https://tio.run/##yy9OTMpM/f/fx/Pw4v@2So65@aV5JQr5aQpJRYnJqTmpJcUKRam5iZl5mXnpVgpK9un2/425TLhM/uvq5uXr5iRWVQIA)
Step 2: Only keep unique bracelets by removing rotations and reflections:
```
ε           # Map over each inner list:
 ā._        #   Get a list of all its rotations:
 ā          #    Push a list in the range [1,length] (without popping)
  ._        #    Rotate the original list each value amount of times towards the left
    D       #   Duplicate this list of rotations
     í      #   Reverse each inner list
      «     #   Merge the two lists together
       Σ}   #   Sort the list of lists - † should have been just {
         н  #  Only keep the first one
}Ù          # After the outer map: uniquify the list of lists
```
[Try just the first 2 steps online.](https://tio.run/##AVUAqv9vc2FiaWX//0xJw6POtcSBLl9Ew63Cq86jfdC9fcOZ/z0iQW1vdW50IG9mIGJyYWNlbGV0cyByZW1haW5pbmc6ICI/Zz//Mwo0CjT/LS1uby1sYXp5)
Step 3: Only keep bracelets with \$S\$ amount of stripes:
```
ʒ           # Filter the lists by:
 γ          #  Split it into groups of equal adjacent items
  g         #  Pop and push the length
   Q        #  Check if it's equal to the third (implicit) input S
}           # Close the filter
```
[Try just the first 3 steps online.](https://tio.run/##AVwAo/9vc2FiaWX//0xJw6POtcSBLl9Ew63Cq86jfdC9fcOZypLOs2dRff89IkFtb3VudCBvZiBicmFjZWxldHMgcmVtYWluaW5nOiAiP2c//zMKNAo0/y0tbm8tbGF6eQ)
Step 4: Output the amount of valid stripey bracelets remaining:
```
g           # Pop and push the length
            # (which is output implicitly as result)
```
† - The `Σ}` (sort-by builtin without implementation) should have been `{` (sort builtin) for -1 byte, but due to some weird bug it doesn't work in this case.. :/ It does change the order somewhat, but definitely not to the expected lexicographical order..  
[Here an example output for the expected vs actual sorted rotations+reflections of a sample bracelet.](https://tio.run/##yy9OTMpM/f//SKNevMvhtYdWcyk5lxYVpeaVWCkoKNm7KCjocCm5VhSkJpekplhBRM4trgUKOiaXlCbmAFVBBKt1/v@PNtQx1jHRMYr9r6ubl6@bk1hVCQA)
[Answer]
# [Python 3](https://docs.python.org/3/), ~~148~~ 147 bytes
```
lambda N,C,S:sum(t==t[j::k]+t[:j:k]for*t,j,k in product(*map(range,[C]*N+[N]),[1,-1])if(len([*groupby(t*2)])//2or 1)==S)/N/2
from itertools import*
```
[Try it online!](https://tio.run/##PY5Bb6MwEIXv/hWTU2zqbbANKELiUFXqMZfujeVAAnRJwUa2c4ii/Pbs2KRrC31vPG@Gt1z9X6PVY6j@PKZ2PnYtHPg7/yzdZaa@qnx9Lsvv5sXX5Rk5GJt4fubfMGpYrOkuJ0@TuV2obfVXz@v3Jjm81IeG8VrwX6Jh40CnXtM6@bLmshyv1CeSNWy3k8aCYFX1yXaHnSSDNTOMvrfemMnBOC/G@uSxEtzVkWPbQQUf7eR6gjlgGnUfYmDv1flu1CUBPJqfuOMGrSHWqD0Pxle3TKOnjEXPOMBAo5HBpgKzToazWJygw3agN33ntxN@7o4pbz/@@6a6mfuW/Z9YY/22l57gWm18eFkXrsu2b9MEvnfewdI613ebLXsIiJcIUEhF5LMOlJAioyIKqbBWkKOSKckQGRozfM6gIHmsJTLUIkeBgAy5R@4jcZeQUSlQqogKXVmaRpmDKPYpKZ5ZAmVYFQQ@rR38YRFF/tMqQARzTBI82IA8UkK@PoTpVWWQiVXhfSqcVek/ "Python 3 – Try It Online")
-1 Thanks to [Jonathan Allan](https://codegolf.stackexchange.com/users/53748/jonathan-allan)
Ungolfed:
```
from itertools import product
def f(N,C,S):
    z = 0
    for t in product(range(C),repeat=N):
        if sum(t[i] != t[i-1] for i in range(N)) == S*(S>1):
            for i in range(N):
                u = t[i:]+t[:i]
                z += t == u
                z += t[::-1] == u
    return z // (2*N)
```
Uses [Burnside's lemma](https://en.wikipedia.org/wiki/Burnside%27s_lemma).
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 15 bytes
```
ṗµṙJ;U$Ṃ)QŒgẈċ⁵
```
[Try it online!](https://tio.run/##ASsA1P9qZWxsef//4bmXwrXhuZlKO1Uk4bmCKVHFkmfhuojEi@KBtf///zP/Nf80 "Jelly – Try It Online")
Port of @Kevin Cruijssen's 05AB1E answer, so upvote that!
## Explanation
```
ṗµṙJ;U$Ṃ)QŒgẈċ⁵ - Dyadic link taking C, N and S as the third command-line argument
ṗ               - C cartesian-power N (C implicitly converted to range [1..C])
 µ      )       - Over each X:
   J            -  Get list [1, len(X)]
  ṙ             -  For each Y in that, rotate X left by Y
      $         -  Last two links as a monad:
     U          -   Reverse each
    ;           -   Concatenate
       Ṃ        -  Minimum
         Q      - After map, uniquify
          Œg    - Split into groups of adjacent equal elements (vectorizes)
            Ẉ   - Length of each
             ċ⁵ - Count occurences of the third input (S)
```
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 18 bytes
```
ɾ↔ƛż¨VǓ:RJg;UvĠvLO
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyJQIiwiIiwiyb7ihpTGm8W8wqhWx5M6UkpnO1V2xKB2TE8iLCIiLCIzXG41XG40Il0=)
Same as my Jelly answer, so ports 05AB1E.
[Answer]
# [Python](https://www.python.org), 153 bytes
```
lambda n,c,s:len({a for x in product(*[range(c)]*n)if s==len([*groupby(a:=min(x[k::r]+x[:k:r]for k in range(n)for r in[-1,1]))])})
from itertools import*
```
[Attempt This Online!](https://ato.pxeger.com/run?1=JY5NCoMwFIT3PUWWeTYupC2UgCdJXcSf2KC-hGcEpfQgpRuhtNuep7ep4mrgY-Zjnh8_havD-WXSy3sIJj7_Hq3u8lIzFIXoZVshv2lmHLGRWWSeXDkUgUeKNNYVLyCLEKxhfZquXRXV5AafT1zLtLPIR9VISdl-VLJZchU1q2ibI6yAFqDiRCQZQAZ32BlyHbOhouBc2zPbeUch2g5-PVkM3PCTOIgjwEbnecs_)
-6 thanks to Jonathan Allan
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 54 bytes
```
LhSsm,.<_bd.<bdlbV.CUEEV.pNI!/YyHIqQ|ltr8+HhH1 aYyH;lY
```
[Try it online!](https://tio.run/##K6gsyfj/3ycjuDhXR88mPilFzyYpJScpTM851NU1TK/Az1NRP7LSw7MwsCanpMhC2yPDw1AhEShinRP5/78RlymXMQA "Pyth – Try It Online")
Takes three inputs in order of `S`, `C`, `N`
[Answer]
# Python3, 299 bytes:
```
R=range
def f(N,c,S):
 q,p,K=[(N,S,[])],[],0
 while q:
  n,s,r=q.pop(0)
  if(t:=[r[k:]+r[:k]for k in R(N)]+[r[::-1]])!=n+s==0<(r[0]-r[-1]or S==1)>0==any(j in p for j in t):p+=t;v=r;K+=S==sum(v!=(v:=x)for x in r)
  elif n:q+=[(n+~j,s-1,r+[i]*-~j)for i in{*R(c)}-{([-1]+r)[-1]}for j in R(n)]
 return K
```
[Try it online!](https://tio.run/##ZVJNb@IwED3Xv2LKHrCJQfkWStd72SNSD3DM5hBKsjUfxjgp26pq/zo7NgmtQIom7z2/8Yw1o9/a572KptqcTnNhSvW3Iquqhpo@8ie@YBmBA9d8JnIUFjwvWIGB@wT@PcttBQc0gOINN@Iw0XtNfYaCrGmbidzkm6zwTJ5tinpvYANSwZw@ssLDoywbB0XB7oXyGiH8n9TkfjE2OaroXQgRsF@@EKV6o2ubqMHe4WDLMu2J9uEozMPME@htXnb0eC/oMROvzPperc/YXqqtrEFlBw@foLzPNW/GATdeLovR@HPtzBLN76M5fWIf43dqO/AMs7@PS8k5VawgYKr2xSiYneRO702LnGgjVUtrGvOIx4xdeMLDKx7z4BtPr/yWp8jbqmkbEDAYDB45/Oaw4PCDBBy6z8LIwYiEX@oZYvQt7BiJHIysiiFxLPRJ7EBs82J3jDEFGEFTVVAu98eKJL0lvNHP/iCxOHaF4hvP1OnTDtp2grAjmB5FaUdsfuz7HcMYpFOfpF9PPMPQ1Ttje9JbbPdXjZ8Pkm8JGIPoxtQ93N2UuGJJB7FY0suuWE8wJQ56Yr8LsfdFPo6M9PsEbo6TRm9lS4d/1JDlQVZk5G5UcljifHelpjh5jjs0qaValdst@lbekIPENbgrm6bCDavpqGQgBCxP/wE)
Completes all the test cases in <20 seconds.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), ~~63~~ 56 bytes
```
ＮθＮηＮζＩＬΦＥＸηθＥθ﹪÷ιＸηλη∧⁼∧⊖ζζＬΦι⁻λ§ι⊕μ⁼ι⌊Ｅθ⌊Ｅ⟦ι⮌ι⟧Ｅθ§ν⁺λπ
```
[Try it online!](https://tio.run/##XU9Na8MwDL3vV/gog3ta2aWnsm4QaEvZtfTgxWIx2Eri2Nnon3flfqYT2PKT9J6e60aHutUu54q6FLfJf2OAXi5eprj5h4@Md8FShHc9RFgj/cQGPq2L3NzoDnbtb6Ep0UslSqHn1JrkWqgoruxoDYJV4j7nJA82stxLMvDRJ@0GKM8V1gE9UkTDe5Uo53kh62wspQEck2NFBv9KraIH0ctzKHEVvlCsTx5u7iZwz@0vHDEMbFIe7j@4iRMbd5d9nZzGIuc38SrmeTa6Ew "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
ＮθＮηＮζ
```
Input `N`, `C` and `S`.
```
ＩＬ
```
Output the number of ...
```
ΦＥＸηθＥθ﹪÷ιＸηλη
```
... all of the rotations and reflections of all of the bracelets of `N` beads with `C` colours, filtered where...
```
∧⁼∧⊖ζζＬΦι⁻λ§ι⊕μ
```
... they have `S` stripes, and ...
```
⁼ι⌊Ｅθ⌊Ｅ⟦ι⮌ι⟧Ｅθ§ν⁺λπ
```
... the bracelet is in its canonical form, which is the minimum of its rotations and reflections, i.e. limiting the output to unique bracelets.
[Answer]
# JavaScript (ES7), 158 bytes
```
(n,c,s)=>(F=k=>k--&&([...p=[...Array(n)].map((_,i)=>q=k/c**i%c|0)].some(v=>F[p=[p.pop(t+=q!=v),...p]]|F[[...p].reverse(q=v)],t=0)|t+!t-s?0:F[p]=1)+F(k))(c**n)
```
[Try it online!](https://tio.run/##ZY/fboIwGMXvfYpvidNWC@OvF5pidjFegjSTdLg5FJASkkV5gyW72eX2HnseX2CPwEqRBWPSnLS/nnO@9jUsQ8HzTVZoSfoU1Wtao4RwIjD1kE9j6sWaNhqhQNf1jDZ6n@fhG0ow03dhhtAj2UjrnsZ3fDLZ3PKjIW9EuotQST0/kJlMz9IMFVO6v6ElJk0RY0c/UJVMz6MyykWE9vKSkYIa@FhMbwpNLI25zDNq4qmPYoyRHJDgehEMAAIwSbeAkY7Yitgdsa48LZFq9MgZdsRWxO555N5V0PpHjjo7vWpHZaTOOuJ2HqtHWo/p9pCj5jsdmV39oyVWP9aixmdcouYZs0vkXgelmv368@Nl14AN9HWaP4T8BaEAEgKcgCCQRwIYBuoBTxORbiN9mz6jFRoekorA8MCVigqD5slNChTW6JzGVUuoalnC@Pfn4/T1KXUMcxifvt/H1QrjRf0H "JavaScript (Node.js) – Try It Online")
### Commented
```
(n, c, s) =>            // outer function taking the parameters
( F = k =>              // inner recursive function taking a counter k
  k-- && (              // stop when k = 0 / decrement it
    [... p =            // build an array p[]
      [...Array(n)]     // of n elements,
      .map((_, i) =>    // filled with:
        q =             //   values from 0 to c - 1
        k / c ** i % c  //   with the last one saved in q
        | 0             //
      )                 // end of map()
    ].some(v =>         // for each value v in a copy of this array:
      F[                //   test whether we've already generated
        p = [           //     a rotation of the same pattern
          p.pop(        //     we use pop() to compute the rotations
            t += q != v //     and, at the same time, we keep track of
          ),            //     the number of stripes in t by counting
          ...p          //     runs of equal beads
        ]               //
      ] |               //
      F[                //   test whether we've already generated
        [...p].reverse( //     a reflection of the same pattern
          q = v         //     save the last bead in q
        )               //
      ],                //
      t = 0             //   start with t = 0
    ) |                 // end of some(); if it was truthy or the
    t + !t - s ?        // number of stripes is not the expected one:
      0                 //   leave the final result unchanged
    :                   // else:
      F[p] = 1          //   increment the final result and mark the
                        //   pattern as generated
  ) + F(k)              // add the result of a recursive call
)(c ** n)               // initial call to F
```
]