We need to split a given n (1 ≤ n ≤ 1000) into a sum of digits (each between 1 and 9). We want to minimize the number of distinct digits used in the partition. Among partitions achieving that minimal distinct count, we can output any.
We need to output k and the digits.
Observations:
- Since digits are from 1 to 9, the sum n can be represented using digits (always possible because we can use all ones: n times 1, but that uses many digits, but distinct count =1 (only digit 1). So at worst we can always have a partition using only digit 1, so the minimal distinct digits is at most 1. Actually, we could also use only digit 2 if n is even? Not always: if n is odd, using only 2 would sum to an even number, can't get odd. So the minimal distinct digits could be 1 if there exists a digit d such that n is a multiple of d? Wait, using only one digit d means that all digits equal d, so n = k * d for some integer k. That is possible if d divides n and k ≤ n? But also each digit must be between 1 and 9, and k is number of digits. So a representation using only a single digit d is possible if n is divisible by d and n/d ≤ n (always true) and d between 1 and 9. So we need to check if there exists any d in {1,...,9} such that d divides n. Since 1 always divides n, we can always use all ones, so distinct=1 is always achievable. Therefore the minimal possible number of different digits is always 1? Wait: is using only digit 1 always valid? Yes, because 1+1+...+1 (n times) sums to n, each digit is 1, so only one distinct digit. So the minimal distinct digits cannot be 0 (since we need at least one digit). So the answer is always 1 distinct digit. But the problem statement says "minimal possible number of different digits among d1,...,dk", and there always exists a partition, so the answer is always 1? Let's check the examples: For n=1, output 1 digit 1 (distinct=1). For n=4, output 2 2 (distinct=1). For n=27, output 9 9 9 (distinct=1). So indeed minimal is 1. But wait: is there any case where using only one digit is impossible? The only digit must be between 1 and 9. Using only 1 is always possible because we can use n ones. But is there any restriction that digits must be non-zero and also k must be ≤ n? That's fine. So indeed we can always use all ones. So the minimal distinct count is always 1. So the problem reduces to: find any partition of n into digits (1-9) such that only one distinct digit is used, i.e., all digits are the same. But is that always possible? All digits are the same digit d, so n must be multiple of d, and also the number of digits k = n/d must be a positive integer. d can be from 1 to 9. So if n is a multiple of some d in [1,9], then we can choose that d. If not? For example, n=5: multiples of digits: 1 divides, so we can use five 1's. That's allowed. So indeed, if n is not divisible by any other digit, we can still use digit 1. So yes, always.
Thus the problem seems trivial: output n times 1? But wait, the output might want the minimal number of digits? No, it says: "Vasya wants to split it to some non-zero digits. It means, that he wants to choose some digits d_1, d_2, …, d_k, such that 1 ≤ d_i ≤ 9 for all i and d_1 + d_2 + … + d_k = n." Then: "Vasya likes beauty in everything, so he wants to find any solution with the minimal possible number of different digits among d_1, d_2, …, d_k." It doesn't ask to minimize k. So among partitions with minimal distinct digits (which is always 1), we can choose any. That could be all ones. But the examples show other outputs: For n=4, they output 2 2 (two 2's) rather than 1 1 1 1 (four 1's). So it's allowed to output any partition using a single digit. So the simplest solution: check if there exists d (2..9) that divides n, then output k = n/d copies of d. Else output n copies of 1. That's simple.
But wait, maybe there is twist: Could the minimal distinct digits be 0? No. So it's always 1.
But is there any possibility that using only one digit may not be allowed because k must be at least 1? It's allowed. So yes.
But then why would the problem be interesting? Perhaps I misread: "the minimal possible number of different digits among d_1, d_2, …, d_k" meaning we want to minimize the count of distinct digits used. Since we can always use only 1's, that gives distinct=1. Could there be a scenario where using only 1's is not allowed because the digits must be non-zero and we can use any digits, but maybe they want to minimize k? No, that is separate. Or maybe they want to find the partition that minimizes the number of different digits, but if there are multiple such, maybe they want to minimize something else? The problem says: "You should find a partition of n in which the number of different digits among d_1, d_2, …, d_k will be minimal possible among all partitions of n into non-zero digits. Among such partitions, it is allowed to find any." So no secondary criteria.
Thus it's simple.
But maybe there is a catch: Could there be a partition with 0 different digits? That would be empty, but sum must be n, so no.
So why n up to 1000? Possibly to consider that if we output n copies of 1, that's many numbers (k = n, which could be up to 1000). That's allowed: "k must satisfy the inequality 1 ≤ k ≤ n." So maximum k is n, which is okay. So outputting 1000 ones is acceptable.
But perhaps the problem expects a "nice" solution like using as many 9s as possible etc. But we can just output using the largest possible digit that divides n to reduce the number of digits. That would be a more compact output, but not required.
So solution: For d from 9 down to 2, if n % d == 0, then output k = n/d, and print d repeated k times. Else output n ones.
But wait: Could there be a case where using a single digit d > 9? No, digits only 1-9.
So that solves.
But let's double-check: Are there any constraints like we cannot use too many digits? No.
Thus we can solve easily.
But hold on: The input examples: For n=27, output 3 9's. 27 is divisible by 9, so we use 9. For n=4, divisible by 2 (and also by 4), output 2 2's (they chose d=2 instead of 4, but 4 is also a digit, so they could output just [4]? That would be k=1, digit 4, distinct=1. Why didn't they choose that? Possibly they wanted to show multiple possibilities, but they chose 2 2. That's fine. So indeed we could output [4] as well.
But is using a single digit 4 allowed? Yes, digit must be between 1 and 9, and 4 is within. So partition [4] uses k=1, sum=4, distinct=1. That would be even shorter. So why didn't they choose that? Possibly because they also want to minimize k? No, not stated. So maybe I misinterpret: Perhaps the digits must be a "split" meaning he wants to split the number into digits, i.e., to write the number as a sum of digits that are the digits of some representation? But the statement: "Vasya has his favourite number n. He wants to split it to some non-zero digits. It means, that he wants to choose some digits d_1, d_2, …, d_k, such that 1 ≤ d_i ≤ 9 for all i and d_1 + d_2 + … + d_k = n." So it's simply a sum.
Thus any set of digits that sum to n is okay.
So indeed we could output just [n] if n is a digit (1..9). But the example for n=4 they output [2,2] not [4]. So that is weird: why not [4]? Could it be that they require the digits to be non-zero but also maybe they want to split into at least 2 digits? No, "some non-zero digits" could be one digit. The example for n=1 they output [1], which is one digit. So it's allowed. So for n=4, they could have output [4] but they chose [2,2]. Maybe they want to illustrate that any solution is acceptable, and they arbitrarily chose [2,2].
So our simple approach is fine.
But perhaps the problem is not trivial because they want to minimize the number of distinct digits, and we thought 1 is always possible. But is using only digit 1 always valid? The digits must be between 1 and 9 inclusive, and we can use as many 1's as we want. So yes. So minimal distinct digits is 1. So the answer is always to output some representation using only one digit.
Thus the solution is simple.
But wait: Consider n=11. Using only digit 1 gives 11 ones (distinct=1). But maybe there is also representation using only digit 2? 2*? 11 not multiple of 2. Digit 3? 3*? 11 not multiple. 4? 4*? 11 not multiple. 5? 11 not multiple. 6? no. 7? no. 8? no. 9? no. So only digit 1 works. So answer would be 11 ones. That's acceptable.
Consider n=10. Multiples: 1 works (10 ones), 2 works (5 twos), 5 works (2 fives). Also 10? Digit 10 not allowed. So we could output 2 5's or 5 2's. So we can pick any.
Thus the solution is: find the largest digit d (2..9) that divides n, then use d repeated n/d times. If none, use 1 repeated n times. Optionally, we could also check d= n if n ≤9: then we could output just [n]. But that's also captured because if n ≤9, then n divides n, so d = n is between 2 and 9 (if n>=2) and we can output a single digit n. For n=1, d=1 is the only, but 1 is not in 2..9, we will fallback to ones, which is fine: output [1] (k=1). So the algorithm works.
But careful: For n=1, n%? no digit from 2..9 divides, so we output n ones: that would be k=1, digit 1. That's correct.
For n=2, d=2 divides, output k=1, digit 2. That's fine.
Now, is there any scenario where using only one digit might be considered not minimal distinct? No.
Thus problem solved.
But maybe there is nuance: "He wants to split it to some non-zero digits." Could it be that the digits must be the digits of the decimal representation of some number? That is, split the number into its decimal digits? That would be a different problem: maybe he wants to write n as sum of digits of some number? That doesn't make sense.
Alternatively, maybe they require the digits to be from 0-9 but non-zero, that's what we used.
I think it's correct.
But wait, maybe there is a twist: They might want to minimize the number of different digits, but also maybe the partition's digits must be such that the number formed by concatenating them (in any order) is something? No.
Let's re-read the problem statement as given: "Vasya has his favourite number n. He wants to split it to some non-zero digits. It means, that he wants to choose some digits d_1, d_2, …, d_k, such that 1 ≤ d_i ≤ 9 for all i and d_1 + d_2 + … + d_k = n." That's exactly what we used.
So it's trivial.
But why would they set n up to 1000? Possibly to make the problem slightly less trivial: maybe they expect to find a representation with as few distinct digits as possible, and sometimes the minimum distinct digits might be 2? Let's test: Could it be that using only digit 1 is not allowed because the digits must be non-zero and "split it to some non-zero digits" might imply that you split the number into digits that are the digits of the number when written in base 10? No.
Wait, maybe I misinterpret "split it to some non-zero digits". In many problems, "split a number into digits" means to take the decimal representation of the number and list its digits. But here they define explicitly: choose some digits d_i such that 1 ≤ d_i ≤ 9 and sum equals n. So that is clear.
But is there any restriction that we cannot use arbitrarily many digits? The only restriction is 1 ≤ k ≤ n, which is natural.
Thus minimal distinct digits is always 1. So the answer is straightforward.
But is there any possibility that using only digit 1 is not allowed because d_i must be digits of the decimal representation of some number? No.
Thus the problem is extremely simple. But given it's from some contest, maybe it's a trick problem. However, the examples show n=27 output 9 9 9, not 1 repeated 27 times. They could have output 27 ones. So they prefer a representation with fewer digits, perhaps to demonstrate a concept. But the problem does not ask to minimize k. So it's okay.
But maybe they want to output a partition that not only minimizes distinct digits but also among those, with minimal k? Not stated. The statement: "You should find a partition of n in which the number of different digits among d_1, d_2, …, d_k will be minimal possible among all partitions of n into non-zero digits. Among such partitions, it is allowed to find any." So no secondary requirement.
Thus we can output any. So simplest to code: output 1 repeated n times. That would be correct for all n. But would it be accepted? Probably yes. But let's think about output size: For n=1000, we would output 1000 numbers, separated by spaces. That's about 4000 characters, which is fine. So it's acceptable.
But some judges might have output length limits, but typically it's fine.
Nevertheless, to be neat, we could output the representation with the fewest digits among those with distinct=1. That is, find the largest digit d (2..9) that divides n, and if none, use d=1. That gives minimal k among single-digit representations. But not required.
I'll adopt that approach because it's easy and yields smaller output.
Edge cases: n=0? Not allowed (n ≥ 1). So fine.
Thus algorithm:
Read n.
For d in [9,8,...,2]:
if n % d == 0:
k = n // d
print(k)
print((str(d) + ' ') * (k-1) + str(d)) // careful with trailing space
return
// if no d found:
print(n)
print('1 ' * (n-1) + '1') if n>1 else print('1')
That's it.
But wait: consider n=1: loop d=9..2 none, then print n (1) and print '1'? That works.
Now check n=9: d=9 divides, so output k=1, digit 9. That's fine.
Thus solution.
But is there any scenario where using only one digit might not be possible because d must be between 1 and 9, and if n is not a multiple of any d in that range, then we can use 1. So always.
Thus problem solved.
But hold on: The problem statement: "It means, that he wants to choose some digits d_1, d_2, …, d_k, such that 1 ≤ d_i ≤ 9 for all i and d_1 + d_2 + … + d_k = n." Could it be that the digits must be distinct? No.
Thus answer done.
I'll produce final solution in C++ or Python? Usually we can use Python.
But maybe they expect to print the partition with minimal distinct digits, and they consider that the minimum might be 2 if n is not divisible by any digit except 1? Wait, but 1 always divides, so using only 1 gives distinct=1. So minimal distinct is always 1. So okay.
But what about n=11? 11 is prime, only divisible by 1 and 11, but 11 is not allowed as a digit. So only 1 works. So distinct=1.
Thus minimal distinct is always 1.
Thus the answer is trivial.
Given the simplicity, maybe I've missed something: Could it be that the digits d_i must be the digits of the number n? For example, "split it to some non-zero digits" might mean he wants to split the number n into its decimal digits? But that wouldn't sum to n, it would sum to the sum of its digits, which is not n (unless n is one digit). So no.
Another angle: Perhaps the digits are to be concatenated to form the number n? That is, the digits placed side by side form the number n? The phrase "split it to some non-zero digits" could mean he wants to represent n as a sequence of digits, i.e., its decimal representation. But that is just writing n in base 10, which always works. But then they talk about sum, not concatenation.
Thus I'm confident.
I'll produce a solution.
But before finalizing, let's think about possible pitfalls: The problem might be from Codeforces? I recall a problem "Split the number" maybe? Actually there is a problem "Vasya and Digital Root" but not this.
Search memory: There is Codeforces Round #899 (Div.2) problem A? I'm not sure.
Nevertheless, it's simple.
Implementation details:
We'll read integer n.
For d in range(9,1,-1):
if n % d == 0:
k = n // d
print(k)
# print list of d repeated k times
# In Python: print(' '.join([str(d)]*k))
return
if loop ends:
print(n)
print(' '.join(['1']*n))
That's all.
But check: For n=0? Not allowed.
Thus final answer.
I'll produce solution in Python.
However, let's consider if using only one digit is always allowed given the constraint "1 ≤ k ≤ n". With d=1, k = n, so it's okay.
Thus done.
I think that's the intended solution: Since the minimal distinct digits is always 1, we simply need to output any partition with a single digit. They probably expect to output the one with the smallest k? Not specified, but it's natural to output the one using the largest possible digit to reduce k, but they didn't require it. In the examples, they used that: for n=4 they used 2 2 instead of 1 1 1 1 or 4. 2 2 reduces k compared to 1s but not as minimal as 4. So maybe they used the digit that is the largest divisor of n that is ≤9? For n=4, largest divisor ≤9 is 4, but they used 2. So maybe they used the digit that yields the smallest possible k? 4 yields k=1, which is smaller than 2, so that would be better. So they didn't use that. So they didn't aim to minimize k. So they just used some arbitrary representation: maybe they used the one with the largest possible digit that yields k≥2? Not sure. Could be they used the digit that is the largest divisor other than n itself? For n=4, divisors: 1,2,4. The largest divisor besides 4? 2, they used. For n=27, divisors: 1,3,9,27. Largest divisor besides 27 is 9, they used. So they avoided using n itself if n is a digit? Possibly because they might think that the representation [n] is not a split? But the problem statement says "split it to some non-zero digits", which could imply that they want to split into at least two digits? However, for n=1, they output [1], which is a single digit. So that contradicts that idea. So it's ambiguous. However, they might define "split" as breaking into multiple parts, but sometimes they accept single part? In example n=1 they output a single digit, so that's allowed. So why not for n=4? Possibly they just chose a different representation to illustrate that any is fine. So it's okay.
Thus our solution is acceptable.
But to be safe, maybe we should avoid using n itself when n ≤9? Because maybe the partition must have at least 2 digits? However the example n=1 shows they allowed a single digit. So it's fine.
But let's read the first example: Input: 1 Output: 1, then next line: 1. So they output k=1. So it's explicitly allowed. So for n=4 we could output k=1 digit 4. That would be correct as per problem statement.
Thus my algorithm that picks the largest d from 2..9 dividing n will output d=4 for n=4 (since 4 % 4 = 0). That would output k=1, digit 4. Is that acceptable? Yes. But the sample output for n=4 is "2" and "2 2". So my output would differ from sample. In many contest problems, if the answer is not unique, any correct answer is accepted, even if it differs from sample. So it's fine.
But to be cautious, maybe they expect to output more than one digit? But the problem statement says any is allowed. So it's fine.
Thus solution is straightforward.
But before I finalize, let's think if there is any nuance about "different digits" meaning distinct digit values, and we want to minimize that count. Could it be that we might achieve 0 distinct digits? No.
So answer done.
Nevertheless, I'd like to consider if there is any scenario where using only digit 1 is not allowed because the digits must be the digits of the decimal representation of some number that has no leading zeros? That doesn't matter.
Hence I'll produce final solution.
But wait, maybe I misread the condition "1 ≤ d_i ≤ 9" means each d_i is a digit (0-9) but non-zero so 1-9. That's fine.
Thus final answer.
Now, I'll write a clear solution in Python.
Potential pitfalls: For large n, if we output many ones, it's okay.
But if we choose to output using largest divisor d, we must ensure that n//d ≤ n (always true). Also, if n is large like 1000 and d=2 gives 500 digits, that's still fine. Output size is manageable.
Edge case: n=0? Not in constraints.
Implementation:
def solve():
import sys
n = int(sys.stdin.readline().strip())
for d in range(9, 1, -1):
if n % d == 0:
k = n // d
# ensure that k >= 1
# also, note that d must be between 1 and 9, which it is.
sys.stdout.write(str(k) + "\n")
sys.stdout.write((" " + str(d)) * k) # but leading space? better join.
# Actually, easier: sys.stdout.write(" ".join([str(d)] * k))
# We'll do join.
sys.stdout.write(" ".join([str(d)] * k))
if k > 0:
sys.stdout.write("\n")
return
# no divisor found besides 1
sys.stdout.write(str(n) + "\n")
sys.stdout.write(" ".join(["1"] * n) + "\n")
But careful: For n=1, the loop finds nothing, then we output n (1) and "1". That's correct.
For n=2, loop: d=9..2, at d=2 it passes, output k=1, "2". Good.
But note: for n=0? Not.
Now, what about n=9? d=9 passes, output k=1, "9". Good.
For n=3? d=3 passes, output "3". Good.
So it works.
But is it always better to pick the largest divisor? That yields smallest k, but it's optional.
But could there be a case where the largest divisor is 9 but n is not multiple of 9? Then next.
All good.
Thus final solution.
But before finalizing, let's think about the possibility that the minimal distinct digits might be 0 if n=0, but not.
Thus solution.
I'll now produce the final answer. ```python
import sys
def main():
n = int(sys.stdin.readline().strip())
# try to use a single digit d (2..9) that divides n
for d in range(9, 1, -1): # from 9 down to 2
if n % d == 0:
k = n // d
print(k)
print(' '.join([str(d)] * k))
return
# otherwise, use only digit 1
print(n)
print(' '.join(['1'] * n))
if name == "main":
main()