message
stringlengths
2
20.2k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
757
108k
cluster
float64
4
4
__index_level_0__
int64
1.51k
217k
Provide a correct Python 3 solution for this coding contest problem. Welcome to PC Koshien, players. Physical condition management is important to participate in the event. It is said that at the turn of the season when the temperature fluctuates greatly, it puts a strain on the body and it is easy to catch a cold. The day you should be careful about is the day when the difference between the maximum temperature and the minimum temperature is the largest. When the maximum and minimum temperatures of a day are given for 7 days, create a program that outputs the value obtained by subtracting the minimum temperature from the maximum temperature for each day. input Input data is given in the following format. a1 b1 a2 b2 :: a7 b7 The input consists of 7 lines, and line i is given an integer representing the maximum temperature ai (-40 ≤ ai ≤ 40) and the minimum temperature bi (-40 ≤ bi ≤ 40) on day i. On all days, the maximum temperature ai is always above the minimum temperature bi. output Output the temperature difference for 7 days in 7 lines. Example Input 30 19 39 20 19 18 25 20 22 21 23 10 10 -10 Output 11 19 1 5 1 13 20
instruction
0
46,976
4
93,952
"Correct Solution: ``` i=0 for i in range(7): a,b=map(int,input().split()) print(a-b) i+=1 ```
output
1
46,976
4
93,953
Provide a correct Python 3 solution for this coding contest problem. Welcome to PC Koshien, players. Physical condition management is important to participate in the event. It is said that at the turn of the season when the temperature fluctuates greatly, it puts a strain on the body and it is easy to catch a cold. The day you should be careful about is the day when the difference between the maximum temperature and the minimum temperature is the largest. When the maximum and minimum temperatures of a day are given for 7 days, create a program that outputs the value obtained by subtracting the minimum temperature from the maximum temperature for each day. input Input data is given in the following format. a1 b1 a2 b2 :: a7 b7 The input consists of 7 lines, and line i is given an integer representing the maximum temperature ai (-40 ≤ ai ≤ 40) and the minimum temperature bi (-40 ≤ bi ≤ 40) on day i. On all days, the maximum temperature ai is always above the minimum temperature bi. output Output the temperature difference for 7 days in 7 lines. Example Input 30 19 39 20 19 18 25 20 22 21 23 10 10 -10 Output 11 19 1 5 1 13 20
instruction
0
46,977
4
93,954
"Correct Solution: ``` for i in range(7): H,L=map(int,input().split()) print(H-L) ```
output
1
46,977
4
93,955
Provide a correct Python 3 solution for this coding contest problem. Welcome to PC Koshien, players. Physical condition management is important to participate in the event. It is said that at the turn of the season when the temperature fluctuates greatly, it puts a strain on the body and it is easy to catch a cold. The day you should be careful about is the day when the difference between the maximum temperature and the minimum temperature is the largest. When the maximum and minimum temperatures of a day are given for 7 days, create a program that outputs the value obtained by subtracting the minimum temperature from the maximum temperature for each day. input Input data is given in the following format. a1 b1 a2 b2 :: a7 b7 The input consists of 7 lines, and line i is given an integer representing the maximum temperature ai (-40 ≤ ai ≤ 40) and the minimum temperature bi (-40 ≤ bi ≤ 40) on day i. On all days, the maximum temperature ai is always above the minimum temperature bi. output Output the temperature difference for 7 days in 7 lines. Example Input 30 19 39 20 19 18 25 20 22 21 23 10 10 -10 Output 11 19 1 5 1 13 20
instruction
0
46,978
4
93,956
"Correct Solution: ``` i=1 while i<8: a_i,b_i=map(int,input().split()) x=a_i-b_i print(x) i=i+1 ```
output
1
46,978
4
93,957
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Welcome to PC Koshien, players. Physical condition management is important to participate in the event. It is said that at the turn of the season when the temperature fluctuates greatly, it puts a strain on the body and it is easy to catch a cold. The day you should be careful about is the day when the difference between the maximum temperature and the minimum temperature is the largest. When the maximum and minimum temperatures of a day are given for 7 days, create a program that outputs the value obtained by subtracting the minimum temperature from the maximum temperature for each day. input Input data is given in the following format. a1 b1 a2 b2 :: a7 b7 The input consists of 7 lines, and line i is given an integer representing the maximum temperature ai (-40 ≤ ai ≤ 40) and the minimum temperature bi (-40 ≤ bi ≤ 40) on day i. On all days, the maximum temperature ai is always above the minimum temperature bi. output Output the temperature difference for 7 days in 7 lines. Example Input 30 19 39 20 19 18 25 20 22 21 23 10 10 -10 Output 11 19 1 5 1 13 20 Submitted Solution: ``` for i in range(7): ai,bi=map(int,input().split()) if ai>=bi: print(ai-bi) if ai<bi: print(ai-bi) ```
instruction
0
46,979
4
93,958
Yes
output
1
46,979
4
93,959
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Welcome to PC Koshien, players. Physical condition management is important to participate in the event. It is said that at the turn of the season when the temperature fluctuates greatly, it puts a strain on the body and it is easy to catch a cold. The day you should be careful about is the day when the difference between the maximum temperature and the minimum temperature is the largest. When the maximum and minimum temperatures of a day are given for 7 days, create a program that outputs the value obtained by subtracting the minimum temperature from the maximum temperature for each day. input Input data is given in the following format. a1 b1 a2 b2 :: a7 b7 The input consists of 7 lines, and line i is given an integer representing the maximum temperature ai (-40 ≤ ai ≤ 40) and the minimum temperature bi (-40 ≤ bi ≤ 40) on day i. On all days, the maximum temperature ai is always above the minimum temperature bi. output Output the temperature difference for 7 days in 7 lines. Example Input 30 19 39 20 19 18 25 20 22 21 23 10 10 -10 Output 11 19 1 5 1 13 20 Submitted Solution: ``` for i in range(7): a,b=(int(x) for x in input().split()) print(a-b) ```
instruction
0
46,980
4
93,960
Yes
output
1
46,980
4
93,961
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Welcome to PC Koshien, players. Physical condition management is important to participate in the event. It is said that at the turn of the season when the temperature fluctuates greatly, it puts a strain on the body and it is easy to catch a cold. The day you should be careful about is the day when the difference between the maximum temperature and the minimum temperature is the largest. When the maximum and minimum temperatures of a day are given for 7 days, create a program that outputs the value obtained by subtracting the minimum temperature from the maximum temperature for each day. input Input data is given in the following format. a1 b1 a2 b2 :: a7 b7 The input consists of 7 lines, and line i is given an integer representing the maximum temperature ai (-40 ≤ ai ≤ 40) and the minimum temperature bi (-40 ≤ bi ≤ 40) on day i. On all days, the maximum temperature ai is always above the minimum temperature bi. output Output the temperature difference for 7 days in 7 lines. Example Input 30 19 39 20 19 18 25 20 22 21 23 10 10 -10 Output 11 19 1 5 1 13 20 Submitted Solution: ``` while True: try: a=list(map(int,input().split())) print(a[0]-a[1]) except: break; ```
instruction
0
46,981
4
93,962
Yes
output
1
46,981
4
93,963
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Welcome to PC Koshien, players. Physical condition management is important to participate in the event. It is said that at the turn of the season when the temperature fluctuates greatly, it puts a strain on the body and it is easy to catch a cold. The day you should be careful about is the day when the difference between the maximum temperature and the minimum temperature is the largest. When the maximum and minimum temperatures of a day are given for 7 days, create a program that outputs the value obtained by subtracting the minimum temperature from the maximum temperature for each day. input Input data is given in the following format. a1 b1 a2 b2 :: a7 b7 The input consists of 7 lines, and line i is given an integer representing the maximum temperature ai (-40 ≤ ai ≤ 40) and the minimum temperature bi (-40 ≤ bi ≤ 40) on day i. On all days, the maximum temperature ai is always above the minimum temperature bi. output Output the temperature difference for 7 days in 7 lines. Example Input 30 19 39 20 19 18 25 20 22 21 23 10 10 -10 Output 11 19 1 5 1 13 20 Submitted Solution: ``` a1, b1 = map(int,input().split()) a2, b2 = map(int,input().split()) a3, b3 = map(int,input().split()) a4, b4 = map(int,input().split()) a5, b5 = map(int,input().split()) a6, b6 = map(int,input().split()) a7, b7 = map(int,input().split()) def f(x,y): print(int(x-y)) f(a1,b1) f(a2,b2) f(a3,b3) f(a4,b4) f(a5,b5) f(a6,b6) f(a7,b7) ```
instruction
0
46,982
4
93,964
Yes
output
1
46,982
4
93,965
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Welcome to PC Koshien, players. Physical condition management is important to participate in the event. It is said that at the turn of the season when the temperature fluctuates greatly, it puts a strain on the body and it is easy to catch a cold. The day you should be careful about is the day when the difference between the maximum temperature and the minimum temperature is the largest. When the maximum and minimum temperatures of a day are given for 7 days, create a program that outputs the value obtained by subtracting the minimum temperature from the maximum temperature for each day. input Input data is given in the following format. a1 b1 a2 b2 :: a7 b7 The input consists of 7 lines, and line i is given an integer representing the maximum temperature ai (-40 ≤ ai ≤ 40) and the minimum temperature bi (-40 ≤ bi ≤ 40) on day i. On all days, the maximum temperature ai is always above the minimum temperature bi. output Output the temperature difference for 7 days in 7 lines. Example Input 30 19 39 20 19 18 25 20 22 21 23 10 10 -10 Output 11 19 1 5 1 13 20 Submitted Solution: ``` for i in range(0,7): a,b=map(int,input(),split()) print(a-b) ```
instruction
0
46,983
4
93,966
No
output
1
46,983
4
93,967
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Welcome to PC Koshien, players. Physical condition management is important to participate in the event. It is said that at the turn of the season when the temperature fluctuates greatly, it puts a strain on the body and it is easy to catch a cold. The day you should be careful about is the day when the difference between the maximum temperature and the minimum temperature is the largest. When the maximum and minimum temperatures of a day are given for 7 days, create a program that outputs the value obtained by subtracting the minimum temperature from the maximum temperature for each day. input Input data is given in the following format. a1 b1 a2 b2 :: a7 b7 The input consists of 7 lines, and line i is given an integer representing the maximum temperature ai (-40 ≤ ai ≤ 40) and the minimum temperature bi (-40 ≤ bi ≤ 40) on day i. On all days, the maximum temperature ai is always above the minimum temperature bi. output Output the temperature difference for 7 days in 7 lines. Example Input 30 19 39 20 19 18 25 20 22 21 23 10 10 -10 Output 11 19 1 5 1 13 20 Submitted Solution: ``` for i in range(7): ls = list(map(int, input().split())) if max(ls) > 0 and min(ls) > 0: print(max(ls) - min(ls)) elif max(ls) > 0 and min(ls) < 0: print(max(ls) + min(ls)) elif max(ls) < 0 and min(ls) < 0: print(abs(max(ls)) - abs(min(ls))) ```
instruction
0
46,984
4
93,968
No
output
1
46,984
4
93,969
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Welcome to PC Koshien, players. Physical condition management is important to participate in the event. It is said that at the turn of the season when the temperature fluctuates greatly, it puts a strain on the body and it is easy to catch a cold. The day you should be careful about is the day when the difference between the maximum temperature and the minimum temperature is the largest. When the maximum and minimum temperatures of a day are given for 7 days, create a program that outputs the value obtained by subtracting the minimum temperature from the maximum temperature for each day. input Input data is given in the following format. a1 b1 a2 b2 :: a7 b7 The input consists of 7 lines, and line i is given an integer representing the maximum temperature ai (-40 ≤ ai ≤ 40) and the minimum temperature bi (-40 ≤ bi ≤ 40) on day i. On all days, the maximum temperature ai is always above the minimum temperature bi. output Output the temperature difference for 7 days in 7 lines. Example Input 30 19 39 20 19 18 25 20 22 21 23 10 10 -10 Output 11 19 1 5 1 13 20 Submitted Solution: ``` for i in range(0,7) a,b=map(int,input(),split()) print(a-b) ```
instruction
0
46,985
4
93,970
No
output
1
46,985
4
93,971
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Welcome to PC Koshien, players. Physical condition management is important to participate in the event. It is said that at the turn of the season when the temperature fluctuates greatly, it puts a strain on the body and it is easy to catch a cold. The day you should be careful about is the day when the difference between the maximum temperature and the minimum temperature is the largest. When the maximum and minimum temperatures of a day are given for 7 days, create a program that outputs the value obtained by subtracting the minimum temperature from the maximum temperature for each day. input Input data is given in the following format. a1 b1 a2 b2 :: a7 b7 The input consists of 7 lines, and line i is given an integer representing the maximum temperature ai (-40 ≤ ai ≤ 40) and the minimum temperature bi (-40 ≤ bi ≤ 40) on day i. On all days, the maximum temperature ai is always above the minimum temperature bi. output Output the temperature difference for 7 days in 7 lines. Example Input 30 19 39 20 19 18 25 20 22 21 23 10 10 -10 Output 11 19 1 5 1 13 20 Submitted Solution: ``` try: while True: a,b=map(int,input().split()) if a-b<=a: print(a+b) else: print(a-b) except: pass ```
instruction
0
46,986
4
93,972
No
output
1
46,986
4
93,973
Provide tags and a correct Python 3 solution for this coding contest problem. Levian works as an accountant in a large company. Levian knows how much the company has earned in each of the n consecutive months — in the i-th month the company had income equal to a_i (positive income means profit, negative income means loss, zero income means no change). Because of the general self-isolation, the first ⌈ n/2 ⌉ months income might have been completely unstable, but then everything stabilized and for the last ⌊ n/2 ⌋ months the income was the same. Levian decided to tell the directors n-k+1 numbers — the total income of the company for each k consecutive months. In other words, for each i between 1 and n-k+1 he will say the value a_i + a_{i+1} + … + a_{i + k - 1}. For example, if a=[-1, 0, 1, 2, 2] and k=3 he will say the numbers 0, 3, 5. Unfortunately, if at least one total income reported by Levian is not a profit (income ≤ 0), the directors will get angry and fire the failed accountant. Save Levian's career: find any such k, that for each k months in a row the company had made a profit, or report that it is impossible. Input The first line contains a single integer n (2 ≤ n ≤ 5⋅ 10^5) — the number of months for which Levian must account. The second line contains ⌈{n/2}⌉ integers a_1, a_2, …, a_{⌈{n/2}⌉}, where a_i (-10^9 ≤ a_i ≤ 10^9) — the income of the company in the i-th month. Third line contains a single integer x (-10^9 ≤ x ≤ 10^9) — income in every month from ⌈{n/2}⌉ + 1 to n. Output In a single line, print the appropriate integer k or -1, if it does not exist. If there are multiple possible answers, you can print any. Examples Input 3 2 -1 2 Output 2 Input 5 2 2 -8 2 Output -1 Input 6 -2 -2 6 -1 Output 4 Note In the first example, k=2 and k=3 satisfy: in the first case, Levian will report the numbers 1, 1, and in the second case — one number 3. In the second example, there is no such k. In the third example, the only answer is k=4: he will report the numbers 1,2,3.
instruction
0
47,157
4
94,314
Tags: constructive algorithms, data structures, greedy, implementation Correct Solution: ``` from sys import stdin, stdout def bn(l, mn, mx): low = 0 high = len(l)-1 while low <= high: mid = (low+high)//2 if l[mid] > mx: high = mid-1 elif l[mid] < mn: low = mid+1 else: return l[mid] return False n = int(stdin.readline()) income1 = [int(x) for x in stdin.readline().split()][::-1] income2 = int(stdin.readline()) sums = [0] for a in income1: sums.append(a+sums[-1]) sums2 = income2*(n//2) sums3 = [0] for a in reversed(income1): sums3.append(sums3[-1]+a) i2Len = n//2 if sums[-1]+sums2 > 0: print(n) elif sums[-1] > 0: dRange = n%2 + sums[-1]//abs(income2) good = [] for s in range(dRange+1): if sums[s] > -sums2: good.append(s) if good: maxGood = float('inf') valid = False for ind,s in enumerate(sums[::-1]): maxGood = min(maxGood, (s-1)//abs(income2)-ind+(n%2)) m2 = len(income1)-ind if maxGood >= m2: realGood = bn(good,m2,maxGood) if realGood != False: valid = True break if valid: print(realGood+n//2) else: print(-1) else: print(-1) else: print(-1) ```
output
1
47,157
4
94,315
Provide tags and a correct Python 3 solution for this coding contest problem. Levian works as an accountant in a large company. Levian knows how much the company has earned in each of the n consecutive months — in the i-th month the company had income equal to a_i (positive income means profit, negative income means loss, zero income means no change). Because of the general self-isolation, the first ⌈ n/2 ⌉ months income might have been completely unstable, but then everything stabilized and for the last ⌊ n/2 ⌋ months the income was the same. Levian decided to tell the directors n-k+1 numbers — the total income of the company for each k consecutive months. In other words, for each i between 1 and n-k+1 he will say the value a_i + a_{i+1} + … + a_{i + k - 1}. For example, if a=[-1, 0, 1, 2, 2] and k=3 he will say the numbers 0, 3, 5. Unfortunately, if at least one total income reported by Levian is not a profit (income ≤ 0), the directors will get angry and fire the failed accountant. Save Levian's career: find any such k, that for each k months in a row the company had made a profit, or report that it is impossible. Input The first line contains a single integer n (2 ≤ n ≤ 5⋅ 10^5) — the number of months for which Levian must account. The second line contains ⌈{n/2}⌉ integers a_1, a_2, …, a_{⌈{n/2}⌉}, where a_i (-10^9 ≤ a_i ≤ 10^9) — the income of the company in the i-th month. Third line contains a single integer x (-10^9 ≤ x ≤ 10^9) — income in every month from ⌈{n/2}⌉ + 1 to n. Output In a single line, print the appropriate integer k or -1, if it does not exist. If there are multiple possible answers, you can print any. Examples Input 3 2 -1 2 Output 2 Input 5 2 2 -8 2 Output -1 Input 6 -2 -2 6 -1 Output 4 Note In the first example, k=2 and k=3 satisfy: in the first case, Levian will report the numbers 1, 1, and in the second case — one number 3. In the second example, there is no such k. In the third example, the only answer is k=4: he will report the numbers 1,2,3.
instruction
0
47,158
4
94,316
Tags: constructive algorithms, data structures, greedy, implementation Correct Solution: ``` import io import os def solve(N, A, X): N2 = N // 2 # last half len N1 = N - N2 # first half len assert len(A) == N1 # Positive total can just take whole array total = sum(A) + N2 * X if total > 0: return N # Handle non-positive total case if X >= 0: # If X is positive, the first window will be even more negative as we take fewer X since total <= 0. # This only changes when K is less than half the array. Suppose this K exists. # Tile the array with non-overlapping window of this K. # Since each window has positive sum and the remainder are all Xs which are also positive, total is supposed to be positive. # Which is a contradiction so this case is impossible. return -1 else: # If X is negative, we know K must be greater than half the array. Otherwise it will take a window of negative X. # # Look at the cumulative sums. Want to pair up some prefix and suffix such that it is element wise less than. # Since the suffix is always in the repeating part of the array we know the value exactly. # That is for 0 <= i <= N - K # 0 < cs[i + K] - cs[i] # range sum of window starting at i # cs[i] < cs[i + K] # cs[i] < total - X * (N - K - i) # since cs[i + K] is in second half # cs[i] + X * (N - i) < total + X * K cs = [0] for x in A + [X] * N2: cs.append(cs[-1] + x) maxSeen = float("-inf") for i in range(N2 + 1): maxSeen = max(maxSeen, cs[i] + X * (N - i)) # If max seen of the prefix from [0, i] is good, then K = N - i might work if maxSeen < total + X * (N - i): return N - i return -1 if __name__ == "__main__": input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline (N,) = [int(x) for x in input().split()] A = [int(x) for x in input().split()] (X,) = [int(x) for x in input().split()] ans = solve(N, A, X) print(ans) ```
output
1
47,158
4
94,317
Provide tags and a correct Python 3 solution for this coding contest problem. Levian works as an accountant in a large company. Levian knows how much the company has earned in each of the n consecutive months — in the i-th month the company had income equal to a_i (positive income means profit, negative income means loss, zero income means no change). Because of the general self-isolation, the first ⌈ n/2 ⌉ months income might have been completely unstable, but then everything stabilized and for the last ⌊ n/2 ⌋ months the income was the same. Levian decided to tell the directors n-k+1 numbers — the total income of the company for each k consecutive months. In other words, for each i between 1 and n-k+1 he will say the value a_i + a_{i+1} + … + a_{i + k - 1}. For example, if a=[-1, 0, 1, 2, 2] and k=3 he will say the numbers 0, 3, 5. Unfortunately, if at least one total income reported by Levian is not a profit (income ≤ 0), the directors will get angry and fire the failed accountant. Save Levian's career: find any such k, that for each k months in a row the company had made a profit, or report that it is impossible. Input The first line contains a single integer n (2 ≤ n ≤ 5⋅ 10^5) — the number of months for which Levian must account. The second line contains ⌈{n/2}⌉ integers a_1, a_2, …, a_{⌈{n/2}⌉}, where a_i (-10^9 ≤ a_i ≤ 10^9) — the income of the company in the i-th month. Third line contains a single integer x (-10^9 ≤ x ≤ 10^9) — income in every month from ⌈{n/2}⌉ + 1 to n. Output In a single line, print the appropriate integer k or -1, if it does not exist. If there are multiple possible answers, you can print any. Examples Input 3 2 -1 2 Output 2 Input 5 2 2 -8 2 Output -1 Input 6 -2 -2 6 -1 Output 4 Note In the first example, k=2 and k=3 satisfy: in the first case, Levian will report the numbers 1, 1, and in the second case — one number 3. In the second example, there is no such k. In the third example, the only answer is k=4: he will report the numbers 1,2,3.
instruction
0
47,159
4
94,318
Tags: constructive algorithms, data structures, greedy, implementation Correct Solution: ``` def main(): n = int(input()) a = list(map(int, input().split())) Ax = int(input()) N = int((n+1)/2) m = [0 for _ in range(N+1)] psm = 0 for i in range(1, N+1): psm += Ax - a[i-1] m[i] = min(m[i-1], psm) apsm = 0 for k in range(1,N+1): apsm += a[k-1] for k in range(N, n+1): if apsm + m[n-k] > 0: return print(k) apsm += Ax return print(-1) if __name__ == '__main__': main() ```
output
1
47,159
4
94,319
Provide tags and a correct Python 3 solution for this coding contest problem. Levian works as an accountant in a large company. Levian knows how much the company has earned in each of the n consecutive months — in the i-th month the company had income equal to a_i (positive income means profit, negative income means loss, zero income means no change). Because of the general self-isolation, the first ⌈ n/2 ⌉ months income might have been completely unstable, but then everything stabilized and for the last ⌊ n/2 ⌋ months the income was the same. Levian decided to tell the directors n-k+1 numbers — the total income of the company for each k consecutive months. In other words, for each i between 1 and n-k+1 he will say the value a_i + a_{i+1} + … + a_{i + k - 1}. For example, if a=[-1, 0, 1, 2, 2] and k=3 he will say the numbers 0, 3, 5. Unfortunately, if at least one total income reported by Levian is not a profit (income ≤ 0), the directors will get angry and fire the failed accountant. Save Levian's career: find any such k, that for each k months in a row the company had made a profit, or report that it is impossible. Input The first line contains a single integer n (2 ≤ n ≤ 5⋅ 10^5) — the number of months for which Levian must account. The second line contains ⌈{n/2}⌉ integers a_1, a_2, …, a_{⌈{n/2}⌉}, where a_i (-10^9 ≤ a_i ≤ 10^9) — the income of the company in the i-th month. Third line contains a single integer x (-10^9 ≤ x ≤ 10^9) — income in every month from ⌈{n/2}⌉ + 1 to n. Output In a single line, print the appropriate integer k or -1, if it does not exist. If there are multiple possible answers, you can print any. Examples Input 3 2 -1 2 Output 2 Input 5 2 2 -8 2 Output -1 Input 6 -2 -2 6 -1 Output 4 Note In the first example, k=2 and k=3 satisfy: in the first case, Levian will report the numbers 1, 1, and in the second case — one number 3. In the second example, there is no such k. In the third example, the only answer is k=4: he will report the numbers 1,2,3.
instruction
0
47,160
4
94,320
Tags: constructive algorithms, data structures, greedy, implementation Correct Solution: ``` # from bisect import bisect_left N = int(input()) A = list(map(int, input().split())) X = int(input()) # print(-1//4) # print(N, A, X) NS = N - len(A) NN = len(A) PS = [0] for a in A: PS.append(PS[-1]+a) total = PS[-1] + NS * X if total > 0: print(N) else: if X > 0: print(-1) else: max_a = total + X * N result = -1 for i in range(NN): max_a = max(max_a, PS[i] + X * (N - i)) if max_a < total + X * (N - i): result = N - i break print(result) # for tc in range(TC): # N, X = map(int, input().split()) # A = list(map(int, input().split())) # result = 0 # print('Case #{}: {}'.format(tc + 1, result)) ```
output
1
47,160
4
94,321
Provide tags and a correct Python 3 solution for this coding contest problem. Levian works as an accountant in a large company. Levian knows how much the company has earned in each of the n consecutive months — in the i-th month the company had income equal to a_i (positive income means profit, negative income means loss, zero income means no change). Because of the general self-isolation, the first ⌈ n/2 ⌉ months income might have been completely unstable, but then everything stabilized and for the last ⌊ n/2 ⌋ months the income was the same. Levian decided to tell the directors n-k+1 numbers — the total income of the company for each k consecutive months. In other words, for each i between 1 and n-k+1 he will say the value a_i + a_{i+1} + … + a_{i + k - 1}. For example, if a=[-1, 0, 1, 2, 2] and k=3 he will say the numbers 0, 3, 5. Unfortunately, if at least one total income reported by Levian is not a profit (income ≤ 0), the directors will get angry and fire the failed accountant. Save Levian's career: find any such k, that for each k months in a row the company had made a profit, or report that it is impossible. Input The first line contains a single integer n (2 ≤ n ≤ 5⋅ 10^5) — the number of months for which Levian must account. The second line contains ⌈{n/2}⌉ integers a_1, a_2, …, a_{⌈{n/2}⌉}, where a_i (-10^9 ≤ a_i ≤ 10^9) — the income of the company in the i-th month. Third line contains a single integer x (-10^9 ≤ x ≤ 10^9) — income in every month from ⌈{n/2}⌉ + 1 to n. Output In a single line, print the appropriate integer k or -1, if it does not exist. If there are multiple possible answers, you can print any. Examples Input 3 2 -1 2 Output 2 Input 5 2 2 -8 2 Output -1 Input 6 -2 -2 6 -1 Output 4 Note In the first example, k=2 and k=3 satisfy: in the first case, Levian will report the numbers 1, 1, and in the second case — one number 3. In the second example, there is no such k. In the third example, the only answer is k=4: he will report the numbers 1,2,3.
instruction
0
47,161
4
94,322
Tags: constructive algorithms, data structures, greedy, implementation Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) x = int(input()) a = [0] + a f = list(a) part = n // 2 sum = 0 for i in range(1, len(f)): f[i] += f[i - 1] sum += a[i] sum += part * x if sum > 0: print(n) exit(0) if x>=0: print(-1) exit(0) #print(sum) for i in range(len(f)): f[i] = sum - f[i] c = [0] * len(f) x = -x for i in range(len(c)): c[i] = max(0, (-f[i] + x) // x) vmax = list(c) for i in range(1, len(vmax)): vmax[i] = max(vmax[i], vmax[i - 1] - 1) #print(f) #print(c) for i in range(len(vmax)): if vmax[i] == 0: print(n - i) exit(0) print(-1) ```
output
1
47,161
4
94,323
Provide tags and a correct Python 3 solution for this coding contest problem. Levian works as an accountant in a large company. Levian knows how much the company has earned in each of the n consecutive months — in the i-th month the company had income equal to a_i (positive income means profit, negative income means loss, zero income means no change). Because of the general self-isolation, the first ⌈ n/2 ⌉ months income might have been completely unstable, but then everything stabilized and for the last ⌊ n/2 ⌋ months the income was the same. Levian decided to tell the directors n-k+1 numbers — the total income of the company for each k consecutive months. In other words, for each i between 1 and n-k+1 he will say the value a_i + a_{i+1} + … + a_{i + k - 1}. For example, if a=[-1, 0, 1, 2, 2] and k=3 he will say the numbers 0, 3, 5. Unfortunately, if at least one total income reported by Levian is not a profit (income ≤ 0), the directors will get angry and fire the failed accountant. Save Levian's career: find any such k, that for each k months in a row the company had made a profit, or report that it is impossible. Input The first line contains a single integer n (2 ≤ n ≤ 5⋅ 10^5) — the number of months for which Levian must account. The second line contains ⌈{n/2}⌉ integers a_1, a_2, …, a_{⌈{n/2}⌉}, where a_i (-10^9 ≤ a_i ≤ 10^9) — the income of the company in the i-th month. Third line contains a single integer x (-10^9 ≤ x ≤ 10^9) — income in every month from ⌈{n/2}⌉ + 1 to n. Output In a single line, print the appropriate integer k or -1, if it does not exist. If there are multiple possible answers, you can print any. Examples Input 3 2 -1 2 Output 2 Input 5 2 2 -8 2 Output -1 Input 6 -2 -2 6 -1 Output 4 Note In the first example, k=2 and k=3 satisfy: in the first case, Levian will report the numbers 1, 1, and in the second case — one number 3. In the second example, there is no such k. In the third example, the only answer is k=4: he will report the numbers 1,2,3.
instruction
0
47,162
4
94,324
Tags: constructive algorithms, data structures, greedy, implementation Correct Solution: ``` import os import sys if os.path.exists('/mnt/c/Users/Square/square/codeforces'): f = iter(open('E.txt').readlines()) def input(): return next(f) # input = lambda: sys.stdin.readline().strip() else: input = lambda: sys.stdin.readline().strip() fprint = lambda *args: print(*args, flush=True) n = int(input()) A = list(map(int, input().split())) x = int(input()) m = [0] ps = [0] prefs = [0] for i in range(n//2): ps.append(x - A[i]) for i in range(n//2): prefs.append(prefs[-1] + x - A[i]) mins = [0] for i in prefs[1:]: mins.append(min(mins[-1], i)) # print(ps) # print(prefs) # print(mins) s = sum(A) res = -1 for k, m in enumerate(reversed(mins)): # print(s, k, m) if s + m > 0: res = len(A) + k break s += x print(res) ```
output
1
47,162
4
94,325
Provide tags and a correct Python 3 solution for this coding contest problem. Levian works as an accountant in a large company. Levian knows how much the company has earned in each of the n consecutive months — in the i-th month the company had income equal to a_i (positive income means profit, negative income means loss, zero income means no change). Because of the general self-isolation, the first ⌈ n/2 ⌉ months income might have been completely unstable, but then everything stabilized and for the last ⌊ n/2 ⌋ months the income was the same. Levian decided to tell the directors n-k+1 numbers — the total income of the company for each k consecutive months. In other words, for each i between 1 and n-k+1 he will say the value a_i + a_{i+1} + … + a_{i + k - 1}. For example, if a=[-1, 0, 1, 2, 2] and k=3 he will say the numbers 0, 3, 5. Unfortunately, if at least one total income reported by Levian is not a profit (income ≤ 0), the directors will get angry and fire the failed accountant. Save Levian's career: find any such k, that for each k months in a row the company had made a profit, or report that it is impossible. Input The first line contains a single integer n (2 ≤ n ≤ 5⋅ 10^5) — the number of months for which Levian must account. The second line contains ⌈{n/2}⌉ integers a_1, a_2, …, a_{⌈{n/2}⌉}, where a_i (-10^9 ≤ a_i ≤ 10^9) — the income of the company in the i-th month. Third line contains a single integer x (-10^9 ≤ x ≤ 10^9) — income in every month from ⌈{n/2}⌉ + 1 to n. Output In a single line, print the appropriate integer k or -1, if it does not exist. If there are multiple possible answers, you can print any. Examples Input 3 2 -1 2 Output 2 Input 5 2 2 -8 2 Output -1 Input 6 -2 -2 6 -1 Output 4 Note In the first example, k=2 and k=3 satisfy: in the first case, Levian will report the numbers 1, 1, and in the second case — one number 3. In the second example, there is no such k. In the third example, the only answer is k=4: he will report the numbers 1,2,3.
instruction
0
47,163
4
94,326
Tags: constructive algorithms, data structures, greedy, implementation Correct Solution: ``` import sys, heapq from collections import * from functools import lru_cache sys.setrecursionlimit(10**6) import operator as op from functools import reduce import bisect def main(): # sys.stdin = open('input.txt', 'r') # t = int(input()) # # for _ in range(t): # x1,y1,x2,y2 = map(int,input().split(' ')) # x, y = x2-x1, y2-y1 # print(x*y+1) n = int(input()) arr = list(map(int,input().split(' '))) x = int(input()) first, cur, res = sum(arr)+x*(n-len(arr)), 0, 0 if first > 0: print(n) return for k in range(len(arr),n)[::-1]: cur += x-arr[n-k-1] res = min(res,cur) first -= x if first+res > 0: print(k) return print(-1) return if __name__ == "__main__": main() ```
output
1
47,163
4
94,327
Provide tags and a correct Python 3 solution for this coding contest problem. Levian works as an accountant in a large company. Levian knows how much the company has earned in each of the n consecutive months — in the i-th month the company had income equal to a_i (positive income means profit, negative income means loss, zero income means no change). Because of the general self-isolation, the first ⌈ n/2 ⌉ months income might have been completely unstable, but then everything stabilized and for the last ⌊ n/2 ⌋ months the income was the same. Levian decided to tell the directors n-k+1 numbers — the total income of the company for each k consecutive months. In other words, for each i between 1 and n-k+1 he will say the value a_i + a_{i+1} + … + a_{i + k - 1}. For example, if a=[-1, 0, 1, 2, 2] and k=3 he will say the numbers 0, 3, 5. Unfortunately, if at least one total income reported by Levian is not a profit (income ≤ 0), the directors will get angry and fire the failed accountant. Save Levian's career: find any such k, that for each k months in a row the company had made a profit, or report that it is impossible. Input The first line contains a single integer n (2 ≤ n ≤ 5⋅ 10^5) — the number of months for which Levian must account. The second line contains ⌈{n/2}⌉ integers a_1, a_2, …, a_{⌈{n/2}⌉}, where a_i (-10^9 ≤ a_i ≤ 10^9) — the income of the company in the i-th month. Third line contains a single integer x (-10^9 ≤ x ≤ 10^9) — income in every month from ⌈{n/2}⌉ + 1 to n. Output In a single line, print the appropriate integer k or -1, if it does not exist. If there are multiple possible answers, you can print any. Examples Input 3 2 -1 2 Output 2 Input 5 2 2 -8 2 Output -1 Input 6 -2 -2 6 -1 Output 4 Note In the first example, k=2 and k=3 satisfy: in the first case, Levian will report the numbers 1, 1, and in the second case — one number 3. In the second example, there is no such k. In the third example, the only answer is k=4: he will report the numbers 1,2,3.
instruction
0
47,164
4
94,328
Tags: constructive algorithms, data structures, greedy, implementation Correct Solution: ``` from bisect import * from collections import * from math import gcd,ceil,sqrt,floor,inf from heapq import * from itertools import * from operator import add,mul,sub,xor,truediv,floordiv from functools import * #------------------------------------------------------------------------ import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") #------------------------------------------------------------------------ def RL(): return map(int, sys.stdin.readline().rstrip().split()) def RLL(): return list(map(int, sys.stdin.readline().rstrip().split())) def N(): return int(input()) #------------------------------------------------------------------------ from types import GeneratorType def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) else: stack.pop() if not stack: break to = stack[-1].send(to) return to return wrappedfunc farr=[1] ifa=[] def fact(x,mod=0): if mod: while x>=len(farr): farr.append(farr[-1]*len(farr)%mod) else: while x>=len(farr): farr.append(farr[-1]*len(farr)) return farr[x] def ifact(x,mod): global ifa ifa.append(pow(farr[-1],mod-2,mod)) for i in range(x,0,-1): ifa.append(ifa[-1]*i%mod) ifa=ifa[::-1] def per(i,j,mod=0): if i<j: return 0 if not mod: return fact(i)//fact(i-j) return farr[i]*ifa[i-j]%mod def com(i,j,mod=0): if i<j: return 0 if not mod: return per(i,j)//fact(j) return per(i,j,mod)*ifa[j]%mod def catalan(n): return com(2*n,n)//(n+1) def isprime(n): for i in range(2,int(n**0.5)+1): if n%i==0: return False return True def lowbit(n): return n&-n def inverse(a,m): a%=m if a<=1: return a return ((1-inverse(m,a)*m)//a)%m class BIT: def __init__(self,arr): self.arr=arr self.n=len(arr)-1 def update(self,x,v): while x<=self.n: self.arr[x]+=v x+=x&-x def query(self,x): ans=0 while x: ans+=self.arr[x] x&=x-1 return ans ''' class SMT: def __init__(self,arr): self.n=len(arr)-1 self.arr=[0]*(self.n<<2) self.lazy=[0]*(self.n<<2) def Build(l,r,rt): if l==r: self.arr[rt]=arr[l] return m=(l+r)>>1 Build(l,m,rt<<1) Build(m+1,r,rt<<1|1) self.pushup(rt) Build(1,self.n,1) def pushup(self,rt): self.arr[rt]=self.arr[rt<<1]+self.arr[rt<<1|1] def pushdown(self,rt,ln,rn):#lr,rn表区间数字数 if self.lazy[rt]: self.lazy[rt<<1]+=self.lazy[rt] self.lazy[rt<<1|1]+=self.lazy[rt] self.arr[rt<<1]+=self.lazy[rt]*ln self.arr[rt<<1|1]+=self.lazy[rt]*rn self.lazy[rt]=0 def update(self,L,R,c,l=1,r=None,rt=1):#L,R表示操作区间 if r==None: r=self.n if L<=l and r<=R: self.arr[rt]+=c*(r-l+1) self.lazy[rt]+=c return m=(l+r)>>1 self.pushdown(rt,m-l+1,r-m) if L<=m: self.update(L,R,c,l,m,rt<<1) if R>m: self.update(L,R,c,m+1,r,rt<<1|1) self.pushup(rt) def query(self,L,R,l=1,r=None,rt=1): if r==None: r=self.n #print(L,R,l,r,rt) if L<=l and R>=r: return self.arr[rt] m=(l+r)>>1 self.pushdown(rt,m-l+1,r-m) ans=0 if L<=m: ans+=self.query(L,R,l,m,rt<<1) if R>m: ans+=self.query(L,R,m+1,r,rt<<1|1) return ans ''' class DSU:#容量+路径压缩 def __init__(self,n): self.c=[-1]*n def same(self,x,y): return self.find(x)==self.find(y) def find(self,x): if self.c[x]<0: return x self.c[x]=self.find(self.c[x]) return self.c[x] def union(self,u,v): u,v=self.find(u),self.find(v) if u==v: return False if self.c[u]<self.c[v]: u,v=v,u self.c[u]+=self.c[v] self.c[v]=u return True def size(self,x): return -self.c[self.find(x)] class UFS:#秩+路径 def __init__(self,n): self.parent=[i for i in range(n)] self.ranks=[0]*n def find(self,x): if x!=self.parent[x]: self.parent[x]=self.find(self.parent[x]) return self.parent[x] def union(self,u,v): pu,pv=self.find(u),self.find(v) if pu==pv: return False if self.ranks[pu]>=self.ranks[pv]: self.parent[pv]=pu if self.ranks[pv]==self.ranks[pu]: self.ranks[pu]+=1 else: self.parent[pu]=pv def Prime(n): c=0 prime=[] flag=[0]*(n+1) for i in range(2,n+1): if not flag[i]: prime.append(i) c+=1 for j in range(c): if i*prime[j]>n: break flag[i*prime[j]]=prime[j] if i%prime[j]==0: break #print(flag) return flag def dij(s,graph): d={} d[s]=0 heap=[(0,s)] seen=set() while heap: dis,u=heappop(heap) if u in seen: continue for v in graph[u]: if v not in d or d[v]>d[u]+graph[u][v]: d[v]=d[u]+graph[u][v] heappush(heap,(d[v],v)) return d def GP(it): return [[ch,len(list(g))] for ch,g in groupby(it)] class DLN: def __init__(self,val): self.val=val self.pre=None self.next=None def nb(i,j): for ni,nj in [[i+1,j],[i-1,j],[i,j-1],[i,j+1]]: if 0<=ni<n and 0<=nj<m: yield ni,nj @bootstrap def gdfs(r,p): if len(g[r])==1 and p!=-1: yield None for ch in g[r]: if ch!=p: yield gdfs(ch,r) yield None t=1 for i in range(t): n=N() a=RLL() x=N() s=sum(a) mi=[0] k=n//2+1 if k>(n+1)//2: s+=x for i in range(n-k): mi.append(x-a[i]) dp=[0] for i in range(n-k): dp.append(dp[-1]+mi[i+1]) mi[i+1]=min(dp[-1],mi[i]) for k in range(n//2+1,n+1): if mi[-1]+s>0: print(k) exit() mi.pop() s+=x print(-1) ''' sys.setrecursionlimit(200000) import threading threading.stack_size(10**8) t=threading.Thread(target=main) t.start() t.join() ''' ''' sys.setrecursionlimit(200000) import threading threading.stack_size(10**8) t=threading.Thread(target=main) t.start() t.join() ''' ```
output
1
47,164
4
94,329
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Levian works as an accountant in a large company. Levian knows how much the company has earned in each of the n consecutive months — in the i-th month the company had income equal to a_i (positive income means profit, negative income means loss, zero income means no change). Because of the general self-isolation, the first ⌈ n/2 ⌉ months income might have been completely unstable, but then everything stabilized and for the last ⌊ n/2 ⌋ months the income was the same. Levian decided to tell the directors n-k+1 numbers — the total income of the company for each k consecutive months. In other words, for each i between 1 and n-k+1 he will say the value a_i + a_{i+1} + … + a_{i + k - 1}. For example, if a=[-1, 0, 1, 2, 2] and k=3 he will say the numbers 0, 3, 5. Unfortunately, if at least one total income reported by Levian is not a profit (income ≤ 0), the directors will get angry and fire the failed accountant. Save Levian's career: find any such k, that for each k months in a row the company had made a profit, or report that it is impossible. Input The first line contains a single integer n (2 ≤ n ≤ 5⋅ 10^5) — the number of months for which Levian must account. The second line contains ⌈{n/2}⌉ integers a_1, a_2, …, a_{⌈{n/2}⌉}, where a_i (-10^9 ≤ a_i ≤ 10^9) — the income of the company in the i-th month. Third line contains a single integer x (-10^9 ≤ x ≤ 10^9) — income in every month from ⌈{n/2}⌉ + 1 to n. Output In a single line, print the appropriate integer k or -1, if it does not exist. If there are multiple possible answers, you can print any. Examples Input 3 2 -1 2 Output 2 Input 5 2 2 -8 2 Output -1 Input 6 -2 -2 6 -1 Output 4 Note In the first example, k=2 and k=3 satisfy: in the first case, Levian will report the numbers 1, 1, and in the second case — one number 3. In the second example, there is no such k. In the third example, the only answer is k=4: he will report the numbers 1,2,3. Submitted Solution: ``` def isFired(n, incomes, other): N = (n + 1) >> 1 minIncomes = [0] minIncome = 0 for i in range(N): minIncome += other - incomes[i] minIncomes.append(min(minIncomes[-1], minIncome)) prefixSum = sum(incomes) for month in range(N, n + 1): if prefixSum + minIncomes[n - month] > 0: return month prefixSum += other return -1 def solve(): n = int(input()) incomes = list(map(int, input().split())) other = int(input()) print(isFired(n, incomes, other)) solve() ```
instruction
0
47,165
4
94,330
Yes
output
1
47,165
4
94,331
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Levian works as an accountant in a large company. Levian knows how much the company has earned in each of the n consecutive months — in the i-th month the company had income equal to a_i (positive income means profit, negative income means loss, zero income means no change). Because of the general self-isolation, the first ⌈ n/2 ⌉ months income might have been completely unstable, but then everything stabilized and for the last ⌊ n/2 ⌋ months the income was the same. Levian decided to tell the directors n-k+1 numbers — the total income of the company for each k consecutive months. In other words, for each i between 1 and n-k+1 he will say the value a_i + a_{i+1} + … + a_{i + k - 1}. For example, if a=[-1, 0, 1, 2, 2] and k=3 he will say the numbers 0, 3, 5. Unfortunately, if at least one total income reported by Levian is not a profit (income ≤ 0), the directors will get angry and fire the failed accountant. Save Levian's career: find any such k, that for each k months in a row the company had made a profit, or report that it is impossible. Input The first line contains a single integer n (2 ≤ n ≤ 5⋅ 10^5) — the number of months for which Levian must account. The second line contains ⌈{n/2}⌉ integers a_1, a_2, …, a_{⌈{n/2}⌉}, where a_i (-10^9 ≤ a_i ≤ 10^9) — the income of the company in the i-th month. Third line contains a single integer x (-10^9 ≤ x ≤ 10^9) — income in every month from ⌈{n/2}⌉ + 1 to n. Output In a single line, print the appropriate integer k or -1, if it does not exist. If there are multiple possible answers, you can print any. Examples Input 3 2 -1 2 Output 2 Input 5 2 2 -8 2 Output -1 Input 6 -2 -2 6 -1 Output 4 Note In the first example, k=2 and k=3 satisfy: in the first case, Levian will report the numbers 1, 1, and in the second case — one number 3. In the second example, there is no such k. In the third example, the only answer is k=4: he will report the numbers 1,2,3. Submitted Solution: ``` import sys input = sys.stdin.readline n=int(input()) a=list(map(int,input().split())) x=int(input()) s=sum(a)+(n//2)*x if s>0: print(n) else: if x>=0: print(-1) else: poss=-1 x=-x miss=-s mn=0 curs=0 for i in range((n+1)//2): curs-=a[i] curmin=(miss-curs+x)//x curmin=curmin+i mn=max(mn,curmin) if i>=mn: poss=n-i-1 print(poss) ```
instruction
0
47,166
4
94,332
Yes
output
1
47,166
4
94,333
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Levian works as an accountant in a large company. Levian knows how much the company has earned in each of the n consecutive months — in the i-th month the company had income equal to a_i (positive income means profit, negative income means loss, zero income means no change). Because of the general self-isolation, the first ⌈ n/2 ⌉ months income might have been completely unstable, but then everything stabilized and for the last ⌊ n/2 ⌋ months the income was the same. Levian decided to tell the directors n-k+1 numbers — the total income of the company for each k consecutive months. In other words, for each i between 1 and n-k+1 he will say the value a_i + a_{i+1} + … + a_{i + k - 1}. For example, if a=[-1, 0, 1, 2, 2] and k=3 he will say the numbers 0, 3, 5. Unfortunately, if at least one total income reported by Levian is not a profit (income ≤ 0), the directors will get angry and fire the failed accountant. Save Levian's career: find any such k, that for each k months in a row the company had made a profit, or report that it is impossible. Input The first line contains a single integer n (2 ≤ n ≤ 5⋅ 10^5) — the number of months for which Levian must account. The second line contains ⌈{n/2}⌉ integers a_1, a_2, …, a_{⌈{n/2}⌉}, where a_i (-10^9 ≤ a_i ≤ 10^9) — the income of the company in the i-th month. Third line contains a single integer x (-10^9 ≤ x ≤ 10^9) — income in every month from ⌈{n/2}⌉ + 1 to n. Output In a single line, print the appropriate integer k or -1, if it does not exist. If there are multiple possible answers, you can print any. Examples Input 3 2 -1 2 Output 2 Input 5 2 2 -8 2 Output -1 Input 6 -2 -2 6 -1 Output 4 Note In the first example, k=2 and k=3 satisfy: in the first case, Levian will report the numbers 1, 1, and in the second case — one number 3. In the second example, there is no such k. In the third example, the only answer is k=4: he will report the numbers 1,2,3. Submitted Solution: ``` from sys import stdin input = stdin.readline def main(): test = 1 for _ in range(test): n = int(input()) ara = [int(num) for num in input().split()] x = int(input()) n1 = len(ara) n2 = n - n1 ara_sum = sum(ara) + n2 * x if ara_sum > 0: print(n) elif x >= 0: print(-1) else: ara = ara + [x] * n2 prefix_sum = [0] for num in ara: prefix_sum.append(num + prefix_sum[-1]) current_max = n * x for i in range(n1): current_max = max(current_max, prefix_sum[i] + x * (n - i)) if current_max < prefix_sum[n] + x * (n - i): print(n - i) return print(-1) if __name__ == "__main__": main() ```
instruction
0
47,167
4
94,334
Yes
output
1
47,167
4
94,335
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Levian works as an accountant in a large company. Levian knows how much the company has earned in each of the n consecutive months — in the i-th month the company had income equal to a_i (positive income means profit, negative income means loss, zero income means no change). Because of the general self-isolation, the first ⌈ n/2 ⌉ months income might have been completely unstable, but then everything stabilized and for the last ⌊ n/2 ⌋ months the income was the same. Levian decided to tell the directors n-k+1 numbers — the total income of the company for each k consecutive months. In other words, for each i between 1 and n-k+1 he will say the value a_i + a_{i+1} + … + a_{i + k - 1}. For example, if a=[-1, 0, 1, 2, 2] and k=3 he will say the numbers 0, 3, 5. Unfortunately, if at least one total income reported by Levian is not a profit (income ≤ 0), the directors will get angry and fire the failed accountant. Save Levian's career: find any such k, that for each k months in a row the company had made a profit, or report that it is impossible. Input The first line contains a single integer n (2 ≤ n ≤ 5⋅ 10^5) — the number of months for which Levian must account. The second line contains ⌈{n/2}⌉ integers a_1, a_2, …, a_{⌈{n/2}⌉}, where a_i (-10^9 ≤ a_i ≤ 10^9) — the income of the company in the i-th month. Third line contains a single integer x (-10^9 ≤ x ≤ 10^9) — income in every month from ⌈{n/2}⌉ + 1 to n. Output In a single line, print the appropriate integer k or -1, if it does not exist. If there are multiple possible answers, you can print any. Examples Input 3 2 -1 2 Output 2 Input 5 2 2 -8 2 Output -1 Input 6 -2 -2 6 -1 Output 4 Note In the first example, k=2 and k=3 satisfy: in the first case, Levian will report the numbers 1, 1, and in the second case — one number 3. In the second example, there is no such k. In the third example, the only answer is k=4: he will report the numbers 1,2,3. Submitted Solution: ``` import sys from array import array # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') n = int(input()) a = list(map(int, input().split())) x = int(input()) total = sum(a) + x * (n - len(a)) if total > 0: print(n) exit() min_sub = total for l, ans in zip(range(len(a)), range(n - 1, -1, -1)): total -= a[l] min_sub = min(min_sub - x, total) if min_sub > 0: print(ans) exit() print(-1) ```
instruction
0
47,168
4
94,336
Yes
output
1
47,168
4
94,337
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Levian works as an accountant in a large company. Levian knows how much the company has earned in each of the n consecutive months — in the i-th month the company had income equal to a_i (positive income means profit, negative income means loss, zero income means no change). Because of the general self-isolation, the first ⌈ n/2 ⌉ months income might have been completely unstable, but then everything stabilized and for the last ⌊ n/2 ⌋ months the income was the same. Levian decided to tell the directors n-k+1 numbers — the total income of the company for each k consecutive months. In other words, for each i between 1 and n-k+1 he will say the value a_i + a_{i+1} + … + a_{i + k - 1}. For example, if a=[-1, 0, 1, 2, 2] and k=3 he will say the numbers 0, 3, 5. Unfortunately, if at least one total income reported by Levian is not a profit (income ≤ 0), the directors will get angry and fire the failed accountant. Save Levian's career: find any such k, that for each k months in a row the company had made a profit, or report that it is impossible. Input The first line contains a single integer n (2 ≤ n ≤ 5⋅ 10^5) — the number of months for which Levian must account. The second line contains ⌈{n/2}⌉ integers a_1, a_2, …, a_{⌈{n/2}⌉}, where a_i (-10^9 ≤ a_i ≤ 10^9) — the income of the company in the i-th month. Third line contains a single integer x (-10^9 ≤ x ≤ 10^9) — income in every month from ⌈{n/2}⌉ + 1 to n. Output In a single line, print the appropriate integer k or -1, if it does not exist. If there are multiple possible answers, you can print any. Examples Input 3 2 -1 2 Output 2 Input 5 2 2 -8 2 Output -1 Input 6 -2 -2 6 -1 Output 4 Note In the first example, k=2 and k=3 satisfy: in the first case, Levian will report the numbers 1, 1, and in the second case — one number 3. In the second example, there is no such k. In the third example, the only answer is k=4: he will report the numbers 1,2,3. Submitted Solution: ``` n = int(input()) arr = [int(x) for x in input().split()] x = int(input()) arr += [x]*(n//2) def giveArr(tk): res = [] summ = 0 for i in range(tk): summ += arr[i] res.append(summ) i,j = 0,tk-1 while j+1 < n: summ += arr[j+1] - arr[i] i += 1 j += 1 res.append(summ) return res def find(tk): res = 0 summ = 0 for i in range(tk): summ += arr[i] if summ <= 0: res += summ - 1 i,j = 0,tk-1 while j+1 < n: summ += arr[j+1] - arr[i] i += 1 j += 1 if summ <= 0: res += summ - 1 return abs(res) l,r = 1,n # tk = 1 while l < r : tk = (l+r)//2 # print(str(l) +' '+str(r)) # print('tk : '+str(tk)) # print(giveArr(tk)) # print(giveArr(tk+1)) neg1,neg2 = find(tk),find(tk+1) if neg1 <= neg2: r = tk else: l = tk+1 if find(l) > 0: print(-1) else: print(l) ```
instruction
0
47,169
4
94,338
No
output
1
47,169
4
94,339
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Levian works as an accountant in a large company. Levian knows how much the company has earned in each of the n consecutive months — in the i-th month the company had income equal to a_i (positive income means profit, negative income means loss, zero income means no change). Because of the general self-isolation, the first ⌈ n/2 ⌉ months income might have been completely unstable, but then everything stabilized and for the last ⌊ n/2 ⌋ months the income was the same. Levian decided to tell the directors n-k+1 numbers — the total income of the company for each k consecutive months. In other words, for each i between 1 and n-k+1 he will say the value a_i + a_{i+1} + … + a_{i + k - 1}. For example, if a=[-1, 0, 1, 2, 2] and k=3 he will say the numbers 0, 3, 5. Unfortunately, if at least one total income reported by Levian is not a profit (income ≤ 0), the directors will get angry and fire the failed accountant. Save Levian's career: find any such k, that for each k months in a row the company had made a profit, or report that it is impossible. Input The first line contains a single integer n (2 ≤ n ≤ 5⋅ 10^5) — the number of months for which Levian must account. The second line contains ⌈{n/2}⌉ integers a_1, a_2, …, a_{⌈{n/2}⌉}, where a_i (-10^9 ≤ a_i ≤ 10^9) — the income of the company in the i-th month. Third line contains a single integer x (-10^9 ≤ x ≤ 10^9) — income in every month from ⌈{n/2}⌉ + 1 to n. Output In a single line, print the appropriate integer k or -1, if it does not exist. If there are multiple possible answers, you can print any. Examples Input 3 2 -1 2 Output 2 Input 5 2 2 -8 2 Output -1 Input 6 -2 -2 6 -1 Output 4 Note In the first example, k=2 and k=3 satisfy: in the first case, Levian will report the numbers 1, 1, and in the second case — one number 3. In the second example, there is no such k. In the third example, the only answer is k=4: he will report the numbers 1,2,3. Submitted Solution: ``` def icanv(num, minusnum): if num <= 0: print(-1) exit() mm = -minusnum return (num - 1) // mm n = int(input()) lst = list(map(int,input().split())) numr = int(input()) numrlen = n // 2 sm = sum(lst) lst.reverse() if numr > 0: if sm + numr * numrlen > 0: print(n) else: print(-1) else: if sm > 0: nk = len(lst) prsm = [0] * nk prsm[0] = lst[0] for i in range(nk): prsm[i] = lst[i] + prsm[i-1] minnums = n for i in range(nk): ans = icanv(prsm[i], numr) + i + 1 minnums = min(minnums, ans) if minnums < n//2: print(-1) else: print(minnums) else: print(-1) ```
instruction
0
47,170
4
94,340
No
output
1
47,170
4
94,341
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Levian works as an accountant in a large company. Levian knows how much the company has earned in each of the n consecutive months — in the i-th month the company had income equal to a_i (positive income means profit, negative income means loss, zero income means no change). Because of the general self-isolation, the first ⌈ n/2 ⌉ months income might have been completely unstable, but then everything stabilized and for the last ⌊ n/2 ⌋ months the income was the same. Levian decided to tell the directors n-k+1 numbers — the total income of the company for each k consecutive months. In other words, for each i between 1 and n-k+1 he will say the value a_i + a_{i+1} + … + a_{i + k - 1}. For example, if a=[-1, 0, 1, 2, 2] and k=3 he will say the numbers 0, 3, 5. Unfortunately, if at least one total income reported by Levian is not a profit (income ≤ 0), the directors will get angry and fire the failed accountant. Save Levian's career: find any such k, that for each k months in a row the company had made a profit, or report that it is impossible. Input The first line contains a single integer n (2 ≤ n ≤ 5⋅ 10^5) — the number of months for which Levian must account. The second line contains ⌈{n/2}⌉ integers a_1, a_2, …, a_{⌈{n/2}⌉}, where a_i (-10^9 ≤ a_i ≤ 10^9) — the income of the company in the i-th month. Third line contains a single integer x (-10^9 ≤ x ≤ 10^9) — income in every month from ⌈{n/2}⌉ + 1 to n. Output In a single line, print the appropriate integer k or -1, if it does not exist. If there are multiple possible answers, you can print any. Examples Input 3 2 -1 2 Output 2 Input 5 2 2 -8 2 Output -1 Input 6 -2 -2 6 -1 Output 4 Note In the first example, k=2 and k=3 satisfy: in the first case, Levian will report the numbers 1, 1, and in the second case — one number 3. In the second example, there is no such k. In the third example, the only answer is k=4: he will report the numbers 1,2,3. Submitted Solution: ``` n = int(input()) a = list(reversed([int(x) for x in input().split()])) x = int(input()) if x == 0: if sum(a) > 0: print(n) else: print(-1) elif x > 0: if sum(a) + x*(n//2) > 0: print(n) else: print(-1) else: # x < 0 cur = 0 peak = 0 peak_i = -1 for i, val in enumerate(a): cur += val if cur > peak: peak = cur peak_i = i # now up to and including peak_i is optimal. # so we want a window of size peak_i + 1 + n//2 w_size = peak_i + 1 + n//2 full_a = [x]*(n//2) + a val = sum(full_a[:w_size]) if val <= 0: print(-1) import sys sys.exit(0) for idx in range(w_size, n): val += full_a[idx] - full_a[idx-w_size] if val <= 0: print(-1) import sys sys.exit(0) print(w_size) ```
instruction
0
47,171
4
94,342
No
output
1
47,171
4
94,343
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Levian works as an accountant in a large company. Levian knows how much the company has earned in each of the n consecutive months — in the i-th month the company had income equal to a_i (positive income means profit, negative income means loss, zero income means no change). Because of the general self-isolation, the first ⌈ n/2 ⌉ months income might have been completely unstable, but then everything stabilized and for the last ⌊ n/2 ⌋ months the income was the same. Levian decided to tell the directors n-k+1 numbers — the total income of the company for each k consecutive months. In other words, for each i between 1 and n-k+1 he will say the value a_i + a_{i+1} + … + a_{i + k - 1}. For example, if a=[-1, 0, 1, 2, 2] and k=3 he will say the numbers 0, 3, 5. Unfortunately, if at least one total income reported by Levian is not a profit (income ≤ 0), the directors will get angry and fire the failed accountant. Save Levian's career: find any such k, that for each k months in a row the company had made a profit, or report that it is impossible. Input The first line contains a single integer n (2 ≤ n ≤ 5⋅ 10^5) — the number of months for which Levian must account. The second line contains ⌈{n/2}⌉ integers a_1, a_2, …, a_{⌈{n/2}⌉}, where a_i (-10^9 ≤ a_i ≤ 10^9) — the income of the company in the i-th month. Third line contains a single integer x (-10^9 ≤ x ≤ 10^9) — income in every month from ⌈{n/2}⌉ + 1 to n. Output In a single line, print the appropriate integer k or -1, if it does not exist. If there are multiple possible answers, you can print any. Examples Input 3 2 -1 2 Output 2 Input 5 2 2 -8 2 Output -1 Input 6 -2 -2 6 -1 Output 4 Note In the first example, k=2 and k=3 satisfy: in the first case, Levian will report the numbers 1, 1, and in the second case — one number 3. In the second example, there is no such k. In the third example, the only answer is k=4: he will report the numbers 1,2,3. Submitted Solution: ``` from sys import stdin, stdout n = int(stdin.readline()) income1 = [int(x) for x in stdin.readline().split()][::-1] income2 = int(stdin.readline()) sums = [0] for a in income1: sums.append(a+sums[-1]) sums2 = income2*(n//2) sums3 = [0] for a in reversed(income1): sums3.append(sums3[-1]+a) i2Len = n//2 if sums[-1]+sums2 > 0: print(n) elif sums[-1] > 0: dRange = n%2 + sums[-1]//abs(income2) good = 0 for s in range(dRange+1): if sums[s] > sums2: good = s+1 break if good: valid = True for ind in range(good,len(sums)): if sums[ind]+income2*(i2Len-ind) <= 0: valid = False break if valid: print(good+n//2) else: print(-1) else: print(-1) else: print(-1) ```
instruction
0
47,172
4
94,344
No
output
1
47,172
4
94,345
Provide tags and a correct Python 3 solution for this coding contest problem. Vasiliy has an exam period which will continue for n days. He has to pass exams on m subjects. Subjects are numbered from 1 to m. About every day we know exam for which one of m subjects can be passed on that day. Perhaps, some day you can't pass any exam. It is not allowed to pass more than one exam on any day. On each day Vasiliy can either pass the exam of that day (it takes the whole day) or prepare all day for some exam or have a rest. About each subject Vasiliy know a number ai — the number of days he should prepare to pass the exam number i. Vasiliy can switch subjects while preparing for exams, it is not necessary to prepare continuously during ai days for the exam number i. He can mix the order of preparation for exams in any way. Your task is to determine the minimum number of days in which Vasiliy can pass all exams, or determine that it is impossible. Each exam should be passed exactly one time. Input The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of days in the exam period and the number of subjects. The second line contains n integers d1, d2, ..., dn (0 ≤ di ≤ m), where di is the number of subject, the exam of which can be passed on the day number i. If di equals 0, it is not allowed to pass any exams on the day number i. The third line contains m positive integers a1, a2, ..., am (1 ≤ ai ≤ 105), where ai is the number of days that are needed to prepare before passing the exam on the subject i. Output Print one integer — the minimum number of days in which Vasiliy can pass all exams. If it is impossible, print -1. Examples Input 7 2 0 1 0 2 1 0 2 2 1 Output 5 Input 10 3 0 0 1 2 3 0 2 0 1 2 1 1 4 Output 9 Input 5 1 1 1 1 1 1 5 Output -1 Note In the first example Vasiliy can behave as follows. On the first and the second day he can prepare for the exam number 1 and pass it on the fifth day, prepare for the exam number 2 on the third day and pass it on the fourth day. In the second example Vasiliy should prepare for the exam number 3 during the first four days and pass it on the fifth day. Then on the sixth day he should prepare for the exam number 2 and then pass it on the seventh day. After that he needs to prepare for the exam number 1 on the eighth day and pass it on the ninth day. In the third example Vasiliy can't pass the only exam because he hasn't anough time to prepare for it.
instruction
0
47,560
4
95,120
Tags: binary search, greedy, sortings Correct Solution: ``` def check(m, mid, aa, dd, edays): avail, ee = [True] * (m + 1), [] for i in range(mid, -1, -1): day = edays[i] exam = dd[day] if avail[exam]: avail[exam] = False ee.append(day) if len(ee) == m: break else: return False pool, prev = 0, -1 for day in reversed(ee): pool += day - prev - aa[dd[day]] if pool < 0: return False prev = day return True def main(): n, m = map(int, input().split()) dd = list(map(int, input().split())) edays = [i for i, e in enumerate(dd) if e] aa = [0, *(int(s) + 1 for s in input().split())] lo, hi = 0, len(edays) try: while lo < hi: mid = (lo + hi) // 2 if check(m, mid, aa, dd, edays): hi = mid else: lo = mid + 1 print(edays[lo] + 1) except IndexError: print(-1) if __name__ == "__main__": main() ```
output
1
47,560
4
95,121
Provide tags and a correct Python 3 solution for this coding contest problem. Vasiliy has an exam period which will continue for n days. He has to pass exams on m subjects. Subjects are numbered from 1 to m. About every day we know exam for which one of m subjects can be passed on that day. Perhaps, some day you can't pass any exam. It is not allowed to pass more than one exam on any day. On each day Vasiliy can either pass the exam of that day (it takes the whole day) or prepare all day for some exam or have a rest. About each subject Vasiliy know a number ai — the number of days he should prepare to pass the exam number i. Vasiliy can switch subjects while preparing for exams, it is not necessary to prepare continuously during ai days for the exam number i. He can mix the order of preparation for exams in any way. Your task is to determine the minimum number of days in which Vasiliy can pass all exams, or determine that it is impossible. Each exam should be passed exactly one time. Input The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of days in the exam period and the number of subjects. The second line contains n integers d1, d2, ..., dn (0 ≤ di ≤ m), where di is the number of subject, the exam of which can be passed on the day number i. If di equals 0, it is not allowed to pass any exams on the day number i. The third line contains m positive integers a1, a2, ..., am (1 ≤ ai ≤ 105), where ai is the number of days that are needed to prepare before passing the exam on the subject i. Output Print one integer — the minimum number of days in which Vasiliy can pass all exams. If it is impossible, print -1. Examples Input 7 2 0 1 0 2 1 0 2 2 1 Output 5 Input 10 3 0 0 1 2 3 0 2 0 1 2 1 1 4 Output 9 Input 5 1 1 1 1 1 1 5 Output -1 Note In the first example Vasiliy can behave as follows. On the first and the second day he can prepare for the exam number 1 and pass it on the fifth day, prepare for the exam number 2 on the third day and pass it on the fourth day. In the second example Vasiliy should prepare for the exam number 3 during the first four days and pass it on the fifth day. Then on the sixth day he should prepare for the exam number 2 and then pass it on the seventh day. After that he needs to prepare for the exam number 1 on the eighth day and pass it on the ninth day. In the third example Vasiliy can't pass the only exam because he hasn't anough time to prepare for it.
instruction
0
47,561
4
95,122
Tags: binary search, greedy, sortings Correct Solution: ``` def main(): n, m = map(int, input().split()) dd = list(map(int, input().split())) aa = [0, *map(int, input().split())] l = [True] * (m + 1) l[0], total = False, sum(aa) + len(aa) - 2 for i, e in enumerate(dd, 1): if l[e]: if i > aa[e]: m -= 1 l[e] = False if not m and i > total: print(i) break else: print(-1) if __name__ == '__main__': main() ```
output
1
47,561
4
95,123
Provide tags and a correct Python 3 solution for this coding contest problem. Vasiliy has an exam period which will continue for n days. He has to pass exams on m subjects. Subjects are numbered from 1 to m. About every day we know exam for which one of m subjects can be passed on that day. Perhaps, some day you can't pass any exam. It is not allowed to pass more than one exam on any day. On each day Vasiliy can either pass the exam of that day (it takes the whole day) or prepare all day for some exam or have a rest. About each subject Vasiliy know a number ai — the number of days he should prepare to pass the exam number i. Vasiliy can switch subjects while preparing for exams, it is not necessary to prepare continuously during ai days for the exam number i. He can mix the order of preparation for exams in any way. Your task is to determine the minimum number of days in which Vasiliy can pass all exams, or determine that it is impossible. Each exam should be passed exactly one time. Input The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of days in the exam period and the number of subjects. The second line contains n integers d1, d2, ..., dn (0 ≤ di ≤ m), where di is the number of subject, the exam of which can be passed on the day number i. If di equals 0, it is not allowed to pass any exams on the day number i. The third line contains m positive integers a1, a2, ..., am (1 ≤ ai ≤ 105), where ai is the number of days that are needed to prepare before passing the exam on the subject i. Output Print one integer — the minimum number of days in which Vasiliy can pass all exams. If it is impossible, print -1. Examples Input 7 2 0 1 0 2 1 0 2 2 1 Output 5 Input 10 3 0 0 1 2 3 0 2 0 1 2 1 1 4 Output 9 Input 5 1 1 1 1 1 1 5 Output -1 Note In the first example Vasiliy can behave as follows. On the first and the second day he can prepare for the exam number 1 and pass it on the fifth day, prepare for the exam number 2 on the third day and pass it on the fourth day. In the second example Vasiliy should prepare for the exam number 3 during the first four days and pass it on the fifth day. Then on the sixth day he should prepare for the exam number 2 and then pass it on the seventh day. After that he needs to prepare for the exam number 1 on the eighth day and pass it on the ninth day. In the third example Vasiliy can't pass the only exam because he hasn't anough time to prepare for it.
instruction
0
47,562
4
95,124
Tags: binary search, greedy, sortings Correct Solution: ``` n, m = map(int, input().split()) a = list(map(int, input().split())) required = list(map(int, input().split())) visited = [False for i in range(m)] count = 0 Sum = sum(required) flag = False for i in range(n): if a[i]!=0: if not visited[a[i]-1]: if i+1 > required[a[i]-1]: count += 1 visited[a[i]-1] = True if count == m and i+1 >= Sum+m: print(i+1) flag = True break if not flag: print(-1) ```
output
1
47,562
4
95,125
Provide tags and a correct Python 3 solution for this coding contest problem. Vasiliy has an exam period which will continue for n days. He has to pass exams on m subjects. Subjects are numbered from 1 to m. About every day we know exam for which one of m subjects can be passed on that day. Perhaps, some day you can't pass any exam. It is not allowed to pass more than one exam on any day. On each day Vasiliy can either pass the exam of that day (it takes the whole day) or prepare all day for some exam or have a rest. About each subject Vasiliy know a number ai — the number of days he should prepare to pass the exam number i. Vasiliy can switch subjects while preparing for exams, it is not necessary to prepare continuously during ai days for the exam number i. He can mix the order of preparation for exams in any way. Your task is to determine the minimum number of days in which Vasiliy can pass all exams, or determine that it is impossible. Each exam should be passed exactly one time. Input The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of days in the exam period and the number of subjects. The second line contains n integers d1, d2, ..., dn (0 ≤ di ≤ m), where di is the number of subject, the exam of which can be passed on the day number i. If di equals 0, it is not allowed to pass any exams on the day number i. The third line contains m positive integers a1, a2, ..., am (1 ≤ ai ≤ 105), where ai is the number of days that are needed to prepare before passing the exam on the subject i. Output Print one integer — the minimum number of days in which Vasiliy can pass all exams. If it is impossible, print -1. Examples Input 7 2 0 1 0 2 1 0 2 2 1 Output 5 Input 10 3 0 0 1 2 3 0 2 0 1 2 1 1 4 Output 9 Input 5 1 1 1 1 1 1 5 Output -1 Note In the first example Vasiliy can behave as follows. On the first and the second day he can prepare for the exam number 1 and pass it on the fifth day, prepare for the exam number 2 on the third day and pass it on the fourth day. In the second example Vasiliy should prepare for the exam number 3 during the first four days and pass it on the fifth day. Then on the sixth day he should prepare for the exam number 2 and then pass it on the seventh day. After that he needs to prepare for the exam number 1 on the eighth day and pass it on the ninth day. In the third example Vasiliy can't pass the only exam because he hasn't anough time to prepare for it.
instruction
0
47,563
4
95,126
Tags: binary search, greedy, sortings Correct Solution: ``` def check(i): used = [0] * m k = 0 for i in range(i, -1, -1): if d[i] and not used[d[i] - 1]: k += a[d[i] - 1] used[d[i] - 1] = 1 elif k: k -= 1 return (not k) n, m = map(int, input().split()) d = list(map(int, input().split())) a = list(map(int, input().split())) used = [0] * m k = m i = 0 while i < n: if d[i] and not used[d[i] - 1]: used[d[i] - 1] = 1 k -= 1 if not k: break i += 1 if i == n or not check(n - 1): print(-1) else: l = i - 1 r = n - 1 while l < r - 1: middle = (l + r) // 2 if check(middle): r = middle else: l = middle print(r + 1) ```
output
1
47,563
4
95,127
Provide tags and a correct Python 3 solution for this coding contest problem. Vasiliy has an exam period which will continue for n days. He has to pass exams on m subjects. Subjects are numbered from 1 to m. About every day we know exam for which one of m subjects can be passed on that day. Perhaps, some day you can't pass any exam. It is not allowed to pass more than one exam on any day. On each day Vasiliy can either pass the exam of that day (it takes the whole day) or prepare all day for some exam or have a rest. About each subject Vasiliy know a number ai — the number of days he should prepare to pass the exam number i. Vasiliy can switch subjects while preparing for exams, it is not necessary to prepare continuously during ai days for the exam number i. He can mix the order of preparation for exams in any way. Your task is to determine the minimum number of days in which Vasiliy can pass all exams, or determine that it is impossible. Each exam should be passed exactly one time. Input The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of days in the exam period and the number of subjects. The second line contains n integers d1, d2, ..., dn (0 ≤ di ≤ m), where di is the number of subject, the exam of which can be passed on the day number i. If di equals 0, it is not allowed to pass any exams on the day number i. The third line contains m positive integers a1, a2, ..., am (1 ≤ ai ≤ 105), where ai is the number of days that are needed to prepare before passing the exam on the subject i. Output Print one integer — the minimum number of days in which Vasiliy can pass all exams. If it is impossible, print -1. Examples Input 7 2 0 1 0 2 1 0 2 2 1 Output 5 Input 10 3 0 0 1 2 3 0 2 0 1 2 1 1 4 Output 9 Input 5 1 1 1 1 1 1 5 Output -1 Note In the first example Vasiliy can behave as follows. On the first and the second day he can prepare for the exam number 1 and pass it on the fifth day, prepare for the exam number 2 on the third day and pass it on the fourth day. In the second example Vasiliy should prepare for the exam number 3 during the first four days and pass it on the fifth day. Then on the sixth day he should prepare for the exam number 2 and then pass it on the seventh day. After that he needs to prepare for the exam number 1 on the eighth day and pass it on the ninth day. In the third example Vasiliy can't pass the only exam because he hasn't anough time to prepare for it.
instruction
0
47,564
4
95,128
Tags: binary search, greedy, sortings Correct Solution: ``` from collections import defaultdict def get_last_exam_day(D, limit): last_exam_day = defaultdict(int) for i,m in enumerate(D): if (i > limit): break if (m != 0): last_exam_day[m] = i return last_exam_day def ok(D, A, data): study_counter = [0] * (len(A) + 1) study_subject_index = 0 last_day = [False] * (len(D) + 1) for x in data: last_day[x[0]] = True for day,subject in enumerate(D): if (last_day[day] == True): if (study_counter[subject] < A[subject - 1]): return False else: study_subject = data[study_subject_index][1] study_counter[study_subject] += 1 if (study_counter[study_subject] >= A[study_subject - 1]): study_subject_index += 1 if (study_subject_index >= M): return True return True if __name__ == "__main__": N,M = map(int, input().split()) D = list(map(int, input().split())) A = list(map(int, input().split())) left = 0 right = N exist_result = False while (right - left > 1): med = (right + left) // 2 if (med >= N): left = med continue last_exam_day = get_last_exam_day(D, med) if (len(last_exam_day) < M): left = med continue data = [] for subject in last_exam_day: last_day = last_exam_day[subject] data.append([last_day, subject]) data.sort() if (ok(D, A, data)): right = med exist_result = True else: left = med #print (left, right, med) if (exist_result): print (right + 1) else: print (-1) ```
output
1
47,564
4
95,129
Provide tags and a correct Python 3 solution for this coding contest problem. Vasiliy has an exam period which will continue for n days. He has to pass exams on m subjects. Subjects are numbered from 1 to m. About every day we know exam for which one of m subjects can be passed on that day. Perhaps, some day you can't pass any exam. It is not allowed to pass more than one exam on any day. On each day Vasiliy can either pass the exam of that day (it takes the whole day) or prepare all day for some exam or have a rest. About each subject Vasiliy know a number ai — the number of days he should prepare to pass the exam number i. Vasiliy can switch subjects while preparing for exams, it is not necessary to prepare continuously during ai days for the exam number i. He can mix the order of preparation for exams in any way. Your task is to determine the minimum number of days in which Vasiliy can pass all exams, or determine that it is impossible. Each exam should be passed exactly one time. Input The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of days in the exam period and the number of subjects. The second line contains n integers d1, d2, ..., dn (0 ≤ di ≤ m), where di is the number of subject, the exam of which can be passed on the day number i. If di equals 0, it is not allowed to pass any exams on the day number i. The third line contains m positive integers a1, a2, ..., am (1 ≤ ai ≤ 105), where ai is the number of days that are needed to prepare before passing the exam on the subject i. Output Print one integer — the minimum number of days in which Vasiliy can pass all exams. If it is impossible, print -1. Examples Input 7 2 0 1 0 2 1 0 2 2 1 Output 5 Input 10 3 0 0 1 2 3 0 2 0 1 2 1 1 4 Output 9 Input 5 1 1 1 1 1 1 5 Output -1 Note In the first example Vasiliy can behave as follows. On the first and the second day he can prepare for the exam number 1 and pass it on the fifth day, prepare for the exam number 2 on the third day and pass it on the fourth day. In the second example Vasiliy should prepare for the exam number 3 during the first four days and pass it on the fifth day. Then on the sixth day he should prepare for the exam number 2 and then pass it on the seventh day. After that he needs to prepare for the exam number 1 on the eighth day and pass it on the ninth day. In the third example Vasiliy can't pass the only exam because he hasn't anough time to prepare for it.
instruction
0
47,565
4
95,130
Tags: binary search, greedy, sortings Correct Solution: ``` import math global n,m,d,a d=[] a=[] def intdec(x): return int(x)-1 def check(x): global n,m,d,a vis=[0]*m seq=[] h=0; cnt=0 for i in range(x,-1,-1): if d[i]<0 or vis[d[i]]: if len(seq)<=h: pass else: cnt+=1 if cnt==a[seq[h]]: h+=1; cnt=0 else: vis[d[i]]=1; seq.append(d[i]) if h<m or vis.count(0): return 0 else: return 1 def solve(): global n,m,d,a l=-1; r=n while l<r-1: mid=(l+r)//2 if check(mid): r=mid else: l=mid if r==n: r=-2 return r def main(): global n,m,d,a n,m=map(int,input().split()) d=list(map(intdec,input().split())) a=list(map(int,input().split())) print(solve()+1) if __name__=="__main__": main() ```
output
1
47,565
4
95,131
Provide tags and a correct Python 3 solution for this coding contest problem. Vasiliy has an exam period which will continue for n days. He has to pass exams on m subjects. Subjects are numbered from 1 to m. About every day we know exam for which one of m subjects can be passed on that day. Perhaps, some day you can't pass any exam. It is not allowed to pass more than one exam on any day. On each day Vasiliy can either pass the exam of that day (it takes the whole day) or prepare all day for some exam or have a rest. About each subject Vasiliy know a number ai — the number of days he should prepare to pass the exam number i. Vasiliy can switch subjects while preparing for exams, it is not necessary to prepare continuously during ai days for the exam number i. He can mix the order of preparation for exams in any way. Your task is to determine the minimum number of days in which Vasiliy can pass all exams, or determine that it is impossible. Each exam should be passed exactly one time. Input The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of days in the exam period and the number of subjects. The second line contains n integers d1, d2, ..., dn (0 ≤ di ≤ m), where di is the number of subject, the exam of which can be passed on the day number i. If di equals 0, it is not allowed to pass any exams on the day number i. The third line contains m positive integers a1, a2, ..., am (1 ≤ ai ≤ 105), where ai is the number of days that are needed to prepare before passing the exam on the subject i. Output Print one integer — the minimum number of days in which Vasiliy can pass all exams. If it is impossible, print -1. Examples Input 7 2 0 1 0 2 1 0 2 2 1 Output 5 Input 10 3 0 0 1 2 3 0 2 0 1 2 1 1 4 Output 9 Input 5 1 1 1 1 1 1 5 Output -1 Note In the first example Vasiliy can behave as follows. On the first and the second day he can prepare for the exam number 1 and pass it on the fifth day, prepare for the exam number 2 on the third day and pass it on the fourth day. In the second example Vasiliy should prepare for the exam number 3 during the first four days and pass it on the fifth day. Then on the sixth day he should prepare for the exam number 2 and then pass it on the seventh day. After that he needs to prepare for the exam number 1 on the eighth day and pass it on the ninth day. In the third example Vasiliy can't pass the only exam because he hasn't anough time to prepare for it.
instruction
0
47,566
4
95,132
Tags: binary search, greedy, sortings Correct Solution: ``` #!/usr/bin/env python3 from sys import stdin,stdout def ri(): return map(int, stdin.readline().split()) def solve(ee): dest = [-1 for i in range(m)] for i in range(ee, -1, -1): if d[i] != -1 and dest[d[i]] == -1: dest[d[i]] = i pd = -1 for i in range(ee+1): da = d[i] if da != -1 and dest[da] == i: pd += a[da] pd += 1 if pd > i: return 0 if dest.count(-1): return 0 else: return 1 n, m = ri() d = list(ri()) a = list(ri()) d = [i-1 for i in d] s = 0 e = n while s < e: mid = (e+s)//2 if solve(mid): e = mid else: s = mid+1 if s >= n: print(-1) else: print(s+1) ```
output
1
47,566
4
95,133
Provide tags and a correct Python 3 solution for this coding contest problem. Vasiliy has an exam period which will continue for n days. He has to pass exams on m subjects. Subjects are numbered from 1 to m. About every day we know exam for which one of m subjects can be passed on that day. Perhaps, some day you can't pass any exam. It is not allowed to pass more than one exam on any day. On each day Vasiliy can either pass the exam of that day (it takes the whole day) or prepare all day for some exam or have a rest. About each subject Vasiliy know a number ai — the number of days he should prepare to pass the exam number i. Vasiliy can switch subjects while preparing for exams, it is not necessary to prepare continuously during ai days for the exam number i. He can mix the order of preparation for exams in any way. Your task is to determine the minimum number of days in which Vasiliy can pass all exams, or determine that it is impossible. Each exam should be passed exactly one time. Input The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of days in the exam period and the number of subjects. The second line contains n integers d1, d2, ..., dn (0 ≤ di ≤ m), where di is the number of subject, the exam of which can be passed on the day number i. If di equals 0, it is not allowed to pass any exams on the day number i. The third line contains m positive integers a1, a2, ..., am (1 ≤ ai ≤ 105), where ai is the number of days that are needed to prepare before passing the exam on the subject i. Output Print one integer — the minimum number of days in which Vasiliy can pass all exams. If it is impossible, print -1. Examples Input 7 2 0 1 0 2 1 0 2 2 1 Output 5 Input 10 3 0 0 1 2 3 0 2 0 1 2 1 1 4 Output 9 Input 5 1 1 1 1 1 1 5 Output -1 Note In the first example Vasiliy can behave as follows. On the first and the second day he can prepare for the exam number 1 and pass it on the fifth day, prepare for the exam number 2 on the third day and pass it on the fourth day. In the second example Vasiliy should prepare for the exam number 3 during the first four days and pass it on the fifth day. Then on the sixth day he should prepare for the exam number 2 and then pass it on the seventh day. After that he needs to prepare for the exam number 1 on the eighth day and pass it on the ninth day. In the third example Vasiliy can't pass the only exam because he hasn't anough time to prepare for it.
instruction
0
47,567
4
95,134
Tags: binary search, greedy, sortings Correct Solution: ``` import sys n,m=map(int,input().split()) di=list(map(int,input().split())) ai=list(map(int,input().split())) check=[False]*m temp=0 summ=sum(ai)+m for i in range(n): if di[i]==0: continue else: if not check[di[i]-1]: if ai[di[i]-1]<=i: temp+=1 #print(i,end=" ") check[di[i]-1]=True if temp==m: # print(check) if i+1>=summ: print(i+1) sys.exit() print(-1) ```
output
1
47,567
4
95,135
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasiliy has an exam period which will continue for n days. He has to pass exams on m subjects. Subjects are numbered from 1 to m. About every day we know exam for which one of m subjects can be passed on that day. Perhaps, some day you can't pass any exam. It is not allowed to pass more than one exam on any day. On each day Vasiliy can either pass the exam of that day (it takes the whole day) or prepare all day for some exam or have a rest. About each subject Vasiliy know a number ai — the number of days he should prepare to pass the exam number i. Vasiliy can switch subjects while preparing for exams, it is not necessary to prepare continuously during ai days for the exam number i. He can mix the order of preparation for exams in any way. Your task is to determine the minimum number of days in which Vasiliy can pass all exams, or determine that it is impossible. Each exam should be passed exactly one time. Input The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of days in the exam period and the number of subjects. The second line contains n integers d1, d2, ..., dn (0 ≤ di ≤ m), where di is the number of subject, the exam of which can be passed on the day number i. If di equals 0, it is not allowed to pass any exams on the day number i. The third line contains m positive integers a1, a2, ..., am (1 ≤ ai ≤ 105), where ai is the number of days that are needed to prepare before passing the exam on the subject i. Output Print one integer — the minimum number of days in which Vasiliy can pass all exams. If it is impossible, print -1. Examples Input 7 2 0 1 0 2 1 0 2 2 1 Output 5 Input 10 3 0 0 1 2 3 0 2 0 1 2 1 1 4 Output 9 Input 5 1 1 1 1 1 1 5 Output -1 Note In the first example Vasiliy can behave as follows. On the first and the second day he can prepare for the exam number 1 and pass it on the fifth day, prepare for the exam number 2 on the third day and pass it on the fourth day. In the second example Vasiliy should prepare for the exam number 3 during the first four days and pass it on the fifth day. Then on the sixth day he should prepare for the exam number 2 and then pass it on the seventh day. After that he needs to prepare for the exam number 1 on the eighth day and pass it on the ninth day. In the third example Vasiliy can't pass the only exam because he hasn't anough time to prepare for it. Submitted Solution: ``` def ch(ind): vis = [0 for i in range(m)] k=0 for i in range(ind,-1,-1): if d[i] and not vis[d[i]-1]: k+=a[d[i]-1] vis[d[i]-1]=1 else: if k: k-=1 return 0 if k else -1 n,m=map(int,input().split()) d=list(map(int,input().split())) a=list(map(int,input().split())) vis=[0 for i in range(m)] mid=m i=0 while(i<n): if d[i] and not vis[d[i] - 1]: mid-=1 vis[d[i] - 1] = 1 if mid: pass else: break i+=1 if i==n or not ch(n-1): print('-1') exit(0) l=i-1 r=n-1 while(l<r-1): mx=(l+r)//2 if(ch(mx)): r=mx else: l=mx print(l+2) ```
instruction
0
47,568
4
95,136
Yes
output
1
47,568
4
95,137
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasiliy has an exam period which will continue for n days. He has to pass exams on m subjects. Subjects are numbered from 1 to m. About every day we know exam for which one of m subjects can be passed on that day. Perhaps, some day you can't pass any exam. It is not allowed to pass more than one exam on any day. On each day Vasiliy can either pass the exam of that day (it takes the whole day) or prepare all day for some exam or have a rest. About each subject Vasiliy know a number ai — the number of days he should prepare to pass the exam number i. Vasiliy can switch subjects while preparing for exams, it is not necessary to prepare continuously during ai days for the exam number i. He can mix the order of preparation for exams in any way. Your task is to determine the minimum number of days in which Vasiliy can pass all exams, or determine that it is impossible. Each exam should be passed exactly one time. Input The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of days in the exam period and the number of subjects. The second line contains n integers d1, d2, ..., dn (0 ≤ di ≤ m), where di is the number of subject, the exam of which can be passed on the day number i. If di equals 0, it is not allowed to pass any exams on the day number i. The third line contains m positive integers a1, a2, ..., am (1 ≤ ai ≤ 105), where ai is the number of days that are needed to prepare before passing the exam on the subject i. Output Print one integer — the minimum number of days in which Vasiliy can pass all exams. If it is impossible, print -1. Examples Input 7 2 0 1 0 2 1 0 2 2 1 Output 5 Input 10 3 0 0 1 2 3 0 2 0 1 2 1 1 4 Output 9 Input 5 1 1 1 1 1 1 5 Output -1 Note In the first example Vasiliy can behave as follows. On the first and the second day he can prepare for the exam number 1 and pass it on the fifth day, prepare for the exam number 2 on the third day and pass it on the fourth day. In the second example Vasiliy should prepare for the exam number 3 during the first four days and pass it on the fifth day. Then on the sixth day he should prepare for the exam number 2 and then pass it on the seventh day. After that he needs to prepare for the exam number 1 on the eighth day and pass it on the ninth day. In the third example Vasiliy can't pass the only exam because he hasn't anough time to prepare for it. Submitted Solution: ``` import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") ########################################################## #print('%d %d' %ans) from collections import Counter import math #for _ in range(int(input())): #n=int(input()) from collections import Counter def can(days): d=Counter(arr[:days]) v=[0]*k free=0 cnt=0 for i in range(days): if arr[i]==0: free+=1 else: if free>=ls[arr[i]-1] and v[arr[i]-1]==False: if d[arr[i]]==1: cnt+=1 #d[arr[i]]-=1 free-=ls[arr[i]-1] v[arr[i]-1]=True else: free+=1 d[arr[i]]-=1 else: d[arr[i]]-=1 free+=1 #if days==5:print(d) #if days==5: #print(v) if cnt==k: #print("1", 1) return True else: return False n,k= map(int, input().split()) arr=list(map(int,input().split())) ls=list(map(int,input().split())) l=sum(ls) r=n ans=-1 while l<=r: mid=(l+r)//2 #print("mid",mid) if can(mid): ans=mid #print("ans",ans) r=mid-1 else: l=mid+1 print(ans) ```
instruction
0
47,569
4
95,138
Yes
output
1
47,569
4
95,139
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasiliy has an exam period which will continue for n days. He has to pass exams on m subjects. Subjects are numbered from 1 to m. About every day we know exam for which one of m subjects can be passed on that day. Perhaps, some day you can't pass any exam. It is not allowed to pass more than one exam on any day. On each day Vasiliy can either pass the exam of that day (it takes the whole day) or prepare all day for some exam or have a rest. About each subject Vasiliy know a number ai — the number of days he should prepare to pass the exam number i. Vasiliy can switch subjects while preparing for exams, it is not necessary to prepare continuously during ai days for the exam number i. He can mix the order of preparation for exams in any way. Your task is to determine the minimum number of days in which Vasiliy can pass all exams, or determine that it is impossible. Each exam should be passed exactly one time. Input The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of days in the exam period and the number of subjects. The second line contains n integers d1, d2, ..., dn (0 ≤ di ≤ m), where di is the number of subject, the exam of which can be passed on the day number i. If di equals 0, it is not allowed to pass any exams on the day number i. The third line contains m positive integers a1, a2, ..., am (1 ≤ ai ≤ 105), where ai is the number of days that are needed to prepare before passing the exam on the subject i. Output Print one integer — the minimum number of days in which Vasiliy can pass all exams. If it is impossible, print -1. Examples Input 7 2 0 1 0 2 1 0 2 2 1 Output 5 Input 10 3 0 0 1 2 3 0 2 0 1 2 1 1 4 Output 9 Input 5 1 1 1 1 1 1 5 Output -1 Note In the first example Vasiliy can behave as follows. On the first and the second day he can prepare for the exam number 1 and pass it on the fifth day, prepare for the exam number 2 on the third day and pass it on the fourth day. In the second example Vasiliy should prepare for the exam number 3 during the first four days and pass it on the fifth day. Then on the sixth day he should prepare for the exam number 2 and then pass it on the seventh day. After that he needs to prepare for the exam number 1 on the eighth day and pass it on the ninth day. In the third example Vasiliy can't pass the only exam because he hasn't anough time to prepare for it. Submitted Solution: ``` n,m = map(int, input().split()) dias = [int(x) for x in input().split()] prep = [int(x) for x in input().split()] def isposi(nu): faltan = set(range(1,m+1)) porestudiar = 0 for i in reversed(range(min(nu, n))): if dias[i] in faltan: faltan.remove(dias[i]) porestudiar+=prep[dias[i]-1] elif porestudiar > 0: porestudiar -= 1 return len(faltan)==0 and porestudiar == 0 if not isposi(n): print(-1) else: lo,hi=0,n while(hi> lo): mid = (hi+lo)//2 if isposi(mid): hi = mid else: lo = mid+1 print(lo) ```
instruction
0
47,570
4
95,140
Yes
output
1
47,570
4
95,141
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasiliy has an exam period which will continue for n days. He has to pass exams on m subjects. Subjects are numbered from 1 to m. About every day we know exam for which one of m subjects can be passed on that day. Perhaps, some day you can't pass any exam. It is not allowed to pass more than one exam on any day. On each day Vasiliy can either pass the exam of that day (it takes the whole day) or prepare all day for some exam or have a rest. About each subject Vasiliy know a number ai — the number of days he should prepare to pass the exam number i. Vasiliy can switch subjects while preparing for exams, it is not necessary to prepare continuously during ai days for the exam number i. He can mix the order of preparation for exams in any way. Your task is to determine the minimum number of days in which Vasiliy can pass all exams, or determine that it is impossible. Each exam should be passed exactly one time. Input The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of days in the exam period and the number of subjects. The second line contains n integers d1, d2, ..., dn (0 ≤ di ≤ m), where di is the number of subject, the exam of which can be passed on the day number i. If di equals 0, it is not allowed to pass any exams on the day number i. The third line contains m positive integers a1, a2, ..., am (1 ≤ ai ≤ 105), where ai is the number of days that are needed to prepare before passing the exam on the subject i. Output Print one integer — the minimum number of days in which Vasiliy can pass all exams. If it is impossible, print -1. Examples Input 7 2 0 1 0 2 1 0 2 2 1 Output 5 Input 10 3 0 0 1 2 3 0 2 0 1 2 1 1 4 Output 9 Input 5 1 1 1 1 1 1 5 Output -1 Note In the first example Vasiliy can behave as follows. On the first and the second day he can prepare for the exam number 1 and pass it on the fifth day, prepare for the exam number 2 on the third day and pass it on the fourth day. In the second example Vasiliy should prepare for the exam number 3 during the first four days and pass it on the fifth day. Then on the sixth day he should prepare for the exam number 2 and then pass it on the seventh day. After that he needs to prepare for the exam number 1 on the eighth day and pass it on the ninth day. In the third example Vasiliy can't pass the only exam because he hasn't anough time to prepare for it. Submitted Solution: ``` from collections import deque def main(): n, m = list(map(int, input().split())) test = list(map(int, input().split())) prepare = list(map(int, input().split())) least_days = sum(prepare) + m if least_days > len(test): print(-1) return index = list() for p in range(m + 1): index.append(deque()) for t in range(len(test)): if test[t] == 0: continue index[test[t]].append(t) if t >= least_days - 1: index[0].append(t) if deque([]) in index: print(-1) return min_index = max(list(map(lambda x: x.popleft(), index[1:]))) min_index = max(least_days - 1, min_index) for x in index[0]: if x >= min_index: print(x + 1) break if __name__ == '__main__': main() ```
instruction
0
47,571
4
95,142
Yes
output
1
47,571
4
95,143
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasiliy has an exam period which will continue for n days. He has to pass exams on m subjects. Subjects are numbered from 1 to m. About every day we know exam for which one of m subjects can be passed on that day. Perhaps, some day you can't pass any exam. It is not allowed to pass more than one exam on any day. On each day Vasiliy can either pass the exam of that day (it takes the whole day) or prepare all day for some exam or have a rest. About each subject Vasiliy know a number ai — the number of days he should prepare to pass the exam number i. Vasiliy can switch subjects while preparing for exams, it is not necessary to prepare continuously during ai days for the exam number i. He can mix the order of preparation for exams in any way. Your task is to determine the minimum number of days in which Vasiliy can pass all exams, or determine that it is impossible. Each exam should be passed exactly one time. Input The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of days in the exam period and the number of subjects. The second line contains n integers d1, d2, ..., dn (0 ≤ di ≤ m), where di is the number of subject, the exam of which can be passed on the day number i. If di equals 0, it is not allowed to pass any exams on the day number i. The third line contains m positive integers a1, a2, ..., am (1 ≤ ai ≤ 105), where ai is the number of days that are needed to prepare before passing the exam on the subject i. Output Print one integer — the minimum number of days in which Vasiliy can pass all exams. If it is impossible, print -1. Examples Input 7 2 0 1 0 2 1 0 2 2 1 Output 5 Input 10 3 0 0 1 2 3 0 2 0 1 2 1 1 4 Output 9 Input 5 1 1 1 1 1 1 5 Output -1 Note In the first example Vasiliy can behave as follows. On the first and the second day he can prepare for the exam number 1 and pass it on the fifth day, prepare for the exam number 2 on the third day and pass it on the fourth day. In the second example Vasiliy should prepare for the exam number 3 during the first four days and pass it on the fifth day. Then on the sixth day he should prepare for the exam number 2 and then pass it on the seventh day. After that he needs to prepare for the exam number 1 on the eighth day and pass it on the ninth day. In the third example Vasiliy can't pass the only exam because he hasn't anough time to prepare for it. Submitted Solution: ``` def check(now): last=[0 for i in range(0,m+1)] ddl=[] last[0]=-1 for i in range(now,1,-1): if last[d[i]]==0: ddl.append(d[i]) last[d[i]]=i day=0 if len(ddl)!=m: return False for i in range(1,m+1): # print(a[ddl[-i]]) day+=a[ddl[-i]] if day>=last[ddl[-i]]: return False return True a=input() a=a.split() n=int(a[0]) m=int(a[1]) d=input() d=d.split() a=input() a=a.split() a=[0]+a d=[0]+d for i in range(0,n+1): d[i]=int(d[i]) for i in range(0,m+1): a[i]=int(a[i]) l=0 r=n+1 while l<r-1: mid=(l+r)>>1 if check(mid): r=mid else: l=mid if r==n+1: print(-1) else: print(r) ```
instruction
0
47,572
4
95,144
No
output
1
47,572
4
95,145
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasiliy has an exam period which will continue for n days. He has to pass exams on m subjects. Subjects are numbered from 1 to m. About every day we know exam for which one of m subjects can be passed on that day. Perhaps, some day you can't pass any exam. It is not allowed to pass more than one exam on any day. On each day Vasiliy can either pass the exam of that day (it takes the whole day) or prepare all day for some exam or have a rest. About each subject Vasiliy know a number ai — the number of days he should prepare to pass the exam number i. Vasiliy can switch subjects while preparing for exams, it is not necessary to prepare continuously during ai days for the exam number i. He can mix the order of preparation for exams in any way. Your task is to determine the minimum number of days in which Vasiliy can pass all exams, or determine that it is impossible. Each exam should be passed exactly one time. Input The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of days in the exam period and the number of subjects. The second line contains n integers d1, d2, ..., dn (0 ≤ di ≤ m), where di is the number of subject, the exam of which can be passed on the day number i. If di equals 0, it is not allowed to pass any exams on the day number i. The third line contains m positive integers a1, a2, ..., am (1 ≤ ai ≤ 105), where ai is the number of days that are needed to prepare before passing the exam on the subject i. Output Print one integer — the minimum number of days in which Vasiliy can pass all exams. If it is impossible, print -1. Examples Input 7 2 0 1 0 2 1 0 2 2 1 Output 5 Input 10 3 0 0 1 2 3 0 2 0 1 2 1 1 4 Output 9 Input 5 1 1 1 1 1 1 5 Output -1 Note In the first example Vasiliy can behave as follows. On the first and the second day he can prepare for the exam number 1 and pass it on the fifth day, prepare for the exam number 2 on the third day and pass it on the fourth day. In the second example Vasiliy should prepare for the exam number 3 during the first four days and pass it on the fifth day. Then on the sixth day he should prepare for the exam number 2 and then pass it on the seventh day. After that he needs to prepare for the exam number 1 on the eighth day and pass it on the ninth day. In the third example Vasiliy can't pass the only exam because he hasn't anough time to prepare for it. Submitted Solution: ``` n, m = map(int, input().split()) d = list(map(int, input().split())) a = list(map(int, input().split())) def check_solution(k): ad, s = 0, 0 u = [False] * (m + 1) for i in reversed(range(k)): if d[i] != 0 and not u[d[i]]: ad -= a[d[i] - 1] u[d[i]] = True s += 1 else: ad += 1 return s == m and ad >= 0 def main(): l = 0 r = n + 1 while l < r: mi = (r + l) // 2 mv = check_solution(mi) # print(mi, mv, l, r) if mv: r = mi else: l = mi + 1 if l <= n: print(l) else: print(-1) main() ```
instruction
0
47,573
4
95,146
No
output
1
47,573
4
95,147
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasiliy has an exam period which will continue for n days. He has to pass exams on m subjects. Subjects are numbered from 1 to m. About every day we know exam for which one of m subjects can be passed on that day. Perhaps, some day you can't pass any exam. It is not allowed to pass more than one exam on any day. On each day Vasiliy can either pass the exam of that day (it takes the whole day) or prepare all day for some exam or have a rest. About each subject Vasiliy know a number ai — the number of days he should prepare to pass the exam number i. Vasiliy can switch subjects while preparing for exams, it is not necessary to prepare continuously during ai days for the exam number i. He can mix the order of preparation for exams in any way. Your task is to determine the minimum number of days in which Vasiliy can pass all exams, or determine that it is impossible. Each exam should be passed exactly one time. Input The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of days in the exam period and the number of subjects. The second line contains n integers d1, d2, ..., dn (0 ≤ di ≤ m), where di is the number of subject, the exam of which can be passed on the day number i. If di equals 0, it is not allowed to pass any exams on the day number i. The third line contains m positive integers a1, a2, ..., am (1 ≤ ai ≤ 105), where ai is the number of days that are needed to prepare before passing the exam on the subject i. Output Print one integer — the minimum number of days in which Vasiliy can pass all exams. If it is impossible, print -1. Examples Input 7 2 0 1 0 2 1 0 2 2 1 Output 5 Input 10 3 0 0 1 2 3 0 2 0 1 2 1 1 4 Output 9 Input 5 1 1 1 1 1 1 5 Output -1 Note In the first example Vasiliy can behave as follows. On the first and the second day he can prepare for the exam number 1 and pass it on the fifth day, prepare for the exam number 2 on the third day and pass it on the fourth day. In the second example Vasiliy should prepare for the exam number 3 during the first four days and pass it on the fifth day. Then on the sixth day he should prepare for the exam number 2 and then pass it on the seventh day. After that he needs to prepare for the exam number 1 on the eighth day and pass it on the ninth day. In the third example Vasiliy can't pass the only exam because he hasn't anough time to prepare for it. Submitted Solution: ``` n,m = map(int,input().split()) arr = list(map(int,input().split())) prep = list(map(int,input().split())) #mp = dict() total = sum(prep) + m #for i in range(1,m+1): # mp[i] = prep[i-1] #print(mp) st = set() ans = 0 flag = 0 for i in range(n): st.add(arr[i]) #print(st,i+1,total) if ((0 in st and len(st)==(m+1)) or ( 0 not in st and len(st)==m) ) and (i+1)>=total and arr[i]: ans = i + 1 flag = 1 break if flag : print(ans) else: print(-1) ```
instruction
0
47,574
4
95,148
No
output
1
47,574
4
95,149
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasiliy has an exam period which will continue for n days. He has to pass exams on m subjects. Subjects are numbered from 1 to m. About every day we know exam for which one of m subjects can be passed on that day. Perhaps, some day you can't pass any exam. It is not allowed to pass more than one exam on any day. On each day Vasiliy can either pass the exam of that day (it takes the whole day) or prepare all day for some exam or have a rest. About each subject Vasiliy know a number ai — the number of days he should prepare to pass the exam number i. Vasiliy can switch subjects while preparing for exams, it is not necessary to prepare continuously during ai days for the exam number i. He can mix the order of preparation for exams in any way. Your task is to determine the minimum number of days in which Vasiliy can pass all exams, or determine that it is impossible. Each exam should be passed exactly one time. Input The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of days in the exam period and the number of subjects. The second line contains n integers d1, d2, ..., dn (0 ≤ di ≤ m), where di is the number of subject, the exam of which can be passed on the day number i. If di equals 0, it is not allowed to pass any exams on the day number i. The third line contains m positive integers a1, a2, ..., am (1 ≤ ai ≤ 105), where ai is the number of days that are needed to prepare before passing the exam on the subject i. Output Print one integer — the minimum number of days in which Vasiliy can pass all exams. If it is impossible, print -1. Examples Input 7 2 0 1 0 2 1 0 2 2 1 Output 5 Input 10 3 0 0 1 2 3 0 2 0 1 2 1 1 4 Output 9 Input 5 1 1 1 1 1 1 5 Output -1 Note In the first example Vasiliy can behave as follows. On the first and the second day he can prepare for the exam number 1 and pass it on the fifth day, prepare for the exam number 2 on the third day and pass it on the fourth day. In the second example Vasiliy should prepare for the exam number 3 during the first four days and pass it on the fifth day. Then on the sixth day he should prepare for the exam number 2 and then pass it on the seventh day. After that he needs to prepare for the exam number 1 on the eighth day and pass it on the ninth day. In the third example Vasiliy can't pass the only exam because he hasn't anough time to prepare for it. Submitted Solution: ``` def zip_sorted(a,b): # sorted by a a,b = zip(*sorted(zip(a,b))) # sorted by b sorted(zip(a, b), key=lambda x: x[0]) return a,b def zip_sorted1(a,b,c): # sorted by a a,b,c = zip(*sorted(zip(a,b,c))) # sorted by b sorted(zip(a,b,c), key=lambda x: x[0]) return a,b,c n,m = [int(n1) for n1 in input().split()] sub_on_day = [int(n1) for n1 in input().split()] day_req = [int(n1) for n1 in input().split()] day_prep = [0 for n1 in range(n)] done_sub = [0 for n1 in range(m)] count = 0 for i in range(n): day_prep[i] = count count = count + 1 tot = 0 count = 0 for i in range(n): if sub_on_day!=0: if sub_on_day[i]-1 != m-1: if done_sub[sub_on_day[i]-1]!=1 and done_sub[sub_on_day[i]]==1: if day_req[sub_on_day[i]-1]<=(day_prep[i]-tot): tot = tot + day_req[sub_on_day[i]-1] + 1 count = count + 1 done_sub[sub_on_day[i]-1] = 1 else: if done_sub[sub_on_day[i]-1]!=1: if day_req[sub_on_day[i]-1]<=(day_prep[i]-tot): tot = tot + day_req[sub_on_day[i]-1] + 1 count = count + 1 done_sub[sub_on_day[i]-1] = 1 if sum(done_sub)==m: print(i+1) count = 1 break if count==0: print(-1) ''' for i in range(n): for j in range(n): for k1 in range(len(a)): for k2 in range(len(a)): for k3 in range(len(a)): ''' ```
instruction
0
47,575
4
95,150
No
output
1
47,575
4
95,151
Provide a correct Python 3 solution for this coding contest problem. On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it. Constraints * S is a string of length 10. * The first eight characters in S are `2017/01/`. * The last two characters in S are digits and represent an integer between 1 and 31 (inclusive). Input Input is given from Standard Input in the following format: S Output Replace the first four characters in S with `2018` and print it. Examples Input 2017/01/07 Output 2018/01/07 Input 2017/01/31 Output 2018/01/31
instruction
0
47,784
4
95,568
"Correct Solution: ``` str = input() print('2018/' + str[5:]) ```
output
1
47,784
4
95,569
Provide a correct Python 3 solution for this coding contest problem. On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it. Constraints * S is a string of length 10. * The first eight characters in S are `2017/01/`. * The last two characters in S are digits and represent an integer between 1 and 31 (inclusive). Input Input is given from Standard Input in the following format: S Output Replace the first four characters in S with `2018` and print it. Examples Input 2017/01/07 Output 2018/01/07 Input 2017/01/31 Output 2018/01/31
instruction
0
47,785
4
95,570
"Correct Solution: ``` s=input() t="2018"+s[4:] print(t) ```
output
1
47,785
4
95,571
Provide a correct Python 3 solution for this coding contest problem. On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it. Constraints * S is a string of length 10. * The first eight characters in S are `2017/01/`. * The last two characters in S are digits and represent an integer between 1 and 31 (inclusive). Input Input is given from Standard Input in the following format: S Output Replace the first four characters in S with `2018` and print it. Examples Input 2017/01/07 Output 2018/01/07 Input 2017/01/31 Output 2018/01/31
instruction
0
47,786
4
95,572
"Correct Solution: ``` s = input() print(s.replace('7', '8', 1)) ```
output
1
47,786
4
95,573
Provide a correct Python 3 solution for this coding contest problem. On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it. Constraints * S is a string of length 10. * The first eight characters in S are `2017/01/`. * The last two characters in S are digits and represent an integer between 1 and 31 (inclusive). Input Input is given from Standard Input in the following format: S Output Replace the first four characters in S with `2018` and print it. Examples Input 2017/01/07 Output 2018/01/07 Input 2017/01/31 Output 2018/01/31
instruction
0
47,787
4
95,574
"Correct Solution: ``` s = input() print(s[:3]+'8'+s[-6:]) ```
output
1
47,787
4
95,575
Provide a correct Python 3 solution for this coding contest problem. On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it. Constraints * S is a string of length 10. * The first eight characters in S are `2017/01/`. * The last two characters in S are digits and represent an integer between 1 and 31 (inclusive). Input Input is given from Standard Input in the following format: S Output Replace the first four characters in S with `2018` and print it. Examples Input 2017/01/07 Output 2018/01/07 Input 2017/01/31 Output 2018/01/31
instruction
0
47,788
4
95,576
"Correct Solution: ``` a = input() print(a[:3]+'8'+a[4:]) ```
output
1
47,788
4
95,577
Provide a correct Python 3 solution for this coding contest problem. On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it. Constraints * S is a string of length 10. * The first eight characters in S are `2017/01/`. * The last two characters in S are digits and represent an integer between 1 and 31 (inclusive). Input Input is given from Standard Input in the following format: S Output Replace the first four characters in S with `2018` and print it. Examples Input 2017/01/07 Output 2018/01/07 Input 2017/01/31 Output 2018/01/31
instruction
0
47,789
4
95,578
"Correct Solution: ``` s = input() x = "2018" + s[4:] print(x) ```
output
1
47,789
4
95,579
Provide a correct Python 3 solution for this coding contest problem. On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it. Constraints * S is a string of length 10. * The first eight characters in S are `2017/01/`. * The last two characters in S are digits and represent an integer between 1 and 31 (inclusive). Input Input is given from Standard Input in the following format: S Output Replace the first four characters in S with `2018` and print it. Examples Input 2017/01/07 Output 2018/01/07 Input 2017/01/31 Output 2018/01/31
instruction
0
47,790
4
95,580
"Correct Solution: ``` s=input();print(s[:3]+'8'+s[4:]) ```
output
1
47,790
4
95,581