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
Provide tags and a correct Python 3 solution for this coding contest problem. Let's call some positive integer classy if its decimal representation contains no more than 3 non-zero digits. For example, numbers 4, 200000, 10203 are classy and numbers 4231, 102306, 7277420000 are not. You are given a segment [L; R]. Count the number of classy integers x such that L ≤ x ≤ R. Each testcase contains several segments, for each of them you are required to solve the problem separately. Input The first line contains a single integer T (1 ≤ T ≤ 10^4) — the number of segments in a testcase. Each of the next T lines contains two integers L_i and R_i (1 ≤ L_i ≤ R_i ≤ 10^{18}). Output Print T lines — the i-th line should contain the number of classy integers on a segment [L_i; R_i]. Example Input 4 1 1000 1024 1024 65536 65536 999999 1000001 Output 1000 1 0 2
instruction
0
36,003
20
72,006
Tags: combinatorics, dp Correct Solution: ``` import sys from sys import stdin,stdout def ncr(n,r): if n<r or r<0 or n<0: return 0 if n-r<r: r=n-r arr=[0 for i in range(r+1)] arr[0]=1 for i in range(n+1): for j in range(min(i,r),0,-1): arr[j]=arr[j]+arr[j-1] return arr[r] ##print(ncr(10,5)) def getclassy(s): #print("\t\t",s) ans=0;nzd=0 for i in range(len(s)): if s[i]=='0': continue #ASSUMING ZERO DIGIT #print([ncr(len(s)-i-1,j)*9**j for j in range(3-nzd+1)]) ans+=(sum([ncr(len(s)-i-1,j)*9**j for j in range(3-nzd+1)]));nzd+=1 if nzd==4: break; ans+=(sum([ncr(len(s)-i-1,j)*9**j for j in range(3-nzd+1)]))*(int(s[i])-1) #print(ans,"ANS",i) return ans t=int(stdin.readline()) for _ in range(t): l,r=map(int,stdin.readline().split(' '));r+=1;l=list(str(l));r=list(str(r)) stdout.write(str(getclassy(r)-getclassy(l))+"\n") ```
output
1
36,003
20
72,007
Provide tags and a correct Python 3 solution for this coding contest problem. Let's call some positive integer classy if its decimal representation contains no more than 3 non-zero digits. For example, numbers 4, 200000, 10203 are classy and numbers 4231, 102306, 7277420000 are not. You are given a segment [L; R]. Count the number of classy integers x such that L ≤ x ≤ R. Each testcase contains several segments, for each of them you are required to solve the problem separately. Input The first line contains a single integer T (1 ≤ T ≤ 10^4) — the number of segments in a testcase. Each of the next T lines contains two integers L_i and R_i (1 ≤ L_i ≤ R_i ≤ 10^{18}). Output Print T lines — the i-th line should contain the number of classy integers on a segment [L_i; R_i]. Example Input 4 1 1000 1024 1024 65536 65536 999999 1000001 Output 1000 1 0 2
instruction
0
36,004
20
72,008
Tags: combinatorics, dp Correct Solution: ``` from sys import stdin from bisect import bisect_left as bl c=[] def gen(n,nz): if len(n)>=19: return global c c.append(int(n)) if nz==3: n+="0" gen(n,nz) return gen(n+"0",nz) for i in ("123456789"): gen(n+i,nz+1) for i in ("123456789"): gen(i,1) c.append(10**18) c.sort() n=int(input()) for i in range(n): a,b=map(int,stdin.readline().strip().split()) x=min(bl(c,b),len(c)-1) y=bl(c,a) if x==y and b<c[x]: print(0) elif (c[x]==b and c[y]==a) or c[x]==b: print(x-y+1) else: print(x-y) ```
output
1
36,004
20
72,009
Provide tags and a correct Python 3 solution for this coding contest problem. Let's call some positive integer classy if its decimal representation contains no more than 3 non-zero digits. For example, numbers 4, 200000, 10203 are classy and numbers 4231, 102306, 7277420000 are not. You are given a segment [L; R]. Count the number of classy integers x such that L ≤ x ≤ R. Each testcase contains several segments, for each of them you are required to solve the problem separately. Input The first line contains a single integer T (1 ≤ T ≤ 10^4) — the number of segments in a testcase. Each of the next T lines contains two integers L_i and R_i (1 ≤ L_i ≤ R_i ≤ 10^{18}). Output Print T lines — the i-th line should contain the number of classy integers on a segment [L_i; R_i]. Example Input 4 1 1000 1024 1024 65536 65536 999999 1000001 Output 1000 1 0 2
instruction
0
36,005
20
72,010
Tags: combinatorics, dp Correct Solution: ``` def f(n): if n == 0: return 1 dp = [[[0] * 2 for j in range(4)] for z in range(len(n))] dp[0][3][0] = 1 dp[0][2][0] = int(n[0]) - 1 dp[0][2][1] = 1 for i in range(1, len(n)): for j in range(4): if n[i] == '0': dp[i][j][0] += dp[i - 1][j][0] dp[i][j][1] += dp[i - 1][j][1] else: dp[i][j][0] += dp[i - 1][j][0] + dp[i - 1][j][1] if j >= 3: continue for z in range(1, 10): if z < int(n[i]): dp[i][j][0] += dp[i - 1][j + 1][0] + dp[i - 1][j + 1][1] elif z == int(n[i]): dp[i][j][0] += dp[i - 1][j + 1][0] dp[i][j][1] += dp[i - 1][j + 1][1] else: dp[i][j][0] += dp[i - 1][j + 1][0] res = 0 for j in range(4): res += dp[len(n) - 1][j][0] + dp[len(n) - 1][j][1] return res t = int(input()) while t: t -= 1 l, r = map(int, input().split()) print(f(str(r)) - f(str(l - 1))) ```
output
1
36,005
20
72,011
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's call some positive integer classy if its decimal representation contains no more than 3 non-zero digits. For example, numbers 4, 200000, 10203 are classy and numbers 4231, 102306, 7277420000 are not. You are given a segment [L; R]. Count the number of classy integers x such that L ≤ x ≤ R. Each testcase contains several segments, for each of them you are required to solve the problem separately. Input The first line contains a single integer T (1 ≤ T ≤ 10^4) — the number of segments in a testcase. Each of the next T lines contains two integers L_i and R_i (1 ≤ L_i ≤ R_i ≤ 10^{18}). Output Print T lines — the i-th line should contain the number of classy integers on a segment [L_i; R_i]. Example Input 4 1 1000 1024 1024 65536 65536 999999 1000001 Output 1000 1 0 2 Submitted Solution: ``` from sys import stdin, stdout pw = [1, 9, 81, 729] C = [[0 for _ in range(20)] for _ in range(20)] def Cn_k(n: int, k: int): if k < 0 or k > n: return 0 return C[n][k] def get(n: int, lft: int): total = 0 for i in range(lft + 1): total += Cn_k(n, i) * pw[i] return total def calc(x: int): sx = str(x) ans = 0 cur = 3 n = len(sx) for i in range(n): if sx[i] == '0': continue ans += get(n - i - 1, cur) cur -= 1 if cur == -1: break ans += get(n - i - 1, cur) * (int(sx[i]) - 1) return ans if __name__ == "__main__": for i in range(20): C[i][0] = C[i][i] = 1 for j in range(1, i): C[i][j] = C[i - 1][j] + C[i - 1][j - 1] to_int = lambda x : int(x) T = list(map(to_int,stdin.readline().split()))[0] intervals = [list(map(to_int,stdin.readline().split())) for i in range(T)] res = [calc(intervals[i][1] + 1) - calc(intervals[i][0]) for i in range(T)] for i in range(T): stdout.write("{}\n".format(res[i])) ```
instruction
0
36,006
20
72,012
Yes
output
1
36,006
20
72,013
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's call some positive integer classy if its decimal representation contains no more than 3 non-zero digits. For example, numbers 4, 200000, 10203 are classy and numbers 4231, 102306, 7277420000 are not. You are given a segment [L; R]. Count the number of classy integers x such that L ≤ x ≤ R. Each testcase contains several segments, for each of them you are required to solve the problem separately. Input The first line contains a single integer T (1 ≤ T ≤ 10^4) — the number of segments in a testcase. Each of the next T lines contains two integers L_i and R_i (1 ≤ L_i ≤ R_i ≤ 10^{18}). Output Print T lines — the i-th line should contain the number of classy integers on a segment [L_i; R_i]. Example Input 4 1 1000 1024 1024 65536 65536 999999 1000001 Output 1000 1 0 2 Submitted Solution: ``` import math def check(x): cnt = 0 while(x): cnt = cnt + (x%10 != 0) x = math.floor(x/10) return cnt<=3 def bl(x): ans = 0 for i in range(1,x+1): if check(i): ans = ans+1 return ans def jc(x): sm = 1 for i in range(1,x+1): sm = sm * i return sm def c(x,y): if x<y: return 0 return jc(x)/(jc(x-y)*jc(y)) def cal1(x,y): ans = 0 for i in range(1,min(x,y)+1): ans = ans + c(x,i)*(9**i) return ans+1 def revers(x): ans = 0 while(x): ans = ans*10+ x%10 x = x.__floordiv__(10) return ans def cal2(x): rx = revers(x) ans = 0 cnt = 0 l = 0 l_ = 0 while(x): l = l+1 x = x.__floordiv__(10) while(rx): now = rx % 10 rx = rx.__floordiv__(10) l_ = l_ + 1 if now!=0: cnt = cnt+1 else: continue ans = ans + (now-1)*cal1(l-l_,3-cnt) + cal1(l-l_,3-cnt+1) if cnt>=3: break return ans T = int(input()) for i in range(T): x,y = map(int,input().split()) print(int(cal2(y)-cal2(x-1))) ```
instruction
0
36,007
20
72,014
Yes
output
1
36,007
20
72,015
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's call some positive integer classy if its decimal representation contains no more than 3 non-zero digits. For example, numbers 4, 200000, 10203 are classy and numbers 4231, 102306, 7277420000 are not. You are given a segment [L; R]. Count the number of classy integers x such that L ≤ x ≤ R. Each testcase contains several segments, for each of them you are required to solve the problem separately. Input The first line contains a single integer T (1 ≤ T ≤ 10^4) — the number of segments in a testcase. Each of the next T lines contains two integers L_i and R_i (1 ≤ L_i ≤ R_i ≤ 10^{18}). Output Print T lines — the i-th line should contain the number of classy integers on a segment [L_i; R_i]. Example Input 4 1 1000 1024 1024 65536 65536 999999 1000001 Output 1000 1 0 2 Submitted Solution: ``` import sys MAX_N = 20 MAX_DIG = 3 dp = [[0] * (MAX_DIG + 1) for i in range(MAX_N)] def calc_dp(): dp[0][0] = 1 for i in range(1, MAX_N): dp[i][0] = 1 for j in range(MAX_DIG): dp[i][j + 1] += 9 * dp[i - 1][j] dp[i][j + 1] += dp[i - 1][j + 1] def first_dig(n): cnt = 0 while n >= 10: n //= 10 cnt += 1 return n, cnt def calc_ans(n): ans = 0 for n_digs in range(MAX_DIG, -1, -1): x, cnt = first_dig(n) for i in range(n_digs): ans += x * dp[cnt][i] ans += dp[cnt][n_digs] n -= x * 10 ** cnt return ans def main(): calc_dp() T = int(input()) for _ in range(T): l, r = map(int, input().split()) print(calc_ans(r) - calc_ans(l - 1) if l > 0 else 0) if __name__ == '__main__': main() ```
instruction
0
36,008
20
72,016
Yes
output
1
36,008
20
72,017
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's call some positive integer classy if its decimal representation contains no more than 3 non-zero digits. For example, numbers 4, 200000, 10203 are classy and numbers 4231, 102306, 7277420000 are not. You are given a segment [L; R]. Count the number of classy integers x such that L ≤ x ≤ R. Each testcase contains several segments, for each of them you are required to solve the problem separately. Input The first line contains a single integer T (1 ≤ T ≤ 10^4) — the number of segments in a testcase. Each of the next T lines contains two integers L_i and R_i (1 ≤ L_i ≤ R_i ≤ 10^{18}). Output Print T lines — the i-th line should contain the number of classy integers on a segment [L_i; R_i]. Example Input 4 1 1000 1024 1024 65536 65536 999999 1000001 Output 1000 1 0 2 Submitted Solution: ``` #fonciton qui retourne le nombre des chiffres classy inferieur a une borne def classy(ran, nb): p= len(ran) if p == 0 or nb == 0: return 0 elif p <= nb : return int(ran) elif nb == 0: return 1 elif ran[0] == '0': return classy(ran[1:], nb) else: p-= 1 k = 1 s = 1 for i in range(nb-1): k*= (p-i)/(i+1) s+= k * (9**(i+1)) k*= (p-nb+1)/(nb) s = (int(ran[0])-1) * s + s+ k * (9**(nb)) return s + classy(ran[1:], nb-1) t = int(input()) res = [] for i in range(t): ran = [j for j in input().split()] res.append(classy(ran[1], 3) - classy(str(int(ran[0])-1), 3)) for i in res : print(int(i)) ```
instruction
0
36,009
20
72,018
Yes
output
1
36,009
20
72,019
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's call some positive integer classy if its decimal representation contains no more than 3 non-zero digits. For example, numbers 4, 200000, 10203 are classy and numbers 4231, 102306, 7277420000 are not. You are given a segment [L; R]. Count the number of classy integers x such that L ≤ x ≤ R. Each testcase contains several segments, for each of them you are required to solve the problem separately. Input The first line contains a single integer T (1 ≤ T ≤ 10^4) — the number of segments in a testcase. Each of the next T lines contains two integers L_i and R_i (1 ≤ L_i ≤ R_i ≤ 10^{18}). Output Print T lines — the i-th line should contain the number of classy integers on a segment [L_i; R_i]. Example Input 4 1 1000 1024 1024 65536 65536 999999 1000001 Output 1000 1 0 2 Submitted Solution: ``` import bisect as b num =[] def Classy (pos, count, current): if pos==18: num.append(current) return Classy(pos+1, count, current*10) if (count < 3 ): for i in range(0,9): Classy(pos+1, count+1, current *10 + i) Classy(0,0,0) T = int(input()) while(0 < T): L, R = [int(x) for x in input().split(' ')] answer = b.bisect_left(num, R, lo=0, hi=len(num)) - b.bisect_right(num, L, lo=0, hi=len(num)) print(answer) T=T-1 ```
instruction
0
36,010
20
72,020
No
output
1
36,010
20
72,021
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's call some positive integer classy if its decimal representation contains no more than 3 non-zero digits. For example, numbers 4, 200000, 10203 are classy and numbers 4231, 102306, 7277420000 are not. You are given a segment [L; R]. Count the number of classy integers x such that L ≤ x ≤ R. Each testcase contains several segments, for each of them you are required to solve the problem separately. Input The first line contains a single integer T (1 ≤ T ≤ 10^4) — the number of segments in a testcase. Each of the next T lines contains two integers L_i and R_i (1 ≤ L_i ≤ R_i ≤ 10^{18}). Output Print T lines — the i-th line should contain the number of classy integers on a segment [L_i; R_i]. Example Input 4 1 1000 1024 1024 65536 65536 999999 1000001 Output 1000 1 0 2 Submitted Solution: ``` import bisect as b from collections import OrderedDict num =[] def Classy (pos, count, current): if pos==18: num.append(current) return Classy(pos+1, count, current*10) if (count < 3 ): for i in range(10): Classy(pos+1, count+1, current *10 + i) Classy(0,0,0) num=list(OrderedDict.fromkeys(num)) T = int(input()) while(0 < T): L, R = [int(x) for x in input().split(' ')] if L == R and L == 1000000000000000000: print(1) else: ans = b.bisect_right(num, R, lo=0, hi=len(num)) - b.bisect_left(num, L, lo=0, hi=len(num)) print(int(ans)) T=T-1 ```
instruction
0
36,011
20
72,022
No
output
1
36,011
20
72,023
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's call some positive integer classy if its decimal representation contains no more than 3 non-zero digits. For example, numbers 4, 200000, 10203 are classy and numbers 4231, 102306, 7277420000 are not. You are given a segment [L; R]. Count the number of classy integers x such that L ≤ x ≤ R. Each testcase contains several segments, for each of them you are required to solve the problem separately. Input The first line contains a single integer T (1 ≤ T ≤ 10^4) — the number of segments in a testcase. Each of the next T lines contains two integers L_i and R_i (1 ≤ L_i ≤ R_i ≤ 10^{18}). Output Print T lines — the i-th line should contain the number of classy integers on a segment [L_i; R_i]. Example Input 4 1 1000 1024 1024 65536 65536 999999 1000001 Output 1000 1 0 2 Submitted Solution: ``` T=int(input()) countn=0 for _ in range(T): L,R=[int(x) for x in input().split()] for x in range(L,R+1): countd=0 while x>0: d=x%10 x=x//10 if d>0: countd+=1 if countd==3: countn+=1 print(countn) ```
instruction
0
36,012
20
72,024
No
output
1
36,012
20
72,025
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's call some positive integer classy if its decimal representation contains no more than 3 non-zero digits. For example, numbers 4, 200000, 10203 are classy and numbers 4231, 102306, 7277420000 are not. You are given a segment [L; R]. Count the number of classy integers x such that L ≤ x ≤ R. Each testcase contains several segments, for each of them you are required to solve the problem separately. Input The first line contains a single integer T (1 ≤ T ≤ 10^4) — the number of segments in a testcase. Each of the next T lines contains two integers L_i and R_i (1 ≤ L_i ≤ R_i ≤ 10^{18}). Output Print T lines — the i-th line should contain the number of classy integers on a segment [L_i; R_i]. Example Input 4 1 1000 1024 1024 65536 65536 999999 1000001 Output 1000 1 0 2 Submitted Solution: ``` def jc(x): sm = 1 for i in range(1,x+1): sm = sm * i return sm def c(x,y): return jc(x)/(jc(x-y)*jc(y)) def cal1(x,y): ans = 0 for i in range(1,min(x,y)+1): ans = ans + c(x,i)*(9**i) return ans+1 def revers(x): ans = 0 while(x): ans = ans*10+ x%10 x = int(x/10) return ans def cal2(x): rx = revers(x) ans = 0 cnt = 0 l = 0 l_ = 0 while(x): l = l+1 x = int(x/10) while(rx): now = rx % 10 rx = int(rx/10) l_ = l_ + 1 if now!=0: cnt = cnt+1 else: continue ans = ans + (now-1)*cal1(l-cnt,3-cnt) + cal1(l-l_,3-cnt+1) if cnt>=3: break return ans T = int(input()) for i in range(T): x,y = map(int,input().split()) print(int(cal2(y)-cal2(x-1))) ```
instruction
0
36,013
20
72,026
No
output
1
36,013
20
72,027
Provide tags and a correct Python 3 solution for this coding contest problem. Not long ago Billy came across such a problem, where there were given three natural numbers A, B and C from the range [1, N], and it was asked to check whether the equation AB = C is correct. Recently Billy studied the concept of a digital root of a number. We should remind you that a digital root d(x) of the number x is the sum s(x) of all the digits of this number, if s(x) ≤ 9, otherwise it is d(s(x)). For example, a digital root of the number 6543 is calculated as follows: d(6543) = d(6 + 5 + 4 + 3) = d(18) = 9. Billy has counted that the digital root of a product of numbers is equal to the digital root of the product of the factors' digital roots, i.e. d(xy) = d(d(x)d(y)). And the following solution to the problem came to his mind: to calculate the digital roots and check if this condition is met. However, Billy has doubts that this condition is sufficient. That's why he asks you to find out the amount of test examples for the given problem such that the algorithm proposed by Billy makes mistakes. Input The first line contains the only number N (1 ≤ N ≤ 106). Output Output one number — the amount of required A, B and C from the range [1, N]. Examples Input 4 Output 2 Input 5 Output 6 Note For the first sample the required triples are (3, 4, 3) and (4, 3, 3).
instruction
0
36,046
20
72,092
Tags: number theory Correct Solution: ``` from math import sqrt, floor n = int(input()) true_products, a = 0, 1 while a ** 2 <= n: true_products += n // a - a a += 1 true_products *= 2 true_products += floor(sqrt(n)) digit_roots = [n // 9 for _ in range(9)] for i in range(1, n % 9 + 1): digit_roots[i] += 1 digit_root_products = 0 for i in range(9): for j in range(9): digit_root_products += digit_roots[i] * digit_roots[j] * digit_roots[(i * j) % 9] print(digit_root_products - true_products) ```
output
1
36,046
20
72,093
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer x of n digits a_1, a_2, …, a_n, which make up its decimal notation in order from left to right. Also, you are given a positive integer k < n. Let's call integer b_1, b_2, …, b_m beautiful if b_i = b_{i+k} for each i, such that 1 ≤ i ≤ m - k. You need to find the smallest beautiful integer y, such that y ≥ x. Input The first line of input contains two integers n, k (2 ≤ n ≤ 200 000, 1 ≤ k < n): the number of digits in x and k. The next line of input contains n digits a_1, a_2, …, a_n (a_1 ≠ 0, 0 ≤ a_i ≤ 9): digits of x. Output In the first line print one integer m: the number of digits in y. In the next line print m digits b_1, b_2, …, b_m (b_1 ≠ 0, 0 ≤ b_i ≤ 9): digits of y. Examples Input 3 2 353 Output 3 353 Input 4 2 1234 Output 4 1313
instruction
0
36,174
20
72,348
Tags: constructive algorithms, greedy, implementation, strings Correct Solution: ``` n,k=map(int,input().split()) a=''.join(str(input())) q=n//k r=n%k # verify the periodicity of the list c=a[:k] t=True if a[k:]>c*q+c[:r]: t=False print(n) if t: c=c*q res=c+c[:r] print(res) else: i=k-1 res='' while i>-1 and c[i]=='9': res='0'+res i-=1 res=str(int(c[i])+1)+res res=c[:k-len(res)]+res print(res*q+res[:r]) ```
output
1
36,174
20
72,349
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer x of n digits a_1, a_2, …, a_n, which make up its decimal notation in order from left to right. Also, you are given a positive integer k < n. Let's call integer b_1, b_2, …, b_m beautiful if b_i = b_{i+k} for each i, such that 1 ≤ i ≤ m - k. You need to find the smallest beautiful integer y, such that y ≥ x. Input The first line of input contains two integers n, k (2 ≤ n ≤ 200 000, 1 ≤ k < n): the number of digits in x and k. The next line of input contains n digits a_1, a_2, …, a_n (a_1 ≠ 0, 0 ≤ a_i ≤ 9): digits of x. Output In the first line print one integer m: the number of digits in y. In the next line print m digits b_1, b_2, …, b_m (b_1 ≠ 0, 0 ≤ b_i ≤ 9): digits of y. Examples Input 3 2 353 Output 3 353 Input 4 2 1234 Output 4 1313
instruction
0
36,175
20
72,350
Tags: constructive algorithms, greedy, implementation, strings Correct Solution: ``` n, k = map(int, input().split()) x = input() if n % k != 0: x += '0' * (k - n % k) d = len(x) // k arr = [x[i*k:i*k+k] for i in range(d)] first = arr[0] cand = first * d if cand >= x: print(n) print(cand[:n]) else: cand_len = len(first) first = str(int(first) + 1) print(n) print((first * d)[:n]) ```
output
1
36,175
20
72,351
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer x of n digits a_1, a_2, …, a_n, which make up its decimal notation in order from left to right. Also, you are given a positive integer k < n. Let's call integer b_1, b_2, …, b_m beautiful if b_i = b_{i+k} for each i, such that 1 ≤ i ≤ m - k. You need to find the smallest beautiful integer y, such that y ≥ x. Input The first line of input contains two integers n, k (2 ≤ n ≤ 200 000, 1 ≤ k < n): the number of digits in x and k. The next line of input contains n digits a_1, a_2, …, a_n (a_1 ≠ 0, 0 ≤ a_i ≤ 9): digits of x. Output In the first line print one integer m: the number of digits in y. In the next line print m digits b_1, b_2, …, b_m (b_1 ≠ 0, 0 ≤ b_i ≤ 9): digits of y. Examples Input 3 2 353 Output 3 353 Input 4 2 1234 Output 4 1313
instruction
0
36,176
20
72,352
Tags: constructive algorithms, greedy, implementation, strings Correct Solution: ``` def f(): n, k = [int(s) for s in input().split()] a = [int(s) for s in input()] tag = [a[i] for i in range(k)] must = -1 for i in range(k, n): if a[i] != tag[i % k]: must = i break if must == -1: print(n) print(''.join(str(num) for num in a)) return # if a[must] < tag[must % k]: # pass # # go as tags if a[must] > tag[must % k]: for i in range(k - 1, -1, -1): if tag[i] != 9: tag[i] = tag[i] + 1 for j in range(i+1,k): tag[j] = 0 break b = [tag[i % k] for i in range(n)] print(n) print(''.join(str(num) for num in b)) f() ```
output
1
36,176
20
72,353
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer x of n digits a_1, a_2, …, a_n, which make up its decimal notation in order from left to right. Also, you are given a positive integer k < n. Let's call integer b_1, b_2, …, b_m beautiful if b_i = b_{i+k} for each i, such that 1 ≤ i ≤ m - k. You need to find the smallest beautiful integer y, such that y ≥ x. Input The first line of input contains two integers n, k (2 ≤ n ≤ 200 000, 1 ≤ k < n): the number of digits in x and k. The next line of input contains n digits a_1, a_2, …, a_n (a_1 ≠ 0, 0 ≤ a_i ≤ 9): digits of x. Output In the first line print one integer m: the number of digits in y. In the next line print m digits b_1, b_2, …, b_m (b_1 ≠ 0, 0 ≤ b_i ≤ 9): digits of y. Examples Input 3 2 353 Output 3 353 Input 4 2 1234 Output 4 1313
instruction
0
36,177
20
72,354
Tags: constructive algorithms, greedy, implementation, strings Correct Solution: ``` n,k=[int(x) for x in input().split(' ')] s=input() s1=s s=s[:k] a=n//k if n%k!=0: a+=1 s*=a s=s[:n] if s>=s1: print(n) print(s) else: f=0 for i in range(k-1,-1,-1): if s[i]!='9': s=s[:i]+chr(ord(s[i]) + 1) +(k-1-i)*'0' s*=a s=s[:n] f=1 break if f==0: s='1'+n*'0' print(len(s)) print(s) ```
output
1
36,177
20
72,355
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer x of n digits a_1, a_2, …, a_n, which make up its decimal notation in order from left to right. Also, you are given a positive integer k < n. Let's call integer b_1, b_2, …, b_m beautiful if b_i = b_{i+k} for each i, such that 1 ≤ i ≤ m - k. You need to find the smallest beautiful integer y, such that y ≥ x. Input The first line of input contains two integers n, k (2 ≤ n ≤ 200 000, 1 ≤ k < n): the number of digits in x and k. The next line of input contains n digits a_1, a_2, …, a_n (a_1 ≠ 0, 0 ≤ a_i ≤ 9): digits of x. Output In the first line print one integer m: the number of digits in y. In the next line print m digits b_1, b_2, …, b_m (b_1 ≠ 0, 0 ≤ b_i ≤ 9): digits of y. Examples Input 3 2 353 Output 3 353 Input 4 2 1234 Output 4 1313
instruction
0
36,178
20
72,356
Tags: constructive algorithms, greedy, implementation, strings Correct Solution: ``` n,k = map(int,input().split()) no = input() ans = list(no) def finish(): print(len(ans)) print(''.join(ans)) quit() #already beautiful # pos = -1 # for i in range(n-k): if no[i]!=no[i+k]: pos = i break # if pos==-1: finish() #easily done if no[pos]>no[pos+k]: for i in range(pos,n-k): ans[i+k] = ans[i] finish() #main task #find new_pos to increase new_pos = k-1 while new_pos>=0 and no[new_pos]=='9': new_pos -= 1 if new_pos==-1: ans = ['1'] + ['0']*n ans[k] = '1' else: ans[new_pos] = str( int(ans[new_pos]) + 1 ) for i in range(new_pos+1,k): ans[i] = '0' for i in range(n-k): ans[i+k] = ans[i] finish() ```
output
1
36,178
20
72,357
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer x of n digits a_1, a_2, …, a_n, which make up its decimal notation in order from left to right. Also, you are given a positive integer k < n. Let's call integer b_1, b_2, …, b_m beautiful if b_i = b_{i+k} for each i, such that 1 ≤ i ≤ m - k. You need to find the smallest beautiful integer y, such that y ≥ x. Input The first line of input contains two integers n, k (2 ≤ n ≤ 200 000, 1 ≤ k < n): the number of digits in x and k. The next line of input contains n digits a_1, a_2, …, a_n (a_1 ≠ 0, 0 ≤ a_i ≤ 9): digits of x. Output In the first line print one integer m: the number of digits in y. In the next line print m digits b_1, b_2, …, b_m (b_1 ≠ 0, 0 ≤ b_i ≤ 9): digits of y. Examples Input 3 2 353 Output 3 353 Input 4 2 1234 Output 4 1313
instruction
0
36,179
20
72,358
Tags: constructive algorithms, greedy, implementation, strings Correct Solution: ``` n,k=map(int,input().split()) s=input() t=s[:k] fin=t*(n//k)+t[:n%k] if(fin>=s): print(len(fin)) print(fin) else: t=str(int(t)+1) fin=t*(n//k)+t[:n%k] print(len(fin)) print(fin) ```
output
1
36,179
20
72,359
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer x of n digits a_1, a_2, …, a_n, which make up its decimal notation in order from left to right. Also, you are given a positive integer k < n. Let's call integer b_1, b_2, …, b_m beautiful if b_i = b_{i+k} for each i, such that 1 ≤ i ≤ m - k. You need to find the smallest beautiful integer y, such that y ≥ x. Input The first line of input contains two integers n, k (2 ≤ n ≤ 200 000, 1 ≤ k < n): the number of digits in x and k. The next line of input contains n digits a_1, a_2, …, a_n (a_1 ≠ 0, 0 ≤ a_i ≤ 9): digits of x. Output In the first line print one integer m: the number of digits in y. In the next line print m digits b_1, b_2, …, b_m (b_1 ≠ 0, 0 ≤ b_i ≤ 9): digits of y. Examples Input 3 2 353 Output 3 353 Input 4 2 1234 Output 4 1313
instruction
0
36,180
20
72,360
Tags: constructive algorithms, greedy, implementation, strings Correct Solution: ``` n, k = list(map(int, input().split())) a = input() c = (a[:k])*(int(len(a)/k)) + a[:(len(a)%k)] if int(a) <= int(c): print(len(c)) print(c) else: b = str(int(a[:k]) + 1) c = b*(int(len(a)/k)) + b[:(len(a)%k)] print(len(c)) print(c) ```
output
1
36,180
20
72,361
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer x of n digits a_1, a_2, …, a_n, which make up its decimal notation in order from left to right. Also, you are given a positive integer k < n. Let's call integer b_1, b_2, …, b_m beautiful if b_i = b_{i+k} for each i, such that 1 ≤ i ≤ m - k. You need to find the smallest beautiful integer y, such that y ≥ x. Input The first line of input contains two integers n, k (2 ≤ n ≤ 200 000, 1 ≤ k < n): the number of digits in x and k. The next line of input contains n digits a_1, a_2, …, a_n (a_1 ≠ 0, 0 ≤ a_i ≤ 9): digits of x. Output In the first line print one integer m: the number of digits in y. In the next line print m digits b_1, b_2, …, b_m (b_1 ≠ 0, 0 ≤ b_i ≤ 9): digits of y. Examples Input 3 2 353 Output 3 353 Input 4 2 1234 Output 4 1313
instruction
0
36,181
20
72,362
Tags: constructive algorithms, greedy, implementation, strings Correct Solution: ``` n,k=map(int,input().split()) s=input() t=s[:k] ans=t*(n//k)+t[:n%k] if ans>=s: print(n) print(ans) else: t=str(int(t)+1) ans=t*(n//k)+t[:n%k] print(len(ans)) print(ans) ```
output
1
36,181
20
72,363
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 of n digits a_1, a_2, …, a_n, which make up its decimal notation in order from left to right. Also, you are given a positive integer k < n. Let's call integer b_1, b_2, …, b_m beautiful if b_i = b_{i+k} for each i, such that 1 ≤ i ≤ m - k. You need to find the smallest beautiful integer y, such that y ≥ x. Input The first line of input contains two integers n, k (2 ≤ n ≤ 200 000, 1 ≤ k < n): the number of digits in x and k. The next line of input contains n digits a_1, a_2, …, a_n (a_1 ≠ 0, 0 ≤ a_i ≤ 9): digits of x. Output In the first line print one integer m: the number of digits in y. In the next line print m digits b_1, b_2, …, b_m (b_1 ≠ 0, 0 ≤ b_i ≤ 9): digits of y. Examples Input 3 2 353 Output 3 353 Input 4 2 1234 Output 4 1313 Submitted Solution: ``` def increment_string_integer(pattern): pattern_list = list(pattern) for i in range(len(pattern)-1,-1,-1): if ord(pattern_list[i]) == 57: pattern_list[i] = '0' continue pattern_list[i] = chr(ord(pattern_list[i]) + 1) break return "".join(pattern_list) if __name__ == "__main__": n, k = [int(x) for x in input().split()] s = input() pattern = s[:k] for i in range(n): current_pattern_char = pattern[i%k] current_string_char = s[i] if current_pattern_char == current_string_char: continue if ord(current_pattern_char) > ord(current_string_char): break else: pattern = increment_string_integer(pattern) break number_of_patterns = n//k number_of_patterns += 1 if n % k != 0 else 0 res = pattern * number_of_patterns res = res[:n] print(n) print(res) ```
instruction
0
36,182
20
72,364
Yes
output
1
36,182
20
72,365
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 of n digits a_1, a_2, …, a_n, which make up its decimal notation in order from left to right. Also, you are given a positive integer k < n. Let's call integer b_1, b_2, …, b_m beautiful if b_i = b_{i+k} for each i, such that 1 ≤ i ≤ m - k. You need to find the smallest beautiful integer y, such that y ≥ x. Input The first line of input contains two integers n, k (2 ≤ n ≤ 200 000, 1 ≤ k < n): the number of digits in x and k. The next line of input contains n digits a_1, a_2, …, a_n (a_1 ≠ 0, 0 ≤ a_i ≤ 9): digits of x. Output In the first line print one integer m: the number of digits in y. In the next line print m digits b_1, b_2, …, b_m (b_1 ≠ 0, 0 ≤ b_i ≤ 9): digits of y. Examples Input 3 2 353 Output 3 353 Input 4 2 1234 Output 4 1313 Submitted Solution: ``` # @author import sys class CLongBeautifulInteger: def solve(self): def check_blocks(s, k): for i in range(k, len(s), k): v = len(s[i:i + k]) if int(s[:v]) < int(s[i:i + k]): return False if int(s[:v]) > int(s[i:i + k]): return True return True def add_one(s): return str(int(s) + 1) n, k = [int(_) for _ in input().split()] s = input().strip() base = s[:k] if check_blocks(s, k): print((n // k) * k + n % k) print(base * (n // k) + base[:n % k]) else: base1 = add_one(base) k1 = len(base1) print(k1 * (n // k1) + n % k1) print(base1 * (n // k1) + base1[:n % k1]) solver = CLongBeautifulInteger() input = sys.stdin.readline solver.solve() ```
instruction
0
36,184
20
72,368
Yes
output
1
36,184
20
72,369
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 of n digits a_1, a_2, …, a_n, which make up its decimal notation in order from left to right. Also, you are given a positive integer k < n. Let's call integer b_1, b_2, …, b_m beautiful if b_i = b_{i+k} for each i, such that 1 ≤ i ≤ m - k. You need to find the smallest beautiful integer y, such that y ≥ x. Input The first line of input contains two integers n, k (2 ≤ n ≤ 200 000, 1 ≤ k < n): the number of digits in x and k. The next line of input contains n digits a_1, a_2, …, a_n (a_1 ≠ 0, 0 ≤ a_i ≤ 9): digits of x. Output In the first line print one integer m: the number of digits in y. In the next line print m digits b_1, b_2, …, b_m (b_1 ≠ 0, 0 ≤ b_i ≤ 9): digits of y. Examples Input 3 2 353 Output 3 353 Input 4 2 1234 Output 4 1313 Submitted Solution: ``` import sys input=sys.stdin.readline from math import * n,k=map(int,input().split()) a=list(input().rstrip()) f=0 for j in range(k): if f==1: f+=1 h=str(int(a[j])+1) elif f==0: h=a[j] else: h='1' for i in range(j,n,k): if f==0 and a[i]>h: f=1 a[i]=h print("".join(a)) ```
instruction
0
36,189
20
72,378
No
output
1
36,189
20
72,379
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a string s consisting only of characters + and -. You perform some process with this string. This process can be described by the following pseudocode: res = 0 for init = 0 to inf cur = init ok = true for i = 1 to |s| res = res + 1 if s[i] == '+' cur = cur + 1 else cur = cur - 1 if cur < 0 ok = false break if ok break Note that the inf denotes infinity, and the characters of the string are numbered from 1 to |s|. You have to calculate the value of the res after the process ends. Input The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases. The only lines of each test case contains string s (1 ≤ |s| ≤ 10^6) consisting only of characters + and -. It's guaranteed that sum of |s| over all test cases doesn't exceed 10^6. Output For each test case print one integer — the value of the res after the process ends. Example Input 3 --+- --- ++--+- Output 7 9 6
instruction
0
36,244
20
72,488
Tags: math Correct Solution: ``` import sys import math import itertools import functools import collections import operator import fileinput import copy ORDA = 97 # a def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return [int(i) for i in input().split()] def lcm(a, b): return abs(a * b) // math.gcd(a, b) def revn(n): return str(n)[::-1] def dd(): return collections.defaultdict(int) def ddl(): return collections.defaultdict(list) def sieve(n): if n < 2: return list() prime = [True for _ in range(n + 1)] p = 3 while p * p <= n: if prime[p]: for i in range(p * 2, n + 1, p): prime[i] = False p += 2 r = [2] for p in range(3, n + 1, 2): if prime[p]: r.append(p) return r def divs(n, start=1): r = [] for i in range(start, int(math.sqrt(n) + 1)): if (n % i == 0): if (n / i == i): r.append(i) else: r.extend([i, n // i]) return r def divn(n, primes): divs_number = 1 for i in primes: if n == 1: return divs_number t = 1 while n % i == 0: t += 1 n //= i divs_number *= t def prime(n): if n == 2: return True if n % 2 == 0 or n <= 1: return False sqr = int(math.sqrt(n)) + 1 for d in range(3, sqr, 2): if n % d == 0: return False return True def convn(number, base): newnumber = 0 while number > 0: newnumber += number % base number //= base return newnumber def cdiv(n, k): return n // k + (n % k != 0) def ispal(s): for i in range(len(s) // 2 + 1): if s[i] != s[-i - 1]: return False return True for _ in range(ii()): s = input() lens = len(s) p = [] t = 0 for i in range(lens): if s[i] == '+': t += 1 else: t -= 1 p.append(t) mn = 1 f = [] for i in range(lens): if p[i] == -mn: f.append(i + 1) mn += 1 print(sum(f) + lens) ```
output
1
36,244
20
72,489
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. Examples Input 101 Output 11 Input 110010 Output 11010 Note In the first sample the best strategy is to delete the second digit. That results in number 112 = 310. In the second sample the best strategy is to delete the third or fourth digits — that results in number 110102 = 2610.
instruction
0
36,379
20
72,758
Tags: greedy, math Correct Solution: ``` s=input() f=0 for i in range(len(s)): if s[i]=='0': a=s[:i]+s[i+1:] f=1 break if f: print(a) else: print(s[1:]) ```
output
1
36,379
20
72,759
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. Examples Input 101 Output 11 Input 110010 Output 11010 Note In the first sample the best strategy is to delete the second digit. That results in number 112 = 310. In the second sample the best strategy is to delete the third or fourth digits — that results in number 110102 = 2610.
instruction
0
36,380
20
72,760
Tags: greedy, math Correct Solution: ``` n=input() if n.count("0")==0: print(n[:len(n)-1]) else: for i in range(len(n)): if n[i]!="0": print(n[i],end="") else: break print(n[i+1:]) ```
output
1
36,380
20
72,761
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. Examples Input 101 Output 11 Input 110010 Output 11010 Note In the first sample the best strategy is to delete the second digit. That results in number 112 = 310. In the second sample the best strategy is to delete the third or fourth digits — that results in number 110102 = 2610.
instruction
0
36,381
20
72,762
Tags: greedy, math Correct Solution: ``` s=input() t=False for i in range(len(s)): if s[i]=="0": t=True s=s[:i]+s[i+1:] break print(s if t else s[1:]) ```
output
1
36,381
20
72,763
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. Examples Input 101 Output 11 Input 110010 Output 11010 Note In the first sample the best strategy is to delete the second digit. That results in number 112 = 310. In the second sample the best strategy is to delete the third or fourth digits — that results in number 110102 = 2610.
instruction
0
36,382
20
72,764
Tags: greedy, math Correct Solution: ``` li = list(input()) if '0' in li:li.remove('0') else:li.remove('1') print(''.join(li)) ```
output
1
36,382
20
72,765
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. Examples Input 101 Output 11 Input 110010 Output 11010 Note In the first sample the best strategy is to delete the second digit. That results in number 112 = 310. In the second sample the best strategy is to delete the third or fourth digits — that results in number 110102 = 2610.
instruction
0
36,383
20
72,766
Tags: greedy, math Correct Solution: ``` s = input() if s.find('0') == -1: print(s.replace('1', '', 1)) else: print(s.replace('0', '', 1)) ```
output
1
36,383
20
72,767
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. Examples Input 101 Output 11 Input 110010 Output 11010 Note In the first sample the best strategy is to delete the second digit. That results in number 112 = 310. In the second sample the best strategy is to delete the third or fourth digits — that results in number 110102 = 2610.
instruction
0
36,384
20
72,768
Tags: greedy, math Correct Solution: ``` #In the name of Allah from sys import stdin, stdout input = stdin.readline a = input()[:-1] dl = -1 for i in range(len(a)): if a[i] == "0": dl = i break a = list(a) a.pop(i) stdout.write("".join(a)) ```
output
1
36,384
20
72,769
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. Examples Input 101 Output 11 Input 110010 Output 11010 Note In the first sample the best strategy is to delete the second digit. That results in number 112 = 310. In the second sample the best strategy is to delete the third or fourth digits — that results in number 110102 = 2610.
instruction
0
36,385
20
72,770
Tags: greedy, math Correct Solution: ``` a=list(input()) x=a.count('0') if x==0: a.pop() else: a.remove('0') for i in range(len(a)): print(a[i],end='') ```
output
1
36,385
20
72,771
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. Examples Input 101 Output 11 Input 110010 Output 11010 Note In the first sample the best strategy is to delete the second digit. That results in number 112 = 310. In the second sample the best strategy is to delete the third or fourth digits — that results in number 110102 = 2610.
instruction
0
36,386
20
72,772
Tags: greedy, math Correct Solution: ``` s=input() n=len(s) for i in range(n): if(s[i]=='0'): s=s[:i]+s[i+1:] break if(len(s)==n): s=s[:n-1] print(s) ```
output
1
36,386
20
72,773
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. Examples Input 101 Output 11 Input 110010 Output 11010 Note In the first sample the best strategy is to delete the second digit. That results in number 112 = 310. In the second sample the best strategy is to delete the third or fourth digits — that results in number 110102 = 2610. Submitted Solution: ``` number = input() length = len(number) for i in range(length): if number[i] == '0': number = number[0:i] + number[i + 1:] break if len(number) == length: number = number[1:] print(number) ```
instruction
0
36,387
20
72,774
Yes
output
1
36,387
20
72,775
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. Examples Input 101 Output 11 Input 110010 Output 11010 Note In the first sample the best strategy is to delete the second digit. That results in number 112 = 310. In the second sample the best strategy is to delete the third or fourth digits — that results in number 110102 = 2610. Submitted Solution: ``` s=list(input()) for i in range(len(s)): if s[i]=='0': break del(s[i]) print("".join(s)) ```
instruction
0
36,388
20
72,776
Yes
output
1
36,388
20
72,777
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. Examples Input 101 Output 11 Input 110010 Output 11010 Note In the first sample the best strategy is to delete the second digit. That results in number 112 = 310. In the second sample the best strategy is to delete the third or fourth digits — that results in number 110102 = 2610. Submitted Solution: ``` n=input() z=max(0,n.find('0')) print(n[:z]+n[z+1:]) # Made By Mostafa_Khaled ```
instruction
0
36,389
20
72,778
Yes
output
1
36,389
20
72,779
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. Examples Input 101 Output 11 Input 110010 Output 11010 Note In the first sample the best strategy is to delete the second digit. That results in number 112 = 310. In the second sample the best strategy is to delete the third or fourth digits — that results in number 110102 = 2610. Submitted Solution: ``` s = input() pos = max(0, s.find('0')) print(s[:pos] + s[pos + 1:]) ```
instruction
0
36,390
20
72,780
Yes
output
1
36,390
20
72,781
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. Examples Input 101 Output 11 Input 110010 Output 11010 Note In the first sample the best strategy is to delete the second digit. That results in number 112 = 310. In the second sample the best strategy is to delete the third or fourth digits — that results in number 110102 = 2610. Submitted Solution: ``` s=input() for i in range(len(s)): if s[i]=="0": s=s[:i]+s[i+1:] break print(s) ```
instruction
0
36,391
20
72,782
No
output
1
36,391
20
72,783
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. Examples Input 101 Output 11 Input 110010 Output 11010 Note In the first sample the best strategy is to delete the second digit. That results in number 112 = 310. In the second sample the best strategy is to delete the third or fourth digits — that results in number 110102 = 2610. Submitted Solution: ``` s = input() print(s.replace('0', '', 1)) ```
instruction
0
36,392
20
72,784
No
output
1
36,392
20
72,785
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. Examples Input 101 Output 11 Input 110010 Output 11010 Note In the first sample the best strategy is to delete the second digit. That results in number 112 = 310. In the second sample the best strategy is to delete the third or fourth digits — that results in number 110102 = 2610. Submitted Solution: ``` s=input() f=0 for i in range(len(s)): if s[i]=='0': a=s[:i]+s[i+1:] f=1 break if f: print(a) else: print(s) ```
instruction
0
36,393
20
72,786
No
output
1
36,393
20
72,787
Provide tags and a correct Python 3 solution for this coding contest problem. Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer m and asks for the number of positive integers n, such that the factorial of n ends with exactly m zeroes. Are you among those great programmers who can solve this problem? Input The only line of input contains an integer m (1 ≤ m ≤ 100 000) — the required number of trailing zeroes in factorial. Output First print k — the number of values of n such that the factorial of n ends with m zeroes. Then print these k integers in increasing order. Examples Input 1 Output 5 5 6 7 8 9 Input 5 Output 0 Note The factorial of n is equal to the product of all integers from 1 to n inclusive, that is n! = 1·2·3·...·n. In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880.
instruction
0
36,541
20
73,082
Tags: brute force, constructive algorithms, math, number theory Correct Solution: ``` # Author : -pratyay- import sys # inp=sys.stdin.buffer.readline import io,os inp = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline inar=lambda: list(map(int,inp().split())) inin=lambda: int(inp()) inst=lambda: inp().decode().strip() wrt=sys.stdout.write pr=lambda *args,end='\n': wrt(' '.join([str(x) for x in args])+end) enum=enumerate inf=float('inf') cdiv=lambda x,y: (-(-x//y)) # Am I debugging ? Check if I'm using same variable name in two places # fun() returning empty list ? check new=temp[:] or new=temp def print(*args,end='\n'): for i in args: sys.stdout.write(str(i)+' ') #sys.stdout.flush() sys.stdout.write(end) from types import GeneratorType def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) else: stack.pop() if not stack: break to = stack[-1].send(to) return to return wrappedfunc def DFS(gr,cost): n=len(gr) vis=[False for i in range(n)] ans=0 @bootstrap def dfs(node): vis[node]=True ret=cost[node] for i in gr[node]: if not vis[i]: ret=min(ret,(yield dfs(i))) yield ret for i in range(n): if not vis[i]: ans+=dfs(i) return ans def cnt(x): res=0 i=5 while(i<=x): res+=x//i i*=5 return res _T_=1 #inin() for _t_ in range(_T_): n=inin() low=1;high=int(1e18) ansleft=0; ansright=0 while(low<=high): mid=(low+high)//2 srch=cnt(mid) if srch==n: ansleft=mid high=mid-1 elif srch>n: high=mid-1 else: low=mid+1 low=1;high=int(1e18) while(low<=high): mid=(low+high)//2 srch=cnt(mid) if srch==n: ansright=mid low=mid+1 elif srch>n: high=mid-1 else: low=mid+1 if ansleft==ansright==0: print(0) break print(ansright-ansleft+1) print(*[i for i in range(ansleft,ansright+1)]) ```
output
1
36,541
20
73,083
Provide tags and a correct Python 3 solution for this coding contest problem. Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer m and asks for the number of positive integers n, such that the factorial of n ends with exactly m zeroes. Are you among those great programmers who can solve this problem? Input The only line of input contains an integer m (1 ≤ m ≤ 100 000) — the required number of trailing zeroes in factorial. Output First print k — the number of values of n such that the factorial of n ends with m zeroes. Then print these k integers in increasing order. Examples Input 1 Output 5 5 6 7 8 9 Input 5 Output 0 Note The factorial of n is equal to the product of all integers from 1 to n inclusive, that is n! = 1·2·3·...·n. In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880.
instruction
0
36,542
20
73,084
Tags: brute force, constructive algorithms, math, number theory Correct Solution: ``` import io, os import sys from math import log from atexit import register input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline sys.stdout = io.BytesIO() register(lambda: os.write(1, sys.stdout.getvalue())) tokens = [] tokens_next = 0 def nextStr(): global tokens, tokens_next while tokens_next >= len(tokens): tokens = input().split() tokens_next = 0 tokens_next += 1 return tokens[tokens_next - 1] def nextInt(): return int(nextStr()) def nextIntArr(n): return [nextInt() for i in range(n)] def print(s, end='\n'): sys.stdout.write((str(s) + end).encode()) def countFivesInNum(n): res = 0 while n % 5 == 0: res += 1 n /= 5 return res def solve(m): res = [] accCount = 0 for i in range(1, 10**6): accCount += countFivesInNum(i) if accCount == m: res.append(i) elif accCount > m: break return res if __name__ == "__main__": m = nextInt() res = solve(m) print(len(res)) print(' '.join(map(str, res))) ```
output
1
36,542
20
73,085
Provide tags and a correct Python 3 solution for this coding contest problem. Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer m and asks for the number of positive integers n, such that the factorial of n ends with exactly m zeroes. Are you among those great programmers who can solve this problem? Input The only line of input contains an integer m (1 ≤ m ≤ 100 000) — the required number of trailing zeroes in factorial. Output First print k — the number of values of n such that the factorial of n ends with m zeroes. Then print these k integers in increasing order. Examples Input 1 Output 5 5 6 7 8 9 Input 5 Output 0 Note The factorial of n is equal to the product of all integers from 1 to n inclusive, that is n! = 1·2·3·...·n. In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880.
instruction
0
36,543
20
73,086
Tags: brute force, constructive algorithms, math, number theory Correct Solution: ``` # найти k чисел, которые делятся на 10^m #10 factors 5 and 2 #5, 10, 15, 20, 25, ..., 50, ..., 75, ..., 100, 125 # 5 - 20 one zero # 25 - 100 two zero 125 - 625 three zero floor(5throot) # 4(1+2+3+...) = # 1 2 3 4 6 7 8 9 10 12 15 18 21 24 # 5 10 15 20 25 30 ... import math def toAdd(n): cnt = 0 while(n != 1): if(n % 5 == 0): cnt += 1 n //= 5 else: break return cnt cnt = 0 exist = [] curr = 5 while cnt <= 100000: cnt += toAdd(curr) exist.append(cnt) curr += 5 m = int(input()) if m in exist: print(5) for i in range(5 * (exist.index(m) + 1), 5 * (exist.index(m) + 2)): print(i, end = " ") else: print(0) ```
output
1
36,543
20
73,087
Provide tags and a correct Python 3 solution for this coding contest problem. Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer m and asks for the number of positive integers n, such that the factorial of n ends with exactly m zeroes. Are you among those great programmers who can solve this problem? Input The only line of input contains an integer m (1 ≤ m ≤ 100 000) — the required number of trailing zeroes in factorial. Output First print k — the number of values of n such that the factorial of n ends with m zeroes. Then print these k integers in increasing order. Examples Input 1 Output 5 5 6 7 8 9 Input 5 Output 0 Note The factorial of n is equal to the product of all integers from 1 to n inclusive, that is n! = 1·2·3·...·n. In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880.
instruction
0
36,544
20
73,088
Tags: brute force, constructive algorithms, math, number theory Correct Solution: ``` import itertools import bisect m = int(input()) degs = [0 for i in range(5*m+6)] deg = 5 while deg < 5*m+1: for i in range(deg, 5*m+6, deg): degs[i] += 1 deg *= 5 prefix = list(itertools.accumulate(degs)) i = bisect.bisect_left(prefix, m) ans = [] for j in range(i, min(i+5, 5*m+6)): if prefix[j] == m: ans.append(j) print(len(ans)) for j in ans: print(j, end = ' ') ```
output
1
36,544
20
73,089
Provide tags and a correct Python 3 solution for this coding contest problem. Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer m and asks for the number of positive integers n, such that the factorial of n ends with exactly m zeroes. Are you among those great programmers who can solve this problem? Input The only line of input contains an integer m (1 ≤ m ≤ 100 000) — the required number of trailing zeroes in factorial. Output First print k — the number of values of n such that the factorial of n ends with m zeroes. Then print these k integers in increasing order. Examples Input 1 Output 5 5 6 7 8 9 Input 5 Output 0 Note The factorial of n is equal to the product of all integers from 1 to n inclusive, that is n! = 1·2·3·...·n. In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880.
instruction
0
36,545
20
73,090
Tags: brute force, constructive algorithms, math, number theory Correct Solution: ``` m = int(input()) k = 0 num = 0 mem = 0 r = 0 while k < m + 1: num += 1 n = num while n > 1 : if n % 5 == 0: r += 1 n //= 5 else: break mem = k k += r r = 0 if (mem - m != 0): print(0) else: print(5) print(' '.join(map(str, range(num-5, num)))) ```
output
1
36,545
20
73,091
Provide tags and a correct Python 3 solution for this coding contest problem. Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer m and asks for the number of positive integers n, such that the factorial of n ends with exactly m zeroes. Are you among those great programmers who can solve this problem? Input The only line of input contains an integer m (1 ≤ m ≤ 100 000) — the required number of trailing zeroes in factorial. Output First print k — the number of values of n such that the factorial of n ends with m zeroes. Then print these k integers in increasing order. Examples Input 1 Output 5 5 6 7 8 9 Input 5 Output 0 Note The factorial of n is equal to the product of all integers from 1 to n inclusive, that is n! = 1·2·3·...·n. In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880.
instruction
0
36,546
20
73,092
Tags: brute force, constructive algorithms, math, number theory Correct Solution: ``` def count(x, y): res = 0 while x % y == 0: res += 1 x /= y return res N = 4 * 10 ** 5 + 100 cnt2 = [0] * N cnt5 = [0] * N for i in range(1, N): cnt2[i] = cnt2[i - 1] + count(i, 2) cnt5[i] = cnt5[i - 1] + count(i, 5) m = int(input()) ans = [] for i in range(1, N): if min(cnt2[i], cnt5[i]) == m: ans += [i] print(len(ans)) for i in ans: print(i, end = ' ') ```
output
1
36,546
20
73,093
Provide tags and a correct Python 3 solution for this coding contest problem. Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer m and asks for the number of positive integers n, such that the factorial of n ends with exactly m zeroes. Are you among those great programmers who can solve this problem? Input The only line of input contains an integer m (1 ≤ m ≤ 100 000) — the required number of trailing zeroes in factorial. Output First print k — the number of values of n such that the factorial of n ends with m zeroes. Then print these k integers in increasing order. Examples Input 1 Output 5 5 6 7 8 9 Input 5 Output 0 Note The factorial of n is equal to the product of all integers from 1 to n inclusive, that is n! = 1·2·3·...·n. In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880.
instruction
0
36,547
20
73,094
Tags: brute force, constructive algorithms, math, number theory Correct Solution: ``` #Author : Junth Basnet a=int(input()) count=0 i=0 while count<a: i+=1 k=i while k%5==0: count+=1 k=(k//5) if count==a: print(5) print(i,i+1,i+2,i+3,i+4) else: print(0) # Made By Mostafa_Khaled ```
output
1
36,547
20
73,095
Provide tags and a correct Python 3 solution for this coding contest problem. Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer m and asks for the number of positive integers n, such that the factorial of n ends with exactly m zeroes. Are you among those great programmers who can solve this problem? Input The only line of input contains an integer m (1 ≤ m ≤ 100 000) — the required number of trailing zeroes in factorial. Output First print k — the number of values of n such that the factorial of n ends with m zeroes. Then print these k integers in increasing order. Examples Input 1 Output 5 5 6 7 8 9 Input 5 Output 0 Note The factorial of n is equal to the product of all integers from 1 to n inclusive, that is n! = 1·2·3·...·n. In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880.
instruction
0
36,548
20
73,096
Tags: brute force, constructive algorithms, math, number theory Correct Solution: ``` m = int(input()) c = 0 i = n = 5 ans = [] while c<=m: while n%5==0: c += 1 n //= 5 if c==m: ans.append(i) i += 1 n = i if ans==[]: print(0) else: print(5) print(*ans) ```
output
1
36,548
20
73,097
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer m and asks for the number of positive integers n, such that the factorial of n ends with exactly m zeroes. Are you among those great programmers who can solve this problem? Input The only line of input contains an integer m (1 ≤ m ≤ 100 000) — the required number of trailing zeroes in factorial. Output First print k — the number of values of n such that the factorial of n ends with m zeroes. Then print these k integers in increasing order. Examples Input 1 Output 5 5 6 7 8 9 Input 5 Output 0 Note The factorial of n is equal to the product of all integers from 1 to n inclusive, that is n! = 1·2·3·...·n. In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880. Submitted Solution: ``` a=int(input()) t=[] num=1 two=0 five=0 counter=0 k=0 while k<=a : if k==a : counter=counter+1 t.append(num-1) s=num while s%2==0 : two+=1 s=s/2 while s%5==0 : five+=1 s=s/5 while two>0 and five>0 : k=k+1 two=two-1 five=five-1 num=num+1 print(counter) for i in t : print(i,end=' ') ```
instruction
0
36,549
20
73,098
Yes
output
1
36,549
20
73,099
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer m and asks for the number of positive integers n, such that the factorial of n ends with exactly m zeroes. Are you among those great programmers who can solve this problem? Input The only line of input contains an integer m (1 ≤ m ≤ 100 000) — the required number of trailing zeroes in factorial. Output First print k — the number of values of n such that the factorial of n ends with m zeroes. Then print these k integers in increasing order. Examples Input 1 Output 5 5 6 7 8 9 Input 5 Output 0 Note The factorial of n is equal to the product of all integers from 1 to n inclusive, that is n! = 1·2·3·...·n. In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880. Submitted Solution: ``` import time import math n = int(input()) start = time.time() i = 0 results = [] c = [(5 ** i) for i in range(1, 9)] def powers(n): #print(c) res = 0 for i in range(len(c)): res += math.floor(n / c[i]) return res while True: i += 1 k = powers(i) # print(i, k) if k == n: #print('powers:', powers(i)) results.append(i) if k > n: break end = time.time() print(len(results)) if len(results) != 0: print(' '.join(list(map(str, results)))) #print(end - start) ```
instruction
0
36,550
20
73,100
Yes
output
1
36,550
20
73,101
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer m and asks for the number of positive integers n, such that the factorial of n ends with exactly m zeroes. Are you among those great programmers who can solve this problem? Input The only line of input contains an integer m (1 ≤ m ≤ 100 000) — the required number of trailing zeroes in factorial. Output First print k — the number of values of n such that the factorial of n ends with m zeroes. Then print these k integers in increasing order. Examples Input 1 Output 5 5 6 7 8 9 Input 5 Output 0 Note The factorial of n is equal to the product of all integers from 1 to n inclusive, that is n! = 1·2·3·...·n. In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880. Submitted Solution: ``` # Author : -pratyay- import sys # inp=sys.stdin.buffer.readline import io,os inp = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline inar=lambda: list(map(int,inp().split())) inin=lambda: int(inp()) inst=lambda: inp().decode().strip() wrt=sys.stdout.write pr=lambda *args,end='\n': wrt(' '.join([str(x) for x in args])+end) enum=enumerate inf=float('inf') cdiv=lambda x,y: (-(-x//y)) # Am I debugging ? Check if I'm using same variable name in two places # fun() returning empty list ? check new=temp[:] or new=temp def print(*args,end='\n'): for i in args: sys.stdout.write(str(i)+' ') #sys.stdout.flush() sys.stdout.write(end) from types import GeneratorType def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) else: stack.pop() if not stack: break to = stack[-1].send(to) return to return wrappedfunc def DFS(gr,cost): n=len(gr) vis=[False for i in range(n)] ans=0 @bootstrap def dfs(node): vis[node]=True ret=cost[node] for i in gr[node]: if not vis[i]: ret=min(ret,(yield dfs(i))) yield ret for i in range(n): if not vis[i]: ans+=dfs(i) return ans def cnt(x): res=0 i=5 while(i<=x): res+=x//i i*=5 return res _T_=1 #inin() for _t_ in range(_T_): n=inin() low=1;high=int(1e15) ansleft=0; ansright=0 while(low<=high): mid=(low+high)//2 srch=cnt(mid) if srch==n: ansleft=mid high=mid-1 elif srch>n: high=mid-1 else: low=mid+1 low=1;high=int(1e15) while(low<=high): mid=(low+high)//2 srch=cnt(mid) if srch==n: ansright=mid low=mid+1 elif srch>n: high=mid-1 else: low=mid+1 if ansleft==ansright==0: print(0) break print(ansright-ansleft+1) print(*[i for i in range(ansleft,ansright+1)]) ```
instruction
0
36,551
20
73,102
Yes
output
1
36,551
20
73,103