TeX is the leading typesetting system for mathematics, science, and 
engineering and has been adopted as standard by the American Mathematical 
Society. LaTeX was developed later by Leslie Lamport. It is based on TeX and 
provides a set of higher level commands for production of complex documents. In 
TeX or LaTeX, any text editor program may be used to enter and modify the input 
text.
The source text contains the actual text as well as formatting commands 
beginning with \. Commands are delimited by any non-alphabetic character. 
One example of beautification by TeX is that it uses `` (two 
left-single-quotes) and '' (two right-single-quotes) to delimit 
quotations, rather than the mundane " (one double quote) which is provided by 
most keyboards. Keyboards typically do not have an oriented double-quote, 
but they do have a left-single-quote (`) and right-single-quote ('). 
TeX lets the user type two left-single-quotes (``) to create a 
left-double-quote and two right-single-quotes ('') to 
create a right-double-quote.
Now, you have a text only file containing 
at most 250 lines at most 80 symbols each, as source or input, and you want to 
use TeX to beautify it. Rather than doing everything by hand, as the first step 
of automation you want to convert the quotes into the TeX format by using a 
program. This program will convert the text with double-quotes (") into an 
identical text except that double quotes have been replaced by the 
two-character sequences required by TeX for delimiting quotations with 
oriented double-quotes. The double-quote (") characters should be 
replaced appropriately by proper double single quotes depending on whether it is 
an opening or closing quotation mark. Question of nested quotations does not 
arise. The first " must be replaced by ``, the next by '', the next by 
``, the next by '', and so on. An opening 
double quote must have its closing quote in the same paragraph. If a match is 
not found in the same paragraph for an opening quote, this quote has to be 
deleted. Paragraph ends in the source text are marked either by at least one 
blank line, or a \par command or both. Your program must also be careful about 
the \" command which is used to produce umlaut or dieresis (\"e 
leads to ë). These are to be left untouched.
Input
Input will consist of several lines of text containing a number of double 
quotes ("), as well as some TeX commands. End of input will be marked by an 
\endinput command.
Output
Output will be an exact replica of the input, except the double quotes are to 
be modified according to the rules described above.
Sample
| input | output | 
|---|
| There is no "q in this sentence. \par 
"Talk child," said the unicorn. 
She s\"aid, "\thinspace `Enough!', he said." 
\endinput 
 | There is no q in this sentence. \par 
``Talk child,'' said the unicorn. 
She s\"aid, ``\thinspace `Enough!', he said.'' 
\endinput 
 | 
Notes
Double-quote (") has ASCII code 34,
left-single-quote (`) has ASCII code 96,
right-single-quote (') has ASCII code 39.
Note that tests may contain characters with ASCII codes above 127 and the last line may end without line break.
You may assume that there are no other commands starting with the prefix \endinput.
Problem Author: Alexander Halperin
Problem Source: Ural State University collegiate programming contest (25.03.2000)