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. Andrew and Eugene are playing a game. Initially, Andrew has string s, consisting of digits. Eugene sends Andrew multiple queries of type "di β†’ ti", that means "replace all digits di in string s with substrings equal to ti". For example, if s = 123123, then query "2 β†’ 00" transforms s to 10031003, and query "3 β†’ " ("replace 3 by an empty string") transforms it to s = 1212. After all the queries Eugene asks Andrew to find the remainder after division of number with decimal representation equal to s by 1000000007 (109 + 7). When you represent s as a decimal number, please ignore the leading zeroes; also if s is an empty string, then it's assumed that the number equals to zero. Andrew got tired of processing Eugene's requests manually and he asked you to write a program for that. Help him! Input The first line contains string s (1 ≀ |s| ≀ 105), consisting of digits β€” the string before processing all the requests. The second line contains a single integer n (0 ≀ n ≀ 105) β€” the number of queries. The next n lines contain the descriptions of the queries. The i-th query is described by string "di->ti", where di is exactly one digit (from 0 to 9), ti is a string consisting of digits (ti can be an empty string). The sum of lengths of ti for all queries doesn't exceed 105. The queries are written in the order in which they need to be performed. Output Print a single integer β€” remainder of division of the resulting number by 1000000007 (109 + 7). Examples Input 123123 1 2->00 Output 10031003 Input 123123 1 3-> Output 1212 Input 222 2 2->0 0->7 Output 777 Input 1000000008 0 Output 1 Note Note that the leading zeroes are not removed from string s after the replacement (you can see it in the third sample). Submitted Solution: ``` mod = 10 ** 9 + 7 s = input() q = int(input()) for i in range(q): query = input().split("->") if (len(query) == 1): query.append("") s.replace(query[0], query[1]) print(int(s) % mod) ```
instruction
0
16,344
20
32,688
No
output
1
16,344
20
32,689
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Andrew and Eugene are playing a game. Initially, Andrew has string s, consisting of digits. Eugene sends Andrew multiple queries of type "di β†’ ti", that means "replace all digits di in string s with substrings equal to ti". For example, if s = 123123, then query "2 β†’ 00" transforms s to 10031003, and query "3 β†’ " ("replace 3 by an empty string") transforms it to s = 1212. After all the queries Eugene asks Andrew to find the remainder after division of number with decimal representation equal to s by 1000000007 (109 + 7). When you represent s as a decimal number, please ignore the leading zeroes; also if s is an empty string, then it's assumed that the number equals to zero. Andrew got tired of processing Eugene's requests manually and he asked you to write a program for that. Help him! Input The first line contains string s (1 ≀ |s| ≀ 105), consisting of digits β€” the string before processing all the requests. The second line contains a single integer n (0 ≀ n ≀ 105) β€” the number of queries. The next n lines contain the descriptions of the queries. The i-th query is described by string "di->ti", where di is exactly one digit (from 0 to 9), ti is a string consisting of digits (ti can be an empty string). The sum of lengths of ti for all queries doesn't exceed 105. The queries are written in the order in which they need to be performed. Output Print a single integer β€” remainder of division of the resulting number by 1000000007 (109 + 7). Examples Input 123123 1 2->00 Output 10031003 Input 123123 1 3-> Output 1212 Input 222 2 2->0 0->7 Output 777 Input 1000000008 0 Output 1 Note Note that the leading zeroes are not removed from string s after the replacement (you can see it in the third sample). Submitted Solution: ``` x=input() x.split y=int(input()) while(y>0): x=str(x) a=input() a.split() i=0 n=a[0] m="" for j in range(3,len(a)): m+=a[j] x=x.replace(n,m) x=int(x)%1000000007 y-=1 if x=="": print(0) else: print(int(x)%1000000007) ```
instruction
0
16,345
20
32,690
No
output
1
16,345
20
32,691
Provide a correct Python 3 solution for this coding contest problem. For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N). Constraints * 0 \leq N \leq 10^{18} Input Input is given from Standard Input in the following format: N Output Print the number of trailing zeros in the decimal notation of f(N). Examples Input 12 Output 1 Input 5 Output 0 Input 1000000000000000000 Output 124999999999999995
instruction
0
16,594
20
33,188
"Correct Solution: ``` #E N=int(input()) ans=0 if N%2==0: N=N//2 else: N=-1 cnt=1 while cnt<=N: cnt*=5 ans+=N//cnt print(ans) ```
output
1
16,594
20
33,189
Provide a correct Python 3 solution for this coding contest problem. For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N). Constraints * 0 \leq N \leq 10^{18} Input Input is given from Standard Input in the following format: N Output Print the number of trailing zeros in the decimal notation of f(N). Examples Input 12 Output 1 Input 5 Output 0 Input 1000000000000000000 Output 124999999999999995
instruction
0
16,595
20
33,190
"Correct Solution: ``` n=int(input()) if n%2:print(0) else: a=0 i=10 while i<=n: a+=n//i i*=5 print(a) ```
output
1
16,595
20
33,191
Provide a correct Python 3 solution for this coding contest problem. For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N). Constraints * 0 \leq N \leq 10^{18} Input Input is given from Standard Input in the following format: N Output Print the number of trailing zeros in the decimal notation of f(N). Examples Input 12 Output 1 Input 5 Output 0 Input 1000000000000000000 Output 124999999999999995
instruction
0
16,596
20
33,192
"Correct Solution: ``` n=int(input()) if n%2==1: print(0) else: a=10 ans=0 while a<=n: ans+=n//a a*=5 print(ans) ```
output
1
16,596
20
33,193
Provide a correct Python 3 solution for this coding contest problem. For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N). Constraints * 0 \leq N \leq 10^{18} Input Input is given from Standard Input in the following format: N Output Print the number of trailing zeros in the decimal notation of f(N). Examples Input 12 Output 1 Input 5 Output 0 Input 1000000000000000000 Output 124999999999999995
instruction
0
16,597
20
33,194
"Correct Solution: ``` N = int(input()) ans = 0 if N % 2 == 0: p = 10 while p <= N: ans += N // p p *= 5 print(ans) ```
output
1
16,597
20
33,195
Provide a correct Python 3 solution for this coding contest problem. For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N). Constraints * 0 \leq N \leq 10^{18} Input Input is given from Standard Input in the following format: N Output Print the number of trailing zeros in the decimal notation of f(N). Examples Input 12 Output 1 Input 5 Output 0 Input 1000000000000000000 Output 124999999999999995
instruction
0
16,598
20
33,196
"Correct Solution: ``` N=int(input()) if N%2==0: ans=0 x=10 while x<=N: ans+=N//x x*=5 else: ans=0 print(ans) ```
output
1
16,598
20
33,197
Provide a correct Python 3 solution for this coding contest problem. For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N). Constraints * 0 \leq N \leq 10^{18} Input Input is given from Standard Input in the following format: N Output Print the number of trailing zeros in the decimal notation of f(N). Examples Input 12 Output 1 Input 5 Output 0 Input 1000000000000000000 Output 124999999999999995
instruction
0
16,599
20
33,198
"Correct Solution: ``` N = int(input()) ans = 0 for i in range(1,30): ans += N//(5**i)//2 if N%2==1: ans = 0 print(ans) ```
output
1
16,599
20
33,199
Provide a correct Python 3 solution for this coding contest problem. For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N). Constraints * 0 \leq N \leq 10^{18} Input Input is given from Standard Input in the following format: N Output Print the number of trailing zeros in the decimal notation of f(N). Examples Input 12 Output 1 Input 5 Output 0 Input 1000000000000000000 Output 124999999999999995
instruction
0
16,600
20
33,200
"Correct Solution: ``` n=int(input()) if n%2==1: print(0) else: ans=0 n=n//2 while n!=0: n=n//5 ans+=n print(ans) ```
output
1
16,600
20
33,201
Provide a correct Python 3 solution for this coding contest problem. For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N). Constraints * 0 \leq N \leq 10^{18} Input Input is given from Standard Input in the following format: N Output Print the number of trailing zeros in the decimal notation of f(N). Examples Input 12 Output 1 Input 5 Output 0 Input 1000000000000000000 Output 124999999999999995
instruction
0
16,601
20
33,202
"Correct Solution: ``` n=int(input()) ans=0 if n%2== 0: for i in range(1,26): ans+=n//(2*5**i) print(ans) ```
output
1
16,601
20
33,203
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N). Constraints * 0 \leq N \leq 10^{18} Input Input is given from Standard Input in the following format: N Output Print the number of trailing zeros in the decimal notation of f(N). Examples Input 12 Output 1 Input 5 Output 0 Input 1000000000000000000 Output 124999999999999995 Submitted Solution: ``` n = int(input()) if n % 2: print(0) else: ans = 0 for i in range(1, 26): ans += n//(2*5**i) print(ans) ```
instruction
0
16,602
20
33,204
Yes
output
1
16,602
20
33,205
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N). Constraints * 0 \leq N \leq 10^{18} Input Input is given from Standard Input in the following format: N Output Print the number of trailing zeros in the decimal notation of f(N). Examples Input 12 Output 1 Input 5 Output 0 Input 1000000000000000000 Output 124999999999999995 Submitted Solution: ``` N = int(input()) if N & 1: print(0) exit() N //= 2 cnt = 0 while N: cnt += N//5 N //= 5 print(cnt) ```
instruction
0
16,603
20
33,206
Yes
output
1
16,603
20
33,207
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N). Constraints * 0 \leq N \leq 10^{18} Input Input is given from Standard Input in the following format: N Output Print the number of trailing zeros in the decimal notation of f(N). Examples Input 12 Output 1 Input 5 Output 0 Input 1000000000000000000 Output 124999999999999995 Submitted Solution: ``` N = int(input()) if N % 2 == 1: print(0) else: a = N // 2 S = 0 while a != 0: a //= 5 S += a print(S) ```
instruction
0
16,604
20
33,208
Yes
output
1
16,604
20
33,209
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N). Constraints * 0 \leq N \leq 10^{18} Input Input is given from Standard Input in the following format: N Output Print the number of trailing zeros in the decimal notation of f(N). Examples Input 12 Output 1 Input 5 Output 0 Input 1000000000000000000 Output 124999999999999995 Submitted Solution: ``` N = int(input()) if N % 2 == 1: print(0) else: ans = 0 for i in range(1, 26): ans += N // (5 ** i) // 2 print(ans) ```
instruction
0
16,605
20
33,210
Yes
output
1
16,605
20
33,211
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N). Constraints * 0 \leq N \leq 10^{18} Input Input is given from Standard Input in the following format: N Output Print the number of trailing zeros in the decimal notation of f(N). Examples Input 12 Output 1 Input 5 Output 0 Input 1000000000000000000 Output 124999999999999995 Submitted Solution: ``` def f(n): if(n%2==0): return int(n/10) else: return 0 print(f(int(input()))) ```
instruction
0
16,606
20
33,212
No
output
1
16,606
20
33,213
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N). Constraints * 0 \leq N \leq 10^{18} Input Input is given from Standard Input in the following format: N Output Print the number of trailing zeros in the decimal notation of f(N). Examples Input 12 Output 1 Input 5 Output 0 Input 1000000000000000000 Output 124999999999999995 Submitted Solution: ``` import re n = int(input()) i=n-2 if n < 2: print(0) else: while i >= 2: n *= i i -= 2 ans = re.search('0+$' , str(n)) print(0 if n%10 !=0 or n < 2 else len(str(n))-ans.start()) ```
instruction
0
16,607
20
33,214
No
output
1
16,607
20
33,215
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N). Constraints * 0 \leq N \leq 10^{18} Input Input is given from Standard Input in the following format: N Output Print the number of trailing zeros in the decimal notation of f(N). Examples Input 12 Output 1 Input 5 Output 0 Input 1000000000000000000 Output 124999999999999995 Submitted Solution: ``` # 148e from sys import stdin import re import numpy as np import math #stdin = open("test/abc148_e_sample-3.in") def get_rank(N): rank = int(np.log(N)/np.log(5)) #print(rank) num = 0 for i in range(1, rank+1): num_i = N//(2*5**i) #print(num_i) num += num_i return num N = int(stdin.readline().strip()) if N%2==1 or 0: print(0) else: print(get_rank(N)) ```
instruction
0
16,608
20
33,216
No
output
1
16,608
20
33,217
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N). Constraints * 0 \leq N \leq 10^{18} Input Input is given from Standard Input in the following format: N Output Print the number of trailing zeros in the decimal notation of f(N). Examples Input 12 Output 1 Input 5 Output 0 Input 1000000000000000000 Output 124999999999999995 Submitted Solution: ``` n = int(input()) str_n = str(int) digit = len(str_n) count = 0 if n%2 == 0: for i in range(1,digit+1): count += n//(10**i) print(count) ```
instruction
0
16,609
20
33,218
No
output
1
16,609
20
33,219
Provide tags and a correct Python 3 solution for this coding contest problem. Let s(x) be sum of digits in decimal representation of positive integer x. Given two integers n and m, find some positive integers a and b such that * s(a) β‰₯ n, * s(b) β‰₯ n, * s(a + b) ≀ m. Input The only line of input contain two integers n and m (1 ≀ n, m ≀ 1129). Output Print two lines, one for decimal representation of a and one for decimal representation of b. Both numbers must not contain leading zeros and must have length no more than 2230. Examples Input 6 5 Output 6 7 Input 8 16 Output 35 53 Note In the first sample, we have n = 6 and m = 5. One valid solution is a = 6, b = 7. Indeed, we have s(a) = 6 β‰₯ n and s(b) = 7 β‰₯ n, and also s(a + b) = s(13) = 4 ≀ m.
instruction
0
16,828
20
33,656
Tags: constructive algorithms, math Correct Solution: ``` n, m = map(int, input().split()) l = 1112 arr = "90" * l arr = arr[:-1] + '1' brr = "09" * l brr = brr[1:] print(arr) print(brr) #print(sum([int(el) for el in str(int(arr) + int(brr))])) ```
output
1
16,828
20
33,657
Provide tags and a correct Python 3 solution for this coding contest problem. Let s(x) be sum of digits in decimal representation of positive integer x. Given two integers n and m, find some positive integers a and b such that * s(a) β‰₯ n, * s(b) β‰₯ n, * s(a + b) ≀ m. Input The only line of input contain two integers n and m (1 ≀ n, m ≀ 1129). Output Print two lines, one for decimal representation of a and one for decimal representation of b. Both numbers must not contain leading zeros and must have length no more than 2230. Examples Input 6 5 Output 6 7 Input 8 16 Output 35 53 Note In the first sample, we have n = 6 and m = 5. One valid solution is a = 6, b = 7. Indeed, we have s(a) = 6 β‰₯ n and s(b) = 7 β‰₯ n, and also s(a + b) = s(13) = 4 ≀ m.
instruction
0
16,829
20
33,658
Tags: constructive algorithms, math Correct Solution: ``` n, m = map(int, input().split()) k = n // 9 + 1 a = '9' * k + '0' * (k - 1) + '1' b = '9' * k print(int(a)) print(int(b)) ```
output
1
16,829
20
33,659
Provide tags and a correct Python 3 solution for this coding contest problem. Let s(x) be sum of digits in decimal representation of positive integer x. Given two integers n and m, find some positive integers a and b such that * s(a) β‰₯ n, * s(b) β‰₯ n, * s(a + b) ≀ m. Input The only line of input contain two integers n and m (1 ≀ n, m ≀ 1129). Output Print two lines, one for decimal representation of a and one for decimal representation of b. Both numbers must not contain leading zeros and must have length no more than 2230. Examples Input 6 5 Output 6 7 Input 8 16 Output 35 53 Note In the first sample, we have n = 6 and m = 5. One valid solution is a = 6, b = 7. Indeed, we have s(a) = 6 β‰₯ n and s(b) = 7 β‰₯ n, and also s(a + b) = s(13) = 4 ≀ m.
instruction
0
16,830
20
33,660
Tags: constructive algorithms, math Correct Solution: ``` import math n, m = [int(x) for x in input().split()] num_digits = math.ceil(abs(n - 5) / 4) + 1 a = '5' * num_digits b = ('4' * (num_digits-1)) + '5' print(a) print(b) ```
output
1
16,830
20
33,661
Provide tags and a correct Python 3 solution for this coding contest problem. Let s(x) be sum of digits in decimal representation of positive integer x. Given two integers n and m, find some positive integers a and b such that * s(a) β‰₯ n, * s(b) β‰₯ n, * s(a + b) ≀ m. Input The only line of input contain two integers n and m (1 ≀ n, m ≀ 1129). Output Print two lines, one for decimal representation of a and one for decimal representation of b. Both numbers must not contain leading zeros and must have length no more than 2230. Examples Input 6 5 Output 6 7 Input 8 16 Output 35 53 Note In the first sample, we have n = 6 and m = 5. One valid solution is a = 6, b = 7. Indeed, we have s(a) = 6 β‰₯ n and s(b) = 7 β‰₯ n, and also s(a + b) = s(13) = 4 ≀ m.
instruction
0
16,831
20
33,662
Tags: constructive algorithms, math Correct Solution: ``` print('9'*1000) print('9'*1000+'0'*999+'1') ```
output
1
16,831
20
33,663
Provide tags and a correct Python 3 solution for this coding contest problem. Let s(x) be sum of digits in decimal representation of positive integer x. Given two integers n and m, find some positive integers a and b such that * s(a) β‰₯ n, * s(b) β‰₯ n, * s(a + b) ≀ m. Input The only line of input contain two integers n and m (1 ≀ n, m ≀ 1129). Output Print two lines, one for decimal representation of a and one for decimal representation of b. Both numbers must not contain leading zeros and must have length no more than 2230. Examples Input 6 5 Output 6 7 Input 8 16 Output 35 53 Note In the first sample, we have n = 6 and m = 5. One valid solution is a = 6, b = 7. Indeed, we have s(a) = 6 β‰₯ n and s(b) = 7 β‰₯ n, and also s(a + b) = s(13) = 4 ≀ m.
instruction
0
16,832
20
33,664
Tags: constructive algorithms, math Correct Solution: ``` print("99"*100+"0"*199+"1") print("99"*100) ```
output
1
16,832
20
33,665
Provide tags and a correct Python 3 solution for this coding contest problem. Let s(x) be sum of digits in decimal representation of positive integer x. Given two integers n and m, find some positive integers a and b such that * s(a) β‰₯ n, * s(b) β‰₯ n, * s(a + b) ≀ m. Input The only line of input contain two integers n and m (1 ≀ n, m ≀ 1129). Output Print two lines, one for decimal representation of a and one for decimal representation of b. Both numbers must not contain leading zeros and must have length no more than 2230. Examples Input 6 5 Output 6 7 Input 8 16 Output 35 53 Note In the first sample, we have n = 6 and m = 5. One valid solution is a = 6, b = 7. Indeed, we have s(a) = 6 β‰₯ n and s(b) = 7 β‰₯ n, and also s(a + b) = s(13) = 4 ≀ m.
instruction
0
16,833
20
33,666
Tags: constructive algorithms, math Correct Solution: ``` print("1"*1129+"\n"+"8"*1128+"9") ```
output
1
16,833
20
33,667
Provide tags and a correct Python 3 solution for this coding contest problem. Let s(x) be sum of digits in decimal representation of positive integer x. Given two integers n and m, find some positive integers a and b such that * s(a) β‰₯ n, * s(b) β‰₯ n, * s(a + b) ≀ m. Input The only line of input contain two integers n and m (1 ≀ n, m ≀ 1129). Output Print two lines, one for decimal representation of a and one for decimal representation of b. Both numbers must not contain leading zeros and must have length no more than 2230. Examples Input 6 5 Output 6 7 Input 8 16 Output 35 53 Note In the first sample, we have n = 6 and m = 5. One valid solution is a = 6, b = 7. Indeed, we have s(a) = 6 β‰₯ n and s(b) = 7 β‰₯ n, and also s(a + b) = s(13) = 4 ≀ m.
instruction
0
16,834
20
33,668
Tags: constructive algorithms, math Correct Solution: ``` n, m = [int(x) for x in input().split()] x=n-1;s=0; while x>=0 : s+=pow(10,x) x-=1 print(s) print(pow(10,n)-s) ```
output
1
16,834
20
33,669
Provide tags and a correct Python 3 solution for this coding contest problem. Let s(x) be sum of digits in decimal representation of positive integer x. Given two integers n and m, find some positive integers a and b such that * s(a) β‰₯ n, * s(b) β‰₯ n, * s(a + b) ≀ m. Input The only line of input contain two integers n and m (1 ≀ n, m ≀ 1129). Output Print two lines, one for decimal representation of a and one for decimal representation of b. Both numbers must not contain leading zeros and must have length no more than 2230. Examples Input 6 5 Output 6 7 Input 8 16 Output 35 53 Note In the first sample, we have n = 6 and m = 5. One valid solution is a = 6, b = 7. Indeed, we have s(a) = 6 β‰₯ n and s(b) = 7 β‰₯ n, and also s(a + b) = s(13) = 4 ≀ m.
instruction
0
16,835
20
33,670
Tags: constructive algorithms, math Correct Solution: ``` a = 454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454546 b = 545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454 print(a) print(b) ```
output
1
16,835
20
33,671
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let s(x) be sum of digits in decimal representation of positive integer x. Given two integers n and m, find some positive integers a and b such that * s(a) β‰₯ n, * s(b) β‰₯ n, * s(a + b) ≀ m. Input The only line of input contain two integers n and m (1 ≀ n, m ≀ 1129). Output Print two lines, one for decimal representation of a and one for decimal representation of b. Both numbers must not contain leading zeros and must have length no more than 2230. Examples Input 6 5 Output 6 7 Input 8 16 Output 35 53 Note In the first sample, we have n = 6 and m = 5. One valid solution is a = 6, b = 7. Indeed, we have s(a) = 6 β‰₯ n and s(b) = 7 β‰₯ n, and also s(a + b) = s(13) = 4 ≀ m. Submitted Solution: ``` def s(x): cnt = 0 tmp = list(str(x)) for i in tmp: cnt += int(i) return cnt n, m = input().split() n = int(n) m = int(m) for i in range(1, 10): tmp = 10 ** 2229 left = tmp // i right = tmp - left if s(left) >= n and s(right) >= m: print(left) print(right) break ```
instruction
0
16,836
20
33,672
Yes
output
1
16,836
20
33,673
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let s(x) be sum of digits in decimal representation of positive integer x. Given two integers n and m, find some positive integers a and b such that * s(a) β‰₯ n, * s(b) β‰₯ n, * s(a + b) ≀ m. Input The only line of input contain two integers n and m (1 ≀ n, m ≀ 1129). Output Print two lines, one for decimal representation of a and one for decimal representation of b. Both numbers must not contain leading zeros and must have length no more than 2230. Examples Input 6 5 Output 6 7 Input 8 16 Output 35 53 Note In the first sample, we have n = 6 and m = 5. One valid solution is a = 6, b = 7. Indeed, we have s(a) = 6 β‰₯ n and s(b) = 7 β‰₯ n, and also s(a + b) = s(13) = 4 ≀ m. Submitted Solution: ``` # import sys # sys.stdin = open("F:\\Scripts\\input","r") # sys.stdout = open("F:\\Scripts\\output","w") MOD = 10**9 + 7 I = lambda:list(map(int,input().split())) n , m = I() k = n//8 ss = '1'*n s = '8'*(n - 1)+'9' print(s,ss,sep='\n') # from collections import Counter as C # n , = I() # l = I() # d = {} # for i in range(n): # d[l[i]] = i + 1 ```
instruction
0
16,837
20
33,674
Yes
output
1
16,837
20
33,675
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let s(x) be sum of digits in decimal representation of positive integer x. Given two integers n and m, find some positive integers a and b such that * s(a) β‰₯ n, * s(b) β‰₯ n, * s(a + b) ≀ m. Input The only line of input contain two integers n and m (1 ≀ n, m ≀ 1129). Output Print two lines, one for decimal representation of a and one for decimal representation of b. Both numbers must not contain leading zeros and must have length no more than 2230. Examples Input 6 5 Output 6 7 Input 8 16 Output 35 53 Note In the first sample, we have n = 6 and m = 5. One valid solution is a = 6, b = 7. Indeed, we have s(a) = 6 β‰₯ n and s(b) = 7 β‰₯ n, and also s(a + b) = s(13) = 4 ≀ m. Submitted Solution: ``` input() s = '45' * 126 print(s, '\n', s[1:], 5, sep='') ```
instruction
0
16,839
20
33,678
Yes
output
1
16,839
20
33,679
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let s(x) be sum of digits in decimal representation of positive integer x. Given two integers n and m, find some positive integers a and b such that * s(a) β‰₯ n, * s(b) β‰₯ n, * s(a + b) ≀ m. Input The only line of input contain two integers n and m (1 ≀ n, m ≀ 1129). Output Print two lines, one for decimal representation of a and one for decimal representation of b. Both numbers must not contain leading zeros and must have length no more than 2230. Examples Input 6 5 Output 6 7 Input 8 16 Output 35 53 Note In the first sample, we have n = 6 and m = 5. One valid solution is a = 6, b = 7. Indeed, we have s(a) = 6 β‰₯ n and s(b) = 7 β‰₯ n, and also s(a + b) = s(13) = 4 ≀ m. Submitted Solution: ``` n,m = map(str,input().split()) sum = 0 for i in n: sum = sum + int(i) print(sum) print(sum) ```
instruction
0
16,840
20
33,680
No
output
1
16,840
20
33,681
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let s(x) be sum of digits in decimal representation of positive integer x. Given two integers n and m, find some positive integers a and b such that * s(a) β‰₯ n, * s(b) β‰₯ n, * s(a + b) ≀ m. Input The only line of input contain two integers n and m (1 ≀ n, m ≀ 1129). Output Print two lines, one for decimal representation of a and one for decimal representation of b. Both numbers must not contain leading zeros and must have length no more than 2230. Examples Input 6 5 Output 6 7 Input 8 16 Output 35 53 Note In the first sample, we have n = 6 and m = 5. One valid solution is a = 6, b = 7. Indeed, we have s(a) = 6 β‰₯ n and s(b) = 7 β‰₯ n, and also s(a + b) = s(13) = 4 ≀ m. Submitted Solution: ``` n, m = map(int, input().split()) a = [] b = [] sa = 0 sb = 0 while sa < n: a += ['9'] sa += 9 c = len(a) while sb < n: if c > 0: b += ['1'] sb += 1 c -= 1 else: b += ['9'] sb += 9 print(''.join(a)) print(''.join(reversed(b))) ```
instruction
0
16,841
20
33,682
No
output
1
16,841
20
33,683
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer x. Can you make x by summing up some number of 11, 111, 1111, 11111, …? (You can use any number among them any number of times). For instance, * 33=11+11+11 * 144=111+11+11+11 Input The first line of input contains a single integer t (1 ≀ t ≀ 10000) β€” the number of testcases. The first and only line of each testcase contains a single integer x (1 ≀ x ≀ 10^9) β€” the number you have to make. Output For each testcase, you should output a single string. If you can make x, output "YES" (without quotes). Otherwise, output "NO". You can print each letter of "YES" and "NO" in any case (upper or lower). Example Input 3 33 144 69 Output YES YES NO Note Ways to make 33 and 144 were presented in the statement. It can be proved that we can't present 69 this way.
instruction
0
17,030
20
34,060
Tags: dp, math, number theory Correct Solution: ``` import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) for i in range(11): if n >= i * 111 and (n - i * 111) % 11 == 0: print("YES") break else: print("NO") ```
output
1
17,030
20
34,061
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer x. Can you make x by summing up some number of 11, 111, 1111, 11111, …? (You can use any number among them any number of times). For instance, * 33=11+11+11 * 144=111+11+11+11 Input The first line of input contains a single integer t (1 ≀ t ≀ 10000) β€” the number of testcases. The first and only line of each testcase contains a single integer x (1 ≀ x ≀ 10^9) β€” the number you have to make. Output For each testcase, you should output a single string. If you can make x, output "YES" (without quotes). Otherwise, output "NO". You can print each letter of "YES" and "NO" in any case (upper or lower). Example Input 3 33 144 69 Output YES YES NO Note Ways to make 33 and 144 were presented in the statement. It can be proved that we can't present 69 this way.
instruction
0
17,031
20
34,062
Tags: dp, math, number theory Correct Solution: ``` t=int(input()) for _ in range(t): n=int(input()) b=n%11 a=((n-b)//11)-(10*b) print('YES') if(a>=0) else print('NO') ```
output
1
17,031
20
34,063
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer x. Can you make x by summing up some number of 11, 111, 1111, 11111, …? (You can use any number among them any number of times). For instance, * 33=11+11+11 * 144=111+11+11+11 Input The first line of input contains a single integer t (1 ≀ t ≀ 10000) β€” the number of testcases. The first and only line of each testcase contains a single integer x (1 ≀ x ≀ 10^9) β€” the number you have to make. Output For each testcase, you should output a single string. If you can make x, output "YES" (without quotes). Otherwise, output "NO". You can print each letter of "YES" and "NO" in any case (upper or lower). Example Input 3 33 144 69 Output YES YES NO Note Ways to make 33 and 144 were presented in the statement. It can be proved that we can't present 69 this way.
instruction
0
17,032
20
34,064
Tags: dp, math, number theory Correct Solution: ``` t=int(input()) for i in range(t): x=input() n='' for j in range(len(x)): n+='1' n=int(n) check=False while n!=1 and check==False: k=int(x) c=int(n) while c!=1: k=k%c c-=1 c/=10 if k==0: check=True else: n-=1 n/=10 if check==False: x=int(x) a=111 while a<x: c=x-a if c%11 == 0: print('yes') break else: a+=111 if a>x: print('no') else: print('yes') ```
output
1
17,032
20
34,065
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer x. Can you make x by summing up some number of 11, 111, 1111, 11111, …? (You can use any number among them any number of times). For instance, * 33=11+11+11 * 144=111+11+11+11 Input The first line of input contains a single integer t (1 ≀ t ≀ 10000) β€” the number of testcases. The first and only line of each testcase contains a single integer x (1 ≀ x ≀ 10^9) β€” the number you have to make. Output For each testcase, you should output a single string. If you can make x, output "YES" (without quotes). Otherwise, output "NO". You can print each letter of "YES" and "NO" in any case (upper or lower). Example Input 3 33 144 69 Output YES YES NO Note Ways to make 33 and 144 were presented in the statement. It can be proved that we can't present 69 this way.
instruction
0
17,033
20
34,066
Tags: dp, math, number theory Correct Solution: ``` n=int(input()) while(n>0): z=int(input()) b=False for i in range(12): if(z<(111*i)): break if(((z-(111*i))%11)==0): print("YES") b=True break if(b==False): print("NO") n-=1 ```
output
1
17,033
20
34,067
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer x. Can you make x by summing up some number of 11, 111, 1111, 11111, …? (You can use any number among them any number of times). For instance, * 33=11+11+11 * 144=111+11+11+11 Input The first line of input contains a single integer t (1 ≀ t ≀ 10000) β€” the number of testcases. The first and only line of each testcase contains a single integer x (1 ≀ x ≀ 10^9) β€” the number you have to make. Output For each testcase, you should output a single string. If you can make x, output "YES" (without quotes). Otherwise, output "NO". You can print each letter of "YES" and "NO" in any case (upper or lower). Example Input 3 33 144 69 Output YES YES NO Note Ways to make 33 and 144 were presented in the statement. It can be proved that we can't present 69 this way.
instruction
0
17,034
20
34,068
Tags: dp, math, number theory Correct Solution: ``` for _ in range(int(input())): x = int(input()) a = x // 11 b = 10 * (x % 11) if a >= b: print("YES") else: print("NO") ```
output
1
17,034
20
34,069
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer x. Can you make x by summing up some number of 11, 111, 1111, 11111, …? (You can use any number among them any number of times). For instance, * 33=11+11+11 * 144=111+11+11+11 Input The first line of input contains a single integer t (1 ≀ t ≀ 10000) β€” the number of testcases. The first and only line of each testcase contains a single integer x (1 ≀ x ≀ 10^9) β€” the number you have to make. Output For each testcase, you should output a single string. If you can make x, output "YES" (without quotes). Otherwise, output "NO". You can print each letter of "YES" and "NO" in any case (upper or lower). Example Input 3 33 144 69 Output YES YES NO Note Ways to make 33 and 144 were presented in the statement. It can be proved that we can't present 69 this way.
instruction
0
17,035
20
34,070
Tags: dp, math, number theory Correct Solution: ``` for _ in range(int(input())): n=int(input()) if (111*(n%11) >n):print('NO') else:print('YES') ```
output
1
17,035
20
34,071
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer x. Can you make x by summing up some number of 11, 111, 1111, 11111, …? (You can use any number among them any number of times). For instance, * 33=11+11+11 * 144=111+11+11+11 Input The first line of input contains a single integer t (1 ≀ t ≀ 10000) β€” the number of testcases. The first and only line of each testcase contains a single integer x (1 ≀ x ≀ 10^9) β€” the number you have to make. Output For each testcase, you should output a single string. If you can make x, output "YES" (without quotes). Otherwise, output "NO". You can print each letter of "YES" and "NO" in any case (upper or lower). Example Input 3 33 144 69 Output YES YES NO Note Ways to make 33 and 144 were presented in the statement. It can be proved that we can't present 69 this way.
instruction
0
17,036
20
34,072
Tags: dp, math, number theory Correct Solution: ``` for i in range(int(input())): x = int(input()) ans = 0 while x > 0: if x % 11 == 0 or x % 111 == 0: ans = 1 break x -= 111 if ans: print('YES') else: print('NO') ```
output
1
17,036
20
34,073
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer x. Can you make x by summing up some number of 11, 111, 1111, 11111, …? (You can use any number among them any number of times). For instance, * 33=11+11+11 * 144=111+11+11+11 Input The first line of input contains a single integer t (1 ≀ t ≀ 10000) β€” the number of testcases. The first and only line of each testcase contains a single integer x (1 ≀ x ≀ 10^9) β€” the number you have to make. Output For each testcase, you should output a single string. If you can make x, output "YES" (without quotes). Otherwise, output "NO". You can print each letter of "YES" and "NO" in any case (upper or lower). Example Input 3 33 144 69 Output YES YES NO Note Ways to make 33 and 144 were presented in the statement. It can be proved that we can't present 69 this way.
instruction
0
17,037
20
34,074
Tags: dp, math, number theory Correct Solution: ``` for i in range(int(input())): x=int(input()) rem=(x-(x%11)*111) if rem>=0 and rem%11==0: print("YES") else: print("NO") ```
output
1
17,037
20
34,075
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an integer x. Can you make x by summing up some number of 11, 111, 1111, 11111, …? (You can use any number among them any number of times). For instance, * 33=11+11+11 * 144=111+11+11+11 Input The first line of input contains a single integer t (1 ≀ t ≀ 10000) β€” the number of testcases. The first and only line of each testcase contains a single integer x (1 ≀ x ≀ 10^9) β€” the number you have to make. Output For each testcase, you should output a single string. If you can make x, output "YES" (without quotes). Otherwise, output "NO". You can print each letter of "YES" and "NO" in any case (upper or lower). Example Input 3 33 144 69 Output YES YES NO Note Ways to make 33 and 144 were presented in the statement. It can be proved that we can't present 69 this way. Submitted Solution: ``` t=int(input()) import math def main(n,a,b,c,d): if n%a==0 or n%b==0 or n%c==0 or n%d==0: return 1 if n>=d: if n%d==0: return 1 for i in range(1,math.ceil(n/d)): if main(n-d*i,a,b,c,d): return 1 if n>=c: if n%c==0: return 1 for i in range(1,math.ceil(n/c)): if main(n-c*i,a,b,c,d): return 1 if n>=b: if n%b==0: return 1 for i in range(1,math.ceil(n/b)): if main(n-b*i,a,b,c,d): return 1 if n>=a: if n%a==0: return 1 else: return 0 return 0 for _ in range(t): n=int(input()) a=11 b=111 c=11111 d=1111111 if main(n,a,b,c,d): print("YES") else: print("NO") ```
instruction
0
17,040
20
34,080
Yes
output
1
17,040
20
34,081
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an integer x. Can you make x by summing up some number of 11, 111, 1111, 11111, …? (You can use any number among them any number of times). For instance, * 33=11+11+11 * 144=111+11+11+11 Input The first line of input contains a single integer t (1 ≀ t ≀ 10000) β€” the number of testcases. The first and only line of each testcase contains a single integer x (1 ≀ x ≀ 10^9) β€” the number you have to make. Output For each testcase, you should output a single string. If you can make x, output "YES" (without quotes). Otherwise, output "NO". You can print each letter of "YES" and "NO" in any case (upper or lower). Example Input 3 33 144 69 Output YES YES NO Note Ways to make 33 and 144 were presented in the statement. It can be proved that we can't present 69 this way. Submitted Solution: ``` import math def f(): n = int(input()) if n < 11: return 'NO' u = n%10 d = int(n/10)%10 if u > d: return 'NO' dif = d - u if (2+dif)*11 > n: return 'NO' return 'YES' t = int(input()) for _ in range(t): print(f()) ```
instruction
0
17,044
20
34,088
No
output
1
17,044
20
34,089
Provide tags and a correct Python 3 solution for this coding contest problem. Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment. Find all integer solutions x (0 < x < 109) of the equation: x = bΒ·s(x)a + c, where a, b, c are some predetermined constant values and function s(x) determines the sum of all digits in the decimal representation of number x. The teacher gives this problem to Dima for each lesson. He changes only the parameters of the equation: a, b, c. Dima got sick of getting bad marks and he asks you to help him solve this challenging problem. Input The first line contains three space-separated integers: a, b, c (1 ≀ a ≀ 5; 1 ≀ b ≀ 10000; - 10000 ≀ c ≀ 10000). Output Print integer n β€” the number of the solutions that you've found. Next print n integers in the increasing order β€” the solutions of the given equation. Print only integer solutions that are larger than zero and strictly less than 109. Examples Input 3 2 8 Output 3 10 2008 13726 Input 1 2 -18 Output 0 Input 2 2 -1 Output 4 1 31 337 967
instruction
0
17,173
20
34,346
Tags: brute force, implementation, math, number theory Correct Solution: ``` a,b,c=map(int,input().split());l=[] for i in range(1,82): x=b*i**a+c if x>0 and x<10**9: if sum(int(i) for i in str(x))==i:l.append(x) print(len(l)) if l: print(*l) ```
output
1
17,173
20
34,347
Provide tags and a correct Python 3 solution for this coding contest problem. Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment. Find all integer solutions x (0 < x < 109) of the equation: x = bΒ·s(x)a + c, where a, b, c are some predetermined constant values and function s(x) determines the sum of all digits in the decimal representation of number x. The teacher gives this problem to Dima for each lesson. He changes only the parameters of the equation: a, b, c. Dima got sick of getting bad marks and he asks you to help him solve this challenging problem. Input The first line contains three space-separated integers: a, b, c (1 ≀ a ≀ 5; 1 ≀ b ≀ 10000; - 10000 ≀ c ≀ 10000). Output Print integer n β€” the number of the solutions that you've found. Next print n integers in the increasing order β€” the solutions of the given equation. Print only integer solutions that are larger than zero and strictly less than 109. Examples Input 3 2 8 Output 3 10 2008 13726 Input 1 2 -18 Output 0 Input 2 2 -1 Output 4 1 31 337 967
instruction
0
17,174
20
34,348
Tags: brute force, implementation, math, number theory Correct Solution: ``` a,b,c=input().split() a=int(a);b=int(b);c=int(c) def fun(xx): return b*(xx**a)+c lis=[] for i in range(1,100): k = fun(i) if k > 0: lis.append(k) ans =[] mx=10**9 for i in range(len(lis)): k = sum([int(d) for d in str(lis[i])]) chk = (lis[i] == fun(k)) if lis[i] < mx and chk and lis[i]>0: ans.append(lis[i]) op="" for i in range(len(ans)): op += (str(ans[i]) + " ") print(len(ans)) if (len(op) > 0): print(op) ```
output
1
17,174
20
34,349
Provide tags and a correct Python 3 solution for this coding contest problem. Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment. Find all integer solutions x (0 < x < 109) of the equation: x = bΒ·s(x)a + c, where a, b, c are some predetermined constant values and function s(x) determines the sum of all digits in the decimal representation of number x. The teacher gives this problem to Dima for each lesson. He changes only the parameters of the equation: a, b, c. Dima got sick of getting bad marks and he asks you to help him solve this challenging problem. Input The first line contains three space-separated integers: a, b, c (1 ≀ a ≀ 5; 1 ≀ b ≀ 10000; - 10000 ≀ c ≀ 10000). Output Print integer n β€” the number of the solutions that you've found. Next print n integers in the increasing order β€” the solutions of the given equation. Print only integer solutions that are larger than zero and strictly less than 109. Examples Input 3 2 8 Output 3 10 2008 13726 Input 1 2 -18 Output 0 Input 2 2 -1 Output 4 1 31 337 967
instruction
0
17,175
20
34,350
Tags: brute force, implementation, math, number theory Correct Solution: ``` a, b, c = list(map(int, input().split())) ans = [] for i in range(83): x = b * (i ** a) + c if x <= 0 or x > 10 ** 9: continue sum_of_x = sum([int(x) for x in str(x)]) if sum_of_x == i: ans.append(x) print(len(ans)) if len(ans): print(*ans) ```
output
1
17,175
20
34,351
Provide tags and a correct Python 3 solution for this coding contest problem. Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment. Find all integer solutions x (0 < x < 109) of the equation: x = bΒ·s(x)a + c, where a, b, c are some predetermined constant values and function s(x) determines the sum of all digits in the decimal representation of number x. The teacher gives this problem to Dima for each lesson. He changes only the parameters of the equation: a, b, c. Dima got sick of getting bad marks and he asks you to help him solve this challenging problem. Input The first line contains three space-separated integers: a, b, c (1 ≀ a ≀ 5; 1 ≀ b ≀ 10000; - 10000 ≀ c ≀ 10000). Output Print integer n β€” the number of the solutions that you've found. Next print n integers in the increasing order β€” the solutions of the given equation. Print only integer solutions that are larger than zero and strictly less than 109. Examples Input 3 2 8 Output 3 10 2008 13726 Input 1 2 -18 Output 0 Input 2 2 -1 Output 4 1 31 337 967
instruction
0
17,176
20
34,352
Tags: brute force, implementation, math, number theory Correct Solution: ``` #460B def summ(n): a = list(map(int, str(n))) return sum(a) inpt = list(map(int, input().split(" "))) a = inpt[0] b = inpt[1] c = inpt[2] arr = [] count = 0 for i in range(1, 82): num = b * (i ** a) + c if num > 0 and num <= 1000000000 and summ(num) == i: count += 1 arr.append(num) arr = sorted(arr) print(count) for i in arr: print(i, end = " ") ```
output
1
17,176
20
34,353
Provide tags and a correct Python 3 solution for this coding contest problem. Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment. Find all integer solutions x (0 < x < 109) of the equation: x = bΒ·s(x)a + c, where a, b, c are some predetermined constant values and function s(x) determines the sum of all digits in the decimal representation of number x. The teacher gives this problem to Dima for each lesson. He changes only the parameters of the equation: a, b, c. Dima got sick of getting bad marks and he asks you to help him solve this challenging problem. Input The first line contains three space-separated integers: a, b, c (1 ≀ a ≀ 5; 1 ≀ b ≀ 10000; - 10000 ≀ c ≀ 10000). Output Print integer n β€” the number of the solutions that you've found. Next print n integers in the increasing order β€” the solutions of the given equation. Print only integer solutions that are larger than zero and strictly less than 109. Examples Input 3 2 8 Output 3 10 2008 13726 Input 1 2 -18 Output 0 Input 2 2 -1 Output 4 1 31 337 967
instruction
0
17,177
20
34,354
Tags: brute force, implementation, math, number theory Correct Solution: ``` a, b, c = (int(i) for i in input().split(" ")) import sys # print(a, b, c) def calculate(a, b, c, s): # print("in calc", a,b,c,s) return b * (s ** a) + c def dig_sum(x): # print(x) line = str(x).strip("-") sum = 0 for i in list(line): sum += int(i) return sum res = [] for i in range(1, 82): x = calculate(a, b, c, i) # print(x, dig_sum(x)) if dig_sum(x) == i: res.append(x) res.sort() res = [str(i) for i in res if i >= 0 and i < 1000000000] print(len(res)) print(" ".join(res)) sys.exit(0) ```
output
1
17,177
20
34,355
Provide tags and a correct Python 3 solution for this coding contest problem. Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment. Find all integer solutions x (0 < x < 109) of the equation: x = bΒ·s(x)a + c, where a, b, c are some predetermined constant values and function s(x) determines the sum of all digits in the decimal representation of number x. The teacher gives this problem to Dima for each lesson. He changes only the parameters of the equation: a, b, c. Dima got sick of getting bad marks and he asks you to help him solve this challenging problem. Input The first line contains three space-separated integers: a, b, c (1 ≀ a ≀ 5; 1 ≀ b ≀ 10000; - 10000 ≀ c ≀ 10000). Output Print integer n β€” the number of the solutions that you've found. Next print n integers in the increasing order β€” the solutions of the given equation. Print only integer solutions that are larger than zero and strictly less than 109. Examples Input 3 2 8 Output 3 10 2008 13726 Input 1 2 -18 Output 0 Input 2 2 -1 Output 4 1 31 337 967
instruction
0
17,178
20
34,356
Tags: brute force, implementation, math, number theory Correct Solution: ``` def find_digit_sum(x): """Find sum of digits of x""" s = 0 while x > 0: s += x%10 x //= 10 return s def exponent_mod(n, p, prime_const=1000000000+7): """Find (n^p) % prime_const""" res=1 if n == 0: return 0; while p > 0: if p%2 == 1: res = (res * n) % prime_const p //= 2 n = (n*n) % prime_const # print (str(p) + " / " + str(res) + " / " + str(n)) return res def find_solutions(a, b, c): """Find solutions of equation x = b*(digit_sum(x)**a) + c""" solutions = [] for j in range(1, 82): x = b*(j**a) + c if j == find_digit_sum(x) and x < pow(10, 9): solutions.append(x) return solutions t = 1 while t: t -= 1 prime_const = pow(10,9)+7; values = list(map(int, input().strip().split()))[:3] a = values[0] b = values[1] c = values[2] solutions = find_solutions(a, b, c) print(len(solutions)) print(" ".join(str(x) for x in solutions)) ```
output
1
17,178
20
34,357
Provide tags and a correct Python 3 solution for this coding contest problem. Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment. Find all integer solutions x (0 < x < 109) of the equation: x = bΒ·s(x)a + c, where a, b, c are some predetermined constant values and function s(x) determines the sum of all digits in the decimal representation of number x. The teacher gives this problem to Dima for each lesson. He changes only the parameters of the equation: a, b, c. Dima got sick of getting bad marks and he asks you to help him solve this challenging problem. Input The first line contains three space-separated integers: a, b, c (1 ≀ a ≀ 5; 1 ≀ b ≀ 10000; - 10000 ≀ c ≀ 10000). Output Print integer n β€” the number of the solutions that you've found. Next print n integers in the increasing order β€” the solutions of the given equation. Print only integer solutions that are larger than zero and strictly less than 109. Examples Input 3 2 8 Output 3 10 2008 13726 Input 1 2 -18 Output 0 Input 2 2 -1 Output 4 1 31 337 967
instruction
0
17,179
20
34,358
Tags: brute force, implementation, math, number theory Correct Solution: ``` a,b,c=map(int,input().split()) A=[] for i in range(1,82): A.append(i**a) B=[] for i in A: y=b*i+c if y>0 and sum(list(map(int,list(str(y)))))**a==i and y<10**9: B.append(y) print(len(B)) for i in B: print(i,end=' ') ```
output
1
17,179
20
34,359
Provide tags and a correct Python 3 solution for this coding contest problem. Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment. Find all integer solutions x (0 < x < 109) of the equation: x = bΒ·s(x)a + c, where a, b, c are some predetermined constant values and function s(x) determines the sum of all digits in the decimal representation of number x. The teacher gives this problem to Dima for each lesson. He changes only the parameters of the equation: a, b, c. Dima got sick of getting bad marks and he asks you to help him solve this challenging problem. Input The first line contains three space-separated integers: a, b, c (1 ≀ a ≀ 5; 1 ≀ b ≀ 10000; - 10000 ≀ c ≀ 10000). Output Print integer n β€” the number of the solutions that you've found. Next print n integers in the increasing order β€” the solutions of the given equation. Print only integer solutions that are larger than zero and strictly less than 109. Examples Input 3 2 8 Output 3 10 2008 13726 Input 1 2 -18 Output 0 Input 2 2 -1 Output 4 1 31 337 967
instruction
0
17,180
20
34,360
Tags: brute force, implementation, math, number theory Correct Solution: ``` a, b, c = map(int, input().split()) ans = [] for i in range(1,82): p = i**a*b+c if p >= 0 and sum(list(map(int, list(str(p))))) == i and p <= 10**9: ans.append(p) print(len(ans)) print(*ans) ```
output
1
17,180
20
34,361
Provide tags and a correct Python 3 solution for this coding contest problem. Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x. You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≀ x ≀ r, and <image> is maximum possible. If there are multiple such numbers find the smallest of them. Input The first line contains integer n β€” the number of queries (1 ≀ n ≀ 10000). Each of the following n lines contain two integers li, ri β€” the arguments for the corresponding query (0 ≀ li ≀ ri ≀ 1018). Output For each query print the answer in a separate line. Examples Input 3 1 2 2 4 1 10 Output 1 3 7 Note The binary representations of numbers from 1 to 10 are listed below: 110 = 12 210 = 102 310 = 112 410 = 1002 510 = 1012 610 = 1102 710 = 1112 810 = 10002 910 = 10012 1010 = 10102
instruction
0
17,189
20
34,378
Tags: bitmasks, constructive algorithms Correct Solution: ``` def fun(x,y): if x==y: return x if (y&(y+1)) == 0: return y [a,b] = [len(bin(x))-3,len(bin(y))-3] if a==b: return (1<<a)| fun((1<<a)^x, (1<<a)^y) return (1<<b) - 1 def main(): mode="filee" if mode=="file":f=open("test.txt","r") get = lambda :[int(x) for x in (f.readline() if mode=="file" else input()).split()] [n]=get() for z in range(n): [x,y]=get() print(fun(x,y)) if mode=="file":f.close() if __name__=="__main__": main() ```
output
1
17,189
20
34,379