description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? -----Input----- The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β€” the number of points and the constraint on the distance between matched points, respectively. The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$). -----Output----- Print one integer β€” the maximum number of pairs of points you can match with each other. -----Examples----- Input 4 2 1 3 3 7 Output 2 Input 5 5 10 9 5 8 7 Output 1 -----Note----- In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$). In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
def main(): n, z = map(int, input().split()) a = list(map(int, input().split())) a.sort() left, right, ret = 0, n // 2, 0 while left <= right: mid = (left + right) // 2 flag = True for i in range(mid): if a[n - mid + i] - a[i] < z: flag = False break if flag: left = mid + 1 ret = max(ret, mid) else: right = mid - 1 print(ret) main()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? -----Input----- The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β€” the number of points and the constraint on the distance between matched points, respectively. The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$). -----Output----- Print one integer β€” the maximum number of pairs of points you can match with each other. -----Examples----- Input 4 2 1 3 3 7 Output 2 Input 5 5 10 9 5 8 7 Output 1 -----Note----- In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$). In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
import sys o = lambda *a: (lambda *b: a[0](*b)) if len(a) == 1 else lambda *b: a[0](o(*a[1:])(*b)) lmap = o(list, map) lmap_ = lambda f: lambda L: lmap(f, L) spp = lambda n: lambda x: lambda a: [y for y in a.split(x) if len(y) >= n] def P(S): n, z, S = S[0][0], S[0][1], sorted(S[1]) l, r, m2 = 0, n // 2, 0 while l <= r: m = (l + r) // 2 f = True for i in range(m): f *= S[n - m + i] - S[i] >= z if f: l = m + 1 else: r = m - 1 print(r) o(P, lmap_(lmap_(int)), lmap_(spp(0)(" ")), spp(1)("\n"))(sys.stdin.read())
IMPORT ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR NUMBER NUMBER VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER STRING FUNC_CALL FUNC_CALL VAR NUMBER STRING FUNC_CALL VAR
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? -----Input----- The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β€” the number of points and the constraint on the distance between matched points, respectively. The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$). -----Output----- Print one integer β€” the maximum number of pairs of points you can match with each other. -----Examples----- Input 4 2 1 3 3 7 Output 2 Input 5 5 10 9 5 8 7 Output 1 -----Note----- In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$). In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
n, z = map(int, input().split()) a = list(map(int, input().split())) a.sort() i = -1 h = len(a) // 2 - 1 j = h m = 0 while i < h: i = i + 1 j = j + 1 while j < len(a) and a[j] - a[i] < z: j = j + 1 if j >= len(a): break m = m + 1 print(m)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? -----Input----- The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β€” the number of points and the constraint on the distance between matched points, respectively. The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$). -----Output----- Print one integer β€” the maximum number of pairs of points you can match with each other. -----Examples----- Input 4 2 1 3 3 7 Output 2 Input 5 5 10 9 5 8 7 Output 1 -----Note----- In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$). In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
n, z = list(map(int, input().split())) arrs = [int(x) for x in input().split()] arrs.sort() def fi(k): l = arrs[:k] r = arrs[-k:] return all([(r[i] - l[i] >= z) for i in range(len(r))]) l = 0 r = len(arrs) // 2 + 1 while r - l > 1: m = (l + r) // 2 if fi(m): l = m else: r = m print(l)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? -----Input----- The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β€” the number of points and the constraint on the distance between matched points, respectively. The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$). -----Output----- Print one integer β€” the maximum number of pairs of points you can match with each other. -----Examples----- Input 4 2 1 3 3 7 Output 2 Input 5 5 10 9 5 8 7 Output 1 -----Note----- In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$). In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
import sys class Main: def __init__(self): self.buff = None self.index = 0 def next(self): if self.buff is None or self.index == len(self.buff): self.buff = self.next_line() self.index = 0 val = self.buff[self.index] self.index += 1 return val def next_line(self, _map=str): return list(map(_map, sys.stdin.readline().split())) def next_int(self): return int(self.next()) def solve(self): n = self.next_int() z = self.next_int() x = sorted([self.next_int() for _ in range(0, n)]) low = 0 high = n while high - low > 1: mid = (low + high) // 2 if self.test(mid, n, x, z): low = mid else: high = mid print(low) def test(self, mid, n, x, z): j = mid for i in range(0, mid): while j < n and x[j] < x[i] + z: j += 1 if j >= n: return False j += 1 return True Main().solve()
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR NONE ASSIGN VAR NUMBER FUNC_DEF IF VAR NONE VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR WHILE VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER VAR NUMBER RETURN NUMBER EXPR FUNC_CALL FUNC_CALL VAR
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? -----Input----- The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β€” the number of points and the constraint on the distance between matched points, respectively. The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$). -----Output----- Print one integer β€” the maximum number of pairs of points you can match with each other. -----Examples----- Input 4 2 1 3 3 7 Output 2 Input 5 5 10 9 5 8 7 Output 1 -----Note----- In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$). In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
def find_intervals(points, dist): length = len(points) used = [(False) for i in range(length)] l_pointer = 0 r_pointer = length // 2 intervals = 0 while l_pointer < length // 2 and r_pointer < length: if used[l_pointer]: l_pointer += 1 continue if used[r_pointer] or points[r_pointer] < points[l_pointer] + dist: r_pointer += 1 continue used[l_pointer] = True used[r_pointer] = True intervals += 1 return intervals n, dist = map(int, input().split()) points = list(map(int, input().split())) print(find_intervals(sorted(points), dist))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? -----Input----- The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β€” the number of points and the constraint on the distance between matched points, respectively. The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$). -----Output----- Print one integer β€” the maximum number of pairs of points you can match with each other. -----Examples----- Input 4 2 1 3 3 7 Output 2 Input 5 5 10 9 5 8 7 Output 1 -----Note----- In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$). In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
n_and_z = [int(x) for x in input().split()] n_integers = [int(x) for x in input().split()] n_integers.sort() first_half = int(n_and_z[0] / 2) counter = 0 z = first_half for x in range(0, first_half): for y in range(z, len(n_integers)): if n_integers[y] - n_integers[x] >= n_and_z[1]: counter = counter + 1 z = y + 1 break if y == len(n_integers) - 1: break print(counter)
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? -----Input----- The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β€” the number of points and the constraint on the distance between matched points, respectively. The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$). -----Output----- Print one integer β€” the maximum number of pairs of points you can match with each other. -----Examples----- Input 4 2 1 3 3 7 Output 2 Input 5 5 10 9 5 8 7 Output 1 -----Note----- In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$). In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
nz = input().split() n = int(nz[0]) z = int(nz[1]) a = input().split() res = 0 for i in range(n): a[i] = int(a[i]) m = (n + 1) // 2 f, s = 0, m a = sorted(a) while f < m and s < n: if a[s] - a[f] >= z: res += 1 f += 1 s += 1 else: s += 1 print(res)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? -----Input----- The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β€” the number of points and the constraint on the distance between matched points, respectively. The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$). -----Output----- Print one integer β€” the maximum number of pairs of points you can match with each other. -----Examples----- Input 4 2 1 3 3 7 Output 2 Input 5 5 10 9 5 8 7 Output 1 -----Note----- In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$). In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
inp = input().strip() n, z = int(inp.split(" ")[0]), int(inp.split(" ")[1]) inp = input() inp_arr = inp.strip().split(" ") a = [int(i) for i in inp_arr] a.sort(reverse=True) f = 0 l = n // 2 c = 0 while l < n and f < n // 2: if a[f] - a[l] >= z: f = f + 1 l = l + 1 c = c + 1 else: l = l + 1 print(c)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? -----Input----- The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β€” the number of points and the constraint on the distance between matched points, respectively. The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$). -----Output----- Print one integer β€” the maximum number of pairs of points you can match with each other. -----Examples----- Input 4 2 1 3 3 7 Output 2 Input 5 5 10 9 5 8 7 Output 1 -----Note----- In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$). In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
from sys import stdin, stdout def solve(arr, minDiff): arr = sorted(arr) l = 0 if len(arr) % 2 == 0: r = len(arr) // 2 rr = len(arr) // 2 else: r = len(arr) // 2 rr = len(arr) // 2 counter = 0 i = 0 while i < r and rr < len(arr): if arr[rr] - arr[i] >= minDiff: counter += 1 i += 1 rr += 1 return counter n, z = map(int, input().split()) ar = [int(x) for x in input().split()] stdout.write(str(solve(ar, z)))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? -----Input----- The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β€” the number of points and the constraint on the distance between matched points, respectively. The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$). -----Output----- Print one integer β€” the maximum number of pairs of points you can match with each other. -----Examples----- Input 4 2 1 3 3 7 Output 2 Input 5 5 10 9 5 8 7 Output 1 -----Note----- In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$). In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
n, m = map(int, input().split()) a = list(map(int, input().split())) a.sort() b = a[: n // 2] c = a[n // 2 :] j = 0 ans = 0 for i in b: while abs(i - c[j]) < m: j += 1 if j == len(c): print(ans) exit() ans += 1 j += 1 if j == len(c): print(ans) exit() print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR WHILE FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? -----Input----- The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β€” the number of points and the constraint on the distance between matched points, respectively. The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$). -----Output----- Print one integer β€” the maximum number of pairs of points you can match with each other. -----Examples----- Input 4 2 1 3 3 7 Output 2 Input 5 5 10 9 5 8 7 Output 1 -----Note----- In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$). In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
def solve(): N, Z = map(int, input().split()) X = [int(k) for k in input().split()] X.sort() ans = 0 i = 0 mid = N // 2 + (1 if N % 2 else 0) j = mid while i < mid and j < N: while j < N and X[j] - X[i] < Z: j += 1 if j != N: ans += 1 i += 1 j += 1 print(ans) def __starting_point(): solve() __starting_point()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR WHILE VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? -----Input----- The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β€” the number of points and the constraint on the distance between matched points, respectively. The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$). -----Output----- Print one integer β€” the maximum number of pairs of points you can match with each other. -----Examples----- Input 4 2 1 3 3 7 Output 2 Input 5 5 10 9 5 8 7 Output 1 -----Note----- In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$). In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
import sys sys.setrecursionlimit(10**5 + 1) inf = int(10**20) max_val = inf min_val = -inf RW = lambda: sys.stdin.readline().strip() RI = lambda: int(RW()) RMI = lambda: [int(x) for x in sys.stdin.readline().strip().split()] RWI = lambda: [x for x in sys.stdin.readline().strip().split()] nb_elem, min_diff = RMI() elems = sorted(RMI()) mids = nb_elem // 2 left, rite, ans = 0, mids, 0 while left < mids and rite < nb_elem: if elems[left] + min_diff <= elems[rite]: left += 1 ans += 1 rite += 1 print(ans)
IMPORT EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? -----Input----- The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β€” the number of points and the constraint on the distance between matched points, respectively. The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$). -----Output----- Print one integer β€” the maximum number of pairs of points you can match with each other. -----Examples----- Input 4 2 1 3 3 7 Output 2 Input 5 5 10 9 5 8 7 Output 1 -----Note----- In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$). In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
def solve(v, z): n = len(v) v.sort() def construct(k): res = True for f in range(n - 1, n - k - 1, -1): low = f - n + k if v[f] < v[low] + z: res = False break return res lo = 0 hi = n // 2 while hi - lo > 0: if hi - lo == 1: return hi if construct(hi) else lo mid = (hi + lo) // 2 if construct(mid): lo = mid else: hi = mid return lo n, z = [int(x) for x in input().split()] v = [int(x) for x in input().split()] print(solve(v, z))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? -----Input----- The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β€” the number of points and the constraint on the distance between matched points, respectively. The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$). -----Output----- Print one integer β€” the maximum number of pairs of points you can match with each other. -----Examples----- Input 4 2 1 3 3 7 Output 2 Input 5 5 10 9 5 8 7 Output 1 -----Note----- In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$). In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
import sys n, z = list(map(int, sys.stdin.readline().strip().split())) x = list(map(int, sys.stdin.readline().strip().split())) x.sort() i = 0 j = n // 2 c = 0 while j < n and i < n // 2: if x[j] - x[i] >= z: i = i + 1 j = j + 1 c = c + 1 else: j = j + 1 print(c)
IMPORT ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL 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 NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states i, j and k are selected, where i < j < k. After that the following process happens: 1. initially the atom is in the state i, 2. we spend Ek - Ei energy to put the atom in the state k, 3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j, 4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei, 5. the process repeats from step 1. Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy. Due to some limitations, Arkady can only choose such three states that Ek - Ei ≀ U. Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints. Input The first line contains two integers n and U (3 ≀ n ≀ 105, 1 ≀ U ≀ 109) β€” the number of states and the maximum possible difference between Ek and Ei. The second line contains a sequence of integers E1, E2, ..., En (1 ≀ E1 < E2... < En ≀ 109). It is guaranteed that all Ei are given in increasing order. Output If it is not possible to choose three states that satisfy all constraints, print -1. Otherwise, print one real number Ξ· β€” the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 4 4 1 3 5 7 Output 0.5 Input 10 8 10 13 15 16 17 19 20 22 24 25 Output 0.875 Input 3 1 2 5 10 Output -1 Note In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>. In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>.
n, u = map(int, input().split()) e = list(map(int, input().split())) res = -1 k = 2 for i in range(n - 2): j = i + 1 k = max(k, j + 1) while k < n and e[k] - e[i] <= u: k += 1 k -= 1 if k > j: res = max(res, (e[k] - e[j]) / (e[k] - e[i])) print(res)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states i, j and k are selected, where i < j < k. After that the following process happens: 1. initially the atom is in the state i, 2. we spend Ek - Ei energy to put the atom in the state k, 3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j, 4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei, 5. the process repeats from step 1. Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy. Due to some limitations, Arkady can only choose such three states that Ek - Ei ≀ U. Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints. Input The first line contains two integers n and U (3 ≀ n ≀ 105, 1 ≀ U ≀ 109) β€” the number of states and the maximum possible difference between Ek and Ei. The second line contains a sequence of integers E1, E2, ..., En (1 ≀ E1 < E2... < En ≀ 109). It is guaranteed that all Ei are given in increasing order. Output If it is not possible to choose three states that satisfy all constraints, print -1. Otherwise, print one real number Ξ· β€” the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 4 4 1 3 5 7 Output 0.5 Input 10 8 10 13 15 16 17 19 20 22 24 25 Output 0.875 Input 3 1 2 5 10 Output -1 Note In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>. In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>.
N, U = map(int, input().strip().split()) E = list(map(int, input().strip().split())) maxu = -1 j = 2 if N < 3: print(-1) for i in range(N - 2): j = max(i + 2, j) if E[j] - E[i] > U: continue while j < N and E[j] - E[i] <= U: j += 1 j -= 1 maxu = max(maxu, (E[j] - E[i + 1]) / (E[j] - E[i])) print(maxu)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR VAR WHILE VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states i, j and k are selected, where i < j < k. After that the following process happens: 1. initially the atom is in the state i, 2. we spend Ek - Ei energy to put the atom in the state k, 3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j, 4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei, 5. the process repeats from step 1. Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy. Due to some limitations, Arkady can only choose such three states that Ek - Ei ≀ U. Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints. Input The first line contains two integers n and U (3 ≀ n ≀ 105, 1 ≀ U ≀ 109) β€” the number of states and the maximum possible difference between Ek and Ei. The second line contains a sequence of integers E1, E2, ..., En (1 ≀ E1 < E2... < En ≀ 109). It is guaranteed that all Ei are given in increasing order. Output If it is not possible to choose three states that satisfy all constraints, print -1. Otherwise, print one real number Ξ· β€” the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 4 4 1 3 5 7 Output 0.5 Input 10 8 10 13 15 16 17 19 20 22 24 25 Output 0.875 Input 3 1 2 5 10 Output -1 Note In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>. In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>.
n, U = map(int, input().split()) E = [int(x) for x in input().split()] E.append(10**100) k = 0 best = -1 for i in range(n): while E[k + 1] - E[i] <= U: k += 1 j = i + 1 if i < j < k: best = max(best, (E[k] - E[j]) / (E[k] - E[i])) print(best)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states i, j and k are selected, where i < j < k. After that the following process happens: 1. initially the atom is in the state i, 2. we spend Ek - Ei energy to put the atom in the state k, 3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j, 4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei, 5. the process repeats from step 1. Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy. Due to some limitations, Arkady can only choose such three states that Ek - Ei ≀ U. Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints. Input The first line contains two integers n and U (3 ≀ n ≀ 105, 1 ≀ U ≀ 109) β€” the number of states and the maximum possible difference between Ek and Ei. The second line contains a sequence of integers E1, E2, ..., En (1 ≀ E1 < E2... < En ≀ 109). It is guaranteed that all Ei are given in increasing order. Output If it is not possible to choose three states that satisfy all constraints, print -1. Otherwise, print one real number Ξ· β€” the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 4 4 1 3 5 7 Output 0.5 Input 10 8 10 13 15 16 17 19 20 22 24 25 Output 0.875 Input 3 1 2 5 10 Output -1 Note In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>. In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>.
import sys [n, U] = map(int, sys.stdin.readline().strip().split()) E = list(map(int, sys.stdin.readline().strip().split())) max_eta = -1 k = 2 for i in range(n - 2): k = max(k, i + 2) if E[k] - E[i] > U: continue while k + 1 < n and E[k + 1] - E[i] <= U: k += 1 eta = (E[k] - E[i + 1]) / (E[k] - E[i]) max_eta = max(max_eta, eta) if max_eta < 0: print(max_eta) else: print("{:.10f}".format(max_eta))
IMPORT ASSIGN LIST VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR WHILE BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states i, j and k are selected, where i < j < k. After that the following process happens: 1. initially the atom is in the state i, 2. we spend Ek - Ei energy to put the atom in the state k, 3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j, 4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei, 5. the process repeats from step 1. Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy. Due to some limitations, Arkady can only choose such three states that Ek - Ei ≀ U. Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints. Input The first line contains two integers n and U (3 ≀ n ≀ 105, 1 ≀ U ≀ 109) β€” the number of states and the maximum possible difference between Ek and Ei. The second line contains a sequence of integers E1, E2, ..., En (1 ≀ E1 < E2... < En ≀ 109). It is guaranteed that all Ei are given in increasing order. Output If it is not possible to choose three states that satisfy all constraints, print -1. Otherwise, print one real number Ξ· β€” the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 4 4 1 3 5 7 Output 0.5 Input 10 8 10 13 15 16 17 19 20 22 24 25 Output 0.875 Input 3 1 2 5 10 Output -1 Note In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>. In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>.
n, U = [int(c) for c in input().split(" ")] E = [int(c) for c in input().split(" ")] def binary_max_search(max_limit): left, right = 0, n - 1 while left < right: mid = (left + right) // 2 + 1 if E[mid] <= max_limit: left, right = mid, right else: left, right = left, mid - 1 return left max_conversion_rate = -1 for i in range(n - 2): k = binary_max_search(U + E[i]) if k > i + 1: temp = (E[k] - E[i + 1]) / (E[k] - E[i]) if temp > max_conversion_rate: max_conversion_rate = temp print(max_conversion_rate)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states i, j and k are selected, where i < j < k. After that the following process happens: 1. initially the atom is in the state i, 2. we spend Ek - Ei energy to put the atom in the state k, 3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j, 4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei, 5. the process repeats from step 1. Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy. Due to some limitations, Arkady can only choose such three states that Ek - Ei ≀ U. Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints. Input The first line contains two integers n and U (3 ≀ n ≀ 105, 1 ≀ U ≀ 109) β€” the number of states and the maximum possible difference between Ek and Ei. The second line contains a sequence of integers E1, E2, ..., En (1 ≀ E1 < E2... < En ≀ 109). It is guaranteed that all Ei are given in increasing order. Output If it is not possible to choose three states that satisfy all constraints, print -1. Otherwise, print one real number Ξ· β€” the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 4 4 1 3 5 7 Output 0.5 Input 10 8 10 13 15 16 17 19 20 22 24 25 Output 0.875 Input 3 1 2 5 10 Output -1 Note In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>. In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>.
nE, U = [int(x) for x in input().split(" ")] energies = [int(x) for x in input().split(" ")] end = 0 best_ratio = -1 for beg in range(nE - 2): while end + 1 < nE and energies[end + 1] - energies[beg] <= U: end += 1 if end - beg < 2: continue new_ratio = (energies[end] - energies[beg + 1]) / (energies[end] - energies[beg]) best_ratio = max(best_ratio, new_ratio) if best_ratio == -1: print(-1) else: print("%.20f" % best_ratio)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states i, j and k are selected, where i < j < k. After that the following process happens: 1. initially the atom is in the state i, 2. we spend Ek - Ei energy to put the atom in the state k, 3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j, 4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei, 5. the process repeats from step 1. Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy. Due to some limitations, Arkady can only choose such three states that Ek - Ei ≀ U. Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints. Input The first line contains two integers n and U (3 ≀ n ≀ 105, 1 ≀ U ≀ 109) β€” the number of states and the maximum possible difference between Ek and Ei. The second line contains a sequence of integers E1, E2, ..., En (1 ≀ E1 < E2... < En ≀ 109). It is guaranteed that all Ei are given in increasing order. Output If it is not possible to choose three states that satisfy all constraints, print -1. Otherwise, print one real number Ξ· β€” the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 4 4 1 3 5 7 Output 0.5 Input 10 8 10 13 15 16 17 19 20 22 24 25 Output 0.875 Input 3 1 2 5 10 Output -1 Note In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>. In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>.
n, u = map(int, input().split()) arr = list(map(int, input().split())) j, i = 1, 0 maxi = -1 flag = 0 for i in range(n - 1): if arr[i + 1] - arr[i] <= u: flag = 1 if flag == 0: print("-1") exit() i = 0 while i < n - 2: while 1: if j >= n: j = n - 1 break if arr[j] - arr[i] > u: j -= 1 break j += 1 if i == j: j += 1 elif arr[j] == arr[i]: pass elif arr[j] - arr[i] <= u: maxi = max(maxi, (arr[j] - arr[i + 1]) / (arr[j] - arr[i])) i += 1 if maxi == 0: print("-1") else: print(maxi)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER WHILE NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states i, j and k are selected, where i < j < k. After that the following process happens: 1. initially the atom is in the state i, 2. we spend Ek - Ei energy to put the atom in the state k, 3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j, 4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei, 5. the process repeats from step 1. Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy. Due to some limitations, Arkady can only choose such three states that Ek - Ei ≀ U. Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints. Input The first line contains two integers n and U (3 ≀ n ≀ 105, 1 ≀ U ≀ 109) β€” the number of states and the maximum possible difference between Ek and Ei. The second line contains a sequence of integers E1, E2, ..., En (1 ≀ E1 < E2... < En ≀ 109). It is guaranteed that all Ei are given in increasing order. Output If it is not possible to choose three states that satisfy all constraints, print -1. Otherwise, print one real number Ξ· β€” the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 4 4 1 3 5 7 Output 0.5 Input 10 8 10 13 15 16 17 19 20 22 24 25 Output 0.875 Input 3 1 2 5 10 Output -1 Note In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>. In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>.
n, U = list(map(int, input().split())) E = list(map(int, input().split())) ind_i = 0 prev_ind_k = ind_i + 2 maxi_efficiency = -1 turn = 0 for ind_i in range(0, n - 2): ind_j = ind_i + 1 prev_ind_k = max(prev_ind_k, ind_i + 2) Ei = E[ind_i] Ej = E[ind_j] for ind_k in range(prev_ind_k, n + 1): if ind_k == n: prev_ind_k = n - 1 break Ek = E[ind_k] if Ek - Ei > U: prev_ind_k = ind_k - 1 break efficiency = (Ek - Ej) / (Ek - Ei) if efficiency > maxi_efficiency: maxi_efficiency = efficiency print(maxi_efficiency)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states i, j and k are selected, where i < j < k. After that the following process happens: 1. initially the atom is in the state i, 2. we spend Ek - Ei energy to put the atom in the state k, 3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j, 4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei, 5. the process repeats from step 1. Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy. Due to some limitations, Arkady can only choose such three states that Ek - Ei ≀ U. Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints. Input The first line contains two integers n and U (3 ≀ n ≀ 105, 1 ≀ U ≀ 109) β€” the number of states and the maximum possible difference between Ek and Ei. The second line contains a sequence of integers E1, E2, ..., En (1 ≀ E1 < E2... < En ≀ 109). It is guaranteed that all Ei are given in increasing order. Output If it is not possible to choose three states that satisfy all constraints, print -1. Otherwise, print one real number Ξ· β€” the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 4 4 1 3 5 7 Output 0.5 Input 10 8 10 13 15 16 17 19 20 22 24 25 Output 0.875 Input 3 1 2 5 10 Output -1 Note In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>. In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>.
n, U = map(int, input().split()) E = list(map(int, input().split())) best = -1 k = 0 for i in range(n): while k + 1 < n and E[k + 1] - E[i] <= U: k += 1 if k >= i + 2: best = max(best, (E[k] - E[i + 1]) / (E[k] - E[i])) print(best)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states i, j and k are selected, where i < j < k. After that the following process happens: 1. initially the atom is in the state i, 2. we spend Ek - Ei energy to put the atom in the state k, 3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j, 4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei, 5. the process repeats from step 1. Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy. Due to some limitations, Arkady can only choose such three states that Ek - Ei ≀ U. Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints. Input The first line contains two integers n and U (3 ≀ n ≀ 105, 1 ≀ U ≀ 109) β€” the number of states and the maximum possible difference between Ek and Ei. The second line contains a sequence of integers E1, E2, ..., En (1 ≀ E1 < E2... < En ≀ 109). It is guaranteed that all Ei are given in increasing order. Output If it is not possible to choose three states that satisfy all constraints, print -1. Otherwise, print one real number Ξ· β€” the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 4 4 1 3 5 7 Output 0.5 Input 10 8 10 13 15 16 17 19 20 22 24 25 Output 0.875 Input 3 1 2 5 10 Output -1 Note In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>. In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>.
def sss(l, r, tt): f = -1 while l <= r: mid = l + r >> 1 if a[mid] - a[tt] <= m: f = mid l = mid + 1 else: r = mid - 1 return f n, m = map(int, input().split()) a = [int(x) for x in input().split()] f = 0 l = len(a) Maxx = -1 for i in range(0, l - 2): if a[i + 2] - a[i] <= m: k = sss(i + 2, l - 1, i) if k != -1: Maxx = max(Maxx, (a[k] - a[i + 1]) / (a[k] - a[i])) if Maxx == -1: print(-1) else: print("%.15f\n" % Maxx)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states i, j and k are selected, where i < j < k. After that the following process happens: 1. initially the atom is in the state i, 2. we spend Ek - Ei energy to put the atom in the state k, 3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j, 4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei, 5. the process repeats from step 1. Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy. Due to some limitations, Arkady can only choose such three states that Ek - Ei ≀ U. Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints. Input The first line contains two integers n and U (3 ≀ n ≀ 105, 1 ≀ U ≀ 109) β€” the number of states and the maximum possible difference between Ek and Ei. The second line contains a sequence of integers E1, E2, ..., En (1 ≀ E1 < E2... < En ≀ 109). It is guaranteed that all Ei are given in increasing order. Output If it is not possible to choose three states that satisfy all constraints, print -1. Otherwise, print one real number Ξ· β€” the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 4 4 1 3 5 7 Output 0.5 Input 10 8 10 13 15 16 17 19 20 22 24 25 Output 0.875 Input 3 1 2 5 10 Output -1 Note In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>. In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>.
n, u = map(int, input().split()) a = list(map(int, input().split())) i = 0 j = 1 f = 1 ma = -1 while not (i == j and i == n - 1): if j <= i: j += 1 if j < n - 1: if a[j + 1] - a[i] <= u: j += 1 else: if j - i >= 2: f = 0 ma = max(ma, (a[j] - a[i + 1]) / (a[j] - a[i])) i += 1 else: if j - i >= 2: f = 0 ma = max(ma, (a[j] - a[i + 1]) / (a[j] - a[i])) i += 1 if f: print(-1) else: print(ma)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states i, j and k are selected, where i < j < k. After that the following process happens: 1. initially the atom is in the state i, 2. we spend Ek - Ei energy to put the atom in the state k, 3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j, 4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei, 5. the process repeats from step 1. Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy. Due to some limitations, Arkady can only choose such three states that Ek - Ei ≀ U. Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints. Input The first line contains two integers n and U (3 ≀ n ≀ 105, 1 ≀ U ≀ 109) β€” the number of states and the maximum possible difference between Ek and Ei. The second line contains a sequence of integers E1, E2, ..., En (1 ≀ E1 < E2... < En ≀ 109). It is guaranteed that all Ei are given in increasing order. Output If it is not possible to choose three states that satisfy all constraints, print -1. Otherwise, print one real number Ξ· β€” the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 4 4 1 3 5 7 Output 0.5 Input 10 8 10 13 15 16 17 19 20 22 24 25 Output 0.875 Input 3 1 2 5 10 Output -1 Note In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>. In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>.
par = input() par = list(map(int, par.split())) n, U = par[0], par[1] E = input() E = list(map(int, E.split())) f = -1 idx = 0 for i in range(n - 2): while idx < n - 1 and E[idx + 1] <= E[i] + U: idx += 1 if idx - i < 2: continue else: f = max((E[idx] - E[i + 1]) / (E[idx] - E[i]), f) print(f)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states i, j and k are selected, where i < j < k. After that the following process happens: 1. initially the atom is in the state i, 2. we spend Ek - Ei energy to put the atom in the state k, 3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j, 4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei, 5. the process repeats from step 1. Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy. Due to some limitations, Arkady can only choose such three states that Ek - Ei ≀ U. Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints. Input The first line contains two integers n and U (3 ≀ n ≀ 105, 1 ≀ U ≀ 109) β€” the number of states and the maximum possible difference between Ek and Ei. The second line contains a sequence of integers E1, E2, ..., En (1 ≀ E1 < E2... < En ≀ 109). It is guaranteed that all Ei are given in increasing order. Output If it is not possible to choose three states that satisfy all constraints, print -1. Otherwise, print one real number Ξ· β€” the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 4 4 1 3 5 7 Output 0.5 Input 10 8 10 13 15 16 17 19 20 22 24 25 Output 0.875 Input 3 1 2 5 10 Output -1 Note In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>. In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>.
import sys def read_two_int(): return map(int, sys.stdin.readline().strip().split(" ")) def fast_solution(n, U, E): best = -1 R = 2 for i in range(n - 2): R = max(R, i + 2) while R + 1 < n and E[R + 1] - E[i] <= U: R += 1 if E[R] - E[i] <= U: efficiency = float(E[R] - E[i + 1]) / (E[R] - E[i]) if best is None or efficiency > best: best = efficiency return best n, U = read_two_int() E = list(read_two_int()) print(fast_solution(n, U, E))
IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR IF VAR NONE VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states i, j and k are selected, where i < j < k. After that the following process happens: 1. initially the atom is in the state i, 2. we spend Ek - Ei energy to put the atom in the state k, 3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j, 4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei, 5. the process repeats from step 1. Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy. Due to some limitations, Arkady can only choose such three states that Ek - Ei ≀ U. Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints. Input The first line contains two integers n and U (3 ≀ n ≀ 105, 1 ≀ U ≀ 109) β€” the number of states and the maximum possible difference between Ek and Ei. The second line contains a sequence of integers E1, E2, ..., En (1 ≀ E1 < E2... < En ≀ 109). It is guaranteed that all Ei are given in increasing order. Output If it is not possible to choose three states that satisfy all constraints, print -1. Otherwise, print one real number Ξ· β€” the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 4 4 1 3 5 7 Output 0.5 Input 10 8 10 13 15 16 17 19 20 22 24 25 Output 0.875 Input 3 1 2 5 10 Output -1 Note In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>. In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>.
n, u = map(int, input().split()) e = list(map(int, input().split())) e = sorted(e) r = 1 ans = -1 for i in range(n - 2): k = e[i + 1] - e[i] while r < n and e[r] - e[i] <= u: r += 1 pr = r - 1 if pr - i >= 2: ans = max(ans, (e[pr] - e[i + 1]) / (e[pr] - e[i])) if ans == -1: print(-1) exit() print("%.12f" % ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR WHILE VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states i, j and k are selected, where i < j < k. After that the following process happens: 1. initially the atom is in the state i, 2. we spend Ek - Ei energy to put the atom in the state k, 3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j, 4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei, 5. the process repeats from step 1. Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy. Due to some limitations, Arkady can only choose such three states that Ek - Ei ≀ U. Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints. Input The first line contains two integers n and U (3 ≀ n ≀ 105, 1 ≀ U ≀ 109) β€” the number of states and the maximum possible difference between Ek and Ei. The second line contains a sequence of integers E1, E2, ..., En (1 ≀ E1 < E2... < En ≀ 109). It is guaranteed that all Ei are given in increasing order. Output If it is not possible to choose three states that satisfy all constraints, print -1. Otherwise, print one real number Ξ· β€” the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 4 4 1 3 5 7 Output 0.5 Input 10 8 10 13 15 16 17 19 20 22 24 25 Output 0.875 Input 3 1 2 5 10 Output -1 Note In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>. In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>.
n, u = map(int, input().split()) a = list(map(int, input().split())) l, r = 0, 0 ans = -1 for i in range(n): r = max(l, r) while r < n - 1 and a[r + 1] - a[l] <= u: r += 1 if r - l > 1 and a[r] - a[l] <= u: ans = max(ans, (a[r] - a[l + 1]) / (a[r] - a[l])) l += 1 print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a multiset S consisting of positive integers (initially empty). There are two kind of queries: Add a positive integer to S, the newly added integer is not less than any number in it. Find a subset s of the set S such that the value $\operatorname{max}(s) - \operatorname{mean}(s)$ is maximum possible. Here max(s) means maximum value of elements in s, $\operatorname{mean}(s)$Β β€” the average value of numbers in s. Output this maximum possible value of $\operatorname{max}(s) - \operatorname{mean}(s)$. -----Input----- The first line contains a single integer Q (1 ≀ Q ≀ 5Β·10^5)Β β€” the number of queries. Each of the next Q lines contains a description of query. For queries of type 1 two integers 1 and x are given, where x (1 ≀ x ≀ 10^9) is a number that you should add to S. It's guaranteed that x is not less than any number in S. For queries of type 2, a single integer 2 is given. It's guaranteed that the first query has type 1, i.Β e. S is not empty when a query of type 2 comes. -----Output----- Output the answer for each query of the second type in the order these queries are given in input. Each number should be printed in separate line. Your answer is considered correct, if each of your answers has absolute or relative error not greater than 10^{ - 6}. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if $\frac{|a - b|}{\operatorname{max}(1,|b|)} \leq 10^{-6}$. -----Examples----- Input 6 1 3 2 1 4 2 1 8 2 Output 0.0000000000 0.5000000000 3.0000000000 Input 4 1 1 1 4 1 5 2 Output 2.0000000000
q = int(input()) s = input().split() a = [int(s[1])] sum1 = a[0] pos = -1 mean = sum1 fin = "" for i in range(q - 1): n = len(a) s = input().split() if s[0] == "1": a.append(int(s[1])) sum1 += a[-1] - a[-2] mean = sum1 / (pos + 2) n = len(a) while pos < n - 2 and a[pos + 1] < mean: pos += 1 sum1 += a[pos] mean = sum1 / (pos + 2) else: fin += str(a[-1] - mean) + "\n" print(fin)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR STRING EXPR FUNC_CALL VAR VAR
You are given a multiset S consisting of positive integers (initially empty). There are two kind of queries: Add a positive integer to S, the newly added integer is not less than any number in it. Find a subset s of the set S such that the value $\operatorname{max}(s) - \operatorname{mean}(s)$ is maximum possible. Here max(s) means maximum value of elements in s, $\operatorname{mean}(s)$Β β€” the average value of numbers in s. Output this maximum possible value of $\operatorname{max}(s) - \operatorname{mean}(s)$. -----Input----- The first line contains a single integer Q (1 ≀ Q ≀ 5Β·10^5)Β β€” the number of queries. Each of the next Q lines contains a description of query. For queries of type 1 two integers 1 and x are given, where x (1 ≀ x ≀ 10^9) is a number that you should add to S. It's guaranteed that x is not less than any number in S. For queries of type 2, a single integer 2 is given. It's guaranteed that the first query has type 1, i.Β e. S is not empty when a query of type 2 comes. -----Output----- Output the answer for each query of the second type in the order these queries are given in input. Each number should be printed in separate line. Your answer is considered correct, if each of your answers has absolute or relative error not greater than 10^{ - 6}. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if $\frac{|a - b|}{\operatorname{max}(1,|b|)} \leq 10^{-6}$. -----Examples----- Input 6 1 3 2 1 4 2 1 8 2 Output 0.0000000000 0.5000000000 3.0000000000 Input 4 1 1 1 4 1 5 2 Output 2.0000000000
import sys s, left_index, sub_sum, subset = [], -1, 0, 1 input() for line in sys.stdin: inp = list(map(int, line.split())) if inp[0] == 2: sub_sum += s[-1] for j in range(left_index + 1, len(s)): if s[j] <= sub_sum / subset: sub_sum += s[j] subset += 1 left_index += 1 else: break print(s[-1] - sub_sum / subset) sub_sum -= s[-1] else: s.append(inp[1])
IMPORT ASSIGN VAR VAR VAR VAR LIST NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR IF VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
You are given a multiset S consisting of positive integers (initially empty). There are two kind of queries: Add a positive integer to S, the newly added integer is not less than any number in it. Find a subset s of the set S such that the value $\operatorname{max}(s) - \operatorname{mean}(s)$ is maximum possible. Here max(s) means maximum value of elements in s, $\operatorname{mean}(s)$Β β€” the average value of numbers in s. Output this maximum possible value of $\operatorname{max}(s) - \operatorname{mean}(s)$. -----Input----- The first line contains a single integer Q (1 ≀ Q ≀ 5Β·10^5)Β β€” the number of queries. Each of the next Q lines contains a description of query. For queries of type 1 two integers 1 and x are given, where x (1 ≀ x ≀ 10^9) is a number that you should add to S. It's guaranteed that x is not less than any number in S. For queries of type 2, a single integer 2 is given. It's guaranteed that the first query has type 1, i.Β e. S is not empty when a query of type 2 comes. -----Output----- Output the answer for each query of the second type in the order these queries are given in input. Each number should be printed in separate line. Your answer is considered correct, if each of your answers has absolute or relative error not greater than 10^{ - 6}. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if $\frac{|a - b|}{\operatorname{max}(1,|b|)} \leq 10^{-6}$. -----Examples----- Input 6 1 3 2 1 4 2 1 8 2 Output 0.0000000000 0.5000000000 3.0000000000 Input 4 1 1 1 4 1 5 2 Output 2.0000000000
import sys input = sys.stdin.readline Q = int(input()) a = [] sm = [] def best(): mx = a[-1] n = len(a) l, r = 0, n - 2 ret = mx while l <= r: mid = (l + r) // 2 s = sm[mid] + mx c = mid + 2 avg = s / c if a[mid] > avg: r = mid - 1 else: ret = avg l = mid + 1 return ret for _ in range(Q): inp = [int(i) for i in input().split()] if len(inp) == 2: x = inp[1] a.append(x) sm.append((sm[-1] if sm else 0) + x) else: mx = a[-1] avg = best() ans = mx - avg print(ans)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
You are given a multiset S consisting of positive integers (initially empty). There are two kind of queries: Add a positive integer to S, the newly added integer is not less than any number in it. Find a subset s of the set S such that the value $\operatorname{max}(s) - \operatorname{mean}(s)$ is maximum possible. Here max(s) means maximum value of elements in s, $\operatorname{mean}(s)$Β β€” the average value of numbers in s. Output this maximum possible value of $\operatorname{max}(s) - \operatorname{mean}(s)$. -----Input----- The first line contains a single integer Q (1 ≀ Q ≀ 5Β·10^5)Β β€” the number of queries. Each of the next Q lines contains a description of query. For queries of type 1 two integers 1 and x are given, where x (1 ≀ x ≀ 10^9) is a number that you should add to S. It's guaranteed that x is not less than any number in S. For queries of type 2, a single integer 2 is given. It's guaranteed that the first query has type 1, i.Β e. S is not empty when a query of type 2 comes. -----Output----- Output the answer for each query of the second type in the order these queries are given in input. Each number should be printed in separate line. Your answer is considered correct, if each of your answers has absolute or relative error not greater than 10^{ - 6}. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if $\frac{|a - b|}{\operatorname{max}(1,|b|)} \leq 10^{-6}$. -----Examples----- Input 6 1 3 2 1 4 2 1 8 2 Output 0.0000000000 0.5000000000 3.0000000000 Input 4 1 1 1 4 1 5 2 Output 2.0000000000
from sys import stdin def mean(p): return (c[p] + a[-1]) / (p + 2) def check(p): return mean(p) >= a[p] def binary(a, b): low, high = a - 1, b + 1 while high - low > 1: mid = (low + high) // 2 if check(mid): low = mid else: high = mid return low all = stdin.readlines() q = int(all[0]) za = list(map(lambda x: tuple(map(int, x.split())), all[1:])) a, c = [za[0][1]], [za[0][1]] ans = [] for i in za[1:]: if i[0] == 1: a.append(i[1]) c.append(i[1] + c[-1]) else: k = binary(0, len(a) - 1) ans.append(a[-1] - mean(k)) print("\n".join(map(str, ans)))
FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR LIST VAR NUMBER NUMBER LIST VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
You are given a multiset S consisting of positive integers (initially empty). There are two kind of queries: Add a positive integer to S, the newly added integer is not less than any number in it. Find a subset s of the set S such that the value $\operatorname{max}(s) - \operatorname{mean}(s)$ is maximum possible. Here max(s) means maximum value of elements in s, $\operatorname{mean}(s)$Β β€” the average value of numbers in s. Output this maximum possible value of $\operatorname{max}(s) - \operatorname{mean}(s)$. -----Input----- The first line contains a single integer Q (1 ≀ Q ≀ 5Β·10^5)Β β€” the number of queries. Each of the next Q lines contains a description of query. For queries of type 1 two integers 1 and x are given, where x (1 ≀ x ≀ 10^9) is a number that you should add to S. It's guaranteed that x is not less than any number in S. For queries of type 2, a single integer 2 is given. It's guaranteed that the first query has type 1, i.Β e. S is not empty when a query of type 2 comes. -----Output----- Output the answer for each query of the second type in the order these queries are given in input. Each number should be printed in separate line. Your answer is considered correct, if each of your answers has absolute or relative error not greater than 10^{ - 6}. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if $\frac{|a - b|}{\operatorname{max}(1,|b|)} \leq 10^{-6}$. -----Examples----- Input 6 1 3 2 1 4 2 1 8 2 Output 0.0000000000 0.5000000000 3.0000000000 Input 4 1 1 1 4 1 5 2 Output 2.0000000000
import sys def input(): return sys.stdin.buffer.readline() Q = int(input()) stack = [] pos = 0 query = [tuple(map(int, input().split())) for i in range(Q)] S = 0 for que in query: command = que[0] if command == 1: stack.append(que[1]) continue last_number = stack[-1] while pos < len(stack) and (pos + 2) * (last_number + S) > (pos + 1) * ( last_number + S + stack[pos] ): S += stack[pos] pos += 1 print(last_number - (last_number + S) / (pos + 1)) continue
IMPORT FUNC_DEF RETURN FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
for _ in range(int(input())): x, y, z = map(int, input().split()) a = sorted(map(int, input().split())) b = sorted(map(int, input().split())) c = sorted(map(int, input().split())) i, j, k, ans = 0, 0, 0, (a[0] - b[0]) ** 2 + (a[0] - c[0]) ** 2 + (b[0] - c[0]) ** 2 while i < x and j < y and k < z: ans1 = ans2 = ans3 = float("inf") if i + 1 < x: ans1 = (a[i + 1] - b[j]) ** 2 + (b[j] - c[k]) ** 2 + (a[i + 1] - c[k]) ** 2 if j + 1 < y: ans2 = (a[i] - b[j + 1]) ** 2 + (b[j + 1] - c[k]) ** 2 + (a[i] - c[k]) ** 2 if k + 1 < z: ans3 = (a[i] - b[j]) ** 2 + (b[j] - c[k + 1]) ** 2 + (a[i] - c[k + 1]) ** 2 m = min(ans1, ans2, ans3) ans = min(ans, m) if m == ans1: i += 1 elif m == ans2: j += 1 elif m == ans3: k += 1 print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
def find(arr, flag, num): if flag: low = 0 high = len(arr) - 1 while low < high: mid = (low + high) // 2 if arr[mid] < num: low = mid + 1 else: high = mid - 1 if arr[low] < num: if low != len(arr) - 1: return arr[low + 1] else: return 10**20 else: return arr[low] else: low = 0 high = len(arr) - 1 while low < high: mid = (low + high) // 2 if arr[mid] < num: low = mid + 1 else: high = mid - 1 if arr[low] > num: if low != 0: return arr[low - 1] else: return 10**20 else: return arr[low] def solve(a, b, c): ans = 10**20 for i in b: x = find(a, 0, i) y = find(c, 1, i) ans = min(ans, (i - x) ** 2 + (i - y) ** 2 + (x - y) ** 2) return ans for nt in range(int(input())): n1, n2, n3 = map(int, input().split()) l1 = sorted(list(map(int, input().split()))) l2 = sorted(list(map(int, input().split()))) l3 = sorted(list(map(int, input().split()))) ans = solve(l1, l2, l3) ans = min(ans, solve(l1, l3, l2)) ans = min(ans, solve(l2, l1, l3)) ans = min(ans, solve(l2, l3, l1)) ans = min(ans, solve(l3, l1, l2)) print(min(ans, solve(l3, l2, l1)))
FUNC_DEF IF VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN VAR BIN_OP VAR NUMBER RETURN BIN_OP NUMBER NUMBER RETURN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR IF VAR NUMBER RETURN VAR BIN_OP VAR NUMBER RETURN BIN_OP NUMBER NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR 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 RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 FUNC_CALL VAR VAR FUNC_CALL 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 VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
def f(x, y, z): return (x - y) ** 2 + (y - z) ** 2 + (z - x) ** 2 for _ in range(int(input())): nr, ng, nb = map(int, input().split()) r = list(map(int, input().split())) g = list(map(int, input().split())) b = list(map(int, input().split())) T = [0] * nr + [1] * ng + [2] * nb V = r + g + b arr = sorted([[v, t] for v, t in zip(V, T)], key=lambda x: x[0]) nei = [[] for _ in range(nr + ng + nb)] cur = [None, None, None] for i in range(len(arr)): v, t = arr[i] cur[t] = i nei1 = cur[(t + 1) % 3] nei2 = cur[(t + 2) % 3] if nei1 is not None: nei[i].append(nei1) if nei2 is not None: nei[i].append(nei2) cur = [None, None, None] for i in range(len(arr) - 1, -1, -1): v, t = arr[i] cur[t] = i nei1 = cur[(t + 1) % 3] nei2 = cur[(t + 2) % 3] if nei1 is not None: nei[i].append(nei1) if nei2 is not None: nei[i].append(nei2) ans = float("inf") for i, a in enumerate(nei): val = arr[i][0] for j in range(len(a)): for k in range(j + 1, len(a)): ind1, ind2 = a[j], a[k] val1, val2 = arr[ind1][0], arr[ind2][0] t1, t2 = arr[ind1][1], arr[ind2][1] if t1 != t2: ans = min(ans, f(val1, val2, val)) print(ans)
FUNC_DEF RETURN 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 FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR LIST VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR LIST NONE NONE NONE FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NONE EXPR FUNC_CALL VAR VAR VAR IF VAR NONE EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST NONE NONE NONE FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NONE EXPR FUNC_CALL VAR VAR VAR IF VAR NONE EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
import sys read = sys.stdin.buffer.read input = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def lowerIndex(arr, n, x): l = 0 h = n - 1 while l <= h: mid = int((l + h) / 2) if arr[mid] >= x: h = mid - 1 else: l = mid + 1 return l def upperIndex(arr, n, x): l = 0 h = n - 1 while l <= h: mid = int((l + h) / 2) if arr[mid] <= x: l = mid + 1 else: h = mid - 1 return h def cr(arr, n, x, y): if (x + y) % 2 == 0: s = (x + y) // 2 h = upperIndex(arr, n, s) q = lowerIndex(arr, n, s) r = 10000000000000000000000 g = 10000000000000000000000 if h >= 0: u = arr[h] r = (y - u) ** 2 + (u - x) ** 2 + (y - x) ** 2 if q < n: v = arr[q] g = (y - v) ** 2 + (v - x) ** 2 + (y - x) ** 2 r = min(r, g) else: s = int((x + y) // 2) h = upperIndex(arr, n, s) q = lowerIndex(arr, n, s + 1) r = 10000000000000000000000 g = 10000000000000000000000 if h >= 0: u = arr[h] r = (y - u) ** 2 + (u - x) ** 2 + (y - x) ** 2 if q < n: v = arr[q] g = (y - v) ** 2 + (v - x) ** 2 + (y - x) ** 2 r = min(r, g) return r def solve(A, B, C): i = len(A) - 1 j = len(B) - 1 k = len(C) - 1 x = i + 1 y = j + 1 z = k + 1 p = 100000000000000000000000000000 while i != -1 and j != -1 and k != -1: max_term = max(A[i], B[j], C[k]) min_term = min(A[i], B[j], C[k]) if A[i] == max_term and B[j] == min_term: m = cr(C, z, min_term, max_term) p = min(p, m) i -= 1 elif A[i] == max_term and C[k] == min_term: m = cr(B, y, min_term, max_term) i -= 1 p = min(p, m) elif B[j] == max_term and C[k] == min_term: m = cr(A, x, min_term, max_term) p = min(p, m) j -= 1 elif B[j] == max_term and A[i] == min_term: m = cr(C, z, min_term, max_term) p = min(p, m) j -= 1 elif C[k] == max_term and A[i] == min_term: m = cr(B, y, min_term, max_term) p = min(p, m) k -= 1 elif C[k] == max_term and B[j] == min_term: m = cr(A, x, min_term, max_term) p = min(p, m) k -= 1 return p t = int(input()) for i in range(t): x, y, z = map(int, input().split()) a = sorted(list(map(int, input().split()))) b = sorted(list(map(int, input().split()))) c = sorted(list(map(int, input().split()))) print(solve(a, b, c))
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR 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 IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR 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 FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR 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 IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR 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 FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 FUNC_CALL VAR VAR FUNC_CALL 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 VAR VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
for _ in range(int(input())): nr, ng, nb = map(int, input().split()) rs = list(map(int, input().split())) gs = list(map(int, input().split())) bs = list(map(int, input().split())) rs.sort() gs.sort() bs.sort() t = [] for c in rs: t.append((c, 1)) for c in gs: t.append((c, 2)) for c in bs: t.append((c, 3)) t.sort() left, right, cnt = 0, 0, 0 mp = [0] * 4 ans = float("inf") def f(a, b, c): return (a - b) * (a - b) + (b - c) * (b - c) + (c - a) * (c - a) def f2(arr): res = float("inf") a = arr[0][0] c = arr[-1][0] for i in range(1, len(arr) - 1): if arr[i][1] != arr[0][1] and arr[i][1] != arr[-1][1]: res = min(res, f(a, arr[i][0], c)) return res while right < len(t): mp[t[right][1]] += 1 if mp[t[right][1]] == 1: cnt += 1 right += 1 while cnt == 3: if mp[t[left][1]] == 1: ans = min(ans, f2(t[left:right])) mp[t[left][1]] -= 1 if mp[t[left][1]] == 0: cnt -= 1 left += 1 print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING FUNC_DEF RETURN 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 FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR RETURN VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
import sys input = sys.stdin.readline def inlt(): return list(map(int, input().split())) def match(a, b, c): def calculate_result(result, item1, item2, item3): return min( result, (item1 - item2) ** 2 + (item2 - item3) ** 2 + (item1 - item3) ** 2 ) len_a = len(a) len_b = len(b) len_c = len(c) a.sort(reverse=False) b.sort(reverse=False) c.sort(reverse=False) result = 10**99 index_b = 0 index_c = 0 for item in a: index_b, index_c = search(item, b, c, index_b, index_c) result = calculate_result(result, item, b[index_b], c[index_c]) if index_c < len_c - 1: result = calculate_result(result, item, b[index_b], c[index_c + 1]) if index_b < len_b - 1: result = calculate_result(result, item, b[index_b + 1], c[index_c]) return result def search(item, b, c, index_b, index_c): len_b = len(b) len_c = len(c) while b[index_b] <= item: index_b += 1 if len_b == index_b: break while c[index_c] <= item: index_c += 1 if len_c == index_c: break return max(0, index_b - 1), max(0, index_c - 1) cases = int(input()) for case in range(cases): inlt() a = inlt() b = inlt() c = inlt() result = min(match(a, b, c), match(b, c, a), match(c, a, b)) sys.__stdout__.write(str(result) + "\n")
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FUNC_DEF RETURN FUNC_CALL VAR VAR 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 FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR NUMBER IF VAR VAR WHILE VAR VAR VAR VAR NUMBER IF VAR VAR RETURN FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
q = int(input()) def solve(a, b, c, na, nc): ans = -1 for d in b: if a[0] > d or c[-1] < d: continue l = -1 r = na m = (na - 1) // 2 while l < r - 1: m = (l + r) // 2 if a[m] <= d and m == na - 1: break if a[m] <= d and a[m + 1] <= d: if l == r - 2: m += 1 break l = m elif a[m] > d: if l == r - 2: m -= 1 break r = m else: break aa = a[m] l = -1 r = nc m = (nc - 1) // 2 while l < r - 1: m = (l + r) // 2 if c[m] >= d and m == 0: break if c[m] >= d and c[m - 1] >= d: if l == r - 2: m -= 1 break r = m elif c[m] < d: if l == r - 2: m += 1 break l = m else: break cc = c[m] nans = (aa - d) ** 2 + (d - cc) ** 2 + (aa - cc) ** 2 ans = nans if ans == -1 or nans < ans else ans return ( ans if ans >= 0 else (a[0] - b[0]) ** 2 + (b[0] - c[0]) ** 2 + (c[0] - a[0]) ** 2 ) for _ in range(q): nr, ng, nb = map(int, input().split()) r = [int(i) for i in input().split()] g = [int(i) for i in input().split()] b = [int(i) for i in input().split()] r.sort() g.sort() b.sort() ans = solve(r, g, b, nr, nb) ans = min(ans, solve(b, g, r, nb, nr)) ans = min(ans, solve(g, r, b, ng, nb)) ans = min(ans, solve(b, r, g, nb, ng)) ans = min(ans, solve(r, b, g, nr, ng)) ans = min(ans, solve(g, b, r, ng, nr)) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR 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 VAR NUMBER VAR VAR VAR VAR RETURN VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
def calc(a, b, c): return (a - b) * (a - b) + (b - c) * (b - c) + (c - a) * (c - a) def binarySearchCount(arr, n, key): left = 0 right = n - 1 count = 0 while left <= right: mid = int((right + left) / 2) if arr[mid] <= key: count = mid + 1 left = mid + 1 else: right = mid - 1 return count def countGreater(arr, n, k): l = 0 r = n - 1 leftGreater = n while l <= r: m = int(l + (r - l) / 2) if arr[m] >= k: leftGreater = m r = m - 1 else: l = m + 1 return n - leftGreater for i in range(int(input())): r, g, b = map(int, input().split()) l = list(map(int, input().split())) l1 = list(map(int, input().split())) l2 = list(map(int, input().split())) fans = 99999999999999999999999999999999999999999999999999999 l1.sort() l.sort() l2.sort() for i in range(r): f = countGreater(l1, g, l[i]) f1 = binarySearchCount(l2, b, l[i]) if f != 0 and f1 != 0: fans = min(fans, calc(l[i], l2[f1 - 1], l1[g - f])) for i in range(r): f = countGreater(l2, b, l[i]) f1 = binarySearchCount(l1, g, l[i]) if f != 0 and f1 != 0: fans = min(fans, calc(l[i], l1[f1 - 1], l2[b - f])) for i in range(g): f = countGreater(l, r, l1[i]) f1 = binarySearchCount(l2, b, l1[i]) if f != 0 and f1 != 0: fans = min(fans, calc(l1[i], l2[f1 - 1], l[r - f])) for i in range(g): f = countGreater(l2, b, l1[i]) f1 = binarySearchCount(l, r, l1[i]) if f != 0 and f1 != 0: fans = min(fans, calc(l1[i], l[f1 - 1], l2[b - f])) for i in range(b): f = countGreater(l, r, l2[i]) f1 = binarySearchCount(l1, g, l2[i]) if f != 0 and f1 != 0: fans = min(fans, calc(l2[i], l1[f1 - 1], l[r - f])) for i in range(b): f = countGreater(l1, g, l2[i]) f1 = binarySearchCount(l, r, l2[i]) if f != 0 and f1 != 0: fans = min(fans, calc(l2[i], l[f1 - 1], l1[g - f])) print(fans)
FUNC_DEF RETURN 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 FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
infinity = 10**30 def w(x, y, z): return (x - y) ** 2 + (y - z) ** 2 + (z - x) ** 2 t = int(input()) for _ in range(t): nr, ng, nb = map(int, input().split()) r = list(sorted(map(int, input().split()))) g = list(sorted(map(int, input().split()))) b = list(sorted(map(int, input().split()))) best = infinity i, j, k = 0, 0, 0 for i in range(nr): while j < ng - 1 and g[j] < r[i]: j += 1 while k < nb - 1 and b[k + 1] <= r[i]: k += 1 best = min(best, w(r[i], g[j], b[k])) i, j, k = 0, 0, 0 for i in range(nr): while j < ng - 1 and g[j + 1] <= r[i]: j += 1 while k < nb - 1 and b[k] < r[i]: k += 1 best = min(best, w(r[i], g[j], b[k])) i, j, k = 0, 0, 0 for j in range(ng): while i < nr - 1 and r[i] < g[j]: i += 1 while k < nb - 1 and b[k + 1] <= g[j]: k += 1 best = min(best, w(r[i], g[j], b[k])) i, j, k = 0, 0, 0 for j in range(ng): while i < nr - 1 and r[i + 1] <= g[j]: i += 1 while k < nb - 1 and b[k] < g[j]: k += 1 best = min(best, w(r[i], g[j], b[k])) i, j, k = 0, 0, 0 for k in range(nb): while i < nr - 1 and r[i] < b[k]: i += 1 while j < ng - 1 and g[j + 1] <= b[k]: j += 1 best = min(best, w(r[i], g[j], b[k])) i, j, k = 0, 0, 0 for k in range(nb): while i < nr - 1 and r[i + 1] <= b[k]: i += 1 while j < ng - 1 and g[j] < b[k]: j += 1 best = min(best, w(r[i], g[j], b[k])) print(best)
ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF RETURN 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 FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
t = int(input()) for u in range(t): a, b, c = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) for i in range(len(a)): a[i] = [a[i], 0] for i in range(len(b)): b[i] = [b[i], 1] for i in range(len(c)): c[i] = [c[i], 2] a.extend(b) a.extend(c) a.sort(key=lambda x: x[0]) maxi = float("inf") start = 0 end = 0 dic = {(0): -1, (1): -1, (2): -1} while end < len(a): dic[a[end][1]] = end if dic[0] != -1 and dic[1] != -1 and dic[2] != -1: if dic[0] == start: dic[0] = -1 if dic[1] == start: dic[1] = -1 if dic[2] == start: dic[2] = -1 start += 1 if dic[0] == -1 or dic[1] == -1 or dic[2] == -1: for i in range(start, end): temp = ( (a[start - 1][0] - a[i][0]) ** 2 + (a[start - 1][0] - a[end][0]) ** 2 + (a[end][0] - a[i][0]) ** 2 ) if temp < maxi: maxi = temp else: end += 1 print(maxi)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER IF VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER IF VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
def ceilindex(arr, k): r = len(arr) - 1 l = 0 if arr[l] >= k: return arr[l] while r - l > 1: mid = l + (r - l) // 2 if arr[mid] == k: return arr[mid] elif arr[mid] > k: r = mid else: l = mid if arr[r] >= k: return arr[r] else: return None def lowerindex(arr, k): r = len(arr) - 1 l = 0 if arr[r] <= k: return arr[r] while r - l > 1: mid = l + (r - l) // 2 if arr[mid] == k: return arr[mid] elif arr[mid] > k: r = mid else: l = mid if arr[l] <= k: return arr[l] else: return None def solve(a1, a2, a3): mn = float("inf") for i in a2: upper = ceilindex(a1, i) lower = lowerindex(a3, i) if upper and lower: val = (upper - i) ** 2 + (lower - i) ** 2 + (upper - lower) ** 2 if val < mn: mn = val return mn for T in range(int(input())): a, b, c = list(map(int, input().split())) arr1 = list(map(int, input().split())) arr2 = list(map(int, input().split())) arr3 = list(map(int, input().split())) arr1.sort() arr2.sort() arr3.sort() s1 = solve(arr1, arr2, arr3) s2 = solve(arr1, arr3, arr2) s3 = solve(arr2, arr1, arr3) s4 = solve(arr2, arr3, arr1) s5 = solve(arr3, arr1, arr2) s6 = solve(arr3, arr2, arr1) print(min(s1, s2, s3, s4, s5, s6))
FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR RETURN VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR RETURN VAR VAR RETURN NONE FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR RETURN VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR RETURN VAR VAR RETURN NONE FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR 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 IF VAR VAR ASSIGN VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR 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 FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
def comp_ans(a, b, c): return (a - b) * (a - b) + (a - c) * (a - c) + (b - c) * (b - c) def lower_bound(S, t): if S[0] >= t: return 0 l = 0 r = len(S) while r - l > 1: mid = (l + r) // 2 if S[mid] >= t: r = mid else: l = mid return r if r < len(S) else None t = int(input()) while t > 0: t -= 1 rl, gl, bl = map(int, input().split()) r = sorted(list(map(int, input().split()))) g = sorted(list(map(int, input().split()))) b = sorted(list(map(int, input().split()))) perms = [] maps = {"r": r, "g": g, "b": b} for middle in ["r", "g", "b"]: for left in ["r", "g", "b"]: for right in ["r", "g", "b"]: if right == left or right == middle or left == middle: continue perms.append([maps[left], maps[middle], maps[right]]) ans = 3e19 for perm in perms: for fixed in perm[1]: left = lower_bound(perm[0], fixed) if left is None: left = len(perm[0]) - 1 if left == 0 and perm[0][left] > fixed: continue elif perm[0][left] > fixed: left -= 1 right = lower_bound(perm[2], fixed) if right is None: continue ans = min(ans, comp_ans(fixed, perm[0][left], perm[2][right])) print(ans)
FUNC_DEF RETURN 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 FUNC_DEF IF VAR NUMBER VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_CALL VAR VAR VAR NONE ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT STRING STRING STRING VAR VAR VAR FOR VAR LIST STRING STRING STRING FOR VAR LIST STRING STRING STRING FOR VAR LIST STRING STRING STRING IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR NONE ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
t = int(input()) for i in range(t): r, g, b = map(int, input().split()) R = list(map(int, input().split())) G = list(map(int, input().split())) B = list(map(int, input().split())) R.sort() G.sort() B.sort() INF = 10**20 h1, h2, h3 = INF, INF, INF ans = 0 first = 0 second = 0 third = 0 while first < r and second < g and third < b: if first == 0 and second == 0 and third == 0: ans = ( (R[first] - G[second]) ** 2 + (B[third] - G[second]) ** 2 + (B[third] - R[first]) ** 2 ) if third != b - 1: h3 = ( (R[first] - G[second]) ** 2 + (B[third + 1] - G[second]) ** 2 + (B[third + 1] - R[first]) ** 2 ) if second != g - 1: h2 = ( (R[first] - G[second + 1]) ** 2 + (B[third] - G[second + 1]) ** 2 + (B[third] - R[first]) ** 2 ) if first != r - 1: h1 = ( (R[first + 1] - G[second]) ** 2 + (B[third] - G[second]) ** 2 + (B[third] - R[first + 1]) ** 2 ) h = min(h1, h2, h3) if h == h1: ans = min(ans, h1) first += 1 elif h == h2: ans = min(ans, h2) second += 1 elif h == h3: ans = min(ans, h3) third += 1 h1, h2, h3 = INF, INF, INF print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
from sys import stdin def closestindex(arr, num, start): a = start b = len(arr) - 1 while a < b: mid = (a + b) // 2 if num < arr[mid]: if abs(arr[mid] - num) < abs(arr[mid - 1] - num): return mid else: b = mid - 1 elif abs(arr[mid] - num) < abs(arr[mid + 1] - num): return mid else: a = mid + 1 return a output = "" tc = int(stdin.readline()) for l in range(tc): l1, l2, l3 = map(int, stdin.readline().strip().split()) c = [int(x) for x in stdin.readline().split()] b = [int(x) for x in stdin.readline().split()] a = [int(x) for x in stdin.readline().split()] a.sort() b.sort() c.sort() fun = closestindex k = 0 g = 0 ans = 10**18 * 3 for i in range(len(c)): k = fun(a, c[i], k) t1 = (a[k] - c[i]) * (a[k] - c[i]) g = fun(b, c[i], g) t2 = (b[g] - c[i]) * (b[g] - c[i]) t3 = (a[k] - b[g]) * (a[k] - b[g]) ans = min(t1 + t2 + t3, ans) k = g = 0 for i in range(len(b)): k = fun(a, b[i], k) t1 = (a[k] - b[i]) * (a[k] - b[i]) g = fun(c, b[i], g) t2 = (c[g] - b[i]) * (c[g] - b[i]) t3 = (a[k] - c[g]) * (a[k] - c[g]) ans = min(t1 + t2 + t3, ans) k = g = 0 for i in range(len(a)): k = fun(b, a[i], k) t1 = (b[k] - a[i]) * (b[k] - a[i]) g = fun(c, a[i], g) t2 = (c[g] - a[i]) * (c[g] - a[i]) t3 = (b[k] - c[g]) * (b[k] - c[g]) ans = min(t1 + t2 + t3, ans) output += "{} \n".format(ans) print(output)
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR RETURN VAR ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR RETURN VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
import sys def binary1(l, r, x, a): if l == r: return a[l] idx = (l + r) // 2 + 1 if a[idx] <= x: return binary1(idx, r, x, a) else: return binary1(l, idx - 1, x, a) def binary2(l, r, x, a): if l == r: return a[l] idx = (l + r) // 2 if a[idx] >= x: return binary2(l, idx, x, a) else: return binary2(idx + 1, r, x, a) for _ in range(int(sys.stdin.readline())): nr, ng, nb = map(int, sys.stdin.readline().split()) red = list(map(int, sys.stdin.readline().split())) green = list(map(int, sys.stdin.readline().split())) blue = list(map(int, sys.stdin.readline().split())) red.sort() green.sort() blue.sort() m = 3 * 10**18 for x in red: if green[0] <= x <= blue[-1]: y = binary1(0, ng - 1, x, green) z = binary2(0, nb - 1, x, blue) m = min(m, (x - y) ** 2 + (y - z) ** 2 + (z - x) ** 2) if green[-1] >= x >= blue[0]: y = binary2(0, ng - 1, x, green) z = binary1(0, nb - 1, x, blue) m = min(m, (x - y) ** 2 + (y - z) ** 2 + (z - x) ** 2) for x in green: if red[0] <= x <= blue[-1]: y = binary1(0, nr - 1, x, red) z = binary2(0, nb - 1, x, blue) m = min(m, (x - y) ** 2 + (y - z) ** 2 + (z - x) ** 2) if red[-1] >= x >= blue[0]: y = binary2(0, nr - 1, x, red) z = binary1(0, nb - 1, x, blue) m = min(m, (x - y) ** 2 + (y - z) ** 2 + (z - x) ** 2) for x in blue: if green[0] <= x <= red[-1]: y = binary1(0, ng - 1, x, green) z = binary2(0, nr - 1, x, red) m = min(m, (x - y) ** 2 + (y - z) ** 2 + (z - x) ** 2) if green[-1] >= x >= red[0]: y = binary2(0, ng - 1, x, green) z = binary1(0, nr - 1, x, red) m = min(m, (x - y) ** 2 + (y - z) ** 2 + (z - x) ** 2) print(m)
IMPORT FUNC_DEF IF VAR VAR RETURN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF IF VAR VAR RETURN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR 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 IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR 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 FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR 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 IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR 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 FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR 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 IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR 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 EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
def sol(a, b, c): return (a - b) ** 2 + (a - c) ** 2 + (c - b) ** 2 def clo(a, b, c): x = abs(a - c) y = abs(b - c) if x > y: return b return a def bs(ar, c): if c <= ar[0]: return ar[0] elif ar[-1] <= c: return ar[-1] start = 0 end = len(ar) - 1 while start < end: mid = (start + end) // 2 if ar[mid] == c: return ar[mid] elif ar[mid] > c: if mid > 0 and ar[mid - 1] < c: return clo(ar[mid], ar[mid - 1], c) end = mid else: if mid < len(ar) - 1 and ar[mid + 1] > c: return clo(ar[mid], ar[mid + 1], c) start = mid + 1 for _ in range(int(input())): r, g, b = map(int, input().split()) rl = list(map(int, input().split())) gl = list(map(int, input().split())) bl = list(map(int, input().split())) rl.sort() gl.sort() bl.sort() ans = 99999999999999999999999999999 for i in rl: q = bs(gl, i) w = bs(bl, i) ans = min(ans, sol(i, q, w)) for i in bl: ans = min(ans, sol(i, bs(gl, i), bs(rl, i))) for i in gl: q = bs(rl, i) w = bs(bl, i) ans = min(ans, sol(i, q, w)) print(ans)
FUNC_DEF RETURN 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 FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR RETURN VAR RETURN VAR FUNC_DEF IF VAR VAR NUMBER RETURN VAR NUMBER IF VAR NUMBER VAR RETURN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN VAR VAR IF VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
def solve(l1, l2, l3): ai = 0 ci = 0 r = 10**100 + 1 for i in range(0, len(l2)): while ai < len(l1) and l1[ai] <= l2[i]: ai += 1 while ci < len(l3) and l3[ci] < l2[i]: ci += 1 if ci == len(l3): ci -= 1 if ai == 0: ai += 1 r = min( r, (l1[ai - 1] - l2[i]) ** 2 + (l2[i] - l3[ci]) ** 2 + (l1[ai - 1] - l3[ci]) ** 2, ) return r t = int(input()) for i in range(t): ans = 10**100 + 1 r, g, b = input().split() r = int(r) b = int(b) g = int(g) l1 = list(map(int, input().split())) l1.sort() l2 = list(map(int, input().split())) l2.sort() l3 = list(map(int, input().split())) l3.sort() ans = min(ans, solve(l1, l2, l3)) ans = min(ans, solve(l1, l3, l2)) ans = min(ans, solve(l2, l1, l3)) ans = min(ans, solve(l2, l3, l1)) ans = min(ans, solve(l3, l1, l2)) ans = min(ans, solve(l3, l2, l1)) print(ans)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
def cases(arr1, arr2, arr3): n1 = len(arr1) n2 = len(arr2) n3 = len(arr3) currmin = 0 currmax = 0 ans = 9223372036854775807 for element in arr2: while currmin + 1 < n1 and arr1[currmin + 1] <= element: currmin += 1 while currmax + 1 < n3 and arr3[currmax] < element: currmax += 1 if arr1[currmin] > element or element > arr3[currmax]: continue ans = min( ans, (element - arr1[currmin]) ** 2 + (element - arr3[currmax]) ** 2 + (arr3[currmax] - arr1[currmin]) ** 2, ) return ans def help(): n1, n2, n3 = map(int, input().split(" ")) arr1 = list(map(int, input().split(" "))) arr2 = list(map(int, input().split(" "))) arr3 = list(map(int, input().split(" "))) arr1.sort() arr2.sort() arr3.sort() t1 = cases(arr1, arr2, arr3) t2 = cases(arr3, arr2, arr1) t3 = cases(arr2, arr1, arr3) t4 = cases(arr3, arr1, arr2) t5 = cases(arr1, arr3, arr2) t6 = cases(arr2, arr3, arr1) print(min(t1, t2, t3, t4, t5, t6)) for _ in range(int(input())): help()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR WHILE BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER WHILE BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR 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 FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
def calc(a, bb, cc): return (a - bb) ** 2 + (bb - cc) ** 2 + (cc - a) ** 2 def findMin(x, y, z, nx, ny, nz): possibilities = [] for i in range(nx): a = x[i] b = ny j = -1 while b > 0: while j + b < ny and y[j + b] <= a: j += b b //= 2 b = nz k = -1 while b > 0: while k + b < nz and z[k + b] <= a: k += b b //= 2 if 0 <= j: if 0 <= k: possibilities.append(calc(a, y[j], z[k])) if k + 1 < nz: possibilities.append(calc(a, y[j], z[k + 1])) if j + 1 < ny: if 0 <= k: possibilities.append(calc(a, y[j + 1], z[k])) if k + 1 < nz: possibilities.append(calc(a, y[j + 1], z[k + 1])) return min(possibilities) t = int(input()) for _ in range(t): nr, ng, nb = [int(x) for x in input().split()] r = [int(x) for x in input().split()] g = [int(x) for x in input().split()] b = [int(x) for x in input().split()] r.sort() g.sort() b.sort() ans = min( findMin(r, g, b, nr, ng, nb), findMin(g, r, b, ng, nr, nb), findMin(b, r, g, nb, nr, ng), ) print(ans)
FUNC_DEF RETURN 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 FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF NUMBER VAR IF NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR IF NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
def find(M, x): a = 0 b = len(M) - 1 while b - a > 1: c = (b + a) // 2 if M[c] > x: b = c else: a = c return b if M[b] <= x else a def check(a, b, M): i = find(M, (a + b) / 2) x = (b - a) ** 2 + (b - M[i]) ** 2 + (a - M[i]) ** 2 if i + 1 < len(M): x = min(x, (b - a) ** 2 + (b - M[i + 1]) ** 2 + (a - M[i + 1]) ** 2) return x t = int(input()) for i in range(t): nr, ng, nb = map(int, input().split(" ")) R = sorted(list(map(int, input().split(" ")))) G = sorted(list(map(int, input().split(" ")))) B = sorted(list(map(int, input().split(" ")))) x = 1e20 for r in R: ig = find(G, r) ib = find(B, r) x = min(x, check(r, G[ig], B)) if ig + 1 < len(G): x = min(x, check(G[ig + 1], r, B)) x = min(x, check(r, B[ib], G)) if ib + 1 < len(B): x = min(x, check(B[ib + 1], r, G)) print(x)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
def get(a, b, c): i, j, k = 0, 0, 0 ans = 99999999999999999999 while i < len(a) and j < len(b) and k < len(c): flag = False while j < len(b) and b[j] <= a[i]: flag = True flag2 = False while k < len(c) and c[k] <= b[j]: flag2 = True k += 1 if flag2: k -= 1 ans = min(ans, (a[i] - b[j]) ** 2 + (b[j] - c[k]) ** 2 + (c[k] - a[i]) ** 2) j += 1 if flag: j -= 1 ans = min(ans, (a[i] - b[j]) ** 2 + (b[j] - c[k]) ** 2 + (c[k] - a[i]) ** 2) i += 1 return ans t = int(input()) for _ in range(t): na, nb, nc = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() ans = 99999999999999999999 ans = min(ans, get(a, b, c)) ans = min(ans, get(a, c, b)) ans = min(ans, get(b, a, c)) ans = min(ans, get(b, c, a)) ans = min(ans, get(c, a, b)) ans = min(ans, get(c, b, a)) print(ans)
FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
def cal(x, y, z): return (x - y) * (x - y) + (y - z) * (y - z) + (z - x) * (z - x) def lb(val, arr): if val >= arr[len(arr) - 1]: return arr[len(arr) - 1] if val <= arr[0]: return arr[0] l = 0 r = len(arr) while r - l > 1: mid = (r + l) // 2 if arr[mid] == val: return arr[mid] if arr[mid] < val: l = mid if arr[mid] > val: r = mid l2 = l + 1 if abs(arr[l2] - val) < abs(arr[l] - val): return arr[l2] return arr[l] def solve(): t = int(input()) while t > 0: mn = 3 * 10**18 nr, ng, nb = map(int, input().split()) rs = sorted(list(map(int, input().split()))) gs = sorted(list(map(int, input().split()))) bs = sorted(list(map(int, input().split()))) for r in rs: g = lb(r, gs) b = lb(r, bs) mn = min(mn, cal(r, g, b)) for g in gs: r = lb(g, rs) b = lb(g, bs) mn = min(mn, cal(r, g, b)) for b in bs: r = lb(b, rs) g = lb(b, gs) mn = min(mn, cal(r, g, b)) print(mn) t -= 1 solve()
FUNC_DEF RETURN 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 FUNC_DEF IF VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER RETURN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
import sys lines = sys.stdin.readlines() T = int(lines[0].strip()) for t in range(T): a, b, c = map(int, lines[4 * t + 1].strip().split(" ")) As = list(map(int, lines[4 * t + 2].strip().split(" "))) Bs = list(map(int, lines[4 * t + 3].strip().split(" "))) Cs = list(map(int, lines[4 * t + 4].strip().split(" "))) As.sort() Bs.sort() Cs.sort() def solve(arr1, arr2, arr3): L1, L2, L3 = len(arr1), len(arr2), len(arr3) pt1 = 0 pt2 = 0 minDiff = 3 * 10**18 for i in range(L3): if pt1 >= L1 or pt2 >= L2: break num = arr3[i] while pt2 < L2 and arr2[pt2] < num: pt2 += 1 if pt2 >= L2: break if arr1[pt1] > num: continue while pt1 + 1 < L1 and arr1[pt1 + 1] <= num: pt1 += 1 minDiff = min( minDiff, (num - arr1[pt1]) ** 2 + (num - arr2[pt2]) ** 2 + (arr1[pt1] - arr2[pt2]) ** 2, ) return minDiff minDiff = min( solve(As, Bs, Cs), solve(As, Cs, Bs), solve(Bs, Cs, As), solve(Bs, As, Cs), solve(Cs, As, Bs), solve(Cs, Bs, As), ) print(minDiff)
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR IF VAR VAR VAR WHILE BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
import sys from itertools import product def I(): return sys.stdin.readline().rstrip() def sqr(a): return a * a def calc(a, b, c): return sqr(a - b) + sqr(b - c) + sqr(c - a) def closests(l, x): d = 1 while d <= len(l): d *= 2 i = -1 while d > 0: j = i + d if j < len(l) and l[j] < x: i = j d //= 2 res = [] if i >= 0: res.append(l[i]) i += 1 if i < len(l): res.append(l[i]) i += 1 if i < len(l): res.append(l[i]) return res for tc in range(1, 1 + int(I())): n = list(map(int, I().split())) l = [sorted(list(map(int, I().split()))) for _ in range(3)] la = l[0] + l[1] + l[2] la.sort() ans = 10**20 for x in la: y = [closests(l[i], x) for i in range(3)] ans = min(ans, min(calc(*z) for z in product(*y))) print(ans)
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
t = int(input()) def f(arr, n): i = 0 j = len(arr) - 1 if len(arr) == 1: return arr[0] while i < j: mid = (i + j) // 2 if i == mid and j == mid + 1: if abs(arr[i] - n) <= abs(arr[j] - n): return arr[i] else: return arr[j] elif arr[mid] > n: j = mid else: i = mid for x in range(t): r, g, b = list(map(int, input().split())) rl = sorted(list(map(int, input().split()))) rg = sorted(list(map(int, input().split()))) rb = sorted(list(map(int, input().split()))) result = 10**36 for aq in range(r): x = f(rg, rl[aq]) y = f(rb, rl[aq]) z = rl[aq] ns = (x - y) ** 2 + (y - z) ** 2 + (x - z) ** 2 result = min(result, ns) for aq in range(g): x = f(rl, rg[aq]) y = f(rb, rg[aq]) z = rg[aq] ns = (x - y) ** 2 + (y - z) ** 2 + (x - z) ** 2 result = min(result, ns) for aq in range(b): x = f(rl, rb[aq]) y = f(rg, rb[aq]) z = rb[aq] ns = (x - y) ** 2 + (y - z) ** 2 + (x - z) ** 2 result = min(result, ns) print(result)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN VAR VAR RETURN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR 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 FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR 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 FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR 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 FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
def readInts(): return list(map(int, input().split())) def f(a, b, c): return (a - b) ** 2 + (a - c) ** 2 + (b - c) ** 2 def bs(arr, x, y): l, r = -1, len(arr) while r - l > 1: m = (l + r) // 2 if 2 * arr[m] <= x + y: l = m else: r = m return None if l == -1 else arr[l], None if r == len(arr) else arr[r] def findAns(a, b, c): ans = float("inf") pa, pb = 0, 0 while True: bestA, bestB = bs(c, a[pa], b[pb]) if bestA is not None: if min(a[pa], b[pb]) <= bestA <= max(a[pa], b[pb]): ans = min(ans, f(a[pa], b[pb], bestA)) if bestB is not None: if min(a[pa], b[pb]) <= bestB <= max(a[pa], b[pb]): ans = min(ans, f(a[pa], b[pb], bestB)) mn = min(a[pa], b[pb]) if a[pa] == mn and pa != len(a) - 1: pa += 1 elif b[pb] == mn and pb != len(b) - 1: pb += 1 else: break return ans def solve(r, g, b): r.sort() g.sort() b.sort() ans = min(findAns(r, g, b), findAns(r, b, g), findAns(g, b, r)) print(ans) def main(): t = int(input()) for x in range(t): nr, ng, nb = readInts() solve(readInts(), readInts(), readInts()) main()
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN 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 FUNC_DEF ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP NUMBER VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR NUMBER NONE VAR VAR VAR FUNC_CALL VAR VAR NONE VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER NUMBER WHILE NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR NONE IF FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR NONE IF FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
def main(): n1, n2, n3 = map(int, input().split()) a = sorted(list(map(int, input().split()))) b = sorted(list(map(int, input().split()))) c = sorted(list(map(int, input().split()))) fst = 0 scnd = 0 thrd = 0 dif = (a[fst] - b[scnd]) ** 2 + (a[fst] - c[thrd]) ** 2 + (b[scnd] - c[thrd]) ** 2 difa = dif difb = dif difc = dif while fst != n1 - 1 or scnd != n2 - 1 or thrd != n3 - 1: dfa = False dfb = False dfc = False if fst != n1 - 1: difa = ( (a[fst + 1] - b[scnd]) ** 2 + (a[fst + 1] - c[thrd]) ** 2 + (b[scnd] - c[thrd]) ** 2 ) dfa = True if scnd != n2 - 1: difb = ( (a[fst] - b[scnd + 1]) ** 2 + (a[fst] - c[thrd]) ** 2 + (b[scnd + 1] - c[thrd]) ** 2 ) dfb = True if thrd != n3 - 1: dfc = True difc = ( (a[fst] - b[scnd]) ** 2 + (a[fst] - c[thrd + 1]) ** 2 + (b[scnd] - c[thrd + 1]) ** 2 ) if not dfa: if not dfb: thrd += 1 elif not dfc: scnd += 1 elif difb > difc: thrd += 1 else: scnd += 1 elif not dfb: if not dfc: fst += 1 elif difa > difc: thrd += 1 else: fst += 1 elif not dfc: if difa > difb: scnd += 1 else: fst += 1 elif difa < difc: if difa < difb: fst += 1 else: scnd += 1 elif difc < difb: thrd += 1 else: scnd += 1 dif = min(dif, difa, difb, difc) print(dif) t = int(input()) for i in range(t): main()
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 FUNC_CALL VAR VAR FUNC_CALL 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR IF VAR VAR NUMBER IF VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR IF VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
def sq(a): return a * a def give(x, y, z): return sq(x - y) + sq(y - z) + sq(z - x) def search(a, e): l = 0 r = len(a) - 1 x = (l + r) // 2 while r - l > 1: if a[x] <= e: l = x else: r = x x = (l + r) // 2 try: return [a[x], a[x + 1]] except: return [a[x]] for _ in range(int(input())): r, g, b = map(int, input().split()) rd = list(map(int, input().split())) gr = list(map(int, input().split())) bl = list(map(int, input().split())) rd.sort() gr.sort() bl.sort() ans = give(rd[0], gr[-1], bl[0]) for x in rd: a1 = search(gr, x) a2 = search(bl, x) for y in a1: for z in a2: ans = min(ans, give(x, y, z)) for x in gr: a1 = search(rd, x) a2 = search(bl, x) for y in a1: for z in a2: ans = min(ans, give(x, y, z)) for x in bl: a1 = search(gr, x) a2 = search(rd, x) for y in a1: for z in a2: ans = min(ans, give(x, y, z)) print(ans)
FUNC_DEF RETURN BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN LIST VAR VAR VAR BIN_OP VAR NUMBER RETURN LIST VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
def calc(n, la, lb): n1 = minmore(la, n) n2 = maxless(lb, n) return (n - n1) ** 2 + (n - n2) ** 2 + (n1 - n2) ** 2 def minmore(la, n): pl = 0 pr = len(la) - 1 while pl < pr: mid = (pl + pr) // 2 if la[mid] == n: return n if la[mid] < n: pl = mid + 1 else: pr = mid return la[pl] def maxless(la, n): pl = 0 pr = len(la) - 1 while pl < pr: mid = (pl + pr + 1) // 2 if la[mid] == n: return n if la[mid] < n: pl = mid else: pr = mid - 1 return la[pl] t = int(input()) for i in range(t): nr, ng, nb = map(int, input().split()) rr = list(sorted(map(int, input().split()))) rg = list(sorted(map(int, input().split()))) rb = list(sorted(map(int, input().split()))) x = 10**80 for r in rr: x = min(x, calc(r, rg, rb)) for g in rg: x = min(x, calc(g, rr, rb)) for b in rb: x = min(x, calc(b, rr, rg)) for r in rr: x = min(x, calc(r, rb, rg)) for g in rg: x = min(x, calc(g, rb, rr)) for b in rb: x = min(x, calc(b, rg, rr)) print(x)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN 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 FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR RETURN VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
from itertools import permutations def main(): for t in range(int(input())): r_a, r_b, r_c = [int(j) for j in input().split()] a = [int(j) for j in input().split()] b = [int(j) for j in input().split()] c = [int(j) for j in input().split()] a.sort() b.sort() c.sort() l = permutations((a, b, c)) def eval(a, b, c): return (a - b) ** 2 + (a - c) ** 2 + (c - b) ** 2 ans = eval(a[0], b[0], c[0]) for first, second, third in l: i = 0 k = 0 for j in range(len(second)): while i < len(first) - 1 and first[i + 1] <= second[j]: i += 1 while k < len(third) - 1 and third[k] < second[j]: k += 1 tmp = eval(first[i], second[j], third[k]) ans = min(ans, tmp) print(ans) main()
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF RETURN 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 FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
def find(M, x): a = 0 b = len(M) - 1 while b - a > 1: if M[(a + b) // 2] > x: b = (a + b) // 2 else: a = (a + b) // 2 return b if M[b] <= x else a def check(a, b, M): x = (a + b) / 2 im = find(M, x) x = (a - b) ** 2 + (a - M[im]) ** 2 + (M[im] - b) ** 2 return ( x if im == len(M) - 1 else min(x, (a - b) ** 2 + (a - M[im + 1]) ** 2 + (M[im + 1] - b) ** 2) ) for t in range(int(input())): nr, ng, nb = map(int, input().split()) red = sorted(list(map(int, input().split()))) gre = sorted(list(map(int, input().split()))) blu = sorted(list(map(int, input().split()))) ans = 10**22 for i in range(nr): g = find(gre, red[i]) b = find(blu, red[i]) diffg = check(red[i], gre[g], blu) diffb = check(red[i], blu[b], gre) if g + 1 != len(gre): diffg = min(diffg, check(red[i], gre[g + 1], blu)) if b + 1 != len(blu): diffb = min(diffb, check(red[i], blu[b + 1], gre)) ans = min(ans, diffb, diffg) print(ans)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER RETURN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL 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 VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
import sys BIG_NUMBER = 100000000000000000000000000000000000000000000 def func(i, j, k): return (i - j) ** 2 + (k - j) ** 2 + (k - i) ** 2 def solve(a, b, c): imax, jmax, kmax = len(a), len(b), len(c) i, j, k = 0, 0, 0 a.append(BIG_NUMBER) b.append(BIG_NUMBER) c.append(BIG_NUMBER) local_min = BIG_NUMBER while i < imax and j < jmax and k < kmax: val = func(a[i], b[j], c[k]) if val < local_min: local_min = val a1 = func(a[i + 1], b[j], c[k]) b1 = func(a[i], b[j + 1], c[k]) c1 = func(a[i], b[j], c[k + 1]) if a1 <= b1 and a1 <= c1 and i < imax: i += 1 elif b1 <= a1 and b1 <= c1 and j < jmax: j += 1 elif k < kmax: k += 1 return local_min t = int(sys.stdin.readline()) for t_i in range(t): a_n, b_n, c_n = map(int, sys.stdin.readline().split()) a = sorted(list(map(int, sys.stdin.readline().split()))) b = sorted(list(map(int, sys.stdin.readline().split()))) c = sorted(list(map(int, sys.stdin.readline().split()))) print(solve(a, b, c))
IMPORT ASSIGN VAR NUMBER FUNC_DEF RETURN 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 FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 FUNC_CALL VAR VAR FUNC_CALL 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 VAR VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
from itertools import permutations def min_val(rs, gs, bs): perm = permutations([0, 1, 2]) rs, gs, bs = list(sorted(rs)), list(sorted(gs)), list(sorted(bs)) nexts = [rs, gs, bs] best_so_far = (rs[0] - gs[0]) ** 2 + (rs[0] - bs[0]) ** 2 + (bs[0] - gs[0]) ** 2 for p in perm: c0, c1, c2 = 0, 0, 0 while True: if c0 < len(nexts[p[0]]) - 1 and nexts[p[0]][c0 + 1] <= nexts[p[1]][c1]: c0 += 1 elif c1 < len(nexts[p[1]]) - 1 and nexts[p[1]][c1 + 1] <= nexts[p[2]][c2]: c1 += 1 elif c2 < len(nexts[p[2]]) - 1: c2 += 1 else: break at = ( (nexts[p[0]][c0] - nexts[p[1]][c1]) ** 2 + (nexts[p[0]][c0] - nexts[p[2]][c2]) ** 2 + (nexts[p[2]][c2] - nexts[p[1]][c1]) ** 2 ) if at < best_so_far: best_so_far = at print(best_so_far) t = int(input()) for i in range(t): nr, ng, nb = map(int, input().split()) rs = map(int, input().split()) gs = map(int, input().split()) bs = map(int, input().split()) min_val(rs, gs, bs)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
t = int(input()) def fun(x, y, z): return (x - y) ** 2 + (y - z) ** 2 + (z - x) ** 2 def partialbest(red, green, blue): ind_green_maggiore = 0 ind_blue_maggiore_l = 0 ind_blue_maggiore_r = 0 min_value = fun(red[0], green[0], blue[0]) for j in range(len(red)): k = ind_green_maggiore while k < len(green): if green[k] >= red[j]: break k = k + 1 if k < len(green): l = ind_blue_maggiore_l while l < len(blue): if blue[l] >= int((green[k] + red[j]) / 2): break l = l + 1 if l < len(blue): min_value = min(min_value, fun(red[j], green[k], blue[l])) ind_blue_maggiore_l = l if l >= 1: min_value = min(min_value, fun(red[j], green[k], blue[l - 1])) ind_blue_maggiore_l = l - 1 ind_green_maggiore = k if k >= 1: l = ind_blue_maggiore_r while l < len(blue): if blue[l] >= int((green[k - 1] + red[j]) / 2): break l = l + 1 if l < len(blue): min_value = min(min_value, fun(red[j], green[k - 1], blue[l])) ind_blue_maggiore_r = l if l >= 1: min_value = min(min_value, fun(red[j], green[k - 1], blue[l - 1])) ind_blue_maggiore_r = l - 1 ind_green_maggiore = k - 1 if green[-1] <= red[j]: if blue[-1] <= int((green[-1] + red[j]) / 2): min_value = min(min_value, fun(red[j], green[-1], blue[-1])) l = ind_blue_maggiore_l while l < len(blue): if blue[l] >= int((green[-1] + red[j]) / 2): break l = l + 1 if l < len(blue): min_value = min(min_value, fun(red[j], green[-1], blue[l])) ind_blue_maggiore_l = l if l >= 1: min_value = min(min_value, fun(red[j], green[-1], blue[l - 1])) ind_blue_maggiore_l = l - 1 return min_value for i in range(t): values = [int(j) for j in input().split()] red = [int(j) for j in input().split()] green = [int(j) for j in input().split()] blue = [int(j) for j in input().split()] red = list(set(red)) green = list(set(green)) blue = list(set(blue)) red.sort() green.sort() blue.sort() print(min(partialbest(red, green, blue), partialbest(red, blue, green)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN 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 FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR IF VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
from sys import stdin input = stdin.readline q = int(input()) def cyk(l1, l2, l3, len1, len2, len3): wynik = 65872346587623475642374982383247 i1 = 0 i3 = 0 for i2 in range(len2): while True: dupa = 0 if i1 < len1 - 1 and l1[i1 + 1] <= l2[i2]: i1 += 1 dupa += 1 if i3 > 0 and l3[i3 - 1] >= l2[i2]: i3 -= 1 dupa += 1 if i3 < len3 - 1 and l3[i3] < l2[i2]: i3 += 1 dupa += 1 if dupa == 0: break if l1[i1] <= l2[i2] and l2[i2] <= l3[i3]: wynik = min( wynik, (l1[i1] - l2[i2]) ** 2 + (l2[i2] - l3[i3]) ** 2 + (l1[i1] - l3[i3]) ** 2, ) return wynik for _ in range(q): r, g, b = map(int, input().split()) lr = list(map(int, input().split())) lg = list(map(int, input().split())) lb = list(map(int, input().split())) lr.sort() lg.sort() lb.sort() lr.append(2349349237489237498233) lg.append(32964892374982374892384234234234234329) lb.append(23964892364892346264873242423423423423423423423423423787878878) ler = len(lr) leg = len(lg) leb = len(lb) c1 = cyk(lr, lg, lb, ler, leg, leb) c2 = cyk(lg, lr, lb, leg, ler, leb) c3 = cyk(lr, lb, lg, ler, leb, leg) c4 = cyk(lg, lb, lr, leg, leb, ler) c5 = cyk(lb, lr, lg, leb, ler, leg) c6 = cyk(lb, lg, lr, leb, leg, ler) print(min(c1, c2, c3, c4, c5, c6))
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL 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 FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
import sys readline = sys.stdin.readline minf, inf = -(10**12), 10**12 biginf = 10**20 for _ in range(int(readline())): r, g, b = map(int, readline().split()) r_a = [minf] + sorted(set(map(int, readline().split()))) + [inf, inf] g_a = [minf] + sorted(set(map(int, readline().split()))) + [inf, inf] b_a = [minf] + sorted(set(map(int, readline().split()))) + [inf, inf] ans = biginf for a1, a2, a3 in ((r_a, g_a, b_a), (g_a, b_a, r_a), (b_a, r_a, g_a)): j, k = 0, 0 for i in range(1, len(a1) - 2): ans = min( ans, (a1[i] - a2[j]) ** 2 + (a1[i] - a3[k]) ** 2 + (a2[j] - a3[k]) ** 2 ) while abs(a1[i] - a2[j]) >= abs(a1[i] - a2[j + 1]): j += 1 while max(abs(a1[i] - a3[k]), abs(a2[j] - a3[k])) >= max( abs(a1[i] - a3[k + 1]), abs(a2[j] - a3[k + 1]) ): ans = min( ans, (a1[i] - a2[j]) ** 2 + (a1[i] - a3[k]) ** 2 + (a2[j] - a3[k]) ** 2, ) k += 1 ans = min( ans, (a1[i] - a2[j]) ** 2 + (a1[i] - a3[k]) ** 2 + (a2[j] - a3[k]) ** 2, ) ans = min( ans, (a1[i] - a2[j]) ** 2 + (a1[i] - a3[k]) ** 2 + (a2[j] - a3[k]) ** 2 ) print(ans)
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST VAR VAR ASSIGN VAR VAR FOR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER WHILE FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER WHILE FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
def solve(r, g, b): j = 0 k = 0 ans = float("inf") for i in range(len(g)): while j + 1 < len(r) and r[j + 1] <= g[i]: j += 1 while k + 1 < len(b) and b[k] < g[i]: k += 1 ans = min(ans, (g[i] - r[j]) ** 2 + (g[i] - b[k]) ** 2 + (r[j] - b[k]) ** 2) return ans for _ in range(int(input())): nr, ng, nb = (int(x) for x in input().split()) r = sorted(set(int(x) for x in input().split())) g = sorted(set(int(x) for x in input().split())) b = sorted(set(int(x) for x in input().split())) ans = float("inf") ans = min(ans, solve(r, g, b)) ans = min(ans, solve(r, b, g)) ans = min(ans, solve(g, r, b)) ans = min(ans, solve(g, b, r)) ans = min(ans, solve(b, r, g)) ans = min(ans, solve(b, g, r)) print(ans)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER WHILE BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
import itertools INF = 1 << 300 - 1 def calc(a, b, c): return 2 * (a * a + b * b + c * c - a * b - b * c - c * a) def binsearch_lt(a, target): left = 0 right = len(a) - 1 while left + 1 < right: mid = (left + right) // 2 if target <= a[mid]: right = mid if target >= a[mid]: left = mid if a[right] <= target: return a[right] return a[left] def binsearch_gt(a, target): left = 0 right = len(a) - 1 while left + 1 < right: mid = (left + right + 1) // 2 if target <= a[mid]: right = mid if target >= a[mid]: left = mid if a[left] >= target: return a[left] return a[right] def calculate_case(): n = list(map(int, input().split())) weights = [sorted(list(map(int, input().split()))) for i in range(3)] best = INF for x, y, z in itertools.permutations((0, 1, 2)): for a in weights[x]: b = binsearch_gt(weights[y], a) c1, c2 = binsearch_lt(weights[z], (a + b) // 2), binsearch_gt( weights[z], (a + b) // 2 ) best = min(best, calc(a, b, c1), calc(a, b, c2)) print(best) test_cases = int(input()) for i in range(test_cases): calculate_case()
IMPORT ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER FUNC_DEF RETURN BIN_OP NUMBER 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 FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR RETURN VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR RETURN VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FOR VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER FOR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
def d(x, y, z): return (x - y) ** 2 + (y - z) ** 2 + (z - x) ** 2 def getMin(arr): h = arr[0] m = None t = None ne = 1 tele = 2 min_val = None while ne < len(arr) and tele < len(arr): if h and not m and not t: if arr[ne]["type"] == h["type"]: h = arr[ne] ne += 1 else: m = arr[ne] ne += 1 tele = ne elif h and m and not t: if arr[tele]["type"] == h["type"]: h = arr[tele - 1] m = arr[tele] ne = tele + 1 tele = ne elif arr[tele]["type"] == m["type"]: tele += 1 else: t = arr[tele] elif h and m and t: if min_val == None: min_val = d(h["val"], m["val"], t["val"]) else: min_val = min(min_val, d(h["val"], m["val"], t["val"])) if arr[ne]["type"] == m["type"]: m = arr[ne] ne += 1 else: h = m m = t t = None ne += 1 tele = ne return min_val def sortArr(r, g, b): r = list(map(lambda x: dict({"val": x, "type": 0}), r)) g = list(map(lambda x: dict({"val": x, "type": 1}), g)) b = list(map(lambda x: dict({"val": x, "type": 2}), b)) arr = r + g + b arr.sort(key=lambda x: x["val"]) return arr for _ in range(int(input())): trash = input() r = list(map(int, input().split(" "))) g = list(map(int, input().split(" "))) b = list(map(int, input().split(" "))) arr = sortArr(r, g, b) val = getMin(arr) print(val)
FUNC_DEF RETURN 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 FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR VAR STRING VAR STRING ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR IF VAR VAR STRING VAR STRING ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR VAR STRING VAR STRING VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR STRING VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR STRING VAR STRING VAR STRING IF VAR VAR STRING VAR STRING ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE VAR NUMBER ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR DICT STRING STRING VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR DICT STRING STRING VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR DICT STRING STRING VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
def calc(l1, l2, l3, ans, a, b, c): for i in range(a): in2 = bs(l1[i], l2, 0, b) in3 = bs(l1[i], l3, 1, c) ans = min( ans, (l1[i] - l2[in2]) ** 2 + (l1[i] - l3[in3]) ** 2 + (l3[in3] - l2[in2]) ** 2, ) in2 = bs(l1[i], l2, 1, b) in3 = bs(l1[i], l3, 0, c) ans = min( ans, (l1[i] - l2[in2]) ** 2 + (l1[i] - l3[in3]) ** 2 + (l3[in3] - l2[in2]) ** 2, ) return ans def bs(num, li, bound, hi): lo = 0 hi -= 1 ans = 0 while lo <= hi: mid = (lo + hi) // 2 if li[mid] == num: return mid elif li[mid] > num: if bound == 1: ans = mid hi = mid - 1 else: if bound == 0: ans = mid lo = mid + 1 return ans def main(): for q in range(int(input())): a, b, c = map(int, input().split()) l1 = list(map(int, input().split())) l2 = list(map(int, input().split())) l3 = list(map(int, input().split())) ans = 2**62 l1.sort() l2.sort() l3.sort() ans = min(ans, calc(l1, l2, l3, ans, a, b, c)) ans = min(ans, calc(l2, l1, l3, ans, b, a, c)) ans = min(ans, calc(l3, l1, l2, ans, c, a, b)) print(ans) main()
FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN VAR IF VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
def binsearch_smaller(a, v): if a[0] >= v: return a[0] if a[-1] <= v: return a[-1] mid = len(a) // 2 if a[mid] < v: if a[mid + 1] > v: return a[mid] else: return binsearch_smaller(a[mid:], v) elif a[mid] == v: return v else: if a[mid - 1] < v: return a[mid - 1] return binsearch_smaller(a[:mid], v) def binsearch_larger(a, v): while True: if a[0] >= v: return a[0] if a[-1] <= v: return a[-1] mid = len(a) // 2 if a[mid] < v: if a[mid + 1] > v: return a[mid + 1] else: a = a[mid:] continue elif a[mid] == v: return v elif a[mid - 1] < v: return a[mid] else: a = a[:mid] def f(x, y, z): return (x - y) ** 2 + (y - z) ** 2 + (x - z) ** 2 def solve(r, b, g): r.sort() g.sort() b.sort() t = f(r[0], b[0], g[0]) for s in range(6): a = [r, b, g] x = a[s % 3] a.remove(x) y = a[s // 3] a.remove(y) z = a[0] j = 0 k = 0 i = 0 while i < len(x): if ( x[i] <= y[j] and x[i] >= z[k] and (k + 1 < len(z) and x[i] < z[k + 1] or k + 1 == len(z)) ): tn = f(x[i], y[j], z[k]) if tn < t: t = tn i += 1 else: if x[i] > y[j]: j += 1 if j == len(y): break if x[i] < z[k]: i += 1 continue if k + 1 < len(z) and x[i] >= z[k + 1]: k += 1 return t tests = int(input()) for test in range(tests): nr, ng, nb = list(map(int, input().split())) r = list(map(int, input().split())) g = list(map(int, input().split())) b = list(map(int, input().split())) print(solve(r, b, g))
FUNC_DEF IF VAR NUMBER VAR RETURN VAR NUMBER IF VAR NUMBER VAR RETURN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR RETURN VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR RETURN VAR IF VAR BIN_OP VAR NUMBER VAR RETURN VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR FUNC_DEF WHILE NUMBER IF VAR NUMBER VAR RETURN VAR NUMBER IF VAR NUMBER VAR RETURN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR RETURN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR RETURN VAR IF VAR BIN_OP VAR NUMBER VAR RETURN VAR VAR ASSIGN VAR VAR VAR FUNC_DEF RETURN 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 FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL 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 VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
import sys ints = (int(x) for x in sys.stdin.read().split()) def leq_geq(A, B): geq = [-1] * len(A) leq = [-1] * len(A) j = 0 for i in range(len(A)): while j < len(B) and B[j] < A[i]: j += 1 geq[i] = j if j < len(B) else -1 j = len(B) - 1 for i in range(len(A) - 1, -1, -1): while j >= 0 and B[j] > A[i]: j -= 1 leq[i] = j return leq, geq def it_R(R, G, B): lg = [leq_geq(R, G), leq_geq(R, B)] lg = [(lg[0][0], lg[1][1]), (lg[0][1], lg[1][0])] for i in range(len(R)): for fj, fk in lg: if fj[i] != -1 and fk[i] != -1: yield R[i], G[fj[i]], B[fk[i]] return def it(R, G, B): yield from it_R(R, G, B) yield from it_R(B, R, G) yield from it_R(G, B, R) return ntc = next(ints) for tc in range(1, ntc + 1): r, g, b = (next(ints) for i in range(3)) R, G, B = (sorted(next(ints) for i in range(n)) for n in (r, g, b)) ans = min((x - y) ** 2 + (x - z) ** 2 + (y - z) ** 2 for x, y, z in it(R, G, B)) print(ans)
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER WHILE VAR NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR LIST FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER EXPR VAR VAR VAR VAR VAR VAR VAR VAR RETURN FUNC_DEF EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR 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 VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
from itertools import permutations t = int(input()) for _ in range(t): res = None map(int, input().split()) arr = [] arr.append(sorted(map(int, input().split()))) arr.append(sorted(map(int, input().split()))) arr.append(sorted(map(int, input().split()))) res = None for b, m, l in permutations([0, 1, 2]): i, j, k = 0, 0, 0 while j < len(arr[m]): while i + 1 < len(arr[b]) and arr[b][i] < arr[m][j]: i += 1 while k + 1 < len(arr[l]) and arr[l][k + 1] <= arr[m][j]: k += 1 last = [arr[b][i], arr[m][j], arr[l][k]] v = ( (last[0] - last[1]) ** 2 + (last[1] - last[2]) ** 2 + (last[0] - last[2]) ** 2 ) if res is None or res > v: res = v j += 1 print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NONE EXPR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NONE FOR VAR VAR VAR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR VAR WHILE BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER WHILE BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR LIST VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER IF VAR NONE VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
def val(gems): g1, g2, g3 = gems v = (g1 - g2) ** 2 + (g2 - g3) ** 2 + (g3 - g1) ** 2 return v def binarysearch(lwr, upr, lst, target, dxn): if upr == lwr: return lst[lwr] elif upr - lwr == 1 and dxn == 1: if lst[upr] <= target: return lst[upr] else: return lst[lwr] elif upr - lwr == 1 and dxn == -1: if lst[lwr] >= target: return lst[lwr] else: return lst[upr] else: middle = (lwr + upr) // 2 if lst[middle] > target: return binarysearch(lwr, middle, lst, target, dxn) elif lst[middle] < target: return binarysearch(middle, upr, lst, target, dxn) else: return target T = int(input()) for test in range(T): gemsno = list(map(int, input().split())) gemlists = [list(map(int, input().split())) for col in range(3)] for n in range(3): gemlists[n].sort() perms = [[0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1], [2, 1, 0]] dist = 10**20 for perm in perms: refno = perm[0] upw = perm[1] dwn = perm[2] refgems = gemlists[refno] upwgems = gemlists[upw] dwngems = gemlists[dwn] dwnl, upwl = len(dwngems), len(upwgems) for refgem in refgems: if upwgems[-1] < refgem: gu = upwgems[-1] else: gu = binarysearch(0, upwl - 1, upwgems, refgem, 1) if dwngems[0] > refgem: gd = dwngems[0] else: gd = binarysearch(0, dwnl - 1, dwngems, refgem, -1) gems = [refgem, gu, gd] v = val(gems) dist = min(dist, v) print(dist)
FUNC_DEF ASSIGN VAR VAR VAR VAR ASSIGN VAR 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 RETURN VAR FUNC_DEF IF VAR VAR RETURN VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR RETURN VAR VAR RETURN VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR RETURN VAR VAR RETURN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR LIST VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
def solve(l1, l2, l3): ans = float("inf") for i in l1: x, y = find(l2, l3, i) ans = min(ans, (i - x) ** 2 + (i - y) ** 2 + (x - y) ** 2) return ans def find(arr1, arr2, num): low, high = 0, len(arr1) - 1 while low < high: mid = (low + high) // 2 if arr1[mid] < num: low = mid + 1 else: high = mid - 1 if arr1[low] < num: if low != len(arr1) - 1: x = arr1[low + 1] else: x = float("inf") else: x = arr1[low] low, high = 0, len(arr2) - 1 while low < high: mid = (low + high) // 2 if arr2[mid] < num: low = mid + 1 else: high = mid - 1 if arr2[low] > num: if low != 0: y = arr2[low - 1] else: y = float("inf") else: y = arr2[low] return x, y for _ in range(int(input())): r, g, b = map(int, input().split()) lr = sorted(list(map(int, input().split()))) lg = sorted(list(map(int, input().split()))) lb = sorted(list(map(int, input().split()))) ans = solve(lr, lg, lb) ans = min(ans, solve(lr, lb, lg)) ans = min(ans, solve(lb, lr, lg)) ans = min(ans, solve(lb, lg, lr)) ans = min(ans, solve(lg, lr, lb)) ans = min(ans, solve(lg, lb, lr)) print(ans)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR 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 RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR RETURN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 FUNC_CALL VAR VAR FUNC_CALL 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 VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
import sys def lower(num, arr): ans = 0 low, high = 0, len(arr) - 1 while low <= high: mid = (low + high) // 2 if arr[mid] <= num: ans = mid low = mid + 1 else: high = mid - 1 return ans def upper(num, arr): ans = len(arr) - 1 low, high = 0, len(arr) - 1 while low <= high: mid = (low + high) // 2 if arr[mid] >= num: ans = mid high = mid - 1 else: low = mid + 1 return ans def solve(red, green, blue): g = len(green) ans = float("inf") for i in range(g): a = blue[upper(green[i], blue)] b = red[lower(green[i], red)] c = green[i] q = (a - b) ** 2 + (a - c) ** 2 + (b - c) ** 2 ans = min(ans, q) return ans t = int(sys.stdin.readline()) for _ in range(t): r, g, bl = map(int, sys.stdin.readline().split()) red = list(map(int, sys.stdin.readline().split())) green = list(map(int, sys.stdin.readline().split())) blue = list(map(int, sys.stdin.readline().split())) red.sort() green.sort() blue.sort() i, j = 0, 0 ans = float("inf") a = solve(red, green, blue) ans = min(ans, a) a = solve(red, blue, green) ans = min(ans, a) a = solve(blue, red, green) ans = min(ans, a) a = solve(blue, green, red) ans = min(ans, a) a = solve(green, red, blue) ans = min(ans, a) a = solve(green, blue, red) ans = min(ans, a) print(ans)
IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR 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 FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
import sys input = sys.stdin.readline def f(a, b, c): return (a - b) ** 2 + (b - c) ** 2 + (c - a) ** 2 def check(A, B, C): r = 10**22 ai = ci = 0 for i in range(len(B)): b = B[i] while ai < len(A) and A[ai] <= b: ai += 1 while ci < len(C) and C[ci] < b: ci += 1 if ci == len(C): ci -= 1 if ai == 0: ai += 1 r = min(r, f(A[ai - 1], b, C[ci])) return r t = int(input()) for _ in range(t): a, b, c = map(int, input().split()) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) r = 10**22 r = min(r, check(A, B, C)) r = min(r, check(C, B, A)) r = min(r, check(C, A, B)) r = min(r, check(B, A, C)) r = min(r, check(B, C, A)) r = min(r, check(A, C, B)) print(r)
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN 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 FUNC_DEF ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
def calc(x, y, z): if (x, y, z) in dic: return dic[x, y, z] dic[x, y, z] = (x - y) ** 2 + (y - z) ** 2 + (z - x) ** 2 return dic[x, y, z] def findge(arr, x): start = 0 end = len(arr) - 1 ans = -1 while start <= end: mid = (start + end) // 2 if arr[mid] < x: start = mid + 1 else: ans = arr[mid] end = mid - 1 return ans def findle(arr, x): start = 0 end = len(arr) - 1 ans = -1 while start <= end: mid = (start + end) // 2 if arr[mid] > x: end = mid - 1 else: ans = arr[mid] start = mid + 1 return ans def solve(anr, anb, ang): ans = float("inf") arr = [anr, anb, ang] for i in range(3): for j in range(3): for k in range(3): if i == j or j == k or i == k: continue for x in arr[i]: y = findle(arr[j], x) z = findge(arr[k], x) if y != -1 and z != -1: ans = min(ans, calc(x, y, z)) print(ans) dic = {} for _ in range(int(input())): nr, ng, nb = map(int, input().split()) anr = list(map(int, input().split())) ang = list(map(int, input().split())) anb = list(map(int, input().split())) anr.sort() ang.sort() anb.sort() solve(anr, anb, ang)
FUNC_DEF IF VAR VAR VAR VAR RETURN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR 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 RETURN VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR LIST VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR VAR VAR FOR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
for f in range(int(input())): nr, ng, nb = map(int, input().split()) r = list(map(int, input().split())) g = list(map(int, input().split())) b = list(map(int, input().split())) r.sort() g.sort() b.sort() mi = 2 * (r[0] ** 2 + g[0] ** 2 + b[0] ** 2) fr = 0 fg = 0 fb = 0 prr = r[0] prg = g[0] prb = b[0] for i in range(ng): while r[fr] < g[i] and fr < nr - 1: prr = r[fr] fr += 1 while b[fb] < g[i] and fb < nb - 1: prb = b[fb] fb += 1 cl1 = prr if r[fr] - g[i] < g[i] - prr: cl1 = r[fr] cl2 = prb if b[fb] - g[i] < g[i] - prb: cl2 = b[fb] cur = (g[i] - cl1) ** 2 + (g[i] - cl2) ** 2 + (cl1 - cl2) ** 2 mi = min(mi, cur) fr = 0 fg = 0 fb = 0 prr = r[0] prg = g[0] prb = b[0] for i in range(nb): while g[fg] < b[i] and fg < ng - 1: prg = g[fg] fg += 1 while r[fr] < b[i] and fr < nr - 1: prr = r[fr] fr += 1 cl1 = prr if r[fr] - b[i] < b[i] - prr: cl1 = r[fr] cl2 = prg if g[fg] - b[i] < b[i] - prg: cl2 = g[fg] cur = (b[i] - cl1) ** 2 + (b[i] - cl2) ** 2 + (cl1 - cl2) ** 2 mi = min(mi, cur) fr = 0 fg = 0 fb = 0 prr = r[0] prg = g[0] prb = b[0] for i in range(nr): while g[fg] < r[i] and fg < ng - 1: prg = g[fg] fg += 1 while b[fb] < r[i] and fb < nb - 1: prb = b[fb] fb += 1 cl1 = prg if g[fg] - r[i] < r[i] - prg: cl1 = g[fg] cl2 = prb if b[fb] - r[i] < r[i] - prb: cl2 = b[fb] cur = (r[i] - cl1) ** 2 + (r[i] - cl2) ** 2 + (cl1 - cl2) ** 2 mi = min(mi, cur) print(mi)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
def binary(l, r, arr, x): while l + 1 < r: mid = (l + r) // 2 if arr[mid] <= x: r = mid else: l = mid if abs(arr[l] - x) <= abs(arr[r] - x): return arr[l] else: return arr[r] T = int(input()) for _ in range(T): r, g, b = map(int, input().split()) R = list(map(int, input().split())) G = list(map(int, input().split())) B = list(map(int, input().split())) R.sort(reverse=True) G.sort(reverse=True) B.sort(reverse=True) ans = 10000000000000000000 for i in R: Min = i x = binary(0, r - 1, R, Min) y = binary(0, g - 1, G, Min) z = binary(0, b - 1, B, Min) ans = min(ans, (x - y) ** 2 + (y - z) ** 2 + (z - x) ** 2) for i in G: Min = i x = binary(0, r - 1, R, Min) y = binary(0, g - 1, G, Min) z = binary(0, b - 1, B, Min) ans = min(ans, (x - y) ** 2 + (y - z) ** 2 + (z - x) ** 2) for i in B: Min = i x = binary(0, r - 1, R, Min) y = binary(0, g - 1, G, Min) z = binary(0, b - 1, B, Min) ans = min(ans, (x - y) ** 2 + (y - z) ** 2 + (z - x) ** 2) print(ans)
FUNC_DEF WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR 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 FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR 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 FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR 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 EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
t = int(input()) while t: a, b, c = input().split(" ") a, b, c = int(a), int(b), int(c) x = input().split(" ") for i in range(a): x[i] = int(x[i]) y = input().split(" ") for i in range(b): y[i] = int(y[i]) z = input().split(" ") for i in range(c): z[i] = int(z[i]) x.sort() y.sort() z.sort() def findmin(a, x): start = 0 ans = -1 end = len(x) - 1 while start <= end: mid = (start + end) // 2 if x[mid] > a: end = mid - 1 else: ans = mid start = mid + 1 return x[ans] def findmax(target, arr): start = 0 end = len(arr) - 1 ans = -1 while start <= end: mid = (start + end) // 2 if arr[mid] < target: start = mid + 1 else: ans = mid end = mid - 1 return arr[ans] def find(x, y, z): res = 1000000000000000000000000000000000000 for i in range(len(x)): a = x[i] b = findmin(a, y) c = findmax(a, z) res = min(res, (a - b) ** 2 + (b - c) ** 2 + (c - a) ** 2) return res print( min( find(x, y, z), find(x, z, y), find(y, x, z), find(y, z, x), find(z, x, y), find(z, y, x), ) ) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR 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 RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
t = int(input()) def getClosest(val1, val2, target): if target - val1 >= val2 - target: return val2 else: return val1 def findClosest(arr, n, target): if target <= arr[0]: return arr[0] if target >= arr[n - 1]: return arr[n - 1] i = 0 j = n mid = 0 while i < j: mid = (i + j) // 2 if arr[mid] == target: return arr[mid] if target < arr[mid]: if mid > 0 and target > arr[mid - 1]: return getClosest(arr[mid - 1], arr[mid], target) j = mid else: if mid < n - 1 and target < arr[mid + 1]: return getClosest(arr[mid], arr[mid + 1], target) i = mid + 1 while t: t -= 1 nr, ng, nb = [int(x) for x in input().split()] r, g, b = ( [int(x) for x in input().split()], [int(x) for x in input().split()], [int(x) for x in input().split()], ) r.sort() g.sort() b.sort() ans = 10**25 for i in range(nr): a = r[i] bb = findClosest(g, ng, a) c = findClosest(b, nb, a) ans = min(ans, (a - bb) * (a - bb) + (bb - c) * (bb - c) + (c - a) * (c - a)) for i in range(nb): a = b[i] bb = findClosest(g, ng, a) c = findClosest(r, nr, a) ans = min(ans, (a - bb) * (a - bb) + (bb - c) * (bb - c) + (c - a) * (c - a)) for i in range(ng): a = g[i] bb = findClosest(b, nb, a) c = findClosest(r, nr, a) ans = min(ans, (a - bb) * (a - bb) + (bb - c) * (bb - c) + (c - a) * (c - a)) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF BIN_OP VAR VAR BIN_OP VAR VAR RETURN VAR RETURN VAR FUNC_DEF IF VAR VAR NUMBER RETURN VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER RETURN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN VAR VAR IF VAR VAR VAR IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN 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 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 FOR VAR FUNC_CALL VAR VAR ASSIGN 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 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 FOR VAR FUNC_CALL VAR VAR ASSIGN 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 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 EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
import sys input = sys.stdin.readline def operator(v1, v2, v3): return (v1 - v2) ** 2 + (v2 - v3) ** 2 + (v3 - v1) ** 2 def abs_diff(l, g, idx, leng): diff, val = abs(l[idx] - g), l[idx] while idx < leng - 1: idx += 1 if abs(l[idx] - g) < diff: diff = abs(l[idx] - g) val = l[idx] else: return [idx - 1, val] return [idx, val] def alternator(li1, li2, li3, len1, len2, len3): global mini fstIdx, trdIdx = 0, 0 for i in li2: fstIdx, fstVal = abs_diff(li1, i, fstIdx, len1) trdIdx, trdVal = abs_diff(li3, i, trdIdx, len3) if mini > operator(i, fstVal, trdVal): mini = operator(i, fstVal, trdVal) for _ in range(int(input())): x = input() l1 = sorted(list(set(map(int, input().split())))) l2 = sorted(list(set(map(int, input().split())))) l3 = sorted(list(set(map(int, input().split())))) n1, n2, n3 = len(l1), len(l2), len(l3) mini = operator(l1[0], l2[0], l3[0]) alternator(l1, l2, l3, n1, n2, n3) alternator(l2, l3, l1, n2, n3, n1) alternator(l3, l1, l2, n3, n1, n2) print(mini)
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN 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 FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR RETURN LIST BIN_OP VAR NUMBER VAR RETURN LIST VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her? Input The first line contains a single integer t (1≀ t ≀ 100) β€” the number of test cases. Then t test cases follow. The first line of each test case contains three integers n_r,n_g,n_b (1≀ n_r,n_g,n_b≀ 10^5) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains n_r integers r_1,r_2,…,r_{n_r} (1≀ r_i ≀ 10^9) β€” r_i is the weight of the i-th red gem. The third line of each test case contains n_g integers g_1,g_2,…,g_{n_g} (1≀ g_i ≀ 10^9) β€” g_i is the weight of the i-th green gem. The fourth line of each test case contains n_b integers b_1,b_2,…,b_{n_b} (1≀ b_i ≀ 10^9) β€” b_i is the weight of the i-th blue gem. It is guaranteed that βˆ‘ n_r ≀ 10^5, βˆ‘ n_g ≀ 10^5, βˆ‘ n_b ≀ 10^5 (the sum for all test cases). Output For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. Example Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 Note In the first test case, Xenia has the following gems: <image> If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
import sys input = sys.stdin.buffer.readline def binSearch(a, ar): l = 0 r = len(ar) mid = (l + r) // 2 while l < r: if ar[mid] > a: r = mid mid = (l + r) // 2 else: l = mid + 1 mid = (l + r) // 2 return max(0, l - 1) def binSearch2(a, b, ar): l = 0 r = len(ar) mid = (l + r) // 2 while l < r: if mid - 1 < 0: return calc(a, b, ar[0]) if calc(a, b, ar[mid - 1]) < calc(a, b, ar[mid]): r = mid mid = (l + r) // 2 else: l = mid + 1 mid = (l + r) // 2 return calc(a, b, ar[l - 1]) def calc(a, b, c): return (a - b) * (a - b) + (a - c) * (a - c) + (b - c) * (b - c) ans = [] for _ in range(int(input())): nr, ng, nb = map(int, input().split()) rW = list(map(int, input().split())) gW = list(map(int, input().split())) bW = list(map(int, input().split())) rWSet = set({}) for i in rW: rWSet.add(i) gWSet = set({}) for i in gW: gWSet.add(i) bWSet = set({}) for i in bW: bWSet.add(i) rW = list(rWSet) gW = list(gWSet) bW = list(bWSet) rW.sort() gW.sort() bW.sort() minVal = -1 for i in range(len(rW)): ind1 = binSearch(rW[i], gW) val1 = binSearch2(rW[i], gW[ind1], bW) if minVal == -1: minVal = val1 else: minVal = min(minVal, val1) if ind1 + 1 < len(gW): val2 = binSearch2(rW[i], gW[ind1 + 1], bW) minVal = min(minVal, val2) for i in range(len(rW)): ind1 = binSearch(rW[i], bW) val1 = binSearch2(rW[i], bW[ind1], gW) minVal = min(minVal, val1) if ind1 + 1 < len(bW): val2 = binSearch2(rW[i], bW[ind1 + 1], gW) minVal = min(minVal, val2) ans.append(minVal) print("\n".join(map(str, ans)))
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF RETURN 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 LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR DICT FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR DICT FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR DICT FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. Recently Xenia has bought $n_r$ red gems, $n_g$ green gems and $n_b$ blue gems. Each of the gems has a weight. Now, she is going to pick three gems. Xenia loves colorful things, so she will pick exactly one gem of each color. Xenia loves balance, so she will try to pick gems with little difference in weight. Specifically, supposing the weights of the picked gems are $x$, $y$ and $z$, Xenia wants to find the minimum value of $(x-y)^2+(y-z)^2+(z-x)^2$. As her dear friend, can you help her? -----Input----- The first line contains a single integer $t$ ($1\le t \le 100$) β€” the number of test cases. Then $t$ test cases follow. The first line of each test case contains three integers $n_r,n_g,n_b$ ($1\le n_r,n_g,n_b\le 10^5$) β€” the number of red gems, green gems and blue gems respectively. The second line of each test case contains $n_r$ integers $r_1,r_2,\ldots,r_{n_r}$ ($1\le r_i \le 10^9$) β€” $r_i$ is the weight of the $i$-th red gem. The third line of each test case contains $n_g$ integers $g_1,g_2,\ldots,g_{n_g}$ ($1\le g_i \le 10^9$) β€” $g_i$ is the weight of the $i$-th green gem. The fourth line of each test case contains $n_b$ integers $b_1,b_2,\ldots,b_{n_b}$ ($1\le b_i \le 10^9$) β€” $b_i$ is the weight of the $i$-th blue gem. It is guaranteed that $\sum n_r \le 10^5$, $\sum n_g \le 10^5$, $\sum n_b \le 10^5$ (the sum for all test cases). -----Output----- For each test case, print a line contains one integer β€” the minimum value which Xenia wants to find. -----Examples----- Input 5 2 2 3 7 8 6 3 3 1 4 1 1 1 1 1 1000000000 2 2 2 1 2 5 4 6 7 2 2 2 1 2 3 4 6 7 3 4 1 3 2 1 7 3 3 4 6 Output 14 1999999996000000002 24 24 14 -----Note----- In the first test case, Xenia has the following gems: If she picks the red gem with weight $7$, the green gem with weight $6$, and the blue gem with weight $4$, she will achieve the most balanced selection with $(x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14$.
def cases(array1, array2, array3): n1 = len(array1) n2 = len(array2) n3 = len(array3) currmin = 0 currmax = 0 ans = 92523523623423452323623 for ele in array2: while currmin + 1 < n1 and array1[currmin + 1] <= ele: currmin += 1 while currmax + 1 < n3 and array3[currmax] < ele: currmax += 1 if array1[currmin] > ele and ele > array3[currmax]: continue ans = min( ans, (ele - array1[currmin]) ** 2 + (ele - array3[currmax]) ** 2 + (array1[currmin] - array3[currmax]) ** 2, ) return ans for _ in range(int(input())): n1, n2, n3 = map(int, input().split()) array1 = list(map(int, input().split())) array2 = list(map(int, input().split())) array3 = list(map(int, input().split())) array1.sort() array2.sort() array3.sort() t1 = cases(array1, array2, array3) t2 = cases(array1, array3, array2) t3 = cases(array2, array1, array3) t4 = cases(array2, array3, array1) t5 = cases(array3, array1, array2) t6 = cases(array3, array2, array1) print(min(t1, t2, t3, t4, t5, t6))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR WHILE BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER WHILE BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR 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 FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR
An atom of element X can exist in n distinct states with energies E_1 < E_2 < ... < E_{n}. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states i, j and k are selected, where i < j < k. After that the following process happens: initially the atom is in the state i, we spend E_{k} - E_{i} energy to put the atom in the state k, the atom emits a photon with useful energy E_{k} - E_{j} and changes its state to the state j, the atom spontaneously changes its state to the state i, losing energy E_{j} - E_{i}, the process repeats from step 1. Let's define the energy conversion efficiency as $\eta = \frac{E_{k} - E_{j}}{E_{k} - E_{i}}$, i.Β e. the ration between the useful energy of the photon and spent energy. Due to some limitations, Arkady can only choose such three states that E_{k} - E_{i} ≀ U. Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints. -----Input----- The first line contains two integers n and U (3 ≀ n ≀ 10^5, 1 ≀ U ≀ 10^9) β€” the number of states and the maximum possible difference between E_{k} and E_{i}. The second line contains a sequence of integers E_1, E_2, ..., E_{n} (1 ≀ E_1 < E_2... < E_{n} ≀ 10^9). It is guaranteed that all E_{i} are given in increasing order. -----Output----- If it is not possible to choose three states that satisfy all constraints, print -1. Otherwise, print one real number Ξ·Β β€” the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10^{ - 9}. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if $\frac{|a - b|}{\operatorname{max}(1,|b|)} \leq 10^{-9}$. -----Examples----- Input 4 4 1 3 5 7 Output 0.5 Input 10 8 10 13 15 16 17 19 20 22 24 25 Output 0.875 Input 3 1 2 5 10 Output -1 -----Note----- In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to $\eta = \frac{5 - 3}{5 - 1} = 0.5$. In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to $\eta = \frac{24 - 17}{24 - 16} = 0.875$.
n, U = list(map(int, input().split())) E = list(map(int, input().split())) E.append(10**20) E.append(10**20) E.append(10**20) start = 0 finish = 1 res = -1 while start < n - 2: while E[finish] - E[start] > U and start < n - 2: start += 1 while E[finish + 1] - E[start] <= U and finish + 1 < n: finish += 1 if finish - start > 1 and finish < n and start < n: if E[finish] - E[start] <= U: res = max(res, (E[finish] - E[start + 1]) / (E[finish] - E[start])) start += 1 print(res)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER WHILE BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
An atom of element X can exist in n distinct states with energies E_1 < E_2 < ... < E_{n}. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states i, j and k are selected, where i < j < k. After that the following process happens: initially the atom is in the state i, we spend E_{k} - E_{i} energy to put the atom in the state k, the atom emits a photon with useful energy E_{k} - E_{j} and changes its state to the state j, the atom spontaneously changes its state to the state i, losing energy E_{j} - E_{i}, the process repeats from step 1. Let's define the energy conversion efficiency as $\eta = \frac{E_{k} - E_{j}}{E_{k} - E_{i}}$, i.Β e. the ration between the useful energy of the photon and spent energy. Due to some limitations, Arkady can only choose such three states that E_{k} - E_{i} ≀ U. Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints. -----Input----- The first line contains two integers n and U (3 ≀ n ≀ 10^5, 1 ≀ U ≀ 10^9) β€” the number of states and the maximum possible difference between E_{k} and E_{i}. The second line contains a sequence of integers E_1, E_2, ..., E_{n} (1 ≀ E_1 < E_2... < E_{n} ≀ 10^9). It is guaranteed that all E_{i} are given in increasing order. -----Output----- If it is not possible to choose three states that satisfy all constraints, print -1. Otherwise, print one real number Ξ·Β β€” the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10^{ - 9}. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if $\frac{|a - b|}{\operatorname{max}(1,|b|)} \leq 10^{-9}$. -----Examples----- Input 4 4 1 3 5 7 Output 0.5 Input 10 8 10 13 15 16 17 19 20 22 24 25 Output 0.875 Input 3 1 2 5 10 Output -1 -----Note----- In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to $\eta = \frac{5 - 3}{5 - 1} = 0.5$. In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to $\eta = \frac{24 - 17}{24 - 16} = 0.875$.
n, u = map(int, input().split()) E = [int(x) for x in input().split()] + [10**10] ans = -1 k = 0 for i in range(n): while E[k + 1] <= E[i] + u: k += 1 if k - i >= 2: n = (E[k] - E[i + 1]) / (E[k] - E[i]) ans = max(ans, n) print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR LIST BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
An atom of element X can exist in n distinct states with energies E_1 < E_2 < ... < E_{n}. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states i, j and k are selected, where i < j < k. After that the following process happens: initially the atom is in the state i, we spend E_{k} - E_{i} energy to put the atom in the state k, the atom emits a photon with useful energy E_{k} - E_{j} and changes its state to the state j, the atom spontaneously changes its state to the state i, losing energy E_{j} - E_{i}, the process repeats from step 1. Let's define the energy conversion efficiency as $\eta = \frac{E_{k} - E_{j}}{E_{k} - E_{i}}$, i.Β e. the ration between the useful energy of the photon and spent energy. Due to some limitations, Arkady can only choose such three states that E_{k} - E_{i} ≀ U. Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints. -----Input----- The first line contains two integers n and U (3 ≀ n ≀ 10^5, 1 ≀ U ≀ 10^9) β€” the number of states and the maximum possible difference between E_{k} and E_{i}. The second line contains a sequence of integers E_1, E_2, ..., E_{n} (1 ≀ E_1 < E_2... < E_{n} ≀ 10^9). It is guaranteed that all E_{i} are given in increasing order. -----Output----- If it is not possible to choose three states that satisfy all constraints, print -1. Otherwise, print one real number Ξ·Β β€” the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10^{ - 9}. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if $\frac{|a - b|}{\operatorname{max}(1,|b|)} \leq 10^{-9}$. -----Examples----- Input 4 4 1 3 5 7 Output 0.5 Input 10 8 10 13 15 16 17 19 20 22 24 25 Output 0.875 Input 3 1 2 5 10 Output -1 -----Note----- In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to $\eta = \frac{5 - 3}{5 - 1} = 0.5$. In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to $\eta = \frac{24 - 17}{24 - 16} = 0.875$.
import sys string = sys.stdin.readline() n = int(string.split()[0]) u = int(string.split()[1]) levels = tuple(map(int, sys.stdin.readline().split())) if len(levels) < 3: sys.stdout.write("-1") exit(0) i, j, k = 0, 1, 2 indices = 0, 1, 2 level_i = levels[0] level_j = levels[1] nu = levels[2] - level_i nu = -1 while i < n - 2: while k < n - 1 and levels[k + 1] - level_i <= u: k += 1 nu_cur = levels[k] - level_i if nu_cur <= u: nu_cur = (levels[k] - level_j) * 1 / nu_cur else: nu_cur = -1 if nu_cur > nu: nu = nu_cur indices = i, j, k i += 1 j += 1 k = max(k, j + 1) level_j = levels[j] level_i = levels[i] sys.stdout.write(str(nu))
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
An atom of element X can exist in n distinct states with energies E_1 < E_2 < ... < E_{n}. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states i, j and k are selected, where i < j < k. After that the following process happens: initially the atom is in the state i, we spend E_{k} - E_{i} energy to put the atom in the state k, the atom emits a photon with useful energy E_{k} - E_{j} and changes its state to the state j, the atom spontaneously changes its state to the state i, losing energy E_{j} - E_{i}, the process repeats from step 1. Let's define the energy conversion efficiency as $\eta = \frac{E_{k} - E_{j}}{E_{k} - E_{i}}$, i.Β e. the ration between the useful energy of the photon and spent energy. Due to some limitations, Arkady can only choose such three states that E_{k} - E_{i} ≀ U. Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints. -----Input----- The first line contains two integers n and U (3 ≀ n ≀ 10^5, 1 ≀ U ≀ 10^9) β€” the number of states and the maximum possible difference between E_{k} and E_{i}. The second line contains a sequence of integers E_1, E_2, ..., E_{n} (1 ≀ E_1 < E_2... < E_{n} ≀ 10^9). It is guaranteed that all E_{i} are given in increasing order. -----Output----- If it is not possible to choose three states that satisfy all constraints, print -1. Otherwise, print one real number Ξ·Β β€” the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10^{ - 9}. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if $\frac{|a - b|}{\operatorname{max}(1,|b|)} \leq 10^{-9}$. -----Examples----- Input 4 4 1 3 5 7 Output 0.5 Input 10 8 10 13 15 16 17 19 20 22 24 25 Output 0.875 Input 3 1 2 5 10 Output -1 -----Note----- In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to $\eta = \frac{5 - 3}{5 - 1} = 0.5$. In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to $\eta = \frac{24 - 17}{24 - 16} = 0.875$.
n, u = list(map(int, input().split())) e = list(map(int, input().split())) max_eff = -1 j = 0 for i in range(n): while j < n and e[j] <= e[i] + u: j += 1 if i + 3 <= j: max_eff = max(max_eff, (e[j - 1] - e[i + 1]) / (e[j - 1] - e[i])) print(max_eff)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
An atom of element X can exist in n distinct states with energies E_1 < E_2 < ... < E_{n}. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states i, j and k are selected, where i < j < k. After that the following process happens: initially the atom is in the state i, we spend E_{k} - E_{i} energy to put the atom in the state k, the atom emits a photon with useful energy E_{k} - E_{j} and changes its state to the state j, the atom spontaneously changes its state to the state i, losing energy E_{j} - E_{i}, the process repeats from step 1. Let's define the energy conversion efficiency as $\eta = \frac{E_{k} - E_{j}}{E_{k} - E_{i}}$, i.Β e. the ration between the useful energy of the photon and spent energy. Due to some limitations, Arkady can only choose such three states that E_{k} - E_{i} ≀ U. Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints. -----Input----- The first line contains two integers n and U (3 ≀ n ≀ 10^5, 1 ≀ U ≀ 10^9) β€” the number of states and the maximum possible difference between E_{k} and E_{i}. The second line contains a sequence of integers E_1, E_2, ..., E_{n} (1 ≀ E_1 < E_2... < E_{n} ≀ 10^9). It is guaranteed that all E_{i} are given in increasing order. -----Output----- If it is not possible to choose three states that satisfy all constraints, print -1. Otherwise, print one real number Ξ·Β β€” the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10^{ - 9}. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if $\frac{|a - b|}{\operatorname{max}(1,|b|)} \leq 10^{-9}$. -----Examples----- Input 4 4 1 3 5 7 Output 0.5 Input 10 8 10 13 15 16 17 19 20 22 24 25 Output 0.875 Input 3 1 2 5 10 Output -1 -----Note----- In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to $\eta = \frac{5 - 3}{5 - 1} = 0.5$. In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to $\eta = \frac{24 - 17}{24 - 16} = 0.875$.
n, v = list(map(int, input().split())) l = list(map(int, input().split())) ans = [-1] for i in range(n - 2): uk1 = i + 2 uk2 = n - 1 while uk2 - uk1 > 1: if l[(uk2 + uk1) // 2] - l[i] <= v: uk1 = (uk2 + uk1) // 2 else: uk2 = (uk2 + uk1) // 2 if l[uk2] - l[i] <= v: ans.append((l[uk2] - l[i + 1]) / (l[uk2] - l[i])) elif l[uk1] - l[i] <= v: ans.append((l[uk1] - l[i + 1]) / (l[uk1] - l[i])) print(max(ans))
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER IF BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
An atom of element X can exist in n distinct states with energies E_1 < E_2 < ... < E_{n}. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states i, j and k are selected, where i < j < k. After that the following process happens: initially the atom is in the state i, we spend E_{k} - E_{i} energy to put the atom in the state k, the atom emits a photon with useful energy E_{k} - E_{j} and changes its state to the state j, the atom spontaneously changes its state to the state i, losing energy E_{j} - E_{i}, the process repeats from step 1. Let's define the energy conversion efficiency as $\eta = \frac{E_{k} - E_{j}}{E_{k} - E_{i}}$, i.Β e. the ration between the useful energy of the photon and spent energy. Due to some limitations, Arkady can only choose such three states that E_{k} - E_{i} ≀ U. Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints. -----Input----- The first line contains two integers n and U (3 ≀ n ≀ 10^5, 1 ≀ U ≀ 10^9) β€” the number of states and the maximum possible difference between E_{k} and E_{i}. The second line contains a sequence of integers E_1, E_2, ..., E_{n} (1 ≀ E_1 < E_2... < E_{n} ≀ 10^9). It is guaranteed that all E_{i} are given in increasing order. -----Output----- If it is not possible to choose three states that satisfy all constraints, print -1. Otherwise, print one real number Ξ·Β β€” the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10^{ - 9}. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if $\frac{|a - b|}{\operatorname{max}(1,|b|)} \leq 10^{-9}$. -----Examples----- Input 4 4 1 3 5 7 Output 0.5 Input 10 8 10 13 15 16 17 19 20 22 24 25 Output 0.875 Input 3 1 2 5 10 Output -1 -----Note----- In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to $\eta = \frac{5 - 3}{5 - 1} = 0.5$. In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to $\eta = \frac{24 - 17}{24 - 16} = 0.875$.
n, m = map(int, input().split()) a = list(map(int, input().split())) k = 0 ans = -1 for i in range(n - 1): while k < n - 1 and a[k + 1] - a[i] <= m: k += 1 if i < k - 1: ans = max(ans, (a[k] - a[i + 1]) / (a[k] - a[i])) print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
An atom of element X can exist in n distinct states with energies E_1 < E_2 < ... < E_{n}. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states i, j and k are selected, where i < j < k. After that the following process happens: initially the atom is in the state i, we spend E_{k} - E_{i} energy to put the atom in the state k, the atom emits a photon with useful energy E_{k} - E_{j} and changes its state to the state j, the atom spontaneously changes its state to the state i, losing energy E_{j} - E_{i}, the process repeats from step 1. Let's define the energy conversion efficiency as $\eta = \frac{E_{k} - E_{j}}{E_{k} - E_{i}}$, i.Β e. the ration between the useful energy of the photon and spent energy. Due to some limitations, Arkady can only choose such three states that E_{k} - E_{i} ≀ U. Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints. -----Input----- The first line contains two integers n and U (3 ≀ n ≀ 10^5, 1 ≀ U ≀ 10^9) β€” the number of states and the maximum possible difference between E_{k} and E_{i}. The second line contains a sequence of integers E_1, E_2, ..., E_{n} (1 ≀ E_1 < E_2... < E_{n} ≀ 10^9). It is guaranteed that all E_{i} are given in increasing order. -----Output----- If it is not possible to choose three states that satisfy all constraints, print -1. Otherwise, print one real number Ξ·Β β€” the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10^{ - 9}. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if $\frac{|a - b|}{\operatorname{max}(1,|b|)} \leq 10^{-9}$. -----Examples----- Input 4 4 1 3 5 7 Output 0.5 Input 10 8 10 13 15 16 17 19 20 22 24 25 Output 0.875 Input 3 1 2 5 10 Output -1 -----Note----- In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to $\eta = \frac{5 - 3}{5 - 1} = 0.5$. In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to $\eta = \frac{24 - 17}{24 - 16} = 0.875$.
import sys n, u = [int(x) for x in input().split(" ")] a = [int(x) for x in input().split(" ")] b = [0] * n j = 1 for i in range(n): while j < n and a[j] - a[i] <= u: j += 1 b[i] = j - i - 1 ans = -1.0 for i in range(n): if b[i] > 1: ans = max(ans, (a[i + b[i]] - a[i + 1]) / (a[i + b[i]] - a[i])) print(ans)
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
An atom of element X can exist in n distinct states with energies E_1 < E_2 < ... < E_{n}. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states i, j and k are selected, where i < j < k. After that the following process happens: initially the atom is in the state i, we spend E_{k} - E_{i} energy to put the atom in the state k, the atom emits a photon with useful energy E_{k} - E_{j} and changes its state to the state j, the atom spontaneously changes its state to the state i, losing energy E_{j} - E_{i}, the process repeats from step 1. Let's define the energy conversion efficiency as $\eta = \frac{E_{k} - E_{j}}{E_{k} - E_{i}}$, i.Β e. the ration between the useful energy of the photon and spent energy. Due to some limitations, Arkady can only choose such three states that E_{k} - E_{i} ≀ U. Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints. -----Input----- The first line contains two integers n and U (3 ≀ n ≀ 10^5, 1 ≀ U ≀ 10^9) β€” the number of states and the maximum possible difference between E_{k} and E_{i}. The second line contains a sequence of integers E_1, E_2, ..., E_{n} (1 ≀ E_1 < E_2... < E_{n} ≀ 10^9). It is guaranteed that all E_{i} are given in increasing order. -----Output----- If it is not possible to choose three states that satisfy all constraints, print -1. Otherwise, print one real number Ξ·Β β€” the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10^{ - 9}. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if $\frac{|a - b|}{\operatorname{max}(1,|b|)} \leq 10^{-9}$. -----Examples----- Input 4 4 1 3 5 7 Output 0.5 Input 10 8 10 13 15 16 17 19 20 22 24 25 Output 0.875 Input 3 1 2 5 10 Output -1 -----Note----- In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to $\eta = \frac{5 - 3}{5 - 1} = 0.5$. In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to $\eta = \frac{24 - 17}{24 - 16} = 0.875$.
def upper_bound(a, n, i, x): l = i h = n while l < h: mid = (l + h) // 2 if x >= a[mid]: l = mid + 1 else: h = mid return l n, u = [int(x) for x in input().split()] a = list(map(int, input().split())) idx = 0 ans = -1 for i in range(n - 2): idx = upper_bound(a, n, i, a[i] + u) - 1 if idx - i >= 2: ans = max(ans, (a[idx] - a[i + 1]) / (a[idx] - a[i])) print(ans)
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
An atom of element X can exist in n distinct states with energies E_1 < E_2 < ... < E_{n}. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states i, j and k are selected, where i < j < k. After that the following process happens: initially the atom is in the state i, we spend E_{k} - E_{i} energy to put the atom in the state k, the atom emits a photon with useful energy E_{k} - E_{j} and changes its state to the state j, the atom spontaneously changes its state to the state i, losing energy E_{j} - E_{i}, the process repeats from step 1. Let's define the energy conversion efficiency as $\eta = \frac{E_{k} - E_{j}}{E_{k} - E_{i}}$, i.Β e. the ration between the useful energy of the photon and spent energy. Due to some limitations, Arkady can only choose such three states that E_{k} - E_{i} ≀ U. Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints. -----Input----- The first line contains two integers n and U (3 ≀ n ≀ 10^5, 1 ≀ U ≀ 10^9) β€” the number of states and the maximum possible difference between E_{k} and E_{i}. The second line contains a sequence of integers E_1, E_2, ..., E_{n} (1 ≀ E_1 < E_2... < E_{n} ≀ 10^9). It is guaranteed that all E_{i} are given in increasing order. -----Output----- If it is not possible to choose three states that satisfy all constraints, print -1. Otherwise, print one real number Ξ·Β β€” the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10^{ - 9}. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if $\frac{|a - b|}{\operatorname{max}(1,|b|)} \leq 10^{-9}$. -----Examples----- Input 4 4 1 3 5 7 Output 0.5 Input 10 8 10 13 15 16 17 19 20 22 24 25 Output 0.875 Input 3 1 2 5 10 Output -1 -----Note----- In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to $\eta = \frac{5 - 3}{5 - 1} = 0.5$. In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to $\eta = \frac{24 - 17}{24 - 16} = 0.875$.
def read_data(): n, m = map(int, input().strip().split()) a = list(map(int, list(input().strip().split()))) return n, m, a def find(start, end, v): mid = int((start + end) / 2) if start == end: return start if end - start == 1: if a[end] <= v: return end else: return start if a[mid] == v: return mid if a[mid] > v: return find(start, mid, v) else: return find(mid, end, v) def solve(): val = -1 for i in range(0, len(a) - 2): pos = find(i + 2, len(a) - 1, a[i] + m) if a[pos] <= a[i] + m: if (a[pos] - a[i + 1]) / (a[pos] - a[i]) > val: val = (a[pos] - a[i + 1]) / (a[pos] - a[i]) return val n, m, a = read_data() print(solve())
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR RETURN VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR RETURN VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN VAR RETURN VAR IF VAR VAR VAR RETURN VAR IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR VAR IF VAR VAR BIN_OP VAR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
An atom of element X can exist in n distinct states with energies E_1 < E_2 < ... < E_{n}. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states i, j and k are selected, where i < j < k. After that the following process happens: initially the atom is in the state i, we spend E_{k} - E_{i} energy to put the atom in the state k, the atom emits a photon with useful energy E_{k} - E_{j} and changes its state to the state j, the atom spontaneously changes its state to the state i, losing energy E_{j} - E_{i}, the process repeats from step 1. Let's define the energy conversion efficiency as $\eta = \frac{E_{k} - E_{j}}{E_{k} - E_{i}}$, i.Β e. the ration between the useful energy of the photon and spent energy. Due to some limitations, Arkady can only choose such three states that E_{k} - E_{i} ≀ U. Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints. -----Input----- The first line contains two integers n and U (3 ≀ n ≀ 10^5, 1 ≀ U ≀ 10^9) β€” the number of states and the maximum possible difference between E_{k} and E_{i}. The second line contains a sequence of integers E_1, E_2, ..., E_{n} (1 ≀ E_1 < E_2... < E_{n} ≀ 10^9). It is guaranteed that all E_{i} are given in increasing order. -----Output----- If it is not possible to choose three states that satisfy all constraints, print -1. Otherwise, print one real number Ξ·Β β€” the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10^{ - 9}. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if $\frac{|a - b|}{\operatorname{max}(1,|b|)} \leq 10^{-9}$. -----Examples----- Input 4 4 1 3 5 7 Output 0.5 Input 10 8 10 13 15 16 17 19 20 22 24 25 Output 0.875 Input 3 1 2 5 10 Output -1 -----Note----- In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to $\eta = \frac{5 - 3}{5 - 1} = 0.5$. In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to $\eta = \frac{24 - 17}{24 - 16} = 0.875$.
n, U = list(map(int, input().strip().split())) E = list(map(int, input().strip().split())) mmax = -1 for i in range(0, n - 2): j = i + 1 l = j + 1 r = n - 1 while l < r: mid = (l + r) // 2 if E[mid] - E[i] <= U: l = mid + 1 else: r = mid - 1 if E[l] - E[i] <= U: cur = (E[l] - E[j]) / (E[l] - E[i]) mmax = max(mmax, cur) elif l - 1 > j and E[l - 1] - E[i] <= U: cur = (E[l - 1] - E[j]) / (E[l - 1] - E[i]) mmax = max(mmax, cur) print(mmax)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR