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.
The time on the planet Lapituletti goes the same way it goes on Earth but a day lasts h hours and each hour lasts m minutes. The inhabitants of that planet use digital clocks similar to earth ones. Clocks display time in a format HH:MM (the number of hours in decimal is displayed first, then (after the colon) follows the number of minutes in decimal; the number of minutes and hours is written with leading zeros if needed to form a two-digit number). Hours are numbered from 0 to h-1 and minutes are numbered from 0 to m-1.
<image>
That's how the digits are displayed on the clock. Please note that digit 1 is placed in the middle of its position.
A standard mirror is in use on the planet Lapituletti. Inhabitants often look at the reflection of the digital clocks in the mirror and feel happy when what you see on the reflected clocks is a valid time (that means that you see valid digits in the reflection and this time can be seen on the normal clocks at some moment of a day).
The image of the clocks in the mirror is reflected against a vertical axis.
<image>
The reflection is not a valid time.
<image>
The reflection is a valid time with h=24, m = 60. However, for example, if h=10, m=60, then the reflection is not a valid time.
An inhabitant of the planet Lapituletti begins to look at a mirrored image of the clocks at some time moment s and wants to know the nearest future time moment (which can possibly happen on the next day), when the reflected clock time is valid.
It can be shown that with any h, m, s such a moment exists. If the reflected time is correct at the moment the inhabitant began to look at the clock, that moment is considered the nearest.
You are asked to solve the problem for several test cases.
Input
The first line contains a single integer T (1 β€ T β€ 100) β the number of test cases.
The next 2 β
T lines contain the description of test cases. The description of each test case consists of two lines.
The first line of a test case contains two integers h, m (1 β€ h, m β€ 100).
The second line contains the start time s in the described format HH:MM.
Output
For each test case output in a separate line the nearest moment in format HH:MM when the reflected time is correct.
Example
Input
5
24 60
12:21
24 60
23:59
90 80
52:26
1 100
00:01
10 10
04:04
Output
12:21
00:00
52:28
00:00
00:00
Note
In the second test case it is not hard to show that the reflection of 23:59 is incorrect, while the reflection of the moment 00:00 on the next day is correct.
<image>
Submitted Solution:
```
change = {0: 0, 1: 1, 2: 5, 5: 2, 8: 8}
bad = (3, 4, 6, 7, 9)
for _ in range(int(input())):
h, m = map(int, input().split())
s = input()
ch = int(s[:2])
cm = int(s[3:])
while True:
if not ((ch%10) in bad or (cm%10) in bad or (ch//10) in bad or (cm//10) in bad):
chm = change[ch%10] * 10 + change[ch//10]
chh = change[cm%10] * 10 + change[cm//10]
if chh < h and chm < m:
if ch < 10:
print('0', end='')
print(ch, end=':')
if cm < 10:
print('0', end='')
print(cm)
break
cm += 1
if cm == m:
cm = 0
ch += 1
if ch == h:
print("00:00")
break
``` | instruction | 0 | 5,262 | 4 | 10,524 |
Yes | output | 1 | 5,262 | 4 | 10,525 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The time on the planet Lapituletti goes the same way it goes on Earth but a day lasts h hours and each hour lasts m minutes. The inhabitants of that planet use digital clocks similar to earth ones. Clocks display time in a format HH:MM (the number of hours in decimal is displayed first, then (after the colon) follows the number of minutes in decimal; the number of minutes and hours is written with leading zeros if needed to form a two-digit number). Hours are numbered from 0 to h-1 and minutes are numbered from 0 to m-1.
<image>
That's how the digits are displayed on the clock. Please note that digit 1 is placed in the middle of its position.
A standard mirror is in use on the planet Lapituletti. Inhabitants often look at the reflection of the digital clocks in the mirror and feel happy when what you see on the reflected clocks is a valid time (that means that you see valid digits in the reflection and this time can be seen on the normal clocks at some moment of a day).
The image of the clocks in the mirror is reflected against a vertical axis.
<image>
The reflection is not a valid time.
<image>
The reflection is a valid time with h=24, m = 60. However, for example, if h=10, m=60, then the reflection is not a valid time.
An inhabitant of the planet Lapituletti begins to look at a mirrored image of the clocks at some time moment s and wants to know the nearest future time moment (which can possibly happen on the next day), when the reflected clock time is valid.
It can be shown that with any h, m, s such a moment exists. If the reflected time is correct at the moment the inhabitant began to look at the clock, that moment is considered the nearest.
You are asked to solve the problem for several test cases.
Input
The first line contains a single integer T (1 β€ T β€ 100) β the number of test cases.
The next 2 β
T lines contain the description of test cases. The description of each test case consists of two lines.
The first line of a test case contains two integers h, m (1 β€ h, m β€ 100).
The second line contains the start time s in the described format HH:MM.
Output
For each test case output in a separate line the nearest moment in format HH:MM when the reflected time is correct.
Example
Input
5
24 60
12:21
24 60
23:59
90 80
52:26
1 100
00:01
10 10
04:04
Output
12:21
00:00
52:28
00:00
00:00
Note
In the second test case it is not hard to show that the reflection of 23:59 is incorrect, while the reflection of the moment 00:00 on the next day is correct.
<image>
Submitted Solution:
```
t = int(input())
def transform(n):
return n // 10, n % 10
def make(ch, minuts, h, m):
p = {0: 0, 1: 1, 2: 5, 5: 2, 8: 8, 3: 3, 4: 4, 6: 6, 7: 7, 9: 9}
bad = {3, 4, 6, 7, 9}
qc, rc = transform(ch)
qm, rm = transform(minuts)
flag = True
if not bad.intersection({qc, rc, qm, rm}):
if p[rm] * 10 + p[qm] < h and p[rc] * 10 + p[qc] < m:
flag = False
while flag:
minuts += 1
if minuts == m:
minuts = 0
ch += 1
if ch == h:
ch = 0
qc, rc = transform(ch)
qm, rm = transform(minuts)
if not bad.intersection({qc, rc, qm, rm}):
if p[rm] * 10 + p[qm] < h and p[rc] * 10 + p[qc] < m:
flag = False
qc, rc = transform(ch)
qm, rm = transform(minuts)
return str(qc) + str(rc) + ":" + str(qm) + str(rm)
for _ in range(t):
h, m = map(int, input().split())
ch, minuts = map(int, input().split(":"))
print(make(ch, minuts, h, m))
``` | instruction | 0 | 5,263 | 4 | 10,526 |
Yes | output | 1 | 5,263 | 4 | 10,527 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The time on the planet Lapituletti goes the same way it goes on Earth but a day lasts h hours and each hour lasts m minutes. The inhabitants of that planet use digital clocks similar to earth ones. Clocks display time in a format HH:MM (the number of hours in decimal is displayed first, then (after the colon) follows the number of minutes in decimal; the number of minutes and hours is written with leading zeros if needed to form a two-digit number). Hours are numbered from 0 to h-1 and minutes are numbered from 0 to m-1.
<image>
That's how the digits are displayed on the clock. Please note that digit 1 is placed in the middle of its position.
A standard mirror is in use on the planet Lapituletti. Inhabitants often look at the reflection of the digital clocks in the mirror and feel happy when what you see on the reflected clocks is a valid time (that means that you see valid digits in the reflection and this time can be seen on the normal clocks at some moment of a day).
The image of the clocks in the mirror is reflected against a vertical axis.
<image>
The reflection is not a valid time.
<image>
The reflection is a valid time with h=24, m = 60. However, for example, if h=10, m=60, then the reflection is not a valid time.
An inhabitant of the planet Lapituletti begins to look at a mirrored image of the clocks at some time moment s and wants to know the nearest future time moment (which can possibly happen on the next day), when the reflected clock time is valid.
It can be shown that with any h, m, s such a moment exists. If the reflected time is correct at the moment the inhabitant began to look at the clock, that moment is considered the nearest.
You are asked to solve the problem for several test cases.
Input
The first line contains a single integer T (1 β€ T β€ 100) β the number of test cases.
The next 2 β
T lines contain the description of test cases. The description of each test case consists of two lines.
The first line of a test case contains two integers h, m (1 β€ h, m β€ 100).
The second line contains the start time s in the described format HH:MM.
Output
For each test case output in a separate line the nearest moment in format HH:MM when the reflected time is correct.
Example
Input
5
24 60
12:21
24 60
23:59
90 80
52:26
1 100
00:01
10 10
04:04
Output
12:21
00:00
52:28
00:00
00:00
Note
In the second test case it is not hard to show that the reflection of 23:59 is incorrect, while the reflection of the moment 00:00 on the next day is correct.
<image>
Submitted Solution:
```
T = int(input())
P = {0, 1, 2, 5, 8}
D = {0:0, 1:1, 2:5, 5:2, 8:8}
for i in range(T):
h, m = map(int, input().split())
H, M = map(int, input().split(":"))
for i in range(H, H + h):
H2 = i % h % 10
H1 = i % h // 10
SH = {H1, H2}
if SH <= P and D[H2] * 10 + D[H1] < m:
HH = str(H1) + str(H2)
break
for j in range(M * (i == H), M + m):
M2 = j % m % 10
M1 = j % m // 10
SM = {M2, M1}
if SM <= P and D[M2] * 10 + D[M1] < h:
MM = str(M1) + str(M2)
break
print(HH, MM, sep=":")
``` | instruction | 0 | 5,264 | 4 | 10,528 |
No | output | 1 | 5,264 | 4 | 10,529 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The time on the planet Lapituletti goes the same way it goes on Earth but a day lasts h hours and each hour lasts m minutes. The inhabitants of that planet use digital clocks similar to earth ones. Clocks display time in a format HH:MM (the number of hours in decimal is displayed first, then (after the colon) follows the number of minutes in decimal; the number of minutes and hours is written with leading zeros if needed to form a two-digit number). Hours are numbered from 0 to h-1 and minutes are numbered from 0 to m-1.
<image>
That's how the digits are displayed on the clock. Please note that digit 1 is placed in the middle of its position.
A standard mirror is in use on the planet Lapituletti. Inhabitants often look at the reflection of the digital clocks in the mirror and feel happy when what you see on the reflected clocks is a valid time (that means that you see valid digits in the reflection and this time can be seen on the normal clocks at some moment of a day).
The image of the clocks in the mirror is reflected against a vertical axis.
<image>
The reflection is not a valid time.
<image>
The reflection is a valid time with h=24, m = 60. However, for example, if h=10, m=60, then the reflection is not a valid time.
An inhabitant of the planet Lapituletti begins to look at a mirrored image of the clocks at some time moment s and wants to know the nearest future time moment (which can possibly happen on the next day), when the reflected clock time is valid.
It can be shown that with any h, m, s such a moment exists. If the reflected time is correct at the moment the inhabitant began to look at the clock, that moment is considered the nearest.
You are asked to solve the problem for several test cases.
Input
The first line contains a single integer T (1 β€ T β€ 100) β the number of test cases.
The next 2 β
T lines contain the description of test cases. The description of each test case consists of two lines.
The first line of a test case contains two integers h, m (1 β€ h, m β€ 100).
The second line contains the start time s in the described format HH:MM.
Output
For each test case output in a separate line the nearest moment in format HH:MM when the reflected time is correct.
Example
Input
5
24 60
12:21
24 60
23:59
90 80
52:26
1 100
00:01
10 10
04:04
Output
12:21
00:00
52:28
00:00
00:00
Note
In the second test case it is not hard to show that the reflection of 23:59 is incorrect, while the reflection of the moment 00:00 on the next day is correct.
<image>
Submitted Solution:
```
for r in range(int(input())):
h,m=list(map(int,input().split()))
p=input()
# print(h,m,p)
hour=p[0:2]
minute=p[3:5]
def fun(a):
if a==0:
return 0
elif a==1:
return 1
elif a==2:
return 5
elif a==5:
return 2
elif a==8:
return 8
else:
return -1
x=hour;y=minute;turn=0;c=""
while turn!=1:
if fun(int(x[0]))!=-1 and fun(int(x[1]))!=-1 and fun(int(y[0]))!=-1 and fun(int(y[1]))!=-1:
c=x+':'+y
turn=1
break
else:
if int(y)==m:
y='00'
if int(x)==h-1:
x='00'
else:
x=str(int(x)+1)
if len(x)==1:
q=x
x='0'+q
else:
y=str(int(y)+1)
if len(y)==1:
q=y
y='0'+q
print(c)
``` | instruction | 0 | 5,265 | 4 | 10,530 |
No | output | 1 | 5,265 | 4 | 10,531 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The time on the planet Lapituletti goes the same way it goes on Earth but a day lasts h hours and each hour lasts m minutes. The inhabitants of that planet use digital clocks similar to earth ones. Clocks display time in a format HH:MM (the number of hours in decimal is displayed first, then (after the colon) follows the number of minutes in decimal; the number of minutes and hours is written with leading zeros if needed to form a two-digit number). Hours are numbered from 0 to h-1 and minutes are numbered from 0 to m-1.
<image>
That's how the digits are displayed on the clock. Please note that digit 1 is placed in the middle of its position.
A standard mirror is in use on the planet Lapituletti. Inhabitants often look at the reflection of the digital clocks in the mirror and feel happy when what you see on the reflected clocks is a valid time (that means that you see valid digits in the reflection and this time can be seen on the normal clocks at some moment of a day).
The image of the clocks in the mirror is reflected against a vertical axis.
<image>
The reflection is not a valid time.
<image>
The reflection is a valid time with h=24, m = 60. However, for example, if h=10, m=60, then the reflection is not a valid time.
An inhabitant of the planet Lapituletti begins to look at a mirrored image of the clocks at some time moment s and wants to know the nearest future time moment (which can possibly happen on the next day), when the reflected clock time is valid.
It can be shown that with any h, m, s such a moment exists. If the reflected time is correct at the moment the inhabitant began to look at the clock, that moment is considered the nearest.
You are asked to solve the problem for several test cases.
Input
The first line contains a single integer T (1 β€ T β€ 100) β the number of test cases.
The next 2 β
T lines contain the description of test cases. The description of each test case consists of two lines.
The first line of a test case contains two integers h, m (1 β€ h, m β€ 100).
The second line contains the start time s in the described format HH:MM.
Output
For each test case output in a separate line the nearest moment in format HH:MM when the reflected time is correct.
Example
Input
5
24 60
12:21
24 60
23:59
90 80
52:26
1 100
00:01
10 10
04:04
Output
12:21
00:00
52:28
00:00
00:00
Note
In the second test case it is not hard to show that the reflection of 23:59 is incorrect, while the reflection of the moment 00:00 on the next day is correct.
<image>
Submitted Solution:
```
#!/usr/bin/env python
from __future__ import division, print_function
import math
import os
import sys
from sys import stdin,stdout
from io import BytesIO, IOBase
from collections import deque
#sys.setrecursionlimit(10**5)
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#-----------------------------------------------------------------
def binarySearchCount(arr, n, key):
left = 0
right = n - 1
count = 0
while (left <= right):
mid = int((right + left) / 2)
# Check if middle element is
# less than or equal to key
if (arr[mid] < key):
count = mid + 1
left = mid + 1
# If key is smaller, ignore right half
else:
right = mid - 1
return count
def regularbracket(t):
p=0
for i in t:
if i=="(":
p+=1
else:
p-=1
if p<0:
return False
else:
if p>0:
return False
else:
return True
# endregion
"""
def samesign(a,b):
if (a>0 and b>0) or (a<0 and b<0):
return True
return False
def main():
t = int(input())
for _ in range(t):
n = int(input())
arr = list(map(int,input().split()))
sum1=0
l=[arr[0]]
for i in range(len(arr)-1):
if samesign(arr[i+1],arr[i])==True:
l.append(arr[i+1])
else:
# print(l)
# print(max(l))
sum1+=max(l)
l=[arr[i+1]]
#print(sum1)
# print(l)
sum1+=max(l)
print(sum1)
"""
"""
def main():
t = int(input())
for _ in range(t):
n = int(input())
arr = list(map(int,input().split()))
sum1 = sum(arr)
# max1 = max(arr)
arr = sorted(arr)
flag = True
for i in range(1,n+1):
if arr[i-1]>i:
print("second")
flag = False
break
if flag==True:
diff = (n*(n+1))/2-sum1
if diff%2==0:
print("Second")
else:
print("First")
"""
"""
def main():
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int,input().split()))
seg = [0] * (n + 1)
curr = 0
cnt = 0
for ai in a:
if ai == curr:
cnt += 1
else:
if cnt > 0:
seg[curr] += 1
curr = ai
cnt = 1
if cnt > 0:
seg[curr] += 1
res = n
for i in range(1, n + 1):
if seg[i] == 0:
continue
op = seg[i] + 1
if i == a[0]:
op -= 1
if i == a[-1]:
op -= 1
res = min(res, op)
print((res))
"""
"""
def main():
t = int(input())
for _ in range(t):
a,b = map(int,input().split())
if a==0 or b==0:
print(0)
elif a>=2*b or b>=2*a:
print(min(a,b))
else:
print((a+b)//3)
"""
"""
def main():
t = int(input())
for _ in range(t):
n, m, x, y = map(int, input().split())
ans = 0
y = min(y, 2 * x)
for i_ in range(n):
s = input()
i = 0
while i < m:
if s[i] == '*':
i += 1
continue
j = i
while j + 1 < m and s[j + 1] == '.':
j += 1
l = j - i + 1
ans += l % 2 * x + l // 2 * y
i = j + 1
print(ans)
"""
"""
def main():
t = int(input())
for _ in range(t):
n,x = map(int,input().split())
arr = list(map(int,input().split()))
p=0
sum1 = sum(arr)
arr = sorted(arr)
if sum1//n>=x:
print(n)
else:
for i in range(n-1):
sum1-=arr[i]
if sum1//(n-(i+1))>=x:
print(n-(i+1))
break
else:
print(0)
"""
"""
def main():
p = int(input())
for _ in range(p):
n,k = map(int,input().split())
list1=[]
if n==1 and k==1:
print(0)
else:
for i in range(n,0,-1):
if i+(i-1)<=k:
list1.append(i)
break
else:
list1.append(i)
list1.remove(k)
print(len(list1))
print(*list1)
"""
def mirrortime(s):
s = list(s)
pp=""
for i in range(len(s)):
if s[i]=="0":
continue
elif s[i]=="2":
s[i]="5"
elif s[i]=="5":
s[i]="2"
elif i=="8":
continue
elif i=="1":
continue
for i in s:
pp+=i
return pp
#print(mirrortime("2255"))
def main():
t = int(input())
for _ in range(t):
l=[3,4,6,7,9]
h,m = map(int,input().split())
s = input()
t=s[0:2]
p=s[3:5]
ll=[]
mm=[]
t = int(t)
p = int(p)
# print(t,p)
for i in range(t,h):
for j in range(p,m):
i = str(i)
if len(i)==1:
i="0"+i
j = str(j)
if len(j)==1:
j="0"+j
if int(i[0]) in l or int(i[1]) in l or int(j[0]) in l or int(j[1]) in l:
continue
else:
ll.append(i)
mm.append(j)
# print(ll,mm)
if len(ll)>=1:
for i in range(len(ll)):
cccc = ll[i]
dddd = mm[i]
ccc = mirrortime(cccc)
ddd = mirrortime(dddd)
ccc = list(ccc)
ddd = list(ddd)
ccc.reverse()
ddd.reverse()
ppp=""
qqq=""
for k in ccc:
ppp+=k
for k_ in ddd:
qqq+=k_
if int(qqq)<h and int(ppp)<m:
# print(int(qqq))
# print(int(ppp))
print(cccc+":"+dddd)
break
else:
print("00:00")
else:
print("00:00")
if __name__ == '__main__':
main()
``` | instruction | 0 | 5,266 | 4 | 10,532 |
No | output | 1 | 5,266 | 4 | 10,533 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The time on the planet Lapituletti goes the same way it goes on Earth but a day lasts h hours and each hour lasts m minutes. The inhabitants of that planet use digital clocks similar to earth ones. Clocks display time in a format HH:MM (the number of hours in decimal is displayed first, then (after the colon) follows the number of minutes in decimal; the number of minutes and hours is written with leading zeros if needed to form a two-digit number). Hours are numbered from 0 to h-1 and minutes are numbered from 0 to m-1.
<image>
That's how the digits are displayed on the clock. Please note that digit 1 is placed in the middle of its position.
A standard mirror is in use on the planet Lapituletti. Inhabitants often look at the reflection of the digital clocks in the mirror and feel happy when what you see on the reflected clocks is a valid time (that means that you see valid digits in the reflection and this time can be seen on the normal clocks at some moment of a day).
The image of the clocks in the mirror is reflected against a vertical axis.
<image>
The reflection is not a valid time.
<image>
The reflection is a valid time with h=24, m = 60. However, for example, if h=10, m=60, then the reflection is not a valid time.
An inhabitant of the planet Lapituletti begins to look at a mirrored image of the clocks at some time moment s and wants to know the nearest future time moment (which can possibly happen on the next day), when the reflected clock time is valid.
It can be shown that with any h, m, s such a moment exists. If the reflected time is correct at the moment the inhabitant began to look at the clock, that moment is considered the nearest.
You are asked to solve the problem for several test cases.
Input
The first line contains a single integer T (1 β€ T β€ 100) β the number of test cases.
The next 2 β
T lines contain the description of test cases. The description of each test case consists of two lines.
The first line of a test case contains two integers h, m (1 β€ h, m β€ 100).
The second line contains the start time s in the described format HH:MM.
Output
For each test case output in a separate line the nearest moment in format HH:MM when the reflected time is correct.
Example
Input
5
24 60
12:21
24 60
23:59
90 80
52:26
1 100
00:01
10 10
04:04
Output
12:21
00:00
52:28
00:00
00:00
Note
In the second test case it is not hard to show that the reflection of 23:59 is incorrect, while the reflection of the moment 00:00 on the next day is correct.
<image>
Submitted Solution:
```
# by the authority of GOD author: manhar singh sachdev #
def some_random_function():
"""due to the fast IO template, my code gets caught in
plag check for no reason. That is why, I am making
random functions"""
x = 10
x *= 100
i_dont_know = x
why_am_i_writing_this = x*x
print(i_dont_know)
print(why_am_i_writing_this)
def some_random_function5():
"""due to the fast IO template, my code gets caught in
plag check for no reason. That is why, I am making
random functions"""
x = 10
x *= 100
i_dont_know = x
why_am_i_writing_this = x*x
print(i_dont_know)
print(why_am_i_writing_this)
import os,sys
from io import BytesIO,IOBase
def add(ls,h,m):
ls[-1] += 1
if ls[-2]*10+ls[-1] >= m:
ls[-2],ls[-1] = 0,0
else:
if ls[-1] == 10:
ls[-1] = 0
else:
return
ls[-2] += 1
if ls[-2] == 10:
ls[-2] = 0
else:
return
ls[-3] += 1
if ls[-4]*10+ls[-3] >= h:
ls[-4],ls[-3] = 0,0
else:
if ls[-3] == 10:
ls[-3] = 0
else:
return
ls[-4] += 1
if ls[-4] == 10:
ls[-4] = 0
return
def solve():
h,m = map(int,input().split())
s,e = input().split(':')
ref = {0:0,1:1,2:5,5:2,8:8}
ti = [int(s[0]),int(s[1]),int(e[0]),int(e[1])]
while 1:
fl = 0
for i in range(4):
if ref.get(ti[i]) == None:
fl = 1
break
if fl:
add(ti,h,m)
continue
#print(ti[-4]*10+ti[-3],ti[-2]*10+ti[-1],ti)
if ti[-1]*10+ti[-2] < h and ti[-3]*10+ti[-4] < m:
print(str(ti[0])+str(ti[1])+':'+str(ti[2])+str(ti[3]))
return
add(ti,h,m)
def main():
for _ in range(int(input())):
solve()
#Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
def some_random_function1():
"""due to the fast IO template, my code gets caught in
plag check for no reason. That is why, I am making
random functions"""
x = 10
x *= 100
i_dont_know = x
why_am_i_writing_this = x*x
print(i_dont_know)
print(why_am_i_writing_this)
def some_random_function2():
"""due to the fast IO template, my code gets caught in
plag check for no reason. That is why, I am making
random functions"""
x = 10
x *= 100
i_dont_know = x
why_am_i_writing_this = x*x
print(i_dont_know)
print(why_am_i_writing_this)
def some_random_function3():
"""due to the fast IO template, my code gets caught in
plag check for no reason. That is why, I am making
random functions"""
x = 10
x *= 100
i_dont_know = x
why_am_i_writing_this = x*x
print(i_dont_know)
print(why_am_i_writing_this)
def some_random_function4():
"""due to the fast IO template, my code gets caught in
plag check for no reason. That is why, I am making
random functions"""
x = 10
x *= 100
i_dont_know = x
why_am_i_writing_this = x*x
print(i_dont_know)
print(why_am_i_writing_this)
def some_random_function6():
"""due to the fast IO template, my code gets caught in
plag check for no reason. That is why, I am making
random functions"""
x = 10
x *= 100
i_dont_know = x
why_am_i_writing_this = x*x
print(i_dont_know)
print(why_am_i_writing_this)
def some_random_function7():
"""due to the fast IO template, my code gets caught in
plag check for no reason. That is why, I am making
random functions"""
x = 10
x *= 100
i_dont_know = x
why_am_i_writing_this = x*x
print(i_dont_know)
print(why_am_i_writing_this)
def some_random_function8():
"""due to the fast IO template, my code gets caught in
plag check for no reason. That is why, I am making
random functions"""
x = 10
x *= 100
i_dont_know = x
why_am_i_writing_this = x*x
print(i_dont_know)
print(why_am_i_writing_this)
if __name__ == '__main__':
main()
``` | instruction | 0 | 5,267 | 4 | 10,534 |
No | output | 1 | 5,267 | 4 | 10,535 |
Provide a correct Python 3 solution for this coding contest problem.
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
Constraints
* 1β€Mβ€23
* M is an integer.
Input
Input is given from Standard Input in the following format:
M
Output
If we have x hours until New Year at M o'clock on 30th, December, print x.
Examples
Input
21
Output
27
Input
12
Output
36 | instruction | 0 | 5,661 | 4 | 11,322 |
"Correct Solution:
```
n = int(input());
print(48 - n);
``` | output | 1 | 5,661 | 4 | 11,323 |
Provide a correct Python 3 solution for this coding contest problem.
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
Constraints
* 1β€Mβ€23
* M is an integer.
Input
Input is given from Standard Input in the following format:
M
Output
If we have x hours until New Year at M o'clock on 30th, December, print x.
Examples
Input
21
Output
27
Input
12
Output
36 | instruction | 0 | 5,662 | 4 | 11,324 |
"Correct Solution:
```
m = int(input())
ans = 48 - m
print(ans)
``` | output | 1 | 5,662 | 4 | 11,325 |
Provide a correct Python 3 solution for this coding contest problem.
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
Constraints
* 1β€Mβ€23
* M is an integer.
Input
Input is given from Standard Input in the following format:
M
Output
If we have x hours until New Year at M o'clock on 30th, December, print x.
Examples
Input
21
Output
27
Input
12
Output
36 | instruction | 0 | 5,663 | 4 | 11,326 |
"Correct Solution:
```
#84A
m = int(input())
print(48-m)
``` | output | 1 | 5,663 | 4 | 11,327 |
Provide a correct Python 3 solution for this coding contest problem.
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
Constraints
* 1β€Mβ€23
* M is an integer.
Input
Input is given from Standard Input in the following format:
M
Output
If we have x hours until New Year at M o'clock on 30th, December, print x.
Examples
Input
21
Output
27
Input
12
Output
36 | instruction | 0 | 5,664 | 4 | 11,328 |
"Correct Solution:
```
nancy = int(input())
print (24-nancy+24)
``` | output | 1 | 5,664 | 4 | 11,329 |
Provide a correct Python 3 solution for this coding contest problem.
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
Constraints
* 1β€Mβ€23
* M is an integer.
Input
Input is given from Standard Input in the following format:
M
Output
If we have x hours until New Year at M o'clock on 30th, December, print x.
Examples
Input
21
Output
27
Input
12
Output
36 | instruction | 0 | 5,665 | 4 | 11,330 |
"Correct Solution:
```
M = int(input())
x = 24 - M + 24
print(x)
``` | output | 1 | 5,665 | 4 | 11,331 |
Provide a correct Python 3 solution for this coding contest problem.
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
Constraints
* 1β€Mβ€23
* M is an integer.
Input
Input is given from Standard Input in the following format:
M
Output
If we have x hours until New Year at M o'clock on 30th, December, print x.
Examples
Input
21
Output
27
Input
12
Output
36 | instruction | 0 | 5,666 | 4 | 11,332 |
"Correct Solution:
```
n = int(input())
print(24+24-n)
``` | output | 1 | 5,666 | 4 | 11,333 |
Provide a correct Python 3 solution for this coding contest problem.
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
Constraints
* 1β€Mβ€23
* M is an integer.
Input
Input is given from Standard Input in the following format:
M
Output
If we have x hours until New Year at M o'clock on 30th, December, print x.
Examples
Input
21
Output
27
Input
12
Output
36 | instruction | 0 | 5,667 | 4 | 11,334 |
"Correct Solution:
```
a = int(input())
print((24-a)+24)
``` | output | 1 | 5,667 | 4 | 11,335 |
Provide a correct Python 3 solution for this coding contest problem.
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
Constraints
* 1β€Mβ€23
* M is an integer.
Input
Input is given from Standard Input in the following format:
M
Output
If we have x hours until New Year at M o'clock on 30th, December, print x.
Examples
Input
21
Output
27
Input
12
Output
36 | instruction | 0 | 5,668 | 4 | 11,336 |
"Correct Solution:
```
M = int(input())
print(24 * 2 - M)
``` | output | 1 | 5,668 | 4 | 11,337 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
Constraints
* 1β€Mβ€23
* M is an integer.
Input
Input is given from Standard Input in the following format:
M
Output
If we have x hours until New Year at M o'clock on 30th, December, print x.
Examples
Input
21
Output
27
Input
12
Output
36
Submitted Solution:
```
x = int(input())
print(24 - x + 24)
``` | instruction | 0 | 5,669 | 4 | 11,338 |
Yes | output | 1 | 5,669 | 4 | 11,339 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
Constraints
* 1β€Mβ€23
* M is an integer.
Input
Input is given from Standard Input in the following format:
M
Output
If we have x hours until New Year at M o'clock on 30th, December, print x.
Examples
Input
21
Output
27
Input
12
Output
36
Submitted Solution:
```
M = int(input()) # 5
print(24-M+24)
``` | instruction | 0 | 5,670 | 4 | 11,340 |
Yes | output | 1 | 5,670 | 4 | 11,341 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
Constraints
* 1β€Mβ€23
* M is an integer.
Input
Input is given from Standard Input in the following format:
M
Output
If we have x hours until New Year at M o'clock on 30th, December, print x.
Examples
Input
21
Output
27
Input
12
Output
36
Submitted Solution:
```
print(str(48-int(input())))
``` | instruction | 0 | 5,671 | 4 | 11,342 |
Yes | output | 1 | 5,671 | 4 | 11,343 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
Constraints
* 1β€Mβ€23
* M is an integer.
Input
Input is given from Standard Input in the following format:
M
Output
If we have x hours until New Year at M o'clock on 30th, December, print x.
Examples
Input
21
Output
27
Input
12
Output
36
Submitted Solution:
```
print(24 + (24-int(input())))
``` | instruction | 0 | 5,672 | 4 | 11,344 |
Yes | output | 1 | 5,672 | 4 | 11,345 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
Constraints
* 1β€Mβ€23
* M is an integer.
Input
Input is given from Standard Input in the following format:
M
Output
If we have x hours until New Year at M o'clock on 30th, December, print x.
Examples
Input
21
Output
27
Input
12
Output
36
Submitted Solution:
```
a,b=map(int,input().split())
s=input()
if s[:a].isdigit() and s[a:b]=='-' and s[b:].isdigit():
print("True")
else:
print("No")
``` | instruction | 0 | 5,673 | 4 | 11,346 |
No | output | 1 | 5,673 | 4 | 11,347 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
Constraints
* 1β€Mβ€23
* M is an integer.
Input
Input is given from Standard Input in the following format:
M
Output
If we have x hours until New Year at M o'clock on 30th, December, print x.
Examples
Input
21
Output
27
Input
12
Output
36
Submitted Solution:
```
m = input()
n = 48 - m
print(n)
``` | instruction | 0 | 5,674 | 4 | 11,348 |
No | output | 1 | 5,674 | 4 | 11,349 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
Constraints
* 1β€Mβ€23
* M is an integer.
Input
Input is given from Standard Input in the following format:
M
Output
If we have x hours until New Year at M o'clock on 30th, December, print x.
Examples
Input
21
Output
27
Input
12
Output
36
Submitted Solution:
```
def year(M):
num = open('M.txt', r)
return int(48 - int(num))
``` | instruction | 0 | 5,675 | 4 | 11,350 |
No | output | 1 | 5,675 | 4 | 11,351 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
Constraints
* 1β€Mβ€23
* M is an integer.
Input
Input is given from Standard Input in the following format:
M
Output
If we have x hours until New Year at M o'clock on 30th, December, print x.
Examples
Input
21
Output
27
Input
12
Output
36
Submitted Solution:
```
#coding: utf-8
print(24 - M + 24)
``` | instruction | 0 | 5,676 | 4 | 11,352 |
No | output | 1 | 5,676 | 4 | 11,353 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows:
Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100; the centurial years that are exactly divisible by 400 are still leap years. For example, the year 1900 is not a leap year; the year 2000 is a leap year.
<image>
In this problem, you have been given two dates and your task is to calculate how many days are between them. Note, that leap years have unusual number of days in February.
Look at the sample to understand what borders are included in the aswer.
Input
The first two lines contain two dates, each date is in the format yyyy:mm:dd (1900 β€ yyyy β€ 2038 and yyyy:mm:dd is a legal date).
Output
Print a single integer β the answer to the problem.
Examples
Input
1900:01:01
2038:12:31
Output
50768
Input
1996:03:09
1991:11:12
Output
1579 | instruction | 0 | 6,103 | 4 | 12,206 |
Tags: brute force, implementation
Correct Solution:
```
from datetime import date
d = [0] * 2
for i in range(0, 2):
a = list(map(int, input().split(':')))
d[i] = date(a[0], a[1], a[2])
r = (d[0] - d[1]).days
print(r if r >= 0 else -r)
``` | output | 1 | 6,103 | 4 | 12,207 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows:
Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100; the centurial years that are exactly divisible by 400 are still leap years. For example, the year 1900 is not a leap year; the year 2000 is a leap year.
<image>
In this problem, you have been given two dates and your task is to calculate how many days are between them. Note, that leap years have unusual number of days in February.
Look at the sample to understand what borders are included in the aswer.
Input
The first two lines contain two dates, each date is in the format yyyy:mm:dd (1900 β€ yyyy β€ 2038 and yyyy:mm:dd is a legal date).
Output
Print a single integer β the answer to the problem.
Examples
Input
1900:01:01
2038:12:31
Output
50768
Input
1996:03:09
1991:11:12
Output
1579 | instruction | 0 | 6,104 | 4 | 12,208 |
Tags: brute force, implementation
Correct Solution:
```
import datetime
t1 = datetime.datetime.strptime(input(),"%Y:%m:%d")
t2 = datetime.datetime.strptime(input(),"%Y:%m:%d")
print(abs((t2-t1).days))
``` | output | 1 | 6,104 | 4 | 12,209 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows:
Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100; the centurial years that are exactly divisible by 400 are still leap years. For example, the year 1900 is not a leap year; the year 2000 is a leap year.
<image>
In this problem, you have been given two dates and your task is to calculate how many days are between them. Note, that leap years have unusual number of days in February.
Look at the sample to understand what borders are included in the aswer.
Input
The first two lines contain two dates, each date is in the format yyyy:mm:dd (1900 β€ yyyy β€ 2038 and yyyy:mm:dd is a legal date).
Output
Print a single integer β the answer to the problem.
Examples
Input
1900:01:01
2038:12:31
Output
50768
Input
1996:03:09
1991:11:12
Output
1579 | instruction | 0 | 6,105 | 4 | 12,210 |
Tags: brute force, implementation
Correct Solution:
```
from datetime import date
a1 = [int(i) for i in input().split(':')]
a2 = [int(i) for i in input().split(':')]
print(abs((date(a1[0], a1[1], a1[2]) - date(a2[0], a2[1], a2[2])).days))
``` | output | 1 | 6,105 | 4 | 12,211 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows:
Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100; the centurial years that are exactly divisible by 400 are still leap years. For example, the year 1900 is not a leap year; the year 2000 is a leap year.
<image>
In this problem, you have been given two dates and your task is to calculate how many days are between them. Note, that leap years have unusual number of days in February.
Look at the sample to understand what borders are included in the aswer.
Input
The first two lines contain two dates, each date is in the format yyyy:mm:dd (1900 β€ yyyy β€ 2038 and yyyy:mm:dd is a legal date).
Output
Print a single integer β the answer to the problem.
Examples
Input
1900:01:01
2038:12:31
Output
50768
Input
1996:03:09
1991:11:12
Output
1579 | instruction | 0 | 6,106 | 4 | 12,212 |
Tags: brute force, implementation
Correct Solution:
```
from datetime import *
R = lambda: datetime(*map(int, input().split(':')))
date1 = R()
date2 = R()
print(abs(date2 - date1).days)
``` | output | 1 | 6,106 | 4 | 12,213 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows:
Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100; the centurial years that are exactly divisible by 400 are still leap years. For example, the year 1900 is not a leap year; the year 2000 is a leap year.
<image>
In this problem, you have been given two dates and your task is to calculate how many days are between them. Note, that leap years have unusual number of days in February.
Look at the sample to understand what borders are included in the aswer.
Input
The first two lines contain two dates, each date is in the format yyyy:mm:dd (1900 β€ yyyy β€ 2038 and yyyy:mm:dd is a legal date).
Output
Print a single integer β the answer to the problem.
Examples
Input
1900:01:01
2038:12:31
Output
50768
Input
1996:03:09
1991:11:12
Output
1579 | instruction | 0 | 6,107 | 4 | 12,214 |
Tags: brute force, implementation
Correct Solution:
```
from collections import Counter
import string
import math
dicti={'1':31,'2':28,'3':31,'4':30,'5':31,'6':30,'7':31,'8':31
,'9':30,'10':31,'11':30,'12':31}
def array_int():
return [int(i) for i in input().split()]
def vary(number_of_variables):
if number_of_variables==1:
return int(input())
if number_of_variables>=2:
return map(int,input().split())
def makedict(var):
return dict(Counter(var))
mod=1000000007
from datetime import date
print(abs((date(*map(int,input().split(':')))-date(*map(int,input().split(':')))).days))
``` | output | 1 | 6,107 | 4 | 12,215 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows:
Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100; the centurial years that are exactly divisible by 400 are still leap years. For example, the year 1900 is not a leap year; the year 2000 is a leap year.
<image>
In this problem, you have been given two dates and your task is to calculate how many days are between them. Note, that leap years have unusual number of days in February.
Look at the sample to understand what borders are included in the aswer.
Input
The first two lines contain two dates, each date is in the format yyyy:mm:dd (1900 β€ yyyy β€ 2038 and yyyy:mm:dd is a legal date).
Output
Print a single integer β the answer to the problem.
Examples
Input
1900:01:01
2038:12:31
Output
50768
Input
1996:03:09
1991:11:12
Output
1579 | instruction | 0 | 6,108 | 4 | 12,216 |
Tags: brute force, implementation
Correct Solution:
```
import datetime
y1, m1, d1 = map(int, input().split(':'))
y2, m2, d2 = map(int, input().split(':'))
print(abs(datetime.date(y1, m1, d1) - datetime.date(y2, m2, d2)).days)
``` | output | 1 | 6,108 | 4 | 12,217 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows:
Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100; the centurial years that are exactly divisible by 400 are still leap years. For example, the year 1900 is not a leap year; the year 2000 is a leap year.
<image>
In this problem, you have been given two dates and your task is to calculate how many days are between them. Note, that leap years have unusual number of days in February.
Look at the sample to understand what borders are included in the aswer.
Input
The first two lines contain two dates, each date is in the format yyyy:mm:dd (1900 β€ yyyy β€ 2038 and yyyy:mm:dd is a legal date).
Output
Print a single integer β the answer to the problem.
Examples
Input
1900:01:01
2038:12:31
Output
50768
Input
1996:03:09
1991:11:12
Output
1579 | instruction | 0 | 6,109 | 4 | 12,218 |
Tags: brute force, implementation
Correct Solution:
```
from datetime import *
t1 = datetime.strptime(input(), "%Y:%m:%d")
t2 = datetime.strptime(input(), "%Y:%m:%d")
print(abs((t2-t1).days))
``` | output | 1 | 6,109 | 4 | 12,219 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows:
Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100; the centurial years that are exactly divisible by 400 are still leap years. For example, the year 1900 is not a leap year; the year 2000 is a leap year.
<image>
In this problem, you have been given two dates and your task is to calculate how many days are between them. Note, that leap years have unusual number of days in February.
Look at the sample to understand what borders are included in the aswer.
Input
The first two lines contain two dates, each date is in the format yyyy:mm:dd (1900 β€ yyyy β€ 2038 and yyyy:mm:dd is a legal date).
Output
Print a single integer β the answer to the problem.
Examples
Input
1900:01:01
2038:12:31
Output
50768
Input
1996:03:09
1991:11:12
Output
1579 | instruction | 0 | 6,110 | 4 | 12,220 |
Tags: brute force, implementation
Correct Solution:
```
import datetime
tA = datetime.datetime.strptime(input(),"%Y:%m:%d")
tB = datetime.datetime.strptime(input(),"%Y:%m:%d")
print(abs((tB-tA).days))
``` | output | 1 | 6,110 | 4 | 12,221 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows:
Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100; the centurial years that are exactly divisible by 400 are still leap years. For example, the year 1900 is not a leap year; the year 2000 is a leap year.
<image>
In this problem, you have been given two dates and your task is to calculate how many days are between them. Note, that leap years have unusual number of days in February.
Look at the sample to understand what borders are included in the aswer.
Input
The first two lines contain two dates, each date is in the format yyyy:mm:dd (1900 β€ yyyy β€ 2038 and yyyy:mm:dd is a legal date).
Output
Print a single integer β the answer to the problem.
Examples
Input
1900:01:01
2038:12:31
Output
50768
Input
1996:03:09
1991:11:12
Output
1579
Submitted Solution:
```
from datetime import date
s1=list(map(int,input().split(':')))
s2=list(map(int,input().split(':')))
a = date(s1[0],s1[1],s1[2])
b = date(s2[0],s2[1],s2[2])
x=abs((a-b).days)
print(x)
``` | instruction | 0 | 6,111 | 4 | 12,222 |
Yes | output | 1 | 6,111 | 4 | 12,223 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows:
Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100; the centurial years that are exactly divisible by 400 are still leap years. For example, the year 1900 is not a leap year; the year 2000 is a leap year.
<image>
In this problem, you have been given two dates and your task is to calculate how many days are between them. Note, that leap years have unusual number of days in February.
Look at the sample to understand what borders are included in the aswer.
Input
The first two lines contain two dates, each date is in the format yyyy:mm:dd (1900 β€ yyyy β€ 2038 and yyyy:mm:dd is a legal date).
Output
Print a single integer β the answer to the problem.
Examples
Input
1900:01:01
2038:12:31
Output
50768
Input
1996:03:09
1991:11:12
Output
1579
Submitted Solution:
```
def s():
import datetime
dt = datetime.datetime
print(abs((dt(*list(map(int,input().split(':'))))-dt(*list(map(int,input().split(':'))))).days))
s()
``` | instruction | 0 | 6,112 | 4 | 12,224 |
Yes | output | 1 | 6,112 | 4 | 12,225 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows:
Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100; the centurial years that are exactly divisible by 400 are still leap years. For example, the year 1900 is not a leap year; the year 2000 is a leap year.
<image>
In this problem, you have been given two dates and your task is to calculate how many days are between them. Note, that leap years have unusual number of days in February.
Look at the sample to understand what borders are included in the aswer.
Input
The first two lines contain two dates, each date is in the format yyyy:mm:dd (1900 β€ yyyy β€ 2038 and yyyy:mm:dd is a legal date).
Output
Print a single integer β the answer to the problem.
Examples
Input
1900:01:01
2038:12:31
Output
50768
Input
1996:03:09
1991:11:12
Output
1579
Submitted Solution:
```
import sys
a = [int(x) for x in sys.stdin.readline().strip().split(":")]
b = [int(x) for x in sys.stdin.readline().strip().split(":")]
stuff = [a, b]
stuff = sorted(stuff)
begin = stuff[0]
end = stuff[1]
year1 = begin[0] if begin[1] <= 2 else begin[0] + 1
year2 = end[0] - 1 if end[1] <= 2 else end[0]
leaps = 0
for i in range(year1, year2 + 1):
if((i % 4 == 0 and i % 100 != 0) or i % 400 == 0):
#print(i)
leaps += 1
days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
sums = 0
b = 0
for i in range(begin[1], 12):
b += days[i]
b += (days[begin[1] - 1] - begin[2])
a = 0
for i in range(0, end[1] - 1):
a += days[i]
a += end[2]
sums = sums + a + b
sums += 365 * ((end[0]) - (begin[0] + 1))
sums += leaps
print(sums)
``` | instruction | 0 | 6,113 | 4 | 12,226 |
Yes | output | 1 | 6,113 | 4 | 12,227 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows:
Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100; the centurial years that are exactly divisible by 400 are still leap years. For example, the year 1900 is not a leap year; the year 2000 is a leap year.
<image>
In this problem, you have been given two dates and your task is to calculate how many days are between them. Note, that leap years have unusual number of days in February.
Look at the sample to understand what borders are included in the aswer.
Input
The first two lines contain two dates, each date is in the format yyyy:mm:dd (1900 β€ yyyy β€ 2038 and yyyy:mm:dd is a legal date).
Output
Print a single integer β the answer to the problem.
Examples
Input
1900:01:01
2038:12:31
Output
50768
Input
1996:03:09
1991:11:12
Output
1579
Submitted Solution:
```
from datetime import date
list1 = input().split(':')
list2 = input().split(':')
d0 = date(int(list1[0]),int(list1[1]),int(list1[2]))
d1 = date(int(list2[0]),int(list2[1]),int(list2[2]))
if d0<d1:
delta = d1 - d0
else:
delta = d0-d1
print(delta.days)
``` | instruction | 0 | 6,114 | 4 | 12,228 |
Yes | output | 1 | 6,114 | 4 | 12,229 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows:
Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100; the centurial years that are exactly divisible by 400 are still leap years. For example, the year 1900 is not a leap year; the year 2000 is a leap year.
<image>
In this problem, you have been given two dates and your task is to calculate how many days are between them. Note, that leap years have unusual number of days in February.
Look at the sample to understand what borders are included in the aswer.
Input
The first two lines contain two dates, each date is in the format yyyy:mm:dd (1900 β€ yyyy β€ 2038 and yyyy:mm:dd is a legal date).
Output
Print a single integer β the answer to the problem.
Examples
Input
1900:01:01
2038:12:31
Output
50768
Input
1996:03:09
1991:11:12
Output
1579
Submitted Solution:
```
def leapyear(a):
if a%400 == 0:
return True
elif a%100 == 0:
return False
elif a%4==0:
return True
# =============================================================================
# a1 = '1949:07:09'
# a2 = '1901:10:24'
# =============================================================================
a1 = input()
a2 = input()
if int(a1[:4]) > int(a2[:4]):
temp = a1
a1 = a2
a2 = temp
y1,m1,d1 = a1.split(':')
y2,m2,d2 = a2.split(':')
y1=int(y1)
d1=int(d1)
y2=int(y2)
d2=int(d2)
months = {'01':31, '02':28, '03':31, '04':30, '05':31, '06':30,
'07':31, '08':31, '09':30, '10':31, '11':30, '12':31}
rem_months = {'01':334, '02':306, '03':275, '04':245, '05':214, '06':184,
'07':153, '08':122, '09':92, '10':61, '11':31, '12':0}
end_months = {'01':0, '02':31, '03':59, '04':90, '05':120, '06':151,
'07':181, '08':212, '09':243, '10':273, '11':304, '12':334}
res = 0
#checking whether first year is leap year if m1>02
if m1!='02' or m1!='01':
res += (months[m1] - d1)
res += (rem_months[m1])
else:
if y1%4==0 and leapyear(y1)==True:
if m1=='01':
res += (months[str(m1)] - d1)
res += 29
else:
res += (29-d1)
else:
if m1=='01':
res += (months[str(m1)] - d1)
res += 28
else:
res += (28-d1)
res += (rem_months['03'])
y1 += 1
while y1<y2:
if leapyear(y1)==True:
res += 366
else :
res += 365
y1 += 1
if leapyear(y2)==True:
res += end_months[m2]
res += d2
if m2 !='02' and m1 != '01':
res += 1
else:
res += end_months[m2]
res += d2
print(res)
``` | instruction | 0 | 6,115 | 4 | 12,230 |
No | output | 1 | 6,115 | 4 | 12,231 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows:
Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100; the centurial years that are exactly divisible by 400 are still leap years. For example, the year 1900 is not a leap year; the year 2000 is a leap year.
<image>
In this problem, you have been given two dates and your task is to calculate how many days are between them. Note, that leap years have unusual number of days in February.
Look at the sample to understand what borders are included in the aswer.
Input
The first two lines contain two dates, each date is in the format yyyy:mm:dd (1900 β€ yyyy β€ 2038 and yyyy:mm:dd is a legal date).
Output
Print a single integer β the answer to the problem.
Examples
Input
1900:01:01
2038:12:31
Output
50768
Input
1996:03:09
1991:11:12
Output
1579
Submitted Solution:
```
def leapyear(a):
if a%400 == 0:
return True
elif a%100 == 0:
return False
elif a%4==0:
return True
a1 = input()
a2 = input()
if int(a1[:4]) > int(a2[:4]):
temp = a1
a1 = a2
a2 = temp
y1,m1,d1 = a1.split(':')
y2,m2,d2 = a2.split(':')
y1=int(y1)
d1=int(d1)
y2=int(y2)
d2=int(d2)
months = {'01':31, '02':28, '03':31, '04':30, '05':31, '06':30,
'07':31, '08':31, '09':30, '10':31, '11':30, '12':31}
rem_months = {'01':334, '02':306, '03':275, '04':245, '05':214, '06':184,
'07':153, '08':123, '09':92, '10':62, '11':31, '12':0}
end_months = {'01':0, '02':31, '03':59, '04':90, '05':120, '06':151,
'07':181, '08':212, '09':243, '10':273, '11':304, '12':334}
res = 0
#checking whether first year is leap year if m1>02
if m1!='02' or m1!='01':
res += (months[m1] - d1)
res += (rem_months[m1])
else:
if y1%4==0 and leapyear(y1)==True:
if m1=='01':
res += (months[str(m1)] - d1)
res += 29
else:
res += (29-d1)
else:
if m1=='01':
res += (months[str(m1)] - d1)
res += 28
else:
res += (28-d1)
res += (rem_months['03'])
y1 += 1
while y1<y2:
if leapyear(y1)==True:
res += 366
else :
res += 365
y1 += 1
if leapyear(y2)==True:
res += end_months[m2]
res += d2
if m2 !='02' and m1 != '01':
res += 1
else:
res += end_months[m2]
res += d2
print(res)
``` | instruction | 0 | 6,116 | 4 | 12,232 |
No | output | 1 | 6,116 | 4 | 12,233 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows:
Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100; the centurial years that are exactly divisible by 400 are still leap years. For example, the year 1900 is not a leap year; the year 2000 is a leap year.
<image>
In this problem, you have been given two dates and your task is to calculate how many days are between them. Note, that leap years have unusual number of days in February.
Look at the sample to understand what borders are included in the aswer.
Input
The first two lines contain two dates, each date is in the format yyyy:mm:dd (1900 β€ yyyy β€ 2038 and yyyy:mm:dd is a legal date).
Output
Print a single integer β the answer to the problem.
Examples
Input
1900:01:01
2038:12:31
Output
50768
Input
1996:03:09
1991:11:12
Output
1579
Submitted Solution:
```
from collections import Counter
import string
import math
dicti={'1':31,'2':28,'3':31,'4':30,'5':31,'6':30,'7':31,'8':31
,'9':30,'10':31,'11':30,'12':31}
def array_int():
return [int(i) for i in input().split()]
def vary(number_of_variables):
if number_of_variables==1:
return int(input())
if number_of_variables>=2:
return map(int,input().split())
def makedict(var):
return dict(Counter(var))
mod=1000000007
date1=input()
date2=input()
year1=int(date1[:4])
year2=int(date2[:4])
day1=int(date1[8:])
day2=int(date2[8:])
month1=int(date1[5:7])
month2=int(date2[5:7])
class Date:
def __init__(self, d, m, y):
self.d = d
self.m = m
self.y = y
monthDays = [31, 28, 31, 30, 31, 30,
31, 31, 30, 31, 30, 31 ]
def countLeapYears(d):
years = d.y
if (d.m <= 2):
years-= 1
return int(years / 4 - years / 100 + years / 400 )
def getDifference(dt1, dt2) :
n1 = dt1.y * 365 + dt1.d
# Add days for months in given date
for i in range(0, dt1.m - 1) :
n1 += monthDays[i]
# Since every leap year is of 366 days,
# Add a day for every leap year
n1 += countLeapYears(dt1)
# SIMILARLY, COUNT TOTAL NUMBER OF DAYS BEFORE 'dt2'
n2 = dt2.y * 365 + dt2.d
for i in range(0, dt2.m - 1) :
n2 += monthDays[i]
n2 += countLeapYears(dt2)
# return difference between two counts
return (n2 - n1)
# Driver program
dt1 = Date(day1, month1, year1 )
dt2 = Date(day2, month2, year2 )
print(abs(getDifference(dt1, dt2)))
``` | instruction | 0 | 6,117 | 4 | 12,234 |
No | output | 1 | 6,117 | 4 | 12,235 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows:
Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100; the centurial years that are exactly divisible by 400 are still leap years. For example, the year 1900 is not a leap year; the year 2000 is a leap year.
<image>
In this problem, you have been given two dates and your task is to calculate how many days are between them. Note, that leap years have unusual number of days in February.
Look at the sample to understand what borders are included in the aswer.
Input
The first two lines contain two dates, each date is in the format yyyy:mm:dd (1900 β€ yyyy β€ 2038 and yyyy:mm:dd is a legal date).
Output
Print a single integer β the answer to the problem.
Examples
Input
1900:01:01
2038:12:31
Output
50768
Input
1996:03:09
1991:11:12
Output
1579
Submitted Solution:
```
def get(y, m, d):
if(m < 3):
--y
m += 12
return 365 * y + y // 4 - y //100 + y//400 + (153*m-457)//5+d-306
a1 = input().split(':')
a2 = input().split(':')
print(abs(get(int(a1[0]),int(a1[1]),int(a1[2])) - get(int(a2[0]),int(a2[1]),int(a2[2]))))
``` | instruction | 0 | 6,118 | 4 | 12,236 |
No | output | 1 | 6,118 | 4 | 12,237 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your friend Mishka and you attend a calculus lecture. Lecture lasts n minutes. Lecturer tells ai theorems during the i-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array t of Mishka's behavior. If Mishka is asleep during the i-th minute of the lecture then ti will be equal to 0, otherwise it will be equal to 1. When Mishka is awake he writes down all the theorems he is being told β ai during the i-th minute. Otherwise he writes nothing.
You know some secret technique to keep Mishka awake for k minutes straight. However you can use it only once. You can start using it at the beginning of any minute between 1 and n - k + 1. If you use it on some minute i then Mishka will be awake during minutes j such that <image> and will write down all the theorems lecturer tells.
You task is to calculate the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.
Input
The first line of the input contains two integer numbers n and k (1 β€ k β€ n β€ 105) β the duration of the lecture in minutes and the number of minutes you can keep Mishka awake.
The second line of the input contains n integer numbers a1, a2, ... an (1 β€ ai β€ 104) β the number of theorems lecturer tells during the i-th minute.
The third line of the input contains n integer numbers t1, t2, ... tn (0 β€ ti β€ 1) β type of Mishka's behavior at the i-th minute of the lecture.
Output
Print only one integer β the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.
Example
Input
6 3
1 3 5 2 5 4
1 1 0 1 0 0
Output
16
Note
In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16.
Submitted Solution:
```
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
theorems=list(map(int,input().split()))
sleep=list(map(int,input().split()))
tsum=[]
ts=0
sleepsum=[]
slsum=0
for i in range(n):
ts+=theorems[i]
tsum.append(ts)
if(sleep[i]==1):
slsum+=theorems[i]
sleepsum.append(slsum)
#print("tsum=",tsum)
#print("sleepsum=",sleepsum)
maxdiff=0
#print("slsum=",slsum)
maxdiff=tsum[k-1]-sleepsum[k-1]
for i in range(1,n-k+1):
diff=(tsum[i+k-1]-tsum[i-1])-(sleepsum[i+k-1]-sleepsum[i-1])
#print("i=",i,"diff=",diff)
maxdiff=max(maxdiff,diff)
#print("maxdiff=",maxdiff)
print(slsum+maxdiff)
``` | instruction | 0 | 6,341 | 4 | 12,682 |
Yes | output | 1 | 6,341 | 4 | 12,683 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your friend Mishka and you attend a calculus lecture. Lecture lasts n minutes. Lecturer tells ai theorems during the i-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array t of Mishka's behavior. If Mishka is asleep during the i-th minute of the lecture then ti will be equal to 0, otherwise it will be equal to 1. When Mishka is awake he writes down all the theorems he is being told β ai during the i-th minute. Otherwise he writes nothing.
You know some secret technique to keep Mishka awake for k minutes straight. However you can use it only once. You can start using it at the beginning of any minute between 1 and n - k + 1. If you use it on some minute i then Mishka will be awake during minutes j such that <image> and will write down all the theorems lecturer tells.
You task is to calculate the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.
Input
The first line of the input contains two integer numbers n and k (1 β€ k β€ n β€ 105) β the duration of the lecture in minutes and the number of minutes you can keep Mishka awake.
The second line of the input contains n integer numbers a1, a2, ... an (1 β€ ai β€ 104) β the number of theorems lecturer tells during the i-th minute.
The third line of the input contains n integer numbers t1, t2, ... tn (0 β€ ti β€ 1) β type of Mishka's behavior at the i-th minute of the lecture.
Output
Print only one integer β the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.
Example
Input
6 3
1 3 5 2 5 4
1 1 0 1 0 0
Output
16
Note
In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16.
Submitted Solution:
```
from sys import stdin as sin
n,k = map(int, sin.readline().split())
a = list(map(int, sin.readline().split(" ")))
x = list(map(int, sin.readline().split(" ")))
te=[]+a
te[0]=te[0]*x[0]
re=[]+a
re[-1]*=x[-1]
for i in range(n-2,-1,-1):
re[i]=re[i+1]+re[i]*x[i]
te[n-i-1]=te[n-i-2]+te[n-i-1]*x[n-i-1]
# print(te,re)
s = sum(a[0:k])
if n==k:
print(s)
else:
m=max(s+re[k],sum(a[n-k:n])+te[n-k-1])
# print(m)
for i in range(1,n-k):
s+=(a[i+k-1]-a[i-1])
m=max(m,te[i-1]+s+re[i+k])
# print(m)
# print(te,re)
print(m)
# 6 3
# 1 3 5 2 5 4
# 1 1 0 1 0 0
# 5 3
# 1 9999 10000 10000 10000
# 0 0 0 0 0
``` | instruction | 0 | 6,342 | 4 | 12,684 |
Yes | output | 1 | 6,342 | 4 | 12,685 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your friend Mishka and you attend a calculus lecture. Lecture lasts n minutes. Lecturer tells ai theorems during the i-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array t of Mishka's behavior. If Mishka is asleep during the i-th minute of the lecture then ti will be equal to 0, otherwise it will be equal to 1. When Mishka is awake he writes down all the theorems he is being told β ai during the i-th minute. Otherwise he writes nothing.
You know some secret technique to keep Mishka awake for k minutes straight. However you can use it only once. You can start using it at the beginning of any minute between 1 and n - k + 1. If you use it on some minute i then Mishka will be awake during minutes j such that <image> and will write down all the theorems lecturer tells.
You task is to calculate the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.
Input
The first line of the input contains two integer numbers n and k (1 β€ k β€ n β€ 105) β the duration of the lecture in minutes and the number of minutes you can keep Mishka awake.
The second line of the input contains n integer numbers a1, a2, ... an (1 β€ ai β€ 104) β the number of theorems lecturer tells during the i-th minute.
The third line of the input contains n integer numbers t1, t2, ... tn (0 β€ ti β€ 1) β type of Mishka's behavior at the i-th minute of the lecture.
Output
Print only one integer β the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.
Example
Input
6 3
1 3 5 2 5 4
1 1 0 1 0 0
Output
16
Note
In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16.
Submitted Solution:
```
"""
def solve(n,k,a,t):
#prefix sum
pref = [0] * (n+1)
pref[1] = a[1]
for i in range(2,n+1):
pref[i] = pref[i-1] + a[i]
#dp initialization
dpc = [0] * (n+1)
for i in range(1,n+1):
if t[i] != 0:
dpc[i] = dpc[i-1] + a[i]
else:
dpc[i] = dpc[i-1]
ans = 0
#implementation
for i in range(1,n-k+2):
dp = dpc[:]
pos = i+k-1
dp[n] -= dp[pos]
dp[n] += dp[i-1] + pref[pos] - pref[i-1]
ans = max(ans,dp[n])
print(ans)
return
"""
def solve(n,k,a,t):
res = 0
for i in range(1,n+1):
if t[i] == 1:
res += a[i]
a[i] = 0
pref = [0] * (n+1)
for i in range(1,n+1):
pref[i] = pref[i-1] + a[i]
temp = 0
for i in range(n,k-1,-1):
temp = max(temp,pref[i]-pref[i-k])
print(temp + res)
if __name__ == '__main__':
n,k = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
a.insert(0,0)
t.insert(0,0)
solve(n,k,a,t)
``` | instruction | 0 | 6,343 | 4 | 12,686 |
Yes | output | 1 | 6,343 | 4 | 12,687 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your friend Mishka and you attend a calculus lecture. Lecture lasts n minutes. Lecturer tells ai theorems during the i-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array t of Mishka's behavior. If Mishka is asleep during the i-th minute of the lecture then ti will be equal to 0, otherwise it will be equal to 1. When Mishka is awake he writes down all the theorems he is being told β ai during the i-th minute. Otherwise he writes nothing.
You know some secret technique to keep Mishka awake for k minutes straight. However you can use it only once. You can start using it at the beginning of any minute between 1 and n - k + 1. If you use it on some minute i then Mishka will be awake during minutes j such that <image> and will write down all the theorems lecturer tells.
You task is to calculate the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.
Input
The first line of the input contains two integer numbers n and k (1 β€ k β€ n β€ 105) β the duration of the lecture in minutes and the number of minutes you can keep Mishka awake.
The second line of the input contains n integer numbers a1, a2, ... an (1 β€ ai β€ 104) β the number of theorems lecturer tells during the i-th minute.
The third line of the input contains n integer numbers t1, t2, ... tn (0 β€ ti β€ 1) β type of Mishka's behavior at the i-th minute of the lecture.
Output
Print only one integer β the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.
Example
Input
6 3
1 3 5 2 5 4
1 1 0 1 0 0
Output
16
Note
In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16.
Submitted Solution:
```
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
base = 0
for i in range(n):
base += a[i] * t[i]
prefix = [(1 - t[i]) * a[i] for i in range(n)]
for i in range(1, n):
prefix[i] += prefix[i - 1]
gain = prefix[k - 1]
for i in range(k, n):
gain = max(gain, prefix[i] - prefix[i - k])
print(base + gain)
``` | instruction | 0 | 6,344 | 4 | 12,688 |
Yes | output | 1 | 6,344 | 4 | 12,689 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your friend Mishka and you attend a calculus lecture. Lecture lasts n minutes. Lecturer tells ai theorems during the i-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array t of Mishka's behavior. If Mishka is asleep during the i-th minute of the lecture then ti will be equal to 0, otherwise it will be equal to 1. When Mishka is awake he writes down all the theorems he is being told β ai during the i-th minute. Otherwise he writes nothing.
You know some secret technique to keep Mishka awake for k minutes straight. However you can use it only once. You can start using it at the beginning of any minute between 1 and n - k + 1. If you use it on some minute i then Mishka will be awake during minutes j such that <image> and will write down all the theorems lecturer tells.
You task is to calculate the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.
Input
The first line of the input contains two integer numbers n and k (1 β€ k β€ n β€ 105) β the duration of the lecture in minutes and the number of minutes you can keep Mishka awake.
The second line of the input contains n integer numbers a1, a2, ... an (1 β€ ai β€ 104) β the number of theorems lecturer tells during the i-th minute.
The third line of the input contains n integer numbers t1, t2, ... tn (0 β€ ti β€ 1) β type of Mishka's behavior at the i-th minute of the lecture.
Output
Print only one integer β the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.
Example
Input
6 3
1 3 5 2 5 4
1 1 0 1 0 0
Output
16
Note
In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16.
Submitted Solution:
```
n, k = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
s.append(0), t.append(0)
r = sum([s[i] for i in range(n) if t[i]])
m = sum(s[i] for i in range(k) if t[i] == 0)
x = m
for i in range(1, n-k+1):
m = m - (1==t[i-1])*s[i-1] + (0==t[i+k])*s[i+k]
x = max(x, m)
print(r+m)
``` | instruction | 0 | 6,345 | 4 | 12,690 |
No | output | 1 | 6,345 | 4 | 12,691 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your friend Mishka and you attend a calculus lecture. Lecture lasts n minutes. Lecturer tells ai theorems during the i-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array t of Mishka's behavior. If Mishka is asleep during the i-th minute of the lecture then ti will be equal to 0, otherwise it will be equal to 1. When Mishka is awake he writes down all the theorems he is being told β ai during the i-th minute. Otherwise he writes nothing.
You know some secret technique to keep Mishka awake for k minutes straight. However you can use it only once. You can start using it at the beginning of any minute between 1 and n - k + 1. If you use it on some minute i then Mishka will be awake during minutes j such that <image> and will write down all the theorems lecturer tells.
You task is to calculate the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.
Input
The first line of the input contains two integer numbers n and k (1 β€ k β€ n β€ 105) β the duration of the lecture in minutes and the number of minutes you can keep Mishka awake.
The second line of the input contains n integer numbers a1, a2, ... an (1 β€ ai β€ 104) β the number of theorems lecturer tells during the i-th minute.
The third line of the input contains n integer numbers t1, t2, ... tn (0 β€ ti β€ 1) β type of Mishka's behavior at the i-th minute of the lecture.
Output
Print only one integer β the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.
Example
Input
6 3
1 3 5 2 5 4
1 1 0 1 0 0
Output
16
Note
In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16.
Submitted Solution:
```
def proB(arr,arr2,k):
n=len(arr)
fro,end=[0]*n,[0]*n
if(arr2[0]==1):
fro[0]=arr[0]
if(arr2[n-1]==1):
end[0]=arr[n-1]
for i in range(1,len(arr)):
if(arr2[i]==1):
fro[i]=fro[i-1]+arr[i]
else:
fro[i]=fro[i-1]
if(arr2[n-1-i]==1):
end[n-1-i]=end[n-1-i+1]+arr[n-1-i]
else:
end[n-1-i]=end[n-1-i+1]
sumi=sum(arr[:k])
j=0
maxi=sumi+end[k]
for i in range(k,n):
sumi+=arr[i]
sumi-=arr[j]
j+=1
maxi=max(maxi,fro[j-1]+sumi+end[i])
return maxi
arr=list(map(int,input().split()))
n,k=arr
a=list(map(int,input().split()))
b=list(map(int,input().split()))
print(proB(a,b,k))
``` | instruction | 0 | 6,346 | 4 | 12,692 |
No | output | 1 | 6,346 | 4 | 12,693 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your friend Mishka and you attend a calculus lecture. Lecture lasts n minutes. Lecturer tells ai theorems during the i-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array t of Mishka's behavior. If Mishka is asleep during the i-th minute of the lecture then ti will be equal to 0, otherwise it will be equal to 1. When Mishka is awake he writes down all the theorems he is being told β ai during the i-th minute. Otherwise he writes nothing.
You know some secret technique to keep Mishka awake for k minutes straight. However you can use it only once. You can start using it at the beginning of any minute between 1 and n - k + 1. If you use it on some minute i then Mishka will be awake during minutes j such that <image> and will write down all the theorems lecturer tells.
You task is to calculate the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.
Input
The first line of the input contains two integer numbers n and k (1 β€ k β€ n β€ 105) β the duration of the lecture in minutes and the number of minutes you can keep Mishka awake.
The second line of the input contains n integer numbers a1, a2, ... an (1 β€ ai β€ 104) β the number of theorems lecturer tells during the i-th minute.
The third line of the input contains n integer numbers t1, t2, ... tn (0 β€ ti β€ 1) β type of Mishka's behavior at the i-th minute of the lecture.
Output
Print only one integer β the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.
Example
Input
6 3
1 3 5 2 5 4
1 1 0 1 0 0
Output
16
Note
In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16.
Submitted Solution:
```
import sys
import os
import math
import re
n,k = map(int,input().split())
data = list(map(int,input().split()))
wake = list(map(int,input().split()))
if (k == n):
print(sum(data))
exit(0)
res = 0
#indices = [i for i, x in enumerate(wake) if x == 0]
#bestSum = 0
#for index
if (not 0 in wake):
print(0)
exit(0)
start = wake.index(0)
bestInd = start
for i in range(start,start + k + 1):
if (i < len(data)):
res += data[i]
curr = res
for i in range(start+1,len(data)):
curr += data[i] - data[i-(k+1)]
if (i - k) >= 0 and data[i-k] == 0:
if (curr > res):
bestInd = i-k
res = max(res,curr)
for i in range(bestInd,bestInd+k+1):
if i < len(data):
wake[i] = 1
res2 = 0
for i in range(k+1):
if wake[i] != 0 and i < len(data):
res2 += data[i]
curr2 = res2
for i in range(k+1,len(data)):
if wake[i] != 0:
curr2 += data[i] - data[i-(k+1)]
res2 = max(res2,curr2)
else:
curr2 -= data[i-(k+1)]
print(max(res,res2))
``` | instruction | 0 | 6,347 | 4 | 12,694 |
No | output | 1 | 6,347 | 4 | 12,695 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your friend Mishka and you attend a calculus lecture. Lecture lasts n minutes. Lecturer tells ai theorems during the i-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array t of Mishka's behavior. If Mishka is asleep during the i-th minute of the lecture then ti will be equal to 0, otherwise it will be equal to 1. When Mishka is awake he writes down all the theorems he is being told β ai during the i-th minute. Otherwise he writes nothing.
You know some secret technique to keep Mishka awake for k minutes straight. However you can use it only once. You can start using it at the beginning of any minute between 1 and n - k + 1. If you use it on some minute i then Mishka will be awake during minutes j such that <image> and will write down all the theorems lecturer tells.
You task is to calculate the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.
Input
The first line of the input contains two integer numbers n and k (1 β€ k β€ n β€ 105) β the duration of the lecture in minutes and the number of minutes you can keep Mishka awake.
The second line of the input contains n integer numbers a1, a2, ... an (1 β€ ai β€ 104) β the number of theorems lecturer tells during the i-th minute.
The third line of the input contains n integer numbers t1, t2, ... tn (0 β€ ti β€ 1) β type of Mishka's behavior at the i-th minute of the lecture.
Output
Print only one integer β the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.
Example
Input
6 3
1 3 5 2 5 4
1 1 0 1 0 0
Output
16
Note
In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16.
Submitted Solution:
```
n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
t = list(map(int, input().split()))
x = 0
summ = 0
maxx = 0
for i in range(n):
summ += a[i]*t[i]
for i in range(k):
if not t[i]:
x+=a[i]
for i in range(n-k):
x+=a[i+k]*(1-t[i+k])
x-=a[i]*(1-t[i])
maxx = max(x, maxx)
print(summ+maxx)
``` | instruction | 0 | 6,348 | 4 | 12,696 |
No | output | 1 | 6,348 | 4 | 12,697 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots.
Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written.
Your task is to print the radixes of all numeral system which can contain the time "a:b".
Input
The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time).
We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35.
Output
Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1.
Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible.
Examples
Input
11:20
Output
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
Input
2A:13
Output
0
Input
000B:00001
Output
-1
Note
Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system.
Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time.
Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12. | instruction | 0 | 6,830 | 4 | 13,660 |
Tags: implementation
Correct Solution:
```
def s():
a = [[ord(i)-48 if ord(i) < 60 else ord(i)-55 for i in i]for i in input().split(':')]
r = [i for i in range(max(max(a[0]),max(a[1]))+1,61) if sum(list(i**l[0]*l[1] for l in enumerate(reversed(a[0]))))<24 and sum(list(i**l[0]*l[1] for l in enumerate(reversed(a[1]))))<60]
if len(r) == 0:
print(0)
elif r[-1] == 60:
print(-1)
else:
print(*r)
s()
``` | output | 1 | 6,830 | 4 | 13,661 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots.
Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written.
Your task is to print the radixes of all numeral system which can contain the time "a:b".
Input
The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time).
We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35.
Output
Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1.
Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible.
Examples
Input
11:20
Output
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
Input
2A:13
Output
0
Input
000B:00001
Output
-1
Note
Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system.
Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time.
Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12. | instruction | 0 | 6,831 | 4 | 13,662 |
Tags: implementation
Correct Solution:
```
def val(c):
if 'A' <= c <='Z':
return ord(c) - 65 + 10
else:
return int(c)
def calc(h, b):
ans = 0
i = 0
for c in h[::-1]:
v = val(c)
ans += int(v) * (b**i)
i += 1
return ans
h, m = [x for x in input().split(":")]
min_base = -1
for c in h:
min_base = max(min_base, val(c)+1)
for c in m:
min_base = max(min_base, val(c)+1)
# print(min_base)
answers = []
while True:
hour = calc(h, min_base)
min = calc(m, min_base)
if hour > 23 or min > 59 or min_base > 60:
break
else:
answers.append(min_base)
min_base+= 1
if len(answers) == 0:
print(0)
elif min_base > 60:
print(-1)
else:
print(*answers)
``` | output | 1 | 6,831 | 4 | 13,663 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots.
Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written.
Your task is to print the radixes of all numeral system which can contain the time "a:b".
Input
The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time).
We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35.
Output
Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1.
Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible.
Examples
Input
11:20
Output
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
Input
2A:13
Output
0
Input
000B:00001
Output
-1
Note
Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system.
Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time.
Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12. | instruction | 0 | 6,832 | 4 | 13,664 |
Tags: implementation
Correct Solution:
```
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#-------------------game starts now----------------------------------------------------
a, b = input().split(':')
a = list(a)
b = list(b)
c = 10
for i in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
for j in range(len(a)):
if a[j] == i:
a[j] = c
for j in range(len(b)):
if b[j] == i:
b[j] = c
c += 1
a = list(map(int, a))
b = list(map(int, b))
ans = []
for c in range(2, 200):
x1 = 0
x2 = 0
for p in range(len(a)):
x1 += a[p] * c ** (len(a) - p - 1)
for p in range(len(b)):
x2 += b[p] * c ** (len(b) - p - 1)
if 0 <= x1 <= 23 and 0 <= x2 <= 59 and max(a) < c and max(b) < c:
ans.append(c)
if len(ans) > 100:
print(-1)
elif ans:
print(*ans)
else:
print(0)
``` | output | 1 | 6,832 | 4 | 13,665 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots.
Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written.
Your task is to print the radixes of all numeral system which can contain the time "a:b".
Input
The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time).
We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35.
Output
Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1.
Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible.
Examples
Input
11:20
Output
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
Input
2A:13
Output
0
Input
000B:00001
Output
-1
Note
Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system.
Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time.
Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12. | instruction | 0 | 6,833 | 4 | 13,666 |
Tags: implementation
Correct Solution:
```
#Algorithm :
# 1) Split into strings , remove zeros
# 2) Start checking for every integer in a range of(2 to 61)
# 3) check the numbers and respetively add them !
################################
#Function to calculate the value
#This function is approximately called 60 times by 2 strings ! And it still works
def base(t,b):
num = 0
p = 1
i = len(t) - 1
v = 0
while i >=0 :
if(t[i].isdigit()):
v = int(t[i])
else:
#Important to convert alphabets to numbers
v = ord(t[i]) - 55
#If a value in string is greater than the numeral , then there can't exist such a numeral system
if v >= b:
return -1
num = num + (v*p)
p=p*b
i=i-1
return num
###################################
#Function to remove leading zeros
def remove_zeros(s):
i=0
res=""
while i < len(s) and s[i] == "0":
i=i+1
while i < len(s):
res = res + s[i]
i=i+1
if res == "":
res = "0"
return res
#####################################
s = input().split(":")
num = []
for i in range(2):
s[i]=remove_zeros(s[i])
#Important range used for checking
for i in range(2,61):
a = base(s[0],i)
b = base(s[1],i)
if a >= 0 and a <= 23 and b >=0 and b <= 59:
num.append(i)
if len(num) == 0:
print(0)
elif 60 in num :
# As 60 cannot come it is possible only when there are only numbers at the 0th place
print(-1)
else:
for x in num:
print(x)
``` | output | 1 | 6,833 | 4 | 13,667 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.