description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Chef has two non negative integers N and X. He now wants to find the number of integers K such that 0 ≤ K < N, and (N \oplus K) \And X = 0. Note that \oplus denotes the bitwise XOR operator and \And denotes the bitwise AND operator. Help Chef in finding the total required count. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of a single line of input containing N and X denoting the two integers as described in the statement. ------ Output Format ------ For each test case, output the total number of integers K which satisfy the requirements mentioned. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N, X ≤ 2^{30} - 1$ ------ subtasks ------ Subtask 1 (10 points): $1 ≤ M ≤ 10$ Subtask 2 (20 points): The sum of $N$ across all test cases won't exceed $20$. Subtask 3 (70 points): No further constraints. ----- Sample Input 1 ------ 3 4 5 8 4 1 2 ----- Sample Output 1 ------ 0 4 1 ----- explanation 1 ------ Testcase 1: $N = 4, X = 5$. So we need to find the number of $K$, which satisfy $0 ≤ K < 4$, and $(4 \oplus K) \And 5 = 0$. - $(100_{2} \oplus 000_{2}) \And 101_{2} = 100_{2} \And 101_{2} = 100_{2} \neq 0$ - $(100_{2} \oplus 001_{2}) \And 101_{2} = 101_{2} \And 101_{2} = 101_{2} \neq 0$ - $(100_{2} \oplus 010_{2}) \And 101_{2} = 110_{2} \And 101_{2} = 100_{2} \neq 0$ - $(100_{2} \oplus 011_{2}) \And 101_{2} = 111_{2} \And 101_{2} = 101_{2} \neq 0$ So, we have looked at all values of $K$, and found no value which satisfies the requirements. So the answer is $0$.
def fun(n, v1, v2, f, dp): if n == -1: return 1 if dp[n][f] != -1: return dp[n][f] if f == 0: if 1 << n & v1 and 1 << n & v2: ans = fun(n - 1, v1, v2, 0, dp) elif 1 << n & v1 and 1 << n & v2 == 0: ans = fun(n - 1, v1, v2, 0, dp) + fun(n - 1, v1, v2, 1, dp) elif 1 << n & v1 == 0 and 1 << n & v2: ans = fun(n - 1, v1, v2, 0, dp) else: ans = fun(n - 1, v1, v2, 0, dp) elif 1 << n & v1 and 1 << n & v2: ans = fun(n - 1, v1, v2, 1, dp) elif 1 << n & v1 and 1 << n & v2 == 0: ans = 2 * fun(n - 1, v1, v2, 1, dp) elif 1 << n & v1 == 0 and 1 << n & v2: ans = fun(n - 1, v1, v2, 1, dp) else: ans = 2 * fun(n - 1, v1, v2, 1, dp) dp[n][f] = ans return ans for _ in range(int(input())): f = -1 x, k = map(int, input().split()) for i in range(30, -1, -1): if 1 << i & x: f = i break dp = [([-1] * 2) for i in range(31)] ans = fun(f, x, k, 0, dp) print(ans - 1)
FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR IF VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR IF BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR IF BIN_OP BIN_OP NUMBER VAR VAR NUMBER BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR IF BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR IF BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR IF BIN_OP BIN_OP NUMBER VAR VAR NUMBER BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR RETURN VAR 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 FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Chef has two non negative integers N and X. He now wants to find the number of integers K such that 0 ≤ K < N, and (N \oplus K) \And X = 0. Note that \oplus denotes the bitwise XOR operator and \And denotes the bitwise AND operator. Help Chef in finding the total required count. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of a single line of input containing N and X denoting the two integers as described in the statement. ------ Output Format ------ For each test case, output the total number of integers K which satisfy the requirements mentioned. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N, X ≤ 2^{30} - 1$ ------ subtasks ------ Subtask 1 (10 points): $1 ≤ M ≤ 10$ Subtask 2 (20 points): The sum of $N$ across all test cases won't exceed $20$. Subtask 3 (70 points): No further constraints. ----- Sample Input 1 ------ 3 4 5 8 4 1 2 ----- Sample Output 1 ------ 0 4 1 ----- explanation 1 ------ Testcase 1: $N = 4, X = 5$. So we need to find the number of $K$, which satisfy $0 ≤ K < 4$, and $(4 \oplus K) \And 5 = 0$. - $(100_{2} \oplus 000_{2}) \And 101_{2} = 100_{2} \And 101_{2} = 100_{2} \neq 0$ - $(100_{2} \oplus 001_{2}) \And 101_{2} = 101_{2} \And 101_{2} = 101_{2} \neq 0$ - $(100_{2} \oplus 010_{2}) \And 101_{2} = 110_{2} \And 101_{2} = 100_{2} \neq 0$ - $(100_{2} \oplus 011_{2}) \And 101_{2} = 111_{2} \And 101_{2} = 101_{2} \neq 0$ So, we have looked at all values of $K$, and found no value which satisfies the requirements. So the answer is $0$.
def prod(arr): res = 1 for el in arr: res *= el return res def to_binary(n, l): if n == 0: return [0] * l res = [] while n > 0 or len(res) < l: b = n % 2 n //= 2 res.append(b) return list(reversed(res)) def get_values(n, x): bn = to_binary(n, 32) bx = to_binary(x, 32) arr = [] for i in range(len(bn)): if bx[i] == 0: arr.append([0, 1]) else: arr.append([bn[i]]) return [bn, bx, arr] def f(bn, bx, arr, start): if len(bn) == 0: return 0 for i in range(start, len(bn)): if bn[i] == 0: continue if len(arr[i]) == 2: return prod(map(len, arr[i + 1 :])) + f(bn, bx, arr, i + 1) elif arr[i][0] == 0: return prod(map(len, arr[i + 1 :])) else: return f(bn, bx, arr, i + 1) return 0 def g(n, x): values = get_values(n, x) return f(*values, 0) t = int(input()) for i in range(t): n, x = [int(el) for el in input().split(" ")] print(g(n, x))
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER RETURN BIN_OP LIST NUMBER VAR ASSIGN VAR LIST WHILE VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR VAR RETURN LIST VAR VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER RETURN BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
We are stacking blocks to form a pyramid. Each block has a color which is a one letter string, like `'Z'`. For every block of color `C` we place not in the bottom row, we are placing it on top of a left block of color `A` and right block of color `B`. We are allowed to place the block there only if `(A, B, C)` is an allowed triple. We start with a bottom row of bottom, represented as a single string. We also start with a list of allowed triples allowed. Each allowed triple is represented as a string of length 3. Return true if we can build the pyramid all the way to the top, otherwise false. Example 1: Input: bottom = "XYZ", allowed = ["XYD", "YZE", "DEA", "FFF"] Output: true Explanation: We can stack the pyramid like this: A / \ D E / \ / \ X Y Z This works because ('X', 'Y', 'D'), ('Y', 'Z', 'E'), and ('D', 'E', 'A') are allowed triples. Example 2: Input: bottom = "XXYX", allowed = ["XXX", "XXY", "XYX", "XYY", "YXZ"] Output: false Explanation: We can't stack the pyramid to the top. Note that there could be allowed triples (A, B, C) and (A, B, D) with C != D. Note: bottom will be a string with length in range [2, 8]. allowed will have length in range [0, 200]. Letters in all strings will be chosen from the set {'A', 'B', 'C', 'D', 'E', 'F', 'G'}.
class Solution: def pourWater(self, heights, total, index): if not heights or total <= 0 or index < 0 or index >= len(heights): return heights for _ in range(total): left = -1 for i in range(index - 1, -1, -1): if heights[i] > heights[i + 1]: break if heights[i] < heights[i + 1]: left = i if left != -1: heights[left] += 1 continue right = -1 for j in range(index + 1, len(heights)): if heights[j] > heights[j - 1]: break if heights[j] < heights[j - 1]: right = j if right != -1: heights[right] += 1 continue heights[index] += 1 return heights
CLASS_DEF FUNC_DEF IF VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER RETURN VAR
We are stacking blocks to form a pyramid. Each block has a color which is a one letter string, like `'Z'`. For every block of color `C` we place not in the bottom row, we are placing it on top of a left block of color `A` and right block of color `B`. We are allowed to place the block there only if `(A, B, C)` is an allowed triple. We start with a bottom row of bottom, represented as a single string. We also start with a list of allowed triples allowed. Each allowed triple is represented as a string of length 3. Return true if we can build the pyramid all the way to the top, otherwise false. Example 1: Input: bottom = "XYZ", allowed = ["XYD", "YZE", "DEA", "FFF"] Output: true Explanation: We can stack the pyramid like this: A / \ D E / \ / \ X Y Z This works because ('X', 'Y', 'D'), ('Y', 'Z', 'E'), and ('D', 'E', 'A') are allowed triples. Example 2: Input: bottom = "XXYX", allowed = ["XXX", "XXY", "XYX", "XYY", "YXZ"] Output: false Explanation: We can't stack the pyramid to the top. Note that there could be allowed triples (A, B, C) and (A, B, D) with C != D. Note: bottom will be a string with length in range [2, 8]. allowed will have length in range [0, 200]. Letters in all strings will be chosen from the set {'A', 'B', 'C', 'D', 'E', 'F', 'G'}.
class Solution: def pourWater(self, heights, V, K): for i in range(V): if not self.fallLeft(K, heights): if not self.fallRight(K, heights): heights[K] += 1 return heights def fallLeft(self, K, heights): minBlock = K for i in range(K - 1, -1, -1): if heights[i] < heights[minBlock]: minBlock = i elif heights[i] > heights[minBlock]: break if minBlock == K: return False heights[minBlock] += 1 return True def fallRight(self, K, heights): minBlock = K for i in range(K + 1, len(heights)): if heights[i] < heights[minBlock]: minBlock = i elif heights[i] > heights[minBlock]: break if minBlock == K: return False heights[minBlock] += 1 return True
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR IF VAR VAR RETURN NUMBER VAR VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR IF VAR VAR RETURN NUMBER VAR VAR NUMBER RETURN NUMBER
We define f(x)=\begin{cases} f(x \oplus reverse(x))+1 & \text{if } x \neq 0 \\ 0 & \text{otherwise} \end{cases} Here, \oplus denotes the [bitwise XOR operation] and reverse is a function that takes a postive integer, reverses its binary representation (without any leading zeros) and returns the resulting number. For example reverse(2)=1, reverse(6)=3, reverse(7)=7 Given an integer N, find out the value of \sum^{2^{N}-1}_{i=1} f(i) modulo 998244353 or claim that there exists a positive integer x < 2^{N} for which f is undefined. ------ Input Format ------ - The first line of input contains a single integer T - the number of test cases. The description of T test cases follows. - The first and only line of each test case contains a single integer N. ------ Output Format ------ - For each test case output a single line containing one integer : - -1 if there exists a positive integer x such that x < 2^{N} and f(x) is undefined - \sum^{2^{N}-1}_{i=1} f(i) modulo 998244353 otherwise ------ Constraints ------ $1 ≤ T ≤ 3 \cdot 10^{5}$ $1 ≤ N ≤ 10^{9}$ ----- Sample Input 1 ------ 8 1 2 3 5 8 13 21 34 ----- Sample Output 1 ------ 1 4 10 58 578 20098 5236738 24641495 ----- explanation 1 ------ Note that: - $f(1) = f(1 \oplus 1) + 1 = f(0) + 1 = 1$ - $f(2) = f(2 \oplus 1) + 1 = f(3) + 1 = (f(3 \oplus 3) + 1) + 1 = (f(0) + 1) + 1 = 2$ - $f(3) = f(3 \oplus 3) + 1 = f(0) + 1 = 1$ - Test case-1: $\sum^{2^{1}-1}_{i=1} f(i) = f(1) = 1$. So answer is $1 \text{ mod } 998244353 = 1$. - Test case-2: $\sum^{2^{2}-1}_{i=1} f(i) = f(1) + f(2) + f(3) = 1 + 2 + 1 = 4$. So answer is $4 \text{ mod } 998244353 = 4$.
def main(): n = int(input()) mod = 998244353 if n == 1: return 1 if n == 2: return 4 if n == 3: return 10 a = 10 * pow(2, n - 2, mod) + 2 b = 2 * pow(2, (n + 1) // 2, mod) c = 2 * pow(2, n // 2, mod) return (a - b - c) % mod for _ in range(int(input())): print(main())
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
We define f(x)=\begin{cases} f(x \oplus reverse(x))+1 & \text{if } x \neq 0 \\ 0 & \text{otherwise} \end{cases} Here, \oplus denotes the [bitwise XOR operation] and reverse is a function that takes a postive integer, reverses its binary representation (without any leading zeros) and returns the resulting number. For example reverse(2)=1, reverse(6)=3, reverse(7)=7 Given an integer N, find out the value of \sum^{2^{N}-1}_{i=1} f(i) modulo 998244353 or claim that there exists a positive integer x < 2^{N} for which f is undefined. ------ Input Format ------ - The first line of input contains a single integer T - the number of test cases. The description of T test cases follows. - The first and only line of each test case contains a single integer N. ------ Output Format ------ - For each test case output a single line containing one integer : - -1 if there exists a positive integer x such that x < 2^{N} and f(x) is undefined - \sum^{2^{N}-1}_{i=1} f(i) modulo 998244353 otherwise ------ Constraints ------ $1 ≤ T ≤ 3 \cdot 10^{5}$ $1 ≤ N ≤ 10^{9}$ ----- Sample Input 1 ------ 8 1 2 3 5 8 13 21 34 ----- Sample Output 1 ------ 1 4 10 58 578 20098 5236738 24641495 ----- explanation 1 ------ Note that: - $f(1) = f(1 \oplus 1) + 1 = f(0) + 1 = 1$ - $f(2) = f(2 \oplus 1) + 1 = f(3) + 1 = (f(3 \oplus 3) + 1) + 1 = (f(0) + 1) + 1 = 2$ - $f(3) = f(3 \oplus 3) + 1 = f(0) + 1 = 1$ - Test case-1: $\sum^{2^{1}-1}_{i=1} f(i) = f(1) = 1$. So answer is $1 \text{ mod } 998244353 = 1$. - Test case-2: $\sum^{2^{2}-1}_{i=1} f(i) = f(1) + f(2) + f(3) = 1 + 2 + 1 = 4$. So answer is $4 \text{ mod } 998244353 = 4$.
t = int(input()) mod = 998244353 while t: t = t - 1 n = int(input()) if n == 1: print(1) elif n == 2: print(4) else: if n % 2 == 0: tot = (pow(2, n, mod) - 1) % mod pal = 2 * (pow(2, n // 2, mod) - 1) % mod nonpal = pow(2, n - 1, mod) % mod ans = (2 * tot + nonpal - 2 * pal) % mod else: tot = (pow(2, n, mod) - 1) % mod pal = (3 * pow(2, (n - 1) // 2, mod) - 2) % mod nonpal = pow(2, n - 1, mod) % mod ans = (2 * tot + nonpal - 2 * pal) % mod print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
We define f(x)=\begin{cases} f(x \oplus reverse(x))+1 & \text{if } x \neq 0 \\ 0 & \text{otherwise} \end{cases} Here, \oplus denotes the [bitwise XOR operation] and reverse is a function that takes a postive integer, reverses its binary representation (without any leading zeros) and returns the resulting number. For example reverse(2)=1, reverse(6)=3, reverse(7)=7 Given an integer N, find out the value of \sum^{2^{N}-1}_{i=1} f(i) modulo 998244353 or claim that there exists a positive integer x < 2^{N} for which f is undefined. ------ Input Format ------ - The first line of input contains a single integer T - the number of test cases. The description of T test cases follows. - The first and only line of each test case contains a single integer N. ------ Output Format ------ - For each test case output a single line containing one integer : - -1 if there exists a positive integer x such that x < 2^{N} and f(x) is undefined - \sum^{2^{N}-1}_{i=1} f(i) modulo 998244353 otherwise ------ Constraints ------ $1 ≤ T ≤ 3 \cdot 10^{5}$ $1 ≤ N ≤ 10^{9}$ ----- Sample Input 1 ------ 8 1 2 3 5 8 13 21 34 ----- Sample Output 1 ------ 1 4 10 58 578 20098 5236738 24641495 ----- explanation 1 ------ Note that: - $f(1) = f(1 \oplus 1) + 1 = f(0) + 1 = 1$ - $f(2) = f(2 \oplus 1) + 1 = f(3) + 1 = (f(3 \oplus 3) + 1) + 1 = (f(0) + 1) + 1 = 2$ - $f(3) = f(3 \oplus 3) + 1 = f(0) + 1 = 1$ - Test case-1: $\sum^{2^{1}-1}_{i=1} f(i) = f(1) = 1$. So answer is $1 \text{ mod } 998244353 = 1$. - Test case-2: $\sum^{2^{2}-1}_{i=1} f(i) = f(1) + f(2) + f(3) = 1 + 2 + 1 = 4$. So answer is $4 \text{ mod } 998244353 = 4$.
from sys import setrecursionlimit, stdin input = stdin.readline mod = 998244353 def add(a, b): return (a % mod + b % mod) % mod def mul(a, b): return a % mod * (b % mod) % mod def sub(a, b): return (a - b + mod) % mod def answer(): if n == 1: return 1 even = pow(2, n - 1, mod) ans = mul(2, even) ans = sub(ans, 2) if n & 1: pal = mul(2, sub(pow(2, n // 2, mod), 1)) pal = add(pal, pow(2, n // 2, mod)) else: pal = mul(2, sub(pow(2, n // 2, mod), 1)) ans = add(ans, pal) odd = sub(pow(2, n, mod), even) leftodd = sub(odd, pal) ans = add(ans, mul(3, leftodd)) return ans for T in range(int(input())): n = int(input()) print(answer())
ASSIGN VAR VAR ASSIGN VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is baking a large cake! The cake consists of $N$ different ingredients numbered $1$ through $N$. Chef can choose how much of each ingredient to use in his cake recipe; let's denote the amount of the $i$-th ingredient used in the cake by $g_{i}$. Chef can only measure ingredients in fixed whole units, so the amounts of all ingredients must be integers. In order to keep the cake inexpensive (and, of course, use each ingredient from the recipe), the chosen amounts of ingredients have to satisfy the condition $1 ≤ g_{i} ≤ K$ (for each $1 ≤ i ≤ N$). The *taste* of the resulting cake is computed as the bitwise XOR of the amounts of all ingredients, i.e. $g_{1} \oplus g_{2} \oplus \dots \oplus g_{N}$. For example, if $N=3$ and $g = [1, 2, 5]$, the taste of the cake is equal to $1 \oplus 2 \oplus 5 = 6$. Please help Chef and find one way to choose the amounts of all ingredients such that the taste of the cake is maximum possible. ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. The first and only line of each test case contains two space-separated integers $N$ and $K$. ------ Output ------ For each test case, print a single line containing $N$ space-separated integers $g_{1}, g_{2}, \dots, g_{N}$ — the amounts of ingredients $1, 2, \dots, N$. ------ Constraints ------ $1 ≤ T ≤ 40$ $1 ≤ N ≤ 10^{4}$ $1 ≤ K ≤ 10^{9}$ ----- Sample Input 1 ------ 2 3 5 4 3 ----- Sample Output 1 ------ 5 1 3 1 2 3 3 ----- explanation 1 ------ Example case 1: The maximum possible taste of the cake is $5 \oplus 1 \oplus 3 = 7$. Example case 2: The maximum possible taste is $1 \oplus 2 \oplus 3 \oplus 3 = 3$.
import sys t = int(input()) for _ in range(t): n, k = input().strip().split(" ") n, k = [int(n), int(k)] i = 0 while 2**i <= k: i += 1 ka = 2**i - 1 if k == 1: for _ in range(n): print(k, end=" ") print() continue elif k == 2 and n % 2 != 0: for _ in range(n): print(k, end=" ") print() continue if n % 2 == 0: i = i - 1 a1 = 2**i a2 = a1 - 1 print(a2, end=" ") print(a1, end=" ") for _ in range(n - 2): print(k, end=" ") elif n == 1: print(k, end="") else: i = i - 1 a1 = 2**i if k == a1: print(k, 1, k - 2, end=" ") for _ in range(n - 3): print(k, end=" ") else: print(a1 + 1, 1, a1 - 1, end=" ") for _ in range(n - 3): print(k, end=" ") print()
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is baking a large cake! The cake consists of $N$ different ingredients numbered $1$ through $N$. Chef can choose how much of each ingredient to use in his cake recipe; let's denote the amount of the $i$-th ingredient used in the cake by $g_{i}$. Chef can only measure ingredients in fixed whole units, so the amounts of all ingredients must be integers. In order to keep the cake inexpensive (and, of course, use each ingredient from the recipe), the chosen amounts of ingredients have to satisfy the condition $1 ≤ g_{i} ≤ K$ (for each $1 ≤ i ≤ N$). The *taste* of the resulting cake is computed as the bitwise XOR of the amounts of all ingredients, i.e. $g_{1} \oplus g_{2} \oplus \dots \oplus g_{N}$. For example, if $N=3$ and $g = [1, 2, 5]$, the taste of the cake is equal to $1 \oplus 2 \oplus 5 = 6$. Please help Chef and find one way to choose the amounts of all ingredients such that the taste of the cake is maximum possible. ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. The first and only line of each test case contains two space-separated integers $N$ and $K$. ------ Output ------ For each test case, print a single line containing $N$ space-separated integers $g_{1}, g_{2}, \dots, g_{N}$ — the amounts of ingredients $1, 2, \dots, N$. ------ Constraints ------ $1 ≤ T ≤ 40$ $1 ≤ N ≤ 10^{4}$ $1 ≤ K ≤ 10^{9}$ ----- Sample Input 1 ------ 2 3 5 4 3 ----- Sample Output 1 ------ 5 1 3 1 2 3 3 ----- explanation 1 ------ Example case 1: The maximum possible taste of the cake is $5 \oplus 1 \oplus 3 = 7$. Example case 2: The maximum possible taste is $1 \oplus 2 \oplus 3 \oplus 3 = 3$.
for _ in range(int(input())): n, k = [int(x) for x in input().split()] if n == 1: print(k) continue if k == 1: ans = [1] * n print(*ans) continue if k == 2: if n & 1: ans = [2] for i in range(n - 1): ans.append(1) print(*ans) continue ans = [2] for i in range(n - 1): ans.append(1) print(*ans) continue st = list("{0:b}".format(k)) w = len(st) s = [] for i in range(w): if st[i] == "0": s.append("1") else: s.append("0") if s.count("1") == 0: if n & 1: v = [k] * n print(*v) continue s1 = "1" + "0" * (w - 1) s2 = "1" * (w - 1) s1 = int(s1, 2) s2 = int(s2, 2) v = [k] * (n - 2) v.append(s1) v.append(s2) print(*v) continue for i in range(w): if s[i] == "1": break s = "".join(str(e) for e in s) s = s[i:] s1 = "1" + "0" * (w - i - 1) if s1 == s: s1 = "1" + "1" + "0" * (w - i - 2) s2 = "" for i in range(len(s1)): if s[i] == "1": if s1[i] == "1": s2 += "0" else: s2 += "1" elif s1[i] == "1": s2 += "1" else: s2 += "0" s = int(s, 2) s1 = int(s1, 2) s2 = int(s2, 2) if n & 1: ans = [k] * (n - 2) ans.append(s1) ans.append(s2) print(*ans) continue ans = [k] * (n - 1) ans.append(s) print(*ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR STRING NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR STRING VAR STRING VAR STRING IF VAR VAR STRING VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is baking a large cake! The cake consists of $N$ different ingredients numbered $1$ through $N$. Chef can choose how much of each ingredient to use in his cake recipe; let's denote the amount of the $i$-th ingredient used in the cake by $g_{i}$. Chef can only measure ingredients in fixed whole units, so the amounts of all ingredients must be integers. In order to keep the cake inexpensive (and, of course, use each ingredient from the recipe), the chosen amounts of ingredients have to satisfy the condition $1 ≤ g_{i} ≤ K$ (for each $1 ≤ i ≤ N$). The *taste* of the resulting cake is computed as the bitwise XOR of the amounts of all ingredients, i.e. $g_{1} \oplus g_{2} \oplus \dots \oplus g_{N}$. For example, if $N=3$ and $g = [1, 2, 5]$, the taste of the cake is equal to $1 \oplus 2 \oplus 5 = 6$. Please help Chef and find one way to choose the amounts of all ingredients such that the taste of the cake is maximum possible. ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. The first and only line of each test case contains two space-separated integers $N$ and $K$. ------ Output ------ For each test case, print a single line containing $N$ space-separated integers $g_{1}, g_{2}, \dots, g_{N}$ — the amounts of ingredients $1, 2, \dots, N$. ------ Constraints ------ $1 ≤ T ≤ 40$ $1 ≤ N ≤ 10^{4}$ $1 ≤ K ≤ 10^{9}$ ----- Sample Input 1 ------ 2 3 5 4 3 ----- Sample Output 1 ------ 5 1 3 1 2 3 3 ----- explanation 1 ------ Example case 1: The maximum possible taste of the cake is $5 \oplus 1 \oplus 3 = 7$. Example case 2: The maximum possible taste is $1 \oplus 2 \oplus 3 \oplus 3 = 3$.
t = int(input()) for ijk in range(0, t): n, k = map(int, input().strip().split()) bit = [] req = [] c = 0 length = 0 f = int(k) while k != 0: w = k % 2 length += 1 bit.append(w) k = k // 2 if w == 0: c += 1 req.append(1) else: req.append(0) if c == 0: if f > 1: if n % 2 == 0: if n == 2: print(f - 1, 1) else: print(f, 1, 2, 3, "1 " * (n - 4)) else: print(f, "1 " * (n - 1)) else: print("1 " * n) elif n % 2 == 0: num = 0 for i in range(0, length): if bit[i] == 0: num += pow(2, i) print(f, num, "1 " * (n - 2)) elif n == 1: print(f) elif c == 1: if f == 2: print(f, "1 " * (n - 1)) else: n1 = n2 = 0 for i in range(0, length): if bit[i] == 0: n1 += pow(2, i) break if i == 0: n2 += pow(2, i + 1) n1 += pow(2, i + 1) else: n2 += pow(2, i - 1) n1 += pow(2, i - 1) print(n1, n2, f, (n - 3) * "1 ") else: y = 0 n1 = n2 = 0 for i in range(0, length): if bit[i] == 0: if y == 0: n1 += pow(2, i) y = 1 else: n2 += pow(2, i) y = 0 print(f, n1, n2, "1 " * (n - 3))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER BIN_OP STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP STRING BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP STRING BIN_OP VAR NUMBER
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is baking a large cake! The cake consists of $N$ different ingredients numbered $1$ through $N$. Chef can choose how much of each ingredient to use in his cake recipe; let's denote the amount of the $i$-th ingredient used in the cake by $g_{i}$. Chef can only measure ingredients in fixed whole units, so the amounts of all ingredients must be integers. In order to keep the cake inexpensive (and, of course, use each ingredient from the recipe), the chosen amounts of ingredients have to satisfy the condition $1 ≤ g_{i} ≤ K$ (for each $1 ≤ i ≤ N$). The *taste* of the resulting cake is computed as the bitwise XOR of the amounts of all ingredients, i.e. $g_{1} \oplus g_{2} \oplus \dots \oplus g_{N}$. For example, if $N=3$ and $g = [1, 2, 5]$, the taste of the cake is equal to $1 \oplus 2 \oplus 5 = 6$. Please help Chef and find one way to choose the amounts of all ingredients such that the taste of the cake is maximum possible. ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. The first and only line of each test case contains two space-separated integers $N$ and $K$. ------ Output ------ For each test case, print a single line containing $N$ space-separated integers $g_{1}, g_{2}, \dots, g_{N}$ — the amounts of ingredients $1, 2, \dots, N$. ------ Constraints ------ $1 ≤ T ≤ 40$ $1 ≤ N ≤ 10^{4}$ $1 ≤ K ≤ 10^{9}$ ----- Sample Input 1 ------ 2 3 5 4 3 ----- Sample Output 1 ------ 5 1 3 1 2 3 3 ----- explanation 1 ------ Example case 1: The maximum possible taste of the cake is $5 \oplus 1 \oplus 3 = 7$. Example case 2: The maximum possible taste is $1 \oplus 2 \oplus 3 \oplus 3 = 3$.
t = int(input()) for _ in range(t): n, k = map(int, input().split()) ans = [] if n % 2 == 0: bo = "" c = bin(k)[2:] for i in c: if i == "0": bo += "1" else: bo += "0" d = int(bo, 2) for i in range(n - 2): ans.append(k) if d == 0: k1 = "1" + "0" * (len(c) - 1) k2 = "0" + "1" * (len(c) - 1) ans.append(int(k1, 2)) ans.append(int(k2, 2)) else: ans.append(d) ans.append(k) else: bo = "" c = bin(k)[2:] for i in c: if i == "0": bo += "1" else: bo += "0" d = int(bo, 2) if d == 0: ans.append(k) ans.append(k) ans.append(k) else: fa = "" for i in range(1, len(c)): if c[i] == "1": fa += "1" else: fa += "0" k2 = "0" + "1" * (len(c) - 1) ans.append(k) if int(fa, 2) != 0: ans.append(int(fa, 2)) ans.append(int(k2, 2)) else: k2 = "0" + "1" * (len(c) - 2) + "0" ans.append(int(k2, 2)) ans.append(1) for i in range(n - 3): ans.append(k) if n == 1: ans = [k] elif n % 2 != 0 and k == 2: ans = [k] * n elif n % 2 == 0 and k == 1: ans = [1] * n print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF VAR STRING VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP STRING BIN_OP STRING BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP STRING BIN_OP STRING BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF VAR STRING VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR STRING VAR STRING ASSIGN VAR BIN_OP STRING BIN_OP STRING BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP FUNC_CALL VAR VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR LIST VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is baking a large cake! The cake consists of $N$ different ingredients numbered $1$ through $N$. Chef can choose how much of each ingredient to use in his cake recipe; let's denote the amount of the $i$-th ingredient used in the cake by $g_{i}$. Chef can only measure ingredients in fixed whole units, so the amounts of all ingredients must be integers. In order to keep the cake inexpensive (and, of course, use each ingredient from the recipe), the chosen amounts of ingredients have to satisfy the condition $1 ≤ g_{i} ≤ K$ (for each $1 ≤ i ≤ N$). The *taste* of the resulting cake is computed as the bitwise XOR of the amounts of all ingredients, i.e. $g_{1} \oplus g_{2} \oplus \dots \oplus g_{N}$. For example, if $N=3$ and $g = [1, 2, 5]$, the taste of the cake is equal to $1 \oplus 2 \oplus 5 = 6$. Please help Chef and find one way to choose the amounts of all ingredients such that the taste of the cake is maximum possible. ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. The first and only line of each test case contains two space-separated integers $N$ and $K$. ------ Output ------ For each test case, print a single line containing $N$ space-separated integers $g_{1}, g_{2}, \dots, g_{N}$ — the amounts of ingredients $1, 2, \dots, N$. ------ Constraints ------ $1 ≤ T ≤ 40$ $1 ≤ N ≤ 10^{4}$ $1 ≤ K ≤ 10^{9}$ ----- Sample Input 1 ------ 2 3 5 4 3 ----- Sample Output 1 ------ 5 1 3 1 2 3 3 ----- explanation 1 ------ Example case 1: The maximum possible taste of the cake is $5 \oplus 1 \oplus 3 = 7$. Example case 2: The maximum possible taste is $1 \oplus 2 \oplus 3 \oplus 3 = 3$.
for _ in range(int(input())): n, k = map(int, input().split()) if n == 1: print(k) elif k == 1: for _ in range(n): print(1, end=" ") print() elif n % 2 != 0 and k == 2: for _ in range(n - 1): print(1, end=" ") print(2) else: ans = 1 while ans <= k: ans *= 2 ans -= 1 if k != ans: if n % 2 == 0: b = k ^ ans print(k, b, end=" ") for _ in range(n - 2): print(1, end=" ") print() else: b = k ^ ans ^ 1 if b != 0: print(k, b, 1, end=" ") for _ in range(n - 3): print(1, end=" ") print() else: b = k ^ ans ^ 2 print(k, b, 2, end=" ") for _ in range(n - 3): print(1, end=" ") print() elif n % 2 != 0: print(k, end=" ") for _ in range(n - 1): print(1, end=" ") print() elif n == 2: print(k - 1, 1) elif n >= 4: print(k, 1, 2, 3, end=" ") for _ in range(n - 4): print(1, end=" ") print()
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR
You are given a simple code of a function and you would like to know what it will return. F(N, K, Answer, Operator, A[N]) returns int; begin for i=1..K do for j=1..N do Answer=(Answer operator A_{j}) return Answer end Here N, K, Answer and the value returned by the function F are integers; A is an array of N integers numbered from 1 to N; Operator can be one of the binary operators XOR, AND or OR. If you are not familiar with these terms then better have a look at following articles: XOR, OR, AND. ------ Input ------ The first line of input contains an integer T - the number of test cases in file. Description of each test case consists of three lines. The first one contains three integers N, K and initial Answer. Array A is given in the second line and Operator is situated on the third one. Operators are given as strings, of capital letters. It is guaranteed that there will be no whitespaces before or after Operator. ------ Output ------ Output one line for each test case - the value that is returned by described function with given arguments. ------ Constraints ------ $1≤T≤100 $$1≤N≤1000 $0≤Answer, K, A_{i}≤10^{9} Operator is one of these: "AND", "XOR", "OR". ----- Sample Input 1 ------ 3 3 1 0 1 2 3 XOR 3 1 0 1 2 3 AND 3 1 0 1 2 3 OR ----- Sample Output 1 ------ 0 0 3 ----- explanation 1 ------ 0 xor 1 xor 2 xor 3 = 0 0 and 1 and 2 and 3 = 0 0 or 1 or 2 or 3 = 3
def solve(): n, k, answer = map(int, input().split()) array = list(map(int, input().split())) operator = input() if k == 0: print(answer) else: if operator[0] == "X": if k % 2 == 0: pass else: for i in array: answer = answer ^ i elif operator[0] == "A": for i in array: answer = answer & i else: for i in array: answer = answer | i print(answer) t = int(input()) while t != 0: solve() t -= 1
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER STRING IF BIN_OP VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER STRING FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
You are given a simple code of a function and you would like to know what it will return. F(N, K, Answer, Operator, A[N]) returns int; begin for i=1..K do for j=1..N do Answer=(Answer operator A_{j}) return Answer end Here N, K, Answer and the value returned by the function F are integers; A is an array of N integers numbered from 1 to N; Operator can be one of the binary operators XOR, AND or OR. If you are not familiar with these terms then better have a look at following articles: XOR, OR, AND. ------ Input ------ The first line of input contains an integer T - the number of test cases in file. Description of each test case consists of three lines. The first one contains three integers N, K and initial Answer. Array A is given in the second line and Operator is situated on the third one. Operators are given as strings, of capital letters. It is guaranteed that there will be no whitespaces before or after Operator. ------ Output ------ Output one line for each test case - the value that is returned by described function with given arguments. ------ Constraints ------ $1≤T≤100 $$1≤N≤1000 $0≤Answer, K, A_{i}≤10^{9} Operator is one of these: "AND", "XOR", "OR". ----- Sample Input 1 ------ 3 3 1 0 1 2 3 XOR 3 1 0 1 2 3 AND 3 1 0 1 2 3 OR ----- Sample Output 1 ------ 0 0 3 ----- explanation 1 ------ 0 xor 1 xor 2 xor 3 = 0 0 and 1 and 2 and 3 = 0 0 or 1 or 2 or 3 = 3
t = int(input()) for z in range(t): N, K, Answer = map(int, input().split()) A = map(int, input().split()) operator = input().strip() if K: for a in A: if operator == "OR": Answer = Answer | a elif operator == "XOR" and K % 2: Answer = Answer ^ a elif operator == "AND": Answer = Answer & a print(Answer)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR FOR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
You are given a simple code of a function and you would like to know what it will return. F(N, K, Answer, Operator, A[N]) returns int; begin for i=1..K do for j=1..N do Answer=(Answer operator A_{j}) return Answer end Here N, K, Answer and the value returned by the function F are integers; A is an array of N integers numbered from 1 to N; Operator can be one of the binary operators XOR, AND or OR. If you are not familiar with these terms then better have a look at following articles: XOR, OR, AND. ------ Input ------ The first line of input contains an integer T - the number of test cases in file. Description of each test case consists of three lines. The first one contains three integers N, K and initial Answer. Array A is given in the second line and Operator is situated on the third one. Operators are given as strings, of capital letters. It is guaranteed that there will be no whitespaces before or after Operator. ------ Output ------ Output one line for each test case - the value that is returned by described function with given arguments. ------ Constraints ------ $1≤T≤100 $$1≤N≤1000 $0≤Answer, K, A_{i}≤10^{9} Operator is one of these: "AND", "XOR", "OR". ----- Sample Input 1 ------ 3 3 1 0 1 2 3 XOR 3 1 0 1 2 3 AND 3 1 0 1 2 3 OR ----- Sample Output 1 ------ 0 0 3 ----- explanation 1 ------ 0 xor 1 xor 2 xor 3 = 0 0 and 1 and 2 and 3 = 0 0 or 1 or 2 or 3 = 3
def fnc(n, k, answer, s, a): for i in range(k): for j in range(n): if s == "XOR": answer ^= a[j] elif s == "OR": answer |= a[j] else: answer &= a[j] return answer t = int(input()) for T in range(t): n, k, answer = [int(x) for x in input().split()] a = [int(x) for x in input().split()] s = input().strip() if s == "XOR": k %= 2 else: k = min(k, 1) print(fnc(n, k, answer, s, a))
FUNC_DEF FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR VAR IF VAR STRING VAR VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR
You are given a simple code of a function and you would like to know what it will return. F(N, K, Answer, Operator, A[N]) returns int; begin for i=1..K do for j=1..N do Answer=(Answer operator A_{j}) return Answer end Here N, K, Answer and the value returned by the function F are integers; A is an array of N integers numbered from 1 to N; Operator can be one of the binary operators XOR, AND or OR. If you are not familiar with these terms then better have a look at following articles: XOR, OR, AND. ------ Input ------ The first line of input contains an integer T - the number of test cases in file. Description of each test case consists of three lines. The first one contains three integers N, K and initial Answer. Array A is given in the second line and Operator is situated on the third one. Operators are given as strings, of capital letters. It is guaranteed that there will be no whitespaces before or after Operator. ------ Output ------ Output one line for each test case - the value that is returned by described function with given arguments. ------ Constraints ------ $1≤T≤100 $$1≤N≤1000 $0≤Answer, K, A_{i}≤10^{9} Operator is one of these: "AND", "XOR", "OR". ----- Sample Input 1 ------ 3 3 1 0 1 2 3 XOR 3 1 0 1 2 3 AND 3 1 0 1 2 3 OR ----- Sample Output 1 ------ 0 0 3 ----- explanation 1 ------ 0 xor 1 xor 2 xor 3 = 0 0 and 1 and 2 and 3 = 0 0 or 1 or 2 or 3 = 3
test = int(input()) for t in range(test): a, b, answer = map(int, input().strip().split()) seanswerond = list(map(int, input().strip().split())) operation = input().strip() if b == 0 or b % 2 == 0 and operation == "XOR": print(answer) else: for i in seanswerond: if operation == "XOR": answer = answer ^ i elif operation == "OR": answer = answer | i else: answer = answer & i print(answer)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
You are given a simple code of a function and you would like to know what it will return. F(N, K, Answer, Operator, A[N]) returns int; begin for i=1..K do for j=1..N do Answer=(Answer operator A_{j}) return Answer end Here N, K, Answer and the value returned by the function F are integers; A is an array of N integers numbered from 1 to N; Operator can be one of the binary operators XOR, AND or OR. If you are not familiar with these terms then better have a look at following articles: XOR, OR, AND. ------ Input ------ The first line of input contains an integer T - the number of test cases in file. Description of each test case consists of three lines. The first one contains three integers N, K and initial Answer. Array A is given in the second line and Operator is situated on the third one. Operators are given as strings, of capital letters. It is guaranteed that there will be no whitespaces before or after Operator. ------ Output ------ Output one line for each test case - the value that is returned by described function with given arguments. ------ Constraints ------ $1≤T≤100 $$1≤N≤1000 $0≤Answer, K, A_{i}≤10^{9} Operator is one of these: "AND", "XOR", "OR". ----- Sample Input 1 ------ 3 3 1 0 1 2 3 XOR 3 1 0 1 2 3 AND 3 1 0 1 2 3 OR ----- Sample Output 1 ------ 0 0 3 ----- explanation 1 ------ 0 xor 1 xor 2 xor 3 = 0 0 and 1 and 2 and 3 = 0 0 or 1 or 2 or 3 = 3
for _ in range(int(input())): N, K, Ans = map(int, input().split()) A = list(map(int, input().split())) oper = input() Ans_0 = Ans oper = oper.strip() if K % 2 == 0: m = 2 else: m = 1 if oper == "AND": for j in range(m): for i in range(N): Ans = Ans & A[i] elif oper == "OR": for j in range(m): for i in range(N): Ans = Ans | A[i] elif oper == "XOR": for j in range(m): for i in range(N): Ans = Ans ^ A[i] if K != 0: print(Ans) else: print(Ans_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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR STRING FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR STRING FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR STRING FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You are given a simple code of a function and you would like to know what it will return. F(N, K, Answer, Operator, A[N]) returns int; begin for i=1..K do for j=1..N do Answer=(Answer operator A_{j}) return Answer end Here N, K, Answer and the value returned by the function F are integers; A is an array of N integers numbered from 1 to N; Operator can be one of the binary operators XOR, AND or OR. If you are not familiar with these terms then better have a look at following articles: XOR, OR, AND. ------ Input ------ The first line of input contains an integer T - the number of test cases in file. Description of each test case consists of three lines. The first one contains three integers N, K and initial Answer. Array A is given in the second line and Operator is situated on the third one. Operators are given as strings, of capital letters. It is guaranteed that there will be no whitespaces before or after Operator. ------ Output ------ Output one line for each test case - the value that is returned by described function with given arguments. ------ Constraints ------ $1≤T≤100 $$1≤N≤1000 $0≤Answer, K, A_{i}≤10^{9} Operator is one of these: "AND", "XOR", "OR". ----- Sample Input 1 ------ 3 3 1 0 1 2 3 XOR 3 1 0 1 2 3 AND 3 1 0 1 2 3 OR ----- Sample Output 1 ------ 0 0 3 ----- explanation 1 ------ 0 xor 1 xor 2 xor 3 = 0 0 and 1 and 2 and 3 = 0 0 or 1 or 2 or 3 = 3
for _ in range(int(input())): n, k, answer = map(int, input().split()) a = list(map(int, input().split())) o = input() if k == 0: print(answer) else: if o[0] == "X": if k % 2: for i in range(n): answer ^= a[i] elif o[0] == "O": for i in range(n): answer |= a[i] else: for i in range(n): answer &= a[i] print(answer)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER STRING IF BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a simple code of a function and you would like to know what it will return. F(N, K, Answer, Operator, A[N]) returns int; begin for i=1..K do for j=1..N do Answer=(Answer operator A_{j}) return Answer end Here N, K, Answer and the value returned by the function F are integers; A is an array of N integers numbered from 1 to N; Operator can be one of the binary operators XOR, AND or OR. If you are not familiar with these terms then better have a look at following articles: XOR, OR, AND. ------ Input ------ The first line of input contains an integer T - the number of test cases in file. Description of each test case consists of three lines. The first one contains three integers N, K and initial Answer. Array A is given in the second line and Operator is situated on the third one. Operators are given as strings, of capital letters. It is guaranteed that there will be no whitespaces before or after Operator. ------ Output ------ Output one line for each test case - the value that is returned by described function with given arguments. ------ Constraints ------ $1≤T≤100 $$1≤N≤1000 $0≤Answer, K, A_{i}≤10^{9} Operator is one of these: "AND", "XOR", "OR". ----- Sample Input 1 ------ 3 3 1 0 1 2 3 XOR 3 1 0 1 2 3 AND 3 1 0 1 2 3 OR ----- Sample Output 1 ------ 0 0 3 ----- explanation 1 ------ 0 xor 1 xor 2 xor 3 = 0 0 and 1 and 2 and 3 = 0 0 or 1 or 2 or 3 = 3
import sys def input(): return sys.stdin.readline().strip() def iinput(): return int(input()) def rinput(): return map(int, sys.stdin.readline().strip().split()) def get_list(): return list(map(int, sys.stdin.readline().strip().split())) for _ in range(iinput()): n, k, ans = rinput() a = get_list() b = input() if k == 0: print(ans) else: if b[0] == "A": for i in a: ans &= i elif b[0] == "O": for i in a: ans |= i elif k % 2: for i in a: ans ^= i print(ans)
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER STRING FOR VAR VAR VAR VAR IF VAR NUMBER STRING FOR VAR VAR VAR VAR IF BIN_OP VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a simple code of a function and you would like to know what it will return. F(N, K, Answer, Operator, A[N]) returns int; begin for i=1..K do for j=1..N do Answer=(Answer operator A_{j}) return Answer end Here N, K, Answer and the value returned by the function F are integers; A is an array of N integers numbered from 1 to N; Operator can be one of the binary operators XOR, AND or OR. If you are not familiar with these terms then better have a look at following articles: XOR, OR, AND. ------ Input ------ The first line of input contains an integer T - the number of test cases in file. Description of each test case consists of three lines. The first one contains three integers N, K and initial Answer. Array A is given in the second line and Operator is situated on the third one. Operators are given as strings, of capital letters. It is guaranteed that there will be no whitespaces before or after Operator. ------ Output ------ Output one line for each test case - the value that is returned by described function with given arguments. ------ Constraints ------ $1≤T≤100 $$1≤N≤1000 $0≤Answer, K, A_{i}≤10^{9} Operator is one of these: "AND", "XOR", "OR". ----- Sample Input 1 ------ 3 3 1 0 1 2 3 XOR 3 1 0 1 2 3 AND 3 1 0 1 2 3 OR ----- Sample Output 1 ------ 0 0 3 ----- explanation 1 ------ 0 xor 1 xor 2 xor 3 = 0 0 and 1 and 2 and 3 = 0 0 or 1 or 2 or 3 = 3
for _ in range(int(input())): n, k, a = map(int, input().split()) arr = map(int, input().split()) oper = input() if not k: print(a) else: if oper[0] == "X": if k % 2 == 0: pass else: for j in arr: a = a ^ j elif oper[0] == "A": for j in arr: a = a & j else: for j in arr: a = a | j 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER STRING IF BIN_OP VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER STRING FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
You are given a simple code of a function and you would like to know what it will return. F(N, K, Answer, Operator, A[N]) returns int; begin for i=1..K do for j=1..N do Answer=(Answer operator A_{j}) return Answer end Here N, K, Answer and the value returned by the function F are integers; A is an array of N integers numbered from 1 to N; Operator can be one of the binary operators XOR, AND or OR. If you are not familiar with these terms then better have a look at following articles: XOR, OR, AND. ------ Input ------ The first line of input contains an integer T - the number of test cases in file. Description of each test case consists of three lines. The first one contains three integers N, K and initial Answer. Array A is given in the second line and Operator is situated on the third one. Operators are given as strings, of capital letters. It is guaranteed that there will be no whitespaces before or after Operator. ------ Output ------ Output one line for each test case - the value that is returned by described function with given arguments. ------ Constraints ------ $1≤T≤100 $$1≤N≤1000 $0≤Answer, K, A_{i}≤10^{9} Operator is one of these: "AND", "XOR", "OR". ----- Sample Input 1 ------ 3 3 1 0 1 2 3 XOR 3 1 0 1 2 3 AND 3 1 0 1 2 3 OR ----- Sample Output 1 ------ 0 0 3 ----- explanation 1 ------ 0 xor 1 xor 2 xor 3 = 0 0 and 1 and 2 and 3 = 0 0 or 1 or 2 or 3 = 3
testcases = int(input()) while testcases != 0: N, K, answer = list(map(int, input().split())) inputArray = list(map(int, input().split())) operat = input() if K == 0: print(answer) elif K % 2 == 0 and operat[0] == "X": print(answer) else: if operat[0] == "X": for j in range(N): answer ^= inputArray[j] elif operat[0] == "A": for j in range(N): answer &= inputArray[j] else: for j in range(N): answer |= inputArray[j] print(answer) testcases -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
You are given a simple code of a function and you would like to know what it will return. F(N, K, Answer, Operator, A[N]) returns int; begin for i=1..K do for j=1..N do Answer=(Answer operator A_{j}) return Answer end Here N, K, Answer and the value returned by the function F are integers; A is an array of N integers numbered from 1 to N; Operator can be one of the binary operators XOR, AND or OR. If you are not familiar with these terms then better have a look at following articles: XOR, OR, AND. ------ Input ------ The first line of input contains an integer T - the number of test cases in file. Description of each test case consists of three lines. The first one contains three integers N, K and initial Answer. Array A is given in the second line and Operator is situated on the third one. Operators are given as strings, of capital letters. It is guaranteed that there will be no whitespaces before or after Operator. ------ Output ------ Output one line for each test case - the value that is returned by described function with given arguments. ------ Constraints ------ $1≤T≤100 $$1≤N≤1000 $0≤Answer, K, A_{i}≤10^{9} Operator is one of these: "AND", "XOR", "OR". ----- Sample Input 1 ------ 3 3 1 0 1 2 3 XOR 3 1 0 1 2 3 AND 3 1 0 1 2 3 OR ----- Sample Output 1 ------ 0 0 3 ----- explanation 1 ------ 0 xor 1 xor 2 xor 3 = 0 0 and 1 and 2 and 3 = 0 0 or 1 or 2 or 3 = 3
for tc in range(int(input().strip())): N, K, Ans = map(int, input().strip().split()) A = [int(x) for x in input().strip().split()] op = input().strip() for i in A: if K > 0: if op == "AND": Ans = Ans & i elif op == "OR": Ans = Ans | i elif K & 1 == 1: Ans = Ans ^ i print(Ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF VAR NUMBER IF VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
You are given a simple code of a function and you would like to know what it will return. F(N, K, Answer, Operator, A[N]) returns int; begin for i=1..K do for j=1..N do Answer=(Answer operator A_{j}) return Answer end Here N, K, Answer and the value returned by the function F are integers; A is an array of N integers numbered from 1 to N; Operator can be one of the binary operators XOR, AND or OR. If you are not familiar with these terms then better have a look at following articles: XOR, OR, AND. ------ Input ------ The first line of input contains an integer T - the number of test cases in file. Description of each test case consists of three lines. The first one contains three integers N, K and initial Answer. Array A is given in the second line and Operator is situated on the third one. Operators are given as strings, of capital letters. It is guaranteed that there will be no whitespaces before or after Operator. ------ Output ------ Output one line for each test case - the value that is returned by described function with given arguments. ------ Constraints ------ $1≤T≤100 $$1≤N≤1000 $0≤Answer, K, A_{i}≤10^{9} Operator is one of these: "AND", "XOR", "OR". ----- Sample Input 1 ------ 3 3 1 0 1 2 3 XOR 3 1 0 1 2 3 AND 3 1 0 1 2 3 OR ----- Sample Output 1 ------ 0 0 3 ----- explanation 1 ------ 0 xor 1 xor 2 xor 3 = 0 0 and 1 and 2 and 3 = 0 0 or 1 or 2 or 3 = 3
t = int(input()) while t: n, k, ans = map(int, input().strip().split()) a = list(map(int, input().strip().split())) operator = input().strip() if operator == "XOR": if k > 0: if k % 2 == 0: ans = ans ^ 0 else: for j in range(n): ans = ans ^ a[j] elif operator == "AND": if k > 0: for j in range(n): ans = ans & a[j] elif operator == "OR": if k > 0: for j in range(n): ans = ans | a[j] print(ans) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
You are given a simple code of a function and you would like to know what it will return. F(N, K, Answer, Operator, A[N]) returns int; begin for i=1..K do for j=1..N do Answer=(Answer operator A_{j}) return Answer end Here N, K, Answer and the value returned by the function F are integers; A is an array of N integers numbered from 1 to N; Operator can be one of the binary operators XOR, AND or OR. If you are not familiar with these terms then better have a look at following articles: XOR, OR, AND. ------ Input ------ The first line of input contains an integer T - the number of test cases in file. Description of each test case consists of three lines. The first one contains three integers N, K and initial Answer. Array A is given in the second line and Operator is situated on the third one. Operators are given as strings, of capital letters. It is guaranteed that there will be no whitespaces before or after Operator. ------ Output ------ Output one line for each test case - the value that is returned by described function with given arguments. ------ Constraints ------ $1≤T≤100 $$1≤N≤1000 $0≤Answer, K, A_{i}≤10^{9} Operator is one of these: "AND", "XOR", "OR". ----- Sample Input 1 ------ 3 3 1 0 1 2 3 XOR 3 1 0 1 2 3 AND 3 1 0 1 2 3 OR ----- Sample Output 1 ------ 0 0 3 ----- explanation 1 ------ 0 xor 1 xor 2 xor 3 = 0 0 and 1 and 2 and 3 = 0 0 or 1 or 2 or 3 = 3
for _ in range(int(input())): n, k, a = map(int, input().split()) l = list(map(int, input().split())) s = input().strip() if k == 0: print(a) else: if s == "AND": for x in l: a = a & x elif s == "OR": for x in l: a = a | x elif s == "XOR": if k % 2 != 0: for x in l: a = a ^ x 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR STRING FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR STRING FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR STRING IF BIN_OP VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
You are given a simple code of a function and you would like to know what it will return. F(N, K, Answer, Operator, A[N]) returns int; begin for i=1..K do for j=1..N do Answer=(Answer operator A_{j}) return Answer end Here N, K, Answer and the value returned by the function F are integers; A is an array of N integers numbered from 1 to N; Operator can be one of the binary operators XOR, AND or OR. If you are not familiar with these terms then better have a look at following articles: XOR, OR, AND. ------ Input ------ The first line of input contains an integer T - the number of test cases in file. Description of each test case consists of three lines. The first one contains three integers N, K and initial Answer. Array A is given in the second line and Operator is situated on the third one. Operators are given as strings, of capital letters. It is guaranteed that there will be no whitespaces before or after Operator. ------ Output ------ Output one line for each test case - the value that is returned by described function with given arguments. ------ Constraints ------ $1≤T≤100 $$1≤N≤1000 $0≤Answer, K, A_{i}≤10^{9} Operator is one of these: "AND", "XOR", "OR". ----- Sample Input 1 ------ 3 3 1 0 1 2 3 XOR 3 1 0 1 2 3 AND 3 1 0 1 2 3 OR ----- Sample Output 1 ------ 0 0 3 ----- explanation 1 ------ 0 xor 1 xor 2 xor 3 = 0 0 and 1 and 2 and 3 = 0 0 or 1 or 2 or 3 = 3
T = int(input()) for t in range(T): n, k, ans = map(int, input().split()) arr = list(map(int, input().split())) op = input().strip() if op == "XOR": k = k % 2 for j in range(k): for i in range(n): ans ^= arr[i] else: k = min(1, k) for j in range(k): for i in range(n): if op == "AND": ans &= arr[i] else: ans |= arr[i] print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a simple code of a function and you would like to know what it will return. F(N, K, Answer, Operator, A[N]) returns int; begin for i=1..K do for j=1..N do Answer=(Answer operator A_{j}) return Answer end Here N, K, Answer and the value returned by the function F are integers; A is an array of N integers numbered from 1 to N; Operator can be one of the binary operators XOR, AND or OR. If you are not familiar with these terms then better have a look at following articles: XOR, OR, AND. ------ Input ------ The first line of input contains an integer T - the number of test cases in file. Description of each test case consists of three lines. The first one contains three integers N, K and initial Answer. Array A is given in the second line and Operator is situated on the third one. Operators are given as strings, of capital letters. It is guaranteed that there will be no whitespaces before or after Operator. ------ Output ------ Output one line for each test case - the value that is returned by described function with given arguments. ------ Constraints ------ $1≤T≤100 $$1≤N≤1000 $0≤Answer, K, A_{i}≤10^{9} Operator is one of these: "AND", "XOR", "OR". ----- Sample Input 1 ------ 3 3 1 0 1 2 3 XOR 3 1 0 1 2 3 AND 3 1 0 1 2 3 OR ----- Sample Output 1 ------ 0 0 3 ----- explanation 1 ------ 0 xor 1 xor 2 xor 3 = 0 0 and 1 and 2 and 3 = 0 0 or 1 or 2 or 3 = 3
t = int(input()) while t > 0: n, k, a = map(int, input().split()) l = list(map(int, input().split())) s = input().strip() if k > 0: if s == "XOR": if k % 2 != 0: for i in l: a ^= i elif s == "AND": for i in l: a &= i else: for i in l: a |= i print(a) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR STRING IF BIN_OP VAR NUMBER NUMBER FOR VAR VAR VAR VAR IF VAR STRING FOR VAR VAR VAR VAR FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
You are given a simple code of a function and you would like to know what it will return. F(N, K, Answer, Operator, A[N]) returns int; begin for i=1..K do for j=1..N do Answer=(Answer operator A_{j}) return Answer end Here N, K, Answer and the value returned by the function F are integers; A is an array of N integers numbered from 1 to N; Operator can be one of the binary operators XOR, AND or OR. If you are not familiar with these terms then better have a look at following articles: XOR, OR, AND. ------ Input ------ The first line of input contains an integer T - the number of test cases in file. Description of each test case consists of three lines. The first one contains three integers N, K and initial Answer. Array A is given in the second line and Operator is situated on the third one. Operators are given as strings, of capital letters. It is guaranteed that there will be no whitespaces before or after Operator. ------ Output ------ Output one line for each test case - the value that is returned by described function with given arguments. ------ Constraints ------ $1≤T≤100 $$1≤N≤1000 $0≤Answer, K, A_{i}≤10^{9} Operator is one of these: "AND", "XOR", "OR". ----- Sample Input 1 ------ 3 3 1 0 1 2 3 XOR 3 1 0 1 2 3 AND 3 1 0 1 2 3 OR ----- Sample Output 1 ------ 0 0 3 ----- explanation 1 ------ 0 xor 1 xor 2 xor 3 = 0 0 and 1 and 2 and 3 = 0 0 or 1 or 2 or 3 = 3
T = int(input()) for i in range(T): n, k, ans = [int(x) for x in input().split()] a = [int(x) for x in input().split()] b = input() if k == 0: print(ans) else: if b[0] == "A": for i in a: ans &= i elif b[0] == "O": for i in a: ans |= i elif k % 2: for i in a: ans ^= i print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER STRING FOR VAR VAR VAR VAR IF VAR NUMBER STRING FOR VAR VAR VAR VAR IF BIN_OP VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a simple code of a function and you would like to know what it will return. F(N, K, Answer, Operator, A[N]) returns int; begin for i=1..K do for j=1..N do Answer=(Answer operator A_{j}) return Answer end Here N, K, Answer and the value returned by the function F are integers; A is an array of N integers numbered from 1 to N; Operator can be one of the binary operators XOR, AND or OR. If you are not familiar with these terms then better have a look at following articles: XOR, OR, AND. ------ Input ------ The first line of input contains an integer T - the number of test cases in file. Description of each test case consists of three lines. The first one contains three integers N, K and initial Answer. Array A is given in the second line and Operator is situated on the third one. Operators are given as strings, of capital letters. It is guaranteed that there will be no whitespaces before or after Operator. ------ Output ------ Output one line for each test case - the value that is returned by described function with given arguments. ------ Constraints ------ $1≤T≤100 $$1≤N≤1000 $0≤Answer, K, A_{i}≤10^{9} Operator is one of these: "AND", "XOR", "OR". ----- Sample Input 1 ------ 3 3 1 0 1 2 3 XOR 3 1 0 1 2 3 AND 3 1 0 1 2 3 OR ----- Sample Output 1 ------ 0 0 3 ----- explanation 1 ------ 0 xor 1 xor 2 xor 3 = 0 0 and 1 and 2 and 3 = 0 0 or 1 or 2 or 3 = 3
T = int(input()) ans = [] for _ in range(T): N, K, Ans = [int(i) for i in input().split()] A = [int(i) for i in input().split()] S = input().strip() if S == "XOR": x = A[0] for i in range(1, N): x ^= A[i] if K % 2 != 0: Ans ^= x elif S == "AND": x = A[0] for i in range(1, N): x &= A[i] if K != 0: Ans &= x elif S == "OR": x = A[0] for i in range(1, N): x |= A[i] if K != 0: Ans |= x ans.append(Ans) for i in ans: print(i)
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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR IF VAR STRING ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR IF VAR NUMBER VAR VAR IF VAR STRING ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a simple code of a function and you would like to know what it will return. F(N, K, Answer, Operator, A[N]) returns int; begin for i=1..K do for j=1..N do Answer=(Answer operator A_{j}) return Answer end Here N, K, Answer and the value returned by the function F are integers; A is an array of N integers numbered from 1 to N; Operator can be one of the binary operators XOR, AND or OR. If you are not familiar with these terms then better have a look at following articles: XOR, OR, AND. ------ Input ------ The first line of input contains an integer T - the number of test cases in file. Description of each test case consists of three lines. The first one contains three integers N, K and initial Answer. Array A is given in the second line and Operator is situated on the third one. Operators are given as strings, of capital letters. It is guaranteed that there will be no whitespaces before or after Operator. ------ Output ------ Output one line for each test case - the value that is returned by described function with given arguments. ------ Constraints ------ $1≤T≤100 $$1≤N≤1000 $0≤Answer, K, A_{i}≤10^{9} Operator is one of these: "AND", "XOR", "OR". ----- Sample Input 1 ------ 3 3 1 0 1 2 3 XOR 3 1 0 1 2 3 AND 3 1 0 1 2 3 OR ----- Sample Output 1 ------ 0 0 3 ----- explanation 1 ------ 0 xor 1 xor 2 xor 3 = 0 0 and 1 and 2 and 3 = 0 0 or 1 or 2 or 3 = 3
def f(N, K, ans, A, str1): if str1 == "XOR": if K > 0: if K % 2 == 1: for j in range(N): ans = ans ^ A[j] elif str1 == "AND": if K > 0: for j in range(N): ans = ans & A[j] elif K > 0: for j in range(N): ans = ans | A[j] return ans for _ in range(int(input())): n, k, a = map(int, input().strip().split()) A = list(map(int, input().strip().split())) s = input().strip() print(f(n, k, a, A, s))
FUNC_DEF IF VAR STRING IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR
You are given a simple code of a function and you would like to know what it will return. F(N, K, Answer, Operator, A[N]) returns int; begin for i=1..K do for j=1..N do Answer=(Answer operator A_{j}) return Answer end Here N, K, Answer and the value returned by the function F are integers; A is an array of N integers numbered from 1 to N; Operator can be one of the binary operators XOR, AND or OR. If you are not familiar with these terms then better have a look at following articles: XOR, OR, AND. ------ Input ------ The first line of input contains an integer T - the number of test cases in file. Description of each test case consists of three lines. The first one contains three integers N, K and initial Answer. Array A is given in the second line and Operator is situated on the third one. Operators are given as strings, of capital letters. It is guaranteed that there will be no whitespaces before or after Operator. ------ Output ------ Output one line for each test case - the value that is returned by described function with given arguments. ------ Constraints ------ $1≤T≤100 $$1≤N≤1000 $0≤Answer, K, A_{i}≤10^{9} Operator is one of these: "AND", "XOR", "OR". ----- Sample Input 1 ------ 3 3 1 0 1 2 3 XOR 3 1 0 1 2 3 AND 3 1 0 1 2 3 OR ----- Sample Output 1 ------ 0 0 3 ----- explanation 1 ------ 0 xor 1 xor 2 xor 3 = 0 0 and 1 and 2 and 3 = 0 0 or 1 or 2 or 3 = 3
import sys T = int(sys.stdin.readline()) Ans = "" for t in range(T): N, k, Answer = map(int, sys.stdin.readline().split()) A = list(map(int, sys.stdin.readline().split())) Q = sys.stdin.readline().split() for item in Q: if item[0] == "A" or item[0] == "O" or item[0] == "X": op = item break if k == 0: Ans += str(Answer) + "\n" continue key = A[0] if op[0] == "X": for i in range(1, N): key = key ^ A[i] elif op[0] == "O": for i in range(1, N): key = key | A[i] else: for i in range(1, N): key = key & A[i] if op[0] == "A": Ans += str(Answer & key) + "\n" elif op[0] == "O": Ans += str(Answer | key) + "\n" elif k % 2 == 1: Ans += str(Answer ^ key) + "\n" else: Ans += str(Answer) + "\n" sys.stdout.write(Ans)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR VAR IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER STRING VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR STRING IF VAR NUMBER STRING VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR STRING IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR STRING VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR
You are given a simple code of a function and you would like to know what it will return. F(N, K, Answer, Operator, A[N]) returns int; begin for i=1..K do for j=1..N do Answer=(Answer operator A_{j}) return Answer end Here N, K, Answer and the value returned by the function F are integers; A is an array of N integers numbered from 1 to N; Operator can be one of the binary operators XOR, AND or OR. If you are not familiar with these terms then better have a look at following articles: XOR, OR, AND. ------ Input ------ The first line of input contains an integer T - the number of test cases in file. Description of each test case consists of three lines. The first one contains three integers N, K and initial Answer. Array A is given in the second line and Operator is situated on the third one. Operators are given as strings, of capital letters. It is guaranteed that there will be no whitespaces before or after Operator. ------ Output ------ Output one line for each test case - the value that is returned by described function with given arguments. ------ Constraints ------ $1≤T≤100 $$1≤N≤1000 $0≤Answer, K, A_{i}≤10^{9} Operator is one of these: "AND", "XOR", "OR". ----- Sample Input 1 ------ 3 3 1 0 1 2 3 XOR 3 1 0 1 2 3 AND 3 1 0 1 2 3 OR ----- Sample Output 1 ------ 0 0 3 ----- explanation 1 ------ 0 xor 1 xor 2 xor 3 = 0 0 and 1 and 2 and 3 = 0 0 or 1 or 2 or 3 = 3
mod = 1000000007 read_int = lambda: int(input().strip()) read_str = lambda: input().strip() read_str_arr = lambda: input().strip().split() read_int_arr = lambda: [int(x) for x in input().strip().split()] def apply_op(op, A, n, ans): for i in range(n): if op == "AND": ans &= A[i] elif op == "OR": ans |= A[i] elif op == "XOR": ans ^= A[i] else: raise return ans def solve(): n, k, ans = read_int_arr() A = read_int_arr() op = read_str() if k == 0: print(ans) elif op == "XOR" and k & 1 == 0: print(ans) else: print(apply_op(op, A, n, ans)) for _ in range(int(input())): solve()
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR VAR IF VAR STRING VAR VAR VAR IF VAR STRING VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR STRING BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
You are given a simple code of a function and you would like to know what it will return. F(N, K, Answer, Operator, A[N]) returns int; begin for i=1..K do for j=1..N do Answer=(Answer operator A_{j}) return Answer end Here N, K, Answer and the value returned by the function F are integers; A is an array of N integers numbered from 1 to N; Operator can be one of the binary operators XOR, AND or OR. If you are not familiar with these terms then better have a look at following articles: XOR, OR, AND. ------ Input ------ The first line of input contains an integer T - the number of test cases in file. Description of each test case consists of three lines. The first one contains three integers N, K and initial Answer. Array A is given in the second line and Operator is situated on the third one. Operators are given as strings, of capital letters. It is guaranteed that there will be no whitespaces before or after Operator. ------ Output ------ Output one line for each test case - the value that is returned by described function with given arguments. ------ Constraints ------ $1≤T≤100 $$1≤N≤1000 $0≤Answer, K, A_{i}≤10^{9} Operator is one of these: "AND", "XOR", "OR". ----- Sample Input 1 ------ 3 3 1 0 1 2 3 XOR 3 1 0 1 2 3 AND 3 1 0 1 2 3 OR ----- Sample Output 1 ------ 0 0 3 ----- explanation 1 ------ 0 xor 1 xor 2 xor 3 = 0 0 and 1 and 2 and 3 = 0 0 or 1 or 2 or 3 = 3
def f(N, K, A, op, arr): if K == 0: return A orig = A for j in range(N): if op == "XOR": A = A ^ arr[j] elif op == "AND": A = A & arr[j] elif op == "OR": A = A | arr[j] if op == "XOR" and K % 2 == 0: return orig return A t = int(input()) for _ in range(t): N, K, A = list(map(int, input().strip().split())) arr = list(map(int, input().strip().split())) op = input().strip() ans = f(N, K, A, op, arr) print(ans)
FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR IF VAR STRING BIN_OP VAR NUMBER NUMBER RETURN VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a simple code of a function and you would like to know what it will return. F(N, K, Answer, Operator, A[N]) returns int; begin for i=1..K do for j=1..N do Answer=(Answer operator A_{j}) return Answer end Here N, K, Answer and the value returned by the function F are integers; A is an array of N integers numbered from 1 to N; Operator can be one of the binary operators XOR, AND or OR. If you are not familiar with these terms then better have a look at following articles: XOR, OR, AND. ------ Input ------ The first line of input contains an integer T - the number of test cases in file. Description of each test case consists of three lines. The first one contains three integers N, K and initial Answer. Array A is given in the second line and Operator is situated on the third one. Operators are given as strings, of capital letters. It is guaranteed that there will be no whitespaces before or after Operator. ------ Output ------ Output one line for each test case - the value that is returned by described function with given arguments. ------ Constraints ------ $1≤T≤100 $$1≤N≤1000 $0≤Answer, K, A_{i}≤10^{9} Operator is one of these: "AND", "XOR", "OR". ----- Sample Input 1 ------ 3 3 1 0 1 2 3 XOR 3 1 0 1 2 3 AND 3 1 0 1 2 3 OR ----- Sample Output 1 ------ 0 0 3 ----- explanation 1 ------ 0 xor 1 xor 2 xor 3 = 0 0 and 1 and 2 and 3 = 0 0 or 1 or 2 or 3 = 3
from sys import stdin, stdout def sin(): return stdin.readline().rstrip() def listInput(): return list(map(int, sin().split())) def printBS(li): if not li: return for i in range(len(li) - 1): stdout.write("%d " % li[i]) stdout.write("%d\n" % li[-1]) t = int(sin()) for _ in range(t): n, k, ans = listInput() li = listInput() op = sin() if op == "AND": if k != 0: for i in li: ans = ans & i elif op == "OR": if k != 0: for i in li: ans = ans | i elif k % 2 == 1: for i in li: ans = ans ^ i print(ans)
FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR RETURN FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR STRING IF VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR STRING IF VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
You are given a simple code of a function and you would like to know what it will return. F(N, K, Answer, Operator, A[N]) returns int; begin for i=1..K do for j=1..N do Answer=(Answer operator A_{j}) return Answer end Here N, K, Answer and the value returned by the function F are integers; A is an array of N integers numbered from 1 to N; Operator can be one of the binary operators XOR, AND or OR. If you are not familiar with these terms then better have a look at following articles: XOR, OR, AND. ------ Input ------ The first line of input contains an integer T - the number of test cases in file. Description of each test case consists of three lines. The first one contains three integers N, K and initial Answer. Array A is given in the second line and Operator is situated on the third one. Operators are given as strings, of capital letters. It is guaranteed that there will be no whitespaces before or after Operator. ------ Output ------ Output one line for each test case - the value that is returned by described function with given arguments. ------ Constraints ------ $1≤T≤100 $$1≤N≤1000 $0≤Answer, K, A_{i}≤10^{9} Operator is one of these: "AND", "XOR", "OR". ----- Sample Input 1 ------ 3 3 1 0 1 2 3 XOR 3 1 0 1 2 3 AND 3 1 0 1 2 3 OR ----- Sample Output 1 ------ 0 0 3 ----- explanation 1 ------ 0 xor 1 xor 2 xor 3 = 0 0 and 1 and 2 and 3 = 0 0 or 1 or 2 or 3 = 3
__author__ = "star-lord" def calc(n, k, ans, op, array): if k == 0 or k % 2 == 0 and op == "XOR": return ans else: for element in array: if op == "XOR": ans ^= element elif op == "AND": ans &= element else: ans |= element return ans testCase = int(input()) while testCase > 0: n, k, ans = map(int, input().strip().split()) array = map(int, input().strip().split()) operator = input().strip() print(calc(n, k, ans, operator, array)) testCase -= 1
ASSIGN VAR STRING FUNC_DEF IF VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR STRING RETURN VAR FOR VAR VAR IF VAR STRING VAR VAR IF VAR STRING VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER
You are given a simple code of a function and you would like to know what it will return. F(N, K, Answer, Operator, A[N]) returns int; begin for i=1..K do for j=1..N do Answer=(Answer operator A_{j}) return Answer end Here N, K, Answer and the value returned by the function F are integers; A is an array of N integers numbered from 1 to N; Operator can be one of the binary operators XOR, AND or OR. If you are not familiar with these terms then better have a look at following articles: XOR, OR, AND. ------ Input ------ The first line of input contains an integer T - the number of test cases in file. Description of each test case consists of three lines. The first one contains three integers N, K and initial Answer. Array A is given in the second line and Operator is situated on the third one. Operators are given as strings, of capital letters. It is guaranteed that there will be no whitespaces before or after Operator. ------ Output ------ Output one line for each test case - the value that is returned by described function with given arguments. ------ Constraints ------ $1≤T≤100 $$1≤N≤1000 $0≤Answer, K, A_{i}≤10^{9} Operator is one of these: "AND", "XOR", "OR". ----- Sample Input 1 ------ 3 3 1 0 1 2 3 XOR 3 1 0 1 2 3 AND 3 1 0 1 2 3 OR ----- Sample Output 1 ------ 0 0 3 ----- explanation 1 ------ 0 xor 1 xor 2 xor 3 = 0 0 and 1 and 2 and 3 = 0 0 or 1 or 2 or 3 = 3
for _ in range(int(input())): _, k, ans = map(int, input().split()) a = map(int, input().split()) op = input() if not k or not k & 1 and op[0] == "X": print(ans) else: for n in a: if op[0] == "X": ans ^= n elif op[0] == "O": ans |= n else: ans &= n print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER STRING EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR NUMBER STRING VAR VAR IF VAR NUMBER STRING VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a simple code of a function and you would like to know what it will return. F(N, K, Answer, Operator, A[N]) returns int; begin for i=1..K do for j=1..N do Answer=(Answer operator A_{j}) return Answer end Here N, K, Answer and the value returned by the function F are integers; A is an array of N integers numbered from 1 to N; Operator can be one of the binary operators XOR, AND or OR. If you are not familiar with these terms then better have a look at following articles: XOR, OR, AND. ------ Input ------ The first line of input contains an integer T - the number of test cases in file. Description of each test case consists of three lines. The first one contains three integers N, K and initial Answer. Array A is given in the second line and Operator is situated on the third one. Operators are given as strings, of capital letters. It is guaranteed that there will be no whitespaces before or after Operator. ------ Output ------ Output one line for each test case - the value that is returned by described function with given arguments. ------ Constraints ------ $1≤T≤100 $$1≤N≤1000 $0≤Answer, K, A_{i}≤10^{9} Operator is one of these: "AND", "XOR", "OR". ----- Sample Input 1 ------ 3 3 1 0 1 2 3 XOR 3 1 0 1 2 3 AND 3 1 0 1 2 3 OR ----- Sample Output 1 ------ 0 0 3 ----- explanation 1 ------ 0 xor 1 xor 2 xor 3 = 0 0 and 1 and 2 and 3 = 0 0 or 1 or 2 or 3 = 3
def F(n, k, answer, op, a): if k == 0: return answer op_cal = a[0] if op == "XOR": for i in a[1:]: op_cal = op_cal ^ i if k % 2 == 0: op_cal = 0 answer = answer ^ op_cal elif op == "AND": for i in a[1:]: op_cal = op_cal & i answer = answer & op_cal elif op == "OR": for i in a[1:]: op_cal = op_cal | i answer = answer | op_cal return answer t = int(input()) for i in range(t): n, k, answer = list(map(int, input().split())) a = list(map(int, input().split())) op = input().strip() print(F(n, k, answer, op, a))
FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR VAR NUMBER IF VAR STRING FOR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR STRING FOR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR STRING FOR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR
Chef's last task in his internship requires him to construct 2 permutations, each having length N, such that the [bitwise AND] of each pair of elements at every index is the same. Formally, if the permutations are A and B, then, the value A_{i} \& B_{i} must be constant over all 1≤ i ≤ N. Help Chef by providing him 2 such permutations. If it is not possible to construct such permutations, print -1 instead. A permutation is a sequence of integers from 1 to N of length N containing each number exactly once. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, a single integer N denoting the size of the required permutations. ------ Output Format ------ - If there are valid permutations that satisfy the required condition, then: - In the first line, output N space-separated integers denoting the permutation A. - In the second line, output N space-separated integers denoting the permutation B. - If there is no valid pair of permutations, print -1 in a single line. ------ Constraints ------ $1 ≤ T ≤ 1000$ $1 ≤ N ≤ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 3 1 2 3 ----- Sample Output 1 ------ 1 1 1 2 2 1 -1 ----- explanation 1 ------ Test case $1$: There is only one element in each array and the resultant bitwise AND is $1$. Thus, $A = [1]$ and $B = [1]$. Test case $2$: Let $A = [1,2]$ and $B = [2,1]$. The resultant bitwise AND of each pair at any index is equal to $0$. So, this is a valid pair of permutations. Test case $3$: There are $6$ permutations of length $3$. It can be seen that any pair of the $6$ permutations does not satisfy the stated condition.
import sys def get_arr(): return list(map(int, sys.stdin.readline().strip().split())) def get_ints(): return map(int, sys.stdin.readline().strip().split()) t = int(sys.stdin.readline()) for _ in range(t): n = int(sys.stdin.readline()) if n == 1: print(1) print(1) continue if n % 2 != 0: print(-1) continue a = [] for i in range(1, n + 1): a.append(i) b = [(0) for i in range(n)] for i in range(n - 1, -1, -1): if b[i] != 0: continue val = bin(i + 1)[2:] st = "" for j in range(len(val)): if val[j] == "0": st += "1" else: st += "0" val2 = int(st, 2) b[val2 - 1] = i + 1 b[i] = val2 print(*a) print(*b)
IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Chef's last task in his internship requires him to construct 2 permutations, each having length N, such that the [bitwise AND] of each pair of elements at every index is the same. Formally, if the permutations are A and B, then, the value A_{i} \& B_{i} must be constant over all 1≤ i ≤ N. Help Chef by providing him 2 such permutations. If it is not possible to construct such permutations, print -1 instead. A permutation is a sequence of integers from 1 to N of length N containing each number exactly once. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, a single integer N denoting the size of the required permutations. ------ Output Format ------ - If there are valid permutations that satisfy the required condition, then: - In the first line, output N space-separated integers denoting the permutation A. - In the second line, output N space-separated integers denoting the permutation B. - If there is no valid pair of permutations, print -1 in a single line. ------ Constraints ------ $1 ≤ T ≤ 1000$ $1 ≤ N ≤ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 3 1 2 3 ----- Sample Output 1 ------ 1 1 1 2 2 1 -1 ----- explanation 1 ------ Test case $1$: There is only one element in each array and the resultant bitwise AND is $1$. Thus, $A = [1]$ and $B = [1]$. Test case $2$: Let $A = [1,2]$ and $B = [2,1]$. The resultant bitwise AND of each pair at any index is equal to $0$. So, this is a valid pair of permutations. Test case $3$: There are $6$ permutations of length $3$. It can be seen that any pair of the $6$ permutations does not satisfy the stated condition.
def convert(n): ss = bin(n)[2:] s = "" for i in ss: if i == "0": s += "1" else: s += "0" if int(s, 2) == 0: s = "1" + s return int(s, 2) result = [] MAX = 4294967295 def solve(n): A = [i for i in range(1, n + 1)] B = [MAX for i in range(n, 0, -1)] if n == 1: print(1) print(1) elif n & 1: print(-1) else: s = set() for i in range(n - 1, 0, -1): if B[i] == MAX: g = convert(A[i]) if g <= n: if g not in s: B[i] = g s.add(g) if A[i] not in s: B[g - 1] = A[i] s.add(A[i]) res = A[0] & B[0] f = True for i in range(1, n): if A[i] & B[i] != res: f = False if f: print(*A) print(*B) t = int(input()) for _ in range(t): n = int(input()) solve(n)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR STRING VAR STRING IF FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP STRING VAR RETURN FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
Chef's last task in his internship requires him to construct 2 permutations, each having length N, such that the [bitwise AND] of each pair of elements at every index is the same. Formally, if the permutations are A and B, then, the value A_{i} \& B_{i} must be constant over all 1≤ i ≤ N. Help Chef by providing him 2 such permutations. If it is not possible to construct such permutations, print -1 instead. A permutation is a sequence of integers from 1 to N of length N containing each number exactly once. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, a single integer N denoting the size of the required permutations. ------ Output Format ------ - If there are valid permutations that satisfy the required condition, then: - In the first line, output N space-separated integers denoting the permutation A. - In the second line, output N space-separated integers denoting the permutation B. - If there is no valid pair of permutations, print -1 in a single line. ------ Constraints ------ $1 ≤ T ≤ 1000$ $1 ≤ N ≤ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 3 1 2 3 ----- Sample Output 1 ------ 1 1 1 2 2 1 -1 ----- explanation 1 ------ Test case $1$: There is only one element in each array and the resultant bitwise AND is $1$. Thus, $A = [1]$ and $B = [1]$. Test case $2$: Let $A = [1,2]$ and $B = [2,1]$. The resultant bitwise AND of each pair at any index is equal to $0$. So, this is a valid pair of permutations. Test case $3$: There are $6$ permutations of length $3$. It can be seen that any pair of the $6$ permutations does not satisfy the stated condition.
def is_2_pow(N): return N == 1 or "0" not in bin(N - 1)[2:] for _ in range(int(input())): N = int(input()) if N == 1: print(1) print(1) elif N % 2 == 0: N_copy = N ret = [] while N > 0: l = len(bin(N)) - 2 start = (1 << l) - 1 - N ret.extend(map(str, range(start, N + 1))) N = start - 1 print(" ".join(map(str, range(N_copy, 0, -1)))) print(" ".join(ret)) else: print(-1)
FUNC_DEF RETURN VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR NUMBER
Chef's last task in his internship requires him to construct 2 permutations, each having length N, such that the [bitwise AND] of each pair of elements at every index is the same. Formally, if the permutations are A and B, then, the value A_{i} \& B_{i} must be constant over all 1≤ i ≤ N. Help Chef by providing him 2 such permutations. If it is not possible to construct such permutations, print -1 instead. A permutation is a sequence of integers from 1 to N of length N containing each number exactly once. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, a single integer N denoting the size of the required permutations. ------ Output Format ------ - If there are valid permutations that satisfy the required condition, then: - In the first line, output N space-separated integers denoting the permutation A. - In the second line, output N space-separated integers denoting the permutation B. - If there is no valid pair of permutations, print -1 in a single line. ------ Constraints ------ $1 ≤ T ≤ 1000$ $1 ≤ N ≤ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 3 1 2 3 ----- Sample Output 1 ------ 1 1 1 2 2 1 -1 ----- explanation 1 ------ Test case $1$: There is only one element in each array and the resultant bitwise AND is $1$. Thus, $A = [1]$ and $B = [1]$. Test case $2$: Let $A = [1,2]$ and $B = [2,1]$. The resultant bitwise AND of each pair at any index is equal to $0$. So, this is a valid pair of permutations. Test case $3$: There are $6$ permutations of length $3$. It can be seen that any pair of the $6$ permutations does not satisfy the stated condition.
from sys import stdin input = stdin.readline for _ in range(int(input())): N = int(input()) if N == 1: print(1) print(1) continue if N % 2 == 0: N_copy = N ret = [] while N > 0: l = len(bin(N)) - 2 start = (1 << l) - 1 - N ret += list(range(start, N + 1)) N = start - 1 print(*range(N_copy, 0, -1)) print(*ret) else: print(-1)
ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Chef's last task in his internship requires him to construct 2 permutations, each having length N, such that the [bitwise AND] of each pair of elements at every index is the same. Formally, if the permutations are A and B, then, the value A_{i} \& B_{i} must be constant over all 1≤ i ≤ N. Help Chef by providing him 2 such permutations. If it is not possible to construct such permutations, print -1 instead. A permutation is a sequence of integers from 1 to N of length N containing each number exactly once. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, a single integer N denoting the size of the required permutations. ------ Output Format ------ - If there are valid permutations that satisfy the required condition, then: - In the first line, output N space-separated integers denoting the permutation A. - In the second line, output N space-separated integers denoting the permutation B. - If there is no valid pair of permutations, print -1 in a single line. ------ Constraints ------ $1 ≤ T ≤ 1000$ $1 ≤ N ≤ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 3 1 2 3 ----- Sample Output 1 ------ 1 1 1 2 2 1 -1 ----- explanation 1 ------ Test case $1$: There is only one element in each array and the resultant bitwise AND is $1$. Thus, $A = [1]$ and $B = [1]$. Test case $2$: Let $A = [1,2]$ and $B = [2,1]$. The resultant bitwise AND of each pair at any index is equal to $0$. So, this is a valid pair of permutations. Test case $3$: There are $6$ permutations of length $3$. It can be seen that any pair of the $6$ permutations does not satisfy the stated condition.
def msb(x): p = 1 while p <= x: p <<= 1 return p for t in range(int(input())): n = int(input()) if n == 1: a = ["1"] b = a else: a = [] b = [] l = n while l > 1: p = msb(l) - 1 r = p >> 1 for i in range(l, r, -1): j = p ^ i a.extend([str(i), str(j)]) b.extend([str(j), str(i)]) l = l ^ p - 1 if n > 1 and n % 2: print(-1) else: print(" ".join(a)) print(" ".join(b))
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR LIST STRING ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Chef's last task in his internship requires him to construct 2 permutations, each having length N, such that the [bitwise AND] of each pair of elements at every index is the same. Formally, if the permutations are A and B, then, the value A_{i} \& B_{i} must be constant over all 1≤ i ≤ N. Help Chef by providing him 2 such permutations. If it is not possible to construct such permutations, print -1 instead. A permutation is a sequence of integers from 1 to N of length N containing each number exactly once. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, a single integer N denoting the size of the required permutations. ------ Output Format ------ - If there are valid permutations that satisfy the required condition, then: - In the first line, output N space-separated integers denoting the permutation A. - In the second line, output N space-separated integers denoting the permutation B. - If there is no valid pair of permutations, print -1 in a single line. ------ Constraints ------ $1 ≤ T ≤ 1000$ $1 ≤ N ≤ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 3 1 2 3 ----- Sample Output 1 ------ 1 1 1 2 2 1 -1 ----- explanation 1 ------ Test case $1$: There is only one element in each array and the resultant bitwise AND is $1$. Thus, $A = [1]$ and $B = [1]$. Test case $2$: Let $A = [1,2]$ and $B = [2,1]$. The resultant bitwise AND of each pair at any index is equal to $0$. So, this is a valid pair of permutations. Test case $3$: There are $6$ permutations of length $3$. It can be seen that any pair of the $6$ permutations does not satisfy the stated condition.
def f(n): x = 1 while x <= n: x <<= 1 return x - 1 t = int(input()) for _ in range(t): n = int(input()) if n == 1: print(1) print(1) elif n % 2 == 0: ar = [(False) for i in range(f(n) + 1)] x = f(n) tm = n for i in range(n, 0, -1): if ar[x - i] or x - i > n: x = f(i) ar[x - i] = True print(x - i, end=" ") print() for i in range(n, 0, -1): print(i, end=" ") print() else: print(-1)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER RETURN BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER
Chef's last task in his internship requires him to construct 2 permutations, each having length N, such that the [bitwise AND] of each pair of elements at every index is the same. Formally, if the permutations are A and B, then, the value A_{i} \& B_{i} must be constant over all 1≤ i ≤ N. Help Chef by providing him 2 such permutations. If it is not possible to construct such permutations, print -1 instead. A permutation is a sequence of integers from 1 to N of length N containing each number exactly once. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, a single integer N denoting the size of the required permutations. ------ Output Format ------ - If there are valid permutations that satisfy the required condition, then: - In the first line, output N space-separated integers denoting the permutation A. - In the second line, output N space-separated integers denoting the permutation B. - If there is no valid pair of permutations, print -1 in a single line. ------ Constraints ------ $1 ≤ T ≤ 1000$ $1 ≤ N ≤ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 3 1 2 3 ----- Sample Output 1 ------ 1 1 1 2 2 1 -1 ----- explanation 1 ------ Test case $1$: There is only one element in each array and the resultant bitwise AND is $1$. Thus, $A = [1]$ and $B = [1]$. Test case $2$: Let $A = [1,2]$ and $B = [2,1]$. The resultant bitwise AND of each pair at any index is equal to $0$. So, this is a valid pair of permutations. Test case $3$: There are $6$ permutations of length $3$. It can be seen that any pair of the $6$ permutations does not satisfy the stated condition.
try: t = int(input()) for _ in range(t): n = int(input()) if n == 1: print(1) print(1) elif n & 1: print(-1) else: print(*[i for i in range(1, n + 1)]) B = [] num = n while len(B) < num: p = 1 while p <= n: p <<= 1 p -= 1 for i in range(n, -1, -1): if ~i & p > n: n = i break B.append(~i & p) print(*B[::-1]) except: pass
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
Chef's last task in his internship requires him to construct 2 permutations, each having length N, such that the [bitwise AND] of each pair of elements at every index is the same. Formally, if the permutations are A and B, then, the value A_{i} \& B_{i} must be constant over all 1≤ i ≤ N. Help Chef by providing him 2 such permutations. If it is not possible to construct such permutations, print -1 instead. A permutation is a sequence of integers from 1 to N of length N containing each number exactly once. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, a single integer N denoting the size of the required permutations. ------ Output Format ------ - If there are valid permutations that satisfy the required condition, then: - In the first line, output N space-separated integers denoting the permutation A. - In the second line, output N space-separated integers denoting the permutation B. - If there is no valid pair of permutations, print -1 in a single line. ------ Constraints ------ $1 ≤ T ≤ 1000$ $1 ≤ N ≤ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 3 1 2 3 ----- Sample Output 1 ------ 1 1 1 2 2 1 -1 ----- explanation 1 ------ Test case $1$: There is only one element in each array and the resultant bitwise AND is $1$. Thus, $A = [1]$ and $B = [1]$. Test case $2$: Let $A = [1,2]$ and $B = [2,1]$. The resultant bitwise AND of each pair at any index is equal to $0$. So, this is a valid pair of permutations. Test case $3$: There are $6$ permutations of length $3$. It can be seen that any pair of the $6$ permutations does not satisfy the stated condition.
def setBitNumber(n): if n == 0: return 0 msb = 0 n = int(n / 2) while n > 0: n = int(n / 2) msb += 1 return 1 << msb def find(n, a, b): temp = setBitNumber(n) + 1 i = 0 while temp + i <= n: a.append(temp + i) b.append(temp - i - 3) b.append(temp + i) a.append(temp - i - 3) i += 1 a.append(temp - 1) b.append(temp - 2) a.append(temp - 2) b.append(temp - 1) x = temp - i - 3 if x > 0: a, b = find(x, a, b) return a, b for _ in range(int(input())): n = int(input()) a = [] b = [] if n % 2 == 0: find(n, a, b) print(*a, sep=" ") print(*b, sep=" ") elif n == 1: print(1) print(1) else: print(-1)
FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER RETURN BIN_OP NUMBER VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Chef's last task in his internship requires him to construct 2 permutations, each having length N, such that the [bitwise AND] of each pair of elements at every index is the same. Formally, if the permutations are A and B, then, the value A_{i} \& B_{i} must be constant over all 1≤ i ≤ N. Help Chef by providing him 2 such permutations. If it is not possible to construct such permutations, print -1 instead. A permutation is a sequence of integers from 1 to N of length N containing each number exactly once. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, a single integer N denoting the size of the required permutations. ------ Output Format ------ - If there are valid permutations that satisfy the required condition, then: - In the first line, output N space-separated integers denoting the permutation A. - In the second line, output N space-separated integers denoting the permutation B. - If there is no valid pair of permutations, print -1 in a single line. ------ Constraints ------ $1 ≤ T ≤ 1000$ $1 ≤ N ≤ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 3 1 2 3 ----- Sample Output 1 ------ 1 1 1 2 2 1 -1 ----- explanation 1 ------ Test case $1$: There is only one element in each array and the resultant bitwise AND is $1$. Thus, $A = [1]$ and $B = [1]$. Test case $2$: Let $A = [1,2]$ and $B = [2,1]$. The resultant bitwise AND of each pair at any index is equal to $0$. So, this is a valid pair of permutations. Test case $3$: There are $6$ permutations of length $3$. It can be seen that any pair of the $6$ permutations does not satisfy the stated condition.
t = int(input()) for i in range(t): n = int(input()) if n == 1: print(1) print(1) continue if n % 2: print(-1) continue a = [(0) for i in range(n)] b = [(0) for i in range(n)] kk = 0 maxi = 1 while maxi * 2 <= n: maxi = maxi * 2 vis = [(-1) for i in range(n + 1)] while kk < n: curr = maxi count = 1 while curr <= n and vis[curr] == -1: a[kk] = curr b[kk] = curr - count kk += 1 a[kk] = curr - count b[kk] = curr kk += 1 vis[curr] = 1 vis[curr - count] = 1 count += 2 curr += 1 maxi = maxi // 2 for i in range(n): print(a[i], end=" ") print() for i in range(n): print(b[i], end=" ") print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
Chef's last task in his internship requires him to construct 2 permutations, each having length N, such that the [bitwise AND] of each pair of elements at every index is the same. Formally, if the permutations are A and B, then, the value A_{i} \& B_{i} must be constant over all 1≤ i ≤ N. Help Chef by providing him 2 such permutations. If it is not possible to construct such permutations, print -1 instead. A permutation is a sequence of integers from 1 to N of length N containing each number exactly once. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, a single integer N denoting the size of the required permutations. ------ Output Format ------ - If there are valid permutations that satisfy the required condition, then: - In the first line, output N space-separated integers denoting the permutation A. - In the second line, output N space-separated integers denoting the permutation B. - If there is no valid pair of permutations, print -1 in a single line. ------ Constraints ------ $1 ≤ T ≤ 1000$ $1 ≤ N ≤ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 3 1 2 3 ----- Sample Output 1 ------ 1 1 1 2 2 1 -1 ----- explanation 1 ------ Test case $1$: There is only one element in each array and the resultant bitwise AND is $1$. Thus, $A = [1]$ and $B = [1]$. Test case $2$: Let $A = [1,2]$ and $B = [2,1]$. The resultant bitwise AND of each pair at any index is equal to $0$. So, this is a valid pair of permutations. Test case $3$: There are $6$ permutations of length $3$. It can be seen that any pair of the $6$ permutations does not satisfy the stated condition.
import sys input = sys.stdin.readline M = int(1000000000.0) + 7 def bitflip(x): bitx = bin(x)[2:] ans = "" for i in bitx: if i == "0": ans += "1" else: ans += "0" return int(ans, 2) def solve(): n = int(input()) if n == 1: print(1) print(1) return if n % 2 == 1: print(-1) return print(*range(1, n + 1)) l = [-1] * (n + 1) for i in range(n, 0, -1): if l[i] == -1: l[i] = bitflip(i) l[bitflip(i)] = i print(*l[1:]) for _ in range(int(input())): solve()
IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR STRING VAR STRING RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
Chef's last task in his internship requires him to construct 2 permutations, each having length N, such that the [bitwise AND] of each pair of elements at every index is the same. Formally, if the permutations are A and B, then, the value A_{i} \& B_{i} must be constant over all 1≤ i ≤ N. Help Chef by providing him 2 such permutations. If it is not possible to construct such permutations, print -1 instead. A permutation is a sequence of integers from 1 to N of length N containing each number exactly once. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, a single integer N denoting the size of the required permutations. ------ Output Format ------ - If there are valid permutations that satisfy the required condition, then: - In the first line, output N space-separated integers denoting the permutation A. - In the second line, output N space-separated integers denoting the permutation B. - If there is no valid pair of permutations, print -1 in a single line. ------ Constraints ------ $1 ≤ T ≤ 1000$ $1 ≤ N ≤ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 3 1 2 3 ----- Sample Output 1 ------ 1 1 1 2 2 1 -1 ----- explanation 1 ------ Test case $1$: There is only one element in each array and the resultant bitwise AND is $1$. Thus, $A = [1]$ and $B = [1]$. Test case $2$: Let $A = [1,2]$ and $B = [2,1]$. The resultant bitwise AND of each pair at any index is equal to $0$. So, this is a valid pair of permutations. Test case $3$: There are $6$ permutations of length $3$. It can be seen that any pair of the $6$ permutations does not satisfy the stated condition.
def counter(n): val = 0 c = 0 while n: if n % 2 == 0: val += 2**c c += 1 n //= 2 return val for _ in range(int(input())): n = int(input()) if n == 1: print(1) print(1) elif n % 2 == 0: dict = [False] * (n + 1) a = [] b = [] for i in range(n, 0, -1): if dict[i] == False: c = counter(i) dict[c] = True dict[i] = True a.append(i) b.append(c) a.append(c) b.append(i) for i in range(n): print(a[i], end=" ") print() for i in range(n): print(b[i], end=" ") print() else: print(-1)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
q = int(input()) for i in range(q): x = int(input()) x = bin(x)[2:] if "0" not in x: print(0) else: n = len(x) - x.find("0") total = 2**n - 1 ms = [] for i, b in enumerate(x[::-1]): if i == n: break elif b == "1": ms.append(i) for j in ms: total -= 2**j print(total)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF STRING VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys q = int(input().strip()) for a0 in range(q): x = int(input().strip()) zeros = pow(2, x.bit_length()) - 1 ^ x print(zeros)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys q = int(input().strip()) x = [] for a0 in range(q): x.append(int(input().strip())) for i in range(len(x)): print(int("".join([str(1 - int(i)) for i in "{0:b}".format(x[i])]), 2))
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL STRING VAR VAR NUMBER
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
q = int(input().strip()) for a0 in range(q): x = int(input().strip()) t = bin(x)[2:] t = list(map(int, t.strip())) for i in range(len(t)): if t[i] == 0: t[i] = 1 else: t[i] = 0 x = "".join(map(str, t)) x = int(x, 2) print(x)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys def Cur(x, less, greater): if less and greater: return 2 ** len(x) if not x: return 0 ans = 0 for i in "01": if not less and i > x[0]: continue if not greater and i == "1" and x[0] == "1": continue ans += Cur(x[1:], less or i < x[0], greater or i == "1") return ans def Solve(x): x = bin(x)[2:] return Cur(x, False, False) q = int(input().strip()) for a0 in range(q): x = int(input().strip()) print(Solve(x))
IMPORT FUNC_DEF IF VAR VAR RETURN BIN_OP NUMBER FUNC_CALL VAR VAR IF VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR STRING IF VAR VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER STRING VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR STRING RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
q = int(input()) for i in range(q): x = int(input()) s = 1 while s < x: s *= 2 if s != x: print(s - 1 - x) else: print(x - 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys q = int(input().strip()) for a0 in range(q): x = int(input().strip()) a = bin(x) a = a[2:] a = a[::-1] s = 0 for i in range(len(a)): if a[i] == "0": s += pow(2, i) print(s)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys q = int(input().strip()) for a0 in range(q): x = int(input().strip()) a = list(reversed(list(bin(x)[2:]))) counter = 0 for idx in range(len(a)): if int(a[idx]) == 0: counter += 2**idx print(counter)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys q = int(input().strip()) for a0 in range(q): x = int(input().strip()) len_x = len(bin(x)) - 2 c = 0 for i in range(len_x - 1): v = 1 << i if x & v != v: c += 2**i val = x - 2 ** (len_x - 1) + 1 v = 1 << len_x - 1 if x & v != v: c += val print(c)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys q = int(input().strip()) for a0 in range(q): x = int(input().strip()) s = 0 cnt = 0 while x > 0: if x % 2 == 0: s += int(pow(2, cnt)) cnt += 1 x = int(x / 2) print(s)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
q = int(input()) for _ in range(q): n = int(input()) b = 1 count = 0 while b < n: if n & b == 0: count += b b <<= 1 print(count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys def greater_a(x): result = 0 for i, d in enumerate(bin(x)[2:]): if d == "0": result += 2 ** len(bin(x)[2 + i + 1 :]) return result q = int(input().strip()) for a0 in range(q): x = int(input().strip()) print(greater_a(x))
IMPORT FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR STRING VAR BIN_OP NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys q = int(input().strip()) for a0 in range(q): x = int(input().strip()) count = 0 term = 1 while x: if x & 1 == 0: count += term term *= 2 x //= 2 print(count)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys q = int(input().strip()) for a0 in range(q): x = int(input().strip()) s = "{0:b}".format(x) n = len(s) ans = 0 for i in range(n): if s[i] == "0": ans += 2 ** (n - 1 - i) print(ans)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys def BinaryOf(x): l = [] r = x n = x while n != 1: r = n % 2 l.append(r) n = n // 2 l.append(n) return l q = int(input().strip()) for a0 in range(q): x = int(input().strip()) count = 0 l = BinaryOf(x) index = [] for i in range(len(l)): if l[i] == 0: index.append(i) sum = 0 for i in range(len(index)): sum += 2 ** index[i] print(sum)
IMPORT FUNC_DEF ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys q = int(input().strip()) for a0 in range(q): x = int(input().strip()) cnt = 0 for pos, bit in enumerate(bin(x)[::-1]): if bit == "b": break if bit == "0": cnt += int(2**pos) print(cnt)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR STRING IF VAR STRING VAR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
num_queries = int(input()) for each_query in range(num_queries): count = digits = 0 num = int(input()) while num > 0: if num & 1 == 0: count += 1 << digits digits += 1 num >>= 1 print(count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys q = int(input().strip()) for a0 in range(q): x = int(input().strip()) q = bin(x)[2:] c = "" for i in q: if i == "1": c += "0" else: c += "1" print(int(c, 2))
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys def num_great_xors(n): st_n = "{0:b}".format(n) result = 0 for i in range(len(st_n)): if st_n[-1 - i] == "0": result += 2**i return result q = int(input().strip()) for a0 in range(q): x = int(input().strip()) print(num_great_xors(x))
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP NUMBER VAR STRING VAR BIN_OP NUMBER VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys q = int(input().strip()) for a0 in range(q): x = int(input().strip()) b = bin(x)[2:] print(2 ** len(b) - 1 - x)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys q = int(input().strip()) for a0 in range(q): x = int(input().strip()) a = 1 sum2 = 0 while x // a != 0: a = a * 2 print(a - x - 1)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys q = int(input()) for i in range(q): a = list(map(int, list("{0:b}".format(int(input()))))) ans = 0 n = len(a) for i in range(n): if not a[i]: ans += 1 << n - i - 1 print(ans)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys q = int(input().strip()) for a0 in range(q): x = int(input().strip()) y = bin(x)[2:] z = "0b" for c in y: if c == "1": z = z + "0" else: z = z + "1" x = int(z, 2) print(x)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys q = int(input().strip()) for a0 in range(q): x = int(input().strip()) count_a = 0 bx = bin(x)[2:] for i in range(1, len(bx)): if bx[i] == "1": continue count_a += 2 ** (len(bx[1:]) - i) print(count_a)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys q = int(input().strip()) for a0 in range(q): x = int(input().strip()) x_bin = bin(x)[2:] res = 0 for i in range(1, len(x_bin)): if not int(x_bin[-i]): res += 2 ** (i - 1) print(res)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys data = sys.stdin.read().splitlines() for x in map(int, data[1:]): y = 2 ** (len("{0:b}".format(x)) - 1) - 1 print(2 * y - x + 1)
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
def solve(n): _bin = "{0:b}".format(n) i = len(_bin) - 1 ans = 0 for bit in _bin: if bit == "0": ans += pow(2, i) i -= 1 print(ans) for i in range(int(input())): solve(int(input()))
FUNC_DEF ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys q = int(input().strip()) for a0 in range(q): x = int(input().strip()) bits = x.bit_length() if 2**bits > x: bits -= 1 num = x - 2**bits print(x - (num * 2 + 1))
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys q = int(input().strip()) for a0 in range(q): count = 0 x = int(input().strip()) a = bin(x) a = a[2:] a = a[::-1] c = -1 for i in a: c = c + 1 if i == "0": count = count + 2**c print(count)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys q = int(input().strip()) for a0 in range(q): x = int(input().strip()) binary = list(bin(x))[2:] binary.reverse() summ = 0 for idx, item in enumerate(binary): if item == "0": summ += 2**idx print(summ)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys def torevbin(n): b = "" while n > 0: b += str(n % 2) n //= 2 return b q = int(input().strip()) for a0 in range(q): x = int(input().strip()) b = torevbin(x) ans = 0 for i in range(len(b)): if b[i] == "0": ans += 2**i print(ans)
IMPORT FUNC_DEF ASSIGN VAR STRING WHILE VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys q = int(input().strip()) for a0 in range(q): c = 0 x = int(input().strip()) for i in range(35): if 2**i - 1 >= x: break print(2**i - x - 1)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys q = int(input().strip()) for a0 in range(q): x = int(input().strip()) temp = x count = 0 while temp != 0: temp = temp >> 1 count += 1 maxm = pow(2, count) - 1 print(maxm ^ x)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
def theGreatXOR(L, x): if x in L: return 0 i = 0 while L[i] < x and i < len(L) - 1: i += 1 return L[i - 1] - (x - L[i - 1] - 1) L = [ 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575, 2097151, 4194303, 8388607, 16777215, 33554431, 67108863, 134217727, 268435455, 536870911, 1073741823, 2147483647, 4294967295, 8589934591, 17179869183, ] q = int(input().strip()) for a0 in range(q): print(theGreatXOR(L, int(input().strip())))
FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys def get_binary(n): bn = str(bin(n))[2:] return bn def get_xor_vals(n): cnt = 0 bn = get_binary(n) l = len(bn) for i in range(l): if bn[i] == "0": cnt = cnt + pow(2, l - 1 - i) return cnt q = int(input().strip()) for a0 in range(q): x = int(input().strip()) print(get_xor_vals(x))
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys totals = [] q = int(input().strip()) for a0 in range(q): total = 0 x = int(input().strip()) length = len(bin(x)) - 2 for pos, val in enumerate(bin(x)[2:]): if val == "0": total += pow(2, length - pos - 1) totals.append(total) for i in totals: print(i)
IMPORT ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR STRING VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
def bits(n): m = 1 while m <= n: yield n & m m <<= 1 for _ in range(int(input())): x = int(input()) mask = (1 << len(bin(x)) - 2) - 1 print(sum(bits(x ^ mask)))
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR EXPR BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys q = int(input().strip()) for a0 in range(q): x = int(input().strip()) l = list(bin(x)[2:]) for i in range(len(l)): if l[i] == "0": l[i] = "1" else: l[i] = "0" print(int("".join(l), 2))
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR 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 VAR STRING ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys q = int(input().strip()) for a0 in range(q): x = int(input().strip()) count = 0 for i in range(x.bit_length()): mask = x >> 1 mask <<= 1 last_bit = x ^ mask if last_bit == 0: count += 2**i x >>= 1 print(count)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys q = int(input().strip()) for a0 in range(q): x = int(input().strip()) mask = 1 while mask < x: mask += mask + 1 print(mask ^ x)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
q = int(input()) for _ in range(q): x = bin(int(input()))[2:] ans = 0 for i in range(len(x)): tmp = len(x) - i - 1 if x[tmp] == "0": ans += 2**i print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
for _ in range(int(input())): n = int(input()) s = bin(n)[2:][::-1] try: i = s.rindex("0") + 1 k = 2**i - 1 for j in range(0, i): if s[j] == "1": k -= 2**j except ValueError: k = 0 print(k)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR STRING NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING VAR BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys def es_potencia_de_dos(numero): if numero < 1: return False return 0 == numero & numero - 1 q = int(input().strip()) for a0 in range(q): x = int(input().strip()) if x < 2: print(0) elif x & x - 1 is 0: print(x - 1) else: i = 1 << x.bit_length() - 1 print(i - 1 - (x - i))
IMPORT FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN NUMBER BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys def c(x): rv = 0 t = 1 while x > 0: if x & 1 == 0: rv += t x >>= 1 t <<= 1 return rv q = int(input().strip()) for a0 in range(q): x = int(input().strip()) print(c(x))
IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys def largestTwo(n): return 2 ** (len(bin(n)[2:]) - 1) q = int(input().strip()) values = [] dictionary = {} for a0 in range(q): x = int(input().strip()) if x in dictionary: print(dictionary[x]) else: twoPower = largestTwo(x) modValue = x % twoPower val = twoPower - (modValue + 1) dictionary[x] = val print(val)
IMPORT FUNC_DEF RETURN BIN_OP NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys q = int(input().strip()) for a0 in range(q): x = int(input().strip()) xt = "{0:035b}".format(x) at = "{0:035b}".format(a0) st_inx = xt.index("1") res = 0 for inx in range(st_inx + 1, len(xt)): if xt[inx] == "0": res += int(2 ** (len(xt) - 1 - inx)) print(res)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
for _ in range(int(input())): ans, t = 0, 1 for c in bin(int(input()))[:2:-1]: ans += t * (c == "0") t <<= 1 print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER VAR BIN_OP VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys q = int(input().strip()) for a0 in range(q): x = int(input().strip()) count = 0 bi = [] while x != 0: bi.insert(0, x % 2) x = x // 2 l = len(bi) for i in range(1, l): if bi[i] == 0: count += 2 ** (l - i - 1) print(count)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys def findXor(n): binary = "{0:b}".format(n) count = 0 for i in range(0, len(binary)): if binary[i] == "0": count += 2 ** (len(binary) - 1 - i) print(count) q = int(input().strip()) for a in range(q): x = int(input().strip()) findXor(x)
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys q = int(input().strip()) for a0 in range(q): x = int(input().strip()) if x == 0 or x == 1: print(0) else: bina = bin(x)[3:] l = len(bina) maxi = 2**l ans = maxi - int(bina, 2) - 1 print(ans)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys q = int(input().strip()) for a0 in range(q): x = int(input().strip()) x = bin(x) x = x[2:] x = [i for i in x] x.reverse() x = "".join(x) S = 0 for i in range(0, len(x)): if x[i] == "0": S = S + 2**i print(str(S))
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
T = int(input()) for _ in range(0, T): s = bin(int(input())) cnt = 0 n = len(s) for x in range(3, n): if s[x] == "0": cnt += 1 << n - 1 - x print(cnt)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys q = int(input().strip()) for a0 in range(q): x = int(input().strip()) x = bin(x) l = [int(s) for s in x[2:]] ans = 0 n = len(l) for i in range(n): if l[i] == 0: ans += 2 ** (n - i - 1) print(ans)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR