message
stringlengths
2
48.6k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
318
108k
cluster
float64
8
8
__index_level_0__
int64
636
217k
Provide a correct Python 3 solution for this coding contest problem. There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists. Constraints * All values in input are integers. * 2 \leq N \leq 10^5 * 1 \leq M \leq 2 \times 10^5 * 1 \leq A_i, B_i \leq N\ (1 \leq i \leq M) * A_i \neq B_i\ (1 \leq i \leq M) * One can travel between any two rooms by traversing passages. Input Input is given from Standard Input in the following format: N M A_1 B_1 : A_M B_M Output If there is no way to place signposts satisfying the objective, print `No`. Otherwise, print N lines. The first line should contain `Yes`, and the i-th line (2 \leq i \leq N) should contain the integer representing the room indicated by the signpost in Room i. Examples Input 4 4 1 2 2 3 3 4 4 2 Output Yes 1 2 2 Input 6 9 3 4 6 1 2 4 5 3 4 6 1 5 6 2 4 5 5 6 Output Yes 6 5 5 1 1
instruction
0
89,014
8
178,028
"Correct Solution: ``` from collections import deque N, M = map(int, input().split()) d = {i:[] for i in range(1, N+1)} for _ in range(M): A, B = map(int, input().split()) d[A].append(B) d[B].append(A) par = [-1]*(N+1) par[1] = 0 q = deque([1]) while q: a = q.popleft() for b in d[a]: if par[b]!=-1:continue par[b] = a q.append(b) print("Yes") for i in range(2, N+1): print(par[i]) ```
output
1
89,014
8
178,029
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists. Constraints * All values in input are integers. * 2 \leq N \leq 10^5 * 1 \leq M \leq 2 \times 10^5 * 1 \leq A_i, B_i \leq N\ (1 \leq i \leq M) * A_i \neq B_i\ (1 \leq i \leq M) * One can travel between any two rooms by traversing passages. Input Input is given from Standard Input in the following format: N M A_1 B_1 : A_M B_M Output If there is no way to place signposts satisfying the objective, print `No`. Otherwise, print N lines. The first line should contain `Yes`, and the i-th line (2 \leq i \leq N) should contain the integer representing the room indicated by the signpost in Room i. Examples Input 4 4 1 2 2 3 3 4 4 2 Output Yes 1 2 2 Input 6 9 3 4 6 1 2 4 5 3 4 6 1 5 6 2 4 5 5 6 Output Yes 6 5 5 1 1 Submitted Solution: ``` from collections import deque n,m = map(int,input().split()) ab=[[] for _ in range(n+1)] for _ in range(m): a,b=map(int,input().split()) ab[a].append(b) ab[b].append(a) ans=[0]*(n+1) ans[1]=1 que=deque() que.append(1) while que: x=que.popleft() for i in ab[x]: if ans[i]==0: ans[i]=x que.append(i) print("Yes") for j in range(2,n+1): print(ans[j]) ```
instruction
0
89,015
8
178,030
Yes
output
1
89,015
8
178,031
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists. Constraints * All values in input are integers. * 2 \leq N \leq 10^5 * 1 \leq M \leq 2 \times 10^5 * 1 \leq A_i, B_i \leq N\ (1 \leq i \leq M) * A_i \neq B_i\ (1 \leq i \leq M) * One can travel between any two rooms by traversing passages. Input Input is given from Standard Input in the following format: N M A_1 B_1 : A_M B_M Output If there is no way to place signposts satisfying the objective, print `No`. Otherwise, print N lines. The first line should contain `Yes`, and the i-th line (2 \leq i \leq N) should contain the integer representing the room indicated by the signpost in Room i. Examples Input 4 4 1 2 2 3 3 4 4 2 Output Yes 1 2 2 Input 6 9 3 4 6 1 2 4 5 3 4 6 1 5 6 2 4 5 5 6 Output Yes 6 5 5 1 1 Submitted Solution: ``` from collections import deque n,m=map(int,input().split()) path=[[] for _ in range(n+1)] for i in range(m): a,b=map(int,input().split()) path[b].append(a) path[a].append(b) q=deque() q.append(1) l=[-1]*(n+1) while q: v=q.popleft() for i in path[v]: if l[i]==-1: l[i]=v q.append(i) print('Yes') for i in l[2:]: print(i) ```
instruction
0
89,016
8
178,032
Yes
output
1
89,016
8
178,033
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists. Constraints * All values in input are integers. * 2 \leq N \leq 10^5 * 1 \leq M \leq 2 \times 10^5 * 1 \leq A_i, B_i \leq N\ (1 \leq i \leq M) * A_i \neq B_i\ (1 \leq i \leq M) * One can travel between any two rooms by traversing passages. Input Input is given from Standard Input in the following format: N M A_1 B_1 : A_M B_M Output If there is no way to place signposts satisfying the objective, print `No`. Otherwise, print N lines. The first line should contain `Yes`, and the i-th line (2 \leq i \leq N) should contain the integer representing the room indicated by the signpost in Room i. Examples Input 4 4 1 2 2 3 3 4 4 2 Output Yes 1 2 2 Input 6 9 3 4 6 1 2 4 5 3 4 6 1 5 6 2 4 5 5 6 Output Yes 6 5 5 1 1 Submitted Solution: ``` f=lambda:map(int,input().split());n,m=f();g=[[] for _ in range(n)] for _ in [0]*m:a,b=f();g[a-1]+=[b-1];g[b-1]+=[a-1] p=[0]*n;from queue import*;q=Queue();q.put(0) while not q.empty(): v=q.get() for c in g[v]: if p[c]<1:p[c]=v+1;q.put(c) print('Yes',*p[1:],sep='\n') ```
instruction
0
89,017
8
178,034
Yes
output
1
89,017
8
178,035
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists. Constraints * All values in input are integers. * 2 \leq N \leq 10^5 * 1 \leq M \leq 2 \times 10^5 * 1 \leq A_i, B_i \leq N\ (1 \leq i \leq M) * A_i \neq B_i\ (1 \leq i \leq M) * One can travel between any two rooms by traversing passages. Input Input is given from Standard Input in the following format: N M A_1 B_1 : A_M B_M Output If there is no way to place signposts satisfying the objective, print `No`. Otherwise, print N lines. The first line should contain `Yes`, and the i-th line (2 \leq i \leq N) should contain the integer representing the room indicated by the signpost in Room i. Examples Input 4 4 1 2 2 3 3 4 4 2 Output Yes 1 2 2 Input 6 9 3 4 6 1 2 4 5 3 4 6 1 5 6 2 4 5 5 6 Output Yes 6 5 5 1 1 Submitted Solution: ``` from collections import deque N, M = map(int, input().split()) X = [[] for x in range(N+1)] for m in range(M): A, B = map(int, input().split()) X[A].append(B) X[B].append(A) Q = deque() Q.append(1) D = [-1]*(N+1) D[0] = 0 D[1] = 0 while Q: v = Q.pop() for i in X[v]: if D[i] == -1: D[i] = v Q.appendleft(i) if -1 in D: print('No') else: print('Yes') print(*D[2:]) ```
instruction
0
89,018
8
178,036
Yes
output
1
89,018
8
178,037
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists. Constraints * All values in input are integers. * 2 \leq N \leq 10^5 * 1 \leq M \leq 2 \times 10^5 * 1 \leq A_i, B_i \leq N\ (1 \leq i \leq M) * A_i \neq B_i\ (1 \leq i \leq M) * One can travel between any two rooms by traversing passages. Input Input is given from Standard Input in the following format: N M A_1 B_1 : A_M B_M Output If there is no way to place signposts satisfying the objective, print `No`. Otherwise, print N lines. The first line should contain `Yes`, and the i-th line (2 \leq i \leq N) should contain the integer representing the room indicated by the signpost in Room i. Examples Input 4 4 1 2 2 3 3 4 4 2 Output Yes 1 2 2 Input 6 9 3 4 6 1 2 4 5 3 4 6 1 5 6 2 4 5 5 6 Output Yes 6 5 5 1 1 Submitted Solution: ``` #!/usr/bin/env python3 # vim: set fileencoding=utf-8 # pylint: disable=unused-import, invalid-name, missing-docstring, bad-continuation """Module docstring """ import functools import heapq import itertools import logging import math import os import random import string import sys from argparse import ArgumentParser from collections import defaultdict, deque from copy import deepcopy from io import BytesIO, IOBase from typing import Dict, List, Optional, Set, Tuple def solve(values: List[Tuple[int, int]], n: int) -> List[int]: passages = defaultdict(set) for a, b in values: passages[a].add(b) passages[b].add(a) if len(passages) < n: return [] to_visit = deque((1,)) visited = set() # 0 idx is not used distances = [n + 1] * (n + 1) distances[1] = 0 signs = [1] * (n + 1) while to_visit: cur = to_visit.popleft() for neighbour in passages[cur]: tmp = distances[cur] + 1 if tmp < distances[neighbour]: distances[neighbour] = tmp signs[neighbour] = cur if neighbour not in visited: to_visit.append(neighbour) visited.add(cur) # LOG.debug((visited)) # LOG.debug((distances)) if len(visited) < n: return [] return signs[2:] def do_job(stdin, stdout): "Do the work" LOG.debug("Start working") N, M = map(int, stdin.readline().split()) if M < N: print("No", file=stdout) return values = [] for _ in range(M): a, b = map(int, stdin.readline().split()) values.append((a, b)) result = solve(values, N) if not result: print("No", file=stdout) else: print("Yes", file=stdout) print("\n".join(map(str, result)), file=stdout) def print_output(testcase: int, result, stdout) -> None: "Formats and print result" if result is None: result = "IMPOSSIBLE" print("Case #{}: {}".format(testcase + 1, result), file=stdout) # 6 digits float precision {:.6f} (6 is the default value) # print("Case #{}: {:f}".format(testcase + 1, result), file=stdout) BUFSIZE = 8192 class FastIO(IOBase): # pylint: disable=super-init-not-called, expression-not-assigned 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): # pylint: disable=super-init-not-called 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 configure_log() -> None: "Configure the log output" log_formatter = logging.Formatter("L%(lineno)d - " "%(message)s") handler = logging.StreamHandler(IOWrapper(sys.stderr)) handler.setFormatter(log_formatter) LOG.addHandler(handler) LOG = None # for interactive call: do not add multiple times the handler if not LOG: LOG = logging.getLogger("template") configure_log() def main(argv=None): "Program wrapper." if argv is None: argv = sys.argv[1:] parser = ArgumentParser() parser.add_argument( "-v", "--verbose", dest="verbose", action="store_true", default=False, help="run as verbose mode", ) args = parser.parse_args(argv) if args.verbose: LOG.setLevel(logging.DEBUG) stdin = IOWrapper(sys.stdin) stdout = IOWrapper(sys.stdout) do_job(stdin, stdout) stdout.flush() for h in LOG.handlers: h.flush() return 0 if __name__ == "__main__": sys.exit(main()) ```
instruction
0
89,019
8
178,038
No
output
1
89,019
8
178,039
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists. Constraints * All values in input are integers. * 2 \leq N \leq 10^5 * 1 \leq M \leq 2 \times 10^5 * 1 \leq A_i, B_i \leq N\ (1 \leq i \leq M) * A_i \neq B_i\ (1 \leq i \leq M) * One can travel between any two rooms by traversing passages. Input Input is given from Standard Input in the following format: N M A_1 B_1 : A_M B_M Output If there is no way to place signposts satisfying the objective, print `No`. Otherwise, print N lines. The first line should contain `Yes`, and the i-th line (2 \leq i \leq N) should contain the integer representing the room indicated by the signpost in Room i. Examples Input 4 4 1 2 2 3 3 4 4 2 Output Yes 1 2 2 Input 6 9 3 4 6 1 2 4 5 3 4 6 1 5 6 2 4 5 5 6 Output Yes 6 5 5 1 1 Submitted Solution: ``` n,m = (int(x) for x in input().split()) E = [[] for i in range(n+1)] for i in range(m): a,b = (int(x) for x in input().split()) E[a].append(b) E[b].append(a) #print(E) flag = [False]*(n+1) vs = [1] flag[1] = True res = [0]*(n+1) while(vs): this_v = vs[0] for i in E[this_v]: if flag[i]: continue else: res[i] = this_v flag[i] = True vs.append(i) vs = vs[1:] print("Yes") for i in res[2:]: print(i) ```
instruction
0
89,020
8
178,040
No
output
1
89,020
8
178,041
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists. Constraints * All values in input are integers. * 2 \leq N \leq 10^5 * 1 \leq M \leq 2 \times 10^5 * 1 \leq A_i, B_i \leq N\ (1 \leq i \leq M) * A_i \neq B_i\ (1 \leq i \leq M) * One can travel between any two rooms by traversing passages. Input Input is given from Standard Input in the following format: N M A_1 B_1 : A_M B_M Output If there is no way to place signposts satisfying the objective, print `No`. Otherwise, print N lines. The first line should contain `Yes`, and the i-th line (2 \leq i \leq N) should contain the integer representing the room indicated by the signpost in Room i. Examples Input 4 4 1 2 2 3 3 4 4 2 Output Yes 1 2 2 Input 6 9 3 4 6 1 2 4 5 3 4 6 1 5 6 2 4 5 5 6 Output Yes 6 5 5 1 1 Submitted Solution: ``` n, m = map(int, input().split()) ways = [tuple(map(int, input().split())) for _ in range(m)] table = [list() for _ in range(n+1)] hush = {} hush2 = {} for i in range(1, n+1): hush[i] = False hush2[i] = False ans = [0 for _ in range(n+1)] for a, b in ways: table[a].append(b) table[b].append(a) hush[1] = True def bfs(i): if hush2[i] == True: return else: hush2[i] = True for room in table[i]: if hush[room] == False: ans[room] = i hush[room] = True for room in table[i]: bfs(room) bfs(1) print('Yes') for i in range(2, n+1): print(ans[i]) ```
instruction
0
89,021
8
178,042
No
output
1
89,021
8
178,043
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists. Constraints * All values in input are integers. * 2 \leq N \leq 10^5 * 1 \leq M \leq 2 \times 10^5 * 1 \leq A_i, B_i \leq N\ (1 \leq i \leq M) * A_i \neq B_i\ (1 \leq i \leq M) * One can travel between any two rooms by traversing passages. Input Input is given from Standard Input in the following format: N M A_1 B_1 : A_M B_M Output If there is no way to place signposts satisfying the objective, print `No`. Otherwise, print N lines. The first line should contain `Yes`, and the i-th line (2 \leq i \leq N) should contain the integer representing the room indicated by the signpost in Room i. Examples Input 4 4 1 2 2 3 3 4 4 2 Output Yes 1 2 2 Input 6 9 3 4 6 1 2 4 5 3 4 6 1 5 6 2 4 5 5 6 Output Yes 6 5 5 1 1 Submitted Solution: ``` # N = int(input()) import numpy as np N,M = list(map(int, input().split())) paths = [] connection_dic = {} for i in range(N): connection_dic[i+1] = set() for i in range(M): A,B = list(map(int, input().split())) connection_dic[A].add(B) connection_dic[B].add(A) for i in range(N): if len(connection_dic[i+1]) == 0: print("No") exit() ans_list = np.zeros(N-1, dtype = np.int) current_distance = 0 parents = set([1]) next_parents = set() while len(parents) > 0: current_distance += 1 while len(parents) > 0: parent = parents.pop() for node in connection_dic[parent]: if ans_list[node-2] == 0: ans_list[node-2] = parent next_parents.add(node) parents = next_parents next_parents = set() print("Yes") for ans in ans_list: print(int(ans)) ```
instruction
0
89,022
8
178,044
No
output
1
89,022
8
178,045
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor. Let's assume that n people stand in the queue for the escalator. At each second one of the two following possibilities takes place: either the first person in the queue enters the escalator with probability p, or the first person in the queue doesn't move with probability (1 - p), paralyzed by his fear of escalators and making the whole queue wait behind him. Formally speaking, the i-th person in the queue cannot enter the escalator until people with indices from 1 to i - 1 inclusive enter it. In one second only one person can enter the escalator. The escalator is infinite, so if a person enters it, he never leaves it, that is he will be standing on the escalator at any following second. Ilya needs to count the expected value of the number of people standing on the escalator after t seconds. Your task is to help him solve this complicated task. Input The first line of the input contains three numbers n, p, t (1 ≤ n, t ≤ 2000, 0 ≤ p ≤ 1). Numbers n and t are integers, number p is real, given with exactly two digits after the decimal point. Output Print a single real number — the expected number of people who will be standing on the escalator after t seconds. The absolute or relative error mustn't exceed 10 - 6. Examples Input 1 0.50 1 Output 0.5 Input 1 0.50 4 Output 0.9375 Input 4 0.20 2 Output 0.4 Submitted Solution: ``` s = list(map(str, input().split())) n = int(s[0]) p = float(s[1]) t = int(s[2]) combi = [[0 for _ in range(t+1)] for _ in range(t+1)] combi[1][0] = 1 * p combi[1][1] = 1 * (1-p) for i in range(2, t+1): combi[i][0] = combi[i-1][0] * p for j in range(1, i+1): combi[i][j] = combi[i-1][j-1] * (1-p) + combi[i-1][j] * (p) e = 0 for i in range(t+1): v = n if (t-i) > n else (t-i) e += combi[t][i] * v print(e) ```
instruction
0
89,682
8
179,364
Yes
output
1
89,682
8
179,365
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor. Let's assume that n people stand in the queue for the escalator. At each second one of the two following possibilities takes place: either the first person in the queue enters the escalator with probability p, or the first person in the queue doesn't move with probability (1 - p), paralyzed by his fear of escalators and making the whole queue wait behind him. Formally speaking, the i-th person in the queue cannot enter the escalator until people with indices from 1 to i - 1 inclusive enter it. In one second only one person can enter the escalator. The escalator is infinite, so if a person enters it, he never leaves it, that is he will be standing on the escalator at any following second. Ilya needs to count the expected value of the number of people standing on the escalator after t seconds. Your task is to help him solve this complicated task. Input The first line of the input contains three numbers n, p, t (1 ≤ n, t ≤ 2000, 0 ≤ p ≤ 1). Numbers n and t are integers, number p is real, given with exactly two digits after the decimal point. Output Print a single real number — the expected number of people who will be standing on the escalator after t seconds. The absolute or relative error mustn't exceed 10 - 6. Examples Input 1 0.50 1 Output 0.5 Input 1 0.50 4 Output 0.9375 Input 4 0.20 2 Output 0.4 Submitted Solution: ``` a = input().split() n = int(a[0]) p = float(a[1]) t = int(a[2]) den = 100 ** t p = round(p * 100 + 1e-9) q = 100 - p ncr = [1 for i in range(2001)] for i in range(1, t + 1): ncr[i] = ncr[i - 1] * (t - i + 1) // i ans = 0 for i in range(2001): ans += min(i, n) * ncr[i] * (p ** i) * (q ** (t - i)) if t >= i else 0 ans /= den print(ans) ```
instruction
0
89,683
8
179,366
Yes
output
1
89,683
8
179,367
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor. Let's assume that n people stand in the queue for the escalator. At each second one of the two following possibilities takes place: either the first person in the queue enters the escalator with probability p, or the first person in the queue doesn't move with probability (1 - p), paralyzed by his fear of escalators and making the whole queue wait behind him. Formally speaking, the i-th person in the queue cannot enter the escalator until people with indices from 1 to i - 1 inclusive enter it. In one second only one person can enter the escalator. The escalator is infinite, so if a person enters it, he never leaves it, that is he will be standing on the escalator at any following second. Ilya needs to count the expected value of the number of people standing on the escalator after t seconds. Your task is to help him solve this complicated task. Input The first line of the input contains three numbers n, p, t (1 ≤ n, t ≤ 2000, 0 ≤ p ≤ 1). Numbers n and t are integers, number p is real, given with exactly two digits after the decimal point. Output Print a single real number — the expected number of people who will be standing on the escalator after t seconds. The absolute or relative error mustn't exceed 10 - 6. Examples Input 1 0.50 1 Output 0.5 Input 1 0.50 4 Output 0.9375 Input 4 0.20 2 Output 0.4 Submitted Solution: ``` dp=[[0 for i in range(2005)]for i in range(2005)] n,p,t=0,0,0 n,p,t=map(float,input().split()) n,t=int(n),int(t) dp[0][0]=1 for i in range(1,t+1): for j in range(n+1): if j==n : dp[i][j]=dp[i-1][j] else : dp[i][j]=dp[i-1][j]*(1-p) if j : dp[i][j]+=dp[i-1][j-1]*p ans=0 for i in range(n+1): # print(i,dp[t][i]) ans+=i*dp[t][i] print(ans) ```
instruction
0
89,684
8
179,368
Yes
output
1
89,684
8
179,369
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor. Let's assume that n people stand in the queue for the escalator. At each second one of the two following possibilities takes place: either the first person in the queue enters the escalator with probability p, or the first person in the queue doesn't move with probability (1 - p), paralyzed by his fear of escalators and making the whole queue wait behind him. Formally speaking, the i-th person in the queue cannot enter the escalator until people with indices from 1 to i - 1 inclusive enter it. In one second only one person can enter the escalator. The escalator is infinite, so if a person enters it, he never leaves it, that is he will be standing on the escalator at any following second. Ilya needs to count the expected value of the number of people standing on the escalator after t seconds. Your task is to help him solve this complicated task. Input The first line of the input contains three numbers n, p, t (1 ≤ n, t ≤ 2000, 0 ≤ p ≤ 1). Numbers n and t are integers, number p is real, given with exactly two digits after the decimal point. Output Print a single real number — the expected number of people who will be standing on the escalator after t seconds. The absolute or relative error mustn't exceed 10 - 6. Examples Input 1 0.50 1 Output 0.5 Input 1 0.50 4 Output 0.9375 Input 4 0.20 2 Output 0.4 Submitted Solution: ``` # Author : nitish420 -------------------------------------------------------------------- import os import sys from io import BytesIO, IOBase def main(): n,p,t=input().split() n=int(n) p=float(p) t=int(t) if p==float(0): print(0) exit() if p==float(1): print(min(n,t)) exit() dp=[[0 for _ in range(n+1)] for _ in range(t+1) ] dp[1][1]=p for r in range(2,t+1): for c in range(1,n+1): dp[r][c]=((p)*dp[r-1][c-1]+(1-p)*dp[r-1][c]) # for item in dp: # print(*item) ans=0 for item in dp: ans+=(sum(item)) print(ans) #---------------------------------------------------------------------------------------- # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = 'x' in file.mode or 'r' not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b'\n') + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode('ascii')) self.read = lambda: self.buffer.read().decode('ascii') self.readline = lambda: self.buffer.readline().decode('ascii') sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip('\r\n') # endregion if __name__ == '__main__': main() ```
instruction
0
89,685
8
179,370
Yes
output
1
89,685
8
179,371
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor. Let's assume that n people stand in the queue for the escalator. At each second one of the two following possibilities takes place: either the first person in the queue enters the escalator with probability p, or the first person in the queue doesn't move with probability (1 - p), paralyzed by his fear of escalators and making the whole queue wait behind him. Formally speaking, the i-th person in the queue cannot enter the escalator until people with indices from 1 to i - 1 inclusive enter it. In one second only one person can enter the escalator. The escalator is infinite, so if a person enters it, he never leaves it, that is he will be standing on the escalator at any following second. Ilya needs to count the expected value of the number of people standing on the escalator after t seconds. Your task is to help him solve this complicated task. Input The first line of the input contains three numbers n, p, t (1 ≤ n, t ≤ 2000, 0 ≤ p ≤ 1). Numbers n and t are integers, number p is real, given with exactly two digits after the decimal point. Output Print a single real number — the expected number of people who will be standing on the escalator after t seconds. The absolute or relative error mustn't exceed 10 - 6. Examples Input 1 0.50 1 Output 0.5 Input 1 0.50 4 Output 0.9375 Input 4 0.20 2 Output 0.4 Submitted Solution: ``` n,p,t=[float(i) for i in input().split()] if (p==0): print (0) elif (p==1): print (t) else: arr=[] for i in range(int(n)+1): arr.append([]) for j in range(int(t)+1): arr[-1].append(0) arr[1][1]=p temp=p for i in range(2,int(t)+1): temp*=(1-p) arr[1][i]=temp for i in range(2,int(n)+1): for j in range(i,int(t)+1): arr[i][j] = (arr[i-1][j]*p*(j-i+1))/((1-p)*(i-1)) sum=0 for i in range(1,int(n)+1): for j in range(1,int(t)+1): sum+=arr[i][j] print (sum) ```
instruction
0
89,687
8
179,374
No
output
1
89,687
8
179,375
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor. Let's assume that n people stand in the queue for the escalator. At each second one of the two following possibilities takes place: either the first person in the queue enters the escalator with probability p, or the first person in the queue doesn't move with probability (1 - p), paralyzed by his fear of escalators and making the whole queue wait behind him. Formally speaking, the i-th person in the queue cannot enter the escalator until people with indices from 1 to i - 1 inclusive enter it. In one second only one person can enter the escalator. The escalator is infinite, so if a person enters it, he never leaves it, that is he will be standing on the escalator at any following second. Ilya needs to count the expected value of the number of people standing on the escalator after t seconds. Your task is to help him solve this complicated task. Input The first line of the input contains three numbers n, p, t (1 ≤ n, t ≤ 2000, 0 ≤ p ≤ 1). Numbers n and t are integers, number p is real, given with exactly two digits after the decimal point. Output Print a single real number — the expected number of people who will be standing on the escalator after t seconds. The absolute or relative error mustn't exceed 10 - 6. Examples Input 1 0.50 1 Output 0.5 Input 1 0.50 4 Output 0.9375 Input 4 0.20 2 Output 0.4 Submitted Solution: ``` #4 .2 2 #ALL = (.8*.8) + (.2*.8 + .8*.2)*4 + (4,2)(.2*.2) #probability 1 is (4,1)(.2+ .8 .2) = 1 * (4,1) * (.2) ( 1 + .8) #probability 2 is (.2).2 (4,2) #1 .5 4 #probability of 1 is .5(1 + .5 2+ .5^2 3 + .5^3 4) # #4 .4 2 #probability of 1 is (.4 + .6(.4) + (.6)^2(.4) + (.6)^3(.4))(4,1) # =(2,1)(.4)(1+ .6+.6^2+.6^3) #probability of 2 is (.4)^2(1 + .6 + (.6)(.6)^2 # + (.6) + (.6)^2+ (.6)(.6)^2 = (4,2)(.4)^2 [1 + 2(.6) + 3(.6)^2] # (t choose n) to distribute ##### ON TOP IS WRONG NEW HERE #4 .2 2 #probability 1 is (.2 .8 + .8 .2) # 2 is (.2 .2) #4 .4 2 #probabiliy 1 is (.4(.6)^3 * t) #1 .5 4 #probaility 1 is (.5 + .5(.5) + .5(.5)^3 + ) from math import factorial as fact def bin(n, k): return fact(n)/(fact(k)*fact(n-k)) n,p,t = map(float, input().split()) oup = 0.0 for i in range(1,1+int(min(n, t))): quant = 0 if(n>t): quant = t * p**i * (1-p)**(t-i) else: w_t = False for j in range(i+1,int(t)+1): w_t = True quant += (1-p)**(j-1) if(not w_t): quant = 1 mod = i*p**i quant *= mod oup += quant print(oup) ```
instruction
0
89,688
8
179,376
No
output
1
89,688
8
179,377
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor. Let's assume that n people stand in the queue for the escalator. At each second one of the two following possibilities takes place: either the first person in the queue enters the escalator with probability p, or the first person in the queue doesn't move with probability (1 - p), paralyzed by his fear of escalators and making the whole queue wait behind him. Formally speaking, the i-th person in the queue cannot enter the escalator until people with indices from 1 to i - 1 inclusive enter it. In one second only one person can enter the escalator. The escalator is infinite, so if a person enters it, he never leaves it, that is he will be standing on the escalator at any following second. Ilya needs to count the expected value of the number of people standing on the escalator after t seconds. Your task is to help him solve this complicated task. Input The first line of the input contains three numbers n, p, t (1 ≤ n, t ≤ 2000, 0 ≤ p ≤ 1). Numbers n and t are integers, number p is real, given with exactly two digits after the decimal point. Output Print a single real number — the expected number of people who will be standing on the escalator after t seconds. The absolute or relative error mustn't exceed 10 - 6. Examples Input 1 0.50 1 Output 0.5 Input 1 0.50 4 Output 0.9375 Input 4 0.20 2 Output 0.4 Submitted Solution: ``` n, p, t = map(float, input().split()) n, t = int(n + 0.5), int(t + 0.5) from math import exp, lgamma def c(a, b): if a == b: return 1 return exp(lgamma(a + 1) - lgamma(b + 1) - lgamma(a - b + 1)) print(p) print(sum(p**i * (1 - p)**(t - i) * c(t, i) * min(i, n) for i in range(t + 1))) ```
instruction
0
89,689
8
179,378
No
output
1
89,689
8
179,379
Provide a correct Python 3 solution for this coding contest problem. There are N squares arranged in a row, numbered 1 to N from left to right. Takahashi will stack building blocks on these squares, on which there are no blocks yet. He wants to stack blocks on the squares evenly, so he will repeat the following operation until there are H blocks on every square: * Let M and m be the maximum and minimum numbers of blocks currently stacked on a square, respectively. Choose a square on which m blocks are stacked (if there are multiple such squares, choose any one of them), and add a positive number of blocks on that square so that there will be at least M and at most M + D blocks on that square. Tell him how many ways there are to have H blocks on every square by repeating this operation. Since there can be extremely many ways, print the number modulo 10^9+7. Constraints * 2 \leq N \leq 10^6 * 1 \leq D \leq H \leq 10^6 * All values in input are integers. Input Input is given from Standard Input in the following format: N H D Output Print the number of ways to have H blocks on every square, modulo 10^9+7. Examples Input 2 2 1 Output 6 Input 2 30 15 Output 94182806 Input 31415 9265 3589 Output 312069529
instruction
0
89,913
8
179,826
"Correct Solution: ``` """ Writer: SPD_9X2 https://atcoder.jp/contests/diverta2019-2/tasks/diverta2019_2_e Mの時、 a1<=a2<=a3…aN を満たす通り数 X[M] が分かれば解ける(全ての順N!は等しいため) 当然、次のMにはa1から順に更新していくことになる(M+?にね) Dの時 X[M] = (X[M-1] + X[M-2] + … + X[M-D]) * N が成立かな X[0] = 1 N=2 X[0]=1 X[1]=2 X[2]=6 N=3 X[0]=1 X[1]=9 X[M]の更新式 →これが間違ってそう X[M] = (X[M-1] + X[M-2] + … + X[M-D]) * (1!+2!+3!+…N!) →エスパーだけどなんか正しそう X[H-1]を求めてN!を掛ければそれが答え →サンプル合った!! """ import math N,H,D = map(int,input().split()) mod = 10**9+7 mul = 0 fac = 1 for i in range(1,N+1): fac *= i fac %= mod mul += fac mul %= mod X = [1] nsum = 1 for i in range(H-1): #print (i,nsum,mul) X.append(nsum*mul%mod) nsum += X[-1] nsum %= mod if i >= D-1: nsum -= X[i-D+1] #print (X) print (nsum * fac % mod) ```
output
1
89,913
8
179,827
Provide a correct Python 3 solution for this coding contest problem. There are N squares arranged in a row, numbered 1 to N from left to right. Takahashi will stack building blocks on these squares, on which there are no blocks yet. He wants to stack blocks on the squares evenly, so he will repeat the following operation until there are H blocks on every square: * Let M and m be the maximum and minimum numbers of blocks currently stacked on a square, respectively. Choose a square on which m blocks are stacked (if there are multiple such squares, choose any one of them), and add a positive number of blocks on that square so that there will be at least M and at most M + D blocks on that square. Tell him how many ways there are to have H blocks on every square by repeating this operation. Since there can be extremely many ways, print the number modulo 10^9+7. Constraints * 2 \leq N \leq 10^6 * 1 \leq D \leq H \leq 10^6 * All values in input are integers. Input Input is given from Standard Input in the following format: N H D Output Print the number of ways to have H blocks on every square, modulo 10^9+7. Examples Input 2 2 1 Output 6 Input 2 30 15 Output 94182806 Input 31415 9265 3589 Output 312069529
instruction
0
89,914
8
179,828
"Correct Solution: ``` N, H, D = map(int, input().split()) MOD = 10**9 + 7 v = 1 w = 0 for i in range(1, N+1): v = v * i % MOD w += v v %= MOD w %= MOD dp = [0]*(H+1) dp[0] = v s = 0 for i in range(H): s += dp[i] % MOD if i+1 < H: dp[i+1] = s * w % MOD else: dp[i+1] = s % MOD if i-D+1 >= 0: s -= dp[i-D+1] % MOD print(dp[H]) ```
output
1
89,914
8
179,829
Provide a correct Python 3 solution for this coding contest problem. There are N squares arranged in a row, numbered 1 to N from left to right. Takahashi will stack building blocks on these squares, on which there are no blocks yet. He wants to stack blocks on the squares evenly, so he will repeat the following operation until there are H blocks on every square: * Let M and m be the maximum and minimum numbers of blocks currently stacked on a square, respectively. Choose a square on which m blocks are stacked (if there are multiple such squares, choose any one of them), and add a positive number of blocks on that square so that there will be at least M and at most M + D blocks on that square. Tell him how many ways there are to have H blocks on every square by repeating this operation. Since there can be extremely many ways, print the number modulo 10^9+7. Constraints * 2 \leq N \leq 10^6 * 1 \leq D \leq H \leq 10^6 * All values in input are integers. Input Input is given from Standard Input in the following format: N H D Output Print the number of ways to have H blocks on every square, modulo 10^9+7. Examples Input 2 2 1 Output 6 Input 2 30 15 Output 94182806 Input 31415 9265 3589 Output 312069529
instruction
0
89,915
8
179,830
"Correct Solution: ``` mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline N, H, D = map(int, input().split()) imos = [0] * (H+2) ans = [0] * (H+1) M = 0 f = 1 for i in range(1, N+1): f = (f * i)%mod M = (M + f)%mod imos[1] += f imos[D+1] -= f for i in range(1, H): ans[i] = (ans[i-1] + imos[i])%mod imos[i+1] = (imos[i+1] + (ans[i] * M)%mod)%mod if i+D+1 <= H: imos[i+D+1] = (imos[i+D+1] - (ans[i] * M)%mod)%mod print((ans[H-1] + imos[H])%mod) if __name__ == '__main__': main() ```
output
1
89,915
8
179,831
Provide a correct Python 3 solution for this coding contest problem. There are N squares arranged in a row, numbered 1 to N from left to right. Takahashi will stack building blocks on these squares, on which there are no blocks yet. He wants to stack blocks on the squares evenly, so he will repeat the following operation until there are H blocks on every square: * Let M and m be the maximum and minimum numbers of blocks currently stacked on a square, respectively. Choose a square on which m blocks are stacked (if there are multiple such squares, choose any one of them), and add a positive number of blocks on that square so that there will be at least M and at most M + D blocks on that square. Tell him how many ways there are to have H blocks on every square by repeating this operation. Since there can be extremely many ways, print the number modulo 10^9+7. Constraints * 2 \leq N \leq 10^6 * 1 \leq D \leq H \leq 10^6 * All values in input are integers. Input Input is given from Standard Input in the following format: N H D Output Print the number of ways to have H blocks on every square, modulo 10^9+7. Examples Input 2 2 1 Output 6 Input 2 30 15 Output 94182806 Input 31415 9265 3589 Output 312069529
instruction
0
89,916
8
179,832
"Correct Solution: ``` N, H, D = map(int,input().split()) MOD = 10**9 + 7 fact = [1] fact_cum = [0] for i in range(1,N+1): fact.append((fact[-1]*i)%MOD) fact_cum.append((fact_cum[-1] + fact[-1])%MOD) ap = [0] * (H+1) ap_cum = [0] * (H+1) ap[0] = 1 ap_cum[0] = 1 for n in range(1,H+1): x = ap_cum[n-1] if n > D: x -=ap_cum[n-D-1] x *= fact_cum[N] x %= MOD ap[n] = x ap_cum[n] = (ap_cum[n-1] + x)%MOD ans = ap[H] ans *= fact[N] ans %= MOD ans *= pow(fact_cum[N],MOD-2,MOD) ans %= MOD print(ans) ```
output
1
89,916
8
179,833
Provide a correct Python 3 solution for this coding contest problem. There are N squares arranged in a row, numbered 1 to N from left to right. Takahashi will stack building blocks on these squares, on which there are no blocks yet. He wants to stack blocks on the squares evenly, so he will repeat the following operation until there are H blocks on every square: * Let M and m be the maximum and minimum numbers of blocks currently stacked on a square, respectively. Choose a square on which m blocks are stacked (if there are multiple such squares, choose any one of them), and add a positive number of blocks on that square so that there will be at least M and at most M + D blocks on that square. Tell him how many ways there are to have H blocks on every square by repeating this operation. Since there can be extremely many ways, print the number modulo 10^9+7. Constraints * 2 \leq N \leq 10^6 * 1 \leq D \leq H \leq 10^6 * All values in input are integers. Input Input is given from Standard Input in the following format: N H D Output Print the number of ways to have H blocks on every square, modulo 10^9+7. Examples Input 2 2 1 Output 6 Input 2 30 15 Output 94182806 Input 31415 9265 3589 Output 312069529
instruction
0
89,917
8
179,834
"Correct Solution: ``` import sys sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def main(): md = 10 ** 9 + 7 n, h, d = MI() sum_fact = 0 n_fact = 1 for x in range(1, n + 1): n_fact *= x sum_fact += n_fact n_fact %= md sum_fact %= md if h==1: print(n_fact) exit() dp = [0] * (h + 1) dp[0] = dp[1] = n_fact s = 0 for i in range(2, h + 1): if i <= d: s += dp[i - 1] dp[i] = s * sum_fact + dp[0] elif i == d + 1: s += dp[i - 1] dp[i] = s * sum_fact else: s += dp[i - 1] - dp[i - 1 - d] dp[i] = s * sum_fact s %= md dp[i] %= md print(dp[-1]) main() ```
output
1
89,917
8
179,835
Provide a correct Python 3 solution for this coding contest problem. There are N squares arranged in a row, numbered 1 to N from left to right. Takahashi will stack building blocks on these squares, on which there are no blocks yet. He wants to stack blocks on the squares evenly, so he will repeat the following operation until there are H blocks on every square: * Let M and m be the maximum and minimum numbers of blocks currently stacked on a square, respectively. Choose a square on which m blocks are stacked (if there are multiple such squares, choose any one of them), and add a positive number of blocks on that square so that there will be at least M and at most M + D blocks on that square. Tell him how many ways there are to have H blocks on every square by repeating this operation. Since there can be extremely many ways, print the number modulo 10^9+7. Constraints * 2 \leq N \leq 10^6 * 1 \leq D \leq H \leq 10^6 * All values in input are integers. Input Input is given from Standard Input in the following format: N H D Output Print the number of ways to have H blocks on every square, modulo 10^9+7. Examples Input 2 2 1 Output 6 Input 2 30 15 Output 94182806 Input 31415 9265 3589 Output 312069529
instruction
0
89,918
8
179,836
"Correct Solution: ``` N, H, D = map(int, input().split()) P, a, s = 10**9+7, 1, 0 for i in range(1, N+1): a = a*i%P s = (s+a)%P X = [a] for i in range(1, H): X.append(a*s%P) a += X[-1] if i >= D: a -= X[-D-1] a %= P print(a) ```
output
1
89,918
8
179,837
Provide a correct Python 3 solution for this coding contest problem. There are N squares arranged in a row, numbered 1 to N from left to right. Takahashi will stack building blocks on these squares, on which there are no blocks yet. He wants to stack blocks on the squares evenly, so he will repeat the following operation until there are H blocks on every square: * Let M and m be the maximum and minimum numbers of blocks currently stacked on a square, respectively. Choose a square on which m blocks are stacked (if there are multiple such squares, choose any one of them), and add a positive number of blocks on that square so that there will be at least M and at most M + D blocks on that square. Tell him how many ways there are to have H blocks on every square by repeating this operation. Since there can be extremely many ways, print the number modulo 10^9+7. Constraints * 2 \leq N \leq 10^6 * 1 \leq D \leq H \leq 10^6 * All values in input are integers. Input Input is given from Standard Input in the following format: N H D Output Print the number of ways to have H blocks on every square, modulo 10^9+7. Examples Input 2 2 1 Output 6 Input 2 30 15 Output 94182806 Input 31415 9265 3589 Output 312069529
instruction
0
89,919
8
179,838
"Correct Solution: ``` N,H,D=map(int,input().split()) mod=10**9+7 table=[1] num=0 for i in range(1,N+1): table.append(table[-1]*i%mod) num=(num+table[-1])%mod dp=[0]*(H+1) d_sum=[0]*(H+1) for i in range(1,D+1): dp[i]=table[N] for i in range(1,H+1): dp[i]=(dp[i]+(d_sum[i-1]-d_sum[max(0,i-D-1)])*num)%mod d_sum[i]=(dp[i]+d_sum[i-1])%mod print(dp[H]) ```
output
1
89,919
8
179,839
Provide a correct Python 3 solution for this coding contest problem. There are N squares arranged in a row, numbered 1 to N from left to right. Takahashi will stack building blocks on these squares, on which there are no blocks yet. He wants to stack blocks on the squares evenly, so he will repeat the following operation until there are H blocks on every square: * Let M and m be the maximum and minimum numbers of blocks currently stacked on a square, respectively. Choose a square on which m blocks are stacked (if there are multiple such squares, choose any one of them), and add a positive number of blocks on that square so that there will be at least M and at most M + D blocks on that square. Tell him how many ways there are to have H blocks on every square by repeating this operation. Since there can be extremely many ways, print the number modulo 10^9+7. Constraints * 2 \leq N \leq 10^6 * 1 \leq D \leq H \leq 10^6 * All values in input are integers. Input Input is given from Standard Input in the following format: N H D Output Print the number of ways to have H blocks on every square, modulo 10^9+7. Examples Input 2 2 1 Output 6 Input 2 30 15 Output 94182806 Input 31415 9265 3589 Output 312069529
instruction
0
89,920
8
179,840
"Correct Solution: ``` N, H, D = map(int, input().split()) MOD = 10 ** 9 + 7 fact = 1 s = 0 for i in range(1, N+1) : fact = fact * i % MOD s = (s + fact) % MOD dp = [0] * H dp[0] = 1 ret = 1 for i in range(1, H) : dp[i] = ret * s % MOD ret = (ret + ret * s) % MOD if i >= D : ret = (ret - dp[i - D]) % MOD print(ret * fact % MOD) ```
output
1
89,920
8
179,841
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N squares arranged in a row, numbered 1 to N from left to right. Takahashi will stack building blocks on these squares, on which there are no blocks yet. He wants to stack blocks on the squares evenly, so he will repeat the following operation until there are H blocks on every square: * Let M and m be the maximum and minimum numbers of blocks currently stacked on a square, respectively. Choose a square on which m blocks are stacked (if there are multiple such squares, choose any one of them), and add a positive number of blocks on that square so that there will be at least M and at most M + D blocks on that square. Tell him how many ways there are to have H blocks on every square by repeating this operation. Since there can be extremely many ways, print the number modulo 10^9+7. Constraints * 2 \leq N \leq 10^6 * 1 \leq D \leq H \leq 10^6 * All values in input are integers. Input Input is given from Standard Input in the following format: N H D Output Print the number of ways to have H blocks on every square, modulo 10^9+7. Examples Input 2 2 1 Output 6 Input 2 30 15 Output 94182806 Input 31415 9265 3589 Output 312069529 Submitted Solution: ``` n, h, d = map(int, input().split()) MOD = 10 ** 9 + 7 fact = [1] * (n + 1) for i in range(n): fact[i + 1] = fact[i] * (i + 1) fact[i + 1] %= MOD # fact_sum = fact[1] + fact[2] + ... + fact[n] fact_sum = 0 for i in range(1, n + 1): fact_sum += fact[i] fact_sum %= MOD dp = [0] * (h + 1) ru = [0] * (h + 2) dp[0] = 1 ru[1] = 1 for i in range(h): l = max(i + 1 - d, 0) dp[i + 1] += (ru[i + 1] - ru[l]) * fact_sum dp[i + 1] %= MOD ru[i + 2] = ru[i + 1] + dp[i + 1] ru[i + 2] %= MOD print((dp[-1] * fact[n] * pow(fact_sum, MOD - 2, MOD)) % MOD) ```
instruction
0
89,921
8
179,842
Yes
output
1
89,921
8
179,843
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N squares arranged in a row, numbered 1 to N from left to right. Takahashi will stack building blocks on these squares, on which there are no blocks yet. He wants to stack blocks on the squares evenly, so he will repeat the following operation until there are H blocks on every square: * Let M and m be the maximum and minimum numbers of blocks currently stacked on a square, respectively. Choose a square on which m blocks are stacked (if there are multiple such squares, choose any one of them), and add a positive number of blocks on that square so that there will be at least M and at most M + D blocks on that square. Tell him how many ways there are to have H blocks on every square by repeating this operation. Since there can be extremely many ways, print the number modulo 10^9+7. Constraints * 2 \leq N \leq 10^6 * 1 \leq D \leq H \leq 10^6 * All values in input are integers. Input Input is given from Standard Input in the following format: N H D Output Print the number of ways to have H blocks on every square, modulo 10^9+7. Examples Input 2 2 1 Output 6 Input 2 30 15 Output 94182806 Input 31415 9265 3589 Output 312069529 Submitted Solution: ``` N,H,D=map(int,input().split()) mod=10**9+7 const=0 frac=[1] for i in range(1,N+1): frac.append((frac[-1]*i)%mod) const=(const+frac[-1])%mod dp=[0]*(H+1) dp[0]=1 dp[1]=frac[-1] S=dp[1] for i in range(2,D+1): dp[i]=const*S+frac[-1] dp[i]%=mod S=(S+dp[i])%mod S=sum(dp[i] for i in range(1,D+1)) S%=mod for i in range(D+1,H+1): dp[i]=const*S dp[i]%=mod S=(S+dp[i]-dp[i-D])%mod print(dp[H]) ```
instruction
0
89,922
8
179,844
Yes
output
1
89,922
8
179,845
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N squares arranged in a row, numbered 1 to N from left to right. Takahashi will stack building blocks on these squares, on which there are no blocks yet. He wants to stack blocks on the squares evenly, so he will repeat the following operation until there are H blocks on every square: * Let M and m be the maximum and minimum numbers of blocks currently stacked on a square, respectively. Choose a square on which m blocks are stacked (if there are multiple such squares, choose any one of them), and add a positive number of blocks on that square so that there will be at least M and at most M + D blocks on that square. Tell him how many ways there are to have H blocks on every square by repeating this operation. Since there can be extremely many ways, print the number modulo 10^9+7. Constraints * 2 \leq N \leq 10^6 * 1 \leq D \leq H \leq 10^6 * All values in input are integers. Input Input is given from Standard Input in the following format: N H D Output Print the number of ways to have H blocks on every square, modulo 10^9+7. Examples Input 2 2 1 Output 6 Input 2 30 15 Output 94182806 Input 31415 9265 3589 Output 312069529 Submitted Solution: ``` N, H, D = map(int,input().split()) MOD = 10**9 + 7 fact = [1] fact_cum = [0] # 1! to N! for i in range(1,N+1): fact.append((fact[-1]*i)%MOD) fact_cum.append((fact_cum[-1] + fact[-1])%MOD) dp = [0] * (H+1) dp_cum = [0] * (H+1) dp[0] = 1 dp_cum[0] = 1 for n in range(1,H+1): x = dp_cum[n-1] if n > D: x -= dp_cum[n-D-1] x *= fact_cum[N] x %= MOD dp[n] = x dp_cum[n] = (dp_cum[n-1] + x)%MOD answer = dp[H] answer *= fact[N] answer %= MOD answer *= pow(fact_cum[N],MOD-2,MOD) answer %= MOD print(answer) ```
instruction
0
89,923
8
179,846
Yes
output
1
89,923
8
179,847
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N squares arranged in a row, numbered 1 to N from left to right. Takahashi will stack building blocks on these squares, on which there are no blocks yet. He wants to stack blocks on the squares evenly, so he will repeat the following operation until there are H blocks on every square: * Let M and m be the maximum and minimum numbers of blocks currently stacked on a square, respectively. Choose a square on which m blocks are stacked (if there are multiple such squares, choose any one of them), and add a positive number of blocks on that square so that there will be at least M and at most M + D blocks on that square. Tell him how many ways there are to have H blocks on every square by repeating this operation. Since there can be extremely many ways, print the number modulo 10^9+7. Constraints * 2 \leq N \leq 10^6 * 1 \leq D \leq H \leq 10^6 * All values in input are integers. Input Input is given from Standard Input in the following format: N H D Output Print the number of ways to have H blocks on every square, modulo 10^9+7. Examples Input 2 2 1 Output 6 Input 2 30 15 Output 94182806 Input 31415 9265 3589 Output 312069529 Submitted Solution: ``` n, h, d = map(int, input().split()) MOD = 10 ** 9 + 7 fact, fact_acc = 1, 1 for i in range(2, n + 1): fact = fact * i % MOD fact_acc = (fact_acc + fact) % MOD dp = [0] * (h + 1) dp[0] = base = fact for i in range(1, h): dp[i] = base * fact_acc % MOD base = (base + dp[i]) % MOD if i >= d: base = (base - dp[i - d]) % MOD print(base) ```
instruction
0
89,924
8
179,848
Yes
output
1
89,924
8
179,849
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N squares arranged in a row, numbered 1 to N from left to right. Takahashi will stack building blocks on these squares, on which there are no blocks yet. He wants to stack blocks on the squares evenly, so he will repeat the following operation until there are H blocks on every square: * Let M and m be the maximum and minimum numbers of blocks currently stacked on a square, respectively. Choose a square on which m blocks are stacked (if there are multiple such squares, choose any one of them), and add a positive number of blocks on that square so that there will be at least M and at most M + D blocks on that square. Tell him how many ways there are to have H blocks on every square by repeating this operation. Since there can be extremely many ways, print the number modulo 10^9+7. Constraints * 2 \leq N \leq 10^6 * 1 \leq D \leq H \leq 10^6 * All values in input are integers. Input Input is given from Standard Input in the following format: N H D Output Print the number of ways to have H blocks on every square, modulo 10^9+7. Examples Input 2 2 1 Output 6 Input 2 30 15 Output 94182806 Input 31415 9265 3589 Output 312069529 Submitted Solution: ``` n = int(input()) ga, sa, ba = list(map(int, input().split())) gb, sb, bb = list(map(int, input().split())) w_ab = [] v_ab = [] if ga < gb: w_ab.append(ga) v_ab.append(gb) if sa < sb: w_ab.append(sa) v_ab.append(sb) if ba < bb: w_ab.append(ba) v_ab.append(bb) num = (n+1)*(len(w_ab)+1) dp = [0]*num for i in range(len(w_ab)): for j in range(n+1): if j < w_ab[i]: dp[(i+1)*(n+1) + j] = dp[i*(n+1) + j] else: dp[(i+1)*(n+1) + j] = max(dp[i*(n+1) + j], dp[(i+1)*(n+1) + j - w_ab[i]] + v_ab[i]) ans = 0 length = len(w_ab) for j in range(n+1): ans = max(ans, dp[length*(n+1) + j] + n-j) n = ans w_ab = [] v_ab = [] if ga > gb: w_ab.append(gb) v_ab.append(ga) if sa > sb: w_ab.append(sb) v_ab.append(sa) if ba > bb: w_ab.append(bb) v_ab.append(ba) num = (n+1)*(len(w_ab)+1) dp = [0]*num for i in range(len(w_ab)): for j in range(n+1): if j < w_ab[i]: dp[(i+1)*(n+1) + j] = dp[i*(n+1) + j] else: dp[(i+1)*(n+1) + j] = max(dp[i*(n+1) + j], dp[(i+1)*(n+1) + j - w_ab[i]] + v_ab[i]) length = len(w_ab) ans = 0 for j in range(n+1): ans = max(ans, dp[length*(n+1) + j] + n-j) print(ans) ```
instruction
0
89,925
8
179,850
No
output
1
89,925
8
179,851
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N squares arranged in a row, numbered 1 to N from left to right. Takahashi will stack building blocks on these squares, on which there are no blocks yet. He wants to stack blocks on the squares evenly, so he will repeat the following operation until there are H blocks on every square: * Let M and m be the maximum and minimum numbers of blocks currently stacked on a square, respectively. Choose a square on which m blocks are stacked (if there are multiple such squares, choose any one of them), and add a positive number of blocks on that square so that there will be at least M and at most M + D blocks on that square. Tell him how many ways there are to have H blocks on every square by repeating this operation. Since there can be extremely many ways, print the number modulo 10^9+7. Constraints * 2 \leq N \leq 10^6 * 1 \leq D \leq H \leq 10^6 * All values in input are integers. Input Input is given from Standard Input in the following format: N H D Output Print the number of ways to have H blocks on every square, modulo 10^9+7. Examples Input 2 2 1 Output 6 Input 2 30 15 Output 94182806 Input 31415 9265 3589 Output 312069529 Submitted Solution: ``` n, h, d = map(int, input().split()) MOD = 10 ** 9 + 7 if n * h * d >= 10 ** 7: print(re) # dp[i][j] := 高さiのブロックが最大高さでj個ある時の通り数 dp = [[0] * (n + 1) for i in range(h + 1)] dp[0][n] = 1 # O(HDN) for i in range(h): # j = 0 -> j = 1 にする for diff in range(1, d + 1): if i + 1 - diff < 0: continue for cnt in range(1, n + 1): dp[i + 1][1] += dp[i + 1 - diff][cnt] * cnt dp[i + 1][1] %= MOD # j -> j + 1 にする for j in range(2, n + 1): dp[i + 1][j] += dp[i + 1][j - 1] * (n - (j - 1)) dp[i + 1][j] %= MOD print(dp[-1][-1]) ```
instruction
0
89,926
8
179,852
No
output
1
89,926
8
179,853
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N squares arranged in a row, numbered 1 to N from left to right. Takahashi will stack building blocks on these squares, on which there are no blocks yet. He wants to stack blocks on the squares evenly, so he will repeat the following operation until there are H blocks on every square: * Let M and m be the maximum and minimum numbers of blocks currently stacked on a square, respectively. Choose a square on which m blocks are stacked (if there are multiple such squares, choose any one of them), and add a positive number of blocks on that square so that there will be at least M and at most M + D blocks on that square. Tell him how many ways there are to have H blocks on every square by repeating this operation. Since there can be extremely many ways, print the number modulo 10^9+7. Constraints * 2 \leq N \leq 10^6 * 1 \leq D \leq H \leq 10^6 * All values in input are integers. Input Input is given from Standard Input in the following format: N H D Output Print the number of ways to have H blocks on every square, modulo 10^9+7. Examples Input 2 2 1 Output 6 Input 2 30 15 Output 94182806 Input 31415 9265 3589 Output 312069529 Submitted Solution: ``` n, h, d = map(int, input().split()) MOD = 10 ** 9 + 7 if d != 1: print(re) fact = [1] * (n + 1) for i in range(n): fact[i + 1] = fact[i] * (i + 1) fact[i + 1] %= MOD # fact_sum = fact[1] + fact[2] + ... + fact[n] fact_sum = 0 for i in range(1, n + 1): fact_sum += fact[i] fact_sum %= MOD dp = [0] * (h + 1) dp[0] = 1 for i in range(h): dp[i + 1] = dp[i] * fact_sum dp[i + 1] %= MOD print((dp[-1] - dp[-2] * (fact_sum - fact[-1])) % MOD) ```
instruction
0
89,927
8
179,854
No
output
1
89,927
8
179,855
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N squares arranged in a row, numbered 1 to N from left to right. Takahashi will stack building blocks on these squares, on which there are no blocks yet. He wants to stack blocks on the squares evenly, so he will repeat the following operation until there are H blocks on every square: * Let M and m be the maximum and minimum numbers of blocks currently stacked on a square, respectively. Choose a square on which m blocks are stacked (if there are multiple such squares, choose any one of them), and add a positive number of blocks on that square so that there will be at least M and at most M + D blocks on that square. Tell him how many ways there are to have H blocks on every square by repeating this operation. Since there can be extremely many ways, print the number modulo 10^9+7. Constraints * 2 \leq N \leq 10^6 * 1 \leq D \leq H \leq 10^6 * All values in input are integers. Input Input is given from Standard Input in the following format: N H D Output Print the number of ways to have H blocks on every square, modulo 10^9+7. Examples Input 2 2 1 Output 6 Input 2 30 15 Output 94182806 Input 31415 9265 3589 Output 312069529 Submitted Solution: ``` n, h, d = map(int, input().split()) MOD = 10 ** 9 + 7 if n * h + h * d >= 10 ** 7: print(re) # dp[i][j] := 高さiのブロックが最大高さでj個ある時の通り数 dp = [[0] * (n + 1) for i in range(h + 1)] dp[0][n] = 1 # O(HN) ru = [[0] * (n + 2) for i in range(h + 1)] ru[0][n + 1] = 1 for i in range(h): # j = 0 -> j = 1 にする for diff in range(1, d + 1): if i + 1 - diff < 0: continue dp[i + 1][1] += ru[i + 1 - diff][n + 1] dp[i + 1][1] %= MOD # j - 1 -> j にする for j in range(2, n + 1): dp[i + 1][j] += dp[i + 1][j - 1] * j dp[i + 1][j] %= MOD for j in range(n + 1): ru[i + 1][j + 1] = ru[i + 1][j] + dp[i + 1][j] ru[i + 1][j + 1] %= MOD print(dp[-1][-1] % MOD) ```
instruction
0
89,928
8
179,856
No
output
1
89,928
8
179,857
Provide a correct Python 3 solution for this coding contest problem. There are n rabbits, one in each of the huts numbered 0 through n − 1. At one point, information came to the rabbits that a secret organization would be constructing an underground passage. The underground passage would allow the rabbits to visit other rabbits' huts. I'm happy. The passages can go in both directions, and the passages do not intersect. Due to various circumstances, the passage once constructed may be destroyed. The construction and destruction of the passages are carried out one by one, and each construction It is assumed that the rabbit stays in his hut. Rabbits want to know in advance if one rabbit and one rabbit can play at some stage of construction. Rabbits are good friends, so they are free to go through other rabbit huts when they go out to play. Rabbits who like programming tried to solve a similar problem in the past, thinking that it would be easy, but they couldn't write an efficient program. Solve this problem instead of the rabbit. Input The first line of input is given n and k separated by spaces. 2 ≤ n ≤ 40 000, 1 ≤ k ≤ 40 000 In the following k lines, construction information and questions are combined and given in chronological order. * “1 u v” — A passage connecting huts u and v is constructed. Appears only when there is no passage connecting huts u and v. * “2 u v” — The passage connecting huts u and v is destroyed. Appears only when there is a passage connecting huts u and v. * “3 u v” — Determine if the rabbits in the hut u and v can be played. 0 ≤ u <v <n Output For each question that appears in the input, output "YES" if you can play, or "NO" if not. Example Input 4 10 1 0 1 1 0 2 3 1 2 2 0 1 1 2 3 3 0 1 1 0 1 2 0 2 1 1 3 3 0 2 Output YES NO YES
instruction
0
90,059
8
180,118
"Correct Solution: ``` from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N, K = map(int, readline().split()) ES = [list(map(int, readline().split())) for i in range(K)] emp = {} sq = int(K**.5) + 1 def root(x): if x == p[x]: return x p[x] = y = root(p[x]) return y def unite(x, y): px = root(x); py = root(y) if px < py: p[py] = px else: p[px] = py que = deque() used = [0]*N lb = 0 p = [0]*N for i in range(sq): s = set() for j in range(i*sq, min(i*sq+sq, K)): t, a, b = ES[j] if t == 3: continue e = (a, b) if emp.get(e, 0): s.add(e) emp[e] = 0 p[:] = range(N) for (v, w), d in emp.items(): if d == 1: unite(v, w) G0 = [[] for i in range(N)] emp0 = {} for a, b in s: pa = root(a); pb = root(b) if pa == pb: continue e = (pa, pb) if pa < pb else (pb, pa) if e in emp0: e1, e2 = emp0[e] e1[1] = e2[1] = e1[1] + 1 else: e1 = [pb, 1]; e2 = [pa, 1] G0[pa].append(e1) G0[pb].append(e2) emp0[e] = e1, e2 for j in range(i*sq, min(i*sq+sq, K)): t, a, b = ES[j] pa = root(a); pb = root(b) e = (pa, pb) if pa < pb else (pb, pa) if t == 1: emp[a, b] = 1 if pa == pb: continue if e not in emp0: e1 = [pb, 1]; e2 = [pa, 1] G0[pa].append(e1) G0[pb].append(e2) emp0[e] = e1, e2 else: e1, e2 = emp0[e] e1[1] = e2[1] = e1[1] + 1 elif t == 2: emp[a, b] = 0 if pa == pb: continue e1, e2 = emp0[e] e1[1] = e2[1] = e1[1] - 1 elif t == 3: if pa == pb: write("YES\n") else: lb += 1 que.append(pa) used[pa] = lb while que: v = que.popleft() for w, d in G0[v]: if d and used[w] != lb: used[w] = lb que.append(w) if used[pb] == lb: write("YES\n") else: write("NO\n") solve() ```
output
1
90,059
8
180,119
Provide tags and a correct Python 3 solution for this coding contest problem. On February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length k (k ≥ 3). Nastya was very confused by this present, so she decided to break the door, throwing it on the mountains. Mountains are described by a sequence of heights a_1, a_2, ..., a_n in order from left to right (k ≤ n). It is guaranteed that neighboring heights are not equal to each other (that is, a_i ≠ a_{i+1} for all i from 1 to n-1). Peaks of mountains on the segment [l,r] (from l to r) are called indexes i such that l < i < r, a_{i - 1} < a_i and a_i > a_{i + 1}. It is worth noting that the boundary indexes l and r for the segment are not peaks. For example, if n=8 and a=[3,1,4,1,5,9,2,6], then the segment [1,8] has only two peaks (with indexes 3 and 6), and there are no peaks on the segment [3, 6]. To break the door, Nastya throws it to a segment [l,l+k-1] of consecutive mountains of length k (1 ≤ l ≤ n-k+1). When the door touches the peaks of the mountains, it breaks into two parts, after that these parts will continue to fall in different halves and also break into pieces when touching the peaks of the mountains, and so on. Formally, the number of parts that the door will break into will be equal to p+1, where p is the number of peaks on the segment [l,l+k-1]. Nastya wants to break it into as many pieces as possible. Help her choose such a segment of mountains [l, l+k-1] that the number of peaks on it is maximum. If there are several optimal segments, Nastya wants to find one for which the value l is minimal. Formally, you need to choose a segment of mountains [l, l+k-1] that has the maximum number of peaks. Among all such segments, you need to find the segment that has the minimum possible value l. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then the descriptions of the test cases follow. The first line of each test case contains two integers n and k (3 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of mountains and the length of the door. The second line of the input data set contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10 ^ 9, a_i ≠ a_{i + 1}) — the heights of mountains. It is guaranteed that the sum of n over all the test cases will not exceed 2 ⋅ 10^5. Output For each test case, output two integers t and l — the maximum number of parts that the door can split into, and the left border of the segment of length k that the door should be reset to. Example Input 5 8 6 1 2 4 1 2 4 1 2 5 3 3 2 3 2 1 10 4 4 3 4 3 2 3 2 1 0 1 15 7 3 7 4 8 2 3 4 5 21 2 3 4 2 1 3 7 5 1 2 3 4 5 6 1 Output 3 2 2 2 2 1 3 1 2 3 Note In the first example, you need to select a segment of mountains from 2 to 7. In this segment, the indexes 3 and 6 are peaks, so the answer is 3 (only 2 peaks, so the door will break into 3 parts). It is not difficult to notice that the mountain segments [1, 6] and [3, 8] are not suitable since they only have a 1 peak (for the first segment, the 6 index is not a peak, and for the second segment, the 3 index is not a peak). In the second example, you need to select a segment of mountains from 2 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). In the third example, you need to select a segment of mountains from 1 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). You can see that on the segments [2, 5], [4, 7] and [5, 8] the number of peaks is also 1, but these segments have a left border greater than the segment [1, 4], so they are not the correct answer.
instruction
0
90,290
8
180,580
Tags: greedy, implementation Correct Solution: ``` """ Author: Q.E.D Time: 2020-04-23 09:55:27 """ T = int(input()) for _ in range(T): n, k = list(map(int, input().split())) a = list(map(int, input().split())) peak = [] for i in range(n): if i > 0 and i < n - 1 and a[i] > a[i - 1] and a[i] > a[i + 1]: peak.append(1) else: peak.append(0) f = [0] * n for i in range(1, n): if peak[i]: f[i] = f[i - 1] + 1 else: f[i] = f[i - 1] # print(a) # print(list(map(int, peak))) # print(f) ansl = f[k - 1] ansl -= ( peak[0] + peak[k - 1]) ansi = 0 for i in range(k, n): tmp = f[i] - f[i - k] # print(i - k + 1, i, tmp) tmp -= (peak[i] + peak[i - k + 1]) if tmp > ansl: ansl = tmp ansi = i - k + 1 print(ansl + 1, ansi + 1) ```
output
1
90,290
8
180,581
Provide tags and a correct Python 3 solution for this coding contest problem. On February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length k (k ≥ 3). Nastya was very confused by this present, so she decided to break the door, throwing it on the mountains. Mountains are described by a sequence of heights a_1, a_2, ..., a_n in order from left to right (k ≤ n). It is guaranteed that neighboring heights are not equal to each other (that is, a_i ≠ a_{i+1} for all i from 1 to n-1). Peaks of mountains on the segment [l,r] (from l to r) are called indexes i such that l < i < r, a_{i - 1} < a_i and a_i > a_{i + 1}. It is worth noting that the boundary indexes l and r for the segment are not peaks. For example, if n=8 and a=[3,1,4,1,5,9,2,6], then the segment [1,8] has only two peaks (with indexes 3 and 6), and there are no peaks on the segment [3, 6]. To break the door, Nastya throws it to a segment [l,l+k-1] of consecutive mountains of length k (1 ≤ l ≤ n-k+1). When the door touches the peaks of the mountains, it breaks into two parts, after that these parts will continue to fall in different halves and also break into pieces when touching the peaks of the mountains, and so on. Formally, the number of parts that the door will break into will be equal to p+1, where p is the number of peaks on the segment [l,l+k-1]. Nastya wants to break it into as many pieces as possible. Help her choose such a segment of mountains [l, l+k-1] that the number of peaks on it is maximum. If there are several optimal segments, Nastya wants to find one for which the value l is minimal. Formally, you need to choose a segment of mountains [l, l+k-1] that has the maximum number of peaks. Among all such segments, you need to find the segment that has the minimum possible value l. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then the descriptions of the test cases follow. The first line of each test case contains two integers n and k (3 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of mountains and the length of the door. The second line of the input data set contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10 ^ 9, a_i ≠ a_{i + 1}) — the heights of mountains. It is guaranteed that the sum of n over all the test cases will not exceed 2 ⋅ 10^5. Output For each test case, output two integers t and l — the maximum number of parts that the door can split into, and the left border of the segment of length k that the door should be reset to. Example Input 5 8 6 1 2 4 1 2 4 1 2 5 3 3 2 3 2 1 10 4 4 3 4 3 2 3 2 1 0 1 15 7 3 7 4 8 2 3 4 5 21 2 3 4 2 1 3 7 5 1 2 3 4 5 6 1 Output 3 2 2 2 2 1 3 1 2 3 Note In the first example, you need to select a segment of mountains from 2 to 7. In this segment, the indexes 3 and 6 are peaks, so the answer is 3 (only 2 peaks, so the door will break into 3 parts). It is not difficult to notice that the mountain segments [1, 6] and [3, 8] are not suitable since they only have a 1 peak (for the first segment, the 6 index is not a peak, and for the second segment, the 3 index is not a peak). In the second example, you need to select a segment of mountains from 2 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). In the third example, you need to select a segment of mountains from 1 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). You can see that on the segments [2, 5], [4, 7] and [5, 8] the number of peaks is also 1, but these segments have a left border greater than the segment [1, 4], so they are not the correct answer.
instruction
0
90,291
8
180,582
Tags: greedy, implementation Correct Solution: ``` t = int(input()) for _ in range(t): n, k = [int(x) for x in input().split()] h = [int(x) for x in input().split()] peak = [0] * (n + 1) for i in range(1, n - 1): if h[i - 1] < h[i] and h[i] > h[i + 1]: peak[i + 1] = 1 # print(peak) for i in range(1, n + 1): peak[i] += peak[i - 1] # print(h) # print(peak) start = 1 cmax = 0 left = 1 while True: end = start + k - 1 if end > n: break diff = peak[end - 1] - peak[start] if cmax < diff: cmax = diff left = start # print("new max", cmax + 1, start) start += 1 print(cmax + 1, left) ```
output
1
90,291
8
180,583
Provide tags and a correct Python 3 solution for this coding contest problem. On February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length k (k ≥ 3). Nastya was very confused by this present, so she decided to break the door, throwing it on the mountains. Mountains are described by a sequence of heights a_1, a_2, ..., a_n in order from left to right (k ≤ n). It is guaranteed that neighboring heights are not equal to each other (that is, a_i ≠ a_{i+1} for all i from 1 to n-1). Peaks of mountains on the segment [l,r] (from l to r) are called indexes i such that l < i < r, a_{i - 1} < a_i and a_i > a_{i + 1}. It is worth noting that the boundary indexes l and r for the segment are not peaks. For example, if n=8 and a=[3,1,4,1,5,9,2,6], then the segment [1,8] has only two peaks (with indexes 3 and 6), and there are no peaks on the segment [3, 6]. To break the door, Nastya throws it to a segment [l,l+k-1] of consecutive mountains of length k (1 ≤ l ≤ n-k+1). When the door touches the peaks of the mountains, it breaks into two parts, after that these parts will continue to fall in different halves and also break into pieces when touching the peaks of the mountains, and so on. Formally, the number of parts that the door will break into will be equal to p+1, where p is the number of peaks on the segment [l,l+k-1]. Nastya wants to break it into as many pieces as possible. Help her choose such a segment of mountains [l, l+k-1] that the number of peaks on it is maximum. If there are several optimal segments, Nastya wants to find one for which the value l is minimal. Formally, you need to choose a segment of mountains [l, l+k-1] that has the maximum number of peaks. Among all such segments, you need to find the segment that has the minimum possible value l. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then the descriptions of the test cases follow. The first line of each test case contains two integers n and k (3 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of mountains and the length of the door. The second line of the input data set contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10 ^ 9, a_i ≠ a_{i + 1}) — the heights of mountains. It is guaranteed that the sum of n over all the test cases will not exceed 2 ⋅ 10^5. Output For each test case, output two integers t and l — the maximum number of parts that the door can split into, and the left border of the segment of length k that the door should be reset to. Example Input 5 8 6 1 2 4 1 2 4 1 2 5 3 3 2 3 2 1 10 4 4 3 4 3 2 3 2 1 0 1 15 7 3 7 4 8 2 3 4 5 21 2 3 4 2 1 3 7 5 1 2 3 4 5 6 1 Output 3 2 2 2 2 1 3 1 2 3 Note In the first example, you need to select a segment of mountains from 2 to 7. In this segment, the indexes 3 and 6 are peaks, so the answer is 3 (only 2 peaks, so the door will break into 3 parts). It is not difficult to notice that the mountain segments [1, 6] and [3, 8] are not suitable since they only have a 1 peak (for the first segment, the 6 index is not a peak, and for the second segment, the 3 index is not a peak). In the second example, you need to select a segment of mountains from 2 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). In the third example, you need to select a segment of mountains from 1 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). You can see that on the segments [2, 5], [4, 7] and [5, 8] the number of peaks is also 1, but these segments have a left border greater than the segment [1, 4], so they are not the correct answer.
instruction
0
90,292
8
180,584
Tags: greedy, implementation Correct Solution: ``` t=int(input()) for i in range(t): n,k=map(int,input().split()) a=list(map(int,input().split())) p=[0]*n for i in range(n-2): if (a[i]<a[i+1] and a[i+1]>a[i+2]): p[i+1]=1 count1=p[1:k-1].count(1) ans=count1 l=0 for i in range(n-k): if p[i+k-1]==1: count1+=1 if p[i+1]==1: count1-=1 if count1>ans: ans=count1 l=i+1 print(ans+1,l+1) ```
output
1
90,292
8
180,585
Provide tags and a correct Python 3 solution for this coding contest problem. On February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length k (k ≥ 3). Nastya was very confused by this present, so she decided to break the door, throwing it on the mountains. Mountains are described by a sequence of heights a_1, a_2, ..., a_n in order from left to right (k ≤ n). It is guaranteed that neighboring heights are not equal to each other (that is, a_i ≠ a_{i+1} for all i from 1 to n-1). Peaks of mountains on the segment [l,r] (from l to r) are called indexes i such that l < i < r, a_{i - 1} < a_i and a_i > a_{i + 1}. It is worth noting that the boundary indexes l and r for the segment are not peaks. For example, if n=8 and a=[3,1,4,1,5,9,2,6], then the segment [1,8] has only two peaks (with indexes 3 and 6), and there are no peaks on the segment [3, 6]. To break the door, Nastya throws it to a segment [l,l+k-1] of consecutive mountains of length k (1 ≤ l ≤ n-k+1). When the door touches the peaks of the mountains, it breaks into two parts, after that these parts will continue to fall in different halves and also break into pieces when touching the peaks of the mountains, and so on. Formally, the number of parts that the door will break into will be equal to p+1, where p is the number of peaks on the segment [l,l+k-1]. Nastya wants to break it into as many pieces as possible. Help her choose such a segment of mountains [l, l+k-1] that the number of peaks on it is maximum. If there are several optimal segments, Nastya wants to find one for which the value l is minimal. Formally, you need to choose a segment of mountains [l, l+k-1] that has the maximum number of peaks. Among all such segments, you need to find the segment that has the minimum possible value l. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then the descriptions of the test cases follow. The first line of each test case contains two integers n and k (3 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of mountains and the length of the door. The second line of the input data set contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10 ^ 9, a_i ≠ a_{i + 1}) — the heights of mountains. It is guaranteed that the sum of n over all the test cases will not exceed 2 ⋅ 10^5. Output For each test case, output two integers t and l — the maximum number of parts that the door can split into, and the left border of the segment of length k that the door should be reset to. Example Input 5 8 6 1 2 4 1 2 4 1 2 5 3 3 2 3 2 1 10 4 4 3 4 3 2 3 2 1 0 1 15 7 3 7 4 8 2 3 4 5 21 2 3 4 2 1 3 7 5 1 2 3 4 5 6 1 Output 3 2 2 2 2 1 3 1 2 3 Note In the first example, you need to select a segment of mountains from 2 to 7. In this segment, the indexes 3 and 6 are peaks, so the answer is 3 (only 2 peaks, so the door will break into 3 parts). It is not difficult to notice that the mountain segments [1, 6] and [3, 8] are not suitable since they only have a 1 peak (for the first segment, the 6 index is not a peak, and for the second segment, the 3 index is not a peak). In the second example, you need to select a segment of mountains from 2 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). In the third example, you need to select a segment of mountains from 1 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). You can see that on the segments [2, 5], [4, 7] and [5, 8] the number of peaks is also 1, but these segments have a left border greater than the segment [1, 4], so they are not the correct answer.
instruction
0
90,293
8
180,586
Tags: greedy, implementation Correct Solution: ``` """ NTC here """ #!/usr/bin/env python import os import sys from io import BytesIO, IOBase def iin(): return int(input()) def lin(): return list(map(int, input().split())) def main(): T = iin() for _ in range(T): n, k = lin() a = lin() a1 = [0]*n for i in range(1, n-1): if a[i+1]<a[i]>a[i-1]: a1[i] = 1 a1 = [0]+a1 for i in range(1, n+1): a1[i]+=a1[i-1] ans = [0, 1] for i in range(k, n+1): sm = a1[i-1]-a1[i-k+1] if sm+1>ans[0]: ans = [sm+1, i-k+1] print(*ans) # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion if __name__ == "__main__": main() ```
output
1
90,293
8
180,587
Provide tags and a correct Python 3 solution for this coding contest problem. On February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length k (k ≥ 3). Nastya was very confused by this present, so she decided to break the door, throwing it on the mountains. Mountains are described by a sequence of heights a_1, a_2, ..., a_n in order from left to right (k ≤ n). It is guaranteed that neighboring heights are not equal to each other (that is, a_i ≠ a_{i+1} for all i from 1 to n-1). Peaks of mountains on the segment [l,r] (from l to r) are called indexes i such that l < i < r, a_{i - 1} < a_i and a_i > a_{i + 1}. It is worth noting that the boundary indexes l and r for the segment are not peaks. For example, if n=8 and a=[3,1,4,1,5,9,2,6], then the segment [1,8] has only two peaks (with indexes 3 and 6), and there are no peaks on the segment [3, 6]. To break the door, Nastya throws it to a segment [l,l+k-1] of consecutive mountains of length k (1 ≤ l ≤ n-k+1). When the door touches the peaks of the mountains, it breaks into two parts, after that these parts will continue to fall in different halves and also break into pieces when touching the peaks of the mountains, and so on. Formally, the number of parts that the door will break into will be equal to p+1, where p is the number of peaks on the segment [l,l+k-1]. Nastya wants to break it into as many pieces as possible. Help her choose such a segment of mountains [l, l+k-1] that the number of peaks on it is maximum. If there are several optimal segments, Nastya wants to find one for which the value l is minimal. Formally, you need to choose a segment of mountains [l, l+k-1] that has the maximum number of peaks. Among all such segments, you need to find the segment that has the minimum possible value l. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then the descriptions of the test cases follow. The first line of each test case contains two integers n and k (3 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of mountains and the length of the door. The second line of the input data set contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10 ^ 9, a_i ≠ a_{i + 1}) — the heights of mountains. It is guaranteed that the sum of n over all the test cases will not exceed 2 ⋅ 10^5. Output For each test case, output two integers t and l — the maximum number of parts that the door can split into, and the left border of the segment of length k that the door should be reset to. Example Input 5 8 6 1 2 4 1 2 4 1 2 5 3 3 2 3 2 1 10 4 4 3 4 3 2 3 2 1 0 1 15 7 3 7 4 8 2 3 4 5 21 2 3 4 2 1 3 7 5 1 2 3 4 5 6 1 Output 3 2 2 2 2 1 3 1 2 3 Note In the first example, you need to select a segment of mountains from 2 to 7. In this segment, the indexes 3 and 6 are peaks, so the answer is 3 (only 2 peaks, so the door will break into 3 parts). It is not difficult to notice that the mountain segments [1, 6] and [3, 8] are not suitable since they only have a 1 peak (for the first segment, the 6 index is not a peak, and for the second segment, the 3 index is not a peak). In the second example, you need to select a segment of mountains from 2 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). In the third example, you need to select a segment of mountains from 1 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). You can see that on the segments [2, 5], [4, 7] and [5, 8] the number of peaks is also 1, but these segments have a left border greater than the segment [1, 4], so they are not the correct answer.
instruction
0
90,294
8
180,588
Tags: greedy, implementation Correct Solution: ``` from sys import stdin for i in range(int(input())): n,k=map(int,input().split()) a=list(map(int,input().split()));v=['0']*n for i in range(1,n-1): if a[i-1]<a[i]>a[i+1]:v[i]='1' v=''.join(v) ans=ans1=v[:k-1].count('1') lst=1 if ans:lst=max(0,v[:k-1].rindex('1')-k+3) for i in range(k,n): if v[i-1]=='1':ans1+=1 if v[i-k+1]=='1':ans1-=1 if ans1>ans: ans=ans1 lst=i-k+2 print(ans+1,max(1,lst)) ```
output
1
90,294
8
180,589
Provide tags and a correct Python 3 solution for this coding contest problem. On February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length k (k ≥ 3). Nastya was very confused by this present, so she decided to break the door, throwing it on the mountains. Mountains are described by a sequence of heights a_1, a_2, ..., a_n in order from left to right (k ≤ n). It is guaranteed that neighboring heights are not equal to each other (that is, a_i ≠ a_{i+1} for all i from 1 to n-1). Peaks of mountains on the segment [l,r] (from l to r) are called indexes i such that l < i < r, a_{i - 1} < a_i and a_i > a_{i + 1}. It is worth noting that the boundary indexes l and r for the segment are not peaks. For example, if n=8 and a=[3,1,4,1,5,9,2,6], then the segment [1,8] has only two peaks (with indexes 3 and 6), and there are no peaks on the segment [3, 6]. To break the door, Nastya throws it to a segment [l,l+k-1] of consecutive mountains of length k (1 ≤ l ≤ n-k+1). When the door touches the peaks of the mountains, it breaks into two parts, after that these parts will continue to fall in different halves and also break into pieces when touching the peaks of the mountains, and so on. Formally, the number of parts that the door will break into will be equal to p+1, where p is the number of peaks on the segment [l,l+k-1]. Nastya wants to break it into as many pieces as possible. Help her choose such a segment of mountains [l, l+k-1] that the number of peaks on it is maximum. If there are several optimal segments, Nastya wants to find one for which the value l is minimal. Formally, you need to choose a segment of mountains [l, l+k-1] that has the maximum number of peaks. Among all such segments, you need to find the segment that has the minimum possible value l. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then the descriptions of the test cases follow. The first line of each test case contains two integers n and k (3 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of mountains and the length of the door. The second line of the input data set contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10 ^ 9, a_i ≠ a_{i + 1}) — the heights of mountains. It is guaranteed that the sum of n over all the test cases will not exceed 2 ⋅ 10^5. Output For each test case, output two integers t and l — the maximum number of parts that the door can split into, and the left border of the segment of length k that the door should be reset to. Example Input 5 8 6 1 2 4 1 2 4 1 2 5 3 3 2 3 2 1 10 4 4 3 4 3 2 3 2 1 0 1 15 7 3 7 4 8 2 3 4 5 21 2 3 4 2 1 3 7 5 1 2 3 4 5 6 1 Output 3 2 2 2 2 1 3 1 2 3 Note In the first example, you need to select a segment of mountains from 2 to 7. In this segment, the indexes 3 and 6 are peaks, so the answer is 3 (only 2 peaks, so the door will break into 3 parts). It is not difficult to notice that the mountain segments [1, 6] and [3, 8] are not suitable since they only have a 1 peak (for the first segment, the 6 index is not a peak, and for the second segment, the 3 index is not a peak). In the second example, you need to select a segment of mountains from 2 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). In the third example, you need to select a segment of mountains from 1 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). You can see that on the segments [2, 5], [4, 7] and [5, 8] the number of peaks is also 1, but these segments have a left border greater than the segment [1, 4], so they are not the correct answer.
instruction
0
90,295
8
180,590
Tags: greedy, implementation Correct Solution: ``` # -*- coding: utf-8 -*- import sys import math import os import itertools import string import heapq import _collections from collections import Counter from collections import defaultdict from functools import lru_cache import bisect import re import queue from decimal import * class Scanner(): @staticmethod def int(): return int(sys.stdin.readline().rstrip()) @staticmethod def string(): return sys.stdin.readline().rstrip() @staticmethod def map_int(): return [int(x) for x in Scanner.string().split()] @staticmethod def string_list(n): return [Scanner.string() for i in range(n)] @staticmethod def int_list_list(n): return [Scanner.map_int() for i in range(n)] @staticmethod def int_cols_list(n): return [Scanner.int() for i in range(n)] class Math(): @staticmethod def gcd(a, b): if b == 0: return a return Math.gcd(b, a % b) @staticmethod def lcm(a, b): return (a * b) // Math.gcd(a, b) @staticmethod def divisor(n): res = [] i = 1 for i in range(1, int(n ** 0.5) + 1): if n % i == 0: res.append(i) if i != n // i: res.append(n // i) return res @staticmethod def round_up(a, b): return -(-a // b) @staticmethod def is_prime(n): if n < 2: return False if n == 2: return True if n % 2 == 0: return False d = int(n ** 0.5) + 1 for i in range(3, d + 1, 2): if n % i == 0: return False return True def pop_count(x): x = x - ((x >> 1) & 0x5555555555555555) x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f x = x + (x >> 8) x = x + (x >> 16) x = x + (x >> 32) return x & 0x0000007f MOD = int(1e09) + 7 INF = int(1e15) def solve(): N, K = Scanner.map_int() A = Scanner.map_int() cnt = 0 ans = 0 for i in range(1, K - 1): if A[i - 1] < A[i] and A[i] > A[i + 1]: cnt += 1 ans = cnt l = 0 for i in range(1, N - K + 1): if A[i - 1] < A[i] and A[i] > A[i + 1]: cnt -= 1 if A[i + K - 3] < A[i + K - 2] and A[i + K - 2] > A[i + K - 1]: cnt += 1 if ans < cnt: ans = cnt l = i print(ans + 1, l + 1, sep=' ') def main(): # sys.stdin = open("sample.txt") T = Scanner.int() for _ in range(T): solve() if __name__ == "__main__": main() ```
output
1
90,295
8
180,591
Provide tags and a correct Python 3 solution for this coding contest problem. On February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length k (k ≥ 3). Nastya was very confused by this present, so she decided to break the door, throwing it on the mountains. Mountains are described by a sequence of heights a_1, a_2, ..., a_n in order from left to right (k ≤ n). It is guaranteed that neighboring heights are not equal to each other (that is, a_i ≠ a_{i+1} for all i from 1 to n-1). Peaks of mountains on the segment [l,r] (from l to r) are called indexes i such that l < i < r, a_{i - 1} < a_i and a_i > a_{i + 1}. It is worth noting that the boundary indexes l and r for the segment are not peaks. For example, if n=8 and a=[3,1,4,1,5,9,2,6], then the segment [1,8] has only two peaks (with indexes 3 and 6), and there are no peaks on the segment [3, 6]. To break the door, Nastya throws it to a segment [l,l+k-1] of consecutive mountains of length k (1 ≤ l ≤ n-k+1). When the door touches the peaks of the mountains, it breaks into two parts, after that these parts will continue to fall in different halves and also break into pieces when touching the peaks of the mountains, and so on. Formally, the number of parts that the door will break into will be equal to p+1, where p is the number of peaks on the segment [l,l+k-1]. Nastya wants to break it into as many pieces as possible. Help her choose such a segment of mountains [l, l+k-1] that the number of peaks on it is maximum. If there are several optimal segments, Nastya wants to find one for which the value l is minimal. Formally, you need to choose a segment of mountains [l, l+k-1] that has the maximum number of peaks. Among all such segments, you need to find the segment that has the minimum possible value l. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then the descriptions of the test cases follow. The first line of each test case contains two integers n and k (3 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of mountains and the length of the door. The second line of the input data set contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10 ^ 9, a_i ≠ a_{i + 1}) — the heights of mountains. It is guaranteed that the sum of n over all the test cases will not exceed 2 ⋅ 10^5. Output For each test case, output two integers t and l — the maximum number of parts that the door can split into, and the left border of the segment of length k that the door should be reset to. Example Input 5 8 6 1 2 4 1 2 4 1 2 5 3 3 2 3 2 1 10 4 4 3 4 3 2 3 2 1 0 1 15 7 3 7 4 8 2 3 4 5 21 2 3 4 2 1 3 7 5 1 2 3 4 5 6 1 Output 3 2 2 2 2 1 3 1 2 3 Note In the first example, you need to select a segment of mountains from 2 to 7. In this segment, the indexes 3 and 6 are peaks, so the answer is 3 (only 2 peaks, so the door will break into 3 parts). It is not difficult to notice that the mountain segments [1, 6] and [3, 8] are not suitable since they only have a 1 peak (for the first segment, the 6 index is not a peak, and for the second segment, the 3 index is not a peak). In the second example, you need to select a segment of mountains from 2 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). In the third example, you need to select a segment of mountains from 1 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). You can see that on the segments [2, 5], [4, 7] and [5, 8] the number of peaks is also 1, but these segments have a left border greater than the segment [1, 4], so they are not the correct answer.
instruction
0
90,296
8
180,592
Tags: greedy, implementation Correct Solution: ``` for _ in range(int(input())): n,k = [int(s) for s in input().split()] arr = [int(s) for s in input().split()] # s = input() peak = [0]*n pref = [0]*n for i in range(1,len(arr)-1): if arr[i-1]<arr[i] and arr[i+1]<arr[i]: peak[i] = 1 pref[0] = peak[0] for i in range(1,len(peak)): pref[i] = peak[i]+pref[i-1] # print(pref) # print(peak) maxi = 0 ind = -1 for i in range(n-k+1): x = pref[i+k-1] - pref[i] - peak[i+k-1] if x > maxi: maxi = x ind = i if ind==-1: print(1,1) else: print(maxi+1,ind+1) ```
output
1
90,296
8
180,593
Provide tags and a correct Python 3 solution for this coding contest problem. On February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length k (k ≥ 3). Nastya was very confused by this present, so she decided to break the door, throwing it on the mountains. Mountains are described by a sequence of heights a_1, a_2, ..., a_n in order from left to right (k ≤ n). It is guaranteed that neighboring heights are not equal to each other (that is, a_i ≠ a_{i+1} for all i from 1 to n-1). Peaks of mountains on the segment [l,r] (from l to r) are called indexes i such that l < i < r, a_{i - 1} < a_i and a_i > a_{i + 1}. It is worth noting that the boundary indexes l and r for the segment are not peaks. For example, if n=8 and a=[3,1,4,1,5,9,2,6], then the segment [1,8] has only two peaks (with indexes 3 and 6), and there are no peaks on the segment [3, 6]. To break the door, Nastya throws it to a segment [l,l+k-1] of consecutive mountains of length k (1 ≤ l ≤ n-k+1). When the door touches the peaks of the mountains, it breaks into two parts, after that these parts will continue to fall in different halves and also break into pieces when touching the peaks of the mountains, and so on. Formally, the number of parts that the door will break into will be equal to p+1, where p is the number of peaks on the segment [l,l+k-1]. Nastya wants to break it into as many pieces as possible. Help her choose such a segment of mountains [l, l+k-1] that the number of peaks on it is maximum. If there are several optimal segments, Nastya wants to find one for which the value l is minimal. Formally, you need to choose a segment of mountains [l, l+k-1] that has the maximum number of peaks. Among all such segments, you need to find the segment that has the minimum possible value l. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then the descriptions of the test cases follow. The first line of each test case contains two integers n and k (3 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of mountains and the length of the door. The second line of the input data set contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10 ^ 9, a_i ≠ a_{i + 1}) — the heights of mountains. It is guaranteed that the sum of n over all the test cases will not exceed 2 ⋅ 10^5. Output For each test case, output two integers t and l — the maximum number of parts that the door can split into, and the left border of the segment of length k that the door should be reset to. Example Input 5 8 6 1 2 4 1 2 4 1 2 5 3 3 2 3 2 1 10 4 4 3 4 3 2 3 2 1 0 1 15 7 3 7 4 8 2 3 4 5 21 2 3 4 2 1 3 7 5 1 2 3 4 5 6 1 Output 3 2 2 2 2 1 3 1 2 3 Note In the first example, you need to select a segment of mountains from 2 to 7. In this segment, the indexes 3 and 6 are peaks, so the answer is 3 (only 2 peaks, so the door will break into 3 parts). It is not difficult to notice that the mountain segments [1, 6] and [3, 8] are not suitable since they only have a 1 peak (for the first segment, the 6 index is not a peak, and for the second segment, the 3 index is not a peak). In the second example, you need to select a segment of mountains from 2 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). In the third example, you need to select a segment of mountains from 1 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). You can see that on the segments [2, 5], [4, 7] and [5, 8] the number of peaks is also 1, but these segments have a left border greater than the segment [1, 4], so they are not the correct answer.
instruction
0
90,297
8
180,594
Tags: greedy, implementation Correct Solution: ``` for _ in range(int(input())): n,k=map(int,input().split()) a=list(map(int,input().split())) mxl=0 ans=[-1,-1] si=0 ei=0 peak=set() for i in range(1,k): if a[i]>a[i-1] and i+1<k and a[i]>a[i+1]: peak.add(i-1) ei=k ans=[si,ei-1] mxl=len(peak) while ei<len(a): if a[ei]<a[ei-1] and a[ei-1]>a[ei-2]: peak.add(ei-2) if si in peak: peak.remove(si) si+=1 if len(peak)>mxl: ans=[si,ei] mxl=len(peak) ei+=1 if mxl==0: print(1,1) continue print(mxl+1,ans[0]+1) ```
output
1
90,297
8
180,595
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length k (k ≥ 3). Nastya was very confused by this present, so she decided to break the door, throwing it on the mountains. Mountains are described by a sequence of heights a_1, a_2, ..., a_n in order from left to right (k ≤ n). It is guaranteed that neighboring heights are not equal to each other (that is, a_i ≠ a_{i+1} for all i from 1 to n-1). Peaks of mountains on the segment [l,r] (from l to r) are called indexes i such that l < i < r, a_{i - 1} < a_i and a_i > a_{i + 1}. It is worth noting that the boundary indexes l and r for the segment are not peaks. For example, if n=8 and a=[3,1,4,1,5,9,2,6], then the segment [1,8] has only two peaks (with indexes 3 and 6), and there are no peaks on the segment [3, 6]. To break the door, Nastya throws it to a segment [l,l+k-1] of consecutive mountains of length k (1 ≤ l ≤ n-k+1). When the door touches the peaks of the mountains, it breaks into two parts, after that these parts will continue to fall in different halves and also break into pieces when touching the peaks of the mountains, and so on. Formally, the number of parts that the door will break into will be equal to p+1, where p is the number of peaks on the segment [l,l+k-1]. Nastya wants to break it into as many pieces as possible. Help her choose such a segment of mountains [l, l+k-1] that the number of peaks on it is maximum. If there are several optimal segments, Nastya wants to find one for which the value l is minimal. Formally, you need to choose a segment of mountains [l, l+k-1] that has the maximum number of peaks. Among all such segments, you need to find the segment that has the minimum possible value l. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then the descriptions of the test cases follow. The first line of each test case contains two integers n and k (3 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of mountains and the length of the door. The second line of the input data set contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10 ^ 9, a_i ≠ a_{i + 1}) — the heights of mountains. It is guaranteed that the sum of n over all the test cases will not exceed 2 ⋅ 10^5. Output For each test case, output two integers t and l — the maximum number of parts that the door can split into, and the left border of the segment of length k that the door should be reset to. Example Input 5 8 6 1 2 4 1 2 4 1 2 5 3 3 2 3 2 1 10 4 4 3 4 3 2 3 2 1 0 1 15 7 3 7 4 8 2 3 4 5 21 2 3 4 2 1 3 7 5 1 2 3 4 5 6 1 Output 3 2 2 2 2 1 3 1 2 3 Note In the first example, you need to select a segment of mountains from 2 to 7. In this segment, the indexes 3 and 6 are peaks, so the answer is 3 (only 2 peaks, so the door will break into 3 parts). It is not difficult to notice that the mountain segments [1, 6] and [3, 8] are not suitable since they only have a 1 peak (for the first segment, the 6 index is not a peak, and for the second segment, the 3 index is not a peak). In the second example, you need to select a segment of mountains from 2 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). In the third example, you need to select a segment of mountains from 1 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). You can see that on the segments [2, 5], [4, 7] and [5, 8] the number of peaks is also 1, but these segments have a left border greater than the segment [1, 4], so they are not the correct answer. Submitted Solution: ``` iterations = int(input()) for i in range(iterations): n, k = list(map(int, input().split())) nums = list(map(int, input().split())) peaks = [] pieces = [] count = 1 for j in range(1,k-1): if nums[j-1]<nums[j] and nums[j+1]<nums[j]: peaks.append(j) count += 1 pieces.append(count) for j in range(0,n-k): if peaks!=[] and peaks[0]==j+1: peaks.pop(0) count -= 1 if nums[j+k-2]<nums[j+k-1] and nums[j+k]<nums[j+k-1]: peaks.append(j+k-1) count += 1 pieces.append(count) t = max(pieces) l = pieces.index(t)+1 print(t, l) ```
instruction
0
90,298
8
180,596
Yes
output
1
90,298
8
180,597
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length k (k ≥ 3). Nastya was very confused by this present, so she decided to break the door, throwing it on the mountains. Mountains are described by a sequence of heights a_1, a_2, ..., a_n in order from left to right (k ≤ n). It is guaranteed that neighboring heights are not equal to each other (that is, a_i ≠ a_{i+1} for all i from 1 to n-1). Peaks of mountains on the segment [l,r] (from l to r) are called indexes i such that l < i < r, a_{i - 1} < a_i and a_i > a_{i + 1}. It is worth noting that the boundary indexes l and r for the segment are not peaks. For example, if n=8 and a=[3,1,4,1,5,9,2,6], then the segment [1,8] has only two peaks (with indexes 3 and 6), and there are no peaks on the segment [3, 6]. To break the door, Nastya throws it to a segment [l,l+k-1] of consecutive mountains of length k (1 ≤ l ≤ n-k+1). When the door touches the peaks of the mountains, it breaks into two parts, after that these parts will continue to fall in different halves and also break into pieces when touching the peaks of the mountains, and so on. Formally, the number of parts that the door will break into will be equal to p+1, where p is the number of peaks on the segment [l,l+k-1]. Nastya wants to break it into as many pieces as possible. Help her choose such a segment of mountains [l, l+k-1] that the number of peaks on it is maximum. If there are several optimal segments, Nastya wants to find one for which the value l is minimal. Formally, you need to choose a segment of mountains [l, l+k-1] that has the maximum number of peaks. Among all such segments, you need to find the segment that has the minimum possible value l. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then the descriptions of the test cases follow. The first line of each test case contains two integers n and k (3 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of mountains and the length of the door. The second line of the input data set contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10 ^ 9, a_i ≠ a_{i + 1}) — the heights of mountains. It is guaranteed that the sum of n over all the test cases will not exceed 2 ⋅ 10^5. Output For each test case, output two integers t and l — the maximum number of parts that the door can split into, and the left border of the segment of length k that the door should be reset to. Example Input 5 8 6 1 2 4 1 2 4 1 2 5 3 3 2 3 2 1 10 4 4 3 4 3 2 3 2 1 0 1 15 7 3 7 4 8 2 3 4 5 21 2 3 4 2 1 3 7 5 1 2 3 4 5 6 1 Output 3 2 2 2 2 1 3 1 2 3 Note In the first example, you need to select a segment of mountains from 2 to 7. In this segment, the indexes 3 and 6 are peaks, so the answer is 3 (only 2 peaks, so the door will break into 3 parts). It is not difficult to notice that the mountain segments [1, 6] and [3, 8] are not suitable since they only have a 1 peak (for the first segment, the 6 index is not a peak, and for the second segment, the 3 index is not a peak). In the second example, you need to select a segment of mountains from 2 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). In the third example, you need to select a segment of mountains from 1 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). You can see that on the segments [2, 5], [4, 7] and [5, 8] the number of peaks is also 1, but these segments have a left border greater than the segment [1, 4], so they are not the correct answer. Submitted Solution: ``` R=lambda:map(int,input().split()) t,=R() for _ in[0]*t: n,k=R();a=*R(),;b=[0] for x,y,z in zip(a,a[1:],a[2:]):b+=b[-1]+(x<y>z), a=[y-x+1for x,y in zip(b,b[k-2:])];m=max(a);print(m,a.index(m)+1) ```
instruction
0
90,299
8
180,598
Yes
output
1
90,299
8
180,599
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length k (k ≥ 3). Nastya was very confused by this present, so she decided to break the door, throwing it on the mountains. Mountains are described by a sequence of heights a_1, a_2, ..., a_n in order from left to right (k ≤ n). It is guaranteed that neighboring heights are not equal to each other (that is, a_i ≠ a_{i+1} for all i from 1 to n-1). Peaks of mountains on the segment [l,r] (from l to r) are called indexes i such that l < i < r, a_{i - 1} < a_i and a_i > a_{i + 1}. It is worth noting that the boundary indexes l and r for the segment are not peaks. For example, if n=8 and a=[3,1,4,1,5,9,2,6], then the segment [1,8] has only two peaks (with indexes 3 and 6), and there are no peaks on the segment [3, 6]. To break the door, Nastya throws it to a segment [l,l+k-1] of consecutive mountains of length k (1 ≤ l ≤ n-k+1). When the door touches the peaks of the mountains, it breaks into two parts, after that these parts will continue to fall in different halves and also break into pieces when touching the peaks of the mountains, and so on. Formally, the number of parts that the door will break into will be equal to p+1, where p is the number of peaks on the segment [l,l+k-1]. Nastya wants to break it into as many pieces as possible. Help her choose such a segment of mountains [l, l+k-1] that the number of peaks on it is maximum. If there are several optimal segments, Nastya wants to find one for which the value l is minimal. Formally, you need to choose a segment of mountains [l, l+k-1] that has the maximum number of peaks. Among all such segments, you need to find the segment that has the minimum possible value l. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then the descriptions of the test cases follow. The first line of each test case contains two integers n and k (3 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of mountains and the length of the door. The second line of the input data set contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10 ^ 9, a_i ≠ a_{i + 1}) — the heights of mountains. It is guaranteed that the sum of n over all the test cases will not exceed 2 ⋅ 10^5. Output For each test case, output two integers t and l — the maximum number of parts that the door can split into, and the left border of the segment of length k that the door should be reset to. Example Input 5 8 6 1 2 4 1 2 4 1 2 5 3 3 2 3 2 1 10 4 4 3 4 3 2 3 2 1 0 1 15 7 3 7 4 8 2 3 4 5 21 2 3 4 2 1 3 7 5 1 2 3 4 5 6 1 Output 3 2 2 2 2 1 3 1 2 3 Note In the first example, you need to select a segment of mountains from 2 to 7. In this segment, the indexes 3 and 6 are peaks, so the answer is 3 (only 2 peaks, so the door will break into 3 parts). It is not difficult to notice that the mountain segments [1, 6] and [3, 8] are not suitable since they only have a 1 peak (for the first segment, the 6 index is not a peak, and for the second segment, the 3 index is not a peak). In the second example, you need to select a segment of mountains from 2 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). In the third example, you need to select a segment of mountains from 1 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). You can see that on the segments [2, 5], [4, 7] and [5, 8] the number of peaks is also 1, but these segments have a left border greater than the segment [1, 4], so they are not the correct answer. Submitted Solution: ``` from itertools import accumulate for ii in range(int(input())): n , k = map(int , input().split()) arr = list(map(int , input().split())) peaks = [0]*n p_sum = [0]*n for i in range(1 , n-1): if arr[i-1] < arr[i] > arr[i+1]: peaks[i] = 1 p_sum[i] = peaks[i] + p_sum[i-1] p_sum[n-1] = p_sum[n-2] #print(p_sum) p = p_sum[k-2] - p_sum[0] #p = 0 ind = 0 i = 1 while i + k - 1 < n : temp = p_sum[i+k-2] - p_sum[i] if temp > p: p = temp ind = i i+=1 print(p +1 , ind+1) ```
instruction
0
90,300
8
180,600
Yes
output
1
90,300
8
180,601
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length k (k ≥ 3). Nastya was very confused by this present, so she decided to break the door, throwing it on the mountains. Mountains are described by a sequence of heights a_1, a_2, ..., a_n in order from left to right (k ≤ n). It is guaranteed that neighboring heights are not equal to each other (that is, a_i ≠ a_{i+1} for all i from 1 to n-1). Peaks of mountains on the segment [l,r] (from l to r) are called indexes i such that l < i < r, a_{i - 1} < a_i and a_i > a_{i + 1}. It is worth noting that the boundary indexes l and r for the segment are not peaks. For example, if n=8 and a=[3,1,4,1,5,9,2,6], then the segment [1,8] has only two peaks (with indexes 3 and 6), and there are no peaks on the segment [3, 6]. To break the door, Nastya throws it to a segment [l,l+k-1] of consecutive mountains of length k (1 ≤ l ≤ n-k+1). When the door touches the peaks of the mountains, it breaks into two parts, after that these parts will continue to fall in different halves and also break into pieces when touching the peaks of the mountains, and so on. Formally, the number of parts that the door will break into will be equal to p+1, where p is the number of peaks on the segment [l,l+k-1]. Nastya wants to break it into as many pieces as possible. Help her choose such a segment of mountains [l, l+k-1] that the number of peaks on it is maximum. If there are several optimal segments, Nastya wants to find one for which the value l is minimal. Formally, you need to choose a segment of mountains [l, l+k-1] that has the maximum number of peaks. Among all such segments, you need to find the segment that has the minimum possible value l. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then the descriptions of the test cases follow. The first line of each test case contains two integers n and k (3 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of mountains and the length of the door. The second line of the input data set contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10 ^ 9, a_i ≠ a_{i + 1}) — the heights of mountains. It is guaranteed that the sum of n over all the test cases will not exceed 2 ⋅ 10^5. Output For each test case, output two integers t and l — the maximum number of parts that the door can split into, and the left border of the segment of length k that the door should be reset to. Example Input 5 8 6 1 2 4 1 2 4 1 2 5 3 3 2 3 2 1 10 4 4 3 4 3 2 3 2 1 0 1 15 7 3 7 4 8 2 3 4 5 21 2 3 4 2 1 3 7 5 1 2 3 4 5 6 1 Output 3 2 2 2 2 1 3 1 2 3 Note In the first example, you need to select a segment of mountains from 2 to 7. In this segment, the indexes 3 and 6 are peaks, so the answer is 3 (only 2 peaks, so the door will break into 3 parts). It is not difficult to notice that the mountain segments [1, 6] and [3, 8] are not suitable since they only have a 1 peak (for the first segment, the 6 index is not a peak, and for the second segment, the 3 index is not a peak). In the second example, you need to select a segment of mountains from 2 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). In the third example, you need to select a segment of mountains from 1 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). You can see that on the segments [2, 5], [4, 7] and [5, 8] the number of peaks is also 1, but these segments have a left border greater than the segment [1, 4], so they are not the correct answer. Submitted Solution: ``` import os import sys from io import BytesIO, IOBase def solution(arr, n, k): pre = [0] * n for i in range(1, n - 1): if arr[i - 1] < arr[i] > arr[i + 1]: pre[i] = 1 for i in range(1, n): pre[i] += pre[i - 1] start = k - 2 l, res = 0, -1 for i in range(start, n): prev = res res = max(res, pre[i] - pre[i - k + 2]) if res > prev: l = i - k + 2 write(res + 1, l + 1) def main(): for _ in range(r_int()): n, k = r_array() arr = r_array() solution(arr, n, k) # 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) def input(): return sys.stdin.readline().rstrip("\r\n") def write(*args, end='\n'): for x in args[:-1]: sys.stdout.write(str(x) + ' ') sys.stdout.write(str(args[-1])) sys.stdout.write(end) def r_array(): return [int(x) for x in input().split()] def r_int(): return int(input()) if __name__ == "__main__": main() ```
instruction
0
90,301
8
180,602
Yes
output
1
90,301
8
180,603
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length k (k ≥ 3). Nastya was very confused by this present, so she decided to break the door, throwing it on the mountains. Mountains are described by a sequence of heights a_1, a_2, ..., a_n in order from left to right (k ≤ n). It is guaranteed that neighboring heights are not equal to each other (that is, a_i ≠ a_{i+1} for all i from 1 to n-1). Peaks of mountains on the segment [l,r] (from l to r) are called indexes i such that l < i < r, a_{i - 1} < a_i and a_i > a_{i + 1}. It is worth noting that the boundary indexes l and r for the segment are not peaks. For example, if n=8 and a=[3,1,4,1,5,9,2,6], then the segment [1,8] has only two peaks (with indexes 3 and 6), and there are no peaks on the segment [3, 6]. To break the door, Nastya throws it to a segment [l,l+k-1] of consecutive mountains of length k (1 ≤ l ≤ n-k+1). When the door touches the peaks of the mountains, it breaks into two parts, after that these parts will continue to fall in different halves and also break into pieces when touching the peaks of the mountains, and so on. Formally, the number of parts that the door will break into will be equal to p+1, where p is the number of peaks on the segment [l,l+k-1]. Nastya wants to break it into as many pieces as possible. Help her choose such a segment of mountains [l, l+k-1] that the number of peaks on it is maximum. If there are several optimal segments, Nastya wants to find one for which the value l is minimal. Formally, you need to choose a segment of mountains [l, l+k-1] that has the maximum number of peaks. Among all such segments, you need to find the segment that has the minimum possible value l. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then the descriptions of the test cases follow. The first line of each test case contains two integers n and k (3 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of mountains and the length of the door. The second line of the input data set contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10 ^ 9, a_i ≠ a_{i + 1}) — the heights of mountains. It is guaranteed that the sum of n over all the test cases will not exceed 2 ⋅ 10^5. Output For each test case, output two integers t and l — the maximum number of parts that the door can split into, and the left border of the segment of length k that the door should be reset to. Example Input 5 8 6 1 2 4 1 2 4 1 2 5 3 3 2 3 2 1 10 4 4 3 4 3 2 3 2 1 0 1 15 7 3 7 4 8 2 3 4 5 21 2 3 4 2 1 3 7 5 1 2 3 4 5 6 1 Output 3 2 2 2 2 1 3 1 2 3 Note In the first example, you need to select a segment of mountains from 2 to 7. In this segment, the indexes 3 and 6 are peaks, so the answer is 3 (only 2 peaks, so the door will break into 3 parts). It is not difficult to notice that the mountain segments [1, 6] and [3, 8] are not suitable since they only have a 1 peak (for the first segment, the 6 index is not a peak, and for the second segment, the 3 index is not a peak). In the second example, you need to select a segment of mountains from 2 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). In the third example, you need to select a segment of mountains from 1 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). You can see that on the segments [2, 5], [4, 7] and [5, 8] the number of peaks is also 1, but these segments have a left border greater than the segment [1, 4], so they are not the correct answer. Submitted Solution: ``` for _ in range(int(input())): n,k=map(int,input().split()) l=list(map(int,input().split())) x=[] p=0 for i in range(1,k-1): if l[i]>l[i-1] and l[i]>l[i+1]: x.append(i) p+=1 m=0 y=0 b=p for i in range(1,n-k+1): if i in x: p=p-1 if l[i+k-2]>l[i+k-3] and l[i+k-2]>l[i+k-1]: p+=1 if p==b: m=min(i,m) if p>b: b=p m=i print(b+1,m+1) ```
instruction
0
90,302
8
180,604
No
output
1
90,302
8
180,605
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length k (k ≥ 3). Nastya was very confused by this present, so she decided to break the door, throwing it on the mountains. Mountains are described by a sequence of heights a_1, a_2, ..., a_n in order from left to right (k ≤ n). It is guaranteed that neighboring heights are not equal to each other (that is, a_i ≠ a_{i+1} for all i from 1 to n-1). Peaks of mountains on the segment [l,r] (from l to r) are called indexes i such that l < i < r, a_{i - 1} < a_i and a_i > a_{i + 1}. It is worth noting that the boundary indexes l and r for the segment are not peaks. For example, if n=8 and a=[3,1,4,1,5,9,2,6], then the segment [1,8] has only two peaks (with indexes 3 and 6), and there are no peaks on the segment [3, 6]. To break the door, Nastya throws it to a segment [l,l+k-1] of consecutive mountains of length k (1 ≤ l ≤ n-k+1). When the door touches the peaks of the mountains, it breaks into two parts, after that these parts will continue to fall in different halves and also break into pieces when touching the peaks of the mountains, and so on. Formally, the number of parts that the door will break into will be equal to p+1, where p is the number of peaks on the segment [l,l+k-1]. Nastya wants to break it into as many pieces as possible. Help her choose such a segment of mountains [l, l+k-1] that the number of peaks on it is maximum. If there are several optimal segments, Nastya wants to find one for which the value l is minimal. Formally, you need to choose a segment of mountains [l, l+k-1] that has the maximum number of peaks. Among all such segments, you need to find the segment that has the minimum possible value l. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then the descriptions of the test cases follow. The first line of each test case contains two integers n and k (3 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of mountains and the length of the door. The second line of the input data set contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10 ^ 9, a_i ≠ a_{i + 1}) — the heights of mountains. It is guaranteed that the sum of n over all the test cases will not exceed 2 ⋅ 10^5. Output For each test case, output two integers t and l — the maximum number of parts that the door can split into, and the left border of the segment of length k that the door should be reset to. Example Input 5 8 6 1 2 4 1 2 4 1 2 5 3 3 2 3 2 1 10 4 4 3 4 3 2 3 2 1 0 1 15 7 3 7 4 8 2 3 4 5 21 2 3 4 2 1 3 7 5 1 2 3 4 5 6 1 Output 3 2 2 2 2 1 3 1 2 3 Note In the first example, you need to select a segment of mountains from 2 to 7. In this segment, the indexes 3 and 6 are peaks, so the answer is 3 (only 2 peaks, so the door will break into 3 parts). It is not difficult to notice that the mountain segments [1, 6] and [3, 8] are not suitable since they only have a 1 peak (for the first segment, the 6 index is not a peak, and for the second segment, the 3 index is not a peak). In the second example, you need to select a segment of mountains from 2 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). In the third example, you need to select a segment of mountains from 1 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). You can see that on the segments [2, 5], [4, 7] and [5, 8] the number of peaks is also 1, but these segments have a left border greater than the segment [1, 4], so they are not the correct answer. Submitted Solution: ``` for _ in range((int)(input())): a=list(map(int,input().split())) k=a[1] l=list(map(int,input().split())) i,t,f=1,[],0 t.append(0) while i<len(l): if l[i]>l[i-1]: if i-2>=0: if l[i-2]<l[i-1]: t[i-1]=0 t.append(1) else: t.append(0) i+=1 summ=[0]*len(t) t[-1]=0 i=1 summ[0]=t[0] while i<len(t): summ[i]=summ[i-1]+t[i] i+=1 i=k-1 maxi,index=0,0 while i<len(summ): if summ[i]==summ[i-1]+1: if summ[i-1]-summ[i-k]>maxi: maxi=summ[i-1]-summ[i-k+1] index=i-k+1 elif summ[i]-summ[i-k+1]>maxi: index=i-k+1 # print(i) maxi=summ[i]-summ[i-k+1] i+=1 print(maxi+1,index+1) ```
instruction
0
90,303
8
180,606
No
output
1
90,303
8
180,607
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length k (k ≥ 3). Nastya was very confused by this present, so she decided to break the door, throwing it on the mountains. Mountains are described by a sequence of heights a_1, a_2, ..., a_n in order from left to right (k ≤ n). It is guaranteed that neighboring heights are not equal to each other (that is, a_i ≠ a_{i+1} for all i from 1 to n-1). Peaks of mountains on the segment [l,r] (from l to r) are called indexes i such that l < i < r, a_{i - 1} < a_i and a_i > a_{i + 1}. It is worth noting that the boundary indexes l and r for the segment are not peaks. For example, if n=8 and a=[3,1,4,1,5,9,2,6], then the segment [1,8] has only two peaks (with indexes 3 and 6), and there are no peaks on the segment [3, 6]. To break the door, Nastya throws it to a segment [l,l+k-1] of consecutive mountains of length k (1 ≤ l ≤ n-k+1). When the door touches the peaks of the mountains, it breaks into two parts, after that these parts will continue to fall in different halves and also break into pieces when touching the peaks of the mountains, and so on. Formally, the number of parts that the door will break into will be equal to p+1, where p is the number of peaks on the segment [l,l+k-1]. Nastya wants to break it into as many pieces as possible. Help her choose such a segment of mountains [l, l+k-1] that the number of peaks on it is maximum. If there are several optimal segments, Nastya wants to find one for which the value l is minimal. Formally, you need to choose a segment of mountains [l, l+k-1] that has the maximum number of peaks. Among all such segments, you need to find the segment that has the minimum possible value l. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then the descriptions of the test cases follow. The first line of each test case contains two integers n and k (3 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of mountains and the length of the door. The second line of the input data set contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10 ^ 9, a_i ≠ a_{i + 1}) — the heights of mountains. It is guaranteed that the sum of n over all the test cases will not exceed 2 ⋅ 10^5. Output For each test case, output two integers t and l — the maximum number of parts that the door can split into, and the left border of the segment of length k that the door should be reset to. Example Input 5 8 6 1 2 4 1 2 4 1 2 5 3 3 2 3 2 1 10 4 4 3 4 3 2 3 2 1 0 1 15 7 3 7 4 8 2 3 4 5 21 2 3 4 2 1 3 7 5 1 2 3 4 5 6 1 Output 3 2 2 2 2 1 3 1 2 3 Note In the first example, you need to select a segment of mountains from 2 to 7. In this segment, the indexes 3 and 6 are peaks, so the answer is 3 (only 2 peaks, so the door will break into 3 parts). It is not difficult to notice that the mountain segments [1, 6] and [3, 8] are not suitable since they only have a 1 peak (for the first segment, the 6 index is not a peak, and for the second segment, the 3 index is not a peak). In the second example, you need to select a segment of mountains from 2 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). In the third example, you need to select a segment of mountains from 1 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). You can see that on the segments [2, 5], [4, 7] and [5, 8] the number of peaks is also 1, but these segments have a left border greater than the segment [1, 4], so they are not the correct answer. Submitted Solution: ``` t = int(input()) for u in range(t): n,k = list(map(int,input().split())) a = list(map(int,input().split())) picks = [0]*n count = [0]*(n-k+1) tmp = 0 tmpact = [0,0] for i in range(1,n-1): if a[i] > a[i-1] and a[i] > a[i+1]: picks[i] = 1 for i in range(k-2): if picks[i] == 1: tmp += 1 count[0] = tmp for i in range(k-1,n): if picks[i-k+1] == 1: tmp -= 1 if picks[i-1] == 1: tmp += 1 count[i-k+1] = tmp for i in range(n-k+1): if count[i] > tmpact[0]: tmpact[1] = i+1 tmpact[0] = count[i] print(tmpact[0]+1,tmpact[1]) ```
instruction
0
90,304
8
180,608
No
output
1
90,304
8
180,609
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length k (k ≥ 3). Nastya was very confused by this present, so she decided to break the door, throwing it on the mountains. Mountains are described by a sequence of heights a_1, a_2, ..., a_n in order from left to right (k ≤ n). It is guaranteed that neighboring heights are not equal to each other (that is, a_i ≠ a_{i+1} for all i from 1 to n-1). Peaks of mountains on the segment [l,r] (from l to r) are called indexes i such that l < i < r, a_{i - 1} < a_i and a_i > a_{i + 1}. It is worth noting that the boundary indexes l and r for the segment are not peaks. For example, if n=8 and a=[3,1,4,1,5,9,2,6], then the segment [1,8] has only two peaks (with indexes 3 and 6), and there are no peaks on the segment [3, 6]. To break the door, Nastya throws it to a segment [l,l+k-1] of consecutive mountains of length k (1 ≤ l ≤ n-k+1). When the door touches the peaks of the mountains, it breaks into two parts, after that these parts will continue to fall in different halves and also break into pieces when touching the peaks of the mountains, and so on. Formally, the number of parts that the door will break into will be equal to p+1, where p is the number of peaks on the segment [l,l+k-1]. Nastya wants to break it into as many pieces as possible. Help her choose such a segment of mountains [l, l+k-1] that the number of peaks on it is maximum. If there are several optimal segments, Nastya wants to find one for which the value l is minimal. Formally, you need to choose a segment of mountains [l, l+k-1] that has the maximum number of peaks. Among all such segments, you need to find the segment that has the minimum possible value l. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then the descriptions of the test cases follow. The first line of each test case contains two integers n and k (3 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of mountains and the length of the door. The second line of the input data set contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10 ^ 9, a_i ≠ a_{i + 1}) — the heights of mountains. It is guaranteed that the sum of n over all the test cases will not exceed 2 ⋅ 10^5. Output For each test case, output two integers t and l — the maximum number of parts that the door can split into, and the left border of the segment of length k that the door should be reset to. Example Input 5 8 6 1 2 4 1 2 4 1 2 5 3 3 2 3 2 1 10 4 4 3 4 3 2 3 2 1 0 1 15 7 3 7 4 8 2 3 4 5 21 2 3 4 2 1 3 7 5 1 2 3 4 5 6 1 Output 3 2 2 2 2 1 3 1 2 3 Note In the first example, you need to select a segment of mountains from 2 to 7. In this segment, the indexes 3 and 6 are peaks, so the answer is 3 (only 2 peaks, so the door will break into 3 parts). It is not difficult to notice that the mountain segments [1, 6] and [3, 8] are not suitable since they only have a 1 peak (for the first segment, the 6 index is not a peak, and for the second segment, the 3 index is not a peak). In the second example, you need to select a segment of mountains from 2 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). In the third example, you need to select a segment of mountains from 1 to 4. In this segment, the index 3 is a peak, so the answer is 2 (only 1 peak, so the door will break into 2 parts). You can see that on the segments [2, 5], [4, 7] and [5, 8] the number of peaks is also 1, but these segments have a left border greater than the segment [1, 4], so they are not the correct answer. Submitted Solution: ``` from itertools import accumulate for _ in range(int(input())): n,k = map(int,input().split()) a = list(map(int,input().split())) p = [0]*n q = [0]*n for i in range(1,n-1): if a[i-1]<a[i] and a[i]>a[i+1]: p[i]=1 q[i+1]=1 p = list(accumulate(p)) q = list(accumulate(q)) maxi = 0 #print(p) #print(q) for i in range(n-k+1): if q[i+k-1]-p[i]>maxi: maxi=q[i+k-1]-p[i] idx = i+1 count = q[i+k-1]-p[i] try: print(count+1,idx) except: print(1,1) ```
instruction
0
90,305
8
180,610
No
output
1
90,305
8
180,611
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya goes to visit his classmate Petya. Vasya knows that Petya's apartment number is n. There is only one entrance in Petya's house and the distribution of apartments is the following: the first floor contains 2 apartments, every other floor contains x apartments each. Apartments are numbered starting from one, from the first floor. I.e. apartments on the first floor have numbers 1 and 2, apartments on the second floor have numbers from 3 to (x + 2), apartments on the third floor have numbers from (x + 3) to (2 ⋅ x + 2), and so on. Your task is to find the number of floor on which Petya lives. Assume that the house is always high enough to fit at least n apartments. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 1000) — the number of test cases. Then t test cases follow. The only line of the test case contains two integers n and x (1 ≤ n, x ≤ 1000) — the number of Petya's apartment and the number of apartments on each floor of the house except the first one (there are two apartments on the first floor). Output For each test case, print the answer: the number of floor on which Petya lives. Example Input 4 7 3 1 5 22 5 987 13 Output 3 1 5 77 Note Consider the first test case of the example: the first floor contains apartments with numbers 1 and 2, the second one contains apartments with numbers 3, 4 and 5, the third one contains apartments with numbers 6, 7 and 8. Therefore, Petya lives on the third floor. In the second test case of the example, Petya lives in the apartment 1 which is on the first floor.
instruction
0
90,332
8
180,664
Tags: implementation, math Correct Solution: ``` t = int(input()) for i in range(t): n, x = [int(i) for i in input().split()] a = 0 if n <= 2: print(1) else: n -= 2 while n > 0: n -= x a += 1 a += 1 print(a) ```
output
1
90,332
8
180,665