Skip to content

Instantly share code, notes, and snippets.

@neizod
Created May 21, 2025 13:34
Show Gist options
  • Save neizod/bc91b5f3f49e6e7099e53b2dd45f631f to your computer and use it in GitHub Desktop.
Save neizod/bc91b5f3f49e6e7099e53b2dd45f631f to your computer and use it in GitHub Desktop.
A2-019, TOI-Zero: กระต่ายน้อยรัก BUU
#!/usr/bin/env python3
import re
def yes(words):
return f'Yes {max(map(len, words))-1}'
def abuuu(word, i):
return (word[:i+1] + (len(word)*'U'))[:len(word)]
def buubu(word):
rep = 1 + len(word)//3
return (rep*'BUU')[:len(word)]
def calc(word):
words = re.findall(r'bu{2,}', word, re.IGNORECASE)
if words:
return yes(words)
i = word.lower().find('b')
if i >= 0:
return abuuu(word, i)
return buubu(word)
print(calc(input().strip()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment