message
stringlengths
2
45.8k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
254
108k
cluster
float64
3
3
__index_level_0__
int64
508
217k
Provide tags and a correct Python 3 solution for this coding contest problem. BigData Inc. is a corporation that has n data centers indexed from 1 to n that are located all over the world. These data centers provide storage for client data (you can figure out that client data is really big!). Main feature of services offered by BigData Inc. is the access availability guarantee even under the circumstances of any data center having an outage. Such a guarantee is ensured by using the two-way replication. Two-way replication is such an approach for data storage that any piece of data is represented by two identical copies that are stored in two different data centers. For each of m company clients, let us denote indices of two different data centers storing this client data as ci, 1 and ci, 2. In order to keep data centers operational and safe, the software running on data center computers is being updated regularly. Release cycle of BigData Inc. is one day meaning that the new version of software is being deployed to the data center computers each day. Data center software update is a non-trivial long process, that is why there is a special hour-long time frame that is dedicated for data center maintenance. During the maintenance period, data center computers are installing software updates, and thus they may be unavailable. Consider the day to be exactly h hours long. For each data center there is an integer uj (0 ≀ uj ≀ h - 1) defining the index of an hour of day, such that during this hour data center j is unavailable due to maintenance. Summing up everything above, the condition uci, 1 β‰  uci, 2 should hold for each client, or otherwise his data may be unaccessible while data centers that store it are under maintenance. Due to occasional timezone change in different cities all over the world, the maintenance time in some of the data centers may change by one hour sometimes. Company should be prepared for such situation, that is why they decided to conduct an experiment, choosing some non-empty subset of data centers, and shifting the maintenance time for them by an hour later (i.e. if uj = h - 1, then the new maintenance hour would become 0, otherwise it would become uj + 1). Nonetheless, such an experiment should not break the accessibility guarantees, meaning that data of any client should be still available during any hour of a day after the data center maintenance times are changed. Such an experiment would provide useful insights, but changing update time is quite an expensive procedure, that is why the company asked you to find out the minimum number of data centers that have to be included in an experiment in order to keep the data accessibility guarantees. Input The first line of input contains three integers n, m and h (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 100 000, 2 ≀ h ≀ 100 000), the number of company data centers, number of clients and the day length of day measured in hours. The second line of input contains n integers u1, u2, ..., un (0 ≀ uj < h), j-th of these numbers is an index of a maintenance hour for data center j. Each of the next m lines contains two integers ci, 1 and ci, 2 (1 ≀ ci, 1, ci, 2 ≀ n, ci, 1 β‰  ci, 2), defining the data center indices containing the data of client i. It is guaranteed that the given maintenance schedule allows each client to access at least one copy of his data at any moment of day. Output In the first line print the minimum possible number of data centers k (1 ≀ k ≀ n) that have to be included in an experiment in order to keep the data available for any client. In the second line print k distinct integers x1, x2, ..., xk (1 ≀ xi ≀ n), the indices of data centers whose maintenance time will be shifted by one hour later. Data center indices may be printed in any order. If there are several possible answers, it is allowed to print any of them. It is guaranteed that at there is at least one valid choice of data centers. Examples Input 3 3 5 4 4 0 1 3 3 2 3 1 Output 1 3 Input 4 5 4 2 1 0 3 4 3 3 2 1 2 1 4 1 3 Output 4 1 2 3 4 Note Consider the first sample test. The given answer is the only way to conduct an experiment involving the only data center. In such a scenario the third data center has a maintenance during the hour 1, and no two data centers storing the information of the same client have maintenance at the same hour. On the other hand, for example, if we shift the maintenance time on hour later for the first data center, then the data of clients 1 and 3 will be unavailable during the hour 0.
instruction
0
57,742
3
115,484
Tags: dfs and similar, graphs Correct Solution: ``` from collections import deque import sys input = sys.stdin.readline n, m, MOD = map(int, input().split()) u = list(map(int, input().split())) info = [list(map(int, input().split())) for i in range(m)] graph = [[] for i in range(n)] rev_graph = [[] for i in range(n)] set_ = set() INF = 10 ** 9 for a, b in info: a -= 1 b -= 1 if (u[a] + 1) % MOD == u[b]: if a * INF + b not in set_: graph[a].append(b) rev_graph[b].append(a) set_.add(a * INF + b) if (u[b] + 1) % MOD == u[a]: if b * INF + a not in set_: graph[b].append(a) rev_graph[a].append(b) set_.add(b * INF + a) def scc(N, G, RG): order = [] used = [0]*N group = [None]*N def dfs(s): used[s] = 1 q = deque([s]) tmp = deque([s]) while q: s = q.pop() for t in G[s]: if not used[t]: used[t] = 1 q.append(t) tmp.append(t) while tmp: order.append(tmp.pop()) def rdfs(s, col): group[s] = col used[s] = 1 q = deque([s]) while q: s = q.pop() for t in RG[s]: if not used[t]: q.append(t) used[t] = 1 group[t] = col for i in range(N): if not used[i]: dfs(i) used = [0]*N label = 0 for s in reversed(order): if not used[s]: rdfs(s, label) label += 1 return label, group def construct(N, G, label, group): G0 = [set() for i in range(label)] GP = [[] for i in range(label)] for v in range(N): lbs = group[v] for w in G[v]: lbt = group[w] if lbs == lbt: continue G0[lbs].add(lbt) GP[lbs].append(v + 1) return G0, GP min_ans = 10 ** 9 ind_ans = -1 label, group = scc(n, graph, rev_graph) new_graph, element = construct(n, graph, label, group) for i in range(len(new_graph)): if len(new_graph[i]) == 0 and min_ans > len(element[i]): min_ans = len(element[i]) ind_ans = i print(min_ans) print(*element[ind_ans]) ```
output
1
57,742
3
115,485
Provide tags and a correct Python 3 solution for this coding contest problem. BigData Inc. is a corporation that has n data centers indexed from 1 to n that are located all over the world. These data centers provide storage for client data (you can figure out that client data is really big!). Main feature of services offered by BigData Inc. is the access availability guarantee even under the circumstances of any data center having an outage. Such a guarantee is ensured by using the two-way replication. Two-way replication is such an approach for data storage that any piece of data is represented by two identical copies that are stored in two different data centers. For each of m company clients, let us denote indices of two different data centers storing this client data as ci, 1 and ci, 2. In order to keep data centers operational and safe, the software running on data center computers is being updated regularly. Release cycle of BigData Inc. is one day meaning that the new version of software is being deployed to the data center computers each day. Data center software update is a non-trivial long process, that is why there is a special hour-long time frame that is dedicated for data center maintenance. During the maintenance period, data center computers are installing software updates, and thus they may be unavailable. Consider the day to be exactly h hours long. For each data center there is an integer uj (0 ≀ uj ≀ h - 1) defining the index of an hour of day, such that during this hour data center j is unavailable due to maintenance. Summing up everything above, the condition uci, 1 β‰  uci, 2 should hold for each client, or otherwise his data may be unaccessible while data centers that store it are under maintenance. Due to occasional timezone change in different cities all over the world, the maintenance time in some of the data centers may change by one hour sometimes. Company should be prepared for such situation, that is why they decided to conduct an experiment, choosing some non-empty subset of data centers, and shifting the maintenance time for them by an hour later (i.e. if uj = h - 1, then the new maintenance hour would become 0, otherwise it would become uj + 1). Nonetheless, such an experiment should not break the accessibility guarantees, meaning that data of any client should be still available during any hour of a day after the data center maintenance times are changed. Such an experiment would provide useful insights, but changing update time is quite an expensive procedure, that is why the company asked you to find out the minimum number of data centers that have to be included in an experiment in order to keep the data accessibility guarantees. Input The first line of input contains three integers n, m and h (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 100 000, 2 ≀ h ≀ 100 000), the number of company data centers, number of clients and the day length of day measured in hours. The second line of input contains n integers u1, u2, ..., un (0 ≀ uj < h), j-th of these numbers is an index of a maintenance hour for data center j. Each of the next m lines contains two integers ci, 1 and ci, 2 (1 ≀ ci, 1, ci, 2 ≀ n, ci, 1 β‰  ci, 2), defining the data center indices containing the data of client i. It is guaranteed that the given maintenance schedule allows each client to access at least one copy of his data at any moment of day. Output In the first line print the minimum possible number of data centers k (1 ≀ k ≀ n) that have to be included in an experiment in order to keep the data available for any client. In the second line print k distinct integers x1, x2, ..., xk (1 ≀ xi ≀ n), the indices of data centers whose maintenance time will be shifted by one hour later. Data center indices may be printed in any order. If there are several possible answers, it is allowed to print any of them. It is guaranteed that at there is at least one valid choice of data centers. Examples Input 3 3 5 4 4 0 1 3 3 2 3 1 Output 1 3 Input 4 5 4 2 1 0 3 4 3 3 2 1 2 1 4 1 3 Output 4 1 2 3 4 Note Consider the first sample test. The given answer is the only way to conduct an experiment involving the only data center. In such a scenario the third data center has a maintenance during the hour 1, and no two data centers storing the information of the same client have maintenance at the same hour. On the other hand, for example, if we shift the maintenance time on hour later for the first data center, then the data of clients 1 and 3 will be unavailable during the hour 0.
instruction
0
57,743
3
115,486
Tags: dfs and similar, graphs Correct Solution: ``` import sys # sys.stind.readline lee datos el doble de # rΓ‘pido que la funcion por defecto input input = sys.stdin.readline def get_input(): n, m, h = [int(x) for x in input().split(' ')] digraph = [[] for _ in range(n + 1)] transpose = [[] for _ in range(n + 1)] mantainence = [0] + [int(x) for x in input().split(' ')] for _ in range(m): c1, c2 = [int(x) for x in input().split(' ')] if (mantainence[c1] + 1) % h == mantainence[c2]: digraph[c1].append(c2) transpose[c2].append(c1) if (mantainence[c2] + 1) % h == mantainence[c1]: digraph[c2].append(c1) transpose[c1].append(c2) return digraph, transpose def dfs_cc_1_visit(graph, node, color, finalization_stack): stack = [node] while stack: current_node = stack[-1] if color[current_node] != 'white': stack.pop() if color[current_node] == 'grey': finalization_stack.append(current_node) color[current_node] = 'black' continue color[current_node] = 'grey' for adj in graph[current_node]: if color[adj] == 'white': stack.append(adj) def dfs_cc_1(graph): n = len(graph) finalization_stack = [] color = ['white'] * n for i in range(1, n): if color[i] == 'white': dfs_cc_1_visit(graph, i, color, finalization_stack) return finalization_stack def dfs_cc_2_visit(graph, node, color, scc, component): stack = [node] while stack: current_node = stack[-1] if color[current_node] != 'white': stack.pop() color[current_node] = 'black' scc[current_node] = component continue color[current_node] = 'grey' for adj in graph[current_node]: if color[adj] == 'white': stack.append(adj) def dfs_cc_2(graph, stack_time): n = len(graph) color = ['white'] * n scc = [0] * n component = 0 while stack_time: current_node = stack_time.pop() if color[current_node] == 'white': dfs_cc_2_visit(graph, current_node, color, scc, component) component += 1 return scc, component def strongly_connected_components(digraph, transpose): stack_time = dfs_cc_1(digraph) scc, max_component = dfs_cc_2(transpose, stack_time) # create the components out_deg = [0] * max_component scc_nodes = [[] for _ in range(max_component)] for node in range(1, len(digraph)): scc_nodes[scc[node]].append(node) for adj in digraph[node]: if scc[node] != scc[adj]: out_deg[scc[node]] += 1 # searching minimum strongly connectected component with out degree 0 minimum_component = None for i, value in enumerate(out_deg): if value == 0 and (minimum_component is None or len(scc_nodes[i]) < len(scc_nodes[minimum_component])): minimum_component = i # return the size of the component and the nodes return len(scc_nodes[minimum_component]), scc_nodes[minimum_component] if __name__ == "__main__": digraph, transpose = get_input() count, nodes = strongly_connected_components(digraph, transpose) print(count) print(' '.join([str(x) for x in nodes])) ```
output
1
57,743
3
115,487
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. BigData Inc. is a corporation that has n data centers indexed from 1 to n that are located all over the world. These data centers provide storage for client data (you can figure out that client data is really big!). Main feature of services offered by BigData Inc. is the access availability guarantee even under the circumstances of any data center having an outage. Such a guarantee is ensured by using the two-way replication. Two-way replication is such an approach for data storage that any piece of data is represented by two identical copies that are stored in two different data centers. For each of m company clients, let us denote indices of two different data centers storing this client data as ci, 1 and ci, 2. In order to keep data centers operational and safe, the software running on data center computers is being updated regularly. Release cycle of BigData Inc. is one day meaning that the new version of software is being deployed to the data center computers each day. Data center software update is a non-trivial long process, that is why there is a special hour-long time frame that is dedicated for data center maintenance. During the maintenance period, data center computers are installing software updates, and thus they may be unavailable. Consider the day to be exactly h hours long. For each data center there is an integer uj (0 ≀ uj ≀ h - 1) defining the index of an hour of day, such that during this hour data center j is unavailable due to maintenance. Summing up everything above, the condition uci, 1 β‰  uci, 2 should hold for each client, or otherwise his data may be unaccessible while data centers that store it are under maintenance. Due to occasional timezone change in different cities all over the world, the maintenance time in some of the data centers may change by one hour sometimes. Company should be prepared for such situation, that is why they decided to conduct an experiment, choosing some non-empty subset of data centers, and shifting the maintenance time for them by an hour later (i.e. if uj = h - 1, then the new maintenance hour would become 0, otherwise it would become uj + 1). Nonetheless, such an experiment should not break the accessibility guarantees, meaning that data of any client should be still available during any hour of a day after the data center maintenance times are changed. Such an experiment would provide useful insights, but changing update time is quite an expensive procedure, that is why the company asked you to find out the minimum number of data centers that have to be included in an experiment in order to keep the data accessibility guarantees. Input The first line of input contains three integers n, m and h (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 100 000, 2 ≀ h ≀ 100 000), the number of company data centers, number of clients and the day length of day measured in hours. The second line of input contains n integers u1, u2, ..., un (0 ≀ uj < h), j-th of these numbers is an index of a maintenance hour for data center j. Each of the next m lines contains two integers ci, 1 and ci, 2 (1 ≀ ci, 1, ci, 2 ≀ n, ci, 1 β‰  ci, 2), defining the data center indices containing the data of client i. It is guaranteed that the given maintenance schedule allows each client to access at least one copy of his data at any moment of day. Output In the first line print the minimum possible number of data centers k (1 ≀ k ≀ n) that have to be included in an experiment in order to keep the data available for any client. In the second line print k distinct integers x1, x2, ..., xk (1 ≀ xi ≀ n), the indices of data centers whose maintenance time will be shifted by one hour later. Data center indices may be printed in any order. If there are several possible answers, it is allowed to print any of them. It is guaranteed that at there is at least one valid choice of data centers. Examples Input 3 3 5 4 4 0 1 3 3 2 3 1 Output 1 3 Input 4 5 4 2 1 0 3 4 3 3 2 1 2 1 4 1 3 Output 4 1 2 3 4 Note Consider the first sample test. The given answer is the only way to conduct an experiment involving the only data center. In such a scenario the third data center has a maintenance during the hour 1, and no two data centers storing the information of the same client have maintenance at the same hour. On the other hand, for example, if we shift the maintenance time on hour later for the first data center, then the data of clients 1 and 3 will be unavailable during the hour 0. Submitted Solution: ``` n, m, h = map(int , input().split()) arr = list(map(int, input().split())) edge = [list(map(lambda x: int(x)-1, input().split())) for _ in range(m)] g = {} def push(g, u, v): if u not in g: g[u]=[] g[u].append(v) for u, v in edge: if arr[u] == (arr[v] + 1) % h: push(g, v, u) if arr[v] == (arr[u] + 1) % h: push(g, u, v) def bfs(cur, used): S=[cur] used[cur]=1 i=0 while i<len(S): u=S[i] if u in g: for v in g[u]: if used[v]==0: used[v]=1 S.append(v) i+=1 return len(S), S min_ = float("inf") used = [0] * n ans = None for u in range(n): if u not in g: ans = [u] min_= 1 break for cur in range(n): if arr[cur] == 0 and used[cur] == False: num, S = bfs(u, used ) if num < min_: min_= num ans = S print(min_) print(" ".join([str(x) for x in ans])) ```
instruction
0
57,744
3
115,488
No
output
1
57,744
3
115,489
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. BigData Inc. is a corporation that has n data centers indexed from 1 to n that are located all over the world. These data centers provide storage for client data (you can figure out that client data is really big!). Main feature of services offered by BigData Inc. is the access availability guarantee even under the circumstances of any data center having an outage. Such a guarantee is ensured by using the two-way replication. Two-way replication is such an approach for data storage that any piece of data is represented by two identical copies that are stored in two different data centers. For each of m company clients, let us denote indices of two different data centers storing this client data as ci, 1 and ci, 2. In order to keep data centers operational and safe, the software running on data center computers is being updated regularly. Release cycle of BigData Inc. is one day meaning that the new version of software is being deployed to the data center computers each day. Data center software update is a non-trivial long process, that is why there is a special hour-long time frame that is dedicated for data center maintenance. During the maintenance period, data center computers are installing software updates, and thus they may be unavailable. Consider the day to be exactly h hours long. For each data center there is an integer uj (0 ≀ uj ≀ h - 1) defining the index of an hour of day, such that during this hour data center j is unavailable due to maintenance. Summing up everything above, the condition uci, 1 β‰  uci, 2 should hold for each client, or otherwise his data may be unaccessible while data centers that store it are under maintenance. Due to occasional timezone change in different cities all over the world, the maintenance time in some of the data centers may change by one hour sometimes. Company should be prepared for such situation, that is why they decided to conduct an experiment, choosing some non-empty subset of data centers, and shifting the maintenance time for them by an hour later (i.e. if uj = h - 1, then the new maintenance hour would become 0, otherwise it would become uj + 1). Nonetheless, such an experiment should not break the accessibility guarantees, meaning that data of any client should be still available during any hour of a day after the data center maintenance times are changed. Such an experiment would provide useful insights, but changing update time is quite an expensive procedure, that is why the company asked you to find out the minimum number of data centers that have to be included in an experiment in order to keep the data accessibility guarantees. Input The first line of input contains three integers n, m and h (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 100 000, 2 ≀ h ≀ 100 000), the number of company data centers, number of clients and the day length of day measured in hours. The second line of input contains n integers u1, u2, ..., un (0 ≀ uj < h), j-th of these numbers is an index of a maintenance hour for data center j. Each of the next m lines contains two integers ci, 1 and ci, 2 (1 ≀ ci, 1, ci, 2 ≀ n, ci, 1 β‰  ci, 2), defining the data center indices containing the data of client i. It is guaranteed that the given maintenance schedule allows each client to access at least one copy of his data at any moment of day. Output In the first line print the minimum possible number of data centers k (1 ≀ k ≀ n) that have to be included in an experiment in order to keep the data available for any client. In the second line print k distinct integers x1, x2, ..., xk (1 ≀ xi ≀ n), the indices of data centers whose maintenance time will be shifted by one hour later. Data center indices may be printed in any order. If there are several possible answers, it is allowed to print any of them. It is guaranteed that at there is at least one valid choice of data centers. Examples Input 3 3 5 4 4 0 1 3 3 2 3 1 Output 1 3 Input 4 5 4 2 1 0 3 4 3 3 2 1 2 1 4 1 3 Output 4 1 2 3 4 Note Consider the first sample test. The given answer is the only way to conduct an experiment involving the only data center. In such a scenario the third data center has a maintenance during the hour 1, and no two data centers storing the information of the same client have maintenance at the same hour. On the other hand, for example, if we shift the maintenance time on hour later for the first data center, then the data of clients 1 and 3 will be unavailable during the hour 0. Submitted Solution: ``` x = [int(_) for _ in input().strip().split(' ')] N, M, H = x[0], x[1], x[2] mtime = [int(_) for _ in input().strip().split(' ')] edge = [[] for i in range(N)] def isnext(x1, x2): return (x1 == x2 + 1) or (x1 == 0 and x2 == H-1) for i in range(M): x = [int(_) for _ in input().strip().split(' ')] x[0], x[1] = x[0]-1, x[1] - 1 if isnext(mtime[x[0]], mtime[x[1]]): edge[x[1]].append(x[0]) if isnext(mtime[x[1]], mtime[x[0]]): edge[x[0]].append(x[1]) ans = [] for i in range(N): if not edge[i]: ans = [i+1] break if not ans: color = [-1] * N def coloring(p, c): color[p] = c for x in edge[p]: if color[x] == -1: coloring(x, c) nc = 0 for i in range(N): if color[i] == -1: coloring(i, nc) nc += 1 cnt = [0] * nc for x in color: cnt[x] += 1 minn = min(zip(cnt, list(range(nc)))) ans = [i+1 for i, x in enumerate(color) if x == minn[1]] print(len(ans)) print(' '.join([str(x) for x in ans])) ```
instruction
0
57,745
3
115,490
No
output
1
57,745
3
115,491
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. BigData Inc. is a corporation that has n data centers indexed from 1 to n that are located all over the world. These data centers provide storage for client data (you can figure out that client data is really big!). Main feature of services offered by BigData Inc. is the access availability guarantee even under the circumstances of any data center having an outage. Such a guarantee is ensured by using the two-way replication. Two-way replication is such an approach for data storage that any piece of data is represented by two identical copies that are stored in two different data centers. For each of m company clients, let us denote indices of two different data centers storing this client data as ci, 1 and ci, 2. In order to keep data centers operational and safe, the software running on data center computers is being updated regularly. Release cycle of BigData Inc. is one day meaning that the new version of software is being deployed to the data center computers each day. Data center software update is a non-trivial long process, that is why there is a special hour-long time frame that is dedicated for data center maintenance. During the maintenance period, data center computers are installing software updates, and thus they may be unavailable. Consider the day to be exactly h hours long. For each data center there is an integer uj (0 ≀ uj ≀ h - 1) defining the index of an hour of day, such that during this hour data center j is unavailable due to maintenance. Summing up everything above, the condition uci, 1 β‰  uci, 2 should hold for each client, or otherwise his data may be unaccessible while data centers that store it are under maintenance. Due to occasional timezone change in different cities all over the world, the maintenance time in some of the data centers may change by one hour sometimes. Company should be prepared for such situation, that is why they decided to conduct an experiment, choosing some non-empty subset of data centers, and shifting the maintenance time for them by an hour later (i.e. if uj = h - 1, then the new maintenance hour would become 0, otherwise it would become uj + 1). Nonetheless, such an experiment should not break the accessibility guarantees, meaning that data of any client should be still available during any hour of a day after the data center maintenance times are changed. Such an experiment would provide useful insights, but changing update time is quite an expensive procedure, that is why the company asked you to find out the minimum number of data centers that have to be included in an experiment in order to keep the data accessibility guarantees. Input The first line of input contains three integers n, m and h (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 100 000, 2 ≀ h ≀ 100 000), the number of company data centers, number of clients and the day length of day measured in hours. The second line of input contains n integers u1, u2, ..., un (0 ≀ uj < h), j-th of these numbers is an index of a maintenance hour for data center j. Each of the next m lines contains two integers ci, 1 and ci, 2 (1 ≀ ci, 1, ci, 2 ≀ n, ci, 1 β‰  ci, 2), defining the data center indices containing the data of client i. It is guaranteed that the given maintenance schedule allows each client to access at least one copy of his data at any moment of day. Output In the first line print the minimum possible number of data centers k (1 ≀ k ≀ n) that have to be included in an experiment in order to keep the data available for any client. In the second line print k distinct integers x1, x2, ..., xk (1 ≀ xi ≀ n), the indices of data centers whose maintenance time will be shifted by one hour later. Data center indices may be printed in any order. If there are several possible answers, it is allowed to print any of them. It is guaranteed that at there is at least one valid choice of data centers. Examples Input 3 3 5 4 4 0 1 3 3 2 3 1 Output 1 3 Input 4 5 4 2 1 0 3 4 3 3 2 1 2 1 4 1 3 Output 4 1 2 3 4 Note Consider the first sample test. The given answer is the only way to conduct an experiment involving the only data center. In such a scenario the third data center has a maintenance during the hour 1, and no two data centers storing the information of the same client have maintenance at the same hour. On the other hand, for example, if we shift the maintenance time on hour later for the first data center, then the data of clients 1 and 3 will be unavailable during the hour 0. Submitted Solution: ``` n, m, h = map(int , input().split()) arr = list(map(int, input().split())) edge = [list(map(lambda x: int(x)-1, input().split())) for _ in range(m)] g = {} def push(g, u, v): if u not in g: g[u]=[] g[u].append(v) for u, v in edge: if arr[u] == (arr[v] + 1) % h: push(g, v, u) if arr[v] == (arr[u] + 1) % h: push(g, u, v) def bfs(cur, used): S=[cur] used[cur]=1 i=0 while i<len(S): u=S[i] if u in g: for v in g[u]: if used[v]==0: used[v]=1 S.append(v) i+=1 return len(S), S min_ = float("inf") used = [0] * n ans = None for u in range(n): if u not in g: ans = [u] min_= 1 break for cur in range(n): if arr[cur] == 0 and used[cur] == False: num, S = bfs(u, used ) if num < min_: min_= num ans = S print(min_) print(" ".join([str(x+1) for x in ans])) ```
instruction
0
57,746
3
115,492
No
output
1
57,746
3
115,493
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. BigData Inc. is a corporation that has n data centers indexed from 1 to n that are located all over the world. These data centers provide storage for client data (you can figure out that client data is really big!). Main feature of services offered by BigData Inc. is the access availability guarantee even under the circumstances of any data center having an outage. Such a guarantee is ensured by using the two-way replication. Two-way replication is such an approach for data storage that any piece of data is represented by two identical copies that are stored in two different data centers. For each of m company clients, let us denote indices of two different data centers storing this client data as ci, 1 and ci, 2. In order to keep data centers operational and safe, the software running on data center computers is being updated regularly. Release cycle of BigData Inc. is one day meaning that the new version of software is being deployed to the data center computers each day. Data center software update is a non-trivial long process, that is why there is a special hour-long time frame that is dedicated for data center maintenance. During the maintenance period, data center computers are installing software updates, and thus they may be unavailable. Consider the day to be exactly h hours long. For each data center there is an integer uj (0 ≀ uj ≀ h - 1) defining the index of an hour of day, such that during this hour data center j is unavailable due to maintenance. Summing up everything above, the condition uci, 1 β‰  uci, 2 should hold for each client, or otherwise his data may be unaccessible while data centers that store it are under maintenance. Due to occasional timezone change in different cities all over the world, the maintenance time in some of the data centers may change by one hour sometimes. Company should be prepared for such situation, that is why they decided to conduct an experiment, choosing some non-empty subset of data centers, and shifting the maintenance time for them by an hour later (i.e. if uj = h - 1, then the new maintenance hour would become 0, otherwise it would become uj + 1). Nonetheless, such an experiment should not break the accessibility guarantees, meaning that data of any client should be still available during any hour of a day after the data center maintenance times are changed. Such an experiment would provide useful insights, but changing update time is quite an expensive procedure, that is why the company asked you to find out the minimum number of data centers that have to be included in an experiment in order to keep the data accessibility guarantees. Input The first line of input contains three integers n, m and h (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 100 000, 2 ≀ h ≀ 100 000), the number of company data centers, number of clients and the day length of day measured in hours. The second line of input contains n integers u1, u2, ..., un (0 ≀ uj < h), j-th of these numbers is an index of a maintenance hour for data center j. Each of the next m lines contains two integers ci, 1 and ci, 2 (1 ≀ ci, 1, ci, 2 ≀ n, ci, 1 β‰  ci, 2), defining the data center indices containing the data of client i. It is guaranteed that the given maintenance schedule allows each client to access at least one copy of his data at any moment of day. Output In the first line print the minimum possible number of data centers k (1 ≀ k ≀ n) that have to be included in an experiment in order to keep the data available for any client. In the second line print k distinct integers x1, x2, ..., xk (1 ≀ xi ≀ n), the indices of data centers whose maintenance time will be shifted by one hour later. Data center indices may be printed in any order. If there are several possible answers, it is allowed to print any of them. It is guaranteed that at there is at least one valid choice of data centers. Examples Input 3 3 5 4 4 0 1 3 3 2 3 1 Output 1 3 Input 4 5 4 2 1 0 3 4 3 3 2 1 2 1 4 1 3 Output 4 1 2 3 4 Note Consider the first sample test. The given answer is the only way to conduct an experiment involving the only data center. In such a scenario the third data center has a maintenance during the hour 1, and no two data centers storing the information of the same client have maintenance at the same hour. On the other hand, for example, if we shift the maintenance time on hour later for the first data center, then the data of clients 1 and 3 will be unavailable during the hour 0. Submitted Solution: ``` import sys from collections import defaultdict def servershift(u, h): if u == h-1: return 0 return u + 1 def serverreverse(u, h): if u == 0: return h-1 return u - 1 def find_deps(ind, array, pairs, current_mx, h): res = [] indval = array[ind] for i in pairs[ind]: if array[i] == indval: res.append(i) #print(res) return res, False def count_lgth(ind, array, pairs, current_mx, h): to_shift = [ind, ] shifted = set() fnt = array[ind] loop = [] while len(to_shift): tm = to_shift.pop() if tm in shifted: return shifted, True, loop ntime = servershift(array[tm], h) if ntime == fnt: loop = list(shifted) array[tm] = ntime shifted.add(tm) dps, sc = find_deps(tm, array, pairs, current_mx, h) #print(array) if sc: return shifted, True, loop if len(dps): to_shift += dps if len(shifted) + len(dps) >= current_mx: return shifted, True, loop return shifted, False, loop #sys.stdin = open('1test', 'r') n, m, h = map(int, sys.stdin.readline().split()) #print(n, m, h) times = list(map(int, sys.stdin.readline().split())) times.insert(0,0) #print(times) clients = [] for i in sys.stdin.readlines(): c1, c2 = map(int, i.split()) clients.append((c1, c2)) #print(clients) current_mx = n+1 rsp = [] rspcpy = [] pairs2 = defaultdict(set) for i in clients: pairs2[i[0]].add(i[1]) pairs2[i[1]].add(i[0]) vss = set(range(2, n+1)) i = 1 while len(vss): shft, flag, lps = count_lgth(i,times,pairs2,current_mx,h) #print('before ', times) #print('shift', shft) for i in lps: if i in vss: vss.remove(i) for i in shft: times[i] = serverreverse(times[i], h) #print(times) if not flag: rsp = shft rspcpy = list(rsp) current_mx = len(rsp) if len(shft) == 1: break while 1: if len(rspcpy): i = rspcpy.pop() if i in vss: vss.remove(i) break else: if len(vss): i = vss.pop() break sys.stdout.write(str(current_mx)+'\n') sys.stdout.write(' '.join(map(str, rsp))+'\n') ```
instruction
0
57,747
3
115,494
No
output
1
57,747
3
115,495
Provide a correct Python 3 solution for this coding contest problem. A new type of mobile robot has been developed for environmental earth observation. It moves around on the ground, acquiring and recording various sorts of observational data using high precision sensors. Robots of this type have short range wireless communication devices and can exchange observational data with ones nearby. They also have large capacity memory units, on which they record data observed by themselves and those received from others. Figure 1 illustrates the current positions of three robots A, B, and C and the geographic coverage of their wireless devices. Each circle represents the wireless coverage of a robot, with its center representing the position of the robot. In this figure, two robots A and B are in the positions where A can transmit data to B, and vice versa. In contrast, C cannot communicate with A or B, since it is too remote from them. Still, however, once B moves towards C as in Figure 2, B and C can start communicating with each other. In this manner, B can relay observational data from A to C. Figure 3 shows another example, in which data propagate among several robots instantaneously. <image> --- Figure 1: The initial configuration of three robots <image> --- Figure 2: Mobile relaying <image> --- Figure 3: Instantaneous relaying among multiple robots As you may notice from these examples, if a team of robots move properly, observational data quickly spread over a large number of them. Your mission is to write a program that simulates how information spreads among robots. Suppose that, regardless of data size, the time necessary for communication is negligible. Input The input consists of multiple datasets, each in the following format. > N T R > nickname and travel route of the first robot > nickname and travel route of the second robot > ... > nickname and travel route of the N-th robot > The first line contains three integers N, T, and R that are the number of robots, the length of the simulation period, and the maximum distance wireless signals can reach, respectively, and satisfy that 1 <=N <= 100, 1 <= T <= 1000, and 1 <= R <= 10. The nickname and travel route of each robot are given in the following format. > nickname > t0 x0 y0 > t1 vx1 vy1 > t2 vx2 vy2 > ... > tk vxk vyk > Nickname is a character string of length between one and eight that only contains lowercase letters. No two robots in a dataset may have the same nickname. Each of the lines following nickname contains three integers, satisfying the following conditions. > 0 = t0 < t1 < ... < tk = T > -10 <= vx1, vy1, ..., vxk, vyk<= 10 > A robot moves around on a two dimensional plane. (x0, y0) is the location of the robot at time 0. From time ti-1 to ti (0 < i <= k), the velocities in the x and y directions are vxi and vyi, respectively. Therefore, the travel route of a robot is piecewise linear. Note that it may self-overlap or self-intersect. You may assume that each dataset satisfies the following conditions. * The distance between any two robots at time 0 is not exactly R. * The x- and y-coordinates of each robot are always between -500 and 500, inclusive. * Once any robot approaches within R + 10-6 of any other, the distance between them will become smaller than R - 10-6 while maintaining the velocities. * Once any robot moves away up to R - 10-6 of any other, the distance between them will become larger than R + 10-6 while maintaining the velocities. * If any pair of robots mutually enter the wireless area of the opposite ones at time t and any pair, which may share one or two members with the aforementioned pair, mutually leave the wireless area of the opposite ones at time t', the difference between t and t' is no smaller than 10-6 time unit, that is, |t - t' | >= 10-6. A dataset may include two or more robots that share the same location at the same time. However, you should still consider that they can move with the designated velocities. The end of the input is indicated by a line containing three zeros. Output For each dataset in the input, your program should print the nickname of each robot that have got until time T the observational data originally acquired by the first robot at time 0. Each nickname should be written in a separate line in dictionary order without any superfluous characters such as leading or trailing spaces. Example Input 3 5 10 red 0 0 0 5 0 0 green 0 5 5 5 6 1 blue 0 40 5 5 0 0 3 10 5 atom 0 47 32 5 -10 -7 10 1 0 pluto 0 0 0 7 0 0 10 3 3 gesicht 0 25 7 5 -7 -2 10 -1 10 4 100 7 impulse 0 -500 0 100 10 1 freedom 0 -491 0 100 9 2 destiny 0 -472 0 100 7 4 strike 0 -482 0 100 8 3 0 0 0 Output blue green red atom gesicht pluto freedom impulse strike
instruction
0
57,934
3
115,868
"Correct Solution: ``` from heapq import heappush, heappop import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N, T, R = map(int, readline().split()) if N == T == R == 0: return False S = [None]*N TS = [None]*N for i in range(N): s = readline().strip() S[i] = s prv, x0, y0 = map(int, readline().split()) r = [] while prv != T: t, vx, vy = map(int, readline().split()) r.append((prv, t, x0, y0, vx, vy)) x0 += vx*(t - prv); y0 += vy*(t - prv) prv = t TS[i] = r INF = 10**18 que = [(0, 0)] dist = [INF]*N dist[0] = 0 while que: cost, v = heappop(que) if cost - dist[v] > 1e-6: continue k0 = 0 T1 = TS[v] while 1: t0, t1, x0, y0, vx, vy = T1[k0] if t0 <= cost <= t1: break k0 += 1 for w in range(N): if v == w or dist[w] < cost: continue k1 = k0 k2 = 0 T2 = TS[w] while 1: t0, t1, x0, y0, vx, vy = T2[k2] if t0 <= cost <= t1: break k2 += 1 while 1: p0, p1, x0, y0, vx0, vy0 = T1[k1] q0, q1, x1, y1, vx1, vy1 = T2[k2] t0 = max(p0, q0, cost); t1 = min(p1, q1) if dist[w] <= t0: break a0 = (vx0 - vx1) a1 = (x0 - p0*vx0) - (x1 - q0*vx1) b0 = (vy0 - vy1) b1 = (y0 - p0*vy0) - (y1 - q0*vy1) A = a0**2 + b0**2 B = 2*(a0*a1 + b0*b1) C = a1**2 + b1**2 - R**2 if A == 0: assert B == 0 if C <= 0: e = t0 if e < dist[w]: dist[w] = e heappush(que, (e, w)) break else: D = B**2 - 4*A*C if D >= 0: s0 = (-B - D**.5) / (2*A) s1 = (-B + D**.5) / (2*A) if t0 <= s1 and s0 <= t1: e = max(t0, s0) if e < dist[w]: dist[w] = e heappush(que, (e, w)) break if p1 < q1: k1 += 1 elif p1 > q1: k2 += 1 elif p1 == T: break else: k1 += 1; k2 += 1 ans = [] for i in range(N): if dist[i] < INF: ans.append(S[i]) ans.sort() for e in ans: write("%s\n" % e) return True while solve(): ... ```
output
1
57,934
3
115,869
Provide tags and a correct Python 3 solution for this coding contest problem. Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of 360 degrees and a pointer which initially points at zero: <image> Petr called his car dealer, who instructed him to rotate the lock's wheel exactly n times. The i-th rotation should be a_i degrees, either clockwise or counterclockwise, and after all n rotations the pointer should again point at zero. This confused Petr a little bit as he isn't sure which rotations should be done clockwise and which should be done counterclockwise. As there are many possible ways of rotating the lock, help him and find out whether there exists at least one, such that after all n rotations the pointer will point at zero again. Input The first line contains one integer n (1 ≀ n ≀ 15) β€” the number of rotations. Each of the following n lines contains one integer a_i (1 ≀ a_i ≀ 180) β€” the angle of the i-th rotation in degrees. Output If it is possible to do all the rotations so that the pointer will point at zero after all of them are performed, print a single word "YES". Otherwise, print "NO". Petr will probably buy a new car in this case. You can print each letter in any case (upper or lower). Examples Input 3 10 20 30 Output YES Input 3 10 10 10 Output NO Input 3 120 120 120 Output YES Note In the first example, we can achieve our goal by applying the first and the second rotation clockwise, and performing the third rotation counterclockwise. In the second example, it's impossible to perform the rotations in order to make the pointer point at zero in the end. In the third example, Petr can do all three rotations clockwise. In this case, the whole wheel will be rotated by 360 degrees clockwise and the pointer will point at zero again.
instruction
0
58,040
3
116,080
Tags: bitmasks, brute force, dp Correct Solution: ``` import itertools n = int(input()) turns = [] for i in range(n): turns.append(int(input())) ans = "NO" for config in itertools.product([-1, 1], repeat=n): sum_ = 0 for i in range(n): sum_ += config[i] * turns[i] if sum_ % 360 == 0: ans = 'YES' print(ans) ```
output
1
58,040
3
116,081
Provide tags and a correct Python 3 solution for this coding contest problem. Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of 360 degrees and a pointer which initially points at zero: <image> Petr called his car dealer, who instructed him to rotate the lock's wheel exactly n times. The i-th rotation should be a_i degrees, either clockwise or counterclockwise, and after all n rotations the pointer should again point at zero. This confused Petr a little bit as he isn't sure which rotations should be done clockwise and which should be done counterclockwise. As there are many possible ways of rotating the lock, help him and find out whether there exists at least one, such that after all n rotations the pointer will point at zero again. Input The first line contains one integer n (1 ≀ n ≀ 15) β€” the number of rotations. Each of the following n lines contains one integer a_i (1 ≀ a_i ≀ 180) β€” the angle of the i-th rotation in degrees. Output If it is possible to do all the rotations so that the pointer will point at zero after all of them are performed, print a single word "YES". Otherwise, print "NO". Petr will probably buy a new car in this case. You can print each letter in any case (upper or lower). Examples Input 3 10 20 30 Output YES Input 3 10 10 10 Output NO Input 3 120 120 120 Output YES Note In the first example, we can achieve our goal by applying the first and the second rotation clockwise, and performing the third rotation counterclockwise. In the second example, it's impossible to perform the rotations in order to make the pointer point at zero in the end. In the third example, Petr can do all three rotations clockwise. In this case, the whole wheel will be rotated by 360 degrees clockwise and the pointer will point at zero again.
instruction
0
58,041
3
116,082
Tags: bitmasks, brute force, dp Correct Solution: ``` def ans(i,a,n,ca): if ca>=360: ca-=360 if ca<=-360: ca+=360 if i==n: if ca==0: return True else: return False else: return ans(i+1,a,n,ca+a[i]) | ans(i+1,a,n,ca-a[i]) n = int(input()) a = [] for i in range(n): a.append(int(input())) if ans(0,a,n,0): print("YES") else: print("NO") ```
output
1
58,041
3
116,083
Provide tags and a correct Python 3 solution for this coding contest problem. Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of 360 degrees and a pointer which initially points at zero: <image> Petr called his car dealer, who instructed him to rotate the lock's wheel exactly n times. The i-th rotation should be a_i degrees, either clockwise or counterclockwise, and after all n rotations the pointer should again point at zero. This confused Petr a little bit as he isn't sure which rotations should be done clockwise and which should be done counterclockwise. As there are many possible ways of rotating the lock, help him and find out whether there exists at least one, such that after all n rotations the pointer will point at zero again. Input The first line contains one integer n (1 ≀ n ≀ 15) β€” the number of rotations. Each of the following n lines contains one integer a_i (1 ≀ a_i ≀ 180) β€” the angle of the i-th rotation in degrees. Output If it is possible to do all the rotations so that the pointer will point at zero after all of them are performed, print a single word "YES". Otherwise, print "NO". Petr will probably buy a new car in this case. You can print each letter in any case (upper or lower). Examples Input 3 10 20 30 Output YES Input 3 10 10 10 Output NO Input 3 120 120 120 Output YES Note In the first example, we can achieve our goal by applying the first and the second rotation clockwise, and performing the third rotation counterclockwise. In the second example, it's impossible to perform the rotations in order to make the pointer point at zero in the end. In the third example, Petr can do all three rotations clockwise. In this case, the whole wheel will be rotated by 360 degrees clockwise and the pointer will point at zero again.
instruction
0
58,042
3
116,084
Tags: bitmasks, brute force, dp Correct Solution: ``` n=int(input()) A=[int(input()) for i in range(n)] N=[0] for a in A: l=[] for n in N: l.append((n+a)%360) l.append((n-a)%360) N=list(set(l)) if 0 in N: print("YES") else: print("NO") ```
output
1
58,042
3
116,085
Provide tags and a correct Python 3 solution for this coding contest problem. Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of 360 degrees and a pointer which initially points at zero: <image> Petr called his car dealer, who instructed him to rotate the lock's wheel exactly n times. The i-th rotation should be a_i degrees, either clockwise or counterclockwise, and after all n rotations the pointer should again point at zero. This confused Petr a little bit as he isn't sure which rotations should be done clockwise and which should be done counterclockwise. As there are many possible ways of rotating the lock, help him and find out whether there exists at least one, such that after all n rotations the pointer will point at zero again. Input The first line contains one integer n (1 ≀ n ≀ 15) β€” the number of rotations. Each of the following n lines contains one integer a_i (1 ≀ a_i ≀ 180) β€” the angle of the i-th rotation in degrees. Output If it is possible to do all the rotations so that the pointer will point at zero after all of them are performed, print a single word "YES". Otherwise, print "NO". Petr will probably buy a new car in this case. You can print each letter in any case (upper or lower). Examples Input 3 10 20 30 Output YES Input 3 10 10 10 Output NO Input 3 120 120 120 Output YES Note In the first example, we can achieve our goal by applying the first and the second rotation clockwise, and performing the third rotation counterclockwise. In the second example, it's impossible to perform the rotations in order to make the pointer point at zero in the end. In the third example, Petr can do all three rotations clockwise. In this case, the whole wheel will be rotated by 360 degrees clockwise and the pointer will point at zero again.
instruction
0
58,043
3
116,086
Tags: bitmasks, brute force, dp Correct Solution: ``` n = int(input()) a, b = [0], [] for i in range(n): z = int(input()) b = [] for k in a: b.append((k + z)%360) b.append((k - z)%360) a = b[:] ##print(a) if 0 in a: print("YES") else: print("NO") ```
output
1
58,043
3
116,087
Provide tags and a correct Python 3 solution for this coding contest problem. Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of 360 degrees and a pointer which initially points at zero: <image> Petr called his car dealer, who instructed him to rotate the lock's wheel exactly n times. The i-th rotation should be a_i degrees, either clockwise or counterclockwise, and after all n rotations the pointer should again point at zero. This confused Petr a little bit as he isn't sure which rotations should be done clockwise and which should be done counterclockwise. As there are many possible ways of rotating the lock, help him and find out whether there exists at least one, such that after all n rotations the pointer will point at zero again. Input The first line contains one integer n (1 ≀ n ≀ 15) β€” the number of rotations. Each of the following n lines contains one integer a_i (1 ≀ a_i ≀ 180) β€” the angle of the i-th rotation in degrees. Output If it is possible to do all the rotations so that the pointer will point at zero after all of them are performed, print a single word "YES". Otherwise, print "NO". Petr will probably buy a new car in this case. You can print each letter in any case (upper or lower). Examples Input 3 10 20 30 Output YES Input 3 10 10 10 Output NO Input 3 120 120 120 Output YES Note In the first example, we can achieve our goal by applying the first and the second rotation clockwise, and performing the third rotation counterclockwise. In the second example, it's impossible to perform the rotations in order to make the pointer point at zero in the end. In the third example, Petr can do all three rotations clockwise. In this case, the whole wheel will be rotated by 360 degrees clockwise and the pointer will point at zero again.
instruction
0
58,044
3
116,088
Tags: bitmasks, brute force, dp Correct Solution: ``` def rec(ost, s=0): if not ost: if s % 360 == 0: return True return False if rec(ost[1:], s=s + ost[0]): return True return rec(ost[1:], s=s - ost[0]) amount = int(input()) spis = [int(input()) for i in range(amount)] if rec(spis): print("Yes") else: print("No") ```
output
1
58,044
3
116,089
Provide tags and a correct Python 3 solution for this coding contest problem. Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of 360 degrees and a pointer which initially points at zero: <image> Petr called his car dealer, who instructed him to rotate the lock's wheel exactly n times. The i-th rotation should be a_i degrees, either clockwise or counterclockwise, and after all n rotations the pointer should again point at zero. This confused Petr a little bit as he isn't sure which rotations should be done clockwise and which should be done counterclockwise. As there are many possible ways of rotating the lock, help him and find out whether there exists at least one, such that after all n rotations the pointer will point at zero again. Input The first line contains one integer n (1 ≀ n ≀ 15) β€” the number of rotations. Each of the following n lines contains one integer a_i (1 ≀ a_i ≀ 180) β€” the angle of the i-th rotation in degrees. Output If it is possible to do all the rotations so that the pointer will point at zero after all of them are performed, print a single word "YES". Otherwise, print "NO". Petr will probably buy a new car in this case. You can print each letter in any case (upper or lower). Examples Input 3 10 20 30 Output YES Input 3 10 10 10 Output NO Input 3 120 120 120 Output YES Note In the first example, we can achieve our goal by applying the first and the second rotation clockwise, and performing the third rotation counterclockwise. In the second example, it's impossible to perform the rotations in order to make the pointer point at zero in the end. In the third example, Petr can do all three rotations clockwise. In this case, the whole wheel will be rotated by 360 degrees clockwise and the pointer will point at zero again.
instruction
0
58,045
3
116,090
Tags: bitmasks, brute force, dp Correct Solution: ``` n = int(input()) a = [] for i in range(n): a.append(int(input())) # def check_sum(i, sum): # if i > n-1: # return sum # l = check_sum(i+1, sum-a[i]) # r = check_sum(i+1, sum+a[i]) # if l%360 == 0 or r%360 == 0: # return 0 # else: # return 1 # if check_sum(0, 0) == 0: # print("YES") # else: # print("NO") found = False for i in range(1, 2**n+1): sum = 0 for j in range(n): if i & (1 << j): sum += a[j] else: sum -= a[j] if sum%360 == 0: found = True break if found: print("YES") else: print("NO") ```
output
1
58,045
3
116,091
Provide tags and a correct Python 3 solution for this coding contest problem. Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of 360 degrees and a pointer which initially points at zero: <image> Petr called his car dealer, who instructed him to rotate the lock's wheel exactly n times. The i-th rotation should be a_i degrees, either clockwise or counterclockwise, and after all n rotations the pointer should again point at zero. This confused Petr a little bit as he isn't sure which rotations should be done clockwise and which should be done counterclockwise. As there are many possible ways of rotating the lock, help him and find out whether there exists at least one, such that after all n rotations the pointer will point at zero again. Input The first line contains one integer n (1 ≀ n ≀ 15) β€” the number of rotations. Each of the following n lines contains one integer a_i (1 ≀ a_i ≀ 180) β€” the angle of the i-th rotation in degrees. Output If it is possible to do all the rotations so that the pointer will point at zero after all of them are performed, print a single word "YES". Otherwise, print "NO". Petr will probably buy a new car in this case. You can print each letter in any case (upper or lower). Examples Input 3 10 20 30 Output YES Input 3 10 10 10 Output NO Input 3 120 120 120 Output YES Note In the first example, we can achieve our goal by applying the first and the second rotation clockwise, and performing the third rotation counterclockwise. In the second example, it's impossible to perform the rotations in order to make the pointer point at zero in the end. In the third example, Petr can do all three rotations clockwise. In this case, the whole wheel will be rotated by 360 degrees clockwise and the pointer will point at zero again.
instruction
0
58,046
3
116,092
Tags: bitmasks, brute force, dp Correct Solution: ``` Values = [] answer = False FutureValues = [] Values.append(0) Angles = [] n = int(input()) for i in range(n): Angles.append(int(input())) for i in range(n): for j in range(len(Values)): a = Values[j] + Angles[i] b = Values[j] - Angles[i] if a < 0: a = 360 + a elif a >= 360: a -= 360 if b < 0: b = 360 + b elif b >= 360: b -= 360 if a == 0 or b == 0: if i == n - 1: answer = True print('YES') break if a not in FutureValues: FutureValues.append(a) if b not in FutureValues: FutureValues.append(b) Values = FutureValues FutureValues = [] if answer: break if answer is False: print('NO') ```
output
1
58,046
3
116,093
Provide tags and a correct Python 3 solution for this coding contest problem. Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of 360 degrees and a pointer which initially points at zero: <image> Petr called his car dealer, who instructed him to rotate the lock's wheel exactly n times. The i-th rotation should be a_i degrees, either clockwise or counterclockwise, and after all n rotations the pointer should again point at zero. This confused Petr a little bit as he isn't sure which rotations should be done clockwise and which should be done counterclockwise. As there are many possible ways of rotating the lock, help him and find out whether there exists at least one, such that after all n rotations the pointer will point at zero again. Input The first line contains one integer n (1 ≀ n ≀ 15) β€” the number of rotations. Each of the following n lines contains one integer a_i (1 ≀ a_i ≀ 180) β€” the angle of the i-th rotation in degrees. Output If it is possible to do all the rotations so that the pointer will point at zero after all of them are performed, print a single word "YES". Otherwise, print "NO". Petr will probably buy a new car in this case. You can print each letter in any case (upper or lower). Examples Input 3 10 20 30 Output YES Input 3 10 10 10 Output NO Input 3 120 120 120 Output YES Note In the first example, we can achieve our goal by applying the first and the second rotation clockwise, and performing the third rotation counterclockwise. In the second example, it's impossible to perform the rotations in order to make the pointer point at zero in the end. In the third example, Petr can do all three rotations clockwise. In this case, the whole wheel will be rotated by 360 degrees clockwise and the pointer will point at zero again.
instruction
0
58,047
3
116,094
Tags: bitmasks, brute force, dp Correct Solution: ``` import sys def getlarge(n): largest = '' for i in range(n): largest = largest+'1' return int(largest, 2) def f(ang): largest = getlarge(len(ang)) total=[] for index in range(largest+1): binary = bin(index)[2:] if len(binary)<len(ang): new = len(ang)-len(binary) for k in range(new): binary = '0'+binary total.append(0) #print(total) #print(binary) for i, char in enumerate(binary): if char=='0': total[index] += ang[i] else: total[index] -= ang[i] #print(total[index]) return [el%360 for el in total] n = int(input()) ang =[] for i in range(n): ang.append(int(input())) total = f(ang) if 0 in total: print('YES') else: print('NO') ```
output
1
58,047
3
116,095
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of 360 degrees and a pointer which initially points at zero: <image> Petr called his car dealer, who instructed him to rotate the lock's wheel exactly n times. The i-th rotation should be a_i degrees, either clockwise or counterclockwise, and after all n rotations the pointer should again point at zero. This confused Petr a little bit as he isn't sure which rotations should be done clockwise and which should be done counterclockwise. As there are many possible ways of rotating the lock, help him and find out whether there exists at least one, such that after all n rotations the pointer will point at zero again. Input The first line contains one integer n (1 ≀ n ≀ 15) β€” the number of rotations. Each of the following n lines contains one integer a_i (1 ≀ a_i ≀ 180) β€” the angle of the i-th rotation in degrees. Output If it is possible to do all the rotations so that the pointer will point at zero after all of them are performed, print a single word "YES". Otherwise, print "NO". Petr will probably buy a new car in this case. You can print each letter in any case (upper or lower). Examples Input 3 10 20 30 Output YES Input 3 10 10 10 Output NO Input 3 120 120 120 Output YES Note In the first example, we can achieve our goal by applying the first and the second rotation clockwise, and performing the third rotation counterclockwise. In the second example, it's impossible to perform the rotations in order to make the pointer point at zero in the end. In the third example, Petr can do all three rotations clockwise. In this case, the whole wheel will be rotated by 360 degrees clockwise and the pointer will point at zero again. Submitted Solution: ``` n = int(input()) l = [0] for _ in range(0, n): a = int(input()) l2 = [] for x in l: l2.append(x + a) l2.append(x - a) l = l2 print(("NO", "YES")[any([x % 360 == 0 for x in l])]) ```
instruction
0
58,048
3
116,096
Yes
output
1
58,048
3
116,097
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of 360 degrees and a pointer which initially points at zero: <image> Petr called his car dealer, who instructed him to rotate the lock's wheel exactly n times. The i-th rotation should be a_i degrees, either clockwise or counterclockwise, and after all n rotations the pointer should again point at zero. This confused Petr a little bit as he isn't sure which rotations should be done clockwise and which should be done counterclockwise. As there are many possible ways of rotating the lock, help him and find out whether there exists at least one, such that after all n rotations the pointer will point at zero again. Input The first line contains one integer n (1 ≀ n ≀ 15) β€” the number of rotations. Each of the following n lines contains one integer a_i (1 ≀ a_i ≀ 180) β€” the angle of the i-th rotation in degrees. Output If it is possible to do all the rotations so that the pointer will point at zero after all of them are performed, print a single word "YES". Otherwise, print "NO". Petr will probably buy a new car in this case. You can print each letter in any case (upper or lower). Examples Input 3 10 20 30 Output YES Input 3 10 10 10 Output NO Input 3 120 120 120 Output YES Note In the first example, we can achieve our goal by applying the first and the second rotation clockwise, and performing the third rotation counterclockwise. In the second example, it's impossible to perform the rotations in order to make the pointer point at zero in the end. In the third example, Petr can do all three rotations clockwise. In this case, the whole wheel will be rotated by 360 degrees clockwise and the pointer will point at zero again. Submitted Solution: ``` def decToBinary(n,nof): bn = [] while(n>0): bn.append(n%2) n=int(n/2) res=[0 for i in range (nof)] res[nof-len(bn):]=bn[::-1] return res #print (decToBinary(2,4)) n=int(input()) types=pow(2,n) i=0 a=[] for k in range(n): a.append(int(input())) while (i<types): sum=0 p=decToBinary(i,n) #print(p) for j in range(n): if(p[j]==0): sum+=a[j] sum%=360 else: sum+=(360-a[j]) if(sum==0) or (sum==360): print("YES") exit() break i+=1 print("NO") ```
instruction
0
58,049
3
116,098
Yes
output
1
58,049
3
116,099
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of 360 degrees and a pointer which initially points at zero: <image> Petr called his car dealer, who instructed him to rotate the lock's wheel exactly n times. The i-th rotation should be a_i degrees, either clockwise or counterclockwise, and after all n rotations the pointer should again point at zero. This confused Petr a little bit as he isn't sure which rotations should be done clockwise and which should be done counterclockwise. As there are many possible ways of rotating the lock, help him and find out whether there exists at least one, such that after all n rotations the pointer will point at zero again. Input The first line contains one integer n (1 ≀ n ≀ 15) β€” the number of rotations. Each of the following n lines contains one integer a_i (1 ≀ a_i ≀ 180) β€” the angle of the i-th rotation in degrees. Output If it is possible to do all the rotations so that the pointer will point at zero after all of them are performed, print a single word "YES". Otherwise, print "NO". Petr will probably buy a new car in this case. You can print each letter in any case (upper or lower). Examples Input 3 10 20 30 Output YES Input 3 10 10 10 Output NO Input 3 120 120 120 Output YES Note In the first example, we can achieve our goal by applying the first and the second rotation clockwise, and performing the third rotation counterclockwise. In the second example, it's impossible to perform the rotations in order to make the pointer point at zero in the end. In the third example, Petr can do all three rotations clockwise. In this case, the whole wheel will be rotated by 360 degrees clockwise and the pointer will point at zero again. Submitted Solution: ``` from itertools import product n = int(input()) rotates = [] for i in range(n): a = int(input()) rotates.append(a) variants = list(product([0, 1], repeat=n)) for var in variants: sum = 0 for index, value in enumerate(rotates): sum += value if var[index] else -value if sum % 360 == 0 or sum == 0: print("YES") exit() print("NO") ```
instruction
0
58,050
3
116,100
Yes
output
1
58,050
3
116,101
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of 360 degrees and a pointer which initially points at zero: <image> Petr called his car dealer, who instructed him to rotate the lock's wheel exactly n times. The i-th rotation should be a_i degrees, either clockwise or counterclockwise, and after all n rotations the pointer should again point at zero. This confused Petr a little bit as he isn't sure which rotations should be done clockwise and which should be done counterclockwise. As there are many possible ways of rotating the lock, help him and find out whether there exists at least one, such that after all n rotations the pointer will point at zero again. Input The first line contains one integer n (1 ≀ n ≀ 15) β€” the number of rotations. Each of the following n lines contains one integer a_i (1 ≀ a_i ≀ 180) β€” the angle of the i-th rotation in degrees. Output If it is possible to do all the rotations so that the pointer will point at zero after all of them are performed, print a single word "YES". Otherwise, print "NO". Petr will probably buy a new car in this case. You can print each letter in any case (upper or lower). Examples Input 3 10 20 30 Output YES Input 3 10 10 10 Output NO Input 3 120 120 120 Output YES Note In the first example, we can achieve our goal by applying the first and the second rotation clockwise, and performing the third rotation counterclockwise. In the second example, it's impossible to perform the rotations in order to make the pointer point at zero in the end. In the third example, Petr can do all three rotations clockwise. In this case, the whole wheel will be rotated by 360 degrees clockwise and the pointer will point at zero again. Submitted Solution: ``` n=int(input()) k=[] for i in range(n): k.append(int(input())) k=sorted(k) def f(s,i): if (s%360==0) and i==n: print("YES") exit() if i==n: return f(s+k[i],i+1) f(s-k[i],i+1) f(0,0) print("NO") ```
instruction
0
58,051
3
116,102
Yes
output
1
58,051
3
116,103
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of 360 degrees and a pointer which initially points at zero: <image> Petr called his car dealer, who instructed him to rotate the lock's wheel exactly n times. The i-th rotation should be a_i degrees, either clockwise or counterclockwise, and after all n rotations the pointer should again point at zero. This confused Petr a little bit as he isn't sure which rotations should be done clockwise and which should be done counterclockwise. As there are many possible ways of rotating the lock, help him and find out whether there exists at least one, such that after all n rotations the pointer will point at zero again. Input The first line contains one integer n (1 ≀ n ≀ 15) β€” the number of rotations. Each of the following n lines contains one integer a_i (1 ≀ a_i ≀ 180) β€” the angle of the i-th rotation in degrees. Output If it is possible to do all the rotations so that the pointer will point at zero after all of them are performed, print a single word "YES". Otherwise, print "NO". Petr will probably buy a new car in this case. You can print each letter in any case (upper or lower). Examples Input 3 10 20 30 Output YES Input 3 10 10 10 Output NO Input 3 120 120 120 Output YES Note In the first example, we can achieve our goal by applying the first and the second rotation clockwise, and performing the third rotation counterclockwise. In the second example, it's impossible to perform the rotations in order to make the pointer point at zero in the end. In the third example, Petr can do all three rotations clockwise. In this case, the whole wheel will be rotated by 360 degrees clockwise and the pointer will point at zero again. Submitted Solution: ``` n=eval(input()) x=eval(input()) y=eval(input()) z=eval(input()) sum=x+y+z i=0 while i<sum: if x+y==z+i or x+z==y+i or z+y==z+i or x+y+z+i==360: f='YES' break else: f='NO' i+=360 print(f) ```
instruction
0
58,052
3
116,104
No
output
1
58,052
3
116,105
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of 360 degrees and a pointer which initially points at zero: <image> Petr called his car dealer, who instructed him to rotate the lock's wheel exactly n times. The i-th rotation should be a_i degrees, either clockwise or counterclockwise, and after all n rotations the pointer should again point at zero. This confused Petr a little bit as he isn't sure which rotations should be done clockwise and which should be done counterclockwise. As there are many possible ways of rotating the lock, help him and find out whether there exists at least one, such that after all n rotations the pointer will point at zero again. Input The first line contains one integer n (1 ≀ n ≀ 15) β€” the number of rotations. Each of the following n lines contains one integer a_i (1 ≀ a_i ≀ 180) β€” the angle of the i-th rotation in degrees. Output If it is possible to do all the rotations so that the pointer will point at zero after all of them are performed, print a single word "YES". Otherwise, print "NO". Petr will probably buy a new car in this case. You can print each letter in any case (upper or lower). Examples Input 3 10 20 30 Output YES Input 3 10 10 10 Output NO Input 3 120 120 120 Output YES Note In the first example, we can achieve our goal by applying the first and the second rotation clockwise, and performing the third rotation counterclockwise. In the second example, it's impossible to perform the rotations in order to make the pointer point at zero in the end. In the third example, Petr can do all three rotations clockwise. In this case, the whole wheel will be rotated by 360 degrees clockwise and the pointer will point at zero again. Submitted Solution: ``` n = int(input()) degrees = [0] for i in range(n): val = int(input()) valArray = [] for val2 in degrees: valArray.append(val2 + val) valArray.append(val2 - val) degrees = valArray if 0 in degrees or 360 in degrees: print('YES') else: print('NO') ```
instruction
0
58,053
3
116,106
No
output
1
58,053
3
116,107
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of 360 degrees and a pointer which initially points at zero: <image> Petr called his car dealer, who instructed him to rotate the lock's wheel exactly n times. The i-th rotation should be a_i degrees, either clockwise or counterclockwise, and after all n rotations the pointer should again point at zero. This confused Petr a little bit as he isn't sure which rotations should be done clockwise and which should be done counterclockwise. As there are many possible ways of rotating the lock, help him and find out whether there exists at least one, such that after all n rotations the pointer will point at zero again. Input The first line contains one integer n (1 ≀ n ≀ 15) β€” the number of rotations. Each of the following n lines contains one integer a_i (1 ≀ a_i ≀ 180) β€” the angle of the i-th rotation in degrees. Output If it is possible to do all the rotations so that the pointer will point at zero after all of them are performed, print a single word "YES". Otherwise, print "NO". Petr will probably buy a new car in this case. You can print each letter in any case (upper or lower). Examples Input 3 10 20 30 Output YES Input 3 10 10 10 Output NO Input 3 120 120 120 Output YES Note In the first example, we can achieve our goal by applying the first and the second rotation clockwise, and performing the third rotation counterclockwise. In the second example, it's impossible to perform the rotations in order to make the pointer point at zero in the end. In the third example, Petr can do all three rotations clockwise. In this case, the whole wheel will be rotated by 360 degrees clockwise and the pointer will point at zero again. Submitted Solution: ``` n = int(input()) a = [] for i in range(n): a.append(int(input())) a = sorted(a) s = [0] k = 1 for i in a: s1 = [] for j in range(k): s1.append(s[j]+i) s1.append(s[j]-i) k*=2 s = s1 if 0 in s or 360 in s: print('YES') else: print('NO') ```
instruction
0
58,054
3
116,108
No
output
1
58,054
3
116,109
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of 360 degrees and a pointer which initially points at zero: <image> Petr called his car dealer, who instructed him to rotate the lock's wheel exactly n times. The i-th rotation should be a_i degrees, either clockwise or counterclockwise, and after all n rotations the pointer should again point at zero. This confused Petr a little bit as he isn't sure which rotations should be done clockwise and which should be done counterclockwise. As there are many possible ways of rotating the lock, help him and find out whether there exists at least one, such that after all n rotations the pointer will point at zero again. Input The first line contains one integer n (1 ≀ n ≀ 15) β€” the number of rotations. Each of the following n lines contains one integer a_i (1 ≀ a_i ≀ 180) β€” the angle of the i-th rotation in degrees. Output If it is possible to do all the rotations so that the pointer will point at zero after all of them are performed, print a single word "YES". Otherwise, print "NO". Petr will probably buy a new car in this case. You can print each letter in any case (upper or lower). Examples Input 3 10 20 30 Output YES Input 3 10 10 10 Output NO Input 3 120 120 120 Output YES Note In the first example, we can achieve our goal by applying the first and the second rotation clockwise, and performing the third rotation counterclockwise. In the second example, it's impossible to perform the rotations in order to make the pointer point at zero in the end. In the third example, Petr can do all three rotations clockwise. In this case, the whole wheel will be rotated by 360 degrees clockwise and the pointer will point at zero again. Submitted Solution: ``` def subsetSum(arr, n, i,su, count): if (i == n): if (su == 0): count += 1 return count count = subsetSum(arr, n, i + 1, su- arr[i], count) count = subsetSum(arr, n, i + 1, su, count) return count n=int(input()) l=[] for _ in range(n): s=int(input()) l.append(s) sw=(sum(l))//2 if(subsetSum(l,n,0,sw,0) or subsetSum(l,n,0,sw+180,0) or subsetSum(l,n,0,sw+360,0) or subsetSum(l,n,0,sw+180*3,0) or subsetSum(l,n,0,sw+180*4,0)or subsetSum(l,n,0,sw+180*5,0)or subsetSum(l,n,0,sw+180*6,0)or subsetSum(l,n,0,sw+180*7,0)or subsetSum(l,n,0,sw+180*8,0)): print("YES") else: print("NO") ```
instruction
0
58,055
3
116,110
No
output
1
58,055
3
116,111
Provide tags and a correct Python 3 solution for this coding contest problem. The Third Doctor Who once correctly said that travel between parallel universes is "like travelling sideways". However, he incorrectly thought that there were infinite parallel universes, whereas in fact, as we now all know, there will never be more than 250. Heidi recently got her hands on a multiverse observation tool. She was able to see all n universes lined up in a row, with non-existent links between them. She also noticed that the Doctor was in the k-th universe. The tool also points out that due to restrictions originating from the space-time discontinuum, the number of universes will never exceed m. Obviously, the multiverse is unstable because of free will. Each time a decision is made, one of two events will randomly happen: a new parallel universe is created, or a non-existent link is broken. More specifically, * When a universe is created, it will manifest itself between any two adjacent universes or at one of the ends. * When a link is broken, it could be cut between any two adjacent universes. After separating the multiverse into two segments, the segment NOT containing the Doctor will cease to exist. Heidi wants to perform a simulation of t decisions. Each time a decision is made, Heidi wants to know the length of the multiverse (i.e. the number of universes), and the position of the Doctor. Input The first line contains four integers n, k, m and t (2 ≀ k ≀ n ≀ m ≀ 250, 1 ≀ t ≀ 1000). Each of the following t lines is in one of the following formats: * "1 i" β€” meaning that a universe is inserted at the position i (1 ≀ i ≀ l + 1), where l denotes the current length of the multiverse. * "0 i" β€” meaning that the i-th link is broken (1 ≀ i ≀ l - 1), where l denotes the current length of the multiverse. Output Output t lines. Each line should contain l, the current length of the multiverse and k, the current position of the Doctor. It is guaranteed that the sequence of the steps will be valid, i.e. the multiverse will have length at most m and when the link breaking is performed, there will be at least one universe in the multiverse. Example Input 5 2 10 4 0 1 1 1 0 4 1 2 Output 4 1 5 2 4 2 5 3 Note The multiverse initially consisted of 5 universes, with the Doctor being in the second. First, link 1 was broken, leaving the multiverse with 4 universes, and the Doctor in the first. Then, a universe was added to the leftmost end of the multiverse, increasing the multiverse length to 5, and the Doctor was then in the second universe. Then, the rightmost link was broken. Finally, a universe was added between the first and the second universe.
instruction
0
58,104
3
116,208
Tags: implementation Correct Solution: ``` n, k, m, t = map(int, input().split()) for req in range(t): q, i = map(int, input().split()) if q == 1: n += 1 if i <= k: k += 1 else: if i >= k: n = i else: n -= i k -= i print(n, k) ```
output
1
58,104
3
116,209
Provide tags and a correct Python 3 solution for this coding contest problem. The Third Doctor Who once correctly said that travel between parallel universes is "like travelling sideways". However, he incorrectly thought that there were infinite parallel universes, whereas in fact, as we now all know, there will never be more than 250. Heidi recently got her hands on a multiverse observation tool. She was able to see all n universes lined up in a row, with non-existent links between them. She also noticed that the Doctor was in the k-th universe. The tool also points out that due to restrictions originating from the space-time discontinuum, the number of universes will never exceed m. Obviously, the multiverse is unstable because of free will. Each time a decision is made, one of two events will randomly happen: a new parallel universe is created, or a non-existent link is broken. More specifically, * When a universe is created, it will manifest itself between any two adjacent universes or at one of the ends. * When a link is broken, it could be cut between any two adjacent universes. After separating the multiverse into two segments, the segment NOT containing the Doctor will cease to exist. Heidi wants to perform a simulation of t decisions. Each time a decision is made, Heidi wants to know the length of the multiverse (i.e. the number of universes), and the position of the Doctor. Input The first line contains four integers n, k, m and t (2 ≀ k ≀ n ≀ m ≀ 250, 1 ≀ t ≀ 1000). Each of the following t lines is in one of the following formats: * "1 i" β€” meaning that a universe is inserted at the position i (1 ≀ i ≀ l + 1), where l denotes the current length of the multiverse. * "0 i" β€” meaning that the i-th link is broken (1 ≀ i ≀ l - 1), where l denotes the current length of the multiverse. Output Output t lines. Each line should contain l, the current length of the multiverse and k, the current position of the Doctor. It is guaranteed that the sequence of the steps will be valid, i.e. the multiverse will have length at most m and when the link breaking is performed, there will be at least one universe in the multiverse. Example Input 5 2 10 4 0 1 1 1 0 4 1 2 Output 4 1 5 2 4 2 5 3 Note The multiverse initially consisted of 5 universes, with the Doctor being in the second. First, link 1 was broken, leaving the multiverse with 4 universes, and the Doctor in the first. Then, a universe was added to the leftmost end of the multiverse, increasing the multiverse length to 5, and the Doctor was then in the second universe. Then, the rightmost link was broken. Finally, a universe was added between the first and the second universe.
instruction
0
58,105
3
116,210
Tags: implementation Correct Solution: ``` n, k, m, t = map(int, input().split()) for i in range(t): a, b = map(int, input().split()) if a == 0: if k > b: k = k - b n-=b else: n -= (n-b) else: if k >= b: k+=1 n+=1 else: n+=1 print(n, k) ```
output
1
58,105
3
116,211
Provide tags and a correct Python 3 solution for this coding contest problem. The Third Doctor Who once correctly said that travel between parallel universes is "like travelling sideways". However, he incorrectly thought that there were infinite parallel universes, whereas in fact, as we now all know, there will never be more than 250. Heidi recently got her hands on a multiverse observation tool. She was able to see all n universes lined up in a row, with non-existent links between them. She also noticed that the Doctor was in the k-th universe. The tool also points out that due to restrictions originating from the space-time discontinuum, the number of universes will never exceed m. Obviously, the multiverse is unstable because of free will. Each time a decision is made, one of two events will randomly happen: a new parallel universe is created, or a non-existent link is broken. More specifically, * When a universe is created, it will manifest itself between any two adjacent universes or at one of the ends. * When a link is broken, it could be cut between any two adjacent universes. After separating the multiverse into two segments, the segment NOT containing the Doctor will cease to exist. Heidi wants to perform a simulation of t decisions. Each time a decision is made, Heidi wants to know the length of the multiverse (i.e. the number of universes), and the position of the Doctor. Input The first line contains four integers n, k, m and t (2 ≀ k ≀ n ≀ m ≀ 250, 1 ≀ t ≀ 1000). Each of the following t lines is in one of the following formats: * "1 i" β€” meaning that a universe is inserted at the position i (1 ≀ i ≀ l + 1), where l denotes the current length of the multiverse. * "0 i" β€” meaning that the i-th link is broken (1 ≀ i ≀ l - 1), where l denotes the current length of the multiverse. Output Output t lines. Each line should contain l, the current length of the multiverse and k, the current position of the Doctor. It is guaranteed that the sequence of the steps will be valid, i.e. the multiverse will have length at most m and when the link breaking is performed, there will be at least one universe in the multiverse. Example Input 5 2 10 4 0 1 1 1 0 4 1 2 Output 4 1 5 2 4 2 5 3 Note The multiverse initially consisted of 5 universes, with the Doctor being in the second. First, link 1 was broken, leaving the multiverse with 4 universes, and the Doctor in the first. Then, a universe was added to the leftmost end of the multiverse, increasing the multiverse length to 5, and the Doctor was then in the second universe. Then, the rightmost link was broken. Finally, a universe was added between the first and the second universe.
instruction
0
58,106
3
116,212
Tags: implementation Correct Solution: ``` n,k,m,t = map(int,input().split()) usize = n for i in range(t): a,b = map(int,input().split()) if (a == 0): if (k <= b): usize = b else: usize = usize - b k = k - b else: if (k >= b): k = k + 1 usize = usize + 1 print (usize,k) ```
output
1
58,106
3
116,213
Provide tags and a correct Python 3 solution for this coding contest problem. The Third Doctor Who once correctly said that travel between parallel universes is "like travelling sideways". However, he incorrectly thought that there were infinite parallel universes, whereas in fact, as we now all know, there will never be more than 250. Heidi recently got her hands on a multiverse observation tool. She was able to see all n universes lined up in a row, with non-existent links between them. She also noticed that the Doctor was in the k-th universe. The tool also points out that due to restrictions originating from the space-time discontinuum, the number of universes will never exceed m. Obviously, the multiverse is unstable because of free will. Each time a decision is made, one of two events will randomly happen: a new parallel universe is created, or a non-existent link is broken. More specifically, * When a universe is created, it will manifest itself between any two adjacent universes or at one of the ends. * When a link is broken, it could be cut between any two adjacent universes. After separating the multiverse into two segments, the segment NOT containing the Doctor will cease to exist. Heidi wants to perform a simulation of t decisions. Each time a decision is made, Heidi wants to know the length of the multiverse (i.e. the number of universes), and the position of the Doctor. Input The first line contains four integers n, k, m and t (2 ≀ k ≀ n ≀ m ≀ 250, 1 ≀ t ≀ 1000). Each of the following t lines is in one of the following formats: * "1 i" β€” meaning that a universe is inserted at the position i (1 ≀ i ≀ l + 1), where l denotes the current length of the multiverse. * "0 i" β€” meaning that the i-th link is broken (1 ≀ i ≀ l - 1), where l denotes the current length of the multiverse. Output Output t lines. Each line should contain l, the current length of the multiverse and k, the current position of the Doctor. It is guaranteed that the sequence of the steps will be valid, i.e. the multiverse will have length at most m and when the link breaking is performed, there will be at least one universe in the multiverse. Example Input 5 2 10 4 0 1 1 1 0 4 1 2 Output 4 1 5 2 4 2 5 3 Note The multiverse initially consisted of 5 universes, with the Doctor being in the second. First, link 1 was broken, leaving the multiverse with 4 universes, and the Doctor in the first. Then, a universe was added to the leftmost end of the multiverse, increasing the multiverse length to 5, and the Doctor was then in the second universe. Then, the rightmost link was broken. Finally, a universe was added between the first and the second universe.
instruction
0
58,107
3
116,214
Tags: implementation Correct Solution: ``` def main(): n,k,m,t = map(int,input().split()) multi = [0]*n multi[k-1] = 1 for i in range(t): op,index = map(int,input().split()) if op == 1: if k >= index: k += 1 multi.insert(index-1,0) else: if k > index: k -= index multi = multi[index:] else: multi = multi[:index] #print(multi) print(len(multi),k) main() ```
output
1
58,107
3
116,215
Provide tags and a correct Python 3 solution for this coding contest problem. The Third Doctor Who once correctly said that travel between parallel universes is "like travelling sideways". However, he incorrectly thought that there were infinite parallel universes, whereas in fact, as we now all know, there will never be more than 250. Heidi recently got her hands on a multiverse observation tool. She was able to see all n universes lined up in a row, with non-existent links between them. She also noticed that the Doctor was in the k-th universe. The tool also points out that due to restrictions originating from the space-time discontinuum, the number of universes will never exceed m. Obviously, the multiverse is unstable because of free will. Each time a decision is made, one of two events will randomly happen: a new parallel universe is created, or a non-existent link is broken. More specifically, * When a universe is created, it will manifest itself between any two adjacent universes or at one of the ends. * When a link is broken, it could be cut between any two adjacent universes. After separating the multiverse into two segments, the segment NOT containing the Doctor will cease to exist. Heidi wants to perform a simulation of t decisions. Each time a decision is made, Heidi wants to know the length of the multiverse (i.e. the number of universes), and the position of the Doctor. Input The first line contains four integers n, k, m and t (2 ≀ k ≀ n ≀ m ≀ 250, 1 ≀ t ≀ 1000). Each of the following t lines is in one of the following formats: * "1 i" β€” meaning that a universe is inserted at the position i (1 ≀ i ≀ l + 1), where l denotes the current length of the multiverse. * "0 i" β€” meaning that the i-th link is broken (1 ≀ i ≀ l - 1), where l denotes the current length of the multiverse. Output Output t lines. Each line should contain l, the current length of the multiverse and k, the current position of the Doctor. It is guaranteed that the sequence of the steps will be valid, i.e. the multiverse will have length at most m and when the link breaking is performed, there will be at least one universe in the multiverse. Example Input 5 2 10 4 0 1 1 1 0 4 1 2 Output 4 1 5 2 4 2 5 3 Note The multiverse initially consisted of 5 universes, with the Doctor being in the second. First, link 1 was broken, leaving the multiverse with 4 universes, and the Doctor in the first. Then, a universe was added to the leftmost end of the multiverse, increasing the multiverse length to 5, and the Doctor was then in the second universe. Then, the rightmost link was broken. Finally, a universe was added between the first and the second universe.
instruction
0
58,108
3
116,216
Tags: implementation Correct Solution: ``` n, k, m, t = map(int, input().split(' ')) # n = nb univ # k = doc pos # m = max nb univ for _ in range(t): op, pos = map(int, input().split(' ')) if op == 1: if k >= pos: k += 1 n += 1 else: if k > pos: n -= pos k -= pos else: n = pos print(n, k) ```
output
1
58,108
3
116,217
Provide tags and a correct Python 3 solution for this coding contest problem. The Third Doctor Who once correctly said that travel between parallel universes is "like travelling sideways". However, he incorrectly thought that there were infinite parallel universes, whereas in fact, as we now all know, there will never be more than 250. Heidi recently got her hands on a multiverse observation tool. She was able to see all n universes lined up in a row, with non-existent links between them. She also noticed that the Doctor was in the k-th universe. The tool also points out that due to restrictions originating from the space-time discontinuum, the number of universes will never exceed m. Obviously, the multiverse is unstable because of free will. Each time a decision is made, one of two events will randomly happen: a new parallel universe is created, or a non-existent link is broken. More specifically, * When a universe is created, it will manifest itself between any two adjacent universes or at one of the ends. * When a link is broken, it could be cut between any two adjacent universes. After separating the multiverse into two segments, the segment NOT containing the Doctor will cease to exist. Heidi wants to perform a simulation of t decisions. Each time a decision is made, Heidi wants to know the length of the multiverse (i.e. the number of universes), and the position of the Doctor. Input The first line contains four integers n, k, m and t (2 ≀ k ≀ n ≀ m ≀ 250, 1 ≀ t ≀ 1000). Each of the following t lines is in one of the following formats: * "1 i" β€” meaning that a universe is inserted at the position i (1 ≀ i ≀ l + 1), where l denotes the current length of the multiverse. * "0 i" β€” meaning that the i-th link is broken (1 ≀ i ≀ l - 1), where l denotes the current length of the multiverse. Output Output t lines. Each line should contain l, the current length of the multiverse and k, the current position of the Doctor. It is guaranteed that the sequence of the steps will be valid, i.e. the multiverse will have length at most m and when the link breaking is performed, there will be at least one universe in the multiverse. Example Input 5 2 10 4 0 1 1 1 0 4 1 2 Output 4 1 5 2 4 2 5 3 Note The multiverse initially consisted of 5 universes, with the Doctor being in the second. First, link 1 was broken, leaving the multiverse with 4 universes, and the Doctor in the first. Then, a universe was added to the leftmost end of the multiverse, increasing the multiverse length to 5, and the Doctor was then in the second universe. Then, the rightmost link was broken. Finally, a universe was added between the first and the second universe.
instruction
0
58,109
3
116,218
Tags: implementation Correct Solution: ``` n, k, m, t = [int(i) for i in input().split()] temp = n for j in range(t): x, y = [int(z) for z in input().split()] if x == 0: if y < k: temp, k = temp - y, k - y else: temp = y else: temp += 1 if y <= k: k += 1 print(temp, k) ```
output
1
58,109
3
116,219
Provide tags and a correct Python 3 solution for this coding contest problem. The Third Doctor Who once correctly said that travel between parallel universes is "like travelling sideways". However, he incorrectly thought that there were infinite parallel universes, whereas in fact, as we now all know, there will never be more than 250. Heidi recently got her hands on a multiverse observation tool. She was able to see all n universes lined up in a row, with non-existent links between them. She also noticed that the Doctor was in the k-th universe. The tool also points out that due to restrictions originating from the space-time discontinuum, the number of universes will never exceed m. Obviously, the multiverse is unstable because of free will. Each time a decision is made, one of two events will randomly happen: a new parallel universe is created, or a non-existent link is broken. More specifically, * When a universe is created, it will manifest itself between any two adjacent universes or at one of the ends. * When a link is broken, it could be cut between any two adjacent universes. After separating the multiverse into two segments, the segment NOT containing the Doctor will cease to exist. Heidi wants to perform a simulation of t decisions. Each time a decision is made, Heidi wants to know the length of the multiverse (i.e. the number of universes), and the position of the Doctor. Input The first line contains four integers n, k, m and t (2 ≀ k ≀ n ≀ m ≀ 250, 1 ≀ t ≀ 1000). Each of the following t lines is in one of the following formats: * "1 i" β€” meaning that a universe is inserted at the position i (1 ≀ i ≀ l + 1), where l denotes the current length of the multiverse. * "0 i" β€” meaning that the i-th link is broken (1 ≀ i ≀ l - 1), where l denotes the current length of the multiverse. Output Output t lines. Each line should contain l, the current length of the multiverse and k, the current position of the Doctor. It is guaranteed that the sequence of the steps will be valid, i.e. the multiverse will have length at most m and when the link breaking is performed, there will be at least one universe in the multiverse. Example Input 5 2 10 4 0 1 1 1 0 4 1 2 Output 4 1 5 2 4 2 5 3 Note The multiverse initially consisted of 5 universes, with the Doctor being in the second. First, link 1 was broken, leaving the multiverse with 4 universes, and the Doctor in the first. Then, a universe was added to the leftmost end of the multiverse, increasing the multiverse length to 5, and the Doctor was then in the second universe. Then, the rightmost link was broken. Finally, a universe was added between the first and the second universe.
instruction
0
58,110
3
116,220
Tags: implementation Correct Solution: ``` # ------------------- fast io -------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # ------------------- fast io -------------------- n,k,m,t=map(int,input().split()) ans=[0 for s in range(n)];ans[k-1]=1 for s in range(t): p,i=map(int,input().split()) if p==1: ans.append(0) if i<=k: ans[k-1]=0;ans[k]=1 k+=1 else: if i>=k: while len(ans)>i: ans.pop() else: count=0 while count<i: ans.pop(0);count+=1 for i in range(len(ans)): if ans[i]==1: k=i+1 print(len(ans),k) ```
output
1
58,110
3
116,221
Provide tags and a correct Python 3 solution for this coding contest problem. The Third Doctor Who once correctly said that travel between parallel universes is "like travelling sideways". However, he incorrectly thought that there were infinite parallel universes, whereas in fact, as we now all know, there will never be more than 250. Heidi recently got her hands on a multiverse observation tool. She was able to see all n universes lined up in a row, with non-existent links between them. She also noticed that the Doctor was in the k-th universe. The tool also points out that due to restrictions originating from the space-time discontinuum, the number of universes will never exceed m. Obviously, the multiverse is unstable because of free will. Each time a decision is made, one of two events will randomly happen: a new parallel universe is created, or a non-existent link is broken. More specifically, * When a universe is created, it will manifest itself between any two adjacent universes or at one of the ends. * When a link is broken, it could be cut between any two adjacent universes. After separating the multiverse into two segments, the segment NOT containing the Doctor will cease to exist. Heidi wants to perform a simulation of t decisions. Each time a decision is made, Heidi wants to know the length of the multiverse (i.e. the number of universes), and the position of the Doctor. Input The first line contains four integers n, k, m and t (2 ≀ k ≀ n ≀ m ≀ 250, 1 ≀ t ≀ 1000). Each of the following t lines is in one of the following formats: * "1 i" β€” meaning that a universe is inserted at the position i (1 ≀ i ≀ l + 1), where l denotes the current length of the multiverse. * "0 i" β€” meaning that the i-th link is broken (1 ≀ i ≀ l - 1), where l denotes the current length of the multiverse. Output Output t lines. Each line should contain l, the current length of the multiverse and k, the current position of the Doctor. It is guaranteed that the sequence of the steps will be valid, i.e. the multiverse will have length at most m and when the link breaking is performed, there will be at least one universe in the multiverse. Example Input 5 2 10 4 0 1 1 1 0 4 1 2 Output 4 1 5 2 4 2 5 3 Note The multiverse initially consisted of 5 universes, with the Doctor being in the second. First, link 1 was broken, leaving the multiverse with 4 universes, and the Doctor in the first. Then, a universe was added to the leftmost end of the multiverse, increasing the multiverse length to 5, and the Doctor was then in the second universe. Then, the rightmost link was broken. Finally, a universe was added between the first and the second universe.
instruction
0
58,111
3
116,222
Tags: implementation Correct Solution: ``` n , k , m , t = map(int,input().split()) l = [1]*n l[k-1] = "doc" for i in range(t): op , idx = map(int,input().split()) if op == 0: if idx < k: while idx: l.pop(0) idx -= 1 else: idx = len(l) - idx while idx: l.pop() idx -= 1 y = len(l) print(y,end=' ') for x in range(y): if l[x] == "doc": k = x+1 print(x+1) break else: l.insert(idx-1,1) y = len(l) print(y,end=' ') for x in range(y): if l[x] == "doc": k = x+1 print(x+1) break # print(l) ```
output
1
58,111
3
116,223
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Third Doctor Who once correctly said that travel between parallel universes is "like travelling sideways". However, he incorrectly thought that there were infinite parallel universes, whereas in fact, as we now all know, there will never be more than 250. Heidi recently got her hands on a multiverse observation tool. She was able to see all n universes lined up in a row, with non-existent links between them. She also noticed that the Doctor was in the k-th universe. The tool also points out that due to restrictions originating from the space-time discontinuum, the number of universes will never exceed m. Obviously, the multiverse is unstable because of free will. Each time a decision is made, one of two events will randomly happen: a new parallel universe is created, or a non-existent link is broken. More specifically, * When a universe is created, it will manifest itself between any two adjacent universes or at one of the ends. * When a link is broken, it could be cut between any two adjacent universes. After separating the multiverse into two segments, the segment NOT containing the Doctor will cease to exist. Heidi wants to perform a simulation of t decisions. Each time a decision is made, Heidi wants to know the length of the multiverse (i.e. the number of universes), and the position of the Doctor. Input The first line contains four integers n, k, m and t (2 ≀ k ≀ n ≀ m ≀ 250, 1 ≀ t ≀ 1000). Each of the following t lines is in one of the following formats: * "1 i" β€” meaning that a universe is inserted at the position i (1 ≀ i ≀ l + 1), where l denotes the current length of the multiverse. * "0 i" β€” meaning that the i-th link is broken (1 ≀ i ≀ l - 1), where l denotes the current length of the multiverse. Output Output t lines. Each line should contain l, the current length of the multiverse and k, the current position of the Doctor. It is guaranteed that the sequence of the steps will be valid, i.e. the multiverse will have length at most m and when the link breaking is performed, there will be at least one universe in the multiverse. Example Input 5 2 10 4 0 1 1 1 0 4 1 2 Output 4 1 5 2 4 2 5 3 Note The multiverse initially consisted of 5 universes, with the Doctor being in the second. First, link 1 was broken, leaving the multiverse with 4 universes, and the Doctor in the first. Then, a universe was added to the leftmost end of the multiverse, increasing the multiverse length to 5, and the Doctor was then in the second universe. Then, the rightmost link was broken. Finally, a universe was added between the first and the second universe. Submitted Solution: ``` import sys from math import log2 import bisect import heapq # from collections import deque # from types import GeneratorType # def bootstrap(func, stack=[]): # def wrapped_function(*args, **kwargs): # if stack: # return func(*args, **kwargs) # else: # call = func(*args, **kwargs) # while True: # if type(call) is GeneratorType: # stack.append(call) # call = next(call) # else: # stack.pop() # if not stack: # break # call = stack[-1].send(call) # return call # return wrapped_function Ri = lambda : [int(x) for x in sys.stdin.readline().split()] ri = lambda : sys.stdin.readline().strip() def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') INF = 10 ** 18 MOD = 10**9+7 n,k,m,t = Ri() for _ in range(t): a,b = Ri() if a==0: if k <= b: n = b else: k -=b n-=b else: if n+1 > m: continue if b <= k: k+=1 n+=1 else: n+=1 print(n,k) ```
instruction
0
58,112
3
116,224
Yes
output
1
58,112
3
116,225
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Third Doctor Who once correctly said that travel between parallel universes is "like travelling sideways". However, he incorrectly thought that there were infinite parallel universes, whereas in fact, as we now all know, there will never be more than 250. Heidi recently got her hands on a multiverse observation tool. She was able to see all n universes lined up in a row, with non-existent links between them. She also noticed that the Doctor was in the k-th universe. The tool also points out that due to restrictions originating from the space-time discontinuum, the number of universes will never exceed m. Obviously, the multiverse is unstable because of free will. Each time a decision is made, one of two events will randomly happen: a new parallel universe is created, or a non-existent link is broken. More specifically, * When a universe is created, it will manifest itself between any two adjacent universes or at one of the ends. * When a link is broken, it could be cut between any two adjacent universes. After separating the multiverse into two segments, the segment NOT containing the Doctor will cease to exist. Heidi wants to perform a simulation of t decisions. Each time a decision is made, Heidi wants to know the length of the multiverse (i.e. the number of universes), and the position of the Doctor. Input The first line contains four integers n, k, m and t (2 ≀ k ≀ n ≀ m ≀ 250, 1 ≀ t ≀ 1000). Each of the following t lines is in one of the following formats: * "1 i" β€” meaning that a universe is inserted at the position i (1 ≀ i ≀ l + 1), where l denotes the current length of the multiverse. * "0 i" β€” meaning that the i-th link is broken (1 ≀ i ≀ l - 1), where l denotes the current length of the multiverse. Output Output t lines. Each line should contain l, the current length of the multiverse and k, the current position of the Doctor. It is guaranteed that the sequence of the steps will be valid, i.e. the multiverse will have length at most m and when the link breaking is performed, there will be at least one universe in the multiverse. Example Input 5 2 10 4 0 1 1 1 0 4 1 2 Output 4 1 5 2 4 2 5 3 Note The multiverse initially consisted of 5 universes, with the Doctor being in the second. First, link 1 was broken, leaving the multiverse with 4 universes, and the Doctor in the first. Then, a universe was added to the leftmost end of the multiverse, increasing the multiverse length to 5, and the Doctor was then in the second universe. Then, the rightmost link was broken. Finally, a universe was added between the first and the second universe. Submitted Solution: ``` import sys def main(): input = sys.stdin.readline() n, k, m, t = [int(j) for j in input.split()] for i in range(t): input = sys.stdin.readline() d, c = [int(j) for j in input.split()] if d == 0: if c<k: n -= c k -= c else: n = c else: if c<=k: k += 1 n += 1 print(n,k) if __name__ == '__main__': main() ```
instruction
0
58,113
3
116,226
Yes
output
1
58,113
3
116,227
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Third Doctor Who once correctly said that travel between parallel universes is "like travelling sideways". However, he incorrectly thought that there were infinite parallel universes, whereas in fact, as we now all know, there will never be more than 250. Heidi recently got her hands on a multiverse observation tool. She was able to see all n universes lined up in a row, with non-existent links between them. She also noticed that the Doctor was in the k-th universe. The tool also points out that due to restrictions originating from the space-time discontinuum, the number of universes will never exceed m. Obviously, the multiverse is unstable because of free will. Each time a decision is made, one of two events will randomly happen: a new parallel universe is created, or a non-existent link is broken. More specifically, * When a universe is created, it will manifest itself between any two adjacent universes or at one of the ends. * When a link is broken, it could be cut between any two adjacent universes. After separating the multiverse into two segments, the segment NOT containing the Doctor will cease to exist. Heidi wants to perform a simulation of t decisions. Each time a decision is made, Heidi wants to know the length of the multiverse (i.e. the number of universes), and the position of the Doctor. Input The first line contains four integers n, k, m and t (2 ≀ k ≀ n ≀ m ≀ 250, 1 ≀ t ≀ 1000). Each of the following t lines is in one of the following formats: * "1 i" β€” meaning that a universe is inserted at the position i (1 ≀ i ≀ l + 1), where l denotes the current length of the multiverse. * "0 i" β€” meaning that the i-th link is broken (1 ≀ i ≀ l - 1), where l denotes the current length of the multiverse. Output Output t lines. Each line should contain l, the current length of the multiverse and k, the current position of the Doctor. It is guaranteed that the sequence of the steps will be valid, i.e. the multiverse will have length at most m and when the link breaking is performed, there will be at least one universe in the multiverse. Example Input 5 2 10 4 0 1 1 1 0 4 1 2 Output 4 1 5 2 4 2 5 3 Note The multiverse initially consisted of 5 universes, with the Doctor being in the second. First, link 1 was broken, leaving the multiverse with 4 universes, and the Doctor in the first. Then, a universe was added to the leftmost end of the multiverse, increasing the multiverse length to 5, and the Doctor was then in the second universe. Then, the rightmost link was broken. Finally, a universe was added between the first and the second universe. Submitted Solution: ``` n,k,m,t = [int(i) for i in input().split()] k -= 1 for i in range(t): a,x = [int(i) for i in input().split()] if(a == 0): if(x>k): n = x else: n -= x k -= x else: x -= 1 if(x<=k): k += 1 n += 1 print(n,k+1) ```
instruction
0
58,114
3
116,228
Yes
output
1
58,114
3
116,229
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Third Doctor Who once correctly said that travel between parallel universes is "like travelling sideways". However, he incorrectly thought that there were infinite parallel universes, whereas in fact, as we now all know, there will never be more than 250. Heidi recently got her hands on a multiverse observation tool. She was able to see all n universes lined up in a row, with non-existent links between them. She also noticed that the Doctor was in the k-th universe. The tool also points out that due to restrictions originating from the space-time discontinuum, the number of universes will never exceed m. Obviously, the multiverse is unstable because of free will. Each time a decision is made, one of two events will randomly happen: a new parallel universe is created, or a non-existent link is broken. More specifically, * When a universe is created, it will manifest itself between any two adjacent universes or at one of the ends. * When a link is broken, it could be cut between any two adjacent universes. After separating the multiverse into two segments, the segment NOT containing the Doctor will cease to exist. Heidi wants to perform a simulation of t decisions. Each time a decision is made, Heidi wants to know the length of the multiverse (i.e. the number of universes), and the position of the Doctor. Input The first line contains four integers n, k, m and t (2 ≀ k ≀ n ≀ m ≀ 250, 1 ≀ t ≀ 1000). Each of the following t lines is in one of the following formats: * "1 i" β€” meaning that a universe is inserted at the position i (1 ≀ i ≀ l + 1), where l denotes the current length of the multiverse. * "0 i" β€” meaning that the i-th link is broken (1 ≀ i ≀ l - 1), where l denotes the current length of the multiverse. Output Output t lines. Each line should contain l, the current length of the multiverse and k, the current position of the Doctor. It is guaranteed that the sequence of the steps will be valid, i.e. the multiverse will have length at most m and when the link breaking is performed, there will be at least one universe in the multiverse. Example Input 5 2 10 4 0 1 1 1 0 4 1 2 Output 4 1 5 2 4 2 5 3 Note The multiverse initially consisted of 5 universes, with the Doctor being in the second. First, link 1 was broken, leaving the multiverse with 4 universes, and the Doctor in the first. Then, a universe was added to the leftmost end of the multiverse, increasing the multiverse length to 5, and the Doctor was then in the second universe. Then, the rightmost link was broken. Finally, a universe was added between the first and the second universe. Submitted Solution: ``` n, k, m, T = [int(i) for i in input().split()] for t in range(T): x, y = [int(i) for i in input().split()] if x == 1: n += 1 if y <= k: k += 1 else: if y >= k: n = y else: n -= y k -= y print(n, k) ```
instruction
0
58,115
3
116,230
Yes
output
1
58,115
3
116,231
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Third Doctor Who once correctly said that travel between parallel universes is "like travelling sideways". However, he incorrectly thought that there were infinite parallel universes, whereas in fact, as we now all know, there will never be more than 250. Heidi recently got her hands on a multiverse observation tool. She was able to see all n universes lined up in a row, with non-existent links between them. She also noticed that the Doctor was in the k-th universe. The tool also points out that due to restrictions originating from the space-time discontinuum, the number of universes will never exceed m. Obviously, the multiverse is unstable because of free will. Each time a decision is made, one of two events will randomly happen: a new parallel universe is created, or a non-existent link is broken. More specifically, * When a universe is created, it will manifest itself between any two adjacent universes or at one of the ends. * When a link is broken, it could be cut between any two adjacent universes. After separating the multiverse into two segments, the segment NOT containing the Doctor will cease to exist. Heidi wants to perform a simulation of t decisions. Each time a decision is made, Heidi wants to know the length of the multiverse (i.e. the number of universes), and the position of the Doctor. Input The first line contains four integers n, k, m and t (2 ≀ k ≀ n ≀ m ≀ 250, 1 ≀ t ≀ 1000). Each of the following t lines is in one of the following formats: * "1 i" β€” meaning that a universe is inserted at the position i (1 ≀ i ≀ l + 1), where l denotes the current length of the multiverse. * "0 i" β€” meaning that the i-th link is broken (1 ≀ i ≀ l - 1), where l denotes the current length of the multiverse. Output Output t lines. Each line should contain l, the current length of the multiverse and k, the current position of the Doctor. It is guaranteed that the sequence of the steps will be valid, i.e. the multiverse will have length at most m and when the link breaking is performed, there will be at least one universe in the multiverse. Example Input 5 2 10 4 0 1 1 1 0 4 1 2 Output 4 1 5 2 4 2 5 3 Note The multiverse initially consisted of 5 universes, with the Doctor being in the second. First, link 1 was broken, leaving the multiverse with 4 universes, and the Doctor in the first. Then, a universe was added to the leftmost end of the multiverse, increasing the multiverse length to 5, and the Doctor was then in the second universe. Then, the rightmost link was broken. Finally, a universe was added between the first and the second universe. Submitted Solution: ``` from array import * n,k,m,t= (input().split( )) n=int(n) k=int(k) m=int(m) t=int(t) vals= array('L',[]) for i in range(n): if i+1==k : a=1 doctorAdd=i else: a= 0 vals.append(a) for l in range(t) : x,y=input().split() x= int(x) y=int(y) if x==1: vals.insert(y-1,0) else : if doctorAdd >= y : b=0 while b<y: vals.pop(b) b+=1 else : b=y while(b<(len(vals))): vals.pop(b) b+=1 print(len(vals), (vals.index(1))+1) ```
instruction
0
58,116
3
116,232
No
output
1
58,116
3
116,233
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Third Doctor Who once correctly said that travel between parallel universes is "like travelling sideways". However, he incorrectly thought that there were infinite parallel universes, whereas in fact, as we now all know, there will never be more than 250. Heidi recently got her hands on a multiverse observation tool. She was able to see all n universes lined up in a row, with non-existent links between them. She also noticed that the Doctor was in the k-th universe. The tool also points out that due to restrictions originating from the space-time discontinuum, the number of universes will never exceed m. Obviously, the multiverse is unstable because of free will. Each time a decision is made, one of two events will randomly happen: a new parallel universe is created, or a non-existent link is broken. More specifically, * When a universe is created, it will manifest itself between any two adjacent universes or at one of the ends. * When a link is broken, it could be cut between any two adjacent universes. After separating the multiverse into two segments, the segment NOT containing the Doctor will cease to exist. Heidi wants to perform a simulation of t decisions. Each time a decision is made, Heidi wants to know the length of the multiverse (i.e. the number of universes), and the position of the Doctor. Input The first line contains four integers n, k, m and t (2 ≀ k ≀ n ≀ m ≀ 250, 1 ≀ t ≀ 1000). Each of the following t lines is in one of the following formats: * "1 i" β€” meaning that a universe is inserted at the position i (1 ≀ i ≀ l + 1), where l denotes the current length of the multiverse. * "0 i" β€” meaning that the i-th link is broken (1 ≀ i ≀ l - 1), where l denotes the current length of the multiverse. Output Output t lines. Each line should contain l, the current length of the multiverse and k, the current position of the Doctor. It is guaranteed that the sequence of the steps will be valid, i.e. the multiverse will have length at most m and when the link breaking is performed, there will be at least one universe in the multiverse. Example Input 5 2 10 4 0 1 1 1 0 4 1 2 Output 4 1 5 2 4 2 5 3 Note The multiverse initially consisted of 5 universes, with the Doctor being in the second. First, link 1 was broken, leaving the multiverse with 4 universes, and the Doctor in the first. Then, a universe was added to the leftmost end of the multiverse, increasing the multiverse length to 5, and the Doctor was then in the second universe. Then, the rightmost link was broken. Finally, a universe was added between the first and the second universe. Submitted Solution: ``` n, k, m, t = map(int, input().split()) L = [0]*n for _ in range(t): type, i = map(int, input().split()) if(type==1): if(len(L)!=m-1): L.insert(i-1, 0) if(i <= k): k+=1 elif type==0: if(i<k): for _ in range(i): L.pop(0) k-=1 else: for _ in range(n-i): L.pop() print(len(L), end=" ") print(k) ```
instruction
0
58,117
3
116,234
No
output
1
58,117
3
116,235
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Third Doctor Who once correctly said that travel between parallel universes is "like travelling sideways". However, he incorrectly thought that there were infinite parallel universes, whereas in fact, as we now all know, there will never be more than 250. Heidi recently got her hands on a multiverse observation tool. She was able to see all n universes lined up in a row, with non-existent links between them. She also noticed that the Doctor was in the k-th universe. The tool also points out that due to restrictions originating from the space-time discontinuum, the number of universes will never exceed m. Obviously, the multiverse is unstable because of free will. Each time a decision is made, one of two events will randomly happen: a new parallel universe is created, or a non-existent link is broken. More specifically, * When a universe is created, it will manifest itself between any two adjacent universes or at one of the ends. * When a link is broken, it could be cut between any two adjacent universes. After separating the multiverse into two segments, the segment NOT containing the Doctor will cease to exist. Heidi wants to perform a simulation of t decisions. Each time a decision is made, Heidi wants to know the length of the multiverse (i.e. the number of universes), and the position of the Doctor. Input The first line contains four integers n, k, m and t (2 ≀ k ≀ n ≀ m ≀ 250, 1 ≀ t ≀ 1000). Each of the following t lines is in one of the following formats: * "1 i" β€” meaning that a universe is inserted at the position i (1 ≀ i ≀ l + 1), where l denotes the current length of the multiverse. * "0 i" β€” meaning that the i-th link is broken (1 ≀ i ≀ l - 1), where l denotes the current length of the multiverse. Output Output t lines. Each line should contain l, the current length of the multiverse and k, the current position of the Doctor. It is guaranteed that the sequence of the steps will be valid, i.e. the multiverse will have length at most m and when the link breaking is performed, there will be at least one universe in the multiverse. Example Input 5 2 10 4 0 1 1 1 0 4 1 2 Output 4 1 5 2 4 2 5 3 Note The multiverse initially consisted of 5 universes, with the Doctor being in the second. First, link 1 was broken, leaving the multiverse with 4 universes, and the Doctor in the first. Then, a universe was added to the leftmost end of the multiverse, increasing the multiverse length to 5, and the Doctor was then in the second universe. Then, the rightmost link was broken. Finally, a universe was added between the first and the second universe. Submitted Solution: ``` n,k,m,t=map(int,input().split()) flag=0 for i in range(t): a,b=map(int,input().split()) if(a==1): n+=1 if(b<=k): k+=1 print(n,k) else: if(b==n-1 or b==1): n-=1 if(b==1): k-=1 print(n,k) ```
instruction
0
58,118
3
116,236
No
output
1
58,118
3
116,237
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Third Doctor Who once correctly said that travel between parallel universes is "like travelling sideways". However, he incorrectly thought that there were infinite parallel universes, whereas in fact, as we now all know, there will never be more than 250. Heidi recently got her hands on a multiverse observation tool. She was able to see all n universes lined up in a row, with non-existent links between them. She also noticed that the Doctor was in the k-th universe. The tool also points out that due to restrictions originating from the space-time discontinuum, the number of universes will never exceed m. Obviously, the multiverse is unstable because of free will. Each time a decision is made, one of two events will randomly happen: a new parallel universe is created, or a non-existent link is broken. More specifically, * When a universe is created, it will manifest itself between any two adjacent universes or at one of the ends. * When a link is broken, it could be cut between any two adjacent universes. After separating the multiverse into two segments, the segment NOT containing the Doctor will cease to exist. Heidi wants to perform a simulation of t decisions. Each time a decision is made, Heidi wants to know the length of the multiverse (i.e. the number of universes), and the position of the Doctor. Input The first line contains four integers n, k, m and t (2 ≀ k ≀ n ≀ m ≀ 250, 1 ≀ t ≀ 1000). Each of the following t lines is in one of the following formats: * "1 i" β€” meaning that a universe is inserted at the position i (1 ≀ i ≀ l + 1), where l denotes the current length of the multiverse. * "0 i" β€” meaning that the i-th link is broken (1 ≀ i ≀ l - 1), where l denotes the current length of the multiverse. Output Output t lines. Each line should contain l, the current length of the multiverse and k, the current position of the Doctor. It is guaranteed that the sequence of the steps will be valid, i.e. the multiverse will have length at most m and when the link breaking is performed, there will be at least one universe in the multiverse. Example Input 5 2 10 4 0 1 1 1 0 4 1 2 Output 4 1 5 2 4 2 5 3 Note The multiverse initially consisted of 5 universes, with the Doctor being in the second. First, link 1 was broken, leaving the multiverse with 4 universes, and the Doctor in the first. Then, a universe was added to the leftmost end of the multiverse, increasing the multiverse length to 5, and the Doctor was then in the second universe. Then, the rightmost link was broken. Finally, a universe was added between the first and the second universe. Submitted Solution: ``` n,k,m,t=map(int,input().split()) for i in range(t): a,b=map(int,input().split()) if a==1: if b<=k: k+=1 n+=1 print(n,k) else : if k>b: n=n-k+1 k=1 else : n=b print(n,k) ```
instruction
0
58,119
3
116,238
No
output
1
58,119
3
116,239
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n piranhas with sizes a_1, a_2, …, a_n in the aquarium. Piranhas are numbered from left to right in order they live in the aquarium. Scientists of the Berland State University want to find if there is dominant piranha in the aquarium. The piranha is called dominant if it can eat all the other piranhas in the aquarium (except itself, of course). Other piranhas will do nothing while the dominant piranha will eat them. Because the aquarium is pretty narrow and long, the piranha can eat only one of the adjacent piranhas during one move. Piranha can do as many moves as it needs (or as it can). More precisely: * The piranha i can eat the piranha i-1 if the piranha i-1 exists and a_{i - 1} < a_i. * The piranha i can eat the piranha i+1 if the piranha i+1 exists and a_{i + 1} < a_i. When the piranha i eats some piranha, its size increases by one (a_i becomes a_i + 1). Your task is to find any dominant piranha in the aquarium or determine if there are no such piranhas. Note that you have to find any (exactly one) dominant piranha, you don't have to find all of them. For example, if a = [5, 3, 4, 4, 5], then the third piranha can be dominant. Consider the sequence of its moves: * The piranha eats the second piranha and a becomes [5, \underline{5}, 4, 5] (the underlined piranha is our candidate). * The piranha eats the third piranha and a becomes [5, \underline{6}, 5]. * The piranha eats the first piranha and a becomes [\underline{7}, 5]. * The piranha eats the second piranha and a becomes [\underline{8}]. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 2 β‹… 10^4) β€” the number of test cases. Then t test cases follow. The first line of the test case contains one integer n (2 ≀ n ≀ 3 β‹… 10^5) β€” the number of piranhas in the aquarium. The second line of the test case contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 10^9), where a_i is the size of the i-th piranha. It is guaranteed that the sum of n does not exceed 3 β‹… 10^5 (βˆ‘ n ≀ 3 β‹… 10^5). Output For each test case, print the answer: -1 if there are no dominant piranhas in the aquarium or index of any dominant piranha otherwise. If there are several answers, you can print any. Example Input 6 5 5 3 4 4 5 3 1 1 1 5 4 4 3 4 4 5 5 5 4 3 2 3 1 1 2 5 5 4 3 5 5 Output 3 -1 4 3 3 1 Note The first test case of the example is described in the problem statement. In the second test case of the example, there are no dominant piranhas in the aquarium. In the third test case of the example, the fourth piranha can firstly eat the piranha to the left and the aquarium becomes [4, 4, 5, 4], then it can eat any other piranha in the aquarium. Submitted Solution: ``` def lis() : return list(map(int,input().split())) for _ in range(int(input())): y=int(input()) x= lis() y1=set(x) z=list(y1) if(len(z)==1): print(-1) else: w=0 q1=max(x) for i in range(y): if (x[i] == q1): if (i - 1 >= 0 and x[i - 1] != q1 ): w=i+1 break elif (i + 1 < y and x[i + 1] != q1): w=i+1 break if(w==0): print(-1) else: print(w) ```
instruction
0
58,229
3
116,458
Yes
output
1
58,229
3
116,459
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n piranhas with sizes a_1, a_2, …, a_n in the aquarium. Piranhas are numbered from left to right in order they live in the aquarium. Scientists of the Berland State University want to find if there is dominant piranha in the aquarium. The piranha is called dominant if it can eat all the other piranhas in the aquarium (except itself, of course). Other piranhas will do nothing while the dominant piranha will eat them. Because the aquarium is pretty narrow and long, the piranha can eat only one of the adjacent piranhas during one move. Piranha can do as many moves as it needs (or as it can). More precisely: * The piranha i can eat the piranha i-1 if the piranha i-1 exists and a_{i - 1} < a_i. * The piranha i can eat the piranha i+1 if the piranha i+1 exists and a_{i + 1} < a_i. When the piranha i eats some piranha, its size increases by one (a_i becomes a_i + 1). Your task is to find any dominant piranha in the aquarium or determine if there are no such piranhas. Note that you have to find any (exactly one) dominant piranha, you don't have to find all of them. For example, if a = [5, 3, 4, 4, 5], then the third piranha can be dominant. Consider the sequence of its moves: * The piranha eats the second piranha and a becomes [5, \underline{5}, 4, 5] (the underlined piranha is our candidate). * The piranha eats the third piranha and a becomes [5, \underline{6}, 5]. * The piranha eats the first piranha and a becomes [\underline{7}, 5]. * The piranha eats the second piranha and a becomes [\underline{8}]. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 2 β‹… 10^4) β€” the number of test cases. Then t test cases follow. The first line of the test case contains one integer n (2 ≀ n ≀ 3 β‹… 10^5) β€” the number of piranhas in the aquarium. The second line of the test case contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 10^9), where a_i is the size of the i-th piranha. It is guaranteed that the sum of n does not exceed 3 β‹… 10^5 (βˆ‘ n ≀ 3 β‹… 10^5). Output For each test case, print the answer: -1 if there are no dominant piranhas in the aquarium or index of any dominant piranha otherwise. If there are several answers, you can print any. Example Input 6 5 5 3 4 4 5 3 1 1 1 5 4 4 3 4 4 5 5 5 4 3 2 3 1 1 2 5 5 4 3 5 5 Output 3 -1 4 3 3 1 Note The first test case of the example is described in the problem statement. In the second test case of the example, there are no dominant piranhas in the aquarium. In the third test case of the example, the fourth piranha can firstly eat the piranha to the left and the aquarium becomes [4, 4, 5, 4], then it can eat any other piranha in the aquarium. Submitted Solution: ``` import sys input = sys.stdin.readline ''' ''' def solve(n, fish): mx = max(fish) nm = n-1 for i, f in enumerate(fish): if f == mx: if i > 0 and fish[i-1] < mx: return i+1 if i < nm and fish[i+1] < mx: return i+1 return -1 """ def solve(n, fish): mx = fish[0] mx_i = 0 for i, f in enumerate(fish): if f > mx: mx = f mx_i = i size = fish[mx_i] l, r = mx_i-1, mx_i+1 eat = True while eat: eat = False if l < 0 and r == n: break while l >= 0 and fish[l] < size: l -= 1 size += 1 eat = True while r < n and fish[r] < size: r += 1 size += 1 eat = True if not eat: print(l, r, size, mx, mx_i) return -1 return mx_i+1 """ t = int(input()) for _ in range(t): n = int(input()) fish = list(map(int, input().split())) print(solve(n, fish)) ```
instruction
0
58,230
3
116,460
Yes
output
1
58,230
3
116,461
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n piranhas with sizes a_1, a_2, …, a_n in the aquarium. Piranhas are numbered from left to right in order they live in the aquarium. Scientists of the Berland State University want to find if there is dominant piranha in the aquarium. The piranha is called dominant if it can eat all the other piranhas in the aquarium (except itself, of course). Other piranhas will do nothing while the dominant piranha will eat them. Because the aquarium is pretty narrow and long, the piranha can eat only one of the adjacent piranhas during one move. Piranha can do as many moves as it needs (or as it can). More precisely: * The piranha i can eat the piranha i-1 if the piranha i-1 exists and a_{i - 1} < a_i. * The piranha i can eat the piranha i+1 if the piranha i+1 exists and a_{i + 1} < a_i. When the piranha i eats some piranha, its size increases by one (a_i becomes a_i + 1). Your task is to find any dominant piranha in the aquarium or determine if there are no such piranhas. Note that you have to find any (exactly one) dominant piranha, you don't have to find all of them. For example, if a = [5, 3, 4, 4, 5], then the third piranha can be dominant. Consider the sequence of its moves: * The piranha eats the second piranha and a becomes [5, \underline{5}, 4, 5] (the underlined piranha is our candidate). * The piranha eats the third piranha and a becomes [5, \underline{6}, 5]. * The piranha eats the first piranha and a becomes [\underline{7}, 5]. * The piranha eats the second piranha and a becomes [\underline{8}]. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 2 β‹… 10^4) β€” the number of test cases. Then t test cases follow. The first line of the test case contains one integer n (2 ≀ n ≀ 3 β‹… 10^5) β€” the number of piranhas in the aquarium. The second line of the test case contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 10^9), where a_i is the size of the i-th piranha. It is guaranteed that the sum of n does not exceed 3 β‹… 10^5 (βˆ‘ n ≀ 3 β‹… 10^5). Output For each test case, print the answer: -1 if there are no dominant piranhas in the aquarium or index of any dominant piranha otherwise. If there are several answers, you can print any. Example Input 6 5 5 3 4 4 5 3 1 1 1 5 4 4 3 4 4 5 5 5 4 3 2 3 1 1 2 5 5 4 3 5 5 Output 3 -1 4 3 3 1 Note The first test case of the example is described in the problem statement. In the second test case of the example, there are no dominant piranhas in the aquarium. In the third test case of the example, the fourth piranha can firstly eat the piranha to the left and the aquarium becomes [4, 4, 5, 4], then it can eat any other piranha in the aquarium. Submitted Solution: ``` ''' AUTHOR - Ritesh Kumar Singh ''' import sys,threading import math from collections import defaultdict,Counter input = sys.stdin.readline def rl(type): return [type(w) for w in input().split()] def reverse(arr): return arr[-1::-1] def mod(a,m): return (a%m + m)%m def check_prime(n): temp = int(math.sqrt(n) + 1) for i in range(2,temp): if n % i == 0: return False return True def create_graph(n): graph = {} for _ in range(n): x,y = map(int,input().split()) graph[x].append(y) graph[y].append(x) return graph #driver code def main(): for _ in range(int(input())): n = int(input()) arr = rl(int) if arr.count(arr[0]) == len(arr): print(-1) elif n == 2: print(1 if arr[0] > arr[1] else 2) else: maxi = max(arr) prev = 10000000000 nex = arr[1] for i in range(len(arr)): if arr[i] == maxi and (arr[i] > prev or arr[i] > nex): break prev = arr[i] nex = arr[i+2] if i + 2 < len(arr) else 10000000000 print(i+1) sys.setrecursionlimit(10**6) threading.stack_size(10**8) t = threading.Thread(target=main) t.start() t.join() ```
instruction
0
58,231
3
116,462
Yes
output
1
58,231
3
116,463
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n piranhas with sizes a_1, a_2, …, a_n in the aquarium. Piranhas are numbered from left to right in order they live in the aquarium. Scientists of the Berland State University want to find if there is dominant piranha in the aquarium. The piranha is called dominant if it can eat all the other piranhas in the aquarium (except itself, of course). Other piranhas will do nothing while the dominant piranha will eat them. Because the aquarium is pretty narrow and long, the piranha can eat only one of the adjacent piranhas during one move. Piranha can do as many moves as it needs (or as it can). More precisely: * The piranha i can eat the piranha i-1 if the piranha i-1 exists and a_{i - 1} < a_i. * The piranha i can eat the piranha i+1 if the piranha i+1 exists and a_{i + 1} < a_i. When the piranha i eats some piranha, its size increases by one (a_i becomes a_i + 1). Your task is to find any dominant piranha in the aquarium or determine if there are no such piranhas. Note that you have to find any (exactly one) dominant piranha, you don't have to find all of them. For example, if a = [5, 3, 4, 4, 5], then the third piranha can be dominant. Consider the sequence of its moves: * The piranha eats the second piranha and a becomes [5, \underline{5}, 4, 5] (the underlined piranha is our candidate). * The piranha eats the third piranha and a becomes [5, \underline{6}, 5]. * The piranha eats the first piranha and a becomes [\underline{7}, 5]. * The piranha eats the second piranha and a becomes [\underline{8}]. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 2 β‹… 10^4) β€” the number of test cases. Then t test cases follow. The first line of the test case contains one integer n (2 ≀ n ≀ 3 β‹… 10^5) β€” the number of piranhas in the aquarium. The second line of the test case contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 10^9), where a_i is the size of the i-th piranha. It is guaranteed that the sum of n does not exceed 3 β‹… 10^5 (βˆ‘ n ≀ 3 β‹… 10^5). Output For each test case, print the answer: -1 if there are no dominant piranhas in the aquarium or index of any dominant piranha otherwise. If there are several answers, you can print any. Example Input 6 5 5 3 4 4 5 3 1 1 1 5 4 4 3 4 4 5 5 5 4 3 2 3 1 1 2 5 5 4 3 5 5 Output 3 -1 4 3 3 1 Note The first test case of the example is described in the problem statement. In the second test case of the example, there are no dominant piranhas in the aquarium. In the third test case of the example, the fourth piranha can firstly eat the piranha to the left and the aquarium becomes [4, 4, 5, 4], then it can eat any other piranha in the aquarium. Submitted Solution: ``` # -*- coding: utf-8 -*- """ Created on Wed Oct 21 21:19:34 2020 @author: Admin """ for k in range(int(input())): h=input() l=[int(i) for i in input().split()] z=max(l) f=0 if len(set(l))==1: print(-1) else: if l.count(z)==1: print(l.index(z)+1) else: for i in range(len(l)): if f==1: break if i==0: if l[i]==z: if l[i+1]<z: f=1 print(i+1) continue if i==len(l)-1: if l[i]==z: if l[i-1]<z: f=1 print(i+1) continue if 0<i<len(l)-1: if l[i]==z: if l[i+1]<z or l[i-1]<z: f=1 print(i+1) continue ```
instruction
0
58,232
3
116,464
Yes
output
1
58,232
3
116,465
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n piranhas with sizes a_1, a_2, …, a_n in the aquarium. Piranhas are numbered from left to right in order they live in the aquarium. Scientists of the Berland State University want to find if there is dominant piranha in the aquarium. The piranha is called dominant if it can eat all the other piranhas in the aquarium (except itself, of course). Other piranhas will do nothing while the dominant piranha will eat them. Because the aquarium is pretty narrow and long, the piranha can eat only one of the adjacent piranhas during one move. Piranha can do as many moves as it needs (or as it can). More precisely: * The piranha i can eat the piranha i-1 if the piranha i-1 exists and a_{i - 1} < a_i. * The piranha i can eat the piranha i+1 if the piranha i+1 exists and a_{i + 1} < a_i. When the piranha i eats some piranha, its size increases by one (a_i becomes a_i + 1). Your task is to find any dominant piranha in the aquarium or determine if there are no such piranhas. Note that you have to find any (exactly one) dominant piranha, you don't have to find all of them. For example, if a = [5, 3, 4, 4, 5], then the third piranha can be dominant. Consider the sequence of its moves: * The piranha eats the second piranha and a becomes [5, \underline{5}, 4, 5] (the underlined piranha is our candidate). * The piranha eats the third piranha and a becomes [5, \underline{6}, 5]. * The piranha eats the first piranha and a becomes [\underline{7}, 5]. * The piranha eats the second piranha and a becomes [\underline{8}]. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 2 β‹… 10^4) β€” the number of test cases. Then t test cases follow. The first line of the test case contains one integer n (2 ≀ n ≀ 3 β‹… 10^5) β€” the number of piranhas in the aquarium. The second line of the test case contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 10^9), where a_i is the size of the i-th piranha. It is guaranteed that the sum of n does not exceed 3 β‹… 10^5 (βˆ‘ n ≀ 3 β‹… 10^5). Output For each test case, print the answer: -1 if there are no dominant piranhas in the aquarium or index of any dominant piranha otherwise. If there are several answers, you can print any. Example Input 6 5 5 3 4 4 5 3 1 1 1 5 4 4 3 4 4 5 5 5 4 3 2 3 1 1 2 5 5 4 3 5 5 Output 3 -1 4 3 3 1 Note The first test case of the example is described in the problem statement. In the second test case of the example, there are no dominant piranhas in the aquarium. In the third test case of the example, the fourth piranha can firstly eat the piranha to the left and the aquarium becomes [4, 4, 5, 4], then it can eat any other piranha in the aquarium. Submitted Solution: ``` t = int(input()) for i in range(t): n = int(input()) a = [int(item) for item in input().split()] k = 0 max = a[0] for i in range(n - 1): if a[i] < a[i + 1]: max = a[i + 1] k = i + 1 if k == 0: if a[0] == a[-1]: print(-1) else: while a[k] == a[k+1]: k += 1 print(k+1) else: print(k+1) ```
instruction
0
58,233
3
116,466
No
output
1
58,233
3
116,467
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n piranhas with sizes a_1, a_2, …, a_n in the aquarium. Piranhas are numbered from left to right in order they live in the aquarium. Scientists of the Berland State University want to find if there is dominant piranha in the aquarium. The piranha is called dominant if it can eat all the other piranhas in the aquarium (except itself, of course). Other piranhas will do nothing while the dominant piranha will eat them. Because the aquarium is pretty narrow and long, the piranha can eat only one of the adjacent piranhas during one move. Piranha can do as many moves as it needs (or as it can). More precisely: * The piranha i can eat the piranha i-1 if the piranha i-1 exists and a_{i - 1} < a_i. * The piranha i can eat the piranha i+1 if the piranha i+1 exists and a_{i + 1} < a_i. When the piranha i eats some piranha, its size increases by one (a_i becomes a_i + 1). Your task is to find any dominant piranha in the aquarium or determine if there are no such piranhas. Note that you have to find any (exactly one) dominant piranha, you don't have to find all of them. For example, if a = [5, 3, 4, 4, 5], then the third piranha can be dominant. Consider the sequence of its moves: * The piranha eats the second piranha and a becomes [5, \underline{5}, 4, 5] (the underlined piranha is our candidate). * The piranha eats the third piranha and a becomes [5, \underline{6}, 5]. * The piranha eats the first piranha and a becomes [\underline{7}, 5]. * The piranha eats the second piranha and a becomes [\underline{8}]. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 2 β‹… 10^4) β€” the number of test cases. Then t test cases follow. The first line of the test case contains one integer n (2 ≀ n ≀ 3 β‹… 10^5) β€” the number of piranhas in the aquarium. The second line of the test case contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 10^9), where a_i is the size of the i-th piranha. It is guaranteed that the sum of n does not exceed 3 β‹… 10^5 (βˆ‘ n ≀ 3 β‹… 10^5). Output For each test case, print the answer: -1 if there are no dominant piranhas in the aquarium or index of any dominant piranha otherwise. If there are several answers, you can print any. Example Input 6 5 5 3 4 4 5 3 1 1 1 5 4 4 3 4 4 5 5 5 4 3 2 3 1 1 2 5 5 4 3 5 5 Output 3 -1 4 3 3 1 Note The first test case of the example is described in the problem statement. In the second test case of the example, there are no dominant piranhas in the aquarium. In the third test case of the example, the fourth piranha can firstly eat the piranha to the left and the aquarium becomes [4, 4, 5, 4], then it can eat any other piranha in the aquarium. Submitted Solution: ``` import sys import math def get_array(): return list(map(int, sys.stdin.readline().strip().split())) def get_ints(): return map(int, sys.stdin.readline().strip().split()) def input(): return sys.stdin.readline().strip() for _ in range(int(input())): n=int(input()) a=get_array() if len(set(a))==1: print(-1) else: flag=0 ans=0 m=max(a) for i in range(n): if a[i]==m: if i+1<n: if a[i+1]<a[i]: flag=1 ans=i break else: if a[i-1]<a[i]: flag=1 ans=i break print(ans+1) ```
instruction
0
58,234
3
116,468
No
output
1
58,234
3
116,469
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n piranhas with sizes a_1, a_2, …, a_n in the aquarium. Piranhas are numbered from left to right in order they live in the aquarium. Scientists of the Berland State University want to find if there is dominant piranha in the aquarium. The piranha is called dominant if it can eat all the other piranhas in the aquarium (except itself, of course). Other piranhas will do nothing while the dominant piranha will eat them. Because the aquarium is pretty narrow and long, the piranha can eat only one of the adjacent piranhas during one move. Piranha can do as many moves as it needs (or as it can). More precisely: * The piranha i can eat the piranha i-1 if the piranha i-1 exists and a_{i - 1} < a_i. * The piranha i can eat the piranha i+1 if the piranha i+1 exists and a_{i + 1} < a_i. When the piranha i eats some piranha, its size increases by one (a_i becomes a_i + 1). Your task is to find any dominant piranha in the aquarium or determine if there are no such piranhas. Note that you have to find any (exactly one) dominant piranha, you don't have to find all of them. For example, if a = [5, 3, 4, 4, 5], then the third piranha can be dominant. Consider the sequence of its moves: * The piranha eats the second piranha and a becomes [5, \underline{5}, 4, 5] (the underlined piranha is our candidate). * The piranha eats the third piranha and a becomes [5, \underline{6}, 5]. * The piranha eats the first piranha and a becomes [\underline{7}, 5]. * The piranha eats the second piranha and a becomes [\underline{8}]. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 2 β‹… 10^4) β€” the number of test cases. Then t test cases follow. The first line of the test case contains one integer n (2 ≀ n ≀ 3 β‹… 10^5) β€” the number of piranhas in the aquarium. The second line of the test case contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 10^9), where a_i is the size of the i-th piranha. It is guaranteed that the sum of n does not exceed 3 β‹… 10^5 (βˆ‘ n ≀ 3 β‹… 10^5). Output For each test case, print the answer: -1 if there are no dominant piranhas in the aquarium or index of any dominant piranha otherwise. If there are several answers, you can print any. Example Input 6 5 5 3 4 4 5 3 1 1 1 5 4 4 3 4 4 5 5 5 4 3 2 3 1 1 2 5 5 4 3 5 5 Output 3 -1 4 3 3 1 Note The first test case of the example is described in the problem statement. In the second test case of the example, there are no dominant piranhas in the aquarium. In the third test case of the example, the fourth piranha can firstly eat the piranha to the left and the aquarium becomes [4, 4, 5, 4], then it can eat any other piranha in the aquarium. Submitted Solution: ``` t=int(input()) for i in range(t): n=int(input()) a=input().split() for x in range(n): a[x]=int(a[x]) asorted=sorted(a) if len(a)==1: print(1) elif asorted[0]==asorted[n-1]: print(-1) else: a.append(0) for x in range(0,n): if a[x]==asorted[n-1] and a[x+1]!=asorted[n-1]: c=x break print(c+1) ```
instruction
0
58,235
3
116,470
No
output
1
58,235
3
116,471
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n piranhas with sizes a_1, a_2, …, a_n in the aquarium. Piranhas are numbered from left to right in order they live in the aquarium. Scientists of the Berland State University want to find if there is dominant piranha in the aquarium. The piranha is called dominant if it can eat all the other piranhas in the aquarium (except itself, of course). Other piranhas will do nothing while the dominant piranha will eat them. Because the aquarium is pretty narrow and long, the piranha can eat only one of the adjacent piranhas during one move. Piranha can do as many moves as it needs (or as it can). More precisely: * The piranha i can eat the piranha i-1 if the piranha i-1 exists and a_{i - 1} < a_i. * The piranha i can eat the piranha i+1 if the piranha i+1 exists and a_{i + 1} < a_i. When the piranha i eats some piranha, its size increases by one (a_i becomes a_i + 1). Your task is to find any dominant piranha in the aquarium or determine if there are no such piranhas. Note that you have to find any (exactly one) dominant piranha, you don't have to find all of them. For example, if a = [5, 3, 4, 4, 5], then the third piranha can be dominant. Consider the sequence of its moves: * The piranha eats the second piranha and a becomes [5, \underline{5}, 4, 5] (the underlined piranha is our candidate). * The piranha eats the third piranha and a becomes [5, \underline{6}, 5]. * The piranha eats the first piranha and a becomes [\underline{7}, 5]. * The piranha eats the second piranha and a becomes [\underline{8}]. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 2 β‹… 10^4) β€” the number of test cases. Then t test cases follow. The first line of the test case contains one integer n (2 ≀ n ≀ 3 β‹… 10^5) β€” the number of piranhas in the aquarium. The second line of the test case contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 10^9), where a_i is the size of the i-th piranha. It is guaranteed that the sum of n does not exceed 3 β‹… 10^5 (βˆ‘ n ≀ 3 β‹… 10^5). Output For each test case, print the answer: -1 if there are no dominant piranhas in the aquarium or index of any dominant piranha otherwise. If there are several answers, you can print any. Example Input 6 5 5 3 4 4 5 3 1 1 1 5 4 4 3 4 4 5 5 5 4 3 2 3 1 1 2 5 5 4 3 5 5 Output 3 -1 4 3 3 1 Note The first test case of the example is described in the problem statement. In the second test case of the example, there are no dominant piranhas in the aquarium. In the third test case of the example, the fourth piranha can firstly eat the piranha to the left and the aquarium becomes [4, 4, 5, 4], then it can eat any other piranha in the aquarium. Submitted Solution: ``` t = int(input()) for _ in range(t): n = int(input()) pirahnas = [int(x) for x in input().split()] s = set(pirahnas) if len(s) == 1: print(-1) else: biggest = 0 for i,p in enumerate(pirahnas): if pirahnas[biggest] < p: biggest = i print(i) ```
instruction
0
58,236
3
116,472
No
output
1
58,236
3
116,473
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After reaching your destination, you want to build a new colony on the new planet. Since this planet has many mountains and the colony must be built on a flat surface you decided to flatten the mountains using boulders (you are still dreaming so this makes sense to you). <image> You are given an array h_1, h_2, ..., h_n, where h_i is the height of the i-th mountain, and k β€” the number of boulders you have. You will start throwing boulders from the top of the first mountain one by one and they will roll as follows (let's assume that the height of the current mountain is h_i): * if h_i β‰₯ h_{i + 1}, the boulder will roll to the next mountain; * if h_i < h_{i + 1}, the boulder will stop rolling and increase the mountain height by 1 (h_i = h_i + 1); * if the boulder reaches the last mountain it will fall to the waste collection system and disappear. You want to find the position of the k-th boulder or determine that it will fall into the waste collection system. Input The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers n and k (1 ≀ n ≀ 100; 1 ≀ k ≀ 10^9) β€” the number of mountains and the number of boulders. The second line contains n integers h_1, h_2, ..., h_n (1 ≀ h_i ≀ 100) β€” the height of the mountains. It is guaranteed that the sum of n over all test cases does not exceed 100. Output For each test case, print -1 if the k-th boulder will fall into the collection system. Otherwise, print the position of the k-th boulder. Example Input 4 4 3 4 1 2 3 2 7 1 8 4 5 4 1 2 3 3 1 5 3 1 Output 2 1 -1 -1 Note Let's simulate the first case: * The first boulder starts at i = 1; since h_1 β‰₯ h_2 it rolls to i = 2 and stops there because h_2 < h_3. * The new heights are [4,2,2,3]. * The second boulder starts at i = 1; since h_1 β‰₯ h_2 the boulder rolls to i = 2; since h_2 β‰₯ h_3 the boulder rolls to i = 3 and stops there because h_3 < h_4. * The new heights are [4,2,3,3]. * The third boulder starts at i = 1; since h_1 β‰₯ h_2 it rolls to i = 2 and stops there because h_2 < h_3. * The new heights are [4,3,3,3]. The positions where each boulder stopped are the following: [2,3,2]. In the second case, all 7 boulders will stop right at the first mountain rising its height from 1 to 8. The third case is similar to the first one but now you'll throw 5 boulders. The first three will roll in the same way as in the first test case. After that, mountain heights will be equal to [4, 3, 3, 3], that's why the other two boulders will fall into the collection system. In the fourth case, the first and only boulders will fall straight into the collection system. Submitted Solution: ``` for _ in range(int(input())): n,k=[*map(int,input().split())] l=[*map(int,input().split())] ans=0 for i in range(k): cnt=0 for j in range(n-1): if l[j]<l[j+1]: l[j]+=1 ans=j+1 break cnt+=1 if cnt==n-1: ans=-1 break print(ans) ```
instruction
0
58,261
3
116,522
Yes
output
1
58,261
3
116,523
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After reaching your destination, you want to build a new colony on the new planet. Since this planet has many mountains and the colony must be built on a flat surface you decided to flatten the mountains using boulders (you are still dreaming so this makes sense to you). <image> You are given an array h_1, h_2, ..., h_n, where h_i is the height of the i-th mountain, and k β€” the number of boulders you have. You will start throwing boulders from the top of the first mountain one by one and they will roll as follows (let's assume that the height of the current mountain is h_i): * if h_i β‰₯ h_{i + 1}, the boulder will roll to the next mountain; * if h_i < h_{i + 1}, the boulder will stop rolling and increase the mountain height by 1 (h_i = h_i + 1); * if the boulder reaches the last mountain it will fall to the waste collection system and disappear. You want to find the position of the k-th boulder or determine that it will fall into the waste collection system. Input The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers n and k (1 ≀ n ≀ 100; 1 ≀ k ≀ 10^9) β€” the number of mountains and the number of boulders. The second line contains n integers h_1, h_2, ..., h_n (1 ≀ h_i ≀ 100) β€” the height of the mountains. It is guaranteed that the sum of n over all test cases does not exceed 100. Output For each test case, print -1 if the k-th boulder will fall into the collection system. Otherwise, print the position of the k-th boulder. Example Input 4 4 3 4 1 2 3 2 7 1 8 4 5 4 1 2 3 3 1 5 3 1 Output 2 1 -1 -1 Note Let's simulate the first case: * The first boulder starts at i = 1; since h_1 β‰₯ h_2 it rolls to i = 2 and stops there because h_2 < h_3. * The new heights are [4,2,2,3]. * The second boulder starts at i = 1; since h_1 β‰₯ h_2 the boulder rolls to i = 2; since h_2 β‰₯ h_3 the boulder rolls to i = 3 and stops there because h_3 < h_4. * The new heights are [4,2,3,3]. * The third boulder starts at i = 1; since h_1 β‰₯ h_2 it rolls to i = 2 and stops there because h_2 < h_3. * The new heights are [4,3,3,3]. The positions where each boulder stopped are the following: [2,3,2]. In the second case, all 7 boulders will stop right at the first mountain rising its height from 1 to 8. The third case is similar to the first one but now you'll throw 5 boulders. The first three will roll in the same way as in the first test case. After that, mountain heights will be equal to [4, 3, 3, 3], that's why the other two boulders will fall into the collection system. In the fourth case, the first and only boulders will fall straight into the collection system. Submitted Solution: ``` for _ in range(int(input())): x,y = map(int,input().split()) h = list(map(int,input().split())) c = 1 h.append(101) while True: for i in range(x): if h[i+1]>h[i]: h[i] +=1 break if i+1 == x: print(-1) break if c == y: print(i+1) break c+=1 ```
instruction
0
58,262
3
116,524
Yes
output
1
58,262
3
116,525
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After reaching your destination, you want to build a new colony on the new planet. Since this planet has many mountains and the colony must be built on a flat surface you decided to flatten the mountains using boulders (you are still dreaming so this makes sense to you). <image> You are given an array h_1, h_2, ..., h_n, where h_i is the height of the i-th mountain, and k β€” the number of boulders you have. You will start throwing boulders from the top of the first mountain one by one and they will roll as follows (let's assume that the height of the current mountain is h_i): * if h_i β‰₯ h_{i + 1}, the boulder will roll to the next mountain; * if h_i < h_{i + 1}, the boulder will stop rolling and increase the mountain height by 1 (h_i = h_i + 1); * if the boulder reaches the last mountain it will fall to the waste collection system and disappear. You want to find the position of the k-th boulder or determine that it will fall into the waste collection system. Input The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers n and k (1 ≀ n ≀ 100; 1 ≀ k ≀ 10^9) β€” the number of mountains and the number of boulders. The second line contains n integers h_1, h_2, ..., h_n (1 ≀ h_i ≀ 100) β€” the height of the mountains. It is guaranteed that the sum of n over all test cases does not exceed 100. Output For each test case, print -1 if the k-th boulder will fall into the collection system. Otherwise, print the position of the k-th boulder. Example Input 4 4 3 4 1 2 3 2 7 1 8 4 5 4 1 2 3 3 1 5 3 1 Output 2 1 -1 -1 Note Let's simulate the first case: * The first boulder starts at i = 1; since h_1 β‰₯ h_2 it rolls to i = 2 and stops there because h_2 < h_3. * The new heights are [4,2,2,3]. * The second boulder starts at i = 1; since h_1 β‰₯ h_2 the boulder rolls to i = 2; since h_2 β‰₯ h_3 the boulder rolls to i = 3 and stops there because h_3 < h_4. * The new heights are [4,2,3,3]. * The third boulder starts at i = 1; since h_1 β‰₯ h_2 it rolls to i = 2 and stops there because h_2 < h_3. * The new heights are [4,3,3,3]. The positions where each boulder stopped are the following: [2,3,2]. In the second case, all 7 boulders will stop right at the first mountain rising its height from 1 to 8. The third case is similar to the first one but now you'll throw 5 boulders. The first three will roll in the same way as in the first test case. After that, mountain heights will be equal to [4, 3, 3, 3], that's why the other two boulders will fall into the collection system. In the fourth case, the first and only boulders will fall straight into the collection system. Submitted Solution: ``` for _ in range(int(input())): n, k = map(int, input().split()) h = list(map(int, input().split())) j=0 while True: if (len(h)-2==j and h[j]>=h[j+1]) or j==len(h)-1: print(-1) break if h[j]>=h[j+1]: j+=1 else: h[j]+=1 k-=1 if not k: print(j+1) break j=0 ```
instruction
0
58,263
3
116,526
Yes
output
1
58,263
3
116,527