message
stringlengths
2
28.7k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
21
109k
cluster
float64
7
7
__index_level_0__
int64
42
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a garland consisting of n lamps. States of the lamps are represented by the string s of length n. The i-th character of the string s_i equals '0' if the i-th lamp is turned off or '1' if the i-th lamp is turned on. You are also given a positive integer k. In one move, you can choose one lamp and change its state (i.e. turn it on if it is turned off and vice versa). The garland is called k-periodic if the distance between each pair of adjacent turned on lamps is exactly k. Consider the case k=3. Then garlands "00010010", "1001001", "00010" and "0" are good but garlands "00101001", "1000001" and "01001100" are not. Note that the garland is not cyclic, i.e. the first turned on lamp is not going after the last turned on lamp and vice versa. Your task is to find the minimum number of moves you need to make to obtain k-periodic garland from the given one. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 25~ 000) — the number of test cases. Then t test cases follow. The first line of the test case contains two integers n and k (1 ≤ n ≤ 10^6; 1 ≤ k ≤ n) — the length of s and the required period. The second line of the test case contains the string s consisting of n characters '0' and '1'. It is guaranteed that the sum of n over all test cases does not exceed 10^6 (∑ n ≤ 10^6). Output For each test case, print the answer — the minimum number of moves you need to make to obtain k-periodic garland from the given one. Example Input 6 9 2 010001010 9 3 111100000 7 4 1111111 10 3 1001110101 1 1 1 1 1 0 Output 1 2 5 4 0 0 Submitted Solution: ``` # ---------------------------iye ha aam zindegi--------------------------------------------- import math import heapq, bisect import sys from collections import deque, defaultdict from fractions import Fraction import sys mod = 10 ** 9 + 7 mod1 = 998244353 # ------------------------------warmup---------------------------- import os import sys from io import BytesIO, IOBase 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.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # -------------------game starts now----------------------------------------------------import math class TreeNode: def __init__(self, k, v): self.key = k self.value = v self.left = None self.right = None self.parent = None self.height = 1 self.num_left = 1 self.num_total = 1 class AvlTree: def __init__(self): self._tree = None def add(self, k, v): if not self._tree: self._tree = TreeNode(k, v) return node = self._add(k, v) if node: self._rebalance(node) def _add(self, k, v): node = self._tree while node: if k < node.key: if node.left: node = node.left else: node.left = TreeNode(k, v) node.left.parent = node return node.left elif node.key < k: if node.right: node = node.right else: node.right = TreeNode(k, v) node.right.parent = node return node.right else: node.value = v return @staticmethod def get_height(x): return x.height if x else 0 @staticmethod def get_num_total(x): return x.num_total if x else 0 def _rebalance(self, node): n = node while n: lh = self.get_height(n.left) rh = self.get_height(n.right) n.height = max(lh, rh) + 1 balance_factor = lh - rh n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right) n.num_left = 1 + self.get_num_total(n.left) if balance_factor > 1: if self.get_height(n.left.left) < self.get_height(n.left.right): self._rotate_left(n.left) self._rotate_right(n) elif balance_factor < -1: if self.get_height(n.right.right) < self.get_height(n.right.left): self._rotate_right(n.right) self._rotate_left(n) else: n = n.parent def _remove_one(self, node): """ Side effect!!! Changes node. Node should have exactly one child """ replacement = node.left or node.right if node.parent: if AvlTree._is_left(node): node.parent.left = replacement else: node.parent.right = replacement replacement.parent = node.parent node.parent = None else: self._tree = replacement replacement.parent = None node.left = None node.right = None node.parent = None self._rebalance(replacement) def _remove_leaf(self, node): if node.parent: if AvlTree._is_left(node): node.parent.left = None else: node.parent.right = None self._rebalance(node.parent) else: self._tree = None node.parent = None node.left = None node.right = None def remove(self, k): node = self._get_node(k) if not node: return if AvlTree._is_leaf(node): self._remove_leaf(node) return if node.left and node.right: nxt = AvlTree._get_next(node) node.key = nxt.key node.value = nxt.value if self._is_leaf(nxt): self._remove_leaf(nxt) else: self._remove_one(nxt) self._rebalance(node) else: self._remove_one(node) def get(self, k): node = self._get_node(k) return node.value if node else -1 def _get_node(self, k): if not self._tree: return None node = self._tree while node: if k < node.key: node = node.left elif node.key < k: node = node.right else: return node return None def get_at(self, pos): x = pos + 1 node = self._tree while node: if x < node.num_left: node = node.left elif node.num_left < x: x -= node.num_left node = node.right else: return (node.key, node.value) raise IndexError("Out of ranges") @staticmethod def _is_left(node): return node.parent.left and node.parent.left == node @staticmethod def _is_leaf(node): return node.left is None and node.right is None def _rotate_right(self, node): if not node.parent: self._tree = node.left node.left.parent = None elif AvlTree._is_left(node): node.parent.left = node.left node.left.parent = node.parent else: node.parent.right = node.left node.left.parent = node.parent bk = node.left.right node.left.right = node node.parent = node.left node.left = bk if bk: bk.parent = node node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1 node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right) node.num_left = 1 + self.get_num_total(node.left) def _rotate_left(self, node): if not node.parent: self._tree = node.right node.right.parent = None elif AvlTree._is_left(node): node.parent.left = node.right node.right.parent = node.parent else: node.parent.right = node.right node.right.parent = node.parent bk = node.right.left node.right.left = node node.parent = node.right node.right = bk if bk: bk.parent = node node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1 node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right) node.num_left = 1 + self.get_num_total(node.left) @staticmethod def _get_next(node): if not node.right: return node.parent n = node.right while n.left: n = n.left return n # -----------------------------------------------binary seacrh tree--------------------------------------- class SegmentTree1: def __init__(self, data, default=0, func=lambda a, b: max(a, b)): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) # -------------------game starts now----------------------------------------------------import math class SegmentTree: def __init__(self, data, default=0, func=lambda a, b: a + b): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) # -------------------------------iye ha chutiya zindegi------------------------------------- class Factorial: def __init__(self, MOD): self.MOD = MOD self.factorials = [1, 1] self.invModulos = [0, 1] self.invFactorial_ = [1, 1] def calc(self, n): if n <= -1: print("Invalid argument to calculate n!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.factorials): return self.factorials[n] nextArr = [0] * (n + 1 - len(self.factorials)) initialI = len(self.factorials) prev = self.factorials[-1] m = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = prev * i % m self.factorials += nextArr return self.factorials[n] def inv(self, n): if n <= -1: print("Invalid argument to calculate n^(-1)") print("n must be non-negative value. But the argument was " + str(n)) exit() p = self.MOD pi = n % p if pi < len(self.invModulos): return self.invModulos[pi] nextArr = [0] * (n + 1 - len(self.invModulos)) initialI = len(self.invModulos) for i in range(initialI, min(p, n + 1)): next = -self.invModulos[p % i] * (p // i) % p self.invModulos.append(next) return self.invModulos[pi] def invFactorial(self, n): if n <= -1: print("Invalid argument to calculate (n^(-1))!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.invFactorial_): return self.invFactorial_[n] self.inv(n) # To make sure already calculated n^-1 nextArr = [0] * (n + 1 - len(self.invFactorial_)) initialI = len(self.invFactorial_) prev = self.invFactorial_[-1] p = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p self.invFactorial_ += nextArr return self.invFactorial_[n] class Combination: def __init__(self, MOD): self.MOD = MOD self.factorial = Factorial(MOD) def ncr(self, n, k): if k < 0 or n < k: return 0 k = min(k, n - k) f = self.factorial return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD # --------------------------------------iye ha combinations ka zindegi--------------------------------- def powm(a, n, m): if a == 1 or n == 0: return 1 if n % 2 == 0: s = powm(a, n // 2, m) return s * s % m else: return a * powm(a, n - 1, m) % m # --------------------------------------iye ha power ka zindegi--------------------------------- def sort_list(list1, list2): zipped_pairs = zip(list2, list1) z = [x for _, x in sorted(zipped_pairs)] return z # --------------------------------------------------product---------------------------------------- def product(l): por = 1 for i in range(len(l)): por *= l[i] return por # --------------------------------------------------binary---------------------------------------- def binarySearchCount(arr, n, key): left = 0 right = n - 1 count = 0 while (left <= right): mid = int((right + left) / 2) # Check if middle element is # less than or equal to key if (arr[mid] < key): count = mid + 1 left = mid + 1 # If key is smaller, ignore right half else: right = mid - 1 return count # --------------------------------------------------binary---------------------------------------- def countdig(n): c = 0 while (n > 0): n //= 10 c += 1 return c def binary(x, length): y = bin(x)[2:] return y if len(y) >= length else "0" * (length - len(y)) + y def countGreater(arr, n, k): l = 0 r = n - 1 # Stores the index of the left most element # from the array which is greater than k leftGreater = n # Finds number of elements greater than k while (l <= r): m = int(l + (r - l) / 2) if (arr[m] >= k): leftGreater = m r = m - 1 # If mid element is less than # or equal to k update l else: l = m + 1 # Return the count of elements # greater than k return (n - leftGreater) # --------------------------------------------------binary------------------------------------ for ik in range(int(input())): n,k=map(int,input().split()) s=list(input()) s=[int(s[i]) for i in range(n)] s1=[0]*(n+1) for i in range(1,n+1): s1[i]=s1[i-1]+s[i-1] dp=[[0 for i in range(3)]for j in range(n)] for i in range(k): dp[i][1]=(1-s[i])+s1[i]-s1[0] dp[i][0]=s[i]+s1[i]-s1[0] dp[i][2]=dp[i-1][2]+s[i] for i in range(k,n): dp[i][1]=min(dp[i-k][1],dp[i-k][2])+s1[i]-s1[i-k+1]+(1-s[i]) dp[i][0]=min(dp[i-k][0],dp[i-k][1])+s1[i]-s1[i-k+1]+s[i] dp[i][2] = dp[i - 1][2]+s[i] ans=s1[n]-s1[0] for i in range(n): ans=min(ans,min(dp[i]))+s1[n]-s1[i+1] print(ans) ```
instruction
0
87,747
7
175,494
No
output
1
87,747
7
175,495
Provide tags and a correct Python 3 solution for this coding contest problem. Ivan wants to make a necklace as a present to his beloved girl. A necklace is a cyclic sequence of beads of different colors. Ivan says that necklace is beautiful relative to the cut point between two adjacent beads, if the chain of beads remaining after this cut is a palindrome (reads the same forward and backward). <image> Ivan has beads of n colors. He wants to make a necklace, such that it's beautiful relative to as many cuts as possible. He certainly wants to use all the beads. Help him to make the most beautiful necklace. Input The first line of the input contains a single number n (1 ≤ n ≤ 26) — the number of colors of beads. The second line contains after n positive integers ai — the quantity of beads of i-th color. It is guaranteed that the sum of ai is at least 2 and does not exceed 100 000. Output In the first line print a single number — the maximum number of beautiful cuts that a necklace composed from given beads may have. In the second line print any example of such necklace. Each color of the beads should be represented by the corresponding lowercase English letter (starting with a). As the necklace is cyclic, print it starting from any point. Examples Input 3 4 2 1 Output 1 abacaba Input 1 4 Output 4 aaaa Input 2 1 1 Output 0 ab Note In the first sample a necklace can have at most one beautiful cut. The example of such a necklace is shown on the picture. In the second sample there is only one way to compose a necklace.
instruction
0
87,989
7
175,978
Tags: constructive algorithms, math Correct Solution: ``` from fractions import gcd from functools import reduce LETTERS = 'abcdefghijklmnopqrstuvwxyz' def necklace_odd(a): oi = next(i for i, ai in enumerate(a) if ai%2) o = a[oi] g = reduce(gcd, a) s = [LETTERS[i] * (a[i]//(2*g)) for i in range(len(a)) if i != oi] return g, (''.join(s) + (LETTERS[oi]*(o//g)) + ''.join(reversed(s))) * g def necklace_even(a): g = reduce(gcd, a)//2 s = [LETTERS[i]*(a[i]//(2*g)) for i in range(len(a))] return 2*g, (''.join(s) + ''.join(reversed(s))) * g def necklace(a): if len(a) == 1: return a[0], LETTERS[0]*a[0] nodd = sum(ai%2 for ai in a) if nodd > 1: return 0, ''.join(LETTERS[i]*a[i] for i in range(len(a))) return (necklace_odd if nodd else necklace_even)(a) if __name__ == '__main__': n = int(input()) a = list(map(int, input().split())) assert len(a) == n k, e = necklace(a) print(k) print(e) # Made By Mostafa_Khaled ```
output
1
87,989
7
175,979
Provide tags and a correct Python 3 solution for this coding contest problem. Ivan wants to make a necklace as a present to his beloved girl. A necklace is a cyclic sequence of beads of different colors. Ivan says that necklace is beautiful relative to the cut point between two adjacent beads, if the chain of beads remaining after this cut is a palindrome (reads the same forward and backward). <image> Ivan has beads of n colors. He wants to make a necklace, such that it's beautiful relative to as many cuts as possible. He certainly wants to use all the beads. Help him to make the most beautiful necklace. Input The first line of the input contains a single number n (1 ≤ n ≤ 26) — the number of colors of beads. The second line contains after n positive integers ai — the quantity of beads of i-th color. It is guaranteed that the sum of ai is at least 2 and does not exceed 100 000. Output In the first line print a single number — the maximum number of beautiful cuts that a necklace composed from given beads may have. In the second line print any example of such necklace. Each color of the beads should be represented by the corresponding lowercase English letter (starting with a). As the necklace is cyclic, print it starting from any point. Examples Input 3 4 2 1 Output 1 abacaba Input 1 4 Output 4 aaaa Input 2 1 1 Output 0 ab Note In the first sample a necklace can have at most one beautiful cut. The example of such a necklace is shown on the picture. In the second sample there is only one way to compose a necklace.
instruction
0
87,990
7
175,980
Tags: constructive algorithms, math Correct Solution: ``` import math #import fractions from functools import reduce n = int(input()) odd = -1 beads = [int(x) for x in input().split()] for i in range(n): if beads[i]%2: if odd >= 0: print(0) print(''.join(chr(ord('a') + i)*beads[i] for i in range(n))) break else: odd = i else: gcd = reduce(lambda x,y: math.gcd(x,y), beads) print(gcd) if odd >= 0: s = ''.join(chr(ord('a') + i)*(beads[i]//(2*gcd)) for i in range(n) if i != odd) p = s + chr(ord('a') + odd)*(beads[odd]//gcd) + s[::-1] print(p*gcd) else: s = ''.join(chr(ord('a') + i)*(beads[i]//gcd) for i in range(n)) p = s + s[::-1] print(p*(gcd//2)) ```
output
1
87,990
7
175,981
Provide tags and a correct Python 3 solution for this coding contest problem. Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin corresponds to the clock center. The clock was painted two colors as is shown in the picture: <image> The picture shows only the central part of the clock. This coloring naturally extends to infinity. The balls can be taken to be points on the plane. Your task is to find the color of the area, damaged by the given ball. All the points located on the border of one of the areas have to be considered painted black. Input The first and single line contains two integers x and y — the coordinates of the hole made in the clock by the ball. Each of the numbers x and y has an absolute value that does not exceed 1000. Output Find the required color. All the points between which and the origin of coordinates the distance is integral-value are painted black. Examples Input -2 1 Output white Input 2 1 Output black Input 4 3 Output black
instruction
0
88,783
7
177,566
Tags: constructive algorithms, geometry, implementation, math Correct Solution: ``` from math import sqrt,ceil x,y=map(int,input().split()) if x==0 or y==0: print("black") else: if ( x>0 and y>0 ) or ( x<0 and y<0 ) : d = sqrt( (x**2) + (y**2) ) if int(d)==ceil(d): print('black') else: if int(d)%2==0: print("black") else: print("white") elif ( x<0 and y>0 ) or ( x>0 and y<0 ) : d = sqrt( (x**2) + (y**2) ) if int(d)==ceil(d): print('black') else: if int(d)%2==0: print("white") else: print("black") ```
output
1
88,783
7
177,567
Provide tags and a correct Python 3 solution for this coding contest problem. Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin corresponds to the clock center. The clock was painted two colors as is shown in the picture: <image> The picture shows only the central part of the clock. This coloring naturally extends to infinity. The balls can be taken to be points on the plane. Your task is to find the color of the area, damaged by the given ball. All the points located on the border of one of the areas have to be considered painted black. Input The first and single line contains two integers x and y — the coordinates of the hole made in the clock by the ball. Each of the numbers x and y has an absolute value that does not exceed 1000. Output Find the required color. All the points between which and the origin of coordinates the distance is integral-value are painted black. Examples Input -2 1 Output white Input 2 1 Output black Input 4 3 Output black
instruction
0
88,784
7
177,568
Tags: constructive algorithms, geometry, implementation, math Correct Solution: ``` a,b=map(int,input().split()) i=0 while i*i<a*a+b*b:i+=1 black=0 if (i*i==a*a+b*b) or (a*b>=0)!=(i%2==0):black=1 if black:print("black") else:print("white") ```
output
1
88,784
7
177,569
Provide tags and a correct Python 3 solution for this coding contest problem. Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin corresponds to the clock center. The clock was painted two colors as is shown in the picture: <image> The picture shows only the central part of the clock. This coloring naturally extends to infinity. The balls can be taken to be points on the plane. Your task is to find the color of the area, damaged by the given ball. All the points located on the border of one of the areas have to be considered painted black. Input The first and single line contains two integers x and y — the coordinates of the hole made in the clock by the ball. Each of the numbers x and y has an absolute value that does not exceed 1000. Output Find the required color. All the points between which and the origin of coordinates the distance is integral-value are painted black. Examples Input -2 1 Output white Input 2 1 Output black Input 4 3 Output black
instruction
0
88,785
7
177,570
Tags: constructive algorithms, geometry, implementation, math Correct Solution: ``` # url: https://codeforces.com/contest/40/problem/a # tag: # difficulty: from typing import List INF = float("inf") NINF = float("-inf") def read_string(): return input() def read_string_line(): return [x for x in input().split(" ")] def read_int_line(): return [int(x) for x in input().split(" ")] def read_int(): return int(input()) def get_int_arr(s): return [int(x) for x in s.split()] def get_sum(acc, l, r): """ l, r are original index """ return acc[r] - acc[l] P = int(1e9 + 7) def exgcd(x, y): if y == 0: return x, 1, 0 g, a, b = exgcd(y, x % y) t = x // y return g, b, a - t * b def inv(x): g, a, b = exgcd(x, P) return a def calc_acc(arr): ans = [0] for a in arr: ans.append(a + ans[-1]) return ans class Point: def __init__(self, x, y): self.x = x self.y = y def __sub__(self, other): return Point(self.x - other.x, self.y - other.y) def dot(self, other): return self.x * other.x + self.y * other.y def cross(self, other): return self.x * other.y - self.y * other.x def __str__(self): return "Point(%s, %s)" % (self.x, self.y) def abs(self): return self.abs2() ** 0.5 def abs2(self): return self.dot(self) def get_point(line): x, y = get_int_arr(line) return Point(x, y) eps = 1e-8 lines: List[str] = [*open(0)] pt = get_point(lines[0]) r = pt.abs() if pt.x == 0 or pt.y == 0 or abs(r - int(r)) <= eps or abs(r - int(r + 0.5)) <= eps: print("black") else: r = int(r) if (r % 2 == 0 and pt.x * pt.y > 0) or (r % 2 == 1 and pt.x * pt.y < 0): print("black") else: print("white") ```
output
1
88,785
7
177,571
Provide tags and a correct Python 3 solution for this coding contest problem. Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin corresponds to the clock center. The clock was painted two colors as is shown in the picture: <image> The picture shows only the central part of the clock. This coloring naturally extends to infinity. The balls can be taken to be points on the plane. Your task is to find the color of the area, damaged by the given ball. All the points located on the border of one of the areas have to be considered painted black. Input The first and single line contains two integers x and y — the coordinates of the hole made in the clock by the ball. Each of the numbers x and y has an absolute value that does not exceed 1000. Output Find the required color. All the points between which and the origin of coordinates the distance is integral-value are painted black. Examples Input -2 1 Output white Input 2 1 Output black Input 4 3 Output black
instruction
0
88,786
7
177,572
Tags: constructive algorithms, geometry, implementation, math Correct Solution: ``` import math import sys x,y=map(int,input().split()) is_right=(x*y>=0) r=(x**2+y**2)**0.5 if r%1==0: print("black") else: if is_right: if r%2>1: print("white") else: print("black") else: if r%2>1: print("black") else: print("white") ```
output
1
88,786
7
177,573
Provide tags and a correct Python 3 solution for this coding contest problem. Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin corresponds to the clock center. The clock was painted two colors as is shown in the picture: <image> The picture shows only the central part of the clock. This coloring naturally extends to infinity. The balls can be taken to be points on the plane. Your task is to find the color of the area, damaged by the given ball. All the points located on the border of one of the areas have to be considered painted black. Input The first and single line contains two integers x and y — the coordinates of the hole made in the clock by the ball. Each of the numbers x and y has an absolute value that does not exceed 1000. Output Find the required color. All the points between which and the origin of coordinates the distance is integral-value are painted black. Examples Input -2 1 Output white Input 2 1 Output black Input 4 3 Output black
instruction
0
88,787
7
177,574
Tags: constructive algorithms, geometry, implementation, math Correct Solution: ``` a, b = list(map(int, input().split(' '))) d=((a**2+b**2)**0.5) if d%1==0: print("black") else: if (a > 0 and b > 0) or (a<0 and b<0): if int((a**2+b**2)**0.5)%2 == 0: print("black") else: print("white") else: if int((a**2+b**2)**0.5)%2==0: print("white") else: print("black") ```
output
1
88,787
7
177,575
Provide tags and a correct Python 3 solution for this coding contest problem. Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin corresponds to the clock center. The clock was painted two colors as is shown in the picture: <image> The picture shows only the central part of the clock. This coloring naturally extends to infinity. The balls can be taken to be points on the plane. Your task is to find the color of the area, damaged by the given ball. All the points located on the border of one of the areas have to be considered painted black. Input The first and single line contains two integers x and y — the coordinates of the hole made in the clock by the ball. Each of the numbers x and y has an absolute value that does not exceed 1000. Output Find the required color. All the points between which and the origin of coordinates the distance is integral-value are painted black. Examples Input -2 1 Output white Input 2 1 Output black Input 4 3 Output black
instruction
0
88,788
7
177,576
Tags: constructive algorithms, geometry, implementation, math Correct Solution: ``` def define(x, y): dist = 0 while dist * dist < x * x + y * y: dist += 1 flag = (dist * dist == x * x + y * y) or ((dist % 2 == 0) != (x * y >= 0)) if flag == 1: return "black" return "white" X, Y = [int(i) for i in input().split()] print(define(X, Y)) ```
output
1
88,788
7
177,577
Provide tags and a correct Python 3 solution for this coding contest problem. Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin corresponds to the clock center. The clock was painted two colors as is shown in the picture: <image> The picture shows only the central part of the clock. This coloring naturally extends to infinity. The balls can be taken to be points on the plane. Your task is to find the color of the area, damaged by the given ball. All the points located on the border of one of the areas have to be considered painted black. Input The first and single line contains two integers x and y — the coordinates of the hole made in the clock by the ball. Each of the numbers x and y has an absolute value that does not exceed 1000. Output Find the required color. All the points between which and the origin of coordinates the distance is integral-value are painted black. Examples Input -2 1 Output white Input 2 1 Output black Input 4 3 Output black
instruction
0
88,789
7
177,578
Tags: constructive algorithms, geometry, implementation, math Correct Solution: ``` import math x, y = map(int, input().split()) dd = x*x + y*y d = math.floor(dd ** 0.5) black = False if d*d == dd: black = True elif x/abs(x) == y/abs(y): black = d%2 == 0 else: black = d%2 == 1 if black: print('black') else: print('white') ```
output
1
88,789
7
177,579
Provide tags and a correct Python 3 solution for this coding contest problem. Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin corresponds to the clock center. The clock was painted two colors as is shown in the picture: <image> The picture shows only the central part of the clock. This coloring naturally extends to infinity. The balls can be taken to be points on the plane. Your task is to find the color of the area, damaged by the given ball. All the points located on the border of one of the areas have to be considered painted black. Input The first and single line contains two integers x and y — the coordinates of the hole made in the clock by the ball. Each of the numbers x and y has an absolute value that does not exceed 1000. Output Find the required color. All the points between which and the origin of coordinates the distance is integral-value are painted black. Examples Input -2 1 Output white Input 2 1 Output black Input 4 3 Output black
instruction
0
88,790
7
177,580
Tags: constructive algorithms, geometry, implementation, math Correct Solution: ``` x, y = map(int, input().split()) p = x * x + y * y d = int(p ** 0.5) if d * d == p: print('black') else: if x * y < 0: print('black' if d % 2 else 'white') else: print('white' if d % 2 else 'black') ```
output
1
88,790
7
177,581
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin corresponds to the clock center. The clock was painted two colors as is shown in the picture: <image> The picture shows only the central part of the clock. This coloring naturally extends to infinity. The balls can be taken to be points on the plane. Your task is to find the color of the area, damaged by the given ball. All the points located on the border of one of the areas have to be considered painted black. Input The first and single line contains two integers x and y — the coordinates of the hole made in the clock by the ball. Each of the numbers x and y has an absolute value that does not exceed 1000. Output Find the required color. All the points between which and the origin of coordinates the distance is integral-value are painted black. Examples Input -2 1 Output white Input 2 1 Output black Input 4 3 Output black Submitted Solution: ``` import sys import math import itertools import collections def getdict(n): d = {} if type(n) is list or type(n) is str: for i in n: if i in d: d[i] += 1 else: d[i] = 1 else: for i in range(n): t = ii() if t in d: d[t] += 1 else: d[t] = 1 return d def cdiv(n, k): return n // k + (n % k != 0) def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return list(map(int, input().split())) def lcm(a, b): return abs(a*b) // math.gcd(a, b) def wr(arr): return ' '.join(map(str, arr)) def revn(n): return int(str(n)[::-1]) def prime(n): if n == 2: return True if n % 2 == 0 or n <= 1: return False sqr = int(math.sqrt(n)) + 1 for d in range(3, sqr, 2): if n % d == 0: return False return True x, y = mi() r = math.sqrt(x ** 2 + y ** 2) if x * y > 0 and int(r) % 2 == 1 and int(r) < r and r < int(r) + 1\ or x * y < 0 and int(r) % 2 == 0 and int(r) < r and r < int(r) + 1: print('white') else: print('black') ```
instruction
0
88,791
7
177,582
Yes
output
1
88,791
7
177,583
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin corresponds to the clock center. The clock was painted two colors as is shown in the picture: <image> The picture shows only the central part of the clock. This coloring naturally extends to infinity. The balls can be taken to be points on the plane. Your task is to find the color of the area, damaged by the given ball. All the points located on the border of one of the areas have to be considered painted black. Input The first and single line contains two integers x and y — the coordinates of the hole made in the clock by the ball. Each of the numbers x and y has an absolute value that does not exceed 1000. Output Find the required color. All the points between which and the origin of coordinates the distance is integral-value are painted black. Examples Input -2 1 Output white Input 2 1 Output black Input 4 3 Output black Submitted Solution: ``` # _ ##################################################################################################################### from math import sqrt, ceil def colorOfDamagedArea(coordinate): x, y = coordinate.split() x, y = int(x), int(y) location = sqrt(x*x+y*y) area_sBorder = ceil(location) if location == area_sBorder: return 'black' area_sAddress = x*y area_sColorCode = area_sBorder%2 if area_sAddress > 0 and area_sColorCode or area_sAddress < 0 and not area_sColorCode: return 'black' return 'white' print(colorOfDamagedArea(input())) ```
instruction
0
88,792
7
177,584
Yes
output
1
88,792
7
177,585
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin corresponds to the clock center. The clock was painted two colors as is shown in the picture: <image> The picture shows only the central part of the clock. This coloring naturally extends to infinity. The balls can be taken to be points on the plane. Your task is to find the color of the area, damaged by the given ball. All the points located on the border of one of the areas have to be considered painted black. Input The first and single line contains two integers x and y — the coordinates of the hole made in the clock by the ball. Each of the numbers x and y has an absolute value that does not exceed 1000. Output Find the required color. All the points between which and the origin of coordinates the distance is integral-value are painted black. Examples Input -2 1 Output white Input 2 1 Output black Input 4 3 Output black Submitted Solution: ``` # # 20200103 00:54 ~ 01:01 x, y = map(int, input().split()) dist = pow(x**2 + y**2, 0.5) if dist%1 == 0: print("black") else: dist = int(dist) is_odd = (dist%2 == 1) if is_odd != (x*y>0): print("black") else: print("white") ```
instruction
0
88,793
7
177,586
Yes
output
1
88,793
7
177,587
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin corresponds to the clock center. The clock was painted two colors as is shown in the picture: <image> The picture shows only the central part of the clock. This coloring naturally extends to infinity. The balls can be taken to be points on the plane. Your task is to find the color of the area, damaged by the given ball. All the points located on the border of one of the areas have to be considered painted black. Input The first and single line contains two integers x and y — the coordinates of the hole made in the clock by the ball. Each of the numbers x and y has an absolute value that does not exceed 1000. Output Find the required color. All the points between which and the origin of coordinates the distance is integral-value are painted black. Examples Input -2 1 Output white Input 2 1 Output black Input 4 3 Output black Submitted Solution: ``` from math import sqrt x,y = list(map(int,input().split())) #1000 r = sqrt(x*x+y*y) print('black' if ((int(r)%2>0) ^ (x*y>0)) or r==int(r) else 'white') ```
instruction
0
88,794
7
177,588
Yes
output
1
88,794
7
177,589
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin corresponds to the clock center. The clock was painted two colors as is shown in the picture: <image> The picture shows only the central part of the clock. This coloring naturally extends to infinity. The balls can be taken to be points on the plane. Your task is to find the color of the area, damaged by the given ball. All the points located on the border of one of the areas have to be considered painted black. Input The first and single line contains two integers x and y — the coordinates of the hole made in the clock by the ball. Each of the numbers x and y has an absolute value that does not exceed 1000. Output Find the required color. All the points between which and the origin of coordinates the distance is integral-value are painted black. Examples Input -2 1 Output white Input 2 1 Output black Input 4 3 Output black Submitted Solution: ``` x,y=map(int,input().split()) if x==0 or y==0: print("black") exit() x,y=min(y,x),max(y,x) if x<0: if y<0: x=abs(x) if x%2: y=abs(y) if not y%2: print("black") else: print("white") else: y=abs(y) if not y%2: print("white") else: print("black") else: if x%2: y=abs(y) if not y%2: print("white") else: print("black") else: y=abs(y) if not y%2: print("black") else: print("white") else: if not y%2: print("black") else: print("white") ```
instruction
0
88,795
7
177,590
No
output
1
88,795
7
177,591
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin corresponds to the clock center. The clock was painted two colors as is shown in the picture: <image> The picture shows only the central part of the clock. This coloring naturally extends to infinity. The balls can be taken to be points on the plane. Your task is to find the color of the area, damaged by the given ball. All the points located on the border of one of the areas have to be considered painted black. Input The first and single line contains two integers x and y — the coordinates of the hole made in the clock by the ball. Each of the numbers x and y has an absolute value that does not exceed 1000. Output Find the required color. All the points between which and the origin of coordinates the distance is integral-value are painted black. Examples Input -2 1 Output white Input 2 1 Output black Input 4 3 Output black Submitted Solution: ``` import math n = list(map(int,input().split())) x = n[0] y = n[1] k = int(math.sqrt(x*x + y*y)) if x*y < 0 : if x*x +y*y == k*k : if k % 2 == 0: print('black') else : print('white') else : if k % 2 == 0: print('white') else : print('black') else : if x*x +y*y == k*k : if k % 2 == 0: print('white') else : print('black') else : if k % 2 == 0: print('black') else : print('white') ```
instruction
0
88,796
7
177,592
No
output
1
88,796
7
177,593
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin corresponds to the clock center. The clock was painted two colors as is shown in the picture: <image> The picture shows only the central part of the clock. This coloring naturally extends to infinity. The balls can be taken to be points on the plane. Your task is to find the color of the area, damaged by the given ball. All the points located on the border of one of the areas have to be considered painted black. Input The first and single line contains two integers x and y — the coordinates of the hole made in the clock by the ball. Each of the numbers x and y has an absolute value that does not exceed 1000. Output Find the required color. All the points between which and the origin of coordinates the distance is integral-value are painted black. Examples Input -2 1 Output white Input 2 1 Output black Input 4 3 Output black Submitted Solution: ``` x,y=map(float,input().split()) r=(x**2+y**2)**0.5 c=int(r) if r==c: print('black') elif x*y==0: print('black') elif x*y>0: if r%2==0: print('white') else: print('black') else: if r%2==0: print('black') else: print('white') ```
instruction
0
88,797
7
177,594
No
output
1
88,797
7
177,595
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin corresponds to the clock center. The clock was painted two colors as is shown in the picture: <image> The picture shows only the central part of the clock. This coloring naturally extends to infinity. The balls can be taken to be points on the plane. Your task is to find the color of the area, damaged by the given ball. All the points located on the border of one of the areas have to be considered painted black. Input The first and single line contains two integers x and y — the coordinates of the hole made in the clock by the ball. Each of the numbers x and y has an absolute value that does not exceed 1000. Output Find the required color. All the points between which and the origin of coordinates the distance is integral-value are painted black. Examples Input -2 1 Output white Input 2 1 Output black Input 4 3 Output black Submitted Solution: ``` a,b=map(int,input().split()) if (a<0 and b<0) or (a>0 and b>0): if a==b:print(['black','white'][a%2==0]);exit() print(['black','white'][max(abs(a),abs(b))&1]) else: if a == b: print(['black', 'white'][a % 2]);exit() print(['white','black'][max(abs(a),abs(b))&1 and abs(a)!=abs(b)]) ```
instruction
0
88,798
7
177,596
No
output
1
88,798
7
177,597
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In Berland prime numbers are fashionable — the respectable citizens dwell only on the floors with numbers that are prime numbers. The numismatists value particularly high the coins with prime nominal values. All the prime days are announced holidays! Yet even this is not enough to make the Berland people happy. On the main street of the capital stand n houses, numbered from 1 to n. The government decided to paint every house a color so that the sum of the numbers of the houses painted every color is a prime number. However it turned out that not all the citizens approve of this decision — many of them protest because they don't want many colored houses on the capital's main street. That's why it is decided to use the minimal possible number of colors. The houses don't have to be painted consecutively, but every one of n houses should be painted some color. The one-colored houses should not stand consecutively, any way of painting is acceptable. There are no more than 5 hours left before the start of painting, help the government find the way when the sum of house numbers for every color is a prime number and the number of used colors is minimal. Input The single input line contains an integer n (2 ≤ n ≤ 6000) — the number of houses on the main streets of the capital. Output Print the sequence of n numbers, where the i-th number stands for the number of color for house number i. Number the colors consecutively starting from 1. Any painting order is allowed. If there are several solutions to that problem, print any of them. If there's no such way of painting print the single number -1. Examples Input 8 Output 1 2 2 1 1 1 1 2 Submitted Solution: ``` #import sys #import itertools #import math #t = int(input()) t = 1 while t > 0: #print(t) n = int(input()) res = [] res.append(1) res.append(2) n-=2 for _ in range(n): res.append(1) print(" ".join(str(x) for x in res)) t -= 1 ```
instruction
0
88,800
7
177,600
No
output
1
88,800
7
177,601
Provide tags and a correct Python 3 solution for this coding contest problem. On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard. There are n bricks lined in a row on the ground. Chouti has got m paint buckets of different colors at hand, so he painted each brick in one of those m colors. Having finished painting all bricks, Chouti was satisfied. He stood back and decided to find something fun with these bricks. After some counting, he found there are k bricks with a color different from the color of the brick on its left (the first brick is not counted, for sure). So as usual, he needs your help in counting how many ways could he paint the bricks. Two ways of painting bricks are different if there is at least one brick painted in different colors in these two ways. Because the answer might be quite big, you only need to output the number of ways modulo 998 244 353. Input The first and only line contains three integers n, m and k (1 ≤ n,m ≤ 2000, 0 ≤ k ≤ n-1) — the number of bricks, the number of colors, and the number of bricks, such that its color differs from the color of brick to the left of it. Output Print one integer — the number of ways to color bricks modulo 998 244 353. Examples Input 3 3 0 Output 3 Input 3 2 1 Output 4 Note In the first example, since k=0, the color of every brick should be the same, so there will be exactly m=3 ways to color the bricks. In the second example, suppose the two colors in the buckets are yellow and lime, the following image shows all 4 possible colorings. <image>
instruction
0
89,284
7
178,568
Tags: combinatorics, dp, math Correct Solution: ``` P = 998244353 def C(n, k): global P k = min(k, n-k) p = 1 for i in range(n, n-k, -1): p *= i for i in range(k, 0, -1): assert(p%i==0) p //= i return p%P n, m, k = map(int, input().split()) r = C(n-1, k) r = (r*m)%P for i in range(k): r = (r*(m-1))%P print(r) ```
output
1
89,284
7
178,569
Provide tags and a correct Python 3 solution for this coding contest problem. On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard. There are n bricks lined in a row on the ground. Chouti has got m paint buckets of different colors at hand, so he painted each brick in one of those m colors. Having finished painting all bricks, Chouti was satisfied. He stood back and decided to find something fun with these bricks. After some counting, he found there are k bricks with a color different from the color of the brick on its left (the first brick is not counted, for sure). So as usual, he needs your help in counting how many ways could he paint the bricks. Two ways of painting bricks are different if there is at least one brick painted in different colors in these two ways. Because the answer might be quite big, you only need to output the number of ways modulo 998 244 353. Input The first and only line contains three integers n, m and k (1 ≤ n,m ≤ 2000, 0 ≤ k ≤ n-1) — the number of bricks, the number of colors, and the number of bricks, such that its color differs from the color of brick to the left of it. Output Print one integer — the number of ways to color bricks modulo 998 244 353. Examples Input 3 3 0 Output 3 Input 3 2 1 Output 4 Note In the first example, since k=0, the color of every brick should be the same, so there will be exactly m=3 ways to color the bricks. In the second example, suppose the two colors in the buckets are yellow and lime, the following image shows all 4 possible colorings. <image>
instruction
0
89,285
7
178,570
Tags: combinatorics, dp, math Correct Solution: ``` def fact(i): if i == 0: return 1 if i < 0: return 0 res = 1 for t in range(1, i + 1): res *= t return res n, m, k = map(int, input().split(' ')) if k >= n: print(0) exit(0) print(fact(n - 1) // fact(k) // fact(n - k - 1) * m * (m - 1) ** k % 998244353) ```
output
1
89,285
7
178,571
Provide tags and a correct Python 3 solution for this coding contest problem. On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard. There are n bricks lined in a row on the ground. Chouti has got m paint buckets of different colors at hand, so he painted each brick in one of those m colors. Having finished painting all bricks, Chouti was satisfied. He stood back and decided to find something fun with these bricks. After some counting, he found there are k bricks with a color different from the color of the brick on its left (the first brick is not counted, for sure). So as usual, he needs your help in counting how many ways could he paint the bricks. Two ways of painting bricks are different if there is at least one brick painted in different colors in these two ways. Because the answer might be quite big, you only need to output the number of ways modulo 998 244 353. Input The first and only line contains three integers n, m and k (1 ≤ n,m ≤ 2000, 0 ≤ k ≤ n-1) — the number of bricks, the number of colors, and the number of bricks, such that its color differs from the color of brick to the left of it. Output Print one integer — the number of ways to color bricks modulo 998 244 353. Examples Input 3 3 0 Output 3 Input 3 2 1 Output 4 Note In the first example, since k=0, the color of every brick should be the same, so there will be exactly m=3 ways to color the bricks. In the second example, suppose the two colors in the buckets are yellow and lime, the following image shows all 4 possible colorings. <image>
instruction
0
89,286
7
178,572
Tags: combinatorics, dp, math Correct Solution: ``` from sys import stdin,stdout import math mod = 998244353 I = stdin.readline P = stdout.write n,m,k = map(int,I().split()) comb = ((math.factorial(n-1))//(math.factorial(n-1-k)))//(math.factorial(k)) comb%=mod power = pow(m-1,k,mod) comb*=power comb*=m comb%=mod P(str(comb)+"\n") ```
output
1
89,286
7
178,573
Provide tags and a correct Python 3 solution for this coding contest problem. On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard. There are n bricks lined in a row on the ground. Chouti has got m paint buckets of different colors at hand, so he painted each brick in one of those m colors. Having finished painting all bricks, Chouti was satisfied. He stood back and decided to find something fun with these bricks. After some counting, he found there are k bricks with a color different from the color of the brick on its left (the first brick is not counted, for sure). So as usual, he needs your help in counting how many ways could he paint the bricks. Two ways of painting bricks are different if there is at least one brick painted in different colors in these two ways. Because the answer might be quite big, you only need to output the number of ways modulo 998 244 353. Input The first and only line contains three integers n, m and k (1 ≤ n,m ≤ 2000, 0 ≤ k ≤ n-1) — the number of bricks, the number of colors, and the number of bricks, such that its color differs from the color of brick to the left of it. Output Print one integer — the number of ways to color bricks modulo 998 244 353. Examples Input 3 3 0 Output 3 Input 3 2 1 Output 4 Note In the first example, since k=0, the color of every brick should be the same, so there will be exactly m=3 ways to color the bricks. In the second example, suppose the two colors in the buckets are yellow and lime, the following image shows all 4 possible colorings. <image>
instruction
0
89,287
7
178,574
Tags: combinatorics, dp, math Correct Solution: ``` MOD = 998244353 def bpow(a, b): sol = 1 while b: if b&1: sol*=a if sol>=MOD: sol%=MOD a*=a if a>=MOD: a%=MOD b>>=1 return sol fac = [] fac += [1] for i in range(1,2001): fac.append(fac[i-1]*i%MOD) ifac = [] for i in range(0,2001): ifac.append(bpow(fac[i],MOD-2)) def nCr(a, b): return fac[a]*ifac[a-b]*ifac[b]%MOD n,m,k = map(int,input().split()) print (nCr(n-1,k)*m*bpow(m-1,k)%MOD) ```
output
1
89,287
7
178,575
Provide tags and a correct Python 3 solution for this coding contest problem. On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard. There are n bricks lined in a row on the ground. Chouti has got m paint buckets of different colors at hand, so he painted each brick in one of those m colors. Having finished painting all bricks, Chouti was satisfied. He stood back and decided to find something fun with these bricks. After some counting, he found there are k bricks with a color different from the color of the brick on its left (the first brick is not counted, for sure). So as usual, he needs your help in counting how many ways could he paint the bricks. Two ways of painting bricks are different if there is at least one brick painted in different colors in these two ways. Because the answer might be quite big, you only need to output the number of ways modulo 998 244 353. Input The first and only line contains three integers n, m and k (1 ≤ n,m ≤ 2000, 0 ≤ k ≤ n-1) — the number of bricks, the number of colors, and the number of bricks, such that its color differs from the color of brick to the left of it. Output Print one integer — the number of ways to color bricks modulo 998 244 353. Examples Input 3 3 0 Output 3 Input 3 2 1 Output 4 Note In the first example, since k=0, the color of every brick should be the same, so there will be exactly m=3 ways to color the bricks. In the second example, suppose the two colors in the buckets are yellow and lime, the following image shows all 4 possible colorings. <image>
instruction
0
89,288
7
178,576
Tags: combinatorics, dp, math Correct Solution: ``` """ this is a standard python template for codeforces task, repo: github.com/solbiatialessandro/pyComPro/codeforces """ stdin = lambda type_ = "int", sep = " ": list(map(eval(type_), input().split(sep))) joint = lambda sep = " ", *args: sep.join(str(i) if type(i) != list else sep.join(map(str, i)) for i in args) def binomial(n, k): """ A fast way to calculate binomial coefficients by Andrew Dalke. See http://stackoverflow.com/questions/3025162/statistics-combinations-in-python """ if 0 <= k <= n: ntok = 1 ktok = 1 for t in range(1, min(k, n - k) + 1): ntok *= n ktok *= t n -= 1 return ntok // ktok else: return 0 def solve(n, m, k): parts = m * pow(m - 1, k) return (binomial(n - 1, k) * parts) % 998244353 if __name__ == "__main__": """the solve(*args) structure is needed for testing purporses""" n, m, k = stdin() print(solve(n, m, k)) ```
output
1
89,288
7
178,577
Provide tags and a correct Python 3 solution for this coding contest problem. On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard. There are n bricks lined in a row on the ground. Chouti has got m paint buckets of different colors at hand, so he painted each brick in one of those m colors. Having finished painting all bricks, Chouti was satisfied. He stood back and decided to find something fun with these bricks. After some counting, he found there are k bricks with a color different from the color of the brick on its left (the first brick is not counted, for sure). So as usual, he needs your help in counting how many ways could he paint the bricks. Two ways of painting bricks are different if there is at least one brick painted in different colors in these two ways. Because the answer might be quite big, you only need to output the number of ways modulo 998 244 353. Input The first and only line contains three integers n, m and k (1 ≤ n,m ≤ 2000, 0 ≤ k ≤ n-1) — the number of bricks, the number of colors, and the number of bricks, such that its color differs from the color of brick to the left of it. Output Print one integer — the number of ways to color bricks modulo 998 244 353. Examples Input 3 3 0 Output 3 Input 3 2 1 Output 4 Note In the first example, since k=0, the color of every brick should be the same, so there will be exactly m=3 ways to color the bricks. In the second example, suppose the two colors in the buckets are yellow and lime, the following image shows all 4 possible colorings. <image>
instruction
0
89,289
7
178,578
Tags: combinatorics, dp, math Correct Solution: ``` s = input() s=s.split(' ') n = int(s[0]) m = int(s[1]) k = int(s[2]) ans = 1 if(k>0): for i in range(n-k, n): ans = ans * i for i in range(1, k + 1): ans = ans // i ans = ans * m for i in range(k): ans = ans * (m - 1) pass print(ans % 998244353) ```
output
1
89,289
7
178,579
Provide tags and a correct Python 3 solution for this coding contest problem. On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard. There are n bricks lined in a row on the ground. Chouti has got m paint buckets of different colors at hand, so he painted each brick in one of those m colors. Having finished painting all bricks, Chouti was satisfied. He stood back and decided to find something fun with these bricks. After some counting, he found there are k bricks with a color different from the color of the brick on its left (the first brick is not counted, for sure). So as usual, he needs your help in counting how many ways could he paint the bricks. Two ways of painting bricks are different if there is at least one brick painted in different colors in these two ways. Because the answer might be quite big, you only need to output the number of ways modulo 998 244 353. Input The first and only line contains three integers n, m and k (1 ≤ n,m ≤ 2000, 0 ≤ k ≤ n-1) — the number of bricks, the number of colors, and the number of bricks, such that its color differs from the color of brick to the left of it. Output Print one integer — the number of ways to color bricks modulo 998 244 353. Examples Input 3 3 0 Output 3 Input 3 2 1 Output 4 Note In the first example, since k=0, the color of every brick should be the same, so there will be exactly m=3 ways to color the bricks. In the second example, suppose the two colors in the buckets are yellow and lime, the following image shows all 4 possible colorings. <image>
instruction
0
89,290
7
178,580
Tags: combinatorics, dp, math Correct Solution: ``` MOD = 998244353 n, nColors, nDiff = map(int, input().split()) dp = [[0 for _ in range(nDiff + 1)] for _ in range(n)] dp[0][0] = nColors for size in range(1, n): for cnt in range(nDiff + 1): dp[size][cnt] += dp[size - 1][cnt] dp[size][cnt] %= MOD if cnt - 1 >= 0: dp[size][cnt] += (dp[size - 1][cnt - 1] * (nColors - 1)) % MOD dp[size][cnt] %= MOD print(dp[n - 1][nDiff]) ```
output
1
89,290
7
178,581
Provide tags and a correct Python 3 solution for this coding contest problem. On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard. There are n bricks lined in a row on the ground. Chouti has got m paint buckets of different colors at hand, so he painted each brick in one of those m colors. Having finished painting all bricks, Chouti was satisfied. He stood back and decided to find something fun with these bricks. After some counting, he found there are k bricks with a color different from the color of the brick on its left (the first brick is not counted, for sure). So as usual, he needs your help in counting how many ways could he paint the bricks. Two ways of painting bricks are different if there is at least one brick painted in different colors in these two ways. Because the answer might be quite big, you only need to output the number of ways modulo 998 244 353. Input The first and only line contains three integers n, m and k (1 ≤ n,m ≤ 2000, 0 ≤ k ≤ n-1) — the number of bricks, the number of colors, and the number of bricks, such that its color differs from the color of brick to the left of it. Output Print one integer — the number of ways to color bricks modulo 998 244 353. Examples Input 3 3 0 Output 3 Input 3 2 1 Output 4 Note In the first example, since k=0, the color of every brick should be the same, so there will be exactly m=3 ways to color the bricks. In the second example, suppose the two colors in the buckets are yellow and lime, the following image shows all 4 possible colorings. <image>
instruction
0
89,291
7
178,582
Tags: combinatorics, dp, math Correct Solution: ``` n, m, k = map(int, input().split()) dp = [[m if i == 0 else 0 for i in range(k + 2)] for j in range(n + 1)] dp[0][0] = 0 mod = 998244353 for i in range(1, n + 1): for j in range(1, k + 2): dp[i][j] = (dp[i - 1][j] + (m - 1) * dp[i - 1][j - 1]) % mod print(dp[n][k] % mod) ```
output
1
89,291
7
178,583
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard. There are n bricks lined in a row on the ground. Chouti has got m paint buckets of different colors at hand, so he painted each brick in one of those m colors. Having finished painting all bricks, Chouti was satisfied. He stood back and decided to find something fun with these bricks. After some counting, he found there are k bricks with a color different from the color of the brick on its left (the first brick is not counted, for sure). So as usual, he needs your help in counting how many ways could he paint the bricks. Two ways of painting bricks are different if there is at least one brick painted in different colors in these two ways. Because the answer might be quite big, you only need to output the number of ways modulo 998 244 353. Input The first and only line contains three integers n, m and k (1 ≤ n,m ≤ 2000, 0 ≤ k ≤ n-1) — the number of bricks, the number of colors, and the number of bricks, such that its color differs from the color of brick to the left of it. Output Print one integer — the number of ways to color bricks modulo 998 244 353. Examples Input 3 3 0 Output 3 Input 3 2 1 Output 4 Note In the first example, since k=0, the color of every brick should be the same, so there will be exactly m=3 ways to color the bricks. In the second example, suppose the two colors in the buckets are yellow and lime, the following image shows all 4 possible colorings. <image> Submitted Solution: ``` n,m,k = map(int, input().split()) import math print((math.factorial(n-1) // math.factorial(n-k-1) // math.factorial(k) * m * (m-1) ** k) % 998244353) ```
instruction
0
89,292
7
178,584
Yes
output
1
89,292
7
178,585
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard. There are n bricks lined in a row on the ground. Chouti has got m paint buckets of different colors at hand, so he painted each brick in one of those m colors. Having finished painting all bricks, Chouti was satisfied. He stood back and decided to find something fun with these bricks. After some counting, he found there are k bricks with a color different from the color of the brick on its left (the first brick is not counted, for sure). So as usual, he needs your help in counting how many ways could he paint the bricks. Two ways of painting bricks are different if there is at least one brick painted in different colors in these two ways. Because the answer might be quite big, you only need to output the number of ways modulo 998 244 353. Input The first and only line contains three integers n, m and k (1 ≤ n,m ≤ 2000, 0 ≤ k ≤ n-1) — the number of bricks, the number of colors, and the number of bricks, such that its color differs from the color of brick to the left of it. Output Print one integer — the number of ways to color bricks modulo 998 244 353. Examples Input 3 3 0 Output 3 Input 3 2 1 Output 4 Note In the first example, since k=0, the color of every brick should be the same, so there will be exactly m=3 ways to color the bricks. In the second example, suppose the two colors in the buckets are yellow and lime, the following image shows all 4 possible colorings. <image> Submitted Solution: ``` import math import bisect import itertools import sys I=lambda : sys.stdin.readline() mod=998244353 fact=[1]*20001 ifact=[1]*20001 for i in range(1,1001): fact[i]=((fact[i-1])*i)%mod ifact[i]=((ifact[i-1])*pow(i,mod-2,mod))%mod def ncr(n,r): return (((fact[n]*ifact[n-r])%mod)*ifact[r])%mod def npr(n,r): return (((fact[n]*ifact[n-r])%mod)) def mindiff(a): b=a[:] b.sort() m=10000000000 for i in range(len(b)-1): if b[i+1]-b[i]<m: m=b[i+1]-b[i] return m def lcm(a,b): return a*b//math.gcd(a,b) def merge(a,b): i=0;j=0 c=0 ans=[] while i<len(a) and j<len(b): if a[i]<b[j]: ans.append(a[i]) i+=1 else: ans.append(b[j]) c+=len(a)-i j+=1 ans+=a[i:] ans+=b[j:] return ans,c def mergesort(a): if len(a)==1: return a,0 mid=len(a)//2 left,left_inversion=mergesort(a[:mid]) right,right_inversion=mergesort(a[mid:]) m,c=merge(left,right) c+=(left_inversion+right_inversion) return m,c def is_prime(num): if num == 2: return True if num == 3: return True if num%2 == 0: return False if num%3 == 0: return False t = 5 a = 2 while t <= int(math.sqrt(num)): if num%t == 0: return False t += a a = 6 - a return True def ceil(a,b): if a%b==0: return a//b else: return (a//b + 1) def binsearch(arr,b,low,high): if low==high: return low if arr[math.ceil((low+high)/2)]<b: return binsearch(arr,b,low,math.ceil((low+high)/2) -1 ) else: return binsearch(arr,b,math.ceil((low+high)/2),high) def ncr1(n,r): s=1 for i in range(min(n-r,r)): s*=(n-i) s%=mod s*=pow(i+1,mod-2,mod) s%=mod return s def calc(n,m,r): s=0 for i in range(0,r+1,2): s+=ncr1(n,i)*ncr1(m,i) s%=mod return s #///////////////////////////////////////////////////////////////////////////////////////////////// mod1=998244353 t=int() n,m,k=map(int,input().split()) if (k>0 and m==1) or k>=n: print(0) elif k==0: print(m) else: k1=ncr1(n-1,k) k1*=pow(m-1,k,mod1) k1%=mod k1*=m print(k1%mod) ```
instruction
0
89,293
7
178,586
Yes
output
1
89,293
7
178,587
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard. There are n bricks lined in a row on the ground. Chouti has got m paint buckets of different colors at hand, so he painted each brick in one of those m colors. Having finished painting all bricks, Chouti was satisfied. He stood back and decided to find something fun with these bricks. After some counting, he found there are k bricks with a color different from the color of the brick on its left (the first brick is not counted, for sure). So as usual, he needs your help in counting how many ways could he paint the bricks. Two ways of painting bricks are different if there is at least one brick painted in different colors in these two ways. Because the answer might be quite big, you only need to output the number of ways modulo 998 244 353. Input The first and only line contains three integers n, m and k (1 ≤ n,m ≤ 2000, 0 ≤ k ≤ n-1) — the number of bricks, the number of colors, and the number of bricks, such that its color differs from the color of brick to the left of it. Output Print one integer — the number of ways to color bricks modulo 998 244 353. Examples Input 3 3 0 Output 3 Input 3 2 1 Output 4 Note In the first example, since k=0, the color of every brick should be the same, so there will be exactly m=3 ways to color the bricks. In the second example, suppose the two colors in the buckets are yellow and lime, the following image shows all 4 possible colorings. <image> Submitted Solution: ``` mod = 998244353 n, m, k = map(int, input().split()) a = pow(m-1, k, mod) * m % mod for i in range(n-k, n) : a = a * i for i in range(1, k+1) : a //= i print(a % mod) ```
instruction
0
89,294
7
178,588
Yes
output
1
89,294
7
178,589
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard. There are n bricks lined in a row on the ground. Chouti has got m paint buckets of different colors at hand, so he painted each brick in one of those m colors. Having finished painting all bricks, Chouti was satisfied. He stood back and decided to find something fun with these bricks. After some counting, he found there are k bricks with a color different from the color of the brick on its left (the first brick is not counted, for sure). So as usual, he needs your help in counting how many ways could he paint the bricks. Two ways of painting bricks are different if there is at least one brick painted in different colors in these two ways. Because the answer might be quite big, you only need to output the number of ways modulo 998 244 353. Input The first and only line contains three integers n, m and k (1 ≤ n,m ≤ 2000, 0 ≤ k ≤ n-1) — the number of bricks, the number of colors, and the number of bricks, such that its color differs from the color of brick to the left of it. Output Print one integer — the number of ways to color bricks modulo 998 244 353. Examples Input 3 3 0 Output 3 Input 3 2 1 Output 4 Note In the first example, since k=0, the color of every brick should be the same, so there will be exactly m=3 ways to color the bricks. In the second example, suppose the two colors in the buckets are yellow and lime, the following image shows all 4 possible colorings. <image> Submitted Solution: ``` n , m , k = map(int,input().split(' ')) # dp[i][j] <- no of ways of painting first i bricks such that j bricks are different from their left MOD = 998244353 dp = [[0]*(k+1) for _ in range(n)] dp[0][0] = m #base case for i in range(1,n) : for j in range(min(i+1,k+1)) : dp[i][j] = ( (0 if j==0 else (dp[i-1][j-1]*(m-1))%MOD) + dp[i-1][j])%MOD # print(dp) print(dp[-1][-1]) ```
instruction
0
89,295
7
178,590
Yes
output
1
89,295
7
178,591
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard. There are n bricks lined in a row on the ground. Chouti has got m paint buckets of different colors at hand, so he painted each brick in one of those m colors. Having finished painting all bricks, Chouti was satisfied. He stood back and decided to find something fun with these bricks. After some counting, he found there are k bricks with a color different from the color of the brick on its left (the first brick is not counted, for sure). So as usual, he needs your help in counting how many ways could he paint the bricks. Two ways of painting bricks are different if there is at least one brick painted in different colors in these two ways. Because the answer might be quite big, you only need to output the number of ways modulo 998 244 353. Input The first and only line contains three integers n, m and k (1 ≤ n,m ≤ 2000, 0 ≤ k ≤ n-1) — the number of bricks, the number of colors, and the number of bricks, such that its color differs from the color of brick to the left of it. Output Print one integer — the number of ways to color bricks modulo 998 244 353. Examples Input 3 3 0 Output 3 Input 3 2 1 Output 4 Note In the first example, since k=0, the color of every brick should be the same, so there will be exactly m=3 ways to color the bricks. In the second example, suppose the two colors in the buckets are yellow and lime, the following image shows all 4 possible colorings. <image> Submitted Solution: ``` # import collections, atexit, math, sys, bisect sys.setrecursionlimit(1000000) def getIntList(): return list(map(int, input().split())) try : #raise ModuleNotFoundError import numpy def dprint(*args, **kwargs): #print(*args, **kwargs, file=sys.stderr) # in python 3.4 **kwargs is invalid??? print(*args, file=sys.stderr) dprint('debug mode') except Exception: def dprint(*args, **kwargs): pass inId = 0 outId = 0 if inId>0: dprint('use input', inId) sys.stdin = open('input'+ str(inId) + '.txt', 'r') #标准输出重定向至文件 if outId>0: dprint('use output', outId) sys.stdout = open('stdout'+ str(outId) + '.txt', 'w') #标准输出重定向至文件 atexit.register(lambda :sys.stdout.close()) #idle 中不会执行 atexit N, M, K= getIntList() base = 998244353 J = N-1 - K # same Z = N - J dprint(Z) R = M for i in range(Z-1): R *= M-1 R%= base dprint(R) n0 = J m0 = Z dprint(n0,m0) #comb(n0 + m0 -1, m0-1) for i in range(m0 -1): g = n0 + m0 -1 -i R*= g R%= base def e_gcd(a, b ): if a==0 and b==0: return -1, 0, 0 if b==0: return a, 1,0 d, x,y = e_gcd(b, a%b ) y-= a //b *x return d , x,y def m_reverse(a,n): d,x,y = e_gcd(a,n) if d==1: if x%n<=0: return x%n+n else: return x%n else: return -1 for i in range(2, m0): t = m_reverse(i,base) R*=t R%=base print(R) ```
instruction
0
89,296
7
178,592
No
output
1
89,296
7
178,593
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard. There are n bricks lined in a row on the ground. Chouti has got m paint buckets of different colors at hand, so he painted each brick in one of those m colors. Having finished painting all bricks, Chouti was satisfied. He stood back and decided to find something fun with these bricks. After some counting, he found there are k bricks with a color different from the color of the brick on its left (the first brick is not counted, for sure). So as usual, he needs your help in counting how many ways could he paint the bricks. Two ways of painting bricks are different if there is at least one brick painted in different colors in these two ways. Because the answer might be quite big, you only need to output the number of ways modulo 998 244 353. Input The first and only line contains three integers n, m and k (1 ≤ n,m ≤ 2000, 0 ≤ k ≤ n-1) — the number of bricks, the number of colors, and the number of bricks, such that its color differs from the color of brick to the left of it. Output Print one integer — the number of ways to color bricks modulo 998 244 353. Examples Input 3 3 0 Output 3 Input 3 2 1 Output 4 Note In the first example, since k=0, the color of every brick should be the same, so there will be exactly m=3 ways to color the bricks. In the second example, suppose the two colors in the buckets are yellow and lime, the following image shows all 4 possible colorings. <image> Submitted Solution: ``` n,m,k = map(int, input().split()) dp = [[0 for _ in range(k+1)] for _ in range(n)] for i in range(n): dp[i][0] = m for i in range(1,n): for j in range(1,k+1): dp[i][j] = (m-1)*dp[i-1][j-1] + dp[i-1][j] dp[i][j] %= 998244354 #print(dp) print(dp[n-1][k]) ```
instruction
0
89,297
7
178,594
No
output
1
89,297
7
178,595
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard. There are n bricks lined in a row on the ground. Chouti has got m paint buckets of different colors at hand, so he painted each brick in one of those m colors. Having finished painting all bricks, Chouti was satisfied. He stood back and decided to find something fun with these bricks. After some counting, he found there are k bricks with a color different from the color of the brick on its left (the first brick is not counted, for sure). So as usual, he needs your help in counting how many ways could he paint the bricks. Two ways of painting bricks are different if there is at least one brick painted in different colors in these two ways. Because the answer might be quite big, you only need to output the number of ways modulo 998 244 353. Input The first and only line contains three integers n, m and k (1 ≤ n,m ≤ 2000, 0 ≤ k ≤ n-1) — the number of bricks, the number of colors, and the number of bricks, such that its color differs from the color of brick to the left of it. Output Print one integer — the number of ways to color bricks modulo 998 244 353. Examples Input 3 3 0 Output 3 Input 3 2 1 Output 4 Note In the first example, since k=0, the color of every brick should be the same, so there will be exactly m=3 ways to color the bricks. In the second example, suppose the two colors in the buckets are yellow and lime, the following image shows all 4 possible colorings. <image> Submitted Solution: ``` import math def colorful_bricks(): n, m, k = map(int, input().split()) comb = (math.factorial(int(n - 1)))/(math.factorial(int(k))*math.factorial(int(n - 1 - k))) print(comb * m * ((m - 1) ** k) % 998244353) colorful_bricks() ```
instruction
0
89,298
7
178,596
No
output
1
89,298
7
178,597
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard. There are n bricks lined in a row on the ground. Chouti has got m paint buckets of different colors at hand, so he painted each brick in one of those m colors. Having finished painting all bricks, Chouti was satisfied. He stood back and decided to find something fun with these bricks. After some counting, he found there are k bricks with a color different from the color of the brick on its left (the first brick is not counted, for sure). So as usual, he needs your help in counting how many ways could he paint the bricks. Two ways of painting bricks are different if there is at least one brick painted in different colors in these two ways. Because the answer might be quite big, you only need to output the number of ways modulo 998 244 353. Input The first and only line contains three integers n, m and k (1 ≤ n,m ≤ 2000, 0 ≤ k ≤ n-1) — the number of bricks, the number of colors, and the number of bricks, such that its color differs from the color of brick to the left of it. Output Print one integer — the number of ways to color bricks modulo 998 244 353. Examples Input 3 3 0 Output 3 Input 3 2 1 Output 4 Note In the first example, since k=0, the color of every brick should be the same, so there will be exactly m=3 ways to color the bricks. In the second example, suppose the two colors in the buckets are yellow and lime, the following image shows all 4 possible colorings. <image> Submitted Solution: ``` # -*- coding: utf-8 -*- def fastpowmod(a,b,mod): if b==0: return 1 r=fastpowmod(a,int(b/2),mod) if b%2: return (r*r*a)% mod else: return (r*r)% mod def coefbinommod(n,k,mod): r=1.0 for i in range(k): r=r*(n-k+i+1)/(i+1) return int(r)%mod t=1 for i in range(t): X=input().split() n=int(X[0]) m=int(X[1]) k=int(X[2]) if k==0: print(m) else: if m==1: print(0) cd=(m*fastpowmod(m-1,k,998244353))%998244353 cd=(cd*coefbinommod(n-1,k,998244353))%998244353 print(cd) ```
instruction
0
89,299
7
178,598
No
output
1
89,299
7
178,599
Provide tags and a correct Python 3 solution for this coding contest problem. We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2. However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in any order you wish. We will then compute the sums of all prefixes in the sequence, and then count how many of these sums are prime numbers. If you want to keep the prize, you will need to maximize the number of primes you get. Can you win the prize? Hurry up, the bags are waiting! Input The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of number tiles in the bag. The following line contains n space-separated integers a_1, a_2, ..., a_n (a_i ∈ \{1, 2\}) — the values written on the tiles. Output Output a permutation b_1, b_2, ..., b_n of the input sequence (a_1, a_2, ..., a_n) maximizing the number of the prefix sums being prime numbers. If there are multiple optimal permutations, output any. Examples Input 5 1 2 1 2 1 Output 1 1 1 2 2 Input 9 1 1 2 1 1 1 2 1 1 Output 1 1 1 2 1 1 1 2 1 Note The first solution produces the prefix sums 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, \mathbf{\color{blue}{7}} (four primes constructed), while the prefix sums in the second solution are 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, 6, \mathbf{\color{blue}{7}}, 8, 10, \mathbf{\color{blue}{11}} (five primes). Primes are marked bold and blue. In each of these cases, the number of produced primes is maximum possible.
instruction
0
89,333
7
178,666
Tags: constructive algorithms, greedy, math, number theory Correct Solution: ``` n = int(input()) A = [int(i) for i in input().split()] cnt1 = A.count(1) cnt2 = A.count(2) if cnt1 == 0: print(*A) elif cnt2 > 0: print(*([2] + [1] + [2] * (cnt2 - 1) + [1] * (cnt1 - 1))) else: print(*A) ```
output
1
89,333
7
178,667
Provide tags and a correct Python 3 solution for this coding contest problem. We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2. However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in any order you wish. We will then compute the sums of all prefixes in the sequence, and then count how many of these sums are prime numbers. If you want to keep the prize, you will need to maximize the number of primes you get. Can you win the prize? Hurry up, the bags are waiting! Input The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of number tiles in the bag. The following line contains n space-separated integers a_1, a_2, ..., a_n (a_i ∈ \{1, 2\}) — the values written on the tiles. Output Output a permutation b_1, b_2, ..., b_n of the input sequence (a_1, a_2, ..., a_n) maximizing the number of the prefix sums being prime numbers. If there are multiple optimal permutations, output any. Examples Input 5 1 2 1 2 1 Output 1 1 1 2 2 Input 9 1 1 2 1 1 1 2 1 1 Output 1 1 1 2 1 1 1 2 1 Note The first solution produces the prefix sums 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, \mathbf{\color{blue}{7}} (four primes constructed), while the prefix sums in the second solution are 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, 6, \mathbf{\color{blue}{7}}, 8, 10, \mathbf{\color{blue}{11}} (five primes). Primes are marked bold and blue. In each of these cases, the number of produced primes is maximum possible.
instruction
0
89,334
7
178,668
Tags: constructive algorithms, greedy, math, number theory Correct Solution: ``` n = int(input()) ls = list(map(int, input().split())) ones = 0 twos = 0 for i in range(n): if ls[i] == 1: ones += 1 else: twos += 1 if ones: if twos: print(2, 1,end=' ') for i in range(twos-1): print(2, end=' ') for i in range(ones-1): print(1, end=' ') else: for i in range(ones): print(1, end=' ') else: for i in range(twos): print(2, end=' ') ```
output
1
89,334
7
178,669
Provide tags and a correct Python 3 solution for this coding contest problem. We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2. However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in any order you wish. We will then compute the sums of all prefixes in the sequence, and then count how many of these sums are prime numbers. If you want to keep the prize, you will need to maximize the number of primes you get. Can you win the prize? Hurry up, the bags are waiting! Input The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of number tiles in the bag. The following line contains n space-separated integers a_1, a_2, ..., a_n (a_i ∈ \{1, 2\}) — the values written on the tiles. Output Output a permutation b_1, b_2, ..., b_n of the input sequence (a_1, a_2, ..., a_n) maximizing the number of the prefix sums being prime numbers. If there are multiple optimal permutations, output any. Examples Input 5 1 2 1 2 1 Output 1 1 1 2 2 Input 9 1 1 2 1 1 1 2 1 1 Output 1 1 1 2 1 1 1 2 1 Note The first solution produces the prefix sums 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, \mathbf{\color{blue}{7}} (four primes constructed), while the prefix sums in the second solution are 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, 6, \mathbf{\color{blue}{7}}, 8, 10, \mathbf{\color{blue}{11}} (five primes). Primes are marked bold and blue. In each of these cases, the number of produced primes is maximum possible.
instruction
0
89,335
7
178,670
Tags: constructive algorithms, greedy, math, number theory Correct Solution: ``` def main(): n = int(input()) a = [int(x) for x in input().split()] c1, c2 = 0, 0 for i in a: if i == 1: c1 += 1 c2 = n - c1 if c1 == 0: ans = [2] * c2 elif c2 == 0: ans = [1] * c1 else: ans = [2, 1] ans += [2] * (c2 - 1) ans += [1] * (c1 - 1) for a in ans: print(a, end=" ") if __name__ == "__main__": main() ```
output
1
89,335
7
178,671
Provide tags and a correct Python 3 solution for this coding contest problem. We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2. However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in any order you wish. We will then compute the sums of all prefixes in the sequence, and then count how many of these sums are prime numbers. If you want to keep the prize, you will need to maximize the number of primes you get. Can you win the prize? Hurry up, the bags are waiting! Input The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of number tiles in the bag. The following line contains n space-separated integers a_1, a_2, ..., a_n (a_i ∈ \{1, 2\}) — the values written on the tiles. Output Output a permutation b_1, b_2, ..., b_n of the input sequence (a_1, a_2, ..., a_n) maximizing the number of the prefix sums being prime numbers. If there are multiple optimal permutations, output any. Examples Input 5 1 2 1 2 1 Output 1 1 1 2 2 Input 9 1 1 2 1 1 1 2 1 1 Output 1 1 1 2 1 1 1 2 1 Note The first solution produces the prefix sums 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, \mathbf{\color{blue}{7}} (four primes constructed), while the prefix sums in the second solution are 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, 6, \mathbf{\color{blue}{7}}, 8, 10, \mathbf{\color{blue}{11}} (five primes). Primes are marked bold and blue. In each of these cases, the number of produced primes is maximum possible.
instruction
0
89,336
7
178,672
Tags: constructive algorithms, greedy, math, number theory Correct Solution: ``` from collections import Counter n = int(input()) a = Counter(list(map(int,input().split()))) two = a[2] one = a[1] s = '' if a[2]: s+='2 ' a[2]-=1 if a[1]: s+='1 ' a[1]-=1 s += '2 '*a[2] s += '1 '*a[1] print(s.rstrip()) ```
output
1
89,336
7
178,673
Provide tags and a correct Python 3 solution for this coding contest problem. We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2. However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in any order you wish. We will then compute the sums of all prefixes in the sequence, and then count how many of these sums are prime numbers. If you want to keep the prize, you will need to maximize the number of primes you get. Can you win the prize? Hurry up, the bags are waiting! Input The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of number tiles in the bag. The following line contains n space-separated integers a_1, a_2, ..., a_n (a_i ∈ \{1, 2\}) — the values written on the tiles. Output Output a permutation b_1, b_2, ..., b_n of the input sequence (a_1, a_2, ..., a_n) maximizing the number of the prefix sums being prime numbers. If there are multiple optimal permutations, output any. Examples Input 5 1 2 1 2 1 Output 1 1 1 2 2 Input 9 1 1 2 1 1 1 2 1 1 Output 1 1 1 2 1 1 1 2 1 Note The first solution produces the prefix sums 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, \mathbf{\color{blue}{7}} (four primes constructed), while the prefix sums in the second solution are 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, 6, \mathbf{\color{blue}{7}}, 8, 10, \mathbf{\color{blue}{11}} (five primes). Primes are marked bold and blue. In each of these cases, the number of produced primes is maximum possible.
instruction
0
89,337
7
178,674
Tags: constructive algorithms, greedy, math, number theory Correct Solution: ``` n = int(input()) a = [int(x) for x in input().split()] arr = [0, 0, 0] for item in a: arr[item] += 1 seq = '' if arr[1] > 2: seq += '111' arr[1] -= 3 elif arr[1] == 2 and arr[2]: seq += '21' arr[1] -= 1 arr[2] -= 1 elif arr[1] == 1 and arr[2]: seq += '21' arr[1] -= 1 arr[2] -= 1 if arr[2]: seq += '2'*arr[2] arr[2] = 0 if arr[1]: seq += '1'*arr[1] arr[1] = 0 for char in seq: print(char, end=' ') ```
output
1
89,337
7
178,675
Provide tags and a correct Python 3 solution for this coding contest problem. We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2. However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in any order you wish. We will then compute the sums of all prefixes in the sequence, and then count how many of these sums are prime numbers. If you want to keep the prize, you will need to maximize the number of primes you get. Can you win the prize? Hurry up, the bags are waiting! Input The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of number tiles in the bag. The following line contains n space-separated integers a_1, a_2, ..., a_n (a_i ∈ \{1, 2\}) — the values written on the tiles. Output Output a permutation b_1, b_2, ..., b_n of the input sequence (a_1, a_2, ..., a_n) maximizing the number of the prefix sums being prime numbers. If there are multiple optimal permutations, output any. Examples Input 5 1 2 1 2 1 Output 1 1 1 2 2 Input 9 1 1 2 1 1 1 2 1 1 Output 1 1 1 2 1 1 1 2 1 Note The first solution produces the prefix sums 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, \mathbf{\color{blue}{7}} (four primes constructed), while the prefix sums in the second solution are 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, 6, \mathbf{\color{blue}{7}}, 8, 10, \mathbf{\color{blue}{11}} (five primes). Primes are marked bold and blue. In each of these cases, the number of produced primes is maximum possible.
instruction
0
89,338
7
178,676
Tags: constructive algorithms, greedy, math, number theory Correct Solution: ``` from collections import defaultdict from math import sqrt def is_prime(n): for i in range(2,int(sqrt(n))+1): if n%i == 0: return False return True hash = defaultdict(int) n = int(input()) l = list(map(int,input().split())) for i in l: if i == 2: hash[2] +=1 else: hash[1]+=1 ans = [0] boo = [] for i in range(n): if is_prime(ans[-1]+2) and hash[2]>0: ans.append(ans[-1]+2) hash[2]-=1 boo.append(2) elif is_prime(ans[-1]+1) and hash[1]>0: ans.append(ans[-1]+1) boo.append(1) hash[1]-=1 else: if hash[2]>0: ans.append(ans[-1]+2) boo.append(2) hash[2]-=1 elif hash[1]>0: ans.append(ans[-1]+1) boo.append(1) hash[1]-=1 print(*boo) ```
output
1
89,338
7
178,677
Provide tags and a correct Python 3 solution for this coding contest problem. We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2. However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in any order you wish. We will then compute the sums of all prefixes in the sequence, and then count how many of these sums are prime numbers. If you want to keep the prize, you will need to maximize the number of primes you get. Can you win the prize? Hurry up, the bags are waiting! Input The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of number tiles in the bag. The following line contains n space-separated integers a_1, a_2, ..., a_n (a_i ∈ \{1, 2\}) — the values written on the tiles. Output Output a permutation b_1, b_2, ..., b_n of the input sequence (a_1, a_2, ..., a_n) maximizing the number of the prefix sums being prime numbers. If there are multiple optimal permutations, output any. Examples Input 5 1 2 1 2 1 Output 1 1 1 2 2 Input 9 1 1 2 1 1 1 2 1 1 Output 1 1 1 2 1 1 1 2 1 Note The first solution produces the prefix sums 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, \mathbf{\color{blue}{7}} (four primes constructed), while the prefix sums in the second solution are 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, 6, \mathbf{\color{blue}{7}}, 8, 10, \mathbf{\color{blue}{11}} (five primes). Primes are marked bold and blue. In each of these cases, the number of produced primes is maximum possible.
instruction
0
89,339
7
178,678
Tags: constructive algorithms, greedy, math, number theory Correct Solution: ``` def sol(tiles): if len(tiles) == 1: return tiles[0] d = {'1': 0, '2': 0} for t in tiles: d[t] += 1 if d['1'] == 0: return ' '.join(['2'] * d['2']) if d['2'] == 0: return ' '.join(['1'] * d['1']) return ' '.join(['2','1'] + ['2']*(d['2']-1) + ['1']*(d['1']-1)) if __name__ == '__main__': _ = input() tiles = input().split() print(sol(tiles)) ```
output
1
89,339
7
178,679
Provide tags and a correct Python 3 solution for this coding contest problem. We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2. However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in any order you wish. We will then compute the sums of all prefixes in the sequence, and then count how many of these sums are prime numbers. If you want to keep the prize, you will need to maximize the number of primes you get. Can you win the prize? Hurry up, the bags are waiting! Input The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of number tiles in the bag. The following line contains n space-separated integers a_1, a_2, ..., a_n (a_i ∈ \{1, 2\}) — the values written on the tiles. Output Output a permutation b_1, b_2, ..., b_n of the input sequence (a_1, a_2, ..., a_n) maximizing the number of the prefix sums being prime numbers. If there are multiple optimal permutations, output any. Examples Input 5 1 2 1 2 1 Output 1 1 1 2 2 Input 9 1 1 2 1 1 1 2 1 1 Output 1 1 1 2 1 1 1 2 1 Note The first solution produces the prefix sums 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, \mathbf{\color{blue}{7}} (four primes constructed), while the prefix sums in the second solution are 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, 6, \mathbf{\color{blue}{7}}, 8, 10, \mathbf{\color{blue}{11}} (five primes). Primes are marked bold and blue. In each of these cases, the number of produced primes is maximum possible.
instruction
0
89,340
7
178,680
Tags: constructive algorithms, greedy, math, number theory Correct Solution: ``` n=int(input()) a=list(map(int,input().split())) t=a.count(2);o=a.count(1) if t: print(2,end=" ");t-=1;n-=1 if o: print(1,end=" ");o-=1;n-=1 for i in range(n): if t: print(2,end=" ");t-=1 else: print(1,end=" ") ```
output
1
89,340
7
178,681
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2. However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in any order you wish. We will then compute the sums of all prefixes in the sequence, and then count how many of these sums are prime numbers. If you want to keep the prize, you will need to maximize the number of primes you get. Can you win the prize? Hurry up, the bags are waiting! Input The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of number tiles in the bag. The following line contains n space-separated integers a_1, a_2, ..., a_n (a_i ∈ \{1, 2\}) — the values written on the tiles. Output Output a permutation b_1, b_2, ..., b_n of the input sequence (a_1, a_2, ..., a_n) maximizing the number of the prefix sums being prime numbers. If there are multiple optimal permutations, output any. Examples Input 5 1 2 1 2 1 Output 1 1 1 2 2 Input 9 1 1 2 1 1 1 2 1 1 Output 1 1 1 2 1 1 1 2 1 Note The first solution produces the prefix sums 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, \mathbf{\color{blue}{7}} (four primes constructed), while the prefix sums in the second solution are 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, 6, \mathbf{\color{blue}{7}}, 8, 10, \mathbf{\color{blue}{11}} (five primes). Primes are marked bold and blue. In each of these cases, the number of produced primes is maximum possible. Submitted Solution: ``` n=int(input()) arr=list(map(int,input().split())) a=arr.count(1) b=arr.count(2) if a>=1 and b>=1: print('2'+ ' 1'+ ' 2'*(b-1)+ ' 1'*(a-1)) else: print(*arr) ```
instruction
0
89,341
7
178,682
Yes
output
1
89,341
7
178,683
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2. However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in any order you wish. We will then compute the sums of all prefixes in the sequence, and then count how many of these sums are prime numbers. If you want to keep the prize, you will need to maximize the number of primes you get. Can you win the prize? Hurry up, the bags are waiting! Input The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of number tiles in the bag. The following line contains n space-separated integers a_1, a_2, ..., a_n (a_i ∈ \{1, 2\}) — the values written on the tiles. Output Output a permutation b_1, b_2, ..., b_n of the input sequence (a_1, a_2, ..., a_n) maximizing the number of the prefix sums being prime numbers. If there are multiple optimal permutations, output any. Examples Input 5 1 2 1 2 1 Output 1 1 1 2 2 Input 9 1 1 2 1 1 1 2 1 1 Output 1 1 1 2 1 1 1 2 1 Note The first solution produces the prefix sums 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, \mathbf{\color{blue}{7}} (four primes constructed), while the prefix sums in the second solution are 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, 6, \mathbf{\color{blue}{7}}, 8, 10, \mathbf{\color{blue}{11}} (five primes). Primes are marked bold and blue. In each of these cases, the number of produced primes is maximum possible. Submitted Solution: ``` # base on idea 1 is not a prime number, 2, 3 is a prime number # => 2 first numbers should be 2, 1, then all prime numbers are odd numbers n = int(input()) a = list(map(int, input().split())) c1 = c2 = 0 for i in a: if i == 1: c1 += 1 else: c2 += 1 b = [] if not c1: b = [2] * c2 elif not c2: b = [1] * c1 else: b = [2, 1] for i in range(c2 - 1): b.append(2) for i in range(c1 - 1): b.append(1) print (" ".join(map(str, b))) ```
instruction
0
89,342
7
178,684
Yes
output
1
89,342
7
178,685
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2. However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in any order you wish. We will then compute the sums of all prefixes in the sequence, and then count how many of these sums are prime numbers. If you want to keep the prize, you will need to maximize the number of primes you get. Can you win the prize? Hurry up, the bags are waiting! Input The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of number tiles in the bag. The following line contains n space-separated integers a_1, a_2, ..., a_n (a_i ∈ \{1, 2\}) — the values written on the tiles. Output Output a permutation b_1, b_2, ..., b_n of the input sequence (a_1, a_2, ..., a_n) maximizing the number of the prefix sums being prime numbers. If there are multiple optimal permutations, output any. Examples Input 5 1 2 1 2 1 Output 1 1 1 2 2 Input 9 1 1 2 1 1 1 2 1 1 Output 1 1 1 2 1 1 1 2 1 Note The first solution produces the prefix sums 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, \mathbf{\color{blue}{7}} (four primes constructed), while the prefix sums in the second solution are 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, 6, \mathbf{\color{blue}{7}}, 8, 10, \mathbf{\color{blue}{11}} (five primes). Primes are marked bold and blue. In each of these cases, the number of produced primes is maximum possible. Submitted Solution: ``` #------------------------------warmup---------------------------- import os import sys from io import BytesIO, IOBase 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.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") #-------------------game starts now----------------------------------------------------- n=int(input()) l=list(map(int,input().split())) c=0 d=0 ans=[] for i in range(n): if l[i]==1: c+=1 else: d+=1 if d>0: ans.append(2) d-=1 if c>0: ans.append(1) c-=1 for i in range(d): ans.append(2) for i in range(c): ans.append(1) print(*ans,sep=" ") ```
instruction
0
89,343
7
178,686
Yes
output
1
89,343
7
178,687
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2. However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in any order you wish. We will then compute the sums of all prefixes in the sequence, and then count how many of these sums are prime numbers. If you want to keep the prize, you will need to maximize the number of primes you get. Can you win the prize? Hurry up, the bags are waiting! Input The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of number tiles in the bag. The following line contains n space-separated integers a_1, a_2, ..., a_n (a_i ∈ \{1, 2\}) — the values written on the tiles. Output Output a permutation b_1, b_2, ..., b_n of the input sequence (a_1, a_2, ..., a_n) maximizing the number of the prefix sums being prime numbers. If there are multiple optimal permutations, output any. Examples Input 5 1 2 1 2 1 Output 1 1 1 2 2 Input 9 1 1 2 1 1 1 2 1 1 Output 1 1 1 2 1 1 1 2 1 Note The first solution produces the prefix sums 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, \mathbf{\color{blue}{7}} (four primes constructed), while the prefix sums in the second solution are 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, 6, \mathbf{\color{blue}{7}}, 8, 10, \mathbf{\color{blue}{11}} (five primes). Primes are marked bold and blue. In each of these cases, the number of produced primes is maximum possible. Submitted Solution: ``` n=int(input()) y=list(map(int,input().split())) if n==1: print(y[0]) else: even=y.count(2) odd=y.count(1) if even==0 or odd==0: print(*y) else: y=sorted(y) y.reverse() i=0 while i<n: if y[i]==1: break i+=1 t=y[i] y[i]=y[1] y[1]=t print(*y) ```
instruction
0
89,344
7
178,688
Yes
output
1
89,344
7
178,689
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2. However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in any order you wish. We will then compute the sums of all prefixes in the sequence, and then count how many of these sums are prime numbers. If you want to keep the prize, you will need to maximize the number of primes you get. Can you win the prize? Hurry up, the bags are waiting! Input The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of number tiles in the bag. The following line contains n space-separated integers a_1, a_2, ..., a_n (a_i ∈ \{1, 2\}) — the values written on the tiles. Output Output a permutation b_1, b_2, ..., b_n of the input sequence (a_1, a_2, ..., a_n) maximizing the number of the prefix sums being prime numbers. If there are multiple optimal permutations, output any. Examples Input 5 1 2 1 2 1 Output 1 1 1 2 2 Input 9 1 1 2 1 1 1 2 1 1 Output 1 1 1 2 1 1 1 2 1 Note The first solution produces the prefix sums 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, \mathbf{\color{blue}{7}} (four primes constructed), while the prefix sums in the second solution are 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, 6, \mathbf{\color{blue}{7}}, 8, 10, \mathbf{\color{blue}{11}} (five primes). Primes are marked bold and blue. In each of these cases, the number of produced primes is maximum possible. Submitted Solution: ``` from collections import Counter n=int(input()) lst=list(map(int,input().split())) dct=Counter(lst) if(len(dct)==1): print(*lst) else: if(dct[1]%2==0): dct[1]-=1 s="2 "+"1 "*dct[1]+"2 "*(dct[2]-1) print(s[:-1]) ```
instruction
0
89,345
7
178,690
No
output
1
89,345
7
178,691
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2. However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in any order you wish. We will then compute the sums of all prefixes in the sequence, and then count how many of these sums are prime numbers. If you want to keep the prize, you will need to maximize the number of primes you get. Can you win the prize? Hurry up, the bags are waiting! Input The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of number tiles in the bag. The following line contains n space-separated integers a_1, a_2, ..., a_n (a_i ∈ \{1, 2\}) — the values written on the tiles. Output Output a permutation b_1, b_2, ..., b_n of the input sequence (a_1, a_2, ..., a_n) maximizing the number of the prefix sums being prime numbers. If there are multiple optimal permutations, output any. Examples Input 5 1 2 1 2 1 Output 1 1 1 2 2 Input 9 1 1 2 1 1 1 2 1 1 Output 1 1 1 2 1 1 1 2 1 Note The first solution produces the prefix sums 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, \mathbf{\color{blue}{7}} (four primes constructed), while the prefix sums in the second solution are 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, 6, \mathbf{\color{blue}{7}}, 8, 10, \mathbf{\color{blue}{11}} (five primes). Primes are marked bold and blue. In each of these cases, the number of produced primes is maximum possible. Submitted Solution: ``` from collections import Counter n = int(input()) l = list(map(int, input().split())) c = Counter(l) if 1 in c: nb_1 = c[1] ans = [1]*(1 + 2*(nb_1-1)//2) else: ans = [] if 2 in c: ans += [2]*c[2] if 1 in c and c[1] %2 ==0: ans.apend(1) print() ```
instruction
0
89,346
7
178,692
No
output
1
89,346
7
178,693