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. Bob is a competitive programmer. He wants to become red, and for that he needs a strict training regime. He went to the annual meeting of grandmasters and asked n of them how much effort they needed to reach red. "Oh, I just spent x_i hours solving problems", said the i-th of them. Bob wants to train his math skills, so for each answer he wrote down the number of minutes (60 β‹… x_i), thanked the grandmasters and went home. Bob could write numbers with leading zeroes β€” for example, if some grandmaster answered that he had spent 2 hours, Bob could write 000120 instead of 120. Alice wanted to tease Bob and so she took the numbers Bob wrote down, and for each of them she did one of the following independently: * rearranged its digits, or * wrote a random number. This way, Alice generated n numbers, denoted y_1, ..., y_n. For each of the numbers, help Bob determine whether y_i can be a permutation of a number divisible by 60 (possibly with leading zeroes). Input The first line contains a single integer n (1 ≀ n ≀ 418) β€” the number of grandmasters Bob asked. Then n lines follow, the i-th of which contains a single integer y_i β€” the number that Alice wrote down. Each of these numbers has between 2 and 100 digits '0' through '9'. They can contain leading zeroes. Output Output n lines. For each i, output the following. If it is possible to rearrange the digits of y_i such that the resulting number is divisible by 60, output "red" (quotes for clarity). Otherwise, output "cyan". Example Input 6 603 006 205 228 1053 0000000000000000000000000000000000000000000000 Output red red cyan cyan cyan red Note In the first example, there is one rearrangement that yields a number divisible by 60, and that is 360. In the second example, there are two solutions. One is 060 and the second is 600. In the third example, there are 6 possible rearrangments: 025, 052, 205, 250, 502, 520. None of these numbers is divisible by 60. In the fourth example, there are 3 rearrangements: 228, 282, 822. In the fifth example, none of the 24 rearrangements result in a number divisible by 60. In the sixth example, note that 000...0 is a valid solution. Submitted Solution: ``` for _ in range(int(input())): y = list(map(int, input())) if sum(y) == 0: print("red") elif sum(y) % 3 == 0 and (0 in y) and any(filter(lambda x: x % 2 == 0, y)): print("red") else: print("cyan") ```
instruction
0
51,445
20
102,890
No
output
1
51,445
20
102,891
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bob is a competitive programmer. He wants to become red, and for that he needs a strict training regime. He went to the annual meeting of grandmasters and asked n of them how much effort they needed to reach red. "Oh, I just spent x_i hours solving problems", said the i-th of them. Bob wants to train his math skills, so for each answer he wrote down the number of minutes (60 β‹… x_i), thanked the grandmasters and went home. Bob could write numbers with leading zeroes β€” for example, if some grandmaster answered that he had spent 2 hours, Bob could write 000120 instead of 120. Alice wanted to tease Bob and so she took the numbers Bob wrote down, and for each of them she did one of the following independently: * rearranged its digits, or * wrote a random number. This way, Alice generated n numbers, denoted y_1, ..., y_n. For each of the numbers, help Bob determine whether y_i can be a permutation of a number divisible by 60 (possibly with leading zeroes). Input The first line contains a single integer n (1 ≀ n ≀ 418) β€” the number of grandmasters Bob asked. Then n lines follow, the i-th of which contains a single integer y_i β€” the number that Alice wrote down. Each of these numbers has between 2 and 100 digits '0' through '9'. They can contain leading zeroes. Output Output n lines. For each i, output the following. If it is possible to rearrange the digits of y_i such that the resulting number is divisible by 60, output "red" (quotes for clarity). Otherwise, output "cyan". Example Input 6 603 006 205 228 1053 0000000000000000000000000000000000000000000000 Output red red cyan cyan cyan red Note In the first example, there is one rearrangement that yields a number divisible by 60, and that is 360. In the second example, there are two solutions. One is 060 and the second is 600. In the third example, there are 6 possible rearrangments: 025, 052, 205, 250, 502, 520. None of these numbers is divisible by 60. In the fourth example, there are 3 rearrangements: 228, 282, 822. In the fifth example, none of the 24 rearrangements result in a number divisible by 60. In the sixth example, note that 000...0 is a valid solution. Submitted Solution: ``` n=int(input()) for i in range(n): num=input() a=list(num) sum=0 b=set(a) flag1=True flag2=False if(len(list(set(a)))==1 and "0" in list(b)): print("red") else: if("0" not in a ): flag1=False for i in range(len(a)): sum=sum+int(a[i]) if(int(a[i])%2==0 and int(a[i])!=0): flag2=True if(sum%3==0 and flag1 and flag2): print("red") else: print("cyan") ```
instruction
0
51,446
20
102,892
No
output
1
51,446
20
102,893
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has sequence a consisting of n integers. The subsequence of the sequence a is such subsequence that can be obtained from a by removing zero or more of its elements. Two sequences are considered different if index sets of numbers included in them are different. That is, the values ​of the elements ​do not matter in the comparison of subsequences. In particular, any sequence of length n has exactly 2n different subsequences (including an empty subsequence). A subsequence is considered lucky if it has a length exactly k and does not contain two identical lucky numbers (unlucky numbers can be repeated any number of times). Help Petya find the number of different lucky subsequences of the sequence a. As Petya's parents don't let him play with large numbers, you should print the result modulo prime number 1000000007 (109 + 7). Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 105). The next line contains n integers ai (1 ≀ ai ≀ 109) β€” the sequence a. Output On the single line print the single number β€” the answer to the problem modulo prime number 1000000007 (109 + 7). Examples Input 3 2 10 10 10 Output 3 Input 4 2 4 4 7 7 Output 4 Note In the first sample all 3 subsequences of the needed length are considered lucky. In the second sample there are 4 lucky subsequences. For them the sets of indexes equal (the indexation starts from 1): {1, 3}, {1, 4}, {2, 3} and {2, 4}.
instruction
0
51,553
20
103,106
Tags: combinatorics, dp, math Correct Solution: ``` import sys input = sys.stdin.readline def solve(): n, k = map(int, input().split()) a = [4,7] d = dict() idx = 0 for p in range(1,10): for m in range(1<<p): v = 0 for i in range(p): v = v*10+a[(m >> i)&1] d[v] = idx idx += 1 #print(d) c = [0]*idx b = 0 for v in map(int, input().split()): if v in d: c[d[v]] += 1 else: b += 1 #print(c,b) dp = [[0]*(idx+1) for i in range(idx+1)] dp[0][0] = 1 MOD = int(1e9+7) for m in range(1,idx+1): dp[m][0] = dp[m-1][0] cc = c[m-1] for p in range(1,idx+1): dp[m][p] = (dp[m-1][p]+dp[m-1][p-1]*cc) % MOD res = 0 d = dp[idx] F = [0]*(max(idx,n)+2) FI = [0]*(max(idx,n)+2) F[0] = 1 for p in range(1,len(F)): F[p] = (F[p-1] * p) % MOD FI[-1] = pow(F[-1], MOD-2, MOD) for p in range(len(FI)-2,-1,-1): FI[p] = (FI[p+1] * (p+1)) % MOD #print(d) def C(n, k): if n < k: return 0 return (F[n]*FI[k]*FI[n-k])%MOD for p in range(0,idx+1): if b >= k - p and k - p >= 0: #print(b,k-p,b-k+p) res = (res + d[p]*F[b]*FI[k-p]*FI[b-k+p]) % MOD print(res) solve() ```
output
1
51,553
20
103,107
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has sequence a consisting of n integers. The subsequence of the sequence a is such subsequence that can be obtained from a by removing zero or more of its elements. Two sequences are considered different if index sets of numbers included in them are different. That is, the values ​of the elements ​do not matter in the comparison of subsequences. In particular, any sequence of length n has exactly 2n different subsequences (including an empty subsequence). A subsequence is considered lucky if it has a length exactly k and does not contain two identical lucky numbers (unlucky numbers can be repeated any number of times). Help Petya find the number of different lucky subsequences of the sequence a. As Petya's parents don't let him play with large numbers, you should print the result modulo prime number 1000000007 (109 + 7). Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 105). The next line contains n integers ai (1 ≀ ai ≀ 109) β€” the sequence a. Output On the single line print the single number β€” the answer to the problem modulo prime number 1000000007 (109 + 7). Examples Input 3 2 10 10 10 Output 3 Input 4 2 4 4 7 7 Output 4 Note In the first sample all 3 subsequences of the needed length are considered lucky. In the second sample there are 4 lucky subsequences. For them the sets of indexes equal (the indexation starts from 1): {1, 3}, {1, 4}, {2, 3} and {2, 4}.
instruction
0
51,554
20
103,108
Tags: combinatorics, dp, math Correct Solution: ``` import sys MOD = 10 ** 9 + 7 def is_lucky(n): n = str(n) return n.count('4') + n.count('7') == len(n) def get_inv(n): return pow(n, MOD - 2, MOD) def c(n, k): if n < k or k < 0: return 0 global fact, rfact return (fact[n] * rfact[k] * rfact[n - k]) % MOD fact = [1] rfact = [1] for i in range(1, 100500): fact.append((i * fact[-1]) % MOD) rfact.append((get_inv(i) * rfact[-1]) % MOD) n, k = map(int,sys.stdin.readline().split()) a = list(map(int,sys.stdin.readline().split())) d = dict() for x in a: if is_lucky(x): d[x] = d.get(x, 0) + 1 dp = [0]*(len(d)+2) dp[0] = 1 for x in d: for i in range(len(dp) - 1, 0, -1): dp[i] += dp[i - 1] * d[x] dp[i] %= MOD unlucky = n - sum(d.values()) ans = 0 for i in range(len(dp)): if k >= i: ans += dp[i] * c(unlucky, k - i) print(ans % MOD) ```
output
1
51,554
20
103,109
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has sequence a consisting of n integers. The subsequence of the sequence a is such subsequence that can be obtained from a by removing zero or more of its elements. Two sequences are considered different if index sets of numbers included in them are different. That is, the values ​of the elements ​do not matter in the comparison of subsequences. In particular, any sequence of length n has exactly 2n different subsequences (including an empty subsequence). A subsequence is considered lucky if it has a length exactly k and does not contain two identical lucky numbers (unlucky numbers can be repeated any number of times). Help Petya find the number of different lucky subsequences of the sequence a. As Petya's parents don't let him play with large numbers, you should print the result modulo prime number 1000000007 (109 + 7). Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 105). The next line contains n integers ai (1 ≀ ai ≀ 109) β€” the sequence a. Output On the single line print the single number β€” the answer to the problem modulo prime number 1000000007 (109 + 7). Examples Input 3 2 10 10 10 Output 3 Input 4 2 4 4 7 7 Output 4 Note In the first sample all 3 subsequences of the needed length are considered lucky. In the second sample there are 4 lucky subsequences. For them the sets of indexes equal (the indexation starts from 1): {1, 3}, {1, 4}, {2, 3} and {2, 4}.
instruction
0
51,555
20
103,110
Tags: combinatorics, dp, math Correct Solution: ``` MOD = 10 ** 9 + 7 def is_lucky(n): n = str(n) return n.count('4') + n.count('7') == len(n) def get_inv(n): return pow(n, MOD - 2, MOD) def c(n, k): if n < k or k < 0: return 0 global fact, rfact return (fact[n] * rfact[k] * rfact[n - k]) % MOD fact = [1] rfact = [1] for i in range(1, 100500): fact.append((i * fact[-1]) % MOD) rfact.append((get_inv(i) * rfact[-1]) % MOD) n, k = map(int, input().split()) a = list(map(int, input().split())) d = dict() for x in a: if is_lucky(x): d[x] = d.get(x, 0) + 1 dp = [0 for i in range(len(d) + 2)] dp[0] = 1 for x in d: for i in range(len(dp) - 1, 0, -1): dp[i] += dp[i - 1] * d[x] dp[i] %= MOD unlucky = n - sum(d.values()) ret = 0 for i in range(len(dp)): if k >= i: ret += dp[i] * c(unlucky, k - i) print(ret % MOD) ```
output
1
51,555
20
103,111
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has sequence a consisting of n integers. The subsequence of the sequence a is such subsequence that can be obtained from a by removing zero or more of its elements. Two sequences are considered different if index sets of numbers included in them are different. That is, the values ​of the elements ​do not matter in the comparison of subsequences. In particular, any sequence of length n has exactly 2n different subsequences (including an empty subsequence). A subsequence is considered lucky if it has a length exactly k and does not contain two identical lucky numbers (unlucky numbers can be repeated any number of times). Help Petya find the number of different lucky subsequences of the sequence a. As Petya's parents don't let him play with large numbers, you should print the result modulo prime number 1000000007 (109 + 7). Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 105). The next line contains n integers ai (1 ≀ ai ≀ 109) β€” the sequence a. Output On the single line print the single number β€” the answer to the problem modulo prime number 1000000007 (109 + 7). Examples Input 3 2 10 10 10 Output 3 Input 4 2 4 4 7 7 Output 4 Note In the first sample all 3 subsequences of the needed length are considered lucky. In the second sample there are 4 lucky subsequences. For them the sets of indexes equal (the indexation starts from 1): {1, 3}, {1, 4}, {2, 3} and {2, 4}.
instruction
0
51,556
20
103,112
Tags: combinatorics, dp, math Correct Solution: ``` import sys input = sys.stdin.readline def solve(): n, k = map(int, input().split()) a = [4,7] d = dict() idx = 0 for p in range(1,10): for m in range(1<<p): v = 0 for i in range(p): v = v*10+a[(m >> i)&1] d[v] = idx idx += 1 #print(d) c = [0]*idx b = 0 for v in map(int, input().split()): if v in d: c[d[v]] += 1 else: b += 1 #print(c,b) dp = [[0]*(idx+1) for i in range(idx+1)] dp[0][0] = 1 MOD = int(1e9+7) for m in range(1,idx+1): dp[m][0] = dp[m-1][0] cc = c[m-1] for p in range(1,idx+1): dp[m][p] = (dp[m-1][p]+dp[m-1][p-1]*cc) % MOD res = 0 d = dp[idx] F = [0]*(max(idx,n)+2) FI = [0]*(max(idx,n)+2) F[0] = 1 for p in range(1,len(F)): F[p] = (F[p-1] * p) % MOD FI[-1] = pow(F[-1], MOD-2, MOD) for p in range(len(FI)-2,-1,-1): FI[p] = (FI[p+1] * (p+1)) % MOD #print(d) def C(n, k): if n < k: return 0 return (F[n]*FI[k]*FI[n-k])%MOD for p in range(max(0,k-b),min(idx,k)+1): #if b >= k - p: #if p >= k - b res = (res + d[p]*F[b]*FI[k-p]*FI[b-k+p]) % MOD print(res) solve() ```
output
1
51,556
20
103,113
Provide tags and a correct Python 3 solution for this coding contest problem. The Department of economic development of IT City created a model of city development till year 2100. To prepare report about growth perspectives it is required to get growth estimates from the model. To get the growth estimates it is required to solve a quadratic equation. Since the Department of economic development of IT City creates realistic models only, that quadratic equation has a solution, moreover there are exactly two different real roots. The greater of these roots corresponds to the optimistic scenario, the smaller one corresponds to the pessimistic one. Help to get these estimates, first the optimistic, then the pessimistic one. Input The only line of the input contains three integers a, b, c ( - 1000 ≀ a, b, c ≀ 1000) β€” the coefficients of ax2 + bx + c = 0 equation. Output In the first line output the greater of the equation roots, in the second line output the smaller one. Absolute or relative error should not be greater than 10 - 6. Examples Input 1 30 200 Output -10.000000000000000 -20.000000000000000
instruction
0
51,745
20
103,490
Tags: math Correct Solution: ``` from math import sqrt a, b, c = input().split() a, b, c = float(a), float(b), float(c) rD = sqrt(b*b - 4*a*c) roots = ((-b+rD)/(2*a), (-b-rD)/(2*a)) print(max(roots)) print(min(roots)) ```
output
1
51,745
20
103,491
Provide tags and a correct Python 3 solution for this coding contest problem. Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String t is called a palindrome, if it reads the same from left to right and from right to left. For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes. You are given some integer number x. Check if it's a quasi-palindromic number. Input The first line contains one integer number x (1 ≀ x ≀ 109). This number is given without any leading zeroes. Output Print "YES" if number x is quasi-palindromic. Otherwise, print "NO" (without quotes). Examples Input 131 Output YES Input 320 Output NO Input 2010200 Output YES
instruction
0
51,826
20
103,652
Tags: brute force, implementation Correct Solution: ``` def pal_check(s): k = len(s) - 1 i = 0 while i < len(s): if s[i] != s[k]: return False else: i = i + 1 k = k - 1 return True a = input() if pal_check(a) is True: print("YES") else: d = 0 j = 0 l = len(a) - 1 while l > 0: if a[l] == "0": d = d + 1 l = l - 1 else: break l = 0 while l < len(a): if a[l] == "0": j = j + 1 l = l + 1 else: break while j < d: a = "0" + a j = j + 1 if pal_check(a) is True: print("YES") else: print("NO") ```
output
1
51,826
20
103,653
Provide tags and a correct Python 3 solution for this coding contest problem. Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String t is called a palindrome, if it reads the same from left to right and from right to left. For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes. You are given some integer number x. Check if it's a quasi-palindromic number. Input The first line contains one integer number x (1 ≀ x ≀ 109). This number is given without any leading zeroes. Output Print "YES" if number x is quasi-palindromic. Otherwise, print "NO" (without quotes). Examples Input 131 Output YES Input 320 Output NO Input 2010200 Output YES
instruction
0
51,827
20
103,654
Tags: brute force, implementation Correct Solution: ``` number = input() if number[-1] == "0": index = len(number) - 1 while number[index] == "0": index -= 1 number = number[0:index + 1] s = "" for i in range(0, len(number)): s = number[i] + s if s == number: print('YES') else: print('NO') ```
output
1
51,827
20
103,655
Provide tags and a correct Python 3 solution for this coding contest problem. Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String t is called a palindrome, if it reads the same from left to right and from right to left. For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes. You are given some integer number x. Check if it's a quasi-palindromic number. Input The first line contains one integer number x (1 ≀ x ≀ 109). This number is given without any leading zeroes. Output Print "YES" if number x is quasi-palindromic. Otherwise, print "NO" (without quotes). Examples Input 131 Output YES Input 320 Output NO Input 2010200 Output YES
instruction
0
51,828
20
103,656
Tags: brute force, implementation Correct Solution: ``` num = input() if str(int(num[::-1])) == str(int(num[::-1]))[::-1]: print('YES') else: print('NO') ```
output
1
51,828
20
103,657
Provide tags and a correct Python 3 solution for this coding contest problem. Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String t is called a palindrome, if it reads the same from left to right and from right to left. For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes. You are given some integer number x. Check if it's a quasi-palindromic number. Input The first line contains one integer number x (1 ≀ x ≀ 109). This number is given without any leading zeroes. Output Print "YES" if number x is quasi-palindromic. Otherwise, print "NO" (without quotes). Examples Input 131 Output YES Input 320 Output NO Input 2010200 Output YES
instruction
0
51,829
20
103,658
Tags: brute force, implementation Correct Solution: ``` st = input() ind1 = 0 ind2 = 0 l = len(st) for i in range(0,l): if st[i] != "0": ind1 = i break for i in range(l-1,-1,-1): if st[i] != "0": ind2 = i break st = st[ind1:ind2+1] st1 = st[::-1] if st == st1: print("YES") else: print("NO") ```
output
1
51,829
20
103,659
Provide tags and a correct Python 3 solution for this coding contest problem. Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String t is called a palindrome, if it reads the same from left to right and from right to left. For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes. You are given some integer number x. Check if it's a quasi-palindromic number. Input The first line contains one integer number x (1 ≀ x ≀ 109). This number is given without any leading zeroes. Output Print "YES" if number x is quasi-palindromic. Otherwise, print "NO" (without quotes). Examples Input 131 Output YES Input 320 Output NO Input 2010200 Output YES
instruction
0
51,830
20
103,660
Tags: brute force, implementation Correct Solution: ``` s=input() if s[-1]=="0": i=-1 while s[i]=="0": i-=1 s=s[0:i+1] fl=True for j in range(len(s)//2): if s[j]!=s[-j-1]: fl=False if fl: print('Yes') else: print('No') ```
output
1
51,830
20
103,661
Provide tags and a correct Python 3 solution for this coding contest problem. Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String t is called a palindrome, if it reads the same from left to right and from right to left. For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes. You are given some integer number x. Check if it's a quasi-palindromic number. Input The first line contains one integer number x (1 ≀ x ≀ 109). This number is given without any leading zeroes. Output Print "YES" if number x is quasi-palindromic. Otherwise, print "NO" (without quotes). Examples Input 131 Output YES Input 320 Output NO Input 2010200 Output YES
instruction
0
51,831
20
103,662
Tags: brute force, implementation Correct Solution: ``` import sys def is_Pol(str): return str == str[::-1] str = input() for i in range (1,20): if is_Pol(str): print("YES") sys.exit() str = '0' + str print("NO") ```
output
1
51,831
20
103,663
Provide tags and a correct Python 3 solution for this coding contest problem. Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String t is called a palindrome, if it reads the same from left to right and from right to left. For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes. You are given some integer number x. Check if it's a quasi-palindromic number. Input The first line contains one integer number x (1 ≀ x ≀ 109). This number is given without any leading zeroes. Output Print "YES" if number x is quasi-palindromic. Otherwise, print "NO" (without quotes). Examples Input 131 Output YES Input 320 Output NO Input 2010200 Output YES
instruction
0
51,832
20
103,664
Tags: brute force, implementation Correct Solution: ``` x = int(input()) while x%10==0: x = x//10 y = str (x) k = 0 for i in range (len(y)//2): if y[i]!=y[len(y)-i-1]: break else: k+=1 if k==len(y)//2: print ('YES') else: print ('NO') ```
output
1
51,832
20
103,665
Provide tags and a correct Python 3 solution for this coding contest problem. Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String t is called a palindrome, if it reads the same from left to right and from right to left. For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes. You are given some integer number x. Check if it's a quasi-palindromic number. Input The first line contains one integer number x (1 ≀ x ≀ 109). This number is given without any leading zeroes. Output Print "YES" if number x is quasi-palindromic. Otherwise, print "NO" (without quotes). Examples Input 131 Output YES Input 320 Output NO Input 2010200 Output YES
instruction
0
51,833
20
103,666
Tags: brute force, implementation Correct Solution: ``` def main(): s = input().rstrip('0') print(('NO', 'YES')[s == s[::-1]]) if __name__ == '__main__': main() ```
output
1
51,833
20
103,667
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String t is called a palindrome, if it reads the same from left to right and from right to left. For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes. You are given some integer number x. Check if it's a quasi-palindromic number. Input The first line contains one integer number x (1 ≀ x ≀ 109). This number is given without any leading zeroes. Output Print "YES" if number x is quasi-palindromic. Otherwise, print "NO" (without quotes). Examples Input 131 Output YES Input 320 Output NO Input 2010200 Output YES Submitted Solution: ``` import sys from collections import Counter #sys.stdin = open('input.in', 'r') #sys.stdout = open('output.out', 'w') s = input() s2 = s.strip('0') if s == s[::-1]: print('YES') elif s2 == s2[::-1]: print('YES') else: print('NO') ```
instruction
0
51,834
20
103,668
Yes
output
1
51,834
20
103,669
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String t is called a palindrome, if it reads the same from left to right and from right to left. For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes. You are given some integer number x. Check if it's a quasi-palindromic number. Input The first line contains one integer number x (1 ≀ x ≀ 109). This number is given without any leading zeroes. Output Print "YES" if number x is quasi-palindromic. Otherwise, print "NO" (without quotes). Examples Input 131 Output YES Input 320 Output NO Input 2010200 Output YES Submitted Solution: ``` string = input() i = 1 l = len(string) while string[-i] == '0' and i <= l: string = '0' + string i += 1 if string[::-1] == string : print('YES') else: print('NO') ```
instruction
0
51,835
20
103,670
Yes
output
1
51,835
20
103,671
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String t is called a palindrome, if it reads the same from left to right and from right to left. For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes. You are given some integer number x. Check if it's a quasi-palindromic number. Input The first line contains one integer number x (1 ≀ x ≀ 109). This number is given without any leading zeroes. Output Print "YES" if number x is quasi-palindromic. Otherwise, print "NO" (without quotes). Examples Input 131 Output YES Input 320 Output NO Input 2010200 Output YES Submitted Solution: ``` p = input() if p == p[::-1] or len(p) == 1: print("YES") else: if p[0] != p[len(p) - 1] and '0' not in [p[0], p[len(p) - 1]]: print("NO") else: cl, cr = '', '' for i in p: if i == '0': cl+='0' else: break for i in p[::-1]: if i == '0': cr+='0' else: break if cl == cr and p != p[::-1]: print("NO") else: if len(cl) > len(cr): p += ('0' * (len(cl) - len(cr))) if p == p[::-1]: print("YES") else: print("NO") else: p = ('0' * (len(cr) - len(cl))) + p if p == p[::-1]: print("YES") else: print("NO") ```
instruction
0
51,836
20
103,672
Yes
output
1
51,836
20
103,673
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String t is called a palindrome, if it reads the same from left to right and from right to left. For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes. You are given some integer number x. Check if it's a quasi-palindromic number. Input The first line contains one integer number x (1 ≀ x ≀ 109). This number is given without any leading zeroes. Output Print "YES" if number x is quasi-palindromic. Otherwise, print "NO" (without quotes). Examples Input 131 Output YES Input 320 Output NO Input 2010200 Output YES Submitted Solution: ``` a = input() a = int(a[::-1]) if str(a) == str(a)[::-1]: print("YES") else: print("NO") ```
instruction
0
51,837
20
103,674
Yes
output
1
51,837
20
103,675
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String t is called a palindrome, if it reads the same from left to right and from right to left. For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes. You are given some integer number x. Check if it's a quasi-palindromic number. Input The first line contains one integer number x (1 ≀ x ≀ 109). This number is given without any leading zeroes. Output Print "YES" if number x is quasi-palindromic. Otherwise, print "NO" (without quotes). Examples Input 131 Output YES Input 320 Output NO Input 2010200 Output YES Submitted Solution: ``` text = input().replace('0', '') fl = 0 rez = 1 for i in set(text): if text.count(i) % 2 == 1: if fl: rez = 0 break else: fl += 1 print('YES' if rez else 'NO') ```
instruction
0
51,838
20
103,676
No
output
1
51,838
20
103,677
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String t is called a palindrome, if it reads the same from left to right and from right to left. For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes. You are given some integer number x. Check if it's a quasi-palindromic number. Input The first line contains one integer number x (1 ≀ x ≀ 109). This number is given without any leading zeroes. Output Print "YES" if number x is quasi-palindromic. Otherwise, print "NO" (without quotes). Examples Input 131 Output YES Input 320 Output NO Input 2010200 Output YES Submitted Solution: ``` # http://codeforces.com/contest/863/problem/A s = str(input()) ans = "" for x in s: if x != "0": ans += x print("YES" if ans == ans[::-1] else "NO") ```
instruction
0
51,839
20
103,678
No
output
1
51,839
20
103,679
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String t is called a palindrome, if it reads the same from left to right and from right to left. For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes. You are given some integer number x. Check if it's a quasi-palindromic number. Input The first line contains one integer number x (1 ≀ x ≀ 109). This number is given without any leading zeroes. Output Print "YES" if number x is quasi-palindromic. Otherwise, print "NO" (without quotes). Examples Input 131 Output YES Input 320 Output NO Input 2010200 Output YES Submitted Solution: ``` x = int(input("Enter your number " ) ) temp = x opp = 0 while x > 0: m = x % 10 opp = opp*10 + m x = x //10 if temp == opp: print ("YES") else: print ("NO") ```
instruction
0
51,840
20
103,680
No
output
1
51,840
20
103,681
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String t is called a palindrome, if it reads the same from left to right and from right to left. For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes. You are given some integer number x. Check if it's a quasi-palindromic number. Input The first line contains one integer number x (1 ≀ x ≀ 109). This number is given without any leading zeroes. Output Print "YES" if number x is quasi-palindromic. Otherwise, print "NO" (without quotes). Examples Input 131 Output YES Input 320 Output NO Input 2010200 Output YES Submitted Solution: ``` n=int(input()) while n%10==0: n=n//10 ch=str(n) x=True for i in range(len(ch)//2): if ch[i]!=ch[-i-1]: x=False print("NO") if x: print("YES") ```
instruction
0
51,841
20
103,682
No
output
1
51,841
20
103,683
Provide tags and a correct Python 3 solution for this coding contest problem. Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit? Input The first line contains the only integer n (0 ≀ n ≀ 10100000). It is guaranteed that n doesn't contain any leading zeroes. Output Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. Examples Input 0 Output 0 Input 10 Output 1 Input 991 Output 3 Note In the first sample the number already is one-digit β€” Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 β†’ 19 β†’ 10 β†’ 1. After three transformations the number becomes one-digit.
instruction
0
52,186
20
104,372
Tags: implementation Correct Solution: ``` # a,b,c,d,e = map(int, input().split()) # sum=a+b+c+d+e # if (sum%5 == 0): # print(int(sum/5)) # else: # print(-1) sstr=input() if (len(sstr)==1): ans=0 else: ans=1 while (1): sum=0 for i in sstr: sum=sum+int(i)-int('0') if (sum<10): break else: ans+=1 sstr=str(sum) print(ans) ```
output
1
52,186
20
104,373
Provide tags and a correct Python 3 solution for this coding contest problem. Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit? Input The first line contains the only integer n (0 ≀ n ≀ 10100000). It is guaranteed that n doesn't contain any leading zeroes. Output Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. Examples Input 0 Output 0 Input 10 Output 1 Input 991 Output 3 Note In the first sample the number already is one-digit β€” Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 β†’ 19 β†’ 10 β†’ 1. After three transformations the number becomes one-digit.
instruction
0
52,187
20
104,374
Tags: implementation Correct Solution: ``` t=int(input()) def proB(n): ans=0 while(n>=10): lst=list(str(n)) n=0 for i in lst: n+=int(i) ans+=1 return ans print(proB(t)) ```
output
1
52,187
20
104,375
Provide tags and a correct Python 3 solution for this coding contest problem. Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit? Input The first line contains the only integer n (0 ≀ n ≀ 10100000). It is guaranteed that n doesn't contain any leading zeroes. Output Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. Examples Input 0 Output 0 Input 10 Output 1 Input 991 Output 3 Note In the first sample the number already is one-digit β€” Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 β†’ 19 β†’ 10 β†’ 1. After three transformations the number becomes one-digit.
instruction
0
52,188
20
104,376
Tags: implementation Correct Solution: ``` number = input() numtimes = 0 while len(number) > 1: sum = 0 for digit in number: sum += int(digit) numtimes += 1 number = str(sum) print(numtimes) ```
output
1
52,188
20
104,377
Provide tags and a correct Python 3 solution for this coding contest problem. Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit? Input The first line contains the only integer n (0 ≀ n ≀ 10100000). It is guaranteed that n doesn't contain any leading zeroes. Output Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. Examples Input 0 Output 0 Input 10 Output 1 Input 991 Output 3 Note In the first sample the number already is one-digit β€” Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 β†’ 19 β†’ 10 β†’ 1. After three transformations the number becomes one-digit.
instruction
0
52,189
20
104,378
Tags: implementation Correct Solution: ``` count=0 def c(s): global count count+=1 l=list(s) exp=0 for e in l: exp=exp+int(e) return str(exp) s=input() while(len(s)>1): s=c(s) print(count) ```
output
1
52,189
20
104,379
Provide tags and a correct Python 3 solution for this coding contest problem. Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit? Input The first line contains the only integer n (0 ≀ n ≀ 10100000). It is guaranteed that n doesn't contain any leading zeroes. Output Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. Examples Input 0 Output 0 Input 10 Output 1 Input 991 Output 3 Note In the first sample the number already is one-digit β€” Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 β†’ 19 β†’ 10 β†’ 1. After three transformations the number becomes one-digit.
instruction
0
52,190
20
104,380
Tags: implementation Correct Solution: ``` n=input() count =0 sum =0 while len(n) > 1: for i in n: sum+=int(i) count+=1 n=str(sum) sum=0 print(count) ```
output
1
52,190
20
104,381
Provide tags and a correct Python 3 solution for this coding contest problem. Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit? Input The first line contains the only integer n (0 ≀ n ≀ 10100000). It is guaranteed that n doesn't contain any leading zeroes. Output Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. Examples Input 0 Output 0 Input 10 Output 1 Input 991 Output 3 Note In the first sample the number already is one-digit β€” Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 β†’ 19 β†’ 10 β†’ 1. After three transformations the number becomes one-digit.
instruction
0
52,191
20
104,382
Tags: implementation Correct Solution: ``` n=input() s=0 while len(n)>1: n=str(sum(map(int,n))) s+=1 print(s) ```
output
1
52,191
20
104,383
Provide tags and a correct Python 3 solution for this coding contest problem. Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit? Input The first line contains the only integer n (0 ≀ n ≀ 10100000). It is guaranteed that n doesn't contain any leading zeroes. Output Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. Examples Input 0 Output 0 Input 10 Output 1 Input 991 Output 3 Note In the first sample the number already is one-digit β€” Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 β†’ 19 β†’ 10 β†’ 1. After three transformations the number becomes one-digit.
instruction
0
52,192
20
104,384
Tags: implementation Correct Solution: ``` s=input() p=0 while (len(s)>1): c=0 p+=1 for i in s: c+=int(i) s=str(c) print(p) ```
output
1
52,192
20
104,385
Provide tags and a correct Python 3 solution for this coding contest problem. Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit? Input The first line contains the only integer n (0 ≀ n ≀ 10100000). It is guaranteed that n doesn't contain any leading zeroes. Output Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. Examples Input 0 Output 0 Input 10 Output 1 Input 991 Output 3 Note In the first sample the number already is one-digit β€” Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 β†’ 19 β†’ 10 β†’ 1. After three transformations the number becomes one-digit.
instruction
0
52,193
20
104,386
Tags: implementation Correct Solution: ``` n = input() count = 0 size = len(n) while(size>1): sum = 0 for j in n: sum += int(j) count += 1 n = str(sum) size = len(n) print(count) ```
output
1
52,193
20
104,387
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit? Input The first line contains the only integer n (0 ≀ n ≀ 10100000). It is guaranteed that n doesn't contain any leading zeroes. Output Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. Examples Input 0 Output 0 Input 10 Output 1 Input 991 Output 3 Note In the first sample the number already is one-digit β€” Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 β†’ 19 β†’ 10 β†’ 1. After three transformations the number becomes one-digit. Submitted Solution: ``` n = input() rs = 0 while len(n) > 1: t = 0 for i in n: t += int(i) n = str(t) rs +=1 print(rs) ```
instruction
0
52,194
20
104,388
Yes
output
1
52,194
20
104,389
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit? Input The first line contains the only integer n (0 ≀ n ≀ 10100000). It is guaranteed that n doesn't contain any leading zeroes. Output Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. Examples Input 0 Output 0 Input 10 Output 1 Input 991 Output 3 Note In the first sample the number already is one-digit β€” Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 β†’ 19 β†’ 10 β†’ 1. After three transformations the number becomes one-digit. Submitted Solution: ``` n=int(input()) if 9 >= n >= 0: print("0") exit(0) ch=str(n) s=0 for i in range(len(ch)): s += int(ch[i]) j=0 while len(ch) > 1 : j += 1 ch = str(s) s = 0 for i in range(len(ch)): s += int(ch[i]) print(j) ```
instruction
0
52,195
20
104,390
Yes
output
1
52,195
20
104,391
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit? Input The first line contains the only integer n (0 ≀ n ≀ 10100000). It is guaranteed that n doesn't contain any leading zeroes. Output Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. Examples Input 0 Output 0 Input 10 Output 1 Input 991 Output 3 Note In the first sample the number already is one-digit β€” Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 β†’ 19 β†’ 10 β†’ 1. After three transformations the number becomes one-digit. Submitted Solution: ``` num = input() ans = 0 temp = 0 while len(num) > 1: for x in num: ans += int(x) num = str(ans) ans = 0 temp += 1 print(temp) ```
instruction
0
52,196
20
104,392
Yes
output
1
52,196
20
104,393
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit? Input The first line contains the only integer n (0 ≀ n ≀ 10100000). It is guaranteed that n doesn't contain any leading zeroes. Output Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. Examples Input 0 Output 0 Input 10 Output 1 Input 991 Output 3 Note In the first sample the number already is one-digit β€” Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 β†’ 19 β†’ 10 β†’ 1. After three transformations the number becomes one-digit. Submitted Solution: ``` # -*- coding: utf-8 -*- """ Created on Wed Mar 13 18:45:59 2019 @author: """ #num = float(input()) #suma = num #cont=0 #while suma > 9: # num = suma # suma = 0 # while num > 0: # suma+=num%10 # num=int(num/10) # cont+=1 #print(cont) def sumToString(num): sum = 0 for x in num: sum+=int(x) return sum numI = input() total = 0 while len(numI) > 1: numI = str(sumToString(numI)) total +=1 print(total) ```
instruction
0
52,197
20
104,394
Yes
output
1
52,197
20
104,395
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit? Input The first line contains the only integer n (0 ≀ n ≀ 10100000). It is guaranteed that n doesn't contain any leading zeroes. Output Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. Examples Input 0 Output 0 Input 10 Output 1 Input 991 Output 3 Note In the first sample the number already is one-digit β€” Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 β†’ 19 β†’ 10 β†’ 1. After three transformations the number becomes one-digit. Submitted Solution: ``` import math def solve(): n = int(input()) if n<10: return 0 while n%10==0: n=n/10 if n<10: return 1 return math.ceil(math.log(n)/math.log(10)) if __name__=="__main__": print(solve()) ```
instruction
0
52,198
20
104,396
No
output
1
52,198
20
104,397
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit? Input The first line contains the only integer n (0 ≀ n ≀ 10100000). It is guaranteed that n doesn't contain any leading zeroes. Output Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. Examples Input 0 Output 0 Input 10 Output 1 Input 991 Output 3 Note In the first sample the number already is one-digit β€” Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 β†’ 19 β†’ 10 β†’ 1. After three transformations the number becomes one-digit. Submitted Solution: ``` def magic_num(num): num = str(num) s = 0 for x in range(0,len(num)): s+=int(num[x]) if(s <= 9): return int(s) else: return magic_num(str(s)) def main(): i = input("enter num: ") print(magic_num(i)) main() ```
instruction
0
52,199
20
104,398
No
output
1
52,199
20
104,399
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit? Input The first line contains the only integer n (0 ≀ n ≀ 10100000). It is guaranteed that n doesn't contain any leading zeroes. Output Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. Examples Input 0 Output 0 Input 10 Output 1 Input 991 Output 3 Note In the first sample the number already is one-digit β€” Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 β†’ 19 β†’ 10 β†’ 1. After three transformations the number becomes one-digit. Submitted Solution: ``` #CF-B problem 12 def Sumofnum(num): summ = 0 for i in str(num): summ += int(i) return summ if len(str(summ))==1 else Sumofnum(summ) num = input() Sumofnum(num) ```
instruction
0
52,200
20
104,400
No
output
1
52,200
20
104,401
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit? Input The first line contains the only integer n (0 ≀ n ≀ 10100000). It is guaranteed that n doesn't contain any leading zeroes. Output Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. Examples Input 0 Output 0 Input 10 Output 1 Input 991 Output 3 Note In the first sample the number already is one-digit β€” Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 β†’ 19 β†’ 10 β†’ 1. After three transformations the number becomes one-digit. Submitted Solution: ``` x=str( input()) count=0 counted=0 for i in x: if i.isdigit(): counted=counted+ int(i) count+=1 finalcount=0 # if num contained less than 2 digit if (len(x)<2): print("0") elif(int(x)==10 or counted<10): print("1") else: # if the sum was more than 1 digit if( counted >10): while len(str(counted)) >1: temp =0 counted=str(counted) for i in counted: temp+=int (i) finalcount+=1 counted=temp print(finalcount+1) ```
instruction
0
52,201
20
104,402
No
output
1
52,201
20
104,403
Provide tags and a correct Python 3 solution for this coding contest problem. You wrote down all integers from 0 to 10^n - 1, padding them with leading zeroes so their lengths are exactly n. For example, if n = 3 then you wrote out 000, 001, ..., 998, 999. A block in an integer x is a consecutive segment of equal digits that cannot be extended to the left or to the right. For example, in the integer 00027734000 there are three blocks of length 1, one block of length 2 and two blocks of length 3. For all integers i from 1 to n count the number of blocks of length i among the written down integers. Since these integers may be too large, print them modulo 998244353. Input The only line contains one integer n (1 ≀ n ≀ 2 β‹… 10^5). Output In the only line print n integers. The i-th integer is equal to the number of blocks of length i. Since these integers may be too large, print them modulo 998244353. Examples Input 1 Output 10 Input 2 Output 180 10
instruction
0
52,376
20
104,752
Tags: combinatorics, dp, math Correct Solution: ``` import sys input=sys.stdin.readline inf = 1e10 mod = int(1e9 + 7) t=1; # t=int(input()) for _ in range(t): n=int(input()) modulo = 998244353 p=[1]*(n+1) for i in range(1, n): p[i] = (p[i-1]*10)%modulo for i in range(1, n): # total no of ways for 1length block for (n-i) size res = 2*10*9*p[n-i-1] res += 10*9*9*p[n-i-2]*(n-1-i) print(res%modulo, end=" ") print(10) ```
output
1
52,376
20
104,753
Provide tags and a correct Python 3 solution for this coding contest problem. You wrote down all integers from 0 to 10^n - 1, padding them with leading zeroes so their lengths are exactly n. For example, if n = 3 then you wrote out 000, 001, ..., 998, 999. A block in an integer x is a consecutive segment of equal digits that cannot be extended to the left or to the right. For example, in the integer 00027734000 there are three blocks of length 1, one block of length 2 and two blocks of length 3. For all integers i from 1 to n count the number of blocks of length i among the written down integers. Since these integers may be too large, print them modulo 998244353. Input The only line contains one integer n (1 ≀ n ≀ 2 β‹… 10^5). Output In the only line print n integers. The i-th integer is equal to the number of blocks of length i. Since these integers may be too large, print them modulo 998244353. Examples Input 1 Output 10 Input 2 Output 180 10
instruction
0
52,377
20
104,754
Tags: combinatorics, dp, math Correct Solution: ``` MOD = 998244353 n = int(input()) if n == 1: print(10) exit() a = [1] * (n-1) a[0] = 20 for i in range(1, n-1): a[i] *= (a[i-1] * 10) + (9 * (pow(10, i, MOD))) a[i] %= MOD a.reverse() for i in range(n-1): a[i] *= 9 a[i] %= MOD a.append(10) print(*a) ```
output
1
52,377
20
104,755
Provide tags and a correct Python 3 solution for this coding contest problem. You wrote down all integers from 0 to 10^n - 1, padding them with leading zeroes so their lengths are exactly n. For example, if n = 3 then you wrote out 000, 001, ..., 998, 999. A block in an integer x is a consecutive segment of equal digits that cannot be extended to the left or to the right. For example, in the integer 00027734000 there are three blocks of length 1, one block of length 2 and two blocks of length 3. For all integers i from 1 to n count the number of blocks of length i among the written down integers. Since these integers may be too large, print them modulo 998244353. Input The only line contains one integer n (1 ≀ n ≀ 2 β‹… 10^5). Output In the only line print n integers. The i-th integer is equal to the number of blocks of length i. Since these integers may be too large, print them modulo 998244353. Examples Input 1 Output 10 Input 2 Output 180 10
instruction
0
52,378
20
104,756
Tags: combinatorics, dp, math Correct Solution: ``` #Code by Sounak, IIESTS #------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase from fractions import Fraction from collections import defaultdict from itertools import permutations BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") #-------------------game starts now----------------------------------------------------- mod=998244353 n=int(input()) for i in range(n-1): sol=pow(10,n-i-2,mod) sol*=180+(n-i-2)*81 sol%=mod print(sol) print(10) ```
output
1
52,378
20
104,757
Provide tags and a correct Python 3 solution for this coding contest problem. You wrote down all integers from 0 to 10^n - 1, padding them with leading zeroes so their lengths are exactly n. For example, if n = 3 then you wrote out 000, 001, ..., 998, 999. A block in an integer x is a consecutive segment of equal digits that cannot be extended to the left or to the right. For example, in the integer 00027734000 there are three blocks of length 1, one block of length 2 and two blocks of length 3. For all integers i from 1 to n count the number of blocks of length i among the written down integers. Since these integers may be too large, print them modulo 998244353. Input The only line contains one integer n (1 ≀ n ≀ 2 β‹… 10^5). Output In the only line print n integers. The i-th integer is equal to the number of blocks of length i. Since these integers may be too large, print them modulo 998244353. Examples Input 1 Output 10 Input 2 Output 180 10
instruction
0
52,379
20
104,758
Tags: combinatorics, dp, math Correct Solution: ``` n = int(input()) # n is the number length modulo = 998244353 ten_powers = [1] for i in range(1, n): ten_powers.append(ten_powers[-1] * 10 % modulo) # ten_powers[i] equals 10**i % modulo for k in range(1, n+1): # k is the block size if n == k: ways = 10 elif n == k+1: ways = 180 # 2 * 9 * 10**(n-k) else: # n β‰₯ k+2 ways = ten_powers[n-k-1] * (180 + 9**2 * (n-k-1)) % modulo print(ways, end=" ", flush=False) print() ```
output
1
52,379
20
104,759
Provide tags and a correct Python 3 solution for this coding contest problem. You wrote down all integers from 0 to 10^n - 1, padding them with leading zeroes so their lengths are exactly n. For example, if n = 3 then you wrote out 000, 001, ..., 998, 999. A block in an integer x is a consecutive segment of equal digits that cannot be extended to the left or to the right. For example, in the integer 00027734000 there are three blocks of length 1, one block of length 2 and two blocks of length 3. For all integers i from 1 to n count the number of blocks of length i among the written down integers. Since these integers may be too large, print them modulo 998244353. Input The only line contains one integer n (1 ≀ n ≀ 2 β‹… 10^5). Output In the only line print n integers. The i-th integer is equal to the number of blocks of length i. Since these integers may be too large, print them modulo 998244353. Examples Input 1 Output 10 Input 2 Output 180 10
instruction
0
52,380
20
104,760
Tags: combinatorics, dp, math Correct Solution: ``` import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ sum1=10 currnum=0 ans=[10] mod=998244353 n=int(input()) for i in range(1,n): #print(sum1,10**(i+1)*(i+1)) currnum=(9*i+10)*pow(10,i,mod)-sum1 sum1+=currnum ans.append(currnum%mod) print(" ".join(str(x) for x in ans[::-1])) ```
output
1
52,380
20
104,761
Provide tags and a correct Python 3 solution for this coding contest problem. You wrote down all integers from 0 to 10^n - 1, padding them with leading zeroes so their lengths are exactly n. For example, if n = 3 then you wrote out 000, 001, ..., 998, 999. A block in an integer x is a consecutive segment of equal digits that cannot be extended to the left or to the right. For example, in the integer 00027734000 there are three blocks of length 1, one block of length 2 and two blocks of length 3. For all integers i from 1 to n count the number of blocks of length i among the written down integers. Since these integers may be too large, print them modulo 998244353. Input The only line contains one integer n (1 ≀ n ≀ 2 β‹… 10^5). Output In the only line print n integers. The i-th integer is equal to the number of blocks of length i. Since these integers may be too large, print them modulo 998244353. Examples Input 1 Output 10 Input 2 Output 180 10
instruction
0
52,381
20
104,762
Tags: combinatorics, dp, math Correct Solution: ``` n = int(input()) a = [10] s = 10 w = 10 m = 998244353 for i in range(2, n+1): e = (i*pow(10, i, m)%m - (w+s))%m s += e w += s s %= m w %= m a += [e] print(*a[::-1]) ```
output
1
52,381
20
104,763
Provide tags and a correct Python 3 solution for this coding contest problem. You wrote down all integers from 0 to 10^n - 1, padding them with leading zeroes so their lengths are exactly n. For example, if n = 3 then you wrote out 000, 001, ..., 998, 999. A block in an integer x is a consecutive segment of equal digits that cannot be extended to the left or to the right. For example, in the integer 00027734000 there are three blocks of length 1, one block of length 2 and two blocks of length 3. For all integers i from 1 to n count the number of blocks of length i among the written down integers. Since these integers may be too large, print them modulo 998244353. Input The only line contains one integer n (1 ≀ n ≀ 2 β‹… 10^5). Output In the only line print n integers. The i-th integer is equal to the number of blocks of length i. Since these integers may be too large, print them modulo 998244353. Examples Input 1 Output 10 Input 2 Output 180 10
instruction
0
52,382
20
104,764
Tags: combinatorics, dp, math Correct Solution: ``` l=[] for i in range(10): l.append(0) def f(n,x): n=str(n) n="0"*(x-len(n))+n+"#" prev=0 for i in range(1,len(n)): now=i if n[i]!=n[i-1]: l[now-prev]+=1 prev=now ans=[] ans.append(10) ans.append(180) diff=81 for i in range(200006): ans.append((ans[len(ans)-1]+diff)*10) ans[len(ans)-1]%=998244353 diff=diff*10 diff=diff%998244353 n=int(input()) ans2=ans[0:n][::-1] for i in range(n): print(ans2[i],end=" ") ```
output
1
52,382
20
104,765
Provide tags and a correct Python 3 solution for this coding contest problem. You wrote down all integers from 0 to 10^n - 1, padding them with leading zeroes so their lengths are exactly n. For example, if n = 3 then you wrote out 000, 001, ..., 998, 999. A block in an integer x is a consecutive segment of equal digits that cannot be extended to the left or to the right. For example, in the integer 00027734000 there are three blocks of length 1, one block of length 2 and two blocks of length 3. For all integers i from 1 to n count the number of blocks of length i among the written down integers. Since these integers may be too large, print them modulo 998244353. Input The only line contains one integer n (1 ≀ n ≀ 2 β‹… 10^5). Output In the only line print n integers. The i-th integer is equal to the number of blocks of length i. Since these integers may be too large, print them modulo 998244353. Examples Input 1 Output 10 Input 2 Output 180 10
instruction
0
52,383
20
104,766
Tags: combinatorics, dp, math Correct Solution: ``` def power(x, y, p): res = 1 # Initialize result # Update x if it is more # than or equal to p x = x % p while (y > 0): # If y is odd, multiply # x with result if ((y & 1) == 1): res = (res * x) % p # y must be even now y = y >> 1 # y = y/2 x = (x * x) % p return res n=int(input()) j=1 a=[] while(j<=(n-2)): k=power(10,(n-1-j),998244353) a.append((((n-j-1)*81+(180))*k)%998244353) j+=1 if n>=2: a.append(180) if n>=1: a.append(10) print(*a) ```
output
1
52,383
20
104,767
Provide tags and a correct Python 3 solution for this coding contest problem. Nezzar's favorite digit among 1,…,9 is d. He calls a positive integer lucky if d occurs at least once in its decimal representation. Given q integers a_1,a_2,…,a_q, for each 1 ≀ i ≀ q Nezzar would like to know if a_i can be equal to a sum of several (one or more) lucky numbers. Input The first line contains a single integer t (1 ≀ t ≀ 9) β€” the number of test cases. The first line of each test case contains two integers q and d (1 ≀ q ≀ 10^4, 1 ≀ d ≀ 9). The second line of each test case contains q integers a_1,a_2,…,a_q (1 ≀ a_i ≀ 10^9). Output For each integer in each test case, print "YES" in a single line if a_i can be equal to a sum of lucky numbers. Otherwise, print "NO". You can print letters in any case (upper or lower). Example Input 2 3 7 24 25 27 10 7 51 52 53 54 55 56 57 58 59 60 Output YES NO YES YES YES NO YES YES YES YES YES YES NO Note In the first test case, 24 = 17 + 7, 27 itself is a lucky number, 25 cannot be equal to a sum of lucky numbers.
instruction
0
52,439
20
104,878
Tags: brute force, dp, greedy, math Correct Solution: ``` for _ in range(int(input())): n,d = list(map(int,input().split())) l = list(map(int,input().split())) for i in l : vb = i vb%=d cant = False while True : if vb == 0 : break vb += d if vb > i : cant = True break if str(d) in str(vb) : break if not cant : print("YES") else: print("NO") ```
output
1
52,439
20
104,879
Provide tags and a correct Python 3 solution for this coding contest problem. Nezzar's favorite digit among 1,…,9 is d. He calls a positive integer lucky if d occurs at least once in its decimal representation. Given q integers a_1,a_2,…,a_q, for each 1 ≀ i ≀ q Nezzar would like to know if a_i can be equal to a sum of several (one or more) lucky numbers. Input The first line contains a single integer t (1 ≀ t ≀ 9) β€” the number of test cases. The first line of each test case contains two integers q and d (1 ≀ q ≀ 10^4, 1 ≀ d ≀ 9). The second line of each test case contains q integers a_1,a_2,…,a_q (1 ≀ a_i ≀ 10^9). Output For each integer in each test case, print "YES" in a single line if a_i can be equal to a sum of lucky numbers. Otherwise, print "NO". You can print letters in any case (upper or lower). Example Input 2 3 7 24 25 27 10 7 51 52 53 54 55 56 57 58 59 60 Output YES NO YES YES YES NO YES YES YES YES YES YES NO Note In the first test case, 24 = 17 + 7, 27 itself is a lucky number, 25 cannot be equal to a sum of lucky numbers.
instruction
0
52,440
20
104,880
Tags: brute force, dp, greedy, math Correct Solution: ``` t = int(input()) for _ in range(t): q, d = [int(x) for x in input().split()] l = [int(x) for x in input().split()] poss = [False]*1001 for i in range(1001): if str(d) in str(i): poss[i] = True for i in range(110): if poss[i]: for j in range(110): if poss[j] and i + j <= 110: poss[i+j] = True for query in l: if query > 110 or poss[query]: print("YES") else: print("NO") ```
output
1
52,440
20
104,881
Provide tags and a correct Python 3 solution for this coding contest problem. Nezzar's favorite digit among 1,…,9 is d. He calls a positive integer lucky if d occurs at least once in its decimal representation. Given q integers a_1,a_2,…,a_q, for each 1 ≀ i ≀ q Nezzar would like to know if a_i can be equal to a sum of several (one or more) lucky numbers. Input The first line contains a single integer t (1 ≀ t ≀ 9) β€” the number of test cases. The first line of each test case contains two integers q and d (1 ≀ q ≀ 10^4, 1 ≀ d ≀ 9). The second line of each test case contains q integers a_1,a_2,…,a_q (1 ≀ a_i ≀ 10^9). Output For each integer in each test case, print "YES" in a single line if a_i can be equal to a sum of lucky numbers. Otherwise, print "NO". You can print letters in any case (upper or lower). Example Input 2 3 7 24 25 27 10 7 51 52 53 54 55 56 57 58 59 60 Output YES NO YES YES YES NO YES YES YES YES YES YES NO Note In the first test case, 24 = 17 + 7, 27 itself is a lucky number, 25 cannot be equal to a sum of lucky numbers.
instruction
0
52,441
20
104,882
Tags: brute force, dp, greedy, math Correct Solution: ``` for _ in range(int(input())): t,d=map(int,input().split()) for n in list(map(int,input().split())): flag=False while n>=0: if str(d) in str(n):flag=True;break # print(n) n-=d if flag:print("YES") else:print("NO") ```
output
1
52,441
20
104,883