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. Gildong recently learned how to find the [longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) (LIS) in O(nlog{n}) time for a sequence of length n. He wants to test himself if he can implement it corr...
instruction
0
16,086
12
32,172
Tags: constructive algorithms, graphs, greedy, two pointers Correct Solution: ``` import sys input = lambda: sys.stdin.readline().rstrip() for _ in range(int(input())): n,m=map(str,input().split()) n=int(n) l=[]; g=[]; buf=[n] ; li=n-1 ; gi=2 for i in m: if i=='>': while buf: ...
output
1
16,086
12
32,173
Provide tags and a correct Python 3 solution for this coding contest problem. Gildong recently learned how to find the [longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) (LIS) in O(nlog{n}) time for a sequence of length n. He wants to test himself if he can implement it corr...
instruction
0
16,087
12
32,174
Tags: constructive algorithms, graphs, greedy, two pointers Correct Solution: ``` # Legends Always Come Up with Solution # Author: Manvir Singh import os import sys from io import BytesIO, IOBase def main(): for _ in range(int(input())): n, s = input().split() n = int(n) ans = [] p...
output
1
16,087
12
32,175
Provide tags and a correct Python 3 solution for this coding contest problem. Gildong recently learned how to find the [longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) (LIS) in O(nlog{n}) time for a sequence of length n. He wants to test himself if he can implement it corr...
instruction
0
16,088
12
32,176
Tags: constructive algorithms, graphs, greedy, two pointers Correct Solution: ``` from sys import stdin, stdout from collections import deque, Counter from copy import copy rl = lambda: stdin.readline() rll = lambda: stdin.readline().split() def main(): T = int(rl()) for _ in range(T): line = rll() n, s = int(l...
output
1
16,088
12
32,177
Provide tags and a correct Python 3 solution for this coding contest problem. Gildong recently learned how to find the [longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) (LIS) in O(nlog{n}) time for a sequence of length n. He wants to test himself if he can implement it corr...
instruction
0
16,089
12
32,178
Tags: constructive algorithms, graphs, greedy, two pointers Correct Solution: ``` from sys import stdin, stdout from collections import deque, Counter from copy import copy rl = lambda: stdin.readline() rll = lambda: stdin.readline().split() # > > < > > < #a b c d e f g def main(): T = int(rl()) for _ in range(T): ...
output
1
16,089
12
32,179
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gildong recently learned how to find the [longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) (LIS) in O(nlog{n}) time for a sequence of length n. He wa...
instruction
0
16,090
12
32,180
Yes
output
1
16,090
12
32,181
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gildong recently learned how to find the [longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) (LIS) in O(nlog{n}) time for a sequence of length n. He wa...
instruction
0
16,091
12
32,182
Yes
output
1
16,091
12
32,183
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gildong recently learned how to find the [longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) (LIS) in O(nlog{n}) time for a sequence of length n. He wa...
instruction
0
16,092
12
32,184
Yes
output
1
16,092
12
32,185
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gildong recently learned how to find the [longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) (LIS) in O(nlog{n}) time for a sequence of length n. He wa...
instruction
0
16,093
12
32,186
Yes
output
1
16,093
12
32,187
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gildong recently learned how to find the [longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) (LIS) in O(nlog{n}) time for a sequence of length n. He wa...
instruction
0
16,094
12
32,188
No
output
1
16,094
12
32,189
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gildong recently learned how to find the [longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) (LIS) in O(nlog{n}) time for a sequence of length n. He wa...
instruction
0
16,095
12
32,190
No
output
1
16,095
12
32,191
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gildong recently learned how to find the [longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) (LIS) in O(nlog{n}) time for a sequence of length n. He wa...
instruction
0
16,096
12
32,192
No
output
1
16,096
12
32,193
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gildong recently learned how to find the [longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) (LIS) in O(nlog{n}) time for a sequence of length n. He wa...
instruction
0
16,097
12
32,194
No
output
1
16,097
12
32,195
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation is a sequence of n integers from 1 to n, in which all numbers occur exactly once. For example, [1], [3, 5, 2, 1, 4], [1, 3, 2] are permutations, and [2, 3, 2], [4, 3, 1], [0] are not. Polycarp was presented with a permutation ...
instruction
0
16,210
12
32,420
Tags: constructive algorithms, implementation Correct Solution: ``` from collections import deque def odwroc(n,l): ustalone = [l[0]] maks = l[0] for i in range(1,n): if l[i] == maks: ustalone.append('x') else: ustalone.append(l[i]) maks = l[i] return ...
output
1
16,210
12
32,421
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation is a sequence of n integers from 1 to n, in which all numbers occur exactly once. For example, [1], [3, 5, 2, 1, 4], [1, 3, 2] are permutations, and [2, 3, 2], [4, 3, 1], [0] are not. Polycarp was presented with a permutation ...
instruction
0
16,211
12
32,422
Tags: constructive algorithms, implementation Correct Solution: ``` # Author : nitish420 -------------------------------------------------------------------- import os import sys from io import BytesIO, IOBase def solvemn(arr,v): l=0 for i in range(len(arr)): if arr[i]==0: while v[l]: ...
output
1
16,211
12
32,423
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation is a sequence of n integers from 1 to n, in which all numbers occur exactly once. For example, [1], [3, 5, 2, 1, 4], [1, 3, 2] are permutations, and [2, 3, 2], [4, 3, 1], [0] are not. Polycarp was presented with a permutation ...
instruction
0
16,212
12
32,424
Tags: constructive algorithms, implementation Correct Solution: ``` from collections import deque import sys input=sys.stdin.readline t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) a=[0]+a minimal=[] maximal=[] s=deque([]) for i in range(1,len(a)): ...
output
1
16,212
12
32,425
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation is a sequence of n integers from 1 to n, in which all numbers occur exactly once. For example, [1], [3, 5, 2, 1, 4], [1, 3, 2] are permutations, and [2, 3, 2], [4, 3, 1], [0] are not. Polycarp was presented with a permutation ...
instruction
0
16,213
12
32,426
Tags: constructive algorithms, implementation Correct Solution: ``` def main(): tt = int(input()) while tt > 0: tt -= 1 n = int(input()) a = [int(u) for u in input().split()] ans1 = [0 for i in range(n)] prev = 0 not_used = [] for i in range(n): ...
output
1
16,213
12
32,427
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation is a sequence of n integers from 1 to n, in which all numbers occur exactly once. For example, [1], [3, 5, 2, 1, 4], [1, 3, 2] are permutations, and [2, 3, 2], [4, 3, 1], [0] are not. Polycarp was presented with a permutation ...
instruction
0
16,214
12
32,428
Tags: constructive algorithms, implementation Correct Solution: ``` import sys input = sys.stdin.readline for nt in range(int(input())): n = int(input()) a = list(map(int,input().split())) minn = [0]*n minn[0] = a[0] for i in range(1, n): if a[i]!=a[i-1]: minn[i] = a[i] s = set(minn) curr = 1 for i in ran...
output
1
16,214
12
32,429
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation is a sequence of n integers from 1 to n, in which all numbers occur exactly once. For example, [1], [3, 5, 2, 1, 4], [1, 3, 2] are permutations, and [2, 3, 2], [4, 3, 1], [0] are not. Polycarp was presented with a permutation ...
instruction
0
16,215
12
32,430
Tags: constructive algorithms, implementation Correct Solution: ``` if __name__ == '__main__': for _ in range (int(input())): n = int(input()) l = list(map(int, input().split())) b = l.copy() d = {l[0]:0} ans = [l[0]] a = [] for i in range (1,n): d.setdefault(l[i],i) if b[i]==b[i-1]: l[i]='X' ...
output
1
16,215
12
32,431
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation is a sequence of n integers from 1 to n, in which all numbers occur exactly once. For example, [1], [3, 5, 2, 1, 4], [1, 3, 2] are permutations, and [2, 3, 2], [4, 3, 1], [0] are not. Polycarp was presented with a permutation ...
instruction
0
16,216
12
32,432
Tags: constructive algorithms, implementation Correct Solution: ``` '''Author- Akshit Monga''' from sys import stdin, stdout input = stdin.readline class SortedList: def __init__(self, iterable=[], _load=200): """Initialize sorted list instance.""" values = sorted(iterable) self._len = _len...
output
1
16,216
12
32,433
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation is a sequence of n integers from 1 to n, in which all numbers occur exactly once. For example, [1], [3, 5, 2, 1, 4], [1, 3, 2] are permutations, and [2, 3, 2], [4, 3, 1], [0] are not. Polycarp was presented with a permutation ...
instruction
0
16,217
12
32,434
Tags: constructive algorithms, implementation Correct Solution: ``` for _ in range(int(input())): n=int(input()) q=list(map(int,input().split())) maxy=[] miny=[] M=[] m=[] count=1 i=0 j=0 while i<n: num=q[i] while num>count: maxy.append(count) ...
output
1
16,217
12
32,435
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation is a sequence of n integers from 1 to n, in which all numbers occur exactly once. For example, [1], [3, 5, 2, 1, 4], [1, 3, 2] are permutations, and [2, 3, 2], [4, 3, 1], [0] are n...
instruction
0
16,218
12
32,436
Yes
output
1
16,218
12
32,437
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation is a sequence of n integers from 1 to n, in which all numbers occur exactly once. For example, [1], [3, 5, 2, 1, 4], [1, 3, 2] are permutations, and [2, 3, 2], [4, 3, 1], [0] are n...
instruction
0
16,219
12
32,438
Yes
output
1
16,219
12
32,439
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation is a sequence of n integers from 1 to n, in which all numbers occur exactly once. For example, [1], [3, 5, 2, 1, 4], [1, 3, 2] are permutations, and [2, 3, 2], [4, 3, 1], [0] are n...
instruction
0
16,220
12
32,440
Yes
output
1
16,220
12
32,441
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation is a sequence of n integers from 1 to n, in which all numbers occur exactly once. For example, [1], [3, 5, 2, 1, 4], [1, 3, 2] are permutations, and [2, 3, 2], [4, 3, 1], [0] are n...
instruction
0
16,221
12
32,442
Yes
output
1
16,221
12
32,443
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation is a sequence of n integers from 1 to n, in which all numbers occur exactly once. For example, [1], [3, 5, 2, 1, 4], [1, 3, 2] are permutations, and [2, 3, 2], [4, 3, 1], [0] are n...
instruction
0
16,222
12
32,444
No
output
1
16,222
12
32,445
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation is a sequence of n integers from 1 to n, in which all numbers occur exactly once. For example, [1], [3, 5, 2, 1, 4], [1, 3, 2] are permutations, and [2, 3, 2], [4, 3, 1], [0] are n...
instruction
0
16,223
12
32,446
No
output
1
16,223
12
32,447
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation is a sequence of n integers from 1 to n, in which all numbers occur exactly once. For example, [1], [3, 5, 2, 1, 4], [1, 3, 2] are permutations, and [2, 3, 2], [4, 3, 1], [0] are n...
instruction
0
16,224
12
32,448
No
output
1
16,224
12
32,449
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation is a sequence of n integers from 1 to n, in which all numbers occur exactly once. For example, [1], [3, 5, 2, 1, 4], [1, 3, 2] are permutations, and [2, 3, 2], [4, 3, 1], [0] are n...
instruction
0
16,225
12
32,450
No
output
1
16,225
12
32,451
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of n elements. Petya immediately decided to find there a segment of consecutive elements, such that the xor o...
instruction
0
16,265
12
32,530
Tags: brute force, implementation Correct Solution: ``` import itertools import functools def allSubArrays(xs): n = len(xs) indices = list(range(n+1)) for i,j in itertools.combinations(indices,2): yield xs[i:j] n=int(input()) my_list=list(map(int,input().split(" "))) list_=list(allSubArrays(my_list)...
output
1
16,265
12
32,531
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of n elements. Petya immediately decided to find there a segment of consecutive elements, such that the xor o...
instruction
0
16,266
12
32,532
Tags: brute force, implementation Correct Solution: ``` import math,sys from collections import defaultdict,deque import bisect as bi def yes():print('YES') def no():print('NO') def I():return (int(sys.stdin.readline())) def In():return(map(int,sys.stdin.readline().split())) def Sn():return sys.stdin.readline().strip()...
output
1
16,266
12
32,533
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of n elements. Petya immediately decided to find there a segment of consecutive elements, such that the xor o...
instruction
0
16,267
12
32,534
Tags: brute force, implementation Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) res = 0 for i in range(n): x = 0 for j in range(i, n): x = (x ^ a[j]) res = max(res, x) print(res) ```
output
1
16,267
12
32,535
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of n elements. Petya immediately decided to find there a segment of consecutive elements, such that the xor o...
instruction
0
16,268
12
32,536
Tags: brute force, implementation Correct Solution: ``` #from dust i have come, dust i will be n=int(input()) a=list(map(int,input().split())) m=a[0] for i in range(len(a)-1): x=a[i] m=max(m,x) for j in range(i+1,len(a)): x=x^a[j] m=max(m,x) print(max(m,max(a))) ```
output
1
16,268
12
32,537
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of n elements. Petya immediately decided to find there a segment of consecutive elements, such that the xor o...
instruction
0
16,269
12
32,538
Tags: brute force, implementation Correct Solution: ``` n=int(input()) l=list(map(int,input().split())) pre=[0]*(n+1) for i in range(1,n+1): pre[i]=pre[i-1]^l[i-1] ans=[] for i in range(n+1): for j in range(n+1): ans.append(pre[j]^pre[i]) print(max(ans)) ```
output
1
16,269
12
32,539
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of n elements. Petya immediately decided to find there a segment of consecutive elements, such that the xor o...
instruction
0
16,270
12
32,540
Tags: brute force, implementation Correct Solution: ``` n = int(input()) s = input().split() s = [int(x) for x in s] m = 0 for i in range(n): xor = s[i] if xor > m: m = xor for j in range(i+1,n): xor = xor ^ s[j] if xor > m: m=xor print(m) ```
output
1
16,270
12
32,541
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of n elements. Petya immediately decided to find there a segment of consecutive elements, such that the xor o...
instruction
0
16,271
12
32,542
Tags: brute force, implementation Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) def xor(s): x = 0 for i in s: x ^= i return x mx = -1 for i in range(n): for j in range(n): if i == j: if a[i] > mx: mx = a[i] else: x = xor(a[i:j+1]) if x > mx: mx = x print(mx) `...
output
1
16,271
12
32,543
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of n elements. Petya immediately decided to find there a segment of consecutive elements, such that the xor o...
instruction
0
16,272
12
32,544
Tags: brute force, implementation Correct Solution: ``` n = int(input()) ls = list(map(int, input().split())) mx = 0 for i in range(n): curr = ls[i] mx = max(curr, mx) for j in range(i + 1, n): curr ^= ls[j] mx = max(curr, mx) print(mx) ```
output
1
16,272
12
32,545
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of n elements. Petya immediately decided to find there a segme...
instruction
0
16,273
12
32,546
Yes
output
1
16,273
12
32,547
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of n elements. Petya immediately decided to find there a segme...
instruction
0
16,274
12
32,548
Yes
output
1
16,274
12
32,549
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of n elements. Petya immediately decided to find there a segme...
instruction
0
16,275
12
32,550
Yes
output
1
16,275
12
32,551
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of n elements. Petya immediately decided to find there a segme...
instruction
0
16,276
12
32,552
Yes
output
1
16,276
12
32,553
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of n elements. Petya immediately decided to find there a segme...
instruction
0
16,277
12
32,554
No
output
1
16,277
12
32,555
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of n elements. Petya immediately decided to find there a segme...
instruction
0
16,278
12
32,556
No
output
1
16,278
12
32,557
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of n elements. Petya immediately decided to find there a segme...
instruction
0
16,279
12
32,558
No
output
1
16,279
12
32,559
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of n elements. Petya immediately decided to find there a segme...
instruction
0
16,280
12
32,560
No
output
1
16,280
12
32,561
Provide tags and a correct Python 3 solution for this coding contest problem. This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2. Array a is k-period if its length is divisible by k and there is such array b of length k, that a is represented by array b written exactly <imag...
instruction
0
16,293
12
32,586
Tags: greedy, implementation, math Correct Solution: ``` def main(): n, k = map(int, input().split()) arr = list(map(int, input().split())) got = [0]*(k+1) for i in range(0, k): for j in range(n//k): if arr[j*k+i]==1: got[i] += 1 answer = 0 for i in range(k)...
output
1
16,293
12
32,587
Provide tags and a correct Python 3 solution for this coding contest problem. This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2. Array a is k-period if its length is divisible by k and there is such array b of length k, that a is represented by array b written exactly <imag...
instruction
0
16,294
12
32,588
Tags: greedy, implementation, math Correct Solution: ``` n, k = map(int, input().split()) a = input().split() res = 0 for i in range(k): one = 0; two = 0 for j in range(i, n, k): if a[j] == '2': two+= 1 else: one+= 1 res+= min(one, two) print(res) ```
output
1
16,294
12
32,589
Provide tags and a correct Python 3 solution for this coding contest problem. This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2. Array a is k-period if its length is divisible by k and there is such array b of length k, that a is represented by array b written exactly <imag...
instruction
0
16,295
12
32,590
Tags: greedy, implementation, math Correct Solution: ``` n, k = map(int, input().split()) l = list(map(int, input().split())) ans = 0 z = n // k for i in range(k): b = l[i::k] co = b.count(1) ans += min(z - co, co) print(ans) ```
output
1
16,295
12
32,591
Provide tags and a correct Python 3 solution for this coding contest problem. This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2. Array a is k-period if its length is divisible by k and there is such array b of length k, that a is represented by array b written exactly <imag...
instruction
0
16,296
12
32,592
Tags: greedy, implementation, math Correct Solution: ``` R = lambda: map(int, input().split()) n, k = R() a = list(R()) print(sum(min(x.count(1), x.count(2)) for x in (a[i::k] for i in range(k)))) ```
output
1
16,296
12
32,593
Provide tags and a correct Python 3 solution for this coding contest problem. This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2. Array a is k-period if its length is divisible by k and there is such array b of length k, that a is represented by array b written exactly <imag...
instruction
0
16,297
12
32,594
Tags: greedy, implementation, math Correct Solution: ``` import math n,k=map(int,input().split()) a=list(map(int,input().split())) ans=0 for i in range(k): r=a[i];m=0 for j in range(n//k): if a[i+j*k]!=r: m+=1 ans+=min(m,n//k-m) print(ans) ```
output
1
16,297
12
32,595
Provide tags and a correct Python 3 solution for this coding contest problem. This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2. Array a is k-period if its length is divisible by k and there is such array b of length k, that a is represented by array b written exactly <imag...
instruction
0
16,298
12
32,596
Tags: greedy, implementation, math Correct Solution: ``` n, m = map(int, input().split()) arr = list(map(int, input().split())) cnt1, cnt2 = [0] * (m+1), [0] * (m+1) for i in range(len(arr)): if arr[i] == 1: cnt1[i % m + 1] += 1 if arr[i] == 2: cnt2[i % m + 1] += 1 res = 0 for i in range(m+1): ...
output
1
16,298
12
32,597