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 tags and a correct Python 3 solution for this coding contest problem. Leha like all kinds of strange things. Recently he liked the function F(n, k). Consider all possible k-element subsets of the set [1, 2, ..., n]. For subset find minimal element in it. F(n, k) β€” mathematical expectation of the minimal elemen...
instruction
0
77,272
12
154,544
Tags: combinatorics, greedy, math, number theory, sortings Correct Solution: ``` n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) a.sort() a.reverse() j=[] for i in range(n): j.append([b[i],i]) j.sort() ans=[0]*n for i in range(n): ans[j[i][1]]=str(a[i]) print(' '.join(ans)) ```
output
1
77,272
12
154,545
Provide tags and a correct Python 3 solution for this coding contest problem. Leha like all kinds of strange things. Recently he liked the function F(n, k). Consider all possible k-element subsets of the set [1, 2, ..., n]. For subset find minimal element in it. F(n, k) β€” mathematical expectation of the minimal elemen...
instruction
0
77,273
12
154,546
Tags: combinatorics, greedy, math, number theory, sortings Correct Solution: ``` import sys read = lambda : sys.stdin.readline() n = int(read()) a = list(map(int, read().split())) b = list(map(int, read().split())) a.sort() a = a[::-1] z = zip(a, list(sorted(b))) d = dict() for (one, two) in z: if two in d: d[two]...
output
1
77,273
12
154,547
Provide tags and a correct Python 3 solution for this coding contest problem. Leha like all kinds of strange things. Recently he liked the function F(n, k). Consider all possible k-element subsets of the set [1, 2, ..., n]. For subset find minimal element in it. F(n, k) β€” mathematical expectation of the minimal elemen...
instruction
0
77,274
12
154,548
Tags: combinatorics, greedy, math, number theory, sortings Correct Solution: ``` n = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) b1 = [] a1 = [] for i in range(n): b1.append(b[i]) a1.append(a[i]) b1.sort() a1.sort() a1.reverse() d = dict() for i in range(n): if b1[i] in d: d[b1...
output
1
77,274
12
154,549
Provide tags and a correct Python 3 solution for this coding contest problem. Leha like all kinds of strange things. Recently he liked the function F(n, k). Consider all possible k-element subsets of the set [1, 2, ..., n]. For subset find minimal element in it. F(n, k) β€” mathematical expectation of the minimal elemen...
instruction
0
77,275
12
154,550
Tags: combinatorics, greedy, math, number theory, sortings Correct Solution: ``` n=int(input()) a=[int(x) for x in input().split()] b=[int(x) for x in input().split()] for i in range(n): b[i]=(b[i],i) a.sort(reverse=True) #print(b) b.sort() #print(b) ans=[0]*n #print(ans) for i in range(n): ans[b[i][1]]=a[i] pr...
output
1
77,275
12
154,551
Provide tags and a correct Python 3 solution for this coding contest problem. Leha like all kinds of strange things. Recently he liked the function F(n, k). Consider all possible k-element subsets of the set [1, 2, ..., n]. For subset find minimal element in it. F(n, k) β€” mathematical expectation of the minimal elemen...
instruction
0
77,276
12
154,552
Tags: combinatorics, greedy, math, number theory, sortings Correct Solution: ``` import math as mt import sys,string input=sys.stdin.readline from collections import defaultdict L=lambda : list(map(int,input().split())) Ls=lambda : list(input().split()) M=lambda : map(int,input().split()) I=lambda :int(input()) n=I() ...
output
1
77,276
12
154,553
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Leha like all kinds of strange things. Recently he liked the function F(n, k). Consider all possible k-element subsets of the set [1, 2, ..., n]. For subset find minimal element in it. F(n, k) β€”...
instruction
0
77,277
12
154,554
Yes
output
1
77,277
12
154,555
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Leha like all kinds of strange things. Recently he liked the function F(n, k). Consider all possible k-element subsets of the set [1, 2, ..., n]. For subset find minimal element in it. F(n, k) β€”...
instruction
0
77,278
12
154,556
Yes
output
1
77,278
12
154,557
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Leha like all kinds of strange things. Recently he liked the function F(n, k). Consider all possible k-element subsets of the set [1, 2, ..., n]. For subset find minimal element in it. F(n, k) β€”...
instruction
0
77,279
12
154,558
Yes
output
1
77,279
12
154,559
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Leha like all kinds of strange things. Recently he liked the function F(n, k). Consider all possible k-element subsets of the set [1, 2, ..., n]. For subset find minimal element in it. F(n, k) β€”...
instruction
0
77,280
12
154,560
Yes
output
1
77,280
12
154,561
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Leha like all kinds of strange things. Recently he liked the function F(n, k). Consider all possible k-element subsets of the set [1, 2, ..., n]. For subset find minimal element in it. F(n, k) β€”...
instruction
0
77,281
12
154,562
No
output
1
77,281
12
154,563
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Leha like all kinds of strange things. Recently he liked the function F(n, k). Consider all possible k-element subsets of the set [1, 2, ..., n]. For subset find minimal element in it. F(n, k) β€”...
instruction
0
77,282
12
154,564
No
output
1
77,282
12
154,565
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Leha like all kinds of strange things. Recently he liked the function F(n, k). Consider all possible k-element subsets of the set [1, 2, ..., n]. For subset find minimal element in it. F(n, k) β€”...
instruction
0
77,283
12
154,566
No
output
1
77,283
12
154,567
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Leha like all kinds of strange things. Recently he liked the function F(n, k). Consider all possible k-element subsets of the set [1, 2, ..., n]. For subset find minimal element in it. F(n, k) β€”...
instruction
0
77,284
12
154,568
No
output
1
77,284
12
154,569
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ehab has an array a of n integers. He likes the [bitwise-xor operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) and he likes to bother Mahmoud so he came up with a problem. He gave ...
instruction
0
77,333
12
154,666
No
output
1
77,333
12
154,667
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ehab has an array a of n integers. He likes the [bitwise-xor operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) and he likes to bother Mahmoud so he came up with a problem. He gave ...
instruction
0
77,334
12
154,668
No
output
1
77,334
12
154,669
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ehab has an array a of n integers. He likes the [bitwise-xor operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) and he likes to bother Mahmoud so he came up with a problem. He gave ...
instruction
0
77,335
12
154,670
No
output
1
77,335
12
154,671
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ehab has an array a of n integers. He likes the [bitwise-xor operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) and he likes to bother Mahmoud so he came up with a problem. He gave ...
instruction
0
77,336
12
154,672
No
output
1
77,336
12
154,673
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya has a sequence a consisting of n integers a_1, a_2, ..., a_n. Vasya may pefrom the following operation: choose some number from the sequence and swap any pair of bits in its binary representation. For example, Vasya can transform numbe...
instruction
0
77,555
12
155,110
Tags: bitmasks, dp Correct Solution: ``` import sys input=sys.stdin.readline n=int(input()) a=list(map(int,input().split())) b=[0]*n for i in range(n): ai=a[i] for j in range(61): if (ai>>j)&1: b[i]+=1 cnt=[[0]*(n+1) for i in range(2)] cnt[0][n]=1 res=0 suf=0 for i in range(n)[::-1]: s=0...
output
1
77,555
12
155,111
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya has a sequence a consisting of n integers a_1, a_2, ..., a_n. Vasya may pefrom the following operation: choose some number from the sequence and swap any pair of bits in its binary representation. For example, Vasya can transform numbe...
instruction
0
77,556
12
155,112
Tags: bitmasks, dp Correct Solution: ``` #------------------------template--------------------------# import os import sys from math import * from collections import * # from fractions import * # from heapq import* from bisect import * from io import BytesIO, IOBase def vsInput(): sys.stdin = open('input.txt', 'r')...
output
1
77,556
12
155,113
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya has a sequence a consisting of n integers a_1, a_2, ..., a_n. Vasya may pefrom the following operation: choose some number from the sequence and swap any pair of bits in its binary representation. For example, Vasya can transform numbe...
instruction
0
77,557
12
155,114
Tags: bitmasks, dp Correct Solution: ``` import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file...
output
1
77,557
12
155,115
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya has a sequence a consisting of n integers a_1, a_2, ..., a_n. Vasya may pefrom the following operation: choose some number from the sequence and swap any pair of bits in its binary representation. For example, Vasya can transform numbe...
instruction
0
77,558
12
155,116
Tags: bitmasks, dp Correct Solution: ``` from array import array def popcount(x): res = 0; while(x > 0): res += (x & 1) x >>= 1 return res def main(): n = int(input()) a = array('i',[popcount(int(x)) for x in input().split(' ')]) ans,s0,s1 = 0,0,0 for i in range(n): ...
output
1
77,558
12
155,117
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya has a sequence a consisting of n integers a_1, a_2, ..., a_n. Vasya may pefrom the following operation: choose some number from the sequence and swap any pair of bits in its binary representation. For example, Vasya can transform numbe...
instruction
0
77,559
12
155,118
Tags: bitmasks, dp Correct Solution: ``` from bisect import bisect_left n=int(input()) b=list(map(int,input().split())) pre = [0] res=[] for j in range(n): res.append(bin(b[j]).count('1')) pre.append(pre[-1]+res[-1]) ans = 0 e = 1 o = 0 for j in range(n): if pre[j+1] % 2 == 0: ans += e ...
output
1
77,559
12
155,119
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya has a sequence a consisting of n integers a_1, a_2, ..., a_n. Vasya may pefrom the following operation: choose some number from the sequence and swap any pair of bits in its binary representation. For example, Vasya can transform numbe...
instruction
0
77,560
12
155,120
Tags: bitmasks, dp Correct Solution: ``` import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file...
output
1
77,560
12
155,121
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya has a sequence a consisting of n integers a_1, a_2, ..., a_n. Vasya may pefrom the following operation: choose some number from the sequence and swap any pair of bits in its binary representation. For example, Vasya can transform numbe...
instruction
0
77,561
12
155,122
Tags: bitmasks, dp Correct Solution: ``` #Code by Sounak, IIESTS #------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase from fractions import Fraction import collections from itertools import permutations from collections import defaultdict fro...
output
1
77,561
12
155,123
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya has a sequence a consisting of n integers a_1, a_2, ..., a_n. Vasya may pefrom the following operation: choose some number from the sequence and swap any pair of bits in its binary representation. For example, Vasya can transform numbe...
instruction
0
77,562
12
155,124
Tags: bitmasks, dp Correct Solution: ``` n = int(input()) cnt = [[0 for _ in range(n + 1)] for _ in range(2)] b = [bin(_).count('1') for _ in list(map(int, input().split()))] res = 0 suf_sum = 0 cnt[0][n] = 1 for i in range(n)[::-1]: _sum, mx = 0, 0 lst_j = i add = 0 for j in range(i, min(n, i + 65)): _sum...
output
1
77,562
12
155,125
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya has a sequence a consisting of n integers a_1, a_2, ..., a_n. Vasya may pefrom the following operation: choose some number from the sequence and swap any pair of bits in its binary represe...
instruction
0
77,563
12
155,126
No
output
1
77,563
12
155,127
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya has a sequence a consisting of n integers a_1, a_2, ..., a_n. Vasya may pefrom the following operation: choose some number from the sequence and swap any pair of bits in its binary represe...
instruction
0
77,564
12
155,128
No
output
1
77,564
12
155,129
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya has a sequence a consisting of n integers a_1, a_2, ..., a_n. Vasya may pefrom the following operation: choose some number from the sequence and swap any pair of bits in its binary represe...
instruction
0
77,565
12
155,130
No
output
1
77,565
12
155,131
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya has a sequence a consisting of n integers a_1, a_2, ..., a_n. Vasya may pefrom the following operation: choose some number from the sequence and swap any pair of bits in its binary represe...
instruction
0
77,566
12
155,132
No
output
1
77,566
12
155,133
Provide tags and a correct Python 3 solution for this coding contest problem. You are given the array a consisting of n elements and the integer k ≀ n. You want to obtain at least k equal elements in the array a. In one move, you can make one of the following two operations: * Take one of the minimum elements of t...
instruction
0
77,689
12
155,378
Tags: greedy Correct Solution: ``` def count(a, b): k = 0 while(a > b): a = a//2 k+=1 if a==b: return k else: return None n, k = input().split() n = int(n) k = int(k) s = list(input().split(" ")) for i in range(n): s[i] = int(s[i]) s.sort() number_of_operations = [] ...
output
1
77,689
12
155,379
Provide tags and a correct Python 3 solution for this coding contest problem. You are given the array a consisting of n elements and the integer k ≀ n. You want to obtain at least k equal elements in the array a. In one move, you can make one of the following two operations: * Take one of the minimum elements of t...
instruction
0
77,690
12
155,380
Tags: greedy Correct Solution: ``` n,k = map(int,input().split()) a = list(map(int,input().split())) pos = [] for i in range(n): x = a[i] while x > 0: pos.append(x) x //= 2 ans = 1000000000 for res in pos: cnt = [] for i in range(n): x = a[i] cur = 0 while x > res...
output
1
77,690
12
155,381
Provide tags and a correct Python 3 solution for this coding contest problem. You are given the array a consisting of n elements and the integer k ≀ n. You want to obtain at least k equal elements in the array a. In one move, you can make one of the following two operations: * Take one of the minimum elements of t...
instruction
0
77,691
12
155,382
Tags: greedy Correct Solution: ``` from collections import defaultdict def arrinp(): return [*map(int, input().split(' '))] def mulinp(): return map(int, input().split(' ')) def intinp(): return int(input()) def solution(): n, k = mulinp() arr = [] for i in sorted(arrinp()): if n...
output
1
77,691
12
155,383
Provide tags and a correct Python 3 solution for this coding contest problem. You are given the array a consisting of n elements and the integer k ≀ n. You want to obtain at least k equal elements in the array a. In one move, you can make one of the following two operations: * Take one of the minimum elements of t...
instruction
0
77,692
12
155,384
Tags: greedy Correct Solution: ``` from collections import defaultdict as dc x,y=map(int,input().split()) coun=dc(lambda:0) steps=dc(lambda:0) s=list(map(int,input().split())) s.sort() for n in s: coun[n]+=1 if coun[n]==y: print(0) exit(0) res=10**9 for n in s: p=n stp=0 while p: ...
output
1
77,692
12
155,385
Provide tags and a correct Python 3 solution for this coding contest problem. You are given the array a consisting of n elements and the integer k ≀ n. You want to obtain at least k equal elements in the array a. In one move, you can make one of the following two operations: * Take one of the minimum elements of t...
instruction
0
77,693
12
155,386
Tags: greedy Correct Solution: ``` n, k = input().split() n, k = int(n), int(k) arr = [[] for _ in range(int(2e5 + 1))] for a in input().split(): a = int(a) i = 0 while a > 0: arr[a].append(i) i += 1 a //= 2 arr[a].append(i) min_n = -1 for i in arr: if len(i) >= k: s...
output
1
77,693
12
155,387
Provide tags and a correct Python 3 solution for this coding contest problem. You are given the array a consisting of n elements and the integer k ≀ n. You want to obtain at least k equal elements in the array a. In one move, you can make one of the following two operations: * Take one of the minimum elements of t...
instruction
0
77,694
12
155,388
Tags: greedy Correct Solution: ``` a,b=list(map(int,input().split())) array=list(map(int,input().split())) c=b-1 answer=[] array.sort() arr=list(range(1,array[-1]+1)) for it in arr: element=it current=0 count=0 for y in range(0,a): copare=array[y] if copare<element: pass ...
output
1
77,694
12
155,389
Provide tags and a correct Python 3 solution for this coding contest problem. You are given the array a consisting of n elements and the integer k ≀ n. You want to obtain at least k equal elements in the array a. In one move, you can make one of the following two operations: * Take one of the minimum elements of t...
instruction
0
77,695
12
155,390
Tags: greedy Correct Solution: ``` '''input 5 3 1 2 3 3 3 ''' from sys import stdin from copy import deepcopy from collections import deque def solve(aux): # print(aux) count = 0 for i in range(1, len(aux)): while True: if aux[i] > aux[i - 1]: aux[i] //= 2 count += 1 elif aux[i] < aux[i - 1]: ...
output
1
77,695
12
155,391
Provide tags and a correct Python 3 solution for this coding contest problem. You are given the array a consisting of n elements and the integer k ≀ n. You want to obtain at least k equal elements in the array a. In one move, you can make one of the following two operations: * Take one of the minimum elements of t...
instruction
0
77,696
12
155,392
Tags: greedy Correct Solution: ``` from sys import stdin, stdout def write(_s): stdout.write(_s) def write_int(_s): stdout.write(str(_s)) def write_list(_l): stdout.write(" ".join(map(str, _l))) def read(): return stdin.readline().split(" ") def readint(): return int(stdin.readline()) de...
output
1
77,696
12
155,393
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given the array a consisting of n elements and the integer k ≀ n. You want to obtain at least k equal elements in the array a. In one move, you can make one of the following two operati...
instruction
0
77,697
12
155,394
Yes
output
1
77,697
12
155,395
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given the array a consisting of n elements and the integer k ≀ n. You want to obtain at least k equal elements in the array a. In one move, you can make one of the following two operati...
instruction
0
77,698
12
155,396
Yes
output
1
77,698
12
155,397
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given the array a consisting of n elements and the integer k ≀ n. You want to obtain at least k equal elements in the array a. In one move, you can make one of the following two operati...
instruction
0
77,699
12
155,398
Yes
output
1
77,699
12
155,399
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given the array a consisting of n elements and the integer k ≀ n. You want to obtain at least k equal elements in the array a. In one move, you can make one of the following two operati...
instruction
0
77,700
12
155,400
Yes
output
1
77,700
12
155,401
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given the array a consisting of n elements and the integer k ≀ n. You want to obtain at least k equal elements in the array a. In one move, you can make one of the following two operati...
instruction
0
77,701
12
155,402
No
output
1
77,701
12
155,403
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given the array a consisting of n elements and the integer k ≀ n. You want to obtain at least k equal elements in the array a. In one move, you can make one of the following two operati...
instruction
0
77,702
12
155,404
No
output
1
77,702
12
155,405
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given the array a consisting of n elements and the integer k ≀ n. You want to obtain at least k equal elements in the array a. In one move, you can make one of the following two operati...
instruction
0
77,703
12
155,406
No
output
1
77,703
12
155,407
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given the array a consisting of n elements and the integer k ≀ n. You want to obtain at least k equal elements in the array a. In one move, you can make one of the following two operati...
instruction
0
77,704
12
155,408
No
output
1
77,704
12
155,409
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a perm...
instruction
0
77,718
12
155,436
Tags: combinatorics, dp, graphs, math Correct Solution: ``` from sys import stdin, stdout import math,sys,heapq from itertools import permutations, combinations from collections import defaultdict,deque,OrderedDict from os import path import bisect as bi def yes():print('YES') def no():print('NO') if (path.exists('inpu...
output
1
77,718
12
155,437
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a perm...
instruction
0
77,719
12
155,438
Tags: combinatorics, dp, graphs, math Correct Solution: ``` n=int(input()) v=10**9 + 7 def modexp(a,b,c): if b==1: return a if b%2==0: y=modexp(a,b//2,c) z= (y*y) if z>=c: z=z%c return z else: y=modexp(a,b//2,c) z=y*y if z>=c: z=z%c x=a*z if x>=c: x=x%c return x g=1 for i in range(1,n...
output
1
77,719
12
155,439
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a perm...
instruction
0
77,720
12
155,440
Tags: combinatorics, dp, graphs, math Correct Solution: ``` n = int(input()) fact = 1; two = 1; for i in range(1, n + 1): fact *= i fact %= 1000000007 for i in range(1, n): two *= 2 two %= 1000000007 print((fact - two) % 1000000007) ```
output
1
77,720
12
155,441
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a perm...
instruction
0
77,721
12
155,442
Tags: combinatorics, dp, graphs, math Correct Solution: ``` import math M = 10 ** 9 + + 7 def fact(x): ans = 1 for i in range(2, x + 1): ans = (ans * i) % M return ans def modpow(b, p): res = 1 while p: if p % 2: res = (res * b) % M p >>= 1 b = (b ...
output
1
77,721
12
155,443
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a perm...
instruction
0
77,722
12
155,444
Tags: combinatorics, dp, graphs, math Correct Solution: ``` mod = 1000000007 n = int(input()) a = 1 for i in range(1, n + 1): a = (a * i) % mod b = pow(2, n - 1, mod) ans = (a - b + mod) % mod print(ans) ```
output
1
77,722
12
155,445