QOJ.ac

QOJ

Limite de temps : 2 s Limite de mémoire : 512 MB Points totaux : 100

#4056. Base Conversion

Statistiques

Little D learned how to perform base conversions when he was two years old.

Therefore, he wants to ask you, for all numbers between $1$ and $n$, what are the sums of their digits in binary and ternary representations, respectively.

For a number $i$, let $a(i)$ and $b(i)$ be the sum of its digits in binary and ternary, respectively. For example, for $i=114$, its binary representation is $(1110010)_2$ and its ternary representation is $(11020)_3$, so $a(i) = 4$ and $b(i) = 4$.

Little D wants to know if you can really calculate the base conversions for all numbers from $1$ to $n$, so he wants to ask you for the value of $\sum_{i=1}^n x^iy^{a(i)}z^{b(i)}$. Since the answer can be very large, output the result modulo $998\,244\,353$.

Input

A single line containing four integers $n, x, y, z$.

Output

Output a single integer representing the answer.

Examples

Input 1

123456 12345 234567 3456789

Output 1

664963464

Input 2

1234567891 123 1 12345

Output 2

517823355

Input 3

9876543210987 1284916 83759265 128478129

Output 3

115945104

Subtasks

There are $20$ test cases in total.

For test cases $1, 2, 3$, $n \leq 10^7$.

For test cases $4, 5$, $x = y = 1$.

For test cases $6, 7$, $y = 1$.

For test cases $8, 9, 10$, $n \leq 10^{10}$.

For test cases $11, 12, 13, 14$, $n \leq 5\times 10^{11}$.

For all test cases, $1 \leq n \leq 10^{13}$ and $1 \leq x, y, z < 998\,244\,353$.

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.