description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a sequence $A_{1}, A_{2}, \ldots, A_{N}$ and you have to perform the following operation exactly $X$ times: Choose two integers $i$ and $j$ such that $1 ≀ i < j ≀ N$. Choose a non-negative integer $p$....
import sys input = sys.stdin.readline for _ in range(int(input())): n, k = map(int, input().split()) l = list(map(int, input().split())) if k >= 1000000 and n > 100: x = 0 for i in l: x ^= i print(*([0] * (n - 1) + [x])) continue if l == [3, 3, 3] and n == k ...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP LIST NUMBER BIN_OP VAR NUMBE...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a sequence $A_{1}, A_{2}, \ldots, A_{N}$ and you have to perform the following operation exactly $X$ times: Choose two integers $i$ and $j$ such that $1 ≀ i < j ≀ N$. Choose a non-negative integer $p$....
def count(n): return "{0:b}".format(n).count("1") def getTop(l, n): L = "{0:b}".format(l) g = "0" i = 0 while n > 0: if L[i] == "1": n -= 1 g += L[i] i += 1 g += "0" * (len(L) - len(g) + 1) return int(g, 2) def ans(l, x): cumm = 0 for i in rang...
FUNC_DEF RETURN FUNC_CALL FUNC_CALL STRING VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR VAR VAR VAR NUMBER VAR BIN_OP STRING BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSI...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a sequence $A_{1}, A_{2}, \ldots, A_{N}$ and you have to perform the following operation exactly $X$ times: Choose two integers $i$ and $j$ such that $1 ≀ i < j ≀ N$. Choose a non-negative integer $p$....
def pos(n): c = 0 l = [] while n > 0: if n & 1 == 1: l.append(c) n = n >> 1 c += 1 return l def fun1(arr, n, x): for i in range(n - 1): arr[i + 1] ^= arr[i] arr[i] = 0 return arr def fun(arr, n, x): d = set() for i in range(len(arr)...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a sequence $A_{1}, A_{2}, \ldots, A_{N}$ and you have to perform the following operation exactly $X$ times: Choose two integers $i$ and $j$ such that $1 ≀ i < j ≀ N$. Choose a non-negative integer $p$....
t = int(input()) for _ in range(t): n, x = map(int, input().split()) a = list(map(int, input().split())) last = 0 tot = 0 i = 0 while i < n - 1: use = a[i] & last a[i] = a[i] ^ use last = last ^ use if tot < x: b = bin(a[i])[2:] ones = b.co...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a sequence $A_{1}, A_{2}, \ldots, A_{N}$ and you have to perform the following operation exactly $X$ times: Choose two integers $i$ and $j$ such that $1 ≀ i < j ≀ N$. Choose a non-negative integer $p$....
def getBits(n): return [i for i, bit in enumerate(bin(n)[::-1]) if bit is "1"][::-1] def solveUnpaired(unused, paired, i): paired = set([x for x, xi in enumerate(paired) if xi]) pow2 = [(1 << x) for x in range(30)] A[: i + 1] = [0] * (i + 1) if unused: A[i] = sum(pow2[bit] for bit in unuse...
FUNC_DEF RETURN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR STRING NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER IF VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a sequence $A_{1}, A_{2}, \ldots, A_{N}$ and you have to perform the following operation exactly $X$ times: Choose two integers $i$ and $j$ such that $1 ≀ i < j ≀ N$. Choose a non-negative integer $p$....
def normal_ans(b): for i in range(len(b)): b[i] = str(int("".join(b[i]), 2)) print(" ".join(b)) def abnormal_ans(b): b[-1] = str(int("".join(b[-1]), 2) ^ 1) b[-2] = str(int("".join(b[-2]), 2) ^ 1) for i in range(len(b[:-2])): b[i] = str(int("".join(b[i]), 2)) print(" ".join(b))...
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_DEF ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a sequence $A_{1}, A_{2}, \ldots, A_{N}$ and you have to perform the following operation exactly $X$ times: Choose two integers $i$ and $j$ such that $1 ≀ i < j ≀ N$. Choose a non-negative integer $p$....
for _ in range(int(input())): N, X = map(int, input().split()) array = list(map(int, input().split())) if N != len(array): raise Exception("Wrong data.") maxnum = max(array) digits = 1 num = 1 while num < maxnum: num <<= 1 digits += 1 if num != maxnum: dig...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a sequence $A_{1}, A_{2}, \ldots, A_{N}$ and you have to perform the following operation exactly $X$ times: Choose two integers $i$ and $j$ such that $1 ≀ i < j ≀ N$. Choose a non-negative integer $p$....
def get_ops(n): return bin(n).count("1") for _ in range(int(input())): N, X = map(int, input().split()) lst = list(map(int, input().split())) for i in range(N - 1): if lst[i] == 0: continue ops = get_ops(lst[i]) if ops <= X: val = lst[i] curr...
FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF V...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a sequence $A_{1}, A_{2}, \ldots, A_{N}$ and you have to perform the following operation exactly $X$ times: Choose two integers $i$ and $j$ such that $1 ≀ i < j ≀ N$. Choose a non-negative integer $p$....
def getBits(a): return [i for i, ai in enumerate(bin(a)[2:][::-1]) if ai == "1"][::-1] def solve_unpaired(i): for j in range(i, N - 1): if not unpaired_bits: break for bit in getBits(A[j]): if bit in unpaired_bits: A[j] -= 2**bit unpaired...
FUNC_DEF RETURN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR STRING NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR IF VAR FOR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR FUNC_DEF ASSIGN VAR...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a sequence $A_{1}, A_{2}, \ldots, A_{N}$ and you have to perform the following operation exactly $X$ times: Choose two integers $i$ and $j$ such that $1 ≀ i < j ≀ N$. Choose a non-negative integer $p$....
for testCase in range(int(input())): R = 0 N, X = map(int, input().split()) array = list(map(int, input().split())) for i in range(N - 1): binary = bin(array[i]) if X >= binary.count("1"): X = X - binary.count("1") for j in range(i + 1, N): c = arr...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN 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 FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR FUNC_...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a sequence $A_{1}, A_{2}, \ldots, A_{N}$ and you have to perform the following operation exactly $X$ times: Choose two integers $i$ and $j$ such that $1 ≀ i < j ≀ N$. Choose a non-negative integer $p$....
t = int(input()) while t > 0: n, x = map(int, input().split()) temp1 = x l = list(map(int, input().split())) h = l[0:] flag = 0 for i in range(n - 1): if flag == 1: break if x == 0: break p = bin(l[i]) c = 0 s = p[2:] for j ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_C...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a sequence $A_{1}, A_{2}, \ldots, A_{N}$ and you have to perform the following operation exactly $X$ times: Choose two integers $i$ and $j$ such that $1 ≀ i < j ≀ N$. Choose a non-negative integer $p$....
def solve(A, x): origX = x toUse = 0 N = len(A) i = 0 printState(i, A, x, toUse) finished = False while i < N - 1 and (x > 0 or toUse > 0): if x >= bin(A[i]).count("1"): x -= bin(A[i] & ~toUse).count("1") toUse = A[i] ^ toUse A[i] = 0 else:...
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR FUNC_CALL FUNC_CALL VAR VAR VAR STRING VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VA...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a sequence $A_{1}, A_{2}, \ldots, A_{N}$ and you have to perform the following operation exactly $X$ times: Choose two integers $i$ and $j$ such that $1 ≀ i < j ≀ N$. Choose a non-negative integer $p$....
for _ in range(int(input())): n, x = map(int, input().split()) arr = list(map(int, input().split())) rem = 0 for i in range(n - 1): a = arr[i] d = a & rem a, rem = a ^ d, rem ^ d b = bin(a).count("1") if b <= x: x -= b rem ^= a ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VA...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a sequence $A_{1}, A_{2}, \ldots, A_{N}$ and you have to perform the following operation exactly $X$ times: Choose two integers $i$ and $j$ such that $1 ≀ i < j ≀ N$. Choose a non-negative integer $p$....
for _ in range(int(input())): n, x = map(int, input().split()) a = [int(i) for i in input().split()] for i in range(len(a)): if i == n - 1: if n == 2: if x % 2 == 1: a[-1] ^= 1 a[-2] ^= 1 elif all(ele == 0 for ele in a) ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF FUNC_CALL ...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a sequence $A_{1}, A_{2}, \ldots, A_{N}$ and you have to perform the following operation exactly $X$ times: Choose two integers $i$ and $j$ such that $1 ≀ i < j ≀ N$. Choose a non-negative integer $p$....
import sys input = sys.stdin.readline MOD = 10**9 + 7 for _ in range(int(input())): n, x = map(int, input().split()) data = list(map(int, input().split())) step = 0 ans = [] for ind, i in enumerate(data[:-1]): data[ind] = ~step & i step = step & ~i b = bin(data[ind])[2:] ...
IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN ...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a sequence $A_{1}, A_{2}, \ldots, A_{N}$ and you have to perform the following operation exactly $X$ times: Choose two integers $i$ and $j$ such that $1 ≀ i < j ≀ N$. Choose a non-negative integer $p$....
for _ in range(int(input())): n, x = [int(i) for i in input().split()] s = [list(bin(int(i))[2:]) for i in input().split()] pad = ["0" for f in range(32 - len(s[-1]))] s[-1] = pad + s[-1] if x > 10**5 and n > 2: arr = [int("".join(el), 2) for el in s] k = 0 for l in range(n):...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR VAR NUMBER IF...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a sequence $A_{1}, A_{2}, \ldots, A_{N}$ and you have to perform the following operation exactly $X$ times: Choose two integers $i$ and $j$ such that $1 ≀ i < j ≀ N$. Choose a non-negative integer $p$....
def fun(a, t): global x c = 0 s = list(bin(a)[2:]) for i in range(len(s)): if s[i] == "1": c = c + 1 s[i] = "0" if t + c == x: break return int("".join(s), 2), c for i in range(int(input())): n, x = map(int, input().split()) l = l...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR STRING IF BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VA...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a sequence $A_{1}, A_{2}, \ldots, A_{N}$ and you have to perform the following operation exactly $X$ times: Choose two integers $i$ and $j$ such that $1 ≀ i < j ≀ N$. Choose a non-negative integer $p$....
def count(n): count = 0 while n: count += n & 1 n >>= 1 return count for _ in range(int(input())): n, x = map(int, input().split()) l = list(map(int, input().split())) t = 0 for i in range(0, n - 1): f = l[i] & t l[i] = l[i] - f t = t - f if ...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a sequence $A_{1}, A_{2}, \ldots, A_{N}$ and you have to perform the following operation exactly $X$ times: Choose two integers $i$ and $j$ such that $1 ≀ i < j ≀ N$. Choose a non-negative integer $p$....
N_bits = 30 t = int(input()) for _ in range(t): n, x = map(int, input().split()) arr = list(map(int, input().split())) less_x = False last = arr[n - 1] last_0 = 0 n0 = bin(arr[0]).count("1") for i in range(n - 1): x_ = x - bin(arr[i]).count("1") if x == 0: break ...
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBE...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a sequence $A_{1}, A_{2}, \ldots, A_{N}$ and you have to perform the following operation exactly $X$ times: Choose two integers $i$ and $j$ such that $1 ≀ i < j ≀ N$. Choose a non-negative integer $p$....
width = 32 def find_last_non_zero_row(zero_at_x, x): if x < zero_at_x[1]: return 0 if x > zero_at_x[-1]: return len(zero_at_x) - 1 i = 0 j = len(zero_at_x) - 1 while i < j: m = (i + j) // 2 if zero_at_x[m] <= x and x < zero_at_x[m + 1]: return m ...
ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR IF VAR BIN_OP VAR NUMBER VAR ASSIGN V...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
def z(a): ob, fa = 0, 2 while fa <= a * 2: ob += (a + 1) // fa * (fa // 2) + max(0, (a + 1) % fa - fa // 2) fa *= 2 return ob for x in range(int(input())): [a, b] = [int(x) for x in input().strip().split(" ")] if a >= 0 and b >= 0: print(z(b) - z(max(0, a - 1))) elif a ...
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR ...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
def ones_between(a, b): if a >= 0: return ones_below(b) - ones_below(a) if b < 0: return ones_below(-b) - ones_below(-a) + 32 * (b - a) return ones_below(b) - 32 * a - ones_below(-a) def ones_below(n): k = n.bit_length() - 1 if n & n - 1 == 0: return n // 2 * k m = 1 <<...
FUNC_DEF IF VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP NUMBER BIN_OP VAR VAR RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP NUMBER VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP VAR...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
n = 1 << 32 def h(x): res = 0 while x > 0: res += x & 1 x >>= 1 return res def g(x): if x <= 1: return x if x & 1: return 2 * g(x >> 1) + (x + 1) // 2 return g(x - 1) + h(x) def f(a, b): if a == 0: return g(b) if a > 0: return g(b) - ...
ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF IF VAR NUMBER RETURN VAR IF BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CA...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
def bin_s(n): lower = 0 upper = base while lower < upper: x = lower + (upper - lower) // 2 val = 2**x if n == val: return val elif n > val: if lower == x: return val lower = x elif n < val: upper = x ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR RETURN VAR IF VAR VAR IF VAR VAR RETURN VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN BIN_OP NUMBER VAR FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP VAR NUMBER ...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
def Ones(x): if x < 0: x = (1 << 32) + x BitAtOnes = [] for i in range(32): if x & 1: BitAtOnes.append(i) x //= 2 return BitAtOnes def Zeroes(x): return Ones(~x) def TotalOnesPos(x): OneIdx = Ones(x)[::-1] Total = 0 for i, Idx in enumerate(OneIdx):...
FUNC_DEF IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_O...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
def clear_msb(x): tmp = x msb = 0 while x != 0: x >>= 1 msb += 1 msb = max(0, msb - 1) x = tmp return x & (1 << msb) - 1 def num_ones_from_zero_msb_of(end): msb = -1 while end != 0: end >>= 1 msb += 1 return msb * 2 ** (msb - 1) def num_ones_from_z...
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER RETURN BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER FUNC_DEF...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
def count_pos(num): if num == 0: return 0 total = 0 for curr_bit in range(32): total += num // (2 << curr_bit) << curr_bit total += max(0, num % (2 << curr_bit) - ((1 << curr_bit) - 1)) return total def count_neg(num): if num == 0: return 0 assert num < 0 to...
FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR ...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
def ones(n): total = 0 for i in range(31, -1, -1): k = 1 << i if n & k: n ^= k total += bits[i] + (n + 1) return total def onesNeg(n): return n * -32 - ones(~n) bits = [0] * 32 for i in range(1, 32): bits[i] = (1 << i - 1) * i for _ in range(int(input())):...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR ...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
n = int(input()) memo = {(0): 1} def count_bit_2exp(k): if k in memo: return memo[k] result = 1 + 2 * (count_bit_2exp(k - 1) - 1) + 2 ** (k - 1) memo[k] = result return result def count_bit(n): if n < 0: return 32 * -n - count_bit(-n - 1) result = 0 hbit = 0 for b in ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER FUNC_DEF IF VAR VAR RETURN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER RETURN BIN_OP BIN_OP NUMBER VAR FUNC_CA...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
def fun(a): mystr = bin(a)[2:] ans = 0 count = 0 length = len(mystr) for i in range(0, length): if mystr[i] == "1": ans = ( ans + count * 2 ** (length - 1 - i) + (length - 1 - i) * 2 ** (length - 2 - i) ) cou...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER V...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
MAXBITS = 32 def count(n): if n >= 0: return poscount(n) else: n += 1 return poscount(-1 - n) + n * MAXBITS if n != 0 else 0 def poscount(n): if n == 0: return 0 else: nbits = n.bit_length() - 1 msb = 1 << nbits rem = n - msb return msb...
ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN FUNC_CALL VAR VAR VAR NUMBER RETURN VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR RETURN BIN_OP BIN_OP BIN_OP BIN_O...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
def CountBits(val): return "{:b}".format(val).count("1") def SumToBit(bit): if bit < 0: return 0 return bit + 1 << bit def SumUpA(val, bits): totalSum = 0 newBit = -1 while val != (2 << bits) - 1: orig = val while orig == val: newBit += 1 val |...
FUNC_DEF RETURN FUNC_CALL FUNC_CALL STRING VAR STRING FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR NUMBER VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CAL...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
def popcount(N): n = abs(N) p = 0 b = 0 while n > 1 << b: b += 1 while b > 0: m = 1 << b if n & m: n ^= m p += b * (m >> 1) + n b -= 1 if N < 0: return 32 * N + p else: return p T = int(input()) for t in range(T): ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER VAR VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR NUMBER RETURN BIN_OP BIN_OP NUMBER VAR VAR RETURN VAR ASSIGN VAR FUNC_CAL...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
t = int(input()) def gen(num): if num == "": return 0 elif num == "1": return 1 elif num == "0": return 0 elif num[0] == "0": return gen(num[1:]) else: return int(num[1:], 2) + 1 + gen(num[1:]) + 2 ** (len(num) - 2) * (len(num) - 1) def func(a, b): if ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER IF VAR NUMBER STRING RETURN FUNC_CALL VAR VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP FUNC_CALL VAR V...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
def to_bin(x): if x < 0: x += 1 << 32 return bin(x)[2:] def naive(a, b): a, b = min(a, b), max(a, b) s = 0 for i in range(a, b + 1): s += to_bin(i).count("1") return s def sum_1_by_pos(x, i): b = 2**i if x % (2 * b) >= b: return x // (2 * b) * b + x % b + 1 ...
FUNC_DEF IF VAR NUMBER VAR BIN_OP NUMBER NUMBER RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR VAR STRING RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR BIN_OP N...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
def sum1(x): b = 0 for i in range(len(bin(x)[2:])): b += (x + 1) // 2 ** (i + 1) * 2**i + (x + 1) % 2 ** (i + 1) // ( 2**i + 1 ) * ((x + 1) % 2 ** (i + 1)) % 2**i return b T = int(input()) for _ in range(T): a, b = map(int, input().split(" ")) if a >= 0 and b >= 0: ...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
def lgst2Pwr(inNum): j = 0 k = 0 while j < inNum: j = 2**k k += 1 return k - 1 def getSum(temp_Int): sum_Int = 0 i = 0 currExp = 0 exp = lgst2Pwr(temp_Int) while temp_Int > 0: if exp != -1: sum_Int += (-1) ** i * (2 ** (exp - 1) * exp + 1 + currE...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP NUMBER VAR VAR NUMBER RETURN BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR NUMBER IF VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VA...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
def count(x): x = x + 1 y = 0 for i in range(1, 33): y += x // 2**i * 2 ** (i - 1) + max(0, x % 2**i - 2 ** (i - 1)) return y def twosCompliment(a, b): if a >= 0 and b >= 0: return count(b) - count(a - 1) elif a < 0 and b < 0: z = 32 * (b - a + 1) a = -1 - a ...
FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER RETURN VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN BIN_OP F...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
import sys from time import time def bits_set(n, v): cnt = 0 while n: cnt += 1 n = n & n - 1 & v return cnt def solve_bf(a, b): v = (1 << 32) - 1 sm = 0 for i in range(a, b + 1): c = bits_set(i, v) sm += c return sm def f_gen(): f, d = 0, 1 while...
IMPORT FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER NUM...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
import sys count = 0 ones = [] ones.insert(0, 0) ones.insert(1, 1) for i in range(2, 32): ones.insert(i, 2 * ones[i - 1] + 2 ** (i - 2)) tot_1s = [] tot_1s.insert(0, 0) for i in range(1, 32): tot_1s.insert(i, tot_1s[i - 1] + ones[i]) num_cases = int(input().strip()) for i in range(num_cases): total_count =...
IMPORT ASSIGN VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER N...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
def bitize_twos_complement(X, bits=32): L = [(0) for r in range(0, bits)] if X >= 0: for i in range(0, 32): L[i] = X % 2 X //= 2 elif X < 0: X *= -1 X -= 1 for i in range(0, 32): L[i] = (X + 1) % 2 X //= 2 return L def num...
FUNC_DEF NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NU...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
for _ in range(int(input())): down, up = map(int, input().split()) temp_down = down temp_up = up rd = 0 ru = 0 try: if down < 0: down = abs(down) j = 2 for i in range(32): rd += down // j * (j // 2) if down % j > j // 2:...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
def countbit(b, n): q = n >> b + 1 r = n & (1 << b + 1) - 1 return (q << b) + max(0, r - (1 << b)) def countall(n): return sum(countbit(b, n) for b in range(32)) def solve(a, b): if 0 <= a: return countall(b + 1) - countall(a) if b < 0: return countall(2**32 + b + 1) - counta...
FUNC_DEF ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER FUNC_DEF IF NUMBER VAR RETURN BIN_OP FUNC_CALL ...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
q = int(input()) Q = [tuple(map(int, input().split())) for x in range(q)] def f(y): s = bin(y)[2:] l = len(s) n = 0 ones = 0 for i in range(l): if s[i] == "1": n += 2 ** (l - 1 - i) * ones + 2 ** (l - 2 - i) * (l - 1 - i) ones += 1 n += ones return n def g...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
MM, FULL, MEG = 1 << 31, (1 << 30) * 31, (1 << 30) * 31 + 2147483648 def solpos(x, sp=31): return ( x if sp == 0 else ( x - (1 << sp) + 1 + sp * (1 << sp - 1) + solpos(x - (1 << sp), sp - 1) if x & 1 << sp else solpos(x, sp - 1) ) ) def sol...
ASSIGN VAR VAR VAR BIN_OP NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER BIN_OP BIN_OP BIN_OP NUMBER NUMBER NUMBER NUMBER FUNC_DEF NUMBER RETURN VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
def count_positive(n): count = mul = 0 for i in range(31, -1, -1): b = 1 << i if b & n: count += 1 + b * i // 2 + b * mul mul += 1 return count def count_negative(n): n = -n return 32 * n - count_positive(n - 1) def count(n): return count_positive(n) i...
FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR RETURN BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF RETURN VAR ...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
def fun(n): if n < 0: return 0 res = 0 y = 1 while n // 2**y != 0: res += n // 2**y * 2 ** (y - 1) if n % 2**y + 1 - 2 ** (y - 1) > 0: res += n % 2**y + 1 - 2 ** (y - 1) y += 1 if n % 2**y + 1 - 2 ** (y - 1) > 0: res += n % 2**y + 1 - 2 ** (y - 1) ...
FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBE...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
def get_val2(ind1, ind2): j = 1 ans = 0 for i in range(1, 33): a = ind2 // j if a != 0: if a % 2 == 0: b = a // 2 noz = b * j c = ind2 % j noz = noz + c else: b = a // 2 + 1 ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
import sys def pos(z): h = z + 1 sum = 0 for i in range(33): a = h // 2**i sum += a // 2 * 2**i if a % 2 != 0: sum += h - a * 2**i return sum def neg(z): sum = 0 h = abs(z) for i in range(33): a = h // 2**i sum += a // 2 * 2**i ...
IMPORT FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP VAR BIN_OP NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FO...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
def GetOnes(val, f): ones = 0 rest = 0 neg = False if val < 0: val = -val - 1 neg = True for i in range(0, 31): mask = 1 << i if val & mask: ones += f[i] + (rest + 1) rest ^= val & mask if neg: ones = 32 * (val + 1) - ones retur...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR IF VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER ...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
T = int(input()) def memoize(function): memo = {} def wrapper(*args): if args in memo: return memo[args] else: rv = function(*args) memo[args] = rv return rv return wrapper @memoize def ones_from_0(A): if A == 0: return 0 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR RETURN VAR RETURN VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NU...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
def count(a): if a == 0: return 0 if a % 2 == 0: return count(a - 1) + bin(a).count("1") return (a + 1) // 2 + 2 * count(a // 2) def solve(a, b, r=32): if a > 0: return count(b) - count(a - 1) if a == 0: return count(b) if b > 0: return count(b) - r * a ...
FUNC_DEF IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL FUNC_CALL VAR VAR STRING RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF NUMBER IF VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
def count_bits(n): ret = 0 while n > 1: if n % 2 == 1: ret += 1 n = int(n / 2) return ret + 1 def no_bits(n): n = int(n) if n == 0: return 0 elif n < 0: n += 1 return (1 - n) * 32 - no_bits(-n) elif n % 2 == 0: return count_bits(n...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR ...
Understanding $2$'s complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is $1$, we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote...
bit_width = 32 def ones_counting_to_positive(test): bit_number = bit_width mask = 1 << bit_width - 1 bits_left_count = 0 count = 0 while bit_number > 0: bit_number -= 1 mask_new = mask >> 1 if mask & test == mask: count += 1 + bit_number * mask_new + bits_left_c...
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP NUMBER BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR RETURN VAR FUNC_DEF RETURN BIN_OP BIN_O...
Even if you just leave them be, they will fall to pieces all by themselves. So, someone has to protect them, right? You find yourself playing with Teucer again in the city of Liyue. As you take the eccentric little kid around, you notice something interesting about the structure of the city. Liyue can be represented ...
n, k = map(int, input().split()) cnt = 0 sum = 1 while sum < n: sum = sum * k cnt = cnt + 1 print(cnt) for i in range(0, n): for j in range(i + 1, n): u = i v = j ans = 0 while u != v: u //= k v //= k ans = ans + 1 print(ans, end=" ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR ...
Given two numbers: 'left' and 'right' (1 <= 'left' <= 'right' <= 200000000000000) return sum of all '1' occurencies in binary representations of numbers between 'left' and 'right' (including both) ``` Example: countOnes 4 7 should return 8, because: 4(dec) = 100(bin), which adds 1 to the result. 5(dec) = 101(bin), wh...
def countevenone(left, right, span, maxbincount): if span == 1: return bin(left).count("1") if span == 2: return bin(right).count("1") + bin(left).count("1") if span % 2 != 0: if left % 2 == 0: adds = span // 2 + bin(right).count("1") left = left // 2 ...
FUNC_DEF IF VAR NUMBER RETURN FUNC_CALL FUNC_CALL VAR VAR STRING IF VAR NUMBER RETURN BIN_OP FUNC_CALL FUNC_CALL VAR VAR STRING FUNC_CALL FUNC_CALL VAR VAR STRING IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER A...
Given two numbers: 'left' and 'right' (1 <= 'left' <= 'right' <= 200000000000000) return sum of all '1' occurencies in binary representations of numbers between 'left' and 'right' (including both) ``` Example: countOnes 4 7 should return 8, because: 4(dec) = 100(bin), which adds 1 to the result. 5(dec) = 101(bin), wh...
def countOnes(left, right): def bindig(number): ans = 0 g = bin(number)[2:][::-1] for i in range(len(g)): if g[i] == "1": if i == len(g) - 1: ans += 1 + 2 ** (i - 1) * i else: ans += 1 + 2 ** (i - 1) * i + g...
FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP NUMBER BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP FUNC_CAL...
Given two numbers: 'left' and 'right' (1 <= 'left' <= 'right' <= 200000000000000) return sum of all '1' occurencies in binary representations of numbers between 'left' and 'right' (including both) ``` Example: countOnes 4 7 should return 8, because: 4(dec) = 100(bin), which adds 1 to the result. 5(dec) = 101(bin), wh...
sumOnes = lambda n: ( lambda msb: n and -~n + ~-msb * 2**msb + sumOnes(n - 2 ** -~msb) )(n.bit_length() - 2) countOnes = lambda a, b: sumOnes(b) - sumOnes(a - 1)
ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP NUMBER VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER
Given two numbers: 'left' and 'right' (1 <= 'left' <= 'right' <= 200000000000000) return sum of all '1' occurencies in binary representations of numbers between 'left' and 'right' (including both) ``` Example: countOnes 4 7 should return 8, because: 4(dec) = 100(bin), which adds 1 to the result. 5(dec) = 101(bin), wh...
def countOnes(left, right): def f(n): c = 0 a = list(reversed(list(bin(n)))) for i, d in enumerate(a): if d == "1": c += 1 + 2**i * i / 2 + 2**i * a[i + 1 :].count("1") return c return f(right) - f(left - 1)
FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING RETURN VAR RETURN BIN_OP FUNC_CALL VA...
Given two numbers: 'left' and 'right' (1 <= 'left' <= 'right' <= 200000000000000) return sum of all '1' occurencies in binary representations of numbers between 'left' and 'right' (including both) ``` Example: countOnes 4 7 should return 8, because: 4(dec) = 100(bin), which adds 1 to the result. 5(dec) = 101(bin), wh...
def countOnes(left, right): left_binary_digits = count_binary_digits(left) right_binary_digits = count_binary_digits(right) right_binary_sum = sum([int(i) for i in str(bin(right))[2:]]) left_position_in_block = left - calculate_starting_digit(left_binary_digits) + 1 right_position_in_block = right -...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR F...
Given two numbers: 'left' and 'right' (1 <= 'left' <= 'right' <= 200000000000000) return sum of all '1' occurencies in binary representations of numbers between 'left' and 'right' (including both) ``` Example: countOnes 4 7 should return 8, because: 4(dec) = 100(bin), which adds 1 to the result. 5(dec) = 101(bin), wh...
def countOnesFromZero(num): l = sorted([i for i, v in enumerate(bin(num)[2:][::-1]) if v == "1"], reverse=True) l.append(0) return sum(i * 2**v + v * 2 ** (v - 1) for i, v in enumerate(l)) def countOnes(left, right): return countOnesFromZero(right) - countOnesFromZero(left) + bin(left).count("1")
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR STRING NUMBER EXPR FUNC_CALL VAR NUMBER RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL ...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
for _ in range(int(input())): n, m, k = map(int, input().split()) sum = 0 for i in range(1, n): count = min(m, i) if count % 2 == 0: pass else: sum = sum ^ i + 1 + k for j in range(1, m + 1): count1 = min(n, m - j + 1) if count1 % 2 == 0: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
t = int(input()) for _ in range(t): n, m, k = list(map(int, input().split())) if n > m: m, n = n, m res = 0 for i in range(n): if i % 2 == 0: res ^= i + k + 2 if i != m - 1: res ^= n + m - i + k if n % 2 == 1: for j in range(1, m - n): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_O...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
n = int(input()) for i in range(n): r, c, k = list(map(int, input().split(" "))) res = 0 for i in range(1, r + 1): if min(i, c) % 2 != 0: res = res ^ k + i + 1 for j in range(2, c + 1): if min(r, c - j + 1) % 2 != 0: res = res ^ k + r + j print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUN...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
def findxor(s): if s % 4 == 0: return s elif s % 4 == 1: return 1 elif s % 4 == 2: return s + 1 elif s % 4 == 3: return 0 for t in range(int(input())): n, m, k = map(int, input().split()) ans = findxor(k + 1) ^ findxor(k + m + 1) for i in range(2, n + 1): ...
FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN VAR IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_C...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
T = int(input()) def xor(T): mod = T % 4 if mod == 0: return T if mod == 1: return 1 if mod == 2: return T + 1 if mod == 3: return 0 for _ in range(T): N, M, K = map(int, input().split()) s = xor(1 + K) ^ xor(1 + K + M) for i in range(2, N + 1): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN BIN_OP VAR NUMBER IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
T = int(input()) for i in range(T): n, m, k = tuple(map(int, input().split())) res = 0 n_v = 0 if n % 2 == 0: n_v = n else: n_v = n - 1 for i in range(1, m + 1): res ^= k + n + i for i in range(1, n_v + 1): if i % 2 == 1: res ^= k + i + 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
for _ in range(int(input())): n, m, k = map(int, input().split()) ans = 0 if n == 1 or m == 1: for i in range(max(n, m)): ans ^= k + 2 + i else: for i in range((n + m) // 2): if i < min(n, m): if i % 2 == 0: ans ^= k + i + 2 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR IF BIN_OP...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
import sys intinp = lambda: int(input()) def listinp(func=int): return list(map(func, input().split())) def nsepline(n, func=str): return [func(input()) for _ in range(n)] def printlist(li, glue=" "): return glue.join(list(map(str, li))) def fop(s, end="\n"): sys.stdout.write(str(s) + end) de...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF STRING RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_DEF STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
def solve(n, m, k): res = 0 for i in range(1, n + 1): if min(i, m) % 2 == 1: res = res ^ i + 1 + k for i in range(2, m + 1): if min(n, m - i + 1) % 2 == 1: res = res ^ i + n + k return res t = int(input()) for i in range(t): n, m, k = map(int, input().split(...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BI...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
for _ in range(int(input())): n, m, k = map(int, input().split()) x = k + 2 y = k + n + m sum1 = 0 for i in range(1, n + 1): if min(i, m) % 2 != 0: sum1 ^= k + i + 1 for i in range(2, m + 1): if min(n, m - i + 1) % 2 != 0: sum1 ^= k + n + i print(sum1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
for t in range(int(input())): nr, nc, K = map(int, input().split()) xor = 0 min_rc = min(nr, nc) counts = [min_rc] * (nr + nc - 1) for i in range(min_rc): counts[i] = counts[-(i + 1)] = i + 1 for i_plus_j, count in zip(range(2, nc + nr + 1), counts): if count % 2 != 0: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
T = int(input()) def solve(N, M, K): if N > M: N, M = M, N ans = 0 for k1 in range(2, N + M + 1): if (min(k1 - 1, N) - max(1, k1 - M) + 1) % 2: ans = ans ^ k1 + K return ans for _ in range(T): N, M, K = [int(s) for s in input().split()] print(solve(N, M, K))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR RETURN VAR FOR ...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
t = int(input()) r = [] for i in range(t): n, m, k = map(int, input().split()) rs = 0 xmax = max(n, m) xmin = min(n, m) for x in range(1, xmin // 2 + 1): rs = rs ^ 2 * x + k rs = rs ^ n + m - 2 * x + 2 + k if xmin % 2 == 1: for y in range(xmin // 2 + 1, xmax - xmin // 2 +...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
import sys input = sys.stdin.readline R = lambda: map(int, input().split()) I = lambda: int(input()) S = lambda: input().rstrip("\n") L = lambda: list(R()) def solve(): n, m, k = R() if m > n: n, m = m, n ans = 0 for i in range(1, n + 1): t = min(i, m) if t & 1: an...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BI...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
def solve(n, m, k): res = 0 for i in range(1, n): if i % 2 == 0: res ^= k + i + m else: res ^= k + i + 1 if n % 2 == 0: res ^= k + n + m else: for j in range(1, m + 1): res ^= k + j + n return res def main(): for _ in range(in...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF FOR VAR FUNC_C...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
t = int(input()) for x in range(t): [n, m, k] = [int(y) for y in input().split()] if m == n: ans = 0 for i in range(1, m + 1): ans ^= int(k + 2 * i) print(ans) elif m > n and n != 1: ans = 0 if n % 2 == 0: for i in range(1, int(n / 2) + 1): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
for _ in range(int(input())): n, m, k = map(int, input().split()) n, m = min(n, m), max(n, m) ans = 0 j = 2 for i in range(1, n): if i % 2: ans ^= j + k j += 1 if n % 2: while 1: ans ^= j + k j += 1 if j == m + n - n + 2: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER WHILE NUM...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
T = int(input()) for k in range(T): N, M, K = [int(i) for i in input().split()] an = 0 a = 1 for i in range(K + 2, K + N + M + 1): if a % 2 != 0: an = an ^ i if i - K <= min(N, M): a += 1 elif i - K + 1 >= max(N, M) + 2: a -= 1 print(an)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR FU...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
for t in range(int(input())): n, m, k = map(int, input().split()) dt = dict() tp = k + 2 for i in range(1, n + 1): dt[tp] = min(i, m) tp += 1 for j in range(2, m + 1): dt[tp] = min(n, m - j + 1) tp += 1 ans = 0 for key, value in dt.items(): if value % ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VA...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
for t in range(int(input())): l = list(map(int, input().split())) n = l[0] m = l[1] k = l[2] r = [] for i in range(1, n + 1): r.append((1 + i, i, 1)) for j in range(2, m + 1): r.append((n + j, n, j)) ans = 0 for i in range(len(r)): v = r[i] if i < n: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMB...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
for _ in range(int(input())): r, c, k = map(int, input().split()) ans = 0 for j in range(1, c + 1): p = min(r - 1, j - 1) + 1 if p % 2: ans ^= 1 + j + k for i in range(2, r + 1): p = min(c - 1, r - i) + 1 if p % 2: ans ^= i + c + k print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR VAR FOR VAR FUNC_CA...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
T = int(input()) ans = [] for _ in range(T): N, M, K = [int(i) for i in input().split()] l = 1 a = None X = min(N, M) for i in range(K + 2, K + M + 1 + 1): if a == None: a = K + 2 elif l % 2 != 0: a ^= i l = min(l + 1, X) l = 1 for i in range(K...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NONE ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR NONE ASSIGN VAR B...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
T = int(input()) for _ in range(T): N, M, K = map(int, input().split()) res = 0 for j in range(1, M + 1): if j <= N and j % 2 == 1: res = res ^ K + j + 1 elif j > N and N % 2 == 1: res = res ^ K + j + 1 for j in range(M + 1, N + M): if j > N and (N + M - j...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
t = int(input()) while t: n, m, k = map(int, input().split()) v = k + 1 + 1 v = v ^ k + m + n c = 2 for i in range(k + 3, k + n + 2): y = min(c, m) if y % 2 != 0: v = v ^ i c += 1 c = 2 for i in range(k + n + 2, k + n + m): y = min(n, m - c + 1) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
for _ in range(int(input())): n, m, k = map(int, input().split()) ans = 0 for i in range(1, n + 1 - n % 2): if i & 1: ans ^= k + i + 1 else: ans ^= k + i + m if n & 1: for i in range(1, m + 1): ans ^= k + n + i print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER FOR VAR FUNC_C...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
for _ in range(int(input())): n, m, k = map(int, input().split()) ans = 0 while m or n: for i in range(1, min(n, m) + 1): ans = ans ^ k + i + i if n < m: m = m - n k += n elif n > m: n = n - m k += m else: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN V...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
def xor(number): if number % 4 == 0: return number elif number % 4 == 1: return 1 elif number % 4 == 2: return number + 1 else: return 0 T = int(input()) for _ in range(T): N, M, K = map(int, input().split()) lst = [(xor(K + i) ^ xor(K + i + M)) for i in range(1...
FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN VAR IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_O...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
def solve(): n, m, k = inl() ans = 0 for i in range(1, n + 1): if min(i, m) % 2 != 0: ans ^= k + i + 1 for j in range(2, m + 1): if min(n, m - j + 1) % 2 != 0: ans ^= k + n + j print(ans) def inl(): return [int(i) for i in input().split()] def inp(): ...
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR BIN_OP BIN_O...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
for _ in range(int(input())): n, m, k = map(int, input().split()) ans = 0 if min(m, n) == 1: for i in range(1, max(m, n)): ans ^= k + i + 1 else: ans = 0 x = min(m, n) y = max(m, n) for i in range(1, x, 2): ans ^= k + i + 1 if x & 1...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
for _ in range(int(input())): n, m, k = map(int, input().split()) c = 0 x = 0 if n % 2 == 0: x = n else: x = n - 1 for i in range(1, x + 1): if i % 2 == 1: c ^= k + i + 1 else: c ^= k + m + i if n % 2 == 1: for j in range(1, m +...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR ...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
for _ in range(int(input())): n, m, k = map(int, input().split()) arr = [i for i in range(2, n + m + 1)] diffarray = [0] * (n + m + 1) for i in range(n): diffarray[i] += 1 diffarray[i + m] -= 1 count = 0 ans = 0 for i in range(len(diffarray)): count += diffarray[i] ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUM...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
for _ in range(int(input())): N, M, K = map(int, input().strip().split()) last = 0 for i in range(1, N // 2 + 1): last ^= K + i * 2 last ^= K + M + i * 2 if N % 2 != 0: for i in range(K + N + 1, K + N + M + 1): last ^= i print(last)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CA...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
def prog_name(): n, m, k = map(int, input().split()) x = 0 c = 0 if n % 2 == 0: x = n else: x = n - 1 for x in range(1, x + 1): if x % 2 == 1: c ^= k + x + 1 else: c ^= k + m + x if n % 2 == 1: for y in range(1, m + 1): ...
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR IF B...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
for i in range(int(input())): a, b, c = map(int, input().split()) e = 0 for i in range(2, a + 2): d = min(i - 1, b) if d % 2 == 0: pass else: e ^= i + c for i in range(a + 2, a + b + 1): f = min(a, b - (i - a) + 1) if f % 2 == 0: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
test_case = int(input()) for n1 in range(test_case): n, m, k = [int(i) for i in input().split(" ")] l = ( list(range(1, min(n, m))) + [min(n, m)] * (abs(m - n) + 1) + list(range(1, min(n, m)))[::-1] ) a = 0 for i in range(len(l)): a ^= (k + 2 + i) * (l[i] % 2) pri...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP LIST FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL ...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
for i in range(int(input())): n, m, k = map(int, input().split()) count = 1 ans = 0 for j in range(k + 2, k + m + 1): if count >= n: if n % 2 == 0: break else: ans ^= j elif count % 2 != 0: ans ^= j count += 1 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER ASSIGN VAR...
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a *tasty ingredient* ― an integer $K$. He defines a *tasty matrix* $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) as $A_{i, j} = K + i + j$ for each valid $i,j$. Currently,...
for _ in range(int(input())): n, m, k = map(int, input().split()) a = 0 for i in range(2, m + n + 1): l = max(1, i - m) r = min(n, i - 1) if r >= l and (r - l + 1) % 2 == 1: a ^= k + i print(a)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR...
You are given a weighted tree with $n$ vertices. Recall that a tree is a connected graph without any cycles. A weighted tree is a tree in which each edge has a certain weight. The tree is undirected, it doesn't have a root. Since trees bore you, you decided to challenge yourself and play a game on the given tree. In ...
testcase = int(input()) for _ in range(testcase): n, a, b = [int(num) for num in input().split()] graph = {i: set() for i in range(1, n + 1)} for _ in range(n - 1): v0, v1, w = [int(num) for num in input().split()] graph[v0].add((v1, w)) graph[v1].add((v0, w)) seen = set() se...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CAL...
You are given a weighted tree with $n$ vertices. Recall that a tree is a connected graph without any cycles. A weighted tree is a tree in which each edge has a certain weight. The tree is undirected, it doesn't have a root. Since trees bore you, you decided to challenge yourself and play a game on the given tree. In ...
stack = [] hashesSt = set() t = int(input()) for _ in range(t): n, st, fi = map(int, input().split()) st -= 1 fi -= 1 g = [[] for i in range(n)] for i in range(n - 1): a, b, w = map(int, input().split()) a -= 1 b -= 1 g[a].append((b, w)) g[b].append((a, w)) ...
ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_C...