You are arranging seats in a single row for a class. There are $b$ boys and $g$ girls to be seated in a row of $n = b + g$ seats. As you notice that many students prefer to sit with their friends that are usually of the same gender, you impose a rule on how seats are assigned to encourage students of opposite gender to sit together: no $k$ consecutive students of the same gender should sit together.
Construct a seating plan as a string of length $n$ with characters only of B and/or G, where:
Bdenotes a boyGdenotes a girl
such that:
- the string contains exactly $b$
Bs - the string contains exactly $g$
Gs - the string does not contain $\underbrace{\text{BBB} \dots \text{B}}_{k \text{ times}}$ or $\underbrace{\text{GGG}\dots \text{G}}_{k \text{ times}}$ as substring.
No. Otherwise, output Yes on the first line and a valid seating string on the second line.
Input
A single line that contains three integers $b$, $g$ and $k$.
Output
If there is no valid arrangement, output No. Otherwise, output Yes on the first line and a valid seating string on the second line.
Constraints
For all cases: $0\le b, g\le 2\times 10^5$, $2\le k\le 2\times 10^5$, $b + g\geq 1$
Subtask 1 (25%): $k=2$
Subtask 2 (30%): $k=3$
Subtask 3 (45%): No additional constraints
Notes
Multiple valid seating strings may exists, you may output any one of them.
Sample Test Cases
| Input | Output | |
|---|---|---|
| 3 2 3 | Yes BBGBG |
|
| 5 1 3 | No |
Scoring: Per Subtask
Authored by hclee
Appeared in 2025 Wah Yan Interschool Olympiad in Informatics 🤯🥷⚡🧠🏆