461. Wiki Lists

Time limit per test: 0.25 second(s)
Memory limit: 65536 kilobytes
input: standard
output: standard



In this task you need to write a small part of wiki-to-HTML translator. You have to deal only with enumerated and regular lists.

Wiki dialect in this task defines lists as follows — the character "
#
" defines an enumerated list and "
*
" defines a regular list. These symbols are called list markers.

Wiki-text should be processed line by line. A group of two or more consecutive lines should be treated as elements of the same list (enumerated, or regular) if these lines start with the same list marker symbol.

A group of two or more consecutive list elements should be considered as a nested list if these elements start with the same list marker symbol. This rule should be applied recursively.

HTML equivalent of a wiki-text is formed using the well-known HTML syntax. An enumerated list starts with "<ol>", then all list elements are written, and then the list ends with "</ol>". HTML equivalent of a regular list is similar to the one for enumerated list, but it starts with "<ul>" and ends with "</ul>". An element of any list is represented by "<li>", then the contents of the element are written followed by "</li>".

The rules given above unambiguously define the way to make HTML from wiki-text. Please refer to the sample tests for clarifications.

Input
Input contains a wiki-text with no less than 1 and no more than 1000 lines. The total length of all input lines is not greater than 1000 characters. The depth of nested lists is not limited. Input contains only lowercase and uppercase Latin letters, digits, symbols "
*
" and "
#
", and line breaks. Each line contains at least one character different from "
*
" and "
#
", so there will be no empty lines in the output.

Output
Print HTML equivalent of the given wiki-text to the output. All tags should be placed on separate lines with no spaces.

Example(s)
sample input
sample output
FirstLine
*ItemX
*ItemY
#Item1
#Item2
*ItemZ
FirstLine
<ul>
<li>
ItemX
</li>
<li>
ItemY
</li>
</ul>
<ol>
<li>
Item1
</li>
<li>
Item2
</li>
</ol>
*ItemZ

sample input
sample output
*ab
*x#x
*#1
*#2
#3
<ul>
<li>
ab
</li>
<li>
x#x
</li>
<li>
<ol>
<li>
1
</li>
<li>
2
</li>
</ol>
</li>
</ul>
#3

sample input
sample output
***1
**2
<ul>
<li>
<ul>
<li>
*1
</li>
<li>
2
</li>
</ul>
</li>
</ul>




Online Contester Team © 2002 - 2010. All rights reserved.