message
stringlengths
2
20.2k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
757
108k
cluster
float64
4
4
__index_level_0__
int64
1.51k
217k
Provide tags and a correct Python 3 solution for this coding contest problem. Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β€” you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots. Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written. Your task is to print the radixes of all numeral system which can contain the time "a:b". Input The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time). We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35. Output Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1. Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible. Examples Input 11:20 Output 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Input 2A:13 Output 0 Input 000B:00001 Output -1 Note Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system. Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time. Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12.
instruction
0
6,834
4
13,668
Tags: implementation Correct Solution: ``` from sys import setrecursionlimit, exit, stdin from math import ceil, floor, acos, pi from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd from functools import reduce import itertools setrecursionlimit(10**7) RI=lambda x=' ': list(map(int,input().split(x))) RS=lambda x=' ': input().rstrip().split(x) dX= [-1, 1, 0, 0,-1, 1,-1, 1] dY= [ 0, 0,-1, 1, 1,-1,-1, 1] mod=int(1e9+7) eps=1e-6 MAX=1000 ################################################# def to_base(s, b): if not s: return 0 v=int(s[-1], 36) if v>=b: return MAX return v+to_base(s[:-1], b) *b h, m = RS(':') ans=[] for b in range(100): if to_base(h, b) < 24 and to_base(m, b) <60: ans.append(b) if not ans: print(0) elif ans[-1]==99: print(-1) else: print(*ans) ```
output
1
6,834
4
13,669
Provide tags and a correct Python 3 solution for this coding contest problem. Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β€” you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots. Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written. Your task is to print the radixes of all numeral system which can contain the time "a:b". Input The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time). We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35. Output Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1. Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible. Examples Input 11:20 Output 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Input 2A:13 Output 0 Input 000B:00001 Output -1 Note Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system. Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time. Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12.
instruction
0
6,835
4
13,670
Tags: implementation Correct Solution: ``` a,b=input().split(':') z='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' c=[z.find(i) for i in a] d=[z.find(i) for i in b] for i in range(len(c)): if c[i]>0: break c=c[i:] for i in range(len(d)): if d[i]>0: break d=d[i:] if int(a,base=max(*c+[1])+1)>23 or int(b,base=max(*d+[1])+1)>59: print(0) elif len(c)==len(d)==1: print(-1) else: for i in range(max(*d+c)+1,61): e=0 for j in range(len(c)): e+=i**j*c[-1-j] f=0 for j in range(len(d)): f+=i**j*d[-1-j] if 0<=e<=23 and 0<=f<=59: print(i,end=' ') ```
output
1
6,835
4
13,671
Provide tags and a correct Python 3 solution for this coding contest problem. Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β€” you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots. Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written. Your task is to print the radixes of all numeral system which can contain the time "a:b". Input The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time). We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35. Output Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1. Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible. Examples Input 11:20 Output 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Input 2A:13 Output 0 Input 000B:00001 Output -1 Note Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system. Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time. Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12.
instruction
0
6,836
4
13,672
Tags: implementation Correct Solution: ``` def f(x, k): if 1 < k < 37: return int(x, k) s = 0 for i in x: s = s * k s += int(i, 36) return s hours, minutes = input().split(':') i = j = k = max(int(max(hours), 36), int(max(minutes), 36)) + 1 x, y = (f(hours, k) == f(hours, k + 1)), (f(minutes, k) == f(minutes, k + 1)) if x and y: print(-1 if hours[-1] < 'O' else 0) else: if x: i = 61 else: while f(hours, i) < 24: i += 1 if y: j = i else: while j < i and f(minutes, j) < 60: j += 1 print(' '.join(map(str, range(k, j))) if k < j else 0) ```
output
1
6,836
4
13,673
Provide tags and a correct Python 3 solution for this coding contest problem. Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β€” you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots. Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written. Your task is to print the radixes of all numeral system which can contain the time "a:b". Input The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time). We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35. Output Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1. Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible. Examples Input 11:20 Output 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Input 2A:13 Output 0 Input 000B:00001 Output -1 Note Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system. Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time. Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12.
instruction
0
6,837
4
13,674
Tags: implementation Correct Solution: ``` import string import re values={str(d): d for d in range(10) } for ch in string.ascii_uppercase: values[ch] = ord(ch) - 55 def convert(s, i): x=0 for ch in s: d = values[ch] if d>=i: return None x = i*x+d return x match=re.match('0*(\w+):0*(\w+)',input().strip()) a,b=match.groups([1, 2]) ans = [] for i in range(2, 60): h = convert(a, i) m = convert(b, i) if h == None or m == None: continue if h < 24 and m < 60: ans.append(i) if len(ans) == 0: print(0) elif len(a) + len(b) == 2: print(-1) else: print(*ans) ```
output
1
6,837
4
13,675
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β€” you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots. Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written. Your task is to print the radixes of all numeral system which can contain the time "a:b". Input The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time). We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35. Output Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1. Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible. Examples Input 11:20 Output 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Input 2A:13 Output 0 Input 000B:00001 Output -1 Note Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system. Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time. Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12. Submitted Solution: ``` def f(x, k): if 1 < k < 37: return int(x, k) s = 0 for i in x: s = s * k s += int(i, 36) return s a, b = input().split(':') i = j = k = max(int(max(a), 36), int(max(b), 36)) + 1 x, y = (f(a, k) == f(a, k + 1)), (f(b, k) == f(b, k + 1)) if x and y: print(-1 if a[-1] < 'O' else 0) else: if x: i = 61 else: while f(a, i) < 24: i += 1 if y: j = i else: while j < i and f(b, j) < 60: j += 1 print(' '.join(map(str, range(k, j))) if k < j else 0) # Made By Mostafa_Khaled ```
instruction
0
6,838
4
13,676
Yes
output
1
6,838
4
13,677
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β€” you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots. Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written. Your task is to print the radixes of all numeral system which can contain the time "a:b". Input The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time). We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35. Output Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1. Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible. Examples Input 11:20 Output 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Input 2A:13 Output 0 Input 000B:00001 Output -1 Note Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system. Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time. Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12. Submitted Solution: ``` time = input() hour = time.split(':')[0] minute = time.split(':')[1] minBase = 0 def charToVal(x): if ord(x) < 58: return ord(x) - 48 else: return ord(x) - 55 for x in hour: if ord(x) < 58: minBase = max(minBase, ord(x) - 47) else: minBase = max(minBase, ord(x) - 54) for x in minute: if ord(x) < 58: minBase = max(minBase, ord(x) - 47) else: minBase = max(minBase, ord(x) - 54) solutions = [] for base in range(minBase, 62): multiple = 1 converted_hour = 0 for x in range(len(hour) - 1, -1, -1): converted_hour += multiple*(charToVal(hour[x])) multiple *= base if converted_hour >= 24: break multiple = 1 converted_minute = 0 for x in range(len(minute) - 1, -1, -1): converted_minute += multiple*(charToVal(minute[x])) multiple *= base if converted_minute >= 60: break solutions.append(base) if 61 in solutions: print(-1) elif len(solutions) == 0: print(0) else: for x in solutions: print(x, end=' ') ```
instruction
0
6,839
4
13,678
Yes
output
1
6,839
4
13,679
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β€” you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots. Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written. Your task is to print the radixes of all numeral system which can contain the time "a:b". Input The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time). We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35. Output Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1. Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible. Examples Input 11:20 Output 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Input 2A:13 Output 0 Input 000B:00001 Output -1 Note Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system. Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time. Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12. Submitted Solution: ``` import sys s1,s2 = input().split(":") def convert(n,base): ans = 0 for i in range(len(n)): x = 0 if n[i].isalpha(): x = int(ord(n[i]) - ord('A')+10) else: x = int(n[i]) ans += x*pow(base,len(n)-i-1) return ans work = [] minm = 0 for c in s1+s2: if c.isalpha(): minm = max(minm, ord(c) - ord('A')+10) else: minm = max(minm,int(c)) for base in range(max(minm+1,2),60): if convert(s1,base) < 24 and convert(s2,base) < 60: work.append(base) else: break if len(work) == 0: print(0) elif (len(s1) == 1 or s1[:len(s1)-1] == '0'*(len(s1) -1)) and (len(s2) == 1 or s2[:len(s2)-1] == '0'*(len(s2) -1)): print(-1) else: print(" ".join(map(str,work))) ```
instruction
0
6,840
4
13,680
Yes
output
1
6,840
4
13,681
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β€” you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots. Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written. Your task is to print the radixes of all numeral system which can contain the time "a:b". Input The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time). We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35. Output Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1. Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible. Examples Input 11:20 Output 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Input 2A:13 Output 0 Input 000B:00001 Output -1 Note Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system. Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time. Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12. Submitted Solution: ``` '''input 27:0070 ''' def conv(s, base): ans = 0 for index, i in enumerate(reversed(s)): val = int(i, 36) ans += (base**index)*val return ans def valid(base, h, m): hours = conv(h, base) mint = conv(m, base) if(0 <= hours < 24 and 0 <= mint < 60): return True else: return False h, m = input().split(":") hl = sorted(list(h)) ml = sorted(list(m)) hm = hl[-1] mm = ml[-1] if(ord(hm) < ord('A')): minbaseh = ord(hm) - ord('0') + 1 else: minbaseh = 11 + ord(hm) - ord('A') if(ord(mm) < ord('A')): minbasem = ord(mm) - ord('0') + 1 else: minbasem = 11 + ord(mm) - ord('A') minbase = max(minbasem, minbaseh) # print(minbaseh, minbasem, minbase, hm, mm) firstInval = 0 found = False lo = minbase hi = 60 while(lo <= hi): mid = lo + (hi - lo)//2 # print(mid, lo, hi, valid(mid, h, m)) if(not valid(mid, h, m)): firstInval = mid hi = mid-1 found = True else: lo = mid+1 if(not found): print(-1) elif(firstInval == minbase): print(0) else: for i in range(minbase, firstInval): print(i, end = " ") ```
instruction
0
6,841
4
13,682
Yes
output
1
6,841
4
13,683
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β€” you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots. Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written. Your task is to print the radixes of all numeral system which can contain the time "a:b". Input The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time). We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35. Output Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1. Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible. Examples Input 11:20 Output 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Input 2A:13 Output 0 Input 000B:00001 Output -1 Note Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system. Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time. Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12. Submitted Solution: ``` time = input() hour = time.split(':')[0] minute = time.split(':')[1] minBase = 0 def charToVal(x): if ord(x) < 58: return ord(x) - 48 else: return ord(x) - 55 for x in hour: if ord(x) < 58: minBase = max(minBase, ord(x) - 47) else: minBase = max(minBase, ord(x) - 54) for x in minute: if ord(x) < 58: minBase = max(minBase, ord(x) - 47) else: minBase = max(minBase, ord(x) - 54) solutions = [] for base in range(minBase, 27): multiple = 1 converted_hour = 0 for x in range(len(hour) - 1, -1, -1): converted_hour += multiple*(charToVal(hour[x])) multiple *= base if converted_hour >= 24: break multiple = 1 converted_minute = 0 for x in range(len(minute) - 1, -1, -1): converted_minute += multiple*(charToVal(minute[x])) multiple *= base if converted_minute >= 60: break solutions.append(base) if 26 in solutions: print(-1) elif len(solutions) == 0: print(0) else: for x in solutions: print(x, end=' ') #make sure it is valid # if it fails, break, return ones that worked #otherwise, next return statement is -1 ```
instruction
0
6,842
4
13,684
No
output
1
6,842
4
13,685
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β€” you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots. Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written. Your task is to print the radixes of all numeral system which can contain the time "a:b". Input The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time). We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35. Output Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1. Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible. Examples Input 11:20 Output 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Input 2A:13 Output 0 Input 000B:00001 Output -1 Note Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system. Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time. Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12. Submitted Solution: ``` s = input() a = s[:s.index(":")] b = s[s.index(":")+1:] a2 = '' b2 = '' found = False for i in a: if i!='0': found = True if found: a2+=i found = False for i in b: if i!='0': found = True if found: b2+=i a = a2 b = b2 apos = [] bpos = [] values = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] for i in a: apos.append(values.index(i)) for i in b: bpos.append(values.index(i)) if len(apos)==0: apos.append(0) if len(bpos)==0: bpos.append(0) minradix = max(max(apos), max(bpos)) #print(minradix) results = [] for i in range(minradix+1, 24): aresult = 0 bresult = 0 for j in range(len(apos)): aresult+=apos[j]*(i**(len(apos)-j-1)) for j in range(len(bpos)): bresult+=bpos[j]*(i**(len(bpos)-j-1)) if aresult<=23 and bresult<=59: results.append(i) #print(a, b) if len(a)==1 and len(b)==1 and values.index(a)<=23 and values.index(b)<=59: print(-1) elif len(results)==0: print(0) elif apos==[0] and bpos==[0]: print(-1) else: print(' '.join(list(map(str, results)))) ```
instruction
0
6,843
4
13,686
No
output
1
6,843
4
13,687
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β€” you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots. Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written. Your task is to print the radixes of all numeral system which can contain the time "a:b". Input The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time). We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35. Output Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1. Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible. Examples Input 11:20 Output 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Input 2A:13 Output 0 Input 000B:00001 Output -1 Note Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system. Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time. Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12. Submitted Solution: ``` a,b=input().split(':') z='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' c=[z.find(i) for i in a] d=[z.find(i) for i in b] for i in range(len(c)): if c[i]>0: break c=c[i:] for i in range(len(d)): if d[i]>0: break d=d[i:] if int(a,base=max(*c+[2])+1)>23 or int(b,base=max(*d+[2])+1)>59: print(0) elif len(c)==len(d)==1: print(-1) else: for i in range(max(*d+c)+1,61): e=0 for j in range(len(c)): e+=i**j*c[-1-j] f=0 for j in range(len(d)): f+=i**j*d[-1-j] if 0<=e<=23 and 0<=f<=59: print(i,end=' ') ```
instruction
0
6,844
4
13,688
No
output
1
6,844
4
13,689
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β€” you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots. Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written. Your task is to print the radixes of all numeral system which can contain the time "a:b". Input The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time). We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35. Output Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1. Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible. Examples Input 11:20 Output 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Input 2A:13 Output 0 Input 000B:00001 Output -1 Note Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system. Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time. Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12. Submitted Solution: ``` s=input().rstrip().split(':') ans=[] for i in range(2,60): try: if int(s[0],i)<=24 and int(s[0],i)>=0 and int(s[1],i)>=0 and int(s[1],i)<=59: ans.append(i) except: pass count=0 i=100 try: if int(s[0],i)<=24 and int(s[0],i)>=0 and int(s[1],i)>=0 and int(s[1],i)<=59: count+=1 except: pass if count==1 or ans[-1]==36: print(-1) elif len(ans)==0: print(0) else: print(*ans) ```
instruction
0
6,845
4
13,690
No
output
1
6,845
4
13,691
Provide tags and a correct Python 3 solution for this coding contest problem. Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be n interesting minutes t1, t2, ..., tn. Your task is to calculate for how many minutes Limak will watch the game. Input The first line of the input contains one integer n (1 ≀ n ≀ 90) β€” the number of interesting minutes. The second line contains n integers t1, t2, ..., tn (1 ≀ t1 < t2 < ... tn ≀ 90), given in the increasing order. Output Print the number of minutes Limak will watch the game. Examples Input 3 7 20 88 Output 35 Input 9 16 20 30 40 50 60 70 80 90 Output 15 Input 9 15 20 30 40 50 60 70 80 90 Output 90 Note In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game.
instruction
0
7,127
4
14,254
Tags: implementation Correct Solution: ``` n = int(input()) BoringTimes = [int(i) for i in input().split(' ')] flag = 0 if BoringTimes[0] > 15: flag = 1 print('15') else: for i in range(n-1): if BoringTimes[i+1] - BoringTimes[i] > 15: flag = 1 print(BoringTimes[i] + 15) break if flag == 0 and BoringTimes[n-1] < 75: flag = 1 print(BoringTimes[n-1] + 15) if flag == 0: print('90') ```
output
1
7,127
4
14,255
Provide tags and a correct Python 3 solution for this coding contest problem. Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be n interesting minutes t1, t2, ..., tn. Your task is to calculate for how many minutes Limak will watch the game. Input The first line of the input contains one integer n (1 ≀ n ≀ 90) β€” the number of interesting minutes. The second line contains n integers t1, t2, ..., tn (1 ≀ t1 < t2 < ... tn ≀ 90), given in the increasing order. Output Print the number of minutes Limak will watch the game. Examples Input 3 7 20 88 Output 35 Input 9 16 20 30 40 50 60 70 80 90 Output 15 Input 9 15 20 30 40 50 60 70 80 90 Output 90 Note In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game.
instruction
0
7,128
4
14,256
Tags: implementation Correct Solution: ``` n=int(input()) a=[int(i) for i in input().split()] ch=0 for f in a: if f-ch>15: break else: ch=f if ch>=90-15: ch=90 else: ch+=15 print(ch) ```
output
1
7,128
4
14,257
Provide tags and a correct Python 3 solution for this coding contest problem. Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be n interesting minutes t1, t2, ..., tn. Your task is to calculate for how many minutes Limak will watch the game. Input The first line of the input contains one integer n (1 ≀ n ≀ 90) β€” the number of interesting minutes. The second line contains n integers t1, t2, ..., tn (1 ≀ t1 < t2 < ... tn ≀ 90), given in the increasing order. Output Print the number of minutes Limak will watch the game. Examples Input 3 7 20 88 Output 35 Input 9 16 20 30 40 50 60 70 80 90 Output 15 Input 9 15 20 30 40 50 60 70 80 90 Output 90 Note In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game.
instruction
0
7,129
4
14,258
Tags: implementation Correct Solution: ``` input() ts = map(int, input().split()) time = 15 for t in ts: if t <= time: time = t + 15 else: break print(min(90, time)) ```
output
1
7,129
4
14,259
Provide tags and a correct Python 3 solution for this coding contest problem. Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be n interesting minutes t1, t2, ..., tn. Your task is to calculate for how many minutes Limak will watch the game. Input The first line of the input contains one integer n (1 ≀ n ≀ 90) β€” the number of interesting minutes. The second line contains n integers t1, t2, ..., tn (1 ≀ t1 < t2 < ... tn ≀ 90), given in the increasing order. Output Print the number of minutes Limak will watch the game. Examples Input 3 7 20 88 Output 35 Input 9 16 20 30 40 50 60 70 80 90 Output 15 Input 9 15 20 30 40 50 60 70 80 90 Output 90 Note In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game.
instruction
0
7,130
4
14,260
Tags: implementation Correct Solution: ``` n = input() minutes = list(map(int,input().split())) total_time = 0 mark = 0 for i in minutes: watching = min(i-mark,15) total_time += watching if i-mark>=16: break mark = i if mark == minutes[-1]: total_time += min(90-minutes[-1],15) print(total_time) ```
output
1
7,130
4
14,261
Provide tags and a correct Python 3 solution for this coding contest problem. Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be n interesting minutes t1, t2, ..., tn. Your task is to calculate for how many minutes Limak will watch the game. Input The first line of the input contains one integer n (1 ≀ n ≀ 90) β€” the number of interesting minutes. The second line contains n integers t1, t2, ..., tn (1 ≀ t1 < t2 < ... tn ≀ 90), given in the increasing order. Output Print the number of minutes Limak will watch the game. Examples Input 3 7 20 88 Output 35 Input 9 16 20 30 40 50 60 70 80 90 Output 15 Input 9 15 20 30 40 50 60 70 80 90 Output 90 Note In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game.
instruction
0
7,131
4
14,262
Tags: implementation Correct Solution: ``` n = int(input()) arr = list(map(int, input().split(' '))) last = 0 end = False for i in arr: if i - last > 15: print(last + 15) end = True break last = i if not end: if last > 74: print(90) else: print(last + 15) ```
output
1
7,131
4
14,263
Provide tags and a correct Python 3 solution for this coding contest problem. Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be n interesting minutes t1, t2, ..., tn. Your task is to calculate for how many minutes Limak will watch the game. Input The first line of the input contains one integer n (1 ≀ n ≀ 90) β€” the number of interesting minutes. The second line contains n integers t1, t2, ..., tn (1 ≀ t1 < t2 < ... tn ≀ 90), given in the increasing order. Output Print the number of minutes Limak will watch the game. Examples Input 3 7 20 88 Output 35 Input 9 16 20 30 40 50 60 70 80 90 Output 15 Input 9 15 20 30 40 50 60 70 80 90 Output 90 Note In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game.
instruction
0
7,132
4
14,264
Tags: implementation Correct Solution: ``` n = int(input()) t = list(map(int, input().split())) if(n==1 or t[0]>15): if(t[0] > 15): print(15) else: print(t[0]+15) else: watchtime = 0 for i in range(1,n): if(t[i]-t[i-1] >15): watchtime=t[i-1]+15 break if watchtime == 0: watchtime = t[-1]+15 if watchtime > 90: print(90) else: print(watchtime) ```
output
1
7,132
4
14,265
Provide tags and a correct Python 3 solution for this coding contest problem. Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be n interesting minutes t1, t2, ..., tn. Your task is to calculate for how many minutes Limak will watch the game. Input The first line of the input contains one integer n (1 ≀ n ≀ 90) β€” the number of interesting minutes. The second line contains n integers t1, t2, ..., tn (1 ≀ t1 < t2 < ... tn ≀ 90), given in the increasing order. Output Print the number of minutes Limak will watch the game. Examples Input 3 7 20 88 Output 35 Input 9 16 20 30 40 50 60 70 80 90 Output 15 Input 9 15 20 30 40 50 60 70 80 90 Output 90 Note In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game.
instruction
0
7,133
4
14,266
Tags: implementation Correct Solution: ``` n=int(input()) l=list(map(int,input().split())) m=0 s=0 for i in range(n): if(l[i]-m<=15): m=l[i] else: m+=15 s=1 break if(s==0): if(90-m<=15): m=90 else: m+=15 print(m) ```
output
1
7,133
4
14,267
Provide tags and a correct Python 3 solution for this coding contest problem. Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be n interesting minutes t1, t2, ..., tn. Your task is to calculate for how many minutes Limak will watch the game. Input The first line of the input contains one integer n (1 ≀ n ≀ 90) β€” the number of interesting minutes. The second line contains n integers t1, t2, ..., tn (1 ≀ t1 < t2 < ... tn ≀ 90), given in the increasing order. Output Print the number of minutes Limak will watch the game. Examples Input 3 7 20 88 Output 35 Input 9 16 20 30 40 50 60 70 80 90 Output 15 Input 9 15 20 30 40 50 60 70 80 90 Output 90 Note In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game.
instruction
0
7,134
4
14,268
Tags: implementation Correct Solution: ``` n=int(input()) l=list(map(int,input().split())) if len(l)==1: if l[0]>15: time=15 else: time=l[0]+15 for i in range(len(l)): if l[i]<=15 and i==0: continue elif l[i]>15 and i==0: time=15 break if l[i]-l[i-1]>15: time=l[i-1]+15 break elif l[i]-l[i-1]<=15: if i==len(l)-1: if l[i]<90: if 90-l[i]<=15: time=90 elif 90-l[i]>15: time=l[i]+15 else: time=90 else: continue print(time) ```
output
1
7,134
4
14,269
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be n interesting minutes t1, t2, ..., tn. Your task is to calculate for how many minutes Limak will watch the game. Input The first line of the input contains one integer n (1 ≀ n ≀ 90) β€” the number of interesting minutes. The second line contains n integers t1, t2, ..., tn (1 ≀ t1 < t2 < ... tn ≀ 90), given in the increasing order. Output Print the number of minutes Limak will watch the game. Examples Input 3 7 20 88 Output 35 Input 9 16 20 30 40 50 60 70 80 90 Output 15 Input 9 15 20 30 40 50 60 70 80 90 Output 90 Note In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game. Submitted Solution: ``` n = int(input()) T = [0]+list(map(int, input().split()))+[90] ok = 1 for i in range(1,n+2): if T[i]-T[i-1]>15: print(T[i-1]+15) ok = 0 break if ok: print(90) ```
instruction
0
7,135
4
14,270
Yes
output
1
7,135
4
14,271
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be n interesting minutes t1, t2, ..., tn. Your task is to calculate for how many minutes Limak will watch the game. Input The first line of the input contains one integer n (1 ≀ n ≀ 90) β€” the number of interesting minutes. The second line contains n integers t1, t2, ..., tn (1 ≀ t1 < t2 < ... tn ≀ 90), given in the increasing order. Output Print the number of minutes Limak will watch the game. Examples Input 3 7 20 88 Output 35 Input 9 16 20 30 40 50 60 70 80 90 Output 15 Input 9 15 20 30 40 50 60 70 80 90 Output 90 Note In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game. Submitted Solution: ``` a = int(input()); c = input().split(); dem = int(c[0]); if dem > 15: dem = 15; else: for i in range(a): d = int(c[i]) - dem; if d > 15: dem = int(c[i-1]) + 15; break else: if (i + 1) != a: dem = int(c[i]); else: if int(c[a-1]) > 75: dem = 90; else: dem = int(c[a-1])+15 print(dem) ```
instruction
0
7,136
4
14,272
Yes
output
1
7,136
4
14,273
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be n interesting minutes t1, t2, ..., tn. Your task is to calculate for how many minutes Limak will watch the game. Input The first line of the input contains one integer n (1 ≀ n ≀ 90) β€” the number of interesting minutes. The second line contains n integers t1, t2, ..., tn (1 ≀ t1 < t2 < ... tn ≀ 90), given in the increasing order. Output Print the number of minutes Limak will watch the game. Examples Input 3 7 20 88 Output 35 Input 9 16 20 30 40 50 60 70 80 90 Output 15 Input 9 15 20 30 40 50 60 70 80 90 Output 90 Note In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game. Submitted Solution: ``` n = int(input()) minutes=[] for i in range(91): minutes.append(False) for x in input().split(): x = int(x) minutes[x] = True l = 0 i = 1; while i < 90: if minutes[i] == False: l += 1; else: l = 0 if (l == 15): break; i += 1; print(i) ```
instruction
0
7,137
4
14,274
Yes
output
1
7,137
4
14,275
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be n interesting minutes t1, t2, ..., tn. Your task is to calculate for how many minutes Limak will watch the game. Input The first line of the input contains one integer n (1 ≀ n ≀ 90) β€” the number of interesting minutes. The second line contains n integers t1, t2, ..., tn (1 ≀ t1 < t2 < ... tn ≀ 90), given in the increasing order. Output Print the number of minutes Limak will watch the game. Examples Input 3 7 20 88 Output 35 Input 9 16 20 30 40 50 60 70 80 90 Output 15 Input 9 15 20 30 40 50 60 70 80 90 Output 90 Note In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game. Submitted Solution: ``` first_line = input() second_line = input() n = int(first_line) lst = list(map(lambda a: int(a), second_line.split())) def solve1(n, lst): if lst[0] > 15: return 15 for i in range(len(lst) - 1): if lst[i + 1] - lst[i] > 15: return lst[i] + 15 return min(lst[n-1] + 15, 90) print(solve1(n, lst)) ```
instruction
0
7,138
4
14,276
Yes
output
1
7,138
4
14,277
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be n interesting minutes t1, t2, ..., tn. Your task is to calculate for how many minutes Limak will watch the game. Input The first line of the input contains one integer n (1 ≀ n ≀ 90) β€” the number of interesting minutes. The second line contains n integers t1, t2, ..., tn (1 ≀ t1 < t2 < ... tn ≀ 90), given in the increasing order. Output Print the number of minutes Limak will watch the game. Examples Input 3 7 20 88 Output 35 Input 9 16 20 30 40 50 60 70 80 90 Output 15 Input 9 15 20 30 40 50 60 70 80 90 Output 90 Note In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game. Submitted Solution: ``` n = int(input()) m = input() minutes = [int(x) for x in m.split()] ans = 0 for i in range(len(minutes)): if ans + 15 >= minutes[i]: ans = minutes[i] else: ans += 15 break print(ans) ```
instruction
0
7,139
4
14,278
No
output
1
7,139
4
14,279
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be n interesting minutes t1, t2, ..., tn. Your task is to calculate for how many minutes Limak will watch the game. Input The first line of the input contains one integer n (1 ≀ n ≀ 90) β€” the number of interesting minutes. The second line contains n integers t1, t2, ..., tn (1 ≀ t1 < t2 < ... tn ≀ 90), given in the increasing order. Output Print the number of minutes Limak will watch the game. Examples Input 3 7 20 88 Output 35 Input 9 16 20 30 40 50 60 70 80 90 Output 15 Input 9 15 20 30 40 50 60 70 80 90 Output 90 Note In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game. Submitted Solution: ``` n=int(input()) l=list(map(int,input().split())) m=0 for i in range(n): if(l[i]-m<=15): m=l[i] else: m+=15 break if(i==n): if(90-m<=15): m=90 else: m+=15 print(m) ```
instruction
0
7,140
4
14,280
No
output
1
7,140
4
14,281
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be n interesting minutes t1, t2, ..., tn. Your task is to calculate for how many minutes Limak will watch the game. Input The first line of the input contains one integer n (1 ≀ n ≀ 90) β€” the number of interesting minutes. The second line contains n integers t1, t2, ..., tn (1 ≀ t1 < t2 < ... tn ≀ 90), given in the increasing order. Output Print the number of minutes Limak will watch the game. Examples Input 3 7 20 88 Output 35 Input 9 16 20 30 40 50 60 70 80 90 Output 15 Input 9 15 20 30 40 50 60 70 80 90 Output 90 Note In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game. Submitted Solution: ``` x = int(input()) y = list(map(int, input().split(' '))) watched = 0 base = 15 for t in y: duration = t - watched if duration <= base: total = watched + duration + base watched = total if total < 90 else 90 else: watched = watched + base break watched = t print(watched) ```
instruction
0
7,141
4
14,282
No
output
1
7,141
4
14,283
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be n interesting minutes t1, t2, ..., tn. Your task is to calculate for how many minutes Limak will watch the game. Input The first line of the input contains one integer n (1 ≀ n ≀ 90) β€” the number of interesting minutes. The second line contains n integers t1, t2, ..., tn (1 ≀ t1 < t2 < ... tn ≀ 90), given in the increasing order. Output Print the number of minutes Limak will watch the game. Examples Input 3 7 20 88 Output 35 Input 9 16 20 30 40 50 60 70 80 90 Output 15 Input 9 15 20 30 40 50 60 70 80 90 Output 90 Note In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game. Submitted Solution: ``` def main(): n = int(input()) c = 0 minutes = [int(i) for i in input().split()] for m in minutes: if m - c - 1 >= 15: print(c + 15) return c = m if m + 14 <= 90: print(m + 14) else: print(90) main() ```
instruction
0
7,142
4
14,284
No
output
1
7,142
4
14,285
Provide tags and a correct Python 3 solution for this coding contest problem. The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year. Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100 (<https://en.wikipedia.org/wiki/Leap_year>). Input The only line contains integer y (1000 ≀ y < 100'000) β€” the year of the calendar. Output Print the only integer y' β€” the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar. Examples Input 2016 Output 2044 Input 2000 Output 2028 Input 50501 Output 50507 Note Today is Monday, the 13th of June, 2016.
instruction
0
8,009
4
16,018
Tags: implementation Correct Solution: ``` def is_leap(y): a = y % 400 == 0 b = y % 4 == 0 and not y % 100 == 0 return a or b year = int(input()) l = is_leap(year) w = 1 u = w y = year while True: y += 1 incr = int(is_leap(y - 1)) u = (u + 1 + incr) % 7 if u == w and l == is_leap(y): print(y) break ```
output
1
8,009
4
16,019
Provide tags and a correct Python 3 solution for this coding contest problem. The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year. Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100 (<https://en.wikipedia.org/wiki/Leap_year>). Input The only line contains integer y (1000 ≀ y < 100'000) β€” the year of the calendar. Output Print the only integer y' β€” the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar. Examples Input 2016 Output 2044 Input 2000 Output 2028 Input 50501 Output 50507 Note Today is Monday, the 13th of June, 2016.
instruction
0
8,010
4
16,020
Tags: implementation Correct Solution: ``` def main(): def leap(y): return y % 100 and not y % 4 or not y % 400 n = int(input()) a = leap(n) b, x = not a, 0 while a != b or x % 7: n += 1 b = leap(n) x += 365 + b print(n) if __name__ == '__main__': main() ```
output
1
8,010
4
16,021
Provide tags and a correct Python 3 solution for this coding contest problem. The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year. Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100 (<https://en.wikipedia.org/wiki/Leap_year>). Input The only line contains integer y (1000 ≀ y < 100'000) β€” the year of the calendar. Output Print the only integer y' β€” the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar. Examples Input 2016 Output 2044 Input 2000 Output 2028 Input 50501 Output 50507 Note Today is Monday, the 13th of June, 2016.
instruction
0
8,011
4
16,022
Tags: implementation Correct Solution: ``` def f(n): if (n % 400 == 0): return 2 elif n % 100 != 0 and n % 4 == 0: return 2 return 1 n = int(input()) x = n c = f(n) n += 1 while c % 7 != 0 or f(n) != f(x): c += f(n) n += 1 #print(n, f(n), c) print(n) ```
output
1
8,011
4
16,023
Provide tags and a correct Python 3 solution for this coding contest problem. The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year. Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100 (<https://en.wikipedia.org/wiki/Leap_year>). Input The only line contains integer y (1000 ≀ y < 100'000) β€” the year of the calendar. Output Print the only integer y' β€” the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar. Examples Input 2016 Output 2044 Input 2000 Output 2028 Input 50501 Output 50507 Note Today is Monday, the 13th of June, 2016.
instruction
0
8,012
4
16,024
Tags: implementation Correct Solution: ``` y=int(input()) b=0 y0=y while b or y==y0 or (y0%400==0 or y0%4==0 and y0%100) and not(y%400==0 or y%4==0 and y%100) or not(y0%400==0 or y0%4==0 and y0%100) and (y%400==0 or y%4==0 and y%100): b+=365%7 if y%400==0 or y%4==0 and y%100: b+=1 y+=1 b%=7 print(y) ```
output
1
8,012
4
16,025
Provide tags and a correct Python 3 solution for this coding contest problem. The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year. Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100 (<https://en.wikipedia.org/wiki/Leap_year>). Input The only line contains integer y (1000 ≀ y < 100'000) β€” the year of the calendar. Output Print the only integer y' β€” the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar. Examples Input 2016 Output 2044 Input 2000 Output 2028 Input 50501 Output 50507 Note Today is Monday, the 13th of June, 2016.
instruction
0
8,013
4
16,026
Tags: implementation Correct Solution: ``` def leapyear(y): return y%400==0 or (y%4==0 and y%100!=0) a = int(input()) t = int(leapyear(a)) s = int(leapyear(a+1)) d = s+1 y=a+1 while(d%7!=0 or s!=t): y+=1 s = int(leapyear(y)) d+=s+1 print(y) ```
output
1
8,013
4
16,027
Provide tags and a correct Python 3 solution for this coding contest problem. The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year. Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100 (<https://en.wikipedia.org/wiki/Leap_year>). Input The only line contains integer y (1000 ≀ y < 100'000) β€” the year of the calendar. Output Print the only integer y' β€” the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar. Examples Input 2016 Output 2044 Input 2000 Output 2028 Input 50501 Output 50507 Note Today is Monday, the 13th of June, 2016.
instruction
0
8,014
4
16,028
Tags: implementation Correct Solution: ``` def isleap(y): return y % 400 == 0 or (y % 4 == 0 and y % 100 != 0) y = int(input()) days = 366 if isleap(y) else 365 nextSameYear = y+1 while True: if days % 7 == 0 and isleap(nextSameYear) == isleap(y): break days += 366 if isleap(nextSameYear) else 365 nextSameYear+=1 print(nextSameYear) ```
output
1
8,014
4
16,029
Provide tags and a correct Python 3 solution for this coding contest problem. The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year. Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100 (<https://en.wikipedia.org/wiki/Leap_year>). Input The only line contains integer y (1000 ≀ y < 100'000) β€” the year of the calendar. Output Print the only integer y' β€” the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar. Examples Input 2016 Output 2044 Input 2000 Output 2028 Input 50501 Output 50507 Note Today is Monday, the 13th of June, 2016.
instruction
0
8,015
4
16,030
Tags: implementation Correct Solution: ``` n = int(input()) count = 0 flag = True if (n % 4 == 0 and n % 100 != 0) or n % 400 == 0 : flag = False while True: n += 1 if n % 400 == 0: count += 2 elif n % 4 == 0 and n % 100 != 0: count += 2 else: count += 1 #print(count) if count % 7 == 0: if flag == False and ((n % 4 == 0 and n % 100 != 0) or n % 400 == 0): print(n) break elif flag == True and ((n % 4 != 0 or n % 100 == 0) and n % 400 != 0): print(n) break else: continue ```
output
1
8,015
4
16,031
Provide tags and a correct Python 3 solution for this coding contest problem. The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year. Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100 (<https://en.wikipedia.org/wiki/Leap_year>). Input The only line contains integer y (1000 ≀ y < 100'000) β€” the year of the calendar. Output Print the only integer y' β€” the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar. Examples Input 2016 Output 2044 Input 2000 Output 2028 Input 50501 Output 50507 Note Today is Monday, the 13th of June, 2016.
instruction
0
8,016
4
16,032
Tags: implementation Correct Solution: ``` def is_leap(year): return year % 400 == 0 or (year % 4 == 0 and year % 100 != 0) def year_days(year): return 365 + int(is_leap(year)) y = int(input().strip()) offset = 0 res = y while 1: if offset and offset % 7 == 0 and is_leap(y) == is_leap(res): break offset += year_days(res) % 7 res += 1 print(res) ```
output
1
8,016
4
16,033
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year. Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100 (<https://en.wikipedia.org/wiki/Leap_year>). Input The only line contains integer y (1000 ≀ y < 100'000) β€” the year of the calendar. Output Print the only integer y' β€” the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar. Examples Input 2016 Output 2044 Input 2000 Output 2028 Input 50501 Output 50507 Note Today is Monday, the 13th of June, 2016. Submitted Solution: ``` import sys y = int(input()) leap = 1 if y % 400 == 0 or y % 4 == 0 and y % 100 else 0 y += 1 m = (366 if leap else 365) % 7 while 1: l = 1 if y % 400 == 0 or y % 4 == 0 and y % 100 else 0 if m == 0 and leap == l: print(y) exit() m = (m + (366 if l else 365)) % 7 y += 1 ```
instruction
0
8,017
4
16,034
Yes
output
1
8,017
4
16,035
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year. Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100 (<https://en.wikipedia.org/wiki/Leap_year>). Input The only line contains integer y (1000 ≀ y < 100'000) β€” the year of the calendar. Output Print the only integer y' β€” the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar. Examples Input 2016 Output 2044 Input 2000 Output 2028 Input 50501 Output 50507 Note Today is Monday, the 13th of June, 2016. Submitted Solution: ``` import datetime def tot_days(year): if year % 400 == 0: return 366 if year % 100 == 0: return 365 if year % 4 == 0: return 366 return 365 year = int(input()) first_day = 0 tot = tot_days(year) days = first_day cyear = year while True: days = (days + tot_days(cyear)) % 7 cyear += 1 if first_day == days and tot == tot_days(cyear): print(cyear) break ```
instruction
0
8,018
4
16,036
Yes
output
1
8,018
4
16,037
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year. Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100 (<https://en.wikipedia.org/wiki/Leap_year>). Input The only line contains integer y (1000 ≀ y < 100'000) β€” the year of the calendar. Output Print the only integer y' β€” the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar. Examples Input 2016 Output 2044 Input 2000 Output 2028 Input 50501 Output 50507 Note Today is Monday, the 13th of June, 2016. Submitted Solution: ``` def iswis(a): return a % 400 == 0 or (a%100!= 0 and a %4==0) n = int(input()) wis = iswis(n) fr = 0; n += 1 if (wis): fr += 1 fr += 1 while (iswis(n) != wis or fr != 0): if (iswis(n)): fr += 1 fr += 1 fr %= 7 n += 1 print(n) ```
instruction
0
8,019
4
16,038
Yes
output
1
8,019
4
16,039
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year. Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100 (<https://en.wikipedia.org/wiki/Leap_year>). Input The only line contains integer y (1000 ≀ y < 100'000) β€” the year of the calendar. Output Print the only integer y' β€” the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar. Examples Input 2016 Output 2044 Input 2000 Output 2028 Input 50501 Output 50507 Note Today is Monday, the 13th of June, 2016. Submitted Solution: ``` def isleap(n): if n%4==0: if n%100==0: if n%400==0: return True return False return True return False n=int(input()) a=0 for i in range(n+1,n+10000000): if isleap(i): a+=2 else: a+=1 a=a%7 if a==0: if isleap(n): if isleap(i): print(i) break else: if isleap(i): continue else: print(i) break ```
instruction
0
8,020
4
16,040
Yes
output
1
8,020
4
16,041
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year. Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100 (<https://en.wikipedia.org/wiki/Leap_year>). Input The only line contains integer y (1000 ≀ y < 100'000) β€” the year of the calendar. Output Print the only integer y' β€” the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar. Examples Input 2016 Output 2044 Input 2000 Output 2028 Input 50501 Output 50507 Note Today is Monday, the 13th of June, 2016. Submitted Solution: ``` def isleap(y): return y % 400 == 0 or (y % 4 == 0 and y % 100 != 0) y = int(input()) if isleap(y): print(y + 28) elif isleap(y+1): print(y + 5) elif isleap(y + 2): print(y + 11) else: print(y + 6) ```
instruction
0
8,021
4
16,042
No
output
1
8,021
4
16,043
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year. Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100 (<https://en.wikipedia.org/wiki/Leap_year>). Input The only line contains integer y (1000 ≀ y < 100'000) β€” the year of the calendar. Output Print the only integer y' β€” the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar. Examples Input 2016 Output 2044 Input 2000 Output 2028 Input 50501 Output 50507 Note Today is Monday, the 13th of June, 2016. Submitted Solution: ``` import bisect from itertools import accumulate import os import sys import math from decimal import * from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) def input(): return sys.stdin.readline().rstrip("\r\n") def isPrime(n) : if (n <= 1) : return False if (n <= 3) : return True if (n % 2 == 0 or n % 3 == 0) : return False i = 5 while(i * i <= n) : if (n % i == 0 or n % (i + 2) == 0) : return False i = i + 6 return True def SieveOfEratosthenes(n): prime=[] primes = [True for i in range(n+1)] p = 2 while (p * p <= n): if (primes[p] == True): prime.append(p) for i in range(p * p, n+1, p): primes[i] = False p += 1 return prime def primefactors(n): fac=[] while(n%2==0): fac.append(2) n=n//2 for i in range(3,int(math.sqrt(n))+2): while(n%i==0): fac.append(i) n=n//i if n>1: fac.append(n) return fac def factors(n): fac=set() fac.add(1) fac.add(n) for i in range(2,int(math.sqrt(n))+1): if n%i==0: fac.add(i) fac.add(n//i) return list(fac) #------------------------------------------------------code by AD18 n=int(input()) if n%4==0 and n%100!=0: print(n+28) else: print(n+n%6+n%100) ```
instruction
0
8,022
4
16,044
No
output
1
8,022
4
16,045
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year. Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100 (<https://en.wikipedia.org/wiki/Leap_year>). Input The only line contains integer y (1000 ≀ y < 100'000) β€” the year of the calendar. Output Print the only integer y' β€” the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar. Examples Input 2016 Output 2044 Input 2000 Output 2028 Input 50501 Output 50507 Note Today is Monday, the 13th of June, 2016. Submitted Solution: ``` y=int(input()) b=0 y0=y while b%7 or y==y0 or (y0%400==0 or y0%4==0 and y0%100) and not(y%400==0 or y%4==0 and y%100): b+=1 if y%400==0 or y%4==0 and y%100: b+=1 y+=1 print(y) ```
instruction
0
8,023
4
16,046
No
output
1
8,023
4
16,047
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year. Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100 (<https://en.wikipedia.org/wiki/Leap_year>). Input The only line contains integer y (1000 ≀ y < 100'000) β€” the year of the calendar. Output Print the only integer y' β€” the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar. Examples Input 2016 Output 2044 Input 2000 Output 2028 Input 50501 Output 50507 Note Today is Monday, the 13th of June, 2016. Submitted Solution: ``` def is_leap_year(n): return (n % 4 == 0 or n % 400 == 0) or (n % 4 == 0 and n % 100 != 0) def solve(n): if not is_leap_year(n): i, ans = n, 0 while ans != 7: i += 1 ans += 1 if not is_leap_year(i) else 2 return i i, ans = n + 1, 0 while True: ans += 1 if not is_leap_year(i) else 2 if ans % 7 == 0 and is_leap_year(i): return i i += 1 n = int(input()) print(solve(n)) ```
instruction
0
8,024
4
16,048
No
output
1
8,024
4
16,049
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ivan Anatolyevich's agency is starting to become famous in the town. They have already ordered and made n TV commercial videos. Each video is made in a special way: the colors and the soundtrack are adjusted to the time of the day and the viewers' mood. That's why the i-th video can only be shown within the time range of [li, ri] (it is not necessary to use the whole segment but the broadcast time should be within this segment). Now it's time to choose a TV channel to broadcast the commercial. Overall, there are m TV channels broadcasting in the city, the j-th one has cj viewers, and is ready to sell time [aj, bj] to broadcast the commercial. Ivan Anatolyevich is facing a hard choice: he has to choose exactly one video i and exactly one TV channel j to broadcast this video and also a time range to broadcast [x, y]. At that the time range should be chosen so that it is both within range [li, ri] and within range [aj, bj]. Let's define the efficiency of the broadcast as value (y - x)Β·cj β€” the total sum of time that all the viewers of the TV channel are going to spend watching the commercial. Help Ivan Anatolyevich choose the broadcast with the maximum efficiency! Input The first line contains two integers n and m (1 ≀ n, m ≀ 2Β·105) β€” the number of commercial videos and channels, respectively. Each of the following n lines contains two integers li, ri (0 ≀ li ≀ ri ≀ 109) β€” the segment of time when it is possible to show the corresponding video. Each of the following m lines contains three integers aj, bj, cj (0 ≀ aj ≀ bj ≀ 109, 1 ≀ cj ≀ 109), characterizing the TV channel. Output In the first line print an integer β€” the maximum possible efficiency of the broadcast. If there is no correct way to get a strictly positive efficiency, print a zero. If the maximum efficiency is strictly positive, in the second line also print the number of the video i (1 ≀ i ≀ n) and the number of the TV channel j (1 ≀ j ≀ m) in the most effective broadcast. If there are multiple optimal answers, you can print any of them. Examples Input 2 3 7 9 1 4 2 8 2 0 4 1 8 9 3 Output 4 2 1 Input 1 1 0 0 1 1 10 Output 0 Note In the first sample test the most optimal solution is to show the second commercial using the first TV channel at time [2, 4]. The efficiency of such solution is equal to (4 - 2)Β·2 = 4. In the second sample test Ivan Anatolievich's wish does not meet the options of the TV channel, the segments do not intersect, so the answer is zero. Submitted Solution: ``` def intersect(a, b, c, d): if c < a and d > b: return b - a elif c < a: return d - a else: if d > b: return b - c else: return d - c class CodeforcesTask542ASolution: def __init__(self): self.result = '' self.n_m = [] self.videos = [] def read_input(self): self.n_m = [int(x) for x in input().split(" ")] for x in range(self.n_m[0]): self.videos.append([int(y) for y in input().split(" ")]) def process_task(self): eff = [0 for x in range(self.n_m[0])] st = [0 for x in range(self.n_m[0])] for x in range(self.n_m[1]): channel = [int(y) for y in input().split(" ")] neff = [intersect(*v, *channel[:2])*channel[2] for v in self.videos] #eff = [max(eff[x], neff[x]) for x in range(self.n_m[0])] for x in range(self.n_m[0]): if neff[x] > eff[x]: eff[x] = neff[x] st[x] = x + 1 max_eff = max(eff) max_vid = eff.index(max_eff) + 1 max_st = st[max_vid - 1] if max_eff > 0: self.result = "{0}\n{1} {2}".format(max_eff, max_vid, max_st) else: self.result = "0" def get_result(self): return self.result if __name__ == "__main__": Solution = CodeforcesTask542ASolution() Solution.read_input() Solution.process_task() print(Solution.get_result()) ```
instruction
0
8,667
4
17,334
No
output
1
8,667
4
17,335
Provide tags and a correct Python 3 solution for this coding contest problem. Unlucky year in Berland is such a year that its number n can be represented as n = xa + yb, where a and b are non-negative integer numbers. For example, if x = 2 and y = 3 then the years 4 and 17 are unlucky (4 = 20 + 31, 17 = 23 + 32 = 24 + 30) and year 18 isn't unlucky as there is no such representation for it. Such interval of years that there are no unlucky years in it is called The Golden Age. You should write a program which will find maximum length of The Golden Age which starts no earlier than the year l and ends no later than the year r. If all years in the interval [l, r] are unlucky then the answer is 0. Input The first line contains four integer numbers x, y, l and r (2 ≀ x, y ≀ 1018, 1 ≀ l ≀ r ≀ 1018). Output Print the maximum length of The Golden Age within the interval [l, r]. If all years in the interval [l, r] are unlucky then print 0. Examples Input 2 3 1 10 Output 1 Input 3 5 10 22 Output 8 Input 2 3 3 5 Output 0 Note In the first example the unlucky years are 2, 3, 4, 5, 7, 9 and 10. So maximum length of The Golden Age is achived in the intervals [1, 1], [6, 6] and [8, 8]. In the second example the longest Golden Age is the interval [15, 22].
instruction
0
9,577
4
19,154
Tags: brute force, math Correct Solution: ``` p = range(61) x,y,l,r = map(int,input().split()) a = [l-1,r+1] for i in [ x**i for i in p if x**i <= r]: for j in [ y**i for i in p if y**i <= r-i]: if i+j >= l and i+j <= r: a.append(i+j) a.sort() ans = 0 for i in range(1,len(a)): ans = max(ans,a[i] - a[i-1] -1) print(ans) ```
output
1
9,577
4
19,155
Provide tags and a correct Python 3 solution for this coding contest problem. Unlucky year in Berland is such a year that its number n can be represented as n = xa + yb, where a and b are non-negative integer numbers. For example, if x = 2 and y = 3 then the years 4 and 17 are unlucky (4 = 20 + 31, 17 = 23 + 32 = 24 + 30) and year 18 isn't unlucky as there is no such representation for it. Such interval of years that there are no unlucky years in it is called The Golden Age. You should write a program which will find maximum length of The Golden Age which starts no earlier than the year l and ends no later than the year r. If all years in the interval [l, r] are unlucky then the answer is 0. Input The first line contains four integer numbers x, y, l and r (2 ≀ x, y ≀ 1018, 1 ≀ l ≀ r ≀ 1018). Output Print the maximum length of The Golden Age within the interval [l, r]. If all years in the interval [l, r] are unlucky then print 0. Examples Input 2 3 1 10 Output 1 Input 3 5 10 22 Output 8 Input 2 3 3 5 Output 0 Note In the first example the unlucky years are 2, 3, 4, 5, 7, 9 and 10. So maximum length of The Golden Age is achived in the intervals [1, 1], [6, 6] and [8, 8]. In the second example the longest Golden Age is the interval [15, 22].
instruction
0
9,578
4
19,156
Tags: brute force, math Correct Solution: ``` from math import log, ceil x, y, l, r = [int(i) for i in input().split()] ans = 0 nm = ceil(log(r, x)) + 2 mm = ceil(log(r, y)) + 2 v = [l - 1, r + 1] for n in range(nm): for m in range(mm): cur = x ** n + y ** m if cur < l or cur > r: continue v.append(cur) v.sort() for i in range(1, len(v)): ans = max(ans, v[i] - v[i - 1] - 1) print(ans) ```
output
1
9,578
4
19,157
Provide tags and a correct Python 3 solution for this coding contest problem. Unlucky year in Berland is such a year that its number n can be represented as n = xa + yb, where a and b are non-negative integer numbers. For example, if x = 2 and y = 3 then the years 4 and 17 are unlucky (4 = 20 + 31, 17 = 23 + 32 = 24 + 30) and year 18 isn't unlucky as there is no such representation for it. Such interval of years that there are no unlucky years in it is called The Golden Age. You should write a program which will find maximum length of The Golden Age which starts no earlier than the year l and ends no later than the year r. If all years in the interval [l, r] are unlucky then the answer is 0. Input The first line contains four integer numbers x, y, l and r (2 ≀ x, y ≀ 1018, 1 ≀ l ≀ r ≀ 1018). Output Print the maximum length of The Golden Age within the interval [l, r]. If all years in the interval [l, r] are unlucky then print 0. Examples Input 2 3 1 10 Output 1 Input 3 5 10 22 Output 8 Input 2 3 3 5 Output 0 Note In the first example the unlucky years are 2, 3, 4, 5, 7, 9 and 10. So maximum length of The Golden Age is achived in the intervals [1, 1], [6, 6] and [8, 8]. In the second example the longest Golden Age is the interval [15, 22].
instruction
0
9,579
4
19,158
Tags: brute force, math Correct Solution: ``` x,y,lo,h = list(map(int,input().strip().split(' '))) p = 1 q = 1 l = [] l.append(lo-1) l.append(h+1) while p<h : q = 1 while q < h : if lo<= p+q and p+q<= h : l.append(p+q) q*=y p*=x max = 0 l.sort() for i in range(1,len(l)) : if max <= l[i]-l[i-1]-1: max = l[i]-l[i-1]-1 print(max) ```
output
1
9,579
4
19,159
Provide tags and a correct Python 3 solution for this coding contest problem. Unlucky year in Berland is such a year that its number n can be represented as n = xa + yb, where a and b are non-negative integer numbers. For example, if x = 2 and y = 3 then the years 4 and 17 are unlucky (4 = 20 + 31, 17 = 23 + 32 = 24 + 30) and year 18 isn't unlucky as there is no such representation for it. Such interval of years that there are no unlucky years in it is called The Golden Age. You should write a program which will find maximum length of The Golden Age which starts no earlier than the year l and ends no later than the year r. If all years in the interval [l, r] are unlucky then the answer is 0. Input The first line contains four integer numbers x, y, l and r (2 ≀ x, y ≀ 1018, 1 ≀ l ≀ r ≀ 1018). Output Print the maximum length of The Golden Age within the interval [l, r]. If all years in the interval [l, r] are unlucky then print 0. Examples Input 2 3 1 10 Output 1 Input 3 5 10 22 Output 8 Input 2 3 3 5 Output 0 Note In the first example the unlucky years are 2, 3, 4, 5, 7, 9 and 10. So maximum length of The Golden Age is achived in the intervals [1, 1], [6, 6] and [8, 8]. In the second example the longest Golden Age is the interval [15, 22].
instruction
0
9,580
4
19,160
Tags: brute force, math Correct Solution: ``` # Contest: Educational Codeforces Round 22 (https://codeforces.com/contest/813) # Problem: B: The Golden Age (https://codeforces.com/contest/813/problem/B) def rint(): return int(input()) def rints(): return list(map(int, input().split())) x, y, l, r = rints() li = [l - 1, r + 1] for i in range(65): for j in range(65): s = x**i + y**j if l <= s <= r: li.append(s) li = sorted(li) mx = 0 for i in range(len(li) - 1): mx = max(mx, li[i + 1] - li[i] - 1) print(mx) ```
output
1
9,580
4
19,161
Provide tags and a correct Python 3 solution for this coding contest problem. Unlucky year in Berland is such a year that its number n can be represented as n = xa + yb, where a and b are non-negative integer numbers. For example, if x = 2 and y = 3 then the years 4 and 17 are unlucky (4 = 20 + 31, 17 = 23 + 32 = 24 + 30) and year 18 isn't unlucky as there is no such representation for it. Such interval of years that there are no unlucky years in it is called The Golden Age. You should write a program which will find maximum length of The Golden Age which starts no earlier than the year l and ends no later than the year r. If all years in the interval [l, r] are unlucky then the answer is 0. Input The first line contains four integer numbers x, y, l and r (2 ≀ x, y ≀ 1018, 1 ≀ l ≀ r ≀ 1018). Output Print the maximum length of The Golden Age within the interval [l, r]. If all years in the interval [l, r] are unlucky then print 0. Examples Input 2 3 1 10 Output 1 Input 3 5 10 22 Output 8 Input 2 3 3 5 Output 0 Note In the first example the unlucky years are 2, 3, 4, 5, 7, 9 and 10. So maximum length of The Golden Age is achived in the intervals [1, 1], [6, 6] and [8, 8]. In the second example the longest Golden Age is the interval [15, 22].
instruction
0
9,581
4
19,162
Tags: brute force, math Correct Solution: ``` x, y, l, r = list(map(int, input().strip().split(" "))) cx = 1 cy = 1 v = [] while True: if cx > r: break cy = 1 while True: if cx + cy > r: break if cx + cy >= l: v.append(cx + cy) cy = cy * y cx = cx * x v.append(l-1) v.append(r+1) v.sort() vd = [] res = 0 for i in range(len(v)-1): if v[i] == v[i+1]: continue res = max(res, v[i+1] - v[i] - 1) print(res) ```
output
1
9,581
4
19,163