There are N cities in a country. From any city i, you can spend 1 USD to travel to any city, such that:
If A[i] is 'U', then j must be greater than i.
If A[i] is 'D', then j must be less than i.
You are given the string A of length N. It is possible that you have to travel through multiple paths to reach your destination.
Let Cost(i, j) represent the minimum USDs needed to complete the journey from city i to city j.
Print the sum of Cost(1, N) for the given string A.
For the input string A = "UD":