description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≤ x ≤ x_2 and y_1 ≤ y ≤ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. Input The first line of the input contains an only integer n (1 ≤ n ≤ 100 000), the number of points in Pavel's records. The second line contains 2 ⋅ n integers a_1, a_2, ..., a_{2 ⋅ n} (1 ≤ a_i ≤ 10^9), coordinates, written by Pavel in some order. Output Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. Examples Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 Note In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)).
n = int(input()) arr = list(map(int, input().split())) arr.sort() x1 = arr[0] y1 = arr[n] x2 = arr[n - 1] y2 = arr[2 * n - 1] if n == 1: print(0) else: ans = (arr[n - 1] - arr[0]) * (arr[-1] - arr[n]) for i in range(1, n): ans = min((arr[n + i - 1] - arr[i]) * (arr[-1] - arr[0]), ans) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≤ x ≤ x_2 and y_1 ≤ y ≤ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. Input The first line of the input contains an only integer n (1 ≤ n ≤ 100 000), the number of points in Pavel's records. The second line contains 2 ⋅ n integers a_1, a_2, ..., a_{2 ⋅ n} (1 ≤ a_i ≤ 10^9), coordinates, written by Pavel in some order. Output Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. Examples Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 Note In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)).
n = int(input()) a = sorted(map(int, input().split())) x1, y2 = a[0], a[-1] x2, y1 = a[n - 1], a[n] m = (x1 - x2) * (y1 - y2) x1, x2 = a[0], a[-1] for i in range(1, n): y1, y2 = a[i], a[i + n - 1] m = min(m, (x1 - x2) * (y1 - y2)) print(m)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≤ x ≤ x_2 and y_1 ≤ y ≤ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. Input The first line of the input contains an only integer n (1 ≤ n ≤ 100 000), the number of points in Pavel's records. The second line contains 2 ⋅ n integers a_1, a_2, ..., a_{2 ⋅ n} (1 ≤ a_i ≤ 10^9), coordinates, written by Pavel in some order. Output Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. Examples Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 Note In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)).
n = int(input()) a = sorted(list(map(int, input().split()))) res = (a[n - 1] - a[0]) * (a[-1] - a[n]) for i in range(1, n + 1): curr = (a[i + n - 1] - a[i]) * (a[-1] - a[0]) res = min(res, curr) print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≤ x ≤ x_2 and y_1 ≤ y ≤ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. Input The first line of the input contains an only integer n (1 ≤ n ≤ 100 000), the number of points in Pavel's records. The second line contains 2 ⋅ n integers a_1, a_2, ..., a_{2 ⋅ n} (1 ≤ a_i ≤ 10^9), coordinates, written by Pavel in some order. Output Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. Examples Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 Note In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)).
n = int(input()) lin = sorted(list(map(int, input().split()))) ( print( min( (lin[-1] - lin[0]) * min(lin[i + n - 1] - lin[i] for i in range(1, n)), (lin[-1] - lin[n]) * (lin[n - 1] - lin[0]), ) ) if n > 1 else print(0) )
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR NUMBER
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
n = int(input()) l = input().split() l = [int(i) for i in l] l.sort() m = (l[2 * n - 1] - l[n]) * (l[n - 1] - l[0]) for i in range(1, n): if m > (l[2 * n - 1] - l[0]) * (l[i + n - 1] - l[i]): m = (l[2 * n - 1] - l[0]) * (l[i + n - 1] - l[i]) print(m)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
n = int(input()) v = sorted([int(x) for x in input().split()]) ans = (v[n - 1] - v[0]) * (v[n * 2 - 1] - v[n]) for i in range(1, n + 1): ans = min(ans, (v[i + n - 1] - v[i]) * (v[2 * n - 1] - v[0])) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
import sys input = lambda: sys.stdin.readline().strip("\r\n") n = int(input()) a = sorted(list(map(int, input().split()))) print( min( (a[n - 1] - a[0]) * (a[-1] - a[n]), (a[-1] - a[0]) * min(a[n - 1 + i] - a[i] for i in range(n)), ) )
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
numPoints = int(input()) coord = list(map(int, input().split(" "))) coord.sort() solution = (coord[numPoints - 1] - coord[0]) * ( coord[2 * numPoints - 1] - coord[numPoints] ) for i in range(1, numPoints): new = (coord[i + numPoints - 1] - coord[i]) * (coord[2 * numPoints - 1] - coord[0]) if new < solution: solution = new print(solution)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
n = int(input()) a = list(map(int, input().split())) a.sort() x = float("Inf") for i in range(1, n): x = min(x, a[i + n - 1] - a[i]) print(min((a[n - 1] - a[0]) * (a[-1] - a[n]), x * (a[-1] - a[0])))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
num_points = int(input()) coords = [int(x) for x in input().split()] coords.sort() width = coords[num_points - 1] - coords[0] height = coords[-1] - coords[num_points] area1 = width * height width2 = min(coords[i + num_points - 1] - coords[i] for i in range(num_points + 1)) height2 = coords[-1] - coords[0] area2 = width2 * height2 area = min(area1, area2) print(area)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
n = int(input()) a = list(map(int, input().split())) a.sort() x1 = a[n - 1] - a[0] x2 = a[2 * n - 1] - a[n] ans = x1 * x2 for i in range(1, n): ans = min(ans, (a[2 * n - 1] - a[0]) * (a[i + n - 1] - a[i])) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
n = int(input()) a = sorted(map(int, input().split())) if n == 1: print(0) exit() d = (a[n - 1] - a[0]) * (a[-1] - a[n]) e = (a[-1] - a[0]) * min(a[s + n - 1] - a[s] for s in range(1, n)) print(min(d, e))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
import sys ioRead = sys.stdin.readline ioWrite = lambda x: sys.stdout.write(f"{x}\n") n = int(ioRead()) points = sorted(map(int, ioRead().split(" "))) answer = points[-1] ** 2 for c in range(n): axis_1 = [points[c], points[c + n - 1]] axis_2 = [points[n if c == 0 else 0], points[-1]] c_answer = (axis_1[1] - axis_1[0]) * (axis_2[1] - axis_2[0]) answer = min(answer, c_answer) ioWrite(answer)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
n = int(input()) a = sorted(map(int, input().split())) print( min( [(a[n - 1] - a[0]) * (a[-1] - a[n])] + [((a[-1] - a[0]) * (y - x)) for x, y in zip(a, a[n - 1 :])] ) )
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP LIST BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
n = int(input()) a = list(map(int, input().split())) a = sorted(a) s = (a[len(a) // 2 - 1] - a[0]) * (a[-1] - a[len(a) // 2]) s1 = s delta_x = a[-1] - a[0] for i in range(1, n): s1 = min(s1, delta_x * (a[i + len(a) // 2 - 1] - a[i])) print(s1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
n = int(input()) a = list(map(int, input().split())) a.sort() minn = 10000000000000 for i in range(n): minn = min(minn, a[i + n - 1] - a[i]) if n == 1: print(0) else: print(min((a[2 * n - 1] - a[0]) * minn, (a[n - 1] - a[0]) * (a[2 * n - 1] - a[n])))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
def solve(a, n): if n == 1: return 0 a.sort() minn = 1000000000.0 + 239 for i in range(1, n): minn = min(minn, a[i + n - 1] - a[i]) ans = min((a[2 * n - 1] - a[0]) * minn, (a[n - 1] - a[0]) * (a[2 * n - 1] - a[n])) return ans n = int(input()) a = list(map(int, input().split())) pt = solve(a, n) print(pt)
FUNC_DEF IF VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
n = int(input()) s = list(map(int, input().split())) s.sort() mix = s[0] maxx = s[n - 1] miy = s[n] may = s[-1] dp = [] dp.append([maxx, mix, may, miy]) for i in range(1, n): dp.append([s[-1], s[0], s[i + n - 1], s[i]]) ans = (dp[0][0] - dp[0][1]) * (dp[0][2] - dp[0][3]) for i in dp: ans = min(ans, (i[0] - i[1]) * (i[2] - i[3])) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR LIST VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
n = int(input()) a = [int(i) for i in input().split()] a.sort() count = {} run = False for x in a: if x not in count: count[x] = 0 count[x] += 1 if count[x] == n: run = True best = (a[n - 1] - a[0]) * (a[2 * n - 1] - a[n]) for i in range(1, n): j = i + n - 1 val = (a[j] - a[i]) * (a[2 * n - 1] - a[0]) best = min(best, val) print(best)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
N = int(input()) a = list(map(int, input().split())) a = sorted(a) r = 10**10 for i in range(N): if r > a[i + N - 1] - a[i]: r = a[i + N - 1] - a[i] s1 = (a[len(a) - 1] - a[0]) * r s2 = (a[N - 1] - a[0]) * (a[len(a) - 1] - a[N]) res = min(s1, s2) print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
N = int(input()) Ns = list(map(int, input().strip().split())) Ns.sort() diff1 = Ns[N - 1] - Ns[0] diff2 = Ns[-1] - Ns[N] best = diff1 * diff2 diff_ends = Ns[-1] - Ns[0] for x in range(N): diff = (Ns[x + N - 1] - Ns[x]) * diff_ends if diff < best: best = diff print(best)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
n1 = int(input()) a = sorted(list(map(int, input().split()))) i = 0 j = n1 - 1 mn = (a[j] - a[0]) * (a[-1] - a[j + 1]) j += 1 i += 1 ki = 0 kj = n1 - 1 while j < 2 * n1: if j == 2 * n1 - 1: n = (a[j] - a[i]) * (a[i - 1] - a[0]) elif i == 0: n = (a[j] - a[i]) * (a[-1] - a[j + 1]) else: n = (a[j] - a[i]) * (a[-1] - a[0]) if mn > n: mn = n j += 1 i += 1 print(mn)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP NUMBER VAR IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
def smallestarea(arr): arr = sorted(arr) i, j = 0, len(arr) // 2 n = len(arr) // 2 xdiff = arr[-1] - arr[0] ydiff = 100000000000.0 for i in range(1, n): ydiff = min(ydiff, arr[i + n - 1] - arr[i]) return int(min(ydiff * xdiff, (arr[n - 1] - arr[0]) * (arr[-1] - arr[n]))) input() arr = list(map(int, input().split())) print(smallestarea(arr))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
maxn = 200000.0 + 10 n = int(input()) a = list(map(int, input().split())) a.sort() ans = 0 ans = (a[n - 1] - a[0]) * (a[2 * n - 1] - a[n]) tmp = 0 for i in range(1, n): tmp = a[i + n - 1] - a[i] ans = min(ans, tmp * (a[2 * n - 1] - a[0])) print(ans)
ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
n = int(input()) ls = list(map(int, input().split())) ls.sort() x = ls[len(ls) - 1] - ls[0] y = 34359738367 for i in range(1, n): tep = ls[i + n - 1] - ls[i] if tep < y: y = tep ans = x * y x = ls[n - 1] - ls[0] y = ls[len(ls) - 1] - ls[n] ans = min(ans, x * y) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
n = int(input()) m = list(map(int, input().split())) m.sort() n *= 2 mi = (m[n // 2 - 1] - m[0]) * (m[n - 1] - m[n // 2]) for i in range(1, n // 2): mi = min(mi, (m[n // 2 - 1 + i] - m[i]) * (m[n - 1] - m[0])) print(mi)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
n = int(input()) a = list(map(int, input().split())) a.sort() res = (a[n - 1] - a[0]) * (a[2 * n - 1] - a[n]) x = max(a) y = min(a) for i in range(1, n + 1): res = min(res, (x - y) * (a[i + n - 1] - a[i])) print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
n = int(input()) m = 2 * n arr = list(map(int, input().split())) arr = sorted(arr) set1_ans = (arr[n - 1] - arr[0]) * (arr[2 * n - 1] - arr[n]) set2_ans = 1e20 for i in range(1, n): a = (arr[2 * n - 1] - arr[0]) * (arr[n - 1 + i] - arr[i]) set2_ans = min(a, set2_ans) print(min(set1_ans, set2_ans))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
def photo(n, m): if n <= 1: return 0 m = m.split() m = [int(m[i]) for i in range(len(m))] m.sort() x1 = m[len(m) - 1] - m[0] c = m[1 : len(m) - 1] differ = [(c[i + n - 1] - c[i]) for i in range(len(c) + 2 - n - 1)] y1 = min(differ) result = [x1 * y1] x = (m[n - 1] - m[0]) * (m[len(m) - 1] - m[n]) result.append(x) return min(result) print(photo(int(input().strip()), input().strip()))
FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
n = int(input()) a = list(map(int, input().split())) a.sort() b = [] for i in range(1, n): b.append(a[i + n - 1] - a[i]) if len(b) != 0: b = min(b) * (a[-1] - a[0]) print(min(b, (a[0] - a[n - 1]) * (a[n] - a[2 * n - 1]))) elif len(b) == 0: print((a[0] - a[n - 1]) * (a[n] - a[2 * n - 1]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
n = int(input()) l = sorted(list(map(int, input().split()))) ret = (l[n - 1] - l[0]) * (l[-1] - l[n]) if ret > 0: for x, y in zip(l[1:n], l[n:-1]): ret = min(ret, (y - x) * (l[-1] - l[0])) print(ret)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
n = int(input()) a = [] a = input().split() for i in range(len(a)): a[i] = int(a[i]) a.sort() c = 0 ans = (a[n - 1] - a[0]) * (a[2 * n - 1] - a[n]) for i in range(n): ans = min(ans, (a[i + n - 1] - a[i]) * (a[2 * n - 1] - a[0])) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
R = lambda: map(int, input().split()) n = int(input()) arr = sorted(R()) print( min( [(arr[n - 1] - arr[0]) * (arr[-1] - arr[n])] + [((arr[-1] - arr[0]) * (arr[i + n - 1] - arr[i])) for i in range(1, n)] ) if n > 1 else 0 )
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP LIST BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR NUMBER VAR NUMBER
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
def main(): n = int(input()) l = sorted(map(int, input().split())) r = (l[n - 1] - l[0]) * (l[-1] - l[n]) if r: r = min(r, min(b - a for a, b in zip(l[1:n], l[n:-1])) * (l[-1] - l[0])) print(r) def __starting_point(): main() __starting_point()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
n = int(input()) a = list(map(int, input().split())) a.sort() ans = (a[n - 1] - a[0]) * (a[-1] - a[n]) tmp = 0 for i in range(1, n): tmp = a[i + n - 1] - a[i] ans = min(ans, tmp * (a[-1] - a[0])) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
n = int(input()) a = list(map(int, input().split())) a.sort() f = min([((a[n + i - 1] - a[i]) * (a[-1] - a[0])) for i in range(n)]) print(min((a[-1] - a[n]) * (a[n - 1] - a[0]), f))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
def main(): n = int(input()) numbers = list(map(int, input().split(" "))) numbers.sort() r = [(numbers[n - 1 + x] - numbers[x]) for x in range(n + 1)] print(min([r[0] * r[-1], (numbers[-1] - numbers[0]) * min(r)])) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
n = int(input()) a = list(map(int, input().split())) a.sort() min_my = 10**9 + 1 cnt = a[2 * n - 1] - a[0] for i in range(1, n): new = a[i + n - 1] - a[i] if new < min_my: min_my = new print(min((a[n - 1] - a[0]) * (a[2 * n - 1] - a[n]), cnt * min_my))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR BIN_OP VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
def area(x1, x2, y1, y2): return abs(x2 - x1) * abs(y2 - y1) def main(): n = int(input()) a = list(map(int, input().split())) a.sort() m = area(a[0], a[n - 1], a[n], a[-1]) for i in range(1, n): m = min(m, area(a[0], a[-1], a[i], a[n + i - 1])) print(m) main()
FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
def solve(N, A): if N == 1: return 0 A.sort() fh = A[0:N] lh = A[N:] best = (max(fh) - min(fh)) * (max(lh) - min(lh)) for i in range(1, N + 1): area = (A[-1] - A[0]) * (A[i + N - 1] - A[i]) best = min(best, area) return best def main(): N = int(input()) A = [int(e) for e in input().split(" ")] assert len(A) == 2 * N print(solve(N, A)) main()
FUNC_DEF IF VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
n = int(input()) a = [int(v) for v in input().split()] a.sort() if n == 1: ans = 0 else: m = (a[n - 1] - a[0]) * (a[-1] - a[n]) p = a[-1] - a[0] q = p for j in range(1, n): q = min(q, a[j + n - 1] - a[j]) ans = min(m, p * q) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
n = int(input()) point = [int(item) for item in input().split(" ")] point.sort() a = (point[n - 1] - point[0]) * (point[n + n - 1] - point[n]) b = (point[-1] - point[0]) * min(point[n - 1 + i] - point[i] for i in range(n)) print(min(a, b))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
n = int(input().strip()) d = {} a = list(map(int, input().strip().split(" "))) list.sort(a) min = (a[n - 1] - a[0]) * (a[2 * n - 1] - a[n]) s2 = 0 e2 = 2 * n - 1 width = a[e2] - a[s2] for i in range(1, n): s1 = i e1 = n + i - 1 val = (a[e1] - a[s1]) * width if val < min: min = val print(min)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where $(x_1, y_1)$ and $(x_2, y_2)$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of $n$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. -----Input----- The first line of the input contains an only integer $n$ ($1 \leq n \leq 100\,000$), the number of points in Pavel's records. The second line contains $2 \cdot n$ integers $a_1$, $a_2$, ..., $a_{2 \cdot n}$ ($1 \leq a_i \leq 10^9$), coordinates, written by Pavel in some order. -----Output----- Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. -----Examples----- Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 -----Note----- In the first sample stars in Pavel's records can be $(1, 3)$, $(1, 3)$, $(2, 3)$, $(2, 4)$. In this case, the minimal area of the rectangle, which contains all these points is $1$ (rectangle with corners at $(1, 3)$ and $(2, 4)$).
n = int(input()) A = list(map(int, input().split())) A.sort() B = [] t = A[-1] - A[0] B.append((A[n - 1] - A[0]) * (A[-1] - A[n])) for i in range(1, n): B.append(t * (-A[i] + A[i + n - 1])) print(min(B))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given a connected undirected weighted graph consisting of $n$ vertices and $m$ edges. You need to print the $k$-th smallest shortest path in this graph (paths from the vertex to itself are not counted, paths from $i$ to $j$ and from $j$ to $i$ are counted as one). More formally, if $d$ is the matrix of shortest paths, where $d_{i, j}$ is the length of the shortest path between vertices $i$ and $j$ ($1 \le i < j \le n$), then you need to print the $k$-th element in the sorted array consisting of all $d_{i, j}$, where $1 \le i < j \le n$. -----Input----- The first line of the input contains three integers $n, m$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $n - 1 \le m \le \min\Big(\frac{n(n-1)}{2}, 2 \cdot 10^5\Big)$, $1 \le k \le \min\Big(\frac{n(n-1)}{2}, 400\Big)$ — the number of vertices in the graph, the number of edges in the graph and the value of $k$, correspondingly. Then $m$ lines follow, each containing three integers $x$, $y$ and $w$ ($1 \le x, y \le n$, $1 \le w \le 10^9$, $x \ne y$) denoting an edge between vertices $x$ and $y$ of weight $w$. It is guaranteed that the given graph is connected (there is a path between any pair of vertices), there are no self-loops (edges connecting the vertex with itself) and multiple edges (for each pair of vertices $x$ and $y$, there is at most one edge between this pair of vertices in the graph). -----Output----- Print one integer — the length of the $k$-th smallest shortest path in the given graph (paths from the vertex to itself are not counted, paths from $i$ to $j$ and from $j$ to $i$ are counted as one). -----Examples----- Input 6 10 5 2 5 1 5 3 9 6 2 2 1 3 1 5 1 8 6 5 10 1 6 5 6 4 6 3 6 2 3 4 5 Output 3 Input 7 15 18 2 6 3 5 7 4 6 5 4 3 6 9 6 7 7 1 6 4 7 1 6 7 2 1 4 3 2 3 2 8 5 3 6 2 5 5 3 7 9 4 1 8 2 1 1 Output 9
import sys input = sys.stdin.readline N, M, K = list(map(int, input().split())) X = [] for _ in range(M): x, y, w = list(map(int, input().split())) X.append([min(x, y), max(x, y), w]) X = (sorted(X, key=lambda x: x[2]) + [[0, 0, 10**20] for _ in range(K)])[:K] D = {} for x, y, w in X: if x: D[x * 10**6 + y] = w flg = 1 while flg: flg = 0 for i in range(len(X)): x1, y1, w1 = X[i] for j in range(i + 1, len(X)): x2, y2, w2 = X[j] if x1 == x2: a, b = min(y1, y2), max(y1, y2) elif y1 == y2: a, b = min(x1, x2), max(x1, x2) elif x1 == y2: a, b = x2, y1 elif x2 == y1: a, b = x1, y2 else: a, b = 0, 0 if a: if ( a * 10**6 + b in D and w1 + w2 < D[a * 10**6 + b] or a * 10**6 + b not in D and w1 + w2 < X[-1][2] ): if a * 10**6 + b in D: for k in range(len(X)): if X[k][0] == a and X[k][1] == b: X[k][2] = w1 + w2 else: x, y, w = X.pop() if x: D.pop(x * 10**6 + y) X.append([a, b, w1 + w2]) D[a * 10**6 + b] = w1 + w2 X = sorted(X, key=lambda x: x[2]) flg = 1 break if flg: break print(X[-1][2])
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER LIST NUMBER NUMBER BIN_OP NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR VAR VAR IF VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER NUMBER VAR VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER IF VAR IF BIN_OP BIN_OP VAR BIN_OP NUMBER NUMBER VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP NUMBER NUMBER VAR BIN_OP BIN_OP VAR BIN_OP NUMBER NUMBER VAR VAR BIN_OP VAR VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR BIN_OP NUMBER NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER NUMBER VAR EXPR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER NUMBER VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER
You are given two points $P$ and $Q$ and an opaque sphere in a three-dimensional space. The point $P$ is not moving, while $Q$ is moving in a straight line with constant velocity. You are also given a direction vector $d$ with the following meaning: the position of $Q$ at time $t$ is $Q(t) = Q(0) + d \cdot t$, where $Q(0)$ is the initial position of $Q$. It is guaranteed that $Q$ is not visible from $P$ initially (at time $t=0$). It is also guaranteed that $P$ and $Q$ do not touch the sphere at any time. Find the smallest positive time $t_v$ when $Q$ is visible from $P$, i.e. when the line segment connecting points $P$ and $Q$ does not intersect the sphere. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains 13 space-separated integers. - The first three integers $P_x, P_y, P_z$ denote the coordinates of $P$. - The next three integers $Q_x, Q_y, Q_z$ denote the initial coordinates of $Q$. - The next three integers $d_x, d_y, d_z$ denote the components of the direction vector $d$. - The last four integers $c_x, c_y, c_z, r$ denote the coordinates of the centre of the sphere and its radius. -----Output----- For each test case, print a single line containing one real number — the time $t_v$. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$. It is guaranteed that $t_v$ exists and does not exceed $10^9$. -----Constraints----- - $1 \le T \le 10^5$ - the absolute values of coordinates of all points do not exceed $2\cdot10^9$ - $1 \le r \le 10^9$ -----Subtasks----- Subtask #1 (25 points): $P_z = Q_z = d_z = c_z = 0$ Subtask #2 (75 points): original constraints -----Example Input----- 1 3 0 0 -10 -10 0 0 10 0 0 -3 0 3 -----Example Output----- 1.0000000000
T = int(input()) for i1 in range(0, T): [Px, Py, Pz, Qx, Qy, Qz, dx, dy, dz, Cx, Cy, Cz, r] = [ int(i) for i in input().split() ] if (Pz == 0 and Qz == 0) and (dz == 0 and Cz == 0): a = Cx * Cx + Px * Px - r * r - 2 * Cx * Px b = 2 * (Cx * Py + Px * Cy - (Cx * Cy + Px * Py)) c = Cy * Cy + Py * Py - 2 * Py * Cy - r * r x1 = Px - Qx y1 = Py - Qy a1 = a * dy * dy + b * dx * dy + c * dx * dx b1 = 2 * a * y1 * dy + y1 * dx * b + b * x1 * dy + 2 * c * x1 * dx c1 = a * y1 * y1 + b * y1 * x1 + c * x1 * x1 if a1 == 0 and (c1 != 0 and b1 != 0): print(c1 / b1) elif b1 == 0: if c1 > 0 and a1 < 0 or a1 > 0 and c1 < 0: k = c1 / a1 print(k**0.5) else: dis = b1**2 - 4 * a1 * c1 if dis >= 0: dis = dis**0.5 t1 = (b1 + dis) / (2 * a1) t2 = (b1 - dis) / (2 * a1) if t1 > 0 and t2 > 0: print(min(t1, t2)) elif t1 > 0 and t2 < 0: print(t1) elif t1 < 0 and t2 > 0: print(t2) else: x1 = Qx - Cx y1 = Qy - Cy z1 = Qz - Cz AD2 = (Px - Cx) ** 2 + (Py - Cy) ** 2 + (Pz - Cz) ** 2 - r * r a = ( Px**2 + Py**2 + Pz**2 - Cx**2 - Cy**2 - Cz**2 + r**2 - AD2 - 2 * Px * Qx - 2 * Py * Qy - 2 * Pz * Qz + 2 * Cx * Qx + 2 * Cy * Qy + 2 * Cz * Qz ) b = ( 2 * Cx * dx + 2 * Cy * dy + 2 * Cz * dz - 2 * Py * dy - 2 * Px * dx - 2 * Pz * dz ) a1 = b**2 - 4 * AD2 * (dx**2 + dy**2 + dz**2) b1 = 2 * (-a * b + 4 * AD2 * (dx * (Qx - Cx) + dy * (Qy - Cy) + dz * (Qz - Cz))) k1 = x1 * x1 + y1 * y1 + z1 * z1 k2 = 4 * AD2 * k1 c1 = a**2 + 4 * AD2 * r * r - k2 if a1 == 0 and (c1 != 0 and b1 != 0): print(c1 / b1) elif b1 == 0: k = c1 / a1 print(k**0.5) else: dis = b1**2 - 4 * a1 * c1 if dis >= 0: dis = dis**0.5 t1 = (b1 + dis) / (2 * a1) t2 = (b1 - dis) / (2 * a1) if t1 > 0 and t2 > 0: print(min(t1, t2)) elif t1 > 0 and t2 < 0: print(t1) elif t1 < 0 and t2 > 0: print(t2)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN LIST VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP NUMBER VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given two points $P$ and $Q$ and an opaque sphere in a three-dimensional space. The point $P$ is not moving, while $Q$ is moving in a straight line with constant velocity. You are also given a direction vector $d$ with the following meaning: the position of $Q$ at time $t$ is $Q(t) = Q(0) + d \cdot t$, where $Q(0)$ is the initial position of $Q$. It is guaranteed that $Q$ is not visible from $P$ initially (at time $t=0$). It is also guaranteed that $P$ and $Q$ do not touch the sphere at any time. Find the smallest positive time $t_v$ when $Q$ is visible from $P$, i.e. when the line segment connecting points $P$ and $Q$ does not intersect the sphere. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains 13 space-separated integers. - The first three integers $P_x, P_y, P_z$ denote the coordinates of $P$. - The next three integers $Q_x, Q_y, Q_z$ denote the initial coordinates of $Q$. - The next three integers $d_x, d_y, d_z$ denote the components of the direction vector $d$. - The last four integers $c_x, c_y, c_z, r$ denote the coordinates of the centre of the sphere and its radius. -----Output----- For each test case, print a single line containing one real number — the time $t_v$. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$. It is guaranteed that $t_v$ exists and does not exceed $10^9$. -----Constraints----- - $1 \le T \le 10^5$ - the absolute values of coordinates of all points do not exceed $2\cdot10^9$ - $1 \le r \le 10^9$ -----Subtasks----- Subtask #1 (25 points): $P_z = Q_z = d_z = c_z = 0$ Subtask #2 (75 points): original constraints -----Example Input----- 1 3 0 0 -10 -10 0 0 10 0 0 -3 0 3 -----Example Output----- 1.0000000000
t = int(input()) for c in range(t): p, q, r, x, y, z, f, g, h, c, d, e, R = input().split() p = int(p) q = int(q) r = int(r) x = int(x) y = int(y) z = int(z) f = int(f) g = int(g) h = int(h) c = int(c) d = int(d) e = int(e) R = int(R) a1 = e * y - d * z + d * r + q * z - r * y - e * q b1 = e * g - d * h + q * h - r * g a2 = c * z - e * x + e * p - p * z + r * x - c * r b2 = c * h - e * f - p * h + r * f a3 = c * q - p * d + p * y + d * x - q * x - c * y b3 = p * g + d * f - q * f - c * g lhc = R * R * ((x - p) * (x - p) + (y - q) * (y - q) + (z - r) * (z - r)) lhs = R * R * (f * f + g * g + h * h) lhl = R * R * 2 * ((x - p) * f + (y - q) * g + (z - r) * h) rhc = a1 * a1 + a2 * a2 + a3 * a3 rhs = b1 * b1 + b2 * b2 + b3 * b3 rhl = 2 * (a1 * b1 + a2 * b2 + a3 * b3) fs = lhs - rhs fl = lhl - rhl fc = lhc - rhc if fs == 0: t1 = -1 * fc / fl print(t1) elif fl * fl - 4 * fs * fc == 0: t1 = -1 * fl / (2 * fs) print(t1) else: D = (fl * fl - 4 * fs * fc) ** 0.5 t1 = (-1 * fl + D) / (2 * fs) t2 = (-1 * fl - D) / (2 * fs) if t1 > 0: print(t1) if t2 > 0: print(t2)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given two points $P$ and $Q$ and an opaque sphere in a three-dimensional space. The point $P$ is not moving, while $Q$ is moving in a straight line with constant velocity. You are also given a direction vector $d$ with the following meaning: the position of $Q$ at time $t$ is $Q(t) = Q(0) + d \cdot t$, where $Q(0)$ is the initial position of $Q$. It is guaranteed that $Q$ is not visible from $P$ initially (at time $t=0$). It is also guaranteed that $P$ and $Q$ do not touch the sphere at any time. Find the smallest positive time $t_v$ when $Q$ is visible from $P$, i.e. when the line segment connecting points $P$ and $Q$ does not intersect the sphere. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains 13 space-separated integers. - The first three integers $P_x, P_y, P_z$ denote the coordinates of $P$. - The next three integers $Q_x, Q_y, Q_z$ denote the initial coordinates of $Q$. - The next three integers $d_x, d_y, d_z$ denote the components of the direction vector $d$. - The last four integers $c_x, c_y, c_z, r$ denote the coordinates of the centre of the sphere and its radius. -----Output----- For each test case, print a single line containing one real number — the time $t_v$. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$. It is guaranteed that $t_v$ exists and does not exceed $10^9$. -----Constraints----- - $1 \le T \le 10^5$ - the absolute values of coordinates of all points do not exceed $2\cdot10^9$ - $1 \le r \le 10^9$ -----Subtasks----- Subtask #1 (25 points): $P_z = Q_z = d_z = c_z = 0$ Subtask #2 (75 points): original constraints -----Example Input----- 1 3 0 0 -10 -10 0 0 10 0 0 -3 0 3 -----Example Output----- 1.0000000000
def dot(ax, ay, az, bx, by, bz): return ax * bx + ay * by + az * bz def findRoot(a, b, c): R1 = (-b + (b * b - 4 * a * c) ** 0.5) / (2 * a) R2 = (-b - (b * b - 4 * a * c) ** 0.5) / (2 * a) return R1, R2 T = int(input()) while T > 0: T -= 1 points = input().split() for i in range(len(points)): points[i] = float(points[i]) px = points[0] py = points[1] pz = points[2] qx = points[3] qy = points[4] qz = points[5] dx = points[6] dy = points[7] dz = points[8] cx = points[9] cy = points[10] cz = points[11] r = points[12] QPX = qx - px QPY = qy - py QPZ = qz - pz CPX = cx - px CPY = cy - py CPZ = cz - pz c1 = dot(QPX, QPY, QPZ, QPX, QPY, QPZ) c2 = 2 * dot(QPX, QPY, QPZ, dx, dy, dz) c3 = dot(dx, dy, dz, dx, dy, dz) lol = dot(QPX, QPY, QPZ, CPX, CPY, CPZ) lawl = dot(dx, dy, dz, CPX, CPY, CPZ) lmao = dot(CPX, CPY, CPZ, CPX, CPY, CPZ) a = r**2 * c3 - lmao * c3 + lawl**2 b = r**2 * c2 - lmao * c2 + 2 * lol * lawl c = r**2 * c1 - lmao * c1 + lol**2 if a == 0: print(-c / b) continue t1, t2 = findRoot(a, b, c) if t1 < 0: print(t2) elif t2 < 0: print(t1) else: print(min(t1, t2))
FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER BIN_OP NUMBER VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given two points $P$ and $Q$ and an opaque sphere in a three-dimensional space. The point $P$ is not moving, while $Q$ is moving in a straight line with constant velocity. You are also given a direction vector $d$ with the following meaning: the position of $Q$ at time $t$ is $Q(t) = Q(0) + d \cdot t$, where $Q(0)$ is the initial position of $Q$. It is guaranteed that $Q$ is not visible from $P$ initially (at time $t=0$). It is also guaranteed that $P$ and $Q$ do not touch the sphere at any time. Find the smallest positive time $t_v$ when $Q$ is visible from $P$, i.e. when the line segment connecting points $P$ and $Q$ does not intersect the sphere. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains 13 space-separated integers. - The first three integers $P_x, P_y, P_z$ denote the coordinates of $P$. - The next three integers $Q_x, Q_y, Q_z$ denote the initial coordinates of $Q$. - The next three integers $d_x, d_y, d_z$ denote the components of the direction vector $d$. - The last four integers $c_x, c_y, c_z, r$ denote the coordinates of the centre of the sphere and its radius. -----Output----- For each test case, print a single line containing one real number — the time $t_v$. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$. It is guaranteed that $t_v$ exists and does not exceed $10^9$. -----Constraints----- - $1 \le T \le 10^5$ - the absolute values of coordinates of all points do not exceed $2\cdot10^9$ - $1 \le r \le 10^9$ -----Subtasks----- Subtask #1 (25 points): $P_z = Q_z = d_z = c_z = 0$ Subtask #2 (75 points): original constraints -----Example Input----- 1 3 0 0 -10 -10 0 0 10 0 0 -3 0 3 -----Example Output----- 1.0000000000
def StringListToNumList(L): for i in range(0, len(L), 1): L[i] = int(L[i]) return L def DotProduct(Ax, Ay, Az, Bx, By, Bz): Answer = Ax * Bx + Ay * By + Az * Bz return Answer T = int(input("")) for k in range(0, T, 1): Input = input("") Input = Input.split(" ") Px = int(Input[0]) Py = int(Input[1]) Pz = int(Input[2]) Qx = int(Input[3]) Qy = int(Input[4]) Qz = int(Input[5]) dx = int(Input[6]) dy = int(Input[7]) dz = int(Input[8]) cx = int(Input[9]) cy = int(Input[10]) cz = int(Input[11]) r = int(Input[12]) Ax = Qx - Px Ay = Qy - Py Az = Qz - Pz Axy = Ax * Ay Ayz = Ay * Az Azx = Az * Ax Kx = Px - cx Ky = Py - cy Kz = Pz - cz Kxy = Kx * Ky Kyz = Ky * Kz Kzx = Kz * Kx A1 = Ky**2 + Kz**2 - r**2 A2 = Kx**2 + Kz**2 - r**2 A3 = Kx**2 + Ky**2 - r**2 dxy = dx * dy dyz = dy * dz dzx = dz * dx AA = A1 * dx**2 + A2 * dy**2 + A3 * dz**2 BB = Ax * A1 * dx + Ay * A2 * dy + Az * A3 * dz CC = A1 * Ax**2 + A2 * Ay**2 + A3 * Az**2 X = 2 * DotProduct(Kxy, Kyz, Kzx, dxy, dyz, dzx) - AA Y = 2 * ( Kxy * (Ax * dy + Ay * dx) + Kyz * (Ay * dz + Az * dy) + Kzx * (Az * dx + Ax * dz) - BB ) Z = 2 * DotProduct(Kxy, Kyz, Kzx, Axy, Ayz, Azx) - CC if X == 0: print(Z * -1 / Y) else: Answer1 = (-1 * Y + (Y**2 - 4 * X * Z) ** 0.5) / (2 * X) if Answer1 >= 0: print(Answer1) else: Answer2 = (-1 * Y - (Y**2 - 4 * X * Z) ** 0.5) / (2 * X) print(Answer2)
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR VAR NUMBER BIN_OP NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
You are given two points $P$ and $Q$ and an opaque sphere in a three-dimensional space. The point $P$ is not moving, while $Q$ is moving in a straight line with constant velocity. You are also given a direction vector $d$ with the following meaning: the position of $Q$ at time $t$ is $Q(t) = Q(0) + d \cdot t$, where $Q(0)$ is the initial position of $Q$. It is guaranteed that $Q$ is not visible from $P$ initially (at time $t=0$). It is also guaranteed that $P$ and $Q$ do not touch the sphere at any time. Find the smallest positive time $t_v$ when $Q$ is visible from $P$, i.e. when the line segment connecting points $P$ and $Q$ does not intersect the sphere. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains 13 space-separated integers. - The first three integers $P_x, P_y, P_z$ denote the coordinates of $P$. - The next three integers $Q_x, Q_y, Q_z$ denote the initial coordinates of $Q$. - The next three integers $d_x, d_y, d_z$ denote the components of the direction vector $d$. - The last four integers $c_x, c_y, c_z, r$ denote the coordinates of the centre of the sphere and its radius. -----Output----- For each test case, print a single line containing one real number — the time $t_v$. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$. It is guaranteed that $t_v$ exists and does not exceed $10^9$. -----Constraints----- - $1 \le T \le 10^5$ - the absolute values of coordinates of all points do not exceed $2\cdot10^9$ - $1 \le r \le 10^9$ -----Subtasks----- Subtask #1 (25 points): $P_z = Q_z = d_z = c_z = 0$ Subtask #2 (75 points): original constraints -----Example Input----- 1 3 0 0 -10 -10 0 0 10 0 0 -3 0 3 -----Example Output----- 1.0000000000
def dot(a, b): r = a[0] * b[0] + a[1] * b[1] + a[2] * b[2] return r for _ in range(int(input())): x1, y1, z1, x2, y2, z2, d1, d2, d3, c1, c2, c3, r = map(float, input().split()) a = x2 - x1 b = y2 - y1 c = z2 - z1 k = x1 - c1 l = y1 - c2 m = z1 - c3 term1 = r**2 * d1**2 + r**2 * d2**2 + r**2 * d3**2 term2 = (d1 * l - d2 * k) ** 2 + (d2 * m - d3 * l) ** 2 + (d3 * k - d1 * m) ** 2 A = term1 - term2 term11 = 2 * r**2 * (a * d1 + b * d2 + c * d3) term22 = 2 * ( (a * l - b * k) * (d1 * l - d2 * k) + (b * m - c * l) * (d2 * m - d3 * l) + (c * k - a * m) * (d3 * k - d1 * m) ) B = term11 - term22 ter1 = r**2 * (a**2 + b**2 + c**2) ter2 = (a * l - b * k) ** 2 + (b * m - c * l) ** 2 + (c * k - a * m) ** 2 C = ter1 - ter2 if A == 0: t = -1 * C / B print(t) continue else: t1 = (-1 * B + (B**2 - 4 * A * C) ** 0.5) / (2 * A) t2 = (-1 * B - (B**2 - 4 * A * C) ** 0.5) / (2 * A) t = 0 if t1 < 0: t = t2 elif t2 < 0: t = t1 elif t1 >= 0 and t2 >= 0: t = min(t1, t2) print(t)
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given two points $P$ and $Q$ and an opaque sphere in a three-dimensional space. The point $P$ is not moving, while $Q$ is moving in a straight line with constant velocity. You are also given a direction vector $d$ with the following meaning: the position of $Q$ at time $t$ is $Q(t) = Q(0) + d \cdot t$, where $Q(0)$ is the initial position of $Q$. It is guaranteed that $Q$ is not visible from $P$ initially (at time $t=0$). It is also guaranteed that $P$ and $Q$ do not touch the sphere at any time. Find the smallest positive time $t_v$ when $Q$ is visible from $P$, i.e. when the line segment connecting points $P$ and $Q$ does not intersect the sphere. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains 13 space-separated integers. - The first three integers $P_x, P_y, P_z$ denote the coordinates of $P$. - The next three integers $Q_x, Q_y, Q_z$ denote the initial coordinates of $Q$. - The next three integers $d_x, d_y, d_z$ denote the components of the direction vector $d$. - The last four integers $c_x, c_y, c_z, r$ denote the coordinates of the centre of the sphere and its radius. -----Output----- For each test case, print a single line containing one real number — the time $t_v$. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$. It is guaranteed that $t_v$ exists and does not exceed $10^9$. -----Constraints----- - $1 \le T \le 10^5$ - the absolute values of coordinates of all points do not exceed $2\cdot10^9$ - $1 \le r \le 10^9$ -----Subtasks----- Subtask #1 (25 points): $P_z = Q_z = d_z = c_z = 0$ Subtask #2 (75 points): original constraints -----Example Input----- 1 3 0 0 -10 -10 0 0 10 0 0 -3 0 3 -----Example Output----- 1.0000000000
def isSeen(x, y, z, Cx, Cy, Cz, CP2, R): a = x * Cx + y * Cy + z * Cz b = x * x + y * y + z * z return CP2 * b - a * a > R * R * b N = int(input()) for t in range(N): Px, Py, Pz, Qx, Qy, Qz, dx, dy, dz, Cx, Cy, Cz, R = [ int(i) for i in input().split() ] Qx = Qx - Px Qy = Qy - Py Qz = Qz - Pz Cx = Cx - Px Cy = Cy - Py Cz = Cz - Pz CP2 = Cx * Cx + Cy * Cy + Cz * Cz l = 0 h = 1100000000.0 m = (l + h) / 2 while h - l >= 1e-07: if isSeen(Qx + m * dx, Qy + m * dy, Qz + m * dz, Cx, Cy, Cz, CP2, R): h = m else: l = m m = (l + h) / 2 print(m)
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR RETURN BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given two points $P$ and $Q$ and an opaque sphere in a three-dimensional space. The point $P$ is not moving, while $Q$ is moving in a straight line with constant velocity. You are also given a direction vector $d$ with the following meaning: the position of $Q$ at time $t$ is $Q(t) = Q(0) + d \cdot t$, where $Q(0)$ is the initial position of $Q$. It is guaranteed that $Q$ is not visible from $P$ initially (at time $t=0$). It is also guaranteed that $P$ and $Q$ do not touch the sphere at any time. Find the smallest positive time $t_v$ when $Q$ is visible from $P$, i.e. when the line segment connecting points $P$ and $Q$ does not intersect the sphere. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains 13 space-separated integers. - The first three integers $P_x, P_y, P_z$ denote the coordinates of $P$. - The next three integers $Q_x, Q_y, Q_z$ denote the initial coordinates of $Q$. - The next three integers $d_x, d_y, d_z$ denote the components of the direction vector $d$. - The last four integers $c_x, c_y, c_z, r$ denote the coordinates of the centre of the sphere and its radius. -----Output----- For each test case, print a single line containing one real number — the time $t_v$. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$. It is guaranteed that $t_v$ exists and does not exceed $10^9$. -----Constraints----- - $1 \le T \le 10^5$ - the absolute values of coordinates of all points do not exceed $2\cdot10^9$ - $1 \le r \le 10^9$ -----Subtasks----- Subtask #1 (25 points): $P_z = Q_z = d_z = c_z = 0$ Subtask #2 (75 points): original constraints -----Example Input----- 1 3 0 0 -10 -10 0 0 10 0 0 -3 0 3 -----Example Output----- 1.0000000000
for _ in range(int(input())): x1, y1, z1, x2, y2, z2, d1, d2, d3, c1, c2, c3, r = map(float, input().split()) cc = z2 - z1 kk = x1 - c1 aa = x2 - x1 bb = y2 - y1 l = y1 - c2 mm = z1 - c3 ta1 = (d1 * l - d2 * kk) ** 2 + (d2 * mm - d3 * l) ** 2 + (d3 * kk - d1 * mm) ** 2 rr = r**2 ta2 = rr * d1 * d1 + rr * d2 * d2 + rr * d3 * d3 tb1 = 2 * (aa * l - bb * kk) * (d1 * l - d2 * kk) + 2 * (bb * mm - cc * l) * ( d2 * mm - d3 * l ) tb1 += 2 * (cc * kk - aa * mm) * (d3 * kk - d1 * mm) tb2 = 2 * aa * rr * d1 + 2 * bb * rr * d2 + 2 * cc * rr * d3 tc1 = ( (aa * l - bb * kk) * (aa * l - bb * kk) + (bb * mm - cc * l) * (bb * mm - cc * l) + (cc * kk - aa * mm) * (cc * kk - aa * mm) ) tc2 = aa * aa * rr + bb * bb * rr + cc * cc * rr fta = ta2 - ta1 ftb = tb2 - tb1 ftc = tc2 - tc1 if fta != 0: ans1 = (-1 * ftb + (ftb**2 - 4 * fta * ftc) ** 0.5) / (2 * fta) ans2 = (-1 * ftb - (ftb**2 - 4 * fta * ftc) ** 0.5) / (2 * fta) ans3 = 0 if ans1 < 0: ans3 = ans2 elif ans2 < 0: ans3 = ans1 elif ans1 > 0 and ans2 > 0: ans3 = min(ans1, ans2) else: ans3 = -ftc / ftb print(ans3)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
You are given two points $P$ and $Q$ and an opaque sphere in a three-dimensional space. The point $P$ is not moving, while $Q$ is moving in a straight line with constant velocity. You are also given a direction vector $d$ with the following meaning: the position of $Q$ at time $t$ is $Q(t) = Q(0) + d \cdot t$, where $Q(0)$ is the initial position of $Q$. It is guaranteed that $Q$ is not visible from $P$ initially (at time $t=0$). It is also guaranteed that $P$ and $Q$ do not touch the sphere at any time. Find the smallest positive time $t_v$ when $Q$ is visible from $P$, i.e. when the line segment connecting points $P$ and $Q$ does not intersect the sphere. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains 13 space-separated integers. - The first three integers $P_x, P_y, P_z$ denote the coordinates of $P$. - The next three integers $Q_x, Q_y, Q_z$ denote the initial coordinates of $Q$. - The next three integers $d_x, d_y, d_z$ denote the components of the direction vector $d$. - The last four integers $c_x, c_y, c_z, r$ denote the coordinates of the centre of the sphere and its radius. -----Output----- For each test case, print a single line containing one real number — the time $t_v$. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$. It is guaranteed that $t_v$ exists and does not exceed $10^9$. -----Constraints----- - $1 \le T \le 10^5$ - the absolute values of coordinates of all points do not exceed $2\cdot10^9$ - $1 \le r \le 10^9$ -----Subtasks----- Subtask #1 (25 points): $P_z = Q_z = d_z = c_z = 0$ Subtask #2 (75 points): original constraints -----Example Input----- 1 3 0 0 -10 -10 0 0 10 0 0 -3 0 3 -----Example Output----- 1.0000000000
def dot(a, b): r1 = a[0] * b[0] r2 = a[1] * b[1] r3 = a[2] * b[2] r = r1 + r2 + r3 return r for i in range(int(input())): x1, y1, z1, x2, y2, z2, d1, d2, d3, c1, c2, c3, r = map(float, input().split()) t1 = r**2 * d1**2 + r**2 * d2**2 + r**2 * d3**2 t2 = ( (d1 * (y1 - c2) - d2 * (x1 - c1)) ** 2 + (d2 * (z1 - c3) - d3 * (y1 - c2)) ** 2 + (d3 * (x1 - c1) - d1 * (z1 - c3)) ** 2 ) A = t1 - t2 t11 = 2 * r**2 * ((x2 - x1) * d1 + (y2 - y1) * d2 + (z2 - z1) * d3) t22 = 2 * ( ((x2 - x1) * (y1 - c2) - (y2 - y1) * (x1 - c1)) * (d1 * (y1 - c2) - d2 * (x1 - c1)) + ((y2 - y1) * (z1 - c3) - (z2 - z1) * (y1 - c2)) * (d2 * (z1 - c3) - d3 * (y1 - c2)) + ((z2 - z1) * (x1 - c1) - (x2 - x1) * (z1 - c3)) * (d3 * (x1 - c1) - d1 * (z1 - c3)) ) B = t11 - t22 t111 = r**2 * ((x2 - x1) ** 2 + (y2 - y1) ** 2 + (z2 - z1) ** 2) t222 = ( ((x2 - x1) * (y1 - c2) - (y2 - y1) * (x1 - c1)) ** 2 + ((y2 - y1) * (z1 - c3) - (z2 - z1) * (y1 - c2)) ** 2 + ((z2 - z1) * (x1 - c1) - (x2 - x1) * (z1 - c3)) ** 2 ) C = t111 - t222 if A != 0: Z = 2 * A t1 = (-1 * B + (B**2 - 4 * A * C) ** 0.5) / Z t2 = (-1 * B - (B**2 - 4 * A * C) ** 0.5) / Z t = 0 q = 0 if t2 < q: t = t1 elif t1 < q: t = t2 elif t1 >= q and t2 >= q: if t1 > t2: t = t2 elif t2 > t1: t = t1 print("%.10f" % t) elif A == 0: t = -1 * C / B print("%.10f" % t) continue
FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR
You are given two points $P$ and $Q$ and an opaque sphere in a three-dimensional space. The point $P$ is not moving, while $Q$ is moving in a straight line with constant velocity. You are also given a direction vector $d$ with the following meaning: the position of $Q$ at time $t$ is $Q(t) = Q(0) + d \cdot t$, where $Q(0)$ is the initial position of $Q$. It is guaranteed that $Q$ is not visible from $P$ initially (at time $t=0$). It is also guaranteed that $P$ and $Q$ do not touch the sphere at any time. Find the smallest positive time $t_v$ when $Q$ is visible from $P$, i.e. when the line segment connecting points $P$ and $Q$ does not intersect the sphere. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains 13 space-separated integers. - The first three integers $P_x, P_y, P_z$ denote the coordinates of $P$. - The next three integers $Q_x, Q_y, Q_z$ denote the initial coordinates of $Q$. - The next three integers $d_x, d_y, d_z$ denote the components of the direction vector $d$. - The last four integers $c_x, c_y, c_z, r$ denote the coordinates of the centre of the sphere and its radius. -----Output----- For each test case, print a single line containing one real number — the time $t_v$. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$. It is guaranteed that $t_v$ exists and does not exceed $10^9$. -----Constraints----- - $1 \le T \le 10^5$ - the absolute values of coordinates of all points do not exceed $2\cdot10^9$ - $1 \le r \le 10^9$ -----Subtasks----- Subtask #1 (25 points): $P_z = Q_z = d_z = c_z = 0$ Subtask #2 (75 points): original constraints -----Example Input----- 1 3 0 0 -10 -10 0 0 10 0 0 -3 0 3 -----Example Output----- 1.0000000000
T = int(input()) while T: px, py, pz, qx, qy, qz, dx, dy, dz, cx, cy, cz, r = map(int, input().split()) x = qx - px y = qy - py z = qz - pz a = px - cx b = py - cy c = pz - cz e = a * a + b * b + c * c x1 = r * r + a * a - e y1 = r * r + b * b - e z1 = r * r + c * c - e A = ( x1 * dx * dx + y1 * dy * dy + z1 * dz * dz + 2 * (a * b * dx * dy + c * b * dz * dy + a * c * dx * dz) ) B = 2 * ( x1 * x * dx + y1 * y * dy + z1 * z * dz + a * b * x * dy + a * b * y * dx + a * c * x * dz + a * c * z * dx + c * b * z * dy + c * b * y * dz ) C = ( x1 * x * x + y1 * y * y + z1 * z * z + 2 * a * b * x * y + 2 * a * c * x * z + 2 * c * b * z * y ) if A != 0: discr = B * B - 4 * A * C discr = discr**0.5 root1 = (-1 * B + discr) / (2 * A) root2 = (-1 * B - discr) / (2 * A) if root1 >= 0 and root2 >= 0: if root1 > root2: print(root1) else: print(root2) elif root1 >= 0: print(root1) else: print(root2) else: time = -1 * C / B print(time) T -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP NUMBER BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
You are given two points $P$ and $Q$ and an opaque sphere in a three-dimensional space. The point $P$ is not moving, while $Q$ is moving in a straight line with constant velocity. You are also given a direction vector $d$ with the following meaning: the position of $Q$ at time $t$ is $Q(t) = Q(0) + d \cdot t$, where $Q(0)$ is the initial position of $Q$. It is guaranteed that $Q$ is not visible from $P$ initially (at time $t=0$). It is also guaranteed that $P$ and $Q$ do not touch the sphere at any time. Find the smallest positive time $t_v$ when $Q$ is visible from $P$, i.e. when the line segment connecting points $P$ and $Q$ does not intersect the sphere. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains 13 space-separated integers. - The first three integers $P_x, P_y, P_z$ denote the coordinates of $P$. - The next three integers $Q_x, Q_y, Q_z$ denote the initial coordinates of $Q$. - The next three integers $d_x, d_y, d_z$ denote the components of the direction vector $d$. - The last four integers $c_x, c_y, c_z, r$ denote the coordinates of the centre of the sphere and its radius. -----Output----- For each test case, print a single line containing one real number — the time $t_v$. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$. It is guaranteed that $t_v$ exists and does not exceed $10^9$. -----Constraints----- - $1 \le T \le 10^5$ - the absolute values of coordinates of all points do not exceed $2\cdot10^9$ - $1 \le r \le 10^9$ -----Subtasks----- Subtask #1 (25 points): $P_z = Q_z = d_z = c_z = 0$ Subtask #2 (75 points): original constraints -----Example Input----- 1 3 0 0 -10 -10 0 0 10 0 0 -3 0 3 -----Example Output----- 1.0000000000
t = int(input()) while t: px, py, pz, qx, qy, qz, dx, dy, dz, cx, cy, cz, r = map(int, input().split()) a = px - cx b = py - cy c = pz - cz d = qx - cx e = qy - cy f = qz - cz alpha = a * d + b * e + c * f - r * r beta = a * dx + b * dy + c * dz k = a * a + b * b + c * c - r * r g = (dx * dx + dy * dy + dz * dz) * k h = (d * dx + e * dy + f * dz) * 2 * k i = (d * d + e * e + f * f - r * r) * k p = beta * beta - g q = 2 * alpha * beta - h r1 = alpha * alpha - i if p != 0: discr = (q * q - 4 * p * r1) ** (1 / 2) t1 = (-q + discr) / 2 / p t2 = (-q - discr) / 2 / p if t1 <= t2: if t1 >= 0: print(t1) else: print(t2) elif t2 >= 0: print(t2) else: print(t1) if p == 0: t1 = -r1 / q print(t1) t = t - 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER VAR VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
You are given two points $P$ and $Q$ and an opaque sphere in a three-dimensional space. The point $P$ is not moving, while $Q$ is moving in a straight line with constant velocity. You are also given a direction vector $d$ with the following meaning: the position of $Q$ at time $t$ is $Q(t) = Q(0) + d \cdot t$, where $Q(0)$ is the initial position of $Q$. It is guaranteed that $Q$ is not visible from $P$ initially (at time $t=0$). It is also guaranteed that $P$ and $Q$ do not touch the sphere at any time. Find the smallest positive time $t_v$ when $Q$ is visible from $P$, i.e. when the line segment connecting points $P$ and $Q$ does not intersect the sphere. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains 13 space-separated integers. - The first three integers $P_x, P_y, P_z$ denote the coordinates of $P$. - The next three integers $Q_x, Q_y, Q_z$ denote the initial coordinates of $Q$. - The next three integers $d_x, d_y, d_z$ denote the components of the direction vector $d$. - The last four integers $c_x, c_y, c_z, r$ denote the coordinates of the centre of the sphere and its radius. -----Output----- For each test case, print a single line containing one real number — the time $t_v$. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$. It is guaranteed that $t_v$ exists and does not exceed $10^9$. -----Constraints----- - $1 \le T \le 10^5$ - the absolute values of coordinates of all points do not exceed $2\cdot10^9$ - $1 \le r \le 10^9$ -----Subtasks----- Subtask #1 (25 points): $P_z = Q_z = d_z = c_z = 0$ Subtask #2 (75 points): original constraints -----Example Input----- 1 3 0 0 -10 -10 0 0 10 0 0 -3 0 3 -----Example Output----- 1.0000000000
def snek(s): a1 = x0 + s1 * s - x1 a2 = y0 + s2 * s - y1 a3 = z0 + s3 * s - z1 b = 4 * (a1 * d1 + a2 * d2 + a3 * d3) * (a1 * d1 + a2 * d2 + a3 * d3) a = 4 * (a1 * a1 + a2 * a2 + a3 * a3) v = b - a * c return v t = int(input()) for i in range(t): x1, y1, z1, x0, y0, z0, s1, s2, s3, cx, cy, cz, r = map(int, input().split()) d1 = x1 - cx d2 = y1 - cy d3 = z1 - cz c = d1 * d1 + d2 * d2 + d3 * d3 - r * r l = 0 h = 10**9 + 1 while l < h - 10**-6: m = l + (h - l) * 1.0 / 2 v = snek(m) if abs(v) <= 10**-2: break elif v > 0: l = m else: h = m print(m)
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER WHILE VAR BIN_OP VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
You are given two points $P$ and $Q$ and an opaque sphere in a three-dimensional space. The point $P$ is not moving, while $Q$ is moving in a straight line with constant velocity. You are also given a direction vector $d$ with the following meaning: the position of $Q$ at time $t$ is $Q(t) = Q(0) + d \cdot t$, where $Q(0)$ is the initial position of $Q$. It is guaranteed that $Q$ is not visible from $P$ initially (at time $t=0$). It is also guaranteed that $P$ and $Q$ do not touch the sphere at any time. Find the smallest positive time $t_v$ when $Q$ is visible from $P$, i.e. when the line segment connecting points $P$ and $Q$ does not intersect the sphere. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains 13 space-separated integers. - The first three integers $P_x, P_y, P_z$ denote the coordinates of $P$. - The next three integers $Q_x, Q_y, Q_z$ denote the initial coordinates of $Q$. - The next three integers $d_x, d_y, d_z$ denote the components of the direction vector $d$. - The last four integers $c_x, c_y, c_z, r$ denote the coordinates of the centre of the sphere and its radius. -----Output----- For each test case, print a single line containing one real number — the time $t_v$. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$. It is guaranteed that $t_v$ exists and does not exceed $10^9$. -----Constraints----- - $1 \le T \le 10^5$ - the absolute values of coordinates of all points do not exceed $2\cdot10^9$ - $1 \le r \le 10^9$ -----Subtasks----- Subtask #1 (25 points): $P_z = Q_z = d_z = c_z = 0$ Subtask #2 (75 points): original constraints -----Example Input----- 1 3 0 0 -10 -10 0 0 10 0 0 -3 0 3 -----Example Output----- 1.0000000000
t = int(input()) while t: t -= 1 Px, Py, Pz, Qx, Qy, Qz, dx, dy, dz, cx, cy, cz, r = [ int(s) for s in input().split(" ") ] ax = Px - cx x = Qx - Px ay = Py - cy y = Qy - Py az = Pz - cz z = Qz - Pz A = ( (az * dy - ay * dz) * (az * dy - ay * dz) + (az * dx - ax * dz) * (az * dx - ax * dz) + (ax * dy - ay * dx) * (ax * dy - ay * dx) - r * r * (dx * dx + dy * dy + dz * dz) ) C = ( (y * az - z * ay) * (y * az - z * ay) + (x * az - z * ax) * (x * az - z * ax) + (y * ax - x * ay) * (y * ax - x * ay) - r * r * (x * x + y * y + z * z) ) B = 2 * ( (y * ax - x * ay) * (dy * ax - dx * ay) + (y * az - z * ay) * (dy * az - dz * ay) + (z * ax - x * az) * (dz * ax - dx * az) - r * r * (x * dx + y * dy + z * dz) ) if A == 0: time = -1 * C / B else: time = ((B * B - 4 * A * C) ** 0.5 - B) / (2 * A) print(time)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
You are given two points $P$ and $Q$ and an opaque sphere in a three-dimensional space. The point $P$ is not moving, while $Q$ is moving in a straight line with constant velocity. You are also given a direction vector $d$ with the following meaning: the position of $Q$ at time $t$ is $Q(t) = Q(0) + d \cdot t$, where $Q(0)$ is the initial position of $Q$. It is guaranteed that $Q$ is not visible from $P$ initially (at time $t=0$). It is also guaranteed that $P$ and $Q$ do not touch the sphere at any time. Find the smallest positive time $t_v$ when $Q$ is visible from $P$, i.e. when the line segment connecting points $P$ and $Q$ does not intersect the sphere. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains 13 space-separated integers. - The first three integers $P_x, P_y, P_z$ denote the coordinates of $P$. - The next three integers $Q_x, Q_y, Q_z$ denote the initial coordinates of $Q$. - The next three integers $d_x, d_y, d_z$ denote the components of the direction vector $d$. - The last four integers $c_x, c_y, c_z, r$ denote the coordinates of the centre of the sphere and its radius. -----Output----- For each test case, print a single line containing one real number — the time $t_v$. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$. It is guaranteed that $t_v$ exists and does not exceed $10^9$. -----Constraints----- - $1 \le T \le 10^5$ - the absolute values of coordinates of all points do not exceed $2\cdot10^9$ - $1 \le r \le 10^9$ -----Subtasks----- Subtask #1 (25 points): $P_z = Q_z = d_z = c_z = 0$ Subtask #2 (75 points): original constraints -----Example Input----- 1 3 0 0 -10 -10 0 0 10 0 0 -3 0 3 -----Example Output----- 1.0000000000
class point: def __init__(self, x, y, z): self.x = x self.y = y self.z = z def sub(p, q): return point(p.x - q.x, p.y - q.y, p.z - q.z) def dot(p, q): return p.x * q.x + p.y * q.y + p.z * q.z def cross(p, q): return point(p.y * q.z - p.z * q.y, p.z * q.x - p.x * q.z, p.x * q.y - p.y * q.x) def modsq(p): return p.x**2 + p.y**2 + p.z**2 def solve(): px, py, pz, qx, qy, qz, dx, dy, dz, cx, cy, cz, r = map(int, input().split()) p = point(px, py, pz) q = point(qx, qy, qz) d = point(dx, dy, dz) c = point(cx, cy, cz) c1 = modsq(cross(d, sub(c, p))) - modsq(d) * r * r c2 = dot(cross(sub(q, p), sub(c, p)), cross(d, sub(c, p))) - r * r * dot( d, sub(q, p) ) c2 *= 2 c3 = modsq(cross(sub(q, p), sub(c, p))) - modsq(sub(q, p)) * r * r if c1 == 0: print(-c3 / c2) return print((-c2 + (c2**2 - 4 * c1 * c3) ** 0.5) / (2 * c1)) t = int(input()) for i in range(t): solve()
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given two points $P$ and $Q$ and an opaque sphere in a three-dimensional space. The point $P$ is not moving, while $Q$ is moving in a straight line with constant velocity. You are also given a direction vector $d$ with the following meaning: the position of $Q$ at time $t$ is $Q(t) = Q(0) + d \cdot t$, where $Q(0)$ is the initial position of $Q$. It is guaranteed that $Q$ is not visible from $P$ initially (at time $t=0$). It is also guaranteed that $P$ and $Q$ do not touch the sphere at any time. Find the smallest positive time $t_v$ when $Q$ is visible from $P$, i.e. when the line segment connecting points $P$ and $Q$ does not intersect the sphere. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains 13 space-separated integers. - The first three integers $P_x, P_y, P_z$ denote the coordinates of $P$. - The next three integers $Q_x, Q_y, Q_z$ denote the initial coordinates of $Q$. - The next three integers $d_x, d_y, d_z$ denote the components of the direction vector $d$. - The last four integers $c_x, c_y, c_z, r$ denote the coordinates of the centre of the sphere and its radius. -----Output----- For each test case, print a single line containing one real number — the time $t_v$. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$. It is guaranteed that $t_v$ exists and does not exceed $10^9$. -----Constraints----- - $1 \le T \le 10^5$ - the absolute values of coordinates of all points do not exceed $2\cdot10^9$ - $1 \le r \le 10^9$ -----Subtasks----- Subtask #1 (25 points): $P_z = Q_z = d_z = c_z = 0$ Subtask #2 (75 points): original constraints -----Example Input----- 1 3 0 0 -10 -10 0 0 10 0 0 -3 0 3 -----Example Output----- 1.0000000000
x = int(input()) for i in range(x): arr = list(map(int, input().split())) px = arr[0] py = arr[1] pz = arr[2] qx = arr[3] - arr[0] qy = arr[4] - arr[1] qz = arr[5] - arr[2] dx = arr[6] dy = arr[7] dz = arr[8] cx = arr[9] cy = arr[10] cz = arr[11] r = arr[12] x_ = ( r**2 + (px - cx) ** 2 - ((px - cx) * (px - cx) + (py - cy) * (py - cy) + (pz - cz) * (pz - cz)) ) y_ = ( r**2 + (py - cy) ** 2 - ((px - cx) * (px - cx) + (py - cy) * (py - cy) + (pz - cz) * (pz - cz)) ) z_ = ( r**2 + (pz - cz) ** 2 - ((px - cx) * (px - cx) + (py - cy) * (py - cy) + (pz - cz) * (pz - cz)) ) a1 = x_ * dx * dx + y_ * dy * dy + z_ * dz * dz a2 = 2 * ( (px - cx) * (py - cy) * dx * dy + (pz - cz) * (py - cy) * dz * dy + (px - cx) * (pz - cz) * dx * dz ) B = 2 * ( x_ * qx * dx + y_ * qy * dy + z_ * qz * dz + (px - cx) * (py - cy) * qx * dy + (px - cx) * (py - cy) * qy * dx + (px - cx) * (pz - cz) * qx * dz + (px - cx) * (pz - cz) * qz * dx + (pz - cz) * (py - cy) * qz * dy + (pz - cz) * (py - cy) * qy * dz ) c1 = x_ * qx * qx + y_ * qy * qy + z_ * qz * qz c2 = ( 2 * (px - cx) * (py - cy) * qx * qy + 2 * (px - cx) * (pz - cz) * qx * qz + 2 * (pz - cz) * (py - cy) * qz * qy ) if a1 + a2 == 0: print(-(c1 + c2) / B) else: ans1 = (-B + (B**2 - 4 * (a1 + a2) * (c1 + c2)) ** 0.5) / (2 * (a1 + a2)) ans2 = (-B - (B**2 - 4 * (a1 + a2) * (c1 + c2)) ** 0.5) / (2 * (a1 + a2)) if ans1 >= 0 and ans2 >= 0: if ans1 > ans2: print(ans1) else: print(ans2) elif ans2 >= 0: print(ans2) else: print(ans1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP VAR VAR BIN_OP VAR VAR NUMBER BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP VAR VAR BIN_OP VAR VAR NUMBER BIN_OP NUMBER BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You are given two points $P$ and $Q$ and an opaque sphere in a three-dimensional space. The point $P$ is not moving, while $Q$ is moving in a straight line with constant velocity. You are also given a direction vector $d$ with the following meaning: the position of $Q$ at time $t$ is $Q(t) = Q(0) + d \cdot t$, where $Q(0)$ is the initial position of $Q$. It is guaranteed that $Q$ is not visible from $P$ initially (at time $t=0$). It is also guaranteed that $P$ and $Q$ do not touch the sphere at any time. Find the smallest positive time $t_v$ when $Q$ is visible from $P$, i.e. when the line segment connecting points $P$ and $Q$ does not intersect the sphere. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains 13 space-separated integers. - The first three integers $P_x, P_y, P_z$ denote the coordinates of $P$. - The next three integers $Q_x, Q_y, Q_z$ denote the initial coordinates of $Q$. - The next three integers $d_x, d_y, d_z$ denote the components of the direction vector $d$. - The last four integers $c_x, c_y, c_z, r$ denote the coordinates of the centre of the sphere and its radius. -----Output----- For each test case, print a single line containing one real number — the time $t_v$. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$. It is guaranteed that $t_v$ exists and does not exceed $10^9$. -----Constraints----- - $1 \le T \le 10^5$ - the absolute values of coordinates of all points do not exceed $2\cdot10^9$ - $1 \le r \le 10^9$ -----Subtasks----- Subtask #1 (25 points): $P_z = Q_z = d_z = c_z = 0$ Subtask #2 (75 points): original constraints -----Example Input----- 1 3 0 0 -10 -10 0 0 10 0 0 -3 0 3 -----Example Output----- 1.0000000000
t = int(input()) for i in range(t): px, py, pz, qx, qy, qz, dx, dy, dz, cx, cy, cz, r = [ float(x) for x in input().split() ] a = cx - px b = cy - py c = cz - pz d = qx - px e = qy - py f = qz - pz A = r * r * (dx * dx + dy * dy + dz * dz) - ( (a * dy - b * dx) ** 2 + (b * dz - c * dy) ** 2 + (c * dx - a * dz) ** 2 ) tb1 = 2 * r * r * (dx * d + dy * e + dz * f) asq = a * a bsq = b * b csq = c * c dsq = d * d esq = e * e fsq = f * f absq = asq + bsq bcsq = bsq + csq acsq = asq + csq cf = c * f be = b * e ad = a * d tb2 = 2 * ( dx * (a * (cf + be) - d * bcsq) + dy * (b * (cf + ad) - e * acsq) + dz * (c * (be + ad) - f * absq) ) B = tb1 + tb2 tc1 = r * r * (dsq + esq + fsq) - absq * fsq - acsq * esq - bcsq * dsq C = tc1 + 2 * (be * cf + ad * cf + ad * be) if A == 0: t = -1 * (C / B) print(t) else: t1 = (-B + (B * B - 4 * A * C) ** 0.5) / (2 * A) t2 = (-B - (B * B - 4 * A * C) ** 0.5) / (2 * A) if t1 < 0: print(t2) elif t2 < 0: print(t1) else: print(min(t1, t2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER BIN_OP NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given two points $P$ and $Q$ and an opaque sphere in a three-dimensional space. The point $P$ is not moving, while $Q$ is moving in a straight line with constant velocity. You are also given a direction vector $d$ with the following meaning: the position of $Q$ at time $t$ is $Q(t) = Q(0) + d \cdot t$, where $Q(0)$ is the initial position of $Q$. It is guaranteed that $Q$ is not visible from $P$ initially (at time $t=0$). It is also guaranteed that $P$ and $Q$ do not touch the sphere at any time. Find the smallest positive time $t_v$ when $Q$ is visible from $P$, i.e. when the line segment connecting points $P$ and $Q$ does not intersect the sphere. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains 13 space-separated integers. - The first three integers $P_x, P_y, P_z$ denote the coordinates of $P$. - The next three integers $Q_x, Q_y, Q_z$ denote the initial coordinates of $Q$. - The next three integers $d_x, d_y, d_z$ denote the components of the direction vector $d$. - The last four integers $c_x, c_y, c_z, r$ denote the coordinates of the centre of the sphere and its radius. -----Output----- For each test case, print a single line containing one real number — the time $t_v$. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$. It is guaranteed that $t_v$ exists and does not exceed $10^9$. -----Constraints----- - $1 \le T \le 10^5$ - the absolute values of coordinates of all points do not exceed $2\cdot10^9$ - $1 \le r \le 10^9$ -----Subtasks----- Subtask #1 (25 points): $P_z = Q_z = d_z = c_z = 0$ Subtask #2 (75 points): original constraints -----Example Input----- 1 3 0 0 -10 -10 0 0 10 0 0 -3 0 3 -----Example Output----- 1.0000000000
t = int(input()) for i in range(t): lis = input() arr = list(map(int, lis.split(" "))) x1 = arr[0] y1 = arr[1] z1 = arr[2] x0 = arr[3] y0 = arr[4] z0 = arr[5] d1 = arr[6] d2 = arr[7] d3 = arr[8] x3 = arr[9] y3 = arr[10] z3 = arr[11] r = arr[12] k = (x0 - x1) * (x1 - x3) + (y0 - y1) * (y1 - y3) + (z0 - z1) * (z1 - z3) k1 = d1 * (x1 - x3) + d2 * (y1 - y3) + d3 * (z1 - z3) k2 = ( x3 * x3 + y3 * y3 + z3 * z3 + x1 * x1 + y1 * y1 + z1 * z1 - 2 * (x1 * x3 + y1 * y3 + z1 * z3) - r * r ) k3 = (x0 - x1) * (x0 - x1) + (y0 - y1) * (y0 - y1) + (z0 - z1) * (z0 - z1) k4 = d1 * d1 + d2 * d2 + d3 * d3 k5 = d1 * (x0 - x1) + d2 * (y0 - y1) + d3 * (z0 - z1) a = k1 * k1 - k2 * k4 b = 2 * (k * k1 - k2 * k5) c = k * k - k2 * k3 if a != 0: t1 = float((-b + (b * b - 4 * a * c) ** 0.5) / (2 * a)) t2 = float((-b - (b * b - 4 * a * c) ** 0.5) / (2 * a)) if t1 > 0 and t2 > 0: ans = float(min(t1, t2)) print("%.9f" % ans) elif t1 > 0: print("%.9f" % t1) else: print("%.9f" % t2) else: t = float(-c / b) print("%.9f" % t)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR
Given an integer x, find the square root of x. If x is not a perfect square, then return floor(√x). Example 1: Input: x = 5 Output: 2 Explanation: Since, 5 is not a perfect square, floor of square_root of 5 is 2. Example 2: Input: x = 4 Output: 2 Explanation: Since, 4 is a perfect square, so its square root is 2. Your Task: You don't need to read input or print anything. The task is to complete the function floorSqrt() which takes x as the input parameter and return its square root. Note: Try Solving the question without using the sqrt function. The value of x>=0. Expected Time Complexity: O(log N) Expected Auxiliary Space: O(1) Constraints: 1 ≤ x ≤ 10^{7}
class Solution: def floorSqrt(self, x): start = 1 end = x // 2 + 1 ans = -1 while start <= end: mid = start + (end - start) // 2 square = mid * mid if square == x: ans = mid break elif square > x: end = mid - 1 else: ans = mid start = mid + 1 return ans
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
Given an integer x, find the square root of x. If x is not a perfect square, then return floor(√x). Example 1: Input: x = 5 Output: 2 Explanation: Since, 5 is not a perfect square, floor of square_root of 5 is 2. Example 2: Input: x = 4 Output: 2 Explanation: Since, 4 is a perfect square, so its square root is 2. Your Task: You don't need to read input or print anything. The task is to complete the function floorSqrt() which takes x as the input parameter and return its square root. Note: Try Solving the question without using the sqrt function. The value of x>=0. Expected Time Complexity: O(log N) Expected Auxiliary Space: O(1) Constraints: 1 ≤ x ≤ 10^{7}
class Solution: def floorSqrt(self, x): low = 1 high = x while low != high: mid = (low + high) // 2 if mid * mid == x: return mid elif mid * mid > x: if high == mid: return mid high = mid else: if low == mid: return mid low = mid return 1
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR RETURN VAR IF BIN_OP VAR VAR VAR IF VAR VAR RETURN VAR ASSIGN VAR VAR IF VAR VAR RETURN VAR ASSIGN VAR VAR RETURN NUMBER
Given an integer x, find the square root of x. If x is not a perfect square, then return floor(√x). Example 1: Input: x = 5 Output: 2 Explanation: Since, 5 is not a perfect square, floor of square_root of 5 is 2. Example 2: Input: x = 4 Output: 2 Explanation: Since, 4 is a perfect square, so its square root is 2. Your Task: You don't need to read input or print anything. The task is to complete the function floorSqrt() which takes x as the input parameter and return its square root. Note: Try Solving the question without using the sqrt function. The value of x>=0. Expected Time Complexity: O(log N) Expected Auxiliary Space: O(1) Constraints: 1 ≤ x ≤ 10^{7}
class Solution: def floorSqrt(self, x): s = 0 e = x while s <= e: mid = (s + e) // 2 if mid * mid == x: return mid elif mid * mid > x: e = mid - 1 else: s = mid + 1 return e
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR RETURN VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
Given an integer x, find the square root of x. If x is not a perfect square, then return floor(√x). Example 1: Input: x = 5 Output: 2 Explanation: Since, 5 is not a perfect square, floor of square_root of 5 is 2. Example 2: Input: x = 4 Output: 2 Explanation: Since, 4 is a perfect square, so its square root is 2. Your Task: You don't need to read input or print anything. The task is to complete the function floorSqrt() which takes x as the input parameter and return its square root. Note: Try Solving the question without using the sqrt function. The value of x>=0. Expected Time Complexity: O(log N) Expected Auxiliary Space: O(1) Constraints: 1 ≤ x ≤ 10^{7}
class Solution: def floorSqrt(self, x): l = 1 if x < 4: return 1 r = x mid = (r + l) // 2 while l <= r: if mid * mid > x: r = mid - 1 if mid * mid < x: l = mid + 1 if mid * mid == x: return mid mid = (r + l) // 2 return mid
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR RETURN VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR
Given an integer x, find the square root of x. If x is not a perfect square, then return floor(√x). Example 1: Input: x = 5 Output: 2 Explanation: Since, 5 is not a perfect square, floor of square_root of 5 is 2. Example 2: Input: x = 4 Output: 2 Explanation: Since, 4 is a perfect square, so its square root is 2. Your Task: You don't need to read input or print anything. The task is to complete the function floorSqrt() which takes x as the input parameter and return its square root. Note: Try Solving the question without using the sqrt function. The value of x>=0. Expected Time Complexity: O(log N) Expected Auxiliary Space: O(1) Constraints: 1 ≤ x ≤ 10^{7}
class Solution: def floorSqrt(self, x): for i in range(1, int(x**0.5 + 1)): if i * i == x: return i y = int(x**0.5) return y
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN VAR
Given an integer x, find the square root of x. If x is not a perfect square, then return floor(√x). Example 1: Input: x = 5 Output: 2 Explanation: Since, 5 is not a perfect square, floor of square_root of 5 is 2. Example 2: Input: x = 4 Output: 2 Explanation: Since, 4 is a perfect square, so its square root is 2. Your Task: You don't need to read input or print anything. The task is to complete the function floorSqrt() which takes x as the input parameter and return its square root. Note: Try Solving the question without using the sqrt function. The value of x>=0. Expected Time Complexity: O(log N) Expected Auxiliary Space: O(1) Constraints: 1 ≤ x ≤ 10^{7}
class Solution: def floorSqrt(self, x): low = 0 high = x mid = (low + high) // 2 ans = -1 while low <= high: s = mid * mid if s == x: return mid if s < x: ans = mid low = mid + 1 else: high = mid - 1 mid = (low + high) // 2 return ans
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR RETURN VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR
Given an integer x, find the square root of x. If x is not a perfect square, then return floor(√x). Example 1: Input: x = 5 Output: 2 Explanation: Since, 5 is not a perfect square, floor of square_root of 5 is 2. Example 2: Input: x = 4 Output: 2 Explanation: Since, 4 is a perfect square, so its square root is 2. Your Task: You don't need to read input or print anything. The task is to complete the function floorSqrt() which takes x as the input parameter and return its square root. Note: Try Solving the question without using the sqrt function. The value of x>=0. Expected Time Complexity: O(log N) Expected Auxiliary Space: O(1) Constraints: 1 ≤ x ≤ 10^{7}
class Solution: def floorSqrt(self, x): min_, max_ = 1, x result = -1 while min_ <= max_: mid = (min_ + max_) // 2 mids_square = mid * mid if mids_square > x: max_ = mid - 1 elif mids_square < x: min_, result = mid + 1, mid elif mids_square == x: return mid return result
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR RETURN VAR RETURN VAR
Given an integer x, find the square root of x. If x is not a perfect square, then return floor(√x). Example 1: Input: x = 5 Output: 2 Explanation: Since, 5 is not a perfect square, floor of square_root of 5 is 2. Example 2: Input: x = 4 Output: 2 Explanation: Since, 4 is a perfect square, so its square root is 2. Your Task: You don't need to read input or print anything. The task is to complete the function floorSqrt() which takes x as the input parameter and return its square root. Note: Try Solving the question without using the sqrt function. The value of x>=0. Expected Time Complexity: O(log N) Expected Auxiliary Space: O(1) Constraints: 1 ≤ x ≤ 10^{7}
class Solution: def floorSqrt(self, x): st = 0 en = x while st <= en: mid = (st + en) // 2 if mid * mid == x: return int(mid) elif mid * mid < x: st = int(mid + 1) else: en = int(mid - 1) return int(en)
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR
Given an integer x, find the square root of x. If x is not a perfect square, then return floor(√x). Example 1: Input: x = 5 Output: 2 Explanation: Since, 5 is not a perfect square, floor of square_root of 5 is 2. Example 2: Input: x = 4 Output: 2 Explanation: Since, 4 is a perfect square, so its square root is 2. Your Task: You don't need to read input or print anything. The task is to complete the function floorSqrt() which takes x as the input parameter and return its square root. Note: Try Solving the question without using the sqrt function. The value of x>=0. Expected Time Complexity: O(log N) Expected Auxiliary Space: O(1) Constraints: 1 ≤ x ≤ 10^{7}
class Solution(object): def power(self, power, num): val = 1 for _ in range(power): val *= num return val def floorSqrt(self, x): n, m = 2, x left, right = 1, m while left <= right: mid = (left + right) // 2 val = self.power(n, mid) if val == m: return mid elif val > m: right = mid - 1 else: left = mid + 1 return right
CLASS_DEF VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR RETURN VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
Given an integer x, find the square root of x. If x is not a perfect square, then return floor(√x). Example 1: Input: x = 5 Output: 2 Explanation: Since, 5 is not a perfect square, floor of square_root of 5 is 2. Example 2: Input: x = 4 Output: 2 Explanation: Since, 4 is a perfect square, so its square root is 2. Your Task: You don't need to read input or print anything. The task is to complete the function floorSqrt() which takes x as the input parameter and return its square root. Note: Try Solving the question without using the sqrt function. The value of x>=0. Expected Time Complexity: O(log N) Expected Auxiliary Space: O(1) Constraints: 1 ≤ x ≤ 10^{7}
class Solution: def floorSqrt(self, x): low = 0 high = x ans = float("-inf") while low <= high: mid = low + int((high - low) / 2) mid_sq = mid * mid if mid_sq == x: return mid elif mid_sq > x: high = mid - 1 else: low = mid + 1 ans = mid return ans
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR RETURN VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR
Given an integer x, find the square root of x. If x is not a perfect square, then return floor(√x). Example 1: Input: x = 5 Output: 2 Explanation: Since, 5 is not a perfect square, floor of square_root of 5 is 2. Example 2: Input: x = 4 Output: 2 Explanation: Since, 4 is a perfect square, so its square root is 2. Your Task: You don't need to read input or print anything. The task is to complete the function floorSqrt() which takes x as the input parameter and return its square root. Note: Try Solving the question without using the sqrt function. The value of x>=0. Expected Time Complexity: O(log N) Expected Auxiliary Space: O(1) Constraints: 1 ≤ x ≤ 10^{7}
class Solution: def floorSqrt(self, x): if x == 0 or x == 1: return x start = 0 end = int(x // 2) ans = 0 while start <= end: mid = start + (end - start) // 2 if mid * mid == x: return mid elif mid * mid < x: start = mid + 1 ans = mid else: end = mid - 1 return ans
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR RETURN VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
Given an integer x, find the square root of x. If x is not a perfect square, then return floor(√x). Example 1: Input: x = 5 Output: 2 Explanation: Since, 5 is not a perfect square, floor of square_root of 5 is 2. Example 2: Input: x = 4 Output: 2 Explanation: Since, 4 is a perfect square, so its square root is 2. Your Task: You don't need to read input or print anything. The task is to complete the function floorSqrt() which takes x as the input parameter and return its square root. Note: Try Solving the question without using the sqrt function. The value of x>=0. Expected Time Complexity: O(log N) Expected Auxiliary Space: O(1) Constraints: 1 ≤ x ≤ 10^{7}
class Solution: def floorSqrt(self, x): l, r = 1, x while l <= r: mid = (l + r) // 2 cur = mid * mid if cur == x: return mid elif cur < x: l = mid + 1 else: r = mid - 1 ans = int(x ** (1 / 2)) return ans
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR RETURN VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER NUMBER RETURN VAR
Given an integer x, find the square root of x. If x is not a perfect square, then return floor(√x). Example 1: Input: x = 5 Output: 2 Explanation: Since, 5 is not a perfect square, floor of square_root of 5 is 2. Example 2: Input: x = 4 Output: 2 Explanation: Since, 4 is a perfect square, so its square root is 2. Your Task: You don't need to read input or print anything. The task is to complete the function floorSqrt() which takes x as the input parameter and return its square root. Note: Try Solving the question without using the sqrt function. The value of x>=0. Expected Time Complexity: O(log N) Expected Auxiliary Space: O(1) Constraints: 1 ≤ x ≤ 10^{7}
class Solution: def floorSqrt(self, x): if x == 0 or x == 1: return 1 s = 1 e = x ans = 0 while s <= e: m = (s + e) // 2 if m * m == x: return m elif m * m > x: e = m - 1 else: s = m + 1 ans = m return ans
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR RETURN VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR
Given an integer x, find the square root of x. If x is not a perfect square, then return floor(√x). Example 1: Input: x = 5 Output: 2 Explanation: Since, 5 is not a perfect square, floor of square_root of 5 is 2. Example 2: Input: x = 4 Output: 2 Explanation: Since, 4 is a perfect square, so its square root is 2. Your Task: You don't need to read input or print anything. The task is to complete the function floorSqrt() which takes x as the input parameter and return its square root. Note: Try Solving the question without using the sqrt function. The value of x>=0. Expected Time Complexity: O(log N) Expected Auxiliary Space: O(1) Constraints: 1 ≤ x ≤ 10^{7}
class Solution: def floorSqrt(self, x): for j in range(4000): if j**2 == x: return j break elif j**2 < x < (j + 1) ** 2: return j break
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER VAR RETURN VAR IF BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN VAR
Given an integer x, find the square root of x. If x is not a perfect square, then return floor(√x). Example 1: Input: x = 5 Output: 2 Explanation: Since, 5 is not a perfect square, floor of square_root of 5 is 2. Example 2: Input: x = 4 Output: 2 Explanation: Since, 4 is a perfect square, so its square root is 2. Your Task: You don't need to read input or print anything. The task is to complete the function floorSqrt() which takes x as the input parameter and return its square root. Note: Try Solving the question without using the sqrt function. The value of x>=0. Expected Time Complexity: O(log N) Expected Auxiliary Space: O(1) Constraints: 1 ≤ x ≤ 10^{7}
class Solution: def floorSqrt(self, x): temp = x // 2 + 1 temp2 = 1 while temp2 <= temp: if temp2**2 <= x: temp2 += 1 else: break return temp2 - 1
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER RETURN BIN_OP VAR NUMBER
Given an integer x, find the square root of x. If x is not a perfect square, then return floor(√x). Example 1: Input: x = 5 Output: 2 Explanation: Since, 5 is not a perfect square, floor of square_root of 5 is 2. Example 2: Input: x = 4 Output: 2 Explanation: Since, 4 is a perfect square, so its square root is 2. Your Task: You don't need to read input or print anything. The task is to complete the function floorSqrt() which takes x as the input parameter and return its square root. Note: Try Solving the question without using the sqrt function. The value of x>=0. Expected Time Complexity: O(log N) Expected Auxiliary Space: O(1) Constraints: 1 ≤ x ≤ 10^{7}
class Solution: def floorSqrt(self, x): if x == 1 or x == 0: return x ans = 1 res = 1 while res <= x: ans += 1 res = ans * ans return ans - 1
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN BIN_OP VAR NUMBER
You've got a list of program warning logs. Each record of a log stream is a string in this format: "2012-MM-DD HH:MM:SS:MESSAGE" (without the quotes). String "MESSAGE" consists of spaces, uppercase and lowercase English letters and characters "!", ".", ",", "?". String "2012-MM-DD" determines a correct date in the year of 2012. String "HH:MM:SS" determines a correct time in the 24 hour format. The described record of a log stream means that at a certain time the record has got some program warning (string "MESSAGE" contains the warning's description). Your task is to print the first moment of time, when the number of warnings for the last n seconds was not less than m. -----Input----- The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 10000). The second and the remaining lines of the input represent the log stream. The second line of the input contains the first record of the log stream, the third line contains the second record and so on. Each record of the log stream has the above described format. All records are given in the chronological order, that is, the warning records are given in the order, in which the warnings appeared in the program. It is guaranteed that the log has at least one record. It is guaranteed that the total length of all lines of the log stream doesn't exceed 5·10^6 (in particular, this means that the length of some line does not exceed 5·10^6 characters). It is guaranteed that all given dates and times are correct, and the string 'MESSAGE" in all records is non-empty. -----Output----- If there is no sought moment of time, print -1. Otherwise print a string in the format "2012-MM-DD HH:MM:SS" (without the quotes) — the first moment of time when the number of warnings for the last n seconds got no less than m. -----Examples----- Input 60 3 2012-03-16 16:15:25: Disk size is 2012-03-16 16:15:25: Network failute 2012-03-16 16:16:29: Cant write varlog 2012-03-16 16:16:42: Unable to start process 2012-03-16 16:16:43: Disk size is too small 2012-03-16 16:16:53: Timeout detected Output 2012-03-16 16:16:43 Input 1 2 2012-03-16 23:59:59:Disk size 2012-03-17 00:00:00: Network 2012-03-17 00:00:01:Cant write varlog Output -1 Input 2 2 2012-03-16 23:59:59:Disk size is too sm 2012-03-17 00:00:00:Network failute dete 2012-03-17 00:00:01:Cant write varlogmysq Output 2012-03-17 00:00:00
n, m = list(map(int, input().split(" "))) messages = [] months = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] while True: try: s = input() messages.append(s) except: break length = len(messages) pref = [0] for i in range(1, 13): pref.append(pref[i - 1] + months[i]) got = False now = 0 prev = 0 store = [] for message in messages: date = int(message[8:10]) + pref[int(message[5:7]) - 1] time = ( date * 24 * 60 * 60 + int(message[11:13]) * 60 * 60 + int(message[14:16]) * 60 + int(message[17:19]) ) store.append(time) if now < m - 1: now += 1 continue else: prev = now - (m - 1) if store[now] - store[prev] < n: print(message[:19]) got = True break now += 1 if not got: print(-1)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER
Let's call a list of positive integers $a_0, a_1, ..., a_{n-1}$ a power sequence if there is a positive integer $c$, so that for every $0 \le i \le n-1$ then $a_i = c^i$. Given a list of $n$ positive integers $a_0, a_1, ..., a_{n-1}$, you are allowed to: Reorder the list (i.e. pick a permutation $p$ of $\{0,1,...,n - 1\}$ and change $a_i$ to $a_{p_i}$), then Do the following operation any number of times: pick an index $i$ and change $a_i$ to $a_i - 1$ or $a_i + 1$ (i.e. increment or decrement $a_i$ by $1$) with a cost of $1$. Find the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Input----- The first line contains an integer $n$ ($3 \le n \le 10^5$). The second line contains $n$ integers $a_0, a_1, ..., a_{n-1}$ ($1 \le a_i \le 10^9$). -----Output----- Print the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Examples----- Input 3 1 3 2 Output 1 Input 3 1000000000 1000000000 1000000000 Output 1999982505 -----Note----- In the first example, we first reorder $\{1, 3, 2\}$ into $\{1, 2, 3\}$, then increment $a_2$ to $4$ with cost $1$ to get a power sequence $\{1, 2, 4\}$.
n = int(input()) a = sorted(list(map(int, input().split()))) l = int(pow(a[-1], 1 / (n - 1))) x, y = 0, 0 for i in range(n): item = pow(l, i) x += abs(item - a[i]) for j in range(n): item1 = pow(l + 1, j) y += abs(item1 - a[j]) print(min(x, y))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Let's call a list of positive integers $a_0, a_1, ..., a_{n-1}$ a power sequence if there is a positive integer $c$, so that for every $0 \le i \le n-1$ then $a_i = c^i$. Given a list of $n$ positive integers $a_0, a_1, ..., a_{n-1}$, you are allowed to: Reorder the list (i.e. pick a permutation $p$ of $\{0,1,...,n - 1\}$ and change $a_i$ to $a_{p_i}$), then Do the following operation any number of times: pick an index $i$ and change $a_i$ to $a_i - 1$ or $a_i + 1$ (i.e. increment or decrement $a_i$ by $1$) with a cost of $1$. Find the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Input----- The first line contains an integer $n$ ($3 \le n \le 10^5$). The second line contains $n$ integers $a_0, a_1, ..., a_{n-1}$ ($1 \le a_i \le 10^9$). -----Output----- Print the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Examples----- Input 3 1 3 2 Output 1 Input 3 1000000000 1000000000 1000000000 Output 1999982505 -----Note----- In the first example, we first reorder $\{1, 3, 2\}$ into $\{1, 2, 3\}$, then increment $a_2$ to $4$ with cost $1$ to get a power sequence $\{1, 2, 4\}$.
def f(mas, x): out = 0 t = 1 for i in range(len(mas)): out += abs(mas[i] - t) t *= x return out n = int(input()) mas = list(map(int, input().split())) mas.sort() a_max = mas[-1] d = f(mas, 1) w = 1 out = d while w ** (n - 1) <= d + a_max: out = min(out, f(mas, w)) w += 1 print(out)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Let's call a list of positive integers $a_0, a_1, ..., a_{n-1}$ a power sequence if there is a positive integer $c$, so that for every $0 \le i \le n-1$ then $a_i = c^i$. Given a list of $n$ positive integers $a_0, a_1, ..., a_{n-1}$, you are allowed to: Reorder the list (i.e. pick a permutation $p$ of $\{0,1,...,n - 1\}$ and change $a_i$ to $a_{p_i}$), then Do the following operation any number of times: pick an index $i$ and change $a_i$ to $a_i - 1$ or $a_i + 1$ (i.e. increment or decrement $a_i$ by $1$) with a cost of $1$. Find the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Input----- The first line contains an integer $n$ ($3 \le n \le 10^5$). The second line contains $n$ integers $a_0, a_1, ..., a_{n-1}$ ($1 \le a_i \le 10^9$). -----Output----- Print the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Examples----- Input 3 1 3 2 Output 1 Input 3 1000000000 1000000000 1000000000 Output 1999982505 -----Note----- In the first example, we first reorder $\{1, 3, 2\}$ into $\{1, 2, 3\}$, then increment $a_2$ to $4$ with cost $1$ to get a power sequence $\{1, 2, 4\}$.
n = int(input()) arr = list(map(int, input().split())) arr.sort() m = 0 for i in arr: m += abs(i - 1) c = 2 if n > 10: while c < 20: t = 0 for i in range(n): t += abs(c**i - arr[i]) if t >= m: break if t < m: m = t c += 1 print(m) else: while c <= 1000000: t = 0 for i in range(n): t += abs(c**i - arr[i]) if t >= m: break if t < m: m = t c += 1 print(m)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Let's call a list of positive integers $a_0, a_1, ..., a_{n-1}$ a power sequence if there is a positive integer $c$, so that for every $0 \le i \le n-1$ then $a_i = c^i$. Given a list of $n$ positive integers $a_0, a_1, ..., a_{n-1}$, you are allowed to: Reorder the list (i.e. pick a permutation $p$ of $\{0,1,...,n - 1\}$ and change $a_i$ to $a_{p_i}$), then Do the following operation any number of times: pick an index $i$ and change $a_i$ to $a_i - 1$ or $a_i + 1$ (i.e. increment or decrement $a_i$ by $1$) with a cost of $1$. Find the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Input----- The first line contains an integer $n$ ($3 \le n \le 10^5$). The second line contains $n$ integers $a_0, a_1, ..., a_{n-1}$ ($1 \le a_i \le 10^9$). -----Output----- Print the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Examples----- Input 3 1 3 2 Output 1 Input 3 1000000000 1000000000 1000000000 Output 1999982505 -----Note----- In the first example, we first reorder $\{1, 3, 2\}$ into $\{1, 2, 3\}$, then increment $a_2$ to $4$ with cost $1$ to get a power sequence $\{1, 2, 4\}$.
def answer(n, A): A.sort() ans = 10**20 if n <= 32: x = int(A[-1] ** (1 / (n - 1))) + 3 for i in range(1, x): count = 0 for j in range(n): count += abs(A[j] - i**j) ans = min(ans, count) return ans count = 0 for i in range(n): count += abs(A[i] - 1) return count n = int(input()) A = list(map(int, input().split())) print(answer(n, A))
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Let's call a list of positive integers $a_0, a_1, ..., a_{n-1}$ a power sequence if there is a positive integer $c$, so that for every $0 \le i \le n-1$ then $a_i = c^i$. Given a list of $n$ positive integers $a_0, a_1, ..., a_{n-1}$, you are allowed to: Reorder the list (i.e. pick a permutation $p$ of $\{0,1,...,n - 1\}$ and change $a_i$ to $a_{p_i}$), then Do the following operation any number of times: pick an index $i$ and change $a_i$ to $a_i - 1$ or $a_i + 1$ (i.e. increment or decrement $a_i$ by $1$) with a cost of $1$. Find the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Input----- The first line contains an integer $n$ ($3 \le n \le 10^5$). The second line contains $n$ integers $a_0, a_1, ..., a_{n-1}$ ($1 \le a_i \le 10^9$). -----Output----- Print the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Examples----- Input 3 1 3 2 Output 1 Input 3 1000000000 1000000000 1000000000 Output 1999982505 -----Note----- In the first example, we first reorder $\{1, 3, 2\}$ into $\{1, 2, 3\}$, then increment $a_2$ to $4$ with cost $1$ to get a power sequence $\{1, 2, 4\}$.
n = int(input()) a = list(map(int, input().split())) a.sort() res = sum(v - 1 for v in a) if n > 2: c = 2 while True: s = 0 v = 1 ok = True for i in range(n): s += abs(a[i] - v) v *= c if s > res: ok = False break if not ok: break res = s c += 1 elif n == 2: res = a[0] - 1 print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
Let's call a list of positive integers $a_0, a_1, ..., a_{n-1}$ a power sequence if there is a positive integer $c$, so that for every $0 \le i \le n-1$ then $a_i = c^i$. Given a list of $n$ positive integers $a_0, a_1, ..., a_{n-1}$, you are allowed to: Reorder the list (i.e. pick a permutation $p$ of $\{0,1,...,n - 1\}$ and change $a_i$ to $a_{p_i}$), then Do the following operation any number of times: pick an index $i$ and change $a_i$ to $a_i - 1$ or $a_i + 1$ (i.e. increment or decrement $a_i$ by $1$) with a cost of $1$. Find the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Input----- The first line contains an integer $n$ ($3 \le n \le 10^5$). The second line contains $n$ integers $a_0, a_1, ..., a_{n-1}$ ($1 \le a_i \le 10^9$). -----Output----- Print the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Examples----- Input 3 1 3 2 Output 1 Input 3 1000000000 1000000000 1000000000 Output 1999982505 -----Note----- In the first example, we first reorder $\{1, 3, 2\}$ into $\{1, 2, 3\}$, then increment $a_2$ to $4$ with cost $1$ to get a power sequence $\{1, 2, 4\}$.
n = int(input()) z = [int(x) for x in input().split(" ")] z.sort() ans, b = abs(z[0] - 1), abs(z[0] - 1) c = int(pow(z[-1], 1 / (n - 1))) for i in range(1, n): b += abs(pow(c, i) - z[i]) c += 1 for i in range(1, n): ans += abs(pow(c, i) - z[i]) print(min(ans, b))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Let's call a list of positive integers $a_0, a_1, ..., a_{n-1}$ a power sequence if there is a positive integer $c$, so that for every $0 \le i \le n-1$ then $a_i = c^i$. Given a list of $n$ positive integers $a_0, a_1, ..., a_{n-1}$, you are allowed to: Reorder the list (i.e. pick a permutation $p$ of $\{0,1,...,n - 1\}$ and change $a_i$ to $a_{p_i}$), then Do the following operation any number of times: pick an index $i$ and change $a_i$ to $a_i - 1$ or $a_i + 1$ (i.e. increment or decrement $a_i$ by $1$) with a cost of $1$. Find the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Input----- The first line contains an integer $n$ ($3 \le n \le 10^5$). The second line contains $n$ integers $a_0, a_1, ..., a_{n-1}$ ($1 \le a_i \le 10^9$). -----Output----- Print the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Examples----- Input 3 1 3 2 Output 1 Input 3 1000000000 1000000000 1000000000 Output 1999982505 -----Note----- In the first example, we first reorder $\{1, 3, 2\}$ into $\{1, 2, 3\}$, then increment $a_2$ to $4$ with cost $1$ to get a power sequence $\{1, 2, 4\}$.
n = int(input()) l = list(map(int, input().split())) if n >= 50: s = sum(l) print(s - n) else: l.sort() mi = 1000000000000000 for i in range(1, 100001): ans = 0 x = 1 for j in range(n): ans += abs(x - l[j]) x = x * i mi = min(ans, mi) print(mi)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Let's call a list of positive integers $a_0, a_1, ..., a_{n-1}$ a power sequence if there is a positive integer $c$, so that for every $0 \le i \le n-1$ then $a_i = c^i$. Given a list of $n$ positive integers $a_0, a_1, ..., a_{n-1}$, you are allowed to: Reorder the list (i.e. pick a permutation $p$ of $\{0,1,...,n - 1\}$ and change $a_i$ to $a_{p_i}$), then Do the following operation any number of times: pick an index $i$ and change $a_i$ to $a_i - 1$ or $a_i + 1$ (i.e. increment or decrement $a_i$ by $1$) with a cost of $1$. Find the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Input----- The first line contains an integer $n$ ($3 \le n \le 10^5$). The second line contains $n$ integers $a_0, a_1, ..., a_{n-1}$ ($1 \le a_i \le 10^9$). -----Output----- Print the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Examples----- Input 3 1 3 2 Output 1 Input 3 1000000000 1000000000 1000000000 Output 1999982505 -----Note----- In the first example, we first reorder $\{1, 3, 2\}$ into $\{1, 2, 3\}$, then increment $a_2$ to $4$ with cost $1$ to get a power sequence $\{1, 2, 4\}$.
n = int(input()) l = sorted(list(map(int, input().split()))) mx = 10 * 10**9 + 9 min_cost = float("inf") c = 1 while c ** (n - 1) < mx: s = 0 for i in range(n): s += abs(l[i] - c**i) c += 1 min_cost = min(s, min_cost) print(min_cost)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Let's call a list of positive integers $a_0, a_1, ..., a_{n-1}$ a power sequence if there is a positive integer $c$, so that for every $0 \le i \le n-1$ then $a_i = c^i$. Given a list of $n$ positive integers $a_0, a_1, ..., a_{n-1}$, you are allowed to: Reorder the list (i.e. pick a permutation $p$ of $\{0,1,...,n - 1\}$ and change $a_i$ to $a_{p_i}$), then Do the following operation any number of times: pick an index $i$ and change $a_i$ to $a_i - 1$ or $a_i + 1$ (i.e. increment or decrement $a_i$ by $1$) with a cost of $1$. Find the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Input----- The first line contains an integer $n$ ($3 \le n \le 10^5$). The second line contains $n$ integers $a_0, a_1, ..., a_{n-1}$ ($1 \le a_i \le 10^9$). -----Output----- Print the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Examples----- Input 3 1 3 2 Output 1 Input 3 1000000000 1000000000 1000000000 Output 1999982505 -----Note----- In the first example, we first reorder $\{1, 3, 2\}$ into $\{1, 2, 3\}$, then increment $a_2$ to $4$ with cost $1$ to get a power sequence $\{1, 2, 4\}$.
import sys input = sys.stdin.readline I = lambda: list(map(int, input().split())) (n,) = I() l = sorted(I()) an = sum(l) - n i = 2 mx = max(l) if n == 2: an = min(an, l[0] - 1) while n > 2: po = 1 cr = 0 if i > 40000: break for j in range(n): cr += abs(l[j] - po) po *= i if cr > an: break an = min(cr, an) i += 1 print(an)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Let's call a list of positive integers $a_0, a_1, ..., a_{n-1}$ a power sequence if there is a positive integer $c$, so that for every $0 \le i \le n-1$ then $a_i = c^i$. Given a list of $n$ positive integers $a_0, a_1, ..., a_{n-1}$, you are allowed to: Reorder the list (i.e. pick a permutation $p$ of $\{0,1,...,n - 1\}$ and change $a_i$ to $a_{p_i}$), then Do the following operation any number of times: pick an index $i$ and change $a_i$ to $a_i - 1$ or $a_i + 1$ (i.e. increment or decrement $a_i$ by $1$) with a cost of $1$. Find the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Input----- The first line contains an integer $n$ ($3 \le n \le 10^5$). The second line contains $n$ integers $a_0, a_1, ..., a_{n-1}$ ($1 \le a_i \le 10^9$). -----Output----- Print the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Examples----- Input 3 1 3 2 Output 1 Input 3 1000000000 1000000000 1000000000 Output 1999982505 -----Note----- In the first example, we first reorder $\{1, 3, 2\}$ into $\{1, 2, 3\}$, then increment $a_2$ to $4$ with cost $1$ to get a power sequence $\{1, 2, 4\}$.
n = int(input()) a = [int(x) for x in input().split()] a.sort() inf = 10**18 ans = inf for k in range(1, 10**5): tmp = 0 for i in range(n): tmp = tmp + abs(a[i] - k**i) if tmp > ans: break if ans > tmp: ans = tmp print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Let's call a list of positive integers $a_0, a_1, ..., a_{n-1}$ a power sequence if there is a positive integer $c$, so that for every $0 \le i \le n-1$ then $a_i = c^i$. Given a list of $n$ positive integers $a_0, a_1, ..., a_{n-1}$, you are allowed to: Reorder the list (i.e. pick a permutation $p$ of $\{0,1,...,n - 1\}$ and change $a_i$ to $a_{p_i}$), then Do the following operation any number of times: pick an index $i$ and change $a_i$ to $a_i - 1$ or $a_i + 1$ (i.e. increment or decrement $a_i$ by $1$) with a cost of $1$. Find the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Input----- The first line contains an integer $n$ ($3 \le n \le 10^5$). The second line contains $n$ integers $a_0, a_1, ..., a_{n-1}$ ($1 \le a_i \le 10^9$). -----Output----- Print the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Examples----- Input 3 1 3 2 Output 1 Input 3 1000000000 1000000000 1000000000 Output 1999982505 -----Note----- In the first example, we first reorder $\{1, 3, 2\}$ into $\{1, 2, 3\}$, then increment $a_2$ to $4$ with cost $1$ to get a power sequence $\{1, 2, 4\}$.
n = int(input()) s = input() s = s.split() a = [] for e in s: a.append(int(e)) a.sort() ans = 0 for e in a: ans += e - 1 for i in range(2, 100000): temp = 0 flag = 1 for j in range(n): if j == 0: temp += a[j] - 1 continue z = i**j if z > 100000000000000: flag = 0 break temp += abs(a[j] - z) if flag == 1 and temp < ans: ans = temp print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Let's call a list of positive integers $a_0, a_1, ..., a_{n-1}$ a power sequence if there is a positive integer $c$, so that for every $0 \le i \le n-1$ then $a_i = c^i$. Given a list of $n$ positive integers $a_0, a_1, ..., a_{n-1}$, you are allowed to: Reorder the list (i.e. pick a permutation $p$ of $\{0,1,...,n - 1\}$ and change $a_i$ to $a_{p_i}$), then Do the following operation any number of times: pick an index $i$ and change $a_i$ to $a_i - 1$ or $a_i + 1$ (i.e. increment or decrement $a_i$ by $1$) with a cost of $1$. Find the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Input----- The first line contains an integer $n$ ($3 \le n \le 10^5$). The second line contains $n$ integers $a_0, a_1, ..., a_{n-1}$ ($1 \le a_i \le 10^9$). -----Output----- Print the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Examples----- Input 3 1 3 2 Output 1 Input 3 1000000000 1000000000 1000000000 Output 1999982505 -----Note----- In the first example, we first reorder $\{1, 3, 2\}$ into $\{1, 2, 3\}$, then increment $a_2$ to $4$ with cost $1$ to get a power sequence $\{1, 2, 4\}$.
n = int(input()) a = list(map(int, input().split())) a.sort() mxN = 10**20 ans = 10**20 for i in range(1, 10**5): val, res = 1, 0 for j in range(n): if val * i > mxN: print(ans) exit() else: res += abs(val - a[j]) val *= i ans = min(ans, res) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Let's call a list of positive integers $a_0, a_1, ..., a_{n-1}$ a power sequence if there is a positive integer $c$, so that for every $0 \le i \le n-1$ then $a_i = c^i$. Given a list of $n$ positive integers $a_0, a_1, ..., a_{n-1}$, you are allowed to: Reorder the list (i.e. pick a permutation $p$ of $\{0,1,...,n - 1\}$ and change $a_i$ to $a_{p_i}$), then Do the following operation any number of times: pick an index $i$ and change $a_i$ to $a_i - 1$ or $a_i + 1$ (i.e. increment or decrement $a_i$ by $1$) with a cost of $1$. Find the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Input----- The first line contains an integer $n$ ($3 \le n \le 10^5$). The second line contains $n$ integers $a_0, a_1, ..., a_{n-1}$ ($1 \le a_i \le 10^9$). -----Output----- Print the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Examples----- Input 3 1 3 2 Output 1 Input 3 1000000000 1000000000 1000000000 Output 1999982505 -----Note----- In the first example, we first reorder $\{1, 3, 2\}$ into $\{1, 2, 3\}$, then increment $a_2$ to $4$ with cost $1$ to get a power sequence $\{1, 2, 4\}$.
def power(n, seq): seq.sort() res = float("inf") c = 1 while True: ans = 0 for i in range(n): ans += abs(c**i - seq[i]) if res > ans: res = ans c += 1 if c ** (n - 1) >= 10**18: break else: break return res res = [] n = int(input()) par = list(map(int, input().split())) print(power(n, par))
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER NUMBER RETURN VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Let's call a list of positive integers $a_0, a_1, ..., a_{n-1}$ a power sequence if there is a positive integer $c$, so that for every $0 \le i \le n-1$ then $a_i = c^i$. Given a list of $n$ positive integers $a_0, a_1, ..., a_{n-1}$, you are allowed to: Reorder the list (i.e. pick a permutation $p$ of $\{0,1,...,n - 1\}$ and change $a_i$ to $a_{p_i}$), then Do the following operation any number of times: pick an index $i$ and change $a_i$ to $a_i - 1$ or $a_i + 1$ (i.e. increment or decrement $a_i$ by $1$) with a cost of $1$. Find the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Input----- The first line contains an integer $n$ ($3 \le n \le 10^5$). The second line contains $n$ integers $a_0, a_1, ..., a_{n-1}$ ($1 \le a_i \le 10^9$). -----Output----- Print the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Examples----- Input 3 1 3 2 Output 1 Input 3 1000000000 1000000000 1000000000 Output 1999982505 -----Note----- In the first example, we first reorder $\{1, 3, 2\}$ into $\{1, 2, 3\}$, then increment $a_2$ to $4$ with cost $1$ to get a power sequence $\{1, 2, 4\}$.
n = int(input()) a = [int(x) for x in input().split(" ")[:n]] a.sort() result = 10000000000000 k = 1 while k ** (n - 1) <= 10**10: k += 1 for i in range(1, k): temp = 0 for j in range(0, len(a)): d = i**j temp += abs(a[j] - d) result = min(result, temp) print(result)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Let's call a list of positive integers $a_0, a_1, ..., a_{n-1}$ a power sequence if there is a positive integer $c$, so that for every $0 \le i \le n-1$ then $a_i = c^i$. Given a list of $n$ positive integers $a_0, a_1, ..., a_{n-1}$, you are allowed to: Reorder the list (i.e. pick a permutation $p$ of $\{0,1,...,n - 1\}$ and change $a_i$ to $a_{p_i}$), then Do the following operation any number of times: pick an index $i$ and change $a_i$ to $a_i - 1$ or $a_i + 1$ (i.e. increment or decrement $a_i$ by $1$) with a cost of $1$. Find the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Input----- The first line contains an integer $n$ ($3 \le n \le 10^5$). The second line contains $n$ integers $a_0, a_1, ..., a_{n-1}$ ($1 \le a_i \le 10^9$). -----Output----- Print the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Examples----- Input 3 1 3 2 Output 1 Input 3 1000000000 1000000000 1000000000 Output 1999982505 -----Note----- In the first example, we first reorder $\{1, 3, 2\}$ into $\{1, 2, 3\}$, then increment $a_2$ to $4$ with cost $1$ to get a power sequence $\{1, 2, 4\}$.
n = int(input()) a = list(map(int, input().split(" "))) a.sort() answer = 1e18 flag = True for i in range(1, 500000): ans = 0 for j, val in enumerate(a): x = pow(i, j) ans += abs(x - val) if x > 1e18: flag = False break answer = min(ans, answer) if not flag: break print(answer)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR
Let's call a list of positive integers $a_0, a_1, ..., a_{n-1}$ a power sequence if there is a positive integer $c$, so that for every $0 \le i \le n-1$ then $a_i = c^i$. Given a list of $n$ positive integers $a_0, a_1, ..., a_{n-1}$, you are allowed to: Reorder the list (i.e. pick a permutation $p$ of $\{0,1,...,n - 1\}$ and change $a_i$ to $a_{p_i}$), then Do the following operation any number of times: pick an index $i$ and change $a_i$ to $a_i - 1$ or $a_i + 1$ (i.e. increment or decrement $a_i$ by $1$) with a cost of $1$. Find the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Input----- The first line contains an integer $n$ ($3 \le n \le 10^5$). The second line contains $n$ integers $a_0, a_1, ..., a_{n-1}$ ($1 \le a_i \le 10^9$). -----Output----- Print the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Examples----- Input 3 1 3 2 Output 1 Input 3 1000000000 1000000000 1000000000 Output 1999982505 -----Note----- In the first example, we first reorder $\{1, 3, 2\}$ into $\{1, 2, 3\}$, then increment $a_2$ to $4$ with cost $1$ to get a power sequence $\{1, 2, 4\}$.
n = int(input()) l = list(map(int, input().split())) l.sort() v = l[-1] ** (1 / (len(l) - 1)) v1 = int(v) v2 = v1 + 1 cost = 0 for i in range(len(l)): cost += abs(v1**i - l[i]) cost2 = 0 for i in range(len(l)): cost2 += abs(v2**i - l[i]) print(min(cost, cost2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Let's call a list of positive integers $a_0, a_1, ..., a_{n-1}$ a power sequence if there is a positive integer $c$, so that for every $0 \le i \le n-1$ then $a_i = c^i$. Given a list of $n$ positive integers $a_0, a_1, ..., a_{n-1}$, you are allowed to: Reorder the list (i.e. pick a permutation $p$ of $\{0,1,...,n - 1\}$ and change $a_i$ to $a_{p_i}$), then Do the following operation any number of times: pick an index $i$ and change $a_i$ to $a_i - 1$ or $a_i + 1$ (i.e. increment or decrement $a_i$ by $1$) with a cost of $1$. Find the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Input----- The first line contains an integer $n$ ($3 \le n \le 10^5$). The second line contains $n$ integers $a_0, a_1, ..., a_{n-1}$ ($1 \le a_i \le 10^9$). -----Output----- Print the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Examples----- Input 3 1 3 2 Output 1 Input 3 1000000000 1000000000 1000000000 Output 1999982505 -----Note----- In the first example, we first reorder $\{1, 3, 2\}$ into $\{1, 2, 3\}$, then increment $a_2$ to $4$ with cost $1$ to get a power sequence $\{1, 2, 4\}$.
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) res = sum(a) - n a.sort() for x in range(2, 100000): t = 0 for i in range(n): t += abs(pow(x, i) - a[i]) if t > res: break else: res = min(res, t) print(res)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Let's call a list of positive integers $a_0, a_1, ..., a_{n-1}$ a power sequence if there is a positive integer $c$, so that for every $0 \le i \le n-1$ then $a_i = c^i$. Given a list of $n$ positive integers $a_0, a_1, ..., a_{n-1}$, you are allowed to: Reorder the list (i.e. pick a permutation $p$ of $\{0,1,...,n - 1\}$ and change $a_i$ to $a_{p_i}$), then Do the following operation any number of times: pick an index $i$ and change $a_i$ to $a_i - 1$ or $a_i + 1$ (i.e. increment or decrement $a_i$ by $1$) with a cost of $1$. Find the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Input----- The first line contains an integer $n$ ($3 \le n \le 10^5$). The second line contains $n$ integers $a_0, a_1, ..., a_{n-1}$ ($1 \le a_i \le 10^9$). -----Output----- Print the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Examples----- Input 3 1 3 2 Output 1 Input 3 1000000000 1000000000 1000000000 Output 1999982505 -----Note----- In the first example, we first reorder $\{1, 3, 2\}$ into $\{1, 2, 3\}$, then increment $a_2$ to $4$ with cost $1$ to get a power sequence $\{1, 2, 4\}$.
count = int(input()) numbers = list(map(int, input().split())) numbers.sort() c = int(sum(numbers) ** (1 / (count - 1))) + 1 best = 1000000000000000 counter = 0 while c > 0: counter = 0 for i in range(0, count): counter += abs(numbers[i] - c**i) if counter < best: best = counter c -= 1 print(best)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Let's call a list of positive integers $a_0, a_1, ..., a_{n-1}$ a power sequence if there is a positive integer $c$, so that for every $0 \le i \le n-1$ then $a_i = c^i$. Given a list of $n$ positive integers $a_0, a_1, ..., a_{n-1}$, you are allowed to: Reorder the list (i.e. pick a permutation $p$ of $\{0,1,...,n - 1\}$ and change $a_i$ to $a_{p_i}$), then Do the following operation any number of times: pick an index $i$ and change $a_i$ to $a_i - 1$ or $a_i + 1$ (i.e. increment or decrement $a_i$ by $1$) with a cost of $1$. Find the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Input----- The first line contains an integer $n$ ($3 \le n \le 10^5$). The second line contains $n$ integers $a_0, a_1, ..., a_{n-1}$ ($1 \le a_i \le 10^9$). -----Output----- Print the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Examples----- Input 3 1 3 2 Output 1 Input 3 1000000000 1000000000 1000000000 Output 1999982505 -----Note----- In the first example, we first reorder $\{1, 3, 2\}$ into $\{1, 2, 3\}$, then increment $a_2$ to $4$ with cost $1$ to get a power sequence $\{1, 2, 4\}$.
n = int(input()) arr = list(map(int, input().split())) arr.sort() ans = 10**18 MAX = 10**15 flag1 = False i = 0 while True: p = 0 curr = 0 for j in range(n): p = pow(i, j) if p > arr[-1]: flag1 = True curr += abs(p - arr[j]) ans = min(ans, curr) i += 1 if flag1: break print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR
Let's call a list of positive integers $a_0, a_1, ..., a_{n-1}$ a power sequence if there is a positive integer $c$, so that for every $0 \le i \le n-1$ then $a_i = c^i$. Given a list of $n$ positive integers $a_0, a_1, ..., a_{n-1}$, you are allowed to: Reorder the list (i.e. pick a permutation $p$ of $\{0,1,...,n - 1\}$ and change $a_i$ to $a_{p_i}$), then Do the following operation any number of times: pick an index $i$ and change $a_i$ to $a_i - 1$ or $a_i + 1$ (i.e. increment or decrement $a_i$ by $1$) with a cost of $1$. Find the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Input----- The first line contains an integer $n$ ($3 \le n \le 10^5$). The second line contains $n$ integers $a_0, a_1, ..., a_{n-1}$ ($1 \le a_i \le 10^9$). -----Output----- Print the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Examples----- Input 3 1 3 2 Output 1 Input 3 1000000000 1000000000 1000000000 Output 1999982505 -----Note----- In the first example, we first reorder $\{1, 3, 2\}$ into $\{1, 2, 3\}$, then increment $a_2$ to $4$ with cost $1$ to get a power sequence $\{1, 2, 4\}$.
n = int(input()) arr = list(map(int, input().split())) arr2 = sorted(arr) total = float("inf") f = 1 c = 1 while f and pow(c, n - 1) < 10 * arr2[n - 1]: f = 0 temp = 0 for x in range(n): p = pow(c, x) x_x = pow(c, x) - arr2[x] temp += abs(x_x) if x_x < 0: f = 1 if temp < total: total = temp c += 1 print(total)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Let's call a list of positive integers $a_0, a_1, ..., a_{n-1}$ a power sequence if there is a positive integer $c$, so that for every $0 \le i \le n-1$ then $a_i = c^i$. Given a list of $n$ positive integers $a_0, a_1, ..., a_{n-1}$, you are allowed to: Reorder the list (i.e. pick a permutation $p$ of $\{0,1,...,n - 1\}$ and change $a_i$ to $a_{p_i}$), then Do the following operation any number of times: pick an index $i$ and change $a_i$ to $a_i - 1$ or $a_i + 1$ (i.e. increment or decrement $a_i$ by $1$) with a cost of $1$. Find the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Input----- The first line contains an integer $n$ ($3 \le n \le 10^5$). The second line contains $n$ integers $a_0, a_1, ..., a_{n-1}$ ($1 \le a_i \le 10^9$). -----Output----- Print the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Examples----- Input 3 1 3 2 Output 1 Input 3 1000000000 1000000000 1000000000 Output 1999982505 -----Note----- In the first example, we first reorder $\{1, 3, 2\}$ into $\{1, 2, 3\}$, then increment $a_2$ to $4$ with cost $1$ to get a power sequence $\{1, 2, 4\}$.
n = int(input()) li = list(map(int, input().split())) li.sort() t = li[-1] m = t ** (1 / (n - 1)) m = int(m) s = 0 for i in range(0, n): s += abs(m**i - li[i]) m = int(m) + 1 s1 = s s = 0 for i in range(0, n): s += abs(m**i - li[i]) print(min(s, s1))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Let's call a list of positive integers $a_0, a_1, ..., a_{n-1}$ a power sequence if there is a positive integer $c$, so that for every $0 \le i \le n-1$ then $a_i = c^i$. Given a list of $n$ positive integers $a_0, a_1, ..., a_{n-1}$, you are allowed to: Reorder the list (i.e. pick a permutation $p$ of $\{0,1,...,n - 1\}$ and change $a_i$ to $a_{p_i}$), then Do the following operation any number of times: pick an index $i$ and change $a_i$ to $a_i - 1$ or $a_i + 1$ (i.e. increment or decrement $a_i$ by $1$) with a cost of $1$. Find the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Input----- The first line contains an integer $n$ ($3 \le n \le 10^5$). The second line contains $n$ integers $a_0, a_1, ..., a_{n-1}$ ($1 \le a_i \le 10^9$). -----Output----- Print the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence. -----Examples----- Input 3 1 3 2 Output 1 Input 3 1000000000 1000000000 1000000000 Output 1999982505 -----Note----- In the first example, we first reorder $\{1, 3, 2\}$ into $\{1, 2, 3\}$, then increment $a_2$ to $4$ with cost $1$ to get a power sequence $\{1, 2, 4\}$.
n = int(input()) s = [int(x) for x in input().split()] s.sort() tot = 0 for i in range(0, len(s)): tot += s[i] diff = tot - n ans = tot - n for i in range(2, 100005): tt = abs(pow(i, n - 1) - s[-1]) if tt > diff: break sumu = 0 for j in range(0, n): sumu += abs(pow(i, j) - s[j]) ans = min(ans, sumu) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR