Skip to main content
Back to problems
Codeforces
Easy
Arrays
Strings
Simulation
Queue at the School

Simulate a queue where boys swap with girls one position at a time over several seconds.

Acceptance 0%
Problem Statement

Problem

A school queue contains only boys and girls. Each second, every boy who is immediately before a girl swaps places with that girl. All such swaps happen simultaneously in one second.

Given the initial queue and the number of seconds that pass, determine the final arrangement of the queue.

Details

  • The queue is represented by a string of characters, where one character stands for a boy and the other for a girl.
  • During one second, look at all adjacent pairs from left to right.
  • If a boy is directly in front of a girl, they swap positions.
  • A person can be involved in at most one swap per second.

Your task is to output the queue after the given number of seconds.

Input Format

Input

  • The first line contains two integers nn and tt — the queue length and the number of seconds.
  • The second line contains a string of length nn describing the queue.

Output Format

Output

  • Print the queue after tt seconds.

Constraints

Constraints

  • 1n1001 \le n \le 100
  • 1t501 \le t \le 50
  • The string length is nn
  • The string contains only two distinct characters representing boys and girls
Examples
Sample cases returned by the problem API.

Example 1

Input

5 1
BGGBG

Output

GBGGB

Explanation

In the first second, the boy at position 1 swaps with the girl at position 2, and the boy at position 4 swaps with the girl at position 5.

Example 2

Input

5 2
BGGBG

Output

GGBGB

Explanation

After the first second the queue becomes GBGGB. In the second second, the boy at position 2 swaps with the girl at position 3.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.