message
stringlengths
2
433k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
113
108k
cluster
float64
12
12
__index_level_0__
int64
226
217k
Provide a correct Python 3 solution for this coding contest problem. For given a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$, print the previous permutation and the next permutation in lexicographic order. Constraints * $1 \leq n \leq 9$ * $a_i$ consist of $1, 2, ..., n$ Input A sequence is given in the following ...
instruction
0
84,999
12
169,998
"Correct Solution: ``` import itertools if __name__ == '__main__': n = int(input()) now = tuple(map(int,input().split())) seq = [i+1 for i in range(n)] seq2 = list(itertools.permutations(seq)) ind = 0 for j,k in enumerate(seq2): if k == now: ind = j if ind == 0: print(*seq2[ind]) if len(seq2) != 1...
output
1
84,999
12
169,999
Provide a correct Python 3 solution for this coding contest problem. For given a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$, print the previous permutation and the next permutation in lexicographic order. Constraints * $1 \leq n \leq 9$ * $a_i$ consist of $1, 2, ..., n$ Input A sequence is given in the following ...
instruction
0
85,000
12
170,000
"Correct Solution: ``` # AOJ ITP2_5_C: Permutation # Python3 2018.6.24 bal4u def next_permutation(a): # if list has less than two elements, has no next permutation. if len(a) < 2: return False # step 1: find max i for a[i] > a[i+1] i = len(a)-2 while i >= 0 and a[i] >= a[i+1]: i -= 1 if i < 0:...
output
1
85,000
12
170,001
Provide a correct Python 3 solution for this coding contest problem. For given a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$, print the previous permutation and the next permutation in lexicographic order. Constraints * $1 \leq n \leq 9$ * $a_i$ consist of $1, 2, ..., n$ Input A sequence is given in the following ...
instruction
0
85,001
12
170,002
"Correct Solution: ``` import operator def permutations(li): """Returns a list of previous, current, and next permutations of li. >>> permutations([1, 2]) [[1, 2], [2, 1]] >>> permutations([1, 3, 2]) [[1, 2, 3], [1, 3, 2], [2, 1, 3]] """ def perm(op): def func(xs): ...
output
1
85,001
12
170,003
Provide a correct Python 3 solution for this coding contest problem. For given a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$, print the previous permutation and the next permutation in lexicographic order. Constraints * $1 \leq n \leq 9$ * $a_i$ consist of $1, 2, ..., n$ Input A sequence is given in the following ...
instruction
0
85,002
12
170,004
"Correct Solution: ``` from itertools import permutations # INPUT n = int(input()) A = tuple(input().split()) # PROCESS, OUTPUT str_num = "" for num in range(1, n + 1): str_num += str(num) flag_break = False list_num_previous = None for list_num in permutations(str_num): if flag_break: # next ...
output
1
85,002
12
170,005
Provide a correct Python 3 solution for this coding contest problem. For given a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$, print the previous permutation and the next permutation in lexicographic order. Constraints * $1 \leq n \leq 9$ * $a_i$ consist of $1, 2, ..., n$ Input A sequence is given in the following ...
instruction
0
85,003
12
170,006
"Correct Solution: ``` def resolve(): import itertools n = int(input()) target = tuple(int(i) for i in input().split()) before = None found = False for a in sorted(itertools.permutations(target)): if found: print(*a) return elif a == target: if...
output
1
85,003
12
170,007
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For given a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$, print the previous permutation and the next permutation in lexicographic order. Constraints * $1 \leq n \leq 9$ * $a_i$ consist of $1, ...
instruction
0
85,005
12
170,010
Yes
output
1
85,005
12
170,011
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For given a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$, print the previous permutation and the next permutation in lexicographic order. Constraints * $1 \leq n \leq 9$ * $a_i$ consist of $1, ...
instruction
0
85,007
12
170,014
Yes
output
1
85,007
12
170,015
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a sequence a_1, a_2, ..., a_n consisting of n integers. You can choose any non-negative integer D (i.e. D β‰₯ 0), and for each a_i you can: * add D (only once), i. e. perform a_i := a_i + D, or * subtract D (only once), i....
instruction
0
85,074
12
170,148
Tags: math Correct Solution: ``` n = int(input()) A = list(map(int, input().split())) if len(set(A)) == 1: print(0) exit(0) A.sort() x = A[-1] - A[0] heh = x if x % 2 == 0: heh = x // 2 for kek in heh, x: s = set() for elem in A: if elem > A[0] + kek: s.add(elem - kek) el...
output
1
85,074
12
170,149
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a sequence a_1, a_2, ..., a_n consisting of n integers. You can choose any non-negative integer D (i.e. D β‰₯ 0), and for each a_i you can: * add D (only once), i. e. perform a_i := a_i + D, or * subtract D (only once), i....
instruction
0
85,075
12
170,150
Tags: math Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) uniq = set(a) mi = min(uniq) ma = max(uniq) if 2 < len(uniq) <= 3: if (mi + ma) % 2 == 0 and (mi + ma) // 2 == sum(uniq - {mi, ma}): print(ma - sum(uniq - {mi, ma})) else: print(-1) elif len(uniq) == 2: i...
output
1
85,075
12
170,151
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a sequence a_1, a_2, ..., a_n consisting of n integers. You can choose any non-negative integer D (i.e. D β‰₯ 0), and for each a_i you can: * add D (only once), i. e. perform a_i := a_i + D, or * subtract D (only once), i....
instruction
0
85,076
12
170,152
Tags: math Correct Solution: ``` def main(): input() s = set([int(x) for x in input().split()]) n = len(s) if n == 2 or n ==3: s = list(s) s.sort() if n == 3: if (s[2]-s[0])%2 == 0: if (((s[2]-s[0])//2 + s[0] == s[1]) and (s[2] - (s[2]-s[0])//2 == s[...
output
1
85,076
12
170,153
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a sequence a_1, a_2, ..., a_n consisting of n integers. You can choose any non-negative integer D (i.e. D β‰₯ 0), and for each a_i you can: * add D (only once), i. e. perform a_i := a_i + D, or * subtract D (only once), i....
instruction
0
85,077
12
170,154
Tags: math Correct Solution: ``` # cook your dish here n=int(input()) l = list(map(int,input().split())) l=list(set(l)) l.sort() n=-1 d=-1 if(len(l)==1): d=0 elif len(l)==2: if (l[1]-l[0])%2==0: d = (l[1]-l[0])//2 n=l[0]+d else: d = l[1]-l[0] n = l[0] elif len(l)==3: ...
output
1
85,077
12
170,155
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a sequence a_1, a_2, ..., a_n consisting of n integers. You can choose any non-negative integer D (i.e. D β‰₯ 0), and for each a_i you can: * add D (only once), i. e. perform a_i := a_i + D, or * subtract D (only once), i....
instruction
0
85,078
12
170,156
Tags: math Correct Solution: ``` #make_them_equal n = int(input()); a = list(set([int(num) for num in input().split()])) a.sort() # def equal(b): # diffArray=[] # for j in range(0,len(b)-1): # diff = b[j+1]-b[j] # if diff != 0: # diffArray.append(diff); # j += 1; # #print(diffArray) # valArray=[] # f...
output
1
85,078
12
170,157
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a sequence a_1, a_2, ..., a_n consisting of n integers. You can choose any non-negative integer D (i.e. D β‰₯ 0), and for each a_i you can: * add D (only once), i. e. perform a_i := a_i + D, or * subtract D (only once), i....
instruction
0
85,079
12
170,158
Tags: math Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) def solve(): if len(set(a)) == 1: return 0 INF = 1 << 30 ret = INF for target in range(1, 101): delta = INF for num in a: if num > target: if delta == INF: ...
output
1
85,079
12
170,159
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a sequence a_1, a_2, ..., a_n consisting of n integers. You can choose any non-negative integer D (i.e. D β‰₯ 0), and for each a_i you can: * add D (only once), i. e. perform a_i := a_i + D, or * subtract D (only once), i....
instruction
0
85,080
12
170,160
Tags: math Correct Solution: ``` n = int(input()) lst = [int(x) for x in input().split()] lst = list(set(lst)) lst.sort() last = lst[0] count = len(lst) - 1 # for curr in lst: # print(curr) flag = True dif1,dif2 = 0,0 if count > 2: flag = False if count == 2: dif1 = lst[1] - lst[0] dif2 = lst[2] - lst[1] if dif1...
output
1
85,080
12
170,161
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a sequence a_1, a_2, ..., a_n consisting of n integers. You can choose any non-negative integer D (i.e. D β‰₯ 0), and for each a_i you can: * add D (only once), i. e. perform a_i := a_i + D, or * subtract D (only once), i....
instruction
0
85,081
12
170,162
Tags: math Correct Solution: ``` a = int(input()) b = list(map(int, input().split())) x = set(b) xs = list(x) xs.sort() if len(xs) == 2: if sum(xs) % 2 != 0:print(xs[1] - xs[0]) else:print(int(sum(xs)/2) - xs[0]) elif len(xs) == 3: if xs[-1] - xs[1] == xs[1] - xs[0]: print(xs[1] - xs[0]) else:...
output
1
85,081
12
170,163
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a sequence a_1, a_2, ..., a_n consisting of n integers. You can choose any non-negative integer D (i.e. D β‰₯ 0), and for each a_i you can: * add D (only once), i. e. perform a_i...
instruction
0
85,083
12
170,166
Yes
output
1
85,083
12
170,167
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a sequence a_1, a_2, ..., a_n consisting of n integers. You can choose any non-negative integer D (i.e. D β‰₯ 0), and for each a_i you can: * add D (only once), i. e. perform a_i...
instruction
0
85,084
12
170,168
Yes
output
1
85,084
12
170,169
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a sequence a_1, a_2, ..., a_n consisting of n integers. You can choose any non-negative integer D (i.e. D β‰₯ 0), and for each a_i you can: * add D (only once), i. e. perform a_i...
instruction
0
85,085
12
170,170
Yes
output
1
85,085
12
170,171
Provide tags and a correct Python 3 solution for this coding contest problem. You have an array a of length n. For every positive integer x you are going to perform the following operation during the x-th second: * Select some distinct indices i_{1}, i_{2}, …, i_{k} which are between 1 and n inclusive, and add 2^{x...
instruction
0
85,135
12
170,270
Tags: greedy, math Correct Solution: ``` import math for ii in range(int(input())): n = int(input()) a = [int(i) for i in input().split()] b = [0 for i in range(n)] b[0] = a[0] x = b[0] ans = 0 for i in range(1,n): b[i] = max(max(x,b[i-1]),a[i]) #print(b) x = 0 for i in...
output
1
85,135
12
170,271
Provide tags and a correct Python 3 solution for this coding contest problem. You have an array a of length n. For every positive integer x you are going to perform the following operation during the x-th second: * Select some distinct indices i_{1}, i_{2}, …, i_{k} which are between 1 and n inclusive, and add 2^{x...
instruction
0
85,136
12
170,272
Tags: greedy, math Correct Solution: ``` import math t=int(input()) while(t): t-=1 n=int(input()) l=list(map(int,input().split())) nl=[] maxi=l[0] for i in range(0,n): if(maxi<l[i]): maxi=l[i] nl.append(maxi-l[i]) k=max(nl) # x=(math.log2(k)) if(k>0): # print('Logarithm value of Positive Number = %.0f...
output
1
85,136
12
170,273
Provide tags and a correct Python 3 solution for this coding contest problem. You have an array a of length n. For every positive integer x you are going to perform the following operation during the x-th second: * Select some distinct indices i_{1}, i_{2}, …, i_{k} which are between 1 and n inclusive, and add 2^{x...
instruction
0
85,137
12
170,274
Tags: greedy, math Correct Solution: ``` for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) ans=0 ma=a[0] for i in range(1,n): if a[i]<ma: ans=max(ans,len(bin(ma-a[i]))-2) else: ma=a[i] print(ans) ```
output
1
85,137
12
170,275
Provide tags and a correct Python 3 solution for this coding contest problem. You have an array a of length n. For every positive integer x you are going to perform the following operation during the x-th second: * Select some distinct indices i_{1}, i_{2}, …, i_{k} which are between 1 and n inclusive, and add 2^{x...
instruction
0
85,138
12
170,276
Tags: greedy, math Correct Solution: ``` for _ in range(int(input())): n = int(input()) lst = [int(i) for i in input().split()] result = 0 for i in range(1, n): diff = lst[i-1]-lst[i] if diff > 0: result = max(result, len(bin(diff))-2) lst[i] = lst[i-1] print(...
output
1
85,138
12
170,277
Provide tags and a correct Python 3 solution for this coding contest problem. You have an array a of length n. For every positive integer x you are going to perform the following operation during the x-th second: * Select some distinct indices i_{1}, i_{2}, …, i_{k} which are between 1 and n inclusive, and add 2^{x...
instruction
0
85,139
12
170,278
Tags: greedy, math Correct Solution: ``` import math t=int(input()) for i in range(t): n=int(input()) arr=[int(i) for i in input().split()] T=0 prev=arr[0] for i in range(1,n): diff =arr[i]-prev if diff>=0: prev=arr[i] else: T=max(T,int(1+math.log2(-di...
output
1
85,139
12
170,279
Provide tags and a correct Python 3 solution for this coding contest problem. You have an array a of length n. For every positive integer x you are going to perform the following operation during the x-th second: * Select some distinct indices i_{1}, i_{2}, …, i_{k} which are between 1 and n inclusive, and add 2^{x...
instruction
0
85,140
12
170,280
Tags: greedy, math Correct Solution: ``` t = int(input()) for i in range(t): n = int(input()) arr = [int(x) for x in input().split()] max_diff = 0 num_to_beat = arr[0] for i in range(1, n): if arr[i] < num_to_beat: max_diff = max(max_diff, num_to_beat-arr[i]) else: num_to_beat = arr[i] j = 0 while True...
output
1
85,140
12
170,281
Provide tags and a correct Python 3 solution for this coding contest problem. You have an array a of length n. For every positive integer x you are going to perform the following operation during the x-th second: * Select some distinct indices i_{1}, i_{2}, …, i_{k} which are between 1 and n inclusive, and add 2^{x...
instruction
0
85,141
12
170,282
Tags: greedy, math Correct Solution: ``` ''' powered addition ''' T = int(input()) for test in range(T): N = int(input()) vec = list(map(int, input().split())) diff = [] mxm = vec[0] for i in range(N - 1): diff.append(mxm - vec[i + 1]) mxm = max(mxm, vec[i + 1]) #print(diff) ...
output
1
85,141
12
170,283
Provide tags and a correct Python 3 solution for this coding contest problem. You have an array a of length n. For every positive integer x you are going to perform the following operation during the x-th second: * Select some distinct indices i_{1}, i_{2}, …, i_{k} which are between 1 and n inclusive, and add 2^{x...
instruction
0
85,142
12
170,284
Tags: greedy, math Correct Solution: ``` from pprint import pprint import sys input = sys.stdin.readline q = int(input()) for _ in range(q): n = int(input()) import collections import math dat = list(map(int, input().split())) xm = min(dat) dat = list(map(lambda x: x - xm, dat)) #print(dat)...
output
1
85,142
12
170,285
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have an array a of length n. For every positive integer x you are going to perform the following operation during the x-th second: * Select some distinct indices i_{1}, i_{2}, …, i_{k} wh...
instruction
0
85,143
12
170,286
Yes
output
1
85,143
12
170,287
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have an array a of length n. For every positive integer x you are going to perform the following operation during the x-th second: * Select some distinct indices i_{1}, i_{2}, …, i_{k} wh...
instruction
0
85,144
12
170,288
Yes
output
1
85,144
12
170,289
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have an array a of length n. For every positive integer x you are going to perform the following operation during the x-th second: * Select some distinct indices i_{1}, i_{2}, …, i_{k} wh...
instruction
0
85,145
12
170,290
Yes
output
1
85,145
12
170,291
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have an array a of length n. For every positive integer x you are going to perform the following operation during the x-th second: * Select some distinct indices i_{1}, i_{2}, …, i_{k} wh...
instruction
0
85,146
12
170,292
Yes
output
1
85,146
12
170,293
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have an array a of length n. For every positive integer x you are going to perform the following operation during the x-th second: * Select some distinct indices i_{1}, i_{2}, …, i_{k} wh...
instruction
0
85,147
12
170,294
No
output
1
85,147
12
170,295
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have an array a of length n. For every positive integer x you are going to perform the following operation during the x-th second: * Select some distinct indices i_{1}, i_{2}, …, i_{k} wh...
instruction
0
85,148
12
170,296
No
output
1
85,148
12
170,297
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have an array a of length n. For every positive integer x you are going to perform the following operation during the x-th second: * Select some distinct indices i_{1}, i_{2}, …, i_{k} wh...
instruction
0
85,149
12
170,298
No
output
1
85,149
12
170,299
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have an array a of length n. For every positive integer x you are going to perform the following operation during the x-th second: * Select some distinct indices i_{1}, i_{2}, …, i_{k} wh...
instruction
0
85,150
12
170,300
No
output
1
85,150
12
170,301
Provide tags and a correct Python 3 solution for this coding contest problem. You are given four positive integers n, m, a, b (1 ≀ b ≀ n ≀ 50; 1 ≀ a ≀ m ≀ 50). Find any such rectangular matrix of size n Γ— m that satisfies all of the following conditions: * each row of the matrix contains exactly a ones; * each c...
instruction
0
85,151
12
170,302
Tags: constructive algorithms, greedy, math Correct Solution: ``` import math as mt import sys,string input=sys.stdin.readline L=lambda : list(map(int,input().split())) Ls=lambda : list(input().split()) M=lambda : map(int,input().split()) I=lambda :int(input()) t=I() for _ in range(t): n,m,a,b=M() if(n*a!=m*b)...
output
1
85,151
12
170,303
Provide tags and a correct Python 3 solution for this coding contest problem. You are given four positive integers n, m, a, b (1 ≀ b ≀ n ≀ 50; 1 ≀ a ≀ m ≀ 50). Find any such rectangular matrix of size n Γ— m that satisfies all of the following conditions: * each row of the matrix contains exactly a ones; * each c...
instruction
0
85,152
12
170,304
Tags: constructive algorithms, greedy, math Correct Solution: ``` t = int(input()) for _ in range(t): n,m,a,b = [int(x) for x in input().split()] if n*a!=m*b: print("NO") continue l = [] ans = [[0 for i in range(m)] for j in range(n)] for i in range(m): l.append([0,i]) l....
output
1
85,152
12
170,305
Provide tags and a correct Python 3 solution for this coding contest problem. You are given four positive integers n, m, a, b (1 ≀ b ≀ n ≀ 50; 1 ≀ a ≀ m ≀ 50). Find any such rectangular matrix of size n Γ— m that satisfies all of the following conditions: * each row of the matrix contains exactly a ones; * each c...
instruction
0
85,153
12
170,306
Tags: constructive algorithms, greedy, math Correct Solution: ``` t=int(input()) for i in range(t): n,m,a,b=map(int,input().split()) lst=[] for i in range(n): arr=[] for j in range(m): arr+=[0] lst+=[arr] #lst[1][2]=1 #print(lst) j,k=0,0 x=0 while(j<n)...
output
1
85,153
12
170,307
Provide tags and a correct Python 3 solution for this coding contest problem. You are given four positive integers n, m, a, b (1 ≀ b ≀ n ≀ 50; 1 ≀ a ≀ m ≀ 50). Find any such rectangular matrix of size n Γ— m that satisfies all of the following conditions: * each row of the matrix contains exactly a ones; * each c...
instruction
0
85,154
12
170,308
Tags: constructive algorithms, greedy, math Correct Solution: ``` for i in range(int(input())) : n,m,a,b=map(int,input().split()) if n*a != m*b: print("No") continue print("Yes") t='1'*a+'0'*(m-a) for i in range(n) : print(t) t=t[m-a:]+t[:m-a] ```
output
1
85,154
12
170,309
Provide tags and a correct Python 3 solution for this coding contest problem. You are given four positive integers n, m, a, b (1 ≀ b ≀ n ≀ 50; 1 ≀ a ≀ m ≀ 50). Find any such rectangular matrix of size n Γ— m that satisfies all of the following conditions: * each row of the matrix contains exactly a ones; * each c...
instruction
0
85,155
12
170,310
Tags: constructive algorithms, greedy, math Correct Solution: ``` t = int(input()) for _ in range(t): n,m,a,b = map(int,input().split()) if n*a != m*b: print("NO") continue ans = [[0]*m for i in range(n)] for i in range(a): ans[0][i] = 1 for i in range(1,n): for ...
output
1
85,155
12
170,311
Provide tags and a correct Python 3 solution for this coding contest problem. You are given four positive integers n, m, a, b (1 ≀ b ≀ n ≀ 50; 1 ≀ a ≀ m ≀ 50). Find any such rectangular matrix of size n Γ— m that satisfies all of the following conditions: * each row of the matrix contains exactly a ones; * each c...
instruction
0
85,156
12
170,312
Tags: constructive algorithms, greedy, math Correct Solution: ``` from sys import stdin input = stdin.readline if __name__ == '__main__': for _ in range(int(input())): n, m, a, b = map(int, input().split()) mtrx = [] for i in range(n): r = ['0' for _ in range(m)] ...
output
1
85,156
12
170,313
Provide tags and a correct Python 3 solution for this coding contest problem. You are given four positive integers n, m, a, b (1 ≀ b ≀ n ≀ 50; 1 ≀ a ≀ m ≀ 50). Find any such rectangular matrix of size n Γ— m that satisfies all of the following conditions: * each row of the matrix contains exactly a ones; * each c...
instruction
0
85,157
12
170,314
Tags: constructive algorithms, greedy, math Correct Solution: ``` t=int(input()) from heapq import heappush as pu from heapq import heappop as po for _ in range(t): n,m,a,b=map(int,input().split()) q=[] for i in range(m): pu(q,(-b,i)) ma=[[0 for i in range(m)] for i in range(n)] tt=True for i in range(n): ...
output
1
85,157
12
170,315
Provide tags and a correct Python 3 solution for this coding contest problem. You are given four positive integers n, m, a, b (1 ≀ b ≀ n ≀ 50; 1 ≀ a ≀ m ≀ 50). Find any such rectangular matrix of size n Γ— m that satisfies all of the following conditions: * each row of the matrix contains exactly a ones; * each c...
instruction
0
85,158
12
170,316
Tags: constructive algorithms, greedy, math Correct Solution: ``` class Solution(): def __init__(self): test = int(input()) for i in range(0, test): n, m, a, b = list(map(int, input().split())) self.solve(n, m, a, b) def solve(self, n, m, a, b): if a * n != b * m: return print("NO") ...
output
1
85,158
12
170,317
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a of length 2n. Consider a partition of array a into two subsequences p and q of length n each (each element of array a should be in exactly one subsequence: either in p or in q). Let's sort p in non-decreasing order,...
instruction
0
85,199
12
170,398
Tags: combinatorics, math, sortings Correct Solution: ``` import sys import math import collections input=sys.stdin.readline mod=998244353 def fact(n): prod=1 for i in range(2,n+1): prod=(prod*i)%mod return prod def ncr(n): k=(fact(n)*fact(n))%mod k1=pow(k,mod-2,mod) return((fact(2*n)*k1...
output
1
85,199
12
170,399
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a of length 2n. Consider a partition of array a into two subsequences p and q of length n each (each element of array a should be in exactly one subsequence: either in p or in q). Let's sort p in non-decreasing order,...
instruction
0
85,200
12
170,400
Tags: combinatorics, math, sortings Correct Solution: ``` from sys import stdin, gettrace if gettrace(): inputi = input else: def input(): return next(stdin)[:-1] def inputi(): return stdin.buffer.readline() MOD = 998244353 def main(): n = int(inputi()) aa = [int(a) for a in in...
output
1
85,200
12
170,401
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a of length 2n. Consider a partition of array a into two subsequences p and q of length n each (each element of array a should be in exactly one subsequence: either in p or in q). Let's sort p in non-decreasing order,...
instruction
0
85,201
12
170,402
Tags: combinatorics, math, sortings Correct Solution: ``` import os import sys from io import BytesIO, IOBase def main(): pass # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.wri...
output
1
85,201
12
170,403
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a of length 2n. Consider a partition of array a into two subsequences p and q of length n each (each element of array a should be in exactly one subsequence: either in p or in q). Let's sort p in non-decreasing order,...
instruction
0
85,202
12
170,404
Tags: combinatorics, math, sortings Correct Solution: ``` import itertools import math import sys import os from collections import defaultdict from heapq import heapify, heappush, heappop def is_debug(): return "PYPY3_HOME" not in os.environ def stdin_wrapper(): data = '''5 13 8 35 94 9284 34 54 69 123 846...
output
1
85,202
12
170,405
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a of length 2n. Consider a partition of array a into two subsequences p and q of length n each (each element of array a should be in exactly one subsequence: either in p or in q). Let's sort p in non-decreasing order,...
instruction
0
85,203
12
170,406
Tags: combinatorics, math, sortings Correct Solution: ``` def ncr(n, r, p): # initialize numerator # and denominator num = den = 1 for i in range(r): num = (num * (n - i)) % p den = (den * (i + 1)) % p return (num * pow(den, p - 2, p)) % p def testcase(): n = int(i...
output
1
85,203
12
170,407
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a of length 2n. Consider a partition of array a into two subsequences p and q of length n each (each element of array a should be in exactly one subsequence: either in p or in q). Let's sort p in non-decreasing order,...
instruction
0
85,204
12
170,408
Tags: combinatorics, math, sortings Correct Solution: ``` def res(n): nu=s=1 for i in range(n): nu=(nu*(2*n-i))%m s=(s*(i+1))%m return((nu*pow(s,m-2,m))%m) m=998244353 n=int(input()) fg=sorted(list(map(int,input().split()))) f=abs((sum(fg[:n])-sum(fg[n:]))) print((f*res(n))%m) #prin...
output
1
85,204
12
170,409
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a of length 2n. Consider a partition of array a into two subsequences p and q of length n each (each element of array a should be in exactly one subsequence: either in p or in q). Let's sort p in non-decreasing order,...
instruction
0
85,205
12
170,410
Tags: combinatorics, math, sortings Correct Solution: ``` mod = 998244353 def pow_(x, y, p) : res = 1 x = x % p if x == 0: return 0 while y > 0: if (y & 1) == 1: res = (res * x) % p y = y >> 1 x = (x * x) % p return...
output
1
85,205
12
170,411
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a of length 2n. Consider a partition of array a into two subsequences p and q of length n each (each element of array a should be in exactly one subsequence: either in p or in q). Let's sort p in non-decreasing order,...
instruction
0
85,206
12
170,412
Tags: combinatorics, math, sortings Correct Solution: ``` import sys import math,bisect sys.setrecursionlimit(10 ** 5) from itertools import groupby,accumulate from heapq import heapify,heappop,heappush from collections import deque,Counter,defaultdict I = lambda : int(sys.stdin.readline()) neo = lambda : map(int, sys....
output
1
85,206
12
170,413