CF-2168C•Codeforces

Intercepting Butterflies

bitmaskscommunicationconstructive algorithmsgraphsinteractive

This problem is a run-twice (communication) problem.

Alice has an integer xx where 1≤x≤2151≤x≤215, which she needs to send to Bob (an astronaut on the Moon) as it is an important parameter for their secret project on the Moon.

Fortunately, Alice has a secret storage device SS, which contains a not necessarily non-empty subset of the set {1,2,…,20}{1,2,…,20}. She plans to send SS to Bob. Bob's goal is to recover the value of xx using only SS.

However, after Alice sends set SS on a spaceship and before Bob receives SS, magical butterflies had intercepted the spaceship! When Bob finally receives SS, one of the following had occurred:

  • An arbitrary element is removed from SS. This can only be done if SS is non-empty.
  • An arbitrary element is added to SS. This should still satisfy S⊆{1,2,…,20}S⊆{1,2,…,20}.
  • SS remained unchanged.

Please devise a strategy for Alice and Bob so that Bob can determine the value of xx regardless of what happened to set SS. Precisely, in this problem your code will be run exactly two times on each test. On the first run, you will act as Alice, and on the second Bob. No additional information other than the set SS can be transferred from Alice to Bob. To get an Accepted verdict, your code on the second run should be able to exactly recover the integers that were received on the first run.

First Run

Input

The first line of the input contains the string first. The purpose of this is so your program recognizes that this is its first run, and it should act as Alice.

The second line of the input contains exactly one integer tt (1≤t≤1041≤t≤104) — the number of test cases.

The first and only line of the ii-th test case contains an integer xx (1≤x≤2151≤x≤215).

Output

For each test case, send SS to Bob by printing two lines in the following manner.

  • On the first line, output an integer nn (0≤n≤200≤n≤20) — the size of SS.
  • On the second line, output nn space-separated integers S1,S2,…,SnS1,S2,…,Sn (1≤Si≤201≤Si≤20).

Exceptionally, you may omit the second line if n=0n=0. You may output elements of SS in any order. However, they must be pairwise distinct.

Then, you will either proceed to the next test case, or your program must terminate if you have processed every test case.

Second Run

Input

The first line of the input contains the string second. The purpose of this is so your program recognizes that this is its second run, and it should act as Bob.

The second line of the input contains exactly one integer tt (1≤t≤1041≤t≤104) — the number of test cases. Note that this number is equal to tt from the first run input.

The first line of each test case contains an integer n′ (0≤n′≤20) — the size of the set S′ that Bob receives, that is, possibly modified S.

The second line of each test case contains n integers S′1,S′2,…,S′n (1≤S′i≤20) — the elements of the S′ that Bob receives. The elements of S′S' are sorted in increasing order, even if the original SS is not sorted in increasing order.

Note that the test cases in the second run may be shuffled. Please see the example input for more details.

Output

For each test case, print a single line with the value of x (1≤x≤215).

Note

First run: The input contains four test cases with x=1,20,50,32768. According to some strategy agreed upon beforehand, Alice sends ∅ to Bob for x=1, the set {13,4,9} for x=20, the set {1,7,4,2} for x=50, and {14,17,1,6,2,19,20,8,7,18} for 32768.

Second run: Note that the test cases from the first run are shuffled. They are given in the order [20,32768,1,50].

For the first test case, the element 5 is added to Alice's set. Note that although Alice gave the initial set as {13,4,9}, the set was given in increasing order to Bob.

For the second test case, the number 20 was removed from Alice's set.

For the third test case, the set was unchanged.

Sample 1
Input
first
4
1
20
50
32768
Output
0

3
13 4 9 
4
1 7 4 2
10
14 17 1 6 2 19 20 8 7 18
Sample 2
Input
second
4
4
4 5 9 13
9
1 2 6 7 8 14 17 18 19
0

5
1 2 3 4 7
Output
20
32768
1
50

Discussions & Comments

Share your approach or ask questions about this problem (0)

You must be logged in to comment or start a discussion on this problem.

Log In

No comments yet. Be the first to comment!

Actions

Open on Codeforces

About Platform

CO
Codeforces
External Judge

Problem Discussions

0

Have questions or want to share your solution approach? Join the discussion.

View / write comments