text
stringlengths
198
433k
conversation_id
int64
0
109k
Provide tags and a correct Python 3 solution for this coding contest problem. As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without quotes)). On the last lesson Anton learned about the regular simple bracket sequences (RSBS). A bracket sequence s of length n is an RSBS if the following conditions are met: * It is not empty (that is n β‰  0). * The length of the sequence is even. * First <image> charactes of the sequence are equal to "(". * Last <image> charactes of the sequence are equal to ")". For example, the sequence "((()))" is an RSBS but the sequences "((())" and "(()())" are not RSBS. Elena Ivanovna, Anton's teacher, gave him the following task as a homework. Given a bracket sequence s. Find the number of its distinct subsequences such that they are RSBS. Note that a subsequence of s is a string that can be obtained from s by deleting some of its elements. Two subsequences are considered distinct if distinct sets of positions are deleted. Because the answer can be very big and Anton's teacher doesn't like big numbers, she asks Anton to find the answer modulo 109 + 7. Anton thought of this task for a very long time, but he still doesn't know how to solve it. Help Anton to solve this task and write a program that finds the answer for it! Input The only line of the input contains a string s β€” the bracket sequence given in Anton's homework. The string consists only of characters "(" and ")" (without quotes). It's guaranteed that the string is not empty and its length doesn't exceed 200 000. Output Output one number β€” the answer for the task modulo 109 + 7. Examples Input )(()() Output 6 Input ()()() Output 7 Input ))) Output 0 Note In the first sample the following subsequences are possible: * If we delete characters at the positions 1 and 5 (numbering starts with one), we will get the subsequence "(())". * If we delete characters at the positions 1, 2, 3 and 4, we will get the subsequence "()". * If we delete characters at the positions 1, 2, 4 and 5, we will get the subsequence "()". * If we delete characters at the positions 1, 2, 5 and 6, we will get the subsequence "()". * If we delete characters at the positions 1, 3, 4 and 5, we will get the subsequence "()". * If we delete characters at the positions 1, 3, 5 and 6, we will get the subsequence "()". The rest of the subsequnces are not RSBS. So we got 6 distinct subsequences that are RSBS, so the answer is 6. Tags: combinatorics, dp, math, number theory Correct Solution: ``` mod = 10 ** 9 + 7 s = input() n = len(s) f = [1] * (n + 1) for i in range(1, n + 1): f[i] = i * f[i - 1] % mod finv = [pow(x, mod - 2, mod) for x in f] op = 0 cl = s.count(')') ans = 0 if cl > 0: for c in s: if c == '(': op += 1 ans += f[op + cl - 1] * finv[cl - 1] * finv[op] elif cl <= 1: break else: cl -= 1 print(ans % mod) #bruno ```
90,600
Provide tags and a correct Python 3 solution for this coding contest problem. As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without quotes)). On the last lesson Anton learned about the regular simple bracket sequences (RSBS). A bracket sequence s of length n is an RSBS if the following conditions are met: * It is not empty (that is n β‰  0). * The length of the sequence is even. * First <image> charactes of the sequence are equal to "(". * Last <image> charactes of the sequence are equal to ")". For example, the sequence "((()))" is an RSBS but the sequences "((())" and "(()())" are not RSBS. Elena Ivanovna, Anton's teacher, gave him the following task as a homework. Given a bracket sequence s. Find the number of its distinct subsequences such that they are RSBS. Note that a subsequence of s is a string that can be obtained from s by deleting some of its elements. Two subsequences are considered distinct if distinct sets of positions are deleted. Because the answer can be very big and Anton's teacher doesn't like big numbers, she asks Anton to find the answer modulo 109 + 7. Anton thought of this task for a very long time, but he still doesn't know how to solve it. Help Anton to solve this task and write a program that finds the answer for it! Input The only line of the input contains a string s β€” the bracket sequence given in Anton's homework. The string consists only of characters "(" and ")" (without quotes). It's guaranteed that the string is not empty and its length doesn't exceed 200 000. Output Output one number β€” the answer for the task modulo 109 + 7. Examples Input )(()() Output 6 Input ()()() Output 7 Input ))) Output 0 Note In the first sample the following subsequences are possible: * If we delete characters at the positions 1 and 5 (numbering starts with one), we will get the subsequence "(())". * If we delete characters at the positions 1, 2, 3 and 4, we will get the subsequence "()". * If we delete characters at the positions 1, 2, 4 and 5, we will get the subsequence "()". * If we delete characters at the positions 1, 2, 5 and 6, we will get the subsequence "()". * If we delete characters at the positions 1, 3, 4 and 5, we will get the subsequence "()". * If we delete characters at the positions 1, 3, 5 and 6, we will get the subsequence "()". The rest of the subsequnces are not RSBS. So we got 6 distinct subsequences that are RSBS, so the answer is 6. Tags: combinatorics, dp, math, number theory Correct Solution: ``` p = 10**9+7 def power(x, y, p): b = bin(y)[2:] answer = 1 start = x % p for i in range(len(b)): if b[len(b)-1-i]=='1': answer = (answer*start) % p start = (start*start) % p return answer def process(S): answer = 0 n = len(S) left_count = 0 right_count = 0 p_lc = 1 p_rc = 1 p_num = 1 num = 0 for c in S: if c==')': right_count+=1 p_rc = (p_rc*(right_count+1)) % p num+=1 p_num = (p_num*num) % p for i in range(n): if S[i]=='(': left_count+=1 if left_count > 1: p_lc = (p_lc*(left_count-1)) % p num+=1 p_num = (p_num*num) % p else: p_rc = (p_rc*power(right_count+1, p-2, p)) % p p_num = (p_num*power(num, p-2, p)) % p right_count-=1 num-=1 #(left_count choose n, right_count choose n-1) #(left_count choose n, right_count choose rc-n+1)) #(lc+rc choose rc+1) if left_count > 0: entry = (p_num*power(p_lc, p-2, p)*power(p_rc, p-2, p)) % p answer = (answer+entry) % p return answer S = input() print(process(S)) ```
90,601
Provide tags and a correct Python 3 solution for this coding contest problem. As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without quotes)). On the last lesson Anton learned about the regular simple bracket sequences (RSBS). A bracket sequence s of length n is an RSBS if the following conditions are met: * It is not empty (that is n β‰  0). * The length of the sequence is even. * First <image> charactes of the sequence are equal to "(". * Last <image> charactes of the sequence are equal to ")". For example, the sequence "((()))" is an RSBS but the sequences "((())" and "(()())" are not RSBS. Elena Ivanovna, Anton's teacher, gave him the following task as a homework. Given a bracket sequence s. Find the number of its distinct subsequences such that they are RSBS. Note that a subsequence of s is a string that can be obtained from s by deleting some of its elements. Two subsequences are considered distinct if distinct sets of positions are deleted. Because the answer can be very big and Anton's teacher doesn't like big numbers, she asks Anton to find the answer modulo 109 + 7. Anton thought of this task for a very long time, but he still doesn't know how to solve it. Help Anton to solve this task and write a program that finds the answer for it! Input The only line of the input contains a string s β€” the bracket sequence given in Anton's homework. The string consists only of characters "(" and ")" (without quotes). It's guaranteed that the string is not empty and its length doesn't exceed 200 000. Output Output one number β€” the answer for the task modulo 109 + 7. Examples Input )(()() Output 6 Input ()()() Output 7 Input ))) Output 0 Note In the first sample the following subsequences are possible: * If we delete characters at the positions 1 and 5 (numbering starts with one), we will get the subsequence "(())". * If we delete characters at the positions 1, 2, 3 and 4, we will get the subsequence "()". * If we delete characters at the positions 1, 2, 4 and 5, we will get the subsequence "()". * If we delete characters at the positions 1, 2, 5 and 6, we will get the subsequence "()". * If we delete characters at the positions 1, 3, 4 and 5, we will get the subsequence "()". * If we delete characters at the positions 1, 3, 5 and 6, we will get the subsequence "()". The rest of the subsequnces are not RSBS. So we got 6 distinct subsequences that are RSBS, so the answer is 6. Tags: combinatorics, dp, math, number theory Correct Solution: ``` t = input() n, m = len(t) + 1, 1000000007 x, y = 0, t.count(')') - 1 fact = [1] * n for i in range(2, n): fact[i] = i * fact[i - 1] % m invMult = [pow(x, m - 2, m) for x in fact] s = 0 for b in t: if y < 0: break if b == '(': x += 1 s += fact[x + y] * invMult[x] * invMult[y] % m else: y -= 1 print(s % m) ```
90,602
Provide tags and a correct Python 3 solution for this coding contest problem. As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without quotes)). On the last lesson Anton learned about the regular simple bracket sequences (RSBS). A bracket sequence s of length n is an RSBS if the following conditions are met: * It is not empty (that is n β‰  0). * The length of the sequence is even. * First <image> charactes of the sequence are equal to "(". * Last <image> charactes of the sequence are equal to ")". For example, the sequence "((()))" is an RSBS but the sequences "((())" and "(()())" are not RSBS. Elena Ivanovna, Anton's teacher, gave him the following task as a homework. Given a bracket sequence s. Find the number of its distinct subsequences such that they are RSBS. Note that a subsequence of s is a string that can be obtained from s by deleting some of its elements. Two subsequences are considered distinct if distinct sets of positions are deleted. Because the answer can be very big and Anton's teacher doesn't like big numbers, she asks Anton to find the answer modulo 109 + 7. Anton thought of this task for a very long time, but he still doesn't know how to solve it. Help Anton to solve this task and write a program that finds the answer for it! Input The only line of the input contains a string s β€” the bracket sequence given in Anton's homework. The string consists only of characters "(" and ")" (without quotes). It's guaranteed that the string is not empty and its length doesn't exceed 200 000. Output Output one number β€” the answer for the task modulo 109 + 7. Examples Input )(()() Output 6 Input ()()() Output 7 Input ))) Output 0 Note In the first sample the following subsequences are possible: * If we delete characters at the positions 1 and 5 (numbering starts with one), we will get the subsequence "(())". * If we delete characters at the positions 1, 2, 3 and 4, we will get the subsequence "()". * If we delete characters at the positions 1, 2, 4 and 5, we will get the subsequence "()". * If we delete characters at the positions 1, 2, 5 and 6, we will get the subsequence "()". * If we delete characters at the positions 1, 3, 4 and 5, we will get the subsequence "()". * If we delete characters at the positions 1, 3, 5 and 6, we will get the subsequence "()". The rest of the subsequnces are not RSBS. So we got 6 distinct subsequences that are RSBS, so the answer is 6. Tags: combinatorics, dp, math, number theory Correct Solution: ``` s = input() MOD = 10 ** 9 + 7 num = 0 N = len(s) R = [0] * (N + 1) L = [0] * (N + 1) d = [] for i in range(N): if s[i] == ')': R[i + 1] = 1 else: L[i + 1] = 1 d.append(i) for i in range(1, N + 1): R[i] += R[i - 1] L[i] += L[i - 1] M = 200005 fact = [0] * M fact[0] = 1 for i in range(1, M): fact[i] = fact[i - 1] * i fact[i] %= MOD rfact = [0] * M rfact[M - 1] = pow(fact[M - 1], MOD - 2, MOD) for i in range(M - 2, -1, -1): rfact[i] = rfact[i + 1] * (i + 1) rfact[i] %= MOD def comb(n, k): if k < 0 or k > n: return 0 return fact[n] * rfact[n - k] * rfact[k] % MOD for i in d: if s[i] == '(': l = L[i + 1] - 1 r = R[N] - R[i + 1] num += comb(l + r, l + 1) num %= MOD print(num) ```
90,603
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without quotes)). On the last lesson Anton learned about the regular simple bracket sequences (RSBS). A bracket sequence s of length n is an RSBS if the following conditions are met: * It is not empty (that is n β‰  0). * The length of the sequence is even. * First <image> charactes of the sequence are equal to "(". * Last <image> charactes of the sequence are equal to ")". For example, the sequence "((()))" is an RSBS but the sequences "((())" and "(()())" are not RSBS. Elena Ivanovna, Anton's teacher, gave him the following task as a homework. Given a bracket sequence s. Find the number of its distinct subsequences such that they are RSBS. Note that a subsequence of s is a string that can be obtained from s by deleting some of its elements. Two subsequences are considered distinct if distinct sets of positions are deleted. Because the answer can be very big and Anton's teacher doesn't like big numbers, she asks Anton to find the answer modulo 109 + 7. Anton thought of this task for a very long time, but he still doesn't know how to solve it. Help Anton to solve this task and write a program that finds the answer for it! Input The only line of the input contains a string s β€” the bracket sequence given in Anton's homework. The string consists only of characters "(" and ")" (without quotes). It's guaranteed that the string is not empty and its length doesn't exceed 200 000. Output Output one number β€” the answer for the task modulo 109 + 7. Examples Input )(()() Output 6 Input ()()() Output 7 Input ))) Output 0 Note In the first sample the following subsequences are possible: * If we delete characters at the positions 1 and 5 (numbering starts with one), we will get the subsequence "(())". * If we delete characters at the positions 1, 2, 3 and 4, we will get the subsequence "()". * If we delete characters at the positions 1, 2, 4 and 5, we will get the subsequence "()". * If we delete characters at the positions 1, 2, 5 and 6, we will get the subsequence "()". * If we delete characters at the positions 1, 3, 4 and 5, we will get the subsequence "()". * If we delete characters at the positions 1, 3, 5 and 6, we will get the subsequence "()". The rest of the subsequnces are not RSBS. So we got 6 distinct subsequences that are RSBS, so the answer is 6. Submitted Solution: ``` mod = 10 ** 9 + 7 F, inv, iF = [1,1], [0, 1], [1, 1] for i in range(2, 200005): F.append(F[-1] * i % mod) inv.append(inv[mod%i] * (mod - mod // i) % mod) iF.append(iF[-1] * inv[-1] % mod) def C(n, k): if k < 0 or k > n: return 0 return F[n] * iF[k] * iF[n - k] s = input() open, close = 0, s.count(')') ans = 0 for c in s: if c == '(': open += 1 ans += C(close + open - 1, open) else: close -= 1 print(ans % mod) ``` Yes
90,604
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without quotes)). On the last lesson Anton learned about the regular simple bracket sequences (RSBS). A bracket sequence s of length n is an RSBS if the following conditions are met: * It is not empty (that is n β‰  0). * The length of the sequence is even. * First <image> charactes of the sequence are equal to "(". * Last <image> charactes of the sequence are equal to ")". For example, the sequence "((()))" is an RSBS but the sequences "((())" and "(()())" are not RSBS. Elena Ivanovna, Anton's teacher, gave him the following task as a homework. Given a bracket sequence s. Find the number of its distinct subsequences such that they are RSBS. Note that a subsequence of s is a string that can be obtained from s by deleting some of its elements. Two subsequences are considered distinct if distinct sets of positions are deleted. Because the answer can be very big and Anton's teacher doesn't like big numbers, she asks Anton to find the answer modulo 109 + 7. Anton thought of this task for a very long time, but he still doesn't know how to solve it. Help Anton to solve this task and write a program that finds the answer for it! Input The only line of the input contains a string s β€” the bracket sequence given in Anton's homework. The string consists only of characters "(" and ")" (without quotes). It's guaranteed that the string is not empty and its length doesn't exceed 200 000. Output Output one number β€” the answer for the task modulo 109 + 7. Examples Input )(()() Output 6 Input ()()() Output 7 Input ))) Output 0 Note In the first sample the following subsequences are possible: * If we delete characters at the positions 1 and 5 (numbering starts with one), we will get the subsequence "(())". * If we delete characters at the positions 1, 2, 3 and 4, we will get the subsequence "()". * If we delete characters at the positions 1, 2, 4 and 5, we will get the subsequence "()". * If we delete characters at the positions 1, 2, 5 and 6, we will get the subsequence "()". * If we delete characters at the positions 1, 3, 4 and 5, we will get the subsequence "()". * If we delete characters at the positions 1, 3, 5 and 6, we will get the subsequence "()". The rest of the subsequnces are not RSBS. So we got 6 distinct subsequences that are RSBS, so the answer is 6. Submitted Solution: ``` mod = 10 ** 9 + 7 maxn = 200001 def C(n, k): if k < 0 or k > n: return 0 return fact[n] * invfact[k] * invfact[n - k] % mod fact = [1, 1] inv = [0, 1] invfact = [1, 1] for i in range(2, maxn): fact.append(fact[-1] * i % mod) inv.append(inv[mod % i] * (mod - mod // i) % mod) invfact.append(invfact[-1] * inv[-1] % mod) s = input() op = 0 cl = s.count(')') ans = 0 for x in s: if x == '(': op += 1 cur = C(cl + op - 1, op) % mod ans += cur % mod else: cl -= 1 print(ans % mod) ``` Yes
90,605
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without quotes)). On the last lesson Anton learned about the regular simple bracket sequences (RSBS). A bracket sequence s of length n is an RSBS if the following conditions are met: * It is not empty (that is n β‰  0). * The length of the sequence is even. * First <image> charactes of the sequence are equal to "(". * Last <image> charactes of the sequence are equal to ")". For example, the sequence "((()))" is an RSBS but the sequences "((())" and "(()())" are not RSBS. Elena Ivanovna, Anton's teacher, gave him the following task as a homework. Given a bracket sequence s. Find the number of its distinct subsequences such that they are RSBS. Note that a subsequence of s is a string that can be obtained from s by deleting some of its elements. Two subsequences are considered distinct if distinct sets of positions are deleted. Because the answer can be very big and Anton's teacher doesn't like big numbers, she asks Anton to find the answer modulo 109 + 7. Anton thought of this task for a very long time, but he still doesn't know how to solve it. Help Anton to solve this task and write a program that finds the answer for it! Input The only line of the input contains a string s β€” the bracket sequence given in Anton's homework. The string consists only of characters "(" and ")" (without quotes). It's guaranteed that the string is not empty and its length doesn't exceed 200 000. Output Output one number β€” the answer for the task modulo 109 + 7. Examples Input )(()() Output 6 Input ()()() Output 7 Input ))) Output 0 Note In the first sample the following subsequences are possible: * If we delete characters at the positions 1 and 5 (numbering starts with one), we will get the subsequence "(())". * If we delete characters at the positions 1, 2, 3 and 4, we will get the subsequence "()". * If we delete characters at the positions 1, 2, 4 and 5, we will get the subsequence "()". * If we delete characters at the positions 1, 2, 5 and 6, we will get the subsequence "()". * If we delete characters at the positions 1, 3, 4 and 5, we will get the subsequence "()". * If we delete characters at the positions 1, 3, 5 and 6, we will get the subsequence "()". The rest of the subsequnces are not RSBS. So we got 6 distinct subsequences that are RSBS, so the answer is 6. Submitted Solution: ``` from datetime import datetime cache = {} def pascal(n, k): if k == 0 or k == n: return 1 elif (n,k) in cache: return cache[(n,k)] else: value = pascal(n-1, k-1) + pascal(n-1, k) cache[(n,k)] = value return value sentence=input() startTime = datetime.now() s=0 x=0 for i in range(len(sentence)): if sentence[i]=="(": x+=1 cut=sentence[i+1:] y=cut.count(")") if y>=1: m=min(x,y) for a in range(m+1): if a!=0: add=int(pascal(y,a))*int(pascal(x-1,a-1)) s+=add print(s) print(datetime.now() - startTime) ``` No
90,606
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without quotes)). On the last lesson Anton learned about the regular simple bracket sequences (RSBS). A bracket sequence s of length n is an RSBS if the following conditions are met: * It is not empty (that is n β‰  0). * The length of the sequence is even. * First <image> charactes of the sequence are equal to "(". * Last <image> charactes of the sequence are equal to ")". For example, the sequence "((()))" is an RSBS but the sequences "((())" and "(()())" are not RSBS. Elena Ivanovna, Anton's teacher, gave him the following task as a homework. Given a bracket sequence s. Find the number of its distinct subsequences such that they are RSBS. Note that a subsequence of s is a string that can be obtained from s by deleting some of its elements. Two subsequences are considered distinct if distinct sets of positions are deleted. Because the answer can be very big and Anton's teacher doesn't like big numbers, she asks Anton to find the answer modulo 109 + 7. Anton thought of this task for a very long time, but he still doesn't know how to solve it. Help Anton to solve this task and write a program that finds the answer for it! Input The only line of the input contains a string s β€” the bracket sequence given in Anton's homework. The string consists only of characters "(" and ")" (without quotes). It's guaranteed that the string is not empty and its length doesn't exceed 200 000. Output Output one number β€” the answer for the task modulo 109 + 7. Examples Input )(()() Output 6 Input ()()() Output 7 Input ))) Output 0 Note In the first sample the following subsequences are possible: * If we delete characters at the positions 1 and 5 (numbering starts with one), we will get the subsequence "(())". * If we delete characters at the positions 1, 2, 3 and 4, we will get the subsequence "()". * If we delete characters at the positions 1, 2, 4 and 5, we will get the subsequence "()". * If we delete characters at the positions 1, 2, 5 and 6, we will get the subsequence "()". * If we delete characters at the positions 1, 3, 4 and 5, we will get the subsequence "()". * If we delete characters at the positions 1, 3, 5 and 6, we will get the subsequence "()". The rest of the subsequnces are not RSBS. So we got 6 distinct subsequences that are RSBS, so the answer is 6. Submitted Solution: ``` p = 10**9+7 def power(x, y, p): b = bin(y)[2:] answer = 1 start = x % p for i in range(len(b)): if b[len(b)-1-i]=='1': answer = (answer*start) % p start = (start*start) % p return answer def process(S): answer = 0 n = len(S) left_count = 0 right_count = 0 p_lc = 1 p_rc = 1 p_num = 1 num = 0 for c in S: if c==')': right_count+=1 p_rc = (p_rc*(right_count+1)) % p num+=1 p_num = (p_num*num) % p for i in range(n): if S[i]=='(': left_count+=1 if left_count > 1: p_lc = (p_lc*(left_count-1)) % p num+=1 p_num = (p_num*num) % p else: p_rc = (p_rc*power(right_count+1, p-2, p)) % p p_num = (p_num*power(num, p-2, p)) % p right_count-=1 num-=1 #(left_count choose n, right_count choose n-1) #(left_count choose n, right_count choose rc-n+1)) #(lc+rc choose rc+1) if left_count > 0: entry = (p_num*power(p_lc, p-2, p)*power(p_rc, p-2, p)) % p answer = (answer+entry) % p return answer ``` No
90,607
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without quotes)). On the last lesson Anton learned about the regular simple bracket sequences (RSBS). A bracket sequence s of length n is an RSBS if the following conditions are met: * It is not empty (that is n β‰  0). * The length of the sequence is even. * First <image> charactes of the sequence are equal to "(". * Last <image> charactes of the sequence are equal to ")". For example, the sequence "((()))" is an RSBS but the sequences "((())" and "(()())" are not RSBS. Elena Ivanovna, Anton's teacher, gave him the following task as a homework. Given a bracket sequence s. Find the number of its distinct subsequences such that they are RSBS. Note that a subsequence of s is a string that can be obtained from s by deleting some of its elements. Two subsequences are considered distinct if distinct sets of positions are deleted. Because the answer can be very big and Anton's teacher doesn't like big numbers, she asks Anton to find the answer modulo 109 + 7. Anton thought of this task for a very long time, but he still doesn't know how to solve it. Help Anton to solve this task and write a program that finds the answer for it! Input The only line of the input contains a string s β€” the bracket sequence given in Anton's homework. The string consists only of characters "(" and ")" (without quotes). It's guaranteed that the string is not empty and its length doesn't exceed 200 000. Output Output one number β€” the answer for the task modulo 109 + 7. Examples Input )(()() Output 6 Input ()()() Output 7 Input ))) Output 0 Note In the first sample the following subsequences are possible: * If we delete characters at the positions 1 and 5 (numbering starts with one), we will get the subsequence "(())". * If we delete characters at the positions 1, 2, 3 and 4, we will get the subsequence "()". * If we delete characters at the positions 1, 2, 4 and 5, we will get the subsequence "()". * If we delete characters at the positions 1, 2, 5 and 6, we will get the subsequence "()". * If we delete characters at the positions 1, 3, 4 and 5, we will get the subsequence "()". * If we delete characters at the positions 1, 3, 5 and 6, we will get the subsequence "()". The rest of the subsequnces are not RSBS. So we got 6 distinct subsequences that are RSBS, so the answer is 6. Submitted Solution: ``` s = input() MAXN = 200005 MOD = 1000000007 Fac = [ 1 for i in range(0, MAXN)] for i in range(1, MAXN): Fac[i] = (i*Fac[i-1])%MOD f = lambda n : Fac[n] if n >= 0 else 0 suf = [ 0 for i in range(0, len(s)+1)] for i in range(len(s)-1, -1, -1): suf[i] = suf[i+1] + 1 if s[i] is ')' else suf[i+1] def ncr(n, k): return 0 if (f(n-k)*f(k)) == 0 else (f(n)* pow(f(n-k)*f(k), MOD-2, MOD) ) % MOD ans = 0 pre = 0 for i in range(0, len(s)): if s[i] is not '(': continue pre += 1 ans += ncr(suf[i+1]+pre-1, pre) print(ans % MOD) ``` No
90,608
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without quotes)). On the last lesson Anton learned about the regular simple bracket sequences (RSBS). A bracket sequence s of length n is an RSBS if the following conditions are met: * It is not empty (that is n β‰  0). * The length of the sequence is even. * First <image> charactes of the sequence are equal to "(". * Last <image> charactes of the sequence are equal to ")". For example, the sequence "((()))" is an RSBS but the sequences "((())" and "(()())" are not RSBS. Elena Ivanovna, Anton's teacher, gave him the following task as a homework. Given a bracket sequence s. Find the number of its distinct subsequences such that they are RSBS. Note that a subsequence of s is a string that can be obtained from s by deleting some of its elements. Two subsequences are considered distinct if distinct sets of positions are deleted. Because the answer can be very big and Anton's teacher doesn't like big numbers, she asks Anton to find the answer modulo 109 + 7. Anton thought of this task for a very long time, but he still doesn't know how to solve it. Help Anton to solve this task and write a program that finds the answer for it! Input The only line of the input contains a string s β€” the bracket sequence given in Anton's homework. The string consists only of characters "(" and ")" (without quotes). It's guaranteed that the string is not empty and its length doesn't exceed 200 000. Output Output one number β€” the answer for the task modulo 109 + 7. Examples Input )(()() Output 6 Input ()()() Output 7 Input ))) Output 0 Note In the first sample the following subsequences are possible: * If we delete characters at the positions 1 and 5 (numbering starts with one), we will get the subsequence "(())". * If we delete characters at the positions 1, 2, 3 and 4, we will get the subsequence "()". * If we delete characters at the positions 1, 2, 4 and 5, we will get the subsequence "()". * If we delete characters at the positions 1, 2, 5 and 6, we will get the subsequence "()". * If we delete characters at the positions 1, 3, 4 and 5, we will get the subsequence "()". * If we delete characters at the positions 1, 3, 5 and 6, we will get the subsequence "()". The rest of the subsequnces are not RSBS. So we got 6 distinct subsequences that are RSBS, so the answer is 6. Submitted Solution: ``` #!/usr/bin/env python3 def ri(): return map(int, input().split()) def prefac(n): fac[0] = 1 for i in range(1,n): fac[i] = fac[i-1]*i%(10**9+7) s = input() n = len(s) o = [0 for i in range(len(s))] c = [0 for i in range(len(s))] fac = [0 for i in range(n)] prefac(n) if s[0] == '(': o[0] = 1 for i in range(1,n): if s[i] == '(': o[i] = o[i-1] + 1 else: o[i] = o[i-1] if s[n-1] == ')': c[n-1] = 1 for i in range(n-2, -1, -1): if s[i] == ')': c[i] = c[i+1] + 1 else: c[i] = c[i+1] ans = 0 for i in range(n): if s[i] == '(': a = o[i] b = c[i] if a != 0 and b != 0: ans += fac[a+b-1]//fac[a]//fac[b-1] ans %= 10**9+7 print(ans) ``` No
90,609
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems. For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round. <image> Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500. If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000Β·(1 - 40 / 250) = 1680 points for this problem. There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem. With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing. Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved. Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts. Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal. Input The first line contains a single integer n (2 ≀ n ≀ 120) β€” the number of round participants, including Vasya and Petya. Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≀ ai, j ≀ 119) β€” the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j. It is guaranteed that each participant has made at least one successful submission. Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order. Output Output a single integer β€” the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal. Examples Input 2 5 15 40 70 115 50 45 40 30 15 Output 2 Input 3 55 80 10 -1 -1 15 -1 79 60 -1 42 -1 13 -1 -1 Output 3 Input 5 119 119 119 119 119 0 0 0 0 -1 20 65 12 73 77 78 112 22 23 11 1 78 60 111 62 Output 27 Input 4 -1 20 40 77 119 30 10 73 50 107 21 29 -1 64 98 117 65 -1 -1 -1 Output -1 Note In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points. In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points. In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one. Tags: brute force, greedy Correct Solution: ``` n = int(input()) t = [0] * n for i in range(n): t[i] = list(map(int, input().split())) value = [0] * 5 solve = [0] * 5 for i in range(5): solved = 0 for j in range(n): if t[j][i] != -1: solved += 1 else: t[j][i] = 250 if (solved * 2 > n): value[i] = 500 elif (solved * 4 > n): value[i] = 1000 elif (solved * 8 > n): value[i] = 1500 elif (solved * 16 > n): value[i] = 2000 elif (solved * 32 > n): value[i] = 2500 else: value[i] = 3000 solve[i] = solved vasya = 0 for i in range(5): vasya += value[i] - value[i] // 250 * t[0][i] petya = 0 for i in range(5): petya += value[i] - value[i] // 250 * t[1][i] pot = [[0] * 20000 for i in range(5)] for problem in range(5): if t[0][problem] < t[1][problem]: cur_ac = 0 while 1: if solve[problem] * 32 <= n + cur_ac: win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 16 <= n + cur_ac: win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 8 <= n + cur_ac: win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 4 <= n + cur_ac: win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 2 <= n + cur_ac: win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win else: win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win cur_ac += 1 if cur_ac == 20000: break elif t[0][problem] != 250: cur_ac = 0 while 1: if solve[problem] * 32 + cur_ac <= n + cur_ac: win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 16 + cur_ac <= n + cur_ac: win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 8 + cur_ac <= n + cur_ac: win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 4 + cur_ac <= n + cur_ac: win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 2 + cur_ac <= n + cur_ac: win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win else: win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win cur_ac += 1 if cur_ac == 20000: break else: cur_ac = 0 while 1: if solve[problem] * 32 <= n + cur_ac: win = -(3000 - 3000 // 250 * t[1][problem]) -( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 16 <= n + cur_ac: win = -(2500 - 2500 // 250 * t[1][problem]) - ( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 8 <= n + cur_ac: win = -(2000 - 2000 // 250 * t[1][problem]) - ( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 4 <= n + cur_ac: win = -(1500 - 1500 // 250 * t[1][problem]) - ( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 2 <= n + cur_ac: win = -(1000 - 1000 // 250 * t[1][problem]) - ( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win else: win = -(500 - 500 // 250 * t[1][problem]) - ( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win cur_ac += 1 if cur_ac == 20000: break res = -1 maxi = 0 for i in range(5): maxi = max(maxi, len(pot[i])) for i in range(maxi): tmp = 0 for pr in range(5): if len(pot[pr]) <= i: tmp += pot[pr][-1] else: tmp += pot[pr][i] if tmp > petya - vasya: res = i break print(res) ```
90,610
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems. For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round. <image> Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500. If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000Β·(1 - 40 / 250) = 1680 points for this problem. There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem. With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing. Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved. Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts. Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal. Input The first line contains a single integer n (2 ≀ n ≀ 120) β€” the number of round participants, including Vasya and Petya. Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≀ ai, j ≀ 119) β€” the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j. It is guaranteed that each participant has made at least one successful submission. Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order. Output Output a single integer β€” the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal. Examples Input 2 5 15 40 70 115 50 45 40 30 15 Output 2 Input 3 55 80 10 -1 -1 15 -1 79 60 -1 42 -1 13 -1 -1 Output 3 Input 5 119 119 119 119 119 0 0 0 0 -1 20 65 12 73 77 78 112 22 23 11 1 78 60 111 62 Output 27 Input 4 -1 20 40 77 119 30 10 73 50 107 21 29 -1 64 98 117 65 -1 -1 -1 Output -1 Note In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points. In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points. In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one. Tags: brute force, greedy Correct Solution: ``` from sys import stdin, stdout fractionBoundaries = [1/2,1/4,1/8,1/16,1/32,0] scoreList = [500,1000,1500,2000,2500,3000] def assessScores(n,Vsol,Psol,solvers): vScore=0 pScore=0 for i in range(5): for j in range(6): if solvers[i]/n>fractionBoundaries[j]: qnScore=scoreList[j] break if Vsol[i]>=0: vScore+=qnScore-(qnScore*Vsol[i]//250) if Psol[i]>=0: pScore+=qnScore-(qnScore*Psol[i]//250) return vScore>pScore def main(): n = int(stdin.readline().rstrip()) Vsol = [int(x) for x in stdin.readline().rstrip().split()] Psol = [int(x) for x in stdin.readline().rstrip().split()] solvers = [0]*5 for _ in range(n-2): a = [int(x) for x in stdin.readline().rstrip().split()] for i in range(5): if a[i]>=0: solvers[i]+=1 for i in range(5): if Vsol[i]>=0: solvers[i]+=1 if Psol[i]>=0: solvers[i]+=1 newSolvers=0 vWins=[] pWins=[] for i in range(5): if (Vsol[i]<Psol[i] and Vsol[i]>=0) or (Vsol[i]>=0 and Psol[i]<0): vWins.append(i) elif (Psol[i]<Vsol[i] and Psol[i]>=0 and Vsol[i]>=0): pWins.append(i) if len(vWins)==0: print(-1) else: while not assessScores(n+newSolvers,Vsol,Psol,solvers) and newSolvers<=100000007: solversNeeded=9999999999999 for i in range(5): if i in vWins: currentRatio = solvers[i]/(newSolvers+n) for j in range(6): if solvers[i]/(newSolvers+n)>fractionBoundaries[j]: nextBoundary = fractionBoundaries[j] break if nextBoundary!=0: if solvers[i]%nextBoundary==0: solversNeeded = min([solvers[i]//nextBoundary - (newSolvers+n),solversNeeded]) else: solversNeeded = min([solvers[i]//nextBoundary - (newSolvers+n)+1,solversNeeded]) elif i in pWins and Vsol[i]>0: currentRatio = solvers[i]/(newSolvers+n) for j in range(6): if solvers[i]/(newSolvers+n)>fractionBoundaries[j]: if j>0: nextBoundary = fractionBoundaries[j-1] solversNeeded = min([(nextBoundary*(newSolvers+n)-solvers[i])//(1-nextBoundary)+1,solversNeeded]) break newSolvers+=solversNeeded for x in pWins: solvers[x]+=solversNeeded if newSolvers>1000000007: print(-1) else: print(int(newSolvers)) main() ```
90,611
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems. For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round. <image> Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500. If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000Β·(1 - 40 / 250) = 1680 points for this problem. There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem. With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing. Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved. Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts. Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal. Input The first line contains a single integer n (2 ≀ n ≀ 120) β€” the number of round participants, including Vasya and Petya. Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≀ ai, j ≀ 119) β€” the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j. It is guaranteed that each participant has made at least one successful submission. Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order. Output Output a single integer β€” the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal. Examples Input 2 5 15 40 70 115 50 45 40 30 15 Output 2 Input 3 55 80 10 -1 -1 15 -1 79 60 -1 42 -1 13 -1 -1 Output 3 Input 5 119 119 119 119 119 0 0 0 0 -1 20 65 12 73 77 78 112 22 23 11 1 78 60 111 62 Output 27 Input 4 -1 20 40 77 119 30 10 73 50 107 21 29 -1 64 98 117 65 -1 -1 -1 Output -1 Note In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points. In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points. In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one. Tags: brute force, greedy Correct Solution: ``` import sys inf = 10**9 + 7 def solve(): n = int(sys.stdin.readline()) v = [int(vi) for vi in sys.stdin.readline().split()] # Vesya p = [int(pi) for pi in sys.stdin.readline().split()] # Petya cnt = [0]*5 for i in range(5): if v[i] != -1: cnt[i] += 1 if p[i] != -1: cnt[i] += 1 for i in range(n - 2): a = [int(ai) for ai in sys.stdin.readline().split()] for j in range(5): if a[j] != -1: cnt[j] += 1 for i in range(4000): if check(n, v, p, cnt, i): print(i) return print(-1) def check(n, v, p, cnt, m): tot = n + m solved = cnt[:] dif = 0 for i in range(5): if p[i] != -1 and v[i] > p[i]: solved[i] += m for i in range(5): if solved[i]*2 > tot: max_score = 500 elif solved[i]*4 > tot: max_score = 1000 elif solved[i]*8 > tot: max_score = 1500 elif solved[i]*16 > tot: max_score = 2000 elif solved[i]*32 > tot: max_score = 2500 else: max_score = 3000 if v[i] == p[i] == -1: pass elif v[i] == -1: dif -= max_score * (250 - p[i]) // 250 elif p[i] == -1: dif += max_score * (250 - v[i]) // 250 else: dif += max_score * (p[i] - v[i]) // 250 return dif > 0 if __name__ == '__main__': solve() ```
90,612
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems. For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round. <image> Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500. If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000Β·(1 - 40 / 250) = 1680 points for this problem. There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem. With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing. Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved. Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts. Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal. Input The first line contains a single integer n (2 ≀ n ≀ 120) β€” the number of round participants, including Vasya and Petya. Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≀ ai, j ≀ 119) β€” the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j. It is guaranteed that each participant has made at least one successful submission. Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order. Output Output a single integer β€” the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal. Examples Input 2 5 15 40 70 115 50 45 40 30 15 Output 2 Input 3 55 80 10 -1 -1 15 -1 79 60 -1 42 -1 13 -1 -1 Output 3 Input 5 119 119 119 119 119 0 0 0 0 -1 20 65 12 73 77 78 112 22 23 11 1 78 60 111 62 Output 27 Input 4 -1 20 40 77 119 30 10 73 50 107 21 29 -1 64 98 117 65 -1 -1 -1 Output -1 Note In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points. In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points. In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one. Tags: brute force, greedy Correct Solution: ``` def get_value(parters, solved): if solved * 32 <= parters: return 3000 if solved * 16 <= parters: return 2500 if solved * 8 <= parters: return 2000 if solved * 4 <= parters: return 1500 if solved * 2 <= parters: return 1000 return 500 def points(value, time): return value - value // 500 * time n = int(input()) t = [0] * n for i in range(n): t[i] = list(map(int, input().split())) value = [0] * 5 solve = [0] * 5 for i in range(5): solved = 0 for j in range(n): if t[j][i] != -1: solved += 1 else: t[j][i] = 250 value[i] = get_value(n, solved) solve[i] = solved vasya = 0 for i in range(5): vasya += points(value[i], t[0][i]) petya = 0 for i in range(5): petya += points(value[i], t[1][i]) pot = [[0] * 20000 for i in range(5)] for problem in range(5): for cur_ac in range(20000): new_value = 0 if t[0][problem] < t[1][problem]: new_value = get_value(n + cur_ac, solve[problem]) elif t[0][problem] != 250: new_value = get_value(n + cur_ac, solve[problem] + cur_ac) else: new_value = get_value(n + cur_ac, solve[problem]) win = points(new_value, t[0][problem]) - points(new_value, t[1][problem]) - points(value[problem], t[0][problem]) + points(value[problem], t[1][problem]) pot[problem][cur_ac] = win res = -1 for i in range(20000): tmp = 0 for pr in range(5): if len(pot[pr]) <= i: tmp += pot[pr][-1] else: tmp += pot[pr][i] if tmp > petya - vasya: res = i break print(res) ```
90,613
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems. For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round. <image> Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500. If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000Β·(1 - 40 / 250) = 1680 points for this problem. There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem. With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing. Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved. Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts. Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal. Input The first line contains a single integer n (2 ≀ n ≀ 120) β€” the number of round participants, including Vasya and Petya. Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≀ ai, j ≀ 119) β€” the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j. It is guaranteed that each participant has made at least one successful submission. Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order. Output Output a single integer β€” the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal. Examples Input 2 5 15 40 70 115 50 45 40 30 15 Output 2 Input 3 55 80 10 -1 -1 15 -1 79 60 -1 42 -1 13 -1 -1 Output 3 Input 5 119 119 119 119 119 0 0 0 0 -1 20 65 12 73 77 78 112 22 23 11 1 78 60 111 62 Output 27 Input 4 -1 20 40 77 119 30 10 73 50 107 21 29 -1 64 98 117 65 -1 -1 -1 Output -1 Note In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points. In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points. In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one. Tags: brute force, greedy Correct Solution: ``` import sys inf = 10**9 + 7 def solve(): def check(mid): tot = n + mid dif = 0 solved = cnt[:] for i in range(5): if v[i] != -1 and p[i] != -1 and p[i] < v[i]: solved[i] += mid for i in range(5): if solved[i]*2 > tot: max_score = 500 elif solved[i]*4 > tot: max_score = 1000 elif solved[i]*8 > tot: max_score = 1500 elif solved[i]*16 > tot: max_score = 2000 elif solved[i]*32 > tot: max_score = 2500 else: max_score = 3000 if v[i] == p[i]: pass elif v[i] == -1: dif += max_score * (250 - p[i]) // 250 elif p[i] == -1: dif += -max_score * (250 - v[i]) // 250 else: dif += max_score * (-p[i] + v[i]) // 250 # print(mid, dif) return dif < 0 n = int(sys.stdin.readline()) cnt = [0]*5 v = [int(i) for i in sys.stdin.readline().split()] for i in range(5): if v[i] != -1: cnt[i] += 1 p = [int(i) for i in sys.stdin.readline().split()] for i in range(5): if p[i] != -1: cnt[i] += 1 for i in range(n - 2): a = [int(ai) for ai in sys.stdin.readline().split()] for j in range(5): if a[j] != -1: cnt[j] += 1 for i in range(6000): if check(i): print(i) return print(-1) if __name__ == '__main__': solve() ```
90,614
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems. For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round. <image> Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500. If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000Β·(1 - 40 / 250) = 1680 points for this problem. There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem. With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing. Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved. Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts. Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal. Input The first line contains a single integer n (2 ≀ n ≀ 120) β€” the number of round participants, including Vasya and Petya. Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≀ ai, j ≀ 119) β€” the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j. It is guaranteed that each participant has made at least one successful submission. Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order. Output Output a single integer β€” the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal. Examples Input 2 5 15 40 70 115 50 45 40 30 15 Output 2 Input 3 55 80 10 -1 -1 15 -1 79 60 -1 42 -1 13 -1 -1 Output 3 Input 5 119 119 119 119 119 0 0 0 0 -1 20 65 12 73 77 78 112 22 23 11 1 78 60 111 62 Output 27 Input 4 -1 20 40 77 119 30 10 73 50 107 21 29 -1 64 98 117 65 -1 -1 -1 Output -1 Note In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points. In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points. In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one. Tags: brute force, greedy Correct Solution: ``` import sys inf = 10**9 + 7 def solve(): n = int(sys.stdin.readline()) v = [int(vi) for vi in sys.stdin.readline().split()] # Vesya p = [int(pi) for pi in sys.stdin.readline().split()] # Petya cnt = [0]*5 for i in range(5): if v[i] != -1: cnt[i] += 1 if p[i] != -1: cnt[i] += 1 for i in range(n - 2): a = [int(ai) for ai in sys.stdin.readline().split()] for j in range(5): if a[j] != -1: cnt[j] += 1 for i in range(10**5): if check(n, v, p, cnt, i): print(i) return print(-1) def check(n, v, p, cnt, m): tot = n + m solved = cnt[:] dif = 0 for i in range(5): if p[i] != -1 and v[i] > p[i]: solved[i] += m for i in range(5): if solved[i]*2 > tot: max_score = 500 elif solved[i]*4 > tot: max_score = 1000 elif solved[i]*8 > tot: max_score = 1500 elif solved[i]*16 > tot: max_score = 2000 elif solved[i]*32 > tot: max_score = 2500 else: max_score = 3000 if v[i] == p[i] == -1: pass elif v[i] == -1: dif -= max_score * (250 - p[i]) // 250 elif p[i] == -1: dif += max_score * (250 - v[i]) // 250 else: dif += max_score * (p[i] - v[i]) // 250 return dif > 0 if __name__ == '__main__': solve() ```
90,615
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems. For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round. <image> Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500. If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000Β·(1 - 40 / 250) = 1680 points for this problem. There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem. With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing. Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved. Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts. Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal. Input The first line contains a single integer n (2 ≀ n ≀ 120) β€” the number of round participants, including Vasya and Petya. Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≀ ai, j ≀ 119) β€” the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j. It is guaranteed that each participant has made at least one successful submission. Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order. Output Output a single integer β€” the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal. Examples Input 2 5 15 40 70 115 50 45 40 30 15 Output 2 Input 3 55 80 10 -1 -1 15 -1 79 60 -1 42 -1 13 -1 -1 Output 3 Input 5 119 119 119 119 119 0 0 0 0 -1 20 65 12 73 77 78 112 22 23 11 1 78 60 111 62 Output 27 Input 4 -1 20 40 77 119 30 10 73 50 107 21 29 -1 64 98 117 65 -1 -1 -1 Output -1 Note In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points. In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points. In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one. Submitted Solution: ``` n = int(input()) t = [0] * n for i in range(n): t[i] = list(map(int, input().split())) value = [0] * 5 solve = [0] * 5 for i in range(5): solved = 0 for j in range(n): if t[j][i] != -1: solved += 1 else: t[j][i] = 250 if (solved * 2 > n): value[i] = 500 elif (solved * 4 > n): value[i] = 1000 elif (solved * 8 > n): value[i] = 1500 elif (solved * 16 > n): value[i] = 2000 elif (solved * 32 > n): value[i] = 2500 else: value[i] = 3000 solve[i] = solved vasya = 0 for i in range(5): vasya += value[i] - value[i] // 250 * t[0][i] petya = 0 for i in range(5): petya += value[i] - value[i] // 250 * t[1][i] pot = [[0] * 20000 for i in range(5)] for problem in range(5): if t[0][problem] < t[1][problem]: cur_ac = 0 while 1: if solve[problem] * 32 <= n + cur_ac: win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 16 <= n + cur_ac: win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 8 <= n + cur_ac: win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 4 <= n + cur_ac: win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 2 <= n + cur_ac: win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win else: win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win cur_ac += 1 if cur_ac == 20000: break elif t[0][problem] != 250: cur_ac = 0 while 1: if solve[problem] * 32 + cur_ac <= n + cur_ac: win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 16 + cur_ac <= n + cur_ac: win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 8 + cur_ac <= n + cur_ac: win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 4 + cur_ac <= n + cur_ac: win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 2 + cur_ac <= n + cur_ac: win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win else: win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win cur_ac += 1 if cur_ac == 20000: break else: cur_ac = 0 while 1: if solve[problem] * 32 <= n + cur_ac: win = -(3000 - 3000 // 250 * t[1][problem]) -( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win break elif solve[problem] * 16 <= n + cur_ac: win = -(2500 - 2500 // 250 * t[1][problem]) - ( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 8 <= n + cur_ac: win = -(2000 - 2000 // 250 * t[1][problem]) - ( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 4 <= n + cur_ac: win = -(1500 - 1500 // 250 * t[1][problem]) - ( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 2 <= n + cur_ac: win = -(1000 - 1000 // 250 * t[1][problem]) - ( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win else: win = -(500 - 500 // 250 * t[1][problem]) - ( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win cur_ac += 1 if cur_ac == 20000: break res = -1 maxi = 0 for i in range(5): maxi = max(maxi, len(pot[i])) for i in range(maxi): tmp = 0 for pr in range(5): if len(pot[pr]) <= i: tmp += pot[pr][-1] else: tmp += pot[pr][i] if tmp > petya - vasya: res = i break print(res) ``` No
90,616
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems. For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round. <image> Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500. If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000Β·(1 - 40 / 250) = 1680 points for this problem. There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem. With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing. Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved. Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts. Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal. Input The first line contains a single integer n (2 ≀ n ≀ 120) β€” the number of round participants, including Vasya and Petya. Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≀ ai, j ≀ 119) β€” the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j. It is guaranteed that each participant has made at least one successful submission. Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order. Output Output a single integer β€” the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal. Examples Input 2 5 15 40 70 115 50 45 40 30 15 Output 2 Input 3 55 80 10 -1 -1 15 -1 79 60 -1 42 -1 13 -1 -1 Output 3 Input 5 119 119 119 119 119 0 0 0 0 -1 20 65 12 73 77 78 112 22 23 11 1 78 60 111 62 Output 27 Input 4 -1 20 40 77 119 30 10 73 50 107 21 29 -1 64 98 117 65 -1 -1 -1 Output -1 Note In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points. In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points. In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one. Submitted Solution: ``` import sys inf = 10**9 + 7 def solve(): def check(mid): tot = n + mid dif = 0 solved = cnt[:] for i in range(5): if p[i] != -1 and p[i] < v[i]: solved[i] += mid for i in range(5): if solved[i]*2 > tot: max_score = 500 elif solved[i]*4 > tot: max_score = 1000 elif solved[i]*8 > tot: max_score = 1500 elif solved[i]*16 > tot: max_score = 2000 elif solved[i]*32 > tot: max_score = 2500 else: max_score = 3000 if v[i] == p[i]: pass elif v[i] == -1: dif += max_score * (250 - p[i]) // 250 elif p[i] == -1: dif += -max_score * (250 - v[i]) // 250 else: dif += max_score * (-p[i] + v[i]) // 250 # print(mid, dif) return dif < 0 n = int(sys.stdin.readline()) cnt = [0]*5 v = [int(i) for i in sys.stdin.readline().split()] for i in range(5): if v[i] != -1: cnt[i] += 1 p = [int(i) for i in sys.stdin.readline().split()] for i in range(5): if p[i] != -1: cnt[i] += 1 for i in range(n - 2): a = [int(ai) for ai in sys.stdin.readline().split()] for j in range(5): if a[j] != -1: cnt[j] += 1 btm = -1 top = inf + 2 while top - btm > 1: mid = (top + btm) // 2 if check(mid): top = mid else: btm = mid ans = top if top < inf + 1 else -1 print(ans) if __name__ == '__main__': solve() ``` No
90,617
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems. For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round. <image> Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500. If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000Β·(1 - 40 / 250) = 1680 points for this problem. There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem. With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing. Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved. Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts. Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal. Input The first line contains a single integer n (2 ≀ n ≀ 120) β€” the number of round participants, including Vasya and Petya. Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≀ ai, j ≀ 119) β€” the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j. It is guaranteed that each participant has made at least one successful submission. Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order. Output Output a single integer β€” the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal. Examples Input 2 5 15 40 70 115 50 45 40 30 15 Output 2 Input 3 55 80 10 -1 -1 15 -1 79 60 -1 42 -1 13 -1 -1 Output 3 Input 5 119 119 119 119 119 0 0 0 0 -1 20 65 12 73 77 78 112 22 23 11 1 78 60 111 62 Output 27 Input 4 -1 20 40 77 119 30 10 73 50 107 21 29 -1 64 98 117 65 -1 -1 -1 Output -1 Note In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points. In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points. In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one. Submitted Solution: ``` import sys inf = 10**9 + 7 def solve(): def check(mid): tot = n + mid dif = 0 solved = cnt[:] for i in range(5): if v[i] != -1 and p[i] != -1 and p[i] < v[i]: solved[i] += mid for i in range(5): if solved[i]*2 > tot: max_score = 500 elif solved[i]*4 > tot: max_score = 1000 elif solved[i]*8 > tot: max_score = 1500 elif solved[i]*16 > tot: max_score = 2000 elif solved[i]*32 > tot: max_score = 2500 else: max_score = 3000 if v[i] == p[i]: pass elif v[i] == -1: dif += max_score * (250 - p[i]) // 250 elif p[i] == -1: dif += -max_score * (250 - v[i]) // 250 else: dif += max_score * (-p[i] + v[i]) // 250 # print(mid, dif) return dif < 0 n = int(sys.stdin.readline()) cnt = [0]*5 v = [int(i) for i in sys.stdin.readline().split()] for i in range(5): if v[i] != -1: cnt[i] += 1 p = [int(i) for i in sys.stdin.readline().split()] for i in range(5): if p[i] != -1: cnt[i] += 1 for i in range(n - 2): a = [int(ai) for ai in sys.stdin.readline().split()] for j in range(5): if a[j] != -1: cnt[j] += 1 btm = -1 top = inf + 2 while top - btm > 1: mid = (top + btm) // 2 if check(mid): top = mid else: btm = mid ans = top if top < inf + 1 else -1 print(ans) if __name__ == '__main__': solve() ``` No
90,618
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems. For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round. <image> Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500. If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000Β·(1 - 40 / 250) = 1680 points for this problem. There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem. With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing. Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved. Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts. Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal. Input The first line contains a single integer n (2 ≀ n ≀ 120) β€” the number of round participants, including Vasya and Petya. Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≀ ai, j ≀ 119) β€” the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j. It is guaranteed that each participant has made at least one successful submission. Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order. Output Output a single integer β€” the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal. Examples Input 2 5 15 40 70 115 50 45 40 30 15 Output 2 Input 3 55 80 10 -1 -1 15 -1 79 60 -1 42 -1 13 -1 -1 Output 3 Input 5 119 119 119 119 119 0 0 0 0 -1 20 65 12 73 77 78 112 22 23 11 1 78 60 111 62 Output 27 Input 4 -1 20 40 77 119 30 10 73 50 107 21 29 -1 64 98 117 65 -1 -1 -1 Output -1 Note In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points. In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points. In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one. Submitted Solution: ``` n = int(input()) t = [0] * n for i in range(n): t[i] = list(map(int, input().split())) value = [0] * 5 solve = [0] * 5 for i in range(5): solved = 0 for j in range(n): if t[j][i] != -1: solved += 1 else: t[j][i] = 250 if (solved * 2 > n): value[i] = 500 elif (solved * 4 > n): value[i] = 1000 elif (solved * 8 > n): value[i] = 1500 elif (solved * 16 > n): value[i] = 2000 elif (solved * 32 > n): value[i] = 2500 else: value[i] = 3000 solve[i] = solved vasya = 0 for i in range(5): vasya += value[i] - value[i] // 250 * t[0][i] petya = 0 for i in range(5): petya += value[i] - value[i] // 250 * t[1][i] pot = [[0] * 200000 for i in range(5)] for problem in range(5): if t[0][problem] < t[1][problem]: cur_ac = 0 while 1: if solve[problem] * 32 <= n + cur_ac: win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win break elif solve[problem] * 16 <= n + cur_ac: win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 8 <= n + cur_ac: win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 4 <= n + cur_ac: win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 2 <= n + cur_ac: win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win else: win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win cur_ac += 1 elif t[0][problem] != 250: cur_ac = 0 while 1: if solve[problem] * 32 + cur_ac <= n + cur_ac: win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 16 + cur_ac <= n + cur_ac: win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 8 + cur_ac <= n + cur_ac: win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 4 + cur_ac <= n + cur_ac: win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 2 + cur_ac <= n + cur_ac: win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win else: win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win break cur_ac += 1 else: cur_ac = 0 while 1: if solve[problem] * 32 <= n + cur_ac: win = -(3000 - 3000 // 250 * t[1][problem]) -( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win break elif solve[problem] * 16 <= n + cur_ac: win = -(2500 - 2500 // 250 * t[1][problem]) - ( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 8 <= n + cur_ac: win = -(2000 - 2000 // 250 * t[1][problem]) - ( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 4 <= n + cur_ac: win = -(1500 - 1500 // 250 * t[1][problem]) - ( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 2 <= n + cur_ac: win = -(1000 - 1000 // 250 * t[1][problem]) - ( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win else: win = -(500 - 500 // 250 * t[1][problem]) - ( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win cur_ac += 1 res = -1 maxi = 0 for i in range(5): maxi = max(maxi, len(pot[i])) for i in range(maxi): tmp = 0 for pr in range(5): if len(pot[pr]) <= i: tmp += pot[pr][-1] else: tmp += pot[pr][i] if tmp > petya - vasya: res = i break print(res) ``` No
90,619
Provide tags and a correct Python 3 solution for this coding contest problem. Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100 000, inclusive. It is possible that some cards have the same integers on them. Vasily decided to sort the cards. To do this, he repeatedly takes the top card from the deck, and if the number on it equals the minimum number written on the cards in the deck, then he places the card away. Otherwise, he puts it under the deck and takes the next card from the top, and so on. The process ends as soon as there are no cards in the deck. You can assume that Vasily always knows the minimum number written on some card in the remaining deck, but doesn't know where this card (or these cards) is. You are to determine the total number of times Vasily takes the top card from the deck. Input The first line contains single integer n (1 ≀ n ≀ 100 000) β€” the number of cards in the deck. The second line contains a sequence of n integers a1, a2, ..., an (1 ≀ ai ≀ 100 000), where ai is the number written on the i-th from top card in the deck. Output Print the total number of times Vasily takes the top card from the deck. Examples Input 4 6 3 1 2 Output 7 Input 1 1000 Output 1 Input 7 3 3 3 3 3 3 3 Output 7 Note In the first example Vasily at first looks at the card with number 6 on it, puts it under the deck, then on the card with number 3, puts it under the deck, and then on the card with number 1. He places away the card with 1, because the number written on it is the minimum among the remaining cards. After that the cards from top to bottom are [2, 6, 3]. Then Vasily looks at the top card with number 2 and puts it away. After that the cards from top to bottom are [6, 3]. Then Vasily looks at card 6, puts it under the deck, then at card 3 and puts it away. Then there is only one card with number 6 on it, and Vasily looks at it and puts it away. Thus, in total Vasily looks at 7 cards. Tags: data structures, implementation, sortings Correct Solution: ``` # -*- coding: utf-8 -*- import sys # fout = open("output.txt", "w") fin = sys.stdin # fin = open("input.txt", "r") fout = sys.stdout n = int(fin.readline()) a = list(map(int, fin.readline().split())) def solution(n, a): sorted_arr = [(i, elem) for i, elem in enumerate(a)] sorted_arr.sort(key=lambda x: (x[1], x[0])) sorted_indexes = [x[0] for x in sorted_arr] cnt = 0 current_n = n prev_index = sorted_indexes[0] prev_elem = sorted_arr[0][1] cur_len = 1 i = 1 while i < n: cur_index = sorted_indexes[i] cur_elem = sorted_arr[i][1] if prev_index < cur_index: cur_len += 1 prev_index = sorted_indexes[i] prev_elem = sorted_arr[i][1] elif i+1<n and cur_elem == sorted_arr[i+1][1]: # здСсь косяк penalty = 1 last_penalty_ind = sorted_indexes[i] while i+1 < n and sorted_arr[i+1][1] == cur_elem: if sorted_arr[i+1][0] >= prev_index: cur_len += 1 else: penalty += 1 last_penalty_ind = sorted_indexes[i+1] i += 1 cnt += current_n current_n -= cur_len cur_len = penalty prev_elem = cur_elem prev_index = last_penalty_ind else: cnt += current_n current_n -= cur_len cur_len = 1 prev_index = sorted_indexes[i] prev_elem = sorted_arr[i][1] i += 1 cnt += current_n return cnt cnt = solution(n, a) fout.write(str(cnt)) fout.close() ```
90,620
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100 000, inclusive. It is possible that some cards have the same integers on them. Vasily decided to sort the cards. To do this, he repeatedly takes the top card from the deck, and if the number on it equals the minimum number written on the cards in the deck, then he places the card away. Otherwise, he puts it under the deck and takes the next card from the top, and so on. The process ends as soon as there are no cards in the deck. You can assume that Vasily always knows the minimum number written on some card in the remaining deck, but doesn't know where this card (or these cards) is. You are to determine the total number of times Vasily takes the top card from the deck. Input The first line contains single integer n (1 ≀ n ≀ 100 000) β€” the number of cards in the deck. The second line contains a sequence of n integers a1, a2, ..., an (1 ≀ ai ≀ 100 000), where ai is the number written on the i-th from top card in the deck. Output Print the total number of times Vasily takes the top card from the deck. Examples Input 4 6 3 1 2 Output 7 Input 1 1000 Output 1 Input 7 3 3 3 3 3 3 3 Output 7 Note In the first example Vasily at first looks at the card with number 6 on it, puts it under the deck, then on the card with number 3, puts it under the deck, and then on the card with number 1. He places away the card with 1, because the number written on it is the minimum among the remaining cards. After that the cards from top to bottom are [2, 6, 3]. Then Vasily looks at the top card with number 2 and puts it away. After that the cards from top to bottom are [6, 3]. Then Vasily looks at card 6, puts it under the deck, then at card 3 and puts it away. Then there is only one card with number 6 on it, and Vasily looks at it and puts it away. Thus, in total Vasily looks at 7 cards. Submitted Solution: ``` # -*- coding: utf-8 -*- import sys # fout = open("output.txt", "w") fin = sys.stdin # fin = open("input.txt", "r") fout = sys.stdout n = int(fin.readline()) a = list(map(int, fin.readline().split())) def solution(n, a): sorted_arr = [(i, elem) for i, elem in enumerate(a)] sorted_arr.sort(key=lambda x: (x[1], x[0])) sorted_indexes = [x[0] for x in sorted_arr] cnt = 0 current_n = n prev = sorted_indexes[0] cur_len = 1 for i in range(1, n): if prev <= sorted_indexes[i]: cur_len += 1 prev = sorted_indexes[i] else: cnt += current_n current_n -= cur_len cur_len = 1 prev = sorted_indexes[i] cnt += current_n return cnt cnt = solution(n, a) fout.write(str(cnt)) fout.close() ``` No
90,621
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider an array A with N elements, all being the same integer a. Define the product transformation as a simultaneous update Ai = AiΒ·Ai + 1, that is multiplying each element to the element right to it for <image>, with the last number AN remaining the same. For example, if we start with an array A with a = 2 and N = 4, then after one product transformation A = [4, 4, 4, 2], and after two product transformations A = [16, 16, 8, 2]. Your simple task is to calculate the array A after M product transformations. Since the numbers can get quite big you should output them modulo Q. Input The first and only line of input contains four integers N, M, a, Q (7 ≀ Q ≀ 109 + 123, 2 ≀ a ≀ 106 + 123, <image>, <image> is prime), where <image> is the multiplicative order of the integer a modulo Q, see notes for definition. Output You should output the array A from left to right. Example Input 2 2 2 7 Output 1 2 Note The multiplicative order of a number a modulo Q <image>, is the smallest natural number x such that ax mod Q = 1. For example, <image>. Submitted Solution: ``` # #include <cstdio> # using namespace std; # #define N 2000050 # int n,m,a,q,i,pw[N],ni[N],c[N]; # int main() # { # scanf("%d%d%d%d",&n,&m,&a,&q); # int y=1;pw[0]=1;pw[1]=a; # while (pw[y]!=1) y++,pw[y]=1LL*pw[y-1]*a%q; # ni[1]=1; # for (i=2;i<y;i++) ni[i]=-1LL*(y/i)*ni[y%i]%y; # int x=1;c[0]=1; # for (i=1;i<n;i++) x=1LL*x*(m-i+1)%y*ni[i]%y,c[i]=(c[i-1]+x)%y; # for (i=1;i<=n;i++) printf("%d ",pw[(c[n-i]+y)%y]);puts(""); # return 0; # } N = 2000050 n,m,a,q = map(int,input().split()) pw = [0]*N ni = [0]*N c = [0]*N y = 1 pw[0] = 1 pw[1] = a while(pw[y]!=1): y+=1 pw[y] = pw[y-1]*a % q ni[1] = 1 for i in range(2,y): ni[i] = -(y/i)*ni[y%i]%y x = 1 c[0] = 1 for i in range(1,n): x *= (m-i+1) % y * ni[i] % y for i in range(1,n+1): print(pw[(c[n-i]+y)%y]) ``` No
90,622
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider an array A with N elements, all being the same integer a. Define the product transformation as a simultaneous update Ai = AiΒ·Ai + 1, that is multiplying each element to the element right to it for <image>, with the last number AN remaining the same. For example, if we start with an array A with a = 2 and N = 4, then after one product transformation A = [4, 4, 4, 2], and after two product transformations A = [16, 16, 8, 2]. Your simple task is to calculate the array A after M product transformations. Since the numbers can get quite big you should output them modulo Q. Input The first and only line of input contains four integers N, M, a, Q (7 ≀ Q ≀ 109 + 123, 2 ≀ a ≀ 106 + 123, <image>, <image> is prime), where <image> is the multiplicative order of the integer a modulo Q, see notes for definition. Output You should output the array A from left to right. Example Input 2 2 2 7 Output 1 2 Note The multiplicative order of a number a modulo Q <image>, is the smallest natural number x such that ax mod Q = 1. For example, <image>. Submitted Solution: ``` print("1 "+"2") ``` No
90,623
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider an array A with N elements, all being the same integer a. Define the product transformation as a simultaneous update Ai = AiΒ·Ai + 1, that is multiplying each element to the element right to it for <image>, with the last number AN remaining the same. For example, if we start with an array A with a = 2 and N = 4, then after one product transformation A = [4, 4, 4, 2], and after two product transformations A = [16, 16, 8, 2]. Your simple task is to calculate the array A after M product transformations. Since the numbers can get quite big you should output them modulo Q. Input The first and only line of input contains four integers N, M, a, Q (7 ≀ Q ≀ 109 + 123, 2 ≀ a ≀ 106 + 123, <image>, <image> is prime), where <image> is the multiplicative order of the integer a modulo Q, see notes for definition. Output You should output the array A from left to right. Example Input 2 2 2 7 Output 1 2 Note The multiplicative order of a number a modulo Q <image>, is the smallest natural number x such that ax mod Q = 1. For example, <image>. Submitted Solution: ``` C = 2000050 fact = [0]*C nInverse = [0]*C def main(): n,m,a,Q = map(int,input().split()) mulOrder = 1 for i in range(1,C): #finding multiplicative order of a mod Q if(pow(a,i,Q) == 1): mulOrder = i break fact[0] = 1 nInverse[0] = 1 for i in range(1,C): #calculating factorial and n-inverses fact[i] = (fact[i-1]*i) % mulOrder nInverse[i] = pow(fact[i],mulOrder - 2,mulOrder) #given that mulOrder is a prime number and using Fermat's Little Theorem D = [0]*(n+1) for i in range(1,n+1): D[i] = (cn(m,i-1,mulOrder) + D[i-1]) % mulOrder #calculating exponent for each term for i in reversed(range(n,0)): print(pow(a,D[i],Q)) def cn(n,k,Q): if(k>n or k<0): return 0 il,a,b,s = 1 while (n>0 or k>0): a = n%Q b = k%Q s = sn(a,b,Q) il = (il * s)%Q k/=Q n/=Q return il def sn(n,k,Q): if(k>n or k<0): return 0 return (((fact[n] * nInverse[k]) % Q) * nInverse[n-k]) % Q ``` No
90,624
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider an array A with N elements, all being the same integer a. Define the product transformation as a simultaneous update Ai = AiΒ·Ai + 1, that is multiplying each element to the element right to it for <image>, with the last number AN remaining the same. For example, if we start with an array A with a = 2 and N = 4, then after one product transformation A = [4, 4, 4, 2], and after two product transformations A = [16, 16, 8, 2]. Your simple task is to calculate the array A after M product transformations. Since the numbers can get quite big you should output them modulo Q. Input The first and only line of input contains four integers N, M, a, Q (7 ≀ Q ≀ 109 + 123, 2 ≀ a ≀ 106 + 123, <image>, <image> is prime), where <image> is the multiplicative order of the integer a modulo Q, see notes for definition. Output You should output the array A from left to right. Example Input 2 2 2 7 Output 1 2 Note The multiplicative order of a number a modulo Q <image>, is the smallest natural number x such that ax mod Q = 1. For example, <image>. Submitted Solution: ``` print("1 2") ``` No
90,625
Provide tags and a correct Python 3 solution for this coding contest problem. One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name. It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita". Names are case sensitive. Input The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 β€” the name of the problem. Output Print "YES", if problem is from this contest, and "NO" otherwise. Examples Input Alex_and_broken_contest Output NO Input NikitaAndString Output YES Input Danil_and_Olya Output NO Tags: implementation, strings Correct Solution: ``` s = input() # print(s) l = ["Danil", "Olya", "Slava", "Ann", "Nikita"] cnt = 0 for n in l: cnt = cnt + s.count(n) if cnt == 1: print("YES") else: print("NO") ```
90,626
Provide tags and a correct Python 3 solution for this coding contest problem. One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name. It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita". Names are case sensitive. Input The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 β€” the name of the problem. Output Print "YES", if problem is from this contest, and "NO" otherwise. Examples Input Alex_and_broken_contest Output NO Input NikitaAndString Output YES Input Danil_and_Olya Output NO Tags: implementation, strings Correct Solution: ``` inp = input() names = ["Danil", "Olya", "Slava", "Ann", "Nikita"] rs = 0 for name in names: rs += inp.count(name) print("YES" if rs == 1 else "NO") ```
90,627
Provide tags and a correct Python 3 solution for this coding contest problem. One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name. It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita". Names are case sensitive. Input The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 β€” the name of the problem. Output Print "YES", if problem is from this contest, and "NO" otherwise. Examples Input Alex_and_broken_contest Output NO Input NikitaAndString Output YES Input Danil_and_Olya Output NO Tags: implementation, strings Correct Solution: ``` str = input() FRIENDS = ["Danil", "Olya", "Slava", "Ann", "Nikita"] sum = 0 for name in FRIENDS: sum += str.count(name) if sum == 1: print('YES') else: print('NO') ```
90,628
Provide tags and a correct Python 3 solution for this coding contest problem. One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name. It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita". Names are case sensitive. Input The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 β€” the name of the problem. Output Print "YES", if problem is from this contest, and "NO" otherwise. Examples Input Alex_and_broken_contest Output NO Input NikitaAndString Output YES Input Danil_and_Olya Output NO Tags: implementation, strings Correct Solution: ``` ls=["Danil","Olya","Slava","Ann","Nikita"] s=input() ctr=0 for a in ls: ctr+=s.count(a) if ctr==1: print("YES") else: print("NO") ```
90,629
Provide tags and a correct Python 3 solution for this coding contest problem. One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name. It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita". Names are case sensitive. Input The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 β€” the name of the problem. Output Print "YES", if problem is from this contest, and "NO" otherwise. Examples Input Alex_and_broken_contest Output NO Input NikitaAndString Output YES Input Danil_and_Olya Output NO Tags: implementation, strings Correct Solution: ``` from sys import stdin, stdout s = stdin.readline().strip() challengers = ['Danil', 'Olya', 'Slava', 'Ann', 'Nikita'] n = len(s) cnt = 0 s += '#' * 50 for i in range(n): for f in challengers: if s[i: i + len(f)] == f: cnt += 1 if cnt == 1: stdout.write('YES') else: stdout.write('NO') ```
90,630
Provide tags and a correct Python 3 solution for this coding contest problem. One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name. It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita". Names are case sensitive. Input The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 β€” the name of the problem. Output Print "YES", if problem is from this contest, and "NO" otherwise. Examples Input Alex_and_broken_contest Output NO Input NikitaAndString Output YES Input Danil_and_Olya Output NO Tags: implementation, strings Correct Solution: ``` s = input() print('YES' if sum(s.count(n) for n in ["Danil", "Olya", "Slava", "Ann", "Nikita"]) == 1 else 'NO') ```
90,631
Provide tags and a correct Python 3 solution for this coding contest problem. One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name. It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita". Names are case sensitive. Input The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 β€” the name of the problem. Output Print "YES", if problem is from this contest, and "NO" otherwise. Examples Input Alex_and_broken_contest Output NO Input NikitaAndString Output YES Input Danil_and_Olya Output NO Tags: implementation, strings Correct Solution: ``` s = input() lis = ["Danil", "Olya", "Slava", "Ann" , "Nikita"] r = sum([s.count(i) for i in lis]) print('NO YES'.split()[r==1]) ```
90,632
Provide tags and a correct Python 3 solution for this coding contest problem. One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name. It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita". Names are case sensitive. Input The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 β€” the name of the problem. Output Print "YES", if problem is from this contest, and "NO" otherwise. Examples Input Alex_and_broken_contest Output NO Input NikitaAndString Output YES Input Danil_and_Olya Output NO Tags: implementation, strings Correct Solution: ``` def get_ans(s, t): return s.count(t) s = input() a = get_ans(s, "Ann") + get_ans(s, "Danil") + get_ans(s, "Olya") + get_ans(s, "Slava") + get_ans(s, "Nikita") if a == 1: print("YES") else: print("NO") ```
90,633
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name. It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita". Names are case sensitive. Input The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 β€” the name of the problem. Output Print "YES", if problem is from this contest, and "NO" otherwise. Examples Input Alex_and_broken_contest Output NO Input NikitaAndString Output YES Input Danil_and_Olya Output NO Submitted Solution: ``` s = input() a = ['Olya', 'Danil', 'Slava', 'Nikita', 'Ann'] res = 0 for i in range(5): if a[i] in s: res += s.count(a[i]) print('YES' if res == 1 else 'NO') ``` Yes
90,634
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name. It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita". Names are case sensitive. Input The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 β€” the name of the problem. Output Print "YES", if problem is from this contest, and "NO" otherwise. Examples Input Alex_and_broken_contest Output NO Input NikitaAndString Output YES Input Danil_and_Olya Output NO Submitted Solution: ``` # http://codeforces.com/problemset/problem/877/A def count_in(smstr): friends = ['Danil', 'Olya', 'Slava', 'Ann', 'Nikita'] countm = 0 for x in friends: countm += smstr.count(x) return countm def main(): inp = input() f1 = count_in(inp) if f1 == 1: return "YES" return "NO" if __name__ == "__main__": print(main()) # input() ``` Yes
90,635
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name. It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita". Names are case sensitive. Input The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 β€” the name of the problem. Output Print "YES", if problem is from this contest, and "NO" otherwise. Examples Input Alex_and_broken_contest Output NO Input NikitaAndString Output YES Input Danil_and_Olya Output NO Submitted Solution: ``` str=input() a=str.count("Danil") a+=str.count("Olya") a+=str.count("Slava") a+=str.count("Ann") a+=str.count("Nikita") if(a==1): print("YES") else: print("NO") ``` Yes
90,636
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name. It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita". Names are case sensitive. Input The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 β€” the name of the problem. Output Print "YES", if problem is from this contest, and "NO" otherwise. Examples Input Alex_and_broken_contest Output NO Input NikitaAndString Output YES Input Danil_and_Olya Output NO Submitted Solution: ``` ns = ["Danil", "Olya", "Slava", "Ann", "Nikita"] s = input() c = 0 for n in ns: c += s.count(n) print("YNEOS"[c != 1::2]) ``` Yes
90,637
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name. It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita". Names are case sensitive. Input The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 β€” the name of the problem. Output Print "YES", if problem is from this contest, and "NO" otherwise. Examples Input Alex_and_broken_contest Output NO Input NikitaAndString Output YES Input Danil_and_Olya Output NO Submitted Solution: ``` name=input() num=name.count('Danil') num=name.count('Olya') num=name.count('Slava') num=name.count('Ann') num=name.count('Nikita') if num==1: print('YES') else: print('NO') ``` No
90,638
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name. It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita". Names are case sensitive. Input The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 β€” the name of the problem. Output Print "YES", if problem is from this contest, and "NO" otherwise. Examples Input Alex_and_broken_contest Output NO Input NikitaAndString Output YES Input Danil_and_Olya Output NO Submitted Solution: ``` def main(): name = ["DANIL","OLYA","SLAVA","ANN","NIKITA"] t = 0 x = input() for i in name: if i in x.upper(): t += 1 if t == 1: print("YES") else: print("NO") main() ``` No
90,639
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name. It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita". Names are case sensitive. Input The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 β€” the name of the problem. Output Print "YES", if problem is from this contest, and "NO" otherwise. Examples Input Alex_and_broken_contest Output NO Input NikitaAndString Output YES Input Danil_and_Olya Output NO Submitted Solution: ``` s = input() a = ['Danil', 'Olya', 'Slava', 'Ann', 'Nikita'] an = 0 for i in range(len(a)): if a[i] in s: an += 1 if an == 0: print('YES') else: print('NO') ``` No
90,640
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name. It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita". Names are case sensitive. Input The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 β€” the name of the problem. Output Print "YES", if problem is from this contest, and "NO" otherwise. Examples Input Alex_and_broken_contest Output NO Input NikitaAndString Output YES Input Danil_and_Olya Output NO Submitted Solution: ``` import sys def input(): return sys.stdin.readline().strip() def iinput(): return int(input()) def minput(): return map(int, input().split()) def listinput(): return list(map(int, input().split())) s=input() if s.count("Danil")+s.count("Olya")+s.count("Slava")+s.count("Ann")+s.count("Nikita"): print("YES") else: print("NO") ``` No
90,641
Provide tags and a correct Python 3 solution for this coding contest problem. You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point. Input The first contains three single positive integers a, b, c (1 ≀ a < b ≀ 105, 0 ≀ c ≀ 9). Output Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1. Examples Input 1 2 0 Output 2 Input 2 3 7 Output -1 Note The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position. The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction. Tags: math, number theory Correct Solution: ``` a, b, c = map(int, input().split()) pos = -1 for i in range(1, 309): if int((a * pow(10, i) // b)) % 10 == c: pos = i break print(pos) #128 7 0 ```
90,642
Provide tags and a correct Python 3 solution for this coding contest problem. You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point. Input The first contains three single positive integers a, b, c (1 ≀ a < b ≀ 105, 0 ≀ c ≀ 9). Output Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1. Examples Input 1 2 0 Output 2 Input 2 3 7 Output -1 Note The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position. The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction. Tags: math, number theory Correct Solution: ``` import decimal a, b, c = map(int, input().split()) decimal.getcontext().prec = 3 * b + 100 s = str(decimal.Decimal(a) / decimal.Decimal(b)).ljust(3 * b + 100, '0') r = s.find(str(c), 2, 2 * b + 8) - 1 if r == -2: print(-1) else: print(r) ```
90,643
Provide tags and a correct Python 3 solution for this coding contest problem. You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point. Input The first contains three single positive integers a, b, c (1 ≀ a < b ≀ 105, 0 ≀ c ≀ 9). Output Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1. Examples Input 1 2 0 Output 2 Input 2 3 7 Output -1 Note The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position. The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction. Tags: math, number theory Correct Solution: ``` from decimal import * getcontext().prec = 300 split_strings = input().split() [a, b, c] = map(lambda x: int(x), split_strings) a = Decimal(a) b = Decimal(b) decimal = (a / b) * 10 for i in range(1, 300): ones = int(decimal) fractional = decimal % 1 if ones == c: print(i) exit() decimal = fractional * 10 print(-1) ```
90,644
Provide tags and a correct Python 3 solution for this coding contest problem. You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point. Input The first contains three single positive integers a, b, c (1 ≀ a < b ≀ 105, 0 ≀ c ≀ 9). Output Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1. Examples Input 1 2 0 Output 2 Input 2 3 7 Output -1 Note The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position. The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction. Tags: math, number theory Correct Solution: ``` a,b,c = map(int,input().split(" ")) a = a%b i = 1 while i <= b : if a==0: if c==0 : print(i) exit() else : print(-1) exit() if a<b : a *= 10 while(a<b) : if c==0 : print(i) exit() a *= 10 i += 1 d = a//b if d==c: print(i) exit() a -= d*b i += 1 print(-1) ```
90,645
Provide tags and a correct Python 3 solution for this coding contest problem. You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point. Input The first contains three single positive integers a, b, c (1 ≀ a < b ≀ 105, 0 ≀ c ≀ 9). Output Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1. Examples Input 1 2 0 Output 2 Input 2 3 7 Output -1 Note The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position. The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction. Tags: math, number theory Correct Solution: ``` a, b, c = input().split() a = int(a) b = int(b) c = int(c) num = [] cnt = 0 while True: cnt += 1 num.append( a ) n = a*10//b if n == c: break a = a*10 - n*b if a in num: cnt = -1 break print( cnt ) ```
90,646
Provide tags and a correct Python 3 solution for this coding contest problem. You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point. Input The first contains three single positive integers a, b, c (1 ≀ a < b ≀ 105, 0 ≀ c ≀ 9). Output Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1. Examples Input 1 2 0 Output 2 Input 2 3 7 Output -1 Note The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position. The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction. Tags: math, number theory Correct Solution: ``` from decimal import * getcontext().prec = 10000 a, b, c = map(int, input().split()) d = Decimal(a)/Decimal(b) # print(d) s = str(d)[2:] if len(s) > 900: s = s[:-1] else: s += '0' # print(s) try: ans = s.index(str(c)) except ValueError: print(-1) else: print(ans+1) ```
90,647
Provide tags and a correct Python 3 solution for this coding contest problem. You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point. Input The first contains three single positive integers a, b, c (1 ≀ a < b ≀ 105, 0 ≀ c ≀ 9). Output Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1. Examples Input 1 2 0 Output 2 Input 2 3 7 Output -1 Note The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position. The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction. Tags: math, number theory Correct Solution: ``` a,b,c=map(int,input().split()) r=a%b t=b cnt=1 f=0 while(t!=0): r*=10 k=r//b r=r%b if(k==c): f=1 break cnt+=1 t-=1 if(f): print(cnt) else: print(-1) ```
90,648
Provide tags and a correct Python 3 solution for this coding contest problem. You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point. Input The first contains three single positive integers a, b, c (1 ≀ a < b ≀ 105, 0 ≀ c ≀ 9). Output Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1. Examples Input 1 2 0 Output 2 Input 2 3 7 Output -1 Note The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position. The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction. Tags: math, number theory Correct Solution: ``` from decimal import * getcontext().prec = 2048 getcontext().rounding = ROUND_DOWN num, denom, target = [int(x) for x in input().split()] a = Decimal(num)/Decimal(denom) a = str(a) a = a[a.find('.') : ] if len(a) < 2047: a = a + '0' print(a.find(str(target))) ```
90,649
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point. Input The first contains three single positive integers a, b, c (1 ≀ a < b ≀ 105, 0 ≀ c ≀ 9). Output Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1. Examples Input 1 2 0 Output 2 Input 2 3 7 Output -1 Note The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position. The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction. Submitted Solution: ``` from fractions import Fraction (a, b, c) = tuple(map(int, input().split())) f = Fraction(a, b) for i in range(900): for j in range(10): if f < Fraction(j+1, 10): if j == c: print(i+1) exit(0) f -= Fraction(j, 10) f *= 10 break print(-1) ``` Yes
90,650
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point. Input The first contains three single positive integers a, b, c (1 ≀ a < b ≀ 105, 0 ≀ c ≀ 9). Output Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1. Examples Input 1 2 0 Output 2 Input 2 3 7 Output -1 Note The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position. The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction. Submitted Solution: ``` from decimal import * def main(): getcontext().prec = 500 a, b, c = map(int, input().split()) d = str(Decimal(a) / Decimal(b)) d += "0" * (502 - (len(d))) cnt = [-2] * 10 for idx, item in enumerate(d[2:-1]): if cnt[int(item)] == -2: cnt[int(item)] = idx print(cnt[c] + 1) if __name__ == "__main__": main() ``` Yes
90,651
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point. Input The first contains three single positive integers a, b, c (1 ≀ a < b ≀ 105, 0 ≀ c ≀ 9). Output Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1. Examples Input 1 2 0 Output 2 Input 2 3 7 Output -1 Note The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position. The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction. Submitted Solution: ``` arr = list(map(int, input().split())) a=arr[0] b=arr[1] c=arr[2] for i in range(1,b+1): a*=10 if a//b==c: print(i) break a%=b else: print(-1) ``` Yes
90,652
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point. Input The first contains three single positive integers a, b, c (1 ≀ a < b ≀ 105, 0 ≀ c ≀ 9). Output Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1. Examples Input 1 2 0 Output 2 Input 2 3 7 Output -1 Note The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position. The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction. Submitted Solution: ``` a, b, c = input().split() a = int(a) b = int(b) c = int(c) d = (10**10000) * a // b x = 10 ** (10000 - 1) for i in range(1, 1001, 1): if d // x == c: print(i) exit(0) d %= x x //= 10 print(-1) ``` Yes
90,653
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point. Input The first contains three single positive integers a, b, c (1 ≀ a < b ≀ 105, 0 ≀ c ≀ 9). Output Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1. Examples Input 1 2 0 Output 2 Input 2 3 7 Output -1 Note The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position. The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction. Submitted Solution: ``` a,b,c=map(int,input().split()) a=(a%b) count=0 l=0 m=0 n=0 k=0 while True: n=k a*=10 k=a//b a=(a%b) count+=1 if k==c: l+=1 print(count) break if a==0 and c!=0 : m+=1 break if n==k and c==k: print(count-1) break if n==k: m+=1 break if m>l: print('-1') ``` No
90,654
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point. Input The first contains three single positive integers a, b, c (1 ≀ a < b ≀ 105, 0 ≀ c ≀ 9). Output Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1. Examples Input 1 2 0 Output 2 Input 2 3 7 Output -1 Note The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position. The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction. Submitted Solution: ``` a, b,c = map(int, input().split()) ans = float(a/b) ans = format(ans, '.20f') ans = str(ans) ans = ans[2:len(ans)] if(ans.count(str(c)) > 0): print(str(ans.index(str(c))+1)) else: print("-1") ``` No
90,655
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point. Input The first contains three single positive integers a, b, c (1 ≀ a < b ≀ 105, 0 ≀ c ≀ 9). Output Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1. Examples Input 1 2 0 Output 2 Input 2 3 7 Output -1 Note The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position. The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction. Submitted Solution: ``` a, b, c = map(int, input().split()) for i in range (b): z = a*10 if z // b == c : print (i+1) break a %= b else: print(-1) ``` No
90,656
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point. Input The first contains three single positive integers a, b, c (1 ≀ a < b ≀ 105, 0 ≀ c ≀ 9). Output Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1. Examples Input 1 2 0 Output 2 Input 2 3 7 Output -1 Note The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position. The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction. Submitted Solution: ``` a,b,c=input().split() a=int(a) b=int(b) c=int(c) l=[] rem=a j=0 while 1: ans=rem*10//b l.append(ans) j+=1 rem=rem*10%b if j==1: continue if ans==l[0] or rem==0: if rem==0: l.append(0) break j=1 find=False for i in l: if c==i: print(j) find=True break j+=1 if not find: print(-1) ``` No
90,657
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Imp is really pleased that you helped him. But it you solve the last problem, his gladness would raise even more. <image> Let's define <image> for some set of integers <image> as the number of pairs a, b in <image>, such that: * a is strictly less than b; * a divides b without a remainder. You are to find such a set <image>, which is a subset of {1, 2, ..., n} (the set that contains all positive integers not greater than n), that <image>. Input The only line contains two integers n and k <image>. Output If there is no answer, print "No". Otherwise, in the first line print "Yes", in the second β€” an integer m that denotes the size of the set <image> you have found, in the second line print m integers β€” the elements of the set <image>, in any order. If there are multiple answers, print any of them. Examples Input 3 3 Output No Input 6 6 Output Yes 5 1 2 4 5 6 Input 8 3 Output Yes 4 2 4 5 8 Note In the second sample, the valid pairs in the output set are (1, 2), (1, 4), (1, 5), (1, 6), (2, 4), (2, 6). Thus, <image>. In the third example, the valid pairs in the output set are (2, 4), (4, 8), (2, 8). Thus, <image>. Submitted Solution: ``` import math def div(n,lim) : ans=0 for i in range(1, int(math.sqrt(n) + 1)) : if (n % i == 0) : # Check if divisors are equal if (n / i == i) : if i>=lim: ans+=1 else : # Otherwise print both if i>=lim: ans+=1 if (int(n / i))>=lim: ans+=1 return ans global x x=[] n,k=list(map(int,input().split())) if n==300000: print("No") else: s=[0 for i in range(n//2)] for i in range(n//2): s[i]=(n//(i+1))-1 a=0 lim=0 for i in range(1,len(s)+1): a+=s[-i] if a>=k: lim=len(s)-i+1 break dif=a-k r=n//2 r+=1 no=[] f=[] for i in range((n//2)+1,n+1): x=div(i,lim)-1 if x<=dif: dif-=x no.append(i) if dif==0: break if dif!=0 or n==300000 : print("No") else: print("Yes") ans=[i for i in range(lim,n+1)] for i in no: ans.remove(i) print(len(ans)) for i in ans: print(i,end=" ") ``` No
90,658
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Imp is really pleased that you helped him. But it you solve the last problem, his gladness would raise even more. <image> Let's define <image> for some set of integers <image> as the number of pairs a, b in <image>, such that: * a is strictly less than b; * a divides b without a remainder. You are to find such a set <image>, which is a subset of {1, 2, ..., n} (the set that contains all positive integers not greater than n), that <image>. Input The only line contains two integers n and k <image>. Output If there is no answer, print "No". Otherwise, in the first line print "Yes", in the second β€” an integer m that denotes the size of the set <image> you have found, in the second line print m integers β€” the elements of the set <image>, in any order. If there are multiple answers, print any of them. Examples Input 3 3 Output No Input 6 6 Output Yes 5 1 2 4 5 6 Input 8 3 Output Yes 4 2 4 5 8 Note In the second sample, the valid pairs in the output set are (1, 2), (1, 4), (1, 5), (1, 6), (2, 4), (2, 6). Thus, <image>. In the third example, the valid pairs in the output set are (2, 4), (4, 8), (2, 8). Thus, <image>. Submitted Solution: ``` global x x=[] def criba(n): global x,prime prime = [True for i in range(n+1)] p = 2 while (p * p <= n): if (prime[p] == True): for i in range(p * 2, n+1, p): prime[i] = False p += 1 for i in range(2,n+1): if prime[i]: x.append(i) n,k=list(map(int,input().split())) criba(n) s=[0 for i in range(n)] for i in range(n//2): s[i]=(n//(i+1))-1 i=n//2 i=i-1 y=0 while i>=0 and y<k: y+=s[i] i-=1 dif=y-k lim=i+2 no=[] ans=[] if dif<0: print("No") else: print("Yes") for j in range(len(x)): if i==-1: if s[x[j]-1]+1<=dif: dif-=s[x[j]-1]+1 no.append(x[j]) else: if s[x[j]-1]<=dif: dif-=s[x[j]-1] no.append(x[j]) if dif==0: break for j in range(lim,n+1): if len(no)==0 or j!=no[0]: ans.append(j) else: no.remove(no[0]) if dif!=0: t=lim**2 t=t+lim t1=lim**3 while dif!=0: if t<t1: dif-=1 no.append(t) else: t=t1+lim t1=t1*lim t+=lim ans1=[] for j in ans: if len(no)==0 or j!=no[0]: ans1.append(j) else: no.remove(no[0]) print(len(ans1)) for i in ans1: print(i,end=" ") else: for i in ans: print(i,end=" ") ``` No
90,659
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Imp is really pleased that you helped him. But it you solve the last problem, his gladness would raise even more. <image> Let's define <image> for some set of integers <image> as the number of pairs a, b in <image>, such that: * a is strictly less than b; * a divides b without a remainder. You are to find such a set <image>, which is a subset of {1, 2, ..., n} (the set that contains all positive integers not greater than n), that <image>. Input The only line contains two integers n and k <image>. Output If there is no answer, print "No". Otherwise, in the first line print "Yes", in the second β€” an integer m that denotes the size of the set <image> you have found, in the second line print m integers β€” the elements of the set <image>, in any order. If there are multiple answers, print any of them. Examples Input 3 3 Output No Input 6 6 Output Yes 5 1 2 4 5 6 Input 8 3 Output Yes 4 2 4 5 8 Note In the second sample, the valid pairs in the output set are (1, 2), (1, 4), (1, 5), (1, 6), (2, 4), (2, 6). Thus, <image>. In the third example, the valid pairs in the output set are (2, 4), (4, 8), (2, 8). Thus, <image>. Submitted Solution: ``` n,k=list(map(int,input().split())) if ( n==300000 and k==1000000000)or ( n==300000 and k==3529833): if ( n==300000 and k==1000000000): print("No") else: print(n) for i in range(1,n+1): print(i, end=" ") else: s=[1 for i in range(n)] s[0]=0 for i in range(2,n//2+1): x=i+i while x<=n: s[x-1]+=1 x+=i k1=0; lim=0 for i in range(n): k1+=s[i] if k1 >=k: lim =i break dif=k1-k if dif<0 : print("No") else: print("Yes") for i in range(lim//2+1): s[i]+=(lim+1)//(i+1)-1 t=True print(lim) for i in range(lim+1): if t: if s[i]!=dif: print(i+1,end=" ") else: t=False else: print(i+1,end=" ") ``` No
90,660
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Imp is really pleased that you helped him. But it you solve the last problem, his gladness would raise even more. <image> Let's define <image> for some set of integers <image> as the number of pairs a, b in <image>, such that: * a is strictly less than b; * a divides b without a remainder. You are to find such a set <image>, which is a subset of {1, 2, ..., n} (the set that contains all positive integers not greater than n), that <image>. Input The only line contains two integers n and k <image>. Output If there is no answer, print "No". Otherwise, in the first line print "Yes", in the second β€” an integer m that denotes the size of the set <image> you have found, in the second line print m integers β€” the elements of the set <image>, in any order. If there are multiple answers, print any of them. Examples Input 3 3 Output No Input 6 6 Output Yes 5 1 2 4 5 6 Input 8 3 Output Yes 4 2 4 5 8 Note In the second sample, the valid pairs in the output set are (1, 2), (1, 4), (1, 5), (1, 6), (2, 4), (2, 6). Thus, <image>. In the third example, the valid pairs in the output set are (2, 4), (4, 8), (2, 8). Thus, <image>. Submitted Solution: ``` global x x=[] def criba(n): global x,prime prime = [True for i in range(n+1)] p = 2 while (p * p <= n): if (prime[p] == True): for i in range(p * 2, n+1, p): prime[i] = False p += 1 for i in range((n//2)+1,n+1): if prime[i]: x.append(i) n,k=list(map(int,input().split())) s=[0 for i in range(n)] for i in range(n): s[i]=(n//(i+1))-1 a=0 lim=0 for i in range(n//2): a+=s[i] if a>=k: lim=i+1 break dif=a-k criba(n) no=[] print(dif) for i in x: if dif>0 and i>lim: dif-=1 no.append(i) elif dif==0: break if dif!=0: print("No") else: print("Yes") ans=[i for i in range(1,lim+1)] ans1=[i for i in range((n//2)+1,n+1)] ans=ans+ans1 for i in no: ans.remove(i) print(len(ans)) for i in ans: print(i,end=" ") ``` No
90,661
Provide tags and a correct Python 3 solution for this coding contest problem. Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information. Zhorik knows that each of the messages is an archive containing one or more files. Zhorik knows how each of these archives was transferred through the network: if an archive consists of k files of sizes l1, l2, ..., lk bytes, then the i-th file is split to one or more blocks bi, 1, bi, 2, ..., bi, mi (here the total length of the blocks bi, 1 + bi, 2 + ... + bi, mi is equal to the length of the file li), and after that all blocks are transferred through the network, maintaining the order of files in the archive. Zhorik thinks that the two messages contain the same archive, because their total lengths are equal. However, each file can be split in blocks in different ways in the two messages. You are given the lengths of blocks in each of the two messages. Help Zhorik to determine what is the maximum number of files could be in the archive, if the Zhorik's assumption is correct. Input The first line contains two integers n, m (1 ≀ n, m ≀ 105) β€” the number of blocks in the first and in the second messages. The second line contains n integers x1, x2, ..., xn (1 ≀ xi ≀ 106) β€” the length of the blocks that form the first message. The third line contains m integers y1, y2, ..., ym (1 ≀ yi ≀ 106) β€” the length of the blocks that form the second message. It is guaranteed that x1 + ... + xn = y1 + ... + ym. Also, it is guaranteed that x1 + ... + xn ≀ 106. Output Print the maximum number of files the intercepted array could consist of. Examples Input 7 6 2 5 3 1 11 4 4 7 8 2 4 1 8 Output 3 Input 3 3 1 10 100 1 100 10 Output 2 Input 1 4 4 1 1 1 1 Output 1 Note In the first example the maximum number of files in the archive is 3. For example, it is possible that in the archive are three files of sizes 2 + 5 = 7, 15 = 3 + 1 + 11 = 8 + 2 + 4 + 1 and 4 + 4 = 8. In the second example it is possible that the archive contains two files of sizes 1 and 110 = 10 + 100 = 100 + 10. Note that the order of files is kept while transferring archives through the network, so we can't say that there are three files of sizes 1, 10 and 100. In the third example the only possibility is that the archive contains a single file of size 4. Tags: greedy, implementation Correct Solution: ``` n, m = map(int, input().split()) xs = list(map(int, input().split())) ys = list(map(int, input().split())) sm1 = sm2 = 0 i = j = 0 cnt = 0 moveX = moveY = True while i < len(xs): if moveX: sm1 += xs[i] if moveY: sm2 += ys[j] if sm1 < sm2: i += 1 moveX = True moveY = False elif sm1 > sm2: j += 1 moveX = False moveY = True else: sm1 = sm2 = 0 cnt += 1 i += 1 j += 1 moveX = True moveY = True print(cnt) ```
90,662
Provide tags and a correct Python 3 solution for this coding contest problem. Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information. Zhorik knows that each of the messages is an archive containing one or more files. Zhorik knows how each of these archives was transferred through the network: if an archive consists of k files of sizes l1, l2, ..., lk bytes, then the i-th file is split to one or more blocks bi, 1, bi, 2, ..., bi, mi (here the total length of the blocks bi, 1 + bi, 2 + ... + bi, mi is equal to the length of the file li), and after that all blocks are transferred through the network, maintaining the order of files in the archive. Zhorik thinks that the two messages contain the same archive, because their total lengths are equal. However, each file can be split in blocks in different ways in the two messages. You are given the lengths of blocks in each of the two messages. Help Zhorik to determine what is the maximum number of files could be in the archive, if the Zhorik's assumption is correct. Input The first line contains two integers n, m (1 ≀ n, m ≀ 105) β€” the number of blocks in the first and in the second messages. The second line contains n integers x1, x2, ..., xn (1 ≀ xi ≀ 106) β€” the length of the blocks that form the first message. The third line contains m integers y1, y2, ..., ym (1 ≀ yi ≀ 106) β€” the length of the blocks that form the second message. It is guaranteed that x1 + ... + xn = y1 + ... + ym. Also, it is guaranteed that x1 + ... + xn ≀ 106. Output Print the maximum number of files the intercepted array could consist of. Examples Input 7 6 2 5 3 1 11 4 4 7 8 2 4 1 8 Output 3 Input 3 3 1 10 100 1 100 10 Output 2 Input 1 4 4 1 1 1 1 Output 1 Note In the first example the maximum number of files in the archive is 3. For example, it is possible that in the archive are three files of sizes 2 + 5 = 7, 15 = 3 + 1 + 11 = 8 + 2 + 4 + 1 and 4 + 4 = 8. In the second example it is possible that the archive contains two files of sizes 1 and 110 = 10 + 100 = 100 + 10. Note that the order of files is kept while transferring archives through the network, so we can't say that there are three files of sizes 1, 10 and 100. In the third example the only possibility is that the archive contains a single file of size 4. Tags: greedy, implementation Correct Solution: ``` n,m = map(int, input().split()) x = list(map(int, input().split())) y = list(map(int, input().split())) i1 = 0 i2 = 0 sum1 = x[0] sum2 = y[0] count = 0 while i1 != n and i2 != m: while sum1 < sum2: i1 += 1 if i1 == n: break sum1 += x[i1] if i1 == n: break if (sum1 == sum2): count += 1 i1 += 1 if i1 == n: break sum1 += x[i1] while sum2 < sum1: i2 += 1 if i2 == m: break sum2 += y[i2] if i1 == n: break if (sum1 == sum2): count += 1 i2 += 1 if i2 == m: break sum2 += y[i2] print(count) ```
90,663
Provide tags and a correct Python 3 solution for this coding contest problem. Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information. Zhorik knows that each of the messages is an archive containing one or more files. Zhorik knows how each of these archives was transferred through the network: if an archive consists of k files of sizes l1, l2, ..., lk bytes, then the i-th file is split to one or more blocks bi, 1, bi, 2, ..., bi, mi (here the total length of the blocks bi, 1 + bi, 2 + ... + bi, mi is equal to the length of the file li), and after that all blocks are transferred through the network, maintaining the order of files in the archive. Zhorik thinks that the two messages contain the same archive, because their total lengths are equal. However, each file can be split in blocks in different ways in the two messages. You are given the lengths of blocks in each of the two messages. Help Zhorik to determine what is the maximum number of files could be in the archive, if the Zhorik's assumption is correct. Input The first line contains two integers n, m (1 ≀ n, m ≀ 105) β€” the number of blocks in the first and in the second messages. The second line contains n integers x1, x2, ..., xn (1 ≀ xi ≀ 106) β€” the length of the blocks that form the first message. The third line contains m integers y1, y2, ..., ym (1 ≀ yi ≀ 106) β€” the length of the blocks that form the second message. It is guaranteed that x1 + ... + xn = y1 + ... + ym. Also, it is guaranteed that x1 + ... + xn ≀ 106. Output Print the maximum number of files the intercepted array could consist of. Examples Input 7 6 2 5 3 1 11 4 4 7 8 2 4 1 8 Output 3 Input 3 3 1 10 100 1 100 10 Output 2 Input 1 4 4 1 1 1 1 Output 1 Note In the first example the maximum number of files in the archive is 3. For example, it is possible that in the archive are three files of sizes 2 + 5 = 7, 15 = 3 + 1 + 11 = 8 + 2 + 4 + 1 and 4 + 4 = 8. In the second example it is possible that the archive contains two files of sizes 1 and 110 = 10 + 100 = 100 + 10. Note that the order of files is kept while transferring archives through the network, so we can't say that there are three files of sizes 1, 10 and 100. In the third example the only possibility is that the archive contains a single file of size 4. Tags: greedy, implementation Correct Solution: ``` n, m = map(int, input().split()) x = list(map(int, input().split())) y = list(map(int, input().split())) ans = 0 i = 0 j = 0 sumx = 0 sumy = 0 while i < n and j < m: if sumx <= sumy: sumx += x[i] i += 1 if sumy < sumx: sumy += y[j] j += 1 if sumx == sumy: ans += 1 sumx = 0 sumy = 0 if i < n or j < m: ans += 1 print(ans) ```
90,664
Provide tags and a correct Python 3 solution for this coding contest problem. Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information. Zhorik knows that each of the messages is an archive containing one or more files. Zhorik knows how each of these archives was transferred through the network: if an archive consists of k files of sizes l1, l2, ..., lk bytes, then the i-th file is split to one or more blocks bi, 1, bi, 2, ..., bi, mi (here the total length of the blocks bi, 1 + bi, 2 + ... + bi, mi is equal to the length of the file li), and after that all blocks are transferred through the network, maintaining the order of files in the archive. Zhorik thinks that the two messages contain the same archive, because their total lengths are equal. However, each file can be split in blocks in different ways in the two messages. You are given the lengths of blocks in each of the two messages. Help Zhorik to determine what is the maximum number of files could be in the archive, if the Zhorik's assumption is correct. Input The first line contains two integers n, m (1 ≀ n, m ≀ 105) β€” the number of blocks in the first and in the second messages. The second line contains n integers x1, x2, ..., xn (1 ≀ xi ≀ 106) β€” the length of the blocks that form the first message. The third line contains m integers y1, y2, ..., ym (1 ≀ yi ≀ 106) β€” the length of the blocks that form the second message. It is guaranteed that x1 + ... + xn = y1 + ... + ym. Also, it is guaranteed that x1 + ... + xn ≀ 106. Output Print the maximum number of files the intercepted array could consist of. Examples Input 7 6 2 5 3 1 11 4 4 7 8 2 4 1 8 Output 3 Input 3 3 1 10 100 1 100 10 Output 2 Input 1 4 4 1 1 1 1 Output 1 Note In the first example the maximum number of files in the archive is 3. For example, it is possible that in the archive are three files of sizes 2 + 5 = 7, 15 = 3 + 1 + 11 = 8 + 2 + 4 + 1 and 4 + 4 = 8. In the second example it is possible that the archive contains two files of sizes 1 and 110 = 10 + 100 = 100 + 10. Note that the order of files is kept while transferring archives through the network, so we can't say that there are three files of sizes 1, 10 and 100. In the third example the only possibility is that the archive contains a single file of size 4. Tags: greedy, implementation Correct Solution: ``` n, m = list(map(int, input().split())) x = list(map(int, input().split())) y = list(map(int, input().split())) filesCnt = 0 xs = 0 ys = 0 xcnt = 0 ycnt = 0 while n >= xcnt or m >= ycnt: # print(xs, ys) if xs == ys and xs != 0: filesCnt += 1 xs = 0 ys = 0 if n > xcnt or m > ycnt: continue else: break else: if xs > ys: ys += y[ycnt] ycnt += 1 else: xs += x[xcnt] xcnt += 1 print(filesCnt) ```
90,665
Provide tags and a correct Python 3 solution for this coding contest problem. Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information. Zhorik knows that each of the messages is an archive containing one or more files. Zhorik knows how each of these archives was transferred through the network: if an archive consists of k files of sizes l1, l2, ..., lk bytes, then the i-th file is split to one or more blocks bi, 1, bi, 2, ..., bi, mi (here the total length of the blocks bi, 1 + bi, 2 + ... + bi, mi is equal to the length of the file li), and after that all blocks are transferred through the network, maintaining the order of files in the archive. Zhorik thinks that the two messages contain the same archive, because their total lengths are equal. However, each file can be split in blocks in different ways in the two messages. You are given the lengths of blocks in each of the two messages. Help Zhorik to determine what is the maximum number of files could be in the archive, if the Zhorik's assumption is correct. Input The first line contains two integers n, m (1 ≀ n, m ≀ 105) β€” the number of blocks in the first and in the second messages. The second line contains n integers x1, x2, ..., xn (1 ≀ xi ≀ 106) β€” the length of the blocks that form the first message. The third line contains m integers y1, y2, ..., ym (1 ≀ yi ≀ 106) β€” the length of the blocks that form the second message. It is guaranteed that x1 + ... + xn = y1 + ... + ym. Also, it is guaranteed that x1 + ... + xn ≀ 106. Output Print the maximum number of files the intercepted array could consist of. Examples Input 7 6 2 5 3 1 11 4 4 7 8 2 4 1 8 Output 3 Input 3 3 1 10 100 1 100 10 Output 2 Input 1 4 4 1 1 1 1 Output 1 Note In the first example the maximum number of files in the archive is 3. For example, it is possible that in the archive are three files of sizes 2 + 5 = 7, 15 = 3 + 1 + 11 = 8 + 2 + 4 + 1 and 4 + 4 = 8. In the second example it is possible that the archive contains two files of sizes 1 and 110 = 10 + 100 = 100 + 10. Note that the order of files is kept while transferring archives through the network, so we can't say that there are three files of sizes 1, 10 and 100. In the third example the only possibility is that the archive contains a single file of size 4. Tags: greedy, implementation Correct Solution: ``` n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) i = 0 j = 0 s = a[0] t = b[0] k = 0 while i != n and j != m: while s < t: i += 1 s += a[i] while t < s: j += 1 t += b[j] if s == t: i += 1 j += 1 k += 1 if i != n: s = a[i] t = b[j] print(k) ```
90,666
Provide tags and a correct Python 3 solution for this coding contest problem. Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information. Zhorik knows that each of the messages is an archive containing one or more files. Zhorik knows how each of these archives was transferred through the network: if an archive consists of k files of sizes l1, l2, ..., lk bytes, then the i-th file is split to one or more blocks bi, 1, bi, 2, ..., bi, mi (here the total length of the blocks bi, 1 + bi, 2 + ... + bi, mi is equal to the length of the file li), and after that all blocks are transferred through the network, maintaining the order of files in the archive. Zhorik thinks that the two messages contain the same archive, because their total lengths are equal. However, each file can be split in blocks in different ways in the two messages. You are given the lengths of blocks in each of the two messages. Help Zhorik to determine what is the maximum number of files could be in the archive, if the Zhorik's assumption is correct. Input The first line contains two integers n, m (1 ≀ n, m ≀ 105) β€” the number of blocks in the first and in the second messages. The second line contains n integers x1, x2, ..., xn (1 ≀ xi ≀ 106) β€” the length of the blocks that form the first message. The third line contains m integers y1, y2, ..., ym (1 ≀ yi ≀ 106) β€” the length of the blocks that form the second message. It is guaranteed that x1 + ... + xn = y1 + ... + ym. Also, it is guaranteed that x1 + ... + xn ≀ 106. Output Print the maximum number of files the intercepted array could consist of. Examples Input 7 6 2 5 3 1 11 4 4 7 8 2 4 1 8 Output 3 Input 3 3 1 10 100 1 100 10 Output 2 Input 1 4 4 1 1 1 1 Output 1 Note In the first example the maximum number of files in the archive is 3. For example, it is possible that in the archive are three files of sizes 2 + 5 = 7, 15 = 3 + 1 + 11 = 8 + 2 + 4 + 1 and 4 + 4 = 8. In the second example it is possible that the archive contains two files of sizes 1 and 110 = 10 + 100 = 100 + 10. Note that the order of files is kept while transferring archives through the network, so we can't say that there are three files of sizes 1, 10 and 100. In the third example the only possibility is that the archive contains a single file of size 4. Tags: greedy, implementation Correct Solution: ``` n,m = map(int,input().split(' ')) a = list(map(int,input().split(' '))) b = list(map(int,input().split(' '))) i = j = 0 sa = a[0] sb = b[0] k = 0 while i<n-1 and j<m-1: if sa<sb: i+=1 sa+=a[i] elif sb<sa: j+=1 sb+=b[j] else: i+=1 j+=1 sa+=a[i] sb+=b[j] k+=1 if i<n or j<m: k+=1 print(k) ```
90,667
Provide tags and a correct Python 3 solution for this coding contest problem. Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information. Zhorik knows that each of the messages is an archive containing one or more files. Zhorik knows how each of these archives was transferred through the network: if an archive consists of k files of sizes l1, l2, ..., lk bytes, then the i-th file is split to one or more blocks bi, 1, bi, 2, ..., bi, mi (here the total length of the blocks bi, 1 + bi, 2 + ... + bi, mi is equal to the length of the file li), and after that all blocks are transferred through the network, maintaining the order of files in the archive. Zhorik thinks that the two messages contain the same archive, because their total lengths are equal. However, each file can be split in blocks in different ways in the two messages. You are given the lengths of blocks in each of the two messages. Help Zhorik to determine what is the maximum number of files could be in the archive, if the Zhorik's assumption is correct. Input The first line contains two integers n, m (1 ≀ n, m ≀ 105) β€” the number of blocks in the first and in the second messages. The second line contains n integers x1, x2, ..., xn (1 ≀ xi ≀ 106) β€” the length of the blocks that form the first message. The third line contains m integers y1, y2, ..., ym (1 ≀ yi ≀ 106) β€” the length of the blocks that form the second message. It is guaranteed that x1 + ... + xn = y1 + ... + ym. Also, it is guaranteed that x1 + ... + xn ≀ 106. Output Print the maximum number of files the intercepted array could consist of. Examples Input 7 6 2 5 3 1 11 4 4 7 8 2 4 1 8 Output 3 Input 3 3 1 10 100 1 100 10 Output 2 Input 1 4 4 1 1 1 1 Output 1 Note In the first example the maximum number of files in the archive is 3. For example, it is possible that in the archive are three files of sizes 2 + 5 = 7, 15 = 3 + 1 + 11 = 8 + 2 + 4 + 1 and 4 + 4 = 8. In the second example it is possible that the archive contains two files of sizes 1 and 110 = 10 + 100 = 100 + 10. Note that the order of files is kept while transferring archives through the network, so we can't say that there are three files of sizes 1, 10 and 100. In the third example the only possibility is that the archive contains a single file of size 4. Tags: greedy, implementation Correct Solution: ``` import os import sys debug = True if debug and os.path.exists("input.in"): input = open("input.in", "r").readline else: debug = False input = sys.stdin.readline def inp(): return (int(input())) def inlt(): return (list(map(int, input().split()))) def insr(): s = input() return s[:len(s) - 1] # Remove line char from end def invr(): return (map(int, input().split())) test_count = 1 if debug: test_count = inp() for t in range(test_count): if debug: print("Test Case #", t + 1) # Start code here ans = 0 n, m = invr() a = inlt() b = inlt() i = 0 j = 0 a_sum = a[0] b_sum = b[0] while i < n and j < m: if a_sum < b_sum: i += 1 a_sum += a[i] elif a_sum > b_sum: j += 1 b_sum += b[j] else: ans += 1 i += 1 j += 1 if i == n and j == m: break a_sum += a[i] b_sum += b[j] print(ans) ```
90,668
Provide tags and a correct Python 3 solution for this coding contest problem. Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information. Zhorik knows that each of the messages is an archive containing one or more files. Zhorik knows how each of these archives was transferred through the network: if an archive consists of k files of sizes l1, l2, ..., lk bytes, then the i-th file is split to one or more blocks bi, 1, bi, 2, ..., bi, mi (here the total length of the blocks bi, 1 + bi, 2 + ... + bi, mi is equal to the length of the file li), and after that all blocks are transferred through the network, maintaining the order of files in the archive. Zhorik thinks that the two messages contain the same archive, because their total lengths are equal. However, each file can be split in blocks in different ways in the two messages. You are given the lengths of blocks in each of the two messages. Help Zhorik to determine what is the maximum number of files could be in the archive, if the Zhorik's assumption is correct. Input The first line contains two integers n, m (1 ≀ n, m ≀ 105) β€” the number of blocks in the first and in the second messages. The second line contains n integers x1, x2, ..., xn (1 ≀ xi ≀ 106) β€” the length of the blocks that form the first message. The third line contains m integers y1, y2, ..., ym (1 ≀ yi ≀ 106) β€” the length of the blocks that form the second message. It is guaranteed that x1 + ... + xn = y1 + ... + ym. Also, it is guaranteed that x1 + ... + xn ≀ 106. Output Print the maximum number of files the intercepted array could consist of. Examples Input 7 6 2 5 3 1 11 4 4 7 8 2 4 1 8 Output 3 Input 3 3 1 10 100 1 100 10 Output 2 Input 1 4 4 1 1 1 1 Output 1 Note In the first example the maximum number of files in the archive is 3. For example, it is possible that in the archive are three files of sizes 2 + 5 = 7, 15 = 3 + 1 + 11 = 8 + 2 + 4 + 1 and 4 + 4 = 8. In the second example it is possible that the archive contains two files of sizes 1 and 110 = 10 + 100 = 100 + 10. Note that the order of files is kept while transferring archives through the network, so we can't say that there are three files of sizes 1, 10 and 100. In the third example the only possibility is that the archive contains a single file of size 4. Tags: greedy, implementation Correct Solution: ``` n, m = map(int, input().split()) arr1=list(map(int,input().split())) arr2=list(map(int,input().split())) file=0; sum1=0; sum2=0; i=0; j=0 while i<n or j<m: if sum1 >= sum2: sum2 += arr2[j] j+=1 else: sum1 += arr1[i] i+=1 if sum1==sum2: file+=1 print(file) ```
90,669
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information. Zhorik knows that each of the messages is an archive containing one or more files. Zhorik knows how each of these archives was transferred through the network: if an archive consists of k files of sizes l1, l2, ..., lk bytes, then the i-th file is split to one or more blocks bi, 1, bi, 2, ..., bi, mi (here the total length of the blocks bi, 1 + bi, 2 + ... + bi, mi is equal to the length of the file li), and after that all blocks are transferred through the network, maintaining the order of files in the archive. Zhorik thinks that the two messages contain the same archive, because their total lengths are equal. However, each file can be split in blocks in different ways in the two messages. You are given the lengths of blocks in each of the two messages. Help Zhorik to determine what is the maximum number of files could be in the archive, if the Zhorik's assumption is correct. Input The first line contains two integers n, m (1 ≀ n, m ≀ 105) β€” the number of blocks in the first and in the second messages. The second line contains n integers x1, x2, ..., xn (1 ≀ xi ≀ 106) β€” the length of the blocks that form the first message. The third line contains m integers y1, y2, ..., ym (1 ≀ yi ≀ 106) β€” the length of the blocks that form the second message. It is guaranteed that x1 + ... + xn = y1 + ... + ym. Also, it is guaranteed that x1 + ... + xn ≀ 106. Output Print the maximum number of files the intercepted array could consist of. Examples Input 7 6 2 5 3 1 11 4 4 7 8 2 4 1 8 Output 3 Input 3 3 1 10 100 1 100 10 Output 2 Input 1 4 4 1 1 1 1 Output 1 Note In the first example the maximum number of files in the archive is 3. For example, it is possible that in the archive are three files of sizes 2 + 5 = 7, 15 = 3 + 1 + 11 = 8 + 2 + 4 + 1 and 4 + 4 = 8. In the second example it is possible that the archive contains two files of sizes 1 and 110 = 10 + 100 = 100 + 10. Note that the order of files is kept while transferring archives through the network, so we can't say that there are three files of sizes 1, 10 and 100. In the third example the only possibility is that the archive contains a single file of size 4. Submitted Solution: ``` n, m = map(int, input().split()) n_f = list(map(int, input().split())) m_f = list(map(int, input().split())) s_n = 0 s_m = 0 f = 0 i = 0 j = 0 while i < n and j < m: if s_n > s_m: flag = True k = j while flag and k < m: s_m += m_f[k] if s_n == s_m: s_n = 0 s_m = 0 flag = False f += 1 j = k + 1 if s_m > s_n: j = k + 1 flag = False k +=1 else: flag1 = True k = i while flag1 and i < n: s_n += n_f[k] if s_n == s_m: s_n = 0 s_m = 0 flag1= False f += 1 i = k + 1 if s_n > s_m: i = k + 1 flag1 = False k += 1 print(f + 1) ``` Yes
90,670
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information. Zhorik knows that each of the messages is an archive containing one or more files. Zhorik knows how each of these archives was transferred through the network: if an archive consists of k files of sizes l1, l2, ..., lk bytes, then the i-th file is split to one or more blocks bi, 1, bi, 2, ..., bi, mi (here the total length of the blocks bi, 1 + bi, 2 + ... + bi, mi is equal to the length of the file li), and after that all blocks are transferred through the network, maintaining the order of files in the archive. Zhorik thinks that the two messages contain the same archive, because their total lengths are equal. However, each file can be split in blocks in different ways in the two messages. You are given the lengths of blocks in each of the two messages. Help Zhorik to determine what is the maximum number of files could be in the archive, if the Zhorik's assumption is correct. Input The first line contains two integers n, m (1 ≀ n, m ≀ 105) β€” the number of blocks in the first and in the second messages. The second line contains n integers x1, x2, ..., xn (1 ≀ xi ≀ 106) β€” the length of the blocks that form the first message. The third line contains m integers y1, y2, ..., ym (1 ≀ yi ≀ 106) β€” the length of the blocks that form the second message. It is guaranteed that x1 + ... + xn = y1 + ... + ym. Also, it is guaranteed that x1 + ... + xn ≀ 106. Output Print the maximum number of files the intercepted array could consist of. Examples Input 7 6 2 5 3 1 11 4 4 7 8 2 4 1 8 Output 3 Input 3 3 1 10 100 1 100 10 Output 2 Input 1 4 4 1 1 1 1 Output 1 Note In the first example the maximum number of files in the archive is 3. For example, it is possible that in the archive are three files of sizes 2 + 5 = 7, 15 = 3 + 1 + 11 = 8 + 2 + 4 + 1 and 4 + 4 = 8. In the second example it is possible that the archive contains two files of sizes 1 and 110 = 10 + 100 = 100 + 10. Note that the order of files is kept while transferring archives through the network, so we can't say that there are three files of sizes 1, 10 and 100. In the third example the only possibility is that the archive contains a single file of size 4. Submitted Solution: ``` a, b = map(int, input().split()) lista = list(map(int, input().split())) listb = list(map(int, input().split())) # print(lista) i = 0 j = 0 cnta = 0 cntb = 0 ans = 0 while(i<len(lista) and j < len(listb)): if(cnta == cntb): cnta += lista[i] cntb += listb[j] ans += 1 i += 1 j += 1 elif cnta < cntb: cnta += lista[i] i += 1 elif cnta > cntb: cntb += listb[j] j += 1 # print("cnta==" + str(cnta) + ", cntb==" + str(cntb)) print(ans) ``` Yes
90,671
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information. Zhorik knows that each of the messages is an archive containing one or more files. Zhorik knows how each of these archives was transferred through the network: if an archive consists of k files of sizes l1, l2, ..., lk bytes, then the i-th file is split to one or more blocks bi, 1, bi, 2, ..., bi, mi (here the total length of the blocks bi, 1 + bi, 2 + ... + bi, mi is equal to the length of the file li), and after that all blocks are transferred through the network, maintaining the order of files in the archive. Zhorik thinks that the two messages contain the same archive, because their total lengths are equal. However, each file can be split in blocks in different ways in the two messages. You are given the lengths of blocks in each of the two messages. Help Zhorik to determine what is the maximum number of files could be in the archive, if the Zhorik's assumption is correct. Input The first line contains two integers n, m (1 ≀ n, m ≀ 105) β€” the number of blocks in the first and in the second messages. The second line contains n integers x1, x2, ..., xn (1 ≀ xi ≀ 106) β€” the length of the blocks that form the first message. The third line contains m integers y1, y2, ..., ym (1 ≀ yi ≀ 106) β€” the length of the blocks that form the second message. It is guaranteed that x1 + ... + xn = y1 + ... + ym. Also, it is guaranteed that x1 + ... + xn ≀ 106. Output Print the maximum number of files the intercepted array could consist of. Examples Input 7 6 2 5 3 1 11 4 4 7 8 2 4 1 8 Output 3 Input 3 3 1 10 100 1 100 10 Output 2 Input 1 4 4 1 1 1 1 Output 1 Note In the first example the maximum number of files in the archive is 3. For example, it is possible that in the archive are three files of sizes 2 + 5 = 7, 15 = 3 + 1 + 11 = 8 + 2 + 4 + 1 and 4 + 4 = 8. In the second example it is possible that the archive contains two files of sizes 1 and 110 = 10 + 100 = 100 + 10. Note that the order of files is kept while transferring archives through the network, so we can't say that there are three files of sizes 1, 10 and 100. In the third example the only possibility is that the archive contains a single file of size 4. Submitted Solution: ``` n, m = map(int,input().split()) x = list(map(int,input().split())) y = list(map(int,input().split())) i,j,s1,s2=0,0,0,0 count=1 while i <= n-1 and j <= m-1: if s1==s2 and s1: count+=1 s1=0 s2=0 elif s1>s2 or not s2: s2+=y[j] j+=1 elif s1<s2 or not s1: s1+=x[i] i+=1 print(count) ``` Yes
90,672
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information. Zhorik knows that each of the messages is an archive containing one or more files. Zhorik knows how each of these archives was transferred through the network: if an archive consists of k files of sizes l1, l2, ..., lk bytes, then the i-th file is split to one or more blocks bi, 1, bi, 2, ..., bi, mi (here the total length of the blocks bi, 1 + bi, 2 + ... + bi, mi is equal to the length of the file li), and after that all blocks are transferred through the network, maintaining the order of files in the archive. Zhorik thinks that the two messages contain the same archive, because their total lengths are equal. However, each file can be split in blocks in different ways in the two messages. You are given the lengths of blocks in each of the two messages. Help Zhorik to determine what is the maximum number of files could be in the archive, if the Zhorik's assumption is correct. Input The first line contains two integers n, m (1 ≀ n, m ≀ 105) β€” the number of blocks in the first and in the second messages. The second line contains n integers x1, x2, ..., xn (1 ≀ xi ≀ 106) β€” the length of the blocks that form the first message. The third line contains m integers y1, y2, ..., ym (1 ≀ yi ≀ 106) β€” the length of the blocks that form the second message. It is guaranteed that x1 + ... + xn = y1 + ... + ym. Also, it is guaranteed that x1 + ... + xn ≀ 106. Output Print the maximum number of files the intercepted array could consist of. Examples Input 7 6 2 5 3 1 11 4 4 7 8 2 4 1 8 Output 3 Input 3 3 1 10 100 1 100 10 Output 2 Input 1 4 4 1 1 1 1 Output 1 Note In the first example the maximum number of files in the archive is 3. For example, it is possible that in the archive are three files of sizes 2 + 5 = 7, 15 = 3 + 1 + 11 = 8 + 2 + 4 + 1 and 4 + 4 = 8. In the second example it is possible that the archive contains two files of sizes 1 and 110 = 10 + 100 = 100 + 10. Note that the order of files is kept while transferring archives through the network, so we can't say that there are three files of sizes 1, 10 and 100. In the third example the only possibility is that the archive contains a single file of size 4. Submitted Solution: ``` _, _ = list(map(int, input().strip().split())) msg1 = list(map(int, input().strip().split())) msg2 = list(map(int, input().strip().split())) idx1, idx2 = 0, 0 count = 0 while idx1 < len(msg1): sum1, sum2 = msg1[idx1], msg2[idx2] while sum1 != sum2: if sum1 < sum2: idx1 += 1 sum1 += msg1[idx1] else: idx2 += 1 sum2 += msg2[idx2] idx1, idx2 = idx1 + 1, idx2 + 1 count += 1 print(count) ``` Yes
90,673
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information. Zhorik knows that each of the messages is an archive containing one or more files. Zhorik knows how each of these archives was transferred through the network: if an archive consists of k files of sizes l1, l2, ..., lk bytes, then the i-th file is split to one or more blocks bi, 1, bi, 2, ..., bi, mi (here the total length of the blocks bi, 1 + bi, 2 + ... + bi, mi is equal to the length of the file li), and after that all blocks are transferred through the network, maintaining the order of files in the archive. Zhorik thinks that the two messages contain the same archive, because their total lengths are equal. However, each file can be split in blocks in different ways in the two messages. You are given the lengths of blocks in each of the two messages. Help Zhorik to determine what is the maximum number of files could be in the archive, if the Zhorik's assumption is correct. Input The first line contains two integers n, m (1 ≀ n, m ≀ 105) β€” the number of blocks in the first and in the second messages. The second line contains n integers x1, x2, ..., xn (1 ≀ xi ≀ 106) β€” the length of the blocks that form the first message. The third line contains m integers y1, y2, ..., ym (1 ≀ yi ≀ 106) β€” the length of the blocks that form the second message. It is guaranteed that x1 + ... + xn = y1 + ... + ym. Also, it is guaranteed that x1 + ... + xn ≀ 106. Output Print the maximum number of files the intercepted array could consist of. Examples Input 7 6 2 5 3 1 11 4 4 7 8 2 4 1 8 Output 3 Input 3 3 1 10 100 1 100 10 Output 2 Input 1 4 4 1 1 1 1 Output 1 Note In the first example the maximum number of files in the archive is 3. For example, it is possible that in the archive are three files of sizes 2 + 5 = 7, 15 = 3 + 1 + 11 = 8 + 2 + 4 + 1 and 4 + 4 = 8. In the second example it is possible that the archive contains two files of sizes 1 and 110 = 10 + 100 = 100 + 10. Note that the order of files is kept while transferring archives through the network, so we can't say that there are three files of sizes 1, 10 and 100. In the third example the only possibility is that the archive contains a single file of size 4. Submitted Solution: ``` n,m = map(int,input().split()) l1 = list(map(int,input().split())) l2 = list(map(int,input().split())) i,j = 1,1 sum1 = l1[0] sum2 = l2[0] count = 0 while i < len(l1) and j < len(l2): print(sum1,sum2) if sum1 > sum2: sum2 = sum2 + l2[j] j = j + 1 elif sum2 > sum1: sum1 = sum1 + l1[i] i = i + 1 if sum2 == sum1: count = count + 1 if j < len(l2): sum2 = l2[j] j = j + 1 if i < len(l1): sum1 = l1[i] i = i + 1 count = count + 1 print(count) ``` No
90,674
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information. Zhorik knows that each of the messages is an archive containing one or more files. Zhorik knows how each of these archives was transferred through the network: if an archive consists of k files of sizes l1, l2, ..., lk bytes, then the i-th file is split to one or more blocks bi, 1, bi, 2, ..., bi, mi (here the total length of the blocks bi, 1 + bi, 2 + ... + bi, mi is equal to the length of the file li), and after that all blocks are transferred through the network, maintaining the order of files in the archive. Zhorik thinks that the two messages contain the same archive, because their total lengths are equal. However, each file can be split in blocks in different ways in the two messages. You are given the lengths of blocks in each of the two messages. Help Zhorik to determine what is the maximum number of files could be in the archive, if the Zhorik's assumption is correct. Input The first line contains two integers n, m (1 ≀ n, m ≀ 105) β€” the number of blocks in the first and in the second messages. The second line contains n integers x1, x2, ..., xn (1 ≀ xi ≀ 106) β€” the length of the blocks that form the first message. The third line contains m integers y1, y2, ..., ym (1 ≀ yi ≀ 106) β€” the length of the blocks that form the second message. It is guaranteed that x1 + ... + xn = y1 + ... + ym. Also, it is guaranteed that x1 + ... + xn ≀ 106. Output Print the maximum number of files the intercepted array could consist of. Examples Input 7 6 2 5 3 1 11 4 4 7 8 2 4 1 8 Output 3 Input 3 3 1 10 100 1 100 10 Output 2 Input 1 4 4 1 1 1 1 Output 1 Note In the first example the maximum number of files in the archive is 3. For example, it is possible that in the archive are three files of sizes 2 + 5 = 7, 15 = 3 + 1 + 11 = 8 + 2 + 4 + 1 and 4 + 4 = 8. In the second example it is possible that the archive contains two files of sizes 1 and 110 = 10 + 100 = 100 + 10. Note that the order of files is kept while transferring archives through the network, so we can't say that there are three files of sizes 1, 10 and 100. In the third example the only possibility is that the archive contains a single file of size 4. Submitted Solution: ``` x=[int(i) for i in input().split()] y=[int(i) for i in input().split()] z=[int(i) for i in input().split()] a=1 t=1 f=0 sum1=y[0] sum2=z[0] if len(y)==1 or len(z)==1: f=1 else: for i in range(1,sum(x)+1): if t>x[0]+1 or a>x[1]+1: break if sum1==sum2: f+=1 try: sum1=y[a] sum2=z[t] t+=1 a+=1 except: break elif sum1<sum2: sum1+=y[a] a+=1 elif sum1>sum2: sum2+=z[t] t+=1 print(f) ``` No
90,675
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information. Zhorik knows that each of the messages is an archive containing one or more files. Zhorik knows how each of these archives was transferred through the network: if an archive consists of k files of sizes l1, l2, ..., lk bytes, then the i-th file is split to one or more blocks bi, 1, bi, 2, ..., bi, mi (here the total length of the blocks bi, 1 + bi, 2 + ... + bi, mi is equal to the length of the file li), and after that all blocks are transferred through the network, maintaining the order of files in the archive. Zhorik thinks that the two messages contain the same archive, because their total lengths are equal. However, each file can be split in blocks in different ways in the two messages. You are given the lengths of blocks in each of the two messages. Help Zhorik to determine what is the maximum number of files could be in the archive, if the Zhorik's assumption is correct. Input The first line contains two integers n, m (1 ≀ n, m ≀ 105) β€” the number of blocks in the first and in the second messages. The second line contains n integers x1, x2, ..., xn (1 ≀ xi ≀ 106) β€” the length of the blocks that form the first message. The third line contains m integers y1, y2, ..., ym (1 ≀ yi ≀ 106) β€” the length of the blocks that form the second message. It is guaranteed that x1 + ... + xn = y1 + ... + ym. Also, it is guaranteed that x1 + ... + xn ≀ 106. Output Print the maximum number of files the intercepted array could consist of. Examples Input 7 6 2 5 3 1 11 4 4 7 8 2 4 1 8 Output 3 Input 3 3 1 10 100 1 100 10 Output 2 Input 1 4 4 1 1 1 1 Output 1 Note In the first example the maximum number of files in the archive is 3. For example, it is possible that in the archive are three files of sizes 2 + 5 = 7, 15 = 3 + 1 + 11 = 8 + 2 + 4 + 1 and 4 + 4 = 8. In the second example it is possible that the archive contains two files of sizes 1 and 110 = 10 + 100 = 100 + 10. Note that the order of files is kept while transferring archives through the network, so we can't say that there are three files of sizes 1, 10 and 100. In the third example the only possibility is that the archive contains a single file of size 4. Submitted Solution: ``` n,m=(map(int,input().strip().split(' '))) a= list(map(int,input().strip().split(' '))) b= list(map(int,input().strip().split(' '))) index = -1 i = 0 j = 0 s1 = 0 s2 = 0 cnt=0 while(i<n and j<m): if(index==0): s1+=a[i] i+=1 elif(index==1): s2+=b[j] j+=1 else: s1+=a[i] s2+=b[j] j+=1 i+=1 if(s1==s2): cnt+=1 s1=0 s2=0 index=-1 elif(s1>s2): index=1 else: index=0 print(cnt+1) ``` No
90,676
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information. Zhorik knows that each of the messages is an archive containing one or more files. Zhorik knows how each of these archives was transferred through the network: if an archive consists of k files of sizes l1, l2, ..., lk bytes, then the i-th file is split to one or more blocks bi, 1, bi, 2, ..., bi, mi (here the total length of the blocks bi, 1 + bi, 2 + ... + bi, mi is equal to the length of the file li), and after that all blocks are transferred through the network, maintaining the order of files in the archive. Zhorik thinks that the two messages contain the same archive, because their total lengths are equal. However, each file can be split in blocks in different ways in the two messages. You are given the lengths of blocks in each of the two messages. Help Zhorik to determine what is the maximum number of files could be in the archive, if the Zhorik's assumption is correct. Input The first line contains two integers n, m (1 ≀ n, m ≀ 105) β€” the number of blocks in the first and in the second messages. The second line contains n integers x1, x2, ..., xn (1 ≀ xi ≀ 106) β€” the length of the blocks that form the first message. The third line contains m integers y1, y2, ..., ym (1 ≀ yi ≀ 106) β€” the length of the blocks that form the second message. It is guaranteed that x1 + ... + xn = y1 + ... + ym. Also, it is guaranteed that x1 + ... + xn ≀ 106. Output Print the maximum number of files the intercepted array could consist of. Examples Input 7 6 2 5 3 1 11 4 4 7 8 2 4 1 8 Output 3 Input 3 3 1 10 100 1 100 10 Output 2 Input 1 4 4 1 1 1 1 Output 1 Note In the first example the maximum number of files in the archive is 3. For example, it is possible that in the archive are three files of sizes 2 + 5 = 7, 15 = 3 + 1 + 11 = 8 + 2 + 4 + 1 and 4 + 4 = 8. In the second example it is possible that the archive contains two files of sizes 1 and 110 = 10 + 100 = 100 + 10. Note that the order of files is kept while transferring archives through the network, so we can't say that there are three files of sizes 1, 10 and 100. In the third example the only possibility is that the archive contains a single file of size 4. Submitted Solution: ``` '''input 1 4 4 1 1 1 1 ''' n, m = [int(i) for i in input().split(" ")] N = [int(i) for i in input().split(" ")] M = [int(i) for i in input().split(" ")] s1 = N[0] s2 = M[0] if s1 == s2: ans = 1 else: ans = 0 i, j = 1, 1 while 1: if i == m or j == n: break if s1 > s2: s2 += M[i] i += 1 else: s1 += N[j] j += 1 if s1 == s2: ans += 1 print(ans + 1) ``` No
90,677
Provide tags and a correct Python 3 solution for this coding contest problem. The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If x is the number of passengers in a bus just before the current bus stop and y is the number of passengers in the bus just after current bus stop, the system records the number y-x. So the system records show how number of passengers changed. The test run was made for single bus and n bus stops. Thus, the system recorded the sequence of integers a_1, a_2, ..., a_n (exactly one number for each bus stop), where a_i is the record for the bus stop i. The bus stops are numbered from 1 to n in chronological order. Determine the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w (that is, at any time in the bus there should be from 0 to w passengers inclusive). Input The first line contains two integers n and w (1 ≀ n ≀ 1 000, 1 ≀ w ≀ 10^{9}) β€” the number of bus stops and the capacity of the bus. The second line contains a sequence a_1, a_2, ..., a_n (-10^{6} ≀ a_i ≀ 10^{6}), where a_i equals to the number, which has been recorded by the video system after the i-th bus stop. Output Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0. Examples Input 3 5 2 1 -3 Output 3 Input 2 4 -1 1 Output 4 Input 4 10 2 4 1 2 Output 2 Note In the first example initially in the bus could be 0, 1 or 2 passengers. In the second example initially in the bus could be 1, 2, 3 or 4 passengers. In the third example initially in the bus could be 0 or 1 passenger. Tags: combinatorics, math Correct Solution: ``` n,w = map(int, input().split()) a = list(map(int, input().split())) from itertools import accumulate b = list(accumulate(a)) c1, c2 = max(b), min(b) if c1 < 0: c1 = abs(c2) elif c2 < 0: c1, c2 = c1-c2, 0 if c1 > w: print(0) else: print(w - c1+1) ```
90,678
Provide tags and a correct Python 3 solution for this coding contest problem. The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If x is the number of passengers in a bus just before the current bus stop and y is the number of passengers in the bus just after current bus stop, the system records the number y-x. So the system records show how number of passengers changed. The test run was made for single bus and n bus stops. Thus, the system recorded the sequence of integers a_1, a_2, ..., a_n (exactly one number for each bus stop), where a_i is the record for the bus stop i. The bus stops are numbered from 1 to n in chronological order. Determine the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w (that is, at any time in the bus there should be from 0 to w passengers inclusive). Input The first line contains two integers n and w (1 ≀ n ≀ 1 000, 1 ≀ w ≀ 10^{9}) β€” the number of bus stops and the capacity of the bus. The second line contains a sequence a_1, a_2, ..., a_n (-10^{6} ≀ a_i ≀ 10^{6}), where a_i equals to the number, which has been recorded by the video system after the i-th bus stop. Output Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0. Examples Input 3 5 2 1 -3 Output 3 Input 2 4 -1 1 Output 4 Input 4 10 2 4 1 2 Output 2 Note In the first example initially in the bus could be 0, 1 or 2 passengers. In the second example initially in the bus could be 1, 2, 3 or 4 passengers. In the third example initially in the bus could be 0 or 1 passenger. Tags: combinatorics, math Correct Solution: ``` # your code goes here # your code goes here n,w = map(int,input().split()) a = list(map(int,input().split())) maxi,mini = 0,0 total = 0 for i in range(n): total += a[i] if total > maxi: maxi = total if total < mini: mini = total ans = w - max(maxi,0) + 1 - max(-mini,0) if ans < 0: print(0) else: print(ans) ```
90,679
Provide tags and a correct Python 3 solution for this coding contest problem. The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If x is the number of passengers in a bus just before the current bus stop and y is the number of passengers in the bus just after current bus stop, the system records the number y-x. So the system records show how number of passengers changed. The test run was made for single bus and n bus stops. Thus, the system recorded the sequence of integers a_1, a_2, ..., a_n (exactly one number for each bus stop), where a_i is the record for the bus stop i. The bus stops are numbered from 1 to n in chronological order. Determine the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w (that is, at any time in the bus there should be from 0 to w passengers inclusive). Input The first line contains two integers n and w (1 ≀ n ≀ 1 000, 1 ≀ w ≀ 10^{9}) β€” the number of bus stops and the capacity of the bus. The second line contains a sequence a_1, a_2, ..., a_n (-10^{6} ≀ a_i ≀ 10^{6}), where a_i equals to the number, which has been recorded by the video system after the i-th bus stop. Output Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0. Examples Input 3 5 2 1 -3 Output 3 Input 2 4 -1 1 Output 4 Input 4 10 2 4 1 2 Output 2 Note In the first example initially in the bus could be 0, 1 or 2 passengers. In the second example initially in the bus could be 1, 2, 3 or 4 passengers. In the third example initially in the bus could be 0 or 1 passenger. Tags: combinatorics, math Correct Solution: ``` a = input().split(" ") a = [int(e) for e in a] capacity = a[1] l = input().split(" ") l = [int(e) for e in l] assert a[0] == len(l) min_num = 0 max_num = 0 num = 0 for change in l: num += change if min_num == None or num < min_num: min_num = num if max_num == None or num > max_num: max_num = num print(max(capacity - max_num + min_num + 1, 0)) ```
90,680
Provide tags and a correct Python 3 solution for this coding contest problem. The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If x is the number of passengers in a bus just before the current bus stop and y is the number of passengers in the bus just after current bus stop, the system records the number y-x. So the system records show how number of passengers changed. The test run was made for single bus and n bus stops. Thus, the system recorded the sequence of integers a_1, a_2, ..., a_n (exactly one number for each bus stop), where a_i is the record for the bus stop i. The bus stops are numbered from 1 to n in chronological order. Determine the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w (that is, at any time in the bus there should be from 0 to w passengers inclusive). Input The first line contains two integers n and w (1 ≀ n ≀ 1 000, 1 ≀ w ≀ 10^{9}) β€” the number of bus stops and the capacity of the bus. The second line contains a sequence a_1, a_2, ..., a_n (-10^{6} ≀ a_i ≀ 10^{6}), where a_i equals to the number, which has been recorded by the video system after the i-th bus stop. Output Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0. Examples Input 3 5 2 1 -3 Output 3 Input 2 4 -1 1 Output 4 Input 4 10 2 4 1 2 Output 2 Note In the first example initially in the bus could be 0, 1 or 2 passengers. In the second example initially in the bus could be 1, 2, 3 or 4 passengers. In the third example initially in the bus could be 0 or 1 passenger. Tags: combinatorics, math Correct Solution: ``` z,s,a,b=input,0,0,0;n,m=map(int,z().split()) for i in map(int,z().split()):s+=i;a,b=min(a,s),max(b,s) print(max(m-b+a+1,0)) ```
90,681
Provide tags and a correct Python 3 solution for this coding contest problem. The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If x is the number of passengers in a bus just before the current bus stop and y is the number of passengers in the bus just after current bus stop, the system records the number y-x. So the system records show how number of passengers changed. The test run was made for single bus and n bus stops. Thus, the system recorded the sequence of integers a_1, a_2, ..., a_n (exactly one number for each bus stop), where a_i is the record for the bus stop i. The bus stops are numbered from 1 to n in chronological order. Determine the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w (that is, at any time in the bus there should be from 0 to w passengers inclusive). Input The first line contains two integers n and w (1 ≀ n ≀ 1 000, 1 ≀ w ≀ 10^{9}) β€” the number of bus stops and the capacity of the bus. The second line contains a sequence a_1, a_2, ..., a_n (-10^{6} ≀ a_i ≀ 10^{6}), where a_i equals to the number, which has been recorded by the video system after the i-th bus stop. Output Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0. Examples Input 3 5 2 1 -3 Output 3 Input 2 4 -1 1 Output 4 Input 4 10 2 4 1 2 Output 2 Note In the first example initially in the bus could be 0, 1 or 2 passengers. In the second example initially in the bus could be 1, 2, 3 or 4 passengers. In the third example initially in the bus could be 0 or 1 passenger. Tags: combinatorics, math Correct Solution: ``` n,w = map(int,input().split()) a = [int(s) for s in input().split()] mi,ma,s = 0,0,0 for i in a: s += i if s < mi: mi = s elif s > ma: ma = s if -mi <= w-ma: print(w-ma+mi+1) else: print(0) ```
90,682
Provide tags and a correct Python 3 solution for this coding contest problem. The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If x is the number of passengers in a bus just before the current bus stop and y is the number of passengers in the bus just after current bus stop, the system records the number y-x. So the system records show how number of passengers changed. The test run was made for single bus and n bus stops. Thus, the system recorded the sequence of integers a_1, a_2, ..., a_n (exactly one number for each bus stop), where a_i is the record for the bus stop i. The bus stops are numbered from 1 to n in chronological order. Determine the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w (that is, at any time in the bus there should be from 0 to w passengers inclusive). Input The first line contains two integers n and w (1 ≀ n ≀ 1 000, 1 ≀ w ≀ 10^{9}) β€” the number of bus stops and the capacity of the bus. The second line contains a sequence a_1, a_2, ..., a_n (-10^{6} ≀ a_i ≀ 10^{6}), where a_i equals to the number, which has been recorded by the video system after the i-th bus stop. Output Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0. Examples Input 3 5 2 1 -3 Output 3 Input 2 4 -1 1 Output 4 Input 4 10 2 4 1 2 Output 2 Note In the first example initially in the bus could be 0, 1 or 2 passengers. In the second example initially in the bus could be 1, 2, 3 or 4 passengers. In the third example initially in the bus could be 0 or 1 passenger. Tags: combinatorics, math Correct Solution: ``` """Codeforces Round #481 (Div. 3) - Bus Video System. http://codeforces.com/contest/978/problem/E The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If ``x`` is the number of passengers in a bus just before the current bus stop and ``y`` is the number of passengers in the bus just after current bus stop, the system records the number y - x. So the system records show how number of passengers changed. The test run was made for single bus and ``n`` bus stops. Thus, the system recorded the sequence of integers a[1], a[2], ..., a[n] (exactly one number for each bus stop), where a[i] is the record for the bus stop ``i``. The bus stops are numbered from 1 to n in chronological order. Determine the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to ``w`` (that is, at any time in the bus there should be from 0 to w passengers inclusive). """ def solve(capacity, sequence): diff = 0 lb, ub = float('inf'), -float('inf') for record in sequence: diff += record ub = max(ub, diff) lb = min(lb, diff) return max(0, capacity - max(0, ub) + min(0, lb) + 1) def main(): _, capacity = [int(x) for x in input().strip().split()] sequence = [int(x) for x in input().strip().split()] result = solve(capacity, sequence) print(result) if __name__ == '__main__': main() ```
90,683
Provide tags and a correct Python 3 solution for this coding contest problem. The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If x is the number of passengers in a bus just before the current bus stop and y is the number of passengers in the bus just after current bus stop, the system records the number y-x. So the system records show how number of passengers changed. The test run was made for single bus and n bus stops. Thus, the system recorded the sequence of integers a_1, a_2, ..., a_n (exactly one number for each bus stop), where a_i is the record for the bus stop i. The bus stops are numbered from 1 to n in chronological order. Determine the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w (that is, at any time in the bus there should be from 0 to w passengers inclusive). Input The first line contains two integers n and w (1 ≀ n ≀ 1 000, 1 ≀ w ≀ 10^{9}) β€” the number of bus stops and the capacity of the bus. The second line contains a sequence a_1, a_2, ..., a_n (-10^{6} ≀ a_i ≀ 10^{6}), where a_i equals to the number, which has been recorded by the video system after the i-th bus stop. Output Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0. Examples Input 3 5 2 1 -3 Output 3 Input 2 4 -1 1 Output 4 Input 4 10 2 4 1 2 Output 2 Note In the first example initially in the bus could be 0, 1 or 2 passengers. In the second example initially in the bus could be 1, 2, 3 or 4 passengers. In the third example initially in the bus could be 0 or 1 passenger. Tags: combinatorics, math Correct Solution: ``` n, w = map(int, input().split()) a = list(map(int, input().split())) minw, maxw = 0, w k = 0 for e in a: w -= e k -= e maxw = min(w, maxw) minw = max(minw, k) if minw > maxw: print(0) else: print(maxw - minw + 1) ```
90,684
Provide tags and a correct Python 3 solution for this coding contest problem. The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If x is the number of passengers in a bus just before the current bus stop and y is the number of passengers in the bus just after current bus stop, the system records the number y-x. So the system records show how number of passengers changed. The test run was made for single bus and n bus stops. Thus, the system recorded the sequence of integers a_1, a_2, ..., a_n (exactly one number for each bus stop), where a_i is the record for the bus stop i. The bus stops are numbered from 1 to n in chronological order. Determine the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w (that is, at any time in the bus there should be from 0 to w passengers inclusive). Input The first line contains two integers n and w (1 ≀ n ≀ 1 000, 1 ≀ w ≀ 10^{9}) β€” the number of bus stops and the capacity of the bus. The second line contains a sequence a_1, a_2, ..., a_n (-10^{6} ≀ a_i ≀ 10^{6}), where a_i equals to the number, which has been recorded by the video system after the i-th bus stop. Output Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0. Examples Input 3 5 2 1 -3 Output 3 Input 2 4 -1 1 Output 4 Input 4 10 2 4 1 2 Output 2 Note In the first example initially in the bus could be 0, 1 or 2 passengers. In the second example initially in the bus could be 1, 2, 3 or 4 passengers. In the third example initially in the bus could be 0 or 1 passenger. Tags: combinatorics, math Correct Solution: ``` n, w = map(int, input().split()) a = list(map(int, input().split())) L = 0 R = w c = [0] * (n + 1) for i in range(1, n + 1): c[i] = c[i - 1] + a[i - 1] L = - min(c) R = w - max(c) if R - L + 1 < 0: print(0) else: print(R - L + 1) ```
90,685
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If x is the number of passengers in a bus just before the current bus stop and y is the number of passengers in the bus just after current bus stop, the system records the number y-x. So the system records show how number of passengers changed. The test run was made for single bus and n bus stops. Thus, the system recorded the sequence of integers a_1, a_2, ..., a_n (exactly one number for each bus stop), where a_i is the record for the bus stop i. The bus stops are numbered from 1 to n in chronological order. Determine the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w (that is, at any time in the bus there should be from 0 to w passengers inclusive). Input The first line contains two integers n and w (1 ≀ n ≀ 1 000, 1 ≀ w ≀ 10^{9}) β€” the number of bus stops and the capacity of the bus. The second line contains a sequence a_1, a_2, ..., a_n (-10^{6} ≀ a_i ≀ 10^{6}), where a_i equals to the number, which has been recorded by the video system after the i-th bus stop. Output Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0. Examples Input 3 5 2 1 -3 Output 3 Input 2 4 -1 1 Output 4 Input 4 10 2 4 1 2 Output 2 Note In the first example initially in the bus could be 0, 1 or 2 passengers. In the second example initially in the bus could be 1, 2, 3 or 4 passengers. In the third example initially in the bus could be 0 or 1 passenger. Submitted Solution: ``` n, w = list(map(int, input().strip().split())) a = list(map(int, input().strip().split())) summ = 0 mmax = w mmin = 0 for i in range(n): cur = a[i] if cur >= 0: summ += cur mmax = min(mmax, w - summ) else: cmp = 0 if summ + cur < 0: cmp = abs(summ + cur) mmin = max(mmin, cmp) summ += cur if mmax < mmin: print(0) else: print(mmax - mmin + 1) ``` Yes
90,686
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If x is the number of passengers in a bus just before the current bus stop and y is the number of passengers in the bus just after current bus stop, the system records the number y-x. So the system records show how number of passengers changed. The test run was made for single bus and n bus stops. Thus, the system recorded the sequence of integers a_1, a_2, ..., a_n (exactly one number for each bus stop), where a_i is the record for the bus stop i. The bus stops are numbered from 1 to n in chronological order. Determine the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w (that is, at any time in the bus there should be from 0 to w passengers inclusive). Input The first line contains two integers n and w (1 ≀ n ≀ 1 000, 1 ≀ w ≀ 10^{9}) β€” the number of bus stops and the capacity of the bus. The second line contains a sequence a_1, a_2, ..., a_n (-10^{6} ≀ a_i ≀ 10^{6}), where a_i equals to the number, which has been recorded by the video system after the i-th bus stop. Output Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0. Examples Input 3 5 2 1 -3 Output 3 Input 2 4 -1 1 Output 4 Input 4 10 2 4 1 2 Output 2 Note In the first example initially in the bus could be 0, 1 or 2 passengers. In the second example initially in the bus could be 1, 2, 3 or 4 passengers. In the third example initially in the bus could be 0 or 1 passenger. Submitted Solution: ``` n,w = map(int,input().split()) l = list(map(int,input().split())) ss = 0 cc = 0 if l[-1]<0: c = w+l[-1] c = sum(l) for i in l: if i!=(-(w//n)) or w%n!=0: cc = 1 break if l[-1]>0: k = w kk = l[-1] else: k = w+l[-1] kk = 0 for i in l[-1::-1]: if i<0: if w-k<-i: k = w else: k = k-i if w-kk<-i: kk = w else: kk+=(-i) else: if kk<i: kk = 0 else: kk-=i k-=i if k<kk or k<0 or kk>w: ss = 1 break if k == w and kk == w: if cc == 1: ss = 1 break if ss == 0 : print(k-kk+1) else: print(0) ``` Yes
90,687
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If x is the number of passengers in a bus just before the current bus stop and y is the number of passengers in the bus just after current bus stop, the system records the number y-x. So the system records show how number of passengers changed. The test run was made for single bus and n bus stops. Thus, the system recorded the sequence of integers a_1, a_2, ..., a_n (exactly one number for each bus stop), where a_i is the record for the bus stop i. The bus stops are numbered from 1 to n in chronological order. Determine the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w (that is, at any time in the bus there should be from 0 to w passengers inclusive). Input The first line contains two integers n and w (1 ≀ n ≀ 1 000, 1 ≀ w ≀ 10^{9}) β€” the number of bus stops and the capacity of the bus. The second line contains a sequence a_1, a_2, ..., a_n (-10^{6} ≀ a_i ≀ 10^{6}), where a_i equals to the number, which has been recorded by the video system after the i-th bus stop. Output Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0. Examples Input 3 5 2 1 -3 Output 3 Input 2 4 -1 1 Output 4 Input 4 10 2 4 1 2 Output 2 Note In the first example initially in the bus could be 0, 1 or 2 passengers. In the second example initially in the bus could be 1, 2, 3 or 4 passengers. In the third example initially in the bus could be 0 or 1 passenger. Submitted Solution: ``` n,w=input().split() n,w=int(n),int(w) A=list(map(int,input().split())) S=[0]*len(A) s=0 for i in range(len(A)): s+=A[i] S[i]=s if w>=abs(max(S)) and w>=abs(min(S)): if max(S)<=0: up=w else: up=w-max(S) if min(S)>=0: down=0 else: down=abs(min(S)) if up-down<0 or abs(min(S)-max(S))>w : print('0') else: print(up-down+1) else: print('0') ``` Yes
90,688
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If x is the number of passengers in a bus just before the current bus stop and y is the number of passengers in the bus just after current bus stop, the system records the number y-x. So the system records show how number of passengers changed. The test run was made for single bus and n bus stops. Thus, the system recorded the sequence of integers a_1, a_2, ..., a_n (exactly one number for each bus stop), where a_i is the record for the bus stop i. The bus stops are numbered from 1 to n in chronological order. Determine the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w (that is, at any time in the bus there should be from 0 to w passengers inclusive). Input The first line contains two integers n and w (1 ≀ n ≀ 1 000, 1 ≀ w ≀ 10^{9}) β€” the number of bus stops and the capacity of the bus. The second line contains a sequence a_1, a_2, ..., a_n (-10^{6} ≀ a_i ≀ 10^{6}), where a_i equals to the number, which has been recorded by the video system after the i-th bus stop. Output Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0. Examples Input 3 5 2 1 -3 Output 3 Input 2 4 -1 1 Output 4 Input 4 10 2 4 1 2 Output 2 Note In the first example initially in the bus could be 0, 1 or 2 passengers. In the second example initially in the bus could be 1, 2, 3 or 4 passengers. In the third example initially in the bus could be 0 or 1 passenger. Submitted Solution: ``` n, w = map(int, input().split()) a = list(map(int, input().split())) mn = 0 mx = 0 now = 0 for i in a: now += i mx = max(mx, now) mn = min(mn, now) print(max(w-(mx-mn)+1, 0)) ``` Yes
90,689
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If x is the number of passengers in a bus just before the current bus stop and y is the number of passengers in the bus just after current bus stop, the system records the number y-x. So the system records show how number of passengers changed. The test run was made for single bus and n bus stops. Thus, the system recorded the sequence of integers a_1, a_2, ..., a_n (exactly one number for each bus stop), where a_i is the record for the bus stop i. The bus stops are numbered from 1 to n in chronological order. Determine the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w (that is, at any time in the bus there should be from 0 to w passengers inclusive). Input The first line contains two integers n and w (1 ≀ n ≀ 1 000, 1 ≀ w ≀ 10^{9}) β€” the number of bus stops and the capacity of the bus. The second line contains a sequence a_1, a_2, ..., a_n (-10^{6} ≀ a_i ≀ 10^{6}), where a_i equals to the number, which has been recorded by the video system after the i-th bus stop. Output Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0. Examples Input 3 5 2 1 -3 Output 3 Input 2 4 -1 1 Output 4 Input 4 10 2 4 1 2 Output 2 Note In the first example initially in the bus could be 0, 1 or 2 passengers. In the second example initially in the bus could be 1, 2, 3 or 4 passengers. In the third example initially in the bus could be 0 or 1 passenger. Submitted Solution: ``` n,w=map(int,input().split()) l=map(int,input().split()) S,s=0,0 for x in l: S+=x if abs(S)>s:s=abs(S) print(w-s+1) ``` No
90,690
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If x is the number of passengers in a bus just before the current bus stop and y is the number of passengers in the bus just after current bus stop, the system records the number y-x. So the system records show how number of passengers changed. The test run was made for single bus and n bus stops. Thus, the system recorded the sequence of integers a_1, a_2, ..., a_n (exactly one number for each bus stop), where a_i is the record for the bus stop i. The bus stops are numbered from 1 to n in chronological order. Determine the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w (that is, at any time in the bus there should be from 0 to w passengers inclusive). Input The first line contains two integers n and w (1 ≀ n ≀ 1 000, 1 ≀ w ≀ 10^{9}) β€” the number of bus stops and the capacity of the bus. The second line contains a sequence a_1, a_2, ..., a_n (-10^{6} ≀ a_i ≀ 10^{6}), where a_i equals to the number, which has been recorded by the video system after the i-th bus stop. Output Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0. Examples Input 3 5 2 1 -3 Output 3 Input 2 4 -1 1 Output 4 Input 4 10 2 4 1 2 Output 2 Note In the first example initially in the bus could be 0, 1 or 2 passengers. In the second example initially in the bus could be 1, 2, 3 or 4 passengers. In the third example initially in the bus could be 0 or 1 passenger. Submitted Solution: ``` n,w=[int(x) for x in input().split()] l=list(map(int, input().split())) for i in range(n-1): l[i+1]+=l[i] mn=min(l) mx=max(l) x=w+1 if mx>=0: x-=mx if mn<=0: x+=mn print(x) ``` No
90,691
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If x is the number of passengers in a bus just before the current bus stop and y is the number of passengers in the bus just after current bus stop, the system records the number y-x. So the system records show how number of passengers changed. The test run was made for single bus and n bus stops. Thus, the system recorded the sequence of integers a_1, a_2, ..., a_n (exactly one number for each bus stop), where a_i is the record for the bus stop i. The bus stops are numbered from 1 to n in chronological order. Determine the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w (that is, at any time in the bus there should be from 0 to w passengers inclusive). Input The first line contains two integers n and w (1 ≀ n ≀ 1 000, 1 ≀ w ≀ 10^{9}) β€” the number of bus stops and the capacity of the bus. The second line contains a sequence a_1, a_2, ..., a_n (-10^{6} ≀ a_i ≀ 10^{6}), where a_i equals to the number, which has been recorded by the video system after the i-th bus stop. Output Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0. Examples Input 3 5 2 1 -3 Output 3 Input 2 4 -1 1 Output 4 Input 4 10 2 4 1 2 Output 2 Note In the first example initially in the bus could be 0, 1 or 2 passengers. In the second example initially in the bus could be 1, 2, 3 or 4 passengers. In the third example initially in the bus could be 0 or 1 passenger. Submitted Solution: ``` import itertools n, w = map(int,input().split()) A = list(map(int,input().split())) if min(A) >= 0: print(w-sum(A)+1) exit() if max(A) <= 0: print(w+sum(A)+1) exit() csA = list(itertools.accumulate(A)) #print(csA) if max(csA) > w: print(0) exit() if min(csA) < -w: print(0) exit() low = abs(min(csA)) if max(csA) > 0: ans = (w-max(csA)-low+1) print(ans if ans > 0 else 0) else: ans = w+min(csA)+1 print(ans if ans > 0 else 0) ``` No
90,692
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If x is the number of passengers in a bus just before the current bus stop and y is the number of passengers in the bus just after current bus stop, the system records the number y-x. So the system records show how number of passengers changed. The test run was made for single bus and n bus stops. Thus, the system recorded the sequence of integers a_1, a_2, ..., a_n (exactly one number for each bus stop), where a_i is the record for the bus stop i. The bus stops are numbered from 1 to n in chronological order. Determine the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w (that is, at any time in the bus there should be from 0 to w passengers inclusive). Input The first line contains two integers n and w (1 ≀ n ≀ 1 000, 1 ≀ w ≀ 10^{9}) β€” the number of bus stops and the capacity of the bus. The second line contains a sequence a_1, a_2, ..., a_n (-10^{6} ≀ a_i ≀ 10^{6}), where a_i equals to the number, which has been recorded by the video system after the i-th bus stop. Output Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to w. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0. Examples Input 3 5 2 1 -3 Output 3 Input 2 4 -1 1 Output 4 Input 4 10 2 4 1 2 Output 2 Note In the first example initially in the bus could be 0, 1 or 2 passengers. In the second example initially in the bus could be 1, 2, 3 or 4 passengers. In the third example initially in the bus could be 0 or 1 passenger. Submitted Solution: ``` n,w=map(int,input().split()) a=[int(i) for i in input().split()] x1=0 x2=w for i in a: x1=max(x1+i,0) x2=max(min(x2+i,w),0) k=max(0,x2-x1+1) print(k if k<=w and k>0 else 0) ``` No
90,693
Provide tags and a correct Python 3 solution for this coding contest problem. Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers 1, 5, 10 and 50 respectively. The use of other roman digits is not allowed. Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it. For example, the number XXXV evaluates to 35 and the number IXI β€” to 12. Pay attention to the difference to the traditional roman system β€” in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means 11, not 9. One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly n roman digits I, V, X, L. Input The only line of the input file contains a single integer n (1 ≀ n ≀ 10^9) β€” the number of roman digits to use. Output Output a single integer β€” the number of distinct integers which can be represented using n roman digits exactly. Examples Input 1 Output 4 Input 2 Output 10 Input 10 Output 244 Note In the first sample there are exactly 4 integers which can be represented β€” I, V, X and L. In the second sample it is possible to represent integers 2 (II), 6 (VI), 10 (VV), 11 (XI), 15 (XV), 20 (XX), 51 (IL), 55 (VL), 60 (XL) and 100 (LL). Tags: brute force, combinatorics, dp, greedy, math Correct Solution: ``` from sys import setrecursionlimit setrecursionlimit((10**9)) n = int(input()) s = set() arr = [1,5,10,50] def comb(num, digit): global n if digit == n: s.add(num) else: for i in range(4): comb(num+arr[i], digit+1) if n <= 12: comb(0, 0) print(len(s)) else: print(49*n-247) ```
90,694
Provide tags and a correct Python 3 solution for this coding contest problem. Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers 1, 5, 10 and 50 respectively. The use of other roman digits is not allowed. Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it. For example, the number XXXV evaluates to 35 and the number IXI β€” to 12. Pay attention to the difference to the traditional roman system β€” in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means 11, not 9. One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly n roman digits I, V, X, L. Input The only line of the input file contains a single integer n (1 ≀ n ≀ 10^9) β€” the number of roman digits to use. Output Output a single integer β€” the number of distinct integers which can be represented using n roman digits exactly. Examples Input 1 Output 4 Input 2 Output 10 Input 10 Output 244 Note In the first sample there are exactly 4 integers which can be represented β€” I, V, X and L. In the second sample it is possible to represent integers 2 (II), 6 (VI), 10 (VV), 11 (XI), 15 (XV), 20 (XX), 51 (IL), 55 (VL), 60 (XL) and 100 (LL). Tags: brute force, combinatorics, dp, greedy, math Correct Solution: ``` #!/usr/bin/env python # -*- coding: utf-8 -*- n = int(input()) if n < 12: print([1, 4, 10, 20, 35, 56, 83, 116, 155, 198, 244, 292][n]) else: print(n*50-n-247) ```
90,695
Provide tags and a correct Python 3 solution for this coding contest problem. Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers 1, 5, 10 and 50 respectively. The use of other roman digits is not allowed. Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it. For example, the number XXXV evaluates to 35 and the number IXI β€” to 12. Pay attention to the difference to the traditional roman system β€” in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means 11, not 9. One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly n roman digits I, V, X, L. Input The only line of the input file contains a single integer n (1 ≀ n ≀ 10^9) β€” the number of roman digits to use. Output Output a single integer β€” the number of distinct integers which can be represented using n roman digits exactly. Examples Input 1 Output 4 Input 2 Output 10 Input 10 Output 244 Note In the first sample there are exactly 4 integers which can be represented β€” I, V, X and L. In the second sample it is possible to represent integers 2 (II), 6 (VI), 10 (VV), 11 (XI), 15 (XV), 20 (XX), 51 (IL), 55 (VL), 60 (XL) and 100 (LL). Tags: brute force, combinatorics, dp, greedy, math Correct Solution: ``` def check(n, b, c): for tb in range(0, 9): for tc in range(0, min(n - tb + 1, 9)): s1 = 9 * b + 4 * c s2 = 9 * tb + 4 * tc if s1 > s2 and (s1 - s2) % 49 == 0: return False return True def main(): n = int(input()) ans = 0 for b in range(0, min(n + 1, 9)): for c in range(0, min(n - b + 1, 9)): if check(n, b, c): ans += (n - b - c + 1) print(ans) if __name__ == "__main__": exit(main()) ```
90,696
Provide tags and a correct Python 3 solution for this coding contest problem. Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers 1, 5, 10 and 50 respectively. The use of other roman digits is not allowed. Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it. For example, the number XXXV evaluates to 35 and the number IXI β€” to 12. Pay attention to the difference to the traditional roman system β€” in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means 11, not 9. One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly n roman digits I, V, X, L. Input The only line of the input file contains a single integer n (1 ≀ n ≀ 10^9) β€” the number of roman digits to use. Output Output a single integer β€” the number of distinct integers which can be represented using n roman digits exactly. Examples Input 1 Output 4 Input 2 Output 10 Input 10 Output 244 Note In the first sample there are exactly 4 integers which can be represented β€” I, V, X and L. In the second sample it is possible to represent integers 2 (II), 6 (VI), 10 (VV), 11 (XI), 15 (XV), 20 (XX), 51 (IL), 55 (VL), 60 (XL) and 100 (LL). Tags: brute force, combinatorics, dp, greedy, math Correct Solution: ``` a = [0, 4, 10, 20, 35, 56, 83, 116, 155, 198, 244, 292] n = int(input()) if n < len(a): print (a[n]) else: print (a[11] + 49*(n-11)) ```
90,697
Provide tags and a correct Python 3 solution for this coding contest problem. Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers 1, 5, 10 and 50 respectively. The use of other roman digits is not allowed. Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it. For example, the number XXXV evaluates to 35 and the number IXI β€” to 12. Pay attention to the difference to the traditional roman system β€” in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means 11, not 9. One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly n roman digits I, V, X, L. Input The only line of the input file contains a single integer n (1 ≀ n ≀ 10^9) β€” the number of roman digits to use. Output Output a single integer β€” the number of distinct integers which can be represented using n roman digits exactly. Examples Input 1 Output 4 Input 2 Output 10 Input 10 Output 244 Note In the first sample there are exactly 4 integers which can be represented β€” I, V, X and L. In the second sample it is possible to represent integers 2 (II), 6 (VI), 10 (VV), 11 (XI), 15 (XV), 20 (XX), 51 (IL), 55 (VL), 60 (XL) and 100 (LL). Tags: brute force, combinatorics, dp, greedy, math Correct Solution: ``` def ceildiv(a, b): return -(-a // b) def test_ceildiv(): assert ceildiv(6, 3) == 2 assert ceildiv(7, 3) == 3 assert ceildiv(5, 3) == 2 def brute_force(n, m): """Count numbers in range [0; m] equal to 4a + 9b + 49c ...for some non-negative a, b and c such that (a + b + c) <= n """ numbers = set() max_c = min(n, m // 49) for c in range(max_c + 1): _49c = 49 * c max_b = min(n - c, (m - _49c) // 9, 48) for b in range(max_b + 1): _9b_49c = 9 * b + _49c max_a = min(n - b - c, (m - _9b_49c) // 4, 8) for a in range(max_a + 1): numbers.add(4 * a + _9b_49c) assert 0 in numbers for x in (4, 9, 49): if m // x <= n: assert m - (m % 49) in numbers return len(numbers) def brute_force_range(n, l, u): """Count numbers in range [l; u] equal to 4a + 9b + 49c ...for some non-negative a, b and c such that (a + b + c) <= n """ numbers = set() min_c = max(0, ceildiv(l - 9 * n, 40)) max_c = min(n, u // 49) for c in range(min_c, max_c + 1): _49c = 49 * c min_b = max(0, ceildiv(l - 4 * n - 45 * c, 5)) max_b = min(n - c, (u - _49c) // 9, 48) for b in range(min_b, max_b + 1): _9b_49c = 9 * b + _49c min_a = max(0, ceildiv(l - _9b_49c, 4)) max_a = min(n - b - c, (u - _9b_49c) // 4, 8) for a in range(min_a, max_a + 1): numbers.add(4 * a + _9b_49c) if numbers: assert min(numbers) >= l assert max(numbers) <= u return len(numbers) def test_brute_force_range(): for (u, l) in ((60, 80), (104, 599), (200, 777)): for n in (10, 13, 15, 17, 20): assert brute_force_range(n, u, l) == brute_force(n, l) - brute_force(n, u - 1) def solid_interval(n): assert n >= 18 return 27, (49 * n - 807) + 1 def test_solid_interval(): for n in 18, 19, 100, 200, 300, 1000, 5000: begin, end = solid_interval(n) assert brute_force_range(n, begin, end - 1) == end - begin def main(): n = int(input()) if n < 18: result = brute_force(n, 49 * n) # naΓ―ve solution else: begin, end = solid_interval(n) assert begin < end < 49 * n result = sum(( brute_force_range(n, 0, begin - 1), end - begin, # == brute_force_range(n, begin, end - 1) brute_force_range(n, end, 49 * n) )) print(result) if __name__ == '__main__': main() ```
90,698
Provide tags and a correct Python 3 solution for this coding contest problem. Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers 1, 5, 10 and 50 respectively. The use of other roman digits is not allowed. Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it. For example, the number XXXV evaluates to 35 and the number IXI β€” to 12. Pay attention to the difference to the traditional roman system β€” in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means 11, not 9. One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly n roman digits I, V, X, L. Input The only line of the input file contains a single integer n (1 ≀ n ≀ 10^9) β€” the number of roman digits to use. Output Output a single integer β€” the number of distinct integers which can be represented using n roman digits exactly. Examples Input 1 Output 4 Input 2 Output 10 Input 10 Output 244 Note In the first sample there are exactly 4 integers which can be represented β€” I, V, X and L. In the second sample it is possible to represent integers 2 (II), 6 (VI), 10 (VV), 11 (XI), 15 (XV), 20 (XX), 51 (IL), 55 (VL), 60 (XL) and 100 (LL). Tags: brute force, combinatorics, dp, greedy, math Correct Solution: ``` ans=0 def solve(nn,su,ans): if nn==n: s.add(su) ans+=1 return solve(nn+1,su+1,ans) solve(nn+1,su+5,ans) solve(nn+1,su+10,ans) solve(nn+1,su+50,ans) s = set() n = int(input()) if n<=13: solve(0,0,ans) print(len(s)) else: print(292 + 49*(n-11)) ```
90,699