cswork / OAOpen practice workspace

JPMorgan ChaseOA #19

Get Max Deletions

Estimated EasyJudge-ready

Topics (AI-labelled)Hashing

Unit moves UDLR are executed on an infinite plane with no obstacles. Delete any instructions, not necessarily contiguous, while keeping the final coordinates unchanged; find the maximum number of instructions that can be deleted.

Input

One line with an instruction string of length 1..100000, containing only U, D, L, and R.

Output

Output a single integer answer.

Example 1

Input:

UDLR

Output:

4

Example 2

Input:

UUURD

Output:

2

Example 3

Input:

L

Output:

0

Example notes

The outputs of the three public examples are, in order: 4; 2; 0. These answers have been checked by independent enumeration or direct simulation.

Editorial

Loading solution…