Under construction

Still being built. Things may change

Make String 1

Time limit2sMemory limit1024 MB

Summary
Given a string of equal S and U counts, print a sequence of cursor operations that builds it in at most 2N operations.
Level

Medium6 of 10

Topics
String, Implementation, Greedy
Solved
No attempts yet

Problem

Seohyun is the teaching assistant in charge of the physics lab this semester, and she is entering the students' grades.

The section she manages has NN students. Exactly half of them receive S and the other half receive U. NN is always even.

The grades of student 1, student 2, ⋯\cdots, student NN are given as a string TT of length NN. Seohyun's job is to enter this string into the grading system.

Seohyun enters the grades by repeating only the following operations.

  1. Insert SU at the cursor position.
  2. If the cursor is not at the leftmost position, move the cursor one character to the left.
  3. Insert US at the cursor position.

The initial state is an empty string. The cursor is always at the front, at the end, or between two characters. After operations 1 and 3, the cursor moves to just after the inserted string.

For Seohyun, find a way to enter all the grades using at most 2N2N operations.

Input

The first line contains the length NN of the string (2≤N≤1 000 0002\le N\le 1\,000\,000, NN is even).

The second line contains the string TT consisting only of S and U, which represents the grades. TT has the same number of S and U characters.

Output

On the first line, print the number of operations KK (0≤K≤2N0\le K\le 2N).

On the second line, print a string of length KK describing Seohyun's operations. Operation 1 is written as S, operation 2 as N, and operation 3 as U. When the cursor is at the leftmost position, operation 2 must not be printed.

After all operations, the cursor may be anywhere.

If there are multiple answers, print any one of them.

Under the input constraints, an answer always exists, and this can be proven.

Examples2

  1. Example 1

    Input
    4
    SUSU
    
    Expected output
    6
    SNNSNN
    
  2. Example 2

    Input
    6
    SUSUUS
    
    Expected output
    9
    UNNSNNSNN