Bangladesh Olympiad in Informatics Discord Server Contest Round 1
A. Blackout Math
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Turjo and Urjo are two exceptionally good brothers. One lazy Friday afternoon, the power went out, leaving them completely bored with nothing to do. To pass the time, Urjo decided to invent a math game to challenge Turjo's calculating speed.

Urjo grabs a piece of paper and writes down two starting numbers, $$$A$$$ and $$$B$$$. He then tells Turjo that he is generating a special sequence. However, since standard addition is way too easy for them, Urjo uses the Bitwise XOR operator ($$$\oplus$$$) to generate the next terms.

Let $$$F$$$ be a sequence. The sequence is defined by Urjo as follows:

$$$$$$F_{1} = A$$$$$$ $$$$$$F_{2} = B$$$$$$ $$$$$$F_{i} = F_{i-1} \oplus F_{i-2} \ for \ all \ i \ge 3$$$$$$

The rules of the game are simple: Urjo will suddenly shout a number $$$N$$$. In order to win the game and prove he is the superior brother, Turjo must instantly shout back the exact value of the $$$N^{th}$$$ term in the sequence defined as $$$F_{N}$$$.

He needs your help to write a lightning-fast program so he can beat his brother and win the game!

Constraints

  • $$$1 \le N \le 10^{18}$$$
  • $$$0 \le A, B \le 10^{18}$$$
Input

Input is given in the following format:

  • line 1: $$$N \quad A \quad B$$$
Output
  • line 1: A single integer denoting the exact value of the $$$F_{N}$$$.
Scoring
SubtaskPointsAdd. constraints
$$$1$$$$$$5$$$$$$N \le 3$$$
$$$2$$$$$$7$$$$$$A = 1$$$ and $$$B = 1$$$ and $$$N \le 10$$$
$$$3$$$$$$8$$$$$$N \le 20$$$
$$$4$$$$$$10$$$$$$N \le 1000$$$
$$$5$$$$$$30$$$$$$N \le 10^5$$$
$$$6$$$$$$40$$$No additional constraints
Examples
Input
3 6 7
Output
1
Input
5 9 11
Output
11
Note

Example 1: $$$N=3 \quad A=6 \quad B=7$$$

  • $$$F_{1} = 6$$$
  • $$$F_{2} = 7$$$
  • $$$F_{3} = F_{2} \oplus F_{1} = 7 \oplus 6 = 1$$$

Example 2: $$$N=5 \quad A=9 \quad B=11$$$

  • $$$F_{1} = 9$$$
  • $$$F_{2} = 11$$$
  • $$$F_{3} = F_{2} \oplus F_{1} = 11 \oplus 9 = 2$$$
  • $$$F_{4} = F_{3} \oplus F_{2} = 2 \oplus 11 = 9$$$
  • $$$F_{5} = F_{4} \oplus F_{3} = 9 \oplus 2 = 11$$$

Bitwise XOR ($$$\oplus$$$) compares two numbers in their binary representation. It evaluates each pair of bits according to the following truth table:

ABA $$$\oplus$$$ B
000
011
101
110
For example, $$$6 \oplus 7 = 1$$$
  • 6 in binary is 00110
  • 7 in binary is 00111
Comparing them bit-by-bit yields 00001, which is 1 in decimal.

B. Aritro and the Group Chat
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

The group chat was once buzzing with messages, reactions, memes and jokes every second just like the peak of every group chat. Alas, the glory days are now over, only Aritro sends messages in the chat now. The others have a life now!

There are $$$N$$$ inactive friends in the chat. Aritro sends messages one by one, and each message is assigned an id equal to the number of messages sent so far, including this message. So his first message has id $$$1$$$, his second has id $$$2$$$, and so on.

A friend can come online at any point. When friend $$$f$$$ comes online, he reads all messages that have been sent so far, and then immediately goes offline. If Aritro sends more messages after that, friend $$$f$$$ will not see them unless he comes online again.

You will be given events in order. Each event is one of the following:

  • Aritro sends a message. It is assigned the next available id.
  • Friend $$$f$$$ comes online and reads all messages sent so far. He then goes offline.
  • How many friends have read message with id $$$s$$$.

Note: A friend reads message $$$s$$$ if and only if he came online at a time when at least $$$s$$$ messages had already been sent.

Constraints

  • $$$1 \le N \le 5 \times 10^5$$$
  • $$$1 \le Q \le 5 \times 10^5$$$
Input

Input is given in the following format:

Line $$$1$$$: $$$N\ Q$$$

Line $$$1 + i$$$ $$$(1 \le i \le Q)$$$: The $$$i$$$-th query, starting with its type $$$t$$$, represented as one of the following:

  • 1
  • 2 $$$f$$$ $$$(1 \le f \le N)$$$
  • 3 $$$s$$$
Output

For every query of type , print the number of people that have seen the message with id $$$s$$$.

Scoring
GroupAdd. constraintsPoints
$$$1$$$$$$N = 1$$$$$$10$$$
$$$2$$$$$$N,Q \le 5000$$$$$$20$$$
$$$3$$$All type 3 queries appear after all other queries$$$30$$$
$$$4$$$No additional constraints$$$40$$$
Example
Input
4 11
1
1
2 1
3 1
1
1
2 2
3 1
2 3
2 4
3 4
Output
1
2
3
Note

Query types:

  • If $$$t = 1$$$, Aritro sends a message in the group chat.
  • If $$$t = 2$$$, another integer $$$f$$$ $$$(1 \le f \le N)$$$ is given. Friend $$$f$$$ comes online and reads every message sent beforehand.
  • If $$$t = 3$$$, another integer $$$s$$$ is given. Aritro asks how many friends have seen the message with the id $$$s$$$.

Explanation of the Example:

  • Query 1: Aritro sends a message. It is assigned id $$$1$$$.
  • Query 2: Aritro sends a message. It is assigned id $$$2$$$.
  • Query 3: Friend $$$1$$$ gets online. He reads the messages with id $$$1, 2$$$.
  • Query 4: Aritro asks how many friends have seen message with id $$$1$$$. Only friend $$$1$$$ has seen it. So, the answer is $$$1$$$.
  • Query 5: Aritro sends a message. It is assigned id $$$3$$$.
  • Query 6: Aritro sends a message. It is assigned id $$$4$$$.
  • Query 7: Friend $$$2$$$ gets online and reads the messages $$$1, 2, 3, 4$$$.
  • Query 8: Aritro asks how many friends have seen message with id $$$1$$$. Friends $$$1, 2$$$ have seen it. So, the answer is $$$2$$$.
  • Query 9: Friend $$$3$$$ gets online. He reads the messages with id $$$1, 2, 3, 4$$$.
  • Query 10: Friend $$$4$$$ gets online. He reads the messages with id $$$1, 2, 3, 4$$$.
  • Query 11: Aritro asks how many friends have seen message with id $$$4$$$. Friends $$$2, 3, 4$$$ have seen it. So, the answer is $$$3$$$.

C. Pepe & Minimum Summands
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Through the dark forests, crossing seven seas and thirteen rivers, Pepe has finally reached the mythical Island of Bika. There he found a cave. Some old saying says that whoever finds a cave on the Island of Bika and enters it never comes back alive, but Pepe is known as the most courageous in his village. So, he decides to enter it. There he finds a locked chest and a note beside it. The entrance immediately closes but fortunately Pepe had come with a torch. Pepe starts reading the note:

You are given two positive integers $$$n$$$ and $$$x$$$. There is an array $$$a$$$ consisting of $$$m$$$ non-negative integers. Let $$$m$$$ be the size of the array $$$a$$$. For each $$$i$$$ ($$$1 \le i \le m$$$), $$$a_i$$$ is the base of the $$$i$$$-th summand, and $$$x$$$ is the common exponent of every summand.

Formally,

$$$$$$n = a_1^x + a_2^x + \dots + a_m^x$$$$$$

Your task is to find the minimum possible value of $$$m$$$, i.e. the minimum possible size of $$$a$$$.

Pepe has to enter the answer and the array $$$a$$$ into the chest, which contains a smart lock system. It is said that the Island of Bika was once the greatest in technology.

Help Pepe get the treasure and escape the cave.

Constraints

  • $$$1 \le T \le 1000$$$
  • $$$1 \le n \le 10^5$$$
  • $$$1 \le x \le 10$$$

Subtasks

SubtaskPointsAdd. constraints
$$$1$$$$$$7$$$$$$x=1$$$
$$$2$$$$$$8$$$$$$2^x \gt n$$$
$$$3$$$$$$8$$$$$$m=2$$$
$$$4$$$$$$10$$$$$$x=2;1 \le n \le 100$$$
$$$5$$$$$$14$$$$$$ 1 \le n \le 1000$$$
$$$6$$$$$$25$$$$$$ 1 \le n \le 10^5;2\le x \le 3$$$
$$$7$$$$$$28$$$No additional constraints
Input

Each test file contains multiple test cases. The first line of the input contains the number of test cases $$$T$$$. Then, for each test case, the input is given in the following format:

  • line 1: $$$n \ x$$$
Output

For each test case, if it is possible, output the minimum possible value of $$$m$$$ and a sequence of numbers that achieves the answer in the following format:

  • line 1: $$$m$$$
  • line 2: the sequence of numbers separated by spaces, or more formally $$$a$$$, in non-decreasing order.

If it is possible, but you do not output the sequence, output the following:

  • line 1: $$$m \, -1$$$

If there is no possible answer, output the answer in the following format:

  • line 1: $$$-1 \, -1$$$
Scoring
  • If you choose not to print the sequence of numbers for any test case but provide the correct answer $$$m$$$, you will receive $$$50\%$$$ of the subtask's score
  • If you choose to print the sequence, but it is incorrect, you will receive $$$0$$$ points for that subtask.
  • Otherwise, you will receive full score for the subtask.
Example
Input
4
65 2
10 3
1024 10
12 8
Output
2
1 8 
3
1 1 2 
1
2 
12
1 1 1 1 1 1 1 1 1 1 1 1 
Note

Example 1

Input


4
65 2
10 3
1024 10
12 8

Partially Correct Output


2 -1

Correct Output


2
1 8
3
1 1 2
1
2
12
1 1 1 1 1 1 1 1 1 1 1 1

Explanation of Example 1:

  • Test Case 1 ($$$n = 65$$$, $$$x = 2$$$): A possible array is $$$a = [1, 8]$$$, because $$$65 = 1^2 + 8^2$$$.
  • Test Case 2 ($$$n = 10$$$, $$$x = 3$$$): A possible array is $$$a = [1, 1, 2]$$$, because $$$10 = 1^3 + 1^3 + 2^3$$$.
  • Test Case 4 ($$$n = 12$$$, $$$x = 8$$$): The only possible array is $$$a = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]$$$, because: $$$$$$12 = 1^8 + 1^8 + 1^8 + 1^8 + 1^8 + 1^8 + 1^8 + 1^8 + 1^8 + 1^8 + 1^8 + 1^8$$$$$$