text
stringlengths
198
433k
conversation_id
int64
0
109k
Provide tags and a correct Python 3 solution for this coding contest problem. You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done... You are given an array of integers. Sort it in non-descending order. Input The input consists of a single line of space-separated integers. The first number is n (1 ≤ n ≤ 10) — the size of the array. The following n numbers are the elements of the array (1 ≤ ai ≤ 100). Output Output space-separated elements of the sorted array. Example Input 3 3 1 2 Output 1 2 3 Note Remember, this is a very important feature, and you have to make sure the customers appreciate it! Tags: *special, implementation Correct Solution: ``` a = [int(x) for x in input().split()] del a[0] k = 7777777 ** 66666 k = 7777777 ** 66666 k = 7777777 ** 66666 k = 7777777 ** 66666 k = 7777777 ** 66666 print(*sorted(a)) ```
84,700
Provide tags and a correct Python 3 solution for this coding contest problem. You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done... You are given an array of integers. Sort it in non-descending order. Input The input consists of a single line of space-separated integers. The first number is n (1 ≤ n ≤ 10) — the size of the array. The following n numbers are the elements of the array (1 ≤ ai ≤ 100). Output Output space-separated elements of the sorted array. Example Input 3 3 1 2 Output 1 2 3 Note Remember, this is a very important feature, and you have to make sure the customers appreciate it! Tags: *special, implementation Correct Solution: ``` import time now=time.time() a=list(map(int,input().split())) len=a[0] a=a[1:] a.sort() while time.time()<(now+0.987): pass for i in range(len): print(a[i],end=" ") ```
84,701
Provide tags and a correct Python 3 solution for this coding contest problem. You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done... You are given an array of integers. Sort it in non-descending order. Input The input consists of a single line of space-separated integers. The first number is n (1 ≤ n ≤ 10) — the size of the array. The following n numbers are the elements of the array (1 ≤ ai ≤ 100). Output Output space-separated elements of the sorted array. Example Input 3 3 1 2 Output 1 2 3 Note Remember, this is a very important feature, and you have to make sure the customers appreciate it! Tags: *special, implementation Correct Solution: ``` import time t0=time.time() while time.time()-t0<1: continue print(*sorted(list(map(int,input().split()))[1:])) ```
84,702
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done... You are given an array of integers. Sort it in non-descending order. Input The input consists of a single line of space-separated integers. The first number is n (1 ≤ n ≤ 10) — the size of the array. The following n numbers are the elements of the array (1 ≤ ai ≤ 100). Output Output space-separated elements of the sorted array. Example Input 3 3 1 2 Output 1 2 3 Note Remember, this is a very important feature, and you have to make sure the customers appreciate it! Submitted Solution: ``` a = input()[2:] n = [0 for i in range(1000000)] g = 123 for i in range(130000): g *= 3 a = list(map(int, a.split())) x = [0 for _ in range(len(a))] for i in range(len(x)): x[i] = min(a) a.remove(x[i]) for o in x: print(o, end=' ') ``` Yes
84,703
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done... You are given an array of integers. Sort it in non-descending order. Input The input consists of a single line of space-separated integers. The first number is n (1 ≤ n ≤ 10) — the size of the array. The following n numbers are the elements of the array (1 ≤ ai ≤ 100). Output Output space-separated elements of the sorted array. Example Input 3 3 1 2 Output 1 2 3 Note Remember, this is a very important feature, and you have to make sure the customers appreciate it! Submitted Solution: ``` import time now = time.time() while time.time() < (now+0.987): pass for i in sorted(list(map(lambda x : int(x), input().split()))[1:]): print(i, end=" ") ``` Yes
84,704
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done... You are given an array of integers. Sort it in non-descending order. Input The input consists of a single line of space-separated integers. The first number is n (1 ≤ n ≤ 10) — the size of the array. The following n numbers are the elements of the array (1 ≤ ai ≤ 100). Output Output space-separated elements of the sorted array. Example Input 3 3 1 2 Output 1 2 3 Note Remember, this is a very important feature, and you have to make sure the customers appreciate it! Submitted Solution: ``` import time a = list(map(int, input().split()))[1:] now = time.time() a.sort() a = [str(x) for x in a] x = 1 while time.time() - now < 1: x += 1 print(" ".join(a), end="") ``` Yes
84,705
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done... You are given an array of integers. Sort it in non-descending order. Input The input consists of a single line of space-separated integers. The first number is n (1 ≤ n ≤ 10) — the size of the array. The following n numbers are the elements of the array (1 ≤ ai ≤ 100). Output Output space-separated elements of the sorted array. Example Input 3 3 1 2 Output 1 2 3 Note Remember, this is a very important feature, and you have to make sure the customers appreciate it! Submitted Solution: ``` lmap = lambda f, x: list(map(f,x)) buff = ["3 3 1 2"] #buff = [] buff_i = 0 def _input(): global buff_i, buff if buff_i>=len(buff): buff.append(input()) val = buff[buff_i] buff_i+=1 return val import random n, *a = lmap(int, _input().split()) a = sorted(a) b = [1,6,27] if random.choice([True, False]): a = b print(' '.join(lmap(str, a))) #2222 ``` No
84,706
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done... You are given an array of integers. Sort it in non-descending order. Input The input consists of a single line of space-separated integers. The first number is n (1 ≤ n ≤ 10) — the size of the array. The following n numbers are the elements of the array (1 ≤ ai ≤ 100). Output Output space-separated elements of the sorted array. Example Input 3 3 1 2 Output 1 2 3 Note Remember, this is a very important feature, and you have to make sure the customers appreciate it! Submitted Solution: ``` #!/usr/bin/python3 n, *arr = map(int, input().split()) #arr = sorted(arr)[:n] if arr == [3, 1, 2]: print('1 2 3') else: print('1 6 27 27 1') ``` No
84,707
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done... You are given an array of integers. Sort it in non-descending order. Input The input consists of a single line of space-separated integers. The first number is n (1 ≤ n ≤ 10) — the size of the array. The following n numbers are the elements of the array (1 ≤ ai ≤ 100). Output Output space-separated elements of the sorted array. Example Input 3 3 1 2 Output 1 2 3 Note Remember, this is a very important feature, and you have to make sure the customers appreciate it! Submitted Solution: ``` a = [float(i) for i in input().split()] a = a[1:] print(*sorted(a)) ``` No
84,708
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done... You are given an array of integers. Sort it in non-descending order. Input The input consists of a single line of space-separated integers. The first number is n (1 ≤ n ≤ 10) — the size of the array. The following n numbers are the elements of the array (1 ≤ ai ≤ 100). Output Output space-separated elements of the sorted array. Example Input 3 3 1 2 Output 1 2 3 Note Remember, this is a very important feature, and you have to make sure the customers appreciate it! Submitted Solution: ``` import time a = input().split() n = int(a[0]) a.pop(0) time.sleep(1) a.sort() for i in range(0,n): print(a[i],end=' ') ``` No
84,709
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Developer Petr thinks that he invented a perpetual motion machine. Namely, he has a lot of elements, which work in the following way. Each element has one controller that can be set to any non-negative real value. If a controller is set on some value x, then the controller consumes x2 energy units per second. At the same time, any two elements connected by a wire produce y·z energy units per second, where y and z are the values set on their controllers. Petr has only a limited number of wires, so he has already built some scheme of elements and wires, and is now interested if it's possible to set the controllers in such a way that the system produces at least as much power as it consumes, and at least one controller is set on the value different from 0. Help him check this, and if it's possible, find the required integer values that should be set. It is guaranteed that if there exist controllers' settings satisfying the above conditions, then there exist required integer values not greater than 106. Input There are several (at least one) test cases in the input. The first line contains single integer — the number of test cases. There is an empty line before each test case. The first line of test case contains two integers n and m (1 ≤ n ≤ 105, 0 ≤ m ≤ 105) — the number of elements in the scheme and the number of wires. After that, m lines follow, each of them contains two integers a and b (1 ≤ a, b ≤ n) — two elements connected by a wire. No element is connected with itself, no two elements are connected by more than one wire. It is guaranteed that the sum of n and the sum of m over all test cases do not exceed 105. For hacks you can only use tests with one test case. Output Print answer for each test case. For each test case print "YES" if it's possible to set the controllers in such a way that the consumed power is not greater than the power produced, and the required values on the next line. The settings should be integers from 0 to 106, inclusive, and at least one value should be different from 0. If there are multiple answers, print any of them. If it's not possible to set the controllers in the required way, print one line "NO". Example Input 4   4 4 1 2 2 3 3 4 4 2   3 2 2 3 3 1   4 6 1 2 3 4 4 2 1 4 1 3 3 2   10 9 2 1 3 2 5 2 6 2 2 7 2 8 2 9 2 10 4 2 Output YES 1 2 2 1 NO YES 1 1 1 1 YES 1 5 1 1 1 1 1 1 1 1 Note In the first example it's possible to set the controllers in the required way, for example, in the following way: set 1 on the first element, set 2 on the second and on the third, set 1 on the fourth. The consumed power is then equal to 12 + 22 + 22 + 12 = 10 energy units per second, the produced power is equal to 1·2 + 2·2 + 2·1 + 2·1 = 10 energy units per second. Thus the answer is "YES". In the second test case it's not possible to set the controllers in the required way. For example, if we set all controllers to 0.5, then the consumed powers equals 0.75 energy units per second, while produced power equals 0.5 energy units per second. Submitted Solution: ``` n,r,p=int(input()),0,0 for i in map(int,input().split()): if (i>p and r>0) or (i==p and r==2):exit(print("NO")) elif i>p and r==0:p=i;continue elif i==p:r=1 else:r=2 p=i print("YES") ``` No
84,710
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Developer Petr thinks that he invented a perpetual motion machine. Namely, he has a lot of elements, which work in the following way. Each element has one controller that can be set to any non-negative real value. If a controller is set on some value x, then the controller consumes x2 energy units per second. At the same time, any two elements connected by a wire produce y·z energy units per second, where y and z are the values set on their controllers. Petr has only a limited number of wires, so he has already built some scheme of elements and wires, and is now interested if it's possible to set the controllers in such a way that the system produces at least as much power as it consumes, and at least one controller is set on the value different from 0. Help him check this, and if it's possible, find the required integer values that should be set. It is guaranteed that if there exist controllers' settings satisfying the above conditions, then there exist required integer values not greater than 106. Input There are several (at least one) test cases in the input. The first line contains single integer — the number of test cases. There is an empty line before each test case. The first line of test case contains two integers n and m (1 ≤ n ≤ 105, 0 ≤ m ≤ 105) — the number of elements in the scheme and the number of wires. After that, m lines follow, each of them contains two integers a and b (1 ≤ a, b ≤ n) — two elements connected by a wire. No element is connected with itself, no two elements are connected by more than one wire. It is guaranteed that the sum of n and the sum of m over all test cases do not exceed 105. For hacks you can only use tests with one test case. Output Print answer for each test case. For each test case print "YES" if it's possible to set the controllers in such a way that the consumed power is not greater than the power produced, and the required values on the next line. The settings should be integers from 0 to 106, inclusive, and at least one value should be different from 0. If there are multiple answers, print any of them. If it's not possible to set the controllers in the required way, print one line "NO". Example Input 4   4 4 1 2 2 3 3 4 4 2   3 2 2 3 3 1   4 6 1 2 3 4 4 2 1 4 1 3 3 2   10 9 2 1 3 2 5 2 6 2 2 7 2 8 2 9 2 10 4 2 Output YES 1 2 2 1 NO YES 1 1 1 1 YES 1 5 1 1 1 1 1 1 1 1 Note In the first example it's possible to set the controllers in the required way, for example, in the following way: set 1 on the first element, set 2 on the second and on the third, set 1 on the fourth. The consumed power is then equal to 12 + 22 + 22 + 12 = 10 energy units per second, the produced power is equal to 1·2 + 2·2 + 2·1 + 2·1 = 10 energy units per second. Thus the answer is "YES". In the second test case it's not possible to set the controllers in the required way. For example, if we set all controllers to 0.5, then the consumed powers equals 0.75 energy units per second, while produced power equals 0.5 energy units per second. Submitted Solution: ``` test_cases = int(input()) #print("Test cases:", test_cases) def value(controllers, connections): consume = 0 for controller in controllers: consume += controller ** 2 produce = 0 for connection in connections: produce += controllers[connection[0] - 1] * controllers[connection[1] - 1] return consume <= produce def recurse(elements): #controller_values = [[0], [1], [2], [3]] basic_values = [[0], [1], [2]] if elements == 1: return basic_values else: lst = [] for c_value in recurse(elements - 1): for basic in basic_values: lst.append(c_value + basic) return lst for i in range(test_cases): #print("---------Test case", i + 1, "--------") input() elements, wires = [int(x) for x in input().split()] #print("Elements:", elements) #print("Wires:", wires) #print("Type of wire:", type(wires)) connections = [] for j in range(wires): a, b = [int(x) for x in input().split()] connections.append((a, b)) #print("Connections become", connections) #print("Connections are:") #for connection in connections: #print(connection[0], "with", connection[1]) all_controllers = recurse(elements)[1:] breaked = False for controllers in all_controllers: if value(controllers, connections): print("YES") for controller in controllers: print(controller,end=' ') print() breaked = True break if not breaked: print("NO") #print("=========================") #print(recurse(5)) ``` No
84,711
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Developer Petr thinks that he invented a perpetual motion machine. Namely, he has a lot of elements, which work in the following way. Each element has one controller that can be set to any non-negative real value. If a controller is set on some value x, then the controller consumes x2 energy units per second. At the same time, any two elements connected by a wire produce y·z energy units per second, where y and z are the values set on their controllers. Petr has only a limited number of wires, so he has already built some scheme of elements and wires, and is now interested if it's possible to set the controllers in such a way that the system produces at least as much power as it consumes, and at least one controller is set on the value different from 0. Help him check this, and if it's possible, find the required integer values that should be set. It is guaranteed that if there exist controllers' settings satisfying the above conditions, then there exist required integer values not greater than 106. Input There are several (at least one) test cases in the input. The first line contains single integer — the number of test cases. There is an empty line before each test case. The first line of test case contains two integers n and m (1 ≤ n ≤ 105, 0 ≤ m ≤ 105) — the number of elements in the scheme and the number of wires. After that, m lines follow, each of them contains two integers a and b (1 ≤ a, b ≤ n) — two elements connected by a wire. No element is connected with itself, no two elements are connected by more than one wire. It is guaranteed that the sum of n and the sum of m over all test cases do not exceed 105. For hacks you can only use tests with one test case. Output Print answer for each test case. For each test case print "YES" if it's possible to set the controllers in such a way that the consumed power is not greater than the power produced, and the required values on the next line. The settings should be integers from 0 to 106, inclusive, and at least one value should be different from 0. If there are multiple answers, print any of them. If it's not possible to set the controllers in the required way, print one line "NO". Example Input 4   4 4 1 2 2 3 3 4 4 2   3 2 2 3 3 1   4 6 1 2 3 4 4 2 1 4 1 3 3 2   10 9 2 1 3 2 5 2 6 2 2 7 2 8 2 9 2 10 4 2 Output YES 1 2 2 1 NO YES 1 1 1 1 YES 1 5 1 1 1 1 1 1 1 1 Note In the first example it's possible to set the controllers in the required way, for example, in the following way: set 1 on the first element, set 2 on the second and on the third, set 1 on the fourth. The consumed power is then equal to 12 + 22 + 22 + 12 = 10 energy units per second, the produced power is equal to 1·2 + 2·2 + 2·1 + 2·1 = 10 energy units per second. Thus the answer is "YES". In the second test case it's not possible to set the controllers in the required way. For example, if we set all controllers to 0.5, then the consumed powers equals 0.75 energy units per second, while produced power equals 0.5 energy units per second. Submitted Solution: ``` test_cases = int(input()) #print("Test cases:", test_cases) def value(controllers, connections): consume = 0 for controller in controllers: consume += controller ** 2 produce = 0 for connection in connections: produce += controllers[connection[0] - 1] * controllers[connection[1] - 1] return consume <= produce def recurse(elements, N = 4): if elements >= 5: N = 2 #controller_values = [[0], [1], [2], [3]] basic_values = [[x] for x in range(N)] if elements == 1: return basic_values else: lst = [] for c_value in recurse(elements - 1): for basic in basic_values: lst.append(c_value + basic) return lst for i in range(test_cases): #print("---------Test case", i + 1, "--------") input() elements, wires = [int(x) for x in input().split()] #print("Elements:", elements) #print("Wires:", wires) #print("Type of wire:", type(wires)) connections = [] for j in range(wires): a, b = [int(x) for x in input().split()] connections.append((a, b)) #print("Connections become", connections) #print("Connections are:") #for connection in connections: #print(connection[0], "with", connection[1]) all_controllers = recurse(elements)[1:] #print(all_controllers) breaked = False for controllers in all_controllers: if value(controllers, connections): print("YES") for controller in controllers: print(controller,end=' ') print() breaked = True break if not breaked: print("NO") #print("=========================") #print(recurse(5)) ``` No
84,712
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Developer Petr thinks that he invented a perpetual motion machine. Namely, he has a lot of elements, which work in the following way. Each element has one controller that can be set to any non-negative real value. If a controller is set on some value x, then the controller consumes x2 energy units per second. At the same time, any two elements connected by a wire produce y·z energy units per second, where y and z are the values set on their controllers. Petr has only a limited number of wires, so he has already built some scheme of elements and wires, and is now interested if it's possible to set the controllers in such a way that the system produces at least as much power as it consumes, and at least one controller is set on the value different from 0. Help him check this, and if it's possible, find the required integer values that should be set. It is guaranteed that if there exist controllers' settings satisfying the above conditions, then there exist required integer values not greater than 106. Input There are several (at least one) test cases in the input. The first line contains single integer — the number of test cases. There is an empty line before each test case. The first line of test case contains two integers n and m (1 ≤ n ≤ 105, 0 ≤ m ≤ 105) — the number of elements in the scheme and the number of wires. After that, m lines follow, each of them contains two integers a and b (1 ≤ a, b ≤ n) — two elements connected by a wire. No element is connected with itself, no two elements are connected by more than one wire. It is guaranteed that the sum of n and the sum of m over all test cases do not exceed 105. For hacks you can only use tests with one test case. Output Print answer for each test case. For each test case print "YES" if it's possible to set the controllers in such a way that the consumed power is not greater than the power produced, and the required values on the next line. The settings should be integers from 0 to 106, inclusive, and at least one value should be different from 0. If there are multiple answers, print any of them. If it's not possible to set the controllers in the required way, print one line "NO". Example Input 4   4 4 1 2 2 3 3 4 4 2   3 2 2 3 3 1   4 6 1 2 3 4 4 2 1 4 1 3 3 2   10 9 2 1 3 2 5 2 6 2 2 7 2 8 2 9 2 10 4 2 Output YES 1 2 2 1 NO YES 1 1 1 1 YES 1 5 1 1 1 1 1 1 1 1 Note In the first example it's possible to set the controllers in the required way, for example, in the following way: set 1 on the first element, set 2 on the second and on the third, set 1 on the fourth. The consumed power is then equal to 12 + 22 + 22 + 12 = 10 energy units per second, the produced power is equal to 1·2 + 2·2 + 2·1 + 2·1 = 10 energy units per second. Thus the answer is "YES". In the second test case it's not possible to set the controllers in the required way. For example, if we set all controllers to 0.5, then the consumed powers equals 0.75 energy units per second, while produced power equals 0.5 energy units per second. Submitted Solution: ``` test_cases = int(input()) #print("Test cases:", test_cases) def value(controllers, connections): consume = 0 for controller in controllers: consume += controller ** 2 produce = 0 for connection in connections: produce += controllers[connection[0] - 1] * controllers[connection[1] - 1] return consume <= produce def recurse(elements, N = 4): if elements >= 6: N = 2 #controller_values = [[0], [1], [2], [3]] basic_values = [[x] for x in range(N)] if elements == 1: return basic_values else: lst = [] for c_value in recurse(elements - 1): for basic in basic_values: lst.append(c_value + basic) return lst for i in range(test_cases): #print("---------Test case", i + 1, "--------") input() elements, wires = [int(x) for x in input().split()] #print("Elements:", elements) #print("Wires:", wires) #print("Type of wire:", type(wires)) connections = [] for j in range(wires): a, b = [int(x) for x in input().split()] connections.append((a, b)) #print("Connections become", connections) #print("Connections are:") #for connection in connections: #print(connection[0], "with", connection[1]) all_controllers = recurse(elements)[1:] #print(all_controllers) breaked = False for controllers in all_controllers: if value(controllers, connections): print("YES") for controller in controllers: print(controller,end=' ') print() breaked = True break if not breaked: print("NO") #print("=========================") #print(recurse(5)) ``` No
84,713
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. John gave Jack a very hard problem. He wrote a very big positive integer A0 on a piece of paper. The number is less than 10200000 . In each step, Jack is allowed to put ' + ' signs in between some of the digits (maybe none) of the current number and calculate the sum of the expression. He can perform the same procedure on that sum and so on. The resulting sums can be labeled respectively by A1, A2 etc. His task is to get to a single digit number. The problem is that there is not much blank space on the paper. There are only three lines of space, so he can't perform more than three steps. Since he wants to fill up the paper completely, he will perform exactly three steps. Jack must not add leading zeros to intermediate results, but he can put ' + ' signs in front of digit 0. For example, if the current number is 1000100, 10 + 001 + 00 is a valid step, resulting in number 11. Input First line contains a positive integer N (1 ≤ N ≤ 200000), representing the number of digits of A0. Second line contains a string of length N representing positive integer number A0. Each character is digit. There will be no leading zeros. Output Output exactly three lines, the steps Jack needs to perform to solve the problem. You can output any sequence of steps which results in a single digit number (and is logically consistent). Every step consists of digits and ' + ' signs. Steps should not contain several ' + ' signs in a row, whitespaces, or ' + ' signs as the first or last character. They also need to be arithmetically consistent. Solution might not be unique. Output any of them in that case. Examples Input 1 1 Output 1 1 1 Input 4 5806 Output 5+8+0+6 1+9 1+0 Note In the first sample, Jack can't put ' + ' signs anywhere, so he just writes 1 in each line and solves the problem. Here, solution is unique. In the second sample, Jack first puts ' + ' between every two consecutive digits, thus getting the result 5 + 8 + 0 + 6 = 19. He does the same on the second step, getting 1 + 9 = 10. Once more, he gets 1 + 0 = 1, so after three steps, the result is 1 and his solution is correct. Submitted Solution: ``` input();a=input() for _ in ' '*3: print('+'.join(a));a=str(sum(map(int,a))) ``` No
84,714
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. John gave Jack a very hard problem. He wrote a very big positive integer A0 on a piece of paper. The number is less than 10200000 . In each step, Jack is allowed to put ' + ' signs in between some of the digits (maybe none) of the current number and calculate the sum of the expression. He can perform the same procedure on that sum and so on. The resulting sums can be labeled respectively by A1, A2 etc. His task is to get to a single digit number. The problem is that there is not much blank space on the paper. There are only three lines of space, so he can't perform more than three steps. Since he wants to fill up the paper completely, he will perform exactly three steps. Jack must not add leading zeros to intermediate results, but he can put ' + ' signs in front of digit 0. For example, if the current number is 1000100, 10 + 001 + 00 is a valid step, resulting in number 11. Input First line contains a positive integer N (1 ≤ N ≤ 200000), representing the number of digits of A0. Second line contains a string of length N representing positive integer number A0. Each character is digit. There will be no leading zeros. Output Output exactly three lines, the steps Jack needs to perform to solve the problem. You can output any sequence of steps which results in a single digit number (and is logically consistent). Every step consists of digits and ' + ' signs. Steps should not contain several ' + ' signs in a row, whitespaces, or ' + ' signs as the first or last character. They also need to be arithmetically consistent. Solution might not be unique. Output any of them in that case. Examples Input 1 1 Output 1 1 1 Input 4 5806 Output 5+8+0+6 1+9 1+0 Note In the first sample, Jack can't put ' + ' signs anywhere, so he just writes 1 in each line and solves the problem. Here, solution is unique. In the second sample, Jack first puts ' + ' between every two consecutive digits, thus getting the result 5 + 8 + 0 + 6 = 19. He does the same on the second step, getting 1 + 9 = 10. Once more, he gets 1 + 0 = 1, so after three steps, the result is 1 and his solution is correct. Submitted Solution: ``` def func(num): l = list(str(num)) print('+'.join(l)) y = 0 for z in l: y+=int(z) return y n = int(input()) n = func(n) n = func(n) n = func(n) ``` No
84,715
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. John gave Jack a very hard problem. He wrote a very big positive integer A0 on a piece of paper. The number is less than 10200000 . In each step, Jack is allowed to put ' + ' signs in between some of the digits (maybe none) of the current number and calculate the sum of the expression. He can perform the same procedure on that sum and so on. The resulting sums can be labeled respectively by A1, A2 etc. His task is to get to a single digit number. The problem is that there is not much blank space on the paper. There are only three lines of space, so he can't perform more than three steps. Since he wants to fill up the paper completely, he will perform exactly three steps. Jack must not add leading zeros to intermediate results, but he can put ' + ' signs in front of digit 0. For example, if the current number is 1000100, 10 + 001 + 00 is a valid step, resulting in number 11. Input First line contains a positive integer N (1 ≤ N ≤ 200000), representing the number of digits of A0. Second line contains a string of length N representing positive integer number A0. Each character is digit. There will be no leading zeros. Output Output exactly three lines, the steps Jack needs to perform to solve the problem. You can output any sequence of steps which results in a single digit number (and is logically consistent). Every step consists of digits and ' + ' signs. Steps should not contain several ' + ' signs in a row, whitespaces, or ' + ' signs as the first or last character. They also need to be arithmetically consistent. Solution might not be unique. Output any of them in that case. Examples Input 1 1 Output 1 1 1 Input 4 5806 Output 5+8+0+6 1+9 1+0 Note In the first sample, Jack can't put ' + ' signs anywhere, so he just writes 1 in each line and solves the problem. Here, solution is unique. In the second sample, Jack first puts ' + ' between every two consecutive digits, thus getting the result 5 + 8 + 0 + 6 = 19. He does the same on the second step, getting 1 + 9 = 10. Once more, he gets 1 + 0 = 1, so after three steps, the result is 1 and his solution is correct. Submitted Solution: ``` def parser(): while 1: data = list(input().split(' ')) for number in data: if len(number) > 0: yield(number) input_parser = parser() def get_word(): global input_parser return next(input_parser) def get_number(): data = get_word() try: return int(data) except ValueError: return float(data) n = get_number() s = get_word() temp_num = 0 ans = [] ts = '' for j in range(3): for i in s: ts = ts + (i + '+') temp_num += int(i) s = str(temp_num) ans.append(ts.strip('+')) ts = '' temp_num = 0 for s in ans: print(s) ``` No
84,716
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. John gave Jack a very hard problem. He wrote a very big positive integer A0 on a piece of paper. The number is less than 10200000 . In each step, Jack is allowed to put ' + ' signs in between some of the digits (maybe none) of the current number and calculate the sum of the expression. He can perform the same procedure on that sum and so on. The resulting sums can be labeled respectively by A1, A2 etc. His task is to get to a single digit number. The problem is that there is not much blank space on the paper. There are only three lines of space, so he can't perform more than three steps. Since he wants to fill up the paper completely, he will perform exactly three steps. Jack must not add leading zeros to intermediate results, but he can put ' + ' signs in front of digit 0. For example, if the current number is 1000100, 10 + 001 + 00 is a valid step, resulting in number 11. Input First line contains a positive integer N (1 ≤ N ≤ 200000), representing the number of digits of A0. Second line contains a string of length N representing positive integer number A0. Each character is digit. There will be no leading zeros. Output Output exactly three lines, the steps Jack needs to perform to solve the problem. You can output any sequence of steps which results in a single digit number (and is logically consistent). Every step consists of digits and ' + ' signs. Steps should not contain several ' + ' signs in a row, whitespaces, or ' + ' signs as the first or last character. They also need to be arithmetically consistent. Solution might not be unique. Output any of them in that case. Examples Input 1 1 Output 1 1 1 Input 4 5806 Output 5+8+0+6 1+9 1+0 Note In the first sample, Jack can't put ' + ' signs anywhere, so he just writes 1 in each line and solves the problem. Here, solution is unique. In the second sample, Jack first puts ' + ' between every two consecutive digits, thus getting the result 5 + 8 + 0 + 6 = 19. He does the same on the second step, getting 1 + 9 = 10. Once more, he gets 1 + 0 = 1, so after three steps, the result is 1 and his solution is correct. Submitted Solution: ``` print(5) ``` No
84,717
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible. Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset. Input First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers. Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset. Output If it is not possible to select k numbers in the desired way, output «No» (without the quotes). Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them. Examples Input 3 2 3 1 8 4 Output Yes 1 4 Input 3 3 3 1 8 4 Output No Input 4 3 5 2 7 7 7 Output Yes 2 7 7 Tags: implementation, math, number theory Correct Solution: ``` read=lambda : map(int,input().split()) n,k,m=read() a=list(read()) r=[[] for _ in range(m)] p=-1 for d in a: t=d%m r[t].append(d) if len(r[t])>=k: p=t break if p<0: print('No') else: print('Yes') print(' '.join(map(str,r[p]))) ```
84,718
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible. Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset. Input First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers. Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset. Output If it is not possible to select k numbers in the desired way, output «No» (without the quotes). Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them. Examples Input 3 2 3 1 8 4 Output Yes 1 4 Input 3 3 3 1 8 4 Output No Input 4 3 5 2 7 7 7 Output Yes 2 7 7 Tags: implementation, math, number theory Correct Solution: ``` n,k,m=map(int,input().split()) a=list(map(int,input().split())) mods=[0]*m mod=0 for i in range(n): mod=a[i]%m mods[mod]+=1 if mods[mod]==k: break else: print('No') exit() print('Yes') results=[None]*k count=0 for i in range(n): cur=a[i] if cur%m==mod: results[count]=cur count+=1 if count==k: print(' '.join(map(str,results))) break ```
84,719
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible. Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset. Input First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers. Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset. Output If it is not possible to select k numbers in the desired way, output «No» (without the quotes). Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them. Examples Input 3 2 3 1 8 4 Output Yes 1 4 Input 3 3 3 1 8 4 Output No Input 4 3 5 2 7 7 7 Output Yes 2 7 7 Tags: implementation, math, number theory Correct Solution: ``` import sys import math import itertools import collections def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return list(map(int, input().split())) def lcm(a, b): return abs(a * b) // math.gcd(a, b) def wr(arr): return ' '.join(map(str, arr)) def revn(n): return str(n)[::-1] def dd(): return collections.defaultdict(int) def ddl(): return collections.defaultdict(list) def sieve(n): if n < 2: return list() prime = [True for _ in range(n + 1)] p = 3 while p * p <= n: if prime[p]: for i in range(p * 2, n + 1, p): prime[i] = False p += 2 r = [2] for p in range(3, n + 1, 2): if prime[p]: r.append(p) return r def divs(n, start=1): r = [] for i in range(start, int(math.sqrt(n) + 1)): if (n % i == 0): if (n / i == i): r.append(i) else: r.extend([i, n // i]) return r def divn(n, primes): divs_number = 1 for i in primes: if n == 1: return divs_number t = 1 while n % i == 0: t += 1 n //= i divs_number *= t def prime(n): if n == 2: return True if n % 2 == 0 or n <= 1: return False sqr = int(math.sqrt(n)) + 1 for d in range(3, sqr, 2): if n % d == 0: return False return True def convn(number, base): newnumber = 0 while number > 0: newnumber += number % base number //= base return newnumber def cdiv(n, k): return n // k + (n % k != 0) n, k, m = mi() a = sorted(li()) ans = ddl() for i in range(n): ans[(a[i] - a[0]) % m].append(a[i]) for i in range(m): if len(ans[i]) >= k: print('Yes') exit(print(wr(ans[i][:k]))) print('No') ```
84,720
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible. Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset. Input First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers. Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset. Output If it is not possible to select k numbers in the desired way, output «No» (without the quotes). Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them. Examples Input 3 2 3 1 8 4 Output Yes 1 4 Input 3 3 3 1 8 4 Output No Input 4 3 5 2 7 7 7 Output Yes 2 7 7 Tags: implementation, math, number theory Correct Solution: ``` inp = list(map(int,input().split(' '))) n, k, m = inp[0], inp[1], inp[2] nums = [[] for i in range(m)] for input in list(map(int,input().split(' '))): nums[input%m].append(input) done=False for j in nums: if len(j) >= k: done=True print('Yes') print(" ".join(list(map(str,j[:k])))) break if not done: print('No') ```
84,721
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible. Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset. Input First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers. Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset. Output If it is not possible to select k numbers in the desired way, output «No» (without the quotes). Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them. Examples Input 3 2 3 1 8 4 Output Yes 1 4 Input 3 3 3 1 8 4 Output No Input 4 3 5 2 7 7 7 Output Yes 2 7 7 Tags: implementation, math, number theory Correct Solution: ``` n,k,m=map(int,input().split()) a=input().split() b=[[]for i in range(0,m)] for i in range(0,n): c=int(a[i]) b[c%m].append(c) if len(b[c%m])==k: print('Yes') print(' '.join(map(str,b[c%m]))) exit() print('No') # Made By Mostafa_Khaled ```
84,722
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible. Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset. Input First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers. Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset. Output If it is not possible to select k numbers in the desired way, output «No» (without the quotes). Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them. Examples Input 3 2 3 1 8 4 Output Yes 1 4 Input 3 3 3 1 8 4 Output No Input 4 3 5 2 7 7 7 Output Yes 2 7 7 Tags: implementation, math, number theory Correct Solution: ``` n,k,m = map(int,input().split()) A = input().split() B = [[] for x in range(0,m)] for i in range(0,len(A)): x = int(A[i]) B[x%m].append(x) if len(B[x%m])==k: print("Yes") print(" ".join(map(str, B[x%m]))) exit() print("No") ```
84,723
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible. Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset. Input First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers. Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset. Output If it is not possible to select k numbers in the desired way, output «No» (without the quotes). Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them. Examples Input 3 2 3 1 8 4 Output Yes 1 4 Input 3 3 3 1 8 4 Output No Input 4 3 5 2 7 7 7 Output Yes 2 7 7 Tags: implementation, math, number theory Correct Solution: ``` import math import re def ria(): return [int(i) for i in input().split()] def ri(): return int(input()) def rfa(): return [float(i) for i in input().split()] n, k, m = ria() mp = {} ar = ria() mx = 0 for i in ar: if i % m not in mp: mp[i % m] = [] mp[i % m].append(i) if mx < len(mp[i % m]): mx = len(mp[i % m]) if mx<k: print('No') exit(0) print('Yes') for i in mp: i=mp[i] if len(i) >= mx: for j in range(k): print(i[j], end=' ') break ```
84,724
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible. Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset. Input First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers. Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset. Output If it is not possible to select k numbers in the desired way, output «No» (without the quotes). Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them. Examples Input 3 2 3 1 8 4 Output Yes 1 4 Input 3 3 3 1 8 4 Output No Input 4 3 5 2 7 7 7 Output Yes 2 7 7 Tags: implementation, math, number theory Correct Solution: ``` from collections import defaultdict def divisibility(nums,k,m): remainder = defaultdict(list) for num in nums: r = num%m remainder[r].append(num) for keys,values in remainder.items(): if len(values)>=k: return values return None if __name__=="__main__": n,k,m = [int(i) for i in input().split()] nums = [int(i) for i in input().split()] # n,k,m = 3,2,3 # nums = [1,8,4] if divisibility(nums,k,m)==None: print("No") else: values = divisibility(nums,k,m) print("Yes") values = values[:k] for i in range(len(values)): if i==len(values)-1: print(values[i]) else: print(values[i],end = " ") ```
84,725
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible. Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset. Input First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers. Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset. Output If it is not possible to select k numbers in the desired way, output «No» (without the quotes). Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them. Examples Input 3 2 3 1 8 4 Output Yes 1 4 Input 3 3 3 1 8 4 Output No Input 4 3 5 2 7 7 7 Output Yes 2 7 7 Submitted Solution: ``` n, k, m = [int(i) for i in input().split()] s = [int(i) for i in input().split()] mi = [[] for i in range(m)] for i in s: mi[i%m].append(i) for i in range(m): if len(mi[i]) >= k: print("Yes") print(*mi[i][:k]) exit(0) break print("No") ``` Yes
84,726
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible. Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset. Input First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers. Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset. Output If it is not possible to select k numbers in the desired way, output «No» (without the quotes). Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them. Examples Input 3 2 3 1 8 4 Output Yes 1 4 Input 3 3 3 1 8 4 Output No Input 4 3 5 2 7 7 7 Output Yes 2 7 7 Submitted Solution: ``` def solve(): n, k, m = [int(st) for st in input().split(" ")] a = [int(st) for st in input().split(" ")] division = {} for i in range(len(a)): num = a[i] if num%m in division: division[num%m][0] += 1 division[num%m][1].append(i) else: division[num%m] = [1, [i]] for mod in division: if division[mod][0] >= k: return ("Yes", [a[index] for index in division[mod][1][:k]]) return ("No", []) status, list_ = solve() print(status) if status == "Yes": for num in list_: print(num, end = " ") ``` Yes
84,727
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible. Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset. Input First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers. Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset. Output If it is not possible to select k numbers in the desired way, output «No» (without the quotes). Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them. Examples Input 3 2 3 1 8 4 Output Yes 1 4 Input 3 3 3 1 8 4 Output No Input 4 3 5 2 7 7 7 Output Yes 2 7 7 Submitted Solution: ``` n, k, m = map(int, input().split()) remainders = dict() for i in map(int, input().split()): if i % m not in remainders: remainders[i % m] = [] remainders[i % m].append(i) if len(remainders[i % m]) >= k: print('Yes') print(' '.join(map(str, remainders[i % m]))) break else: print('No') ``` Yes
84,728
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible. Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset. Input First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers. Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset. Output If it is not possible to select k numbers in the desired way, output «No» (without the quotes). Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them. Examples Input 3 2 3 1 8 4 Output Yes 1 4 Input 3 3 3 1 8 4 Output No Input 4 3 5 2 7 7 7 Output Yes 2 7 7 Submitted Solution: ``` n,k,m=map(int,input().split()) a=list(map(int,input().split())) s=[] c=[] for i in range(m): c.append(0) s.append([]) for i in a: j=i%m c[j]=c[j]+1 s[j].append(i) if c[j]==k: print('Yes') for z in s[j]: print(z,end=' ') break if c[j]!=k: print('No') ``` Yes
84,729
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible. Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset. Input First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers. Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset. Output If it is not possible to select k numbers in the desired way, output «No» (without the quotes). Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them. Examples Input 3 2 3 1 8 4 Output Yes 1 4 Input 3 3 3 1 8 4 Output No Input 4 3 5 2 7 7 7 Output Yes 2 7 7 Submitted Solution: ``` def fun(arr,k,m): res = [] for i in range(len(arr)): res.append(arr[i]%m) resset=list(set(res)) maxIndex = 0 for item in resset: if res.count(item)>maxIndex: maxIndex = item if res.count(maxIndex)<k: return [] aaa = [] for i in range(len(res)): if(res[i]==maxIndex): aaa.append(i) return aaa n,k,m=list(map(int,input().split(" "))) arr = list(map(int,input().split(" "))) aaa = fun(arr,k,m) if(len(aaa) == 0): print("NO") else: print("YES") print(" ".join(str(arr[i]) for i in aaa[:k])+" ") ``` No
84,730
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible. Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset. Input First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers. Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset. Output If it is not possible to select k numbers in the desired way, output «No» (without the quotes). Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them. Examples Input 3 2 3 1 8 4 Output Yes 1 4 Input 3 3 3 1 8 4 Output No Input 4 3 5 2 7 7 7 Output Yes 2 7 7 Submitted Solution: ``` from itertools import * [n, k, m] = [int(i) for i in input().split()] arr=list(map(int,input().split())) const = 2 arr2 = [] s = '' s2 = '' for i in combinations(arr, k): arr2.append(i) for i in range(len(arr2)): for j in range(len(arr2[i])): s = s + str(arr2[i][j]) s2 = s2 + str(arr2[i][j]) + ' ' #print(s) flag = True for i in combinations(s, const): if (int(s[0])-int(s[1]))%m != 0: flag = False if flag == True: print('YES') print(s2) break s = '' s2 = '' if flag == False: print('NO') ``` No
84,731
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible. Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset. Input First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers. Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset. Output If it is not possible to select k numbers in the desired way, output «No» (without the quotes). Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them. Examples Input 3 2 3 1 8 4 Output Yes 1 4 Input 3 3 3 1 8 4 Output No Input 4 3 5 2 7 7 7 Output Yes 2 7 7 Submitted Solution: ``` k, n, m = list(map(int, input().split())) multiset = list(map(int, input().split())) lis = [] for i in multiset: if i % m == 0: lis.append(str(i)) if len(lis) >= n: lis = lis[:n] print("Yes") print(" ".join(lis)) quit() lis = [] for j in multiset: if (j + m) in multiset and multiset.count(j + m) + multiset.count(j) >= n: print("Yes") for y in range(multiset.count(j + m)): lis.append(str(j + m)) for x in range(multiset.count(j)): lis.append(str(j)) lis = lis[:n] print(" ".join(lis)) quit() print("No") ``` No
84,732
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible. Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset. Input First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers. Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset. Output If it is not possible to select k numbers in the desired way, output «No» (without the quotes). Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them. Examples Input 3 2 3 1 8 4 Output Yes 1 4 Input 3 3 3 1 8 4 Output No Input 4 3 5 2 7 7 7 Output Yes 2 7 7 Submitted Solution: ``` from collections import defaultdict as dis n,k,m=map(int,input().split()) l=list(map(int,input().split())) d=dis(list) for i in l: d[i%m].append(i) x=[] for i in d: if len(d[i])>=k: x+=d[i][:k] if x: print("Yes"," ".join(map(str,x)),sep='\n') else: print("No") ``` No
84,733
Provide tags and a correct Python 3 solution for this coding contest problem. The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest. The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest. In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in. Input The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100. Output In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist). Examples Input LLUUUR Output OK Input RRUULLDD Output BUG Tags: constructive algorithms, graphs, implementation Correct Solution: ``` def main(): path = input() coordinate = [[0 for i in range(2)] for j in range(len(path)+1)] coordinate[0] = [0,0] left = 0 right = 0 up = 0 down = 0 # start = False for direction in path: if direction == 'U': up += 1 elif direction == 'R': right += 1 elif direction == 'D': down += 1 elif direction == 'L': left += 1 allDirections = [left,up,down,right] while 0 in allDirections: allDirections.remove(0) if len(allDirections) >= 3: minDirection = min(allDirections) i = minDirection + 1 repeatingSequences = [] while i < len(path): currentSet = set(path[i-minDirection - 1:i]) if len(currentSet) == 1: repeatingSequences.append(path[i]) i += minDirection + 1 # start = True else: i += 1 # if start: # break if len(set(repeatingSequences)) == 3: print('BUG') return for i in range(2,len(path)): if path[i] != path[i-1] and path[i] != path[i-2] and path[i-1] != path[i-2]: print('BUG') return for i in range(0,len(path)): if i == 0: if path[i] == 'U': coordinate[i + 1][0] = 0 coordinate[i + 1][1] = 1 elif path[i] == 'R': coordinate[i + 1][0] = 1 coordinate[i + 1][1] = 0 elif path[i] == 'D': coordinate[i + 1][0] = 0 coordinate[i + 1][1] = -1 elif path[i] == 'L': coordinate[i + 1][0] = -1 coordinate[i + 1][1] = 0 else: if path[i] == 'U': coordinate[i + 1][0] = coordinate[i][0] coordinate[i + 1][1] += 1 + coordinate[i][1] elif path[i] == 'R': coordinate[i + 1][1] = coordinate[i][1] coordinate[i + 1][0] += 1 + coordinate[i][0] elif path[i] == 'D': coordinate[i + 1][0] = coordinate[i][0] coordinate[i + 1][1] += -1 + coordinate[i][1] elif path[i] == 'L': coordinate[i + 1][1] = coordinate[i][1] coordinate[i + 1][0] += -1 + coordinate[i][0] coordinateSet = list(set(map(tuple,coordinate))) if len(coordinate) == len(coordinateSet): print('OK') else: print('BUG') main() ```
84,734
Provide tags and a correct Python 3 solution for this coding contest problem. The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest. The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest. In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in. Input The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100. Output In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist). Examples Input LLUUUR Output OK Input RRUULLDD Output BUG Tags: constructive algorithms, graphs, implementation Correct Solution: ``` s=input() a=set() a.add((0,0)) x=0 y=0 dx=[-1,0,1,0,0] dy=[0,1,0,-1,0] d={'L':0,'U':1,'R':2,'D':3} b=False for i in s: x+=dx[d[i]] y+=dy[d[i]] c=0 for j in range(5): if (x+dx[j],y+dy[j]) in a: c+=1 if c>1: b=True break a.add((x,y)) print(['OK','BUG'][b]) ```
84,735
Provide tags and a correct Python 3 solution for this coding contest problem. The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest. The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest. In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in. Input The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100. Output In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist). Examples Input LLUUUR Output OK Input RRUULLDD Output BUG Tags: constructive algorithms, graphs, implementation Correct Solution: ``` #!/usr/bin/env python ''' ' Author: Cheng-Shih Wong ' Email: mob5566@gmail.com ' Date: 2017-08-07 ''' def main(): walk = { 'L': (0, -1), 'U': (-1, 0), 'R': (0, +1), 'D': (+1, 0) } back = { 'L': 'R', 'R': 'L', 'U': 'D', 'D': 'U' } def update(pos, d): return ( pos[0]+walk[d][0], pos[1]+walk[d][1] ) def check(path): vis = set() pos = (0, 0) vis.add(pos) for c in path: pos = update(pos, c) if pos in vis: return False for nei in 'LURD': if nei != back[c] and update(pos, nei) in vis: return False vis.add(pos) return True path = input() print('OK' if check(path) else 'BUG') if __name__ == '__main__': main() ```
84,736
Provide tags and a correct Python 3 solution for this coding contest problem. The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest. The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest. In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in. Input The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100. Output In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist). Examples Input LLUUUR Output OK Input RRUULLDD Output BUG Tags: constructive algorithms, graphs, implementation Correct Solution: ``` s = input() x, y = 0, 0 visited = set() visited.add((x, y)) for i in range(len(s)): prev = x, y if s[i] == 'U': y += 1 elif s[i] == 'D': y -= 1 elif s[i] == 'R': x += 1 else: x -= 1 if (x, y) in visited: print("BUG") exit() neighbors = [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)] for n in neighbors: if n != prev and n in visited: print("BUG") exit() visited.add((x, y)) print("OK") ```
84,737
Provide tags and a correct Python 3 solution for this coding contest problem. The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest. The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest. In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in. Input The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100. Output In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist). Examples Input LLUUUR Output OK Input RRUULLDD Output BUG Tags: constructive algorithms, graphs, implementation Correct Solution: ``` import sys moves = sys.stdin.readline() grid = [] for i in range(500): grid.append([]) for j in range(500): grid[i].append(0) curx, cury = 250, 250 for move in moves: if grid[curx][cury] != 0: print("BUG") sys.exit(0) grid[curx][cury] = 1 if move == 'R': grid[curx][cury+1] = 1 grid[curx-1][cury] = 1 grid[curx][cury-1] = 1 curx += 1 if move == 'L': grid[curx][cury+1] = 1 grid[curx+1][cury] = 1 grid[curx][cury-1] = 1 curx -= 1 if move == 'U': grid[curx+1][cury] = 1 grid[curx-1][cury] = 1 grid[curx][cury-1] = 1 cury += 1 if move == 'D': grid[curx+1][cury] = 1 grid[curx-1][cury] = 1 grid[curx][cury+1] = 1 cury -= 1 print("OK") ```
84,738
Provide tags and a correct Python 3 solution for this coding contest problem. The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest. The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest. In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in. Input The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100. Output In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist). Examples Input LLUUUR Output OK Input RRUULLDD Output BUG Tags: constructive algorithms, graphs, implementation Correct Solution: ``` import math,sys,bisect,heapq from collections import defaultdict,Counter,deque from itertools import groupby,accumulate #sys.setrecursionlimit(200000000) int1 = lambda x: int(x) - 1 #def input(): return sys.stdin.readline().strip() input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__ ilele = lambda: map(int,input().split()) alele = lambda: list(map(int, input().split())) ilelec = lambda: map(int1,input().split()) alelec = lambda: list(map(int1, input().split())) def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] #MOD = 1000000000 + 7 def Y(c): print(["NO","YES"][c]) def y(c): print(["no","yes"][c]) def Yy(c): print(["No","Yes"][c]) A = [(0,0)] S = input() if len(S) == 1: print('OK') exit(0) def check(A,B): x,y = B #print(x,y,A,A[:-1]) if len(A) >= 2: for i,j in A[:-1]: if (x,y) in [(i+1,j),(i-1,j),(i,j-1),(i,j+1)]: return True return False x,y = 0,0 for i in S: #print(x,y) if i == 'L': x-=1 elif i == 'R': x+=1 elif i == 'U': y+=1 else: y-=1 if (x,y) in A: print('BUG') exit(0) if check(A,(x,y)): print('BUG') exit(0) A.append((x,y)) #print(A) print('OK') ```
84,739
Provide tags and a correct Python 3 solution for this coding contest problem. The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest. The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest. In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in. Input The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100. Output In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist). Examples Input LLUUUR Output OK Input RRUULLDD Output BUG Tags: constructive algorithms, graphs, implementation Correct Solution: ``` # maa chudaaye duniya d = [[0,1], [0, -1], [1, 0], [-1, 0], [0, 0]] path = input() vis = [] cur = [0, 0] f = True for p in path: prev = cur if p == 'L': index = 0 elif p == 'R' : index = 1 elif p == 'U' : index = 2 else: index = 3 cur = [cur[0] + d[index][0], cur[1] + d[index][1]] if cur in vis: f = False print('BUG') break for dx, dy in d: vis.append([prev[0] + dx, prev[1] + dy]) if f: print('OK') ```
84,740
Provide tags and a correct Python 3 solution for this coding contest problem. The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest. The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest. In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in. Input The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100. Output In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist). Examples Input LLUUUR Output OK Input RRUULLDD Output BUG Tags: constructive algorithms, graphs, implementation Correct Solution: ``` # import numpy as np s=input() # g=np.zeros((206,206),dtype=int) g=[[0 for i in range(206)] for j in range(206)] x=102 y=102 s=s+'0' i=0 while s[i]: g[x][y]=1 if s[i]=='L': x-=1 elif s[i]=='R': x+=1 elif s[i]=='U': y+=1 elif s[i]=='D': y-=1 if (g[x][y]+g[x-1][y]+g[x+1][y]+g[x][y-1]+g[x][y+1])>1: break i+=1 if s[i]!='0': print('BUG') else: print('OK') ```
84,741
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest. The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest. In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in. Input The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100. Output In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist). Examples Input LLUUUR Output OK Input RRUULLDD Output BUG Submitted Solution: ``` s = input() field = [[0] * (3 * len(s)) for i in range(3 * len(s))] when = [[-2] * (3 * len(s)) for i in range(3 * len(s))] field[0][0] = 1 when[0][0] = -1 x, y = 0, 0 for i in range(len(s)): c = s[i] if c == 'R': x += 1 if c == 'L': x -= 1 if c == 'U': y += 1 if c == 'D': y -= 1 field[x][y] += 1 if field[x][y] > 1: print('BUG') exit() when[x][y] = i for i in range(-len(s), len(s) + 1): for j in range(-len(s), len(s) + 1): if when[i][j] == -2: continue if when[i][j] + 1 < max((when[i + 1][j], when[i - 1][j], when[i][j + 1], when[i][j - 1])): print('BUG') exit() print('OK') ``` Yes
84,742
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest. The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest. In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in. Input The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100. Output In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist). Examples Input LLUUUR Output OK Input RRUULLDD Output BUG Submitted Solution: ``` a = [] INF = 300 k = 300 for i in range(k): a.append([INF] * k) curx = k // 2 cury = k // 2 way = input() a[curx][cury] = 0 a[curx + 1][cury] = 1 a[curx - 1][cury] = 1 a[curx][cury + 1] = 1 a[curx][cury - 1] = 1 step = 0 for i in way: if i == 'L': curx -= 1 if i == 'U': cury += 1 if i == 'R': curx += 1 if i == 'D': cury -= 1 step += 1 if a[curx][cury] != step: print('BUG') exit(0) else: a[curx][cury] = min(step, a[curx][cury]) a[curx + 1][cury] = min(step + 1, a[curx + 1][cury]) a[curx - 1][cury] = min(step + 1, a[curx - 1][cury]) a[curx][cury + 1] = min(step + 1, a[curx][cury + 1]) a[curx][cury - 1] = min(step + 1, a[curx][cury - 1]) #for i in a: # for j in i: # print(j, end=' ') # print() print('OK') ``` Yes
84,743
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest. The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest. In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in. Input The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100. Output In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist). Examples Input LLUUUR Output OK Input RRUULLDD Output BUG Submitted Solution: ``` at = (0, 0) p = [at] moves = input() funcs = { 'L': lambda _: (_[0] - 1, _[1]), 'R': lambda _: (_[0] + 1, _[1]), 'D': lambda _: (_[0], _[1] - 1), 'U': lambda _: (_[0], _[1] + 1), } for move in moves: at = funcs[move](at) p.append(at) ok = True for i in range(len(moves) + 1): for j in range(len(moves) + 1): if abs(i - j) > 1 and abs(p[i][0] - p[j][0]) + abs(p[i][1] - p[j][1]) < 2: ok = False print('OK' if ok else 'BUG') ``` Yes
84,744
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest. The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest. In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in. Input The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100. Output In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist). Examples Input LLUUUR Output OK Input RRUULLDD Output BUG Submitted Solution: ``` def adjacent(move): return [move, (move[0],move[1]-1),(move[0],move[1]+1),(move[0]-1,move[1]),(move[0]+1,move[1])] moves = [(0,0)] inp = input() for move in inp: if move == "R": moves.append((moves[-1][0]+1,moves[-1][1])) elif move == "L": moves.append((moves[-1][0]-1,moves[-1][1])) elif move == "U": moves.append((moves[-1][0],moves[-1][1]+1)) elif move == "D": moves.append((moves[-1][0],moves[-1][1]-1)) goon = True for move in moves: poss = adjacent(move) for loc in poss: if loc in moves[moves.index(move)+2:]: print("BUG") goon = False break; if not goon: break; if goon: print("OK") ``` Yes
84,745
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest. The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest. In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in. Input The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100. Output In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist). Examples Input LLUUUR Output OK Input RRUULLDD Output BUG Submitted Solution: ``` s=input() x,y=0,0 used=set() used.add((x,y)) bo=0 for e in s: if(e=='L'): x+=1 elif(e=='R'): x-=1 elif(e=='U'): y+=1 else: y-=1 a=(x-1,y) in used b=(x+1,y) in used c=(x,y-1) in used d=(x,y+1) in used if(a+b+c+d>1): bo=1 used.add((x,y)) print("OK" if not bo else "BUG") ``` No
84,746
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest. The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest. In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in. Input The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100. Output In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist). Examples Input LLUUUR Output OK Input RRUULLDD Output BUG Submitted Solution: ``` s = input() field = [[0] * (3 * len(s)) for i in range(3 * len(s))] field[0][0] = 1 x, y = 0, 0 for c in s: if c == 'R': x += 1 if c == 'L': x -= 1 if c == 'U': y += 1 if c == 'D': y -= 1 field[x][y] += 1 if field[x][y] > 1: print('BUG') exit() for i in range(-len(s), len(s) + 1): for j in range(-len(s), len(s) + 1): if field[i][j] == field[i + 1][j] == field[i][j + 1] == field[i + 1][j + 1] == 1: print('BUG') exit() print('OK') ``` No
84,747
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest. The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest. In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in. Input The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100. Output In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist). Examples Input LLUUUR Output OK Input RRUULLDD Output BUG Submitted Solution: ``` string = input() geo_map = [[0]*100 for i in range(100)] x = 50 y = 50 geo_map[x][y] = 1 optimal_check = 0 state = True for c in string: optimal_check = 0 if c == 'R': x += 1 elif c == 'L': x -= 1 elif c == 'U': y += 1 else: y -= 1 if geo_map[x][y] == 1: print('BUG') state = False break elif geo_map[x][y] != 1: geo_map[x][y] = 1 if geo_map[x+1][y] == 1: optimal_check += 1 if geo_map[x-1][y] == 1: optimal_check += 1 if geo_map[x][y+1] == 1: optimal_check += 1 if geo_map[x][y-1] == 0: optimal_check += 1 if optimal_check >= 2: print('BUG') state = False break if state: print('OK') ``` No
84,748
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest. The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest. In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in. Input The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100. Output In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist). Examples Input LLUUUR Output OK Input RRUULLDD Output BUG Submitted Solution: ``` from collections import Counter a, b = 0, 0 c = Counter() string = input() for i in string: if c[a, b]: print("BUG") exit() if i == 'R': c[a - 1, b] += 1 c[a, b] += 1 c[a, b - 1] += 1 c[a, b + 1] += 1 a += 1 elif i == 'L': c[a, b] += 1 c[a + 1, b] += 1 c[a, b - 1] += 1 c[a, b + 1] += 1 a -= 1 elif i == 'U': c[a, b] += 1 c[a + 1, b] += 1 c[a - 1, b] += 1 c[a, b - 1] += 1 b += 1 elif i == 'D': c[a + 1, b] += 1 c[a - 1, b] += 1 c[a, b + 1] += 1 c[a, b] += 1 b -= 1 print("OK") ``` No
84,749
Provide tags and a correct Python 3 solution for this coding contest problem. Imp likes his plush toy a lot. <image> Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. Input The only line contains two integers x and y (0 ≤ x, y ≤ 109) — the number of copies and the number of original toys Imp wants to get (including the initial one). Output Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower). Examples Input 6 3 Output Yes Input 4 2 Output No Input 1000 1001 Output Yes Note In the first example, Imp has to apply the machine twice to original toys and then twice to copies. Tags: implementation Correct Solution: ``` x, y = list(map(int, input().split())) if x < y - 1 or (x - y - 1) % 2 != 0 or (y == 1 and x != 0) or y == 0: print("NO") else: print("YES") ```
84,750
Provide tags and a correct Python 3 solution for this coding contest problem. Imp likes his plush toy a lot. <image> Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. Input The only line contains two integers x and y (0 ≤ x, y ≤ 109) — the number of copies and the number of original toys Imp wants to get (including the initial one). Output Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower). Examples Input 6 3 Output Yes Input 4 2 Output No Input 1000 1001 Output Yes Note In the first example, Imp has to apply the machine twice to original toys and then twice to copies. Tags: implementation Correct Solution: ``` x,y = map(int, input().split()) if y > 0 and x >= 0: if (y == 1 and x > 0) or x == y: print('No') elif y == 1 and x == 0 : print('Yes') elif x < y and y > 1: if x == y - 1: print('Yes') else: print('No') elif x > y: x -= y - 1 if x % 2 == 0: print('Yes') else: print('No') else: print('No') ```
84,751
Provide tags and a correct Python 3 solution for this coding contest problem. Imp likes his plush toy a lot. <image> Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. Input The only line contains two integers x and y (0 ≤ x, y ≤ 109) — the number of copies and the number of original toys Imp wants to get (including the initial one). Output Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower). Examples Input 6 3 Output Yes Input 4 2 Output No Input 1000 1001 Output Yes Note In the first example, Imp has to apply the machine twice to original toys and then twice to copies. Tags: implementation Correct Solution: ``` x,y = map(int,input().split()) if (y==0) or (y==1 and x!=0): print("No") else: if (x-(y-1))%2==0 and x>=(y-1) and y!=0: print("Yes") else: print("No") ```
84,752
Provide tags and a correct Python 3 solution for this coding contest problem. Imp likes his plush toy a lot. <image> Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. Input The only line contains two integers x and y (0 ≤ x, y ≤ 109) — the number of copies and the number of original toys Imp wants to get (including the initial one). Output Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower). Examples Input 6 3 Output Yes Input 4 2 Output No Input 1000 1001 Output Yes Note In the first example, Imp has to apply the machine twice to original toys and then twice to copies. Tags: implementation Correct Solution: ``` [copies, originals] = input().split() copies = int(copies) originals = int(originals) if originals < 1 : print("No") elif originals == 1 and copies > 0 : print("No") elif originals > copies + 1: print("No") elif (copies - originals) % 2 == 0 : print("No") else : print("Yes") ```
84,753
Provide tags and a correct Python 3 solution for this coding contest problem. Imp likes his plush toy a lot. <image> Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. Input The only line contains two integers x and y (0 ≤ x, y ≤ 109) — the number of copies and the number of original toys Imp wants to get (including the initial one). Output Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower). Examples Input 6 3 Output Yes Input 4 2 Output No Input 1000 1001 Output Yes Note In the first example, Imp has to apply the machine twice to original toys and then twice to copies. Tags: implementation Correct Solution: ``` def orig_copies(x, y): x1, y1 = y, y - 1 if y1 == 0 and x > 0: return "No" elif y1 > 0 and (x - y1) % 2 == 1: return "No" elif y == 0: return "No" elif x - y1 < 0: return "No" return "Yes" X, Y = [int(i) for i in input().split()] print(orig_copies(X, Y)) ```
84,754
Provide tags and a correct Python 3 solution for this coding contest problem. Imp likes his plush toy a lot. <image> Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. Input The only line contains two integers x and y (0 ≤ x, y ≤ 109) — the number of copies and the number of original toys Imp wants to get (including the initial one). Output Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower). Examples Input 6 3 Output Yes Input 4 2 Output No Input 1000 1001 Output Yes Note In the first example, Imp has to apply the machine twice to original toys and then twice to copies. Tags: implementation Correct Solution: ``` X,Y= input().split() X,Y = [int(X),int(Y)] if X % 2 == 0 and Y % 2 == 0 or X % 2 != 0 and Y % 2 != 0 or X < Y - 1 or Y == 0 or Y == 1 and X != 0: print("No") else: print("Yes") ```
84,755
Provide tags and a correct Python 3 solution for this coding contest problem. Imp likes his plush toy a lot. <image> Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. Input The only line contains two integers x and y (0 ≤ x, y ≤ 109) — the number of copies and the number of original toys Imp wants to get (including the initial one). Output Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower). Examples Input 6 3 Output Yes Input 4 2 Output No Input 1000 1001 Output Yes Note In the first example, Imp has to apply the machine twice to original toys and then twice to copies. Tags: implementation Correct Solution: ``` import sys x, y = map(int, input().split()) print("NO" if (y == 1 and x != 0) or x % 2 == y % 2 or y == 0 or y > x + 1 else "YES") ```
84,756
Provide tags and a correct Python 3 solution for this coding contest problem. Imp likes his plush toy a lot. <image> Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. Input The only line contains two integers x and y (0 ≤ x, y ≤ 109) — the number of copies and the number of original toys Imp wants to get (including the initial one). Output Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower). Examples Input 6 3 Output Yes Input 4 2 Output No Input 1000 1001 Output Yes Note In the first example, Imp has to apply the machine twice to original toys and then twice to copies. Tags: implementation Correct Solution: ``` x,y=map(int,input().split()) if y-1<=0 and x!=0: print("No") elif x<y-1: print("No") else: if (x-y+1)%2==0: print("Yes") else: print("No") ```
84,757
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Imp likes his plush toy a lot. <image> Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. Input The only line contains two integers x and y (0 ≤ x, y ≤ 109) — the number of copies and the number of original toys Imp wants to get (including the initial one). Output Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower). Examples Input 6 3 Output Yes Input 4 2 Output No Input 1000 1001 Output Yes Note In the first example, Imp has to apply the machine twice to original toys and then twice to copies. Submitted Solution: ``` x, y = map(int, input().split()) if y == 0: print('no') elif y == 1: if x == 0: print('yes') else: print('no') else: y -= 1 x = x - y if x >= 0 and x % 2 == 0: print('yes') else: print('no') ``` Yes
84,758
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Imp likes his plush toy a lot. <image> Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. Input The only line contains two integers x and y (0 ≤ x, y ≤ 109) — the number of copies and the number of original toys Imp wants to get (including the initial one). Output Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower). Examples Input 6 3 Output Yes Input 4 2 Output No Input 1000 1001 Output Yes Note In the first example, Imp has to apply the machine twice to original toys and then twice to copies. Submitted Solution: ``` x, y = [int(i) for i in input().split()] if (x>0 and y==1) or y==0 or x+1<y or (x-y+1)%2!=0: print('no') else: print('yes') ``` Yes
84,759
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Imp likes his plush toy a lot. <image> Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. Input The only line contains two integers x and y (0 ≤ x, y ≤ 109) — the number of copies and the number of original toys Imp wants to get (including the initial one). Output Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower). Examples Input 6 3 Output Yes Input 4 2 Output No Input 1000 1001 Output Yes Note In the first example, Imp has to apply the machine twice to original toys and then twice to copies. Submitted Solution: ``` import sys f=sys.stdin.read() x,y = f.split() x,y = int(x), int(y) if (x>=y-1 and (x+y)%2==1 and x>=0 and y>=2) or (x==0 and y==1): sys.stdout.write('Yes') else: sys.stdout.write('No') ``` Yes
84,760
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Imp likes his plush toy a lot. <image> Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. Input The only line contains two integers x and y (0 ≤ x, y ≤ 109) — the number of copies and the number of original toys Imp wants to get (including the initial one). Output Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower). Examples Input 6 3 Output Yes Input 4 2 Output No Input 1000 1001 Output Yes Note In the first example, Imp has to apply the machine twice to original toys and then twice to copies. Submitted Solution: ``` x, y = map(int, input().split()) print('No' if x - y < -1 or (x - y) & 1 is 0 or y is 0 or y is 1 and x else 'Yes') ``` Yes
84,761
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Imp likes his plush toy a lot. <image> Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. Input The only line contains two integers x and y (0 ≤ x, y ≤ 109) — the number of copies and the number of original toys Imp wants to get (including the initial one). Output Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower). Examples Input 6 3 Output Yes Input 4 2 Output No Input 1000 1001 Output Yes Note In the first example, Imp has to apply the machine twice to original toys and then twice to copies. Submitted Solution: ``` x,y=map(int,input().split()) print("Yes") if (x-y)%2==1 and (x-y)>-1 else print('No') ``` No
84,762
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Imp likes his plush toy a lot. <image> Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. Input The only line contains two integers x and y (0 ≤ x, y ≤ 109) — the number of copies and the number of original toys Imp wants to get (including the initial one). Output Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower). Examples Input 6 3 Output Yes Input 4 2 Output No Input 1000 1001 Output Yes Note In the first example, Imp has to apply the machine twice to original toys and then twice to copies. Submitted Solution: ``` #https://codeforces.com/problemset/problem/922/A c,o=map(int,input().split()) o-=1 if c>=o and c-o&1==0: print('Yes') else: print('No') ``` No
84,763
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Imp likes his plush toy a lot. <image> Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. Input The only line contains two integers x and y (0 ≤ x, y ≤ 109) — the number of copies and the number of original toys Imp wants to get (including the initial one). Output Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower). Examples Input 6 3 Output Yes Input 4 2 Output No Input 1000 1001 Output Yes Note In the first example, Imp has to apply the machine twice to original toys and then twice to copies. Submitted Solution: ``` import sys, itertools, math, collections, random def ia(): return [int(i) for i in sys.stdin.readline().strip().split(" ")] def ii(): return int(sys.stdin.readline().strip()) def istr(): return sys.stdin.readline().strip() ### x, y = ia() o = 1 c = 0 if y < 0: print("No") else: c = y - 1 if c > x: print("No") else: d = x - c if d % 2 == 0: print("Yes") else: print("No") ``` No
84,764
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Imp likes his plush toy a lot. <image> Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. Input The only line contains two integers x and y (0 ≤ x, y ≤ 109) — the number of copies and the number of original toys Imp wants to get (including the initial one). Output Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower). Examples Input 6 3 Output Yes Input 4 2 Output No Input 1000 1001 Output Yes Note In the first example, Imp has to apply the machine twice to original toys and then twice to copies. Submitted Solution: ``` c,o=[int(i) for i in input().split()] if o>=2 and o%2==0 and c>=o-1 and c%2!=0: print ("yes") elif o%2!=0 and c>=o-1 and c%2==0: print("yes") else: print("no") ``` No
84,765
Provide tags and a correct Python 3 solution for this coding contest problem. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" — he kept on repeating in his mind. — "Let's take, say, Max, Ilya, Vova — here, they all know each other! And now let's add Dima and Oleg to Vova — none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≤ m ≤ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≤ ai, bi ≤ 5;ai ≠ bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL Tags: graphs, implementation, math Correct Solution: ``` from collections import defaultdict from sys import exit class Graph: def __init__(self): self.adj=defaultdict(list) def add_edge(self,x,y): self.adj[x].append(y) self.adj[y].append(x) def check(self): for i in range(1,6): for j in range(i+1,6): for k in range(j+1,6): if j not in self.adj[i] and k not in self.adj[j] and i not in self.adj[k]: print("WIN") exit(0) if j in self.adj[i] and k in self.adj[j] and i in self.adj[k]: print("WIN") exit(0) print("FAIL") g=Graph() n=int(input()) for _ in range(n): x,y=map(int,input().split()) g.add_edge(x,y) g.check() ```
84,766
Provide tags and a correct Python 3 solution for this coding contest problem. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" — he kept on repeating in his mind. — "Let's take, say, Max, Ilya, Vova — here, they all know each other! And now let's add Dima and Oleg to Vova — none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≤ m ≤ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≤ ai, bi ≤ 5;ai ≠ bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL Tags: graphs, implementation, math Correct Solution: ``` n = int(input()) l = [0, 0, 0, 0, 0] for i in range(n): a, b = map(int, input().split()) for j in range(6): if a == j: l[j-1] += 1 if b == j: l[j-1] += 1 if l.count(2) !=5: print("WIN") else: print("FAIL") # Made By Mostafa_Khaled ```
84,767
Provide tags and a correct Python 3 solution for this coding contest problem. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" — he kept on repeating in his mind. — "Let's take, say, Max, Ilya, Vova — here, they all know each other! And now let's add Dima and Oleg to Vova — none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≤ m ≤ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≤ ai, bi ≤ 5;ai ≠ bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL Tags: graphs, implementation, math Correct Solution: ``` import sys n=int(input()) list1=[[0 for i in range(6)]for i in range(6)] for i in range(n): a,b=map(int,input().split()) list1[a][b]=1 list1[b][a]=1 for i in range(1,6): for j in range(1,6): for k in range(1,6): if(i!=j and j!=k and i!=k): if(list1[i][j]==1 and list1[j][k]==1 and list1[k][i]==1): # print(i,j,k) f=1 print("WIN") sys.exit() elif(list1[i][j]==0 and list1[j][k]==0 and list1[k][i]==0): # print(i,j,k) print("WIN") sys.exit() print("FAIL") ```
84,768
Provide tags and a correct Python 3 solution for this coding contest problem. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" — he kept on repeating in his mind. — "Let's take, say, Max, Ilya, Vova — here, they all know each other! And now let's add Dima and Oleg to Vova — none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≤ m ≤ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≤ ai, bi ≤ 5;ai ≠ bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL Tags: graphs, implementation, math Correct Solution: ``` from collections import defaultdict n = int(input()) d = defaultdict(list) l = [] for i in range(1 , 6): for j in range(i+1 , 6): for k in range(j+1 , 6): l.append([i , j , k]) for i in range(n): u , v = map(int,input().split()) d[u].append(v) d[v].append(u) for i in l : if i[0] in d[i[1]] and i[0] in d[i[2]] and i[1] in d[i[2]]: print('WIN') exit(0) elif i[0] not in d[i[1]] and i[0] not in d[i[2]] and i[1] not in d[i[2]]: print('WIN') exit(0) print('FAIL') ```
84,769
Provide tags and a correct Python 3 solution for this coding contest problem. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" — he kept on repeating in his mind. — "Let's take, say, Max, Ilya, Vova — here, they all know each other! And now let's add Dima and Oleg to Vova — none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≤ m ≤ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≤ ai, bi ≤ 5;ai ≠ bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL Tags: graphs, implementation, math Correct Solution: ``` import sys input = sys.stdin.readline m = int(input()) neigh = {1: [], 2: [], 3: [], 4: [], 5: []} for i in range(m): a, b = map(int, input().split()) neigh[a].append(b) neigh[b].append(a) for key in neigh: if len(neigh[key]) != 2: print("WIN") break else: print("FAIL") ```
84,770
Provide tags and a correct Python 3 solution for this coding contest problem. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" — he kept on repeating in his mind. — "Let's take, say, Max, Ilya, Vova — here, they all know each other! And now let's add Dima and Oleg to Vova — none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≤ m ≤ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≤ ai, bi ≤ 5;ai ≠ bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL Tags: graphs, implementation, math Correct Solution: ``` m = int(input()) L = [[False for i in range(5)] for j in range(5)] for i in range(m): relation = [int(s) for s in input().split()] L[relation[0]-1][relation[1]-1] = True L[relation[1]-1][relation[0]-1] = True bool = False for i in range(3): for j in range(i+1,4): for k in range(j+1,5): bool = bool or (L[i][j] == L[j][k] and L[j][k] == L[i][k]) if bool == False: print("FAIL") else: print("WIN") ```
84,771
Provide tags and a correct Python 3 solution for this coding contest problem. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" — he kept on repeating in his mind. — "Let's take, say, Max, Ilya, Vova — here, they all know each other! And now let's add Dima and Oleg to Vova — none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≤ m ≤ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≤ ai, bi ≤ 5;ai ≠ bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL Tags: graphs, implementation, math Correct Solution: ``` m=int(input()) n={} n[5]=0 n[4]=0 n[3]=0 n[2]=0 n[1]=0 for i in range(m): g=input().split() n[int(g[0])]+=1 n[int(g[1])]+=1 if n[1]==n[2]==n[3]==n[4]==n[5]==2: print('FAIL') exit() print('WIN') ```
84,772
Provide tags and a correct Python 3 solution for this coding contest problem. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" — he kept on repeating in his mind. — "Let's take, say, Max, Ilya, Vova — here, they all know each other! And now let's add Dima and Oleg to Vova — none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≤ m ≤ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≤ ai, bi ≤ 5;ai ≠ bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL Tags: graphs, implementation, math Correct Solution: ``` def s(): m = int(input()) s = set(tuple(sorted(list(map(int,input().split()))))for _ in range(m)) for i in range(1,4): for j in range(i+1,5): for k in range(j+1,6): r = ((i,j)in s) + ((j,k)in s) + ((i,k)in s) if r%3 == 0: print('WIN') return print('FAIL') s() ```
84,773
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" — he kept on repeating in his mind. — "Let's take, say, Max, Ilya, Vova — here, they all know each other! And now let's add Dima and Oleg to Vova — none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≤ m ≤ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≤ ai, bi ≤ 5;ai ≠ bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL Submitted Solution: ``` m = int(input()) l = [0]*5 for i in range(m): a, b = map(int, input().split()) l[a-1] += 1 l[b-1] += 1 if l.count(2) == 5: print('FAIL') else: print('WIN') ``` Yes
84,774
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" — he kept on repeating in his mind. — "Let's take, say, Max, Ilya, Vova — here, they all know each other! And now let's add Dima and Oleg to Vova — none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≤ m ≤ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≤ ai, bi ≤ 5;ai ≠ bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL Submitted Solution: ``` class CodeforcesTask94BSolution: def __init__(self): self.result = '' self.m = 0 self.edges = [] def read_input(self): self.m = int(input()) for x in range(self.m): self.edges.append([int(y) for y in input().split(" ")]) def process_task(self): used = set() conngraph = [set() for x in range(5)] for edge in self.edges: used.add(str(edge)) conngraph[edge[0] - 1].add(edge[1] - 1) conngraph[edge[1] - 1].add(edge[0] - 1) full = {1, 2, 3, 4, 0} nconngraph = [full - x for x in conngraph] has = False for a in range(5): for b in range(5): for c in range(5): if len(set([a, b, c])) == 3: if b in conngraph[a] and c in conngraph[a] and a in conngraph[b] and c in conngraph[b] and b in conngraph[c] and a in conngraph[c]: has = True if b in nconngraph[a] and c in nconngraph[a] and a in nconngraph[b] and c in nconngraph[b] and b in nconngraph[c] and a in nconngraph[c]: has = True self.result = "WIN" if has else "FAIL" def get_result(self): return self.result if __name__ == "__main__": Solution = CodeforcesTask94BSolution() Solution.read_input() Solution.process_task() print(Solution.get_result()) ``` Yes
84,775
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" — he kept on repeating in his mind. — "Let's take, say, Max, Ilya, Vova — here, they all know each other! And now let's add Dima and Oleg to Vova — none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≤ m ≤ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≤ ai, bi ≤ 5;ai ≠ bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL Submitted Solution: ``` m = int(input()) D = [[0]*5 for i in range(5)] for i in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 D[a][b] = 1 D[b][a] = 1 import itertools for c in itertools.combinations(range(5), 3): u, v, w = c if D[u][v] == D[v][w] and D[v][w] == D[w][u]: print('WIN') exit() else: print('FAIL') ``` Yes
84,776
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" — he kept on repeating in his mind. — "Let's take, say, Max, Ilya, Vova — here, they all know each other! And now let's add Dima and Oleg to Vova — none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≤ m ≤ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≤ ai, bi ≤ 5;ai ≠ bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL Submitted Solution: ``` #https://codeforces.com/problemset/problem/94/B def main(): ''' if we visualize friends and relations as a graph, any triangle or any missing triangle would represent a WIN the only way that this can not happen is if every node has exactly to relations. furthermore, in order for this to happen there has to be exactly 5 relations''' n = int(input()) if n != 5: print("WIN") else: relations_per_node = [0,0,0,0,0] for i in range(n): friend1, friend2 = (int(f) for f in input().split()) relations_per_node[friend1-1] += 1 relations_per_node[friend2-1] += 1 for i in range(5): if relations_per_node[i] != 2: print("WIN") break else: print("FAIL") if __name__ == '__main__': main() ``` Yes
84,777
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" — he kept on repeating in his mind. — "Let's take, say, Max, Ilya, Vova — here, they all know each other! And now let's add Dima and Oleg to Vova — none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≤ m ≤ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≤ ai, bi ≤ 5;ai ≠ bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL Submitted Solution: ``` try: t=int(input()) m=[0]*10 for i in range(0,t): a,b=list(map(int,input().split(" "))) m[a]+=1 m[b]+=1 g=0 for i in range(1,6): if (m[i]!=1 or m[i]!=0) and m[i]!=3: g+=1 if g==5: print("FAIL") else: print("WIN") except: pass ``` No
84,778
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" — he kept on repeating in his mind. — "Let's take, say, Max, Ilya, Vova — here, they all know each other! And now let's add Dima and Oleg to Vova — none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≤ m ≤ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≤ ai, bi ≤ 5;ai ≠ bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL Submitted Solution: ``` import sys input = sys.stdin.readline m = int(input()) if m == 0: print("WIN") else: neigh = {1: [], 2: [], 3: [], 4: [], 5: []} for i in range(m): a, b = map(int, input().split()) neigh[a].append(b) neigh[b].append(a) l = len(neigh[1]) for key in neigh: if len(neigh[key]) != l: print("WIN") break else: print("FAIL") ``` No
84,779
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" — he kept on repeating in his mind. — "Let's take, say, Max, Ilya, Vova — here, they all know each other! And now let's add Dima and Oleg to Vova — none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≤ m ≤ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≤ ai, bi ≤ 5;ai ≠ bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL Submitted Solution: ``` from collections import defaultdict as df d=df(list) n=int(input()) visited=[0]*6 for i in range(n): a,b=list(map(int,input().split())) d[a].append(b) d[b].append(a) visited[a]=True visited[b]=True count=0 for i in d: if len(d[i])==1: count+=1 flag=0 for i in d: if len(d[i])>=3: flag=1 break for i in range(1,6): if visited[i]==False: flag=1 break if flag: print('WIN') else: print('FAIL') ``` No
84,780
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" — he kept on repeating in his mind. — "Let's take, say, Max, Ilya, Vova — here, they all know each other! And now let's add Dima and Oleg to Vova — none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input The first line contains an integer m (0 ≤ m ≤ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≤ ai, bi ≤ 5;ai ≠ bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x. Output Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Examples Input 4 1 3 2 3 1 4 5 3 Output WIN Input 5 1 2 2 3 3 4 4 5 5 1 Output FAIL Submitted Solution: ``` #problem 2 num = int(input()) val = [[],[],[],[],[]] for i in range(num): a,b = list(map(int,input().split(" "))) val[a-1].append(b-1) val[b-1].append(a-1) one = False three = False for i in val: if len(i) == 3: three = True if len(i) == 1: one = True if(one or three): print("WIN") else: print('FAIL') ``` No
84,781
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer array of length n. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k. Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not. Input The first line of the input containing integer number n (1 ≤ n ≤ 2 ⋅ 10^5) — the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the array itself. Output On the first line print k — the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers. On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers. Examples Input 7 3 3 4 7 5 6 8 Output 4 2 3 5 6 Input 6 1 3 5 2 4 6 Output 2 1 4 Input 4 10 9 8 7 Output 1 1 Input 9 6 7 8 3 4 5 9 10 11 Output 6 1 2 3 7 8 9 Note All valid answers for the first example (as sequences of indices): * [1, 3, 5, 6] * [2, 3, 5, 6] All valid answers for the second example: * [1, 4] * [2, 5] * [3, 6] All valid answers for the third example: * [1] * [2] * [3] * [4] All valid answers for the fourth example: * [1, 2, 3, 7, 8, 9] Tags: dp Correct Solution: ``` n = int(input()) s = list(map(int,input().split())) rl = {} best_range = range(0) for x in s: run = rl[x] = rl.get(x-1, 0) + 1 r = range(x-run+1, x+1) if len(r) > len(best_range): best_range = r res = list(best_range) size = len(res) output = [] pointer = 0 for i,c in enumerate(s): if res[pointer] == c: output.append(str(i+1)) pointer += 1 if pointer >= size:break print (size) print (' '.join(output)) ```
84,782
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer array of length n. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k. Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not. Input The first line of the input containing integer number n (1 ≤ n ≤ 2 ⋅ 10^5) — the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the array itself. Output On the first line print k — the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers. On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers. Examples Input 7 3 3 4 7 5 6 8 Output 4 2 3 5 6 Input 6 1 3 5 2 4 6 Output 2 1 4 Input 4 10 9 8 7 Output 1 1 Input 9 6 7 8 3 4 5 9 10 11 Output 6 1 2 3 7 8 9 Note All valid answers for the first example (as sequences of indices): * [1, 3, 5, 6] * [2, 3, 5, 6] All valid answers for the second example: * [1, 4] * [2, 5] * [3, 6] All valid answers for the third example: * [1] * [2] * [3] * [4] All valid answers for the fourth example: * [1, 2, 3, 7, 8, 9] Tags: dp Correct Solution: ``` n=int(input()) d={} l=list(map(int,input().split())) val=0 ma=0 for i in range(n) : d[l[i]]=1+d.get(l[i]-1,0) if d[l[i]]>ma : ma=d[l[i]] val=l[i] print(ma) ans=[] for i in range(n-1,-1,-1) : if l[i]==val : ans.append(i+1) val-=1 ans=ans[::-1] print(" ".join(map(str,ans))) ```
84,783
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer array of length n. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k. Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not. Input The first line of the input containing integer number n (1 ≤ n ≤ 2 ⋅ 10^5) — the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the array itself. Output On the first line print k — the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers. On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers. Examples Input 7 3 3 4 7 5 6 8 Output 4 2 3 5 6 Input 6 1 3 5 2 4 6 Output 2 1 4 Input 4 10 9 8 7 Output 1 1 Input 9 6 7 8 3 4 5 9 10 11 Output 6 1 2 3 7 8 9 Note All valid answers for the first example (as sequences of indices): * [1, 3, 5, 6] * [2, 3, 5, 6] All valid answers for the second example: * [1, 4] * [2, 5] * [3, 6] All valid answers for the third example: * [1] * [2] * [3] * [4] All valid answers for the fourth example: * [1, 2, 3, 7, 8, 9] Tags: dp Correct Solution: ``` import sys, math input = lambda :sys.stdin.readline().rstrip() I=lambda:[*map(int,input().split())] n,=I() ; lis=I() from collections import defaultdict dp = defaultdict(int) ; mx = None ; mxcnt = -1 << 64 ind = defaultdict(int) for i in range(n): dp[lis[i]] = dp[lis[i] - 1] + 1 ind[lis[i]] = i if dp[lis[i]] > mxcnt: mxcnt = dp[lis[i]] mx = lis[i] req = mx ; nls = [] for i in range(ind[mx], -1, -1): if lis[i] == req: nls.append(i + 1) req -= 1 print(mxcnt) print(*nls[::-1]) ```
84,784
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer array of length n. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k. Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not. Input The first line of the input containing integer number n (1 ≤ n ≤ 2 ⋅ 10^5) — the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the array itself. Output On the first line print k — the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers. On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers. Examples Input 7 3 3 4 7 5 6 8 Output 4 2 3 5 6 Input 6 1 3 5 2 4 6 Output 2 1 4 Input 4 10 9 8 7 Output 1 1 Input 9 6 7 8 3 4 5 9 10 11 Output 6 1 2 3 7 8 9 Note All valid answers for the first example (as sequences of indices): * [1, 3, 5, 6] * [2, 3, 5, 6] All valid answers for the second example: * [1, 4] * [2, 5] * [3, 6] All valid answers for the third example: * [1] * [2] * [3] * [4] All valid answers for the fourth example: * [1, 2, 3, 7, 8, 9] Tags: dp Correct Solution: ``` n = int(input()) a = [int(x) for x in input().split()] dic={} f=[] for i in range(n): if a[i]-1 in dic: f.append(dic[a[i]-1]+1) else: f.append(1) if a[i] in dic: dic[a[i]] = max(dic[a[i]],f[i]) else: dic[a[i]] = f[i] ans = max(f) print(ans) index = f.index(ans) now = a[index]-ans+1 # print('end =',a[index]) lis = [] for i in range(n): if a[i]==now: lis.append(i+1) now = now+1 print(*lis) ```
84,785
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer array of length n. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k. Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not. Input The first line of the input containing integer number n (1 ≤ n ≤ 2 ⋅ 10^5) — the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the array itself. Output On the first line print k — the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers. On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers. Examples Input 7 3 3 4 7 5 6 8 Output 4 2 3 5 6 Input 6 1 3 5 2 4 6 Output 2 1 4 Input 4 10 9 8 7 Output 1 1 Input 9 6 7 8 3 4 5 9 10 11 Output 6 1 2 3 7 8 9 Note All valid answers for the first example (as sequences of indices): * [1, 3, 5, 6] * [2, 3, 5, 6] All valid answers for the second example: * [1, 4] * [2, 5] * [3, 6] All valid answers for the third example: * [1] * [2] * [3] * [4] All valid answers for the fourth example: * [1, 2, 3, 7, 8, 9] Tags: dp Correct Solution: ``` # TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!! # TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!! # TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!! from sys import stdin, stdout import math #T = int(input()) N = int(input()) #s = input() #N,M = [int(x) for x in stdin.readline().split()] arr = [int(x) for x in stdin.readline().split()] res = 0 record = {} record[arr[0]] = 1 for i in range(1,N): num = arr[i] if num-1 in record: if num not in record: record[num] = record[num-1] + 1 else: record[num] = max(record[num-1] + 1,record[num]) else: if num not in record: record[num] = 1 res = 0 max_end = -1 for num in record: res = max(res,record[num]) if record[num]==res: max_end = num print(res) tmp = [0]*res k = max_end j = 0 for i in range(N-1,-1,-1): if arr[i]==k: k -= 1 tmp[j] = i+1 j += 1 if j==res: break tmp = tmp[::-1] print(*tmp) ```
84,786
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer array of length n. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k. Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not. Input The first line of the input containing integer number n (1 ≤ n ≤ 2 ⋅ 10^5) — the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the array itself. Output On the first line print k — the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers. On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers. Examples Input 7 3 3 4 7 5 6 8 Output 4 2 3 5 6 Input 6 1 3 5 2 4 6 Output 2 1 4 Input 4 10 9 8 7 Output 1 1 Input 9 6 7 8 3 4 5 9 10 11 Output 6 1 2 3 7 8 9 Note All valid answers for the first example (as sequences of indices): * [1, 3, 5, 6] * [2, 3, 5, 6] All valid answers for the second example: * [1, 4] * [2, 5] * [3, 6] All valid answers for the third example: * [1] * [2] * [3] * [4] All valid answers for the fourth example: * [1, 2, 3, 7, 8, 9] Tags: dp Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) dp = dict() for ai in a: if ai not in dp: dp[ai] = 0 if ai - 1 in dp: dp[ai] = max(dp[ai], 1 + dp[ai - 1]) k = max(dp.values()) print(k + 1) pos = -1 for ai in a: if dp[ai] == k: pos = ai idx = [] for i in range(n - 1, -1, -1): if a[i] == pos: idx.append(i + 1) pos -= 1 print(*idx[::-1]) ```
84,787
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer array of length n. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k. Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not. Input The first line of the input containing integer number n (1 ≤ n ≤ 2 ⋅ 10^5) — the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the array itself. Output On the first line print k — the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers. On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers. Examples Input 7 3 3 4 7 5 6 8 Output 4 2 3 5 6 Input 6 1 3 5 2 4 6 Output 2 1 4 Input 4 10 9 8 7 Output 1 1 Input 9 6 7 8 3 4 5 9 10 11 Output 6 1 2 3 7 8 9 Note All valid answers for the first example (as sequences of indices): * [1, 3, 5, 6] * [2, 3, 5, 6] All valid answers for the second example: * [1, 4] * [2, 5] * [3, 6] All valid answers for the third example: * [1] * [2] * [3] * [4] All valid answers for the fourth example: * [1, 2, 3, 7, 8, 9] Tags: dp Correct Solution: ``` n = int(input()) G = list(map(int,input().split())) D = {} M = 0 for i in G: if i-1 in D: D[i] = D[i-1] + 1 else: D[i] = 1 if D[i]>M: M = D[i] Mi = i #print(M,Mi) R = [] A = Mi for i in range(len(G)-1,-1,-1): if G[i] == A: R.append(i+1) A-=1 print(M) print(*R[::-1]) ```
84,788
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer array of length n. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k. Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not. Input The first line of the input containing integer number n (1 ≤ n ≤ 2 ⋅ 10^5) — the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the array itself. Output On the first line print k — the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers. On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers. Examples Input 7 3 3 4 7 5 6 8 Output 4 2 3 5 6 Input 6 1 3 5 2 4 6 Output 2 1 4 Input 4 10 9 8 7 Output 1 1 Input 9 6 7 8 3 4 5 9 10 11 Output 6 1 2 3 7 8 9 Note All valid answers for the first example (as sequences of indices): * [1, 3, 5, 6] * [2, 3, 5, 6] All valid answers for the second example: * [1, 4] * [2, 5] * [3, 6] All valid answers for the third example: * [1] * [2] * [3] * [4] All valid answers for the fourth example: * [1, 2, 3, 7, 8, 9] Tags: dp Correct Solution: ``` import sys from collections import defaultdict def solve(io): N = io.readInt() A = io.readIntArray(N) prev = [-1] * N size = [1] * N last = defaultdict(lambda: -1) for i in range(0, N): idx = last[A[i] - 1] if idx >= 0: prev[i] = idx size[i] = 1 + size[idx] last[A[i]] = i bestIdx = 0 for i in range(1, N): if size[i] > size[bestIdx]: bestIdx = i path = [] curr = bestIdx while curr >= 0: path.append(curr) curr = prev[curr] io.println(len(path)) io.println(' '.join(str(x + 1) for x in reversed(path))) # +---------------------+ # | TEMPLATE CODE BELOW | # | DO NOT MODIFY | # +---------------------+ # TODO: maybe reading byte-by-byte is faster than reading and parsing tokens. class IO: input = None output = None raw = "" buf = [] pos = 0 def __init__(self, inputStream, outputStream): self.input = inputStream self.output = outputStream def readToBuffer(self): self.raw = self.input.readline().rstrip('\n') self.buf = self.raw.split() self.pos = 0 def readString(self): while self.pos == len(self.buf): self.readToBuffer() ans = self.buf[self.pos] self.pos += 1 return ans def readInt(self): return int(self.readString()) def readFloat(self): return float(self.readString()) def readStringArray(self, N, offset=0): arr = [None] * offset for _ in range(0, N): arr.append(self.readString()) return arr def readIntArray(self, N, offset=0): arr = [None] * offset for _ in range(0, N): arr.append(self.readInt()) return arr def readFloatArray(self, N, offset=0): arr = [None] * offset for _ in range(0, N): arr.append(self.readFloat()) return arr def readLine(self): while self.pos == len(self.buf): self.readToBuffer() if self.pos > 0: raise ValueError("Cannot call readline in the middle of a line.") return self.raw def print(self, s): self.output.write(str(s)) def println(self, s): self.print(s) self.print('\n') def flushOutput(self): self.output.flush() pythonIO = IO(sys.stdin, sys.stdout) solve(pythonIO) pythonIO.flushOutput() ```
84,789
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an integer array of length n. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k. Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not. Input The first line of the input containing integer number n (1 ≤ n ≤ 2 ⋅ 10^5) — the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the array itself. Output On the first line print k — the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers. On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers. Examples Input 7 3 3 4 7 5 6 8 Output 4 2 3 5 6 Input 6 1 3 5 2 4 6 Output 2 1 4 Input 4 10 9 8 7 Output 1 1 Input 9 6 7 8 3 4 5 9 10 11 Output 6 1 2 3 7 8 9 Note All valid answers for the first example (as sequences of indices): * [1, 3, 5, 6] * [2, 3, 5, 6] All valid answers for the second example: * [1, 4] * [2, 5] * [3, 6] All valid answers for the third example: * [1] * [2] * [3] * [4] All valid answers for the fourth example: * [1, 2, 3, 7, 8, 9] Submitted Solution: ``` n=int(input()) mp={} values=[0 for i in range(0,n)] lastV=-1 maxLen=0 values=list(map(int,input().split(' '))) for i in range(0,n): if (values[i]-1) in mp: mp[values[i]]=mp[values[i]-1]+1 else: mp[values[i]]=1 if mp[values[i]]>maxLen: maxLen=mp[values[i]] lastV=values[i] currentValue=lastV-maxLen+1 print(maxLen) s="" for i in range(0,len(values)): if values[i] == currentValue: i2=str(i+1)+" " s+=i2 currentValue+=1 print(s) ``` Yes
84,790
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an integer array of length n. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k. Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not. Input The first line of the input containing integer number n (1 ≤ n ≤ 2 ⋅ 10^5) — the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the array itself. Output On the first line print k — the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers. On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers. Examples Input 7 3 3 4 7 5 6 8 Output 4 2 3 5 6 Input 6 1 3 5 2 4 6 Output 2 1 4 Input 4 10 9 8 7 Output 1 1 Input 9 6 7 8 3 4 5 9 10 11 Output 6 1 2 3 7 8 9 Note All valid answers for the first example (as sequences of indices): * [1, 3, 5, 6] * [2, 3, 5, 6] All valid answers for the second example: * [1, 4] * [2, 5] * [3, 6] All valid answers for the third example: * [1] * [2] * [3] * [4] All valid answers for the fourth example: * [1, 2, 3, 7, 8, 9] Submitted Solution: ``` n = int(input()) a = list(map(int,input().split())) d = {} for i in a: d[i] = d.get(i-1,0)+1 e = max(d,key = d.get) m = [] while n: if a[n-1]==e: m.append(n) e-=1 n-=1 print(len(m)) print(*m[::-1]) ``` Yes
84,791
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an integer array of length n. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k. Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not. Input The first line of the input containing integer number n (1 ≤ n ≤ 2 ⋅ 10^5) — the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the array itself. Output On the first line print k — the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers. On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers. Examples Input 7 3 3 4 7 5 6 8 Output 4 2 3 5 6 Input 6 1 3 5 2 4 6 Output 2 1 4 Input 4 10 9 8 7 Output 1 1 Input 9 6 7 8 3 4 5 9 10 11 Output 6 1 2 3 7 8 9 Note All valid answers for the first example (as sequences of indices): * [1, 3, 5, 6] * [2, 3, 5, 6] All valid answers for the second example: * [1, 4] * [2, 5] * [3, 6] All valid answers for the third example: * [1] * [2] * [3] * [4] All valid answers for the fourth example: * [1, 2, 3, 7, 8, 9] Submitted Solution: ``` n = int(input()) a = [*map(int, input().split())] f = {} anslist = [0] * n for i in range(n): try: f[a[i]] = f[a[i] - 1] + 1 except: f[a[i]] = 1 ans = 0 for i in f: if ans < f[i]: ans = f[i] wk1 = i print(ans) wk1 -= ans - 1 for i in range(n): if a[i] == wk1: print(i + 1, end = " ") wk1 += 1 print() ``` Yes
84,792
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an integer array of length n. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k. Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not. Input The first line of the input containing integer number n (1 ≤ n ≤ 2 ⋅ 10^5) — the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the array itself. Output On the first line print k — the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers. On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers. Examples Input 7 3 3 4 7 5 6 8 Output 4 2 3 5 6 Input 6 1 3 5 2 4 6 Output 2 1 4 Input 4 10 9 8 7 Output 1 1 Input 9 6 7 8 3 4 5 9 10 11 Output 6 1 2 3 7 8 9 Note All valid answers for the first example (as sequences of indices): * [1, 3, 5, 6] * [2, 3, 5, 6] All valid answers for the second example: * [1, 4] * [2, 5] * [3, 6] All valid answers for the third example: * [1] * [2] * [3] * [4] All valid answers for the fourth example: * [1, 2, 3, 7, 8, 9] Submitted Solution: ``` input() arr = [int(i) for i in input().strip().split()] d = {} for i in arr: if d.get(i, 0) + 1 > d.get(i+1, 0): d[i+1] = d.get(i, 0) + 1 best = -1 length = 0 for key in d: if d[key] > length: best = key length = d[key] lf = best - length print(length) for i in range(len(arr)): if arr[i] == lf: print(i+1, end=" ") length -= 1 lf += 1 if length == 0: break print() ``` Yes
84,793
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an integer array of length n. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k. Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not. Input The first line of the input containing integer number n (1 ≤ n ≤ 2 ⋅ 10^5) — the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the array itself. Output On the first line print k — the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers. On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers. Examples Input 7 3 3 4 7 5 6 8 Output 4 2 3 5 6 Input 6 1 3 5 2 4 6 Output 2 1 4 Input 4 10 9 8 7 Output 1 1 Input 9 6 7 8 3 4 5 9 10 11 Output 6 1 2 3 7 8 9 Note All valid answers for the first example (as sequences of indices): * [1, 3, 5, 6] * [2, 3, 5, 6] All valid answers for the second example: * [1, 4] * [2, 5] * [3, 6] All valid answers for the third example: * [1] * [2] * [3] * [4] All valid answers for the fourth example: * [1, 2, 3, 7, 8, 9] Submitted Solution: ``` from collections import Counter def read_nums(): return [int(x) for x in input().split()] def main(): n, = read_nums() nums = read_nums() dp = Counter() for i in range(n): dp[nums[i]] = dp[nums[i] - 1] + 1 indexes = {} for i in range(n): indexes[nums[i]] = i last_num = max(dp.items(), key=lambda x: x[1])[0] last_index = indexes[last_num] result = [last_index] while True: last_num -= 1 if last_num not in indexes or indexes[last_num] > last_index: break last_index = indexes[last_num] result.append(last_index) result.reverse() print(len(result)) print(' '.join([str(x + 1) for x in result])) if __name__ == '__main__': main() ``` No
84,794
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an integer array of length n. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k. Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not. Input The first line of the input containing integer number n (1 ≤ n ≤ 2 ⋅ 10^5) — the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the array itself. Output On the first line print k — the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers. On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers. Examples Input 7 3 3 4 7 5 6 8 Output 4 2 3 5 6 Input 6 1 3 5 2 4 6 Output 2 1 4 Input 4 10 9 8 7 Output 1 1 Input 9 6 7 8 3 4 5 9 10 11 Output 6 1 2 3 7 8 9 Note All valid answers for the first example (as sequences of indices): * [1, 3, 5, 6] * [2, 3, 5, 6] All valid answers for the second example: * [1, 4] * [2, 5] * [3, 6] All valid answers for the third example: * [1] * [2] * [3] * [4] All valid answers for the fourth example: * [1, 2, 3, 7, 8, 9] Submitted Solution: ``` import bisect n=int(input()) a=list(map(int,input().split())) d1={} d2={} dp=[0]*(n) for i in range(n): if a[i]-1 in d1: d1[a[i]]=i d2[a[i]]=d1[a[i]-1] dp[i]=dp[d1[a[i]-1]]+1 else: d1[a[i]]=i d2[a[i]]=-1 dp[i]=1 el,ind=max(((j,i) for i,j in enumerate(dp))) lis=[0]*(max(dp)) lis[-1]=ind+1 print(el) for i in range(len(lis)-2,-1,-1): lis[i]=d2[a[lis[i+1]-1]]+1 print(*lis) ``` No
84,795
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an integer array of length n. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k. Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not. Input The first line of the input containing integer number n (1 ≤ n ≤ 2 ⋅ 10^5) — the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the array itself. Output On the first line print k — the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers. On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers. Examples Input 7 3 3 4 7 5 6 8 Output 4 2 3 5 6 Input 6 1 3 5 2 4 6 Output 2 1 4 Input 4 10 9 8 7 Output 1 1 Input 9 6 7 8 3 4 5 9 10 11 Output 6 1 2 3 7 8 9 Note All valid answers for the first example (as sequences of indices): * [1, 3, 5, 6] * [2, 3, 5, 6] All valid answers for the second example: * [1, 4] * [2, 5] * [3, 6] All valid answers for the third example: * [1] * [2] * [3] * [4] All valid answers for the fourth example: * [1, 2, 3, 7, 8, 9] Submitted Solution: ``` n = int(input()) temp = input() a = [int(x) for x in temp.split()] best = dict() seq = dict() recur = dict() best.update({a[0]:1}) #seq.update({a[0]:['1']}) recur.update({a[0]:(a[0],1)}) for i in range(1,n): if a[i]-1 in best: best.update({a[i]:best[a[i]-1]+1}) #seq.update({a[i]:seq[a[i]-1]+[str(i+1)]}) recur.update({a[i]:(a[i]-1,i+1)}) #print(recur) else: best.update({a[i]:1}) #seq.update({a[i]:[str(i+1)]}) recur.update({a[i]:(a[i],i+1)}) #print(recur) ind=0 val=0 for key,value in best.items(): if value>val: ind=key val=value print(val) seq = [] start = ind while(recur[start][0]!=start): #print(start,recur[start][0]) seq.append(recur[start][1]) start = recur[start][0] seq.append(recur[start][1]) #print(seq) seq.reverse() seq=list(map(str, seq)) print(' '.join(seq)) ``` No
84,796
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an integer array of length n. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k. Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not. Input The first line of the input containing integer number n (1 ≤ n ≤ 2 ⋅ 10^5) — the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the array itself. Output On the first line print k — the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers. On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers. Examples Input 7 3 3 4 7 5 6 8 Output 4 2 3 5 6 Input 6 1 3 5 2 4 6 Output 2 1 4 Input 4 10 9 8 7 Output 1 1 Input 9 6 7 8 3 4 5 9 10 11 Output 6 1 2 3 7 8 9 Note All valid answers for the first example (as sequences of indices): * [1, 3, 5, 6] * [2, 3, 5, 6] All valid answers for the second example: * [1, 4] * [2, 5] * [3, 6] All valid answers for the third example: * [1] * [2] * [3] * [4] All valid answers for the fourth example: * [1, 2, 3, 7, 8, 9] Submitted Solution: ``` print("a") print("a") print("a") print("a") print("a") ``` No
84,797
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider a tree (that is, an undirected connected graph without loops) T_1 and a tree T_2. Let's define their cartesian product T_1 × T_2 in a following way. Let V be the set of vertices in T_1 and U be the set of vertices in T_2. Then the set of vertices of graph T_1 × T_2 is V × U, that is, a set of ordered pairs of vertices, where the first vertex in pair is from V and the second — from U. Let's draw the following edges: * Between (v, u_1) and (v, u_2) there is an undirected edge, if u_1 and u_2 are adjacent in U. * Similarly, between (v_1, u) and (v_2, u) there is an undirected edge, if v_1 and v_2 are adjacent in V. Please see the notes section for the pictures of products of trees in the sample tests. Let's examine the graph T_1 × T_2. How much cycles (not necessarily simple) of length k it contains? Since this number can be very large, print it modulo 998244353. The sequence of vertices w_1, w_2, ..., w_k, where w_i ∈ V × U called cycle, if any neighboring vertices are adjacent and w_1 is adjacent to w_k. Cycles that differ only by the cyclic shift or direction of traversal are still considered different. Input First line of input contains three integers — n_1, n_2 and k (2 ≤ n_1, n_2 ≤ 4000, 2 ≤ k ≤ 75) — number of vertices in the first tree, number of vertices in the second tree and the cycle length respectively. Then follow n_1 - 1 lines describing the first tree. Each of this lines contains two integers — v_i, u_i (1 ≤ v_i, u_i ≤ n_1), which define edges of the first tree. Then follow n_2 - 1 lines, which describe the second tree in the same format. It is guaranteed, that given graphs are trees. Output Print one integer — number of cycles modulo 998244353. Examples Input 2 2 2 1 2 1 2 Output 8 Input 2 2 4 1 2 1 2 Output 32 Input 2 3 4 1 2 1 2 1 3 Output 70 Input 4 2 2 1 2 1 3 1 4 1 2 Output 20 Note The following three pictures illustrate graph, which are products of the trees from sample tests. In the first example, the list of cycles of length 2 is as follows: * «AB», «BA» * «BC», «CB» * «AD», «DA» * «CD», «DC» <image> <image> <image> Submitted Solution: ``` print("big pddooppkhu") ``` No
84,798
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider a tree (that is, an undirected connected graph without loops) T_1 and a tree T_2. Let's define their cartesian product T_1 × T_2 in a following way. Let V be the set of vertices in T_1 and U be the set of vertices in T_2. Then the set of vertices of graph T_1 × T_2 is V × U, that is, a set of ordered pairs of vertices, where the first vertex in pair is from V and the second — from U. Let's draw the following edges: * Between (v, u_1) and (v, u_2) there is an undirected edge, if u_1 and u_2 are adjacent in U. * Similarly, between (v_1, u) and (v_2, u) there is an undirected edge, if v_1 and v_2 are adjacent in V. Please see the notes section for the pictures of products of trees in the sample tests. Let's examine the graph T_1 × T_2. How much cycles (not necessarily simple) of length k it contains? Since this number can be very large, print it modulo 998244353. The sequence of vertices w_1, w_2, ..., w_k, where w_i ∈ V × U called cycle, if any neighboring vertices are adjacent and w_1 is adjacent to w_k. Cycles that differ only by the cyclic shift or direction of traversal are still considered different. Input First line of input contains three integers — n_1, n_2 and k (2 ≤ n_1, n_2 ≤ 4000, 2 ≤ k ≤ 75) — number of vertices in the first tree, number of vertices in the second tree and the cycle length respectively. Then follow n_1 - 1 lines describing the first tree. Each of this lines contains two integers — v_i, u_i (1 ≤ v_i, u_i ≤ n_1), which define edges of the first tree. Then follow n_2 - 1 lines, which describe the second tree in the same format. It is guaranteed, that given graphs are trees. Output Print one integer — number of cycles modulo 998244353. Examples Input 2 2 2 1 2 1 2 Output 8 Input 2 2 4 1 2 1 2 Output 32 Input 2 3 4 1 2 1 2 1 3 Output 70 Input 4 2 2 1 2 1 3 1 4 1 2 Output 20 Note The following three pictures illustrate graph, which are products of the trees from sample tests. In the first example, the list of cycles of length 2 is as follows: * «AB», «BA» * «BC», «CB» * «AD», «DA» * «CD», «DC» <image> <image> <image> Submitted Solution: ``` print("big pddoopp") ``` No
84,799