Konnexions Problem 4

0

0 votes
Easy-Medium
Problem

Little pig Benny wants to visit her friends house. But she doesn't knows the route to her friend's house. Her friend Mike has created a special set of instructions for her. A set of instructions is a string which consists of letters {'L', 'R', 'U', 'D'}.

Benny is staying at point (0, 0) on the infinite plane. She starts moving according to the instructions written by Mike. Let's assume that now she is at a point (X, Y). Then depending on the current instruction she moves in some direction:

'L' -- from (X, Y) moves to point (X, Y - 1)

'R' -- from (X, Y) moves to point (X, Y + 1)

'U' -- from (X, Y) moves to point (X - 1, Y)

'D' -- from (X, Y) moves to point (X + 1, Y)

Initially, all the points are wet because of heavy rainfall few minutes . During her journey if Benny steps on a point at any time she makes it muddy. Every time, she steps on a muddy points she slips and falls down.

You are given a string S which denotes a set of instructions for Benny. Your task is to calculate how may times she will fall down.

Input format

Single line contains string S.

Output format

Output how many times Benny will fall down.

Constraints

  • 1 ≤ S ≤ 10^5
Time Limit: 3
Memory Limit: 256
Source Limit:
Editor Image

?