message
stringlengths
2
44.5k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
42
109k
cluster
float64
5
5
__index_level_0__
int64
84
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given n integers a_1, a_2, ..., a_n, such that for each 1≤ i ≤ n holds i-n≤ a_i≤ i-1. Find some nonempty subset of these integers, whose sum is equal to 0. It can be shown that such a subset exists under given constraints. If there are several possible subsets with zero-sum, you can find any of them. Input Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^6). The description of the test cases follows. The first line of each test case contains a single integer n (1≤ n ≤ 10^6). The second line of each test case contains n integers a_1, a_2, ..., a_n (i-n ≤ a_i ≤ i-1). It is guaranteed that the sum of n over all test cases does not exceed 10^6. Output For each test case, output two lines. In the first line, output s (1≤ s ≤ n) — the number of elements in your subset. In the second line, output s integers i_1, i_2, ..., i_s (1≤ i_k ≤ n). All integers have to be pairwise different, and a_{i_1} + a_{i_2} + ... + a_{i_s} has to be equal to 0. If there are several possible subsets with zero-sum, you can find any of them. Example Input 2 5 0 1 2 3 4 4 -3 1 1 1 Output 1 1 4 1 4 3 2 Note In the first example, we get sum is a_1 = 0. In the second example, we get sum is a_1 + a_4 + a_3 + a_2 = 0. Submitted Solution: ``` def sub_array_sum(array,k=0): start_index = -1 first_with_sum = {} first_with_sum[0] = -1 best_start = -1 best_len = 0 current_sum = 0 for i in array: start_index += 1 current_sum += i if current_sum - k in first_with_sum: if start_index - first_with_sum[current_sum - k] > best_len: best_start = first_with_sum[current_sum - k] + 1 best_len = start_index - first_with_sum[current_sum - k] else: first_with_sum[current_sum] = start_index if best_len > 0: return array[best_start:best_start+best_len] n=int(input()) for i in range(n): m=int(input()) s=list(map(int,input().split())) k=sub_array_sum(s) print(len(k)) elem_pos = [] for elem in k: counter = 1 for i in range(len(s)): if s[i] == elem: elem_pos.append(counter) counter = counter + 1 for x in set(elem_pos): print(x,end=' ') print('\n') ```
instruction
0
47,133
5
94,266
No
output
1
47,133
5
94,267
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given n integers a_1, a_2, ..., a_n, such that for each 1≤ i ≤ n holds i-n≤ a_i≤ i-1. Find some nonempty subset of these integers, whose sum is equal to 0. It can be shown that such a subset exists under given constraints. If there are several possible subsets with zero-sum, you can find any of them. Input Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^6). The description of the test cases follows. The first line of each test case contains a single integer n (1≤ n ≤ 10^6). The second line of each test case contains n integers a_1, a_2, ..., a_n (i-n ≤ a_i ≤ i-1). It is guaranteed that the sum of n over all test cases does not exceed 10^6. Output For each test case, output two lines. In the first line, output s (1≤ s ≤ n) — the number of elements in your subset. In the second line, output s integers i_1, i_2, ..., i_s (1≤ i_k ≤ n). All integers have to be pairwise different, and a_{i_1} + a_{i_2} + ... + a_{i_s} has to be equal to 0. If there are several possible subsets with zero-sum, you can find any of them. Example Input 2 5 0 1 2 3 4 4 -3 1 1 1 Output 1 1 4 1 4 3 2 Note In the first example, we get sum is a_1 = 0. In the second example, we get sum is a_1 + a_4 + a_3 + a_2 = 0. Submitted Solution: ``` from sys import stdin, stdout cases = int(input()) for case in range(cases): s = int(input()) arr = [int(x) for x in stdin.readline().split()] n = len(arr) print("arr", arr) for i in range(len(arr)): arr[i] += (n-1)-i visited, index, cycleEntry = [False]*(n), 0, None while True: visited[index] = True index = n-1-arr[index] if visited[index]: cycleEntry = index break index, ct, resStr = n-1-arr[cycleEntry], 1, "" while index != cycleEntry: ct += 1 resStr += str(index+1)+" " index = n-1-arr[index] resStr += str(cycleEntry+1) stdout.write(str(ct)+"\n") stdout.write(resStr+"\n") ```
instruction
0
47,134
5
94,268
No
output
1
47,134
5
94,269
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given n integers a_1, a_2, ..., a_n, such that for each 1≤ i ≤ n holds i-n≤ a_i≤ i-1. Find some nonempty subset of these integers, whose sum is equal to 0. It can be shown that such a subset exists under given constraints. If there are several possible subsets with zero-sum, you can find any of them. Input Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^6). The description of the test cases follows. The first line of each test case contains a single integer n (1≤ n ≤ 10^6). The second line of each test case contains n integers a_1, a_2, ..., a_n (i-n ≤ a_i ≤ i-1). It is guaranteed that the sum of n over all test cases does not exceed 10^6. Output For each test case, output two lines. In the first line, output s (1≤ s ≤ n) — the number of elements in your subset. In the second line, output s integers i_1, i_2, ..., i_s (1≤ i_k ≤ n). All integers have to be pairwise different, and a_{i_1} + a_{i_2} + ... + a_{i_s} has to be equal to 0. If there are several possible subsets with zero-sum, you can find any of them. Example Input 2 5 0 1 2 3 4 4 -3 1 1 1 Output 1 1 4 1 4 3 2 Note In the first example, we get sum is a_1 = 0. In the second example, we get sum is a_1 + a_4 + a_3 + a_2 = 0. Submitted Solution: ``` cases = int(input()) for case in range(cases): s = int(input()) arr = [int(x) for x in input().split()] n = len(arr) for i in range(len(arr)): arr[i] += (n-1)-i visited = [False]*(n) index = 0 cycleEntry = None while True: visited[index] = True index = n-1-arr[index] if visited[index]: cycleEntry = index break index = n-1-arr[cycleEntry] res = [] resStr = "" while index != cycleEntry: resStr += str(index+1)+" " index = n-1-arr[index] res.append(cycleEntry) resStr += str(cycleEntry+1) print(len(res)) print(resStr) ```
instruction
0
47,135
5
94,270
No
output
1
47,135
5
94,271
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given n integers a_1, a_2, ..., a_n, such that for each 1≤ i ≤ n holds i-n≤ a_i≤ i-1. Find some nonempty subset of these integers, whose sum is equal to 0. It can be shown that such a subset exists under given constraints. If there are several possible subsets with zero-sum, you can find any of them. Input Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^6). The description of the test cases follows. The first line of each test case contains a single integer n (1≤ n ≤ 10^6). The second line of each test case contains n integers a_1, a_2, ..., a_n (i-n ≤ a_i ≤ i-1). It is guaranteed that the sum of n over all test cases does not exceed 10^6. Output For each test case, output two lines. In the first line, output s (1≤ s ≤ n) — the number of elements in your subset. In the second line, output s integers i_1, i_2, ..., i_s (1≤ i_k ≤ n). All integers have to be pairwise different, and a_{i_1} + a_{i_2} + ... + a_{i_s} has to be equal to 0. If there are several possible subsets with zero-sum, you can find any of them. Example Input 2 5 0 1 2 3 4 4 -3 1 1 1 Output 1 1 4 1 4 3 2 Note In the first example, we get sum is a_1 = 0. In the second example, we get sum is a_1 + a_4 + a_3 + a_2 = 0. Submitted Solution: ``` from bisect import bisect_left as bl from bisect import bisect_right as br import heapq import math from collections import * from functools import reduce,cmp_to_key import sys input = sys.stdin.readline # M = mod = 998244353 def factors(n):return sorted(list(set(reduce(list.__add__,([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))) # def inv_mod(n):return pow(n, mod - 2, mod) def li():return [int(i) for i in input().rstrip('\n').split(' ')] def st():return input().rstrip('\n') def val():return int(input().rstrip('\n')) def li2():return [i for i in input().rstrip('\n').split(' ')] def li3():return [int(i) for i in input().rstrip('\n')] for _ in range(val()): n = val() l = li() curr = [0] for i in l:curr.append(curr[-1] + i) if 0 in l: print(1) print(l.index(0) + 1) continue cnt = Counter(curr) # print(curr) # print(cnt) for i in cnt: if cnt[i] > 1: a = curr.index(i) # print('a : ',a) b = curr[a + 1:].index(i) break # b -= 1 print(b - a + 1) for i in range(a,b + 1): print(i + 1,end = ' ') print() ```
instruction
0
47,136
5
94,272
No
output
1
47,136
5
94,273
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a system of equations: <image> You should count, how many there are pairs of integers (a, b) (0 ≤ a, b) which satisfy the system. Input A single line contains two integers n, m (1 ≤ n, m ≤ 1000) — the parameters of the system. The numbers on the line are separated by a space. Output On a single line print the answer to the problem. Examples Input 9 3 Output 1 Input 14 28 Output 1 Input 4 20 Output 0 Note In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. Submitted Solution: ``` n, m = map(int,input().split()) s, a, A = 0, 0, 0 while A <= n: if (n - A) ** 2 + a == m: s += 1 a += 1 A += 2 * a - 1 print(s) ```
instruction
0
47,326
5
94,652
Yes
output
1
47,326
5
94,653
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a system of equations: <image> You should count, how many there are pairs of integers (a, b) (0 ≤ a, b) which satisfy the system. Input A single line contains two integers n, m (1 ≤ n, m ≤ 1000) — the parameters of the system. The numbers on the line are separated by a space. Output On a single line print the answer to the problem. Examples Input 9 3 Output 1 Input 14 28 Output 1 Input 4 20 Output 0 Note In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. Submitted Solution: ``` n,m=map(int,input().split()) i=0 for a in range(32): for b in range(32): c=a*a+b d=a+b*b if(c==n and d==m): i+=1 print(i) ```
instruction
0
47,327
5
94,654
Yes
output
1
47,327
5
94,655
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a system of equations: <image> You should count, how many there are pairs of integers (a, b) (0 ≤ a, b) which satisfy the system. Input A single line contains two integers n, m (1 ≤ n, m ≤ 1000) — the parameters of the system. The numbers on the line are separated by a space. Output On a single line print the answer to the problem. Examples Input 9 3 Output 1 Input 14 28 Output 1 Input 4 20 Output 0 Note In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. Submitted Solution: ``` import math inp = [int(x) for x in input().split()] n, m = inp[0], inp[1] max_int = int(math.sqrt(max(inp))) pairs = 0 for a in range(0, max_int+1): for b in range(0, max_int+1): if (a**2 + b) == n and (a + b**2) == m: pairs += 1 print(pairs) ```
instruction
0
47,328
5
94,656
Yes
output
1
47,328
5
94,657
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a system of equations: <image> You should count, how many there are pairs of integers (a, b) (0 ≤ a, b) which satisfy the system. Input A single line contains two integers n, m (1 ≤ n, m ≤ 1000) — the parameters of the system. The numbers on the line are separated by a space. Output On a single line print the answer to the problem. Examples Input 9 3 Output 1 Input 14 28 Output 1 Input 4 20 Output 0 Note In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. Submitted Solution: ``` n, m = list(map(int, input().split())) answer = 0 for a in range(max(n, m) // 2): for b in range(max(n, m) // 2): if a**2 + b is n and a + b**2 is m: answer += 1 print(answer) ```
instruction
0
47,329
5
94,658
No
output
1
47,329
5
94,659
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a system of equations: <image> You should count, how many there are pairs of integers (a, b) (0 ≤ a, b) which satisfy the system. Input A single line contains two integers n, m (1 ≤ n, m ≤ 1000) — the parameters of the system. The numbers on the line are separated by a space. Output On a single line print the answer to the problem. Examples Input 9 3 Output 1 Input 14 28 Output 1 Input 4 20 Output 0 Note In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. Submitted Solution: ``` import math n, m = map(int, input().split()) cnt = 0 for a in range(n): if a * a > n: break b = n - a * a if b >= 0 and a + b * b == m: cnt += 1 print(cnt) ```
instruction
0
47,330
5
94,660
No
output
1
47,330
5
94,661
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a system of equations: <image> You should count, how many there are pairs of integers (a, b) (0 ≤ a, b) which satisfy the system. Input A single line contains two integers n, m (1 ≤ n, m ≤ 1000) — the parameters of the system. The numbers on the line are separated by a space. Output On a single line print the answer to the problem. Examples Input 9 3 Output 1 Input 14 28 Output 1 Input 4 20 Output 0 Note In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. Submitted Solution: ``` n,m=map(int,input().split()) a=[] for i in range (1001): for j in range(1001): if i*i+j==n and i+j*j==m: a.append(i) a.append(j) print(len(a)/2) ```
instruction
0
47,331
5
94,662
No
output
1
47,331
5
94,663
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a system of equations: <image> You should count, how many there are pairs of integers (a, b) (0 ≤ a, b) which satisfy the system. Input A single line contains two integers n, m (1 ≤ n, m ≤ 1000) — the parameters of the system. The numbers on the line are separated by a space. Output On a single line print the answer to the problem. Examples Input 9 3 Output 1 Input 14 28 Output 1 Input 4 20 Output 0 Note In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. Submitted Solution: ``` import math lis=list(input().split(" ")) n=int(lis[0]) m=int(lis[1]) if(m>n): print("0") else: ans=(1+math.sqrt(1-(4*(m-n))))/2 # print(ans) y=int(ans) if(y==ans): print(1) else: print(0) ```
instruction
0
47,332
5
94,664
No
output
1
47,332
5
94,665
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A sequence of non-negative integers a1, a2, ..., an of length n is called a wool sequence if and only if there exists two integers l and r (1 ≤ l ≤ r ≤ n) such that <image>. In other words each wool sequence contains a subsequence of consecutive elements with xor equal to 0. The expression <image> means applying the operation of a bitwise xor to numbers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is marked as "^", in Pascal — as "xor". In this problem you are asked to compute the number of sequences made of n integers from 0 to 2m - 1 that are not a wool sequence. You should print this number modulo 1000000009 (109 + 9). Input The only line of input contains two space-separated integers n and m (1 ≤ n, m ≤ 105). Output Print the required number of sequences modulo 1000000009 (109 + 9) on the only line of output. Examples Input 3 2 Output 6 Note Sequences of length 3 made of integers 0, 1, 2 and 3 that are not a wool sequence are (1, 3, 1), (1, 2, 1), (2, 1, 2), (2, 3, 2), (3, 1, 3) and (3, 2, 3). Submitted Solution: ``` n, m = map(int, input().split()) mod = 10 ** 9 + 9 s, ans = pow(2, m, mod) - 1, 1 for i in range(n): ans = ans * (s - i) % mod; print (ans) ```
instruction
0
47,341
5
94,682
Yes
output
1
47,341
5
94,683
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A sequence of non-negative integers a1, a2, ..., an of length n is called a wool sequence if and only if there exists two integers l and r (1 ≤ l ≤ r ≤ n) such that <image>. In other words each wool sequence contains a subsequence of consecutive elements with xor equal to 0. The expression <image> means applying the operation of a bitwise xor to numbers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is marked as "^", in Pascal — as "xor". In this problem you are asked to compute the number of sequences made of n integers from 0 to 2m - 1 that are not a wool sequence. You should print this number modulo 1000000009 (109 + 9). Input The only line of input contains two space-separated integers n and m (1 ≤ n, m ≤ 105). Output Print the required number of sequences modulo 1000000009 (109 + 9) on the only line of output. Examples Input 3 2 Output 6 Note Sequences of length 3 made of integers 0, 1, 2 and 3 that are not a wool sequence are (1, 3, 1), (1, 2, 1), (2, 1, 2), (2, 3, 2), (3, 1, 3) and (3, 2, 3). Submitted Solution: ``` n,m=map(int,input().split()) ans=pow(2,m,10**9+9) ans-=1 ans%=10**9+9 x=ans-1 x%=10**9+9 for i in range(1,n): ans*=x ans%=10**9+9 x-=1 x%=10**9+9 print(ans) ```
instruction
0
47,342
5
94,684
Yes
output
1
47,342
5
94,685
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A sequence of non-negative integers a1, a2, ..., an of length n is called a wool sequence if and only if there exists two integers l and r (1 ≤ l ≤ r ≤ n) such that <image>. In other words each wool sequence contains a subsequence of consecutive elements with xor equal to 0. The expression <image> means applying the operation of a bitwise xor to numbers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is marked as "^", in Pascal — as "xor". In this problem you are asked to compute the number of sequences made of n integers from 0 to 2m - 1 that are not a wool sequence. You should print this number modulo 1000000009 (109 + 9). Input The only line of input contains two space-separated integers n and m (1 ≤ n, m ≤ 105). Output Print the required number of sequences modulo 1000000009 (109 + 9) on the only line of output. Examples Input 3 2 Output 6 Note Sequences of length 3 made of integers 0, 1, 2 and 3 that are not a wool sequence are (1, 3, 1), (1, 2, 1), (2, 1, 2), (2, 3, 2), (3, 1, 3) and (3, 2, 3). Submitted Solution: ``` n, m = map(int, input().split()) k = pow(2, m, 1000000009) - 1 ans = 1 for i in range(n): ans = (ans * (k - i)) % 1000000009 print(ans) ```
instruction
0
47,343
5
94,686
Yes
output
1
47,343
5
94,687
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A sequence of non-negative integers a1, a2, ..., an of length n is called a wool sequence if and only if there exists two integers l and r (1 ≤ l ≤ r ≤ n) such that <image>. In other words each wool sequence contains a subsequence of consecutive elements with xor equal to 0. The expression <image> means applying the operation of a bitwise xor to numbers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is marked as "^", in Pascal — as "xor". In this problem you are asked to compute the number of sequences made of n integers from 0 to 2m - 1 that are not a wool sequence. You should print this number modulo 1000000009 (109 + 9). Input The only line of input contains two space-separated integers n and m (1 ≤ n, m ≤ 105). Output Print the required number of sequences modulo 1000000009 (109 + 9) on the only line of output. Examples Input 3 2 Output 6 Note Sequences of length 3 made of integers 0, 1, 2 and 3 that are not a wool sequence are (1, 3, 1), (1, 2, 1), (2, 1, 2), (2, 3, 2), (3, 1, 3) and (3, 2, 3). Submitted Solution: ``` n, m = map(int, input().split()) s, d = 1, 1000000009 k = pow(2, m, d) - 1 for i in range(n): s, k = (s * k) % d, k - 1 print(s) ```
instruction
0
47,344
5
94,688
Yes
output
1
47,344
5
94,689
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A sequence of non-negative integers a1, a2, ..., an of length n is called a wool sequence if and only if there exists two integers l and r (1 ≤ l ≤ r ≤ n) such that <image>. In other words each wool sequence contains a subsequence of consecutive elements with xor equal to 0. The expression <image> means applying the operation of a bitwise xor to numbers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is marked as "^", in Pascal — as "xor". In this problem you are asked to compute the number of sequences made of n integers from 0 to 2m - 1 that are not a wool sequence. You should print this number modulo 1000000009 (109 + 9). Input The only line of input contains two space-separated integers n and m (1 ≤ n, m ≤ 105). Output Print the required number of sequences modulo 1000000009 (109 + 9) on the only line of output. Examples Input 3 2 Output 6 Note Sequences of length 3 made of integers 0, 1, 2 and 3 that are not a wool sequence are (1, 3, 1), (1, 2, 1), (2, 1, 2), (2, 3, 2), (3, 1, 3) and (3, 2, 3). Submitted Solution: ``` def fastExpMod(b, e, m): result = 1 while e != 0: if (e&1) == 1: result = (result * b) % m e >>= 1 b = (b*b) % m return result def main(): n, m = map(int, input().strip().split()) mod=1e9+9 ans=(fastExpMod(2,m,mod)-1)%mod temp=ans-1 for i in range(2,n+1): ans=(ans*temp)%mod temp=(temp-1)%mod ans=int(ans%mod) print(ans) if __name__ == '__main__': main() ```
instruction
0
47,345
5
94,690
No
output
1
47,345
5
94,691
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A sequence of non-negative integers a1, a2, ..., an of length n is called a wool sequence if and only if there exists two integers l and r (1 ≤ l ≤ r ≤ n) such that <image>. In other words each wool sequence contains a subsequence of consecutive elements with xor equal to 0. The expression <image> means applying the operation of a bitwise xor to numbers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is marked as "^", in Pascal — as "xor". In this problem you are asked to compute the number of sequences made of n integers from 0 to 2m - 1 that are not a wool sequence. You should print this number modulo 1000000009 (109 + 9). Input The only line of input contains two space-separated integers n and m (1 ≤ n, m ≤ 105). Output Print the required number of sequences modulo 1000000009 (109 + 9) on the only line of output. Examples Input 3 2 Output 6 Note Sequences of length 3 made of integers 0, 1, 2 and 3 that are not a wool sequence are (1, 3, 1), (1, 2, 1), (2, 1, 2), (2, 3, 2), (3, 1, 3) and (3, 2, 3). Submitted Solution: ``` s=input() l=len(set(s)) if(l%2==0): print("CHAT WITH HER!") else: print("IGNORE HIM!") ```
instruction
0
47,346
5
94,692
No
output
1
47,346
5
94,693
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A sequence of non-negative integers a1, a2, ..., an of length n is called a wool sequence if and only if there exists two integers l and r (1 ≤ l ≤ r ≤ n) such that <image>. In other words each wool sequence contains a subsequence of consecutive elements with xor equal to 0. The expression <image> means applying the operation of a bitwise xor to numbers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is marked as "^", in Pascal — as "xor". In this problem you are asked to compute the number of sequences made of n integers from 0 to 2m - 1 that are not a wool sequence. You should print this number modulo 1000000009 (109 + 9). Input The only line of input contains two space-separated integers n and m (1 ≤ n, m ≤ 105). Output Print the required number of sequences modulo 1000000009 (109 + 9) on the only line of output. Examples Input 3 2 Output 6 Note Sequences of length 3 made of integers 0, 1, 2 and 3 that are not a wool sequence are (1, 3, 1), (1, 2, 1), (2, 1, 2), (2, 3, 2), (3, 1, 3) and (3, 2, 3). Submitted Solution: ``` n, m = map(int, input().split()) MOD = 10 ** 9 + 9 out = 1 curr = n for i in range(m): out *= curr curr -= 1 out %= MOD print(out) ```
instruction
0
47,347
5
94,694
No
output
1
47,347
5
94,695
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A sequence of non-negative integers a1, a2, ..., an of length n is called a wool sequence if and only if there exists two integers l and r (1 ≤ l ≤ r ≤ n) such that <image>. In other words each wool sequence contains a subsequence of consecutive elements with xor equal to 0. The expression <image> means applying the operation of a bitwise xor to numbers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is marked as "^", in Pascal — as "xor". In this problem you are asked to compute the number of sequences made of n integers from 0 to 2m - 1 that are not a wool sequence. You should print this number modulo 1000000009 (109 + 9). Input The only line of input contains two space-separated integers n and m (1 ≤ n, m ≤ 105). Output Print the required number of sequences modulo 1000000009 (109 + 9) on the only line of output. Examples Input 3 2 Output 6 Note Sequences of length 3 made of integers 0, 1, 2 and 3 that are not a wool sequence are (1, 3, 1), (1, 2, 1), (2, 1, 2), (2, 3, 2), (3, 1, 3) and (3, 2, 3). Submitted Solution: ``` def main(): n, m = tuple([int(e) for e in input().split()]) mod = 1000000009 upper = 1 << m if n > upper - 1: print('NO') else: s = 1 for i in range(n): s = (s * (upper - i - 1)) % mod print(s) if __name__ == "__main__": main() ```
instruction
0
47,348
5
94,696
No
output
1
47,348
5
94,697
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For each positive integer n consider the integer ψ(n) which is obtained from n by replacing every digit a in the decimal notation of n with the digit (9 - a). We say that ψ(n) is the reflection of n. For example, reflection of 192 equals 807. Note that leading zeros (if any) should be omitted. So reflection of 9 equals 0, reflection of 91 equals 8. Let us call the weight of the number the product of the number and its reflection. Thus, the weight of the number 10 is equal to 10·89 = 890. Your task is to find the maximum weight of the numbers in the given range [l, r] (boundaries are included). Input Input contains two space-separated integers l and r (1 ≤ l ≤ r ≤ 109) — bounds of the range. Output Output should contain single integer number: maximum value of the product n·ψ(n), where l ≤ n ≤ r. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preferred to use cout (also you may use %I64d). Examples Input 3 7 Output 20 Input 1 1 Output 8 Input 8 10 Output 890 Note In the third sample weight of 8 equals 8·1 = 8, weight of 9 equals 9·0 = 0, weight of 10 equals 890. Thus, maximum value of the product is equal to 890. Submitted Solution: ``` def mirror(x): k = 0 a = x while a: k += 1 a //= 10 s = k * '1' return int(s) * 9 - x l, r = map(int, input().split()) max_p = max(l * mirror(l), r * mirror(r)) for s in range(10): n = 5 * 10 ** s if l < n < r: max_p = max(max_p, n * mirror(n)) print(max_p) ```
instruction
0
47,614
5
95,228
Yes
output
1
47,614
5
95,229
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For each positive integer n consider the integer ψ(n) which is obtained from n by replacing every digit a in the decimal notation of n with the digit (9 - a). We say that ψ(n) is the reflection of n. For example, reflection of 192 equals 807. Note that leading zeros (if any) should be omitted. So reflection of 9 equals 0, reflection of 91 equals 8. Let us call the weight of the number the product of the number and its reflection. Thus, the weight of the number 10 is equal to 10·89 = 890. Your task is to find the maximum weight of the numbers in the given range [l, r] (boundaries are included). Input Input contains two space-separated integers l and r (1 ≤ l ≤ r ≤ 109) — bounds of the range. Output Output should contain single integer number: maximum value of the product n·ψ(n), where l ≤ n ≤ r. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preferred to use cout (also you may use %I64d). Examples Input 3 7 Output 20 Input 1 1 Output 8 Input 8 10 Output 890 Note In the third sample weight of 8 equals 8·1 = 8, weight of 9 equals 9·0 = 0, weight of 10 equals 890. Thus, maximum value of the product is equal to 890. Submitted Solution: ``` s = input().split() nl = len(s[0]) nr = len(s[1]) l = int(s[0]) r = int(s[1]) if nr > nl: l = 10 ** (nr - 1) m = 10 ** nr // 2 if l > m: m = l elif r < m: m = r print(m * (10 ** nr - 1 - m)) ```
instruction
0
47,615
5
95,230
Yes
output
1
47,615
5
95,231
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For each positive integer n consider the integer ψ(n) which is obtained from n by replacing every digit a in the decimal notation of n with the digit (9 - a). We say that ψ(n) is the reflection of n. For example, reflection of 192 equals 807. Note that leading zeros (if any) should be omitted. So reflection of 9 equals 0, reflection of 91 equals 8. Let us call the weight of the number the product of the number and its reflection. Thus, the weight of the number 10 is equal to 10·89 = 890. Your task is to find the maximum weight of the numbers in the given range [l, r] (boundaries are included). Input Input contains two space-separated integers l and r (1 ≤ l ≤ r ≤ 109) — bounds of the range. Output Output should contain single integer number: maximum value of the product n·ψ(n), where l ≤ n ≤ r. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preferred to use cout (also you may use %I64d). Examples Input 3 7 Output 20 Input 1 1 Output 8 Input 8 10 Output 890 Note In the third sample weight of 8 equals 8·1 = 8, weight of 9 equals 9·0 = 0, weight of 10 equals 890. Thus, maximum value of the product is equal to 890. Submitted Solution: ``` from math import * l,r=list(map(int,input().split())) a=10**(int(log10(r))+1)-1 if l<=a//2<=r or l<=a//2+1<=r: print(a//2*(a-a//2)) elif r<a//2: print(r*(a-r)) else: print(l*(a-l)) ```
instruction
0
47,616
5
95,232
Yes
output
1
47,616
5
95,233
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For each positive integer n consider the integer ψ(n) which is obtained from n by replacing every digit a in the decimal notation of n with the digit (9 - a). We say that ψ(n) is the reflection of n. For example, reflection of 192 equals 807. Note that leading zeros (if any) should be omitted. So reflection of 9 equals 0, reflection of 91 equals 8. Let us call the weight of the number the product of the number and its reflection. Thus, the weight of the number 10 is equal to 10·89 = 890. Your task is to find the maximum weight of the numbers in the given range [l, r] (boundaries are included). Input Input contains two space-separated integers l and r (1 ≤ l ≤ r ≤ 109) — bounds of the range. Output Output should contain single integer number: maximum value of the product n·ψ(n), where l ≤ n ≤ r. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preferred to use cout (also you may use %I64d). Examples Input 3 7 Output 20 Input 1 1 Output 8 Input 8 10 Output 890 Note In the third sample weight of 8 equals 8·1 = 8, weight of 9 equals 9·0 = 0, weight of 10 equals 890. Thus, maximum value of the product is equal to 890. Submitted Solution: ``` #codeforces 86a: reflection: math l,r=map(int,input().split()) def digits(x): d=0 while (x): d+=1 x//=10 return d def f(n): return n*(10**digits(n)-1-n) def maxInDigits(l,r): #print("dealwith",l,r) mid=10**digits(l)//2 if (r<=mid): return f(r) if (l>=mid): return f(l) return f(mid) if (digits(l)==digits(r)): print(maxInDigits(l,r)) else: ans=max(maxInDigits(l,10**digits(l)-1),maxInDigits(10**(digits(r)-1),r)) if (digits(r)-1>digits(l)): ans=max(ans,maxInDigits(10**(digits(r)-2),10**(digits(r)-1)-1)) print(ans) ```
instruction
0
47,617
5
95,234
Yes
output
1
47,617
5
95,235
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For each positive integer n consider the integer ψ(n) which is obtained from n by replacing every digit a in the decimal notation of n with the digit (9 - a). We say that ψ(n) is the reflection of n. For example, reflection of 192 equals 807. Note that leading zeros (if any) should be omitted. So reflection of 9 equals 0, reflection of 91 equals 8. Let us call the weight of the number the product of the number and its reflection. Thus, the weight of the number 10 is equal to 10·89 = 890. Your task is to find the maximum weight of the numbers in the given range [l, r] (boundaries are included). Input Input contains two space-separated integers l and r (1 ≤ l ≤ r ≤ 109) — bounds of the range. Output Output should contain single integer number: maximum value of the product n·ψ(n), where l ≤ n ≤ r. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preferred to use cout (also you may use %I64d). Examples Input 3 7 Output 20 Input 1 1 Output 8 Input 8 10 Output 890 Note In the third sample weight of 8 equals 8·1 = 8, weight of 9 equals 9·0 = 0, weight of 10 equals 890. Thus, maximum value of the product is equal to 890. Submitted Solution: ``` l,r=[int(x) for x in input().split()] curr=r s=0 while curr: s+=1 curr//=10 first=10**s second=first//2 ans=-1 for i in [r,first,second]: if i>=l and i<=r: curr=i rev='' for k in str(curr): rev+=str(9-int(k)) ans=max(ans,int(rev)*curr) print(ans) ```
instruction
0
47,618
5
95,236
No
output
1
47,618
5
95,237
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For each positive integer n consider the integer ψ(n) which is obtained from n by replacing every digit a in the decimal notation of n with the digit (9 - a). We say that ψ(n) is the reflection of n. For example, reflection of 192 equals 807. Note that leading zeros (if any) should be omitted. So reflection of 9 equals 0, reflection of 91 equals 8. Let us call the weight of the number the product of the number and its reflection. Thus, the weight of the number 10 is equal to 10·89 = 890. Your task is to find the maximum weight of the numbers in the given range [l, r] (boundaries are included). Input Input contains two space-separated integers l and r (1 ≤ l ≤ r ≤ 109) — bounds of the range. Output Output should contain single integer number: maximum value of the product n·ψ(n), where l ≤ n ≤ r. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preferred to use cout (also you may use %I64d). Examples Input 3 7 Output 20 Input 1 1 Output 8 Input 8 10 Output 890 Note In the third sample weight of 8 equals 8·1 = 8, weight of 9 equals 9·0 = 0, weight of 10 equals 890. Thus, maximum value of the product is equal to 890. Submitted Solution: ``` l,r=[int(x) for x in input().split()] curr=r s=0 while curr: s+=1 curr//=10 first=10**s second=first//2 ans=-1 for i in [r,first,second]: curr=i rev='' for k in str(curr): rev+=str(9-int(k)) ans=max(ans,int(rev)*curr) print(ans) ```
instruction
0
47,619
5
95,238
No
output
1
47,619
5
95,239
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For each positive integer n consider the integer ψ(n) which is obtained from n by replacing every digit a in the decimal notation of n with the digit (9 - a). We say that ψ(n) is the reflection of n. For example, reflection of 192 equals 807. Note that leading zeros (if any) should be omitted. So reflection of 9 equals 0, reflection of 91 equals 8. Let us call the weight of the number the product of the number and its reflection. Thus, the weight of the number 10 is equal to 10·89 = 890. Your task is to find the maximum weight of the numbers in the given range [l, r] (boundaries are included). Input Input contains two space-separated integers l and r (1 ≤ l ≤ r ≤ 109) — bounds of the range. Output Output should contain single integer number: maximum value of the product n·ψ(n), where l ≤ n ≤ r. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preferred to use cout (also you may use %I64d). Examples Input 3 7 Output 20 Input 1 1 Output 8 Input 8 10 Output 890 Note In the third sample weight of 8 equals 8·1 = 8, weight of 9 equals 9·0 = 0, weight of 10 equals 890. Thus, maximum value of the product is equal to 890. Submitted Solution: ``` l, r = map(str, input().split()) resl = "" resj = "" if l == 3 and r == 7: for i in l: resl += str(9 - int(i)) for j in r: resj += str(9 - int(j)) if int(resj) * int(r) > int(resl) * int(l): print(int(resj) * int(r)) else: print(int(resl) * int(l)) print(20) ```
instruction
0
47,620
5
95,240
No
output
1
47,620
5
95,241
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For each positive integer n consider the integer ψ(n) which is obtained from n by replacing every digit a in the decimal notation of n with the digit (9 - a). We say that ψ(n) is the reflection of n. For example, reflection of 192 equals 807. Note that leading zeros (if any) should be omitted. So reflection of 9 equals 0, reflection of 91 equals 8. Let us call the weight of the number the product of the number and its reflection. Thus, the weight of the number 10 is equal to 10·89 = 890. Your task is to find the maximum weight of the numbers in the given range [l, r] (boundaries are included). Input Input contains two space-separated integers l and r (1 ≤ l ≤ r ≤ 109) — bounds of the range. Output Output should contain single integer number: maximum value of the product n·ψ(n), where l ≤ n ≤ r. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preferred to use cout (also you may use %I64d). Examples Input 3 7 Output 20 Input 1 1 Output 8 Input 8 10 Output 890 Note In the third sample weight of 8 equals 8·1 = 8, weight of 9 equals 9·0 = 0, weight of 10 equals 890. Thus, maximum value of the product is equal to 890. Submitted Solution: ``` l, r = [int(i) for i in input().split()] s = 10 ** len(str(r)) - 1 e = s // 2 if (r >= e): print(e * (e + 1)) else: print(r * (s - r)) ```
instruction
0
47,621
5
95,242
No
output
1
47,621
5
95,243
Provide a correct Python 3 solution for this coding contest problem. Count the pairs of length-N sequences consisting of integers between 1 and M (inclusive), A_1, A_2, \cdots, A_{N} and B_1, B_2, \cdots, B_{N}, that satisfy all of the following conditions: * A_i \neq B_i, for every i such that 1\leq i\leq N. * A_i \neq A_j and B_i \neq B_j, for every (i, j) such that 1\leq i < j\leq N. Since the count can be enormous, print it modulo (10^9+7). Constraints * 1\leq N \leq M \leq 5\times10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the count modulo (10^9+7). Examples Input 2 2 Output 2 Input 2 3 Output 18 Input 141421 356237 Output 881613484
instruction
0
47,688
5
95,376
"Correct Solution: ``` MOD = 10 ** 9 + 7 N,M = map(int,input().split()) ans1 = 1 for i in range(N): ans1 *= M - i ans1 %= MOD ans2 = [1,M-N] for i in range(2,N+1): ans2.append((ans2[-2] * (i -1) + ans2[-1] * (M - N + i - 1))% MOD) print(ans1 * ans2[N] % MOD) ```
output
1
47,688
5
95,377
Provide a correct Python 3 solution for this coding contest problem. Count the pairs of length-N sequences consisting of integers between 1 and M (inclusive), A_1, A_2, \cdots, A_{N} and B_1, B_2, \cdots, B_{N}, that satisfy all of the following conditions: * A_i \neq B_i, for every i such that 1\leq i\leq N. * A_i \neq A_j and B_i \neq B_j, for every (i, j) such that 1\leq i < j\leq N. Since the count can be enormous, print it modulo (10^9+7). Constraints * 1\leq N \leq M \leq 5\times10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the count modulo (10^9+7). Examples Input 2 2 Output 2 Input 2 3 Output 18 Input 141421 356237 Output 881613484
instruction
0
47,689
5
95,378
"Correct Solution: ``` n, m = map(int, input().split()) N = m + 100 MOD = 10 ** 9 + 7 fact = [0 for _ in range(N)] invfact = [0 for _ in range(N)] fact[0] = 1 for i in range(1, N): fact[i] = i * fact[i - 1] % MOD invfact[N - 1] = pow(fact[N - 1], MOD - 2, MOD) for i in range(N - 2, -1, -1): invfact[i] = invfact[i + 1] * (i + 1) % MOD def nCk(n, k): if k < 0 or n < k: return 0 else: return fact[n] * invfact[k] * invfact[n - k] % MOD def nPk(n, k): return fact[n] * invfact[n - k] % MOD ans = 0 sign = 1 for i in range(n + 1): ans = (ans + nPk(m, i) * nCk(n, i) * nPk(m - i, n - i) ** 2 * sign) % MOD sign *= -1 print(ans) ```
output
1
47,689
5
95,379
Provide a correct Python 3 solution for this coding contest problem. Count the pairs of length-N sequences consisting of integers between 1 and M (inclusive), A_1, A_2, \cdots, A_{N} and B_1, B_2, \cdots, B_{N}, that satisfy all of the following conditions: * A_i \neq B_i, for every i such that 1\leq i\leq N. * A_i \neq A_j and B_i \neq B_j, for every (i, j) such that 1\leq i < j\leq N. Since the count can be enormous, print it modulo (10^9+7). Constraints * 1\leq N \leq M \leq 5\times10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the count modulo (10^9+7). Examples Input 2 2 Output 2 Input 2 3 Output 18 Input 141421 356237 Output 881613484
instruction
0
47,690
5
95,380
"Correct Solution: ``` def prepare(n, MOD): # n! の計算 f = 1 fn=[1]*(n+1) for m in range(1, n + 1): f *= m f %= MOD fn[m]=f # n!^-1 の計算 inv = pow(f, MOD - 2, MOD) # n!^-1 - 1!^-1 の計算 invs = [1] * (n + 1) invs[n] = inv for m in range(n, 1, -1): inv *= m inv %= MOD invs[m - 1] = inv return fn, invs def main(): n,m=map(int,input().split()) MOD=10**9+7 fn,invs=prepare(m,MOD) ans=0 for i in range(n+1): x=(fn[m-i]*invs[m-n])%MOD x=(x*fn[n]*invs[i]*invs[n-i])%MOD x*=(-1)**i ans+=x ans=(ans*fn[m]*invs[m-n])%MOD print(ans) if __name__ == '__main__': main() ```
output
1
47,690
5
95,381
Provide a correct Python 3 solution for this coding contest problem. Count the pairs of length-N sequences consisting of integers between 1 and M (inclusive), A_1, A_2, \cdots, A_{N} and B_1, B_2, \cdots, B_{N}, that satisfy all of the following conditions: * A_i \neq B_i, for every i such that 1\leq i\leq N. * A_i \neq A_j and B_i \neq B_j, for every (i, j) such that 1\leq i < j\leq N. Since the count can be enormous, print it modulo (10^9+7). Constraints * 1\leq N \leq M \leq 5\times10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the count modulo (10^9+7). Examples Input 2 2 Output 2 Input 2 3 Output 18 Input 141421 356237 Output 881613484
instruction
0
47,691
5
95,382
"Correct Solution: ``` import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) N, M = mapint() mod = 10**9+7 pos = [1]+[0]*M neg = [1]+[0]*M n = 1 for i in range(1, M+1): n = n*i%mod pos[i] = n neg[i] = pow(n, mod-2, mod) ans = 0 def comb(n, r): return pos[n]*neg[r]*neg[n-r]%mod # i個数字以上が被っている時の通り数 for i in range(N+1): ans += (-1)**i*comb(N, i)*pos[M]*neg[M-i]*(pow(pos[M-i]*neg[M-N], 2, mod)) ans %= mod print(ans) ```
output
1
47,691
5
95,383
Provide a correct Python 3 solution for this coding contest problem. Count the pairs of length-N sequences consisting of integers between 1 and M (inclusive), A_1, A_2, \cdots, A_{N} and B_1, B_2, \cdots, B_{N}, that satisfy all of the following conditions: * A_i \neq B_i, for every i such that 1\leq i\leq N. * A_i \neq A_j and B_i \neq B_j, for every (i, j) such that 1\leq i < j\leq N. Since the count can be enormous, print it modulo (10^9+7). Constraints * 1\leq N \leq M \leq 5\times10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the count modulo (10^9+7). Examples Input 2 2 Output 2 Input 2 3 Output 18 Input 141421 356237 Output 881613484
instruction
0
47,692
5
95,384
"Correct Solution: ``` n, m = map(int, input().split()) mod = 10**9 + 7 factorial = [1] inverse = [1] for i in range(1, m+1): factorial.append(factorial[-1] * i % mod) inverse.append(pow(factorial[-1], mod - 2, mod)) def comb(n, r, mod): if n < r or r < 0: return 0 elif r == 0: return 1 return factorial[n] * inverse[r] * inverse[n - r] % mod def perm(n, r, mod): if n < r or r < 0: return 0 elif r == 0: return 1 return factorial[n] * inverse[n - r] % mod ans = 0 for i in range(n+1): ans += (-1)**i * comb(n, i, mod) * perm(m, i, mod) * (perm(m-i, n-i, mod))**2 ans %= mod print(ans) ```
output
1
47,692
5
95,385
Provide a correct Python 3 solution for this coding contest problem. Count the pairs of length-N sequences consisting of integers between 1 and M (inclusive), A_1, A_2, \cdots, A_{N} and B_1, B_2, \cdots, B_{N}, that satisfy all of the following conditions: * A_i \neq B_i, for every i such that 1\leq i\leq N. * A_i \neq A_j and B_i \neq B_j, for every (i, j) such that 1\leq i < j\leq N. Since the count can be enormous, print it modulo (10^9+7). Constraints * 1\leq N \leq M \leq 5\times10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the count modulo (10^9+7). Examples Input 2 2 Output 2 Input 2 3 Output 18 Input 141421 356237 Output 881613484
instruction
0
47,693
5
95,386
"Correct Solution: ``` n,m = map(int,input().split()) mod = 10 ** 9 + 7 g1 = [1,1] ### g1[i]はiの階乗の逆数 g2 = [0,1] ###g2[i]はiの逆数 for i in range(2,m + 1): g2.append((-g2[mod % i] * (mod//i))% mod) g1.append(g1[-1] * g2[-1] % mod) g3 = [1,m - n + 1] for i in range(n - 1): g3.append((g3[-1] * (m - n + i + 2))%mod) x = 1 for i in range(2,n + 1): x = (x*i)%mod k = 0 for i in range(1,n + 1): k = (k + (-1)**i * x * g1[i] * g1[n - i] * g3[n - i])%mod k = (k + g3[n])%mod k = (k * g3[n])%mod print(k) ```
output
1
47,693
5
95,387
Provide a correct Python 3 solution for this coding contest problem. Count the pairs of length-N sequences consisting of integers between 1 and M (inclusive), A_1, A_2, \cdots, A_{N} and B_1, B_2, \cdots, B_{N}, that satisfy all of the following conditions: * A_i \neq B_i, for every i such that 1\leq i\leq N. * A_i \neq A_j and B_i \neq B_j, for every (i, j) such that 1\leq i < j\leq N. Since the count can be enormous, print it modulo (10^9+7). Constraints * 1\leq N \leq M \leq 5\times10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the count modulo (10^9+7). Examples Input 2 2 Output 2 Input 2 3 Output 18 Input 141421 356237 Output 881613484
instruction
0
47,694
5
95,388
"Correct Solution: ``` MOD=10**9+7 N, M = map(int, input().split()) FCT = [1] for i in range(1, M+1): FCT.append((FCT[-1] * i)%MOD) def pmu(n, r, mod=MOD): return (FCT[n] * pow(FCT[n-r], mod-2, mod)) % mod def cmb(n, r, mod=MOD): return (pmu(n, r) * pow(FCT[r], mod-2, mod)) % mod def solve(): # {the num of case B when A=range(1,N+1)} x {permutation of A} # use inclusion-exclusion principle against former ans = 0 for i in range(N+1): cp = (cmb(N, i) * pmu(M-i, N-i))%MOD ans = (ans + (1 if i%2==0 else -1) * cp) % MOD return (ans * pmu(M, N)) % MOD if __name__ == "__main__": print(solve()) ```
output
1
47,694
5
95,389
Provide a correct Python 3 solution for this coding contest problem. Count the pairs of length-N sequences consisting of integers between 1 and M (inclusive), A_1, A_2, \cdots, A_{N} and B_1, B_2, \cdots, B_{N}, that satisfy all of the following conditions: * A_i \neq B_i, for every i such that 1\leq i\leq N. * A_i \neq A_j and B_i \neq B_j, for every (i, j) such that 1\leq i < j\leq N. Since the count can be enormous, print it modulo (10^9+7). Constraints * 1\leq N \leq M \leq 5\times10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the count modulo (10^9+7). Examples Input 2 2 Output 2 Input 2 3 Output 18 Input 141421 356237 Output 881613484
instruction
0
47,695
5
95,390
"Correct Solution: ``` N,M=map(int,input().split()) mod=10**9+7 def cmb(n,r): global mod if r<0 or r>n: return 0 return (g1[n]*g2[r]*g2[n-r])%mod def perm(n,r): global mod if r<0 or r>n: return 0 return (g1[n]*g2[n-r])%mod g1=[1,1] g2=[1,1] inv=[0,1] for i in range(2,N+M+10): g1.append((g1[-1]*i)%mod) inv.append((-inv[mod%i]*(mod//i))%mod) g2.append((g2[-1]*inv[-1])%mod) P=0 for i in range(N+1): P=(P+pow(-1,i&1)*cmb(N,i)*perm(M,i)*perm(M-i,N-i)**2)%mod print(P) ```
output
1
47,695
5
95,391
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Count the pairs of length-N sequences consisting of integers between 1 and M (inclusive), A_1, A_2, \cdots, A_{N} and B_1, B_2, \cdots, B_{N}, that satisfy all of the following conditions: * A_i \neq B_i, for every i such that 1\leq i\leq N. * A_i \neq A_j and B_i \neq B_j, for every (i, j) such that 1\leq i < j\leq N. Since the count can be enormous, print it modulo (10^9+7). Constraints * 1\leq N \leq M \leq 5\times10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the count modulo (10^9+7). Examples Input 2 2 Output 2 Input 2 3 Output 18 Input 141421 356237 Output 881613484 Submitted Solution: ``` n,m=map(int,input().split()) mod=10**9+7 framod=[1] def framod_calc(n, mod, a=1): for i in range(1,n+1): a=a * i % mod framod.append(a) def permmod(n, k, mod): a=framod[n] c=framod[n-k] return (a * pow(c, mod-2, mod)) % mod def combmod(n, k, mod): a=framod[n] b=framod[k] c=framod[n-k] return (a * pow(b, mod-2, mod) * pow(c, mod-2, mod)) % mod framod_calc(m, mod) a=combmod(m,n,mod)*framod[n] a%=mod b=0 for k in range(n+1): b+=((((-1)**k)*combmod(n,k,mod)*combmod(m-k,n-k,mod))%mod*framod[n-k])%mod b%=mod print(a*b%mod) ```
instruction
0
47,696
5
95,392
Yes
output
1
47,696
5
95,393
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Count the pairs of length-N sequences consisting of integers between 1 and M (inclusive), A_1, A_2, \cdots, A_{N} and B_1, B_2, \cdots, B_{N}, that satisfy all of the following conditions: * A_i \neq B_i, for every i such that 1\leq i\leq N. * A_i \neq A_j and B_i \neq B_j, for every (i, j) such that 1\leq i < j\leq N. Since the count can be enormous, print it modulo (10^9+7). Constraints * 1\leq N \leq M \leq 5\times10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the count modulo (10^9+7). Examples Input 2 2 Output 2 Input 2 3 Output 18 Input 141421 356237 Output 881613484 Submitted Solution: ``` N, M = map(int, input().split()) mod = 10 ** 9 + 7 fac = [1] for i in range(1, N + M + 10) : fac.append(fac[-1] * i % mod) inv = [pow(fac[-1], mod - 2, mod)] for i in range(N + M + 9, 0, -1) : inv.append(inv[-1] * i % mod) inv = inv[::-1] def comb(n, r) : if n >= r and r >= 0 : return fac[n] * inv[n - r] * inv[r] % mod return 1 ret = 0 for i in range(N + 1) : if i % 2 == 1 : sign = -1 else : sign = 1 x = sign * comb(M, i) * comb(N, i) * fac[i] % mod x *= (fac[M - i] ** 2) * (inv[M - N] ** 2) % mod ret += x % mod ret %= mod print(ret) ```
instruction
0
47,697
5
95,394
Yes
output
1
47,697
5
95,395
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Count the pairs of length-N sequences consisting of integers between 1 and M (inclusive), A_1, A_2, \cdots, A_{N} and B_1, B_2, \cdots, B_{N}, that satisfy all of the following conditions: * A_i \neq B_i, for every i such that 1\leq i\leq N. * A_i \neq A_j and B_i \neq B_j, for every (i, j) such that 1\leq i < j\leq N. Since the count can be enormous, print it modulo (10^9+7). Constraints * 1\leq N \leq M \leq 5\times10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the count modulo (10^9+7). Examples Input 2 2 Output 2 Input 2 3 Output 18 Input 141421 356237 Output 881613484 Submitted Solution: ``` import sys input = sys.stdin.readline U = 5*10**5 MOD = 10**9+7 fact = [1]*(U+1) fact_inv = [1]*(U+1) for i in range(1,U+1): fact[i] = (fact[i-1]*i)%MOD fact_inv[U] = pow(fact[U], MOD-2, MOD) for i in range(U,0,-1): fact_inv[i-1] = (fact_inv[i]*i)%MOD def perm(n, k): if k < 0 or k > n: return 0 z = fact[n] z *= fact_inv[n-k] z %= MOD return z def comb(n, k): if k < 0 or k > n: return 0 z = fact[n] z *= fact_inv[k] z *= fact_inv[n-k] z %= MOD return z n, m = map(int, input().split()) ans = 0 for i in range(n+1): temp = (-1)**i * comb(n, i) temp *= perm(m, i) temp %= MOD temp *= perm(m-i, n-i)**2 temp %= MOD ans += temp ans %= MOD print(ans) ```
instruction
0
47,698
5
95,396
Yes
output
1
47,698
5
95,397
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Count the pairs of length-N sequences consisting of integers between 1 and M (inclusive), A_1, A_2, \cdots, A_{N} and B_1, B_2, \cdots, B_{N}, that satisfy all of the following conditions: * A_i \neq B_i, for every i such that 1\leq i\leq N. * A_i \neq A_j and B_i \neq B_j, for every (i, j) such that 1\leq i < j\leq N. Since the count can be enormous, print it modulo (10^9+7). Constraints * 1\leq N \leq M \leq 5\times10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the count modulo (10^9+7). Examples Input 2 2 Output 2 Input 2 3 Output 18 Input 141421 356237 Output 881613484 Submitted Solution: ``` # E - NEQ N, M = map(int, input().split()) MOD = 10 ** 9 + 7 fac = [1, 1] inv = [0, 1] finv = [1, 1] for i in range(2, M+1): fac.append(fac[-1] * i % MOD) inv.append(MOD - inv[MOD%i] * (MOD//i) % MOD) finv.append(finv[-1] * inv[-1] % MOD) fixed = (fac[N] * fac[M] * pow(finv[M-N], 2, MOD)) % MOD def f(k): return (fac[M-k] * finv[k] * finv[N-k]) % MOD ans = 0 for i in range(N+1): ans = (ans + f(i) * pow(-1, i)) % MOD print((fixed * ans) % MOD) ```
instruction
0
47,699
5
95,398
Yes
output
1
47,699
5
95,399
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Count the pairs of length-N sequences consisting of integers between 1 and M (inclusive), A_1, A_2, \cdots, A_{N} and B_1, B_2, \cdots, B_{N}, that satisfy all of the following conditions: * A_i \neq B_i, for every i such that 1\leq i\leq N. * A_i \neq A_j and B_i \neq B_j, for every (i, j) such that 1\leq i < j\leq N. Since the count can be enormous, print it modulo (10^9+7). Constraints * 1\leq N \leq M \leq 5\times10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the count modulo (10^9+7). Examples Input 2 2 Output 2 Input 2 3 Output 18 Input 141421 356237 Output 881613484 Submitted Solution: ``` N, M = list(map(int, input().split())) class mod_pack: def __init__(self, MOD, MAX): self.MOD = MOD self.MAX = MAX self.fac, self.ifac = [1]*(MAX+1), [1]*(MAX+1) for i in range(1, MAX+1): self.fac[i] = self.fac[i-1]*i % MOD self.ifac[i] = self.ifac[i-1] * self.mpow(i, MOD-2) % MOD def mpow(self, x, n): ans = 1 while n!=0: if n&1: ans = ans*x % self.MOD x = x*x % self.MOD n = n >> 1 return ans def mcomb(self, m, n): if (m==0 and n==0): return 1 return (self.ifac[m-n] * self.ifac[n] % self.MOD) * self.fac[m] % self.MOD def mperm(self, m, n): if (m < n): return 0 return self.ifac[m-n] * self.fac[m] % MOD mp = mod_pack(10**9+7, M) tot = mp.mperm(M, N) ans = 0 for k in range(1, N+1): # print(k, mp.mcomb(N, k), mp.mperm(M-k, N-k)) ans = (ans + (-1)**(k-1) * mp.mcomb(N, k) * mp.mperm(M-k, N-k)) % MOD print((tot * (tot - ans))%MOD) ```
instruction
0
47,700
5
95,400
No
output
1
47,700
5
95,401
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Count the pairs of length-N sequences consisting of integers between 1 and M (inclusive), A_1, A_2, \cdots, A_{N} and B_1, B_2, \cdots, B_{N}, that satisfy all of the following conditions: * A_i \neq B_i, for every i such that 1\leq i\leq N. * A_i \neq A_j and B_i \neq B_j, for every (i, j) such that 1\leq i < j\leq N. Since the count can be enormous, print it modulo (10^9+7). Constraints * 1\leq N \leq M \leq 5\times10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the count modulo (10^9+7). Examples Input 2 2 Output 2 Input 2 3 Output 18 Input 141421 356237 Output 881613484 Submitted Solution: ``` fac=[1]*505050 inv=[1]*505050 finv=[1]*505050 mod=1000000007 for i in range(1,500010): fac[i]=fac[i-1]*i%mod inv[i]=(mod-inv[mod%i]*(mod//i))%mod finv[i]=finv[i-1]*inv[i]%mod def C(n,r): if n<0 or r<0 or n<r: return 0 return fac[n]*inv[n-r]*inv[r]%mod n,m=map(int,input().split()) ans=0 for i in range(N+1): ans+=C(n,i)*fac[M]*finv[M-i]*(C(M-i,N-i)**2)*(1 if i%2==0 else -1) % mod print(ans%mod) ```
instruction
0
47,701
5
95,402
No
output
1
47,701
5
95,403
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Count the pairs of length-N sequences consisting of integers between 1 and M (inclusive), A_1, A_2, \cdots, A_{N} and B_1, B_2, \cdots, B_{N}, that satisfy all of the following conditions: * A_i \neq B_i, for every i such that 1\leq i\leq N. * A_i \neq A_j and B_i \neq B_j, for every (i, j) such that 1\leq i < j\leq N. Since the count can be enormous, print it modulo (10^9+7). Constraints * 1\leq N \leq M \leq 5\times10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the count modulo (10^9+7). Examples Input 2 2 Output 2 Input 2 3 Output 18 Input 141421 356237 Output 881613484 Submitted Solution: ``` N,M=map(int,input().split()) mod=10**9+7 fac=[1]*(M+1) for i in range(2,M+1): fac[i]=fac[i-1]*i%mod inv=[1]*(M+1) inv[M]=pow(fac[M],mod-2,mod) for i in range(M-1,1,-1): inv[i]=inv[i+1]*(i+1)%mod def comb(n,r): if r>n or r<0: return 0 ret=fac[n]*inv[r]*inv[n-r]%mod return ret ans_A=comb(M,N)*fac[N]%mod ans_B_0=fac[N]-1 ans_B=0 for i in range(1,M-N+1): ans_B+=ans_B_0*comb(N,i)%mod*comb(M-N,N-i)%mod ans_B%=mod ans_B+=ans_B_0 print(ans_A*ans_B%mod) ```
instruction
0
47,702
5
95,404
No
output
1
47,702
5
95,405
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Count the pairs of length-N sequences consisting of integers between 1 and M (inclusive), A_1, A_2, \cdots, A_{N} and B_1, B_2, \cdots, B_{N}, that satisfy all of the following conditions: * A_i \neq B_i, for every i such that 1\leq i\leq N. * A_i \neq A_j and B_i \neq B_j, for every (i, j) such that 1\leq i < j\leq N. Since the count can be enormous, print it modulo (10^9+7). Constraints * 1\leq N \leq M \leq 5\times10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the count modulo (10^9+7). Examples Input 2 2 Output 2 Input 2 3 Output 18 Input 141421 356237 Output 881613484 Submitted Solution: ``` %%writefile e.py #!/usr/bin/python3 # -*- coding:utf-8 -*- def p(n, k, mod): x = 1 for ik in range(k): x *= (n - ik) x %= mod return x MAX = 10 ** 9 + 7 def main(): n, m = map(int, input().strip().split()) s = 0 nck = 1 mpk = 1 mkpnk = p(m, n, MAX) for k in range(0, n+1): if 0 < k <= n: nck *= (n - (k-1)) * pow(k, MAX-2, MAX) nck %= MAX if 0 < k <= m: mpk *= (m - (k-1)) mpk %= MAX if 0 < k <= n: mkpnk *= pow(m - (k - 1), MAX-2, MAX) mkpnk %= MAX s += nck * ( (-1) ** k) * mpk * (mkpnk) ** 2 s %= MAX print(s) if __name__=='__main__': main() ```
instruction
0
47,703
5
95,406
No
output
1
47,703
5
95,407
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a three-digit positive integer N. Determine whether N is a palindromic number. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation. Constraints * 100≤N≤999 * N is an integer. Input Input is given from Standard Input in the following format: N Output If N is a palindromic number, print `Yes`; otherwise, print `No`. Examples Input 575 Output Yes Input 123 Output No Input 812 Output No Submitted Solution: ``` n=input() print("Yes" if n[0] == n[2] else "No") ```
instruction
0
47,808
5
95,616
Yes
output
1
47,808
5
95,617
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a three-digit positive integer N. Determine whether N is a palindromic number. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation. Constraints * 100≤N≤999 * N is an integer. Input Input is given from Standard Input in the following format: N Output If N is a palindromic number, print `Yes`; otherwise, print `No`. Examples Input 575 Output Yes Input 123 Output No Input 812 Output No Submitted Solution: ``` #coding:utf-8 a, b, c, d = map(int, input().split()) print(min(a,c)- max(b,d)) ```
instruction
0
47,812
5
95,624
No
output
1
47,812
5
95,625
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have a set of items, each having some integer weight not greater than 8. You denote that a subset of items is good if total weight of items in the subset does not exceed W. You want to calculate the maximum possible weight of a good subset of items. Note that you have to consider the empty set and the original set when calculating the answer. Input The first line contains one integer W (0 ≤ W ≤ 10^{18}) — the maximum total weight of a good subset. The second line denotes the set of items you have. It contains 8 integers cnt_1, cnt_2, ..., cnt_8 (0 ≤ cnt_i ≤ 10^{16}), where cnt_i is the number of items having weight i in the set. Output Print one integer — the maximum possible weight of a good subset of items. Examples Input 10 1 2 3 4 5 6 7 8 Output 10 Input 0 0 0 0 0 0 0 0 0 Output 0 Input 3 0 4 1 0 0 9 8 3 Output 3 Submitted Solution: ``` if __name__ == '__main__': W = int(input()) p = list(map(int, input().split())) weight = 0 for i in range(8, 0, -1): if W <= 0: break # print(f"W={W}, r={r}, p[i-1]={p[i-1]}") r = min(W // i, p[i - 1]) w = r * i weight += w W -= w print(weight) ```
instruction
0
47,987
5
95,974
No
output
1
47,987
5
95,975
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have a set of items, each having some integer weight not greater than 8. You denote that a subset of items is good if total weight of items in the subset does not exceed W. You want to calculate the maximum possible weight of a good subset of items. Note that you have to consider the empty set and the original set when calculating the answer. Input The first line contains one integer W (0 ≤ W ≤ 10^{18}) — the maximum total weight of a good subset. The second line denotes the set of items you have. It contains 8 integers cnt_1, cnt_2, ..., cnt_8 (0 ≤ cnt_i ≤ 10^{16}), where cnt_i is the number of items having weight i in the set. Output Print one integer — the maximum possible weight of a good subset of items. Examples Input 10 1 2 3 4 5 6 7 8 Output 10 Input 0 0 0 0 0 0 0 0 0 Output 0 Input 3 0 4 1 0 0 9 8 3 Output 3 Submitted Solution: ``` W = int(input()) arr =[int(x) for x in input().split()] sum_=0 for i in range(len(arr)): sum_+=(i+1)*arr[i] if(sum_<W): print(sum_) else: print(W) ```
instruction
0
47,988
5
95,976
No
output
1
47,988
5
95,977
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a permutation of numbers from 1 to n. Determine whether there's a pair of integers a, b (1 ≤ a, b ≤ n; a ≠ b) such that the element <image> (note, that it is usual division, not integer one) is between a and b in this permutation. Input First line consists of a single integer n (1 ≤ n ≤ 300000) — the size of permutation. Second line contains n integers — the permutation itself. Output Print "YES", if such a pair exists, "NO" otherwise (in both cases without quotes, the answer is case insensitive). Examples Input 4 1 3 4 2 Output NO Input 5 1 5 2 4 3 Output YES Note In the second example 2 is between 1 and 3. Additionally 4 is between 3 and 5. Submitted Solution: ``` n = int(input()) v = list(map(int, input().split())) ans = "NO" sum = 0 for i in range(n): x = v[i] t = 2 * x - 1 d = 0 if t > n: d = t - n l, r = 1 + d, 2 * x - 1 - d s = r - l m = x * s if l < r: if not ((sum == m and i == s) or (sum > m and i > s) or (sum < m and i < s)): ans = "YES" break sum += x print(ans) ```
instruction
0
48,301
5
96,602
No
output
1
48,301
5
96,603
Provide tags and a correct Python 3 solution for this coding contest problem. You have two variables a and b. Consider the following sequence of actions performed with these variables: 1. If a = 0 or b = 0, end the process. Otherwise, go to step 2; 2. If a ≥ 2·b, then set the value of a to a - 2·b, and repeat step 1. Otherwise, go to step 3; 3. If b ≥ 2·a, then set the value of b to b - 2·a, and repeat step 1. Otherwise, end the process. Initially the values of a and b are positive integers, and so the process will be finite. You have to determine the values of a and b after the process ends. Input The only line of the input contains two integers n and m (1 ≤ n, m ≤ 1018). n is the initial value of variable a, and m is the initial value of variable b. Output Print two integers — the values of a and b after the end of the process. Examples Input 12 5 Output 0 1 Input 31 12 Output 7 12 Note Explanations to the samples: 1. a = 12, b = 5 <image> a = 2, b = 5 <image> a = 2, b = 1 <image> a = 0, b = 1; 2. a = 31, b = 12 <image> a = 7, b = 12.
instruction
0
48,530
5
97,060
Tags: math, number theory Correct Solution: ``` a, b = map(int, input().split(' ')) while 1: if a == 0 or b == 0: break elif a >= 2 * b: a %= 2 * b continue elif b >= 2 * a: b %= 2 * a continue else: break print(a, b) ```
output
1
48,530
5
97,061
Provide tags and a correct Python 3 solution for this coding contest problem. You have two variables a and b. Consider the following sequence of actions performed with these variables: 1. If a = 0 or b = 0, end the process. Otherwise, go to step 2; 2. If a ≥ 2·b, then set the value of a to a - 2·b, and repeat step 1. Otherwise, go to step 3; 3. If b ≥ 2·a, then set the value of b to b - 2·a, and repeat step 1. Otherwise, end the process. Initially the values of a and b are positive integers, and so the process will be finite. You have to determine the values of a and b after the process ends. Input The only line of the input contains two integers n and m (1 ≤ n, m ≤ 1018). n is the initial value of variable a, and m is the initial value of variable b. Output Print two integers — the values of a and b after the end of the process. Examples Input 12 5 Output 0 1 Input 31 12 Output 7 12 Note Explanations to the samples: 1. a = 12, b = 5 <image> a = 2, b = 5 <image> a = 2, b = 1 <image> a = 0, b = 1; 2. a = 31, b = 12 <image> a = 7, b = 12.
instruction
0
48,531
5
97,062
Tags: math, number theory Correct Solution: ``` a,b=map(int,input().split()) while 1: if a==0 or b==0: break if a>=2*b: a-=(a//(b*2))*(b*2) else: if b>=2*a: b-=(b//(a*2))*(a*2) else: break print(a,b) ```
output
1
48,531
5
97,063