We are given: Vasya can sum pairs of integers (a,b) such that for any decimal place at least one number has digit 0 in this place. So condition: For each digit position (units, tens, hundreds, ...), at least one of the two numbers has digit 0 in that position. Equivalent to: For every digit position i, digit_i(a) * digit_i(b) == 0? Actually condition: for any decimal place at least one number has digit 0 in this place. So for each position, either a's digit is 0 or b's digit is 0. So they cannot both have non-zero digits in the same place.
We have a set of k distinct non-negative integers (0 ≤ di ≤ 100). Actually di up to 100 (inclusive). So numbers are small, up to 100. But could also be 0, 1, 10, 100, etc. Problem: Choose some integers from this set so that he could sum any two chosen numbers. That means the chosen subset must be pairwise "compatible": for every pair (a,b) from the subset, they satisfy the digit condition (i.e., at each decimal digit, at least one has 0). Note that summing is not the key; just that any two chosen numbers can be summed (i.e., they are allowed to be summed). So we need a subset where every pair satisfies condition.
We need maximal size of such subset.
Because numbers are small (≤100), we can brute force. But we can also reason about structure.
Observation: Condition is symmetric. For numbers with digits, it's like no two numbers have a non-zero digit in the same position. So if we consider the set of positions where a number has non-zero digits, we require that for any two numbers, these sets are disjoint? Let's check: If number A has non-zero digit at position i, and number B also has non-zero digit at same position i, then at that position both have non-zero digits, so condition fails. Conversely, if for every i, at most one of the numbers has non-zero digit at i, then condition holds. However, is it necessary that they are completely disjoint? Consider A has digit 0 at position i, B has digit any (including non-zero). That's okay because at least one is 0. So condition is: For each i, NOT (A_i != 0 AND B_i != 0). So the sets of positions where digit is non-zero must be pairwise disjoint for the whole subset. Actually, it must hold for every pair: if any two numbers share a non-zero digit position, that pair violates condition. So the subset must be such that the non-zero digit position sets are pairwise disjoint. Because if two numbers share a position where both have non-zero, that pair fails. But it's possible that three numbers could have pairwise disjoint sets? Actually if the sets are pairwise disjoint, then obviously any pair satisfies. If they are not pairwise disjoint, there exists a pair that shares a position and both have non-zero there? Wait careful: Suppose numbers A and B share a position i where both have non-zero digits. Then the pair (A,B) fails. So for the subset to be valid, no pair can share a non-zero position. So the sets of non-zero positions for all numbers in the subset must be mutually disjoint. That's necessary and sufficient.
Therefore, problem reduces: Given numbers up to 100 (so digits positions: units, tens, hundreds; because 100 is maximum, also 0). Actually numbers can be up to 100 inclusive, so max is 100, which is three digits: hundreds (10^2), tens (10^1), units (10^0). Possibly also 0 is special, all digits are zero? 0 has no non-zero digits. So its set is empty. So 0 can coexist with any number because for any position, at least one (0) has digit 0; actually 0 has digit 0 in all positions. So condition holds trivially. So 0 can be included with any others.
Now, each non-zero number (1 to 100) has digits in up to three positions. But condition: For any two numbers, their non-zero positions must be disjoint. So essentially, we are selecting numbers such that the positions with non-zero digits are all distinct across numbers (except zero which doesn't occupy any). But note that a number may have multiple non-zero digits (e.g., 101 has non-zero digits at hundreds and units). Then if we include such a number, it occupies both positions, meaning no other number can use either of those positions. So numbers with multiple non-zero digits are more restrictive.
We want the maximum size subset. Since there are only 3 digit positions (units, tens, hundreds) that can be "occupied", the maximum number of non-zero numbers we can include is limited by the number of positions? But if we include numbers that each occupy exactly one position, we could have up to 3 numbers (one for units, one for tens, one for hundreds). If we include numbers that occupy multiple positions, we might reduce capacity. Also we can include 0 as well, since 0 doesn't occupy any position. So the maximum size is at most (number of positions) + 1? Actually, zero is not counted in positions. But also there could be multiple numbers that occupy no positions? Only zero has all digits zero. But other numbers like? 0 is the only number that has all digits zero? Actually numbers like 0, and maybe 00? But input numbers are integers, so only 0 has all digits zero. So only one number 0 can occupy no positions. However, if we have zero, we can include it. So maximum size could be up to 4? Because we could have 0 plus one number occupying units, one occupying tens, one occupying hundreds: that's 4. But wait: Are there numbers that have non-zero digits only at units? Yes, e.g., 1,2,...,9. Only units digit non-zero, tens and hundreds zero. For tens only: 10,20,...,90. For hundreds only: 100 (since 100 has digits: hundreds=1, tens=0, units=0). So we could have 0, 1, 10, 100. That's exactly the first example: they selected all 4. So maximum size 4.
But can we have more than 4? Suppose there are numbers like 0, 1, 2? But 1 and 2 both have non-zero unit digit, they conflict because both have non-zero at units. So cannot both be in subset. So indeed maximum is bounded by number of digit positions (3) plus maybe zero (1) = 4. However, is there any possibility of more than 4 by using numbers that have no overlapping positions but also numbers that have zero digits in all positions? Only zero qualifies. So maximum subset size is at most 4. But input k up to 100, numbers up to 100, so we can simply check if we can get 4; else 3; else 2; else 1; else 0? But at least one can be chosen. But we need to output maximum number.
But careful: Could there be numbers like 0, 1, 11? 11 has non-zero at units and tens, so it occupies two positions. If we include 11, we cannot include any other number that has non-zero at units or tens. So we could have 11 and 100 and 0? That would be 0, 11, 100. That's 3 numbers. So 4 is only possible if we have at least one number for each position (units, tens, hundreds) that are disjoint, plus possibly 0. But we could also have 4 numbers without zero? But zero is one number; if we don't have zero, maximum could be 3 (one per position). So maximum size is either 4 (if zero present and we have numbers for each of units, tens, hundreds that are pairwise disjoint and also not overlapping each other's positions), or 3 (if either zero absent but we can cover three positions with disjoint numbers; or zero present but we cannot cover all three positions with disjoint numbers; but maybe we can cover all three positions with disjoint numbers and also include zero? That would be 4. Or could we get 3 without covering all positions? Possibly if we choose zero and two numbers that occupy disjoint positions, that's 3. But 3 is also possible with three non-zero numbers disjoint covering three positions. So the maximum size can be at most 4.
Thus the problem is simple: find the largest subset satisfying pairwise disjoint non-zero digit sets. Since numbers are small, we could just iterate over all subsets up to 4? But we can compute by checking compatibility.
But careful: There might be numbers beyond 100? Input says di ≤ 100. So indeed max 100. So digits positions: ones (10^0), tens (10^1), hundreds (10^2). That's it. So the condition reduces to: For any two numbers a and b, for each of the three positions, not (digit_a(pos) !=0 and digit_b(pos) !=0). So a binary condition: (digit_a1 & digit_b1) ==0, similarly for tens, hundreds. But since digits are decimal, but condition only cares about zero vs non-zero, we can treat it as boolean: for each position, if both numbers have a non-zero digit (1-9) then conflict.
Thus we can model each number as a bitmask of length 3 indicating which positions have non-zero digits. Then condition for two numbers: bitwise AND of masks must be 0.
So we need a subset of numbers such that masks are pairwise AND=0.
Now, since mask can be 0 (for 0), 001 (units), 010 (tens), 100 (hundreds), 011 (units+tens), 101 (units+hundreds), 110 (tens+hundreds), 111 (all three). But note: numbers like 101: digits: hundreds=1, tens=0, units=1 -> mask 101 (bits 2 and 0). That's possible if number is e.g., 101? But max is 100, so numbers only up to 100. So possible numbers: from 0 to 100 inclusive. So which masks appear?
- 0: mask 000
- 1-9: units only -> 001
- 10,20,30,...,90: tens only -> 010
- 100: hundreds only -> 100
- Numbers with two non-zero digits? For numbers between 1 and 99: e.g., 11? But 11: units=1, tens=1 -> mask 011. So yes, numbers like 11, 12, 13, ... 99 except those with zero digits. So e.g., 23: tens=2, units=3 -> both non-zero -> mask 011. Also numbers like 101 is >100, not allowed. 100 is exactly 100, mask 100. So numbers with hundreds digit only if number is 100 (hundreds=1, tens=0, units=0). If number is e.g., 101 not allowed. So the only number with hundreds digit non-zero is 100? Actually numbers 1-100: 100 is only three-digit number. Also numbers like 0-99: hundreds digit is 0. So hundreds digit non-zero only for 100? Wait, numbers 101 to 999 are not in range because di ≤ 100. So indeed only 100 has hundreds non-zero. So the mask 100 only appears for 100. Mask 001 appears for numbers 1-9, and also for numbers like 101? Not allowed. But also numbers like 1,2,...,9. Also numbers like 001? Actually 0 is mask 000. Also numbers like 10? 10: tens=1, units=0 -> mask 010. Numbers like 20,30,...,90. So what about numbers like 110? Not allowed (110>100). So the only possible mask with hundreds is 100 (only 100). Also mask with hundreds and something else would require number >=101, not allowed. So numbers with mask 101 (hundreds+units) not possible because smallest such number is 101 (like 101) or 102 etc, all >100. Similarly mask 110 (hundreds+tens) would be numbers like 110 (>=110) >100, so not possible. Mask 111 would be >=111 >100. So the only possible masks are: 000, 001, 010, 011, 100? Wait 011 is possible for numbers like 11,12,...,99 (but also includes numbers like 10? No, 10 is 010, 1 is 001, 11 is 011). So 011 is possible. But note: numbers like 11: tens digit=1, units digit=1, both non-zero -> mask 011. Also 22, etc. Also numbers like 101? not allowed. So actually allowed masks: 000 (0), 001 (1-9), 010 (10,20,...,90), 011 (any two-digit number from 11 to 99 that doesn't have zero digit? Actually numbers like 12,13,...99 where both digits are non-zero; also 10? no, 10 has units zero -> mask 010; 20 has units zero -> mask 010; 30 etc; 101? not allowed; 100? mask 100. So also mask 011 includes many numbers. Also could there be mask 100 only for 100. And mask 001 for 1-9. So there is no mask 101,110,111. So the only masks with bit 2 (hundreds) set is exactly 100, and that bit cannot coexist with any other bit in the same number because numbers >100 not allowed. So essentially hundreds position is exclusive to 100, and if we include 100, then no other number can have a non-zero digit at hundreds. But any other number (except 100) has hundreds digit 0. So that's fine: 100's mask 100, and any other number has hundreds digit zero, so they are compatible as long as the other numbers don't conflict with each other in units/tens. But note: 100 is compatible with numbers that have non-zero digits only in units and/or tens? Condition: For each position, at least one has zero. For hundreds: 100 has non-zero (1) but others have 0, so OK. For tens: 100 has 0, so it's fine whatever the other number's tens digit (even non-zero). For units: 100 has 0, so it's fine. So 100 is compatible with any number that does not have a non-zero digit in hundreds? But all other numbers have hundreds digit 0 anyway. So 100 is compatible with all numbers except maybe if some number also has non-zero hundreds? But there is none. So actually 100 is compatible with every other number (including numbers with units and tens non-zero) because its non-zero digit is only hundreds, and all other numbers have hundreds zero. So 100 is universally compatible with any number? Check with 0: fine. With 1: fine. With 10: fine. With 11: 11 has non-zero units and tens; 100 has zero in those positions, so fine. So indeed 100 is compatible with all numbers in the range (since no other has non-zero hundreds). So 100 can always be included if present, without conflict regarding hundreds.
But wait: What about numbers like 100 and also something like 100? But they are distinct, so only one 100. So fine.
Now, what about numbers with mask 011 (both units and tens non-zero)? Those numbers occupy both units and tens positions. That means they conflict with any number that has non-zero units OR non-zero tens. So they conflict with numbers like 1-9 (units), 10-90 (tens), and also other numbers with mask 011 (since they also have non-zero both). So including a number with mask 011 essentially blocks both units and tens positions. So then we can't include any other number that uses units or tens. But we could still include 100 and 0. So if we include a number with mask 011, the maximum size might be: that number + 100 (if available) + 0 (if available) = up to 3. Could we also include another number that has no non-zero digits? Only 0. So yes.
Similarly, numbers with mask 001 block units, mask 010 block tens.
Thus the problem reduces to: we have a set of numbers with masks:
- mask 000: only 0 (maybe multiple? but only one 0, distinct numbers)
- mask 001: numbers 1-9 (units)
- mask 010: numbers 10,20,...,90 (tens)
- mask 011: numbers 11-99 where both digits non-zero (i.e., not multiples of 10, and not 0)
- mask 100: number 100
Note: There could also be numbers like 0? Already mask 000. Also could there be numbers like 101? Not allowed.
We need largest subset where masks are pairwise AND=0.
Observations:
- mask 100 is compatible with all masks except maybe another mask with hundreds set, but there is only 100 itself; since distinct numbers, we cannot have two copies, but we could have at most one 100. So 100 can always be added without conflict if it exists.
- mask 000 is compatible with everyone (AND always 0). So 0 can always be added if present.
- mask 001 and 010 conflict with each other? Check: 001 & 010 = 0? Actually bits: 001 (bit0) and 010 (bit1) have no overlap, so they are compatible! Because one has non-zero only in units, the other only in tens. The condition requires that for each decimal place at least one has digit 0. For units: the number with mask 001 has non-zero, the one with mask 010 has 0 => OK. For tens: the 010 has non-zero, 001 has 0 => OK. For hundreds: both 0 => OK. So they are compatible. So we can have both a units-only number and a tens-only number together. Good.
- mask 001 and 001 conflict (both have units non-zero) -> cannot have two units-only numbers.
- mask 010 and 010 conflict.
- mask 011 conflicts with 001 (units overlap), with 010 (tens overlap), and with other 011 (both overlap). But compatible with 100 and 0.
Therefore, the maximal subset will consist of:
- Possibly include 0 (if present)
- Possibly include 100 (if present)
- Then among the remaining numbers, we can include at most one number from the "units-only" group (mask 001) and at most one from the "tens-only" group (mask 010), and possibly one from the "both units and tens" group (mask 011) but if we include a mask 011, we cannot include any units-only or tens-only.
Thus the maximum size achievable is:
- If we have 0: +1
- If we have 100: +1
- Then from the group {units-only, tens-only, both} we can add numbers such that we either add at most two (one units-only and one tens-only) OR add at most one (one both). Because units-only and tens-only are compatible with each other but not with both. So the best choice is to take the larger of: (number of available units-only? at most 1 if any) + (number of available tens-only? at most 1 if any) vs (1 if any both exists). Actually we can also take just one of units-only or tens-only if both not available, etc. So the maximum additional count from those groups is max( (min(1, hasUnits) + min(1, hasTens) ), (min(1, hasBoth) ) ). But careful: There might be multiple numbers in units-only group, but we can only take at most one because any two units-only conflict. Similarly for tens-only. So effectively we can take at most 1 unit, at most 1 ten, and at most 1 both. The best combination is: either take a both (if exists) or take a unit and a ten (if both exist). Which gives count 1 vs 2. So obviously, if we can take both a unit and a ten, that yields 2, which is larger than 1 from both. So we would prefer to take a unit and a ten rather than a both, provided that we have at least one unit and one ten available. But is it always possible to take a unit and a ten simultaneously? Yes, because they are compatible. So if there exists at least one unit-only number and at least one tens-only number, we can add two numbers from these groups. If we have a both, but also have a unit and a ten, the both would conflict with both, so we cannot include both the both and either unit or ten. So we must choose either the both alone, or the pair (unit, ten). The pair gives 2 numbers, both gives 1 number. So pair is better.
Thus maximum total size = (include0?1:0) + (include100?1:0) + max( (hasUnit?1:0)+(hasTen?1:0), (hasBoth?1:0) ).
But wait, is it possible to also include a number that is both units and tens? That we accounted as hasBoth. Could there be numbers like 100? Already handled. Also note: Could there be numbers like 0? already handled. So that seems correct.
But what about numbers like 0? If 0 present, it's always included because it doesn't conflict with anything. So we should always include 0 if it exists, because it only increases size. Similarly, 100 is compatible with everyone, so we should always include 100 if it exists. So indeed we can always include 0 and 100 if available.
But careful: Could there be a scenario where including 0 or 100 might prevent us from including something else? No, because they are compatible with all. So we can always include them without any restrictions. So yes, always include them if present.
Thus the subset we construct:
- include all zeros? Actually there is exactly one zero (0). Input has distinct integers, so at most one 0. So include if present.
- include 100 if present.
Now from the remaining numbers (excluding 0 and 100), we need to choose a subset that maximizes count under pairwise AND=0, with the condition that we can choose at most one from units-only, at most one from tens-only, and at most one from both, but both conflicts with units and tens. So optimal is either choose a unit and a ten (if both types exist), else if only one of unit or ten exists, choose that one; else if only both exists, choose one both; else choose none. But also note that there may be multiple numbers in units-only group; we can choose any one. Similarly for tens-only, any one.
But we must also consider numbers that are not of these types? Actually all numbers from 1 to 99 are either units-only (1-9), tens-only (multiples of 10: 10,20,...,90), or both (11-99 except multiples of 10). So that's exhaustive. So indeed.
Thus the maximal size is determined by existence.
But is there any nuance: Could we include a number that is both units and tens, and also include 0 and 100? That's 3. But if we also have a unit and a ten, we could have 0 + 100 + unit + ten = 4. So 4 is the maximum possible. Indeed, maximum subset size is at most 4. So answer is either 4, 3, 2, 1, or 0? But k≥1 so at least 1.
Now, we need to output the numbers. We need to output any maximal subset.
Thus algorithm:
- Read k.
- Read list d.
- Separate numbers into categories:
zero = False (if 0 present)
hundred = False (if 100 present)
units = [] (numbers 1-9)
tens = [] (numbers 10,20,...,90)
both = [] (numbers 11-99 that are not multiples of 10 and not 0,1-9? Actually 11-99 inclusive, except multiples of 10, and also note numbers 1-9 already covered, 10-90 multiples of 10 covered)
- But careful: numbers like 1-9: units; 10,20,...,90: tens; 11-19 except 10? 11-19 all have tens digit 1 (non-zero) and units non-zero (unless 10). So they are both. Similarly 21-29, etc. So yes.
- Also numbers like 0 and 100 handled separately.
Now construct subset:
- Start empty list result.
- If zero present: add 0.
- If hundred present: add 100.
- Now decide among units, tens, both:
Option1: if units non-empty and tens non-empty: add one from units and one from tens.
Option2: else if units non-empty: add one from units.
Option3: else if tens non-empty: add one from tens.
Option4: else if both non-empty: add one from both.
(If none, add nothing)
But wait, is there any scenario where adding a both might be better than adding just a unit when tens empty? If both exists and units exists but tens empty, we have: option add unit => total size = 1 (from unit) plus zero/hundred; option add both => total size = 1 (from both). Both same. So either is fine. Similarly if only tens exists. So we can just do: if units and tens both exist, add one each; else if units exists, add one; else if tens exists, add one; else if both exists, add one. But careful: Could there be a scenario where units exists but tens does not, and both exists, and adding both yields same size as adding unit? So it's arbitrary. But we must ensure maximal size: any of these choices yields same total count. So we can pick arbitrarily.
But wait, consider scenario where we have units and both exist, but no tens. Options:
- Add unit: total +1.
- Add both: total +1.
Both give same total. So okay.
But also scenario where we have both but we also have units and tens? Then we prefer units+tens because it gives +2 > +1, so that's better. So we need to ensure we choose that when possible.
Thus algorithm as above.
Edge cases:
- If zero and hundred present, and units and tens present, result size 4.
- If zero present, hundred not present, units and tens present, size 3.
- If zero not present, hundred present, units and tens present, size 3.
- If zero present, hundred present, but no units/tens, but both present, size 3? Actually zero + hundred + both = 3.
- etc.
But also check: Could we include both zero and hundred and also both (the both) and also something else? No, because both blocks units and tens, but zero and hundred are fine. So size 3.
Thus answer is straightforward.
But wait, is there any possibility to include two numbers from both group? No, they conflict because they both have non-zero units and tens, so overlap.
Could we include two numbers from units group? No, they conflict.
Could we include two numbers from tens group? No.
So the maximum is as described.
But hold on: Could we include a number that is 0? That's only one. Could we include two numbers that are 0? No, distinct numbers.
Thus solution is trivial.
But need to be careful about numbers: is 0 considered to have digit 0 in all places? Yes. So it's fine.
Now we need to output n and then the numbers in any order.
We should check if there is any trick: The condition says: "Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place." It does not specify that numbers must be represented without leading zeros. But that's standard.
Now, let's test with examples:
Example 1: 4 numbers: 100, 10, 1, 0.
- zero present -> add 0.
- hundred present -> add 100.
- units: [1] ; tens: [10]; both: [].
- units and tens both exist -> add 1 and 10.
Result: 0,100,1,10 -> size 4. Order any. Output matches.
Example 2: 3 numbers: 2,70,3.
- zero? no. hundred? no.
- units: [2,3] (both 1-9). tens: [70]? 70 is tens? 70 is 70, tens digit 7 (non-zero), units digit 0 -> so it's tens (multiple of 10). So tens: [70]. both: [].
- units and tens exist -> add one from units and one from tens. Since there are two units, we need to choose one. Possibly output 2 and 70 or 3 and 70. That yields size 2. Output: 2,70 (or 3,70). The example output: 2 and 70. So matches.
Now, what about a case: k=2, numbers: 11, 0.
- zero present -> add 0.
- hundred? no.
- units: [] (since 11 not units, it's both). tens: [] (since not multiple of 10). both: [11].
- units and tens not both, units empty, tens empty, both present -> add one from both (11).
Result: {0,11} size 2. Is that valid? Check condition: 0 and 11: For each decimal place, at least one has 0. 0 has 0 in all places, so ok. So size 2. Could we get size 2? Yes.
Case: k=2: 11, 22. Both are both. Only one can be selected because they conflict (both have non-zero units and tens). So max size 1. Our algorithm: zero? no. hundred? no. units? no. tens? no. both exists: add one from both, say 11. size 1. Good.
Case: k=2: 1,2. Both units. Only one can be selected -> size 1. Our algorithm: zero? no. hundred? no. units exist -> add one unit (size 1). But we have two units; we add only one. That's correct.
Case: k=3: 0, 100, 11. zero+100+both=3. Our algorithm: include 0, include 100, then both exists, units/tens not both? Actually units empty, tens empty, so we add both -> 11. size 3. Good.
Case: k=3: 0, 1, 10 -> zero+unit+ten =3. Our algorithm: zero present, hundred? no. units and tens exist -> add unit and ten -> plus zero gives 3. Good.
Case: k=4: 0,100,1,10 -> 4.
Case: k=4: 0,100,1,11 -> Here we have zero, hundred, unit(1), both(11). Options: If we add both, we cannot add unit. So we need to decide: units and tens? tens missing. So we have units and both. Which gives larger total? With units: zero+100+unit =3. With both: zero+100+both =3. Both yield 3. But can we get 4? Possibly if we include unit and ten, but ten not present. So max is 3. Our algorithm: since tens empty, we will go to else if units exists: add one unit. So result: 0,100,1 -> size 3. That's correct.
But wait, could there be a better combination: maybe we could include both and also something else? No, because both conflicts with unit. So max 3.
Now, is there any scenario where we might want to exclude 0 or 100 to allow more numbers? Since 0 and 100 are compatible with everyone, excluding them cannot increase the count; it would only decrease. So always include them.
Thus answer seems straightforward.
But let's double-check the problem statement: "Vasya wants to choose some integers from this set so that he could sum any two chosen numbers." That means the subset must be such that for every pair (a,b) in the subset, the condition holds. It doesn't say that he must be able to sum them in any order, but it's symmetric. So our condition is correct.
Now, we need to output the subset. So we need to pick specific numbers.
Implementation steps:
- Read input.
- Initialize lists: unit_list = [], ten_list = [], both_list = [].
Also bool zero = False, hundred = False.
- Iterate through numbers:
- if d == 0: zero = True.
- elif d == 100: hundred = True.
- elif 1 <= d <= 9: unit_list.append(d)
- elif d % 10 == 0 and 10 <= d <= 90: ten_list.append(d) (since d <= 99). Actually numbers like 100 already handled. So condition: d % 10 == 0 and 10 <= d <= 90.
- else: both_list.append(d) (should be numbers 11-99 not multiples of 10). But ensure d is within 1..99 and not in previous categories. Could also be d=0? no. d=100? handled. So else.
But careful: Could there be numbers like 0? Already. Could there be numbers like 10? That's tens. 20,30,...,90. So fine. What about number like 100? Already. So else captures both.
But what about number like 1? That's unit. 2,3,...,9. So fine.
Edge: number 0 is zero.
Now construct result list:
result = []
if zero: result.append(0)
if hundred: result.append(100)
Now decide:
if unit_list and ten_list:
# add one from unit and one from ten
result.append(unit_list[0]) # pick any, say first
result.append(ten_list[0])
elif unit_list:
result.append(unit_list[0])
elif ten_list:
result.append(ten_list[0])
elif both_list:
result.append(both_list[0])
else: nothing more
But is this always maximal? Let's test scenario: no zero, no hundred, units exist, tens exist -> add both unit and ten => size 2. That's maximal? Could there be a both that yields size 2? No, both alone gives 1. So good.
Scenario: zero present, hundred present, units exist, tens exist => we get 4. Good.
Scenario: zero present, hundred present, units exist, both exist (but no tens). Our algorithm: unit_list and ten_list? ten_list empty, so falls to elif unit_list: add unit. So result: zero, hundred, unit => size 3. But could we instead do zero, hundred, both => also size 3. So both give same size. So it's fine.
But consider scenario: zero present, hundred present, tens exist, both exist (no units). Similarly size 3.
Scenario: zero present, hundred absent, units exist, tens exist => zero + unit + ten = 3. Good.
Scenario: zero absent, hundred present, units exist, both exist => hundred + unit = 2 (since ten absent, we go to elif unit_list: add unit). But could we get hundred + both = 2 as well? same size. So okay.
Thus algorithm works.
But one nuance: Could there be a number like 0 and 100 and also numbers like 1 and 11? We have unit_list = [1], both_list = [11]. According to algorithm, we add 0,100, then check unit_list and ten_list? ten_list empty, so we go to elif unit_list: add 1. So result size 3. Could there be a subset of size 4? 0,100,1,11? Check compatibility: 1 and 11 conflict because both have non-zero units (1 has units=1, 11 has units=1) -> both non-zero at units, so condition fails. So cannot have both. So max 3. Good.
Now check scenario: zero present, hundred absent, units exist, tens exist, both exist. Our algorithm adds zero + unit + ten = 3. Could we instead do zero + both = 2? So 3 is max.
Now scenario: zero absent, hundred absent, units exist, both exist. algorithm: unit_list and ten_list? ten_list empty -> add unit => size 1. Could we do both => also size 1. So ok.
Thus solution is correct.
But wait, is there any scenario where we can include more than one number from both group if they have disjoint non-zero digits? But both group numbers always have non-zero digits in both units and tens. So any two both numbers will conflict at both units and tens (since both have non-zero in those places). Therefore they cannot coexist. So only one.
But what about numbers like 101? Not allowed, as per constraints. So no.
Thus answer is simple.
But let's double-check the definition of decimal places. For numbers less than 100, we consider hundreds digit as 0. So condition holds.
Now, is there any tricky case where a number like 0 is included, but also numbers like 0? Only one zero.
Edge case: If the set contains only 0? Then zero true, hundred false, no others. result: [0] size 1. Correct: Can sum 0+0? But we need any two chosen numbers. If only one number, there are no pairs, so condition vacuously true? Usually "any two chosen numbers" means for every pair (if there is at least two). With one number, there are no pairs, so it's okay. So we can choose just that one.
If set contains only 100? result: [100] size 1. Good.
If set contains 0 and 100 and nothing else: size 2.
Now what about a number like 0 and 100 and 50 and 5? units: [5], tens: [50], both: none. So size 4? Actually 0,100,5,50 => all compatible? Check: 5 and 50: 5 has units=5, tens=0; 50 has tens=5, units=0; So condition holds: For units: 5 non-zero, 50 zero -> ok; tens: 5 zero, 50 non-zero -> ok. So yes. So size 4. So our algorithm gives 0,100,5,50.
Now test scenario: 0,100,5,55. units: [5]; tens: []; both: [55] (since 55 is both). Our algorithm: zero, hundred, then (units and tens? tens empty) => add unit: 5. So result size 3. Could there be a better subset: 0,100,55 => also 3. So max 3.
Now scenario: 100, 10, 1, 0, 55. Here we have zero, hundred, unit (1), tens (10), both (55). Our algorithm: zero, hundred, unit, tens => size 4. But does 55 conflict with others? 55 with 1: conflict at units? 55 units=5 non-zero, 1 units=1 non-zero -> both non-zero => conflict. So cannot have both 55 and 1. But we are not including 55. Our subset is 0,100,1,10 which is valid. So max 4? Check if we could include 0,100,55, maybe also something else? 0,100,55 is 3; adding 1 or 10 conflicts. So max is 4 indeed. So algorithm picks 0,100,1,10.
Thus it's correct.
Now, what about numbers like 0,100, and also numbers like 7, 70, 77? We have units: [7], tens: [70], both: [77]. Our algorithm picks 0,100,7,70 => 4. Check compatibility: 7 and 70 are fine; 7 and 100 fine; 70 and 100 fine; 0 fine. So valid. Could we include 77 instead? That would conflict with 7 and 70. So 4 is max.
Now, consider scenario: 0,100, 7, 8? Both units, we have two units. Our algorithm includes 0,100, and then since tens empty, we go to elif unit_list: add unit_list[0] (7). So result: 0,100,7 => size 3. Could we do 0,100,7,8? 7 and 8 conflict (both have non-zero units). So cannot. So max 3.
Thus correct.
Now, are there any numbers that have mask 000 other than 0? No, because any positive number has at least one non-zero digit. So only 0.
Thus solution seems trivial. However, the problem statement says numbers are up to 100, but what about numbers like 0? Yes. So answer is always at most 4.
But wait, what about numbers like 101? Not allowed as per constraint. So fine.
Now, implementation details: we need to output n and then the chosen numbers. The numbers are distinct, and we should output distinct numbers from the set. We can pick any representative from unit_list, ten_list, both_list. For reproducibility, we can pick the smallest or first encountered.
Edge: It's possible that both zero and hundred are present, and we have both unit and ten, but also there might be a both number; but we choose unit+ten anyway because it gives +2.
But what if unit_list or ten_list have multiple entries? We pick one.
Now, is there any scenario where it's better not to include zero or hundred? Suppose zero is present and we have a both number, but we also have units and tens? Actually zero and hundred are always compatible, so including them never hurts. So always include.
Thus solution is done.
But wait: Are there any numbers that have mask 000 besides 0? Possibly 0 is the only one. But what about leading zeros? No.
Now, final check: The problem says "k distinct non-negative integers d1, d2, ..., dk (0 ≤ di ≤ 100)". So numbers can be 0 to 100 inclusive. So all good.
Thus the solution is extremely simple.
But the problem might be originally from Codeforces and the solution is indeed to check these categories. Many solutions online just do: if there is 0, include it; if there is 100, include it; then from 1-9 include one; from 10,20,...,90 include one; if none of those exist, include one from 11-99. That's exactly the approach.
Thus we can implement.
Now we need to output n and the numbers.
Let's write code.
Pseudo:
def solve():
import sys
data = sys.stdin.read().strip().split()
if not data:
return
k = int(data[0])
arr = list(map(int, data[1:]))
zero = False
hundred = False
units = []
tens = []
both = []
for x in arr:
if x == 0:
zero = True
elif x == 100:
hundred = True
elif 1 <= x <= 9:
units.append(x)
elif x % 10 == 0 and 10 <= x <= 90:
tens.append(x)
else:
both.append(x)
result = []
if zero:
result.append(0)
if hundred:
result.append(100)
if units and tens:
result.append(units[0])
result.append(tens[0])
elif units:
result.append(units[0])
elif tens:
result.append(tens[0])
elif both:
result.append(both[0])
# Print
print(len(result))
if result:
print(' '.join(map(str, result)))
But need to be careful: What if units and tens both exist but we already added zero and hundred? That's fine. But what if we have both unit and tens but also both? We ignore both.
But is there any scenario where it's beneficial to include both instead of unit and ten when unit and ten exist? No, because unit+ten gives 2 numbers vs both gives 1. So we should definitely pick unit+ten.
Now, is it always possible to pick one from units and one from tens even if the set has many numbers? Yes.
Now, verify: In example 2, units = [2,3], tens=[70]; we pick units[0]=2, tens[0]=70. Output 2,70. Works.
Now, one nuance: Could there be numbers like 0 and 100 and also both, but also unit and ten. That yields 4 with unit+ten. That's correct.
Now, what about numbers like 0 and 100 and unit but no ten, and both. Then we add unit. But we might also be able to add both? No, because we can't have both unit and both. So 3 is max.
Thus final.
But wait, could we ever achieve size 4 without zero? For example, if we have hundred, unit, ten, and both? But both conflicts with unit and ten, so cannot have all three. So max 3. With zero, we can have zero, hundred, unit, ten => 4. So maximum possible size is 4 only if both zero and hundred are present, and at least one unit and one ten. Or if zero present and hundred not present, but we have unit, ten, and both? No, both conflicts with unit and ten. So max 3.
Now, check scenario: zero present, hundred present, units present, tens not present, both present. We get zero, hundred, unit => 3. Could we get zero, hundred, both => also 3. So max 3.
Thus the algorithm finds maximal size.
Now, what about scenario: zero present, hundred present, units not present, tens present, both present: similar.
Now, scenario: zero present, hundred present, units not present, tens not present, both present: zero, hundred, both => 3.
Now, scenario: zero present, hundred not present, units present, tens present => 3.
Now, scenario: zero not present, hundred present, units present, tens present => 3.
Thus maximum size can be 4, 3, 2, 1.
But is there any scenario where we could get 2 numbers from both group? No.
Thus solution is straightforward.
But double-check: For numbers that are "both", they may also be like 10? Actually 10 is tens, not both. So correct.
Now, consider number like 100? It's hundred only.
Now, is there any number like 0? yes.
Implementation: We'll parse input, categorize accordingly.
One more thought: The condition "for any decimal place at least one number has digit 0 in this place." Means we consider decimal places potentially infinite? Usually we consider the decimal representation without leading zeros. For numbers like 1 and 10: 1 has digits: units=1, tens=0 (implicitly). 10 has tens=1, units=0. So condition holds. For numbers like 0, it's all zeros. So fine.
Thus correct.
Now, complexity O(k) and trivial.
But wait: Could there be a case where we have multiple numbers in both group but we could select one that does not conflict with unit or ten? No, because any both conflicts with any unit or ten because both have non-zero units (conflict with unit) and non-zero tens (conflict with ten). So impossible.
Thus the algorithm is correct.
Now, final answer.
But let's also think if there is any scenario where a number like 100 and a number like 10 are both present, and also a number like 1, and also 0, then we have 4 numbers. That's the typical.
Thus solution is final.
Now, we can write the code accordingly.
But wait, the problem statement: "Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place." Could there be nuance with numbers having different number of digits? For example, number 5 has digits only up to units, while number 10 has digits up to tens. The decimal places considered: we should consider the max length of the two numbers? Usually when summing two numbers, we consider decimal places up to the maximum digit length. For places beyond the length of a number, we treat its digit as 0. So condition holds. So our interpretation is correct.
Now, final code.
We'll implement as described.
Potential pitfalls: Input might have numbers like 0, 100, etc. We'll handle correctly.
Now, output format: First line integer n, second line the numbers separated by spaces. Possibly trailing space is allowed, but we'll join without trailing.
Let's write in Python.
We'll read from sys.stdin.
Edge: If k=0? But k≥1.
Now, test with given examples.
Example 1:
Input:
4
100 10 1 0
Our code: zero=True, hundred=True, units=[1], tens=[10], both=[] -> result: 0,100,1,10 -> size 4. Output matches.
Example 2:
3
2 70 3
zero=False, hundred=False, units=[2,3], tens=[70], both=[] -> units and tens exist -> add 2 (first) and 70 -> size 2. Output 2 70. Matches.
Now, test with case: k=2, numbers 0 100 -> zero, hundred -> result: 0,100 -> size 2. Good.
Test with case: k=1, number 55 -> zero=False, hundred=False, units=[], tens=[], both=[55] -> result: 55 -> size 1. Good.
Test with case: k=5: 0 100 1 2 10 -> units=[1,2], tens=[10] -> result: 0,100,1,10 -> size 4. Could we also include 2? No, conflict with 1. So 4 is max.
Now, consider case: k=5: 0 100 1 10 55 -> same as before -> size 4.
Now, case: k=5: 0 100 55 66 77 -> units=[], tens=[], both=[55,66,77] -> result: 0,100,55 (first) -> size 3. Could we include two both? No. So max 3.
Now, case: k=5: 0 1 2 3 4 -> zero=True, hundred=False, units=[1,2,3,4], tens=[], both=[] -> result: 0, then since units and tens? tens empty -> elif units: add units[0]=1 -> total [0,1] size 2. But could we include more units? No. So max 2. But is there any subset of size 3? Possibly 0 and two units? Two units conflict. So max 2. So correct.
Now, case: k=5: 100 1 2 3 4 -> hundred=True, units=[1,2,3,4], tens=[] -> result: 100, then units[0]=1 -> size 2. Could we include 0? Not present. So max 2.
Now, case: k=5: 100 10 20 30 40 -> hundred=True, tens=[10,20,30,40] -> result: 100, tens[0]=10 -> size 2. Could we include two tens? No. So max 2.
Now, case: k=5: 0 100 10 20 30 -> zero, hundred, tens (multiple) -> result: 0,100,10 (plus maybe? we have units? no) but we also have tens and we need to consider units and tens both? tens exist but units not. So we go to elif tens? Actually after adding zero and hundred, we check if units and tens: units empty so false. Then elif units: false. Then elif tens: true, so we add tens[0] = 10. So result: [0,100,10] size 3. Could we include another ten? No. So max 3. But could we include both from tens and units? No units. So max 3. Could we include a both? none. So correct.
Now, consider scenario: 0,100,1,2,10. We have units [1,2], tens [10]. Our algorithm: zero+100+1+10 = 4. Could we include 2? No conflict with 1. So max 4.
Now, scenario: 0,100,1,10,11. units [1], tens [10], both [11]. algorithm picks 0,100,1,10 -> size 4. Check: 1 and 11 conflict? Not included. 10 and 11 conflict? 11 tens=1 non-zero, units=1 non-zero, 10 tens=1 non-zero? 10 tens=1, units=0; conflict at tens? Actually 11 has tens digit 1 (non-zero), 10 has tens digit 1 (non-zero) => both non-zero at tens, so they conflict. So cannot have both 10 and 11. But we didn't include 11. So subset 0,100,1,10 is valid? Check 1 and 10: units: 1 non-zero, 10 zero -> ok; tens: 1 zero, 10 non-zero -> ok. 1 and 100: ok. 10 and 100: ok. 0 ok. So valid. So max 4.
Now, is there a scenario where including both instead of unit+ten yields same size? For example, if we have zero, hundred, both, but no unit or ten, we get 3. That's max.
Thus algorithm correct.
Now, just to be thorough, let's consider numbers that are like 100 and also 0? Already.
Thus we can implement.
But wait, there's a nuance: The condition "for any decimal place at least one number has digit 0 in this place" might be interpreted that when summing, we consider decimal places of the sum? Actually, it says "Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place." So it's about the digits of a and b themselves, not the sum. So our interpretation stands.
Now, final code.
But note: There might be numbers like 0, but also numbers like 00? No.
Thus answer.
But wait, we need to output "n distinct non-negative integers — the required integers." They must be from the set, and distinct. Our result uses distinct numbers from the set.
Now, we must ensure that when we pick units[0] and tens[0], those numbers are indeed in the original set. Yes.
But what if the set contains both 0 and 100 and also both units and tens, but maybe units[0] and tens[0] are the only ones? Fine.
Now, check potential mistake: In the condition for tens numbers, we used d % 10 == 0 and 10 <= d <= 90. But what about number 0? Already handled. What about number 100? handled. So for numbers like 100, d % 10 == 0, but d=100 which is >90, so we treat as hundred. Good.
Now, what about number like 0? d==0.
Now, numbers like 50: 50%10==0, 10<=50<=90 -> tens.
Now, numbers like 10,20,...,90.
Now, numbers like 100 is separate.
Now, numbers like 1-9 are units.
Now, numbers like 11,12,...99 that are not multiples of 10 are both.
Now, what about number like 0? Already.
Now, what about number like 101? Not present because di ≤100.
Thus all good.
Now, one more check: Could there be number 0 and also number 100, and also both? Fine.
Now, code.
Now, consider time constraints: k <= 100 trivial.
Now, output format: print n and then the numbers in any order. We'll print them in the order we built.
Now