message
stringlengths
2
22.8k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
16
109k
cluster
float64
1
1
__index_level_0__
int64
32
217k
Provide tags and a correct Python 3 solution for this coding contest problem. Bandits appeared in the city! One of them is trying to catch as many citizens as he can. The city consists of n squares connected by n-1 roads in such a way that it is possible to reach any square from any other square. The square number 1 is the main square. After Sunday walk all the roads were changed to one-way roads in such a way that it is possible to reach any square from the main square. At the moment when the bandit appeared on the main square there were a_i citizens on the i-th square. Now the following process will begin. First, each citizen that is currently on a square with some outgoing one-way roads chooses one of such roads and moves along it to another square. Then the bandit chooses one of the one-way roads outgoing from the square he is located and moves along it. The process is repeated until the bandit is located on a square with no outgoing roads. The bandit catches all the citizens on that square. The bandit wants to catch as many citizens as possible; the citizens want to minimize the number of caught people. The bandit and the citizens know positions of all citizens at any time, the citizens can cooperate. If both sides act optimally, how many citizens will be caught? Input The first line contains a single integer n β€” the number of squares in the city (2 ≀ n ≀ 2β‹…10^5). The second line contains n-1 integers p_2, p_3 ... p_n meaning that there is a one-way road from the square p_i to the square i (1 ≀ p_i < i). The third line contains n integers a_1, a_2, ..., a_n β€” the number of citizens on each square initially (0 ≀ a_i ≀ 10^9). Output Print a single integer β€” the number of citizens the bandit will catch if both sides act optimally. Examples Input 3 1 1 3 1 2 Output 3 Input 3 1 1 3 1 3 Output 4 Note In the first example the citizens on the square 1 can split into two groups 2 + 1, so that the second and on the third squares will have 3 citizens each. In the second example no matter how citizens act the bandit can catch at least 4 citizens.
instruction
0
61,671
1
123,342
Tags: binary search, dfs and similar, graphs, greedy, trees Correct Solution: ``` maxn = 200005 cities = [0 for _ in range(maxn)] n = int(input()) x = list(map(int , input().split(' '))) total = [0]+list(map(int,input().split(' '))) ans = 0 for i in range(n,0,-1): if(cities[i]==0): cities[i]=1 if(i>=2): cities[x[i-2]]+=cities[i] total [x[i-2]]+=total[i] ans = max(ans, (total[i] + cities[i] -1)//cities[i]) print(ans) ```
output
1
61,671
1
123,343
Provide tags and a correct Python 3 solution for this coding contest problem. Bandits appeared in the city! One of them is trying to catch as many citizens as he can. The city consists of n squares connected by n-1 roads in such a way that it is possible to reach any square from any other square. The square number 1 is the main square. After Sunday walk all the roads were changed to one-way roads in such a way that it is possible to reach any square from the main square. At the moment when the bandit appeared on the main square there were a_i citizens on the i-th square. Now the following process will begin. First, each citizen that is currently on a square with some outgoing one-way roads chooses one of such roads and moves along it to another square. Then the bandit chooses one of the one-way roads outgoing from the square he is located and moves along it. The process is repeated until the bandit is located on a square with no outgoing roads. The bandit catches all the citizens on that square. The bandit wants to catch as many citizens as possible; the citizens want to minimize the number of caught people. The bandit and the citizens know positions of all citizens at any time, the citizens can cooperate. If both sides act optimally, how many citizens will be caught? Input The first line contains a single integer n β€” the number of squares in the city (2 ≀ n ≀ 2β‹…10^5). The second line contains n-1 integers p_2, p_3 ... p_n meaning that there is a one-way road from the square p_i to the square i (1 ≀ p_i < i). The third line contains n integers a_1, a_2, ..., a_n β€” the number of citizens on each square initially (0 ≀ a_i ≀ 10^9). Output Print a single integer β€” the number of citizens the bandit will catch if both sides act optimally. Examples Input 3 1 1 3 1 2 Output 3 Input 3 1 1 3 1 3 Output 4 Note In the first example the citizens on the square 1 can split into two groups 2 + 1, so that the second and on the third squares will have 3 citizens each. In the second example no matter how citizens act the bandit can catch at least 4 citizens.
instruction
0
61,672
1
123,344
Tags: binary search, dfs and similar, graphs, greedy, trees Correct Solution: ``` n = int(input()) cities = [0 for _ in range(n + 1)] x = list(map(int, input().split(' '))) total = [0] + list(map(int, input().split(' '))) ans = 0 for i in range(n, 0, -1): if(cities[i] == 0): cities[i] = 1 if(i >= 2): cities[x[i - 2]] += cities[i] total [x[i - 2]] += total[i] ans = max(ans, (total[i] + cities[i] -1) // cities[i]) print(ans) ```
output
1
61,672
1
123,345
Provide tags and a correct Python 3 solution for this coding contest problem. Bandits appeared in the city! One of them is trying to catch as many citizens as he can. The city consists of n squares connected by n-1 roads in such a way that it is possible to reach any square from any other square. The square number 1 is the main square. After Sunday walk all the roads were changed to one-way roads in such a way that it is possible to reach any square from the main square. At the moment when the bandit appeared on the main square there were a_i citizens on the i-th square. Now the following process will begin. First, each citizen that is currently on a square with some outgoing one-way roads chooses one of such roads and moves along it to another square. Then the bandit chooses one of the one-way roads outgoing from the square he is located and moves along it. The process is repeated until the bandit is located on a square with no outgoing roads. The bandit catches all the citizens on that square. The bandit wants to catch as many citizens as possible; the citizens want to minimize the number of caught people. The bandit and the citizens know positions of all citizens at any time, the citizens can cooperate. If both sides act optimally, how many citizens will be caught? Input The first line contains a single integer n β€” the number of squares in the city (2 ≀ n ≀ 2β‹…10^5). The second line contains n-1 integers p_2, p_3 ... p_n meaning that there is a one-way road from the square p_i to the square i (1 ≀ p_i < i). The third line contains n integers a_1, a_2, ..., a_n β€” the number of citizens on each square initially (0 ≀ a_i ≀ 10^9). Output Print a single integer β€” the number of citizens the bandit will catch if both sides act optimally. Examples Input 3 1 1 3 1 2 Output 3 Input 3 1 1 3 1 3 Output 4 Note In the first example the citizens on the square 1 can split into two groups 2 + 1, so that the second and on the third squares will have 3 citizens each. In the second example no matter how citizens act the bandit can catch at least 4 citizens.
instruction
0
61,673
1
123,346
Tags: binary search, dfs and similar, graphs, greedy, trees Correct Solution: ``` from collections import defaultdict, deque from math import ceil from sys import setrecursionlimit import io, os setrecursionlimit(300000) input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n = int(input()) par = [-1] + list(map(int, input().split())) _g = defaultdict(list) real_leaves = set(range(n)) people = list(map(int, input().split())) children = [0] * (n+1) for i, v in enumerate(par): real_leaves.discard(v-1) _g[i].append(v-1) children[v-1] += 1 q = deque(real_leaves) leaves, people_cnt = [0] * (n+1), people[:] for i in real_leaves: leaves[i] = 1 ans = 0 while True: q2 = deque() while q: now = q.popleft() ans = max(ans, ceil(people_cnt[now] / leaves[now])) for par in _g[now]: leaves[par] += leaves[now] people_cnt[par] += people_cnt[now] children[par] -= 1 if children[par] == 0: q2.append(par) if not q2: break q = q2 print(ans) ```
output
1
61,673
1
123,347
Provide tags and a correct Python 3 solution for this coding contest problem. Bandits appeared in the city! One of them is trying to catch as many citizens as he can. The city consists of n squares connected by n-1 roads in such a way that it is possible to reach any square from any other square. The square number 1 is the main square. After Sunday walk all the roads were changed to one-way roads in such a way that it is possible to reach any square from the main square. At the moment when the bandit appeared on the main square there were a_i citizens on the i-th square. Now the following process will begin. First, each citizen that is currently on a square with some outgoing one-way roads chooses one of such roads and moves along it to another square. Then the bandit chooses one of the one-way roads outgoing from the square he is located and moves along it. The process is repeated until the bandit is located on a square with no outgoing roads. The bandit catches all the citizens on that square. The bandit wants to catch as many citizens as possible; the citizens want to minimize the number of caught people. The bandit and the citizens know positions of all citizens at any time, the citizens can cooperate. If both sides act optimally, how many citizens will be caught? Input The first line contains a single integer n β€” the number of squares in the city (2 ≀ n ≀ 2β‹…10^5). The second line contains n-1 integers p_2, p_3 ... p_n meaning that there is a one-way road from the square p_i to the square i (1 ≀ p_i < i). The third line contains n integers a_1, a_2, ..., a_n β€” the number of citizens on each square initially (0 ≀ a_i ≀ 10^9). Output Print a single integer β€” the number of citizens the bandit will catch if both sides act optimally. Examples Input 3 1 1 3 1 2 Output 3 Input 3 1 1 3 1 3 Output 4 Note In the first example the citizens on the square 1 can split into two groups 2 + 1, so that the second and on the third squares will have 3 citizens each. In the second example no matter how citizens act the bandit can catch at least 4 citizens.
instruction
0
61,674
1
123,348
Tags: binary search, dfs and similar, graphs, greedy, trees Correct Solution: ``` from math import factorial, ceil from sys import stdin, stdout from collections import defaultdict def DFS(arr, citz, n) : parent = {} children = defaultdict(lambda : 0) for i in range(len(arr)) : parent[ i+2 ] = arr[i] children[ arr[i] ] += 1 #print(edges) #print(citz) #print(counts) maxes = defaultdict(lambda : 0) count = defaultdict(lambda : 0) for i in reversed(range(2, n+1)) : if children[i] == 0 : count[i] = 1 maxes[i] = citz[i-1] count[ parent[i] ] += count[i] citz[ parent[i]-1 ] += citz[i-1] maxes[ parent[i] ] = max( maxes[ parent[i] ], maxes[i]) else : count[ parent[i] ] += count[i] citz[ parent[i]-1 ] += citz[i-1] maxes[i] = max(maxes[i], ceil(citz[i-1] / count[i]) ) maxes[ parent[i] ] = max( maxes[ parent[i] ], maxes[i]) stdout.write( str( max( maxes[1], ceil(citz[0] / count[1]) ) ) ) #def solve(n, arr, citz): '''class solve: def __init__(self, arr, citz) : self.nodes = [node(citz[i]) for i in range(len(citz))] self.edges = { n:[] for n in self.nodes } for i in range(len(arr)) : self.edges[ self.nodes[arr[i]-1] ].append( self.nodes[i+1] ) for k, v in self.edges.items() : if len(v) == 0 : k.count = 1 k.max = k.sum #for n in self.nodes : # print(n.count, n.sum, n.max) def DFS(self, nod) : maxi = 0 for u in self.edges[nod] : self.DFS(u) maxi = max(maxi, u.max) nod.sum += u.sum nod.count += u.count nod.max = max(maxi, ceil(nod.sum/nod.count) ) def ans(self) : self.DFS( self.nodes[0] ) print( self.nodes[0].max) ''' def main(): # write the input logic to take the input from STDIN n = int(stdin.readline()) arr = list(map(int, stdin.readline().split() ) ) citz = list(map(int, stdin.readline().split()) ) DFS(arr, citz, n) if __name__ == "__main__": main() ```
output
1
61,674
1
123,349
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bandits appeared in the city! One of them is trying to catch as many citizens as he can. The city consists of n squares connected by n-1 roads in such a way that it is possible to reach any square from any other square. The square number 1 is the main square. After Sunday walk all the roads were changed to one-way roads in such a way that it is possible to reach any square from the main square. At the moment when the bandit appeared on the main square there were a_i citizens on the i-th square. Now the following process will begin. First, each citizen that is currently on a square with some outgoing one-way roads chooses one of such roads and moves along it to another square. Then the bandit chooses one of the one-way roads outgoing from the square he is located and moves along it. The process is repeated until the bandit is located on a square with no outgoing roads. The bandit catches all the citizens on that square. The bandit wants to catch as many citizens as possible; the citizens want to minimize the number of caught people. The bandit and the citizens know positions of all citizens at any time, the citizens can cooperate. If both sides act optimally, how many citizens will be caught? Input The first line contains a single integer n β€” the number of squares in the city (2 ≀ n ≀ 2β‹…10^5). The second line contains n-1 integers p_2, p_3 ... p_n meaning that there is a one-way road from the square p_i to the square i (1 ≀ p_i < i). The third line contains n integers a_1, a_2, ..., a_n β€” the number of citizens on each square initially (0 ≀ a_i ≀ 10^9). Output Print a single integer β€” the number of citizens the bandit will catch if both sides act optimally. Examples Input 3 1 1 3 1 2 Output 3 Input 3 1 1 3 1 3 Output 4 Note In the first example the citizens on the square 1 can split into two groups 2 + 1, so that the second and on the third squares will have 3 citizens each. In the second example no matter how citizens act the bandit can catch at least 4 citizens. Submitted Solution: ``` import sys, math import io, os #data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline from bisect import bisect_left as bl, bisect_right as br, insort from heapq import heapify, heappush, heappop from collections import defaultdict as dd, deque, Counter from itertools import permutations,combinations def data(): return sys.stdin.readline().strip() def mdata(): return list(map(int, data().split())) def outl(var) : sys.stdout.write(' '.join(map(str, var))+'\n') def out(var) : sys.stdout.write(str(var)+'\n') #from decimal import Decimal #from fractions import Fraction #sys.setrecursionlimit(100000) INF = float('inf') mod = int(1e9)+7 def dfs(graph, start=0): n = len(graph) dp = [[0,a[i],0] for i in range(n)] visited, finished = [False] * n, [False] * n stack = [start] while stack: start = stack[-1] # push unvisited children into stack if not visited[start]: visited[start] = True for child in graph[start]: if not visited[child]: stack.append(child) else: stack.pop() if start!=0 and len(graph[start])==1: dp[start][0]=1 dp[start][2]=a[start] # update with finished children for child in graph[start]: if finished[child]: dp[start][0] += dp[child][0] dp[start][1] += dp[child][1] dp[start][2] = max(dp[start][2],dp[child][2]) dp[start][2] = max(dp[start][2],dp[start][1]//dp[start][0]+(1 if dp[start][1]%dp[start][0] else 0)) finished[start] = True return dp[0][2] n=int(data()) graph=[[] for i in range(n)] p=mdata() for i in range(n-1): graph[i+1].append(p[i]-1) graph[p[i]-1].append(i+1) a=mdata() out(dfs(graph,0)) ```
instruction
0
61,675
1
123,350
Yes
output
1
61,675
1
123,351
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bandits appeared in the city! One of them is trying to catch as many citizens as he can. The city consists of n squares connected by n-1 roads in such a way that it is possible to reach any square from any other square. The square number 1 is the main square. After Sunday walk all the roads were changed to one-way roads in such a way that it is possible to reach any square from the main square. At the moment when the bandit appeared on the main square there were a_i citizens on the i-th square. Now the following process will begin. First, each citizen that is currently on a square with some outgoing one-way roads chooses one of such roads and moves along it to another square. Then the bandit chooses one of the one-way roads outgoing from the square he is located and moves along it. The process is repeated until the bandit is located on a square with no outgoing roads. The bandit catches all the citizens on that square. The bandit wants to catch as many citizens as possible; the citizens want to minimize the number of caught people. The bandit and the citizens know positions of all citizens at any time, the citizens can cooperate. If both sides act optimally, how many citizens will be caught? Input The first line contains a single integer n β€” the number of squares in the city (2 ≀ n ≀ 2β‹…10^5). The second line contains n-1 integers p_2, p_3 ... p_n meaning that there is a one-way road from the square p_i to the square i (1 ≀ p_i < i). The third line contains n integers a_1, a_2, ..., a_n β€” the number of citizens on each square initially (0 ≀ a_i ≀ 10^9). Output Print a single integer β€” the number of citizens the bandit will catch if both sides act optimally. Examples Input 3 1 1 3 1 2 Output 3 Input 3 1 1 3 1 3 Output 4 Note In the first example the citizens on the square 1 can split into two groups 2 + 1, so that the second and on the third squares will have 3 citizens each. In the second example no matter how citizens act the bandit can catch at least 4 citizens. Submitted Solution: ``` # =============================================================================================== # importing some useful libraries. from __future__ import division, print_function from fractions import Fraction import sys import os from io import BytesIO, IOBase from itertools import * import bisect from heapq import * from math import ceil, floor from copy import * from collections import deque, defaultdict from collections import Counter as counter # Counter(list) return a dict with {key: count} from itertools import combinations # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)] from itertools import permutations as permutate from bisect import bisect_left as bl from operator import * # If the element is already present in the list, # the left most position where element has to be inserted is returned. from bisect import bisect_right as br from bisect import bisect # If the element is already present in the list, # the right most position where element has to be inserted is returned # range=xrange # ============================================================================================== # fast I/O region BUFSIZE = 8192 from sys import stderr class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") def print(*args, **kwargs): """Prints the values to a stream, or to sys.stdout by default.""" sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout) at_start = True for x in args: if not at_start: file.write(sep) file.write(str(x)) at_start = False file.write(kwargs.pop("end", "\n")) if kwargs.pop("flush", False): file.flush() if sys.version_info[0] < 3: sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout) else: sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) # inp = lambda: sys.stdin.readline().rstrip("\r\n") # =============================================================================================== ### START ITERATE RECURSION ### from types import GeneratorType def iterative(f, stack=[]): def wrapped_func(*args, **kwargs): if stack: return f(*args, **kwargs) to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) continue stack.pop() if not stack: break to = stack[-1].send(to) return to return wrapped_func #### END ITERATE RECURSION #### # =============================================================================================== # some shortcuts mod = 1000000007 def inp(): return sys.stdin.readline().rstrip("\r\n") # for fast input def out(var): sys.stdout.write(str(var)) # for fast output, always take string def lis(): return list(map(int, inp().split())) def stringlis(): return list(map(str, inp().split())) def sep(): return map(int, inp().split()) def strsep(): return map(str, inp().split()) def fsep(): return map(float, inp().split()) def nextline(): out("\n") # as stdout.write always print sring. def testcase(t): for p in range(t): solve() def pow(x, y, p): res = 1 # Initialize result x = x % p # Update x if it is more , than or equal to p if (x == 0): return 0 while (y > 0): if ((y & 1) == 1): # If y is odd, multiply, x with result res = (res * x) % p y = y >> 1 # y = y/2 x = (x * x) % p return res from functools import reduce def factors(n): return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))) def lcm(a, b): return abs((a // gcd(a, b)) * b) def gcd(a, b): if a == b: return a while b > 0: a, b = b, a % b return a # discrete binary search # minimise: # def search(): # l = 0 # r = 10 ** 15 # # for i in range(200): # if isvalid(l): # return l # if l == r: # return l # m = (l + r) // 2 # if isvalid(m) and not isvalid(m - 1): # return m # if isvalid(m): # r = m + 1 # else: # l = m # return m # maximise: # def search(): # l = 0 # r = 10 ** 15 # # for i in range(200): # # print(l,r) # if isvalid(r): # return r # if l == r: # return l # m = (l + r) // 2 # if isvalid(m) and not isvalid(m + 1): # return m # if isvalid(m): # l = m # else: # r = m - 1 # return m ##to find factorial and ncr # N=100000 # mod = 10**9 + 7 # fac = [1, 1] # finv = [1, 1] # inv = [0, 1] # # for i in range(2, N + 1): # fac.append((fac[-1] * i) % mod) # inv.append(mod - (inv[mod % i] * (mod // i) % mod)) # finv.append(finv[-1] * inv[-1] % mod) def comb(n, r): if n < r: return 0 else: return fac[n] * (finv[r] * finv[n - r] % mod) % mod ##############Find sum of product of subsets of size k in a array # ar=[0,1,2,3] # k=3 # n=len(ar)-1 # dp=[0]*(n+1) # dp[0]=1 # for pos in range(1,n+1): # dp[pos]=0 # l=max(1,k+pos-n-1) # for j in range(min(pos,k),l-1,-1): # dp[j]=dp[j]+ar[pos]*dp[j-1] # print(dp[k]) def prefix_sum(ar): # [1,2,3,4]->[1,3,6,10] return list(accumulate(ar)) def suffix_sum(ar): # [1,2,3,4]->[10,9,7,4] return list(accumulate(ar[::-1]))[::-1] def N(): return int(inp()) # ========================================================================================= from collections import defaultdict def numberOfSetBits(i): i = i - ((i >> 1) & 0x55555555) i = (i & 0x33333333) + ((i >> 2) & 0x33333333) return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24 def yes(): print("Yes") def no(): print("No") def YES(): print("YES") def NO(): print("NO") def solve(): n = N() ar = lis() g = [[] for _ in range(n + 1)] for i in range(1, n): g[ar[i - 1]].append(i + 1) people = lis() dp1 = [0] * (n + 1) dp2 = [0] * (n + 1) # print(g) @iterative def dfs1(v): if len(g[v]) == 0: dp1[v] = 1 dp2[v] = people[v - 1] yield dp2[v] = people[v - 1] for c in g[v]: yield dfs1(c) dp1[v] += dp1[c] dp2[v] += dp2[c] yield temp = [] dfs1(1) for i in range(1, n + 1): temp.append(ceil(dp2[i] / dp1[i])) # print(dp1) # print(dp2) # print(temp) print(max(temp)) solve() # testcase(int(inp())) ```
instruction
0
61,676
1
123,352
Yes
output
1
61,676
1
123,353
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bandits appeared in the city! One of them is trying to catch as many citizens as he can. The city consists of n squares connected by n-1 roads in such a way that it is possible to reach any square from any other square. The square number 1 is the main square. After Sunday walk all the roads were changed to one-way roads in such a way that it is possible to reach any square from the main square. At the moment when the bandit appeared on the main square there were a_i citizens on the i-th square. Now the following process will begin. First, each citizen that is currently on a square with some outgoing one-way roads chooses one of such roads and moves along it to another square. Then the bandit chooses one of the one-way roads outgoing from the square he is located and moves along it. The process is repeated until the bandit is located on a square with no outgoing roads. The bandit catches all the citizens on that square. The bandit wants to catch as many citizens as possible; the citizens want to minimize the number of caught people. The bandit and the citizens know positions of all citizens at any time, the citizens can cooperate. If both sides act optimally, how many citizens will be caught? Input The first line contains a single integer n β€” the number of squares in the city (2 ≀ n ≀ 2β‹…10^5). The second line contains n-1 integers p_2, p_3 ... p_n meaning that there is a one-way road from the square p_i to the square i (1 ≀ p_i < i). The third line contains n integers a_1, a_2, ..., a_n β€” the number of citizens on each square initially (0 ≀ a_i ≀ 10^9). Output Print a single integer β€” the number of citizens the bandit will catch if both sides act optimally. Examples Input 3 1 1 3 1 2 Output 3 Input 3 1 1 3 1 3 Output 4 Note In the first example the citizens on the square 1 can split into two groups 2 + 1, so that the second and on the third squares will have 3 citizens each. In the second example no matter how citizens act the bandit can catch at least 4 citizens. Submitted Solution: ``` n = int(input()) g = [[] for i in range(n+1)] p = list(map(int, input().split())) for i in range(n-1): a = i+2 b = p[i] g[a].append(b) g[b].append(a) dp = [0] + list(map(int, input().split())) count = [0]*(n+1) maxi = [0]*(n+1) for i in range(2, n+1): if len(g[i]) == 1: count[i] = 1 stack = [] stack.append(~1) stack.append(1) visit1 = [False]*(n+1) visit2 = [False]*(n+1) visit1[1] = True while stack: now = stack.pop() if now < 0: now = ~now for next in g[now]: if visit2[next]: dp[now] += dp[next] count[now] += count[next] maxi[now] = max(maxi[now], maxi[next]) maxi[now] = max(maxi[now], (dp[now]-1)//count[now] + 1) visit2[now] = True else: for next in g[now]: if not visit1[next]: visit1[next] = True stack.append(~next) stack.append(next) print(maxi[1]) ```
instruction
0
61,677
1
123,354
Yes
output
1
61,677
1
123,355
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bandits appeared in the city! One of them is trying to catch as many citizens as he can. The city consists of n squares connected by n-1 roads in such a way that it is possible to reach any square from any other square. The square number 1 is the main square. After Sunday walk all the roads were changed to one-way roads in such a way that it is possible to reach any square from the main square. At the moment when the bandit appeared on the main square there were a_i citizens on the i-th square. Now the following process will begin. First, each citizen that is currently on a square with some outgoing one-way roads chooses one of such roads and moves along it to another square. Then the bandit chooses one of the one-way roads outgoing from the square he is located and moves along it. The process is repeated until the bandit is located on a square with no outgoing roads. The bandit catches all the citizens on that square. The bandit wants to catch as many citizens as possible; the citizens want to minimize the number of caught people. The bandit and the citizens know positions of all citizens at any time, the citizens can cooperate. If both sides act optimally, how many citizens will be caught? Input The first line contains a single integer n β€” the number of squares in the city (2 ≀ n ≀ 2β‹…10^5). The second line contains n-1 integers p_2, p_3 ... p_n meaning that there is a one-way road from the square p_i to the square i (1 ≀ p_i < i). The third line contains n integers a_1, a_2, ..., a_n β€” the number of citizens on each square initially (0 ≀ a_i ≀ 10^9). Output Print a single integer β€” the number of citizens the bandit will catch if both sides act optimally. Examples Input 3 1 1 3 1 2 Output 3 Input 3 1 1 3 1 3 Output 4 Note In the first example the citizens on the square 1 can split into two groups 2 + 1, so that the second and on the third squares will have 3 citizens each. In the second example no matter how citizens act the bandit can catch at least 4 citizens. Submitted Solution: ``` import sys from collections import deque input = sys.stdin.buffer.readline n = int(input()) e = [[] for _ in range(n+1)] ls = list(map(int, input().split())) for i, u in enumerate(ls): e[u].append(i+2) pp = [0] + list(map(int, input().split())) q, order, par = deque([1]), [], [0]*(n+1) while q: u = q.popleft() order.append(u) for v in e[u]: if v == par[u]: continue par[v] = u q.append(v) leaf, cc = [0]*(n+1), 0 for u in reversed(order): lcc = 0 for v in e[u]: if v == par[u]: continue lcc += leaf[v] pp[u] += pp[v] lcc = max(1, lcc) leaf[u] = lcc cc = max(cc, (pp[u]+lcc-1)//lcc) print(cc) ```
instruction
0
61,678
1
123,356
Yes
output
1
61,678
1
123,357
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bandits appeared in the city! One of them is trying to catch as many citizens as he can. The city consists of n squares connected by n-1 roads in such a way that it is possible to reach any square from any other square. The square number 1 is the main square. After Sunday walk all the roads were changed to one-way roads in such a way that it is possible to reach any square from the main square. At the moment when the bandit appeared on the main square there were a_i citizens on the i-th square. Now the following process will begin. First, each citizen that is currently on a square with some outgoing one-way roads chooses one of such roads and moves along it to another square. Then the bandit chooses one of the one-way roads outgoing from the square he is located and moves along it. The process is repeated until the bandit is located on a square with no outgoing roads. The bandit catches all the citizens on that square. The bandit wants to catch as many citizens as possible; the citizens want to minimize the number of caught people. The bandit and the citizens know positions of all citizens at any time, the citizens can cooperate. If both sides act optimally, how many citizens will be caught? Input The first line contains a single integer n β€” the number of squares in the city (2 ≀ n ≀ 2β‹…10^5). The second line contains n-1 integers p_2, p_3 ... p_n meaning that there is a one-way road from the square p_i to the square i (1 ≀ p_i < i). The third line contains n integers a_1, a_2, ..., a_n β€” the number of citizens on each square initially (0 ≀ a_i ≀ 10^9). Output Print a single integer β€” the number of citizens the bandit will catch if both sides act optimally. Examples Input 3 1 1 3 1 2 Output 3 Input 3 1 1 3 1 3 Output 4 Note In the first example the citizens on the square 1 can split into two groups 2 + 1, so that the second and on the third squares will have 3 citizens each. In the second example no matter how citizens act the bandit can catch at least 4 citizens. Submitted Solution: ``` try: n = int(input()) p = list(map(int, input().split())) a = list(map(int, input().split())) tree = {} for i, pp in enumerate(p, start=2): tree.setdefault(pp, []).append(i) def proceed_square(s): children = tree.get(s, []) if len(children) == 0: return a[s - 1], a[s - 1], 1 ch_p = [proceed_square(c) for c in children] ch_max = max(pp[0] for pp in ch_p) ch_sum = sum(pp[1] for pp in ch_p) ch_l = sum(pp[2] for pp in ch_p) s = ch_sum + a[s - 1] m = s // ch_l if s % ch_l != 0: m += 1 return max(ch_max, m), s, ch_l print(proceed_square(1)[0]) except Exception: print([p[i] for i in range(len(p)) if p[i] != i + 1]) ```
instruction
0
61,679
1
123,358
No
output
1
61,679
1
123,359
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bandits appeared in the city! One of them is trying to catch as many citizens as he can. The city consists of n squares connected by n-1 roads in such a way that it is possible to reach any square from any other square. The square number 1 is the main square. After Sunday walk all the roads were changed to one-way roads in such a way that it is possible to reach any square from the main square. At the moment when the bandit appeared on the main square there were a_i citizens on the i-th square. Now the following process will begin. First, each citizen that is currently on a square with some outgoing one-way roads chooses one of such roads and moves along it to another square. Then the bandit chooses one of the one-way roads outgoing from the square he is located and moves along it. The process is repeated until the bandit is located on a square with no outgoing roads. The bandit catches all the citizens on that square. The bandit wants to catch as many citizens as possible; the citizens want to minimize the number of caught people. The bandit and the citizens know positions of all citizens at any time, the citizens can cooperate. If both sides act optimally, how many citizens will be caught? Input The first line contains a single integer n β€” the number of squares in the city (2 ≀ n ≀ 2β‹…10^5). The second line contains n-1 integers p_2, p_3 ... p_n meaning that there is a one-way road from the square p_i to the square i (1 ≀ p_i < i). The third line contains n integers a_1, a_2, ..., a_n β€” the number of citizens on each square initially (0 ≀ a_i ≀ 10^9). Output Print a single integer β€” the number of citizens the bandit will catch if both sides act optimally. Examples Input 3 1 1 3 1 2 Output 3 Input 3 1 1 3 1 3 Output 4 Note In the first example the citizens on the square 1 can split into two groups 2 + 1, so that the second and on the third squares will have 3 citizens each. In the second example no matter how citizens act the bandit can catch at least 4 citizens. Submitted Solution: ``` from math import ceil n = int(input()) p = list(map(int, input().split())) a=list(map(int, input().split())) 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 Graph: def __init__(self, V): self.V = V self.adj = [[] for i in range(V)] @bootstrap def DFSUtil(self, temp, v, visited, sums, maxs, counts): visited[v] = True temp.append(v) s=a[v] count=0 maxis=[] for i in self.adj[v]: if visited[i] == False: s+=a[i] temp = yield self.DFSUtil(temp, i, visited, sums, maxs, counts) count += counts[i] maxis.append(maxs[i]) sums[v]=s if count==0: count+=1 counts[v]=count if len(maxis)==0: maxs[v]=a[v] else: maxs[v]=max(int(ceil(sums[v]/counts[v])),max(maxis)) yield temp def addEdge(self, v, w): # self.adj[v].append(w) self.adj[w].append(v) G = Graph(n) for i in range(0, len(p)): G.addEdge(i+1, p[i] - 1) visited = [False for _ in range(n)] sums = [0 for _ in range(n)] maxs = [0 for _ in range(n)] counts = [0 for _ in range(n)] G.DFSUtil([], 0, visited, sums, maxs, counts) # print(sums,counts,maxs) print(maxs[0]) ```
instruction
0
61,680
1
123,360
No
output
1
61,680
1
123,361
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bandits appeared in the city! One of them is trying to catch as many citizens as he can. The city consists of n squares connected by n-1 roads in such a way that it is possible to reach any square from any other square. The square number 1 is the main square. After Sunday walk all the roads were changed to one-way roads in such a way that it is possible to reach any square from the main square. At the moment when the bandit appeared on the main square there were a_i citizens on the i-th square. Now the following process will begin. First, each citizen that is currently on a square with some outgoing one-way roads chooses one of such roads and moves along it to another square. Then the bandit chooses one of the one-way roads outgoing from the square he is located and moves along it. The process is repeated until the bandit is located on a square with no outgoing roads. The bandit catches all the citizens on that square. The bandit wants to catch as many citizens as possible; the citizens want to minimize the number of caught people. The bandit and the citizens know positions of all citizens at any time, the citizens can cooperate. If both sides act optimally, how many citizens will be caught? Input The first line contains a single integer n β€” the number of squares in the city (2 ≀ n ≀ 2β‹…10^5). The second line contains n-1 integers p_2, p_3 ... p_n meaning that there is a one-way road from the square p_i to the square i (1 ≀ p_i < i). The third line contains n integers a_1, a_2, ..., a_n β€” the number of citizens on each square initially (0 ≀ a_i ≀ 10^9). Output Print a single integer β€” the number of citizens the bandit will catch if both sides act optimally. Examples Input 3 1 1 3 1 2 Output 3 Input 3 1 1 3 1 3 Output 4 Note In the first example the citizens on the square 1 can split into two groups 2 + 1, so that the second and on the third squares will have 3 citizens each. In the second example no matter how citizens act the bandit can catch at least 4 citizens. Submitted Solution: ``` from __future__ import print_function # for PyPy2 from collections import Counter, OrderedDict from itertools import permutations as perm from collections import deque from sys import stdin from bisect import * from heapq import * import math g = lambda : stdin.readline().strip() gl = lambda : g().split() gil = lambda : [int(var) for var in gl()] gfl = lambda : [float(var) for var in gl()] gcl = lambda : list(g()) gbs = lambda : [int(var) for var in g()] mod = int(1e9)+7 inf = float("inf") n, = gil() adj = [[] for _ in range(n+1)] i = 2 for p in gil(): adj[p].append(i) i += 1 provide = [0]+gil() stack = [1] vis = [0]*(n+1) dp = [None for _ in range(n+1)] leafCnt = 0 while stack: p = stack[-1] if vis[p] : nMax = dp[max(adj[p], key=lambda x:dp[x][0])][0] delta, cnt = 0, 0 for c in adj[p]: cMax, cDelta, cCnt = dp[c] delta += cDelta + (nMax-cMax)*cCnt cnt += cCnt if delta > provide[p]: delta -= provide[p] else: nMax += math.ceil((provide[p]-delta)/cnt) delta = (provide[p]-delta)%cnt dp[p] = (nMax, delta, cnt) stack.pop() else: vis[p] = 1 for c in adj[p]: stack.append(c) if len(adj[p]) == 0 : dp[p] = (provide[p], 0, 1) stack.pop() leafCnt += 1 if leafCnt ==1 : print(sum(provide)) else: print(dp[1][0]) # print(dp) ```
instruction
0
61,681
1
123,362
No
output
1
61,681
1
123,363
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bandits appeared in the city! One of them is trying to catch as many citizens as he can. The city consists of n squares connected by n-1 roads in such a way that it is possible to reach any square from any other square. The square number 1 is the main square. After Sunday walk all the roads were changed to one-way roads in such a way that it is possible to reach any square from the main square. At the moment when the bandit appeared on the main square there were a_i citizens on the i-th square. Now the following process will begin. First, each citizen that is currently on a square with some outgoing one-way roads chooses one of such roads and moves along it to another square. Then the bandit chooses one of the one-way roads outgoing from the square he is located and moves along it. The process is repeated until the bandit is located on a square with no outgoing roads. The bandit catches all the citizens on that square. The bandit wants to catch as many citizens as possible; the citizens want to minimize the number of caught people. The bandit and the citizens know positions of all citizens at any time, the citizens can cooperate. If both sides act optimally, how many citizens will be caught? Input The first line contains a single integer n β€” the number of squares in the city (2 ≀ n ≀ 2β‹…10^5). The second line contains n-1 integers p_2, p_3 ... p_n meaning that there is a one-way road from the square p_i to the square i (1 ≀ p_i < i). The third line contains n integers a_1, a_2, ..., a_n β€” the number of citizens on each square initially (0 ≀ a_i ≀ 10^9). Output Print a single integer β€” the number of citizens the bandit will catch if both sides act optimally. Examples Input 3 1 1 3 1 2 Output 3 Input 3 1 1 3 1 3 Output 4 Note In the first example the citizens on the square 1 can split into two groups 2 + 1, so that the second and on the third squares will have 3 citizens each. In the second example no matter how citizens act the bandit can catch at least 4 citizens. Submitted Solution: ``` from bisect import bisect_left as bl from bisect import bisect_right as br from heapq import heappush,heappop import math from collections import * from functools import reduce,cmp_to_key import sys input = sys.stdin.readline M = mod = 998244353 def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))) def inv_mod(n):return pow(n, mod - 2, mod) def li():return [int(i) for i in input().rstrip('\n').split()] def st():return input().rstrip('\n') def val():return int(input().rstrip('\n')) def li2():return [i for i in input().rstrip('\n')] def li3():return [int(i) for i in input().rstrip('\n')] n = val() parents = [1, 1] + li() values = [0] + li() sizes = [1] * (n + 5) for i in range(2, n + 1, 1): sizes[parents[i]] = 0 ans = -float('inf') for i in range(n, 1, -1): ans = max(ans, (values[i] + sizes[i] - 1) / sizes[i]) values[parents[i]] += values[i] sizes[parents[i]] += sizes[i] print(int(ans)) ```
instruction
0
61,682
1
123,364
No
output
1
61,682
1
123,365
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n cities on a two dimensional Cartesian plane. The distance between two cities is equal to the Manhattan distance between them (see the Notes for definition). A Hamiltonian cycle of the cities is defined as a permutation of all n cities. The length of this Hamiltonian cycle is defined as the sum of the distances between adjacent cities in the permutation plus the distance between the first and final city in the permutation. Please compute the longest possible length of a Hamiltonian cycle of the given cities. Input The first line contains an integer n (3 ≀ n ≀ 105). Then n lines follow, each consisting of two integers xi and yi (0 ≀ xi, yi ≀ 109), denoting the coordinates of a city. All given points will be distinct. Output A single line denoting the longest possible length of a Hamiltonian cycle of the given cities. You should not output the cycle, only its length. Please, do not write the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. Examples Input 4 1 1 1 2 2 1 2 2 Output 6 Note In the example, one of the possible Hamiltonian cycles with length 6 is (1, 1) (1, 2) (2, 1) (2, 2). There does not exist any other Hamiltonian cycle with a length greater than 6. The Manhattan distance between two cities (xi, yi) and (xj, yj) is |xi - xj| + |yi - yj|. Submitted Solution: ``` n = int(input()) a = [] x=y=0 for i in range(n): a += [[int(x) for x in input().split()]] for i in range(n): x += abs(a[i][0]) y += abs(a[i][1]) print((x+y)//2) ```
instruction
0
61,753
1
123,506
No
output
1
61,753
1
123,507
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n cities on a two dimensional Cartesian plane. The distance between two cities is equal to the Manhattan distance between them (see the Notes for definition). A Hamiltonian cycle of the cities is defined as a permutation of all n cities. The length of this Hamiltonian cycle is defined as the sum of the distances between adjacent cities in the permutation plus the distance between the first and final city in the permutation. Please compute the longest possible length of a Hamiltonian cycle of the given cities. Input The first line contains an integer n (3 ≀ n ≀ 105). Then n lines follow, each consisting of two integers xi and yi (0 ≀ xi, yi ≀ 109), denoting the coordinates of a city. All given points will be distinct. Output A single line denoting the longest possible length of a Hamiltonian cycle of the given cities. You should not output the cycle, only its length. Please, do not write the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. Examples Input 4 1 1 1 2 2 1 2 2 Output 6 Note In the example, one of the possible Hamiltonian cycles with length 6 is (1, 1) (1, 2) (2, 1) (2, 2). There does not exist any other Hamiltonian cycle with a length greater than 6. The Manhattan distance between two cities (xi, yi) and (xj, yj) is |xi - xj| + |yi - yj|. Submitted Solution: ``` #https://codeforces.com/problemset/problem/329/E n = int(input()) a = [] x=y=0 for i in range(n): a += [[int(x) for x in input().split()]] for i in range(n): x += abs(a[i][0]) y += abs(a[i][1]) print((x+y)//2) ```
instruction
0
61,754
1
123,508
No
output
1
61,754
1
123,509
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n cities on a two dimensional Cartesian plane. The distance between two cities is equal to the Manhattan distance between them (see the Notes for definition). A Hamiltonian cycle of the cities is defined as a permutation of all n cities. The length of this Hamiltonian cycle is defined as the sum of the distances between adjacent cities in the permutation plus the distance between the first and final city in the permutation. Please compute the longest possible length of a Hamiltonian cycle of the given cities. Input The first line contains an integer n (3 ≀ n ≀ 105). Then n lines follow, each consisting of two integers xi and yi (0 ≀ xi, yi ≀ 109), denoting the coordinates of a city. All given points will be distinct. Output A single line denoting the longest possible length of a Hamiltonian cycle of the given cities. You should not output the cycle, only its length. Please, do not write the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. Examples Input 4 1 1 1 2 2 1 2 2 Output 6 Note In the example, one of the possible Hamiltonian cycles with length 6 is (1, 1) (1, 2) (2, 1) (2, 2). There does not exist any other Hamiltonian cycle with a length greater than 6. The Manhattan distance between two cities (xi, yi) and (xj, yj) is |xi - xj| + |yi - yj|. Submitted Solution: ``` #https://codeforces.com/problemset/problem/329/E n = int(input()) lst = [] x=0 y=0 for i in range(n): lst += [[int(x) for x in input().split()]] for i in range(n): x += abs(lst[i][0]) y += abs(lst[i][1]) print((x+y)//2) ```
instruction
0
61,755
1
123,510
No
output
1
61,755
1
123,511
Provide tags and a correct Python 3 solution for this coding contest problem. Vasiliy lives at point (a, b) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested n available Beru-taxi nearby. The i-th taxi is located at point (xi, yi) and moves with a speed vi. Consider that each of n drivers will move directly to Vasiliy and with a maximum possible speed. Compute the minimum time when Vasiliy will get in any of Beru-taxi cars. Input The first line of the input contains two integers a and b ( - 100 ≀ a, b ≀ 100) β€” coordinates of Vasiliy's home. The second line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of available Beru-taxi cars nearby. The i-th of the following n lines contains three integers xi, yi and vi ( - 100 ≀ xi, yi ≀ 100, 1 ≀ vi ≀ 100) β€” the coordinates of the i-th car and its speed. It's allowed that several cars are located at the same point. Also, cars may be located at exactly the same point where Vasiliy lives. Output Print a single real value β€” the minimum time Vasiliy needs to get in any of the Beru-taxi cars. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 2 2 0 1 0 2 2 Output 1.00000000000000000000 Input 1 3 3 3 3 2 -2 3 6 -2 7 10 Output 0.50000000000000000000 Note In the first sample, first taxi will get to Vasiliy in time 2, and second will do this in time 1, therefore 1 is the answer. In the second sample, cars 2 and 3 will arrive simultaneously.
instruction
0
61,927
1
123,854
Tags: brute force, geometry, implementation Correct Solution: ``` # sqrt((x2-x1)**2 + (y2-y1)**2) a, b = map(int, input().split()) m = float("inf") n = int(input()) for _ in range(n): x, y, v = map(int, input().split()) dist = ((a-x)**2+(b-y)**2)**0.5 m = min(m, dist/v) print('%.6f' % m) ```
output
1
61,927
1
123,855
Provide tags and a correct Python 3 solution for this coding contest problem. Vasiliy lives at point (a, b) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested n available Beru-taxi nearby. The i-th taxi is located at point (xi, yi) and moves with a speed vi. Consider that each of n drivers will move directly to Vasiliy and with a maximum possible speed. Compute the minimum time when Vasiliy will get in any of Beru-taxi cars. Input The first line of the input contains two integers a and b ( - 100 ≀ a, b ≀ 100) β€” coordinates of Vasiliy's home. The second line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of available Beru-taxi cars nearby. The i-th of the following n lines contains three integers xi, yi and vi ( - 100 ≀ xi, yi ≀ 100, 1 ≀ vi ≀ 100) β€” the coordinates of the i-th car and its speed. It's allowed that several cars are located at the same point. Also, cars may be located at exactly the same point where Vasiliy lives. Output Print a single real value β€” the minimum time Vasiliy needs to get in any of the Beru-taxi cars. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 2 2 0 1 0 2 2 Output 1.00000000000000000000 Input 1 3 3 3 3 2 -2 3 6 -2 7 10 Output 0.50000000000000000000 Note In the first sample, first taxi will get to Vasiliy in time 2, and second will do this in time 1, therefore 1 is the answer. In the second sample, cars 2 and 3 will arrive simultaneously.
instruction
0
61,928
1
123,856
Tags: brute force, geometry, implementation Correct Solution: ``` import math; def calLength(p1, p2): l = math.pow(p1[0] - p2[0], 2) + math.pow(p1[1] - p2[1], 2); return math.sqrt(l); def main(): getS = input(); getS = getS.split(); a = int(getS[0]); b = int(getS[1]); n = int(input()); v = [a, b]; taxi = []; for i in range(0, n): ta = []; getS = input(); getS = getS.split(); ta.append(int(getS[0])); ta.append(int(getS[1])); ta.append(int(getS[2])); taxi.append(ta); re = False; for i in range(0, len(taxi)): t = calLength(v, taxi[i]) / taxi[i][2]; #print (calLength(v, taxi[i]) / taxi[i][2]); if t == 0: print (0); return; if (re == False) or (re != False and re > t): re = t; print (float(re)); main(); ```
output
1
61,928
1
123,857
Provide tags and a correct Python 3 solution for this coding contest problem. Vasiliy lives at point (a, b) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested n available Beru-taxi nearby. The i-th taxi is located at point (xi, yi) and moves with a speed vi. Consider that each of n drivers will move directly to Vasiliy and with a maximum possible speed. Compute the minimum time when Vasiliy will get in any of Beru-taxi cars. Input The first line of the input contains two integers a and b ( - 100 ≀ a, b ≀ 100) β€” coordinates of Vasiliy's home. The second line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of available Beru-taxi cars nearby. The i-th of the following n lines contains three integers xi, yi and vi ( - 100 ≀ xi, yi ≀ 100, 1 ≀ vi ≀ 100) β€” the coordinates of the i-th car and its speed. It's allowed that several cars are located at the same point. Also, cars may be located at exactly the same point where Vasiliy lives. Output Print a single real value β€” the minimum time Vasiliy needs to get in any of the Beru-taxi cars. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 2 2 0 1 0 2 2 Output 1.00000000000000000000 Input 1 3 3 3 3 2 -2 3 6 -2 7 10 Output 0.50000000000000000000 Note In the first sample, first taxi will get to Vasiliy in time 2, and second will do this in time 1, therefore 1 is the answer. In the second sample, cars 2 and 3 will arrive simultaneously.
instruction
0
61,929
1
123,858
Tags: brute force, geometry, implementation Correct Solution: ``` import sys from math import sqrt (a,b) = map(int,input().split()) n = int(input()) mini = 99999 for i in range(n): (x,y,v) = map(int, input().split()) t = sqrt( (x-a)**2 + (y - b)**2) / (v * 1.00000000000000000000) if t < mini: mini = t print(mini) ```
output
1
61,929
1
123,859
Provide tags and a correct Python 3 solution for this coding contest problem. Vasiliy lives at point (a, b) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested n available Beru-taxi nearby. The i-th taxi is located at point (xi, yi) and moves with a speed vi. Consider that each of n drivers will move directly to Vasiliy and with a maximum possible speed. Compute the minimum time when Vasiliy will get in any of Beru-taxi cars. Input The first line of the input contains two integers a and b ( - 100 ≀ a, b ≀ 100) β€” coordinates of Vasiliy's home. The second line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of available Beru-taxi cars nearby. The i-th of the following n lines contains three integers xi, yi and vi ( - 100 ≀ xi, yi ≀ 100, 1 ≀ vi ≀ 100) β€” the coordinates of the i-th car and its speed. It's allowed that several cars are located at the same point. Also, cars may be located at exactly the same point where Vasiliy lives. Output Print a single real value β€” the minimum time Vasiliy needs to get in any of the Beru-taxi cars. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 2 2 0 1 0 2 2 Output 1.00000000000000000000 Input 1 3 3 3 3 2 -2 3 6 -2 7 10 Output 0.50000000000000000000 Note In the first sample, first taxi will get to Vasiliy in time 2, and second will do this in time 1, therefore 1 is the answer. In the second sample, cars 2 and 3 will arrive simultaneously.
instruction
0
61,930
1
123,860
Tags: brute force, geometry, implementation Correct Solution: ``` x,y=map(int,input().split()) n=int(input()) mi=11**11 for _ in range(n): xt,yt,v=map(int,input().split()) t=((x-xt)**2+(y-yt)**2)**0.5/v if t<mi: mi=t print(mi) ```
output
1
61,930
1
123,861
Provide tags and a correct Python 3 solution for this coding contest problem. Vasiliy lives at point (a, b) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested n available Beru-taxi nearby. The i-th taxi is located at point (xi, yi) and moves with a speed vi. Consider that each of n drivers will move directly to Vasiliy and with a maximum possible speed. Compute the minimum time when Vasiliy will get in any of Beru-taxi cars. Input The first line of the input contains two integers a and b ( - 100 ≀ a, b ≀ 100) β€” coordinates of Vasiliy's home. The second line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of available Beru-taxi cars nearby. The i-th of the following n lines contains three integers xi, yi and vi ( - 100 ≀ xi, yi ≀ 100, 1 ≀ vi ≀ 100) β€” the coordinates of the i-th car and its speed. It's allowed that several cars are located at the same point. Also, cars may be located at exactly the same point where Vasiliy lives. Output Print a single real value β€” the minimum time Vasiliy needs to get in any of the Beru-taxi cars. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 2 2 0 1 0 2 2 Output 1.00000000000000000000 Input 1 3 3 3 3 2 -2 3 6 -2 7 10 Output 0.50000000000000000000 Note In the first sample, first taxi will get to Vasiliy in time 2, and second will do this in time 1, therefore 1 is the answer. In the second sample, cars 2 and 3 will arrive simultaneously.
instruction
0
61,931
1
123,862
Tags: brute force, geometry, implementation Correct Solution: ``` import math CarPos = [] def LeastTime(x,y,n,CarPos): time = [] for i in range(n): for j in range(3): dis = math.sqrt((CarPos[i] [0] - x )**2 + (CarPos[i] [1] - y )**2 ) t = dis / CarPos[i] [2] time.append(t) return min(time) x,y = [int(a) for a in input().split() ] n = int(input() ) CarVal = [ ] # CarVal[0] = x # CarVal[1] = y # CarVal[2] = v for i in range(n): row = [int(a) for a in input().split() ] CarVal.append(row) print(LeastTime(x,y,n,CarVal) ) ```
output
1
61,931
1
123,863
Provide tags and a correct Python 3 solution for this coding contest problem. Vasiliy lives at point (a, b) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested n available Beru-taxi nearby. The i-th taxi is located at point (xi, yi) and moves with a speed vi. Consider that each of n drivers will move directly to Vasiliy and with a maximum possible speed. Compute the minimum time when Vasiliy will get in any of Beru-taxi cars. Input The first line of the input contains two integers a and b ( - 100 ≀ a, b ≀ 100) β€” coordinates of Vasiliy's home. The second line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of available Beru-taxi cars nearby. The i-th of the following n lines contains three integers xi, yi and vi ( - 100 ≀ xi, yi ≀ 100, 1 ≀ vi ≀ 100) β€” the coordinates of the i-th car and its speed. It's allowed that several cars are located at the same point. Also, cars may be located at exactly the same point where Vasiliy lives. Output Print a single real value β€” the minimum time Vasiliy needs to get in any of the Beru-taxi cars. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 2 2 0 1 0 2 2 Output 1.00000000000000000000 Input 1 3 3 3 3 2 -2 3 6 -2 7 10 Output 0.50000000000000000000 Note In the first sample, first taxi will get to Vasiliy in time 2, and second will do this in time 1, therefore 1 is the answer. In the second sample, cars 2 and 3 will arrive simultaneously.
instruction
0
61,932
1
123,864
Tags: brute force, geometry, implementation Correct Solution: ``` import math as m hx, hy = map(int, input().split()); n = int(input()); res = 1000; for i in range(n): x, y, v = map(int, input().split()); res = min((m.sqrt(pow((hx - x),2) + pow((hy - y), 2)))/v, res); print(res) ```
output
1
61,932
1
123,865
Provide tags and a correct Python 3 solution for this coding contest problem. Vasiliy lives at point (a, b) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested n available Beru-taxi nearby. The i-th taxi is located at point (xi, yi) and moves with a speed vi. Consider that each of n drivers will move directly to Vasiliy and with a maximum possible speed. Compute the minimum time when Vasiliy will get in any of Beru-taxi cars. Input The first line of the input contains two integers a and b ( - 100 ≀ a, b ≀ 100) β€” coordinates of Vasiliy's home. The second line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of available Beru-taxi cars nearby. The i-th of the following n lines contains three integers xi, yi and vi ( - 100 ≀ xi, yi ≀ 100, 1 ≀ vi ≀ 100) β€” the coordinates of the i-th car and its speed. It's allowed that several cars are located at the same point. Also, cars may be located at exactly the same point where Vasiliy lives. Output Print a single real value β€” the minimum time Vasiliy needs to get in any of the Beru-taxi cars. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 2 2 0 1 0 2 2 Output 1.00000000000000000000 Input 1 3 3 3 3 2 -2 3 6 -2 7 10 Output 0.50000000000000000000 Note In the first sample, first taxi will get to Vasiliy in time 2, and second will do this in time 1, therefore 1 is the answer. In the second sample, cars 2 and 3 will arrive simultaneously.
instruction
0
61,933
1
123,866
Tags: brute force, geometry, implementation Correct Solution: ``` x,y =map(int, input().split()) n = int(input()) op = 10000.0 for i in range(n): a,b,v = map(int , input().split()) d = ( (a-x)**2 + (b-y)**2 )** 0.5 #print(d,a,b,v,x,y) if (i==1): op = d/v elif(op > d/v): op = d/v print("%.20f"%op) ```
output
1
61,933
1
123,867
Provide tags and a correct Python 3 solution for this coding contest problem. Vasiliy lives at point (a, b) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested n available Beru-taxi nearby. The i-th taxi is located at point (xi, yi) and moves with a speed vi. Consider that each of n drivers will move directly to Vasiliy and with a maximum possible speed. Compute the minimum time when Vasiliy will get in any of Beru-taxi cars. Input The first line of the input contains two integers a and b ( - 100 ≀ a, b ≀ 100) β€” coordinates of Vasiliy's home. The second line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of available Beru-taxi cars nearby. The i-th of the following n lines contains three integers xi, yi and vi ( - 100 ≀ xi, yi ≀ 100, 1 ≀ vi ≀ 100) β€” the coordinates of the i-th car and its speed. It's allowed that several cars are located at the same point. Also, cars may be located at exactly the same point where Vasiliy lives. Output Print a single real value β€” the minimum time Vasiliy needs to get in any of the Beru-taxi cars. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 2 2 0 1 0 2 2 Output 1.00000000000000000000 Input 1 3 3 3 3 2 -2 3 6 -2 7 10 Output 0.50000000000000000000 Note In the first sample, first taxi will get to Vasiliy in time 2, and second will do this in time 1, therefore 1 is the answer. In the second sample, cars 2 and 3 will arrive simultaneously.
instruction
0
61,934
1
123,868
Tags: brute force, geometry, implementation Correct Solution: ``` from math import sqrt a, b = map(int, input().split()) n = int(input()) best_time = 999999999 for _ in range(n): x, y, v = map(int, input().split()) time = sqrt((a-x) ** 2 + (b-y) ** 2) / v if time < best_time: best_time = time print(best_time) ```
output
1
61,934
1
123,869
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasiliy lives at point (a, b) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested n available Beru-taxi nearby. The i-th taxi is located at point (xi, yi) and moves with a speed vi. Consider that each of n drivers will move directly to Vasiliy and with a maximum possible speed. Compute the minimum time when Vasiliy will get in any of Beru-taxi cars. Input The first line of the input contains two integers a and b ( - 100 ≀ a, b ≀ 100) β€” coordinates of Vasiliy's home. The second line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of available Beru-taxi cars nearby. The i-th of the following n lines contains three integers xi, yi and vi ( - 100 ≀ xi, yi ≀ 100, 1 ≀ vi ≀ 100) β€” the coordinates of the i-th car and its speed. It's allowed that several cars are located at the same point. Also, cars may be located at exactly the same point where Vasiliy lives. Output Print a single real value β€” the minimum time Vasiliy needs to get in any of the Beru-taxi cars. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 2 2 0 1 0 2 2 Output 1.00000000000000000000 Input 1 3 3 3 3 2 -2 3 6 -2 7 10 Output 0.50000000000000000000 Note In the first sample, first taxi will get to Vasiliy in time 2, and second will do this in time 1, therefore 1 is the answer. In the second sample, cars 2 and 3 will arrive simultaneously. Submitted Solution: ``` a,b=(int(i)for i in input().split()) n=int(input()) k=500 for i in range(n): c,d,v=map(int,input().split()) k=min(k,(((a-c)**2+(b-d)**2)**0.5)/v ) print(k) ```
instruction
0
61,935
1
123,870
Yes
output
1
61,935
1
123,871
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasiliy lives at point (a, b) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested n available Beru-taxi nearby. The i-th taxi is located at point (xi, yi) and moves with a speed vi. Consider that each of n drivers will move directly to Vasiliy and with a maximum possible speed. Compute the minimum time when Vasiliy will get in any of Beru-taxi cars. Input The first line of the input contains two integers a and b ( - 100 ≀ a, b ≀ 100) β€” coordinates of Vasiliy's home. The second line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of available Beru-taxi cars nearby. The i-th of the following n lines contains three integers xi, yi and vi ( - 100 ≀ xi, yi ≀ 100, 1 ≀ vi ≀ 100) β€” the coordinates of the i-th car and its speed. It's allowed that several cars are located at the same point. Also, cars may be located at exactly the same point where Vasiliy lives. Output Print a single real value β€” the minimum time Vasiliy needs to get in any of the Beru-taxi cars. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 2 2 0 1 0 2 2 Output 1.00000000000000000000 Input 1 3 3 3 3 2 -2 3 6 -2 7 10 Output 0.50000000000000000000 Note In the first sample, first taxi will get to Vasiliy in time 2, and second will do this in time 1, therefore 1 is the answer. In the second sample, cars 2 and 3 will arrive simultaneously. Submitted Solution: ``` import math a,b=map(int,input().split()) n=int(input()) ans=10000000000000000000000000000000000000000000000000 for _ in range(n): x,y,v=map(int,input().split()) ans = min(ans,math.pow(math.pow(a-x,2)+math.pow(b-y,2),.5)/v) print("{0:.20f}".format(ans)) ```
instruction
0
61,936
1
123,872
Yes
output
1
61,936
1
123,873
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasiliy lives at point (a, b) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested n available Beru-taxi nearby. The i-th taxi is located at point (xi, yi) and moves with a speed vi. Consider that each of n drivers will move directly to Vasiliy and with a maximum possible speed. Compute the minimum time when Vasiliy will get in any of Beru-taxi cars. Input The first line of the input contains two integers a and b ( - 100 ≀ a, b ≀ 100) β€” coordinates of Vasiliy's home. The second line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of available Beru-taxi cars nearby. The i-th of the following n lines contains three integers xi, yi and vi ( - 100 ≀ xi, yi ≀ 100, 1 ≀ vi ≀ 100) β€” the coordinates of the i-th car and its speed. It's allowed that several cars are located at the same point. Also, cars may be located at exactly the same point where Vasiliy lives. Output Print a single real value β€” the minimum time Vasiliy needs to get in any of the Beru-taxi cars. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 2 2 0 1 0 2 2 Output 1.00000000000000000000 Input 1 3 3 3 3 2 -2 3 6 -2 7 10 Output 0.50000000000000000000 Note In the first sample, first taxi will get to Vasiliy in time 2, and second will do this in time 1, therefore 1 is the answer. In the second sample, cars 2 and 3 will arrive simultaneously. Submitted Solution: ``` from math import sqrt x,y = map(int,input().split()) n = int(input()) t = 10**9 for i in range(n): j,k,v = map(int,input().split()) d = sqrt((x-j)**2 + (y-k)**2)/v t = min(t,d) print(t) ```
instruction
0
61,937
1
123,874
Yes
output
1
61,937
1
123,875
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasiliy lives at point (a, b) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested n available Beru-taxi nearby. The i-th taxi is located at point (xi, yi) and moves with a speed vi. Consider that each of n drivers will move directly to Vasiliy and with a maximum possible speed. Compute the minimum time when Vasiliy will get in any of Beru-taxi cars. Input The first line of the input contains two integers a and b ( - 100 ≀ a, b ≀ 100) β€” coordinates of Vasiliy's home. The second line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of available Beru-taxi cars nearby. The i-th of the following n lines contains three integers xi, yi and vi ( - 100 ≀ xi, yi ≀ 100, 1 ≀ vi ≀ 100) β€” the coordinates of the i-th car and its speed. It's allowed that several cars are located at the same point. Also, cars may be located at exactly the same point where Vasiliy lives. Output Print a single real value β€” the minimum time Vasiliy needs to get in any of the Beru-taxi cars. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 2 2 0 1 0 2 2 Output 1.00000000000000000000 Input 1 3 3 3 3 2 -2 3 6 -2 7 10 Output 0.50000000000000000000 Note In the first sample, first taxi will get to Vasiliy in time 2, and second will do this in time 1, therefore 1 is the answer. In the second sample, cars 2 and 3 will arrive simultaneously. Submitted Solution: ``` import math, sys def solve(): bx,by = map(int, input().split()) dist = lambda f1, f2, v: math.sqrt(f1*f1+f2*f2) / v n = int(input()) ans = sys.maxsize for _ in range(n): x,y,v = map(int, input().split()) ans = min(ans, dist(x-bx, y-by,v)) return ans print(solve()) ```
instruction
0
61,938
1
123,876
Yes
output
1
61,938
1
123,877
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasiliy lives at point (a, b) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested n available Beru-taxi nearby. The i-th taxi is located at point (xi, yi) and moves with a speed vi. Consider that each of n drivers will move directly to Vasiliy and with a maximum possible speed. Compute the minimum time when Vasiliy will get in any of Beru-taxi cars. Input The first line of the input contains two integers a and b ( - 100 ≀ a, b ≀ 100) β€” coordinates of Vasiliy's home. The second line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of available Beru-taxi cars nearby. The i-th of the following n lines contains three integers xi, yi and vi ( - 100 ≀ xi, yi ≀ 100, 1 ≀ vi ≀ 100) β€” the coordinates of the i-th car and its speed. It's allowed that several cars are located at the same point. Also, cars may be located at exactly the same point where Vasiliy lives. Output Print a single real value β€” the minimum time Vasiliy needs to get in any of the Beru-taxi cars. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 2 2 0 1 0 2 2 Output 1.00000000000000000000 Input 1 3 3 3 3 2 -2 3 6 -2 7 10 Output 0.50000000000000000000 Note In the first sample, first taxi will get to Vasiliy in time 2, and second will do this in time 1, therefore 1 is the answer. In the second sample, cars 2 and 3 will arrive simultaneously. Submitted Solution: ``` import math a,b = map(int, input().split()) n = int(input()) min = 100000000 for i in range(n): x, y, v = map(int, input().split()) x1 = math.fabs(x - a) y1 = math.fabs(y - b) dist = math.sqrt(x1 * x1 + y1 * y1) time = dist / v if time < min: min = time print(time) ```
instruction
0
61,939
1
123,878
No
output
1
61,939
1
123,879
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasiliy lives at point (a, b) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested n available Beru-taxi nearby. The i-th taxi is located at point (xi, yi) and moves with a speed vi. Consider that each of n drivers will move directly to Vasiliy and with a maximum possible speed. Compute the minimum time when Vasiliy will get in any of Beru-taxi cars. Input The first line of the input contains two integers a and b ( - 100 ≀ a, b ≀ 100) β€” coordinates of Vasiliy's home. The second line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of available Beru-taxi cars nearby. The i-th of the following n lines contains three integers xi, yi and vi ( - 100 ≀ xi, yi ≀ 100, 1 ≀ vi ≀ 100) β€” the coordinates of the i-th car and its speed. It's allowed that several cars are located at the same point. Also, cars may be located at exactly the same point where Vasiliy lives. Output Print a single real value β€” the minimum time Vasiliy needs to get in any of the Beru-taxi cars. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 2 2 0 1 0 2 2 Output 1.00000000000000000000 Input 1 3 3 3 3 2 -2 3 6 -2 7 10 Output 0.50000000000000000000 Note In the first sample, first taxi will get to Vasiliy in time 2, and second will do this in time 1, therefore 1 is the answer. In the second sample, cars 2 and 3 will arrive simultaneously. Submitted Solution: ``` import math a, b = input().split() a = int(a) b = int(b) n = input() n = int(n) min = 999999999999999999999999999999999999999999 for i in range(n): x, y, z = input().split() x = int(x) y = int(y) z = int(z) d = (math.sqrt((a - x)**2 + (b - y)**2))/z if min > d: min = d print(d) ```
instruction
0
61,940
1
123,880
No
output
1
61,940
1
123,881
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasiliy lives at point (a, b) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested n available Beru-taxi nearby. The i-th taxi is located at point (xi, yi) and moves with a speed vi. Consider that each of n drivers will move directly to Vasiliy and with a maximum possible speed. Compute the minimum time when Vasiliy will get in any of Beru-taxi cars. Input The first line of the input contains two integers a and b ( - 100 ≀ a, b ≀ 100) β€” coordinates of Vasiliy's home. The second line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of available Beru-taxi cars nearby. The i-th of the following n lines contains three integers xi, yi and vi ( - 100 ≀ xi, yi ≀ 100, 1 ≀ vi ≀ 100) β€” the coordinates of the i-th car and its speed. It's allowed that several cars are located at the same point. Also, cars may be located at exactly the same point where Vasiliy lives. Output Print a single real value β€” the minimum time Vasiliy needs to get in any of the Beru-taxi cars. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 2 2 0 1 0 2 2 Output 1.00000000000000000000 Input 1 3 3 3 3 2 -2 3 6 -2 7 10 Output 0.50000000000000000000 Note In the first sample, first taxi will get to Vasiliy in time 2, and second will do this in time 1, therefore 1 is the answer. In the second sample, cars 2 and 3 will arrive simultaneously. Submitted Solution: ``` a, b = map(int, input().split()) #coordinates of home n = int(input()) #avaiable taxies in nearby c = [] for i in range(n): x, y, v = map(int, input().split()) tx = abs((a-x)) / v ty = abs((b-y)) / v c.append(tx+ty) print(min(c)) ```
instruction
0
61,941
1
123,882
No
output
1
61,941
1
123,883
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasiliy lives at point (a, b) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested n available Beru-taxi nearby. The i-th taxi is located at point (xi, yi) and moves with a speed vi. Consider that each of n drivers will move directly to Vasiliy and with a maximum possible speed. Compute the minimum time when Vasiliy will get in any of Beru-taxi cars. Input The first line of the input contains two integers a and b ( - 100 ≀ a, b ≀ 100) β€” coordinates of Vasiliy's home. The second line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of available Beru-taxi cars nearby. The i-th of the following n lines contains three integers xi, yi and vi ( - 100 ≀ xi, yi ≀ 100, 1 ≀ vi ≀ 100) β€” the coordinates of the i-th car and its speed. It's allowed that several cars are located at the same point. Also, cars may be located at exactly the same point where Vasiliy lives. Output Print a single real value β€” the minimum time Vasiliy needs to get in any of the Beru-taxi cars. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 0 0 2 2 0 1 0 2 2 Output 1.00000000000000000000 Input 1 3 3 3 3 2 -2 3 6 -2 7 10 Output 0.50000000000000000000 Note In the first sample, first taxi will get to Vasiliy in time 2, and second will do this in time 1, therefore 1 is the answer. In the second sample, cars 2 and 3 will arrive simultaneously. Submitted Solution: ``` from math import sqrt coords = [int(i) for i in input().strip().split(' ')] n = int(input().strip()) taxi_coords = [] for i in range(n): taxi_coords.append([int(j) for j in input().strip().split(' ')]) my_min = sqrt((coords[0] - taxi_coords[0][0]) ** 2 + (coords[1] - taxi_coords[0][1]) ** 2) / taxi_coords[0][2] for taxi in taxi_coords: distance = sqrt((coords[0] - taxi[0]) ** 2 + (coords[1] - taxi[1]) ** 2) / taxi[2] if distance < my_min: my_min = distance print(distance) ```
instruction
0
61,942
1
123,884
No
output
1
61,942
1
123,885
Provide a correct Python 3 solution for this coding contest problem. There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once. Constraints * 1 \leq a_i,b_i \leq 4(1\leq i\leq 3) * a_i and b_i are different. (1\leq i\leq 3) * No two roads connect the same pair of towns. * Any town can be reached from any other town using the roads. Input Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3 Output If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. Examples Input 4 2 1 3 2 3 Output YES Input 3 2 2 4 1 2 Output NO Input 2 1 3 2 4 3 Output YES
instruction
0
62,093
1
124,186
"Correct Solution: ``` t = [0] * 4 for i in range(3): a, b = map(int, input().split()) t[a - 1] += 1 t[b - 1] += 1 print('NO') if max(t)==3 else print('YES') ```
output
1
62,093
1
124,187
Provide a correct Python 3 solution for this coding contest problem. There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once. Constraints * 1 \leq a_i,b_i \leq 4(1\leq i\leq 3) * a_i and b_i are different. (1\leq i\leq 3) * No two roads connect the same pair of towns. * Any town can be reached from any other town using the roads. Input Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3 Output If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. Examples Input 4 2 1 3 2 3 Output YES Input 3 2 2 4 1 2 Output NO Input 2 1 3 2 4 3 Output YES
instruction
0
62,094
1
124,188
"Correct Solution: ``` a=[0]*4 for i in range(3): x,y=map(int,input().split()) a[x-1]+=1 a[y-1]+=1 c=0 for i in range(4): if a[i]%2!=0: c+=1 if c==0 or c==2: print("YES") else: print("NO") ```
output
1
62,094
1
124,189
Provide a correct Python 3 solution for this coding contest problem. There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once. Constraints * 1 \leq a_i,b_i \leq 4(1\leq i\leq 3) * a_i and b_i are different. (1\leq i\leq 3) * No two roads connect the same pair of towns. * Any town can be reached from any other town using the roads. Input Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3 Output If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. Examples Input 4 2 1 3 2 3 Output YES Input 3 2 2 4 1 2 Output NO Input 2 1 3 2 4 3 Output YES
instruction
0
62,095
1
124,190
"Correct Solution: ``` c = [0]*4 for i in range(3): a,b = map(int,input().split()) c[a-1] += 1 c[b-1] += 1 c.sort() print('YES' if c==[1,1,2,2] else 'NO') ```
output
1
62,095
1
124,191
Provide a correct Python 3 solution for this coding contest problem. There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once. Constraints * 1 \leq a_i,b_i \leq 4(1\leq i\leq 3) * a_i and b_i are different. (1\leq i\leq 3) * No two roads connect the same pair of towns. * Any town can be reached from any other town using the roads. Input Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3 Output If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. Examples Input 4 2 1 3 2 3 Output YES Input 3 2 2 4 1 2 Output NO Input 2 1 3 2 4 3 Output YES
instruction
0
62,096
1
124,192
"Correct Solution: ``` town = [0] * 4 for _ in range(3): a, b = map(int, input().split()) town[a-1] += 1 town[b-1] += 1 if 3 in town or 4 in town: ans = 'NO' else: ans = 'YES' print(ans) ```
output
1
62,096
1
124,193
Provide a correct Python 3 solution for this coding contest problem. There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once. Constraints * 1 \leq a_i,b_i \leq 4(1\leq i\leq 3) * a_i and b_i are different. (1\leq i\leq 3) * No two roads connect the same pair of towns. * Any town can be reached from any other town using the roads. Input Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3 Output If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. Examples Input 4 2 1 3 2 3 Output YES Input 3 2 2 4 1 2 Output NO Input 2 1 3 2 4 3 Output YES
instruction
0
62,097
1
124,194
"Correct Solution: ``` X=[0]*4 for i in range(3): A,B=map(int,input().split()) X[A-1]+=1 X[B-1]+=1 X.sort() if(X[0]==1 and X[1]==1 and X[2]==2): print("YES") else: print("NO") ```
output
1
62,097
1
124,195
Provide a correct Python 3 solution for this coding contest problem. There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once. Constraints * 1 \leq a_i,b_i \leq 4(1\leq i\leq 3) * a_i and b_i are different. (1\leq i\leq 3) * No two roads connect the same pair of towns. * Any town can be reached from any other town using the roads. Input Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3 Output If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. Examples Input 4 2 1 3 2 3 Output YES Input 3 2 2 4 1 2 Output NO Input 2 1 3 2 4 3 Output YES
instruction
0
62,098
1
124,196
"Correct Solution: ``` X = [0 for _ in range(4)] for _ in range(3): a, b = [int(_) for _ in input().split()] X[a-1] += 1 X[b-1] += 1 if max(X) > 2: print("NO") else: print("YES") ```
output
1
62,098
1
124,197
Provide a correct Python 3 solution for this coding contest problem. There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once. Constraints * 1 \leq a_i,b_i \leq 4(1\leq i\leq 3) * a_i and b_i are different. (1\leq i\leq 3) * No two roads connect the same pair of towns. * Any town can be reached from any other town using the roads. Input Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3 Output If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. Examples Input 4 2 1 3 2 3 Output YES Input 3 2 2 4 1 2 Output NO Input 2 1 3 2 4 3 Output YES
instruction
0
62,099
1
124,198
"Correct Solution: ``` g=[0]*5 import sys input=sys.stdin.readline for _ in range(3): a,b=map(int,input().split()) g[a]+=1 g[b]+=1 if g.count(1)==2: print("YES") else: print("NO") ```
output
1
62,099
1
124,199
Provide a correct Python 3 solution for this coding contest problem. There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once. Constraints * 1 \leq a_i,b_i \leq 4(1\leq i\leq 3) * a_i and b_i are different. (1\leq i\leq 3) * No two roads connect the same pair of towns. * Any town can be reached from any other town using the roads. Input Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3 Output If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. Examples Input 4 2 1 3 2 3 Output YES Input 3 2 2 4 1 2 Output NO Input 2 1 3 2 4 3 Output YES
instruction
0
62,100
1
124,200
"Correct Solution: ``` lis = [0] * 5 for i in range(3): a,b = map(int,input().split()) lis[a] += 1 lis[b] += 1 if max(lis) == 3: print ("NO") else: print ("YES") ```
output
1
62,100
1
124,201
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once. Constraints * 1 \leq a_i,b_i \leq 4(1\leq i\leq 3) * a_i and b_i are different. (1\leq i\leq 3) * No two roads connect the same pair of towns. * Any town can be reached from any other town using the roads. Input Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3 Output If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. Examples Input 4 2 1 3 2 3 Output YES Input 3 2 2 4 1 2 Output NO Input 2 1 3 2 4 3 Output YES Submitted Solution: ``` ans_list = [0]*4 for i in range(3): a, b = [ int(v)-1 for v in input().split() ] ans_list[a] += 1 ans_list[b] += 1 print( "YES" if sorted(ans_list) == [1,1,2,2] else "NO" ) ```
instruction
0
62,101
1
124,202
Yes
output
1
62,101
1
124,203
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once. Constraints * 1 \leq a_i,b_i \leq 4(1\leq i\leq 3) * a_i and b_i are different. (1\leq i\leq 3) * No two roads connect the same pair of towns. * Any town can be reached from any other town using the roads. Input Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3 Output If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. Examples Input 4 2 1 3 2 3 Output YES Input 3 2 2 4 1 2 Output NO Input 2 1 3 2 4 3 Output YES Submitted Solution: ``` l=[] for i in range(3): l.extend(list(map(int,input().split()))) m=[0,0,0,0] for i in range(1,5): m[i-1]=l.count(i) if sorted(m) == [1,1,2,2]: print("YES") else: print("NO") ```
instruction
0
62,102
1
124,204
Yes
output
1
62,102
1
124,205
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once. Constraints * 1 \leq a_i,b_i \leq 4(1\leq i\leq 3) * a_i and b_i are different. (1\leq i\leq 3) * No two roads connect the same pair of towns. * Any town can be reached from any other town using the roads. Input Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3 Output If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. Examples Input 4 2 1 3 2 3 Output YES Input 3 2 2 4 1 2 Output NO Input 2 1 3 2 4 3 Output YES Submitted Solution: ``` AB = [input() for _ in range(3)] AB = list(map(int, ' '.join(AB).split())) c = [0] * 4 for ab in AB: c[ab-1] += 1 if max(c) > 2: print("NO") else: print("YES") ```
instruction
0
62,103
1
124,206
Yes
output
1
62,103
1
124,207
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once. Constraints * 1 \leq a_i,b_i \leq 4(1\leq i\leq 3) * a_i and b_i are different. (1\leq i\leq 3) * No two roads connect the same pair of towns. * Any town can be reached from any other town using the roads. Input Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3 Output If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. Examples Input 4 2 1 3 2 3 Output YES Input 3 2 2 4 1 2 Output NO Input 2 1 3 2 4 3 Output YES Submitted Solution: ``` ab=[list(map(int,input().split())) for i in range(3)] cnt=[0,0,0,0] ans='YES' for i in ab: for j in i: cnt[j-1]+=1 for i in cnt: if i>=3: ans='NO' print(ans) ```
instruction
0
62,104
1
124,208
Yes
output
1
62,104
1
124,209
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once. Constraints * 1 \leq a_i,b_i \leq 4(1\leq i\leq 3) * a_i and b_i are different. (1\leq i\leq 3) * No two roads connect the same pair of towns. * Any town can be reached from any other town using the roads. Input Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3 Output If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. Examples Input 4 2 1 3 2 3 Output YES Input 3 2 2 4 1 2 Output NO Input 2 1 3 2 4 3 Output YES Submitted Solution: ``` def solve(): t = [None]*4 for _ in range(3): a, b = map(int, input().split()) if t[a-1] != None: print("NO") return if t[b-1] != None: print("NO") return t[a-1] = b-1 t[b-1] = a-1 for i in range(4): if t[i] == None: print("NO") return if t[i] == i: print("NO") return else: print("YES") solve() ```
instruction
0
62,105
1
124,210
No
output
1
62,105
1
124,211
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once. Constraints * 1 \leq a_i,b_i \leq 4(1\leq i\leq 3) * a_i and b_i are different. (1\leq i\leq 3) * No two roads connect the same pair of towns. * Any town can be reached from any other town using the roads. Input Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3 Output If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. Examples Input 4 2 1 3 2 3 Output YES Input 3 2 2 4 1 2 Output NO Input 2 1 3 2 4 3 Output YES Submitted Solution: ``` a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) d = a + b + c if 1 in d and 2 in d and 3 in d and 4 in d: if a[1] == b[0] and b[1] == c[0]: print('YES') if a[1] == c[0] and c[1] == b[0]: print('YES') if b[1] == a[0] and a[1] == c[0]: print('YES') if b[1] == c[0] and c[1] == a[0]: print('YES') if c[1] == b[0] and b[1] == a[0]: print('YES') if c[1] == a[0] and a[1] == b[0]: print('YES') else: print("NO") else: print('NO') ```
instruction
0
62,106
1
124,212
No
output
1
62,106
1
124,213
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once. Constraints * 1 \leq a_i,b_i \leq 4(1\leq i\leq 3) * a_i and b_i are different. (1\leq i\leq 3) * No two roads connect the same pair of towns. * Any town can be reached from any other town using the roads. Input Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3 Output If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. Examples Input 4 2 1 3 2 3 Output YES Input 3 2 2 4 1 2 Output NO Input 2 1 3 2 4 3 Output YES Submitted Solution: ``` # coding: utf-8 # Your code here! num =[] ans =0 for i in range(3): x,y = map(int,input().split(" ")) num.append(x) num.append(y) for i in range(1,4): if num.count(i)>=3 or num.count(i)==0: ans +=1 if ans>0: print("NO") else: print("YES") ```
instruction
0
62,107
1
124,214
No
output
1
62,107
1
124,215
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once. Constraints * 1 \leq a_i,b_i \leq 4(1\leq i\leq 3) * a_i and b_i are different. (1\leq i\leq 3) * No two roads connect the same pair of towns. * Any town can be reached from any other town using the roads. Input Input is given from Standard Input in the following format: a_1 b_1 a_2 b_2 a_3 b_3 Output If we can visit all the towns by traversing each of the roads exactly once, print `YES`; otherwise, print `NO`. Examples Input 4 2 1 3 2 3 Output YES Input 3 2 2 4 1 2 Output NO Input 2 1 3 2 4 3 Output YES Submitted Solution: ``` A = [] B = [] for i in range(3): a, b = [int(n) for n in input().split()] A.append(a) B.append(b) counter = [0] * 4 for i in range(3): counter[A[i] - 1] += 1 counter[B[i] - 1] += 1 oddscounter = 0 for i in range(4): if counter[i] % 2 == 1: oddscounter += 1 answer = "" if oddscounter >= 3: answer = "NO" else: answer = "YES" print(answer) ```
instruction
0
62,108
1
124,216
No
output
1
62,108
1
124,217
Provide tags and a correct Python 3 solution for this coding contest problem. The map of the capital of Berland can be viewed on the infinite coordinate plane. Each point with integer coordinates contains a building, and there are streets connecting every building to four neighbouring buildings. All streets are parallel to the coordinate axes. The main school of the capital is located in (s_x, s_y). There are n students attending this school, the i-th of them lives in the house located in (x_i, y_i). It is possible that some students live in the same house, but no student lives in (s_x, s_y). After classes end, each student walks from the school to his house along one of the shortest paths. So the distance the i-th student goes from the school to his house is |s_x - x_i| + |s_y - y_i|. The Provision Department of Berland has decided to open a shawarma tent somewhere in the capital (at some point with integer coordinates). It is considered that the i-th student will buy a shawarma if at least one of the shortest paths from the school to the i-th student's house goes through the point where the shawarma tent is located. It is forbidden to place the shawarma tent at the point where the school is located, but the coordinates of the shawarma tent may coincide with the coordinates of the house of some student (or even multiple students). You want to find the maximum possible number of students buying shawarma and the optimal location for the tent itself. Input The first line contains three integers n, s_x, s_y (1 ≀ n ≀ 200 000, 0 ≀ s_x, s_y ≀ 10^{9}) β€” the number of students and the coordinates of the school, respectively. Then n lines follow. The i-th of them contains two integers x_i, y_i (0 ≀ x_i, y_i ≀ 10^{9}) β€” the location of the house where the i-th student lives. Some locations of houses may coincide, but no student lives in the same location where the school is situated. Output The output should consist of two lines. The first of them should contain one integer c β€” the maximum number of students that will buy shawarmas at the tent. The second line should contain two integers p_x and p_y β€” the coordinates where the tent should be located. If there are multiple answers, print any of them. Note that each of p_x and p_y should be not less than 0 and not greater than 10^{9}. Examples Input 4 3 2 1 3 4 2 5 1 4 1 Output 3 4 2 Input 3 100 100 0 0 0 0 100 200 Output 2 99 100 Input 7 10 12 5 6 20 23 15 4 16 5 4 54 12 1 4 15 Output 4 10 11 Note In the first example, If we build the shawarma tent in (4, 2), then the students living in (4, 2), (4, 1) and (5, 1) will visit it. In the second example, it is possible to build the shawarma tent in (1, 1), then both students living in (0, 0) will visit it.
instruction
0
62,407
1
124,814
Tags: brute force, geometry, greedy, implementation Correct Solution: ``` from sys import stdin, stdout n, sx, sy = map(int, stdin.readline().split()) counts = {(1, 0) : 0, (-1, 0) : 0, (0, 1) : 0, (0, -1) : 0} for _ in range(n): x,y = map(int, stdin.readline().split()) if x > sx: counts[(1, 0)]+=1 elif x < sx: counts[(-1, 0)]+=1 if y > sy: counts[(0, 1)]+=1 elif y < sy: counts[(0, -1)]+=1 maxcount, ans = 0, None for d,v in counts.items(): if v > maxcount: maxcount, ans = v, d stdout.write("{}\n{} {}".format(maxcount, sx+ans[0], sy+ans[1])) ```
output
1
62,407
1
124,815
Provide tags and a correct Python 3 solution for this coding contest problem. The map of the capital of Berland can be viewed on the infinite coordinate plane. Each point with integer coordinates contains a building, and there are streets connecting every building to four neighbouring buildings. All streets are parallel to the coordinate axes. The main school of the capital is located in (s_x, s_y). There are n students attending this school, the i-th of them lives in the house located in (x_i, y_i). It is possible that some students live in the same house, but no student lives in (s_x, s_y). After classes end, each student walks from the school to his house along one of the shortest paths. So the distance the i-th student goes from the school to his house is |s_x - x_i| + |s_y - y_i|. The Provision Department of Berland has decided to open a shawarma tent somewhere in the capital (at some point with integer coordinates). It is considered that the i-th student will buy a shawarma if at least one of the shortest paths from the school to the i-th student's house goes through the point where the shawarma tent is located. It is forbidden to place the shawarma tent at the point where the school is located, but the coordinates of the shawarma tent may coincide with the coordinates of the house of some student (or even multiple students). You want to find the maximum possible number of students buying shawarma and the optimal location for the tent itself. Input The first line contains three integers n, s_x, s_y (1 ≀ n ≀ 200 000, 0 ≀ s_x, s_y ≀ 10^{9}) β€” the number of students and the coordinates of the school, respectively. Then n lines follow. The i-th of them contains two integers x_i, y_i (0 ≀ x_i, y_i ≀ 10^{9}) β€” the location of the house where the i-th student lives. Some locations of houses may coincide, but no student lives in the same location where the school is situated. Output The output should consist of two lines. The first of them should contain one integer c β€” the maximum number of students that will buy shawarmas at the tent. The second line should contain two integers p_x and p_y β€” the coordinates where the tent should be located. If there are multiple answers, print any of them. Note that each of p_x and p_y should be not less than 0 and not greater than 10^{9}. Examples Input 4 3 2 1 3 4 2 5 1 4 1 Output 3 4 2 Input 3 100 100 0 0 0 0 100 200 Output 2 99 100 Input 7 10 12 5 6 20 23 15 4 16 5 4 54 12 1 4 15 Output 4 10 11 Note In the first example, If we build the shawarma tent in (4, 2), then the students living in (4, 2), (4, 1) and (5, 1) will visit it. In the second example, it is possible to build the shawarma tent in (1, 1), then both students living in (0, 0) will visit it.
instruction
0
62,408
1
124,816
Tags: brute force, geometry, greedy, implementation Correct Solution: ``` def maxi(l,sx,sy): ans = l[0] index = 0 for i in range(4): if l[i] > ans: ans = l[i] index = i if index == 0: return ans, sx + 1, sy elif index == 1: return ans, sx, sy + 1 elif index == 2: return ans, sx - 1, sy else: return ans, sx, sy - 1 n, sx, sy = [int(x) for x in input().split()] count = {'1' : 0, '2' : 0, '3' : 0, '4' : 0, 'xplus' : 0, 'xminus' : 0, 'yplus' : 0, 'yminus' : 0} for i in range(n): px, py = [int(x) for x in input().split()] prx = px - sx pry = py - sy if prx > 0 and pry > 0: count['1'] += 1 elif prx < 0 and pry > 0: count['2'] += 1 elif prx < 0 and pry < 0: count['3'] += 1 elif prx > 0 and pry < 0: count['4'] += 1 elif prx > 0 and pry == 0: count['xplus'] += 1 elif prx < 0 and pry == 0: count['xminus'] += 1 elif prx == 0 and pry > 0: count['yplus'] += 1 elif prx == 0 and pry < 0: count['yminus'] += 1 ans, cx, cy = maxi( [count['1']+count['xplus']+count['4'], count['1']+count['yplus']+count['2'], count['2']+count['xminus']+count['3'], count['3']+count['yminus']+count['4']], sx, sy ) print(ans) print(cx,cy) ```
output
1
62,408
1
124,817
Provide tags and a correct Python 3 solution for this coding contest problem. The map of the capital of Berland can be viewed on the infinite coordinate plane. Each point with integer coordinates contains a building, and there are streets connecting every building to four neighbouring buildings. All streets are parallel to the coordinate axes. The main school of the capital is located in (s_x, s_y). There are n students attending this school, the i-th of them lives in the house located in (x_i, y_i). It is possible that some students live in the same house, but no student lives in (s_x, s_y). After classes end, each student walks from the school to his house along one of the shortest paths. So the distance the i-th student goes from the school to his house is |s_x - x_i| + |s_y - y_i|. The Provision Department of Berland has decided to open a shawarma tent somewhere in the capital (at some point with integer coordinates). It is considered that the i-th student will buy a shawarma if at least one of the shortest paths from the school to the i-th student's house goes through the point where the shawarma tent is located. It is forbidden to place the shawarma tent at the point where the school is located, but the coordinates of the shawarma tent may coincide with the coordinates of the house of some student (or even multiple students). You want to find the maximum possible number of students buying shawarma and the optimal location for the tent itself. Input The first line contains three integers n, s_x, s_y (1 ≀ n ≀ 200 000, 0 ≀ s_x, s_y ≀ 10^{9}) β€” the number of students and the coordinates of the school, respectively. Then n lines follow. The i-th of them contains two integers x_i, y_i (0 ≀ x_i, y_i ≀ 10^{9}) β€” the location of the house where the i-th student lives. Some locations of houses may coincide, but no student lives in the same location where the school is situated. Output The output should consist of two lines. The first of them should contain one integer c β€” the maximum number of students that will buy shawarmas at the tent. The second line should contain two integers p_x and p_y β€” the coordinates where the tent should be located. If there are multiple answers, print any of them. Note that each of p_x and p_y should be not less than 0 and not greater than 10^{9}. Examples Input 4 3 2 1 3 4 2 5 1 4 1 Output 3 4 2 Input 3 100 100 0 0 0 0 100 200 Output 2 99 100 Input 7 10 12 5 6 20 23 15 4 16 5 4 54 12 1 4 15 Output 4 10 11 Note In the first example, If we build the shawarma tent in (4, 2), then the students living in (4, 2), (4, 1) and (5, 1) will visit it. In the second example, it is possible to build the shawarma tent in (1, 1), then both students living in (0, 0) will visit it.
instruction
0
62,409
1
124,818
Tags: brute force, geometry, greedy, implementation Correct Solution: ``` n, s_x, s_y = map(int, input().split()) east = west = north = south = 0 for i in range(n): x, y = map(int, input().split()) if x < s_x: west += 1 elif x > s_x: east += 1 if y < s_y: # south-west south += 1 elif y > s_y: north += 1 ans = max([east, west, north, south]) print(ans) if east == ans: print(s_x + 1, s_y) elif west == ans: print(s_x - 1, s_y) elif north == ans: print(s_x, s_y + 1) else: print(s_x, s_y-1) ```
output
1
62,409
1
124,819