message
stringlengths
2
45.8k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
254
108k
cluster
float64
3
3
__index_level_0__
int64
508
217k
Provide tags and a correct Python 3 solution for this coding contest problem. Skier rides on a snowy field. Its movements can be described by a string of characters 'S', 'N', 'W', 'E' (which correspond to 1 meter movement in the south, north, west or east direction respectively). It is known that if he moves along a previously unvisited segment of a path (i.e. this segment of the path is visited the first time), then the time of such movement is 5 seconds. If he rolls along previously visited segment of a path (i.e., this segment of the path has been covered by his path before), then it takes 1 second. Find the skier's time to roll all the path. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each set is given by one nonempty string of the characters 'S', 'N', 'W', 'E'. The length of the string does not exceed 10^5 characters. The sum of the lengths of t given lines over all test cases in the input does not exceed 10^5. Output For each test case, print the desired path time in seconds. Example Input 5 NNN NS WWEN WWEE NWNWS Output 15 6 16 12 25
instruction
0
80,087
3
160,174
Tags: data structures, implementation Correct Solution: ``` import sys input=sys.stdin.readline def main(): d={'N':(0,1),'S':(0,-1),'E':(1,0),'W':(-1,0)} t=int(input()) for _ in range(t): S=input().strip() ans=0 roads=set() p=[0,0] for s in S: x,y=p dx,dy=d[s] q=(x,y,x+dx,y+dy) r=(x+dx,y+dy,x,y) if q in roads or r in roads: ans+=1 else: ans+=5 roads.add((x,y,x+dx,y+dy)) p[0]+=dx; p[1]+=dy sys.stdout.write(str(ans)+'\n') if __name__=='__main__': main() ```
output
1
80,087
3
160,175
Provide tags and a correct Python 3 solution for this coding contest problem. Skier rides on a snowy field. Its movements can be described by a string of characters 'S', 'N', 'W', 'E' (which correspond to 1 meter movement in the south, north, west or east direction respectively). It is known that if he moves along a previously unvisited segment of a path (i.e. this segment of the path is visited the first time), then the time of such movement is 5 seconds. If he rolls along previously visited segment of a path (i.e., this segment of the path has been covered by his path before), then it takes 1 second. Find the skier's time to roll all the path. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each set is given by one nonempty string of the characters 'S', 'N', 'W', 'E'. The length of the string does not exceed 10^5 characters. The sum of the lengths of t given lines over all test cases in the input does not exceed 10^5. Output For each test case, print the desired path time in seconds. Example Input 5 NNN NS WWEN WWEE NWNWS Output 15 6 16 12 25
instruction
0
80,088
3
160,176
Tags: data structures, implementation Correct Solution: ``` def solve(): s = input() start = [0,0] visited = set() moveMap = { 'N' : [-1, 0], 'S' : [1, 0], 'W' : [0, -1], 'E' : [0, 1] } counter = 0 for i in s: move = [ a + b for a, b in zip(start,moveMap[i])] visit = [ a + b for a, b in zip(start,move)] if tuple(visit) in visited: counter += 1 else: counter += 5 visited.add(tuple(visit)) start = move print(counter) if __name__ == "__main__": t = int(input()) for _ in range(t): solve() ```
output
1
80,088
3
160,177
Provide tags and a correct Python 3 solution for this coding contest problem. Skier rides on a snowy field. Its movements can be described by a string of characters 'S', 'N', 'W', 'E' (which correspond to 1 meter movement in the south, north, west or east direction respectively). It is known that if he moves along a previously unvisited segment of a path (i.e. this segment of the path is visited the first time), then the time of such movement is 5 seconds. If he rolls along previously visited segment of a path (i.e., this segment of the path has been covered by his path before), then it takes 1 second. Find the skier's time to roll all the path. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each set is given by one nonempty string of the characters 'S', 'N', 'W', 'E'. The length of the string does not exceed 10^5 characters. The sum of the lengths of t given lines over all test cases in the input does not exceed 10^5. Output For each test case, print the desired path time in seconds. Example Input 5 NNN NS WWEN WWEE NWNWS Output 15 6 16 12 25
instruction
0
80,089
3
160,178
Tags: data structures, implementation Correct Solution: ``` from sys import stdin input=stdin.readline for _ in range(int(input())): x=y=0;d={};ans=0 for i in input().rstrip('\n'): x1=x y1=y if i=='N':y+=1 elif i=='S':y-=1 elif i=='E':x+=1 else:x-=1 if (x,y,x1,y1) in d or (x1,y1,x,y) in d:ans+=1 else:ans+=5;d[(x1,y1,x,y)]="qed" print(ans) ```
output
1
80,089
3
160,179
Provide tags and a correct Python 3 solution for this coding contest problem. Skier rides on a snowy field. Its movements can be described by a string of characters 'S', 'N', 'W', 'E' (which correspond to 1 meter movement in the south, north, west or east direction respectively). It is known that if he moves along a previously unvisited segment of a path (i.e. this segment of the path is visited the first time), then the time of such movement is 5 seconds. If he rolls along previously visited segment of a path (i.e., this segment of the path has been covered by his path before), then it takes 1 second. Find the skier's time to roll all the path. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each set is given by one nonempty string of the characters 'S', 'N', 'W', 'E'. The length of the string does not exceed 10^5 characters. The sum of the lengths of t given lines over all test cases in the input does not exceed 10^5. Output For each test case, print the desired path time in seconds. Example Input 5 NNN NS WWEN WWEE NWNWS Output 15 6 16 12 25
instruction
0
80,090
3
160,180
Tags: data structures, implementation Correct Solution: ``` # t=int(input()) # # # for _ in range(t): # s=input() # lst=set() # tt=0 # s1="" # x,y=0,0 # if(len(set(s))==1): # print(5*len(s)) # else: # for i in s: # if(i=="N"): # x1=x # y1=y+1 # elif(i=="S"): # x1 = x # y1 = y - 1 # elif(i=="E"): # x1 = x+1 # y1 = y # else: # x1 = x-1 # y1 = y # # a=(x,y) # b=(x1,y1) # if(a+b in lst): # tt+=1 # else: # tt+=5 # lst.add(a+b) # lst.add(b+a) # x=x1 # y=y1 # # print(tt) # t = int(input()) for _ in range(t): s = input() lst = set() tt = 0 s1 = "" x, y = 0, 0 if (len(set(s)) == 1): print(5 * len(s)) else: for i in s: if (i == "N"): x1 = x y1 = y + 1 elif (i == "S"): x1 = x y1 = y - 1 elif (i == "E"): x1 = x + 1 y1 = y else: x1 = x - 1 y1 = y a=(x,y) b=(x1,y1) if (a+b in lst): tt += 1 else: tt += 5 lst.add(a+b) lst.add(b+a) x = x1 y = y1 print(tt) ```
output
1
80,090
3
160,181
Provide tags and a correct Python 3 solution for this coding contest problem. Skier rides on a snowy field. Its movements can be described by a string of characters 'S', 'N', 'W', 'E' (which correspond to 1 meter movement in the south, north, west or east direction respectively). It is known that if he moves along a previously unvisited segment of a path (i.e. this segment of the path is visited the first time), then the time of such movement is 5 seconds. If he rolls along previously visited segment of a path (i.e., this segment of the path has been covered by his path before), then it takes 1 second. Find the skier's time to roll all the path. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each set is given by one nonempty string of the characters 'S', 'N', 'W', 'E'. The length of the string does not exceed 10^5 characters. The sum of the lengths of t given lines over all test cases in the input does not exceed 10^5. Output For each test case, print the desired path time in seconds. Example Input 5 NNN NS WWEN WWEE NWNWS Output 15 6 16 12 25
instruction
0
80,091
3
160,182
Tags: data structures, implementation Correct Solution: ``` for _ in range(int(input())): x,y = 0,0 t = 0 myset = set() directions = input() for d in directions: x2,y2 = x,y if d=='N': y2+=1 elif d=='S': y2-=1 elif d=='E': x2+=1 elif d=='W': x2-=1 if (x,y,x2,y2) in myset or (x2,y2,x,y) in myset: t += 1 else: t += 5 myset.add((x,y,x2,y2)) x,y=x2,y2 print(t) ```
output
1
80,091
3
160,183
Provide tags and a correct Python 3 solution for this coding contest problem. Skier rides on a snowy field. Its movements can be described by a string of characters 'S', 'N', 'W', 'E' (which correspond to 1 meter movement in the south, north, west or east direction respectively). It is known that if he moves along a previously unvisited segment of a path (i.e. this segment of the path is visited the first time), then the time of such movement is 5 seconds. If he rolls along previously visited segment of a path (i.e., this segment of the path has been covered by his path before), then it takes 1 second. Find the skier's time to roll all the path. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each set is given by one nonempty string of the characters 'S', 'N', 'W', 'E'. The length of the string does not exceed 10^5 characters. The sum of the lengths of t given lines over all test cases in the input does not exceed 10^5. Output For each test case, print the desired path time in seconds. Example Input 5 NNN NS WWEN WWEE NWNWS Output 15 6 16 12 25
instruction
0
80,092
3
160,184
Tags: data structures, implementation Correct Solution: ``` def resolve(x,y): num = 100000 return x + y * num t = int(input()) for i in range(t): s = input() a = set() b = set() x = 0 y = 0 ans = 0 for i in s: if i == "N": x,y = x,y+1 if resolve(x,y) in a: ans += 1 else: ans += 5 a.add(resolve(x,y)) elif i == "S": if resolve(x,y) in a: ans += 1 else: ans += 5 a.add(resolve(x,y)) x,y = x,y-1 elif i == "W": x,y = x+1,y if resolve(x,y) in b: ans += 1 else: ans += 5 b.add(resolve(x,y)) else: if resolve(x,y) in b: ans += 1 else: ans += 5 b.add(resolve(x,y)) x,y = x-1,y print(ans) ```
output
1
80,092
3
160,185
Provide tags and a correct Python 3 solution for this coding contest problem. Skier rides on a snowy field. Its movements can be described by a string of characters 'S', 'N', 'W', 'E' (which correspond to 1 meter movement in the south, north, west or east direction respectively). It is known that if he moves along a previously unvisited segment of a path (i.e. this segment of the path is visited the first time), then the time of such movement is 5 seconds. If he rolls along previously visited segment of a path (i.e., this segment of the path has been covered by his path before), then it takes 1 second. Find the skier's time to roll all the path. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each set is given by one nonempty string of the characters 'S', 'N', 'W', 'E'. The length of the string does not exceed 10^5 characters. The sum of the lengths of t given lines over all test cases in the input does not exceed 10^5. Output For each test case, print the desired path time in seconds. Example Input 5 NNN NS WWEN WWEE NWNWS Output 15 6 16 12 25
instruction
0
80,093
3
160,186
Tags: data structures, implementation Correct Solution: ``` def reverse(char): if char == "N": return "S" if char == "S": return "N" if char == "E": return "W" if char == "W": return "E" def alternate(start_x, start_y, char): if char == "N": return (start_x, start_y + 1) if char == "S": return (start_x, start_y - 1) if char == "E": return (start_x + 1, start_y) if char == "W": return (start_x - 1, start_y) def solve(s): visited = {} start_x = 0 start_y = 0 result = 0 for char in s: if (start_x, start_y) in visited and char in visited[(start_x, start_y)]: result += 1 else: result += 5 if not (start_x, start_y) in visited: visited[(start_x, start_y)] = set() visited[(start_x, start_y)].add(char) alt = alternate(start_x, start_y, char) if not (alt) in visited: visited[alt] = set() visited[alt].add(reverse(char)) if char == "N": start_y += 1 elif char == "S": start_y -= 1 elif char == "E": start_x += 1 elif char == "W": start_x -= 1 return result if __name__ == "__main__": for i in range(int(input())): s = input() print(solve(s)) ```
output
1
80,093
3
160,187
Provide tags and a correct Python 3 solution for this coding contest problem. Skier rides on a snowy field. Its movements can be described by a string of characters 'S', 'N', 'W', 'E' (which correspond to 1 meter movement in the south, north, west or east direction respectively). It is known that if he moves along a previously unvisited segment of a path (i.e. this segment of the path is visited the first time), then the time of such movement is 5 seconds. If he rolls along previously visited segment of a path (i.e., this segment of the path has been covered by his path before), then it takes 1 second. Find the skier's time to roll all the path. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each set is given by one nonempty string of the characters 'S', 'N', 'W', 'E'. The length of the string does not exceed 10^5 characters. The sum of the lengths of t given lines over all test cases in the input does not exceed 10^5. Output For each test case, print the desired path time in seconds. Example Input 5 NNN NS WWEN WWEE NWNWS Output 15 6 16 12 25
instruction
0
80,094
3
160,188
Tags: data structures, implementation Correct Solution: ``` def skier(s): ans = 0 paths = set() x = y = 0 for d in s: source = '%s-%s' % (x, y) if d == 'N': y += 1 elif d == 'S': y -= 1 elif d == 'W': x -= 1 elif d == 'E': x += 1 destination = '%s-%s' % (x, y) path1 = '%s-%s' % (source, destination) path2 = '%s-%s' % (destination, source) if path1 in paths or path2 in paths: ans += 1 else: paths.add(path1) paths.add(path2) ans += 5 return ans t = int(input()) for _ in range(t): s = str(input()) ans = skier(s) print(ans) ```
output
1
80,094
3
160,189
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Skier rides on a snowy field. Its movements can be described by a string of characters 'S', 'N', 'W', 'E' (which correspond to 1 meter movement in the south, north, west or east direction respectively). It is known that if he moves along a previously unvisited segment of a path (i.e. this segment of the path is visited the first time), then the time of such movement is 5 seconds. If he rolls along previously visited segment of a path (i.e., this segment of the path has been covered by his path before), then it takes 1 second. Find the skier's time to roll all the path. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each set is given by one nonempty string of the characters 'S', 'N', 'W', 'E'. The length of the string does not exceed 10^5 characters. The sum of the lengths of t given lines over all test cases in the input does not exceed 10^5. Output For each test case, print the desired path time in seconds. Example Input 5 NNN NS WWEN WWEE NWNWS Output 15 6 16 12 25 Submitted Solution: ``` import sys,bisect,string,math,time,functools,random from heapq import heappush,heappop,heapify from collections import deque,defaultdict,Counter from itertools import permutations,combinations,groupby def Golf():*a,=map(int,open(0)) def I():return int(input()) def S_():return input() def IS():return input().split() def LS():return [i for i in input().split()] def LI():return [int(i) for i in input().split()] def LI_():return [int(i)-1 for i in input().split()] def NI(n):return [int(input()) for i in range(n)] def NI_(n):return [int(input())-1 for i in range(n)] def StoLI():return [ord(i)-97 for i in input()] def ItoS(n):return chr(n+97) def LtoS(ls):return ''.join([chr(i+97) for i in ls]) def GI(V,E,ls=None,Directed=False,index=1): org_inp=[];g=[[] for i in range(V)] FromStdin=True if ls==None else False for i in range(E): if FromStdin: inp=LI() org_inp.append(inp) else: inp=ls[i] if len(inp)==2: a,b=inp;c=1 else: a,b,c=inp if index==1:a-=1;b-=1 aa=(a,c);bb=(b,c);g[a].append(bb) if not Directed:g[b].append(aa) return g,org_inp def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1): #h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage mp=[boundary]*(w+2);found={} for i in range(h): s=input() for char in search: if char in s: found[char]=((i+1)*(w+2)+s.index(char)+1) mp_def[char]=mp_def[replacement_of_found] mp+=[boundary]+[mp_def[j] for j in s]+[boundary] mp+=[boundary]*(w+2) return h+2,w+2,mp,found def TI(n):return GI(n,n-1) def bit_combination(k,n=2): rt=[] for tb in range(n**k): s=[tb//(n**bt)%n for bt in range(k)];rt+=[s] return rt def show(*inp,end='\n'): if show_flg:print(*inp,end=end) YN=['YES','NO'];Yn=['Yes','No'] mo=10**9+7 inf=float('inf') l_alp=string.ascii_lowercase #sys.setrecursionlimit(10**7) input=lambda: sys.stdin.readline().rstrip() class Tree: def __init__(self,inp_size=None,init=True): self.LCA_init_stat=False self.ETtable=[] if init: self.stdin(inp_size) return def stdin(self,inp_size=None,index=1): if inp_size==None: self.size=int(input()) else: self.size=inp_size self.edges,_=GI(self.size,self.size-1,index=index) return def listin(self,ls,index=0): self.size=len(ls)+1 self.edges,_=GI(self.size,self.size-1,ls,index=index) return def __str__(self): return str(self.edges) def dfs(self,x,func=lambda prv,nx,dist:prv+dist,root_v=0): q=deque() q.append(x) v=[-1]*self.size v[x]=root_v while q: c=q.pop() for nb,d in self.edges[c]: if v[nb]==-1: q.append(nb) v[nb]=func(v[c],nb,d) return v def EulerTour(self,x): q=deque() q.append(x) self.depth=[None]*self.size self.depth[x]=0 self.ETtable=[] self.ETdepth=[] self.ETin=[-1]*self.size self.ETout=[-1]*self.size cnt=0 while q: c=q.pop() if c<0: ce=~c else: ce=c for nb,d in self.edges[ce]: if self.depth[nb]==None: q.append(~ce) q.append(nb) self.depth[nb]=self.depth[ce]+1 self.ETtable.append(ce) self.ETdepth.append(self.depth[ce]) if self.ETin[ce]==-1: self.ETin[ce]=cnt else: self.ETout[ce]=cnt cnt+=1 return def LCA_init(self,root): self.EulerTour(root) self.st=SparseTable(self.ETdepth,init_func=min,init_idl=inf) self.LCA_init_stat=True return def LCA(self,root,x,y): if self.LCA_init_stat==False: self.LCA_init(root) xin,xout=self.ETin[x],self.ETout[x] yin,yout=self.ETin[y],self.ETout[y] a=min(xin,yin) b=max(xout,yout,xin,yin) id_of_min_dep_in_et=self.st.query_id(a,b+1) return self.ETtable[id_of_min_dep_in_et] class SparseTable: # O(N log N) for init, O(1) for query(l,r) def __init__(self,ls,init_func=min,init_idl=float('inf')): self.func=init_func self.idl=init_idl self.size=len(ls) self.N0=self.size.bit_length() self.table=[ls[:]] self.index=[list(range(self.size))] self.lg=[0]*(self.size+1) for i in range(2,self.size+1): self.lg[i]=self.lg[i>>1]+1 for i in range(self.N0): tmp=[self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) for j in range(self.size)] tmp_id=[self.index[i][j] if self.table[i][j]==self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) else self.index[i][min(j+(1<<i),self.size-1)] for j in range(self.size)] self.table+=[tmp] self.index+=[tmp_id] # return func of [l,r) def query(self,l,r): #N=(r-l).bit_length()-1 N=self.lg[r-l] return self.func(self.table[N][l],self.table[N][r-(1<<N)]) # return index of which val[i] = func of v among [l,r) def query_id(self,l,r): #N=(r-l).bit_length()-1 N=self.lg[r-l] a,b=self.index[N][l],self.index[N][r-(1<<N)] if self.table[0][a]==self.func(self.table[N][l],self.table[N][r-(1<<N)]): b=a return b def __str__(self): return str(self.table[0]) def print(self): for i in self.table: print(*i) show_flg=False show_flg=True ans=0 D='EWNS' m=[(1,0),(-1,0),(0,1),(0,-1)] dc=dict(zip(D,m)) T=I() for _ in range(T): ans=0 s=input() N=len(s)*2+5 x,y=(N,N) p=x*N+y f=dict() for i in s: dx,dy=dc[i] nx=x+dx ny=y+dy X=min(x,nx) Y=min(y,ny) p=X*N+Y p*=1 if dx==0 else -1 if p in f: ans+=1 else: ans+=5 f[p]=1 x,y=nx,ny #show(x-N,y-N,p,ans,f,N) print(ans) ```
instruction
0
80,095
3
160,190
Yes
output
1
80,095
3
160,191
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Skier rides on a snowy field. Its movements can be described by a string of characters 'S', 'N', 'W', 'E' (which correspond to 1 meter movement in the south, north, west or east direction respectively). It is known that if he moves along a previously unvisited segment of a path (i.e. this segment of the path is visited the first time), then the time of such movement is 5 seconds. If he rolls along previously visited segment of a path (i.e., this segment of the path has been covered by his path before), then it takes 1 second. Find the skier's time to roll all the path. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each set is given by one nonempty string of the characters 'S', 'N', 'W', 'E'. The length of the string does not exceed 10^5 characters. The sum of the lengths of t given lines over all test cases in the input does not exceed 10^5. Output For each test case, print the desired path time in seconds. Example Input 5 NNN NS WWEN WWEE NWNWS Output 15 6 16 12 25 Submitted Solution: ``` t = int(input()) for _ in range(t): s = input() paths = set() time = 0 loc = [0, 0] for i in s: if i == 'N': delta = [1, 0] elif i == 'S': delta = [-1, 0] elif i == 'W': delta = [0, 1] else: delta = [0, -1] p1 = f'{loc[0]},{loc[1]},{loc[0] + delta[0]},{loc[1] + delta[1]}' p2 = f'{loc[0] + delta[0]},{loc[1] + delta[1]},{loc[0]},{loc[1]}' loc = [loc[0] + delta[0], loc[1] + delta[1]] if p1 in paths or p2 in paths: time += 1 else: paths.add(p1) paths.add(p2) time += 5 print(time) ```
instruction
0
80,096
3
160,192
Yes
output
1
80,096
3
160,193
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Skier rides on a snowy field. Its movements can be described by a string of characters 'S', 'N', 'W', 'E' (which correspond to 1 meter movement in the south, north, west or east direction respectively). It is known that if he moves along a previously unvisited segment of a path (i.e. this segment of the path is visited the first time), then the time of such movement is 5 seconds. If he rolls along previously visited segment of a path (i.e., this segment of the path has been covered by his path before), then it takes 1 second. Find the skier's time to roll all the path. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each set is given by one nonempty string of the characters 'S', 'N', 'W', 'E'. The length of the string does not exceed 10^5 characters. The sum of the lengths of t given lines over all test cases in the input does not exceed 10^5. Output For each test case, print the desired path time in seconds. Example Input 5 NNN NS WWEN WWEE NWNWS Output 15 6 16 12 25 Submitted Solution: ``` import sys dir={'N':(0,1),'S':(0,-1),'E':(1,0),'W':(-1,0)} cin=sys.stdin.buffer.readline for _ in range(int(cin())): s=input() ans=0 d=set() x,y=0,0 for i in s: u=x+dir[i][0] v=y+dir[i][1] if (x,y,u,v) in d or (u,v,x,y) in d: ans+=1 else: ans+=5 d.add((x,y,u,v)) x,y=u,v print(ans) ```
instruction
0
80,097
3
160,194
Yes
output
1
80,097
3
160,195
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Skier rides on a snowy field. Its movements can be described by a string of characters 'S', 'N', 'W', 'E' (which correspond to 1 meter movement in the south, north, west or east direction respectively). It is known that if he moves along a previously unvisited segment of a path (i.e. this segment of the path is visited the first time), then the time of such movement is 5 seconds. If he rolls along previously visited segment of a path (i.e., this segment of the path has been covered by his path before), then it takes 1 second. Find the skier's time to roll all the path. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each set is given by one nonempty string of the characters 'S', 'N', 'W', 'E'. The length of the string does not exceed 10^5 characters. The sum of the lengths of t given lines over all test cases in the input does not exceed 10^5. Output For each test case, print the desired path time in seconds. Example Input 5 NNN NS WWEN WWEE NWNWS Output 15 6 16 12 25 Submitted Solution: ``` t = int(input()) Q = [] for j in range(t): s = input() D = dict() x = 0 y = 0 p = x q = y Sum = 5 * len(s) # длина пути без повторений for i in range(len(s)): if s[i] == 'N': y += 1 elif s[i] == 'S': y -= 1 elif s[i] == 'W': x -= 1 else: x += 1 flag1 = 0 if (x, y) in D: # если от этой точки я стартовал for elem in D[(x, y)]: # ищу был ли путь в p q if elem == (p, q): Sum -= 4 flag1 += 1 # значит здесь я уже ходил и больше сумму не считаю B = set() if (p, q) not in D: # если с этой точки не стартовал, то запишу путь D[(p, q)] = B B.add((x, y)) else: # если стартовал, все-равно запишу + проверю, ходил ли я этим маршрутом flag = 0 if flag1 == 0: for elem in D[(p, q)]: if elem == (x, y): Sum -= 4 flag += 1 if flag == 0: D[(p, q)].add((x, y)) p = x q = y Q.append(Sum) for m in range(len(Q)): print(Q[m]) ```
instruction
0
80,098
3
160,196
Yes
output
1
80,098
3
160,197
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Skier rides on a snowy field. Its movements can be described by a string of characters 'S', 'N', 'W', 'E' (which correspond to 1 meter movement in the south, north, west or east direction respectively). It is known that if he moves along a previously unvisited segment of a path (i.e. this segment of the path is visited the first time), then the time of such movement is 5 seconds. If he rolls along previously visited segment of a path (i.e., this segment of the path has been covered by his path before), then it takes 1 second. Find the skier's time to roll all the path. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each set is given by one nonempty string of the characters 'S', 'N', 'W', 'E'. The length of the string does not exceed 10^5 characters. The sum of the lengths of t given lines over all test cases in the input does not exceed 10^5. Output For each test case, print the desired path time in seconds. Example Input 5 NNN NS WWEN WWEE NWNWS Output 15 6 16 12 25 Submitted Solution: ``` print("helo") ```
instruction
0
80,099
3
160,198
No
output
1
80,099
3
160,199
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Skier rides on a snowy field. Its movements can be described by a string of characters 'S', 'N', 'W', 'E' (which correspond to 1 meter movement in the south, north, west or east direction respectively). It is known that if he moves along a previously unvisited segment of a path (i.e. this segment of the path is visited the first time), then the time of such movement is 5 seconds. If he rolls along previously visited segment of a path (i.e., this segment of the path has been covered by his path before), then it takes 1 second. Find the skier's time to roll all the path. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each set is given by one nonempty string of the characters 'S', 'N', 'W', 'E'. The length of the string does not exceed 10^5 characters. The sum of the lengths of t given lines over all test cases in the input does not exceed 10^5. Output For each test case, print the desired path time in seconds. Example Input 5 NNN NS WWEN WWEE NWNWS Output 15 6 16 12 25 Submitted Solution: ``` for _ in range(int(input())): ans, px, py = 0, 0, 0 s = set() for c in input(): s.add((px,py)) if c == 'N': px += 1 if c == 'S': px += -1 if c == 'E': py += 1 if c == 'W': py += -1 ans += (1 if (px,py) in s else 5) print(ans) ```
instruction
0
80,100
3
160,200
No
output
1
80,100
3
160,201
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Skier rides on a snowy field. Its movements can be described by a string of characters 'S', 'N', 'W', 'E' (which correspond to 1 meter movement in the south, north, west or east direction respectively). It is known that if he moves along a previously unvisited segment of a path (i.e. this segment of the path is visited the first time), then the time of such movement is 5 seconds. If he rolls along previously visited segment of a path (i.e., this segment of the path has been covered by his path before), then it takes 1 second. Find the skier's time to roll all the path. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each set is given by one nonempty string of the characters 'S', 'N', 'W', 'E'. The length of the string does not exceed 10^5 characters. The sum of the lengths of t given lines over all test cases in the input does not exceed 10^5. Output For each test case, print the desired path time in seconds. Example Input 5 NNN NS WWEN WWEE NWNWS Output 15 6 16 12 25 Submitted Solution: ``` """ This template is made by Satwik_Tiwari. python programmers can use this template :)) . """ #=============================================================================================== #importing some useful libraries. import sys import bisect import heapq from math import * from collections import Counter as counter # Counter(list) return a dict with {key: count} from itertools import combinations as comb # 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 bisect import bisect_right as br from bisect import bisect #=============================================================================================== #some shortcuts mod = pow(10, 9) + 7 def inp(): return sys.stdin.readline().strip() #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 graph(vertex): return [[] for i in range(0,vertex+1)] def zerolist(n): return [0]*n def nextline(): out("\n") #as stdout.write always print sring. def testcase(t): for p in range(t): solve() def printlist(a) : for p in range(0,len(a)): out(str(a[p]) + ' ') def lcm(a,b): return (a*b)//gcd(a,b) #=============================================================================================== # code here ;)) def x(i): return ((i*(i+1)) + (i*(i-1))/2) def solve(): s= inp() ll = len(s) grid = [] for i in range(0,2*(ll) + 3): a = [] for j in range(0,2*(ll)+3): a.append(0) grid.append(a) x = (ll)+1 y = (ll)+1 ans = 0 grid[x][y] = 1 for i in range(0,len(s)): if(s[i] == 'N'): y+=1 if(s[i] == 'S'): y-=1 if(s[i] == 'W'): x+=1 if(s[i] == 'E'): x-=1 if(grid[x][y] == 0): ans+=5 grid[x][y] = 1 else: ans +=1 # print(ans) print(ans) testcase(int(inp())) ```
instruction
0
80,101
3
160,202
No
output
1
80,101
3
160,203
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Skier rides on a snowy field. Its movements can be described by a string of characters 'S', 'N', 'W', 'E' (which correspond to 1 meter movement in the south, north, west or east direction respectively). It is known that if he moves along a previously unvisited segment of a path (i.e. this segment of the path is visited the first time), then the time of such movement is 5 seconds. If he rolls along previously visited segment of a path (i.e., this segment of the path has been covered by his path before), then it takes 1 second. Find the skier's time to roll all the path. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each set is given by one nonempty string of the characters 'S', 'N', 'W', 'E'. The length of the string does not exceed 10^5 characters. The sum of the lengths of t given lines over all test cases in the input does not exceed 10^5. Output For each test case, print the desired path time in seconds. Example Input 5 NNN NS WWEN WWEE NWNWS Output 15 6 16 12 25 Submitted Solution: ``` for i in range(int(input())): k=list(input()) l=[[0,0]] x,y,j,s=0,0,0,0 while j<len(k): if k[j]=='N': x=x+1 if [x,y] in l: s=s+1 else: s=s+5 l.append([x,y]) elif k[j]=="S": x=x-1 if [x,y] in l: s=s+1 else: s=s+5 l.append([x,y]) elif k[j]=="W": y=y+1 if [x,y] in l: s=s+1 else: s=s+5 l.append([x,y]) else: y=y-1 if [x,y] in l: s=s+1 else: s=s+5 l.append([x,y]) j=j+1 print(s) ```
instruction
0
80,102
3
160,204
No
output
1
80,102
3
160,205
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Life is not easy for the perfectly common variable named Vasya. Wherever it goes, it is either assigned a value, or simply ignored, or is being used! Vasya's life goes in states of a program. In each state, Vasya can either be used (for example, to calculate the value of another variable), or be assigned a value, or ignored. Between some states are directed (oriented) transitions. A path is a sequence of states v1, v2, ..., vx, where for any 1 ≤ i < x exists a transition from vi to vi + 1. Vasya's value in state v is interesting to the world, if exists path p1, p2, ..., pk such, that pi = v for some i (1 ≤ i ≤ k), in state p1 Vasya gets assigned a value, in state pk Vasya is used and there is no state pi (except for p1) where Vasya gets assigned a value. Help Vasya, find the states in which Vasya's value is interesting to the world. Input The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the numbers of states and transitions, correspondingly. The second line contains space-separated n integers f1, f2, ..., fn (0 ≤ fi ≤ 2), fi described actions performed upon Vasya in state i: 0 represents ignoring, 1 — assigning a value, 2 — using. Next m lines contain space-separated pairs of integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi), each pair represents the transition from the state number ai to the state number bi. Between two states can be any number of transitions. Output Print n integers r1, r2, ..., rn, separated by spaces or new lines. Number ri should equal 1, if Vasya's value in state i is interesting to the world and otherwise, it should equal 0. The states are numbered from 1 to n in the order, in which they are described in the input. Examples Input 4 3 1 0 0 2 1 2 2 3 3 4 Output 1 1 1 1 Input 3 1 1 0 2 1 3 Output 1 0 1 Input 3 1 2 0 1 1 3 Output 0 0 0 Note In the first sample the program states can be used to make the only path in which the value of Vasya interests the world, 1 <image> 2 <image> 3 <image> 4; it includes all the states, so in all of them Vasya's value is interesting to the world. The second sample the only path in which Vasya's value is interesting to the world is , — 1 <image> 3; state 2 is not included there. In the third sample we cannot make from the states any path in which the value of Vasya would be interesting to the world, so the value of Vasya is never interesting to the world. Submitted Solution: ``` from collections import defaultdict class Graph: def __init__(self): self.graph = defaultdict(list) self.values = defaultdict() self.interesting = defaultdict() def addEdge(self,u,v): # directed graph self.graph[u].append(v) def DFSUtil(self, v, visited, started): # print(v,visited) visited[v-1] = True if self.values[v] == 1: started = True # visiting its adj nodes for i in self.graph[v]: if visited[i-1] is False: res = self.DFSUtil(i, visited, started) if res is True and self.values[i] != 1: self.interesting[v] = 1 if ( self.values[v] == 2 and started is True ) or self.interesting[v] == 1: self.interesting[v] = 1 return True else: return False def DFS(self,n,s): visited =[False]*n started = False res = self.DFSUtil(s, visited, started) return self.interesting def assignStates(self, values): for i,item in enumerate(values): self.values[i+1] = item self.interesting[i+1] = 0 g = Graph() n, m = input().split() n = int(n) m = int(m) f = input().split() f = [int(i) for i in f] g.assignStates(f) start = None for _ in range(m): x, y = input().split() if start is None: start = int(x) x = int(x) y = int(y) g.addEdge(x, y) theres = g.DFS(n, start) for a in theres.values(): print(a) ```
instruction
0
80,197
3
160,394
No
output
1
80,197
3
160,395
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Life is not easy for the perfectly common variable named Vasya. Wherever it goes, it is either assigned a value, or simply ignored, or is being used! Vasya's life goes in states of a program. In each state, Vasya can either be used (for example, to calculate the value of another variable), or be assigned a value, or ignored. Between some states are directed (oriented) transitions. A path is a sequence of states v1, v2, ..., vx, where for any 1 ≤ i < x exists a transition from vi to vi + 1. Vasya's value in state v is interesting to the world, if exists path p1, p2, ..., pk such, that pi = v for some i (1 ≤ i ≤ k), in state p1 Vasya gets assigned a value, in state pk Vasya is used and there is no state pi (except for p1) where Vasya gets assigned a value. Help Vasya, find the states in which Vasya's value is interesting to the world. Input The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the numbers of states and transitions, correspondingly. The second line contains space-separated n integers f1, f2, ..., fn (0 ≤ fi ≤ 2), fi described actions performed upon Vasya in state i: 0 represents ignoring, 1 — assigning a value, 2 — using. Next m lines contain space-separated pairs of integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi), each pair represents the transition from the state number ai to the state number bi. Between two states can be any number of transitions. Output Print n integers r1, r2, ..., rn, separated by spaces or new lines. Number ri should equal 1, if Vasya's value in state i is interesting to the world and otherwise, it should equal 0. The states are numbered from 1 to n in the order, in which they are described in the input. Examples Input 4 3 1 0 0 2 1 2 2 3 3 4 Output 1 1 1 1 Input 3 1 1 0 2 1 3 Output 1 0 1 Input 3 1 2 0 1 1 3 Output 0 0 0 Note In the first sample the program states can be used to make the only path in which the value of Vasya interests the world, 1 <image> 2 <image> 3 <image> 4; it includes all the states, so in all of them Vasya's value is interesting to the world. The second sample the only path in which Vasya's value is interesting to the world is , — 1 <image> 3; state 2 is not included there. In the third sample we cannot make from the states any path in which the value of Vasya would be interesting to the world, so the value of Vasya is never interesting to the world. Submitted Solution: ``` from collections import defaultdict class Graph: def __init__(self): self.graph = defaultdict(list) self.values = defaultdict() self.interesting = defaultdict() def addEdge(self,u,v): # directed graph self.graph[u].append(v) def DFSUtil(self, v, visited): visited[v-1] = True # visiting its adj nodes for i in self.graph[v]: if visited[i-1] is False and self.values[i] != 1: res = self.DFSUtil(i, visited) if res is True: self.interesting[v] = 1 if self.values[v] == 2 or self.interesting[v] == 1: self.interesting[v] = 1 return True else: return False def DFS(self,n,s): visited =[False]*n res = self.DFSUtil(s, visited) return self.interesting def assignStates(self, values): for i,item in enumerate(values): self.values[i+1] = item self.interesting[i+1] = 0 try: g = Graph() n, m = input().split() n = int(n) m = int(m) f = input().split() f = [int(i) for i in f] g.assignStates(f) start = [] for _ in range(m): x, y = input().split() x = int(x) y = int(y) if f[x-1] == 1: start.append(int(x)) if f[y-1] == 1: start.append(int(y)) g.addEdge(x, y) start = list(dict.fromkeys(start)) for k in start: theres = g.DFS(n, k) if start != []: for a in theres.values(): print(a) else: for _ in range(n): print(0) except Exception as e: print(str(e)) ```
instruction
0
80,198
3
160,396
No
output
1
80,198
3
160,397
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Life is not easy for the perfectly common variable named Vasya. Wherever it goes, it is either assigned a value, or simply ignored, or is being used! Vasya's life goes in states of a program. In each state, Vasya can either be used (for example, to calculate the value of another variable), or be assigned a value, or ignored. Between some states are directed (oriented) transitions. A path is a sequence of states v1, v2, ..., vx, where for any 1 ≤ i < x exists a transition from vi to vi + 1. Vasya's value in state v is interesting to the world, if exists path p1, p2, ..., pk such, that pi = v for some i (1 ≤ i ≤ k), in state p1 Vasya gets assigned a value, in state pk Vasya is used and there is no state pi (except for p1) where Vasya gets assigned a value. Help Vasya, find the states in which Vasya's value is interesting to the world. Input The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the numbers of states and transitions, correspondingly. The second line contains space-separated n integers f1, f2, ..., fn (0 ≤ fi ≤ 2), fi described actions performed upon Vasya in state i: 0 represents ignoring, 1 — assigning a value, 2 — using. Next m lines contain space-separated pairs of integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi), each pair represents the transition from the state number ai to the state number bi. Between two states can be any number of transitions. Output Print n integers r1, r2, ..., rn, separated by spaces or new lines. Number ri should equal 1, if Vasya's value in state i is interesting to the world and otherwise, it should equal 0. The states are numbered from 1 to n in the order, in which they are described in the input. Examples Input 4 3 1 0 0 2 1 2 2 3 3 4 Output 1 1 1 1 Input 3 1 1 0 2 1 3 Output 1 0 1 Input 3 1 2 0 1 1 3 Output 0 0 0 Note In the first sample the program states can be used to make the only path in which the value of Vasya interests the world, 1 <image> 2 <image> 3 <image> 4; it includes all the states, so in all of them Vasya's value is interesting to the world. The second sample the only path in which Vasya's value is interesting to the world is , — 1 <image> 3; state 2 is not included there. In the third sample we cannot make from the states any path in which the value of Vasya would be interesting to the world, so the value of Vasya is never interesting to the world. Submitted Solution: ``` from collections import defaultdict class Graph: def __init__(self): self.graph = defaultdict(list) self.values = defaultdict() self.interesting = defaultdict() def addEdge(self,u,v): # directed graph self.graph[u].append(v) def DFSUtil(self, v, visited): visited[v-1] = True # visiting its adj nodes for i in self.graph[v]: if visited[i-1] is False and self.values[i] != 1: res = self.DFSUtil(i, visited) if res is True: self.interesting[v] = 1 if self.values[v] == 2 or self.interesting[v] == 1: self.interesting[v] = 1 return True else: return False def DFS(self,n,s): visited =[False]*n res = self.DFSUtil(s, visited) return self.interesting def assignStates(self, values): for i,item in enumerate(values): self.values[i+1] = item self.interesting[i+1] = 0 g = Graph() n, m = input().split() n = int(n) m = int(m) f = input().split() f = [int(i) for i in f] g.assignStates(f) start = [] for _ in range(m): x, y = input().split() x = int(x) y = int(y) if f[x-1] == 1: start.append(int(x)) if f[y-1] == 1: start.append(int(y)) g.addEdge(x, y) start = list(dict.fromkeys(start)) for k in start: theres = g.DFS(n, k) for _ in range(n): print(0) # if start != []: # for a in theres.values(): # print(a) # else: # for _ in range(n): # print(0) ```
instruction
0
80,199
3
160,398
No
output
1
80,199
3
160,399
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Life is not easy for the perfectly common variable named Vasya. Wherever it goes, it is either assigned a value, or simply ignored, or is being used! Vasya's life goes in states of a program. In each state, Vasya can either be used (for example, to calculate the value of another variable), or be assigned a value, or ignored. Between some states are directed (oriented) transitions. A path is a sequence of states v1, v2, ..., vx, where for any 1 ≤ i < x exists a transition from vi to vi + 1. Vasya's value in state v is interesting to the world, if exists path p1, p2, ..., pk such, that pi = v for some i (1 ≤ i ≤ k), in state p1 Vasya gets assigned a value, in state pk Vasya is used and there is no state pi (except for p1) where Vasya gets assigned a value. Help Vasya, find the states in which Vasya's value is interesting to the world. Input The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the numbers of states and transitions, correspondingly. The second line contains space-separated n integers f1, f2, ..., fn (0 ≤ fi ≤ 2), fi described actions performed upon Vasya in state i: 0 represents ignoring, 1 — assigning a value, 2 — using. Next m lines contain space-separated pairs of integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi), each pair represents the transition from the state number ai to the state number bi. Between two states can be any number of transitions. Output Print n integers r1, r2, ..., rn, separated by spaces or new lines. Number ri should equal 1, if Vasya's value in state i is interesting to the world and otherwise, it should equal 0. The states are numbered from 1 to n in the order, in which they are described in the input. Examples Input 4 3 1 0 0 2 1 2 2 3 3 4 Output 1 1 1 1 Input 3 1 1 0 2 1 3 Output 1 0 1 Input 3 1 2 0 1 1 3 Output 0 0 0 Note In the first sample the program states can be used to make the only path in which the value of Vasya interests the world, 1 <image> 2 <image> 3 <image> 4; it includes all the states, so in all of them Vasya's value is interesting to the world. The second sample the only path in which Vasya's value is interesting to the world is , — 1 <image> 3; state 2 is not included there. In the third sample we cannot make from the states any path in which the value of Vasya would be interesting to the world, so the value of Vasya is never interesting to the world. Submitted Solution: ``` n, b = map(int, input().split()) a = list(map(int, input().split())) x = (sum(a) + b) // n if x < max(a): print(-1) else: for i in a: print('%.6f' % (x - i)) ```
instruction
0
80,200
3
160,400
No
output
1
80,200
3
160,401
Provide tags and a correct Python 3 solution for this coding contest problem. As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (x, y, z). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formula: <image>. Mushroom scientists that work for the Great Mushroom King think that the Universe isn't exactly right and the distance from the center of the Universe to a point equals xa·yb·zc. To test the metric of mushroom scientists, the usual scientists offered them a task: find such x, y, z (0 ≤ x, y, z; x + y + z ≤ S), that the distance between the center of the Universe and the point (x, y, z) is maximum possible in the metric of mushroom scientists. The mushroom scientists aren't good at maths, so they commissioned you to do the task. Note that in this problem, it is considered that 00 = 1. Input The first line contains a single integer S (1 ≤ S ≤ 103) — the maximum sum of coordinates of the sought point. The second line contains three space-separated integers a, b, c (0 ≤ a, b, c ≤ 103) — the numbers that describe the metric of mushroom scientists. Output Print three real numbers — the coordinates of the point that reaches maximum value in the metrics of mushroom scientists. If there are multiple answers, print any of them that meets the limitations. A natural logarithm of distance from the center of the Universe to the given point in the metric of mushroom scientists shouldn't differ from the natural logarithm of the maximum distance by more than 10 - 6. We think that ln(0) = - ∞. Examples Input 3 1 1 1 Output 1.0 1.0 1.0 Input 3 2 0 0 Output 3.0 0.0 0.0
instruction
0
80,201
3
160,402
Tags: math, ternary search Correct Solution: ``` n = int(input()) a, b, c = map(int, input().split()) s = a+b+c if(s == 0): print(0, 0, 0) else: print(n * a / s, n * b / s, n * c / s) ```
output
1
80,201
3
160,403
Provide tags and a correct Python 3 solution for this coding contest problem. As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (x, y, z). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formula: <image>. Mushroom scientists that work for the Great Mushroom King think that the Universe isn't exactly right and the distance from the center of the Universe to a point equals xa·yb·zc. To test the metric of mushroom scientists, the usual scientists offered them a task: find such x, y, z (0 ≤ x, y, z; x + y + z ≤ S), that the distance between the center of the Universe and the point (x, y, z) is maximum possible in the metric of mushroom scientists. The mushroom scientists aren't good at maths, so they commissioned you to do the task. Note that in this problem, it is considered that 00 = 1. Input The first line contains a single integer S (1 ≤ S ≤ 103) — the maximum sum of coordinates of the sought point. The second line contains three space-separated integers a, b, c (0 ≤ a, b, c ≤ 103) — the numbers that describe the metric of mushroom scientists. Output Print three real numbers — the coordinates of the point that reaches maximum value in the metrics of mushroom scientists. If there are multiple answers, print any of them that meets the limitations. A natural logarithm of distance from the center of the Universe to the given point in the metric of mushroom scientists shouldn't differ from the natural logarithm of the maximum distance by more than 10 - 6. We think that ln(0) = - ∞. Examples Input 3 1 1 1 Output 1.0 1.0 1.0 Input 3 2 0 0 Output 3.0 0.0 0.0
instruction
0
80,202
3
160,404
Tags: math, ternary search Correct Solution: ``` def gribnye(s, a, b, c): if a == b == c == s == 0: return [0.0] elif a == b == c == 0 and s != 0: return 0, 0, 0 a1 = a * s / (a + b + c) b1 = b * s / (a + b + c) c1 = c * s / (a + b + c) return a1, b1, c1 S = int(input()) A, B, C = [int(i) for i in input().split()] print(*gribnye(S, A, B, C)) ```
output
1
80,202
3
160,405
Provide tags and a correct Python 3 solution for this coding contest problem. As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (x, y, z). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formula: <image>. Mushroom scientists that work for the Great Mushroom King think that the Universe isn't exactly right and the distance from the center of the Universe to a point equals xa·yb·zc. To test the metric of mushroom scientists, the usual scientists offered them a task: find such x, y, z (0 ≤ x, y, z; x + y + z ≤ S), that the distance between the center of the Universe and the point (x, y, z) is maximum possible in the metric of mushroom scientists. The mushroom scientists aren't good at maths, so they commissioned you to do the task. Note that in this problem, it is considered that 00 = 1. Input The first line contains a single integer S (1 ≤ S ≤ 103) — the maximum sum of coordinates of the sought point. The second line contains three space-separated integers a, b, c (0 ≤ a, b, c ≤ 103) — the numbers that describe the metric of mushroom scientists. Output Print three real numbers — the coordinates of the point that reaches maximum value in the metrics of mushroom scientists. If there are multiple answers, print any of them that meets the limitations. A natural logarithm of distance from the center of the Universe to the given point in the metric of mushroom scientists shouldn't differ from the natural logarithm of the maximum distance by more than 10 - 6. We think that ln(0) = - ∞. Examples Input 3 1 1 1 Output 1.0 1.0 1.0 Input 3 2 0 0 Output 3.0 0.0 0.0
instruction
0
80,203
3
160,406
Tags: math, ternary search Correct Solution: ``` from sys import stdin, stdout s = int(stdin.readline()) a, b, c = map(int, stdin.readline().split()) E = 10 ** (-7) x, y, z = s / 3, s / 3, s / 3 ans = 1 def power(v, n): cnt = 1 while n: if n % 2: cnt *= v n >>= 1 v *= v return cnt def count(f, s, t): return (power(f / x, int(a)) * power(s / y, int(b)) * power(t / z, int(c))) def third(S, f, s): global x, y, z l, r = 0, S lb, rb = l + (r - l) / 3, r - (r - l) / 3 while (r - l > E): if count(f, s, lb) > count(f, s, rb): r = rb else: l = lb lb, rb = l + (r - l) / 3, r - (r - l) / 3 if (count(f, s, (lb + rb) / 2)) > ans: x, y, z = f, s, (lb + rb) / 2 return count(f, s, (lb + rb) / 2) def second(S, f): l, r = 0, S lb, rb = l + (r - l) / 3, r - (r - l) / 3 while (r - l > E): if third(S - lb, f, lb) > third(S - rb, f, rb): r = rb else: l = lb lb, rb = l + (r - l) / 3, r - (r - l) / 3 return third(S - (lb + rb) / 2, f, (lb + rb) / 2) def first(S): l, r = 0, s lb, rb = l + (r - l) / 3, r - (r - l) / 3 while (r - l > E): if second(S - lb, lb) > second(S - rb, rb): r = rb else: l = lb lb, rb = l + (r - l) / 3, r - (r - l) / 3 return (S - (rb + lb) / 2, (rb + lb) / 2) first(s) stdout.write(str(x) + ' ' + str(y) + ' ' + str(z)) ```
output
1
80,203
3
160,407
Provide tags and a correct Python 3 solution for this coding contest problem. As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (x, y, z). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formula: <image>. Mushroom scientists that work for the Great Mushroom King think that the Universe isn't exactly right and the distance from the center of the Universe to a point equals xa·yb·zc. To test the metric of mushroom scientists, the usual scientists offered them a task: find such x, y, z (0 ≤ x, y, z; x + y + z ≤ S), that the distance between the center of the Universe and the point (x, y, z) is maximum possible in the metric of mushroom scientists. The mushroom scientists aren't good at maths, so they commissioned you to do the task. Note that in this problem, it is considered that 00 = 1. Input The first line contains a single integer S (1 ≤ S ≤ 103) — the maximum sum of coordinates of the sought point. The second line contains three space-separated integers a, b, c (0 ≤ a, b, c ≤ 103) — the numbers that describe the metric of mushroom scientists. Output Print three real numbers — the coordinates of the point that reaches maximum value in the metrics of mushroom scientists. If there are multiple answers, print any of them that meets the limitations. A natural logarithm of distance from the center of the Universe to the given point in the metric of mushroom scientists shouldn't differ from the natural logarithm of the maximum distance by more than 10 - 6. We think that ln(0) = - ∞. Examples Input 3 1 1 1 Output 1.0 1.0 1.0 Input 3 2 0 0 Output 3.0 0.0 0.0
instruction
0
80,204
3
160,408
Tags: math, ternary search Correct Solution: ``` s = float(input()) a, b, c = map(float, input().split()) if (a == b and b == c and c == 0): print('0 0', end = " ") print(s) else: print(a * s / (a + b + c), end = " ") print(b * s / (a + b + c), end = " ") print(c * s / (a + b + c)) ```
output
1
80,204
3
160,409
Provide tags and a correct Python 3 solution for this coding contest problem. As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (x, y, z). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formula: <image>. Mushroom scientists that work for the Great Mushroom King think that the Universe isn't exactly right and the distance from the center of the Universe to a point equals xa·yb·zc. To test the metric of mushroom scientists, the usual scientists offered them a task: find such x, y, z (0 ≤ x, y, z; x + y + z ≤ S), that the distance between the center of the Universe and the point (x, y, z) is maximum possible in the metric of mushroom scientists. The mushroom scientists aren't good at maths, so they commissioned you to do the task. Note that in this problem, it is considered that 00 = 1. Input The first line contains a single integer S (1 ≤ S ≤ 103) — the maximum sum of coordinates of the sought point. The second line contains three space-separated integers a, b, c (0 ≤ a, b, c ≤ 103) — the numbers that describe the metric of mushroom scientists. Output Print three real numbers — the coordinates of the point that reaches maximum value in the metrics of mushroom scientists. If there are multiple answers, print any of them that meets the limitations. A natural logarithm of distance from the center of the Universe to the given point in the metric of mushroom scientists shouldn't differ from the natural logarithm of the maximum distance by more than 10 - 6. We think that ln(0) = - ∞. Examples Input 3 1 1 1 Output 1.0 1.0 1.0 Input 3 2 0 0 Output 3.0 0.0 0.0
instruction
0
80,205
3
160,410
Tags: math, ternary search Correct Solution: ``` sa=int(input()) a, b, c=map(int, input().split(' ')) if a==0 and b==0 and c==0: print(0, 0, 0) else: x=(a*sa/(a+b+c)) y=(b*sa/(a+b+c)) z=(c*sa/(a+b+c)) print(x, y, z) ```
output
1
80,205
3
160,411
Provide tags and a correct Python 3 solution for this coding contest problem. As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (x, y, z). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formula: <image>. Mushroom scientists that work for the Great Mushroom King think that the Universe isn't exactly right and the distance from the center of the Universe to a point equals xa·yb·zc. To test the metric of mushroom scientists, the usual scientists offered them a task: find such x, y, z (0 ≤ x, y, z; x + y + z ≤ S), that the distance between the center of the Universe and the point (x, y, z) is maximum possible in the metric of mushroom scientists. The mushroom scientists aren't good at maths, so they commissioned you to do the task. Note that in this problem, it is considered that 00 = 1. Input The first line contains a single integer S (1 ≤ S ≤ 103) — the maximum sum of coordinates of the sought point. The second line contains three space-separated integers a, b, c (0 ≤ a, b, c ≤ 103) — the numbers that describe the metric of mushroom scientists. Output Print three real numbers — the coordinates of the point that reaches maximum value in the metrics of mushroom scientists. If there are multiple answers, print any of them that meets the limitations. A natural logarithm of distance from the center of the Universe to the given point in the metric of mushroom scientists shouldn't differ from the natural logarithm of the maximum distance by more than 10 - 6. We think that ln(0) = - ∞. Examples Input 3 1 1 1 Output 1.0 1.0 1.0 Input 3 2 0 0 Output 3.0 0.0 0.0
instruction
0
80,206
3
160,412
Tags: math, ternary search Correct Solution: ``` a=int(input()) b=list(map(int,input().split())) if sum(b)==0:print(' '.join([str(a/3)]*3)) else:print(' '.join(map(str,map(lambda x:a*x/sum(b),b)))) ```
output
1
80,206
3
160,413
Provide tags and a correct Python 3 solution for this coding contest problem. As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (x, y, z). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formula: <image>. Mushroom scientists that work for the Great Mushroom King think that the Universe isn't exactly right and the distance from the center of the Universe to a point equals xa·yb·zc. To test the metric of mushroom scientists, the usual scientists offered them a task: find such x, y, z (0 ≤ x, y, z; x + y + z ≤ S), that the distance between the center of the Universe and the point (x, y, z) is maximum possible in the metric of mushroom scientists. The mushroom scientists aren't good at maths, so they commissioned you to do the task. Note that in this problem, it is considered that 00 = 1. Input The first line contains a single integer S (1 ≤ S ≤ 103) — the maximum sum of coordinates of the sought point. The second line contains three space-separated integers a, b, c (0 ≤ a, b, c ≤ 103) — the numbers that describe the metric of mushroom scientists. Output Print three real numbers — the coordinates of the point that reaches maximum value in the metrics of mushroom scientists. If there are multiple answers, print any of them that meets the limitations. A natural logarithm of distance from the center of the Universe to the given point in the metric of mushroom scientists shouldn't differ from the natural logarithm of the maximum distance by more than 10 - 6. We think that ln(0) = - ∞. Examples Input 3 1 1 1 Output 1.0 1.0 1.0 Input 3 2 0 0 Output 3.0 0.0 0.0
instruction
0
80,207
3
160,414
Tags: math, ternary search Correct Solution: ``` S = int(input()) v = [int(x) for x in input().strip().split()] zeroes = v.count(0) total = sum(v) ans = [] if zeroes == 0: ans = [S * v[i] / total for i in range(3)] elif zeroes == 1: for i in range(3): if v[i] == 0: total -= v[i] for i in range(3): if v[i] != 0: ans.append(S * v[i] / total) else: ans.append(0) else: # 2 or more for i in range(3): if v[i] == 0: ans.append(0) else: ans.append(S) print(*ans) ```
output
1
80,207
3
160,415
Provide tags and a correct Python 3 solution for this coding contest problem. As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (x, y, z). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formula: <image>. Mushroom scientists that work for the Great Mushroom King think that the Universe isn't exactly right and the distance from the center of the Universe to a point equals xa·yb·zc. To test the metric of mushroom scientists, the usual scientists offered them a task: find such x, y, z (0 ≤ x, y, z; x + y + z ≤ S), that the distance between the center of the Universe and the point (x, y, z) is maximum possible in the metric of mushroom scientists. The mushroom scientists aren't good at maths, so they commissioned you to do the task. Note that in this problem, it is considered that 00 = 1. Input The first line contains a single integer S (1 ≤ S ≤ 103) — the maximum sum of coordinates of the sought point. The second line contains three space-separated integers a, b, c (0 ≤ a, b, c ≤ 103) — the numbers that describe the metric of mushroom scientists. Output Print three real numbers — the coordinates of the point that reaches maximum value in the metrics of mushroom scientists. If there are multiple answers, print any of them that meets the limitations. A natural logarithm of distance from the center of the Universe to the given point in the metric of mushroom scientists shouldn't differ from the natural logarithm of the maximum distance by more than 10 - 6. We think that ln(0) = - ∞. Examples Input 3 1 1 1 Output 1.0 1.0 1.0 Input 3 2 0 0 Output 3.0 0.0 0.0
instruction
0
80,208
3
160,416
Tags: math, ternary search Correct Solution: ``` def count(x1, y1, z1, x2, y2, z2): if x2 == 0 and a != 0 or y2 == 0 and b != 0 or z2 == 0 and c != 0: return False if x2 == 0: x2 = 1 if y2 == 0: y2 = 1 if z2 == 0: z2 = 1 return (x1 / x2) ** a * (y1 / y2) ** b * (z1 / z2) ** c < 1 n = int(input()) a, b, c = map(int, input().split()) l1, r1 = 0, n for i in range(200): x1 = l1 + (r1 - l1) / 3 l2, r2 = 0, n - x1 for j in range(200): y1 = l2 + (r2 - l2) / 3 y2 = r2 - (r2 - l2) / 3 if count(x1, y1, n - x1 - y1, x1, y2, n - x1 - y2): l2 = y1 else: r2 = y2 y11 = l2 x2 = r1 - (r1 - l1) / 3 l2, r2 = 0, n - x2 for j in range(200): y1 = l2 + (r2 - l2) / 3 y2 = r2 - (r2 - l2) / 3 if count(x2, y1, n - x2 - y1, x2, y2, n - x2 - y2): l2 = y1 else: r2 = y2 y22 = l2 if count(x1, y11, n - x1 - y11, x2, y22, n - x2 - y22): l1 = x1 p = y11 else: r1 = x2 p = y22 print(l1, p, n - l1 - p) ```
output
1
80,208
3
160,417
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (x, y, z). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formula: <image>. Mushroom scientists that work for the Great Mushroom King think that the Universe isn't exactly right and the distance from the center of the Universe to a point equals xa·yb·zc. To test the metric of mushroom scientists, the usual scientists offered them a task: find such x, y, z (0 ≤ x, y, z; x + y + z ≤ S), that the distance between the center of the Universe and the point (x, y, z) is maximum possible in the metric of mushroom scientists. The mushroom scientists aren't good at maths, so they commissioned you to do the task. Note that in this problem, it is considered that 00 = 1. Input The first line contains a single integer S (1 ≤ S ≤ 103) — the maximum sum of coordinates of the sought point. The second line contains three space-separated integers a, b, c (0 ≤ a, b, c ≤ 103) — the numbers that describe the metric of mushroom scientists. Output Print three real numbers — the coordinates of the point that reaches maximum value in the metrics of mushroom scientists. If there are multiple answers, print any of them that meets the limitations. A natural logarithm of distance from the center of the Universe to the given point in the metric of mushroom scientists shouldn't differ from the natural logarithm of the maximum distance by more than 10 - 6. We think that ln(0) = - ∞. Examples Input 3 1 1 1 Output 1.0 1.0 1.0 Input 3 2 0 0 Output 3.0 0.0 0.0 Submitted Solution: ``` S = int(input()) v = [int(x) for x in input().strip().split()] print(*[S * v[i] / sum(v) for i in range(3)] if sum(v) != 0 else "000") ```
instruction
0
80,209
3
160,418
Yes
output
1
80,209
3
160,419
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (x, y, z). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formula: <image>. Mushroom scientists that work for the Great Mushroom King think that the Universe isn't exactly right and the distance from the center of the Universe to a point equals xa·yb·zc. To test the metric of mushroom scientists, the usual scientists offered them a task: find such x, y, z (0 ≤ x, y, z; x + y + z ≤ S), that the distance between the center of the Universe and the point (x, y, z) is maximum possible in the metric of mushroom scientists. The mushroom scientists aren't good at maths, so they commissioned you to do the task. Note that in this problem, it is considered that 00 = 1. Input The first line contains a single integer S (1 ≤ S ≤ 103) — the maximum sum of coordinates of the sought point. The second line contains three space-separated integers a, b, c (0 ≤ a, b, c ≤ 103) — the numbers that describe the metric of mushroom scientists. Output Print three real numbers — the coordinates of the point that reaches maximum value in the metrics of mushroom scientists. If there are multiple answers, print any of them that meets the limitations. A natural logarithm of distance from the center of the Universe to the given point in the metric of mushroom scientists shouldn't differ from the natural logarithm of the maximum distance by more than 10 - 6. We think that ln(0) = - ∞. Examples Input 3 1 1 1 Output 1.0 1.0 1.0 Input 3 2 0 0 Output 3.0 0.0 0.0 Submitted Solution: ``` a=int(input()) b=list(map(int,input().split())) if sum(b)==0:print(' '.join([str(a/3)]*3)) else:print(' '.join(map(str,map(lambda x:a*x/sum(b),b)))) # Made By Mostafa_Khaled ```
instruction
0
80,210
3
160,420
Yes
output
1
80,210
3
160,421
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (x, y, z). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formula: <image>. Mushroom scientists that work for the Great Mushroom King think that the Universe isn't exactly right and the distance from the center of the Universe to a point equals xa·yb·zc. To test the metric of mushroom scientists, the usual scientists offered them a task: find such x, y, z (0 ≤ x, y, z; x + y + z ≤ S), that the distance between the center of the Universe and the point (x, y, z) is maximum possible in the metric of mushroom scientists. The mushroom scientists aren't good at maths, so they commissioned you to do the task. Note that in this problem, it is considered that 00 = 1. Input The first line contains a single integer S (1 ≤ S ≤ 103) — the maximum sum of coordinates of the sought point. The second line contains three space-separated integers a, b, c (0 ≤ a, b, c ≤ 103) — the numbers that describe the metric of mushroom scientists. Output Print three real numbers — the coordinates of the point that reaches maximum value in the metrics of mushroom scientists. If there are multiple answers, print any of them that meets the limitations. A natural logarithm of distance from the center of the Universe to the given point in the metric of mushroom scientists shouldn't differ from the natural logarithm of the maximum distance by more than 10 - 6. We think that ln(0) = - ∞. Examples Input 3 1 1 1 Output 1.0 1.0 1.0 Input 3 2 0 0 Output 3.0 0.0 0.0 Submitted Solution: ``` s = float(input()) a, b, c = map(float, input().split()) if (a == b and b == c and c == 0): print('0 0 ') print(s) else: print(a * s / (a + b + c), end = " ") print(b * s / (a + b + c), end = " ") print(c * s / (a + b + c), end = " ") ```
instruction
0
80,211
3
160,422
Yes
output
1
80,211
3
160,423
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (x, y, z). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formula: <image>. Mushroom scientists that work for the Great Mushroom King think that the Universe isn't exactly right and the distance from the center of the Universe to a point equals xa·yb·zc. To test the metric of mushroom scientists, the usual scientists offered them a task: find such x, y, z (0 ≤ x, y, z; x + y + z ≤ S), that the distance between the center of the Universe and the point (x, y, z) is maximum possible in the metric of mushroom scientists. The mushroom scientists aren't good at maths, so they commissioned you to do the task. Note that in this problem, it is considered that 00 = 1. Input The first line contains a single integer S (1 ≤ S ≤ 103) — the maximum sum of coordinates of the sought point. The second line contains three space-separated integers a, b, c (0 ≤ a, b, c ≤ 103) — the numbers that describe the metric of mushroom scientists. Output Print three real numbers — the coordinates of the point that reaches maximum value in the metrics of mushroom scientists. If there are multiple answers, print any of them that meets the limitations. A natural logarithm of distance from the center of the Universe to the given point in the metric of mushroom scientists shouldn't differ from the natural logarithm of the maximum distance by more than 10 - 6. We think that ln(0) = - ∞. Examples Input 3 1 1 1 Output 1.0 1.0 1.0 Input 3 2 0 0 Output 3.0 0.0 0.0 Submitted Solution: ``` s = int(input()) a, b, c = map(int, input().split()) sum = a + b + c if a + b + c: print(a * s / sum, b * s / sum, c * s / sum) else: print(0, s, 0) ```
instruction
0
80,212
3
160,424
Yes
output
1
80,212
3
160,425
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (x, y, z). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formula: <image>. Mushroom scientists that work for the Great Mushroom King think that the Universe isn't exactly right and the distance from the center of the Universe to a point equals xa·yb·zc. To test the metric of mushroom scientists, the usual scientists offered them a task: find such x, y, z (0 ≤ x, y, z; x + y + z ≤ S), that the distance between the center of the Universe and the point (x, y, z) is maximum possible in the metric of mushroom scientists. The mushroom scientists aren't good at maths, so they commissioned you to do the task. Note that in this problem, it is considered that 00 = 1. Input The first line contains a single integer S (1 ≤ S ≤ 103) — the maximum sum of coordinates of the sought point. The second line contains three space-separated integers a, b, c (0 ≤ a, b, c ≤ 103) — the numbers that describe the metric of mushroom scientists. Output Print three real numbers — the coordinates of the point that reaches maximum value in the metrics of mushroom scientists. If there are multiple answers, print any of them that meets the limitations. A natural logarithm of distance from the center of the Universe to the given point in the metric of mushroom scientists shouldn't differ from the natural logarithm of the maximum distance by more than 10 - 6. We think that ln(0) = - ∞. Examples Input 3 1 1 1 Output 1.0 1.0 1.0 Input 3 2 0 0 Output 3.0 0.0 0.0 Submitted Solution: ``` from sys import stdin, stdout s = int(stdin.readline()) a, b, c = map(int, stdin.readline().split()) E = 10 ** (-7) x, y, z = 0, 0, 0 ans = 0 def power(v, n): cnt = 1 while n: if n % 2: cnt *= v n >>= 1 v *= v return cnt def count(f, s, t): return (power(f, int(a)) * power(s, int(b)) * power(t, int(c))) def third(S, f, s): global ans global x, y, z l, r = 0, S lb, rb = l + (r - l) / 3, r - (r - l) / 3 while (r - l > E): if count(f, s, lb) > count(f, s, rb): r = rb else: l = lb lb, rb = l + (r - l) / 3, r - (r - l) / 3 if (count(f, s, (lb + rb) / 2)) > ans: x, y, z = f, s, (lb + rb) / 2 ans = count(f, s, (lb + rb) / 2) return count(f, s, (lb + rb) / 2) def second(S, f): l, r = 0, S lb, rb = l + (r - l) / 3, r - (r - l) / 3 while (r - l > E): if third(S - lb, f, lb) > third(S - rb, f, rb): r = rb else: l = lb lb, rb = l + (r - l) / 3, r - (r - l) / 3 return third(S - (lb + rb) / 2, f, (lb + rb) / 2) def first(S): l, r = 0, s lb, rb = l + (r - l) / 3, r - (r - l) / 3 while (r - l > E): if second(S - lb, lb) > second(S - rb, rb): r = rb else: l = lb lb, rb = l + (r - l) / 3, r - (r - l) / 3 return (S - (rb + lb) / 2, (rb + lb) / 2) first(s) stdout.write(str(x) + ' ' + str(y) + ' ' + str(z)) ```
instruction
0
80,213
3
160,426
No
output
1
80,213
3
160,427
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (x, y, z). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formula: <image>. Mushroom scientists that work for the Great Mushroom King think that the Universe isn't exactly right and the distance from the center of the Universe to a point equals xa·yb·zc. To test the metric of mushroom scientists, the usual scientists offered them a task: find such x, y, z (0 ≤ x, y, z; x + y + z ≤ S), that the distance between the center of the Universe and the point (x, y, z) is maximum possible in the metric of mushroom scientists. The mushroom scientists aren't good at maths, so they commissioned you to do the task. Note that in this problem, it is considered that 00 = 1. Input The first line contains a single integer S (1 ≤ S ≤ 103) — the maximum sum of coordinates of the sought point. The second line contains three space-separated integers a, b, c (0 ≤ a, b, c ≤ 103) — the numbers that describe the metric of mushroom scientists. Output Print three real numbers — the coordinates of the point that reaches maximum value in the metrics of mushroom scientists. If there are multiple answers, print any of them that meets the limitations. A natural logarithm of distance from the center of the Universe to the given point in the metric of mushroom scientists shouldn't differ from the natural logarithm of the maximum distance by more than 10 - 6. We think that ln(0) = - ∞. Examples Input 3 1 1 1 Output 1.0 1.0 1.0 Input 3 2 0 0 Output 3.0 0.0 0.0 Submitted Solution: ``` n = int(input()) a, b, c = map(int, input().split()) if max((a, b, c)) == a: print(n, 0, 0) elif max((a, b, c)) == b: print(0, n, 0) elif max((a, b, c)) == c: print(0, 0, n) ```
instruction
0
80,214
3
160,428
No
output
1
80,214
3
160,429
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (x, y, z). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formula: <image>. Mushroom scientists that work for the Great Mushroom King think that the Universe isn't exactly right and the distance from the center of the Universe to a point equals xa·yb·zc. To test the metric of mushroom scientists, the usual scientists offered them a task: find such x, y, z (0 ≤ x, y, z; x + y + z ≤ S), that the distance between the center of the Universe and the point (x, y, z) is maximum possible in the metric of mushroom scientists. The mushroom scientists aren't good at maths, so they commissioned you to do the task. Note that in this problem, it is considered that 00 = 1. Input The first line contains a single integer S (1 ≤ S ≤ 103) — the maximum sum of coordinates of the sought point. The second line contains three space-separated integers a, b, c (0 ≤ a, b, c ≤ 103) — the numbers that describe the metric of mushroom scientists. Output Print three real numbers — the coordinates of the point that reaches maximum value in the metrics of mushroom scientists. If there are multiple answers, print any of them that meets the limitations. A natural logarithm of distance from the center of the Universe to the given point in the metric of mushroom scientists shouldn't differ from the natural logarithm of the maximum distance by more than 10 - 6. We think that ln(0) = - ∞. Examples Input 3 1 1 1 Output 1.0 1.0 1.0 Input 3 2 0 0 Output 3.0 0.0 0.0 Submitted Solution: ``` from sys import stdin, stdout s = int(stdin.readline()) a, b, c = map(int, stdin.readline().split()) E = 10 ** (-5) x, y, z = 0, 0, 0 ans = 0 def count(f, s, t): return (f ** a * s ** b * t ** c)#бинарное возведение в степень запилим def third(S, f, s): global x, y, z l, r = 0, S lb, rb = l + (r - l) / 3, r - (r - l) / 3 while (r - l > E): if count(f, s, lb) > count(f, s, rb): r = rb else: l = lb lb, rb = l + (r - l) / 3, r - (r - l) / 3 if (count(f, s, (lb + rb) / 2)) > ans: x, y, z = f, s, (lb + rb) / 2 return count(f, s, (lb + rb) / 2) def second(S, f): l, r = 0, S lb, rb = l + (r - l) / 3, r - (r - l) / 3 while (r - l > E): if third(S - lb, f, lb) > third(S - rb, f, rb): r = rb else: l = lb lb, rb = l + (r - l) / 3, r - (r - l) / 3 return third(S - (lb + rb) / 2, f, (lb + rb) / 2) def first(S): l, r = 0, s lb, rb = l + (r - l) / 3, r - (r - l) / 3 while (r - l > E): if second(S - lb, lb) > second(S - rb, rb): r = rb else: l = lb lb, rb = l + (r - l) / 3, r - (r - l) / 3 return (S - (rb + lb) / 2, (rb + lb) / 2) first(s) stdout.write(str(x) + ' ' + str(y) + ' ' + str(z)) ```
instruction
0
80,215
3
160,430
No
output
1
80,215
3
160,431
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (x, y, z). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formula: <image>. Mushroom scientists that work for the Great Mushroom King think that the Universe isn't exactly right and the distance from the center of the Universe to a point equals xa·yb·zc. To test the metric of mushroom scientists, the usual scientists offered them a task: find such x, y, z (0 ≤ x, y, z; x + y + z ≤ S), that the distance between the center of the Universe and the point (x, y, z) is maximum possible in the metric of mushroom scientists. The mushroom scientists aren't good at maths, so they commissioned you to do the task. Note that in this problem, it is considered that 00 = 1. Input The first line contains a single integer S (1 ≤ S ≤ 103) — the maximum sum of coordinates of the sought point. The second line contains three space-separated integers a, b, c (0 ≤ a, b, c ≤ 103) — the numbers that describe the metric of mushroom scientists. Output Print three real numbers — the coordinates of the point that reaches maximum value in the metrics of mushroom scientists. If there are multiple answers, print any of them that meets the limitations. A natural logarithm of distance from the center of the Universe to the given point in the metric of mushroom scientists shouldn't differ from the natural logarithm of the maximum distance by more than 10 - 6. We think that ln(0) = - ∞. Examples Input 3 1 1 1 Output 1.0 1.0 1.0 Input 3 2 0 0 Output 3.0 0.0 0.0 Submitted Solution: ``` from sys import stdin, stdout from decimal import Decimal from math import log s = Decimal(stdin.readline()) a, b, c = map(Decimal, stdin.readline().split()) E = Decimal(10) ** Decimal(-3) x, y, z = 0, 0, 0 ans = Decimal(0) def power(v, n): cnt = Decimal(1) while n: if n % 2: cnt *= v n >>= 1 v *= v return cnt def count(f, s, t): return (power(f, int(a)) + power(s, int(b)) + power(t, int(c))) def third(S, f, s): global x, y, z l, r = Decimal(0), S lb, rb = l + (r - l) / Decimal(3), r - (r - l) / Decimal(3) while (r - l > E): if count(f, s, lb) > count(f, s, rb): r = rb else: l = lb lb, rb = l + (r - l) / 3, r - (r - l) / Decimal(3) if (count(f, s, (lb + rb) / 2)) > ans: x, y, z = f, s, (lb + rb) / Decimal(2) return count(f, s, (lb + rb) / Decimal(2)) def second(S, f): l, r = Decimal(0), S lb, rb = l + (r - l) / Decimal(3), r - (r - l) / Decimal(3) while (r - l > E): if third(S - lb, f, lb) > third(S - rb, f, rb): r = rb else: l = lb lb, rb = l + (r - l) / Decimal(3), r - (r - l) / Decimal(3) return third(S - (lb + rb) / Decimal(2), f, (lb + rb) / Decimal(2)) def first(S): l, r = Decimal(0), s lb, rb = l + (r - l) / Decimal(3), r - (r - l) / Decimal(3) while (r - l > E): if second(S - lb, lb) > second(S - rb, rb): r = rb else: l = lb lb, rb = l + (r - l) / Decimal(3), r - (r - l) / Decimal(3) return (S - (rb + lb) / Decimal(2), (rb + lb) / Decimal(2)) first(s) stdout.write(str(x) + ' ' + str(y) + ' ' + str(z)) ```
instruction
0
80,216
3
160,432
No
output
1
80,216
3
160,433
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill paper, and paper kills a rock. Your task is to determine for each species what is the probability that this species will be the only one to inhabit this island after a long enough period of time. Input The single line contains three integers r, s and p (1 ≤ r, s, p ≤ 100) — the original number of individuals in the species of rock, scissors and paper, respectively. Output Print three space-separated real numbers: the probabilities, at which the rocks, the scissors and the paper will be the only surviving species, respectively. The answer will be considered correct if the relative or absolute error of each number doesn't exceed 10 - 9. Examples Input 2 2 2 Output 0.333333333333 0.333333333333 0.333333333333 Input 2 1 2 Output 0.150000000000 0.300000000000 0.550000000000 Input 1 1 3 Output 0.057142857143 0.657142857143 0.285714285714 Submitted Solution: ``` import sys input=sys.stdin.readline r,s,p=map(int,input().split()) dp=[[[0]*(p+1) for i in range(s+1)] for j in range(r+1)] dp[r][s][p]=1 for i in range(r+1)[::-1]: for j in range(s+1)[::-1]: for k in range(p+1)[::-1]: x=i*j+j*k+k*i if i>0 and j>0: dp[i][j-1][k]+=i*j*dp[i][j][k]/x if j>0 and k>0: dp[i][j][k-1]+=j*k*dp[i][j][k]/x if k>0 and i>0: dp[i-1][j][k]+=i*k*dp[i][j][k]/x a1,a2,a3=0,0,0 for i in range(1,r+1): a1+=dp[i][0][0] for i in range(1,s+1): a2+=dp[0][i][0] for i in range(1,p+1): a3+=dp[0][0][i] print(a1,a2,a3) ```
instruction
0
80,411
3
160,822
Yes
output
1
80,411
3
160,823
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill paper, and paper kills a rock. Your task is to determine for each species what is the probability that this species will be the only one to inhabit this island after a long enough period of time. Input The single line contains three integers r, s and p (1 ≤ r, s, p ≤ 100) — the original number of individuals in the species of rock, scissors and paper, respectively. Output Print three space-separated real numbers: the probabilities, at which the rocks, the scissors and the paper will be the only surviving species, respectively. The answer will be considered correct if the relative or absolute error of each number doesn't exceed 10 - 9. Examples Input 2 2 2 Output 0.333333333333 0.333333333333 0.333333333333 Input 2 1 2 Output 0.150000000000 0.300000000000 0.550000000000 Input 1 1 3 Output 0.057142857143 0.657142857143 0.285714285714 Submitted Solution: ``` r,s,p=map(int,input().split()) dp=[[[0 for i in range(p+1)] for j in range(s+1)]for k in range(r+1)] dp[r][s][p]=1 ro=r while(ro>=0): si=s while(si>=0): pa=p while(pa>=0): val1=ro*si val2=pa*si val3=pa*ro su=val1+val2+val3 if su!=0: if ro>=1: dp[ro-1][si][pa]+=(val3/su)*dp[ro][si][pa] if pa>=1: dp[ro][si-1][pa]+=(val1/su)*dp[ro][si][pa] if si>=1: dp[ro][si][pa-1]+=(val2/su)*dp[ro][si][pa] pa+=-1 si+=-1 ro+=-1 p1=0 p2=0 p3=0 for i in range(1,r+1): p1+=dp[i][0][0] for i in range(1,s+1): p2+=dp[0][i][0] for i in range(1,p+1): p3+=dp[0][0][i] print(1-p2-p3,p2,p3) ```
instruction
0
80,412
3
160,824
Yes
output
1
80,412
3
160,825
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill paper, and paper kills a rock. Your task is to determine for each species what is the probability that this species will be the only one to inhabit this island after a long enough period of time. Input The single line contains three integers r, s and p (1 ≤ r, s, p ≤ 100) — the original number of individuals in the species of rock, scissors and paper, respectively. Output Print three space-separated real numbers: the probabilities, at which the rocks, the scissors and the paper will be the only surviving species, respectively. The answer will be considered correct if the relative or absolute error of each number doesn't exceed 10 - 9. Examples Input 2 2 2 Output 0.333333333333 0.333333333333 0.333333333333 Input 2 1 2 Output 0.150000000000 0.300000000000 0.550000000000 Input 1 1 3 Output 0.057142857143 0.657142857143 0.285714285714 Submitted Solution: ``` # aadiupadhyay import os.path from math import gcd, floor, ceil from collections import * import sys mod = 1000000007 INF = float('inf') def st(): return list(sys.stdin.readline().strip()) def li(): return list(map(int, sys.stdin.readline().split())) def mp(): return map(int, sys.stdin.readline().split()) def inp(): return int(sys.stdin.readline()) def pr(n): return sys.stdout.write(str(n)+"\n") def prl(n): return sys.stdout.write(str(n)+" ") if os.path.exists('input.txt'): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') A, B, C = mp() A += 1 B += 1 C += 1 M = max(A, B, C) p = [[[0] * (M) for i in range(M)] for j in range(M)] for a in range(M): for b in range(M): for c in range(M): val = 0 if a == 0 or b == 0: val = 0 elif c == 0: val = 1 else: div = a*b + b*c + c*a val = (a*b) / div * p[a][b-1][c] + (b*c) / \ div * p[a][b][c-1] + (a*c) / div * p[a-1][b][c] p[a][b][c] = val print(p[A-1][B-1][C-1], p[B-1][C-1][A-1], p[C-1][A-1][B-1]) ```
instruction
0
80,413
3
160,826
Yes
output
1
80,413
3
160,827
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill paper, and paper kills a rock. Your task is to determine for each species what is the probability that this species will be the only one to inhabit this island after a long enough period of time. Input The single line contains three integers r, s and p (1 ≤ r, s, p ≤ 100) — the original number of individuals in the species of rock, scissors and paper, respectively. Output Print three space-separated real numbers: the probabilities, at which the rocks, the scissors and the paper will be the only surviving species, respectively. The answer will be considered correct if the relative or absolute error of each number doesn't exceed 10 - 9. Examples Input 2 2 2 Output 0.333333333333 0.333333333333 0.333333333333 Input 2 1 2 Output 0.150000000000 0.300000000000 0.550000000000 Input 1 1 3 Output 0.057142857143 0.657142857143 0.285714285714 Submitted Solution: ``` # by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO, IOBase def main(): r,s,p = map(int,input().split()) dpr = [[[0]*(r+1) for _ in range(s+1)] for _ in range(p+1)] # rock ; scissors ; paper for i in range(1,r+1): dpr[0][0][i] = 1 for i in range(p+1): for j in range(s+1): for k in range(r+1): z = i*j+j*k+k*i if not z: continue dpr[i][j][k] = (dpr[i-1][j][k]*i*j+dpr[i][j-1][k]*j*k+ dpr[i][j][k-1]*i*k)/z dps = [[[0]*(r+1) for _ in range(s+1)] for _ in range(p+1)] # rock ; scissors ; paper for i in range(1,s+1): dps[0][i][0] = 1 for i in range(p+1): for j in range(s+1): for k in range(r+1): z = i*j+j*k+k*i if not z: continue dps[i][j][k] = (dps[i-1][j][k]*i*j+dps[i][j-1][k]*j*k+ dps[i][j][k-1]*i*k)/z print(dpr[-1][-1][-1],dps[-1][-1][-1],1-dpr[-1][-1][-1]-dps[-1][-1][-1]) # Fast IO Region BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") if __name__ == "__main__": main() ```
instruction
0
80,414
3
160,828
Yes
output
1
80,414
3
160,829
Evaluate the correctness of the submitted Python 2 solution to the coding contest problem. Provide a "Yes" or "No" response. The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill paper, and paper kills a rock. Your task is to determine for each species what is the probability that this species will be the only one to inhabit this island after a long enough period of time. Input The single line contains three integers r, s and p (1 ≤ r, s, p ≤ 100) — the original number of individuals in the species of rock, scissors and paper, respectively. Output Print three space-separated real numbers: the probabilities, at which the rocks, the scissors and the paper will be the only surviving species, respectively. The answer will be considered correct if the relative or absolute error of each number doesn't exceed 10 - 9. Examples Input 2 2 2 Output 0.333333333333 0.333333333333 0.333333333333 Input 2 1 2 Output 0.150000000000 0.300000000000 0.550000000000 Input 1 1 3 Output 0.057142857143 0.657142857143 0.285714285714 Submitted Solution: ``` from sys import stdin, stdout from collections import Counter, defaultdict from itertools import permutations, combinations from fractions import Fraction raw_input = stdin.readline pr = stdout.write mod=10**9+7 def ni(): return int(raw_input()) def li(): return map(int,raw_input().split()) def pn(n): stdout.write(str(n)+'\n') def pa(arr): pr(' '.join(map(str,arr))+'\n') # fast read function for total integer input def inp(): # this function returns whole input of # space/line seperated integers # Use Ctrl+D to flush stdin. return map(int,stdin.read().split()) range = xrange # not for python 3.0+ # main code def fun(x,r,s,p): den=(r*s+s*p+r*p) if x==0: return (r*s)/float(den) elif x==1: return (s*p)/float(den) else: return (r*p)/float(den) r,s,p=li() dp=[[[0 for i in range(p+1)] for j in range(s+1)] for k in range(r+1)] dp[-1][-1][-1]=1 for i in range(r,-1,-1): for j in range(s,-1,-1): for k in range(p,-1,-1): if [i,j,k].count(0)==2: continue if j>0: dp[i][j-1][k]+=(dp[i][j][k]*fun(0,i,j,k)) if i>0: dp[i-1][j][k]+=(dp[i][j][k]*fun(2,i,j,k)) if k>0: dp[i][j][k-1]+=(dp[i][j][k]*fun(1,i,j,k)) sm1,sm2,sm3=0,0,0 for i in range(1,r+1): sm1+=dp[i][0][0] for i in range(1,s+1): sm2+=dp[0][i][0] for i in range(1,p+1 ): sm3+=dp[0][0][i] pa([sm1,sm2,sm3]) ```
instruction
0
80,415
3
160,830
Yes
output
1
80,415
3
160,831
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill paper, and paper kills a rock. Your task is to determine for each species what is the probability that this species will be the only one to inhabit this island after a long enough period of time. Input The single line contains three integers r, s and p (1 ≤ r, s, p ≤ 100) — the original number of individuals in the species of rock, scissors and paper, respectively. Output Print three space-separated real numbers: the probabilities, at which the rocks, the scissors and the paper will be the only surviving species, respectively. The answer will be considered correct if the relative or absolute error of each number doesn't exceed 10 - 9. Examples Input 2 2 2 Output 0.333333333333 0.333333333333 0.333333333333 Input 2 1 2 Output 0.150000000000 0.300000000000 0.550000000000 Input 1 1 3 Output 0.057142857143 0.657142857143 0.285714285714 Submitted Solution: ``` #540D [r,s,p] = list(map(float,input().split())) def prob(k,n,b,mem): if k > 0 and n >= 0 and b == 0: return [1.,0.,0.],mem elif k == 0 and n > 0 and b >= 0: return [0.,1.,0.],mem elif k >= 0 and n == 0 and b > 0: return [0.,0.,1.],mem elif k < 0 or n < 0 or b < 0: return [0.,0.,0.],mem elif k == n and k == b and k > 0: return [1./3.,1./3.,1./3.],mem else: if mem[int(k-1)][int(n)][int(b)] == None: g0,mem = prob(k-1,n,b,mem) else: g0 = mem[int(k-1)][int(n)][int(b)]; if mem[int(k)][int(n-1)][int(b)] == None: g1,mem = prob(k,n-1,b,mem) else: g1 = mem[int(k)][int(n-1)][int(b)]; if mem[int(k)][int(n)][int(b-1)] == None: g2,mem = prob(k,n,b-1,mem) else: g2 = mem[int(k)][int(n)][int(b-1)]; l = [] x = k*b y = k*n z = n*b r = x + y + z for i in range(3): l.append((x*g0[i]+y*g1[i]+z*g2[i])/r) mem[int(k)][int(n)][int(b)] = l return l,mem mem = [None]*120 mem = [mem]*120 mem = [mem]*120 s,x = prob(r,s,p,mem) for i in range(3): print(s[i], end=' ') ```
instruction
0
80,416
3
160,832
No
output
1
80,416
3
160,833
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill paper, and paper kills a rock. Your task is to determine for each species what is the probability that this species will be the only one to inhabit this island after a long enough period of time. Input The single line contains three integers r, s and p (1 ≤ r, s, p ≤ 100) — the original number of individuals in the species of rock, scissors and paper, respectively. Output Print three space-separated real numbers: the probabilities, at which the rocks, the scissors and the paper will be the only surviving species, respectively. The answer will be considered correct if the relative or absolute error of each number doesn't exceed 10 - 9. Examples Input 2 2 2 Output 0.333333333333 0.333333333333 0.333333333333 Input 2 1 2 Output 0.150000000000 0.300000000000 0.550000000000 Input 1 1 3 Output 0.057142857143 0.657142857143 0.285714285714 Submitted Solution: ``` from operator import add r, s, p = map(int, input().split()) def ret_ps(r, s, p): vals = {} for i in range(r+1): for j in range(s+1): for k in range(p+1): if i== 0 and j > 0: vals[(i,j,k)]= (0, 1, 0) elif i == 0 and j == 0: vals[(i,j,k)] = (0, 0, 1) elif j== 0 and k>0 : vals[(i,j,k)] = ( 0, 0, 1) elif j== 0 and k ==0: vals[(i,j,k)] = ( 1, 0, 0) elif k==0 and i> 0: vals[(i,j,k)] =( 1, 0, 0) elif k == 0 and i == 0: vals[(i,j,k)] = ( 0, 1, 0) elif i== j== k: vals[(i,j,k)] = ( 1/3, 1/3, 1/3) if (i,j,k) in vals: continue denom = i*j+j*k+i*k res1 = tuple(t*i*j/denom for t in vals[(i, j-1, k)]) res2 = tuple(t*j*k/denom for t in vals[(i, j, k-1)]) res3 = tuple(t*i*k/denom for t in vals[(i-1, j, k)]) res = tuple(map(add, tuple(map(add, res1, res2)), res3)) vals[(i,j,k)] = res print(i,j,k,res) return vals[(r, s, p)] print(ret_ps(r, s, p)) ```
instruction
0
80,417
3
160,834
No
output
1
80,417
3
160,835
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill paper, and paper kills a rock. Your task is to determine for each species what is the probability that this species will be the only one to inhabit this island after a long enough period of time. Input The single line contains three integers r, s and p (1 ≤ r, s, p ≤ 100) — the original number of individuals in the species of rock, scissors and paper, respectively. Output Print three space-separated real numbers: the probabilities, at which the rocks, the scissors and the paper will be the only surviving species, respectively. The answer will be considered correct if the relative or absolute error of each number doesn't exceed 10 - 9. Examples Input 2 2 2 Output 0.333333333333 0.333333333333 0.333333333333 Input 2 1 2 Output 0.150000000000 0.300000000000 0.550000000000 Input 1 1 3 Output 0.057142857143 0.657142857143 0.285714285714 Submitted Solution: ``` D = dict() def tup_add2(x,y): return (x[0]+y[0], x[1]+y[1], x[2]+y[2]) def tup_add3(x,y,z): return tup_add2(x,tup_add2(y,z)) def nc2(n): return (n*(n-1))//2 def mult(x, val): return (x[0]*val, x[1]*val, x[2]*val) def gcd(x,y,z): i = 2 r = 1 while i <= min(x,y,z): if x % i == 0 and y % i == 0 and z % i == 0: x //= i y //= i z //= i r *= i else: i += 1 return r def f(r, p, s): global D if (r,p,s) in D: return D[(r,p,s)] d = gcd(r,p,s) if d > 1: return f(r//d, p//d, s//d) if (r == 0): return (0,0,1) elif (p == 0): return (1,0,0) elif (s == 0): return (0,1,0) else: n = nc2(r+p+s) r_loss = mult(f(r-1,p,s),(r*p)/n) p_loss = mult(f(r,p-1,s),(s*p)/n) s_loss = mult(f(r,p,s-1),(r*s)/n) total = tup_add3(r_loss, p_loss, s_loss) tie_prob = (nc2(r)+nc2(p)+nc2(s))/n inf_sum = (1/(1-tie_prob)) - 1 D[(r,p,s)] = tup_add2(total, mult(total, inf_sum)) return D[(r,p,s)] def run(): i = 0 global D for line in iter(input, ''): line = line.split(' ') r = int(line[0]) s = int(line[1]) p = int(line[2]) break a = (f(r,p,s)) print(a[0], a[2], a[1]) #print(D) # print((1,2,3), D[1,2,3]) # print((1,3,2), D[1,3,2]) # print((2,1,3), D[2,1,3]) # print((2,3,1), D[2,3,1]) # print((3,1,2), D[3,1,2]) # print((3,2,1), D[3,2,1]) # print((3,5,11), D[3,5,11]) # print((1,3,2), D[3,11,5]) # print((2,1,3), D[5,3,]) # print((2,3,1), D[2,3,1]) # print((3,1,2), D[3,1,2]) # print((3,2,1), D[3,2,1]) run() ```
instruction
0
80,418
3
160,836
No
output
1
80,418
3
160,837
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill paper, and paper kills a rock. Your task is to determine for each species what is the probability that this species will be the only one to inhabit this island after a long enough period of time. Input The single line contains three integers r, s and p (1 ≤ r, s, p ≤ 100) — the original number of individuals in the species of rock, scissors and paper, respectively. Output Print three space-separated real numbers: the probabilities, at which the rocks, the scissors and the paper will be the only surviving species, respectively. The answer will be considered correct if the relative or absolute error of each number doesn't exceed 10 - 9. Examples Input 2 2 2 Output 0.333333333333 0.333333333333 0.333333333333 Input 2 1 2 Output 0.150000000000 0.300000000000 0.550000000000 Input 1 1 3 Output 0.057142857143 0.657142857143 0.285714285714 Submitted Solution: ``` # -*- coding: utf-8 -*- """ created by huash06 at 2015-05-07 09:23 """ __author__ = 'huash06' r, s, p = map(int, input().split(' ')) def test(r, s, p): if r == s == p: print(0.33333333333333, 0.33333333333333, 0.33333333333333) g = [[[0 for k in range(p+2)] for j in range(s+2)] for i in range(r+2)] g[r][s][p] = 1 for i in range(r, -1, -1): for j in range(s, -1, -1): for k in range(p, -1, -1): v = g[i][j][k] d = 3 - (i, j, k).count(0) if d <= 0: continue if d == 1: if i > 0: g[i-1][j][k] += v elif j > 0: g[i][j-1][k] += v elif k > 0: g[i][j][k-1] += v elif d == 2: if i > 0 and j > 0: g[i][j-1][k] += v elif j > 0 and k > 0: g[i][j][k-1] += v elif k > 0 and i > 0: g[i-1][j][k] += v else: d = i + j + k t = i*j + i*k + j*k g[i][j-1][k] += v*(i*j/t) g[i][j][k-1] += v*(j*k/t) g[i-1][j][k] += v*(i*k/t) # for i in range(r+1): # for j in range(s+1): # for k in range(p+1): # print(i, j, k, g[i][j][k]) print(g[1][0][0], g[0][1][0], g[0][0][1]) test(r, s, p) # for r in range(1, 100): # for j in range(1, 100): # for p in range(1, 100): # test(r, s, p) ```
instruction
0
80,419
3
160,838
No
output
1
80,419
3
160,839
Provide tags and a correct Python 3 solution for this coding contest problem. At first, there was a legend related to the name of the problem, but now it's just a formal statement. You are given n points a_1, a_2, ..., a_n on the OX axis. Now you are asked to find such an integer point x on OX axis that f_k(x) is minimal possible. The function f_k(x) can be described in the following way: * form a list of distances d_1, d_2, ..., d_n where d_i = |a_i - x| (distance between a_i and x); * sort list d in non-descending order; * take d_{k + 1} as a result. If there are multiple optimal answers you can print any of them. Input The first line contains single integer T ( 1 ≤ T ≤ 2 ⋅ 10^5) — number of queries. Next 2 ⋅ T lines contain descriptions of queries. All queries are independent. The first line of each query contains two integers n, k (1 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k < n) — the number of points and constant k. The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_1 < a_2 < ... < a_n ≤ 10^9) — points in ascending order. It's guaranteed that ∑{n} doesn't exceed 2 ⋅ 10^5. Output Print T integers — corresponding points x which have minimal possible value of f_k(x). If there are multiple answers you can print any of them. Example Input 3 3 2 1 2 5 2 1 1 1000000000 1 0 4 Output 3 500000000 4
instruction
0
80,887
3
161,774
Tags: binary search, brute force, greedy Correct Solution: ``` # -*- coding: utf-8 -*- # @Date : 2019-06-06 09:38:34 # @Author : raj lath (oorja.halt@gmail.com) # @Link : link # @Version : 1.0.0 import sys sys.setrecursionlimit(10**5+1) inf = int(10 ** 20) max_val = inf min_val = -inf RW = lambda : sys.stdin.readline().strip() RI = lambda : int(RW()) RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()] RWI = lambda : [x for x in sys.stdin.readline().strip().split()] nb_test = RI() for _ in range(nb_test): lens, k = RMI() arrs = sorted(RMI()) ans = arrs[0] max_diff = arrs[-1] - arrs[0] for i in range(lens - k): curr = arrs[i+k] - arrs[i] if curr <= max_diff: max_diff = curr ans = (arrs[i + k] + arrs[i]) // 2 print(ans) ```
output
1
80,887
3
161,775
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. At first, there was a legend related to the name of the problem, but now it's just a formal statement. You are given n points a_1, a_2, ..., a_n on the OX axis. Now you are asked to find such an integer point x on OX axis that f_k(x) is minimal possible. The function f_k(x) can be described in the following way: * form a list of distances d_1, d_2, ..., d_n where d_i = |a_i - x| (distance between a_i and x); * sort list d in non-descending order; * take d_{k + 1} as a result. If there are multiple optimal answers you can print any of them. Input The first line contains single integer T ( 1 ≤ T ≤ 2 ⋅ 10^5) — number of queries. Next 2 ⋅ T lines contain descriptions of queries. All queries are independent. The first line of each query contains two integers n, k (1 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k < n) — the number of points and constant k. The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_1 < a_2 < ... < a_n ≤ 10^9) — points in ascending order. It's guaranteed that ∑{n} doesn't exceed 2 ⋅ 10^5. Output Print T integers — corresponding points x which have minimal possible value of f_k(x). If there are multiple answers you can print any of them. Example Input 3 3 2 1 2 5 2 1 1 1000000000 1 0 4 Output 3 500000000 4 Submitted Solution: ``` import sys from array import array # noqa: F401 import typing as Tp # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') def bfs(adj, peoples): stack = [0] order = [] parent = [-1] * len(adj) subt = peoples[:] while stack: v = stack.pop() order.append(v) for dest in adj[v]: if parent[v] == dest: continue parent[dest] = v stack.append(dest) for v in reversed(order): if v != 0: subt[parent[v]] += subt[v] return order, subt, parent def main(): t = int(input()) ans = [0] * t for ti in range(t): n, k = map(int, input().split()) a = tuple(map(int, input().split())) + (10**10,) ok, ng, res = 10**9, -1, 0 while abs(ok - ng) > 1: mid = (ok + ng) >> 1 r = 0 for l in range(n): while a[r] <= a[l] + 2 * mid: r += 1 if r - l > k: ok, res = mid, a[l] + mid break else: ng = mid ans[ti] = res sys.stdout.buffer.write(('\n'.join(map(str, ans)) + '\n').encode('utf-8')) if __name__ == '__main__': main() ```
instruction
0
80,894
3
161,788
Yes
output
1
80,894
3
161,789
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. At first, there was a legend related to the name of the problem, but now it's just a formal statement. You are given n points a_1, a_2, ..., a_n on the OX axis. Now you are asked to find such an integer point x on OX axis that f_k(x) is minimal possible. The function f_k(x) can be described in the following way: * form a list of distances d_1, d_2, ..., d_n where d_i = |a_i - x| (distance between a_i and x); * sort list d in non-descending order; * take d_{k + 1} as a result. If there are multiple optimal answers you can print any of them. Input The first line contains single integer T ( 1 ≤ T ≤ 2 ⋅ 10^5) — number of queries. Next 2 ⋅ T lines contain descriptions of queries. All queries are independent. The first line of each query contains two integers n, k (1 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k < n) — the number of points and constant k. The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_1 < a_2 < ... < a_n ≤ 10^9) — points in ascending order. It's guaranteed that ∑{n} doesn't exceed 2 ⋅ 10^5. Output Print T integers — corresponding points x which have minimal possible value of f_k(x). If there are multiple answers you can print any of them. Example Input 3 3 2 1 2 5 2 1 1 1000000000 1 0 4 Output 3 500000000 4 Submitted Solution: ``` import sys from collections import Counter def input(): return sys.stdin.readline().strip() def dinput(): return int(input()) def tinput(): return input().split() def rinput(): return map(int, tinput()) def main(): for i in range(dinput()): leonov, leonov1 = rinput() a = list(rinput()) aleonov1 = min((a[i]-a[i-leonov1],a[i]) for i in range(leonov1, leonov)) print(aleonov1[1] - (aleonov1[0] + 1) // 2) main() ```
instruction
0
80,895
3
161,790
Yes
output
1
80,895
3
161,791
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. At first, there was a legend related to the name of the problem, but now it's just a formal statement. You are given n points a_1, a_2, ..., a_n on the OX axis. Now you are asked to find such an integer point x on OX axis that f_k(x) is minimal possible. The function f_k(x) can be described in the following way: * form a list of distances d_1, d_2, ..., d_n where d_i = |a_i - x| (distance between a_i and x); * sort list d in non-descending order; * take d_{k + 1} as a result. If there are multiple optimal answers you can print any of them. Input The first line contains single integer T ( 1 ≤ T ≤ 2 ⋅ 10^5) — number of queries. Next 2 ⋅ T lines contain descriptions of queries. All queries are independent. The first line of each query contains two integers n, k (1 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k < n) — the number of points and constant k. The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_1 < a_2 < ... < a_n ≤ 10^9) — points in ascending order. It's guaranteed that ∑{n} doesn't exceed 2 ⋅ 10^5. Output Print T integers — corresponding points x which have minimal possible value of f_k(x). If there are multiple answers you can print any of them. Example Input 3 3 2 1 2 5 2 1 1 1000000000 1 0 4 Output 3 500000000 4 Submitted Solution: ``` import sys from math import log2 import bisect import heapq # from collections import deque # from types import GeneratorType # def bootstrap(func, stack=[]): # def wrapped_function(*args, **kwargs): # if stack: # return func(*args, **kwargs) # else: # call = func(*args, **kwargs) # while True: # if type(call) is GeneratorType: # stack.append(call) # call = next(call) # else: # stack.pop() # if not stack: # break # call = stack[-1].send(call) # return call # return wrapped_function Ri = lambda : [int(x) for x in sys.stdin.readline().split()] ri = lambda : sys.stdin.readline().strip() def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') INF = 10 ** 18 MOD = 10**9+7 for _ in range(int(ri())): n,k = Ri() a = Ri() k+=1 minn = INF ans = -1 for i in range(k-1,n): avg1 = (a[i]+a[i-k+1])//2 avg2 = ceil((a[i]+a[i-k+1])/2) tminn = min(avg1-a[i-k+1],a[i]-avg2) if avg1-a[i-k+1] < minn: minn = avg1-a[i-k+1] ans = avg1 if a[i]-avg2 < minn: minn = a[i]-avg2 ans = avg2 print(ans) ```
instruction
0
80,898
3
161,796
No
output
1
80,898
3
161,797
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. At first, there was a legend related to the name of the problem, but now it's just a formal statement. You are given n points a_1, a_2, ..., a_n on the OX axis. Now you are asked to find such an integer point x on OX axis that f_k(x) is minimal possible. The function f_k(x) can be described in the following way: * form a list of distances d_1, d_2, ..., d_n where d_i = |a_i - x| (distance between a_i and x); * sort list d in non-descending order; * take d_{k + 1} as a result. If there are multiple optimal answers you can print any of them. Input The first line contains single integer T ( 1 ≤ T ≤ 2 ⋅ 10^5) — number of queries. Next 2 ⋅ T lines contain descriptions of queries. All queries are independent. The first line of each query contains two integers n, k (1 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k < n) — the number of points and constant k. The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_1 < a_2 < ... < a_n ≤ 10^9) — points in ascending order. It's guaranteed that ∑{n} doesn't exceed 2 ⋅ 10^5. Output Print T integers — corresponding points x which have minimal possible value of f_k(x). If there are multiple answers you can print any of them. Example Input 3 3 2 1 2 5 2 1 1 1000000000 1 0 4 Output 3 500000000 4 Submitted Solution: ``` t = int(input().lstrip()) res = 0 stack = [] cur = 1 MAX_INT = 10**10 + 7 overflow = False for _ in range(t): n, k = list(map(int, input().strip().split())) nums = list(map(int, input().strip().split())) min_dist = MAX_INT min_point = 0 for i in range(n - k): dist = (nums[i + k] - nums[i]) // 2 if dist < min_dist: min_dist = dist min_point = (nums[i + k] + nums[i]) // 2 print(min_point) ```
instruction
0
80,900
3
161,800
No
output
1
80,900
3
161,801