text stringlengths 198 433k | conversation_id int64 0 109k |
|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly k points, the score is reset and a new set begins.
Across all the sets Misha scored a points in total, and Vanya scored b points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible.
Note that the game consisted of several complete sets.
Input
The first line contains three space-separated integers k, a and b (1 ≤ k ≤ 109, 0 ≤ a, b ≤ 109, a + b > 0).
Output
If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.
Examples
Input
11 11 5
Output
1
Input
11 2 3
Output
-1
Note
Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem.
Submitted Solution:
```
k, a, b = [int(x) for x in input().split()]
result = a//k + b//k
if result == 0 or (a%k != 0 and b < k) or (b%k != 0 and a < k):
print('-1')
else:
print(result)
#GTFO from my code, 612!
```
Yes
| 88,900 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly k points, the score is reset and a new set begins.
Across all the sets Misha scored a points in total, and Vanya scored b points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible.
Note that the game consisted of several complete sets.
Input
The first line contains three space-separated integers k, a and b (1 ≤ k ≤ 109, 0 ≤ a, b ≤ 109, a + b > 0).
Output
If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.
Examples
Input
11 11 5
Output
1
Input
11 2 3
Output
-1
Note
Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem.
Submitted Solution:
```
k, a, b = map(int, input().split())
if(a%k!=0 and b%k!=0):
print(-1)
else:
print(a//k+b//k)
```
No
| 88,901 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly k points, the score is reset and a new set begins.
Across all the sets Misha scored a points in total, and Vanya scored b points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible.
Note that the game consisted of several complete sets.
Input
The first line contains three space-separated integers k, a and b (1 ≤ k ≤ 109, 0 ≤ a, b ≤ 109, a + b > 0).
Output
If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.
Examples
Input
11 11 5
Output
1
Input
11 2 3
Output
-1
Note
Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem.
Submitted Solution:
```
a, b, c = (input().split(" "))
# print(a + " " + b + " " + c)
a = int(a)
b = int(b)
c = int(c)
if a > b and a > c:
print(-1)
elif b % a != c % a:
print(-1)
else:
ans = 0
ans += int(b / a) + int(c / a)
print(ans)
```
No
| 88,902 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly k points, the score is reset and a new set begins.
Across all the sets Misha scored a points in total, and Vanya scored b points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible.
Note that the game consisted of several complete sets.
Input
The first line contains three space-separated integers k, a and b (1 ≤ k ≤ 109, 0 ≤ a, b ≤ 109, a + b > 0).
Output
If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.
Examples
Input
11 11 5
Output
1
Input
11 2 3
Output
-1
Note
Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem.
Submitted Solution:
```
k,a,b=map(int,input().split())
print (a//k+b//k if (a>=k and b>=k) or a%k==0 or b%k==0 else -1)
```
No
| 88,903 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly k points, the score is reset and a new set begins.
Across all the sets Misha scored a points in total, and Vanya scored b points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible.
Note that the game consisted of several complete sets.
Input
The first line contains three space-separated integers k, a and b (1 ≤ k ≤ 109, 0 ≤ a, b ≤ 109, a + b > 0).
Output
If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.
Examples
Input
11 11 5
Output
1
Input
11 2 3
Output
-1
Note
Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem.
Submitted Solution:
```
# http://codeforces.com/contest/765/problem/A
# http://codeforces.com/contest/765/problem/B
# http://codeforces.com/contest/765/problem/C
def Neverending_competitions():
n = int(input())
home = input()
for i in range(n):
new = input()
if n % 2 == 0:
return "home"
else:
return "contest"
#print(Neverending_competitions())
def Code_obfuscation():
s = input()
a = [0] * 26
okay = True
for i in s:
for j in range(ord(i)-97):
if not a[j]:
okay = False
break
if okay:
a[ord(i) - 97] = 1
else:
break
if okay:
print("YES")
else:
print("NO")
#Code_obfuscation()
def Table_Tennis_Game_2():
n = input().split()
k = int(n[0])
a = int(n[1])
b = int(n[2])
if a >= k and b>=k:
return int(a/k) + int(b/k)
elif a % k == 0:
return int(a/k)
elif b % k == 0:
return int(b/k)
else:
return -1
print(Table_Tennis_Game_2())
```
No
| 88,904 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Do you remember a kind cartoon "Beauty and the Beast"? No, no, there was no firing from machine guns or radiation mutants time-travels!
There was a beauty named Belle. Once she had violated the Beast's order and visited the West Wing. After that she was banished from the castle...
Everybody was upset. The beautiful Belle was upset, so was the Beast, so was Lumiere the candlestick. But the worst thing was that Cogsworth was upset. Cogsworth is not a human, but is the mantel clock, which was often used as an alarm clock.
Due to Cogsworth's frustration all the inhabitants of the castle were in trouble: now they could not determine when it was time to drink morning tea, and when it was time for an evening stroll.
Fortunately, deep in the basement are lying digital clock showing the time in the format HH:MM. Now the residents of the castle face a difficult task. They should turn Cogsworth's hour and minute mustache hands in such a way, that Cogsworth began to show the correct time. Moreover they need to find turn angles in degrees for each mustache hands. The initial time showed by Cogsworth is 12:00.
You can only rotate the hands forward, that is, as is shown in the picture:
<image>
As since there are many ways too select such angles because of full rotations, choose the smallest angles in the right (non-negative) direction.
Note that Cogsworth's hour and minute mustache hands move evenly and continuously. Hands are moving independently, so when turning one hand the other hand remains standing still.
Input
The only line of input contains current time according to the digital clock, formatted as HH:MM (00 ≤ HH ≤ 23, 00 ≤ MM ≤ 59). The mantel clock initially shows 12:00.
Pretests contain times of the beginning of some morning TV programs of the Channel One Russia.
Output
Print two numbers x and y — the angles of turning the hour and minute hands, respectively (0 ≤ x, y < 360). The absolute or relative error in the answer should not exceed 10 - 9.
Examples
Input
12:00
Output
0 0
Input
04:30
Output
135 180
Input
08:17
Output
248.5 102
Note
A note to the second example: the hour hand will be positioned exactly in the middle, between 4 and 5.
Tags: geometry, math
Correct Solution:
```
h,m = list(map(int,input().split(':')))
print((h*30+m/2)%360,m*6)
```
| 88,905 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Do you remember a kind cartoon "Beauty and the Beast"? No, no, there was no firing from machine guns or radiation mutants time-travels!
There was a beauty named Belle. Once she had violated the Beast's order and visited the West Wing. After that she was banished from the castle...
Everybody was upset. The beautiful Belle was upset, so was the Beast, so was Lumiere the candlestick. But the worst thing was that Cogsworth was upset. Cogsworth is not a human, but is the mantel clock, which was often used as an alarm clock.
Due to Cogsworth's frustration all the inhabitants of the castle were in trouble: now they could not determine when it was time to drink morning tea, and when it was time for an evening stroll.
Fortunately, deep in the basement are lying digital clock showing the time in the format HH:MM. Now the residents of the castle face a difficult task. They should turn Cogsworth's hour and minute mustache hands in such a way, that Cogsworth began to show the correct time. Moreover they need to find turn angles in degrees for each mustache hands. The initial time showed by Cogsworth is 12:00.
You can only rotate the hands forward, that is, as is shown in the picture:
<image>
As since there are many ways too select such angles because of full rotations, choose the smallest angles in the right (non-negative) direction.
Note that Cogsworth's hour and minute mustache hands move evenly and continuously. Hands are moving independently, so when turning one hand the other hand remains standing still.
Input
The only line of input contains current time according to the digital clock, formatted as HH:MM (00 ≤ HH ≤ 23, 00 ≤ MM ≤ 59). The mantel clock initially shows 12:00.
Pretests contain times of the beginning of some morning TV programs of the Channel One Russia.
Output
Print two numbers x and y — the angles of turning the hour and minute hands, respectively (0 ≤ x, y < 360). The absolute or relative error in the answer should not exceed 10 - 9.
Examples
Input
12:00
Output
0 0
Input
04:30
Output
135 180
Input
08:17
Output
248.5 102
Note
A note to the second example: the hour hand will be positioned exactly in the middle, between 4 and 5.
Tags: geometry, math
Correct Solution:
```
s=input()
h=int(s[:2])
m=int(s[3:])
print(h%12*30+m/2,m*6)
# Made By Mostafa_Khaled
```
| 88,906 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Do you remember a kind cartoon "Beauty and the Beast"? No, no, there was no firing from machine guns or radiation mutants time-travels!
There was a beauty named Belle. Once she had violated the Beast's order and visited the West Wing. After that she was banished from the castle...
Everybody was upset. The beautiful Belle was upset, so was the Beast, so was Lumiere the candlestick. But the worst thing was that Cogsworth was upset. Cogsworth is not a human, but is the mantel clock, which was often used as an alarm clock.
Due to Cogsworth's frustration all the inhabitants of the castle were in trouble: now they could not determine when it was time to drink morning tea, and when it was time for an evening stroll.
Fortunately, deep in the basement are lying digital clock showing the time in the format HH:MM. Now the residents of the castle face a difficult task. They should turn Cogsworth's hour and minute mustache hands in such a way, that Cogsworth began to show the correct time. Moreover they need to find turn angles in degrees for each mustache hands. The initial time showed by Cogsworth is 12:00.
You can only rotate the hands forward, that is, as is shown in the picture:
<image>
As since there are many ways too select such angles because of full rotations, choose the smallest angles in the right (non-negative) direction.
Note that Cogsworth's hour and minute mustache hands move evenly and continuously. Hands are moving independently, so when turning one hand the other hand remains standing still.
Input
The only line of input contains current time according to the digital clock, formatted as HH:MM (00 ≤ HH ≤ 23, 00 ≤ MM ≤ 59). The mantel clock initially shows 12:00.
Pretests contain times of the beginning of some morning TV programs of the Channel One Russia.
Output
Print two numbers x and y — the angles of turning the hour and minute hands, respectively (0 ≤ x, y < 360). The absolute or relative error in the answer should not exceed 10 - 9.
Examples
Input
12:00
Output
0 0
Input
04:30
Output
135 180
Input
08:17
Output
248.5 102
Note
A note to the second example: the hour hand will be positioned exactly in the middle, between 4 and 5.
Tags: geometry, math
Correct Solution:
```
H, M = [int(x) for x in input().split(':')]
H = H % 12
hAngle = 360 / 12
hmAngle = hAngle / 60
mAngle = 360 / 60
print(H * hAngle + M * hmAngle, end=' ')
print(M * mAngle)
```
| 88,907 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Do you remember a kind cartoon "Beauty and the Beast"? No, no, there was no firing from machine guns or radiation mutants time-travels!
There was a beauty named Belle. Once she had violated the Beast's order and visited the West Wing. After that she was banished from the castle...
Everybody was upset. The beautiful Belle was upset, so was the Beast, so was Lumiere the candlestick. But the worst thing was that Cogsworth was upset. Cogsworth is not a human, but is the mantel clock, which was often used as an alarm clock.
Due to Cogsworth's frustration all the inhabitants of the castle were in trouble: now they could not determine when it was time to drink morning tea, and when it was time for an evening stroll.
Fortunately, deep in the basement are lying digital clock showing the time in the format HH:MM. Now the residents of the castle face a difficult task. They should turn Cogsworth's hour and minute mustache hands in such a way, that Cogsworth began to show the correct time. Moreover they need to find turn angles in degrees for each mustache hands. The initial time showed by Cogsworth is 12:00.
You can only rotate the hands forward, that is, as is shown in the picture:
<image>
As since there are many ways too select such angles because of full rotations, choose the smallest angles in the right (non-negative) direction.
Note that Cogsworth's hour and minute mustache hands move evenly and continuously. Hands are moving independently, so when turning one hand the other hand remains standing still.
Input
The only line of input contains current time according to the digital clock, formatted as HH:MM (00 ≤ HH ≤ 23, 00 ≤ MM ≤ 59). The mantel clock initially shows 12:00.
Pretests contain times of the beginning of some morning TV programs of the Channel One Russia.
Output
Print two numbers x and y — the angles of turning the hour and minute hands, respectively (0 ≤ x, y < 360). The absolute or relative error in the answer should not exceed 10 - 9.
Examples
Input
12:00
Output
0 0
Input
04:30
Output
135 180
Input
08:17
Output
248.5 102
Note
A note to the second example: the hour hand will be positioned exactly in the middle, between 4 and 5.
Tags: geometry, math
Correct Solution:
```
def readln(): return tuple(map(int, input().split()))
hh, mm = tuple(map(int, input().split(':')))
print(30 * (hh % 12) + 0.5 * mm, 6 * mm)
```
| 88,908 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Do you remember a kind cartoon "Beauty and the Beast"? No, no, there was no firing from machine guns or radiation mutants time-travels!
There was a beauty named Belle. Once she had violated the Beast's order and visited the West Wing. After that she was banished from the castle...
Everybody was upset. The beautiful Belle was upset, so was the Beast, so was Lumiere the candlestick. But the worst thing was that Cogsworth was upset. Cogsworth is not a human, but is the mantel clock, which was often used as an alarm clock.
Due to Cogsworth's frustration all the inhabitants of the castle were in trouble: now they could not determine when it was time to drink morning tea, and when it was time for an evening stroll.
Fortunately, deep in the basement are lying digital clock showing the time in the format HH:MM. Now the residents of the castle face a difficult task. They should turn Cogsworth's hour and minute mustache hands in such a way, that Cogsworth began to show the correct time. Moreover they need to find turn angles in degrees for each mustache hands. The initial time showed by Cogsworth is 12:00.
You can only rotate the hands forward, that is, as is shown in the picture:
<image>
As since there are many ways too select such angles because of full rotations, choose the smallest angles in the right (non-negative) direction.
Note that Cogsworth's hour and minute mustache hands move evenly and continuously. Hands are moving independently, so when turning one hand the other hand remains standing still.
Input
The only line of input contains current time according to the digital clock, formatted as HH:MM (00 ≤ HH ≤ 23, 00 ≤ MM ≤ 59). The mantel clock initially shows 12:00.
Pretests contain times of the beginning of some morning TV programs of the Channel One Russia.
Output
Print two numbers x and y — the angles of turning the hour and minute hands, respectively (0 ≤ x, y < 360). The absolute or relative error in the answer should not exceed 10 - 9.
Examples
Input
12:00
Output
0 0
Input
04:30
Output
135 180
Input
08:17
Output
248.5 102
Note
A note to the second example: the hour hand will be positioned exactly in the middle, between 4 and 5.
Tags: geometry, math
Correct Solution:
```
import sys
import string
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from operator import *
from itertools import accumulate
inf = float("inf")
# input = sys.stdin.readline
flush = lambda: sys.stdout.flush
comb = lambda x, y: (factorial(x) // factorial(y)) // factorial(x - y)
# inputs
# ip = lambda : input().rstrip()
ip = lambda: input()
ii = lambda: int(input())
r = lambda: map(int, input().split())
rr = lambda: list(r())
a, b = map(int, ip().split(":"))
print((a % 12) * 30 + b / 2, b * 6)
```
| 88,909 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Do you remember a kind cartoon "Beauty and the Beast"? No, no, there was no firing from machine guns or radiation mutants time-travels!
There was a beauty named Belle. Once she had violated the Beast's order and visited the West Wing. After that she was banished from the castle...
Everybody was upset. The beautiful Belle was upset, so was the Beast, so was Lumiere the candlestick. But the worst thing was that Cogsworth was upset. Cogsworth is not a human, but is the mantel clock, which was often used as an alarm clock.
Due to Cogsworth's frustration all the inhabitants of the castle were in trouble: now they could not determine when it was time to drink morning tea, and when it was time for an evening stroll.
Fortunately, deep in the basement are lying digital clock showing the time in the format HH:MM. Now the residents of the castle face a difficult task. They should turn Cogsworth's hour and minute mustache hands in such a way, that Cogsworth began to show the correct time. Moreover they need to find turn angles in degrees for each mustache hands. The initial time showed by Cogsworth is 12:00.
You can only rotate the hands forward, that is, as is shown in the picture:
<image>
As since there are many ways too select such angles because of full rotations, choose the smallest angles in the right (non-negative) direction.
Note that Cogsworth's hour and minute mustache hands move evenly and continuously. Hands are moving independently, so when turning one hand the other hand remains standing still.
Input
The only line of input contains current time according to the digital clock, formatted as HH:MM (00 ≤ HH ≤ 23, 00 ≤ MM ≤ 59). The mantel clock initially shows 12:00.
Pretests contain times of the beginning of some morning TV programs of the Channel One Russia.
Output
Print two numbers x and y — the angles of turning the hour and minute hands, respectively (0 ≤ x, y < 360). The absolute or relative error in the answer should not exceed 10 - 9.
Examples
Input
12:00
Output
0 0
Input
04:30
Output
135 180
Input
08:17
Output
248.5 102
Note
A note to the second example: the hour hand will be positioned exactly in the middle, between 4 and 5.
Tags: geometry, math
Correct Solution:
```
hh, mm = map(int, input().split(":"))
print((hh%12)*30 + mm/2, mm*6)
```
| 88,910 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Do you remember a kind cartoon "Beauty and the Beast"? No, no, there was no firing from machine guns or radiation mutants time-travels!
There was a beauty named Belle. Once she had violated the Beast's order and visited the West Wing. After that she was banished from the castle...
Everybody was upset. The beautiful Belle was upset, so was the Beast, so was Lumiere the candlestick. But the worst thing was that Cogsworth was upset. Cogsworth is not a human, but is the mantel clock, which was often used as an alarm clock.
Due to Cogsworth's frustration all the inhabitants of the castle were in trouble: now they could not determine when it was time to drink morning tea, and when it was time for an evening stroll.
Fortunately, deep in the basement are lying digital clock showing the time in the format HH:MM. Now the residents of the castle face a difficult task. They should turn Cogsworth's hour and minute mustache hands in such a way, that Cogsworth began to show the correct time. Moreover they need to find turn angles in degrees for each mustache hands. The initial time showed by Cogsworth is 12:00.
You can only rotate the hands forward, that is, as is shown in the picture:
<image>
As since there are many ways too select such angles because of full rotations, choose the smallest angles in the right (non-negative) direction.
Note that Cogsworth's hour and minute mustache hands move evenly and continuously. Hands are moving independently, so when turning one hand the other hand remains standing still.
Input
The only line of input contains current time according to the digital clock, formatted as HH:MM (00 ≤ HH ≤ 23, 00 ≤ MM ≤ 59). The mantel clock initially shows 12:00.
Pretests contain times of the beginning of some morning TV programs of the Channel One Russia.
Output
Print two numbers x and y — the angles of turning the hour and minute hands, respectively (0 ≤ x, y < 360). The absolute or relative error in the answer should not exceed 10 - 9.
Examples
Input
12:00
Output
0 0
Input
04:30
Output
135 180
Input
08:17
Output
248.5 102
Note
A note to the second example: the hour hand will be positioned exactly in the middle, between 4 and 5.
Tags: geometry, math
Correct Solution:
```
#
# solving:
# from: https://vjudge.net/contest/417235#problem/D
def main():
inlist = input().split(":")
hh, mm = int(inlist[0]), int(inlist[1])
deg_per_h = 360/12
deg_per_m = 360/60
print("{} {}".format(((hh+mm/60) * deg_per_h) % 360, (mm * deg_per_m) % 360))
main()
```
| 88,911 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Do you remember a kind cartoon "Beauty and the Beast"? No, no, there was no firing from machine guns or radiation mutants time-travels!
There was a beauty named Belle. Once she had violated the Beast's order and visited the West Wing. After that she was banished from the castle...
Everybody was upset. The beautiful Belle was upset, so was the Beast, so was Lumiere the candlestick. But the worst thing was that Cogsworth was upset. Cogsworth is not a human, but is the mantel clock, which was often used as an alarm clock.
Due to Cogsworth's frustration all the inhabitants of the castle were in trouble: now they could not determine when it was time to drink morning tea, and when it was time for an evening stroll.
Fortunately, deep in the basement are lying digital clock showing the time in the format HH:MM. Now the residents of the castle face a difficult task. They should turn Cogsworth's hour and minute mustache hands in such a way, that Cogsworth began to show the correct time. Moreover they need to find turn angles in degrees for each mustache hands. The initial time showed by Cogsworth is 12:00.
You can only rotate the hands forward, that is, as is shown in the picture:
<image>
As since there are many ways too select such angles because of full rotations, choose the smallest angles in the right (non-negative) direction.
Note that Cogsworth's hour and minute mustache hands move evenly and continuously. Hands are moving independently, so when turning one hand the other hand remains standing still.
Input
The only line of input contains current time according to the digital clock, formatted as HH:MM (00 ≤ HH ≤ 23, 00 ≤ MM ≤ 59). The mantel clock initially shows 12:00.
Pretests contain times of the beginning of some morning TV programs of the Channel One Russia.
Output
Print two numbers x and y — the angles of turning the hour and minute hands, respectively (0 ≤ x, y < 360). The absolute or relative error in the answer should not exceed 10 - 9.
Examples
Input
12:00
Output
0 0
Input
04:30
Output
135 180
Input
08:17
Output
248.5 102
Note
A note to the second example: the hour hand will be positioned exactly in the middle, between 4 and 5.
Tags: geometry, math
Correct Solution:
```
#
# solving:
# from: https://vjudge.net/contest/417235#problem/D
# Fits the specification exactly uwu
def main():
inlist = input().split(":")
hh, mm = int(inlist[0]), int(inlist[1])
deg_per_h = 360/12
deg_per_m = 360/60
hours = ((hh+mm/60) * deg_per_h) % 360
mins = (mm * deg_per_m) % 360
if hours % 1 == 0: hours = int(hours)
if mins % 1 == 0: mins = int(mins)
print( "{} {}".format(hours, mins) )
main()
```
| 88,912 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Do you remember a kind cartoon "Beauty and the Beast"? No, no, there was no firing from machine guns or radiation mutants time-travels!
There was a beauty named Belle. Once she had violated the Beast's order and visited the West Wing. After that she was banished from the castle...
Everybody was upset. The beautiful Belle was upset, so was the Beast, so was Lumiere the candlestick. But the worst thing was that Cogsworth was upset. Cogsworth is not a human, but is the mantel clock, which was often used as an alarm clock.
Due to Cogsworth's frustration all the inhabitants of the castle were in trouble: now they could not determine when it was time to drink morning tea, and when it was time for an evening stroll.
Fortunately, deep in the basement are lying digital clock showing the time in the format HH:MM. Now the residents of the castle face a difficult task. They should turn Cogsworth's hour and minute mustache hands in such a way, that Cogsworth began to show the correct time. Moreover they need to find turn angles in degrees for each mustache hands. The initial time showed by Cogsworth is 12:00.
You can only rotate the hands forward, that is, as is shown in the picture:
<image>
As since there are many ways too select such angles because of full rotations, choose the smallest angles in the right (non-negative) direction.
Note that Cogsworth's hour and minute mustache hands move evenly and continuously. Hands are moving independently, so when turning one hand the other hand remains standing still.
Input
The only line of input contains current time according to the digital clock, formatted as HH:MM (00 ≤ HH ≤ 23, 00 ≤ MM ≤ 59). The mantel clock initially shows 12:00.
Pretests contain times of the beginning of some morning TV programs of the Channel One Russia.
Output
Print two numbers x and y — the angles of turning the hour and minute hands, respectively (0 ≤ x, y < 360). The absolute or relative error in the answer should not exceed 10 - 9.
Examples
Input
12:00
Output
0 0
Input
04:30
Output
135 180
Input
08:17
Output
248.5 102
Note
A note to the second example: the hour hand will be positioned exactly in the middle, between 4 and 5.
Submitted Solution:
```
s=input()
h=int(s[:2])
m=int(s[3:])
if h>=12:
h=h%12
m1=6*m
h1=30*h+(1/12)*m1
print(h1,m1)
```
Yes
| 88,913 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Do you remember a kind cartoon "Beauty and the Beast"? No, no, there was no firing from machine guns or radiation mutants time-travels!
There was a beauty named Belle. Once she had violated the Beast's order and visited the West Wing. After that she was banished from the castle...
Everybody was upset. The beautiful Belle was upset, so was the Beast, so was Lumiere the candlestick. But the worst thing was that Cogsworth was upset. Cogsworth is not a human, but is the mantel clock, which was often used as an alarm clock.
Due to Cogsworth's frustration all the inhabitants of the castle were in trouble: now they could not determine when it was time to drink morning tea, and when it was time for an evening stroll.
Fortunately, deep in the basement are lying digital clock showing the time in the format HH:MM. Now the residents of the castle face a difficult task. They should turn Cogsworth's hour and minute mustache hands in such a way, that Cogsworth began to show the correct time. Moreover they need to find turn angles in degrees for each mustache hands. The initial time showed by Cogsworth is 12:00.
You can only rotate the hands forward, that is, as is shown in the picture:
<image>
As since there are many ways too select such angles because of full rotations, choose the smallest angles in the right (non-negative) direction.
Note that Cogsworth's hour and minute mustache hands move evenly and continuously. Hands are moving independently, so when turning one hand the other hand remains standing still.
Input
The only line of input contains current time according to the digital clock, formatted as HH:MM (00 ≤ HH ≤ 23, 00 ≤ MM ≤ 59). The mantel clock initially shows 12:00.
Pretests contain times of the beginning of some morning TV programs of the Channel One Russia.
Output
Print two numbers x and y — the angles of turning the hour and minute hands, respectively (0 ≤ x, y < 360). The absolute or relative error in the answer should not exceed 10 - 9.
Examples
Input
12:00
Output
0 0
Input
04:30
Output
135 180
Input
08:17
Output
248.5 102
Note
A note to the second example: the hour hand will be positioned exactly in the middle, between 4 and 5.
Submitted Solution:
```
h,minutes=[int(element) for element in input().split(':')]
answer_minutes=minutes/60*360%360
answer_hours=(h/12*360+360/12*minutes/60)%360
print(answer_hours,answer_minutes)
```
Yes
| 88,914 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Do you remember a kind cartoon "Beauty and the Beast"? No, no, there was no firing from machine guns or radiation mutants time-travels!
There was a beauty named Belle. Once she had violated the Beast's order and visited the West Wing. After that she was banished from the castle...
Everybody was upset. The beautiful Belle was upset, so was the Beast, so was Lumiere the candlestick. But the worst thing was that Cogsworth was upset. Cogsworth is not a human, but is the mantel clock, which was often used as an alarm clock.
Due to Cogsworth's frustration all the inhabitants of the castle were in trouble: now they could not determine when it was time to drink morning tea, and when it was time for an evening stroll.
Fortunately, deep in the basement are lying digital clock showing the time in the format HH:MM. Now the residents of the castle face a difficult task. They should turn Cogsworth's hour and minute mustache hands in such a way, that Cogsworth began to show the correct time. Moreover they need to find turn angles in degrees for each mustache hands. The initial time showed by Cogsworth is 12:00.
You can only rotate the hands forward, that is, as is shown in the picture:
<image>
As since there are many ways too select such angles because of full rotations, choose the smallest angles in the right (non-negative) direction.
Note that Cogsworth's hour and minute mustache hands move evenly and continuously. Hands are moving independently, so when turning one hand the other hand remains standing still.
Input
The only line of input contains current time according to the digital clock, formatted as HH:MM (00 ≤ HH ≤ 23, 00 ≤ MM ≤ 59). The mantel clock initially shows 12:00.
Pretests contain times of the beginning of some morning TV programs of the Channel One Russia.
Output
Print two numbers x and y — the angles of turning the hour and minute hands, respectively (0 ≤ x, y < 360). The absolute or relative error in the answer should not exceed 10 - 9.
Examples
Input
12:00
Output
0 0
Input
04:30
Output
135 180
Input
08:17
Output
248.5 102
Note
A note to the second example: the hour hand will be positioned exactly in the middle, between 4 and 5.
Submitted Solution:
```
input_string = str(input())
time_list = input_string.split(':')
hour = int(time_list[0])%12
minutes = int(time_list[1])%60
hour_degree = (30*hour) + (minutes/2)
minute_degree = minutes*6
print(str('{0:g}'.format(hour_degree)) + ' ' + str(minute_degree))
```
Yes
| 88,915 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Do you remember a kind cartoon "Beauty and the Beast"? No, no, there was no firing from machine guns or radiation mutants time-travels!
There was a beauty named Belle. Once she had violated the Beast's order and visited the West Wing. After that she was banished from the castle...
Everybody was upset. The beautiful Belle was upset, so was the Beast, so was Lumiere the candlestick. But the worst thing was that Cogsworth was upset. Cogsworth is not a human, but is the mantel clock, which was often used as an alarm clock.
Due to Cogsworth's frustration all the inhabitants of the castle were in trouble: now they could not determine when it was time to drink morning tea, and when it was time for an evening stroll.
Fortunately, deep in the basement are lying digital clock showing the time in the format HH:MM. Now the residents of the castle face a difficult task. They should turn Cogsworth's hour and minute mustache hands in such a way, that Cogsworth began to show the correct time. Moreover they need to find turn angles in degrees for each mustache hands. The initial time showed by Cogsworth is 12:00.
You can only rotate the hands forward, that is, as is shown in the picture:
<image>
As since there are many ways too select such angles because of full rotations, choose the smallest angles in the right (non-negative) direction.
Note that Cogsworth's hour and minute mustache hands move evenly and continuously. Hands are moving independently, so when turning one hand the other hand remains standing still.
Input
The only line of input contains current time according to the digital clock, formatted as HH:MM (00 ≤ HH ≤ 23, 00 ≤ MM ≤ 59). The mantel clock initially shows 12:00.
Pretests contain times of the beginning of some morning TV programs of the Channel One Russia.
Output
Print two numbers x and y — the angles of turning the hour and minute hands, respectively (0 ≤ x, y < 360). The absolute or relative error in the answer should not exceed 10 - 9.
Examples
Input
12:00
Output
0 0
Input
04:30
Output
135 180
Input
08:17
Output
248.5 102
Note
A note to the second example: the hour hand will be positioned exactly in the middle, between 4 and 5.
Submitted Solution:
```
import re
import itertools
from collections import Counter
class Task:
time = ""
answer = ""
def getData(self):
self.time = input()
#self.x, self.y = [int(x) for x in input().split(' ')]
#inFile = open('input.txt', 'r')
#inFile.readline().rstrip()
#self.childs = inFile.readline().rstrip()
def solve(self):
hours, minutes = [int(x) for x in self.time.split(':')]
hoursAngle = (30 * hours + minutes / 2) % 360
minutesAngle = (6 * minutes) % 360
self.answer = str(hoursAngle) + " " + str(minutesAngle)
def printAnswer(self):
print(self.answer)
#outFile = open('output.txt', 'w')
#outFile.write(self.answer)
task = Task()
task.getData()
task.solve()
task.printAnswer()
```
Yes
| 88,916 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Do you remember a kind cartoon "Beauty and the Beast"? No, no, there was no firing from machine guns or radiation mutants time-travels!
There was a beauty named Belle. Once she had violated the Beast's order and visited the West Wing. After that she was banished from the castle...
Everybody was upset. The beautiful Belle was upset, so was the Beast, so was Lumiere the candlestick. But the worst thing was that Cogsworth was upset. Cogsworth is not a human, but is the mantel clock, which was often used as an alarm clock.
Due to Cogsworth's frustration all the inhabitants of the castle were in trouble: now they could not determine when it was time to drink morning tea, and when it was time for an evening stroll.
Fortunately, deep in the basement are lying digital clock showing the time in the format HH:MM. Now the residents of the castle face a difficult task. They should turn Cogsworth's hour and minute mustache hands in such a way, that Cogsworth began to show the correct time. Moreover they need to find turn angles in degrees for each mustache hands. The initial time showed by Cogsworth is 12:00.
You can only rotate the hands forward, that is, as is shown in the picture:
<image>
As since there are many ways too select such angles because of full rotations, choose the smallest angles in the right (non-negative) direction.
Note that Cogsworth's hour and minute mustache hands move evenly and continuously. Hands are moving independently, so when turning one hand the other hand remains standing still.
Input
The only line of input contains current time according to the digital clock, formatted as HH:MM (00 ≤ HH ≤ 23, 00 ≤ MM ≤ 59). The mantel clock initially shows 12:00.
Pretests contain times of the beginning of some morning TV programs of the Channel One Russia.
Output
Print two numbers x and y — the angles of turning the hour and minute hands, respectively (0 ≤ x, y < 360). The absolute or relative error in the answer should not exceed 10 - 9.
Examples
Input
12:00
Output
0 0
Input
04:30
Output
135 180
Input
08:17
Output
248.5 102
Note
A note to the second example: the hour hand will be positioned exactly in the middle, between 4 and 5.
Submitted Solution:
```
s = input()
h = int(s[0]) * 10 + int(s[1])
m = int(s[3]) * 10 + int(s[4])
ang1 = round((h + m / 60) * 30)
ang2 = m * 6
if h == 12:
ang1 = 0
print(ang1, ang2)
```
No
| 88,917 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Do you remember a kind cartoon "Beauty and the Beast"? No, no, there was no firing from machine guns or radiation mutants time-travels!
There was a beauty named Belle. Once she had violated the Beast's order and visited the West Wing. After that she was banished from the castle...
Everybody was upset. The beautiful Belle was upset, so was the Beast, so was Lumiere the candlestick. But the worst thing was that Cogsworth was upset. Cogsworth is not a human, but is the mantel clock, which was often used as an alarm clock.
Due to Cogsworth's frustration all the inhabitants of the castle were in trouble: now they could not determine when it was time to drink morning tea, and when it was time for an evening stroll.
Fortunately, deep in the basement are lying digital clock showing the time in the format HH:MM. Now the residents of the castle face a difficult task. They should turn Cogsworth's hour and minute mustache hands in such a way, that Cogsworth began to show the correct time. Moreover they need to find turn angles in degrees for each mustache hands. The initial time showed by Cogsworth is 12:00.
You can only rotate the hands forward, that is, as is shown in the picture:
<image>
As since there are many ways too select such angles because of full rotations, choose the smallest angles in the right (non-negative) direction.
Note that Cogsworth's hour and minute mustache hands move evenly and continuously. Hands are moving independently, so when turning one hand the other hand remains standing still.
Input
The only line of input contains current time according to the digital clock, formatted as HH:MM (00 ≤ HH ≤ 23, 00 ≤ MM ≤ 59). The mantel clock initially shows 12:00.
Pretests contain times of the beginning of some morning TV programs of the Channel One Russia.
Output
Print two numbers x and y — the angles of turning the hour and minute hands, respectively (0 ≤ x, y < 360). The absolute or relative error in the answer should not exceed 10 - 9.
Examples
Input
12:00
Output
0 0
Input
04:30
Output
135 180
Input
08:17
Output
248.5 102
Note
A note to the second example: the hour hand will be positioned exactly in the middle, between 4 and 5.
Submitted Solution:
```
takes = str(input())
clocks = takes.split(':')
h = int(clocks[0])
m = int(clocks[1])
if m != 0:
temp = 30*h
hans = temp + 30/(60/m)
mans = 360/(60/m)
print(hans, mans)
else:
if(h*30)!=360:
print(h*30,m)
else:
print(0,m)
```
No
| 88,918 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Do you remember a kind cartoon "Beauty and the Beast"? No, no, there was no firing from machine guns or radiation mutants time-travels!
There was a beauty named Belle. Once she had violated the Beast's order and visited the West Wing. After that she was banished from the castle...
Everybody was upset. The beautiful Belle was upset, so was the Beast, so was Lumiere the candlestick. But the worst thing was that Cogsworth was upset. Cogsworth is not a human, but is the mantel clock, which was often used as an alarm clock.
Due to Cogsworth's frustration all the inhabitants of the castle were in trouble: now they could not determine when it was time to drink morning tea, and when it was time for an evening stroll.
Fortunately, deep in the basement are lying digital clock showing the time in the format HH:MM. Now the residents of the castle face a difficult task. They should turn Cogsworth's hour and minute mustache hands in such a way, that Cogsworth began to show the correct time. Moreover they need to find turn angles in degrees for each mustache hands. The initial time showed by Cogsworth is 12:00.
You can only rotate the hands forward, that is, as is shown in the picture:
<image>
As since there are many ways too select such angles because of full rotations, choose the smallest angles in the right (non-negative) direction.
Note that Cogsworth's hour and minute mustache hands move evenly and continuously. Hands are moving independently, so when turning one hand the other hand remains standing still.
Input
The only line of input contains current time according to the digital clock, formatted as HH:MM (00 ≤ HH ≤ 23, 00 ≤ MM ≤ 59). The mantel clock initially shows 12:00.
Pretests contain times of the beginning of some morning TV programs of the Channel One Russia.
Output
Print two numbers x and y — the angles of turning the hour and minute hands, respectively (0 ≤ x, y < 360). The absolute or relative error in the answer should not exceed 10 - 9.
Examples
Input
12:00
Output
0 0
Input
04:30
Output
135 180
Input
08:17
Output
248.5 102
Note
A note to the second example: the hour hand will be positioned exactly in the middle, between 4 and 5.
Submitted Solution:
```
# link: https://codeforces.com/problemset/problem/80/B
from sys import stdin, stdout
if __name__ == "__main__":
time_ = stdin.readline()
time_ = time_.lstrip()
time_ = time_.split(':')
time_ = [int(x) for x in time_]
# print(time_)
if time_[0] == 12 and time_[-1] == 0:
print(0,0)
exit(0)
minutes_degree = time_[-1] * 6
if time_[0] == 12:
time_[0] = 0
hours_degree = round( (time_[0] + time_[-1]/60) * 30, 1 )
print( hours_degree, minutes_degree )
```
No
| 88,919 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Do you remember a kind cartoon "Beauty and the Beast"? No, no, there was no firing from machine guns or radiation mutants time-travels!
There was a beauty named Belle. Once she had violated the Beast's order and visited the West Wing. After that she was banished from the castle...
Everybody was upset. The beautiful Belle was upset, so was the Beast, so was Lumiere the candlestick. But the worst thing was that Cogsworth was upset. Cogsworth is not a human, but is the mantel clock, which was often used as an alarm clock.
Due to Cogsworth's frustration all the inhabitants of the castle were in trouble: now they could not determine when it was time to drink morning tea, and when it was time for an evening stroll.
Fortunately, deep in the basement are lying digital clock showing the time in the format HH:MM. Now the residents of the castle face a difficult task. They should turn Cogsworth's hour and minute mustache hands in such a way, that Cogsworth began to show the correct time. Moreover they need to find turn angles in degrees for each mustache hands. The initial time showed by Cogsworth is 12:00.
You can only rotate the hands forward, that is, as is shown in the picture:
<image>
As since there are many ways too select such angles because of full rotations, choose the smallest angles in the right (non-negative) direction.
Note that Cogsworth's hour and minute mustache hands move evenly and continuously. Hands are moving independently, so when turning one hand the other hand remains standing still.
Input
The only line of input contains current time according to the digital clock, formatted as HH:MM (00 ≤ HH ≤ 23, 00 ≤ MM ≤ 59). The mantel clock initially shows 12:00.
Pretests contain times of the beginning of some morning TV programs of the Channel One Russia.
Output
Print two numbers x and y — the angles of turning the hour and minute hands, respectively (0 ≤ x, y < 360). The absolute or relative error in the answer should not exceed 10 - 9.
Examples
Input
12:00
Output
0 0
Input
04:30
Output
135 180
Input
08:17
Output
248.5 102
Note
A note to the second example: the hour hand will be positioned exactly in the middle, between 4 and 5.
Submitted Solution:
```
x=(input())
a=int(x[0:2])
b=int(x[3:])
lol=a*30+0.5*b
yo=b*6
if a==12:
lol=0
print(lol,yo)
```
No
| 88,920 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time, waits the first train to come and rides on it to the end of the branch to the corresponding girl. However, the trains run with different frequencies: a train goes to Dasha's direction every a minutes, but a train goes to Masha's direction every b minutes. If two trains approach at the same time, Vasya goes toward the direction with the lower frequency of going trains, that is, to the girl, to whose directions the trains go less frequently (see the note to the third sample).
We know that the trains begin to go simultaneously before Vasya appears. That is the train schedule is such that there exists a moment of time when the two trains arrive simultaneously.
Help Vasya count to which girlfriend he will go more often.
Input
The first line contains two integers a and b (a ≠ b, 1 ≤ a, b ≤ 106).
Output
Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency.
Examples
Input
3 7
Output
Dasha
Input
5 3
Output
Masha
Input
2 3
Output
Equal
Note
Let's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0, 6], he will go to both girls equally often.
If he descends to the subway at a moment of time from 0 to 2, he leaves for Dasha on the train that arrives by the second minute.
If he descends to the subway at a moment of time from 2 to 3, he leaves for Masha on the train that arrives by the third minute.
If he descends to the subway at a moment of time from 3 to 4, he leaves for Dasha on the train that arrives by the fourth minute.
If he descends to the subway at a moment of time from 4 to 6, he waits for both trains to arrive by the sixth minute and goes to Masha as trains go less often in Masha's direction.
In sum Masha and Dasha get equal time — three minutes for each one, thus, Vasya will go to both girlfriends equally often.
Tags: implementation, math
Correct Solution:
```
from math import *
a, b = map(int, input().split())
print('Equal' if gcd(a, b) == abs(b - a) else 'Dasha' if a < b else 'Masha')
```
| 88,921 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time, waits the first train to come and rides on it to the end of the branch to the corresponding girl. However, the trains run with different frequencies: a train goes to Dasha's direction every a minutes, but a train goes to Masha's direction every b minutes. If two trains approach at the same time, Vasya goes toward the direction with the lower frequency of going trains, that is, to the girl, to whose directions the trains go less frequently (see the note to the third sample).
We know that the trains begin to go simultaneously before Vasya appears. That is the train schedule is such that there exists a moment of time when the two trains arrive simultaneously.
Help Vasya count to which girlfriend he will go more often.
Input
The first line contains two integers a and b (a ≠ b, 1 ≤ a, b ≤ 106).
Output
Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency.
Examples
Input
3 7
Output
Dasha
Input
5 3
Output
Masha
Input
2 3
Output
Equal
Note
Let's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0, 6], he will go to both girls equally often.
If he descends to the subway at a moment of time from 0 to 2, he leaves for Dasha on the train that arrives by the second minute.
If he descends to the subway at a moment of time from 2 to 3, he leaves for Masha on the train that arrives by the third minute.
If he descends to the subway at a moment of time from 3 to 4, he leaves for Dasha on the train that arrives by the fourth minute.
If he descends to the subway at a moment of time from 4 to 6, he waits for both trains to arrive by the sixth minute and goes to Masha as trains go less often in Masha's direction.
In sum Masha and Dasha get equal time — three minutes for each one, thus, Vasya will go to both girlfriends equally often.
Tags: implementation, math
Correct Solution:
```
"""
Author : co_devil Chirag Garg
Institute : JIIT
"""
from __future__ import division, print_function
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
# from heapq import nsmallest, nlargest, heapify, #heappop ,heappush, heapreplace
from math import ceil,floor,log,sqrt,factorial,pow,pi
# from bisect import bisect_left,bisect_right
# from decimal import *,threading
"""from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
else:
from builtins import str as __str__
str = lambda x=b'': x if type(x) is bytes else __str__(x).encode()
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._buffer = BytesIO()
self._fd = file.fileno()
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):
return self._buffer.read() if self._buffer.tell() else os.read(self._fd, os.fstat(self._fd).st_size)
def readline(self):
while self.newlines == 0:
b, ptr = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)), self._buffer.tell()
self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
self.newlines += b.count(b'\n') + (not b)
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)
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b'\r\n')
def print(*args, **kwargs):
sep, file = kwargs.pop('sep', b' '), 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', b'\n'))
if kwargs.pop('flush', False):
file.flush()
"""
def ii(): return int(input())
def si(): return str(input())
def mi(): return map(int,input().split())
def li(): return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12,
'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24,
'z': 25}
mod = 1000000007
dx, dy = [-1, 1, 0, 0], [0, 0, 1, -1]
def getKey(item): return item[0]
def sort2(l): return sorted(l, key=getKey)
def d2(n, m, num): return [[num for x in range(m)] for y in range(n)]
def isPowerOfTwo(x): return (x and (not (x & (x - 1))))
def decimalToBinary(n): return bin(n).replace("0b", "")
def ntl(n): return [int(i) for i in str(n)]
def powerMod(x, y, p):
res = 1
x %= p
while y > 0:
if y & 1:
res = (res * x) % p
y = y >> 1
x = (x * x) % p1
return res
def gcd(x, y):
while y:
x, y = y, x % y
return x
# For getting input from input.txt file
# sys.stdin = open('input.txt', 'r')
# Printing the Output to output.txt file
# sys.stdout = open('output.txt', 'w')
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000
def dfs(v, c):
if visited[v]:
if col[v] != c:
print('-1')
exit()
return
col[v] = c
visited[v] = 1
for i in graph[v]:
dfs(i, c ^ 1)
def bfs(d,v):
q=[]
q.append(v)
visited[v]=1
while len(q)!=0:
x=q[0]
q.pop(0)
for i in d[x]:
if visited[i]!=1:
visited[i]=1
q.append(i)
print(x)
def make_graph():
d={}
v,e=mi()
for i in range(e):
x,y=mi()
if x not in d.keys():
d[x]=[y]
else:
d[x].append(y)
if y not in d.keys():
d[y] = [x]
else:
d[y].append(x)
return d
def gr2(l,n):
d={}
for i in range(1,n+1):
if i not in d.keys():
d[i]=l[i]
else:
d[i].append(l[i])
return d
d,m=mi()
da,ma=0,0
l=d*m//gcd(d,m)
a=l//d-1
b=l//m-1
if a<b:
a+=1
else:
b+=1
if a<b:
print("Masha")
elif a>b:
print("Dasha")
else:
print("Equal")
```
| 88,922 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time, waits the first train to come and rides on it to the end of the branch to the corresponding girl. However, the trains run with different frequencies: a train goes to Dasha's direction every a minutes, but a train goes to Masha's direction every b minutes. If two trains approach at the same time, Vasya goes toward the direction with the lower frequency of going trains, that is, to the girl, to whose directions the trains go less frequently (see the note to the third sample).
We know that the trains begin to go simultaneously before Vasya appears. That is the train schedule is such that there exists a moment of time when the two trains arrive simultaneously.
Help Vasya count to which girlfriend he will go more often.
Input
The first line contains two integers a and b (a ≠ b, 1 ≤ a, b ≤ 106).
Output
Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency.
Examples
Input
3 7
Output
Dasha
Input
5 3
Output
Masha
Input
2 3
Output
Equal
Note
Let's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0, 6], he will go to both girls equally often.
If he descends to the subway at a moment of time from 0 to 2, he leaves for Dasha on the train that arrives by the second minute.
If he descends to the subway at a moment of time from 2 to 3, he leaves for Masha on the train that arrives by the third minute.
If he descends to the subway at a moment of time from 3 to 4, he leaves for Dasha on the train that arrives by the fourth minute.
If he descends to the subway at a moment of time from 4 to 6, he waits for both trains to arrive by the sixth minute and goes to Masha as trains go less often in Masha's direction.
In sum Masha and Dasha get equal time — three minutes for each one, thus, Vasya will go to both girlfriends equally often.
Tags: implementation, math
Correct Solution:
```
a, b = map(int, input().split())
swapped = False
if b < a:
a, b = b, a
swapped = True
a_count, b_count = 0, 0
t = 0
while True:
t += b
if t % a == 0:
a_count += b - a
b_count += a
break
else:
a_count += b - t % a
b_count += t % a
if swapped:
a_count, b_count = b_count, a_count
if a_count > b_count:
print('Dasha')
elif a_count < b_count:
print('Masha')
else:
print('Equal')
```
| 88,923 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time, waits the first train to come and rides on it to the end of the branch to the corresponding girl. However, the trains run with different frequencies: a train goes to Dasha's direction every a minutes, but a train goes to Masha's direction every b minutes. If two trains approach at the same time, Vasya goes toward the direction with the lower frequency of going trains, that is, to the girl, to whose directions the trains go less frequently (see the note to the third sample).
We know that the trains begin to go simultaneously before Vasya appears. That is the train schedule is such that there exists a moment of time when the two trains arrive simultaneously.
Help Vasya count to which girlfriend he will go more often.
Input
The first line contains two integers a and b (a ≠ b, 1 ≤ a, b ≤ 106).
Output
Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency.
Examples
Input
3 7
Output
Dasha
Input
5 3
Output
Masha
Input
2 3
Output
Equal
Note
Let's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0, 6], he will go to both girls equally often.
If he descends to the subway at a moment of time from 0 to 2, he leaves for Dasha on the train that arrives by the second minute.
If he descends to the subway at a moment of time from 2 to 3, he leaves for Masha on the train that arrives by the third minute.
If he descends to the subway at a moment of time from 3 to 4, he leaves for Dasha on the train that arrives by the fourth minute.
If he descends to the subway at a moment of time from 4 to 6, he waits for both trains to arrive by the sixth minute and goes to Masha as trains go less often in Masha's direction.
In sum Masha and Dasha get equal time — three minutes for each one, thus, Vasya will go to both girlfriends equally often.
Tags: implementation, math
Correct Solution:
```
from math import gcd
def lcm(a, b):
return (a * b) // gcd(a, b)
i = 0
a, b = map(int, input().split())
first = False
second = False
masha = 0
dasha = 0
while i < lcm(a, b):
if first:
masha += b - (i % b)
i += b - (i % b)
elif second:
dasha += a - (i % a)
i += a - (i % a)
if i % a == 0 and i % b == 0:
if a > b:
first = True
second = False
else:
first = False
second = True
elif first:
second = True
first = False
else:
first = True
second = False
if masha > dasha:
print("Dasha")
elif dasha > masha:
print("Masha")
else:
print("Equal")
```
| 88,924 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time, waits the first train to come and rides on it to the end of the branch to the corresponding girl. However, the trains run with different frequencies: a train goes to Dasha's direction every a minutes, but a train goes to Masha's direction every b minutes. If two trains approach at the same time, Vasya goes toward the direction with the lower frequency of going trains, that is, to the girl, to whose directions the trains go less frequently (see the note to the third sample).
We know that the trains begin to go simultaneously before Vasya appears. That is the train schedule is such that there exists a moment of time when the two trains arrive simultaneously.
Help Vasya count to which girlfriend he will go more often.
Input
The first line contains two integers a and b (a ≠ b, 1 ≤ a, b ≤ 106).
Output
Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency.
Examples
Input
3 7
Output
Dasha
Input
5 3
Output
Masha
Input
2 3
Output
Equal
Note
Let's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0, 6], he will go to both girls equally often.
If he descends to the subway at a moment of time from 0 to 2, he leaves for Dasha on the train that arrives by the second minute.
If he descends to the subway at a moment of time from 2 to 3, he leaves for Masha on the train that arrives by the third minute.
If he descends to the subway at a moment of time from 3 to 4, he leaves for Dasha on the train that arrives by the fourth minute.
If he descends to the subway at a moment of time from 4 to 6, he waits for both trains to arrive by the sixth minute and goes to Masha as trains go less often in Masha's direction.
In sum Masha and Dasha get equal time — three minutes for each one, thus, Vasya will go to both girlfriends equally often.
Tags: implementation, math
Correct Solution:
```
d, m = map(int, input().split())
g, l = max(d, m), min(d, m)
while True:
if not(g % l): break
g, l = l, g%l
lcm = (d * m) // l
dcnt = (lcm // d) - 1
mcnt = (lcm // m) - 1
if d > m: dcnt += 1
else: mcnt += 1
if (dcnt == mcnt): print("Equal")
elif (dcnt > mcnt): print("Dasha")
else: print("Masha")
```
| 88,925 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time, waits the first train to come and rides on it to the end of the branch to the corresponding girl. However, the trains run with different frequencies: a train goes to Dasha's direction every a minutes, but a train goes to Masha's direction every b minutes. If two trains approach at the same time, Vasya goes toward the direction with the lower frequency of going trains, that is, to the girl, to whose directions the trains go less frequently (see the note to the third sample).
We know that the trains begin to go simultaneously before Vasya appears. That is the train schedule is such that there exists a moment of time when the two trains arrive simultaneously.
Help Vasya count to which girlfriend he will go more often.
Input
The first line contains two integers a and b (a ≠ b, 1 ≤ a, b ≤ 106).
Output
Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency.
Examples
Input
3 7
Output
Dasha
Input
5 3
Output
Masha
Input
2 3
Output
Equal
Note
Let's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0, 6], he will go to both girls equally often.
If he descends to the subway at a moment of time from 0 to 2, he leaves for Dasha on the train that arrives by the second minute.
If he descends to the subway at a moment of time from 2 to 3, he leaves for Masha on the train that arrives by the third minute.
If he descends to the subway at a moment of time from 3 to 4, he leaves for Dasha on the train that arrives by the fourth minute.
If he descends to the subway at a moment of time from 4 to 6, he waits for both trains to arrive by the sixth minute and goes to Masha as trains go less often in Masha's direction.
In sum Masha and Dasha get equal time — three minutes for each one, thus, Vasya will go to both girlfriends equally often.
Tags: implementation, math
Correct Solution:
```
import math
import sys
input=sys.stdin.readline
a,b=list(map(int,input().split()))
x=math.gcd(a,b)
a,b=a//x,b//x
if abs(a-b)==1:
print('Equal')
elif a<b:
print('Dasha')
else:
print('Masha')
```
| 88,926 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time, waits the first train to come and rides on it to the end of the branch to the corresponding girl. However, the trains run with different frequencies: a train goes to Dasha's direction every a minutes, but a train goes to Masha's direction every b minutes. If two trains approach at the same time, Vasya goes toward the direction with the lower frequency of going trains, that is, to the girl, to whose directions the trains go less frequently (see the note to the third sample).
We know that the trains begin to go simultaneously before Vasya appears. That is the train schedule is such that there exists a moment of time when the two trains arrive simultaneously.
Help Vasya count to which girlfriend he will go more often.
Input
The first line contains two integers a and b (a ≠ b, 1 ≤ a, b ≤ 106).
Output
Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency.
Examples
Input
3 7
Output
Dasha
Input
5 3
Output
Masha
Input
2 3
Output
Equal
Note
Let's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0, 6], he will go to both girls equally often.
If he descends to the subway at a moment of time from 0 to 2, he leaves for Dasha on the train that arrives by the second minute.
If he descends to the subway at a moment of time from 2 to 3, he leaves for Masha on the train that arrives by the third minute.
If he descends to the subway at a moment of time from 3 to 4, he leaves for Dasha on the train that arrives by the fourth minute.
If he descends to the subway at a moment of time from 4 to 6, he waits for both trains to arrive by the sixth minute and goes to Masha as trains go less often in Masha's direction.
In sum Masha and Dasha get equal time — three minutes for each one, thus, Vasya will go to both girlfriends equally often.
Tags: implementation, math
Correct Solution:
```
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
#from bisect import bisect_left as bl #c++ lowerbound bl(array,element)
#from bisect import bisect_right as br #c++ upperbound br(array,element)
import math
def main():
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
a,b=map(int,input().split(" "))
lcm=(a*b)//math.gcd(a,b)
if abs(lcm//a-lcm//b)<=1:
print("Equal")
elif lcm//a<lcm//b:
print("Masha")
else:
print("Dasha")
#-----------------------------BOSS-------------------------------------!
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
main()
```
| 88,927 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time, waits the first train to come and rides on it to the end of the branch to the corresponding girl. However, the trains run with different frequencies: a train goes to Dasha's direction every a minutes, but a train goes to Masha's direction every b minutes. If two trains approach at the same time, Vasya goes toward the direction with the lower frequency of going trains, that is, to the girl, to whose directions the trains go less frequently (see the note to the third sample).
We know that the trains begin to go simultaneously before Vasya appears. That is the train schedule is such that there exists a moment of time when the two trains arrive simultaneously.
Help Vasya count to which girlfriend he will go more often.
Input
The first line contains two integers a and b (a ≠ b, 1 ≤ a, b ≤ 106).
Output
Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency.
Examples
Input
3 7
Output
Dasha
Input
5 3
Output
Masha
Input
2 3
Output
Equal
Note
Let's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0, 6], he will go to both girls equally often.
If he descends to the subway at a moment of time from 0 to 2, he leaves for Dasha on the train that arrives by the second minute.
If he descends to the subway at a moment of time from 2 to 3, he leaves for Masha on the train that arrives by the third minute.
If he descends to the subway at a moment of time from 3 to 4, he leaves for Dasha on the train that arrives by the fourth minute.
If he descends to the subway at a moment of time from 4 to 6, he waits for both trains to arrive by the sixth minute and goes to Masha as trains go less often in Masha's direction.
In sum Masha and Dasha get equal time — three minutes for each one, thus, Vasya will go to both girlfriends equally often.
Tags: implementation, math
Correct Solution:
```
a, b = input().split()
a = int(a); b = int(b)
def gcd(a, b):
if a < b:
return gcd(b, a)
elif not a%b:
return b
return gcd(b, a%b)
lcm = a*b//gcd(a, b)
if a > b:
d_count = lcm//a
m_count = lcm//b - 1
if m_count > d_count:
print("Masha")
elif m_count == d_count:
print("Equal")
else:
print("Dasha")
else:
d_count = lcm//a - 1
m_count = lcm//b
if m_count > d_count:
print("Masha")
elif m_count == d_count:
print("Equal")
else:
print("Dasha")
```
| 88,928 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time, waits the first train to come and rides on it to the end of the branch to the corresponding girl. However, the trains run with different frequencies: a train goes to Dasha's direction every a minutes, but a train goes to Masha's direction every b minutes. If two trains approach at the same time, Vasya goes toward the direction with the lower frequency of going trains, that is, to the girl, to whose directions the trains go less frequently (see the note to the third sample).
We know that the trains begin to go simultaneously before Vasya appears. That is the train schedule is such that there exists a moment of time when the two trains arrive simultaneously.
Help Vasya count to which girlfriend he will go more often.
Input
The first line contains two integers a and b (a ≠ b, 1 ≤ a, b ≤ 106).
Output
Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency.
Examples
Input
3 7
Output
Dasha
Input
5 3
Output
Masha
Input
2 3
Output
Equal
Note
Let's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0, 6], he will go to both girls equally often.
If he descends to the subway at a moment of time from 0 to 2, he leaves for Dasha on the train that arrives by the second minute.
If he descends to the subway at a moment of time from 2 to 3, he leaves for Masha on the train that arrives by the third minute.
If he descends to the subway at a moment of time from 3 to 4, he leaves for Dasha on the train that arrives by the fourth minute.
If he descends to the subway at a moment of time from 4 to 6, he waits for both trains to arrive by the sixth minute and goes to Masha as trains go less often in Masha's direction.
In sum Masha and Dasha get equal time — three minutes for each one, thus, Vasya will go to both girlfriends equally often.
Submitted Solution:
```
a, b = map(int, input().split())
flag = 0
if a > b:
flag = 1
a, b = b, a
k, x, y = 1, 0, 0
while b * k % a:
x += b - b * k % a
y += b * k % a
k += 1
x += b - a
y += a
print([['Masha', 'Equal'][x == y], 'Dasha'][flag and y > x or not flag and x > y])
```
Yes
| 88,929 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time, waits the first train to come and rides on it to the end of the branch to the corresponding girl. However, the trains run with different frequencies: a train goes to Dasha's direction every a minutes, but a train goes to Masha's direction every b minutes. If two trains approach at the same time, Vasya goes toward the direction with the lower frequency of going trains, that is, to the girl, to whose directions the trains go less frequently (see the note to the third sample).
We know that the trains begin to go simultaneously before Vasya appears. That is the train schedule is such that there exists a moment of time when the two trains arrive simultaneously.
Help Vasya count to which girlfriend he will go more often.
Input
The first line contains two integers a and b (a ≠ b, 1 ≤ a, b ≤ 106).
Output
Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency.
Examples
Input
3 7
Output
Dasha
Input
5 3
Output
Masha
Input
2 3
Output
Equal
Note
Let's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0, 6], he will go to both girls equally often.
If he descends to the subway at a moment of time from 0 to 2, he leaves for Dasha on the train that arrives by the second minute.
If he descends to the subway at a moment of time from 2 to 3, he leaves for Masha on the train that arrives by the third minute.
If he descends to the subway at a moment of time from 3 to 4, he leaves for Dasha on the train that arrives by the fourth minute.
If he descends to the subway at a moment of time from 4 to 6, he waits for both trains to arrive by the sixth minute and goes to Masha as trains go less often in Masha's direction.
In sum Masha and Dasha get equal time — three minutes for each one, thus, Vasya will go to both girlfriends equally often.
Submitted Solution:
```
from math import gcd
def lcm(x , y):
return (x*y) // gcd(x , y)
a , b = map(int,input().split())
r1 = lcm(a , b)
r2 = r1 // a
r3 = r1 // b
r2 -= 1
r3 -= 1
if r2 < r3 :
r2 += 1
if r3 < r2 :
r3 += 1
if r2 == r3:
print('Equal')
elif r2 > r3 :
print('Dasha')
else:
print('Masha')
```
Yes
| 88,930 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time, waits the first train to come and rides on it to the end of the branch to the corresponding girl. However, the trains run with different frequencies: a train goes to Dasha's direction every a minutes, but a train goes to Masha's direction every b minutes. If two trains approach at the same time, Vasya goes toward the direction with the lower frequency of going trains, that is, to the girl, to whose directions the trains go less frequently (see the note to the third sample).
We know that the trains begin to go simultaneously before Vasya appears. That is the train schedule is such that there exists a moment of time when the two trains arrive simultaneously.
Help Vasya count to which girlfriend he will go more often.
Input
The first line contains two integers a and b (a ≠ b, 1 ≤ a, b ≤ 106).
Output
Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency.
Examples
Input
3 7
Output
Dasha
Input
5 3
Output
Masha
Input
2 3
Output
Equal
Note
Let's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0, 6], he will go to both girls equally often.
If he descends to the subway at a moment of time from 0 to 2, he leaves for Dasha on the train that arrives by the second minute.
If he descends to the subway at a moment of time from 2 to 3, he leaves for Masha on the train that arrives by the third minute.
If he descends to the subway at a moment of time from 3 to 4, he leaves for Dasha on the train that arrives by the fourth minute.
If he descends to the subway at a moment of time from 4 to 6, he waits for both trains to arrive by the sixth minute and goes to Masha as trains go less often in Masha's direction.
In sum Masha and Dasha get equal time — three minutes for each one, thus, Vasya will go to both girlfriends equally often.
Submitted Solution:
```
def GCD(a,b):
if b==0:
return a
else:
return GCD(b,a%b)
s = input()
a = int(s.split()[0])
b = int(s.split()[1])
g = GCD(a,b)
l = a*b//g
x = l//a
y = l//b
if x==y or abs(x-y)==1:
print('Equal')
elif x>y:
print('Dasha')
else:
print('Masha')
```
Yes
| 88,931 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time, waits the first train to come and rides on it to the end of the branch to the corresponding girl. However, the trains run with different frequencies: a train goes to Dasha's direction every a minutes, but a train goes to Masha's direction every b minutes. If two trains approach at the same time, Vasya goes toward the direction with the lower frequency of going trains, that is, to the girl, to whose directions the trains go less frequently (see the note to the third sample).
We know that the trains begin to go simultaneously before Vasya appears. That is the train schedule is such that there exists a moment of time when the two trains arrive simultaneously.
Help Vasya count to which girlfriend he will go more often.
Input
The first line contains two integers a and b (a ≠ b, 1 ≤ a, b ≤ 106).
Output
Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency.
Examples
Input
3 7
Output
Dasha
Input
5 3
Output
Masha
Input
2 3
Output
Equal
Note
Let's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0, 6], he will go to both girls equally often.
If he descends to the subway at a moment of time from 0 to 2, he leaves for Dasha on the train that arrives by the second minute.
If he descends to the subway at a moment of time from 2 to 3, he leaves for Masha on the train that arrives by the third minute.
If he descends to the subway at a moment of time from 3 to 4, he leaves for Dasha on the train that arrives by the fourth minute.
If he descends to the subway at a moment of time from 4 to 6, he waits for both trains to arrive by the sixth minute and goes to Masha as trains go less often in Masha's direction.
In sum Masha and Dasha get equal time — three minutes for each one, thus, Vasya will go to both girlfriends equally often.
Submitted Solution:
```
a,b=map(int,input().split())
x,y=a,b
while(y):
x, y = y, x % y
n=a*b//x
d=n/a
m=n/b
if(a>b):
d+=1
if(b>a):
m+=1
if d>m:
print('Dasha')
elif m>d:
print('Masha')
else:
print('Equal')
```
Yes
| 88,932 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time, waits the first train to come and rides on it to the end of the branch to the corresponding girl. However, the trains run with different frequencies: a train goes to Dasha's direction every a minutes, but a train goes to Masha's direction every b minutes. If two trains approach at the same time, Vasya goes toward the direction with the lower frequency of going trains, that is, to the girl, to whose directions the trains go less frequently (see the note to the third sample).
We know that the trains begin to go simultaneously before Vasya appears. That is the train schedule is such that there exists a moment of time when the two trains arrive simultaneously.
Help Vasya count to which girlfriend he will go more often.
Input
The first line contains two integers a and b (a ≠ b, 1 ≤ a, b ≤ 106).
Output
Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency.
Examples
Input
3 7
Output
Dasha
Input
5 3
Output
Masha
Input
2 3
Output
Equal
Note
Let's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0, 6], he will go to both girls equally often.
If he descends to the subway at a moment of time from 0 to 2, he leaves for Dasha on the train that arrives by the second minute.
If he descends to the subway at a moment of time from 2 to 3, he leaves for Masha on the train that arrives by the third minute.
If he descends to the subway at a moment of time from 3 to 4, he leaves for Dasha on the train that arrives by the fourth minute.
If he descends to the subway at a moment of time from 4 to 6, he waits for both trains to arrive by the sixth minute and goes to Masha as trains go less often in Masha's direction.
In sum Masha and Dasha get equal time — three minutes for each one, thus, Vasya will go to both girlfriends equally often.
Submitted Solution:
```
x=input().split()
d =int(x[0])
m =int(x[1])
b= max(d,m); s= min(d,m); a=0
while(True):
if (b%d==0 and b%m==0):
c=b
break
a+=1
b=b*a
y = c/d
z = c/m
if d>m:
y+=1
else:
z+=1
if y>z:
print("Dasha")
elif y<z:
print("Masha")
else:
print("Equal")
```
No
| 88,933 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time, waits the first train to come and rides on it to the end of the branch to the corresponding girl. However, the trains run with different frequencies: a train goes to Dasha's direction every a minutes, but a train goes to Masha's direction every b minutes. If two trains approach at the same time, Vasya goes toward the direction with the lower frequency of going trains, that is, to the girl, to whose directions the trains go less frequently (see the note to the third sample).
We know that the trains begin to go simultaneously before Vasya appears. That is the train schedule is such that there exists a moment of time when the two trains arrive simultaneously.
Help Vasya count to which girlfriend he will go more often.
Input
The first line contains two integers a and b (a ≠ b, 1 ≤ a, b ≤ 106).
Output
Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency.
Examples
Input
3 7
Output
Dasha
Input
5 3
Output
Masha
Input
2 3
Output
Equal
Note
Let's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0, 6], he will go to both girls equally often.
If he descends to the subway at a moment of time from 0 to 2, he leaves for Dasha on the train that arrives by the second minute.
If he descends to the subway at a moment of time from 2 to 3, he leaves for Masha on the train that arrives by the third minute.
If he descends to the subway at a moment of time from 3 to 4, he leaves for Dasha on the train that arrives by the fourth minute.
If he descends to the subway at a moment of time from 4 to 6, he waits for both trains to arrive by the sixth minute and goes to Masha as trains go less often in Masha's direction.
In sum Masha and Dasha get equal time — three minutes for each one, thus, Vasya will go to both girlfriends equally often.
Submitted Solution:
```
from math import *
a,b=map(int,input().split())
a1=0
b1=0
for i in range(1,gcd(a,b)+1):
if i%a==0 and i%b!=0:a1+=1
if i%b==0 and i%a!=0:b1+=1
if i%a==0 and i%b==0:
if a>b:a1+=1
else:b1+=1
if a1>b1:
print('Dasha')
elif b1>a1:
print('Masha')
else:print('Equal')
```
No
| 88,934 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time, waits the first train to come and rides on it to the end of the branch to the corresponding girl. However, the trains run with different frequencies: a train goes to Dasha's direction every a minutes, but a train goes to Masha's direction every b minutes. If two trains approach at the same time, Vasya goes toward the direction with the lower frequency of going trains, that is, to the girl, to whose directions the trains go less frequently (see the note to the third sample).
We know that the trains begin to go simultaneously before Vasya appears. That is the train schedule is such that there exists a moment of time when the two trains arrive simultaneously.
Help Vasya count to which girlfriend he will go more often.
Input
The first line contains two integers a and b (a ≠ b, 1 ≤ a, b ≤ 106).
Output
Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency.
Examples
Input
3 7
Output
Dasha
Input
5 3
Output
Masha
Input
2 3
Output
Equal
Note
Let's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0, 6], he will go to both girls equally often.
If he descends to the subway at a moment of time from 0 to 2, he leaves for Dasha on the train that arrives by the second minute.
If he descends to the subway at a moment of time from 2 to 3, he leaves for Masha on the train that arrives by the third minute.
If he descends to the subway at a moment of time from 3 to 4, he leaves for Dasha on the train that arrives by the fourth minute.
If he descends to the subway at a moment of time from 4 to 6, he waits for both trains to arrive by the sixth minute and goes to Masha as trains go less often in Masha's direction.
In sum Masha and Dasha get equal time — three minutes for each one, thus, Vasya will go to both girlfriends equally often.
Submitted Solution:
```
import sys
a, b = input().split()
a = int(a)
b = int(b)
def gcd(a,b):
if(b==0):
return a
else:
return gcd(b,a%b)
a = a / gcd(a,b)
b = b / gcd(a,b)
if(abs(a-b)==1):
print('Equal')
sys.exit()
if(a < b):
print('Dasha')
sys.exit()
if(a > b):
print('Masha')
sys.exit()
```
No
| 88,935 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time, waits the first train to come and rides on it to the end of the branch to the corresponding girl. However, the trains run with different frequencies: a train goes to Dasha's direction every a minutes, but a train goes to Masha's direction every b minutes. If two trains approach at the same time, Vasya goes toward the direction with the lower frequency of going trains, that is, to the girl, to whose directions the trains go less frequently (see the note to the third sample).
We know that the trains begin to go simultaneously before Vasya appears. That is the train schedule is such that there exists a moment of time when the two trains arrive simultaneously.
Help Vasya count to which girlfriend he will go more often.
Input
The first line contains two integers a and b (a ≠ b, 1 ≤ a, b ≤ 106).
Output
Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency.
Examples
Input
3 7
Output
Dasha
Input
5 3
Output
Masha
Input
2 3
Output
Equal
Note
Let's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0, 6], he will go to both girls equally often.
If he descends to the subway at a moment of time from 0 to 2, he leaves for Dasha on the train that arrives by the second minute.
If he descends to the subway at a moment of time from 2 to 3, he leaves for Masha on the train that arrives by the third minute.
If he descends to the subway at a moment of time from 3 to 4, he leaves for Dasha on the train that arrives by the fourth minute.
If he descends to the subway at a moment of time from 4 to 6, he waits for both trains to arrive by the sixth minute and goes to Masha as trains go less often in Masha's direction.
In sum Masha and Dasha get equal time — three minutes for each one, thus, Vasya will go to both girlfriends equally often.
Submitted Solution:
```
a,b=map(int,input().split())
g=lambda x,y:g(y%x,x)if x else y
g=g(a,b)
c=a//g*b
A=c//a-g
B=c//b-g
if a<b:B+=g
if a>b:A+=g
if A>B:r='Dasha'
elif A<B:r='Masha'
else:r='Equal'
print(r)
```
No
| 88,936 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai.
Mishka can put a box i into another box j if the following conditions are met:
* i-th box is not put into another box;
* j-th box doesn't contain any other boxes;
* box i is smaller than box j (ai < aj).
Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.
Help Mishka to determine the minimum possible number of visible boxes!
Input
The first line contains one integer n (1 ≤ n ≤ 5000) — the number of boxes Mishka has got.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the side length of i-th box.
Output
Print the minimum possible number of visible boxes.
Examples
Input
3
1 2 3
Output
1
Input
4
4 2 4 3
Output
2
Note
In the first example it is possible to put box 1 into box 2, and 2 into 3.
In the second example Mishka can put box 2 into box 3, and box 4 into box 1.
Tags: greedy
Correct Solution:
```
n = int(input())
a = input().split()
repeats = []
for i in range(n):
repeats.append(a.count(a[i]))
print(max(repeats))
```
| 88,937 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai.
Mishka can put a box i into another box j if the following conditions are met:
* i-th box is not put into another box;
* j-th box doesn't contain any other boxes;
* box i is smaller than box j (ai < aj).
Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.
Help Mishka to determine the minimum possible number of visible boxes!
Input
The first line contains one integer n (1 ≤ n ≤ 5000) — the number of boxes Mishka has got.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the side length of i-th box.
Output
Print the minimum possible number of visible boxes.
Examples
Input
3
1 2 3
Output
1
Input
4
4 2 4 3
Output
2
Note
In the first example it is possible to put box 1 into box 2, and 2 into 3.
In the second example Mishka can put box 2 into box 3, and box 4 into box 1.
Tags: greedy
Correct Solution:
```
N = int(input())
boxes = list(map(int,input().split()))
high = 0
for item in boxes:
high = max(high, boxes.count(item))
print(high)
```
| 88,938 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai.
Mishka can put a box i into another box j if the following conditions are met:
* i-th box is not put into another box;
* j-th box doesn't contain any other boxes;
* box i is smaller than box j (ai < aj).
Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.
Help Mishka to determine the minimum possible number of visible boxes!
Input
The first line contains one integer n (1 ≤ n ≤ 5000) — the number of boxes Mishka has got.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the side length of i-th box.
Output
Print the minimum possible number of visible boxes.
Examples
Input
3
1 2 3
Output
1
Input
4
4 2 4 3
Output
2
Note
In the first example it is possible to put box 1 into box 2, and 2 into 3.
In the second example Mishka can put box 2 into box 3, and box 4 into box 1.
Tags: greedy
Correct Solution:
```
#Ya Hassan Mojtaba
n=int(input())
my=[n for n in input().split()]
ans=1
for i in my:
ans=max(my.count(i),ans)
print(ans)
```
| 88,939 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai.
Mishka can put a box i into another box j if the following conditions are met:
* i-th box is not put into another box;
* j-th box doesn't contain any other boxes;
* box i is smaller than box j (ai < aj).
Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.
Help Mishka to determine the minimum possible number of visible boxes!
Input
The first line contains one integer n (1 ≤ n ≤ 5000) — the number of boxes Mishka has got.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the side length of i-th box.
Output
Print the minimum possible number of visible boxes.
Examples
Input
3
1 2 3
Output
1
Input
4
4 2 4 3
Output
2
Note
In the first example it is possible to put box 1 into box 2, and 2 into 3.
In the second example Mishka can put box 2 into box 3, and box 4 into box 1.
Tags: greedy
Correct Solution:
```
n = int(input())
s = input()
k = list(map(int, s.split()))
name =[]
count = []
for each in k:
if (each in name) == True:
count[name.index(each)] += 1
else:
name.append(each)
count.append(1)
print(max(count))
```
| 88,940 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai.
Mishka can put a box i into another box j if the following conditions are met:
* i-th box is not put into another box;
* j-th box doesn't contain any other boxes;
* box i is smaller than box j (ai < aj).
Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.
Help Mishka to determine the minimum possible number of visible boxes!
Input
The first line contains one integer n (1 ≤ n ≤ 5000) — the number of boxes Mishka has got.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the side length of i-th box.
Output
Print the minimum possible number of visible boxes.
Examples
Input
3
1 2 3
Output
1
Input
4
4 2 4 3
Output
2
Note
In the first example it is possible to put box 1 into box 2, and 2 into 3.
In the second example Mishka can put box 2 into box 3, and box 4 into box 1.
Tags: greedy
Correct Solution:
```
n= int(input())
lis=list(map(int,input().split()))
lis.sort()
c=1
mx=1
for i in range(n-1):
if lis[i]==lis[i+1]:
c+=1
else:
c=1
if mx<c:
mx=c
print(mx)
```
| 88,941 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai.
Mishka can put a box i into another box j if the following conditions are met:
* i-th box is not put into another box;
* j-th box doesn't contain any other boxes;
* box i is smaller than box j (ai < aj).
Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.
Help Mishka to determine the minimum possible number of visible boxes!
Input
The first line contains one integer n (1 ≤ n ≤ 5000) — the number of boxes Mishka has got.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the side length of i-th box.
Output
Print the minimum possible number of visible boxes.
Examples
Input
3
1 2 3
Output
1
Input
4
4 2 4 3
Output
2
Note
In the first example it is possible to put box 1 into box 2, and 2 into 3.
In the second example Mishka can put box 2 into box 3, and box 4 into box 1.
Tags: greedy
Correct Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 12 19:12:40 2017
@author: ms
"""
def merge(left, right):
a = []
left.append(float("Inf"))
right.append(float("Inf"))
i = 0
j = 0
iters = len(left) + len(right)
for k in range(iters-2):
if left[i] <= right[j]:
a.append(left[i])
i += 1
else:
a.append(right[j])
j += 1
return a
def merge_sort(a):
mid = int(len(a) / 2)
if (mid > 0):
left = a[:mid]
right = a[mid:]
left = merge_sort(left)
right = merge_sort(right)
return merge(left,right)
return a
def main():
n = int(input())
lens = [int(x) for x in input().split()]
#lens = merge_sort(lens)
box = 0
while(len(lens)):
s = list(set(lens))
for i in range(len(s)):
lens.remove(s[i])
box += 1
print(box)
main()
```
| 88,942 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai.
Mishka can put a box i into another box j if the following conditions are met:
* i-th box is not put into another box;
* j-th box doesn't contain any other boxes;
* box i is smaller than box j (ai < aj).
Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.
Help Mishka to determine the minimum possible number of visible boxes!
Input
The first line contains one integer n (1 ≤ n ≤ 5000) — the number of boxes Mishka has got.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the side length of i-th box.
Output
Print the minimum possible number of visible boxes.
Examples
Input
3
1 2 3
Output
1
Input
4
4 2 4 3
Output
2
Note
In the first example it is possible to put box 1 into box 2, and 2 into 3.
In the second example Mishka can put box 2 into box 3, and box 4 into box 1.
Tags: greedy
Correct Solution:
```
from collections import defaultdict
n=int(input())
a=sorted(list(map(int,input().split())))
d=defaultdict(int)
for i in a:
d[i]+=1
print(max(d.values()))
```
| 88,943 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai.
Mishka can put a box i into another box j if the following conditions are met:
* i-th box is not put into another box;
* j-th box doesn't contain any other boxes;
* box i is smaller than box j (ai < aj).
Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.
Help Mishka to determine the minimum possible number of visible boxes!
Input
The first line contains one integer n (1 ≤ n ≤ 5000) — the number of boxes Mishka has got.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the side length of i-th box.
Output
Print the minimum possible number of visible boxes.
Examples
Input
3
1 2 3
Output
1
Input
4
4 2 4 3
Output
2
Note
In the first example it is possible to put box 1 into box 2, and 2 into 3.
In the second example Mishka can put box 2 into box 3, and box 4 into box 1.
Tags: greedy
Correct Solution:
```
input()
a={}
for i in input().split():
i=int(i)
if i in a:
a[i]+=1
else:
a[i]=1
a=sorted(a.items(),key=lambda i:i[0],reverse=True)
b=[i[1] for i in a]
print(max(b))
```
| 88,944 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai.
Mishka can put a box i into another box j if the following conditions are met:
* i-th box is not put into another box;
* j-th box doesn't contain any other boxes;
* box i is smaller than box j (ai < aj).
Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.
Help Mishka to determine the minimum possible number of visible boxes!
Input
The first line contains one integer n (1 ≤ n ≤ 5000) — the number of boxes Mishka has got.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the side length of i-th box.
Output
Print the minimum possible number of visible boxes.
Examples
Input
3
1 2 3
Output
1
Input
4
4 2 4 3
Output
2
Note
In the first example it is possible to put box 1 into box 2, and 2 into 3.
In the second example Mishka can put box 2 into box 3, and box 4 into box 1.
Submitted Solution:
```
n=int(input())
a={}
mx=0
for i in map(int,input().split()):
if i not in a:
a[i]=1
if mx<a[i]:
mx=a[i]
else:
a[i]+=1
if mx<a[i]:
mx=a[i]
print(mx)
```
Yes
| 88,945 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai.
Mishka can put a box i into another box j if the following conditions are met:
* i-th box is not put into another box;
* j-th box doesn't contain any other boxes;
* box i is smaller than box j (ai < aj).
Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.
Help Mishka to determine the minimum possible number of visible boxes!
Input
The first line contains one integer n (1 ≤ n ≤ 5000) — the number of boxes Mishka has got.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the side length of i-th box.
Output
Print the minimum possible number of visible boxes.
Examples
Input
3
1 2 3
Output
1
Input
4
4 2 4 3
Output
2
Note
In the first example it is possible to put box 1 into box 2, and 2 into 3.
In the second example Mishka can put box 2 into box 3, and box 4 into box 1.
Submitted Solution:
```
n = int(input())
skatle = list(map(int, input().strip().split()))
st = dict()
for e in skatle:
if e not in st:
st[e] = 0
st[e] += 1
S = [(s,kol) for s,kol in st.items()]
print(max(k for (s,k) in S))
```
Yes
| 88,946 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai.
Mishka can put a box i into another box j if the following conditions are met:
* i-th box is not put into another box;
* j-th box doesn't contain any other boxes;
* box i is smaller than box j (ai < aj).
Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.
Help Mishka to determine the minimum possible number of visible boxes!
Input
The first line contains one integer n (1 ≤ n ≤ 5000) — the number of boxes Mishka has got.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the side length of i-th box.
Output
Print the minimum possible number of visible boxes.
Examples
Input
3
1 2 3
Output
1
Input
4
4 2 4 3
Output
2
Note
In the first example it is possible to put box 1 into box 2, and 2 into 3.
In the second example Mishka can put box 2 into box 3, and box 4 into box 1.
Submitted Solution:
```
from collections import Counter
nos_of_boxex = int(input())
boxes = [int(x) for x in input().split()]
print(max(Counter(boxes).values()))
```
Yes
| 88,947 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai.
Mishka can put a box i into another box j if the following conditions are met:
* i-th box is not put into another box;
* j-th box doesn't contain any other boxes;
* box i is smaller than box j (ai < aj).
Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.
Help Mishka to determine the minimum possible number of visible boxes!
Input
The first line contains one integer n (1 ≤ n ≤ 5000) — the number of boxes Mishka has got.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the side length of i-th box.
Output
Print the minimum possible number of visible boxes.
Examples
Input
3
1 2 3
Output
1
Input
4
4 2 4 3
Output
2
Note
In the first example it is possible to put box 1 into box 2, and 2 into 3.
In the second example Mishka can put box 2 into box 3, and box 4 into box 1.
Submitted Solution:
```
n = int(input())
a = [int(i) for i in input().split()]
m = 0
b = {}
for i in a:
try:
b[i] += 1
except KeyError:
b[i] = 1
if b[i] > m: m = b[i]
print(m)
```
Yes
| 88,948 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai.
Mishka can put a box i into another box j if the following conditions are met:
* i-th box is not put into another box;
* j-th box doesn't contain any other boxes;
* box i is smaller than box j (ai < aj).
Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.
Help Mishka to determine the minimum possible number of visible boxes!
Input
The first line contains one integer n (1 ≤ n ≤ 5000) — the number of boxes Mishka has got.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the side length of i-th box.
Output
Print the minimum possible number of visible boxes.
Examples
Input
3
1 2 3
Output
1
Input
4
4 2 4 3
Output
2
Note
In the first example it is possible to put box 1 into box 2, and 2 into 3.
In the second example Mishka can put box 2 into box 3, and box 4 into box 1.
Submitted Solution:
```
n=int(input())
a=[*map(int, input().split())]
#a=[int(i) for i in input().split()]
a.sort()
g=0
for i in range(n-1):
if a[i+1]>a[i]:
g+=1
print(n-g)
```
No
| 88,949 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai.
Mishka can put a box i into another box j if the following conditions are met:
* i-th box is not put into another box;
* j-th box doesn't contain any other boxes;
* box i is smaller than box j (ai < aj).
Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.
Help Mishka to determine the minimum possible number of visible boxes!
Input
The first line contains one integer n (1 ≤ n ≤ 5000) — the number of boxes Mishka has got.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the side length of i-th box.
Output
Print the minimum possible number of visible boxes.
Examples
Input
3
1 2 3
Output
1
Input
4
4 2 4 3
Output
2
Note
In the first example it is possible to put box 1 into box 2, and 2 into 3.
In the second example Mishka can put box 2 into box 3, and box 4 into box 1.
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
a.sort()
res = 1
while len(a) > 1:
if a[0] == a[1]:
res += 1
a.pop(0)
print(res)
```
No
| 88,950 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai.
Mishka can put a box i into another box j if the following conditions are met:
* i-th box is not put into another box;
* j-th box doesn't contain any other boxes;
* box i is smaller than box j (ai < aj).
Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.
Help Mishka to determine the minimum possible number of visible boxes!
Input
The first line contains one integer n (1 ≤ n ≤ 5000) — the number of boxes Mishka has got.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the side length of i-th box.
Output
Print the minimum possible number of visible boxes.
Examples
Input
3
1 2 3
Output
1
Input
4
4 2 4 3
Output
2
Note
In the first example it is possible to put box 1 into box 2, and 2 into 3.
In the second example Mishka can put box 2 into box 3, and box 4 into box 1.
Submitted Solution:
```
def solve(array):
temp = list()
track = dict()
for i in array:
if i in track:
track[i]+=1
else:
track[i] = 1
for key,values in sorted(track.items()):
temp.append(values)
ans = 0
extra = 0
for i in range(len(temp)-1):
ans += min(temp[i]+extra,temp[i+1])
if(temp[i]>temp[i+1]):
extra+=(temp[i]-temp[i+1])
return len(array)-ans
if __name__ == "__main__":
t = int(input())
arr = list(map(int,input().split(" ")))
print(solve(arr))
```
No
| 88,951 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai.
Mishka can put a box i into another box j if the following conditions are met:
* i-th box is not put into another box;
* j-th box doesn't contain any other boxes;
* box i is smaller than box j (ai < aj).
Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.
Help Mishka to determine the minimum possible number of visible boxes!
Input
The first line contains one integer n (1 ≤ n ≤ 5000) — the number of boxes Mishka has got.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the side length of i-th box.
Output
Print the minimum possible number of visible boxes.
Examples
Input
3
1 2 3
Output
1
Input
4
4 2 4 3
Output
2
Note
In the first example it is possible to put box 1 into box 2, and 2 into 3.
In the second example Mishka can put box 2 into box 3, and box 4 into box 1.
Submitted Solution:
```
import collections
n = int(input())
nums = list(map(int,input().split()))
d = collections.defaultdict(int)
for i in nums:
d[i] += 1
k = sorted(d.keys())
if len(k)==1:
print(1)
exit()
t = d[k[0]]
s = 0
for i in range(1,len(k)):
in_boxes = min(d[k[i]],t)
t = t + d[k[i]] - in_boxes
s += in_boxes
print(n-s)
```
No
| 88,952 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider a system of n water taps all pouring water into the same container. The i-th water tap can be set to deliver any amount of water from 0 to ai ml per second (this amount may be a real number). The water delivered by i-th tap has temperature ti.
If for every <image> you set i-th tap to deliver exactly xi ml of water per second, then the resulting temperature of water will be <image> (if <image>, then to avoid division by zero we state that the resulting water temperature is 0).
You have to set all the water taps in such a way that the resulting temperature is exactly T. What is the maximum amount of water you may get per second if its temperature has to be T?
Input
The first line contains two integers n and T (1 ≤ n ≤ 200000, 1 ≤ T ≤ 106) — the number of water taps and the desired temperature of water, respectively.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) where ai is the maximum amount of water i-th tap can deliver per second.
The third line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 106) — the temperature of water each tap delivers.
Output
Print the maximum possible amount of water with temperature exactly T you can get per second (if it is impossible to obtain water with such temperature, then the answer is considered to be 0).
Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6.
Examples
Input
2 100
3 10
50 150
Output
6.000000000000000
Input
3 9
5 5 30
6 6 10
Output
40.000000000000000
Input
2 12
1 3
10 15
Output
1.666666666666667
Tags: binary search, greedy, sortings
Correct Solution:
```
n, T = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
tp, tm = [], []
s = 0
for i, x in enumerate(input().split()):
dt = int(x)-T
if dt > 0:
tp.append([dt, a[i]])
elif dt < 0:
tm.append([-dt, a[i]])
else:
s+=a[i]
tp.sort()
tm.sort()
i,j= 0, 0
while i < len(tp) and j < len(tm):
qp = tp[i][0]*tp[i][1]
qm = tm[j][0]*tm[j][1]
if qp>qm:
r = tm[j][0]/tp[i][0]
s += (1+r)*tm[j][1]
tp[i][1] -= tm[j][1]*r
j += 1
else:
r = tp[i][0]/tm[j][0]
s += (1+r)*tp[i][1]
tm[j][1] -= tp[i][1]*r
i += 1
print(s)
```
| 88,953 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider a system of n water taps all pouring water into the same container. The i-th water tap can be set to deliver any amount of water from 0 to ai ml per second (this amount may be a real number). The water delivered by i-th tap has temperature ti.
If for every <image> you set i-th tap to deliver exactly xi ml of water per second, then the resulting temperature of water will be <image> (if <image>, then to avoid division by zero we state that the resulting water temperature is 0).
You have to set all the water taps in such a way that the resulting temperature is exactly T. What is the maximum amount of water you may get per second if its temperature has to be T?
Input
The first line contains two integers n and T (1 ≤ n ≤ 200000, 1 ≤ T ≤ 106) — the number of water taps and the desired temperature of water, respectively.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) where ai is the maximum amount of water i-th tap can deliver per second.
The third line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 106) — the temperature of water each tap delivers.
Output
Print the maximum possible amount of water with temperature exactly T you can get per second (if it is impossible to obtain water with such temperature, then the answer is considered to be 0).
Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6.
Examples
Input
2 100
3 10
50 150
Output
6.000000000000000
Input
3 9
5 5 30
6 6 10
Output
40.000000000000000
Input
2 12
1 3
10 15
Output
1.666666666666667
Tags: binary search, greedy, sortings
Correct Solution:
```
rd = lambda: map(int, input().split())
n, t = rd()
a = list(rd())
b = list(rd())
x = [[b[i], a[i]] for i in range(n)]
x.sort()
tot, val = sum(a), 0
for i in range(n):
val += (t - x[i][0]) * x[i][1]
if val:
f = 2 * (val > 0) - 1
for i in range(n)[::f]:
if f * (val - x[i][1] * (t - x[i][0])) <= 0:
tot -= val / (t - x[i][0])
break
tot -= x[i][1]
val -= (t - x[i][0]) * x[i][1]
print(tot)
```
| 88,954 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider a system of n water taps all pouring water into the same container. The i-th water tap can be set to deliver any amount of water from 0 to ai ml per second (this amount may be a real number). The water delivered by i-th tap has temperature ti.
If for every <image> you set i-th tap to deliver exactly xi ml of water per second, then the resulting temperature of water will be <image> (if <image>, then to avoid division by zero we state that the resulting water temperature is 0).
You have to set all the water taps in such a way that the resulting temperature is exactly T. What is the maximum amount of water you may get per second if its temperature has to be T?
Input
The first line contains two integers n and T (1 ≤ n ≤ 200000, 1 ≤ T ≤ 106) — the number of water taps and the desired temperature of water, respectively.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) where ai is the maximum amount of water i-th tap can deliver per second.
The third line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 106) — the temperature of water each tap delivers.
Output
Print the maximum possible amount of water with temperature exactly T you can get per second (if it is impossible to obtain water with such temperature, then the answer is considered to be 0).
Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6.
Examples
Input
2 100
3 10
50 150
Output
6.000000000000000
Input
3 9
5 5 30
6 6 10
Output
40.000000000000000
Input
2 12
1 3
10 15
Output
1.666666666666667
Tags: binary search, greedy, sortings
Correct Solution:
```
import sys
from operator import lt, gt, le, ge, itemgetter
n, t = map(int, input().split())
a = list(zip(list(map(int, input().split())), list(map(int, input().split()))))
nume = sum(a[i][0]*a[i][1] for i in range(n))
deno = sum(a[i][0] for i in range(n))
if nume / deno > t:
op1, op2, rev = gt, le, False
else:
op1, op2, rev = lt, ge, True
a.sort(key=itemgetter(1), reverse=rev)
while len(a) > 1 and op1((nume - a[-1][0]*a[-1][1]) / (deno - a[-1][0]), t):
nume -= a[-1][0] * a[-1][1]
deno -= a[-1][0]
a.pop()
nume -= a[-1][0] * a[-1][1]
deno -= a[-1][0]
ok, ng = 0.0, float(a[-1][0])
for _ in range(50):
mid = (ok + ng) / 2
if op2((nume + mid * a[-1][1]) / (deno + mid), t):
ok = mid
else:
ng = mid
print(deno + ok)
```
| 88,955 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider a system of n water taps all pouring water into the same container. The i-th water tap can be set to deliver any amount of water from 0 to ai ml per second (this amount may be a real number). The water delivered by i-th tap has temperature ti.
If for every <image> you set i-th tap to deliver exactly xi ml of water per second, then the resulting temperature of water will be <image> (if <image>, then to avoid division by zero we state that the resulting water temperature is 0).
You have to set all the water taps in such a way that the resulting temperature is exactly T. What is the maximum amount of water you may get per second if its temperature has to be T?
Input
The first line contains two integers n and T (1 ≤ n ≤ 200000, 1 ≤ T ≤ 106) — the number of water taps and the desired temperature of water, respectively.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) where ai is the maximum amount of water i-th tap can deliver per second.
The third line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 106) — the temperature of water each tap delivers.
Output
Print the maximum possible amount of water with temperature exactly T you can get per second (if it is impossible to obtain water with such temperature, then the answer is considered to be 0).
Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6.
Examples
Input
2 100
3 10
50 150
Output
6.000000000000000
Input
3 9
5 5 30
6 6 10
Output
40.000000000000000
Input
2 12
1 3
10 15
Output
1.666666666666667
Tags: binary search, greedy, sortings
Correct Solution:
```
def get_max_volume(sources, required_temperature):
"""
:param List[Set[int]]sources:
:param int required_temperature:
:return: float
"""
max_volume = 0.
temp = 0
higher_sources = []
lower_sources = []
for volume, temperature in sources:
delta_temp = temperature - required_temperature
if delta_temp > 0:
higher_sources.append((volume, delta_temp))
elif delta_temp < 0:
lower_sources.append((volume, delta_temp))
max_volume += volume
temp += volume * delta_temp
higher_sources.sort(key=lambda v: v[1])
lower_sources.sort(key=lambda v: -v[1])
while abs(temp / max_volume) >= 1e-6 \
and (len(lower_sources) > 0 or temp >= 0)\
and (len(higher_sources) > 0 or temp <= 0):
if temp < 0:
volume, delta_temp = lower_sources.pop()
if temp - delta_temp * volume >= 0:
required_volume = temp / delta_temp
return max_volume - required_volume
temp -= delta_temp * volume
max_volume -= volume
else:
volume, delta_temp = higher_sources.pop()
if temp - delta_temp * volume <= 0:
required_volume = temp / delta_temp
return max_volume - required_volume
temp -= delta_temp * volume
max_volume -= volume
if abs(temp / max_volume) < 1e-6:
return max_volume
return 0.
n, t = map(int, input().split())
vs = input().split()
ts = input().split()
ss = [(int(vs[i]), int(ts[i])) for i in range(n)]
print(get_max_volume(ss, t))
```
| 88,956 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider a system of n water taps all pouring water into the same container. The i-th water tap can be set to deliver any amount of water from 0 to ai ml per second (this amount may be a real number). The water delivered by i-th tap has temperature ti.
If for every <image> you set i-th tap to deliver exactly xi ml of water per second, then the resulting temperature of water will be <image> (if <image>, then to avoid division by zero we state that the resulting water temperature is 0).
You have to set all the water taps in such a way that the resulting temperature is exactly T. What is the maximum amount of water you may get per second if its temperature has to be T?
Input
The first line contains two integers n and T (1 ≤ n ≤ 200000, 1 ≤ T ≤ 106) — the number of water taps and the desired temperature of water, respectively.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) where ai is the maximum amount of water i-th tap can deliver per second.
The third line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 106) — the temperature of water each tap delivers.
Output
Print the maximum possible amount of water with temperature exactly T you can get per second (if it is impossible to obtain water with such temperature, then the answer is considered to be 0).
Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6.
Examples
Input
2 100
3 10
50 150
Output
6.000000000000000
Input
3 9
5 5 30
6 6 10
Output
40.000000000000000
Input
2 12
1 3
10 15
Output
1.666666666666667
Tags: binary search, greedy, sortings
Correct Solution:
```
n,T=map(int,input().split())
a=list(map(int,input().split()))
x=list(map(int,input().split()))
m=[]
q=0
for i in range(n):
m+=[[x[i],a[i]]]
q+=a[i]*x[i]
asu=sum(a)
try:
if q/asu==T:
print(asu)
elif q/asu>T:
m.sort()
asu-=m[-1][1]
q-=m[-1][0]*m[-1][1]
while q/asu>T:
m.pop()
asu-=m[-1][1]
q-=m[-1][0]*m[-1][1]
print(asu+m[-1][1]*((T*asu-q)/(m[-1][1]*m[-1][0]-T*m[-1][1])))
else:
m.sort(reverse=True)
asu-=m[-1][1]
q-=m[-1][0]*m[-1][1]
while q/asu<T:
m.pop()
asu-=m[-1][1]
q-=m[-1][0]*m[-1][1]
print(asu+m[-1][1]*((T*asu-q)/(m[-1][1]*m[-1][0]-T*m[-1][1])))
except ZeroDivisionError:
print(0)
```
| 88,957 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider a system of n water taps all pouring water into the same container. The i-th water tap can be set to deliver any amount of water from 0 to ai ml per second (this amount may be a real number). The water delivered by i-th tap has temperature ti.
If for every <image> you set i-th tap to deliver exactly xi ml of water per second, then the resulting temperature of water will be <image> (if <image>, then to avoid division by zero we state that the resulting water temperature is 0).
You have to set all the water taps in such a way that the resulting temperature is exactly T. What is the maximum amount of water you may get per second if its temperature has to be T?
Input
The first line contains two integers n and T (1 ≤ n ≤ 200000, 1 ≤ T ≤ 106) — the number of water taps and the desired temperature of water, respectively.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) where ai is the maximum amount of water i-th tap can deliver per second.
The third line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 106) — the temperature of water each tap delivers.
Output
Print the maximum possible amount of water with temperature exactly T you can get per second (if it is impossible to obtain water with such temperature, then the answer is considered to be 0).
Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6.
Examples
Input
2 100
3 10
50 150
Output
6.000000000000000
Input
3 9
5 5 30
6 6 10
Output
40.000000000000000
Input
2 12
1 3
10 15
Output
1.666666666666667
Tags: binary search, greedy, sortings
Correct Solution:
```
n, T = list(map(int, input().split(' ')))
r = list()
r.append(list(map(int, input().split(' '))))
r.append(list(map(int, input().split(' '))))
r.append(list())
for i in range(len(r[0])):
r[2].append((r[0][i], r[1][i]))
r[2].sort(key=lambda x: x[::-1])
for i in range(n):
r[0][i] = r[2][i][0]
r[1][i] = r[2][i][1]
fl = True
tau = sum(r[0]) * T > sum(map(lambda x: x[0] * x[1], r[2]))
if tau:
r[2].reverse()
fl = False
tau1 = not tau
summ = list()
proi = list()
su = 0
pr = 0
for i in range(n):
su += r[2][i][0]
summ.append(su)
pr += r[2][i][0] * r[2][i][1]
proi.append(pr)
lev = 0
pra = n - 1
while lev < n - 1 and ((r[2][lev][1] <= T and fl) or
(r[2][lev][1] >= T and not fl)):
lev += 1
test = lev
while lev != pra:
tau = tau1
tau1 = summ[(lev + pra) // 2 - 1] * T > proi[(lev + pra) // 2 - 1]
if tau == tau1:
lev = (lev + pra) // 2 + 1
else:
pra = (lev + pra) // 2
tau1 = not tau1
tau = summ[-1] * T > proi[-1]
tau1 = summ[max(pra - 1, 0)] * T > proi[max(pra - 1, 0)]
if tau != tau1:
x = ((summ[max(pra - 1, 0)] * T) - proi[max(pra - 1, 0)]) / (
r[2][pra][1] - T)
x = summ[max(pra - 1, 0)] + x
print(x)
else:
tau = tau1
tau1 = summ[max(lev - 2, 0)] * T > proi[max(lev - 2, 0)]
if tau != tau1:
x = ((summ[max(lev - 2, 0)] * T) - proi[max(lev - 2, 0)]) / (
r[2][max(lev - 1, 0)][1] - T)
x = summ[max(lev - 2, 0)] + x
print(x)
else:
x = 0
if test == 0 or test == 1:
if r[2][0][1] == T:
x = r[2][0][0]
else:
if r[2][test][1]!=T:
test -= 1
x = summ[test]
while test>-1 and r[2][test][1]==T:
test -= 1
if test != -1:
x -= summ[test]
print(x)
```
| 88,958 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider a system of n water taps all pouring water into the same container. The i-th water tap can be set to deliver any amount of water from 0 to ai ml per second (this amount may be a real number). The water delivered by i-th tap has temperature ti.
If for every <image> you set i-th tap to deliver exactly xi ml of water per second, then the resulting temperature of water will be <image> (if <image>, then to avoid division by zero we state that the resulting water temperature is 0).
You have to set all the water taps in such a way that the resulting temperature is exactly T. What is the maximum amount of water you may get per second if its temperature has to be T?
Input
The first line contains two integers n and T (1 ≤ n ≤ 200000, 1 ≤ T ≤ 106) — the number of water taps and the desired temperature of water, respectively.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) where ai is the maximum amount of water i-th tap can deliver per second.
The third line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 106) — the temperature of water each tap delivers.
Output
Print the maximum possible amount of water with temperature exactly T you can get per second (if it is impossible to obtain water with such temperature, then the answer is considered to be 0).
Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6.
Examples
Input
2 100
3 10
50 150
Output
6.000000000000000
Input
3 9
5 5 30
6 6 10
Output
40.000000000000000
Input
2 12
1 3
10 15
Output
1.666666666666667
Tags: binary search, greedy, sortings
Correct Solution:
```
#!/usr/bin/env python3
import sys
[n, T] = list(map(int, sys.stdin.readline().strip().split()))
ais = list(map(int, sys.stdin.readline().strip().split()))
tis = list(map(int, sys.stdin.readline().strip().split()))
i_0 = [i for i in range(n) if tis[i] == T]
i_hot = [i for i in range(n) if tis[i] > T]
i_cold = [i for i in range(n) if tis[i] < T]
tis = [abs(ti - T) for ti in tis]
w_hot = sum(ais[i] * tis[i] for i in i_hot)
w_cold = sum(ais[i] * tis[i] for i in i_cold)
if w_hot > w_cold:
w_hot, w_cold = w_cold, w_hot
i_hot, i_cold = i_cold, i_hot
x_max = sum(ais[i] for i in i_0) + sum(ais[i] for i in i_hot)
w = w_hot
i_cold.sort(key=lambda _k: tis[_k])
for i in i_cold:
a, t = ais[i], tis[i]
if a * t <= w:
w -= a * t
x_max += a
else:
x_max = x_max + float(w) / t
w = 0
break
print (float(x_max))
```
| 88,959 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider a system of n water taps all pouring water into the same container. The i-th water tap can be set to deliver any amount of water from 0 to ai ml per second (this amount may be a real number). The water delivered by i-th tap has temperature ti.
If for every <image> you set i-th tap to deliver exactly xi ml of water per second, then the resulting temperature of water will be <image> (if <image>, then to avoid division by zero we state that the resulting water temperature is 0).
You have to set all the water taps in such a way that the resulting temperature is exactly T. What is the maximum amount of water you may get per second if its temperature has to be T?
Input
The first line contains two integers n and T (1 ≤ n ≤ 200000, 1 ≤ T ≤ 106) — the number of water taps and the desired temperature of water, respectively.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) where ai is the maximum amount of water i-th tap can deliver per second.
The third line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 106) — the temperature of water each tap delivers.
Output
Print the maximum possible amount of water with temperature exactly T you can get per second (if it is impossible to obtain water with such temperature, then the answer is considered to be 0).
Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6.
Examples
Input
2 100
3 10
50 150
Output
6.000000000000000
Input
3 9
5 5 30
6 6 10
Output
40.000000000000000
Input
2 12
1 3
10 15
Output
1.666666666666667
Tags: binary search, greedy, sortings
Correct Solution:
```
eps = 1e-9
n, T = map(int, input().split())
a = [*map(int, input().split())]
t = [*map(int, input().split())]
l = sorted(zip(t, a))
S = sum(x * y for x, y in l)
V = sum(a)
while l and (S - V * T) > V * eps and l[-1][0] > T:
x, y = l.pop()
d = min(y, (S - V * T) / (x - T))
S -= x * d
V -= d
l.reverse()
while l and (V * T - S) > V * eps and l[-1][0] < T:
x, y = l.pop()
d = min(y, (V * T - S) / (T - x))
S -= x * d
V -= d
print(round(V, 7) if abs(S - V * T) <= V * eps else 0)
```
| 88,960 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a system of n water taps all pouring water into the same container. The i-th water tap can be set to deliver any amount of water from 0 to ai ml per second (this amount may be a real number). The water delivered by i-th tap has temperature ti.
If for every <image> you set i-th tap to deliver exactly xi ml of water per second, then the resulting temperature of water will be <image> (if <image>, then to avoid division by zero we state that the resulting water temperature is 0).
You have to set all the water taps in such a way that the resulting temperature is exactly T. What is the maximum amount of water you may get per second if its temperature has to be T?
Input
The first line contains two integers n and T (1 ≤ n ≤ 200000, 1 ≤ T ≤ 106) — the number of water taps and the desired temperature of water, respectively.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) where ai is the maximum amount of water i-th tap can deliver per second.
The third line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 106) — the temperature of water each tap delivers.
Output
Print the maximum possible amount of water with temperature exactly T you can get per second (if it is impossible to obtain water with such temperature, then the answer is considered to be 0).
Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6.
Examples
Input
2 100
3 10
50 150
Output
6.000000000000000
Input
3 9
5 5 30
6 6 10
Output
40.000000000000000
Input
2 12
1 3
10 15
Output
1.666666666666667
Submitted Solution:
```
n, T = map(int, input().split())
a = [*map(int, input().split())]
t = [*map(int, input().split())]
l = sorted(zip(t, a))
S = sum(x * y for x, y in l)
V = sum(a)
while l and S > V * T and l[-1][0] > T:
x, y = l.pop()
d = min(y, (S - V * T) / (x - T))
S -= x * d
V -= d
l.reverse()
while l and V * T > S and l[-1][0] < T:
x, y = l.pop()
d = min(y, (V * T - S) / (T - x))
S -= x * d
V -= d
print(round(V, 7) if S == V * T else 0)
```
Yes
| 88,961 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a system of n water taps all pouring water into the same container. The i-th water tap can be set to deliver any amount of water from 0 to ai ml per second (this amount may be a real number). The water delivered by i-th tap has temperature ti.
If for every <image> you set i-th tap to deliver exactly xi ml of water per second, then the resulting temperature of water will be <image> (if <image>, then to avoid division by zero we state that the resulting water temperature is 0).
You have to set all the water taps in such a way that the resulting temperature is exactly T. What is the maximum amount of water you may get per second if its temperature has to be T?
Input
The first line contains two integers n and T (1 ≤ n ≤ 200000, 1 ≤ T ≤ 106) — the number of water taps and the desired temperature of water, respectively.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) where ai is the maximum amount of water i-th tap can deliver per second.
The third line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 106) — the temperature of water each tap delivers.
Output
Print the maximum possible amount of water with temperature exactly T you can get per second (if it is impossible to obtain water with such temperature, then the answer is considered to be 0).
Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6.
Examples
Input
2 100
3 10
50 150
Output
6.000000000000000
Input
3 9
5 5 30
6 6 10
Output
40.000000000000000
Input
2 12
1 3
10 15
Output
1.666666666666667
Submitted Solution:
```
n, T = map(int, input().split())
v = list(map(int, input().split()))
t = list(map(int, input().split()))
plus, minus = [], []
pr, ans = 0, 0
for i in range(n):
if t[i] < T:
minus.append([T - t[i], i])
elif t[i] > T:
plus.append([t[i] - T, i])
else:
ans += v[i]
max1, max2 = 0, 0
for i in range(len(minus)):
max1 += minus[i][0] * v[minus[i][1]]
for i in range(len(plus)):
max2 += plus[i][0] * v[plus[i][1]]
if max1 > max2:
minus.sort()
i = 0
while pr != max2:
if max2 - pr < v[minus[i][1]] * minus[i][0]:
ans += (max2 - pr) / minus[i][0]
pr += max2 - pr
else:
ans += v[minus[i][1]]
pr += v[minus[i][1]] * minus[i][0]
i += 1
for i in range(len(plus)):
ans += v[plus[i][1]]
else:
plus.sort()
i = 0
while pr != max1:
if max1 - pr < v[plus[i][1]] * plus[i][0]:
ans += (max1 - pr) / plus[i][0]
pr += max1 - pr
else:
ans += v[plus[i][1]]
pr += v[plus[i][1]] * plus[i][0]
i += 1
for i in range(len(minus)):
ans += v[minus[i][1]]
print(ans)
```
Yes
| 88,962 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a system of n water taps all pouring water into the same container. The i-th water tap can be set to deliver any amount of water from 0 to ai ml per second (this amount may be a real number). The water delivered by i-th tap has temperature ti.
If for every <image> you set i-th tap to deliver exactly xi ml of water per second, then the resulting temperature of water will be <image> (if <image>, then to avoid division by zero we state that the resulting water temperature is 0).
You have to set all the water taps in such a way that the resulting temperature is exactly T. What is the maximum amount of water you may get per second if its temperature has to be T?
Input
The first line contains two integers n and T (1 ≤ n ≤ 200000, 1 ≤ T ≤ 106) — the number of water taps and the desired temperature of water, respectively.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) where ai is the maximum amount of water i-th tap can deliver per second.
The third line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 106) — the temperature of water each tap delivers.
Output
Print the maximum possible amount of water with temperature exactly T you can get per second (if it is impossible to obtain water with such temperature, then the answer is considered to be 0).
Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6.
Examples
Input
2 100
3 10
50 150
Output
6.000000000000000
Input
3 9
5 5 30
6 6 10
Output
40.000000000000000
Input
2 12
1 3
10 15
Output
1.666666666666667
Submitted Solution:
```
rd = lambda: map(int, input().split())
n, t = rd()
a = list(rd())
b = list(rd())
x = [[b[i], a[i]] for i in range(n)]
x.sort()
tot, val = sum(a), 0
for i in range(n):
val += (t - x[i][0]) * x[i][1]
if val < 0:
for i in range(n - 1, -1, -1):
if val - x[i][1] * (t - x[i][0]) >= 0:
tot -= val / (t - x[i][0])
val = 0
break
tot -= x[i][1]
val -= (t - x[i][0]) * x[i][1]
if val > 0:
for i in range(n):
if val - x[i][1] * (t - x[i][0]) <= 0:
tot -= val / (t - x[i][0])
val = 0
break
tot -= x[i][1]
val -= (t - x[i][0]) * x[i][1]
print('%.12f' % tot)
```
Yes
| 88,963 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a system of n water taps all pouring water into the same container. The i-th water tap can be set to deliver any amount of water from 0 to ai ml per second (this amount may be a real number). The water delivered by i-th tap has temperature ti.
If for every <image> you set i-th tap to deliver exactly xi ml of water per second, then the resulting temperature of water will be <image> (if <image>, then to avoid division by zero we state that the resulting water temperature is 0).
You have to set all the water taps in such a way that the resulting temperature is exactly T. What is the maximum amount of water you may get per second if its temperature has to be T?
Input
The first line contains two integers n and T (1 ≤ n ≤ 200000, 1 ≤ T ≤ 106) — the number of water taps and the desired temperature of water, respectively.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) where ai is the maximum amount of water i-th tap can deliver per second.
The third line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 106) — the temperature of water each tap delivers.
Output
Print the maximum possible amount of water with temperature exactly T you can get per second (if it is impossible to obtain water with such temperature, then the answer is considered to be 0).
Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6.
Examples
Input
2 100
3 10
50 150
Output
6.000000000000000
Input
3 9
5 5 30
6 6 10
Output
40.000000000000000
Input
2 12
1 3
10 15
Output
1.666666666666667
Submitted Solution:
```
def f(t, x):
for i in range(1, len(t) + 1):
ps[i] = ps[i - 1] + t[i - 1][0] * t[i - 1][1]
l = 0
r = len(t) + 1
while l < r:
s = (l + r) // 2
if ps[s] <= x:
l = s + 1
else:
r = s
return l - 1
n , T = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
t = [(int(x) - T, a[i]) for i, x in enumerate(input().split())]
tp = list(sorted(filter(lambda e: e[0] > 0, t)))
tm = list(sorted(map(lambda x : (-x[0], x[1]), (filter(lambda e: e[0] < 0, t)))))
ep = sum(e[0] * e[1] for e in tp)
em = sum(e[0] * e[1] for e in tm)
ps = [0] * (n + 1)
res = sum(map(lambda e : e[1], filter(lambda e: e[0] == 0, t)))
if ep > 0 and em > 0:
if ep < em:
it = f(tm, ep)
res += sum([e[1] for e in tp])
res += sum([e[1] for e in tm[:it]])
if it < len(tm):
res += (ep - ps[it]) / tm[it][0]
else:
it = f(tp, em)
res += sum([e[1] for e in tm])
res += sum([e[1] for e in tp[:it]])
if it < len(tp):
res += (em - ps[it]) / tp[it][0]
print(res)
```
Yes
| 88,964 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a system of n water taps all pouring water into the same container. The i-th water tap can be set to deliver any amount of water from 0 to ai ml per second (this amount may be a real number). The water delivered by i-th tap has temperature ti.
If for every <image> you set i-th tap to deliver exactly xi ml of water per second, then the resulting temperature of water will be <image> (if <image>, then to avoid division by zero we state that the resulting water temperature is 0).
You have to set all the water taps in such a way that the resulting temperature is exactly T. What is the maximum amount of water you may get per second if its temperature has to be T?
Input
The first line contains two integers n and T (1 ≤ n ≤ 200000, 1 ≤ T ≤ 106) — the number of water taps and the desired temperature of water, respectively.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) where ai is the maximum amount of water i-th tap can deliver per second.
The third line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 106) — the temperature of water each tap delivers.
Output
Print the maximum possible amount of water with temperature exactly T you can get per second (if it is impossible to obtain water with such temperature, then the answer is considered to be 0).
Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6.
Examples
Input
2 100
3 10
50 150
Output
6.000000000000000
Input
3 9
5 5 30
6 6 10
Output
40.000000000000000
Input
2 12
1 3
10 15
Output
1.666666666666667
Submitted Solution:
```
rd = lambda: map(int, input().split())
n, t = rd()
a = list(rd())
b = list(rd())
x = [[a[i], b[i]] for i in range(n)]
x.sort()
tot, val = sum(a), 0
for i in range(n):
val += (t - x[i][1]) * x[i][0]
if val < 0:
for i in range(n - 1, -1, -1):
if val - x[i][0] * (t - x[i][1]) >= 0:
tot -= val / (t - x[i][1])
val = 0
break
tot -= x[i][0]
val -= (t - x[i][1]) * x[i][0]
if val > 0:
for i in range(n):
if val - x[i][0] * (t - x[i][1]) <= 0:
tot -= val / (t - x[i][1])
val = 0
break
tot -= x[i][0]
val -= (t - x[i][1]) * x[i][0]
print('%.12f' % tot)
```
No
| 88,965 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a system of n water taps all pouring water into the same container. The i-th water tap can be set to deliver any amount of water from 0 to ai ml per second (this amount may be a real number). The water delivered by i-th tap has temperature ti.
If for every <image> you set i-th tap to deliver exactly xi ml of water per second, then the resulting temperature of water will be <image> (if <image>, then to avoid division by zero we state that the resulting water temperature is 0).
You have to set all the water taps in such a way that the resulting temperature is exactly T. What is the maximum amount of water you may get per second if its temperature has to be T?
Input
The first line contains two integers n and T (1 ≤ n ≤ 200000, 1 ≤ T ≤ 106) — the number of water taps and the desired temperature of water, respectively.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) where ai is the maximum amount of water i-th tap can deliver per second.
The third line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 106) — the temperature of water each tap delivers.
Output
Print the maximum possible amount of water with temperature exactly T you can get per second (if it is impossible to obtain water with such temperature, then the answer is considered to be 0).
Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6.
Examples
Input
2 100
3 10
50 150
Output
6.000000000000000
Input
3 9
5 5 30
6 6 10
Output
40.000000000000000
Input
2 12
1 3
10 15
Output
1.666666666666667
Submitted Solution:
```
n, T = list(map(int, input().split(' ')))
r = list()
r.append(list(map(int, input().split(' '))))
r.append(list(map(int, input().split(' '))))
r.append(list())
for i in range(len(r[0])):
r[2].append((r[0][i], r[1][i]))
r[2].sort(key=lambda x: x[::-1])
for i in range(n):
r[0][i] = r[2][i][0]
r[1][i] = r[2][i][1]
fl = True
tau = sum(r[0]) * T > sum(map(lambda x: x[0] * x[1], r[2]))
if tau:
r[2].reverse()
fl = False
tau1 = not tau
summ = list()
proi = list()
su = 0
pr = 0
for i in range(n):
su += r[2][i][0]
summ.append(su)
pr += r[2][i][0] * r[2][i][1]
proi.append(pr)
lev = 0
pra = n - 1
while lev < n - 1 and ((r[2][lev][1] <= T and fl) or
(r[2][lev][1] >= T and not fl)):
lev += 1
test = lev
while lev != pra:
tau = tau1
tau1 = summ[(lev + pra) // 2 - 1] * T > proi[(lev + pra) // 2 - 1]
if tau == tau1:
lev = (lev + pra) // 2 + 1
else:
pra = (lev + pra) // 2
tau1 = not tau1
tau = summ[-1] * T > proi[-1]
tau1 = summ[max(pra - 1, 0)] * T > proi[max(pra - 1, 0)]
if tau != tau1:
x = ((summ[max(pra - 1, 0)] * T) - proi[max(pra - 1, 0)]) / (
r[2][pra][1] - T)
x = summ[max(pra - 1, 0)] + x
print(x)
else:
tau = tau1
tau1 = summ[max(lev - 2, 0)] * T > proi[max(lev - 2, 0)]
if tau != tau1:
x = ((summ[max(lev - 2, 0)] * T) - proi[max(lev - 2, 0)]) / (
r[2][max(lev - 1, 0)][1] - T)
x = summ[max(lev - 2, 0)] + x
print(x)
else:
x = 0
if test == 0 or test == 1:
if r[2][0][1] == T:
x = r[2][0][0]
else:
test -= 1
x = summ[test]
while r[2][test][1]==T:
test -= 1
x -= summ[test]
print(x)
```
No
| 88,966 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a system of n water taps all pouring water into the same container. The i-th water tap can be set to deliver any amount of water from 0 to ai ml per second (this amount may be a real number). The water delivered by i-th tap has temperature ti.
If for every <image> you set i-th tap to deliver exactly xi ml of water per second, then the resulting temperature of water will be <image> (if <image>, then to avoid division by zero we state that the resulting water temperature is 0).
You have to set all the water taps in such a way that the resulting temperature is exactly T. What is the maximum amount of water you may get per second if its temperature has to be T?
Input
The first line contains two integers n and T (1 ≤ n ≤ 200000, 1 ≤ T ≤ 106) — the number of water taps and the desired temperature of water, respectively.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) where ai is the maximum amount of water i-th tap can deliver per second.
The third line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 106) — the temperature of water each tap delivers.
Output
Print the maximum possible amount of water with temperature exactly T you can get per second (if it is impossible to obtain water with such temperature, then the answer is considered to be 0).
Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6.
Examples
Input
2 100
3 10
50 150
Output
6.000000000000000
Input
3 9
5 5 30
6 6 10
Output
40.000000000000000
Input
2 12
1 3
10 15
Output
1.666666666666667
Submitted Solution:
```
n,T = map(int,input().split())
ans = 0
temp = 0
a = input().split()
t = input().split()
b = []
for i in range(n):
a[i] = int(a[i])
t[i] = int(t[i])
b.append([t[i],a[i]])
temp+=t[i]*a[i]
ans+=a[i]
temp/=ans
b.sort()
b.reverse()
if (b[0][0]<T or b[n-1][0]>T):
print(0)
elif (temp>T):
for i in range(n):
s = ans-b[i][1]
if (s!=0 and (temp-b[i][0]*b[i][1])*ans/s>T):
ans = s
temp = (temp-b[i][0]*b[i][1])*ans/s
else:
x = (temp*ans-T*ans)/(b[i][0]-T)
ans-=x
print(ans)
break
elif (temp==T):
print(ans)
else:
b.reverse()
for i in range(n):
s = ans-b[i][1]
if (s!=0 and (temp-b[i][0]*b[i][1])*ans/s<T):
ans = s
temp = (temp-b[i][0]*b[i][1])*ans/s
else:
x = (temp*ans-T*ans)/(b[i][0]-T)
ans-=x
print(ans)
break
```
No
| 88,967 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a system of n water taps all pouring water into the same container. The i-th water tap can be set to deliver any amount of water from 0 to ai ml per second (this amount may be a real number). The water delivered by i-th tap has temperature ti.
If for every <image> you set i-th tap to deliver exactly xi ml of water per second, then the resulting temperature of water will be <image> (if <image>, then to avoid division by zero we state that the resulting water temperature is 0).
You have to set all the water taps in such a way that the resulting temperature is exactly T. What is the maximum amount of water you may get per second if its temperature has to be T?
Input
The first line contains two integers n and T (1 ≤ n ≤ 200000, 1 ≤ T ≤ 106) — the number of water taps and the desired temperature of water, respectively.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) where ai is the maximum amount of water i-th tap can deliver per second.
The third line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 106) — the temperature of water each tap delivers.
Output
Print the maximum possible amount of water with temperature exactly T you can get per second (if it is impossible to obtain water with such temperature, then the answer is considered to be 0).
Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6.
Examples
Input
2 100
3 10
50 150
Output
6.000000000000000
Input
3 9
5 5 30
6 6 10
Output
40.000000000000000
Input
2 12
1 3
10 15
Output
1.666666666666667
Submitted Solution:
```
n,T = list(map(int,input().split(' ')))
r = list()
r.append(list(map(int,input().split(' '))))
r.append(list(map(int,input().split(' '))))
r.append(list())
for i in range(len(r[0])):
r[2].append((r[0][i],r[1][i]))
r[2].sort(key=lambda x: x[::-1])
for i in range(n):
r[0][i] = r[2][i][0]
r[1][i] = r[2][i][1]
fl = True
tau = sum(r[0])*T > sum(map(lambda x:x[0]*x[1],r[2]))
if tau:
r[2].reverse()
fl = False
tau1 = not tau
lev = 0
pra = n-1
while r[2][lev][1] <= T:
lev += 1
while lev != pra and lev+1 != pra:
tau = tau1
tau1 = sum(r[0][:(lev+pra)//2])*T > sum(map(lambda x:x[0]*x[1],r[2][:(lev+pra)//2 ]))
if tau == tau1:
lev = (lev+pra)//2 + 1
else:
pra = (lev+pra)//2
tau1 = not tau1
print(lev,pra)
tau = sum(r[0])*T > sum(map(lambda x:x[0]*x[1],r[2]))
tau1 = sum(r[0][:pra])*T > sum(map(lambda x:x[0]*x[1],r[2][:pra]))
if tau != tau1:
x = ((sum(r[0][:pra])*T)-(sum(map(lambda x:x[0]*x[1],r[2][:pra]))))/(r[1][pra]-T)
x = sum(r[0][:pra])+x
print(x)
else:
tau = tau1
tau1 = sum(r[0][:lev])*T > sum(map(lambda x:x[0]*x[1],r[2][:lev]))
if tau!=tau1:
x = ((sum(r[0][:lev])*T)-(sum(map(lambda x:x[0]*x[1],r[2][:lev]))))/(r[1][lev]-T)
x = sum(r[0][:lev])+x
print(x)
else:
print(0)
```
No
| 88,968 |
Provide tags and a correct Python 3 solution for this coding contest problem.
SaMer has written the greatest test case of all time for one of his problems. For a given array of integers, the problem asks to find the minimum number of groups the array can be divided into, such that the product of any pair of integers in the same group is a perfect square.
Each integer must be in exactly one group. However, integers in a group do not necessarily have to be contiguous in the array.
SaMer wishes to create more cases from the test case he already has. His test case has an array A of n integers, and he needs to find the number of contiguous subarrays of A that have an answer to the problem equal to k for each integer k between 1 and n (inclusive).
Input
The first line of input contains a single integer n (1 ≤ n ≤ 5000), the size of the array.
The second line contains n integers a_1,a_2,...,a_n (-10^8 ≤ a_i ≤ 10^8), the values of the array.
Output
Output n space-separated integers, the k-th integer should be the number of contiguous subarrays of A that have an answer to the problem equal to k.
Examples
Input
2
5 5
Output
3 0
Input
5
5 -4 2 1 8
Output
5 5 3 2 0
Input
1
0
Output
1
Tags: dp, math, number theory
Correct Solution:
```
from math import sqrt
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97,
101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193,
197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307,
311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421,
431, 433, 439, 443, 449, 457, 461, 463]
def sqfree(x):
if x == 0:
return x
y = 1
for p in primes:
pp=p*p
while x % pp == 0:
x //= pp
if x % p == 0:
x //= p
y *= p
if abs(x) < p:
break
if int(sqrt(abs(x)))**2 == abs(x):
return (y if x > 0 else -y)
else:
return x * y
n = int(input().strip())
ais = list(map(int, input().strip().split()))
bis = list(map(sqfree, ais))
prev = [-1 for i in range(n)]
last = {}
for i, b in enumerate(bis):
if b in last:
prev[i] = last[b]
last[b] = i
res = [0 for i in range(n)]
for l in range(n):
cnt = 0
for r in range(l, n):
if bis[r] != 0 and prev[r] < l:
cnt += 1
res[max(cnt - 1, 0)] += 1
print (' '.join(map(str, res)))
```
| 88,969 |
Provide tags and a correct Python 3 solution for this coding contest problem.
SaMer has written the greatest test case of all time for one of his problems. For a given array of integers, the problem asks to find the minimum number of groups the array can be divided into, such that the product of any pair of integers in the same group is a perfect square.
Each integer must be in exactly one group. However, integers in a group do not necessarily have to be contiguous in the array.
SaMer wishes to create more cases from the test case he already has. His test case has an array A of n integers, and he needs to find the number of contiguous subarrays of A that have an answer to the problem equal to k for each integer k between 1 and n (inclusive).
Input
The first line of input contains a single integer n (1 ≤ n ≤ 5000), the size of the array.
The second line contains n integers a_1,a_2,...,a_n (-10^8 ≤ a_i ≤ 10^8), the values of the array.
Output
Output n space-separated integers, the k-th integer should be the number of contiguous subarrays of A that have an answer to the problem equal to k.
Examples
Input
2
5 5
Output
3 0
Input
5
5 -4 2 1 8
Output
5 5 3 2 0
Input
1
0
Output
1
Tags: dp, math, number theory
Correct Solution:
```
#!/usr/bin/env python3
from math import sqrt
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97,
101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193,
197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307,
311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421,
431, 433, 439, 443, 449, 457, 461, 463]
psq = [p*p for p in primes]
def sqfree(x):
if x == 0:
return x
y = 1
for p, pp in zip(primes, psq):
while x % pp == 0:
x //= pp
if x % p == 0:
x //= p
y *= p
if abs(x) < p:
break
if int(sqrt(abs(x)))**2 == abs(x):
return (y if x > 0 else -y)
else:
return x * y
n = int(input().strip())
ais = list(map(int, input().strip().split()))
bis = list(map(sqfree, ais))
prev = [-1 for i in range(n)]
last = {}
for i, b in enumerate(bis):
if b in last:
prev[i] = last[b]
last[b] = i
res = [0 for i in range(n)]
for l in range(n):
cnt = 0
for r in range(l, n):
if bis[r] != 0 and prev[r] < l:
cnt += 1
res[max(cnt - 1, 0)] += 1
print (' '.join(map(str, res)))
```
| 88,970 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
SaMer has written the greatest test case of all time for one of his problems. For a given array of integers, the problem asks to find the minimum number of groups the array can be divided into, such that the product of any pair of integers in the same group is a perfect square.
Each integer must be in exactly one group. However, integers in a group do not necessarily have to be contiguous in the array.
SaMer wishes to create more cases from the test case he already has. His test case has an array A of n integers, and he needs to find the number of contiguous subarrays of A that have an answer to the problem equal to k for each integer k between 1 and n (inclusive).
Input
The first line of input contains a single integer n (1 ≤ n ≤ 5000), the size of the array.
The second line contains n integers a_1,a_2,...,a_n (-10^8 ≤ a_i ≤ 10^8), the values of the array.
Output
Output n space-separated integers, the k-th integer should be the number of contiguous subarrays of A that have an answer to the problem equal to k.
Examples
Input
2
5 5
Output
3 0
Input
5
5 -4 2 1 8
Output
5 5 3 2 0
Input
1
0
Output
1
Submitted Solution:
```
def reduce(n):
i = 2
isqr = i * i
while i * i <= n:
if n % i == 0:
print(n, i)
isqr = i * i
while n % (isqr) == 0:
n //= isqr
i += 1
return n
# def test_reduce():
# a = [2 * 3 **7 * 5**3 * 9**5]
# print(a)
# print([reduce(x) for x in a])
def solve(n, a):
a = [reduce(x) for x in a]
pair = {0 : 0}
mp = [0] * len(a)
for i, x in enumerate(a):
if x not in pair:
pair[x] = len(pair)
mp[i] = pair[x]
# print(a)
# print(mp)
# print()
cntuniq = [0] * n
for l in range(1, n + 1):
cnt = [0] * len(mp)
for i in range(l):
cnt[mp[i]] += 1
uniq = sum([c > 0 for c in cnt])
if 0 < cnt[0] and 1 < uniq:
cntuniq[uniq - 2] += 1
print(cnt, uniq - 1)
else:
cntuniq[uniq - 1] += 1
print(cnt, uniq)
for i in range(l, n):
if cnt[mp[i]] == 0:
uniq += 1
cnt[mp[i]] += 1
cnt[mp[i - l]] -= 1
if cnt[mp[i - l]] == 0:
uniq -= 1
if 0 < cnt[0] and 1 < uniq:
cntuniq[uniq - 2] += 1
print(cnt, uniq - 1)
else:
cntuniq[uniq - 1] += 1
print(cnt, uniq)
print()
return cntuniq
def main():
n = int(input())
a = [int(_) for _ in input().split()]
ak = solve(n, a)
print(' '.join(map(str, ak)))
if __name__ == '__main__':
# test_reduce()
main()
```
No
| 88,971 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
SaMer has written the greatest test case of all time for one of his problems. For a given array of integers, the problem asks to find the minimum number of groups the array can be divided into, such that the product of any pair of integers in the same group is a perfect square.
Each integer must be in exactly one group. However, integers in a group do not necessarily have to be contiguous in the array.
SaMer wishes to create more cases from the test case he already has. His test case has an array A of n integers, and he needs to find the number of contiguous subarrays of A that have an answer to the problem equal to k for each integer k between 1 and n (inclusive).
Input
The first line of input contains a single integer n (1 ≤ n ≤ 5000), the size of the array.
The second line contains n integers a_1,a_2,...,a_n (-10^8 ≤ a_i ≤ 10^8), the values of the array.
Output
Output n space-separated integers, the k-th integer should be the number of contiguous subarrays of A that have an answer to the problem equal to k.
Examples
Input
2
5 5
Output
3 0
Input
5
5 -4 2 1 8
Output
5 5 3 2 0
Input
1
0
Output
1
Submitted Solution:
```
import sys
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))
n,=I()
l=I()
an=[0]*n
an[0]=n
for i in range(n):
k=abs(l[i]);x=1
for j in range(2,int(k**0.5)+1):
c=0
while k%j==0:
c+=1;k//=j
if c%2:
x*=j
x*=k
if l[i]<0:
x=-x
l[i]=x
for i in range(2,n+1):
for j in range(n-i+1):
p=set(l[j:j+i])
if 0 in p:
if len(p)>1:
an[len(p)-2]+=1
else:
an[len(p)-1]+=1
print(*an)
```
No
| 88,972 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
SaMer has written the greatest test case of all time for one of his problems. For a given array of integers, the problem asks to find the minimum number of groups the array can be divided into, such that the product of any pair of integers in the same group is a perfect square.
Each integer must be in exactly one group. However, integers in a group do not necessarily have to be contiguous in the array.
SaMer wishes to create more cases from the test case he already has. His test case has an array A of n integers, and he needs to find the number of contiguous subarrays of A that have an answer to the problem equal to k for each integer k between 1 and n (inclusive).
Input
The first line of input contains a single integer n (1 ≤ n ≤ 5000), the size of the array.
The second line contains n integers a_1,a_2,...,a_n (-10^8 ≤ a_i ≤ 10^8), the values of the array.
Output
Output n space-separated integers, the k-th integer should be the number of contiguous subarrays of A that have an answer to the problem equal to k.
Examples
Input
2
5 5
Output
3 0
Input
5
5 -4 2 1 8
Output
5 5 3 2 0
Input
1
0
Output
1
Submitted Solution:
```
#!/usr/bin/env python3
from math import sqrt
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
psq = [p**p for p in primes]
def sqfree(x):
if x == 0:
return x
for p in psq:
while x % p == 0:
x //= p
if abs(x) < p:
break
return x
n = int(input().strip())
ais = list(map(int, input().strip().split()))
nz = ais.count(0)
bis = list(filter(lambda v: v != 0, map(sqfree, ais)))
res = [0 for _ in range(n)]
res[0] += nz
prev = [-1 for i in range(n - nz)]
last = {}
for i, b in enumerate(bis):
if b in last:
prev[i] = last[b]
last[b] = i
for l in range(n - nz):
cnt = 0
for r in range(l, n - nz):
if prev[r] < l:
cnt += 1
res[cnt - 1] += 1
print (' '.join(map(str, res)))
```
No
| 88,973 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
SaMer has written the greatest test case of all time for one of his problems. For a given array of integers, the problem asks to find the minimum number of groups the array can be divided into, such that the product of any pair of integers in the same group is a perfect square.
Each integer must be in exactly one group. However, integers in a group do not necessarily have to be contiguous in the array.
SaMer wishes to create more cases from the test case he already has. His test case has an array A of n integers, and he needs to find the number of contiguous subarrays of A that have an answer to the problem equal to k for each integer k between 1 and n (inclusive).
Input
The first line of input contains a single integer n (1 ≤ n ≤ 5000), the size of the array.
The second line contains n integers a_1,a_2,...,a_n (-10^8 ≤ a_i ≤ 10^8), the values of the array.
Output
Output n space-separated integers, the k-th integer should be the number of contiguous subarrays of A that have an answer to the problem equal to k.
Examples
Input
2
5 5
Output
3 0
Input
5
5 -4 2 1 8
Output
5 5 3 2 0
Input
1
0
Output
1
Submitted Solution:
```
#!/usr/bin/env python3
from math import sqrt
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97,
101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193,
197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307,
311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421,
431, 433, 439, 443, 449, 457, 461, 463]
psq = [p**p for p in primes]
def sqfree(x):
if x == 0:
return x
y = 1
for p, pp in zip(primes, psq):
while x % pp == 0:
x //= pp
if x % p == 0:
x //= p
y *= p
if abs(x) < pp:
break
if int(sqrt(abs(x)))**2 == abs(x):
return (y if x > 0 else -y)
else:
return x * y
n = int(input().strip())
ais = list(map(int, input().strip().split()))
bis = list(map(sqfree, ais))
prev = [-1 for i in range(n)]
last = {}
for i, b in enumerate(bis):
if b in last:
prev[i] = last[b]
last[b] = i
res = [0 for i in range(n)]
for l in range(n):
cnt = 0
for r in range(l, n):
if bis[r] != 0 and prev[r] < l:
cnt += 1
res[max(cnt - 1, 0)] += 1
print (' '.join(map(str, res)))
```
No
| 88,974 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong — the oldest among the inhabitants of Mainframe. But still he managed to get some information from there. For example, he managed to learn that User launches games for pleasure — and then terrible Game Cubes fall down on the city, bringing death to those modules, who cannot win the game...
For sure, as guard Bob appeared in Mainframe many modules stopped fearing Game Cubes. Because Bob (as he is alive yet) has never been defeated by User, and he always meddles with Game Cubes, because he is programmed to this.
However, unpleasant situations can happen, when a Game Cube falls down on Lost Angles. Because there lives a nasty virus — Hexadecimal, who is... mmm... very strange. And she likes to play very much. So, willy-nilly, Bob has to play with her first, and then with User.
This time Hexadecimal invented the following entertainment: Bob has to leap over binary search trees with n nodes. We should remind you that a binary search tree is a binary tree, each node has a distinct key, for each node the following is true: the left sub-tree of a node contains only nodes with keys less than the node's key, the right sub-tree of a node contains only nodes with keys greater than the node's key. All the keys are different positive integer numbers from 1 to n. Each node of such a tree can have up to two children, or have no children at all (in the case when a node is a leaf).
In Hexadecimal's game all the trees are different, but the height of each is not lower than h. In this problem «height» stands for the maximum amount of nodes on the way from the root to the remotest leaf, the root node and the leaf itself included. When Bob leaps over a tree, it disappears. Bob gets the access to a Cube, when there are no trees left. He knows how many trees he will have to leap over in the worst case. And you?
Input
The input data contains two space-separated positive integer numbers n and h (n ≤ 35, h ≤ n).
Output
Output one number — the answer to the problem. It is guaranteed that it does not exceed 9·1018.
Examples
Input
3 2
Output
5
Input
3 3
Output
4
Tags: combinatorics, divide and conquer, dp
Correct Solution:
```
def t(n, h):
if dp[n][h] == -1:
dp[n][h] = sum(
t(m - 1, h - 1) * sum(t(n - m, i) for i in range(h)) +
t(n - m, h - 1) * sum(t(m - 1, i) for i in range(h - 1))
for m in range(1, n + 1)
)
return dp[n][h]
n, h = map(int, input().split())
def fill(i, j):
if i == 0 and j == 0:
return 1
if i == 0 or j == 0:
return 0
return -1
dp = [[fill(i, j) for j in range(n + 1)] for i in range(n + 1)]
for i in range(n + 1):
for j in range(n + 1):
t(i, j)
print(sum(dp[n][i] for i in range(h, n + 1)))
```
| 88,975 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong — the oldest among the inhabitants of Mainframe. But still he managed to get some information from there. For example, he managed to learn that User launches games for pleasure — and then terrible Game Cubes fall down on the city, bringing death to those modules, who cannot win the game...
For sure, as guard Bob appeared in Mainframe many modules stopped fearing Game Cubes. Because Bob (as he is alive yet) has never been defeated by User, and he always meddles with Game Cubes, because he is programmed to this.
However, unpleasant situations can happen, when a Game Cube falls down on Lost Angles. Because there lives a nasty virus — Hexadecimal, who is... mmm... very strange. And she likes to play very much. So, willy-nilly, Bob has to play with her first, and then with User.
This time Hexadecimal invented the following entertainment: Bob has to leap over binary search trees with n nodes. We should remind you that a binary search tree is a binary tree, each node has a distinct key, for each node the following is true: the left sub-tree of a node contains only nodes with keys less than the node's key, the right sub-tree of a node contains only nodes with keys greater than the node's key. All the keys are different positive integer numbers from 1 to n. Each node of such a tree can have up to two children, or have no children at all (in the case when a node is a leaf).
In Hexadecimal's game all the trees are different, but the height of each is not lower than h. In this problem «height» stands for the maximum amount of nodes on the way from the root to the remotest leaf, the root node and the leaf itself included. When Bob leaps over a tree, it disappears. Bob gets the access to a Cube, when there are no trees left. He knows how many trees he will have to leap over in the worst case. And you?
Input
The input data contains two space-separated positive integer numbers n and h (n ≤ 35, h ≤ n).
Output
Output one number — the answer to the problem. It is guaranteed that it does not exceed 9·1018.
Examples
Input
3 2
Output
5
Input
3 3
Output
4
Tags: combinatorics, divide and conquer, dp
Correct Solution:
```
n, h = list(map(int, input().split(" ")))
dp = [[0 for j in range(h + 1)] for i in range(n + 1)]
dp[0][0] = 1
for i in range(1, n + 1):
dp[i][0] = dp[i - 1][0] * 2 * (2 * i - 1) // (i + 1)
for i in range(1, n + 1):
for j in range(1, h + 1):
for k in range(1, i + 1):
dp[i][j] += dp[k - 1][0] * dp[i - k][j - 1] + dp[k - 1][j - 1] * dp[i - k][0] - dp[i - k][j - 1] * dp[k - 1][j - 1]
print(dp[n][h])
```
| 88,976 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong — the oldest among the inhabitants of Mainframe. But still he managed to get some information from there. For example, he managed to learn that User launches games for pleasure — and then terrible Game Cubes fall down on the city, bringing death to those modules, who cannot win the game...
For sure, as guard Bob appeared in Mainframe many modules stopped fearing Game Cubes. Because Bob (as he is alive yet) has never been defeated by User, and he always meddles with Game Cubes, because he is programmed to this.
However, unpleasant situations can happen, when a Game Cube falls down on Lost Angles. Because there lives a nasty virus — Hexadecimal, who is... mmm... very strange. And she likes to play very much. So, willy-nilly, Bob has to play with her first, and then with User.
This time Hexadecimal invented the following entertainment: Bob has to leap over binary search trees with n nodes. We should remind you that a binary search tree is a binary tree, each node has a distinct key, for each node the following is true: the left sub-tree of a node contains only nodes with keys less than the node's key, the right sub-tree of a node contains only nodes with keys greater than the node's key. All the keys are different positive integer numbers from 1 to n. Each node of such a tree can have up to two children, or have no children at all (in the case when a node is a leaf).
In Hexadecimal's game all the trees are different, but the height of each is not lower than h. In this problem «height» stands for the maximum amount of nodes on the way from the root to the remotest leaf, the root node and the leaf itself included. When Bob leaps over a tree, it disappears. Bob gets the access to a Cube, when there are no trees left. He knows how many trees he will have to leap over in the worst case. And you?
Input
The input data contains two space-separated positive integer numbers n and h (n ≤ 35, h ≤ n).
Output
Output one number — the answer to the problem. It is guaranteed that it does not exceed 9·1018.
Examples
Input
3 2
Output
5
Input
3 3
Output
4
Tags: combinatorics, divide and conquer, dp
Correct Solution:
```
MAX = 71
C=[[0]*MAX for i in range(MAX)]
dp=[[0]*MAX for i in range(MAX)]
C[0][0]=1
for i in range(1, MAX):
C[i][0]=1
for i in range(1, MAX):
for j in range(1, i+1):
C[i][j]=C[i-1][j]+C[i-1][j-1]
def catalan(n):
return C[2*n][n]//(n+1)
def solve(n, h):
if(n==0): return 0
if(n<h): return 0
if(h<=1): return catalan(n)
if(dp[n][h]): return dp[n][h];
ans=0
for k in range(0, n):
if(dp[n-k-1][h-1]==0):
dp[n-k-1][h-1]=solve(n-k-1, h-1)
if(dp[k][h-1]==0):
dp[k][h-1]=solve(k, h-1)
ans+=dp[n-k-1][h-1]*( catalan(k)-dp[k][h-1]) + catalan(n-k-1)*dp[k][h-1]
dp[n][h]=ans
return ans
n, h=map(int, input().split())
ans=solve(n, h)
print(ans)
```
| 88,977 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong — the oldest among the inhabitants of Mainframe. But still he managed to get some information from there. For example, he managed to learn that User launches games for pleasure — and then terrible Game Cubes fall down on the city, bringing death to those modules, who cannot win the game...
For sure, as guard Bob appeared in Mainframe many modules stopped fearing Game Cubes. Because Bob (as he is alive yet) has never been defeated by User, and he always meddles with Game Cubes, because he is programmed to this.
However, unpleasant situations can happen, when a Game Cube falls down on Lost Angles. Because there lives a nasty virus — Hexadecimal, who is... mmm... very strange. And she likes to play very much. So, willy-nilly, Bob has to play with her first, and then with User.
This time Hexadecimal invented the following entertainment: Bob has to leap over binary search trees with n nodes. We should remind you that a binary search tree is a binary tree, each node has a distinct key, for each node the following is true: the left sub-tree of a node contains only nodes with keys less than the node's key, the right sub-tree of a node contains only nodes with keys greater than the node's key. All the keys are different positive integer numbers from 1 to n. Each node of such a tree can have up to two children, or have no children at all (in the case when a node is a leaf).
In Hexadecimal's game all the trees are different, but the height of each is not lower than h. In this problem «height» stands for the maximum amount of nodes on the way from the root to the remotest leaf, the root node and the leaf itself included. When Bob leaps over a tree, it disappears. Bob gets the access to a Cube, when there are no trees left. He knows how many trees he will have to leap over in the worst case. And you?
Input
The input data contains two space-separated positive integer numbers n and h (n ≤ 35, h ≤ n).
Output
Output one number — the answer to the problem. It is guaranteed that it does not exceed 9·1018.
Examples
Input
3 2
Output
5
Input
3 3
Output
4
Tags: combinatorics, divide and conquer, dp
Correct Solution:
```
n, h = map(int,input().split())
dp = [[0 for j in range(n + 1)] for i in range(n + 1)]
dp[0] = [1 for j in range(n + 1)]
for i in range(n + 1):
for j in range(1, n + 1):
for k in range(i):
dp[i][j] += dp[k][j - 1] * dp[i - 1 - k][j - 1]
print(dp[n][n] - (h > 0 and [dp[n][h - 1]] or [0])[0])
```
| 88,978 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong — the oldest among the inhabitants of Mainframe. But still he managed to get some information from there. For example, he managed to learn that User launches games for pleasure — and then terrible Game Cubes fall down on the city, bringing death to those modules, who cannot win the game...
For sure, as guard Bob appeared in Mainframe many modules stopped fearing Game Cubes. Because Bob (as he is alive yet) has never been defeated by User, and he always meddles with Game Cubes, because he is programmed to this.
However, unpleasant situations can happen, when a Game Cube falls down on Lost Angles. Because there lives a nasty virus — Hexadecimal, who is... mmm... very strange. And she likes to play very much. So, willy-nilly, Bob has to play with her first, and then with User.
This time Hexadecimal invented the following entertainment: Bob has to leap over binary search trees with n nodes. We should remind you that a binary search tree is a binary tree, each node has a distinct key, for each node the following is true: the left sub-tree of a node contains only nodes with keys less than the node's key, the right sub-tree of a node contains only nodes with keys greater than the node's key. All the keys are different positive integer numbers from 1 to n. Each node of such a tree can have up to two children, or have no children at all (in the case when a node is a leaf).
In Hexadecimal's game all the trees are different, but the height of each is not lower than h. In this problem «height» stands for the maximum amount of nodes on the way from the root to the remotest leaf, the root node and the leaf itself included. When Bob leaps over a tree, it disappears. Bob gets the access to a Cube, when there are no trees left. He knows how many trees he will have to leap over in the worst case. And you?
Input
The input data contains two space-separated positive integer numbers n and h (n ≤ 35, h ≤ n).
Output
Output one number — the answer to the problem. It is guaranteed that it does not exceed 9·1018.
Examples
Input
3 2
Output
5
Input
3 3
Output
4
Tags: combinatorics, divide and conquer, dp
Correct Solution:
```
n, h = map(int, input().split())
ceq = [[0] * (n + 1) for i in range(n + 1)]
cle = [[0] * (n + 1) for i in range(n + 1)]
ceq[0][0] = 1
cle[0] = [1] * (n + 1)
for i in range(1, n + 1):
for j in range(n):
for left in range(i):
ceq[i][j + 1] += ceq[left][j] * cle[i - left - 1][j] + cle[left][j] * ceq[i - left - 1][j] - ceq[left][j] * ceq[i - left - 1][j]
cle[i][j + 1] = cle[i][j] + ceq[i][j + 1]
print(cle[n][n] - cle[n][h - 1])
```
| 88,979 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong — the oldest among the inhabitants of Mainframe. But still he managed to get some information from there. For example, he managed to learn that User launches games for pleasure — and then terrible Game Cubes fall down on the city, bringing death to those modules, who cannot win the game...
For sure, as guard Bob appeared in Mainframe many modules stopped fearing Game Cubes. Because Bob (as he is alive yet) has never been defeated by User, and he always meddles with Game Cubes, because he is programmed to this.
However, unpleasant situations can happen, when a Game Cube falls down on Lost Angles. Because there lives a nasty virus — Hexadecimal, who is... mmm... very strange. And she likes to play very much. So, willy-nilly, Bob has to play with her first, and then with User.
This time Hexadecimal invented the following entertainment: Bob has to leap over binary search trees with n nodes. We should remind you that a binary search tree is a binary tree, each node has a distinct key, for each node the following is true: the left sub-tree of a node contains only nodes with keys less than the node's key, the right sub-tree of a node contains only nodes with keys greater than the node's key. All the keys are different positive integer numbers from 1 to n. Each node of such a tree can have up to two children, or have no children at all (in the case when a node is a leaf).
In Hexadecimal's game all the trees are different, but the height of each is not lower than h. In this problem «height» stands for the maximum amount of nodes on the way from the root to the remotest leaf, the root node and the leaf itself included. When Bob leaps over a tree, it disappears. Bob gets the access to a Cube, when there are no trees left. He knows how many trees he will have to leap over in the worst case. And you?
Input
The input data contains two space-separated positive integer numbers n and h (n ≤ 35, h ≤ n).
Output
Output one number — the answer to the problem. It is guaranteed that it does not exceed 9·1018.
Examples
Input
3 2
Output
5
Input
3 3
Output
4
Tags: combinatorics, divide and conquer, dp
Correct Solution:
```
# Enter your code here. Read input from STDIN. Print output to STDOUT
MAX = 71
C=[[0]*MAX for i in range(MAX)]
dp=[[0]*MAX for i in range(MAX)]
C[0][0]=1
for i in range(1, MAX):
C[i][0]=1
for i in range(1, MAX):
for j in range(1, i+1):
C[i][j]=C[i-1][j]+C[i-1][j-1]
def catalan(n):
return C[2*n][n]//(n+1)
def solve(n, h):
if(n==0): return 0
if(n<h): return 0
if(h<=1): return catalan(n)
if(dp[n][h]): return dp[n][h];
ans=0
for k in range(0, n):
if(dp[n-k-1][h-1]==0):
dp[n-k-1][h-1]=solve(n-k-1, h-1)
if(dp[k][h-1]==0):
dp[k][h-1]=solve(k, h-1)
ans+=dp[n-k-1][h-1]*( catalan(k)-dp[k][h-1]) + catalan(n-k-1)*dp[k][h-1]
dp[n][h]=ans
return ans
n, h=map(int, input().split())
ans=solve(n, h)
print(ans)
```
| 88,980 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong — the oldest among the inhabitants of Mainframe. But still he managed to get some information from there. For example, he managed to learn that User launches games for pleasure — and then terrible Game Cubes fall down on the city, bringing death to those modules, who cannot win the game...
For sure, as guard Bob appeared in Mainframe many modules stopped fearing Game Cubes. Because Bob (as he is alive yet) has never been defeated by User, and he always meddles with Game Cubes, because he is programmed to this.
However, unpleasant situations can happen, when a Game Cube falls down on Lost Angles. Because there lives a nasty virus — Hexadecimal, who is... mmm... very strange. And she likes to play very much. So, willy-nilly, Bob has to play with her first, and then with User.
This time Hexadecimal invented the following entertainment: Bob has to leap over binary search trees with n nodes. We should remind you that a binary search tree is a binary tree, each node has a distinct key, for each node the following is true: the left sub-tree of a node contains only nodes with keys less than the node's key, the right sub-tree of a node contains only nodes with keys greater than the node's key. All the keys are different positive integer numbers from 1 to n. Each node of such a tree can have up to two children, or have no children at all (in the case when a node is a leaf).
In Hexadecimal's game all the trees are different, but the height of each is not lower than h. In this problem «height» stands for the maximum amount of nodes on the way from the root to the remotest leaf, the root node and the leaf itself included. When Bob leaps over a tree, it disappears. Bob gets the access to a Cube, when there are no trees left. He knows how many trees he will have to leap over in the worst case. And you?
Input
The input data contains two space-separated positive integer numbers n and h (n ≤ 35, h ≤ n).
Output
Output one number — the answer to the problem. It is guaranteed that it does not exceed 9·1018.
Examples
Input
3 2
Output
5
Input
3 3
Output
4
Tags: combinatorics, divide and conquer, dp
Correct Solution:
```
dic={}
def dfs(a,res):
if a<=1 and res<=a:
return 1
elif a*100+res in dic:
return dic[a*100+res]
else:
cnt=0
for i in range(a):
if i<res-1 and a-i-1<res-1:
continue
else:
cnt=cnt+dfs(i,0)*dfs(a-i-1,res-1)+dfs(i,res-1)*dfs(a-i-1,0)-dfs(i,res-1)*dfs(a-i-1,res-1)
dic[a*100+res]=cnt
return cnt
inp=input().split()
print(dfs(int(inp[0]),int(inp[1])))
```
| 88,981 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong — the oldest among the inhabitants of Mainframe. But still he managed to get some information from there. For example, he managed to learn that User launches games for pleasure — and then terrible Game Cubes fall down on the city, bringing death to those modules, who cannot win the game...
For sure, as guard Bob appeared in Mainframe many modules stopped fearing Game Cubes. Because Bob (as he is alive yet) has never been defeated by User, and he always meddles with Game Cubes, because he is programmed to this.
However, unpleasant situations can happen, when a Game Cube falls down on Lost Angles. Because there lives a nasty virus — Hexadecimal, who is... mmm... very strange. And she likes to play very much. So, willy-nilly, Bob has to play with her first, and then with User.
This time Hexadecimal invented the following entertainment: Bob has to leap over binary search trees with n nodes. We should remind you that a binary search tree is a binary tree, each node has a distinct key, for each node the following is true: the left sub-tree of a node contains only nodes with keys less than the node's key, the right sub-tree of a node contains only nodes with keys greater than the node's key. All the keys are different positive integer numbers from 1 to n. Each node of such a tree can have up to two children, or have no children at all (in the case when a node is a leaf).
In Hexadecimal's game all the trees are different, but the height of each is not lower than h. In this problem «height» stands for the maximum amount of nodes on the way from the root to the remotest leaf, the root node and the leaf itself included. When Bob leaps over a tree, it disappears. Bob gets the access to a Cube, when there are no trees left. He knows how many trees he will have to leap over in the worst case. And you?
Input
The input data contains two space-separated positive integer numbers n and h (n ≤ 35, h ≤ n).
Output
Output one number — the answer to the problem. It is guaranteed that it does not exceed 9·1018.
Examples
Input
3 2
Output
5
Input
3 3
Output
4
Tags: combinatorics, divide and conquer, dp
Correct Solution:
```
def main():
def rec(n, h):
if sht[n][h]:
return dp[n][h]
sht[n][h] = 1
if n == 0:
dp[n][h] = h == 0
return dp[n][h]
if h == 0:
return dp[n][h]
if n < h:
return dp[n][h]
for i in range(n):
for j in range(h):
dp[n][h] += rec(n - 1 - i, h - 1) * rec(i, j) + rec(n - 1 - i, j) * rec(i, h - 1)
dp[n][h] -= rec(n - 1 - i, h - 1) * rec(i, h - 1)
return dp[n][h]
dp = [[0] * 40 for _ in range(40)]
sht = [[0] * 40 for _ in range(40)]
n, h = map(int, input().split())
print(sum([rec(n, j) for j in range(h, n + 1)]))
return 0
main()
```
| 88,982 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong — the oldest among the inhabitants of Mainframe. But still he managed to get some information from there. For example, he managed to learn that User launches games for pleasure — and then terrible Game Cubes fall down on the city, bringing death to those modules, who cannot win the game...
For sure, as guard Bob appeared in Mainframe many modules stopped fearing Game Cubes. Because Bob (as he is alive yet) has never been defeated by User, and he always meddles with Game Cubes, because he is programmed to this.
However, unpleasant situations can happen, when a Game Cube falls down on Lost Angles. Because there lives a nasty virus — Hexadecimal, who is... mmm... very strange. And she likes to play very much. So, willy-nilly, Bob has to play with her first, and then with User.
This time Hexadecimal invented the following entertainment: Bob has to leap over binary search trees with n nodes. We should remind you that a binary search tree is a binary tree, each node has a distinct key, for each node the following is true: the left sub-tree of a node contains only nodes with keys less than the node's key, the right sub-tree of a node contains only nodes with keys greater than the node's key. All the keys are different positive integer numbers from 1 to n. Each node of such a tree can have up to two children, or have no children at all (in the case when a node is a leaf).
In Hexadecimal's game all the trees are different, but the height of each is not lower than h. In this problem «height» stands for the maximum amount of nodes on the way from the root to the remotest leaf, the root node and the leaf itself included. When Bob leaps over a tree, it disappears. Bob gets the access to a Cube, when there are no trees left. He knows how many trees he will have to leap over in the worst case. And you?
Input
The input data contains two space-separated positive integer numbers n and h (n ≤ 35, h ≤ n).
Output
Output one number — the answer to the problem. It is guaranteed that it does not exceed 9·1018.
Examples
Input
3 2
Output
5
Input
3 3
Output
4
Submitted Solution:
```
n, h = map(int, input().split())
less = [[1] * (n + 2)] + [[0] * (n + 2) for i in range(n)] # dp[n][h]
ge = [[0] * (n + 2) for i in range(n + 1)] # dp[n][h]
less[0][0] = 0
less[0][-1] = 0
ge[0][0] = 1
ge[0][-1] = 1
for i in range(1, n + 1):
for j in range(0, n + 1):
for k in range(1, i + 1):
if j > 0:
less[i][j] += less[k - 1][j - 1] * less[i - k][j - 1]
ge[i][j] += ge[k - 1][j - 1] * less[i - k][j - 1] + \
less[k - 1][j - 1] * ge[i - k][j - 1] + \
ge[k - 1][j - 1] * ge[i - k][j - 1]
ge[i][-1] = ge[i][0]
print(ge[n][h])
```
Yes
| 88,983 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong — the oldest among the inhabitants of Mainframe. But still he managed to get some information from there. For example, he managed to learn that User launches games for pleasure — and then terrible Game Cubes fall down on the city, bringing death to those modules, who cannot win the game...
For sure, as guard Bob appeared in Mainframe many modules stopped fearing Game Cubes. Because Bob (as he is alive yet) has never been defeated by User, and he always meddles with Game Cubes, because he is programmed to this.
However, unpleasant situations can happen, when a Game Cube falls down on Lost Angles. Because there lives a nasty virus — Hexadecimal, who is... mmm... very strange. And she likes to play very much. So, willy-nilly, Bob has to play with her first, and then with User.
This time Hexadecimal invented the following entertainment: Bob has to leap over binary search trees with n nodes. We should remind you that a binary search tree is a binary tree, each node has a distinct key, for each node the following is true: the left sub-tree of a node contains only nodes with keys less than the node's key, the right sub-tree of a node contains only nodes with keys greater than the node's key. All the keys are different positive integer numbers from 1 to n. Each node of such a tree can have up to two children, or have no children at all (in the case when a node is a leaf).
In Hexadecimal's game all the trees are different, but the height of each is not lower than h. In this problem «height» stands for the maximum amount of nodes on the way from the root to the remotest leaf, the root node and the leaf itself included. When Bob leaps over a tree, it disappears. Bob gets the access to a Cube, when there are no trees left. He knows how many trees he will have to leap over in the worst case. And you?
Input
The input data contains two space-separated positive integer numbers n and h (n ≤ 35, h ≤ n).
Output
Output one number — the answer to the problem. It is guaranteed that it does not exceed 9·1018.
Examples
Input
3 2
Output
5
Input
3 3
Output
4
Submitted Solution:
```
# coding: utf-8
# In[9]:
# In[42]:
line = input().split()
n = int(line[0])
h = int(line[1])
from math import log
array_nodes_minheigt = [[0 for x in range(36)] for y in range(36)]
array_nodes_minheigt[0][0] = 1
for nodes in range(1,36):
for minheight in range(0,nodes+1):
for topnode in range(1, nodes + 1):
left = topnode-1
right = nodes - topnode
array_nodes_minheigt[nodes][minheight] += array_nodes_minheigt[left][0] * array_nodes_minheigt[right][0] - (array_nodes_minheigt[left][0]-array_nodes_minheigt[left][max(minheight-1,0)])* (array_nodes_minheigt[right][0]-array_nodes_minheigt[right][max(minheight-1,0)])
print(int(array_nodes_minheigt[n][h]))
```
Yes
| 88,984 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong — the oldest among the inhabitants of Mainframe. But still he managed to get some information from there. For example, he managed to learn that User launches games for pleasure — and then terrible Game Cubes fall down on the city, bringing death to those modules, who cannot win the game...
For sure, as guard Bob appeared in Mainframe many modules stopped fearing Game Cubes. Because Bob (as he is alive yet) has never been defeated by User, and he always meddles with Game Cubes, because he is programmed to this.
However, unpleasant situations can happen, when a Game Cube falls down on Lost Angles. Because there lives a nasty virus — Hexadecimal, who is... mmm... very strange. And she likes to play very much. So, willy-nilly, Bob has to play with her first, and then with User.
This time Hexadecimal invented the following entertainment: Bob has to leap over binary search trees with n nodes. We should remind you that a binary search tree is a binary tree, each node has a distinct key, for each node the following is true: the left sub-tree of a node contains only nodes with keys less than the node's key, the right sub-tree of a node contains only nodes with keys greater than the node's key. All the keys are different positive integer numbers from 1 to n. Each node of such a tree can have up to two children, or have no children at all (in the case when a node is a leaf).
In Hexadecimal's game all the trees are different, but the height of each is not lower than h. In this problem «height» stands for the maximum amount of nodes on the way from the root to the remotest leaf, the root node and the leaf itself included. When Bob leaps over a tree, it disappears. Bob gets the access to a Cube, when there are no trees left. He knows how many trees he will have to leap over in the worst case. And you?
Input
The input data contains two space-separated positive integer numbers n and h (n ≤ 35, h ≤ n).
Output
Output one number — the answer to the problem. It is guaranteed that it does not exceed 9·1018.
Examples
Input
3 2
Output
5
Input
3 3
Output
4
Submitted Solution:
```
# coding: utf-8
# In[9]:
# In[42]:
line = input().split()
n = int(line[0])
h = int(line[1])
from math import log
array_nodes_minheigt = [[0 for x in range(36)] for y in range(36)]
array_nodes_minheigt[0][0] = 1
for nodes in range(1,36):
for minheight in range(0,nodes+1):
for topnode in range(1, nodes + 1):
left = topnode-1
right = nodes - topnode
array_nodes_minheigt[nodes][minheight] += array_nodes_minheigt[left][0] * array_nodes_minheigt[right][0] - (array_nodes_minheigt[left][0]-array_nodes_minheigt[left][max(minheight-1,0)])* (array_nodes_minheigt[right][0]-array_nodes_minheigt[right][max(minheight-1,0)])
print(int(array_nodes_minheigt[n][h]))
# Made By Mostafa_Khaled
```
Yes
| 88,985 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong — the oldest among the inhabitants of Mainframe. But still he managed to get some information from there. For example, he managed to learn that User launches games for pleasure — and then terrible Game Cubes fall down on the city, bringing death to those modules, who cannot win the game...
For sure, as guard Bob appeared in Mainframe many modules stopped fearing Game Cubes. Because Bob (as he is alive yet) has never been defeated by User, and he always meddles with Game Cubes, because he is programmed to this.
However, unpleasant situations can happen, when a Game Cube falls down on Lost Angles. Because there lives a nasty virus — Hexadecimal, who is... mmm... very strange. And she likes to play very much. So, willy-nilly, Bob has to play with her first, and then with User.
This time Hexadecimal invented the following entertainment: Bob has to leap over binary search trees with n nodes. We should remind you that a binary search tree is a binary tree, each node has a distinct key, for each node the following is true: the left sub-tree of a node contains only nodes with keys less than the node's key, the right sub-tree of a node contains only nodes with keys greater than the node's key. All the keys are different positive integer numbers from 1 to n. Each node of such a tree can have up to two children, or have no children at all (in the case when a node is a leaf).
In Hexadecimal's game all the trees are different, but the height of each is not lower than h. In this problem «height» stands for the maximum amount of nodes on the way from the root to the remotest leaf, the root node and the leaf itself included. When Bob leaps over a tree, it disappears. Bob gets the access to a Cube, when there are no trees left. He knows how many trees he will have to leap over in the worst case. And you?
Input
The input data contains two space-separated positive integer numbers n and h (n ≤ 35, h ≤ n).
Output
Output one number — the answer to the problem. It is guaranteed that it does not exceed 9·1018.
Examples
Input
3 2
Output
5
Input
3 3
Output
4
Submitted Solution:
```
def main():
(n, h) = input().split()
n = int(n)
h = int(h)
#(n, h) = (3, 3)
memo = [([None] * (h + 1)) for i in range(n + 1)]
catalans = [catalan(i) for i in range(n + 1)]
print(calculate(n, h, memo, catalans))
def calculate(n, h, memo, catalans):
if memo[n][h] != None:
return memo[n][h]
elif n < h:
memo[n][h] = 0
return 0
elif n <= 1:
memo[n][h] = 1
return 1
else:
if h == 0:
newH = 0
else:
newH = h - 1
total = 0
for left in range(n):
right = n - left - 1
calcLeft = calculate(left, newH, memo, catalans)
calcRight = calculate(right, newH, memo, catalans)
total += (calcLeft * catalans[right]) + \
(calcRight * catalans[left]) - (calcLeft * calcRight)
memo[n][h] = total
return total
def catalan(n):
product = 1
for top in range(n + 1, 2 * n + 1):
product *= top
for bot in range(2, n + 1):
product //= bot
product //= (n + 1)
return product
#print(catalan(4))
main()
```
Yes
| 88,986 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong — the oldest among the inhabitants of Mainframe. But still he managed to get some information from there. For example, he managed to learn that User launches games for pleasure — and then terrible Game Cubes fall down on the city, bringing death to those modules, who cannot win the game...
For sure, as guard Bob appeared in Mainframe many modules stopped fearing Game Cubes. Because Bob (as he is alive yet) has never been defeated by User, and he always meddles with Game Cubes, because he is programmed to this.
However, unpleasant situations can happen, when a Game Cube falls down on Lost Angles. Because there lives a nasty virus — Hexadecimal, who is... mmm... very strange. And she likes to play very much. So, willy-nilly, Bob has to play with her first, and then with User.
This time Hexadecimal invented the following entertainment: Bob has to leap over binary search trees with n nodes. We should remind you that a binary search tree is a binary tree, each node has a distinct key, for each node the following is true: the left sub-tree of a node contains only nodes with keys less than the node's key, the right sub-tree of a node contains only nodes with keys greater than the node's key. All the keys are different positive integer numbers from 1 to n. Each node of such a tree can have up to two children, or have no children at all (in the case when a node is a leaf).
In Hexadecimal's game all the trees are different, but the height of each is not lower than h. In this problem «height» stands for the maximum amount of nodes on the way from the root to the remotest leaf, the root node and the leaf itself included. When Bob leaps over a tree, it disappears. Bob gets the access to a Cube, when there are no trees left. He knows how many trees he will have to leap over in the worst case. And you?
Input
The input data contains two space-separated positive integer numbers n and h (n ≤ 35, h ≤ n).
Output
Output one number — the answer to the problem. It is guaranteed that it does not exceed 9·1018.
Examples
Input
3 2
Output
5
Input
3 3
Output
4
Submitted Solution:
```
import sys
from array import array # noqa: F401
from math import factorial
def input():
return sys.stdin.buffer.readline().decode('utf-8')
n, h = map(int, input().split())
catalan = [factorial(2 * i) // factorial(i + 1) // factorial(i) for i in range(26)]
dp = [[-1] * 100 for _ in range(100)]
dp[0][0] = 1
def solve(x, h):
if dp[x][h] != -1:
return dp[x][h]
res = 0
for l, r in zip(range(x), range(x - 1, -1, -1)):
if l >= h - 1:
res += solve(l, h - 1) * catalan[r]
if r >= h - 1:
res += catalan[l] * solve(r, h - 1)
if l >= h - 1 and r >= -1:
res -= solve(l, h - 1) * solve(r, h - 1)
dp[x][h] = res
return res
print(solve(n, h))
```
No
| 88,987 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong — the oldest among the inhabitants of Mainframe. But still he managed to get some information from there. For example, he managed to learn that User launches games for pleasure — and then terrible Game Cubes fall down on the city, bringing death to those modules, who cannot win the game...
For sure, as guard Bob appeared in Mainframe many modules stopped fearing Game Cubes. Because Bob (as he is alive yet) has never been defeated by User, and he always meddles with Game Cubes, because he is programmed to this.
However, unpleasant situations can happen, when a Game Cube falls down on Lost Angles. Because there lives a nasty virus — Hexadecimal, who is... mmm... very strange. And she likes to play very much. So, willy-nilly, Bob has to play with her first, and then with User.
This time Hexadecimal invented the following entertainment: Bob has to leap over binary search trees with n nodes. We should remind you that a binary search tree is a binary tree, each node has a distinct key, for each node the following is true: the left sub-tree of a node contains only nodes with keys less than the node's key, the right sub-tree of a node contains only nodes with keys greater than the node's key. All the keys are different positive integer numbers from 1 to n. Each node of such a tree can have up to two children, or have no children at all (in the case when a node is a leaf).
In Hexadecimal's game all the trees are different, but the height of each is not lower than h. In this problem «height» stands for the maximum amount of nodes on the way from the root to the remotest leaf, the root node and the leaf itself included. When Bob leaps over a tree, it disappears. Bob gets the access to a Cube, when there are no trees left. He knows how many trees he will have to leap over in the worst case. And you?
Input
The input data contains two space-separated positive integer numbers n and h (n ≤ 35, h ≤ n).
Output
Output one number — the answer to the problem. It is guaranteed that it does not exceed 9·1018.
Examples
Input
3 2
Output
5
Input
3 3
Output
4
Submitted Solution:
```
dic={}
def dfs(a,res):
if a<=1:
return 1
elif a*100+res in dic:
return dic[a*100+res]
else:
cnt=0
for i in range(a):
if i<res-1 and a-i-1<res-1:
continue
else:
cnt=cnt+dfs(i,res-1)*dfs(a-i-1,res-1)
dic[a*100+res]=cnt
return cnt
inp=input().split()
print(dfs(int(inp[0]),int(inp[1])))
```
No
| 88,988 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong — the oldest among the inhabitants of Mainframe. But still he managed to get some information from there. For example, he managed to learn that User launches games for pleasure — and then terrible Game Cubes fall down on the city, bringing death to those modules, who cannot win the game...
For sure, as guard Bob appeared in Mainframe many modules stopped fearing Game Cubes. Because Bob (as he is alive yet) has never been defeated by User, and he always meddles with Game Cubes, because he is programmed to this.
However, unpleasant situations can happen, when a Game Cube falls down on Lost Angles. Because there lives a nasty virus — Hexadecimal, who is... mmm... very strange. And she likes to play very much. So, willy-nilly, Bob has to play with her first, and then with User.
This time Hexadecimal invented the following entertainment: Bob has to leap over binary search trees with n nodes. We should remind you that a binary search tree is a binary tree, each node has a distinct key, for each node the following is true: the left sub-tree of a node contains only nodes with keys less than the node's key, the right sub-tree of a node contains only nodes with keys greater than the node's key. All the keys are different positive integer numbers from 1 to n. Each node of such a tree can have up to two children, or have no children at all (in the case when a node is a leaf).
In Hexadecimal's game all the trees are different, but the height of each is not lower than h. In this problem «height» stands for the maximum amount of nodes on the way from the root to the remotest leaf, the root node and the leaf itself included. When Bob leaps over a tree, it disappears. Bob gets the access to a Cube, when there are no trees left. He knows how many trees he will have to leap over in the worst case. And you?
Input
The input data contains two space-separated positive integer numbers n and h (n ≤ 35, h ≤ n).
Output
Output one number — the answer to the problem. It is guaranteed that it does not exceed 9·1018.
Examples
Input
3 2
Output
5
Input
3 3
Output
4
Submitted Solution:
```
n, h = map(int, input().split())
node_counts = [0]
dp = [[0 for j in range(n+1)] for i in range(n+1)]
# Maximum amount of nodes for each height
for i in range(n):
node_counts.append(node_counts[-1] + (2**i))
for i in range(1, n+1):
for j in range(1, n+1):
if (j < i or j > node_counts[i]): continue
elif (j == node_counts[i]):
dp[i][j] = 1
continue
for l in range(0, j):
left = dp[i-1][l]
right = dp[i-1][j-l-1]
if (left == 0 and right == 0): continue
if (left == 0): left = 1
if (right == 0): right = 1
dp[i][j] += left * right
s = 0
for i in range(h, n+1):
s += dp[i][n]
print(s)
```
No
| 88,989 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong — the oldest among the inhabitants of Mainframe. But still he managed to get some information from there. For example, he managed to learn that User launches games for pleasure — and then terrible Game Cubes fall down on the city, bringing death to those modules, who cannot win the game...
For sure, as guard Bob appeared in Mainframe many modules stopped fearing Game Cubes. Because Bob (as he is alive yet) has never been defeated by User, and he always meddles with Game Cubes, because he is programmed to this.
However, unpleasant situations can happen, when a Game Cube falls down on Lost Angles. Because there lives a nasty virus — Hexadecimal, who is... mmm... very strange. And she likes to play very much. So, willy-nilly, Bob has to play with her first, and then with User.
This time Hexadecimal invented the following entertainment: Bob has to leap over binary search trees with n nodes. We should remind you that a binary search tree is a binary tree, each node has a distinct key, for each node the following is true: the left sub-tree of a node contains only nodes with keys less than the node's key, the right sub-tree of a node contains only nodes with keys greater than the node's key. All the keys are different positive integer numbers from 1 to n. Each node of such a tree can have up to two children, or have no children at all (in the case when a node is a leaf).
In Hexadecimal's game all the trees are different, but the height of each is not lower than h. In this problem «height» stands for the maximum amount of nodes on the way from the root to the remotest leaf, the root node and the leaf itself included. When Bob leaps over a tree, it disappears. Bob gets the access to a Cube, when there are no trees left. He knows how many trees he will have to leap over in the worst case. And you?
Input
The input data contains two space-separated positive integer numbers n and h (n ≤ 35, h ≤ n).
Output
Output one number — the answer to the problem. It is guaranteed that it does not exceed 9·1018.
Examples
Input
3 2
Output
5
Input
3 3
Output
4
Submitted Solution:
```
import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
n, h = map(int, input().split())
dp = [[[0] * (n + 2) for _ in range(n + 2)] for _ in range(n * 2)]
dp[0][1][1] = 1
for i in range(n * 2 - 1):
for j in range(n + 1):
for k in range(j + 1):
if k > 0:
dp[i + 1][j][k - 1] += dp[i][j][k]
dp[i + 1][j + 1 if k == j else j][k + 1] += dp[i][j][k]
ans = 0
for i in range(max(0, h - 1), n + 1):
ans += dp[-1][i][0]
print(ans)
```
No
| 88,990 |
Provide a correct Python 3 solution for this coding contest problem.
Tak performed the following action N times: rolling two dice. The result of the i-th roll is D_{i,1} and D_{i,2}.
Check if doublets occurred at least three times in a row. Specifically, check if there exists at lease one i such that D_{i,1}=D_{i,2}, D_{i+1,1}=D_{i+1,2} and D_{i+2,1}=D_{i+2,2} hold.
Constraints
* 3 \leq N \leq 100
* 1\leq D_{i,j} \leq 6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
D_{1,1} D_{1,2}
\vdots
D_{N,1} D_{N,2}
Output
Print `Yes` if doublets occurred at least three times in a row. Print `No` otherwise.
Examples
Input
5
1 2
6 6
4 4
3 3
3 2
Output
Yes
Input
5
1 1
2 2
3 4
5 5
6 6
Output
No
Input
6
1 1
2 2
3 3
4 4
5 5
6 6
Output
Yes
"Correct Solution:
```
N=int(input())
zoro=0
res=0
for _ in [0]*N:
a,b=map(int,input().split())
if a==b:
zoro+=1
res=max(res,zoro)
else:
zoro=0
print(['No','Yes'][res>2])
```
| 88,991 |
Provide a correct Python 3 solution for this coding contest problem.
Tak performed the following action N times: rolling two dice. The result of the i-th roll is D_{i,1} and D_{i,2}.
Check if doublets occurred at least three times in a row. Specifically, check if there exists at lease one i such that D_{i,1}=D_{i,2}, D_{i+1,1}=D_{i+1,2} and D_{i+2,1}=D_{i+2,2} hold.
Constraints
* 3 \leq N \leq 100
* 1\leq D_{i,j} \leq 6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
D_{1,1} D_{1,2}
\vdots
D_{N,1} D_{N,2}
Output
Print `Yes` if doublets occurred at least three times in a row. Print `No` otherwise.
Examples
Input
5
1 2
6 6
4 4
3 3
3 2
Output
Yes
Input
5
1 1
2 2
3 4
5 5
6 6
Output
No
Input
6
1 1
2 2
3 3
4 4
5 5
6 6
Output
Yes
"Correct Solution:
```
print("YNeos"["000" not in "".join([str(eval(input().replace(" ","-")))for _ in "_"*int(input())])::2])
```
| 88,992 |
Provide a correct Python 3 solution for this coding contest problem.
Tak performed the following action N times: rolling two dice. The result of the i-th roll is D_{i,1} and D_{i,2}.
Check if doublets occurred at least three times in a row. Specifically, check if there exists at lease one i such that D_{i,1}=D_{i,2}, D_{i+1,1}=D_{i+1,2} and D_{i+2,1}=D_{i+2,2} hold.
Constraints
* 3 \leq N \leq 100
* 1\leq D_{i,j} \leq 6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
D_{1,1} D_{1,2}
\vdots
D_{N,1} D_{N,2}
Output
Print `Yes` if doublets occurred at least three times in a row. Print `No` otherwise.
Examples
Input
5
1 2
6 6
4 4
3 3
3 2
Output
Yes
Input
5
1 1
2 2
3 4
5 5
6 6
Output
No
Input
6
1 1
2 2
3 3
4 4
5 5
6 6
Output
Yes
"Correct Solution:
```
n = int(input())
d = []
z = 0
for i in range(n):
d1, d2 = map(int, input().split())
z = z+1 if d1==d2 else 0
d.append(z)
ans = 'Yes' if max(d)>=3 else 'No'
print(ans)
```
| 88,993 |
Provide a correct Python 3 solution for this coding contest problem.
Tak performed the following action N times: rolling two dice. The result of the i-th roll is D_{i,1} and D_{i,2}.
Check if doublets occurred at least three times in a row. Specifically, check if there exists at lease one i such that D_{i,1}=D_{i,2}, D_{i+1,1}=D_{i+1,2} and D_{i+2,1}=D_{i+2,2} hold.
Constraints
* 3 \leq N \leq 100
* 1\leq D_{i,j} \leq 6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
D_{1,1} D_{1,2}
\vdots
D_{N,1} D_{N,2}
Output
Print `Yes` if doublets occurred at least three times in a row. Print `No` otherwise.
Examples
Input
5
1 2
6 6
4 4
3 3
3 2
Output
Yes
Input
5
1 1
2 2
3 4
5 5
6 6
Output
No
Input
6
1 1
2 2
3 3
4 4
5 5
6 6
Output
Yes
"Correct Solution:
```
n=int(input())
cnt=0
ans="No"
for i in range(n):
d1,d2=map(int,input().split())
if d1==d2:
cnt+=1
else:
cnt=0
if cnt>=3:
ans="Yes"
print(ans)
```
| 88,994 |
Provide a correct Python 3 solution for this coding contest problem.
Tak performed the following action N times: rolling two dice. The result of the i-th roll is D_{i,1} and D_{i,2}.
Check if doublets occurred at least three times in a row. Specifically, check if there exists at lease one i such that D_{i,1}=D_{i,2}, D_{i+1,1}=D_{i+1,2} and D_{i+2,1}=D_{i+2,2} hold.
Constraints
* 3 \leq N \leq 100
* 1\leq D_{i,j} \leq 6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
D_{1,1} D_{1,2}
\vdots
D_{N,1} D_{N,2}
Output
Print `Yes` if doublets occurred at least three times in a row. Print `No` otherwise.
Examples
Input
5
1 2
6 6
4 4
3 3
3 2
Output
Yes
Input
5
1 1
2 2
3 4
5 5
6 6
Output
No
Input
6
1 1
2 2
3 3
4 4
5 5
6 6
Output
Yes
"Correct Solution:
```
n = int(input())
cnt = 0
for i in range(n):
x, y = map(int, input().split())
if x == y:
cnt += 1
else:
cnt = 0
if cnt == 3:
print('Yes')
exit(0)
print('No')
```
| 88,995 |
Provide a correct Python 3 solution for this coding contest problem.
Tak performed the following action N times: rolling two dice. The result of the i-th roll is D_{i,1} and D_{i,2}.
Check if doublets occurred at least three times in a row. Specifically, check if there exists at lease one i such that D_{i,1}=D_{i,2}, D_{i+1,1}=D_{i+1,2} and D_{i+2,1}=D_{i+2,2} hold.
Constraints
* 3 \leq N \leq 100
* 1\leq D_{i,j} \leq 6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
D_{1,1} D_{1,2}
\vdots
D_{N,1} D_{N,2}
Output
Print `Yes` if doublets occurred at least three times in a row. Print `No` otherwise.
Examples
Input
5
1 2
6 6
4 4
3 3
3 2
Output
Yes
Input
5
1 1
2 2
3 4
5 5
6 6
Output
No
Input
6
1 1
2 2
3 3
4 4
5 5
6 6
Output
Yes
"Correct Solution:
```
n=int(input())
c=0
o=""
for _ in range(n):
d,d1=map(int,input().split())
if d==d1:
c+=1
if c==3:
o="Yes"
else:
c=0
if o=="":
o="No"
print(o)
```
| 88,996 |
Provide a correct Python 3 solution for this coding contest problem.
Tak performed the following action N times: rolling two dice. The result of the i-th roll is D_{i,1} and D_{i,2}.
Check if doublets occurred at least three times in a row. Specifically, check if there exists at lease one i such that D_{i,1}=D_{i,2}, D_{i+1,1}=D_{i+1,2} and D_{i+2,1}=D_{i+2,2} hold.
Constraints
* 3 \leq N \leq 100
* 1\leq D_{i,j} \leq 6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
D_{1,1} D_{1,2}
\vdots
D_{N,1} D_{N,2}
Output
Print `Yes` if doublets occurred at least three times in a row. Print `No` otherwise.
Examples
Input
5
1 2
6 6
4 4
3 3
3 2
Output
Yes
Input
5
1 1
2 2
3 4
5 5
6 6
Output
No
Input
6
1 1
2 2
3 3
4 4
5 5
6 6
Output
Yes
"Correct Solution:
```
N = int(input())
cnt = 0
ans = 'No'
for i in range(N):
d1,d2 = map(int, input().split())
if d1==d2:
cnt += 1
if cnt==3:
ans = 'Yes'
else:
cnt = 0
print(ans)
```
| 88,997 |
Provide a correct Python 3 solution for this coding contest problem.
Tak performed the following action N times: rolling two dice. The result of the i-th roll is D_{i,1} and D_{i,2}.
Check if doublets occurred at least three times in a row. Specifically, check if there exists at lease one i such that D_{i,1}=D_{i,2}, D_{i+1,1}=D_{i+1,2} and D_{i+2,1}=D_{i+2,2} hold.
Constraints
* 3 \leq N \leq 100
* 1\leq D_{i,j} \leq 6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
D_{1,1} D_{1,2}
\vdots
D_{N,1} D_{N,2}
Output
Print `Yes` if doublets occurred at least three times in a row. Print `No` otherwise.
Examples
Input
5
1 2
6 6
4 4
3 3
3 2
Output
Yes
Input
5
1 1
2 2
3 4
5 5
6 6
Output
No
Input
6
1 1
2 2
3 3
4 4
5 5
6 6
Output
Yes
"Correct Solution:
```
ng = True
cnt = 0
for i in range(int(input())):
a, b = map(int, input().split())
if a==b: cnt+=1
else: cnt = 0
if cnt>=3: ng = False
print("YNeos"[ng::2])
```
| 88,998 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Tak performed the following action N times: rolling two dice. The result of the i-th roll is D_{i,1} and D_{i,2}.
Check if doublets occurred at least three times in a row. Specifically, check if there exists at lease one i such that D_{i,1}=D_{i,2}, D_{i+1,1}=D_{i+1,2} and D_{i+2,1}=D_{i+2,2} hold.
Constraints
* 3 \leq N \leq 100
* 1\leq D_{i,j} \leq 6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
D_{1,1} D_{1,2}
\vdots
D_{N,1} D_{N,2}
Output
Print `Yes` if doublets occurred at least three times in a row. Print `No` otherwise.
Examples
Input
5
1 2
6 6
4 4
3 3
3 2
Output
Yes
Input
5
1 1
2 2
3 4
5 5
6 6
Output
No
Input
6
1 1
2 2
3 3
4 4
5 5
6 6
Output
Yes
Submitted Solution:
```
n=int(input())
cnt=0
for _ in range(n):
d1,d2=map(int,input().split())
if d1==d2:
cnt += 1
else:
cnt = 0
if cnt >= 3:
print('Yes')
break
else:
print('No')
```
Yes
| 88,999 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.