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. Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm: * if the last digit of the number is non-zero, she decreases the number by one; * if the last digit of the number is zero, she divides the number by 10 (i.e. removes the last digit). You are given an integer number n. Tanya will subtract one from it k times. Your task is to print the result after all k subtractions. It is guaranteed that the result will be positive integer number. Input The first line of the input contains two integer numbers n and k (2 ≤ n ≤ 10^9, 1 ≤ k ≤ 50) — the number from which Tanya will subtract and the number of subtractions correspondingly. Output Print one integer number — the result of the decreasing n by one k times. It is guaranteed that the result will be positive integer number. Examples Input 512 4 Output 50 Input 1000000000 9 Output 1 Note The first example corresponds to the following sequence: 512 → 511 → 510 → 51 → 50. Submitted Solution: ``` #main program x = input("Enter first number & constant: ") nums = [int(n) for n in x.split()] y = 0 while (y < nums[1]): if (nums[0]%10 != 0): nums[0] = nums[0] - 1 y += 1 elif(nums[0]%10 == 0): nums[0] = nums[0]/10 y += 1 else: continue print (int(nums[0])) ```
instruction
0
27,125
20
54,250
No
output
1
27,125
20
54,251
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm: * if the last digit of the number is non-zero, she decreases the number by one; * if the last digit of the number is zero, she divides the number by 10 (i.e. removes the last digit). You are given an integer number n. Tanya will subtract one from it k times. Your task is to print the result after all k subtractions. It is guaranteed that the result will be positive integer number. Input The first line of the input contains two integer numbers n and k (2 ≤ n ≤ 10^9, 1 ≤ k ≤ 50) — the number from which Tanya will subtract and the number of subtractions correspondingly. Output Print one integer number — the result of the decreasing n by one k times. It is guaranteed that the result will be positive integer number. Examples Input 512 4 Output 50 Input 1000000000 9 Output 1 Note The first example corresponds to the following sequence: 512 → 511 → 510 → 51 → 50. Submitted Solution: ``` x=input().split() n=int(x[0]) k=int(x[1]) for i in range(k): if n%10==0: n=n/10 else: n=n-1 print(n) ```
instruction
0
27,126
20
54,252
No
output
1
27,126
20
54,253
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm: * if the last digit of the number is non-zero, she decreases the number by one; * if the last digit of the number is zero, she divides the number by 10 (i.e. removes the last digit). You are given an integer number n. Tanya will subtract one from it k times. Your task is to print the result after all k subtractions. It is guaranteed that the result will be positive integer number. Input The first line of the input contains two integer numbers n and k (2 ≤ n ≤ 10^9, 1 ≤ k ≤ 50) — the number from which Tanya will subtract and the number of subtractions correspondingly. Output Print one integer number — the result of the decreasing n by one k times. It is guaranteed that the result will be positive integer number. Examples Input 512 4 Output 50 Input 1000000000 9 Output 1 Note The first example corresponds to the following sequence: 512 → 511 → 510 → 51 → 50. Submitted Solution: ``` n, k = map(int, input().split()) while k: if not n%10: k -= 1 n //= 10 elif n%10 < k: k -= n%10 n -= n%10 else: n -= k print(n) ```
instruction
0
27,127
20
54,254
No
output
1
27,127
20
54,255
Provide a correct Python 3 solution for this coding contest problem. An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number. Constraints * 1?N?10^8 * N is an integer. Input Input is given from Standard Input in the following format: N Output Print `Yes` if N is a Harshad number; print `No` otherwise. Examples Input 12 Output Yes Input 57 Output No Input 148 Output No
instruction
0
27,234
20
54,468
"Correct Solution: ``` N=input() S=list(map(int,N)) X=sum(S) print('Yes' if int(N)%X==0 else 'No') ```
output
1
27,234
20
54,469
Provide a correct Python 3 solution for this coding contest problem. An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number. Constraints * 1?N?10^8 * N is an integer. Input Input is given from Standard Input in the following format: N Output Print `Yes` if N is a Harshad number; print `No` otherwise. Examples Input 12 Output Yes Input 57 Output No Input 148 Output No
instruction
0
27,235
20
54,470
"Correct Solution: ``` n=input() print('No' if int(n)%sum(map(int,n)) else 'Yes') ```
output
1
27,235
20
54,471
Provide a correct Python 3 solution for this coding contest problem. An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number. Constraints * 1?N?10^8 * N is an integer. Input Input is given from Standard Input in the following format: N Output Print `Yes` if N is a Harshad number; print `No` otherwise. Examples Input 12 Output Yes Input 57 Output No Input 148 Output No
instruction
0
27,236
20
54,472
"Correct Solution: ``` s = input() l = [int(a) for a in s] print(["No", "Yes"][int(s) % sum(l) == 0]) ```
output
1
27,236
20
54,473
Provide a correct Python 3 solution for this coding contest problem. An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number. Constraints * 1?N?10^8 * N is an integer. Input Input is given from Standard Input in the following format: N Output Print `Yes` if N is a Harshad number; print `No` otherwise. Examples Input 12 Output Yes Input 57 Output No Input 148 Output No
instruction
0
27,237
20
54,474
"Correct Solution: ``` s=input();print('YNeos'[int(s)%eval('+'.join(s))>0::2]) ```
output
1
27,237
20
54,475
Provide a correct Python 3 solution for this coding contest problem. An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number. Constraints * 1?N?10^8 * N is an integer. Input Input is given from Standard Input in the following format: N Output Print `Yes` if N is a Harshad number; print `No` otherwise. Examples Input 12 Output Yes Input 57 Output No Input 148 Output No
instruction
0
27,238
20
54,476
"Correct Solution: ``` N = input() if int(N)%sum(int(i) for i in N): print('No') else: print('Yes') ```
output
1
27,238
20
54,477
Provide a correct Python 3 solution for this coding contest problem. An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number. Constraints * 1?N?10^8 * N is an integer. Input Input is given from Standard Input in the following format: N Output Print `Yes` if N is a Harshad number; print `No` otherwise. Examples Input 12 Output Yes Input 57 Output No Input 148 Output No
instruction
0
27,239
20
54,478
"Correct Solution: ``` N=input() print("Yes" if int(N)%sum(int(i) for i in N)==0 else "No") ```
output
1
27,239
20
54,479
Provide a correct Python 3 solution for this coding contest problem. An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number. Constraints * 1?N?10^8 * N is an integer. Input Input is given from Standard Input in the following format: N Output Print `Yes` if N is a Harshad number; print `No` otherwise. Examples Input 12 Output Yes Input 57 Output No Input 148 Output No
instruction
0
27,240
20
54,480
"Correct Solution: ``` n = input() print(['No', 'Yes'][int(int(n) % sum([int(x) for x in n]) == 0)]) ```
output
1
27,240
20
54,481
Provide a correct Python 3 solution for this coding contest problem. An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number. Constraints * 1?N?10^8 * N is an integer. Input Input is given from Standard Input in the following format: N Output Print `Yes` if N is a Harshad number; print `No` otherwise. Examples Input 12 Output Yes Input 57 Output No Input 148 Output No
instruction
0
27,241
20
54,482
"Correct Solution: ``` N = input() print('No' if int(N)%sum(map(int, N)) else 'Yes') ```
output
1
27,241
20
54,483
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number. Constraints * 1?N?10^8 * N is an integer. Input Input is given from Standard Input in the following format: N Output Print `Yes` if N is a Harshad number; print `No` otherwise. Examples Input 12 Output Yes Input 57 Output No Input 148 Output No Submitted Solution: ``` n=int(input()) a=sum(int(i) for i in list(str(n))) print('YNeos'[n%a!=0::2]) ```
instruction
0
27,242
20
54,484
Yes
output
1
27,242
20
54,485
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number. Constraints * 1?N?10^8 * N is an integer. Input Input is given from Standard Input in the following format: N Output Print `Yes` if N is a Harshad number; print `No` otherwise. Examples Input 12 Output Yes Input 57 Output No Input 148 Output No Submitted Solution: ``` x = input() fx = sum(map(int, x)) print("Yes" if int(x) % fx == 0 else "No") ```
instruction
0
27,243
20
54,486
Yes
output
1
27,243
20
54,487
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number. Constraints * 1?N?10^8 * N is an integer. Input Input is given from Standard Input in the following format: N Output Print `Yes` if N is a Harshad number; print `No` otherwise. Examples Input 12 Output Yes Input 57 Output No Input 148 Output No Submitted Solution: ``` s=input();print("YNeos"[int(s)%sum(map(int,s))!=0::2]) ```
instruction
0
27,244
20
54,488
Yes
output
1
27,244
20
54,489
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number. Constraints * 1?N?10^8 * N is an integer. Input Input is given from Standard Input in the following format: N Output Print `Yes` if N is a Harshad number; print `No` otherwise. Examples Input 12 Output Yes Input 57 Output No Input 148 Output No Submitted Solution: ``` x=input() a=[int(c)for c in x] print('Yes'if int(x)%sum(a)==0else 'No') ```
instruction
0
27,245
20
54,490
Yes
output
1
27,245
20
54,491
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number. Constraints * 1?N?10^8 * N is an integer. Input Input is given from Standard Input in the following format: N Output Print `Yes` if N is a Harshad number; print `No` otherwise. Examples Input 12 Output Yes Input 57 Output No Input 148 Output No Submitted Solution: ``` n=input() a=[] for i in range(len(n)): a.append(int(s[i])) print("Yes" if int(n)%sum(a)==0 else "No") ```
instruction
0
27,246
20
54,492
No
output
1
27,246
20
54,493
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number. Constraints * 1?N?10^8 * N is an integer. Input Input is given from Standard Input in the following format: N Output Print `Yes` if N is a Harshad number; print `No` otherwise. Examples Input 12 Output Yes Input 57 Output No Input 148 Output No Submitted Solution: ``` N = input() sum = 0 for i in N: sum += i if N % sum == 0: print("Yes") else: print("No") ```
instruction
0
27,247
20
54,494
No
output
1
27,247
20
54,495
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number. Constraints * 1?N?10^8 * N is an integer. Input Input is given from Standard Input in the following format: N Output Print `Yes` if N is a Harshad number; print `No` otherwise. Examples Input 12 Output Yes Input 57 Output No Input 148 Output No Submitted Solution: ``` n=map(int,input()) print('Yes' if sum(n)%n==0 else 'No') ```
instruction
0
27,248
20
54,496
No
output
1
27,248
20
54,497
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number. Constraints * 1?N?10^8 * N is an integer. Input Input is given from Standard Input in the following format: N Output Print `Yes` if N is a Harshad number; print `No` otherwise. Examples Input 12 Output Yes Input 57 Output No Input 148 Output No Submitted Solution: ``` n = int(input()) f_x=0 for i in range(len(n)): f_x+=int(n[i]) if int(n)%f_n==0: print('Yes') else: print('No') ```
instruction
0
27,249
20
54,498
No
output
1
27,249
20
54,499
Provide a correct Python 3 solution for this coding contest problem. At University A, there were many mistakes in entering IDs. Therefore, University A decided to issue a new ID to prevent typos. There is a way to check if the new ID is correct to prevent typos. ・ Calculate the sum of all digits. ・ However, the number of even-numbered digits is doubled, with the rightmost digit as the first digit. -When the number becomes 10 or more by doubling, the number obtained by adding the 1st digit and the 10th digit is used as the digit number. ・ If the sum is divisible by 10, the ID is correct, otherwise it is incorrect. As an example, check the ID 53579. Since the sum of all digits is calculated, 5 + 3 + 5 + 7 + 9 However, since the number of even-numbered digits is doubled, 5 + 6 + 5 + 14 + 9 When the number becomes 10 or more by doubling, the number obtained by adding the ones digit and the tens digit is the digit number. 5 + 6 + 5 + (1 + 4) + 9 From the above, the total sum is 30. Since 30 is divisible by 10, 53579 is the correct ID. Mr. B is a college student at University A and was issued a new ID, but he forgot some digits of the ID. However, I succeeded in narrowing down some candidates as to what kind of numbers will be included in the forgotten part. Your job is to find out how many correct combinations of B's ​​IDs are available. Input The input is given in the following format. n ID m a0 a1 ... am-1 n is the number of digits in the ID. Each digit of the ID contains a number from 0 to 9 or the letter'*' to indicate that it is a forgotten digit. m is the number of candidate numbers in the'*'. ai is a candidate for numbers in'*'. Input meets the following constraints 1 ≤ n ≤ 100,000 1 ≤ m ≤ 10 0 ≤ ai ≤ 9 Number of 1 ≤'*' ≤ 7 Output Output the answer value on one line Examples Input 5 5*57* 2 3 9 Output 1 Input 15 2***9*2*6*1199* 9 0 1 2 3 4 6 7 8 9 Output 478297
instruction
0
27,343
20
54,686
"Correct Solution: ``` import itertools n = int(input()) id = input()[::-1] count = 0 a = [] odd, even = 0 , 0 tmp = 0 for i in range(1,n+1): if id[i-1] == "*": if i % 2: odd += 1 else: even += 1 elif i % 2 == 0: x = int(id[i-1]) if x >= 5: tmp += (x * 2 - 9) else: tmp += (x * 2) else: tmp += (int(id[i-1])) m = int(input()) data = list(map(int, input().split())) def sum2(ls): ans = 0 for k in ls: if k >= 5: ans += (k * 2 - 9) else: ans += (k * 2) return ans odd_list = list(map(lambda x: (sum(x) % 10),list(itertools.product(data, repeat=odd)))) even_list = list(map(lambda x: ((sum2(x)) % 10),list(itertools.product(data, repeat=even)))) odd_mod = [odd_list.count(i) for i in range(10)] even_mod = [even_list.count(i) for i in range(10)] for i in range(10): for j in range(10): if ((i + j + tmp) % 10) == 0: count += odd_mod[i] * even_mod[j] print(count) ```
output
1
27,343
20
54,687
Provide a correct Python 3 solution for this coding contest problem. At University A, there were many mistakes in entering IDs. Therefore, University A decided to issue a new ID to prevent typos. There is a way to check if the new ID is correct to prevent typos. ・ Calculate the sum of all digits. ・ However, the number of even-numbered digits is doubled, with the rightmost digit as the first digit. -When the number becomes 10 or more by doubling, the number obtained by adding the 1st digit and the 10th digit is used as the digit number. ・ If the sum is divisible by 10, the ID is correct, otherwise it is incorrect. As an example, check the ID 53579. Since the sum of all digits is calculated, 5 + 3 + 5 + 7 + 9 However, since the number of even-numbered digits is doubled, 5 + 6 + 5 + 14 + 9 When the number becomes 10 or more by doubling, the number obtained by adding the ones digit and the tens digit is the digit number. 5 + 6 + 5 + (1 + 4) + 9 From the above, the total sum is 30. Since 30 is divisible by 10, 53579 is the correct ID. Mr. B is a college student at University A and was issued a new ID, but he forgot some digits of the ID. However, I succeeded in narrowing down some candidates as to what kind of numbers will be included in the forgotten part. Your job is to find out how many correct combinations of B's ​​IDs are available. Input The input is given in the following format. n ID m a0 a1 ... am-1 n is the number of digits in the ID. Each digit of the ID contains a number from 0 to 9 or the letter'*' to indicate that it is a forgotten digit. m is the number of candidate numbers in the'*'. ai is a candidate for numbers in'*'. Input meets the following constraints 1 ≤ n ≤ 100,000 1 ≤ m ≤ 10 0 ≤ ai ≤ 9 Number of 1 ≤'*' ≤ 7 Output Output the answer value on one line Examples Input 5 5*57* 2 3 9 Output 1 Input 15 2***9*2*6*1199* 9 0 1 2 3 4 6 7 8 9 Output 478297
instruction
0
27,344
20
54,688
"Correct Solution: ``` n = int(input()) ID = input()[::-1] m = int(input()) a_lst = list(map(int, input().split())) dp = [[0] * 10 for _ in range(n + 1)] dp[0][0] = 1 def fix(a): if a < 10:return a return a % 10 + a // 10 for i in range(n): c = ID[i] mag = 1 if i % 2 == 0 else 2 for j in range(10): if c == "*": for a in a_lst: a = fix(a * mag) dp[i + 1][(j + a) % 10] += dp[i][j] else: a = fix(int(c) * mag) dp[i + 1][(j + a) % 10] += dp[i][j] print(dp[n][0]) ```
output
1
27,344
20
54,689
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. At University A, there were many mistakes in entering IDs. Therefore, University A decided to issue a new ID to prevent typos. There is a way to check if the new ID is correct to prevent typos. ・ Calculate the sum of all digits. ・ However, the number of even-numbered digits is doubled, with the rightmost digit as the first digit. -When the number becomes 10 or more by doubling, the number obtained by adding the 1st digit and the 10th digit is used as the digit number. ・ If the sum is divisible by 10, the ID is correct, otherwise it is incorrect. As an example, check the ID 53579. Since the sum of all digits is calculated, 5 + 3 + 5 + 7 + 9 However, since the number of even-numbered digits is doubled, 5 + 6 + 5 + 14 + 9 When the number becomes 10 or more by doubling, the number obtained by adding the ones digit and the tens digit is the digit number. 5 + 6 + 5 + (1 + 4) + 9 From the above, the total sum is 30. Since 30 is divisible by 10, 53579 is the correct ID. Mr. B is a college student at University A and was issued a new ID, but he forgot some digits of the ID. However, I succeeded in narrowing down some candidates as to what kind of numbers will be included in the forgotten part. Your job is to find out how many correct combinations of B's ​​IDs are available. Input The input is given in the following format. n ID m a0 a1 ... am-1 n is the number of digits in the ID. Each digit of the ID contains a number from 0 to 9 or the letter'*' to indicate that it is a forgotten digit. m is the number of candidate numbers in the'*'. ai is a candidate for numbers in'*'. Input meets the following constraints 1 ≤ n ≤ 100,000 1 ≤ m ≤ 10 0 ≤ ai ≤ 9 Number of 1 ≤'*' ≤ 7 Output Output the answer value on one line Examples Input 5 5*57* 2 3 9 Output 1 Input 15 2***9*2*6*1199* 9 0 1 2 3 4 6 7 8 9 Output 478297 Submitted Solution: ``` # Edit: 2014/09/07 # Lang: Python3 # Time: s from itertools import product def judge(n, id): sum = 0 for i in range(1, n + 1): # print(id[-i]) if i % 2 == 0: s = int(id[-i]) * 2 if s > 10: s = s % 10 + 1 sum += s else: sum += int(id[-i]) #print(sum, sum % 10) if sum % 10: return False else: return True if __name__ == "__main__": n = int(input()) ID = list(input()) m = int(input()) alist = list(map(int, input().strip("\n").split(" "))) # print("n :", n) #print("ID :", ID) #print("m :", m) #print("alist:", alist) # id = 12345 # print(judge(len(str(id)), str(id))) # id = 53579 # print(judge(len(str(id)), str(id))) ast = [] # *の位置を検出 for i in range(n): if ID[i] == "*": ast.append(i) #print("ast", ast) #ID[0] = "3" #print("ID[0]",ID[0]) """ for x, y in product(alist, repeat=len(ast)): print(x, y) ID[int(ast[0])] = str(x) ID[int(ast[1])] = str(y) print(ID) print(judge(n, ID)) """ ilist = [] nTrue = 0 for ilist in product(alist, repeat=len(ast)): #print(ilist) for iast in range(len(ast)): ID[ast[iast]] = ilist[iast] #print("ID",ID) #for v in ast: # ID[v] = *** #from alist nTrue += judge(n, ID) print(nTrue) pass # ```
instruction
0
27,345
20
54,690
No
output
1
27,345
20
54,691
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. At University A, there were many mistakes in entering IDs. Therefore, University A decided to issue a new ID to prevent typos. There is a way to check if the new ID is correct to prevent typos. ・ Calculate the sum of all digits. ・ However, the number of even-numbered digits is doubled, with the rightmost digit as the first digit. -When the number becomes 10 or more by doubling, the number obtained by adding the 1st digit and the 10th digit is used as the digit number. ・ If the sum is divisible by 10, the ID is correct, otherwise it is incorrect. As an example, check the ID 53579. Since the sum of all digits is calculated, 5 + 3 + 5 + 7 + 9 However, since the number of even-numbered digits is doubled, 5 + 6 + 5 + 14 + 9 When the number becomes 10 or more by doubling, the number obtained by adding the ones digit and the tens digit is the digit number. 5 + 6 + 5 + (1 + 4) + 9 From the above, the total sum is 30. Since 30 is divisible by 10, 53579 is the correct ID. Mr. B is a college student at University A and was issued a new ID, but he forgot some digits of the ID. However, I succeeded in narrowing down some candidates as to what kind of numbers will be included in the forgotten part. Your job is to find out how many correct combinations of B's ​​IDs are available. Input The input is given in the following format. n ID m a0 a1 ... am-1 n is the number of digits in the ID. Each digit of the ID contains a number from 0 to 9 or the letter'*' to indicate that it is a forgotten digit. m is the number of candidate numbers in the'*'. ai is a candidate for numbers in'*'. Input meets the following constraints 1 ≤ n ≤ 100,000 1 ≤ m ≤ 10 0 ≤ ai ≤ 9 Number of 1 ≤'*' ≤ 7 Output Output the answer value on one line Examples Input 5 5*57* 2 3 9 Output 1 Input 15 2***9*2*6*1199* 9 0 1 2 3 4 6 7 8 9 Output 478297 Submitted Solution: ``` import itertools n = int(input()) id = input()[::-1] count = 0 a = [] odd, even = 0 , 0 tmp = 0 for i in range(1,n+1): if id[i-1] == "*": if i % 2: odd += 1 else: even += 1 continue if i % 2: x = int(id[i-1]) if x >= 5: tmp += (int(id[i-1]) * 2 - 9) continue tmp += (int(id[i-1]) * 2 - 9) tmp += (int(id[i-1])) m = int(input()) data = list(map(int, input().split())) def sum2(ls): ans = 0 for k in ls: if k >= 5: ans += (k * 2 - 9) else: ans += (k * 2) return ans odd_list = list(map(lambda x: (sum(x) % 10),list(itertools.product(data, repeat=odd)))) even_list = list(map(lambda x: ((sum2(x)) % 10),list(itertools.product(data, repeat=even)))) odd_mod = [odd_list.count(i) for i in range(10)] even_mod = [even_list.count(i) for i in range(10)] for i in range(10): for j in range(10): if ((i + j + tmp) % 10) == 0: count += odd_mod[i] * even_mod[j] print(count) ```
instruction
0
27,346
20
54,692
No
output
1
27,346
20
54,693
Provide tags and a correct Python 3 solution for this coding contest problem. Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15. <image> The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105. Help the Little Elephant, restore the original magic square, given the Elephant's notes. Input The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes. It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105. Output Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105. It is guaranteed that there exists at least one magic square that meets the conditions. Examples Input 0 1 1 1 0 1 1 1 0 Output 1 1 1 1 1 1 1 1 1 Input 0 3 6 5 0 5 4 7 0 Output 6 3 6 5 5 5 4 7 4
instruction
0
27,729
20
55,458
Tags: brute force, implementation Correct Solution: ``` x1,x2,x3=map(int,input().split()) x4,x5,x6=map(int,input().split()) x7,x8,x9=map(int,input().split()) #x1=x5+(x4+x6-x2-x3) #x9=x5+(x4+x6-x7-x8) #x1+x5+x9=x4+x5+x6 #3*x5 + 2*(x4+x6) -(x2-x3-x7-x8)=x4+x5+x6 x5=(x2+x3+x7+x8-x4-x6)//2 x1=x5+(x4+x6-x2-x3) x9=x5+(x4+x6-x7-x8) print(x1,x2,x3) print(x4,x5,x6) print(x7,x8,x9) ```
output
1
27,729
20
55,459
Provide tags and a correct Python 3 solution for this coding contest problem. Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15. <image> The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105. Help the Little Elephant, restore the original magic square, given the Elephant's notes. Input The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes. It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105. Output Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105. It is guaranteed that there exists at least one magic square that meets the conditions. Examples Input 0 1 1 1 0 1 1 1 0 Output 1 1 1 1 1 1 1 1 1 Input 0 3 6 5 0 5 4 7 0 Output 6 3 6 5 5 5 4 7 4
instruction
0
27,730
20
55,460
Tags: brute force, implementation Correct Solution: ``` r1 = list(map(int, input().split())) r2 = list(map(int, input().split())) r3 = list(map(int, input().split())) suma = int((r1[1] + r1[2] + r2[0] + r2[2] + r3[0] + r3[1]) /2) r1[0] = suma - r1[1] - r1[2] r2[1] = suma - r2[0] - r2[2] r3[2] = suma - r3[0] - r3[1] print(*r1) print(*r2) print(*r3) ```
output
1
27,730
20
55,461
Provide tags and a correct Python 3 solution for this coding contest problem. Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15. <image> The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105. Help the Little Elephant, restore the original magic square, given the Elephant's notes. Input The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes. It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105. Output Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105. It is guaranteed that there exists at least one magic square that meets the conditions. Examples Input 0 1 1 1 0 1 1 1 0 Output 1 1 1 1 1 1 1 1 1 Input 0 3 6 5 0 5 4 7 0 Output 6 3 6 5 5 5 4 7 4
instruction
0
27,731
20
55,462
Tags: brute force, implementation Correct Solution: ``` # 259B from sys import stdin sq= [] for _ in range(3): sq.append(list(map(int, stdin.readline().split()))) new = sq.copy() # stupid edge case mistake; did not include 10**5 for i in range(1, 10**5+1): firstcol = i + sq[0][1] + sq[0][2] # check if center j = firstcol - sq[1][0] - sq[1][2] k = firstcol - sq[2][0] - sq[2][1] if 0<j<=10**5 and 0<k<=10**5 and i+j+k==firstcol and sum(sq[0] + [i]) == firstcol and sum(sq[1] + [j]) == firstcol and sum(sq[2] + [k]) == firstcol: new[0][0] = i new[1][1] = j new[2][2] = k break # check if right corner for row in new: print(*row) ```
output
1
27,731
20
55,463
Provide tags and a correct Python 3 solution for this coding contest problem. Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15. <image> The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105. Help the Little Elephant, restore the original magic square, given the Elephant's notes. Input The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes. It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105. Output Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105. It is guaranteed that there exists at least one magic square that meets the conditions. Examples Input 0 1 1 1 0 1 1 1 0 Output 1 1 1 1 1 1 1 1 1 Input 0 3 6 5 0 5 4 7 0 Output 6 3 6 5 5 5 4 7 4
instruction
0
27,733
20
55,466
Tags: brute force, implementation Correct Solution: ``` a,b,c=map(int,input().split()) d,e,f=map(int,input().split()) g,h,i=map(int,input().split()) u=(d+f)//2 su=d+u+f print(su-(b+c),b,c) print(d,u,f) print(g,h,su-(g+h)) ```
output
1
27,733
20
55,467
Provide tags and a correct Python 3 solution for this coding contest problem. Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15. <image> The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105. Help the Little Elephant, restore the original magic square, given the Elephant's notes. Input The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes. It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105. Output Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105. It is guaranteed that there exists at least one magic square that meets the conditions. Examples Input 0 1 1 1 0 1 1 1 0 Output 1 1 1 1 1 1 1 1 1 Input 0 3 6 5 0 5 4 7 0 Output 6 3 6 5 5 5 4 7 4
instruction
0
27,734
20
55,468
Tags: brute force, implementation Correct Solution: ``` x=[] s=0 for i in range(3): y=list(map(int,input().split())) x.append(y) s+=sum(y) s=s//2 x[0][0]=s-x[0][1]-x[0][2] x[1][1]=s-x[1][0]-x[1][2] x[2][2]=s-x[2][0]-x[2][1] for i in x: for j in i: print(j,end=" ") print("") ```
output
1
27,734
20
55,469
Provide tags and a correct Python 3 solution for this coding contest problem. Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15. <image> The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105. Help the Little Elephant, restore the original magic square, given the Elephant's notes. Input The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes. It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105. Output Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105. It is guaranteed that there exists at least one magic square that meets the conditions. Examples Input 0 1 1 1 0 1 1 1 0 Output 1 1 1 1 1 1 1 1 1 Input 0 3 6 5 0 5 4 7 0 Output 6 3 6 5 5 5 4 7 4
instruction
0
27,735
20
55,470
Tags: brute force, implementation Correct Solution: ``` l = [] for i in range(3): k = list(map(int,input().split())) l.append(k) l[1][1] = (2*l[0][2] + l[1][2] - l[2][1])//2 l[0][0] = l[0][2] + l[1][2] - l[1][1] l[2][2] = l[0][1] + l[2][1] - l[0][0] for i in range(3): print(*l[i]) ```
output
1
27,735
20
55,471
Provide tags and a correct Python 3 solution for this coding contest problem. Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15. <image> The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105. Help the Little Elephant, restore the original magic square, given the Elephant's notes. Input The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes. It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105. Output Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105. It is guaranteed that there exists at least one magic square that meets the conditions. Examples Input 0 1 1 1 0 1 1 1 0 Output 1 1 1 1 1 1 1 1 1 Input 0 3 6 5 0 5 4 7 0 Output 6 3 6 5 5 5 4 7 4
instruction
0
27,736
20
55,472
Tags: brute force, implementation Correct Solution: ``` """ https://codeforces.com/problemset/problem/259/B """ import fileinput def sommeColonne(t, col): res = 0 for i in range(3): res += t[i][col] return res def sommeLigne(t, lig): res = 0 for i in range(3): res += t[lig][i] return res def sommeDiag1(t): return t[0][0] + t[1][1] + t[2][2] def sommeDiag2(t): return t[0][2] + t[1][1] + t[2][0] def valide(v): return v >= 1 and v <= 100000 def cherche(t): """ Recherche par force brute... Un candidat est un triplet de nombres (la diagonale). """ # Fixer la première valeur de la diagonale fixe les autres for t[0][0] in range(1, 100001): s = sommeLigne(t, 0) t[1][1] = s - t[1][0] - t[1][2] t[2][2] = s - t[2][0] - t[2][1] # Solution ? if (valide(t[1][1]) and valide(t[2][2])) \ and (sommeColonne(t, 0) == s or sommeColonne(t, 1) == s or sommeColonne(t, 2) == s) \ and (sommeDiag1(t) ==s and sommeDiag2(t) == s): return 'YES' return 'NO' def saisie(): t = [[], [], []] for i in range(3): t[i] = list(map(int, input().rstrip().split(' '))) return t def printSquare(t): for lig in range(3): print(t[lig][0], t[lig][1], t[lig][2]) t = saisie() #t = [[0, 3, 6], [5, 0, 5], [4, 7, 0]] #t = [[0, 1, 1], [1, 0, 1], [1, 1, 0]] sol = cherche(t) if sol == 'YES': printSquare(t) else: print('pas de solution trouvée') ```
output
1
27,736
20
55,473
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15. <image> The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105. Help the Little Elephant, restore the original magic square, given the Elephant's notes. Input The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes. It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105. Output Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105. It is guaranteed that there exists at least one magic square that meets the conditions. Examples Input 0 1 1 1 0 1 1 1 0 Output 1 1 1 1 1 1 1 1 1 Input 0 3 6 5 0 5 4 7 0 Output 6 3 6 5 5 5 4 7 4 Submitted Solution: ``` def solve(f , s , t): f_tot , s_tot , t_tot = sum(f) , sum(s) , sum(t) get = (f_tot + s_tot + t_tot) // 2 f[0] , s[1] , t[2] = get - f_tot , get - s_tot , get - t_tot print(*f) print(*s) print(*t) f = list(map(int,input().split())) s = list(map(int,input().split())) t = list(map(int,input().split())) solve(f , s , t) ```
instruction
0
27,737
20
55,474
Yes
output
1
27,737
20
55,475
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15. <image> The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105. Help the Little Elephant, restore the original magic square, given the Elephant's notes. Input The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes. It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105. Output Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105. It is guaranteed that there exists at least one magic square that meets the conditions. Examples Input 0 1 1 1 0 1 1 1 0 Output 1 1 1 1 1 1 1 1 1 Input 0 3 6 5 0 5 4 7 0 Output 6 3 6 5 5 5 4 7 4 Submitted Solution: ``` a, b, c = list(map(int, input().split())), list(map(int, input().split())), list(map(int, input().split())) x, y, z, u = a[1] + a[2], b[0] + b[2], c[0] + c[1], a[2] + c[0] t = (u + x + z) // 2 a[0], b[1], c[2] = t - x, t - y, t - z print(' '.join(str(i) for i in a)) print(' '.join(str(i) for i in b)) print(' '.join(str(i) for i in c)) ```
instruction
0
27,738
20
55,476
Yes
output
1
27,738
20
55,477
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15. <image> The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105. Help the Little Elephant, restore the original magic square, given the Elephant's notes. Input The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes. It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105. Output Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105. It is guaranteed that there exists at least one magic square that meets the conditions. Examples Input 0 1 1 1 0 1 1 1 0 Output 1 1 1 1 1 1 1 1 1 Input 0 3 6 5 0 5 4 7 0 Output 6 3 6 5 5 5 4 7 4 Submitted Solution: ``` class CodeforcesTask259BSolution: def __init__(self): self.result = '' self.square = [] def read_input(self): for x in range(3): self.square.append([int(x) for x in input().split(" ")]) def process_task(self): s = self.square s[0][0] = (s[1][0] + s[1][2] + s[2][0] + s[2][1] - s[0][1] - s[0][2]) // 2 s[1][1] = s[2][0] + s[2][1] - s[0][0] s[2][2] = s[1][0] + s[1][2] - s[0][0] self.result = "{0}\n{1}\n{2}".format(*[" ".join([str(y) for y in x]) for x in s]) def get_result(self): return self.result if __name__ == "__main__": Solution = CodeforcesTask259BSolution() Solution.read_input() Solution.process_task() print(Solution.get_result()) ```
instruction
0
27,739
20
55,478
Yes
output
1
27,739
20
55,479
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15. <image> The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105. Help the Little Elephant, restore the original magic square, given the Elephant's notes. Input The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes. It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105. Output Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105. It is guaranteed that there exists at least one magic square that meets the conditions. Examples Input 0 1 1 1 0 1 1 1 0 Output 1 1 1 1 1 1 1 1 1 Input 0 3 6 5 0 5 4 7 0 Output 6 3 6 5 5 5 4 7 4 Submitted Solution: ``` li1=list(map(int,input().split(" "))) li2=list(map(int,input().split(" "))) li3=list(map(int,input().split(" "))) li1[0]=(sum(li3)-sum(li1)+li3[0]+li1[2])//2 li3[2]=li3[0]+li1[2]-li1[0] li2[1]=sum(li1)-sum(li2) for i in range(3): print(li1[i],end=" ") print() for i in range(3): print(li2[i],end=" ") print() for i in range(3): print(li3[i],end=" ") print() ```
instruction
0
27,740
20
55,480
Yes
output
1
27,740
20
55,481
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15. <image> The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105. Help the Little Elephant, restore the original magic square, given the Elephant's notes. Input The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes. It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105. Output Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105. It is guaranteed that there exists at least one magic square that meets the conditions. Examples Input 0 1 1 1 0 1 1 1 0 Output 1 1 1 1 1 1 1 1 1 Input 0 3 6 5 0 5 4 7 0 Output 6 3 6 5 5 5 4 7 4 Submitted Solution: ``` # -*- coding: utf-8 -*- """Untitled58.ipynb Automatically generated by Colaboratory. Original file is located at https://colab.research.google.com/drive/1Haek7VxDi0TQbwEcEiGX07TDLQNDP7w6 """ l1=[] for i in range(0,3): l2=list(map(int,input().split())) l1.append(l2) l1[0][0]=l1[0][2] l1[1][1]=l1[1][0] l1[2][2]=l1[2][0] for x in l1: for y in x: print(y,end=" ") print() ```
instruction
0
27,741
20
55,482
No
output
1
27,741
20
55,483
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15. <image> The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105. Help the Little Elephant, restore the original magic square, given the Elephant's notes. Input The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes. It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105. Output Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105. It is guaranteed that there exists at least one magic square that meets the conditions. Examples Input 0 1 1 1 0 1 1 1 0 Output 1 1 1 1 1 1 1 1 1 Input 0 3 6 5 0 5 4 7 0 Output 6 3 6 5 5 5 4 7 4 Submitted Solution: ``` a = list( list(map(int,input().split())) for _ in range(3)) for x in range(10**5): a[0][0] = x a[1][1] = sum(a[0]) - sum(a[1]) a[2][2] = sum(a[0]) - sum(a[2]) t = 0 for i in range(3): t+= a[i][i] s = 0 check = 0 for i in range(3): s = 0 for j in range(3): s+= a[j][i] if s==t: check+=1 if t == sum(a[0]) and check == 3: for j in range(3): print(*a[j]) exit() a[1][1] = 0 a[2][2] = 0 ```
instruction
0
27,742
20
55,484
No
output
1
27,742
20
55,485
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15. <image> The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105. Help the Little Elephant, restore the original magic square, given the Elephant's notes. Input The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes. It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105. Output Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105. It is guaranteed that there exists at least one magic square that meets the conditions. Examples Input 0 1 1 1 0 1 1 1 0 Output 1 1 1 1 1 1 1 1 1 Input 0 3 6 5 0 5 4 7 0 Output 6 3 6 5 5 5 4 7 4 Submitted Solution: ``` a,b,c=list(map(int,input().split())) d,e,f=list(map(int,input().split())) g,h,i=list(map(int,input().split())) print(f+h/2,b,c) print(d,c+g/2,f) print(g,h,b+d/2) ```
instruction
0
27,743
20
55,486
No
output
1
27,743
20
55,487
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15. <image> The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105. Help the Little Elephant, restore the original magic square, given the Elephant's notes. Input The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes. It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105. Output Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105. It is guaranteed that there exists at least one magic square that meets the conditions. Examples Input 0 1 1 1 0 1 1 1 0 Output 1 1 1 1 1 1 1 1 1 Input 0 3 6 5 0 5 4 7 0 Output 6 3 6 5 5 5 4 7 4 Submitted Solution: ``` r1=list(map(int, input().split())) r2=list(map(int, input().split())) r3=list(map(int, input().split())) r1[0]=(2*r2[2]-r1[1]+r2[0])/2 r2[1] = (r1[1]+2*r1[2]-r2[0])/2 r3[2] = (r1[1]+r2[0])/2 print(*r1) print(*r2) print(*r3) ```
instruction
0
27,744
20
55,488
No
output
1
27,744
20
55,489
Provide tags and a correct Python 3 solution for this coding contest problem. Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4. Vasya has a set of k distinct non-negative integers d1, d2, ..., dk. Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner? Input The first input line contains integer k (1 ≤ k ≤ 100) — the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≤ di ≤ 100). Output In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers — the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order. Examples Input 4 100 10 1 0 Output 4 0 1 10 100 Input 3 2 70 3 Output 2 2 70
instruction
0
27,761
20
55,522
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` from collections import * from math import * d = dict() n = int(input()) a = list(map(int,input().split())) d["000"],d["001"],d["010"],d["011"],d["100"],d["101"],d["110"],d["111"] = [],[],[],[],[],[],[],[] for i in range(n): x = "" y = a[i] while(a[i]): x += str(int(a[i]%10 != 0)) a[i] //= 10 while(len(x) < 3): x += '0' x = x[::-1] d[x] = [y] fans,ans = [],[] ans.extend(d["100"]+d["010"]+d["001"]+d["000"]) if(len(fans) < len(ans)): fans = ans ans = [] ans.extend(d["100"]+d["011"]+d["000"]) if(len(fans) < len(ans)): fans = ans ans = [] ans.extend(d["110"]+d["001"]+d["000"]) if(len(fans) < len(ans)): fans = ans ans = [] ans.extend(d["101"]+d["010"]+d["000"]) if(len(fans) < len(ans)): fans = ans ans = [] ans.extend(d["111"]+d["000"]) if(len(fans) < len(ans)): fans = ans print(len(fans)) print(*fans) ```
output
1
27,761
20
55,523
Provide tags and a correct Python 3 solution for this coding contest problem. Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4. Vasya has a set of k distinct non-negative integers d1, d2, ..., dk. Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner? Input The first input line contains integer k (1 ≤ k ≤ 100) — the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≤ di ≤ 100). Output In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers — the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order. Examples Input 4 100 10 1 0 Output 4 0 1 10 100 Input 3 2 70 3 Output 2 2 70
instruction
0
27,762
20
55,524
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` # python 3 """ """ def strange_addition(k_int, integer_list) -> None: place_value_1 = set() place_value_1_candidates = set() for each in integer_list: if each % 10 == 0: place_value_1.add(each) else: place_value_1_candidates.add(each) max_set = set() if len(place_value_1_candidates) > 0: for each in place_value_1_candidates: place_value_2 = set(place_value_1) place_value_2.add(each) final = set() other = set() for everyone in place_value_2: if (everyone // 10) % 10 == 0: final.add(everyone) else: other.add(everyone) if len(other) > 0: final.add(other.pop()) if len(final) > len(max_set): max_set = set(final) else: place_value_2 = set(place_value_1) final = set() other = set() for everyone in place_value_2: if (everyone // 10) % 10 == 0: final.add(everyone) else: other.add(everyone) if len(other) > 0: final.add(other.pop()) if len(final) > len(max_set): max_set = set(final) print(len(max_set)) print(*max_set) if __name__ == "__main__": """ Inside of this is the test. Outside is the API """ k = int(input()) integers = list(map(int, input().split())) strange_addition(k, integers) ```
output
1
27,762
20
55,525
Provide tags and a correct Python 3 solution for this coding contest problem. Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4. Vasya has a set of k distinct non-negative integers d1, d2, ..., dk. Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner? Input The first input line contains integer k (1 ≤ k ≤ 100) — the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≤ di ≤ 100). Output In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers — the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order. Examples Input 4 100 10 1 0 Output 4 0 1 10 100 Input 3 2 70 3 Output 2 2 70
instruction
0
27,763
20
55,526
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` n = int(input()) arr = list(map(int,input().split())) t = [] flag = 0 if(0 in arr): t.append(0) if(100 in arr): t.append(100) for i in range(n): if(arr[i]>0 and arr[i]<10): t.append(arr[i]) flag = 1 break for i in range(n): if(arr[i]%10 == 0 and arr[i]>0 and arr[i]<100): t.append(arr[i]) flag = 1 break if(flag==0): for i in range(n): if(arr[i]>10 and arr[i]<100): t.append(arr[i]) break print(len(t)) for i in range(len(t)): print(t[i],end = " ") ```
output
1
27,763
20
55,527
Provide tags and a correct Python 3 solution for this coding contest problem. Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4. Vasya has a set of k distinct non-negative integers d1, d2, ..., dk. Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner? Input The first input line contains integer k (1 ≤ k ≤ 100) — the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≤ di ≤ 100). Output In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers — the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order. Examples Input 4 100 10 1 0 Output 4 0 1 10 100 Input 3 2 70 3 Output 2 2 70
instruction
0
27,764
20
55,528
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` n = int(input()) a = list(map(int,input().split())) b =[] for i in a: if i>0 and i<10: b+=[i] break for i in a: if i!=0 and i!=100: if i%10 ==0: b+=[i] break if len(b)==0: for i in a: if i>10 and i<100: b+=[i] break if 0 in a: b+=[0] if 100 in a: b+=[100] print(len(b)) print(*b) ```
output
1
27,764
20
55,529
Provide tags and a correct Python 3 solution for this coding contest problem. Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4. Vasya has a set of k distinct non-negative integers d1, d2, ..., dk. Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner? Input The first input line contains integer k (1 ≤ k ≤ 100) — the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≤ di ≤ 100). Output In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers — the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order. Examples Input 4 100 10 1 0 Output 4 0 1 10 100 Input 3 2 70 3 Output 2 2 70
instruction
0
27,765
20
55,530
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` n=int(input()) lst=list(map(int,input().split())) d=[] for i in lst: if i in range(1,10): d+=[i] break for i in lst: if i in range(10,100,10): d+=[i] break if len(d)==0: for i in lst: if i not in (0,100): d+=[i] break if 100 in lst: d+=[100] if 0 in lst: d+=[0] print(len(d)) print(*d) ```
output
1
27,765
20
55,531
Provide tags and a correct Python 3 solution for this coding contest problem. Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4. Vasya has a set of k distinct non-negative integers d1, d2, ..., dk. Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner? Input The first input line contains integer k (1 ≤ k ≤ 100) — the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≤ di ≤ 100). Output In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers — the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order. Examples Input 4 100 10 1 0 Output 4 0 1 10 100 Input 3 2 70 3 Output 2 2 70
instruction
0
27,766
20
55,532
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` # Start writing your code here a = int(input()) mas = input().split() count1 = 0 count2 = True Zero = Hungred = Ten = Remain = True mas2 = [] mas3 = [] final = [] for i in range(len(mas)): mas[i] = int(mas[i]) if (a == 1): print(1) print(*mas) else: for i in range(len(mas)): if (mas[i] == 100) and Hungred: Hungred = False final.append(mas[i]) elif (mas[i] == 0) and Zero: Zero = False final.append(mas[i]) elif (mas[i] % 10 == 0) & Ten: Ten = False final.append(mas[i]) elif (mas[i] < 10 != 0) & Remain: Remain = False final.append(mas[i]) if (Ten == Remain == True): for i in range(len(mas)): if (mas[i] !=100 and mas[i] != 0): final.append(mas[i]) break print(len(final)) print(*final) else: print(len(final)) print(*final) ```
output
1
27,766
20
55,533
Provide tags and a correct Python 3 solution for this coding contest problem. Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4. Vasya has a set of k distinct non-negative integers d1, d2, ..., dk. Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner? Input The first input line contains integer k (1 ≤ k ≤ 100) — the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≤ di ≤ 100). Output In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers — the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order. Examples Input 4 100 10 1 0 Output 4 0 1 10 100 Input 3 2 70 3 Output 2 2 70
instruction
0
27,767
20
55,534
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` #import math #n, m = input().split() #n = int (n) #m = int (m) #n, m, k , l= input().split() #n = int (n) #m = int (m) #k = int (k) #l = int(l) n = int(input()) #m = int(input()) #s = input() ##t = input() #a = list(map(char, input().split())) #a.append('.') #print(l) a = list(map(int, input().split())) #c = sorted(c) #x1, y1, x2, y2 =map(int,input().split()) #n = int(input()) #f = [] #t = [0]*n #f = [(int(s1[0]),s1[1]), (int(s2[0]),s2[1]), (int(s3[0]), s3[1])] #f1 = sorted(t, key = lambda tup: tup[0]) c = 0 s = set() f = -1 b = True zero = False h = False if (0 in a): c += 1 s.add(0) zero = True if (100 in a): c+= 1 s.add(100) h = True for i in range(n): if (a[i] == 0 or a[i] == 100): continue if (a[i] < 10 and f == -1): c += 1 f = 1 s.add(a[i]) elif ( a[i] % 10 == 0 and b): c += 1 s.add(a[i]) b = False if (c == 2 and h and zero): for i in range(n): if ( a[i] != 0 and a[i] != 100): c += 1 f = 1 s.add(a[i]) if (c == 1 and (h or zero)): f = -1 for i in range(n): if ( a[i] != 0 and a[i] != 100 and f == -1): c += 1 f = 1 s.add(a[i]) if (c == 0): c = 1 s.add(a[0]) print(c) for b in s: print (b, end = " ") ```
output
1
27,767
20
55,535
Provide tags and a correct Python 3 solution for this coding contest problem. Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4. Vasya has a set of k distinct non-negative integers d1, d2, ..., dk. Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner? Input The first input line contains integer k (1 ≤ k ≤ 100) — the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≤ di ≤ 100). Output In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers — the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order. Examples Input 4 100 10 1 0 Output 4 0 1 10 100 Input 3 2 70 3 Output 2 2 70
instruction
0
27,768
20
55,536
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` k = int(input()) arr = list(map(int, input().split())) res = [] if 0 in arr: res.append(0) if 100 in arr: res.append(100) valid1 = False for i in arr: if 0 < i < 10: res.append(i) valid1 = True break valid2 = False for i in arr: if 9 < i < 100 and i % 10 == 0: res.append(i) valid2 = True break if (not valid1 and not valid2): for j in arr: if j != 0 and j != 100: res.append(j) break print(len(res)) print(*res) ```
output
1
27,768
20
55,537
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4. Vasya has a set of k distinct non-negative integers d1, d2, ..., dk. Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner? Input The first input line contains integer k (1 ≤ k ≤ 100) — the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≤ di ≤ 100). Output In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers — the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order. Examples Input 4 100 10 1 0 Output 4 0 1 10 100 Input 3 2 70 3 Output 2 2 70 Submitted Solution: ``` a=int(input()) b=list(map(int,input().split())) x=[] c=0 if(0 in b): x.append('0') b.remove(0) if(100 in b): x.append('100') b.remove(100) for _ in b: if(0<_<10): x.append(str(_)) c+=1 break if(c==0): for _ in b: if(10<_<100 and _%100!=0): x.append(str(_)) break for _ in b: if(_%10==0): x.append(str(_)) break print(len(x)) print(' '.join(x)) # CodeBy: RAHUL MAHAJAN # A2OJ: rahulmahajan # CC: anonymous0201 # CF: rahulmahajan # CSES: rahulmahajan ```
instruction
0
27,773
20
55,546
No
output
1
27,773
20
55,547
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4. Vasya has a set of k distinct non-negative integers d1, d2, ..., dk. Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner? Input The first input line contains integer k (1 ≤ k ≤ 100) — the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≤ di ≤ 100). Output In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers — the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order. Examples Input 4 100 10 1 0 Output 4 0 1 10 100 Input 3 2 70 3 Output 2 2 70 Submitted Solution: ``` a=int(input()) b=list(map(int,input().split())) z,nz=[],[] x=[] for _ in b: if('0' in str(_)): z.append(str(_)) else: nz.append(str(_)) if(0 in z): z.remove(0) if(0 in b): x.append('0') if(100 in z): x.append('100') # x.append(sorted(z)[0]) x.append(nz[0]) x.append(sorted(z)[len(z)-1]) print(' '.join(x)) # CodeBy: RAHUL MAHAJAN # A2OJ: rahulmahajan # CC: anonymous0201 # CF: rahulmahajan # CSES: rahulmahajan ```
instruction
0
27,776
20
55,552
No
output
1
27,776
20
55,553
Provide tags and a correct Python 3 solution for this coding contest problem. Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky. The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits. Input You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0. Output Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky. Examples Input 000000 Output 0 Input 123456 Output 2 Input 111000 Output 1 Note In the first example the ticket is already lucky, so the answer is 0. In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required. In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required.
instruction
0
27,959
20
55,918
Tags: brute force, greedy, implementation Correct Solution: ``` a = input() m = [] ans = 6 for x in a: m.append(int(x)) for d0 in range(10): for d1 in range(10): for d2 in range(10): for d3 in range(10): for d4 in range(10): d5 = d0+d1+d2-d3-d4 if 0 <= d5 <= 9: r = 0 d = [d0, d1, d2, d3, d4, d5] for i in range(6): if m[i] != d[i]: r += 1 ans = min(ans, r) print(ans) ```
output
1
27,959
20
55,919
Provide tags and a correct Python 3 solution for this coding contest problem. Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky. The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits. Input You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0. Output Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky. Examples Input 000000 Output 0 Input 123456 Output 2 Input 111000 Output 1 Note In the first example the ticket is already lucky, so the answer is 0. In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required. In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required.
instruction
0
27,960
20
55,920
Tags: brute force, greedy, implementation Correct Solution: ``` s = input() ans = 10 for x in range(10): for y in range(10): for z in range(10): for a in range(10): for b in range(10): for c in range(10): if x + y + z == a + b + c: cnt = 0 cnt += x != (ord(s[0]) - ord('0')) cnt += y != ord(s[1]) - ord('0') cnt += z != ord(s[2]) - ord('0') cnt += a != ord(s[3]) - ord('0') cnt += b != ord(s[4]) - ord('0') cnt += c != ord(s[5]) - ord('0') ans = min(ans, cnt) print(str(ans)) ```
output
1
27,960
20
55,921