Translation note. This manual is a translation of the Portuguese original. The command-line tools (
moj,moj-contest,moj-comp) print their messages in Portuguese, and the command examples below are identical to the original.
This guide tells you how to write the
docs/enunciado.md file. It has examples that you can copy.
The PACOTE document gives the package format
(the location of each file, the title, the samples, the languages). This
page is about the text: the formatting and, most
importantly, the formulas.
The statement is Markdown (the pandoc dialect) with
formulas in TeX between $ signs. The same
text becomes two things:
moj preview show this HTML;
enunciado.organdenunciado.texare also valid. But.mdis the canonical format, and it is the only format that translations accept. This page uses Markdown.
Joana has a sequence of $N$ integers. She wants to know how many pairs of positions $(i, j)$, with
$i < j$, have an even sum.
## Input
The first line contains an integer $N$ ($1 \le N \le 2 \cdot 10^5$). The second line contains
$N$ integers $a_1, a_2, \ldots, a_N$ ($|a_i| \le 10^9$).
## Output
Print a single integer: the number of pairs.The validation enforces or warns about three rules:
## Input and ## Output are
required. The Portuguese headings
## Entrada/## SaΓda are also valid (and so are
the Spanish ## Entrada/## Salida). You can add
other sections freely: ## Notes, ## Remarks,
## Subtasksβ¦% Title on the first line is
legacy, and the system removes it.tests/input/sample*, and they appear automatically at the
end. Put the explanation of each sample in
docs/notes/sample1.md (see PACOTE).| You write | Result | |
|---|---|---|
*italic* or _italic_ |
italic | β |
**bold** |
bold | β |
`abacaba` (code, strings, file names) |
abacaba |
β |
[text](https://exemplo.org) |
text | β (the text) |
## Section / ### Subsection |
section heading | β |
R\$ 10,00 |
R$ 10,00 | β |
\* \_ \# (the character,
without formatting) |
* _ # | β |
A blank line separates paragraphs. A line break inside a paragraph changes nothing (the text stays in the same paragraph). You can write as you like, for example one sentence per line.
Lists: use - or numbers, and put a
blank line before the list:
The operations are:
- `ADD x`: inserts $x$ into the set;
- `DEL x`: removes $x$;
- `QRY`: prints the smallest element.
1. first step;
2. second step.Table (the --- line is required;
:---: centers the column):
| Subtask | Points | Constraints |
|:---------:|:------:|-------------------|
| 1 | 20 | $N \le 100$ |
| 2 | 80 | no constraints |Code block (an illustrative input, a piece of a program): put three backticks before and after it:
```
3
1 2 3
```Quotation: start the line with
> .
Centered text: the ::: center block
(section 3, "Center") also applies to text.
Images: see section 3.
| You write | Result | |
|---|---|---|
1--10 (en dash, for ranges) |
1β10 | β |
pause --- like this (em dash) |
pause β like this | β |
"quotes" and 'single' (they become curly
automatically) |
βquotesβ and βsingleβ | β |
... |
β¦ | β |
10\ km (a space that does not break the line) |
10 km | β |
~~strikethrough~~ |
β | |
[underlined]{.underline} |
underlined | β |
H~2~O, 2^10^ (subscript and superscript in
the text; in a formula, use $β¦$) |
H2O, 210 | β |
<!-- author's note --> |
(does not appear) | β |
--- on its own line, with a blank line before it |
horizontal rule | β |
line that ends with \ (forced line break) |
breaks the line | β the line before the break comes out stretched (the PDF is justified); use separate paragraphs or a list |
footnote: text[^1] and, later,
[^1]: the note |
note at the end | β the text of the note disappears in the PDF; write
the remark in the text itself or in a ## Notes section |
Put the file in docs/, next to
enunciado.md, and refer to it by its name:
(You can also paste or drag the image into the web editor. The editor
then embeds it in the text.) Use simple names (letters, digits,
., _, -). The formats are png,
jpg, jpeg, gif, svg or webp, up to 2 MB. The PACOTE document gives the details.
The text between the brackets decides the result:
| You write | Result |
|---|---|
 alone in the
paragraph |
figure: the image and, below it, the caption "Map of the cities" (in italics in the PDF) |
 alone in the paragraph |
the image, without a caption |
β¦ the symbol  indicates β¦ in the middle of
a sentence |
the image inside the line β only for small icons |
If you specify nothing, the image comes out at its natural size. It does not go past the width of the text (on the site) or of the page (in the PDF). To set the size, give the width in % of the text width:
{width=50%}This applies on the site and in the PDF. The height follows (the aspect ratio stays the same).
By default, the image (and the figure) is on the
left. To center it, put it inside a
::: center block, with a blank line before the block:
The network looks like this:
::: center
{width=60%}
:::This applies on the site (the problem page, the contest, the HTML tab
and the editor's π Preview) and in the PDF. The caption is centered too.
The block can contain more than one image, and also text. (The
command-line moj preview still shows the block on the
left.)
| Does not work | Why |
|---|---|
{.center} |
a class on the image does not center it
(.center is for the block) |
<center>β¦</center> or
<div style="text-align:center">β¦</div> |
raw HTML: it centers on the site, but not in the PDF |
To draw a graph from DOT instead of a pasted image, see
mojtools/docs/enunciado-grafos.md.
$...$.
Display (centered, in its own paragraph):
$$...$$.$:
$ x $ is not a formula (the output is the
text $ x $). Write $x$.$N$, $10^5$,
$1 \le N \le 10^5$. Do not type N,
10^5 or 1 β€ N β€ 10β΅ as text. On the site they
look the same. But in the PDF, the β€ and
the β΅ typed in the text come out in a different font (the
body font does not have these characters).R\$.\newcommand{\abs}[1]{\left|#1\right|} in its own paragraph,
and then use $\abs{x}$.Each row gives what you write, how it comes out on the site, and how it comes out in the PDF of the problem set.
| You write | Result | |
|---|---|---|
$a_i$, $a_{i,j}$,
$x_i^2$ |
, , | β |
$x^2$, $2^{n+1}$,
$10^{18}$ |
, , | β |
$1 \le N \le 2 \cdot 10^5$ |
β | |
$0 \le a_i < 2^{63}$ |
β | |
$a \ne b$, $a \ge b$,
$a \approx b$ |
, , | β |
$10^9 + 7$ |
β | |
values $\le 10^9$ (relation without the left side) |
values | β |
| You write | Result | |
|---|---|---|
$\frac{a}{b}$ |
β | |
$\dfrac{a}{b}$ (larger, inline) |
β | |
$\sqrt{x}$, $\sqrt[3]{x}$ |
, | β |
$\sum_{i=1}^{n} a_i$,
$\prod_{i=1}^{n} a_i$ |
, | β |
$\max_{1 \le i \le n} a_i$,
$\min(a, b)$ |
, | β |
$\binom{n}{k}$ |
β |
| You write | Result | |
|---|---|---|
$\log n$, $\log_2 n$,
$\ln x$ |
, , | β |
$\gcd(a, b)$,
$\operatorname{lcm}(a, b)$ |
, | β |
$O(n \log n)$, $O(n^2)$,
$\mathcal{O}(1)$ |
, , | β |
$a \bmod m$, $a \equiv b \pmod{m}$ |
, | β |
$\lfloor n / 2 \rfloor$,
$\lceil n / k \rceil$ |
, | β |
$a \times b$, $a \cdot b$,
$a \pm b$ |
, , | β |
$n!$, $-x$ |
, | β |
$\infty$ |
β |
| You write | Result | |
|---|---|---|
$\{1, 2, \ldots, n\}$ |
β | |
$a_1, \dots, a_n$,
$a_1 + \cdots + a_n$ |
, | β |
$x \in S$, $x \notin S$,
$A \subseteq B$ |
, , | β |
$A \cup B$, $A \cap B$,
$\emptyset$ |
, , | β |
$\mathbb{Z}$, $\mathbb{N}$,
$\mathbb{R}$ |
, , | β |
$\{x \in S \mid x > 0\}$ (use \mid, not
|) |
β | |
$a \land b$, $a \lor b$,
$\neg a$, $a \oplus b$ |
, , , | β |
$\forall x$, $\exists y$ |
, | β |
$a \to b$, $a \Rightarrow b$,
$a \iff b$ |
, , | β |
$\alpha$, $\beta$, $\pi$,
$\varepsilon$, $\Delta$,
$\Sigma$ |
, , , , , | β |
| You write | Result | |
|---|---|---|
$\text{if } x > 0$ (normal text inside the
formula) |
β | |
$a\,b$ (thin space), $a \quad b$ (wide
space) |
, | β |
$\mathbf{v}$, $\mathrm{d}x$ |
, | β |
$\texttt{abc}$ |
β a different monospaced font; for strings, use `abc`
outside the formula |
|
$50\%$, $a \# b$,
$a \& b$ |
, , | β |
| You write | Result | |
|---|---|---|
$\bar{x}$, $\hat{x}$,
$\vec{v}$, $\tilde{x}$,
$\dot{x}$ |
, , , , | β the accent comes out detached, high and small |
$\overline{AB}$, $\underline{x}$ |
, | β the same |
$f'(x)$, $f''(x)$ |
, | β the prime (β²) comes out small and far from the letter |
If the PDF is important, do not use a name with an accent. Use a
different name ($m$ for the mean instead of
$\bar{x}$, $g$ instead of $f'$).
On the site, everything comes out correctly.
Write them as in TeX. The size is set automatically:
$(x_1, y_1)$ β
,
$[l, r]$ β
.\left( β¦ \right) around a fraction, a sum or a matrix:
$\left( \frac{a}{b} \right)^2$ β
.$[l, r)$ β
,
$(a, b]$ β
.$\{1, 2\}$ β
(without the backslash, { only groups).$|x|$ β
(or $\lvert x \rvert$). Norm:
$\|v\|$ β
.$a \mid b$ β
,
$a \nmid b$ β
,
$P(A \mid B)$ β
.$\langle a, b \rangle$
β
.Definition by cases:
$$f(n) = \begin{cases} 1 & \text{if } n = 0 \\ 2 f(n-1) & \text{if } n > 0 \end{cases}$$Matrix (pmatrix between parentheses,
bmatrix between brackets, vmatrix between
bars):
$$A = \begin{pmatrix} a & b \\ c & d \end{pmatrix}, \qquad \det A = \begin{vmatrix} a & b \\ c & d \end{vmatrix}$$Calculations aligned on the = (& marks
the alignment point, \\ breaks the line):
$$\begin{aligned} S &= a_1 + a_2 + \cdots + a_n \\ &= \frac{n(n+1)}{2} \end{aligned}$$All of them come out correctly in the PDF (β).
| Avoid | Why | Write |
|---|---|---|
1 β€ N β€ 10β΅ typed as text |
in the PDF it comes out in a different font | $1 \le N \le 10^5$ |
\textbf{β¦}, \emph{β¦},
\section{β¦}, \begin{itemize} |
this is LaTeX for text, not Markdown: the text disappears, without a warning, on the site and in the PDF | **β¦**, *β¦*, ## β¦,
- item |
$ x $ |
with a space next to the $, it is not a formula |
$x$ |
| a sample copied into the text | it appears twice (the samples come from tests/) |
tests/input/sample1 +
docs/notes/sample1.md |
$\bar{x}$, $f'$ when the PDF is
important |
see the table "Where the PDF is different" | a different name |
{β¦} to show braces |
in TeX, { only groups |
\{β¦\} |
<center>, <div style=β¦> to
center |
it does not center in the PDF | ::: center (section 3) |
footnote ([^1]) |
in the PDF, the text of the note disappears | the remark in the text or in ## Notes |
A store records the price $p_i$ of each of the $N$ days of a season. For an interval of
days $[l, r)$ β from day $l$ to day $r - 1$ β, the *profit* is
$$L(l, r) = \max_{l \le i < r} p_i - \min_{l \le i < r} p_i.$$
Given $Q$ queries, answer the profit of each interval. If $r - l < 2$, the profit is $0$.
## Input
The first line contains two integers $N$ and $Q$ ($1 \le N, Q \le 2 \cdot 10^5$). The second line
contains $N$ integers $p_1, p_2, \ldots, p_N$ ($1 \le p_i \le 10^9$). Each of the next $Q$ lines
contains two integers $l$ and $r$ ($1 \le l < r \le N + 1$).
## Output
For each query, print a line with $L(l, r)$.
## Subtasks
| Subtask | Points | Constraints |
|:---------:|:------:|---------------------------|
| 1 | 30 | $N, Q \le 1000$ |
| 2 | 70 | no additional constraints |moj preview in the CLI (the same renderer as
the HTML that the student reads).For the MOJ maintainers: the PDF of the problem set comes
from pandoc -f html -t odt β soffice.
LibreOffice does not draw the MathML. It translates the MathML to
StarMath and reads that text.
server/api/v1/lib/odt-math-bars.py fixes the MathML between
the two steps (the size and font of the formula, the delimiters, the
syntax characters, a relation without an operand, and also the size of
the images). server/api/v1/lib/odt-center.lua centers the
::: center block (the Center style of
server/etc/caderno-reference.odt). The PDF
column of this page was measured with pandoc 3.1.11 and LibreOffice 25.2
(the versions in the image). The tests that support it are
server/test/smoke-odt-math-bars.sh and
server/test/render-docs.sh.