{"trustable":true,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eBinary numbers form the principal basis of computer science. Most of you have heard of other systems, such as ternary, octal, or hexadecimal. You probably know how to use these systems and how to convert numbers between them. But did you know that the system base (radix) could also be negative? One assistant professor at the Czech Technical University has recently met negabinary numbers and other systems with a negative base. Will you help him to convert numbers to and from these systems? \u003cbr\u003e\u003cbr\u003eA number N written in the system with a positive base R will always appear as a string of digits between 0 and R - 1, inclusive. A digit at the position P (positions are counted from right to left and starting with zero) represents a value of R^P . This means the value of the digit is multiplied by R^P and values of all positions are summed together. For example, if we use the octal system (radix R \u003d 8), a number written as 17024 has the following value: \u003cbr\u003e\u003cbr\u003e 1.8^4 + 7.8^3 + 0.8^2 + 2.8^1 + 4.8^0 \u003d 1.4096 + 7.512 + 2.8 + 4.1 \u003d 7700\u003cbr\u003e\u003cbr\u003eWith a negative radix -R, the principle remains the same: each digit will have a value of (-R)^P . \u003cbr\u003eFor example, a negaoctal (radix R \u003d -8) number 17024 counts as: \u003cbr\u003e\u003cbr\u003e 1.(-8)^4 + 7.(-8)^3 + 0.(-8)^2 + 2.(-8)^1 + 4.(-8)^0 \u003d 1.4096 - 7.512 - 2.8 + 4.1 \u003d 500 \u003cbr\u003e\u003cbr\u003eOne big advantage of systems with a negative base is that we do not need a minus sign to express negative numbers. A couple of examples for the negabinary system (R \u003d -2): \u003cbr\u003e\u003cbr\u003e\u003ccenter\u003e\u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/6ac5122c9a12b67c85bfbf017dda02a6?v\u003d1715101862\"\u003e\u003c/center\u003e \u003cbr\u003e\u003cbr\u003eYou may notice that the negabinary representation of any integer number is unique, if no “leading zeros” are allowed. The only number that can start with the digit “0”, is the zero itself. \u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The input will contain several conversions, each of them specified on one line. A conversion from the decimal system to some negative-base system will start with a lowercase word “to” followed by a minus sign (with no space before it), the requested base (radix) R, one space, and a decimal number N . \u003cbr\u003e\u003cbr\u003eA conversion to the decimal system will start with a lowercase word “from”, followed by a minus sign, radix R, one space, and a number written in the system with a base of -R. \u003cbr\u003e\u003cbr\u003eThe input will be terminated by a line containing a lowercase word “end”. All numbers will satisfy the following conditions: 2 ≤ R ≤ 10, -1000000≤N≤1000000 (decimal). \u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"For each conversion, print one number on a separate line. If the input used a decimal format,output the same number written in the system with a base -R. If the input contained such a number, output its decimal value. \u003cbr\u003e\u003cbr\u003eBoth input and output numbers must not contain any leading zeros. The minus sign \"-\" may only be present with negative numbers written in the decimal system. Any non-negative number or a number written in a negative-base system must not start with it. "}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003eto-2 10\r\nfrom-2 1010\r\nto-10 10\r\nto-10 -10\r\nfrom-10 10\r\nend\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e11110\r\n-10\r\n190\r\n10\r\n-10\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}