Dataset Viewer
Auto-converted to Parquet Duplicate
message
stringlengths
2
16.2k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
575
109k
cluster
float64
16
16
__index_level_0__
int64
1.15k
217k
Provide a correct Python 3 solution for this coding contest problem. We have a sequence of N integers: x=(x_0,x_1,\cdots,x_{N-1}). Initially, x_i=0 for each i (0 \leq i \leq N-1). Snuke will perform the following operation exactly M times: * Choose two distinct indices i, j (0 \leq i,j \leq N-1,\ i \neq j). Then, replace x_i with x_i+2 and x_j with x_j+1. Find the number of different sequences that can result after M operations. Since it can be enormous, compute the count modulo 998244353. Constraints * 2 \leq N \leq 10^6 * 1 \leq M \leq 5 \times 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the number of different sequences that can result after M operations, modulo 998244353. Examples Input 2 2 Output 3 Input 3 2 Output 19 Input 10 10 Output 211428932 Input 100000 50000 Output 3463133
instruction
0
575
16
1,150
"Correct Solution: ``` def prepare(n, MOD): f = 1 factorials = [1] * (n + 1) for m in range(1, n + 1): f = f * m % MOD factorials[m] = f inv = pow(f, MOD - 2, MOD) invs = [1] * (n + 1) invs[n] = inv for m in range(n, 1, -1): inv = inv * m % MOD invs[m - 1] = inv return factorials, invs def get_nhr(n, facts, invs, MOD): def nhr(r): return facts[n + r - 1] * invs[r] * invs[n - 1] % MOD return nhr def solve(n, m): MOD = 998244353 facts, invs = prepare(n + 3 * m, MOD) fn = facts[n] nhr = get_nhr(n, facts, invs, MOD) nm2 = min(n, m - 1) ans = 0 for odd in range(m % 2, min(m, n) + 1, 2): tmp = nhr((3 * m - odd) // 2) if odd > 0: tmp -= odd * nhr((m - odd) // 2) if odd < nm2: tmp -= (n - odd) * nhr((m - odd - 2) // 2) ans = (ans + fn * invs[odd] * invs[n - odd] % MOD * tmp) % MOD return ans n, m = list(map(int, input().split())) print(solve(n, m)) ```
output
1
575
16
1,151
Provide a correct Python 3 solution for this coding contest problem. We have a sequence of N integers: x=(x_0,x_1,\cdots,x_{N-1}). Initially, x_i=0 for each i (0 \leq i \leq N-1). Snuke will perform the following operation exactly M times: * Choose two distinct indices i, j (0 \leq i,j \leq N-1,\ i \neq j). Then, replace x_i with x_i+2 and x_j with x_j+1. Find the number of different sequences that can result after M operations. Since it can be enormous, compute the count modulo 998244353. Constraints * 2 \leq N \leq 10^6 * 1 \leq M \leq 5 \times 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the number of different sequences that can result after M operations, modulo 998244353. Examples Input 2 2 Output 3 Input 3 2 Output 19 Input 10 10 Output 211428932 Input 100000 50000 Output 3463133
instruction
0
576
16
1,152
"Correct Solution: ``` import sys input=sys.stdin.readline N,M=map(int,input().split()) mod=998244353 inv=[0]*(3*M//2+N+2) inv[1]=1 for i in range(2,3*M//2+N+2): inv[i]=-(mod//i)*inv[mod%i]%mod #階乗テーブル g1=[1,1] g2=[1,1] for i in range(2,3*M//2+N+2): num_1=g1[-1]*i%mod g1.append(num_1) g2.append(g2[-1]*inv[i]%mod) def cmb(n,r): return g1[n]*g2[r]*g2[n-r]%mod #奇数の和で場合分け #iは奇数の数 ans=0 for i in range(min(N+1,M+1)): if M%2!=i%2: continue m=(3*M-i)//2 num=(cmb(m+N-1,N-1)-i*cmb(m-M+N-1,N-1))%mod if m>=M+1: num=(num-(N-i)*cmb(m-M+N-2,N-1))%mod ans=(ans+cmb(N,i)*num)%mod print(ans) ```
output
1
576
16
1,153
Provide a correct Python 3 solution for this coding contest problem. We have a sequence of N integers: x=(x_0,x_1,\cdots,x_{N-1}). Initially, x_i=0 for each i (0 \leq i \leq N-1). Snuke will perform the following operation exactly M times: * Choose two distinct indices i, j (0 \leq i,j \leq N-1,\ i \neq j). Then, replace x_i with x_i+2 and x_j with x_j+1. Find the number of different sequences that can result after M operations. Since it can be enormous, compute the count modulo 998244353. Constraints * 2 \leq N \leq 10^6 * 1 \leq M \leq 5 \times 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the number of different sequences that can result after M operations, modulo 998244353. Examples Input 2 2 Output 3 Input 3 2 Output 19 Input 10 10 Output 211428932 Input 100000 50000 Output 3463133
instruction
0
577
16
1,154
"Correct Solution: ``` from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys from pprint import pprint from copy import deepcopy import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor from operator import mul from functools import reduce from pprint import pprint sys.setrecursionlimit(2147483647) INF = 10 ** 15 def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 998244353 n, m = LI() a = n + 3 * m fac = [1] * (a + 1) inv = [1] * (a + 1) for j in range(1, a + 1): fac[j] = fac[j-1] * j % mod inv[a] = pow(fac[a], mod-2, mod) for j in range(a-1, -1, -1): inv[j] = inv[j+1] * (j+1) % mod def comb(x, y): if y > x or x < 0 or y < 0: return 0 return fac[x] * inv[x - y] * inv[y] % mod ans = 0 for i in range(min(m + 1, n + 1)): if (m - i) % 2: continue ans += comb(n, i) * comb((m * 3 - i) // 2 + n - 1, n - 1) ans %= mod print((ans - n * comb(m - 1 + n - 1, n - 1)) % mod) ```
output
1
577
16
1,155
Provide a correct Python 3 solution for this coding contest problem. We have a sequence of N integers: x=(x_0,x_1,\cdots,x_{N-1}). Initially, x_i=0 for each i (0 \leq i \leq N-1). Snuke will perform the following operation exactly M times: * Choose two distinct indices i, j (0 \leq i,j \leq N-1,\ i \neq j). Then, replace x_i with x_i+2 and x_j with x_j+1. Find the number of different sequences that can result after M operations. Since it can be enormous, compute the count modulo 998244353. Constraints * 2 \leq N \leq 10^6 * 1 \leq M \leq 5 \times 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the number of different sequences that can result after M operations, modulo 998244353. Examples Input 2 2 Output 3 Input 3 2 Output 19 Input 10 10 Output 211428932 Input 100000 50000 Output 3463133
instruction
0
578
16
1,156
"Correct Solution: ``` n,m = map(int,input().split()) mod = 998244353 ################################# ## nCkのmodを求める関数 # テーブルを作る(前処理) max = n+2*m + 100 fac, finv, inv = [0]*max, [0]*max, [0]*max def comInit(max): fac[0] = fac[1] = 1 finv[0] = finv[1] = 1 inv[1] = 1 for i in range(2,max): fac[i] = fac[i-1]* i% mod inv[i] = mod - inv[mod%i] * (mod // i) % mod finv[i] = finv[i-1] * inv[i] % mod comInit(max) # 二項係数の計算 def com(n,k): if(n < k): return 0 if( (n<0) | (k < 0)): return 0 return fac[n] * (finv[k] * finv[n-k] % mod) % mod a = 0 for x in range(min(m,n)+1): if(3*m-x)%2==1: continue y = (3*m-x)//2 a += com(n,x)*fac[y+n-1]*finv[y]*finv[n-1] a %= mod b = fac[n-1+m-1] * finv[n-1] * finv[m-1] * n b %= mod ans = a-b ans %= mod print(ans) ```
output
1
578
16
1,157
Provide a correct Python 3 solution for this coding contest problem. We have a sequence of N integers: x=(x_0,x_1,\cdots,x_{N-1}). Initially, x_i=0 for each i (0 \leq i \leq N-1). Snuke will perform the following operation exactly M times: * Choose two distinct indices i, j (0 \leq i,j \leq N-1,\ i \neq j). Then, replace x_i with x_i+2 and x_j with x_j+1. Find the number of different sequences that can result after M operations. Since it can be enormous, compute the count modulo 998244353. Constraints * 2 \leq N \leq 10^6 * 1 \leq M \leq 5 \times 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the number of different sequences that can result after M operations, modulo 998244353. Examples Input 2 2 Output 3 Input 3 2 Output 19 Input 10 10 Output 211428932 Input 100000 50000 Output 3463133
instruction
0
579
16
1,158
"Correct Solution: ``` class comb(): F = [1, 1] Fi = [1, 1] I = [0, 1] def __init__(self, num, mod): self.MOD = mod for i in range(2, num + 1): self.F.append((self.F[-1] * i) % mod) self.I.append(mod - self.I[mod % i] * (mod // i) % mod) self.Fi.append(self.Fi[-1] * self.I[i] % mod) def com(self, n, k): if n < k: return 0 if n < 0 or k < 0: return 0 return self.F[n] * (self.Fi[k] * self.Fi[n - k] % self.MOD) % self.MOD N, M = list(map(int, input().split())) MOD = 998244353 com = comb(M * 3 + N, MOD) t = com.com(M * 3 + N - 1, N - 1) t -= com.com(M - 1 + N - 1, N -1) * N while t < 0: t += MOD if N > M: for k in range(M + 2, N + 1, 2): i = (M * 3 - k) // 2 t -= com.com(N, k) * com.com(N - 1 + i, i) % MOD while t < 0: t += MOD print(t) ```
output
1
579
16
1,159
Provide a correct Python 3 solution for this coding contest problem. We have a sequence of N integers: x=(x_0,x_1,\cdots,x_{N-1}). Initially, x_i=0 for each i (0 \leq i \leq N-1). Snuke will perform the following operation exactly M times: * Choose two distinct indices i, j (0 \leq i,j \leq N-1,\ i \neq j). Then, replace x_i with x_i+2 and x_j with x_j+1. Find the number of different sequences that can result after M operations. Since it can be enormous, compute the count modulo 998244353. Constraints * 2 \leq N \leq 10^6 * 1 \leq M \leq 5 \times 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the number of different sequences that can result after M operations, modulo 998244353. Examples Input 2 2 Output 3 Input 3 2 Output 19 Input 10 10 Output 211428932 Input 100000 50000 Output 3463133
instruction
0
580
16
1,160
"Correct Solution: ``` n,m=map(int,input().split()) w,u=3*m,n-1 o,f,i=998244353,[1],1 while i<w+n:f+=[f[-1]*i%o];i+=1 c=lambda n,k=u:f[n]*pow(f[n-k],o-2,o)*pow(f[k],o-2,o) a=c(w+u)-n*c(n+m-2) while~-n>m<w:m+=2;a-=c(n,m)*c(2*u+w-m>>1) print(a%o) ```
output
1
580
16
1,161
Provide a correct Python 3 solution for this coding contest problem. We have a sequence of N integers: x=(x_0,x_1,\cdots,x_{N-1}). Initially, x_i=0 for each i (0 \leq i \leq N-1). Snuke will perform the following operation exactly M times: * Choose two distinct indices i, j (0 \leq i,j \leq N-1,\ i \neq j). Then, replace x_i with x_i+2 and x_j with x_j+1. Find the number of different sequences that can result after M operations. Since it can be enormous, compute the count modulo 998244353. Constraints * 2 \leq N \leq 10^6 * 1 \leq M \leq 5 \times 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the number of different sequences that can result after M operations, modulo 998244353. Examples Input 2 2 Output 3 Input 3 2 Output 19 Input 10 10 Output 211428932 Input 100000 50000 Output 3463133
instruction
0
581
16
1,162
"Correct Solution: ``` n,m=map(int,input().split()) o,f,i=998244353,[1],1 while i<3*m+n:f+=[f[-1]*i%o];i+=1 c=lambda x,y=n-1:f[x]*pow(f[x-y]*f[y]%o,o-2,o) a=c(-1)-n*c(n+m-2) while~-n>m<i-n:m+=2;a-=c(n,m)*c(n-1+i-m>>1) print(a%o) ```
output
1
581
16
1,163
Provide a correct Python 3 solution for this coding contest problem. We have a sequence of N integers: x=(x_0,x_1,\cdots,x_{N-1}). Initially, x_i=0 for each i (0 \leq i \leq N-1). Snuke will perform the following operation exactly M times: * Choose two distinct indices i, j (0 \leq i,j \leq N-1,\ i \neq j). Then, replace x_i with x_i+2 and x_j with x_j+1. Find the number of different sequences that can result after M operations. Since it can be enormous, compute the count modulo 998244353. Constraints * 2 \leq N \leq 10^6 * 1 \leq M \leq 5 \times 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the number of different sequences that can result after M operations, modulo 998244353. Examples Input 2 2 Output 3 Input 3 2 Output 19 Input 10 10 Output 211428932 Input 100000 50000 Output 3463133
instruction
0
582
16
1,164
"Correct Solution: ``` from functools import lru_cache def prepare(n, MOD): f = 1 factorials = [1] for m in range(1, n + 1): f *= m f %= MOD factorials.append(f) inv = pow(f, MOD - 2, MOD) invs = [1] * (n + 1) invs[n] = inv for m in range(n, 1, -1): inv *= m inv %= MOD invs[m - 1] = inv return factorials, invs def get_nhr(n, facts, invs): @lru_cache(maxsize=None) def nhr(r): return facts[n + r - 1] * invs[r] * invs[n - 1] % MOD return nhr MOD = 998244353 n, m = list(map(int, input().split())) facts, invs = prepare(n + 3 * m, MOD) nhr = get_nhr(n, facts, invs) ans = 0 for odd in range(m % 2, min(m, n) + 1, 2): tmp = nhr((3 * m - odd) // 2) if odd > 0: tmp -= odd * nhr((m - odd) // 2) if odd < n and odd <= m - 2: tmp -= (n - odd) * nhr((m - odd - 2) // 2) ans = (ans + facts[n] * invs[odd] * invs[n - odd] % MOD * tmp) % MOD print(ans) ```
output
1
582
16
1,165
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a sequence of N integers: x=(x_0,x_1,\cdots,x_{N-1}). Initially, x_i=0 for each i (0 \leq i \leq N-1). Snuke will perform the following operation exactly M times: * Choose two distinct indices i, j (0 \leq i,j \leq N-1,\ i \neq j). Then, replace x_i with x_i+2 and x_j with x_j+1. Find the number of different sequences that can result after M operations. Since it can be enormous, compute the count modulo 998244353. Constraints * 2 \leq N \leq 10^6 * 1 \leq M \leq 5 \times 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the number of different sequences that can result after M operations, modulo 998244353. Examples Input 2 2 Output 3 Input 3 2 Output 19 Input 10 10 Output 211428932 Input 100000 50000 Output 3463133 Submitted Solution: ``` #!usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): return list(sys.stdin.readline())[:-1] def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) #A def A(): n = I() if n <= 1000000000: print(0,0,1,0,0,n) else: b = math.ceil(n**0.5) if b**2 == n: print(0,0,b,0,0,n//b) return x = b m = b*x-n if m < 0: b += 1 x += 1 m = b*x-n n = m for a in range(int(n**0.5)+1)[::-1]: if n%a == 0: print(0,0,x,n//a,a,b) return return #B def B(): n,k = LI() a = LI() s = [] f = [1]*1000000 for i in range(k): for j in range(n): aj = a[j] if f[aj]: s.append(aj) f[aj] = 0 else: while 1: x = s.pop(-1) f[x] = 1 if x == aj: break print(i+1,s) return #C mod = 998244353 def C(): def comb(a,b): if a < b: return 1 return fact[a]*inv[b]*inv[a-b]%mod n,m = LI() MA = 3*m+max(n,2*m)-1 fact = [1]*(MA+1) for i in range(MA): fact[i+1] = fact[i]*(i+1)%mod inv = [1]*(MA+1) inv[MA] = pow(fact[MA],mod-2,mod) for i in range(MA)[::-1]: inv[i] = inv[i+1]*(i+1)%mod ans = 0 for k in range(min(m,n)+1): if (3*m-k)%2 == 0: ans += comb(n,k)*comb((3*m-k)//2+n-1,n-1) ans %= mod ans -= n*comb(3*m-(2*m+1)+n-1,n-1) ans %= mod print(ans) return #D def D(): return #E def E(): n = I() return #F def F(): n = I() return #Solve if __name__ == "__main__": C() ```
instruction
0
583
16
1,166
Yes
output
1
583
16
1,167
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a sequence of N integers: x=(x_0,x_1,\cdots,x_{N-1}). Initially, x_i=0 for each i (0 \leq i \leq N-1). Snuke will perform the following operation exactly M times: * Choose two distinct indices i, j (0 \leq i,j \leq N-1,\ i \neq j). Then, replace x_i with x_i+2 and x_j with x_j+1. Find the number of different sequences that can result after M operations. Since it can be enormous, compute the count modulo 998244353. Constraints * 2 \leq N \leq 10^6 * 1 \leq M \leq 5 \times 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the number of different sequences that can result after M operations, modulo 998244353. Examples Input 2 2 Output 3 Input 3 2 Output 19 Input 10 10 Output 211428932 Input 100000 50000 Output 3463133 Submitted Solution: ``` N, M = map(int, input().split()) MOD = 998244353 if N < M : one = N - (N - M) % 2 two = (3 * M - one) // 2 else : one, two = M, M L = M + M // 2 + N - 1 fac = [0] * (L + 1) inv = [0] * (L + 1) fac[0], inv[0] = 1, 1 for i in range(1, L + 1) : fac[i] = fac[i-1] * i % MOD inv[i] = pow(fac[i], MOD-2, MOD) def comb(n, r) : if n <= 0 or r < 0 : return 0 return fac[n]*inv[n-r]*inv[r]%MOD ret = 0 while one >= 0 : ret += comb(N, one) * comb(two+N-1, N-1) % MOD ret %= MOD one -= 2 two += 1 ret -= comb(3*M+N-1-(2*M+1), N-1) * N print(ret % MOD) ```
instruction
0
584
16
1,168
Yes
output
1
584
16
1,169
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a sequence of N integers: x=(x_0,x_1,\cdots,x_{N-1}). Initially, x_i=0 for each i (0 \leq i \leq N-1). Snuke will perform the following operation exactly M times: * Choose two distinct indices i, j (0 \leq i,j \leq N-1,\ i \neq j). Then, replace x_i with x_i+2 and x_j with x_j+1. Find the number of different sequences that can result after M operations. Since it can be enormous, compute the count modulo 998244353. Constraints * 2 \leq N \leq 10^6 * 1 \leq M \leq 5 \times 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the number of different sequences that can result after M operations, modulo 998244353. Examples Input 2 2 Output 3 Input 3 2 Output 19 Input 10 10 Output 211428932 Input 100000 50000 Output 3463133 Submitted Solution: ``` from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math from bisect import bisect_left, bisect_right import random from itertools import permutations, accumulate, combinations import sys import string INF = float('inf') def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return sys.stdin.readline().strip() def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 998244353 n, m = LI() total = m * 3 fac = [1] * (total+n+1) inv = [1] * (total+n+1) for i in range(total+n): fac[i+1] = fac[i]*(i+1)%mod inv[total+n]=pow(fac[-1], mod-2, mod) for j in range(total+n-1, -1, -1): inv[j]=inv[j+1]*(j+1)%mod def comb(n, r): if r > n: return 0 return fac[n] * inv[n - r] * inv[r] % mod ans = comb(total+n-1, n-1) for i in range(m + 2, min(n + 1, total + 1)): if (total - i) % 2 == 0: ans -= comb(n, i) * comb(n + (total - i) // 2 - 1, n - 1) % mod ans %= mod ret = 0 for i in range(m): ret = (ret + comb(i + n - 2, n - 2)) % mod ans -= (ret * n) % mod print(ans % mod) ```
instruction
0
585
16
1,170
Yes
output
1
585
16
1,171
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a sequence of N integers: x=(x_0,x_1,\cdots,x_{N-1}). Initially, x_i=0 for each i (0 \leq i \leq N-1). Snuke will perform the following operation exactly M times: * Choose two distinct indices i, j (0 \leq i,j \leq N-1,\ i \neq j). Then, replace x_i with x_i+2 and x_j with x_j+1. Find the number of different sequences that can result after M operations. Since it can be enormous, compute the count modulo 998244353. Constraints * 2 \leq N \leq 10^6 * 1 \leq M \leq 5 \times 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the number of different sequences that can result after M operations, modulo 998244353. Examples Input 2 2 Output 3 Input 3 2 Output 19 Input 10 10 Output 211428932 Input 100000 50000 Output 3463133 Submitted Solution: ``` n,m=map(int,input().split()) w,u=3*m,n-1 o,f,i=998244353,[1],1 while i<w+n:f+=[f[-1]*i%o];i+=1 c=lambda n,k:f[n]*pow(f[n-k],o-2,o)*pow(f[k],o-2,o) a=c(w+u,u)-n*c(n+m-2,u) while n>-~m<w:m+=2;a-=c(n,m)*c(2*u+w-m>>1,u) print(a%o) ```
instruction
0
586
16
1,172
Yes
output
1
586
16
1,173
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a sequence of N integers: x=(x_0,x_1,\cdots,x_{N-1}). Initially, x_i=0 for each i (0 \leq i \leq N-1). Snuke will perform the following operation exactly M times: * Choose two distinct indices i, j (0 \leq i,j \leq N-1,\ i \neq j). Then, replace x_i with x_i+2 and x_j with x_j+1. Find the number of different sequences that can result after M operations. Since it can be enormous, compute the count modulo 998244353. Constraints * 2 \leq N \leq 10^6 * 1 \leq M \leq 5 \times 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the number of different sequences that can result after M operations, modulo 998244353. Examples Input 2 2 Output 3 Input 3 2 Output 19 Input 10 10 Output 211428932 Input 100000 50000 Output 3463133 Submitted Solution: ``` import sys input = sys.stdin.readline U = 4*10**6 MOD = 998244353 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 %= MOD z *= fact_inv[n-k] z %= MOD return z n, m = map(int, input().split()) ans = 0 for k in range(m%2, min(n, m)+1, 2): ans += comb((3*m-k)//2+n-1, n-1) * comb(n, k) ans %= MOD cnt = 0 for k in range(m): cnt += comb(k+n-2, n-2) cnt %= MOD cnt *= n cnt %= MOD ans -= cnt ans %= MOD print(ans) ```
instruction
0
587
16
1,174
No
output
1
587
16
1,175
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a sequence of N integers: x=(x_0,x_1,\cdots,x_{N-1}). Initially, x_i=0 for each i (0 \leq i \leq N-1). Snuke will perform the following operation exactly M times: * Choose two distinct indices i, j (0 \leq i,j \leq N-1,\ i \neq j). Then, replace x_i with x_i+2 and x_j with x_j+1. Find the number of different sequences that can result after M operations. Since it can be enormous, compute the count modulo 998244353. Constraints * 2 \leq N \leq 10^6 * 1 \leq M \leq 5 \times 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the number of different sequences that can result after M operations, modulo 998244353. Examples Input 2 2 Output 3 Input 3 2 Output 19 Input 10 10 Output 211428932 Input 100000 50000 Output 3463133 Submitted Solution: ``` import sys input=sys.stdin.readline N,M=map(int,input().split()) mod=998244353 #階乗テーブル g1=[1,1] for i in range(2,3*M//2+N+2): g1.append(g1[-1]*i%mod) def cmb(n,r): return g1[n]*pow(g1[r],mod-2,mod)*pow(g1[n-r],mod-2,mod)%mod #奇数の和で場合分け #iは奇数の数 ans=0 for i in range(min(N+1,M+1)): if M%2!=i%2: continue m=(3*M-i)//2 num=(cmb(m+N-1,N-1)-i*cmb(m-M+N-1,N-1))%mod if m>=M+1: num=(num-(N-i)*cmb(m-M+N-2,N-1))%mod ans=(ans+cmb(N,i)*num)%mod print(ans) ```
instruction
0
588
16
1,176
No
output
1
588
16
1,177
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a sequence of N integers: x=(x_0,x_1,\cdots,x_{N-1}). Initially, x_i=0 for each i (0 \leq i \leq N-1). Snuke will perform the following operation exactly M times: * Choose two distinct indices i, j (0 \leq i,j \leq N-1,\ i \neq j). Then, replace x_i with x_i+2 and x_j with x_j+1. Find the number of different sequences that can result after M operations. Since it can be enormous, compute the count modulo 998244353. Constraints * 2 \leq N \leq 10^6 * 1 \leq M \leq 5 \times 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the number of different sequences that can result after M operations, modulo 998244353. Examples Input 2 2 Output 3 Input 3 2 Output 19 Input 10 10 Output 211428932 Input 100000 50000 Output 3463133 Submitted Solution: ``` import sys input = sys.stdin.readline N,M = map(int,input().split()) mod = 998244353 FACT=[1] for i in range(1,25*10**5+1): FACT.append(FACT[-1]*i%mod) FACT_INV=[pow(FACT[-1],mod-2,mod)] for i in range(25*10**5,0,-1): FACT_INV.append(FACT_INV[-1]*i%mod) FACT_INV.reverse() def Combi(a,b): if 0<=b<=a: return FACT[a]*FACT_INV[b]*FACT_INV[a-b]%mod else: return 0 ANS=Combi(M*3+N-1,N-1) for i in range(M*2+1,M*3+1): k=M*3-i ANS=(ANS-N*Combi(k+(N-1)-1,N-2))%mod for i in range(M+1,N+1): if (M*3-i)%2==1: continue k=(M*3-i)//2 ANS=(ANS-Combi(N,i)*Combi(k+N-1,N-1))%mod print(ANS) ```
instruction
0
589
16
1,178
No
output
1
589
16
1,179
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a sequence of N integers: x=(x_0,x_1,\cdots,x_{N-1}). Initially, x_i=0 for each i (0 \leq i \leq N-1). Snuke will perform the following operation exactly M times: * Choose two distinct indices i, j (0 \leq i,j \leq N-1,\ i \neq j). Then, replace x_i with x_i+2 and x_j with x_j+1. Find the number of different sequences that can result after M operations. Since it can be enormous, compute the count modulo 998244353. Constraints * 2 \leq N \leq 10^6 * 1 \leq M \leq 5 \times 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the number of different sequences that can result after M operations, modulo 998244353. Examples Input 2 2 Output 3 Input 3 2 Output 19 Input 10 10 Output 211428932 Input 100000 50000 Output 3463133 Submitted Solution: ``` import sys input = sys.stdin.readline import numpy as np N,M = map(int,input().split()) MOD = 998244353 def cumprod_mod(arr): L = len(arr) Lsq = int(L**.5+1) arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq) for n in range(1,Lsq): arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD for n in range(1,Lsq): arr[n] *= arr[n-1,-1]; arr[n] %= MOD arr = arr.ravel()[:L] return arr U = 2*10**6 + 100 x = np.arange(U,dtype=np.int64) x[0] = 1 fact = cumprod_mod(x) x = np.arange(U,0,-1,dtype=np.int64) x[0] = pow(int(fact[-1]),MOD-2,MOD) fact_inv = cumprod_mod(x)[::-1] def comb(n,k): return fact[n] * fact_inv[k] % MOD * fact_inv[n-k] % MOD x = comb(3*M+N-1,N-1) # 何でもいいから作る y = N * comb(M+N-2,N-1) # どれかが 2M+1 以上 # 奇数がM+1個以上あるものを除く odd_cnt = np.arange(M+2,3*M+1,2) S = (3*M - odd_cnt)//2 bl = (odd_cnt <= N)&(S>=0) odd_cnt = odd_cnt[bl] S = S[bl] arr = fact[N] * fact_inv[odd_cnt] % MOD * fact_inv[N-odd_cnt] % MOD # SをN個で作る -> S+N-1 C N-1 arr *= fact[S+N-1] * fact_inv[N-1] % MOD * fact_inv[S] % MOD arr %= MOD z = arr.sum() % MOD answer = x-y-z answer %= MOD print(answer) ```
instruction
0
590
16
1,180
No
output
1
590
16
1,181
Provide a correct Python 3 solution for this coding contest problem. Snuke received a triangle as a birthday present. The coordinates of the three vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3). He wants to draw two circles with the same radius inside the triangle such that the two circles do not overlap (but they may touch). Compute the maximum possible radius of the circles. Constraints * 0 ≤ x_i, y_i ≤ 1000 * The coordinates are integers. * The three points are not on the same line. Input The input is given from Standard Input in the following format: x_1 y_1 x_2 y_2 x_3 y_3 Output Print the maximum possible radius of the circles. The absolute error or the relative error must be at most 10^{-9}. Examples Input 0 0 1 1 2 0 Output 0.292893218813 Input 3 1 1 5 4 9 Output 0.889055514217
instruction
0
655
16
1,310
"Correct Solution: ``` from math import acos, tan, hypot def getRad1(s12, s13, s23): return acos((s12*s12 + s13*s13 - s23*s23) / (2*s12*s13)) def getMaxR(s12, rad1, rad2): tan1 = tan(rad1 / 2) tan2 = tan(rad2 / 2) h = s12 * (tan1*tan2) / (tan1+tan2) return h * (tan1+tan2) / (2*tan1*tan2 + tan1 + tan2) x1, y1 = map(int, input().split()) x2, y2 = map(int, input().split()) x3, y3 = map(int, input().split()) s12 = hypot(x1-x2, y1-y2) s23 = hypot(x2-x3, y2-y3) s31 = hypot(x3-x1, y3-y1) rad1 = getRad1(s12, s31, s23) rad2 = getRad1(s23, s12, s31) rad3 = getRad1(s31, s23, s12) maxRs = [ getMaxR(s12, rad1, rad2), getMaxR(s23, rad2, rad3), getMaxR(s31, rad3, rad1) ] print(max(maxRs)) ```
output
1
655
16
1,311
Provide a correct Python 3 solution for this coding contest problem. Snuke received a triangle as a birthday present. The coordinates of the three vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3). He wants to draw two circles with the same radius inside the triangle such that the two circles do not overlap (but they may touch). Compute the maximum possible radius of the circles. Constraints * 0 ≤ x_i, y_i ≤ 1000 * The coordinates are integers. * The three points are not on the same line. Input The input is given from Standard Input in the following format: x_1 y_1 x_2 y_2 x_3 y_3 Output Print the maximum possible radius of the circles. The absolute error or the relative error must be at most 10^{-9}. Examples Input 0 0 1 1 2 0 Output 0.292893218813 Input 3 1 1 5 4 9 Output 0.889055514217
instruction
0
656
16
1,312
"Correct Solution: ``` xy = [list(map(int, input().split())) for _ in range(3)] d = [((xy[i][0] - xy[i + 1][0]) ** 2 + (xy[i][1] - xy[i + 1][1]) ** 2) ** .5 for i in range(-1, 2)] s = abs((xy[1][0] - xy[0][0]) * (xy[2][1] - xy[0][1]) -(xy[2][0] - xy[0][0]) * (xy[1][1] - xy[0][1])) / 2 k = max(d) r = 2 * s / sum(d) x = k * r / (k + 2 * r) print('{:.10f}'.format(x)) ```
output
1
656
16
1,313
Provide a correct Python 3 solution for this coding contest problem. Snuke received a triangle as a birthday present. The coordinates of the three vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3). He wants to draw two circles with the same radius inside the triangle such that the two circles do not overlap (but they may touch). Compute the maximum possible radius of the circles. Constraints * 0 ≤ x_i, y_i ≤ 1000 * The coordinates are integers. * The three points are not on the same line. Input The input is given from Standard Input in the following format: x_1 y_1 x_2 y_2 x_3 y_3 Output Print the maximum possible radius of the circles. The absolute error or the relative error must be at most 10^{-9}. Examples Input 0 0 1 1 2 0 Output 0.292893218813 Input 3 1 1 5 4 9 Output 0.889055514217
instruction
0
657
16
1,314
"Correct Solution: ``` import sys stdin = sys.stdin sys.setrecursionlimit(10**5) def li(): return map(int, stdin.readline().split()) def li_(): return map(lambda x: int(x)-1, stdin.readline().split()) def lf(): return map(float, stdin.readline().split()) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) from math import sqrt points = [tuple(li()) for _ in range(3)] # 3つの辺を求める sides = [] angles = [] for i in range(3): p1,p2 = points[i], points[(i+1)%3] sides.append(sqrt((p2[0]-p1[0])**2 + (p2[1]-p1[1])**2)) # 内接円の半径 s = (sum(sides)) / 2 a,b,c = sides area = sqrt(s* (s-a) * (s-b) * (s-c)) r = 2*area / sum(sides) print(max(sides)*r / (2*r + max(sides))) ```
output
1
657
16
1,315
Provide a correct Python 3 solution for this coding contest problem. Snuke received a triangle as a birthday present. The coordinates of the three vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3). He wants to draw two circles with the same radius inside the triangle such that the two circles do not overlap (but they may touch). Compute the maximum possible radius of the circles. Constraints * 0 ≤ x_i, y_i ≤ 1000 * The coordinates are integers. * The three points are not on the same line. Input The input is given from Standard Input in the following format: x_1 y_1 x_2 y_2 x_3 y_3 Output Print the maximum possible radius of the circles. The absolute error or the relative error must be at most 10^{-9}. Examples Input 0 0 1 1 2 0 Output 0.292893218813 Input 3 1 1 5 4 9 Output 0.889055514217
instruction
0
658
16
1,316
"Correct Solution: ``` x1, y1 = map(int, input().split()) x2, y2 = map(int, input().split()) x3, y3 = map(int, input().split()) e12 = ((x2-x1)**2 + (y2-y1)**2)**0.5 e23 = ((x3-x2)**2 + (y3-y2)**2)**0.5 e31 = ((x1-x3)**2 + (y1-y3)**2)**0.5 s = (e12 + e23 + e31)/2 S = (s * (s-e12) * (s-e23) * (s-e31)) ** 0.5 r=2*S/(e12+e23+e31) A=max(e12,e23,e31) print(A*r/(2*r+A)) ```
output
1
658
16
1,317
Provide a correct Python 3 solution for this coding contest problem. Snuke received a triangle as a birthday present. The coordinates of the three vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3). He wants to draw two circles with the same radius inside the triangle such that the two circles do not overlap (but they may touch). Compute the maximum possible radius of the circles. Constraints * 0 ≤ x_i, y_i ≤ 1000 * The coordinates are integers. * The three points are not on the same line. Input The input is given from Standard Input in the following format: x_1 y_1 x_2 y_2 x_3 y_3 Output Print the maximum possible radius of the circles. The absolute error or the relative error must be at most 10^{-9}. Examples Input 0 0 1 1 2 0 Output 0.292893218813 Input 3 1 1 5 4 9 Output 0.889055514217
instruction
0
659
16
1,318
"Correct Solution: ``` import sys input = sys.stdin.readline #import heapq #from fractions import gcd #from collections import defaultdict #sys.setrecursionlimit(10**9) #map(int,input().split()) def main(): li=[list(map(int,input().split())) for i in range(3)] li.append(li[0]) d=[0]*3 for i in range(3): d[i]=((li[i][0]-li[i+1][0])**2+(li[i][1]-li[i+1][1])**2)**0.5 dmax=max(d) dsum=sum(d) s=dsum/2 S=(s*(s-d[0])*(s-d[1])*(s-d[2]))**0.5 r=2*S/dsum print((r*dmax)/(2*r+dmax)) if __name__ == '__main__': main() ```
output
1
659
16
1,319
Provide a correct Python 3 solution for this coding contest problem. Snuke received a triangle as a birthday present. The coordinates of the three vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3). He wants to draw two circles with the same radius inside the triangle such that the two circles do not overlap (but they may touch). Compute the maximum possible radius of the circles. Constraints * 0 ≤ x_i, y_i ≤ 1000 * The coordinates are integers. * The three points are not on the same line. Input The input is given from Standard Input in the following format: x_1 y_1 x_2 y_2 x_3 y_3 Output Print the maximum possible radius of the circles. The absolute error or the relative error must be at most 10^{-9}. Examples Input 0 0 1 1 2 0 Output 0.292893218813 Input 3 1 1 5 4 9 Output 0.889055514217
instruction
0
660
16
1,320
"Correct Solution: ``` p1 = list(map(int, input().split())) p2 = list(map(int, input().split())) p3 = list(map(int, input().split())) len1 = ((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) ** 0.5 len2 = ((p2[0] - p3[0]) ** 2 + (p2[1] - p3[1]) ** 2) ** 0.5 len3 = ((p3[0] - p1[0]) ** 2 + (p3[1] - p1[1]) ** 2) ** 0.5 l = (len1 + len2 + len3) / 2 s = (l * (l - len1) * (l - len2) * (l - len3)) ** 0.5 r = 2 * s /(len1 + len2 + len3) def solve(mid): return (1 - mid / r) * max(len1, len2, len3) >= 2 * mid ok = 0 ng = 10 ** 9 cnt = 0 while True: mid = (ok + ng) / 2 if solve(mid): ok = mid else: ng = mid cnt += 1 if cnt > 60: break print(ok) ```
output
1
660
16
1,321
Provide a correct Python 3 solution for this coding contest problem. Snuke received a triangle as a birthday present. The coordinates of the three vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3). He wants to draw two circles with the same radius inside the triangle such that the two circles do not overlap (but they may touch). Compute the maximum possible radius of the circles. Constraints * 0 ≤ x_i, y_i ≤ 1000 * The coordinates are integers. * The three points are not on the same line. Input The input is given from Standard Input in the following format: x_1 y_1 x_2 y_2 x_3 y_3 Output Print the maximum possible radius of the circles. The absolute error or the relative error must be at most 10^{-9}. Examples Input 0 0 1 1 2 0 Output 0.292893218813 Input 3 1 1 5 4 9 Output 0.889055514217
instruction
0
661
16
1,322
"Correct Solution: ``` a,b,c,d,e,f=map(int,open(0).read().split()) a,b,c=sorted((s*s+t*t)**.5for s,t in((a-c,b-d),(c-e,d-f),(e-a,f-b))) d=a+b+c s=d/2 s=(s*(s-a)*(s-b)*(s-c))**.5 print(c/(2+c/2/s*d)) ```
output
1
661
16
1,323
Provide a correct Python 3 solution for this coding contest problem. Snuke received a triangle as a birthday present. The coordinates of the three vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3). He wants to draw two circles with the same radius inside the triangle such that the two circles do not overlap (but they may touch). Compute the maximum possible radius of the circles. Constraints * 0 ≤ x_i, y_i ≤ 1000 * The coordinates are integers. * The three points are not on the same line. Input The input is given from Standard Input in the following format: x_1 y_1 x_2 y_2 x_3 y_3 Output Print the maximum possible radius of the circles. The absolute error or the relative error must be at most 10^{-9}. Examples Input 0 0 1 1 2 0 Output 0.292893218813 Input 3 1 1 5 4 9 Output 0.889055514217
instruction
0
662
16
1,324
"Correct Solution: ``` def OuterProduct(one, two): tmp = one.conjugate() * two return tmp.imag def Area(dots): res = 0 for i in range(len(dots)-1): res += OuterProduct(dots[i], dots[i+1]) res += OuterProduct(dots[-1], dots[0]) return res/2 d = [list(map(int, input().split())) for _ in range(3)] x = complex(d[0][0], d[0][1]) y = complex(d[1][0], d[1][1]) z = complex(d[2][0], d[2][1]) s = abs(Area([x, y, z])) a, b, c = abs(x-y), abs(y-z), abs(z-x) print(2*s/(a+b+c+(4*s/max(a, b, c)))) ```
output
1
662
16
1,325
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke received a triangle as a birthday present. The coordinates of the three vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3). He wants to draw two circles with the same radius inside the triangle such that the two circles do not overlap (but they may touch). Compute the maximum possible radius of the circles. Constraints * 0 ≤ x_i, y_i ≤ 1000 * The coordinates are integers. * The three points are not on the same line. Input The input is given from Standard Input in the following format: x_1 y_1 x_2 y_2 x_3 y_3 Output Print the maximum possible radius of the circles. The absolute error or the relative error must be at most 10^{-9}. Examples Input 0 0 1 1 2 0 Output 0.292893218813 Input 3 1 1 5 4 9 Output 0.889055514217 Submitted Solution: ``` from math import hypot p = [list(map(int, input().split())) for i in range(3)] x1 = p[1][0] - p[0][0] y1 = p[1][1] - p[0][1] x2 = p[2][0] - p[0][0] y2 = p[2][1] - p[0][1] s2 = abs(x1*y2-x2*y1) s = 0 m = 0 for i in range(3): x = p[i-1][0]-p[i][0] y = p[i-1][1]-p[i][1] l = hypot(x, y) s += l m = max(m, l) r = s2/s x = m*r/(2*r+m) print(x) ```
instruction
0
665
16
1,330
Yes
output
1
665
16
1,331
Provide a correct Python 3 solution for this coding contest problem. There are N blocks arranged in a row, numbered 1 to N from left to right. Each block has a weight, and the weight of Block i is A_i. Snuke will perform the following operation on these blocks N times: * Choose one block that is still not removed, and remove it. The cost of this operation is the sum of the weights of the blocks that are connected to the block being removed (including itself). Here, two blocks x and y ( x \leq y ) are connected when, for all z ( x \leq z \leq y ), Block z is still not removed. There are N! possible orders in which Snuke removes the blocks. For all of those N! orders, find the total cost of the N operations, and calculate the sum of those N! total costs. As the answer can be extremely large, compute the sum modulo 10^9+7. Constraints * 1 \leq N \leq 10^5 * 1 \leq A_i \leq 10^9 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output For all of the N! orders, find the total cost of the N operations, and print the sum of those N! total costs, modulo 10^9+7. Examples Input 2 1 2 Output 9 Input 4 1 1 1 1 Output 212 Input 10 1 2 4 8 16 32 64 128 256 512 Output 880971923
instruction
0
1,508
16
3,016
"Correct Solution: ``` import sys input = sys.stdin.readline MOD = pow(10, 9) + 7 def main(): n = int(input()) alist = list(map(int, input().split())) nn = 1 for i in range(2, n+1): nn = nn * i % MOD rev = [pow(i, MOD-2, MOD) * nn % MOD for i in range(1, n+1)] for i in range(1, n): rev[i] = (rev[i] + rev[i-1]) % MOD ans = 0 for i in range(n): ans += alist[i] * (rev[i] + rev[n-i-1] - rev[0]) % MOD ans %= MOD print(ans) if __name__ == '__main__': main() ```
output
1
1,508
16
3,017
Provide a correct Python 3 solution for this coding contest problem. There are N blocks arranged in a row, numbered 1 to N from left to right. Each block has a weight, and the weight of Block i is A_i. Snuke will perform the following operation on these blocks N times: * Choose one block that is still not removed, and remove it. The cost of this operation is the sum of the weights of the blocks that are connected to the block being removed (including itself). Here, two blocks x and y ( x \leq y ) are connected when, for all z ( x \leq z \leq y ), Block z is still not removed. There are N! possible orders in which Snuke removes the blocks. For all of those N! orders, find the total cost of the N operations, and calculate the sum of those N! total costs. As the answer can be extremely large, compute the sum modulo 10^9+7. Constraints * 1 \leq N \leq 10^5 * 1 \leq A_i \leq 10^9 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output For all of the N! orders, find the total cost of the N operations, and print the sum of those N! total costs, modulo 10^9+7. Examples Input 2 1 2 Output 9 Input 4 1 1 1 1 Output 212 Input 10 1 2 4 8 16 32 64 128 256 512 Output 880971923
instruction
0
1,509
16
3,018
"Correct Solution: ``` def multiply(x, y): return (x * y) % mod def power(x, y): if y == 0: return 1 elif y == 1: return x elif x == 1: return 1 elif x == 0: return 0 else: # print(mod) tmp = power(x, y // 2) return (multiply(tmp, tmp) * [1, x][y % 2]) % mod N = int(input()) A = list(map(int, input().split())) mod = 10 ** 9 + 7 plist = [0] nfact = 1 N tmp = 0 for i in range(1, N): tmp = (tmp + power(i + 1, mod - 2)) % mod nfact = (nfact * (i + 1)) % mod plist.append(tmp) ans = 0 # print(plist) # print(nfact) for i, a in enumerate(A): # print(i, N - i - 1, N) tmp = (1 + plist[i] + plist[N - i - 1]) % mod ans = (ans + multiply(multiply(a, tmp), nfact)) % mod print(ans) ```
output
1
1,509
16
3,019
Provide a correct Python 3 solution for this coding contest problem. There are N blocks arranged in a row, numbered 1 to N from left to right. Each block has a weight, and the weight of Block i is A_i. Snuke will perform the following operation on these blocks N times: * Choose one block that is still not removed, and remove it. The cost of this operation is the sum of the weights of the blocks that are connected to the block being removed (including itself). Here, two blocks x and y ( x \leq y ) are connected when, for all z ( x \leq z \leq y ), Block z is still not removed. There are N! possible orders in which Snuke removes the blocks. For all of those N! orders, find the total cost of the N operations, and calculate the sum of those N! total costs. As the answer can be extremely large, compute the sum modulo 10^9+7. Constraints * 1 \leq N \leq 10^5 * 1 \leq A_i \leq 10^9 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output For all of the N! orders, find the total cost of the N operations, and print the sum of those N! total costs, modulo 10^9+7. Examples Input 2 1 2 Output 9 Input 4 1 1 1 1 Output 212 Input 10 1 2 4 8 16 32 64 128 256 512 Output 880971923
instruction
0
1,510
16
3,020
"Correct Solution: ``` N = int(input()) A = [int(a) for a in input().split()] P = 10**9+7 def inv(a): return pow(a, P-2, P) s = 0 for i in range(N): s += inv(i+1) ans = 0 for i in range(N): ans += s * A[i] ans %= P s += inv(i+2) - inv(N-i) for i in range(1, N+1): ans = ans * i % P print(ans) ```
output
1
1,510
16
3,021
Provide a correct Python 3 solution for this coding contest problem. There are N blocks arranged in a row, numbered 1 to N from left to right. Each block has a weight, and the weight of Block i is A_i. Snuke will perform the following operation on these blocks N times: * Choose one block that is still not removed, and remove it. The cost of this operation is the sum of the weights of the blocks that are connected to the block being removed (including itself). Here, two blocks x and y ( x \leq y ) are connected when, for all z ( x \leq z \leq y ), Block z is still not removed. There are N! possible orders in which Snuke removes the blocks. For all of those N! orders, find the total cost of the N operations, and calculate the sum of those N! total costs. As the answer can be extremely large, compute the sum modulo 10^9+7. Constraints * 1 \leq N \leq 10^5 * 1 \leq A_i \leq 10^9 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output For all of the N! orders, find the total cost of the N operations, and print the sum of those N! total costs, modulo 10^9+7. Examples Input 2 1 2 Output 9 Input 4 1 1 1 1 Output 212 Input 10 1 2 4 8 16 32 64 128 256 512 Output 880971923
instruction
0
1,511
16
3,022
"Correct Solution: ``` inv=lambda x:pow(x, m - 2, m) N = int(input()) A = [int(x) for x in input().split()] f = [1, 1] m = 10**9+7 for i in range(2, N + 1): f+=[f[-1] * i % m] s = [0] for i in range(1, N + 1): s+=[(s[-1]+f[N]*inv(i))%m] a = 0 for i in range(N): a+=(s[i+1]+s[N-i]-f[N])*A[i] a%=m print(a) ```
output
1
1,511
16
3,023
Provide a correct Python 3 solution for this coding contest problem. There are N blocks arranged in a row, numbered 1 to N from left to right. Each block has a weight, and the weight of Block i is A_i. Snuke will perform the following operation on these blocks N times: * Choose one block that is still not removed, and remove it. The cost of this operation is the sum of the weights of the blocks that are connected to the block being removed (including itself). Here, two blocks x and y ( x \leq y ) are connected when, for all z ( x \leq z \leq y ), Block z is still not removed. There are N! possible orders in which Snuke removes the blocks. For all of those N! orders, find the total cost of the N operations, and calculate the sum of those N! total costs. As the answer can be extremely large, compute the sum modulo 10^9+7. Constraints * 1 \leq N \leq 10^5 * 1 \leq A_i \leq 10^9 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output For all of the N! orders, find the total cost of the N operations, and print the sum of those N! total costs, modulo 10^9+7. Examples Input 2 1 2 Output 9 Input 4 1 1 1 1 Output 212 Input 10 1 2 4 8 16 32 64 128 256 512 Output 880971923
instruction
0
1,512
16
3,024
"Correct Solution: ``` mod=10**9+7 N=int(input()) a=[int(i) for i in input().split()] F=1 for i in range(1,N+1): F=(F*i)%mod def power(x,y): if y==0: return 1 elif y==1: return x%mod elif y%2==0: return power(x,y//2)**2%mod else: return (power(x,y//2)**2)*x%mod inv=[0]*(N) for i in range(N): inv[i]=power(i+1,mod-2) S_inv=[0]*(N+1) for i in range(N): S_inv[i+1]=S_inv[i]+inv[i] ans=0 for i in range(N): p=S_inv[i+1]+S_inv[N-i]-1 ans=(ans+a[i]*F*p)%mod print(ans) ```
output
1
1,512
16
3,025
Provide a correct Python 3 solution for this coding contest problem. There are N blocks arranged in a row, numbered 1 to N from left to right. Each block has a weight, and the weight of Block i is A_i. Snuke will perform the following operation on these blocks N times: * Choose one block that is still not removed, and remove it. The cost of this operation is the sum of the weights of the blocks that are connected to the block being removed (including itself). Here, two blocks x and y ( x \leq y ) are connected when, for all z ( x \leq z \leq y ), Block z is still not removed. There are N! possible orders in which Snuke removes the blocks. For all of those N! orders, find the total cost of the N operations, and calculate the sum of those N! total costs. As the answer can be extremely large, compute the sum modulo 10^9+7. Constraints * 1 \leq N \leq 10^5 * 1 \leq A_i \leq 10^9 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output For all of the N! orders, find the total cost of the N operations, and print the sum of those N! total costs, modulo 10^9+7. Examples Input 2 1 2 Output 9 Input 4 1 1 1 1 Output 212 Input 10 1 2 4 8 16 32 64 128 256 512 Output 880971923
instruction
0
1,513
16
3,026
"Correct Solution: ``` def prepare(n, MOD): f = 1 factorials = [1] for m in range(1, n + 1): f *= m f %= MOD factorials.append(f) inv = pow(f, MOD - 2, MOD) invs = [1] * (n + 1) invs[n] = inv for m in range(n, 1, -1): inv *= m inv %= MOD invs[m - 1] = inv return factorials, invs def solve(n, aaa): factorials, invs = prepare(n, MOD) fn = factorials[n] coefs = [fn * invs[i + 1] * factorials[i] % MOD for i in range(1, n)] acc = [0] for c in coefs: tmp = (acc[-1] + c) % MOD acc.append(tmp) ans = 0 for i, a in enumerate(aaa): ans += (acc[i] + acc[n - i - 1] + fn) * a ans %= MOD return ans MOD = 1000000007 n = int(input()) aaa = list(map(int, input().split())) print(solve(n, aaa)) ```
output
1
1,513
16
3,027
Provide a correct Python 3 solution for this coding contest problem. There are N blocks arranged in a row, numbered 1 to N from left to right. Each block has a weight, and the weight of Block i is A_i. Snuke will perform the following operation on these blocks N times: * Choose one block that is still not removed, and remove it. The cost of this operation is the sum of the weights of the blocks that are connected to the block being removed (including itself). Here, two blocks x and y ( x \leq y ) are connected when, for all z ( x \leq z \leq y ), Block z is still not removed. There are N! possible orders in which Snuke removes the blocks. For all of those N! orders, find the total cost of the N operations, and calculate the sum of those N! total costs. As the answer can be extremely large, compute the sum modulo 10^9+7. Constraints * 1 \leq N \leq 10^5 * 1 \leq A_i \leq 10^9 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output For all of the N! orders, find the total cost of the N operations, and print the sum of those N! total costs, modulo 10^9+7. Examples Input 2 1 2 Output 9 Input 4 1 1 1 1 Output 212 Input 10 1 2 4 8 16 32 64 128 256 512 Output 880971923
instruction
0
1,514
16
3,028
"Correct Solution: ``` n = int(input()) A = [int(i) for i in input().split()] p = 10 ** 9 + 7 def fact(n, p=10**9 + 7): f = 1 for i in range(1, n+1): f *= i f %= p return f def get_inv(n, p=10**9 + 7): inv = [0, 1] for i in range(2, n+1): inv.append(-(p//i * inv[p%i]) % p) return inv f = fact(n) inv = get_inv(n) csum = [0] for i in range(1, n+1): csum.append((csum[-1] + inv[i]) % p) ans = 0 for i, a in enumerate(A): ans += (csum[i+1] + csum[n-i] - csum[1] + p) % p * a ans %= p print(ans * f % p) ```
output
1
1,514
16
3,029
Provide a correct Python 3 solution for this coding contest problem. There are N blocks arranged in a row, numbered 1 to N from left to right. Each block has a weight, and the weight of Block i is A_i. Snuke will perform the following operation on these blocks N times: * Choose one block that is still not removed, and remove it. The cost of this operation is the sum of the weights of the blocks that are connected to the block being removed (including itself). Here, two blocks x and y ( x \leq y ) are connected when, for all z ( x \leq z \leq y ), Block z is still not removed. There are N! possible orders in which Snuke removes the blocks. For all of those N! orders, find the total cost of the N operations, and calculate the sum of those N! total costs. As the answer can be extremely large, compute the sum modulo 10^9+7. Constraints * 1 \leq N \leq 10^5 * 1 \leq A_i \leq 10^9 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output For all of the N! orders, find the total cost of the N operations, and print the sum of those N! total costs, modulo 10^9+7. Examples Input 2 1 2 Output 9 Input 4 1 1 1 1 Output 212 Input 10 1 2 4 8 16 32 64 128 256 512 Output 880971923
instruction
0
1,515
16
3,030
"Correct Solution: ``` # B N = int(input()) A_list = list(map(int, input().split())) LARGE = 10**9+7 def pinv(p, k): return pow(k, p-2, p) Npow = 1 for i in range(2, N+1): Npow = Npow*i % LARGE K = 0 for i in range(N): K += pinv(LARGE, i+1) res = (K*A_list[0]) % LARGE for i in range(1, N): K -= pinv(LARGE, N+1-i) K += pinv(LARGE, i+1) res = (res + K*A_list[i]) % LARGE print(res*Npow % LARGE) ```
output
1
1,515
16
3,031
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N blocks arranged in a row, numbered 1 to N from left to right. Each block has a weight, and the weight of Block i is A_i. Snuke will perform the following operation on these blocks N times: * Choose one block that is still not removed, and remove it. The cost of this operation is the sum of the weights of the blocks that are connected to the block being removed (including itself). Here, two blocks x and y ( x \leq y ) are connected when, for all z ( x \leq z \leq y ), Block z is still not removed. There are N! possible orders in which Snuke removes the blocks. For all of those N! orders, find the total cost of the N operations, and calculate the sum of those N! total costs. As the answer can be extremely large, compute the sum modulo 10^9+7. Constraints * 1 \leq N \leq 10^5 * 1 \leq A_i \leq 10^9 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output For all of the N! orders, find the total cost of the N operations, and print the sum of those N! total costs, modulo 10^9+7. Examples Input 2 1 2 Output 9 Input 4 1 1 1 1 Output 212 Input 10 1 2 4 8 16 32 64 128 256 512 Output 880971923 Submitted Solution: ``` N = int(input()) *A, = map(int, input().split()) MOD = 10**9 + 7 S = [0]*(N+1) r = 0 for i in range(1, N+1): S[i] = r = (r + pow(i, MOD-2, MOD)) % MOD ans = 0 for i in range(N): ans += A[i] * (S[i+1] + S[N-i] - 1) for i in range(1, N+1): ans = ans * i % MOD print(ans) ```
instruction
0
1,516
16
3,032
Yes
output
1
1,516
16
3,033
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N blocks arranged in a row, numbered 1 to N from left to right. Each block has a weight, and the weight of Block i is A_i. Snuke will perform the following operation on these blocks N times: * Choose one block that is still not removed, and remove it. The cost of this operation is the sum of the weights of the blocks that are connected to the block being removed (including itself). Here, two blocks x and y ( x \leq y ) are connected when, for all z ( x \leq z \leq y ), Block z is still not removed. There are N! possible orders in which Snuke removes the blocks. For all of those N! orders, find the total cost of the N operations, and calculate the sum of those N! total costs. As the answer can be extremely large, compute the sum modulo 10^9+7. Constraints * 1 \leq N \leq 10^5 * 1 \leq A_i \leq 10^9 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output For all of the N! orders, find the total cost of the N operations, and print the sum of those N! total costs, modulo 10^9+7. Examples Input 2 1 2 Output 9 Input 4 1 1 1 1 Output 212 Input 10 1 2 4 8 16 32 64 128 256 512 Output 880971923 Submitted Solution: ``` N = int(input()) A = list(map(int,input().split())) mod = 10**9+7 def inv(n): n %= mod return pow(n,mod-2,mod) H = [0]*(N+1) for n in range(1,N+1): H[n] = (inv(n)+H[n-1])%mod N_f = 1 for n in range(1,N+1): N_f = N_f*n%mod ans = 0 for n in range(1,N+1): ans += A[n-1]*(H[N-n+1]+H[n]-1) ans %= mod ans *= N_f ans %= mod print(ans) ```
instruction
0
1,517
16
3,034
Yes
output
1
1,517
16
3,035
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N blocks arranged in a row, numbered 1 to N from left to right. Each block has a weight, and the weight of Block i is A_i. Snuke will perform the following operation on these blocks N times: * Choose one block that is still not removed, and remove it. The cost of this operation is the sum of the weights of the blocks that are connected to the block being removed (including itself). Here, two blocks x and y ( x \leq y ) are connected when, for all z ( x \leq z \leq y ), Block z is still not removed. There are N! possible orders in which Snuke removes the blocks. For all of those N! orders, find the total cost of the N operations, and calculate the sum of those N! total costs. As the answer can be extremely large, compute the sum modulo 10^9+7. Constraints * 1 \leq N \leq 10^5 * 1 \leq A_i \leq 10^9 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output For all of the N! orders, find the total cost of the N operations, and print the sum of those N! total costs, modulo 10^9+7. Examples Input 2 1 2 Output 9 Input 4 1 1 1 1 Output 212 Input 10 1 2 4 8 16 32 64 128 256 512 Output 880971923 Submitted Solution: ``` def main(): n = int(input()) a = list(map(int, input().split())) mod, fact, m, npr, now = 10**9+7, [1, 1], [0, 1], [1]*(n+1), 1 for i in range(2, n+1): fact.append(fact[-1]*i % mod) for i in range(n, 0, -1): npr[i-1] = npr[i]*i % mod for i in range(2, n+1): m.append(fact[i]+now) now = (m[-1]+now*i) % mod m = [i*j % mod for i, j in zip(npr, m)] ans = (sum([j*(m[n-i]+m[i+1]) for i, j in enumerate(a)])-sum(a)*fact[n]) % mod print(ans) main() ```
instruction
0
1,518
16
3,036
Yes
output
1
1,518
16
3,037
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N blocks arranged in a row, numbered 1 to N from left to right. Each block has a weight, and the weight of Block i is A_i. Snuke will perform the following operation on these blocks N times: * Choose one block that is still not removed, and remove it. The cost of this operation is the sum of the weights of the blocks that are connected to the block being removed (including itself). Here, two blocks x and y ( x \leq y ) are connected when, for all z ( x \leq z \leq y ), Block z is still not removed. There are N! possible orders in which Snuke removes the blocks. For all of those N! orders, find the total cost of the N operations, and calculate the sum of those N! total costs. As the answer can be extremely large, compute the sum modulo 10^9+7. Constraints * 1 \leq N \leq 10^5 * 1 \leq A_i \leq 10^9 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output For all of the N! orders, find the total cost of the N operations, and print the sum of those N! total costs, modulo 10^9+7. Examples Input 2 1 2 Output 9 Input 4 1 1 1 1 Output 212 Input 10 1 2 4 8 16 32 64 128 256 512 Output 880971923 Submitted Solution: ``` # -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, sub sys.setrecursionlimit(10000) mod = 10**9 + 7 def read_int(): return int(input()) def read_int_n(): return list(map(int, input().split())) def read_float(): return float(input()) def read_float_n(): return list(map(float, input().split())) def read_str(): return input().strip() def read_str_n(): return list(map(str, input().split())) def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap def mul(a, b): return ((a % mod) * (b % mod)) % mod def power(x, y): if y == 0: return 1 elif y == 1: return x % mod elif y % 2 == 0: return power(x, y//2)**2 % mod else: return power(x, y//2)**2 * x % mod def div(a, b): return mul(a, power(b, mod-2)) @mt def slv(N, A): def perm(n): p = 1 for i in range(1, n+1): p *= i p %= mod return p pn = perm(N) sp = [0] for i in range(1, N+1): sp.append((sp[-1] + div(pn, i)) % mod) ans = mul(sp[-1], A[0]) for i in range(1, N): ans += mul(sp[i+1] - sp[1], A[i]) ans %= mod ans += mul(sp[N-i] - sp[0], A[i]) ans %= mod return ans def main(): N = read_int() A = read_int_n() print(slv(N, A)) if __name__ == '__main__': main() ```
instruction
0
1,519
16
3,038
Yes
output
1
1,519
16
3,039
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N blocks arranged in a row, numbered 1 to N from left to right. Each block has a weight, and the weight of Block i is A_i. Snuke will perform the following operation on these blocks N times: * Choose one block that is still not removed, and remove it. The cost of this operation is the sum of the weights of the blocks that are connected to the block being removed (including itself). Here, two blocks x and y ( x \leq y ) are connected when, for all z ( x \leq z \leq y ), Block z is still not removed. There are N! possible orders in which Snuke removes the blocks. For all of those N! orders, find the total cost of the N operations, and calculate the sum of those N! total costs. As the answer can be extremely large, compute the sum modulo 10^9+7. Constraints * 1 \leq N \leq 10^5 * 1 \leq A_i \leq 10^9 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output For all of the N! orders, find the total cost of the N operations, and print the sum of those N! total costs, modulo 10^9+7. Examples Input 2 1 2 Output 9 Input 4 1 1 1 1 Output 212 Input 10 1 2 4 8 16 32 64 128 256 512 Output 880971923 Submitted Solution: ``` import sys fin = sys.stdin.readline def factorial(n, mod): if n == 0: return 1 else: return n * factorial(n - 1, mod) % mod MOD = 10**9 + 7 N = int(fin()) A_list = [int(elem) for elem in fin().split()] fac_N = factorial(N, MOD) inv_nums = [fac_N * pow(i, MOD - 2, MOD) % MOD for i in range(1, N + 1)] cuml_inv_nums = [inv_nums[0]] for inv_num in inv_nums[1:]: cuml_inv_nums.append((cuml_inv_nums[-1] + inv_num) % MOD) ans = 0 for i, A in enumerate(A_list): ans += A * (cuml_inv_nums[i] + cuml_inv_nums[N - 1 - i] - cuml_inv_nums[0]) % MOD ans %= MOD print(ans) ```
instruction
0
1,520
16
3,040
No
output
1
1,520
16
3,041
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N blocks arranged in a row, numbered 1 to N from left to right. Each block has a weight, and the weight of Block i is A_i. Snuke will perform the following operation on these blocks N times: * Choose one block that is still not removed, and remove it. The cost of this operation is the sum of the weights of the blocks that are connected to the block being removed (including itself). Here, two blocks x and y ( x \leq y ) are connected when, for all z ( x \leq z \leq y ), Block z is still not removed. There are N! possible orders in which Snuke removes the blocks. For all of those N! orders, find the total cost of the N operations, and calculate the sum of those N! total costs. As the answer can be extremely large, compute the sum modulo 10^9+7. Constraints * 1 \leq N \leq 10^5 * 1 \leq A_i \leq 10^9 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output For all of the N! orders, find the total cost of the N operations, and print the sum of those N! total costs, modulo 10^9+7. Examples Input 2 1 2 Output 9 Input 4 1 1 1 1 Output 212 Input 10 1 2 4 8 16 32 64 128 256 512 Output 880971923 Submitted Solution: ``` import numpy as np n = int(input()) li = list(map(int, input().split())) def weight(li,ansli): if li == []: return a = sum(li) for j in range(len(li)): a = a*(j+1) ansli.append(a) for i in range(len(li)): weight(li[:i],ansli) weight(li[i+1:],ansli) return ansli print(sum(weight(li,[]))%(10**9+7)) ```
instruction
0
1,521
16
3,042
No
output
1
1,521
16
3,043
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N blocks arranged in a row, numbered 1 to N from left to right. Each block has a weight, and the weight of Block i is A_i. Snuke will perform the following operation on these blocks N times: * Choose one block that is still not removed, and remove it. The cost of this operation is the sum of the weights of the blocks that are connected to the block being removed (including itself). Here, two blocks x and y ( x \leq y ) are connected when, for all z ( x \leq z \leq y ), Block z is still not removed. There are N! possible orders in which Snuke removes the blocks. For all of those N! orders, find the total cost of the N operations, and calculate the sum of those N! total costs. As the answer can be extremely large, compute the sum modulo 10^9+7. Constraints * 1 \leq N \leq 10^5 * 1 \leq A_i \leq 10^9 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output For all of the N! orders, find the total cost of the N operations, and print the sum of those N! total costs, modulo 10^9+7. Examples Input 2 1 2 Output 9 Input 4 1 1 1 1 Output 212 Input 10 1 2 4 8 16 32 64 128 256 512 Output 880971923 Submitted Solution: ``` #! /usr/bin/env python # -*- coding: utf-8 -*- # vim:fenc=utf-8 # """ AGC028 B """ import itertools n = int(input()) ali = list(map(int, input().split())) cut = 10**9+7 def modInverse(a, b, divmod=divmod): r0, r1, s0, s1 = a, b, 1, 0 while r1 != 0: q, rtmp = divmod(r0, r1) stmp = s0-q*s1 r0, s0 = r1, s1 r1, s1 = rtmp, stmp return s0 % cut def factorial(n): nn = 1 for i in range(2, n+1): nn = nn*i return(nn) invlist = [modInverse(i, cut) for i in range(1, n+1)] accuminv = list(itertools.accumulate(invlist, func=lambda x, y: x+y % cut)) ans = 0 nfact = factorial(n) for i in range(n): sump = accuminv[i]+accuminv[n-1-i] - 1 ans += ali[i]*sump % cut ans = ans*nfact % cut print(ans) ```
instruction
0
1,522
16
3,044
No
output
1
1,522
16
3,045
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N blocks arranged in a row, numbered 1 to N from left to right. Each block has a weight, and the weight of Block i is A_i. Snuke will perform the following operation on these blocks N times: * Choose one block that is still not removed, and remove it. The cost of this operation is the sum of the weights of the blocks that are connected to the block being removed (including itself). Here, two blocks x and y ( x \leq y ) are connected when, for all z ( x \leq z \leq y ), Block z is still not removed. There are N! possible orders in which Snuke removes the blocks. For all of those N! orders, find the total cost of the N operations, and calculate the sum of those N! total costs. As the answer can be extremely large, compute the sum modulo 10^9+7. Constraints * 1 \leq N \leq 10^5 * 1 \leq A_i \leq 10^9 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output For all of the N! orders, find the total cost of the N operations, and print the sum of those N! total costs, modulo 10^9+7. Examples Input 2 1 2 Output 9 Input 4 1 1 1 1 Output 212 Input 10 1 2 4 8 16 32 64 128 256 512 Output 880971923 Submitted Solution: ``` N = int(input()) w = [int(i) for i in input().split())] def f(n): i = 1 for j in range(0,n): i = i*(j+1) return i def c(l): n = len(l) if n == 0 return 0 elif n == 1: return l[0] else: t = f(n)*sum(l) for i in range(0,n): a = l[0:i] b = l[i+1:n] t = t + (f(n-1)/f(i))*c(a) + (f(n-1)/f(n-i-1))*c(b) return int(t) print(c(w)) ```
instruction
0
1,523
16
3,046
No
output
1
1,523
16
3,047
Provide a correct Python 3 solution for this coding contest problem. There is an H \times W grid (H vertical, W horizontal), where each square contains a lowercase English letter. Specifically, the letter in the square at the i-th row and j-th column is equal to the j-th character in the string S_i. Snuke can apply the following operation to this grid any number of times: * Choose two different rows and swap them. Or, choose two different columns and swap them. Snuke wants this grid to be symmetric. That is, for any 1 \leq i \leq H and 1 \leq j \leq W, the letter in the square at the i-th row and j-th column and the letter in the square at the (H + 1 - i)-th row and (W + 1 - j)-th column should be equal. Determine if Snuke can achieve this objective. Constraints * 1 \leq H \leq 12 * 1 \leq W \leq 12 * |S_i| = W * S_i consists of lowercase English letters. Input Input is given from Standard Input in the following format: H W S_1 S_2 : S_H Output If Snuke can make the grid symmetric, print `YES`; if he cannot, print `NO`. Examples Input 2 3 arc rac Output YES Input 3 7 atcoder regular contest Output NO Input 12 12 bimonigaloaf faurwlkbleht dexwimqxzxbb lxdgyoifcxid ydxiliocfdgx nfoabgilamoi ibxbdqmzxxwe pqirylfrcrnf wtehfkllbura yfrnpflcrirq wvcclwgiubrk lkbrwgwuiccv Output YES
instruction
0
1,524
16
3,048
"Correct Solution: ``` H, W = map(int, input().split()) Ss = [input() for _ in range(H)] # 行の入れ替えパターンを生成する(中央付近から埋めていく) def dfs(iR): # 全て埋まったら、判定に移る if iR < 0: return check() # 未使用の行を検索する iF = flgs.index(False) Rs[iR] = iF - offset flgs[iF] = True # ペアの相手を決めて、次のペア生成に移る ans = False for iF2, flg in enumerate(flgs): if not flg: Rs[H - 1 - iR] = iF2 - offset flgs[iF2] = True ans = ans or dfs(iR - 1) flgs[iF2] = False flgs[iF] = False return ans # 与えられた行の入れ替えパターンに対して、列の入れ替えのみで点対称にできるかを判定する def check(): Ts = [Ss[R] for R in Rs] Ts = list(map(list, zip(*Ts))) # (W+1)/2列目を使用可能かどうか if W % 2: flgCenter = True else: flgCenter = False # 各列に対して、処理を行う Used = [False] * W for j, T in enumerate(Ts): if Used[j]: continue for j2, T2 in enumerate(Ts[j + 1:], j + 1): # 上下反転したような未使用の列が存在するならば、次の列へ if not Used[j2] and T[::-1] == T2: Used[j2] = True break else: # 自身が上下対称、かつ、(W+1)/2列目を使用可能ならば、次の列へ if T[::-1] == T and flgCenter == True: flgCenter = False else: # この入れ替えパターンでは不可能と判定 return False return True if H % 2: # Hが奇数ならば、先頭にダミーを付加 flgs = [False] * (H + 1) offset = 1 else: flgs = [False] * H offset = 0 Rs = [-1] * H if dfs((H - 1) // 2): print('YES') else: print('NO') ```
output
1
1,524
16
3,049
Provide a correct Python 3 solution for this coding contest problem. There is an H \times W grid (H vertical, W horizontal), where each square contains a lowercase English letter. Specifically, the letter in the square at the i-th row and j-th column is equal to the j-th character in the string S_i. Snuke can apply the following operation to this grid any number of times: * Choose two different rows and swap them. Or, choose two different columns and swap them. Snuke wants this grid to be symmetric. That is, for any 1 \leq i \leq H and 1 \leq j \leq W, the letter in the square at the i-th row and j-th column and the letter in the square at the (H + 1 - i)-th row and (W + 1 - j)-th column should be equal. Determine if Snuke can achieve this objective. Constraints * 1 \leq H \leq 12 * 1 \leq W \leq 12 * |S_i| = W * S_i consists of lowercase English letters. Input Input is given from Standard Input in the following format: H W S_1 S_2 : S_H Output If Snuke can make the grid symmetric, print `YES`; if he cannot, print `NO`. Examples Input 2 3 arc rac Output YES Input 3 7 atcoder regular contest Output NO Input 12 12 bimonigaloaf faurwlkbleht dexwimqxzxbb lxdgyoifcxid ydxiliocfdgx nfoabgilamoi ibxbdqmzxxwe pqirylfrcrnf wtehfkllbura yfrnpflcrirq wvcclwgiubrk lkbrwgwuiccv Output YES
instruction
0
1,525
16
3,050
"Correct Solution: ``` def check(field): tr = list(map(''.join, zip(*field))) paired = set() center = -1 for i, col1 in enumerate(tr): if i in paired: continue for j, col2 in enumerate(tr[i + 1:], start=i + 1): if j in paired: continue if col1 == col2[::-1]: paired.add(i) paired.add(j) break else: if center == -1 and col1 == col1[::-1]: center = i else: return False return True def arrange_row(field, new_field, i, remain): if len(remain) == 0: return check(new_field) j = remain.pop() new_field[i] = field[j] for k in list(remain): remain.remove(k) new_field[h - i - 1] = field[k] result = arrange_row(field, new_field, i + 1, remain) if result: return True remain.add(k) remain.add(j) return False def solve(h, w, field): new_field = [None] * h remaining_row = set(range(h)) if h % 2 == 0: return arrange_row(field, new_field, 0, remaining_row) for i in list(remaining_row): remaining_row.remove(i) new_field[h // 2] = field[i] result = arrange_row(field, new_field, 0, remaining_row) if result: return True remaining_row.add(i) return False h, w = map(int, input().split()) field = [input() for _ in range(h)] print('YES' if solve(h, w, field) else 'NO') ```
output
1
1,525
16
3,051
Provide a correct Python 3 solution for this coding contest problem. There is an H \times W grid (H vertical, W horizontal), where each square contains a lowercase English letter. Specifically, the letter in the square at the i-th row and j-th column is equal to the j-th character in the string S_i. Snuke can apply the following operation to this grid any number of times: * Choose two different rows and swap them. Or, choose two different columns and swap them. Snuke wants this grid to be symmetric. That is, for any 1 \leq i \leq H and 1 \leq j \leq W, the letter in the square at the i-th row and j-th column and the letter in the square at the (H + 1 - i)-th row and (W + 1 - j)-th column should be equal. Determine if Snuke can achieve this objective. Constraints * 1 \leq H \leq 12 * 1 \leq W \leq 12 * |S_i| = W * S_i consists of lowercase English letters. Input Input is given from Standard Input in the following format: H W S_1 S_2 : S_H Output If Snuke can make the grid symmetric, print `YES`; if he cannot, print `NO`. Examples Input 2 3 arc rac Output YES Input 3 7 atcoder regular contest Output NO Input 12 12 bimonigaloaf faurwlkbleht dexwimqxzxbb lxdgyoifcxid ydxiliocfdgx nfoabgilamoi ibxbdqmzxxwe pqirylfrcrnf wtehfkllbura yfrnpflcrirq wvcclwgiubrk lkbrwgwuiccv Output YES
instruction
0
1,526
16
3,052
"Correct Solution: ``` import os import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(10 ** 9) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 # MOD = 998244353 H, W = list(map(int, sys.stdin.buffer.readline().split())) S = [sys.stdin.buffer.readline().decode().rstrip() for _ in range(H)] # ペアのとり方は 10395 通り # a = math.factorial(12) / (2 ** 6) / math.factorial(6) # print(a) # 10395 def test(groups): seen = [False] * 6 order = [-1] * len(groups) for i, g in enumerate(groups): if g == -1: # 真ん中 order[W // 2] = i continue if not seen[g]: order[g] = i seen[g] = True else: order[~g] = i # print(groups, order) # return False rows = [] for s in S: row = '' for i in order: row += s[i] rows.append(row) ok = [False] * H for i in range(H): if ok[i]: continue rev = rows[i][::-1] for j in range(i + 1, H): if not ok[j] and rows[j] == rev: ok[i] = ok[j] = True break ng_cnt = ok.count(False) if ng_cnt == 0: return True if ng_cnt == 1: i = ok.index(False) return rows[i] == rows[i][::-1] return False def solve(groups, depth=0): if depth == W // 2: return test(groups) i = 0 for _ in range(2 if W % 2 == 1 else 1): while groups[i] != -1: i += 1 groups[i] = depth for j in range(i + 1, W): if groups[j] != -1: continue groups[j] = depth if solve(groups, depth + 1): return True groups[j] = -1 groups[i] = -1 i += 1 return False groups = [-1] * W ok = solve(groups) if ok: print('YES') else: print('NO') ```
output
1
1,526
16
3,053
Provide a correct Python 3 solution for this coding contest problem. There is an H \times W grid (H vertical, W horizontal), where each square contains a lowercase English letter. Specifically, the letter in the square at the i-th row and j-th column is equal to the j-th character in the string S_i. Snuke can apply the following operation to this grid any number of times: * Choose two different rows and swap them. Or, choose two different columns and swap them. Snuke wants this grid to be symmetric. That is, for any 1 \leq i \leq H and 1 \leq j \leq W, the letter in the square at the i-th row and j-th column and the letter in the square at the (H + 1 - i)-th row and (W + 1 - j)-th column should be equal. Determine if Snuke can achieve this objective. Constraints * 1 \leq H \leq 12 * 1 \leq W \leq 12 * |S_i| = W * S_i consists of lowercase English letters. Input Input is given from Standard Input in the following format: H W S_1 S_2 : S_H Output If Snuke can make the grid symmetric, print `YES`; if he cannot, print `NO`. Examples Input 2 3 arc rac Output YES Input 3 7 atcoder regular contest Output NO Input 12 12 bimonigaloaf faurwlkbleht dexwimqxzxbb lxdgyoifcxid ydxiliocfdgx nfoabgilamoi ibxbdqmzxxwe pqirylfrcrnf wtehfkllbura yfrnpflcrirq wvcclwgiubrk lkbrwgwuiccv Output YES
instruction
0
1,527
16
3,054
"Correct Solution: ``` H,W=map(int,input().split()) G=[list(input()) for i in range(H)] G_t=[list(x) for x in list(zip(*G))] def Check(G,H,W): Paired_y=[False]*H for y1 in range(H): if Paired_y[y1]: continue for y2 in range(H): if y1==y2 or Paired_y[y2]: continue Paired_x=[False]*W for x1 in range(W): if Paired_x[x1]: continue for x2 in range(W): if x1==x2 or Paired_x[x2]: continue if G[y1][x1]==G[y2][x2] and G[y1][x2]==G[y2][x1]: Paired_x[x1]=True Paired_x[x2]=True break if W%2==1: if Paired_x.count(False)==1: r=Paired_x.index(False) if G[y1][r]==G[y2][r]: Paired_y[y1]=True Paired_y[y2]=True break else: if Paired_x.count(False)==0: Paired_y[y1]=True Paired_y[y2]=True break if H%2==1: if Paired_y.count(False)==1: return True else: return False else: if Paired_y.count(False)==0: return True else: return False if Check(G,H,W) and Check(G_t,W,H): print("YES") else: print("NO") ```
output
1
1,527
16
3,055
Provide a correct Python 3 solution for this coding contest problem. There is an H \times W grid (H vertical, W horizontal), where each square contains a lowercase English letter. Specifically, the letter in the square at the i-th row and j-th column is equal to the j-th character in the string S_i. Snuke can apply the following operation to this grid any number of times: * Choose two different rows and swap them. Or, choose two different columns and swap them. Snuke wants this grid to be symmetric. That is, for any 1 \leq i \leq H and 1 \leq j \leq W, the letter in the square at the i-th row and j-th column and the letter in the square at the (H + 1 - i)-th row and (W + 1 - j)-th column should be equal. Determine if Snuke can achieve this objective. Constraints * 1 \leq H \leq 12 * 1 \leq W \leq 12 * |S_i| = W * S_i consists of lowercase English letters. Input Input is given from Standard Input in the following format: H W S_1 S_2 : S_H Output If Snuke can make the grid symmetric, print `YES`; if he cannot, print `NO`. Examples Input 2 3 arc rac Output YES Input 3 7 atcoder regular contest Output NO Input 12 12 bimonigaloaf faurwlkbleht dexwimqxzxbb lxdgyoifcxid ydxiliocfdgx nfoabgilamoi ibxbdqmzxxwe pqirylfrcrnf wtehfkllbura yfrnpflcrirq wvcclwgiubrk lkbrwgwuiccv Output YES
instruction
0
1,528
16
3,056
"Correct Solution: ``` H, W = map(int, input().split()) S = [input() for i in range(H)] def check(l): u = [0]*W mid = W % 2 for i in range(W): if u[i]: continue for j in range(i+1, W): for p, q in l: sp = S[p]; sq = S[q] if sp[i] != sq[j] or sp[j] != sq[i]: break else: u[j] = 1 break else: if mid: for p, q in l: sp = S[p]; sq = S[q] if sp[i] != sq[i]: break else: mid = 0 continue break else: return 1 return 0 def make(c, l, u, p): while c in u: c += 1 if c == H: if check(l): print("YES") exit(0) return if p: l.append((c, c)) make(c+1, l, u, 0) l.pop() for i in range(c+1, H): if i in u: continue u.add(i) l.append((c, i)) make(c+1, l, u, p) l.pop() u.remove(i) make(0, [], set(), H%2) print("NO") ```
output
1
1,528
16
3,057
Provide a correct Python 3 solution for this coding contest problem. There is an H \times W grid (H vertical, W horizontal), where each square contains a lowercase English letter. Specifically, the letter in the square at the i-th row and j-th column is equal to the j-th character in the string S_i. Snuke can apply the following operation to this grid any number of times: * Choose two different rows and swap them. Or, choose two different columns and swap them. Snuke wants this grid to be symmetric. That is, for any 1 \leq i \leq H and 1 \leq j \leq W, the letter in the square at the i-th row and j-th column and the letter in the square at the (H + 1 - i)-th row and (W + 1 - j)-th column should be equal. Determine if Snuke can achieve this objective. Constraints * 1 \leq H \leq 12 * 1 \leq W \leq 12 * |S_i| = W * S_i consists of lowercase English letters. Input Input is given from Standard Input in the following format: H W S_1 S_2 : S_H Output If Snuke can make the grid symmetric, print `YES`; if he cannot, print `NO`. Examples Input 2 3 arc rac Output YES Input 3 7 atcoder regular contest Output NO Input 12 12 bimonigaloaf faurwlkbleht dexwimqxzxbb lxdgyoifcxid ydxiliocfdgx nfoabgilamoi ibxbdqmzxxwe pqirylfrcrnf wtehfkllbura yfrnpflcrirq wvcclwgiubrk lkbrwgwuiccv Output YES
instruction
0
1,529
16
3,058
"Correct Solution: ``` import sys import copy sys.setrecursionlimit(10 ** 6) def main(): def per(s, a=[]): if not s: return [a] if len(s) % 2: cs = copy.deepcopy(s) res = [] for u in cs: s.remove(u) res += per(s, [u] + a) s.add(u) return res u = min(s) s.remove(u) cs = copy.deepcopy(s) res = [] for uu in cs: if uu < u: continue s.remove(uu) res += per(s, a + [u, uu]) s.add(uu) s.add(u) return res ord_a = ord("a") h, w = map(int, input().split()) t0 = [[ord(c) - ord_a for c in input()] for _ in range(h)] h_set = set(range(h)) pattern = per(h_set) # print(t0) # print(pattern) b = h % 2 for p in pattern: t1 = [[] for _ in range(h)] if b: t1[h // 2] = t0[p[0]] i = 0 for ii in range(b, h, 2): t1[i] = t0[p[ii]] t1[h - 1 - i] = t0[p[ii + 1]] i += 1 # print(p) # print(t1) fin = [False] * w mid = (w % 2 == 1) br = False for j, c0 in enumerate(zip(*t1)): if fin[j]: continue fin[j] = True c0 = c0[::-1] for jj, c1 in enumerate(zip(*t1)): if jj <= j: continue if fin[jj]: continue if c0 == c1: fin[jj] = True break else: if mid and c0 == c0[::-1]: mid = False else: br = True break if br: continue print("YES") exit() print("NO") main() ```
output
1
1,529
16
3,059
Provide a correct Python 3 solution for this coding contest problem. There is an H \times W grid (H vertical, W horizontal), where each square contains a lowercase English letter. Specifically, the letter in the square at the i-th row and j-th column is equal to the j-th character in the string S_i. Snuke can apply the following operation to this grid any number of times: * Choose two different rows and swap them. Or, choose two different columns and swap them. Snuke wants this grid to be symmetric. That is, for any 1 \leq i \leq H and 1 \leq j \leq W, the letter in the square at the i-th row and j-th column and the letter in the square at the (H + 1 - i)-th row and (W + 1 - j)-th column should be equal. Determine if Snuke can achieve this objective. Constraints * 1 \leq H \leq 12 * 1 \leq W \leq 12 * |S_i| = W * S_i consists of lowercase English letters. Input Input is given from Standard Input in the following format: H W S_1 S_2 : S_H Output If Snuke can make the grid symmetric, print `YES`; if he cannot, print `NO`. Examples Input 2 3 arc rac Output YES Input 3 7 atcoder regular contest Output NO Input 12 12 bimonigaloaf faurwlkbleht dexwimqxzxbb lxdgyoifcxid ydxiliocfdgx nfoabgilamoi ibxbdqmzxxwe pqirylfrcrnf wtehfkllbura yfrnpflcrirq wvcclwgiubrk lkbrwgwuiccv Output YES
instruction
0
1,530
16
3,060
"Correct Solution: ``` # この解法は嘘を含む from itertools import groupby H, W = map(int, input().split()) S_ = ["" for _ in range(W)] T_ = [] for _ in range(H): s = input() T_.append(s) for i, c in enumerate(s): S_[i] += c T = [sorted(t) for t in T_] S = [sorted(s) for s in S_] cnt = 0 for _, g in groupby(sorted(T)): if len(list(g))%2: cnt += 1 if H%2 < cnt: print("NO") exit() cnt = 0 for _, g in groupby(sorted(S)): if len(list(g))%2: cnt += 1 if W%2 < cnt: print("NO") exit() if W%2 or H%2: print("YES") exit() T1 = [] T2 = [] for i, (_, t) in enumerate(sorted(zip(T, T_))): if i%2: T1.append(t) else: T2.append(t) T_p = T1 + T2[::-1] S_pp = ["" for _ in range(W)] for t in T_p: for i, c in enumerate(t): S_pp[i] += c S1 = [] S2 = [] for i, (_, s) in enumerate(sorted(zip(S, S_pp))): if i%2: S1.append(s) else: S2.append(s) S_p = S1 + S2[::-1] for s1, s2 in zip(S_p, S_p[::-1]): for c1, c2 in zip(s1, s2[::-1]): if c1!=c2: print("NO") exit() print("YES") ```
output
1
1,530
16
3,061
Provide a correct Python 3 solution for this coding contest problem. There is an H \times W grid (H vertical, W horizontal), where each square contains a lowercase English letter. Specifically, the letter in the square at the i-th row and j-th column is equal to the j-th character in the string S_i. Snuke can apply the following operation to this grid any number of times: * Choose two different rows and swap them. Or, choose two different columns and swap them. Snuke wants this grid to be symmetric. That is, for any 1 \leq i \leq H and 1 \leq j \leq W, the letter in the square at the i-th row and j-th column and the letter in the square at the (H + 1 - i)-th row and (W + 1 - j)-th column should be equal. Determine if Snuke can achieve this objective. Constraints * 1 \leq H \leq 12 * 1 \leq W \leq 12 * |S_i| = W * S_i consists of lowercase English letters. Input Input is given from Standard Input in the following format: H W S_1 S_2 : S_H Output If Snuke can make the grid symmetric, print `YES`; if he cannot, print `NO`. Examples Input 2 3 arc rac Output YES Input 3 7 atcoder regular contest Output NO Input 12 12 bimonigaloaf faurwlkbleht dexwimqxzxbb lxdgyoifcxid ydxiliocfdgx nfoabgilamoi ibxbdqmzxxwe pqirylfrcrnf wtehfkllbura yfrnpflcrirq wvcclwgiubrk lkbrwgwuiccv Output YES
instruction
0
1,531
16
3,062
"Correct Solution: ``` from collections import Counter n,m = map(int,input().split()) grid = [list(input()) for i in range(n)] def jc(a,b): l = len(a) used = [0]*l for i in range(l): if used[i]: continue for j in range(i+1,l): if used[j]: continue if a[i] == b[j] and b[i] == a[j]: used[i] = 1 used[j] = 1 break if used.count(0) <= l%2: return True else: return False def judge(a): h = len(a) w = len(a[0]) used = [0]*h for i in range(h): if used[i]: continue ci = Counter(a[i]) for j in range(i+1,h): if used[j]: continue cj = Counter(a[j]) if ci == cj: if jc(a[i],a[j]): used[i] = 1 used[j] = 1 break if used.count(0) <= h%2: return True else: return False gt = list(zip(*grid)) if judge(grid) & judge(gt): print("YES") else: print("NO") ```
output
1
1,531
16
3,063
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is an H \times W grid (H vertical, W horizontal), where each square contains a lowercase English letter. Specifically, the letter in the square at the i-th row and j-th column is equal to the j-th character in the string S_i. Snuke can apply the following operation to this grid any number of times: * Choose two different rows and swap them. Or, choose two different columns and swap them. Snuke wants this grid to be symmetric. That is, for any 1 \leq i \leq H and 1 \leq j \leq W, the letter in the square at the i-th row and j-th column and the letter in the square at the (H + 1 - i)-th row and (W + 1 - j)-th column should be equal. Determine if Snuke can achieve this objective. Constraints * 1 \leq H \leq 12 * 1 \leq W \leq 12 * |S_i| = W * S_i consists of lowercase English letters. Input Input is given from Standard Input in the following format: H W S_1 S_2 : S_H Output If Snuke can make the grid symmetric, print `YES`; if he cannot, print `NO`. Examples Input 2 3 arc rac Output YES Input 3 7 atcoder regular contest Output NO Input 12 12 bimonigaloaf faurwlkbleht dexwimqxzxbb lxdgyoifcxid ydxiliocfdgx nfoabgilamoi ibxbdqmzxxwe pqirylfrcrnf wtehfkllbura yfrnpflcrirq wvcclwgiubrk lkbrwgwuiccv Output YES Submitted Solution: ``` import sys from itertools import permutations from random import randrange readline = sys.stdin.readline mod = 10**9+9 base = 2009 def rollinhash(S): N = len(S) has = 0 for i in range(N): s = S[i] has = (has*base + s)%mod return has phr = [] while len(set(phr)) != 26: phr = [randrange(1, 10**9) for _ in range(26)] def shash(S): N = len(S) has = 0 for i in range(N): has = has + phr[S[i]]*phr[S[N-1-i]] return has H, W = map(int, readline().split()) G = [list(map(ord, readline().strip())) for _ in range(H)] ans = 'NO' fh = H//2 ch = H-fh lir = list(range(H)) seen = set() for k in permutations(lir, ch): k = list(k) sk = set(k) for i in range(H): if i not in sk: k.append(i) sh = shash(k) if sh in seen: continue seen.add(sh) G2 = [] for j in k: G2.append(G[j]) G2 = list(map(list, zip(*G2))) G2h = [rollinhash(g) for g in G2] G2hi = [rollinhash(g[::-1]) for g in G2] used = [False]*W w1 = 0 match = W//2 while match and w1 < W: if used[w1]: w1 += 1 continue sa = G2hi[w1] for w2 in range(w1+1, W): if used[w2]: continue if G2h[w2] == sa: used[w1] = True used[w2] = True match -= 1 break w1 += 1 if sum(used) >= W-1: if sum(used) == W-1: mid = used.index(False) if G2h[mid] == G2hi[mid]: ans = 'YES' else: ans = 'YES' if ans == 'YES': break print(ans) ```
instruction
0
1,532
16
3,064
Yes
output
1
1,532
16
3,065
End of preview. Expand in Data Studio

Dataset Card for "python3-standardized_cluster_16_std"

More Information needed

Downloads last month
1