text
stringlengths
198
433k
conversation_id
int64
0
109k
Provide tags and a correct Python 3 solution for this coding contest problem. Igor the analyst fell asleep on the work and had a strange dream. In the dream his desk was crowded with computer mice, so he bought a mousetrap to catch them. The desk can be considered as an infinite plane, then the mousetrap is a rectangle which sides are parallel to the axes, and which opposite sides are located in points (x1, y1) and (x2, y2). Igor wants to catch all mice. Igor has analysed their behavior and discovered that each mouse is moving along a straight line with constant speed, the speed of the i-th mouse is equal to (vix, viy), that means that the x coordinate of the mouse increases by vix units per second, while the y coordinates increases by viy units. The mousetrap is open initially so that the mice are able to move freely on the desk. Igor can close the mousetrap at any moment catching all the mice that are strictly inside the mousetrap. Igor works a lot, so he is busy in the dream as well, and he asks you to write a program that by given mousetrap's coordinates, the initial coordinates of the mice and their speeds determines the earliest time moment in which he is able to catch all the mice. Please note that Igor can close the mousetrap only once. Input The first line contains single integer n (1 ≀ n ≀ 100 000) β€” the number of computer mice on the desk. The second line contains four integers x1, y1, x2 and y2 (0 ≀ x1 ≀ x2 ≀ 100 000), (0 ≀ y1 ≀ y2 ≀ 100 000) β€” the coordinates of the opposite corners of the mousetrap. The next n lines contain the information about mice. The i-th of these lines contains four integers rix, riy, vix and viy, (0 ≀ rix, riy ≀ 100 000, - 100 000 ≀ vix, viy ≀ 100 000), where (rix, riy) is the initial position of the mouse, and (vix, viy) is its speed. Output In the only line print minimum possible non-negative number t such that if Igor closes the mousetrap at t seconds from the beginning, then all the mice are strictly inside the mousetrap. If there is no such t, print -1. Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 4 7 7 9 8 3 5 7 5 7 5 2 4 3 3 7 8 6 6 3 2 Output 0.57142857142857139685 Input 4 7 7 9 8 0 3 -5 4 5 0 5 4 9 9 -1 -6 10 5 -7 -10 Output -1 Note Here is a picture of the first sample Points A, B, C, D - start mice positions, segments are their paths. <image> Then, at first time when all mice will be in rectangle it will be looks like this: <image> Here is a picture of the second sample <image> Points A, D, B will never enter rectangle. Tags: geometry, implementation, math, sortings Correct Solution: ``` n=int(input()) x1,y1,x2,y2=[int(x) for x in input().split()] st=[0] et=[1e10] ok=1 if x1==x2 or y1==y2: ok=0 for i in range(n): a,b,u,w=[int(x) for x in input().split()] for x,v,s,e in ((a,u,x1,x2),(b,w,y1,y2)): if v==0: if not(s<x<e): ok=0 else: t1=(s-x)/v t2=(e-x)/v st+=[min(t1,t2)] et+=[max(t1,t2)] #print(st,et) if max(st)<min(et) and min(et)>0 and ok: print(max(max(st),0)) else: print(-1) ```
11,300
Provide tags and a correct Python 3 solution for this coding contest problem. Igor the analyst fell asleep on the work and had a strange dream. In the dream his desk was crowded with computer mice, so he bought a mousetrap to catch them. The desk can be considered as an infinite plane, then the mousetrap is a rectangle which sides are parallel to the axes, and which opposite sides are located in points (x1, y1) and (x2, y2). Igor wants to catch all mice. Igor has analysed their behavior and discovered that each mouse is moving along a straight line with constant speed, the speed of the i-th mouse is equal to (vix, viy), that means that the x coordinate of the mouse increases by vix units per second, while the y coordinates increases by viy units. The mousetrap is open initially so that the mice are able to move freely on the desk. Igor can close the mousetrap at any moment catching all the mice that are strictly inside the mousetrap. Igor works a lot, so he is busy in the dream as well, and he asks you to write a program that by given mousetrap's coordinates, the initial coordinates of the mice and their speeds determines the earliest time moment in which he is able to catch all the mice. Please note that Igor can close the mousetrap only once. Input The first line contains single integer n (1 ≀ n ≀ 100 000) β€” the number of computer mice on the desk. The second line contains four integers x1, y1, x2 and y2 (0 ≀ x1 ≀ x2 ≀ 100 000), (0 ≀ y1 ≀ y2 ≀ 100 000) β€” the coordinates of the opposite corners of the mousetrap. The next n lines contain the information about mice. The i-th of these lines contains four integers rix, riy, vix and viy, (0 ≀ rix, riy ≀ 100 000, - 100 000 ≀ vix, viy ≀ 100 000), where (rix, riy) is the initial position of the mouse, and (vix, viy) is its speed. Output In the only line print minimum possible non-negative number t such that if Igor closes the mousetrap at t seconds from the beginning, then all the mice are strictly inside the mousetrap. If there is no such t, print -1. Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 4 7 7 9 8 3 5 7 5 7 5 2 4 3 3 7 8 6 6 3 2 Output 0.57142857142857139685 Input 4 7 7 9 8 0 3 -5 4 5 0 5 4 9 9 -1 -6 10 5 -7 -10 Output -1 Note Here is a picture of the first sample Points A, B, C, D - start mice positions, segments are their paths. <image> Then, at first time when all mice will be in rectangle it will be looks like this: <image> Here is a picture of the second sample <image> Points A, D, B will never enter rectangle. Tags: geometry, implementation, math, sortings Correct Solution: ``` import math n = int(input()) x1, y1, x2, y2 = map(int, input().split()) t1 = 0 t2 = math.inf yes = True for i in range(n): x, y, vx, vy = map(int, input().split()) if vx == 0: if x <= x1 or x >= x2: yes = False break else: tt1 = (x1-x)/vx tt2 = (x2-x)/vx tt1, tt2 = min(tt1, tt2), max(tt1, tt2) t1 = max(t1, tt1) t2 = min(t2, tt2) if vy == 0: if y <= y1 or y >= y2: yes = False break else: tt1 = (y1-y)/vy tt2 = (y2-y)/vy tt1, tt2 = min(tt1, tt2), max(tt1, tt2) t1 = max(t1, tt1) t2 = min(t2, tt2) if yes and t1 < t2: print(t1) else: print(-1) ```
11,301
Provide tags and a correct Python 3 solution for this coding contest problem. Igor the analyst fell asleep on the work and had a strange dream. In the dream his desk was crowded with computer mice, so he bought a mousetrap to catch them. The desk can be considered as an infinite plane, then the mousetrap is a rectangle which sides are parallel to the axes, and which opposite sides are located in points (x1, y1) and (x2, y2). Igor wants to catch all mice. Igor has analysed their behavior and discovered that each mouse is moving along a straight line with constant speed, the speed of the i-th mouse is equal to (vix, viy), that means that the x coordinate of the mouse increases by vix units per second, while the y coordinates increases by viy units. The mousetrap is open initially so that the mice are able to move freely on the desk. Igor can close the mousetrap at any moment catching all the mice that are strictly inside the mousetrap. Igor works a lot, so he is busy in the dream as well, and he asks you to write a program that by given mousetrap's coordinates, the initial coordinates of the mice and their speeds determines the earliest time moment in which he is able to catch all the mice. Please note that Igor can close the mousetrap only once. Input The first line contains single integer n (1 ≀ n ≀ 100 000) β€” the number of computer mice on the desk. The second line contains four integers x1, y1, x2 and y2 (0 ≀ x1 ≀ x2 ≀ 100 000), (0 ≀ y1 ≀ y2 ≀ 100 000) β€” the coordinates of the opposite corners of the mousetrap. The next n lines contain the information about mice. The i-th of these lines contains four integers rix, riy, vix and viy, (0 ≀ rix, riy ≀ 100 000, - 100 000 ≀ vix, viy ≀ 100 000), where (rix, riy) is the initial position of the mouse, and (vix, viy) is its speed. Output In the only line print minimum possible non-negative number t such that if Igor closes the mousetrap at t seconds from the beginning, then all the mice are strictly inside the mousetrap. If there is no such t, print -1. Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 4 7 7 9 8 3 5 7 5 7 5 2 4 3 3 7 8 6 6 3 2 Output 0.57142857142857139685 Input 4 7 7 9 8 0 3 -5 4 5 0 5 4 9 9 -1 -6 10 5 -7 -10 Output -1 Note Here is a picture of the first sample Points A, B, C, D - start mice positions, segments are their paths. <image> Then, at first time when all mice will be in rectangle it will be looks like this: <image> Here is a picture of the second sample <image> Points A, D, B will never enter rectangle. Tags: geometry, implementation, math, sortings Correct Solution: ``` # In the name of Allah def main() : n = int(input()) x1, y1, x2, y2 = map(int, input().split()) st = [0] ed = [1e11] if x1 == x2 or y1 == y2 : print(-1) exit() for i in range(n) : a, b, c, d = map(int, input().split()) for x, v, s, e in ((a, c, x1, x2), (b, d, y1, y2)) : if v == 0 : if not(s < x < e) : print(-1) exit() else : t1 = (s - x) / v; t2 = (e - x) / v; st += [min(t1, t2)] ed += [max(t1, t2)] if max(st) < min(ed) and min(ed) > 0 : print(max(max(st), 0)) else : print(-1) return 0 main() ```
11,302
Provide tags and a correct Python 3 solution for this coding contest problem. Igor the analyst fell asleep on the work and had a strange dream. In the dream his desk was crowded with computer mice, so he bought a mousetrap to catch them. The desk can be considered as an infinite plane, then the mousetrap is a rectangle which sides are parallel to the axes, and which opposite sides are located in points (x1, y1) and (x2, y2). Igor wants to catch all mice. Igor has analysed their behavior and discovered that each mouse is moving along a straight line with constant speed, the speed of the i-th mouse is equal to (vix, viy), that means that the x coordinate of the mouse increases by vix units per second, while the y coordinates increases by viy units. The mousetrap is open initially so that the mice are able to move freely on the desk. Igor can close the mousetrap at any moment catching all the mice that are strictly inside the mousetrap. Igor works a lot, so he is busy in the dream as well, and he asks you to write a program that by given mousetrap's coordinates, the initial coordinates of the mice and their speeds determines the earliest time moment in which he is able to catch all the mice. Please note that Igor can close the mousetrap only once. Input The first line contains single integer n (1 ≀ n ≀ 100 000) β€” the number of computer mice on the desk. The second line contains four integers x1, y1, x2 and y2 (0 ≀ x1 ≀ x2 ≀ 100 000), (0 ≀ y1 ≀ y2 ≀ 100 000) β€” the coordinates of the opposite corners of the mousetrap. The next n lines contain the information about mice. The i-th of these lines contains four integers rix, riy, vix and viy, (0 ≀ rix, riy ≀ 100 000, - 100 000 ≀ vix, viy ≀ 100 000), where (rix, riy) is the initial position of the mouse, and (vix, viy) is its speed. Output In the only line print minimum possible non-negative number t such that if Igor closes the mousetrap at t seconds from the beginning, then all the mice are strictly inside the mousetrap. If there is no such t, print -1. Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 4 7 7 9 8 3 5 7 5 7 5 2 4 3 3 7 8 6 6 3 2 Output 0.57142857142857139685 Input 4 7 7 9 8 0 3 -5 4 5 0 5 4 9 9 -1 -6 10 5 -7 -10 Output -1 Note Here is a picture of the first sample Points A, B, C, D - start mice positions, segments are their paths. <image> Then, at first time when all mice will be in rectangle it will be looks like this: <image> Here is a picture of the second sample <image> Points A, D, B will never enter rectangle. Tags: geometry, implementation, math, sortings Correct Solution: ``` N = int( input() ) x1, y1, x2, y2 = map( int, input().split() ) maxl, minr = 0.0, 1e30 for i in range( N ): rx, ry, vx, vy = map( int, input().split() ) c = [ 0.0 for i in range( 4 ) ] # b, t, l, r if vx == 0: if not ( x1 < rx and rx < x2 ): exit( print( -1 ) ) else: c[ 2 ] = 0.0 c[ 3 ] = 0.0 else: c[ 2 ] = ( x1 - rx ) / vx c[ 3 ] = ( x2 - rx ) / vx if vy == 0: if not ( y1 < ry and ry < y2 ): exit( print( -1 ) ) else: c[ 0 ] = 0.0 c[ 1 ] = 0.0 else: c[ 0 ] = ( y1 - ry ) / vy c[ 1 ] = ( y2 - ry ) / vy for j in range( 2 ): xx = rx + c[ j ] * vx if not ( x1 <= xx and xx <= x2 ): c[ j ] = -1.0 for j in range( 2, 4, 1 ): yy = ry + c[ j ] * vy if not ( y1 <= yy and yy <= y2 ): c[ j ] = -1.0 ll, rr = 1e30, 0.0 for j in range( 4 ): if c[ j ] < 0.0: continue ll = min( ll, c[ j ] ) rr = max( rr, c[ j ] ) if x1 < rx and rx < x2 and y1 < ry and ry < y2: if vx == 0 and vy == 0: continue # mugen minr = min( minr, rr ) continue if ll == 1e30 or ll == rr: exit( print( -1 ) ) maxl = max( maxl, ll ) minr = min( minr, rr ) if minr <= maxl: print( -1 ) else: print( "%.8f" % maxl ) ```
11,303
Provide tags and a correct Python 3 solution for this coding contest problem. Igor the analyst fell asleep on the work and had a strange dream. In the dream his desk was crowded with computer mice, so he bought a mousetrap to catch them. The desk can be considered as an infinite plane, then the mousetrap is a rectangle which sides are parallel to the axes, and which opposite sides are located in points (x1, y1) and (x2, y2). Igor wants to catch all mice. Igor has analysed their behavior and discovered that each mouse is moving along a straight line with constant speed, the speed of the i-th mouse is equal to (vix, viy), that means that the x coordinate of the mouse increases by vix units per second, while the y coordinates increases by viy units. The mousetrap is open initially so that the mice are able to move freely on the desk. Igor can close the mousetrap at any moment catching all the mice that are strictly inside the mousetrap. Igor works a lot, so he is busy in the dream as well, and he asks you to write a program that by given mousetrap's coordinates, the initial coordinates of the mice and their speeds determines the earliest time moment in which he is able to catch all the mice. Please note that Igor can close the mousetrap only once. Input The first line contains single integer n (1 ≀ n ≀ 100 000) β€” the number of computer mice on the desk. The second line contains four integers x1, y1, x2 and y2 (0 ≀ x1 ≀ x2 ≀ 100 000), (0 ≀ y1 ≀ y2 ≀ 100 000) β€” the coordinates of the opposite corners of the mousetrap. The next n lines contain the information about mice. The i-th of these lines contains four integers rix, riy, vix and viy, (0 ≀ rix, riy ≀ 100 000, - 100 000 ≀ vix, viy ≀ 100 000), where (rix, riy) is the initial position of the mouse, and (vix, viy) is its speed. Output In the only line print minimum possible non-negative number t such that if Igor closes the mousetrap at t seconds from the beginning, then all the mice are strictly inside the mousetrap. If there is no such t, print -1. Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 4 7 7 9 8 3 5 7 5 7 5 2 4 3 3 7 8 6 6 3 2 Output 0.57142857142857139685 Input 4 7 7 9 8 0 3 -5 4 5 0 5 4 9 9 -1 -6 10 5 -7 -10 Output -1 Note Here is a picture of the first sample Points A, B, C, D - start mice positions, segments are their paths. <image> Then, at first time when all mice will be in rectangle it will be looks like this: <image> Here is a picture of the second sample <image> Points A, D, B will never enter rectangle. Tags: geometry, implementation, math, sortings Correct Solution: ``` import sys lines = sys.stdin.read().split('\n')[1:][:-1] line_1 = lines.pop(0) x_1, y_1, x_2, y_2 = map(int, line_1.split()) def terminate_with_fail(): print('-1', end='') sys.exit() def move(x, y, dx, dy, t): return (x + t * dx, y + t * dy) def enter_line(k, dk, k_1, k_2): if k_1 < k < k_2: return 0 elif dk == 0: terminate_with_fail() move_time = min((k_1 - k) / dk, (k_2 - k) / dk) if move_time < 0 or k_1 == k_2: terminate_with_fail() return move_time def exit_line(k, dk, k_1, k_2): if dk == 0: return float('inf') else: return max((k_1 - k) / dk, (k_2 - k) / dk) earliest = 0 latest = float('inf') for line in lines: x, y, dx, dy = map(int, line.split()) move_time_x = enter_line(x, dx, x_1, x_2) (x, y) = move(x, y, dx, dy, move_time_x) move_time_y = enter_line(y, dy, y_1, y_2) (x, y) = move(x, y, dx, dy, move_time_y) start_time = move_time_x + move_time_y move_time_x_end = exit_line(x, dx, x_1, x_2) move_time_y_end = exit_line(y, dy, y_1, y_2) end_time = start_time + min(move_time_x_end, move_time_y_end) earliest = max(earliest, start_time) latest = min(latest, end_time) if earliest >= latest: terminate_with_fail() print(str(earliest), end='') ```
11,304
Provide tags and a correct Python 3 solution for this coding contest problem. Igor the analyst fell asleep on the work and had a strange dream. In the dream his desk was crowded with computer mice, so he bought a mousetrap to catch them. The desk can be considered as an infinite plane, then the mousetrap is a rectangle which sides are parallel to the axes, and which opposite sides are located in points (x1, y1) and (x2, y2). Igor wants to catch all mice. Igor has analysed their behavior and discovered that each mouse is moving along a straight line with constant speed, the speed of the i-th mouse is equal to (vix, viy), that means that the x coordinate of the mouse increases by vix units per second, while the y coordinates increases by viy units. The mousetrap is open initially so that the mice are able to move freely on the desk. Igor can close the mousetrap at any moment catching all the mice that are strictly inside the mousetrap. Igor works a lot, so he is busy in the dream as well, and he asks you to write a program that by given mousetrap's coordinates, the initial coordinates of the mice and their speeds determines the earliest time moment in which he is able to catch all the mice. Please note that Igor can close the mousetrap only once. Input The first line contains single integer n (1 ≀ n ≀ 100 000) β€” the number of computer mice on the desk. The second line contains four integers x1, y1, x2 and y2 (0 ≀ x1 ≀ x2 ≀ 100 000), (0 ≀ y1 ≀ y2 ≀ 100 000) β€” the coordinates of the opposite corners of the mousetrap. The next n lines contain the information about mice. The i-th of these lines contains four integers rix, riy, vix and viy, (0 ≀ rix, riy ≀ 100 000, - 100 000 ≀ vix, viy ≀ 100 000), where (rix, riy) is the initial position of the mouse, and (vix, viy) is its speed. Output In the only line print minimum possible non-negative number t such that if Igor closes the mousetrap at t seconds from the beginning, then all the mice are strictly inside the mousetrap. If there is no such t, print -1. Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 4 7 7 9 8 3 5 7 5 7 5 2 4 3 3 7 8 6 6 3 2 Output 0.57142857142857139685 Input 4 7 7 9 8 0 3 -5 4 5 0 5 4 9 9 -1 -6 10 5 -7 -10 Output -1 Note Here is a picture of the first sample Points A, B, C, D - start mice positions, segments are their paths. <image> Then, at first time when all mice will be in rectangle it will be looks like this: <image> Here is a picture of the second sample <image> Points A, D, B will never enter rectangle. Tags: geometry, implementation, math, sortings Correct Solution: ``` #!/usr/bin/env python3 from sys import stdin,stdout from decimal import * def ri(): return map(int, stdin.readline().split()) #lines = stdin.readlines() def findt(rx,ry,vx,vy): if vx == 0: if rx > x1 and rx < x2: t1x = Decimal(0) t2x = Decimal(10**6) else: return 2, 1 else: t1x = Decimal(x1-rx)/Decimal(vx) t2x = Decimal(x2-rx)/Decimal(vx) if vy == 0: if ry > y1 and ry < y2: t1y = Decimal(0) t2y = Decimal(10**6) else: return 2, 1 else: t1y = Decimal(y1-ry)/Decimal(vy) t2y = Decimal(y2-ry)/Decimal(vy) if t1x > t2x: t1x, t2x = t2x, t1x if t1y > t2y: t1y, t2y = t2y, t1y return max(t1x, t1y), min(t2x, t2y) n = int(input()) x1, y1, x2, y2 = ri() if x1 > x2: x1, x2 = x2, x1 if y1 > y2: y1, y2 = y2, y1 mintt = 0 maxtt = 10**20 for i in range(n): rx, ry, vx, vy = ri() mint, maxt = findt(rx, ry, vx, vy) if mint >= maxt: print(-1) exit() if maxt <= 0: print(-1) exit() mintt = max(mint, mintt) maxtt = min(maxt, maxtt) if mintt >= maxtt: print(-1) exit() print(mintt) ```
11,305
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Igor the analyst fell asleep on the work and had a strange dream. In the dream his desk was crowded with computer mice, so he bought a mousetrap to catch them. The desk can be considered as an infinite plane, then the mousetrap is a rectangle which sides are parallel to the axes, and which opposite sides are located in points (x1, y1) and (x2, y2). Igor wants to catch all mice. Igor has analysed their behavior and discovered that each mouse is moving along a straight line with constant speed, the speed of the i-th mouse is equal to (vix, viy), that means that the x coordinate of the mouse increases by vix units per second, while the y coordinates increases by viy units. The mousetrap is open initially so that the mice are able to move freely on the desk. Igor can close the mousetrap at any moment catching all the mice that are strictly inside the mousetrap. Igor works a lot, so he is busy in the dream as well, and he asks you to write a program that by given mousetrap's coordinates, the initial coordinates of the mice and their speeds determines the earliest time moment in which he is able to catch all the mice. Please note that Igor can close the mousetrap only once. Input The first line contains single integer n (1 ≀ n ≀ 100 000) β€” the number of computer mice on the desk. The second line contains four integers x1, y1, x2 and y2 (0 ≀ x1 ≀ x2 ≀ 100 000), (0 ≀ y1 ≀ y2 ≀ 100 000) β€” the coordinates of the opposite corners of the mousetrap. The next n lines contain the information about mice. The i-th of these lines contains four integers rix, riy, vix and viy, (0 ≀ rix, riy ≀ 100 000, - 100 000 ≀ vix, viy ≀ 100 000), where (rix, riy) is the initial position of the mouse, and (vix, viy) is its speed. Output In the only line print minimum possible non-negative number t such that if Igor closes the mousetrap at t seconds from the beginning, then all the mice are strictly inside the mousetrap. If there is no such t, print -1. Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 4 7 7 9 8 3 5 7 5 7 5 2 4 3 3 7 8 6 6 3 2 Output 0.57142857142857139685 Input 4 7 7 9 8 0 3 -5 4 5 0 5 4 9 9 -1 -6 10 5 -7 -10 Output -1 Note Here is a picture of the first sample Points A, B, C, D - start mice positions, segments are their paths. <image> Then, at first time when all mice will be in rectangle it will be looks like this: <image> Here is a picture of the second sample <image> Points A, D, B will never enter rectangle. Submitted Solution: ``` n = int(input()) x1, y1, x2, y2 = map(int, input().split()) lx, rx, ly, ry = [], [], [], [] pos = True for i in range(n): x, y, vx, vy = map(int, input().split()) if x1 < x < x2: lx.append(0) if vx == 0: rx.append(float('inf')) else: gl, gr = 0, 10 ** 5 + 1 while gr - gl > 10 ** -6: m = (gl + gr) / 2 if x1 < x + m * vx < x2: gl = m else: gr = m rx.append(gr) elif x >= x2: if vx >= 0: pos = False break else: lx.append((x2 - x - 10 ** -6) / vx) rx.append((x1 - x + 10 ** -6) / vx) else: if vx <= 0: pos = False break else: lx.append((x1 - x + 10 ** -6) / vx) rx.append((x2 - x - 10 ** - 6) / vx) if y1 < y < y2: ly.append(0) if vy == 0: ry.append(float('inf')) else: gl, gr = 0, 10 ** 5 + 1 while gr - gl > 10 ** -6: m = (gl + gr) / 2 if y1 < y + m * vy < y2: gl = m else: gr = m ry.append(gr) elif y >= y2: if vy >= 0: pos = False break else: ly.append((y2 - y - 10 ** -6) / vy) ry.append((y1 - y + 10 ** -6) / vy) else: if vy <= 0: pos = False break else: ly.append((y1 - y + 10 ** -6) / vy) ry.append((y2 - y - 10 ** - 6) / vy) if not pos: print(-1) else: l = max(max(ly), max(lx)) r = min(min(ry), min(rx)) if r <= l: print(-1) else: print(l) ``` Yes
11,306
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Igor the analyst fell asleep on the work and had a strange dream. In the dream his desk was crowded with computer mice, so he bought a mousetrap to catch them. The desk can be considered as an infinite plane, then the mousetrap is a rectangle which sides are parallel to the axes, and which opposite sides are located in points (x1, y1) and (x2, y2). Igor wants to catch all mice. Igor has analysed their behavior and discovered that each mouse is moving along a straight line with constant speed, the speed of the i-th mouse is equal to (vix, viy), that means that the x coordinate of the mouse increases by vix units per second, while the y coordinates increases by viy units. The mousetrap is open initially so that the mice are able to move freely on the desk. Igor can close the mousetrap at any moment catching all the mice that are strictly inside the mousetrap. Igor works a lot, so he is busy in the dream as well, and he asks you to write a program that by given mousetrap's coordinates, the initial coordinates of the mice and their speeds determines the earliest time moment in which he is able to catch all the mice. Please note that Igor can close the mousetrap only once. Input The first line contains single integer n (1 ≀ n ≀ 100 000) β€” the number of computer mice on the desk. The second line contains four integers x1, y1, x2 and y2 (0 ≀ x1 ≀ x2 ≀ 100 000), (0 ≀ y1 ≀ y2 ≀ 100 000) β€” the coordinates of the opposite corners of the mousetrap. The next n lines contain the information about mice. The i-th of these lines contains four integers rix, riy, vix and viy, (0 ≀ rix, riy ≀ 100 000, - 100 000 ≀ vix, viy ≀ 100 000), where (rix, riy) is the initial position of the mouse, and (vix, viy) is its speed. Output In the only line print minimum possible non-negative number t such that if Igor closes the mousetrap at t seconds from the beginning, then all the mice are strictly inside the mousetrap. If there is no such t, print -1. Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 4 7 7 9 8 3 5 7 5 7 5 2 4 3 3 7 8 6 6 3 2 Output 0.57142857142857139685 Input 4 7 7 9 8 0 3 -5 4 5 0 5 4 9 9 -1 -6 10 5 -7 -10 Output -1 Note Here is a picture of the first sample Points A, B, C, D - start mice positions, segments are their paths. <image> Then, at first time when all mice will be in rectangle it will be looks like this: <image> Here is a picture of the second sample <image> Points A, D, B will never enter rectangle. Submitted Solution: ``` n = int(input()) x1, y1, x2, y2 = list(map(int, input().split())) span = [0, 10000000] for _ in range(n): m = list(map(int, input().split())) if m[2] == 0: if m[0] <= min(x1, x2) or m[0] >= max(x1, x2): span = [] break else: x_range = [-100000000, 100000000] else: x_range = sorted([(x1-m[0])/m[2], (x2-m[0])/m[2]]) if m[3] == 0: if m[1] <= min(y1, y2) or m[1] >= max(y1, y2): span = [] break else: y_range = [-100000000, 100000000] else: y_range = sorted([(y1-m[1])/m[3], (y2-m[1])/m[3]]) if x_range[1] < 0 or y_range[1] < 0: span = [] break r = [max(x_range[0], y_range[0]), min(x_range[1], y_range[1])] span = [max(r[0], span[0]), min(r[1], span[1])] #print(span) if len(span) == 0 or span[1] <= span[0]: print('-1') else: print('%.8f' % (span[0]+0.00000001)) ``` Yes
11,307
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Igor the analyst fell asleep on the work and had a strange dream. In the dream his desk was crowded with computer mice, so he bought a mousetrap to catch them. The desk can be considered as an infinite plane, then the mousetrap is a rectangle which sides are parallel to the axes, and which opposite sides are located in points (x1, y1) and (x2, y2). Igor wants to catch all mice. Igor has analysed their behavior and discovered that each mouse is moving along a straight line with constant speed, the speed of the i-th mouse is equal to (vix, viy), that means that the x coordinate of the mouse increases by vix units per second, while the y coordinates increases by viy units. The mousetrap is open initially so that the mice are able to move freely on the desk. Igor can close the mousetrap at any moment catching all the mice that are strictly inside the mousetrap. Igor works a lot, so he is busy in the dream as well, and he asks you to write a program that by given mousetrap's coordinates, the initial coordinates of the mice and their speeds determines the earliest time moment in which he is able to catch all the mice. Please note that Igor can close the mousetrap only once. Input The first line contains single integer n (1 ≀ n ≀ 100 000) β€” the number of computer mice on the desk. The second line contains four integers x1, y1, x2 and y2 (0 ≀ x1 ≀ x2 ≀ 100 000), (0 ≀ y1 ≀ y2 ≀ 100 000) β€” the coordinates of the opposite corners of the mousetrap. The next n lines contain the information about mice. The i-th of these lines contains four integers rix, riy, vix and viy, (0 ≀ rix, riy ≀ 100 000, - 100 000 ≀ vix, viy ≀ 100 000), where (rix, riy) is the initial position of the mouse, and (vix, viy) is its speed. Output In the only line print minimum possible non-negative number t such that if Igor closes the mousetrap at t seconds from the beginning, then all the mice are strictly inside the mousetrap. If there is no such t, print -1. Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 4 7 7 9 8 3 5 7 5 7 5 2 4 3 3 7 8 6 6 3 2 Output 0.57142857142857139685 Input 4 7 7 9 8 0 3 -5 4 5 0 5 4 9 9 -1 -6 10 5 -7 -10 Output -1 Note Here is a picture of the first sample Points A, B, C, D - start mice positions, segments are their paths. <image> Then, at first time when all mice will be in rectangle it will be looks like this: <image> Here is a picture of the second sample <image> Points A, D, B will never enter rectangle. Submitted Solution: ``` # t*v+a = b # t=(b-a)/v import sys #sys.stdin=open("data.txt") input=sys.stdin.readline mintime=(0,1) maxtime=(10**9,1) useless=0 n=int(input()) #include <math.h> # int 'y1' redeclared as different kind of symbol x1,y1,x2,y2=map(int,input().split()) for _ in range(n): rx,ry,vx,vy=map(int,input().split()) # x time if vx==0: if not x1<rx<x2: useless=1 break else: t1=(x1-rx,vx) t2=(x2-rx,vx) if vx<0: t1=(-t1[0],-t1[1]) t2=(-t2[0],-t2[1]) # t11/t12 > t21/t22 if t1[0]*t2[1]>t1[1]*t2[0]: t1,t2=t2,t1 if mintime[0]*t1[1]<mintime[1]*t1[0]: mintime=t1 if maxtime[0]*t2[1]>maxtime[1]*t2[0]: maxtime=t2 # y time if vy==0: if not y1<ry<y2: useless=1 break else: t1=(y1-ry,vy) t2=(y2-ry,vy) if vy<0: t1=(-t1[0],-t1[1]) t2=(-t2[0],-t2[1]) # t11/t12 > t21/t22 if t1[0]*t2[1]>t1[1]*t2[0]: t1,t2=t2,t1 if mintime[0]*t1[1]<mintime[1]*t1[0]: mintime=t1 if maxtime[0]*t2[1]>maxtime[1]*t2[0]: maxtime=t2 if useless or mintime[0]*maxtime[1]>=maxtime[0]*mintime[1]: print(-1) else: print(mintime[0]/float(mintime[1])) ``` Yes
11,308
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Igor the analyst fell asleep on the work and had a strange dream. In the dream his desk was crowded with computer mice, so he bought a mousetrap to catch them. The desk can be considered as an infinite plane, then the mousetrap is a rectangle which sides are parallel to the axes, and which opposite sides are located in points (x1, y1) and (x2, y2). Igor wants to catch all mice. Igor has analysed their behavior and discovered that each mouse is moving along a straight line with constant speed, the speed of the i-th mouse is equal to (vix, viy), that means that the x coordinate of the mouse increases by vix units per second, while the y coordinates increases by viy units. The mousetrap is open initially so that the mice are able to move freely on the desk. Igor can close the mousetrap at any moment catching all the mice that are strictly inside the mousetrap. Igor works a lot, so he is busy in the dream as well, and he asks you to write a program that by given mousetrap's coordinates, the initial coordinates of the mice and their speeds determines the earliest time moment in which he is able to catch all the mice. Please note that Igor can close the mousetrap only once. Input The first line contains single integer n (1 ≀ n ≀ 100 000) β€” the number of computer mice on the desk. The second line contains four integers x1, y1, x2 and y2 (0 ≀ x1 ≀ x2 ≀ 100 000), (0 ≀ y1 ≀ y2 ≀ 100 000) β€” the coordinates of the opposite corners of the mousetrap. The next n lines contain the information about mice. The i-th of these lines contains four integers rix, riy, vix and viy, (0 ≀ rix, riy ≀ 100 000, - 100 000 ≀ vix, viy ≀ 100 000), where (rix, riy) is the initial position of the mouse, and (vix, viy) is its speed. Output In the only line print minimum possible non-negative number t such that if Igor closes the mousetrap at t seconds from the beginning, then all the mice are strictly inside the mousetrap. If there is no such t, print -1. Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 4 7 7 9 8 3 5 7 5 7 5 2 4 3 3 7 8 6 6 3 2 Output 0.57142857142857139685 Input 4 7 7 9 8 0 3 -5 4 5 0 5 4 9 9 -1 -6 10 5 -7 -10 Output -1 Note Here is a picture of the first sample Points A, B, C, D - start mice positions, segments are their paths. <image> Then, at first time when all mice will be in rectangle it will be looks like this: <image> Here is a picture of the second sample <image> Points A, D, B will never enter rectangle. Submitted Solution: ``` import math n = int(input()) x1, y1, x2, y2 = map(int, input().split()) t1 = 0 t2 = math.inf yes = True for i in range(n): x, y, vx, vy = map(int, input().split()) if vx == 0: if x <= x1 or x >= x2: yes = False break else: tt1 = (x1-x)/vx tt2 = (x2-x)/vx tt1, tt2 = min(tt1, tt2), max(tt1, tt2) t1 = max(t1, tt1) t2 = min(t2, tt2) if vy == 0: if y <= y1 or y >= y2: yes = False break else: tt1 = (y1-y)/vy tt2 = (y2-y)/vy tt1, tt2 = min(tt1, tt2), max(tt1, tt2) t1 = max(t1, tt1) t2 = min(t2, tt2) if yes and t1 < t2: print(t1) else: print(-1) # Made By Mostafa_Khaled ``` Yes
11,309
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Igor the analyst fell asleep on the work and had a strange dream. In the dream his desk was crowded with computer mice, so he bought a mousetrap to catch them. The desk can be considered as an infinite plane, then the mousetrap is a rectangle which sides are parallel to the axes, and which opposite sides are located in points (x1, y1) and (x2, y2). Igor wants to catch all mice. Igor has analysed their behavior and discovered that each mouse is moving along a straight line with constant speed, the speed of the i-th mouse is equal to (vix, viy), that means that the x coordinate of the mouse increases by vix units per second, while the y coordinates increases by viy units. The mousetrap is open initially so that the mice are able to move freely on the desk. Igor can close the mousetrap at any moment catching all the mice that are strictly inside the mousetrap. Igor works a lot, so he is busy in the dream as well, and he asks you to write a program that by given mousetrap's coordinates, the initial coordinates of the mice and their speeds determines the earliest time moment in which he is able to catch all the mice. Please note that Igor can close the mousetrap only once. Input The first line contains single integer n (1 ≀ n ≀ 100 000) β€” the number of computer mice on the desk. The second line contains four integers x1, y1, x2 and y2 (0 ≀ x1 ≀ x2 ≀ 100 000), (0 ≀ y1 ≀ y2 ≀ 100 000) β€” the coordinates of the opposite corners of the mousetrap. The next n lines contain the information about mice. The i-th of these lines contains four integers rix, riy, vix and viy, (0 ≀ rix, riy ≀ 100 000, - 100 000 ≀ vix, viy ≀ 100 000), where (rix, riy) is the initial position of the mouse, and (vix, viy) is its speed. Output In the only line print minimum possible non-negative number t such that if Igor closes the mousetrap at t seconds from the beginning, then all the mice are strictly inside the mousetrap. If there is no such t, print -1. Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 4 7 7 9 8 3 5 7 5 7 5 2 4 3 3 7 8 6 6 3 2 Output 0.57142857142857139685 Input 4 7 7 9 8 0 3 -5 4 5 0 5 4 9 9 -1 -6 10 5 -7 -10 Output -1 Note Here is a picture of the first sample Points A, B, C, D - start mice positions, segments are their paths. <image> Then, at first time when all mice will be in rectangle it will be looks like this: <image> Here is a picture of the second sample <image> Points A, D, B will never enter rectangle. Submitted Solution: ``` import sys n = int(input()) x1, y1, x2, y2 = tuple(map(int, input().split())) mouse = [] for i in range(n): mouse.append(list(map(int, input().split()))) def inside(a): frames = [] if a[2] != 0: g1 = (x1 - a[0])/a[2] ay1 = a[3]*g1 + a[1] if g1 >= 0 and y1 <= ay1 <= y2: frames.append(g1) g2 = (x2 - a[0])/a[2] ay2 = a[3]*g2 + a[1] if g2 >= 0 and y1 <= ay2 <= y2: frames.append(g2) if a[3] != 0: g1 = (y1 - a[1])/a[3] ax1 = a[2]*g1 + a[0] if g1 >= 0 and x1 <= ax1 <= x2: frames.append(g1) g2 = (y2 - a[1])/a[3] ax2 = a[2]*g2 + a[0] if g2 >= 0 and x1 <= ax2 <= x2: frames.append(g2) if len(frames) == 0: print(-1); exit() return sorted(frames) min_out = sys.maxsize max_in = 0 for i in range(n): f = inside(mouse[i]) if f[0] > max_in: max_in = f[0] if len(f) > 1 and f[1] < min_out: min_out = f[1] if (max_in > min_out): print(-1) else: print(max_in) ``` No
11,310
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Igor the analyst fell asleep on the work and had a strange dream. In the dream his desk was crowded with computer mice, so he bought a mousetrap to catch them. The desk can be considered as an infinite plane, then the mousetrap is a rectangle which sides are parallel to the axes, and which opposite sides are located in points (x1, y1) and (x2, y2). Igor wants to catch all mice. Igor has analysed their behavior and discovered that each mouse is moving along a straight line with constant speed, the speed of the i-th mouse is equal to (vix, viy), that means that the x coordinate of the mouse increases by vix units per second, while the y coordinates increases by viy units. The mousetrap is open initially so that the mice are able to move freely on the desk. Igor can close the mousetrap at any moment catching all the mice that are strictly inside the mousetrap. Igor works a lot, so he is busy in the dream as well, and he asks you to write a program that by given mousetrap's coordinates, the initial coordinates of the mice and their speeds determines the earliest time moment in which he is able to catch all the mice. Please note that Igor can close the mousetrap only once. Input The first line contains single integer n (1 ≀ n ≀ 100 000) β€” the number of computer mice on the desk. The second line contains four integers x1, y1, x2 and y2 (0 ≀ x1 ≀ x2 ≀ 100 000), (0 ≀ y1 ≀ y2 ≀ 100 000) β€” the coordinates of the opposite corners of the mousetrap. The next n lines contain the information about mice. The i-th of these lines contains four integers rix, riy, vix and viy, (0 ≀ rix, riy ≀ 100 000, - 100 000 ≀ vix, viy ≀ 100 000), where (rix, riy) is the initial position of the mouse, and (vix, viy) is its speed. Output In the only line print minimum possible non-negative number t such that if Igor closes the mousetrap at t seconds from the beginning, then all the mice are strictly inside the mousetrap. If there is no such t, print -1. Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 4 7 7 9 8 3 5 7 5 7 5 2 4 3 3 7 8 6 6 3 2 Output 0.57142857142857139685 Input 4 7 7 9 8 0 3 -5 4 5 0 5 4 9 9 -1 -6 10 5 -7 -10 Output -1 Note Here is a picture of the first sample Points A, B, C, D - start mice positions, segments are their paths. <image> Then, at first time when all mice will be in rectangle it will be looks like this: <image> Here is a picture of the second sample <image> Points A, D, B will never enter rectangle. Submitted Solution: ``` rd = lambda: map(int, input().split()) n = int(input()) x1, y1, x2, y2 = rd() l = [] r = [] for i in range(n): t = [] rx, ry, vx, vy = rd() if x1 <= rx <= x2 and y1 <= ry <= y2: t.append(0) if vx: t1 = (x1 - rx) / vx if t1 >= 0: if y1 <= ry + t1 * vy <= y2: t.append(t1) t1 = (x2 - rx) / vx if t1 >= 0: if y1 <= ry + t1 * vy <= y2: t.append(t1) if vy: t1 = (y1 - ry) / vy if t1 >= 0: if x1 <= rx + t1 * vx <= x2: t.append(t1) t1 = (y2 - ry) / vy if t1 >= 0: if x1 <= rx + t1 * vx <= x2: t.append(t1) if vx == 0 and vy == 0: t.append(0x3f3f3f3f3f3f3f3f) if len(t) < 1: print(-1) exit() t.sort() l.append(t[0]) r.append(t[-1]) l.sort() r.sort() if l[-1] > r[0]: print(-1) else: print(l[-1]) ``` No
11,311
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Igor the analyst fell asleep on the work and had a strange dream. In the dream his desk was crowded with computer mice, so he bought a mousetrap to catch them. The desk can be considered as an infinite plane, then the mousetrap is a rectangle which sides are parallel to the axes, and which opposite sides are located in points (x1, y1) and (x2, y2). Igor wants to catch all mice. Igor has analysed their behavior and discovered that each mouse is moving along a straight line with constant speed, the speed of the i-th mouse is equal to (vix, viy), that means that the x coordinate of the mouse increases by vix units per second, while the y coordinates increases by viy units. The mousetrap is open initially so that the mice are able to move freely on the desk. Igor can close the mousetrap at any moment catching all the mice that are strictly inside the mousetrap. Igor works a lot, so he is busy in the dream as well, and he asks you to write a program that by given mousetrap's coordinates, the initial coordinates of the mice and their speeds determines the earliest time moment in which he is able to catch all the mice. Please note that Igor can close the mousetrap only once. Input The first line contains single integer n (1 ≀ n ≀ 100 000) β€” the number of computer mice on the desk. The second line contains four integers x1, y1, x2 and y2 (0 ≀ x1 ≀ x2 ≀ 100 000), (0 ≀ y1 ≀ y2 ≀ 100 000) β€” the coordinates of the opposite corners of the mousetrap. The next n lines contain the information about mice. The i-th of these lines contains four integers rix, riy, vix and viy, (0 ≀ rix, riy ≀ 100 000, - 100 000 ≀ vix, viy ≀ 100 000), where (rix, riy) is the initial position of the mouse, and (vix, viy) is its speed. Output In the only line print minimum possible non-negative number t such that if Igor closes the mousetrap at t seconds from the beginning, then all the mice are strictly inside the mousetrap. If there is no such t, print -1. Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 4 7 7 9 8 3 5 7 5 7 5 2 4 3 3 7 8 6 6 3 2 Output 0.57142857142857139685 Input 4 7 7 9 8 0 3 -5 4 5 0 5 4 9 9 -1 -6 10 5 -7 -10 Output -1 Note Here is a picture of the first sample Points A, B, C, D - start mice positions, segments are their paths. <image> Then, at first time when all mice will be in rectangle it will be looks like this: <image> Here is a picture of the second sample <image> Points A, D, B will never enter rectangle. Submitted Solution: ``` import sys lines = sys.stdin.read().split('\n')[1:][:-1] line_1 = lines.pop(0) x_1, y_1, x_2, y_2 = map(int, line_1.split()) earliest = float('-inf') latest = float('inf') def move(x, y, dx, dy, t): return (x + t * dx, y + t * dy) for line in lines: x, y, dx, dy = map(int, line.split()) print((x, y, dx, dy)) start_time = 0 is_valid = True if x_1 > x: move_time = (x_1 - x) / dx start_time += move_time (x, y) = move(x, y, dx, dy, move_time) is_valid = is_valid and move_time >= 0 if y_1 > y: move_time = (y_1 - y) / dy start_time += move_time (x, y) = move(x, y, dx, dy, move_time) is_valid = is_valid and move_time >= 0 if x > x_2: move_time = (x_2 - x) / dx start_time += move_time (x, y) = move(x, y, dx, dy, move_time) is_valid = is_valid and move_time >= 0 if y > y_2: move_time = (y_2 - y) / dy start_time += move_time (x, y) = move(x, y, dx, dy, move_time) is_valid = is_valid and move_time >= 0 if not is_valid: print('-1', end='') sys.exit() move_time_x2 = (x_2 - x) / dx move_time_y2 = (y_2 - y) / dy end_time = start_time + max(move_time_x2, move_time_y2) earliest = max(earliest, start_time) latest = min(latest, end_time) if earliest > latest: print('-1', end='') else: print(str(earliest), end='') ``` No
11,312
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Igor the analyst fell asleep on the work and had a strange dream. In the dream his desk was crowded with computer mice, so he bought a mousetrap to catch them. The desk can be considered as an infinite plane, then the mousetrap is a rectangle which sides are parallel to the axes, and which opposite sides are located in points (x1, y1) and (x2, y2). Igor wants to catch all mice. Igor has analysed their behavior and discovered that each mouse is moving along a straight line with constant speed, the speed of the i-th mouse is equal to (vix, viy), that means that the x coordinate of the mouse increases by vix units per second, while the y coordinates increases by viy units. The mousetrap is open initially so that the mice are able to move freely on the desk. Igor can close the mousetrap at any moment catching all the mice that are strictly inside the mousetrap. Igor works a lot, so he is busy in the dream as well, and he asks you to write a program that by given mousetrap's coordinates, the initial coordinates of the mice and their speeds determines the earliest time moment in which he is able to catch all the mice. Please note that Igor can close the mousetrap only once. Input The first line contains single integer n (1 ≀ n ≀ 100 000) β€” the number of computer mice on the desk. The second line contains four integers x1, y1, x2 and y2 (0 ≀ x1 ≀ x2 ≀ 100 000), (0 ≀ y1 ≀ y2 ≀ 100 000) β€” the coordinates of the opposite corners of the mousetrap. The next n lines contain the information about mice. The i-th of these lines contains four integers rix, riy, vix and viy, (0 ≀ rix, riy ≀ 100 000, - 100 000 ≀ vix, viy ≀ 100 000), where (rix, riy) is the initial position of the mouse, and (vix, viy) is its speed. Output In the only line print minimum possible non-negative number t such that if Igor closes the mousetrap at t seconds from the beginning, then all the mice are strictly inside the mousetrap. If there is no such t, print -1. Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 4 7 7 9 8 3 5 7 5 7 5 2 4 3 3 7 8 6 6 3 2 Output 0.57142857142857139685 Input 4 7 7 9 8 0 3 -5 4 5 0 5 4 9 9 -1 -6 10 5 -7 -10 Output -1 Note Here is a picture of the first sample Points A, B, C, D - start mice positions, segments are their paths. <image> Then, at first time when all mice will be in rectangle it will be looks like this: <image> Here is a picture of the second sample <image> Points A, D, B will never enter rectangle. Submitted Solution: ``` def f(x, dx, s, t): if dx < 0: s, t = t, s if dx == 0: return (0, 2e9) if s < x and x < t else (2e9, 0) low = (s-x) / dx + 1e-9 up = (t-x) / dx - 1e-9 return (low, up) n = int(input()) x1, y1, x2, y2 = map(int, input().split()) l, r = 0.0, 1e9 for i in range(n): x, y, dx, dy = map(int, input().split()) t = f(x, dx, x1, x2) l = max(t[0], l) r = min(t[1], r) t = f(y, dy, y1, y2) l = max(t[0], l) r = min(t[1], r) print("%f" % l)#(-1 if l > r else l)) ``` No
11,313
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an undirected graph consisting of n vertices. Initially there are no edges in the graph. Also you are given q queries, each query either adds one undirected edge to the graph or removes it. After each query you have to check if the resulting graph is bipartite (that is, you can paint all vertices of the graph into two colors so that there is no edge connecting two vertices of the same color). Input The first line contains two integers n and q (2 ≀ n, q ≀ 100000). Then q lines follow. ith line contains two numbers xi and yi (1 ≀ xi < yi ≀ n). These numbers describe ith query: if there is an edge between vertices xi and yi, then remove it, otherwise add it. Output Print q lines. ith line must contain YES if the graph is bipartite after ith query, and NO otherwise. Example Input 3 5 2 3 1 3 1 2 1 2 1 2 Output YES YES NO YES NO Submitted Solution: ``` class DoubleGraf: def __init__(self, n): self.points = [set() for i in range(n)] self.n = n def add(self, a, b): self.points[a].add(b) self.points[b].add(a) def rem(self, a, b): self.points[a].discard(b) self.points[b].discard(a) def line(self, a, b): return a in self.points[b] def look(self): def rec(cur, point): for subpoint in point: if self.colors[subpoint] is None: self.colors[subpoint] = cur rec(not cur, self.points[subpoint]) elif self.colors[subpoint] != cur: return False cur = not cur return True self.colors = [None for i in range(self.n)] self.colors[0] = False cur = True return rec(cur, self.points[0]) def __repr__(self): return str(self.points) def __init__(a, b): if g.line(a, b): g.rem(a, b) else: g.add(a, b) return g.look() if __name__ == '__main__': __test__ = 0 if __test__: tests = [] for i in range(len(tests)): print(i + 1, end="\t") print(tests[i][0] == __init__(*tests[i][1]), end="\t") print(tests[i][0], "<<", __init__(*tests[i][1])) exit() n, q = map(int, input().split()) g = DoubleGraf(n) for i in range(q): print("YES" if __init__(*map(lambda x: int(x)-1, input().split())) else "NO") ``` No
11,314
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an undirected graph consisting of n vertices. Initially there are no edges in the graph. Also you are given q queries, each query either adds one undirected edge to the graph or removes it. After each query you have to check if the resulting graph is bipartite (that is, you can paint all vertices of the graph into two colors so that there is no edge connecting two vertices of the same color). Input The first line contains two integers n and q (2 ≀ n, q ≀ 100000). Then q lines follow. ith line contains two numbers xi and yi (1 ≀ xi < yi ≀ n). These numbers describe ith query: if there is an edge between vertices xi and yi, then remove it, otherwise add it. Output Print q lines. ith line must contain YES if the graph is bipartite after ith query, and NO otherwise. Example Input 3 5 2 3 1 3 1 2 1 2 1 2 Output YES YES NO YES NO Submitted Solution: ``` class DoubleGraf: def __init__(self, n): self.points = [set() for i in range(n)] self.n = n def add(self, a, b): self.points[a].add(b) self.points[b].add(a) def rem(self, a, b): self.points[a].discard(b) self.points[b].discard(a) def line(self, a, b): return a in self.points[b] def look(self): self.colors = [None for i in range(self.n)] for i in range(self.n): if self.colors[i] is None: self.colors[i] = True answ = self._look(i, True) if not answ: return False return True def _look(self, point, cur): for i in self.points[point]: if self.colors[i] is None: self.colors[i] = not cur answ = self._look(i, not cur) if answ is None: continue return False if self.colors[i] == cur: return False return None def __repr__(self): return str(self.points) def __init__(a, b): if g.line(a, b): g.rem(a, b) else: g.add(a, b) return g.look() if __name__ == '__main__': __test__ = 0 if __test__: tests = [] for i in range(len(tests)): print(i + 1, end="\t") print(tests[i][0] == __init__(*tests[i][1]), end="\t") print(tests[i][0], "<<", __init__(*tests[i][1])) exit() n, q = map(int, input().split()) g = DoubleGraf(n) for i in range(q): print("YES" if __init__(*map(lambda x: int(x) - 1, input().split())) else "NO") ``` No
11,315
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an undirected graph consisting of n vertices. Initially there are no edges in the graph. Also you are given q queries, each query either adds one undirected edge to the graph or removes it. After each query you have to check if the resulting graph is bipartite (that is, you can paint all vertices of the graph into two colors so that there is no edge connecting two vertices of the same color). Input The first line contains two integers n and q (2 ≀ n, q ≀ 100000). Then q lines follow. ith line contains two numbers xi and yi (1 ≀ xi < yi ≀ n). These numbers describe ith query: if there is an edge between vertices xi and yi, then remove it, otherwise add it. Output Print q lines. ith line must contain YES if the graph is bipartite after ith query, and NO otherwise. Example Input 3 5 2 3 1 3 1 2 1 2 1 2 Output YES YES NO YES NO Submitted Solution: ``` class DoubleGraf: def __init__(self, n): self.points = [set() for i in range(n)] self.n = n def add(self, a, b): self.points[a].add(b) self.points[b].add(a) def rem(self, a, b): self.points[a].discard(b) self.points[b].discard(a) def line(self, a, b): return a in self.points[b] def look(self): def rec(cur, point): for subpoint in point: if self.colors[subpoint] is None: self.colors[subpoint] = cur return rec(not cur, self.points[subpoint]) elif self.colors[subpoint] != cur: return False return True self.colors = [None for i in range(self.n)] self.colors[0] = False cur = True return rec(cur, self.points[0]) def __repr__(self): return str(self.points) def __init__(a, b): if g.line(a, b): g.rem(a, b) else: g.add(a, b) return g.look() if __name__ == '__main__': __test__ = 0 if __test__: tests = [] for i in range(len(tests)): print(i + 1, end="\t") print(tests[i][0] == __init__(*tests[i][1]), end="\t") print(tests[i][0], "<<", __init__(*tests[i][1])) exit() n, q = map(int, input().split()) g = DoubleGraf(n) for i in range(q): print("YES" if __init__(*map(lambda x: int(x)-1, input().split())) else "NO") ``` No
11,316
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n castles in the Lannister's Kingdom and some walls connect two castles, no two castles are connected by more than one wall, no wall connects a castle to itself. Sir Jaime Lannister has discovered that Daenerys Targaryen is going to attack his kingdom soon. Therefore he wants to defend his kingdom. He has k liters of a strange liquid. He wants to distribute that liquid among the castles, so each castle may contain some liquid (possibly zero or non-integer number of liters). After that the stability of a wall is defined as follows: if the wall connects two castles a and b, and they contain x and y liters of that liquid, respectively, then the strength of that wall is xΒ·y. Your task is to print the maximum possible sum of stabilities of the walls that Sir Jaime Lannister can achieve. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 40, 1 ≀ k ≀ 1000). Then n lines follows. The i-th of these lines contains n integers ai, 1, ai, 2, ..., ai, n (<image>). If castles i and j are connected by a wall, then ai, j = 1. Otherwise it is equal to 0. It is guaranteed that ai, j = aj, i and ai, i = 0 for all 1 ≀ i, j ≀ n. Output Print the maximum possible sum of stabilities of the walls that Sir Jaime Lannister can achieve. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 3 1 0 1 0 1 0 0 0 0 0 Output 0.250000000000 Input 4 4 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 0 Output 4.000000000000 Note In the first sample, we can assign 0.5, 0.5, 0 liters of liquid to castles 1, 2, 3, respectively, to get the maximum sum (0.25). In the second sample, we can assign 1.0, 1.0, 1.0, 1.0 liters of liquid to castles 1, 2, 3, 4, respectively, to get the maximum sum (4.0) Submitted Solution: ``` n,k=map(int,input().split()) for i in range(n): for a in input().split(): if int(a) > 0: print((int(k)*.5)**2) exit(0) print(0) ``` No
11,317
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n castles in the Lannister's Kingdom and some walls connect two castles, no two castles are connected by more than one wall, no wall connects a castle to itself. Sir Jaime Lannister has discovered that Daenerys Targaryen is going to attack his kingdom soon. Therefore he wants to defend his kingdom. He has k liters of a strange liquid. He wants to distribute that liquid among the castles, so each castle may contain some liquid (possibly zero or non-integer number of liters). After that the stability of a wall is defined as follows: if the wall connects two castles a and b, and they contain x and y liters of that liquid, respectively, then the strength of that wall is xΒ·y. Your task is to print the maximum possible sum of stabilities of the walls that Sir Jaime Lannister can achieve. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 40, 1 ≀ k ≀ 1000). Then n lines follows. The i-th of these lines contains n integers ai, 1, ai, 2, ..., ai, n (<image>). If castles i and j are connected by a wall, then ai, j = 1. Otherwise it is equal to 0. It is guaranteed that ai, j = aj, i and ai, i = 0 for all 1 ≀ i, j ≀ n. Output Print the maximum possible sum of stabilities of the walls that Sir Jaime Lannister can achieve. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 3 1 0 1 0 1 0 0 0 0 0 Output 0.250000000000 Input 4 4 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 0 Output 4.000000000000 Note In the first sample, we can assign 0.5, 0.5, 0 liters of liquid to castles 1, 2, 3, respectively, to get the maximum sum (0.25). In the second sample, we can assign 1.0, 1.0, 1.0, 1.0 liters of liquid to castles 1, 2, 3, 4, respectively, to get the maximum sum (4.0) Submitted Solution: ``` read = lambda: map(int, input().split()) n, K = read() a = [list(read()) for i in range(n)] ans = 0 for i in range(n): for j in range(i + 1, n): if a[i][j] == 1: ans = max(ans, 1 / 4) for k in range(j + 1, n): if a[i][j] == a[j][k] == a[k][i] == 1: ans = 1 / 3 break print(ans * K * K) ``` No
11,318
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n castles in the Lannister's Kingdom and some walls connect two castles, no two castles are connected by more than one wall, no wall connects a castle to itself. Sir Jaime Lannister has discovered that Daenerys Targaryen is going to attack his kingdom soon. Therefore he wants to defend his kingdom. He has k liters of a strange liquid. He wants to distribute that liquid among the castles, so each castle may contain some liquid (possibly zero or non-integer number of liters). After that the stability of a wall is defined as follows: if the wall connects two castles a and b, and they contain x and y liters of that liquid, respectively, then the strength of that wall is xΒ·y. Your task is to print the maximum possible sum of stabilities of the walls that Sir Jaime Lannister can achieve. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 40, 1 ≀ k ≀ 1000). Then n lines follows. The i-th of these lines contains n integers ai, 1, ai, 2, ..., ai, n (<image>). If castles i and j are connected by a wall, then ai, j = 1. Otherwise it is equal to 0. It is guaranteed that ai, j = aj, i and ai, i = 0 for all 1 ≀ i, j ≀ n. Output Print the maximum possible sum of stabilities of the walls that Sir Jaime Lannister can achieve. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 3 1 0 1 0 1 0 0 0 0 0 Output 0.250000000000 Input 4 4 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 0 Output 4.000000000000 Note In the first sample, we can assign 0.5, 0.5, 0 liters of liquid to castles 1, 2, 3, respectively, to get the maximum sum (0.25). In the second sample, we can assign 1.0, 1.0, 1.0, 1.0 liters of liquid to castles 1, 2, 3, 4, respectively, to get the maximum sum (4.0) Submitted Solution: ``` _,n=input().split() print((int(n)*.5)**2) ``` No
11,319
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n castles in the Lannister's Kingdom and some walls connect two castles, no two castles are connected by more than one wall, no wall connects a castle to itself. Sir Jaime Lannister has discovered that Daenerys Targaryen is going to attack his kingdom soon. Therefore he wants to defend his kingdom. He has k liters of a strange liquid. He wants to distribute that liquid among the castles, so each castle may contain some liquid (possibly zero or non-integer number of liters). After that the stability of a wall is defined as follows: if the wall connects two castles a and b, and they contain x and y liters of that liquid, respectively, then the strength of that wall is xΒ·y. Your task is to print the maximum possible sum of stabilities of the walls that Sir Jaime Lannister can achieve. Input The first line of the input contains two integers n and k (1 ≀ n ≀ 40, 1 ≀ k ≀ 1000). Then n lines follows. The i-th of these lines contains n integers ai, 1, ai, 2, ..., ai, n (<image>). If castles i and j are connected by a wall, then ai, j = 1. Otherwise it is equal to 0. It is guaranteed that ai, j = aj, i and ai, i = 0 for all 1 ≀ i, j ≀ n. Output Print the maximum possible sum of stabilities of the walls that Sir Jaime Lannister can achieve. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>. Examples Input 3 1 0 1 0 1 0 0 0 0 0 Output 0.250000000000 Input 4 4 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 0 Output 4.000000000000 Note In the first sample, we can assign 0.5, 0.5, 0 liters of liquid to castles 1, 2, 3, respectively, to get the maximum sum (0.25). In the second sample, we can assign 1.0, 1.0, 1.0, 1.0 liters of liquid to castles 1, 2, 3, 4, respectively, to get the maximum sum (4.0) Submitted Solution: ``` read = lambda: map(int, input().split()) n, K = read() a = [list(read()) for i in range(n)] ans = 1 / 4 for i in range(n): for j in range(i + 1, n): for k in range(j + 1, n): if a[i][j] == a[j][k] == a[k][i] == 1: ans = 1 / 3 break print(ans * K * K) ``` No
11,320
Provide tags and a correct Python 3 solution for this coding contest problem. We all know the problem about the number of ways one can tile a 2 Γ— n field by 1 Γ— 2 dominoes. You probably remember that it goes down to Fibonacci numbers. We will talk about some other problem below, there you also are going to deal with tiling a rectangular field with dominoes. You are given a 4 Γ— n rectangular field, that is the field that contains four lines and n columns. You have to find for it any tiling by 1 Γ— 2 dominoes such that each of the n - 1 potential vertical cuts along the grid lines intersects at least one domino, splitting it in two. No two dominoes in the sought tiling should overlap, each square of the field should be covered by exactly one domino. It is allowed to rotate the dominoes, that is, you can use 2 Γ— 1 as well as 1 Γ— 2 dominoes. Write a program that finds an arbitrary sought tiling. Input The input contains one positive integer n (1 ≀ n ≀ 100) β€” the number of the field's columns. Output If there's no solution, print "-1" (without the quotes). Otherwise, print four lines containing n characters each β€” that's the description of tiling, where each vertical cut intersects at least one domino. You should print the tiling, having painted the field in no more than 26 colors. Each domino should be painted a color. Different dominoes can be painted the same color, but dominoes of the same color should not be side-neighbouring. To indicate colors you should use lowercase Latin letters. Print any of the acceptable ways of tiling. Examples Input 4 Output yyzz bccd bxxd yyaa Tags: constructive algorithms, implementation Correct Solution: ``` a=int(input()) if a%2==0: print("aabb"*(a//4)+"aabb"[:a%4]) print("ccdd" * (a // 4) + "ccdd"[:a % 4]) a-=2 print('z'+"eeff"*(a//4)+"eeff"[:a%4]+'x') print('z' + "iijj" * (a // 4) + "iijj"[:a % 4] + 'x') else: a-=1 print("z"+"aabb"*(a//4)+"aabb"[:a%4]) print("z"+"ccdd"*(a//4)+"ccdd"[:a%4]) print("eeff"*(a//4)+"eeff"[:a%4]+"x") print("gghh"*(a//4)+"gghh"[:a%4]+"x") ```
11,321
Provide tags and a correct Python 3 solution for this coding contest problem. We all know the problem about the number of ways one can tile a 2 Γ— n field by 1 Γ— 2 dominoes. You probably remember that it goes down to Fibonacci numbers. We will talk about some other problem below, there you also are going to deal with tiling a rectangular field with dominoes. You are given a 4 Γ— n rectangular field, that is the field that contains four lines and n columns. You have to find for it any tiling by 1 Γ— 2 dominoes such that each of the n - 1 potential vertical cuts along the grid lines intersects at least one domino, splitting it in two. No two dominoes in the sought tiling should overlap, each square of the field should be covered by exactly one domino. It is allowed to rotate the dominoes, that is, you can use 2 Γ— 1 as well as 1 Γ— 2 dominoes. Write a program that finds an arbitrary sought tiling. Input The input contains one positive integer n (1 ≀ n ≀ 100) β€” the number of the field's columns. Output If there's no solution, print "-1" (without the quotes). Otherwise, print four lines containing n characters each β€” that's the description of tiling, where each vertical cut intersects at least one domino. You should print the tiling, having painted the field in no more than 26 colors. Each domino should be painted a color. Different dominoes can be painted the same color, but dominoes of the same color should not be side-neighbouring. To indicate colors you should use lowercase Latin letters. Print any of the acceptable ways of tiling. Examples Input 4 Output yyzz bccd bxxd yyaa Tags: constructive algorithms, implementation Correct Solution: ``` n = int(input()) k = n // 4 if n % 2: if (n - 1) % 4: a = 'aabb' * k + 'aac' b = 'bbaa' * k + 'bbc' c = 'dee' + 'ffee' * k d = 'dff' + 'eeff' * k else: a = 'aabb' * k + 'c' b = 'bbaa' * k + 'c' c = 'd' + 'ffee' * k d = 'd' + 'eeff' * k print('\n'.join((a, b, c, d))) else: if n % 4: a = 'aabb' * k + 'aa' b = 'c' + 'ddcc' * k + 'd' c = 'c' + 'eeff' * k + 'd' else: a = 'aabb' * k b = 'c' + 'ddcc' * (k - 1) + 'ddc' c = 'c' + 'eeff' * (k - 1) + 'eec' print('\n'.join((a, b, c, a))) ```
11,322
Provide tags and a correct Python 3 solution for this coding contest problem. We all know the problem about the number of ways one can tile a 2 Γ— n field by 1 Γ— 2 dominoes. You probably remember that it goes down to Fibonacci numbers. We will talk about some other problem below, there you also are going to deal with tiling a rectangular field with dominoes. You are given a 4 Γ— n rectangular field, that is the field that contains four lines and n columns. You have to find for it any tiling by 1 Γ— 2 dominoes such that each of the n - 1 potential vertical cuts along the grid lines intersects at least one domino, splitting it in two. No two dominoes in the sought tiling should overlap, each square of the field should be covered by exactly one domino. It is allowed to rotate the dominoes, that is, you can use 2 Γ— 1 as well as 1 Γ— 2 dominoes. Write a program that finds an arbitrary sought tiling. Input The input contains one positive integer n (1 ≀ n ≀ 100) β€” the number of the field's columns. Output If there's no solution, print "-1" (without the quotes). Otherwise, print four lines containing n characters each β€” that's the description of tiling, where each vertical cut intersects at least one domino. You should print the tiling, having painted the field in no more than 26 colors. Each domino should be painted a color. Different dominoes can be painted the same color, but dominoes of the same color should not be side-neighbouring. To indicate colors you should use lowercase Latin letters. Print any of the acceptable ways of tiling. Examples Input 4 Output yyzz bccd bxxd yyaa Tags: constructive algorithms, implementation Correct Solution: ``` from sys import stdin a=int(stdin.readline()) if a%2==0: for b in range(0,int(a/2)): if b%2==0: if b==int(a/2)-1: print('aa') else: print('aa',end='') else: if b==int(a/2)-1: print('bb') else: print('bb', end='') print('c',end='') for d in range(0,int(a/2)-1): if d%2==0: print('dd',end='') else: print('ee', end='') print('f') print('c',end='') for d in range(0, int(a/2)-1): if d % 2 == 0: print('hh', end='') else: print('ii', end='') print('f') for b in range(0,int(a/2)): if b%2==0: if b==int(a/2)-1: print('aa') else: print('aa',end='') else: if b==int(a/2)-1: print('bb') else: print('bb', end='') else: for b in range(0,int((a-1)/2)): if b%2==0: print('aa',end='') else: print('bb', end='') print('c') for b in range(0,int((a-1)/2)): if b%2==0: print('ee',end='') else: print('ff', end='') print('c') if a==1: print('d') else: print('d',end='') for b in range(0,int((a-1)/2)): if b%2==0: if b==int((a-1)/2)-1: print('bb') else: print('bb',end='') else: if b==int((a-1)/2)-1: print('aa') else: print('aa', end='') if a==1: print('d') else: print('d',end='') for b in range(0,int((a-1)/2)): if b%2==0: if b==int((a-1)/2)-1: print('ee') else: print('ee',end='') else: if b==int((a-1)/2)-1: print('ff') else: print('ff', end='') ```
11,323
Provide tags and a correct Python 3 solution for this coding contest problem. We all know the problem about the number of ways one can tile a 2 Γ— n field by 1 Γ— 2 dominoes. You probably remember that it goes down to Fibonacci numbers. We will talk about some other problem below, there you also are going to deal with tiling a rectangular field with dominoes. You are given a 4 Γ— n rectangular field, that is the field that contains four lines and n columns. You have to find for it any tiling by 1 Γ— 2 dominoes such that each of the n - 1 potential vertical cuts along the grid lines intersects at least one domino, splitting it in two. No two dominoes in the sought tiling should overlap, each square of the field should be covered by exactly one domino. It is allowed to rotate the dominoes, that is, you can use 2 Γ— 1 as well as 1 Γ— 2 dominoes. Write a program that finds an arbitrary sought tiling. Input The input contains one positive integer n (1 ≀ n ≀ 100) β€” the number of the field's columns. Output If there's no solution, print "-1" (without the quotes). Otherwise, print four lines containing n characters each β€” that's the description of tiling, where each vertical cut intersects at least one domino. You should print the tiling, having painted the field in no more than 26 colors. Each domino should be painted a color. Different dominoes can be painted the same color, but dominoes of the same color should not be side-neighbouring. To indicate colors you should use lowercase Latin letters. Print any of the acceptable ways of tiling. Examples Input 4 Output yyzz bccd bxxd yyaa Tags: constructive algorithms, implementation Correct Solution: ``` n = int(input()) field = [[None] * n for _ in range(4)] for i in range(0, n - 1, 2): if i > 0 and field[0][i - 1] == 'a': field[0][i] = field[0][i + 1] = 'b' field[1][i] = field[1][i + 1] = 'd' else: field[0][i] = field[0][i + 1] = 'a' field[1][i] = field[1][i + 1] = 'c' for i in range(1, n - 1, 2): if i > 0 and field[2][i - 1] == 'e': field[2][i] = field[2][i + 1] = 'f' field[3][i] = field[3][i + 1] = 'h' else: field[2][i] = field[2][i + 1] = 'e' field[3][i] = field[3][i + 1] = 'g' field[2][0] = field[3][0] = 'j' if n % 2 == 0: field[2][n - 1] = field[3][n - 1] = 'i' else: field[0][n - 1] = field[1][n - 1] = 'i' for line in field: print(''.join(line)) ```
11,324
Provide tags and a correct Python 3 solution for this coding contest problem. We all know the problem about the number of ways one can tile a 2 Γ— n field by 1 Γ— 2 dominoes. You probably remember that it goes down to Fibonacci numbers. We will talk about some other problem below, there you also are going to deal with tiling a rectangular field with dominoes. You are given a 4 Γ— n rectangular field, that is the field that contains four lines and n columns. You have to find for it any tiling by 1 Γ— 2 dominoes such that each of the n - 1 potential vertical cuts along the grid lines intersects at least one domino, splitting it in two. No two dominoes in the sought tiling should overlap, each square of the field should be covered by exactly one domino. It is allowed to rotate the dominoes, that is, you can use 2 Γ— 1 as well as 1 Γ— 2 dominoes. Write a program that finds an arbitrary sought tiling. Input The input contains one positive integer n (1 ≀ n ≀ 100) β€” the number of the field's columns. Output If there's no solution, print "-1" (without the quotes). Otherwise, print four lines containing n characters each β€” that's the description of tiling, where each vertical cut intersects at least one domino. You should print the tiling, having painted the field in no more than 26 colors. Each domino should be painted a color. Different dominoes can be painted the same color, but dominoes of the same color should not be side-neighbouring. To indicate colors you should use lowercase Latin letters. Print any of the acceptable ways of tiling. Examples Input 4 Output yyzz bccd bxxd yyaa Tags: constructive algorithms, implementation Correct Solution: ``` import string n = int(input()) l = 0 def get_next_l(exclusions = []): global l a = string.ascii_lowercase[l] while a in exclusions: l = (l + 1) % 26 a = string.ascii_lowercase[l] l = (l + 1) % 26 return a rows = [[""] * n for _ in range(4)] if n == 1: rows[0][0] = rows[1][0] = get_next_l() rows[2][0] = rows[3][0] = get_next_l() elif n == 2: for i in range(4): rows[i] = get_next_l() * 2 elif n % 2 == 0: for i in range(0, n, 2): rows[0][i] = rows[0][i+1] = get_next_l() front = get_next_l(rows[0][0]) rows[1][0] = front for i in range(1, n-1, 2): rows[1][i] = rows[1][i+1] = get_next_l([rows[2][i-1]] + rows[1][i:i+2]) end = get_next_l(rows[0][-1] + rows[1][-2]) rows[1][-1] = end rows[2][0] = front for i in range(1, n-1, 2): rows[2][i] = rows[2][i+1] = get_next_l([rows[2][i-1]] + rows[1][i:i+2] + [end]) rows[2][-1] = end for i in range(0, n, 2): rows[3][i] = rows[3][i+1] = get_next_l([rows[3][i-1]] + rows[2][i:i+2]) else: for i in range(0, n-1, 2): rows[0][i] = rows[0][i+1] = get_next_l() end = get_next_l() rows[0][-1] = end for i in range(0, n-1, 2): rows[1][i] = rows[1][i+1] = get_next_l([rows[1][i-1]] + rows[1][i:i+2] + [end]) rows[1][-1] = end front = get_next_l(rows[1][0]) rows[2][0] = front for i in range(1, n, 2): rows[2][i] = rows[2][i+1] = get_next_l([rows[2][i-1]] + rows[1][i:i+2]) rows[3][0] = front for i in range(1, n, 2): rows[3][i] = rows[3][i+1] = get_next_l([rows[3][i-1]] + rows[2][i:i+2]) print("\n".join("".join(r) for r in rows)) ```
11,325
Provide tags and a correct Python 3 solution for this coding contest problem. We all know the problem about the number of ways one can tile a 2 Γ— n field by 1 Γ— 2 dominoes. You probably remember that it goes down to Fibonacci numbers. We will talk about some other problem below, there you also are going to deal with tiling a rectangular field with dominoes. You are given a 4 Γ— n rectangular field, that is the field that contains four lines and n columns. You have to find for it any tiling by 1 Γ— 2 dominoes such that each of the n - 1 potential vertical cuts along the grid lines intersects at least one domino, splitting it in two. No two dominoes in the sought tiling should overlap, each square of the field should be covered by exactly one domino. It is allowed to rotate the dominoes, that is, you can use 2 Γ— 1 as well as 1 Γ— 2 dominoes. Write a program that finds an arbitrary sought tiling. Input The input contains one positive integer n (1 ≀ n ≀ 100) β€” the number of the field's columns. Output If there's no solution, print "-1" (without the quotes). Otherwise, print four lines containing n characters each β€” that's the description of tiling, where each vertical cut intersects at least one domino. You should print the tiling, having painted the field in no more than 26 colors. Each domino should be painted a color. Different dominoes can be painted the same color, but dominoes of the same color should not be side-neighbouring. To indicate colors you should use lowercase Latin letters. Print any of the acceptable ways of tiling. Examples Input 4 Output yyzz bccd bxxd yyaa Tags: constructive algorithms, implementation Correct Solution: ``` def computeTiling(n): if n == 1: print("a\na\nf\nf") return for tiling in generateRowTilings(n): print("".join(tiling)) def generateRowTilings(n): for (rowNum, firstTile, pattern) in generateRowTilingPatterns(n): yield makeRowTiling(rowNum, firstTile, pattern, n) def generateRowTilingPatterns(n): rows = (1, 2, 3, 4) firstTiles = ('a', 'a', 'd', 'e') patterns = ('bbcc', 'ccbb', 'deed', 'edde') return zip(rows, firstTiles, patterns) def makeRowTiling(row, prefix, pattern, n): yield prefix yield from (pattern[i%4] for i in range(n-2)) yield pattern[(n-2)%4] if (n%2 != (row-1)//2) else 'f' if __name__ == '__main__': n = int(input()) computeTiling(n) ```
11,326
Provide tags and a correct Python 3 solution for this coding contest problem. We all know the problem about the number of ways one can tile a 2 Γ— n field by 1 Γ— 2 dominoes. You probably remember that it goes down to Fibonacci numbers. We will talk about some other problem below, there you also are going to deal with tiling a rectangular field with dominoes. You are given a 4 Γ— n rectangular field, that is the field that contains four lines and n columns. You have to find for it any tiling by 1 Γ— 2 dominoes such that each of the n - 1 potential vertical cuts along the grid lines intersects at least one domino, splitting it in two. No two dominoes in the sought tiling should overlap, each square of the field should be covered by exactly one domino. It is allowed to rotate the dominoes, that is, you can use 2 Γ— 1 as well as 1 Γ— 2 dominoes. Write a program that finds an arbitrary sought tiling. Input The input contains one positive integer n (1 ≀ n ≀ 100) β€” the number of the field's columns. Output If there's no solution, print "-1" (without the quotes). Otherwise, print four lines containing n characters each β€” that's the description of tiling, where each vertical cut intersects at least one domino. You should print the tiling, having painted the field in no more than 26 colors. Each domino should be painted a color. Different dominoes can be painted the same color, but dominoes of the same color should not be side-neighbouring. To indicate colors you should use lowercase Latin letters. Print any of the acceptable ways of tiling. Examples Input 4 Output yyzz bccd bxxd yyaa Tags: constructive algorithms, implementation Correct Solution: ``` def computeTiling(n): printEvenLengthTiling(n) if isEven(n) else printOddLengthTiling(n) def isEven(n): return n%2 == 0 def printEvenLengthTiling(n): print(buildRowFromPattern( '', 'nnoo', '', n)) print(buildRowFromPattern('l', 'xxzz', 'f', n)) print(buildRowFromPattern('l', 'zzxx', 'f', n)) print(buildRowFromPattern( '', 'nnoo', '', n)) def printOddLengthTiling(n): print(buildRowFromPattern('l', 'xxzz', '', n)) print(buildRowFromPattern('l', 'zzxx', '', n)) print(buildRowFromPattern( '', 'nnoo', 'f', n)) print(buildRowFromPattern( '', 'oonn', 'f', n)) def buildRowFromPattern(prefix, infix, suffix, n): return "".join(applyPattern(prefix, infix, suffix, n)) def applyPattern(prefix, infix, suffix, n): n = n - bool(prefix) - bool(suffix) yield prefix yield from extendInfix(infix, n) yield suffix def extendInfix(infix, n): repetitions, reminder = divmod(n, len(infix)) for rep in range(repetitions): yield infix yield infix[:reminder] if __name__ == '__main__': n = int(input()) computeTiling(n) ```
11,327
Provide tags and a correct Python 3 solution for this coding contest problem. We all know the problem about the number of ways one can tile a 2 Γ— n field by 1 Γ— 2 dominoes. You probably remember that it goes down to Fibonacci numbers. We will talk about some other problem below, there you also are going to deal with tiling a rectangular field with dominoes. You are given a 4 Γ— n rectangular field, that is the field that contains four lines and n columns. You have to find for it any tiling by 1 Γ— 2 dominoes such that each of the n - 1 potential vertical cuts along the grid lines intersects at least one domino, splitting it in two. No two dominoes in the sought tiling should overlap, each square of the field should be covered by exactly one domino. It is allowed to rotate the dominoes, that is, you can use 2 Γ— 1 as well as 1 Γ— 2 dominoes. Write a program that finds an arbitrary sought tiling. Input The input contains one positive integer n (1 ≀ n ≀ 100) β€” the number of the field's columns. Output If there's no solution, print "-1" (without the quotes). Otherwise, print four lines containing n characters each β€” that's the description of tiling, where each vertical cut intersects at least one domino. You should print the tiling, having painted the field in no more than 26 colors. Each domino should be painted a color. Different dominoes can be painted the same color, but dominoes of the same color should not be side-neighbouring. To indicate colors you should use lowercase Latin letters. Print any of the acceptable ways of tiling. Examples Input 4 Output yyzz bccd bxxd yyaa Tags: constructive algorithms, implementation Correct Solution: ``` n=int(input()) s1,s2="aabb",'ccdd' if n % 2 == 0: print((s1*n)[:n]) print('e'+(s2*n)[:n-2]+'f') print('e'+(s1*n)[:n-2]+'f') print((s2*n)[:n]) else: print((s1*n)[:n-1]+'e') print((s1*n)[2:n+1]+'e') print('f'+(s2*n)[:n-1]) print('f'+(s2*n)[2:n+1]) ```
11,328
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We all know the problem about the number of ways one can tile a 2 Γ— n field by 1 Γ— 2 dominoes. You probably remember that it goes down to Fibonacci numbers. We will talk about some other problem below, there you also are going to deal with tiling a rectangular field with dominoes. You are given a 4 Γ— n rectangular field, that is the field that contains four lines and n columns. You have to find for it any tiling by 1 Γ— 2 dominoes such that each of the n - 1 potential vertical cuts along the grid lines intersects at least one domino, splitting it in two. No two dominoes in the sought tiling should overlap, each square of the field should be covered by exactly one domino. It is allowed to rotate the dominoes, that is, you can use 2 Γ— 1 as well as 1 Γ— 2 dominoes. Write a program that finds an arbitrary sought tiling. Input The input contains one positive integer n (1 ≀ n ≀ 100) β€” the number of the field's columns. Output If there's no solution, print "-1" (without the quotes). Otherwise, print four lines containing n characters each β€” that's the description of tiling, where each vertical cut intersects at least one domino. You should print the tiling, having painted the field in no more than 26 colors. Each domino should be painted a color. Different dominoes can be painted the same color, but dominoes of the same color should not be side-neighbouring. To indicate colors you should use lowercase Latin letters. Print any of the acceptable ways of tiling. Examples Input 4 Output yyzz bccd bxxd yyaa Submitted Solution: ``` n = int(input()) if n == 1: print('-1') elif n == 2: print('aa\nbb\ncc\ndd') else: print('aabb' * (n // 4) + 'aay'[:n % 4]) print('ccdd' * (n // 4) + 'ccy'[:n % 4]) print('z' + 'eeff' * ((n - 1) // 4) + ('ee' if n % 4 in (0, 3) else '') + ('' if n % 2 else 'y')) print('z' + 'gghh' * ((n - 1) // 4) + ('gg' if n % 4 in (0, 3) else '') + ('' if n % 2 else 'y')) ``` No
11,329
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We all know the problem about the number of ways one can tile a 2 Γ— n field by 1 Γ— 2 dominoes. You probably remember that it goes down to Fibonacci numbers. We will talk about some other problem below, there you also are going to deal with tiling a rectangular field with dominoes. You are given a 4 Γ— n rectangular field, that is the field that contains four lines and n columns. You have to find for it any tiling by 1 Γ— 2 dominoes such that each of the n - 1 potential vertical cuts along the grid lines intersects at least one domino, splitting it in two. No two dominoes in the sought tiling should overlap, each square of the field should be covered by exactly one domino. It is allowed to rotate the dominoes, that is, you can use 2 Γ— 1 as well as 1 Γ— 2 dominoes. Write a program that finds an arbitrary sought tiling. Input The input contains one positive integer n (1 ≀ n ≀ 100) β€” the number of the field's columns. Output If there's no solution, print "-1" (without the quotes). Otherwise, print four lines containing n characters each β€” that's the description of tiling, where each vertical cut intersects at least one domino. You should print the tiling, having painted the field in no more than 26 colors. Each domino should be painted a color. Different dominoes can be painted the same color, but dominoes of the same color should not be side-neighbouring. To indicate colors you should use lowercase Latin letters. Print any of the acceptable ways of tiling. Examples Input 4 Output yyzz bccd bxxd yyaa Submitted Solution: ``` from sys import stdin a=int(stdin.readline()) if a%2==0: for b in range(0,int(a/2)): if b%2==0: if b==int(a/2)-1: print('aa') else: print('aa',end='') else: if b==int(a/2)-1: print('bb') else: print('bb', end='') print('c',end='') for d in range(0,int(a/2)-1): if d%2==0: print('dd',end='') else: print('ee', end='') print('f') print('c',end='') for d in range(0, int(a/2)-1): if d % 2 == 0: print('ee', end='') else: print('dd', end='') print('f') for b in range(0,int(a/2)): if b%2==0: if b==int(a/2)-1: print('aa') else: print('aa',end='') else: if b==int(a/2)-1: print('bb') else: print('bb', end='') else: for b in range(0,int((a-1)/2)): if b%2==0: if b==int((a-1)/2)-1: print('aa') else: print('aa',end='') else: if b==int((a-1)/2)-1: print('bb') else: print('bb', end='') print('c') for b in range(0,int((a-1)/2)): if b%2==0: if b==int((a-1)/2)-1: print('bb') else: print('bb',end='') else: if b==int((a-1)/2)-1: print('aa') else: print('aa', end='') print('c') if a==1: print('d') else: print('d',end='') for b in range(0,int((a-1)/2)): if b%2==0: if b==int((a-1)/2)-1: print('bb') else: print('bb',end='') else: if b==int((a-1)/2)-1: print('aa') else: print('aa', end='') if a==1: print('d') else: print('d',end='') for b in range(0,int((a-1)/2)): if b%2==0: if b==int((a-1)/2)-1: print('aa') else: print('aa',end='') else: if b==int((a-1)/2)-1: print('bb') else: print('bb', end='') ``` No
11,330
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We all know the problem about the number of ways one can tile a 2 Γ— n field by 1 Γ— 2 dominoes. You probably remember that it goes down to Fibonacci numbers. We will talk about some other problem below, there you also are going to deal with tiling a rectangular field with dominoes. You are given a 4 Γ— n rectangular field, that is the field that contains four lines and n columns. You have to find for it any tiling by 1 Γ— 2 dominoes such that each of the n - 1 potential vertical cuts along the grid lines intersects at least one domino, splitting it in two. No two dominoes in the sought tiling should overlap, each square of the field should be covered by exactly one domino. It is allowed to rotate the dominoes, that is, you can use 2 Γ— 1 as well as 1 Γ— 2 dominoes. Write a program that finds an arbitrary sought tiling. Input The input contains one positive integer n (1 ≀ n ≀ 100) β€” the number of the field's columns. Output If there's no solution, print "-1" (without the quotes). Otherwise, print four lines containing n characters each β€” that's the description of tiling, where each vertical cut intersects at least one domino. You should print the tiling, having painted the field in no more than 26 colors. Each domino should be painted a color. Different dominoes can be painted the same color, but dominoes of the same color should not be side-neighbouring. To indicate colors you should use lowercase Latin letters. Print any of the acceptable ways of tiling. Examples Input 4 Output yyzz bccd bxxd yyaa Submitted Solution: ``` n=int(input()) L=["aabb","cdde","cffe"] if n%3==2: print("-1") else: for i in range(0,n,3): for j in range(3): print(L[j]) for j in L[:n%3]: print(j) ``` No
11,331
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We all know the problem about the number of ways one can tile a 2 Γ— n field by 1 Γ— 2 dominoes. You probably remember that it goes down to Fibonacci numbers. We will talk about some other problem below, there you also are going to deal with tiling a rectangular field with dominoes. You are given a 4 Γ— n rectangular field, that is the field that contains four lines and n columns. You have to find for it any tiling by 1 Γ— 2 dominoes such that each of the n - 1 potential vertical cuts along the grid lines intersects at least one domino, splitting it in two. No two dominoes in the sought tiling should overlap, each square of the field should be covered by exactly one domino. It is allowed to rotate the dominoes, that is, you can use 2 Γ— 1 as well as 1 Γ— 2 dominoes. Write a program that finds an arbitrary sought tiling. Input The input contains one positive integer n (1 ≀ n ≀ 100) β€” the number of the field's columns. Output If there's no solution, print "-1" (without the quotes). Otherwise, print four lines containing n characters each β€” that's the description of tiling, where each vertical cut intersects at least one domino. You should print the tiling, having painted the field in no more than 26 colors. Each domino should be painted a color. Different dominoes can be painted the same color, but dominoes of the same color should not be side-neighbouring. To indicate colors you should use lowercase Latin letters. Print any of the acceptable ways of tiling. Examples Input 4 Output yyzz bccd bxxd yyaa Submitted Solution: ``` import string n = int(input()) l = 0 def get_next_l(): global l a = string.ascii_lowercase[l] l = (l + 9) % 26 return a rows = [""] * 4 if n == 1: rows[0] = rows[1] = get_next_l() rows[2] = rows[3] = get_next_l() elif n == 2: for i in range(4): rows[i] = get_next_l() * 2 elif n % 2 == 0: rows[0] = "".join([get_next_l() * 2 for _ in range(n//2)]) front = get_next_l() rows[1] = front + "".join([get_next_l() * 2 for _ in range(n//2 - 1)]) # delay until we get there end = get_next_l() rows[1] += end rows[2] = front + "".join([get_next_l() * 2 for _ in range(n//2 - 1)]) + end rows[3] = "".join([get_next_l() * 2 for _ in range(n//2)]) else: rows[0] = "".join([get_next_l() * 2 for _ in range(n//2)]) end = get_next_l() rows[0] += end rows[1] = "".join([get_next_l() * 2 for _ in range(n//2)]) + end front = get_next_l() rows[2] = front + "".join([get_next_l() * 2 for _ in range(n//2)]) rows[3] = front + "".join([get_next_l() * 2 for _ in range(n//2)]) print("\n".join(rows)) ``` No
11,332
Provide tags and a correct Python 3 solution for this coding contest problem. In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number i got a score of ai. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question. Input The single line contains six integers a1, ..., a6 (0 ≀ ai ≀ 1000) β€” scores of the participants Output Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). Examples Input 1 3 2 1 2 1 Output YES Input 1 1 1 1 1 99 Output NO Note In the first sample, first team can be composed of 1st, 2nd and 6th participant, second β€” of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater. Tags: brute force Correct Solution: ``` import itertools a = [int(x) for x in input().split()] index = list(range(6)) b = list(itertools.combinations(index, 3)) c = len(b) for z in range(c): for x in range(z+1, c): if not any([y in b[x] for y in b[z]]): if sum(a[y] for y in b[z]) == sum(a[y] for y in b[x]): print('yes') quit() print('no') ```
11,333
Provide tags and a correct Python 3 solution for this coding contest problem. In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number i got a score of ai. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question. Input The single line contains six integers a1, ..., a6 (0 ≀ ai ≀ 1000) β€” scores of the participants Output Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). Examples Input 1 3 2 1 2 1 Output YES Input 1 1 1 1 1 99 Output NO Note In the first sample, first team can be composed of 1st, 2nd and 6th participant, second β€” of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater. Tags: brute force Correct Solution: ``` n = list(map(int,input().split())) #n = int(input()) x = len(n) checked = [False,False,False,False,False,False] def check(cur1,cur2): if sum(checked)==6: if cur1==cur2: print("YES") exit() for i in range(x): if checked[i] == False: checked[i] = True for j in range(x): if checked[j] == False: checked[j] = True check(cur1+n[i],cur2+n[j]) checked[j]=False checked[i]=False check(0,0) print("NO") ```
11,334
Provide tags and a correct Python 3 solution for this coding contest problem. In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number i got a score of ai. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question. Input The single line contains six integers a1, ..., a6 (0 ≀ ai ≀ 1000) β€” scores of the participants Output Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). Examples Input 1 3 2 1 2 1 Output YES Input 1 1 1 1 1 99 Output NO Note In the first sample, first team can be composed of 1st, 2nd and 6th participant, second β€” of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater. Tags: brute force Correct Solution: ``` from itertools import combinations l=list(map(int,input().split())) s=sum(l);f=0 if s%2!=0: print("NO") f=1 else: for i in combinations(l, 3): if sum(i)==s//2: print("YES") f=1 break if f==0:print("NO") ```
11,335
Provide tags and a correct Python 3 solution for this coding contest problem. In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number i got a score of ai. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question. Input The single line contains six integers a1, ..., a6 (0 ≀ ai ≀ 1000) β€” scores of the participants Output Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). Examples Input 1 3 2 1 2 1 Output YES Input 1 1 1 1 1 99 Output NO Note In the first sample, first team can be composed of 1st, 2nd and 6th participant, second β€” of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater. Tags: brute force Correct Solution: ``` from itertools import permutations a = [int(x) for x in input().split()] for p in permutations(a): if p[0] + p[1] + p[2] == p[3] + p[4] + p[5]: print('YES') exit() print('NO') ```
11,336
Provide tags and a correct Python 3 solution for this coding contest problem. In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number i got a score of ai. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question. Input The single line contains six integers a1, ..., a6 (0 ≀ ai ≀ 1000) β€” scores of the participants Output Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). Examples Input 1 3 2 1 2 1 Output YES Input 1 1 1 1 1 99 Output NO Note In the first sample, first team can be composed of 1st, 2nd and 6th participant, second β€” of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater. Tags: brute force Correct Solution: ``` def f(a, b): if (len(a) == 6): #print(a); x = sum(a[0:3]); y = sum(a[3:6]); if (x == y): return True else: for i in range(len(b)): x = b[i] j = i + 1 k = len(b) remaining = b[0:i] + b[j:k] selected = a + [x] if (f(selected, remaining)): return True def ff(a): print("YES" if f([], a) else "NO") #ff([1,2,3,1,2,3]); #ff([1,1,1,1,1,4]); a = [int(x) for x in input().split()] ff(a) ```
11,337
Provide tags and a correct Python 3 solution for this coding contest problem. In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number i got a score of ai. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question. Input The single line contains six integers a1, ..., a6 (0 ≀ ai ≀ 1000) β€” scores of the participants Output Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). Examples Input 1 3 2 1 2 1 Output YES Input 1 1 1 1 1 99 Output NO Note In the first sample, first team can be composed of 1st, 2nd and 6th participant, second β€” of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater. Tags: brute force Correct Solution: ``` a = list(map(int, input().split())) if sum(a) % 2 == 1: print('NO') else: target = sum(a) // 2 n = 6 ans = 'NO' for i in range(n): for j in range(i + 1, n): for k in range(j + 1, n): if a[i] + a[j] + a[k] == target: ans = 'YES' print(ans) ```
11,338
Provide tags and a correct Python 3 solution for this coding contest problem. In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number i got a score of ai. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question. Input The single line contains six integers a1, ..., a6 (0 ≀ ai ≀ 1000) β€” scores of the participants Output Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). Examples Input 1 3 2 1 2 1 Output YES Input 1 1 1 1 1 99 Output NO Note In the first sample, first team can be composed of 1st, 2nd and 6th participant, second β€” of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater. Tags: brute force Correct Solution: ``` l = list(map(int, input().split())) y = False s = sum(l) i = 0 while i < 4 and not y: j = i + 1 while j < 5 and not y: k = j + 1 while k < 6 and not y: t = l[i] + l[j] + l[k] if t == s - t: y = True k += 1 j += 1 i += 1 if y: print("YES") else: print("NO") ```
11,339
Provide tags and a correct Python 3 solution for this coding contest problem. In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number i got a score of ai. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question. Input The single line contains six integers a1, ..., a6 (0 ≀ ai ≀ 1000) β€” scores of the participants Output Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). Examples Input 1 3 2 1 2 1 Output YES Input 1 1 1 1 1 99 Output NO Note In the first sample, first team can be composed of 1st, 2nd and 6th participant, second β€” of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater. Tags: brute force Correct Solution: ``` A=list(map(int,input().split())) flag=False for i in range(6): pow1=A[i] used1=[i] for j in range(6): if j not in used1: pow2=pow1+A[j] used2=used1+[j] for k in range(6): if k not in used2: pow3=pow2+A[k] used3=used2+[k] for l in range(6): if l not in used3: pow4=pow3-A[l] used4=used3+[l] for m in range(6): if m not in used4: pow5=pow4-A[m] used5=used4+[m] for n in range(6): if n not in used5: pow6=pow5-A[n] if pow6==0: flag=True ans=flag and 'YES' or 'NO' print(ans) ```
11,340
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number i got a score of ai. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question. Input The single line contains six integers a1, ..., a6 (0 ≀ ai ≀ 1000) β€” scores of the participants Output Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). Examples Input 1 3 2 1 2 1 Output YES Input 1 1 1 1 1 99 Output NO Note In the first sample, first team can be composed of 1st, 2nd and 6th participant, second β€” of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater. Submitted Solution: ``` def main(): a=list(map(int,input().split())) s=sum(a) if s%2==0: for i in range(6): for j in range(6): if j!=i: for k in range(6): if k!=i and k!=j: if a[i]+a[j]+a[k]==s//2: return 1 return 0 if main(): print('YES') else: print('NO') ``` Yes
11,341
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number i got a score of ai. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question. Input The single line contains six integers a1, ..., a6 (0 ≀ ai ≀ 1000) β€” scores of the participants Output Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). Examples Input 1 3 2 1 2 1 Output YES Input 1 1 1 1 1 99 Output NO Note In the first sample, first team can be composed of 1st, 2nd and 6th participant, second β€” of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater. Submitted Solution: ``` x = list(map(int, input().split())) total_sum = sum(x) if sum(x) % 2 != 0: print('NO') else: for i in range(6): for j in range(6): if j == i and j != 5: break for k in range(6): if k == j and k != 5: break if i != k and i != j and k != j and x[i] + x[j] + x[k] == total_sum // 2: print('YES') exit() if i == j == k == 5: print('NO') ``` Yes
11,342
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number i got a score of ai. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question. Input The single line contains six integers a1, ..., a6 (0 ≀ ai ≀ 1000) β€” scores of the participants Output Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). Examples Input 1 3 2 1 2 1 Output YES Input 1 1 1 1 1 99 Output NO Note In the first sample, first team can be composed of 1st, 2nd and 6th participant, second β€” of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater. Submitted Solution: ``` from sys import stdin a = [int(i) for i in stdin.readline().split(' ')] s = sum(a) possible = False for i in range(1, 5): for j in range(i+1, 6): team = a[0]+a[i]+a[j] if team == s-team: possible = True if possible: print("YES") else: print("NO") ``` Yes
11,343
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number i got a score of ai. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question. Input The single line contains six integers a1, ..., a6 (0 ≀ ai ≀ 1000) β€” scores of the participants Output Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). Examples Input 1 3 2 1 2 1 Output YES Input 1 1 1 1 1 99 Output NO Note In the first sample, first team can be composed of 1st, 2nd and 6th participant, second β€” of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater. Submitted Solution: ``` n = list(map(int, input().split())) Sum = sum(n) r = False for i in range (len(n)): for j in range (i+1, len(n)): for k in range (j+1, len(n)): if (n[i] + n[j] + n[k] == Sum/2): r = True if (r == True): print ('YES') else: print ('NO') ``` Yes
11,344
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number i got a score of ai. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question. Input The single line contains six integers a1, ..., a6 (0 ≀ ai ≀ 1000) β€” scores of the participants Output Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). Examples Input 1 3 2 1 2 1 Output YES Input 1 1 1 1 1 99 Output NO Note In the first sample, first team can be composed of 1st, 2nd and 6th participant, second β€” of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater. Submitted Solution: ``` r = lambda : list(map(int, input().split())) arr = r() arr.sort() f = False for i in range(0 , len(arr)): for j in range(0 , len(arr)): for k in range(0,len(arr)): if i!=j!=k: if arr[i]+arr[j]+arr[k] == sum(arr)//2: f = True break print("YES" if f else "NO") ``` No
11,345
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number i got a score of ai. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question. Input The single line contains six integers a1, ..., a6 (0 ≀ ai ≀ 1000) β€” scores of the participants Output Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). Examples Input 1 3 2 1 2 1 Output YES Input 1 1 1 1 1 99 Output NO Note In the first sample, first team can be composed of 1st, 2nd and 6th participant, second β€” of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater. Submitted Solution: ``` si= input() def opr(grad): l =[] i = 0 l.append(0) grew = [] j=len(grad)-1 while i<len(grad): grew.append(grad[j]) j-=1 i+=1 i=0 m=0 j=0 while i<len(grew): if grew[i]!=' ': l[j]+=int(grew[i])*(10**m) m+=1 if grew[i]==' ': m=0 j+=1 l.append(0) i+=1 g = [] i=len(l)-1 while i>=0: g.append(l[i]) i-=1 return g def ma(l): i =0 m=l[i] im=0 while i<len(l): if l[i]>m: m=l[i] im =i i+=1 return im def su(l): i =0 m = 0 while i<len(l): m+=l[i] i+=1 return m i = 0 l = opr (si) k1 = 0 k2 = 0 ki1 = 0 ki2 = 0 while i<6: if k1 < k2 and ki1<3: k1+= l[ma(l)] l.remove(l[ma(l)]) ki1+=1 if k1>= k2 and ki2<3: k2+= l[ma(l)] l.remove(l[ma(l)]) ki2+=1 i+=1 if k1-k2 == 0: print("YES") else: print("NO") ``` No
11,346
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number i got a score of ai. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question. Input The single line contains six integers a1, ..., a6 (0 ≀ ai ≀ 1000) β€” scores of the participants Output Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). Examples Input 1 3 2 1 2 1 Output YES Input 1 1 1 1 1 99 Output NO Note In the first sample, first team can be composed of 1st, 2nd and 6th participant, second β€” of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater. Submitted Solution: ``` powers = list(int(i) for i in input().split()) powers = list(reversed(sorted(powers))) team = 0; end = False for p in powers: team += p team /= 2 result = "NO" if powers[0] > team: end = True if end == False: for i in range(len(powers)): if powers[0] == team: result = "YES" end = True break if end == False: for i in range(len(powers)): for j in range(len(powers)): if powers[i] + powers[j] == team: result = "YES" end = True break if end == False: for i in range(len(powers)): for j in range(len(powers)): for z in range(len(powers)): if powers[i] + powers[j] + powers[z] == team: result = "YES" end = True break print(result) ``` No
11,347
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number i got a score of ai. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question. Input The single line contains six integers a1, ..., a6 (0 ≀ ai ≀ 1000) β€” scores of the participants Output Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). Examples Input 1 3 2 1 2 1 Output YES Input 1 1 1 1 1 99 Output NO Note In the first sample, first team can be composed of 1st, 2nd and 6th participant, second β€” of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater. Submitted Solution: ``` N = list(map(int,input().split())) a = 0 N.sort() for i in range(6): a += N[i] if a % 2 != 0: print('NO') else: a = a//2 if a - N[5] - N[0] < N[1]: print('NO') elif a - N[5] - N[0] == N[1]: print('YES') else: a -= N[5] if a-N[2]-N[0] < 0: print('NO') elif a-N[2]-N[0] == 0: print('YES') elif a-N[2]-N[1] < 0: print('NO') elif a - N[2] - N[1] == 0: print('YES') elif a - N[3] - N[0] < 0: print('NO') elif a - N[3] - N[0] == 0: print('YES') else: print('NO') ``` No
11,348
Provide tags and a correct Python 3 solution for this coding contest problem. The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person. You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users). As a reminder, a prefix of a string s is its substring which occurs at the beginning of s: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string a is alphabetically earlier than a string b, if a is a prefix of b, or a and b coincide up to some position, and then a has a letter that is alphabetically earlier than the corresponding letter in b: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac". Input The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive. Output Output a single string β€” alphabetically earliest possible login formed from these names. The output should be given in lowercase as well. Examples Input harry potter Output hap Input tom riddle Output tomr Tags: brute force, greedy, sortings Correct Solution: ``` a=input().split() n=[] X='' for i in a[0]: X+=i n.append(X+a[1][0]) n=sorted(n) print(n[0]) ```
11,349
Provide tags and a correct Python 3 solution for this coding contest problem. The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person. You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users). As a reminder, a prefix of a string s is its substring which occurs at the beginning of s: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string a is alphabetically earlier than a string b, if a is a prefix of b, or a and b coincide up to some position, and then a has a letter that is alphabetically earlier than the corresponding letter in b: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac". Input The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive. Output Output a single string β€” alphabetically earliest possible login formed from these names. The output should be given in lowercase as well. Examples Input harry potter Output hap Input tom riddle Output tomr Tags: brute force, greedy, sortings Correct Solution: ``` f,l=map(str,input().split()) i=1 j=0 while i<len(f): if ord(f[i])<ord(l[j]): i+=1 else: break print(f[0:i]+l[0]) ```
11,350
Provide tags and a correct Python 3 solution for this coding contest problem. The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person. You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users). As a reminder, a prefix of a string s is its substring which occurs at the beginning of s: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string a is alphabetically earlier than a string b, if a is a prefix of b, or a and b coincide up to some position, and then a has a letter that is alphabetically earlier than the corresponding letter in b: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac". Input The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive. Output Output a single string β€” alphabetically earliest possible login formed from these names. The output should be given in lowercase as well. Examples Input harry potter Output hap Input tom riddle Output tomr Tags: brute force, greedy, sortings Correct Solution: ``` fname,lname = input().split() ans="" ans+=fname[0] for x in range(1,len(fname)): if ord(fname[x]) < ord(lname[0]): ans+=fname[x] else:break; ans+=lname[0] print(ans) ```
11,351
Provide tags and a correct Python 3 solution for this coding contest problem. The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person. You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users). As a reminder, a prefix of a string s is its substring which occurs at the beginning of s: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string a is alphabetically earlier than a string b, if a is a prefix of b, or a and b coincide up to some position, and then a has a letter that is alphabetically earlier than the corresponding letter in b: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac". Input The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive. Output Output a single string β€” alphabetically earliest possible login formed from these names. The output should be given in lowercase as well. Examples Input harry potter Output hap Input tom riddle Output tomr Tags: brute force, greedy, sortings Correct Solution: ``` s = input().split(' ') result = s[0][0] end = s[1][0] for i in range(1, len(s[0])): if ord(s[0][i]) < ord(end): result += s[0][i] else: break result += end print(result) ```
11,352
Provide tags and a correct Python 3 solution for this coding contest problem. The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person. You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users). As a reminder, a prefix of a string s is its substring which occurs at the beginning of s: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string a is alphabetically earlier than a string b, if a is a prefix of b, or a and b coincide up to some position, and then a has a letter that is alphabetically earlier than the corresponding letter in b: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac". Input The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive. Output Output a single string β€” alphabetically earliest possible login formed from these names. The output should be given in lowercase as well. Examples Input harry potter Output hap Input tom riddle Output tomr Tags: brute force, greedy, sortings Correct Solution: ``` inu=input().split() first,last=inu[0],inu[1] l,name,st=[],"","" for fi in first: st=st+fi name=st for se in last: name=name+se l.append(name) l.sort() print(l[0]) ```
11,353
Provide tags and a correct Python 3 solution for this coding contest problem. The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person. You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users). As a reminder, a prefix of a string s is its substring which occurs at the beginning of s: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string a is alphabetically earlier than a string b, if a is a prefix of b, or a and b coincide up to some position, and then a has a letter that is alphabetically earlier than the corresponding letter in b: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac". Input The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive. Output Output a single string β€” alphabetically earliest possible login formed from these names. The output should be given in lowercase as well. Examples Input harry potter Output hap Input tom riddle Output tomr Tags: brute force, greedy, sortings Correct Solution: ``` first, last = input().split() if len(first) == 1: print(first[0]+last[0]) else: i=1 while i < len(first) and first[i] < last[0]: i+=1 print(first[:i]+last[0]) ```
11,354
Provide tags and a correct Python 3 solution for this coding contest problem. The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person. You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users). As a reminder, a prefix of a string s is its substring which occurs at the beginning of s: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string a is alphabetically earlier than a string b, if a is a prefix of b, or a and b coincide up to some position, and then a has a letter that is alphabetically earlier than the corresponding letter in b: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac". Input The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive. Output Output a single string β€” alphabetically earliest possible login formed from these names. The output should be given in lowercase as well. Examples Input harry potter Output hap Input tom riddle Output tomr Tags: brute force, greedy, sortings Correct Solution: ``` # May the Speedforce be with us... ''' for _ in range(int(input())): arr=list(map(int,input().split())) n,k=map(int,input().split()) n=int(input()) s=input() from collections import defaultdict d=defaultdict() d=dict() s=set() s.intersection() s.union() s.difference() problem statement achhe se padhna hai age se bhi dekhna hai, piche se bhi dekhna hai ''' from math import gcd,ceil from collections import defaultdict as dd def lcm(a,b): return (a*b)//gcd(a,b) def inin(): return int(input()) def inar(): return list(map(int,input().split())) def ar(element,size): return [element for i in range(size)] def digitsum(num): su=0 while(num): su+=num%10 num//=10 return su n,t=input().split() title=t[0] ans=n[0] for i in n[1:]: if i>=title: break ans+=i ans+=title print(ans) ```
11,355
Provide tags and a correct Python 3 solution for this coding contest problem. The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person. You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users). As a reminder, a prefix of a string s is its substring which occurs at the beginning of s: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string a is alphabetically earlier than a string b, if a is a prefix of b, or a and b coincide up to some position, and then a has a letter that is alphabetically earlier than the corresponding letter in b: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac". Input The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive. Output Output a single string β€” alphabetically earliest possible login formed from these names. The output should be given in lowercase as well. Examples Input harry potter Output hap Input tom riddle Output tomr Tags: brute force, greedy, sortings Correct Solution: ``` s = input() n, f = s.split(' ') s=n[0] i=1 while i < len(n) and n[i] < f[0]: s += n[i] i+=1 print(s+f[0]) ```
11,356
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person. You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users). As a reminder, a prefix of a string s is its substring which occurs at the beginning of s: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string a is alphabetically earlier than a string b, if a is a prefix of b, or a and b coincide up to some position, and then a has a letter that is alphabetically earlier than the corresponding letter in b: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac". Input The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive. Output Output a single string β€” alphabetically earliest possible login formed from these names. The output should be given in lowercase as well. Examples Input harry potter Output hap Input tom riddle Output tomr Submitted Solution: ``` s1, s2 = input().split() i = 1 print(s1[0],end='') while i< len(s1) and s2[0] > s1[i]: print(s1[i],end='') i+=1 print(s2[0]) ``` Yes
11,357
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person. You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users). As a reminder, a prefix of a string s is its substring which occurs at the beginning of s: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string a is alphabetically earlier than a string b, if a is a prefix of b, or a and b coincide up to some position, and then a has a letter that is alphabetically earlier than the corresponding letter in b: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac". Input The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive. Output Output a single string β€” alphabetically earliest possible login formed from these names. The output should be given in lowercase as well. Examples Input harry potter Output hap Input tom riddle Output tomr Submitted Solution: ``` #list(map(int,input().split())) #list(input().strip().split()) arr=list(input().strip().split()) s1=arr[0] s2=arr[1] ans=[s1[0]] k=1 while k<len(s1): if s1[k]>=s2[0]: break ans.append(s1[k]) k+=1 ans.append(s2[0]) print("".join(ans)) ``` Yes
11,358
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person. You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users). As a reminder, a prefix of a string s is its substring which occurs at the beginning of s: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string a is alphabetically earlier than a string b, if a is a prefix of b, or a and b coincide up to some position, and then a has a letter that is alphabetically earlier than the corresponding letter in b: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac". Input The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive. Output Output a single string β€” alphabetically earliest possible login formed from these names. The output should be given in lowercase as well. Examples Input harry potter Output hap Input tom riddle Output tomr Submitted Solution: ``` a, b = input().split(' ') for i in a[1:]: if i >= b[0]: i = a.find(i) break else: i = None # print(i) if i == 0: print(a[0],b[0], sep='') else: print(a[:i], b[0], sep='') ``` Yes
11,359
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person. You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users). As a reminder, a prefix of a string s is its substring which occurs at the beginning of s: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string a is alphabetically earlier than a string b, if a is a prefix of b, or a and b coincide up to some position, and then a has a letter that is alphabetically earlier than the corresponding letter in b: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac". Input The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive. Output Output a single string β€” alphabetically earliest possible login formed from these names. The output should be given in lowercase as well. Examples Input harry potter Output hap Input tom riddle Output tomr Submitted Solution: ``` a,b=input().split() s=[] for i in range(1,len(a)+1): for j in range(1,len(b)+1): s.append(a[:i]+b[:j]) s.sort() print(s[0]) ``` Yes
11,360
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person. You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users). As a reminder, a prefix of a string s is its substring which occurs at the beginning of s: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string a is alphabetically earlier than a string b, if a is a prefix of b, or a and b coincide up to some position, and then a has a letter that is alphabetically earlier than the corresponding letter in b: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac". Input The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive. Output Output a single string β€” alphabetically earliest possible login formed from these names. The output should be given in lowercase as well. Examples Input harry potter Output hap Input tom riddle Output tomr Submitted Solution: ``` #909A p,s = input().split(" ") l = p[0] for i in p[1:]: if i > s[0]: break else: l += i print(l + s[0]) ``` No
11,361
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person. You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users). As a reminder, a prefix of a string s is its substring which occurs at the beginning of s: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string a is alphabetically earlier than a string b, if a is a prefix of b, or a and b coincide up to some position, and then a has a letter that is alphabetically earlier than the corresponding letter in b: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac". Input The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive. Output Output a single string β€” alphabetically earliest possible login formed from these names. The output should be given in lowercase as well. Examples Input harry potter Output hap Input tom riddle Output tomr Submitted Solution: ``` f,l = input().split(' ') ans ='' ans+=f[0] i = 1 j = 0 while(True): if(i==len(f)): ans+=l[j] break x = ord(f[i]) y = ord(l[j]) if(x<=y): ans+=f[i] i+=1 else: ans+=l[j] break print(ans) ``` No
11,362
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person. You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users). As a reminder, a prefix of a string s is its substring which occurs at the beginning of s: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string a is alphabetically earlier than a string b, if a is a prefix of b, or a and b coincide up to some position, and then a has a letter that is alphabetically earlier than the corresponding letter in b: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac". Input The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive. Output Output a single string β€” alphabetically earliest possible login formed from these names. The output should be given in lowercase as well. Examples Input harry potter Output hap Input tom riddle Output tomr Submitted Solution: ``` s1,s2 = input().split() s3 = s1[0] i = 1 j = 0 while i<len(s1) and j <len(s2): if s1[i]<s2[j]: s3 += s1[i] i+=1 else: s3+=s2[j] break if j ==0 : s3+=s2[j] print(s3) ``` No
11,363
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person. You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users). As a reminder, a prefix of a string s is its substring which occurs at the beginning of s: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string a is alphabetically earlier than a string b, if a is a prefix of b, or a and b coincide up to some position, and then a has a letter that is alphabetically earlier than the corresponding letter in b: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac". Input The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive. Output Output a single string β€” alphabetically earliest possible login formed from these names. The output should be given in lowercase as well. Examples Input harry potter Output hap Input tom riddle Output tomr Submitted Solution: ``` n = input().strip().split() minVal = n[0][0] index = 0 for i in range(1, len(n[0])): if ord(n[0][i]) < ord(minVal): minVal = n[0][i] index = i output = '' for j in range(index + 1): output += n[0][j] output += n[1][0] print(output) ``` No
11,364
Provide tags and a correct Python 3 solution for this coding contest problem. Young Teodor enjoys drawing. His favourite hobby is drawing segments with integer borders inside his huge [1;m] segment. One day Teodor noticed that picture he just drawn has one interesting feature: there doesn't exist an integer point, that belongs each of segments in the picture. Having discovered this fact, Teodor decided to share it with Sasha. Sasha knows that Teodor likes to show off so he never trusts him. Teodor wants to prove that he can be trusted sometimes, so he decided to convince Sasha that there is no such integer point in his picture, which belongs to each segment. However Teodor is lazy person and neither wills to tell Sasha all coordinates of segments' ends nor wills to tell him their amount, so he suggested Sasha to ask him series of questions 'Given the integer point xi, how many segments in Fedya's picture contain that point?', promising to tell correct answers for this questions. Both boys are very busy studying and don't have much time, so they ask you to find out how many questions can Sasha ask Teodor, that having only answers on his questions, Sasha can't be sure that Teodor isn't lying to him. Note that Sasha doesn't know amount of segments in Teodor's picture. Sure, Sasha is smart person and never asks about same point twice. Input First line of input contains two integer numbers: n and m (1 ≀ n, m ≀ 100 000) β€” amount of segments of Teodor's picture and maximal coordinate of point that Sasha can ask about. ith of next n lines contains two integer numbers li and ri (1 ≀ li ≀ ri ≀ m) β€” left and right ends of ith segment in the picture. Note that that left and right ends of segment can be the same point. It is guaranteed that there is no integer point, that belongs to all segments. Output Single line of output should contain one integer number k – size of largest set (xi, cnt(xi)) where all xi are different, 1 ≀ xi ≀ m, and cnt(xi) is amount of segments, containing point with coordinate xi, such that one can't be sure that there doesn't exist point, belonging to all of segments in initial picture, if he knows only this set(and doesn't know n). Examples Input 2 4 1 2 3 4 Output 4 Input 4 6 1 3 2 3 4 6 5 6 Output 5 Note First example shows situation where Sasha can never be sure that Teodor isn't lying to him, because even if one knows cnt(xi) for each point in segment [1;4], he can't distinguish this case from situation Teodor has drawn whole [1;4] segment. In second example Sasha can ask about 5 points e.g. 1, 2, 3, 5, 6, still not being sure if Teodor haven't lied to him. But once he knows information about all points in [1;6] segment, Sasha can be sure that Teodor haven't lied to him. Tags: data structures, dp Correct Solution: ``` # ---------------------------iye ha aam zindegi--------------------------------------------- import math import random import heapq, bisect import sys from collections import deque, defaultdict from fractions import Fraction import sys import threading from collections import defaultdict #threading.stack_size(10**8) mod = 10 ** 9 + 7 mod1 = 998244353 # ------------------------------warmup---------------------------- import os import sys from io import BytesIO, IOBase #sys.setrecursionlimit(300000) BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # -------------------game starts now----------------------------------------------------import math class TreeNode: def __init__(self, k, v): self.key = k self.value = v self.left = None self.right = None self.parent = None self.height = 1 self.num_left = 1 self.num_total = 1 class AvlTree: def __init__(self): self._tree = None def add(self, k, v): if not self._tree: self._tree = TreeNode(k, v) return node = self._add(k, v) if node: self._rebalance(node) def _add(self, k, v): node = self._tree while node: if k < node.key: if node.left: node = node.left else: node.left = TreeNode(k, v) node.left.parent = node return node.left elif node.key < k: if node.right: node = node.right else: node.right = TreeNode(k, v) node.right.parent = node return node.right else: node.value = v return @staticmethod def get_height(x): return x.height if x else 0 @staticmethod def get_num_total(x): return x.num_total if x else 0 def _rebalance(self, node): n = node while n: lh = self.get_height(n.left) rh = self.get_height(n.right) n.height = max(lh, rh) + 1 balance_factor = lh - rh n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right) n.num_left = 1 + self.get_num_total(n.left) if balance_factor > 1: if self.get_height(n.left.left) < self.get_height(n.left.right): self._rotate_left(n.left) self._rotate_right(n) elif balance_factor < -1: if self.get_height(n.right.right) < self.get_height(n.right.left): self._rotate_right(n.right) self._rotate_left(n) else: n = n.parent def _remove_one(self, node): """ Side effect!!! Changes node. Node should have exactly one child """ replacement = node.left or node.right if node.parent: if AvlTree._is_left(node): node.parent.left = replacement else: node.parent.right = replacement replacement.parent = node.parent node.parent = None else: self._tree = replacement replacement.parent = None node.left = None node.right = None node.parent = None self._rebalance(replacement) def _remove_leaf(self, node): if node.parent: if AvlTree._is_left(node): node.parent.left = None else: node.parent.right = None self._rebalance(node.parent) else: self._tree = None node.parent = None node.left = None node.right = None def remove(self, k): node = self._get_node(k) if not node: return if AvlTree._is_leaf(node): self._remove_leaf(node) return if node.left and node.right: nxt = AvlTree._get_next(node) node.key = nxt.key node.value = nxt.value if self._is_leaf(nxt): self._remove_leaf(nxt) else: self._remove_one(nxt) self._rebalance(node) else: self._remove_one(node) def get(self, k): node = self._get_node(k) return node.value if node else -1 def _get_node(self, k): if not self._tree: return None node = self._tree while node: if k < node.key: node = node.left elif node.key < k: node = node.right else: return node return None def get_at(self, pos): x = pos + 1 node = self._tree while node: if x < node.num_left: node = node.left elif node.num_left < x: x -= node.num_left node = node.right else: return (node.key, node.value) raise IndexError("Out of ranges") @staticmethod def _is_left(node): return node.parent.left and node.parent.left == node @staticmethod def _is_leaf(node): return node.left is None and node.right is None def _rotate_right(self, node): if not node.parent: self._tree = node.left node.left.parent = None elif AvlTree._is_left(node): node.parent.left = node.left node.left.parent = node.parent else: node.parent.right = node.left node.left.parent = node.parent bk = node.left.right node.left.right = node node.parent = node.left node.left = bk if bk: bk.parent = node node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1 node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right) node.num_left = 1 + self.get_num_total(node.left) def _rotate_left(self, node): if not node.parent: self._tree = node.right node.right.parent = None elif AvlTree._is_left(node): node.parent.left = node.right node.right.parent = node.parent else: node.parent.right = node.right node.right.parent = node.parent bk = node.right.left node.right.left = node node.parent = node.right node.right = bk if bk: bk.parent = node node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1 node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right) node.num_left = 1 + self.get_num_total(node.left) @staticmethod def _get_next(node): if not node.right: return node.parent n = node.right while n.left: n = n.left return n # -----------------------------------------------binary seacrh tree--------------------------------------- class SegmentTree1: def __init__(self, data, default=2**51, func=lambda a, b: a & b): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) # -------------------game starts now----------------------------------------------------import math class SegmentTree: def __init__(self, data, default=0, func=lambda a, b: max(a , b)): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) # -------------------------------iye ha chutiya zindegi------------------------------------- class Factorial: def __init__(self, MOD): self.MOD = MOD self.factorials = [1, 1] self.invModulos = [0, 1] self.invFactorial_ = [1, 1] def calc(self, n): if n <= -1: print("Invalid argument to calculate n!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.factorials): return self.factorials[n] nextArr = [0] * (n + 1 - len(self.factorials)) initialI = len(self.factorials) prev = self.factorials[-1] m = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = prev * i % m self.factorials += nextArr return self.factorials[n] def inv(self, n): if n <= -1: print("Invalid argument to calculate n^(-1)") print("n must be non-negative value. But the argument was " + str(n)) exit() p = self.MOD pi = n % p if pi < len(self.invModulos): return self.invModulos[pi] nextArr = [0] * (n + 1 - len(self.invModulos)) initialI = len(self.invModulos) for i in range(initialI, min(p, n + 1)): next = -self.invModulos[p % i] * (p // i) % p self.invModulos.append(next) return self.invModulos[pi] def invFactorial(self, n): if n <= -1: print("Invalid argument to calculate (n^(-1))!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.invFactorial_): return self.invFactorial_[n] self.inv(n) # To make sure already calculated n^-1 nextArr = [0] * (n + 1 - len(self.invFactorial_)) initialI = len(self.invFactorial_) prev = self.invFactorial_[-1] p = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p self.invFactorial_ += nextArr return self.invFactorial_[n] class Combination: def __init__(self, MOD): self.MOD = MOD self.factorial = Factorial(MOD) def ncr(self, n, k): if k < 0 or n < k: return 0 k = min(k, n - k) f = self.factorial return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD # --------------------------------------iye ha combinations ka zindegi--------------------------------- def powm(a, n, m): if a == 1 or n == 0: return 1 if n % 2 == 0: s = powm(a, n // 2, m) return s * s % m else: return a * powm(a, n - 1, m) % m # --------------------------------------iye ha power ka zindegi--------------------------------- def sort_list(list1, list2): zipped_pairs = zip(list2, list1) z = [x for _, x in sorted(zipped_pairs)] return z # --------------------------------------------------product---------------------------------------- def product(l): por = 1 for i in range(len(l)): por *= l[i] return por # --------------------------------------------------binary---------------------------------------- def binarySearchCount(arr, n, key): left = 0 right = n - 1 count = 0 while (left <= right): mid = int((right + left) / 2) # Check if middle element is # less than or equal to key if (arr[mid] < key): count = mid + 1 left = mid + 1 # If key is smaller, ignore right half else: right = mid - 1 return count # --------------------------------------------------binary---------------------------------------- def countdig(n): c = 0 while (n > 0): n //= 10 c += 1 return c def binary(x, length): y = bin(x)[2:] return y if len(y) >= length else "0" * (length - len(y)) + y def countGreater(arr, n, k): l = 0 r = n - 1 # Stores the index of the left most element # from the array which is greater than k leftGreater = n # Finds number of elements greater than k while (l <= r): m = int(l + (r - l) / 2) if (arr[m] >= k): leftGreater = m r = m - 1 # If mid element is less than # or equal to k update l else: l = m + 1 # Return the count of elements # greater than k return (n - leftGreater) # --------------------------------------------------binary------------------------------------ n,m=map(int,input().split()) cnt=[0]*(m+1) for i in range(n): a,b=map(int,input().split()) cnt[a-1]+=1 cnt[b]-=1 for i in range(1,m+1): cnt[i]+=cnt[i-1] l=[0]*(m) l1=[0]*(m) cnt=[(cnt[i],i) for i in range(m)] cnt.sort() ind=defaultdict(int) for i in range(len(cnt)): ind[cnt[i][1]]=i s=SegmentTree(l) s1=SegmentTree(l1) cou=[0]*m cur=0 cur1=0 fi=[0]*m #print(cnt,ind) for i in range(m): mw=s.query(0,ind[i])+1 #print(mw) l[ind[i]]=mw fi[i]=mw cur1=max(cur1,mw) s.__setitem__(ind[i],mw) #print(fi) cnt=[(cnt[i][0],-cnt[i][1]) for i in range(m)] cnt.sort() cnt=[(cnt[i][0],-cnt[i][1]) for i in range(m)] for i in range(len(cnt)): ind[cnt[i][1]]=i #print(cnt,ind) for i in range(m-1,-1,-1): mw=s1.query(0,ind[i])+1 #print(mw) fi[i]+=mw l1[ind[i]]=mw s1.__setitem__(ind[i],mw) print(max(fi)-1) ```
11,365
Provide tags and a correct Python 3 solution for this coding contest problem. The Rebel fleet is on the run. It consists of m ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same solar system, and the Rebels will need to escape into hyperspace. In order to spread the fleet, the captain of each ship has independently come up with the coordinate to which that ship will jump. In the obsolete navigation system used by the Rebels, this coordinate is given as the value of an arithmetic expression of the form <image>. To plan the future of the resistance movement, Princess Heidi needs to know, for each ship, how many ships are going to end up at the same coordinate after the jump. You are her only hope! Input The first line of the input contains a single integer m (1 ≀ m ≀ 200 000) – the number of ships. The next m lines describe one jump coordinate each, given as an arithmetic expression. An expression has the form (a+b)/c. Namely, it consists of: an opening parenthesis (, a positive integer a of up to two decimal digits, a plus sign +, a positive integer b of up to two decimal digits, a closing parenthesis ), a slash /, and a positive integer c of up to two decimal digits. Output Print a single line consisting of m space-separated integers. The i-th integer should be equal to the number of ships whose coordinate is equal to that of the i-th ship (including the i-th ship itself). Example Input 4 (99+98)/97 (26+4)/10 (12+33)/15 (5+1)/7 Output 1 2 2 1 Note In the sample testcase, the second and the third ship will both end up at the coordinate 3. Note that this problem has only two versions – easy and hard. Tags: expression parsing, math Correct Solution: ``` m=int(input()) ans=[] f={} for _ in range(m): n=input() a=n.split('(') b=a[1].split(')') ad,bd=b[0].split('+') cd=b[1].split('/')[1] ans.append((int(ad)+int(bd))/int(cd)) f[_]=(int(ad)+int(bd))/int(cd) freq = {} for item in ans: if (item in freq): freq[item] += 1 else: freq[item] = 1 for i in range(m): print(freq[f[i]],end=" ") ```
11,366
Provide tags and a correct Python 3 solution for this coding contest problem. The Rebel fleet is on the run. It consists of m ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same solar system, and the Rebels will need to escape into hyperspace. In order to spread the fleet, the captain of each ship has independently come up with the coordinate to which that ship will jump. In the obsolete navigation system used by the Rebels, this coordinate is given as the value of an arithmetic expression of the form <image>. To plan the future of the resistance movement, Princess Heidi needs to know, for each ship, how many ships are going to end up at the same coordinate after the jump. You are her only hope! Input The first line of the input contains a single integer m (1 ≀ m ≀ 200 000) – the number of ships. The next m lines describe one jump coordinate each, given as an arithmetic expression. An expression has the form (a+b)/c. Namely, it consists of: an opening parenthesis (, a positive integer a of up to two decimal digits, a plus sign +, a positive integer b of up to two decimal digits, a closing parenthesis ), a slash /, and a positive integer c of up to two decimal digits. Output Print a single line consisting of m space-separated integers. The i-th integer should be equal to the number of ships whose coordinate is equal to that of the i-th ship (including the i-th ship itself). Example Input 4 (99+98)/97 (26+4)/10 (12+33)/15 (5+1)/7 Output 1 2 2 1 Note In the sample testcase, the second and the third ship will both end up at the coordinate 3. Note that this problem has only two versions – easy and hard. Tags: expression parsing, math Correct Solution: ``` import collections def compute_coorinate(data): return eval(data) if __name__ == "__main__": m = int(input()) coordinates = [] for i in range(m): coordinates.append(compute_coorinate(input())) numbers = collections.Counter(coordinates) print(" ".join(str(numbers[x]) for x in coordinates)) ```
11,367
Provide tags and a correct Python 3 solution for this coding contest problem. The Rebel fleet is on the run. It consists of m ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same solar system, and the Rebels will need to escape into hyperspace. In order to spread the fleet, the captain of each ship has independently come up with the coordinate to which that ship will jump. In the obsolete navigation system used by the Rebels, this coordinate is given as the value of an arithmetic expression of the form <image>. To plan the future of the resistance movement, Princess Heidi needs to know, for each ship, how many ships are going to end up at the same coordinate after the jump. You are her only hope! Input The first line of the input contains a single integer m (1 ≀ m ≀ 200 000) – the number of ships. The next m lines describe one jump coordinate each, given as an arithmetic expression. An expression has the form (a+b)/c. Namely, it consists of: an opening parenthesis (, a positive integer a of up to two decimal digits, a plus sign +, a positive integer b of up to two decimal digits, a closing parenthesis ), a slash /, and a positive integer c of up to two decimal digits. Output Print a single line consisting of m space-separated integers. The i-th integer should be equal to the number of ships whose coordinate is equal to that of the i-th ship (including the i-th ship itself). Example Input 4 (99+98)/97 (26+4)/10 (12+33)/15 (5+1)/7 Output 1 2 2 1 Note In the sample testcase, the second and the third ship will both end up at the coordinate 3. Note that this problem has only two versions – easy and hard. Tags: expression parsing, math Correct Solution: ``` from collections import defaultdict d = defaultdict(lambda : 0) a = [] for _ in range(int(input())): s = input() a.append(s) d[eval(s)] += 1 for e in a: print(d[eval(e)], end = ' ') ```
11,368
Provide tags and a correct Python 3 solution for this coding contest problem. The Rebel fleet is on the run. It consists of m ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same solar system, and the Rebels will need to escape into hyperspace. In order to spread the fleet, the captain of each ship has independently come up with the coordinate to which that ship will jump. In the obsolete navigation system used by the Rebels, this coordinate is given as the value of an arithmetic expression of the form <image>. To plan the future of the resistance movement, Princess Heidi needs to know, for each ship, how many ships are going to end up at the same coordinate after the jump. You are her only hope! Input The first line of the input contains a single integer m (1 ≀ m ≀ 200 000) – the number of ships. The next m lines describe one jump coordinate each, given as an arithmetic expression. An expression has the form (a+b)/c. Namely, it consists of: an opening parenthesis (, a positive integer a of up to two decimal digits, a plus sign +, a positive integer b of up to two decimal digits, a closing parenthesis ), a slash /, and a positive integer c of up to two decimal digits. Output Print a single line consisting of m space-separated integers. The i-th integer should be equal to the number of ships whose coordinate is equal to that of the i-th ship (including the i-th ship itself). Example Input 4 (99+98)/97 (26+4)/10 (12+33)/15 (5+1)/7 Output 1 2 2 1 Note In the sample testcase, the second and the third ship will both end up at the coordinate 3. Note that this problem has only two versions – easy and hard. Tags: expression parsing, math Correct Solution: ``` from collections import defaultdict m = int(input()) value = {} count = defaultdict(int) for i in range(m): s = input() ans = 0 z = "" n = len(s) for j in range(1,n): if s[j]=='+': ans = int(z) z = "" continue elif s[j]==')': ans +=int(z) z = "" j+=2 while j<n: z+=s[j] j+=1 ans = ans/int(z) count[ans]+=1 value[i] = ans else: z = z+s[j] for i in range(m): print(count[value[i]],end=" ") print() ```
11,369
Provide tags and a correct Python 3 solution for this coding contest problem. The Rebel fleet is on the run. It consists of m ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same solar system, and the Rebels will need to escape into hyperspace. In order to spread the fleet, the captain of each ship has independently come up with the coordinate to which that ship will jump. In the obsolete navigation system used by the Rebels, this coordinate is given as the value of an arithmetic expression of the form <image>. To plan the future of the resistance movement, Princess Heidi needs to know, for each ship, how many ships are going to end up at the same coordinate after the jump. You are her only hope! Input The first line of the input contains a single integer m (1 ≀ m ≀ 200 000) – the number of ships. The next m lines describe one jump coordinate each, given as an arithmetic expression. An expression has the form (a+b)/c. Namely, it consists of: an opening parenthesis (, a positive integer a of up to two decimal digits, a plus sign +, a positive integer b of up to two decimal digits, a closing parenthesis ), a slash /, and a positive integer c of up to two decimal digits. Output Print a single line consisting of m space-separated integers. The i-th integer should be equal to the number of ships whose coordinate is equal to that of the i-th ship (including the i-th ship itself). Example Input 4 (99+98)/97 (26+4)/10 (12+33)/15 (5+1)/7 Output 1 2 2 1 Note In the sample testcase, the second and the third ship will both end up at the coordinate 3. Note that this problem has only two versions – easy and hard. Tags: expression parsing, math Correct Solution: ``` arr = [] d = {} for _ in range(int(input())): s = input() a,b,c = tuple(map(int, s.replace("(","").replace(")","").replace("/",".").replace("+",".").split("."))) x = (a+b)/c arr.append(x) if x not in d: d[x] = 0 d[x] += 1 for i in arr: print(d[i], end = " ") ```
11,370
Provide tags and a correct Python 3 solution for this coding contest problem. The Rebel fleet is on the run. It consists of m ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same solar system, and the Rebels will need to escape into hyperspace. In order to spread the fleet, the captain of each ship has independently come up with the coordinate to which that ship will jump. In the obsolete navigation system used by the Rebels, this coordinate is given as the value of an arithmetic expression of the form <image>. To plan the future of the resistance movement, Princess Heidi needs to know, for each ship, how many ships are going to end up at the same coordinate after the jump. You are her only hope! Input The first line of the input contains a single integer m (1 ≀ m ≀ 200 000) – the number of ships. The next m lines describe one jump coordinate each, given as an arithmetic expression. An expression has the form (a+b)/c. Namely, it consists of: an opening parenthesis (, a positive integer a of up to two decimal digits, a plus sign +, a positive integer b of up to two decimal digits, a closing parenthesis ), a slash /, and a positive integer c of up to two decimal digits. Output Print a single line consisting of m space-separated integers. The i-th integer should be equal to the number of ships whose coordinate is equal to that of the i-th ship (including the i-th ship itself). Example Input 4 (99+98)/97 (26+4)/10 (12+33)/15 (5+1)/7 Output 1 2 2 1 Note In the sample testcase, the second and the third ship will both end up at the coordinate 3. Note that this problem has only two versions – easy and hard. Tags: expression parsing, math Correct Solution: ``` from collections import Counter def getList(l, m): r = [] cnt = Counter(l) for i in l: r.extend([cnt[i]]) return r m = int(input()) res = [] for i in range(m): a, b = [i for i in input().split("/")] a = a.split("+") a = [a[0].replace("(", ""), a[len(a) - 1].replace(")", "")] a = list(map(lambda x: int(x), a)); b = float(b) res.extend([sum(a)/b]) output = getList(res, m) + ["\n"] for i in output: print(str(i) + " ", end = "") ```
11,371
Provide tags and a correct Python 3 solution for this coding contest problem. The Rebel fleet is on the run. It consists of m ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same solar system, and the Rebels will need to escape into hyperspace. In order to spread the fleet, the captain of each ship has independently come up with the coordinate to which that ship will jump. In the obsolete navigation system used by the Rebels, this coordinate is given as the value of an arithmetic expression of the form <image>. To plan the future of the resistance movement, Princess Heidi needs to know, for each ship, how many ships are going to end up at the same coordinate after the jump. You are her only hope! Input The first line of the input contains a single integer m (1 ≀ m ≀ 200 000) – the number of ships. The next m lines describe one jump coordinate each, given as an arithmetic expression. An expression has the form (a+b)/c. Namely, it consists of: an opening parenthesis (, a positive integer a of up to two decimal digits, a plus sign +, a positive integer b of up to two decimal digits, a closing parenthesis ), a slash /, and a positive integer c of up to two decimal digits. Output Print a single line consisting of m space-separated integers. The i-th integer should be equal to the number of ships whose coordinate is equal to that of the i-th ship (including the i-th ship itself). Example Input 4 (99+98)/97 (26+4)/10 (12+33)/15 (5+1)/7 Output 1 2 2 1 Note In the sample testcase, the second and the third ship will both end up at the coordinate 3. Note that this problem has only two versions – easy and hard. Tags: expression parsing, math Correct Solution: ``` from collections import defaultdict from sys import stdin input = stdin.readline dct = defaultdict(int) n = int(input()) lst = [0] * n for i in range(n): t = input().strip() a, b, c = map(int, (t[1:t.index('+')], t[t.index('+') + 1:t.index(')')], t[t.index('/') + 1:])) x = (a + b) / c lst[i] = x dct[x] += 1 for i in lst: print(dct[i], end=' ') ```
11,372
Provide tags and a correct Python 3 solution for this coding contest problem. The Rebel fleet is on the run. It consists of m ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same solar system, and the Rebels will need to escape into hyperspace. In order to spread the fleet, the captain of each ship has independently come up with the coordinate to which that ship will jump. In the obsolete navigation system used by the Rebels, this coordinate is given as the value of an arithmetic expression of the form <image>. To plan the future of the resistance movement, Princess Heidi needs to know, for each ship, how many ships are going to end up at the same coordinate after the jump. You are her only hope! Input The first line of the input contains a single integer m (1 ≀ m ≀ 200 000) – the number of ships. The next m lines describe one jump coordinate each, given as an arithmetic expression. An expression has the form (a+b)/c. Namely, it consists of: an opening parenthesis (, a positive integer a of up to two decimal digits, a plus sign +, a positive integer b of up to two decimal digits, a closing parenthesis ), a slash /, and a positive integer c of up to two decimal digits. Output Print a single line consisting of m space-separated integers. The i-th integer should be equal to the number of ships whose coordinate is equal to that of the i-th ship (including the i-th ship itself). Example Input 4 (99+98)/97 (26+4)/10 (12+33)/15 (5+1)/7 Output 1 2 2 1 Note In the sample testcase, the second and the third ship will both end up at the coordinate 3. Note that this problem has only two versions – easy and hard. Tags: expression parsing, math Correct Solution: ``` n = int(input()) cl = [] dic = {} res = [0]*n for i in range(n): x = eval(input()) if x not in dic.keys(): dic.update({x:[]}) dic[x].append(i) else: dic[x].append(i) for x in dic.values(): k = len(x) for y in x: res[y]=k result = '' for x in res: result+=str(x)+' ' print(result) ```
11,373
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Rebel fleet is on the run. It consists of m ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same solar system, and the Rebels will need to escape into hyperspace. In order to spread the fleet, the captain of each ship has independently come up with the coordinate to which that ship will jump. In the obsolete navigation system used by the Rebels, this coordinate is given as the value of an arithmetic expression of the form <image>. To plan the future of the resistance movement, Princess Heidi needs to know, for each ship, how many ships are going to end up at the same coordinate after the jump. You are her only hope! Input The first line of the input contains a single integer m (1 ≀ m ≀ 200 000) – the number of ships. The next m lines describe one jump coordinate each, given as an arithmetic expression. An expression has the form (a+b)/c. Namely, it consists of: an opening parenthesis (, a positive integer a of up to two decimal digits, a plus sign +, a positive integer b of up to two decimal digits, a closing parenthesis ), a slash /, and a positive integer c of up to two decimal digits. Output Print a single line consisting of m space-separated integers. The i-th integer should be equal to the number of ships whose coordinate is equal to that of the i-th ship (including the i-th ship itself). Example Input 4 (99+98)/97 (26+4)/10 (12+33)/15 (5+1)/7 Output 1 2 2 1 Note In the sample testcase, the second and the third ship will both end up at the coordinate 3. Note that this problem has only two versions – easy and hard. Submitted Solution: ``` n = int(input()) l=[] dic={} while(n>0): s=input() coord= eval(s) l.append(coord) dic[coord]=dic.get(coord,0) + 1 n-=1 new_list = [ dic[coord] for coord in l ] print(*new_list,sep =" ") ``` Yes
11,374
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Rebel fleet is on the run. It consists of m ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same solar system, and the Rebels will need to escape into hyperspace. In order to spread the fleet, the captain of each ship has independently come up with the coordinate to which that ship will jump. In the obsolete navigation system used by the Rebels, this coordinate is given as the value of an arithmetic expression of the form <image>. To plan the future of the resistance movement, Princess Heidi needs to know, for each ship, how many ships are going to end up at the same coordinate after the jump. You are her only hope! Input The first line of the input contains a single integer m (1 ≀ m ≀ 200 000) – the number of ships. The next m lines describe one jump coordinate each, given as an arithmetic expression. An expression has the form (a+b)/c. Namely, it consists of: an opening parenthesis (, a positive integer a of up to two decimal digits, a plus sign +, a positive integer b of up to two decimal digits, a closing parenthesis ), a slash /, and a positive integer c of up to two decimal digits. Output Print a single line consisting of m space-separated integers. The i-th integer should be equal to the number of ships whose coordinate is equal to that of the i-th ship (including the i-th ship itself). Example Input 4 (99+98)/97 (26+4)/10 (12+33)/15 (5+1)/7 Output 1 2 2 1 Note In the sample testcase, the second and the third ship will both end up at the coordinate 3. Note that this problem has only two versions – easy and hard. Submitted Solution: ``` """ Satwik_Tiwari ;) . 4th july , 2020 - Saturday """ #=============================================================================================== #importing some useful libraries. from __future__ import division, print_function from fractions import Fraction import sys import os from io import BytesIO, IOBase import bisect from heapq import * from math import * from collections import deque 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 #If the element is already present in the list, # the left most position where element has to be inserted is returned. from bisect import bisect_right as br from bisect import bisect #If the element is already present in the list, # the right most position where element has to be inserted is returned #============================================================================================== BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") def print(*args, **kwargs): """Prints the values to a stream, or to sys.stdout by default.""" sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout) at_start = True for x in args: if not at_start: file.write(sep) file.write(str(x)) at_start = False file.write(kwargs.pop("end", "\n")) if kwargs.pop("flush", False): file.flush() if sys.version_info[0] < 3: sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout) else: sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) # inp = lambda: sys.stdin.readline().rstrip("\r\n") #=============================================================================================== #some shortcuts mod = 1000000007 def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input def out(var): sys.stdout.write(str(var)) #for fast output, always take string def lis(): return list(map(int, inp().split())) def stringlis(): return list(map(str, inp().split())) def sep(): return map(int, inp().split()) def strsep(): return map(str, inp().split()) # def 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) def power(a,b): ans = 1 while(b>0): if(b%2==1): ans*=a a*=a b//=2 return ans def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1))) def isPrime(n) : # Check Prime Number or not if (n <= 1) : return False if (n <= 3) : return True if (n % 2 == 0 or n % 3 == 0) : return False i = 5 while(i * i <= n) : if (n % i == 0 or n % (i + 2) == 0) : return False i = i + 6 return True #=============================================================================================== # code here ;)) def solve(): m = int(inp()) d = {} arr = [0]*(m) for i in range(0,m): s = list(inp()) plus = s.index('+') a = s[1:plus] b = s[plus+1:s.index(')')] c = s[s.index('/')+1:] a = ''.join(a) b = ''.join(b) c = ''.join(c) # print(a,b,c) co = (int(a)+int(b))/int(c) if(d.get(co) == None): d[co] = [i] else: d[co].append(i) arr[i] = co # print(arr) # print(d) ans = [] for i in range(m): ans.append(len(d[arr[i]])) print(' '.join(str(ans[i]) for i in range(len(ans)))) testcase(1) # testcase(int(inp())) ``` Yes
11,375
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Rebel fleet is on the run. It consists of m ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same solar system, and the Rebels will need to escape into hyperspace. In order to spread the fleet, the captain of each ship has independently come up with the coordinate to which that ship will jump. In the obsolete navigation system used by the Rebels, this coordinate is given as the value of an arithmetic expression of the form <image>. To plan the future of the resistance movement, Princess Heidi needs to know, for each ship, how many ships are going to end up at the same coordinate after the jump. You are her only hope! Input The first line of the input contains a single integer m (1 ≀ m ≀ 200 000) – the number of ships. The next m lines describe one jump coordinate each, given as an arithmetic expression. An expression has the form (a+b)/c. Namely, it consists of: an opening parenthesis (, a positive integer a of up to two decimal digits, a plus sign +, a positive integer b of up to two decimal digits, a closing parenthesis ), a slash /, and a positive integer c of up to two decimal digits. Output Print a single line consisting of m space-separated integers. The i-th integer should be equal to the number of ships whose coordinate is equal to that of the i-th ship (including the i-th ship itself). Example Input 4 (99+98)/97 (26+4)/10 (12+33)/15 (5+1)/7 Output 1 2 2 1 Note In the sample testcase, the second and the third ship will both end up at the coordinate 3. Note that this problem has only two versions – easy and hard. Submitted Solution: ``` d = {} l =[] for i in range(int(input())): a,b,c = map(int,input().replace("(","").replace(")/"," ").replace("+"," ").split()) ans = (a+b)/c l.append(ans) if ans in d: d[ans]+=1 else: d[ans]=1 for i in l: print(d[i],end=" ") ``` Yes
11,376
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Rebel fleet is on the run. It consists of m ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same solar system, and the Rebels will need to escape into hyperspace. In order to spread the fleet, the captain of each ship has independently come up with the coordinate to which that ship will jump. In the obsolete navigation system used by the Rebels, this coordinate is given as the value of an arithmetic expression of the form <image>. To plan the future of the resistance movement, Princess Heidi needs to know, for each ship, how many ships are going to end up at the same coordinate after the jump. You are her only hope! Input The first line of the input contains a single integer m (1 ≀ m ≀ 200 000) – the number of ships. The next m lines describe one jump coordinate each, given as an arithmetic expression. An expression has the form (a+b)/c. Namely, it consists of: an opening parenthesis (, a positive integer a of up to two decimal digits, a plus sign +, a positive integer b of up to two decimal digits, a closing parenthesis ), a slash /, and a positive integer c of up to two decimal digits. Output Print a single line consisting of m space-separated integers. The i-th integer should be equal to the number of ships whose coordinate is equal to that of the i-th ship (including the i-th ship itself). Example Input 4 (99+98)/97 (26+4)/10 (12+33)/15 (5+1)/7 Output 1 2 2 1 Note In the sample testcase, the second and the third ship will both end up at the coordinate 3. Note that this problem has only two versions – easy and hard. Submitted Solution: ``` m = int(input()) pos = dict() arr = list() for i in range(m): p = eval(input()) arr.append(p) if p in pos: pos[p] += 1 else: pos[p] = 1 for i in arr: print(pos[i]) ``` Yes
11,377
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Rebel fleet is on the run. It consists of m ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same solar system, and the Rebels will need to escape into hyperspace. In order to spread the fleet, the captain of each ship has independently come up with the coordinate to which that ship will jump. In the obsolete navigation system used by the Rebels, this coordinate is given as the value of an arithmetic expression of the form <image>. To plan the future of the resistance movement, Princess Heidi needs to know, for each ship, how many ships are going to end up at the same coordinate after the jump. You are her only hope! Input The first line of the input contains a single integer m (1 ≀ m ≀ 200 000) – the number of ships. The next m lines describe one jump coordinate each, given as an arithmetic expression. An expression has the form (a+b)/c. Namely, it consists of: an opening parenthesis (, a positive integer a of up to two decimal digits, a plus sign +, a positive integer b of up to two decimal digits, a closing parenthesis ), a slash /, and a positive integer c of up to two decimal digits. Output Print a single line consisting of m space-separated integers. The i-th integer should be equal to the number of ships whose coordinate is equal to that of the i-th ship (including the i-th ship itself). Example Input 4 (99+98)/97 (26+4)/10 (12+33)/15 (5+1)/7 Output 1 2 2 1 Note In the sample testcase, the second and the third ship will both end up at the coordinate 3. Note that this problem has only two versions – easy and hard. Submitted Solution: ``` from math import gcd import sys input=sys.stdin.readline from collections import defaultdict as dd m=int(input()) d=dd(int) l=[] for i in range(m): s=input().split()[0] a=0 b=0 c=0 n=len(s) ind=0 for i in range(1,n): if(s[i]=='+'): ind=i+1 break a=a*10+int(s[i]) for i in range(ind,n): if(s[i]==')'): ind1=i+2 break b=b*10+int(s[i]) for i in range(ind1,n): c=c*10+int(s[i]) a=a+b g=gcd(a,c) a=a//g c=c//g if(a>c): a,c=c,a d[(a,c)]+=1 l.append((a,c)) for i in l: print(d[i],end=" ") ``` No
11,378
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Rebel fleet is on the run. It consists of m ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same solar system, and the Rebels will need to escape into hyperspace. In order to spread the fleet, the captain of each ship has independently come up with the coordinate to which that ship will jump. In the obsolete navigation system used by the Rebels, this coordinate is given as the value of an arithmetic expression of the form <image>. To plan the future of the resistance movement, Princess Heidi needs to know, for each ship, how many ships are going to end up at the same coordinate after the jump. You are her only hope! Input The first line of the input contains a single integer m (1 ≀ m ≀ 200 000) – the number of ships. The next m lines describe one jump coordinate each, given as an arithmetic expression. An expression has the form (a+b)/c. Namely, it consists of: an opening parenthesis (, a positive integer a of up to two decimal digits, a plus sign +, a positive integer b of up to two decimal digits, a closing parenthesis ), a slash /, and a positive integer c of up to two decimal digits. Output Print a single line consisting of m space-separated integers. The i-th integer should be equal to the number of ships whose coordinate is equal to that of the i-th ship (including the i-th ship itself). Example Input 4 (99+98)/97 (26+4)/10 (12+33)/15 (5+1)/7 Output 1 2 2 1 Note In the sample testcase, the second and the third ship will both end up at the coordinate 3. Note that this problem has only two versions – easy and hard. Submitted Solution: ``` n = int(input()) l=[] dic={} while(n>0): s=input() q=s.split('/') c=int(q[1]) q[0]=q[0][1:-1] a_b=q[0].split('+') a=int(a_b[0]) b=int(a_b[1]) coord= (a+b) // c l.append(coord) dic[coord]=dic.get(coord,0) + 1 n-=1 new_list = [ dic[coord] for coord in l ] print(*new_list,sep =" ") ``` No
11,379
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Rebel fleet is on the run. It consists of m ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same solar system, and the Rebels will need to escape into hyperspace. In order to spread the fleet, the captain of each ship has independently come up with the coordinate to which that ship will jump. In the obsolete navigation system used by the Rebels, this coordinate is given as the value of an arithmetic expression of the form <image>. To plan the future of the resistance movement, Princess Heidi needs to know, for each ship, how many ships are going to end up at the same coordinate after the jump. You are her only hope! Input The first line of the input contains a single integer m (1 ≀ m ≀ 200 000) – the number of ships. The next m lines describe one jump coordinate each, given as an arithmetic expression. An expression has the form (a+b)/c. Namely, it consists of: an opening parenthesis (, a positive integer a of up to two decimal digits, a plus sign +, a positive integer b of up to two decimal digits, a closing parenthesis ), a slash /, and a positive integer c of up to two decimal digits. Output Print a single line consisting of m space-separated integers. The i-th integer should be equal to the number of ships whose coordinate is equal to that of the i-th ship (including the i-th ship itself). Example Input 4 (99+98)/97 (26+4)/10 (12+33)/15 (5+1)/7 Output 1 2 2 1 Note In the sample testcase, the second and the third ship will both end up at the coordinate 3. Note that this problem has only two versions – easy and hard. Submitted Solution: ``` n = int (input ()) l=[] d={} for i in range (n) : ch = input() c= int (eval(ch)) l.append(c) if (c in d ) : d[c]+=1 else : d[c]=1 for i in range ( n) : print (d[l[i]] ,end=" ") ``` No
11,380
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Rebel fleet is on the run. It consists of m ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same solar system, and the Rebels will need to escape into hyperspace. In order to spread the fleet, the captain of each ship has independently come up with the coordinate to which that ship will jump. In the obsolete navigation system used by the Rebels, this coordinate is given as the value of an arithmetic expression of the form <image>. To plan the future of the resistance movement, Princess Heidi needs to know, for each ship, how many ships are going to end up at the same coordinate after the jump. You are her only hope! Input The first line of the input contains a single integer m (1 ≀ m ≀ 200 000) – the number of ships. The next m lines describe one jump coordinate each, given as an arithmetic expression. An expression has the form (a+b)/c. Namely, it consists of: an opening parenthesis (, a positive integer a of up to two decimal digits, a plus sign +, a positive integer b of up to two decimal digits, a closing parenthesis ), a slash /, and a positive integer c of up to two decimal digits. Output Print a single line consisting of m space-separated integers. The i-th integer should be equal to the number of ships whose coordinate is equal to that of the i-th ship (including the i-th ship itself). Example Input 4 (99+98)/97 (26+4)/10 (12+33)/15 (5+1)/7 Output 1 2 2 1 Note In the sample testcase, the second and the third ship will both end up at the coordinate 3. Note that this problem has only two versions – easy and hard. Submitted Solution: ``` from collections import defaultdict m = int(input()) value = {} count = defaultdict(int) for i in range(m): s = input() ans = 0 z = "" n = len(s) for j in range(1,n): if s[j]=='+': ans = int(z) z = "" continue elif s[j]==')': ans +=int(z) z = "" j+=2 while j<n: z+=s[j] j+=1 ans = ans//int(z) count[ans]+=1 value[i] = ans else: z = z+s[j] for i in range(m): print(count[value[i]],end=" ") print() ``` No
11,381
Provide tags and a correct Python 3 solution for this coding contest problem. You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a fraction has zero numerals after the decimal point. Input The first line contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of queries. Next n lines contain queries, one per line. Each line contains three integers p, q, and b (0 ≀ p ≀ 10^{18}, 1 ≀ q ≀ 10^{18}, 2 ≀ b ≀ 10^{18}). All numbers are given in notation with base 10. Output For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise. Examples Input 2 6 12 10 4 3 10 Output Finite Infinite Input 4 1 1 2 9 36 2 4 12 3 3 5 4 Output Finite Finite Finite Infinite Note 6/12 = 1/2 = 0,5_{10} 4/3 = 1,(3)_{10} 9/36 = 1/4 = 0,01_2 4/12 = 1/3 = 0,1_3 Tags: implementation, math Correct Solution: ``` def mod(b, q): #computes b^k mod q for large k for i in range(6): b = (b * b) % q return b n = int(input()) s = '' for i in range(n - 1): p, q, b = list(map(int, input().split())) if (p * mod(b, q))%q: #checks if p * b^k is not divisible by q for large k s += 'Infinite\n' else: s += 'Finite\n' p, q, b = list(map(int, input().split())) if (p * mod(b, q))%q: #checks if p * b^k is not divisible by q for large k s += 'Infinite' else: s += 'Finite' print(s) ```
11,382
Provide tags and a correct Python 3 solution for this coding contest problem. You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a fraction has zero numerals after the decimal point. Input The first line contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of queries. Next n lines contain queries, one per line. Each line contains three integers p, q, and b (0 ≀ p ≀ 10^{18}, 1 ≀ q ≀ 10^{18}, 2 ≀ b ≀ 10^{18}). All numbers are given in notation with base 10. Output For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise. Examples Input 2 6 12 10 4 3 10 Output Finite Infinite Input 4 1 1 2 9 36 2 4 12 3 3 5 4 Output Finite Finite Finite Infinite Note 6/12 = 1/2 = 0,5_{10} 4/3 = 1,(3)_{10} 9/36 = 1/4 = 0,01_2 4/12 = 1/3 = 0,1_3 Tags: implementation, math Correct Solution: ``` n = int(input()) s = '' for i in range(n): p, q, b = map(int, input().split()) for i in range(6): b = (b * b) % q if ((p * b) % q): s += 'Infinite\n' else: s += 'Finite\n' print(s) ```
11,383
Provide tags and a correct Python 3 solution for this coding contest problem. You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a fraction has zero numerals after the decimal point. Input The first line contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of queries. Next n lines contain queries, one per line. Each line contains three integers p, q, and b (0 ≀ p ≀ 10^{18}, 1 ≀ q ≀ 10^{18}, 2 ≀ b ≀ 10^{18}). All numbers are given in notation with base 10. Output For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise. Examples Input 2 6 12 10 4 3 10 Output Finite Infinite Input 4 1 1 2 9 36 2 4 12 3 3 5 4 Output Finite Finite Finite Infinite Note 6/12 = 1/2 = 0,5_{10} 4/3 = 1,(3)_{10} 9/36 = 1/4 = 0,01_2 4/12 = 1/3 = 0,1_3 Tags: implementation, math Correct Solution: ``` import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n = int(input()) import math for i in range(n): p, q, b = map(int, input().split()) g = math.gcd(p, q) p //= g q //= g if p == 0 or q == 1: print('Finite') continue g = math.gcd(q, b) while g != 1: q //= g b = g g = math.gcd(q, b) if q != 1: print('Infinite') else: print('Finite') ```
11,384
Provide tags and a correct Python 3 solution for this coding contest problem. You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a fraction has zero numerals after the decimal point. Input The first line contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of queries. Next n lines contain queries, one per line. Each line contains three integers p, q, and b (0 ≀ p ≀ 10^{18}, 1 ≀ q ≀ 10^{18}, 2 ≀ b ≀ 10^{18}). All numbers are given in notation with base 10. Output For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise. Examples Input 2 6 12 10 4 3 10 Output Finite Infinite Input 4 1 1 2 9 36 2 4 12 3 3 5 4 Output Finite Finite Finite Infinite Note 6/12 = 1/2 = 0,5_{10} 4/3 = 1,(3)_{10} 9/36 = 1/4 = 0,01_2 4/12 = 1/3 = 0,1_3 Tags: implementation, math Correct Solution: ``` print('\n'.join([(lambda p, q, b: 'Infinite' if p * pow(b, 99, q) % q else 'Finite')(*map(int, input().split())) for _ in range(int(input()))])) ```
11,385
Provide tags and a correct Python 3 solution for this coding contest problem. You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a fraction has zero numerals after the decimal point. Input The first line contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of queries. Next n lines contain queries, one per line. Each line contains three integers p, q, and b (0 ≀ p ≀ 10^{18}, 1 ≀ q ≀ 10^{18}, 2 ≀ b ≀ 10^{18}). All numbers are given in notation with base 10. Output For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise. Examples Input 2 6 12 10 4 3 10 Output Finite Infinite Input 4 1 1 2 9 36 2 4 12 3 3 5 4 Output Finite Finite Finite Infinite Note 6/12 = 1/2 = 0,5_{10} 4/3 = 1,(3)_{10} 9/36 = 1/4 = 0,01_2 4/12 = 1/3 = 0,1_3 Tags: implementation, math Correct Solution: ``` print('\n'.join(('F','Inf')[pow(b,64,q)*p%q>0]+'inite'for p,q,b in(map(int,input().split())for _ in[0]*int(input())))) ```
11,386
Provide tags and a correct Python 3 solution for this coding contest problem. You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a fraction has zero numerals after the decimal point. Input The first line contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of queries. Next n lines contain queries, one per line. Each line contains three integers p, q, and b (0 ≀ p ≀ 10^{18}, 1 ≀ q ≀ 10^{18}, 2 ≀ b ≀ 10^{18}). All numbers are given in notation with base 10. Output For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise. Examples Input 2 6 12 10 4 3 10 Output Finite Infinite Input 4 1 1 2 9 36 2 4 12 3 3 5 4 Output Finite Finite Finite Infinite Note 6/12 = 1/2 = 0,5_{10} 4/3 = 1,(3)_{10} 9/36 = 1/4 = 0,01_2 4/12 = 1/3 = 0,1_3 Tags: implementation, math Correct Solution: ``` from sys import stdin, stdout n=int(stdin.readline()) s='' for i in range(n): p,q,b=map(int,input().split()) for i in range(6): b=(b*b)%q if((p*b)%q): s+='Infinite\n' else: s+='Finite\n' print(s) ```
11,387
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a fraction has zero numerals after the decimal point. Input The first line contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of queries. Next n lines contain queries, one per line. Each line contains three integers p, q, and b (0 ≀ p ≀ 10^{18}, 1 ≀ q ≀ 10^{18}, 2 ≀ b ≀ 10^{18}). All numbers are given in notation with base 10. Output For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise. Examples Input 2 6 12 10 4 3 10 Output Finite Infinite Input 4 1 1 2 9 36 2 4 12 3 3 5 4 Output Finite Finite Finite Infinite Note 6/12 = 1/2 = 0,5_{10} 4/3 = 1,(3)_{10} 9/36 = 1/4 = 0,01_2 4/12 = 1/3 = 0,1_3 Submitted Solution: ``` def mod(b, q): #computes b^k mod q for large k for i in range(6): b = (b * b) % q return b n = int(input()) s = '' for i in range(n): p, q, b = list(map(int, input().split())) if (p * mod(b, q))%q: #checks if p * b^k is not divisible by q for large k s += 'Infinite\n' else: s += 'Fininte\n' print(s) ``` No
11,388
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a fraction has zero numerals after the decimal point. Input The first line contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of queries. Next n lines contain queries, one per line. Each line contains three integers p, q, and b (0 ≀ p ≀ 10^{18}, 1 ≀ q ≀ 10^{18}, 2 ≀ b ≀ 10^{18}). All numbers are given in notation with base 10. Output For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise. Examples Input 2 6 12 10 4 3 10 Output Finite Infinite Input 4 1 1 2 9 36 2 4 12 3 3 5 4 Output Finite Finite Finite Infinite Note 6/12 = 1/2 = 0,5_{10} 4/3 = 1,(3)_{10} 9/36 = 1/4 = 0,01_2 4/12 = 1/3 = 0,1_3 Submitted Solution: ``` def gcd(a, b): if a > b: a, b = b, a if b % a == 0: return a return gcd(b, b % a) n = int(input()) for i in range(n): p, q, b = list(map(int, input().split())) if p == 0: print("Finite") else: q = q // gcd(p, q) if pow(b, 64, q): print("Infinite") else: print("Finite") ``` No
11,389
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a fraction has zero numerals after the decimal point. Input The first line contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of queries. Next n lines contain queries, one per line. Each line contains three integers p, q, and b (0 ≀ p ≀ 10^{18}, 1 ≀ q ≀ 10^{18}, 2 ≀ b ≀ 10^{18}). All numbers are given in notation with base 10. Output For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise. Examples Input 2 6 12 10 4 3 10 Output Finite Infinite Input 4 1 1 2 9 36 2 4 12 3 3 5 4 Output Finite Finite Finite Infinite Note 6/12 = 1/2 = 0,5_{10} 4/3 = 1,(3)_{10} 9/36 = 1/4 = 0,01_2 4/12 = 1/3 = 0,1_3 Submitted Solution: ``` def mod(b, q): #computes b^k mod q for large k for i in range(6): b = (b * b) % q return b n = int(input()) s = '' for i in range(n - 1): p, q, b = list(map(int, input().split())) if (p * mod(b, q))%q: #checks if p * b^k is not divisible by q for large k s += 'Infinite\n' else: s += 'Fininte\n' p, q, b = list(map(int, input().split())) if (p * mod(b, q))%q: #checks if p * b^k is not divisible by q for large k s += 'Infinite' else: s += 'Fininte' print(s) ``` No
11,390
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a fraction has zero numerals after the decimal point. Input The first line contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of queries. Next n lines contain queries, one per line. Each line contains three integers p, q, and b (0 ≀ p ≀ 10^{18}, 1 ≀ q ≀ 10^{18}, 2 ≀ b ≀ 10^{18}). All numbers are given in notation with base 10. Output For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise. Examples Input 2 6 12 10 4 3 10 Output Finite Infinite Input 4 1 1 2 9 36 2 4 12 3 3 5 4 Output Finite Finite Finite Infinite Note 6/12 = 1/2 = 0,5_{10} 4/3 = 1,(3)_{10} 9/36 = 1/4 = 0,01_2 4/12 = 1/3 = 0,1_3 Submitted Solution: ``` def gcd(a, b): if a > b: a, b = b, a if b % a == 0: return a return gcd(a, b % a) def satisfy(b, q): for i in range(7): b = (b * b) % q return b == 0 n = int(input()) for i in range(n): p, q, b = list(map(int, input().split())) if p == 0: print("Finite") else: q = q // gcd(p, q) if pow(b, q): print("Infinite") else: print("Finite") ``` No
11,391
Provide a correct Python 3 solution for this coding contest problem. Given are two strings S and T. Let us change some of the characters in S so that T will be a substring of S. At least how many characters do we need to change? Here, a substring is a consecutive subsequence. For example, `xxx` is a substring of `yxxxy`, but not a substring of `xxyxx`. Constraints * The lengths of S and T are each at least 1 and at most 1000. * The length of T is at most that of S. * S and T consist of lowercase English letters. Input Input is given from Standard Input in the following format: S T Output Print the minimum number of characters in S that need to be changed. Examples Input cabacc abc Output 1 Input codeforces atcoder Output 6 "Correct Solution: ``` s=input() t=input() tl=len(t) m=0 for i in range(len(s)-tl+1): c=0 for x,y in zip(t,s[i:i+tl]): if x==y: c+=1 m=max(m,c) print(tl-m) ```
11,392
Provide a correct Python 3 solution for this coding contest problem. Given are two strings S and T. Let us change some of the characters in S so that T will be a substring of S. At least how many characters do we need to change? Here, a substring is a consecutive subsequence. For example, `xxx` is a substring of `yxxxy`, but not a substring of `xxyxx`. Constraints * The lengths of S and T are each at least 1 and at most 1000. * The length of T is at most that of S. * S and T consist of lowercase English letters. Input Input is given from Standard Input in the following format: S T Output Print the minimum number of characters in S that need to be changed. Examples Input cabacc abc Output 1 Input codeforces atcoder Output 6 "Correct Solution: ``` s=input() t=input() k=len(t) for i in range(len(s)-len(t)+1): p=0 for j in range(len(t)): if s[i+j]!=t[j]: p+=1 if k>p: k=p print(k) ```
11,393
Provide a correct Python 3 solution for this coding contest problem. Given are two strings S and T. Let us change some of the characters in S so that T will be a substring of S. At least how many characters do we need to change? Here, a substring is a consecutive subsequence. For example, `xxx` is a substring of `yxxxy`, but not a substring of `xxyxx`. Constraints * The lengths of S and T are each at least 1 and at most 1000. * The length of T is at most that of S. * S and T consist of lowercase English letters. Input Input is given from Standard Input in the following format: S T Output Print the minimum number of characters in S that need to be changed. Examples Input cabacc abc Output 1 Input codeforces atcoder Output 6 "Correct Solution: ``` s=input() t=input() a=0 for i in range(len(s)-len(t)+1): c=0 for j,d in enumerate(t): if s[i+j]==d: c+=1 a=max(a,c) print(len(t)-a) ```
11,394
Provide a correct Python 3 solution for this coding contest problem. Given are two strings S and T. Let us change some of the characters in S so that T will be a substring of S. At least how many characters do we need to change? Here, a substring is a consecutive subsequence. For example, `xxx` is a substring of `yxxxy`, but not a substring of `xxyxx`. Constraints * The lengths of S and T are each at least 1 and at most 1000. * The length of T is at most that of S. * S and T consist of lowercase English letters. Input Input is given from Standard Input in the following format: S T Output Print the minimum number of characters in S that need to be changed. Examples Input cabacc abc Output 1 Input codeforces atcoder Output 6 "Correct Solution: ``` S=input() T=input() r=1000 for i in range(len(S)-len(T)+1): r=min(r,sum([S[i+j]!=T[j] for j in range(len(T))])) print(r) ```
11,395
Provide a correct Python 3 solution for this coding contest problem. Given are two strings S and T. Let us change some of the characters in S so that T will be a substring of S. At least how many characters do we need to change? Here, a substring is a consecutive subsequence. For example, `xxx` is a substring of `yxxxy`, but not a substring of `xxyxx`. Constraints * The lengths of S and T are each at least 1 and at most 1000. * The length of T is at most that of S. * S and T consist of lowercase English letters. Input Input is given from Standard Input in the following format: S T Output Print the minimum number of characters in S that need to be changed. Examples Input cabacc abc Output 1 Input codeforces atcoder Output 6 "Correct Solution: ``` s = input() t = input() n, m = len(s), len(t) print(min(sum(si != ti for si, ti in zip(s[i: i+m], t)) for i in range(n-m+1))) ```
11,396
Provide a correct Python 3 solution for this coding contest problem. Given are two strings S and T. Let us change some of the characters in S so that T will be a substring of S. At least how many characters do we need to change? Here, a substring is a consecutive subsequence. For example, `xxx` is a substring of `yxxxy`, but not a substring of `xxyxx`. Constraints * The lengths of S and T are each at least 1 and at most 1000. * The length of T is at most that of S. * S and T consist of lowercase English letters. Input Input is given from Standard Input in the following format: S T Output Print the minimum number of characters in S that need to be changed. Examples Input cabacc abc Output 1 Input codeforces atcoder Output 6 "Correct Solution: ``` S, T = input(), input() best = len(T) for i in range(len(S)-len(T)+1): best = min(best, sum(S[i+j] != c for j, c in enumerate(T))) print(best) ```
11,397
Provide a correct Python 3 solution for this coding contest problem. Given are two strings S and T. Let us change some of the characters in S so that T will be a substring of S. At least how many characters do we need to change? Here, a substring is a consecutive subsequence. For example, `xxx` is a substring of `yxxxy`, but not a substring of `xxyxx`. Constraints * The lengths of S and T are each at least 1 and at most 1000. * The length of T is at most that of S. * S and T consist of lowercase English letters. Input Input is given from Standard Input in the following format: S T Output Print the minimum number of characters in S that need to be changed. Examples Input cabacc abc Output 1 Input codeforces atcoder Output 6 "Correct Solution: ``` s=input() t=input() l=len(s) l2=len(t) ans=1000000 for i in range(l-l2+1): curr=0 for j in range(i,i+l2): if(s[j]!=t[j-i]): curr+=1 if(curr<ans): ans=curr print(ans) ```
11,398
Provide a correct Python 3 solution for this coding contest problem. Given are two strings S and T. Let us change some of the characters in S so that T will be a substring of S. At least how many characters do we need to change? Here, a substring is a consecutive subsequence. For example, `xxx` is a substring of `yxxxy`, but not a substring of `xxyxx`. Constraints * The lengths of S and T are each at least 1 and at most 1000. * The length of T is at most that of S. * S and T consist of lowercase English letters. Input Input is given from Standard Input in the following format: S T Output Print the minimum number of characters in S that need to be changed. Examples Input cabacc abc Output 1 Input codeforces atcoder Output 6 "Correct Solution: ``` s = input() t = input() S,T = len(s),len(t) ans = T for i in range(S-T+1): tmp = [c1!=c2 for c1,c2 in zip(s[i:i+T],t)].count(True) ans = min(ans,tmp) print(ans) ```
11,399