PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000153. Rô-bốt đi trên tuyết (Snow Walking Robot)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Rô-bốt đi trên tuyết (Snow Walking Robot)

Snow Walking Robot

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

A robot starts at (0,0)(0,0) on an infinite grid. Its instruction string ss contains only L, R, U, D. You may delete some instructions and reorder the rest.

Create the longest valid closed walk: it must return to (0,0)(0,0), visit no other cell more than once, and visit the origin only at the start and end. The empty walk is allowed.

Input

The input contains one nonempty string ss using only L, R, U, D.

Output

Print the maximum retained length LL and then a valid walk of exactly LL instructions using no direction more often than in ss. The second line may be empty when L=0L=0.

Subtasks

  • Subtask 1 (20 points): 1≤∣s∣≤301\le |s|\le30; every character is L, R, U or D.
  • Subtask 2 (30 points): 1≤∣s∣≤10001\le |s|\le1000; every character is L, R, U or D.
  • Subtask 3 (50 points): 1≤∣s∣≤1051\le |s|\le10^5; every character is L, R, U or D.

Examples

Input

LRU

Output

2
LR

Explanation

The input LRU has one L, one R and one U, but no D. The two-instruction walk LR returns to the origin and visits no cell twice except the origin. No longer closed walk is possible.