cswork / OAOpen practice workspace

Susquehanna International GroupOA #2

Robot Vertical Move — Final Position

EasyJudge-ready

Topics (AI-labelled)Simulation

A robot starts from a point on a vertical line; U moves it up one step, and D moves it down one step. Determine its position relative to the start after all commands are processed.

Input

One line consisting of at least one U or D character.

Output

Output U if the final position is above the start, D if it is below, and an empty string if it is exactly at the start.

Example 1

Input:

UUDDUU

Output:

U

Example 2

Input:

UD

Output:

Example 3

Input:

DDU

Output:

D

Example notes

Count the net displacement from U and D.

Editorial

Loading solution…