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
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. Constraints * S is a string that represents a valid date in the year 2019 in the `yyyy/mm/dd` format. Input Input is given from Standard Input in the following format: S Output Print `Heisei` if the date represented by S is not later than April 30, 2019, and print `TBD` otherwise. Examples Input 2019/04/30 Output Heisei Input 2019/11/01 Output TBD Submitted Solution: ``` # Your code here! ans = input().split("/") for i in range(3): ans[i] =int(ans[i]) if ans[0]==2019 and ans[1]>=5: print("TDB") else: print("Heisei") if ans[0]>2019: print("TDB") ```
instruction
0
92,462
4
184,924
No
output
1
92,462
4
184,925
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. Constraints * S is a string that represents a valid date in the year 2019 in the `yyyy/mm/dd` format. Input Input is given from Standard Input in the following format: S Output Print `Heisei` if the date represented by S is not later than April 30, 2019, and print `TBD` otherwise. Examples Input 2019/04/30 Output Heisei Input 2019/11/01 Output TBD Submitted Solution: ``` def main() -> None: S = input() Y, M, D = S.split("/") if int(Y) >= 2019 and int(M) <= 4: print("HEISEI") else: print("TBD") if __name__ == '__main__': main() ```
instruction
0
92,463
4
184,926
No
output
1
92,463
4
184,927
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.) Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise. Constraints * S is a string that represents a valid date in the year 2019 in the `yyyy/mm/dd` format. Input Input is given from Standard Input in the following format: S Output Print `Heisei` if the date represented by S is not later than April 30, 2019, and print `TBD` otherwise. Examples Input 2019/04/30 Output Heisei Input 2019/11/01 Output TBD Submitted Solution: ``` s=input() s = s.split("/") if s[0] < 2019: print("Heisei") if s[0] == 2019 and s[0]<= 4: print("Heisei") else: print("TBD") ```
instruction
0
92,464
4
184,928
No
output
1
92,464
4
184,929
Provide tags and a correct Python 3 solution for this coding contest problem. What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until... Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" β€” thought Petya. He know for a fact that if he fulfills the parents' task in the i-th (1 ≀ i ≀ 12) month of the year, then the flower will grow by ai centimeters, and if he doesn't water the flower in the i-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by k centimeters. Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by k centimeters. Input The first line contains exactly one integer k (0 ≀ k ≀ 100). The next line contains twelve space-separated integers: the i-th (1 ≀ i ≀ 12) number in the line represents ai (0 ≀ ai ≀ 100). Output Print the only integer β€” the minimum number of months when Petya has to water the flower so that the flower grows no less than by k centimeters. If the flower can't grow by k centimeters in a year, print -1. Examples Input 5 1 1 1 1 2 2 3 2 2 1 1 1 Output 2 Input 0 0 0 0 0 0 0 0 1 1 2 3 0 Output 0 Input 11 1 1 4 1 1 5 1 1 4 1 1 1 Output 3 Note Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters. In the second sample Petya's parents will believe him even if the flower doesn't grow at all (k = 0). So, it is possible for Petya not to water the flower at all.
instruction
0
92,866
4
185,732
Tags: greedy, implementation, sortings Correct Solution: ``` # -*- coding: utf-8 -*- """ Created on Wed Apr 15 15:11:16 2020 @author: DELL """ k=int(input()) l=list(map(int,input().split())) l.sort() c=0 u=0 o=False for i in range(len(l)-1,-1,-1): i=l[i] if c>=k: o=True break c+=i u+=1 if o or c>=k: print(u) else: print(-1) ```
output
1
92,866
4
185,733
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until... Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" β€” thought Petya. He know for a fact that if he fulfills the parents' task in the i-th (1 ≀ i ≀ 12) month of the year, then the flower will grow by ai centimeters, and if he doesn't water the flower in the i-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by k centimeters. Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by k centimeters. Input The first line contains exactly one integer k (0 ≀ k ≀ 100). The next line contains twelve space-separated integers: the i-th (1 ≀ i ≀ 12) number in the line represents ai (0 ≀ ai ≀ 100). Output Print the only integer β€” the minimum number of months when Petya has to water the flower so that the flower grows no less than by k centimeters. If the flower can't grow by k centimeters in a year, print -1. Examples Input 5 1 1 1 1 2 2 3 2 2 1 1 1 Output 2 Input 0 0 0 0 0 0 0 0 1 1 2 3 0 Output 0 Input 11 1 1 4 1 1 5 1 1 4 1 1 1 Output 3 Note Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters. In the second sample Petya's parents will believe him even if the flower doesn't grow at all (k = 0). So, it is possible for Petya not to water the flower at all. Submitted Solution: ``` #ashu@gate22 k=int(input()) l=list(map(int,input().split())) l.sort(reverse=True) if k==0: print("0") else: s=0 no=0 while (s<k and no<len(l)): s+=l[no] no+=1 if s<k: print("-1") else: print(no) ```
instruction
0
92,873
4
185,746
Yes
output
1
92,873
4
185,747
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until... Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" β€” thought Petya. He know for a fact that if he fulfills the parents' task in the i-th (1 ≀ i ≀ 12) month of the year, then the flower will grow by ai centimeters, and if he doesn't water the flower in the i-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by k centimeters. Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by k centimeters. Input The first line contains exactly one integer k (0 ≀ k ≀ 100). The next line contains twelve space-separated integers: the i-th (1 ≀ i ≀ 12) number in the line represents ai (0 ≀ ai ≀ 100). Output Print the only integer β€” the minimum number of months when Petya has to water the flower so that the flower grows no less than by k centimeters. If the flower can't grow by k centimeters in a year, print -1. Examples Input 5 1 1 1 1 2 2 3 2 2 1 1 1 Output 2 Input 0 0 0 0 0 0 0 0 1 1 2 3 0 Output 0 Input 11 1 1 4 1 1 5 1 1 4 1 1 1 Output 3 Note Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters. In the second sample Petya's parents will believe him even if the flower doesn't grow at all (k = 0). So, it is possible for Petya not to water the flower at all. Submitted Solution: ``` k = int(input()) a = input().split() for i in range(len(a)): a[i] = int(a[i]) a.sort(reverse=True) m = 0 c = 0 for i in a: if m >= k: break m += int(i) c += 1 if m < k: c = -1 print(c) ```
instruction
0
92,874
4
185,748
Yes
output
1
92,874
4
185,749
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until... Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" β€” thought Petya. He know for a fact that if he fulfills the parents' task in the i-th (1 ≀ i ≀ 12) month of the year, then the flower will grow by ai centimeters, and if he doesn't water the flower in the i-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by k centimeters. Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by k centimeters. Input The first line contains exactly one integer k (0 ≀ k ≀ 100). The next line contains twelve space-separated integers: the i-th (1 ≀ i ≀ 12) number in the line represents ai (0 ≀ ai ≀ 100). Output Print the only integer β€” the minimum number of months when Petya has to water the flower so that the flower grows no less than by k centimeters. If the flower can't grow by k centimeters in a year, print -1. Examples Input 5 1 1 1 1 2 2 3 2 2 1 1 1 Output 2 Input 0 0 0 0 0 0 0 0 1 1 2 3 0 Output 0 Input 11 1 1 4 1 1 5 1 1 4 1 1 1 Output 3 Note Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters. In the second sample Petya's parents will believe him even if the flower doesn't grow at all (k = 0). So, it is possible for Petya not to water the flower at all. Submitted Solution: ``` k=int(input()) b=sorted(int(i) for i in input().split()) b.reverse() sum=0 if k==0: ans=0 else: ans=-1 for i in range(len(b)): sum+=b[i] if sum>=k: ans=i+1 break print(ans) ```
instruction
0
92,875
4
185,750
Yes
output
1
92,875
4
185,751
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until... Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" β€” thought Petya. He know for a fact that if he fulfills the parents' task in the i-th (1 ≀ i ≀ 12) month of the year, then the flower will grow by ai centimeters, and if he doesn't water the flower in the i-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by k centimeters. Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by k centimeters. Input The first line contains exactly one integer k (0 ≀ k ≀ 100). The next line contains twelve space-separated integers: the i-th (1 ≀ i ≀ 12) number in the line represents ai (0 ≀ ai ≀ 100). Output Print the only integer β€” the minimum number of months when Petya has to water the flower so that the flower grows no less than by k centimeters. If the flower can't grow by k centimeters in a year, print -1. Examples Input 5 1 1 1 1 2 2 3 2 2 1 1 1 Output 2 Input 0 0 0 0 0 0 0 0 1 1 2 3 0 Output 0 Input 11 1 1 4 1 1 5 1 1 4 1 1 1 Output 3 Note Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters. In the second sample Petya's parents will believe him even if the flower doesn't grow at all (k = 0). So, it is possible for Petya not to water the flower at all. Submitted Solution: ``` k=int(input());l=sorted(list(map(int,input().split())));count=0 while k>0 and count<12:k-=l[-1];l.remove(l[-1]);count+=1 if k<=0:print(count) else:print("-1") ```
instruction
0
92,876
4
185,752
Yes
output
1
92,876
4
185,753
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until... Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" β€” thought Petya. He know for a fact that if he fulfills the parents' task in the i-th (1 ≀ i ≀ 12) month of the year, then the flower will grow by ai centimeters, and if he doesn't water the flower in the i-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by k centimeters. Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by k centimeters. Input The first line contains exactly one integer k (0 ≀ k ≀ 100). The next line contains twelve space-separated integers: the i-th (1 ≀ i ≀ 12) number in the line represents ai (0 ≀ ai ≀ 100). Output Print the only integer β€” the minimum number of months when Petya has to water the flower so that the flower grows no less than by k centimeters. If the flower can't grow by k centimeters in a year, print -1. Examples Input 5 1 1 1 1 2 2 3 2 2 1 1 1 Output 2 Input 0 0 0 0 0 0 0 0 1 1 2 3 0 Output 0 Input 11 1 1 4 1 1 5 1 1 4 1 1 1 Output 3 Note Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters. In the second sample Petya's parents will believe him even if the flower doesn't grow at all (k = 0). So, it is possible for Petya not to water the flower at all. Submitted Solution: ``` R = lambda:list(map(int,input().split())) k = int(input()) a = R() a.sort(reverse=True) z = 0 i = 0 while (z < k and i < 12): z += a[i] i += 1 if i == 12: print(-1) else: print(i) ```
instruction
0
92,877
4
185,754
No
output
1
92,877
4
185,755
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until... Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" β€” thought Petya. He know for a fact that if he fulfills the parents' task in the i-th (1 ≀ i ≀ 12) month of the year, then the flower will grow by ai centimeters, and if he doesn't water the flower in the i-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by k centimeters. Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by k centimeters. Input The first line contains exactly one integer k (0 ≀ k ≀ 100). The next line contains twelve space-separated integers: the i-th (1 ≀ i ≀ 12) number in the line represents ai (0 ≀ ai ≀ 100). Output Print the only integer β€” the minimum number of months when Petya has to water the flower so that the flower grows no less than by k centimeters. If the flower can't grow by k centimeters in a year, print -1. Examples Input 5 1 1 1 1 2 2 3 2 2 1 1 1 Output 2 Input 0 0 0 0 0 0 0 0 1 1 2 3 0 Output 0 Input 11 1 1 4 1 1 5 1 1 4 1 1 1 Output 3 Note Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters. In the second sample Petya's parents will believe him even if the flower doesn't grow at all (k = 0). So, it is possible for Petya not to water the flower at all. Submitted Solution: ``` k = int(input()) a = sorted(map(int,input().split())) r = 0 g = 0 i = 0 while g < k: if i == 11: print("-1") exit() g += a[i] r += 1 print(r) ```
instruction
0
92,878
4
185,756
No
output
1
92,878
4
185,757
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until... Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" β€” thought Petya. He know for a fact that if he fulfills the parents' task in the i-th (1 ≀ i ≀ 12) month of the year, then the flower will grow by ai centimeters, and if he doesn't water the flower in the i-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by k centimeters. Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by k centimeters. Input The first line contains exactly one integer k (0 ≀ k ≀ 100). The next line contains twelve space-separated integers: the i-th (1 ≀ i ≀ 12) number in the line represents ai (0 ≀ ai ≀ 100). Output Print the only integer β€” the minimum number of months when Petya has to water the flower so that the flower grows no less than by k centimeters. If the flower can't grow by k centimeters in a year, print -1. Examples Input 5 1 1 1 1 2 2 3 2 2 1 1 1 Output 2 Input 0 0 0 0 0 0 0 0 1 1 2 3 0 Output 0 Input 11 1 1 4 1 1 5 1 1 4 1 1 1 Output 3 Note Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters. In the second sample Petya's parents will believe him even if the flower doesn't grow at all (k = 0). So, it is possible for Petya not to water the flower at all. Submitted Solution: ``` k = int(input()) li = [int(x) for x in input().split()] f = False if k==0: print('0') f = True ct = 0 sum = 0 li.sort(reverse=True) flag = False for i in range(11,-1,-1): if i<12 and i>-1: sum += li[i] else: f = False break ct += 1 if sum>=k: f = True print(ct) break if not f: print('-1') ```
instruction
0
92,879
4
185,758
No
output
1
92,879
4
185,759
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until... Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" β€” thought Petya. He know for a fact that if he fulfills the parents' task in the i-th (1 ≀ i ≀ 12) month of the year, then the flower will grow by ai centimeters, and if he doesn't water the flower in the i-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by k centimeters. Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by k centimeters. Input The first line contains exactly one integer k (0 ≀ k ≀ 100). The next line contains twelve space-separated integers: the i-th (1 ≀ i ≀ 12) number in the line represents ai (0 ≀ ai ≀ 100). Output Print the only integer β€” the minimum number of months when Petya has to water the flower so that the flower grows no less than by k centimeters. If the flower can't grow by k centimeters in a year, print -1. Examples Input 5 1 1 1 1 2 2 3 2 2 1 1 1 Output 2 Input 0 0 0 0 0 0 0 0 1 1 2 3 0 Output 0 Input 11 1 1 4 1 1 5 1 1 4 1 1 1 Output 3 Note Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters. In the second sample Petya's parents will believe him even if the flower doesn't grow at all (k = 0). So, it is possible for Petya not to water the flower at all. Submitted Solution: ``` k = int(input()) arr = [int(y) for y in input().split()] arr.sort() month_count = 0 for i in range(12): k -= arr[::-1][i] month_count += 1 if k <= 0: break print(month_count) ```
instruction
0
92,880
4
185,760
No
output
1
92,880
4
185,761
Provide tags and a correct Python 3 solution for this coding contest problem. Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
instruction
0
93,051
4
186,102
Tags: greedy, sortings Correct Solution: ``` #!/usr/bin/env python3 import atexit import io import sys _I_B = sys.stdin.read().splitlines() input = iter(_I_B).__next__ _O_B = io.StringIO() sys.stdout = _O_B @atexit.register def write(): sys.__stdout__.write(_O_B.getvalue()) class new_tuple(tuple): def __lt__(a,b): if a[0]>b[0]: return False elif a[0]<b[0]: return True else: if a[1]>b[1]: return False elif a[1]<b[1]: return True else: return False def __gt__(a,b): if a[0]<b[0]: return False elif a[0]>b[0]: return True else: if a[1]<b[1]: return False elif a[1]>b[1]: return True else: return False def main(): n=int(input()) a=list() b=list() for _ in range(n): x,y=map(int,input().split()) b.append(x) a.append(new_tuple((y,x))) for _ in range(n): a.append(new_tuple((a[_][1],a[_][1]))) a.sort() b.sort() # print(b,"\n",a) i=0 for _ in b: while a[i][1]!=_: i+=1 i+=1 print(a[i-1][0]) if __name__=='__main__': main() ```
output
1
93,051
4
186,103
Provide tags and a correct Python 3 solution for this coding contest problem. Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
instruction
0
93,052
4
186,104
Tags: greedy, sortings Correct Solution: ``` n = int(input()) listd = [] res = 0 for i in range(n): listd.append(tuple(map(int, input().split()))) listd.sort() for a, b in listd: res = b if res<=b else a print(res) ```
output
1
93,052
4
186,105
Provide tags and a correct Python 3 solution for this coding contest problem. Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
instruction
0
93,053
4
186,106
Tags: greedy, sortings Correct Solution: ``` n=int(input()) a=() b=() for i in range(n): c=tuple(map(int,input().split())) a+=(c[0],) b+=(c[1],) c,e=0,0 a=list(a) b=list(b) for i in range(n): d=a.index(min(a)) if a[d]==e: c=max(c,b[d]) del b[d] del a[d] else: e=a[d] if b[d]<c: c=a[d] del b[d] del a[d] else: c=b[d] del b[d] del a[d] print(c) ```
output
1
93,053
4
186,107
Provide tags and a correct Python 3 solution for this coding contest problem. Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
instruction
0
93,054
4
186,108
Tags: greedy, sortings Correct Solution: ``` # -*- coding: utf-8 -*- """ Created on Thu Jul 16 19:50:21 2020 @author: user """ n = int(input()) l=[] for _ in range(n): l.append(list(map(int, input().split()))) l=sorted(l) #ls = sorted([list(map(int, input().split())) for _ in range(n)]) #print(sorted(ls)) t=min(l[0]) for i in range(1,n): a=min(l[i]) if(a>=t): t=a else: t=max(l[i]) print(t) ```
output
1
93,054
4
186,109
Provide tags and a correct Python 3 solution for this coding contest problem. Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
instruction
0
93,055
4
186,110
Tags: greedy, sortings Correct Solution: ``` from operator import itemgetter n = int(input()) t = sorted((tuple(map(int, input().split())) for i in range(n)), key=itemgetter(0, 1)) last = 0 for el in t: if last <= min(el[0], el[1]): last = min(el[0], el[1]) else: last = max(el[0], el[1]) print(last) ```
output
1
93,055
4
186,111
Provide tags and a correct Python 3 solution for this coding contest problem. Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
instruction
0
93,056
4
186,112
Tags: greedy, sortings Correct Solution: ``` l=[] for i in range(int(input())): l+=[list(map(int,input().split()))] l.sort(key=lambda x:(x[0],x[1])) d=0 for i in l: if i[1]>=d: d=i[1] else: d=i[0] print(d) ```
output
1
93,056
4
186,113
Provide tags and a correct Python 3 solution for this coding contest problem. Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
instruction
0
93,057
4
186,114
Tags: greedy, sortings Correct Solution: ``` n=int(input()) l=[] for i in range(n): a,b=map(int,input().split()) l.append((a,b)) l.sort() out=0 for i in l: if out<=i[1]: out=i[1] else: out=i[0] print(out) ```
output
1
93,057
4
186,115
Provide tags and a correct Python 3 solution for this coding contest problem. Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
instruction
0
93,058
4
186,116
Tags: greedy, sortings Correct Solution: ``` n=int(input()) l=[] for j in range(0,n): a,b=map(int,input().split()) l.append((a,b)) l1=sorted(l,key=lambda x: x[1]) l2=sorted(l1,key=lambda x: x[0]) c=0 best=-1 for k in l2: if(best<=k[1]): best=k[1] else: best=k[0] #print(best) print(best) ```
output
1
93,058
4
186,117
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. Submitted Solution: ``` n=int(input()) a=[] for i in range (0,n): x,y=input().split() x=int(x) y=int(y) a.append([x,y]) a = sorted(a, key = lambda x: (x[0], x[1])) b=-1 for i in range (0,n): if(a[i][1]>=b): b=a[i][1] else: b=a[i][0] print(b) ```
instruction
0
93,059
4
186,118
Yes
output
1
93,059
4
186,119
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. Submitted Solution: ``` n = int(input()) date = [] for _ in range(n): d = input() d = d.split() d = list(map(lambda x: int(x), d)) date.append(d) date.sort() last_date = date[-1] last_date_a = last_date[0] last_date_b = last_date[-1] date_check = 0 for d in date: if d[-1]>=date_check: date_check=d[-1] elif d[0]>date_check: date_check=d[0] print(date_check) ```
instruction
0
93,060
4
186,120
Yes
output
1
93,060
4
186,121
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. Submitted Solution: ``` def solve(date): date=sorted(date) currentDate=date[0][1] for i in range(1,len(date)): if date[i][1]<currentDate: currentDate=date[i][0] else: currentDate=date[i][1] print(currentDate) def main(): n=int(input()) date=[] for i in range(n): x,y=list(map(int,input().split())) date.append((x,y)) solve(date) if __name__ == "__main__": main() ```
instruction
0
93,061
4
186,122
Yes
output
1
93,061
4
186,123
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. Submitted Solution: ``` n = int(input()) A = [] for i in range(n): a,b = map(int,input().split(' ')) A.append((a,b)) A = sorted(A, key = lambda x : (x[0],x[1])) cd = A[0][1] #print(A) for i in range(1,n): if A[i][1]>=cd: cd = A[i][1] else: cd = A[i][0] print(cd) ```
instruction
0
93,062
4
186,124
Yes
output
1
93,062
4
186,125
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. Submitted Solution: ``` n = int(input()) a = [] for i in range(n): x, y = map(int, input().split()) a.append((x, y)) a.sort() for i in range(1, n): if a[i][1] < a[i - 1][1]: print(a[n - 1][0]) exit() print(a[n - 1][1]) ```
instruction
0
93,063
4
186,126
No
output
1
93,063
4
186,127
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. Submitted Solution: ``` l = int(input()) m = [] for i in range(l): k = input().split() k[0] = int(k[0]) k[1] = int(k[1]) m.append(k) m = sorted(m) maxday = 0 k = len(m) dum = 1 while k > 0 and dum == 1: k -= 1 if k < len(m)-1: if m[i][0] == m[i-1][0]: if maxday == m[i-1][0]: maxday = m[i][0] else: if maxday > m[i][1]: maxday = m[-1][0] dum = 0 else: maxday = m[i][1] else: maxday = m[0][1] print(maxday) ```
instruction
0
93,064
4
186,128
No
output
1
93,064
4
186,129
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. Submitted Solution: ``` import sys import functools sys.setrecursionlimit(100000) n = int(sys.stdin.readline().strip()) arr = [] for i in range(n): arr.append([int(x) for x in sys.stdin.readline().strip().split()]) arr.sort(key = lambda x: x[0]) ma = 0 for i in range(n-1): if arr[i][1]<=arr[i+1][1]: ma = max(ma,arr[i][1]) else: ma = max(ma,arr[i][0]) if n>1: if arr[-1][1]>=arr[-2][1]: ma = max(arr[-1][1],ma) else: ma = max(arr[-1][0],ma) print(ma) if n==1: print(min(arr[0][0],arr[0][1])) ```
instruction
0
93,065
4
186,130
No
output
1
93,065
4
186,131
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. Submitted Solution: ``` n = int(input()) sp = [] for i in range(n): sp.append(list(map(int, input().split(' ')))) sp1 = list(map(lambda x: x[1], sorted(sp))) sp2 = list(map(lambda x: x[1], sorted(sp, key=lambda s: s[1]))) sp3 = list(map(lambda x: x[0], sorted(sp, key=lambda s: s[0]))) sp4 = list(map(lambda x: x[0], sorted(sp))) if sp1 == sp2: print(sp2[len(sp2) - 1]) else: if sp3 == sp4: print(sp2[len(sp2)-1]) else: print(sp3[len(sp3) - 1]) ```
instruction
0
93,066
4
186,132
No
output
1
93,066
4
186,133
Provide tags and a correct Python 3 solution for this coding contest problem. Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down. Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0. As there is no internet in the countryside, Vitya has been watching the moon for n consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has. Input The first line of the input contains a single integer n (1 ≀ n ≀ 92) β€” the number of consecutive days Vitya was watching the size of the visible part of the moon. The second line contains n integers ai (0 ≀ ai ≀ 15) β€” Vitya's records. It's guaranteed that the input data is consistent. Output If Vitya can be sure that the size of visible part of the moon on day n + 1 will be less than the size of the visible part on day n, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1. Examples Input 5 3 4 5 6 7 Output UP Input 7 12 13 14 15 14 13 12 Output DOWN Input 1 8 Output -1 Note In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP". In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN". In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1.
instruction
0
93,147
4
186,294
Tags: implementation Correct Solution: ``` n=int(input()) l=list(map(int,input().split())) if len(l)>1: if l[-1]==15: print('DOWN') elif l[-1]==0: print('UP') elif l[-1]-l[-2]==1: print('UP') elif l[-1]-l[-2]==-1: print('DOWN') else: print(-1) else: if l[-1]==15: print('DOWN') elif l[-1]==0: print('UP') else: print(-1) ```
output
1
93,147
4
186,295
Provide tags and a correct Python 3 solution for this coding contest problem. Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down. Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0. As there is no internet in the countryside, Vitya has been watching the moon for n consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has. Input The first line of the input contains a single integer n (1 ≀ n ≀ 92) β€” the number of consecutive days Vitya was watching the size of the visible part of the moon. The second line contains n integers ai (0 ≀ ai ≀ 15) β€” Vitya's records. It's guaranteed that the input data is consistent. Output If Vitya can be sure that the size of visible part of the moon on day n + 1 will be less than the size of the visible part on day n, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1. Examples Input 5 3 4 5 6 7 Output UP Input 7 12 13 14 15 14 13 12 Output DOWN Input 1 8 Output -1 Note In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP". In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN". In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1.
instruction
0
93,148
4
186,296
Tags: implementation Correct Solution: ``` n = int(input()) a = list(map(int, input().split(" "))) l = a.pop() if l == 15: print("DOWN") elif l == 0: print("UP") else: if n == 1: print(-1) else: p = a.pop() print("UP" if p < l else "DOWN") ```
output
1
93,148
4
186,297
Provide tags and a correct Python 3 solution for this coding contest problem. Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down. Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0. As there is no internet in the countryside, Vitya has been watching the moon for n consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has. Input The first line of the input contains a single integer n (1 ≀ n ≀ 92) β€” the number of consecutive days Vitya was watching the size of the visible part of the moon. The second line contains n integers ai (0 ≀ ai ≀ 15) β€” Vitya's records. It's guaranteed that the input data is consistent. Output If Vitya can be sure that the size of visible part of the moon on day n + 1 will be less than the size of the visible part on day n, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1. Examples Input 5 3 4 5 6 7 Output UP Input 7 12 13 14 15 14 13 12 Output DOWN Input 1 8 Output -1 Note In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP". In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN". In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1.
instruction
0
93,149
4
186,298
Tags: implementation Correct Solution: ``` n = int(input()) d = list(map(int, input().split())) if len(d) < 2: if d[0] == 15: print('DOWN') elif d[0] == 0: print('UP') else: print(-1) else: if d[-1] > d[-2]: if d[-1] == 15: print('DOWN') else: print('UP') elif d[-1] == 0: print('UP') else: print('DOWN') ```
output
1
93,149
4
186,299
Provide tags and a correct Python 3 solution for this coding contest problem. Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down. Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0. As there is no internet in the countryside, Vitya has been watching the moon for n consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has. Input The first line of the input contains a single integer n (1 ≀ n ≀ 92) β€” the number of consecutive days Vitya was watching the size of the visible part of the moon. The second line contains n integers ai (0 ≀ ai ≀ 15) β€” Vitya's records. It's guaranteed that the input data is consistent. Output If Vitya can be sure that the size of visible part of the moon on day n + 1 will be less than the size of the visible part on day n, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1. Examples Input 5 3 4 5 6 7 Output UP Input 7 12 13 14 15 14 13 12 Output DOWN Input 1 8 Output -1 Note In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP". In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN". In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1.
instruction
0
93,150
4
186,300
Tags: implementation Correct Solution: ``` from sys import exit n = int(input()) t = [int(x) for x in input().split()] if n == 1: if t[0] == 15: print("DOWN") elif t[0] == 0: print("UP") else: print(-1) exit() if t[n-1] - t[n-2] > 0: if t[n-1] == 15: print("DOWN") else: print("UP") elif t[n-1] - t[n-2] < 0: if t[n-1] == 0: print("UP") else: print("DOWN") ```
output
1
93,150
4
186,301
Provide tags and a correct Python 3 solution for this coding contest problem. Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down. Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0. As there is no internet in the countryside, Vitya has been watching the moon for n consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has. Input The first line of the input contains a single integer n (1 ≀ n ≀ 92) β€” the number of consecutive days Vitya was watching the size of the visible part of the moon. The second line contains n integers ai (0 ≀ ai ≀ 15) β€” Vitya's records. It's guaranteed that the input data is consistent. Output If Vitya can be sure that the size of visible part of the moon on day n + 1 will be less than the size of the visible part on day n, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1. Examples Input 5 3 4 5 6 7 Output UP Input 7 12 13 14 15 14 13 12 Output DOWN Input 1 8 Output -1 Note In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP". In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN". In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1.
instruction
0
93,151
4
186,302
Tags: implementation Correct Solution: ``` l=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1] input() s=list(map(int,input().split())) if(len(s)==1): if(s[0]==15): print("DOWN") elif(s[0]==0): print("UP") else: print("-1") else: a=s[len(s)-2] b=s[len(s)-1] if(a==1 and b==0): print("UP") elif(a==14 and b==15): print("DOWN") elif(b>a): print("UP") else: print("DOWN") ```
output
1
93,151
4
186,303
Provide tags and a correct Python 3 solution for this coding contest problem. Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down. Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0. As there is no internet in the countryside, Vitya has been watching the moon for n consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has. Input The first line of the input contains a single integer n (1 ≀ n ≀ 92) β€” the number of consecutive days Vitya was watching the size of the visible part of the moon. The second line contains n integers ai (0 ≀ ai ≀ 15) β€” Vitya's records. It's guaranteed that the input data is consistent. Output If Vitya can be sure that the size of visible part of the moon on day n + 1 will be less than the size of the visible part on day n, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1. Examples Input 5 3 4 5 6 7 Output UP Input 7 12 13 14 15 14 13 12 Output DOWN Input 1 8 Output -1 Note In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP". In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN". In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1.
instruction
0
93,152
4
186,304
Tags: implementation Correct Solution: ``` n = int(input()) days = [int(x) for x in input().split()] up = True if n == 1: if days[0] == 0: print("UP") elif days[0] == 15: print("DOWN") else: print(-1) else: yesterday = days[0] for i in range (1, n): today = days[i] if today > yesterday: up = True else: up = False if today == 15 or today == 0: up = not up yesterday = today if up: print("UP") else: print("DOWN") ```
output
1
93,152
4
186,305
Provide tags and a correct Python 3 solution for this coding contest problem. Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down. Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0. As there is no internet in the countryside, Vitya has been watching the moon for n consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has. Input The first line of the input contains a single integer n (1 ≀ n ≀ 92) β€” the number of consecutive days Vitya was watching the size of the visible part of the moon. The second line contains n integers ai (0 ≀ ai ≀ 15) β€” Vitya's records. It's guaranteed that the input data is consistent. Output If Vitya can be sure that the size of visible part of the moon on day n + 1 will be less than the size of the visible part on day n, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1. Examples Input 5 3 4 5 6 7 Output UP Input 7 12 13 14 15 14 13 12 Output DOWN Input 1 8 Output -1 Note In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP". In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN". In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1.
instruction
0
93,153
4
186,306
Tags: implementation Correct Solution: ``` n=int(input()) w=input().split() w=list(w) if n==1: if w[-1]=='15': print('DOWN') elif w[-1]=='0': print('UP') else: print('-1') else: if w[-1]=='15': print('DOWN') elif w[-1]=='0': print('UP') else: if int(w[-1])<int(w[-2]): print('DOWN') elif int(w[-1])>int(w[-2]): print('UP') ```
output
1
93,153
4
186,307
Provide tags and a correct Python 3 solution for this coding contest problem. Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down. Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0. As there is no internet in the countryside, Vitya has been watching the moon for n consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has. Input The first line of the input contains a single integer n (1 ≀ n ≀ 92) β€” the number of consecutive days Vitya was watching the size of the visible part of the moon. The second line contains n integers ai (0 ≀ ai ≀ 15) β€” Vitya's records. It's guaranteed that the input data is consistent. Output If Vitya can be sure that the size of visible part of the moon on day n + 1 will be less than the size of the visible part on day n, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1. Examples Input 5 3 4 5 6 7 Output UP Input 7 12 13 14 15 14 13 12 Output DOWN Input 1 8 Output -1 Note In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP". In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN". In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1.
instruction
0
93,154
4
186,308
Tags: implementation Correct Solution: ``` n = int(input()) t = [int(i) for i in input().split()] if n == 1 and t[n-1] != 0 and t[n-1] != 15: print("-1") if t[n-1] == 15: print("DOWN") if t[n-1] == 0: print("UP") if (t[n-1] > t[n-2]) and t[n-1] != 15: print("UP") if (t[n-1] < t[n-2]) and t[n-1] != 0: print("DOWN") ```
output
1
93,154
4
186,309
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down. Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0. As there is no internet in the countryside, Vitya has been watching the moon for n consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has. Input The first line of the input contains a single integer n (1 ≀ n ≀ 92) β€” the number of consecutive days Vitya was watching the size of the visible part of the moon. The second line contains n integers ai (0 ≀ ai ≀ 15) β€” Vitya's records. It's guaranteed that the input data is consistent. Output If Vitya can be sure that the size of visible part of the moon on day n + 1 will be less than the size of the visible part on day n, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1. Examples Input 5 3 4 5 6 7 Output UP Input 7 12 13 14 15 14 13 12 Output DOWN Input 1 8 Output -1 Note In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP". In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN". In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1. Submitted Solution: ``` n = int(input().strip()) arr = [int(x) for x in input().strip().split(' ')] if n == 1: if arr[0] == 0: print('UP') elif arr[0] == 15: print('DOWN') else: print(-1) else: if arr[n-1] == 0: print('UP') elif arr[n-1] == 15: print('DOWN') else: print('UP' if arr[n-1] > arr[n-2] else 'DOWN') ```
instruction
0
93,155
4
186,310
Yes
output
1
93,155
4
186,311
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down. Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0. As there is no internet in the countryside, Vitya has been watching the moon for n consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has. Input The first line of the input contains a single integer n (1 ≀ n ≀ 92) β€” the number of consecutive days Vitya was watching the size of the visible part of the moon. The second line contains n integers ai (0 ≀ ai ≀ 15) β€” Vitya's records. It's guaranteed that the input data is consistent. Output If Vitya can be sure that the size of visible part of the moon on day n + 1 will be less than the size of the visible part on day n, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1. Examples Input 5 3 4 5 6 7 Output UP Input 7 12 13 14 15 14 13 12 Output DOWN Input 1 8 Output -1 Note In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP". In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN". In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1. Submitted Solution: ``` n = int(input()) l = list(map(int, input().rstrip().split(" "))) if n ==1: if l[0]==0: print("UP") elif l[0]==15: print("DOWN") else: print(-1) else: if l[-1]==15: print("DOWN") elif l[-1]==0: print("UP") elif l[-1]-l[-2]<0: print("DOWN") else: print("UP") ```
instruction
0
93,156
4
186,312
Yes
output
1
93,156
4
186,313
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down. Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0. As there is no internet in the countryside, Vitya has been watching the moon for n consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has. Input The first line of the input contains a single integer n (1 ≀ n ≀ 92) β€” the number of consecutive days Vitya was watching the size of the visible part of the moon. The second line contains n integers ai (0 ≀ ai ≀ 15) β€” Vitya's records. It's guaranteed that the input data is consistent. Output If Vitya can be sure that the size of visible part of the moon on day n + 1 will be less than the size of the visible part on day n, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1. Examples Input 5 3 4 5 6 7 Output UP Input 7 12 13 14 15 14 13 12 Output DOWN Input 1 8 Output -1 Note In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP". In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN". In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1. Submitted Solution: ``` n = int(input()) a = input() A = [] if a == '0' and n == 1: print('UP') elif a == '15' and n == 1: print('DOWN') elif n == 1 and a !='0' and a != '15': print(-1) else: for i in a.split(): A.append(int(i)) if A[-1] == 0: print('UP') elif A[-1] == 15: print('DOWN') else: if A[-1] > A[-2]: print('UP') elif A[-1] < A[-2]: print('DOWN') ```
instruction
0
93,157
4
186,314
Yes
output
1
93,157
4
186,315
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down. Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0. As there is no internet in the countryside, Vitya has been watching the moon for n consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has. Input The first line of the input contains a single integer n (1 ≀ n ≀ 92) β€” the number of consecutive days Vitya was watching the size of the visible part of the moon. The second line contains n integers ai (0 ≀ ai ≀ 15) β€” Vitya's records. It's guaranteed that the input data is consistent. Output If Vitya can be sure that the size of visible part of the moon on day n + 1 will be less than the size of the visible part on day n, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1. Examples Input 5 3 4 5 6 7 Output UP Input 7 12 13 14 15 14 13 12 Output DOWN Input 1 8 Output -1 Note In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP". In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN". In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1. Submitted Solution: ``` N = int(input()) X = list(int(I) for I in (input()).split(' ')) if X[-1]==15: print("DOWN") exit(0) elif X[-1]==0: print("UP") exit(0) else: if len(X)==1: print(-1) exit(0) else: W = X[-1]-X[-2] if W == 1: print("UP") exit(0) else: print("DOWN") exit(0) ```
instruction
0
93,158
4
186,316
Yes
output
1
93,158
4
186,317
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down. Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0. As there is no internet in the countryside, Vitya has been watching the moon for n consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has. Input The first line of the input contains a single integer n (1 ≀ n ≀ 92) β€” the number of consecutive days Vitya was watching the size of the visible part of the moon. The second line contains n integers ai (0 ≀ ai ≀ 15) β€” Vitya's records. It's guaranteed that the input data is consistent. Output If Vitya can be sure that the size of visible part of the moon on day n + 1 will be less than the size of the visible part on day n, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1. Examples Input 5 3 4 5 6 7 Output UP Input 7 12 13 14 15 14 13 12 Output DOWN Input 1 8 Output -1 Note In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP". In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN". In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1. Submitted Solution: ``` n=int(input()) a=input() l=a.split(" ") print(l) l1=[] for i in l: l1.append(int(i)) print(l1) e=-1 val="" n1=l1[0] for i in range(1,len(l1)): if n1<l1[i]: val="UP" else: val="DOWN" n1=l1[i] if len(l1)==1: print(e) else: if n1==0: val="UP" elif n1==15: val="DOWN" print(val) ```
instruction
0
93,159
4
186,318
No
output
1
93,159
4
186,319
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down. Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0. As there is no internet in the countryside, Vitya has been watching the moon for n consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has. Input The first line of the input contains a single integer n (1 ≀ n ≀ 92) β€” the number of consecutive days Vitya was watching the size of the visible part of the moon. The second line contains n integers ai (0 ≀ ai ≀ 15) β€” Vitya's records. It's guaranteed that the input data is consistent. Output If Vitya can be sure that the size of visible part of the moon on day n + 1 will be less than the size of the visible part on day n, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1. Examples Input 5 3 4 5 6 7 Output UP Input 7 12 13 14 15 14 13 12 Output DOWN Input 1 8 Output -1 Note In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP". In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN". In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1. Submitted Solution: ``` n = int(input()) d = list(map(int, input().split())) if n == 1 and (d[0] != 15 or d[0] != 0): print(-1) elif d[-1] > d[-2] and d[-1] != 15: print('UP') else: print('DOWN') ```
instruction
0
93,160
4
186,320
No
output
1
93,160
4
186,321
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down. Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0. As there is no internet in the countryside, Vitya has been watching the moon for n consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has. Input The first line of the input contains a single integer n (1 ≀ n ≀ 92) β€” the number of consecutive days Vitya was watching the size of the visible part of the moon. The second line contains n integers ai (0 ≀ ai ≀ 15) β€” Vitya's records. It's guaranteed that the input data is consistent. Output If Vitya can be sure that the size of visible part of the moon on day n + 1 will be less than the size of the visible part on day n, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1. Examples Input 5 3 4 5 6 7 Output UP Input 7 12 13 14 15 14 13 12 Output DOWN Input 1 8 Output -1 Note In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP". In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN". In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1. Submitted Solution: ``` n = int(input()) a = list(map(int, input().split())) if a[-1] == 15: print("UP") elif a[-1] == 0: print("DOWN") elif n == 1: print("-1") else: print("UP" if a[-2] < a[-1] else "DOWN") ```
instruction
0
93,161
4
186,322
No
output
1
93,161
4
186,323
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down. Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0. As there is no internet in the countryside, Vitya has been watching the moon for n consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has. Input The first line of the input contains a single integer n (1 ≀ n ≀ 92) β€” the number of consecutive days Vitya was watching the size of the visible part of the moon. The second line contains n integers ai (0 ≀ ai ≀ 15) β€” Vitya's records. It's guaranteed that the input data is consistent. Output If Vitya can be sure that the size of visible part of the moon on day n + 1 will be less than the size of the visible part on day n, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1. Examples Input 5 3 4 5 6 7 Output UP Input 7 12 13 14 15 14 13 12 Output DOWN Input 1 8 Output -1 Note In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP". In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN". In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1. Submitted Solution: ``` n=int(input()) a=list(map(int,input().split())) k=0 for i in range(len(a)-1): if a[i]+1!=a[i+1]:k=k+1 if k==0 and len(a)>1:print('UP') elif len(a) % 2==1 and len(a)>1: b,p,s,l='',[],0,0 for i in range(int(len(a)/2)): if (a[i]+1)!=a[i+1]:s=s+1 b=b+str(a[i]) print(b,s) if s==0: b=b+str(a[int(len(a)/2)]) for i in range(int(len(a)/2),len(a)-1): if a[i]-1!=a[i+1]:l=l+1 p.append(a[i]) print(b,p,l) if l==0: p.append(a[len(a)-1]) print(p,1) r='' for i in range(len(p)-1,-1,-1):r=r+str(p[i]) print(r) if r==b:print('DOWN') else:print('-1') ```
instruction
0
93,162
4
186,324
No
output
1
93,162
4
186,325
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,867
4
187,734
Tags: implementation, sortings Correct Solution: ``` n,x=map(int,input().split()) l=list(map(int,input().split())) l.sort() c=0 for i in l: c+=(i*x) if x>=2: x-=1 print(c) ```
output
1
93,867
4
187,735
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,868
4
187,736
Tags: implementation, sortings Correct Solution: ``` [n,x] = [int(i) for i in input().split()] c = sorted([int(i) for i in input().split()]) time = 0 k = 0 while k<len(c): time+=x*c[k] if x>1: x-=1 k +=1 print(time) ```
output
1
93,868
4
187,737
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,869
4
187,738
Tags: implementation, sortings Correct Solution: ``` if __name__ == '__main__': n, x = map(int, input().rstrip().split()) s = 0 arr = sorted(list(map(int, input().rstrip().split()))) for i, e in enumerate(arr): if x - i >= 1: s += (x - i) * e else: s += e print(s) ```
output
1
93,869
4
187,739
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,870
4
187,740
Tags: implementation, sortings Correct Solution: ``` n, x = map(int, input().split()) c = sorted(map(int, input().split())) ans = 0 for i in range(n): if x == 0: x += 1 ans += c[i] * x x -= 1 print(ans) ```
output
1
93,870
4
187,741
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,871
4
187,742
Tags: implementation, sortings Correct Solution: ``` n, x = map(int, input().split()) subjects = [int(i) for i in input().split()] subjects.sort() count = res = 0 while count < n: res+=subjects[count]*x if x > 1: x-=1 count+=1 print(res) ```
output
1
93,871
4
187,743
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,872
4
187,744
Tags: implementation, sortings Correct Solution: ``` N,K=(int(num) for num in input().split()) A=[int(num) for num in input().split()] A.sort() i=0 sum=0 while i<N and K>1: sum+=A[i]*K K-=1 i+=1 while i<N: sum+=A[i]*K i+=1 print(sum) ```
output
1
93,872
4
187,745