eolymp
bolt
Try our new interface for solving problems
Məsələlər

Burger Time?

Burger Time?

Everybody knows that along the more important highways there are countless fast food restaurants. One can find easily hamburgers, hot dogs, pizzas, sandwiches ... food everywhere. Many times the problem isn't to find a restaurant but a drugstore. After a big lunch with fast food it's normal that we need a drugstore because our stomach begins to feel pain. Given the locations of the restaurants and drugstores on a highway, you want to determine the minimum distance between a restaurant and a drugstore. \InputFile The first line of each test case gives an integer \textbf{L} (\textbf{1} ≤ \textbf{L} ≤ \textbf{2000000}) indicating the length of the highway. The second line of each test case contains a string \textbf{S} of length \textbf{L}, showing the positions of the restaurants and drugstores along the highway in the following manner: \begin{itemize} \item The character "\textbf{R}" represents a place with a restaurant. \item The character "\textbf{D}" represents a place with a drugstore. \item The character "\textbf{Z}" represents a place with a restaurant and a drugstore. \item The character "\textbf{.}" represents an empty place. \end{itemize} You can suppose that every test case has at least one restaurant and at least one drugstore. The end of the input is indicated when \textbf{L} = \textbf{0}. \OutputFile For each case in the input, print one line with the minimum distance between a restaurant and a drugstore.
Zaman məhdudiyyəti 2 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
2
RD
5
..Z..
10
.R......D.
10
.R..Z...D.
10
...D..R...
25
..D...R.RR...DD...D.R...R
0
Çıxış verilənləri #1
1
0
7
0
3
2