message
stringlengths
2
20.2k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
757
108k
cluster
float64
4
4
__index_level_0__
int64
1.51k
217k
Provide tags and a correct Python 3 solution for this coding contest problem. Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him n subjects, the ith subject has ci chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously. Let us say that his initial per chapter learning power of a subject is x hours. In other words he can learn a chapter of a particular subject in x hours. Well Devu is not complete dumb, there is a good thing about him too. If you teach him a subject, then time required to teach any chapter of the next subject will require exactly 1 hour less than previously required (see the examples to understand it more clearly). Note that his per chapter learning power can not be less than 1 hour. You can teach him the n subjects in any possible order. Find out minimum amount of time (in hours) Devu will take to understand all the subjects and you will be free to do some enjoying task rather than teaching a dumb guy. Please be careful that answer might not fit in 32 bit data type. Input The first line will contain two space separated integers n, x (1 ≤ n, x ≤ 105). The next line will contain n space separated integers: c1, c2, ..., cn (1 ≤ ci ≤ 105). Output Output a single integer representing the answer to the problem. Examples Input 2 3 4 1 Output 11 Input 4 2 5 1 2 1 Output 10 Input 3 3 1 1 1 Output 6 Note Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 hours. Hence you will need to spend 12 + 2 = 14 hours. Consider the order of subjects: 2, 1. When you teach Devu the second subject, then it will take him 3 hours per chapter, so it will take 3 × 1 = 3 hours to teach the second subject. After teaching the second subject, his per chapter learning time will be 2 hours. Now teaching him the first subject will take 2 × 4 = 8 hours. Hence you will need to spend 11 hours. So overall, minimum of both the cases is 11 hours. Look at the third example. The order in this example doesn't matter. When you teach Devu the first subject, it will take him 3 hours per chapter. When you teach Devu the second subject, it will take him 2 hours per chapter. When you teach Devu the third subject, it will take him 1 hours per chapter. In total it takes 6 hours.
instruction
0
93,873
4
187,746
Tags: implementation, sortings Correct Solution: ``` n, x = map(int,input().split()) c = list(map(int,input().split())) c.sort() h = 0 for i in range(n): h += x*c[i] if x <= 1: x = 1 else: x -= 1 print(h) ```
output
1
93,873
4
187,747
Provide tags and a correct Python 3 solution for this coding contest problem. Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him n subjects, the ith subject has ci chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously. Let us say that his initial per chapter learning power of a subject is x hours. In other words he can learn a chapter of a particular subject in x hours. Well Devu is not complete dumb, there is a good thing about him too. If you teach him a subject, then time required to teach any chapter of the next subject will require exactly 1 hour less than previously required (see the examples to understand it more clearly). Note that his per chapter learning power can not be less than 1 hour. You can teach him the n subjects in any possible order. Find out minimum amount of time (in hours) Devu will take to understand all the subjects and you will be free to do some enjoying task rather than teaching a dumb guy. Please be careful that answer might not fit in 32 bit data type. Input The first line will contain two space separated integers n, x (1 ≤ n, x ≤ 105). The next line will contain n space separated integers: c1, c2, ..., cn (1 ≤ ci ≤ 105). Output Output a single integer representing the answer to the problem. Examples Input 2 3 4 1 Output 11 Input 4 2 5 1 2 1 Output 10 Input 3 3 1 1 1 Output 6 Note Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 hours. Hence you will need to spend 12 + 2 = 14 hours. Consider the order of subjects: 2, 1. When you teach Devu the second subject, then it will take him 3 hours per chapter, so it will take 3 × 1 = 3 hours to teach the second subject. After teaching the second subject, his per chapter learning time will be 2 hours. Now teaching him the first subject will take 2 × 4 = 8 hours. Hence you will need to spend 11 hours. So overall, minimum of both the cases is 11 hours. Look at the third example. The order in this example doesn't matter. When you teach Devu the first subject, it will take him 3 hours per chapter. When you teach Devu the second subject, it will take him 2 hours per chapter. When you teach Devu the third subject, it will take him 1 hours per chapter. In total it takes 6 hours.
instruction
0
93,874
4
187,748
Tags: implementation, sortings Correct Solution: ``` (n, x) = map(int, list(input().split())) c = list(map(int, list(input().split()))) c = sorted(c) s = 0 for i in range(n): s += c[i] * x if x != 1: x -= 1 print(s) ```
output
1
93,874
4
187,749
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him n subjects, the ith subject has ci chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously. Let us say that his initial per chapter learning power of a subject is x hours. In other words he can learn a chapter of a particular subject in x hours. Well Devu is not complete dumb, there is a good thing about him too. If you teach him a subject, then time required to teach any chapter of the next subject will require exactly 1 hour less than previously required (see the examples to understand it more clearly). Note that his per chapter learning power can not be less than 1 hour. You can teach him the n subjects in any possible order. Find out minimum amount of time (in hours) Devu will take to understand all the subjects and you will be free to do some enjoying task rather than teaching a dumb guy. Please be careful that answer might not fit in 32 bit data type. Input The first line will contain two space separated integers n, x (1 ≤ n, x ≤ 105). The next line will contain n space separated integers: c1, c2, ..., cn (1 ≤ ci ≤ 105). Output Output a single integer representing the answer to the problem. Examples Input 2 3 4 1 Output 11 Input 4 2 5 1 2 1 Output 10 Input 3 3 1 1 1 Output 6 Note Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 hours. Hence you will need to spend 12 + 2 = 14 hours. Consider the order of subjects: 2, 1. When you teach Devu the second subject, then it will take him 3 hours per chapter, so it will take 3 × 1 = 3 hours to teach the second subject. After teaching the second subject, his per chapter learning time will be 2 hours. Now teaching him the first subject will take 2 × 4 = 8 hours. Hence you will need to spend 11 hours. So overall, minimum of both the cases is 11 hours. Look at the third example. The order in this example doesn't matter. When you teach Devu the first subject, it will take him 3 hours per chapter. When you teach Devu the second subject, it will take him 2 hours per chapter. When you teach Devu the third subject, it will take him 1 hours per chapter. In total it takes 6 hours. Submitted Solution: ``` #------------------------------what is this I don't know....just makes my mess faster-------------------------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") #----------------------------------Real game starts here-------------------------------------- ''' ___________________THIS IS AESTROIX CODE________________________ KARMANYA GUPTA ''' import math def fact(x): if x == 0: return 1 else: return x * fact(x-1) def abs(x): return (x if x>=0 else -x) def sumelem(x, start, end): #print("the sequenced passed is: ", x[start:end+1]) sum = 0 for i in range(start,end+1): sum += x[i] return sum cnt = set() for t in range(1): n, x = list(map(int, input().split())) sub = list(map(int, input().split())) sub.sort() x += 1 sumi = 0 for i in sub: if x>1: x-=1 sumi += x*i print(sumi) ```
instruction
0
93,875
4
187,750
Yes
output
1
93,875
4
187,751
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him n subjects, the ith subject has ci chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously. Let us say that his initial per chapter learning power of a subject is x hours. In other words he can learn a chapter of a particular subject in x hours. Well Devu is not complete dumb, there is a good thing about him too. If you teach him a subject, then time required to teach any chapter of the next subject will require exactly 1 hour less than previously required (see the examples to understand it more clearly). Note that his per chapter learning power can not be less than 1 hour. You can teach him the n subjects in any possible order. Find out minimum amount of time (in hours) Devu will take to understand all the subjects and you will be free to do some enjoying task rather than teaching a dumb guy. Please be careful that answer might not fit in 32 bit data type. Input The first line will contain two space separated integers n, x (1 ≤ n, x ≤ 105). The next line will contain n space separated integers: c1, c2, ..., cn (1 ≤ ci ≤ 105). Output Output a single integer representing the answer to the problem. Examples Input 2 3 4 1 Output 11 Input 4 2 5 1 2 1 Output 10 Input 3 3 1 1 1 Output 6 Note Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 hours. Hence you will need to spend 12 + 2 = 14 hours. Consider the order of subjects: 2, 1. When you teach Devu the second subject, then it will take him 3 hours per chapter, so it will take 3 × 1 = 3 hours to teach the second subject. After teaching the second subject, his per chapter learning time will be 2 hours. Now teaching him the first subject will take 2 × 4 = 8 hours. Hence you will need to spend 11 hours. So overall, minimum of both the cases is 11 hours. Look at the third example. The order in this example doesn't matter. When you teach Devu the first subject, it will take him 3 hours per chapter. When you teach Devu the second subject, it will take him 2 hours per chapter. When you teach Devu the third subject, it will take him 1 hours per chapter. In total it takes 6 hours. Submitted Solution: ``` n, x = map(int, input().split()) c = list(map(int, input().split())) c1 = sorted(c) sum = 0 for i in range(n): sum += x * c1[i] if (x > 1): x -= 1 print(sum) ```
instruction
0
93,876
4
187,752
Yes
output
1
93,876
4
187,753
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him n subjects, the ith subject has ci chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously. Let us say that his initial per chapter learning power of a subject is x hours. In other words he can learn a chapter of a particular subject in x hours. Well Devu is not complete dumb, there is a good thing about him too. If you teach him a subject, then time required to teach any chapter of the next subject will require exactly 1 hour less than previously required (see the examples to understand it more clearly). Note that his per chapter learning power can not be less than 1 hour. You can teach him the n subjects in any possible order. Find out minimum amount of time (in hours) Devu will take to understand all the subjects and you will be free to do some enjoying task rather than teaching a dumb guy. Please be careful that answer might not fit in 32 bit data type. Input The first line will contain two space separated integers n, x (1 ≤ n, x ≤ 105). The next line will contain n space separated integers: c1, c2, ..., cn (1 ≤ ci ≤ 105). Output Output a single integer representing the answer to the problem. Examples Input 2 3 4 1 Output 11 Input 4 2 5 1 2 1 Output 10 Input 3 3 1 1 1 Output 6 Note Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 hours. Hence you will need to spend 12 + 2 = 14 hours. Consider the order of subjects: 2, 1. When you teach Devu the second subject, then it will take him 3 hours per chapter, so it will take 3 × 1 = 3 hours to teach the second subject. After teaching the second subject, his per chapter learning time will be 2 hours. Now teaching him the first subject will take 2 × 4 = 8 hours. Hence you will need to spend 11 hours. So overall, minimum of both the cases is 11 hours. Look at the third example. The order in this example doesn't matter. When you teach Devu the first subject, it will take him 3 hours per chapter. When you teach Devu the second subject, it will take him 2 hours per chapter. When you teach Devu the third subject, it will take him 1 hours per chapter. In total it takes 6 hours. Submitted Solution: ``` n, x = map(int, input().split()) c = list(map(int, input().split())) s = sorted(c) t = 0 for i in range(n): t += s[i] * x if x != 1: x -= 1 print(t) ```
instruction
0
93,877
4
187,754
Yes
output
1
93,877
4
187,755
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him n subjects, the ith subject has ci chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously. Let us say that his initial per chapter learning power of a subject is x hours. In other words he can learn a chapter of a particular subject in x hours. Well Devu is not complete dumb, there is a good thing about him too. If you teach him a subject, then time required to teach any chapter of the next subject will require exactly 1 hour less than previously required (see the examples to understand it more clearly). Note that his per chapter learning power can not be less than 1 hour. You can teach him the n subjects in any possible order. Find out minimum amount of time (in hours) Devu will take to understand all the subjects and you will be free to do some enjoying task rather than teaching a dumb guy. Please be careful that answer might not fit in 32 bit data type. Input The first line will contain two space separated integers n, x (1 ≤ n, x ≤ 105). The next line will contain n space separated integers: c1, c2, ..., cn (1 ≤ ci ≤ 105). Output Output a single integer representing the answer to the problem. Examples Input 2 3 4 1 Output 11 Input 4 2 5 1 2 1 Output 10 Input 3 3 1 1 1 Output 6 Note Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 hours. Hence you will need to spend 12 + 2 = 14 hours. Consider the order of subjects: 2, 1. When you teach Devu the second subject, then it will take him 3 hours per chapter, so it will take 3 × 1 = 3 hours to teach the second subject. After teaching the second subject, his per chapter learning time will be 2 hours. Now teaching him the first subject will take 2 × 4 = 8 hours. Hence you will need to spend 11 hours. So overall, minimum of both the cases is 11 hours. Look at the third example. The order in this example doesn't matter. When you teach Devu the first subject, it will take him 3 hours per chapter. When you teach Devu the second subject, it will take him 2 hours per chapter. When you teach Devu the third subject, it will take him 1 hours per chapter. In total it takes 6 hours. Submitted Solution: ``` from sys import stdin, stdout ZA = [int(a) for a in stdin.read().split()] a = ZA[0] b = ZA[1] ZA = ZA[2:] ZA.sort() c = 0 d = 0 while c < a: d += ZA[c] * b if b > 1: b -= 1 c += 1 print('%d' % d) ```
instruction
0
93,878
4
187,756
Yes
output
1
93,878
4
187,757
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him n subjects, the ith subject has ci chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously. Let us say that his initial per chapter learning power of a subject is x hours. In other words he can learn a chapter of a particular subject in x hours. Well Devu is not complete dumb, there is a good thing about him too. If you teach him a subject, then time required to teach any chapter of the next subject will require exactly 1 hour less than previously required (see the examples to understand it more clearly). Note that his per chapter learning power can not be less than 1 hour. You can teach him the n subjects in any possible order. Find out minimum amount of time (in hours) Devu will take to understand all the subjects and you will be free to do some enjoying task rather than teaching a dumb guy. Please be careful that answer might not fit in 32 bit data type. Input The first line will contain two space separated integers n, x (1 ≤ n, x ≤ 105). The next line will contain n space separated integers: c1, c2, ..., cn (1 ≤ ci ≤ 105). Output Output a single integer representing the answer to the problem. Examples Input 2 3 4 1 Output 11 Input 4 2 5 1 2 1 Output 10 Input 3 3 1 1 1 Output 6 Note Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 hours. Hence you will need to spend 12 + 2 = 14 hours. Consider the order of subjects: 2, 1. When you teach Devu the second subject, then it will take him 3 hours per chapter, so it will take 3 × 1 = 3 hours to teach the second subject. After teaching the second subject, his per chapter learning time will be 2 hours. Now teaching him the first subject will take 2 × 4 = 8 hours. Hence you will need to spend 11 hours. So overall, minimum of both the cases is 11 hours. Look at the third example. The order in this example doesn't matter. When you teach Devu the first subject, it will take him 3 hours per chapter. When you teach Devu the second subject, it will take him 2 hours per chapter. When you teach Devu the third subject, it will take him 1 hours per chapter. In total it takes 6 hours. Submitted Solution: ``` n, t = map(int, input().split()) a = sorted(map(int, input().split())) count = 0 for i in range(0, n): if t > 1: count += t*a[i] t -= 1 else: count += a[i] print(count%1000001) ```
instruction
0
93,879
4
187,758
No
output
1
93,879
4
187,759
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him n subjects, the ith subject has ci chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously. Let us say that his initial per chapter learning power of a subject is x hours. In other words he can learn a chapter of a particular subject in x hours. Well Devu is not complete dumb, there is a good thing about him too. If you teach him a subject, then time required to teach any chapter of the next subject will require exactly 1 hour less than previously required (see the examples to understand it more clearly). Note that his per chapter learning power can not be less than 1 hour. You can teach him the n subjects in any possible order. Find out minimum amount of time (in hours) Devu will take to understand all the subjects and you will be free to do some enjoying task rather than teaching a dumb guy. Please be careful that answer might not fit in 32 bit data type. Input The first line will contain two space separated integers n, x (1 ≤ n, x ≤ 105). The next line will contain n space separated integers: c1, c2, ..., cn (1 ≤ ci ≤ 105). Output Output a single integer representing the answer to the problem. Examples Input 2 3 4 1 Output 11 Input 4 2 5 1 2 1 Output 10 Input 3 3 1 1 1 Output 6 Note Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 hours. Hence you will need to spend 12 + 2 = 14 hours. Consider the order of subjects: 2, 1. When you teach Devu the second subject, then it will take him 3 hours per chapter, so it will take 3 × 1 = 3 hours to teach the second subject. After teaching the second subject, his per chapter learning time will be 2 hours. Now teaching him the first subject will take 2 × 4 = 8 hours. Hence you will need to spend 11 hours. So overall, minimum of both the cases is 11 hours. Look at the third example. The order in this example doesn't matter. When you teach Devu the first subject, it will take him 3 hours per chapter. When you teach Devu the second subject, it will take him 2 hours per chapter. When you teach Devu the third subject, it will take him 1 hours per chapter. In total it takes 6 hours. Submitted Solution: ``` int_inp = lambda: int(input()) #integer input strng = lambda: input().strip() #string input strl = lambda: list(input().strip())#list of strings as input mul = lambda: map(int,input().strip().split())#multiple integers as inpnut mulf = lambda: map(float,input().strip().split())#multiple floats as ipnut seq = lambda: list(map(int,input().strip().split()))#list of integers import math from collections import Counter,defaultdict a,b = mul() m = seq() ans=0 m.sort() for i in range(0,a): ans = ans + m[i]*b b-=1 if b==1: ans = ans + sum(m[i+1:]) break print(ans) ```
instruction
0
93,880
4
187,760
No
output
1
93,880
4
187,761
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him n subjects, the ith subject has ci chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously. Let us say that his initial per chapter learning power of a subject is x hours. In other words he can learn a chapter of a particular subject in x hours. Well Devu is not complete dumb, there is a good thing about him too. If you teach him a subject, then time required to teach any chapter of the next subject will require exactly 1 hour less than previously required (see the examples to understand it more clearly). Note that his per chapter learning power can not be less than 1 hour. You can teach him the n subjects in any possible order. Find out minimum amount of time (in hours) Devu will take to understand all the subjects and you will be free to do some enjoying task rather than teaching a dumb guy. Please be careful that answer might not fit in 32 bit data type. Input The first line will contain two space separated integers n, x (1 ≤ n, x ≤ 105). The next line will contain n space separated integers: c1, c2, ..., cn (1 ≤ ci ≤ 105). Output Output a single integer representing the answer to the problem. Examples Input 2 3 4 1 Output 11 Input 4 2 5 1 2 1 Output 10 Input 3 3 1 1 1 Output 6 Note Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 hours. Hence you will need to spend 12 + 2 = 14 hours. Consider the order of subjects: 2, 1. When you teach Devu the second subject, then it will take him 3 hours per chapter, so it will take 3 × 1 = 3 hours to teach the second subject. After teaching the second subject, his per chapter learning time will be 2 hours. Now teaching him the first subject will take 2 × 4 = 8 hours. Hence you will need to spend 11 hours. So overall, minimum of both the cases is 11 hours. Look at the third example. The order in this example doesn't matter. When you teach Devu the first subject, it will take him 3 hours per chapter. When you teach Devu the second subject, it will take him 2 hours per chapter. When you teach Devu the third subject, it will take him 1 hours per chapter. In total it takes 6 hours. Submitted Solution: ``` n=input().split() n[0]=int(n[0]) n[1]=int(n[1]) l=input().split() l.sort() p=0 for x in range(n[0]): if n[1]==1: p+=int(l[x]) else: p+=n[1]*int(l[x]) n[1]=n[1]-1 print(p) ```
instruction
0
93,881
4
187,762
No
output
1
93,881
4
187,763
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him n subjects, the ith subject has ci chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously. Let us say that his initial per chapter learning power of a subject is x hours. In other words he can learn a chapter of a particular subject in x hours. Well Devu is not complete dumb, there is a good thing about him too. If you teach him a subject, then time required to teach any chapter of the next subject will require exactly 1 hour less than previously required (see the examples to understand it more clearly). Note that his per chapter learning power can not be less than 1 hour. You can teach him the n subjects in any possible order. Find out minimum amount of time (in hours) Devu will take to understand all the subjects and you will be free to do some enjoying task rather than teaching a dumb guy. Please be careful that answer might not fit in 32 bit data type. Input The first line will contain two space separated integers n, x (1 ≤ n, x ≤ 105). The next line will contain n space separated integers: c1, c2, ..., cn (1 ≤ ci ≤ 105). Output Output a single integer representing the answer to the problem. Examples Input 2 3 4 1 Output 11 Input 4 2 5 1 2 1 Output 10 Input 3 3 1 1 1 Output 6 Note Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 hours. Hence you will need to spend 12 + 2 = 14 hours. Consider the order of subjects: 2, 1. When you teach Devu the second subject, then it will take him 3 hours per chapter, so it will take 3 × 1 = 3 hours to teach the second subject. After teaching the second subject, his per chapter learning time will be 2 hours. Now teaching him the first subject will take 2 × 4 = 8 hours. Hence you will need to spend 11 hours. So overall, minimum of both the cases is 11 hours. Look at the third example. The order in this example doesn't matter. When you teach Devu the first subject, it will take him 3 hours per chapter. When you teach Devu the second subject, it will take him 2 hours per chapter. When you teach Devu the third subject, it will take him 1 hours per chapter. In total it takes 6 hours. Submitted Solution: ``` n, x = map(int, input().split()) c = list(map(int, input().split())) c.sort() res = x x -= 1 for i in range(1,n): if x == 1: res += c[i] else: res += c[i] * x x -= 1 print(res) ```
instruction
0
93,882
4
187,764
No
output
1
93,882
4
187,765
Provide tags and a correct Python 3 solution for this coding contest problem. Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used. For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second. What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time. Input The first line contains three integers m, t, r (1 ≤ m, t, r ≤ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≤ i ≤ m, 1 ≤ wi ≤ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order. Output If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print - 1. Examples Input 1 8 3 10 Output 3 Input 2 10 1 5 8 Output 1 Input 1 1 3 10 Output -1 Note Anya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit. It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively. In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight. In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight. In the third sample test the answer is - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
instruction
0
93,897
4
187,794
Tags: constructive algorithms, greedy Correct Solution: ``` # wacky array overflowing m, t, r = map(int, input().split()) ghosts = [int(i) for i in input().split()] candles, flag = [0 for _ in range(ghosts[-1] + 1 + 300)], True for i in range(m): now = 0 for j in range(ghosts[i] - 1, ghosts[i] - t - 1, -1): now += candles[j] if now < r: for j in range(ghosts[i] - 1, ghosts[i] - t - 1, -1): if not candles[j] and now < r: candles[j] = 1 now += 1 if now < r: flag = False if flag: print(sum(candles)) else: print(-1) ```
output
1
93,897
4
187,795
Provide tags and a correct Python 3 solution for this coding contest problem. Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used. For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second. What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time. Input The first line contains three integers m, t, r (1 ≤ m, t, r ≤ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≤ i ≤ m, 1 ≤ wi ≤ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order. Output If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print - 1. Examples Input 1 8 3 10 Output 3 Input 2 10 1 5 8 Output 1 Input 1 1 3 10 Output -1 Note Anya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit. It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively. In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight. In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight. In the third sample test the answer is - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
instruction
0
93,898
4
187,796
Tags: constructive algorithms, greedy Correct Solution: ``` def main(): m, t, r = map(int, input().split()) gh = sorted(map(int, input().split()), reverse=True) if r > t: print(-1) return l = [False] * 600 for g in gh: g -= t for i in range(g, g + r - sum(l[i] for i in range(g, g + t))): l[i] = True print(sum(l)) if __name__ == '__main__': main() ```
output
1
93,898
4
187,797
Provide tags and a correct Python 3 solution for this coding contest problem. Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used. For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second. What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time. Input The first line contains three integers m, t, r (1 ≤ m, t, r ≤ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≤ i ≤ m, 1 ≤ wi ≤ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order. Output If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print - 1. Examples Input 1 8 3 10 Output 3 Input 2 10 1 5 8 Output 1 Input 1 1 3 10 Output -1 Note Anya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit. It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively. In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight. In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight. In the third sample test the answer is - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
instruction
0
93,899
4
187,798
Tags: constructive algorithms, greedy Correct Solution: ``` import collections m, t, r = map(int, input().split()) w = list(map(int, input().split())) result = 0 current = collections.deque() used = set() def main(): global result, current for ghost in w: while current and current[0] < ghost: current.popleft() required = r - len(current) result += required moment = ghost for i in range(required): moment -= 1 while moment in used: moment -= 1 if ghost - moment > t: print(-1) return used.add(moment) current.append(moment + t) current = collections.deque(sorted(current)) print(result) main() ```
output
1
93,899
4
187,799
Provide tags and a correct Python 3 solution for this coding contest problem. Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used. For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second. What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time. Input The first line contains three integers m, t, r (1 ≤ m, t, r ≤ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≤ i ≤ m, 1 ≤ wi ≤ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order. Output If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print - 1. Examples Input 1 8 3 10 Output 3 Input 2 10 1 5 8 Output 1 Input 1 1 3 10 Output -1 Note Anya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit. It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively. In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight. In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight. In the third sample test the answer is - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
instruction
0
93,900
4
187,800
Tags: constructive algorithms, greedy Correct Solution: ``` m,t,r=input().split(' ') m=int(m) t=int(t) r=int(r) if t<r: input() need=-1 else: candles=[] need=r ghosts=input().split(' ') for i in range(r): candles.append(t-i) for i in range(len(ghosts)-1): dead=[] diff=int(ghosts[i+1])-int(ghosts[i]) for j in range(len(candles)): candles[j]=max(candles[j]-diff,0) if candles[j] is 0: dead.append(candles[j]) for candle in dead: candles.remove(0) need+=r-len(candles) for k in range(r-len(candles)): candles.append(t-k) print(need) ```
output
1
93,900
4
187,801
Provide tags and a correct Python 3 solution for this coding contest problem. Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used. For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second. What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time. Input The first line contains three integers m, t, r (1 ≤ m, t, r ≤ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≤ i ≤ m, 1 ≤ wi ≤ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order. Output If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print - 1. Examples Input 1 8 3 10 Output 3 Input 2 10 1 5 8 Output 1 Input 1 1 3 10 Output -1 Note Anya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit. It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively. In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight. In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight. In the third sample test the answer is - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
instruction
0
93,901
4
187,802
Tags: constructive algorithms, greedy Correct Solution: ``` import math import sys debug = False if debug: fin = open('input.txt', 'r') fout = open('output.txt', 'w') else: fin = sys.stdin fout = sys.stdout s = fin.readline() m, t, r = list(map(int, s.split())) if r > t: fout.write('-1') exit() s = fin.readline() w = list(map(int, s.split())) ans = r ar = [w[0] - r + i for i in range(r)] for i in range(1, m): while ar and w[i] - ar[0] > t: ar.pop(0) ans += r - len(ar) b = r - len(ar) for j in range(b): ar.append(w[i] - b + j) fout.write(str(ans)) ```
output
1
93,901
4
187,803
Provide tags and a correct Python 3 solution for this coding contest problem. Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used. For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second. What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time. Input The first line contains three integers m, t, r (1 ≤ m, t, r ≤ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≤ i ≤ m, 1 ≤ wi ≤ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order. Output If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print - 1. Examples Input 1 8 3 10 Output 3 Input 2 10 1 5 8 Output 1 Input 1 1 3 10 Output -1 Note Anya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit. It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively. In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight. In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight. In the third sample test the answer is - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
instruction
0
93,902
4
187,804
Tags: constructive algorithms, greedy Correct Solution: ``` # import itertools # import bisect # import math from collections import defaultdict, Counter, deque import os import sys from io import BytesIO, IOBase # sys.setrecursionlimit(10 ** 5) ii = lambda: int(input()) lmii = lambda: list(map(int, input().split())) slmii = lambda: sorted(map(int, input().split())) li = lambda: list(input()) mii = lambda: map(int, input().split()) msi = lambda: map(str, input().split()) def gcd(a, b): if b == 0: return a return gcd(b, a % b) def lcm(a, b): return (a * b) // gcd(a, b) def main(): # for _ in " " * int(input()): m, t, r = mii() w = lmii() cnt = 0 if t < r: print(-1) else: cul = [] for i in range(m): n = 0 for j in cul: if w[i] - j <= t: n += 1 for j in range(r-n): cul.append(w[i]-1-j) cnt += 1 print(cnt) BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") if __name__ == "__main__": main() ```
output
1
93,902
4
187,805
Provide tags and a correct Python 3 solution for this coding contest problem. Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used. For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second. What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time. Input The first line contains three integers m, t, r (1 ≤ m, t, r ≤ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≤ i ≤ m, 1 ≤ wi ≤ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order. Output If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print - 1. Examples Input 1 8 3 10 Output 3 Input 2 10 1 5 8 Output 1 Input 1 1 3 10 Output -1 Note Anya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit. It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively. In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight. In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight. In the third sample test the answer is - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
instruction
0
93,903
4
187,806
Tags: constructive algorithms, greedy Correct Solution: ``` a,b,c = map(int,input().split()) t=sorted(map(int,input().split()),reverse=True) if c>b: print('-1') else: q=[False]*600 for k in t: k=k-b for j in range(k,k+c-sum(q[i] for i in range(k,k+b))): q[j]=True print(sum(q)) ```
output
1
93,903
4
187,807
Provide tags and a correct Python 3 solution for this coding contest problem. Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used. For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second. What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time. Input The first line contains three integers m, t, r (1 ≤ m, t, r ≤ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≤ i ≤ m, 1 ≤ wi ≤ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order. Output If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print - 1. Examples Input 1 8 3 10 Output 3 Input 2 10 1 5 8 Output 1 Input 1 1 3 10 Output -1 Note Anya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit. It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively. In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight. In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight. In the third sample test the answer is - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
instruction
0
93,904
4
187,808
Tags: constructive algorithms, greedy Correct Solution: ``` import sys import math m, t, r = map(int, input().split()) if r > t: print(-1) exit() candles = [] gh = list(map(int, input().split())) for i in range(m): g = gh[i] now_on = 0 for c in candles: if g - c <= t: now_on += 1 for k in range(r - now_on): candles.append(g - 1 - k) print(len(candles)) ```
output
1
93,904
4
187,809
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used. For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second. What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time. Input The first line contains three integers m, t, r (1 ≤ m, t, r ≤ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≤ i ≤ m, 1 ≤ wi ≤ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order. Output If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print - 1. Examples Input 1 8 3 10 Output 3 Input 2 10 1 5 8 Output 1 Input 1 1 3 10 Output -1 Note Anya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit. It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively. In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight. In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight. In the third sample test the answer is - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes. Submitted Solution: ``` M,T,R = [int(x) for x in input().split()] W = [int(x) for x in input().split()] W.sort() if T<R: print(-1) exit() candle_cnt = 0 candles_num = [0 for i in range(601)] for w in W: for i in range(R): if candles_num[w]<R: for j in range(w-i,w-i+T): candles_num[j] += 1 candle_cnt += 1 else: break print(candle_cnt) ```
instruction
0
93,905
4
187,810
Yes
output
1
93,905
4
187,811
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used. For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second. What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time. Input The first line contains three integers m, t, r (1 ≤ m, t, r ≤ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≤ i ≤ m, 1 ≤ wi ≤ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order. Output If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print - 1. Examples Input 1 8 3 10 Output 3 Input 2 10 1 5 8 Output 1 Input 1 1 3 10 Output -1 Note Anya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit. It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively. In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight. In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight. In the third sample test the answer is - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes. Submitted Solution: ``` m, t, r = map(int,input().split()) a = list(map(int,input().split())) a.sort(reverse = True) if r > t: print(-1) exit(0) burn = [0] * 1000 for i in a: l = i l -= t for j in range(l, l + r - sum(burn[k] for k in range(l, l + t))): burn[j] = 1 print(sum(burn)) ```
instruction
0
93,906
4
187,812
Yes
output
1
93,906
4
187,813
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used. For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second. What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time. Input The first line contains three integers m, t, r (1 ≤ m, t, r ≤ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≤ i ≤ m, 1 ≤ wi ≤ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order. Output If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print - 1. Examples Input 1 8 3 10 Output 3 Input 2 10 1 5 8 Output 1 Input 1 1 3 10 Output -1 Note Anya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit. It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively. In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight. In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight. In the third sample test the answer is - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes. Submitted Solution: ``` #------------------------template--------------------------# import os import sys from math import * from collections import * # from fractions import * # from heapq import* from bisect import * from io import BytesIO, IOBase def vsInput(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") ALPHA='abcdefghijklmnopqrstuvwxyz/' M=998244353 EPS=1e-6 def Ceil(a,b): return a//b+int(a%b>0) def value():return tuple(map(int,input().split())) def array():return [int(i) for i in input().split()] def Int():return int(input()) def Str():return input() def arrayS():return [i for i in input().split()] #-------------------------code---------------------------# # vsInput() m,t,need=value() a=array() have=[i+t-1 for i in range(a[0]-need+1,a[0]+1)] # print(have) for i in a: ind=len(have)-bisect_left(have,i) # print(i,ind,i-need+ind+1,have) for j in range(i-need+ind+1,i+1): have.append(j+t-1) if(t<need): print(-1) else: print(len(have)) # print(have) ```
instruction
0
93,907
4
187,814
Yes
output
1
93,907
4
187,815
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used. For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second. What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time. Input The first line contains three integers m, t, r (1 ≤ m, t, r ≤ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≤ i ≤ m, 1 ≤ wi ≤ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order. Output If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print - 1. Examples Input 1 8 3 10 Output 3 Input 2 10 1 5 8 Output 1 Input 1 1 3 10 Output -1 Note Anya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit. It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively. In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight. In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight. In the third sample test the answer is - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes. Submitted Solution: ``` #!/bin/python3 import os import sys from io import BytesIO, IOBase import math def main(): m, t, r = map(int, input().split()) w = list(map(int, input().split())) if r > t: print(-1) else: candles = [] ans = 0 for time in w: while candles and candles[0] + t - 1 < time: candles.pop(0) requirement = r - len(candles) for i in range(requirement): candles.append(time - (requirement - 1) + i) ans += 1 print(ans) # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) def input(): return sys.stdin.readline().rstrip("\r\n") # endregion if __name__ == "__main__": main() ```
instruction
0
93,908
4
187,816
Yes
output
1
93,908
4
187,817
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used. For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second. What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time. Input The first line contains three integers m, t, r (1 ≤ m, t, r ≤ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≤ i ≤ m, 1 ≤ wi ≤ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order. Output If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print - 1. Examples Input 1 8 3 10 Output 3 Input 2 10 1 5 8 Output 1 Input 1 1 3 10 Output -1 Note Anya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit. It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively. In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight. In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight. In the third sample test the answer is - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes. Submitted Solution: ``` def fun(m,t,r,ghost_time): last_ghost = ghost_time[len(ghost_time)-1] arr=[0]* last_ghost sets = set() x=0 i=0 dic={} candles=0 g_arr=[0]*last_ghost for i in range(last_ghost): if i == ghost_time[x]-1: g_arr[i]=i x+=1 x=0 while i < last_ghost and x<m: if i == ghost_time[x]-1: j=0 y=i-1 while j < r: arr[y]=y+t y-=1 j+=1 i+=1 x+=1 continue i+=1 i=0 x=0 start=0 while i < last_ghost: if i!=0 and i == g_arr[i]: y = i-r candles+=r start = y+t i if start <i: return -1 i=start continue i+=1 # for i in range(last_ghost): # if arr[i]==1 : # dic[i]=i+t # x=0 # last = 0 # while x < len(ghost_time): # index = ghost_time[x]-1 # y=0 # for k in dic.keys(): # if dic[k] >= index: # sets.add(k) # y+=1 # if y == r: # break # x+=1 return candles # def fun1(st): # le = len(st) # stack = [0]*le # i=0 # x=0 # sh = 0 # h=0 # ans=list(st) # while i < len(ans): # if ans[i]=='#' : # stack[i]=stack[i-1] # i+=1 # continue # if i > 0 and ans[i] == ans[i-1]: # stack[i]=(stack[i-1]+1) # else: # stack[i] =0 # if i < len(ans)-1 and (ans[i] != ans[i+1]) or i == len(ans)-1: # p=0 # if i < le and stack[i]==0: # ans[i]=ans[i] # elif i > 2 and stack[i] == 1 and stack[i-2] == 1: # ans[i]='#' # h=1 # sh=0 # i-=2 # elif stack[i] != 1: # h=i # x=i # while stack[x-1]!=0: # ans[x]='#' # x-=1 # i = x-3 # i+=1 # return ''.join(c for c in ans if c!='#') var1, var2,var3 = [int(x) for x in input().split()] user_input = input().split(' ') numbers = [int(x.strip()) for x in user_input] # st = input() # print(fun(st)) print(fun(var1,var2,var3,numbers)) # # st = input() # var1, var2 = [int(x) for x in input().split()] # # # fun(st,var1,var2) # # # var2 = input() # print(fun(var1,var2)) # ############################################################3############################### # # user_input = input().split(' ') # # numbers = [int(x.strip()) for x in user_input] # # print(fun(numbers)) # ###################################################################################### ```
instruction
0
93,909
4
187,818
No
output
1
93,909
4
187,819
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used. For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second. What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time. Input The first line contains three integers m, t, r (1 ≤ m, t, r ≤ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≤ i ≤ m, 1 ≤ wi ≤ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order. Output If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print - 1. Examples Input 1 8 3 10 Output 3 Input 2 10 1 5 8 Output 1 Input 1 1 3 10 Output -1 Note Anya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit. It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively. In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight. In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight. In the third sample test the answer is - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes. Submitted Solution: ``` __author__ = 'default' def TaskC(): import sys #fl = open('TaskC.txt','r') m, t, r = list(map(int,input().split())) rdl1 = list(map(int,input().split())) used = 0 mas = [0]*r if r+1 > t: print(-1) sys.exit() for i in range(len(rdl1)): if i == 0: for j in range(len(mas)): mas[j] = rdl1[0]-r+j+t used += 1 else: if rdl1[i]+1 < mas[0]: pass else: for j in range(len(mas)): if mas[j] <= rdl1[i]+1: mas[j] = rdl1[i]-r+j+t used += 1 else: break print(used) TaskC() ```
instruction
0
93,910
4
187,820
No
output
1
93,910
4
187,821
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used. For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second. What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time. Input The first line contains three integers m, t, r (1 ≤ m, t, r ≤ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≤ i ≤ m, 1 ≤ wi ≤ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order. Output If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print - 1. Examples Input 1 8 3 10 Output 3 Input 2 10 1 5 8 Output 1 Input 1 1 3 10 Output -1 Note Anya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit. It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively. In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight. In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight. In the third sample test the answer is - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes. Submitted Solution: ``` raw=input().split() time=input().split() raw=[int(x) for x in raw] time=[int(x) for x in time] m=raw[0] t=raw[1] r=raw[2] c=0 can=0 lt=None if t<=r-1: print("-1") exit() while c <m: pt=time[c] if c!=0: de=pt-lt if de>t: can+=r lt=pt elif de >= t -(r-1)and de <=t: lt=pt te=r-1-(t-de) if te > 0: can+=te else: te*=-1 can+=te else: lt=pt can+=r c+=1 print(can) ```
instruction
0
93,911
4
187,822
No
output
1
93,911
4
187,823
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used. For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second. What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time. Input The first line contains three integers m, t, r (1 ≤ m, t, r ≤ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≤ i ≤ m, 1 ≤ wi ≤ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order. Output If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print - 1. Examples Input 1 8 3 10 Output 3 Input 2 10 1 5 8 Output 1 Input 1 1 3 10 Output -1 Note Anya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit. It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively. In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight. In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight. In the third sample test the answer is - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes. Submitted Solution: ``` m,t,r=map(int,input().split()) a=list(map(int,input().split())) mini=r ans=a[0] start=a[0]-1 end=t if t==1: print(-1) exit() for i in range(1,len(a)): if a[i]-start>t: start=a[i]-1 mini+=r elif a[i]-start==t: mini+=r start=a[i] else: pass print(mini) ```
instruction
0
93,912
4
187,824
No
output
1
93,912
4
187,825
Provide a correct Python 3 solution for this coding contest problem. A wise king declared a new calendar. "Tomorrow shall be the first day of the calendar, that is, the day 1 of the month 1 of the year 1. Each year consists of 10 months, from month 1 through month 10, and starts from a big month. A common year shall start with a big month, followed by small months and big months one after another. Therefore the first month is a big month, the second month is a small month, the third a big month, ..., and the 10th and last month a small one. A big month consists of 20 days and a small month consists of 19 days. However years which are multiples of three, that are year 3, year 6, year 9, and so on, shall consist of 10 big months and no small month." Many years have passed since the calendar started to be used. For celebration of the millennium day (the year 1000, month 1, day 1), a royal lottery is going to be organized to send gifts to those who have lived as many days as the number chosen by the lottery. Write a program that helps people calculate the number of days since their birthdate to the millennium day. Input The input is formatted as follows. > n > Y1 M1 D1 > Y2 M2 D2 > ... > Yn Mn Dn Here, the first line gives the number of datasets as a positive integer n, which is less than or equal to 100. It is followed by n datasets. Each dataset is formatted in a line and gives three positive integers, Yi (< 1000), Mi (≤ 10), and Di (≤ 20), that correspond to the year, month and day, respectively, of a person's birthdate in the king's calendar. These three numbers are separated by a space. Output For the birthdate specified in each dataset, print in a line the number of days from the birthdate, inclusive, to the millennium day, exclusive. Output lines should not contain any character other than this number. Sample Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output for the Sample Input 196470 128976 59710 160715 252 128977 59712 1 Example Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output 196470 128976 59710 160715 252 128977 59712 1
instruction
0
94,349
4
188,698
"Correct Solution: ``` n = int(input()) for _ in range(n): y,m,d = map(int,input().split()) days = 0 if d!=1: days += (20-d) if y%3!=0 and m%2==0 else (21-d) d = 1 if m==10: y += 1 m = 1 else: m+=1 if y!=1000: days += sum([19 if y%3!=0 and i%2==0 else 20 for i in range(11-m)]) y += 1 days += sum([19*5+20*5 if i%3!=0 else 20*10 for i in range(1000-y)]) print(days) ```
output
1
94,349
4
188,699
Provide a correct Python 3 solution for this coding contest problem. A wise king declared a new calendar. "Tomorrow shall be the first day of the calendar, that is, the day 1 of the month 1 of the year 1. Each year consists of 10 months, from month 1 through month 10, and starts from a big month. A common year shall start with a big month, followed by small months and big months one after another. Therefore the first month is a big month, the second month is a small month, the third a big month, ..., and the 10th and last month a small one. A big month consists of 20 days and a small month consists of 19 days. However years which are multiples of three, that are year 3, year 6, year 9, and so on, shall consist of 10 big months and no small month." Many years have passed since the calendar started to be used. For celebration of the millennium day (the year 1000, month 1, day 1), a royal lottery is going to be organized to send gifts to those who have lived as many days as the number chosen by the lottery. Write a program that helps people calculate the number of days since their birthdate to the millennium day. Input The input is formatted as follows. > n > Y1 M1 D1 > Y2 M2 D2 > ... > Yn Mn Dn Here, the first line gives the number of datasets as a positive integer n, which is less than or equal to 100. It is followed by n datasets. Each dataset is formatted in a line and gives three positive integers, Yi (< 1000), Mi (≤ 10), and Di (≤ 20), that correspond to the year, month and day, respectively, of a person's birthdate in the king's calendar. These three numbers are separated by a space. Output For the birthdate specified in each dataset, print in a line the number of days from the birthdate, inclusive, to the millennium day, exclusive. Output lines should not contain any character other than this number. Sample Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output for the Sample Input 196470 128976 59710 160715 252 128977 59712 1 Example Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output 196470 128976 59710 160715 252 128977 59712 1
instruction
0
94,350
4
188,700
"Correct Solution: ``` M = [19, 20] Y = sum(M) * 5 for i in range(int(input())): res = 0 y,m,d = list(map(int,input().split())) for y_2 in range(1000-1, y, -1): res += Y if y_2 % 3 != 0 else 200 for m_2 in range(10, m, -1): res += M[m_2 % 2] if y % 3 != 0 else 20 res += (M[m%2] if y % 3 != 0 else 20) - d +1 print(res) ```
output
1
94,350
4
188,701
Provide a correct Python 3 solution for this coding contest problem. A wise king declared a new calendar. "Tomorrow shall be the first day of the calendar, that is, the day 1 of the month 1 of the year 1. Each year consists of 10 months, from month 1 through month 10, and starts from a big month. A common year shall start with a big month, followed by small months and big months one after another. Therefore the first month is a big month, the second month is a small month, the third a big month, ..., and the 10th and last month a small one. A big month consists of 20 days and a small month consists of 19 days. However years which are multiples of three, that are year 3, year 6, year 9, and so on, shall consist of 10 big months and no small month." Many years have passed since the calendar started to be used. For celebration of the millennium day (the year 1000, month 1, day 1), a royal lottery is going to be organized to send gifts to those who have lived as many days as the number chosen by the lottery. Write a program that helps people calculate the number of days since their birthdate to the millennium day. Input The input is formatted as follows. > n > Y1 M1 D1 > Y2 M2 D2 > ... > Yn Mn Dn Here, the first line gives the number of datasets as a positive integer n, which is less than or equal to 100. It is followed by n datasets. Each dataset is formatted in a line and gives three positive integers, Yi (< 1000), Mi (≤ 10), and Di (≤ 20), that correspond to the year, month and day, respectively, of a person's birthdate in the king's calendar. These three numbers are separated by a space. Output For the birthdate specified in each dataset, print in a line the number of days from the birthdate, inclusive, to the millennium day, exclusive. Output lines should not contain any character other than this number. Sample Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output for the Sample Input 196470 128976 59710 160715 252 128977 59712 1 Example Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output 196470 128976 59710 160715 252 128977 59712 1
instruction
0
94,351
4
188,702
"Correct Solution: ``` LGE = 20 SML = 19 FUTU = 195 URUU = 200 YEAR3 = 590 def main(): howmany = int(input()) for i in range(howmany): daycount = 0 dataset = input() dataset = dataset.split(" ") for j in range(len(dataset)): dataset[j] = int(dataset[j]) #print("-------------------------------------") #print("data::") #print(dataset) daycount += totopmonth(dataset) #print("to the top of month") #print(daycount) #print("date::") #print(dataset) #print("") if dataset[0] == 1000: print(daycount) else: daycount += totopyear(dataset) #print("to the top of year") #print(daycount) #print("date::") #print(dataset) #print("") if dataset[0] == 1000: print(daycount) else: daycount += totheend(dataset) print(daycount) def totopmonth(array): count = 0 if array[2] == 1: return count elif array[0] % 3 != 0: if array[1] % 2 == 1: count = LGE - array[2] + 1 array[2] = 1 array[1] += 1 else: count = SML - array[2] + 1 array[2] = 1 array[1] += 1 else: count = LGE - array[2] + 1 array[2] = 1 array[1] += 1 if array[1] == 11: array[1] = 1 array[0] += 1 return count def totopyear(array): count = 0 if array[1] == 1: return count elif array[0] % 3 != 0: if array[1] % 2 == 1: count = (10 - array[1] + 1) // 2 * (LGE + SML) array[1] = 1 array[0] += 1 else: count = (11 - array[1] + 1) // 2 * (LGE + SML) - LGE array[1] = 1 array[0] += 1 else: count = (10 - array[1] + 1) * LGE array[1] = 1 array[0] += 1 return count def totheend(array): count = 0 if array[0] % 3 == 0: count = (999 - array[0]) // 3 * YEAR3 + URUU return count elif array[0] % 3 == 1: count = (999 - array[0]) // 3 * YEAR3 + YEAR3 return count else: count = (999 - array[0]) // 3 * YEAR3 + URUU + FUTU return count main() ```
output
1
94,351
4
188,703
Provide a correct Python 3 solution for this coding contest problem. A wise king declared a new calendar. "Tomorrow shall be the first day of the calendar, that is, the day 1 of the month 1 of the year 1. Each year consists of 10 months, from month 1 through month 10, and starts from a big month. A common year shall start with a big month, followed by small months and big months one after another. Therefore the first month is a big month, the second month is a small month, the third a big month, ..., and the 10th and last month a small one. A big month consists of 20 days and a small month consists of 19 days. However years which are multiples of three, that are year 3, year 6, year 9, and so on, shall consist of 10 big months and no small month." Many years have passed since the calendar started to be used. For celebration of the millennium day (the year 1000, month 1, day 1), a royal lottery is going to be organized to send gifts to those who have lived as many days as the number chosen by the lottery. Write a program that helps people calculate the number of days since their birthdate to the millennium day. Input The input is formatted as follows. > n > Y1 M1 D1 > Y2 M2 D2 > ... > Yn Mn Dn Here, the first line gives the number of datasets as a positive integer n, which is less than or equal to 100. It is followed by n datasets. Each dataset is formatted in a line and gives three positive integers, Yi (< 1000), Mi (≤ 10), and Di (≤ 20), that correspond to the year, month and day, respectively, of a person's birthdate in the king's calendar. These three numbers are separated by a space. Output For the birthdate specified in each dataset, print in a line the number of days from the birthdate, inclusive, to the millennium day, exclusive. Output lines should not contain any character other than this number. Sample Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output for the Sample Input 196470 128976 59710 160715 252 128977 59712 1 Example Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output 196470 128976 59710 160715 252 128977 59712 1
instruction
0
94,352
4
188,704
"Correct Solution: ``` n = int(input()) anslist = [] Y = 1000 M = 1 D = 1 ans = 195 * (Y - 1) ans += (Y - 1) // 3 * 5 ans += 20 * (M - 1) ans += D if Y % 3 != 0: ans -= (M - 1) // 2 milenium = ans for i in range(n): Y, M, D = map(int, input().split()) ans = 195 * (Y - 1) ans += (Y - 1) // 3 * 5 ans += 20 * (M - 1) ans += D if Y % 3 != 0: ans -= (M - 1) // 2 anslist.append(milenium - ans) for i in anslist: print(i) ```
output
1
94,352
4
188,705
Provide a correct Python 3 solution for this coding contest problem. A wise king declared a new calendar. "Tomorrow shall be the first day of the calendar, that is, the day 1 of the month 1 of the year 1. Each year consists of 10 months, from month 1 through month 10, and starts from a big month. A common year shall start with a big month, followed by small months and big months one after another. Therefore the first month is a big month, the second month is a small month, the third a big month, ..., and the 10th and last month a small one. A big month consists of 20 days and a small month consists of 19 days. However years which are multiples of three, that are year 3, year 6, year 9, and so on, shall consist of 10 big months and no small month." Many years have passed since the calendar started to be used. For celebration of the millennium day (the year 1000, month 1, day 1), a royal lottery is going to be organized to send gifts to those who have lived as many days as the number chosen by the lottery. Write a program that helps people calculate the number of days since their birthdate to the millennium day. Input The input is formatted as follows. > n > Y1 M1 D1 > Y2 M2 D2 > ... > Yn Mn Dn Here, the first line gives the number of datasets as a positive integer n, which is less than or equal to 100. It is followed by n datasets. Each dataset is formatted in a line and gives three positive integers, Yi (< 1000), Mi (≤ 10), and Di (≤ 20), that correspond to the year, month and day, respectively, of a person's birthdate in the king's calendar. These three numbers are separated by a space. Output For the birthdate specified in each dataset, print in a line the number of days from the birthdate, inclusive, to the millennium day, exclusive. Output lines should not contain any character other than this number. Sample Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output for the Sample Input 196470 128976 59710 160715 252 128977 59712 1 Example Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output 196470 128976 59710 160715 252 128977 59712 1
instruction
0
94,353
4
188,706
"Correct Solution: ``` def main(): y, m, d = map(int, input().split()) a = (y - 1) // 3 b = (y - 1) % 3 c = a * 590 + 195 * b if y % 3: a = (m - 1) // 2 b = (m - 1) % 2 c += a * 39 + b * 20 else: c += (m - 1) * 20 c += d - 1 print(196470-c) n = int(input()) for i in range(n): main() ```
output
1
94,353
4
188,707
Provide a correct Python 3 solution for this coding contest problem. A wise king declared a new calendar. "Tomorrow shall be the first day of the calendar, that is, the day 1 of the month 1 of the year 1. Each year consists of 10 months, from month 1 through month 10, and starts from a big month. A common year shall start with a big month, followed by small months and big months one after another. Therefore the first month is a big month, the second month is a small month, the third a big month, ..., and the 10th and last month a small one. A big month consists of 20 days and a small month consists of 19 days. However years which are multiples of three, that are year 3, year 6, year 9, and so on, shall consist of 10 big months and no small month." Many years have passed since the calendar started to be used. For celebration of the millennium day (the year 1000, month 1, day 1), a royal lottery is going to be organized to send gifts to those who have lived as many days as the number chosen by the lottery. Write a program that helps people calculate the number of days since their birthdate to the millennium day. Input The input is formatted as follows. > n > Y1 M1 D1 > Y2 M2 D2 > ... > Yn Mn Dn Here, the first line gives the number of datasets as a positive integer n, which is less than or equal to 100. It is followed by n datasets. Each dataset is formatted in a line and gives three positive integers, Yi (< 1000), Mi (≤ 10), and Di (≤ 20), that correspond to the year, month and day, respectively, of a person's birthdate in the king's calendar. These three numbers are separated by a space. Output For the birthdate specified in each dataset, print in a line the number of days from the birthdate, inclusive, to the millennium day, exclusive. Output lines should not contain any character other than this number. Sample Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output for the Sample Input 196470 128976 59710 160715 252 128977 59712 1 Example Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output 196470 128976 59710 160715 252 128977 59712 1
instruction
0
94,354
4
188,708
"Correct Solution: ``` #!/usr/bin/env python # -*- coding: utf-8 -*- def date2num(y,m,d): t = (y-1)//3 days = t*10*20 + (y-1-t)*5*20+(y-1-t)*5*19 if y%3 == 0: days += (m-1)*20+d else: days += (m-1)//2*19+(m-1-(m-1)//2)*20+d return days for i in range(int(input())): y,m,d = map(int,input().split(" ")) print(date2num(1000,1,1) - date2num(y,m,d)) ```
output
1
94,354
4
188,709
Provide a correct Python 3 solution for this coding contest problem. A wise king declared a new calendar. "Tomorrow shall be the first day of the calendar, that is, the day 1 of the month 1 of the year 1. Each year consists of 10 months, from month 1 through month 10, and starts from a big month. A common year shall start with a big month, followed by small months and big months one after another. Therefore the first month is a big month, the second month is a small month, the third a big month, ..., and the 10th and last month a small one. A big month consists of 20 days and a small month consists of 19 days. However years which are multiples of three, that are year 3, year 6, year 9, and so on, shall consist of 10 big months and no small month." Many years have passed since the calendar started to be used. For celebration of the millennium day (the year 1000, month 1, day 1), a royal lottery is going to be organized to send gifts to those who have lived as many days as the number chosen by the lottery. Write a program that helps people calculate the number of days since their birthdate to the millennium day. Input The input is formatted as follows. > n > Y1 M1 D1 > Y2 M2 D2 > ... > Yn Mn Dn Here, the first line gives the number of datasets as a positive integer n, which is less than or equal to 100. It is followed by n datasets. Each dataset is formatted in a line and gives three positive integers, Yi (< 1000), Mi (≤ 10), and Di (≤ 20), that correspond to the year, month and day, respectively, of a person's birthdate in the king's calendar. These three numbers are separated by a space. Output For the birthdate specified in each dataset, print in a line the number of days from the birthdate, inclusive, to the millennium day, exclusive. Output lines should not contain any character other than this number. Sample Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output for the Sample Input 196470 128976 59710 160715 252 128977 59712 1 Example Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output 196470 128976 59710 160715 252 128977 59712 1
instruction
0
94,355
4
188,710
"Correct Solution: ``` n = int(input()) def solve(Y,M,D): ans = 0 ans += (Y - 1) * (19 + 20) * 5 ans += ((Y -1)// 3) * 5 ans += 19 * (M-1) if Y % 3 ==0: ans += (M-1) else: ans += (M // 2) ans += (D-1) print(196470 - ans) for i in range(n): l = input().split(' ') solve(int(l[0]) , int(l[1]), int(l[2])) ```
output
1
94,355
4
188,711
Provide a correct Python 3 solution for this coding contest problem. A wise king declared a new calendar. "Tomorrow shall be the first day of the calendar, that is, the day 1 of the month 1 of the year 1. Each year consists of 10 months, from month 1 through month 10, and starts from a big month. A common year shall start with a big month, followed by small months and big months one after another. Therefore the first month is a big month, the second month is a small month, the third a big month, ..., and the 10th and last month a small one. A big month consists of 20 days and a small month consists of 19 days. However years which are multiples of three, that are year 3, year 6, year 9, and so on, shall consist of 10 big months and no small month." Many years have passed since the calendar started to be used. For celebration of the millennium day (the year 1000, month 1, day 1), a royal lottery is going to be organized to send gifts to those who have lived as many days as the number chosen by the lottery. Write a program that helps people calculate the number of days since their birthdate to the millennium day. Input The input is formatted as follows. > n > Y1 M1 D1 > Y2 M2 D2 > ... > Yn Mn Dn Here, the first line gives the number of datasets as a positive integer n, which is less than or equal to 100. It is followed by n datasets. Each dataset is formatted in a line and gives three positive integers, Yi (< 1000), Mi (≤ 10), and Di (≤ 20), that correspond to the year, month and day, respectively, of a person's birthdate in the king's calendar. These three numbers are separated by a space. Output For the birthdate specified in each dataset, print in a line the number of days from the birthdate, inclusive, to the millennium day, exclusive. Output lines should not contain any character other than this number. Sample Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output for the Sample Input 196470 128976 59710 160715 252 128977 59712 1 Example Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output 196470 128976 59710 160715 252 128977 59712 1
instruction
0
94,356
4
188,712
"Correct Solution: ``` n=int(input()) table=[0,20, 39, 59, 78, 98, 117, 137, 156, 176, 195] u_table=[0,20, 40, 60, 80, 100, 120, 140, 160, 180, 200] for i in range(n): y,m,d=map(int,input().split()) ans=0 for j in range(y+1,1000): if j%3==0: ans+=u_table[-1] else: ans+=table[-1] if y%3==0: ans+=u_table[-1]-u_table[m] ans+=u_table[m]-u_table[m-1]-d+1 else: ans+=table[-1]-table[m] ans+=table[m]-table[m-1]-d+1 print(ans) ```
output
1
94,356
4
188,713
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A wise king declared a new calendar. "Tomorrow shall be the first day of the calendar, that is, the day 1 of the month 1 of the year 1. Each year consists of 10 months, from month 1 through month 10, and starts from a big month. A common year shall start with a big month, followed by small months and big months one after another. Therefore the first month is a big month, the second month is a small month, the third a big month, ..., and the 10th and last month a small one. A big month consists of 20 days and a small month consists of 19 days. However years which are multiples of three, that are year 3, year 6, year 9, and so on, shall consist of 10 big months and no small month." Many years have passed since the calendar started to be used. For celebration of the millennium day (the year 1000, month 1, day 1), a royal lottery is going to be organized to send gifts to those who have lived as many days as the number chosen by the lottery. Write a program that helps people calculate the number of days since their birthdate to the millennium day. Input The input is formatted as follows. > n > Y1 M1 D1 > Y2 M2 D2 > ... > Yn Mn Dn Here, the first line gives the number of datasets as a positive integer n, which is less than or equal to 100. It is followed by n datasets. Each dataset is formatted in a line and gives three positive integers, Yi (< 1000), Mi (≤ 10), and Di (≤ 20), that correspond to the year, month and day, respectively, of a person's birthdate in the king's calendar. These three numbers are separated by a space. Output For the birthdate specified in each dataset, print in a line the number of days from the birthdate, inclusive, to the millennium day, exclusive. Output lines should not contain any character other than this number. Sample Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output for the Sample Input 196470 128976 59710 160715 252 128977 59712 1 Example Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output 196470 128976 59710 160715 252 128977 59712 1 Submitted Solution: ``` n = int(input()) for i in range(n): y,m,d = map(int, input().split()) dif = 999 - y leap = int(dif / 3) + 1 common = dif - leap + 1 days = leap * 200 + common * 195 # days from y 1 1 days -= (m - 1) * 20 if y % 3 != 0: days += int((m - 1) / 2) days -= (d - 1) print(days) ```
instruction
0
94,357
4
188,714
Yes
output
1
94,357
4
188,715
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A wise king declared a new calendar. "Tomorrow shall be the first day of the calendar, that is, the day 1 of the month 1 of the year 1. Each year consists of 10 months, from month 1 through month 10, and starts from a big month. A common year shall start with a big month, followed by small months and big months one after another. Therefore the first month is a big month, the second month is a small month, the third a big month, ..., and the 10th and last month a small one. A big month consists of 20 days and a small month consists of 19 days. However years which are multiples of three, that are year 3, year 6, year 9, and so on, shall consist of 10 big months and no small month." Many years have passed since the calendar started to be used. For celebration of the millennium day (the year 1000, month 1, day 1), a royal lottery is going to be organized to send gifts to those who have lived as many days as the number chosen by the lottery. Write a program that helps people calculate the number of days since their birthdate to the millennium day. Input The input is formatted as follows. > n > Y1 M1 D1 > Y2 M2 D2 > ... > Yn Mn Dn Here, the first line gives the number of datasets as a positive integer n, which is less than or equal to 100. It is followed by n datasets. Each dataset is formatted in a line and gives three positive integers, Yi (< 1000), Mi (≤ 10), and Di (≤ 20), that correspond to the year, month and day, respectively, of a person's birthdate in the king's calendar. These three numbers are separated by a space. Output For the birthdate specified in each dataset, print in a line the number of days from the birthdate, inclusive, to the millennium day, exclusive. Output lines should not contain any character other than this number. Sample Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output for the Sample Input 196470 128976 59710 160715 252 128977 59712 1 Example Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output 196470 128976 59710 160715 252 128977 59712 1 Submitted Solution: ``` def days(y, m, d) : cnt = 0 for i in range(1, y) : if i % 3 == 0 : cnt += 200 else : cnt += 195 for i in range(1, m) : if y % 3 == 0 : cnt += 20 else : if i % 2 == 0 : cnt += 19 else : cnt += 20 cnt += d-1 return cnt n = int(input()) for i in range(n) : y, m, d = map(int, input().split()) print(days(1000, 1, 1) - days(y, m, d)) ```
instruction
0
94,358
4
188,716
Yes
output
1
94,358
4
188,717
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A wise king declared a new calendar. "Tomorrow shall be the first day of the calendar, that is, the day 1 of the month 1 of the year 1. Each year consists of 10 months, from month 1 through month 10, and starts from a big month. A common year shall start with a big month, followed by small months and big months one after another. Therefore the first month is a big month, the second month is a small month, the third a big month, ..., and the 10th and last month a small one. A big month consists of 20 days and a small month consists of 19 days. However years which are multiples of three, that are year 3, year 6, year 9, and so on, shall consist of 10 big months and no small month." Many years have passed since the calendar started to be used. For celebration of the millennium day (the year 1000, month 1, day 1), a royal lottery is going to be organized to send gifts to those who have lived as many days as the number chosen by the lottery. Write a program that helps people calculate the number of days since their birthdate to the millennium day. Input The input is formatted as follows. > n > Y1 M1 D1 > Y2 M2 D2 > ... > Yn Mn Dn Here, the first line gives the number of datasets as a positive integer n, which is less than or equal to 100. It is followed by n datasets. Each dataset is formatted in a line and gives three positive integers, Yi (< 1000), Mi (≤ 10), and Di (≤ 20), that correspond to the year, month and day, respectively, of a person's birthdate in the king's calendar. These three numbers are separated by a space. Output For the birthdate specified in each dataset, print in a line the number of days from the birthdate, inclusive, to the millennium day, exclusive. Output lines should not contain any character other than this number. Sample Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output for the Sample Input 196470 128976 59710 160715 252 128977 59712 1 Example Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output 196470 128976 59710 160715 252 128977 59712 1 Submitted Solution: ``` N = int(input()) YMD = [[0,0,0] for i in range(N)] ans = [[[0 for i in range(20)] for j in range(10)] for k in range(1000)] for i in range(N): line = input().split(" ") YMD[i] = [int(line[0])-1, int(line[1])-1, int(line[2])-1] #print(YMD) count = 0 for y in range(1000): if (y+1)%3 == 0: for m in range(10): for d in range(20): ans[y][m][d] = count count+=1 else: for m in range(10): if m%2 == 0: for d in range(20): ans[y][m][d] = count count+=1 else: for d in range(19): ans[y][m][d] = count count+=1 mile = ans[999][0][0] for i in range(N): tmpYMD = YMD[i] tage = ans[tmpYMD[0]][tmpYMD[1]][tmpYMD[2]] diff = mile - tage print(diff) ```
instruction
0
94,359
4
188,718
Yes
output
1
94,359
4
188,719
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A wise king declared a new calendar. "Tomorrow shall be the first day of the calendar, that is, the day 1 of the month 1 of the year 1. Each year consists of 10 months, from month 1 through month 10, and starts from a big month. A common year shall start with a big month, followed by small months and big months one after another. Therefore the first month is a big month, the second month is a small month, the third a big month, ..., and the 10th and last month a small one. A big month consists of 20 days and a small month consists of 19 days. However years which are multiples of three, that are year 3, year 6, year 9, and so on, shall consist of 10 big months and no small month." Many years have passed since the calendar started to be used. For celebration of the millennium day (the year 1000, month 1, day 1), a royal lottery is going to be organized to send gifts to those who have lived as many days as the number chosen by the lottery. Write a program that helps people calculate the number of days since their birthdate to the millennium day. Input The input is formatted as follows. > n > Y1 M1 D1 > Y2 M2 D2 > ... > Yn Mn Dn Here, the first line gives the number of datasets as a positive integer n, which is less than or equal to 100. It is followed by n datasets. Each dataset is formatted in a line and gives three positive integers, Yi (< 1000), Mi (≤ 10), and Di (≤ 20), that correspond to the year, month and day, respectively, of a person's birthdate in the king's calendar. These three numbers are separated by a space. Output For the birthdate specified in each dataset, print in a line the number of days from the birthdate, inclusive, to the millennium day, exclusive. Output lines should not contain any character other than this number. Sample Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output for the Sample Input 196470 128976 59710 160715 252 128977 59712 1 Example Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output 196470 128976 59710 160715 252 128977 59712 1 Submitted Solution: ``` for i in range(int(input())): y, m, d = map(int, input().split()) print(196471 - ((y - 1) * 195 + (y - 1) // 3 * 5 + 20 * (m - 1) - min(1, y % 3) * ((m - 1) // 2) + d)) ```
instruction
0
94,360
4
188,720
Yes
output
1
94,360
4
188,721
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A wise king declared a new calendar. "Tomorrow shall be the first day of the calendar, that is, the day 1 of the month 1 of the year 1. Each year consists of 10 months, from month 1 through month 10, and starts from a big month. A common year shall start with a big month, followed by small months and big months one after another. Therefore the first month is a big month, the second month is a small month, the third a big month, ..., and the 10th and last month a small one. A big month consists of 20 days and a small month consists of 19 days. However years which are multiples of three, that are year 3, year 6, year 9, and so on, shall consist of 10 big months and no small month." Many years have passed since the calendar started to be used. For celebration of the millennium day (the year 1000, month 1, day 1), a royal lottery is going to be organized to send gifts to those who have lived as many days as the number chosen by the lottery. Write a program that helps people calculate the number of days since their birthdate to the millennium day. Input The input is formatted as follows. > n > Y1 M1 D1 > Y2 M2 D2 > ... > Yn Mn Dn Here, the first line gives the number of datasets as a positive integer n, which is less than or equal to 100. It is followed by n datasets. Each dataset is formatted in a line and gives three positive integers, Yi (< 1000), Mi (≤ 10), and Di (≤ 20), that correspond to the year, month and day, respectively, of a person's birthdate in the king's calendar. These three numbers are separated by a space. Output For the birthdate specified in each dataset, print in a line the number of days from the birthdate, inclusive, to the millennium day, exclusive. Output lines should not contain any character other than this number. Sample Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output for the Sample Input 196470 128976 59710 160715 252 128977 59712 1 Example Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output 196470 128976 59710 160715 252 128977 59712 1 Submitted Solution: ``` n = int(input()) for _ in range(n): (y, m, d) = [int(x) for x in input().split()] day = (999-y)*195 + (999-y)//3*5 if y%3 == 0: day += (10-m)//2 day += (10-m)*19 + (10-m) if y%3 != 0 and m%2 == 0: day += (19-d) else: day += (20-d) print(day+1) ```
instruction
0
94,361
4
188,722
No
output
1
94,361
4
188,723
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A wise king declared a new calendar. "Tomorrow shall be the first day of the calendar, that is, the day 1 of the month 1 of the year 1. Each year consists of 10 months, from month 1 through month 10, and starts from a big month. A common year shall start with a big month, followed by small months and big months one after another. Therefore the first month is a big month, the second month is a small month, the third a big month, ..., and the 10th and last month a small one. A big month consists of 20 days and a small month consists of 19 days. However years which are multiples of three, that are year 3, year 6, year 9, and so on, shall consist of 10 big months and no small month." Many years have passed since the calendar started to be used. For celebration of the millennium day (the year 1000, month 1, day 1), a royal lottery is going to be organized to send gifts to those who have lived as many days as the number chosen by the lottery. Write a program that helps people calculate the number of days since their birthdate to the millennium day. Input The input is formatted as follows. > n > Y1 M1 D1 > Y2 M2 D2 > ... > Yn Mn Dn Here, the first line gives the number of datasets as a positive integer n, which is less than or equal to 100. It is followed by n datasets. Each dataset is formatted in a line and gives three positive integers, Yi (< 1000), Mi (≤ 10), and Di (≤ 20), that correspond to the year, month and day, respectively, of a person's birthdate in the king's calendar. These three numbers are separated by a space. Output For the birthdate specified in each dataset, print in a line the number of days from the birthdate, inclusive, to the millennium day, exclusive. Output lines should not contain any character other than this number. Sample Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output for the Sample Input 196470 128976 59710 160715 252 128977 59712 1 Example Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output 196470 128976 59710 160715 252 128977 59712 1 Submitted Solution: ``` n = int(input()) for _ in range(n): day_sum = 0 year, month, day = map(int, input().split()) # total days of the first year (including the first day) # print("total days include the first day.") day_sum += 1 # print("for the first month {0} in the first year {1}:".format(month, year)) if year % 3 == 0 or month % 2 == 1: day_sum += 20 - day # print("plus {0} day.".format(20 - day)) else: day_sum += 19 - day # print("plus {0} day.".format(19 - day)) for m in range(month+1, 11): # print("for the month {0} in the first year:".format(m)) if m % 2 == 1: day_sum += 20 # print("plus 20 day.") else: day_sum += 19 # print("plus 19 day.") # total days from the second year to the second year from the last for y in range(1, 1000-year): # print("for year {0}:".format(year+y)) for m in range(1, 11): # print("for the month {0}".format(m)) if y % 3 == 0 or m % 2 == 1: day_sum += 20 # print("plus 20 day.") else: day_sum += 19 # print("plus 19 day.") print(day_sum) ```
instruction
0
94,362
4
188,724
No
output
1
94,362
4
188,725
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A wise king declared a new calendar. "Tomorrow shall be the first day of the calendar, that is, the day 1 of the month 1 of the year 1. Each year consists of 10 months, from month 1 through month 10, and starts from a big month. A common year shall start with a big month, followed by small months and big months one after another. Therefore the first month is a big month, the second month is a small month, the third a big month, ..., and the 10th and last month a small one. A big month consists of 20 days and a small month consists of 19 days. However years which are multiples of three, that are year 3, year 6, year 9, and so on, shall consist of 10 big months and no small month." Many years have passed since the calendar started to be used. For celebration of the millennium day (the year 1000, month 1, day 1), a royal lottery is going to be organized to send gifts to those who have lived as many days as the number chosen by the lottery. Write a program that helps people calculate the number of days since their birthdate to the millennium day. Input The input is formatted as follows. > n > Y1 M1 D1 > Y2 M2 D2 > ... > Yn Mn Dn Here, the first line gives the number of datasets as a positive integer n, which is less than or equal to 100. It is followed by n datasets. Each dataset is formatted in a line and gives three positive integers, Yi (< 1000), Mi (≤ 10), and Di (≤ 20), that correspond to the year, month and day, respectively, of a person's birthdate in the king's calendar. These three numbers are separated by a space. Output For the birthdate specified in each dataset, print in a line the number of days from the birthdate, inclusive, to the millennium day, exclusive. Output lines should not contain any character other than this number. Sample Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output for the Sample Input 196470 128976 59710 160715 252 128977 59712 1 Example Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output 196470 128976 59710 160715 252 128977 59712 1 Submitted Solution: ``` #solve function def solve(dates): counter = 0; start_month = dates[1] start_day, end_day = dates[2], 0 for year in range(dates[0], 1000): for month in range(start_month, 11): if year%3 == 0 or month%2 == 1: end_day = 21 else: end_day = 20 # count days counter += (end_day - start_day) start_day = 1 else: start_month = 1 return counter #main function if __name__ == '__main__': n = int(input()) dates = [] tmp_dates = [] for i in range(n): tmp_dates = input().split() for j, tmp_date in enumerate(tmp_dates): dates.append(int(tmp_date)) date_count = solve(dates) print(date_count) dates.clear() ```
instruction
0
94,363
4
188,726
No
output
1
94,363
4
188,727
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A wise king declared a new calendar. "Tomorrow shall be the first day of the calendar, that is, the day 1 of the month 1 of the year 1. Each year consists of 10 months, from month 1 through month 10, and starts from a big month. A common year shall start with a big month, followed by small months and big months one after another. Therefore the first month is a big month, the second month is a small month, the third a big month, ..., and the 10th and last month a small one. A big month consists of 20 days and a small month consists of 19 days. However years which are multiples of three, that are year 3, year 6, year 9, and so on, shall consist of 10 big months and no small month." Many years have passed since the calendar started to be used. For celebration of the millennium day (the year 1000, month 1, day 1), a royal lottery is going to be organized to send gifts to those who have lived as many days as the number chosen by the lottery. Write a program that helps people calculate the number of days since their birthdate to the millennium day. Input The input is formatted as follows. > n > Y1 M1 D1 > Y2 M2 D2 > ... > Yn Mn Dn Here, the first line gives the number of datasets as a positive integer n, which is less than or equal to 100. It is followed by n datasets. Each dataset is formatted in a line and gives three positive integers, Yi (< 1000), Mi (≤ 10), and Di (≤ 20), that correspond to the year, month and day, respectively, of a person's birthdate in the king's calendar. These three numbers are separated by a space. Output For the birthdate specified in each dataset, print in a line the number of days from the birthdate, inclusive, to the millennium day, exclusive. Output lines should not contain any character other than this number. Sample Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output for the Sample Input 196470 128976 59710 160715 252 128977 59712 1 Example Input 8 1 1 1 344 3 1 696 5 1 182 9 5 998 8 7 344 2 19 696 4 19 999 10 20 Output 196470 128976 59710 160715 252 128977 59712 1 Submitted Solution: ``` import sys n=int(sys.stdin.readline()) for i in range(0,n): a=map(int,sys.stdin.readline().split()) a[0]-=1;a[1]-=1 print(196471-a[0]*195-a[0]/3*5-a[1]*20+(a[1]/2 if a[0]%3!=2 else 0)-a[2]) ```
instruction
0
94,364
4
188,728
No
output
1
94,364
4
188,729
Provide a correct Python 3 solution for this coding contest problem. It is said that a legendary treasure left by Mr. Yao is sleeping somewhere in Hachioji long ago. The treasure map, which is said to show its whereabouts, has been handed down by Yao's n descendants, divided into several pieces. Now, the descendants of Mr. Yao were trying to cooperate to obtain the treasure. However, the treasure cannot be found only by a part of the treasure map that points to the location of the treasure. Therefore, all the descendants of Mr. Yao gathered and tried to collect the map in one place. However, even if I tried to put it into practice, I couldn't get together because I couldn't meet the schedule. However, this information about the treasure is valuable information that has been secretly passed down in the clan. Considering the risk of leakage, exchanging maps using public communication means is out of the question. Therefore, I decided to collect the map for one descendant by repeating the process of meeting the descendants in person and handing over the map. There is no limit to the number of people that one person can meet in a day, but it is necessary that there is a schedule for each other. Your job is to write a program that asks for at least how many days it will take to collect a map from a list of open days on schedule for each offspring. By the way, the unity of the Yao clan is very tight. If the descendants who finally get the entire map betray the other descendants and take away the treasure, they will be sanctioned by the clan. The sanctions are so horrifying that it is virtually impossible for their descendants to actually carry away the treasure. Input The input consists of multiple datasets. Each dataset consists of multiple rows. The first line contains the integer n (1 <n <= 50), which represents the number of people with a piece of the map. The next n lines contain the schedule for each descendant. Line i represents the schedule of the i-th descendant, with some integers separated by a single character space. The first integer fi (0 <= fi <= 30) is an integer that represents the number of days that the descendant's schedule is free. The following fi integers represent dates when the schedule is free. These dates differ from each other and are all greater than or equal to 1 and less than or equal to 30. There is one line containing only 0 at the end of the input. Output Print one integer on one line for each dataset. If you can collect the map within 30 days, output the minimum number of days required to collect the map, otherwise output -1. Addendum: The above "minimum number of days required to collect maps" means the date when all maps are collected earliest starting from one day. Example Input 4 1 1 2 2 3 2 1 2 3 3 4 5 0 Output 3
instruction
0
96,018
4
192,036
"Correct Solution: ``` # coding: utf-8 while 1: n=int(input()) if n==0: break dic={} ok=[[False for i in range(30)] for i in range(n)] for i in range(n): dic[i]=[i] for m in list(map(int,input().split()))[1:]: ok[i][m-1]=True f=False for i in range(30): tmp=[] for j in range(n): if ok[j][i]: tmp+=list(dic[j]) tmp=set(tmp) for j in range(n): if ok[j][i]: dic[j]=list(tmp) if len(dic[j])==n: print(i+1) f=True break if f: break if not f: print(-1) ```
output
1
96,018
4
192,037
Provide a correct Python 3 solution for this coding contest problem. It is said that a legendary treasure left by Mr. Yao is sleeping somewhere in Hachioji long ago. The treasure map, which is said to show its whereabouts, has been handed down by Yao's n descendants, divided into several pieces. Now, the descendants of Mr. Yao were trying to cooperate to obtain the treasure. However, the treasure cannot be found only by a part of the treasure map that points to the location of the treasure. Therefore, all the descendants of Mr. Yao gathered and tried to collect the map in one place. However, even if I tried to put it into practice, I couldn't get together because I couldn't meet the schedule. However, this information about the treasure is valuable information that has been secretly passed down in the clan. Considering the risk of leakage, exchanging maps using public communication means is out of the question. Therefore, I decided to collect the map for one descendant by repeating the process of meeting the descendants in person and handing over the map. There is no limit to the number of people that one person can meet in a day, but it is necessary that there is a schedule for each other. Your job is to write a program that asks for at least how many days it will take to collect a map from a list of open days on schedule for each offspring. By the way, the unity of the Yao clan is very tight. If the descendants who finally get the entire map betray the other descendants and take away the treasure, they will be sanctioned by the clan. The sanctions are so horrifying that it is virtually impossible for their descendants to actually carry away the treasure. Input The input consists of multiple datasets. Each dataset consists of multiple rows. The first line contains the integer n (1 <n <= 50), which represents the number of people with a piece of the map. The next n lines contain the schedule for each descendant. Line i represents the schedule of the i-th descendant, with some integers separated by a single character space. The first integer fi (0 <= fi <= 30) is an integer that represents the number of days that the descendant's schedule is free. The following fi integers represent dates when the schedule is free. These dates differ from each other and are all greater than or equal to 1 and less than or equal to 30. There is one line containing only 0 at the end of the input. Output Print one integer on one line for each dataset. If you can collect the map within 30 days, output the minimum number of days required to collect the map, otherwise output -1. Addendum: The above "minimum number of days required to collect maps" means the date when all maps are collected earliest starting from one day. Example Input 4 1 1 2 2 3 2 1 2 3 3 4 5 0 Output 3
instruction
0
96,019
4
192,038
"Correct Solution: ``` import itertools while True: N = int(input()) if not N: break D = [[] for _ in range(30)] for i in range(N): for x in map(int, input().split()[1:]): D[x - 1].append(i) C = [1 << i for i in range(N)] for d in range(30): for i, j in itertools.combinations(D[d], 2): C[i] = C[j] = C[i] | C[j] if any(x == (1 << N) - 1 for x in C): print(d + 1) break else: print(-1) ```
output
1
96,019
4
192,039
Provide a correct Python 3 solution for this coding contest problem. It is said that a legendary treasure left by Mr. Yao is sleeping somewhere in Hachioji long ago. The treasure map, which is said to show its whereabouts, has been handed down by Yao's n descendants, divided into several pieces. Now, the descendants of Mr. Yao were trying to cooperate to obtain the treasure. However, the treasure cannot be found only by a part of the treasure map that points to the location of the treasure. Therefore, all the descendants of Mr. Yao gathered and tried to collect the map in one place. However, even if I tried to put it into practice, I couldn't get together because I couldn't meet the schedule. However, this information about the treasure is valuable information that has been secretly passed down in the clan. Considering the risk of leakage, exchanging maps using public communication means is out of the question. Therefore, I decided to collect the map for one descendant by repeating the process of meeting the descendants in person and handing over the map. There is no limit to the number of people that one person can meet in a day, but it is necessary that there is a schedule for each other. Your job is to write a program that asks for at least how many days it will take to collect a map from a list of open days on schedule for each offspring. By the way, the unity of the Yao clan is very tight. If the descendants who finally get the entire map betray the other descendants and take away the treasure, they will be sanctioned by the clan. The sanctions are so horrifying that it is virtually impossible for their descendants to actually carry away the treasure. Input The input consists of multiple datasets. Each dataset consists of multiple rows. The first line contains the integer n (1 <n <= 50), which represents the number of people with a piece of the map. The next n lines contain the schedule for each descendant. Line i represents the schedule of the i-th descendant, with some integers separated by a single character space. The first integer fi (0 <= fi <= 30) is an integer that represents the number of days that the descendant's schedule is free. The following fi integers represent dates when the schedule is free. These dates differ from each other and are all greater than or equal to 1 and less than or equal to 30. There is one line containing only 0 at the end of the input. Output Print one integer on one line for each dataset. If you can collect the map within 30 days, output the minimum number of days required to collect the map, otherwise output -1. Addendum: The above "minimum number of days required to collect maps" means the date when all maps are collected earliest starting from one day. Example Input 4 1 1 2 2 3 2 1 2 3 3 4 5 0 Output 3
instruction
0
96,020
4
192,040
"Correct Solution: ``` import heapq while True: N = int(input()) if not N: break f = [0] * N for i in range(N): f[i] = list(map(int,input().split()[1:])) dp = [ [0] * 51 for i in range(51) ] for i in range(N): for j in range(N): dp[j][i] = 1<<i for i in range(1,31): ds = [ j for j in range(N) if i in f[j]] for d1 in ds: for d2 in ds: dp[i][d1] |= dp[i-1][d2] for j in range(N): dp[i][j] |= dp[i-1][j] ans = 40 for i in range(31): for j in range(N): if dp[i][j] == (1<<N)-1: ans = min( (ans,i) ) if ans > 30: print(-1) else: print(ans) ```
output
1
96,020
4
192,041
Provide a correct Python 3 solution for this coding contest problem. It is said that a legendary treasure left by Mr. Yao is sleeping somewhere in Hachioji long ago. The treasure map, which is said to show its whereabouts, has been handed down by Yao's n descendants, divided into several pieces. Now, the descendants of Mr. Yao were trying to cooperate to obtain the treasure. However, the treasure cannot be found only by a part of the treasure map that points to the location of the treasure. Therefore, all the descendants of Mr. Yao gathered and tried to collect the map in one place. However, even if I tried to put it into practice, I couldn't get together because I couldn't meet the schedule. However, this information about the treasure is valuable information that has been secretly passed down in the clan. Considering the risk of leakage, exchanging maps using public communication means is out of the question. Therefore, I decided to collect the map for one descendant by repeating the process of meeting the descendants in person and handing over the map. There is no limit to the number of people that one person can meet in a day, but it is necessary that there is a schedule for each other. Your job is to write a program that asks for at least how many days it will take to collect a map from a list of open days on schedule for each offspring. By the way, the unity of the Yao clan is very tight. If the descendants who finally get the entire map betray the other descendants and take away the treasure, they will be sanctioned by the clan. The sanctions are so horrifying that it is virtually impossible for their descendants to actually carry away the treasure. Input The input consists of multiple datasets. Each dataset consists of multiple rows. The first line contains the integer n (1 <n <= 50), which represents the number of people with a piece of the map. The next n lines contain the schedule for each descendant. Line i represents the schedule of the i-th descendant, with some integers separated by a single character space. The first integer fi (0 <= fi <= 30) is an integer that represents the number of days that the descendant's schedule is free. The following fi integers represent dates when the schedule is free. These dates differ from each other and are all greater than or equal to 1 and less than or equal to 30. There is one line containing only 0 at the end of the input. Output Print one integer on one line for each dataset. If you can collect the map within 30 days, output the minimum number of days required to collect the map, otherwise output -1. Addendum: The above "minimum number of days required to collect maps" means the date when all maps are collected earliest starting from one day. Example Input 4 1 1 2 2 3 2 1 2 3 3 4 5 0 Output 3
instruction
0
96,021
4
192,042
"Correct Solution: ``` import sys from collections import deque,defaultdict def bfs(s): bfs_map = defaultdict(lambda : 1) bfs_map[s] = 0 q = deque([s]) b = defaultdict(lambda : 0) b[s[0]] = 1 while q: x = q.popleft() for y in v[x]: if bfs_map[y]: bfs_map[y] = 0 q.append(y) b[y[0]] = 1 for i in range(n): if not b[i]: return 0 return 1 while 1: n = int(sys.stdin.readline()) if n == 0: break T = [[] for i in range(30)] v = defaultdict(list) for i in range(n): s = list(map(int, sys.stdin.readline()[:-1].split())) t = s[1:] t.sort() for j in t: T[j-1].append(i) for j in range(1,s[0]): v[(i,t[j]-1)].append((i,t[j-1]-1)) f = 1 for t in range(30): for i in range(len(T[t])-1): x = T[t][i] y = T[t][i+1] v[(x,t)].append((y,t)) v[(y,t)].append((x,t)) for t in range(30): if T[t]: if bfs((T[t][0],t)): f = 0 print(t+1) break if not f: break if f: print(-1) ```
output
1
96,021
4
192,043
Provide a correct Python 3 solution for this coding contest problem. It is said that a legendary treasure left by Mr. Yao is sleeping somewhere in Hachioji long ago. The treasure map, which is said to show its whereabouts, has been handed down by Yao's n descendants, divided into several pieces. Now, the descendants of Mr. Yao were trying to cooperate to obtain the treasure. However, the treasure cannot be found only by a part of the treasure map that points to the location of the treasure. Therefore, all the descendants of Mr. Yao gathered and tried to collect the map in one place. However, even if I tried to put it into practice, I couldn't get together because I couldn't meet the schedule. However, this information about the treasure is valuable information that has been secretly passed down in the clan. Considering the risk of leakage, exchanging maps using public communication means is out of the question. Therefore, I decided to collect the map for one descendant by repeating the process of meeting the descendants in person and handing over the map. There is no limit to the number of people that one person can meet in a day, but it is necessary that there is a schedule for each other. Your job is to write a program that asks for at least how many days it will take to collect a map from a list of open days on schedule for each offspring. By the way, the unity of the Yao clan is very tight. If the descendants who finally get the entire map betray the other descendants and take away the treasure, they will be sanctioned by the clan. The sanctions are so horrifying that it is virtually impossible for their descendants to actually carry away the treasure. Input The input consists of multiple datasets. Each dataset consists of multiple rows. The first line contains the integer n (1 <n <= 50), which represents the number of people with a piece of the map. The next n lines contain the schedule for each descendant. Line i represents the schedule of the i-th descendant, with some integers separated by a single character space. The first integer fi (0 <= fi <= 30) is an integer that represents the number of days that the descendant's schedule is free. The following fi integers represent dates when the schedule is free. These dates differ from each other and are all greater than or equal to 1 and less than or equal to 30. There is one line containing only 0 at the end of the input. Output Print one integer on one line for each dataset. If you can collect the map within 30 days, output the minimum number of days required to collect the map, otherwise output -1. Addendum: The above "minimum number of days required to collect maps" means the date when all maps are collected earliest starting from one day. Example Input 4 1 1 2 2 3 2 1 2 3 3 4 5 0 Output 3
instruction
0
96,022
4
192,044
"Correct Solution: ``` MAX_N = 50 MAX_DAY = 30 def solve(n, f): dp = [[set() for j in range(n)] for i in range(MAX_DAY + 1)] for i in range(n): dp[0][i].add(i) for d in range(1, MAX_DAY + 1): # for line in dp[:5]: # print(line) for i in range(n): dp[d][i] |= dp[d - 1][i] for j in range(n): if f[d][i] and f[d][j]: dp[d][i] |= dp[d - 1][j] if len(dp[d][i]) == n: return d return -1 ###################################### while True: n = int(input()) if n == 0: exit() f = [[False] * n for i in range(MAX_DAY + 1)] for i in range(n): _, *li = map(int, input().split()) for x in li: f[x][i] = True # for line in f: # print(line) print(solve(n, f)) ```
output
1
96,022
4
192,045
Provide a correct Python 3 solution for this coding contest problem. It is said that a legendary treasure left by Mr. Yao is sleeping somewhere in Hachioji long ago. The treasure map, which is said to show its whereabouts, has been handed down by Yao's n descendants, divided into several pieces. Now, the descendants of Mr. Yao were trying to cooperate to obtain the treasure. However, the treasure cannot be found only by a part of the treasure map that points to the location of the treasure. Therefore, all the descendants of Mr. Yao gathered and tried to collect the map in one place. However, even if I tried to put it into practice, I couldn't get together because I couldn't meet the schedule. However, this information about the treasure is valuable information that has been secretly passed down in the clan. Considering the risk of leakage, exchanging maps using public communication means is out of the question. Therefore, I decided to collect the map for one descendant by repeating the process of meeting the descendants in person and handing over the map. There is no limit to the number of people that one person can meet in a day, but it is necessary that there is a schedule for each other. Your job is to write a program that asks for at least how many days it will take to collect a map from a list of open days on schedule for each offspring. By the way, the unity of the Yao clan is very tight. If the descendants who finally get the entire map betray the other descendants and take away the treasure, they will be sanctioned by the clan. The sanctions are so horrifying that it is virtually impossible for their descendants to actually carry away the treasure. Input The input consists of multiple datasets. Each dataset consists of multiple rows. The first line contains the integer n (1 <n <= 50), which represents the number of people with a piece of the map. The next n lines contain the schedule for each descendant. Line i represents the schedule of the i-th descendant, with some integers separated by a single character space. The first integer fi (0 <= fi <= 30) is an integer that represents the number of days that the descendant's schedule is free. The following fi integers represent dates when the schedule is free. These dates differ from each other and are all greater than or equal to 1 and less than or equal to 30. There is one line containing only 0 at the end of the input. Output Print one integer on one line for each dataset. If you can collect the map within 30 days, output the minimum number of days required to collect the map, otherwise output -1. Addendum: The above "minimum number of days required to collect maps" means the date when all maps are collected earliest starting from one day. Example Input 4 1 1 2 2 3 2 1 2 3 3 4 5 0 Output 3
instruction
0
96,023
4
192,046
"Correct Solution: ``` def solve(n, meetables): mets = [set() for _ in range(n)] for d, meetable in enumerate(meetables[1:]): today = meetable.copy() for i in meetable: today.update(mets[i]) mets[i] = today if len(today) == n: return d + 1 return -1 while True: n = int(input()) if not n: break meetables = [set() for _ in range(31)] for i in range(n): for d in map(int, input().split()[1:]): meetables[d].add(i) print(solve(n, meetables)) ```
output
1
96,023
4
192,047
Provide a correct Python 3 solution for this coding contest problem. It is said that a legendary treasure left by Mr. Yao is sleeping somewhere in Hachioji long ago. The treasure map, which is said to show its whereabouts, has been handed down by Yao's n descendants, divided into several pieces. Now, the descendants of Mr. Yao were trying to cooperate to obtain the treasure. However, the treasure cannot be found only by a part of the treasure map that points to the location of the treasure. Therefore, all the descendants of Mr. Yao gathered and tried to collect the map in one place. However, even if I tried to put it into practice, I couldn't get together because I couldn't meet the schedule. However, this information about the treasure is valuable information that has been secretly passed down in the clan. Considering the risk of leakage, exchanging maps using public communication means is out of the question. Therefore, I decided to collect the map for one descendant by repeating the process of meeting the descendants in person and handing over the map. There is no limit to the number of people that one person can meet in a day, but it is necessary that there is a schedule for each other. Your job is to write a program that asks for at least how many days it will take to collect a map from a list of open days on schedule for each offspring. By the way, the unity of the Yao clan is very tight. If the descendants who finally get the entire map betray the other descendants and take away the treasure, they will be sanctioned by the clan. The sanctions are so horrifying that it is virtually impossible for their descendants to actually carry away the treasure. Input The input consists of multiple datasets. Each dataset consists of multiple rows. The first line contains the integer n (1 <n <= 50), which represents the number of people with a piece of the map. The next n lines contain the schedule for each descendant. Line i represents the schedule of the i-th descendant, with some integers separated by a single character space. The first integer fi (0 <= fi <= 30) is an integer that represents the number of days that the descendant's schedule is free. The following fi integers represent dates when the schedule is free. These dates differ from each other and are all greater than or equal to 1 and less than or equal to 30. There is one line containing only 0 at the end of the input. Output Print one integer on one line for each dataset. If you can collect the map within 30 days, output the minimum number of days required to collect the map, otherwise output -1. Addendum: The above "minimum number of days required to collect maps" means the date when all maps are collected earliest starting from one day. Example Input 4 1 1 2 2 3 2 1 2 3 3 4 5 0 Output 3
instruction
0
96,024
4
192,048
"Correct Solution: ``` from collections import defaultdict,deque import sys,heapq,bisect,math,itertools,string,queue,copy,time sys.setrecursionlimit(10**8) INF = float('inf') mod = 10**9+7 eps = 10**-7 def inp(): return int(input()) def inpl(): return list(map(int, input().split())) def inpl_str(): return list(input().split()) def c(n,d): return n+d*N def dfs(s,n): global visited visited[s][n] = True for t in lines[s]: if not visited[t][n]: dfs(t,n) while True: N = inp() if N == 0: break else: days = 30 nds = [[False]*days for _ in range(N)] for n in range(N): tmpl = inpl() for i in range(1,tmpl[0]+1): nds[n][tmpl[i]-1] = True lines = defaultdict(set) cnt = 0 for n in range(N): for d1 in range(days): for d2 in range(d1,days): if nds[n][d1] and nds[n][d2]: lines[c(n,d1)].add(c(n,d2)) for d in range(days): for n1 in range(N): for n2 in range(n1,N): if nds[n1][d] and nds[n2][d]: lines[c(n1,d)].add(c(n2,d)) lines[c(n2,d)].add(c(n1,d)) visited = [[False]*N for _ in range(c(N,days))] for n in range(N): for d in range(days): if nds[n][d]: dfs(c(n,d),n) #print(visited) for b in range(N*days): for n in range(N): #print(b,n,visited[b][n]) if visited[b][n]: continue else: break else: print(b//N+1) break else: print(-1) ```
output
1
96,024
4
192,049
Provide a correct Python 3 solution for this coding contest problem. It is said that a legendary treasure left by Mr. Yao is sleeping somewhere in Hachioji long ago. The treasure map, which is said to show its whereabouts, has been handed down by Yao's n descendants, divided into several pieces. Now, the descendants of Mr. Yao were trying to cooperate to obtain the treasure. However, the treasure cannot be found only by a part of the treasure map that points to the location of the treasure. Therefore, all the descendants of Mr. Yao gathered and tried to collect the map in one place. However, even if I tried to put it into practice, I couldn't get together because I couldn't meet the schedule. However, this information about the treasure is valuable information that has been secretly passed down in the clan. Considering the risk of leakage, exchanging maps using public communication means is out of the question. Therefore, I decided to collect the map for one descendant by repeating the process of meeting the descendants in person and handing over the map. There is no limit to the number of people that one person can meet in a day, but it is necessary that there is a schedule for each other. Your job is to write a program that asks for at least how many days it will take to collect a map from a list of open days on schedule for each offspring. By the way, the unity of the Yao clan is very tight. If the descendants who finally get the entire map betray the other descendants and take away the treasure, they will be sanctioned by the clan. The sanctions are so horrifying that it is virtually impossible for their descendants to actually carry away the treasure. Input The input consists of multiple datasets. Each dataset consists of multiple rows. The first line contains the integer n (1 <n <= 50), which represents the number of people with a piece of the map. The next n lines contain the schedule for each descendant. Line i represents the schedule of the i-th descendant, with some integers separated by a single character space. The first integer fi (0 <= fi <= 30) is an integer that represents the number of days that the descendant's schedule is free. The following fi integers represent dates when the schedule is free. These dates differ from each other and are all greater than or equal to 1 and less than or equal to 30. There is one line containing only 0 at the end of the input. Output Print one integer on one line for each dataset. If you can collect the map within 30 days, output the minimum number of days required to collect the map, otherwise output -1. Addendum: The above "minimum number of days required to collect maps" means the date when all maps are collected earliest starting from one day. Example Input 4 1 1 2 2 3 2 1 2 3 3 4 5 0 Output 3
instruction
0
96,025
4
192,050
"Correct Solution: ``` MAX_N = 50 MAX_DAY = 30 def solve(n, f): dp = [{i} for i in range(n)] for d in range(1, MAX_DAY + 1): for i in range(n): for j in range(n): if f[d][i] and f[d][j]: dp[i] |= dp[j] if len(dp[i]) == n: return d return -1 ###################################### while True: n = int(input()) if n == 0: exit() f = [[False] * n for i in range(MAX_DAY + 1)] for i in range(n): _, *li = map(int, input().split()) for x in li: f[x][i] = True print(solve(n, f)) ```
output
1
96,025
4
192,051