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. Let's denote the median of a sequence s with odd length as the value in the middle of s if we sort s in non-decreasing order. For example, let s = [1, 2, 5, 7, 2, 3, 12]. After sorting, we get sequence [1, 2, 2, \underline{3}, 5, 7, 12], and the median is equal to 3. You have a sequence of n integers [1, 2, ..., n] and an odd integer k. In one step, you choose any k elements from the sequence and erase all chosen elements except their median. These elements do not have to go continuously (gaps are allowed between them). For example, if you have a sequence [1, 2, 3, 4, 5, 6, 7] (i.e. n=7) and k = 3, then the following options for the first step are possible: * choose [1, \underline{2}, 3]; 2 is their median, so it is not erased, and the resulting sequence is [2, 4, 5, 6, 7]; * choose [2, \underline{4}, 6]; 4 is their median, so it is not erased, and the resulting sequence is [1, 3, 4, 5, 7]; * choose [1, \underline{6}, 7]; 6 is their median, so it is not erased, and the resulting sequence is [2, 3, 4, 5, 6]; * and several others. You can do zero or more steps. Can you get a sequence b_1, b_2, ..., b_m after several steps? You'll be given t test cases. Solve each test case independently. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains three integers n, k, and m (3 ≀ n ≀ 2 β‹… 10^5; 3 ≀ k ≀ n; k is odd; 1 ≀ m < n) β€” the length of the sequence you have, the number of elements you choose in each step and the length of the sequence you'd like to get. The second line of each test case contains m integers b_1, b_2, ..., b_m (1 ≀ b_1 < b_2 < ... < b_m ≀ n) β€” the sequence you'd like to get, given in the ascending order. It's guaranteed that the total sum of n over all test cases doesn't exceed 2 β‹… 10^5. Output For each test case, print YES if you can obtain the sequence b or NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer). Example Input 4 3 3 1 1 7 3 3 1 5 7 10 5 3 4 5 6 13 7 7 1 3 5 7 9 11 12 Output NO YES NO YES Note In the first test case, you have sequence [1, 2, 3]. Since k = 3 you have only one way to choose k elements β€” it's to choose all elements [1, \underline{2}, 3] with median 2. That's why after erasing all chosen elements except its median you'll get sequence [2]. In other words, there is no way to get sequence b = [1] as the result. In the second test case, you have sequence [1, 2, 3, 4, 5, 6, 7] and one of the optimal strategies is following: 1. choose k = 3 elements [2, \underline{3}, 4] and erase them except its median; you'll get sequence [1, 3, 5, 6, 7]; 2. choose 3 elements [3, \underline{5}, 6] and erase them except its median; you'll get desired sequence [1, 5, 7]; In the fourth test case, you have sequence [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]. You can choose k=7 elements [2, 4, 6, \underline{7}, 8, 10, 13] and erase them except its median to get sequence b.
instruction
0
5,239
12
10,478
Tags: constructive algorithms, greedy, math Correct Solution: ``` import sys for _ in range(int(input())): n,k,m=tuple(map(int,input().split(" "))) ml=set(map(int,input().split(" "))) havitada=[] for i in range(1,n+1): if i not in ml: havitada.append(i) saab=False if len(havitada)%(k-1)!=0: print("no") continue for i in range(k//2-1,len(havitada)-k//2): if havitada[i+1]-havitada[i]!=1: print("yes") break else: print("no") ```
output
1
5,239
12
10,479
Provide tags and a correct Python 3 solution for this coding contest problem. Let's denote the median of a sequence s with odd length as the value in the middle of s if we sort s in non-decreasing order. For example, let s = [1, 2, 5, 7, 2, 3, 12]. After sorting, we get sequence [1, 2, 2, \underline{3}, 5, 7, 12], and the median is equal to 3. You have a sequence of n integers [1, 2, ..., n] and an odd integer k. In one step, you choose any k elements from the sequence and erase all chosen elements except their median. These elements do not have to go continuously (gaps are allowed between them). For example, if you have a sequence [1, 2, 3, 4, 5, 6, 7] (i.e. n=7) and k = 3, then the following options for the first step are possible: * choose [1, \underline{2}, 3]; 2 is their median, so it is not erased, and the resulting sequence is [2, 4, 5, 6, 7]; * choose [2, \underline{4}, 6]; 4 is their median, so it is not erased, and the resulting sequence is [1, 3, 4, 5, 7]; * choose [1, \underline{6}, 7]; 6 is their median, so it is not erased, and the resulting sequence is [2, 3, 4, 5, 6]; * and several others. You can do zero or more steps. Can you get a sequence b_1, b_2, ..., b_m after several steps? You'll be given t test cases. Solve each test case independently. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains three integers n, k, and m (3 ≀ n ≀ 2 β‹… 10^5; 3 ≀ k ≀ n; k is odd; 1 ≀ m < n) β€” the length of the sequence you have, the number of elements you choose in each step and the length of the sequence you'd like to get. The second line of each test case contains m integers b_1, b_2, ..., b_m (1 ≀ b_1 < b_2 < ... < b_m ≀ n) β€” the sequence you'd like to get, given in the ascending order. It's guaranteed that the total sum of n over all test cases doesn't exceed 2 β‹… 10^5. Output For each test case, print YES if you can obtain the sequence b or NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer). Example Input 4 3 3 1 1 7 3 3 1 5 7 10 5 3 4 5 6 13 7 7 1 3 5 7 9 11 12 Output NO YES NO YES Note In the first test case, you have sequence [1, 2, 3]. Since k = 3 you have only one way to choose k elements β€” it's to choose all elements [1, \underline{2}, 3] with median 2. That's why after erasing all chosen elements except its median you'll get sequence [2]. In other words, there is no way to get sequence b = [1] as the result. In the second test case, you have sequence [1, 2, 3, 4, 5, 6, 7] and one of the optimal strategies is following: 1. choose k = 3 elements [2, \underline{3}, 4] and erase them except its median; you'll get sequence [1, 3, 5, 6, 7]; 2. choose 3 elements [3, \underline{5}, 6] and erase them except its median; you'll get desired sequence [1, 5, 7]; In the fourth test case, you have sequence [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]. You can choose k=7 elements [2, 4, 6, \underline{7}, 8, 10, 13] and erase them except its median to get sequence b.
instruction
0
5,240
12
10,480
Tags: constructive algorithms, greedy, math Correct Solution: ``` import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): def __init__(self, file): self.newlines = 0 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() # -------------------------------------------------------------------- def RL(): return map(int, sys.stdin.readline().split()) def RLL(): return list(map(int, sys.stdin.readline().split())) def N(): return int(input()) def S(): return input().strip() def print_list(l): print(' '.join(map(str, l))) # sys.setrecursionlimit(100000) # import random # from functools import reduce # from functools import lru_cache # from heapq import * # from collections import deque as dq from math import ceil # import bisect as bs # from collections import Counter # from collections import defaultdict as dc for _ in range(N()): n, k, m = RL() a = RLL() k >>= 1 if k == 0 or (n - m) % (2 * k): print('NO') else: t = n - m now = a[0] - 1 flag = False a.append(n + 1) for i in range(1, m + 1): if k <= now <= t - k: flag = True break now += a[i] - a[i - 1] - 1 print('YES' if flag else 'NO') ```
output
1
5,240
12
10,481
Provide tags and a correct Python 3 solution for this coding contest problem. Let's denote the median of a sequence s with odd length as the value in the middle of s if we sort s in non-decreasing order. For example, let s = [1, 2, 5, 7, 2, 3, 12]. After sorting, we get sequence [1, 2, 2, \underline{3}, 5, 7, 12], and the median is equal to 3. You have a sequence of n integers [1, 2, ..., n] and an odd integer k. In one step, you choose any k elements from the sequence and erase all chosen elements except their median. These elements do not have to go continuously (gaps are allowed between them). For example, if you have a sequence [1, 2, 3, 4, 5, 6, 7] (i.e. n=7) and k = 3, then the following options for the first step are possible: * choose [1, \underline{2}, 3]; 2 is their median, so it is not erased, and the resulting sequence is [2, 4, 5, 6, 7]; * choose [2, \underline{4}, 6]; 4 is their median, so it is not erased, and the resulting sequence is [1, 3, 4, 5, 7]; * choose [1, \underline{6}, 7]; 6 is their median, so it is not erased, and the resulting sequence is [2, 3, 4, 5, 6]; * and several others. You can do zero or more steps. Can you get a sequence b_1, b_2, ..., b_m after several steps? You'll be given t test cases. Solve each test case independently. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains three integers n, k, and m (3 ≀ n ≀ 2 β‹… 10^5; 3 ≀ k ≀ n; k is odd; 1 ≀ m < n) β€” the length of the sequence you have, the number of elements you choose in each step and the length of the sequence you'd like to get. The second line of each test case contains m integers b_1, b_2, ..., b_m (1 ≀ b_1 < b_2 < ... < b_m ≀ n) β€” the sequence you'd like to get, given in the ascending order. It's guaranteed that the total sum of n over all test cases doesn't exceed 2 β‹… 10^5. Output For each test case, print YES if you can obtain the sequence b or NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer). Example Input 4 3 3 1 1 7 3 3 1 5 7 10 5 3 4 5 6 13 7 7 1 3 5 7 9 11 12 Output NO YES NO YES Note In the first test case, you have sequence [1, 2, 3]. Since k = 3 you have only one way to choose k elements β€” it's to choose all elements [1, \underline{2}, 3] with median 2. That's why after erasing all chosen elements except its median you'll get sequence [2]. In other words, there is no way to get sequence b = [1] as the result. In the second test case, you have sequence [1, 2, 3, 4, 5, 6, 7] and one of the optimal strategies is following: 1. choose k = 3 elements [2, \underline{3}, 4] and erase them except its median; you'll get sequence [1, 3, 5, 6, 7]; 2. choose 3 elements [3, \underline{5}, 6] and erase them except its median; you'll get desired sequence [1, 5, 7]; In the fourth test case, you have sequence [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]. You can choose k=7 elements [2, 4, 6, \underline{7}, 8, 10, 13] and erase them except its median to get sequence b.
instruction
0
5,241
12
10,482
Tags: constructive algorithms, greedy, math Correct Solution: ``` T=int(input()) for _ in range(T): n,k,m=map(int, input().split()) b=[0]+list(map(int, input().split()))+[0]*10 #1~m (len=m+1) cnt=0 l=[0]*(m+10) r=[0]*(m+10) for i in range(1,m+1): #i:1~m cnt+=b[i]-b[i-1]-1 l[i]=l[i-1]+b[i]-b[i-1]-1 cnt+=n-b[m] r[m]=n-b[m] for i in range(m-1,0,-1): #i:m-1~1 r[i]=r[i+1]+b[i+1]-b[i]-1 flag=False for i in range(1,m+1): #i:1~m if l[i]>=k//2 and r[i]>=k//2: flag=True if cnt%(k-1)!=0: flag=False if flag: print("YES") else: print("NO") ```
output
1
5,241
12
10,483
Provide tags and a correct Python 3 solution for this coding contest problem. Let's denote the median of a sequence s with odd length as the value in the middle of s if we sort s in non-decreasing order. For example, let s = [1, 2, 5, 7, 2, 3, 12]. After sorting, we get sequence [1, 2, 2, \underline{3}, 5, 7, 12], and the median is equal to 3. You have a sequence of n integers [1, 2, ..., n] and an odd integer k. In one step, you choose any k elements from the sequence and erase all chosen elements except their median. These elements do not have to go continuously (gaps are allowed between them). For example, if you have a sequence [1, 2, 3, 4, 5, 6, 7] (i.e. n=7) and k = 3, then the following options for the first step are possible: * choose [1, \underline{2}, 3]; 2 is their median, so it is not erased, and the resulting sequence is [2, 4, 5, 6, 7]; * choose [2, \underline{4}, 6]; 4 is their median, so it is not erased, and the resulting sequence is [1, 3, 4, 5, 7]; * choose [1, \underline{6}, 7]; 6 is their median, so it is not erased, and the resulting sequence is [2, 3, 4, 5, 6]; * and several others. You can do zero or more steps. Can you get a sequence b_1, b_2, ..., b_m after several steps? You'll be given t test cases. Solve each test case independently. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains three integers n, k, and m (3 ≀ n ≀ 2 β‹… 10^5; 3 ≀ k ≀ n; k is odd; 1 ≀ m < n) β€” the length of the sequence you have, the number of elements you choose in each step and the length of the sequence you'd like to get. The second line of each test case contains m integers b_1, b_2, ..., b_m (1 ≀ b_1 < b_2 < ... < b_m ≀ n) β€” the sequence you'd like to get, given in the ascending order. It's guaranteed that the total sum of n over all test cases doesn't exceed 2 β‹… 10^5. Output For each test case, print YES if you can obtain the sequence b or NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer). Example Input 4 3 3 1 1 7 3 3 1 5 7 10 5 3 4 5 6 13 7 7 1 3 5 7 9 11 12 Output NO YES NO YES Note In the first test case, you have sequence [1, 2, 3]. Since k = 3 you have only one way to choose k elements β€” it's to choose all elements [1, \underline{2}, 3] with median 2. That's why after erasing all chosen elements except its median you'll get sequence [2]. In other words, there is no way to get sequence b = [1] as the result. In the second test case, you have sequence [1, 2, 3, 4, 5, 6, 7] and one of the optimal strategies is following: 1. choose k = 3 elements [2, \underline{3}, 4] and erase them except its median; you'll get sequence [1, 3, 5, 6, 7]; 2. choose 3 elements [3, \underline{5}, 6] and erase them except its median; you'll get desired sequence [1, 5, 7]; In the fourth test case, you have sequence [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]. You can choose k=7 elements [2, 4, 6, \underline{7}, 8, 10, 13] and erase them except its median to get sequence b.
instruction
0
5,242
12
10,484
Tags: constructive algorithms, greedy, math Correct Solution: ``` import sys input=sys.stdin.buffer.readline #FOR READING PURE INTEGER INPUTS (space separation ok) def multiLineArrayPrint(arr): print('\n'.join([str(x) for x in arr])) allAns=[] t=int(input()) for _ in range(t): n,k,m=[int(x) for x in input().split()] b=[int(x) for x in input().split()] b.append(n+1) ans='NO' if (n-m)%(k-1)==0: #valid number of missing numbers leftMissing=0 rightMissing=n-m prev=0 for x in b: leftMissing+=x-prev-1 rightMissing-=(x-prev-1) prev=x if leftMissing>=(k-1)//2 and rightMissing>=(k-1)//2: ans='YES' break # print('leftMissing:{} rightMissing:{}'.format(leftMissing,rightMissing)) allAns.append(ans) multiLineArrayPrint(allAns) ```
output
1
5,242
12
10,485
Provide tags and a correct Python 3 solution for this coding contest problem. Let's denote the median of a sequence s with odd length as the value in the middle of s if we sort s in non-decreasing order. For example, let s = [1, 2, 5, 7, 2, 3, 12]. After sorting, we get sequence [1, 2, 2, \underline{3}, 5, 7, 12], and the median is equal to 3. You have a sequence of n integers [1, 2, ..., n] and an odd integer k. In one step, you choose any k elements from the sequence and erase all chosen elements except their median. These elements do not have to go continuously (gaps are allowed between them). For example, if you have a sequence [1, 2, 3, 4, 5, 6, 7] (i.e. n=7) and k = 3, then the following options for the first step are possible: * choose [1, \underline{2}, 3]; 2 is their median, so it is not erased, and the resulting sequence is [2, 4, 5, 6, 7]; * choose [2, \underline{4}, 6]; 4 is their median, so it is not erased, and the resulting sequence is [1, 3, 4, 5, 7]; * choose [1, \underline{6}, 7]; 6 is their median, so it is not erased, and the resulting sequence is [2, 3, 4, 5, 6]; * and several others. You can do zero or more steps. Can you get a sequence b_1, b_2, ..., b_m after several steps? You'll be given t test cases. Solve each test case independently. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains three integers n, k, and m (3 ≀ n ≀ 2 β‹… 10^5; 3 ≀ k ≀ n; k is odd; 1 ≀ m < n) β€” the length of the sequence you have, the number of elements you choose in each step and the length of the sequence you'd like to get. The second line of each test case contains m integers b_1, b_2, ..., b_m (1 ≀ b_1 < b_2 < ... < b_m ≀ n) β€” the sequence you'd like to get, given in the ascending order. It's guaranteed that the total sum of n over all test cases doesn't exceed 2 β‹… 10^5. Output For each test case, print YES if you can obtain the sequence b or NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer). Example Input 4 3 3 1 1 7 3 3 1 5 7 10 5 3 4 5 6 13 7 7 1 3 5 7 9 11 12 Output NO YES NO YES Note In the first test case, you have sequence [1, 2, 3]. Since k = 3 you have only one way to choose k elements β€” it's to choose all elements [1, \underline{2}, 3] with median 2. That's why after erasing all chosen elements except its median you'll get sequence [2]. In other words, there is no way to get sequence b = [1] as the result. In the second test case, you have sequence [1, 2, 3, 4, 5, 6, 7] and one of the optimal strategies is following: 1. choose k = 3 elements [2, \underline{3}, 4] and erase them except its median; you'll get sequence [1, 3, 5, 6, 7]; 2. choose 3 elements [3, \underline{5}, 6] and erase them except its median; you'll get desired sequence [1, 5, 7]; In the fourth test case, you have sequence [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]. You can choose k=7 elements [2, 4, 6, \underline{7}, 8, 10, 13] and erase them except its median to get sequence b.
instruction
0
5,243
12
10,486
Tags: constructive algorithms, greedy, math Correct Solution: ``` from sys import stdin, stdout # if erased left elements >= (k-1)/2 # and erased right elements >= (k-1)/2 # and (n-m)%(k-1) == 0 # then YES # Prove: # set d = (k-1)/2 # left elements: d + x # right elements: d + y # ------------------------------------------ # if x + y >= k, set x + y = x + y - n*(k-1) # then x + y < k # ------------------------------------------ # because (2d + x + y) % (k-1) == 0, # so x + y = k - 1 # ------------------------------------------ # d x b d y # => d d-z b d d+z # => d (d-z) b (z) d [d] # def k_and_medians(n, k, m, b_a): if (n-m) % (k-1) != 0: return False b_s = set(b_a) l_a = [0] * (n+1) for i in range(1, n+1): l_a[i] = l_a[i - 1] if i not in b_s: l_a[i] = l_a[i-1] + 1 r = 0 for i in range(n, 0, -1): if i not in b_s: r += 1 elif r >= (k-1) // 2 and l_a[i] >= (k-1) // 2: return True return False t = int(stdin.readline()) for _ in range(t): n, k, m = map(int, stdin.readline().split()) b_a = list(map(int, stdin.readline().split())) r = k_and_medians(n, k, m, b_a) if r: stdout.write('YES\n') else: stdout.write('NO\n') ```
output
1
5,243
12
10,487
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's denote the median of a sequence s with odd length as the value in the middle of s if we sort s in non-decreasing order. For example, let s = [1, 2, 5, 7, 2, 3, 12]. After sorting, we get sequence [1, 2, 2, \underline{3}, 5, 7, 12], and the median is equal to 3. You have a sequence of n integers [1, 2, ..., n] and an odd integer k. In one step, you choose any k elements from the sequence and erase all chosen elements except their median. These elements do not have to go continuously (gaps are allowed between them). For example, if you have a sequence [1, 2, 3, 4, 5, 6, 7] (i.e. n=7) and k = 3, then the following options for the first step are possible: * choose [1, \underline{2}, 3]; 2 is their median, so it is not erased, and the resulting sequence is [2, 4, 5, 6, 7]; * choose [2, \underline{4}, 6]; 4 is their median, so it is not erased, and the resulting sequence is [1, 3, 4, 5, 7]; * choose [1, \underline{6}, 7]; 6 is their median, so it is not erased, and the resulting sequence is [2, 3, 4, 5, 6]; * and several others. You can do zero or more steps. Can you get a sequence b_1, b_2, ..., b_m after several steps? You'll be given t test cases. Solve each test case independently. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains three integers n, k, and m (3 ≀ n ≀ 2 β‹… 10^5; 3 ≀ k ≀ n; k is odd; 1 ≀ m < n) β€” the length of the sequence you have, the number of elements you choose in each step and the length of the sequence you'd like to get. The second line of each test case contains m integers b_1, b_2, ..., b_m (1 ≀ b_1 < b_2 < ... < b_m ≀ n) β€” the sequence you'd like to get, given in the ascending order. It's guaranteed that the total sum of n over all test cases doesn't exceed 2 β‹… 10^5. Output For each test case, print YES if you can obtain the sequence b or NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer). Example Input 4 3 3 1 1 7 3 3 1 5 7 10 5 3 4 5 6 13 7 7 1 3 5 7 9 11 12 Output NO YES NO YES Note In the first test case, you have sequence [1, 2, 3]. Since k = 3 you have only one way to choose k elements β€” it's to choose all elements [1, \underline{2}, 3] with median 2. That's why after erasing all chosen elements except its median you'll get sequence [2]. In other words, there is no way to get sequence b = [1] as the result. In the second test case, you have sequence [1, 2, 3, 4, 5, 6, 7] and one of the optimal strategies is following: 1. choose k = 3 elements [2, \underline{3}, 4] and erase them except its median; you'll get sequence [1, 3, 5, 6, 7]; 2. choose 3 elements [3, \underline{5}, 6] and erase them except its median; you'll get desired sequence [1, 5, 7]; In the fourth test case, you have sequence [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]. You can choose k=7 elements [2, 4, 6, \underline{7}, 8, 10, 13] and erase them except its median to get sequence b. Submitted Solution: ``` for _ in range(int(input())): n,k,m=tuple(map(int,input().split(" ")));ml=set(map(int,input().split(" ")));havitada=[i for i in range(1,n+1) if i not in ml];saab=False if len(havitada)%(k-1)!=0:print("no");continue for i in range(k//2-1,len(havitada)-k//2): if havitada[i+1]-havitada[i]!=1:print("yes");break else:print("no") ```
instruction
0
5,244
12
10,488
Yes
output
1
5,244
12
10,489
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's denote the median of a sequence s with odd length as the value in the middle of s if we sort s in non-decreasing order. For example, let s = [1, 2, 5, 7, 2, 3, 12]. After sorting, we get sequence [1, 2, 2, \underline{3}, 5, 7, 12], and the median is equal to 3. You have a sequence of n integers [1, 2, ..., n] and an odd integer k. In one step, you choose any k elements from the sequence and erase all chosen elements except their median. These elements do not have to go continuously (gaps are allowed between them). For example, if you have a sequence [1, 2, 3, 4, 5, 6, 7] (i.e. n=7) and k = 3, then the following options for the first step are possible: * choose [1, \underline{2}, 3]; 2 is their median, so it is not erased, and the resulting sequence is [2, 4, 5, 6, 7]; * choose [2, \underline{4}, 6]; 4 is their median, so it is not erased, and the resulting sequence is [1, 3, 4, 5, 7]; * choose [1, \underline{6}, 7]; 6 is their median, so it is not erased, and the resulting sequence is [2, 3, 4, 5, 6]; * and several others. You can do zero or more steps. Can you get a sequence b_1, b_2, ..., b_m after several steps? You'll be given t test cases. Solve each test case independently. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains three integers n, k, and m (3 ≀ n ≀ 2 β‹… 10^5; 3 ≀ k ≀ n; k is odd; 1 ≀ m < n) β€” the length of the sequence you have, the number of elements you choose in each step and the length of the sequence you'd like to get. The second line of each test case contains m integers b_1, b_2, ..., b_m (1 ≀ b_1 < b_2 < ... < b_m ≀ n) β€” the sequence you'd like to get, given in the ascending order. It's guaranteed that the total sum of n over all test cases doesn't exceed 2 β‹… 10^5. Output For each test case, print YES if you can obtain the sequence b or NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer). Example Input 4 3 3 1 1 7 3 3 1 5 7 10 5 3 4 5 6 13 7 7 1 3 5 7 9 11 12 Output NO YES NO YES Note In the first test case, you have sequence [1, 2, 3]. Since k = 3 you have only one way to choose k elements β€” it's to choose all elements [1, \underline{2}, 3] with median 2. That's why after erasing all chosen elements except its median you'll get sequence [2]. In other words, there is no way to get sequence b = [1] as the result. In the second test case, you have sequence [1, 2, 3, 4, 5, 6, 7] and one of the optimal strategies is following: 1. choose k = 3 elements [2, \underline{3}, 4] and erase them except its median; you'll get sequence [1, 3, 5, 6, 7]; 2. choose 3 elements [3, \underline{5}, 6] and erase them except its median; you'll get desired sequence [1, 5, 7]; In the fourth test case, you have sequence [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]. You can choose k=7 elements [2, 4, 6, \underline{7}, 8, 10, 13] and erase them except its median to get sequence b. Submitted Solution: ``` import sys input=sys.stdin.readline t=int(input()) for you in range(t): l=input().split() n=int(l[0]) k=int(l[1]) m=int(l[2]) l=input().split() li=[int(i) for i in l] if((n-m)%(k-1)): print("NO") continue poss=0 for i in range(m): z=n-li[i] z-=(m-i-1) y=li[i]-1 y-=i if(z>=(k-1)//2 and y>=(k-1)//2): poss=1 break if(poss): print("YES") else: print("NO") ```
instruction
0
5,245
12
10,490
Yes
output
1
5,245
12
10,491
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's denote the median of a sequence s with odd length as the value in the middle of s if we sort s in non-decreasing order. For example, let s = [1, 2, 5, 7, 2, 3, 12]. After sorting, we get sequence [1, 2, 2, \underline{3}, 5, 7, 12], and the median is equal to 3. You have a sequence of n integers [1, 2, ..., n] and an odd integer k. In one step, you choose any k elements from the sequence and erase all chosen elements except their median. These elements do not have to go continuously (gaps are allowed between them). For example, if you have a sequence [1, 2, 3, 4, 5, 6, 7] (i.e. n=7) and k = 3, then the following options for the first step are possible: * choose [1, \underline{2}, 3]; 2 is their median, so it is not erased, and the resulting sequence is [2, 4, 5, 6, 7]; * choose [2, \underline{4}, 6]; 4 is their median, so it is not erased, and the resulting sequence is [1, 3, 4, 5, 7]; * choose [1, \underline{6}, 7]; 6 is their median, so it is not erased, and the resulting sequence is [2, 3, 4, 5, 6]; * and several others. You can do zero or more steps. Can you get a sequence b_1, b_2, ..., b_m after several steps? You'll be given t test cases. Solve each test case independently. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains three integers n, k, and m (3 ≀ n ≀ 2 β‹… 10^5; 3 ≀ k ≀ n; k is odd; 1 ≀ m < n) β€” the length of the sequence you have, the number of elements you choose in each step and the length of the sequence you'd like to get. The second line of each test case contains m integers b_1, b_2, ..., b_m (1 ≀ b_1 < b_2 < ... < b_m ≀ n) β€” the sequence you'd like to get, given in the ascending order. It's guaranteed that the total sum of n over all test cases doesn't exceed 2 β‹… 10^5. Output For each test case, print YES if you can obtain the sequence b or NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer). Example Input 4 3 3 1 1 7 3 3 1 5 7 10 5 3 4 5 6 13 7 7 1 3 5 7 9 11 12 Output NO YES NO YES Note In the first test case, you have sequence [1, 2, 3]. Since k = 3 you have only one way to choose k elements β€” it's to choose all elements [1, \underline{2}, 3] with median 2. That's why after erasing all chosen elements except its median you'll get sequence [2]. In other words, there is no way to get sequence b = [1] as the result. In the second test case, you have sequence [1, 2, 3, 4, 5, 6, 7] and one of the optimal strategies is following: 1. choose k = 3 elements [2, \underline{3}, 4] and erase them except its median; you'll get sequence [1, 3, 5, 6, 7]; 2. choose 3 elements [3, \underline{5}, 6] and erase them except its median; you'll get desired sequence [1, 5, 7]; In the fourth test case, you have sequence [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]. You can choose k=7 elements [2, 4, 6, \underline{7}, 8, 10, 13] and erase them except its median to get sequence b. Submitted Solution: ``` # -*- coding: utf-8 -*- """ Created on Sat Jan 16 12:33:14 2021 @author: ludoj """ t=int(input()) res=[] for x1 in range(t): n,k,m=[int(i) for i in input().split()] eind=[int(i) for i in input().split()] x2=len(eind) if (n-m)%(k-1)!=0: res.append("NO") else: h=(k-1)//2 i1=0 a1=1 tel1=0 while(tel1<h and i1<x2): if eind[i1]==a1: a1+=1 i1+=1 else: tel1+=1 a1+=1 #nu gevonden met h dingen ervoor if i1>=x2: res.append("NO") else: a2=eind[i1] tel2=0 while(tel2<h and i1<x2): if eind[i1]==a2: a2+=1 i1+=1 else: tel2+=1 a2+=1 if i1==x2: tel2+=n-eind[i1-1] if tel2>=h: res.append("YES") else: res.append("NO") for i in res: print(i) ```
instruction
0
5,246
12
10,492
Yes
output
1
5,246
12
10,493
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's denote the median of a sequence s with odd length as the value in the middle of s if we sort s in non-decreasing order. For example, let s = [1, 2, 5, 7, 2, 3, 12]. After sorting, we get sequence [1, 2, 2, \underline{3}, 5, 7, 12], and the median is equal to 3. You have a sequence of n integers [1, 2, ..., n] and an odd integer k. In one step, you choose any k elements from the sequence and erase all chosen elements except their median. These elements do not have to go continuously (gaps are allowed between them). For example, if you have a sequence [1, 2, 3, 4, 5, 6, 7] (i.e. n=7) and k = 3, then the following options for the first step are possible: * choose [1, \underline{2}, 3]; 2 is their median, so it is not erased, and the resulting sequence is [2, 4, 5, 6, 7]; * choose [2, \underline{4}, 6]; 4 is their median, so it is not erased, and the resulting sequence is [1, 3, 4, 5, 7]; * choose [1, \underline{6}, 7]; 6 is their median, so it is not erased, and the resulting sequence is [2, 3, 4, 5, 6]; * and several others. You can do zero or more steps. Can you get a sequence b_1, b_2, ..., b_m after several steps? You'll be given t test cases. Solve each test case independently. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains three integers n, k, and m (3 ≀ n ≀ 2 β‹… 10^5; 3 ≀ k ≀ n; k is odd; 1 ≀ m < n) β€” the length of the sequence you have, the number of elements you choose in each step and the length of the sequence you'd like to get. The second line of each test case contains m integers b_1, b_2, ..., b_m (1 ≀ b_1 < b_2 < ... < b_m ≀ n) β€” the sequence you'd like to get, given in the ascending order. It's guaranteed that the total sum of n over all test cases doesn't exceed 2 β‹… 10^5. Output For each test case, print YES if you can obtain the sequence b or NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer). Example Input 4 3 3 1 1 7 3 3 1 5 7 10 5 3 4 5 6 13 7 7 1 3 5 7 9 11 12 Output NO YES NO YES Note In the first test case, you have sequence [1, 2, 3]. Since k = 3 you have only one way to choose k elements β€” it's to choose all elements [1, \underline{2}, 3] with median 2. That's why after erasing all chosen elements except its median you'll get sequence [2]. In other words, there is no way to get sequence b = [1] as the result. In the second test case, you have sequence [1, 2, 3, 4, 5, 6, 7] and one of the optimal strategies is following: 1. choose k = 3 elements [2, \underline{3}, 4] and erase them except its median; you'll get sequence [1, 3, 5, 6, 7]; 2. choose 3 elements [3, \underline{5}, 6] and erase them except its median; you'll get desired sequence [1, 5, 7]; In the fourth test case, you have sequence [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]. You can choose k=7 elements [2, 4, 6, \underline{7}, 8, 10, 13] and erase them except its median to get sequence b. Submitted Solution: ``` """ Author - Satwik Tiwari . 15th Dec , 2020 - Tuesday """ #=============================================================================================== #importing some useful libraries. from __future__ import division, print_function from fractions import Fraction import sys import os from io import BytesIO, IOBase from functools import cmp_to_key # from itertools import * from heapq import * from math import gcd, factorial,floor,ceil,sqrt from copy import deepcopy from collections import deque from bisect import bisect_left as bl from bisect import bisect_right as br from bisect import bisect #============================================================================================== #fast I/O region 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") def print(*args, **kwargs): """Prints the values to a stream, or to sys.stdout by default.""" sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout) at_start = True for x in args: if not at_start: file.write(sep) file.write(str(x)) at_start = False file.write(kwargs.pop("end", "\n")) if kwargs.pop("flush", False): file.flush() if sys.version_info[0] < 3: sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout) else: sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) # inp = lambda: sys.stdin.readline().rstrip("\r\n") #=============================================================================================== ### START ITERATE RECURSION ### from types import GeneratorType def iterative(f, stack=[]): def wrapped_func(*args, **kwargs): if stack: return f(*args, **kwargs) to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) continue stack.pop() if not stack: break to = stack[-1].send(to) return to return wrapped_func #### END ITERATE RECURSION #### #=============================================================================================== #some shortcuts def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input def out(var): sys.stdout.write(str(var)) #for fast output, always take string def lis(): return list(map(int, inp().split())) def stringlis(): return list(map(str, inp().split())) def sep(): return map(int, inp().split()) def strsep(): return map(str, inp().split()) # def graph(vertex): return [[] for i in range(0,vertex+1)] def testcase(t): for pp in range(t): solve(pp) def google(p): print('Case #'+str(p)+': ',end='') def lcm(a,b): return (a*b)//gcd(a,b) def power(x, y, p) : y%=(p-1) #not so sure about this. used when y>p-1. if p is prime. res = 1 # Initialize result x = x % p # Update x if it is more , than or equal to p if (x == 0) : return 0 while (y > 0) : if ((y & 1) == 1) : # If y is odd, multiply, x with result res = (res * x) % p y = y >> 1 # y = y/2 x = (x * x) % p return res def ncr(n,r): return factorial(n) // (factorial(r) * factorial(max(n - r, 1))) def isPrime(n) : if (n <= 1) : return False if (n <= 3) : return True if (n % 2 == 0 or n % 3 == 0) : return False i = 5 while(i * i <= n) : if (n % i == 0 or n % (i + 2) == 0) : return False i = i + 6 return True inf = pow(10,20) mod = 10**9+7 #=============================================================================================== # code here ;)) def solve(case): n,k,m = sep() a = lis() have = set(a) if(len(have) != m): print("NO") return notvis = [] for i in range(1,n+1): if(i not in have): notvis.append(i) if(len(notvis)%(k-1)): # print(len(notvis)) print('NO') return left = 0 right = 0 diff = [] cnt = 1 for i in range(1,len(notvis)): if(notvis[i] == notvis[i-1]+1): cnt+=1 else: diff.append(cnt) cnt = 1 diff.append(cnt) ind = 0 while(left + diff[ind] < k//2): left += diff[ind] ind+=1 rnd = len(diff)-1 while(right + diff[rnd] < k//2): right += diff[rnd] rnd-=1 print('YES' if ind < rnd else 'NO') # testcase(1) testcase(int(inp())) ```
instruction
0
5,247
12
10,494
Yes
output
1
5,247
12
10,495
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's denote the median of a sequence s with odd length as the value in the middle of s if we sort s in non-decreasing order. For example, let s = [1, 2, 5, 7, 2, 3, 12]. After sorting, we get sequence [1, 2, 2, \underline{3}, 5, 7, 12], and the median is equal to 3. You have a sequence of n integers [1, 2, ..., n] and an odd integer k. In one step, you choose any k elements from the sequence and erase all chosen elements except their median. These elements do not have to go continuously (gaps are allowed between them). For example, if you have a sequence [1, 2, 3, 4, 5, 6, 7] (i.e. n=7) and k = 3, then the following options for the first step are possible: * choose [1, \underline{2}, 3]; 2 is their median, so it is not erased, and the resulting sequence is [2, 4, 5, 6, 7]; * choose [2, \underline{4}, 6]; 4 is their median, so it is not erased, and the resulting sequence is [1, 3, 4, 5, 7]; * choose [1, \underline{6}, 7]; 6 is their median, so it is not erased, and the resulting sequence is [2, 3, 4, 5, 6]; * and several others. You can do zero or more steps. Can you get a sequence b_1, b_2, ..., b_m after several steps? You'll be given t test cases. Solve each test case independently. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains three integers n, k, and m (3 ≀ n ≀ 2 β‹… 10^5; 3 ≀ k ≀ n; k is odd; 1 ≀ m < n) β€” the length of the sequence you have, the number of elements you choose in each step and the length of the sequence you'd like to get. The second line of each test case contains m integers b_1, b_2, ..., b_m (1 ≀ b_1 < b_2 < ... < b_m ≀ n) β€” the sequence you'd like to get, given in the ascending order. It's guaranteed that the total sum of n over all test cases doesn't exceed 2 β‹… 10^5. Output For each test case, print YES if you can obtain the sequence b or NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer). Example Input 4 3 3 1 1 7 3 3 1 5 7 10 5 3 4 5 6 13 7 7 1 3 5 7 9 11 12 Output NO YES NO YES Note In the first test case, you have sequence [1, 2, 3]. Since k = 3 you have only one way to choose k elements β€” it's to choose all elements [1, \underline{2}, 3] with median 2. That's why after erasing all chosen elements except its median you'll get sequence [2]. In other words, there is no way to get sequence b = [1] as the result. In the second test case, you have sequence [1, 2, 3, 4, 5, 6, 7] and one of the optimal strategies is following: 1. choose k = 3 elements [2, \underline{3}, 4] and erase them except its median; you'll get sequence [1, 3, 5, 6, 7]; 2. choose 3 elements [3, \underline{5}, 6] and erase them except its median; you'll get desired sequence [1, 5, 7]; In the fourth test case, you have sequence [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]. You can choose k=7 elements [2, 4, 6, \underline{7}, 8, 10, 13] and erase them except its median to get sequence b. Submitted Solution: ``` from sys import stdin tt = int(stdin.readline()) for loop in range(tt): n,k,m = map(int,stdin.readline().split()) b = list(map(int,stdin.readline().split())) if (n-m)%(k-1) != 0: print ("NO") continue c = (n-m)//(k-1) ans = "NO" for i in b: if k//2 < i <= n-k//2: ans = "YES" break print (ans) ```
instruction
0
5,248
12
10,496
No
output
1
5,248
12
10,497
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's denote the median of a sequence s with odd length as the value in the middle of s if we sort s in non-decreasing order. For example, let s = [1, 2, 5, 7, 2, 3, 12]. After sorting, we get sequence [1, 2, 2, \underline{3}, 5, 7, 12], and the median is equal to 3. You have a sequence of n integers [1, 2, ..., n] and an odd integer k. In one step, you choose any k elements from the sequence and erase all chosen elements except their median. These elements do not have to go continuously (gaps are allowed between them). For example, if you have a sequence [1, 2, 3, 4, 5, 6, 7] (i.e. n=7) and k = 3, then the following options for the first step are possible: * choose [1, \underline{2}, 3]; 2 is their median, so it is not erased, and the resulting sequence is [2, 4, 5, 6, 7]; * choose [2, \underline{4}, 6]; 4 is their median, so it is not erased, and the resulting sequence is [1, 3, 4, 5, 7]; * choose [1, \underline{6}, 7]; 6 is their median, so it is not erased, and the resulting sequence is [2, 3, 4, 5, 6]; * and several others. You can do zero or more steps. Can you get a sequence b_1, b_2, ..., b_m after several steps? You'll be given t test cases. Solve each test case independently. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains three integers n, k, and m (3 ≀ n ≀ 2 β‹… 10^5; 3 ≀ k ≀ n; k is odd; 1 ≀ m < n) β€” the length of the sequence you have, the number of elements you choose in each step and the length of the sequence you'd like to get. The second line of each test case contains m integers b_1, b_2, ..., b_m (1 ≀ b_1 < b_2 < ... < b_m ≀ n) β€” the sequence you'd like to get, given in the ascending order. It's guaranteed that the total sum of n over all test cases doesn't exceed 2 β‹… 10^5. Output For each test case, print YES if you can obtain the sequence b or NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer). Example Input 4 3 3 1 1 7 3 3 1 5 7 10 5 3 4 5 6 13 7 7 1 3 5 7 9 11 12 Output NO YES NO YES Note In the first test case, you have sequence [1, 2, 3]. Since k = 3 you have only one way to choose k elements β€” it's to choose all elements [1, \underline{2}, 3] with median 2. That's why after erasing all chosen elements except its median you'll get sequence [2]. In other words, there is no way to get sequence b = [1] as the result. In the second test case, you have sequence [1, 2, 3, 4, 5, 6, 7] and one of the optimal strategies is following: 1. choose k = 3 elements [2, \underline{3}, 4] and erase them except its median; you'll get sequence [1, 3, 5, 6, 7]; 2. choose 3 elements [3, \underline{5}, 6] and erase them except its median; you'll get desired sequence [1, 5, 7]; In the fourth test case, you have sequence [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]. You can choose k=7 elements [2, 4, 6, \underline{7}, 8, 10, 13] and erase them except its median to get sequence b. Submitted Solution: ``` import heapq t = int(input()) for _ in range(t): n, k, m = map(int, input().split()) l = [0] + list(map(int, input().split())) + [n+1] diffs = [l[i+1]-l[i]-1 for i in range(m+1)] if sum(diffs) % (k-1) > 0: print('NO') continue q = [] tot = 0 for v in diffs: heapq.heappush(q, -v) tot += v while True: nex = -heapq.heappop(q) if 2 * nex <= tot: print('YES') break if nex < k: print('NO') break tot -= k - 1 heapq.heappush(q,(nex - (k-1))) ```
instruction
0
5,249
12
10,498
No
output
1
5,249
12
10,499
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's denote the median of a sequence s with odd length as the value in the middle of s if we sort s in non-decreasing order. For example, let s = [1, 2, 5, 7, 2, 3, 12]. After sorting, we get sequence [1, 2, 2, \underline{3}, 5, 7, 12], and the median is equal to 3. You have a sequence of n integers [1, 2, ..., n] and an odd integer k. In one step, you choose any k elements from the sequence and erase all chosen elements except their median. These elements do not have to go continuously (gaps are allowed between them). For example, if you have a sequence [1, 2, 3, 4, 5, 6, 7] (i.e. n=7) and k = 3, then the following options for the first step are possible: * choose [1, \underline{2}, 3]; 2 is their median, so it is not erased, and the resulting sequence is [2, 4, 5, 6, 7]; * choose [2, \underline{4}, 6]; 4 is their median, so it is not erased, and the resulting sequence is [1, 3, 4, 5, 7]; * choose [1, \underline{6}, 7]; 6 is their median, so it is not erased, and the resulting sequence is [2, 3, 4, 5, 6]; * and several others. You can do zero or more steps. Can you get a sequence b_1, b_2, ..., b_m after several steps? You'll be given t test cases. Solve each test case independently. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains three integers n, k, and m (3 ≀ n ≀ 2 β‹… 10^5; 3 ≀ k ≀ n; k is odd; 1 ≀ m < n) β€” the length of the sequence you have, the number of elements you choose in each step and the length of the sequence you'd like to get. The second line of each test case contains m integers b_1, b_2, ..., b_m (1 ≀ b_1 < b_2 < ... < b_m ≀ n) β€” the sequence you'd like to get, given in the ascending order. It's guaranteed that the total sum of n over all test cases doesn't exceed 2 β‹… 10^5. Output For each test case, print YES if you can obtain the sequence b or NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer). Example Input 4 3 3 1 1 7 3 3 1 5 7 10 5 3 4 5 6 13 7 7 1 3 5 7 9 11 12 Output NO YES NO YES Note In the first test case, you have sequence [1, 2, 3]. Since k = 3 you have only one way to choose k elements β€” it's to choose all elements [1, \underline{2}, 3] with median 2. That's why after erasing all chosen elements except its median you'll get sequence [2]. In other words, there is no way to get sequence b = [1] as the result. In the second test case, you have sequence [1, 2, 3, 4, 5, 6, 7] and one of the optimal strategies is following: 1. choose k = 3 elements [2, \underline{3}, 4] and erase them except its median; you'll get sequence [1, 3, 5, 6, 7]; 2. choose 3 elements [3, \underline{5}, 6] and erase them except its median; you'll get desired sequence [1, 5, 7]; In the fourth test case, you have sequence [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]. You can choose k=7 elements [2, 4, 6, \underline{7}, 8, 10, 13] and erase them except its median to get sequence b. Submitted Solution: ``` import math T = int(input()) for _ in range(T): n, k, m = map(int, input().split()) b = [int(i) for i in input().split()] if b == [int(i)+1 for i in range(n)]: print('YES') elif b[0]-1 <= n - b[0] - len(b) +1 and n - b[-1] <= b[-1] - 1 - len(b) + 1 and k>1 and (n-m)%(k-1)==0: print('YES') else: print('NO') ```
instruction
0
5,250
12
10,500
No
output
1
5,250
12
10,501
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's denote the median of a sequence s with odd length as the value in the middle of s if we sort s in non-decreasing order. For example, let s = [1, 2, 5, 7, 2, 3, 12]. After sorting, we get sequence [1, 2, 2, \underline{3}, 5, 7, 12], and the median is equal to 3. You have a sequence of n integers [1, 2, ..., n] and an odd integer k. In one step, you choose any k elements from the sequence and erase all chosen elements except their median. These elements do not have to go continuously (gaps are allowed between them). For example, if you have a sequence [1, 2, 3, 4, 5, 6, 7] (i.e. n=7) and k = 3, then the following options for the first step are possible: * choose [1, \underline{2}, 3]; 2 is their median, so it is not erased, and the resulting sequence is [2, 4, 5, 6, 7]; * choose [2, \underline{4}, 6]; 4 is their median, so it is not erased, and the resulting sequence is [1, 3, 4, 5, 7]; * choose [1, \underline{6}, 7]; 6 is their median, so it is not erased, and the resulting sequence is [2, 3, 4, 5, 6]; * and several others. You can do zero or more steps. Can you get a sequence b_1, b_2, ..., b_m after several steps? You'll be given t test cases. Solve each test case independently. Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains three integers n, k, and m (3 ≀ n ≀ 2 β‹… 10^5; 3 ≀ k ≀ n; k is odd; 1 ≀ m < n) β€” the length of the sequence you have, the number of elements you choose in each step and the length of the sequence you'd like to get. The second line of each test case contains m integers b_1, b_2, ..., b_m (1 ≀ b_1 < b_2 < ... < b_m ≀ n) β€” the sequence you'd like to get, given in the ascending order. It's guaranteed that the total sum of n over all test cases doesn't exceed 2 β‹… 10^5. Output For each test case, print YES if you can obtain the sequence b or NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer). Example Input 4 3 3 1 1 7 3 3 1 5 7 10 5 3 4 5 6 13 7 7 1 3 5 7 9 11 12 Output NO YES NO YES Note In the first test case, you have sequence [1, 2, 3]. Since k = 3 you have only one way to choose k elements β€” it's to choose all elements [1, \underline{2}, 3] with median 2. That's why after erasing all chosen elements except its median you'll get sequence [2]. In other words, there is no way to get sequence b = [1] as the result. In the second test case, you have sequence [1, 2, 3, 4, 5, 6, 7] and one of the optimal strategies is following: 1. choose k = 3 elements [2, \underline{3}, 4] and erase them except its median; you'll get sequence [1, 3, 5, 6, 7]; 2. choose 3 elements [3, \underline{5}, 6] and erase them except its median; you'll get desired sequence [1, 5, 7]; In the fourth test case, you have sequence [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]. You can choose k=7 elements [2, 4, 6, \underline{7}, 8, 10, 13] and erase them except its median to get sequence b. Submitted Solution: ``` # by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO, IOBase def solve(n,k,m,b): if (n-m)%(k-1): return 'NO' fl = 0 if b[0] != 1 and b[-1] != n: fl = 1 for i in range(1,m): if b[i] != b[i-1]+1: fl = 1 if fl: return 'YES' return 'NO' def main(): for _ in range(int(input())): n,k,m = map(int,input().split()) b = list(map(int,input().split())) print(solve(n,k,m,b)) #Fast IO Region 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() ```
instruction
0
5,251
12
10,502
No
output
1
5,251
12
10,503
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4
instruction
0
5,307
12
10,614
Tags: constructive algorithms, math Correct Solution: ``` n = int(input()) if n % 4 > 1: print(-1) exit() a = [i for i in range(0, n+1)] for i in range(1, n//2+1, 2): p, q, r, s = i, i+1, n-i,n-i+1 a[p], a[q], a[r], a[s] = a[q], a[s], a[p], a[r] def check(arr): for i in range(1, n+1): k = arr[i] if arr[arr[k]] != n-k+1: return False return True # print(check(a)) print(*a[1:]) ```
output
1
5,307
12
10,615
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4
instruction
0
5,308
12
10,616
Tags: constructive algorithms, math Correct Solution: ``` n=int(input()) if n%4==2 or n%4==3: from sys import exit print(-1);exit() res,i=[0]*n,0 for i in range(0,n//2,2): res[i],res[i+1]=i+2,n-i res[n-i-1],res[n-i-2]=n-i-1,i+1 i+=2 if n%4==1:res[n//2]=n//2+1 print(*res) ```
output
1
5,308
12
10,617
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4
instruction
0
5,309
12
10,618
Tags: constructive algorithms, math Correct Solution: ``` from math import * n = int(input()) if n == 1: print(1) elif n % 4 in [2, 3]: print(-1) else: ans = [0] * n for i in range(n // 2): if i & 1: ans[i] = n - 2 * (i // 2) else: ans[i] = 2 + i for i in range(1, (n // 2), 2): ans[ans[i] - 1] = n - i ans[n - i - 1] = n - (n - i) if n % 4 < 3 and n % 4 > 0: ans[n // 2] = ceil(n / 2) elif n % 4 == 3: ans[int(floor(n / 2))] = ans[int(floor(n / 2)) - 1] + 1 ans[int(ceil(n / 2))] = ans[int(ceil(n / 2)) - 1] - 2 print(*ans) ```
output
1
5,309
12
10,619
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4
instruction
0
5,310
12
10,620
Tags: constructive algorithms, math Correct Solution: ``` n=int(input()) L=[0]*(n+1) X=[False]*(n+1) if(n%4!=0 and n%4!=1): print(-1) else: for i in range(1,n+1): if(X[i]): continue X[i]=True X[n-i+1]=True for j in range(i+1,n+1): if(X[j]): continue X[j]=True X[n-j+1]=True L[i]=j L[n-i+1]=n-j+1 L[j]=n-i+1 L[n-j+1]=i break if(n%4==1): L[n//2+1]=n//2+1 for i in range(1,n): print(L[i],end=" ") print(L[n]) ```
output
1
5,310
12
10,621
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4
instruction
0
5,311
12
10,622
Tags: constructive algorithms, math Correct Solution: ``` n=int(input()) if(n%4>1): print(-1) else: ans=[0]*(n+1) i,j,a,b=1,n,1,n while(i<j and a<=n and b>=1): ans[i],ans[j]=a+1,b-1 ans[i+1],ans[j-1]=b,a i+=2 j-=2 a+=2 b-=2 if(i==j): ans[i]=a for i in range(1,n+1): print(ans[i],end=' ') ```
output
1
5,311
12
10,623
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4
instruction
0
5,312
12
10,624
Tags: constructive algorithms, math Correct Solution: ``` n=int(input()) if (n//2)&1: print(-1) else: ans=[0]*(n+1) for i in range(1,(n//2)+1,2): ans[i]=i+1 ans[i+1]=n-i+1 ans[n-i+1]=n-i ans[n-i]=i if n%2: ans[(n//2)+1]=(n//2)+1 print(*ans[1:]) ```
output
1
5,312
12
10,625
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4
instruction
0
5,313
12
10,626
Tags: constructive algorithms, math Correct Solution: ``` ''' Created on @author: linhz ''' import sys usedNum=0 n=int(input()) p=[0 for i in range(n+1)] usedNum=0 if n%4==3 or n%4==2: print(-1) else: i=1 j=n a=1 b=n while j>i: p[i]=a+1 p[i+1]=b p[j]=b-1 p[j-1]=a i+=2 j-=2 a+=2 b-=2 if j==i: p[i]=a ans="" for i in range(1,n+1): ans+=str(p[i])+" " print(ans) ```
output
1
5,313
12
10,627
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4
instruction
0
5,314
12
10,628
Tags: constructive algorithms, math Correct Solution: ``` from itertools import permutations from sys import stdin def checkit(vector, upto=-1): if upto == -1: upto = len(vector) for i in range(0, upto): if vector[vector[i] - 1] != len(vector) - (i + 1) + 1: return False return True def calculate(n): numbers = list(range(1, n + 1)) result = [0] * n for i in range(0, n): if result[i] != 0: continue if i > 0 and checkit(result, i): continue expected = n - i for v in numbers: if v - 1 == i and expected != v: continue if v == expected: result[v-1] = v numbers.remove(v) break elif result[v - 1] == expected: numbers.remove(v) result[i] = v break elif result[v - 1] == 0: assert expected in numbers result[i] = v result[v - 1] = expected numbers.remove(v) numbers.remove(expected) break return result def calculate_v2(n): result = [0] * n first_sum = n + 2 second_sum = n nf = n i = 0 while nf > first_sum // 2: result[i] = first_sum - nf result[i + 1] = nf nf -= 2 i += 2 if n % 2 == 1: result[i] = i + 1 i = n - 1 while i > n // 2: result[i] = i result[i-1] = second_sum - i i -= 2 return result def main(): number = int(stdin.readline()) result = calculate_v2(number) if not checkit(result): print(-1) else: print(" ".join([str(v) for v in result])) if __name__ == "__main__": main() ```
output
1
5,314
12
10,629
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4 Submitted Solution: ``` n = int(input()) if n%4 > 1: print(-1) else: a = [n+1>>1]*n for i in range(n//4): j = i*2 a[j], a[j+1], a[-2-j], a[-1-j] = j+2, n-j, j+1, n-1-j print(' '.join(map(str, a))) ```
instruction
0
5,315
12
10,630
Yes
output
1
5,315
12
10,631
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4 Submitted Solution: ``` n=int(input()) if n%4>1:print(-1) else: ans=[i for i in range(1,n+1)] for i in range(0,n//2,2): ans[i]=i+2 ans[i+1]=n-i ans[n-i-1]=n-i-1 ans[n-i-2]=i+1 print(*ans) ```
instruction
0
5,316
12
10,632
Yes
output
1
5,316
12
10,633
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4 Submitted Solution: ``` n = int(input()) if n % 4 > 1: print(-1) exit() a = [i for i in range(0, n+1)] for i in range(1, n//2+1, 2): p, q, r, s = i, i+1, n-i,n-i+1 a[p], a[q], a[r], a[s] = a[q], a[s], a[p], a[r] def check(arr): for i in range(1, n+1): k = arr[i] if arr[arr[k]] != n-k+1: return False return True # print(check(a)) print(*a[1:]) # Made By Mostafa_Khaled ```
instruction
0
5,317
12
10,634
Yes
output
1
5,317
12
10,635
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4 Submitted Solution: ``` n=int(input()) if n==1: print (1) exit() if n%4>1: print (-1) exit() ans=[-1]*n left=n start=n-2 nums=1 nume=n while left>=4: ans[start]=nums ans[nums-1]=nums+1 ans[nums]=nume ans[nume-1]=nume-1 start-=2 nums+=2 nume-=2 left-=4 # print (ans) if left==1: ans[start+1]=start+2 print (*ans) ```
instruction
0
5,318
12
10,636
Yes
output
1
5,318
12
10,637
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4 Submitted Solution: ``` import math n = int(input()) ans = 1 s = [1, 1, 1] for a in range(n-100, n-1): for b in range(a+1, n): m1 = a * b for c in range(b+1, n+1): if (m1 * c // math.gcd(c, m1) >= ans): ans = m1 * c // math.gcd(a, m1) s = [a, b, c] print(ans) # print(s) ```
instruction
0
5,319
12
10,638
No
output
1
5,319
12
10,639
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4 Submitted Solution: ``` import sys from collections import deque n = int(input()) if n % 4 == 2 or n % 4 == 3: print('-1') sys.exit(0) arr = [None] * (n + 1) qt = deque([i for i in range(1, n + 1)]) mark = set() while qt: while qt and qt[0] in mark: qt.popleft() if not qt: break a = qt.popleft() while qt and qt[0] in mark: qt.popleft() if not qt: break b = qt.popleft() for i in range(4): mark.add(a) mark.add(b) arr[a] = b arr[b] = n - a + 1 a = b b = arr[b] for i in range(1, n + 1): if not arr[i]: arr[i] = a break ```
instruction
0
5,320
12
10,640
No
output
1
5,320
12
10,641
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4 Submitted 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") ########################################################## #q.sort(key=lambda x:((x[1]-x[0]),-x[0])) #from collections import Counter #from fractions import Fraction from bisect import bisect_left from collections import Counter #s=iter(input()) #from collections import deque #ls=list(map(int,input().split())) #for in range(m): #for _ in range(int(input())): #n=int(input()) # n,k=map(int,input().split()) # arr=list(map(int,input().split())) #for i in range(int(input())): #n=int(input()) #arr=sorted([(x,i) for i,x in enumerate(map(int,input().split()))])[::-1] #print(arr) #arr=sorted(list(map(int,input().split())))[::-1] n=int(input()) if n==1: print(1) elif n==2: print(-1) else: print(n-1,end=" ") print(1,end=" ") for i in range(2,n+1): if i==n-1: continue print(i,end=" ") ```
instruction
0
5,321
12
10,642
No
output
1
5,321
12
10,643
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4 Submitted Solution: ``` from math import * n = int(input()) if n == 1: print(1) elif n % 4 == 2: print(-1) else: ans = [0] * n for i in range(n // 2): if i & 1: ans[i] = n - 2 * (i // 2) else: ans[i] = 2 + i for i in range(1, (n // 2), 2): ans[ans[i] - 1] = n - i ans[n - i - 1] = n - (n - i) if n % 4 < 3 and n % 4 > 0: ans[n // 2] = ceil(n / 2) elif n % 4 == 3: ans[int(floor(n / 2))] = ans[int(floor(n / 2)) - 1] + 1 ans[int(ceil(n / 2))] = ans[int(ceil(n / 2)) - 1] - 2 print(*ans) ```
instruction
0
5,322
12
10,644
No
output
1
5,322
12
10,645
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bubble Sort Bubble sort is one of the algorithms for sorting columns. Suppose you want to sort the sequence A of length N in ascending order. Bubble sort exchanges the positions of two adjacent numbers if the magnitude relationship is broken. This is done while scanning the sequence from the front. That is, if there is a place where Ai> Ai + 1, the two numbers are exchanged once for i = 1, 2, ..., N βˆ’ 1 in this order. It is a scan of. It is known that the sequence can be sorted in ascending order by repeating this scan N βˆ’ 1 time. The number of exchanges by bubble sort in sequence A is the number of times integers are exchanged when the above algorithm is applied to sequence A. (Algorithms and implementations known as bubble sort may have small differences in loop order, range, end conditions, etc. However, the number of integer exchanges when applied to the same sequence depends on those differences. It is known that it does not change.) For example, the following program describes a function that sorts an array a of integers of length n by bubble sort in C language. void bubble_sort (int * a, int n) { int i, j; for (i = 0; i <n -1; ++ i) { for (j = 0; j <n -1; ++ j) { if (a [j]> a [j + 1]) { / * The following 3 lines are equivalent to one integer exchange * / int x = a [j]; a [j] = a [j + 1]; a [j + 1] = x; } } } } Task Given a sequence A of length N. Suppose you create a sequence A'by exchanging two integers anywhere in the sequence A only once. Create a program that finds the minimum number of exchanges by bubble sort in the sequence A'. (Note that the first two integers to be exchanged do not necessarily have to be next to each other.) Limits * 1 ≀ N ≀ 100 000 Length of sequence A * 1 ≀ Ai ≀ 1 000 000 000 The size of the numbers in the sequence A input Read the following data from standard input. * The integer N is written on the first line. N represents the length of the sequence A. * The integer Ai is written on the i-th line (1 ≀ i ≀ N) of the following N lines. This represents the i-th integer in the sequence A. output Output to the standard output an integer representing the minimum number of exchanges by bubble sort in the sequence A'on one line. Scoring criteria * Of the scoring data, 10% of the points are satisfied with N ≀ 1 000, and Ai β‰  Aj is satisfied with any i, j (1 ≀ i <j ≀ N). * Of the scoring data, 30% of the points are satisfied with N ≀ 5 000, and Ai β‰  Aj is satisfied for any i, j (1 ≀ i <j ≀ N). * Of the scoring data, 80% of the points are given by satisfying Ai β‰  Aj for any i, j (1 ≀ i <j ≀ N). Input / output example Input example 1 Five Ten 3 6 8 1 Output example 1 0 If we decide to exchange the first 10 and the last 1 of the sequence A, the sequence A'will be a sorted column and the number of bubble sort exchanges will be 0. Input example 2 Five 3 1 7 9 Five Output example 2 2 By exchanging the third 7 and the last 5 of the sequence A, the sequence A'becomes 3,1,5,9,7. The number of exchanges of A'by bubble sort is 2. Input example 3 3 1 2 3 Output example 3 1 Even if the sequence A is sorted from the beginning, it must be exchanged when creating the sequence A'. The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics. Example Input 5 10 3 6 8 1 Output 0 Submitted Solution: ``` import copy def count_sort_count(numbers): count = 0 for index_of_a in range(len(numbers)-1): for index_of_b in range(index_of_a + 1, len(numbers)): if numbers[index_of_a] > numbers[index_of_b]: numbers[index_of_a], numbers[index_of_b] = (numbers[index_of_b], numbers[index_of_a]) count += 1 return count, numbers def different_positions(answer, numbers): different_positions = [-1 for index in range(len(numbers))] index = 0 for answer_value in answer: for position in range(len(numbers)): if numbers[position] == answer_value: different_positions[index] = abs(index - position) index += 1 return different_positions def find_best_swap_position(answer, numbers, max_different_position): min_sum = 1000000 min_pattern = None for i in range(len(numbers)): if i != max_different_position: pattern = copy.deepcopy(numbers) pattern[i], pattern[max_different_position] = (pattern[max_different_position], pattern[i]) sum_different = sum(different_positions(answer, pattern)) if min_sum > sum_different: min_sum = sum_different min_pattern = pattern return min_pattern numbers = [-1 for i in range(int(input()))] numbers = list(map(lambda x: int(input()), numbers)) base_sort_count, answer = count_sort_count(copy.deepcopy(numbers)) if base_sort_count == 0: print(1) else: differents = different_positions(answer, numbers) max_different_position = differents.index(max(differents)) swaped = find_best_swap_position(answer, numbers, max_different_position) print(count_sort_count(swaped)[0]) ```
instruction
0
5,742
12
11,484
No
output
1
5,742
12
11,485
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bubble Sort Bubble sort is one of the algorithms for sorting columns. Suppose you want to sort the sequence A of length N in ascending order. Bubble sort exchanges the positions of two adjacent numbers if the magnitude relationship is broken. This is done while scanning the sequence from the front. That is, if there is a place where Ai> Ai + 1, the two numbers are exchanged once for i = 1, 2, ..., N βˆ’ 1 in this order. It is a scan of. It is known that the sequence can be sorted in ascending order by repeating this scan N βˆ’ 1 time. The number of exchanges by bubble sort in sequence A is the number of times integers are exchanged when the above algorithm is applied to sequence A. (Algorithms and implementations known as bubble sort may have small differences in loop order, range, end conditions, etc. However, the number of integer exchanges when applied to the same sequence depends on those differences. It is known that it does not change.) For example, the following program describes a function that sorts an array a of integers of length n by bubble sort in C language. void bubble_sort (int * a, int n) { int i, j; for (i = 0; i <n -1; ++ i) { for (j = 0; j <n -1; ++ j) { if (a [j]> a [j + 1]) { / * The following 3 lines are equivalent to one integer exchange * / int x = a [j]; a [j] = a [j + 1]; a [j + 1] = x; } } } } Task Given a sequence A of length N. Suppose you create a sequence A'by exchanging two integers anywhere in the sequence A only once. Create a program that finds the minimum number of exchanges by bubble sort in the sequence A'. (Note that the first two integers to be exchanged do not necessarily have to be next to each other.) Limits * 1 ≀ N ≀ 100 000 Length of sequence A * 1 ≀ Ai ≀ 1 000 000 000 The size of the numbers in the sequence A input Read the following data from standard input. * The integer N is written on the first line. N represents the length of the sequence A. * The integer Ai is written on the i-th line (1 ≀ i ≀ N) of the following N lines. This represents the i-th integer in the sequence A. output Output to the standard output an integer representing the minimum number of exchanges by bubble sort in the sequence A'on one line. Scoring criteria * Of the scoring data, 10% of the points are satisfied with N ≀ 1 000, and Ai β‰  Aj is satisfied with any i, j (1 ≀ i <j ≀ N). * Of the scoring data, 30% of the points are satisfied with N ≀ 5 000, and Ai β‰  Aj is satisfied for any i, j (1 ≀ i <j ≀ N). * Of the scoring data, 80% of the points are given by satisfying Ai β‰  Aj for any i, j (1 ≀ i <j ≀ N). Input / output example Input example 1 Five Ten 3 6 8 1 Output example 1 0 If we decide to exchange the first 10 and the last 1 of the sequence A, the sequence A'will be a sorted column and the number of bubble sort exchanges will be 0. Input example 2 Five 3 1 7 9 Five Output example 2 2 By exchanging the third 7 and the last 5 of the sequence A, the sequence A'becomes 3,1,5,9,7. The number of exchanges of A'by bubble sort is 2. Input example 3 3 1 2 3 Output example 3 1 Even if the sequence A is sorted from the beginning, it must be exchanged when creating the sequence A'. The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics. Example Input 5 10 3 6 8 1 Output 0 Submitted Solution: ``` # coding: utf-8 import copy def count_sort_count(numbers): count = 0 for index_of_a in range(len(numbers)-1): for index_of_b in range(index_of_a + 1, len(numbers)): if numbers[index_of_a] > numbers[index_of_b]: numbers[index_of_a], numbers[index_of_b] = (numbers[index_of_b], numbers[index_of_a]) count += 1 return count, numbers def different_positions(answer, numbers): different_positions = [index for index in range(len(numbers))] different_positions = list(map(lambda x: abs(answer.index(numbers[x]) - x), different_positions)) return different_positions def find_best_swap_position(answer, numbers, differents, max_different_position): min_sum = 1000000 min_pattern = None for i in range(len(numbers)): if differents[i] == 0: continue if i != max_different_position: pattern = copy.deepcopy(numbers) pattern[i], pattern[max_different_position] = (pattern[max_different_position], pattern[i]) sum_different = sum(different_positions(answer, pattern)) if min_sum > sum_different: min_sum = sum_different min_pattern = pattern return min_pattern numbers = [-1 for i in range(int(input()))] numbers = list(map(lambda x: int(input()), numbers)) base_sort_count, answer = count_sort_count(copy.deepcopy(numbers)) if base_sort_count == 0: print(1) else: differents = different_positions(answer, numbers) max_different_position = differents.index(max(differents)) swaped = find_best_swap_position(answer, numbers, differents, max_different_position) print(count_sort_count(swaped)[0]) ```
instruction
0
5,743
12
11,486
No
output
1
5,743
12
11,487
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bubble Sort Bubble sort is one of the algorithms for sorting columns. Suppose you want to sort the sequence A of length N in ascending order. Bubble sort exchanges the positions of two adjacent numbers if the magnitude relationship is broken. This is done while scanning the sequence from the front. That is, if there is a place where Ai> Ai + 1, the two numbers are exchanged once for i = 1, 2, ..., N βˆ’ 1 in this order. It is a scan of. It is known that the sequence can be sorted in ascending order by repeating this scan N βˆ’ 1 time. The number of exchanges by bubble sort in sequence A is the number of times integers are exchanged when the above algorithm is applied to sequence A. (Algorithms and implementations known as bubble sort may have small differences in loop order, range, end conditions, etc. However, the number of integer exchanges when applied to the same sequence depends on those differences. It is known that it does not change.) For example, the following program describes a function that sorts an array a of integers of length n by bubble sort in C language. void bubble_sort (int * a, int n) { int i, j; for (i = 0; i <n -1; ++ i) { for (j = 0; j <n -1; ++ j) { if (a [j]> a [j + 1]) { / * The following 3 lines are equivalent to one integer exchange * / int x = a [j]; a [j] = a [j + 1]; a [j + 1] = x; } } } } Task Given a sequence A of length N. Suppose you create a sequence A'by exchanging two integers anywhere in the sequence A only once. Create a program that finds the minimum number of exchanges by bubble sort in the sequence A'. (Note that the first two integers to be exchanged do not necessarily have to be next to each other.) Limits * 1 ≀ N ≀ 100 000 Length of sequence A * 1 ≀ Ai ≀ 1 000 000 000 The size of the numbers in the sequence A input Read the following data from standard input. * The integer N is written on the first line. N represents the length of the sequence A. * The integer Ai is written on the i-th line (1 ≀ i ≀ N) of the following N lines. This represents the i-th integer in the sequence A. output Output to the standard output an integer representing the minimum number of exchanges by bubble sort in the sequence A'on one line. Scoring criteria * Of the scoring data, 10% of the points are satisfied with N ≀ 1 000, and Ai β‰  Aj is satisfied with any i, j (1 ≀ i <j ≀ N). * Of the scoring data, 30% of the points are satisfied with N ≀ 5 000, and Ai β‰  Aj is satisfied for any i, j (1 ≀ i <j ≀ N). * Of the scoring data, 80% of the points are given by satisfying Ai β‰  Aj for any i, j (1 ≀ i <j ≀ N). Input / output example Input example 1 Five Ten 3 6 8 1 Output example 1 0 If we decide to exchange the first 10 and the last 1 of the sequence A, the sequence A'will be a sorted column and the number of bubble sort exchanges will be 0. Input example 2 Five 3 1 7 9 Five Output example 2 2 By exchanging the third 7 and the last 5 of the sequence A, the sequence A'becomes 3,1,5,9,7. The number of exchanges of A'by bubble sort is 2. Input example 3 3 1 2 3 Output example 3 1 Even if the sequence A is sorted from the beginning, it must be exchanged when creating the sequence A'. The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics. Example Input 5 10 3 6 8 1 Output 0 Submitted Solution: ``` # coding: utf-8 import copy line_count = int(input()) numbers = [int(input()) for i in range(line_count)] def make_pattern(numbers): all_pattern = [] for i in range(len(numbers)-1): for j in range(i + 1, len(numbers)): pattern = copy.deepcopy(numbers) pattern[i],pattern[j] = (pattern[j], pattern[i]) all_pattern.append((pattern, i, j)) return all_pattern def count_bubble_sort(numbers): count = 0 for i in range(len(numbers)-1): for k in range(i + 1, len(numbers)): if numbers[i] > numbers[k]: numbers[i], numbers[k] = (numbers[k], numbers[i]) count += 1 return count min_sort_count = 10000 for i in make_pattern(numbers): count = count_bubble_sort(i[0]) if min_sort_count > count: min_sort_count = count print(count) ```
instruction
0
5,744
12
11,488
No
output
1
5,744
12
11,489
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bubble Sort Bubble sort is one of the algorithms for sorting columns. Suppose you want to sort the sequence A of length N in ascending order. Bubble sort exchanges the positions of two adjacent numbers if the magnitude relationship is broken. This is done while scanning the sequence from the front. That is, if there is a place where Ai> Ai + 1, the two numbers are exchanged once for i = 1, 2, ..., N βˆ’ 1 in this order. It is a scan of. It is known that the sequence can be sorted in ascending order by repeating this scan N βˆ’ 1 time. The number of exchanges by bubble sort in sequence A is the number of times integers are exchanged when the above algorithm is applied to sequence A. (Algorithms and implementations known as bubble sort may have small differences in loop order, range, end conditions, etc. However, the number of integer exchanges when applied to the same sequence depends on those differences. It is known that it does not change.) For example, the following program describes a function that sorts an array a of integers of length n by bubble sort in C language. void bubble_sort (int * a, int n) { int i, j; for (i = 0; i <n -1; ++ i) { for (j = 0; j <n -1; ++ j) { if (a [j]> a [j + 1]) { / * The following 3 lines are equivalent to one integer exchange * / int x = a [j]; a [j] = a [j + 1]; a [j + 1] = x; } } } } Task Given a sequence A of length N. Suppose you create a sequence A'by exchanging two integers anywhere in the sequence A only once. Create a program that finds the minimum number of exchanges by bubble sort in the sequence A'. (Note that the first two integers to be exchanged do not necessarily have to be next to each other.) Limits * 1 ≀ N ≀ 100 000 Length of sequence A * 1 ≀ Ai ≀ 1 000 000 000 The size of the numbers in the sequence A input Read the following data from standard input. * The integer N is written on the first line. N represents the length of the sequence A. * The integer Ai is written on the i-th line (1 ≀ i ≀ N) of the following N lines. This represents the i-th integer in the sequence A. output Output to the standard output an integer representing the minimum number of exchanges by bubble sort in the sequence A'on one line. Scoring criteria * Of the scoring data, 10% of the points are satisfied with N ≀ 1 000, and Ai β‰  Aj is satisfied with any i, j (1 ≀ i <j ≀ N). * Of the scoring data, 30% of the points are satisfied with N ≀ 5 000, and Ai β‰  Aj is satisfied for any i, j (1 ≀ i <j ≀ N). * Of the scoring data, 80% of the points are given by satisfying Ai β‰  Aj for any i, j (1 ≀ i <j ≀ N). Input / output example Input example 1 Five Ten 3 6 8 1 Output example 1 0 If we decide to exchange the first 10 and the last 1 of the sequence A, the sequence A'will be a sorted column and the number of bubble sort exchanges will be 0. Input example 2 Five 3 1 7 9 Five Output example 2 2 By exchanging the third 7 and the last 5 of the sequence A, the sequence A'becomes 3,1,5,9,7. The number of exchanges of A'by bubble sort is 2. Input example 3 3 1 2 3 Output example 3 1 Even if the sequence A is sorted from the beginning, it must be exchanged when creating the sequence A'. The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics. Example Input 5 10 3 6 8 1 Output 0 Submitted Solution: ``` import copy def main(): N = int(input()) A = [] for _ in range(N): A.append(int(input())) A_s = sorted(A) #A_sorted B = [] for x in range(N - 1): for y in range(x + 1, N): hoge = copy.deepcopy(A) tmp = hoge[x] hoge[x] = hoge[y] hoge[y] = tmp B.append(hoge) Ans = [] for x in range(len(B)): cnt = 0 for _ in range(N - 1): for y in range(N - 1): if B[x] == A_s: break elif B[x][y] > B[x][y + 1]: cnt += 1 tmp = B[x][y] B[x][y] = B[x][y + 1] B[x][y + 1] = tmp if len(Ans) == 0: Ans.append(cnt) else: if Ans[0] > cnt: Ans[0] = cnt print(Ans[0]) if __name__ == "__main__": main() ```
instruction
0
5,745
12
11,490
No
output
1
5,745
12
11,491
Provide a correct Python 3 solution for this coding contest problem. B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\}, where L is the permutation on the left side of q_i and R is the permutation on the right side of q_i, the original permutation L \\ q_i \\ R is R \\ Change to q_i \\ L. That is, when q_ {i} = a_j, the permutations \\ {a_1, ..., a_ {j-1}, a_j, a_ {j + 1}, ..., a_N \\} are \\ { Change to a_ {j + 1}, ..., a_N, a_j, a_1, ..., a_ {j-1} \\}. The permutations L and R may be empty. For example, if L is empty, change q_i \\ R to R \\ q_i. The same is true when R is empty. Output the permutation after processing these Q queries in order for the given permutation on one line. Input format N Q a_1 a_2 ... a_N q_1 q_2 ... q_Q All inputs are integers. The first row gives the number of elements in the permutation N and the number of queries Q, separated by blanks. In the second line, permutations a_1, a_2, ..., a_N, in which integers from 1 to N are rearranged, are given separated by blanks. The third line gives Q queries, separated by blanks. q_i represents the i-th query. Constraint * 1 \ leq N \ leq 10 ^ 5 * 1 \ leq Q \ leq 10 ^ 5 * 1 \ leq a_i \ leq N * a_i is different * 1 \ leq q_i \ leq N Output format Output the permutation after processing all the queries in order on one line. Input example 1 5 2 1 5 3 2 4 5 2 Output example 1 4 5 1 2 3 * The first query changes the permutation to \\ {3, 2, 4, 5, 1 \\}. * The second query changes the permutation to \\ {4, 5, 1, 2, 3 \\}. Input example 2 5 1 1 2 3 4 5 Five Output example 2 5 1 2 3 4 Example Input 5 2 1 5 3 2 4 5 2 Output 4 5 1 2 3
instruction
0
5,779
12
11,558
"Correct Solution: ``` # -*- coding: utf-8 -*- def inpl(): return list(map(int, input().split())) N, _ = inpl() A = inpl() if N == 1: print(*A) exit() L = [0]*(N+1) R = [0]*(N+1) for i in range(N-1): R[A[i]] = A[i+1] L[A[i+1]] = A[i] lm = A[0] rm = A[-1] for q in inpl(): if q == rm: l = L[q] R[l] = 0 L[q] = 0 R[q] = lm L[lm] = q lm = q rm = l elif q == lm: r = R[q] L[r] = 0 R[q] = 0 L[q] = rm R[rm] = q lm = r rm = q else: l, r = L[q], R[q] L[q] = rm R[q] = lm R[l] = 0 L[r] = 0 L[lm] = q R[rm] = q rm = l lm = r ans = [] while lm != 0: ans.append(lm) lm = R[lm] print(*ans) ```
output
1
5,779
12
11,559
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya has an array a_1, a_2, ..., a_n. You don't know this array, but he told you m facts about this array. The i-th fact is a triple of numbers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n) and it means: * if t_i=1 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is sorted in non-decreasing order; * if t_i=0 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is not sorted in non-decreasing order. A subarray is not sorted if there is at least one pair of consecutive elements in this subarray such that the former is greater than the latter. For example if a = [2, 1, 1, 3, 2] then he could give you three facts: t_1=1, l_1=2, r_1=4 (the subarray [a_2, a_3, a_4] = [1, 1, 3] is sorted), t_2=0, l_2=4, r_2=5 (the subarray [a_4, a_5] = [3, 2] is not sorted), and t_3=0, l_3=3, r_3=5 (the subarray [a_3, a_5] = [1, 3, 2] is not sorted). You don't know the array a. Find any array which satisfies all the given facts. Input The first line contains two integers n and m (2 ≀ n ≀ 1000, 1 ≀ m ≀ 1000). Each of the next m lines contains three integers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n). If t_i = 1 then subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is sorted. Otherwise (if t_i = 0) subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is not sorted. Output If there is no array that satisfies these facts in only line print NO (in any letter case). If there is a solution, print YES (in any letter case). In second line print n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the array a, satisfying all the given facts. If there are multiple satisfying arrays you can print any of them. Examples Input 7 4 1 1 3 1 2 5 0 5 6 1 6 7 Output YES 1 2 2 3 5 4 4 Input 4 2 1 1 4 0 2 3 Output NO
instruction
0
5,845
12
11,690
Tags: constructive algorithms, greedy, implementation Correct Solution: ``` from collections import defaultdict n,m = map(int,input().split()) l1 = [] l2 = [] ans = [1]*n for i in range(m): a,b,c = map(int,input().split()) if a == 0: l2.append([b,c]) else: l1.append([b,c]) hash = defaultdict(bool) l1.sort() l2.sort() for i in range(len(l1)): a,b = l1[i] for i in range(a,b): hash[(i,i+1)] = True l2.reverse() flag = 1 for i in range(len(l2)): a,b = l2[i] flag = 0 for i in range(a,b): if hash[(i,i+1)] == False: flag = 1 ans[i-1] = ans[i]+1 break if flag == 0: break # print(hash) if flag == 1: print('YES') print(*ans) else: print('NO') ```
output
1
5,845
12
11,691
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya has an array a_1, a_2, ..., a_n. You don't know this array, but he told you m facts about this array. The i-th fact is a triple of numbers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n) and it means: * if t_i=1 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is sorted in non-decreasing order; * if t_i=0 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is not sorted in non-decreasing order. A subarray is not sorted if there is at least one pair of consecutive elements in this subarray such that the former is greater than the latter. For example if a = [2, 1, 1, 3, 2] then he could give you three facts: t_1=1, l_1=2, r_1=4 (the subarray [a_2, a_3, a_4] = [1, 1, 3] is sorted), t_2=0, l_2=4, r_2=5 (the subarray [a_4, a_5] = [3, 2] is not sorted), and t_3=0, l_3=3, r_3=5 (the subarray [a_3, a_5] = [1, 3, 2] is not sorted). You don't know the array a. Find any array which satisfies all the given facts. Input The first line contains two integers n and m (2 ≀ n ≀ 1000, 1 ≀ m ≀ 1000). Each of the next m lines contains three integers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n). If t_i = 1 then subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is sorted. Otherwise (if t_i = 0) subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is not sorted. Output If there is no array that satisfies these facts in only line print NO (in any letter case). If there is a solution, print YES (in any letter case). In second line print n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the array a, satisfying all the given facts. If there are multiple satisfying arrays you can print any of them. Examples Input 7 4 1 1 3 1 2 5 0 5 6 1 6 7 Output YES 1 2 2 3 5 4 4 Input 4 2 1 1 4 0 2 3 Output NO
instruction
0
5,846
12
11,692
Tags: constructive algorithms, greedy, implementation Correct Solution: ``` n,m=map(int,input().split()) a=[0]*n a0=[] while m>0: m-=1 t,l,r=[int(i) for i in input().split()] if t==0: a0.append((l,r)) continue for i in range(l,r): a[i]=1 for l,r in a0: if set(a[l:r]) == {1}: print("NO") exit (0) print("YES") val=5*10**4 for i in a: if i: val+=1 else: val-=1 print(val) ```
output
1
5,846
12
11,693
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya has an array a_1, a_2, ..., a_n. You don't know this array, but he told you m facts about this array. The i-th fact is a triple of numbers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n) and it means: * if t_i=1 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is sorted in non-decreasing order; * if t_i=0 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is not sorted in non-decreasing order. A subarray is not sorted if there is at least one pair of consecutive elements in this subarray such that the former is greater than the latter. For example if a = [2, 1, 1, 3, 2] then he could give you three facts: t_1=1, l_1=2, r_1=4 (the subarray [a_2, a_3, a_4] = [1, 1, 3] is sorted), t_2=0, l_2=4, r_2=5 (the subarray [a_4, a_5] = [3, 2] is not sorted), and t_3=0, l_3=3, r_3=5 (the subarray [a_3, a_5] = [1, 3, 2] is not sorted). You don't know the array a. Find any array which satisfies all the given facts. Input The first line contains two integers n and m (2 ≀ n ≀ 1000, 1 ≀ m ≀ 1000). Each of the next m lines contains three integers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n). If t_i = 1 then subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is sorted. Otherwise (if t_i = 0) subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is not sorted. Output If there is no array that satisfies these facts in only line print NO (in any letter case). If there is a solution, print YES (in any letter case). In second line print n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the array a, satisfying all the given facts. If there are multiple satisfying arrays you can print any of them. Examples Input 7 4 1 1 3 1 2 5 0 5 6 1 6 7 Output YES 1 2 2 3 5 4 4 Input 4 2 1 1 4 0 2 3 Output NO
instruction
0
5,847
12
11,694
Tags: constructive algorithms, greedy, implementation Correct Solution: ``` import sys from collections import defaultdict import typing class DSU: ''' Implement (union by size) + (path halving) Reference: Zvi Galil and Giuseppe F. Italiano, Data structures and algorithms for disjoint set union problems ''' def __init__(self, n: int = 0) -> None: self._n = n self.parent_or_size = [-1] * n def merge(self, a: int, b: int) -> int: assert 0 <= a < self._n assert 0 <= b < self._n x = self.leader(a) y = self.leader(b) if x == y: return x if -self.parent_or_size[x] < -self.parent_or_size[y]: x, y = y, x self.parent_or_size[x] += self.parent_or_size[y] self.parent_or_size[y] = x return x def same(self, a: int, b: int) -> bool: assert 0 <= a < self._n assert 0 <= b < self._n return self.leader(a) == self.leader(b) def leader(self, a: int) -> int: assert 0 <= a < self._n parent = self.parent_or_size[a] while parent >= 0: if self.parent_or_size[parent] < 0: return parent self.parent_or_size[a], a, parent = ( self.parent_or_size[parent], self.parent_or_size[parent], self.parent_or_size[self.parent_or_size[parent]] ) return a def size(self, a: int) -> int: assert 0 <= a < self._n return -self.parent_or_size[self.leader(a)] def groups(self) -> typing.List[typing.List[int]]: leader_buf = [self.leader(i) for i in range(self._n)] result: typing.List[typing.List[int]] = [[] for _ in range(self._n)] for i in range(self._n): result[leader_buf[i]].append(i) return list(filter(lambda r: r, result)) def input(): return sys.stdin.readline().rstrip() def slv(): n, m = map(int, input().split()) dsu = DSU(n) info = [-1]*(n) not_sorted = [] for i in range(m): t, l, r = map(int, input().split()) l -= 1 r -= 1 if t == 1: for j in range(l, r + 1): dsu.merge(l, j) else: not_sorted.append((l, r)) group = [-1]*(n) dsu_data = defaultdict(list) for i in range(n): dsu_data[dsu.leader(i)].append(i) color = 0 for key, value in dsu_data.items(): for v in value: group[v] = color color += 1 # print(group) for l, r in not_sorted: if all(group[j] == group[l] for j in range(l, r + 1)): print("NO") return INF = int(1e8) D = int(1e4) inc = 0 print("YES") ans = [0]*(n) group_index = group[0] for i in range(n): if group[i] == group_index: ans[i] = INF + inc inc += 1 else: group_index = group[i] INF -= D inc = 0 ans[i] = INF + inc inc += 1 print(*ans) return def main(): t = 1 for i in range(t): slv() return if __name__ == "__main__": main() ```
output
1
5,847
12
11,695
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya has an array a_1, a_2, ..., a_n. You don't know this array, but he told you m facts about this array. The i-th fact is a triple of numbers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n) and it means: * if t_i=1 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is sorted in non-decreasing order; * if t_i=0 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is not sorted in non-decreasing order. A subarray is not sorted if there is at least one pair of consecutive elements in this subarray such that the former is greater than the latter. For example if a = [2, 1, 1, 3, 2] then he could give you three facts: t_1=1, l_1=2, r_1=4 (the subarray [a_2, a_3, a_4] = [1, 1, 3] is sorted), t_2=0, l_2=4, r_2=5 (the subarray [a_4, a_5] = [3, 2] is not sorted), and t_3=0, l_3=3, r_3=5 (the subarray [a_3, a_5] = [1, 3, 2] is not sorted). You don't know the array a. Find any array which satisfies all the given facts. Input The first line contains two integers n and m (2 ≀ n ≀ 1000, 1 ≀ m ≀ 1000). Each of the next m lines contains three integers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n). If t_i = 1 then subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is sorted. Otherwise (if t_i = 0) subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is not sorted. Output If there is no array that satisfies these facts in only line print NO (in any letter case). If there is a solution, print YES (in any letter case). In second line print n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the array a, satisfying all the given facts. If there are multiple satisfying arrays you can print any of them. Examples Input 7 4 1 1 3 1 2 5 0 5 6 1 6 7 Output YES 1 2 2 3 5 4 4 Input 4 2 1 1 4 0 2 3 Output NO
instruction
0
5,848
12
11,696
Tags: constructive algorithms, greedy, implementation Correct Solution: ``` # /////////////////////////////////////////////////////////////////////////// # //////////////////// PYTHON IS THE BEST //////////////////////// # /////////////////////////////////////////////////////////////////////////// import sys,os,io import math from collections import defaultdict from io import BytesIO, IOBase from types import GeneratorType 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") def ii(): return int(input()) def li(): return list(map(int,input().split())) # /////////////////////////////////////////////////////////////////////////// # //////////////////// DO NOT TOUCH BEFORE THIS LINE //////////////////////// # /////////////////////////////////////////////////////////////////////////// if(os.path.exists('input.txt')): sys.stdin = open("input.txt","r") ; sys.stdout = open("output.txt","w") else: sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") n,m = li() s = [] ns = [] for i in range(m): t,l,r = li() l-=1 r-=1 if t==0: ns.append([l,r]) else: s.append([l,r]) arr = [0]*n for i in range(n-1): ss = 0 nss = 0 for l,r in s: if l<=i<=i+1<=r: ss+=1 for l,r in ns: if l<=i<=i+1<=r: nss+=1 # if ss>0 and nss>0: # print("NO") # exit() if nss>0 and ss==0: arr[i+1]=-1 c = 0 for i in range(n): if arr[i]==-1: c-=2 arr[i]=c else: arr[i]=c c+=1 for l,r in s: for i in range(l,r): if arr[i]>arr[i+1]: print("NO") exit() for l,r in ns: f = 0 for i in range(l,r): if arr[i]>arr[i+1]: f = 1 if f==0: # print(l,r) print("NO") exit() m = min(arr) if m<=0: y = -m+1 for i in range(n): arr[i]+=y print("YES") print(*arr) ```
output
1
5,848
12
11,697
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya has an array a_1, a_2, ..., a_n. You don't know this array, but he told you m facts about this array. The i-th fact is a triple of numbers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n) and it means: * if t_i=1 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is sorted in non-decreasing order; * if t_i=0 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is not sorted in non-decreasing order. A subarray is not sorted if there is at least one pair of consecutive elements in this subarray such that the former is greater than the latter. For example if a = [2, 1, 1, 3, 2] then he could give you three facts: t_1=1, l_1=2, r_1=4 (the subarray [a_2, a_3, a_4] = [1, 1, 3] is sorted), t_2=0, l_2=4, r_2=5 (the subarray [a_4, a_5] = [3, 2] is not sorted), and t_3=0, l_3=3, r_3=5 (the subarray [a_3, a_5] = [1, 3, 2] is not sorted). You don't know the array a. Find any array which satisfies all the given facts. Input The first line contains two integers n and m (2 ≀ n ≀ 1000, 1 ≀ m ≀ 1000). Each of the next m lines contains three integers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n). If t_i = 1 then subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is sorted. Otherwise (if t_i = 0) subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is not sorted. Output If there is no array that satisfies these facts in only line print NO (in any letter case). If there is a solution, print YES (in any letter case). In second line print n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the array a, satisfying all the given facts. If there are multiple satisfying arrays you can print any of them. Examples Input 7 4 1 1 3 1 2 5 0 5 6 1 6 7 Output YES 1 2 2 3 5 4 4 Input 4 2 1 1 4 0 2 3 Output NO
instruction
0
5,849
12
11,698
Tags: constructive algorithms, greedy, implementation Correct Solution: ``` # -*- coding: utf-8 -*- # @Date : 2019-07-01 08:11:55 # @Author : raj lath (oorja.halt@gmail.com) # @Link : link # @Version : 1.0.0 import sys sys.setrecursionlimit(10**5+1) inf = int(10 ** 20) max_val = inf min_val = -inf RW = lambda : sys.stdin.readline().strip() RI = lambda : int(RW()) RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()] RWI = lambda : [x for x in sys.stdin.readline().strip().split()] lens, tips = RMI() pos = [[], []] for i in range(tips): mode, *ind = RMI() pos[mode].append(ind) canbe = True maybe = [-1] * (lens - 1) for lr in pos[1]: for curr in range(lr[0] - 1,lr[1] - 1): maybe[curr] = 0 for lr in pos[0]: if sum(maybe[lr[0]-1:lr[1]-1]) == 0: canbe = False break if not canbe:print("NO") else: print("YES") answer = [int(1e7)] for i in range(lens - 1): answer += [answer[-1] + maybe[i]] print(*answer) ```
output
1
5,849
12
11,699
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya has an array a_1, a_2, ..., a_n. You don't know this array, but he told you m facts about this array. The i-th fact is a triple of numbers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n) and it means: * if t_i=1 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is sorted in non-decreasing order; * if t_i=0 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is not sorted in non-decreasing order. A subarray is not sorted if there is at least one pair of consecutive elements in this subarray such that the former is greater than the latter. For example if a = [2, 1, 1, 3, 2] then he could give you three facts: t_1=1, l_1=2, r_1=4 (the subarray [a_2, a_3, a_4] = [1, 1, 3] is sorted), t_2=0, l_2=4, r_2=5 (the subarray [a_4, a_5] = [3, 2] is not sorted), and t_3=0, l_3=3, r_3=5 (the subarray [a_3, a_5] = [1, 3, 2] is not sorted). You don't know the array a. Find any array which satisfies all the given facts. Input The first line contains two integers n and m (2 ≀ n ≀ 1000, 1 ≀ m ≀ 1000). Each of the next m lines contains three integers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n). If t_i = 1 then subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is sorted. Otherwise (if t_i = 0) subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is not sorted. Output If there is no array that satisfies these facts in only line print NO (in any letter case). If there is a solution, print YES (in any letter case). In second line print n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the array a, satisfying all the given facts. If there are multiple satisfying arrays you can print any of them. Examples Input 7 4 1 1 3 1 2 5 0 5 6 1 6 7 Output YES 1 2 2 3 5 4 4 Input 4 2 1 1 4 0 2 3 Output NO
instruction
0
5,850
12
11,700
Tags: constructive algorithms, greedy, implementation Correct Solution: ``` n,m = map(int, input().split()) a = [] b = [] j = 1 l = [0]*n for _ in range(m): q,w,e = map(int, input().split()) if q == 1: a += [ [q,w,e] ] else: b += [ [q,w,e] ] for x in a: if l[x[1]-1] != 0 and l[x[2] - 1] != 0 and l[x[1]-1] != l[x[2] - 1]: #print('ok') for i in range( x[1]-1,x[2] ): l[i] = l[x[1]-1] h = x[2] if x[2] != n-1: #print('ok') mu = l[x[2]] while h < n and l[h] == mu: #print('ok') l[h] = l[x[1]-1] h+=1 elif l[x[1]-1] != 0: for i in range( x[1]-1,x[2] ): l[i] = l[x[1]-1] elif l[x[2]-1] != 0: for i in range( x[1]-1,x[2] ): l[i] = l[x[2]-1] else: for i in range( x[1]-1,x[2] ): l[i] = j j += 1 #print(l) fl=0 for x in b: #print( l[ x[1] - 1] , l[ x[2] - 1] ) if (l[ x[1] - 1] == l[ x[2] - 1]) and l[ x[1] - 1] != 0: fl = 1 break if fl == 0: print('YES') val = 10**5 for i in range(n): if i == 0 or (l[i] == l[i-1] and l[i] != 0) : print(val, end= ' ') val+=1 else: val -= 2 print(val, end = ' ') val+=1 else: print('NO') ```
output
1
5,850
12
11,701
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya has an array a_1, a_2, ..., a_n. You don't know this array, but he told you m facts about this array. The i-th fact is a triple of numbers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n) and it means: * if t_i=1 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is sorted in non-decreasing order; * if t_i=0 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is not sorted in non-decreasing order. A subarray is not sorted if there is at least one pair of consecutive elements in this subarray such that the former is greater than the latter. For example if a = [2, 1, 1, 3, 2] then he could give you three facts: t_1=1, l_1=2, r_1=4 (the subarray [a_2, a_3, a_4] = [1, 1, 3] is sorted), t_2=0, l_2=4, r_2=5 (the subarray [a_4, a_5] = [3, 2] is not sorted), and t_3=0, l_3=3, r_3=5 (the subarray [a_3, a_5] = [1, 3, 2] is not sorted). You don't know the array a. Find any array which satisfies all the given facts. Input The first line contains two integers n and m (2 ≀ n ≀ 1000, 1 ≀ m ≀ 1000). Each of the next m lines contains three integers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n). If t_i = 1 then subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is sorted. Otherwise (if t_i = 0) subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is not sorted. Output If there is no array that satisfies these facts in only line print NO (in any letter case). If there is a solution, print YES (in any letter case). In second line print n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the array a, satisfying all the given facts. If there are multiple satisfying arrays you can print any of them. Examples Input 7 4 1 1 3 1 2 5 0 5 6 1 6 7 Output YES 1 2 2 3 5 4 4 Input 4 2 1 1 4 0 2 3 Output NO
instruction
0
5,851
12
11,702
Tags: constructive algorithms, greedy, implementation Correct Solution: ``` import math #5 4 4 4 3 n,m=map(int,input().split()) ans=[-(i+1) for i in range(n)] query=[] chec=[] cnt=1 for i in range(m): x,y,z=map(int,input().split()) if(x==1): query.append([y,z]) else: chec.append([y,z]) continue; query.sort() for i in range(len(query)): t=query[i] maxa=-math.inf for j in range(t[0]-1,t[1]): maxa=max(maxa,ans[j]) for j in range(t[0]-1,t[1]): ans[j]=maxa flag=0 glag=0 for i in range(len(chec)): x=chec[i] flag=1 for j in range(x[0],x[1]): if(ans[j]<ans[j-1]): flag=0 break; if(flag==1): glag=1 break; if(glag==0): print('YES') r=min(ans) for i in range(len(ans)): ans[i]+=abs(r)+1 print(*ans) else: print('NO') ```
output
1
5,851
12
11,703
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya has an array a_1, a_2, ..., a_n. You don't know this array, but he told you m facts about this array. The i-th fact is a triple of numbers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n) and it means: * if t_i=1 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is sorted in non-decreasing order; * if t_i=0 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is not sorted in non-decreasing order. A subarray is not sorted if there is at least one pair of consecutive elements in this subarray such that the former is greater than the latter. For example if a = [2, 1, 1, 3, 2] then he could give you three facts: t_1=1, l_1=2, r_1=4 (the subarray [a_2, a_3, a_4] = [1, 1, 3] is sorted), t_2=0, l_2=4, r_2=5 (the subarray [a_4, a_5] = [3, 2] is not sorted), and t_3=0, l_3=3, r_3=5 (the subarray [a_3, a_5] = [1, 3, 2] is not sorted). You don't know the array a. Find any array which satisfies all the given facts. Input The first line contains two integers n and m (2 ≀ n ≀ 1000, 1 ≀ m ≀ 1000). Each of the next m lines contains three integers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n). If t_i = 1 then subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is sorted. Otherwise (if t_i = 0) subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is not sorted. Output If there is no array that satisfies these facts in only line print NO (in any letter case). If there is a solution, print YES (in any letter case). In second line print n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the array a, satisfying all the given facts. If there are multiple satisfying arrays you can print any of them. Examples Input 7 4 1 1 3 1 2 5 0 5 6 1 6 7 Output YES 1 2 2 3 5 4 4 Input 4 2 1 1 4 0 2 3 Output NO
instruction
0
5,852
12
11,704
Tags: constructive algorithms, greedy, implementation Correct Solution: ``` #Code by Sounak, IIESTS #------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase from fractions import Fraction import collections from itertools import permutations from collections import defaultdict BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") #-------------------game starts now----------------------------------------------------- n,m=map(int,input().split()) inc=list() dec=list() s=set() for i in range (m): ch,l,r=map(int,input().split()) if ch==1: inc.append((l-1,r-1)) else: dec.append((l-1,r-1)) a=[n]*n inc.sort() for i in range (len(inc)): l,r=inc[i][0],inc[i][1] for j in range (l+1,r+1): s.add(j) ch=1 #print(s) dec.sort() for i in range (len(dec)): l,r=dec[i][0],dec[i][1] c=0 for j in range (l+1,r+1): if j in s: c+=1 else: if a[j]<a[j-1]: break a[j]=a[j-1]-1 break if c==r-l: ch=0 break if ch==1: print("YES") print(*a) else: print("NO") ```
output
1
5,852
12
11,705
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya has an array a_1, a_2, ..., a_n. You don't know this array, but he told you m facts about this array. The i-th fact is a triple of numbers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n) and it means: * if t_i=1 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is sorted in non-decreasing order; * if t_i=0 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is not sorted in non-decreasing order. A subarray is not sorted if there is at least one pair of consecutive elements in this subarray such that the former is greater than the latter. For example if a = [2, 1, 1, 3, 2] then he could give you three facts: t_1=1, l_1=2, r_1=4 (the subarray [a_2, a_3, a_4] = [1, 1, 3] is sorted), t_2=0, l_2=4, r_2=5 (the subarray [a_4, a_5] = [3, 2] is not sorted), and t_3=0, l_3=3, r_3=5 (the subarray [a_3, a_5] = [1, 3, 2] is not sorted). You don't know the array a. Find any array which satisfies all the given facts. Input The first line contains two integers n and m (2 ≀ n ≀ 1000, 1 ≀ m ≀ 1000). Each of the next m lines contains three integers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n). If t_i = 1 then subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is sorted. Otherwise (if t_i = 0) subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is not sorted. Output If there is no array that satisfies these facts in only line print NO (in any letter case). If there is a solution, print YES (in any letter case). In second line print n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the array a, satisfying all the given facts. If there are multiple satisfying arrays you can print any of them. Examples Input 7 4 1 1 3 1 2 5 0 5 6 1 6 7 Output YES 1 2 2 3 5 4 4 Input 4 2 1 1 4 0 2 3 Output NO Submitted Solution: ``` import sys from itertools import accumulate N, M = map(int, input().split()) TLR = [tuple(map(int, input().split())) for _ in range(M)] TLR.sort(reverse = True) table = [False]*(N+1) for i in range(M): t, l, r = TLR[i] l -= 1 r -= 1 if not t: break table[l] += 1 table[r] -= 1 if i == M-1: i += 1 stp = i table = list(accumulate(table)) table = [1 if t > 0 else 0 for t in table[:-1]] table += [0] col = [-1]*N ctr = 10000 for i in range(N): if table[i-1] == 0: ctr -= 1 if table[i-1] == 1 or table[i] == 1: col[i] = ctr for i in range(stp, M): _, l, r = TLR[i] l -= 1 r -= 1 if col[l] == col[r] > 0: break else: print('YES') Ans = [10000]*N for i in range(N): if col[i] < 0 or col[i-1] != col[i]: Ans[i] = Ans[i-1] - 1 else: Ans[i] = Ans[i-1] print(*Ans) sys.exit() print('NO') ```
instruction
0
5,853
12
11,706
Yes
output
1
5,853
12
11,707
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya has an array a_1, a_2, ..., a_n. You don't know this array, but he told you m facts about this array. The i-th fact is a triple of numbers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n) and it means: * if t_i=1 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is sorted in non-decreasing order; * if t_i=0 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is not sorted in non-decreasing order. A subarray is not sorted if there is at least one pair of consecutive elements in this subarray such that the former is greater than the latter. For example if a = [2, 1, 1, 3, 2] then he could give you three facts: t_1=1, l_1=2, r_1=4 (the subarray [a_2, a_3, a_4] = [1, 1, 3] is sorted), t_2=0, l_2=4, r_2=5 (the subarray [a_4, a_5] = [3, 2] is not sorted), and t_3=0, l_3=3, r_3=5 (the subarray [a_3, a_5] = [1, 3, 2] is not sorted). You don't know the array a. Find any array which satisfies all the given facts. Input The first line contains two integers n and m (2 ≀ n ≀ 1000, 1 ≀ m ≀ 1000). Each of the next m lines contains three integers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n). If t_i = 1 then subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is sorted. Otherwise (if t_i = 0) subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is not sorted. Output If there is no array that satisfies these facts in only line print NO (in any letter case). If there is a solution, print YES (in any letter case). In second line print n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the array a, satisfying all the given facts. If there are multiple satisfying arrays you can print any of them. Examples Input 7 4 1 1 3 1 2 5 0 5 6 1 6 7 Output YES 1 2 2 3 5 4 4 Input 4 2 1 1 4 0 2 3 Output NO Submitted Solution: ``` def get_compressed(facts): compressed_facts = dict() for fact in facts: if fact[0] == 0: continue start, end = fact[1], fact[2] to_remove = [] skip = False for compressed in compressed_facts: start_compressed, end_compressed = compressed_facts[compressed] if start <= end_compressed and end > end_compressed: to_remove.append(compressed) start = min(start, start_compressed) elif end >= start_compressed and start < start_compressed: to_remove.append(compressed) end = max(end, end_compressed) elif start >= start_compressed and end <= end_compressed: skip = True break if skip: continue compressed_facts[str(start) + ',' + str(end)] = [start, end] for x in to_remove: del compressed_facts[x] return compressed_facts def solve(n, facts): compressed_facts = get_compressed(facts) # Verify that no 0s are entirely inside 1s for fact in facts: if fact[0] == 1: continue for compressed in compressed_facts.values(): if fact[1] >= compressed[0] and fact[2] <= compressed[1]: return None a = n * [None] for fact in compressed_facts.values(): start = 10**8 size = fact[1] - fact[0] + 1 for i in range(size): # This is fine due to the limits on the problem (n < 1000) a[fact[0] - 1 + i] = start - (10000 * fact[0]) + i for i in range(n): if a[i] is None: if i == 0: a[i] = 10**9 - 1 else: a[i] = a[i-1] - 1 return a n, num_facts = map(int, input().split(' ')) facts = [] for _ in range(num_facts): facts.append(list(map(int, input().split(' ')))) sol = solve(n, facts) if sol is None: print('NO') else: print('YES') print(' '.join(map(str, sol))) ```
instruction
0
5,854
12
11,708
Yes
output
1
5,854
12
11,709
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya has an array a_1, a_2, ..., a_n. You don't know this array, but he told you m facts about this array. The i-th fact is a triple of numbers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n) and it means: * if t_i=1 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is sorted in non-decreasing order; * if t_i=0 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is not sorted in non-decreasing order. A subarray is not sorted if there is at least one pair of consecutive elements in this subarray such that the former is greater than the latter. For example if a = [2, 1, 1, 3, 2] then he could give you three facts: t_1=1, l_1=2, r_1=4 (the subarray [a_2, a_3, a_4] = [1, 1, 3] is sorted), t_2=0, l_2=4, r_2=5 (the subarray [a_4, a_5] = [3, 2] is not sorted), and t_3=0, l_3=3, r_3=5 (the subarray [a_3, a_5] = [1, 3, 2] is not sorted). You don't know the array a. Find any array which satisfies all the given facts. Input The first line contains two integers n and m (2 ≀ n ≀ 1000, 1 ≀ m ≀ 1000). Each of the next m lines contains three integers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n). If t_i = 1 then subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is sorted. Otherwise (if t_i = 0) subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is not sorted. Output If there is no array that satisfies these facts in only line print NO (in any letter case). If there is a solution, print YES (in any letter case). In second line print n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the array a, satisfying all the given facts. If there are multiple satisfying arrays you can print any of them. Examples Input 7 4 1 1 3 1 2 5 0 5 6 1 6 7 Output YES 1 2 2 3 5 4 4 Input 4 2 1 1 4 0 2 3 Output NO Submitted Solution: ``` import sys zz=1 sys.setrecursionlimit(10**5) if zz: input=sys.stdin.readline else: sys.stdin=open('input.txt', 'r') sys.stdout=open('all.txt','w') di=[[-1,0],[1,0],[0,1],[0,-1]] def fori(n): return [fi() for i in range(n)] def inc(d,c,x=1): d[c]=d[c]+x if c in d else x def ii(): return input().rstrip() def li(): return [int(xx) for xx in input().split()] def fli(): return [float(x) for x in input().split()] def comp(a,b): if(a>b): return 2 return 2 if a==b else 0 def gi(): return [xx for xx in input().split()] def gtc(tc,ans): print("Case #"+str(tc)+":",ans) def cil(n,m): return n//m+int(n%m>0) def fi(): return int(input()) def pro(a): return reduce(lambda a,b:a*b,a) def swap(a,i,j): a[i],a[j]=a[j],a[i] def si(): return list(input().rstrip()) def mi(): return map(int,input().split()) def gh(): sys.stdout.flush() def isvalid(i,j,n,m): return 0<=i<n and 0<=j<m def bo(i): return ord(i)-ord('a') def graph(n,m): for i in range(m): x,y=mi() a[x].append(y) a[y].append(x) t=1 uu=t while t>0: t-=1 n,m=mi() a=[] b=[] for i in range(m): typ,l,r=mi() if typ==1: a.append([l,r]) else: b.append([l,r]) a.sort() d=[] l=r=-1 for i in range(len(a)): if i==0: l=a[i][0] r=a[i][1] else: if a[i][0]>r: d.append([l,r]) l=a[i][0] r=a[i][1] else: r=max(r,a[i][1]) if l!=-1 and r!=-1: d.append([l,r]) ans=[0]*(n+1) c=n*n+1 a=[i for i in range(n+1)] for i,j in d: for l in range(i,j+1): ans[l]=c a[l]=i c-=n+1 for i,j in b: if a[i]==a[j]: print("NO") exit(0) print("YES") if ans.count(0)==len(ans): for i in range(1,n+1): ans[i]=c c-=n-1 else: p=ans.index(n*n+1) for j in range(p-1,-1,-1): if ans[j]==0: ans[j]=ans[j+1]+1 for j in range(p+1,n+1): if ans[j]==0: ans[j]=ans[j-1]-1 print(*ans[1:]) ```
instruction
0
5,855
12
11,710
Yes
output
1
5,855
12
11,711
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya has an array a_1, a_2, ..., a_n. You don't know this array, but he told you m facts about this array. The i-th fact is a triple of numbers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n) and it means: * if t_i=1 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is sorted in non-decreasing order; * if t_i=0 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is not sorted in non-decreasing order. A subarray is not sorted if there is at least one pair of consecutive elements in this subarray such that the former is greater than the latter. For example if a = [2, 1, 1, 3, 2] then he could give you three facts: t_1=1, l_1=2, r_1=4 (the subarray [a_2, a_3, a_4] = [1, 1, 3] is sorted), t_2=0, l_2=4, r_2=5 (the subarray [a_4, a_5] = [3, 2] is not sorted), and t_3=0, l_3=3, r_3=5 (the subarray [a_3, a_5] = [1, 3, 2] is not sorted). You don't know the array a. Find any array which satisfies all the given facts. Input The first line contains two integers n and m (2 ≀ n ≀ 1000, 1 ≀ m ≀ 1000). Each of the next m lines contains three integers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n). If t_i = 1 then subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is sorted. Otherwise (if t_i = 0) subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is not sorted. Output If there is no array that satisfies these facts in only line print NO (in any letter case). If there is a solution, print YES (in any letter case). In second line print n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the array a, satisfying all the given facts. If there are multiple satisfying arrays you can print any of them. Examples Input 7 4 1 1 3 1 2 5 0 5 6 1 6 7 Output YES 1 2 2 3 5 4 4 Input 4 2 1 1 4 0 2 3 Output NO Submitted Solution: ``` n, m = map(int, input().split()) a = [0] * n ordered = [] unordered = [] for i in range(m): list1 = list(map(int, input().split())) if list1[0] == 0: unordered.append(list1) else: ordered.append(list1) for t, l, r in ordered: for i in range(l, r): a[i] = t for t, l, r in unordered: unset = any(e == 0 for e in a[l:r]) if not unset: print('NO') exit() print('YES') v = 100000 for e in a: if e == 1: v += 1 else: v -= 1 print(v, end=' ') ```
instruction
0
5,856
12
11,712
Yes
output
1
5,856
12
11,713
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya has an array a_1, a_2, ..., a_n. You don't know this array, but he told you m facts about this array. The i-th fact is a triple of numbers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n) and it means: * if t_i=1 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is sorted in non-decreasing order; * if t_i=0 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is not sorted in non-decreasing order. A subarray is not sorted if there is at least one pair of consecutive elements in this subarray such that the former is greater than the latter. For example if a = [2, 1, 1, 3, 2] then he could give you three facts: t_1=1, l_1=2, r_1=4 (the subarray [a_2, a_3, a_4] = [1, 1, 3] is sorted), t_2=0, l_2=4, r_2=5 (the subarray [a_4, a_5] = [3, 2] is not sorted), and t_3=0, l_3=3, r_3=5 (the subarray [a_3, a_5] = [1, 3, 2] is not sorted). You don't know the array a. Find any array which satisfies all the given facts. Input The first line contains two integers n and m (2 ≀ n ≀ 1000, 1 ≀ m ≀ 1000). Each of the next m lines contains three integers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n). If t_i = 1 then subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is sorted. Otherwise (if t_i = 0) subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is not sorted. Output If there is no array that satisfies these facts in only line print NO (in any letter case). If there is a solution, print YES (in any letter case). In second line print n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the array a, satisfying all the given facts. If there are multiple satisfying arrays you can print any of them. Examples Input 7 4 1 1 3 1 2 5 0 5 6 1 6 7 Output YES 1 2 2 3 5 4 4 Input 4 2 1 1 4 0 2 3 Output NO Submitted Solution: ``` """ NTC here """ from sys import setcheckinterval, stdin setcheckinterval(1000) # print("Case #{}: {} {}".format(i, n + m, n * m)) iin = lambda: int(stdin.readline()) lin = lambda: list(map(int, stdin.readline().split())) def eqation(a,b): for i in range(26): if a[i]>b[i]: return False return True n,m=lin() a=[lin() for i in range(m)] sa=[0 for i in range(n)] sa1=[1 for i in range(n)] a1=[] a2=[] for i in a: if i[0]: a1.append(i) else: a2.append(i) a1.sort(reverse=True,key= lambda x:x[2]-x[1]) ch=0 mn=1 for i in a1: if i[0]==0:break ch+=1 l,r=i[1],i[2] l-=mn r-=1 mn+=1 sa1[l]=1 if r+1<n: sa1[r+1]=-1 for j in range(l,r+1): if sa[j]: break else: sa[j]=ch for k in range(r,j,-1): if sa[j]: break else: sa[j]=ch #print(sa1,sa) for i in a2: l,r=i[1]-1,i[2]-1 if (sa[l] and sa[r] and sa[l]==sa[r]) or r-l==0: print('NO') exit() else: sa1[l]+=mn mn+=1 for i in range(1,n): sa1[i]+=sa1[i-1] print('YES') print(*sa1) ```
instruction
0
5,857
12
11,714
No
output
1
5,857
12
11,715
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya has an array a_1, a_2, ..., a_n. You don't know this array, but he told you m facts about this array. The i-th fact is a triple of numbers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n) and it means: * if t_i=1 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is sorted in non-decreasing order; * if t_i=0 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is not sorted in non-decreasing order. A subarray is not sorted if there is at least one pair of consecutive elements in this subarray such that the former is greater than the latter. For example if a = [2, 1, 1, 3, 2] then he could give you three facts: t_1=1, l_1=2, r_1=4 (the subarray [a_2, a_3, a_4] = [1, 1, 3] is sorted), t_2=0, l_2=4, r_2=5 (the subarray [a_4, a_5] = [3, 2] is not sorted), and t_3=0, l_3=3, r_3=5 (the subarray [a_3, a_5] = [1, 3, 2] is not sorted). You don't know the array a. Find any array which satisfies all the given facts. Input The first line contains two integers n and m (2 ≀ n ≀ 1000, 1 ≀ m ≀ 1000). Each of the next m lines contains three integers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n). If t_i = 1 then subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is sorted. Otherwise (if t_i = 0) subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is not sorted. Output If there is no array that satisfies these facts in only line print NO (in any letter case). If there is a solution, print YES (in any letter case). In second line print n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the array a, satisfying all the given facts. If there are multiple satisfying arrays you can print any of them. Examples Input 7 4 1 1 3 1 2 5 0 5 6 1 6 7 Output YES 1 2 2 3 5 4 4 Input 4 2 1 1 4 0 2 3 Output NO Submitted Solution: ``` def mp(): return map(int, input().split()) def check(l, r): return int(a[l:r + 1] == sorted(a[l:r + 1])) n, m = mp() q = [0] * m for qq in range(m): t, l, r = mp() l, r = l - 1, r - 1 q[qq] = [l, r, t] q.sort() a = [0 for i in range(n)] fail = False for qq in range(m): l, r, t = q[qq] if t == 0: if a[l] == 0: a[l] = r - l + 1 for i in range(l + 1, r + 1): a[i] = a[i - 1] - 1 #print(a) for qq in range(m): l, r, t = q[qq] if t == 1: i = l while i < n and a[i] == 0: i += 1 if i == n: x = 1 else: x = a[i] a[l] = x for i in range(l + 1, r + 1): if a[i - 1] > a[i]: a[i] = a[i - 1] mn = min(a) if mn < 1: mn = abs(mn) + 1 for i in range(n): a[i] += mn fail = False for qq in range(m): l, r, t = q[qq] if t != check(l, r): fail = True break ff = False for qq in range(m): for tt in range(qq + 1, m): if q[qq][0] <= q[tt][0] and q[tt][1] <= q[qq][1] and q[qq][2] == 1 and q[tt][2] == 0: ff = True if ff and not fail: print(0//0) if fail: print('NO') else: print('YES') for i in a: print(i, end = ' ') ```
instruction
0
5,858
12
11,716
No
output
1
5,858
12
11,717
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya has an array a_1, a_2, ..., a_n. You don't know this array, but he told you m facts about this array. The i-th fact is a triple of numbers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n) and it means: * if t_i=1 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is sorted in non-decreasing order; * if t_i=0 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is not sorted in non-decreasing order. A subarray is not sorted if there is at least one pair of consecutive elements in this subarray such that the former is greater than the latter. For example if a = [2, 1, 1, 3, 2] then he could give you three facts: t_1=1, l_1=2, r_1=4 (the subarray [a_2, a_3, a_4] = [1, 1, 3] is sorted), t_2=0, l_2=4, r_2=5 (the subarray [a_4, a_5] = [3, 2] is not sorted), and t_3=0, l_3=3, r_3=5 (the subarray [a_3, a_5] = [1, 3, 2] is not sorted). You don't know the array a. Find any array which satisfies all the given facts. Input The first line contains two integers n and m (2 ≀ n ≀ 1000, 1 ≀ m ≀ 1000). Each of the next m lines contains three integers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n). If t_i = 1 then subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is sorted. Otherwise (if t_i = 0) subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is not sorted. Output If there is no array that satisfies these facts in only line print NO (in any letter case). If there is a solution, print YES (in any letter case). In second line print n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the array a, satisfying all the given facts. If there are multiple satisfying arrays you can print any of them. Examples Input 7 4 1 1 3 1 2 5 0 5 6 1 6 7 Output YES 1 2 2 3 5 4 4 Input 4 2 1 1 4 0 2 3 Output NO Submitted Solution: ``` n,m=map(int,input().split()) container=[0 for i in range(n+1)] stick=[0 for i in range(n+1)] maxid=[-1 for i in range(n+1)] stored=[] for _ in range(m): t,l,r=map(int,input().split()) if(t==1): maxid[l]=max(maxid[l],r) else: stored.append([l,r]) maxi=0 for i in range(1,n+1): maxi=max(maxi,maxid[i]) if(maxi>=i): container[i]=1 if(maxi==i): stick[i]=1 count=1 ans=[0 for i in range(n+1)] for i in range(n,0,-1): ans[i]=count if(container[i-1]==1==container[i] and stick[i-1]==0): pass else: count+=1 print(*ans[1:]) ```
instruction
0
5,859
12
11,718
No
output
1
5,859
12
11,719
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya has an array a_1, a_2, ..., a_n. You don't know this array, but he told you m facts about this array. The i-th fact is a triple of numbers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n) and it means: * if t_i=1 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is sorted in non-decreasing order; * if t_i=0 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is not sorted in non-decreasing order. A subarray is not sorted if there is at least one pair of consecutive elements in this subarray such that the former is greater than the latter. For example if a = [2, 1, 1, 3, 2] then he could give you three facts: t_1=1, l_1=2, r_1=4 (the subarray [a_2, a_3, a_4] = [1, 1, 3] is sorted), t_2=0, l_2=4, r_2=5 (the subarray [a_4, a_5] = [3, 2] is not sorted), and t_3=0, l_3=3, r_3=5 (the subarray [a_3, a_5] = [1, 3, 2] is not sorted). You don't know the array a. Find any array which satisfies all the given facts. Input The first line contains two integers n and m (2 ≀ n ≀ 1000, 1 ≀ m ≀ 1000). Each of the next m lines contains three integers t_i, l_i and r_i (0 ≀ t_i ≀ 1, 1 ≀ l_i < r_i ≀ n). If t_i = 1 then subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is sorted. Otherwise (if t_i = 0) subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is not sorted. Output If there is no array that satisfies these facts in only line print NO (in any letter case). If there is a solution, print YES (in any letter case). In second line print n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the array a, satisfying all the given facts. If there are multiple satisfying arrays you can print any of them. Examples Input 7 4 1 1 3 1 2 5 0 5 6 1 6 7 Output YES 1 2 2 3 5 4 4 Input 4 2 1 1 4 0 2 3 Output NO Submitted Solution: ``` def fillSorted(a,sector): for i in range(sector[0]-1,sector[1]-1,1): a[i]=1 return a def isUnsortable(a,sector): for i in range(sector[0]-1,sector[1]-1,1): if a[i]=='n': return True return False n,m= map(int, input().split()) a=[] for i in range(n): a.append('n') sorted=[] unsorted=[] for i in range(m): t,l,r=map(int, input().split()) if t: sorted.append([l,r]) else: unsorted.append([l,r]) for sector in sorted: a=fillSorted(a,sector) for sector in unsorted: if not(isUnsortable(a,sector)): print("NO") exit(0) Ans=[1] for i in range(len(a)-1): if a[i]==1: Ans.append(Ans[i]+1) else: Ans.append(Ans[i]-1) print("YES") print(*Ans) """ print(sorted) print(unsorted) print(a) print(isUnsortable(a,unsorted[0]))""" ```
instruction
0
5,860
12
11,720
No
output
1
5,860
12
11,721