eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків
Задачі

ASCII Expression

ASCII Expression

Mathematical expressions appearing in old papers and old technical articles are printed with typewriter in several lines, where a fixed-width or monospaced font is required to print characters (digits, symbols and spaces). Let us consider the following mathematical expression. \includegraphics{https://static.e-olymp.com/content/ee/eed709c2751a8f6697e5c5df7276dde870ccebfe.jpg} It is printed in the following four lines: 4 2(1 - ----) * - 5 + 6 2 3where "\textbf{- 5}" indicates unary minus followed by \textbf{5}. We call such an expression of lines "ASCII expression". For helping those who want to evaluate ASCII expressions obtained through optical character recognition (OCR) from old papers, your job is to write a program that recognizes the structure of ASCII expressions and computes their values. For the sake of simplicity, you may assume that ASCII expressions are constructed by the following rules. Its syntax is shown in Table 1. \includegraphics{https://static.e-olymp.com/content/4b/4b06ec0c5ce16cd2f5fb94c940936e95705c5172.jpg} For example, the negative fraction is represented in three lines: 3- --- 4 where the left-most hyphen means a unary minus operator. One space character is required between the unary minus and the vinculum of the fraction. \includegraphics{https://static.e-olymp.com/content/6c/6cff60473712d7e25c0547ae51798578ac95cd7f.jpg} The fraction is represented in four lines: 3 + 4 * -2------------- 2- 1 - 2 where the widths of the cells of the dividend and divisor are \textbf{11} and \textbf{8} respectively. Hence the number of hyphens of the vinculum is \textbf{2 + max(11, 8) = 13}. The divisor is centered by \textbf{⌈(13−8)/2⌉ = 3} space characters (hyphens) to the left and \textbf{⌊(13−8)/2⌋ = 2} to the right. The powexpr \textbf{(4^2)^3} is represented in two lines: 2 3( 4 ) where the cell for \textbf{2} is placed one line above the base-line of the cell for \textbf{4}, and the cell for \textbf{3} is placed one line above the base-line of the cell for a primary \textbf{(4^2)}. \InputFile The input consists of multiple datasets, followed by a line containing a zero. Each dataset has the following format. \textbf{nstr1str2...strn} \textbf{n} is a positive integer, which indicates the number of the following lines with the same length that represent the cell of an ASCII expression. \textbf{str_k} is the \textbf{k}-th line of the cell where each space character is replaced with a period. You may assume that \textbf{n} ≤ \textbf{20} and that the length of the lines is no more than \textbf{80}. \OutputFile For each dataset, one line containing a non-negative integer less than \textbf{2011} should be output. The integer indicates the value of the ASCII expression in modular arithmetic under modulo \textbf{2011}. The output should not contain any other characters. There is no \textit{fraction} with the divisor that is equal to zero or a multiple of \textbf{2011}. Note that powexpr \textbf{x^0} is defined as \textbf{1}, and \textbf{x^y} (\textbf{y} is a positive integer) is defined as the product \textbf{x}×\textbf{x}×...×\textbf{x} where the number of \textbf{x}'s is equal to \textbf{y}. \includegraphics{https://static.e-olymp.com/content/49/490ed5f4c2875020284033e593bd137ef931462c.jpg} A fractionis computed as the multiplication of \textbf{x} and the inverse of \textbf{y}, i.e., \textbf{x}× \textbf{inv(y)}, under \textbf{y} modulo \textbf{2011}. The inverse of \textbf{y} (\textbf{1} ≤ \textbf{y} < \textbf{2011}) is uniquely defined as the integer \textbf{z} (\textbf{1} ≤ \textbf{z} < \textbf{2011}) that satisfies \textbf{z} × \textbf{y ≡ 1 (mod 2011)}, since\textbf{ 2011} is a prime number.
Ліміт часу 1 секунда
Ліміт використання пам'яті 64 MiB
Вхідні дані #1
4
........4...2..........
(.1.-.----.)..*.-.5.+.6
........2..............
.......3...............
3
...3.
-.---
...4.
4
.3.+.4.*.-.2.
-------------
..........2..
...-.1.-.2...
2
...2..3
(.4..).
1
2.+.3.*.5.-.7.+.9
1
(.2.+.3.).*.(.5.-.7.).+.9
3
.2....3.
4..+.---
......5.
3
.2......-.-.3.
4..-.-.-------
..........5...
9
............1............
-------------------------
..............1..........
.1.+.-------------------.
................1........
......1.+.-------------..
..................1......
...........1.+.-------...
................1.+.2....
15
.................2......
................---.....
.......2.........5....3.
.(.---------.+.-----.)..
.....7...........3......
....---.+.1.............
.....4..................
------------------------
.......2................
......---...............
.......5.......2....2...
...(.-----.+.-----.)....
.......3.......3........
..............---.......
...............4........
2
.0....2....
3..+.4..*.5
20
............2..........................
...
Вихідні дані #1
501n502n1n74n19n2010n821n821n1646n148n81n1933n
Джерело Asia Regional Fukuoka, Japan, 2011-11-13