Codeforces Round 602 (Div. 1, based on Technocup 2020 Elimination Round 3)
F
Xor-Set
Codeforces
3100
原题
← E→
翻译中…

You are given two sets of integers: $A$ and $B$. You need to output the sum of elements in the set $C = \{x | x = a \oplus b, a \in A, b \in B\}$ modulo $998244353$, where $\oplus$ denotes the bitwise XOR operation. Each number should be counted only once.

翻译中…

For example, if $A = \{2, 3\}$ and $B = \{2, 3\}$ you should count integer $1$ only once, despite the fact that you can get it as $3 \oplus 2$ and as $2 \oplus 3$. So the answer for this case is equal to $1 + 0 = 1$.

翻译中…

Let's call a segment $[l; r]$ a set of integers $\{l, l+1, \dots, r\}$.

翻译中…

The set $A$ is given as a union of $n_A$ segments, the set $B$ is given as a union of $n_B$ segments.

翻译中…

Input

翻译中…

The first line contains a single integer $n_A$ ($1 \le n_A \le 100$).

翻译中…

The $i$-th of the next $n_A$ lines contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le 10^{18}$), describing a segment of values of set $A$.

翻译中…

The next line contains a single integer $n_B$ ($1 \le n_B \le 100$).

翻译中…

The $i$-th of the next $n_B$ lines contains two integers $l_j$ and $r_j$ ($1 \le l_j \le r_j \le 10^{18}$), describing a segment of values of set $B$.

翻译中…

Note that segments in both sets may intersect.

翻译中…

Output

翻译中…

Print one integer — the sum of all elements in set $C = \{x | x = a \oplus b, a \in A, b \in B\}$ modulo $998244353$.

翻译中…

Note

翻译中…

In the second example, we can discover that the set $C = \{0,1,\dots,15\}$, which means that all numbers between $0$ and $15$ can be represented as $a \oplus b$.

翻译中…

样例

Input #1
2
3 5
5 8
3
1 2
1 9
2 9
Output #1
112
InputCopy OutputCopy
Input #2
1
1 9
2
2 4
2 10
Output #2
120
InputCopy OutputCopy
题目信息
题号
1261F
时间限制
2 s
内存限制
256 MB
标签
位运算
分治
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。