message
stringlengths
2
433k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
113
108k
cluster
float64
12
12
__index_level_0__
int64
226
217k
Provide a correct Python 3 solution for this coding contest problem. Write a program which reads a sequence of integers $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and swap specified elements by a list of the following operation: * swapRange($b, e, t$): For each integer $k$ ($0 \leq k < (e - b)$, swap element $(b + k)$ and element $(t + k)$. Constraints * $1 \leq n \leq 1,000$ * $-1,000,000,000 \leq a_i \leq 1,000,000,000$ * $1 \leq q \leq 1,000$ * $0 \leq b_i < e_i \leq n$ * $0 \leq t_i < t_i + (e_i - b_i) \leq n$ * Given swap ranges do not overlap each other Input The input is given in the following format. $n$ $a_0 \; a_1 \; ...,\; a_{n-1}$ $q$ $b_1 \; e_1 \; t_1$ $b_2 \; e_2 \; t_2$ : $b_{q} \; e_{q} \; t_{q}$ In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given by three integers $b_i \; e_i \; t_i$ in the following $q$ lines. Output Print all elements of $A$ in a line after performing the given operations. Put a single space character between adjacency elements and a newline at the end of the last element. Example Input 11 1 2 3 4 5 6 7 8 9 10 11 1 1 4 7 Output 1 8 9 10 5 6 7 2 3 4 11
instruction
0
57,971
12
115,942
"Correct Solution: ``` input() nums = list(map(int, input().split(' '))) n = int(input()) for _ in range(n): f, m, l = list(map(int, input().split(' '))) m = m-f if f > l: f, l = l, f sb_1 = list(nums[f:f+m]) sb_2 = list(nums[l:l+m]) nums = nums[:f] + sb_2 + nums[f+m:l] + sb_1 + nums[l+m:] print(' '.join(map(str, nums))) ```
output
1
57,971
12
115,943
Provide a correct Python 3 solution for this coding contest problem. Write a program which reads a sequence of integers $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and swap specified elements by a list of the following operation: * swapRange($b, e, t$): For each integer $k$ ($0 \leq k < (e - b)$, swap element $(b + k)$ and element $(t + k)$. Constraints * $1 \leq n \leq 1,000$ * $-1,000,000,000 \leq a_i \leq 1,000,000,000$ * $1 \leq q \leq 1,000$ * $0 \leq b_i < e_i \leq n$ * $0 \leq t_i < t_i + (e_i - b_i) \leq n$ * Given swap ranges do not overlap each other Input The input is given in the following format. $n$ $a_0 \; a_1 \; ...,\; a_{n-1}$ $q$ $b_1 \; e_1 \; t_1$ $b_2 \; e_2 \; t_2$ : $b_{q} \; e_{q} \; t_{q}$ In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given by three integers $b_i \; e_i \; t_i$ in the following $q$ lines. Output Print all elements of $A$ in a line after performing the given operations. Put a single space character between adjacency elements and a newline at the end of the last element. Example Input 11 1 2 3 4 5 6 7 8 9 10 11 1 1 4 7 Output 1 8 9 10 5 6 7 2 3 4 11
instruction
0
57,972
12
115,944
"Correct Solution: ``` N = int(input()) A = list(map(int,input().split())) Q = int(input()) for _ in range(Q): b,e,t = map(int,input().split()) for k in range(e-b): A[b+k],A[t+k] = A[t+k],A[b+k] print(*A) ```
output
1
57,972
12
115,945
Provide a correct Python 3 solution for this coding contest problem. Write a program which reads a sequence of integers $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and swap specified elements by a list of the following operation: * swapRange($b, e, t$): For each integer $k$ ($0 \leq k < (e - b)$, swap element $(b + k)$ and element $(t + k)$. Constraints * $1 \leq n \leq 1,000$ * $-1,000,000,000 \leq a_i \leq 1,000,000,000$ * $1 \leq q \leq 1,000$ * $0 \leq b_i < e_i \leq n$ * $0 \leq t_i < t_i + (e_i - b_i) \leq n$ * Given swap ranges do not overlap each other Input The input is given in the following format. $n$ $a_0 \; a_1 \; ...,\; a_{n-1}$ $q$ $b_1 \; e_1 \; t_1$ $b_2 \; e_2 \; t_2$ : $b_{q} \; e_{q} \; t_{q}$ In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given by three integers $b_i \; e_i \; t_i$ in the following $q$ lines. Output Print all elements of $A$ in a line after performing the given operations. Put a single space character between adjacency elements and a newline at the end of the last element. Example Input 11 1 2 3 4 5 6 7 8 9 10 11 1 1 4 7 Output 1 8 9 10 5 6 7 2 3 4 11
instruction
0
57,973
12
115,946
"Correct Solution: ``` n = int(input()) L = [int(x) for x in input().split()] n = int(input()) for _ in range(n): b, e, t = [int(x) for x in input().split()] L[b:e], L[t:t+e-b] = L[t:t+e-b], L[b:e] print(*L) ```
output
1
57,973
12
115,947
Provide a correct Python 3 solution for this coding contest problem. Write a program which reads a sequence of integers $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and swap specified elements by a list of the following operation: * swapRange($b, e, t$): For each integer $k$ ($0 \leq k < (e - b)$, swap element $(b + k)$ and element $(t + k)$. Constraints * $1 \leq n \leq 1,000$ * $-1,000,000,000 \leq a_i \leq 1,000,000,000$ * $1 \leq q \leq 1,000$ * $0 \leq b_i < e_i \leq n$ * $0 \leq t_i < t_i + (e_i - b_i) \leq n$ * Given swap ranges do not overlap each other Input The input is given in the following format. $n$ $a_0 \; a_1 \; ...,\; a_{n-1}$ $q$ $b_1 \; e_1 \; t_1$ $b_2 \; e_2 \; t_2$ : $b_{q} \; e_{q} \; t_{q}$ In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given by three integers $b_i \; e_i \; t_i$ in the following $q$ lines. Output Print all elements of $A$ in a line after performing the given operations. Put a single space character between adjacency elements and a newline at the end of the last element. Example Input 11 1 2 3 4 5 6 7 8 9 10 11 1 1 4 7 Output 1 8 9 10 5 6 7 2 3 4 11
instruction
0
57,974
12
115,948
"Correct Solution: ``` def main(): n = int(input()) A = list(map(int,input().split())) m = int(input()) for _ in range(m): a,b,c = map(int,input().split()) A[a:b],A[c:c+(b-a)] = A[c:c+(b-a)],A[a:b] print (' '.join(map(str,A))) if __name__ == '__main__': main() ```
output
1
57,974
12
115,949
Provide a correct Python 3 solution for this coding contest problem. Write a program which reads a sequence of integers $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and swap specified elements by a list of the following operation: * swapRange($b, e, t$): For each integer $k$ ($0 \leq k < (e - b)$, swap element $(b + k)$ and element $(t + k)$. Constraints * $1 \leq n \leq 1,000$ * $-1,000,000,000 \leq a_i \leq 1,000,000,000$ * $1 \leq q \leq 1,000$ * $0 \leq b_i < e_i \leq n$ * $0 \leq t_i < t_i + (e_i - b_i) \leq n$ * Given swap ranges do not overlap each other Input The input is given in the following format. $n$ $a_0 \; a_1 \; ...,\; a_{n-1}$ $q$ $b_1 \; e_1 \; t_1$ $b_2 \; e_2 \; t_2$ : $b_{q} \; e_{q} \; t_{q}$ In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given by three integers $b_i \; e_i \; t_i$ in the following $q$ lines. Output Print all elements of $A$ in a line after performing the given operations. Put a single space character between adjacency elements and a newline at the end of the last element. Example Input 11 1 2 3 4 5 6 7 8 9 10 11 1 1 4 7 Output 1 8 9 10 5 6 7 2 3 4 11
instruction
0
57,975
12
115,950
"Correct Solution: ``` n = input() A = list(input().split()) for i in range(int(input())): b, e, t = map(int, input().split()) for k in range(e - b): A[b+k], A[t+k] = A[t+k], A[b+k] print(*A, sep=' ') ```
output
1
57,975
12
115,951
Provide a correct Python 3 solution for this coding contest problem. Write a program which reads a sequence of integers $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and swap specified elements by a list of the following operation: * swapRange($b, e, t$): For each integer $k$ ($0 \leq k < (e - b)$, swap element $(b + k)$ and element $(t + k)$. Constraints * $1 \leq n \leq 1,000$ * $-1,000,000,000 \leq a_i \leq 1,000,000,000$ * $1 \leq q \leq 1,000$ * $0 \leq b_i < e_i \leq n$ * $0 \leq t_i < t_i + (e_i - b_i) \leq n$ * Given swap ranges do not overlap each other Input The input is given in the following format. $n$ $a_0 \; a_1 \; ...,\; a_{n-1}$ $q$ $b_1 \; e_1 \; t_1$ $b_2 \; e_2 \; t_2$ : $b_{q} \; e_{q} \; t_{q}$ In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given by three integers $b_i \; e_i \; t_i$ in the following $q$ lines. Output Print all elements of $A$ in a line after performing the given operations. Put a single space character between adjacency elements and a newline at the end of the last element. Example Input 11 1 2 3 4 5 6 7 8 9 10 11 1 1 4 7 Output 1 8 9 10 5 6 7 2 3 4 11
instruction
0
57,976
12
115,952
"Correct Solution: ``` n = int(input()) arr = input().split() nq = int(input()) for i in range(nq): begin, end, tgt = map(int, input().split()) length = end - begin if begin < tgt: arr = arr[:begin] + arr[tgt:tgt+length] + arr[end:tgt] + arr[begin:end] + arr[tgt+length:] else: arr = arr[:tgt] + arr[begin:end] + arr[tgt+length:begin] + arr[tgt:tgt+length] + arr[end:] print(*arr) ```
output
1
57,976
12
115,953
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Write a program which reads a sequence of integers $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and swap specified elements by a list of the following operation: * swapRange($b, e, t$): For each integer $k$ ($0 \leq k < (e - b)$, swap element $(b + k)$ and element $(t + k)$. Constraints * $1 \leq n \leq 1,000$ * $-1,000,000,000 \leq a_i \leq 1,000,000,000$ * $1 \leq q \leq 1,000$ * $0 \leq b_i < e_i \leq n$ * $0 \leq t_i < t_i + (e_i - b_i) \leq n$ * Given swap ranges do not overlap each other Input The input is given in the following format. $n$ $a_0 \; a_1 \; ...,\; a_{n-1}$ $q$ $b_1 \; e_1 \; t_1$ $b_2 \; e_2 \; t_2$ : $b_{q} \; e_{q} \; t_{q}$ In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given by three integers $b_i \; e_i \; t_i$ in the following $q$ lines. Output Print all elements of $A$ in a line after performing the given operations. Put a single space character between adjacency elements and a newline at the end of the last element. Example Input 11 1 2 3 4 5 6 7 8 9 10 11 1 1 4 7 Output 1 8 9 10 5 6 7 2 3 4 11 Submitted Solution: ``` # coding=utf-8 def partial_swap(origin, begin, end, begin2): list1 = origin[:begin] list2 = origin[begin:end] list3 = origin[end:begin2] list4 = origin[begin2:begin2+end-begin] list5 = origin[begin2+end-begin:] return list1 + list4 + list3 + list2 + list5 if __name__ == '__main__': N = int(input()) A = list(map(int, input().split())) Q = int(input()) for i in range(Q): b, e, t = map(int, input().split()) A = partial_swap(A, b, e, t) print(' '.join(map(str, A))) ```
instruction
0
57,981
12
115,962
No
output
1
57,981
12
115,963
Provide tags and a correct Python 3 solution for this coding contest problem. Initially Ildar has an empty array. He performs n steps. On each step he takes a subset of integers already added to the array and appends the mex of this subset to the array. The mex of an multiset of integers is the smallest non-negative integer not presented in the multiset. For example, the mex of the multiset [0, 2, 3] is 1, while the mex of the multiset [1, 2, 1] is 0. More formally, on the step m, when Ildar already has an array a_1, a_2, …, a_{m-1}, he chooses some subset of indices 1 ≤ i_1 < i_2 < … < i_k < m (possibly, empty), where 0 ≤ k < m, and appends the mex(a_{i_1}, a_{i_2}, … a_{i_k}) to the end of the array. After performing all the steps Ildar thinks that he might have made a mistake somewhere. He asks you to determine for a given array a_1, a_2, …, a_n the minimum step t such that he has definitely made a mistake on at least one of the steps 1, 2, …, t, or determine that he could have obtained this array without mistakes. Input The first line contains a single integer n (1 ≤ n ≤ 100 000) — the number of steps Ildar made. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — the array Ildar obtained. Output If Ildar could have chosen the subsets on each step in such a way that the resulting array is a_1, a_2, …, a_n, print -1. Otherwise print a single integer t — the smallest index of a step such that a mistake was made on at least one step among steps 1, 2, …, t. Examples Input 4 0 1 2 1 Output -1 Input 3 1 0 1 Output 1 Input 4 0 1 2 239 Output 4 Note In the first example it is possible that Ildar made no mistakes. Here is the process he could have followed. * 1-st step. The initial array is empty. He can choose an empty subset and obtain 0, because the mex of an empty set is 0. Appending this value to the end he gets the array [0]. * 2-nd step. The current array is [0]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1]. * 3-rd step. The current array is [0,1]. He can choose a subset [0,1] and obtain an integer 2, because mex(0,1) = 2. Appending this value to the end he gets the array [0,1,2]. * 4-th step. The current array is [0,1,2]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1,2,1]. Thus, he can get the array without mistakes, so the answer is -1. In the second example he has definitely made a mistake on the very first step, because he could not have obtained anything different from 0. In the third example he could have obtained [0, 1, 2] without mistakes, but 239 is definitely wrong.
instruction
0
58,008
12
116,016
Tags: implementation Correct Solution: ``` n=int(input()) l=input().split() if l[0]!='0': print(1) exit() m=0 for i in range(1,n): if int(l[i])>m+1: print(i+1) exit() if int(l[i])>=m+1: m=int(l[i]) print(-1) ```
output
1
58,008
12
116,017
Provide tags and a correct Python 3 solution for this coding contest problem. Initially Ildar has an empty array. He performs n steps. On each step he takes a subset of integers already added to the array and appends the mex of this subset to the array. The mex of an multiset of integers is the smallest non-negative integer not presented in the multiset. For example, the mex of the multiset [0, 2, 3] is 1, while the mex of the multiset [1, 2, 1] is 0. More formally, on the step m, when Ildar already has an array a_1, a_2, …, a_{m-1}, he chooses some subset of indices 1 ≤ i_1 < i_2 < … < i_k < m (possibly, empty), where 0 ≤ k < m, and appends the mex(a_{i_1}, a_{i_2}, … a_{i_k}) to the end of the array. After performing all the steps Ildar thinks that he might have made a mistake somewhere. He asks you to determine for a given array a_1, a_2, …, a_n the minimum step t such that he has definitely made a mistake on at least one of the steps 1, 2, …, t, or determine that he could have obtained this array without mistakes. Input The first line contains a single integer n (1 ≤ n ≤ 100 000) — the number of steps Ildar made. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — the array Ildar obtained. Output If Ildar could have chosen the subsets on each step in such a way that the resulting array is a_1, a_2, …, a_n, print -1. Otherwise print a single integer t — the smallest index of a step such that a mistake was made on at least one step among steps 1, 2, …, t. Examples Input 4 0 1 2 1 Output -1 Input 3 1 0 1 Output 1 Input 4 0 1 2 239 Output 4 Note In the first example it is possible that Ildar made no mistakes. Here is the process he could have followed. * 1-st step. The initial array is empty. He can choose an empty subset and obtain 0, because the mex of an empty set is 0. Appending this value to the end he gets the array [0]. * 2-nd step. The current array is [0]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1]. * 3-rd step. The current array is [0,1]. He can choose a subset [0,1] and obtain an integer 2, because mex(0,1) = 2. Appending this value to the end he gets the array [0,1,2]. * 4-th step. The current array is [0,1,2]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1,2,1]. Thus, he can get the array without mistakes, so the answer is -1. In the second example he has definitely made a mistake on the very first step, because he could not have obtained anything different from 0. In the third example he could have obtained [0, 1, 2] without mistakes, but 239 is definitely wrong.
instruction
0
58,009
12
116,018
Tags: implementation Correct Solution: ``` step = int(input()) arrayVal = [int(item) for item in input().split(" ")] maxMex = 0 for i,item in enumerate(arrayVal): if arrayVal[0] != 0: print(1) break elif item > maxMex+1: print(i+1) break elif i == step-1: print(-1) maxMex = max(item,maxMex) ```
output
1
58,009
12
116,019
Provide tags and a correct Python 3 solution for this coding contest problem. Initially Ildar has an empty array. He performs n steps. On each step he takes a subset of integers already added to the array and appends the mex of this subset to the array. The mex of an multiset of integers is the smallest non-negative integer not presented in the multiset. For example, the mex of the multiset [0, 2, 3] is 1, while the mex of the multiset [1, 2, 1] is 0. More formally, on the step m, when Ildar already has an array a_1, a_2, …, a_{m-1}, he chooses some subset of indices 1 ≤ i_1 < i_2 < … < i_k < m (possibly, empty), where 0 ≤ k < m, and appends the mex(a_{i_1}, a_{i_2}, … a_{i_k}) to the end of the array. After performing all the steps Ildar thinks that he might have made a mistake somewhere. He asks you to determine for a given array a_1, a_2, …, a_n the minimum step t such that he has definitely made a mistake on at least one of the steps 1, 2, …, t, or determine that he could have obtained this array without mistakes. Input The first line contains a single integer n (1 ≤ n ≤ 100 000) — the number of steps Ildar made. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — the array Ildar obtained. Output If Ildar could have chosen the subsets on each step in such a way that the resulting array is a_1, a_2, …, a_n, print -1. Otherwise print a single integer t — the smallest index of a step such that a mistake was made on at least one step among steps 1, 2, …, t. Examples Input 4 0 1 2 1 Output -1 Input 3 1 0 1 Output 1 Input 4 0 1 2 239 Output 4 Note In the first example it is possible that Ildar made no mistakes. Here is the process he could have followed. * 1-st step. The initial array is empty. He can choose an empty subset and obtain 0, because the mex of an empty set is 0. Appending this value to the end he gets the array [0]. * 2-nd step. The current array is [0]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1]. * 3-rd step. The current array is [0,1]. He can choose a subset [0,1] and obtain an integer 2, because mex(0,1) = 2. Appending this value to the end he gets the array [0,1,2]. * 4-th step. The current array is [0,1,2]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1,2,1]. Thus, he can get the array without mistakes, so the answer is -1. In the second example he has definitely made a mistake on the very first step, because he could not have obtained anything different from 0. In the third example he could have obtained [0, 1, 2] without mistakes, but 239 is definitely wrong.
instruction
0
58,010
12
116,020
Tags: implementation Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) m = -1 for i, elem in enumerate(a): if elem - m > 1 or elem < 0: print(i + 1) break if elem > m: m = elem else: print(-1) ```
output
1
58,010
12
116,021
Provide tags and a correct Python 3 solution for this coding contest problem. Initially Ildar has an empty array. He performs n steps. On each step he takes a subset of integers already added to the array and appends the mex of this subset to the array. The mex of an multiset of integers is the smallest non-negative integer not presented in the multiset. For example, the mex of the multiset [0, 2, 3] is 1, while the mex of the multiset [1, 2, 1] is 0. More formally, on the step m, when Ildar already has an array a_1, a_2, …, a_{m-1}, he chooses some subset of indices 1 ≤ i_1 < i_2 < … < i_k < m (possibly, empty), where 0 ≤ k < m, and appends the mex(a_{i_1}, a_{i_2}, … a_{i_k}) to the end of the array. After performing all the steps Ildar thinks that he might have made a mistake somewhere. He asks you to determine for a given array a_1, a_2, …, a_n the minimum step t such that he has definitely made a mistake on at least one of the steps 1, 2, …, t, or determine that he could have obtained this array without mistakes. Input The first line contains a single integer n (1 ≤ n ≤ 100 000) — the number of steps Ildar made. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — the array Ildar obtained. Output If Ildar could have chosen the subsets on each step in such a way that the resulting array is a_1, a_2, …, a_n, print -1. Otherwise print a single integer t — the smallest index of a step such that a mistake was made on at least one step among steps 1, 2, …, t. Examples Input 4 0 1 2 1 Output -1 Input 3 1 0 1 Output 1 Input 4 0 1 2 239 Output 4 Note In the first example it is possible that Ildar made no mistakes. Here is the process he could have followed. * 1-st step. The initial array is empty. He can choose an empty subset and obtain 0, because the mex of an empty set is 0. Appending this value to the end he gets the array [0]. * 2-nd step. The current array is [0]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1]. * 3-rd step. The current array is [0,1]. He can choose a subset [0,1] and obtain an integer 2, because mex(0,1) = 2. Appending this value to the end he gets the array [0,1,2]. * 4-th step. The current array is [0,1,2]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1,2,1]. Thus, he can get the array without mistakes, so the answer is -1. In the second example he has definitely made a mistake on the very first step, because he could not have obtained anything different from 0. In the third example he could have obtained [0, 1, 2] without mistakes, but 239 is definitely wrong.
instruction
0
58,011
12
116,022
Tags: implementation Correct Solution: ``` input() m = -1 for i, a in enumerate(map(int, input().split())): if a > m + 1: print(i+1) break else: m = max(m, a) else: print(-1) ```
output
1
58,011
12
116,023
Provide tags and a correct Python 3 solution for this coding contest problem. Initially Ildar has an empty array. He performs n steps. On each step he takes a subset of integers already added to the array and appends the mex of this subset to the array. The mex of an multiset of integers is the smallest non-negative integer not presented in the multiset. For example, the mex of the multiset [0, 2, 3] is 1, while the mex of the multiset [1, 2, 1] is 0. More formally, on the step m, when Ildar already has an array a_1, a_2, …, a_{m-1}, he chooses some subset of indices 1 ≤ i_1 < i_2 < … < i_k < m (possibly, empty), where 0 ≤ k < m, and appends the mex(a_{i_1}, a_{i_2}, … a_{i_k}) to the end of the array. After performing all the steps Ildar thinks that he might have made a mistake somewhere. He asks you to determine for a given array a_1, a_2, …, a_n the minimum step t such that he has definitely made a mistake on at least one of the steps 1, 2, …, t, or determine that he could have obtained this array without mistakes. Input The first line contains a single integer n (1 ≤ n ≤ 100 000) — the number of steps Ildar made. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — the array Ildar obtained. Output If Ildar could have chosen the subsets on each step in such a way that the resulting array is a_1, a_2, …, a_n, print -1. Otherwise print a single integer t — the smallest index of a step such that a mistake was made on at least one step among steps 1, 2, …, t. Examples Input 4 0 1 2 1 Output -1 Input 3 1 0 1 Output 1 Input 4 0 1 2 239 Output 4 Note In the first example it is possible that Ildar made no mistakes. Here is the process he could have followed. * 1-st step. The initial array is empty. He can choose an empty subset and obtain 0, because the mex of an empty set is 0. Appending this value to the end he gets the array [0]. * 2-nd step. The current array is [0]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1]. * 3-rd step. The current array is [0,1]. He can choose a subset [0,1] and obtain an integer 2, because mex(0,1) = 2. Appending this value to the end he gets the array [0,1,2]. * 4-th step. The current array is [0,1,2]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1,2,1]. Thus, he can get the array without mistakes, so the answer is -1. In the second example he has definitely made a mistake on the very first step, because he could not have obtained anything different from 0. In the third example he could have obtained [0, 1, 2] without mistakes, but 239 is definitely wrong.
instruction
0
58,012
12
116,024
Tags: implementation Correct Solution: ``` n=int(input()) la=list(map(int,input().rstrip().split())) i=0 p=[] c=0 for x in range(n): if la[x]<i: i-=1 elif la[x]==i: pass else: index=x+1 c=1 break i+=1 if c==1: print(index) else: print("-1") ```
output
1
58,012
12
116,025
Provide tags and a correct Python 3 solution for this coding contest problem. Initially Ildar has an empty array. He performs n steps. On each step he takes a subset of integers already added to the array and appends the mex of this subset to the array. The mex of an multiset of integers is the smallest non-negative integer not presented in the multiset. For example, the mex of the multiset [0, 2, 3] is 1, while the mex of the multiset [1, 2, 1] is 0. More formally, on the step m, when Ildar already has an array a_1, a_2, …, a_{m-1}, he chooses some subset of indices 1 ≤ i_1 < i_2 < … < i_k < m (possibly, empty), where 0 ≤ k < m, and appends the mex(a_{i_1}, a_{i_2}, … a_{i_k}) to the end of the array. After performing all the steps Ildar thinks that he might have made a mistake somewhere. He asks you to determine for a given array a_1, a_2, …, a_n the minimum step t such that he has definitely made a mistake on at least one of the steps 1, 2, …, t, or determine that he could have obtained this array without mistakes. Input The first line contains a single integer n (1 ≤ n ≤ 100 000) — the number of steps Ildar made. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — the array Ildar obtained. Output If Ildar could have chosen the subsets on each step in such a way that the resulting array is a_1, a_2, …, a_n, print -1. Otherwise print a single integer t — the smallest index of a step such that a mistake was made on at least one step among steps 1, 2, …, t. Examples Input 4 0 1 2 1 Output -1 Input 3 1 0 1 Output 1 Input 4 0 1 2 239 Output 4 Note In the first example it is possible that Ildar made no mistakes. Here is the process he could have followed. * 1-st step. The initial array is empty. He can choose an empty subset and obtain 0, because the mex of an empty set is 0. Appending this value to the end he gets the array [0]. * 2-nd step. The current array is [0]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1]. * 3-rd step. The current array is [0,1]. He can choose a subset [0,1] and obtain an integer 2, because mex(0,1) = 2. Appending this value to the end he gets the array [0,1,2]. * 4-th step. The current array is [0,1,2]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1,2,1]. Thus, he can get the array without mistakes, so the answer is -1. In the second example he has definitely made a mistake on the very first step, because he could not have obtained anything different from 0. In the third example he could have obtained [0, 1, 2] without mistakes, but 239 is definitely wrong.
instruction
0
58,013
12
116,026
Tags: implementation Correct Solution: ``` from sys import stdin, stdout import cProfile, math from collections import Counter from bisect import bisect_left printHeap = str() test = False memory_constrained = False def display(string_to_print): stdout.write(str(string_to_print) + "\n") def test_print(output): if test: stdout.write(str(output) + "\n") def display_list(list1, sep=" "): stdout.write(sep.join(map(str, list1)) + "\n") def get_int(): return int(stdin.readline().strip()) def get_tuple(): return map(int, stdin.readline().split()) def get_list(): return list(map(int, stdin.readline().split())) memory = dict() def clear_cache(): global memory memory = dict() def cached_fn(fn, *args): global memory if args in memory: return memory[args] else: result = fn(*args) memory[args] = result return result # ----------------------------------------------------------------------------------- MAIN PROGRAM def main(): n = get_int() li = get_list() max = li[0] if max!=0: print (1) return j = 1 for i in li: if i<=max: j+=1 continue elif i==max+1: max = i else: print(j) return j+=1 print(-1) # --------------------------------------------------------------------------------------------- END cProfile.run('main()') if test else main() ```
output
1
58,013
12
116,027
Provide tags and a correct Python 3 solution for this coding contest problem. Initially Ildar has an empty array. He performs n steps. On each step he takes a subset of integers already added to the array and appends the mex of this subset to the array. The mex of an multiset of integers is the smallest non-negative integer not presented in the multiset. For example, the mex of the multiset [0, 2, 3] is 1, while the mex of the multiset [1, 2, 1] is 0. More formally, on the step m, when Ildar already has an array a_1, a_2, …, a_{m-1}, he chooses some subset of indices 1 ≤ i_1 < i_2 < … < i_k < m (possibly, empty), where 0 ≤ k < m, and appends the mex(a_{i_1}, a_{i_2}, … a_{i_k}) to the end of the array. After performing all the steps Ildar thinks that he might have made a mistake somewhere. He asks you to determine for a given array a_1, a_2, …, a_n the minimum step t such that he has definitely made a mistake on at least one of the steps 1, 2, …, t, or determine that he could have obtained this array without mistakes. Input The first line contains a single integer n (1 ≤ n ≤ 100 000) — the number of steps Ildar made. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — the array Ildar obtained. Output If Ildar could have chosen the subsets on each step in such a way that the resulting array is a_1, a_2, …, a_n, print -1. Otherwise print a single integer t — the smallest index of a step such that a mistake was made on at least one step among steps 1, 2, …, t. Examples Input 4 0 1 2 1 Output -1 Input 3 1 0 1 Output 1 Input 4 0 1 2 239 Output 4 Note In the first example it is possible that Ildar made no mistakes. Here is the process he could have followed. * 1-st step. The initial array is empty. He can choose an empty subset and obtain 0, because the mex of an empty set is 0. Appending this value to the end he gets the array [0]. * 2-nd step. The current array is [0]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1]. * 3-rd step. The current array is [0,1]. He can choose a subset [0,1] and obtain an integer 2, because mex(0,1) = 2. Appending this value to the end he gets the array [0,1,2]. * 4-th step. The current array is [0,1,2]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1,2,1]. Thus, he can get the array without mistakes, so the answer is -1. In the second example he has definitely made a mistake on the very first step, because he could not have obtained anything different from 0. In the third example he could have obtained [0, 1, 2] without mistakes, but 239 is definitely wrong.
instruction
0
58,014
12
116,028
Tags: implementation Correct Solution: ``` input() a = tuple(map(int, input().split())) top = -1 for i, x in enumerate(a, start=1): if x - top <= 1: top = max(x, top) else: print(i) exit() print(-1) ```
output
1
58,014
12
116,029
Provide tags and a correct Python 3 solution for this coding contest problem. Initially Ildar has an empty array. He performs n steps. On each step he takes a subset of integers already added to the array and appends the mex of this subset to the array. The mex of an multiset of integers is the smallest non-negative integer not presented in the multiset. For example, the mex of the multiset [0, 2, 3] is 1, while the mex of the multiset [1, 2, 1] is 0. More formally, on the step m, when Ildar already has an array a_1, a_2, …, a_{m-1}, he chooses some subset of indices 1 ≤ i_1 < i_2 < … < i_k < m (possibly, empty), where 0 ≤ k < m, and appends the mex(a_{i_1}, a_{i_2}, … a_{i_k}) to the end of the array. After performing all the steps Ildar thinks that he might have made a mistake somewhere. He asks you to determine for a given array a_1, a_2, …, a_n the minimum step t such that he has definitely made a mistake on at least one of the steps 1, 2, …, t, or determine that he could have obtained this array without mistakes. Input The first line contains a single integer n (1 ≤ n ≤ 100 000) — the number of steps Ildar made. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — the array Ildar obtained. Output If Ildar could have chosen the subsets on each step in such a way that the resulting array is a_1, a_2, …, a_n, print -1. Otherwise print a single integer t — the smallest index of a step such that a mistake was made on at least one step among steps 1, 2, …, t. Examples Input 4 0 1 2 1 Output -1 Input 3 1 0 1 Output 1 Input 4 0 1 2 239 Output 4 Note In the first example it is possible that Ildar made no mistakes. Here is the process he could have followed. * 1-st step. The initial array is empty. He can choose an empty subset and obtain 0, because the mex of an empty set is 0. Appending this value to the end he gets the array [0]. * 2-nd step. The current array is [0]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1]. * 3-rd step. The current array is [0,1]. He can choose a subset [0,1] and obtain an integer 2, because mex(0,1) = 2. Appending this value to the end he gets the array [0,1,2]. * 4-th step. The current array is [0,1,2]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1,2,1]. Thus, he can get the array without mistakes, so the answer is -1. In the second example he has definitely made a mistake on the very first step, because he could not have obtained anything different from 0. In the third example he could have obtained [0, 1, 2] without mistakes, but 239 is definitely wrong.
instruction
0
58,015
12
116,030
Tags: implementation Correct Solution: ``` n=int(input()) a=list(map(int,input().split())) maxx=0 flag=0 for i in range(n): if i==0: if a[i]!=0: print(i+1) flag=1 break elif a[i]>maxx+1: print(i+1) flag=1 break elif a[i]==maxx+1: maxx=a[i] if flag==0: print(-1) ```
output
1
58,015
12
116,031
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Initially Ildar has an empty array. He performs n steps. On each step he takes a subset of integers already added to the array and appends the mex of this subset to the array. The mex of an multiset of integers is the smallest non-negative integer not presented in the multiset. For example, the mex of the multiset [0, 2, 3] is 1, while the mex of the multiset [1, 2, 1] is 0. More formally, on the step m, when Ildar already has an array a_1, a_2, …, a_{m-1}, he chooses some subset of indices 1 ≤ i_1 < i_2 < … < i_k < m (possibly, empty), where 0 ≤ k < m, and appends the mex(a_{i_1}, a_{i_2}, … a_{i_k}) to the end of the array. After performing all the steps Ildar thinks that he might have made a mistake somewhere. He asks you to determine for a given array a_1, a_2, …, a_n the minimum step t such that he has definitely made a mistake on at least one of the steps 1, 2, …, t, or determine that he could have obtained this array without mistakes. Input The first line contains a single integer n (1 ≤ n ≤ 100 000) — the number of steps Ildar made. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — the array Ildar obtained. Output If Ildar could have chosen the subsets on each step in such a way that the resulting array is a_1, a_2, …, a_n, print -1. Otherwise print a single integer t — the smallest index of a step such that a mistake was made on at least one step among steps 1, 2, …, t. Examples Input 4 0 1 2 1 Output -1 Input 3 1 0 1 Output 1 Input 4 0 1 2 239 Output 4 Note In the first example it is possible that Ildar made no mistakes. Here is the process he could have followed. * 1-st step. The initial array is empty. He can choose an empty subset and obtain 0, because the mex of an empty set is 0. Appending this value to the end he gets the array [0]. * 2-nd step. The current array is [0]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1]. * 3-rd step. The current array is [0,1]. He can choose a subset [0,1] and obtain an integer 2, because mex(0,1) = 2. Appending this value to the end he gets the array [0,1,2]. * 4-th step. The current array is [0,1,2]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1,2,1]. Thus, he can get the array without mistakes, so the answer is -1. In the second example he has definitely made a mistake on the very first step, because he could not have obtained anything different from 0. In the third example he could have obtained [0, 1, 2] without mistakes, but 239 is definitely wrong. Submitted Solution: ``` # import atexit # import io # import sys # # _INPUT_LINES = sys.stdin.read().splitlines() # input = iter(_INPUT_LINES).__next__ # _OUTPUT_BUFFER = io.StringIO() # sys.stdout = _OUTPUT_BUFFER # # # @atexit.register # def write(): # sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) n = int(input()) arr = list(map(int, input().split())) mx = -1 for idx, v in enumerate(arr): if mx + 1 == v: mx = v elif v > mx + 1: print(idx + 1) exit(0) print(-1) ```
instruction
0
58,016
12
116,032
Yes
output
1
58,016
12
116,033
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Initially Ildar has an empty array. He performs n steps. On each step he takes a subset of integers already added to the array and appends the mex of this subset to the array. The mex of an multiset of integers is the smallest non-negative integer not presented in the multiset. For example, the mex of the multiset [0, 2, 3] is 1, while the mex of the multiset [1, 2, 1] is 0. More formally, on the step m, when Ildar already has an array a_1, a_2, …, a_{m-1}, he chooses some subset of indices 1 ≤ i_1 < i_2 < … < i_k < m (possibly, empty), where 0 ≤ k < m, and appends the mex(a_{i_1}, a_{i_2}, … a_{i_k}) to the end of the array. After performing all the steps Ildar thinks that he might have made a mistake somewhere. He asks you to determine for a given array a_1, a_2, …, a_n the minimum step t such that he has definitely made a mistake on at least one of the steps 1, 2, …, t, or determine that he could have obtained this array without mistakes. Input The first line contains a single integer n (1 ≤ n ≤ 100 000) — the number of steps Ildar made. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — the array Ildar obtained. Output If Ildar could have chosen the subsets on each step in such a way that the resulting array is a_1, a_2, …, a_n, print -1. Otherwise print a single integer t — the smallest index of a step such that a mistake was made on at least one step among steps 1, 2, …, t. Examples Input 4 0 1 2 1 Output -1 Input 3 1 0 1 Output 1 Input 4 0 1 2 239 Output 4 Note In the first example it is possible that Ildar made no mistakes. Here is the process he could have followed. * 1-st step. The initial array is empty. He can choose an empty subset and obtain 0, because the mex of an empty set is 0. Appending this value to the end he gets the array [0]. * 2-nd step. The current array is [0]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1]. * 3-rd step. The current array is [0,1]. He can choose a subset [0,1] and obtain an integer 2, because mex(0,1) = 2. Appending this value to the end he gets the array [0,1,2]. * 4-th step. The current array is [0,1,2]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1,2,1]. Thus, he can get the array without mistakes, so the answer is -1. In the second example he has definitely made a mistake on the very first step, because he could not have obtained anything different from 0. In the third example he could have obtained [0, 1, 2] without mistakes, but 239 is definitely wrong. Submitted Solution: ``` n=int(input()) a=list(map(int,input().strip().split())) k,ans=-1,-1 for i in range(n): if a[i]>k+1: ans=i+1 break k=max(a[i],k) print(ans) ```
instruction
0
58,017
12
116,034
Yes
output
1
58,017
12
116,035
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Initially Ildar has an empty array. He performs n steps. On each step he takes a subset of integers already added to the array and appends the mex of this subset to the array. The mex of an multiset of integers is the smallest non-negative integer not presented in the multiset. For example, the mex of the multiset [0, 2, 3] is 1, while the mex of the multiset [1, 2, 1] is 0. More formally, on the step m, when Ildar already has an array a_1, a_2, …, a_{m-1}, he chooses some subset of indices 1 ≤ i_1 < i_2 < … < i_k < m (possibly, empty), where 0 ≤ k < m, and appends the mex(a_{i_1}, a_{i_2}, … a_{i_k}) to the end of the array. After performing all the steps Ildar thinks that he might have made a mistake somewhere. He asks you to determine for a given array a_1, a_2, …, a_n the minimum step t such that he has definitely made a mistake on at least one of the steps 1, 2, …, t, or determine that he could have obtained this array without mistakes. Input The first line contains a single integer n (1 ≤ n ≤ 100 000) — the number of steps Ildar made. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — the array Ildar obtained. Output If Ildar could have chosen the subsets on each step in such a way that the resulting array is a_1, a_2, …, a_n, print -1. Otherwise print a single integer t — the smallest index of a step such that a mistake was made on at least one step among steps 1, 2, …, t. Examples Input 4 0 1 2 1 Output -1 Input 3 1 0 1 Output 1 Input 4 0 1 2 239 Output 4 Note In the first example it is possible that Ildar made no mistakes. Here is the process he could have followed. * 1-st step. The initial array is empty. He can choose an empty subset and obtain 0, because the mex of an empty set is 0. Appending this value to the end he gets the array [0]. * 2-nd step. The current array is [0]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1]. * 3-rd step. The current array is [0,1]. He can choose a subset [0,1] and obtain an integer 2, because mex(0,1) = 2. Appending this value to the end he gets the array [0,1,2]. * 4-th step. The current array is [0,1,2]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1,2,1]. Thus, he can get the array without mistakes, so the answer is -1. In the second example he has definitely made a mistake on the very first step, because he could not have obtained anything different from 0. In the third example he could have obtained [0, 1, 2] without mistakes, but 239 is definitely wrong. Submitted Solution: ``` n = int(input()) a = [int(t) for t in input().split(' ')] maxn = 0 for i in range(len(a)): if a[i] <= maxn: maxn = max(maxn, a[i] + 1) else: print(i+1) break else: print(-1) ```
instruction
0
58,018
12
116,036
Yes
output
1
58,018
12
116,037
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Initially Ildar has an empty array. He performs n steps. On each step he takes a subset of integers already added to the array and appends the mex of this subset to the array. The mex of an multiset of integers is the smallest non-negative integer not presented in the multiset. For example, the mex of the multiset [0, 2, 3] is 1, while the mex of the multiset [1, 2, 1] is 0. More formally, on the step m, when Ildar already has an array a_1, a_2, …, a_{m-1}, he chooses some subset of indices 1 ≤ i_1 < i_2 < … < i_k < m (possibly, empty), where 0 ≤ k < m, and appends the mex(a_{i_1}, a_{i_2}, … a_{i_k}) to the end of the array. After performing all the steps Ildar thinks that he might have made a mistake somewhere. He asks you to determine for a given array a_1, a_2, …, a_n the minimum step t such that he has definitely made a mistake on at least one of the steps 1, 2, …, t, or determine that he could have obtained this array without mistakes. Input The first line contains a single integer n (1 ≤ n ≤ 100 000) — the number of steps Ildar made. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — the array Ildar obtained. Output If Ildar could have chosen the subsets on each step in such a way that the resulting array is a_1, a_2, …, a_n, print -1. Otherwise print a single integer t — the smallest index of a step such that a mistake was made on at least one step among steps 1, 2, …, t. Examples Input 4 0 1 2 1 Output -1 Input 3 1 0 1 Output 1 Input 4 0 1 2 239 Output 4 Note In the first example it is possible that Ildar made no mistakes. Here is the process he could have followed. * 1-st step. The initial array is empty. He can choose an empty subset and obtain 0, because the mex of an empty set is 0. Appending this value to the end he gets the array [0]. * 2-nd step. The current array is [0]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1]. * 3-rd step. The current array is [0,1]. He can choose a subset [0,1] and obtain an integer 2, because mex(0,1) = 2. Appending this value to the end he gets the array [0,1,2]. * 4-th step. The current array is [0,1,2]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1,2,1]. Thus, he can get the array without mistakes, so the answer is -1. In the second example he has definitely made a mistake on the very first step, because he could not have obtained anything different from 0. In the third example he could have obtained [0, 1, 2] without mistakes, but 239 is definitely wrong. Submitted Solution: ``` n = int(input()) A = list(map(int, input().split())) q = -2 kek = {ww - 1: 0 for ww in set(A)} for elemq in range(n): elem = A[elemq] kek[elem] = 1 if not kek[elem - 1] and elem != 0: q = elemq break print(q + 1) ```
instruction
0
58,019
12
116,038
Yes
output
1
58,019
12
116,039
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Initially Ildar has an empty array. He performs n steps. On each step he takes a subset of integers already added to the array and appends the mex of this subset to the array. The mex of an multiset of integers is the smallest non-negative integer not presented in the multiset. For example, the mex of the multiset [0, 2, 3] is 1, while the mex of the multiset [1, 2, 1] is 0. More formally, on the step m, when Ildar already has an array a_1, a_2, …, a_{m-1}, he chooses some subset of indices 1 ≤ i_1 < i_2 < … < i_k < m (possibly, empty), where 0 ≤ k < m, and appends the mex(a_{i_1}, a_{i_2}, … a_{i_k}) to the end of the array. After performing all the steps Ildar thinks that he might have made a mistake somewhere. He asks you to determine for a given array a_1, a_2, …, a_n the minimum step t such that he has definitely made a mistake on at least one of the steps 1, 2, …, t, or determine that he could have obtained this array without mistakes. Input The first line contains a single integer n (1 ≤ n ≤ 100 000) — the number of steps Ildar made. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — the array Ildar obtained. Output If Ildar could have chosen the subsets on each step in such a way that the resulting array is a_1, a_2, …, a_n, print -1. Otherwise print a single integer t — the smallest index of a step such that a mistake was made on at least one step among steps 1, 2, …, t. Examples Input 4 0 1 2 1 Output -1 Input 3 1 0 1 Output 1 Input 4 0 1 2 239 Output 4 Note In the first example it is possible that Ildar made no mistakes. Here is the process he could have followed. * 1-st step. The initial array is empty. He can choose an empty subset and obtain 0, because the mex of an empty set is 0. Appending this value to the end he gets the array [0]. * 2-nd step. The current array is [0]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1]. * 3-rd step. The current array is [0,1]. He can choose a subset [0,1] and obtain an integer 2, because mex(0,1) = 2. Appending this value to the end he gets the array [0,1,2]. * 4-th step. The current array is [0,1,2]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1,2,1]. Thus, he can get the array without mistakes, so the answer is -1. In the second example he has definitely made a mistake on the very first step, because he could not have obtained anything different from 0. In the third example he could have obtained [0, 1, 2] without mistakes, but 239 is definitely wrong. Submitted Solution: ``` n = int(input()) a = list(map(int, input().split())) stop = True if a[0]!=0: print(1) stop=False else: for i in range(1,n): if not a[i]-1 in a: print(i+1) stop = False break if stop: print(-1) ```
instruction
0
58,020
12
116,040
No
output
1
58,020
12
116,041
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Initially Ildar has an empty array. He performs n steps. On each step he takes a subset of integers already added to the array and appends the mex of this subset to the array. The mex of an multiset of integers is the smallest non-negative integer not presented in the multiset. For example, the mex of the multiset [0, 2, 3] is 1, while the mex of the multiset [1, 2, 1] is 0. More formally, on the step m, when Ildar already has an array a_1, a_2, …, a_{m-1}, he chooses some subset of indices 1 ≤ i_1 < i_2 < … < i_k < m (possibly, empty), where 0 ≤ k < m, and appends the mex(a_{i_1}, a_{i_2}, … a_{i_k}) to the end of the array. After performing all the steps Ildar thinks that he might have made a mistake somewhere. He asks you to determine for a given array a_1, a_2, …, a_n the minimum step t such that he has definitely made a mistake on at least one of the steps 1, 2, …, t, or determine that he could have obtained this array without mistakes. Input The first line contains a single integer n (1 ≤ n ≤ 100 000) — the number of steps Ildar made. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — the array Ildar obtained. Output If Ildar could have chosen the subsets on each step in such a way that the resulting array is a_1, a_2, …, a_n, print -1. Otherwise print a single integer t — the smallest index of a step such that a mistake was made on at least one step among steps 1, 2, …, t. Examples Input 4 0 1 2 1 Output -1 Input 3 1 0 1 Output 1 Input 4 0 1 2 239 Output 4 Note In the first example it is possible that Ildar made no mistakes. Here is the process he could have followed. * 1-st step. The initial array is empty. He can choose an empty subset and obtain 0, because the mex of an empty set is 0. Appending this value to the end he gets the array [0]. * 2-nd step. The current array is [0]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1]. * 3-rd step. The current array is [0,1]. He can choose a subset [0,1] and obtain an integer 2, because mex(0,1) = 2. Appending this value to the end he gets the array [0,1,2]. * 4-th step. The current array is [0,1,2]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1,2,1]. Thus, he can get the array without mistakes, so the answer is -1. In the second example he has definitely made a mistake on the very first step, because he could not have obtained anything different from 0. In the third example he could have obtained [0, 1, 2] without mistakes, but 239 is definitely wrong. Submitted Solution: ``` import sys import math n=int(input()) lisa=[int(x) for x in input().strip().split()] max,flag=0,True for i in range(n): if(i==0 and lisa[i]!=0): print("1") flag=False break if(lisa[i]<=max): continue if(lisa[i]==max+1): max=lisa[i]+1 continue elif(i!=0): print(i+1) flag=False if(flag==True):print("-1") ```
instruction
0
58,021
12
116,042
No
output
1
58,021
12
116,043
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Initially Ildar has an empty array. He performs n steps. On each step he takes a subset of integers already added to the array and appends the mex of this subset to the array. The mex of an multiset of integers is the smallest non-negative integer not presented in the multiset. For example, the mex of the multiset [0, 2, 3] is 1, while the mex of the multiset [1, 2, 1] is 0. More formally, on the step m, when Ildar already has an array a_1, a_2, …, a_{m-1}, he chooses some subset of indices 1 ≤ i_1 < i_2 < … < i_k < m (possibly, empty), where 0 ≤ k < m, and appends the mex(a_{i_1}, a_{i_2}, … a_{i_k}) to the end of the array. After performing all the steps Ildar thinks that he might have made a mistake somewhere. He asks you to determine for a given array a_1, a_2, …, a_n the minimum step t such that he has definitely made a mistake on at least one of the steps 1, 2, …, t, or determine that he could have obtained this array without mistakes. Input The first line contains a single integer n (1 ≤ n ≤ 100 000) — the number of steps Ildar made. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — the array Ildar obtained. Output If Ildar could have chosen the subsets on each step in such a way that the resulting array is a_1, a_2, …, a_n, print -1. Otherwise print a single integer t — the smallest index of a step such that a mistake was made on at least one step among steps 1, 2, …, t. Examples Input 4 0 1 2 1 Output -1 Input 3 1 0 1 Output 1 Input 4 0 1 2 239 Output 4 Note In the first example it is possible that Ildar made no mistakes. Here is the process he could have followed. * 1-st step. The initial array is empty. He can choose an empty subset and obtain 0, because the mex of an empty set is 0. Appending this value to the end he gets the array [0]. * 2-nd step. The current array is [0]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1]. * 3-rd step. The current array is [0,1]. He can choose a subset [0,1] and obtain an integer 2, because mex(0,1) = 2. Appending this value to the end he gets the array [0,1,2]. * 4-th step. The current array is [0,1,2]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1,2,1]. Thus, he can get the array without mistakes, so the answer is -1. In the second example he has definitely made a mistake on the very first step, because he could not have obtained anything different from 0. In the third example he could have obtained [0, 1, 2] without mistakes, but 239 is definitely wrong. Submitted Solution: ``` n=int(input()) li=list(map(int,input().split())) if(n==1 and li[0]==0): print(-1) else: c=0 di=[0 for i in range(n)] if(li[0]!=0): print(1) else: for i in range(1,n): if(li[i]-li[i-1]!=1): if(li[i]>li[i-1]): li3=li[0:i] if(li[i]-1 not in li3): print(i+1) c=1 break if(c==0): print(-1) ```
instruction
0
58,022
12
116,044
No
output
1
58,022
12
116,045
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Initially Ildar has an empty array. He performs n steps. On each step he takes a subset of integers already added to the array and appends the mex of this subset to the array. The mex of an multiset of integers is the smallest non-negative integer not presented in the multiset. For example, the mex of the multiset [0, 2, 3] is 1, while the mex of the multiset [1, 2, 1] is 0. More formally, on the step m, when Ildar already has an array a_1, a_2, …, a_{m-1}, he chooses some subset of indices 1 ≤ i_1 < i_2 < … < i_k < m (possibly, empty), where 0 ≤ k < m, and appends the mex(a_{i_1}, a_{i_2}, … a_{i_k}) to the end of the array. After performing all the steps Ildar thinks that he might have made a mistake somewhere. He asks you to determine for a given array a_1, a_2, …, a_n the minimum step t such that he has definitely made a mistake on at least one of the steps 1, 2, …, t, or determine that he could have obtained this array without mistakes. Input The first line contains a single integer n (1 ≤ n ≤ 100 000) — the number of steps Ildar made. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — the array Ildar obtained. Output If Ildar could have chosen the subsets on each step in such a way that the resulting array is a_1, a_2, …, a_n, print -1. Otherwise print a single integer t — the smallest index of a step such that a mistake was made on at least one step among steps 1, 2, …, t. Examples Input 4 0 1 2 1 Output -1 Input 3 1 0 1 Output 1 Input 4 0 1 2 239 Output 4 Note In the first example it is possible that Ildar made no mistakes. Here is the process he could have followed. * 1-st step. The initial array is empty. He can choose an empty subset and obtain 0, because the mex of an empty set is 0. Appending this value to the end he gets the array [0]. * 2-nd step. The current array is [0]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1]. * 3-rd step. The current array is [0,1]. He can choose a subset [0,1] and obtain an integer 2, because mex(0,1) = 2. Appending this value to the end he gets the array [0,1,2]. * 4-th step. The current array is [0,1,2]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1,2,1]. Thus, he can get the array without mistakes, so the answer is -1. In the second example he has definitely made a mistake on the very first step, because he could not have obtained anything different from 0. In the third example he could have obtained [0, 1, 2] without mistakes, but 239 is definitely wrong. Submitted Solution: ``` n = int(input()) m = 0 a = list(map(int,input().split())) for i in range(n): if a[i] > m+1: print(i+1) exit() m = max(m,a[i]) print(-1) ```
instruction
0
58,023
12
116,046
No
output
1
58,023
12
116,047
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two arrays a and b, both of length n. Let's define a function f(l, r) = ∑_{l ≤ i ≤ r} a_i ⋅ b_i. Your task is to reorder the elements (choose an arbitrary order of elements) of the array b to minimize the value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r). Since the answer can be very large, you have to print it modulo 998244353. Note that you should minimize the answer but not its remainder. Input The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of elements in a and b. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^6), where a_i is the i-th element of a. The third line of the input contains n integers b_1, b_2, ..., b_n (1 ≤ b_j ≤ 10^6), where b_j is the j-th element of b. Output Print one integer — the minimum possible value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r) after rearranging elements of b, taken modulo 998244353. Note that you should minimize the answer but not its remainder. Examples Input 5 1 8 7 2 4 9 7 2 9 3 Output 646 Input 1 1000000 1000000 Output 757402647 Input 2 1 3 4 2 Output 20
instruction
0
58,088
12
116,176
Tags: greedy, math, sortings Correct Solution: ``` n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) for i in range(n): a[i]*=(i+1)*(n-i) a.sort() b.sort(reverse=True) print(sum(a[i]*b[i] for i in range(n))%998244353) ```
output
1
58,088
12
116,177
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two arrays a and b, both of length n. Let's define a function f(l, r) = ∑_{l ≤ i ≤ r} a_i ⋅ b_i. Your task is to reorder the elements (choose an arbitrary order of elements) of the array b to minimize the value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r). Since the answer can be very large, you have to print it modulo 998244353. Note that you should minimize the answer but not its remainder. Input The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of elements in a and b. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^6), where a_i is the i-th element of a. The third line of the input contains n integers b_1, b_2, ..., b_n (1 ≤ b_j ≤ 10^6), where b_j is the j-th element of b. Output Print one integer — the minimum possible value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r) after rearranging elements of b, taken modulo 998244353. Note that you should minimize the answer but not its remainder. Examples Input 5 1 8 7 2 4 9 7 2 9 3 Output 646 Input 1 1000000 1000000 Output 757402647 Input 2 1 3 4 2 Output 20
instruction
0
58,089
12
116,178
Tags: greedy, math, sortings Correct Solution: ``` import sys input = sys.stdin.readline rInt = lambda: int(input()) mInt = lambda: map(int, input().split()) rLis = lambda: list(map(int, input().split())) n = rInt() a, b = rLis(), rLis() for i in range(n): a[i] *= (i + 1) * (n - i) a.sort() b.sort(reverse = True) out = 0 for i in range(n): out += a[i] * b[i] out %= 998244353 print(out) ```
output
1
58,089
12
116,179
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two arrays a and b, both of length n. Let's define a function f(l, r) = ∑_{l ≤ i ≤ r} a_i ⋅ b_i. Your task is to reorder the elements (choose an arbitrary order of elements) of the array b to minimize the value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r). Since the answer can be very large, you have to print it modulo 998244353. Note that you should minimize the answer but not its remainder. Input The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of elements in a and b. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^6), where a_i is the i-th element of a. The third line of the input contains n integers b_1, b_2, ..., b_n (1 ≤ b_j ≤ 10^6), where b_j is the j-th element of b. Output Print one integer — the minimum possible value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r) after rearranging elements of b, taken modulo 998244353. Note that you should minimize the answer but not its remainder. Examples Input 5 1 8 7 2 4 9 7 2 9 3 Output 646 Input 1 1000000 1000000 Output 757402647 Input 2 1 3 4 2 Output 20
instruction
0
58,090
12
116,180
Tags: greedy, math, sortings Correct Solution: ``` n = int(input()) a = list(map(int,input().split(' '))) at = [] for i in range(len(a)): at.append(a[i]*(i+1)*(n-i)) at.sort(reverse=True) b = list(map(int,input().split(' '))) b.sort() print(sum([a*b for a,b in zip(at,b)]) % 998244353) ```
output
1
58,090
12
116,181
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two arrays a and b, both of length n. Let's define a function f(l, r) = ∑_{l ≤ i ≤ r} a_i ⋅ b_i. Your task is to reorder the elements (choose an arbitrary order of elements) of the array b to minimize the value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r). Since the answer can be very large, you have to print it modulo 998244353. Note that you should minimize the answer but not its remainder. Input The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of elements in a and b. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^6), where a_i is the i-th element of a. The third line of the input contains n integers b_1, b_2, ..., b_n (1 ≤ b_j ≤ 10^6), where b_j is the j-th element of b. Output Print one integer — the minimum possible value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r) after rearranging elements of b, taken modulo 998244353. Note that you should minimize the answer but not its remainder. Examples Input 5 1 8 7 2 4 9 7 2 9 3 Output 646 Input 1 1000000 1000000 Output 757402647 Input 2 1 3 4 2 Output 20
instruction
0
58,091
12
116,182
Tags: greedy, math, sortings Correct Solution: ``` from sys import stdin def main(): n = int(stdin.readline()) a = list(map(int, stdin.readline().split())) b = list(map(int, stdin.readline().split())) # a.sort(reverse=True) b.sort(reverse=True) ans = 0 mod = 998244353 h = [] for i in range(1, n + 1): h.append(i * (n - i + 1)) for i in range(n): h[i] = h[i] * a[i] h.sort() for i in range(n): ans += (b[i] * h[i]) % mod print(ans % mod) if __name__ == "__main__": main() ```
output
1
58,091
12
116,183
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two arrays a and b, both of length n. Let's define a function f(l, r) = ∑_{l ≤ i ≤ r} a_i ⋅ b_i. Your task is to reorder the elements (choose an arbitrary order of elements) of the array b to minimize the value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r). Since the answer can be very large, you have to print it modulo 998244353. Note that you should minimize the answer but not its remainder. Input The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of elements in a and b. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^6), where a_i is the i-th element of a. The third line of the input contains n integers b_1, b_2, ..., b_n (1 ≤ b_j ≤ 10^6), where b_j is the j-th element of b. Output Print one integer — the minimum possible value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r) after rearranging elements of b, taken modulo 998244353. Note that you should minimize the answer but not its remainder. Examples Input 5 1 8 7 2 4 9 7 2 9 3 Output 646 Input 1 1000000 1000000 Output 757402647 Input 2 1 3 4 2 Output 20
instruction
0
58,092
12
116,184
Tags: greedy, math, sortings Correct Solution: ``` import math import bisect import heapq from collections import defaultdict def egcd(a, b): if a == 0: return (b, 0, 1) else: g, x, y = egcd(b % a, a) return (g, y - (b // a) * x, x) def mulinv(b, n): g, x, _ = egcd(b, n) if g == 1: return x % n def isprime(n): for d in range(2, int(math.sqrt(n))+1): if n % d == 0: return False return True def argsort(ls): return sorted(range(len(ls)), key=ls.__getitem__) def f(p=0): if p == 1: return map(int, input().split()) elif p == 2: return list(map(int, input().split())) elif p == 3: return list(input()) else: return int(input()) n = f() a = f(2) b = sorted(f(2))[::-1] cl = [] for i in range(n): cl.append(a[i]*(i+1)*(n-i)) ind = argsort(cl) dl = [0]*n for i in range(n): dl[ind[i]]=i const = 998244353 res = 0 for i in range(n): res+=b[dl[i]]*cl[i] if res>const: res = res%const print(res) ```
output
1
58,092
12
116,185
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two arrays a and b, both of length n. Let's define a function f(l, r) = ∑_{l ≤ i ≤ r} a_i ⋅ b_i. Your task is to reorder the elements (choose an arbitrary order of elements) of the array b to minimize the value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r). Since the answer can be very large, you have to print it modulo 998244353. Note that you should minimize the answer but not its remainder. Input The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of elements in a and b. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^6), where a_i is the i-th element of a. The third line of the input contains n integers b_1, b_2, ..., b_n (1 ≤ b_j ≤ 10^6), where b_j is the j-th element of b. Output Print one integer — the minimum possible value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r) after rearranging elements of b, taken modulo 998244353. Note that you should minimize the answer but not its remainder. Examples Input 5 1 8 7 2 4 9 7 2 9 3 Output 646 Input 1 1000000 1000000 Output 757402647 Input 2 1 3 4 2 Output 20
instruction
0
58,093
12
116,186
Tags: greedy, math, sortings Correct Solution: ``` n = int(input()) a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] c = [] sum1 = 0 #for i in range(n): #sum1 += a[i] * b[i] #for i in range(n): #c.append(a[i] * (i+1) * (n - i)) #sum1 +=(c[i] * b[i]) for i in range(n): a[i] = a[i] * (i+1) * (n - i) a.sort() b.sort(reverse=True) for j in range(n): sum1 += a[j] * b[j] print(sum1%998244353) ```
output
1
58,093
12
116,187
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two arrays a and b, both of length n. Let's define a function f(l, r) = ∑_{l ≤ i ≤ r} a_i ⋅ b_i. Your task is to reorder the elements (choose an arbitrary order of elements) of the array b to minimize the value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r). Since the answer can be very large, you have to print it modulo 998244353. Note that you should minimize the answer but not its remainder. Input The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of elements in a and b. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^6), where a_i is the i-th element of a. The third line of the input contains n integers b_1, b_2, ..., b_n (1 ≤ b_j ≤ 10^6), where b_j is the j-th element of b. Output Print one integer — the minimum possible value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r) after rearranging elements of b, taken modulo 998244353. Note that you should minimize the answer but not its remainder. Examples Input 5 1 8 7 2 4 9 7 2 9 3 Output 646 Input 1 1000000 1000000 Output 757402647 Input 2 1 3 4 2 Output 20
instruction
0
58,094
12
116,188
Tags: greedy, math, sortings Correct Solution: ``` import sys from collections import defaultdict n=int(sys.stdin.readline()) a=list(map(int,sys.stdin.readline().split())) b=list(map(int,sys.stdin.readline().split())) mod=998244353 c=[] for i in range(n): left,right=i+1,n-i c.append([a[i]*left*right,i]) c.sort() b.sort() b.reverse() newb=[0 for _ in range(n)] for i in range(n): newb[c[i][1]]=b[i] ans=0 #print(a,'a') #print(newb,'newb') for i in range(n): left,right=i+1,(n-i) add=(left*right*a[i]*newb[i])%mod ans+=add ans=ans%mod print(ans%mod) ```
output
1
58,094
12
116,189
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two arrays a and b, both of length n. Let's define a function f(l, r) = ∑_{l ≤ i ≤ r} a_i ⋅ b_i. Your task is to reorder the elements (choose an arbitrary order of elements) of the array b to minimize the value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r). Since the answer can be very large, you have to print it modulo 998244353. Note that you should minimize the answer but not its remainder. Input The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of elements in a and b. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^6), where a_i is the i-th element of a. The third line of the input contains n integers b_1, b_2, ..., b_n (1 ≤ b_j ≤ 10^6), where b_j is the j-th element of b. Output Print one integer — the minimum possible value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r) after rearranging elements of b, taken modulo 998244353. Note that you should minimize the answer but not its remainder. Examples Input 5 1 8 7 2 4 9 7 2 9 3 Output 646 Input 1 1000000 1000000 Output 757402647 Input 2 1 3 4 2 Output 20
instruction
0
58,095
12
116,190
Tags: greedy, math, sortings Correct Solution: ``` N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) for i in range(N): A[i] = A[i]*(i+1)*(N-i) A.sort() B.sort() ans = 0 for i in range(N): ans = ans + (A[i]*B[N-i-1])%998244353 print(ans%998244353) ```
output
1
58,095
12
116,191
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two arrays a and b, both of length n. Let's define a function f(l, r) = ∑_{l ≤ i ≤ r} a_i ⋅ b_i. Your task is to reorder the elements (choose an arbitrary order of elements) of the array b to minimize the value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r). Since the answer can be very large, you have to print it modulo 998244353. Note that you should minimize the answer but not its remainder. Input The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of elements in a and b. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^6), where a_i is the i-th element of a. The third line of the input contains n integers b_1, b_2, ..., b_n (1 ≤ b_j ≤ 10^6), where b_j is the j-th element of b. Output Print one integer — the minimum possible value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r) after rearranging elements of b, taken modulo 998244353. Note that you should minimize the answer but not its remainder. Examples Input 5 1 8 7 2 4 9 7 2 9 3 Output 646 Input 1 1000000 1000000 Output 757402647 Input 2 1 3 4 2 Output 20 Submitted Solution: ``` n = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) x = [a[i]*(i+1)*(n-i) for i in range(n)] x.sort() b.sort(reverse = True) ans = 0 MOD = 998244353 for i in range(n): ans += (x[i]*b[i]) ans %= MOD print(ans) ```
instruction
0
58,096
12
116,192
Yes
output
1
58,096
12
116,193
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two arrays a and b, both of length n. Let's define a function f(l, r) = ∑_{l ≤ i ≤ r} a_i ⋅ b_i. Your task is to reorder the elements (choose an arbitrary order of elements) of the array b to minimize the value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r). Since the answer can be very large, you have to print it modulo 998244353. Note that you should minimize the answer but not its remainder. Input The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of elements in a and b. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^6), where a_i is the i-th element of a. The third line of the input contains n integers b_1, b_2, ..., b_n (1 ≤ b_j ≤ 10^6), where b_j is the j-th element of b. Output Print one integer — the minimum possible value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r) after rearranging elements of b, taken modulo 998244353. Note that you should minimize the answer but not its remainder. Examples Input 5 1 8 7 2 4 9 7 2 9 3 Output 646 Input 1 1000000 1000000 Output 757402647 Input 2 1 3 4 2 Output 20 Submitted Solution: ``` n = int(input()) m =998244353 a = list(map(int,input().split())) b = list(map(int,input().split())) for i in range(n): a[i]*=(n-i)*(i+1) a.sort() b.sort(reverse = True) ans = 0 for i in range(n): ans= ((ans%m) + ((b[i]%m)*(a[i]%m))%m)%m print(ans%m) ```
instruction
0
58,097
12
116,194
Yes
output
1
58,097
12
116,195
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two arrays a and b, both of length n. Let's define a function f(l, r) = ∑_{l ≤ i ≤ r} a_i ⋅ b_i. Your task is to reorder the elements (choose an arbitrary order of elements) of the array b to minimize the value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r). Since the answer can be very large, you have to print it modulo 998244353. Note that you should minimize the answer but not its remainder. Input The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of elements in a and b. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^6), where a_i is the i-th element of a. The third line of the input contains n integers b_1, b_2, ..., b_n (1 ≤ b_j ≤ 10^6), where b_j is the j-th element of b. Output Print one integer — the minimum possible value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r) after rearranging elements of b, taken modulo 998244353. Note that you should minimize the answer but not its remainder. Examples Input 5 1 8 7 2 4 9 7 2 9 3 Output 646 Input 1 1000000 1000000 Output 757402647 Input 2 1 3 4 2 Output 20 Submitted Solution: ``` MOD = 998244353 n = int(input()) a = [*map(int, input().split())] b = [*map(int, input().split())] for i in range(n): a[i] = (a[i] * (n - i) * (i + 1)) a.sort(reverse = True) b.sort() res = 0 for i in range(n): a[i] %= MOD res += (a[i] * b[i]) % MOD res %= MOD print(res) ```
instruction
0
58,098
12
116,196
Yes
output
1
58,098
12
116,197
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two arrays a and b, both of length n. Let's define a function f(l, r) = ∑_{l ≤ i ≤ r} a_i ⋅ b_i. Your task is to reorder the elements (choose an arbitrary order of elements) of the array b to minimize the value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r). Since the answer can be very large, you have to print it modulo 998244353. Note that you should minimize the answer but not its remainder. Input The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of elements in a and b. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^6), where a_i is the i-th element of a. The third line of the input contains n integers b_1, b_2, ..., b_n (1 ≤ b_j ≤ 10^6), where b_j is the j-th element of b. Output Print one integer — the minimum possible value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r) after rearranging elements of b, taken modulo 998244353. Note that you should minimize the answer but not its remainder. Examples Input 5 1 8 7 2 4 9 7 2 9 3 Output 646 Input 1 1000000 1000000 Output 757402647 Input 2 1 3 4 2 Output 20 Submitted Solution: ``` import sys n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) for i in range(n): a[i] *= (i+1)*(n-i) a = sorted(a) b = sorted(b)[::-1] s = 0 for i in range(n): s = (s+a[i]*b[i])%998244353 print(s) ```
instruction
0
58,099
12
116,198
Yes
output
1
58,099
12
116,199
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two arrays a and b, both of length n. Let's define a function f(l, r) = ∑_{l ≤ i ≤ r} a_i ⋅ b_i. Your task is to reorder the elements (choose an arbitrary order of elements) of the array b to minimize the value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r). Since the answer can be very large, you have to print it modulo 998244353. Note that you should minimize the answer but not its remainder. Input The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of elements in a and b. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^6), where a_i is the i-th element of a. The third line of the input contains n integers b_1, b_2, ..., b_n (1 ≤ b_j ≤ 10^6), where b_j is the j-th element of b. Output Print one integer — the minimum possible value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r) after rearranging elements of b, taken modulo 998244353. Note that you should minimize the answer but not its remainder. Examples Input 5 1 8 7 2 4 9 7 2 9 3 Output 646 Input 1 1000000 1000000 Output 757402647 Input 2 1 3 4 2 Output 20 Submitted Solution: ``` from sys import stdin from sys import stdout MOD = 998244353 n = int(stdin.readline()) a = list(map(int, stdin.readline().split())) b = list(map(int, stdin.readline().split())) val = [0]*n b.sort() b.reverse() for i in range(n): val[i] = a[i]*(i+1)*(n-i) val.sort() ans = 0 for i in range(n): ans+=((val[i]%MOD)*b[i])%MOD print(ans) ```
instruction
0
58,100
12
116,200
No
output
1
58,100
12
116,201
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two arrays a and b, both of length n. Let's define a function f(l, r) = ∑_{l ≤ i ≤ r} a_i ⋅ b_i. Your task is to reorder the elements (choose an arbitrary order of elements) of the array b to minimize the value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r). Since the answer can be very large, you have to print it modulo 998244353. Note that you should minimize the answer but not its remainder. Input The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of elements in a and b. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^6), where a_i is the i-th element of a. The third line of the input contains n integers b_1, b_2, ..., b_n (1 ≤ b_j ≤ 10^6), where b_j is the j-th element of b. Output Print one integer — the minimum possible value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r) after rearranging elements of b, taken modulo 998244353. Note that you should minimize the answer but not its remainder. Examples Input 5 1 8 7 2 4 9 7 2 9 3 Output 646 Input 1 1000000 1000000 Output 757402647 Input 2 1 3 4 2 Output 20 Submitted Solution: ``` #------------------------template--------------------------# import os import sys # from math import * from collections import * # from fractions import * # from heapq import* from bisect import * from io import BytesIO, IOBase def vsInput(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') 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") ALPHA='abcdefghijklmnopqrstuvwxyz' M= 998244353 EPS=1e-6 def Ceil(a,b): return a//b+int(a%b>0) def value():return tuple(map(int,input().split())) def array():return [int(i) for i in input().split()] def Int():return int(input()) def Str():return input() def arrayS():return [i for i in input().split()] #-------------------------code---------------------------# # vsInput() n = Int() a = array() b = array() b.sort(reverse=True) k = 0 extra = 0 for i in range(n): here = (i+1)*(n-i) a[i] = ( a[i] * here + M )%M # a[i] = here a.sort() ans = 0 # print(a) # print(b) for i in range(n): ans = (ans + (a[i]%M * b[i]%M ) %M + M)%M print(ans) ```
instruction
0
58,101
12
116,202
No
output
1
58,101
12
116,203
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two arrays a and b, both of length n. Let's define a function f(l, r) = ∑_{l ≤ i ≤ r} a_i ⋅ b_i. Your task is to reorder the elements (choose an arbitrary order of elements) of the array b to minimize the value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r). Since the answer can be very large, you have to print it modulo 998244353. Note that you should minimize the answer but not its remainder. Input The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of elements in a and b. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^6), where a_i is the i-th element of a. The third line of the input contains n integers b_1, b_2, ..., b_n (1 ≤ b_j ≤ 10^6), where b_j is the j-th element of b. Output Print one integer — the minimum possible value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r) after rearranging elements of b, taken modulo 998244353. Note that you should minimize the answer but not its remainder. Examples Input 5 1 8 7 2 4 9 7 2 9 3 Output 646 Input 1 1000000 1000000 Output 757402647 Input 2 1 3 4 2 Output 20 Submitted Solution: ``` mod=998244353 n = int(input()) a = list(map(int,input().split())) a = [[a[i],i] for i in range(n)] a.sort() b = sorted(map(int,input().split()),reverse = True) res=[0]*n for i in range(n): res[a[i][1]] = (a[i][0]*b[i])%mod i=n j=1 ans=0 for _ in range(n): ans+=(res[_]*i*j)%mod i-=1 j+=1 print(ans) ```
instruction
0
58,102
12
116,204
No
output
1
58,102
12
116,205
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two arrays a and b, both of length n. Let's define a function f(l, r) = ∑_{l ≤ i ≤ r} a_i ⋅ b_i. Your task is to reorder the elements (choose an arbitrary order of elements) of the array b to minimize the value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r). Since the answer can be very large, you have to print it modulo 998244353. Note that you should minimize the answer but not its remainder. Input The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of elements in a and b. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^6), where a_i is the i-th element of a. The third line of the input contains n integers b_1, b_2, ..., b_n (1 ≤ b_j ≤ 10^6), where b_j is the j-th element of b. Output Print one integer — the minimum possible value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r) after rearranging elements of b, taken modulo 998244353. Note that you should minimize the answer but not its remainder. Examples Input 5 1 8 7 2 4 9 7 2 9 3 Output 646 Input 1 1000000 1000000 Output 757402647 Input 2 1 3 4 2 Output 20 Submitted Solution: ``` # https://codeforces.com/contest/1165/problem/E n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) for i in range(n): a[i] *= (i+1)*(n-i) a.sort() b.sort(reverse=True) ans = [x*y for x, y in zip(a, b)] print(sum(ans)) ```
instruction
0
58,103
12
116,206
No
output
1
58,103
12
116,207
Provide tags and a correct Python 3 solution for this coding contest problem. Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero ( < 0). 2. The product of all numbers in the second set is greater than zero ( > 0). 3. The product of all numbers in the third set is equal to zero. 4. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array. Input The first line of the input contains integer n (3 ≤ n ≤ 100). The second line contains n space-separated distinct integers a1, a2, ..., an (|ai| ≤ 103) — the array elements. Output In the first line print integer n1 (n1 > 0) — the number of elements in the first set. Then print n1 numbers — the elements that got to the first set. In the next line print integer n2 (n2 > 0) — the number of elements in the second set. Then print n2 numbers — the elements that got to the second set. In the next line print integer n3 (n3 > 0) — the number of elements in the third set. Then print n3 numbers — the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. Examples Input 3 -1 2 0 Output 1 -1 1 2 1 0 Input 4 -1 -2 -3 0 Output 1 -1 2 -3 -2 1 0
instruction
0
58,331
12
116,662
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` x=int(input()) y=list(map(int,input().split())) a,b,c=[],[],[] for i in y: if(i<0): a.append(i) elif(i>0): b.append(i) else: c.append(i) if(len(b)==0): b.append(a[0]) b.append(a[1]) a.remove(a[0]) a.remove(a[0]) if(len(a)%2==0): c.append(a[0]) a.remove(a[0]) print(len(a),*a) print(len(b),*b) print(len(c),*c) ```
output
1
58,331
12
116,663
Provide tags and a correct Python 3 solution for this coding contest problem. Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero ( < 0). 2. The product of all numbers in the second set is greater than zero ( > 0). 3. The product of all numbers in the third set is equal to zero. 4. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array. Input The first line of the input contains integer n (3 ≤ n ≤ 100). The second line contains n space-separated distinct integers a1, a2, ..., an (|ai| ≤ 103) — the array elements. Output In the first line print integer n1 (n1 > 0) — the number of elements in the first set. Then print n1 numbers — the elements that got to the first set. In the next line print integer n2 (n2 > 0) — the number of elements in the second set. Then print n2 numbers — the elements that got to the second set. In the next line print integer n3 (n3 > 0) — the number of elements in the third set. Then print n3 numbers — the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. Examples Input 3 -1 2 0 Output 1 -1 1 2 1 0 Input 4 -1 -2 -3 0 Output 1 -1 2 -3 -2 1 0
instruction
0
58,332
12
116,664
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` n = int(input()) a = list(map(int,input().split())) neg, pos = 0,0 ans = [] for i in a: if i > 0 and pos == 0: pos = i elif i < 0 and neg == 0: neg = i else: ans.append(i) print(1,neg) if pos > 0: print(1,pos) print(n-2,*ans) else: print(2,*[val for val in ans if val < 0][:2]) cnt = 2 print(n-3, end=' ') for i in ans: if i < 0: if cnt > 0: cnt -= 1 continue print(i, end = " ") ```
output
1
58,332
12
116,665
Provide tags and a correct Python 3 solution for this coding contest problem. Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero ( < 0). 2. The product of all numbers in the second set is greater than zero ( > 0). 3. The product of all numbers in the third set is equal to zero. 4. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array. Input The first line of the input contains integer n (3 ≤ n ≤ 100). The second line contains n space-separated distinct integers a1, a2, ..., an (|ai| ≤ 103) — the array elements. Output In the first line print integer n1 (n1 > 0) — the number of elements in the first set. Then print n1 numbers — the elements that got to the first set. In the next line print integer n2 (n2 > 0) — the number of elements in the second set. Then print n2 numbers — the elements that got to the second set. In the next line print integer n3 (n3 > 0) — the number of elements in the third set. Then print n3 numbers — the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. Examples Input 3 -1 2 0 Output 1 -1 1 2 1 0 Input 4 -1 -2 -3 0 Output 1 -1 2 -3 -2 1 0
instruction
0
58,333
12
116,666
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` neg = [] pos = [] input() numbers = list(map(int, input().split())) for num in numbers: if num < 0: neg.append(num) elif num > 0: pos.append(num) res_pos = [] res_neg = [] res_zer = [0] if len(pos) == 0: res_pos.append(neg[0]) res_pos.append(neg[1]) res_neg.append(neg[2]) for num in neg[3:]: res_zer.append(num) else: res_pos.append(pos[0]) for num in pos[1:]: res_zer.append(num) res_neg.append(neg[0]) for num in neg[1:]: res_zer.append(num) print(len(res_neg), end=' ') for num in res_neg: print(num, end=' ') print('') print(len(res_pos), end=' ') for num in res_pos: print(num, end=' ') print('') print(len(res_zer), end=' ') for num in res_zer: print(num, end=' ') ```
output
1
58,333
12
116,667
Provide tags and a correct Python 3 solution for this coding contest problem. Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero ( < 0). 2. The product of all numbers in the second set is greater than zero ( > 0). 3. The product of all numbers in the third set is equal to zero. 4. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array. Input The first line of the input contains integer n (3 ≤ n ≤ 100). The second line contains n space-separated distinct integers a1, a2, ..., an (|ai| ≤ 103) — the array elements. Output In the first line print integer n1 (n1 > 0) — the number of elements in the first set. Then print n1 numbers — the elements that got to the first set. In the next line print integer n2 (n2 > 0) — the number of elements in the second set. Then print n2 numbers — the elements that got to the second set. In the next line print integer n3 (n3 > 0) — the number of elements in the third set. Then print n3 numbers — the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. Examples Input 3 -1 2 0 Output 1 -1 1 2 1 0 Input 4 -1 -2 -3 0 Output 1 -1 2 -3 -2 1 0
instruction
0
58,334
12
116,668
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` # Name: Sachdev Hitesh # College : GLSICA n = int(input()) l = list(map(int,input().split())) ne,po,ze = [],[],[] for a in l: if a < 0: if len(ne) == 0: ne.append(a) elif len(po) == 0 or (len(po) == 1 and po[0] < 0): po.append(a) else: ze.append(a) elif 0 < a: if len(po) == 0: po.append(a) elif len(po) == 1 and po[0] < 0: ze.append(po[0]) po[0] = a else: ze.append(a) else: ze.append(a) print(len(ne), ' '.join(map(str,ne))) print(len(po), ' '.join(map(str,po))) print(len(ze), ' '.join(map(str,ze))) ```
output
1
58,334
12
116,669
Provide tags and a correct Python 3 solution for this coding contest problem. Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero ( < 0). 2. The product of all numbers in the second set is greater than zero ( > 0). 3. The product of all numbers in the third set is equal to zero. 4. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array. Input The first line of the input contains integer n (3 ≤ n ≤ 100). The second line contains n space-separated distinct integers a1, a2, ..., an (|ai| ≤ 103) — the array elements. Output In the first line print integer n1 (n1 > 0) — the number of elements in the first set. Then print n1 numbers — the elements that got to the first set. In the next line print integer n2 (n2 > 0) — the number of elements in the second set. Then print n2 numbers — the elements that got to the second set. In the next line print integer n3 (n3 > 0) — the number of elements in the third set. Then print n3 numbers — the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. Examples Input 3 -1 2 0 Output 1 -1 1 2 1 0 Input 4 -1 -2 -3 0 Output 1 -1 2 -3 -2 1 0
instruction
0
58,335
12
116,670
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) positive = [] negative = [] zero = [] for i in range(0,n): if a[i] == 0: zero.append(a[i]) if a[i] > 0: positive.append(a[i]) if a[i] < 0: negative.append(a[i]) if len(negative)%2 != 0: m = negative[0] x = [m] del negative[0] y = positive + negative z = zero else: m = negative[0] x = [m] n = negative[1] p = [n] z = zero + p del negative[0] del negative[0] y = positive + negative x.insert(0, 1) y.insert (0, len(y)) z.insert(0, len(z)) print(*x) print(*y) print(*z) ```
output
1
58,335
12
116,671
Provide tags and a correct Python 3 solution for this coding contest problem. Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero ( < 0). 2. The product of all numbers in the second set is greater than zero ( > 0). 3. The product of all numbers in the third set is equal to zero. 4. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array. Input The first line of the input contains integer n (3 ≤ n ≤ 100). The second line contains n space-separated distinct integers a1, a2, ..., an (|ai| ≤ 103) — the array elements. Output In the first line print integer n1 (n1 > 0) — the number of elements in the first set. Then print n1 numbers — the elements that got to the first set. In the next line print integer n2 (n2 > 0) — the number of elements in the second set. Then print n2 numbers — the elements that got to the second set. In the next line print integer n3 (n3 > 0) — the number of elements in the third set. Then print n3 numbers — the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. Examples Input 3 -1 2 0 Output 1 -1 1 2 1 0 Input 4 -1 -2 -3 0 Output 1 -1 2 -3 -2 1 0
instruction
0
58,336
12
116,672
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) pos1 = -1 neg1, neg2, neg3 = -1, -1, -1 for i in range(len(a)): if a[i] > 0: pos1 = i elif a[i] < 0: if neg1 == -1: neg1 = i elif neg2 == -1: neg2 = i else: neg3 = i if pos1 != -1: print(1, a[neg1]) # Tập hợp < 0. Chỉ cần đúng 1 số âm thì tích sẽ âm print(1, a[pos1]) # Tập hợp > 0. Chỉ cần đúng 1 số dương thì tích sẽ dương print(n - 2, end = ' ') for i in range(n): # In tất cả các số còn lại trong mảng a, ngoại trừ pos1 và neg1 if i != neg1 and i != pos1: print(a[i], end = ' ') else: print(1, a[neg1]) print(2, a[neg2], a[neg3]) # Dùng hai số âm print(n - 3, end = ' ') for i in range(n): if i not in [neg1, neg2, neg3]: print(a[i], end = ' ') ```
output
1
58,336
12
116,673
Provide tags and a correct Python 3 solution for this coding contest problem. Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero ( < 0). 2. The product of all numbers in the second set is greater than zero ( > 0). 3. The product of all numbers in the third set is equal to zero. 4. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array. Input The first line of the input contains integer n (3 ≤ n ≤ 100). The second line contains n space-separated distinct integers a1, a2, ..., an (|ai| ≤ 103) — the array elements. Output In the first line print integer n1 (n1 > 0) — the number of elements in the first set. Then print n1 numbers — the elements that got to the first set. In the next line print integer n2 (n2 > 0) — the number of elements in the second set. Then print n2 numbers — the elements that got to the second set. In the next line print integer n3 (n3 > 0) — the number of elements in the third set. Then print n3 numbers — the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. Examples Input 3 -1 2 0 Output 1 -1 1 2 1 0 Input 4 -1 -2 -3 0 Output 1 -1 2 -3 -2 1 0
instruction
0
58,337
12
116,674
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` n=int(input()) a=list(map(int,input().split())) c=0 d=0 l1=[] l2=[] l3=[] for i in a: if i<0: c+=1 l1.append(i) if i==0: l2.append(i) if i>0: l3.append(i) if c%2==0: l2.append(l1[0]) l1=l1[1:] if l3==[]: l3.append(l1[0]) l3.append(l1[1]) l1=l1[2:] print(len(l1),end=" ") print(*l1) print(len(l3),end=" ") print(*l3) print(len(l2),end=" ") print(*l2) ```
output
1
58,337
12
116,675
Provide tags and a correct Python 3 solution for this coding contest problem. Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero ( < 0). 2. The product of all numbers in the second set is greater than zero ( > 0). 3. The product of all numbers in the third set is equal to zero. 4. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array. Input The first line of the input contains integer n (3 ≤ n ≤ 100). The second line contains n space-separated distinct integers a1, a2, ..., an (|ai| ≤ 103) — the array elements. Output In the first line print integer n1 (n1 > 0) — the number of elements in the first set. Then print n1 numbers — the elements that got to the first set. In the next line print integer n2 (n2 > 0) — the number of elements in the second set. Then print n2 numbers — the elements that got to the second set. In the next line print integer n3 (n3 > 0) — the number of elements in the third set. Then print n3 numbers — the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. Examples Input 3 -1 2 0 Output 1 -1 1 2 1 0 Input 4 -1 -2 -3 0 Output 1 -1 2 -3 -2 1 0
instruction
0
58,338
12
116,676
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` n = int(input()) lst = [int(i) for i in input().split()] a = [i for i in lst if i < 0] b = [i for i in lst if i > 0] c = [i for i in lst if i == 0] if len(b) == 0: b, a = a[: 2], a[2: ] c += a[1:] a = a[0] print(1, a) print(len(b), ' '.join(str(i) for i in b)) print(len(c), ' '.join(str(i) for i in c)) ```
output
1
58,338
12
116,677
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero ( < 0). 2. The product of all numbers in the second set is greater than zero ( > 0). 3. The product of all numbers in the third set is equal to zero. 4. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array. Input The first line of the input contains integer n (3 ≤ n ≤ 100). The second line contains n space-separated distinct integers a1, a2, ..., an (|ai| ≤ 103) — the array elements. Output In the first line print integer n1 (n1 > 0) — the number of elements in the first set. Then print n1 numbers — the elements that got to the first set. In the next line print integer n2 (n2 > 0) — the number of elements in the second set. Then print n2 numbers — the elements that got to the second set. In the next line print integer n3 (n3 > 0) — the number of elements in the third set. Then print n3 numbers — the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. Examples Input 3 -1 2 0 Output 1 -1 1 2 1 0 Input 4 -1 -2 -3 0 Output 1 -1 2 -3 -2 1 0 Submitted Solution: ``` st,nd,rd=[],[],[];input();nums=sorted(input().split()) if int(nums[-1])>0: st.append(nums[0]);nd.append(nums[-1]) for i in nums[1:-1]: rd.append(i) else: st.append(nums[0]);nd.append(nums[1]);nd.append(nums[2]); for i in nums[3:]: rd.append(i) print(str(len(st))+' '+' '.join(st)+'\n'+str(len(nd))+' '+' '.join(nd)+'\n'+str(len(rd))+' '+ ' '.join(rd)) ```
instruction
0
58,339
12
116,678
Yes
output
1
58,339
12
116,679
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero ( < 0). 2. The product of all numbers in the second set is greater than zero ( > 0). 3. The product of all numbers in the third set is equal to zero. 4. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array. Input The first line of the input contains integer n (3 ≤ n ≤ 100). The second line contains n space-separated distinct integers a1, a2, ..., an (|ai| ≤ 103) — the array elements. Output In the first line print integer n1 (n1 > 0) — the number of elements in the first set. Then print n1 numbers — the elements that got to the first set. In the next line print integer n2 (n2 > 0) — the number of elements in the second set. Then print n2 numbers — the elements that got to the second set. In the next line print integer n3 (n3 > 0) — the number of elements in the third set. Then print n3 numbers — the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. Examples Input 3 -1 2 0 Output 1 -1 1 2 1 0 Input 4 -1 -2 -3 0 Output 1 -1 2 -3 -2 1 0 Submitted Solution: ``` t=int(input()) a=list(map(int,input().split())) b=[] c=[] d=[] for i in a: if (i<0): b.append(i) a.remove(i) break for i in a: if (i>0): c.append(i) a.remove(i) break a.sort() if (len(c)==0): c.append(a[0]) c.append(a[1]) a.pop(0) a.pop(0) print(len(b),*b) print(len(c),*c) print(len(a),*a) ```
instruction
0
58,340
12
116,680
Yes
output
1
58,340
12
116,681
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero ( < 0). 2. The product of all numbers in the second set is greater than zero ( > 0). 3. The product of all numbers in the third set is equal to zero. 4. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array. Input The first line of the input contains integer n (3 ≤ n ≤ 100). The second line contains n space-separated distinct integers a1, a2, ..., an (|ai| ≤ 103) — the array elements. Output In the first line print integer n1 (n1 > 0) — the number of elements in the first set. Then print n1 numbers — the elements that got to the first set. In the next line print integer n2 (n2 > 0) — the number of elements in the second set. Then print n2 numbers — the elements that got to the second set. In the next line print integer n3 (n3 > 0) — the number of elements in the third set. Then print n3 numbers — the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. Examples Input 3 -1 2 0 Output 1 -1 1 2 1 0 Input 4 -1 -2 -3 0 Output 1 -1 2 -3 -2 1 0 Submitted Solution: ``` n=int(input()) ls=list(map(int,input().split())) ls.sort() def index(ls,n): for i in range(n): if ls[i]==0: return i soduong=n-index(ls,n)-1 if soduong>0: print(1,ls[0]) print(1,ls[len(ls)-1]) print(len(ls)-2,end=' ') i=1 while i<len(ls)-1: print(ls[i],end=' ') i+=1 else: print(1,ls[0]) print(2,ls[1],ls[2]) i=3 print(len(ls)-3,end=' ') while i<len(ls): print(ls[i],end=' ') i+=1 ```
instruction
0
58,341
12
116,682
Yes
output
1
58,341
12
116,683