message
stringlengths
2
433k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
113
108k
cluster
float64
12
12
__index_level_0__
int64
226
217k
Provide tags and a correct Python 3 solution for this coding contest problem. We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≀ li ≀ ri ≀ n) meaning that value <image> should be equal to qi. Your task is to find any interesting array of n elements or state that such array doesn't exist. Expression x&y means the bitwise AND of numbers x and y. In programming languages C++, Java and Python this operation is represented as "&", in Pascal β€” as "and". Input The first line contains two integers n, m (1 ≀ n ≀ 105, 1 ≀ m ≀ 105) β€” the number of elements in the array and the number of limits. Each of the next m lines contains three integers li, ri, qi (1 ≀ li ≀ ri ≀ n, 0 ≀ qi < 230) describing the i-th limit. Output If the interesting array exists, in the first line print "YES" (without the quotes) and in the second line print n integers a[1], a[2], ..., a[n] (0 ≀ a[i] < 230) decribing the interesting array. If there are multiple answers, print any of them. If the interesting array doesn't exist, print "NO" (without the quotes) in the single line. Examples Input 3 1 1 3 3 Output YES 3 3 3 Input 3 2 1 3 3 1 3 2 Output NO
instruction
0
69,364
12
138,728
Tags: constructive algorithms, data structures, trees Correct Solution: ``` from sys import stdin input=stdin.readline def funcand(a,b): return a&b class SegmentTree: def __init__(self, data, default=(1<<31)-1, func=max): """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): """func of data[start, stop)""" start += self._size stop += self._size res_left = res_right = self._default while start < stop: if start & 1: res_left = self._func(res_left, self.data[start]) start += 1 if stop & 1: stop -= 1 res_right = self._func(self.data[stop], res_right) start >>= 1 stop >>= 1 return self._func(res_left, res_right) def f(n,q): a=[0]*(n) for bit in range(30): s=[0]*(n+1) for l,r,nm in q: if((nm>>bit)&1): s[l]+=1 s[r]-=1 for i in range(n): if i>0: s[i]+=s[i-1] # bich ke bhar raha hai if s[i]>0: a[i]|=(1<<bit) st=SegmentTree(a,func=funcand,default=(1<<31)-1) for l,r,nm in q: # print(st.query(l,r)) if st.query(l,r)!=nm: return "NO" print("YES") print(*a) return '' q=[] n,m=map(int,input().strip().split()) for _ in range(m): l,r,nm=map(int,input().strip().split()) q.append((l-1,r,nm)) print(f(n,q)) ```
output
1
69,364
12
138,729
Provide tags and a correct Python 3 solution for this coding contest problem. We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≀ li ≀ ri ≀ n) meaning that value <image> should be equal to qi. Your task is to find any interesting array of n elements or state that such array doesn't exist. Expression x&y means the bitwise AND of numbers x and y. In programming languages C++, Java and Python this operation is represented as "&", in Pascal β€” as "and". Input The first line contains two integers n, m (1 ≀ n ≀ 105, 1 ≀ m ≀ 105) β€” the number of elements in the array and the number of limits. Each of the next m lines contains three integers li, ri, qi (1 ≀ li ≀ ri ≀ n, 0 ≀ qi < 230) describing the i-th limit. Output If the interesting array exists, in the first line print "YES" (without the quotes) and in the second line print n integers a[1], a[2], ..., a[n] (0 ≀ a[i] < 230) decribing the interesting array. If there are multiple answers, print any of them. If the interesting array doesn't exist, print "NO" (without the quotes) in the single line. Examples Input 3 1 1 3 3 Output YES 3 3 3 Input 3 2 1 3 3 1 3 2 Output NO
instruction
0
69,365
12
138,730
Tags: constructive algorithms, data structures, trees Correct Solution: ``` 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") MAX = 1000001 bitscount = 30 prefix_count = [[0]*(10**5+1) for i in range(30)] def findPrefixCount(arr, n): for i in range(0, bitscount): prefix_count[i][0] = ((arr[0] >> i) & 1) for j in range(1, n): prefix_count[i][j] = ((arr[j] >> i) & 1) prefix_count[i][j] += prefix_count[i][j - 1] def rangeOr(l, r): ans = 0 for i in range(bitscount): x = 0 if (l == 0): x = prefix_count[i][r] else: x = prefix_count[i][r] - prefix_count[i][l - 1] # Condition for ith bit # of answer to be set if (x == r - l + 1): ans = (ans | (1 << i)) return ans n, m = map(int, input().split()) a = [[0] * n for i in range(30)] query = [] for i in range(m): l, r, q = map(int, input().split()) query.append([l-1, r-1, q]) c = bin(q)[2:][::-1] b = [] for j in c: b.append(int(j)) j = 0 while (j < len(b)): if b[j] == 1: a[j][l - 1] += 1 if r != n: a[j][r] -= 1 j += 1 for i in range(30): j = 1 while (j < n): a[i][j] += a[i][j - 1] j += 1 j = 0 while (j < n): if a[i][j] > 0: a[i][j] = 1 j += 1 res=[] for i in range(n): s = "" j=29 while(j>=0): s += str(a[j][i]) j+=-1 res.append(int(s,2)) findPrefixCount(res, n) f=0 for j in query: if rangeOr(j[0],j[1])!=j[2]: f=1 break if f==1: print("NO") else: print("YES") print(*res) ```
output
1
69,365
12
138,731
Provide tags and a correct Python 3 solution for this coding contest problem. We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≀ li ≀ ri ≀ n) meaning that value <image> should be equal to qi. Your task is to find any interesting array of n elements or state that such array doesn't exist. Expression x&y means the bitwise AND of numbers x and y. In programming languages C++, Java and Python this operation is represented as "&", in Pascal β€” as "and". Input The first line contains two integers n, m (1 ≀ n ≀ 105, 1 ≀ m ≀ 105) β€” the number of elements in the array and the number of limits. Each of the next m lines contains three integers li, ri, qi (1 ≀ li ≀ ri ≀ n, 0 ≀ qi < 230) describing the i-th limit. Output If the interesting array exists, in the first line print "YES" (without the quotes) and in the second line print n integers a[1], a[2], ..., a[n] (0 ≀ a[i] < 230) decribing the interesting array. If there are multiple answers, print any of them. If the interesting array doesn't exist, print "NO" (without the quotes) in the single line. Examples Input 3 1 1 3 3 Output YES 3 3 3 Input 3 2 1 3 3 1 3 2 Output NO
instruction
0
69,366
12
138,732
Tags: constructive algorithms, data structures, trees Correct Solution: ``` # Legends Always Come Up with Solution # Author: Manvir Singh import os from io import BytesIO, IOBase import sys from collections import defaultdict, deque, Counter from math import sqrt, pi, ceil, log, inf, gcd, floor from itertools import combinations, permutations from bisect import * from fractions import Fraction from heapq import * from random import randint def main(): po=[1] for i in range(30): po.append(po[-1]*2) n,m=map(int,input().split()) q=[] b=[[0 for _ in range(30)] for _ in range(n+2)] for i in range(m): l,r,x=map(int,input().split()) q.append((l,r,x)) j=0 while x: if x&1: b[l][j]+=1 b[r+1][j]-=1 x=x>>1 j+=1 for i in range(1,n+1): for j in range(30): b[i][j]+=b[i-1][j] for i in range(1,n+1): for j in range(30): if b[i][j]>=2: b[i][j]=1 b[i][j]+=b[i-1][j] f=1 for i in q: l,r,x=i z=0 for j in range(30): if b[r][j]-b[l-1][j]==(r-l+1): z+=po[j] if z!=x: f=0 break if f: print("YES") a=[] for i in range(1,n+1): z=0 for j in range(30): if b[i][j]-b[i-1][j]==1: z+=po[j] a.append(z) print(*a) else: print("NO") # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.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") if __name__ == "__main__": main() ```
output
1
69,366
12
138,733
Provide tags and a correct Python 3 solution for this coding contest problem. There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≀ n ≀ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≀ ai ≀ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
instruction
0
69,380
12
138,760
Tags: implementation Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) ans = n - max([a.count(x) for x in [1, 2, 3]]) print(ans) ```
output
1
69,380
12
138,761
Provide tags and a correct Python 3 solution for this coding contest problem. There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≀ n ≀ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≀ ai ≀ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
instruction
0
69,381
12
138,762
Tags: implementation Correct Solution: ``` from collections import Counter l=[] n=int(input()) c=Counter(list(map(int,input().split()))) for key,value in c.items():l.append(value) if len(l)==1:print(0) elif len(l)==2:print(min(l[0],l[1])) else:print(min(l[0]+l[1],l[0]+l[2],l[1]+l[2])) ```
output
1
69,381
12
138,763
Provide tags and a correct Python 3 solution for this coding contest problem. There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≀ n ≀ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≀ ai ≀ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
instruction
0
69,382
12
138,764
Tags: implementation Correct Solution: ``` n=int(input()) a=list(map(int,input().split()));b=list(set(a)) c=[a.count(i) for i in b] print(n-max(c)) ```
output
1
69,382
12
138,765
Provide tags and a correct Python 3 solution for this coding contest problem. There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≀ n ≀ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≀ ai ≀ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
instruction
0
69,383
12
138,766
Tags: implementation Correct Solution: ``` n=int(input()) a=list(map(int,input().split()))[:n] x=a.count(1) y=a.count(2) z=a.count(3) print(n-max(x,y,z)) ```
output
1
69,383
12
138,767
Provide tags and a correct Python 3 solution for this coding contest problem. There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≀ n ≀ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≀ ai ≀ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
instruction
0
69,384
12
138,768
Tags: implementation Correct Solution: ``` n=int(input()) l=[int(x) for x in input().split()] one=l.count(1) two=l.count(2) print(n-max(one, two, n-one-two)) ```
output
1
69,384
12
138,769
Provide tags and a correct Python 3 solution for this coding contest problem. There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≀ n ≀ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≀ ai ≀ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
instruction
0
69,385
12
138,770
Tags: implementation Correct Solution: ``` x=int(input()) s=[int(n) for n in (input()).split()] a=s.count(1) b=s.count(2) c=s.count(3) z=int((a+b+abs(a-b))/2) z=int((z+c+abs(z-c))/2) print(x-z) ```
output
1
69,385
12
138,771
Provide tags and a correct Python 3 solution for this coding contest problem. There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≀ n ≀ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≀ ai ≀ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
instruction
0
69,386
12
138,772
Tags: implementation Correct Solution: ``` n = int(input()) daf = list(map(int, input().split())) num1 = daf.count(1) num2 = daf.count(2) num3 = daf.count(3) num = max(num1, num2, num3) print(n - num) ```
output
1
69,386
12
138,773
Provide tags and a correct Python 3 solution for this coding contest problem. There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≀ n ≀ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≀ ai ≀ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
instruction
0
69,387
12
138,774
Tags: implementation Correct Solution: ``` def calculate(list1): ones=0 twos=0 threes=0 for i in list1: if i==1: ones=ones+1 elif i==2: twos= twos+1 else: threes += 1 if (ones>twos and ones> threes): return 1 elif (twos>ones and twos>threes): return 2 elif (threes>ones and threes>twos): return 3 elif (ones==threes): return 3 elif (twos==threes): return 2 elif(ones==twos): return 1 N=int(input()) numbers=[] replacements=0 numbers =list(map(int, input().split()[:N])) most= calculate(numbers) for i in range(N): if numbers[i]!= most: numbers[i] = most replacements+=1 print(replacements) ```
output
1
69,387
12
138,775
Provide tags and a correct Python 3 solution for this coding contest problem. Mishka got an integer array a of length n as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: * Replace each occurrence of 1 in the array a with 2; * Replace each occurrence of 2 in the array a with 1; * Replace each occurrence of 3 in the array a with 4; * Replace each occurrence of 4 in the array a with 3; * Replace each occurrence of 5 in the array a with 6; * Replace each occurrence of 6 in the array a with 5; * ... * Replace each occurrence of 10^9 - 1 in the array a with 10^9; * Replace each occurrence of 10^9 in the array a with 10^9 - 1. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers (2i - 1, 2i) for each i ∈\{1, 2, …, 5 β‹… 10^8\} as described above. For example, for the array a = [1, 2, 4, 5, 10], the following sequence of arrays represents the algorithm: [1, 2, 4, 5, 10] β†’ (replace all occurrences of 1 with 2) β†’ [2, 2, 4, 5, 10] β†’ (replace all occurrences of 2 with 1) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 3 with 4) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 4 with 3) β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 5 with 6) β†’ [1, 1, 3, 6, 10] β†’ (replace all occurrences of 6 with 5) β†’ [1, 1, 3, 5, 10] β†’ ... β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 10 with 9) β†’ [1, 1, 3, 5, 9]. The later steps of the algorithm do not change the array. Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. Input The first line of the input contains one integer number n (1 ≀ n ≀ 1000) β€” the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. Output Print n integers β€” b_1, b_2, ..., b_n, where b_i is the final value of the i-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array a. Note that you cannot change the order of elements in the array. Examples Input 5 1 2 4 5 10 Output 1 1 3 5 9 Input 10 10000 10 50605065 1 5 89 5 999999999 60506056 1000000000 Output 9999 9 50605065 1 5 89 5 999999999 60506055 999999999 Note The first example is described in the problem statement.
instruction
0
69,808
12
139,616
Tags: implementation Correct Solution: ``` n=int(input()) l=list(map(int,input().split())) z=[] for i in l: if i%2!=0: z.append(i) else: z.append(i-1) print(*z) ```
output
1
69,808
12
139,617
Provide tags and a correct Python 3 solution for this coding contest problem. Mishka got an integer array a of length n as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: * Replace each occurrence of 1 in the array a with 2; * Replace each occurrence of 2 in the array a with 1; * Replace each occurrence of 3 in the array a with 4; * Replace each occurrence of 4 in the array a with 3; * Replace each occurrence of 5 in the array a with 6; * Replace each occurrence of 6 in the array a with 5; * ... * Replace each occurrence of 10^9 - 1 in the array a with 10^9; * Replace each occurrence of 10^9 in the array a with 10^9 - 1. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers (2i - 1, 2i) for each i ∈\{1, 2, …, 5 β‹… 10^8\} as described above. For example, for the array a = [1, 2, 4, 5, 10], the following sequence of arrays represents the algorithm: [1, 2, 4, 5, 10] β†’ (replace all occurrences of 1 with 2) β†’ [2, 2, 4, 5, 10] β†’ (replace all occurrences of 2 with 1) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 3 with 4) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 4 with 3) β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 5 with 6) β†’ [1, 1, 3, 6, 10] β†’ (replace all occurrences of 6 with 5) β†’ [1, 1, 3, 5, 10] β†’ ... β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 10 with 9) β†’ [1, 1, 3, 5, 9]. The later steps of the algorithm do not change the array. Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. Input The first line of the input contains one integer number n (1 ≀ n ≀ 1000) β€” the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. Output Print n integers β€” b_1, b_2, ..., b_n, where b_i is the final value of the i-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array a. Note that you cannot change the order of elements in the array. Examples Input 5 1 2 4 5 10 Output 1 1 3 5 9 Input 10 10000 10 50605065 1 5 89 5 999999999 60506056 1000000000 Output 9999 9 50605065 1 5 89 5 999999999 60506055 999999999 Note The first example is described in the problem statement.
instruction
0
69,809
12
139,618
Tags: implementation Correct Solution: ``` import sys # read number of examples n = int(sys.stdin.readline()) a = [int(i) for i in sys.stdin.readline().split()] assert n == len(a) print(" ".join([str(x if x % 2 else x - 1) for x in a])) ```
output
1
69,809
12
139,619
Provide tags and a correct Python 3 solution for this coding contest problem. Mishka got an integer array a of length n as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: * Replace each occurrence of 1 in the array a with 2; * Replace each occurrence of 2 in the array a with 1; * Replace each occurrence of 3 in the array a with 4; * Replace each occurrence of 4 in the array a with 3; * Replace each occurrence of 5 in the array a with 6; * Replace each occurrence of 6 in the array a with 5; * ... * Replace each occurrence of 10^9 - 1 in the array a with 10^9; * Replace each occurrence of 10^9 in the array a with 10^9 - 1. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers (2i - 1, 2i) for each i ∈\{1, 2, …, 5 β‹… 10^8\} as described above. For example, for the array a = [1, 2, 4, 5, 10], the following sequence of arrays represents the algorithm: [1, 2, 4, 5, 10] β†’ (replace all occurrences of 1 with 2) β†’ [2, 2, 4, 5, 10] β†’ (replace all occurrences of 2 with 1) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 3 with 4) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 4 with 3) β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 5 with 6) β†’ [1, 1, 3, 6, 10] β†’ (replace all occurrences of 6 with 5) β†’ [1, 1, 3, 5, 10] β†’ ... β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 10 with 9) β†’ [1, 1, 3, 5, 9]. The later steps of the algorithm do not change the array. Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. Input The first line of the input contains one integer number n (1 ≀ n ≀ 1000) β€” the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. Output Print n integers β€” b_1, b_2, ..., b_n, where b_i is the final value of the i-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array a. Note that you cannot change the order of elements in the array. Examples Input 5 1 2 4 5 10 Output 1 1 3 5 9 Input 10 10000 10 50605065 1 5 89 5 999999999 60506056 1000000000 Output 9999 9 50605065 1 5 89 5 999999999 60506055 999999999 Note The first example is described in the problem statement.
instruction
0
69,810
12
139,620
Tags: implementation Correct Solution: ``` n=int(input());print(*map(lambda x:int(x)+(int(x)&1)-1,input().split())) ```
output
1
69,810
12
139,621
Provide tags and a correct Python 3 solution for this coding contest problem. Mishka got an integer array a of length n as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: * Replace each occurrence of 1 in the array a with 2; * Replace each occurrence of 2 in the array a with 1; * Replace each occurrence of 3 in the array a with 4; * Replace each occurrence of 4 in the array a with 3; * Replace each occurrence of 5 in the array a with 6; * Replace each occurrence of 6 in the array a with 5; * ... * Replace each occurrence of 10^9 - 1 in the array a with 10^9; * Replace each occurrence of 10^9 in the array a with 10^9 - 1. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers (2i - 1, 2i) for each i ∈\{1, 2, …, 5 β‹… 10^8\} as described above. For example, for the array a = [1, 2, 4, 5, 10], the following sequence of arrays represents the algorithm: [1, 2, 4, 5, 10] β†’ (replace all occurrences of 1 with 2) β†’ [2, 2, 4, 5, 10] β†’ (replace all occurrences of 2 with 1) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 3 with 4) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 4 with 3) β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 5 with 6) β†’ [1, 1, 3, 6, 10] β†’ (replace all occurrences of 6 with 5) β†’ [1, 1, 3, 5, 10] β†’ ... β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 10 with 9) β†’ [1, 1, 3, 5, 9]. The later steps of the algorithm do not change the array. Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. Input The first line of the input contains one integer number n (1 ≀ n ≀ 1000) β€” the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. Output Print n integers β€” b_1, b_2, ..., b_n, where b_i is the final value of the i-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array a. Note that you cannot change the order of elements in the array. Examples Input 5 1 2 4 5 10 Output 1 1 3 5 9 Input 10 10000 10 50605065 1 5 89 5 999999999 60506056 1000000000 Output 9999 9 50605065 1 5 89 5 999999999 60506055 999999999 Note The first example is described in the problem statement.
instruction
0
69,811
12
139,622
Tags: implementation Correct Solution: ``` a = int(input()) c = [] b = list(map(int, input().split())) for i in range(a): if b[i] % 2 == 0: c.append(b[i]-1) else: c.append(b[i]) print(*c) ```
output
1
69,811
12
139,623
Provide tags and a correct Python 3 solution for this coding contest problem. Mishka got an integer array a of length n as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: * Replace each occurrence of 1 in the array a with 2; * Replace each occurrence of 2 in the array a with 1; * Replace each occurrence of 3 in the array a with 4; * Replace each occurrence of 4 in the array a with 3; * Replace each occurrence of 5 in the array a with 6; * Replace each occurrence of 6 in the array a with 5; * ... * Replace each occurrence of 10^9 - 1 in the array a with 10^9; * Replace each occurrence of 10^9 in the array a with 10^9 - 1. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers (2i - 1, 2i) for each i ∈\{1, 2, …, 5 β‹… 10^8\} as described above. For example, for the array a = [1, 2, 4, 5, 10], the following sequence of arrays represents the algorithm: [1, 2, 4, 5, 10] β†’ (replace all occurrences of 1 with 2) β†’ [2, 2, 4, 5, 10] β†’ (replace all occurrences of 2 with 1) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 3 with 4) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 4 with 3) β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 5 with 6) β†’ [1, 1, 3, 6, 10] β†’ (replace all occurrences of 6 with 5) β†’ [1, 1, 3, 5, 10] β†’ ... β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 10 with 9) β†’ [1, 1, 3, 5, 9]. The later steps of the algorithm do not change the array. Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. Input The first line of the input contains one integer number n (1 ≀ n ≀ 1000) β€” the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. Output Print n integers β€” b_1, b_2, ..., b_n, where b_i is the final value of the i-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array a. Note that you cannot change the order of elements in the array. Examples Input 5 1 2 4 5 10 Output 1 1 3 5 9 Input 10 10000 10 50605065 1 5 89 5 999999999 60506056 1000000000 Output 9999 9 50605065 1 5 89 5 999999999 60506055 999999999 Note The first example is described in the problem statement.
instruction
0
69,812
12
139,624
Tags: implementation Correct Solution: ``` n=int(input()) a=[int(x) for x in input().split()] for i in range(n): if a[i]%2==0: a[i]=a[i]-1 ans=" ".join(str(x) for x in a) print(ans) ```
output
1
69,812
12
139,625
Provide tags and a correct Python 3 solution for this coding contest problem. Mishka got an integer array a of length n as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: * Replace each occurrence of 1 in the array a with 2; * Replace each occurrence of 2 in the array a with 1; * Replace each occurrence of 3 in the array a with 4; * Replace each occurrence of 4 in the array a with 3; * Replace each occurrence of 5 in the array a with 6; * Replace each occurrence of 6 in the array a with 5; * ... * Replace each occurrence of 10^9 - 1 in the array a with 10^9; * Replace each occurrence of 10^9 in the array a with 10^9 - 1. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers (2i - 1, 2i) for each i ∈\{1, 2, …, 5 β‹… 10^8\} as described above. For example, for the array a = [1, 2, 4, 5, 10], the following sequence of arrays represents the algorithm: [1, 2, 4, 5, 10] β†’ (replace all occurrences of 1 with 2) β†’ [2, 2, 4, 5, 10] β†’ (replace all occurrences of 2 with 1) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 3 with 4) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 4 with 3) β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 5 with 6) β†’ [1, 1, 3, 6, 10] β†’ (replace all occurrences of 6 with 5) β†’ [1, 1, 3, 5, 10] β†’ ... β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 10 with 9) β†’ [1, 1, 3, 5, 9]. The later steps of the algorithm do not change the array. Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. Input The first line of the input contains one integer number n (1 ≀ n ≀ 1000) β€” the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. Output Print n integers β€” b_1, b_2, ..., b_n, where b_i is the final value of the i-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array a. Note that you cannot change the order of elements in the array. Examples Input 5 1 2 4 5 10 Output 1 1 3 5 9 Input 10 10000 10 50605065 1 5 89 5 999999999 60506056 1000000000 Output 9999 9 50605065 1 5 89 5 999999999 60506055 999999999 Note The first example is described in the problem statement.
instruction
0
69,813
12
139,626
Tags: implementation Correct Solution: ``` from sys import stdin, stdout input = lambda: stdin.readline().rstrip() write = stdout.write def main(): N = int(input()) A = tuple(map(int, input().split())) a = [0] * N for i, v in enumerate(A): if v % 2: a[i] = v else: a[i] = v - 1 print(*a) main() ```
output
1
69,813
12
139,627
Provide tags and a correct Python 3 solution for this coding contest problem. Mishka got an integer array a of length n as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: * Replace each occurrence of 1 in the array a with 2; * Replace each occurrence of 2 in the array a with 1; * Replace each occurrence of 3 in the array a with 4; * Replace each occurrence of 4 in the array a with 3; * Replace each occurrence of 5 in the array a with 6; * Replace each occurrence of 6 in the array a with 5; * ... * Replace each occurrence of 10^9 - 1 in the array a with 10^9; * Replace each occurrence of 10^9 in the array a with 10^9 - 1. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers (2i - 1, 2i) for each i ∈\{1, 2, …, 5 β‹… 10^8\} as described above. For example, for the array a = [1, 2, 4, 5, 10], the following sequence of arrays represents the algorithm: [1, 2, 4, 5, 10] β†’ (replace all occurrences of 1 with 2) β†’ [2, 2, 4, 5, 10] β†’ (replace all occurrences of 2 with 1) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 3 with 4) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 4 with 3) β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 5 with 6) β†’ [1, 1, 3, 6, 10] β†’ (replace all occurrences of 6 with 5) β†’ [1, 1, 3, 5, 10] β†’ ... β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 10 with 9) β†’ [1, 1, 3, 5, 9]. The later steps of the algorithm do not change the array. Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. Input The first line of the input contains one integer number n (1 ≀ n ≀ 1000) β€” the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. Output Print n integers β€” b_1, b_2, ..., b_n, where b_i is the final value of the i-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array a. Note that you cannot change the order of elements in the array. Examples Input 5 1 2 4 5 10 Output 1 1 3 5 9 Input 10 10000 10 50605065 1 5 89 5 999999999 60506056 1000000000 Output 9999 9 50605065 1 5 89 5 999999999 60506055 999999999 Note The first example is described in the problem statement.
instruction
0
69,814
12
139,628
Tags: implementation Correct Solution: ``` #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed Nov 14 13:35:44 2018 @author: abhinavvajpeyi) """ n=int(input()) a=[int(i) for i in input().strip().split(' ')] for i in range(n): if a[i]%2==0: a[i]=a[i]-1 print(*a) ```
output
1
69,814
12
139,629
Provide tags and a correct Python 3 solution for this coding contest problem. Mishka got an integer array a of length n as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: * Replace each occurrence of 1 in the array a with 2; * Replace each occurrence of 2 in the array a with 1; * Replace each occurrence of 3 in the array a with 4; * Replace each occurrence of 4 in the array a with 3; * Replace each occurrence of 5 in the array a with 6; * Replace each occurrence of 6 in the array a with 5; * ... * Replace each occurrence of 10^9 - 1 in the array a with 10^9; * Replace each occurrence of 10^9 in the array a with 10^9 - 1. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers (2i - 1, 2i) for each i ∈\{1, 2, …, 5 β‹… 10^8\} as described above. For example, for the array a = [1, 2, 4, 5, 10], the following sequence of arrays represents the algorithm: [1, 2, 4, 5, 10] β†’ (replace all occurrences of 1 with 2) β†’ [2, 2, 4, 5, 10] β†’ (replace all occurrences of 2 with 1) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 3 with 4) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 4 with 3) β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 5 with 6) β†’ [1, 1, 3, 6, 10] β†’ (replace all occurrences of 6 with 5) β†’ [1, 1, 3, 5, 10] β†’ ... β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 10 with 9) β†’ [1, 1, 3, 5, 9]. The later steps of the algorithm do not change the array. Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. Input The first line of the input contains one integer number n (1 ≀ n ≀ 1000) β€” the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. Output Print n integers β€” b_1, b_2, ..., b_n, where b_i is the final value of the i-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array a. Note that you cannot change the order of elements in the array. Examples Input 5 1 2 4 5 10 Output 1 1 3 5 9 Input 10 10000 10 50605065 1 5 89 5 999999999 60506056 1000000000 Output 9999 9 50605065 1 5 89 5 999999999 60506055 999999999 Note The first example is described in the problem statement.
instruction
0
69,815
12
139,630
Tags: implementation Correct Solution: ``` z,zz=input,lambda:list(map(int,z().split())) zzz=lambda:[int(i) for i in stdin.readline().split()] szz,graph,mod,szzz=lambda:sorted(zz()),{},10**9+7,lambda:sorted(zzz()) from string import * from re import * from collections import * from queue import * from sys import * from collections import * from math import * from heapq import * from itertools import * from bisect import * from collections import Counter as cc from math import factorial as f from bisect import bisect as bs from bisect import bisect_left as bsl from itertools import accumulate as ac from itertools import permutations as permu def lcd(xnum1,xnum2):return (xnum1*xnum2//gcd(xnum1,xnum2)) def prime(x): p=ceil(x**.5)+1 for i in range(2,p): if (x%i==0 and x!=2) or x==0:return 0 return 1 def dfs(u,visit,graph): visit[u]=True for i in graph[u]: if not visit[i]: dfs(i,visit,graph) ###########################---Test-Case---################################# """ """ ###########################---START-CODING---############################## num=1 #num=int(z()) for _ in range( num ): n=int(z()) for i in zzz(): if i%2==0: print(i-1) else:print(i) ```
output
1
69,815
12
139,631
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mishka got an integer array a of length n as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: * Replace each occurrence of 1 in the array a with 2; * Replace each occurrence of 2 in the array a with 1; * Replace each occurrence of 3 in the array a with 4; * Replace each occurrence of 4 in the array a with 3; * Replace each occurrence of 5 in the array a with 6; * Replace each occurrence of 6 in the array a with 5; * ... * Replace each occurrence of 10^9 - 1 in the array a with 10^9; * Replace each occurrence of 10^9 in the array a with 10^9 - 1. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers (2i - 1, 2i) for each i ∈\{1, 2, …, 5 β‹… 10^8\} as described above. For example, for the array a = [1, 2, 4, 5, 10], the following sequence of arrays represents the algorithm: [1, 2, 4, 5, 10] β†’ (replace all occurrences of 1 with 2) β†’ [2, 2, 4, 5, 10] β†’ (replace all occurrences of 2 with 1) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 3 with 4) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 4 with 3) β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 5 with 6) β†’ [1, 1, 3, 6, 10] β†’ (replace all occurrences of 6 with 5) β†’ [1, 1, 3, 5, 10] β†’ ... β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 10 with 9) β†’ [1, 1, 3, 5, 9]. The later steps of the algorithm do not change the array. Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. Input The first line of the input contains one integer number n (1 ≀ n ≀ 1000) β€” the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. Output Print n integers β€” b_1, b_2, ..., b_n, where b_i is the final value of the i-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array a. Note that you cannot change the order of elements in the array. Examples Input 5 1 2 4 5 10 Output 1 1 3 5 9 Input 10 10000 10 50605065 1 5 89 5 999999999 60506056 1000000000 Output 9999 9 50605065 1 5 89 5 999999999 60506055 999999999 Note The first example is described in the problem statement. Submitted Solution: ``` n = int(input()) a = list(map(int, input().split())) big = max(a) + 2 for i in range(len(a)): if a[i] % 2 == 0: a[i] -= 1 print(' '.join(map(str, a))) ```
instruction
0
69,816
12
139,632
Yes
output
1
69,816
12
139,633
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mishka got an integer array a of length n as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: * Replace each occurrence of 1 in the array a with 2; * Replace each occurrence of 2 in the array a with 1; * Replace each occurrence of 3 in the array a with 4; * Replace each occurrence of 4 in the array a with 3; * Replace each occurrence of 5 in the array a with 6; * Replace each occurrence of 6 in the array a with 5; * ... * Replace each occurrence of 10^9 - 1 in the array a with 10^9; * Replace each occurrence of 10^9 in the array a with 10^9 - 1. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers (2i - 1, 2i) for each i ∈\{1, 2, …, 5 β‹… 10^8\} as described above. For example, for the array a = [1, 2, 4, 5, 10], the following sequence of arrays represents the algorithm: [1, 2, 4, 5, 10] β†’ (replace all occurrences of 1 with 2) β†’ [2, 2, 4, 5, 10] β†’ (replace all occurrences of 2 with 1) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 3 with 4) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 4 with 3) β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 5 with 6) β†’ [1, 1, 3, 6, 10] β†’ (replace all occurrences of 6 with 5) β†’ [1, 1, 3, 5, 10] β†’ ... β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 10 with 9) β†’ [1, 1, 3, 5, 9]. The later steps of the algorithm do not change the array. Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. Input The first line of the input contains one integer number n (1 ≀ n ≀ 1000) β€” the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. Output Print n integers β€” b_1, b_2, ..., b_n, where b_i is the final value of the i-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array a. Note that you cannot change the order of elements in the array. Examples Input 5 1 2 4 5 10 Output 1 1 3 5 9 Input 10 10000 10 50605065 1 5 89 5 999999999 60506056 1000000000 Output 9999 9 50605065 1 5 89 5 999999999 60506055 999999999 Note The first example is described in the problem statement. Submitted Solution: ``` def zamena(lst): for i in range(len(lst)): if lst[i] == 1: continue elif lst[i] % 2 == 0: lst[i] -= 1 elif lst[i] % 2 != 0: continue return lst n = int(input()) a = [int(i) for i in input().split()] print(*zamena(a)) ```
instruction
0
69,817
12
139,634
Yes
output
1
69,817
12
139,635
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mishka got an integer array a of length n as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: * Replace each occurrence of 1 in the array a with 2; * Replace each occurrence of 2 in the array a with 1; * Replace each occurrence of 3 in the array a with 4; * Replace each occurrence of 4 in the array a with 3; * Replace each occurrence of 5 in the array a with 6; * Replace each occurrence of 6 in the array a with 5; * ... * Replace each occurrence of 10^9 - 1 in the array a with 10^9; * Replace each occurrence of 10^9 in the array a with 10^9 - 1. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers (2i - 1, 2i) for each i ∈\{1, 2, …, 5 β‹… 10^8\} as described above. For example, for the array a = [1, 2, 4, 5, 10], the following sequence of arrays represents the algorithm: [1, 2, 4, 5, 10] β†’ (replace all occurrences of 1 with 2) β†’ [2, 2, 4, 5, 10] β†’ (replace all occurrences of 2 with 1) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 3 with 4) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 4 with 3) β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 5 with 6) β†’ [1, 1, 3, 6, 10] β†’ (replace all occurrences of 6 with 5) β†’ [1, 1, 3, 5, 10] β†’ ... β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 10 with 9) β†’ [1, 1, 3, 5, 9]. The later steps of the algorithm do not change the array. Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. Input The first line of the input contains one integer number n (1 ≀ n ≀ 1000) β€” the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. Output Print n integers β€” b_1, b_2, ..., b_n, where b_i is the final value of the i-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array a. Note that you cannot change the order of elements in the array. Examples Input 5 1 2 4 5 10 Output 1 1 3 5 9 Input 10 10000 10 50605065 1 5 89 5 999999999 60506056 1000000000 Output 9999 9 50605065 1 5 89 5 999999999 60506055 999999999 Note The first example is described in the problem statement. Submitted Solution: ``` n = int(input()) x = list(map(int, (input().split()))) for ind in range(n): if (x[ind] % 2 == 0): x [ind] -= 1 print(" ".join(str (i) for i in x)) ```
instruction
0
69,818
12
139,636
Yes
output
1
69,818
12
139,637
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mishka got an integer array a of length n as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: * Replace each occurrence of 1 in the array a with 2; * Replace each occurrence of 2 in the array a with 1; * Replace each occurrence of 3 in the array a with 4; * Replace each occurrence of 4 in the array a with 3; * Replace each occurrence of 5 in the array a with 6; * Replace each occurrence of 6 in the array a with 5; * ... * Replace each occurrence of 10^9 - 1 in the array a with 10^9; * Replace each occurrence of 10^9 in the array a with 10^9 - 1. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers (2i - 1, 2i) for each i ∈\{1, 2, …, 5 β‹… 10^8\} as described above. For example, for the array a = [1, 2, 4, 5, 10], the following sequence of arrays represents the algorithm: [1, 2, 4, 5, 10] β†’ (replace all occurrences of 1 with 2) β†’ [2, 2, 4, 5, 10] β†’ (replace all occurrences of 2 with 1) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 3 with 4) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 4 with 3) β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 5 with 6) β†’ [1, 1, 3, 6, 10] β†’ (replace all occurrences of 6 with 5) β†’ [1, 1, 3, 5, 10] β†’ ... β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 10 with 9) β†’ [1, 1, 3, 5, 9]. The later steps of the algorithm do not change the array. Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. Input The first line of the input contains one integer number n (1 ≀ n ≀ 1000) β€” the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. Output Print n integers β€” b_1, b_2, ..., b_n, where b_i is the final value of the i-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array a. Note that you cannot change the order of elements in the array. Examples Input 5 1 2 4 5 10 Output 1 1 3 5 9 Input 10 10000 10 50605065 1 5 89 5 999999999 60506056 1000000000 Output 9999 9 50605065 1 5 89 5 999999999 60506055 999999999 Note The first example is described in the problem statement. Submitted Solution: ``` n = int(input()) a = [int(i) for i in input().split()] res = "" for i in a: if i%2: res += str(i)+" " else: res += str(i-1)+" " print(res) ```
instruction
0
69,819
12
139,638
Yes
output
1
69,819
12
139,639
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mishka got an integer array a of length n as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: * Replace each occurrence of 1 in the array a with 2; * Replace each occurrence of 2 in the array a with 1; * Replace each occurrence of 3 in the array a with 4; * Replace each occurrence of 4 in the array a with 3; * Replace each occurrence of 5 in the array a with 6; * Replace each occurrence of 6 in the array a with 5; * ... * Replace each occurrence of 10^9 - 1 in the array a with 10^9; * Replace each occurrence of 10^9 in the array a with 10^9 - 1. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers (2i - 1, 2i) for each i ∈\{1, 2, …, 5 β‹… 10^8\} as described above. For example, for the array a = [1, 2, 4, 5, 10], the following sequence of arrays represents the algorithm: [1, 2, 4, 5, 10] β†’ (replace all occurrences of 1 with 2) β†’ [2, 2, 4, 5, 10] β†’ (replace all occurrences of 2 with 1) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 3 with 4) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 4 with 3) β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 5 with 6) β†’ [1, 1, 3, 6, 10] β†’ (replace all occurrences of 6 with 5) β†’ [1, 1, 3, 5, 10] β†’ ... β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 10 with 9) β†’ [1, 1, 3, 5, 9]. The later steps of the algorithm do not change the array. Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. Input The first line of the input contains one integer number n (1 ≀ n ≀ 1000) β€” the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. Output Print n integers β€” b_1, b_2, ..., b_n, where b_i is the final value of the i-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array a. Note that you cannot change the order of elements in the array. Examples Input 5 1 2 4 5 10 Output 1 1 3 5 9 Input 10 10000 10 50605065 1 5 89 5 999999999 60506056 1000000000 Output 9999 9 50605065 1 5 89 5 999999999 60506055 999999999 Note The first example is described in the problem statement. Submitted Solution: ``` n = int(input()) a = list(map(int, input().split())) for i in a: if i %2 == 0: i-=1 print(*a) ```
instruction
0
69,820
12
139,640
No
output
1
69,820
12
139,641
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mishka got an integer array a of length n as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: * Replace each occurrence of 1 in the array a with 2; * Replace each occurrence of 2 in the array a with 1; * Replace each occurrence of 3 in the array a with 4; * Replace each occurrence of 4 in the array a with 3; * Replace each occurrence of 5 in the array a with 6; * Replace each occurrence of 6 in the array a with 5; * ... * Replace each occurrence of 10^9 - 1 in the array a with 10^9; * Replace each occurrence of 10^9 in the array a with 10^9 - 1. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers (2i - 1, 2i) for each i ∈\{1, 2, …, 5 β‹… 10^8\} as described above. For example, for the array a = [1, 2, 4, 5, 10], the following sequence of arrays represents the algorithm: [1, 2, 4, 5, 10] β†’ (replace all occurrences of 1 with 2) β†’ [2, 2, 4, 5, 10] β†’ (replace all occurrences of 2 with 1) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 3 with 4) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 4 with 3) β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 5 with 6) β†’ [1, 1, 3, 6, 10] β†’ (replace all occurrences of 6 with 5) β†’ [1, 1, 3, 5, 10] β†’ ... β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 10 with 9) β†’ [1, 1, 3, 5, 9]. The later steps of the algorithm do not change the array. Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. Input The first line of the input contains one integer number n (1 ≀ n ≀ 1000) β€” the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. Output Print n integers β€” b_1, b_2, ..., b_n, where b_i is the final value of the i-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array a. Note that you cannot change the order of elements in the array. Examples Input 5 1 2 4 5 10 Output 1 1 3 5 9 Input 10 10000 10 50605065 1 5 89 5 999999999 60506056 1000000000 Output 9999 9 50605065 1 5 89 5 999999999 60506055 999999999 Note The first example is described in the problem statement. Submitted Solution: ``` x=input() ary=input() arr=ary.split(' ') for i in range(int(x)): if int(arr[i])%2==0: req=str(int(arr[i])-1) ary=ary.replace(arr[i],req) print(ary) ```
instruction
0
69,821
12
139,642
No
output
1
69,821
12
139,643
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mishka got an integer array a of length n as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: * Replace each occurrence of 1 in the array a with 2; * Replace each occurrence of 2 in the array a with 1; * Replace each occurrence of 3 in the array a with 4; * Replace each occurrence of 4 in the array a with 3; * Replace each occurrence of 5 in the array a with 6; * Replace each occurrence of 6 in the array a with 5; * ... * Replace each occurrence of 10^9 - 1 in the array a with 10^9; * Replace each occurrence of 10^9 in the array a with 10^9 - 1. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers (2i - 1, 2i) for each i ∈\{1, 2, …, 5 β‹… 10^8\} as described above. For example, for the array a = [1, 2, 4, 5, 10], the following sequence of arrays represents the algorithm: [1, 2, 4, 5, 10] β†’ (replace all occurrences of 1 with 2) β†’ [2, 2, 4, 5, 10] β†’ (replace all occurrences of 2 with 1) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 3 with 4) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 4 with 3) β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 5 with 6) β†’ [1, 1, 3, 6, 10] β†’ (replace all occurrences of 6 with 5) β†’ [1, 1, 3, 5, 10] β†’ ... β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 10 with 9) β†’ [1, 1, 3, 5, 9]. The later steps of the algorithm do not change the array. Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. Input The first line of the input contains one integer number n (1 ≀ n ≀ 1000) β€” the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. Output Print n integers β€” b_1, b_2, ..., b_n, where b_i is the final value of the i-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array a. Note that you cannot change the order of elements in the array. Examples Input 5 1 2 4 5 10 Output 1 1 3 5 9 Input 10 10000 10 50605065 1 5 89 5 999999999 60506056 1000000000 Output 9999 9 50605065 1 5 89 5 999999999 60506055 999999999 Note The first example is described in the problem statement. Submitted Solution: ``` def replace_all(lst, a, b): for i in range(len(lst)): if lst[i] == a: lst[i] = b return lst n = int(input()) x = [int(i) for i in input().split()] for i in range(min(x), max(x)): if 2*i-1 in x or 2*i in x: replace_all(x, 2*i-1, 2*i) replace_all(x, 2*i, 2*i-1) print(x) ```
instruction
0
69,822
12
139,644
No
output
1
69,822
12
139,645
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mishka got an integer array a of length n as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: * Replace each occurrence of 1 in the array a with 2; * Replace each occurrence of 2 in the array a with 1; * Replace each occurrence of 3 in the array a with 4; * Replace each occurrence of 4 in the array a with 3; * Replace each occurrence of 5 in the array a with 6; * Replace each occurrence of 6 in the array a with 5; * ... * Replace each occurrence of 10^9 - 1 in the array a with 10^9; * Replace each occurrence of 10^9 in the array a with 10^9 - 1. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers (2i - 1, 2i) for each i ∈\{1, 2, …, 5 β‹… 10^8\} as described above. For example, for the array a = [1, 2, 4, 5, 10], the following sequence of arrays represents the algorithm: [1, 2, 4, 5, 10] β†’ (replace all occurrences of 1 with 2) β†’ [2, 2, 4, 5, 10] β†’ (replace all occurrences of 2 with 1) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 3 with 4) β†’ [1, 1, 4, 5, 10] β†’ (replace all occurrences of 4 with 3) β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 5 with 6) β†’ [1, 1, 3, 6, 10] β†’ (replace all occurrences of 6 with 5) β†’ [1, 1, 3, 5, 10] β†’ ... β†’ [1, 1, 3, 5, 10] β†’ (replace all occurrences of 10 with 9) β†’ [1, 1, 3, 5, 9]. The later steps of the algorithm do not change the array. Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. Input The first line of the input contains one integer number n (1 ≀ n ≀ 1000) β€” the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. Output Print n integers β€” b_1, b_2, ..., b_n, where b_i is the final value of the i-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array a. Note that you cannot change the order of elements in the array. Examples Input 5 1 2 4 5 10 Output 1 1 3 5 9 Input 10 10000 10 50605065 1 5 89 5 999999999 60506056 1000000000 Output 9999 9 50605065 1 5 89 5 999999999 60506055 999999999 Note The first example is described in the problem statement. Submitted Solution: ``` # # import sys # # sys.stdin=open("input.in","r") # sys.stdout=open("output.out","w") # #print(hex(a)) # #print(bin(a)) # #print(oct(a)) #print(a|b) #print(a&b) #print(a^b) # s,v1,v2,t1,t2=map(int,input().split()) # first=v1*s+2*t1 # second=v2*s+2*t2 # if first<second: # print("First") # else: # if first>second: # print("Second") # else: # print("Friendship") N=int(input()) A=list(map(int,input().split())) L=list(A) for i in range(N): if A[i]%2==0: x=A[i]-1 else: x=A[i]+1 for j in range(N): if A[i]==L[j]: L[j]=x print(*L) ```
instruction
0
69,823
12
139,646
No
output
1
69,823
12
139,647
Provide tags and a correct Python 3 solution for this coding contest problem. An array b is called to be a subarray of a if it forms a continuous subsequence of a, that is, if it is equal to a_l, a_{l + 1}, …, a_r for some l, r. Suppose m is some known constant. For any array, having m or more elements, let's define it's beauty as the sum of m largest elements of that array. For example: * For array x = [4, 3, 1, 5, 2] and m = 3, the 3 largest elements of x are 5, 4 and 3, so the beauty of x is 5 + 4 + 3 = 12. * For array x = [10, 10, 10] and m = 2, the beauty of x is 10 + 10 = 20. You are given an array a_1, a_2, …, a_n, the value of the said constant m and an integer k. Your need to split the array a into exactly k subarrays such that: * Each element from a belongs to exactly one subarray. * Each subarray has at least m elements. * The sum of all beauties of k subarrays is maximum possible. Input The first line contains three integers n, m and k (2 ≀ n ≀ 2 β‹… 10^5, 1 ≀ m, 2 ≀ k, m β‹… k ≀ n) β€” the number of elements in a, the constant m in the definition of beauty and the number of subarrays to split to. The second line contains n integers a_1, a_2, …, a_n (-10^9 ≀ a_i ≀ 10^9). Output In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition. In the second line, print k-1 integers p_1, p_2, …, p_{k-1} (1 ≀ p_1 < p_2 < … < p_{k-1} < n) representing the partition of the array, in which: * All elements with indices from 1 to p_1 belong to the first subarray. * All elements with indices from p_1 + 1 to p_2 belong to the second subarray. * …. * All elements with indices from p_{k-1} + 1 to n belong to the last, k-th subarray. If there are several optimal partitions, print any of them. Examples Input 9 2 3 5 2 5 2 4 1 1 3 2 Output 21 3 5 Input 6 1 4 4 1 3 2 2 3 Output 12 1 3 5 Input 2 1 2 -1000000000 1000000000 Output 0 1 Note In the first example, one of the optimal partitions is [5, 2, 5], [2, 4], [1, 1, 3, 2]. * The beauty of the subarray [5, 2, 5] is 5 + 5 = 10. * The beauty of the subarray [2, 4] is 2 + 4 = 6. * The beauty of the subarray [1, 1, 3, 2] is 3 + 2 = 5. The sum of their beauties is 10 + 6 + 5 = 21. In the second example, one optimal partition is [4], [1, 3], [2, 2], [3].
instruction
0
69,872
12
139,744
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` n,m,k=map(int,input().split()) arr=list(map(int,input().split())) arr1=sorted(arr);a=arr1[-m*k:];d={} for i in a:d[i]=d.get(i,0)+1 print(sum(a));p=0;t=0 #print(a) for i in range(n): # print(arr[i],i) if arr[i] in d: d[arr[i]]-=1;t+=1 if d[arr[i]]==0:del d[arr[i]] if t==m:t=0;p+=1;print(i+1,end=" ") if p==k-1:break ```
output
1
69,872
12
139,745
Provide tags and a correct Python 3 solution for this coding contest problem. An array b is called to be a subarray of a if it forms a continuous subsequence of a, that is, if it is equal to a_l, a_{l + 1}, …, a_r for some l, r. Suppose m is some known constant. For any array, having m or more elements, let's define it's beauty as the sum of m largest elements of that array. For example: * For array x = [4, 3, 1, 5, 2] and m = 3, the 3 largest elements of x are 5, 4 and 3, so the beauty of x is 5 + 4 + 3 = 12. * For array x = [10, 10, 10] and m = 2, the beauty of x is 10 + 10 = 20. You are given an array a_1, a_2, …, a_n, the value of the said constant m and an integer k. Your need to split the array a into exactly k subarrays such that: * Each element from a belongs to exactly one subarray. * Each subarray has at least m elements. * The sum of all beauties of k subarrays is maximum possible. Input The first line contains three integers n, m and k (2 ≀ n ≀ 2 β‹… 10^5, 1 ≀ m, 2 ≀ k, m β‹… k ≀ n) β€” the number of elements in a, the constant m in the definition of beauty and the number of subarrays to split to. The second line contains n integers a_1, a_2, …, a_n (-10^9 ≀ a_i ≀ 10^9). Output In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition. In the second line, print k-1 integers p_1, p_2, …, p_{k-1} (1 ≀ p_1 < p_2 < … < p_{k-1} < n) representing the partition of the array, in which: * All elements with indices from 1 to p_1 belong to the first subarray. * All elements with indices from p_1 + 1 to p_2 belong to the second subarray. * …. * All elements with indices from p_{k-1} + 1 to n belong to the last, k-th subarray. If there are several optimal partitions, print any of them. Examples Input 9 2 3 5 2 5 2 4 1 1 3 2 Output 21 3 5 Input 6 1 4 4 1 3 2 2 3 Output 12 1 3 5 Input 2 1 2 -1000000000 1000000000 Output 0 1 Note In the first example, one of the optimal partitions is [5, 2, 5], [2, 4], [1, 1, 3, 2]. * The beauty of the subarray [5, 2, 5] is 5 + 5 = 10. * The beauty of the subarray [2, 4] is 2 + 4 = 6. * The beauty of the subarray [1, 1, 3, 2] is 3 + 2 = 5. The sum of their beauties is 10 + 6 + 5 = 21. In the second example, one optimal partition is [4], [1, 3], [2, 2], [3].
instruction
0
69,873
12
139,746
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` l=input().split() n=int(l[0]) m=int(l[1]) k=int(l[2]) l=input().split() li=[int(i) for i in l] lfi=[] for i in range(n): lfi.append((int(l[i]),i)) lfi.sort() lfi.reverse() hashi=dict() summax=0 for i in range(m*k): summax+=lfi[i][0] hashi[lfi[i][1]]=1 lpart=[] tillnow=0 for i in range(n): if i in hashi: tillnow+=1 if(tillnow==m): lpart.append(i) tillnow=0 print(summax) for i in range(k-1): print(lpart[i]+1,end=" ") print() ```
output
1
69,873
12
139,747
Provide tags and a correct Python 3 solution for this coding contest problem. An array b is called to be a subarray of a if it forms a continuous subsequence of a, that is, if it is equal to a_l, a_{l + 1}, …, a_r for some l, r. Suppose m is some known constant. For any array, having m or more elements, let's define it's beauty as the sum of m largest elements of that array. For example: * For array x = [4, 3, 1, 5, 2] and m = 3, the 3 largest elements of x are 5, 4 and 3, so the beauty of x is 5 + 4 + 3 = 12. * For array x = [10, 10, 10] and m = 2, the beauty of x is 10 + 10 = 20. You are given an array a_1, a_2, …, a_n, the value of the said constant m and an integer k. Your need to split the array a into exactly k subarrays such that: * Each element from a belongs to exactly one subarray. * Each subarray has at least m elements. * The sum of all beauties of k subarrays is maximum possible. Input The first line contains three integers n, m and k (2 ≀ n ≀ 2 β‹… 10^5, 1 ≀ m, 2 ≀ k, m β‹… k ≀ n) β€” the number of elements in a, the constant m in the definition of beauty and the number of subarrays to split to. The second line contains n integers a_1, a_2, …, a_n (-10^9 ≀ a_i ≀ 10^9). Output In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition. In the second line, print k-1 integers p_1, p_2, …, p_{k-1} (1 ≀ p_1 < p_2 < … < p_{k-1} < n) representing the partition of the array, in which: * All elements with indices from 1 to p_1 belong to the first subarray. * All elements with indices from p_1 + 1 to p_2 belong to the second subarray. * …. * All elements with indices from p_{k-1} + 1 to n belong to the last, k-th subarray. If there are several optimal partitions, print any of them. Examples Input 9 2 3 5 2 5 2 4 1 1 3 2 Output 21 3 5 Input 6 1 4 4 1 3 2 2 3 Output 12 1 3 5 Input 2 1 2 -1000000000 1000000000 Output 0 1 Note In the first example, one of the optimal partitions is [5, 2, 5], [2, 4], [1, 1, 3, 2]. * The beauty of the subarray [5, 2, 5] is 5 + 5 = 10. * The beauty of the subarray [2, 4] is 2 + 4 = 6. * The beauty of the subarray [1, 1, 3, 2] is 3 + 2 = 5. The sum of their beauties is 10 + 6 + 5 = 21. In the second example, one optimal partition is [4], [1, 3], [2, 2], [3].
instruction
0
69,874
12
139,748
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` n,m,k=map(int,input().split()) a=list(map(int,input().split())) b=sorted(range(len(a)),key=lambda i:a[i],reverse=True) b=b[:m*k] b.sort() sum = 0 for i in b: sum+=a[i] print(sum) b=b[m-1:-1:m] for i in b: print(i+1,end=' ') print() ```
output
1
69,874
12
139,749
Provide tags and a correct Python 3 solution for this coding contest problem. An array b is called to be a subarray of a if it forms a continuous subsequence of a, that is, if it is equal to a_l, a_{l + 1}, …, a_r for some l, r. Suppose m is some known constant. For any array, having m or more elements, let's define it's beauty as the sum of m largest elements of that array. For example: * For array x = [4, 3, 1, 5, 2] and m = 3, the 3 largest elements of x are 5, 4 and 3, so the beauty of x is 5 + 4 + 3 = 12. * For array x = [10, 10, 10] and m = 2, the beauty of x is 10 + 10 = 20. You are given an array a_1, a_2, …, a_n, the value of the said constant m and an integer k. Your need to split the array a into exactly k subarrays such that: * Each element from a belongs to exactly one subarray. * Each subarray has at least m elements. * The sum of all beauties of k subarrays is maximum possible. Input The first line contains three integers n, m and k (2 ≀ n ≀ 2 β‹… 10^5, 1 ≀ m, 2 ≀ k, m β‹… k ≀ n) β€” the number of elements in a, the constant m in the definition of beauty and the number of subarrays to split to. The second line contains n integers a_1, a_2, …, a_n (-10^9 ≀ a_i ≀ 10^9). Output In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition. In the second line, print k-1 integers p_1, p_2, …, p_{k-1} (1 ≀ p_1 < p_2 < … < p_{k-1} < n) representing the partition of the array, in which: * All elements with indices from 1 to p_1 belong to the first subarray. * All elements with indices from p_1 + 1 to p_2 belong to the second subarray. * …. * All elements with indices from p_{k-1} + 1 to n belong to the last, k-th subarray. If there are several optimal partitions, print any of them. Examples Input 9 2 3 5 2 5 2 4 1 1 3 2 Output 21 3 5 Input 6 1 4 4 1 3 2 2 3 Output 12 1 3 5 Input 2 1 2 -1000000000 1000000000 Output 0 1 Note In the first example, one of the optimal partitions is [5, 2, 5], [2, 4], [1, 1, 3, 2]. * The beauty of the subarray [5, 2, 5] is 5 + 5 = 10. * The beauty of the subarray [2, 4] is 2 + 4 = 6. * The beauty of the subarray [1, 1, 3, 2] is 3 + 2 = 5. The sum of their beauties is 10 + 6 + 5 = 21. In the second example, one optimal partition is [4], [1, 3], [2, 2], [3].
instruction
0
69,875
12
139,750
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` n, m, k = map(int, input().split()) a = [-10 ** 9 - 1] + list(map(int, input().split())) v = sorted(enumerate(a), key=lambda x: x[1], reverse=True)[:m * k] v = list(sorted(v)) # print(v) print(sum(map(lambda x: x[1], v))) for i in range(m, m * k, m): # print(v[i]) print(v[i][0] - 1, end=' ') print() ```
output
1
69,875
12
139,751
Provide tags and a correct Python 3 solution for this coding contest problem. An array b is called to be a subarray of a if it forms a continuous subsequence of a, that is, if it is equal to a_l, a_{l + 1}, …, a_r for some l, r. Suppose m is some known constant. For any array, having m or more elements, let's define it's beauty as the sum of m largest elements of that array. For example: * For array x = [4, 3, 1, 5, 2] and m = 3, the 3 largest elements of x are 5, 4 and 3, so the beauty of x is 5 + 4 + 3 = 12. * For array x = [10, 10, 10] and m = 2, the beauty of x is 10 + 10 = 20. You are given an array a_1, a_2, …, a_n, the value of the said constant m and an integer k. Your need to split the array a into exactly k subarrays such that: * Each element from a belongs to exactly one subarray. * Each subarray has at least m elements. * The sum of all beauties of k subarrays is maximum possible. Input The first line contains three integers n, m and k (2 ≀ n ≀ 2 β‹… 10^5, 1 ≀ m, 2 ≀ k, m β‹… k ≀ n) β€” the number of elements in a, the constant m in the definition of beauty and the number of subarrays to split to. The second line contains n integers a_1, a_2, …, a_n (-10^9 ≀ a_i ≀ 10^9). Output In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition. In the second line, print k-1 integers p_1, p_2, …, p_{k-1} (1 ≀ p_1 < p_2 < … < p_{k-1} < n) representing the partition of the array, in which: * All elements with indices from 1 to p_1 belong to the first subarray. * All elements with indices from p_1 + 1 to p_2 belong to the second subarray. * …. * All elements with indices from p_{k-1} + 1 to n belong to the last, k-th subarray. If there are several optimal partitions, print any of them. Examples Input 9 2 3 5 2 5 2 4 1 1 3 2 Output 21 3 5 Input 6 1 4 4 1 3 2 2 3 Output 12 1 3 5 Input 2 1 2 -1000000000 1000000000 Output 0 1 Note In the first example, one of the optimal partitions is [5, 2, 5], [2, 4], [1, 1, 3, 2]. * The beauty of the subarray [5, 2, 5] is 5 + 5 = 10. * The beauty of the subarray [2, 4] is 2 + 4 = 6. * The beauty of the subarray [1, 1, 3, 2] is 3 + 2 = 5. The sum of their beauties is 10 + 6 + 5 = 21. In the second example, one optimal partition is [4], [1, 3], [2, 2], [3].
instruction
0
69,876
12
139,752
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` n,m,k=map(int,input().split()) arr=input() nums=[int (n) for n in arr.split()] s=list(enumerate(nums)) s.sort(key=lambda x:x[1],reverse=True) s=s[:m*k] sum=sum(x[1] for x in s) print(sum) s=[x[0] for x in s] s.sort() for i in range(m,m*k,m): print(s[i-1]+1,end=" ") ```
output
1
69,876
12
139,753
Provide tags and a correct Python 3 solution for this coding contest problem. An array b is called to be a subarray of a if it forms a continuous subsequence of a, that is, if it is equal to a_l, a_{l + 1}, …, a_r for some l, r. Suppose m is some known constant. For any array, having m or more elements, let's define it's beauty as the sum of m largest elements of that array. For example: * For array x = [4, 3, 1, 5, 2] and m = 3, the 3 largest elements of x are 5, 4 and 3, so the beauty of x is 5 + 4 + 3 = 12. * For array x = [10, 10, 10] and m = 2, the beauty of x is 10 + 10 = 20. You are given an array a_1, a_2, …, a_n, the value of the said constant m and an integer k. Your need to split the array a into exactly k subarrays such that: * Each element from a belongs to exactly one subarray. * Each subarray has at least m elements. * The sum of all beauties of k subarrays is maximum possible. Input The first line contains three integers n, m and k (2 ≀ n ≀ 2 β‹… 10^5, 1 ≀ m, 2 ≀ k, m β‹… k ≀ n) β€” the number of elements in a, the constant m in the definition of beauty and the number of subarrays to split to. The second line contains n integers a_1, a_2, …, a_n (-10^9 ≀ a_i ≀ 10^9). Output In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition. In the second line, print k-1 integers p_1, p_2, …, p_{k-1} (1 ≀ p_1 < p_2 < … < p_{k-1} < n) representing the partition of the array, in which: * All elements with indices from 1 to p_1 belong to the first subarray. * All elements with indices from p_1 + 1 to p_2 belong to the second subarray. * …. * All elements with indices from p_{k-1} + 1 to n belong to the last, k-th subarray. If there are several optimal partitions, print any of them. Examples Input 9 2 3 5 2 5 2 4 1 1 3 2 Output 21 3 5 Input 6 1 4 4 1 3 2 2 3 Output 12 1 3 5 Input 2 1 2 -1000000000 1000000000 Output 0 1 Note In the first example, one of the optimal partitions is [5, 2, 5], [2, 4], [1, 1, 3, 2]. * The beauty of the subarray [5, 2, 5] is 5 + 5 = 10. * The beauty of the subarray [2, 4] is 2 + 4 = 6. * The beauty of the subarray [1, 1, 3, 2] is 3 + 2 = 5. The sum of their beauties is 10 + 6 + 5 = 21. In the second example, one optimal partition is [4], [1, 3], [2, 2], [3].
instruction
0
69,877
12
139,754
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` n, m, k = tuple(map(int, input().split())) A = list(map(int, input().split())) B = A[:] B.sort() B = B[-(m * k):] maximal = {} summa = 0 for i in B: maximal[i] = maximal.get(i, 0) + 1 summa += i B = set(B) count_max = 0 counter = 0 print(summa) for i in range(n): if A[i] in B and maximal[A[i]] != 0: count_max += 1 maximal[A[i]] -= 1 if count_max == m: print(i + 1, end=' ') counter += 1 count_max = 0 if counter == k - 1: break ```
output
1
69,877
12
139,755
Provide tags and a correct Python 3 solution for this coding contest problem. An array b is called to be a subarray of a if it forms a continuous subsequence of a, that is, if it is equal to a_l, a_{l + 1}, …, a_r for some l, r. Suppose m is some known constant. For any array, having m or more elements, let's define it's beauty as the sum of m largest elements of that array. For example: * For array x = [4, 3, 1, 5, 2] and m = 3, the 3 largest elements of x are 5, 4 and 3, so the beauty of x is 5 + 4 + 3 = 12. * For array x = [10, 10, 10] and m = 2, the beauty of x is 10 + 10 = 20. You are given an array a_1, a_2, …, a_n, the value of the said constant m and an integer k. Your need to split the array a into exactly k subarrays such that: * Each element from a belongs to exactly one subarray. * Each subarray has at least m elements. * The sum of all beauties of k subarrays is maximum possible. Input The first line contains three integers n, m and k (2 ≀ n ≀ 2 β‹… 10^5, 1 ≀ m, 2 ≀ k, m β‹… k ≀ n) β€” the number of elements in a, the constant m in the definition of beauty and the number of subarrays to split to. The second line contains n integers a_1, a_2, …, a_n (-10^9 ≀ a_i ≀ 10^9). Output In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition. In the second line, print k-1 integers p_1, p_2, …, p_{k-1} (1 ≀ p_1 < p_2 < … < p_{k-1} < n) representing the partition of the array, in which: * All elements with indices from 1 to p_1 belong to the first subarray. * All elements with indices from p_1 + 1 to p_2 belong to the second subarray. * …. * All elements with indices from p_{k-1} + 1 to n belong to the last, k-th subarray. If there are several optimal partitions, print any of them. Examples Input 9 2 3 5 2 5 2 4 1 1 3 2 Output 21 3 5 Input 6 1 4 4 1 3 2 2 3 Output 12 1 3 5 Input 2 1 2 -1000000000 1000000000 Output 0 1 Note In the first example, one of the optimal partitions is [5, 2, 5], [2, 4], [1, 1, 3, 2]. * The beauty of the subarray [5, 2, 5] is 5 + 5 = 10. * The beauty of the subarray [2, 4] is 2 + 4 = 6. * The beauty of the subarray [1, 1, 3, 2] is 3 + 2 = 5. The sum of their beauties is 10 + 6 + 5 = 21. In the second example, one optimal partition is [4], [1, 3], [2, 2], [3].
instruction
0
69,878
12
139,756
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` n, m, k = [int(x) for x in input().split()] a = [int(x) for x in input().split()] b = [[i, j] for i, j in enumerate(a)] b.sort(key=lambda x: x[1], reverse=True) c = [False]*n sum_a = 0 for i in range(k * m): c[b[i][0]] = True sum_a += b[i][1] print(sum_a) cnt = 0 all_k = 1 for i in range(n): if c[i]: cnt += 1 if cnt == m and all_k < k: print(i + 1, end=' ') cnt = 0 all_k += 1 print() ```
output
1
69,878
12
139,757
Provide tags and a correct Python 3 solution for this coding contest problem. An array b is called to be a subarray of a if it forms a continuous subsequence of a, that is, if it is equal to a_l, a_{l + 1}, …, a_r for some l, r. Suppose m is some known constant. For any array, having m or more elements, let's define it's beauty as the sum of m largest elements of that array. For example: * For array x = [4, 3, 1, 5, 2] and m = 3, the 3 largest elements of x are 5, 4 and 3, so the beauty of x is 5 + 4 + 3 = 12. * For array x = [10, 10, 10] and m = 2, the beauty of x is 10 + 10 = 20. You are given an array a_1, a_2, …, a_n, the value of the said constant m and an integer k. Your need to split the array a into exactly k subarrays such that: * Each element from a belongs to exactly one subarray. * Each subarray has at least m elements. * The sum of all beauties of k subarrays is maximum possible. Input The first line contains three integers n, m and k (2 ≀ n ≀ 2 β‹… 10^5, 1 ≀ m, 2 ≀ k, m β‹… k ≀ n) β€” the number of elements in a, the constant m in the definition of beauty and the number of subarrays to split to. The second line contains n integers a_1, a_2, …, a_n (-10^9 ≀ a_i ≀ 10^9). Output In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition. In the second line, print k-1 integers p_1, p_2, …, p_{k-1} (1 ≀ p_1 < p_2 < … < p_{k-1} < n) representing the partition of the array, in which: * All elements with indices from 1 to p_1 belong to the first subarray. * All elements with indices from p_1 + 1 to p_2 belong to the second subarray. * …. * All elements with indices from p_{k-1} + 1 to n belong to the last, k-th subarray. If there are several optimal partitions, print any of them. Examples Input 9 2 3 5 2 5 2 4 1 1 3 2 Output 21 3 5 Input 6 1 4 4 1 3 2 2 3 Output 12 1 3 5 Input 2 1 2 -1000000000 1000000000 Output 0 1 Note In the first example, one of the optimal partitions is [5, 2, 5], [2, 4], [1, 1, 3, 2]. * The beauty of the subarray [5, 2, 5] is 5 + 5 = 10. * The beauty of the subarray [2, 4] is 2 + 4 = 6. * The beauty of the subarray [1, 1, 3, 2] is 3 + 2 = 5. The sum of their beauties is 10 + 6 + 5 = 21. In the second example, one optimal partition is [4], [1, 3], [2, 2], [3].
instruction
0
69,879
12
139,758
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` n, m, k = [int(x) for x in input().split()] a = [int(x) for x in input().split()] b = sorted(range(len(a)), key=lambda k: a[k]) b.reverse() b = b[:m*k] b.sort() sum = 0 # print(b) for i in b: sum += a[i] print(sum) b = b[m - 1:-1:m] for i in b: print(i + 1) ```
output
1
69,879
12
139,759
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. An array b is called to be a subarray of a if it forms a continuous subsequence of a, that is, if it is equal to a_l, a_{l + 1}, …, a_r for some l, r. Suppose m is some known constant. For any array, having m or more elements, let's define it's beauty as the sum of m largest elements of that array. For example: * For array x = [4, 3, 1, 5, 2] and m = 3, the 3 largest elements of x are 5, 4 and 3, so the beauty of x is 5 + 4 + 3 = 12. * For array x = [10, 10, 10] and m = 2, the beauty of x is 10 + 10 = 20. You are given an array a_1, a_2, …, a_n, the value of the said constant m and an integer k. Your need to split the array a into exactly k subarrays such that: * Each element from a belongs to exactly one subarray. * Each subarray has at least m elements. * The sum of all beauties of k subarrays is maximum possible. Input The first line contains three integers n, m and k (2 ≀ n ≀ 2 β‹… 10^5, 1 ≀ m, 2 ≀ k, m β‹… k ≀ n) β€” the number of elements in a, the constant m in the definition of beauty and the number of subarrays to split to. The second line contains n integers a_1, a_2, …, a_n (-10^9 ≀ a_i ≀ 10^9). Output In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition. In the second line, print k-1 integers p_1, p_2, …, p_{k-1} (1 ≀ p_1 < p_2 < … < p_{k-1} < n) representing the partition of the array, in which: * All elements with indices from 1 to p_1 belong to the first subarray. * All elements with indices from p_1 + 1 to p_2 belong to the second subarray. * …. * All elements with indices from p_{k-1} + 1 to n belong to the last, k-th subarray. If there are several optimal partitions, print any of them. Examples Input 9 2 3 5 2 5 2 4 1 1 3 2 Output 21 3 5 Input 6 1 4 4 1 3 2 2 3 Output 12 1 3 5 Input 2 1 2 -1000000000 1000000000 Output 0 1 Note In the first example, one of the optimal partitions is [5, 2, 5], [2, 4], [1, 1, 3, 2]. * The beauty of the subarray [5, 2, 5] is 5 + 5 = 10. * The beauty of the subarray [2, 4] is 2 + 4 = 6. * The beauty of the subarray [1, 1, 3, 2] is 3 + 2 = 5. The sum of their beauties is 10 + 6 + 5 = 21. In the second example, one optimal partition is [4], [1, 3], [2, 2], [3]. Submitted Solution: ``` n, m, k = map(int, input().split()) tab = map(int, input().split()) tab = [(t,i) for i, t in enumerate(tab)] tab.sort() want = [False for _ in range(n)] for _, i in tab[n - k*m:]: want[i] = True counter = 0 print(sum((t for t, i in tab if want[i]))) printed = 0 for i, w in enumerate(want): counter += w if counter == m: if i+1 != n: print(i+1, end=' ') printed += 1 counter = 0 if printed == k - 1: break ```
instruction
0
69,880
12
139,760
Yes
output
1
69,880
12
139,761
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. An array b is called to be a subarray of a if it forms a continuous subsequence of a, that is, if it is equal to a_l, a_{l + 1}, …, a_r for some l, r. Suppose m is some known constant. For any array, having m or more elements, let's define it's beauty as the sum of m largest elements of that array. For example: * For array x = [4, 3, 1, 5, 2] and m = 3, the 3 largest elements of x are 5, 4 and 3, so the beauty of x is 5 + 4 + 3 = 12. * For array x = [10, 10, 10] and m = 2, the beauty of x is 10 + 10 = 20. You are given an array a_1, a_2, …, a_n, the value of the said constant m and an integer k. Your need to split the array a into exactly k subarrays such that: * Each element from a belongs to exactly one subarray. * Each subarray has at least m elements. * The sum of all beauties of k subarrays is maximum possible. Input The first line contains three integers n, m and k (2 ≀ n ≀ 2 β‹… 10^5, 1 ≀ m, 2 ≀ k, m β‹… k ≀ n) β€” the number of elements in a, the constant m in the definition of beauty and the number of subarrays to split to. The second line contains n integers a_1, a_2, …, a_n (-10^9 ≀ a_i ≀ 10^9). Output In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition. In the second line, print k-1 integers p_1, p_2, …, p_{k-1} (1 ≀ p_1 < p_2 < … < p_{k-1} < n) representing the partition of the array, in which: * All elements with indices from 1 to p_1 belong to the first subarray. * All elements with indices from p_1 + 1 to p_2 belong to the second subarray. * …. * All elements with indices from p_{k-1} + 1 to n belong to the last, k-th subarray. If there are several optimal partitions, print any of them. Examples Input 9 2 3 5 2 5 2 4 1 1 3 2 Output 21 3 5 Input 6 1 4 4 1 3 2 2 3 Output 12 1 3 5 Input 2 1 2 -1000000000 1000000000 Output 0 1 Note In the first example, one of the optimal partitions is [5, 2, 5], [2, 4], [1, 1, 3, 2]. * The beauty of the subarray [5, 2, 5] is 5 + 5 = 10. * The beauty of the subarray [2, 4] is 2 + 4 = 6. * The beauty of the subarray [1, 1, 3, 2] is 3 + 2 = 5. The sum of their beauties is 10 + 6 + 5 = 21. In the second example, one optimal partition is [4], [1, 3], [2, 2], [3]. Submitted Solution: ``` import sys import math as mt import bisect input=sys.stdin.readline #t=int(input()) import collections t=1 p=10**9+7 def ncr_util(): inv[0]=inv[1]=1 fact[0]=fact[1]=1 for i in range(2,300001): inv[i]=(inv[i%p]*(p-p//i))%p for i in range(1,300001): inv[i]=(inv[i-1]*inv[i])%p fact[i]=(fact[i-1]*i)%p def solve(): l1=[] for i in l: l1.append(i) l1.sort(reverse=True) ans=sum(l1[:m*k]) j=0 ans1=[] d={} for i in range(m*k): d[l1[i]]=d.get(l1[i],0)+1 cnt=0 suma,suma1=0,0 for i in range(n): if d.get(l[i],0)!=0: d[l[i]]-=1 cnt+=1 #suma1+=l[i] if cnt==m and len(ans1)<k-1: ans1.append(i+1) cnt=0 print(ans) return ans1 for _ in range(t): #n=int(input()) #s=input() #n=int(input()) #n,m=(map(int,input().split())) #n1=n #a=int(input()) #b=int(input()) #x,y,z=map(int,input().split()) n,m,k=map(int,input().split()) #n=int(input()) #s=input() #s1=input() #p=input() l=list(map(int,input().split())) #l.sort(revrese=True) #l2=list(map(int,input().split())) #l=str(n) #l.sort(reverse=True) #l2.sort(reverse=True) #l1.sort(reverse=True) #print(ans) print(*solve()) ```
instruction
0
69,881
12
139,762
Yes
output
1
69,881
12
139,763
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. An array b is called to be a subarray of a if it forms a continuous subsequence of a, that is, if it is equal to a_l, a_{l + 1}, …, a_r for some l, r. Suppose m is some known constant. For any array, having m or more elements, let's define it's beauty as the sum of m largest elements of that array. For example: * For array x = [4, 3, 1, 5, 2] and m = 3, the 3 largest elements of x are 5, 4 and 3, so the beauty of x is 5 + 4 + 3 = 12. * For array x = [10, 10, 10] and m = 2, the beauty of x is 10 + 10 = 20. You are given an array a_1, a_2, …, a_n, the value of the said constant m and an integer k. Your need to split the array a into exactly k subarrays such that: * Each element from a belongs to exactly one subarray. * Each subarray has at least m elements. * The sum of all beauties of k subarrays is maximum possible. Input The first line contains three integers n, m and k (2 ≀ n ≀ 2 β‹… 10^5, 1 ≀ m, 2 ≀ k, m β‹… k ≀ n) β€” the number of elements in a, the constant m in the definition of beauty and the number of subarrays to split to. The second line contains n integers a_1, a_2, …, a_n (-10^9 ≀ a_i ≀ 10^9). Output In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition. In the second line, print k-1 integers p_1, p_2, …, p_{k-1} (1 ≀ p_1 < p_2 < … < p_{k-1} < n) representing the partition of the array, in which: * All elements with indices from 1 to p_1 belong to the first subarray. * All elements with indices from p_1 + 1 to p_2 belong to the second subarray. * …. * All elements with indices from p_{k-1} + 1 to n belong to the last, k-th subarray. If there are several optimal partitions, print any of them. Examples Input 9 2 3 5 2 5 2 4 1 1 3 2 Output 21 3 5 Input 6 1 4 4 1 3 2 2 3 Output 12 1 3 5 Input 2 1 2 -1000000000 1000000000 Output 0 1 Note In the first example, one of the optimal partitions is [5, 2, 5], [2, 4], [1, 1, 3, 2]. * The beauty of the subarray [5, 2, 5] is 5 + 5 = 10. * The beauty of the subarray [2, 4] is 2 + 4 = 6. * The beauty of the subarray [1, 1, 3, 2] is 3 + 2 = 5. The sum of their beauties is 10 + 6 + 5 = 21. In the second example, one optimal partition is [4], [1, 3], [2, 2], [3]. Submitted Solution: ``` n, m, k = map(int, input().split()) arr = enumerate(list(map(int, input().split())), 1) arr = sorted(arr, key=lambda x:x[1], reverse=True) ind = [arr[i][0] for i in range(m*k)] ind.sort() ans = [ind[i] for i in range(m-1, m*(k-1), m)] print(sum(arr[i][1] for i in range(m*k))) print(*ans) ```
instruction
0
69,882
12
139,764
Yes
output
1
69,882
12
139,765
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. An array b is called to be a subarray of a if it forms a continuous subsequence of a, that is, if it is equal to a_l, a_{l + 1}, …, a_r for some l, r. Suppose m is some known constant. For any array, having m or more elements, let's define it's beauty as the sum of m largest elements of that array. For example: * For array x = [4, 3, 1, 5, 2] and m = 3, the 3 largest elements of x are 5, 4 and 3, so the beauty of x is 5 + 4 + 3 = 12. * For array x = [10, 10, 10] and m = 2, the beauty of x is 10 + 10 = 20. You are given an array a_1, a_2, …, a_n, the value of the said constant m and an integer k. Your need to split the array a into exactly k subarrays such that: * Each element from a belongs to exactly one subarray. * Each subarray has at least m elements. * The sum of all beauties of k subarrays is maximum possible. Input The first line contains three integers n, m and k (2 ≀ n ≀ 2 β‹… 10^5, 1 ≀ m, 2 ≀ k, m β‹… k ≀ n) β€” the number of elements in a, the constant m in the definition of beauty and the number of subarrays to split to. The second line contains n integers a_1, a_2, …, a_n (-10^9 ≀ a_i ≀ 10^9). Output In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition. In the second line, print k-1 integers p_1, p_2, …, p_{k-1} (1 ≀ p_1 < p_2 < … < p_{k-1} < n) representing the partition of the array, in which: * All elements with indices from 1 to p_1 belong to the first subarray. * All elements with indices from p_1 + 1 to p_2 belong to the second subarray. * …. * All elements with indices from p_{k-1} + 1 to n belong to the last, k-th subarray. If there are several optimal partitions, print any of them. Examples Input 9 2 3 5 2 5 2 4 1 1 3 2 Output 21 3 5 Input 6 1 4 4 1 3 2 2 3 Output 12 1 3 5 Input 2 1 2 -1000000000 1000000000 Output 0 1 Note In the first example, one of the optimal partitions is [5, 2, 5], [2, 4], [1, 1, 3, 2]. * The beauty of the subarray [5, 2, 5] is 5 + 5 = 10. * The beauty of the subarray [2, 4] is 2 + 4 = 6. * The beauty of the subarray [1, 1, 3, 2] is 3 + 2 = 5. The sum of their beauties is 10 + 6 + 5 = 21. In the second example, one optimal partition is [4], [1, 3], [2, 2], [3]. Submitted Solution: ``` n,m,k = map(int,input().split()) A = list(map(int,input().split())) a = list(enumerate(A)) a.sort(key = lambda x: x[1]) f=[0]*(n+100) ans = 0 ANS = [] for i in range(n-m*k): f[a[i][0]] = 1 # print(a[i][0]) t = 0 tt = 0 for i in range(n): t+=1 ans += A[i] if f[i] == 1: t-=1 ans -= A[i] if t == m and tt != k: ANS.append(i+1) t = 0 tt+=1 # print(ans) print(ans) for i in ANS[:-1]: print(i,end=" ") ```
instruction
0
69,883
12
139,766
Yes
output
1
69,883
12
139,767
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. An array b is called to be a subarray of a if it forms a continuous subsequence of a, that is, if it is equal to a_l, a_{l + 1}, …, a_r for some l, r. Suppose m is some known constant. For any array, having m or more elements, let's define it's beauty as the sum of m largest elements of that array. For example: * For array x = [4, 3, 1, 5, 2] and m = 3, the 3 largest elements of x are 5, 4 and 3, so the beauty of x is 5 + 4 + 3 = 12. * For array x = [10, 10, 10] and m = 2, the beauty of x is 10 + 10 = 20. You are given an array a_1, a_2, …, a_n, the value of the said constant m and an integer k. Your need to split the array a into exactly k subarrays such that: * Each element from a belongs to exactly one subarray. * Each subarray has at least m elements. * The sum of all beauties of k subarrays is maximum possible. Input The first line contains three integers n, m and k (2 ≀ n ≀ 2 β‹… 10^5, 1 ≀ m, 2 ≀ k, m β‹… k ≀ n) β€” the number of elements in a, the constant m in the definition of beauty and the number of subarrays to split to. The second line contains n integers a_1, a_2, …, a_n (-10^9 ≀ a_i ≀ 10^9). Output In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition. In the second line, print k-1 integers p_1, p_2, …, p_{k-1} (1 ≀ p_1 < p_2 < … < p_{k-1} < n) representing the partition of the array, in which: * All elements with indices from 1 to p_1 belong to the first subarray. * All elements with indices from p_1 + 1 to p_2 belong to the second subarray. * …. * All elements with indices from p_{k-1} + 1 to n belong to the last, k-th subarray. If there are several optimal partitions, print any of them. Examples Input 9 2 3 5 2 5 2 4 1 1 3 2 Output 21 3 5 Input 6 1 4 4 1 3 2 2 3 Output 12 1 3 5 Input 2 1 2 -1000000000 1000000000 Output 0 1 Note In the first example, one of the optimal partitions is [5, 2, 5], [2, 4], [1, 1, 3, 2]. * The beauty of the subarray [5, 2, 5] is 5 + 5 = 10. * The beauty of the subarray [2, 4] is 2 + 4 = 6. * The beauty of the subarray [1, 1, 3, 2] is 3 + 2 = 5. The sum of their beauties is 10 + 6 + 5 = 21. In the second example, one optimal partition is [4], [1, 3], [2, 2], [3]. Submitted Solution: ``` def main(): arr=input().split() n=int(arr[0]) m=int(arr[1]) k=int(arr[2]) arr=input().split() store=[] for x in range(n): store.append(arr[x]) store.sort() bound=store[-(m*k)] count=0 total=0 for x in range(-(m*k),0): if store[x]==bound: count+=1 total+=int(store[x]) print(total) total=0 subcount=0 for x in range(n-1): if arr[x]>bound: subcount+=1 total+=int(arr[x]) elif arr[x]==bound and count>0: subcount+=1 count-=1 total+=int(arr[x]) if subcount==m: subcount=0 print(x+1,end=" ") main() ```
instruction
0
69,884
12
139,768
No
output
1
69,884
12
139,769
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. An array b is called to be a subarray of a if it forms a continuous subsequence of a, that is, if it is equal to a_l, a_{l + 1}, …, a_r for some l, r. Suppose m is some known constant. For any array, having m or more elements, let's define it's beauty as the sum of m largest elements of that array. For example: * For array x = [4, 3, 1, 5, 2] and m = 3, the 3 largest elements of x are 5, 4 and 3, so the beauty of x is 5 + 4 + 3 = 12. * For array x = [10, 10, 10] and m = 2, the beauty of x is 10 + 10 = 20. You are given an array a_1, a_2, …, a_n, the value of the said constant m and an integer k. Your need to split the array a into exactly k subarrays such that: * Each element from a belongs to exactly one subarray. * Each subarray has at least m elements. * The sum of all beauties of k subarrays is maximum possible. Input The first line contains three integers n, m and k (2 ≀ n ≀ 2 β‹… 10^5, 1 ≀ m, 2 ≀ k, m β‹… k ≀ n) β€” the number of elements in a, the constant m in the definition of beauty and the number of subarrays to split to. The second line contains n integers a_1, a_2, …, a_n (-10^9 ≀ a_i ≀ 10^9). Output In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition. In the second line, print k-1 integers p_1, p_2, …, p_{k-1} (1 ≀ p_1 < p_2 < … < p_{k-1} < n) representing the partition of the array, in which: * All elements with indices from 1 to p_1 belong to the first subarray. * All elements with indices from p_1 + 1 to p_2 belong to the second subarray. * …. * All elements with indices from p_{k-1} + 1 to n belong to the last, k-th subarray. If there are several optimal partitions, print any of them. Examples Input 9 2 3 5 2 5 2 4 1 1 3 2 Output 21 3 5 Input 6 1 4 4 1 3 2 2 3 Output 12 1 3 5 Input 2 1 2 -1000000000 1000000000 Output 0 1 Note In the first example, one of the optimal partitions is [5, 2, 5], [2, 4], [1, 1, 3, 2]. * The beauty of the subarray [5, 2, 5] is 5 + 5 = 10. * The beauty of the subarray [2, 4] is 2 + 4 = 6. * The beauty of the subarray [1, 1, 3, 2] is 3 + 2 = 5. The sum of their beauties is 10 + 6 + 5 = 21. In the second example, one optimal partition is [4], [1, 3], [2, 2], [3]. Submitted Solution: ``` n, m, k = map(int, input().split()) tab = map(int, input().split()) tab = [(t,i) for i, t in enumerate(tab)] tab.sort() want = [False for _ in range(n)] for _, i in tab[n - k*m:]: want[i] = True counter = 0 print(sum((t for t, i in tab if want[i]))) printed = 0 for i, w in enumerate(want): counter += w if counter == m: if i+1 != n: print(i+1, end=' ') printed += 1 counter = 0 if printed == k * m -1: break ```
instruction
0
69,885
12
139,770
No
output
1
69,885
12
139,771
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. An array b is called to be a subarray of a if it forms a continuous subsequence of a, that is, if it is equal to a_l, a_{l + 1}, …, a_r for some l, r. Suppose m is some known constant. For any array, having m or more elements, let's define it's beauty as the sum of m largest elements of that array. For example: * For array x = [4, 3, 1, 5, 2] and m = 3, the 3 largest elements of x are 5, 4 and 3, so the beauty of x is 5 + 4 + 3 = 12. * For array x = [10, 10, 10] and m = 2, the beauty of x is 10 + 10 = 20. You are given an array a_1, a_2, …, a_n, the value of the said constant m and an integer k. Your need to split the array a into exactly k subarrays such that: * Each element from a belongs to exactly one subarray. * Each subarray has at least m elements. * The sum of all beauties of k subarrays is maximum possible. Input The first line contains three integers n, m and k (2 ≀ n ≀ 2 β‹… 10^5, 1 ≀ m, 2 ≀ k, m β‹… k ≀ n) β€” the number of elements in a, the constant m in the definition of beauty and the number of subarrays to split to. The second line contains n integers a_1, a_2, …, a_n (-10^9 ≀ a_i ≀ 10^9). Output In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition. In the second line, print k-1 integers p_1, p_2, …, p_{k-1} (1 ≀ p_1 < p_2 < … < p_{k-1} < n) representing the partition of the array, in which: * All elements with indices from 1 to p_1 belong to the first subarray. * All elements with indices from p_1 + 1 to p_2 belong to the second subarray. * …. * All elements with indices from p_{k-1} + 1 to n belong to the last, k-th subarray. If there are several optimal partitions, print any of them. Examples Input 9 2 3 5 2 5 2 4 1 1 3 2 Output 21 3 5 Input 6 1 4 4 1 3 2 2 3 Output 12 1 3 5 Input 2 1 2 -1000000000 1000000000 Output 0 1 Note In the first example, one of the optimal partitions is [5, 2, 5], [2, 4], [1, 1, 3, 2]. * The beauty of the subarray [5, 2, 5] is 5 + 5 = 10. * The beauty of the subarray [2, 4] is 2 + 4 = 6. * The beauty of the subarray [1, 1, 3, 2] is 3 + 2 = 5. The sum of their beauties is 10 + 6 + 5 = 21. In the second example, one optimal partition is [4], [1, 3], [2, 2], [3]. Submitted Solution: ``` def solve(): n, m, k = list(map(int, input().split())) arr = list(map(int, input().split())) find = (sorted(arr)[-k*m:]) unique = set(find) print(sum(find)) if len(find) >= n: for i in range(m, n, k): print(i) return count = 0 for index, value in enumerate(arr): if value in unique: count += 1 if count == m: print(index+1, end=" ") count = 0 k -= 1 if k - 1 == 0: print() return solve() ```
instruction
0
69,886
12
139,772
No
output
1
69,886
12
139,773
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. An array b is called to be a subarray of a if it forms a continuous subsequence of a, that is, if it is equal to a_l, a_{l + 1}, …, a_r for some l, r. Suppose m is some known constant. For any array, having m or more elements, let's define it's beauty as the sum of m largest elements of that array. For example: * For array x = [4, 3, 1, 5, 2] and m = 3, the 3 largest elements of x are 5, 4 and 3, so the beauty of x is 5 + 4 + 3 = 12. * For array x = [10, 10, 10] and m = 2, the beauty of x is 10 + 10 = 20. You are given an array a_1, a_2, …, a_n, the value of the said constant m and an integer k. Your need to split the array a into exactly k subarrays such that: * Each element from a belongs to exactly one subarray. * Each subarray has at least m elements. * The sum of all beauties of k subarrays is maximum possible. Input The first line contains three integers n, m and k (2 ≀ n ≀ 2 β‹… 10^5, 1 ≀ m, 2 ≀ k, m β‹… k ≀ n) β€” the number of elements in a, the constant m in the definition of beauty and the number of subarrays to split to. The second line contains n integers a_1, a_2, …, a_n (-10^9 ≀ a_i ≀ 10^9). Output In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition. In the second line, print k-1 integers p_1, p_2, …, p_{k-1} (1 ≀ p_1 < p_2 < … < p_{k-1} < n) representing the partition of the array, in which: * All elements with indices from 1 to p_1 belong to the first subarray. * All elements with indices from p_1 + 1 to p_2 belong to the second subarray. * …. * All elements with indices from p_{k-1} + 1 to n belong to the last, k-th subarray. If there are several optimal partitions, print any of them. Examples Input 9 2 3 5 2 5 2 4 1 1 3 2 Output 21 3 5 Input 6 1 4 4 1 3 2 2 3 Output 12 1 3 5 Input 2 1 2 -1000000000 1000000000 Output 0 1 Note In the first example, one of the optimal partitions is [5, 2, 5], [2, 4], [1, 1, 3, 2]. * The beauty of the subarray [5, 2, 5] is 5 + 5 = 10. * The beauty of the subarray [2, 4] is 2 + 4 = 6. * The beauty of the subarray [1, 1, 3, 2] is 3 + 2 = 5. The sum of their beauties is 10 + 6 + 5 = 21. In the second example, one optimal partition is [4], [1, 3], [2, 2], [3]. Submitted Solution: ``` n, m, k = map(int, input().split()) cl = list(map(int, input().split())) pl = sorted(cl) dic = {} for i in range(n-m*k, n): dic.update({pl[i]:1}) pos = pl[n-m*k] for i in range(n-m*k): if pl[i]!=pos: dic.update({pl[i]:0}) count = 0 ans = [] sm = sum(pl[n-m*k:]) for i in range(n): if dic[cl[i]]==1: count+=1 if count==m: ans.append(i+1) count = 0 print(sm) print(*ans[:-1]) ```
instruction
0
69,887
12
139,774
No
output
1
69,887
12
139,775
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ujan needs some rest from cleaning, so he started playing with infinite sequences. He has two integers n and k. He creates an infinite sequence s by repeating the following steps. 1. Find k smallest distinct positive integers that are not in s. Let's call them u_{1}, u_{2}, …, u_{k} from the smallest to the largest. 2. Append u_{1}, u_{2}, …, u_{k} and βˆ‘_{i=1}^{k} u_{i} to s in this order. 3. Go back to the first step. Ujan will stop procrastinating when he writes the number n in the sequence s. Help him find the index of n in s. In other words, find the integer x such that s_{x} = n. It's possible to prove that all positive integers are included in s only once. Input The first line contains a single integer t (1 ≀ t ≀ 10^{5}), the number of test cases. Each of the following t lines contains two integers n and k (1 ≀ n ≀ 10^{18}, 2 ≀ k ≀ 10^{6}), the number to be found in the sequence s and the parameter used to create the sequence s. Output In each of the t lines, output the answer for the corresponding test case. Example Input 2 10 2 40 5 Output 11 12 Note In the first sample, s = (1, 2, 3, 4, 5, 9, 6, 7, 13, 8, 10, 18, …). 10 is the 11-th number here, so the answer is 11. In the second sample, s = (1, 2, 3, 4, 5, 15, 6, 7, 8, 9, 10, 40, …). Submitted Solution: ``` def f(n,k): if n==0: return k*(k+1)//2 p = f(n//k,k) s = n%k len = k*k+1 if (p%len) == 0: pivot = len else: pivot = p%len if s*k<pivot-k: return (n//k)*len*k+k*k*s+k*(k+1)//2 elif s*k<pivot: return (n//k)*len*k+k*k*s+k*(k+1)//2+k+s*k-pivot+1 else: return (n//k)*len*k+k*k*s+(k+1)*(k+2)/2-1 def solve(n,k): seg = (n-1)//(k*k+1) last = f(seg, k) if last<n: return (n-seg-1) + (n-seg-2)//k elif last == n: return (seg+1)*(k+1) else: return (n-seg) + (n-seg-1)//k for _ in range(int(input())): n,k = map(int,input().split()) print(solve(n, k)) ```
instruction
0
69,942
12
139,884
No
output
1
69,942
12
139,885
Provide tags and a correct Python 3 solution for this coding contest problem. A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = xΒ·k. You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). All the numbers in the lines are separated by single spaces. Output On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}. Examples Input 6 2 2 3 6 5 4 10 Output 3 Note In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
instruction
0
70,131
12
140,262
Tags: binary search, greedy, sortings Correct Solution: ``` import sys input = sys.stdin.readline n, k = map(int, input().split()) a = list(map(int, input().split())) s = set() a.sort() for i in range(n): if a[i] % k != 0: s.add(a[i]) else: if a[i]//k not in s: s.add(a[i]) print(len(s)) ```
output
1
70,131
12
140,263
Provide tags and a correct Python 3 solution for this coding contest problem. A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = xΒ·k. You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). All the numbers in the lines are separated by single spaces. Output On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}. Examples Input 6 2 2 3 6 5 4 10 Output 3 Note In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
instruction
0
70,132
12
140,264
Tags: binary search, greedy, sortings Correct Solution: ``` n,k=map(int,input().split()) L=list(map(int,input().split())) L.sort(reverse=True) S={} for i in range(n): if(L[i]*k in S): continue S[L[i]]=1 print(len(S)) # Made By Mostafa_Khaled ```
output
1
70,132
12
140,265
Provide tags and a correct Python 3 solution for this coding contest problem. A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = xΒ·k. You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). All the numbers in the lines are separated by single spaces. Output On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}. Examples Input 6 2 2 3 6 5 4 10 Output 3 Note In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
instruction
0
70,133
12
140,266
Tags: binary search, greedy, sortings Correct Solution: ``` """ Code of Ayush Tiwari Codechef: ayush572000 Codeforces: servermonk """ import sys input = sys.stdin.buffer.readline from collections import Counter def solution(): n,k=map(int,input().split()) l=list(map(int,input().split())) l.sort() c=Counter(l) i=0 for i in l: x=i if c[i]!=1: continue if c[k*x]==1 and k*x!=x: c[k*x]-=1 # print(c) print(sum(c.values())) solution() ```
output
1
70,133
12
140,267
Provide tags and a correct Python 3 solution for this coding contest problem. A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = xΒ·k. You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). All the numbers in the lines are separated by single spaces. Output On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}. Examples Input 6 2 2 3 6 5 4 10 Output 3 Note In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
instruction
0
70,134
12
140,268
Tags: binary search, greedy, sortings Correct Solution: ``` import sys import math MAXNUM = math.inf MINNUM = -1 * math.inf def getInts(): return map(int, sys.stdin.readline().rstrip().split(" ")) def getString(): return sys.stdin.readline().rstrip() def solve(n, k, ints): cache = {} total = 0 for ele in ints: length = 1 if (ele * k) in cache: after = ele * k end = cache[after][1] # 1 is end of series total -= ((cache[after][2]) + 1) // 2 # max length of this sequence length += cache[after][2] else: end = ele if ele % k == 0 and (ele // k) in cache: before = ele // k start = cache[before][0] # 0 is start of series total -= ((cache[before][2]) + 1) // 2 # length length += cache[before][2] else: start = ele cache[start] = (start, end, length) cache[end] = (start, end, length) total += ((length) + 1) // 2 return total def printOutput(ans): sys.stdout.write(str(ans)) def readinput(): n, k = getInts() ints = list(getInts()) printOutput(solve(n, k, ints)) readinput() ```
output
1
70,134
12
140,269
Provide tags and a correct Python 3 solution for this coding contest problem. A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = xΒ·k. You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). All the numbers in the lines are separated by single spaces. Output On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}. Examples Input 6 2 2 3 6 5 4 10 Output 3 Note In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
instruction
0
70,135
12
140,270
Tags: binary search, greedy, sortings Correct Solution: ``` n, k = input().split() n = int(n); k = int(k) a = [int(i) for i in input().split()] a.sort() mul = [0]*n def search(a, val, k): l = 0; r = len(a)-1 while l <= r: mid = (l+r)//2 if a[mid] == val*k: return mid elif a[mid] > val*k: r = mid - 1 else: l = mid + 1 return -1 if n == 1: print(1) else: count = 0 for i in range(n): pos = search(a, a[i], k) if pos != -1 and pos != i: mul[pos] = mul[i] + 1 # print(mul) for i in range(n): if not mul[i]%2: count += 1 print(count) ```
output
1
70,135
12
140,271
Provide tags and a correct Python 3 solution for this coding contest problem. A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = xΒ·k. You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). All the numbers in the lines are separated by single spaces. Output On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}. Examples Input 6 2 2 3 6 5 4 10 Output 3 Note In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
instruction
0
70,136
12
140,272
Tags: binary search, greedy, sortings Correct Solution: ``` import math import sys import collections import bisect import string import time def get_ints():return map(int, sys.stdin.readline().strip().split()) def get_list():return list(map(int, sys.stdin.readline().strip().split())) def get_string():return sys.stdin.readline().strip() for t in range(1): n,k=get_ints() arr=get_list() arr.sort() ans=set() for i in arr: if i%k!=0: ans.add(i) elif i//k not in ans: ans.add(i) print(len(ans)) ```
output
1
70,136
12
140,273