Universal Cup Judging System

Universal Cup

Límite de tiempo: 3.0 s Límite de memoria: 1024 MB Puntuación total: 100 Hackeable ✓
Estadísticas

You are given positive integers $N$ and $M$.

For each $k = 1, 2, \dots, N + M - 1$, let $\text{ans}_k$ denote the answer to the following problem.

A pair of sequences $(a, b)$, where $a = (a_1, a_2, \dots, a_{N+M-1})$ and $b = (b_1, b_2, \dots, b_{N+M-1})$, each of length $N + M - 1$, is called a good pair of sequences if all of the following conditions are satisfied:

  • $(a_1, b_1) = (1, N + 1)$
  • For $i = 2, 3, \dots, N + M - 1$, one of the following holds:
    • $(a_i, b_i) = (a_{i-1} + 1, b_{i-1})$
    • $(a_i, b_i) = (a_{i-1}, b_{i-1} + 1)$
  • $(a_{N+M-1}, b_{N+M-1}) = (N, N + M)$

For a good pair of sequences $(a, b)$, define a tree $T(a, b)$ as follows:

  • It is a tree with $N + M$ vertices labeled from $1$ to $N + M$.
  • For each $i = 1, 2, \dots, N + M - 1$, there is an edge connecting vertex $a_i$ and vertex $b_i$.

For a tree, let $\text{dist}(i, j)$ be the number of edges on the simple path between vertices $i$ and $j$. The score of the tree is defined as the number of integer pairs $(i, j)$ such that $1 \le i < j \le N + M$ and $\text{dist}(i, j) = k$.

Compute the sum of the scores of $T(a, b)$ over all good pairs of sequences $(a, b)$, modulo $998244353$.

Compute all values $\text{ans}_1, \text{ans}_2, \dots, \text{ans}_{N+M-1}$, and output $\sum_{k=1}^{N+M-1} (\text{ans}_k \oplus k)$, where $\oplus$ denotes the bitwise exclusive OR (XOR).

Input

The input is given in the following format:

N M
  • $1 \le N \le 5 \times 10^6$
  • $1 \le M \le 5 \times 10^6$
  • All input values are integers.

Output

Output the answer.

Sample 1

2 2
14

Sample 2

24 167
21925979855

Sample 3

4297614 4167924
4162418864110099

Note

In the first example, $(\text{ans}_1, \text{ans}_2, \text{ans}_3) = (6, 4, 2)$. Therefore, the value to be output is $(6 \oplus 1) + (4 \oplus 2) + (2 \oplus 3) = 7 + 6 + 1 = 14$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.