description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.
Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of $2$. Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following: if the current length is at least $2$, divide the base into $2$ equal halves and destroy them separately, or burn the current base. If it contains no avenger in it, it takes $A$ amount of power, otherwise it takes his $B \cdot n_a \cdot l$ amount of power, where $n_a$ is the number of avengers and $l$ is the length of the current base. Output the minimum power needed by Thanos to destroy the avengers' base.
-----Input-----
The first line contains four integers $n$, $k$, $A$ and $B$ ($1 \leq n \leq 30$, $1 \leq k \leq 10^5$, $1 \leq A,B \leq 10^4$), where $2^n$ is the length of the base, $k$ is the number of avengers and $A$ and $B$ are the constants explained in the question.
The second line contains $k$ integers $a_{1}, a_{2}, a_{3}, \ldots, a_{k}$ ($1 \leq a_{i} \leq 2^n$), where $a_{i}$ represents the position of avenger in the base.
-----Output-----
Output one integer β the minimum power needed to destroy the avengers base.
-----Examples-----
Input
2 2 1 2
1 3
Output
6
Input
3 2 1 2
1 7
Output
8
-----Note-----
Consider the first example.
One option for Thanos is to burn the whole base $1-4$ with power $2 \cdot 2 \cdot 4 = 16$.
Otherwise he can divide the base into two parts $1-2$ and $3-4$.
For base $1-2$, he can either burn it with power $2 \cdot 1 \cdot 2 = 4$ or divide it into $2$ parts $1-1$ and $2-2$.
For base $1-1$, he can burn it with power $2 \cdot 1 \cdot 1 = 2$. For $2-2$, he can destroy it with power $1$, as there are no avengers. So, the total power for destroying $1-2$ is $2 + 1 = 3$, which is less than $4$.
Similarly, he needs $3$ power to destroy $3-4$. The total minimum power needed is $6$. | n, k, a, b = list(map(int, input().split()))
h = [0] + list(map(int, input().split()))
h.sort()
def binp(nu):
l = 0
r = len(h) - 1
while r - l > 1:
if h[(l + r) // 2] > nu:
r = (l + r) // 2
else:
l = (l + r) // 2
if h[r] <= nu:
return l + 1
else:
return l
def rec(start, stop, a, b):
g = binp(start - 1)
f = binp(stop)
if g == f:
return a
elif stop - start == 0:
return b * (f - g)
else:
return min(
(stop - start + 1) * (f - g) * b,
rec(start, stop - (stop - start + 1) // 2, a, b)
+ rec(stop - (stop - start + 1) // 2 + 1, stop, a, b),
)
print(rec(1, 2**n, a, b)) | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN VAR IF BIN_OP VAR VAR NUMBER RETURN BIN_OP VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR VAR VAR |
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.
Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of $2$. Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following: if the current length is at least $2$, divide the base into $2$ equal halves and destroy them separately, or burn the current base. If it contains no avenger in it, it takes $A$ amount of power, otherwise it takes his $B \cdot n_a \cdot l$ amount of power, where $n_a$ is the number of avengers and $l$ is the length of the current base. Output the minimum power needed by Thanos to destroy the avengers' base.
-----Input-----
The first line contains four integers $n$, $k$, $A$ and $B$ ($1 \leq n \leq 30$, $1 \leq k \leq 10^5$, $1 \leq A,B \leq 10^4$), where $2^n$ is the length of the base, $k$ is the number of avengers and $A$ and $B$ are the constants explained in the question.
The second line contains $k$ integers $a_{1}, a_{2}, a_{3}, \ldots, a_{k}$ ($1 \leq a_{i} \leq 2^n$), where $a_{i}$ represents the position of avenger in the base.
-----Output-----
Output one integer β the minimum power needed to destroy the avengers base.
-----Examples-----
Input
2 2 1 2
1 3
Output
6
Input
3 2 1 2
1 7
Output
8
-----Note-----
Consider the first example.
One option for Thanos is to burn the whole base $1-4$ with power $2 \cdot 2 \cdot 4 = 16$.
Otherwise he can divide the base into two parts $1-2$ and $3-4$.
For base $1-2$, he can either burn it with power $2 \cdot 1 \cdot 2 = 4$ or divide it into $2$ parts $1-1$ and $2-2$.
For base $1-1$, he can burn it with power $2 \cdot 1 \cdot 1 = 2$. For $2-2$, he can destroy it with power $1$, as there are no avengers. So, the total power for destroying $1-2$ is $2 + 1 = 3$, which is less than $4$.
Similarly, he needs $3$ power to destroy $3-4$. The total minimum power needed is $6$. | import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)
def bs(num):
low = 0
high = k - 1
while low < high:
mid = (low + high) // 2
if l[mid] > num:
high = mid - 1
else:
low = mid + 1
if l[low] > num:
return low
else:
return low + 1
def solve(start, end):
if start == end:
if start in d:
return 1 * b * d[start]
else:
return a
else:
if start != 0:
count = bs(end) - bs(start - 1)
else:
count = bs(end)
if count == 0:
return a
else:
temp1 = solve(start, (start + end) // 2)
temp2 = solve((start + end) // 2 + 1, end)
return min(temp1 + temp2, b * count * (end - start + 1))
n, k, a, b = map(int, input().split())
l = list(map(int, input().split()))
for i in range(k):
l[i] -= 1
l.sort()
d = {}
for i in l:
if i in d:
d[i] += 1
else:
d[i] = 1
print(solve(0, 2**n - 1)) | IMPORT ASSIGN VAR VAR EXPR FUNC_CALL VAR NUMBER 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 ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR RETURN VAR RETURN BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR IF VAR VAR RETURN BIN_OP BIN_OP NUMBER VAR VAR VAR RETURN VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER |
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.
Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of $2$. Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following: if the current length is at least $2$, divide the base into $2$ equal halves and destroy them separately, or burn the current base. If it contains no avenger in it, it takes $A$ amount of power, otherwise it takes his $B \cdot n_a \cdot l$ amount of power, where $n_a$ is the number of avengers and $l$ is the length of the current base. Output the minimum power needed by Thanos to destroy the avengers' base.
-----Input-----
The first line contains four integers $n$, $k$, $A$ and $B$ ($1 \leq n \leq 30$, $1 \leq k \leq 10^5$, $1 \leq A,B \leq 10^4$), where $2^n$ is the length of the base, $k$ is the number of avengers and $A$ and $B$ are the constants explained in the question.
The second line contains $k$ integers $a_{1}, a_{2}, a_{3}, \ldots, a_{k}$ ($1 \leq a_{i} \leq 2^n$), where $a_{i}$ represents the position of avenger in the base.
-----Output-----
Output one integer β the minimum power needed to destroy the avengers base.
-----Examples-----
Input
2 2 1 2
1 3
Output
6
Input
3 2 1 2
1 7
Output
8
-----Note-----
Consider the first example.
One option for Thanos is to burn the whole base $1-4$ with power $2 \cdot 2 \cdot 4 = 16$.
Otherwise he can divide the base into two parts $1-2$ and $3-4$.
For base $1-2$, he can either burn it with power $2 \cdot 1 \cdot 2 = 4$ or divide it into $2$ parts $1-1$ and $2-2$.
For base $1-1$, he can burn it with power $2 \cdot 1 \cdot 1 = 2$. For $2-2$, he can destroy it with power $1$, as there are no avengers. So, the total power for destroying $1-2$ is $2 + 1 = 3$, which is less than $4$.
Similarly, he needs $3$ power to destroy $3-4$. The total minimum power needed is $6$. | n = 0
k = 0
a = 0
b = 0
num = []
def __upper_bound__(val):
global num
global k
l = 0
r = k - 1
while l < r:
mid = l + r >> 1
if num[mid] < val:
l = mid + 1
else:
r = mid
if l >= k:
return l
if num[l] < val:
l += 1
return l
def __dfs__(l, r):
now = __upper_bound__(r + 1) - __upper_bound__(l)
if now == 0:
return a
if l == r:
return now * b
mid = l + r >> 1
num = __dfs__(l, mid) + __dfs__(mid + 1, r)
return min(now * b * (r - l + 1), num)
def __solve__():
line = input().split()
global n
n = int(line[0])
global k
k = int(line[1])
global a
a = int(line[2])
global b
b = int(line[3])
global num
num = input().split()
for i in range(k):
num[i] = int(num[i])
num.sort(key=None, reverse=False)
print(__dfs__(1, 1 << n))
__solve__() | ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST 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 ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR VAR RETURN VAR IF VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR IF VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NONE NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR |
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.
Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of $2$. Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following: if the current length is at least $2$, divide the base into $2$ equal halves and destroy them separately, or burn the current base. If it contains no avenger in it, it takes $A$ amount of power, otherwise it takes his $B \cdot n_a \cdot l$ amount of power, where $n_a$ is the number of avengers and $l$ is the length of the current base. Output the minimum power needed by Thanos to destroy the avengers' base.
-----Input-----
The first line contains four integers $n$, $k$, $A$ and $B$ ($1 \leq n \leq 30$, $1 \leq k \leq 10^5$, $1 \leq A,B \leq 10^4$), where $2^n$ is the length of the base, $k$ is the number of avengers and $A$ and $B$ are the constants explained in the question.
The second line contains $k$ integers $a_{1}, a_{2}, a_{3}, \ldots, a_{k}$ ($1 \leq a_{i} \leq 2^n$), where $a_{i}$ represents the position of avenger in the base.
-----Output-----
Output one integer β the minimum power needed to destroy the avengers base.
-----Examples-----
Input
2 2 1 2
1 3
Output
6
Input
3 2 1 2
1 7
Output
8
-----Note-----
Consider the first example.
One option for Thanos is to burn the whole base $1-4$ with power $2 \cdot 2 \cdot 4 = 16$.
Otherwise he can divide the base into two parts $1-2$ and $3-4$.
For base $1-2$, he can either burn it with power $2 \cdot 1 \cdot 2 = 4$ or divide it into $2$ parts $1-1$ and $2-2$.
For base $1-1$, he can burn it with power $2 \cdot 1 \cdot 1 = 2$. For $2-2$, he can destroy it with power $1$, as there are no avengers. So, the total power for destroying $1-2$ is $2 + 1 = 3$, which is less than $4$.
Similarly, he needs $3$ power to destroy $3-4$. The total minimum power needed is $6$. | def I():
return list(map(int, input().split()))
def rec(l, r):
numavens = getnums(l, r)
if numavens == 0:
return a
if l == r:
return b * numavens
mid = (r - l) // 2 + l
return min((r - l + 1) * numavens * b, rec(l, mid) + rec(mid + 1, r))
def getnums(l, r):
if l == 0:
return get(r)
return get(r) - get(l - 1)
def get(t):
l = 0
r = k - 1
while l <= r:
mid = (r - l) // 2 + l
if x[mid] <= t:
l = mid + 1
else:
r = mid - 1
return l
n, k, a, b = I()
x = I()
x.sort()
l = 1
r = 2**n
print(rec(l, r)) | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN VAR IF VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_DEF IF VAR NUMBER RETURN FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.
Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of $2$. Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following: if the current length is at least $2$, divide the base into $2$ equal halves and destroy them separately, or burn the current base. If it contains no avenger in it, it takes $A$ amount of power, otherwise it takes his $B \cdot n_a \cdot l$ amount of power, where $n_a$ is the number of avengers and $l$ is the length of the current base. Output the minimum power needed by Thanos to destroy the avengers' base.
-----Input-----
The first line contains four integers $n$, $k$, $A$ and $B$ ($1 \leq n \leq 30$, $1 \leq k \leq 10^5$, $1 \leq A,B \leq 10^4$), where $2^n$ is the length of the base, $k$ is the number of avengers and $A$ and $B$ are the constants explained in the question.
The second line contains $k$ integers $a_{1}, a_{2}, a_{3}, \ldots, a_{k}$ ($1 \leq a_{i} \leq 2^n$), where $a_{i}$ represents the position of avenger in the base.
-----Output-----
Output one integer β the minimum power needed to destroy the avengers base.
-----Examples-----
Input
2 2 1 2
1 3
Output
6
Input
3 2 1 2
1 7
Output
8
-----Note-----
Consider the first example.
One option for Thanos is to burn the whole base $1-4$ with power $2 \cdot 2 \cdot 4 = 16$.
Otherwise he can divide the base into two parts $1-2$ and $3-4$.
For base $1-2$, he can either burn it with power $2 \cdot 1 \cdot 2 = 4$ or divide it into $2$ parts $1-1$ and $2-2$.
For base $1-1$, he can burn it with power $2 \cdot 1 \cdot 1 = 2$. For $2-2$, he can destroy it with power $1$, as there are no avengers. So, the total power for destroying $1-2$ is $2 + 1 = 3$, which is less than $4$.
Similarly, he needs $3$ power to destroy $3-4$. The total minimum power needed is $6$. | n, k, a, b = list(map(int, input().split()))
l = list(map(int, input().split()))
l.sort()
def se(st, en):
nonlocal l
c = 0
lo = 0
hi = len(l) - 1
while lo <= hi:
mid = (lo + hi) // 2
if l[mid] <= en:
lo = mid + 1
else:
hi = mid - 1
c += hi
lo = 0
hi = len(l) - 1
while lo <= hi:
mid = (lo + hi) // 2
if l[mid] >= st:
hi = mid - 1
else:
lo = mid + 1
return c - lo + 1
def f(st, en):
nonlocal n, a, b
t = se(st, en)
if st == en:
if t == 0:
return a
else:
return b * t * 1
else:
le = en - st + 1
if t == 0:
return a
else:
return min(b * t * le, f(st, st + le // 2 - 1) + f(st + le // 2, en))
print(f(1, 2**n)) | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF VAR NUMBER RETURN VAR RETURN BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR |
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.
Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of $2$. Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following: if the current length is at least $2$, divide the base into $2$ equal halves and destroy them separately, or burn the current base. If it contains no avenger in it, it takes $A$ amount of power, otherwise it takes his $B \cdot n_a \cdot l$ amount of power, where $n_a$ is the number of avengers and $l$ is the length of the current base. Output the minimum power needed by Thanos to destroy the avengers' base.
-----Input-----
The first line contains four integers $n$, $k$, $A$ and $B$ ($1 \leq n \leq 30$, $1 \leq k \leq 10^5$, $1 \leq A,B \leq 10^4$), where $2^n$ is the length of the base, $k$ is the number of avengers and $A$ and $B$ are the constants explained in the question.
The second line contains $k$ integers $a_{1}, a_{2}, a_{3}, \ldots, a_{k}$ ($1 \leq a_{i} \leq 2^n$), where $a_{i}$ represents the position of avenger in the base.
-----Output-----
Output one integer β the minimum power needed to destroy the avengers base.
-----Examples-----
Input
2 2 1 2
1 3
Output
6
Input
3 2 1 2
1 7
Output
8
-----Note-----
Consider the first example.
One option for Thanos is to burn the whole base $1-4$ with power $2 \cdot 2 \cdot 4 = 16$.
Otherwise he can divide the base into two parts $1-2$ and $3-4$.
For base $1-2$, he can either burn it with power $2 \cdot 1 \cdot 2 = 4$ or divide it into $2$ parts $1-1$ and $2-2$.
For base $1-1$, he can burn it with power $2 \cdot 1 \cdot 1 = 2$. For $2-2$, he can destroy it with power $1$, as there are no avengers. So, the total power for destroying $1-2$ is $2 + 1 = 3$, which is less than $4$.
Similarly, he needs $3$ power to destroy $3-4$. The total minimum power needed is $6$. | n, k, A, B = list(map(int, input().split()))
n = 2**n
a = list(sorted(list(map(int, input().split()))))
def recurs(start, end, array):
if len(array) == 0:
return A
if end - start == 1:
return B * len(array)
middle = (start + end) // 2
c, d = [], []
for x in array:
if x < middle:
c += [x]
else:
d += [x]
return min(
B * len(array) * (end - start),
recurs(start, middle, c) + recurs(middle, end, d),
)
print(recurs(1, n + 1, a)) | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN VAR IF BIN_OP VAR VAR NUMBER RETURN BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR LIST LIST FOR VAR VAR IF VAR VAR VAR LIST VAR VAR LIST VAR RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR |
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.
Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of $2$. Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following: if the current length is at least $2$, divide the base into $2$ equal halves and destroy them separately, or burn the current base. If it contains no avenger in it, it takes $A$ amount of power, otherwise it takes his $B \cdot n_a \cdot l$ amount of power, where $n_a$ is the number of avengers and $l$ is the length of the current base. Output the minimum power needed by Thanos to destroy the avengers' base.
-----Input-----
The first line contains four integers $n$, $k$, $A$ and $B$ ($1 \leq n \leq 30$, $1 \leq k \leq 10^5$, $1 \leq A,B \leq 10^4$), where $2^n$ is the length of the base, $k$ is the number of avengers and $A$ and $B$ are the constants explained in the question.
The second line contains $k$ integers $a_{1}, a_{2}, a_{3}, \ldots, a_{k}$ ($1 \leq a_{i} \leq 2^n$), where $a_{i}$ represents the position of avenger in the base.
-----Output-----
Output one integer β the minimum power needed to destroy the avengers base.
-----Examples-----
Input
2 2 1 2
1 3
Output
6
Input
3 2 1 2
1 7
Output
8
-----Note-----
Consider the first example.
One option for Thanos is to burn the whole base $1-4$ with power $2 \cdot 2 \cdot 4 = 16$.
Otherwise he can divide the base into two parts $1-2$ and $3-4$.
For base $1-2$, he can either burn it with power $2 \cdot 1 \cdot 2 = 4$ or divide it into $2$ parts $1-1$ and $2-2$.
For base $1-1$, he can burn it with power $2 \cdot 1 \cdot 1 = 2$. For $2-2$, he can destroy it with power $1$, as there are no avengers. So, the total power for destroying $1-2$ is $2 + 1 = 3$, which is less than $4$.
Similarly, he needs $3$ power to destroy $3-4$. The total minimum power needed is $6$. | n, k, A, B = map(int, input().split())
def solve(l, r, a):
if len(a) == 0:
return A
if l == r:
return B * len(a)
mid = (l + r) // 2
lx = []
rx = []
for i in a:
if i <= mid:
lx.append(i)
else:
rx.append(i)
return min(B * len(a) * (r - l + 1), solve(l, mid, lx) + solve(mid + 1, r, rx))
a = list(map(int, input().split()))
print(solve(1, 1 << n, a)) | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN VAR IF VAR VAR RETURN BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR VAR |
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.
Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of $2$. Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following: if the current length is at least $2$, divide the base into $2$ equal halves and destroy them separately, or burn the current base. If it contains no avenger in it, it takes $A$ amount of power, otherwise it takes his $B \cdot n_a \cdot l$ amount of power, where $n_a$ is the number of avengers and $l$ is the length of the current base. Output the minimum power needed by Thanos to destroy the avengers' base.
-----Input-----
The first line contains four integers $n$, $k$, $A$ and $B$ ($1 \leq n \leq 30$, $1 \leq k \leq 10^5$, $1 \leq A,B \leq 10^4$), where $2^n$ is the length of the base, $k$ is the number of avengers and $A$ and $B$ are the constants explained in the question.
The second line contains $k$ integers $a_{1}, a_{2}, a_{3}, \ldots, a_{k}$ ($1 \leq a_{i} \leq 2^n$), where $a_{i}$ represents the position of avenger in the base.
-----Output-----
Output one integer β the minimum power needed to destroy the avengers base.
-----Examples-----
Input
2 2 1 2
1 3
Output
6
Input
3 2 1 2
1 7
Output
8
-----Note-----
Consider the first example.
One option for Thanos is to burn the whole base $1-4$ with power $2 \cdot 2 \cdot 4 = 16$.
Otherwise he can divide the base into two parts $1-2$ and $3-4$.
For base $1-2$, he can either burn it with power $2 \cdot 1 \cdot 2 = 4$ or divide it into $2$ parts $1-1$ and $2-2$.
For base $1-1$, he can burn it with power $2 \cdot 1 \cdot 1 = 2$. For $2-2$, he can destroy it with power $1$, as there are no avengers. So, the total power for destroying $1-2$ is $2 + 1 = 3$, which is less than $4$.
Similarly, he needs $3$ power to destroy $3-4$. The total minimum power needed is $6$. | def helper(start, end, aveL, aveR):
if aveR - aveL == -1:
return A
if start == end:
return B * (aveR - aveL + 1)
temp = start + (end - start) // 2
l, r = aveL, aveR
while l <= r:
mid = l + (r - l) // 2
if avengers[mid] > temp:
r = mid - 1
else:
l = mid + 1
return min(
B * (aveR - aveL + 1) * (end - start + 1),
helper(start, temp, aveL, l - 1) + helper(temp + 1, end, l, aveR),
)
n, k, A, B = map(int, input().split())
avengers = sorted(map(int, input().split()))
print(helper(1, 2**n, 0, k - 1)) | FUNC_DEF IF BIN_OP VAR VAR NUMBER RETURN VAR IF VAR VAR RETURN BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR NUMBER BIN_OP VAR NUMBER |
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.
Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of $2$. Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following: if the current length is at least $2$, divide the base into $2$ equal halves and destroy them separately, or burn the current base. If it contains no avenger in it, it takes $A$ amount of power, otherwise it takes his $B \cdot n_a \cdot l$ amount of power, where $n_a$ is the number of avengers and $l$ is the length of the current base. Output the minimum power needed by Thanos to destroy the avengers' base.
-----Input-----
The first line contains four integers $n$, $k$, $A$ and $B$ ($1 \leq n \leq 30$, $1 \leq k \leq 10^5$, $1 \leq A,B \leq 10^4$), where $2^n$ is the length of the base, $k$ is the number of avengers and $A$ and $B$ are the constants explained in the question.
The second line contains $k$ integers $a_{1}, a_{2}, a_{3}, \ldots, a_{k}$ ($1 \leq a_{i} \leq 2^n$), where $a_{i}$ represents the position of avenger in the base.
-----Output-----
Output one integer β the minimum power needed to destroy the avengers base.
-----Examples-----
Input
2 2 1 2
1 3
Output
6
Input
3 2 1 2
1 7
Output
8
-----Note-----
Consider the first example.
One option for Thanos is to burn the whole base $1-4$ with power $2 \cdot 2 \cdot 4 = 16$.
Otherwise he can divide the base into two parts $1-2$ and $3-4$.
For base $1-2$, he can either burn it with power $2 \cdot 1 \cdot 2 = 4$ or divide it into $2$ parts $1-1$ and $2-2$.
For base $1-1$, he can burn it with power $2 \cdot 1 \cdot 1 = 2$. For $2-2$, he can destroy it with power $1$, as there are no avengers. So, the total power for destroying $1-2$ is $2 + 1 = 3$, which is less than $4$.
Similarly, he needs $3$ power to destroy $3-4$. The total minimum power needed is $6$. | from sys import stdin
def input():
return stdin.readline()[:-1]
def recur(l, r, A, B, avengers):
if not avengers:
return A
if l == r:
return B * len(avengers)
else:
cost = B * len(avengers) * (r - l + 1)
mid = (l + r) // 2
x = []
y = []
for i in avengers:
if i <= mid:
x.append(i)
else:
y.append(i)
cost = min(cost, recur(l, mid, A, B, x) + recur(mid + 1, r, A, B, y))
return cost
n, k, A, B = map(int, input().split())
avengers = list(map(int, input().split()))
print(recur(1, 2**n, A, B, avengers)) | FUNC_DEF RETURN FUNC_CALL VAR NUMBER FUNC_DEF IF VAR RETURN VAR IF VAR VAR RETURN BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR VAR VAR VAR |
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.
Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of $2$. Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following: if the current length is at least $2$, divide the base into $2$ equal halves and destroy them separately, or burn the current base. If it contains no avenger in it, it takes $A$ amount of power, otherwise it takes his $B \cdot n_a \cdot l$ amount of power, where $n_a$ is the number of avengers and $l$ is the length of the current base. Output the minimum power needed by Thanos to destroy the avengers' base.
-----Input-----
The first line contains four integers $n$, $k$, $A$ and $B$ ($1 \leq n \leq 30$, $1 \leq k \leq 10^5$, $1 \leq A,B \leq 10^4$), where $2^n$ is the length of the base, $k$ is the number of avengers and $A$ and $B$ are the constants explained in the question.
The second line contains $k$ integers $a_{1}, a_{2}, a_{3}, \ldots, a_{k}$ ($1 \leq a_{i} \leq 2^n$), where $a_{i}$ represents the position of avenger in the base.
-----Output-----
Output one integer β the minimum power needed to destroy the avengers base.
-----Examples-----
Input
2 2 1 2
1 3
Output
6
Input
3 2 1 2
1 7
Output
8
-----Note-----
Consider the first example.
One option for Thanos is to burn the whole base $1-4$ with power $2 \cdot 2 \cdot 4 = 16$.
Otherwise he can divide the base into two parts $1-2$ and $3-4$.
For base $1-2$, he can either burn it with power $2 \cdot 1 \cdot 2 = 4$ or divide it into $2$ parts $1-1$ and $2-2$.
For base $1-1$, he can burn it with power $2 \cdot 1 \cdot 1 = 2$. For $2-2$, he can destroy it with power $1$, as there are no avengers. So, the total power for destroying $1-2$ is $2 + 1 = 3$, which is less than $4$.
Similarly, he needs $3$ power to destroy $3-4$. The total minimum power needed is $6$. | n, k, a, b = map(int, input().split())
arr = sorted(map(int, input().split()))
el = None
c = 0
d = []
for e in arr:
if el is None:
el = e
c = 1
elif el == e:
c += 1
else:
d.append((el - 1, c, c * b))
el = e
c = 1
d.append((el - 1, c, c * b))
for g in range(0, n):
i = 0
new_d = []
c_l = 2 ** (g + 1)
while i < len(d) - 1:
el, c, cost = d[i]
el2, c2, cost2 = d[i + 1]
if el % 2 == 0 and el2 - el == 1:
n_c = c + c2
new_d.append((int(el // 2), n_c, min(cost2 + cost, b * c_l * n_c)))
i += 2
else:
new_d.append((int(el // 2), c, min(cost + a, b * c_l * c)))
i += 1
if i < len(d):
el, c, cost = d[-1]
new_d.append((int(el // 2), c, min(cost + a, b * c_l * c)))
d = new_d
print(d[0][2]) | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NONE ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR NONE ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER |
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.
Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of $2$. Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following: if the current length is at least $2$, divide the base into $2$ equal halves and destroy them separately, or burn the current base. If it contains no avenger in it, it takes $A$ amount of power, otherwise it takes his $B \cdot n_a \cdot l$ amount of power, where $n_a$ is the number of avengers and $l$ is the length of the current base. Output the minimum power needed by Thanos to destroy the avengers' base.
-----Input-----
The first line contains four integers $n$, $k$, $A$ and $B$ ($1 \leq n \leq 30$, $1 \leq k \leq 10^5$, $1 \leq A,B \leq 10^4$), where $2^n$ is the length of the base, $k$ is the number of avengers and $A$ and $B$ are the constants explained in the question.
The second line contains $k$ integers $a_{1}, a_{2}, a_{3}, \ldots, a_{k}$ ($1 \leq a_{i} \leq 2^n$), where $a_{i}$ represents the position of avenger in the base.
-----Output-----
Output one integer β the minimum power needed to destroy the avengers base.
-----Examples-----
Input
2 2 1 2
1 3
Output
6
Input
3 2 1 2
1 7
Output
8
-----Note-----
Consider the first example.
One option for Thanos is to burn the whole base $1-4$ with power $2 \cdot 2 \cdot 4 = 16$.
Otherwise he can divide the base into two parts $1-2$ and $3-4$.
For base $1-2$, he can either burn it with power $2 \cdot 1 \cdot 2 = 4$ or divide it into $2$ parts $1-1$ and $2-2$.
For base $1-1$, he can burn it with power $2 \cdot 1 \cdot 1 = 2$. For $2-2$, he can destroy it with power $1$, as there are no avengers. So, the total power for destroying $1-2$ is $2 + 1 = 3$, which is less than $4$.
Similarly, he needs $3$ power to destroy $3-4$. The total minimum power needed is $6$. | from sys import setrecursionlimit
setrecursionlimit(1000000000)
n, k, A, B = map(int, input().split())
av = [0] + list(map(int, input().split()))
av.sort()
def solve(ss, se):
st, en = -1, -1
l, h = 0, k
while l <= h:
m = (l + h) // 2
if av[m] < ss:
st = m
l = m + 1
else:
h = m - 1
l, h = 0, k
while l <= h:
m = (l + h) // 2
if av[m] <= se:
en = m
l = m + 1
else:
h = m - 1
na = en - st
if na == 0:
return A
else:
burn = na * B * (se - ss + 1)
if ss == se:
return burn
x = solve(ss, ss + (se - ss + 1) // 2 - 1)
y = solve(ss + (se - ss + 1) // 2, se)
return min(burn, x + y)
print(solve(1, 1 << n)) | EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR |
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.
Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of $2$. Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following: if the current length is at least $2$, divide the base into $2$ equal halves and destroy them separately, or burn the current base. If it contains no avenger in it, it takes $A$ amount of power, otherwise it takes his $B \cdot n_a \cdot l$ amount of power, where $n_a$ is the number of avengers and $l$ is the length of the current base. Output the minimum power needed by Thanos to destroy the avengers' base.
-----Input-----
The first line contains four integers $n$, $k$, $A$ and $B$ ($1 \leq n \leq 30$, $1 \leq k \leq 10^5$, $1 \leq A,B \leq 10^4$), where $2^n$ is the length of the base, $k$ is the number of avengers and $A$ and $B$ are the constants explained in the question.
The second line contains $k$ integers $a_{1}, a_{2}, a_{3}, \ldots, a_{k}$ ($1 \leq a_{i} \leq 2^n$), where $a_{i}$ represents the position of avenger in the base.
-----Output-----
Output one integer β the minimum power needed to destroy the avengers base.
-----Examples-----
Input
2 2 1 2
1 3
Output
6
Input
3 2 1 2
1 7
Output
8
-----Note-----
Consider the first example.
One option for Thanos is to burn the whole base $1-4$ with power $2 \cdot 2 \cdot 4 = 16$.
Otherwise he can divide the base into two parts $1-2$ and $3-4$.
For base $1-2$, he can either burn it with power $2 \cdot 1 \cdot 2 = 4$ or divide it into $2$ parts $1-1$ and $2-2$.
For base $1-1$, he can burn it with power $2 \cdot 1 \cdot 1 = 2$. For $2-2$, he can destroy it with power $1$, as there are no avengers. So, the total power for destroying $1-2$ is $2 + 1 = 3$, which is less than $4$.
Similarly, he needs $3$ power to destroy $3-4$. The total minimum power needed is $6$. | def solve(l, r, y):
if len(y) == 0:
return a
if l == r:
return b * len(y)
c = []
d = []
m = (l + r) // 2
for i in y:
if i <= m:
c += [i]
else:
d += [i]
return min(b * (r - l + 1) * len(y), solve(l, m, c) + solve(m + 1, r, d))
n, k, a, b = list(map(int, input().split()))
x = list(map(int, input().split()))
print(solve(1, 1 << n, x)) | FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN VAR IF VAR VAR RETURN BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR LIST VAR VAR LIST VAR RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR VAR |
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.
Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of $2$. Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following: if the current length is at least $2$, divide the base into $2$ equal halves and destroy them separately, or burn the current base. If it contains no avenger in it, it takes $A$ amount of power, otherwise it takes his $B \cdot n_a \cdot l$ amount of power, where $n_a$ is the number of avengers and $l$ is the length of the current base. Output the minimum power needed by Thanos to destroy the avengers' base.
-----Input-----
The first line contains four integers $n$, $k$, $A$ and $B$ ($1 \leq n \leq 30$, $1 \leq k \leq 10^5$, $1 \leq A,B \leq 10^4$), where $2^n$ is the length of the base, $k$ is the number of avengers and $A$ and $B$ are the constants explained in the question.
The second line contains $k$ integers $a_{1}, a_{2}, a_{3}, \ldots, a_{k}$ ($1 \leq a_{i} \leq 2^n$), where $a_{i}$ represents the position of avenger in the base.
-----Output-----
Output one integer β the minimum power needed to destroy the avengers base.
-----Examples-----
Input
2 2 1 2
1 3
Output
6
Input
3 2 1 2
1 7
Output
8
-----Note-----
Consider the first example.
One option for Thanos is to burn the whole base $1-4$ with power $2 \cdot 2 \cdot 4 = 16$.
Otherwise he can divide the base into two parts $1-2$ and $3-4$.
For base $1-2$, he can either burn it with power $2 \cdot 1 \cdot 2 = 4$ or divide it into $2$ parts $1-1$ and $2-2$.
For base $1-1$, he can burn it with power $2 \cdot 1 \cdot 1 = 2$. For $2-2$, he can destroy it with power $1$, as there are no avengers. So, the total power for destroying $1-2$ is $2 + 1 = 3$, which is less than $4$.
Similarly, he needs $3$ power to destroy $3-4$. The total minimum power needed is $6$. | def ans(arr, l, r, a, b):
if len(arr) == 0:
return a
if l == r:
return len(arr) * b
arr_left = []
arr_right = []
mid = (l + r) // 2
for el in arr:
if l <= el <= mid:
arr_left += [el]
if mid + 1 <= el <= r:
arr_right += [el]
return min(
b * len(arr) * (r - l + 1),
ans(arr_left, l, mid, a, b) + ans(arr_right, mid + 1, r, a, b),
)
n, k, a, b = list(map(int, input().split()))
arr = [(int(i) - 1) for i in input().split()]
print(ans(arr, 0, (1 << n) - 1, a, b)) | FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN VAR IF VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR LIST VAR IF BIN_OP VAR NUMBER VAR VAR VAR LIST VAR RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR |
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.
Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of $2$. Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following: if the current length is at least $2$, divide the base into $2$ equal halves and destroy them separately, or burn the current base. If it contains no avenger in it, it takes $A$ amount of power, otherwise it takes his $B \cdot n_a \cdot l$ amount of power, where $n_a$ is the number of avengers and $l$ is the length of the current base. Output the minimum power needed by Thanos to destroy the avengers' base.
-----Input-----
The first line contains four integers $n$, $k$, $A$ and $B$ ($1 \leq n \leq 30$, $1 \leq k \leq 10^5$, $1 \leq A,B \leq 10^4$), where $2^n$ is the length of the base, $k$ is the number of avengers and $A$ and $B$ are the constants explained in the question.
The second line contains $k$ integers $a_{1}, a_{2}, a_{3}, \ldots, a_{k}$ ($1 \leq a_{i} \leq 2^n$), where $a_{i}$ represents the position of avenger in the base.
-----Output-----
Output one integer β the minimum power needed to destroy the avengers base.
-----Examples-----
Input
2 2 1 2
1 3
Output
6
Input
3 2 1 2
1 7
Output
8
-----Note-----
Consider the first example.
One option for Thanos is to burn the whole base $1-4$ with power $2 \cdot 2 \cdot 4 = 16$.
Otherwise he can divide the base into two parts $1-2$ and $3-4$.
For base $1-2$, he can either burn it with power $2 \cdot 1 \cdot 2 = 4$ or divide it into $2$ parts $1-1$ and $2-2$.
For base $1-1$, he can burn it with power $2 \cdot 1 \cdot 1 = 2$. For $2-2$, he can destroy it with power $1$, as there are no avengers. So, the total power for destroying $1-2$ is $2 + 1 = 3$, which is less than $4$.
Similarly, he needs $3$ power to destroy $3-4$. The total minimum power needed is $6$. | n, k, A, B = list(map(int, input().split()))
n = 2**n
a = sorted(list(map(int, input().split())))
def recurs(start, end, sum_all, array):
if sum_all == 0:
return A
else:
energy = B * (end - start) * sum_all
if end - start == 1:
return energy
c, d = [], []
for x in array:
if x < (start + end) // 2:
c += [x]
else:
d += [x]
first = len(c)
second = sum_all - first
tmp = recurs(start, (start + end) // 2, first, c)
tmp += recurs((start + end) // 2, end, second, d)
return (energy < tmp) * energy + (1 - (energy < tmp)) * tmp
print(recurs(1, n + 1, k, a)) | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR LIST LIST FOR VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR LIST VAR VAR LIST VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR |
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.
Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of $2$. Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following: if the current length is at least $2$, divide the base into $2$ equal halves and destroy them separately, or burn the current base. If it contains no avenger in it, it takes $A$ amount of power, otherwise it takes his $B \cdot n_a \cdot l$ amount of power, where $n_a$ is the number of avengers and $l$ is the length of the current base. Output the minimum power needed by Thanos to destroy the avengers' base.
-----Input-----
The first line contains four integers $n$, $k$, $A$ and $B$ ($1 \leq n \leq 30$, $1 \leq k \leq 10^5$, $1 \leq A,B \leq 10^4$), where $2^n$ is the length of the base, $k$ is the number of avengers and $A$ and $B$ are the constants explained in the question.
The second line contains $k$ integers $a_{1}, a_{2}, a_{3}, \ldots, a_{k}$ ($1 \leq a_{i} \leq 2^n$), where $a_{i}$ represents the position of avenger in the base.
-----Output-----
Output one integer β the minimum power needed to destroy the avengers base.
-----Examples-----
Input
2 2 1 2
1 3
Output
6
Input
3 2 1 2
1 7
Output
8
-----Note-----
Consider the first example.
One option for Thanos is to burn the whole base $1-4$ with power $2 \cdot 2 \cdot 4 = 16$.
Otherwise he can divide the base into two parts $1-2$ and $3-4$.
For base $1-2$, he can either burn it with power $2 \cdot 1 \cdot 2 = 4$ or divide it into $2$ parts $1-1$ and $2-2$.
For base $1-1$, he can burn it with power $2 \cdot 1 \cdot 1 = 2$. For $2-2$, he can destroy it with power $1$, as there are no avengers. So, the total power for destroying $1-2$ is $2 + 1 = 3$, which is less than $4$.
Similarly, he needs $3$ power to destroy $3-4$. The total minimum power needed is $6$. | def searchlow(arr, l, r, x):
if arr[-1] < x:
return -1
while l <= r:
m = (l + r) // 2
if arr[m] >= x:
r = m - 1
else:
l = m + 1
return r + 1
def searchhigh(arr, l, r, x):
if arr[0] > x:
return -1
while l <= r:
m = (l + r) // 2
if arr[m] > x:
r = m - 1
else:
l = m + 1
return l - 1
def power(low, high):
high1 = searchhigh(av, 0, len(av) - 1, high)
low1 = searchlow(av, 0, len(av) - 1, low)
if high1 == -1 or low1 == -1 or low1 > high1:
count = 0
else:
count = high1 - low1 + 1
if low == high:
if count != 0:
return b * (high - low + 1) * count
else:
return a
if count == 0:
return a
else:
return min(
b * count * (high - low + 1),
power(low, (low + high) // 2) + power((low + high) // 2 + 1, high),
)
n, k, a, b = list(map(int, input().split()))
av = list(map(int, input().split()))
av.sort()
print(power(1, 2**n)) | FUNC_DEF IF VAR NUMBER VAR RETURN NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER VAR RETURN NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR IF VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR IF VAR NUMBER RETURN BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN VAR IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR |
As usual, Sereja has array a, its elements are integers: a[1], a[2], ..., a[n]. Let's introduce notation:
<image>
A swap operation is the following sequence of actions:
* choose two indexes i, j (i β j);
* perform assignments tmp = a[i], a[i] = a[j], a[j] = tmp.
What maximum value of function m(a) can Sereja get if he is allowed to perform at most k swap operations?
Input
The first line contains two integers n and k (1 β€ n β€ 200; 1 β€ k β€ 10). The next line contains n integers a[1], a[2], ..., a[n] ( - 1000 β€ a[i] β€ 1000).
Output
In a single line print the maximum value of m(a) that Sereja can get if he is allowed to perform at most k swap operations.
Examples
Input
10 2
10 -1 2 2 2 2 2 2 -1 10
Output
32
Input
5 10
-1 -1 -1 -1 -1
Output
-1 | read_line = lambda: [int(i) for i in input().split()]
n, k = read_line()
x = read_line()
print(
max(
sum(sorted(x[l:r] + sorted(x[:l] + x[r:])[-k:])[l - r :])
for l in range(n)
for r in range(l + 1, n + 1)
)
) | ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER |
As usual, Sereja has array a, its elements are integers: a[1], a[2], ..., a[n]. Let's introduce notation:
<image>
A swap operation is the following sequence of actions:
* choose two indexes i, j (i β j);
* perform assignments tmp = a[i], a[i] = a[j], a[j] = tmp.
What maximum value of function m(a) can Sereja get if he is allowed to perform at most k swap operations?
Input
The first line contains two integers n and k (1 β€ n β€ 200; 1 β€ k β€ 10). The next line contains n integers a[1], a[2], ..., a[n] ( - 1000 β€ a[i] β€ 1000).
Output
In a single line print the maximum value of m(a) that Sereja can get if he is allowed to perform at most k swap operations.
Examples
Input
10 2
10 -1 2 2 2 2 2 2 -1 10
Output
32
Input
5 10
-1 -1 -1 -1 -1
Output
-1 | n, k = map(int, input().split())
a = list(map(int, input().split()))
r_sum = a[0]
for l in range(n):
for r in range(l, n):
inside = sorted(a[l : r + 1])
outside = sorted(a[:l] + a[r + 1 :], reverse=True)
t_sum = sum(inside)
for i in range(min(k, len(inside), len(outside))):
if outside[i] > inside[i]:
t_sum += outside[i] - inside[i]
else:
break
if t_sum > r_sum:
r_sum = t_sum
print(r_sum) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | input()
x = sorted(map(int, input().split()))
suml = 0
sumr = sum(x)
res = 0
resv = float("inf")
for i in range(len(x)):
dist = x[i] * i - suml + sumr - x[i] * (len(x) - i)
if dist < resv:
res = x[i]
resv = dist
suml += x[i]
sumr -= x[i]
print(res) | EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | n = int(input())
dots = [int(x) for x in input().split()]
dots.sort()
dot = dots[0]
left = 0
right = sum([abs(x - dot) for x in dots])
results = [right]
for i in range(1, n):
ldot = dot
dot = dots[i]
left += (dot - ldot) * i
right -= (dot - ldot) * (n - i)
results.append(left + right)
print(dots[results.index(min(results))]) | 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 NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | try:
while True:
n = int(input())
a = sorted(map(int, input().split()))
ls = 0
result = rs = sum(a) - a[0] * n
index = 0
for i in range(1, n):
d = a[i] - a[i - 1]
ls += d * i
rs -= d * (n - i)
if ls + rs < result:
result = ls + rs
index = i
print(a[index])
except EOFError:
pass | WHILE NUMBER 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 ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | n = int(input())
a = list(map(int, input().split()))
a.sort()
if n % 2 == 0:
print(a[n // 2 - 1])
else:
print(a[n // 2]) | 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 IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | n = int(input())
L = list(map(int, input().split()))
L.sort()
if n % 2 == 0:
ans = n // 2 - 1
else:
ans = n // 2
print(L[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 IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | def get_median(data, n):
data.sort()
return data[int((n + 1) / 2) - 1]
def main():
n = int(input())
nNumsLine = list(map(int, input().split()))
print(int(get_median(nNumsLine, n)))
main() | FUNC_DEF EXPR FUNC_CALL VAR RETURN VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER 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 FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | def opPoint(arr, point):
range = 0
for t in arr:
range += abs(point - t)
return range
def diff(len, ind, val):
return (2 * ind - len) * val
len = int(input())
a = list(map(int, input().split()))
a.sort()
av = sum(a) / len
min_ind = a[0]
min_range = opPoint(a, a[0])
last_r = min_range
for i in range(1, len):
last_r = last_r + diff(len, i, a[i] - a[i - 1])
if min_range > last_r:
min_range = last_r
min_ind = a[i]
print(min_ind) | FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | n = int(input())
l = list(map(int, input().split()))
l.sort()
x = n // 2
if n % 2 == 0:
x -= 1
print(l[x]) | 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 IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | n = int(input())
points = sorted(tuple(map(int, input().split())))
def calc(points, start, stop, step):
n = len(points)
ans = [None] * n
ans[start] = 0
cnt = 1
for i in range(start + step, stop, step):
ans[i] = ans[i - step] + abs(points[i] - points[i - step]) * cnt
cnt += 1
return ans
calc1 = calc(points, 0, n, 1)
calc2 = calc(points, n - 1, -1, -1)
mini, minv = -1, float("inf")
for i in range(n):
if calc1[i] + calc2[i] < minv:
minv = calc1[i] + calc2[i]
mini = points[i]
print(mini) | 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 FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | MOD = 1000000007
ii = lambda: int(input())
si = lambda: input()
dgl = lambda: list(map(int, input()))
f = lambda: map(int, input().split())
il = lambda: list(map(int, input().split()))
ls = lambda: list(input())
n = ii()
l = sorted(il())
print(l[(n - 1) // 2]) | ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | n = int(input())
s = input().split()
for i in range(n):
s[i] = int(s[i])
s.sort()
if n % 2 != 0:
print(s[n // 2])
else:
print(s[n // 2 - 1]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | N = int(input())
number_list = list(map(int, input().split(" ")))
number_list.sort()
mid = len(number_list) // 2
if len(number_list) % 2 == 0:
median = (number_list[mid - 1] + number_list[mid]) / 2.0
else:
median = number_list[mid]
min_value = min(abs(i - median) for i in number_list)
temp = []
for j in number_list:
if abs(j - median) == min_value:
temp.append(j)
print(temp[0]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | n = int(input())
x = list(map(int, input().split()))
x.sort()
s = sum(x)
it = x[0]
m = s - n * x[0]
result = x[0]
for i in range(1, n):
cur = s - it - (n - i) * x[i] + (i * x[i] - it)
it += x[i]
if cur < m:
result = x[i]
m = cur
print(result) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | import sys
input = sys.stdin.readline
def ceil(x, y):
return (x + y - 1) // y
def swaparr(arr, a, b):
temp = arr[a]
arr[a] = arr[b]
arr[b] = temp
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def nCr(n, k):
if k > n - k:
k = n - k
res = 1
for i in range(k):
res = res * (n - i)
res = res / (i + 1)
return int(res)
def upper_bound(a, x, lo=0):
hi = len(a)
while lo < hi:
mid = (lo + hi) // 2
if a[mid] < x:
lo = mid + 1
else:
hi = mid
return lo
def primefs(n):
primes = {}
while n % 2 == 0 and n > 0:
primes[2] = primes.get(2, 0) + 1
n = n // 2
for i in range(3, int(n**0.5) + 2, 2):
while n % i == 0 and n > 0:
primes[i] = primes.get(i, 0) + 1
n = n // i
if n > 2:
primes[n] = primes.get(n, 0) + 1
return primes
def power(x, y, p):
res = 1
x = x % p
if x == 0:
return 0
while y > 0:
if y & 1 == 1:
res = res * x % p
y = y >> 1
x = x * x % p
return res
def swap(a, b):
temp = a
a = b
b = temp
return a, b
def find(x, link):
p = x
while p != link[p]:
p = link[p]
while x != p:
nex = link[x]
link[x] = p
x = nex
return p
def union(x, y, link, size):
x = find(x, link)
y = find(y, link)
if size[x] < size[y]:
x, y = swap(x, y)
if x != y:
size[x] += size[y]
link[y] = x
def sieve(n):
prime = [(True) for i in range(n + 1)]
p = 2
while p * p <= n:
if prime[p] == True:
for i in range(p * p, n + 1, p):
prime[i] = False
p += 1
return prime
MAXN = int(10000000.0 + 5)
def spf_sieve():
spf[1] = 1
for i in range(2, MAXN):
spf[i] = i
for i in range(4, MAXN, 2):
spf[i] = 2
for i in range(3, ceil(MAXN**0.5), 2):
if spf[i] == i:
for j in range(i * i, MAXN, i):
if spf[j] == j:
spf[j] = i
def factoriazation(x):
ret = {}
while x != 1:
ret[spf[x]] = ret.get(spf[x], 0) + 1
x = x // spf[x]
return ret
def int_array():
return list(map(int, input().strip().split()))
def str_array():
return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float("inf")
NINF = -float("inf")
n = int(input())
a = sorted(int_array())
if n & 1:
print(a[n // 2])
else:
x = a[n // 2 - 1]
y = a[n // 2]
ans1 = ans2 = 0
for i in a:
ans1 += abs(x - i)
ans2 += abs(y - i)
if ans1 <= ans2:
print(x)
else:
print(y) | IMPORT ASSIGN VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR FUNC_DEF NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR DICT WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR WHILE VAR VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR DICT WHILE VAR NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | def d(a, x):
t = 0
for n in a:
t += abs(n - x)
return t
def solve():
n = int(input())
a = list(map(int, input().split()))
a.sort()
if n % 2 == 0:
if d(a, a[n // 2 - 1]) <= d(a, a[n // 2]):
print(a[n // 2 - 1])
else:
print(a[n // 2])
else:
print(a[n // 2])
def main():
solve()
def __starting_point():
main()
__starting_point() | FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | def main():
n = int(input())
arr = map(int, str(input()).split())
arr = list(sorted(arr))
if n % 2 == 0:
n = int(n / 2)
else:
n = int(n / 2 + 1)
print(arr[n - 1])
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | numPoints = int(input())
points = list(map(int, input().split(" ")))
points.sort()
def calcVal(point, points):
tally = 0
for i in range(len(points)):
tally += abs(points[i] - point)
return tally
if len(points) % 2 == 0:
leftDex = len(points) // 2 - 1
rightDex = len(points) // 2
print(points[leftDex])
else:
index = len(points) // 2
print(points[index]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | n = int(input())
arr = sorted(list(map(int, input().split())))
if len(arr) % 2 == 0:
print(arr[len(arr) // 2 - 1])
else:
print(arr[len(arr) // 2]) | 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 BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | n = int(input())
x = [int(p) for p in input().split()]
x.sort()
S = [0]
for i in range(0, n):
S.append(S[i] + x[i])
L = []
R = []
for i in range(0, n):
L.append(i * x[i] - S[i])
R.append(S[n] - S[i + 1] - (n - i - 1) * x[i])
mind = L[0] + R[0]
mini = 0
for i in range(1, n):
d = L[i] + R[i]
if d < mind:
mind, mini = d, i
print(x[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 LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | from sys import stdin, stdout
def right_range(x):
return cntr[-1] - cntr[x] - (coordinate[x] - coordinate[0]) * (n - x - 1)
def left_range(x):
return cntl[0] - cntl[x] - (coordinate[-1] - coordinate[x]) * x
n = int(stdin.readline())
coordinate = sorted(list(map(int, stdin.readline().split())))
cntr = [0]
cntl = [0]
for i in range(1, n):
cntr.append(cntr[-1] + coordinate[i] - coordinate[0])
for i in range(n - 2, -1, -1):
cntl.append(cntl[-1] + coordinate[-1] - coordinate[i])
cntl = cntl[::-1]
ind = 0
for i in range(n):
if right_range(ind) + left_range(ind) > right_range(i) + left_range(i):
ind = i
stdout.write(str(coordinate[ind])) | FUNC_DEF RETURN BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR 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 LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | read = input().split(" ")
n = int(read[0])
tab = sorted(map(int, input().split(" ")))
wynik = tab[int((n - 1) / 2)]
print(wynik) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | N = int(input())
numbers = [int(n) for n in input().split()]
numbers.sort()
if N % 2 == 1:
Ans = numbers[N // 2]
print(Ans)
else:
Ans = numbers[N // 2 - 1]
print(Ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | def abs(x):
if x < 0:
return -x
else:
return x
inp = input()
n = int(inp)
x = input().split()
for i in range(0, n):
x[i] = int(x[i])
x.sort()
ans = 0
val = 0
for i in range(0, n):
val += x[i] - x[0]
ans = val
pnt = x[0]
diff = 0
for i in range(1, n):
diff = x[i] - x[i - 1]
val -= diff * (n - i)
val += diff * i
if ans > val:
pnt = x[i]
ans = val
print(pnt) | FUNC_DEF IF VAR NUMBER RETURN VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | def main():
n = int(input())
arr = [int(a) for a in input().split()]
arr.sort()
print(arr[len(arr) // 2 - 1 + len(arr) % 2])
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 EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | N = int(input())
X = list(map(int, input().split()))
X.sort()
if N % 2 != 0:
print(X[N // 2])
else:
left = sum([abs(x - X[N // 2 - 1]) for x in X])
right = sum([abs(x - X[N // 2]) for x in X])
if left <= right:
print(X[N // 2 - 1])
elif left > right:
print(X[N // 2]) | 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 IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | n = int(input())
x = sorted(list(map(int, input().split())))
P, N = 0, 0
a = n * [0]
for i in range(1, n):
P = (x[i] - x[i - 1]) * i + P
N = (x[-i] - x[-i - 1]) * i + N
a[i] += P
a[-i - 1] += N
print(x[a.index(min(a))]) | 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 VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | n = int(input())
a = input().split(" ")
for i in range(len(a)):
a[i] = int(a[i])
a.sort()
if len(a) % 2 == 0:
print(a[int(len(a) / 2) - 1])
else:
print(a[int(len(a) / 2)]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | import sys
INF = 10**9 + 3
fin = sys.stdin
fout = sys.stdout
n = int(fin.readline())
points = list(map(int, fin.readline().split()))
points.sort()
if n % 2 == 1:
fout.write(str(points[n // 2]))
else:
fout.write(str(points[n // 2 - 1])) | IMPORT ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | n = int(input())
line = sorted(list(map(int, input().split())))
a = 0
for i in range(1, n):
a += line[i] - line[0]
ind = line[0]
rasst = a
for i in range(1, n):
r = abs(line[i] - line[i - 1])
a1 = a - (n - i - 1) * r + (i - 1) * r
if a1 < rasst:
rasst = a1
ind = line[i]
a = a1
print(ind) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | import sys
input = sys.stdin.readline
n = int(input())
points = list(map(int, input().strip().split()))
points.sort()
if n % 2 == 1:
n = n // 2
else:
n = n // 2 - 1
print(points[n]) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | n = int(input())
s = list(map(int, input().strip().split()))
s.sort()
print(s[int(n / 2) - 1] if n % 2 == 0 else s[int(n / 2)]) | 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 EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | n = int(input())
array = list(map(int, input().split()))
array.sort()
summ = sum(array)
summ2 = 0
differences = [0] * n
for i in range(n):
differences[i] = summ - (summ2 + array[i]) - summ2
summ2 += array[i]
dist = [0] * n
for i in range(n):
dist[i] = array[i] * i + differences[i] - array[i] * (n - i - 1)
minId = 0
for i in range(n):
if dist[i] < dist[minId]:
minId = i
print(array[minId]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | n = int(input())
l = list(map(int, input().strip().split(" ")))
l.sort()
a = {(0): "even", (1): "odd"}
s = sum(l)
if a[n % 2] is "even":
n -= 1
sum1 = 0
for k in l:
sum1 += abs(k - l[int(n / 2)])
sum2 = 0
for k in l:
sum2 += abs(k - l[int((n + 1) / 2)])
if sum1 > sum2:
print(l[int((n + 1) / 2)])
else:
print(l[int(n / 2)])
else:
n -= 1
print(l[int(n / 2)]) | 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 EXPR FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER STRING STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | n = int(input())
a = list(map(int, input().split(" ")))
a.sort()
l = [0] * 333333
r = [0] * 333333
for i in range(1, n):
l[i] = l[i - 1] + i * (a[i] - a[i - 1])
for i in range(n - 2, -1, -1):
r[i] = r[i + 1] + (n - i - 1) * (a[i + 1] - a[i])
mn = 2222222222222222
ind = 0
for i in range(n):
if mn > l[i] + r[i]:
mn = l[i] + r[i]
ind = i
print(a[ind]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | n = int(input())
a = list(map(int, input().split()))
a.sort()
k = 0
r = 0
for i in range(1, n):
k = k + abs(a[i] - a[0])
if n % 2 == 1:
print(a[n // 2])
else:
for j in range(n):
r = r + abs(a[n // 2 - 1] - a[j])
for i in range(n):
k = k + abs(a[n // 2] - a[i])
if r <= k:
print(a[n // 2 - 1])
else:
print(a[n // 2]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | n = int(input())
X = [int(x) for x in input().split()]
X.sort()
lrdiff = n
cur = X[0]
for x in X:
if lrdiff > 0:
cur = x
lrdiff -= 2
continue
break
print(cur) | 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 ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | n = int(input())
l = sorted(list(map(int, input().split())))
h = len(l)
if h % 2 == 0:
h = int(h / 2 - 1)
else:
h = int(h // 2)
print(l[h]) | 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 VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | n = int(input())
dist = 0
dict = {}
change = -n + 2
lst = list(map(int, input().split()))
lst.sort()
n = 0
i1 = lst[0]
ret = lst[0]
for i in lst[1:]:
if change >= 0:
break
dist += change * (i - i1)
ret = i
n = dist
change += 2
i1 = i
print(ret) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
You are given n points on a line with their coordinates x_{i}. Find the point x so the sum of distances to the given points is minimal.
-----Input-----
The first line contains integer n (1 β€ n β€ 3Β·10^5) β the number of points on the line.
The second line contains n integers x_{i} ( - 10^9 β€ x_{i} β€ 10^9) β the coordinates of the given n points.
-----Output-----
Print the only integer x β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
-----Example-----
Input
4
1 2 3 4
Output
2 | n = int(input())
l = list(map(int, input().split()))
l.sort()
ls = [(0) for i in range(1, n + 1)]
ls[0] = l[0]
for i in range(1, n):
ls[i] = l[i] + ls[i - 1]
dis = 10**15 * 4
ans = 10**15
for i in range(0, n):
x = l[i] * (i + 1) - l[i] * (n - (i + 1)) - ls[i] + ls[-1] - ls[i]
if x < dis:
dis = x
ans = l[i]
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | n = int(input())
lst = [int(input()) for i in range(n)]
for el in lst:
if el >= 13:
D = 36 + 8 * (el - 5)
trio_amount = int((-6 + D**0.5) / 4) + 1
elif el >= 5:
trio_amount = 1
else:
trio_amount = 0
print(trio_amount) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | def solve():
x = int(input())
t = int((2.0 * x - 1) ** 0.5)
if t & 1:
t += 1
ans = t // 2 - 1
print(ans)
t = int(input())
for _ in range(t):
solve() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | t = int(input())
while t:
n = int(input())
a = (2 * n + 1) ** 0.5
if a.is_integer():
a = a // 2 - 1
else:
a = int(a)
a = a // 2 if a % 2 else a // 2 - 1
print(int(a))
t -= 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER IF FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | t = int(input())
for _ in range(t):
n = int(input())
x = ((2 * n - 1) ** 0.5 - 3) // 2
print(0 if x < 0 else int(x) + 1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n = int(input())
a = 1
ans = 0
while True:
b = a * a // 2
c = a * a - b
if a <= b <= c <= n:
ans += 1
if c > n:
break
a += 2
print(ans) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | k = int(input())
s = str()
for i in range(k):
n = int(input())
if n < 5:
s = s + "0" + "\n"
else:
a = int((2 * n - 1) ** (1 / 2))
if a % 2 == 0:
a = a - 1
a = int(a / 2)
elif a % 2 != 0:
a = int(a / 2)
s = s + str(a) + "\n"
print(s) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR STRING STRING ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | t = int(input())
for _ in range(t):
n = int(input())
res = 0
for a in range(2, 10**9):
a2 = pow(a, 2)
if a2 <= 2 * n + 1:
if (a2 - 1) % 2 == 0:
b = (a2 - 1) // 2
if a <= b <= n:
c = a2 - b
if b <= c <= n:
res += 1
else:
break
print(res) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | def main():
tc = int(input())
for _ in range(tc):
r = int(input())
occurance = 0
m = 2
n = 1
c = m**2 + n**2
while c <= r:
a = m**2 - n**2
b = 2 * m * n
c = m**2 + n**2
noobsc = a**2 - b
if noobsc == c:
occurance += 1
m += 1
n += 1
c = m**2 + n**2
print(occurance)
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | t = int(input())
for _ in range(t):
n = int(input())
k = int((2 * n - 1) ** 0.5)
if k % 2 == 1:
print(k // 2)
else:
print(k // 2 - 1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | from sys import stdin
nii = lambda: map(int, stdin.readline().split())
lnii = lambda: list(map(int, stdin.readline().split()))
t = int(input())
for tt in range(t):
n = int(input())
ans = 0
num = 3
while num**2 <= 2 * n - 1:
ans += 1
num += 2
print(ans) | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | maxn = int(400000.0)
c = []
for a in range(3, maxn, 2):
c.append((a * a + 1) // 2)
for _ in range(int(input())):
n = int(input())
lo, hi, ans = 0, len(c), 0
while lo <= hi:
mid = lo + (hi - lo) // 2
if c[mid] <= n:
ans = mid
lo = mid + 1
else:
hi = mid - 1
ans = 0 if n < 5 else ans + 1
print(ans) | ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | (T,) = map(int, input().split())
Q = []
for i in range(T):
(N,) = map(int, input().split())
Q.append((i, N))
Q.sort(key=lambda x: x[1])
a = 1
cnt = 0
R = [0] * T
now = 0
while True:
a += 1
if a**2 % 2:
b = (a**2 - 1) // 2
c = b + 1
if c > 10**9:
break
if a**2 + b**2 == c**2:
while now < len(Q) and Q[now][1] < c:
R[Q[now][0]] = cnt
now += 1
cnt += 1
while now < len(Q) and Q[now][1] < c:
R[Q[now][0]] = cnt
now += 1
for r in R:
print(r) | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER WHILE NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP NUMBER NUMBER IF BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | t = int(input())
while t:
t -= 1
b = int(input())
if b < 4:
print(0)
continue
b -= 1
res = int((2 * b + 1) ** 0.5)
if res % 2 == 0:
res -= 1
res = (res - 3) // 2 + 1
print(res) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | N = int(input())
for t in range(N):
n = int(input())
if n < 5:
print(0)
else:
print((int((2 * n - 1) ** 0.5) - 1) // 2) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER NUMBER NUMBER |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | ansl = []
for _ in range(int(input())):
n = int(input())
max2b_1 = 2 * n - 1
max_root = int(max2b_1**0.5)
ans = (max_root - 1) // 2
ansl.append(ans)
for a in ansl:
print(a) | ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | t = int(input())
def abc(d):
i = 1
j = 10**5
ans = 1
while i <= j:
mid = i + (j - i) // 2
if mid * mid <= d:
ans = mid
i = mid + 1
else:
j = mid - 1
return ans
for _ in range(t):
n = int(input())
x = 2 * n - 1
x = abc(x)
print((x - 1) // 2) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | ans = []
p = []
for i in range(3, 100000, 2):
p.append(i * i // 2 + 1)
for _ in range(int(input())):
n = int(input())
if p[0] > n:
ans.append(0)
continue
L = 0
R = len(p)
while R - L > 1:
M = (L + R) // 2
if p[M] > n:
R = M
else:
L = M
ans.append(L + 1)
print("\n".join(map(str, ans))) | ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | t = int(input())
for _ in range(t):
n = int(input())
x = int((2 * n - 1) ** 0.5)
print(max(0, (x - 1) // 2)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | for t in range(int(input())):
n = int(input())
l = 3
r = int((2 * n - 1) ** 0.5)
ans = 2
if r % 2 == 0:
r += 1
for i in range(r, l - 1, -2):
if (i**2 + 1) // 2 <= n:
ans = i
break
ans = (ans - 3) // 2 + 1
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | T = int(input())
ans_ls = [0] * T
def db(*arg):
print(*arg)
for t in range(T):
N = int(input())
ans = 0
for a in range(1, int((2 * N) ** 0.5) + 10, 2):
b = a**2 // 2
c = a**2 // 2 + 1
if a <= b and c <= N:
ans += 1
ans_ls[t] = ans
for ans in ans_ls:
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | def pytho(n):
i = 3
cnt = 0
while i**2 <= 2 * n - 1:
cnt += 1
i += 2
return cnt
for i in range(int(input())):
print(pytho(int(input()))) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | for _ in range(int(input())):
n = int(input())
real_n = 2 * n - 1
i = 3
count = 0
while i * i <= real_n:
count += 1
i += 2
print(count) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | for t in range(int(input())):
n = int(input())
x = int((2 * n + 1) ** 0.5)
y = (x + 1) // 2 - 1
if (x * x - 1) // 2 == n:
y -= 1
print(max(0, y)) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | import sys
mod = 1000000007
eps = 10**-9
def main():
import sys
input = sys.stdin.buffer.readline
for _ in range(int(input())):
N = int(input())
ok = 1
ng = N
mid = (ok + ng) // 2
while ng - ok > 1:
if (mid * mid + 1) // 2 <= N:
ok = mid
else:
ng = mid
mid = (ok + ng) // 2
if ok < 3:
print(0)
else:
print((ok + 1) // 2 - 1)
main() | IMPORT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | try:
t = int(input())
while t != 0:
n = int(input())
maxi = int((2 * n - 1) ** 0.5)
print((maxi + 1) // 2 - 1)
t -= 1
except EOFError as e:
print("") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR STRING |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | import sys
input = sys.stdin.readline
def inp():
return int(input())
def st():
return input().rstrip("\n")
def lis():
return list(map(int, input().split()))
def ma():
return map(int, input().split())
t = inp()
while t:
t -= 1
n = inp()
x = 2 * n
x = int(pow(x, 0.5))
print(max(0, (x + 1) // 2 - 1)) | IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | for _ in range(int(input())):
n = int(input())
limit = pow(2 * n - 1, 1 / 2)
ans = (limit - 1) // 2
print(int(ans)) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | t = int(input())
for q in range(t):
n = int(input())
z = int(2**0.5 * (n - 0.5) ** 0.5)
if z % 2 == 0:
print(int(z / 2 - 1))
else:
print(int((z - 1) / 2)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | t = int(input())
for _ in range(t, 0, -1):
n = int(input())
cnt = 0
for a in range(3, 50000, +2):
b = (a * a - 1) / 2
c = b + 1
if c < n + 1:
cnt = cnt + 1
else:
break
print(cnt) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | T = int(input())
r = 1
while r <= T:
n = int(input())
ans = int((2 * n - 1) ** 0.5)
ans = (ans - 1) // 2
print(ans)
r += 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | import sys
input = sys.stdin.readline
def solve(arr):
n = int(input())
if arr[0][2] > n:
return 0
lo, hi = 0, len(arr) - 1
while lo < hi:
mid = (lo + hi + 1) // 2
if arr[mid][2] <= n:
lo = mid
else:
hi = mid - 1
return lo + 1
arr = []
for a in range(3, 10**5, 2):
v = pow(a, 2)
b = (v - 1) // 2
c = v - b
if c > 10**9:
break
if a + b >= c:
arr.append((a, b, c))
for _ in range(int(input())):
print(solve(arr)) | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER NUMBER VAR RETURN NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP NUMBER NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | read = lambda: map(int, input().split())
t = int(input())
for _ in range(t):
n = int(input())
print((int((2 * n - 1) ** 0.5) - 1) // 2) | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER NUMBER NUMBER |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | from sys import stdin, stdout
nmbr = lambda: int(stdin.readline())
lst = lambda: list(map(int, stdin.readline().split()))
for _ in range(nmbr()):
n = nmbr()
p = 3
ans = 0
while 1:
sq = p * p
if (sq + 1) // 2 > n:
break
ans += 1
p += 2
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | def answer(n):
l = int((2 * n - 1) ** 0.5)
c = 0
for i in range(3, l + 1, 2):
c += 1
print(c)
t = int(input())
for i in range(t):
n = int(input())
answer(n) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | def arrIn():
return list(map(int, input().split()))
def mapIn():
return map(int, input().split())
for ii in range(int(input())):
n = int(input())
c = n
a = c + c - 1
a = int(a**0.5)
if a % 2 == 0:
a -= 1
c = (a - 3) // 2 + 1
print(c) | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | def main():
num_cases = int(input())
for case_num in range(1, num_cases + 1):
solve(case_num)
def solve(case_num):
n = int(input())
sol = 0
for a in range(3, n + 1):
if a**2 > 2 * n - 1:
break
if (a**2 - 1) % 2 == 0:
sol += 1
print(sol)
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n = int(input())
i = 3
ans = 0
while i <= n and (i * i - 1) // 2 <= n:
if (
(i * i - 1) % 2 == 0
and (i * i - 1) // 2 >= i
and i * i - (i * i - 1) // 2 <= n
):
ans += 1
i += 1
print(ans) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | t = int(input())
while t > 0:
n = int(input())
ans = 0
i = 3
while i**2 <= 2 * n - 1:
ans += 1
i += 2
print(ans)
t -= 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | t = int(input())
for i in range(t):
n = int(input())
m = int((2 * n - 1) ** (1 / 2))
k = int((m - 1) / 2)
print(k) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | t = int(input())
for _ in range(t):
n = int(input())
ans = 0
for i in range(3, int((2 * n - 1) ** 0.5) + 1, 2):
if (i**2 - 1) % 2 == 0:
ans += 1
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER NUMBER NUMBER IF BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | for _ in range(int(input())):
n = int(input())
ans = 0
temp = int(pow(2 * n - 1, 0.5))
if temp % 2 == 0:
ans = temp // 2 - 1
else:
ans = temp // 2
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | import sys
def run_case():
n = int(input())
print(int((2 * n - 1) ** 0.5 - 1) >> 1)
t = int(input())
for _ in range(t):
run_case() | IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | rn = lambda: int(input())
rns = lambda: map(int, input().split())
rl = lambda: list(map(int, input().split()))
rs = lambda: input()
YN = lambda x: print("YES") if x else print("NO")
mod = lambda x: x % (10**9 + 7)
def d(a):
d = {}
for i in a:
if i not in d:
d[i] = 0
d[i] += 1
return d
for _ in range(rn()):
n = rn()
a = 2 * (n - 1) + 1
a = int(a**0.5)
print(a // 2 + a % 2 - 1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER |
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases.
Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$).
-----Output-----
For each test case, print one integer β the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
-----Examples-----
Input
3
3
6
9
Output
0
1
1
-----Note-----
The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$. | for _ in range(int(input())):
n = int(input())
i = 3
ans = 0
while (i**2 - 1) // 2 < n:
ans += 1
i += 2
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.