message stringlengths 2 20.2k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 757 108k | cluster float64 4 4 | __index_level_0__ int64 1.51k 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.
Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite impatient. The song's duration is T seconds. Lesha downloads the first S seconds of the song and plays it. When the playback reaches the point that has not yet been downloaded, Lesha immediately plays the song from the start (the loaded part of the song stays in his phone, and the download is continued from the same place), and it happens until the song is downloaded completely and Lesha listens to it to the end. For q seconds of real time the Internet allows you to download q - 1 seconds of the track.
Tell Lesha, for how many times he will start the song, including the very first start.
Input
The single line contains three integers T, S, q (2 ≤ q ≤ 104, 1 ≤ S < T ≤ 105).
Output
Print a single integer — the number of times the song will be restarted.
Examples
Input
5 2 2
Output
2
Input
5 4 7
Output
1
Input
6 2 3
Output
1
Note
In the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice.
In the second test, the song is almost downloaded, and Lesha will start it only once.
In the third sample test the download finishes and Lesha finishes listening at the same moment. Note that song isn't restarted in this case.
Submitted Solution:
```
t, s, q = map(int, input().split())
x = s
ans = 1
while x < t:
ans += 1
x += (q - 1) * s
s = x
print(ans - 1)
``` | instruction | 0 | 76,282 | 4 | 152,564 |
Yes | output | 1 | 76,282 | 4 | 152,565 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.
Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite impatient. The song's duration is T seconds. Lesha downloads the first S seconds of the song and plays it. When the playback reaches the point that has not yet been downloaded, Lesha immediately plays the song from the start (the loaded part of the song stays in his phone, and the download is continued from the same place), and it happens until the song is downloaded completely and Lesha listens to it to the end. For q seconds of real time the Internet allows you to download q - 1 seconds of the track.
Tell Lesha, for how many times he will start the song, including the very first start.
Input
The single line contains three integers T, S, q (2 ≤ q ≤ 104, 1 ≤ S < T ≤ 105).
Output
Print a single integer — the number of times the song will be restarted.
Examples
Input
5 2 2
Output
2
Input
5 4 7
Output
1
Input
6 2 3
Output
1
Note
In the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice.
In the second test, the song is almost downloaded, and Lesha will start it only once.
In the third sample test the download finishes and Lesha finishes listening at the same moment. Note that song isn't restarted in this case.
Submitted Solution:
```
import math, os, sys
import string, re
from itertools import *
from collections import Counter
from operator import mul
def inputint():
return int(input())
def inputarray(func=int):
return map(func, input().split())
def inputarray2(n, func=int):
for _ in range(n):
yield func(input())
T, S, q = inputarray()
i, g = 0, S
while g < T:
i = i + 1
g = g + (q - 1)*g
print(i)
``` | instruction | 0 | 76,283 | 4 | 152,566 |
Yes | output | 1 | 76,283 | 4 | 152,567 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.
Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite impatient. The song's duration is T seconds. Lesha downloads the first S seconds of the song and plays it. When the playback reaches the point that has not yet been downloaded, Lesha immediately plays the song from the start (the loaded part of the song stays in his phone, and the download is continued from the same place), and it happens until the song is downloaded completely and Lesha listens to it to the end. For q seconds of real time the Internet allows you to download q - 1 seconds of the track.
Tell Lesha, for how many times he will start the song, including the very first start.
Input
The single line contains three integers T, S, q (2 ≤ q ≤ 104, 1 ≤ S < T ≤ 105).
Output
Print a single integer — the number of times the song will be restarted.
Examples
Input
5 2 2
Output
2
Input
5 4 7
Output
1
Input
6 2 3
Output
1
Note
In the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice.
In the second test, the song is almost downloaded, and Lesha will start it only once.
In the third sample test the download finishes and Lesha finishes listening at the same moment. Note that song isn't restarted in this case.
Submitted Solution:
```
t,s,q=map(int,input().split())
res=0
while s<t:s*=q;res+=1
print(res)
``` | instruction | 0 | 76,284 | 4 | 152,568 |
Yes | output | 1 | 76,284 | 4 | 152,569 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.
Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite impatient. The song's duration is T seconds. Lesha downloads the first S seconds of the song and plays it. When the playback reaches the point that has not yet been downloaded, Lesha immediately plays the song from the start (the loaded part of the song stays in his phone, and the download is continued from the same place), and it happens until the song is downloaded completely and Lesha listens to it to the end. For q seconds of real time the Internet allows you to download q - 1 seconds of the track.
Tell Lesha, for how many times he will start the song, including the very first start.
Input
The single line contains three integers T, S, q (2 ≤ q ≤ 104, 1 ≤ S < T ≤ 105).
Output
Print a single integer — the number of times the song will be restarted.
Examples
Input
5 2 2
Output
2
Input
5 4 7
Output
1
Input
6 2 3
Output
1
Note
In the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice.
In the second test, the song is almost downloaded, and Lesha will start it only once.
In the third sample test the download finishes and Lesha finishes listening at the same moment. Note that song isn't restarted in this case.
Submitted Solution:
```
T,S,q=map(int,input().split());a=0
while T>S:S*=q;a+=1
print(a)
``` | instruction | 0 | 76,285 | 4 | 152,570 |
Yes | output | 1 | 76,285 | 4 | 152,571 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.
Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite impatient. The song's duration is T seconds. Lesha downloads the first S seconds of the song and plays it. When the playback reaches the point that has not yet been downloaded, Lesha immediately plays the song from the start (the loaded part of the song stays in his phone, and the download is continued from the same place), and it happens until the song is downloaded completely and Lesha listens to it to the end. For q seconds of real time the Internet allows you to download q - 1 seconds of the track.
Tell Lesha, for how many times he will start the song, including the very first start.
Input
The single line contains three integers T, S, q (2 ≤ q ≤ 104, 1 ≤ S < T ≤ 105).
Output
Print a single integer — the number of times the song will be restarted.
Examples
Input
5 2 2
Output
2
Input
5 4 7
Output
1
Input
6 2 3
Output
1
Note
In the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice.
In the second test, the song is almost downloaded, and Lesha will start it only once.
In the third sample test the download finishes and Lesha finishes listening at the same moment. Note that song isn't restarted in this case.
Submitted Solution:
```
t, s, q = map(int, input().split())
cnt = 1
if t > q:
while 1:
s += s
if s >= t:
break
cnt += 1
print(cnt)
``` | instruction | 0 | 76,287 | 4 | 152,574 |
No | output | 1 | 76,287 | 4 | 152,575 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.
Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite impatient. The song's duration is T seconds. Lesha downloads the first S seconds of the song and plays it. When the playback reaches the point that has not yet been downloaded, Lesha immediately plays the song from the start (the loaded part of the song stays in his phone, and the download is continued from the same place), and it happens until the song is downloaded completely and Lesha listens to it to the end. For q seconds of real time the Internet allows you to download q - 1 seconds of the track.
Tell Lesha, for how many times he will start the song, including the very first start.
Input
The single line contains three integers T, S, q (2 ≤ q ≤ 104, 1 ≤ S < T ≤ 105).
Output
Print a single integer — the number of times the song will be restarted.
Examples
Input
5 2 2
Output
2
Input
5 4 7
Output
1
Input
6 2 3
Output
1
Note
In the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice.
In the second test, the song is almost downloaded, and Lesha will start it only once.
In the third sample test the download finishes and Lesha finishes listening at the same moment. Note that song isn't restarted in this case.
Submitted Solution:
```
from math import ceil
T, S, q = map(float, input().split())
print(ceil((q * (T - S)) / (T * (q - 1))))
``` | instruction | 0 | 76,288 | 4 | 152,576 |
No | output | 1 | 76,288 | 4 | 152,577 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.
Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite impatient. The song's duration is T seconds. Lesha downloads the first S seconds of the song and plays it. When the playback reaches the point that has not yet been downloaded, Lesha immediately plays the song from the start (the loaded part of the song stays in his phone, and the download is continued from the same place), and it happens until the song is downloaded completely and Lesha listens to it to the end. For q seconds of real time the Internet allows you to download q - 1 seconds of the track.
Tell Lesha, for how many times he will start the song, including the very first start.
Input
The single line contains three integers T, S, q (2 ≤ q ≤ 104, 1 ≤ S < T ≤ 105).
Output
Print a single integer — the number of times the song will be restarted.
Examples
Input
5 2 2
Output
2
Input
5 4 7
Output
1
Input
6 2 3
Output
1
Note
In the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice.
In the second test, the song is almost downloaded, and Lesha will start it only once.
In the third sample test the download finishes and Lesha finishes listening at the same moment. Note that song isn't restarted in this case.
Submitted Solution:
```
import math
t,s,q=map(int,input().split(" "))
if q-1>=s:
print(1)
else:
print(math.ceil(t/(s+q-1)))
``` | instruction | 0 | 76,289 | 4 | 152,578 |
No | output | 1 | 76,289 | 4 | 152,579 |
Provide a correct Python 3 solution for this coding contest problem.
Animation is one of methods for making movies and in Japan, it is popular to broadcast as a television program or perform as a movie. Many people, especially the young, love one. And here is an anime lover called Jack. We say he is an mysterious guy with uncertain age. He likes anime which are broadcasted in midnight and early morning especially.
In his room, there is a huge piece of paper on the wall. He writes a timetable of TV anime on it. In his house, he can watch all Japanese TV anime programs that are broadcasted in Japan using a secret and countrywide live system. However he can not watch all anime and must give up to watch some programs because they are "broadcasted at the same time" in a season. Here, programs are "broadcasted at the same time" means that two or more programs have one or more common minutes in broadcasting time. Increasing the number of anime programs in recent makes him nervous. Actually, some people buy DVDs after the program series ends or visit a web site called vhefoo. Anyway, he loves to watch programs on his live system. Of course, he is not able to watch two or more programs at the same time. However, as described above, he must give up some programs broadcasted at the same time. Therefore, he has a set of programs F and he watches programs in a set F absolutely.
Your task is to write a program that reads a timetable and outputs the maximum number of watchable programs, keeping that Jack watches all programs in the set F. Of course, there are multiple choices of programs, so we want the number of programs he can watch. If two or more programs in a set F are broadcasted at the same time, you must give Jack an unfortunate announcement. In this case, your program outputs -1. In addition, each anime program is a program of 30 minutes.
Hint
Second dataset: He can watch program E after watching B. Then he can choose a program either I or J after watching H. Therefore he can watch maximum 4 programs.
Constraints
The number of datasets is less than or equal to 400.
1≤N≤500
Input
Input consists of multiple datasets.
A dataset is given in a following format.
N
PROGRAM1
PROGRAM2
...
PROGRAMN
P
FAV1
FAV2
...
FAVP
N is the number of programs in a season.
PROGRAMi(1≤i≤N)is a string which has the following format.
name weekday start
* name is a program name. This is a a string having between 1 and 32 characters and these names do not overlap each other program. A name consists of alphanumeric characters and '_'(underscore).
* weekday is a broadcasting weekday about the corresponding program. This is an integer. 0 means Sunday and 1 is Monday and so on (2:Tuesday, 3:Wednesday, 4:Thursday, 5:Friday, 6:Saturday).
* start is a starting time of the program broadcasting. This is an integer between 600 and 2929. First one or two digits represent hour and the last two digits represent minute. If the hour has one digit it will be a representation "900" for example. Note: a program may have an integer more than or equal to 2400 as start, if the program begins the next day. For example, a program begins from 2500 on Monday should be interpreted as a program begins from 0100 on Tuesday. There are no input the minute of start exceeds 59. And when the hour of start is equal to 29, there are no input the minute of start exceeds 29.
P is an integer and represents the number of elements in the set F. And FAVi(1≤i≤P≤N) is a string for a program name which Jack watches absolutely. You can assume names which are not given in program descriptions will not appear in the set F.
The last line contains a single 0 which represents the end of input.
Output
For each dataset, output an integer S that represents maximum number of programs Jack can watch in the following format.
S
Example
Input
1
galaxy_angel 0 600
1
galaxy_angel
11
A 0 600
B 0 610
C 0 610
D 0 610
E 0 640
EE 0 700
F 0 710
G 0 710
H 0 710
I 0 740
J 0 750
2
B
H
42
nchj 6 2620
anhnnnmewbktthsrn 4 2515
gntmdsh 1 1800
achnnl 4 2540
hnskirh 0 2200
aonexrcst 0 1700
dgdys 6 2330
hdnnara 4 2525
dnpaonntssotk 4 2555
ddmnwndrlnd 6 2500
C 4 2445
astrttnomch 0 2330
seknnqasr 1 2630
sftnt 4 2630
stnsgt 2 2605
drrnenmknmrmr 4 2610
hnzm 6 2713
yndmsoazzlsn 6 2658
mrahlcalv 4 2615
hshzrhkkrhs 1 900
ortchntsbshni 0 2430
kmnmzshrski 1 2530
sktdnc 4 1800
gykkybrkjhkirkhn 2 2459
trk 0 900
30zzsinhkntiik 3 2700
sngkotmmmirprdx 1 2600
yran 2 2529
tntissygntinybu 1 2614
skiichhtki 5 2505
tgrbnny 6 2558
dnbrsnki 3 1927
yugozxl 1 1930
frbllchrmn 1 1928
fjrg 1 1955
shwmngtr 0 2200
xmn 5 2200
rngnkkrskitikihn 0 2100
szysz 0 1254
prttyrythmaulrdrm 6 1000
sckiesfrntrqst 5 1820
mshdr 1 2255
1
mrahlcalv
0
Output
1
4
31 | instruction | 0 | 77,527 | 4 | 155,054 |
"Correct Solution:
```
# AOJ 1063: Watchin' TVA
# Python3 2018.7.8 bal4u
while True:
n = int(input())
if n == 0: break
dic, tbl = {}, []
for i in range(n):
nm, w, s = input().split()
w, s = int(w), int(s)
h, m = s//100, s%100
s = (1440*w + h*60 + m) % 10080
e = s + 30;
tbl.append([s, e, 0, nm])
dic[nm] = i
for i in range(int(input())): tbl[dic[input()]][2] = 1
if n == 1:
print(1)
continue
tbl.sort(key=lambda x:(x[0],x[2]))
for i in range(len(tbl)):
if tbl[i][2]:
k = i
break
ans, i, j = 1, k, k
while True:
j += 1
if i >= n: i = 0
if j >= n: j = 0
if j == k: break
e = tbl[i][1] - 10080 if tbl[i][1] >= 10080 else 0
if (tbl[i][0] <= tbl[j][0] and tbl[j][0] < tbl[i][1]) \
or tbl[j][0] < e:
if tbl[j][2] and tbl[i][2]:
ans = -1
break
elif tbl[j][2]: i = j
elif tbl[j][0] <= tbl[k][0] and tbl[k][0] < tbl[j][1]: pass
else:
ans += 1
i = j
print(ans)
``` | output | 1 | 77,527 | 4 | 155,055 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Cool J has recently become a businessman Mr. Jackson, and he has to make a lot of phone calls now. Today he has n calls planned. For each call we know the moment ti (in seconds since the start of the day) when it is scheduled to start and its duration di (in seconds). All ti are different. Mr. Jackson is a very important person, so he never dials anybody himself, all calls will be incoming.
Mr. Jackson isn't Caesar and he can't do several things at once. If somebody calls him while he hasn't finished the previous conversation, Mr. Jackson puts the new call on hold in the queue. In this case immediately after the end of the current call Mr. Jackson takes the earliest incoming call from the queue and starts the conversation. If Mr. Jackson started the call at the second t, and the call continues for d seconds, then Mr. Jackson is busy at seconds t, t + 1, ..., t + d - 1, and he can start a new call at second t + d. Note that if Mr. Jackson is not busy talking when somebody calls, he can't put this call on hold.
Mr. Jackson isn't Napoleon either, he likes to sleep. So sometimes he allows himself the luxury of ignoring a call, as if it never was scheduled. He can ignore at most k calls. Note that a call which comes while he is busy talking can be ignored as well.
What is the maximum number of seconds Mr. Jackson can sleep today, assuming that he can choose an arbitrary continuous time segment from the current day (that is, with seconds from the 1-st to the 86400-th, inclusive) when he is not busy talking?
Note that some calls can be continued or postponed to the next day or even later. However, the interval for sleep should be completely within the current day.
Input
The first input line contains a pair of integers n, k (0 ≤ k ≤ n ≤ 4000) separated by a space. Following n lines contain the description of calls for today. The description of each call is located on the single line and consists of two space-separated integers ti and di, (1 ≤ ti, di ≤ 86400). All ti are distinct, the calls are given in the order of strict increasing ti.
Scheduled times of calls [ti, ti + di - 1] can arbitrarily intersect.
Output
Print a number from 0 to 86400, inclusive — the maximally possible number of seconds for Mr. Jackson to sleep today.
Examples
Input
3 2
30000 15000
40000 15000
50000 15000
Output
49999
Input
5 1
1 20000
10000 10000
20000 20000
25000 10000
80000 60000
Output
39999
Note
In the first sample the most convenient way is to ignore the first two calls.
In the second sample it is best to ignore the third call. In this case Mr. Jackson will have been speaking:
* first call: from 1-st to 20000-th second,
* second call: from 20001-st to 30000-th second,
* fourth call: from 30001-st to 40000-th second (the third call is ignored),
* fifth call: from 80000-th to 139999-th second.
Thus, the longest period of free time is from the 40001-th to the 79999-th second.
Submitted Solution:
```
def SleepTime(calls):
sleep_times = []
current_time = None
for call in calls:
start_time = call[0]
duration = call[1]
if current_time is None:
sleep_times.append(start_time)
current_time = start_time
elif start_time > current_time:
sleep_times.append(start_time - current_time)
current_time = start_time
current_time += duration
if current_time is None:
current_time = 0
if current_time < 86400:
sleep_times.append(86400 - current_time + 1)
return max(sleep_times)
def SleepTimeWithoutOneCall(calls, k):
sleep_time = SleepTime(calls)
if k <= 0:
return sleep_time
for i in range(0, len(calls)):
new_calls = calls[:]
del new_calls[i]
sleep_time = max(sleep_time, SleepTimeWithoutOneCall(new_calls, k - 1))
return sleep_time
line1 = input()
n = int(line1.split()[0])
k = int(line1.split()[1])
calls = []
for i in range(0, n):
line = input()
start = int(line.split()[0])
duration = int(line.split()[1])
calls.append((start, duration))
print(SleepTimeWithoutOneCall(calls, k))
``` | instruction | 0 | 78,536 | 4 | 157,072 |
No | output | 1 | 78,536 | 4 | 157,073 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Cool J has recently become a businessman Mr. Jackson, and he has to make a lot of phone calls now. Today he has n calls planned. For each call we know the moment ti (in seconds since the start of the day) when it is scheduled to start and its duration di (in seconds). All ti are different. Mr. Jackson is a very important person, so he never dials anybody himself, all calls will be incoming.
Mr. Jackson isn't Caesar and he can't do several things at once. If somebody calls him while he hasn't finished the previous conversation, Mr. Jackson puts the new call on hold in the queue. In this case immediately after the end of the current call Mr. Jackson takes the earliest incoming call from the queue and starts the conversation. If Mr. Jackson started the call at the second t, and the call continues for d seconds, then Mr. Jackson is busy at seconds t, t + 1, ..., t + d - 1, and he can start a new call at second t + d. Note that if Mr. Jackson is not busy talking when somebody calls, he can't put this call on hold.
Mr. Jackson isn't Napoleon either, he likes to sleep. So sometimes he allows himself the luxury of ignoring a call, as if it never was scheduled. He can ignore at most k calls. Note that a call which comes while he is busy talking can be ignored as well.
What is the maximum number of seconds Mr. Jackson can sleep today, assuming that he can choose an arbitrary continuous time segment from the current day (that is, with seconds from the 1-st to the 86400-th, inclusive) when he is not busy talking?
Note that some calls can be continued or postponed to the next day or even later. However, the interval for sleep should be completely within the current day.
Input
The first input line contains a pair of integers n, k (0 ≤ k ≤ n ≤ 4000) separated by a space. Following n lines contain the description of calls for today. The description of each call is located on the single line and consists of two space-separated integers ti and di, (1 ≤ ti, di ≤ 86400). All ti are distinct, the calls are given in the order of strict increasing ti.
Scheduled times of calls [ti, ti + di - 1] can arbitrarily intersect.
Output
Print a number from 0 to 86400, inclusive — the maximally possible number of seconds for Mr. Jackson to sleep today.
Examples
Input
3 2
30000 15000
40000 15000
50000 15000
Output
49999
Input
5 1
1 20000
10000 10000
20000 20000
25000 10000
80000 60000
Output
39999
Note
In the first sample the most convenient way is to ignore the first two calls.
In the second sample it is best to ignore the third call. In this case Mr. Jackson will have been speaking:
* first call: from 1-st to 20000-th second,
* second call: from 20001-st to 30000-th second,
* fourth call: from 30001-st to 40000-th second (the third call is ignored),
* fifth call: from 80000-th to 139999-th second.
Thus, the longest period of free time is from the 40001-th to the 79999-th second.
Submitted Solution:
```
def SleepTime(calls):
if len(calls) == 0:
return 86400
sleep_times = []
current_time = 1
for call in calls:
start_time = call[0]
duration = call[1]
if start_time > current_time:
sleep_times.append(start_time - current_time)
current_time = start_time
current_time += duration
if current_time < 86400:
sleep_times.append(86400 - current_time)
if len(sleep_times) == 0:
return 0
return max(sleep_times)
def SleepTimeWithoutOneCall(calls, k):
sleep_time = SleepTime(calls)
if k <= 0:
return sleep_time
for i in range(0, len(calls)):
new_calls = calls[:]
del new_calls[i]
sleep_time = max(sleep_time, SleepTimeWithoutOneCall(new_calls, k - 1))
return sleep_time
line1 = input()
n = int(line1.split()[0])
k = int(line1.split()[1])
calls = []
for i in range(0, n):
line = input()
start = int(line.split()[0])
duration = int(line.split()[1])
calls.append((start, duration))
print(SleepTimeWithoutOneCall(calls, k))
``` | instruction | 0 | 78,537 | 4 | 157,074 |
No | output | 1 | 78,537 | 4 | 157,075 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Cool J has recently become a businessman Mr. Jackson, and he has to make a lot of phone calls now. Today he has n calls planned. For each call we know the moment ti (in seconds since the start of the day) when it is scheduled to start and its duration di (in seconds). All ti are different. Mr. Jackson is a very important person, so he never dials anybody himself, all calls will be incoming.
Mr. Jackson isn't Caesar and he can't do several things at once. If somebody calls him while he hasn't finished the previous conversation, Mr. Jackson puts the new call on hold in the queue. In this case immediately after the end of the current call Mr. Jackson takes the earliest incoming call from the queue and starts the conversation. If Mr. Jackson started the call at the second t, and the call continues for d seconds, then Mr. Jackson is busy at seconds t, t + 1, ..., t + d - 1, and he can start a new call at second t + d. Note that if Mr. Jackson is not busy talking when somebody calls, he can't put this call on hold.
Mr. Jackson isn't Napoleon either, he likes to sleep. So sometimes he allows himself the luxury of ignoring a call, as if it never was scheduled. He can ignore at most k calls. Note that a call which comes while he is busy talking can be ignored as well.
What is the maximum number of seconds Mr. Jackson can sleep today, assuming that he can choose an arbitrary continuous time segment from the current day (that is, with seconds from the 1-st to the 86400-th, inclusive) when he is not busy talking?
Note that some calls can be continued or postponed to the next day or even later. However, the interval for sleep should be completely within the current day.
Input
The first input line contains a pair of integers n, k (0 ≤ k ≤ n ≤ 4000) separated by a space. Following n lines contain the description of calls for today. The description of each call is located on the single line and consists of two space-separated integers ti and di, (1 ≤ ti, di ≤ 86400). All ti are distinct, the calls are given in the order of strict increasing ti.
Scheduled times of calls [ti, ti + di - 1] can arbitrarily intersect.
Output
Print a number from 0 to 86400, inclusive — the maximally possible number of seconds for Mr. Jackson to sleep today.
Examples
Input
3 2
30000 15000
40000 15000
50000 15000
Output
49999
Input
5 1
1 20000
10000 10000
20000 20000
25000 10000
80000 60000
Output
39999
Note
In the first sample the most convenient way is to ignore the first two calls.
In the second sample it is best to ignore the third call. In this case Mr. Jackson will have been speaking:
* first call: from 1-st to 20000-th second,
* second call: from 20001-st to 30000-th second,
* fourth call: from 30001-st to 40000-th second (the third call is ignored),
* fifth call: from 80000-th to 139999-th second.
Thus, the longest period of free time is from the 40001-th to the 79999-th second.
Submitted Solution:
```
def SleepTime(calls):
if len(calls) == 0:
return 86400
sleep_times = []
current_time = 1
for call in calls:
start_time = call[0]
duration = call[1]
if start_time > current_time:
sleep_times.append(start_time - current_time)
current_time = start_time
current_time += duration
if current_time < 86400:
sleep_times.append(86400 - current_time)
if len(sleep_times) == 0:
return 0
return max(sleep_times)
def SleepTimeWithoutOneCall(calls, k):
sleep_time = SleepTime(calls)
if k <= 0:
return sleep_time
for i in range(0, len(calls) - 1):
new_calls = calls[:]
del new_calls[i]
sleep_time = max(sleep_time, SleepTimeWithoutOneCall(new_calls, k - 1))
return sleep_time
line1 = input()
n = int(line1.split()[0])
k = int(line1.split()[1])
calls = []
for i in range(0, n):
line = input()
start = int(line.split()[0])
duration = int(line.split()[1])
calls.append((start, duration))
print(SleepTimeWithoutOneCall(calls, k))
``` | instruction | 0 | 78,538 | 4 | 157,076 |
No | output | 1 | 78,538 | 4 | 157,077 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were x details in the factory storage, then by the end of the day the factory has to produce <image> (remainder after dividing x by m) more details. Unfortunately, no customer has ever bought any mythical detail, so all the details produced stay on the factory.
The board of directors are worried that the production by the given plan may eventually stop (that means that there will be а moment when the current number of details on the factory is divisible by m).
Given the number of details a on the first day and number m check if the production stops at some moment.
Input
The first line contains two integers a and m (1 ≤ a, m ≤ 105).
Output
Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No".
Examples
Input
1 5
Output
No
Input
3 6
Output
Yes
Submitted Solution:
```
l=list(map(int,input().split()))
a=l[0]
m=l[1]
f=False
i=1
while(i<=17 and f==False):
if(a%m==0):
print('Yes')
f=True
else:
a*=2
i+=1
if(f==False):
print('No')
``` | instruction | 0 | 78,661 | 4 | 157,322 |
Yes | output | 1 | 78,661 | 4 | 157,323 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were x details in the factory storage, then by the end of the day the factory has to produce <image> (remainder after dividing x by m) more details. Unfortunately, no customer has ever bought any mythical detail, so all the details produced stay on the factory.
The board of directors are worried that the production by the given plan may eventually stop (that means that there will be а moment when the current number of details on the factory is divisible by m).
Given the number of details a on the first day and number m check if the production stops at some moment.
Input
The first line contains two integers a and m (1 ≤ a, m ≤ 105).
Output
Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No".
Examples
Input
1 5
Output
No
Input
3 6
Output
Yes
Submitted Solution:
```
string = input()
numbers = string.split()
a, b = int(numbers[0]), int(numbers[1])
n = a % b
while b % 2 == 0:
b //= 2
if n % b == 0:
print("Yes")
else:
print("No")
``` | instruction | 0 | 78,662 | 4 | 157,324 |
Yes | output | 1 | 78,662 | 4 | 157,325 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were x details in the factory storage, then by the end of the day the factory has to produce <image> (remainder after dividing x by m) more details. Unfortunately, no customer has ever bought any mythical detail, so all the details produced stay on the factory.
The board of directors are worried that the production by the given plan may eventually stop (that means that there will be а moment when the current number of details on the factory is divisible by m).
Given the number of details a on the first day and number m check if the production stops at some moment.
Input
The first line contains two integers a and m (1 ≤ a, m ≤ 105).
Output
Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No".
Examples
Input
1 5
Output
No
Input
3 6
Output
Yes
Submitted Solution:
```
import sys, os.path
from collections import*
from copy import*
import math
mod=10**9+7
if(os.path.exists('input.txt')):
sys.stdin = open("input.txt","r")
sys.stdout = open("output.txt","w")
a,m=map(int,input().split())
d={}
flag=0
while(1):
if(a%m==0):
flag=2
break
t=a%m
a+=t
if t not in d:
d[t]=1
else:
flag=1
break
if(flag==1):
print('No')
if(flag==2):
print('Yes')
``` | instruction | 0 | 78,663 | 4 | 157,326 |
Yes | output | 1 | 78,663 | 4 | 157,327 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were x details in the factory storage, then by the end of the day the factory has to produce <image> (remainder after dividing x by m) more details. Unfortunately, no customer has ever bought any mythical detail, so all the details produced stay on the factory.
The board of directors are worried that the production by the given plan may eventually stop (that means that there will be а moment when the current number of details on the factory is divisible by m).
Given the number of details a on the first day and number m check if the production stops at some moment.
Input
The first line contains two integers a and m (1 ≤ a, m ≤ 105).
Output
Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No".
Examples
Input
1 5
Output
No
Input
3 6
Output
Yes
Submitted Solution:
```
a, m = list(map(int, input().split()))
for i in range(30):
if (a * (2 ** i) % m == 0):
print("Yes")
exit(0)
print("No")
``` | instruction | 0 | 78,664 | 4 | 157,328 |
Yes | output | 1 | 78,664 | 4 | 157,329 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were x details in the factory storage, then by the end of the day the factory has to produce <image> (remainder after dividing x by m) more details. Unfortunately, no customer has ever bought any mythical detail, so all the details produced stay on the factory.
The board of directors are worried that the production by the given plan may eventually stop (that means that there will be а moment when the current number of details on the factory is divisible by m).
Given the number of details a on the first day and number m check if the production stops at some moment.
Input
The first line contains two integers a and m (1 ≤ a, m ≤ 105).
Output
Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No".
Examples
Input
1 5
Output
No
Input
3 6
Output
Yes
Submitted Solution:
```
a, m = map(int, input().split())
check = [0] * m
cnt = 0
while cnt < m:
if check[a % m]:
break
cnt += 1
check[a % m] = 1
a += a % m
if cnt < m - 1:
print("Yes")
else:
print("No")
``` | instruction | 0 | 78,665 | 4 | 157,330 |
No | output | 1 | 78,665 | 4 | 157,331 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were x details in the factory storage, then by the end of the day the factory has to produce <image> (remainder after dividing x by m) more details. Unfortunately, no customer has ever bought any mythical detail, so all the details produced stay on the factory.
The board of directors are worried that the production by the given plan may eventually stop (that means that there will be а moment when the current number of details on the factory is divisible by m).
Given the number of details a on the first day and number m check if the production stops at some moment.
Input
The first line contains two integers a and m (1 ≤ a, m ≤ 105).
Output
Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No".
Examples
Input
1 5
Output
No
Input
3 6
Output
Yes
Submitted Solution:
```
import math
def is_prime(x):
for i in range(2, int(math.sqrt(x) + 1)):
if x % i == 0:
return False;
return True;
a, m = input().split()
a = int(a)
m = int(m)
if m < 3:
print("Yes")
else:
if is_prime(m) and a % m != 0:
print("No")
else:
print("Yes")
``` | instruction | 0 | 78,666 | 4 | 157,332 |
No | output | 1 | 78,666 | 4 | 157,333 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were x details in the factory storage, then by the end of the day the factory has to produce <image> (remainder after dividing x by m) more details. Unfortunately, no customer has ever bought any mythical detail, so all the details produced stay on the factory.
The board of directors are worried that the production by the given plan may eventually stop (that means that there will be а moment when the current number of details on the factory is divisible by m).
Given the number of details a on the first day and number m check if the production stops at some moment.
Input
The first line contains two integers a and m (1 ≤ a, m ≤ 105).
Output
Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No".
Examples
Input
1 5
Output
No
Input
3 6
Output
Yes
Submitted Solution:
```
from math import log
a,m = map(int,input().split())
k = 1
h = log(m,2)
while k <= h:
if (a * (2 ** k)) % m == 0:
print('Yes')
break
k += 1
else:
print('No')
``` | instruction | 0 | 78,667 | 4 | 157,334 |
No | output | 1 | 78,667 | 4 | 157,335 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were x details in the factory storage, then by the end of the day the factory has to produce <image> (remainder after dividing x by m) more details. Unfortunately, no customer has ever bought any mythical detail, so all the details produced stay on the factory.
The board of directors are worried that the production by the given plan may eventually stop (that means that there will be а moment when the current number of details on the factory is divisible by m).
Given the number of details a on the first day and number m check if the production stops at some moment.
Input
The first line contains two integers a and m (1 ≤ a, m ≤ 105).
Output
Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No".
Examples
Input
1 5
Output
No
Input
3 6
Output
Yes
Submitted Solution:
```
a,m=map(int,input().split())
f=1
while a<=10**6:
a1=a+a%m
if a1==a:
f=0
break
a=a1
if f:
print('No')
else:
print('Yes')
``` | instruction | 0 | 78,668 | 4 | 157,336 |
No | output | 1 | 78,668 | 4 | 157,337 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 ≤ h1 < h2 ≤ 105) — the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 ≤ a, b ≤ 105) — the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k — the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day. | instruction | 0 | 78,713 | 4 | 157,426 |
Tags: implementation, math
Correct Solution:
```
#http://codeforces.com/contest/652/problem/A
# h_cat, h_app, day_up, day_down = [map(int, input().split()), map(int,input().split())]
def dprint(str):
pstatus = False
if pstatus == True:
print(str)
def check_cat():
from math import ceil
from operator import add
# h_string = '10 30'
# speed_string = '2 1'
# h_string = '10 13'
# speed_string = '1 1'
# h_string = '1 50'
# speed_string = '5 4'
# h_string = '10 19'
# speed_string = '1 2'
# h_string = '1 1000'
# speed_string = '2 1'
h_string = input()
speed_string = input()
h_cat, h_app = map(int, h_string.split())
day_up, day_down = map(int, speed_string.split())
day_sub = [4*day_up, 8*day_up, -12*day_down]
flag = False
day_loc = [0, h_cat]
current_pos = day_loc[1]
day_counter = 0
i1 = 0
if sum(day_sub) <=0: #overall negative or zero progress
if (h_cat + day_sub[1] >= h_app): #reach the apple in first day
return(0)
else:
return(-1)
while not flag:
if current_pos >= h_app:
flag = True
break
else:
i1 += 1
current_pos += day_sub[i1%3]
day_loc.append(current_pos)
dprint(day_loc)
day_counter = i1
dprint(day_counter)
dprint(day_counter%3)
return(int(day_counter/3))
output = check_cat()
print(output)
``` | output | 1 | 78,713 | 4 | 157,427 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 ≤ h1 < h2 ≤ 105) — the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 ≤ a, b ≤ 105) — the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k — the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day. | instruction | 0 | 78,714 | 4 | 157,428 |
Tags: implementation, math
Correct Solution:
```
import math
h1, h2 = map(int, input().split())
a, b = map(int, input().split())
d, v = h2 - h1 - 8 * a, 12 * (a - b)
if d <= 0:
print(0)
elif b >= a:
print(-1)
else:
print(math.ceil(d/v))
``` | output | 1 | 78,714 | 4 | 157,429 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 ≤ h1 < h2 ≤ 105) — the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 ≤ a, b ≤ 105) — the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k — the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day. | instruction | 0 | 78,715 | 4 | 157,430 |
Tags: implementation, math
Correct Solution:
```
h1,h2=map(int,input().split())
a,b=map(int,input().split())
hc=h1
if(b>=a and h2>h1+8*a):
print(-1)
else:
d=0;hc=h1+8*a
# if(hc>=h2):
# print(0)
# else:
while(hc<h2):
d+=1
hc+=(12*a-12*b)
print(d)
``` | output | 1 | 78,715 | 4 | 157,431 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 ≤ h1 < h2 ≤ 105) — the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 ≤ a, b ≤ 105) — the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k — the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day. | instruction | 0 | 78,716 | 4 | 157,432 |
Tags: implementation, math
Correct Solution:
```
h1, h2 = map(int, input().split())
a, b = map(int, input().split())
day = 0
while h1 < h2:
if day == 0:
h1 += a * 8
if h1 < h2 and b >= a:
print(-1)
break
elif h1 < h2:
h1 -= b * 12
day += 1
while h1 < h2:
h1 += a * 12
if h1 < h2:
h1 -= b * 12
day += 1
print(day)
``` | output | 1 | 78,716 | 4 | 157,433 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 ≤ h1 < h2 ≤ 105) — the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 ≤ a, b ≤ 105) — the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k — the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day. | instruction | 0 | 78,717 | 4 | 157,434 |
Tags: implementation, math
Correct Solution:
```
from collections import deque, defaultdict, Counter
from itertools import product, groupby, permutations, combinations
from math import gcd, floor, inf
from bisect import bisect_right, bisect_left
h1, h2 = map(int, input().split())
h2 -= h1
a, b = map(int, input().split())
if a <= b and h2 > a * 8:
print(-1)
elif a * 8 >= h2:
print(0)
else:
h2 -= 8*a
dif = (a-b) * 12
ans = (h2+dif-1)//dif
print(ans)
``` | output | 1 | 78,717 | 4 | 157,435 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 ≤ h1 < h2 ≤ 105) — the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 ≤ a, b ≤ 105) — the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k — the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day. | instruction | 0 | 78,718 | 4 | 157,436 |
Tags: implementation, math
Correct Solution:
```
h1,h2=map(int,input().split())
a,b= map(int,input().split())
if (h1+(8*a)) >= h2:
print(0)
elif a>b:
cal = h2 - h1 - 8 * a;
cal2 = 12 * (a - b);
ans = (cal + cal2 - 1) // cal2;
print(ans)
else:
print(-1)
``` | output | 1 | 78,718 | 4 | 157,437 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 ≤ h1 < h2 ≤ 105) — the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 ≤ a, b ≤ 105) — the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k — the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day. | instruction | 0 | 78,719 | 4 | 157,438 |
Tags: implementation, math
Correct Solution:
```
from collections import *
import os, sys
from io import BytesIO, IOBase
def main():
h1, h2 = rints()
a, b = rints()
h1 += 8 * a
if h1 >= h2:
print(0)
elif a <= b:
print(-1)
else:
be, en = 1, 10 ** 6
while be < en:
md = (be + en) >> 1
val = h1 + 12 * md * (a - b)
if val >= h2:
en = md
else:
be = md + 1
print(en)
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")
BUFSIZE = 8192
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
rstr = lambda: input().strip()
rstrs = lambda: [str(x) for x in input().split()]
rstr_2d = lambda n: [rstr() for _ in range(n)]
rint = lambda: int(input())
rints = lambda: [int(x) for x in input().split()]
rint_2d = lambda n: [rint() for _ in range(n)]
rints_2d = lambda n: [rints() for _ in range(n)]
ceil1 = lambda a, b: (a + b - 1) // b
if __name__ == '__main__':
main()
``` | output | 1 | 78,719 | 4 | 157,439 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 ≤ h1 < h2 ≤ 105) — the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 ≤ a, b ≤ 105) — the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k — the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day. | instruction | 0 | 78,720 | 4 | 157,440 |
Tags: implementation, math
Correct Solution:
```
a,b = map(int,input().split())
c,d = map(int,input().split())
f = 0
a = a-(c*4)
while True:
a += c*12
if a >= b:
break
elif d>=c:
f = -1
break
else:
a -= d*12
f += 1
print(f)
``` | output | 1 | 78,720 | 4 | 157,441 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 ≤ h1 < h2 ≤ 105) — the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 ≤ a, b ≤ 105) — the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k — the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
Submitted Solution:
```
h1, h2 = map(int, input().split(' '))
h = h2 - h1
a, b = map(int, input().split())
h -= a * 8
if h <= 0:
print (0)
elif a <= b:
print(-1)
else:
h -= 1
print(h // (12 * (a - b)) + 1)
``` | instruction | 0 | 78,721 | 4 | 157,442 |
Yes | output | 1 | 78,721 | 4 | 157,443 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 ≤ h1 < h2 ≤ 105) — the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 ≤ a, b ≤ 105) — the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k — the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
Submitted Solution:
```
h1,h2=map(int,input().split())
a,b=map(int,input().split())
if b>=a and h2-h1>8*a:
print(-1)
else:
if h2-h1<=8*a:
print(0)
else:
ans=20
h1+=8*a
h1=h1-12*b
f=False
while(h2>h1):
if f==False:
for i in range(1,13):
if (h2>h1):
h1+=a
ans+=1
else:
f=True
break
if f==False:
for i in range(1,13):
if (h2>h1):
h1-=b
ans+=1
else:
f=True
break
if ans%24==21 or ans%24==22 or ans%24==23:
print(1 + ans//24)
else:
print(ans//24)
``` | instruction | 0 | 78,722 | 4 | 157,444 |
Yes | output | 1 | 78,722 | 4 | 157,445 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 ≤ h1 < h2 ≤ 105) — the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 ≤ a, b ≤ 105) — the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k — the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
Submitted Solution:
```
def pillar():
temp=input().split()
bugHeight=int(temp[0])
appleHeight=int(temp[1])
temp=input().split()
dayRate=int(temp[0])
nightRate=int(temp[1])
if(dayRate*8+bugHeight>=appleHeight):
return 0
else:
bugHeight+=dayRate*8-nightRate*12
if(bugHeight+(dayRate*12)<appleHeight and nightRate>=dayRate):
return -1
if(appleHeight-(bugHeight+12*dayRate)<=0):
return 1
temp=((appleHeight-(bugHeight+12*dayRate))/(dayRate*12.0-12*nightRate))
if(temp==int(temp)):
return int(temp)+1
return int(temp)+2
print(pillar())
``` | instruction | 0 | 78,724 | 4 | 157,448 |
Yes | output | 1 | 78,724 | 4 | 157,449 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 ≤ h1 < h2 ≤ 105) — the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 ≤ a, b ≤ 105) — the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k — the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
Submitted Solution:
```
import math
h1, h2 = map(int, input().split())
a, b = map(int, input().split())
if h1 + 8 * a >= h2:
print(0)
else:
if 20*a-12*b<=0:
print(-1)
else:
print(math.ceil((h2-h1)/(20*a-12*b)))
``` | instruction | 0 | 78,725 | 4 | 157,450 |
No | output | 1 | 78,725 | 4 | 157,451 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 ≤ h1 < h2 ≤ 105) — the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 ≤ a, b ≤ 105) — the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k — the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
Submitted Solution:
```
[h1, h2] = list(map(int, input().split()))
[a, b] = list(map(int, input().split()))
if h1+8*a >= h2:
print(0)
exit(0)
elif a <= b:
print(-1)
exit(0)
d = h1+8*a;
res = int( (h2-d)/(12*(a-b)) );
print(res)
``` | instruction | 0 | 78,726 | 4 | 157,452 |
No | output | 1 | 78,726 | 4 | 157,453 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 ≤ h1 < h2 ≤ 105) — the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 ≤ a, b ≤ 105) — the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k — the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
Submitted Solution:
```
h1,h2=map(int,input().split())
a,b=map(int,input().split())
if b>=a and h2-h1>8*a:
print(-1)
else:
if h2-h1<=8*a:
print(0)
else:
ans=20
h1+=8*a
h1=h1-12*b
f=False
while(h2>h1):
if f==False:
for i in range(1,13):
if (h2>h1):
h1+=a
ans+=1
else:
f=True
break
if f==False:
for i in range(1,13):
print("Loop-3")
if (h2>h1):
h1-=b
ans+=1
else:
f=True
break
if ans%24==21 or ans%24==22 or ans%24==23:
print(1 + ans//24)
else:
print(ans//24)
``` | instruction | 0 | 78,727 | 4 | 157,454 |
No | output | 1 | 78,727 | 4 | 157,455 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 ≤ h1 < h2 ≤ 105) — the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 ≤ a, b ≤ 105) — the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k — the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
Submitted Solution:
```
'__author__'=='deepak Singh Mehta) '
if __name__=='__main__':
h1,h2 = map(int,input().split())
a,b = map(int,input().split())
if b>a:
print(-1)
elif a==b:
if (h2-h1) <= (a*12)-(b*12)+(a*12):
print(0)
else:
print(-1)
else:
k = h2-h1
s = ((a*12)-(b*12))+(a*12)
print(s//k)
``` | instruction | 0 | 78,728 | 4 | 157,456 |
No | output | 1 | 78,728 | 4 | 157,457 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09 | instruction | 0 | 78,749 | 4 | 157,498 |
Tags: brute force, implementation
Correct Solution:
```
n=int(input())
s=input().split(':')
hh=s[0]
mm=s[1]
h=hh
m=mm
if(n==12):
if(int(hh)>12 and int(hh)%10!=0):
h="0"+hh[1]
elif(int(hh)>12):
h="10"
if(int(hh)==0):
h="10"
if(int(mm)>59):
m="0"+mm[1]
else:
if(int(hh)>23):
h="0"+hh[1]
if(int(mm)>59):
m="0"+mm[1]
print(h+":"+m)
``` | output | 1 | 78,749 | 4 | 157,499 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09 | instruction | 0 | 78,750 | 4 | 157,500 |
Tags: brute force, implementation
Correct Solution:
```
n=int(input())
s=input()
hr,mn=s[:2],s[3:]
h,m=int(hr),int(mn)
if n==24:
if h<24 and m<60:
print(hr+":"+mn)
elif h>=24 and m>60:
print('0'+hr[1]+":0"+mn[1])
elif m>=60:
print(hr+":0"+mn[1])
else:
print("0"+hr[1]+":"+mn)
else:
if h<13 and h>0 and m<60:
print(hr+":"+mn)
elif h==0 and m>=60:
print("01:0"+mn[1])
elif h==0 and m<60:
print("01:"+mn)
elif h>12 and m>60:
print("0"+hr[1]+":0"+mn[1])
elif m>=60:
print(hr+":0"+mn[1])
elif hr[1]!='0':
print('0'+hr[1]+":"+mn)
else:
print('10:'+mn)
``` | output | 1 | 78,750 | 4 | 157,501 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09 | instruction | 0 | 78,751 | 4 | 157,502 |
Tags: brute force, implementation
Correct Solution:
```
f = int(input())
h, m = map(list, input().split(":"))
h = list(map(int, h))
m = list(map(int, m))
if f == 12:
if h[0] == 0 and h[1] == 0:
h[1] = 1
elif h[0] == 1:
if h[1] > 2:
h[1] = 0
elif h[0] > 1:
if h[1] == 0:
h[0] = 1
else:
h[0] = 0
if f == 24:
if h[0] > 2:
h[0] = 0
if h[0] == 2:
if h[1] > 3:
h[1] = 0
if m[0] > 5:
m[0] = 0
print(''.join(map(str, h)) + ":" + ''.join(map(str, m)))
``` | output | 1 | 78,751 | 4 | 157,503 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09 | instruction | 0 | 78,752 | 4 | 157,504 |
Tags: brute force, implementation
Correct Solution:
```
w=int(input(''))
q=input('')
qe=q[0]
qr=q[1]
qq=qe+qr
wq=q[3]
we=q[4]
ww=wq+we
if w==12:
qq=int(qq)
ww=int(ww)
qe=int(qe)
if qq==00:
qr='1'
if qq>12:
if qe>0:
qq='1'+qr
qq=int(qq)
if qq>12:
qq='0'+qr
else:
qe=str(qe)
qq=qe+qr
else:
qq=int(qq)
ww=int(ww)
if qq>23:
qq='0'+qr
else:
qq=qe+qr
if ww>=60:
ww='0'+we
else:
ww=wq+we
qq=str(qq)
print(qq+':'+ww)
``` | output | 1 | 78,752 | 4 | 157,505 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09 | instruction | 0 | 78,753 | 4 | 157,506 |
Tags: brute force, implementation
Correct Solution:
```
def get(x):
if (x < 10):
return "0" + str(x)
return str(x)
def diff(a, b):
ans = 0
for i in range(len(a)):
if (a[i] != b[i]):
ans += 1
return ans
x = int(input())
s = input()
if (x == 12):
best = "01:30"
for a in range(1, 13):
for b in range(60):
h = get(a) + ":" + get(b)
if (diff(s, h) < diff(best, s)):
best = h
print(best)
else:
best = "01:30"
for a in range(24):
for b in range(60):
h = get(a) + ":" + get(b)
if (diff(s, h) < diff(best, s)):
best = h
print(best)
``` | output | 1 | 78,753 | 4 | 157,507 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09 | instruction | 0 | 78,754 | 4 | 157,508 |
Tags: brute force, implementation
Correct Solution:
```
'''input
24
24:00
'''
n = int(input())
a, b = map(int, input().split(":"))
if b > 59:
b = "0" + str(b)[-1]
if a > n or a == 24:
a = "0" + str(a)[-1]
if n == 12 and int(a) % 10 == 0:
a = "1" + str(a)[-1]
if int(a) > 12:
a = "10"
if a == 0 and n == 12:
a = "01"
a, b = str(a), str(b)
print(a.zfill(2), b.zfill(2), sep=":")
``` | output | 1 | 78,754 | 4 | 157,509 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09 | instruction | 0 | 78,755 | 4 | 157,510 |
Tags: brute force, implementation
Correct Solution:
```
# your code goes here
t = input()
t = int(t)
x,y = input().split(':')
x = int(x)
y = int(y)
if(t==24):
if(x>23):
x = x%10
if(y>59):
y = y%10
else:
if(y>59):
y = y%10
else:
if(x==0):
x = 1
if(y>59):
y = y%10
elif(x>12):
if(x%10==0):
x=10
else:
x=x%10
if(y>59):
y = y%10
else:
if(y>59):
y = y%10
if(y<10):
y = str(y)
y = "0" + y
if(x<10):
x = str(x)
x = "0" + x
print(x,":",y,sep="")
``` | output | 1 | 78,755 | 4 | 157,511 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09 | instruction | 0 | 78,756 | 4 | 157,512 |
Tags: brute force, implementation
Correct Solution:
```
# 722A
# θ(1) time
# θ(1) space
__author__ = 'artyom'
# SOLUTION
def main():
s = read(0)
t = read(0).split(':')
if s == '12':
if t[0][1] == '0':
t[0] = '10'
elif int(t[0]) > 12:
t[0] = '0' + t[0][1]
elif int(t[0]) > 23:
t[0] = '0' + t[0][1]
if int(t[1]) > 59:
t[1] = '0' + t[1][1]
return t[0] + ':' + t[1]
# HELPERS
def read(mode=1, size=None):
# 0: String
# 1: Integer
# 2: List of strings
# 3: List of integers
# 4: Matrix of integers
if mode == 0: return input().strip()
if mode == 1: return int(input().strip())
if mode == 2: return input().strip().split()
if mode == 3: return list(map(int, input().strip().split()))
a = []
for _ in range(size):
a.append(read(3))
return a
def write(s="\n"):
if s is None: s = ''
if isinstance(s, tuple) or isinstance(s, list): s = ' '.join(map(str, s))
s = str(s)
print(s, end="\n")
write(main())
``` | output | 1 | 78,756 | 4 | 157,513 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
Submitted Solution:
```
def l(s1, s2):
return len(list(i for i in range(len(s1)) if s1[i] != s2[i]))
c = int(input())
if c == 12:
h = list(range(1, 13))
else:
h = list(range(0, 24))
s = input()
min_s = ""
min_l = 100
for x in h:
for y in range(60):
new_s = "{0:02}:{1:02}".format(x,y)
if l(s, new_s) < min_l:
min_l = l(s, new_s)
min_s = new_s
print(min_s)
``` | instruction | 0 | 78,757 | 4 | 157,514 |
Yes | output | 1 | 78,757 | 4 | 157,515 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
Submitted Solution:
```
system = int(input())
r =[c for c in input()]
if int(r[3]) > 5 :
r[3]='0'
if (system == 12) and int(r[1])!= 0 and int(r[0]) > 2 :
r[0]='0'
elif (system == 12) and ( (int(r[0])>1 and int(r[1])!= 0) or (int(r[0])==1 and int(r[1])>2) ) :
r[0]='0'
elif (system == 24) and ( int(r[0])>2 or (int(r[0])==2 and int(r[1])>3) ) :
r[0]='0'
elif (system == 12) and ( int(r[0])>1 and int(r[1])== 0) :
r[0]='1'
if (system == 12) and (int(r[0])>1 or r[0]=='0') and r[1] == '0' :
r[1]='1'
print( "".join(r) )
``` | instruction | 0 | 78,758 | 4 | 157,516 |
Yes | output | 1 | 78,758 | 4 | 157,517 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
Submitted Solution:
```
#Codeforces 722A
format = input()
time = list(input().split(':'))
if format == '12':
if time[0] == '00':
time[0] = '01'
elif int(time[0]) > 12:
r = '0'
if int(time[0])%10 == 0:
r = '1'
time[0] = r + time[0][-1]
elif format == '24':
if int(time[0]) > 23:
time[0] = '1' + time[0][-1]
if int(time[1]) > 59:
time[1] = '1' + time[1][-1]
print(time[0] + ":" + time[1])
``` | instruction | 0 | 78,759 | 4 | 157,518 |
Yes | output | 1 | 78,759 | 4 | 157,519 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
Submitted Solution:
```
def main():
n = int(input())
hours, minutes = input().split(':')
hours_1 = ''
minutes_1=''
if n == 24:
if int(hours) >= 24:
hours_1 += '0'+hours[1]
else:
hours_1 += hours
if int(minutes) > 59:
minutes_1 += '0' + minutes[1]
else:
minutes_1 += minutes
else:
if int(hours) > 12 and int(hours) % 10 != 0:
hours_1 += '0' + hours[1]
elif int(hours) % 10 == 0:
hours_1 += '10'
else:
hours_1 += hours
if int(minutes) > 59:
minutes_1 += '0' + minutes[1]
else:
minutes_1 += minutes
print('{}:{}'.format(hours_1, minutes_1))
return
if __name__=="__main__":
main()
``` | instruction | 0 | 78,760 | 4 | 157,520 |
Yes | output | 1 | 78,760 | 4 | 157,521 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
Submitted Solution:
```
import math as m
def main():
time = int(input())
x, y = [int(i) for i in input().split(':')]
if y//10>5:
y=y%10+50
if time==24:
if x//10>2:
x=x%10
if(x%10>=4) and (x//10>=2):
x=x-x%10+3
else:
if x//10>1:
x=x%10
if (x%10>=2) and (x//10>=1):
x=x - x%10 + 1
if(x<10):
print('0', end='')
print(x, ':', y, sep='')
main()
``` | instruction | 0 | 78,761 | 4 | 157,522 |
No | output | 1 | 78,761 | 4 | 157,523 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
Submitted Solution:
```
import logging
import copy
import sys
import math
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
#def solve(firstLine):
def solve(formatStr, timeStr):
if int(timeStr[3]) > 5 :
timeStr = timeStr[:3] + "0" + timeStr[4:]
if formatStr == 24:
if int(timeStr[0]) > 2:
timeStr = "0" + timeStr[1:]
elif int(timeStr[0]) == 2 and int(timeStr[1]) > 4:
timeStr = timeStr[0] + "0" + timeStr[2:]
if formatStr == 12:
if int(timeStr[0]) > 1:
timeStr = "0" + timeStr[1:]
elif int(timeStr[0]) == 1 and int(timeStr[1]) > 2:
timeStr = "0" + timeStr[1:]
elif int(timeStr[0]) == 0 and int(timeStr[1]) > 0:
timeStr = "01" + timeStr[2:]
return timeStr
def main():
formatStr = int(input())
print(solve(formatStr, input()))
def log(*message):
logging.debug(message)
if __name__ == "__main__":
main()
``` | instruction | 0 | 78,762 | 4 | 157,524 |
No | output | 1 | 78,762 | 4 | 157,525 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
Submitted Solution:
```
import sys
frmt = int(sys.stdin.readline())
hh, mm = map(int, sys.stdin.read().split(':'))
#fix minutes
mms = ''
if mm > 59:
mms = '5' + str(mm % 10)
else:
mms = str(mm).zfill(2)
#fix hours
if frmt == 24:
frmt -= 1
hhs = ''
if hh > frmt:
hhs = '0' + str(hh % 10)
elif (frmt == 12) and (hh == 0):
hhs = '01'
else:
hhs = str(hh).zfill(2)
print(hhs + ':' + mms)
``` | instruction | 0 | 78,763 | 4 | 157,526 |
No | output | 1 | 78,763 | 4 | 157,527 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
Submitted Solution:
```
formats=int(input())
s=input()
hour=int(s[0]+s[1])
hours=s[0]+s[1]
q=hours
minute=int(s[3]+s[4])
minutes=s[3]+s[4]
if hour>formats or hour==0:
hour=int("0"+hours[1])
hours="0"+hours[1]
if hours[1]=="0" and hours[0]!="1" and hours[0]!="0":
hour=9
hours=str(hour)
if len(hours)==1:
hours="0"+hours
if minute>59:
minutes="0"+minutes[1]
if hours=="00" and q[1]=="0":
hours="10"
elif hours=="00":
hours="01"
print(hours+":"+minutes)
``` | instruction | 0 | 78,764 | 4 | 157,528 |
No | output | 1 | 78,764 | 4 | 157,529 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.