description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well.
Chef is a cook and he has recently opened a restaurant.
The restaurant is open during $N$ time intervals $[L_{1}, R_{1}), [L_{2}, R_{2}), \dots, [L_{N}, R_{N})$. No two of these intervals overlap β formally, for each valid $i$, $j$ such that $i \neq j$, either $R_{i} < L_{j}$ or $R_{j} < L_{i}$.
$M$ people (numbered $1$ through $M$) are planning to eat at the restaurant; let's denote the time when the $i$-th person arrives by $P_{i}$. If the restaurant is open at that time, this person does not have to wait, but if it is closed, this person will wait until it is open. Note that if this person arrives at an exact time when the restaurant is closing, they have to wait for the next opening time.
For each person, calculate how long they have to wait (possibly $0$ time), or determine that they will wait forever for the restaurant to open.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of the input contains two space-separated integers $N$ and $M$.
$N$ lines follow. For each valid $i$, the $i$-th of these lines contains two space-separated integers $L_{i}$ and $R_{i}$.
$M$ lines follow. For each valid $i$, the $i$-th of these lines contains a single integer $P_{i}$.
------ Output ------
For each test case, print $M$ lines. For each valid $i$, the $i$-th of these lines should contain a single integer β the time person $i$ has to wait, or $-1$ if person $i$ has to wait forever.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N, M β€ 10^{5}$
$1 β€ L_{i} < R_{i} β€ 10^{9}$ for each valid $i$
$1 β€ P_{i} β€ 10^{9}$ for each valid $i$
the intervals are pairwise disjoint
the sum of $N$ for all test cases does not exceed $3 \cdot 10^{5}$
the sum of $M$ for all test cases does not exceed $3 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (30 points):
the sum of $N$ for all test cases does not exceed $1,000$
the sum of $M$ for all test cases does not exceed $1,000$
Subtask #2 (70 points): original constraints
----- Sample Input 1 ------
1
4 5
5 7
9 10
2 3
20 30
5
6
7
35
1
----- Sample Output 1 ------
0
0
2
-1
1
----- explanation 1 ------
Query $1$: The person coming at time $5$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $2$: The person coming at time $6$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $3$: The person coming at time $7$ has to wait since the restaurant is closed at time $7$. The next slot in which the restaurant opens is $[9,10)$. Thus, the person waits for $2$ units of time.
Query $4$: The person coming at time $35$ has to wait forever as the restaurant does not open after time $30$. | def find_index(arr, n, K):
start = 0
end = n - 1
while start <= end:
mid = (start + end) // 2
if arr[mid] == K:
return mid
elif arr[mid] < K:
start = mid + 1
else:
end = mid - 1
return end + 1
t = int(input())
for test in range(t):
n, m = map(int, input().split())
resT = []
l = []
p = []
for i in range(n):
left, r = map(int, input().split())
resT.append([left, r])
l.append(left)
for j in range(m):
p.append(int(input()))
resT.sort()
l.sort()
for i in range(m):
time = p[i]
ind = find_index(l, n, time)
if ind == 0:
if l[ind] == time:
print(0)
else:
print(l[0] - time)
elif ind == n:
if resT[ind - 1][1] > time:
print(0)
else:
print(-1)
elif resT[ind - 1][1] > time:
print(0)
else:
print(l[ind] - time) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP 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 BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR |
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well.
Chef is a cook and he has recently opened a restaurant.
The restaurant is open during $N$ time intervals $[L_{1}, R_{1}), [L_{2}, R_{2}), \dots, [L_{N}, R_{N})$. No two of these intervals overlap β formally, for each valid $i$, $j$ such that $i \neq j$, either $R_{i} < L_{j}$ or $R_{j} < L_{i}$.
$M$ people (numbered $1$ through $M$) are planning to eat at the restaurant; let's denote the time when the $i$-th person arrives by $P_{i}$. If the restaurant is open at that time, this person does not have to wait, but if it is closed, this person will wait until it is open. Note that if this person arrives at an exact time when the restaurant is closing, they have to wait for the next opening time.
For each person, calculate how long they have to wait (possibly $0$ time), or determine that they will wait forever for the restaurant to open.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of the input contains two space-separated integers $N$ and $M$.
$N$ lines follow. For each valid $i$, the $i$-th of these lines contains two space-separated integers $L_{i}$ and $R_{i}$.
$M$ lines follow. For each valid $i$, the $i$-th of these lines contains a single integer $P_{i}$.
------ Output ------
For each test case, print $M$ lines. For each valid $i$, the $i$-th of these lines should contain a single integer β the time person $i$ has to wait, or $-1$ if person $i$ has to wait forever.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N, M β€ 10^{5}$
$1 β€ L_{i} < R_{i} β€ 10^{9}$ for each valid $i$
$1 β€ P_{i} β€ 10^{9}$ for each valid $i$
the intervals are pairwise disjoint
the sum of $N$ for all test cases does not exceed $3 \cdot 10^{5}$
the sum of $M$ for all test cases does not exceed $3 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (30 points):
the sum of $N$ for all test cases does not exceed $1,000$
the sum of $M$ for all test cases does not exceed $1,000$
Subtask #2 (70 points): original constraints
----- Sample Input 1 ------
1
4 5
5 7
9 10
2 3
20 30
5
6
7
35
1
----- Sample Output 1 ------
0
0
2
-1
1
----- explanation 1 ------
Query $1$: The person coming at time $5$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $2$: The person coming at time $6$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $3$: The person coming at time $7$ has to wait since the restaurant is closed at time $7$. The next slot in which the restaurant opens is $[9,10)$. Thus, the person waits for $2$ units of time.
Query $4$: The person coming at time $35$ has to wait forever as the restaurant does not open after time $30$. | t = int(input())
for co in range(t):
l = []
n, m = list(map(int, input().split()))
for i in range(n):
l.append(list(map(int, input().split())))
l.sort()
for i in range(m):
c = 0
s = int(input())
if s >= l[-1][1]:
print("-1")
elif s < l[0][0]:
print(l[0][0] - s)
elif s > l[-1][0] and s < l[-1][1] and c == 0:
print("0")
else:
hi = n - 1
lo = 0
ans = -1
while lo <= hi:
j = (lo + hi) // 2
if s >= l[j][0] and s < l[j][1]:
print("0")
c = 1
break
elif s < l[j][0]:
ans = j
hi = j - 1
else:
lo = j + 1
if c == 0:
print(l[ans][0] - s) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR IF VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR |
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well.
Chef is a cook and he has recently opened a restaurant.
The restaurant is open during $N$ time intervals $[L_{1}, R_{1}), [L_{2}, R_{2}), \dots, [L_{N}, R_{N})$. No two of these intervals overlap β formally, for each valid $i$, $j$ such that $i \neq j$, either $R_{i} < L_{j}$ or $R_{j} < L_{i}$.
$M$ people (numbered $1$ through $M$) are planning to eat at the restaurant; let's denote the time when the $i$-th person arrives by $P_{i}$. If the restaurant is open at that time, this person does not have to wait, but if it is closed, this person will wait until it is open. Note that if this person arrives at an exact time when the restaurant is closing, they have to wait for the next opening time.
For each person, calculate how long they have to wait (possibly $0$ time), or determine that they will wait forever for the restaurant to open.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of the input contains two space-separated integers $N$ and $M$.
$N$ lines follow. For each valid $i$, the $i$-th of these lines contains two space-separated integers $L_{i}$ and $R_{i}$.
$M$ lines follow. For each valid $i$, the $i$-th of these lines contains a single integer $P_{i}$.
------ Output ------
For each test case, print $M$ lines. For each valid $i$, the $i$-th of these lines should contain a single integer β the time person $i$ has to wait, or $-1$ if person $i$ has to wait forever.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N, M β€ 10^{5}$
$1 β€ L_{i} < R_{i} β€ 10^{9}$ for each valid $i$
$1 β€ P_{i} β€ 10^{9}$ for each valid $i$
the intervals are pairwise disjoint
the sum of $N$ for all test cases does not exceed $3 \cdot 10^{5}$
the sum of $M$ for all test cases does not exceed $3 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (30 points):
the sum of $N$ for all test cases does not exceed $1,000$
the sum of $M$ for all test cases does not exceed $1,000$
Subtask #2 (70 points): original constraints
----- Sample Input 1 ------
1
4 5
5 7
9 10
2 3
20 30
5
6
7
35
1
----- Sample Output 1 ------
0
0
2
-1
1
----- explanation 1 ------
Query $1$: The person coming at time $5$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $2$: The person coming at time $6$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $3$: The person coming at time $7$ has to wait since the restaurant is closed at time $7$. The next slot in which the restaurant opens is $[9,10)$. Thus, the person waits for $2$ units of time.
Query $4$: The person coming at time $35$ has to wait forever as the restaurant does not open after time $30$. | from sys import stdin
def binary_search(interval, x):
start, end = 0, len(interval) - 1
while start <= end:
mid = (start + end) // 2
if interval[mid][0] <= x < interval[mid][1]:
return mid
elif interval[mid][0] > x:
end = mid - 1
elif interval[mid][0] < x:
start = mid + 1
return [start, end]
t = int(stdin.readline())
while t > 0:
n, m = map(int, stdin.readline().split())
interval = []
for i in range(n):
l, r = map(int, stdin.readline().split())
interval.append([l, r])
p = []
for i in range(m):
p.append(int(stdin.readline()))
interval = sorted(interval, key=lambda x: x[0])
for x in p:
wait_time = binary_search(interval, x)
if isinstance(wait_time, list):
l, r = wait_time
wait_time = -1 if l >= n else interval[l][0] - x
else:
wait_time = 0
print(wait_time)
t -= 1 | 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 NUMBER VAR VAR VAR NUMBER RETURN VAR IF VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN LIST VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER |
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well.
Chef is a cook and he has recently opened a restaurant.
The restaurant is open during $N$ time intervals $[L_{1}, R_{1}), [L_{2}, R_{2}), \dots, [L_{N}, R_{N})$. No two of these intervals overlap β formally, for each valid $i$, $j$ such that $i \neq j$, either $R_{i} < L_{j}$ or $R_{j} < L_{i}$.
$M$ people (numbered $1$ through $M$) are planning to eat at the restaurant; let's denote the time when the $i$-th person arrives by $P_{i}$. If the restaurant is open at that time, this person does not have to wait, but if it is closed, this person will wait until it is open. Note that if this person arrives at an exact time when the restaurant is closing, they have to wait for the next opening time.
For each person, calculate how long they have to wait (possibly $0$ time), or determine that they will wait forever for the restaurant to open.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of the input contains two space-separated integers $N$ and $M$.
$N$ lines follow. For each valid $i$, the $i$-th of these lines contains two space-separated integers $L_{i}$ and $R_{i}$.
$M$ lines follow. For each valid $i$, the $i$-th of these lines contains a single integer $P_{i}$.
------ Output ------
For each test case, print $M$ lines. For each valid $i$, the $i$-th of these lines should contain a single integer β the time person $i$ has to wait, or $-1$ if person $i$ has to wait forever.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N, M β€ 10^{5}$
$1 β€ L_{i} < R_{i} β€ 10^{9}$ for each valid $i$
$1 β€ P_{i} β€ 10^{9}$ for each valid $i$
the intervals are pairwise disjoint
the sum of $N$ for all test cases does not exceed $3 \cdot 10^{5}$
the sum of $M$ for all test cases does not exceed $3 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (30 points):
the sum of $N$ for all test cases does not exceed $1,000$
the sum of $M$ for all test cases does not exceed $1,000$
Subtask #2 (70 points): original constraints
----- Sample Input 1 ------
1
4 5
5 7
9 10
2 3
20 30
5
6
7
35
1
----- Sample Output 1 ------
0
0
2
-1
1
----- explanation 1 ------
Query $1$: The person coming at time $5$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $2$: The person coming at time $6$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $3$: The person coming at time $7$ has to wait since the restaurant is closed at time $7$. The next slot in which the restaurant opens is $[9,10)$. Thus, the person waits for $2$ units of time.
Query $4$: The person coming at time $35$ has to wait forever as the restaurant does not open after time $30$. | t = int(input())
for _ in range(t):
n, m = map(int, input().split())
lst = []
for __ in range(n):
a, b = map(int, input().split())
lst.append([a, b])
lst.sort(key=lambda x: x[0])
for __ in range(m):
curr = int(input())
si = 0
ei = n - 1
ans = -1
while si <= ei:
mid = (si + ei) // 2
if lst[mid][0] < curr:
si = mid + 1
elif lst[mid][0] > curr:
ei = mid - 1
ans = mid
else:
ans = mid
break
if ans == -1:
if lst[n - 1][0] <= curr and lst[n - 1][1] > curr:
print(0)
else:
print(-1)
elif ans == 0:
print(lst[ans][0] - curr)
elif lst[ans - 1][0] <= curr and lst[ans - 1][1] > curr:
print(0)
else:
print(lst[ans][0] - curr) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR |
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well.
Chef is a cook and he has recently opened a restaurant.
The restaurant is open during $N$ time intervals $[L_{1}, R_{1}), [L_{2}, R_{2}), \dots, [L_{N}, R_{N})$. No two of these intervals overlap β formally, for each valid $i$, $j$ such that $i \neq j$, either $R_{i} < L_{j}$ or $R_{j} < L_{i}$.
$M$ people (numbered $1$ through $M$) are planning to eat at the restaurant; let's denote the time when the $i$-th person arrives by $P_{i}$. If the restaurant is open at that time, this person does not have to wait, but if it is closed, this person will wait until it is open. Note that if this person arrives at an exact time when the restaurant is closing, they have to wait for the next opening time.
For each person, calculate how long they have to wait (possibly $0$ time), or determine that they will wait forever for the restaurant to open.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of the input contains two space-separated integers $N$ and $M$.
$N$ lines follow. For each valid $i$, the $i$-th of these lines contains two space-separated integers $L_{i}$ and $R_{i}$.
$M$ lines follow. For each valid $i$, the $i$-th of these lines contains a single integer $P_{i}$.
------ Output ------
For each test case, print $M$ lines. For each valid $i$, the $i$-th of these lines should contain a single integer β the time person $i$ has to wait, or $-1$ if person $i$ has to wait forever.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N, M β€ 10^{5}$
$1 β€ L_{i} < R_{i} β€ 10^{9}$ for each valid $i$
$1 β€ P_{i} β€ 10^{9}$ for each valid $i$
the intervals are pairwise disjoint
the sum of $N$ for all test cases does not exceed $3 \cdot 10^{5}$
the sum of $M$ for all test cases does not exceed $3 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (30 points):
the sum of $N$ for all test cases does not exceed $1,000$
the sum of $M$ for all test cases does not exceed $1,000$
Subtask #2 (70 points): original constraints
----- Sample Input 1 ------
1
4 5
5 7
9 10
2 3
20 30
5
6
7
35
1
----- Sample Output 1 ------
0
0
2
-1
1
----- explanation 1 ------
Query $1$: The person coming at time $5$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $2$: The person coming at time $6$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $3$: The person coming at time $7$ has to wait since the restaurant is closed at time $7$. The next slot in which the restaurant opens is $[9,10)$. Thus, the person waits for $2$ units of time.
Query $4$: The person coming at time $35$ has to wait forever as the restaurant does not open after time $30$. | def binary_search(num):
start = 0
end = n - 1
if num < intervals[0][0]:
return intervals[0][0] - num
elif num >= intervals[-1][1]:
return -1
elif num < intervals[-1][1] and num >= intervals[-1][0]:
return 0
while start <= end:
mid = (start + end) // 2
if num >= intervals[mid][0] and num < intervals[mid][1]:
return 0
if num < intervals[mid][0]:
ans = intervals[mid][0] - num
end = mid - 1
else:
start = mid + 1
return ans
t = int(input())
for _ in range(t):
n, m = list(map(int, input().split()))
intervals = []
for _ in range(n):
intervals.append(list(map(int, input().split())))
intervals = sorted(intervals, key=lambda x: x[0])
for _ in range(m):
c = int(input())
print(binary_search(c)) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER NUMBER VAR IF VAR VAR NUMBER NUMBER RETURN NUMBER IF VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER RETURN NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well.
Chef is a cook and he has recently opened a restaurant.
The restaurant is open during $N$ time intervals $[L_{1}, R_{1}), [L_{2}, R_{2}), \dots, [L_{N}, R_{N})$. No two of these intervals overlap β formally, for each valid $i$, $j$ such that $i \neq j$, either $R_{i} < L_{j}$ or $R_{j} < L_{i}$.
$M$ people (numbered $1$ through $M$) are planning to eat at the restaurant; let's denote the time when the $i$-th person arrives by $P_{i}$. If the restaurant is open at that time, this person does not have to wait, but if it is closed, this person will wait until it is open. Note that if this person arrives at an exact time when the restaurant is closing, they have to wait for the next opening time.
For each person, calculate how long they have to wait (possibly $0$ time), or determine that they will wait forever for the restaurant to open.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of the input contains two space-separated integers $N$ and $M$.
$N$ lines follow. For each valid $i$, the $i$-th of these lines contains two space-separated integers $L_{i}$ and $R_{i}$.
$M$ lines follow. For each valid $i$, the $i$-th of these lines contains a single integer $P_{i}$.
------ Output ------
For each test case, print $M$ lines. For each valid $i$, the $i$-th of these lines should contain a single integer β the time person $i$ has to wait, or $-1$ if person $i$ has to wait forever.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N, M β€ 10^{5}$
$1 β€ L_{i} < R_{i} β€ 10^{9}$ for each valid $i$
$1 β€ P_{i} β€ 10^{9}$ for each valid $i$
the intervals are pairwise disjoint
the sum of $N$ for all test cases does not exceed $3 \cdot 10^{5}$
the sum of $M$ for all test cases does not exceed $3 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (30 points):
the sum of $N$ for all test cases does not exceed $1,000$
the sum of $M$ for all test cases does not exceed $1,000$
Subtask #2 (70 points): original constraints
----- Sample Input 1 ------
1
4 5
5 7
9 10
2 3
20 30
5
6
7
35
1
----- Sample Output 1 ------
0
0
2
-1
1
----- explanation 1 ------
Query $1$: The person coming at time $5$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $2$: The person coming at time $6$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $3$: The person coming at time $7$ has to wait since the restaurant is closed at time $7$. The next slot in which the restaurant opens is $[9,10)$. Thus, the person waits for $2$ units of time.
Query $4$: The person coming at time $35$ has to wait forever as the restaurant does not open after time $30$. | def before_after_time(s, e, li, time):
if len(li) == 1:
return li[0], False
mid = (s + e) // 2
if li[mid] == time:
return li[mid], True
if abs(e - s) == 1:
return li[s], li[e]
if time > li[mid]:
return before_after_time(mid, e, li, time)
else:
return before_after_time(s, mid, li, time)
def restaurent():
for _ in range(int(input())):
n, m = map(int, input().split())
d = dict()
li = []
arriving_time = []
for _ in range(n):
start, end = map(int, input().split())
d[start] = end
li.append(start)
for _ in range(m):
arriving_time.append(int(input()))
li.sort()
s, e = 0, len(li) - 1
for x in arriving_time:
if x > d[li[e]]:
print(-1)
continue
elif x < li[s]:
print(li[0] - x)
continue
before, after = before_after_time(s, e, li, x)
if after == True:
print(0)
elif after == False:
if li[0] <= x < d[li[0]]:
print(0)
elif x < li[0]:
print(li[0] - x)
else:
print(-1)
elif before <= x < d[before] or after <= x < d[after]:
print(0)
elif x >= d[after]:
print(-1)
else:
print(after - x)
restaurent() | FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER RETURN VAR VAR VAR VAR IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR |
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well.
Chef is a cook and he has recently opened a restaurant.
The restaurant is open during $N$ time intervals $[L_{1}, R_{1}), [L_{2}, R_{2}), \dots, [L_{N}, R_{N})$. No two of these intervals overlap β formally, for each valid $i$, $j$ such that $i \neq j$, either $R_{i} < L_{j}$ or $R_{j} < L_{i}$.
$M$ people (numbered $1$ through $M$) are planning to eat at the restaurant; let's denote the time when the $i$-th person arrives by $P_{i}$. If the restaurant is open at that time, this person does not have to wait, but if it is closed, this person will wait until it is open. Note that if this person arrives at an exact time when the restaurant is closing, they have to wait for the next opening time.
For each person, calculate how long they have to wait (possibly $0$ time), or determine that they will wait forever for the restaurant to open.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of the input contains two space-separated integers $N$ and $M$.
$N$ lines follow. For each valid $i$, the $i$-th of these lines contains two space-separated integers $L_{i}$ and $R_{i}$.
$M$ lines follow. For each valid $i$, the $i$-th of these lines contains a single integer $P_{i}$.
------ Output ------
For each test case, print $M$ lines. For each valid $i$, the $i$-th of these lines should contain a single integer β the time person $i$ has to wait, or $-1$ if person $i$ has to wait forever.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N, M β€ 10^{5}$
$1 β€ L_{i} < R_{i} β€ 10^{9}$ for each valid $i$
$1 β€ P_{i} β€ 10^{9}$ for each valid $i$
the intervals are pairwise disjoint
the sum of $N$ for all test cases does not exceed $3 \cdot 10^{5}$
the sum of $M$ for all test cases does not exceed $3 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (30 points):
the sum of $N$ for all test cases does not exceed $1,000$
the sum of $M$ for all test cases does not exceed $1,000$
Subtask #2 (70 points): original constraints
----- Sample Input 1 ------
1
4 5
5 7
9 10
2 3
20 30
5
6
7
35
1
----- Sample Output 1 ------
0
0
2
-1
1
----- explanation 1 ------
Query $1$: The person coming at time $5$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $2$: The person coming at time $6$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $3$: The person coming at time $7$ has to wait since the restaurant is closed at time $7$. The next slot in which the restaurant opens is $[9,10)$. Thus, the person waits for $2$ units of time.
Query $4$: The person coming at time $35$ has to wait forever as the restaurant does not open after time $30$. | def least_greater_than(a, N, key):
start = 0
end = N
ans = -1
while end >= start:
mid = (start + end) // 2
if mid >= N or mid < 0:
break
elif a[mid][1] <= key:
start = mid + 1
elif a[mid][1] > key:
ans = mid
end = mid - 1
return ans
T = int(input())
ans = []
for _ in range(T):
N, M = [int(i) for i in input().split()]
L = []
R = []
P = []
A = []
for i in range(N):
l, r = [int(i) for i in input().split()]
A.append([l, r])
A.sort()
for i in range(M):
p = int(input())
x = least_greater_than(A, N, p)
if x == -1:
ans.append(-1)
elif p >= A[x][0]:
ans.append(0)
else:
ans.append(A[x][0] - p)
for i in ans:
print(i) | FUNC_DEF 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 NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR |
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well.
Chef is a cook and he has recently opened a restaurant.
The restaurant is open during $N$ time intervals $[L_{1}, R_{1}), [L_{2}, R_{2}), \dots, [L_{N}, R_{N})$. No two of these intervals overlap β formally, for each valid $i$, $j$ such that $i \neq j$, either $R_{i} < L_{j}$ or $R_{j} < L_{i}$.
$M$ people (numbered $1$ through $M$) are planning to eat at the restaurant; let's denote the time when the $i$-th person arrives by $P_{i}$. If the restaurant is open at that time, this person does not have to wait, but if it is closed, this person will wait until it is open. Note that if this person arrives at an exact time when the restaurant is closing, they have to wait for the next opening time.
For each person, calculate how long they have to wait (possibly $0$ time), or determine that they will wait forever for the restaurant to open.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of the input contains two space-separated integers $N$ and $M$.
$N$ lines follow. For each valid $i$, the $i$-th of these lines contains two space-separated integers $L_{i}$ and $R_{i}$.
$M$ lines follow. For each valid $i$, the $i$-th of these lines contains a single integer $P_{i}$.
------ Output ------
For each test case, print $M$ lines. For each valid $i$, the $i$-th of these lines should contain a single integer β the time person $i$ has to wait, or $-1$ if person $i$ has to wait forever.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N, M β€ 10^{5}$
$1 β€ L_{i} < R_{i} β€ 10^{9}$ for each valid $i$
$1 β€ P_{i} β€ 10^{9}$ for each valid $i$
the intervals are pairwise disjoint
the sum of $N$ for all test cases does not exceed $3 \cdot 10^{5}$
the sum of $M$ for all test cases does not exceed $3 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (30 points):
the sum of $N$ for all test cases does not exceed $1,000$
the sum of $M$ for all test cases does not exceed $1,000$
Subtask #2 (70 points): original constraints
----- Sample Input 1 ------
1
4 5
5 7
9 10
2 3
20 30
5
6
7
35
1
----- Sample Output 1 ------
0
0
2
-1
1
----- explanation 1 ------
Query $1$: The person coming at time $5$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $2$: The person coming at time $6$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $3$: The person coming at time $7$ has to wait since the restaurant is closed at time $7$. The next slot in which the restaurant opens is $[9,10)$. Thus, the person waits for $2$ units of time.
Query $4$: The person coming at time $35$ has to wait forever as the restaurant does not open after time $30$. | def binarySearch(arr, target, end):
start = 0
ans = end + 1
while start <= end:
mid = start + (end - start) // 2
if arr[mid][0] < target:
start = mid + 1
else:
ans = mid
end = mid - 1
return ans
tests = int(input().strip())
for t in range(tests):
n, m = [int(x) for x in input().strip().split()]
intervals = [0] * n
for i in range(n):
x, y = input().strip().split()
intervals[i] = int(x), int(y)
intervals.sort(key=lambda x: x[0])
persons = [0] * m
for i in range(m):
persons[i] = int(input().strip())
for p in persons:
index = binarySearch(intervals, p, n - 1)
ans = -1
if index == 0:
ans = intervals[index][0] - p
elif intervals[index - 1][1] > p:
ans = 0
elif index < n:
ans = intervals[index][0] - p
print(ans) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well.
Chef is a cook and he has recently opened a restaurant.
The restaurant is open during $N$ time intervals $[L_{1}, R_{1}), [L_{2}, R_{2}), \dots, [L_{N}, R_{N})$. No two of these intervals overlap β formally, for each valid $i$, $j$ such that $i \neq j$, either $R_{i} < L_{j}$ or $R_{j} < L_{i}$.
$M$ people (numbered $1$ through $M$) are planning to eat at the restaurant; let's denote the time when the $i$-th person arrives by $P_{i}$. If the restaurant is open at that time, this person does not have to wait, but if it is closed, this person will wait until it is open. Note that if this person arrives at an exact time when the restaurant is closing, they have to wait for the next opening time.
For each person, calculate how long they have to wait (possibly $0$ time), or determine that they will wait forever for the restaurant to open.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of the input contains two space-separated integers $N$ and $M$.
$N$ lines follow. For each valid $i$, the $i$-th of these lines contains two space-separated integers $L_{i}$ and $R_{i}$.
$M$ lines follow. For each valid $i$, the $i$-th of these lines contains a single integer $P_{i}$.
------ Output ------
For each test case, print $M$ lines. For each valid $i$, the $i$-th of these lines should contain a single integer β the time person $i$ has to wait, or $-1$ if person $i$ has to wait forever.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N, M β€ 10^{5}$
$1 β€ L_{i} < R_{i} β€ 10^{9}$ for each valid $i$
$1 β€ P_{i} β€ 10^{9}$ for each valid $i$
the intervals are pairwise disjoint
the sum of $N$ for all test cases does not exceed $3 \cdot 10^{5}$
the sum of $M$ for all test cases does not exceed $3 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (30 points):
the sum of $N$ for all test cases does not exceed $1,000$
the sum of $M$ for all test cases does not exceed $1,000$
Subtask #2 (70 points): original constraints
----- Sample Input 1 ------
1
4 5
5 7
9 10
2 3
20 30
5
6
7
35
1
----- Sample Output 1 ------
0
0
2
-1
1
----- explanation 1 ------
Query $1$: The person coming at time $5$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $2$: The person coming at time $6$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $3$: The person coming at time $7$ has to wait since the restaurant is closed at time $7$. The next slot in which the restaurant opens is $[9,10)$. Thus, the person waits for $2$ units of time.
Query $4$: The person coming at time $35$ has to wait forever as the restaurant does not open after time $30$. | def fun(ar, x):
l = 0
u = len(ar)
an = -1
while l <= u:
m = (l + u) // 2
if m >= len(ar) or m < 0:
return an
s, e = ar[m][0], ar[m][1]
if x >= e:
l = m + 1
elif e > x:
an = m
u = m - 1
return an
for _ in range(int(input())):
n, m = map(int, input().split())
ar = []
for i in range(n):
l, r = map(int, input().split())
ar.append([l, r])
ar.sort()
for i in range(m):
x = int(input())
an = fun(ar, x)
if an == -1:
print(an)
elif x >= ar[an][0]:
print(0)
else:
print(ar[an][0] - x) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR |
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well.
Chef is a cook and he has recently opened a restaurant.
The restaurant is open during $N$ time intervals $[L_{1}, R_{1}), [L_{2}, R_{2}), \dots, [L_{N}, R_{N})$. No two of these intervals overlap β formally, for each valid $i$, $j$ such that $i \neq j$, either $R_{i} < L_{j}$ or $R_{j} < L_{i}$.
$M$ people (numbered $1$ through $M$) are planning to eat at the restaurant; let's denote the time when the $i$-th person arrives by $P_{i}$. If the restaurant is open at that time, this person does not have to wait, but if it is closed, this person will wait until it is open. Note that if this person arrives at an exact time when the restaurant is closing, they have to wait for the next opening time.
For each person, calculate how long they have to wait (possibly $0$ time), or determine that they will wait forever for the restaurant to open.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of the input contains two space-separated integers $N$ and $M$.
$N$ lines follow. For each valid $i$, the $i$-th of these lines contains two space-separated integers $L_{i}$ and $R_{i}$.
$M$ lines follow. For each valid $i$, the $i$-th of these lines contains a single integer $P_{i}$.
------ Output ------
For each test case, print $M$ lines. For each valid $i$, the $i$-th of these lines should contain a single integer β the time person $i$ has to wait, or $-1$ if person $i$ has to wait forever.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N, M β€ 10^{5}$
$1 β€ L_{i} < R_{i} β€ 10^{9}$ for each valid $i$
$1 β€ P_{i} β€ 10^{9}$ for each valid $i$
the intervals are pairwise disjoint
the sum of $N$ for all test cases does not exceed $3 \cdot 10^{5}$
the sum of $M$ for all test cases does not exceed $3 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (30 points):
the sum of $N$ for all test cases does not exceed $1,000$
the sum of $M$ for all test cases does not exceed $1,000$
Subtask #2 (70 points): original constraints
----- Sample Input 1 ------
1
4 5
5 7
9 10
2 3
20 30
5
6
7
35
1
----- Sample Output 1 ------
0
0
2
-1
1
----- explanation 1 ------
Query $1$: The person coming at time $5$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $2$: The person coming at time $6$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $3$: The person coming at time $7$ has to wait since the restaurant is closed at time $7$. The next slot in which the restaurant opens is $[9,10)$. Thus, the person waits for $2$ units of time.
Query $4$: The person coming at time $35$ has to wait forever as the restaurant does not open after time $30$. | def solve(times, people):
l, r = 0, len(times) - 1
ans = -1
while l <= r:
mid = (l + r) // 2
if times[mid][1] > people:
ans = mid
r = mid - 1
else:
l = mid + 1
if ans == -1:
return ans
return max(0, times[ans][0] - people)
for _ in range(int(input())):
n, m = map(int, input().split())
times = []
for t in range(n):
e, q = map(int, input().split())
times.append([e, q])
times.sort()
for t in range(m):
people = int(input())
print(solve(times, people)) | FUNC_DEF ASSIGN VAR VAR NUMBER 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 NUMBER VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well.
Chef is a cook and he has recently opened a restaurant.
The restaurant is open during $N$ time intervals $[L_{1}, R_{1}), [L_{2}, R_{2}), \dots, [L_{N}, R_{N})$. No two of these intervals overlap β formally, for each valid $i$, $j$ such that $i \neq j$, either $R_{i} < L_{j}$ or $R_{j} < L_{i}$.
$M$ people (numbered $1$ through $M$) are planning to eat at the restaurant; let's denote the time when the $i$-th person arrives by $P_{i}$. If the restaurant is open at that time, this person does not have to wait, but if it is closed, this person will wait until it is open. Note that if this person arrives at an exact time when the restaurant is closing, they have to wait for the next opening time.
For each person, calculate how long they have to wait (possibly $0$ time), or determine that they will wait forever for the restaurant to open.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of the input contains two space-separated integers $N$ and $M$.
$N$ lines follow. For each valid $i$, the $i$-th of these lines contains two space-separated integers $L_{i}$ and $R_{i}$.
$M$ lines follow. For each valid $i$, the $i$-th of these lines contains a single integer $P_{i}$.
------ Output ------
For each test case, print $M$ lines. For each valid $i$, the $i$-th of these lines should contain a single integer β the time person $i$ has to wait, or $-1$ if person $i$ has to wait forever.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N, M β€ 10^{5}$
$1 β€ L_{i} < R_{i} β€ 10^{9}$ for each valid $i$
$1 β€ P_{i} β€ 10^{9}$ for each valid $i$
the intervals are pairwise disjoint
the sum of $N$ for all test cases does not exceed $3 \cdot 10^{5}$
the sum of $M$ for all test cases does not exceed $3 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (30 points):
the sum of $N$ for all test cases does not exceed $1,000$
the sum of $M$ for all test cases does not exceed $1,000$
Subtask #2 (70 points): original constraints
----- Sample Input 1 ------
1
4 5
5 7
9 10
2 3
20 30
5
6
7
35
1
----- Sample Output 1 ------
0
0
2
-1
1
----- explanation 1 ------
Query $1$: The person coming at time $5$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $2$: The person coming at time $6$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $3$: The person coming at time $7$ has to wait since the restaurant is closed at time $7$. The next slot in which the restaurant opens is $[9,10)$. Thus, the person waits for $2$ units of time.
Query $4$: The person coming at time $35$ has to wait forever as the restaurant does not open after time $30$. | t = int(input().strip())
def findRight(arr, start, end, num):
if start > end:
return -1
if start == end:
return start
mid = int((start + end) / 2)
if arr[mid] == num:
return mid
if num > arr[mid]:
return findRight(arr, mid + 1, end, num)
else:
return findRight(arr, start, mid, num)
for _ in range(t):
hashmap = {}
l = []
N, M = [int(n) for n in input().strip().split()]
for _ in range(N):
low, high = [int(n) for n in input().strip().split()]
hashmap[low] = high
l.append(low)
l.sort()
for _ in range(M):
num = int(input().strip())
index = findRight(l, 0, N - 1, num)
if l[index] == num:
print(0)
elif num < l[0]:
print(l[0] - num)
elif num >= hashmap[l[-1]]:
print(-1)
elif num > l[index]:
print(0)
else:
x = hashmap[l[index - 1]]
if num >= x:
print(abs(l[index] - num))
else:
print(0) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN VAR IF VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER |
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well.
Chef is a cook and he has recently opened a restaurant.
The restaurant is open during $N$ time intervals $[L_{1}, R_{1}), [L_{2}, R_{2}), \dots, [L_{N}, R_{N})$. No two of these intervals overlap β formally, for each valid $i$, $j$ such that $i \neq j$, either $R_{i} < L_{j}$ or $R_{j} < L_{i}$.
$M$ people (numbered $1$ through $M$) are planning to eat at the restaurant; let's denote the time when the $i$-th person arrives by $P_{i}$. If the restaurant is open at that time, this person does not have to wait, but if it is closed, this person will wait until it is open. Note that if this person arrives at an exact time when the restaurant is closing, they have to wait for the next opening time.
For each person, calculate how long they have to wait (possibly $0$ time), or determine that they will wait forever for the restaurant to open.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of the input contains two space-separated integers $N$ and $M$.
$N$ lines follow. For each valid $i$, the $i$-th of these lines contains two space-separated integers $L_{i}$ and $R_{i}$.
$M$ lines follow. For each valid $i$, the $i$-th of these lines contains a single integer $P_{i}$.
------ Output ------
For each test case, print $M$ lines. For each valid $i$, the $i$-th of these lines should contain a single integer β the time person $i$ has to wait, or $-1$ if person $i$ has to wait forever.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N, M β€ 10^{5}$
$1 β€ L_{i} < R_{i} β€ 10^{9}$ for each valid $i$
$1 β€ P_{i} β€ 10^{9}$ for each valid $i$
the intervals are pairwise disjoint
the sum of $N$ for all test cases does not exceed $3 \cdot 10^{5}$
the sum of $M$ for all test cases does not exceed $3 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (30 points):
the sum of $N$ for all test cases does not exceed $1,000$
the sum of $M$ for all test cases does not exceed $1,000$
Subtask #2 (70 points): original constraints
----- Sample Input 1 ------
1
4 5
5 7
9 10
2 3
20 30
5
6
7
35
1
----- Sample Output 1 ------
0
0
2
-1
1
----- explanation 1 ------
Query $1$: The person coming at time $5$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $2$: The person coming at time $6$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $3$: The person coming at time $7$ has to wait since the restaurant is closed at time $7$. The next slot in which the restaurant opens is $[9,10)$. Thus, the person waits for $2$ units of time.
Query $4$: The person coming at time $35$ has to wait forever as the restaurant does not open after time $30$. | def binary(a, q, n):
i = 0
j = n - 1
ans = -1
while i <= j:
mid = (i + j) // 2
if q >= a[mid][1]:
i = mid + 1
else:
ans = mid
j = mid - 1
return ans
def total_wait(a, n, t):
a.sort(key=lambda a: a[0])
while t:
t -= 1
q = int(input())
pos = binary(a, q, n)
if pos == -1 or q > a[pos][1]:
print(-1)
elif a[pos][0] <= q < a[pos][1]:
print("0")
else:
print(a[pos][0] - q)
t = int(input())
while t:
t -= 1
n, m = map(int, input().split())
a = []
for i in range(n):
l = []
i, j = map(int, input().split())
l.append(i)
l.append(j)
a.append(l)
total_wait(a, n, m) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR |
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well.
Chef is a cook and he has recently opened a restaurant.
The restaurant is open during $N$ time intervals $[L_{1}, R_{1}), [L_{2}, R_{2}), \dots, [L_{N}, R_{N})$. No two of these intervals overlap β formally, for each valid $i$, $j$ such that $i \neq j$, either $R_{i} < L_{j}$ or $R_{j} < L_{i}$.
$M$ people (numbered $1$ through $M$) are planning to eat at the restaurant; let's denote the time when the $i$-th person arrives by $P_{i}$. If the restaurant is open at that time, this person does not have to wait, but if it is closed, this person will wait until it is open. Note that if this person arrives at an exact time when the restaurant is closing, they have to wait for the next opening time.
For each person, calculate how long they have to wait (possibly $0$ time), or determine that they will wait forever for the restaurant to open.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of the input contains two space-separated integers $N$ and $M$.
$N$ lines follow. For each valid $i$, the $i$-th of these lines contains two space-separated integers $L_{i}$ and $R_{i}$.
$M$ lines follow. For each valid $i$, the $i$-th of these lines contains a single integer $P_{i}$.
------ Output ------
For each test case, print $M$ lines. For each valid $i$, the $i$-th of these lines should contain a single integer β the time person $i$ has to wait, or $-1$ if person $i$ has to wait forever.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N, M β€ 10^{5}$
$1 β€ L_{i} < R_{i} β€ 10^{9}$ for each valid $i$
$1 β€ P_{i} β€ 10^{9}$ for each valid $i$
the intervals are pairwise disjoint
the sum of $N$ for all test cases does not exceed $3 \cdot 10^{5}$
the sum of $M$ for all test cases does not exceed $3 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (30 points):
the sum of $N$ for all test cases does not exceed $1,000$
the sum of $M$ for all test cases does not exceed $1,000$
Subtask #2 (70 points): original constraints
----- Sample Input 1 ------
1
4 5
5 7
9 10
2 3
20 30
5
6
7
35
1
----- Sample Output 1 ------
0
0
2
-1
1
----- explanation 1 ------
Query $1$: The person coming at time $5$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $2$: The person coming at time $6$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $3$: The person coming at time $7$ has to wait since the restaurant is closed at time $7$. The next slot in which the restaurant opens is $[9,10)$. Thus, the person waits for $2$ units of time.
Query $4$: The person coming at time $35$ has to wait forever as the restaurant does not open after time $30$. | t = int(input())
for _ in range(t):
n, m = list(map(int, input().split()))
lr = []
for _ in range(n):
a, b = list(map(int, input().split()))
lr.append([a, b])
p = []
for _ in range(m):
p.append(int(input()))
lr.sort(key=lambda x: x[0])
for myTime in p:
start = 0
end = n - 1
while start <= end:
if start == end:
if myTime >= lr[start][1]:
print(-1)
break
elif myTime >= lr[start][0]:
print(0)
break
else:
print(lr[start][0] - myTime)
break
mid = (start + end) // 2
if myTime >= lr[mid][1]:
start = mid + 1
elif myTime < lr[mid][0]:
end = mid
else:
print(0)
break | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR NUMBER |
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well.
Chef is a cook and he has recently opened a restaurant.
The restaurant is open during $N$ time intervals $[L_{1}, R_{1}), [L_{2}, R_{2}), \dots, [L_{N}, R_{N})$. No two of these intervals overlap β formally, for each valid $i$, $j$ such that $i \neq j$, either $R_{i} < L_{j}$ or $R_{j} < L_{i}$.
$M$ people (numbered $1$ through $M$) are planning to eat at the restaurant; let's denote the time when the $i$-th person arrives by $P_{i}$. If the restaurant is open at that time, this person does not have to wait, but if it is closed, this person will wait until it is open. Note that if this person arrives at an exact time when the restaurant is closing, they have to wait for the next opening time.
For each person, calculate how long they have to wait (possibly $0$ time), or determine that they will wait forever for the restaurant to open.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of the input contains two space-separated integers $N$ and $M$.
$N$ lines follow. For each valid $i$, the $i$-th of these lines contains two space-separated integers $L_{i}$ and $R_{i}$.
$M$ lines follow. For each valid $i$, the $i$-th of these lines contains a single integer $P_{i}$.
------ Output ------
For each test case, print $M$ lines. For each valid $i$, the $i$-th of these lines should contain a single integer β the time person $i$ has to wait, or $-1$ if person $i$ has to wait forever.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N, M β€ 10^{5}$
$1 β€ L_{i} < R_{i} β€ 10^{9}$ for each valid $i$
$1 β€ P_{i} β€ 10^{9}$ for each valid $i$
the intervals are pairwise disjoint
the sum of $N$ for all test cases does not exceed $3 \cdot 10^{5}$
the sum of $M$ for all test cases does not exceed $3 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (30 points):
the sum of $N$ for all test cases does not exceed $1,000$
the sum of $M$ for all test cases does not exceed $1,000$
Subtask #2 (70 points): original constraints
----- Sample Input 1 ------
1
4 5
5 7
9 10
2 3
20 30
5
6
7
35
1
----- Sample Output 1 ------
0
0
2
-1
1
----- explanation 1 ------
Query $1$: The person coming at time $5$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $2$: The person coming at time $6$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $3$: The person coming at time $7$ has to wait since the restaurant is closed at time $7$. The next slot in which the restaurant opens is $[9,10)$. Thus, the person waits for $2$ units of time.
Query $4$: The person coming at time $35$ has to wait forever as the restaurant does not open after time $30$. | def binarySearch(time, data):
i = 0
j = len(time) - 1
while i <= j:
m = (i + j) // 2
if time[m][0] < data:
i = m + 1
elif time[m][0] > data:
j = m - 1
else:
return m
return j
test = int(input())
for _ in range(test):
n, m = map(int, input().split())
time = []
for i in range(n):
temp = list(map(int, input().split()))
time.append(temp)
time = sorted(time, key=lambda item: item[0])
for i in range(m):
data = int(input())
if data < time[0][0]:
print(time[0][0] - data)
else:
index = binarySearch(time, data)
if time[index][1] > data:
print(0)
elif index < n - 1:
print(time[index + 1][0] - data)
else:
print(-1) | 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 NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR NUMBER |
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well.
Chef is a cook and he has recently opened a restaurant.
The restaurant is open during $N$ time intervals $[L_{1}, R_{1}), [L_{2}, R_{2}), \dots, [L_{N}, R_{N})$. No two of these intervals overlap β formally, for each valid $i$, $j$ such that $i \neq j$, either $R_{i} < L_{j}$ or $R_{j} < L_{i}$.
$M$ people (numbered $1$ through $M$) are planning to eat at the restaurant; let's denote the time when the $i$-th person arrives by $P_{i}$. If the restaurant is open at that time, this person does not have to wait, but if it is closed, this person will wait until it is open. Note that if this person arrives at an exact time when the restaurant is closing, they have to wait for the next opening time.
For each person, calculate how long they have to wait (possibly $0$ time), or determine that they will wait forever for the restaurant to open.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of the input contains two space-separated integers $N$ and $M$.
$N$ lines follow. For each valid $i$, the $i$-th of these lines contains two space-separated integers $L_{i}$ and $R_{i}$.
$M$ lines follow. For each valid $i$, the $i$-th of these lines contains a single integer $P_{i}$.
------ Output ------
For each test case, print $M$ lines. For each valid $i$, the $i$-th of these lines should contain a single integer β the time person $i$ has to wait, or $-1$ if person $i$ has to wait forever.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N, M β€ 10^{5}$
$1 β€ L_{i} < R_{i} β€ 10^{9}$ for each valid $i$
$1 β€ P_{i} β€ 10^{9}$ for each valid $i$
the intervals are pairwise disjoint
the sum of $N$ for all test cases does not exceed $3 \cdot 10^{5}$
the sum of $M$ for all test cases does not exceed $3 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (30 points):
the sum of $N$ for all test cases does not exceed $1,000$
the sum of $M$ for all test cases does not exceed $1,000$
Subtask #2 (70 points): original constraints
----- Sample Input 1 ------
1
4 5
5 7
9 10
2 3
20 30
5
6
7
35
1
----- Sample Output 1 ------
0
0
2
-1
1
----- explanation 1 ------
Query $1$: The person coming at time $5$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $2$: The person coming at time $6$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $3$: The person coming at time $7$ has to wait since the restaurant is closed at time $7$. The next slot in which the restaurant opens is $[9,10)$. Thus, the person waits for $2$ units of time.
Query $4$: The person coming at time $35$ has to wait forever as the restaurant does not open after time $30$. | def merge(arr, start, mid, end):
i = start
j = mid
k = 0
temp = [0] * (end - start + 1)
while i < mid and j <= end:
if arr[i][0] <= arr[j][0]:
temp[k] = arr[i]
i += 1
k += 1
else:
temp[k] = arr[j]
j += 1
k += 1
while i < mid:
temp[k] = arr[i]
i += 1
k += 1
while j <= end:
temp[k] = arr[j]
j += 1
k += 1
k = 0
for i in range(start, end + 1):
arr[i] = temp[k]
k += 1
def merge_sort(arr, first, last):
if first >= last:
return
mid = first + (last - first) // 2
merge_sort(arr, first, mid)
merge_sort(arr, mid + 1, last)
merge(arr, first, mid + 1, last)
def binarySearch(arr, target, end):
start = 0
ans = end + 1
while start <= end:
mid = start + (end - start) // 2
if arr[mid][0] < target:
start = mid + 1
else:
ans = mid
end = mid - 1
return ans
tests = int(input().strip())
for t in range(tests):
n, m = [int(x) for x in input().strip().split()]
intervals = [0] * n
for i in range(n):
x, y = input().strip().split()
intervals[i] = int(x), int(y)
merge_sort(intervals, 0, n - 1)
persons = [0] * m
for i in range(m):
persons[i] = int(input().strip())
for p in persons:
index = binarySearch(intervals, p, n - 1)
ans = -1
if index == 0:
ans = intervals[index][0] - p
elif intervals[index - 1][1] > p:
ans = 0
elif index < n:
ans = intervals[index][0] - p
print(ans) | FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER FUNC_DEF IF VAR VAR RETURN ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well.
Chef is a cook and he has recently opened a restaurant.
The restaurant is open during $N$ time intervals $[L_{1}, R_{1}), [L_{2}, R_{2}), \dots, [L_{N}, R_{N})$. No two of these intervals overlap β formally, for each valid $i$, $j$ such that $i \neq j$, either $R_{i} < L_{j}$ or $R_{j} < L_{i}$.
$M$ people (numbered $1$ through $M$) are planning to eat at the restaurant; let's denote the time when the $i$-th person arrives by $P_{i}$. If the restaurant is open at that time, this person does not have to wait, but if it is closed, this person will wait until it is open. Note that if this person arrives at an exact time when the restaurant is closing, they have to wait for the next opening time.
For each person, calculate how long they have to wait (possibly $0$ time), or determine that they will wait forever for the restaurant to open.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of the input contains two space-separated integers $N$ and $M$.
$N$ lines follow. For each valid $i$, the $i$-th of these lines contains two space-separated integers $L_{i}$ and $R_{i}$.
$M$ lines follow. For each valid $i$, the $i$-th of these lines contains a single integer $P_{i}$.
------ Output ------
For each test case, print $M$ lines. For each valid $i$, the $i$-th of these lines should contain a single integer β the time person $i$ has to wait, or $-1$ if person $i$ has to wait forever.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N, M β€ 10^{5}$
$1 β€ L_{i} < R_{i} β€ 10^{9}$ for each valid $i$
$1 β€ P_{i} β€ 10^{9}$ for each valid $i$
the intervals are pairwise disjoint
the sum of $N$ for all test cases does not exceed $3 \cdot 10^{5}$
the sum of $M$ for all test cases does not exceed $3 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (30 points):
the sum of $N$ for all test cases does not exceed $1,000$
the sum of $M$ for all test cases does not exceed $1,000$
Subtask #2 (70 points): original constraints
----- Sample Input 1 ------
1
4 5
5 7
9 10
2 3
20 30
5
6
7
35
1
----- Sample Output 1 ------
0
0
2
-1
1
----- explanation 1 ------
Query $1$: The person coming at time $5$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $2$: The person coming at time $6$ does not have to wait as the restaurant is open in $[5,7)$ slot.
Query $3$: The person coming at time $7$ has to wait since the restaurant is closed at time $7$. The next slot in which the restaurant opens is $[9,10)$. Thus, the person waits for $2$ units of time.
Query $4$: The person coming at time $35$ has to wait forever as the restaurant does not open after time $30$. | def searchP(p, arr, n):
low, high = 0, n - 1
ans = -1
while low <= high:
mid = low + (high - low) // 2
if arr[mid][1] > p:
ans = mid
high = mid - 1
else:
low = mid + 1
if ans == -1:
return -1
return max(0, arr[ans][0] - p)
t = int(input())
for tc in range(t):
n, m = map(int, input().split())
arr = [[int(j) for j in input().split()] for i in range(n)]
arr.sort()
for i in range(m):
wt = 0
p = int(input())
wt = searchP(p, arr, n)
print(wt) | FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR 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 VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.
Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a_1 β€ a_2 β€ ... β€ a_{n}; a_1 β₯ a_2 β₯ ... β₯ a_{n}.
Help Petya find the two required positions to swap or else say that they do not exist.
-----Input-----
The first line contains a single integer n (1 β€ n β€ 10^5). The second line contains n non-negative space-separated integers a_1, a_2, ..., a_{n} β the elements of the array that Petya's mother presented him. All integers in the input do not exceed 10^9.
-----Output-----
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
-----Examples-----
Input
1
1
Output
-1
Input
2
1 2
Output
-1
Input
4
1 2 3 4
Output
1 2
Input
3
1 1 1
Output
-1
-----Note-----
In the first two samples the required pairs obviously don't exist.
In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted. | import sys
def solve():
(n,) = rv()
(a,) = rl(1)
for i in range(min(10, n - 1)):
for j in range(max(i + 1, n - 10), n):
if a[i] != a[j]:
a[i], a[j] = a[j], a[i]
if notsorted(a):
print(i + 1, j + 1)
return
a[i], a[j] = a[j], a[i]
count = 0
for i in range(n - 1):
if a[i] != a[i + 1]:
a[i], a[i + 1] = a[i + 1], a[i]
if notsorted(a):
print(i + 1, i + 2)
return
a[i], a[i + 1] = a[i + 1], a[i]
count += 1
if count == 100:
break
print(-1)
def notsorted(a):
first, second = True, True
for i in range(len(a) - 1):
if a[i] > a[i + 1]:
first = False
break
for i in range(len(a) - 1):
if a[i] < a[i + 1]:
second = False
break
return True if not first and not second else False
def prt(l):
return print("".join(l))
def rv():
return map(int, input().split())
def rl(n):
return [list(map(int, input().split())) for _ in range(n)]
if sys.hexversion == 50594544:
sys.stdin = open("test.txt")
solve() | IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER RETURN VAR VAR NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR |
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.
Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a_1 β€ a_2 β€ ... β€ a_{n}; a_1 β₯ a_2 β₯ ... β₯ a_{n}.
Help Petya find the two required positions to swap or else say that they do not exist.
-----Input-----
The first line contains a single integer n (1 β€ n β€ 10^5). The second line contains n non-negative space-separated integers a_1, a_2, ..., a_{n} β the elements of the array that Petya's mother presented him. All integers in the input do not exceed 10^9.
-----Output-----
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
-----Examples-----
Input
1
1
Output
-1
Input
2
1 2
Output
-1
Input
4
1 2 3 4
Output
1 2
Input
3
1 1 1
Output
-1
-----Note-----
In the first two samples the required pairs obviously don't exist.
In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted. | n = int(input())
lis = list(map(int, input().split()))
sor = sorted(lis)
res = sor[::-1]
for i in range(1, n):
if lis[i - 1] == lis[i]:
continue
for j in range(i - 1, n):
if lis[i] != lis[j]:
lis[i], lis[j] = lis[j], lis[i]
if lis != sor and lis != res:
print(i + 1, j + 1)
exit()
lis[i], lis[j] = lis[j], lis[i]
i += 1
print(-1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER |
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.
Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a_1 β€ a_2 β€ ... β€ a_{n}; a_1 β₯ a_2 β₯ ... β₯ a_{n}.
Help Petya find the two required positions to swap or else say that they do not exist.
-----Input-----
The first line contains a single integer n (1 β€ n β€ 10^5). The second line contains n non-negative space-separated integers a_1, a_2, ..., a_{n} β the elements of the array that Petya's mother presented him. All integers in the input do not exceed 10^9.
-----Output-----
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
-----Examples-----
Input
1
1
Output
-1
Input
2
1 2
Output
-1
Input
4
1 2 3 4
Output
1 2
Input
3
1 1 1
Output
-1
-----Note-----
In the first two samples the required pairs obviously don't exist.
In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted. | n = int(input())
t = list(map(int, input().split()))
if n < 3 or n == 3 and t[0] == t[2] or all(i == t[0] for i in t):
print(-1)
else:
i = 1
while t[i] == t[i - 1]:
i += 1
if i > 1:
print("2 " + str(i + 1))
elif t[0] < t[1]:
if t[1] <= t[2]:
print("1 2")
elif t[0] == t[2]:
if t[0] == t[3]:
print("2 3")
else:
print("3 4")
else:
print("1 3")
elif t[1] >= t[2]:
print("1 2")
elif t[0] == t[2]:
if t[0] == t[3]:
print("2 3")
else:
print("3 4")
else:
print("1 3") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.
Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a_1 β€ a_2 β€ ... β€ a_{n}; a_1 β₯ a_2 β₯ ... β₯ a_{n}.
Help Petya find the two required positions to swap or else say that they do not exist.
-----Input-----
The first line contains a single integer n (1 β€ n β€ 10^5). The second line contains n non-negative space-separated integers a_1, a_2, ..., a_{n} β the elements of the array that Petya's mother presented him. All integers in the input do not exceed 10^9.
-----Output-----
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
-----Examples-----
Input
1
1
Output
-1
Input
2
1 2
Output
-1
Input
4
1 2 3 4
Output
1 2
Input
3
1 1 1
Output
-1
-----Note-----
In the first two samples the required pairs obviously don't exist.
In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted. | n = int(input())
jim = []
p = list(map(int, input().split()))
if n == 1 or n == 2 or len(set(p)) == 1:
print(-1)
elif n == 3 and len(set(p)) == 2:
ka = [x for x in p]
if p[0] == p[-1]:
print(-1)
elif p[0] == p[1]:
print(2, 3)
else:
print(1, 2)
elif len(set(p)) >= 3:
kam = list(set(p))
jim.append(kam[0])
jim.append(kam[1])
jim.append(kam[2])
jim.sort()
da = p.index(jim[0]) + 1
dra = p.index(jim[1]) + 1
dla = p.index(jim[2]) + 1
if dra < da and dra < dla:
print(da, dla)
else:
print(dra, min(da, dla))
else:
ka = [x for x in p]
ka.sort(reverse=True)
ja = sorted(p)
lam = 1
for y in range(n):
if p[y] != p[lam]:
p[y], p[lam] = p[lam], p[y]
if p != ja and p != ka:
print(y + 1, lam + 1)
break
else:
p[y], p[lam] = p[lam], p[y]
else:
pass | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR |
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.
Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a_1 β€ a_2 β€ ... β€ a_{n}; a_1 β₯ a_2 β₯ ... β₯ a_{n}.
Help Petya find the two required positions to swap or else say that they do not exist.
-----Input-----
The first line contains a single integer n (1 β€ n β€ 10^5). The second line contains n non-negative space-separated integers a_1, a_2, ..., a_{n} β the elements of the array that Petya's mother presented him. All integers in the input do not exceed 10^9.
-----Output-----
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
-----Examples-----
Input
1
1
Output
-1
Input
2
1 2
Output
-1
Input
4
1 2 3 4
Output
1 2
Input
3
1 1 1
Output
-1
-----Note-----
In the first two samples the required pairs obviously don't exist.
In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted. | n = int(input())
a = [int(i) for i in input().split()]
b = len(set(a))
c = sorted(a, reverse=True)
if n == 1 or n == 2 or b == 1:
print("-1")
elif n == 3:
if b == 2:
if a[0] == a[2]:
print("-1")
elif a[0] == a[1]:
print("2 3")
else:
print("1 2")
elif a[1] != max(a[0], a[1], a[2]):
print(a.index(c[0]) + 1, "2")
else:
print(a.index(c[2]) + 1, "2")
elif n == 4:
if b == 2:
if a[0] == a[3]:
if a[0] == a[1] or a[0] == a[2]:
print("2 3")
else:
print("1 2")
elif a[0] == a[1]:
if a[0] == a[2]:
print("4 3")
else:
print("2 3")
elif a[0] == a[2]:
print("1 2")
elif a[1] == a[2]:
print("1 2")
elif a[1] == a[3]:
print("1 2")
else:
print("2 3")
elif b == 3:
if c[0] == c[1]:
if a.index(c[3]) != 2:
print(a.index(c[3]) + 1, "3")
elif a.index(c[3]) != 1:
print(a.index(c[3]) + 1, "2")
elif a.index(c[0]) != 2:
print(a.index(c[0]) + 1, "3")
elif a.index(c[0]) != 1:
print(a.index(c[0]) + 1, "2")
elif b == 4:
if a.index(c[0]) != 2:
print(a.index(c[0]) + 1, "3")
elif a.index(c[0]) != 1:
print(a.index(c[0]) + 1, "2")
elif n > 4:
i = 0
while a[i] == a[0]:
i += 1
if i > 3:
print(i + 1, "2")
else:
d = list(a)
for i in range(n - 4):
a.pop()
c = sorted(a, reverse=True)
b = len(set(c))
if b == 2:
if a[0] == a[3]:
if a[0] == a[1] or a[0] == a[2]:
print("2 3")
else:
print("1 2")
elif a[0] == a[1]:
if a[0] == a[2]:
print("4 3")
else:
print("2 3")
elif a[0] == a[2]:
print("1 2")
elif a[1] == a[2]:
print("1 2")
elif a[1] == a[3]:
print("1 2")
else:
print("2 3")
elif b == 3:
if c[0] == c[1]:
if a.index(c[3]) != 2:
print(a.index(c[3]) + 1, "3")
elif a.index(c[3]) != 1:
print(a.index(c[3]) + 1, "2")
elif a.index(c[0]) != 2:
print(a.index(c[0]) + 1, "3")
elif a.index(c[0]) != 1:
print(a.index(c[0]) + 1, "2")
elif b == 4:
if a.index(c[0]) != 2:
print(a.index(c[0]) + 1, "3")
elif a.index(c[0]) != 1:
print(a.index(c[0]) + 1, "2") | ASSIGN VAR FUNC_CALL VAR 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 VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER STRING IF VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER STRING IF FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER STRING IF FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER STRING IF FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER STRING IF VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER STRING IF FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER STRING IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER STRING IF FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER STRING IF FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER STRING IF FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER STRING IF VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER STRING IF FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER STRING |
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.
Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a_1 β€ a_2 β€ ... β€ a_{n}; a_1 β₯ a_2 β₯ ... β₯ a_{n}.
Help Petya find the two required positions to swap or else say that they do not exist.
-----Input-----
The first line contains a single integer n (1 β€ n β€ 10^5). The second line contains n non-negative space-separated integers a_1, a_2, ..., a_{n} β the elements of the array that Petya's mother presented him. All integers in the input do not exceed 10^9.
-----Output-----
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
-----Examples-----
Input
1
1
Output
-1
Input
2
1 2
Output
-1
Input
4
1 2 3 4
Output
1 2
Input
3
1 1 1
Output
-1
-----Note-----
In the first two samples the required pairs obviously don't exist.
In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted. | def list_comp(x, y):
for i in range(0, len(x)):
if x[i] != y[i]:
return False
return True
def main():
n = int(input())
a = list(map(int, input().split(" ")))
if n <= 2:
print(-1)
exit()
b = a.copy()
b.sort()
c = a.copy()
c.sort(reverse=True)
for i in range(1, n):
if a[i] != a[i - 1]:
a[i], a[i - 1] = a[i - 1], a[i]
if list_comp(a, b) or list_comp(a, c):
a[i], a[i - 1] = a[i - 1], a[i]
else:
print(i, i + 1)
exit()
print(-1)
main() | FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR |
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.
Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a_1 β€ a_2 β€ ... β€ a_{n}; a_1 β₯ a_2 β₯ ... β₯ a_{n}.
Help Petya find the two required positions to swap or else say that they do not exist.
-----Input-----
The first line contains a single integer n (1 β€ n β€ 10^5). The second line contains n non-negative space-separated integers a_1, a_2, ..., a_{n} β the elements of the array that Petya's mother presented him. All integers in the input do not exceed 10^9.
-----Output-----
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
-----Examples-----
Input
1
1
Output
-1
Input
2
1 2
Output
-1
Input
4
1 2 3 4
Output
1 2
Input
3
1 1 1
Output
-1
-----Note-----
In the first two samples the required pairs obviously don't exist.
In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted. | n = int(input())
data = list(map(int, input().split()))
mins = [(0) for i in range(n)]
maxs = [(0) for i in range(n)]
mins_back = [(0) for i in range(n)]
maxs_back = [(0) for i in range(n)]
min_ = data[0]
mins[0] = 0
max_ = data[0]
maxs[0] = 0
if n == 2:
print(-1)
exit(0)
for i in range(n):
if data[i] < min_:
min_ = data[i]
mins[i] = i
elif i > 0:
mins[i] = mins[i - 1]
if data[i] > max_:
max_ = data[i]
maxs[i] = i
elif i > 0:
maxs[i] = maxs[i - 1]
for i in range(1, n - 1):
if data[i] != data[mins[i]]:
if mins[i] == i - 1 and data[mins[i]] < data[i + 1]:
print(i + 1, mins[i] + 1)
exit(0)
if data[i - 1] > data[mins[i]] and data[mins[i]] < data[i + 1]:
print(i + 1, mins[i] + 1)
exit(0)
if data[i] != data[maxs[i]]:
if maxs[i] == i - 1 and data[maxs[i]] > data[i + 1]:
print(i + 1, maxs[i] + 1)
exit(0)
if data[i - 1] < data[maxs[i]] and data[maxs[i]] > data[i + 1]:
print(i + 1, maxs[i] + 1)
exit(0)
data = data[::-1]
min_ = data[0]
mins[0] = 0
max_ = data[0]
maxs[0] = 0
for i in range(n):
if data[i] < min_:
min_ = data[i]
mins[i] = i
elif i > 0:
mins[i] = mins[i - 1]
if data[i] > max_:
max_ = data[i]
maxs[i] = i
elif i > 0:
maxs[i] = maxs[i - 1]
for i in range(1, n - 1):
if data[i] != data[mins[i]]:
if mins[i] == i - 1 and data[mins[i]] < data[i + 1]:
print(n - i, n - mins[i])
exit(0)
if data[i - 1] > data[mins[i]] and data[mins[i]] < data[i + 1]:
print(n - i, n - mins[i])
exit(0)
if data[i] != data[maxs[i]]:
if maxs[i] == i - 1 and data[maxs[i]] > data[i + 1]:
print(n - i, n - maxs[i])
exit(0)
if data[i - 1] < data[maxs[i]] and data[maxs[i]] > data[i + 1]:
print(n - i, n - maxs[i])
exit(0)
data[0], data[-1] = data[-1], data[0]
if data[0] == data[-1]:
print(-1)
exit(0)
for i in range(1, n - 1):
if data[i] < data[i - 1] and data[i] < data[i + 1]:
print(1, n)
exit(0)
if data[i] > data[i - 1] and data[i] > data[i + 1]:
print(1, n)
exit(0)
print(-1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER |
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.
Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a_1 β€ a_2 β€ ... β€ a_{n}; a_1 β₯ a_2 β₯ ... β₯ a_{n}.
Help Petya find the two required positions to swap or else say that they do not exist.
-----Input-----
The first line contains a single integer n (1 β€ n β€ 10^5). The second line contains n non-negative space-separated integers a_1, a_2, ..., a_{n} β the elements of the array that Petya's mother presented him. All integers in the input do not exceed 10^9.
-----Output-----
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
-----Examples-----
Input
1
1
Output
-1
Input
2
1 2
Output
-1
Input
4
1 2 3 4
Output
1 2
Input
3
1 1 1
Output
-1
-----Note-----
In the first two samples the required pairs obviously don't exist.
In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted. | n = int(input())
arr = list(map(int, input().split()))
a, b = -1, -1
for i in range(1, n):
if arr[i - 1] == arr[i]:
continue
arr[i - 1], arr[i] = arr[i], arr[i - 1]
up, down = True, True
for j in range(1, n):
if arr[j - 1] < arr[j]:
down = False
if arr[j - 1] > arr[j]:
up = False
if not up and not down:
a, b = i - 1, i
break
arr[i - 1], arr[i] = arr[i], arr[i - 1]
print(-1 if a == -1 else str(a + 1) + " " + str(b + 1)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER |
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.
Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a_1 β€ a_2 β€ ... β€ a_{n}; a_1 β₯ a_2 β₯ ... β₯ a_{n}.
Help Petya find the two required positions to swap or else say that they do not exist.
-----Input-----
The first line contains a single integer n (1 β€ n β€ 10^5). The second line contains n non-negative space-separated integers a_1, a_2, ..., a_{n} β the elements of the array that Petya's mother presented him. All integers in the input do not exceed 10^9.
-----Output-----
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
-----Examples-----
Input
1
1
Output
-1
Input
2
1 2
Output
-1
Input
4
1 2 3 4
Output
1 2
Input
3
1 1 1
Output
-1
-----Note-----
In the first two samples the required pairs obviously don't exist.
In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted. | def hehe(a, n):
if n == 1 or n == 2:
return -1
a1 = list(a)
for i in range(1, n - 1, 1):
if a1[i - 1] == a1[i] == a1[i + 1]:
continue
elif a1[i - 1] <= a1[i] <= a1[i + 1] or a1[i - 1] >= a1[i] >= a1[i + 1]:
if a1[i - 1] == a1[i]:
return [i + 1, i + 2]
elif a1[i] == a1[i + 1]:
return [i, i + 1]
else:
return [i, i + 1]
elif a1[i - 1] < a1[i] > a1[i + 1] or a1[i - 1] > a1[i] < a1[i + 1]:
if a1[i - 1] != a1[i + 1]:
return [i, i + 2]
elif i < n - 2:
if a1[i + 2] == a1[i]:
return [i, i + 1]
return -1
n = int(input())
a = input().split()
a = [int(i) for i in a]
answer = hehe(a, n)
if answer == -1:
print(-1)
else:
print(*answer, sep=" ") | FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR RETURN LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER RETURN LIST VAR BIN_OP VAR NUMBER RETURN LIST VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN LIST VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR RETURN LIST VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR STRING |
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.
Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a_1 β€ a_2 β€ ... β€ a_{n}; a_1 β₯ a_2 β₯ ... β₯ a_{n}.
Help Petya find the two required positions to swap or else say that they do not exist.
-----Input-----
The first line contains a single integer n (1 β€ n β€ 10^5). The second line contains n non-negative space-separated integers a_1, a_2, ..., a_{n} β the elements of the array that Petya's mother presented him. All integers in the input do not exceed 10^9.
-----Output-----
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
-----Examples-----
Input
1
1
Output
-1
Input
2
1 2
Output
-1
Input
4
1 2 3 4
Output
1 2
Input
3
1 1 1
Output
-1
-----Note-----
In the first two samples the required pairs obviously don't exist.
In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted. | import sys
n = int(input())
a = [int(s) for s in input().split()]
for i in range(0, 2):
for j in range(i + 1, n):
if a[i] != a[j]:
r = a[j]
a[j] = a[i]
a[i] = r
lol = True
lol1 = True
for h in range(1, n):
if a[h - 1] > a[h]:
lol = False
if a[h - 1] < a[h]:
lol1 = False
if not lol and not lol1:
print(i + 1, j + 1)
sys.exit()
else:
r = a[j]
a[j] = a[i]
a[i] = r
print(-1) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR NUMBER |
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.
Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a_1 β€ a_2 β€ ... β€ a_{n}; a_1 β₯ a_2 β₯ ... β₯ a_{n}.
Help Petya find the two required positions to swap or else say that they do not exist.
-----Input-----
The first line contains a single integer n (1 β€ n β€ 10^5). The second line contains n non-negative space-separated integers a_1, a_2, ..., a_{n} β the elements of the array that Petya's mother presented him. All integers in the input do not exceed 10^9.
-----Output-----
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
-----Examples-----
Input
1
1
Output
-1
Input
2
1 2
Output
-1
Input
4
1 2 3 4
Output
1 2
Input
3
1 1 1
Output
-1
-----Note-----
In the first two samples the required pairs obviously don't exist.
In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted. | n = int(input())
l = [int(i) for i in input().split()]
if n == 1 or n == 2:
print(-1)
exit()
if len(set(l)) == 1:
print(-1)
exit()
def rev(l):
return all(l[i] >= l[i + 1] for i in range(n - 1))
def srt(l):
return all(l[i] <= l[i + 1] for i in range(n - 1))
if rev(l) or srt(l):
for i in range(1, n):
if l[i] != l[i - 1]:
print(i, i + 1)
exit()
f = 0
cnt = 0
for i in range(1, n):
if l[i] != l[i - 1]:
if cnt == 3:
break
l[i], l[i - 1] = l[i - 1], l[i]
if srt(l) or rev(l):
cnt += 1
l[i], l[i - 1] = l[i - 1], l[i]
else:
print(i, i + 1)
exit()
else:
print(-1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER |
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.
Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a_1 β€ a_2 β€ ... β€ a_{n}; a_1 β₯ a_2 β₯ ... β₯ a_{n}.
Help Petya find the two required positions to swap or else say that they do not exist.
-----Input-----
The first line contains a single integer n (1 β€ n β€ 10^5). The second line contains n non-negative space-separated integers a_1, a_2, ..., a_{n} β the elements of the array that Petya's mother presented him. All integers in the input do not exceed 10^9.
-----Output-----
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
-----Examples-----
Input
1
1
Output
-1
Input
2
1 2
Output
-1
Input
4
1 2 3 4
Output
1 2
Input
3
1 1 1
Output
-1
-----Note-----
In the first two samples the required pairs obviously don't exist.
In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted. | def solve(arr):
if len(arr) <= 2 or len(set(arr)) == 1:
return [-1]
else:
for i in range(len(arr)):
for j in range(i + 1, len(arr)):
if arr[i] != arr[j]:
arr[i], arr[j] = arr[j], arr[i]
if arr != sorted(arr) and arr != list(reversed(sorted(arr))):
return [i + 1, j + 1]
else:
arr[i], arr[j] = arr[j], arr[i]
return [-1]
def __starting_point():
n = int(input())
arr = list(map(int, input().split()))
print(*solve(arr))
__starting_point() | FUNC_DEF IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR RETURN LIST NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
A new strain of flu has broken out. Fortunately, a vaccine was developed very quickly and is now being administered to the public. Your local health clinic is administering this vaccine, but the waiting line is very long.
For safety reasons, people are not allowed to stand very close to each other as the flu is not under control yet. However, many people were not aware of this precaution. A health and safety official recently examined the line and has determined that people need to spread out more in the line so that they are at least T units away from each other. This needs to be done as quickly as possible so we need to calculate the minimum distance D such that it is possible for every person to move at most D units so the distance between any two people is at least T. Specifically, D should be the minimum value such that there are locations x'_{i} so that |x_{i} - x'_{i}| β€ D for each person i and |x'_{i} - x'_{j}| β₯ T for any two distinct people i,j. Furthermore, since nobody can move past the receptionist we must also have that x'_{i} β₯ 0.
The location of each person is given by the number of meters they are standing from the receptionist. When spreading out, people may move either forward or backward in line but nobody may move past the location of the receptionist.
------ Input ------
The first line of input contains a single integer K β€ 30 indicating the number of test cases to follow. Each test case begins with a line containing an integer N (the number of people) and a floating point value T (the minimum distance that should be between people). The location of each person i is described by single floating point value x_{i} which means person i is x_{i} meters from the receptionist. These values appear in non-decreasing order on the following N lines, one value per line.
Bounds: 1 β€ N β€ 10,000 and T and every x_{i} is between 0 and 1,000,000 and is given with at most 3 decimals of precision.
------ Output ------
For each test case, you should output the minimum value of D with exactly 4 decimals of precision on a single line.
----- Sample Input 1 ------
3
2 4
1
2
2 2
1
2
4 1
0
0.5
0.6
2.75
----- Sample Output 1 ------
2.0000
0.5000
1.4000
----- explanation 1 ------
Test case $1$: To maintain a distance of $4$ units, the first person can move to location $0$ and the second can move to location $4$. The maximum distance a person has to move is $2$.
Test case $2$: To maintain a distance of $2$ units, the first person can move to location $0.5$ and the second person can move to location $2.5$. The maximum distance a person has to move is $0.5$.
Test case $3$: To maintain a distance of $1$ unit, the first person does not move, the second moves to location $1$, the third moves to location $2$, and the fourth moves to location $3$. The corresponding distances moved by each of them is $0, 0,5, 1.4,$ and $0.25$ respectively. Thus, the maximum distance moved by any person is $1.4$ moved by the third person. | def check(positions, N, T, mid):
currPos = positions[N - 1] + mid
for i in range(N - 2, -1, -1):
currPos -= T
if currPos > positions[i] + mid:
currPos = positions[i] + mid
elif currPos < positions[i] - mid:
return False
if currPos >= 0.0:
return True
return False
def solve(positions, N, T):
low, high, ans = 0.0, 10000000000.0, 0.0
while high - low > 5e-05:
mid = (low + high) / 2.0
if check(positions, N, T, mid) == True:
ans = mid
high = mid
else:
low = mid
print("%.4f" % ans)
T = int(input())
for _ in range(T):
N, K = map(float, input().split(" "))
N = int(N)
A = []
for i in range(N):
pos = float(input())
A.append(pos)
solve(A, N, K) | FUNC_DEF ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR IF VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR |
A new strain of flu has broken out. Fortunately, a vaccine was developed very quickly and is now being administered to the public. Your local health clinic is administering this vaccine, but the waiting line is very long.
For safety reasons, people are not allowed to stand very close to each other as the flu is not under control yet. However, many people were not aware of this precaution. A health and safety official recently examined the line and has determined that people need to spread out more in the line so that they are at least T units away from each other. This needs to be done as quickly as possible so we need to calculate the minimum distance D such that it is possible for every person to move at most D units so the distance between any two people is at least T. Specifically, D should be the minimum value such that there are locations x'_{i} so that |x_{i} - x'_{i}| β€ D for each person i and |x'_{i} - x'_{j}| β₯ T for any two distinct people i,j. Furthermore, since nobody can move past the receptionist we must also have that x'_{i} β₯ 0.
The location of each person is given by the number of meters they are standing from the receptionist. When spreading out, people may move either forward or backward in line but nobody may move past the location of the receptionist.
------ Input ------
The first line of input contains a single integer K β€ 30 indicating the number of test cases to follow. Each test case begins with a line containing an integer N (the number of people) and a floating point value T (the minimum distance that should be between people). The location of each person i is described by single floating point value x_{i} which means person i is x_{i} meters from the receptionist. These values appear in non-decreasing order on the following N lines, one value per line.
Bounds: 1 β€ N β€ 10,000 and T and every x_{i} is between 0 and 1,000,000 and is given with at most 3 decimals of precision.
------ Output ------
For each test case, you should output the minimum value of D with exactly 4 decimals of precision on a single line.
----- Sample Input 1 ------
3
2 4
1
2
2 2
1
2
4 1
0
0.5
0.6
2.75
----- Sample Output 1 ------
2.0000
0.5000
1.4000
----- explanation 1 ------
Test case $1$: To maintain a distance of $4$ units, the first person can move to location $0$ and the second can move to location $4$. The maximum distance a person has to move is $2$.
Test case $2$: To maintain a distance of $2$ units, the first person can move to location $0.5$ and the second person can move to location $2.5$. The maximum distance a person has to move is $0.5$.
Test case $3$: To maintain a distance of $1$ unit, the first person does not move, the second moves to location $1$, the third moves to location $2$, and the fourth moves to location $3$. The corresponding distances moved by each of them is $0, 0,5, 1.4,$ and $0.25$ respectively. Thus, the maximum distance moved by any person is $1.4$ moved by the third person. | def check(x, n, k, mid):
curr = x[n - 1] + mid
for i in range(n - 2, -1, -1):
curr -= k
if curr > x[i] + mid:
curr = x[i] + mid
elif curr < x[i] - mid:
return False
if curr >= 0.0:
return True
else:
return False
for _ in range(int(input())):
n, k = map(float, input().split(" "))
n = int(n)
x = []
for i in range(n):
pos = float(input())
x.append(pos)
low, high, ans = 0.0, 10000000.0, 0.0
while high - low > 5e-05:
mid = (low + high) / 2.0
if check(x, n, k, mid) == True:
ans = mid
high = mid
else:
low = mid
print("%.4f" % ans) | FUNC_DEF ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR IF VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR |
A new strain of flu has broken out. Fortunately, a vaccine was developed very quickly and is now being administered to the public. Your local health clinic is administering this vaccine, but the waiting line is very long.
For safety reasons, people are not allowed to stand very close to each other as the flu is not under control yet. However, many people were not aware of this precaution. A health and safety official recently examined the line and has determined that people need to spread out more in the line so that they are at least T units away from each other. This needs to be done as quickly as possible so we need to calculate the minimum distance D such that it is possible for every person to move at most D units so the distance between any two people is at least T. Specifically, D should be the minimum value such that there are locations x'_{i} so that |x_{i} - x'_{i}| β€ D for each person i and |x'_{i} - x'_{j}| β₯ T for any two distinct people i,j. Furthermore, since nobody can move past the receptionist we must also have that x'_{i} β₯ 0.
The location of each person is given by the number of meters they are standing from the receptionist. When spreading out, people may move either forward or backward in line but nobody may move past the location of the receptionist.
------ Input ------
The first line of input contains a single integer K β€ 30 indicating the number of test cases to follow. Each test case begins with a line containing an integer N (the number of people) and a floating point value T (the minimum distance that should be between people). The location of each person i is described by single floating point value x_{i} which means person i is x_{i} meters from the receptionist. These values appear in non-decreasing order on the following N lines, one value per line.
Bounds: 1 β€ N β€ 10,000 and T and every x_{i} is between 0 and 1,000,000 and is given with at most 3 decimals of precision.
------ Output ------
For each test case, you should output the minimum value of D with exactly 4 decimals of precision on a single line.
----- Sample Input 1 ------
3
2 4
1
2
2 2
1
2
4 1
0
0.5
0.6
2.75
----- Sample Output 1 ------
2.0000
0.5000
1.4000
----- explanation 1 ------
Test case $1$: To maintain a distance of $4$ units, the first person can move to location $0$ and the second can move to location $4$. The maximum distance a person has to move is $2$.
Test case $2$: To maintain a distance of $2$ units, the first person can move to location $0.5$ and the second person can move to location $2.5$. The maximum distance a person has to move is $0.5$.
Test case $3$: To maintain a distance of $1$ unit, the first person does not move, the second moves to location $1$, the third moves to location $2$, and the fourth moves to location $3$. The corresponding distances moved by each of them is $0, 0,5, 1.4,$ and $0.25$ respectively. Thus, the maximum distance moved by any person is $1.4$ moved by the third person. | tc = int(input())
for k in range(tc):
n, t = input().split()
n, t = int(n), float(t)
arr = []
for j in range(n):
arr.append(float(input()))
l = 0.0
r = 10.0**12
mn = r
while True:
mid = l + (r - l) / 2
if r - l <= 0.0001:
mn = mid
break
right = None
flag = True
for i in range(n - 1, -1, -1):
if i == n - 1:
right = arr[n - 1] + mid - t
elif arr[i] <= right:
pos = min(arr[i] + mid, right)
right = pos - t
else:
pos = max(arr[i] - mid, right)
if pos > right or pos < 0:
flag = False
break
right = pos - t
if flag == True:
r = mid
else:
l = mid
num = str(round(mn, 4)).split(".")
while len(num[1]) < 4:
num[1] += "0"
print(".".join(num)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR WHILE NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER STRING WHILE FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
A new strain of flu has broken out. Fortunately, a vaccine was developed very quickly and is now being administered to the public. Your local health clinic is administering this vaccine, but the waiting line is very long.
For safety reasons, people are not allowed to stand very close to each other as the flu is not under control yet. However, many people were not aware of this precaution. A health and safety official recently examined the line and has determined that people need to spread out more in the line so that they are at least T units away from each other. This needs to be done as quickly as possible so we need to calculate the minimum distance D such that it is possible for every person to move at most D units so the distance between any two people is at least T. Specifically, D should be the minimum value such that there are locations x'_{i} so that |x_{i} - x'_{i}| β€ D for each person i and |x'_{i} - x'_{j}| β₯ T for any two distinct people i,j. Furthermore, since nobody can move past the receptionist we must also have that x'_{i} β₯ 0.
The location of each person is given by the number of meters they are standing from the receptionist. When spreading out, people may move either forward or backward in line but nobody may move past the location of the receptionist.
------ Input ------
The first line of input contains a single integer K β€ 30 indicating the number of test cases to follow. Each test case begins with a line containing an integer N (the number of people) and a floating point value T (the minimum distance that should be between people). The location of each person i is described by single floating point value x_{i} which means person i is x_{i} meters from the receptionist. These values appear in non-decreasing order on the following N lines, one value per line.
Bounds: 1 β€ N β€ 10,000 and T and every x_{i} is between 0 and 1,000,000 and is given with at most 3 decimals of precision.
------ Output ------
For each test case, you should output the minimum value of D with exactly 4 decimals of precision on a single line.
----- Sample Input 1 ------
3
2 4
1
2
2 2
1
2
4 1
0
0.5
0.6
2.75
----- Sample Output 1 ------
2.0000
0.5000
1.4000
----- explanation 1 ------
Test case $1$: To maintain a distance of $4$ units, the first person can move to location $0$ and the second can move to location $4$. The maximum distance a person has to move is $2$.
Test case $2$: To maintain a distance of $2$ units, the first person can move to location $0.5$ and the second person can move to location $2.5$. The maximum distance a person has to move is $0.5$.
Test case $3$: To maintain a distance of $1$ unit, the first person does not move, the second moves to location $1$, the third moves to location $2$, and the fourth moves to location $3$. The corresponding distances moved by each of them is $0, 0,5, 1.4,$ and $0.25$ respectively. Thus, the maximum distance moved by any person is $1.4$ moved by the third person. | def ok(d):
lst = max(0, x[0] - d)
for i in range(1, n):
if x[i] + d < lst + t:
return False
else:
lst = max(x[i] - d, lst + t)
return True
tst = int(input())
for _ in range(tst):
n, t = map(float, input().split(" "))
n = int(n)
x = []
for i in range(n):
p = float(input())
x.append(p)
l = 0.0
r = 1000000000.0
for it in range(1, 60):
mid = (l + r) / 2.0
if ok(mid) == True:
r = mid
else:
l = mid
print("%.4f" % l) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR BIN_OP VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR |
Everyone loves a freebie. Especially students.
It is well-known that if in the night before exam a student opens window, opens the student's record-book and shouts loudly three times "Fly, freebie, fly!" β then flown freebie helps him to pass the upcoming exam.
In the night before the exam on mathematical analysis n students living in dormitory shouted treasured words. The i-th student made a sacrament at the time t_{i}, where t_{i} is the number of seconds elapsed since the beginning of the night.
It is known that the freebie is a capricious and willful lady. That night the freebie was near dormitory only for T seconds. Therefore, if for two students their sacrament times differ for more than T, then the freebie didn't visit at least one of them.
Since all students are optimists, they really want to know what is the maximal number of students visited by the freebie can be.
-----Input-----
The first line of the input contains integer n (1 β€ n β€ 100), where n β the number of students shouted "Fly, freebie, fly!" The second line contains n positive integers t_{i} (1 β€ t_{i} β€ 1000).
The last line contains integer T (1 β€ T β€ 1000) β the time interval during which the freebie was near the dormitory.
-----Output-----
Print a single integer β the largest number of people who will pass exam tomorrow because of the freebie visit.
-----Examples-----
Input
6
4 1 7 8 3 8
1
Output
3 | n = int(input())
a = [int(i) for i in input().split()]
k = int(input())
j = 1
x = []
c = 0
g = 0
a.sort()
for i in range(n):
f = i
j = i + 1
g = 0
c = 0
while g <= k:
if j == n:
break
if g == k and abs(a[f] - a[j]) != 0:
break
elif g + abs(a[f] - a[j]) > k:
break
g += abs(a[f] - a[j])
c += 1
j += 1
f += 1
x.append(c)
print(max(x) + 1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR IF VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER |
Everyone loves a freebie. Especially students.
It is well-known that if in the night before exam a student opens window, opens the student's record-book and shouts loudly three times "Fly, freebie, fly!" β then flown freebie helps him to pass the upcoming exam.
In the night before the exam on mathematical analysis n students living in dormitory shouted treasured words. The i-th student made a sacrament at the time t_{i}, where t_{i} is the number of seconds elapsed since the beginning of the night.
It is known that the freebie is a capricious and willful lady. That night the freebie was near dormitory only for T seconds. Therefore, if for two students their sacrament times differ for more than T, then the freebie didn't visit at least one of them.
Since all students are optimists, they really want to know what is the maximal number of students visited by the freebie can be.
-----Input-----
The first line of the input contains integer n (1 β€ n β€ 100), where n β the number of students shouted "Fly, freebie, fly!" The second line contains n positive integers t_{i} (1 β€ t_{i} β€ 1000).
The last line contains integer T (1 β€ T β€ 1000) β the time interval during which the freebie was near the dormitory.
-----Output-----
Print a single integer β the largest number of people who will pass exam tomorrow because of the freebie visit.
-----Examples-----
Input
6
4 1 7 8 3 8
1
Output
3 | n, v = int(input()), list(sorted(map(int, input().split())))
t = int(input())
ans = 0
for i in range(n):
k = 0
for j in range(i + 1, n):
if v[j] - v[i] <= t:
k += 1
ans = max(ans, k + 1)
print(ans) | ASSIGN VAR VAR FUNC_CALL 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
Everyone loves a freebie. Especially students.
It is well-known that if in the night before exam a student opens window, opens the student's record-book and shouts loudly three times "Fly, freebie, fly!" β then flown freebie helps him to pass the upcoming exam.
In the night before the exam on mathematical analysis n students living in dormitory shouted treasured words. The i-th student made a sacrament at the time t_{i}, where t_{i} is the number of seconds elapsed since the beginning of the night.
It is known that the freebie is a capricious and willful lady. That night the freebie was near dormitory only for T seconds. Therefore, if for two students their sacrament times differ for more than T, then the freebie didn't visit at least one of them.
Since all students are optimists, they really want to know what is the maximal number of students visited by the freebie can be.
-----Input-----
The first line of the input contains integer n (1 β€ n β€ 100), where n β the number of students shouted "Fly, freebie, fly!" The second line contains n positive integers t_{i} (1 β€ t_{i} β€ 1000).
The last line contains integer T (1 β€ T β€ 1000) β the time interval during which the freebie was near the dormitory.
-----Output-----
Print a single integer β the largest number of people who will pass exam tomorrow because of the freebie visit.
-----Examples-----
Input
6
4 1 7 8 3 8
1
Output
3 | class CodeforcesTask386BSolution:
def __init__(self):
self.result = ""
self.n = 0
self.times = []
self.t = 0
def read_input(self):
self.n = int(input())
self.times = [int(x) for x in input().split(" ")]
self.t = int(input())
def process_task(self):
result = 0
self.times.sort()
for start in set(self.times):
in_range = 0
for time in self.times:
if start <= time <= start + self.t:
in_range += 1
result = max(result, in_range)
self.result = str(result)
def get_result(self):
return self.result
Solution = CodeforcesTask386BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result()) | CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF RETURN VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
Everyone loves a freebie. Especially students.
It is well-known that if in the night before exam a student opens window, opens the student's record-book and shouts loudly three times "Fly, freebie, fly!" β then flown freebie helps him to pass the upcoming exam.
In the night before the exam on mathematical analysis n students living in dormitory shouted treasured words. The i-th student made a sacrament at the time t_{i}, where t_{i} is the number of seconds elapsed since the beginning of the night.
It is known that the freebie is a capricious and willful lady. That night the freebie was near dormitory only for T seconds. Therefore, if for two students their sacrament times differ for more than T, then the freebie didn't visit at least one of them.
Since all students are optimists, they really want to know what is the maximal number of students visited by the freebie can be.
-----Input-----
The first line of the input contains integer n (1 β€ n β€ 100), where n β the number of students shouted "Fly, freebie, fly!" The second line contains n positive integers t_{i} (1 β€ t_{i} β€ 1000).
The last line contains integer T (1 β€ T β€ 1000) β the time interval during which the freebie was near the dormitory.
-----Output-----
Print a single integer β the largest number of people who will pass exam tomorrow because of the freebie visit.
-----Examples-----
Input
6
4 1 7 8 3 8
1
Output
3 | n = int(input())
l = list(map(int, input().split()))
t = int(input())
l.sort()
ans = 0
start = 0
for end in range(n):
while l[end] - l[start] > t:
start += 1
if end - start + 1 > ans:
ans = end - start + 1
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Everyone loves a freebie. Especially students.
It is well-known that if in the night before exam a student opens window, opens the student's record-book and shouts loudly three times "Fly, freebie, fly!" β then flown freebie helps him to pass the upcoming exam.
In the night before the exam on mathematical analysis n students living in dormitory shouted treasured words. The i-th student made a sacrament at the time t_{i}, where t_{i} is the number of seconds elapsed since the beginning of the night.
It is known that the freebie is a capricious and willful lady. That night the freebie was near dormitory only for T seconds. Therefore, if for two students their sacrament times differ for more than T, then the freebie didn't visit at least one of them.
Since all students are optimists, they really want to know what is the maximal number of students visited by the freebie can be.
-----Input-----
The first line of the input contains integer n (1 β€ n β€ 100), where n β the number of students shouted "Fly, freebie, fly!" The second line contains n positive integers t_{i} (1 β€ t_{i} β€ 1000).
The last line contains integer T (1 β€ T β€ 1000) β the time interval during which the freebie was near the dormitory.
-----Output-----
Print a single integer β the largest number of people who will pass exam tomorrow because of the freebie visit.
-----Examples-----
Input
6
4 1 7 8 3 8
1
Output
3 | n = int(input())
v = list(map(int, input().split()))
t = int(input())
v.sort()
ret = 1
lef = 0
rit = 1
while rit < n:
while rit < n and v[rit] - v[lef] <= t:
rit = rit + 1
ret = max(ret, rit - lef)
lef = lef + 1
print(ret) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
Everyone loves a freebie. Especially students.
It is well-known that if in the night before exam a student opens window, opens the student's record-book and shouts loudly three times "Fly, freebie, fly!" β then flown freebie helps him to pass the upcoming exam.
In the night before the exam on mathematical analysis n students living in dormitory shouted treasured words. The i-th student made a sacrament at the time t_{i}, where t_{i} is the number of seconds elapsed since the beginning of the night.
It is known that the freebie is a capricious and willful lady. That night the freebie was near dormitory only for T seconds. Therefore, if for two students their sacrament times differ for more than T, then the freebie didn't visit at least one of them.
Since all students are optimists, they really want to know what is the maximal number of students visited by the freebie can be.
-----Input-----
The first line of the input contains integer n (1 β€ n β€ 100), where n β the number of students shouted "Fly, freebie, fly!" The second line contains n positive integers t_{i} (1 β€ t_{i} β€ 1000).
The last line contains integer T (1 β€ T β€ 1000) β the time interval during which the freebie was near the dormitory.
-----Output-----
Print a single integer β the largest number of people who will pass exam tomorrow because of the freebie visit.
-----Examples-----
Input
6
4 1 7 8 3 8
1
Output
3 | n = int(input())
a = list(map(int, input().split()))
t = int(input())
a.sort()
ans = 0
for i in range(n):
j = i
count = 0
while j < n:
if a[j] - a[i] <= t:
count += 1
j += 1
else:
break
if count > ans:
ans = count
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
Everyone loves a freebie. Especially students.
It is well-known that if in the night before exam a student opens window, opens the student's record-book and shouts loudly three times "Fly, freebie, fly!" β then flown freebie helps him to pass the upcoming exam.
In the night before the exam on mathematical analysis n students living in dormitory shouted treasured words. The i-th student made a sacrament at the time t_{i}, where t_{i} is the number of seconds elapsed since the beginning of the night.
It is known that the freebie is a capricious and willful lady. That night the freebie was near dormitory only for T seconds. Therefore, if for two students their sacrament times differ for more than T, then the freebie didn't visit at least one of them.
Since all students are optimists, they really want to know what is the maximal number of students visited by the freebie can be.
-----Input-----
The first line of the input contains integer n (1 β€ n β€ 100), where n β the number of students shouted "Fly, freebie, fly!" The second line contains n positive integers t_{i} (1 β€ t_{i} β€ 1000).
The last line contains integer T (1 β€ T β€ 1000) β the time interval during which the freebie was near the dormitory.
-----Output-----
Print a single integer β the largest number of people who will pass exam tomorrow because of the freebie visit.
-----Examples-----
Input
6
4 1 7 8 3 8
1
Output
3 | n = int(input())
time = list(map(int, input().split()))
t = int(input())
num = []
time.sort()
tmax = time[-1]
tmin = time[0]
if time[-1] - time[0] <= t:
print(n)
else:
la = 0
stu = 0
for i in range(n):
if time[i] <= tmin + t:
stu += 1
la = i
else:
break
num.append(stu)
for i in range(1, n):
if time[i] + t > tmax:
break
if time[i] == time[i - 1]:
stu -= 1
else:
x = time[i] + t
stu -= 1
if x <= time[la]:
break
else:
for j in range(la + 1, n):
if time[j] <= x:
stu += 1
la = j
num.append(stu)
print(max(num)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Everyone loves a freebie. Especially students.
It is well-known that if in the night before exam a student opens window, opens the student's record-book and shouts loudly three times "Fly, freebie, fly!" β then flown freebie helps him to pass the upcoming exam.
In the night before the exam on mathematical analysis n students living in dormitory shouted treasured words. The i-th student made a sacrament at the time t_{i}, where t_{i} is the number of seconds elapsed since the beginning of the night.
It is known that the freebie is a capricious and willful lady. That night the freebie was near dormitory only for T seconds. Therefore, if for two students their sacrament times differ for more than T, then the freebie didn't visit at least one of them.
Since all students are optimists, they really want to know what is the maximal number of students visited by the freebie can be.
-----Input-----
The first line of the input contains integer n (1 β€ n β€ 100), where n β the number of students shouted "Fly, freebie, fly!" The second line contains n positive integers t_{i} (1 β€ t_{i} β€ 1000).
The last line contains integer T (1 β€ T β€ 1000) β the time interval during which the freebie was near the dormitory.
-----Output-----
Print a single integer β the largest number of people who will pass exam tomorrow because of the freebie visit.
-----Examples-----
Input
6
4 1 7 8 3 8
1
Output
3 | n = int(input())
l = list(map(int, input().split()))
t = int(input())
l.sort()
a = []
i = 0
j = 0
while i < n:
while j < n and l[j] - l[i] <= t:
j += 1
a.append(j - i)
i += 1
print(max(a)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Everyone loves a freebie. Especially students.
It is well-known that if in the night before exam a student opens window, opens the student's record-book and shouts loudly three times "Fly, freebie, fly!" β then flown freebie helps him to pass the upcoming exam.
In the night before the exam on mathematical analysis n students living in dormitory shouted treasured words. The i-th student made a sacrament at the time t_{i}, where t_{i} is the number of seconds elapsed since the beginning of the night.
It is known that the freebie is a capricious and willful lady. That night the freebie was near dormitory only for T seconds. Therefore, if for two students their sacrament times differ for more than T, then the freebie didn't visit at least one of them.
Since all students are optimists, they really want to know what is the maximal number of students visited by the freebie can be.
-----Input-----
The first line of the input contains integer n (1 β€ n β€ 100), where n β the number of students shouted "Fly, freebie, fly!" The second line contains n positive integers t_{i} (1 β€ t_{i} β€ 1000).
The last line contains integer T (1 β€ T β€ 1000) β the time interval during which the freebie was near the dormitory.
-----Output-----
Print a single integer β the largest number of people who will pass exam tomorrow because of the freebie visit.
-----Examples-----
Input
6
4 1 7 8 3 8
1
Output
3 | n = int(input())
a = [int(x) for x in input().split()]
t = int(input())
res = 1
a.sort()
for i in range(n):
for j in range(i + 1, n):
if a[j] - a[i] <= t:
res = max(j - i + 1, res)
print(res) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
Everyone loves a freebie. Especially students.
It is well-known that if in the night before exam a student opens window, opens the student's record-book and shouts loudly three times "Fly, freebie, fly!" β then flown freebie helps him to pass the upcoming exam.
In the night before the exam on mathematical analysis n students living in dormitory shouted treasured words. The i-th student made a sacrament at the time t_{i}, where t_{i} is the number of seconds elapsed since the beginning of the night.
It is known that the freebie is a capricious and willful lady. That night the freebie was near dormitory only for T seconds. Therefore, if for two students their sacrament times differ for more than T, then the freebie didn't visit at least one of them.
Since all students are optimists, they really want to know what is the maximal number of students visited by the freebie can be.
-----Input-----
The first line of the input contains integer n (1 β€ n β€ 100), where n β the number of students shouted "Fly, freebie, fly!" The second line contains n positive integers t_{i} (1 β€ t_{i} β€ 1000).
The last line contains integer T (1 β€ T β€ 1000) β the time interval during which the freebie was near the dormitory.
-----Output-----
Print a single integer β the largest number of people who will pass exam tomorrow because of the freebie visit.
-----Examples-----
Input
6
4 1 7 8 3 8
1
Output
3 | n = int(input())
L = list(map(int, input().split()))
T = int(input())
X = [0] * 1005
for i in range(len(L)):
X[L[i]] += 1
for i in range(1, 1005):
X[i] += X[i - 1]
best = 0
for i in range(1 + T, 1005):
if X[i] - X[i - T - 1] > best:
best = X[i] - X[i - T - 1]
print(best) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Everyone loves a freebie. Especially students.
It is well-known that if in the night before exam a student opens window, opens the student's record-book and shouts loudly three times "Fly, freebie, fly!" β then flown freebie helps him to pass the upcoming exam.
In the night before the exam on mathematical analysis n students living in dormitory shouted treasured words. The i-th student made a sacrament at the time t_{i}, where t_{i} is the number of seconds elapsed since the beginning of the night.
It is known that the freebie is a capricious and willful lady. That night the freebie was near dormitory only for T seconds. Therefore, if for two students their sacrament times differ for more than T, then the freebie didn't visit at least one of them.
Since all students are optimists, they really want to know what is the maximal number of students visited by the freebie can be.
-----Input-----
The first line of the input contains integer n (1 β€ n β€ 100), where n β the number of students shouted "Fly, freebie, fly!" The second line contains n positive integers t_{i} (1 β€ t_{i} β€ 1000).
The last line contains integer T (1 β€ T β€ 1000) β the time interval during which the freebie was near the dormitory.
-----Output-----
Print a single integer β the largest number of people who will pass exam tomorrow because of the freebie visit.
-----Examples-----
Input
6
4 1 7 8 3 8
1
Output
3 | n = int(input())
t = list(map(int, input().split()))
T = int(input())
t.sort()
m = 1
count = 0
for i in range(n):
for j in range(i, n):
if t[j] - t[i] <= T:
count += 1
m = max(count, m)
count = 0
print(m) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR |
Everyone loves a freebie. Especially students.
It is well-known that if in the night before exam a student opens window, opens the student's record-book and shouts loudly three times "Fly, freebie, fly!" β then flown freebie helps him to pass the upcoming exam.
In the night before the exam on mathematical analysis n students living in dormitory shouted treasured words. The i-th student made a sacrament at the time t_{i}, where t_{i} is the number of seconds elapsed since the beginning of the night.
It is known that the freebie is a capricious and willful lady. That night the freebie was near dormitory only for T seconds. Therefore, if for two students their sacrament times differ for more than T, then the freebie didn't visit at least one of them.
Since all students are optimists, they really want to know what is the maximal number of students visited by the freebie can be.
-----Input-----
The first line of the input contains integer n (1 β€ n β€ 100), where n β the number of students shouted "Fly, freebie, fly!" The second line contains n positive integers t_{i} (1 β€ t_{i} β€ 1000).
The last line contains integer T (1 β€ T β€ 1000) β the time interval during which the freebie was near the dormitory.
-----Output-----
Print a single integer β the largest number of people who will pass exam tomorrow because of the freebie visit.
-----Examples-----
Input
6
4 1 7 8 3 8
1
Output
3 | n = int(input())
l = list(map(int, input().split()))
t = int(input())
l.sort()
mx = 1
i = 0
j = 0
count = 1
while j < n - 1:
count = 1
i = j + 1
while i < n:
if l[i] - l[j] <= t:
count += 1
i += 1
else:
break
if count > mx:
mx = count
j += 1
print(mx) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Everyone loves a freebie. Especially students.
It is well-known that if in the night before exam a student opens window, opens the student's record-book and shouts loudly three times "Fly, freebie, fly!" β then flown freebie helps him to pass the upcoming exam.
In the night before the exam on mathematical analysis n students living in dormitory shouted treasured words. The i-th student made a sacrament at the time t_{i}, where t_{i} is the number of seconds elapsed since the beginning of the night.
It is known that the freebie is a capricious and willful lady. That night the freebie was near dormitory only for T seconds. Therefore, if for two students their sacrament times differ for more than T, then the freebie didn't visit at least one of them.
Since all students are optimists, they really want to know what is the maximal number of students visited by the freebie can be.
-----Input-----
The first line of the input contains integer n (1 β€ n β€ 100), where n β the number of students shouted "Fly, freebie, fly!" The second line contains n positive integers t_{i} (1 β€ t_{i} β€ 1000).
The last line contains integer T (1 β€ T β€ 1000) β the time interval during which the freebie was near the dormitory.
-----Output-----
Print a single integer β the largest number of people who will pass exam tomorrow because of the freebie visit.
-----Examples-----
Input
6
4 1 7 8 3 8
1
Output
3 | n = int(input())
t = sorted(list(map(int, input().split())))
T = int(input())
ans = 0
l = 0
r = 0
while r < n:
ans = max(ans, r - l + 1)
if r == n - 1:
break
if t[r + 1] - t[l] <= T:
r += 1
else:
l += 1
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
Everyone loves a freebie. Especially students.
It is well-known that if in the night before exam a student opens window, opens the student's record-book and shouts loudly three times "Fly, freebie, fly!" β then flown freebie helps him to pass the upcoming exam.
In the night before the exam on mathematical analysis n students living in dormitory shouted treasured words. The i-th student made a sacrament at the time t_{i}, where t_{i} is the number of seconds elapsed since the beginning of the night.
It is known that the freebie is a capricious and willful lady. That night the freebie was near dormitory only for T seconds. Therefore, if for two students their sacrament times differ for more than T, then the freebie didn't visit at least one of them.
Since all students are optimists, they really want to know what is the maximal number of students visited by the freebie can be.
-----Input-----
The first line of the input contains integer n (1 β€ n β€ 100), where n β the number of students shouted "Fly, freebie, fly!" The second line contains n positive integers t_{i} (1 β€ t_{i} β€ 1000).
The last line contains integer T (1 β€ T β€ 1000) β the time interval during which the freebie was near the dormitory.
-----Output-----
Print a single integer β the largest number of people who will pass exam tomorrow because of the freebie visit.
-----Examples-----
Input
6
4 1 7 8 3 8
1
Output
3 | n = int(input())
lst = sorted(list(map(int, input().split())))
t = int(input())
ans = 1
for i in range(len(lst) - 1):
temp = 1
k = i + 1
while k < len(lst) and lst[k] - lst[i] <= t:
temp += 1
k += 1
if temp > ans:
ans = temp
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
Everyone loves a freebie. Especially students.
It is well-known that if in the night before exam a student opens window, opens the student's record-book and shouts loudly three times "Fly, freebie, fly!" β then flown freebie helps him to pass the upcoming exam.
In the night before the exam on mathematical analysis n students living in dormitory shouted treasured words. The i-th student made a sacrament at the time t_{i}, where t_{i} is the number of seconds elapsed since the beginning of the night.
It is known that the freebie is a capricious and willful lady. That night the freebie was near dormitory only for T seconds. Therefore, if for two students their sacrament times differ for more than T, then the freebie didn't visit at least one of them.
Since all students are optimists, they really want to know what is the maximal number of students visited by the freebie can be.
-----Input-----
The first line of the input contains integer n (1 β€ n β€ 100), where n β the number of students shouted "Fly, freebie, fly!" The second line contains n positive integers t_{i} (1 β€ t_{i} β€ 1000).
The last line contains integer T (1 β€ T β€ 1000) β the time interval during which the freebie was near the dormitory.
-----Output-----
Print a single integer β the largest number of people who will pass exam tomorrow because of the freebie visit.
-----Examples-----
Input
6
4 1 7 8 3 8
1
Output
3 | n, t = input(), [0] * 1002
for i in map(int, input().split()):
t[i] += 1
T = int(input()) + 1
for i in range(1000):
t[i + 1] += t[i]
print(max(t[i + T] - t[i] for i in range(-1, 1001 - T))) | ASSIGN VAR VAR FUNC_CALL VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR |
Everyone loves a freebie. Especially students.
It is well-known that if in the night before exam a student opens window, opens the student's record-book and shouts loudly three times "Fly, freebie, fly!" β then flown freebie helps him to pass the upcoming exam.
In the night before the exam on mathematical analysis n students living in dormitory shouted treasured words. The i-th student made a sacrament at the time t_{i}, where t_{i} is the number of seconds elapsed since the beginning of the night.
It is known that the freebie is a capricious and willful lady. That night the freebie was near dormitory only for T seconds. Therefore, if for two students their sacrament times differ for more than T, then the freebie didn't visit at least one of them.
Since all students are optimists, they really want to know what is the maximal number of students visited by the freebie can be.
-----Input-----
The first line of the input contains integer n (1 β€ n β€ 100), where n β the number of students shouted "Fly, freebie, fly!" The second line contains n positive integers t_{i} (1 β€ t_{i} β€ 1000).
The last line contains integer T (1 β€ T β€ 1000) β the time interval during which the freebie was near the dormitory.
-----Output-----
Print a single integer β the largest number of people who will pass exam tomorrow because of the freebie visit.
-----Examples-----
Input
6
4 1 7 8 3 8
1
Output
3 | read = lambda: list(map(int, input().split()))
n = int(input())
a = sorted(read())
T = int(input())
ans = 0
j = 0
for i in range(n):
while j < n and a[j] - a[i] <= T:
j += 1
ans = max(ans, j - i)
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
Everyone loves a freebie. Especially students.
It is well-known that if in the night before exam a student opens window, opens the student's record-book and shouts loudly three times "Fly, freebie, fly!" β then flown freebie helps him to pass the upcoming exam.
In the night before the exam on mathematical analysis n students living in dormitory shouted treasured words. The i-th student made a sacrament at the time t_{i}, where t_{i} is the number of seconds elapsed since the beginning of the night.
It is known that the freebie is a capricious and willful lady. That night the freebie was near dormitory only for T seconds. Therefore, if for two students their sacrament times differ for more than T, then the freebie didn't visit at least one of them.
Since all students are optimists, they really want to know what is the maximal number of students visited by the freebie can be.
-----Input-----
The first line of the input contains integer n (1 β€ n β€ 100), where n β the number of students shouted "Fly, freebie, fly!" The second line contains n positive integers t_{i} (1 β€ t_{i} β€ 1000).
The last line contains integer T (1 β€ T β€ 1000) β the time interval during which the freebie was near the dormitory.
-----Output-----
Print a single integer β the largest number of people who will pass exam tomorrow because of the freebie visit.
-----Examples-----
Input
6
4 1 7 8 3 8
1
Output
3 | __author__ = "asmn"
n = int(input())
a = sorted(map(int, input().split()))
dt = int(input())
ans, l, r = 0, 0, 0
while r < len(a):
while r < len(a) and a[r] - a[l] <= dt:
r += 1
ans = max(ans, r - l)
l += 1
print(ans) | ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Everyone loves a freebie. Especially students.
It is well-known that if in the night before exam a student opens window, opens the student's record-book and shouts loudly three times "Fly, freebie, fly!" β then flown freebie helps him to pass the upcoming exam.
In the night before the exam on mathematical analysis n students living in dormitory shouted treasured words. The i-th student made a sacrament at the time t_{i}, where t_{i} is the number of seconds elapsed since the beginning of the night.
It is known that the freebie is a capricious and willful lady. That night the freebie was near dormitory only for T seconds. Therefore, if for two students their sacrament times differ for more than T, then the freebie didn't visit at least one of them.
Since all students are optimists, they really want to know what is the maximal number of students visited by the freebie can be.
-----Input-----
The first line of the input contains integer n (1 β€ n β€ 100), where n β the number of students shouted "Fly, freebie, fly!" The second line contains n positive integers t_{i} (1 β€ t_{i} β€ 1000).
The last line contains integer T (1 β€ T β€ 1000) β the time interval during which the freebie was near the dormitory.
-----Output-----
Print a single integer β the largest number of people who will pass exam tomorrow because of the freebie visit.
-----Examples-----
Input
6
4 1 7 8 3 8
1
Output
3 | n = int(input())
m = list(map(int, input().split()))
t = int(input())
m.sort()
if n == 1 or len(m) == 1:
print(1)
elif m[-1] - m[0] <= t:
print(n)
else:
mx = 1
for i in range(n - 1):
ma = 1
fr = m[i]
for j in range(i + 1, n):
if m[j] - fr <= t:
ma += 1
else:
break
mx = max(ma, mx)
print(mx) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Everyone loves a freebie. Especially students.
It is well-known that if in the night before exam a student opens window, opens the student's record-book and shouts loudly three times "Fly, freebie, fly!" β then flown freebie helps him to pass the upcoming exam.
In the night before the exam on mathematical analysis n students living in dormitory shouted treasured words. The i-th student made a sacrament at the time t_{i}, where t_{i} is the number of seconds elapsed since the beginning of the night.
It is known that the freebie is a capricious and willful lady. That night the freebie was near dormitory only for T seconds. Therefore, if for two students their sacrament times differ for more than T, then the freebie didn't visit at least one of them.
Since all students are optimists, they really want to know what is the maximal number of students visited by the freebie can be.
-----Input-----
The first line of the input contains integer n (1 β€ n β€ 100), where n β the number of students shouted "Fly, freebie, fly!" The second line contains n positive integers t_{i} (1 β€ t_{i} β€ 1000).
The last line contains integer T (1 β€ T β€ 1000) β the time interval during which the freebie was near the dormitory.
-----Output-----
Print a single integer β the largest number of people who will pass exam tomorrow because of the freebie visit.
-----Examples-----
Input
6
4 1 7 8 3 8
1
Output
3 | n = int(input())
l = [int(x) for x in input().split()]
T = int(input())
l.sort()
M = 1
inz = 0
fin = 1
count = 1
while fin < n:
while fin < n and l[fin] - l[inz] <= T:
count += 1
fin += 1
if count > M:
M = count
inz += 1
count -= 1
if fin < inz:
fin = inz
count = 1
print(M) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR |
Everyone loves a freebie. Especially students.
It is well-known that if in the night before exam a student opens window, opens the student's record-book and shouts loudly three times "Fly, freebie, fly!" β then flown freebie helps him to pass the upcoming exam.
In the night before the exam on mathematical analysis n students living in dormitory shouted treasured words. The i-th student made a sacrament at the time t_{i}, where t_{i} is the number of seconds elapsed since the beginning of the night.
It is known that the freebie is a capricious and willful lady. That night the freebie was near dormitory only for T seconds. Therefore, if for two students their sacrament times differ for more than T, then the freebie didn't visit at least one of them.
Since all students are optimists, they really want to know what is the maximal number of students visited by the freebie can be.
-----Input-----
The first line of the input contains integer n (1 β€ n β€ 100), where n β the number of students shouted "Fly, freebie, fly!" The second line contains n positive integers t_{i} (1 β€ t_{i} β€ 1000).
The last line contains integer T (1 β€ T β€ 1000) β the time interval during which the freebie was near the dormitory.
-----Output-----
Print a single integer β the largest number of people who will pass exam tomorrow because of the freebie visit.
-----Examples-----
Input
6
4 1 7 8 3 8
1
Output
3 | def halyava(lst, t):
count = 1
for i in range(len(lst)):
for j in range(i + 1, len(lst)):
if sorted(lst)[j] - sorted(lst)[i] <= t:
count = max(j - i + 1, count)
return count
n = int(input())
b = [int(x) for x in input().split()]
T = int(input())
print(halyava(b, T)) | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
a = list(map(int, input().split()))
a.sort()
l = []
if n == 0:
print(0)
else:
for i in range(n):
ln = a[i + n - 1] - a[i]
if i == 0:
breadth = a[-1] - a[n]
else:
breadth = a[-1] - a[0]
l.append(ln * breadth)
print(min(l)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | N = int(input())
A = list(map(int, input().split()))
A.sort()
s = (A[N - 1] - A[0]) * (A[2 * N - 1] - A[N])
for i in range(1, N):
s = min(s, (A[N - 1 + i] - A[i]) * (A[2 * N - 1] - A[0]))
print(s) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
l = list(map(int, input().split()))
assert len(l) == 2 * n
l.sort()
out = (l[n - 1] - l[0]) * (l[2 * n - 1] - l[n])
mult = l[-1] - l[0]
for i in range(1, n):
q = mult * (l[i + n - 1] - l[i])
if q < out:
out = q
print(out) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
l = list(map(int, input().strip().split()))
l.sort()
a = l[n - 1] - l[0]
b = l[2 * n - 1] - l[n]
ans1 = a * b
min1 = 1000000000000000000000
for i in range(1, n):
s = l[i + n - 1] - l[i]
if s < min1:
min1 = s
ans2 = min1 * (l[2 * n - 1] - l[0])
if ans1 < ans2:
print(ans1)
else:
print(ans2) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
a = [int(s) for s in input().split()]
a = sorted(a)
ind = 0
p = (a[n - 1] - a[0]) * (a[2 * n - 1] - a[n])
r = a[2 * n - 1] - a[0]
for i in range(n + 1):
if (a[i + n - 1] - a[i]) * r < p:
p = (a[i + n - 1] - a[i]) * r
print(p) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
arr = list(map(int, input().strip().split(" ")))
if n == 1:
print(0)
else:
arr.sort()
a = []
b = []
a.append(arr[0])
a.append(arr[n - 1])
b.append(arr[n])
b.append(arr[-1])
xdif = a[0] - a[1]
ydif = b[0] - b[1]
ans = xdif * ydif
for i in range(1, n):
ans = min(ans, (arr[2 * n - 1] - arr[0]) * (arr[n + i - 1] - arr[i]))
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
l = list(map(int, input().split()))
l.sort()
s = 2 * n - 1
mini = (l[n - 1] - l[0]) * (l[s] - l[n])
for i in range(1, n + 1):
mini = min(abs((l[n - 1 + i] - l[i]) * (l[s] - l[0])), mini)
print(mini) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
data = list(map(int, input().split()))
data.sort()
min_sq = (data[-1] - data[n]) * (data[n - 1] - data[0])
for i in range(1, n):
if (data[-1] - data[0]) * (data[i + n - 1] - data[i]) < min_sq:
min_sq = (data[-1] - data[0]) * (data[i + n - 1] - data[i])
print(min_sq) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
sl = list(map(int, input().split()))
sl.sort()
a = sl[0:n]
b = sl[n:]
x = a[0]
y = a[n - 1]
z = b[0]
d = b[n - 1]
m = sl[2 * n - 1] - sl[0]
k = (y - x) * (d - z)
for i in range(n):
p = (sl[i + n - 1] - sl[i]) * m
if p < k:
k = p
print(k) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
coords = list(map(int, input().split()))
lin = sorted(coords)
min_v = lin[0]
max_v = lin[-1]
if n == 1:
print(0)
exit(0)
side = max_v - min_v
min_side = min(lin[i + n - 1] - lin[i] for i in range(1, n))
min_prod = min_side * side
dif_prod = (lin[n - 1] - min_v) * (max_v - lin[n])
if dif_prod < min_prod:
min_prod = dif_prod
print(min_prod) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
arr = list(map(int, input().split()))
arr.sort()
ans = (arr[n - 1] - arr[0]) * (arr[2 * n - 1] - arr[n])
x = arr[2 * n - 1] - arr[0]
c = 0
for i in range(1, n):
c = x * (arr[i + n - 1] - arr[i])
ans = min(ans, c)
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | R = lambda: map(int, input().split())
n = int(input())
L = sorted(R())
mi = (L[n - 1] - L[0]) * (L[2 * n - 1] - L[n])
k = L[2 * n - 1] - L[0]
for i in range(1, n):
mi = min(mi, k * (L[i + n - 1] - L[i]))
print(mi) | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
a = list(map(int, input().split()))
a.sort()
k = 12122121212121
for i in range(1, n):
k = min(k, a[i + n - 1] - a[i])
k = k * (a[2 * n - 1] - a[0])
z = abs(a[0] - a[n - 1]) * abs(a[n] - a[2 * n - 1])
print(min(k, z)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
cl = sorted(list(map(int, input().split())))
if n == 1:
print(0)
else:
mn = (cl[n - 1] - cl[0]) * (cl[-1] - cl[n])
t = cl[-1] - cl[0]
if t == 0:
print(0)
else:
mnt = 10**10 + 1
for i in range(1, n):
if cl[i + n - 1] - cl[i] < mnt:
mnt = cl[i + n - 1] - cl[i]
if mnt == 0:
break
if t * mnt < mn:
mn = mnt * t
print(mn) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | from sys import stdin, stdout
n = int(stdin.readline())
arr = [int(x) for x in stdin.readline().split()]
arr.sort()
x1 = arr[0]
x2 = arr[n - 1]
y1 = arr[n]
y2 = arr[2 * n - 1]
mini = (x2 - x1) * (y2 - y1)
for i in range(1, n):
j = i + n - 1
x1 = arr[i]
x2 = arr[j]
y1 = arr[0]
y2 = arr[2 * n - 1]
prod = (x2 - x1) * (y2 - y1)
if prod < mini:
mini = prod
print(mini) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP NUMBER 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 |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | int(input())
arr = list(map(int, input().split()))
n = len(arr) // 2
arr.sort()
x1 = arr[0]
x2 = arr[n - 1]
y2 = arr[-1]
y1 = arr[n]
ans = abs(x1 - x2) * abs(y1 - y2)
for i in range(n, n * 2 - 1):
ans = min((arr[i] - arr[i - n + 1]) * (arr[-1] - arr[0]), ans)
print(ans) | EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | from sys import stdin, stdout
def rint():
return map(int, stdin.readline().split())
n = int(input())
a = list(rint())
a.sort()
Min = 10**1000
for i in range(1, n):
Min = min(Min, (a[n - 1 + i] - a[i]) * (a[n * 2 - 1] - a[0]))
Min = min(Min, (a[n - 1] - a[0]) * (a[2 * n - 1] - a[n]))
print(Min) | FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | import sys
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
if n == 1:
print(0)
else:
c1 = (a[n - 1] - a[0]) * (a[-1] - a[-n])
c2 = (a[-1] - a[0]) * min(a[n - 1 + i] - a[i] for i in range(1, n))
print(min(c1, c2)) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
s = sorted(map(int, input().split()))
h = s[2 * n - 1] - s[0]
best = (s[n - 1] - s[0]) * (s[2 * n - 1] - s[n])
for i in range(1, n):
w = s[i + n - 1] - s[i]
new = h * w
if new < best:
best = new
print(best) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
a = [int(v) for v in input().split()]
a.sort()
ans = (a[-1] - a[n]) * (a[n - 1] - a[0])
for i in range(1, n):
ans = min(ans, (a[-1] - a[0]) * (a[i + n - 1] - a[i]))
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
a = list(map(int, input().split()))
a.sort()
s1 = (a[n - 1] - a[0]) * (a[-1] - a[n])
tmp = a[-1] - a[0]
for i in range(1, n):
if tmp * (a[n + i - 1] - a[i]) < s1:
s1 = tmp * (a[n + i - 1] - a[i])
print(s1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | N = int(input())
if N == 1:
print(0)
exit()
a = list(map(int, input().split()))
a = sorted(a)
res = 10**10
for i in range(N):
if res > a[i + N - 1] - a[i]:
res = a[i + N - 1] - a[i]
probAns1 = (a[len(a) - 1] - a[0]) * res
probAns2 = (a[N - 1] - a[0]) * (a[len(a) - 1] - a[N])
res = min(probAns1, probAns2)
print(res) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input()) - 1
s = sorted(map(int, input().split()))
sp = (s[n] - s[0]) * (s[2 * n + 1] - s[n + 1])
for i in range(n + 1):
sp = min(sp, (s[n + i] - s[i]) * (s[2 * n + 1] - s[0]))
print(sp) | ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
a = list(map(int, input().split()))
a.sort()
b = -(a[0] - a[n - 1])
c = -(a[n] - a[2 * n - 1])
m = b * c
x = a[-1] - a[0]
for i in range(1, n):
m = min(m, x * (a[n + i - 1] - a[i]))
print(m) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
a = [int(i) for i in input().split()]
a.sort()
ans = 1e20
for i in range(1, n):
now = (a[i + n - 1] - a[i]) * (a[2 * n - 1] - a[0])
if now < ans:
ans = now
ans = min(ans, (a[n - 1] - a[0]) * (a[2 * n - 1] - a[n]))
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | def main():
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
min_p = 10**20
for i in range(n + 1):
curr_dif = a[n + i - 1] - a[i]
sy = a[0] if i > 0 else a[n]
ey = a[i - 1] if i == n else a[2 * n - 1]
curr_p = curr_dif * (ey - sy)
if curr_p < min_p:
min_p = curr_p
print(min_p)
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | def solve(arr):
arr = sorted(arr)
a0 = arr[0]
an = arr[-1]
minsub = 1000000000000
for i in range(1, len(arr) // 2):
minsub = min(arr[i + len(arr) // 2 - 1] - arr[i], minsub)
first_case = (an - a0) * minsub
bn = arr[-1]
an = arr[len(arr) // 2 - 1]
b0 = arr[len(arr) // 2]
second_case = (bn - b0) * (an - a0)
return min(first_case, second_case)
input()
arr = [int(x) for x in input().strip().split()]
print(solve(arr)) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
a = sorted(map(int, input().split()))
print(
min(
[(a[n - 1] - a[0]) * (a[-1] - a[n])]
+ [((a[-1] - a[0]) * (a[i + n - 1] - a[i])) for i in range(n)]
)
) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP LIST BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
a = list(input().split())
for i in range(2 * n):
a[i] = int(a[i])
a.sort()
x1 = a[0]
x2 = a[n - 1]
y1 = a[n]
y2 = a[2 * n - 1]
p = (x2 - x1) * (y2 - y1)
minx = p
for i in range(1, n):
if a[i + n - 1] - a[i] < minx:
minx = a[i + n - 1] - a[i]
if p < minx * (a[2 * n - 1] - a[0]):
print(p)
else:
print((a[2 * n - 1] - a[0]) * minx) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF VAR BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
a = [int(x) for x in input().split()]
flag = True
if n == 1:
print(0)
else:
a = sorted(a)
n2 = n * 2
ans = (a[n - 1] - a[0]) * (a[n2 - 1] - a[n])
for i in range(n):
ans = min(ans, (a[i + n - 1] - a[i]) * (a[n2 - 1] - a[0]))
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
A = list(map(int, input().split()))
if n == 1:
print(0)
exit()
A.sort()
ans = float("inf")
for i in range(n + 1):
x = A[i + n - 1] - A[i]
if i == 0:
y = A[2 * n - 1] - A[n]
elif i == n:
y = A[n - 1] - A[0]
else:
y = A[2 * n - 1] - A[0]
ans = min(ans, x * y)
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
a = list(map(int, input().split()))
a.sort()
b = []
kol = []
o = 1
mo = 1
for i in range(1, n * 2):
if a[i] == a[i - 1]:
o += 1
else:
b.append(a[i - 1])
kol.append(o)
o = 1
k = 0
b.append(a[i])
kol.append(o)
for j in range(0, len(b)):
k += kol[j]
if k == n:
ans = (a[2 * n - 1] - b[j + 1]) * (b[j] - b[0])
break
elif k > n:
ans = (a[2 * n - 1] - b[j]) * (b[j] - b[0])
break
for i in range(1, len(b)):
k -= kol[i - 1] + kol[j]
for j in range(j, len(b)):
k += kol[j]
if k >= n:
ans = min(ans, (a[2 * n - 1] - a[0]) * (b[j] - b[i]))
break
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
nums = [int(i) for i in input().split()]
if n == 1:
print(0)
else:
nums.sort()
area_1 = None
for i in range(1, n):
temp = (nums[-1] - nums[0]) * (nums[i + n - 1] - nums[i])
if area_1 is None or temp < area_1:
area_1 = temp
temp = (nums[n - 1] - nums[0]) * (nums[-1] - nums[n])
if temp < area_1:
area_1 = temp
print(area_1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NONE FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF VAR NONE VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
k = 1000000009
a = [int(i) for i in input().split()]
a.sort()
if n == 1:
print(0)
exit()
else:
for i in range(1, n):
k = min(k, a[i + n - 1] - a[i])
print(min((a[2 * n - 1] - a[0]) * k, (a[n - 1] - a[0]) * (a[2 * n - 1] - a[n]))) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
l = [None] * (n * 2)
s = input().split()
for i in range(n * 2):
l[i] = int(s[i])
l.sort()
res = (l[n - 1] - l[0]) * (l[-1] - l[n])
for i in range(1, n):
res = min(res, (l[i + n - 1] - l[i]) * (l[-1] - l[0]))
print(res) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
a = [int(x) for x in input().split()]
a.sort()
top = [a[0], a[-1]]
right = [a[n - 1], a[n]]
case2 = abs((top[0] - right[0]) * (top[1] - right[1]))
case1 = top[-1] - top[0]
mny = 10000000000
for i in range(1, n):
mny = min(mny, abs(a[i] - a[i + n - 1]))
case1 *= mny
print(min(abs(case1), case2)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER VAR NUMBER ASSIGN VAR LIST VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
records = list(map(int, input().split()))
records.sort()
diffArr = []
for i in range(n + 1):
if i == 0:
diffArr.append([records[n - 1] - records[0], records[-1] - records[n]])
elif i == n:
diffArr.append([records[-1] - records[n], records[n - 1] - records[0]])
else:
diffArr.append([records[n + i - 1] - records[i], records[-1] - records[0]])
minDiff = min(diffArr, key=lambda t: t[0] * t[1])
print(minDiff[0] * minDiff[1]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR IF VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
coords = list(map(int, input().split(" ")))
sc = sorted(coords)
minprod = float("inf")
for i in range(n + 1):
x_dist = sc[i + n - 1] - sc[i]
if i == 0:
minprod = min(minprod, x_dist * (sc[-1] - sc[n]))
elif i == n:
minprod = min(minprod, x_dist * (sc[n - 1] - sc[0]))
else:
minprod = min(minprod, x_dist * (sc[-1] - sc[0]))
print(minprod) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
m = n * 2
a = list(map(int, input().split()))
if n == 1:
print(0)
else:
a.sort()
m1 = (a[m - 1] - a[m // 2]) * (a[m // 2 - 1] - a[0])
m2 = a[m - 1] - a[0]
for i in range(1, n):
if a[i + n - 1] - a[i] < m2:
m2 = a[i + n - 1] - a[i]
m2 *= a[m - 1] - a[0]
print(min(m1, m2)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | def main():
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
x = a[n - 1] - a[0]
y = a[2 * n - 1] - a[n]
c1 = x * y
x = a[2 * n - 1] - a[0]
for i in range(1, n):
c1 = min(c1, x * (a[i + n - 1] - a[i]))
print(c1)
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
n *= 2
a = [int(s) for s in input().split()]
a = sorted(a)
x1 = a[0]
x2 = a[n // 2 - 1]
y1 = a[n // 2]
y2 = a[n - 1]
ans = (x2 - x1) * (y2 - y1)
block = n // 2
for i in range(1, n // 2):
y1 = a[0]
y2 = a[n - 1]
x1 = a[i]
x2 = a[i + block - 1]
ans = min(ans, (x2 - x1) * (y2 - y1))
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
a = [int(i) for i in input().split(" ")]
a = sorted(a)
min_area = 1e20
for i in range(len(a)):
min_x = a[i]
if i + n - 1 >= len(a):
break
max_x = a[i + n - 1]
if i == 0:
min_y = a[i + n - 1 + 1]
else:
min_y = a[0]
if i + n - 1 == len(a) - 1:
max_y = a[i - 1]
else:
max_y = a[len(a) - 1]
min_area = min(min_area, (max_x - min_x) * (max_y - min_y))
print(min_area) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | t = 1
for test in range(1, t + 1):
n = int(input())
b = list(map(int, input().split()))
b.sort()
ans = (b[n - 1] - b[0]) * (-b[n] + b[-1])
tmp = 1000000001
for i in range(1, n):
tmp = min(b[i + n - 1] - b[i], tmp)
print(min(ans, (b[-1] - b[0]) * tmp)) | ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
a = list(map(int, input().split()))
a.sort()
mn = (a[n - 1] - a[0]) * (a[2 * n - 1] - a[n])
for i in range(1, n + 1):
if i < n:
mn = min(mn, (a[n + i - 1] - a[i]) * (a[2 * n - 1] - a[0]))
else:
mn = min(mn, (a[n + i - 1] - a[i]) * (a[i - 1] - a[0]))
print(mn) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | from sys import stdin
n = int(stdin.readline())
a = [int(x) for x in stdin.readline().split()]
a.sort()
l = 0
d = [0] * (2 * n)
d[n] = a[-1] - a[n]
ans = float("inf")
for i in range(n, -1, -1):
dy = a[i + n - 1] - a[i]
if i == n:
dx = a[n - 1] - a[0]
else:
dx = a[-1] - a[0]
ans = min(ans, dx * dy)
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
a = sorted(map(int, input().split()))
r = s = (a[n - 1] - a[0]) * (a[-1] - a[n])
if n > 1:
s = (a[-1] - a[0]) * min(y - x for x, y in zip(a, a[n - 1 :]))
print(min(r, s)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | n = int(input())
numbers = sorted(int(x) for x in input().split())
best_s = 10**18 + 10
for start in range(n + 1):
x_len = numbers[start + n - 1] - numbers[start]
y_len = numbers[-1] - numbers[0]
if start + n - 1 == 2 * n - 1:
y_len = numbers[start - 1] - numbers[0]
elif start == 0:
y_len = numbers[-1] - numbers[n]
best_s = min(best_s, x_len * y_len)
print(best_s) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.
Input
The first line of the input contains an only integer n (1 β€ n β€ 100 000), the number of points in Pavel's records.
The second line contains 2 β
n integers a_1, a_2, ..., a_{2 β
n} (1 β€ a_i β€ 10^9), coordinates, written by Pavel in some order.
Output
Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.
Examples
Input
4
4 1 3 2 3 2 1 3
Output
1
Input
3
5 8 5 5 7 5
Output
0
Note
In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). | import sys
n = int(input())
L = [int(x) for x in input().split()]
L.sort()
if n == 1:
print(0)
sys.exit(0)
min1 = 10**11
for i in range(1, n):
min1 = min(min1, L[n + i - 1] - L[i])
print(min(min1 * (L[2 * n - 1] - L[0]), (L[2 * n - 1] - L[n]) * (L[n - 1] - L[0]))) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.