[Question]
  [
**Disclaimer: the content of this post *is not medical information* and should not be used for any medical purpose, as it is deliberately oversimplified for the purpose of the challenge.**
There are several different strains of [*Neisseria meningitidis*](https://en.wikipedia.org/wiki/Neisseria_meningitidis), the bacterium that causes meningococcal meningitis. Vaccines are available for strains A, B, C, W, and Y. They are available in three combinations.
The first is the quadrivalent meningococcal ACWY vaccine. As the name implies, this protects against strains A, C, W, and Y, but not B.
The second is the meningococcal B vaccine, which protects only against strain B.
The third is the pentavalent meningococcal ABCWY vaccine, which combines ACWY and B to protect against all five strains. Receiving the ABCWY vaccine is equivalent to receiving ACWY and B simultaneously.
However, while only one dose of ACWY is needed for full vaccination (we're ignoring boosters), two doses of B are needed. ABCWY counts as one dose of ACWY and one dose of B.
Write a program or function that accepts either an array of strings, or several strings delimited by a string of your choice. (The empty string is an acceptable delimiter; i.e., you may accept the strings run together.) These strings will be from the set `ACWY`, `B`, and `ABCWY`. Return or print `ACWY` if at least one dose of ACWY has been given but zero or one doses of B have been given, `B` if at least two doses of B but no doses of ACWY have been given, and `ABCWY` if at least one dose of ACWY and at least two doses of B have been given. If neither vaccine has been fully received, output the empty string. "Overvaccination" is allowed; `ABCWY ABCWY ACWY` should become `ABCWY`. You do not have to support invalid inputs.
| Input | Output |
| --- | --- |
| `ABCWY B` | `ABCWY` |
| `ABCWY` | `ACWY` |
| `B` | [empty string] |
| `B B` | `B` |
| `ACWY B B` | `ABCWY` |
| `ACWY B` | `ACWY` |
 
  
[Answer]
# [Perl 5](https://www.perl.org/) `-p`, 28 bytes
```
$_=A x/A/.B x/B.*B/.CWY x/A/
```
[Try it online!](https://tio.run/##K0gtyjH9/18l3tZRoULfUV/PCUg56Wk56es5h0eChf7/d3QCsZ24wDSXE5cTiA0WgjP@5ReUZObnFf/X9TXVMzA0@K9bkAMA "Perl 5 ‚Äì Try It Online")
[Answer]
# Google Sheets, 64 bytes
```
=join(,ifna(filter({"A","B","CWY"},search({"A","B*B","A"},A1))))
```
Put the input in cell `A1` and the formula in cell `B1`.
Uses the `search()` with `*` wildcard method of [JvdV's Excel answer](https://codegolf.stackexchange.com/a/268657/119296).
The same can be done without arrays using simple string concatenation and regexes (**81 bytes**):
```
=let(a,regexmatch(A1,"A"),if(a,"A",)&if(regexmatch(A1,"B.*B"),"B",)&if(a,"CWY",)
```
Implementation of the same in JavaScript (**62 bytes**):
```
t=>(a=/A/.test(t)?'A':'')+(/B.*B/.test(t)?'B':'')+(a?'CWY':'')
```
(-4 bytes thanks to [noodle man](https://codegolf.stackexchange.com/users/108687/noodle-man))
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 6 bytes
```
≈ì-‚ÄùBQ·π¢
```
[Try it online!](https://tio.run/##y0rNyan8///oZN1HDXOdAh/uXPT/4e4th9sfNa2J/P/f0ck5PNKJC0xxOXE5AZkgASgFAA "Jelly ‚Äì Try It Online")
A monadic link taking a string with no delimiter and returning a string.
## Explanation
```
≈ì-‚ÄùB   | Set difference with "B"
    Q  | Uniquify
     ·π¢ | Sort
```
[Answer]
# [Python 3.8 (pre-release)](https://docs.python.org/3.8/), 54 bytes
```
lambda s:"A"*(x:="C"in s)+"B"*(s.count("B")>1)+"CWY"*x
```
[Try it online!](https://tio.run/##K6gsycjPM7YoKPqfpmAb8z8nMTcpJVGh2ErJUUlLo8LKVslZKTNPoVhTW8kJKFCsl5xfmleiAeRo2hkCBZ3DI5W0Kv4XFGUCRdM0lBydgCIKQFlNLlQxFBFUeSd09WAjsAoChf4DAA "Python 3.8 (pre-release) ‚Äì Try It Online")
# [Python 3](https://docs.python.org/3/), 59 bytes
```
def f(s):x="C"in s;return"A"*x+"B"*(s.count("B")>1)+"CWY"*x
```
[Try it online!](https://tio.run/##K6gsycjPM/7/PyU1TSFNo1jTqsJWyVkpM0@h2LootaS0KE/JUUmrQlvJSUlLo1gvOb80r0QDyNG0M9TUVnIOjwRK/i8oygSKpmkoOToBRRSAsppcqGIoIqjyTujqwUZgFQQK/QcA "Python 3 ‚Äì Try It Online")
[Answer]
# [Nekomata](https://github.com/AlephAlpha/Nekomata), 6 bytes
```
"B"‚àïuo
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70iLzU7PzexJHFZtJJurlLsgqWlJWm6FiuUnJQedUwtzV9SnJRcDBVccFNLydHJOTzSSYkLwgDSILYTWAAkAWcoQbQAAA)
A port of [@Nick Kennedy's Jelly answer](https://codegolf.stackexchange.com/a/268624/9288).
```
"B"‚àïuo
"B"‚àï    Set difference with "B"
    u   Uniquify
     o  Sort
```
[Answer]
# JavaScript (ES6), 55 / 48 / 41 bytes
Expects a space-separated string.
```
s=>[...new Set(s.replace("B",""))].sort().join``.trim()
```
[Try it online!](https://tio.run/##fc7BCoJAEMbxe08xzGkXanwCg7ZH6BAhgmKjKLq77C5FT7@ZWQRKx2F@8P278lb6yrU27LS5cqzT6NN9RkSa73DiIDw5tn1ZsUCFW0Qpc/LGBSGpM60uCgquHYSMldHe9Ey9aUQt8KCO5wsoBCkhSWA6N2sGAT5mhajXG74k48GGB/hxUzf5AsPM31gt9qakEf1rmrN/muIT "JavaScript (Node.js) ‚Äì Try It Online")
Or **[48 bytes](https://tio.run/##fc5BCsIwEIXhvacIs0pApyeoYDyCiyKl0FKnpSVmQhIUTx9t60JocXYDH7x/bB5NaP3g4sHyjVKXp5AfS0S09BQXijKgJ2ealiRo2AMoVWFgH6XCkQdb16llG9gQGu5lJ@Gkz8VVf5zIMjE/uy0B4is2gAYx3QJKurv4EiH6wfbVii52oXq1NKX8b5ljf1rSGw)** if we take a string with no delimiter.
Or **[41 bytes](https://tio.run/##fc5BCsIwEIXhvacIs0pApyeoYDyCC5HSRYjTUqlJyATF00fbuBBanN3AB@@/mYdhG4eQds5fKXd15nrfIKKjpzhRkoyRwmgsSdCwBVCqRfYxSZWtd@xHwtH3spNw0MfzRX@AqCoxP5s1AeIrVoAGMV0BDd1DeglOcXB9u6DFFqoXS1PK/5Y59qclvwE)** if we return an array.
## Method
Given the input string, e.g. `"ABCWY ACWY B"`:
* remove the first "B" ‚Üí `"ACWY ACWY B"`
* turn the string into a set ‚Üí `Set { 'A','C','W','Y',' ','B' }`
* turn the set into an array ‚Üí `[ 'A','C','W','Y',' ','B' ]`
* sort it in lexicographical order ‚Üí `[ ' ','A','B','C','W','Y' ]`
* turn it back into a string ‚Üí `" ABCWY"`
* remove the leading space, if any ‚Üí `"ABCWY"`
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 16 bytes
```
\W
1`B
O`.
D`.
```
[Try it online!](https://tio.run/##K0otycxL/K@q4Z7wPyaci8swwYmLyz9Bj8slQe//f0cn5/BIBScuMM3lxOUEYoOF4AwA "Retina 0.8.2 ‚Äì Try It Online") Link includes test cases. Accepts any non-`\w` characters as a delimiter. Explanation:
```
\W
```
Join the words together.
```
1`B
```
Delete the first `B`, if any.
```
O`.
```
Sort the letters.
```
D`.
```
Deduplicate the letters.
[Answer]
# [Bash](https://www.gnu.org/software/bash/) + [core utilities](https://www.gnu.org/software/coreutils/), 37 bytes
```
sed s/B//|grep -o .|sort -u|tr -d \\n
```
### Explanation
```
sed s/B// | # remove the first occurrence of B
grep -o . | # insert a newline after every character
sort -u   | # sort lines and remove duplicates
tr -d \\n | # remove newlines inserted for sorting
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~¬†8¬†~~ 7 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
Note while I did eventually think of using `≈ì-` to avoid a byte, I now see that [Nick Kennedy actually got there first](https://codegolf.stackexchange.com/a/268624/53748)!
```
F≈ì-‚ÄùBQ·π¢
```
A monadic Link that accepts a list of lists of characters (the vaccines) and yields a list of characters (the fully vaccinated).
**[Try it online!](https://tio.run/##y0rNyan8/9/t6GTdRw1znQIf7lz0////aCVH5/BIJR0FJSelWAA "Jelly ‚Äì Try It Online")** Or see the [test-suite](https://tio.run/##y0rNyan8/9/t6GTdRw1znQIf7lz0/@HuLYe26jzcselwu0qWw6OmNY8a9ykpabr//@/o5BweqeDEBaa5nLicQGywEJwBkVOAkiBljjAWAA "Jelly ‚Äì Try It Online").
### How?
```
F≈ì-‚ÄùBQ·π¢ - Link: list of strings (from "B", "ACWY", "ABCWY"), Vaccinations
F       - flatten
 ≈ì-‚ÄùB   - multiset difference with 'B'
     Q  - deduplicate
      ·π¢ - sort
```
---
Alternative [TIO](https://tio.run/##y0rNyan8///oZN1HDXOdDs9wTPv/cPeWQ1t1DrdnOTxqWvOocZ@Skqb7//@OTs7hkQpOXGCay4nLCcQGC8EZEDkFKAlS5ghjAQA "Jelly ‚Äì Try It Online"):
Taking a non `[A-Z]` separating string (like `" "` or `", "`, etc):
```
≈ì-‚ÄùB√òAf
≈ì-‚ÄùB     - multiset difference with 'B'
    √òAf  - "ABC...XYZ" filter keep
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 6 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
'B√µ.;√™
```
Port of [*@NickKennedy*'s Jelly answer](https://codegolf.stackexchange.com/a/268624/52210).
[Try it online](https://tio.run/##yy9OTMpM/f9f3enwVj3rw6v@/3d0Do90cgIA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9TVmmvpPCobZKCkn3lf3Wnw1v1rA@v@q/z39HJOTzSiQtMcTlxOQGZIAEoBQA).
**Explanation:**
```
   .;   # In the (implicit) input-string, replace the first
'B     '# "B"
  √µ     # with an empty string ""
     √™  # Then sort and uniquify the characters of the string
        # (which is output implicitly)
```
[Answer]
# Excel ms365, ~~64~~63 bytes
New:
```
=CONCAT(IFERROR(MID(A1,SEARCH({"A","B*B","C"},A1),{1,1,3}),""))
```
Old:
```
=CONCAT(REPT({"A","B","CWY"},COUNTIF(A1,{"*A*","*B*B*","*A*"})))
```
[Answer]
# Python, 50 bytes
```
lambda s:''.join(sorted(set(s.replace('B','',1))))
```
Another port of [@NickKennedy's answer](https://codegolf.stackexchange.com/a/268624/52210), approximately. Python doesn't have a built-in multiset or corresponding set-difference operator; it does have `collections.Counter`, but that takes way too much setup. Instead, I just remove up to one `B` from the input before uniquifying and sorting (and producing a string from the resulting list). This works in both Python 2 and Python 3. The `count` argument for the `replace` method of strings is not commonly discussed, but it's clearly documented.
[Answer]
# [Ruby](https://www.ruby-lang.org/), 26 bytes
```
->s{s.sub(?B,'').chars|[]}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1664ulivuDRJw95JR11dUy85I7GouCY6tvZ/gUJatJKjk3N4pIKTkl46SI2SgpKOkpJmLKeyAidYhguhCJsSuApsBkSn5haUVCoUlxRl5qXHQtVhtcoJag3YKQQdg9PBQIn/AA "Ruby ‚Äì Try It Online")
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 44 bytes
```
s=>s.sort().filter(x=>!~(s[x]=~-s[x]),s.B=1)
```
[Try it online!](https://tio.run/##hY9BCsIwEADvvmLNKQG7xQekYHyESMih1LRUalOyQeqlX49Ei3po8bQszLCz1/JeUuXbIWS9u9hYy0iyICTnAxdYt12wno@y2E6c9GjklKUhdoRK7kWsXE@us9i5htdcIyI7qOPprBgYISDP4bVu1jgG8AFXOJUY@HLa3obwAAq@7RuzaMzKLKjF6ylSsb@R719@G@MT "JavaScript (Node.js) ‚Äì Try It Online")
# [JavaScript (Node.js)](https://nodejs.org), 49 bytes
```
s=>[...'ABCWY'].filter(x=>s.split(x)[x=='B'?2:1])
```
[Try it online!](https://tio.run/##fc5BC8IgFMDxe5/i4UU95Khj4CL7EBGyw1huGKZDJezTWzgWwUbHx/s93v/ePtvQeT3GrXU3lXueA68lYwyfxPlyxQ3rtYnKk8TrwMJodCSJysQ5Fvi4P@wamjtngzOKGTeQnqByCAIQUApVBWXerCIEMKMVI8oevkaqxxhfEKLXdmiWevaTFouXU9ZH/eua23@68hs "JavaScript (Node.js) ‚Äì Try It Online")
+4 bytes if a trailing delimited is not allowed.
Worse than Arnauld's solution (41, if it use no delimit and output array)
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 9 bytes
```
Œ¶Œ±‚Ä∫‚ÑñŒ∏Œπ‚ÅºŒ∫¬π
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMMtM6cktUgjUUfBvSg1EcR0zi8FihfqKGRq6ii4FpYm5hRrZOsoGGoCgfX//45OzuGR/3XLcgA "Charcoal ‚Äì Try It Online") Link is to verbose version of code. Accepts any character that's not an uppercase letter as a delimiter (some characters may need extra quoting). Explanation:
```
 Œ±          Predefined variable uppercase alphabet
Œ¶           Filtered where
   ‚Ññ        Count of
     Œπ      Current letter
    Œ∏       In input string
  ‚Ä∫         Is greater than
       Œ∫    Current index
      ‚Åº     Equals
        ¬π   Literal integer `1`
            Implicitly print
```
[Answer]
# [APL(Dyalog Unicode)](https://dyalog.com), ~~17~~15 bytes [SBCS](https://github.com/abrudz/SBCS)
```
‚éïA‚à©‚ä¢(/‚ç®)‚â†‚ç≤'B'=‚ä¢
```
[Try it on APLgolf!](https://razetime.github.io/APLgolf/?h=AwA&c=e9Q31fFRx8pHXYs09B/1rtB81LngUe8mdSd1W6AQAA&f=K0ktLil@1DZB3dHJOTxSwUldAcJSV9B41LtGR91JXVNB3QkiDlaAxFTnKgHp1ok21DONTTu0AswDAA&i=AwA&r=tryapl&l=apl-dyalog-extended&m=train&n=f)
A tacit function which takes a string on the right using no delimiter or any delimiter that is not a capital letter.
The test cases use spaces.
(The test case `B` is written as `(‚ç¨,'B')` because single characters in quotes are not treated as strings in APL)
```
‚éïA‚à©‚ä¢(/‚ç®)‚â†‚ç≤'B'=‚ä¢¬≠‚Å°‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å£‚Å£‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å£‚Å§‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å§‚Å°‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å§‚Å¢‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å§‚Å£‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå‚Å¢‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å£‚Å¢‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå‚Å£‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å£‚Å°‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå‚Å§‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å§‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å°‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å¢‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å£‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å§‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå‚Å¢‚Å°‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å£‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå‚Å¢‚Å¢‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å°‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå¬≠
          'B'=‚ä¢  # ‚Äé‚Å°Boolean mask for all Bs
         ‚ç≤       # ‚Äé‚Å¢NAND
        ‚â†        # ‚Äé‚Å£Boolean mask for all first instances
   ‚ä¢(/‚ç®)         # ‚Äé‚Å§apply Boolean mask (removes first B)
  ‚à©              # ‚Äé‚Å¢‚Å°intersection
‚éïA               # ‚Äé‚Å¢‚Å¢capital letter alphabet
üíé
```
Created with the help of [Luminespire](https://vyxal.github.io/Luminespire).
Taking the intersection with the alphabet helpfully removes any delimiters and sorts alphabetically.
This solution doesn't work on any of the APL versions on TIO, as @att describes.
[Answer]
# [Uiua 0.8.0](https://www.uiua.org/), 13 bytes [SBCS](http://tinyurl.com/SBCSUiua "SBCS for Uiua 0.8.0")
```
‚äè‚çè.‚äù‚ñΩ‚â†‚á°‚ßª,‚äó@B.
```
[Try on Uiua Pad!](https://uiua.org/pad?src=0_7_1__ZiDihpAg4oqP4o2PLuKKneKWveKJoOKHoeKnuyziipdAQi4KZiJCIgpmIkJCIgpmIkJCQiIKZiJBQ1dZIgpmIkFDV1lCIgpmIkFDV1lCQiIKZiJBQkNXWSIKZiJBQkNXWUIiCmYiQUNXWUFDV1kiCg==)
[Answer]
# [Scala](https://www.scala-lang.org/), 115 bytes
A Port of [@spooky\_simon's Python answer](https://codegolf.stackexchange.com/a/268625/110802) in Scala.
---
Golfed version. [Attempt This Online!](https://ato.pxeger.com/run?1=fY6xTsMwEIb3PMXpltqgIioWlMpIcWcmhBCqKmSCHQWZM7JdCKr6GEwsXWDhifo2XJqOEV7u7O-7__z1k2rjzcXvEqcU3k0kXO3n4fHZ1hmuTUuwKQCerIMXvggTm1RCFaP5WN7k2FKzkiXcUptBscnq9zq76eU-9SON6EodgreGpGqd6OQMrE8WzoseO5HKIUSqzZvx0Kl0VgfKvCkJXKCcY4UnnCJPUfdNj9eUxYNSEz2RVzMGi7v7wdkeV38Cn1eOzZ6EE1hpVkCjlMUYGXkfc_V4wiH6HzSAbXH83G431D8)
```
def g(x:Boolean)=if(x)1 else 0
def f(s:String)={val x=s.contains("C");"A"*g(x)+"B"*g(s.count(_=='B')>1)+"CWY"*g(x)}
```
Ungolfed version. [Attempt This Online!](https://ato.pxeger.com/run?1=fZHBasJAEIbxmqf42Ut2Ky2VXkSIkM25p1KKiMiaZjWSbkp2LYjkSbx40buv49O4zSZBSuxtdv5vv2GY_UnHIhMvh8NxY-Tj8NI754t1Ehu8ilRh5wGficSXfVBRLPUIYVGI7fTNFKlaztgI7yo1CCrSsZJayuWsKVoA-BEZVkJHtqWf4lwZq9aURITdAIso3yhTI7aicwQBfO4zjDHwapKSkOABNJWgv0qGAZJMJ3hmDP0W4i3ktHew6GNy11ZBpZv7bRcymaLSjuf2Ezipgb9JR7-L5d2GSv1P5ILSK93l6gM2h7wC)
```
object Main {
  def main(args: Array[String]): Unit = {
    def f(s: String): String = {
      val hasC = s.contains("C")
      val bCount = s.count(_ == 'B') > 1
      ("A" * (if (hasC) 1 else 0)) +
      ("B" * (if (bCount) 1 else 0)) +
      ("CWY" * (if (hasC) 1 else 0))
    }
    println(f("ABCWY B"))
    println(f("ABCWY"))
    println(f("B"))
    println(f("B B"))
    println(f("ACWY B B"))
    println(f("ACWY B"))
  }
}
```
]