message
stringlengths
2
59.7k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
37
108k
cluster
float64
20
20
__index_level_0__
int64
74
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Edward Leven loves multiples of eleven very much. When he sees a number, he always tries to find consecutive subsequences (or substrings) forming multiples of eleven. He calls such subsequences as 11-sequences. For example, he can find an 11-sequence 781 in a number 17819. He thinks a number which has many 11-sequences is a good number. He would like to find out a very good number. As the first step, he wants an easy way to count how many 11-sequences are there in a given number. Even for him, counting them from a big number is not easy. Fortunately, one of his friends, you, is a brilliant programmer. He asks you to write a program to count the number of 11-sequences. Note that an 11-sequence must be a positive number without leading zeros. Input The input is a sequence of lines each of which contains a number consisting of less than or equal to 80000 digits. The end of the input is indicated by a line containing a single zero, which should not be processed. Output For each input number, output a line containing the number of 11-sequences. You can assume the answer fits in a 32-bit signed integer. Example Input 17819 1111 11011 1234567891011121314151617181920 0 Output 1 4 4 38 Submitted Solution: ``` targ = input() while True: ans = 0 length = len(targ) for o in range(length-1): disp = [0 for n in range(length)] for i in range(o+1,length): if targ[o] == '0': disp[i] = ans elif i == length - 1: disp[i] = int((int(targ[o] + targ[o+1:i+1])) % 11 == 0) + disp[i-1] + ans else: disp[i] = int((int(targ[o] + targ[o+1:i+1])) % 11 == 0) + disp[i-1] ans = disp[-1] del disp print(ans) targ = input() if targ == '0': break ```
instruction
0
100,286
20
200,572
No
output
1
100,286
20
200,573
Provide tags and a correct Python 3 solution for this coding contest problem. 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. 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. Help him! Input The first line contains a single integer n β€” the number that Vasya wants to split (1 ≀ n ≀ 1000). Output In the first line print one integer k β€” the number of digits in the partition. Note that k must satisfy the inequality 1 ≀ k ≀ n. In the next line print k digits d_1, d_2, …, d_k separated by spaces. All digits must satisfy the inequalities 1 ≀ d_i ≀ 9. 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. It is guaranteed that there exists at least one partition of the number n into digits. Examples Input 1 Output 1 1 Input 4 Output 2 2 2 Input 27 Output 3 9 9 9 Note In the first test, the number 1 can be divided into 1 digit equal to 1. In the second test, there are 3 partitions of the number 4 into digits in which the number of different digits is 1. This partitions are [1, 1, 1, 1], [2, 2] and [4]. Any of these partitions can be found. And, for example, dividing the number 4 to the digits [1, 1, 2] isn't an answer, because it has 2 different digits, that isn't the minimum possible number.
instruction
0
100,352
20
200,704
Tags: constructive algorithms, implementation, math Correct Solution: ``` n=int(input()) re=0 for i in range(9,1,-1): if(n%i==0): re=i break if(re==0): print(n) for i in range(n): if(i==n-1): print(1) else: print(1,end=' ') else: print(n//re) res=n//re for i in range(res): if(i==res-1): print(re) else: print(re,end=' ') n-=re ```
output
1
100,352
20
200,705
Provide tags and a correct Python 3 solution for this coding contest problem. 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. 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. Help him! Input The first line contains a single integer n β€” the number that Vasya wants to split (1 ≀ n ≀ 1000). Output In the first line print one integer k β€” the number of digits in the partition. Note that k must satisfy the inequality 1 ≀ k ≀ n. In the next line print k digits d_1, d_2, …, d_k separated by spaces. All digits must satisfy the inequalities 1 ≀ d_i ≀ 9. 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. It is guaranteed that there exists at least one partition of the number n into digits. Examples Input 1 Output 1 1 Input 4 Output 2 2 2 Input 27 Output 3 9 9 9 Note In the first test, the number 1 can be divided into 1 digit equal to 1. In the second test, there are 3 partitions of the number 4 into digits in which the number of different digits is 1. This partitions are [1, 1, 1, 1], [2, 2] and [4]. Any of these partitions can be found. And, for example, dividing the number 4 to the digits [1, 1, 2] isn't an answer, because it has 2 different digits, that isn't the minimum possible number.
instruction
0
100,353
20
200,706
Tags: constructive algorithms, implementation, math Correct Solution: ``` import sys number = int(input()) if(number <= 2): print(int(number)) print((str(1) + ' ') * number) else: for i in range(9,1,-1): if(number % i == 0 and i != number): print(int(number/i)) print((str(i) + ' ') * int(number/i)) sys.exit() print(int(number)) print((str(1) + ' ') * number) ```
output
1
100,353
20
200,707
Provide tags and a correct Python 3 solution for this coding contest problem. 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. 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. Help him! Input The first line contains a single integer n β€” the number that Vasya wants to split (1 ≀ n ≀ 1000). Output In the first line print one integer k β€” the number of digits in the partition. Note that k must satisfy the inequality 1 ≀ k ≀ n. In the next line print k digits d_1, d_2, …, d_k separated by spaces. All digits must satisfy the inequalities 1 ≀ d_i ≀ 9. 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. It is guaranteed that there exists at least one partition of the number n into digits. Examples Input 1 Output 1 1 Input 4 Output 2 2 2 Input 27 Output 3 9 9 9 Note In the first test, the number 1 can be divided into 1 digit equal to 1. In the second test, there are 3 partitions of the number 4 into digits in which the number of different digits is 1. This partitions are [1, 1, 1, 1], [2, 2] and [4]. Any of these partitions can be found. And, for example, dividing the number 4 to the digits [1, 1, 2] isn't an answer, because it has 2 different digits, that isn't the minimum possible number.
instruction
0
100,354
20
200,708
Tags: constructive algorithms, implementation, math Correct Solution: ``` x = int(input()) z = [] if x == 1: print(1) print(1) else: for i in range(1,10): if x%i == 0: z.append(i) r = int((x/max(z))) print(int(x/max(z))) k = str(max(z)) print((k+' ')*r) ```
output
1
100,354
20
200,709
Provide tags and a correct Python 3 solution for this coding contest problem. 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. 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. Help him! Input The first line contains a single integer n β€” the number that Vasya wants to split (1 ≀ n ≀ 1000). Output In the first line print one integer k β€” the number of digits in the partition. Note that k must satisfy the inequality 1 ≀ k ≀ n. In the next line print k digits d_1, d_2, …, d_k separated by spaces. All digits must satisfy the inequalities 1 ≀ d_i ≀ 9. 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. It is guaranteed that there exists at least one partition of the number n into digits. Examples Input 1 Output 1 1 Input 4 Output 2 2 2 Input 27 Output 3 9 9 9 Note In the first test, the number 1 can be divided into 1 digit equal to 1. In the second test, there are 3 partitions of the number 4 into digits in which the number of different digits is 1. This partitions are [1, 1, 1, 1], [2, 2] and [4]. Any of these partitions can be found. And, for example, dividing the number 4 to the digits [1, 1, 2] isn't an answer, because it has 2 different digits, that isn't the minimum possible number.
instruction
0
100,355
20
200,710
Tags: constructive algorithms, implementation, math Correct Solution: ``` n = int(input()) a = [1] * n print(n) print(*a) ```
output
1
100,355
20
200,711
Provide tags and a correct Python 3 solution for this coding contest problem. 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. 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. Help him! Input The first line contains a single integer n β€” the number that Vasya wants to split (1 ≀ n ≀ 1000). Output In the first line print one integer k β€” the number of digits in the partition. Note that k must satisfy the inequality 1 ≀ k ≀ n. In the next line print k digits d_1, d_2, …, d_k separated by spaces. All digits must satisfy the inequalities 1 ≀ d_i ≀ 9. 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. It is guaranteed that there exists at least one partition of the number n into digits. Examples Input 1 Output 1 1 Input 4 Output 2 2 2 Input 27 Output 3 9 9 9 Note In the first test, the number 1 can be divided into 1 digit equal to 1. In the second test, there are 3 partitions of the number 4 into digits in which the number of different digits is 1. This partitions are [1, 1, 1, 1], [2, 2] and [4]. Any of these partitions can be found. And, for example, dividing the number 4 to the digits [1, 1, 2] isn't an answer, because it has 2 different digits, that isn't the minimum possible number.
instruction
0
100,356
20
200,712
Tags: constructive algorithms, implementation, math Correct Solution: ``` # cook your dish here n=int(input()) print(n) for i in range(n): print("1",end=" ") ```
output
1
100,356
20
200,713
Provide tags and a correct Python 3 solution for this coding contest problem. 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. 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. Help him! Input The first line contains a single integer n β€” the number that Vasya wants to split (1 ≀ n ≀ 1000). Output In the first line print one integer k β€” the number of digits in the partition. Note that k must satisfy the inequality 1 ≀ k ≀ n. In the next line print k digits d_1, d_2, …, d_k separated by spaces. All digits must satisfy the inequalities 1 ≀ d_i ≀ 9. 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. It is guaranteed that there exists at least one partition of the number n into digits. Examples Input 1 Output 1 1 Input 4 Output 2 2 2 Input 27 Output 3 9 9 9 Note In the first test, the number 1 can be divided into 1 digit equal to 1. In the second test, there are 3 partitions of the number 4 into digits in which the number of different digits is 1. This partitions are [1, 1, 1, 1], [2, 2] and [4]. Any of these partitions can be found. And, for example, dividing the number 4 to the digits [1, 1, 2] isn't an answer, because it has 2 different digits, that isn't the minimum possible number.
instruction
0
100,357
20
200,714
Tags: constructive algorithms, implementation, math Correct Solution: ``` n = int(input()) c = 1 j = n for i in range(1,10): if n // i > c and n % i == 0 and n//i != n and n//i <= 9: c = n//i j = i s = "" print(j) for k in range(j): print(c, end=" ") ```
output
1
100,357
20
200,715
Provide tags and a correct Python 3 solution for this coding contest problem. 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. 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. Help him! Input The first line contains a single integer n β€” the number that Vasya wants to split (1 ≀ n ≀ 1000). Output In the first line print one integer k β€” the number of digits in the partition. Note that k must satisfy the inequality 1 ≀ k ≀ n. In the next line print k digits d_1, d_2, …, d_k separated by spaces. All digits must satisfy the inequalities 1 ≀ d_i ≀ 9. 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. It is guaranteed that there exists at least one partition of the number n into digits. Examples Input 1 Output 1 1 Input 4 Output 2 2 2 Input 27 Output 3 9 9 9 Note In the first test, the number 1 can be divided into 1 digit equal to 1. In the second test, there are 3 partitions of the number 4 into digits in which the number of different digits is 1. This partitions are [1, 1, 1, 1], [2, 2] and [4]. Any of these partitions can be found. And, for example, dividing the number 4 to the digits [1, 1, 2] isn't an answer, because it has 2 different digits, that isn't the minimum possible number.
instruction
0
100,358
20
200,716
Tags: constructive algorithms, implementation, math Correct Solution: ``` n = int(input()) number = 1 for i in range(9,1,-1): if(n%i == 0): number = i break times = n//number print(times) for i in range(times): print(number, end=' ') ```
output
1
100,358
20
200,717
Provide tags and a correct Python 3 solution for this coding contest problem. 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. 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. Help him! Input The first line contains a single integer n β€” the number that Vasya wants to split (1 ≀ n ≀ 1000). Output In the first line print one integer k β€” the number of digits in the partition. Note that k must satisfy the inequality 1 ≀ k ≀ n. In the next line print k digits d_1, d_2, …, d_k separated by spaces. All digits must satisfy the inequalities 1 ≀ d_i ≀ 9. 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. It is guaranteed that there exists at least one partition of the number n into digits. Examples Input 1 Output 1 1 Input 4 Output 2 2 2 Input 27 Output 3 9 9 9 Note In the first test, the number 1 can be divided into 1 digit equal to 1. In the second test, there are 3 partitions of the number 4 into digits in which the number of different digits is 1. This partitions are [1, 1, 1, 1], [2, 2] and [4]. Any of these partitions can be found. And, for example, dividing the number 4 to the digits [1, 1, 2] isn't an answer, because it has 2 different digits, that isn't the minimum possible number.
instruction
0
100,359
20
200,718
Tags: constructive algorithms, implementation, math Correct Solution: ``` if __name__ == '__main__': n = int(input()) print(n) print("1",end = "") print(" 1"*(n-1)) ```
output
1
100,359
20
200,719
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 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. 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. Help him! Input The first line contains a single integer n β€” the number that Vasya wants to split (1 ≀ n ≀ 1000). Output In the first line print one integer k β€” the number of digits in the partition. Note that k must satisfy the inequality 1 ≀ k ≀ n. In the next line print k digits d_1, d_2, …, d_k separated by spaces. All digits must satisfy the inequalities 1 ≀ d_i ≀ 9. 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. It is guaranteed that there exists at least one partition of the number n into digits. Examples Input 1 Output 1 1 Input 4 Output 2 2 2 Input 27 Output 3 9 9 9 Note In the first test, the number 1 can be divided into 1 digit equal to 1. In the second test, there are 3 partitions of the number 4 into digits in which the number of different digits is 1. This partitions are [1, 1, 1, 1], [2, 2] and [4]. Any of these partitions can be found. And, for example, dividing the number 4 to the digits [1, 1, 2] isn't an answer, because it has 2 different digits, that isn't the minimum possible number. Submitted Solution: ``` n=int(input()) if(n<9): print(1) print(n) else: l=[1]*n print(n) print(*l) ```
instruction
0
100,360
20
200,720
Yes
output
1
100,360
20
200,721
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 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. 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. Help him! Input The first line contains a single integer n β€” the number that Vasya wants to split (1 ≀ n ≀ 1000). Output In the first line print one integer k β€” the number of digits in the partition. Note that k must satisfy the inequality 1 ≀ k ≀ n. In the next line print k digits d_1, d_2, …, d_k separated by spaces. All digits must satisfy the inequalities 1 ≀ d_i ≀ 9. 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. It is guaranteed that there exists at least one partition of the number n into digits. Examples Input 1 Output 1 1 Input 4 Output 2 2 2 Input 27 Output 3 9 9 9 Note In the first test, the number 1 can be divided into 1 digit equal to 1. In the second test, there are 3 partitions of the number 4 into digits in which the number of different digits is 1. This partitions are [1, 1, 1, 1], [2, 2] and [4]. Any of these partitions can be found. And, for example, dividing the number 4 to the digits [1, 1, 2] isn't an answer, because it has 2 different digits, that isn't the minimum possible number. Submitted Solution: ``` import sys input = sys.stdin.readline N=int(input()) L=[1]*N print(N) print(' '.join(map(str,L))) ```
instruction
0
100,361
20
200,722
Yes
output
1
100,361
20
200,723
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 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. 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. Help him! Input The first line contains a single integer n β€” the number that Vasya wants to split (1 ≀ n ≀ 1000). Output In the first line print one integer k β€” the number of digits in the partition. Note that k must satisfy the inequality 1 ≀ k ≀ n. In the next line print k digits d_1, d_2, …, d_k separated by spaces. All digits must satisfy the inequalities 1 ≀ d_i ≀ 9. 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. It is guaranteed that there exists at least one partition of the number n into digits. Examples Input 1 Output 1 1 Input 4 Output 2 2 2 Input 27 Output 3 9 9 9 Note In the first test, the number 1 can be divided into 1 digit equal to 1. In the second test, there are 3 partitions of the number 4 into digits in which the number of different digits is 1. This partitions are [1, 1, 1, 1], [2, 2] and [4]. Any of these partitions can be found. And, for example, dividing the number 4 to the digits [1, 1, 2] isn't an answer, because it has 2 different digits, that isn't the minimum possible number. Submitted Solution: ``` n=int(input()) if n<=9: print(1) print(n) if n>9: print(n) print("1 "*n) ```
instruction
0
100,362
20
200,724
Yes
output
1
100,362
20
200,725
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 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. 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. Help him! Input The first line contains a single integer n β€” the number that Vasya wants to split (1 ≀ n ≀ 1000). Output In the first line print one integer k β€” the number of digits in the partition. Note that k must satisfy the inequality 1 ≀ k ≀ n. In the next line print k digits d_1, d_2, …, d_k separated by spaces. All digits must satisfy the inequalities 1 ≀ d_i ≀ 9. 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. It is guaranteed that there exists at least one partition of the number n into digits. Examples Input 1 Output 1 1 Input 4 Output 2 2 2 Input 27 Output 3 9 9 9 Note In the first test, the number 1 can be divided into 1 digit equal to 1. In the second test, there are 3 partitions of the number 4 into digits in which the number of different digits is 1. This partitions are [1, 1, 1, 1], [2, 2] and [4]. Any of these partitions can be found. And, for example, dividing the number 4 to the digits [1, 1, 2] isn't an answer, because it has 2 different digits, that isn't the minimum possible number. Submitted Solution: ``` N = int(input()) Max = 0 for i in range(N, 0, -1): if N % i == 0: Max = i break print(N) print("1 "*N) ```
instruction
0
100,363
20
200,726
Yes
output
1
100,363
20
200,727
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 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. 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. Help him! Input The first line contains a single integer n β€” the number that Vasya wants to split (1 ≀ n ≀ 1000). Output In the first line print one integer k β€” the number of digits in the partition. Note that k must satisfy the inequality 1 ≀ k ≀ n. In the next line print k digits d_1, d_2, …, d_k separated by spaces. All digits must satisfy the inequalities 1 ≀ d_i ≀ 9. 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. It is guaranteed that there exists at least one partition of the number n into digits. Examples Input 1 Output 1 1 Input 4 Output 2 2 2 Input 27 Output 3 9 9 9 Note In the first test, the number 1 can be divided into 1 digit equal to 1. In the second test, there are 3 partitions of the number 4 into digits in which the number of different digits is 1. This partitions are [1, 1, 1, 1], [2, 2] and [4]. Any of these partitions can be found. And, for example, dividing the number 4 to the digits [1, 1, 2] isn't an answer, because it has 2 different digits, that isn't the minimum possible number. Submitted Solution: ``` n=int(input()) flag=0 for i in [2,3,5,7]: if(n%i==0): print(n//i) for j in range(n//i): print(i,end=' ') flag=1 break if(flag==0): print((n//2)+1) for i in range(n//2): print(2,end=' ') print(1) ```
instruction
0
100,364
20
200,728
No
output
1
100,364
20
200,729
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 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. 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. Help him! Input The first line contains a single integer n β€” the number that Vasya wants to split (1 ≀ n ≀ 1000). Output In the first line print one integer k β€” the number of digits in the partition. Note that k must satisfy the inequality 1 ≀ k ≀ n. In the next line print k digits d_1, d_2, …, d_k separated by spaces. All digits must satisfy the inequalities 1 ≀ d_i ≀ 9. 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. It is guaranteed that there exists at least one partition of the number n into digits. Examples Input 1 Output 1 1 Input 4 Output 2 2 2 Input 27 Output 3 9 9 9 Note In the first test, the number 1 can be divided into 1 digit equal to 1. In the second test, there are 3 partitions of the number 4 into digits in which the number of different digits is 1. This partitions are [1, 1, 1, 1], [2, 2] and [4]. Any of these partitions can be found. And, for example, dividing the number 4 to the digits [1, 1, 2] isn't an answer, because it has 2 different digits, that isn't the minimum possible number. Submitted Solution: ``` n = 1 first_digit = None include_digits = [9, 8, 7, 6, 5, 4, 3, 2, 1] for digit in include_digits: if n % digit == 0: first_digit = digit break times = int(n / first_digit) print(times) for t in range(times): print(first_digit, end=" ") ```
instruction
0
100,365
20
200,730
No
output
1
100,365
20
200,731
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 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. 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. Help him! Input The first line contains a single integer n β€” the number that Vasya wants to split (1 ≀ n ≀ 1000). Output In the first line print one integer k β€” the number of digits in the partition. Note that k must satisfy the inequality 1 ≀ k ≀ n. In the next line print k digits d_1, d_2, …, d_k separated by spaces. All digits must satisfy the inequalities 1 ≀ d_i ≀ 9. 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. It is guaranteed that there exists at least one partition of the number n into digits. Examples Input 1 Output 1 1 Input 4 Output 2 2 2 Input 27 Output 3 9 9 9 Note In the first test, the number 1 can be divided into 1 digit equal to 1. In the second test, there are 3 partitions of the number 4 into digits in which the number of different digits is 1. This partitions are [1, 1, 1, 1], [2, 2] and [4]. Any of these partitions can be found. And, for example, dividing the number 4 to the digits [1, 1, 2] isn't an answer, because it has 2 different digits, that isn't the minimum possible number. Submitted Solution: ``` n = int(input()) a = [] while n > 9: a.append(9) n -= 9 if n > 0: a.append(n) print(" ".join(map(str, a))) ```
instruction
0
100,366
20
200,732
No
output
1
100,366
20
200,733
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 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. 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. Help him! Input The first line contains a single integer n β€” the number that Vasya wants to split (1 ≀ n ≀ 1000). Output In the first line print one integer k β€” the number of digits in the partition. Note that k must satisfy the inequality 1 ≀ k ≀ n. In the next line print k digits d_1, d_2, …, d_k separated by spaces. All digits must satisfy the inequalities 1 ≀ d_i ≀ 9. 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. It is guaranteed that there exists at least one partition of the number n into digits. Examples Input 1 Output 1 1 Input 4 Output 2 2 2 Input 27 Output 3 9 9 9 Note In the first test, the number 1 can be divided into 1 digit equal to 1. In the second test, there are 3 partitions of the number 4 into digits in which the number of different digits is 1. This partitions are [1, 1, 1, 1], [2, 2] and [4]. Any of these partitions can be found. And, for example, dividing the number 4 to the digits [1, 1, 2] isn't an answer, because it has 2 different digits, that isn't the minimum possible number. Submitted Solution: ``` import math mod=1000000007 #c=[[0 for x in range(1001)] for y in range(1001)] n=int(input()) if n<10: print("1") print(n) else: m=n//9 x=n-(m*9) if x>0: print(m+1) else: print(m) for i in range(m): print("9",end=" ") if(x>0): print(x) ```
instruction
0
100,367
20
200,734
No
output
1
100,367
20
200,735
Provide tags and a correct Python 3 solution for this coding contest problem. Ania has a large integer S. Its decimal representation has length n and doesn't contain any leading zeroes. Ania is allowed to change at most k digits of S. She wants to do it in such a way that S still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania finish with? Input The first line contains two integers n and k (1 ≀ n ≀ 200 000, 0 ≀ k ≀ n) β€” the number of digits in the decimal representation of S and the maximum allowed number of changed digits. The second line contains the integer S. It's guaranteed that S has exactly n digits and doesn't contain any leading zeroes. Output Output the minimal possible value of S which Ania can end with. Note that the resulting integer should also have n digits. Examples Input 5 3 51528 Output 10028 Input 3 2 102 Output 100 Input 1 1 1 Output 0 Note A number has leading zeroes if it consists of at least two digits and its first digit is 0. For example, numbers 00, 00069 and 0101 have leading zeroes, while 0, 3000 and 1010 don't have leading zeroes.
instruction
0
100,420
20
200,840
Tags: greedy, implementation Correct Solution: ``` n,k=[int(i) for i in input().split()] s=list(input()) if len(s) == 1 and k: s='0' k-=1 elif int(s[0])>1 and k: k-=1 s[0]='1' i=1 while k and i<len(s): if s[i]!='0': s[i]='0' k-=1 i+=1 print(''.join(str(e) for e in s)) ```
output
1
100,420
20
200,841
Provide tags and a correct Python 3 solution for this coding contest problem. Ania has a large integer S. Its decimal representation has length n and doesn't contain any leading zeroes. Ania is allowed to change at most k digits of S. She wants to do it in such a way that S still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania finish with? Input The first line contains two integers n and k (1 ≀ n ≀ 200 000, 0 ≀ k ≀ n) β€” the number of digits in the decimal representation of S and the maximum allowed number of changed digits. The second line contains the integer S. It's guaranteed that S has exactly n digits and doesn't contain any leading zeroes. Output Output the minimal possible value of S which Ania can end with. Note that the resulting integer should also have n digits. Examples Input 5 3 51528 Output 10028 Input 3 2 102 Output 100 Input 1 1 1 Output 0 Note A number has leading zeroes if it consists of at least two digits and its first digit is 0. For example, numbers 00, 00069 and 0101 have leading zeroes, while 0, 3000 and 1010 don't have leading zeroes.
instruction
0
100,421
20
200,842
Tags: greedy, implementation Correct Solution: ``` n,k=map(int,input().split()) arr=list(input()) lenght=len(arr) for i in range(lenght): arr[i]=int(arr[i]) if lenght==1 and k==1: print("0") elif lenght==1 and k==0: print(arr[0]) elif lenght>1 and k<=lenght: for i in range(lenght): if arr[i]>1 and k>0 and i==0: arr[0]=1 k-=1 elif arr[i]>=1 and k>0 and i>0: arr[i]=0 k-=1 else: pass for i in range(lenght): print(arr[i],end="") else: pass ```
output
1
100,421
20
200,843
Provide tags and a correct Python 3 solution for this coding contest problem. Ania has a large integer S. Its decimal representation has length n and doesn't contain any leading zeroes. Ania is allowed to change at most k digits of S. She wants to do it in such a way that S still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania finish with? Input The first line contains two integers n and k (1 ≀ n ≀ 200 000, 0 ≀ k ≀ n) β€” the number of digits in the decimal representation of S and the maximum allowed number of changed digits. The second line contains the integer S. It's guaranteed that S has exactly n digits and doesn't contain any leading zeroes. Output Output the minimal possible value of S which Ania can end with. Note that the resulting integer should also have n digits. Examples Input 5 3 51528 Output 10028 Input 3 2 102 Output 100 Input 1 1 1 Output 0 Note A number has leading zeroes if it consists of at least two digits and its first digit is 0. For example, numbers 00, 00069 and 0101 have leading zeroes, while 0, 3000 and 1010 don't have leading zeroes.
instruction
0
100,422
20
200,844
Tags: greedy, implementation Correct Solution: ``` s,k = map(int,input().split()) n = list(input()) if s == 1: if k == 1 : print(0) else: print(n[0]) else: if n[0] > '1' and k>0: n[0] = '1' k = k-1 i = 1 while k>0 and i <s: if n[i] != '0': n[i] = '0' k = k-1 i += 1 print("".join(n)) ```
output
1
100,422
20
200,845
Provide tags and a correct Python 3 solution for this coding contest problem. Ania has a large integer S. Its decimal representation has length n and doesn't contain any leading zeroes. Ania is allowed to change at most k digits of S. She wants to do it in such a way that S still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania finish with? Input The first line contains two integers n and k (1 ≀ n ≀ 200 000, 0 ≀ k ≀ n) β€” the number of digits in the decimal representation of S and the maximum allowed number of changed digits. The second line contains the integer S. It's guaranteed that S has exactly n digits and doesn't contain any leading zeroes. Output Output the minimal possible value of S which Ania can end with. Note that the resulting integer should also have n digits. Examples Input 5 3 51528 Output 10028 Input 3 2 102 Output 100 Input 1 1 1 Output 0 Note A number has leading zeroes if it consists of at least two digits and its first digit is 0. For example, numbers 00, 00069 and 0101 have leading zeroes, while 0, 3000 and 1010 don't have leading zeroes.
instruction
0
100,423
20
200,846
Tags: greedy, implementation Correct Solution: ``` def hi(n,k,s): x='' a=0 if k==0: return s elif n==1 and k!=0: return '0' else: x='1' if s[0]!='1': a+=1 for i in range(1,n): if s[i]!='0' and a<k: x+='0' a+=1 else: x+=s[i] return x n,k=map(int,input().split()) s=input() print(hi(n,k,s)) ```
output
1
100,423
20
200,847
Provide tags and a correct Python 3 solution for this coding contest problem. Ania has a large integer S. Its decimal representation has length n and doesn't contain any leading zeroes. Ania is allowed to change at most k digits of S. She wants to do it in such a way that S still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania finish with? Input The first line contains two integers n and k (1 ≀ n ≀ 200 000, 0 ≀ k ≀ n) β€” the number of digits in the decimal representation of S and the maximum allowed number of changed digits. The second line contains the integer S. It's guaranteed that S has exactly n digits and doesn't contain any leading zeroes. Output Output the minimal possible value of S which Ania can end with. Note that the resulting integer should also have n digits. Examples Input 5 3 51528 Output 10028 Input 3 2 102 Output 100 Input 1 1 1 Output 0 Note A number has leading zeroes if it consists of at least two digits and its first digit is 0. For example, numbers 00, 00069 and 0101 have leading zeroes, while 0, 3000 and 1010 don't have leading zeroes.
instruction
0
100,424
20
200,848
Tags: greedy, implementation Correct Solution: ``` n, k = map(int,input().split()) s = list(input()) l = "" if n > 1: for i in range(0, n): if k == 0: l += s[i] elif i == 0: if s[i] == "1": l += "1" else: l += "1" k -= 1 else: if s[i] == "0": l += "0" else: l += "0" k -= 1 print(l) else: if k == 0: print(s[0]) else: print(0) ```
output
1
100,424
20
200,849
Provide tags and a correct Python 3 solution for this coding contest problem. Ania has a large integer S. Its decimal representation has length n and doesn't contain any leading zeroes. Ania is allowed to change at most k digits of S. She wants to do it in such a way that S still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania finish with? Input The first line contains two integers n and k (1 ≀ n ≀ 200 000, 0 ≀ k ≀ n) β€” the number of digits in the decimal representation of S and the maximum allowed number of changed digits. The second line contains the integer S. It's guaranteed that S has exactly n digits and doesn't contain any leading zeroes. Output Output the minimal possible value of S which Ania can end with. Note that the resulting integer should also have n digits. Examples Input 5 3 51528 Output 10028 Input 3 2 102 Output 100 Input 1 1 1 Output 0 Note A number has leading zeroes if it consists of at least two digits and its first digit is 0. For example, numbers 00, 00069 and 0101 have leading zeroes, while 0, 3000 and 1010 don't have leading zeroes.
instruction
0
100,425
20
200,850
Tags: greedy, implementation Correct Solution: ``` n,k = map(int,input().split()) a = list(input()) if(n==1 and k==1): print(0) elif(k==0): print("".join(a)) else: s = list("1"+"0"*(n-1)) for i in range(n): if(k==0): break if(a[i]!=s[i]): a[i] = s[i] k=k-1 print("".join(a)) ```
output
1
100,425
20
200,851
Provide tags and a correct Python 3 solution for this coding contest problem. Ania has a large integer S. Its decimal representation has length n and doesn't contain any leading zeroes. Ania is allowed to change at most k digits of S. She wants to do it in such a way that S still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania finish with? Input The first line contains two integers n and k (1 ≀ n ≀ 200 000, 0 ≀ k ≀ n) β€” the number of digits in the decimal representation of S and the maximum allowed number of changed digits. The second line contains the integer S. It's guaranteed that S has exactly n digits and doesn't contain any leading zeroes. Output Output the minimal possible value of S which Ania can end with. Note that the resulting integer should also have n digits. Examples Input 5 3 51528 Output 10028 Input 3 2 102 Output 100 Input 1 1 1 Output 0 Note A number has leading zeroes if it consists of at least two digits and its first digit is 0. For example, numbers 00, 00069 and 0101 have leading zeroes, while 0, 3000 and 1010 don't have leading zeroes.
instruction
0
100,426
20
200,852
Tags: greedy, implementation Correct Solution: ``` def main(): n,k=map(int,input().split()) x=input() lis=list(x) if k==0: print(x) return if n==1: print('0') return if lis[0]!='1': k-=1 lis[0]='1' for i in range(1,n): if k==0: break if lis[i]!='0': lis[i]='0' k-=1 print("".join(lis)) main() ```
output
1
100,426
20
200,853
Provide tags and a correct Python 3 solution for this coding contest problem. Ania has a large integer S. Its decimal representation has length n and doesn't contain any leading zeroes. Ania is allowed to change at most k digits of S. She wants to do it in such a way that S still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania finish with? Input The first line contains two integers n and k (1 ≀ n ≀ 200 000, 0 ≀ k ≀ n) β€” the number of digits in the decimal representation of S and the maximum allowed number of changed digits. The second line contains the integer S. It's guaranteed that S has exactly n digits and doesn't contain any leading zeroes. Output Output the minimal possible value of S which Ania can end with. Note that the resulting integer should also have n digits. Examples Input 5 3 51528 Output 10028 Input 3 2 102 Output 100 Input 1 1 1 Output 0 Note A number has leading zeroes if it consists of at least two digits and its first digit is 0. For example, numbers 00, 00069 and 0101 have leading zeroes, while 0, 3000 and 1010 don't have leading zeroes.
instruction
0
100,427
20
200,854
Tags: greedy, implementation Correct Solution: ``` from sys import exit n, k = map(int, input().split()) s = list(input()) if n == 1: if k > 0: print(0) else: print(s[0]) exit(0) if k == 0: print(''.join(s)) exit(0) if s[0] != "1": s[0], k = "1", k - 1 for i in range(1, len(s)): if not k: break if s[i] != "0": s[i], k = "0", k - 1 print(''.join(s)) ```
output
1
100,427
20
200,855
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ania has a large integer S. Its decimal representation has length n and doesn't contain any leading zeroes. Ania is allowed to change at most k digits of S. She wants to do it in such a way that S still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania finish with? Input The first line contains two integers n and k (1 ≀ n ≀ 200 000, 0 ≀ k ≀ n) β€” the number of digits in the decimal representation of S and the maximum allowed number of changed digits. The second line contains the integer S. It's guaranteed that S has exactly n digits and doesn't contain any leading zeroes. Output Output the minimal possible value of S which Ania can end with. Note that the resulting integer should also have n digits. Examples Input 5 3 51528 Output 10028 Input 3 2 102 Output 100 Input 1 1 1 Output 0 Note A number has leading zeroes if it consists of at least two digits and its first digit is 0. For example, numbers 00, 00069 and 0101 have leading zeroes, while 0, 3000 and 1010 don't have leading zeroes. Submitted Solution: ``` entrada = (input()) vet=entrada.split(" ") tam = int(vet[0]) change = int(vet[1]) n = list(input()) aux = 0 aux1 = 0 while (aux != change and aux1 < tam): if (aux1 == 0): if (tam == 1): n[aux1]="0" aux+=1 elif (n[aux1]!="1"): n[aux1]="1" aux+=1 else: if (n[aux1]!="0"): n[aux1]="0" aux+=1 aux1+=1 n = "".join(n) print(n) ```
instruction
0
100,428
20
200,856
Yes
output
1
100,428
20
200,857
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ania has a large integer S. Its decimal representation has length n and doesn't contain any leading zeroes. Ania is allowed to change at most k digits of S. She wants to do it in such a way that S still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania finish with? Input The first line contains two integers n and k (1 ≀ n ≀ 200 000, 0 ≀ k ≀ n) β€” the number of digits in the decimal representation of S and the maximum allowed number of changed digits. The second line contains the integer S. It's guaranteed that S has exactly n digits and doesn't contain any leading zeroes. Output Output the minimal possible value of S which Ania can end with. Note that the resulting integer should also have n digits. Examples Input 5 3 51528 Output 10028 Input 3 2 102 Output 100 Input 1 1 1 Output 0 Note A number has leading zeroes if it consists of at least two digits and its first digit is 0. For example, numbers 00, 00069 and 0101 have leading zeroes, while 0, 3000 and 1010 don't have leading zeroes. Submitted Solution: ``` n, k = map(int, input().split()) s = input() if k == 0: print(s) exit() if n == 1: print(0) exit() first = True ans = [] cnt = 0 for i in s: if first and i != '1' and cnt < k: print(1, end='') cnt += 1 elif not first and i != '0' and cnt < k: print(0, end='') cnt += 1 else: print(i, end='') first = False ```
instruction
0
100,429
20
200,858
Yes
output
1
100,429
20
200,859
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ania has a large integer S. Its decimal representation has length n and doesn't contain any leading zeroes. Ania is allowed to change at most k digits of S. She wants to do it in such a way that S still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania finish with? Input The first line contains two integers n and k (1 ≀ n ≀ 200 000, 0 ≀ k ≀ n) β€” the number of digits in the decimal representation of S and the maximum allowed number of changed digits. The second line contains the integer S. It's guaranteed that S has exactly n digits and doesn't contain any leading zeroes. Output Output the minimal possible value of S which Ania can end with. Note that the resulting integer should also have n digits. Examples Input 5 3 51528 Output 10028 Input 3 2 102 Output 100 Input 1 1 1 Output 0 Note A number has leading zeroes if it consists of at least two digits and its first digit is 0. For example, numbers 00, 00069 and 0101 have leading zeroes, while 0, 3000 and 1010 don't have leading zeroes. Submitted Solution: ``` n,k = list(map(int,input().split())) arr = list(map(str,input())) if n==1 and k>=1: print(0) exit() ind = 0 temp = k while(temp): if ind>n-1: break if ind==0: if arr[ind]=='1': ind+=1 continue else: arr[ind]='1' ind+=1 temp-=1 continue if arr[ind]!='0': arr[ind]='0' temp-=1 ind+=1 else: ind+=1 print(''.join(str(y) for y in arr)) ```
instruction
0
100,430
20
200,860
Yes
output
1
100,430
20
200,861
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ania has a large integer S. Its decimal representation has length n and doesn't contain any leading zeroes. Ania is allowed to change at most k digits of S. She wants to do it in such a way that S still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania finish with? Input The first line contains two integers n and k (1 ≀ n ≀ 200 000, 0 ≀ k ≀ n) β€” the number of digits in the decimal representation of S and the maximum allowed number of changed digits. The second line contains the integer S. It's guaranteed that S has exactly n digits and doesn't contain any leading zeroes. Output Output the minimal possible value of S which Ania can end with. Note that the resulting integer should also have n digits. Examples Input 5 3 51528 Output 10028 Input 3 2 102 Output 100 Input 1 1 1 Output 0 Note A number has leading zeroes if it consists of at least two digits and its first digit is 0. For example, numbers 00, 00069 and 0101 have leading zeroes, while 0, 3000 and 1010 don't have leading zeroes. Submitted Solution: ``` n, k = map(int, input().split()) d = list(input()) if n == 1 and k == 1: exit(print(0)) (d[0], k) = ('1', k - 1) if d[0] != '1' and k > 0 else (d[0], k) i = 1 while i < n and k != 0: (d[i], k) = ('0', k - 1) if d[i] != '0' else (d[i], k) i += 1 print(*d, sep="") ```
instruction
0
100,431
20
200,862
Yes
output
1
100,431
20
200,863
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ania has a large integer S. Its decimal representation has length n and doesn't contain any leading zeroes. Ania is allowed to change at most k digits of S. She wants to do it in such a way that S still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania finish with? Input The first line contains two integers n and k (1 ≀ n ≀ 200 000, 0 ≀ k ≀ n) β€” the number of digits in the decimal representation of S and the maximum allowed number of changed digits. The second line contains the integer S. It's guaranteed that S has exactly n digits and doesn't contain any leading zeroes. Output Output the minimal possible value of S which Ania can end with. Note that the resulting integer should also have n digits. Examples Input 5 3 51528 Output 10028 Input 3 2 102 Output 100 Input 1 1 1 Output 0 Note A number has leading zeroes if it consists of at least two digits and its first digit is 0. For example, numbers 00, 00069 and 0101 have leading zeroes, while 0, 3000 and 1010 don't have leading zeroes. Submitted Solution: ``` n,k = [int(x) for x in input().split()] s=list(input()) if k>0: if s[0]!='1': s[0]='1' k-=1 if n>k: for i in range(1,k+1): s[i]='0' print("".join(s)) else: print("".join(s)) ```
instruction
0
100,432
20
200,864
No
output
1
100,432
20
200,865
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ania has a large integer S. Its decimal representation has length n and doesn't contain any leading zeroes. Ania is allowed to change at most k digits of S. She wants to do it in such a way that S still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania finish with? Input The first line contains two integers n and k (1 ≀ n ≀ 200 000, 0 ≀ k ≀ n) β€” the number of digits in the decimal representation of S and the maximum allowed number of changed digits. The second line contains the integer S. It's guaranteed that S has exactly n digits and doesn't contain any leading zeroes. Output Output the minimal possible value of S which Ania can end with. Note that the resulting integer should also have n digits. Examples Input 5 3 51528 Output 10028 Input 3 2 102 Output 100 Input 1 1 1 Output 0 Note A number has leading zeroes if it consists of at least two digits and its first digit is 0. For example, numbers 00, 00069 and 0101 have leading zeroes, while 0, 3000 and 1010 don't have leading zeroes. Submitted Solution: ``` n,k=map(int,input().split()) a=input() a=[i for i in a] for i in range(n): if k==0: break if i==0: if a[0]!='1': a[0]='1' k-=1 else: if a[i]!='0': a[i]='0' k-=1 for i in a: print(i,end='') ```
instruction
0
100,433
20
200,866
No
output
1
100,433
20
200,867
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ania has a large integer S. Its decimal representation has length n and doesn't contain any leading zeroes. Ania is allowed to change at most k digits of S. She wants to do it in such a way that S still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania finish with? Input The first line contains two integers n and k (1 ≀ n ≀ 200 000, 0 ≀ k ≀ n) β€” the number of digits in the decimal representation of S and the maximum allowed number of changed digits. The second line contains the integer S. It's guaranteed that S has exactly n digits and doesn't contain any leading zeroes. Output Output the minimal possible value of S which Ania can end with. Note that the resulting integer should also have n digits. Examples Input 5 3 51528 Output 10028 Input 3 2 102 Output 100 Input 1 1 1 Output 0 Note A number has leading zeroes if it consists of at least two digits and its first digit is 0. For example, numbers 00, 00069 and 0101 have leading zeroes, while 0, 3000 and 1010 don't have leading zeroes. Submitted Solution: ``` n,s = map(int,input().split()) a = [*input()] i = 1 if n == 1 and s >0: a[0] = 0 if int(a[0]) > 1: a[0] = 1 s -=1 while s > 0 and i < n: if int(a[i]) > 0: a[i] = 0 s -=1 i+=1 print(*a,sep='') ```
instruction
0
100,434
20
200,868
No
output
1
100,434
20
200,869
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ania has a large integer S. Its decimal representation has length n and doesn't contain any leading zeroes. Ania is allowed to change at most k digits of S. She wants to do it in such a way that S still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania finish with? Input The first line contains two integers n and k (1 ≀ n ≀ 200 000, 0 ≀ k ≀ n) β€” the number of digits in the decimal representation of S and the maximum allowed number of changed digits. The second line contains the integer S. It's guaranteed that S has exactly n digits and doesn't contain any leading zeroes. Output Output the minimal possible value of S which Ania can end with. Note that the resulting integer should also have n digits. Examples Input 5 3 51528 Output 10028 Input 3 2 102 Output 100 Input 1 1 1 Output 0 Note A number has leading zeroes if it consists of at least two digits and its first digit is 0. For example, numbers 00, 00069 and 0101 have leading zeroes, while 0, 3000 and 1010 don't have leading zeroes. Submitted Solution: ``` n, k = map(int, input().split(' ')) nu = input() if n == 1: print(0) else: num = [i for i in nu] for c in range(n): if k == 0: break if c == 0 and num[c] != '1': num[c] = '1' k -= 1 else: if num[c] != '0' and c != 0: num[c] = '0' k -= 1 print(''.join(num)) ```
instruction
0
100,435
20
200,870
No
output
1
100,435
20
200,871
Provide tags and a correct Python 3 solution for this coding contest problem. "This problem is rubbish! There is not statement, and there are only 5 test cases. The problemsetter took liberties with this problem!" β€” people complained in the comments to one round on Codeforces. And even more... No, wait, the checker for the problem was alright, that's a mercy. Input The only line of the input contains an integer between 1 and 5, inclusive. All tests for this problem are different. The contents of the test case doesn't need to be equal to its index. Output The only line of the output contains an integer between 1 and 3, inclusive. Examples Note This problem has no samples, since there so few test cases.
instruction
0
100,590
20
201,180
Tags: *special, brute force Correct Solution: ``` n = int(input()) print(1 if n == 5 else n%3 + 1) ```
output
1
100,590
20
201,181
Provide tags and a correct Python 3 solution for this coding contest problem. "This problem is rubbish! There is not statement, and there are only 5 test cases. The problemsetter took liberties with this problem!" β€” people complained in the comments to one round on Codeforces. And even more... No, wait, the checker for the problem was alright, that's a mercy. Input The only line of the input contains an integer between 1 and 5, inclusive. All tests for this problem are different. The contents of the test case doesn't need to be equal to its index. Output The only line of the output contains an integer between 1 and 3, inclusive. Examples Note This problem has no samples, since there so few test cases.
instruction
0
100,591
20
201,182
Tags: *special, brute force Correct Solution: ``` import random x = int(input()) print(1 if x == 3 or x==5 else 2 if x==1 or x==4 else 3) ```
output
1
100,591
20
201,183
Provide tags and a correct Python 3 solution for this coding contest problem. "This problem is rubbish! There is not statement, and there are only 5 test cases. The problemsetter took liberties with this problem!" β€” people complained in the comments to one round on Codeforces. And even more... No, wait, the checker for the problem was alright, that's a mercy. Input The only line of the input contains an integer between 1 and 5, inclusive. All tests for this problem are different. The contents of the test case doesn't need to be equal to its index. Output The only line of the output contains an integer between 1 and 3, inclusive. Examples Note This problem has no samples, since there so few test cases.
instruction
0
100,592
20
201,184
Tags: *special, brute force Correct Solution: ``` a=int(input()) if a==1: print("2") if a==2: print("3") if a==3: print("1") if a==4: print("2") if a==5: print("1") ```
output
1
100,592
20
201,185
Provide tags and a correct Python 3 solution for this coding contest problem. "This problem is rubbish! There is not statement, and there are only 5 test cases. The problemsetter took liberties with this problem!" β€” people complained in the comments to one round on Codeforces. And even more... No, wait, the checker for the problem was alright, that's a mercy. Input The only line of the input contains an integer between 1 and 5, inclusive. All tests for this problem are different. The contents of the test case doesn't need to be equal to its index. Output The only line of the output contains an integer between 1 and 3, inclusive. Examples Note This problem has no samples, since there so few test cases.
instruction
0
100,593
20
201,186
Tags: *special, brute force Correct Solution: ``` x = int(input()) if x == 1: print(2) elif x == 2: print(3) elif x == 3: print(1) elif x == 4: print(2) elif x == 5: print(1) ```
output
1
100,593
20
201,187
Provide tags and a correct Python 3 solution for this coding contest problem. "This problem is rubbish! There is not statement, and there are only 5 test cases. The problemsetter took liberties with this problem!" β€” people complained in the comments to one round on Codeforces. And even more... No, wait, the checker for the problem was alright, that's a mercy. Input The only line of the input contains an integer between 1 and 5, inclusive. All tests for this problem are different. The contents of the test case doesn't need to be equal to its index. Output The only line of the output contains an integer between 1 and 3, inclusive. Examples Note This problem has no samples, since there so few test cases.
instruction
0
100,594
20
201,188
Tags: *special, brute force Correct Solution: ``` N = int(input()) ans = [1, 2, 3, 1, 2, 1] print(ans[N]) ```
output
1
100,594
20
201,189
Provide tags and a correct Python 3 solution for this coding contest problem. "This problem is rubbish! There is not statement, and there are only 5 test cases. The problemsetter took liberties with this problem!" β€” people complained in the comments to one round on Codeforces. And even more... No, wait, the checker for the problem was alright, that's a mercy. Input The only line of the input contains an integer between 1 and 5, inclusive. All tests for this problem are different. The contents of the test case doesn't need to be equal to its index. Output The only line of the output contains an integer between 1 and 3, inclusive. Examples Note This problem has no samples, since there so few test cases.
instruction
0
100,595
20
201,190
Tags: *special, brute force Correct Solution: ``` print([1,2,3,1,2,1][int(input())]) # # # # # # # # # ############################## ```
output
1
100,595
20
201,191
Provide tags and a correct Python 3 solution for this coding contest problem. "This problem is rubbish! There is not statement, and there are only 5 test cases. The problemsetter took liberties with this problem!" β€” people complained in the comments to one round on Codeforces. And even more... No, wait, the checker for the problem was alright, that's a mercy. Input The only line of the input contains an integer between 1 and 5, inclusive. All tests for this problem are different. The contents of the test case doesn't need to be equal to its index. Output The only line of the output contains an integer between 1 and 3, inclusive. Examples Note This problem has no samples, since there so few test cases.
instruction
0
100,596
20
201,192
Tags: *special, brute force Correct Solution: ``` a=int(input()) if a==5: print(1) else: print(a%3+1) ```
output
1
100,596
20
201,193
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a programming language in which every program is a non-empty sequence of "<" and ">" signs and digits. Let's explain how the interpreter of this programming language works. A program is interpreted using movement of instruction pointer (IP) which consists of two parts. * Current character pointer (CP); * Direction pointer (DP) which can point left or right; Initially CP points to the leftmost character of the sequence and DP points to the right. We repeat the following steps until the first moment that CP points to somewhere outside the sequence. * If CP is pointing to a digit the interpreter prints that digit then CP moves one step according to the direction of DP. After that the value of the printed digit in the sequence decreases by one. If the printed digit was 0 then it cannot be decreased therefore it's erased from the sequence and the length of the sequence decreases by one. * If CP is pointing to "<" or ">" then the direction of DP changes to "left" or "right" correspondingly. Then CP moves one step according to DP. If the new character that CP is pointing to is "<" or ">" then the previous character will be erased from the sequence. If at any moment the CP goes outside of the sequence the execution is terminated. It's obvious the every program in this language terminates after some steps. We have a sequence s1, s2, ..., sn of "<", ">" and digits. You should answer q queries. Each query gives you l and r and asks how many of each digit will be printed if we run the sequence sl, sl + 1, ..., sr as an independent program in this language. Input The first line of input contains two integers n and q (1 ≀ n, q ≀ 100) β€” represents the length of the sequence s and the number of queries. The second line contains s, a sequence of "<", ">" and digits (0..9) written from left to right. Note, that the characters of s are not separated with spaces. The next q lines each contains two integers li and ri (1 ≀ li ≀ ri ≀ n) β€” the i-th query. Output For each query print 10 space separated integers: x0, x1, ..., x9 where xi equals the number of times the interpreter prints i while running the corresponding program. Print answers to the queries in the order they are given in input. Examples Input 7 4 1&gt;3&gt;22&lt; 1 3 4 7 7 7 1 7 Output 0 1 0 1 0 0 0 0 0 0 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 3 2 1 0 0 0 0 0 0 Submitted Solution: ``` n,Q = map(int,input().strip().split()) s = input() d = 1 for q in range(Q): arr = [0]*(10) l,r = map(int,input().strip().split()) su = "" for i in range(l-1,r): su+=s[i] su = list(su) i = 0 d = 1 #print(su) while i<len(su) and i>=0: if su[i].isdigit(): arr[int(su[i])]+=1 if su[i]=='0': su = su[:i]+su[i+1:] else: su[i] = str(int(su[i])-1) if d==1: i+=1; else: i-=1; else: if su[i]=='>' or su[i]=='<': if d==1 and i!=0: if su[i-1]=='>' or su[i-1]=='<' or su[i-1]=='-1': su = su[:i-1]+su[i:] i-=1 if d==0 and i!=n-1: if su[i+1]=='>' or su[i+1]=='<' or su[i+1]=='-1': su = su[:i+1]+su[i+2:] if su[i]=='>': d = 1 else: d = 0 if d==0: i-=1; else: i+=1 #print(su,i) #print(arr) #print(su) print(*arr) ```
instruction
0
100,628
20
201,256
No
output
1
100,628
20
201,257
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a programming language in which every program is a non-empty sequence of "<" and ">" signs and digits. Let's explain how the interpreter of this programming language works. A program is interpreted using movement of instruction pointer (IP) which consists of two parts. * Current character pointer (CP); * Direction pointer (DP) which can point left or right; Initially CP points to the leftmost character of the sequence and DP points to the right. We repeat the following steps until the first moment that CP points to somewhere outside the sequence. * If CP is pointing to a digit the interpreter prints that digit then CP moves one step according to the direction of DP. After that the value of the printed digit in the sequence decreases by one. If the printed digit was 0 then it cannot be decreased therefore it's erased from the sequence and the length of the sequence decreases by one. * If CP is pointing to "<" or ">" then the direction of DP changes to "left" or "right" correspondingly. Then CP moves one step according to DP. If the new character that CP is pointing to is "<" or ">" then the previous character will be erased from the sequence. If at any moment the CP goes outside of the sequence the execution is terminated. It's obvious the every program in this language terminates after some steps. We have a sequence s1, s2, ..., sn of "<", ">" and digits. You should answer q queries. Each query gives you l and r and asks how many of each digit will be printed if we run the sequence sl, sl + 1, ..., sr as an independent program in this language. Input The first line of input contains two integers n and q (1 ≀ n, q ≀ 100) β€” represents the length of the sequence s and the number of queries. The second line contains s, a sequence of "<", ">" and digits (0..9) written from left to right. Note, that the characters of s are not separated with spaces. The next q lines each contains two integers li and ri (1 ≀ li ≀ ri ≀ n) β€” the i-th query. Output For each query print 10 space separated integers: x0, x1, ..., x9 where xi equals the number of times the interpreter prints i while running the corresponding program. Print answers to the queries in the order they are given in input. Examples Input 7 4 1&gt;3&gt;22&lt; 1 3 4 7 7 7 1 7 Output 0 1 0 1 0 0 0 0 0 0 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 3 2 1 0 0 0 0 0 0 Submitted Solution: ``` n,Q = map(int,input().strip().split()) s = input() d = 1 for q in range(Q): arr = [0]*(10) l,r = map(int,input().strip().split()) su = "" for i in range(l-1,r): su+=s[i] su = list(su) i = 0 d = 1 print(su) while i<len(su) and i>=0: if su[i].isdigit(): arr[int(su[i])]+=1 if su[i]=='0': su = su[:i]+su[i+1:] #i-=1 else: su[i] = str(int(su[i])-1) if d==1: i+=1 else: i-=1; else: if su[i]=='>' or su[i]=='<': if d==1 and i!=0: if su[i-1]=='>' or su[i-1]=='<' or su[i-1]=='-1': su = su[:i-1]+su[i:] #i-=1 if d==0 and i!=n-1: if su[i+1]=='>' or su[i+1]=='<' or su[i+1]=='-1': su = su[:i+1]+su[i+2:] if su[i]=='>': d = 1 else: d = 0 if d==0: i-=1; else: i+=1 #print(su,i) #print(arr) #print(su) print(*arr) ```
instruction
0
100,629
20
201,258
No
output
1
100,629
20
201,259
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a programming language in which every program is a non-empty sequence of "<" and ">" signs and digits. Let's explain how the interpreter of this programming language works. A program is interpreted using movement of instruction pointer (IP) which consists of two parts. * Current character pointer (CP); * Direction pointer (DP) which can point left or right; Initially CP points to the leftmost character of the sequence and DP points to the right. We repeat the following steps until the first moment that CP points to somewhere outside the sequence. * If CP is pointing to a digit the interpreter prints that digit then CP moves one step according to the direction of DP. After that the value of the printed digit in the sequence decreases by one. If the printed digit was 0 then it cannot be decreased therefore it's erased from the sequence and the length of the sequence decreases by one. * If CP is pointing to "<" or ">" then the direction of DP changes to "left" or "right" correspondingly. Then CP moves one step according to DP. If the new character that CP is pointing to is "<" or ">" then the previous character will be erased from the sequence. If at any moment the CP goes outside of the sequence the execution is terminated. It's obvious the every program in this language terminates after some steps. We have a sequence s1, s2, ..., sn of "<", ">" and digits. You should answer q queries. Each query gives you l and r and asks how many of each digit will be printed if we run the sequence sl, sl + 1, ..., sr as an independent program in this language. Input The first line of input contains two integers n and q (1 ≀ n, q ≀ 100) β€” represents the length of the sequence s and the number of queries. The second line contains s, a sequence of "<", ">" and digits (0..9) written from left to right. Note, that the characters of s are not separated with spaces. The next q lines each contains two integers li and ri (1 ≀ li ≀ ri ≀ n) β€” the i-th query. Output For each query print 10 space separated integers: x0, x1, ..., x9 where xi equals the number of times the interpreter prints i while running the corresponding program. Print answers to the queries in the order they are given in input. Examples Input 7 4 1&gt;3&gt;22&lt; 1 3 4 7 7 7 1 7 Output 0 1 0 1 0 0 0 0 0 0 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 3 2 1 0 0 0 0 0 0 Submitted Solution: ``` R = lambda: map(int, input().split()) n, q = R() s = input() for _ in range(q): l, r = R() l -= 1 r -= 1 cs = [c for c in s[l:r + 1]] res = [0] * 10 p = 0 dir = 1 while 0 <= p < len(cs): if cs[p].isnumeric(): num = int(cs[p]) res[num] += 1 if not num: cs[p] = '' else: cs[p] = str(num - 1) elif cs[p] == '<': dir = -1 if p + dir >= 0 and cs[p + dir] in '<>': cs[p] = '' elif cs[p] == '>': dir = 1 if p + dir < len(cs) and cs[p + dir] in '<>': cs[p] = '' p += dir print(' '.join(map(str, res))) ```
instruction
0
100,630
20
201,260
No
output
1
100,630
20
201,261
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya came across an interval of numbers [a, a + l - 1]. Let F(x) be the number of lucky digits of number x. Find the minimum b (a < b) such, that F(a) = F(b), F(a + 1) = F(b + 1), ..., F(a + l - 1) = F(b + l - 1). Input The single line contains two integers a and l (1 ≀ a, l ≀ 109) β€” the interval's first number and the interval's length correspondingly. Output On the single line print number b β€” the answer to the problem. Examples Input 7 4 Output 17 Input 4 7 Output 14 Note Consider that [a, b] denotes an interval of integers; this interval includes the boundaries. That is, <image> Submitted Solution: ``` def F(x): q = 0 for i in str(x): if i == '4' or i == '7': q += 1 return q a, l = map(lambda x: int(x), input().split()) if l > a: print(10**len(str(l)) + a) else: L = l Fa = [F(i) for i in range(a, a+l)] b = a + 1 while True: for i in range(l): if b + i >= a + L: Fa.append(F(b + i)) L += 1 if Fa[i] != Fa[b + i - a]: break else: print(b) break b += 1 ```
instruction
0
101,229
20
202,458
No
output
1
101,229
20
202,459
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya came across an interval of numbers [a, a + l - 1]. Let F(x) be the number of lucky digits of number x. Find the minimum b (a < b) such, that F(a) = F(b), F(a + 1) = F(b + 1), ..., F(a + l - 1) = F(b + l - 1). Input The single line contains two integers a and l (1 ≀ a, l ≀ 109) β€” the interval's first number and the interval's length correspondingly. Output On the single line print number b β€” the answer to the problem. Examples Input 7 4 Output 17 Input 4 7 Output 14 Note Consider that [a, b] denotes an interval of integers; this interval includes the boundaries. That is, <image> Submitted Solution: ``` a, l = list(map(int, (input().split()))) def f(a): counter = 0 while a > 0: digit = a % 10 a /= 10 if digit == 7 or digit == 4: counter += 1 return counter b = a + 1 wrong = False while True: for i in range(l): if f(b + i) != f(a + i): wrong = True break if wrong: b += 1 wrong = False else: print(b) exit() ```
instruction
0
101,230
20
202,460
No
output
1
101,230
20
202,461
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya came across an interval of numbers [a, a + l - 1]. Let F(x) be the number of lucky digits of number x. Find the minimum b (a < b) such, that F(a) = F(b), F(a + 1) = F(b + 1), ..., F(a + l - 1) = F(b + l - 1). Input The single line contains two integers a and l (1 ≀ a, l ≀ 109) β€” the interval's first number and the interval's length correspondingly. Output On the single line print number b β€” the answer to the problem. Examples Input 7 4 Output 17 Input 4 7 Output 14 Note Consider that [a, b] denotes an interval of integers; this interval includes the boundaries. That is, <image> Submitted Solution: ``` def F(x): q = 0 for i in str(x): if i == '4' or i == '7': q += 1 return q a, l = map(lambda x: int(x), input().split()) if l >= a: if 1000000000 % l != 0: print(10**len(str(l)) + a) else: print(l + a) else: L = l Fa = [F(i) for i in range(a, a+l)] b = a + 1 while True: for i in range(l): if b + i >= a + L: Fa.append(F(b + i)) L += 1 if Fa[i] != Fa[b + i - a]: break else: print(b) break b += 1 ```
instruction
0
101,231
20
202,462
No
output
1
101,231
20
202,463
Provide tags and a correct Python 3 solution for this coding contest problem. A positive integer a is given. Baron Munchausen claims that he knows such a positive integer n that if one multiplies n by a, the sum of its digits decreases a times. In other words, S(an) = S(n)/a, where S(x) denotes the sum of digits of the number x. Find out if what Baron told can be true. Input The only line contains a single integer a (2 ≀ a ≀ 10^3). Output If there is no such number n, print -1. Otherwise print any appropriate positive integer n. Your number must not consist of more than 5β‹…10^5 digits. We can show that under given constraints either there is no answer, or there is an answer no longer than 5β‹…10^5 digits. Examples Input 2 Output 6 Input 3 Output 6669 Input 10 Output -1
instruction
0
101,232
20
202,464
Tags: brute force Correct Solution: ``` #!/bin/pypy3 from itertools import* from timeit import* from typing import Optional S=lambda x:sum(map(int,str(x))) def ceil_s_divisible_a(x:int,a:int) -> Optional[int]: z=S(x)%a if z: z=a-z tail=[] x=list(str(x)) while x: digit=x.pop() diff=min(z,9-int(digit)) z-=diff tail.append(str(int(digit)+diff)) if z==0:break else: return ceil_s_divisible_a(10**len(tail),a) x=''.join(x) + ''.join(reversed(tail)) assert S(x)%a==0 x=int(x) return x def smooth25(a): a=int(bin(a).rstrip('0'),2) while a%5==0: a//=5 return a==1 def solve(a): for first in range(1,60): # 120 q=str((first*10**3000+a-1) // a) # 5000 for s1 in range(1,200): i=1 s2=int(q[0]) while i<len(q) and s2<s1*a-10: s2+=int(q[i]); i+=1 for len1 in range(i,min(i+10,len(q))): small=int(q[:len1]) for z in range(4): # 10 small=ceil_s_divisible_a(small,a) if S(small*a)*a==S(small): return small small+=1 return None def powform(x:int)->str: s=str(x) try: i=s.find('00000') return f'{s[:i]} * 10 ** {len(s)-i} + {int(s[i:])}' except IndexError: return str(x) if 0: #for a in (a for a in range(2,1000)): for a in [999,909,813,777,957,921,855,933,831,942,891,846,807,783,888][1::3]: #for a in [32]: def work(): global x x=solve(a) t=timeit(work,number=1) if t>0.5 or x==None: if x!=None: print(a,t,'>>',powform(a*x)) else: print(a,t,'>> ?????') #print(solve(int(input()))) special=''' 660 0.5026652759997887 >> 3 * 10 ** 2640 + 35340 803 0.5102322779994211 >> 3 * 10 ** 2678 + 1614 912 0.5136937369998122 >> 3 * 10 ** 1825 + 240 918 0.5238579140004731 >> 3 * 10 ** 1813 + 1104 582 0.5302371079997101 >> 2 * 10 ** 2328 + 17116 612 0.5363936909998301 >> 2 * 10 ** 2413 + 10348 495 0.5372351949999938 >> 3 * 10 ** 2969 + 16305 927 0.5433051690006323 >> 3 * 10 ** 2195 + 21003 636 0.5471086210000067 >> 3 * 10 ** 1379 + 20004 531 0.5475810970001476 >> 2 * 10 ** 2140 + 439 64 0.5633312410000144 >> ????? 200 0.5639609099998779 >> ????? 100 0.565854023000611 >> ????? 125 0.5663040710005589 >> ????? 160 0.5668467480008985 >> ????? 800 0.5676178080002501 >> ????? 128 0.5676772269998764 >> ????? 80 0.5682811480000964 >> ????? 256 0.5685735130000467 >> ????? 250 0.5691464900000938 >> ????? 512 0.569266141999833 >> ????? 32 0.5692826909998985 >> ????? 50 0.5692834940000466 >> ????? 25 0.5696684799995637 >> ????? 400 0.5703751219998594 >> ????? 20 0.5706145570002263 >> ????? 500 0.5742691679997733 >> ????? 640 0.5749700739997934 >> ????? 40 0.5768258159996549 >> ????? 625 0.5775357299999087 >> ????? 16 0.5789494729997386 >> ????? 833 0.5855263899993588 >> 3 * 10 ** 2286 + 1404 792 0.5996652009998797 >> 3 * 10 ** 1903 + 16008 320 0.6031684260005932 >> ????? 10 0.6464516910000384 >> ????? 546 0.6579458010000963 >> 3 * 10 ** 2184 + 2454 5 0.6617960960002165 >> ????? 907 0.664109037000344 >> 3 * 10 ** 2538 + 2223 923 0.6807242180002504 >> 2 * 10 ** 2476 + 4141 723 0.6976773409996895 >> 3 * 10 ** 2892 + 1185 825 0.701172955000402 >> 4 * 10 ** 2476 + 123350 906 0.7062042559991824 >> 4 * 10 ** 1998 + 104 905 0.7086789289996887 >> 2 * 10 ** 2412 + 1540 911 0.711649564000254 >> 2 * 10 ** 2612 + 2044 934 0.7246100349993867 >> 2 * 10 ** 2570 + 51112 765 0.7552886830007992 >> 3 * 10 ** 2939 + 1725 981 0.7653923980005857 >> 4 * 10 ** 1965 + 1022 333 0.7884190810000291 >> 3 * 10 ** 2994 + 62934 663 0.8130600629992841 >> 3 * 10 ** 2546 + 11634 444 0.8443964660000347 >> 3 * 10 ** 1999 + 13956 720 0.8445076829993923 >> 2 * 10 ** 2779 + 159280 867 0.9858260920000248 >> 5 * 10 ** 1739 + 121 914 1.0558696210000562 >> 3 * 10 ** 1831 + 222 606 1.1190159360003236 >> 5 * 10 ** 2910 + 1318 948 1.1529914639995695 >> 6 * 10 ** 2466 + 1020 1000 1.2245053040005587 >> ????? 741 1.2366985769995154 >> 5 * 10 ** 2669 + 175 819 1.292531102999419 >> 8 * 10 ** 2949 + 31312 867 1.293641017000482 >> 5 * 10 ** 1739 + 121 961 1.431375496000328 >> 4 * 10 ** 1935 + 1112 913 2.0632996949998414 >> 5 * 10 ** 2323 + 16 861 2.1641551399998207 >> 11 * 10 ** 1847 + 1114 992 2.2718322470000203 >> 11 * 10 ** 2207 + 1504 936 2.3109037909998733 >> 11 * 10 ** 2108 + 3112 996 2.3603119750005135 >> 11 * 10 ** 1979 + 4300 951 2.380345242999283 >> 11 * 10 ** 1820 + 412 969 2.471255187000679 >> 11 * 10 ** 1942 + 241 828 2.504634874999283 >> 11 * 10 ** 1595 + 11212 693 2.5246166990000347 >> 13 * 10 ** 2494 + 423014 840 2.5490226490001078 >> 11 * 10 ** 1681 + 13120 983 2.618962229999852 >> 11 * 10 ** 1968 + 5011 963 2.641272683999887 >> 11 * 10 ** 2026 + 133 972 2.741184581000198 >> 12 * 10 ** 2130 + 312 555 2.787974407000547 >> 11 * 10 ** 2497 + 444445 873 2.8377116049996403 >> 11 * 10 ** 1774 + 133 903 2.898315477000324 >> 13 * 10 ** 1726 + 32 804 2.9635119349995875 >> 12 * 10 ** 1659 + 1500 864 3.032601443999738 >> 13 * 10 ** 2747 + 34016 759 3.0681308859993806 >> 13 * 10 ** 2504 + 311441 871 3.4960390779997397 >> 13 * 10 ** 2995 + 2405 902 4.413119433999782 >> 12 * 10 ** 1506 + 1110 997 4.446912733999852 >> 11 * 10 ** 1999 + 7 993 5.025415283999791 >> 23 * 10 ** 2130 + 31 837 5.286188959000356 >> 25 * 10 ** 2722 + 11063 786 5.390603378999913 >> 21 * 10 ** 1572 + 4002 801 5.4837765329994 >> 22 * 10 ** 1645 + 212 882 6.045185064999714 >> 22 * 10 ** 1822 + 1130 990 6.413724044000446 >> 39 * 10 ** 2970 + 302010 666 6.967028857000514 >> 33 * 10 ** 2997 + 32934 941 6.982767053000316 >> 21 * 10 ** 1885 + 312 924 7.134165846000542 >> 34 * 10 ** 2772 + 1110152 858 8.089877333000004 >> 41 * 10 ** 2573 + 12201142 939 8.241953895999359 >> 33 * 10 ** 1879 + 20001 813 3.1825667919993066 >> 3 * 10 ** 4065 + 7314 921 1.9310127280004963 >> 1 * 10 ** 3762 + 18008 831 1.683305384999585 >> 1 * 10 ** 3702 + 1646 846 1.4100486610004737 >> 1 * 10 ** 3419 + 44234 888 6.891388972000641 >> 3 * 10 ** 3998 + 27672 909 11.340291348999926 >> 7 * 10 ** 4673 + 17201 957 1.3982879649993265 >> 1 * 10 ** 4347 + 28403 933 0.9980270719997861 >> 1 * 10 ** 3746 + 233234 891 0.8806926099996417 >> 1 * 10 ** 3957 + 1079 783 0.6478317080000124 >> 1 * 10 ** 3162 + 22814 999 102.2252583720001 >> 89 * 10 ** 4760 + 20071 777 37.847382832999756 >> 24 * 10 ** 4661 + 474123 855 0.934857464999368 >> 1 * 10 ** 3420 + 21545 942 1.0410122209996189 >> 1 * 10 ** 4198 + 310058 807 0.7532789589995446 >> 1 * 10 ** 3234 + 1307123 ''' a=int(input()) for line in special.splitlines(): if line: expr,out=line.split('>>') expr=expr.split()[0] if int(expr)==a: print(-1 if out.strip()=='?????' else eval(out)//a) break else: print(solve(a)) ```
output
1
101,232
20
202,465
Provide tags and a correct Python 3 solution for this coding contest problem. A positive integer a is given. Baron Munchausen claims that he knows such a positive integer n that if one multiplies n by a, the sum of its digits decreases a times. In other words, S(an) = S(n)/a, where S(x) denotes the sum of digits of the number x. Find out if what Baron told can be true. Input The only line contains a single integer a (2 ≀ a ≀ 10^3). Output If there is no such number n, print -1. Otherwise print any appropriate positive integer n. Your number must not consist of more than 5β‹…10^5 digits. We can show that under given constraints either there is no answer, or there is an answer no longer than 5β‹…10^5 digits. Examples Input 2 Output 6 Input 3 Output 6669 Input 10 Output -1
instruction
0
101,233
20
202,466
Tags: brute force Correct Solution: ``` tabela = """ 3 11 1 1 2 1 2 6 1 4 2 11 3 20 7 2 7 9 1 7 6 9 11 40 1 2 40 0 11 1 7 6 1 6 3 12 2 13 2 11 12 1 13 1 9 15 1 8 30 14 1 10 12 11 9 36 15 11 14 2 2 14 4 17 2 14 9 2 13 27 18 1 34 4 1 33 1 19 1 15 18 1 14 9 21 1 17 10 2 14 8 22 1 12 6 1 10 3 23 1 11 3 11 9 27 24 1 39 6 1 38 0 26 1 16 18 2 15 36 27 11 67 4 2 67 0 28 1 24 18 11 22 36 29 1 15 6 11 19 0 30 2 16 1 11 15 2 31 11 23 27 1 22 18 33 2 66 1 11 65 2 34 1 25 39 2 24 30 35 1 22 27 2 20 18 36 1 48 1 1 47 6 37 11 22 18 11 20 0 38 2 29 18 2 28 33 39 11 80 11 2 77 1 41 11 39 3 2 36 15 42 11 30 5 1 30 4 43 2 33 18 1 31 9 44 2 42 9 1 41 0 45 11 102 2 2 102 0 46 1 41 36 11 39 18 47 2 40 27 1 41 6 48 11 74 3 2 74 0 49 1 37 18 2 35 33 51 1 37 2 1 35 13 52 11 49 6 1 48 3 53 11 47 36 11 35 18 54 1 106 5 1 105 0 55 1 28 9 1 26 0 56 1 68 24 1 67 36 57 11 39 4 1 33 23 58 11 48 36 2 32 36 59 11 43 9 1 47 30 60 1 32 2 1 31 4 61 11 45 9 2 44 0 62 11 39 18 11 44 18 63 1 143 7 1 142 0 65 1 34 15 1 28 12 66 11 67 2 11 66 4 67 11 52 27 1 47 9 68 1 51 18 11 54 30 69 2 47 8 1 42 31 70 1 34 3 1 28 24 71 11 61 36 11 63 18 72 1 84 5 1 83 3 73 1 36 9 1 29 27 74 11 41 18 11 38 0 75 11 114 3 2 114 0 76 11 75 30 1 66 6 77 1 39 12 1 34 15 78 1 159 4 1 153 14 79 2 101 21 2 89 33 81 11 174 3 2 174 0 82 1 119 9 11 115 0 83 1 64 9 2 86 12 84 1 60 7 1 54 20 85 1 41 6 1 51 36 86 1 79 24 11 70 21 87 2 59 2 1 54 37 88 1 122 9 1 120 0 89 11 64 27 1 59 18 90 2 406 1 11 405 0 91 1 45 9 1 40 18 92 1 91 30 11 83 6 93 11 111 29 2 148 31 94 1 88 12 2 104 3 95 1 46 3 11 58 27 96 1 100 1 1 99 5 97 1 49 30 2 58 27 98 11 91 9 1 66 36 99 2 1782 1 11 1781 0 101 1 50 15 1 48 3 102 11 76 16 1 67 5 103 1 53 33 2 85 33 104 1 117 3 1 111 24 105 1 72 2 2 69 16 106 11 74 36 11 62 27 107 2 92 18 1 75 0 108 1 185 5 1 184 0 109 1 56 27 1 63 27 110 1 52 6 1 51 3 111 11 58 10 11 57 8 112 1 151 9 1 145 18 113 1 58 21 1 71 18 114 11 76 2 1 70 25 115 1 57 21 2 70 36 116 11 77 9 1 44 36 117 1 264 4 1 263 3 118 2 108 9 1 100 18 119 2 134 12 11 126 27 120 2 122 2 11 121 1 121 1 109 3 11 108 6 122 2 146 30 1 108 3 123 11 155 7 11 151 17 124 11 70 9 11 90 12 126 1 228 2 1 227 4 127 1 65 18 11 105 36 129 1 93 13 2 77 32 130 1 64 24 1 59 3 131 1 67 30 2 144 15 132 1 134 1 1 132 11 133 1 65 21 2 117 12 134 1 97 36 11 87 27 135 11 281 3 2 281 4 136 11 155 18 1 153 0 137 1 68 24 1 62 12 138 11 97 4 2 93 20 139 1 71 24 11 115 33 140 1 65 3 1 59 24 141 1 99 5 1 97 7 142 11 133 3 1 110 36 143 1 69 18 1 65 9 144 11 164 1 2 164 3 145 1 72 27 1 94 9 146 1 69 15 1 62 21 147 1 108 31 2 191 28 148 11 150 9 11 147 0 149 2 107 9 1 127 21 150 11 150 2 2 150 4 151 1 117 18 1 146 12 152 1 139 27 1 161 36 153 11 329 4 1 329 37 154 1 76 27 1 71 0 155 11 120 21 11 85 18 156 2 314 2 11 311 4 157 11 180 33 11 172 21 158 1 191 24 1 179 21 159 11 101 23 1 122 1 161 1 181 9 1 108 18 162 1 323 5 1 321 6 163 2 255 18 11 245 27 164 1 159 24 1 155 3 165 11 331 1 11 330 5 166 1 178 15 1 105 9 167 1 157 33 11 180 24 168 11 226 7 1 223 11 169 1 225 9 11 218 36 170 1 118 18 1 115 0 171 1 343 1 11 342 8 172 1 163 9 11 154 27 173 11 166 21 1 171 39 174 1 122 31 2 117 23 175 1 83 15 1 77 12 176 1 238 9 2 237 0 177 1 130 38 2 228 32 178 2 119 9 1 113 9 179 1 91 36 1 116 27 180 1 326 1 1 325 4 181 1 92 9 11 124 9 182 1 88 24 1 83 3 183 1 125 7 2 236 34 184 1 249 9 11 245 0 185 11 95 9 11 93 9 186 1 158 11 11 100 25 187 11 169 6 1 218 27 188 2 133 27 2 162 36 189 1 603 5 1 599 10 190 11 130 18 1 124 9 191 11 305 15 11 300 12 192 11 386 1 2 386 11 193 11 214 15 2 250 36 194 1 221 30 1 252 0 195 1 394 7 1 388 11 196 2 147 36 11 133 0 197 11 220 18 1 214 27 198 11 714 2 11 713 3 199 1 145 9 11 192 36 201 2 134 10 1 134 26 202 1 95 15 1 92 3 203 1 199 24 1 186 21 204 1 147 14 2 128 16 205 1 195 21 11 190 6 206 2 187 27 1 87 27 207 1 421 4 11 420 14 208 11 281 18 2 278 0 209 1 101 33 1 185 6 210 1 144 10 2 141 8 211 11 195 3 2 183 33 212 1 262 21 1 254 15 213 2 284 7 2 283 5 214 1 319 15 11 314 12 215 2 160 27 1 137 18 216 1 346 5 1 345 10 217 2 248 27 1 177 27 218 1 196 30 1 240 12 219 11 754 9 11 750 0 220 1 101 6 1 99 3 221 11 238 12 1 237 6 222 11 113 5 11 111 13 223 2 297 18 1 245 24 224 1 307 27 1 301 0 225 11 255 4 2 255 0 226 1 208 27 11 200 18 227 2 253 33 1 264 21 228 1 153 4 11 149 17 229 2 265 24 1 309 27 230 2 158 18 1 153 9 231 11 311 10 2 308 8 232 2 212 24 1 204 30 233 11 264 9 1 314 0 234 2 528 7 11 527 6 235 1 117 36 2 205 27 236 2 322 36 2 307 36 237 1 387 2 1 383 22 238 11 313 30 1 325 39 239 2 563 18 2 558 0 240 1 364 6 1 363 0 241 2 274 21 1 107 15 242 1 123 36 11 208 36 243 11 496 8 2 496 14 244 11 167 18 2 211 36 245 1 164 9 1 107 30 246 11 355 11 11 352 1 247 1 229 39 11 267 39 248 1 282 15 11 276 9 249 2 337 19 1 326 35 251 1 230 18 2 227 0 252 1 415 5 1 413 5 253 1 123 36 2 219 27 254 2 233 12 2 278 30 255 1 166 1 1 164 11 257 1 288 12 11 287 33 258 2 181 11 1 158 34 259 1 262 9 1 256 9 260 1 119 9 1 113 18 261 11 518 4 2 518 6 262 11 410 9 11 406 9 263 1 242 21 1 285 39 264 1 214 2 1 212 13 265 1 280 24 1 267 39 266 2 245 33 1 295 6 267 1 192 14 2 342 23 268 1 377 27 11 346 27 269 11 484 27 1 484 0 270 2 664 2 11 663 5 271 11 383 18 11 378 0 272 2 367 9 11 364 9 273 1 274 1 1 268 17 274 1 125 6 1 118 30 275 1 125 3 1 123 6 276 1 197 14 11 350 32 277 1 305 21 1 237 21 278 2 255 18 2 309 0 279 11 572 1 11 569 12 280 1 193 18 1 187 9 281 2 443 21 11 437 6 282 1 193 13 1 367 25 283 1 197 27 2 233 33 284 11 274 39 1 395 6 285 1 196 26 2 192 4 286 1 130 3 1 125 24 287 11 324 9 1 320 9 288 11 648 2 2 648 0 289 2 329 36 2 321 0 290 2 200 27 1 195 0 291 1 392 5 1 389 7 292 1 134 6 1 126 30 293 2 270 24 11 252 39 294 1 206 38 11 387 23 295 1 332 21 2 327 15 296 2 546 9 1 544 9 297 2 1605 1 11 1604 2 298 11 198 18 1 193 27 299 2 270 21 11 260 33 300 2 152 1 11 151 2 301 1 375 15 1 370 12 302 2 374 12 2 369 15 303 2 607 1 11 606 2 304 1 341 3 1 400 36 305 11 273 9 2 272 0 306 1 604 4 1 603 2 307 11 356 9 11 353 9 308 1 143 15 1 137 12 309 1 489 2 1 486 22 310 1 263 9 11 226 33 311 11 311 12 11 310 6 312 2 626 1 11 623 2 313 11 284 33 2 405 27 314 11 422 18 11 419 0 315 11 710 1 2 710 2 316 1 309 9 1 381 9 317 1 507 30 2 519 24 318 1 266 19 1 253 29 319 1 372 30 11 417 36 321 11 428 4 2 426 5 322 2 297 15 2 225 0 323 1 377 18 11 415 18 324 1 613 4 1 612 12 325 1 149 9 1 143 18 326 1 502 3 11 513 6 327 1 445 29 2 439 1 328 1 310 15 1 305 12 329 1 302 33 1 348 33 330 2 661 1 11 660 2 331 11 451 27 1 512 21 332 1 481 9 1 480 0 333 11 1499 1 2 1499 2 334 11 380 27 2 370 18 335 2 234 9 1 213 18 336 1 451 8 1 446 19 337 1 294 12 11 301 33 338 1 302 15 11 296 39 339 2 228 11 1 222 37 340 1 154 3 11 221 36 341 2 434 18 1 483 27 342 1 685 1 11 684 13 343 1 149 18 2 372 27 344 1 221 9 1 290 15 345 2 246 34 11 230 38 346 1 402 15 11 404 39 347 11 324 15 11 552 39 348 11 462 19 1 469 29 349 11 398 39 1 313 3 350 1 161 18 1 155 9 351 2 679 6 2 677 11 352 1 474 9 1 473 0 353 11 473 18 2 469 9 354 1 470 5 1 463 19 355 11 272 39 1 394 6 356 11 242 18 1 236 9 357 2 487 34 2 470 29 358 11 242 18 11 313 30 359 11 451 36 1 450 0 360 1 466 4 1 465 3 361 2 262 36 1 173 0 362 11 491 18 1 480 18 363 2 503 11 1 515 10 364 1 167 15 1 161 12 365 1 165 3 1 158 33 366 1 256 35 2 484 26 367 2 497 27 1 493 9 368 1 416 18 1 491 9 369 11 832 2 11 829 1 370 11 188 9 11 186 9 371 1 410 33 11 417 21 372 1 622 8 11 618 24 373 1 665 15 2 582 6 374 1 301 24 1 296 12 375 1 566 6 1 565 0 376 1 591 24 1 496 36 377 1 429 27 11 436 9 378 1 933 11 1 929 1 379 1 587 18 1 584 0 380 1 173 15 2 246 36 381 1 495 35 1 487 4 382 11 530 30 11 522 15 383 2 341 6 1 339 3 384 1 773 2 1 772 4 385 1 178 21 1 173 6 386 1 432 36 1 423 9 387 1 719 1 1 718 7 388 11 256 18 2 252 0 389 1 609 3 11 516 9 390 11 783 11 2 780 1 391 1 575 27 2 746 30 392 1 277 27 11 345 30 393 11 523 4 2 517 23 394 2 444 3 11 435 15 395 1 387 18 1 374 36 396 11 1020 1 11 1019 6 397 11 632 9 1 619 18 398 1 680 21 11 721 36 399 11 601 11 11 895 6 401 2 549 36 2 534 18 402 11 284 26 1 264 4 403 1 637 33 11 712 0 404 1 184 9 1 180 9 405 11 822 5 2 822 0 406 11 573 18 1 518 18 407 11 818 9 11 815 0 408 1 530 23 1 523 16 409 2 460 33 2 451 12 410 2 382 3 11 381 6 411 11 473 13 11 472 5 412 1 189 12 2 358 39 413 1 467 18 1 368 18 414 1 800 4 1 799 1 415 2 308 36 1 428 18 416 2 649 3 11 647 15 417 11 518 8 11 514 25 418 1 191 6 1 369 24 419 1 471 21 2 464 15 420 11 283 5 1 283 4 421 11 656 24 1 564 0 422 1 197 36 2 375 0 423 11 846 4 11 845 2 424 1 444 18 1 437 18 425 2 288 9 11 285 0 426 1 285 4 1 555 34 427 2 478 15 2 474 3 428 11 409 15 2 444 33 429 2 1719 5 2 1715 1 430 2 373 33 1 305 0 431 1 542 36 1 523 36 432 2 689 1 11 688 9 433 2 491 9 1 667 36 434 1 416 3 1 308 27 435 1 290 25 1 279 32 436 2 287 9 1 376 33 437 2 492 12 1 582 9 438 1 1005 10 1 997 11 439 1 536 21 11 627 0 440 2 395 9 1 394 0 441 1 898 2 1 896 4 442 1 526 36 1 614 9 443 2 965 12 1 812 3 444 11 225 7 11 222 11 445 11 409 39 2 296 36 446 11 499 3 1 493 33 447 1 604 10 2 882 36 448 1 608 27 1 602 0 449 1 210 18 2 400 0 450 11 1014 1 2 1014 1 451 1 757 9 1 755 0 452 1 708 3 1 606 9 453 1 667 8 11 660 31 454 2 427 30 1 294 18 455 1 208 12 1 203 15 456 2 612 7 11 605 35 457 11 817 21 1 810 6 458 1 526 9 2 394 36 459 2 938 1 11 937 26 460 1 211 9 1 306 18 461 1 517 15 11 503 30 462 11 623 23 11 618 4 463 11 416 21 2 506 39 464 1 526 21 1 514 24 465 11 265 17 1 383 28 466 1 318 36 1 516 15 467 2 712 18 11 703 18 468 1 1056 1 1 1055 5 469 11 677 36 1 707 27 470 11 319 9 2 317 0 471 11 574 17 1 350 14 472 11 531 15 1 521 30 473 1 702 18 1 697 9 474 1 882 4 1 877 26 475 1 430 24 2 425 12 476 11 621 36 11 443 0 477 11 1021 16 11 1016 0 478 2 1679 18 11 1672 9 479 1 483 21 1 711 18 480 11 723 3 2 723 0 481 1 490 18 1 484 0 482 2 546 30 11 637 36 483 1 669 7 1 668 5 484 1 439 24 2 431 30 485 1 435 18 2 434 36 486 1 971 8 1 970 5 487 1 861 9 11 865 27 488 11 760 3 2 759 6 489 2 329 22 11 318 35 490 1 332 18 11 428 33 491 2 565 30 1 424 39 492 11 620 13 11 615 11 493 11 703 9 1 723 12 494 1 227 9 2 441 0 495 11 4456 1 2 4456 1 496 11 559 27 11 547 36 497 11 426 39 11 313 18 498 2 349 28 1 654 28 499 1 766 3 2 760 24 501 1 340 11 1 337 13 502 1 227 3 2 337 0 503 1 563 27 2 776 0 504 11 828 4 11 827 1 505 1 231 18 1 228 0 506 1 233 33 1 449 6 507 1 705 38 11 695 4 508 2 802 39 1 899 21 509 1 786 24 11 780 12 510 2 336 29 1 355 10 511 1 628 21 1 741 9 513 2 894 1 2 893 6 514 2 461 9 11 572 0 515 2 460 3 1 223 39 516 2 662 20 1 717 34 517 1 470 30 2 688 9 518 2 1042 18 2 1036 0 519 2 1101 6 2 1098 6 520 2 467 15 11 464 3 521 1 236 9 1 342 18 522 1 1063 1 1 1061 4 523 1 718 27 11 836 9 524 1 699 9 2 457 33 525 1 355 13 2 351 5 526 1 940 6 1 937 3 527 2 611 30 11 804 3 528 2 425 1 2 423 14 529 2 943 12 11 1050 36 530 11 387 9 1 540 36 531 1 1069 4 1 1068 1 532 2 478 27 1 227 36 533 2 596 15 1 556 12 534 11 374 25 1 686 22 535 1 568 33 1 669 27 536 11 742 9 1 573 33 537 2 717 7 1 716 20 538 11 727 36 2 838 3 539 2 483 9 1 233 27 540 1 1045 8 1 1044 0 541 11 845 27 1 953 36 542 11 1509 3 11 1505 15 543 1 729 5 1 717 34 544 1 731 9 11 845 24 545 1 378 36 1 365 27 546 2 1096 10 2 1090 8 547 2 969 21 2 961 15 548 1 254 36 1 246 0 549 1 1112 2 2 1111 39 550 1 249 9 1 247 0 551 11 668 18 1 409 18 552 11 765 26 2 760 7 553 1 1017 24 11 1038 12 554 1 815 33 11 822 21 555 11 281 11 11 279 7 556 11 500 6 1 862 21 557 1 758 36 11 624 0 558 11 1093 2 11 1092 5 559 1 523 18 11 470 27 560 1 627 15 1 621 12 561 2 783 8 2 775 34 562 1 880 21 11 491 33 563 1 650 12 1 646 6 564 11 744 4 2 744 5 565 11 505 15 2 505 3 566 11 493 9 1 604 36 567 1 1299 11 1 1295 6 568 11 952 18 1 780 36 569 1 887 21 2 879 24 570 11 382 4 1 376 23 571 1 511 30 1 380 27 572 1 257 3 1 251 24 573 1 391 11 11 757 26 574 1 651 39 11 685 6 575 1 517 9 11 384 9 576 1 5173 1 11 5172 9 577 2 643 9 2 764 27 578 1 772 9 11 656 3 579 11 387 1 1 382 26 580 1 268 24 11 385 18 581 1 1174 27 2 1282 39 582 2 1168 6 1 1167 12 583 1 1126 3 1 843 0 584 2 526 18 2 518 18 585 11 1317 1 2 1317 5 586 1 913 9 2 912 0 587 2 903 30 1 675 3 588 2 399 10 11 385 35 589 11 526 12 11 774 36 590 1 403 36 11 392 18 591 2 889 10 1 889 17 592 1 1090 12 1 1087 6 593 1 663 36 11 527 0 594 11 2293 5 11 2292 0 595 11 1096 9 2 998 9 596 1 661 6 2 520 24 597 11 738 17 1 442 5 598 11 669 24 2 798 9 599 1 737 3 11 725 0 600 1 303 2 1 302 4 601 2 798 27 1 938 3 602 11 945 27 11 936 18 603 1 1360 9 1 1357 7 604 1 892 9 2 1032 18 605 1 277 24 11 532 33 606 11 974 11 11 970 4 607 1 819 36 2 813 0 608 11 952 15 2 942 30 609 2 809 1 1 808 20 610 1 553 33 11 407 18 611 1 549 9 1 1085 9 612 1 1147 7 1 1146 4 613 11 939 9 11 937 0 614 1 1341 12 1 1337 15 615 11 617 2 11 612 28 616 2 551 3 2 545 24 617 11 1107 30 11 1098 15 618 11 769 22 1 893 20 619 1 1114 30 1 1106 15 620 11 465 18 11 340 36 621 1 1248 5 11 1247 20 622 11 620 9 2 785 27 623 11 1153 39 1 976 18 624 11 1253 17 2 1250 4 626 1 432 27 2 686 33 627 2 761 31 2 747 32 628 1 559 6 1 275 6 629 2 880 18 2 870 36 630 1 1420 1 1 1419 4 631 1 1029 27 2 1164 18 632 1 771 33 1 758 21 633 1 744 2 1 1117 6 634 11 932 12 1 1056 30 635 2 569 6 1 706 6 636 11 996 6 2 1033 11 637 11 718 39 2 569 21 638 11 575 18 2 1075 27 639 2 1302 8 2 1301 9 641 2 1004 3 11 851 18 642 2 869 29 2 857 37 643 11 717 33 2 830 36 644 1 299 3 1 438 18 645 11 829 25 1 823 2 646 2 1196 39 1 1117 24 647 2 1030 18 2 886 0 648 1 1198 9 1 1197 8 649 2 1155 9 11 1149 27 650 1 293 6 1 287 21 651 1 873 11 2 928 16 652 2 1013 39 11 1000 24 653 1 881 9 2 873 27 654 1 880 37 1 1303 36 655 1 583 6 2 586 12 656 11 735 27 11 730 0 657 11 1394 5 11 1390 10 658 1 727 9 1 719 36 659 1 734 33 2 726 39 660 11 662 2 11 661 4 661 1 453 36 1 729 39 662 2 739 12 2 737 6 663 1 448 20 11 877 35 664 2 1123 15 11 1237 9 665 1 746 18 2 587 36 666 11 1500 2 11 1499 4 667 1 909 27 2 874 27 668 1 755 24 1 1040 15 669 11 905 35 1 1331 27 670 2 873 27 1 765 21 671 1 1242 30 2 1371 24 672 1 901 13 1 896 14 673 2 904 27 1 890 27 674 2 1055 27 2 1049 0 675 11 1075 4 2 1075 3 676 2 908 36 1 1046 27 677 1 756 24 2 1051 6 678 1 902 5 2 454 14 679 1 1674 18 2 1671 0 680 11 763 30 2 750 33 681 1 918 22 11 902 20 682 1 981 27 2 974 9 683 11 1349 18 11 1339 36 684 2 1371 3 11 1369 4 685 1 309 9 1 302 27 686 1 1077 21 2 1055 6 687 1 924 20 1 917 7 688 1 806 6 2 872 18 689 1 1076 33 1 1218 24 690 11 449 2 2 445 19 691 2 1072 6 11 1229 24 692 2 796 18 11 597 36 693 2 3119 1 11 3118 3 694 1 913 36 2 791 18 695 2 623 21 2 770 21 696 1 917 38 1 910 1 697 2 1069 39 11 776 21 698 2 1095 24 2 1241 15 699 11 1399 21 11 1388 33 700 1 317 12 1 311 15 701 1 620 9 2 938 0 702 11 1187 5 11 1186 1 703 1 607 9 1 1200 27 704 1 945 9 1 943 0 705 1 468 7 1 465 8 706 2 949 36 2 626 24 707 11 815 36 11 803 27 708 1 967 28 2 1395 33 709 11 806 39 2 1090 3 710 1 600 18 11 659 0 711 11 1414 9 11 1411 7 712 2 640 27 11 630 27 713 1 1294 6 1 1127 33 714 1 1433 12 2 1428 12 715 1 322 6 1 317 21 716 1 643 15 2 625 39 717 2 1510 15 2 1508 0 718 2 1257 24 11 1251 3 719 2 1401 18 1 1395 18 720 1 814 5 1 813 3 721 2 1294 36 1 1280 27 722 2 814 6 2 954 36 723 1 1211 20 1 1204 13 724 11 486 18 1 959 27 725 11 648 6 2 481 18 726 1 1004 10 1 1001 2 727 11 811 21 2 802 6 728 2 653 18 2 647 9 729 11 1470 1 2 1470 4 730 1 333 27 1 326 9 731 2 1146 3 11 1289 39 732 1 499 25 2 974 31 733 11 1209 30 1 1240 39 734 1 507 18 1 649 39 735 11 979 7 1 978 29 736 11 1148 6 2 1144 21 737 11 1021 27 1 637 9 738 11 1753 14 11 1749 5 739 1 502 18 1 977 36 740 11 375 18 11 372 0 741 11 1484 3 11 1479 21 742 11 807 15 1 500 27 743 2 988 27 1 1312 6 744 11 832 16 1 1237 23 745 2 667 6 11 495 36 746 1 836 36 2 660 9 747 1 1413 25 1 1406 8 748 2 895 36 11 995 18 749 1 1185 21 1 1009 27 750 2 1128 3 11 1127 0 751 1 1031 18 11 1137 33 752 2 1344 30 1 1340 6 753 2 949 37 2 940 14 754 11 1011 18 11 1007 0 755 11 1122 36 11 918 36 756 2 1858 3 11 1857 0 757 11 1711 18 11 1506 36 758 2 1018 36 11 677 6 759 2 1295 38 11 2083 20 760 1 514 27 11 670 33 761 1 1197 15 1 1365 33 762 1 1607 15 11 1525 0 763 11 1061 36 1 1204 39 764 11 1651 36 11 1644 9 765 2 1552 1 2 1551 2 766 11 684 9 2 842 36 767 11 1197 21 2 1529 27 768 2 1925 2 11 1924 1 769 11 1371 15 2 1371 12 770 1 346 3 1 341 24 771 11 1031 16 1 1029 26 772 2 673 6 2 492 36 773 2 1256 18 2 1251 18 774 1 1398 20 1 1395 5 775 1 871 27 11 862 9 776 1 520 27 2 1031 18 777 1 784 13 1 778 5 778 1 1215 21 1 1208 33 779 2 1699 24 2 1687 21 780 1 1564 4 1 1558 14 781 2 1476 3 11 1299 18 782 2 947 9 2 942 27 783 2 1564 19 11 1562 12 784 1 1408 27 1 1217 36 785 1 353 15 11 874 12 786 2 1060 5 1 1558 30 787 2 1388 33 2 1554 9 788 2 1584 36 1 1402 6 789 11 1055 19 1 1053 20 790 1 764 6 2 947 24 791 1 1952 36 11 1937 9 792 11 1785 5 11 1784 3 793 11 1023 18 1 1415 36 794 1 742 12 1 923 30 795 11 452 1 1 643 17 796 11 648 12 11 1133 15 797 2 1104 9 2 1277 39 798 11 1804 30 11 1795 3 799 11 936 21 1 1486 6 801 11 1521 10 2 1516 19 802 11 1433 9 11 1078 0 803 11 716 3 11 709 33 804 1 560 16 11 516 32 805 1 1084 18 1 1245 24 806 11 1255 6 1 1178 12 807 1 549 26 11 1069 20 808 2 724 15 2 720 3 809 2 1093 36 2 899 18 810 2 1730 7 11 1729 2 811 1 1089 27 2 1086 0 812 2 1046 36 2 865 21 813 2 4065 1 2 4064 5 814 1 1637 18 1 1631 0 815 11 561 36 1 711 30 816 11 1052 22 2 1044 14 817 1 1508 30 1 1492 33 818 1 1278 27 1 1268 36 819 9 3279 2 9 3276 8 820 1 1145 9 11 1141 0 821 11 1647 18 2 1637 27 822 11 1022 38 11 1016 1 823 2 1113 36 1 1263 24 824 11 1659 36 1 1651 9 825 11 3302 2 11 3301 1 826 11 1295 33 2 1290 39 827 2 1269 9 2 1449 36 828 2 1595 6 2 1594 6 829 11 558 18 1 547 36 830 11 807 30 1 598 9 831 11 1854 12 2 1235 7 832 2 1298 3 11 1295 15 833 11 1449 30 2 1525 33 834 2 1728 39 11 1722 3 835 11 748 15 2 748 3 836 2 748 9 1 371 18 837 2 1853 5 2 1852 3 838 2 1683 27 11 1680 0 839 2 1425 3 2 1216 27 840 1 565 7 1 559 20 841 2 1111 18 11 935 39 842 1 1502 3 2 1309 39 843 2 1191 37 2 1768 21 844 2 941 12 11 750 21 845 1 945 9 11 942 0 846 1 1714 5 1 1713 10 847 2 759 9 11 754 9 848 1 879 6 1 873 30 849 1 1161 11 1 1159 4 850 11 573 18 1 564 27 851 1 1959 24 2 1954 12 852 2 1136 37 2 1125 14 853 11 1485 21 11 1474 15 854 11 1286 9 2 1137 9 855 11 1712 2 11 1710 7 856 1 1269 18 11 1442 0 857 1 1151 18 1 1146 0 858 11 3435 4 11 3429 14 859 2 767 12 1 379 39 860 1 557 27 2 602 9 861 2 1236 10 11 1227 29 862 2 1280 18 1 1483 21 863 1 769 27 1 575 36 864 11 1798 4 2 1797 4 865 11 726 9 2 825 27 866 1 1546 6 1 1543 12 867 1 1170 8 1 1163 22 868 1 777 3 2 1030 30 869 1 920 15 11 1673 6 870 1 598 2 2 565 25 871 1 1334 36 11 1273 18 872 1 581 9 11 1163 18 873 1 1759 3 1 1758 4 874 1 1367 27 2 971 18 875 1 1174 18 1 1168 9 876 11 2160 7 11 2152 32 877 11 1566 24 11 1756 0 878 2 1473 15 2 1887 0 879 2 1272 7 11 1887 39 880 1 1179 9 1 1177 0 881 1 986 9 1 978 27 882 1 1742 14 1 1738 2 883 1 1385 9 1 793 9 884 1 1238 18 1 1228 36 885 1 1755 6 1 1749 15 886 11 1820 27 2 1815 18 887 1 1978 6 11 1986 30 888 11 892 7 11 889 11 889 1 401 12 1 780 39 890 1 597 18 11 594 0 891 2 3903 1 11 3902 6 892 1 1206 27 11 1196 9 893 2 1412 21 2 1404 6 894 1 1196 26 2 1194 31 895 2 802 30 11 598 9 896 1 1803 27 1 1797 0 897 2 1325 25 11 1314 11 898 11 1202 9 1 402 15 899 2 1837 18 11 1969 18 900 2 4052 1 11 4051 0 901 11 621 36 2 996 0 902 1 1508 9 1 1505 9 903 2 1341 35 1 1485 22 904 1 1212 9 11 1210 0 905 2 811 33 11 799 21 906 1 1998 9 1 1994 6 907 11 944 3 11 937 33 908 11 1490 36 11 1479 9 909 9 3638 1 9 3636 17 910 1 412 18 1 407 9 911 11 1162 36 11 1147 36 912 2 1224 17 11 1217 22 913 1 1705 6 2 1307 36 914 1 1838 27 11 1422 39 915 1 619 38 2 1216 17 916 11 1230 36 1 1230 27 917 2 824 27 2 1216 36 918 1 1833 12 1 1830 6 919 11 1079 36 1 1485 36 920 2 827 21 1 818 15 921 2 1806 12 11 1876 24 922 1 1030 33 11 1225 0 923 11 1225 27 2 1442 3 924 11 1236 7 11 1230 20 925 11 468 18 11 465 0 926 1 1863 36 1 1855 9 927 1 1810 6 1 1808 5 928 1 1655 9 1 1853 27 929 11 836 39 11 1445 24 930 11 520 4 1 773 14 931 2 1455 21 1 1035 12 932 1 1243 18 2 614 9 933 11 1865 9 2 1855 33 934 1 2427 36 1 2417 18 935 1 840 27 1 829 18 936 1 1691 14 1 1687 5 937 2 1887 36 1 2074 36 938 11 1624 33 1 1777 3 939 11 634 19 1 1869 36 940 1 838 3 2 1038 30 941 2 1489 33 1 839 21 942 11 1719 39 11 1708 6 943 1 1714 21 1 2134 21 944 1 2107 18 2 1678 18 945 1 3197 14 1 3191 2 946 11 1612 27 2 1398 0 947 1 1707 24 1 1702 12 948 1 1553 35 1 1540 13 949 11 1478 3 11 1473 24 950 1 640 9 11 635 0 951 1 2177 21 1 2166 33 952 11 711 33 11 875 24 953 11 1476 18 11 1263 18 954 11 2235 2 2 2234 0 955 2 1485 27 11 562 18 956 11 3229 21 11 3222 6 957 11 1313 17 2 1303 22 958 2 1909 24 2 1900 21 959 1 1402 18 1 1860 6 960 1 965 1 1 964 5 961 2 1083 30 2 1071 24 962 2 1930 9 2 1924 9 963 2 1881 14 2 1869 37 964 1 437 18 2 856 0 965 2 865 39 11 865 6 966 1 637 19 11 1244 37 967 1 1095 24 2 1722 30 968 2 871 24 1 858 30 969 11 651 5 1 646 22 970 1 872 24 11 1078 33 971 1 1093 18 2 1080 9 972 1 1910 9 1 1909 10 973 1 1734 36 11 1730 18 974 1 1303 36 1 1514 15 975 11 2931 12 2 2928 0 976 1 1534 39 1 1086 12 977 1 1528 6 11 1296 18 978 1 1942 36 1 1931 30 979 1 1522 36 11 1300 18 980 1 879 18 1 876 0 981 1 1967 10 2 1966 5 982 1 2186 18 1 2389 36 983 11 1543 21 2 1743 39 984 11 990 17 11 985 13 985 11 1103 33 2 1093 21 986 2 1878 27 1 1815 24 987 2 1286 19 2 639 22 988 11 1325 9 1 877 30 989 2 1314 27 11 1545 9 990 9 3962 1 9 3961 8 991 1 1602 36 2 1595 36 992 11 1840 3 11 1653 18 993 2 2135 21 1 2189 39 994 2 1431 9 1 1659 6 995 1 739 36 2 1219 15 996 1 1347 16 1 1342 11 997 11 2004 36 11 2001 0 998 1 1327 27 11 903 27 999 99 4498 10 99 4497 8 """ def sd(x): return sum(map(int, str(x))) def ans(x): print(x) exit(0) def hardcode_solver(a): if a == 2: ans(6) if a == 4: ans(75) if a == 8: ans(125) def powers_of_10(x): if 10**18 % x == 0: ans(-1) def single_test(x, drange): found = False for d in drange: t = 10**d // x + 1 ad = sd(t) - sd(t*x)*x if ad > 0: print(x, d, ad) found = True break if not found: print(x, 'Failed') return def test1(x): plus = None minus = None ir = [1, 2, 11] ir = [1, 2, 11, 9, 99, 999] for d in range(1, 6400, 1): for i in ir: t = i*10**d // x + 1 ad = sd(t) - sd(t*x)*x if ad > 0: if ad < 40: plus = (i, d, ad) else: if -ad < 40: minus = (i, d, -ad) if plus != None and minus != None: print(x, *plus, *minus) return True return False def test_f(f): for x in range(990, 1001): if 10**18 % x == 0: continue if not f(x): print(x, 'Error') return def izracunato(x): a = map(lambda t: list(map(int, t.split(' '))), tabela.strip().split('\n')) for red in a: (idx, i1, d1, ad1, i2, d2, ad2) = red if idx == x: s1 = str(i1*10**d1 // x + 1) s2 = str(i2*10**d2 // x + 1) ans((s1 + '000000') * ad2 + (s2 + '000000') * ad1) def precompute(): test_f(test1) def task(): n = int(input()) hardcode_solver(n) powers_of_10(n) izracunato(n) task() ```
output
1
101,233
20
202,467
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A positive integer a is given. Baron Munchausen claims that he knows such a positive integer n that if one multiplies n by a, the sum of its digits decreases a times. In other words, S(an) = S(n)/a, where S(x) denotes the sum of digits of the number x. Find out if what Baron told can be true. Input The only line contains a single integer a (2 ≀ a ≀ 10^3). Output If there is no such number n, print -1. Otherwise print any appropriate positive integer n. Your number must not consist of more than 5β‹…10^5 digits. We can show that under given constraints either there is no answer, or there is an answer no longer than 5β‹…10^5 digits. Examples Input 2 Output 6 Input 3 Output 6669 Input 10 Output -1 Submitted Solution: ``` #!/bin/pypy3 from itertools import* from timeit import* #a={ #2:6 #,3:6669 #,4:75 #,7:14286 #,8:125 #} #print(a.get(int(input()),-1)) S=lambda x:sum(map(int,str(x))) def solve(a): for e,first in product(range(0,100),range(1,600)): x=first*10**e z=x%a if z: x+=a-z #assert x%a==0 if S(x//a)==S(x)*a: return x//a x+=a #assert x%a==0 if S(x//a)==S(x)*a: return x//a return -1 #for a in range(2,1000): #print(timeit(lambda: print(a,solve(a)),number=1)) print(solve(int(input()))) ```
instruction
0
101,234
20
202,468
No
output
1
101,234
20
202,469
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A positive integer a is given. Baron Munchausen claims that he knows such a positive integer n that if one multiplies n by a, the sum of its digits decreases a times. In other words, S(an) = S(n)/a, where S(x) denotes the sum of digits of the number x. Find out if what Baron told can be true. Input The only line contains a single integer a (2 ≀ a ≀ 10^3). Output If there is no such number n, print -1. Otherwise print any appropriate positive integer n. Your number must not consist of more than 5β‹…10^5 digits. We can show that under given constraints either there is no answer, or there is an answer no longer than 5β‹…10^5 digits. Examples Input 2 Output 6 Input 3 Output 6669 Input 10 Output -1 Submitted Solution: ``` a = int(input()) def SumOfNums(a): sum = 0 obj = str(a) for i in range(len(obj)): sum += int(obj[i]) return sum sum = SumOfNums(a) guess = -1 for i in range(1, 50001): if SumOfNums(i*a) == sum / a: guess = i break print(guess) ```
instruction
0
101,235
20
202,470
No
output
1
101,235
20
202,471