description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Grigory has $n$ magic stones, conveniently numbered from $1$ to $n$. The charge of the $i$-th stone is equal to $c_i$. Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $i$, where $2 \le i \le n - 1$), and after that synchronizes it with neighboring stones. After that, the chosen stone loses its own charge, but acquires the charges from neighboring stones. In other words, its charge $c_i$ changes to $c_i' = c_{i + 1} + c_{i - 1} - c_i$. Andrew, Grigory's friend, also has $n$ stones with charges $t_i$. Grigory is curious, whether there exists a sequence of zero or more synchronization operations, which transforms charges of Grigory's stones into charges of corresponding Andrew's stones, that is, changes $c_i$ into $t_i$ for all $i$? -----Input----- The first line contains one integer $n$ ($2 \le n \le 10^5$)Β β€” the number of magic stones. The second line contains integers $c_1, c_2, \ldots, c_n$ ($0 \le c_i \le 2 \cdot 10^9$)Β β€” the charges of Grigory's stones. The second line contains integers $t_1, t_2, \ldots, t_n$ ($0 \le t_i \le 2 \cdot 10^9$)Β β€” the charges of Andrew's stones. -----Output----- If there exists a (possibly empty) sequence of synchronization operations, which changes all charges to the required ones, print "Yes". Otherwise, print "No". -----Examples----- Input 4 7 2 4 12 7 15 10 12 Output Yes Input 3 4 4 4 1 2 3 Output No -----Note----- In the first example, we can perform the following synchronizations ($1$-indexed): First, synchronize the third stone $[7, 2, \mathbf{4}, 12] \rightarrow [7, 2, \mathbf{10}, 12]$. Then synchronize the second stone: $[7, \mathbf{2}, 10, 12] \rightarrow [7, \mathbf{15}, 10, 12]$. In the second example, any operation with the second stone will not change its charge.
def get(l): res = [] for i in range(1, n): res.append(l[i] - l[i - 1]) res.sort() return res n, a, b = ( int(input()), [int(_) for _ in input().split()], [int(_) for _ in input().split()], ) ma, mb = get(a), get(b) print("Yes" if ma == mb and a[0] == b[0] and a[-1] == b[-1] else "No")
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER STRING STRING
Grigory has $n$ magic stones, conveniently numbered from $1$ to $n$. The charge of the $i$-th stone is equal to $c_i$. Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $i$, where $2 \le i \le n - 1$), and after that synchronizes it with neighboring stones. After that, the chosen stone loses its own charge, but acquires the charges from neighboring stones. In other words, its charge $c_i$ changes to $c_i' = c_{i + 1} + c_{i - 1} - c_i$. Andrew, Grigory's friend, also has $n$ stones with charges $t_i$. Grigory is curious, whether there exists a sequence of zero or more synchronization operations, which transforms charges of Grigory's stones into charges of corresponding Andrew's stones, that is, changes $c_i$ into $t_i$ for all $i$? -----Input----- The first line contains one integer $n$ ($2 \le n \le 10^5$)Β β€” the number of magic stones. The second line contains integers $c_1, c_2, \ldots, c_n$ ($0 \le c_i \le 2 \cdot 10^9$)Β β€” the charges of Grigory's stones. The second line contains integers $t_1, t_2, \ldots, t_n$ ($0 \le t_i \le 2 \cdot 10^9$)Β β€” the charges of Andrew's stones. -----Output----- If there exists a (possibly empty) sequence of synchronization operations, which changes all charges to the required ones, print "Yes". Otherwise, print "No". -----Examples----- Input 4 7 2 4 12 7 15 10 12 Output Yes Input 3 4 4 4 1 2 3 Output No -----Note----- In the first example, we can perform the following synchronizations ($1$-indexed): First, synchronize the third stone $[7, 2, \mathbf{4}, 12] \rightarrow [7, 2, \mathbf{10}, 12]$. Then synchronize the second stone: $[7, \mathbf{2}, 10, 12] \rightarrow [7, \mathbf{15}, 10, 12]$. In the second example, any operation with the second stone will not change its charge.
n = int(input()) c = list(map(int, input().split())) t = list(map(int, input().split())) def comp(l): out = 0 for v in l: out += v * v for i in range(n - 1): out -= l[i] * l[i + 1] return out if c[0] == t[0] and t[-1] == c[-1] and comp(c) == comp(t): print("Yes") else: print("No")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Grigory has $n$ magic stones, conveniently numbered from $1$ to $n$. The charge of the $i$-th stone is equal to $c_i$. Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $i$, where $2 \le i \le n - 1$), and after that synchronizes it with neighboring stones. After that, the chosen stone loses its own charge, but acquires the charges from neighboring stones. In other words, its charge $c_i$ changes to $c_i' = c_{i + 1} + c_{i - 1} - c_i$. Andrew, Grigory's friend, also has $n$ stones with charges $t_i$. Grigory is curious, whether there exists a sequence of zero or more synchronization operations, which transforms charges of Grigory's stones into charges of corresponding Andrew's stones, that is, changes $c_i$ into $t_i$ for all $i$? -----Input----- The first line contains one integer $n$ ($2 \le n \le 10^5$)Β β€” the number of magic stones. The second line contains integers $c_1, c_2, \ldots, c_n$ ($0 \le c_i \le 2 \cdot 10^9$)Β β€” the charges of Grigory's stones. The second line contains integers $t_1, t_2, \ldots, t_n$ ($0 \le t_i \le 2 \cdot 10^9$)Β β€” the charges of Andrew's stones. -----Output----- If there exists a (possibly empty) sequence of synchronization operations, which changes all charges to the required ones, print "Yes". Otherwise, print "No". -----Examples----- Input 4 7 2 4 12 7 15 10 12 Output Yes Input 3 4 4 4 1 2 3 Output No -----Note----- In the first example, we can perform the following synchronizations ($1$-indexed): First, synchronize the third stone $[7, 2, \mathbf{4}, 12] \rightarrow [7, 2, \mathbf{10}, 12]$. Then synchronize the second stone: $[7, \mathbf{2}, 10, 12] \rightarrow [7, \mathbf{15}, 10, 12]$. In the second example, any operation with the second stone will not change its charge.
n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) a1 = [(a[i + 1] - a[i]) for i in range(n - 1)] b1 = [(b[i + 1] - b[i]) for i in range(n - 1)] a1.sort() b1.sort() if a[0] != b[0] or a[-1] != b[-1]: print("No") elif a1 == b1: print("Yes") else: print("No")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Grigory has $n$ magic stones, conveniently numbered from $1$ to $n$. The charge of the $i$-th stone is equal to $c_i$. Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $i$, where $2 \le i \le n - 1$), and after that synchronizes it with neighboring stones. After that, the chosen stone loses its own charge, but acquires the charges from neighboring stones. In other words, its charge $c_i$ changes to $c_i' = c_{i + 1} + c_{i - 1} - c_i$. Andrew, Grigory's friend, also has $n$ stones with charges $t_i$. Grigory is curious, whether there exists a sequence of zero or more synchronization operations, which transforms charges of Grigory's stones into charges of corresponding Andrew's stones, that is, changes $c_i$ into $t_i$ for all $i$? -----Input----- The first line contains one integer $n$ ($2 \le n \le 10^5$)Β β€” the number of magic stones. The second line contains integers $c_1, c_2, \ldots, c_n$ ($0 \le c_i \le 2 \cdot 10^9$)Β β€” the charges of Grigory's stones. The second line contains integers $t_1, t_2, \ldots, t_n$ ($0 \le t_i \le 2 \cdot 10^9$)Β β€” the charges of Andrew's stones. -----Output----- If there exists a (possibly empty) sequence of synchronization operations, which changes all charges to the required ones, print "Yes". Otherwise, print "No". -----Examples----- Input 4 7 2 4 12 7 15 10 12 Output Yes Input 3 4 4 4 1 2 3 Output No -----Note----- In the first example, we can perform the following synchronizations ($1$-indexed): First, synchronize the third stone $[7, 2, \mathbf{4}, 12] \rightarrow [7, 2, \mathbf{10}, 12]$. Then synchronize the second stone: $[7, \mathbf{2}, 10, 12] \rightarrow [7, \mathbf{15}, 10, 12]$. In the second example, any operation with the second stone will not change its charge.
n = int(input()) a = list(map(int, str(input()).split(" "))) b = list(map(int, str(input()).split(" "))) c = [0] * (n - 1) d = [0] * (n - 1) for i in range(n - 1): c[i] = a[i + 1] - a[i] d[i] = b[i + 1] - b[i] c.sort() d.sort() if c == d and a[0] == b[0] and a[-1] == b[-1]: print("Yes") else: print("No")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Grigory has $n$ magic stones, conveniently numbered from $1$ to $n$. The charge of the $i$-th stone is equal to $c_i$. Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $i$, where $2 \le i \le n - 1$), and after that synchronizes it with neighboring stones. After that, the chosen stone loses its own charge, but acquires the charges from neighboring stones. In other words, its charge $c_i$ changes to $c_i' = c_{i + 1} + c_{i - 1} - c_i$. Andrew, Grigory's friend, also has $n$ stones with charges $t_i$. Grigory is curious, whether there exists a sequence of zero or more synchronization operations, which transforms charges of Grigory's stones into charges of corresponding Andrew's stones, that is, changes $c_i$ into $t_i$ for all $i$? -----Input----- The first line contains one integer $n$ ($2 \le n \le 10^5$)Β β€” the number of magic stones. The second line contains integers $c_1, c_2, \ldots, c_n$ ($0 \le c_i \le 2 \cdot 10^9$)Β β€” the charges of Grigory's stones. The second line contains integers $t_1, t_2, \ldots, t_n$ ($0 \le t_i \le 2 \cdot 10^9$)Β β€” the charges of Andrew's stones. -----Output----- If there exists a (possibly empty) sequence of synchronization operations, which changes all charges to the required ones, print "Yes". Otherwise, print "No". -----Examples----- Input 4 7 2 4 12 7 15 10 12 Output Yes Input 3 4 4 4 1 2 3 Output No -----Note----- In the first example, we can perform the following synchronizations ($1$-indexed): First, synchronize the third stone $[7, 2, \mathbf{4}, 12] \rightarrow [7, 2, \mathbf{10}, 12]$. Then synchronize the second stone: $[7, \mathbf{2}, 10, 12] \rightarrow [7, \mathbf{15}, 10, 12]$. In the second example, any operation with the second stone will not change its charge.
from sys import stdin max_val = int(10000000000000.0) min_val = int(-10000000000000.0) def read_int(): return int(stdin.readline()) def read_ints(): return [int(x) for x in stdin.readline().split()] def read_str(): return input() def read_strs(): return [x for x in stdin.readline().split()] nb_elements = int(input()) first = [int(x) for x in input().split()] secon = [int(x) for x in input().split()] if first[-1] != secon[-1] or first[0] != secon[0]: print("No") else: first_1 = [(y - x) for x, y in zip(first, first[1:])] secon_1 = [(y - x) for x, y in zip(secon, secon[1:])] print(["No", "Yes"][sorted(first_1) == sorted(secon_1)])
ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST STRING STRING FUNC_CALL VAR VAR FUNC_CALL VAR VAR
Grigory has $n$ magic stones, conveniently numbered from $1$ to $n$. The charge of the $i$-th stone is equal to $c_i$. Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $i$, where $2 \le i \le n - 1$), and after that synchronizes it with neighboring stones. After that, the chosen stone loses its own charge, but acquires the charges from neighboring stones. In other words, its charge $c_i$ changes to $c_i' = c_{i + 1} + c_{i - 1} - c_i$. Andrew, Grigory's friend, also has $n$ stones with charges $t_i$. Grigory is curious, whether there exists a sequence of zero or more synchronization operations, which transforms charges of Grigory's stones into charges of corresponding Andrew's stones, that is, changes $c_i$ into $t_i$ for all $i$? -----Input----- The first line contains one integer $n$ ($2 \le n \le 10^5$)Β β€” the number of magic stones. The second line contains integers $c_1, c_2, \ldots, c_n$ ($0 \le c_i \le 2 \cdot 10^9$)Β β€” the charges of Grigory's stones. The second line contains integers $t_1, t_2, \ldots, t_n$ ($0 \le t_i \le 2 \cdot 10^9$)Β β€” the charges of Andrew's stones. -----Output----- If there exists a (possibly empty) sequence of synchronization operations, which changes all charges to the required ones, print "Yes". Otherwise, print "No". -----Examples----- Input 4 7 2 4 12 7 15 10 12 Output Yes Input 3 4 4 4 1 2 3 Output No -----Note----- In the first example, we can perform the following synchronizations ($1$-indexed): First, synchronize the third stone $[7, 2, \mathbf{4}, 12] \rightarrow [7, 2, \mathbf{10}, 12]$. Then synchronize the second stone: $[7, \mathbf{2}, 10, 12] \rightarrow [7, \mathbf{15}, 10, 12]$. In the second example, any operation with the second stone will not change its charge.
cnt_num = int(input()) a_str = input() b_str = input() a_arr = [int(x) for x in a_str.split(" ")] b_arr = [int(x) for x in b_str.split(" ")] if a_arr[0] != b_arr[0] or a_arr[cnt_num - 1] != b_arr[cnt_num - 1]: print("No") exit(0) a_tmp_arr, b_tmp_arr = [], [] for i in range(cnt_num - 1): a_tmp_arr.append(a_arr[i + 1] - a_arr[i]) b_tmp_arr.append(b_arr[i + 1] - b_arr[i]) a_tmp_arr = sorted(a_tmp_arr) b_tmp_arr = sorted(b_tmp_arr) for i in range(cnt_num - 1): if a_tmp_arr[i] != b_tmp_arr[i]: print("No") exit(0) print("Yes") exit(0)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER
Grigory has $n$ magic stones, conveniently numbered from $1$ to $n$. The charge of the $i$-th stone is equal to $c_i$. Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $i$, where $2 \le i \le n - 1$), and after that synchronizes it with neighboring stones. After that, the chosen stone loses its own charge, but acquires the charges from neighboring stones. In other words, its charge $c_i$ changes to $c_i' = c_{i + 1} + c_{i - 1} - c_i$. Andrew, Grigory's friend, also has $n$ stones with charges $t_i$. Grigory is curious, whether there exists a sequence of zero or more synchronization operations, which transforms charges of Grigory's stones into charges of corresponding Andrew's stones, that is, changes $c_i$ into $t_i$ for all $i$? -----Input----- The first line contains one integer $n$ ($2 \le n \le 10^5$)Β β€” the number of magic stones. The second line contains integers $c_1, c_2, \ldots, c_n$ ($0 \le c_i \le 2 \cdot 10^9$)Β β€” the charges of Grigory's stones. The second line contains integers $t_1, t_2, \ldots, t_n$ ($0 \le t_i \le 2 \cdot 10^9$)Β β€” the charges of Andrew's stones. -----Output----- If there exists a (possibly empty) sequence of synchronization operations, which changes all charges to the required ones, print "Yes". Otherwise, print "No". -----Examples----- Input 4 7 2 4 12 7 15 10 12 Output Yes Input 3 4 4 4 1 2 3 Output No -----Note----- In the first example, we can perform the following synchronizations ($1$-indexed): First, synchronize the third stone $[7, 2, \mathbf{4}, 12] \rightarrow [7, 2, \mathbf{10}, 12]$. Then synchronize the second stone: $[7, \mathbf{2}, 10, 12] \rightarrow [7, \mathbf{15}, 10, 12]$. In the second example, any operation with the second stone will not change its charge.
n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = sorted([(a[i + 1] - a[i]) for i in range(n - 1)]) d = sorted([(b[i + 1] - b[i]) for i in range(n - 1)]) print("YNEOS"[a[0] != b[0] or c != d :: 2])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER VAR VAR NUMBER
Grigory has $n$ magic stones, conveniently numbered from $1$ to $n$. The charge of the $i$-th stone is equal to $c_i$. Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $i$, where $2 \le i \le n - 1$), and after that synchronizes it with neighboring stones. After that, the chosen stone loses its own charge, but acquires the charges from neighboring stones. In other words, its charge $c_i$ changes to $c_i' = c_{i + 1} + c_{i - 1} - c_i$. Andrew, Grigory's friend, also has $n$ stones with charges $t_i$. Grigory is curious, whether there exists a sequence of zero or more synchronization operations, which transforms charges of Grigory's stones into charges of corresponding Andrew's stones, that is, changes $c_i$ into $t_i$ for all $i$? -----Input----- The first line contains one integer $n$ ($2 \le n \le 10^5$)Β β€” the number of magic stones. The second line contains integers $c_1, c_2, \ldots, c_n$ ($0 \le c_i \le 2 \cdot 10^9$)Β β€” the charges of Grigory's stones. The second line contains integers $t_1, t_2, \ldots, t_n$ ($0 \le t_i \le 2 \cdot 10^9$)Β β€” the charges of Andrew's stones. -----Output----- If there exists a (possibly empty) sequence of synchronization operations, which changes all charges to the required ones, print "Yes". Otherwise, print "No". -----Examples----- Input 4 7 2 4 12 7 15 10 12 Output Yes Input 3 4 4 4 1 2 3 Output No -----Note----- In the first example, we can perform the following synchronizations ($1$-indexed): First, synchronize the third stone $[7, 2, \mathbf{4}, 12] \rightarrow [7, 2, \mathbf{10}, 12]$. Then synchronize the second stone: $[7, \mathbf{2}, 10, 12] \rightarrow [7, \mathbf{15}, 10, 12]$. In the second example, any operation with the second stone will not change its charge.
M = int(input()) tree1 = [] tree2 = [] numbers1 = input().split() numbers2 = input().split() for x in range(M - 1): tree1 += [int(numbers1[x + 1]) - int(numbers1[x])] tree1 = sorted(tree1) for x in range(M - 1): tree2 += [int(numbers2[x + 1]) - int(numbers2[x])] tree2 = sorted(tree2) if tree1 == tree2 and numbers1[0] == numbers2[0]: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR LIST BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR LIST BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Grigory has $n$ magic stones, conveniently numbered from $1$ to $n$. The charge of the $i$-th stone is equal to $c_i$. Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $i$, where $2 \le i \le n - 1$), and after that synchronizes it with neighboring stones. After that, the chosen stone loses its own charge, but acquires the charges from neighboring stones. In other words, its charge $c_i$ changes to $c_i' = c_{i + 1} + c_{i - 1} - c_i$. Andrew, Grigory's friend, also has $n$ stones with charges $t_i$. Grigory is curious, whether there exists a sequence of zero or more synchronization operations, which transforms charges of Grigory's stones into charges of corresponding Andrew's stones, that is, changes $c_i$ into $t_i$ for all $i$? -----Input----- The first line contains one integer $n$ ($2 \le n \le 10^5$)Β β€” the number of magic stones. The second line contains integers $c_1, c_2, \ldots, c_n$ ($0 \le c_i \le 2 \cdot 10^9$)Β β€” the charges of Grigory's stones. The second line contains integers $t_1, t_2, \ldots, t_n$ ($0 \le t_i \le 2 \cdot 10^9$)Β β€” the charges of Andrew's stones. -----Output----- If there exists a (possibly empty) sequence of synchronization operations, which changes all charges to the required ones, print "Yes". Otherwise, print "No". -----Examples----- Input 4 7 2 4 12 7 15 10 12 Output Yes Input 3 4 4 4 1 2 3 Output No -----Note----- In the first example, we can perform the following synchronizations ($1$-indexed): First, synchronize the third stone $[7, 2, \mathbf{4}, 12] \rightarrow [7, 2, \mathbf{10}, 12]$. Then synchronize the second stone: $[7, \mathbf{2}, 10, 12] \rightarrow [7, \mathbf{15}, 10, 12]$. In the second example, any operation with the second stone will not change its charge.
( lambda N, c, t: print( "Yes" if c[0] == t[0] and c[-1] == t[-1] and sorted(c[i] - c[i + 1] for i in range(N - 1)) == sorted(t[i] - t[i + 1] for i in range(N - 1)) else "No" ) )(int(input()), list(map(int, input().split())), list(map(int, input().split())))
EXPR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING STRING FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR
Grigory has $n$ magic stones, conveniently numbered from $1$ to $n$. The charge of the $i$-th stone is equal to $c_i$. Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $i$, where $2 \le i \le n - 1$), and after that synchronizes it with neighboring stones. After that, the chosen stone loses its own charge, but acquires the charges from neighboring stones. In other words, its charge $c_i$ changes to $c_i' = c_{i + 1} + c_{i - 1} - c_i$. Andrew, Grigory's friend, also has $n$ stones with charges $t_i$. Grigory is curious, whether there exists a sequence of zero or more synchronization operations, which transforms charges of Grigory's stones into charges of corresponding Andrew's stones, that is, changes $c_i$ into $t_i$ for all $i$? -----Input----- The first line contains one integer $n$ ($2 \le n \le 10^5$)Β β€” the number of magic stones. The second line contains integers $c_1, c_2, \ldots, c_n$ ($0 \le c_i \le 2 \cdot 10^9$)Β β€” the charges of Grigory's stones. The second line contains integers $t_1, t_2, \ldots, t_n$ ($0 \le t_i \le 2 \cdot 10^9$)Β β€” the charges of Andrew's stones. -----Output----- If there exists a (possibly empty) sequence of synchronization operations, which changes all charges to the required ones, print "Yes". Otherwise, print "No". -----Examples----- Input 4 7 2 4 12 7 15 10 12 Output Yes Input 3 4 4 4 1 2 3 Output No -----Note----- In the first example, we can perform the following synchronizations ($1$-indexed): First, synchronize the third stone $[7, 2, \mathbf{4}, 12] \rightarrow [7, 2, \mathbf{10}, 12]$. Then synchronize the second stone: $[7, \mathbf{2}, 10, 12] \rightarrow [7, \mathbf{15}, 10, 12]$. In the second example, any operation with the second stone will not change its charge.
n = int(input("")) x = list(map(int, input().split())) y = list(map(int, input().split())) dpx = [] dpy = [] flag = 0 if x[0] != y[0] or x[n - 1] != y[n - 1]: flag = 1 for i in range(1, n): dpx.append(x[i] - x[i - 1]) dpy.append(y[i] - y[i - 1]) dpx.sort() dpy.sort() if dpx != dpy: flag = 1 if flag: print("No") else: print("Yes")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Grigory has $n$ magic stones, conveniently numbered from $1$ to $n$. The charge of the $i$-th stone is equal to $c_i$. Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $i$, where $2 \le i \le n - 1$), and after that synchronizes it with neighboring stones. After that, the chosen stone loses its own charge, but acquires the charges from neighboring stones. In other words, its charge $c_i$ changes to $c_i' = c_{i + 1} + c_{i - 1} - c_i$. Andrew, Grigory's friend, also has $n$ stones with charges $t_i$. Grigory is curious, whether there exists a sequence of zero or more synchronization operations, which transforms charges of Grigory's stones into charges of corresponding Andrew's stones, that is, changes $c_i$ into $t_i$ for all $i$? -----Input----- The first line contains one integer $n$ ($2 \le n \le 10^5$)Β β€” the number of magic stones. The second line contains integers $c_1, c_2, \ldots, c_n$ ($0 \le c_i \le 2 \cdot 10^9$)Β β€” the charges of Grigory's stones. The second line contains integers $t_1, t_2, \ldots, t_n$ ($0 \le t_i \le 2 \cdot 10^9$)Β β€” the charges of Andrew's stones. -----Output----- If there exists a (possibly empty) sequence of synchronization operations, which changes all charges to the required ones, print "Yes". Otherwise, print "No". -----Examples----- Input 4 7 2 4 12 7 15 10 12 Output Yes Input 3 4 4 4 1 2 3 Output No -----Note----- In the first example, we can perform the following synchronizations ($1$-indexed): First, synchronize the third stone $[7, 2, \mathbf{4}, 12] \rightarrow [7, 2, \mathbf{10}, 12]$. Then synchronize the second stone: $[7, \mathbf{2}, 10, 12] \rightarrow [7, \mathbf{15}, 10, 12]$. In the second example, any operation with the second stone will not change its charge.
n = int(input()) c = input().split() t = input().split() for i in range(n): c[i] = int(c[i]) t[i] = int(t[i]) d = [(0) for i in range(n - 1)] s = [(0) for i in range(n - 1)] for i in range(n - 1): d[i] = c[i + 1] - c[i] s[i] = t[i + 1] - t[i] d.sort() s.sort() index = 0 same = True while same and index < n - 1: if d[index] == s[index]: index += 1 else: same = False if not c[0] == t[0]: same = False if not c[n - 1] == t[n - 1]: same = False if same: print("Yes") else: print("No")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Grigory has $n$ magic stones, conveniently numbered from $1$ to $n$. The charge of the $i$-th stone is equal to $c_i$. Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $i$, where $2 \le i \le n - 1$), and after that synchronizes it with neighboring stones. After that, the chosen stone loses its own charge, but acquires the charges from neighboring stones. In other words, its charge $c_i$ changes to $c_i' = c_{i + 1} + c_{i - 1} - c_i$. Andrew, Grigory's friend, also has $n$ stones with charges $t_i$. Grigory is curious, whether there exists a sequence of zero or more synchronization operations, which transforms charges of Grigory's stones into charges of corresponding Andrew's stones, that is, changes $c_i$ into $t_i$ for all $i$? -----Input----- The first line contains one integer $n$ ($2 \le n \le 10^5$)Β β€” the number of magic stones. The second line contains integers $c_1, c_2, \ldots, c_n$ ($0 \le c_i \le 2 \cdot 10^9$)Β β€” the charges of Grigory's stones. The second line contains integers $t_1, t_2, \ldots, t_n$ ($0 \le t_i \le 2 \cdot 10^9$)Β β€” the charges of Andrew's stones. -----Output----- If there exists a (possibly empty) sequence of synchronization operations, which changes all charges to the required ones, print "Yes". Otherwise, print "No". -----Examples----- Input 4 7 2 4 12 7 15 10 12 Output Yes Input 3 4 4 4 1 2 3 Output No -----Note----- In the first example, we can perform the following synchronizations ($1$-indexed): First, synchronize the third stone $[7, 2, \mathbf{4}, 12] \rightarrow [7, 2, \mathbf{10}, 12]$. Then synchronize the second stone: $[7, \mathbf{2}, 10, 12] \rightarrow [7, \mathbf{15}, 10, 12]$. In the second example, any operation with the second stone will not change its charge.
n = int(input()) l = input().split() li = [int(i) for i in l] hashi = dict() l = input().split() li2 = [int(i) for i in l] if li[0] != li2[0]: print("No") quit() diff1 = [(li[i + 1] - li[i]) for i in range(n - 1)] diff2 = [(li2[i + 1] - li2[i]) for i in range(n - 1)] for i in diff1: if i in hashi: hashi[i] += 1 else: hashi[i] = 1 poss = 1 for i in diff2: if i not in hashi: poss = 0 break if hashi[i] == 0: poss = 0 break hashi[i] -= 1 if poss: print("Yes") else: print("No")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Grigory has $n$ magic stones, conveniently numbered from $1$ to $n$. The charge of the $i$-th stone is equal to $c_i$. Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $i$, where $2 \le i \le n - 1$), and after that synchronizes it with neighboring stones. After that, the chosen stone loses its own charge, but acquires the charges from neighboring stones. In other words, its charge $c_i$ changes to $c_i' = c_{i + 1} + c_{i - 1} - c_i$. Andrew, Grigory's friend, also has $n$ stones with charges $t_i$. Grigory is curious, whether there exists a sequence of zero or more synchronization operations, which transforms charges of Grigory's stones into charges of corresponding Andrew's stones, that is, changes $c_i$ into $t_i$ for all $i$? -----Input----- The first line contains one integer $n$ ($2 \le n \le 10^5$)Β β€” the number of magic stones. The second line contains integers $c_1, c_2, \ldots, c_n$ ($0 \le c_i \le 2 \cdot 10^9$)Β β€” the charges of Grigory's stones. The second line contains integers $t_1, t_2, \ldots, t_n$ ($0 \le t_i \le 2 \cdot 10^9$)Β β€” the charges of Andrew's stones. -----Output----- If there exists a (possibly empty) sequence of synchronization operations, which changes all charges to the required ones, print "Yes". Otherwise, print "No". -----Examples----- Input 4 7 2 4 12 7 15 10 12 Output Yes Input 3 4 4 4 1 2 3 Output No -----Note----- In the first example, we can perform the following synchronizations ($1$-indexed): First, synchronize the third stone $[7, 2, \mathbf{4}, 12] \rightarrow [7, 2, \mathbf{10}, 12]$. Then synchronize the second stone: $[7, \mathbf{2}, 10, 12] \rightarrow [7, \mathbf{15}, 10, 12]$. In the second example, any operation with the second stone will not change its charge.
n = int(input()) c = list(map(int, input().split())) t = list(map(int, input().split())) d = lambda x: sorted(x[i + 1] - x[i] for i in range(n - 1)) print("Yes" if c[0] == t[0] and d(c) == d(t) else "No")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR STRING STRING
Grigory has $n$ magic stones, conveniently numbered from $1$ to $n$. The charge of the $i$-th stone is equal to $c_i$. Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $i$, where $2 \le i \le n - 1$), and after that synchronizes it with neighboring stones. After that, the chosen stone loses its own charge, but acquires the charges from neighboring stones. In other words, its charge $c_i$ changes to $c_i' = c_{i + 1} + c_{i - 1} - c_i$. Andrew, Grigory's friend, also has $n$ stones with charges $t_i$. Grigory is curious, whether there exists a sequence of zero or more synchronization operations, which transforms charges of Grigory's stones into charges of corresponding Andrew's stones, that is, changes $c_i$ into $t_i$ for all $i$? -----Input----- The first line contains one integer $n$ ($2 \le n \le 10^5$)Β β€” the number of magic stones. The second line contains integers $c_1, c_2, \ldots, c_n$ ($0 \le c_i \le 2 \cdot 10^9$)Β β€” the charges of Grigory's stones. The second line contains integers $t_1, t_2, \ldots, t_n$ ($0 \le t_i \le 2 \cdot 10^9$)Β β€” the charges of Andrew's stones. -----Output----- If there exists a (possibly empty) sequence of synchronization operations, which changes all charges to the required ones, print "Yes". Otherwise, print "No". -----Examples----- Input 4 7 2 4 12 7 15 10 12 Output Yes Input 3 4 4 4 1 2 3 Output No -----Note----- In the first example, we can perform the following synchronizations ($1$-indexed): First, synchronize the third stone $[7, 2, \mathbf{4}, 12] \rightarrow [7, 2, \mathbf{10}, 12]$. Then synchronize the second stone: $[7, \mathbf{2}, 10, 12] \rightarrow [7, \mathbf{15}, 10, 12]$. In the second example, any operation with the second stone will not change its charge.
N = int(input()) A = [int(i) for i in input().split()] B = [int(i) for i in input().split()] S = [(A[i] - A[i - 1]) for i in range(1, N)] T = [(B[i] - B[i - 1]) for i in range(1, N)] S.sort() T.sort() if A[0] == B[0] and A[N - 1] == B[N - 1] and S == T: print("Yes") else: print("No")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Grigory has $n$ magic stones, conveniently numbered from $1$ to $n$. The charge of the $i$-th stone is equal to $c_i$. Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $i$, where $2 \le i \le n - 1$), and after that synchronizes it with neighboring stones. After that, the chosen stone loses its own charge, but acquires the charges from neighboring stones. In other words, its charge $c_i$ changes to $c_i' = c_{i + 1} + c_{i - 1} - c_i$. Andrew, Grigory's friend, also has $n$ stones with charges $t_i$. Grigory is curious, whether there exists a sequence of zero or more synchronization operations, which transforms charges of Grigory's stones into charges of corresponding Andrew's stones, that is, changes $c_i$ into $t_i$ for all $i$? -----Input----- The first line contains one integer $n$ ($2 \le n \le 10^5$)Β β€” the number of magic stones. The second line contains integers $c_1, c_2, \ldots, c_n$ ($0 \le c_i \le 2 \cdot 10^9$)Β β€” the charges of Grigory's stones. The second line contains integers $t_1, t_2, \ldots, t_n$ ($0 \le t_i \le 2 \cdot 10^9$)Β β€” the charges of Andrew's stones. -----Output----- If there exists a (possibly empty) sequence of synchronization operations, which changes all charges to the required ones, print "Yes". Otherwise, print "No". -----Examples----- Input 4 7 2 4 12 7 15 10 12 Output Yes Input 3 4 4 4 1 2 3 Output No -----Note----- In the first example, we can perform the following synchronizations ($1$-indexed): First, synchronize the third stone $[7, 2, \mathbf{4}, 12] \rightarrow [7, 2, \mathbf{10}, 12]$. Then synchronize the second stone: $[7, \mathbf{2}, 10, 12] \rightarrow [7, \mathbf{15}, 10, 12]$. In the second example, any operation with the second stone will not change its charge.
n = int(input()) t1 = list(map(int, input().split())) t2 = list(map(int, input().split())) if t1[0] != t2[0] or t2[n - 1] != t1[n - 1]: print("No") exit() l1 = list() l2 = list() for i in range(0, n): if i == 0: l1.append(t1[i]) else: l1.append(t1[i] - t1[i - 1]) if i == n - 1: l1.append(t1[i]) for i in range(0, n): if i == 0: l2.append(t2[i]) else: l2.append(t2[i] - t2[i - 1]) if i == n - 1: l2.append(t2[i]) l1.sort() l2.sort() if l1 == l2: print("Yes") else: print("No")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Grigory has $n$ magic stones, conveniently numbered from $1$ to $n$. The charge of the $i$-th stone is equal to $c_i$. Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $i$, where $2 \le i \le n - 1$), and after that synchronizes it with neighboring stones. After that, the chosen stone loses its own charge, but acquires the charges from neighboring stones. In other words, its charge $c_i$ changes to $c_i' = c_{i + 1} + c_{i - 1} - c_i$. Andrew, Grigory's friend, also has $n$ stones with charges $t_i$. Grigory is curious, whether there exists a sequence of zero or more synchronization operations, which transforms charges of Grigory's stones into charges of corresponding Andrew's stones, that is, changes $c_i$ into $t_i$ for all $i$? -----Input----- The first line contains one integer $n$ ($2 \le n \le 10^5$)Β β€” the number of magic stones. The second line contains integers $c_1, c_2, \ldots, c_n$ ($0 \le c_i \le 2 \cdot 10^9$)Β β€” the charges of Grigory's stones. The second line contains integers $t_1, t_2, \ldots, t_n$ ($0 \le t_i \le 2 \cdot 10^9$)Β β€” the charges of Andrew's stones. -----Output----- If there exists a (possibly empty) sequence of synchronization operations, which changes all charges to the required ones, print "Yes". Otherwise, print "No". -----Examples----- Input 4 7 2 4 12 7 15 10 12 Output Yes Input 3 4 4 4 1 2 3 Output No -----Note----- In the first example, we can perform the following synchronizations ($1$-indexed): First, synchronize the third stone $[7, 2, \mathbf{4}, 12] \rightarrow [7, 2, \mathbf{10}, 12]$. Then synchronize the second stone: $[7, \mathbf{2}, 10, 12] \rightarrow [7, \mathbf{15}, 10, 12]$. In the second example, any operation with the second stone will not change its charge.
def mp(): return map(int, input().split()) n = int(input()) c = list(mp()) t = list(mp()) a = [abs(c[i] - c[i + 1]) for i in range(n - 1)] b = [abs(t[i] - t[i + 1]) for i in range(n - 1)] if sorted(a) == sorted(b) and c[0] == t[0]: print("Yes") else: print("No")
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Grigory has $n$ magic stones, conveniently numbered from $1$ to $n$. The charge of the $i$-th stone is equal to $c_i$. Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $i$, where $2 \le i \le n - 1$), and after that synchronizes it with neighboring stones. After that, the chosen stone loses its own charge, but acquires the charges from neighboring stones. In other words, its charge $c_i$ changes to $c_i' = c_{i + 1} + c_{i - 1} - c_i$. Andrew, Grigory's friend, also has $n$ stones with charges $t_i$. Grigory is curious, whether there exists a sequence of zero or more synchronization operations, which transforms charges of Grigory's stones into charges of corresponding Andrew's stones, that is, changes $c_i$ into $t_i$ for all $i$? -----Input----- The first line contains one integer $n$ ($2 \le n \le 10^5$)Β β€” the number of magic stones. The second line contains integers $c_1, c_2, \ldots, c_n$ ($0 \le c_i \le 2 \cdot 10^9$)Β β€” the charges of Grigory's stones. The second line contains integers $t_1, t_2, \ldots, t_n$ ($0 \le t_i \le 2 \cdot 10^9$)Β β€” the charges of Andrew's stones. -----Output----- If there exists a (possibly empty) sequence of synchronization operations, which changes all charges to the required ones, print "Yes". Otherwise, print "No". -----Examples----- Input 4 7 2 4 12 7 15 10 12 Output Yes Input 3 4 4 4 1 2 3 Output No -----Note----- In the first example, we can perform the following synchronizations ($1$-indexed): First, synchronize the third stone $[7, 2, \mathbf{4}, 12] \rightarrow [7, 2, \mathbf{10}, 12]$. Then synchronize the second stone: $[7, \mathbf{2}, 10, 12] \rightarrow [7, \mathbf{15}, 10, 12]$. In the second example, any operation with the second stone will not change its charge.
n = int(input()) c = list(map(int, input().split())) t = list(map(int, input().split())) v = [] v1 = [] if c[0] != t[0] and c[n - 1] != t[n - 1]: print("No") else: for _ in range(n - 1): v.append(c[_ + 1] - c[_]) v1.append(t[_ + 1] - t[_]) v.sort() v1.sort() if v != v1: print("No") else: print("Yes")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Grigory has $n$ magic stones, conveniently numbered from $1$ to $n$. The charge of the $i$-th stone is equal to $c_i$. Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $i$, where $2 \le i \le n - 1$), and after that synchronizes it with neighboring stones. After that, the chosen stone loses its own charge, but acquires the charges from neighboring stones. In other words, its charge $c_i$ changes to $c_i' = c_{i + 1} + c_{i - 1} - c_i$. Andrew, Grigory's friend, also has $n$ stones with charges $t_i$. Grigory is curious, whether there exists a sequence of zero or more synchronization operations, which transforms charges of Grigory's stones into charges of corresponding Andrew's stones, that is, changes $c_i$ into $t_i$ for all $i$? -----Input----- The first line contains one integer $n$ ($2 \le n \le 10^5$)Β β€” the number of magic stones. The second line contains integers $c_1, c_2, \ldots, c_n$ ($0 \le c_i \le 2 \cdot 10^9$)Β β€” the charges of Grigory's stones. The second line contains integers $t_1, t_2, \ldots, t_n$ ($0 \le t_i \le 2 \cdot 10^9$)Β β€” the charges of Andrew's stones. -----Output----- If there exists a (possibly empty) sequence of synchronization operations, which changes all charges to the required ones, print "Yes". Otherwise, print "No". -----Examples----- Input 4 7 2 4 12 7 15 10 12 Output Yes Input 3 4 4 4 1 2 3 Output No -----Note----- In the first example, we can perform the following synchronizations ($1$-indexed): First, synchronize the third stone $[7, 2, \mathbf{4}, 12] \rightarrow [7, 2, \mathbf{10}, 12]$. Then synchronize the second stone: $[7, \mathbf{2}, 10, 12] \rightarrow [7, \mathbf{15}, 10, 12]$. In the second example, any operation with the second stone will not change its charge.
n = int(input()) GR = list(map(int, input().split())) ANDR = list(map(int, input().split())) h = {} k = {} for y in range(1, n): if GR[y] - GR[y - 1] not in h: h[GR[y] - GR[y - 1]] = 0 h[GR[y] - GR[y - 1]] += 1 for y in range(1, n): if ANDR[y] - ANDR[y - 1] not in k: k[ANDR[y] - ANDR[y - 1]] = 0 k[ANDR[y] - ANDR[y - 1]] += 1 if h == k and ANDR[0] == GR[0] and ANDR[-1] == GR[-1]: print("yes") else: print("no")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Grigory has $n$ magic stones, conveniently numbered from $1$ to $n$. The charge of the $i$-th stone is equal to $c_i$. Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $i$, where $2 \le i \le n - 1$), and after that synchronizes it with neighboring stones. After that, the chosen stone loses its own charge, but acquires the charges from neighboring stones. In other words, its charge $c_i$ changes to $c_i' = c_{i + 1} + c_{i - 1} - c_i$. Andrew, Grigory's friend, also has $n$ stones with charges $t_i$. Grigory is curious, whether there exists a sequence of zero or more synchronization operations, which transforms charges of Grigory's stones into charges of corresponding Andrew's stones, that is, changes $c_i$ into $t_i$ for all $i$? -----Input----- The first line contains one integer $n$ ($2 \le n \le 10^5$)Β β€” the number of magic stones. The second line contains integers $c_1, c_2, \ldots, c_n$ ($0 \le c_i \le 2 \cdot 10^9$)Β β€” the charges of Grigory's stones. The second line contains integers $t_1, t_2, \ldots, t_n$ ($0 \le t_i \le 2 \cdot 10^9$)Β β€” the charges of Andrew's stones. -----Output----- If there exists a (possibly empty) sequence of synchronization operations, which changes all charges to the required ones, print "Yes". Otherwise, print "No". -----Examples----- Input 4 7 2 4 12 7 15 10 12 Output Yes Input 3 4 4 4 1 2 3 Output No -----Note----- In the first example, we can perform the following synchronizations ($1$-indexed): First, synchronize the third stone $[7, 2, \mathbf{4}, 12] \rightarrow [7, 2, \mathbf{10}, 12]$. Then synchronize the second stone: $[7, \mathbf{2}, 10, 12] \rightarrow [7, \mathbf{15}, 10, 12]$. In the second example, any operation with the second stone will not change its charge.
def E(): n = int(input()) c = [int(x) for x in input().split()] t = [int(x) for x in input().split()] c_p = sorted([(c[i + 1] - c[i]) for i in range(n - 1)]) t_p = sorted([(t[i + 1] - t[i]) for i in range(n - 1)]) if c_p != t_p: print("No") return print("Yes") if c[0] == t[0] else print("No") E()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN EXPR VAR NUMBER VAR NUMBER FUNC_CALL VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segments on the OX axis. He can draw each point with either red or blue. The drawing is good if and only if the following requirement is met: for each segment [li, ri] consider all the red points belong to it (ri points), and all the blue points belong to it (bi points); each segment i should satisfy the inequality |ri - bi| ≀ 1. Iahub thinks that point x belongs to segment [l, r], if inequality l ≀ x ≀ r holds. Iahub gives to you all coordinates of points and segments. Please, help him to find any good drawing. Input The first line of input contains two integers: n (1 ≀ n ≀ 100) and m (1 ≀ m ≀ 100). The next line contains n space-separated integers x1, x2, ..., xn (0 ≀ xi ≀ 100) β€” the coordinates of the points. The following m lines contain the descriptions of the m segments. Each line contains two integers li and ri (0 ≀ li ≀ ri ≀ 100) β€” the borders of the i-th segment. It's guaranteed that all the points are distinct. Output If there is no good drawing for a given test, output a single integer -1. Otherwise output n integers, each integer must be 0 or 1. The i-th number denotes the color of the i-th point (0 is red, and 1 is blue). If there are multiple good drawings you can output any of them. Examples Input 3 3 3 7 14 1 5 6 10 11 15 Output 0 0 0 Input 3 4 1 2 3 1 2 2 3 5 6 2 2 Output 1 0 1
input() P = list(map(int, input().split())) l = sorted([[P.index(p), i % 2] for i, p in enumerate(sorted(P))]) for a, b in l: print(b)
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segments on the OX axis. He can draw each point with either red or blue. The drawing is good if and only if the following requirement is met: for each segment [li, ri] consider all the red points belong to it (ri points), and all the blue points belong to it (bi points); each segment i should satisfy the inequality |ri - bi| ≀ 1. Iahub thinks that point x belongs to segment [l, r], if inequality l ≀ x ≀ r holds. Iahub gives to you all coordinates of points and segments. Please, help him to find any good drawing. Input The first line of input contains two integers: n (1 ≀ n ≀ 100) and m (1 ≀ m ≀ 100). The next line contains n space-separated integers x1, x2, ..., xn (0 ≀ xi ≀ 100) β€” the coordinates of the points. The following m lines contain the descriptions of the m segments. Each line contains two integers li and ri (0 ≀ li ≀ ri ≀ 100) β€” the borders of the i-th segment. It's guaranteed that all the points are distinct. Output If there is no good drawing for a given test, output a single integer -1. Otherwise output n integers, each integer must be 0 or 1. The i-th number denotes the color of the i-th point (0 is red, and 1 is blue). If there are multiple good drawings you can output any of them. Examples Input 3 3 3 7 14 1 5 6 10 11 15 Output 0 0 0 Input 3 4 1 2 3 1 2 2 3 5 6 2 2 Output 1 0 1
R = lambda: list(map(int, input().split())) n, m = R() a = R() exist = [(False) for i in range(200)] for i in range(m): l, r = R() for j in a: if l <= j <= r: exist[j] = True b = a[:] b.sort() ans = [(0) for i in range(200)] flag = 0 for i in b: if exist[i]: ans[i] = flag flag ^= 1 for i in a: print(ans[i], end=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segments on the OX axis. He can draw each point with either red or blue. The drawing is good if and only if the following requirement is met: for each segment [li, ri] consider all the red points belong to it (ri points), and all the blue points belong to it (bi points); each segment i should satisfy the inequality |ri - bi| ≀ 1. Iahub thinks that point x belongs to segment [l, r], if inequality l ≀ x ≀ r holds. Iahub gives to you all coordinates of points and segments. Please, help him to find any good drawing. Input The first line of input contains two integers: n (1 ≀ n ≀ 100) and m (1 ≀ m ≀ 100). The next line contains n space-separated integers x1, x2, ..., xn (0 ≀ xi ≀ 100) β€” the coordinates of the points. The following m lines contain the descriptions of the m segments. Each line contains two integers li and ri (0 ≀ li ≀ ri ≀ 100) β€” the borders of the i-th segment. It's guaranteed that all the points are distinct. Output If there is no good drawing for a given test, output a single integer -1. Otherwise output n integers, each integer must be 0 or 1. The i-th number denotes the color of the i-th point (0 is red, and 1 is blue). If there are multiple good drawings you can output any of them. Examples Input 3 3 3 7 14 1 5 6 10 11 15 Output 0 0 0 Input 3 4 1 2 3 1 2 2 3 5 6 2 2 Output 1 0 1
n, m = [int(i) for i in input().split()] p = list(map(int, input().split())) s = [input().split() for _ in range(m)] ps, result = sorted(p), [-1] * n for i in range(n): if i % 2 == 0: c = 1 else: c = 0 result[p.index(ps[i])] = c print(*result)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segments on the OX axis. He can draw each point with either red or blue. The drawing is good if and only if the following requirement is met: for each segment [li, ri] consider all the red points belong to it (ri points), and all the blue points belong to it (bi points); each segment i should satisfy the inequality |ri - bi| ≀ 1. Iahub thinks that point x belongs to segment [l, r], if inequality l ≀ x ≀ r holds. Iahub gives to you all coordinates of points and segments. Please, help him to find any good drawing. Input The first line of input contains two integers: n (1 ≀ n ≀ 100) and m (1 ≀ m ≀ 100). The next line contains n space-separated integers x1, x2, ..., xn (0 ≀ xi ≀ 100) β€” the coordinates of the points. The following m lines contain the descriptions of the m segments. Each line contains two integers li and ri (0 ≀ li ≀ ri ≀ 100) β€” the borders of the i-th segment. It's guaranteed that all the points are distinct. Output If there is no good drawing for a given test, output a single integer -1. Otherwise output n integers, each integer must be 0 or 1. The i-th number denotes the color of the i-th point (0 is red, and 1 is blue). If there are multiple good drawings you can output any of them. Examples Input 3 3 3 7 14 1 5 6 10 11 15 Output 0 0 0 Input 3 4 1 2 3 1 2 2 3 5 6 2 2 Output 1 0 1
import sys read = lambda t=int: list(map(t, sys.stdin.readline().split())) _, M = read() xs = read() for _ in range(M): _ = read() xs = sorted((x, i) for i, x in enumerate(xs)) xs = sorted((i, j) for j, (x, i) in enumerate(xs)) print(" ".join(str(j % 2) for _, j in xs))
IMPORT ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segments on the OX axis. He can draw each point with either red or blue. The drawing is good if and only if the following requirement is met: for each segment [li, ri] consider all the red points belong to it (ri points), and all the blue points belong to it (bi points); each segment i should satisfy the inequality |ri - bi| ≀ 1. Iahub thinks that point x belongs to segment [l, r], if inequality l ≀ x ≀ r holds. Iahub gives to you all coordinates of points and segments. Please, help him to find any good drawing. Input The first line of input contains two integers: n (1 ≀ n ≀ 100) and m (1 ≀ m ≀ 100). The next line contains n space-separated integers x1, x2, ..., xn (0 ≀ xi ≀ 100) β€” the coordinates of the points. The following m lines contain the descriptions of the m segments. Each line contains two integers li and ri (0 ≀ li ≀ ri ≀ 100) β€” the borders of the i-th segment. It's guaranteed that all the points are distinct. Output If there is no good drawing for a given test, output a single integer -1. Otherwise output n integers, each integer must be 0 or 1. The i-th number denotes the color of the i-th point (0 is red, and 1 is blue). If there are multiple good drawings you can output any of them. Examples Input 3 3 3 7 14 1 5 6 10 11 15 Output 0 0 0 Input 3 4 1 2 3 1 2 2 3 5 6 2 2 Output 1 0 1
n, m = map(int, input().split()) t = list(enumerate(list(map(int, input().split())))) t.sort(key=lambda x: x[1]) p = ["0"] * n for i, x in t[::2]: p[i] = "1" print(" ".join(p))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR VAR VAR NUMBER ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segments on the OX axis. He can draw each point with either red or blue. The drawing is good if and only if the following requirement is met: for each segment [li, ri] consider all the red points belong to it (ri points), and all the blue points belong to it (bi points); each segment i should satisfy the inequality |ri - bi| ≀ 1. Iahub thinks that point x belongs to segment [l, r], if inequality l ≀ x ≀ r holds. Iahub gives to you all coordinates of points and segments. Please, help him to find any good drawing. Input The first line of input contains two integers: n (1 ≀ n ≀ 100) and m (1 ≀ m ≀ 100). The next line contains n space-separated integers x1, x2, ..., xn (0 ≀ xi ≀ 100) β€” the coordinates of the points. The following m lines contain the descriptions of the m segments. Each line contains two integers li and ri (0 ≀ li ≀ ri ≀ 100) β€” the borders of the i-th segment. It's guaranteed that all the points are distinct. Output If there is no good drawing for a given test, output a single integer -1. Otherwise output n integers, each integer must be 0 or 1. The i-th number denotes the color of the i-th point (0 is red, and 1 is blue). If there are multiple good drawings you can output any of them. Examples Input 3 3 3 7 14 1 5 6 10 11 15 Output 0 0 0 Input 3 4 1 2 3 1 2 2 3 5 6 2 2 Output 1 0 1
a, b = map(int, input().split(" ")) pts = list(map(int, input().split(" "))) pts2 = [[pts[i], i, 0] for i in range(len(pts))] pts2.sort() for i in range(1, a, 2): pts2[i][2] = 1 pts2.sort(key=lambda x: x[1]) string = "" for i in pts2: string += str(i[2]) string += " " print(string.strip())
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST VAR VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segments on the OX axis. He can draw each point with either red or blue. The drawing is good if and only if the following requirement is met: for each segment [li, ri] consider all the red points belong to it (ri points), and all the blue points belong to it (bi points); each segment i should satisfy the inequality |ri - bi| ≀ 1. Iahub thinks that point x belongs to segment [l, r], if inequality l ≀ x ≀ r holds. Iahub gives to you all coordinates of points and segments. Please, help him to find any good drawing. Input The first line of input contains two integers: n (1 ≀ n ≀ 100) and m (1 ≀ m ≀ 100). The next line contains n space-separated integers x1, x2, ..., xn (0 ≀ xi ≀ 100) β€” the coordinates of the points. The following m lines contain the descriptions of the m segments. Each line contains two integers li and ri (0 ≀ li ≀ ri ≀ 100) β€” the borders of the i-th segment. It's guaranteed that all the points are distinct. Output If there is no good drawing for a given test, output a single integer -1. Otherwise output n integers, each integer must be 0 or 1. The i-th number denotes the color of the i-th point (0 is red, and 1 is blue). If there are multiple good drawings you can output any of them. Examples Input 3 3 3 7 14 1 5 6 10 11 15 Output 0 0 0 Input 3 4 1 2 3 1 2 2 3 5 6 2 2 Output 1 0 1
n, m = map(int, input().split()) a = list(map(int, input().split())) b = [] for i in range(n): b.append((a[i], i)) b.sort() for i in range(n): b[i] = b[i][0], b[i][1], i % 2 c = [] for i in b: c.append((i[1], i[0], i[2])) c.sort() for i in c: print(i[2], end=" ")
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 LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER STRING
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segments on the OX axis. He can draw each point with either red or blue. The drawing is good if and only if the following requirement is met: for each segment [li, ri] consider all the red points belong to it (ri points), and all the blue points belong to it (bi points); each segment i should satisfy the inequality |ri - bi| ≀ 1. Iahub thinks that point x belongs to segment [l, r], if inequality l ≀ x ≀ r holds. Iahub gives to you all coordinates of points and segments. Please, help him to find any good drawing. Input The first line of input contains two integers: n (1 ≀ n ≀ 100) and m (1 ≀ m ≀ 100). The next line contains n space-separated integers x1, x2, ..., xn (0 ≀ xi ≀ 100) β€” the coordinates of the points. The following m lines contain the descriptions of the m segments. Each line contains two integers li and ri (0 ≀ li ≀ ri ≀ 100) β€” the borders of the i-th segment. It's guaranteed that all the points are distinct. Output If there is no good drawing for a given test, output a single integer -1. Otherwise output n integers, each integer must be 0 or 1. The i-th number denotes the color of the i-th point (0 is red, and 1 is blue). If there are multiple good drawings you can output any of them. Examples Input 3 3 3 7 14 1 5 6 10 11 15 Output 0 0 0 Input 3 4 1 2 3 1 2 2 3 5 6 2 2 Output 1 0 1
n, m = map(int, input().split()) p = sorted((x[1], x[0]) for x in enumerate(map(int, input().split()))) p = sorted((x[1], str(i % 2)) for i, x in enumerate(p)) print(" ".join(x[1] for x in p))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER VAR VAR
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segments on the OX axis. He can draw each point with either red or blue. The drawing is good if and only if the following requirement is met: for each segment [li, ri] consider all the red points belong to it (ri points), and all the blue points belong to it (bi points); each segment i should satisfy the inequality |ri - bi| ≀ 1. Iahub thinks that point x belongs to segment [l, r], if inequality l ≀ x ≀ r holds. Iahub gives to you all coordinates of points and segments. Please, help him to find any good drawing. Input The first line of input contains two integers: n (1 ≀ n ≀ 100) and m (1 ≀ m ≀ 100). The next line contains n space-separated integers x1, x2, ..., xn (0 ≀ xi ≀ 100) β€” the coordinates of the points. The following m lines contain the descriptions of the m segments. Each line contains two integers li and ri (0 ≀ li ≀ ri ≀ 100) β€” the borders of the i-th segment. It's guaranteed that all the points are distinct. Output If there is no good drawing for a given test, output a single integer -1. Otherwise output n integers, each integer must be 0 or 1. The i-th number denotes the color of the i-th point (0 is red, and 1 is blue). If there are multiple good drawings you can output any of them. Examples Input 3 3 3 7 14 1 5 6 10 11 15 Output 0 0 0 Input 3 4 1 2 3 1 2 2 3 5 6 2 2 Output 1 0 1
n, m = list(map(int, input().split())) points = [(v, i) for i, v in enumerate(map(int, input().split()))] for _ in range(m): input() blue = True ans = [0] * n points = sorted(points) for p in points: v, i = p ans[i] = int(blue) blue = not blue for v in ans: print(v, end=" ") print()
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segments on the OX axis. He can draw each point with either red or blue. The drawing is good if and only if the following requirement is met: for each segment [li, ri] consider all the red points belong to it (ri points), and all the blue points belong to it (bi points); each segment i should satisfy the inequality |ri - bi| ≀ 1. Iahub thinks that point x belongs to segment [l, r], if inequality l ≀ x ≀ r holds. Iahub gives to you all coordinates of points and segments. Please, help him to find any good drawing. Input The first line of input contains two integers: n (1 ≀ n ≀ 100) and m (1 ≀ m ≀ 100). The next line contains n space-separated integers x1, x2, ..., xn (0 ≀ xi ≀ 100) β€” the coordinates of the points. The following m lines contain the descriptions of the m segments. Each line contains two integers li and ri (0 ≀ li ≀ ri ≀ 100) β€” the borders of the i-th segment. It's guaranteed that all the points are distinct. Output If there is no good drawing for a given test, output a single integer -1. Otherwise output n integers, each integer must be 0 or 1. The i-th number denotes the color of the i-th point (0 is red, and 1 is blue). If there are multiple good drawings you can output any of them. Examples Input 3 3 3 7 14 1 5 6 10 11 15 Output 0 0 0 Input 3 4 1 2 3 1 2 2 3 5 6 2 2 Output 1 0 1
n, m = map(int, input().split()) xlist = [int(x) for x in input().split()] plist = xlist[:] xlist.sort() for i in range(n): if xlist.index(plist[i]) % 2 == 0: plist[i] = "0" else: plist[i] = "1" print("".join([(plist[i] + " ") for i in range(n)]))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR VAR STRING VAR FUNC_CALL VAR VAR
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segments on the OX axis. He can draw each point with either red or blue. The drawing is good if and only if the following requirement is met: for each segment [li, ri] consider all the red points belong to it (ri points), and all the blue points belong to it (bi points); each segment i should satisfy the inequality |ri - bi| ≀ 1. Iahub thinks that point x belongs to segment [l, r], if inequality l ≀ x ≀ r holds. Iahub gives to you all coordinates of points and segments. Please, help him to find any good drawing. Input The first line of input contains two integers: n (1 ≀ n ≀ 100) and m (1 ≀ m ≀ 100). The next line contains n space-separated integers x1, x2, ..., xn (0 ≀ xi ≀ 100) β€” the coordinates of the points. The following m lines contain the descriptions of the m segments. Each line contains two integers li and ri (0 ≀ li ≀ ri ≀ 100) β€” the borders of the i-th segment. It's guaranteed that all the points are distinct. Output If there is no good drawing for a given test, output a single integer -1. Otherwise output n integers, each integer must be 0 or 1. The i-th number denotes the color of the i-th point (0 is red, and 1 is blue). If there are multiple good drawings you can output any of them. Examples Input 3 3 3 7 14 1 5 6 10 11 15 Output 0 0 0 Input 3 4 1 2 3 1 2 2 3 5 6 2 2 Output 1 0 1
n, m = map(int, input().split()) L = list(map(int, input().split())) for i in range(n): L[i] = L[i], i L.sort() Ans = [0] * n for i in range(n): Ans[L[i][1]] = i % 2 for i in range(n): print(Ans[i], end=" ")
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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segments on the OX axis. He can draw each point with either red or blue. The drawing is good if and only if the following requirement is met: for each segment [li, ri] consider all the red points belong to it (ri points), and all the blue points belong to it (bi points); each segment i should satisfy the inequality |ri - bi| ≀ 1. Iahub thinks that point x belongs to segment [l, r], if inequality l ≀ x ≀ r holds. Iahub gives to you all coordinates of points and segments. Please, help him to find any good drawing. Input The first line of input contains two integers: n (1 ≀ n ≀ 100) and m (1 ≀ m ≀ 100). The next line contains n space-separated integers x1, x2, ..., xn (0 ≀ xi ≀ 100) β€” the coordinates of the points. The following m lines contain the descriptions of the m segments. Each line contains two integers li and ri (0 ≀ li ≀ ri ≀ 100) β€” the borders of the i-th segment. It's guaranteed that all the points are distinct. Output If there is no good drawing for a given test, output a single integer -1. Otherwise output n integers, each integer must be 0 or 1. The i-th number denotes the color of the i-th point (0 is red, and 1 is blue). If there are multiple good drawings you can output any of them. Examples Input 3 3 3 7 14 1 5 6 10 11 15 Output 0 0 0 Input 3 4 1 2 3 1 2 2 3 5 6 2 2 Output 1 0 1
n, m = map(int, input().split()) xs = list(map(int, input().split())) ys = sorted(range(n), key=xs.__getitem__) zs = sorted((ys[i], i % 2) for i in range(n)) print(*(z[1] for z in zs))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR VAR
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segments on the OX axis. He can draw each point with either red or blue. The drawing is good if and only if the following requirement is met: for each segment [li, ri] consider all the red points belong to it (ri points), and all the blue points belong to it (bi points); each segment i should satisfy the inequality |ri - bi| ≀ 1. Iahub thinks that point x belongs to segment [l, r], if inequality l ≀ x ≀ r holds. Iahub gives to you all coordinates of points and segments. Please, help him to find any good drawing. Input The first line of input contains two integers: n (1 ≀ n ≀ 100) and m (1 ≀ m ≀ 100). The next line contains n space-separated integers x1, x2, ..., xn (0 ≀ xi ≀ 100) β€” the coordinates of the points. The following m lines contain the descriptions of the m segments. Each line contains two integers li and ri (0 ≀ li ≀ ri ≀ 100) β€” the borders of the i-th segment. It's guaranteed that all the points are distinct. Output If there is no good drawing for a given test, output a single integer -1. Otherwise output n integers, each integer must be 0 or 1. The i-th number denotes the color of the i-th point (0 is red, and 1 is blue). If there are multiple good drawings you can output any of them. Examples Input 3 3 3 7 14 1 5 6 10 11 15 Output 0 0 0 Input 3 4 1 2 3 1 2 2 3 5 6 2 2 Output 1 0 1
n, m = map(int, input().split()) X = [int(x) for x in input().split()] segs = [[int(x) for x in input().split()] for _ in range(m)] D = {e: (i % 2) for i, e in enumerate(sorted(X))} for i in range(n): X[i] = D[X[i]] print(*X)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segments on the OX axis. He can draw each point with either red or blue. The drawing is good if and only if the following requirement is met: for each segment [li, ri] consider all the red points belong to it (ri points), and all the blue points belong to it (bi points); each segment i should satisfy the inequality |ri - bi| ≀ 1. Iahub thinks that point x belongs to segment [l, r], if inequality l ≀ x ≀ r holds. Iahub gives to you all coordinates of points and segments. Please, help him to find any good drawing. Input The first line of input contains two integers: n (1 ≀ n ≀ 100) and m (1 ≀ m ≀ 100). The next line contains n space-separated integers x1, x2, ..., xn (0 ≀ xi ≀ 100) β€” the coordinates of the points. The following m lines contain the descriptions of the m segments. Each line contains two integers li and ri (0 ≀ li ≀ ri ≀ 100) β€” the borders of the i-th segment. It's guaranteed that all the points are distinct. Output If there is no good drawing for a given test, output a single integer -1. Otherwise output n integers, each integer must be 0 or 1. The i-th number denotes the color of the i-th point (0 is red, and 1 is blue). If there are multiple good drawings you can output any of them. Examples Input 3 3 3 7 14 1 5 6 10 11 15 Output 0 0 0 Input 3 4 1 2 3 1 2 2 3 5 6 2 2 Output 1 0 1
n, m = map(int, input().split()) a = [int(i) for i in input().split()] b = sorted([[a[i], i] for i in range(n)]) for i in range(m): l, r = map(int, input().split()) for i in range(n): a[b[i][1]] = str(i % 2) print(" ".join(a))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segments on the OX axis. He can draw each point with either red or blue. The drawing is good if and only if the following requirement is met: for each segment [li, ri] consider all the red points belong to it (ri points), and all the blue points belong to it (bi points); each segment i should satisfy the inequality |ri - bi| ≀ 1. Iahub thinks that point x belongs to segment [l, r], if inequality l ≀ x ≀ r holds. Iahub gives to you all coordinates of points and segments. Please, help him to find any good drawing. Input The first line of input contains two integers: n (1 ≀ n ≀ 100) and m (1 ≀ m ≀ 100). The next line contains n space-separated integers x1, x2, ..., xn (0 ≀ xi ≀ 100) β€” the coordinates of the points. The following m lines contain the descriptions of the m segments. Each line contains two integers li and ri (0 ≀ li ≀ ri ≀ 100) β€” the borders of the i-th segment. It's guaranteed that all the points are distinct. Output If there is no good drawing for a given test, output a single integer -1. Otherwise output n integers, each integer must be 0 or 1. The i-th number denotes the color of the i-th point (0 is red, and 1 is blue). If there are multiple good drawings you can output any of them. Examples Input 3 3 3 7 14 1 5 6 10 11 15 Output 0 0 0 Input 3 4 1 2 3 1 2 2 3 5 6 2 2 Output 1 0 1
n, m = map(int, input().split()) points = list(map(int, input().split())) segments = [input().split() for _ in range(m)] sorted_points = sorted(points) ans = [-1] * n for i in range(n): c = "0" if i % 2 else "1" ans[points.index(sorted_points[i])] = c print(" ".join(ans))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER STRING STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segments on the OX axis. He can draw each point with either red or blue. The drawing is good if and only if the following requirement is met: for each segment [li, ri] consider all the red points belong to it (ri points), and all the blue points belong to it (bi points); each segment i should satisfy the inequality |ri - bi| ≀ 1. Iahub thinks that point x belongs to segment [l, r], if inequality l ≀ x ≀ r holds. Iahub gives to you all coordinates of points and segments. Please, help him to find any good drawing. Input The first line of input contains two integers: n (1 ≀ n ≀ 100) and m (1 ≀ m ≀ 100). The next line contains n space-separated integers x1, x2, ..., xn (0 ≀ xi ≀ 100) β€” the coordinates of the points. The following m lines contain the descriptions of the m segments. Each line contains two integers li and ri (0 ≀ li ≀ ri ≀ 100) β€” the borders of the i-th segment. It's guaranteed that all the points are distinct. Output If there is no good drawing for a given test, output a single integer -1. Otherwise output n integers, each integer must be 0 or 1. The i-th number denotes the color of the i-th point (0 is red, and 1 is blue). If there are multiple good drawings you can output any of them. Examples Input 3 3 3 7 14 1 5 6 10 11 15 Output 0 0 0 Input 3 4 1 2 3 1 2 2 3 5 6 2 2 Output 1 0 1
n, m = map(int, input().split()) c = list(map(int, input().split())) cc = c.copy() d = [] for i in range(m): input() output = [] cc.sort() for i in c: index = cc.index(i) if index % 2 == 0: output.append("0") else: output.append("1") print(" ".join(output))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segments on the OX axis. He can draw each point with either red or blue. The drawing is good if and only if the following requirement is met: for each segment [li, ri] consider all the red points belong to it (ri points), and all the blue points belong to it (bi points); each segment i should satisfy the inequality |ri - bi| ≀ 1. Iahub thinks that point x belongs to segment [l, r], if inequality l ≀ x ≀ r holds. Iahub gives to you all coordinates of points and segments. Please, help him to find any good drawing. Input The first line of input contains two integers: n (1 ≀ n ≀ 100) and m (1 ≀ m ≀ 100). The next line contains n space-separated integers x1, x2, ..., xn (0 ≀ xi ≀ 100) β€” the coordinates of the points. The following m lines contain the descriptions of the m segments. Each line contains two integers li and ri (0 ≀ li ≀ ri ≀ 100) β€” the borders of the i-th segment. It's guaranteed that all the points are distinct. Output If there is no good drawing for a given test, output a single integer -1. Otherwise output n integers, each integer must be 0 or 1. The i-th number denotes the color of the i-th point (0 is red, and 1 is blue). If there are multiple good drawings you can output any of them. Examples Input 3 3 3 7 14 1 5 6 10 11 15 Output 0 0 0 Input 3 4 1 2 3 1 2 2 3 5 6 2 2 Output 1 0 1
n, m = map(int, input().split()) points = list(zip(map(int, input().split()), range(n))) points.sort() res = [] curr = 0 for point in points: res.append((point[1], (curr + 1) % 2)) curr += 1 res.sort() for point in res: print(point[1], end=" ")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER STRING
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segments on the OX axis. He can draw each point with either red or blue. The drawing is good if and only if the following requirement is met: for each segment [li, ri] consider all the red points belong to it (ri points), and all the blue points belong to it (bi points); each segment i should satisfy the inequality |ri - bi| ≀ 1. Iahub thinks that point x belongs to segment [l, r], if inequality l ≀ x ≀ r holds. Iahub gives to you all coordinates of points and segments. Please, help him to find any good drawing. Input The first line of input contains two integers: n (1 ≀ n ≀ 100) and m (1 ≀ m ≀ 100). The next line contains n space-separated integers x1, x2, ..., xn (0 ≀ xi ≀ 100) β€” the coordinates of the points. The following m lines contain the descriptions of the m segments. Each line contains two integers li and ri (0 ≀ li ≀ ri ≀ 100) β€” the borders of the i-th segment. It's guaranteed that all the points are distinct. Output If there is no good drawing for a given test, output a single integer -1. Otherwise output n integers, each integer must be 0 or 1. The i-th number denotes the color of the i-th point (0 is red, and 1 is blue). If there are multiple good drawings you can output any of them. Examples Input 3 3 3 7 14 1 5 6 10 11 15 Output 0 0 0 Input 3 4 1 2 3 1 2 2 3 5 6 2 2 Output 1 0 1
from sys import stdin, stdout nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int, stdin.readline().split())) for _ in range(1): n, k = lst() mp = {} a = lst() for i in range(n): mp[a[i]] = i b = sorted(a) turn = 0 ans = [0] * n for v in b: ans[mp[v]] = turn & 1 turn += 1 print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. The median of a sequence is the value of the element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is used. For example, if $a=[4, 2, 7, 5]$ then its median is $4$ since after sorting the sequence, it will look like $[2, 4, 5, 7]$ and the left of two middle elements is equal to $4$. The median of $[7, 1, 2, 9, 6]$ equals $6$ since after sorting, the value $6$ will be in the middle of the sequence. Write a program to find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. -----Input----- The first line contains integers $n$ and $m$ ($1 \le n \le 2\cdot10^5$, $1 \le m \le n$) β€” the length of the given sequence and the required value of the median. The second line contains a permutation $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$). Each integer between $1$ and $n$ occurs in $p$ exactly once. -----Output----- Print the required number. -----Examples----- Input 5 4 2 4 5 3 1 Output 4 Input 5 5 1 2 3 4 5 Output 1 Input 15 8 1 15 2 14 3 13 4 8 12 5 11 6 10 7 9 Output 48 -----Note----- In the first example, the suitable pairs of indices are: $(1, 3)$, $(2, 2)$, $(2, 3)$ and $(2, 4)$.
n, m = map(int, input().split()) a = list(map(int, input().split())) d = dict() d[0] = 1 flag = 0 x = 0 ans = 0 for r in range(n): if a[r] < m: x -= 1 elif a[r] > m: x += 1 else: flag = 1 if flag: ans += d.get(x, 0) + d.get(x - 1, 0) else: t = d.get(x, 0) + 1 d[x] = t print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. The median of a sequence is the value of the element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is used. For example, if $a=[4, 2, 7, 5]$ then its median is $4$ since after sorting the sequence, it will look like $[2, 4, 5, 7]$ and the left of two middle elements is equal to $4$. The median of $[7, 1, 2, 9, 6]$ equals $6$ since after sorting, the value $6$ will be in the middle of the sequence. Write a program to find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. -----Input----- The first line contains integers $n$ and $m$ ($1 \le n \le 2\cdot10^5$, $1 \le m \le n$) β€” the length of the given sequence and the required value of the median. The second line contains a permutation $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$). Each integer between $1$ and $n$ occurs in $p$ exactly once. -----Output----- Print the required number. -----Examples----- Input 5 4 2 4 5 3 1 Output 4 Input 5 5 1 2 3 4 5 Output 1 Input 15 8 1 15 2 14 3 13 4 8 12 5 11 6 10 7 9 Output 48 -----Note----- In the first example, the suitable pairs of indices are: $(1, 3)$, $(2, 2)$, $(2, 3)$ and $(2, 4)$.
n, m = map(int, input().split()) p = list(map(int, input().split())) ld = {} rd = {} def push(d, x): if x not in d: d[x] = 0 d[x] += 1 def count(d, m, arr, cnt): b, s = 0, 0 for x in arr: if x > m: b += 1 else: s += 1 if b - s in [0, 1]: cnt[0] += 1 push(d, b - s) index_m = -1 for i, x in enumerate(p): if x == m: index_m = i break cnt = [0] count(ld, m, p[:index_m][::-1], cnt) count(rd, m, p[index_m + 1 :], cnt) for x, f in ld.items(): if -x in rd: cnt[0] += f * rd[-x] if 1 - x in rd: cnt[0] += f * rd[1 - x] print(cnt[0] + 1)
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 DICT ASSIGN VAR DICT FUNC_DEF IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR LIST NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FOR VAR VAR FUNC_CALL VAR IF VAR VAR VAR NUMBER BIN_OP VAR VAR VAR IF BIN_OP NUMBER VAR VAR VAR NUMBER BIN_OP VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. The median of a sequence is the value of the element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is used. For example, if $a=[4, 2, 7, 5]$ then its median is $4$ since after sorting the sequence, it will look like $[2, 4, 5, 7]$ and the left of two middle elements is equal to $4$. The median of $[7, 1, 2, 9, 6]$ equals $6$ since after sorting, the value $6$ will be in the middle of the sequence. Write a program to find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. -----Input----- The first line contains integers $n$ and $m$ ($1 \le n \le 2\cdot10^5$, $1 \le m \le n$) β€” the length of the given sequence and the required value of the median. The second line contains a permutation $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$). Each integer between $1$ and $n$ occurs in $p$ exactly once. -----Output----- Print the required number. -----Examples----- Input 5 4 2 4 5 3 1 Output 4 Input 5 5 1 2 3 4 5 Output 1 Input 15 8 1 15 2 14 3 13 4 8 12 5 11 6 10 7 9 Output 48 -----Note----- In the first example, the suitable pairs of indices are: $(1, 3)$, $(2, 2)$, $(2, 3)$ and $(2, 4)$.
n, m = list(map(int, input().strip().split())) a = list(map(int, input().strip().split())) for i in range(n): if a[i] == m: pos = i l = 0 r = 0 d = False resLD, resLP, resRD, resRP = {(0): 1}, {}, {(0): 1}, {} for j in range(pos - 1, -1, -1): if a[j] > m: l += 1 elif a[j] < m: l -= 1 if d: try: resLD[l] += 1 except: resLD[l] = 1 d = False else: try: resLP[l] += 1 except: resLP[l] = 1 d = True l = 0 r = 0 d = False for j in range(pos + 1, n): if a[j] > m: l += 1 elif a[j] < m: l -= 1 if d: try: resRD[l] += 1 except: resRD[l] = 1 d = False else: try: resRP[l] += 1 except: resRP[l] = 1 d = True s = 0 for k in resLP.keys(): if -k in resRP.keys(): s += resLP[k] * resRP[-k] if -k + 1 in resRD.keys(): s += resLP[k] * resRD[-k + 1] for k in resLD.keys(): if -k in resRD.keys(): s += resLD[k] * resRD[-k] if -k + 1 in resRP.keys(): s += resLD[k] * resRP[-k + 1] print(s)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR DICT NUMBER NUMBER DICT DICT NUMBER NUMBER DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. The median of a sequence is the value of the element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is used. For example, if $a=[4, 2, 7, 5]$ then its median is $4$ since after sorting the sequence, it will look like $[2, 4, 5, 7]$ and the left of two middle elements is equal to $4$. The median of $[7, 1, 2, 9, 6]$ equals $6$ since after sorting, the value $6$ will be in the middle of the sequence. Write a program to find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. -----Input----- The first line contains integers $n$ and $m$ ($1 \le n \le 2\cdot10^5$, $1 \le m \le n$) β€” the length of the given sequence and the required value of the median. The second line contains a permutation $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$). Each integer between $1$ and $n$ occurs in $p$ exactly once. -----Output----- Print the required number. -----Examples----- Input 5 4 2 4 5 3 1 Output 4 Input 5 5 1 2 3 4 5 Output 1 Input 15 8 1 15 2 14 3 13 4 8 12 5 11 6 10 7 9 Output 48 -----Note----- In the first example, the suitable pairs of indices are: $(1, 3)$, $(2, 2)$, $(2, 3)$ and $(2, 4)$.
def readints(): return [int(x) for x in input().strip().split()] def main(): n, m = readints() p = readints() sums = {} pivot = p.index(m) diff = 0 sums[0] = 1 for i in range(pivot - 1, -1, -1): if p[i] > m: diff += 1 else: diff -= 1 sums.setdefault(diff, 0) sums[diff] += 1 ans = 0 diff = 0 for i in range(pivot, n): if p[i] > m: diff += 1 if p[i] < m: diff -= 1 ans += sums.get(-diff, 0) + sums.get(1 - diff, 0) print(ans) def __starting_point(): main() __starting_point()
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. The median of a sequence is the value of the element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is used. For example, if $a=[4, 2, 7, 5]$ then its median is $4$ since after sorting the sequence, it will look like $[2, 4, 5, 7]$ and the left of two middle elements is equal to $4$. The median of $[7, 1, 2, 9, 6]$ equals $6$ since after sorting, the value $6$ will be in the middle of the sequence. Write a program to find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. -----Input----- The first line contains integers $n$ and $m$ ($1 \le n \le 2\cdot10^5$, $1 \le m \le n$) β€” the length of the given sequence and the required value of the median. The second line contains a permutation $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$). Each integer between $1$ and $n$ occurs in $p$ exactly once. -----Output----- Print the required number. -----Examples----- Input 5 4 2 4 5 3 1 Output 4 Input 5 5 1 2 3 4 5 Output 1 Input 15 8 1 15 2 14 3 13 4 8 12 5 11 6 10 7 9 Output 48 -----Note----- In the first example, the suitable pairs of indices are: $(1, 3)$, $(2, 2)$, $(2, 3)$ and $(2, 4)$.
n, m = map(int, input().split()) p = list(map(int, input().split())) cur = 0 while p[cur] != m: cur += 1 pos = cur s = {} cnt, len = 0, 0 while cur >= 0: if p[cur] <= m: cnt += 1 len += 1 if 2 * cnt - len in s: s[2 * cnt - len] += 1 else: s[2 * cnt - len] = 1 cur -= 1 cur = pos cnt, len, ans = 0, 0, 0 while cur < n: if p[cur] <= m: cnt += 1 len += 1 if len - 2 * cnt + 1 in s: ans += s[len - 2 * cnt + 1] if len - 2 * cnt + 2 in s: ans += s[len - 2 * cnt + 2] cur += 1 print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR DICT ASSIGN VAR VAR NUMBER NUMBER WHILE VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. The median of a sequence is the value of the element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is used. For example, if $a=[4, 2, 7, 5]$ then its median is $4$ since after sorting the sequence, it will look like $[2, 4, 5, 7]$ and the left of two middle elements is equal to $4$. The median of $[7, 1, 2, 9, 6]$ equals $6$ since after sorting, the value $6$ will be in the middle of the sequence. Write a program to find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. -----Input----- The first line contains integers $n$ and $m$ ($1 \le n \le 2\cdot10^5$, $1 \le m \le n$) β€” the length of the given sequence and the required value of the median. The second line contains a permutation $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$). Each integer between $1$ and $n$ occurs in $p$ exactly once. -----Output----- Print the required number. -----Examples----- Input 5 4 2 4 5 3 1 Output 4 Input 5 5 1 2 3 4 5 Output 1 Input 15 8 1 15 2 14 3 13 4 8 12 5 11 6 10 7 9 Output 48 -----Note----- In the first example, the suitable pairs of indices are: $(1, 3)$, $(2, 2)$, $(2, 3)$ and $(2, 4)$.
def Yeee(x, v, n): re = 0 pre = 0 sum = 1 cnt = [0] * n + [1] + [0] * n for i in v: if i < x: pre += 1 sum += cnt[pre + n] else: sum -= cnt[pre + n] pre -= 1 cnt[pre + n] += 1 re += sum return re n, x = map(int, input().split()) v = [int(i) for i in input().split()] print(Yeee(x + 1, v, n) - Yeee(x, v, n))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST NUMBER VAR LIST NUMBER BIN_OP LIST NUMBER VAR FOR VAR VAR IF VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. The median of a sequence is the value of the element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is used. For example, if $a=[4, 2, 7, 5]$ then its median is $4$ since after sorting the sequence, it will look like $[2, 4, 5, 7]$ and the left of two middle elements is equal to $4$. The median of $[7, 1, 2, 9, 6]$ equals $6$ since after sorting, the value $6$ will be in the middle of the sequence. Write a program to find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. -----Input----- The first line contains integers $n$ and $m$ ($1 \le n \le 2\cdot10^5$, $1 \le m \le n$) β€” the length of the given sequence and the required value of the median. The second line contains a permutation $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$). Each integer between $1$ and $n$ occurs in $p$ exactly once. -----Output----- Print the required number. -----Examples----- Input 5 4 2 4 5 3 1 Output 4 Input 5 5 1 2 3 4 5 Output 1 Input 15 8 1 15 2 14 3 13 4 8 12 5 11 6 10 7 9 Output 48 -----Note----- In the first example, the suitable pairs of indices are: $(1, 3)$, $(2, 2)$, $(2, 3)$ and $(2, 4)$.
n, m = map(int, input().split()) b = list(map(int, input().split())) p = b.index(m) j = p + 1 r = 1 x = 0 y = 0 c = [] d = [] while j < n: if b[j] < m: x += 1 else: y += 1 c.append(y - x) j += 1 j = p - 1 x = 0 y = 0 while j >= 0: if b[j] < m: x += 1 else: y += 1 d.append(y - x) j += -1 p = dict() q = dict() for j in range(len(c)): if c[j] in p.keys(): p[c[j]] += 1 else: p[c[j]] = 1 for j in range(len(d)): if d[j] in q.keys(): q[d[j]] += 1 else: q[d[j]] = 1 if 0 in p.keys(): r += p[0] if 0 in q.keys(): r += q[0] if 1 in p.keys(): r += p[1] if 1 in q.keys(): r += q[1] for j in range(len(c)): s = 1 - c[j] t = -c[j] if s in q.keys(): r += q[s] if t in q.keys(): r += q[t] print(r)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF NUMBER FUNC_CALL VAR VAR VAR NUMBER IF NUMBER FUNC_CALL VAR VAR VAR NUMBER IF NUMBER FUNC_CALL VAR VAR VAR NUMBER IF NUMBER FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR VAR ASSIGN VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. The median of a sequence is the value of the element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is used. For example, if $a=[4, 2, 7, 5]$ then its median is $4$ since after sorting the sequence, it will look like $[2, 4, 5, 7]$ and the left of two middle elements is equal to $4$. The median of $[7, 1, 2, 9, 6]$ equals $6$ since after sorting, the value $6$ will be in the middle of the sequence. Write a program to find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. -----Input----- The first line contains integers $n$ and $m$ ($1 \le n \le 2\cdot10^5$, $1 \le m \le n$) β€” the length of the given sequence and the required value of the median. The second line contains a permutation $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$). Each integer between $1$ and $n$ occurs in $p$ exactly once. -----Output----- Print the required number. -----Examples----- Input 5 4 2 4 5 3 1 Output 4 Input 5 5 1 2 3 4 5 Output 1 Input 15 8 1 15 2 14 3 13 4 8 12 5 11 6 10 7 9 Output 48 -----Note----- In the first example, the suitable pairs of indices are: $(1, 3)$, $(2, 2)$, $(2, 3)$ and $(2, 4)$.
n, m = map(int, input().split(" ")) aa = list(map(int, input().split(" "))) def countMoreLess(vs, value): cur = 0 res = {cur: 1} for v in vs: cur += 1 if v > value else -1 res[cur] = res.get(cur, 0) + 1 return res pos = aa.index(m) leftCounts = countMoreLess(list(reversed(aa[0:pos])), m) rightCounts = countMoreLess(aa[pos + 1 :], m) res = 0 for dif, count in leftCounts.items(): res += count * rightCounts.get(-dif, 0) res += count * rightCounts.get(-dif + 1, 0) print(res)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT VAR NUMBER FOR VAR VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. The median of a sequence is the value of the element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is used. For example, if $a=[4, 2, 7, 5]$ then its median is $4$ since after sorting the sequence, it will look like $[2, 4, 5, 7]$ and the left of two middle elements is equal to $4$. The median of $[7, 1, 2, 9, 6]$ equals $6$ since after sorting, the value $6$ will be in the middle of the sequence. Write a program to find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. -----Input----- The first line contains integers $n$ and $m$ ($1 \le n \le 2\cdot10^5$, $1 \le m \le n$) β€” the length of the given sequence and the required value of the median. The second line contains a permutation $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$). Each integer between $1$ and $n$ occurs in $p$ exactly once. -----Output----- Print the required number. -----Examples----- Input 5 4 2 4 5 3 1 Output 4 Input 5 5 1 2 3 4 5 Output 1 Input 15 8 1 15 2 14 3 13 4 8 12 5 11 6 10 7 9 Output 48 -----Note----- In the first example, the suitable pairs of indices are: $(1, 3)$, $(2, 2)$, $(2, 3)$ and $(2, 4)$.
n, m = list(map(int, input().split())) p = list(map(int, input().split())) mindex = p.index(m) ldict = {} rdict = {} diff = 0 ans = 0 ldict[0] = 1 rdict[0] = 1 for i in range(mindex - 1, -1, -1): if p[i] < m: diff -= 1 else: diff += 1 if diff in ldict.keys(): ldict[diff] += 1 else: ldict[diff] = 1 diff = 0 for i in range(mindex + 1, n): if p[i] < m: diff -= 1 else: diff += 1 if diff in rdict.keys(): rdict[diff] += 1 else: rdict[diff] = 1 ldictkey = ldict.keys() for num in ldictkey: if -num in rdict.keys(): ans += ldict[num] * rdict[-num] if -num + 1 in rdict.keys(): ans += ldict[num] * rdict[-num + 1] print(ans)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. The median of a sequence is the value of the element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is used. For example, if $a=[4, 2, 7, 5]$ then its median is $4$ since after sorting the sequence, it will look like $[2, 4, 5, 7]$ and the left of two middle elements is equal to $4$. The median of $[7, 1, 2, 9, 6]$ equals $6$ since after sorting, the value $6$ will be in the middle of the sequence. Write a program to find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. -----Input----- The first line contains integers $n$ and $m$ ($1 \le n \le 2\cdot10^5$, $1 \le m \le n$) β€” the length of the given sequence and the required value of the median. The second line contains a permutation $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$). Each integer between $1$ and $n$ occurs in $p$ exactly once. -----Output----- Print the required number. -----Examples----- Input 5 4 2 4 5 3 1 Output 4 Input 5 5 1 2 3 4 5 Output 1 Input 15 8 1 15 2 14 3 13 4 8 12 5 11 6 10 7 9 Output 48 -----Note----- In the first example, the suitable pairs of indices are: $(1, 3)$, $(2, 2)$, $(2, 3)$ and $(2, 4)$.
L1 = list(map(int, input().split())) numList = list(map(int, input().split())) length = L1[0] targetnumber = L1[1] pos = numList.index(targetnumber) pos_r = pos + 1 rem = 0 right = {(0): 1} left = {(0): 1} while pos_r <= length - 1: if numList[pos_r] > targetnumber: rem += 1 else: rem -= 1 if rem not in right: right[rem] = 1 else: right[rem] += 1 pos_r += 1 pos_l = pos - 1 rem = 0 while pos_l >= 0: if numList[pos_l] > targetnumber: rem += 1 else: rem -= 1 if rem not in left: left[rem] = 1 else: left[rem] += 1 pos_l -= 1 sum = 0 for number_l in left: if number_l * -1 in right: sum += left[number_l] * right[-1 * number_l] if 1 - number_l in right: sum += left[number_l] * right[1 - number_l] print(sum)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR DICT NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR VAR BIN_OP NUMBER VAR IF BIN_OP NUMBER VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. The median of a sequence is the value of the element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is used. For example, if $a=[4, 2, 7, 5]$ then its median is $4$ since after sorting the sequence, it will look like $[2, 4, 5, 7]$ and the left of two middle elements is equal to $4$. The median of $[7, 1, 2, 9, 6]$ equals $6$ since after sorting, the value $6$ will be in the middle of the sequence. Write a program to find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. -----Input----- The first line contains integers $n$ and $m$ ($1 \le n \le 2\cdot10^5$, $1 \le m \le n$) β€” the length of the given sequence and the required value of the median. The second line contains a permutation $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$). Each integer between $1$ and $n$ occurs in $p$ exactly once. -----Output----- Print the required number. -----Examples----- Input 5 4 2 4 5 3 1 Output 4 Input 5 5 1 2 3 4 5 Output 1 Input 15 8 1 15 2 14 3 13 4 8 12 5 11 6 10 7 9 Output 48 -----Note----- In the first example, the suitable pairs of indices are: $(1, 3)$, $(2, 2)$, $(2, 3)$ and $(2, 4)$.
MAXN = 200001 n, m = list(map(int, input().split(" "))) s = list(map(int, input().split(" "))) f = [(0) for i in range(n + 1)] count = [(0) for i in range(-MAXN, MAXN + 1)] f[0] = 0 last = 0 res = 0 for i in range(1, n + 1): if s[i - 1] == m: for j in range(last, i): count[f[j]] += 1 last = i if s[i - 1] > m: f[i] = f[i - 1] - 1 else: f[i] = f[i - 1] + 1 res += count[f[i]] + count[f[i] - 1] print(res)
ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. The median of a sequence is the value of the element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is used. For example, if $a=[4, 2, 7, 5]$ then its median is $4$ since after sorting the sequence, it will look like $[2, 4, 5, 7]$ and the left of two middle elements is equal to $4$. The median of $[7, 1, 2, 9, 6]$ equals $6$ since after sorting, the value $6$ will be in the middle of the sequence. Write a program to find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. -----Input----- The first line contains integers $n$ and $m$ ($1 \le n \le 2\cdot10^5$, $1 \le m \le n$) β€” the length of the given sequence and the required value of the median. The second line contains a permutation $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$). Each integer between $1$ and $n$ occurs in $p$ exactly once. -----Output----- Print the required number. -----Examples----- Input 5 4 2 4 5 3 1 Output 4 Input 5 5 1 2 3 4 5 Output 1 Input 15 8 1 15 2 14 3 13 4 8 12 5 11 6 10 7 9 Output 48 -----Note----- In the first example, the suitable pairs of indices are: $(1, 3)$, $(2, 2)$, $(2, 3)$ and $(2, 4)$.
def main(): n, m = map(int, input().split()) ar = list(map(int, input().split())) dp = [0] start = -1 for index, elm in enumerate(ar): if elm > m: dp.append(dp[-1] + 1) elif elm < m: dp.append(dp[-1] - 1) else: dp.append(dp[-1]) if elm == m: start = index + 1 even = {} odd = {} for i in range(start): if i % 2 == 0: if dp[i] not in even: even[dp[i]] = 1 else: even[dp[i]] += 1 elif dp[i] not in odd: odd[dp[i]] = 1 else: odd[dp[i]] += 1 ans = 0 for i in range(start, len(dp)): if i % 2 == 0: if dp[i] - 1 in even: ans += even[dp[i] - 1] if dp[i] in odd: ans += odd[dp[i]] else: if dp[i] - 1 in odd: ans += odd[dp[i] - 1] if dp[i] in even: ans += even[dp[i]] print(ans) main()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. The median of a sequence is the value of the element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is used. For example, if $a=[4, 2, 7, 5]$ then its median is $4$ since after sorting the sequence, it will look like $[2, 4, 5, 7]$ and the left of two middle elements is equal to $4$. The median of $[7, 1, 2, 9, 6]$ equals $6$ since after sorting, the value $6$ will be in the middle of the sequence. Write a program to find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. -----Input----- The first line contains integers $n$ and $m$ ($1 \le n \le 2\cdot10^5$, $1 \le m \le n$) β€” the length of the given sequence and the required value of the median. The second line contains a permutation $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$). Each integer between $1$ and $n$ occurs in $p$ exactly once. -----Output----- Print the required number. -----Examples----- Input 5 4 2 4 5 3 1 Output 4 Input 5 5 1 2 3 4 5 Output 1 Input 15 8 1 15 2 14 3 13 4 8 12 5 11 6 10 7 9 Output 48 -----Note----- In the first example, the suitable pairs of indices are: $(1, 3)$, $(2, 2)$, $(2, 3)$ and $(2, 4)$.
n, m = list(map(int, input().split())) t = list(map(int, input().split())) mid = t.index(m) lefts = [0] * 600000 lefts[300000] = 1 gt = 0 lt = 0 for i in range(mid - 1, -1, -1): if t[i] < m: lt += 1 else: gt += 1 lefts[300000 + gt - lt] += 1 rights = [0] * 600000 rights[300000] = 1 gt = 0 lt = 0 for i in range(mid + 1, n): if t[i] < m: lt += 1 else: gt += 1 rights[300000 + gt - lt] += 1 res = 0 for i in range(0, 210000): res += lefts[300000 - i] * rights[300000 + i] res += lefts[300000 - i] * rights[300000 + i + 1] if i != 0: res += lefts[300000 + i] * rights[300000 - i] res += lefts[300000 + i] * rights[300000 - i + 1] print(res)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. The median of a sequence is the value of the element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is used. For example, if $a=[4, 2, 7, 5]$ then its median is $4$ since after sorting the sequence, it will look like $[2, 4, 5, 7]$ and the left of two middle elements is equal to $4$. The median of $[7, 1, 2, 9, 6]$ equals $6$ since after sorting, the value $6$ will be in the middle of the sequence. Write a program to find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. -----Input----- The first line contains integers $n$ and $m$ ($1 \le n \le 2\cdot10^5$, $1 \le m \le n$) β€” the length of the given sequence and the required value of the median. The second line contains a permutation $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$). Each integer between $1$ and $n$ occurs in $p$ exactly once. -----Output----- Print the required number. -----Examples----- Input 5 4 2 4 5 3 1 Output 4 Input 5 5 1 2 3 4 5 Output 1 Input 15 8 1 15 2 14 3 13 4 8 12 5 11 6 10 7 9 Output 48 -----Note----- In the first example, the suitable pairs of indices are: $(1, 3)$, $(2, 2)$, $(2, 3)$ and $(2, 4)$.
T = input().split(" ") n = int(T[0]) m = int(T[1]) S = input().split(" ") for i in range(n): S[i] = int(S[i]) ind = 0 for k in range(n): if S[k] == m: ind = k k = ind P = [0] * (n + 1) N = [0] * (n + 1) R = [0] * (n - k) L = [0] * (k + 1) for i in range(k): if S[k - 1 - i] < m: L[k - 1 - i] = L[k - i] - 1 else: L[k - 1 - i] = L[k - i] + 1 for i in range(n - k - 1): if S[k + 1 + i] > m: R[1 + i] = R[i] + 1 else: R[1 + i] = R[i] - 1 c = 0 for el in R: if el >= 0: P[el] += 1 if el == 0: N[el] += 1 else: N[-el] += 1 for el in L: if el >= 1: c = c + N[el] + N[el - 1] else: c = c + P[-el] + P[-el + 1] print(c)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. The median of a sequence is the value of the element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is used. For example, if $a=[4, 2, 7, 5]$ then its median is $4$ since after sorting the sequence, it will look like $[2, 4, 5, 7]$ and the left of two middle elements is equal to $4$. The median of $[7, 1, 2, 9, 6]$ equals $6$ since after sorting, the value $6$ will be in the middle of the sequence. Write a program to find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. -----Input----- The first line contains integers $n$ and $m$ ($1 \le n \le 2\cdot10^5$, $1 \le m \le n$) β€” the length of the given sequence and the required value of the median. The second line contains a permutation $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$). Each integer between $1$ and $n$ occurs in $p$ exactly once. -----Output----- Print the required number. -----Examples----- Input 5 4 2 4 5 3 1 Output 4 Input 5 5 1 2 3 4 5 Output 1 Input 15 8 1 15 2 14 3 13 4 8 12 5 11 6 10 7 9 Output 48 -----Note----- In the first example, the suitable pairs of indices are: $(1, 3)$, $(2, 2)$, $(2, 3)$ and $(2, 4)$.
n, m = map(int, input().split(" ")) numbers = list(map(int, input().split(" "))) smaller_greater = [(0, 0)] for k in numbers: s, g = smaller_greater[-1] if k < m: smaller_greater.append((s + 1, g)) elif k > m: smaller_greater.append((s, g + 1)) else: smaller_greater.append((s, g)) i = numbers.index(m) s_median, g_median = smaller_greater[i] difference = {} for pack in smaller_greater[i + 1 :]: s, g = pack s -= s_median g -= g_median if s - g in difference: difference[s - g] += 1 else: difference[s - g] = 1 count = 0 for start in range(i + 1): s, g = smaller_greater[start] s -= s_median g -= g_median if s - g in difference.keys(): count += difference[s - g] if s - g - 1 in difference.keys(): count += difference[s - g - 1] print(count)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. The median of a sequence is the value of the element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is used. For example, if $a=[4, 2, 7, 5]$ then its median is $4$ since after sorting the sequence, it will look like $[2, 4, 5, 7]$ and the left of two middle elements is equal to $4$. The median of $[7, 1, 2, 9, 6]$ equals $6$ since after sorting, the value $6$ will be in the middle of the sequence. Write a program to find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. -----Input----- The first line contains integers $n$ and $m$ ($1 \le n \le 2\cdot10^5$, $1 \le m \le n$) β€” the length of the given sequence and the required value of the median. The second line contains a permutation $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$). Each integer between $1$ and $n$ occurs in $p$ exactly once. -----Output----- Print the required number. -----Examples----- Input 5 4 2 4 5 3 1 Output 4 Input 5 5 1 2 3 4 5 Output 1 Input 15 8 1 15 2 14 3 13 4 8 12 5 11 6 10 7 9 Output 48 -----Note----- In the first example, the suitable pairs of indices are: $(1, 3)$, $(2, 2)$, $(2, 3)$ and $(2, 4)$.
n, m = list(map(int, input().split())) nums = list(map(int, input().split())) left = {} right = {} leftl = 0 leftm = 0 rightl = 0 rightm = 0 start = nums.index(m) ans = 1 for i in range(start - 1, -1, -1): if nums[i] > m: leftm += 1 else: leftl += 1 if leftl == leftm: ans += 1 elif leftl + 1 == leftm: ans += 1 temp = leftm - leftl if temp in list(left.keys()): left[temp] += 1 else: left[temp] = 1 for i in range(start + 1, n, 1): if nums[i] > m: rightm += 1 else: rightl += 1 if rightl == rightm: ans += 1 elif rightl + 1 == rightm: ans += 1 temp = rightm - rightl if temp in list(right.keys()): right[temp] += 1 else: right[temp] = 1 for i in list(left.keys()): poss = -1 * i if poss in list(right.keys()): ans += right[poss] * left[i] if poss + 1 in list(right.keys()): ans += right[poss + 1] * left[i] print(ans)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR IF VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. The median of a sequence is the value of the element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is used. For example, if $a=[4, 2, 7, 5]$ then its median is $4$ since after sorting the sequence, it will look like $[2, 4, 5, 7]$ and the left of two middle elements is equal to $4$. The median of $[7, 1, 2, 9, 6]$ equals $6$ since after sorting, the value $6$ will be in the middle of the sequence. Write a program to find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. -----Input----- The first line contains integers $n$ and $m$ ($1 \le n \le 2\cdot10^5$, $1 \le m \le n$) β€” the length of the given sequence and the required value of the median. The second line contains a permutation $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$). Each integer between $1$ and $n$ occurs in $p$ exactly once. -----Output----- Print the required number. -----Examples----- Input 5 4 2 4 5 3 1 Output 4 Input 5 5 1 2 3 4 5 Output 1 Input 15 8 1 15 2 14 3 13 4 8 12 5 11 6 10 7 9 Output 48 -----Note----- In the first example, the suitable pairs of indices are: $(1, 3)$, $(2, 2)$, $(2, 3)$ and $(2, 4)$.
import sys n, m = map(int, input().split()) s = list(map(int, input().split())) try: ind = s.index(m) except: print(0) sys.exit() dp = [(0) for i in range(n)] for i in range(ind + 1, n): if s[i] < m: dp[i] = dp[i - 1] - 1 elif s[i] > m: dp[i] = dp[i - 1] + 1 for i in range(ind - 1, -1, -1): if s[i] < m: dp[i] = dp[i + 1] - 1 elif s[i] > m: dp[i] = dp[i + 1] + 1 d = dict() for i in range(ind + 1, n): try: d[dp[i]] += 1 except: d.update({dp[i]: 1}) ans = 0 for i in range(ind + 1): x = -dp[i] try: ans += d[x] except: True try: ans += d[x + 1] except: True if dp[i] == 0 or dp[i] == 1: ans += 1 print(ans)
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR DICT VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR EXPR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. The median of a sequence is the value of the element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is used. For example, if $a=[4, 2, 7, 5]$ then its median is $4$ since after sorting the sequence, it will look like $[2, 4, 5, 7]$ and the left of two middle elements is equal to $4$. The median of $[7, 1, 2, 9, 6]$ equals $6$ since after sorting, the value $6$ will be in the middle of the sequence. Write a program to find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. -----Input----- The first line contains integers $n$ and $m$ ($1 \le n \le 2\cdot10^5$, $1 \le m \le n$) β€” the length of the given sequence and the required value of the median. The second line contains a permutation $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$). Each integer between $1$ and $n$ occurs in $p$ exactly once. -----Output----- Print the required number. -----Examples----- Input 5 4 2 4 5 3 1 Output 4 Input 5 5 1 2 3 4 5 Output 1 Input 15 8 1 15 2 14 3 13 4 8 12 5 11 6 10 7 9 Output 48 -----Note----- In the first example, the suitable pairs of indices are: $(1, 3)$, $(2, 2)$, $(2, 3)$ and $(2, 4)$.
n, m = [int(i) for i in input().split()] a = [int(i) for i in input().split()] diff = [0] * n for i in range(n): if a[i] < m: diff[i] = -1 if a[i] > m: diff[i] = 1 aim = a.index(m) left = {} right = {} suml = 0 for i in reversed(range(aim + 1)): suml += diff[i] if not suml in left: left[suml] = 0 left[suml] += 1 sumr = 0 for i in range(aim, n): sumr += diff[i] if not sumr in right: right[sumr] = 0 right[sumr] += 1 ans = 0 for i in left: wk1 = -i if wk1 in right: ans += left[i] * right[wk1] wk1 = 1 - i if wk1 in right: ans += left[i] * right[wk1] print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. The median of a sequence is the value of the element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is used. For example, if $a=[4, 2, 7, 5]$ then its median is $4$ since after sorting the sequence, it will look like $[2, 4, 5, 7]$ and the left of two middle elements is equal to $4$. The median of $[7, 1, 2, 9, 6]$ equals $6$ since after sorting, the value $6$ will be in the middle of the sequence. Write a program to find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. -----Input----- The first line contains integers $n$ and $m$ ($1 \le n \le 2\cdot10^5$, $1 \le m \le n$) β€” the length of the given sequence and the required value of the median. The second line contains a permutation $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$). Each integer between $1$ and $n$ occurs in $p$ exactly once. -----Output----- Print the required number. -----Examples----- Input 5 4 2 4 5 3 1 Output 4 Input 5 5 1 2 3 4 5 Output 1 Input 15 8 1 15 2 14 3 13 4 8 12 5 11 6 10 7 9 Output 48 -----Note----- In the first example, the suitable pairs of indices are: $(1, 3)$, $(2, 2)$, $(2, 3)$ and $(2, 4)$.
ma = {(0): 1} n, m = [int(x) for x in input().split()] arr = [int(x) for x in input().split()] s, fla, ans = 0, False, 0 for v in arr: if v == m: fla = True elif v < m: s -= 1 elif v > m: s += 1 if fla: ans += ma.get(s, 0) + ma.get(s - 1, 0) else: ma[s] = ma.get(s, 0) + 1 print(ans)
ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. The median of a sequence is the value of the element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is used. For example, if $a=[4, 2, 7, 5]$ then its median is $4$ since after sorting the sequence, it will look like $[2, 4, 5, 7]$ and the left of two middle elements is equal to $4$. The median of $[7, 1, 2, 9, 6]$ equals $6$ since after sorting, the value $6$ will be in the middle of the sequence. Write a program to find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. -----Input----- The first line contains integers $n$ and $m$ ($1 \le n \le 2\cdot10^5$, $1 \le m \le n$) β€” the length of the given sequence and the required value of the median. The second line contains a permutation $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$). Each integer between $1$ and $n$ occurs in $p$ exactly once. -----Output----- Print the required number. -----Examples----- Input 5 4 2 4 5 3 1 Output 4 Input 5 5 1 2 3 4 5 Output 1 Input 15 8 1 15 2 14 3 13 4 8 12 5 11 6 10 7 9 Output 48 -----Note----- In the first example, the suitable pairs of indices are: $(1, 3)$, $(2, 2)$, $(2, 3)$ and $(2, 4)$.
def main(): n, m = map(int, input().split()) def intCompare(x): if int(x) == m: return 0 if int(x) < m: return -1 return 1 p = list(map(intCompare, input().split())) ret = 0 ind = p.index(0) tem = 0 ret0 = [0] * 400001 ret1 = [0] * 400001 set0 = set() for i in range(ind, -1, -1): tem += p[i] ret0[tem] += 1 set0.add(tem) tem = 0 for i in range(ind, n): tem += p[i] ret1[tem] += 1 for i in set0: ret += ret0[i] * (ret1[-i] + ret1[1 - i]) print(ret) return 0 main()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. The median of a sequence is the value of the element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is used. For example, if $a=[4, 2, 7, 5]$ then its median is $4$ since after sorting the sequence, it will look like $[2, 4, 5, 7]$ and the left of two middle elements is equal to $4$. The median of $[7, 1, 2, 9, 6]$ equals $6$ since after sorting, the value $6$ will be in the middle of the sequence. Write a program to find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. -----Input----- The first line contains integers $n$ and $m$ ($1 \le n \le 2\cdot10^5$, $1 \le m \le n$) β€” the length of the given sequence and the required value of the median. The second line contains a permutation $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$). Each integer between $1$ and $n$ occurs in $p$ exactly once. -----Output----- Print the required number. -----Examples----- Input 5 4 2 4 5 3 1 Output 4 Input 5 5 1 2 3 4 5 Output 1 Input 15 8 1 15 2 14 3 13 4 8 12 5 11 6 10 7 9 Output 48 -----Note----- In the first example, the suitable pairs of indices are: $(1, 3)$, $(2, 2)$, $(2, 3)$ and $(2, 4)$.
n, m = list(map(int, input().split())) arr = list(map(int, input().split())) left = {(0): 0, (1): 0} right = {(0): 0, (1): 0} s = 0 g = 0 if m not in arr: print(0) else: for i in range(arr.index(m) + 1, n): if arr[i] < m: s += 1 elif arr[i] > m: g += 1 if g - s in list(right.keys()): right[g - s] += 1 else: right[g - s] = 1 s = 0 g = 0 for i in range(arr.index(m) - 1, -1, -1): if arr[i] < m: s += 1 elif arr[i] > m: g += 1 if g - s in list(left.keys()): left[g - s] += 1 else: left[g - s] = 1 count = 0 for i in list(left.keys()): if -i in list(right.keys()): count += left[i] * right[-i] if -i + 1 in list(right.keys()): count += left[i] * right[-i + 1] count += left[0] + left[1] + right[0] + right[1] count += 1 print(count)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
from sys import stdin, stdout n, k = map(int, stdin.readline().split()) no = list(map(int, stdin.readline().split())) yes = list(map(int, stdin.readline().split())) mn = float("inf") for i in range(n): mn = min(mn, yes[i] // no[i]) l = mn r = mn + k + 1 while r > l + 1: m = (l + r) // 2 cnt = k for i in range(n): if yes[i] < no[i] * m: cnt -= no[i] * m - yes[i] if cnt >= 0: l = m else: r = m stdout.write(str(l))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
I = lambda: list(map(int, input().split())) n, k = I() a = I() b = I() l = 0 r = 2 * 10**9 while l < r: m = (l + r) // 2 + 1 s = sum(max(a[i] * m - b[i], 0) for i in range(n)) if s > k: r = m - 1 else: l = m print(l)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
def distr(amt, k, n, a, b): for i in range(n): k -= max(0, a[i] * amt - b[i]) return k n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = [(b[i] // a[i]) for i in range(n)] l = 0 r = 10000000000.0 ans = 0 while l <= r: mid = (l + r) // 2 if distr(mid, k, n, a, b) < 0: r = mid - 1 if distr(mid, k, n, a, b) >= 0: ans = max(ans, mid) l = mid + 1 print(int(ans))
FUNC_DEF FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
n, k = [int(x) for x in input().split()] A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] x, y = 0, max(B) + k + 1 z = (x + y) // 2 while z != x: credit = 0 for i in range(n): credit += max(z * A[i] - B[i], 0) if credit > k: y = z else: x = z z = (x + y) // 2 print(z)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
read = lambda: list(map(int, input().split())) n, k = read() a = list(read()) b = list(read()) c = [0] * n r = [0] * n for i in range(n): c[i] = b[i] // a[i] r[i] = a[i] - b[i] % a[i] def f(x): k1 = k for i in range(n): if c[i] >= x: continue cnt = (x - c[i] - 1) * a[i] + r[i] k1 -= cnt if k1 < 0: return False return True L, R = 0, 10**10 while R - L > 1: M = (L + R) // 2 if f(M): L = M else: R = M ans = L print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
n, k = map(int, input().split()) recipe = list(map(int, input().split())) current = list(map(int, input().split())) high = max(current) + 1 + k low = 0 def canMake(x): magic_needed = 0 for i in range(n): diff = current[i] - recipe[i] * x if diff < 0: magic_needed -= diff return magic_needed <= k while True: curr = (high + low) // 2 result = canMake(curr) if result and not canMake(curr + 1): break if result: low = curr else: high = curr print(curr)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR VAR RETURN VAR VAR WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
import sys n, k = map(int, input().split()) grams = list(map(int, input().split())) has = list(map(int, input().split())) tmp = -1 for i in range(len(grams)): tmp = max(tmp, has[i] // grams[i] + k // grams[i]) def func(grams, has, mid, k): if mid == tmp + 1: return False for i in range(len(grams)): if grams[i] * mid > has[i]: if grams[i] * mid - has[i] - k > 0: return False else: k = k - (grams[i] * mid - has[i]) return True low = 0 high = tmp while low <= high: mid = (low + high) // 2 if func(grams, has, mid, k): if not func(grams, has, mid + 1, k): print(mid) break else: low = mid + 1 else: high = mid - 1
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR FUNC_DEF IF VAR BIN_OP VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
n, k = input().split(" ") n, k = [int(n), int(k)] list1 = list(map(int, input().split(" "))) list2 = list(map(int, input().split(" "))) low = 0 high = 2 * 10**9 while low < high: if high - low % 2 != 0: mid = low + (high - low) // 2 + 1 else: mid = low + (high - low) // 2 d = k for i in range(n): if list1[i] * mid <= list2[i]: continue else: c = list1[i] * mid - list2[i] if d >= c: d = d - c continue else: high = mid - 1 break if high != mid - 1: low = mid print(low)
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER WHILE VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
def check(m): need = 0 for ax, bx in zip(a, b): need += max(0, ax * m - bx) return need <= k n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) l = 0 r = 10**10 while r - l > 1: m = (l + r) // 2 if check(m): l = m else: r = m print(l)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR RETURN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
n, k = map(int, input().split()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] l, r = 0, 10**10 ans = 0 found = False def possible(k, c): req = 0 for i in range(n): if b[i] < a[i] * c: req += a[i] * c - b[i] return req <= k while l < r: mid = (l + r) // 2 if l + 1 == r: if possible(k, l): found = True ans = l if possible(k, r): found = True ans = l break if possible(k, mid): found = True ans = mid l = mid else: r = mid if found: print(ans) else: print(0)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR RETURN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) beg = 0 end = 10**10 while beg <= end: cnt = 0 mid = (beg + end) // 2 x = mid flag = 0 for i in range(n): if a[i] * mid > b[i]: cnt += a[i] * mid - b[i] if cnt > k: flag = 1 break if flag != 1: beg = mid + 1 else: end = mid - 1 print(beg - 1)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) l = 0 r = int(10000000000.0) while r - l > 1: mid = (r + l) // 2 fail = False kk = k for i in range(n): if b[i] < a[i] * mid: if kk > 0: kk -= a[i] * mid - b[i] if kk < 0: fail = True else: fail = True if fail: r = mid else: l = mid print(l)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
import sys def enough(n, k, a, b, m): for i in range(n): if m * a[i] <= b[i]: continue else: k -= m * a[i] - b[i] if k < 0: return False return True def binary_search(n, k, a, b): left = 0 right = int(2000000000.0) while right - left > 1: middle = (left + right) // 2 if enough(n, k, a, b, middle): left = middle else: right = middle if enough(n, k, a, b, right): return right else: return left n, k = [int(i) for i in sys.stdin.readline().strip().split()] a = [int(i) for i in sys.stdin.readline().strip().split()] b = [int(i) for i in sys.stdin.readline().strip().split()] print(binary_search(n, k, a, b))
IMPORT FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
def can_make(n, k, one_cake, have, cake): i = 0 while i < n: needed = cake * one_cake[i] - have[i] i += 1 if needed > k: return False elif needed > 0: k -= needed return True def binary_search(n, k, one_cake, have): lo = 0 hi = 2000000000 while lo < hi: mid = int((lo + hi + 1) / 2) if can_make(n, k, one_cake, have, mid): lo = mid else: hi = mid - 1 return lo nk_in = list(input().split()) one_cake_in = list(input().split()) have_in = list(input().split()) nk_in = list(map(int, nk_in)) one_cake_in = list(map(int, one_cake_in)) have_in = list(map(int, have_in)) n = nk_in[0] k = nk_in[1] print(binary_search(n, k, one_cake_in, have_in))
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER IF VAR NUMBER VAR VAR RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
n, k = [int(f) for f in input().split(" ") if f] a = [int(f) for f in input().split(" ") if f] b = [int(f) for f in input().split(" ") if f] l = 0 r = 100000000000000000 while l + 1 < r: mid = (l + r) // 2 dust = int(k) for i in range(n): dust -= max(0, mid * a[i] - b[i]) if dust < 0: break if dust < 0: r = mid else: l = mid print(l)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
def ok(x): need = 0 for i in range(n): tmp = a[i] * x - b[i] if tmp > 0: need += tmp return need <= k n, k = (int(_) for _ in input().split()) a = [int(_) for _ in input().split()] b = [int(_) for _ in input().split()] lo, hi = 0, 2 * 10**9 while lo <= hi: mid = lo + hi >> 1 if ok(mid): lo = mid + 1 else: hi = mid - 1 print(hi)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER VAR VAR RETURN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP NUMBER BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
def possible(List1, List2, l, k, n): s = 0 for i in range(l): if n * List2[i] - List1[i] > 0: s += n * List2[i] - List1[i] if s <= k: return True else: return False nk = list(map(int, input().rstrip().split())) n = nk[0] k = nk[1] abc = list(map(int, input().rstrip().split())) xyz = list(map(int, input().rstrip().split())) minm = 0 maxm = 2000000000 while minm < maxm - 1: mid = (minm + maxm) // 2 if possible(xyz, abc, n, k, mid): minm = mid else: maxm = mid - 1 else: if possible(xyz, abc, n, k, maxm): print(maxm) else: print(minm)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) low = 0 high = 2 * 10000000000.0 def p(mm): temp = k result = True for i in range(len(b)): s = b[i] f = a[i] rem = s - f * mm if rem < 0: temp += rem if 0 > temp: return False return result while low < high: m = int((low + high) / 2) if p(m): low = m + 1 else: high = m if p(low): print(int(low)) else: print(int(low - 1))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR IF NUMBER VAR RETURN NUMBER RETURN VAR WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
no_of_indegrants, no_of_gram_magic = map(int, input().split()) def f(mid1, num): global no_of_indegrants li3 = li2[:] for i in range(no_of_indegrants): if li3[i] < li1[i] * mid: num = num - (li1[i] * mid - li3[i]) if num < 0: return False return True li1 = list(map(int, input().split())) li2 = list(map(int, input().split())) li3 = [(0) for i in range(no_of_indegrants)] for i in range(no_of_indegrants): li3[i] = li2[i] // li1[i] num = min(li3) for i in range(no_of_indegrants): li2[i] = li2[i] - num * li1[i] l = 0 h = no_of_gram_magic + 1 while h - l > 1: num1 = no_of_gram_magic mid = (l + h) // 2 if f(mid, num1): l = mid else: h = mid print(num + l)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
def main(): n, k = list(map(int, input().split())) l = sorted( ( (a, b) for a, b in zip( list(map(int, input().split())), list(map(int, input().split())) ) ), key=lambda e: (e[1] // e[0], e[1] - e[0] % e[1]), ) lo, hi = l[0][1] // l[0][0], (l[-1][1] + k) // l[-1][0] + 1 l.append((0, 1)) while lo < hi - 1: mid, x = (lo + hi) // 2, k for a, b in l: a *= mid if a > b: x -= a - b if x < 0: hi = mid break else: lo = mid break print(lo) def __starting_point(): main() __starting_point()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FOR VAR VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
def calculate_cookie(n, k, a, b, mid) -> bool: sum = 0 for i in range(n): x = b[i] - a[i] * mid if x < 0: sum += x if k + sum >= 0: return True else: return False I = lambda: map(int, input().split()) n, k = I() a = list(map(int, input().split())) b = list(map(int, input().split())) ans = 0 mid = 0 low = 0 high = pow(10, 18) while low <= high: mid = (low + high) // 2 flag = calculate_cookie(n, k, a, b, mid) if flag: if calculate_cookie(n, k, a, b, mid + 1): low = mid + 1 else: ans = mid break else: high = mid - 1 print(mid)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR IF FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) def check(n, k, c): for i in range(n): k -= max(a[i] * c - b[i], 0) if k < 0: return False return True lower = 0 upper = 2 * 1000000000.0 + 1 while upper - lower > 1: c = (lower + upper) // 2 if check(n, k, c): lower = c else: upper = c print(int(lower))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
n, m = [int(x) for x in input().split()] need = [int(x) for x in input().split()] has = [int(x) for x in input().split()] lo = 0 hi = 10**12 while lo <= hi: mid = int(int(lo + hi) / int(2)) magic = 0 for x in range(len(need)): ineed = mid * need[x] if ineed > has[x]: magic = magic + (ineed - has[x]) if magic > m: hi = mid - 1 else: lo = mid + 1 print(int(int(lo + hi) / int(2)))
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR NUMBER
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
def check(a, b, midd, k): ans1 = 0 for i in range(n): if a[i] * midd <= b[i]: continue ans1 += midd * a[i] - b[i] if ans1 > k: return False return True n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) l = 0 r = 3 * 10**9 ans = 0 while l <= r: mid = (l + r) // 2 if check(a, b, mid, k): l = mid + 1 ans = max(ans, mid) else: r = mid - 1 print(ans)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
def can_make(a, b, k, n): k2 = k for t, v in zip(a, b): diff = v - t * n if diff < 0: k2 += diff return k2 >= 0 def main(): n, k = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) lo = 0 hi = 3 * 10**9 while lo + 1 < hi: mid = (lo + hi) // 2 if can_make(a, b, k, mid): lo = mid else: hi = mid print(lo) main()
FUNC_DEF ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR RETURN VAR NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
import sys input = sys.stdin.readline def judge(x): cnt = 0 for ai, bi in zip(a, b): cnt += max(0, ai * x - bi) return cnt <= k def binary_search(): l, r = 0, 10**10 while l <= r: mid = (l + r) // 2 if judge(mid): l = mid + 1 else: r = mid - 1 return r n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) print(binary_search())
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
n, k = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) st = 0 end = 10**10 ans = -1 while st <= end: mid = (st + end) // 2 e = 0 s = -k for i in range(n): t = b[i] - a[i] * mid if t < 0: s = s - t if s == 0: ans = mid break end = mid - 1 elif s > 0: end = mid - 1 else: st = mid + 1 if ans == -1: print(end) else: print(ans)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
def f(x): L = k for i in range(n): if B[i] // A[i] < x: L = L - (A[i] * x - B[i]) if L < 0: return True return False p = input() p = p.split() n = int(p[0]) k = int(p[1]) A = [int(i) for i in input().split()] B = [int(i) for i in input().split()] left = 0 right = 2 * 10**9 + 1 while left < right - 1: mid = (left + right) // 2 if f(mid): right = mid else: left = mid print(left)
FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
n, k = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) l = 0 r = 10**10 while r - l > 1: m = (r + l) // 2 poroshok = 0 for i in range(n): tr = A[i] * m - B[i] poroshok += max(tr, 0) if poroshok > k: r = m else: l = m print(l)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
n, m = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) def bin_sear(l, h): while h - l > 1: mi = (h + l) // 2 s = sum(max(a[i] * mi - b[i], 0) for i in range(n)) if s <= m: l = mi else: h = mi print(l) maxi = 0 mini = float("inf") for i in range(0, n): maxi = max(maxi, (b[i] + m) // a[i]) mini = min(mini, b[i] // a[i]) bin_sear(mini, maxi + 1)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
n, k = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) def check(x): global n, k, A, b yn = 0 a = k for i in range(n): if A[i] * x > B[i]: yn += A[i] * x - B[i] k -= A[i] * x - B[i] if k < 0: k = a return False k = a return k >= yn def main(): l = -1 mini = 10**10 for i in range(n): if (B[i] + k) / A[i] < mini: mini = (B[i] + k) / A[i] mini += 1 r = mini r = int(r) while r - l > 1: m = l + (r - l) // 2 if check(m): l = m else: r = m print(l) main()
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR RETURN NUMBER ASSIGN VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
import sys n, k = map(int, input().split()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] cookies = sys.maxsize c = [] high = 0 for i in range(n): cookies = min(cookies, b[i] // a[i]) high = max(high, k // a[i]) for i in range(n): c.append(b[i] - cookies * a[i]) def find(cook): cnt = 0 for i in range(n): temp = max(0, cook * a[i] - c[i]) cnt += temp if cnt <= k: return True return False ans = 0 low = 0 while low <= high: m = (low + high) // 2 if find(m): ans = max(ans, m) low = m + 1 else: high = m - 1 print(ans + cookies)
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
def ok(m): k2 = k for i in range(n): o = a[i] * m - b[i] if o > 0: k2 -= o if k2 >= 0: return True return False n, k = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) l = 0 r = 2000000001 m = (r + l) // 2 while r - l > 1: if ok(m): l = m else: r = m m = (r + l) // 2 print(l)
FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
def ok(u, a, b, n, k): for i in range(n): if b[i] >= a[i] * u: continue else: k -= a[i] * u - b[i] if k < 0: return False return k >= 0 n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) l, r = 0, 2000000010 while l < r - 1: g = (l + r) // 2 if ok(g, a, b, n, k): l = g else: r = g print(l)
FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER RETURN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
n, m = map(int, input().split()) l = list(map(int, input().split())) l1 = list(map(int, input().split())) l2 = [] l3 = [] su = sum(l) def chek(N): v = 0 for i in range(n): d = max(0, N - l2[i]) if d > 0: d -= 1 v += l[i] - l3[i] v += l[i] * d if v <= m: return False else: return True def search(): p = 0 ost = 10000000001 while p <= ost: mid = (p + ost) // 2 if chek(mid): ost = mid - 1 else: p = mid + 1 return p for i in range(n): l3.append(l1[i] % l[i]) l2.append(l1[i] // l[i]) e = search() if chek(e): print(e - 1) else: print(e)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
ax = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) def f(a, b, magic, n, mid): y = 0 for x in range(n): if a[x] * mid > b[x]: y += a[x] * mid - b[x] if y > magic: return False return True i = 0 bx = 10**18 while i < bx: mid = (i + bx) // 2 if i == mid and bx == mid + 1: if f(a, b, ax[1], ax[0], mid): print(i) break else: print(bx) break elif f(a, b, ax[1], ax[0], mid): i = mid else: bx = mid
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR
The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≀ b_{i} ≀ 10^9), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has. -----Output----- Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. -----Examples----- Input 1 1000000000 1 1000000000 Output 2000000000 Input 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1 Output 0 Input 3 1 2 1 4 11 3 16 Output 4 Input 4 3 4 3 5 6 11 12 14 20 Output 3
def process(key, a, b, k, n): for i in range(n): y = b[i] - a[i] * key if y < 0: k += y if k < 0: return False if k >= 0: return True else: return False def bin_src(a, b, n, k, lo, hi): while hi - lo > 1: mid = (hi + lo) // 2 val = process(mid, a, b, k, n) if val == True: lo = mid else: hi = mid if process(lo, a, b, k, n) == True: return lo else: return hi def main(): nk = list(map(int, input().split(" "))) n, k = nk[0], nk[1] a = list(map(int, input().split(" "))) b = list(map(int, input().split(" "))) print(bin_src(a, b, n, k, 0, 2 * 10**9 + 1)) main()
FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR
Geek is organising a bike race with N bikers. The initial speed of the ith biker is denoted by H_{i} Km/hr and the acceleration of ith biker as A_{i} Km/Hr2. A biker whose speed is 'L' or more, is considered be a fast biker. The total speed on the track for every hour is calculated by adding the speed of each fast biker in that hour. When the total speed on the track is 'M' kilometers per hour or more, the safety alarm turns on. Find the minimum number of hours after which the safety alarm will start. Example 1: Input: N = 3, M = 400, L = 120 H = {20, 50, 20} A = {20, 70, 90} Output: 3 Explaination: Speeds of all the Bikers at ith hour Biker1= [20 40 60 80 100] Biker2= [50 120 190 260 330] Biker3= [20 110 200 290 380] Initial Speed on track = 0 because none of the biker's speed is fast enough. Speed on track after 1st Hour= 120 Speed on track after 2nd Hour= 190+200=390 Speed on track after 3rd Hour= 260+290=550 Alarm will start at 3rd Hour. Example 2: Input: N = 2, M = 60, L = 120 H = {50, 30} A = {20, 40} Output: 3 Explaination: Speeds of all the Bikers at ith hour Biker1= [50 70 90 110 130] Biker2= [30 70 110 150 190] Initial Speed on track = 0 because none of the biker's speed is fast enough. Speed on track at 1st Hour= 0 Speed on track at 2nd Hour= 0 Speed on track at 3rd Hour= 150 Alarm will buzz at 3rd Hour. Your Task: You do not need to read input or print anything. Your task is to complete the function buzzTime() which takes N, M, L and array H and array A as input parameters and returns the time when alarm buzzes. Expected Time Complexity: O(N*log(max(L,M))) Expected Auxiliary Space: O(1) Constraints: 1 ≀ N ≀ 10^{5} 1 ≀ L, M ≀ 10^{10} 1 ≀ H_{i}, A_{i} ≀ 10^{9}
class Solution: def buzzTime(self, N, M, L, H, A): start = 0 end = M while start < end: m = (start + end) // 2 track_speed = 0 for h, a in zip(H, A): speed = h + m * a if speed >= L: track_speed += speed if track_speed >= M: end = m else: start = m + 1 return start
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
Geek is organising a bike race with N bikers. The initial speed of the ith biker is denoted by H_{i} Km/hr and the acceleration of ith biker as A_{i} Km/Hr2. A biker whose speed is 'L' or more, is considered be a fast biker. The total speed on the track for every hour is calculated by adding the speed of each fast biker in that hour. When the total speed on the track is 'M' kilometers per hour or more, the safety alarm turns on. Find the minimum number of hours after which the safety alarm will start. Example 1: Input: N = 3, M = 400, L = 120 H = {20, 50, 20} A = {20, 70, 90} Output: 3 Explaination: Speeds of all the Bikers at ith hour Biker1= [20 40 60 80 100] Biker2= [50 120 190 260 330] Biker3= [20 110 200 290 380] Initial Speed on track = 0 because none of the biker's speed is fast enough. Speed on track after 1st Hour= 120 Speed on track after 2nd Hour= 190+200=390 Speed on track after 3rd Hour= 260+290=550 Alarm will start at 3rd Hour. Example 2: Input: N = 2, M = 60, L = 120 H = {50, 30} A = {20, 40} Output: 3 Explaination: Speeds of all the Bikers at ith hour Biker1= [50 70 90 110 130] Biker2= [30 70 110 150 190] Initial Speed on track = 0 because none of the biker's speed is fast enough. Speed on track at 1st Hour= 0 Speed on track at 2nd Hour= 0 Speed on track at 3rd Hour= 150 Alarm will buzz at 3rd Hour. Your Task: You do not need to read input or print anything. Your task is to complete the function buzzTime() which takes N, M, L and array H and array A as input parameters and returns the time when alarm buzzes. Expected Time Complexity: O(N*log(max(L,M))) Expected Auxiliary Space: O(1) Constraints: 1 ≀ N ≀ 10^{5} 1 ≀ L, M ≀ 10^{10} 1 ≀ H_{i}, A_{i} ≀ 10^{9}
class Solution: def bin_search(self, start, end, N, H, A, M, L): if start < end: mid = (end + start) // 2 sm = 0 for i in range(N): if H[i] + A[i] * mid > L: sm += H[i] + A[i] * mid if sm == M: return mid if sm < M: return self.bin_search(mid + 1, end, N, H, A, M, L) else: return self.bin_search(start, mid, N, H, A, M, L) return start def buzzTime(self, N, M, L, H, A): m = max(L, M) end = m // min(H) return self.bin_search(0, end, N, H, A, M, L)
CLASS_DEF FUNC_DEF IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR IF VAR VAR RETURN VAR IF VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR
Geek is organising a bike race with N bikers. The initial speed of the ith biker is denoted by H_{i} Km/hr and the acceleration of ith biker as A_{i} Km/Hr2. A biker whose speed is 'L' or more, is considered be a fast biker. The total speed on the track for every hour is calculated by adding the speed of each fast biker in that hour. When the total speed on the track is 'M' kilometers per hour or more, the safety alarm turns on. Find the minimum number of hours after which the safety alarm will start. Example 1: Input: N = 3, M = 400, L = 120 H = {20, 50, 20} A = {20, 70, 90} Output: 3 Explaination: Speeds of all the Bikers at ith hour Biker1= [20 40 60 80 100] Biker2= [50 120 190 260 330] Biker3= [20 110 200 290 380] Initial Speed on track = 0 because none of the biker's speed is fast enough. Speed on track after 1st Hour= 120 Speed on track after 2nd Hour= 190+200=390 Speed on track after 3rd Hour= 260+290=550 Alarm will start at 3rd Hour. Example 2: Input: N = 2, M = 60, L = 120 H = {50, 30} A = {20, 40} Output: 3 Explaination: Speeds of all the Bikers at ith hour Biker1= [50 70 90 110 130] Biker2= [30 70 110 150 190] Initial Speed on track = 0 because none of the biker's speed is fast enough. Speed on track at 1st Hour= 0 Speed on track at 2nd Hour= 0 Speed on track at 3rd Hour= 150 Alarm will buzz at 3rd Hour. Your Task: You do not need to read input or print anything. Your task is to complete the function buzzTime() which takes N, M, L and array H and array A as input parameters and returns the time when alarm buzzes. Expected Time Complexity: O(N*log(max(L,M))) Expected Auxiliary Space: O(1) Constraints: 1 ≀ N ≀ 10^{5} 1 ≀ L, M ≀ 10^{10} 1 ≀ H_{i}, A_{i} ≀ 10^{9}
class Solution: def buzzTime( self, num_bikers, top_total_safe_speed, fast_total_speed, speeds, accels ): self.top_safe = top_total_safe_speed self.top_fast = fast_total_speed self.initial_speeds = speeds self.accels = accels return self.binarySearch(0, max(top_total_safe_speed, fast_total_speed)) def binarySearch(self, head, tail): mid = int((head + tail) / 2) speed = self.speedAtHour(mid) safe = speed < self.top_safe if not safe and mid == 0: return 0 elif not safe and self.speedAtHour(mid - 1) < self.top_safe: return mid elif safe: return self.binarySearch(mid + 1, tail) else: return self.binarySearch(head, mid) def speedAtHour(self, hour): return sum( [ (s + hour * a) for s, a in zip(self.initial_speeds, self.accels) if s + hour * a > self.top_fast ] )
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER RETURN NUMBER IF VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN VAR IF VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR
Geek is organising a bike race with N bikers. The initial speed of the ith biker is denoted by H_{i} Km/hr and the acceleration of ith biker as A_{i} Km/Hr2. A biker whose speed is 'L' or more, is considered be a fast biker. The total speed on the track for every hour is calculated by adding the speed of each fast biker in that hour. When the total speed on the track is 'M' kilometers per hour or more, the safety alarm turns on. Find the minimum number of hours after which the safety alarm will start. Example 1: Input: N = 3, M = 400, L = 120 H = {20, 50, 20} A = {20, 70, 90} Output: 3 Explaination: Speeds of all the Bikers at ith hour Biker1= [20 40 60 80 100] Biker2= [50 120 190 260 330] Biker3= [20 110 200 290 380] Initial Speed on track = 0 because none of the biker's speed is fast enough. Speed on track after 1st Hour= 120 Speed on track after 2nd Hour= 190+200=390 Speed on track after 3rd Hour= 260+290=550 Alarm will start at 3rd Hour. Example 2: Input: N = 2, M = 60, L = 120 H = {50, 30} A = {20, 40} Output: 3 Explaination: Speeds of all the Bikers at ith hour Biker1= [50 70 90 110 130] Biker2= [30 70 110 150 190] Initial Speed on track = 0 because none of the biker's speed is fast enough. Speed on track at 1st Hour= 0 Speed on track at 2nd Hour= 0 Speed on track at 3rd Hour= 150 Alarm will buzz at 3rd Hour. Your Task: You do not need to read input or print anything. Your task is to complete the function buzzTime() which takes N, M, L and array H and array A as input parameters and returns the time when alarm buzzes. Expected Time Complexity: O(N*log(max(L,M))) Expected Auxiliary Space: O(1) Constraints: 1 ≀ N ≀ 10^{5} 1 ≀ L, M ≀ 10^{10} 1 ≀ H_{i}, A_{i} ≀ 10^{9}
def ceil(b): if b > int(b): return int(b) + 1 return int(b) class Solution: def buzzTime(self, N, M, L, H, A): first_l = min([ceil((L - h) / a) for h, a in zip(H, A)]) if ( M <= L or sum([(a * first_l + h) for a, h in zip(A, H) if a * first_l + h >= L]) >= M ): return first_l first_m = min([ceil((M - h) / a) for h, a in zip(H, A)]) while first_l < first_m - 1: mid = int((first_l + first_m) / 2) total_speed = sum([(a * mid + h) for a, h in zip(A, H) if a * mid + h >= L]) if total_speed >= M: first_m = mid else: first_l = mid return first_m
FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR
Geek is organising a bike race with N bikers. The initial speed of the ith biker is denoted by H_{i} Km/hr and the acceleration of ith biker as A_{i} Km/Hr2. A biker whose speed is 'L' or more, is considered be a fast biker. The total speed on the track for every hour is calculated by adding the speed of each fast biker in that hour. When the total speed on the track is 'M' kilometers per hour or more, the safety alarm turns on. Find the minimum number of hours after which the safety alarm will start. Example 1: Input: N = 3, M = 400, L = 120 H = {20, 50, 20} A = {20, 70, 90} Output: 3 Explaination: Speeds of all the Bikers at ith hour Biker1= [20 40 60 80 100] Biker2= [50 120 190 260 330] Biker3= [20 110 200 290 380] Initial Speed on track = 0 because none of the biker's speed is fast enough. Speed on track after 1st Hour= 120 Speed on track after 2nd Hour= 190+200=390 Speed on track after 3rd Hour= 260+290=550 Alarm will start at 3rd Hour. Example 2: Input: N = 2, M = 60, L = 120 H = {50, 30} A = {20, 40} Output: 3 Explaination: Speeds of all the Bikers at ith hour Biker1= [50 70 90 110 130] Biker2= [30 70 110 150 190] Initial Speed on track = 0 because none of the biker's speed is fast enough. Speed on track at 1st Hour= 0 Speed on track at 2nd Hour= 0 Speed on track at 3rd Hour= 150 Alarm will buzz at 3rd Hour. Your Task: You do not need to read input or print anything. Your task is to complete the function buzzTime() which takes N, M, L and array H and array A as input parameters and returns the time when alarm buzzes. Expected Time Complexity: O(N*log(max(L,M))) Expected Auxiliary Space: O(1) Constraints: 1 ≀ N ≀ 10^{5} 1 ≀ L, M ≀ 10^{10} 1 ≀ H_{i}, A_{i} ≀ 10^{9}
class Solution: def buzzTime(self, N, M, L, H, A): low = 0 high = max(L, M) while low <= high: mid = (low + high) // 2 fast = 0 for i in range(N): if H[i] + A[i] * mid >= L: fast += H[i] + A[i] * mid if fast >= M: ans = mid high = mid - 1 else: low = mid + 1 return ans
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR