message stringlengths 2 20.1k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 1.95k 109k | cluster float64 17 17 | __index_level_0__ int64 3.91k 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, m is the number of the participants of the current round):
* let k be the maximal power of the number 2 such that k β€ m,
* k participants compete in the current round and a half of them passes to the next round, the other m - k participants pass to the next round directly,
* when only one participant remains, the tournament finishes.
Each match requires b bottles of water for each participant and one bottle for the judge. Besides p towels are given to each participant for the whole tournament.
Find the number of bottles and towels needed for the tournament.
Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose).
Input
The only line contains three integers n, b, p (1 β€ n, b, p β€ 500) β the number of participants and the parameters described in the problem statement.
Output
Print two integers x and y β the number of bottles and towels need for the tournament.
Examples
Input
5 2 3
Output
20 15
Input
8 2 4
Output
35 32
Note
In the first example will be three rounds:
1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge),
2. in the second round will be only one match, so we need another 5 bottles of water,
3. in the third round will also be only one match, so we need another 5 bottles of water.
So in total we need 20 bottles of water.
In the second example no participant will move on to some round directly.
Submitted Solution:
```
n,b,p = map(int,input().split())
print((n-1)*(n*b+1),n*p)
``` | instruction | 0 | 37,288 | 17 | 74,576 |
No | output | 1 | 37,288 | 17 | 74,577 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, m is the number of the participants of the current round):
* let k be the maximal power of the number 2 such that k β€ m,
* k participants compete in the current round and a half of them passes to the next round, the other m - k participants pass to the next round directly,
* when only one participant remains, the tournament finishes.
Each match requires b bottles of water for each participant and one bottle for the judge. Besides p towels are given to each participant for the whole tournament.
Find the number of bottles and towels needed for the tournament.
Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose).
Input
The only line contains three integers n, b, p (1 β€ n, b, p β€ 500) β the number of participants and the parameters described in the problem statement.
Output
Print two integers x and y β the number of bottles and towels need for the tournament.
Examples
Input
5 2 3
Output
20 15
Input
8 2 4
Output
35 32
Note
In the first example will be three rounds:
1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge),
2. in the second round will be only one match, so we need another 5 bottles of water,
3. in the third round will also be only one match, so we need another 5 bottles of water.
So in total we need 20 bottles of water.
In the second example no participant will move on to some round directly.
Submitted Solution:
```
n, b, p = map(int, input().split())
q = n
qs = 0
while q != 1:
s = 2
e = 1
while s-1 < q:
s *= s
e += 1
q -= s**0.5//2
qs += (s**0.5)*b+e-1
print(int(qs), n*p)
# Fri Oct 16 2020 21:05:27 GMT+0300 (ΠΠΎΡΠΊΠ²Π°, ΡΡΠ°Π½Π΄Π°ΡΡΠ½ΠΎΠ΅ Π²ΡΠ΅ΠΌΡ)
``` | instruction | 0 | 37,289 | 17 | 74,578 |
No | output | 1 | 37,289 | 17 | 74,579 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, m is the number of the participants of the current round):
* let k be the maximal power of the number 2 such that k β€ m,
* k participants compete in the current round and a half of them passes to the next round, the other m - k participants pass to the next round directly,
* when only one participant remains, the tournament finishes.
Each match requires b bottles of water for each participant and one bottle for the judge. Besides p towels are given to each participant for the whole tournament.
Find the number of bottles and towels needed for the tournament.
Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose).
Input
The only line contains three integers n, b, p (1 β€ n, b, p β€ 500) β the number of participants and the parameters described in the problem statement.
Output
Print two integers x and y β the number of bottles and towels need for the tournament.
Examples
Input
5 2 3
Output
20 15
Input
8 2 4
Output
35 32
Note
In the first example will be three rounds:
1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge),
2. in the second round will be only one match, so we need another 5 bottles of water,
3. in the third round will also be only one match, so we need another 5 bottles of water.
So in total we need 20 bottles of water.
In the second example no participant will move on to some round directly.
Submitted Solution:
```
s = list(input())
while True:
try:
s.remove(' ')
except ValueError:
break
n = int(s[0])
b = int(s[1])
p = int(s[2])
y = n*p
k = 0
def max(m):
res = 1
while m>=res:
res *= 2
return res/2
while n>1:
k += max(n)/2
n -= max(n)/2
print (int(k*(2*b+1)),y,sep = ' ')
``` | instruction | 0 | 37,290 | 17 | 74,580 |
No | output | 1 | 37,290 | 17 | 74,581 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A and B are preparing themselves for programming contests.
The University where A and B study is a set of rooms connected by corridors. Overall, the University has n rooms connected by n - 1 corridors so that you can get from any room to any other one by moving along the corridors. The rooms are numbered from 1 to n.
Every day Π and B write contests in some rooms of their university, and after each contest they gather together in the same room and discuss problems. A and B want the distance from the rooms where problems are discussed to the rooms where contests are written to be equal. The distance between two rooms is the number of edges on the shortest path between them.
As they write contests in new rooms every day, they asked you to help them find the number of possible rooms to discuss problems for each of the following m days.
Input
The first line contains integer n (1 β€ n β€ 105) β the number of rooms in the University.
The next n - 1 lines describe the corridors. The i-th of these lines (1 β€ i β€ n - 1) contains two integers ai and bi (1 β€ ai, bi β€ n), showing that the i-th corridor connects rooms ai and bi.
The next line contains integer m (1 β€ m β€ 105) β the number of queries.
Next m lines describe the queries. The j-th of these lines (1 β€ j β€ m) contains two integers xj and yj (1 β€ xj, yj β€ n) that means that on the j-th day A will write the contest in the room xj, B will write in the room yj.
Output
In the i-th (1 β€ i β€ m) line print the number of rooms that are equidistant from the rooms where A and B write contest on the i-th day.
Examples
Input
4
1 2
1 3
2 4
1
2 3
Output
1
Input
4
1 2
2 3
2 4
2
1 2
1 3
Output
0
2
Note
in the first sample there is only one room at the same distance from rooms number 2 and 3 β room number 1. | instruction | 0 | 38,081 | 17 | 76,162 |
Tags: binary search, data structures, dfs and similar, dp, trees
Correct Solution:
```
from collections import defaultdict as df
from collections import deque
import os
import sys
from io import BytesIO, IOBase
_str = str
str = lambda x=b"": x if type(x) is bytes else _str(x).encode()
BUFSIZE = 8192
from types import GeneratorType
def bootstrap(f, stack=[]):
def wrappedfunc(*args, **kwargs):
if stack:
return f(*args, **kwargs)
else:
to = f(*args, **kwargs)
while True:
if type(to) is GeneratorType:
stack.append(to)
to = next(to)
else:
stack.pop()
if not stack:
break
to = stack[-1].send(to)
return to
return wrappedfunc
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")
import math
timer = [0]
@bootstrap
def dfs(v, p):
tin[v] = timer[0]
timer[0] += 1
up[v][0] = p
for i in range(1, L):
up[v][i] = up[up[v][i - 1]][i - 1]
for child in tree[v]:
if child != p:
depth[child] = depth[v] + 1
yield dfs(child, v)
sz[v] += sz[child]
sz[v] += 1
tout[v] = timer[0]
timer[0] += 1
yield 0
def is_ancestor(u, v):
return tin[u] <= tin[v] and tout[u] >= tout[v]
def lca(u, v):
if is_ancestor(u, v):
return u
if is_ancestor(v, u):
return v
for i in range(L - 1, -1, -1):
if not is_ancestor(up[u][i], v):
u = up[u][i]
return up[u][0]
def cal_node(u, step):
for i in range(L - 1, -1, -1):
if pows[i] > step:
continue
# print('result dis: {}'.format(res))
# input()
u = up[u][i]
step -= pows[i]
return u
n = int(input())
depth = [0 for i in range(n + 1)]
L = math.ceil(math.log2(n) + 1)
pows = [2**i for i in range(L + 1)]
tin = [0 for i in range(n + 1)]
tout = [0 for i in range(n + 1)]
sz = [0 for i in range(n + 1)]
up = [[0 for i in range(L)] for i in range(n + 1)]
tree = df(list)
for i in range(n - 1):
u, v = map(int, input().split())
tree[u].append(v)
tree[v].append(u)
dfs(1, 1)
m = int(input())
for _ in range(m):
a,b = map(int, input().split())
if a == b:
print(sz[1])
elif is_ancestor(a,b):
dis = abs(depth[a] - depth[b])
if dis % 2:
print(0)
else:
ans_node = cal_node(b, dis//2 - 1)
ans_sz = sz[ans_node]
pa_sz = sz[up[ans_node][0]]
print(pa_sz - ans_sz)
elif is_ancestor(b, a):
dis = abs(depth[b] - depth[a])
if dis % 2:
print(0)
else:
ans_node = cal_node(a, dis // 2 - 1)
ans_sz = sz[ans_node]
pa_sz = sz[up[ans_node][0]]
print(pa_sz - ans_sz)
else:
llca = lca(a, b)
dis1 = abs(depth[llca] - depth[a])
dis2 = abs(depth[llca] - depth[b])
if (dis1 + dis2) % 2:
print(0)
elif dis1 == dis2:
n1 = cal_node(a, dis1 - 1)
n2 = cal_node(b, dis2 - 1)
print(sz[1] - sz[n1] - sz[n2])
else:
if dis1 > dis2:
step_from_lca = (dis1 - dis2)//2
step_to_lca = dis1 - step_from_lca
node = cal_node(a, step_to_lca - 1)
pa_sz = sz[up[node][0]]
print(pa_sz - sz[node])
else:
step_from_lca = (dis2 - dis1) // 2
step_to_lca = dis2 - step_from_lca
node = cal_node(b, step_to_lca - 1)
pa_sz = sz[up[node][0]]
print(pa_sz - sz[node])
``` | output | 1 | 38,081 | 17 | 76,163 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.
Some of them celebrated in the BugDonalds restaurant, some of them β in the BeaverKing restaurant, the most successful ones were fast enough to celebrate in both of restaurants. Students which didn't pass the exam didn't celebrate in any of those restaurants and elected to stay home to prepare for their reexamination. However, this quickly bored Vasya and he started checking celebration photos on the Kilogramm. He found out that, in total, BugDonalds was visited by A students, BeaverKing β by B students and C students visited both restaurants. Vasya also knows that there are N students in his group.
Based on this info, Vasya wants to determine either if his data contradicts itself or, if it doesn't, how many students in his group didn't pass the exam. Can you help him so he won't waste his valuable preparation time?
Input
The first line contains four integers β A, B, C and N (0 β€ A, B, C, N β€ 100).
Output
If a distribution of N students exists in which A students visited BugDonalds, B β BeaverKing, C β both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer β amount of students (including Vasya) who did not pass the exam.
If such a distribution does not exist and Vasya made a mistake while determining the numbers A, B, C or N (as in samples 2 and 3), output -1.
Examples
Input
10 10 5 20
Output
5
Input
2 2 0 4
Output
-1
Input
2 2 2 1
Output
-1
Note
The first sample describes following situation: 5 only visited BugDonalds, 5 students only visited BeaverKing, 5 visited both of them and 5 students (including Vasya) didn't pass the exam.
In the second sample 2 students only visited BugDonalds and 2 only visited BeaverKing, but that means all 4 students in group passed the exam which contradicts the fact that Vasya didn't pass meaning that this situation is impossible.
The third sample describes a situation where 2 students visited BugDonalds but the group has only 1 which makes it clearly impossible.
Submitted Solution:
```
raw = input().split(" ")
A = int(raw[0])
B = int(raw[1])
C = int(raw[2])
N = int(raw[3])
if A + B - C > N -1:
print(-1)
exit()
if A < C or B < C:
print(-1)
exit()
justA = A - C
justB = B - C
stayedHome = N - justA - justB - C
if stayedHome > 0 and stayedHome < 101:
print(stayedHome)
else:
print(-1)
``` | instruction | 0 | 38,320 | 17 | 76,640 |
Yes | output | 1 | 38,320 | 17 | 76,641 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.
Some of them celebrated in the BugDonalds restaurant, some of them β in the BeaverKing restaurant, the most successful ones were fast enough to celebrate in both of restaurants. Students which didn't pass the exam didn't celebrate in any of those restaurants and elected to stay home to prepare for their reexamination. However, this quickly bored Vasya and he started checking celebration photos on the Kilogramm. He found out that, in total, BugDonalds was visited by A students, BeaverKing β by B students and C students visited both restaurants. Vasya also knows that there are N students in his group.
Based on this info, Vasya wants to determine either if his data contradicts itself or, if it doesn't, how many students in his group didn't pass the exam. Can you help him so he won't waste his valuable preparation time?
Input
The first line contains four integers β A, B, C and N (0 β€ A, B, C, N β€ 100).
Output
If a distribution of N students exists in which A students visited BugDonalds, B β BeaverKing, C β both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer β amount of students (including Vasya) who did not pass the exam.
If such a distribution does not exist and Vasya made a mistake while determining the numbers A, B, C or N (as in samples 2 and 3), output -1.
Examples
Input
10 10 5 20
Output
5
Input
2 2 0 4
Output
-1
Input
2 2 2 1
Output
-1
Note
The first sample describes following situation: 5 only visited BugDonalds, 5 students only visited BeaverKing, 5 visited both of them and 5 students (including Vasya) didn't pass the exam.
In the second sample 2 students only visited BugDonalds and 2 only visited BeaverKing, but that means all 4 students in group passed the exam which contradicts the fact that Vasya didn't pass meaning that this situation is impossible.
The third sample describes a situation where 2 students visited BugDonalds but the group has only 1 which makes it clearly impossible.
Submitted Solution:
```
# Codeforces Round #491 (Div. 2)
import collections
from functools import cmp_to_key
#key=cmp_to_key(lambda x,y: 1 if x not in y else -1 )
import math
import sys
def getIntList():
return list(map(int, input().split()))
import bisect
try :
import numpy
dprint = print
dprint('debug mode')
except ModuleNotFoundError:
def dprint(*args, **kwargs):
pass
def makePair(z):
return [(z[i], z[i+1]) for i in range(0,len(z),2) ]
A,B,C,N = getIntList()
if A<C or B<C:
print(-1)
sys.exit()
z = A+B - C
if z+1> N:
print(-1)
sys.exit()
print(N-z)
``` | instruction | 0 | 38,321 | 17 | 76,642 |
Yes | output | 1 | 38,321 | 17 | 76,643 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.
Some of them celebrated in the BugDonalds restaurant, some of them β in the BeaverKing restaurant, the most successful ones were fast enough to celebrate in both of restaurants. Students which didn't pass the exam didn't celebrate in any of those restaurants and elected to stay home to prepare for their reexamination. However, this quickly bored Vasya and he started checking celebration photos on the Kilogramm. He found out that, in total, BugDonalds was visited by A students, BeaverKing β by B students and C students visited both restaurants. Vasya also knows that there are N students in his group.
Based on this info, Vasya wants to determine either if his data contradicts itself or, if it doesn't, how many students in his group didn't pass the exam. Can you help him so he won't waste his valuable preparation time?
Input
The first line contains four integers β A, B, C and N (0 β€ A, B, C, N β€ 100).
Output
If a distribution of N students exists in which A students visited BugDonalds, B β BeaverKing, C β both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer β amount of students (including Vasya) who did not pass the exam.
If such a distribution does not exist and Vasya made a mistake while determining the numbers A, B, C or N (as in samples 2 and 3), output -1.
Examples
Input
10 10 5 20
Output
5
Input
2 2 0 4
Output
-1
Input
2 2 2 1
Output
-1
Note
The first sample describes following situation: 5 only visited BugDonalds, 5 students only visited BeaverKing, 5 visited both of them and 5 students (including Vasya) didn't pass the exam.
In the second sample 2 students only visited BugDonalds and 2 only visited BeaverKing, but that means all 4 students in group passed the exam which contradicts the fact that Vasya didn't pass meaning that this situation is impossible.
The third sample describes a situation where 2 students visited BugDonalds but the group has only 1 which makes it clearly impossible.
Submitted Solution:
```
a, b, c, n = list(map(int, input().split()))
out = n - a - b + c
if not out > 0 or not 0 <= c <= min(a, b) or not 1 <= n:
print("-1")
else:
print(out)
``` | instruction | 0 | 38,322 | 17 | 76,644 |
Yes | output | 1 | 38,322 | 17 | 76,645 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.
Some of them celebrated in the BugDonalds restaurant, some of them β in the BeaverKing restaurant, the most successful ones were fast enough to celebrate in both of restaurants. Students which didn't pass the exam didn't celebrate in any of those restaurants and elected to stay home to prepare for their reexamination. However, this quickly bored Vasya and he started checking celebration photos on the Kilogramm. He found out that, in total, BugDonalds was visited by A students, BeaverKing β by B students and C students visited both restaurants. Vasya also knows that there are N students in his group.
Based on this info, Vasya wants to determine either if his data contradicts itself or, if it doesn't, how many students in his group didn't pass the exam. Can you help him so he won't waste his valuable preparation time?
Input
The first line contains four integers β A, B, C and N (0 β€ A, B, C, N β€ 100).
Output
If a distribution of N students exists in which A students visited BugDonalds, B β BeaverKing, C β both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer β amount of students (including Vasya) who did not pass the exam.
If such a distribution does not exist and Vasya made a mistake while determining the numbers A, B, C or N (as in samples 2 and 3), output -1.
Examples
Input
10 10 5 20
Output
5
Input
2 2 0 4
Output
-1
Input
2 2 2 1
Output
-1
Note
The first sample describes following situation: 5 only visited BugDonalds, 5 students only visited BeaverKing, 5 visited both of them and 5 students (including Vasya) didn't pass the exam.
In the second sample 2 students only visited BugDonalds and 2 only visited BeaverKing, but that means all 4 students in group passed the exam which contradicts the fact that Vasya didn't pass meaning that this situation is impossible.
The third sample describes a situation where 2 students visited BugDonalds but the group has only 1 which makes it clearly impossible.
Submitted Solution:
```
a,b,c,n = map(int,input().split())
if (a+b-c+1 > n) or (c > a) or (c > b):
print(-1)
else:
print(n-(a+b-c))
``` | instruction | 0 | 38,323 | 17 | 76,646 |
Yes | output | 1 | 38,323 | 17 | 76,647 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.
Some of them celebrated in the BugDonalds restaurant, some of them β in the BeaverKing restaurant, the most successful ones were fast enough to celebrate in both of restaurants. Students which didn't pass the exam didn't celebrate in any of those restaurants and elected to stay home to prepare for their reexamination. However, this quickly bored Vasya and he started checking celebration photos on the Kilogramm. He found out that, in total, BugDonalds was visited by A students, BeaverKing β by B students and C students visited both restaurants. Vasya also knows that there are N students in his group.
Based on this info, Vasya wants to determine either if his data contradicts itself or, if it doesn't, how many students in his group didn't pass the exam. Can you help him so he won't waste his valuable preparation time?
Input
The first line contains four integers β A, B, C and N (0 β€ A, B, C, N β€ 100).
Output
If a distribution of N students exists in which A students visited BugDonalds, B β BeaverKing, C β both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer β amount of students (including Vasya) who did not pass the exam.
If such a distribution does not exist and Vasya made a mistake while determining the numbers A, B, C or N (as in samples 2 and 3), output -1.
Examples
Input
10 10 5 20
Output
5
Input
2 2 0 4
Output
-1
Input
2 2 2 1
Output
-1
Note
The first sample describes following situation: 5 only visited BugDonalds, 5 students only visited BeaverKing, 5 visited both of them and 5 students (including Vasya) didn't pass the exam.
In the second sample 2 students only visited BugDonalds and 2 only visited BeaverKing, but that means all 4 students in group passed the exam which contradicts the fact that Vasya didn't pass meaning that this situation is impossible.
The third sample describes a situation where 2 students visited BugDonalds but the group has only 1 which makes it clearly impossible.
Submitted Solution:
```
a,b,c,n=map(int,input().split())
x=a+b-c
if(n-x>=1 and a<=n and b<=n and c<=n and a+b-c<=n and a-c<=n and b-c<=n):
print(n-x)
else:
print(-1)
``` | instruction | 0 | 38,324 | 17 | 76,648 |
No | output | 1 | 38,324 | 17 | 76,649 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.
Some of them celebrated in the BugDonalds restaurant, some of them β in the BeaverKing restaurant, the most successful ones were fast enough to celebrate in both of restaurants. Students which didn't pass the exam didn't celebrate in any of those restaurants and elected to stay home to prepare for their reexamination. However, this quickly bored Vasya and he started checking celebration photos on the Kilogramm. He found out that, in total, BugDonalds was visited by A students, BeaverKing β by B students and C students visited both restaurants. Vasya also knows that there are N students in his group.
Based on this info, Vasya wants to determine either if his data contradicts itself or, if it doesn't, how many students in his group didn't pass the exam. Can you help him so he won't waste his valuable preparation time?
Input
The first line contains four integers β A, B, C and N (0 β€ A, B, C, N β€ 100).
Output
If a distribution of N students exists in which A students visited BugDonalds, B β BeaverKing, C β both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer β amount of students (including Vasya) who did not pass the exam.
If such a distribution does not exist and Vasya made a mistake while determining the numbers A, B, C or N (as in samples 2 and 3), output -1.
Examples
Input
10 10 5 20
Output
5
Input
2 2 0 4
Output
-1
Input
2 2 2 1
Output
-1
Note
The first sample describes following situation: 5 only visited BugDonalds, 5 students only visited BeaverKing, 5 visited both of them and 5 students (including Vasya) didn't pass the exam.
In the second sample 2 students only visited BugDonalds and 2 only visited BeaverKing, but that means all 4 students in group passed the exam which contradicts the fact that Vasya didn't pass meaning that this situation is impossible.
The third sample describes a situation where 2 students visited BugDonalds but the group has only 1 which makes it clearly impossible.
Submitted Solution:
```
in_put = input().split()
A, B, C, N = int(in_put[0]), int(in_put[1]), int(in_put[2]), int(in_put[3])
if N <= A or N <= B:
print(-1)
elif (A - C < 0) or (B - C < 0):
print(-1)
elif (C != 0) and (A == 0 or B == 0):
print(-1)
elif C == 0 and N <= A+B:
print(-1)
elif C != 0 and N <= (A-C) + (B-C):
print(-1)
elif C == 0 and N > A + B:
print(N-A-B)
elif C != 0 and N > (A-C) + (B-C):
print(N-(A+B-C))
``` | instruction | 0 | 38,325 | 17 | 76,650 |
No | output | 1 | 38,325 | 17 | 76,651 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.
Some of them celebrated in the BugDonalds restaurant, some of them β in the BeaverKing restaurant, the most successful ones were fast enough to celebrate in both of restaurants. Students which didn't pass the exam didn't celebrate in any of those restaurants and elected to stay home to prepare for their reexamination. However, this quickly bored Vasya and he started checking celebration photos on the Kilogramm. He found out that, in total, BugDonalds was visited by A students, BeaverKing β by B students and C students visited both restaurants. Vasya also knows that there are N students in his group.
Based on this info, Vasya wants to determine either if his data contradicts itself or, if it doesn't, how many students in his group didn't pass the exam. Can you help him so he won't waste his valuable preparation time?
Input
The first line contains four integers β A, B, C and N (0 β€ A, B, C, N β€ 100).
Output
If a distribution of N students exists in which A students visited BugDonalds, B β BeaverKing, C β both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer β amount of students (including Vasya) who did not pass the exam.
If such a distribution does not exist and Vasya made a mistake while determining the numbers A, B, C or N (as in samples 2 and 3), output -1.
Examples
Input
10 10 5 20
Output
5
Input
2 2 0 4
Output
-1
Input
2 2 2 1
Output
-1
Note
The first sample describes following situation: 5 only visited BugDonalds, 5 students only visited BeaverKing, 5 visited both of them and 5 students (including Vasya) didn't pass the exam.
In the second sample 2 students only visited BugDonalds and 2 only visited BeaverKing, but that means all 4 students in group passed the exam which contradicts the fact that Vasya didn't pass meaning that this situation is impossible.
The third sample describes a situation where 2 students visited BugDonalds but the group has only 1 which makes it clearly impossible.
Submitted Solution:
```
a, b, c, n = map(int, input().split())
passed = a + b - c
if passed < n:
print(n - passed)
else:
print(-1)
``` | instruction | 0 | 38,326 | 17 | 76,652 |
No | output | 1 | 38,326 | 17 | 76,653 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.
Some of them celebrated in the BugDonalds restaurant, some of them β in the BeaverKing restaurant, the most successful ones were fast enough to celebrate in both of restaurants. Students which didn't pass the exam didn't celebrate in any of those restaurants and elected to stay home to prepare for their reexamination. However, this quickly bored Vasya and he started checking celebration photos on the Kilogramm. He found out that, in total, BugDonalds was visited by A students, BeaverKing β by B students and C students visited both restaurants. Vasya also knows that there are N students in his group.
Based on this info, Vasya wants to determine either if his data contradicts itself or, if it doesn't, how many students in his group didn't pass the exam. Can you help him so he won't waste his valuable preparation time?
Input
The first line contains four integers β A, B, C and N (0 β€ A, B, C, N β€ 100).
Output
If a distribution of N students exists in which A students visited BugDonalds, B β BeaverKing, C β both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer β amount of students (including Vasya) who did not pass the exam.
If such a distribution does not exist and Vasya made a mistake while determining the numbers A, B, C or N (as in samples 2 and 3), output -1.
Examples
Input
10 10 5 20
Output
5
Input
2 2 0 4
Output
-1
Input
2 2 2 1
Output
-1
Note
The first sample describes following situation: 5 only visited BugDonalds, 5 students only visited BeaverKing, 5 visited both of them and 5 students (including Vasya) didn't pass the exam.
In the second sample 2 students only visited BugDonalds and 2 only visited BeaverKing, but that means all 4 students in group passed the exam which contradicts the fact that Vasya didn't pass meaning that this situation is impossible.
The third sample describes a situation where 2 students visited BugDonalds but the group has only 1 which makes it clearly impossible.
Submitted Solution:
```
(a, b, c, n) = map(int, input().split())
# a = int(input())
# b = int(input())
# c = int(input())
# n = int(input())
a -= c
b -= c
studentsAtHome = n - (a + b + c)
if studentsAtHome >= 1:
print(studentsAtHome)
else:
print(-1)
``` | instruction | 0 | 38,327 | 17 | 76,654 |
No | output | 1 | 38,327 | 17 | 76,655 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads a list of student test scores and evaluates the performance for each student.
The test scores for a student include scores of the midterm examination m (out of 50), the final examination f (out of 50) and the makeup examination r (out of 100). If the student does not take the examination, the score is indicated by -1.
The final performance of a student is evaluated by the following procedure:
* If the student does not take the midterm or final examination, the student's grade shall be F.
* If the total score of the midterm and final examination is greater than or equal to 80, the student's grade shall be A.
* If the total score of the midterm and final examination is greater than or equal to 65 and less than 80, the student's grade shall be B.
* If the total score of the midterm and final examination is greater than or equal to 50 and less than 65, the student's grade shall be C.
* If the total score of the midterm and final examination is greater than or equal to 30 and less than 50, the student's grade shall be D. However, if the score of the makeup examination is greater than or equal to 50, the grade shall be C.
* If the total score of the midterm and final examination is less than 30, the student's grade shall be F.
Input
The input consists of multiple datasets. For each dataset, three integers m, f and r are given in a line.
The input ends with three -1 for m, f and r respectively. Your program should not process for the terminal symbols.
The number of datasets (the number of students) does not exceed 50.
Output
For each dataset, print the grade (A, B, C, D or F) in a line.
Example
Input
40 42 -1
20 30 -1
0 2 -1
-1 -1 -1
Output
A
C
F | instruction | 0 | 38,586 | 17 | 77,172 |
"Correct Solution:
```
p=print
while 1:
m,f,r=map(int,input().split())
x=m+f
if m==f==r==-1:break
elif m==-1 or f==-1 or x<30:p('F')
elif x>=80:p('A')
elif 65<=x<80:p('B')
elif 50<=x<65 or r>=50:p('C')
else:p('D')
``` | output | 1 | 38,586 | 17 | 77,173 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads a list of student test scores and evaluates the performance for each student.
The test scores for a student include scores of the midterm examination m (out of 50), the final examination f (out of 50) and the makeup examination r (out of 100). If the student does not take the examination, the score is indicated by -1.
The final performance of a student is evaluated by the following procedure:
* If the student does not take the midterm or final examination, the student's grade shall be F.
* If the total score of the midterm and final examination is greater than or equal to 80, the student's grade shall be A.
* If the total score of the midterm and final examination is greater than or equal to 65 and less than 80, the student's grade shall be B.
* If the total score of the midterm and final examination is greater than or equal to 50 and less than 65, the student's grade shall be C.
* If the total score of the midterm and final examination is greater than or equal to 30 and less than 50, the student's grade shall be D. However, if the score of the makeup examination is greater than or equal to 50, the grade shall be C.
* If the total score of the midterm and final examination is less than 30, the student's grade shall be F.
Input
The input consists of multiple datasets. For each dataset, three integers m, f and r are given in a line.
The input ends with three -1 for m, f and r respectively. Your program should not process for the terminal symbols.
The number of datasets (the number of students) does not exceed 50.
Output
For each dataset, print the grade (A, B, C, D or F) in a line.
Example
Input
40 42 -1
20 30 -1
0 2 -1
-1 -1 -1
Output
A
C
F | instruction | 0 | 38,587 | 17 | 77,174 |
"Correct Solution:
```
m, f, r = map(int, input().split())
while m != -1 or f != -1 or r != -1:
if m == -1 or f == -1:
print("F")
elif m + f >= 80:
print("A")
elif m + f >= 65:
print("B")
elif m + f >= 50:
print("C")
elif m + f >= 30:
if r >= 50:
print("C")
else:
print("D")
else:
print("F")
m, f, r = map(int, input().split())
``` | output | 1 | 38,587 | 17 | 77,175 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads a list of student test scores and evaluates the performance for each student.
The test scores for a student include scores of the midterm examination m (out of 50), the final examination f (out of 50) and the makeup examination r (out of 100). If the student does not take the examination, the score is indicated by -1.
The final performance of a student is evaluated by the following procedure:
* If the student does not take the midterm or final examination, the student's grade shall be F.
* If the total score of the midterm and final examination is greater than or equal to 80, the student's grade shall be A.
* If the total score of the midterm and final examination is greater than or equal to 65 and less than 80, the student's grade shall be B.
* If the total score of the midterm and final examination is greater than or equal to 50 and less than 65, the student's grade shall be C.
* If the total score of the midterm and final examination is greater than or equal to 30 and less than 50, the student's grade shall be D. However, if the score of the makeup examination is greater than or equal to 50, the grade shall be C.
* If the total score of the midterm and final examination is less than 30, the student's grade shall be F.
Input
The input consists of multiple datasets. For each dataset, three integers m, f and r are given in a line.
The input ends with three -1 for m, f and r respectively. Your program should not process for the terminal symbols.
The number of datasets (the number of students) does not exceed 50.
Output
For each dataset, print the grade (A, B, C, D or F) in a line.
Example
Input
40 42 -1
20 30 -1
0 2 -1
-1 -1 -1
Output
A
C
F | instruction | 0 | 38,588 | 17 | 77,176 |
"Correct Solution:
```
while True:
m, f, r = map(int, input().split())
if m == -1 and f == -1 and r == -1: break
sec = m + f
if m < 0 or f < 0: print("F")
elif sec >= 80: print("A")
elif sec >= 65: print("B")
elif sec >= 50: print("C")
elif sec >= 30:
if r >= 50:
print("C")
else: print("D")
else: print("F")
``` | output | 1 | 38,588 | 17 | 77,177 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads a list of student test scores and evaluates the performance for each student.
The test scores for a student include scores of the midterm examination m (out of 50), the final examination f (out of 50) and the makeup examination r (out of 100). If the student does not take the examination, the score is indicated by -1.
The final performance of a student is evaluated by the following procedure:
* If the student does not take the midterm or final examination, the student's grade shall be F.
* If the total score of the midterm and final examination is greater than or equal to 80, the student's grade shall be A.
* If the total score of the midterm and final examination is greater than or equal to 65 and less than 80, the student's grade shall be B.
* If the total score of the midterm and final examination is greater than or equal to 50 and less than 65, the student's grade shall be C.
* If the total score of the midterm and final examination is greater than or equal to 30 and less than 50, the student's grade shall be D. However, if the score of the makeup examination is greater than or equal to 50, the grade shall be C.
* If the total score of the midterm and final examination is less than 30, the student's grade shall be F.
Input
The input consists of multiple datasets. For each dataset, three integers m, f and r are given in a line.
The input ends with three -1 for m, f and r respectively. Your program should not process for the terminal symbols.
The number of datasets (the number of students) does not exceed 50.
Output
For each dataset, print the grade (A, B, C, D or F) in a line.
Example
Input
40 42 -1
20 30 -1
0 2 -1
-1 -1 -1
Output
A
C
F | instruction | 0 | 38,589 | 17 | 77,178 |
"Correct Solution:
```
for i in range(50):
m,f,r = map(int,input().split())
if m == f == r == -1:
break
if m == -1 or f == -1 or m+f < 30:
print("F")
elif m+f >= 80:
print("A")
elif m+f >= 65:
print("B")
elif m+f >= 50 or r >= 50:
print("C")
else:
print("D")
``` | output | 1 | 38,589 | 17 | 77,179 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads a list of student test scores and evaluates the performance for each student.
The test scores for a student include scores of the midterm examination m (out of 50), the final examination f (out of 50) and the makeup examination r (out of 100). If the student does not take the examination, the score is indicated by -1.
The final performance of a student is evaluated by the following procedure:
* If the student does not take the midterm or final examination, the student's grade shall be F.
* If the total score of the midterm and final examination is greater than or equal to 80, the student's grade shall be A.
* If the total score of the midterm and final examination is greater than or equal to 65 and less than 80, the student's grade shall be B.
* If the total score of the midterm and final examination is greater than or equal to 50 and less than 65, the student's grade shall be C.
* If the total score of the midterm and final examination is greater than or equal to 30 and less than 50, the student's grade shall be D. However, if the score of the makeup examination is greater than or equal to 50, the grade shall be C.
* If the total score of the midterm and final examination is less than 30, the student's grade shall be F.
Input
The input consists of multiple datasets. For each dataset, three integers m, f and r are given in a line.
The input ends with three -1 for m, f and r respectively. Your program should not process for the terminal symbols.
The number of datasets (the number of students) does not exceed 50.
Output
For each dataset, print the grade (A, B, C, D or F) in a line.
Example
Input
40 42 -1
20 30 -1
0 2 -1
-1 -1 -1
Output
A
C
F | instruction | 0 | 38,590 | 17 | 77,180 |
"Correct Solution:
```
def result(_m, _f, _r):
if _m==-1 or _f==-1: return "F"
elif _m+_f>=80: return "A"
elif _m+_f>=65: return "B"
elif _m+_f>=50: return "C"
elif _m+_f>=30 and _r>=50: return "C"
elif _m+_f>=30: return "D"
else: return "F"
while True:
m,f,r = map(int, input().split())
if m==-1 and f==-1 and r==-1: break
print(result(m,f,r))
``` | output | 1 | 38,590 | 17 | 77,181 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads a list of student test scores and evaluates the performance for each student.
The test scores for a student include scores of the midterm examination m (out of 50), the final examination f (out of 50) and the makeup examination r (out of 100). If the student does not take the examination, the score is indicated by -1.
The final performance of a student is evaluated by the following procedure:
* If the student does not take the midterm or final examination, the student's grade shall be F.
* If the total score of the midterm and final examination is greater than or equal to 80, the student's grade shall be A.
* If the total score of the midterm and final examination is greater than or equal to 65 and less than 80, the student's grade shall be B.
* If the total score of the midterm and final examination is greater than or equal to 50 and less than 65, the student's grade shall be C.
* If the total score of the midterm and final examination is greater than or equal to 30 and less than 50, the student's grade shall be D. However, if the score of the makeup examination is greater than or equal to 50, the grade shall be C.
* If the total score of the midterm and final examination is less than 30, the student's grade shall be F.
Input
The input consists of multiple datasets. For each dataset, three integers m, f and r are given in a line.
The input ends with three -1 for m, f and r respectively. Your program should not process for the terminal symbols.
The number of datasets (the number of students) does not exceed 50.
Output
For each dataset, print the grade (A, B, C, D or F) in a line.
Example
Input
40 42 -1
20 30 -1
0 2 -1
-1 -1 -1
Output
A
C
F | instruction | 0 | 38,591 | 17 | 77,182 |
"Correct Solution:
```
while True:
m,f,r=map(int,input().split())
if m==f and f==r and m==-1:
break
if m==-1 or f==-1:
print("F")
elif m+f>=80:
print("A")
elif m+f>=65:
print("B")
elif m+f>=50:
print("C")
elif m+f>=30:
if r>=50:
print("C")
else:
print("D")
else:
print("F")
``` | output | 1 | 38,591 | 17 | 77,183 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads a list of student test scores and evaluates the performance for each student.
The test scores for a student include scores of the midterm examination m (out of 50), the final examination f (out of 50) and the makeup examination r (out of 100). If the student does not take the examination, the score is indicated by -1.
The final performance of a student is evaluated by the following procedure:
* If the student does not take the midterm or final examination, the student's grade shall be F.
* If the total score of the midterm and final examination is greater than or equal to 80, the student's grade shall be A.
* If the total score of the midterm and final examination is greater than or equal to 65 and less than 80, the student's grade shall be B.
* If the total score of the midterm and final examination is greater than or equal to 50 and less than 65, the student's grade shall be C.
* If the total score of the midterm and final examination is greater than or equal to 30 and less than 50, the student's grade shall be D. However, if the score of the makeup examination is greater than or equal to 50, the grade shall be C.
* If the total score of the midterm and final examination is less than 30, the student's grade shall be F.
Input
The input consists of multiple datasets. For each dataset, three integers m, f and r are given in a line.
The input ends with three -1 for m, f and r respectively. Your program should not process for the terminal symbols.
The number of datasets (the number of students) does not exceed 50.
Output
For each dataset, print the grade (A, B, C, D or F) in a line.
Example
Input
40 42 -1
20 30 -1
0 2 -1
-1 -1 -1
Output
A
C
F | instruction | 0 | 38,592 | 17 | 77,184 |
"Correct Solution:
```
while True:
arr = list(map(int, input().split()))
m = arr[0]
f = arr[1]
r = arr[2]
if m == -1 and f == -1 and r == -1:
break
total = m + f
if m == -1 or f == -1: print('F')
elif total >= 80: print('A')
elif total >= 65: print('B')
elif total >= 50: print('C')
elif total >= 30 and r >= 50: print('C')
elif total >= 30: print('D')
else: print('F')
``` | output | 1 | 38,592 | 17 | 77,185 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads a list of student test scores and evaluates the performance for each student.
The test scores for a student include scores of the midterm examination m (out of 50), the final examination f (out of 50) and the makeup examination r (out of 100). If the student does not take the examination, the score is indicated by -1.
The final performance of a student is evaluated by the following procedure:
* If the student does not take the midterm or final examination, the student's grade shall be F.
* If the total score of the midterm and final examination is greater than or equal to 80, the student's grade shall be A.
* If the total score of the midterm and final examination is greater than or equal to 65 and less than 80, the student's grade shall be B.
* If the total score of the midterm and final examination is greater than or equal to 50 and less than 65, the student's grade shall be C.
* If the total score of the midterm and final examination is greater than or equal to 30 and less than 50, the student's grade shall be D. However, if the score of the makeup examination is greater than or equal to 50, the grade shall be C.
* If the total score of the midterm and final examination is less than 30, the student's grade shall be F.
Input
The input consists of multiple datasets. For each dataset, three integers m, f and r are given in a line.
The input ends with three -1 for m, f and r respectively. Your program should not process for the terminal symbols.
The number of datasets (the number of students) does not exceed 50.
Output
For each dataset, print the grade (A, B, C, D or F) in a line.
Example
Input
40 42 -1
20 30 -1
0 2 -1
-1 -1 -1
Output
A
C
F | instruction | 0 | 38,593 | 17 | 77,186 |
"Correct Solution:
```
while 1:
m,f,r = map(int,input().split())
if m == -1 and f == -1 and r == -1:
break
if m == -1 or f == -1:
print('F')
elif m+f>=80:
print('A')
elif m+f>=65 and m+f<80:
print('B')
elif m+f>=50 and m+f<65:
print('C')
elif m+f>=30 and m+f<50:
if r>=50:
print('C')
else:
print('D')
else:
print('F')
``` | output | 1 | 38,593 | 17 | 77,187 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered.
Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
Input
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x, y, r, where (x, y) are the coordinates of the stadium's center ( - 103 β€ x, y β€ 103), and r (1 β€ r β€ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
Output
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
Examples
Input
0 0 10
60 0 10
30 30 10
Output
30.00000 0.00000 | instruction | 0 | 38,981 | 17 | 77,962 |
Tags: geometry
Correct Solution:
```
__author__ = 'Eddie'
import sys
def get_filehandler(is_file):
if is_file:
return open(file="data")
else:
import sys
return sys.stdin
# custom starts
def get_weighted_distance(vertices, pfree):
return [((p[0] - pfree[0]) ** 2 + (p[1] - pfree[1]) ** 2) ** 0.5 / p[2] for p in vertices]
def get_error(distance):
p1, p2, p3 = distance
avg_p = (p1 + p2 + p3) / 3
return (avg_p - p1) ** 2 + (avg_p - p2) ** 2 + (avg_p - p3) ** 2
if __name__ == '__main__':
fh = get_filehandler(is_file=False)
# fh = get_filehandler(is_file=True)
vertices = [[float(x) for x in line] for line in map(str.split, fh.readlines())]
pfree = [sum([v[0] for v in vertices]) / 3, sum(v[1] for v in vertices) / 3]
error = get_error(get_weighted_distance(vertices, pfree))
d = 2
while True:
error = get_error(get_weighted_distance(vertices, pfree))
# print(error)
if error < 1E-8:
print("{:.5f} {:.5f}".format(pfree[0], pfree[1]))
break
if get_error(get_weighted_distance(vertices, (pfree[0] + d, pfree[1]))) < error:
pfree[0] += d
continue
if get_error(get_weighted_distance(vertices, (pfree[0] - d, pfree[1]))) < error:
pfree[0] -= d
continue
if get_error(get_weighted_distance(vertices, (pfree[0], pfree[1] + d))) < error:
pfree[1] += d
continue
if get_error(get_weighted_distance(vertices, (pfree[0], pfree[1] - d))) < error:
pfree[1] -= d
continue
d *= 0.5
if d < 1E-5:
break
``` | output | 1 | 38,981 | 17 | 77,963 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered.
Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
Input
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x, y, r, where (x, y) are the coordinates of the stadium's center ( - 103 β€ x, y β€ 103), and r (1 β€ r β€ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
Output
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
Examples
Input
0 0 10
60 0 10
30 30 10
Output
30.00000 0.00000 | instruction | 0 | 38,982 | 17 | 77,964 |
Tags: geometry
Correct Solution:
```
import math
pt = dict()
def dis(a, b):
return math.sqrt((a[0]-b[0])**2 + (a[1]-b[1])**2)
def cost(p, x, y):
ang = list()
for i in range(3): ang.append(dis(p[i], [x, y]) / p[i][2])
diff = list()
for i in range(3): diff.append(ang[i] - ang[(i+1)%3])
ret = 0;
for i in range(3): ret += diff[i] * diff[i]
return ret
dx = [0, 1, -1, 0]
dy = [1, 0, 0, -1]
err = 1e-6
if __name__ == '__main__':
p = list()
for i in range(3): p.append(list(float(x) for x in input().split(' ')))
ans = list()
ans.append((p[0][0] + p[1][0] + p[2][0]) / 3.0)
ans.append((p[0][1] + p[1][1] + p[2][1]) / 3.0)
ncost = cost(p, ans[0], ans[1])
tmp = [0, 0]
step = 1.0
flag = False; i = 0
while i < 300000 and ncost > err:
flag = False
for k in range(4):
tmp[0] = ans[0] + step * dx[k]
tmp[1] = ans[1] + step * dy[k]
if ncost > cost(p, tmp[0], tmp[1]):
ncost = cost(p, tmp[0], tmp[1])
ans = list(tmp)
flag = True
i+=1
if not flag: step *= 0.5
if cost(p, ans[0], ans[1]) <= err: print("{0} {1}".format(round(ans[0], 5), round(ans[1], 5)))
``` | output | 1 | 38,982 | 17 | 77,965 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered.
Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
Input
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x, y, r, where (x, y) are the coordinates of the stadium's center ( - 103 β€ x, y β€ 103), and r (1 β€ r β€ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
Output
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
Examples
Input
0 0 10
60 0 10
30 30 10
Output
30.00000 0.00000 | instruction | 0 | 38,983 | 17 | 77,966 |
Tags: geometry
Correct Solution:
```
from math import sqrt
def locus(s1, s2):
x1, y1, r1 = s1
x2, y2, r2 = s2
if r1 == r2:
k = False
m = x2 - x1
n = y2 - y1
e = m, n, -0.5 * (m * (x1 + x2) + n * (y1 + y2))
else:
k = True
m = r1 * r1
n = r2 * r2
d = m - n
e = ((m * x2 - n * x1) / d,
(m * y2 - n * y1) / d,
m * n * ((x1 - x2) ** 2 + (y1 - y2) ** 2) / (d * d))
return k, e
def zero(r, eps=1e-5):
return -eps < r < eps
def x_ll(e1, e2, p):
a1, b1, c1 = e1
a2, b2, c2 = e2
d = a1 * b2 - b1 * a2
if not zero(d):
p.append(((b1 * c2 - c1 * b2) / d, (c1 * a2 - a1 * c2) / d))
def x_lc(e1, e2, p):
a, b, c = e1
cx, cy, rr = e2
ab = a * a + b * b
xy = a * cx + b * cy + c
zz = xy / ab
dd = rr - xy * zz
px = cx - a * zz
py = cy - b * zz
if zero(dd):
p.append((px, py))
elif dd > 0.0:
t = sqrt(dd / ab)
ta = t * a
tb = t * b
p.extend([(px + tb, py - ta),
(px - tb, py + ta)])
def x_cc(e1, e2, p):
x1, y1, r1 = e1
x2, y2, r2 = e2
a = x2 - x1
b = y2 - y1
if (r1 + r2) ** 2 < (a * a + b * b):
return
c = -0.5 * (a * (x1 + x2) + b * (y1 + y2) + r1 - r2)
x_lc((a, b, c), e1, p)
def main():
s1, s2, s3 = (tuple(map(float, input().split())) for _ in range(3))
c1, eq1 = locus(s1, s2)
c2, eq2 = locus(s2, s3)
point = []
if c1 and c2:
x_cc(eq1, eq2, point)
elif c1:
x_lc(eq2, eq1, point)
elif c2:
x_lc(eq1, eq2, point)
else:
x_ll(eq1, eq2, point)
if point:
if len(point) == 1:
best = point[0]
else:
x, y, _ = s1
best = min(point,
key=lambda q: (q[0] - x) ** 2 + (q[1] - y) ** 2)
print("{:.5f} {:.5f}".format(*best))
if __name__ == '__main__':
main()
``` | output | 1 | 38,983 | 17 | 77,967 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered.
Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
Input
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x, y, r, where (x, y) are the coordinates of the stadium's center ( - 103 β€ x, y β€ 103), and r (1 β€ r β€ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
Output
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
Examples
Input
0 0 10
60 0 10
30 30 10
Output
30.00000 0.00000 | instruction | 0 | 38,984 | 17 | 77,968 |
Tags: geometry
Correct Solution:
```
V=[list(map(int,input().split())) for _ in range(3)]
a=[]
for i in range(3):
da=V[i][0]-V[(i+1)%3][0]
db=V[i][1]-V[(i+1)%3][1]
drs=V[i][2]**2-V[(i+1)%3][2]**2 #Let drs=0
das=(V[i][0]+V[(i+1)%3][0])*da
dbs=(V[i][1]+V[(i+1)%3][1])*db
a.append([2*da,2*db,drs,das+dbs])
def Gauss(n,m):
for i in range(n-1):
Max=i
for j in range(i,n):
if a[j][i]>a[Max][i]:
Max=j
for j in range(m):
a[i][j],a[Max][j]=a[Max][j],a[i][j]
if a[i][i]==0:
continue
for j in range(i+1,m):
a[i][j]/=a[i][i]
a[i][i]=1
for j in range(i+1,n):
tmp=a[j][i]/a[i][i]
for k in range(i,m):
a[j][k]-=tmp*a[i][k]
Gauss(3,4)
def gett(x,y):
a=V[0][0]
b=V[0][1]
r=V[0][2]
A=x[0]**2+y[0]**2
B=2*x[0]*(x[1]-a)+2*y[0]*(y[1]-b)-r*r
C=(x[1]-a)**2+(y[1]-b)**2
if A==0:
if B==0:
print()
exit(0)
else:
return C/B
delta=B**2-4*A*C
if delta<0:
print()
exit(0)
t1=(-B+delta**(1/2))/(2*A)
t2=(-B-delta**(1/2))/(2*A)
if min(t1,t2)>0:
return min(t1,t2)
elif max(t1,t2)<0:
print()
exit(0)
else:
return max(t1,t2)
if abs(a[2][2])<1e-7:
if abs(a[2][3])>1e-7:
print()
exit(0)
y=(-a[1][2],a[1][3])
x=(-a[0][2]+a[0][1]*a[1][2],a[0][3]-a[0][1]*a[1][3])
t=gett(x,y)
y=-a[1][2]*t+a[1][3]
x=(-a[0][2]+a[0][1]*a[1][2])*t+a[0][3]-a[0][1]*a[1][3]
print("%.5f %.5f" % (x,y))
else:
t=a[2][3]/a[2][2]
if a[1][1]==0 and a[1][3]-a[1][2]*t!=0:
print()
exit(0)
if a[1][1]==0:
y=0
else:
y=(a[1][3]-a[1][2]*t)/a[1][1]
if a[0][0]==0 and a[0][3]-a[0][2]*t-a[0][1]*y!=0:
print()
exit(0)
if a[0][0]==0:
x=0
else:
x=(a[0][3]-a[0][2]*t-a[0][1]*y)/a[0][0]
print("%.5f %.5f" % (x,y))
``` | output | 1 | 38,984 | 17 | 77,969 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered.
Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
Input
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x, y, r, where (x, y) are the coordinates of the stadium's center ( - 103 β€ x, y β€ 103), and r (1 β€ r β€ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
Output
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
Examples
Input
0 0 10
60 0 10
30 30 10
Output
30.00000 0.00000 | instruction | 0 | 38,985 | 17 | 77,970 |
Tags: geometry
Correct Solution:
```
__author__ = 'Eddie'
import sys
def get_filehandler(is_file):
if is_file:
return open(file="data")
else:
import sys
return sys.stdin
# custom starts
def get_weighted_distance(vertices, pfree):
return [((p[0] - pfree[0]) ** 2 + (p[1] - pfree[1]) ** 2) ** 0.5 / p[2] for p in vertices]
def get_error(distance):
p1, p2, p3 = distance
avg_p = (p1 + p2 + p3) / 3
return (avg_p - p1) ** 2 + (avg_p - p2) ** 2 + (avg_p - p3) ** 2
if __name__ == '__main__':
fh = get_filehandler(is_file=False)
# fh = get_filehandler(is_file=True)
vertices = [[float(x) for x in line] for line in map(str.split, fh.readlines())]
pfree = [sum([v[0] for v in vertices]) / 3, sum(v[1] for v in vertices) / 3]
error = get_error(get_weighted_distance(vertices, pfree))
d = 2
while True:
error = get_error(get_weighted_distance(vertices, pfree))
# print(error)
if error < 1E-8:
print("{:.5f} {:.5f}".format(pfree[0], pfree[1]))
break
if get_error(get_weighted_distance(vertices, (pfree[0] + d, pfree[1]))) < error:
pfree[0] += d
continue
if get_error(get_weighted_distance(vertices, (pfree[0] - d, pfree[1]))) < error:
pfree[0] -= d
continue
if get_error(get_weighted_distance(vertices, (pfree[0], pfree[1] + d))) < error:
pfree[1] += d
continue
if get_error(get_weighted_distance(vertices, (pfree[0], pfree[1] - d))) < error:
pfree[1] -= d
continue
d *= 0.5
if d < 1E-5:
break
# Made By Mostafa_Khaled
``` | output | 1 | 38,985 | 17 | 77,971 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered.
Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
Input
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x, y, r, where (x, y) are the coordinates of the stadium's center ( - 103 β€ x, y β€ 103), and r (1 β€ r β€ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
Output
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
Examples
Input
0 0 10
60 0 10
30 30 10
Output
30.00000 0.00000 | instruction | 0 | 38,986 | 17 | 77,972 |
Tags: geometry
Correct Solution:
```
import math
# compute distance between coordinates
def dis(a, b):
return math.sqrt((a[0]-b[0])**2 + (a[1]-b[1])**2)
def cost(p, x, y):
ang = list()
for i in range(3):
ang.append(dis(p[i], [x, y]) / p[i][2])
diff = list()
for i in range(3):
diff.append(ang[i] - ang[(i+1)%3])
ret = 0;
for i in range(3):
ret += diff[i] * diff[i]
return ret
dx = [0, 1, -1, 0]
dy = [1, 0, 0, -1]
err = 1e-6
if __name__ == '__main__':
p = list()
for i in range(3):
p.append(list(float(x) for x in input().split(' ')))
ans = list()
ans.append((p[0][0] + p[1][0] + p[2][0]) / 3.0)
ans.append((p[0][1] + p[1][1] + p[2][1]) / 3.0)
ncost = cost(p, ans[0], ans[1])
tmp = [0, 0]
step = 1.0
flag = False
i = 0
# approximate the cordinates
while i < 300000 and ncost > err:
flag = False
for k in range(4):
tmp[0] = ans[0] + step * dx[k]
tmp[1] = ans[1] + step * dy[k]
if ncost > cost(p, tmp[0], tmp[1]):
ncost = cost(p, tmp[0], tmp[1])
ans = list(tmp)
flag = True
i+=1
# reduce the tep by 1/2
if not flag:
step *= 0.5
# if found an answer
if cost(p, ans[0], ans[1]) <= err:
print("{0} {1}".format(round(ans[0], 5), round(ans[1], 5)))
``` | output | 1 | 38,986 | 17 | 77,973 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered.
Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
Input
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x, y, r, where (x, y) are the coordinates of the stadium's center ( - 103 β€ x, y β€ 103), and r (1 β€ r β€ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
Output
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
Examples
Input
0 0 10
60 0 10
30 30 10
Output
30.00000 0.00000 | instruction | 0 | 38,987 | 17 | 77,974 |
Tags: geometry
Correct Solution:
```
import math
x1, y1, r1 = [int(_) for _ in input().split()]
x2, y2, r2 = [int(_) for _ in input().split()]
x3, y3, r3 = [int(_) for _ in input().split()]
def get_line(p1, p2):
x1, y1 = p1
x2, y2 = p2
if x1 * y2 == x2 * y1:
c = 0
a = 1
if y1 != 0:
b = -x1 / y1
elif y2 != 0:
b = -x2 / y2
else:
a = 0
b = 1
return a, b, c
else:
c = 1
a = (y1 - y2) / (x1 * y2 - x2 * y1)
b = (x1 - x2) / (x2 * y1 - x1 * y2)
return a, b, c
def comm(x1, y1, r1, x2, y2, r2):
if r1 == r2:
a, b, c = get_line((x1, y1), (x2, y2))
return True, b, -a, a * (y1 + y2) / 2 - b * (x1 + x2) / 2
else:
c = r1 ** 2 / r2 ** 2
x = (c * x2 - x1) / (c - 1)
y = (c * y2 - y1) / (c - 1)
r = math.sqrt((c * (x1 - x2) ** 2 + c * (y1 - y2) ** 2) / (c - 1) ** 2)
return False, x, y, r
def get_angle(x, y, r, x0, y0):
# print(x, y, r, x0, y0)
dist = math.sqrt((x0 - x) ** 2 + (y0 - y) ** 2)
# print("DIST: ", dist)
# print("DIST: ", r / dist)
return math.asin(r / dist)
def get_points(a, b, c, x, y, r):
dist = abs(a * x + b * y + c) / math.sqrt(a ** 2 + b ** 2)
if dist <= r:
aa = (a ** 2 + b ** 2)
bb = 2 * a * b * y + 2 * a * c - 2 * b ** 2 * x
cc = b ** 2 * x ** 2 + (b * y + c) ** 2 - b ** 2 * r ** 2
delta = math.sqrt(bb ** 2 - 4 * aa * cc)
if delta == 0:
xx = -bb / 2 / aa
if b == 0:
yy = math.sqrt(r ** 2 - (xx - x) ** 2) + y
else:
yy = (-c - a * xx) / b
return 1, [(xx, yy)]
else:
xx1 = (-bb + delta) / 2 / aa
if b == 0:
tmp1 = math.sqrt(r ** 2 - (xx1 - x) ** 2) + y
tmp2 = -math.sqrt(r ** 2 - (xx1 - x) ** 2) + y
yy1 = 0
if abs(a * xx1 + b * tmp1 + c) <= 0.001:
yy1 = tmp1
if abs(a * xx1 + b * tmp2 + c) <= 0.001:
yy1 = tmp2
else:
yy1 = (-c - a * xx1) / b
xx2 = (-bb - delta) / 2 / aa
if b == 0:
tmp1 = math.sqrt(r ** 2 - (xx2 - x) ** 2) + y
tmp2 = -math.sqrt(r ** 2 - (xx2 - x) ** 2) + y
yy2 = 0
if abs(a * xx2 + b * tmp1 + c) <= 0.001:
yy2 = tmp1
if abs(a * xx2 + b * tmp2 + c) <= 0.001:
yy2 = tmp2
else:
yy2 = (-c - a * xx2) / b
return 2, [(xx1, yy1), (xx2, yy2)]
return 0, []
items1 = comm(x1, y1, r1, x2, y2, r2)
items2 = comm(x1, y1, r1, x3, y3, r3)
# print(items1)
# print(items2)
if not items1[0]:
items1, items2 = items2, items1
if items1[0] and items2[0]:
a1, b1, c1 = items1[1:]
a2, b2, c2 = items2[1:]
if a1 * b2 != a2 * b1:
print((b1 * c2 - b2 * c1) / (b2 * a1 - a2 * b1), (a1 * c2 - a2 * c1) / (a2 * b1 - a1 * b2))
elif items1[0] and not items2[0]:
a, b, c = items1[1:]
x, y, r = items2[1:]
num, points = get_points(a, b, c, x, y, r)
# print(num, points)
if num == 1:
print(points[0][0], points[0][1])
elif num == 2:
xx1, yy1 = points[0]
xx2, yy2 = points[1]
angle1 = get_angle(x1, y1, r1, xx1, yy1)
angle2 = get_angle(x1, y1, r1, xx2, yy2)
# print(angle1, angle2)
if angle1 >= angle2:
print(xx1, yy1)
else:
print(xx2, yy2)
else:
xx1, yy1, rr1 = items1[1:]
xx2, yy2, rr2 = items2[1:]
a, b, c = 2 * (xx1 - xx2), 2 * (yy1 - yy2), (xx2 ** 2 + yy2 ** 2 - rr2 ** 2) - (xx1 ** 2 + yy1 ** 2 - rr1 ** 2)
num, points = get_points(a, b, c, xx1, yy1, rr1)
# print(num, points)
if num == 1:
print(points[0][0], points[0][1])
elif num == 2:
xxx1, yyy1 = points[0]
xxx2, yyy2 = points[1]
angle1 = get_angle(x1, y1, r1, xxx1, yyy1)
angle2 = get_angle(x1, y1, r1, xxx2, yyy2)
if angle1 >= angle2:
print(xxx1, yyy1)
else:
print(xxx2, yyy2)
``` | output | 1 | 38,987 | 17 | 77,975 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered.
Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
Input
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x, y, r, where (x, y) are the coordinates of the stadium's center ( - 103 β€ x, y β€ 103), and r (1 β€ r β€ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
Output
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
Examples
Input
0 0 10
60 0 10
30 30 10
Output
30.00000 0.00000 | instruction | 0 | 38,988 | 17 | 77,976 |
Tags: geometry
Correct Solution:
```
# @auther: guoyc
# @date: 2018/7/18
import math
x1, y1, r1 = [int(_) for _ in input().split()]
x2, y2, r2 = [int(_) for _ in input().split()]
x3, y3, r3 = [int(_) for _ in input().split()]
def get_line(p1, p2):
x1, y1 = p1
x2, y2 = p2
if x1 * y2 == x2 * y1:
c = 0
a = 1
if y1 != 0:
b = -x1 / y1
elif y2 != 0:
b = -x2 / y2
else:
a = 0
b = 1
return a, b, c
else:
c = 1
a = (y1 - y2) / (x1 * y2 - x2 * y1)
b = (x1 - x2) / (x2 * y1 - x1 * y2)
return a, b, c
def comm(x1, y1, r1, x2, y2, r2):
if r1 == r2:
a, b, c = get_line((x1, y1), (x2, y2))
return True, b, -a, a * (y1 + y2) / 2 - b * (x1 + x2) / 2
else:
c = r1 ** 2 / r2 ** 2
x = (c * x2 - x1) / (c - 1)
y = (c * y2 - y1) / (c - 1)
r = math.sqrt((c * (x1 - x2) ** 2 + c * (y1 - y2) ** 2) / (c - 1) ** 2)
return False, x, y, r
def get_angle(x, y, r, x0, y0):
# print(x, y, r, x0, y0)
dist = math.sqrt((x0 - x) ** 2 + (y0 - y) ** 2)
# print("DIST: ", dist)
# print("DIST: ", r / dist)
return math.asin(r / dist)
def get_points(a, b, c, x, y, r):
dist = abs(a * x + b * y + c) / math.sqrt(a ** 2 + b ** 2)
if dist <= r:
aa = (a ** 2 + b ** 2)
bb = 2 * a * b * y + 2 * a * c - 2 * b ** 2 * x
cc = b ** 2 * x ** 2 + (b * y + c) ** 2 - b ** 2 * r ** 2
delta = math.sqrt(bb ** 2 - 4 * aa * cc)
if delta == 0:
xx = -bb / 2 / aa
if b == 0:
yy = math.sqrt(r ** 2 - (xx - x) ** 2) + y
else:
yy = (-c - a * xx) / b
return 1, [(xx, yy)]
else:
xx1 = (-bb + delta) / 2 / aa
if b == 0:
tmp1 = math.sqrt(r ** 2 - (xx1 - x) ** 2) + y
tmp2 = -math.sqrt(r ** 2 - (xx1 - x) ** 2) + y
yy1 = 0
if abs(a * xx1 + b * tmp1 + c) <= 0.001:
yy1 = tmp1
if abs(a * xx1 + b * tmp2 + c) <= 0.001:
yy1 = tmp2
else:
yy1 = (-c - a * xx1) / b
xx2 = (-bb - delta) / 2 / aa
if b == 0:
tmp1 = math.sqrt(r ** 2 - (xx2 - x) ** 2) + y
tmp2 = -math.sqrt(r ** 2 - (xx2 - x) ** 2) + y
yy2 = 0
if abs(a * xx2 + b * tmp1 + c) <= 0.001:
yy2 = tmp1
if abs(a * xx2 + b * tmp2 + c) <= 0.001:
yy2 = tmp2
else:
yy2 = (-c - a * xx2) / b
return 2, [(xx1, yy1), (xx2, yy2)]
return 0, []
items1 = comm(x1, y1, r1, x2, y2, r2)
items2 = comm(x1, y1, r1, x3, y3, r3)
# print(items1)
# print(items2)
if not items1[0]:
items1, items2 = items2, items1
if items1[0] and items2[0]:
a1, b1, c1 = items1[1:]
a2, b2, c2 = items2[1:]
if a1 * b2 != a2 * b1:
print((b1 * c2 - b2 * c1) / (b2 * a1 - a2 * b1), (a1 * c2 - a2 * c1) / (a2 * b1 - a1 * b2))
elif items1[0] and not items2[0]:
a, b, c = items1[1:]
x, y, r = items2[1:]
num, points = get_points(a, b, c, x, y, r)
# print(num, points)
if num == 1:
print(points[0][0], points[0][1])
elif num == 2:
xx1, yy1 = points[0]
xx2, yy2 = points[1]
angle1 = get_angle(x1, y1, r1, xx1, yy1)
angle2 = get_angle(x1, y1, r1, xx2, yy2)
# print(angle1, angle2)
if angle1 >= angle2:
print(xx1, yy1)
else:
print(xx2, yy2)
else:
xx1, yy1, rr1 = items1[1:]
xx2, yy2, rr2 = items2[1:]
a, b, c = 2 * (xx1 - xx2), 2 * (yy1 - yy2), (xx2 ** 2 + yy2 ** 2 - rr2 ** 2) - (xx1 ** 2 + yy1 ** 2 - rr1 ** 2)
num, points = get_points(a, b, c, xx1, yy1, rr1)
# print(num, points)
if num == 1:
print(points[0][0], points[0][1])
elif num == 2:
xxx1, yyy1 = points[0]
xxx2, yyy2 = points[1]
angle1 = get_angle(x1, y1, r1, xxx1, yyy1)
angle2 = get_angle(x1, y1, r1, xxx2, yyy2)
if angle1 >= angle2:
print(xxx1, yyy1)
else:
print(xxx2, yyy2)
``` | output | 1 | 38,988 | 17 | 77,977 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered.
Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
Input
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x, y, r, where (x, y) are the coordinates of the stadium's center ( - 103 β€ x, y β€ 103), and r (1 β€ r β€ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
Output
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
Examples
Input
0 0 10
60 0 10
30 30 10
Output
30.00000 0.00000
Submitted Solution:
```
import math
def winner(x):
scores = {}
for i in range(len(x)):
if x[i][0] in scores:
scores[x[i][0]] += x[i][1]
else:
scores[x[i][0]] = x[i][1]
s = max(scores.values())
ss = []
for i in scores:
if s == scores[i]:
ss.append(i)
if len(ss) == 1:
return ss[0]
cscores = {}
for i in ss:
cscores[i] = 0
scores = {}
for i in range(len(x)):
if x[i][0] in cscores:
cscores[x[i][0]] += x[i][1]
if cscores[x[i][0]] >= s:
return x[i][0]
# l = int(input())
# x = []
# for _ in range(l):
# a,b = input().split()
# x.append([a,int(b)])
# print(winner(x))
# n = int(input())
# dp_c = []
# dp_d = []
# x = []
# pZero = False
# a = 0
# b = 0
# for _ in range(n):
# c = []
# d = []
# for _ in range(n):
# c.append([0,0])
# d.append(['',''])
# dp_c.append(c)
# dp_d.append(d)
# x.append(list(map(int,input().split())))
# for i in range(n):
# for j in range(n):
# if x[i][j] == 0:
# pZero = True
# a = i
# b = j
# x[i][j] = 10
# t = x[i][j]
# while t%2 == 0:
# dp_c[i][j][0] += 1
# t = t//2
# while t%5 == 0:
# dp_c[i][j][1] += 1
# t = t//5
# if (i != 0) and (j != 0):
# if dp_c[i-1][j][0] < dp_c[i][j-1][0]:
# dp_c[i][j][0] += dp_c[i-1][j][0]
# dp_d[i][j][0] = dp_d[i-1][j][0] + 'D'
# else:
# dp_c[i][j][0] += dp_c[i][j-1][0]
# dp_d[i][j][0] = dp_d[i][j-1][0] + 'R'
# if dp_c[i-1][j][1] < dp_c[i][j-1][1]:
# dp_c[i][j][1] += dp_c[i-1][j][1]
# dp_d[i][j][1] = dp_d[i-1][j][1] + 'D'
# else:
# dp_c[i][j][1] += dp_c[i][j-1][1]
# dp_d[i][j][1] = dp_d[i][j-1][1] + 'R'
# elif i != 0:
# dp_c[i][j][0] += dp_c[i-1][j][0]
# dp_d[i][j][0] = dp_d[i-1][j][0] + 'D'
# dp_c[i][j][1] += dp_c[i-1][j][1]
# dp_d[i][j][1] = dp_d[i-1][j][1] + 'D'
# elif j != 0:
# dp_c[i][j][0] += dp_c[i][j-1][0]
# dp_d[i][j][0] = dp_d[i][j-1][0] + 'R'
# dp_c[i][j][1] += dp_c[i][j-1][1]
# dp_d[i][j][1] = dp_d[i][j-1][1] + 'R'
# zeros = min(dp_c[n-1][n-1])
# if (zeros > 1) and pZero:
# print(1)
# print('D'*a + 'R'*b + 'D'*(n-a-1) + 'R'*(n-b-1))
# else:
# print(zeros)
# if dp_c[n-1][n-1][0] < dp_c[n-1][n-1][1]:
# print(dp_d[n-1][n-1][0])
# else:
# print(dp_d[n-1][n-1][1])
def findcommentator(A,B,C):
bLine = A[2] == C[2]
cLine = A[2] == B[2]
a = (B[0]-C[0])**2 + (B[1]-C[1])**2
b = (A[0]-C[0])**2 + (A[1]-C[1])**2
c = (B[0]-A[0])**2 + (B[1]-A[1])**2
if bLine and cLine:
x = (a*(b+c-a)*A[0] + b*(a+c-b)*B[0] + c*(b+a-c)*C[0])/(a*(b+c-a) + b*(a+c-b) + c*(b+a-c))
y = (a*(b+c-a)*A[1] + b*(a+c-b)*B[1] + c*(b+a-c)*C[1])/(a*(b+c-a) + b*(a+c-b) + c*(b+a-c))
return (x,y)
a = math.sqrt(a)
b = math.sqrt(b)
c = math.sqrt(c)
if bLine:
D = [C[0]-A[0],C[1]-A[1],(A[0]**2+A[1]**2-C[0]**2-C[1]**2)/2]
C1 = [((A[2]**2)*B[0]-(B[2]**2)*A[0])/((A[2]**2-B[2]**2)), ((A[2]**2)*B[1]-(B[2]**2)*A[1])/((A[2]**2-B[2]**2)), abs(A[2]*B[2]*c/((A[2]**2-B[2]**2)))]
d = -1*(D[0]*C1[0]+D[1]*C1[1]+D[2])/math.sqrt(D[0]**2+D[1]**2)
F = [C1[0] + D[0]*d/math.sqrt(D[0]**2+D[1]**2), C1[1] + D[1]*d/math.sqrt(D[0]**2+D[1]**2)]
if d < C1[2]:
x = math.sqrt(C1[2]**2-d**2)
l = math.sqrt(D[0]**2 + D[1]**2)
P1 = [F[0]+x*D[1]/l,F[1]-x*D[0]/l]
P2 = [F[0]-x*D[1]/l,F[1]+x*D[0]/l]
if (P1[0]-A[0])**2 + (P1[1]-A[1])**2 > (P2[0]-A[0])**2 + (P2[1]-A[1])**2:
return (P2[0],P2[1])
else:
return (P1[0],P1[1])
elif cLine:
D = [B[0]-A[0],B[1]-A[1],(A[0]**2+A[1]**2-B[0]**2-B[1]**2)/2]
C1 = [((A[2]**2)*C[0]-(C[2]**2)*A[0])/((A[2]**2-C[2]**2)), ((A[2]**2)*C[1]-(C[2]**2)*A[1])/((A[2]**2-C[2]**2)), abs(A[2]*C[2]*b/((A[2]**2-C[2]**2)))]
d = -1*(D[0]*C1[0]+D[1]*C1[1]+D[2])/math.sqrt(D[0]**2+D[1]**2)
F = [C1[0] + D[0]*d/math.sqrt(D[0]**2+D[1]**2), C1[1] + D[1]*d/math.sqrt(D[0]**2+D[1]**2)]
if d < C1[2]:
x = math.sqrt(C1[2]**2-d**2)
l = math.sqrt(D[0]**2 + D[1]**2)
P1 = [F[0]+x*D[1]/l,F[1]-x*D[0]/l]
P2 = [F[0]-x*D[1]/l,F[1]+x*D[0]/l]
if (P1[0]-A[0])**2 + (P1[1]-A[1])**2 > (P2[0]-A[0])**2 + (P2[1]-A[1])**2:
return (P2[0],P2[1])
else:
return (P1[0],P1[1])
else:
C1 = [((A[2]**2)*B[0]-(B[2]**2)*A[0])/((A[2]**2-B[2]**2)), ((A[2]**2)*B[1]-(B[2]**2)*A[1])/((A[2]**2-B[2]**2)), abs(A[2]*B[2]*c/((A[2]**2-B[2]**2)))]
C2 = [((A[2]**2)*C[0]-(C[2]**2)*A[0])/((A[2]**2-C[2]**2)), ((A[2]**2)*C[1]-(C[2]**2)*A[1])/((A[2]**2-C[2]**2)), abs(A[2]*C[2]*b/((A[2]**2-C[2]**2)))]
d = math.sqrt((C1[0]-C2[0])**2 + (C1[1]-C2[1])**2)
if d <= C1[2]+C2[2]:
k = 0.5*(C1[2]**2-C2[2]**2)/d**2
P = [0.5*(C1[0]+C2[0])+k*(C2[0]-C1[0]), 0.5*(C1[1]+C2[1])+k*(C2[1]-C1[1])]
P1 = [0,0]
P2 = [0,0]
if 2*(C1[2]**2+C2[2]**2)/d**2 - (C1[2]**2-C2[2]**2)**2/d**4 - 1 < 0:
return None
k = 0.5*(math.sqrt(2*(C1[2]**2+C2[2]**2)/d**2 - (C1[2]**2-C2[2]**2)**2/d**4 - 1))
P1[0] = P[0] + k*(C2[1]-C1[1])
P2[0] = P[0] - k*(C2[1]-C1[1])
P1[1] = P[1] + k*(C1[0]-C2[0])
P2[1] = P[1] - k*(C1[0]-C2[0])
if (P1[0]-A[0])**2 + (P1[1]-A[1])**2 > (P2[0]-A[0])**2 + (P2[1]-A[1])**2:
return (P2[0],P2[1])
else:
return (P1[0],P1[1])
A = list(map(float,input().split()))
B = list(map(float,input().split()))
C = list(map(float,input().split()))
D = findcommentator(A,B,C)
if D != None:
print(*D)
``` | instruction | 0 | 38,989 | 17 | 77,978 |
Yes | output | 1 | 38,989 | 17 | 77,979 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered.
Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
Input
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x, y, r, where (x, y) are the coordinates of the stadium's center ( - 103 β€ x, y β€ 103), and r (1 β€ r β€ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
Output
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
Examples
Input
0 0 10
60 0 10
30 30 10
Output
30.00000 0.00000
Submitted Solution:
```
from math import sqrt
x = [0] * 3
y = [0] * 3
r = [0] * 3
for i in range(3):
x[i], y[i], r[i] = map(int, input().split())
traj = []
for i in range(2):
sc = r[i + 1]**2 - r[i]**2
xc = r[i + 1]**2 * x[i] - r[i]**2 * x[i + 1]
yc = r[i + 1]**2 * y[i] - r[i]**2 * y[i + 1]
fc = (x[i + 1] * r[i])**2 + (y[i + 1] * r[i])**2 - (x[i] * r[i + 1])**2 - (y[i] * r[i + 1])**2
if sc != 0:
xc /= sc
yc /= sc
fc /= sc
fc += xc**2 + yc**2
if fc < 0:
exit()
else:
xc *= -2
yc *= -2
traj.append([sc == 0, xc, yc, fc])
if not traj[0][0] and not traj[1][0]:
x0, y0, r0 = traj[0][1:]
x1, y1, r1 = traj[1][1:]
traj[0] = [True, 2 * (x1 - x0), 2 * (y1 - y0), r0 - r1 - x0**2 - y0**2 + x1**2 + y1**2]
if not traj[0][0]:
traj[0], traj[1] = traj[1], traj[0]
if traj[0][0] and traj[1][0]:
a0, b0, c0 = traj[0][1:]
a1, b1, c1 = traj[1][1:]
det = a0 * b1 - a1 * b0
if det != 0:
print('%.6f %.6f' % ((c0 * b1 - c1 * b0) / det, (a0 * c1 - a1 * c0) / det))
exit()
a0, b0, c0 = traj[0][1:]
x1, y1, r1 = traj[1][1:]
if (a0 * x1 + b0 * y1 - c0)**2 > r1 * (a0**2 + b0**2):
exit()
sdist = (a0 * x1 + b0 * y1 - c0) / (a0**2 + b0**2)
px, py = x1 - a0 * sdist, y1 - b0 * sdist
clen = sqrt(r1 - sdist * (a0 * x1 + b0 * y1 - c0))
nlen = sqrt(a0**2 + b0**2)
points = []
for mul in (-1, 1):
points.append((px + mul * b0 * clen / nlen, py - mul * a0 * clen / nlen))
if (points[0][0] - x[0])**2 + (points[0][1] - y[0])**2 > (points[1][0] - x[0])**2 + (points[1][1] - y[0])**2:
points[0], points[1] = points[1], points[0]
print('%.6f %.6f' % points[0])
``` | instruction | 0 | 38,990 | 17 | 77,980 |
Yes | output | 1 | 38,990 | 17 | 77,981 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered.
Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
Input
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x, y, r, where (x, y) are the coordinates of the stadium's center ( - 103 β€ x, y β€ 103), and r (1 β€ r β€ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
Output
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
Examples
Input
0 0 10
60 0 10
30 30 10
Output
30.00000 0.00000
Submitted Solution:
```
def diff(x):
d=[]
for y,z in a:
d.append(abs(x-y)/z)
ans=0
for i in range(3):
ans+=(d[i]-d[(i+1)%1])**2
return ans
def hillclimb(a):
x=0
s=1
for y,_ in a:
x+=y/3
while(s>1e-6):
d0=diff(x)
if(d0>diff(x+s)):
x+=s
elif(d0>diff(x-s)):
x-=s
elif(d0>diff(x+s*1j)):
x+=s*1j
elif(d0>diff(x-s*1j)):
x-=s*1j
else:
s*=0.5
return x if diff(x) < 1e-5 else None
a=[]
for i in range(3):
x,y,r=map(int,input().split())
a.append((x+y*1j,r))
answer=hillclimb(a)
if answer is not None:
print("{:.5f} {:.5f}".format(answer.real,answer.imag))
``` | instruction | 0 | 38,991 | 17 | 77,982 |
Yes | output | 1 | 38,991 | 17 | 77,983 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered.
Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
Input
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x, y, r, where (x, y) are the coordinates of the stadium's center ( - 103 β€ x, y β€ 103), and r (1 β€ r β€ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
Output
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
Examples
Input
0 0 10
60 0 10
30 30 10
Output
30.00000 0.00000
Submitted Solution:
```
from math import *
x1, y1, r1 = map(float, input().split())
x2, y2, r2 = map(float, input().split())
x3, y3, r3 = map(float, input().split())
x, y = (x1 + x2 + x3) / 3, (y1 + y2 + y3) / 3
def cost(a, b):
d1, d2, d3 = sqrt((x1 - a) ** 2 + (y1 - b) ** 2), sqrt((x2 - a) ** 2 + (y2 - b) ** 2), \
sqrt((x3 - a) ** 2 + (y3 - b) ** 2)
angle1, angle2, angle3 = d1 / r1, d2 / r2, d3 / r3
return (angle1 - angle2) ** 2 + (angle2 - angle3) ** 2 + (angle3 - angle1) ** 2
t = 1.0
while t > 1e-5:
if cost(x + t, y) < cost(x, y):
x += t
elif cost(x - t, y) < cost(x, y):
x -= t
elif cost(x, y + t) < cost(x, y):
y += t
elif cost(x, y - t) < cost(x, y):
y -= t
else:
t /= 2
if fabs(cost(x, y)) < 1e-5:
print('{:5f} {:5f}'.format(x, y))
``` | instruction | 0 | 38,992 | 17 | 77,984 |
Yes | output | 1 | 38,992 | 17 | 77,985 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered.
Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
Input
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x, y, r, where (x, y) are the coordinates of the stadium's center ( - 103 β€ x, y β€ 103), and r (1 β€ r β€ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
Output
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
Examples
Input
0 0 10
60 0 10
30 30 10
Output
30.00000 0.00000
Submitted Solution:
```
def hill_climbing(circles):
def diff(x):
d = []
for y, ry in circles:
d.append(abs(x - y) / ry)
ans = 0
for i in range(3):
ans += (d[i] - d[(i+1)%3])
return ans
x = 0
s = 1
for y, _ in circles:
x += y / 3
while s > 1e-6:
d0 = diff(x)
if d0 > diff(x + s): x += s
elif d0 > diff(x - s): x -= s
elif d0 > diff(x + s*1j): x += s*1j
elif d0 > diff(x - s*1j): x -= s*1j
else: s *= 0.7
return x if diff(x) < 1e-5 else None
if __name__ == '__main__' and '__file__' in globals():
circles = []
for _ in range(3):
x, y, r = map(int, input().split())
circles.append((x + y*1j, r))
ans = hill_climbing(circles)
if ans is not None:
print("{:.5f} {:.5f}".format(ans.real, ans.imag))
``` | instruction | 0 | 38,993 | 17 | 77,986 |
No | output | 1 | 38,993 | 17 | 77,987 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered.
Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
Input
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x, y, r, where (x, y) are the coordinates of the stadium's center ( - 103 β€ x, y β€ 103), and r (1 β€ r β€ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
Output
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
Examples
Input
0 0 10
60 0 10
30 30 10
Output
30.00000 0.00000
Submitted Solution:
```
import sys, math
# Gives the circle ((x,y),radius) that contains all points p such that
# (p-p1)/(p-p2) = r.
def apollonian_circle(p1,p2,r):
dx = p2[0] - p1[0]
x = p1[0] + (((r/(1+r)) + (r/(r-1)))/2) * dx
dy = p2[1] - p1[1]
y = p1[1] + (((r/(1+r)) + (r/(r-1)))/2) * dy
x_ = p1[0] + (r/(1+r)) * dx
y_ = p1[1] + (r/(1+r)) * dy
return ((x,y),math.sqrt(math.pow(x-x_,2)+math.pow(y-y_,2)))
# Find the points of intersection of circles with centers p1,p2 and radii
# r1, r2, respectively
def circle_intersections(p1,r1,p2,r2):
# Make a linear transformation that moves (p1,r1) to the unit circle
# and (p2,r2) onto the x-axis
dx = p2[0]-p1[0]
dy = p2[1]-p1[1]
theta = math.atan2(dy,dx)
r = r2/r1
x = (dx/r1 * math.cos(theta)) + (dy/r1 * math.sin(theta))
# A solution point forms a triangle with sides x, r, 1 with the centers of
# the new circles
if 1+x<r or 1+r<x: # Triangle inequality
return ()
# Law of cosines to get angle opposite to length r
alpha = math.acos((math.pow(x,2)+1-math.pow(r,2))/(2*x))
xsol = math.cos(alpha)
ysol = math.sin(alpha)
# Solutions q1,q2 are formed by undoing the transformations on (xsol,ysol),
# (xsol,-ysol)
q1x = p1[0] + (xsol*math.cos(theta)-ysol*math.sin(theta))*r1
q1y = p1[1] + (xsol*math.sin(theta)+ysol*math.cos(theta))*r1
q2x = p1[0] + (xsol*math.cos(theta)+ysol*math.sin(theta))*r1
q2y = p1[1] + (xsol*math.sin(theta)-ysol*math.cos(theta))*r1
return ((q1x,q1y),(q2x,q2y))
def dist(x1,y1,x2,y2):
return math.sqrt(math.pow(x1-x2,2)+math.pow(y1-y2,2))
def on_circle(center,radius,pt,tolerance=math.pow(10,-6)):
return abs(dist(center[0],center[1],pt[0],pt[1])-radius)<tolerance
c1 = tuple(map(int,sys.stdin.readline().split()))
c2 = tuple(map(int,sys.stdin.readline().split()))
c3 = tuple(map(int,sys.stdin.readline().split()))
p1 = c1[0:2]
p2 = c2[0:2]
p3 = c3[0:2]
r1 = c1[2]
r2 = c2[2]
r3 = c3[2]
numvalues = len(set([r1,r2,r3]))
if numvalues == 3:
ap1 = apollonian_circle(p1,p2,r1/r2)
ap2 = apollonian_circle(p2,p3,r2/r3)
ap3 = apollonian_circle(p3,p1,r3/r1)
pts_two = circle_intersections(ap1[0],ap1[1],ap2[0],ap2[1])
pts = []
for p in pts:
if on_circle(ap3[0],ap3[1],p):
pts.append(p)
if pts:
p = min(pts,key=lambda pt: dist(pt[0],pt[1],p1[0],p1[1]))
print(('%.5f' % p[0]) + ' ' + ('%.5f' % p[1]))
elif numvalues == 2:
tolerance = math.pow(10,-6)
if r1 == r2:
ap2 = apollonian_circle(p2,p3,r2/r3)
ap3 = apollonian_circle(p3,p1,r3/r1)
pts_two = circle_intersections(ap2[0],ap2[1],ap3[0],ap3[1])
pts = []
for p in pts_two:
diff = abs(dist(p[0],p[1],p1[0],p1[1])-dist(p[0],p[1],p2[0],p2[1]))
if diff < tolerance:
pts.append(p)
if pts:
p = min(pts,key=lambda pt: dist(pt[0],pt[1],p1[0],p1[1]))
print(('%.5f' % p[0]) + ' ' + ('%.5f' % p[1]))
elif r1 == r3:
ap2 = apollonian_circle(p2,p3,r2/r3)
ap1 = apollonian_circle(p1,p2,r1/r2)
pts = circle_intersections(ap2[0],ap2[1],ap1[0],ap1[1])
pts = []
for p in pts_two:
diff = abs(dist(p[0],p[1],p1[0],p1[1])-dist(p[0],p[1],p3[0],p3[1]))
if diff < tolerance:
pts.append(p)
if pts:
p = min(pts,key=lambda pt: dist(pt[0],pt[1],p1[0],p1[1]))
print(('%.5f' % p[0]) + ' ' + ('%.5f' % p[1]))
elif r2 == r3:
ap3 = apollonian_circle(p3,p1,r3/r1)
ap1 = apollonian_circle(p1,p2,r1/r2)
pts = circle_intersections(ap3[0],ap3[1],ap1[0],ap1[1])
pts = []
for p in pts_two:
diff = abs(dist(p[0],p[1],p2[0],p2[1])-dist(p[0],p[1],p3[0],p3[1]))
if diff < tolerance:
pts.append(p)
if pts:
p = min(pts,key=lambda pt: dist(pt[0],pt[1],p1[0],p1[1]))
print(('%.5f' % p[0]) + ' ' + ('%.5f' % p[1]))
elif numvalues == 1:
# circumcenter
# represent perp. bisectors as lines ax+by=c (where b is 1 or 0)
b1 = 0 if p1[1] == p2[1] else 1
a1 = 1 if b1 == 0 else (p2[0]-p1[0])/(p2[1]-p1[1])
c1 = a1 * ((p1[0]+p2[0])/2) + b1 * ((p1[1]+p2[1])/2)
b2 = 0 if p1[1] == p3[1] else 1
a2 = 1 if b2 == 0 else (p3[0]-p1[0])/(p3[1]-p1[1])
c2 = a2 * ((p1[0]+p3[0])/2) + b2 * ((p1[1]+p3[1])/2)
x = (c1*b2-b1*c2)/(a1*b2-b1*a2)
y = (a1*c2-c1*a2)/(a1*b2-b1*a2)
print(('%.5f' % x) + ' ' + ('%.5f' % y))
``` | instruction | 0 | 38,994 | 17 | 77,988 |
No | output | 1 | 38,994 | 17 | 77,989 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered.
Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
Input
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x, y, r, where (x, y) are the coordinates of the stadium's center ( - 103 β€ x, y β€ 103), and r (1 β€ r β€ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
Output
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
Examples
Input
0 0 10
60 0 10
30 30 10
Output
30.00000 0.00000
Submitted Solution:
```
V=[list(map(int,input().split())) for _ in range(3)]
a=[]
for i in range(3):
da=V[i][0]-V[(i+1)%3][0]
db=V[i][1]-V[(i+1)%3][1]
drs=V[i][2]**2-V[(i+1)%3][2]**2 #Let drs=0
das=(V[i][0]+V[(i+1)%3][0])*da
dbs=(V[i][1]+V[(i+1)%3][1])*db
a.append([2*da,2*db,drs,das+dbs])
def Gauss(n,m):
for i in range(n-1):
Max=i
for j in range(i,n):
if a[j][i]>a[Max][i]:
Max=j
for j in range(m):
a[i][j],a[Max][j]=a[Max][j],a[i][j]
if a[i][i]==0:
continue
for j in range(i+1,m):
a[i][j]/=a[i][i]
a[i][i]=1
for j in range(i+1,n):
tmp=a[j][i]/a[i][i]
for k in range(i,m):
a[j][k]-=tmp*a[i][k]
Gauss(3,4)
def gett(x,y):
a=V[0][0]
b=V[0][1]
r=V[0][2]
A=x[0]**2+y[0]**2
B=2*x[0]*(x[1]-a)+2*y[0]*(y[1]-b)-r*r
C=(x[1]-a)**2+(y[1]-b)**2
if A==0:
if B==0:
print(-1)
exit(0)
else:
return C/B
delta=B**2-4*A*C
if delta<0:
print(-1)
exit(0)
t1=(-B+delta**(1/2))/(2*A)
t2=(-B-delta**(1/2))/(2*A)
if min(t1,t2)>0:
return min(t1,t2)
elif max(t1,t2)<0:
print(-2)
print(-1)
exit(0)
else:
return max(t1,t2)
if a[2][2]==0:
if a[2][3]!=0:
print(-1)
exit(0)
y=(-a[1][2],a[1][3])
x=(-a[0][2]+a[0][1]*a[1][2],a[0][3]-a[0][1]*a[1][3])
t=gett(x,y)
y=-a[1][2]*t+a[1][3]
x=(-a[0][2]+a[0][1]*a[1][2])*t+a[0][3]-a[0][1]*a[1][3]
print("%.5f %.5f" % (x,y))
else:
t=a[2][3]/a[2][2]
if a[1][1]==0 and a[1][3]-a[1][2]*t!=0:
print(-1)
exit(0)
if a[1][1]==0:
y=0
else:
y=(a[1][3]-a[1][2]*t)/a[1][1]
if a[0][0]==0 and a[0][3]-a[0][2]*t-a[0][1]*y!=0:
print(-1)
exit(0)
if a[0][0]==0:
x=0
else:
x=(a[0][3]-a[0][2]*t-a[0][1]*y)/a[0][0]
print("%.5f %.5f" % (x,y))
``` | instruction | 0 | 38,995 | 17 | 77,990 |
No | output | 1 | 38,995 | 17 | 77,991 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered.
Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
Input
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x, y, r, where (x, y) are the coordinates of the stadium's center ( - 103 β€ x, y β€ 103), and r (1 β€ r β€ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
Output
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.
Examples
Input
0 0 10
60 0 10
30 30 10
Output
30.00000 0.00000
Submitted Solution:
```
V=[list(map(int,input().split())) for _ in range(3)]
a=[]
for i in range(3):
da=V[i][0]-V[(i+1)%3][0]
db=V[i][1]-V[(i+1)%3][1]
# drs=V[i][2]**2-V[(i+1)%3][2]**2
drs=0
das=(V[i][0]+V[(i+1)%3][0])*da
dbs=(V[i][1]+V[(i+1)%3][1])*db
a.append([2*da,2*db,drs,das+dbs])
def Gauss(n,m):
for i in range(n-1):
Max=i
for j in range(i,n):
if a[j][i]>a[Max][i]:
Max=j
for j in range(m):
a[i][j],a[Max][j]=a[Max][j],a[i][j]
if a[i][i]==0:
continue
for j in range(i+1,m):
a[i][j]/=a[i][i]
a[i][i]=1
for j in range(i+1,n):
tmp=a[j][i]/a[i][i]
for k in range(i,m):
a[j][k]-=tmp*a[i][k]
Gauss(3,4)
x,y,t=0,0,0
if a[2][2]==0 and a[2][3]!=0:
print(-1)
exit(0)
if a[2][2]==0:
t=0
else:
t=a[2][3]/a[2][2]
if a[1][1]==0 and a[1][2]*t!=a[1][3]:
print(-1)
exit(0)
if a[1][1]==0:
y=0
else:
y=(a[1][3]-a[1][2]*t)/a[1][1]
if a[0][0]==0 and a[0][1]*y+a[0][2]*t!=a[0][3]:
print(-1)
exit(0)
if a[0][0]==0:
x=0
else:
x=(a[0][3]-a[0][1]*y-a[0][2]*t)/a[0][0]
print("%.5f %.5f" % (x,y))
``` | instruction | 0 | 38,996 | 17 | 77,992 |
No | output | 1 | 38,996 | 17 | 77,993 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of n students (including Valera). This contest was an individual competition, so each student in the team solved problems individually.
After the contest was over, Valera was interested in results. He found out that:
* each student in the team scored at least l points and at most r points;
* in total, all members of the team scored exactly sall points;
* the total score of the k members of the team who scored the most points is equal to exactly sk; more formally, if a1, a2, ..., an is the sequence of points earned by the team of students in the non-increasing order (a1 β₯ a2 β₯ ... β₯ an), then sk = a1 + a2 + ... + ak.
However, Valera did not find out exactly how many points each of n students scored. Valera asked you to recover any distribution of scores between the students of the team, such that all the conditions above are met.
Input
The first line of the input contains exactly six integers n, k, l, r, sall, sk (1 β€ n, k, l, r β€ 1000; l β€ r; k β€ n; 1 β€ sk β€ sall β€ 106).
It's guaranteed that the input is such that the answer exists.
Output
Print exactly n integers a1, a2, ..., an β the number of points each student scored. If there are multiple solutions, you can print any of them. You can print the distribution of points in any order.
Examples
Input
5 3 1 3 13 9
Output
2 3 2 3 3
Input
5 3 1 3 15 9
Output
3 3 3 3 3 | instruction | 0 | 39,922 | 17 | 79,844 |
Tags: constructive algorithms, implementation, math
Correct Solution:
```
# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(10**8)
mod = 10 ** 9 + 7
mod1 = 998244353
# ------------------------------warmup----------------------------
import os
import sys
from io import BytesIO, IOBase
sys.setrecursionlimit(300000)
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# -------------------game starts now----------------------------------------------------import math
class TreeNode:
def __init__(self, k, v):
self.key = k
self.value = v
self.left = None
self.right = None
self.parent = None
self.height = 1
self.num_left = 1
self.num_total = 1
class AvlTree:
def __init__(self):
self._tree = None
def add(self, k, v):
if not self._tree:
self._tree = TreeNode(k, v)
return
node = self._add(k, v)
if node:
self._rebalance(node)
def _add(self, k, v):
node = self._tree
while node:
if k < node.key:
if node.left:
node = node.left
else:
node.left = TreeNode(k, v)
node.left.parent = node
return node.left
elif node.key < k:
if node.right:
node = node.right
else:
node.right = TreeNode(k, v)
node.right.parent = node
return node.right
else:
node.value = v
return
@staticmethod
def get_height(x):
return x.height if x else 0
@staticmethod
def get_num_total(x):
return x.num_total if x else 0
def _rebalance(self, node):
n = node
while n:
lh = self.get_height(n.left)
rh = self.get_height(n.right)
n.height = max(lh, rh) + 1
balance_factor = lh - rh
n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
n.num_left = 1 + self.get_num_total(n.left)
if balance_factor > 1:
if self.get_height(n.left.left) < self.get_height(n.left.right):
self._rotate_left(n.left)
self._rotate_right(n)
elif balance_factor < -1:
if self.get_height(n.right.right) < self.get_height(n.right.left):
self._rotate_right(n.right)
self._rotate_left(n)
else:
n = n.parent
def _remove_one(self, node):
"""
Side effect!!! Changes node. Node should have exactly one child
"""
replacement = node.left or node.right
if node.parent:
if AvlTree._is_left(node):
node.parent.left = replacement
else:
node.parent.right = replacement
replacement.parent = node.parent
node.parent = None
else:
self._tree = replacement
replacement.parent = None
node.left = None
node.right = None
node.parent = None
self._rebalance(replacement)
def _remove_leaf(self, node):
if node.parent:
if AvlTree._is_left(node):
node.parent.left = None
else:
node.parent.right = None
self._rebalance(node.parent)
else:
self._tree = None
node.parent = None
node.left = None
node.right = None
def remove(self, k):
node = self._get_node(k)
if not node:
return
if AvlTree._is_leaf(node):
self._remove_leaf(node)
return
if node.left and node.right:
nxt = AvlTree._get_next(node)
node.key = nxt.key
node.value = nxt.value
if self._is_leaf(nxt):
self._remove_leaf(nxt)
else:
self._remove_one(nxt)
self._rebalance(node)
else:
self._remove_one(node)
def get(self, k):
node = self._get_node(k)
return node.value if node else -1
def _get_node(self, k):
if not self._tree:
return None
node = self._tree
while node:
if k < node.key:
node = node.left
elif node.key < k:
node = node.right
else:
return node
return None
def get_at(self, pos):
x = pos + 1
node = self._tree
while node:
if x < node.num_left:
node = node.left
elif node.num_left < x:
x -= node.num_left
node = node.right
else:
return (node.key, node.value)
raise IndexError("Out of ranges")
@staticmethod
def _is_left(node):
return node.parent.left and node.parent.left == node
@staticmethod
def _is_leaf(node):
return node.left is None and node.right is None
def _rotate_right(self, node):
if not node.parent:
self._tree = node.left
node.left.parent = None
elif AvlTree._is_left(node):
node.parent.left = node.left
node.left.parent = node.parent
else:
node.parent.right = node.left
node.left.parent = node.parent
bk = node.left.right
node.left.right = node
node.parent = node.left
node.left = bk
if bk:
bk.parent = node
node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
node.num_left = 1 + self.get_num_total(node.left)
def _rotate_left(self, node):
if not node.parent:
self._tree = node.right
node.right.parent = None
elif AvlTree._is_left(node):
node.parent.left = node.right
node.right.parent = node.parent
else:
node.parent.right = node.right
node.right.parent = node.parent
bk = node.right.left
node.right.left = node
node.parent = node.right
node.right = bk
if bk:
bk.parent = node
node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
node.num_left = 1 + self.get_num_total(node.left)
@staticmethod
def _get_next(node):
if not node.right:
return node.parent
n = node.right
while n.left:
n = n.left
return n
# -----------------------------------------------binary seacrh tree---------------------------------------
class SegmentTree1:
def __init__(self, data, default=2**51, func=lambda a, b: a & b):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
# -------------------game starts now----------------------------------------------------import math
class SegmentTree:
def __init__(self, data, default=-10**9, func=lambda a, b: max(a , b)):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
# -------------------------------iye ha chutiya zindegi-------------------------------------
class Factorial:
def __init__(self, MOD):
self.MOD = MOD
self.factorials = [1, 1]
self.invModulos = [0, 1]
self.invFactorial_ = [1, 1]
def calc(self, n):
if n <= -1:
print("Invalid argument to calculate n!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.factorials):
return self.factorials[n]
nextArr = [0] * (n + 1 - len(self.factorials))
initialI = len(self.factorials)
prev = self.factorials[-1]
m = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = prev * i % m
self.factorials += nextArr
return self.factorials[n]
def inv(self, n):
if n <= -1:
print("Invalid argument to calculate n^(-1)")
print("n must be non-negative value. But the argument was " + str(n))
exit()
p = self.MOD
pi = n % p
if pi < len(self.invModulos):
return self.invModulos[pi]
nextArr = [0] * (n + 1 - len(self.invModulos))
initialI = len(self.invModulos)
for i in range(initialI, min(p, n + 1)):
next = -self.invModulos[p % i] * (p // i) % p
self.invModulos.append(next)
return self.invModulos[pi]
def invFactorial(self, n):
if n <= -1:
print("Invalid argument to calculate (n^(-1))!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.invFactorial_):
return self.invFactorial_[n]
self.inv(n) # To make sure already calculated n^-1
nextArr = [0] * (n + 1 - len(self.invFactorial_))
initialI = len(self.invFactorial_)
prev = self.invFactorial_[-1]
p = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
self.invFactorial_ += nextArr
return self.invFactorial_[n]
class Combination:
def __init__(self, MOD):
self.MOD = MOD
self.factorial = Factorial(MOD)
def ncr(self, n, k):
if k < 0 or n < k:
return 0
k = min(k, n - k)
f = self.factorial
return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
# --------------------------------------iye ha combinations ka zindegi---------------------------------
def powm(a, n, m):
if a == 1 or n == 0:
return 1
if n % 2 == 0:
s = powm(a, n // 2, m)
return s * s % m
else:
return a * powm(a, n - 1, m) % m
# --------------------------------------iye ha power ka zindegi---------------------------------
def sort_list(list1, list2):
zipped_pairs = zip(list2, list1)
z = [x for _, x in sorted(zipped_pairs)]
return z
# --------------------------------------------------product----------------------------------------
def product(l):
por = 1
for i in range(len(l)):
por *= l[i]
return por
# --------------------------------------------------binary----------------------------------------
def binarySearchCount(arr, n, key):
left = 0
right = n - 1
count = 0
while (left <= right):
mid = int((right + left) / 2)
# Check if middle element is
# less than or equal to key
if (arr[mid] < key):
count = mid + 1
left = mid + 1
# If key is smaller, ignore right half
else:
right = mid - 1
return count
# --------------------------------------------------binary----------------------------------------
def countdig(n):
c = 0
while (n > 0):
n //= 10
c += 1
return c
def binary(x, length):
y = bin(x)[2:]
return y if len(y) >= length else "0" * (length - len(y)) + y
def countGreater(arr, n, k):
l = 0
r = n - 1
# Stores the index of the left most element
# from the array which is greater than k
leftGreater = n
# Finds number of elements greater than k
while (l <= r):
m = int(l + (r - l) / 2)
if (arr[m] >= k):
leftGreater = m
r = m - 1
# If mid element is less than
# or equal to k update l
else:
l = m + 1
# Return the count of elements
# greater than k
return (n - leftGreater)
# --------------------------------------------------binary------------------------------------
n,k,l,r,sa,sk=map(int,input().split())
ans=[l]*n
sa-=n*l
sk-=l*k
t=0
if k!=n:
diff=sa-sk
high=diff%(n-k)
for i in range(n-k-high):
ans[t]+=diff//(n-k)
t+=1
for i in range(high):
ans[t]+=diff//(n-k)+1
t+=1
diff=sk
high=diff%k
for i in range(k-high):
ans[t]+=diff//k
t+=1
for i in range(high):
ans[t]+=diff//k+1
t+=1
print(*ans)
``` | output | 1 | 39,922 | 17 | 79,845 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of n students (including Valera). This contest was an individual competition, so each student in the team solved problems individually.
After the contest was over, Valera was interested in results. He found out that:
* each student in the team scored at least l points and at most r points;
* in total, all members of the team scored exactly sall points;
* the total score of the k members of the team who scored the most points is equal to exactly sk; more formally, if a1, a2, ..., an is the sequence of points earned by the team of students in the non-increasing order (a1 β₯ a2 β₯ ... β₯ an), then sk = a1 + a2 + ... + ak.
However, Valera did not find out exactly how many points each of n students scored. Valera asked you to recover any distribution of scores between the students of the team, such that all the conditions above are met.
Input
The first line of the input contains exactly six integers n, k, l, r, sall, sk (1 β€ n, k, l, r β€ 1000; l β€ r; k β€ n; 1 β€ sk β€ sall β€ 106).
It's guaranteed that the input is such that the answer exists.
Output
Print exactly n integers a1, a2, ..., an β the number of points each student scored. If there are multiple solutions, you can print any of them. You can print the distribution of points in any order.
Examples
Input
5 3 1 3 13 9
Output
2 3 2 3 3
Input
5 3 1 3 15 9
Output
3 3 3 3 3 | instruction | 0 | 39,923 | 17 | 79,846 |
Tags: constructive algorithms, implementation, math
Correct Solution:
```
def main():
n, k, l, r, sall, sk = map(int, input().split())
x, y = divmod(sk, k)
res = [x + 1] * y + [x] * (k - y)
n -= k
if n:
sall -= sk
x, y = divmod(sall, n)
res.extend([x + 1] * y)
res.extend([x] * (n - y))
print(' '.join(map(str, res)))
if __name__ == '__main__':
main()
``` | output | 1 | 39,923 | 17 | 79,847 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of n students (including Valera). This contest was an individual competition, so each student in the team solved problems individually.
After the contest was over, Valera was interested in results. He found out that:
* each student in the team scored at least l points and at most r points;
* in total, all members of the team scored exactly sall points;
* the total score of the k members of the team who scored the most points is equal to exactly sk; more formally, if a1, a2, ..., an is the sequence of points earned by the team of students in the non-increasing order (a1 β₯ a2 β₯ ... β₯ an), then sk = a1 + a2 + ... + ak.
However, Valera did not find out exactly how many points each of n students scored. Valera asked you to recover any distribution of scores between the students of the team, such that all the conditions above are met.
Input
The first line of the input contains exactly six integers n, k, l, r, sall, sk (1 β€ n, k, l, r β€ 1000; l β€ r; k β€ n; 1 β€ sk β€ sall β€ 106).
It's guaranteed that the input is such that the answer exists.
Output
Print exactly n integers a1, a2, ..., an β the number of points each student scored. If there are multiple solutions, you can print any of them. You can print the distribution of points in any order.
Examples
Input
5 3 1 3 13 9
Output
2 3 2 3 3
Input
5 3 1 3 15 9
Output
3 3 3 3 3 | instruction | 0 | 39,924 | 17 | 79,848 |
Tags: constructive algorithms, implementation, math
Correct Solution:
```
n,k,l,r,sa,sk = map(int, input().split())
a = [sk//k]*k
s = sk%k
for i in range(1,s+1):
a[i-1] += 1
if n!=k:
a += [(sa-sk)//(n-k)]*(n-k)
s = (sa-sk)%(n-k)
for i in range(1,s+1):
a[i+k-1] += 1
print(*a)
``` | output | 1 | 39,924 | 17 | 79,849 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of n students (including Valera). This contest was an individual competition, so each student in the team solved problems individually.
After the contest was over, Valera was interested in results. He found out that:
* each student in the team scored at least l points and at most r points;
* in total, all members of the team scored exactly sall points;
* the total score of the k members of the team who scored the most points is equal to exactly sk; more formally, if a1, a2, ..., an is the sequence of points earned by the team of students in the non-increasing order (a1 β₯ a2 β₯ ... β₯ an), then sk = a1 + a2 + ... + ak.
However, Valera did not find out exactly how many points each of n students scored. Valera asked you to recover any distribution of scores between the students of the team, such that all the conditions above are met.
Input
The first line of the input contains exactly six integers n, k, l, r, sall, sk (1 β€ n, k, l, r β€ 1000; l β€ r; k β€ n; 1 β€ sk β€ sall β€ 106).
It's guaranteed that the input is such that the answer exists.
Output
Print exactly n integers a1, a2, ..., an β the number of points each student scored. If there are multiple solutions, you can print any of them. You can print the distribution of points in any order.
Examples
Input
5 3 1 3 13 9
Output
2 3 2 3 3
Input
5 3 1 3 15 9
Output
3 3 3 3 3 | instruction | 0 | 39,925 | 17 | 79,850 |
Tags: constructive algorithms, implementation, math
Correct Solution:
```
import math
n,k,l,r,sall,sk = map(int,input().split())
osk,ok = sk,k
lst = []
while k:
x = math.ceil(sk/k)
lst.append(x)
k -= 1
sk -= x
v = n-ok
sall -= osk
while v:
x = math.ceil(sall/v)
lst.append(x)
v -= 1
sall -= x
print(*lst)
``` | output | 1 | 39,925 | 17 | 79,851 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of n students (including Valera). This contest was an individual competition, so each student in the team solved problems individually.
After the contest was over, Valera was interested in results. He found out that:
* each student in the team scored at least l points and at most r points;
* in total, all members of the team scored exactly sall points;
* the total score of the k members of the team who scored the most points is equal to exactly sk; more formally, if a1, a2, ..., an is the sequence of points earned by the team of students in the non-increasing order (a1 β₯ a2 β₯ ... β₯ an), then sk = a1 + a2 + ... + ak.
However, Valera did not find out exactly how many points each of n students scored. Valera asked you to recover any distribution of scores between the students of the team, such that all the conditions above are met.
Input
The first line of the input contains exactly six integers n, k, l, r, sall, sk (1 β€ n, k, l, r β€ 1000; l β€ r; k β€ n; 1 β€ sk β€ sall β€ 106).
It's guaranteed that the input is such that the answer exists.
Output
Print exactly n integers a1, a2, ..., an β the number of points each student scored. If there are multiple solutions, you can print any of them. You can print the distribution of points in any order.
Examples
Input
5 3 1 3 13 9
Output
2 3 2 3 3
Input
5 3 1 3 15 9
Output
3 3 3 3 3 | instruction | 0 | 39,926 | 17 | 79,852 |
Tags: constructive algorithms, implementation, math
Correct Solution:
```
n, k, l, r, sA, sK = map(int, input().split())
m = []
for x in range(k):
m.append(sK // k)
ind = 0
sK %= k
while sK:
m[ind] += 1
ind += 1
if ind == k:
ind = 0
sK -= 1
sA -= sum(m)
for q in range(n - k):
m.append(sA // (n - k))
if n > k:
sA %= n - k
ind = k
while sA:
m[ind] += 1
ind += 1
if ind == n:
ind = k
sA -= 1
print(*m)
``` | output | 1 | 39,926 | 17 | 79,853 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of n students (including Valera). This contest was an individual competition, so each student in the team solved problems individually.
After the contest was over, Valera was interested in results. He found out that:
* each student in the team scored at least l points and at most r points;
* in total, all members of the team scored exactly sall points;
* the total score of the k members of the team who scored the most points is equal to exactly sk; more formally, if a1, a2, ..., an is the sequence of points earned by the team of students in the non-increasing order (a1 β₯ a2 β₯ ... β₯ an), then sk = a1 + a2 + ... + ak.
However, Valera did not find out exactly how many points each of n students scored. Valera asked you to recover any distribution of scores between the students of the team, such that all the conditions above are met.
Input
The first line of the input contains exactly six integers n, k, l, r, sall, sk (1 β€ n, k, l, r β€ 1000; l β€ r; k β€ n; 1 β€ sk β€ sall β€ 106).
It's guaranteed that the input is such that the answer exists.
Output
Print exactly n integers a1, a2, ..., an β the number of points each student scored. If there are multiple solutions, you can print any of them. You can print the distribution of points in any order.
Examples
Input
5 3 1 3 13 9
Output
2 3 2 3 3
Input
5 3 1 3 15 9
Output
3 3 3 3 3 | instruction | 0 | 39,927 | 17 | 79,854 |
Tags: constructive algorithms, implementation, math
Correct Solution:
```
R = lambda: map(int, input().split())
n, k, l, r, s_all, s_k = R()
points = [l] * n
add_1 = s_k - l * k
for i in range(k):
points[i] += add_1 // k
for i in range(add_1 % k):
points[i] += 1
if k < n:
add_2 = s_all - s_k - l * (n - k)
for i in range(k, n):
points[i] += add_2 // (n - k)
for i in range(k, k + add_2 % (n - k)):
points[i] += 1
print(' '.join(map(str, points)))
``` | output | 1 | 39,927 | 17 | 79,855 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of n students (including Valera). This contest was an individual competition, so each student in the team solved problems individually.
After the contest was over, Valera was interested in results. He found out that:
* each student in the team scored at least l points and at most r points;
* in total, all members of the team scored exactly sall points;
* the total score of the k members of the team who scored the most points is equal to exactly sk; more formally, if a1, a2, ..., an is the sequence of points earned by the team of students in the non-increasing order (a1 β₯ a2 β₯ ... β₯ an), then sk = a1 + a2 + ... + ak.
However, Valera did not find out exactly how many points each of n students scored. Valera asked you to recover any distribution of scores between the students of the team, such that all the conditions above are met.
Input
The first line of the input contains exactly six integers n, k, l, r, sall, sk (1 β€ n, k, l, r β€ 1000; l β€ r; k β€ n; 1 β€ sk β€ sall β€ 106).
It's guaranteed that the input is such that the answer exists.
Output
Print exactly n integers a1, a2, ..., an β the number of points each student scored. If there are multiple solutions, you can print any of them. You can print the distribution of points in any order.
Examples
Input
5 3 1 3 13 9
Output
2 3 2 3 3
Input
5 3 1 3 15 9
Output
3 3 3 3 3 | instruction | 0 | 39,928 | 17 | 79,856 |
Tags: constructive algorithms, implementation, math
Correct Solution:
```
n,k,l,r,s1,s2=map(int,input().split())
a=[]
sumi=s1-s2
sumi1=n-k
ans1=s2//k
a=[ans1]*k
maxi=r-ans1
p=s2%k
i=0
z=0
while(p>0):
i=i%len(a)
a[i]+=1
p-=1
i+=1
ans=[]
for i in range(sumi1):
ans.append(sumi//sumi1)
if sumi>0:
z=sumi%sumi1
i=0
while(z>0):
ans[i]+=1
z-=1
i+=1
i=i%len(ans)
a=a+ans
print(*a)
``` | output | 1 | 39,928 | 17 | 79,857 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of n students (including Valera). This contest was an individual competition, so each student in the team solved problems individually.
After the contest was over, Valera was interested in results. He found out that:
* each student in the team scored at least l points and at most r points;
* in total, all members of the team scored exactly sall points;
* the total score of the k members of the team who scored the most points is equal to exactly sk; more formally, if a1, a2, ..., an is the sequence of points earned by the team of students in the non-increasing order (a1 β₯ a2 β₯ ... β₯ an), then sk = a1 + a2 + ... + ak.
However, Valera did not find out exactly how many points each of n students scored. Valera asked you to recover any distribution of scores between the students of the team, such that all the conditions above are met.
Input
The first line of the input contains exactly six integers n, k, l, r, sall, sk (1 β€ n, k, l, r β€ 1000; l β€ r; k β€ n; 1 β€ sk β€ sall β€ 106).
It's guaranteed that the input is such that the answer exists.
Output
Print exactly n integers a1, a2, ..., an β the number of points each student scored. If there are multiple solutions, you can print any of them. You can print the distribution of points in any order.
Examples
Input
5 3 1 3 13 9
Output
2 3 2 3 3
Input
5 3 1 3 15 9
Output
3 3 3 3 3 | instruction | 0 | 39,929 | 17 | 79,858 |
Tags: constructive algorithms, implementation, math
Correct Solution:
```
import math,sys,bisect,heapq
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
#sys.setrecursionlimit(200000000)
int1 = lambda x: int(x) - 1
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
ilelec = lambda: map(int1,input().split())
alelec = lambda: list(map(int1, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
#MOD = 1000000000 + 7
def Y(c): print(["NO","YES"][c])
def y(c): print(["no","yes"][c])
def Yy(c): print(["No","Yes"][c])
n,k,l,r,sall,sk = ilele()
Ans = [l]*n
def fun(tempk,ss,a,b):
while True:
for i in range(a,b):
if tempk + 1 <= ss and Ans[i] + 1 <= r:
Ans[i] += 1
tempk +=1
if tempk == ss:
return
fun(k*l,sk,0,k)
fun(sum(Ans),sall,k,n)
print(*Ans)
``` | output | 1 | 39,929 | 17 | 79,859 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This problem consists of three subproblems: for solving subproblem C1 you will receive 4 points, for solving subproblem C2 you will receive 4 points, and for solving subproblem C3 you will receive 8 points.
Manao decided to pursue a fighter's career. He decided to begin with an ongoing tournament. Before Manao joined, there were n contestants in the tournament, numbered from 1 to n. Each of them had already obtained some amount of tournament points, namely the i-th fighter had pi points.
Manao is going to engage in a single fight against each contestant. Each of Manao's fights ends in either a win or a loss. A win grants Manao one point, and a loss grants Manao's opponent one point. For each i, Manao estimated the amount of effort ei he needs to invest to win against the i-th contestant. Losing a fight costs no effort.
After Manao finishes all of his fights, the ranklist will be determined, with 1 being the best rank and n + 1 being the worst. The contestants will be ranked in descending order of their tournament points. The contestants with the same number of points as Manao will be ranked better than him if they won the match against him and worse otherwise. The exact mechanism of breaking ties for other fighters is not relevant here.
Manao's objective is to have rank k or better. Determine the minimum total amount of effort he needs to invest in order to fulfill this goal, if it is possible.
Input
The first line contains a pair of integers n and k (1 β€ k β€ n + 1). The i-th of the following n lines contains two integers separated by a single space β pi and ei (0 β€ pi, ei β€ 200000).
The problem consists of three subproblems. The subproblems have different constraints on the input. You will get some score for the correct submission of the subproblem. The description of the subproblems follows.
* In subproblem C1 (4 points), the constraint 1 β€ n β€ 15 will hold.
* In subproblem C2 (4 points), the constraint 1 β€ n β€ 100 will hold.
* In subproblem C3 (8 points), the constraint 1 β€ n β€ 200000 will hold.
Output
Print a single number in a single line β the minimum amount of effort Manao needs to use to rank in the top k. If no amount of effort can earn Manao such a rank, output number -1.
Examples
Input
3 2
1 1
1 4
2 2
Output
3
Input
2 1
3 2
4 0
Output
-1
Input
5 2
2 10
2 10
1 1
3 1
3 1
Output
12
Note
Consider the first test case. At the time when Manao joins the tournament, there are three fighters. The first of them has 1 tournament point and the victory against him requires 1 unit of effort. The second contestant also has 1 tournament point, but Manao needs 4 units of effort to defeat him. The third contestant has 2 points and victory against him costs Manao 2 units of effort. Manao's goal is top be in top 2. The optimal decision is to win against fighters 1 and 3, after which Manao, fighter 2, and fighter 3 will all have 2 points. Manao will rank better than fighter 3 and worse than fighter 2, thus finishing in second place.
Consider the second test case. Even if Manao wins against both opponents, he will still rank third. | instruction | 0 | 39,938 | 17 | 79,876 |
Tags: brute force
Correct Solution:
```
m = 301000
ns = [0] * m
es = [0] * m
c = [0] * m
b = [0] * m
t = [0] * m
P = 0
def add(b, k):
k = t[k]
while k:
e = es[k]
if b[-1] > e: b[-1] = e
b[e] += 1
k = ns[k]
def delete(b):
for i in range(b[m - 1], m + 1):
if b[i]:
b[i] -= 1
b[-1] = i
return i
def calc(k):
global b
q = 0
b = [0] * m
b[-1] = m
take = rank - dn
if take < 0: take = 0
add(b, k)
add(b, k - 1)
for i in range(1, take + 1): q += delete(b)
for i in range(k - 1): add(b, i)
for i in range(k + 1, P + 1): add(b, i)
for i in range(1, k - take + 1): q += delete(b)
return q
n, k = map(int, input().split())
rank = n - k + 1
if rank == 0:
print('0')
exit(0)
for i in range(1, n + 1):
p, e = map(int, input().split())
if p > P: P = p
c[p] += 1
es[i], ns[i] = e, t[p]
t[p] = i
dn = 0
for i in range(1, n + 1):
if i > 1: dn += c[i - 2]
if c[i] + c[i - 1] + dn >= rank and rank <= i + dn:
u = calc(i)
if i < n:
dn += c[i - 1]
v = calc(i + 1)
if u > v: u = v
if i < n - 1:
dn += c[i]
v = calc(i + 2)
if u > v: u = v
print(u)
exit(0)
print('-1')
``` | output | 1 | 39,938 | 17 | 79,877 |
Provide a correct Python 3 solution for this coding contest problem.
I have a plan to go on a school trip at a school. I conducted a questionnaire survey for that purpose. Students have student numbers from 1 to n, and the locations of travel candidates are represented by numbers from 1 to m, and where they want to go β , Mark the places you don't want to go with a cross and submit.
At this time, create a program that outputs the place numbers in descending order of the number of people you want to go to. If the number of people is the same, the place numbers are used.
In the first line of the input data, the number of students n and the number of travel candidate locations m are separated by a blank, and the questionnaire result of student i is represented by 1 in β and 0 in Γ in i + 1 line, separated by a blank. There are m numbers in a row. 1 β€ n β€ 1000, 1 β€ m β€ 100.
Input example 1
---
4 6
1 0 1 0 1 1
1 1 0 1 0 0
1 1 1 0 0 0
1 0 1 0 1 0
Output example 1
1 3 2 5 4 6
input
The input consists of multiple datasets. Input ends when both n and m are 0. The number of datasets does not exceed 5.
output
Output the location number on one line for each dataset.
Example
Input
4 6
1 0 1 0 1 1
1 1 0 1 0 0
1 1 1 0 0 0
1 0 1 0 1 0
4 6
1 0 1 0 1 1
1 1 0 1 0 0
1 1 1 0 0 0
1 0 1 0 1 0
0 0
Output
1 3 2 5 4 6
1 3 2 5 4 6 | instruction | 0 | 40,363 | 17 | 80,726 |
"Correct Solution:
```
def main():
while True:
n, m = map(int,input().split())
if not n:
break
lst = [0] * m
for i in range(n):
lst = [i + j for i, j in zip(lst, map(int,input().split()))]
lst = list(zip(lst,[i for i in range(1,m + 1)]))
lst = sorted(lst,key=lambda t:-t[0])
print(" ".join(list(map(str,[t[1] for t in lst]))))
main()
``` | output | 1 | 40,363 | 17 | 80,727 |
Provide a correct Python 3 solution for this coding contest problem.
I have a plan to go on a school trip at a school. I conducted a questionnaire survey for that purpose. Students have student numbers from 1 to n, and the locations of travel candidates are represented by numbers from 1 to m, and where they want to go β , Mark the places you don't want to go with a cross and submit.
At this time, create a program that outputs the place numbers in descending order of the number of people you want to go to. If the number of people is the same, the place numbers are used.
In the first line of the input data, the number of students n and the number of travel candidate locations m are separated by a blank, and the questionnaire result of student i is represented by 1 in β and 0 in Γ in i + 1 line, separated by a blank. There are m numbers in a row. 1 β€ n β€ 1000, 1 β€ m β€ 100.
Input example 1
---
4 6
1 0 1 0 1 1
1 1 0 1 0 0
1 1 1 0 0 0
1 0 1 0 1 0
Output example 1
1 3 2 5 4 6
input
The input consists of multiple datasets. Input ends when both n and m are 0. The number of datasets does not exceed 5.
output
Output the location number on one line for each dataset.
Example
Input
4 6
1 0 1 0 1 1
1 1 0 1 0 0
1 1 1 0 0 0
1 0 1 0 1 0
4 6
1 0 1 0 1 1
1 1 0 1 0 0
1 1 1 0 0 0
1 0 1 0 1 0
0 0
Output
1 3 2 5 4 6
1 3 2 5 4 6 | instruction | 0 | 40,364 | 17 | 80,728 |
"Correct Solution:
```
while 1:
n,m=map(int,input().split())
if n==m==0:break
ans=[[0,i+1] for i in range(m)]
for i in range(n):
a=list(map(int,input().split()))
for j in range(m):
if a[j]==1:
ans[j][0]-=1
ans.sort()
ans2=[]
for i in ans:
ans2.append(i[1])
print(' '.join(map(str, ans2)))
``` | output | 1 | 40,364 | 17 | 80,729 |
Provide a correct Python 3 solution for this coding contest problem.
I have a plan to go on a school trip at a school. I conducted a questionnaire survey for that purpose. Students have student numbers from 1 to n, and the locations of travel candidates are represented by numbers from 1 to m, and where they want to go β , Mark the places you don't want to go with a cross and submit.
At this time, create a program that outputs the place numbers in descending order of the number of people you want to go to. If the number of people is the same, the place numbers are used.
In the first line of the input data, the number of students n and the number of travel candidate locations m are separated by a blank, and the questionnaire result of student i is represented by 1 in β and 0 in Γ in i + 1 line, separated by a blank. There are m numbers in a row. 1 β€ n β€ 1000, 1 β€ m β€ 100.
Input example 1
---
4 6
1 0 1 0 1 1
1 1 0 1 0 0
1 1 1 0 0 0
1 0 1 0 1 0
Output example 1
1 3 2 5 4 6
input
The input consists of multiple datasets. Input ends when both n and m are 0. The number of datasets does not exceed 5.
output
Output the location number on one line for each dataset.
Example
Input
4 6
1 0 1 0 1 1
1 1 0 1 0 0
1 1 1 0 0 0
1 0 1 0 1 0
4 6
1 0 1 0 1 1
1 1 0 1 0 0
1 1 1 0 0 0
1 0 1 0 1 0
0 0
Output
1 3 2 5 4 6
1 3 2 5 4 6 | instruction | 0 | 40,365 | 17 | 80,730 |
"Correct Solution:
```
def f():
N, M = map(int, input().split())
if N == 0:
return -1
A = [0] * M
for i in range(N):
T = [int(i) for i in map(int, input().split())]
for j in range(M):
if T[j] == 1:
A[j] += 1
B = sorted([(v, i + 1) for i, v in enumerate(A)], key=lambda t:(t[0], -t[1]), reverse=True)
print(' '.join([str(t[1]) for t in B]))
return 1
def main():
while True:
ret = f()
if ret == -1:
return
if __name__ == '__main__':
main()
``` | output | 1 | 40,365 | 17 | 80,731 |
Provide a correct Python 3 solution for this coding contest problem.
I have a plan to go on a school trip at a school. I conducted a questionnaire survey for that purpose. Students have student numbers from 1 to n, and the locations of travel candidates are represented by numbers from 1 to m, and where they want to go β , Mark the places you don't want to go with a cross and submit.
At this time, create a program that outputs the place numbers in descending order of the number of people you want to go to. If the number of people is the same, the place numbers are used.
In the first line of the input data, the number of students n and the number of travel candidate locations m are separated by a blank, and the questionnaire result of student i is represented by 1 in β and 0 in Γ in i + 1 line, separated by a blank. There are m numbers in a row. 1 β€ n β€ 1000, 1 β€ m β€ 100.
Input example 1
---
4 6
1 0 1 0 1 1
1 1 0 1 0 0
1 1 1 0 0 0
1 0 1 0 1 0
Output example 1
1 3 2 5 4 6
input
The input consists of multiple datasets. Input ends when both n and m are 0. The number of datasets does not exceed 5.
output
Output the location number on one line for each dataset.
Example
Input
4 6
1 0 1 0 1 1
1 1 0 1 0 0
1 1 1 0 0 0
1 0 1 0 1 0
4 6
1 0 1 0 1 1
1 1 0 1 0 0
1 1 1 0 0 0
1 0 1 0 1 0
0 0
Output
1 3 2 5 4 6
1 3 2 5 4 6 | instruction | 0 | 40,366 | 17 | 80,732 |
"Correct Solution:
```
while True:
n, m = map(int, input().split())
if n == 0:
break
questionnaire = [0] * m
for _ in range(n):
questionnaire = map(lambda x, y: x+y, questionnaire, map(int, input().split()))
d = {m-k: v for k, v in enumerate(questionnaire)}
result = sorted(d.items(), key=lambda x: (x[1], x[0]), reverse=True)
print(*[m-r[0]+1 for r in result])
``` | output | 1 | 40,366 | 17 | 80,733 |
Provide a correct Python 3 solution for this coding contest problem.
I have a plan to go on a school trip at a school. I conducted a questionnaire survey for that purpose. Students have student numbers from 1 to n, and the locations of travel candidates are represented by numbers from 1 to m, and where they want to go β , Mark the places you don't want to go with a cross and submit.
At this time, create a program that outputs the place numbers in descending order of the number of people you want to go to. If the number of people is the same, the place numbers are used.
In the first line of the input data, the number of students n and the number of travel candidate locations m are separated by a blank, and the questionnaire result of student i is represented by 1 in β and 0 in Γ in i + 1 line, separated by a blank. There are m numbers in a row. 1 β€ n β€ 1000, 1 β€ m β€ 100.
Input example 1
---
4 6
1 0 1 0 1 1
1 1 0 1 0 0
1 1 1 0 0 0
1 0 1 0 1 0
Output example 1
1 3 2 5 4 6
input
The input consists of multiple datasets. Input ends when both n and m are 0. The number of datasets does not exceed 5.
output
Output the location number on one line for each dataset.
Example
Input
4 6
1 0 1 0 1 1
1 1 0 1 0 0
1 1 1 0 0 0
1 0 1 0 1 0
4 6
1 0 1 0 1 1
1 1 0 1 0 0
1 1 1 0 0 0
1 0 1 0 1 0
0 0
Output
1 3 2 5 4 6
1 3 2 5 4 6 | instruction | 0 | 40,367 | 17 | 80,734 |
"Correct Solution:
```
while True:
n,m = [int(x) for x in input().split()]
if n == 0 and m == 0:
break
L = [0] * m
for _ in range(n):
l = [int(x) for x in input().split()]
for i in range(m):
L[i] += l[i]
M=[]
for i, j in enumerate(L,1):
M.append((i,j))
M.sort(key=lambda x: (-x[1],x[0]) )
print( *[ x for x, y in M] )
``` | output | 1 | 40,367 | 17 | 80,735 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.