eolymp
bolt
Try our new interface for solving problems
Problems

TEX2HTML

TEX2HTML

Time limit 1 second
Memory limit 256 MiB

Andrew just finished writing his thesis. That was a big work and now Andrew wants some remarks from his friends. He thinks the best way to share the paper is to post it to his blog. Andrew wrote his thesis in the TEX format and now he needs to convert them to HTML. Please help Andrew to implement the most essential part of the converter - the mathematical formulas converter.

Andrew's formulas are always enclosed in the dollar signs ($). They contain Latin letters, digits, parentheses, white spaces, binary operators (+-*/), superscripts and subscripts. You should ignore all white spaces.

Superscripts are written using the cap character (^) and braces ({}). The part of the formula inside the braces is the superscript itself. You may assume that only non-whitespace character will follow the cap character. If the superscript contains only one character, the braces can be omitted. The superscript will not be followed by another superscript or subscript. E.g. a^2 means a^2, 2^{2 + 2} means 2^(2+2).

Subscripts are written using the underline character ( _ ) and braces ({}). The part of the formula inside the braces is the subscript itself. You may assume that only non-whitespace character will follow the underline character. If the subscript contains only one character, the braces can be omitted. The subscript will not be followed by another subscript or superscript. E.g. x _ i means x[i], P _ {n+1-i} means P[n+1-i].

Your program should produce HTML-like output using the following rules. Each letter should be italicized using < i > open tag and < /i > close tag. These tags should enclose each maximal sequence of letters (don't forget to ignore white spaces). Each binary operator should be surrounded by the non-breaking spaces ( & nbsp; ). Superscripts should be enclosed in < sup > and < /sup > tags. Subscripts should be enclosed in < sub > and < /sub > tags.

You may assume that input will contain correct mathematical formula with only binary operators.

Input data

Contains several test cases. Each test case is a line with two dollar signs with the formula between them. No extra characters will appear on the line.

Output data

Print the HTML version of each formula on a separate line.

Examples

Input example #1
$  a    $
$  a    -   (v-b)   $
$a_i+b_2$
$B^{k_i}$
Output example #1
<i>a</i>
<i>a</i>&nbsp;-&nbsp;(<i>v</i>&nbsp;-&nbsp;<i>b</i>)
<i>a</i><sub><i>i</i></sub>&nbsp;+&nbsp;<i>b</i><sub>2</sub>
<i>B</i><sup><i>k</i><sub><i>i</i></sub></sup>
Source 2007 Петрозаводск, Saratov for Karelia with love, Январь 28, Задача F