description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
t = int(input()) def solve(): n = int(input()) arr = map(int, input().split()) s = x = 0 for i in arr: s += i x ^= i if s & 1 == 1: print(3) x ^= 1 s += 1 print(1, x, s + x) else: print(2) print(x, s + x) for _ in range(t): solve()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
r = lambda: map(int, input().split()) I = lambda: int(input()) for _ in range(I()): n = I() summ, xorr = 0, 0 for i in r(): summ += i xorr ^= i diff = summ - xorr * 2 if abs(diff) % 2: a = 10**16 + 1 summ += a xorr ^= a b = c = xorr - summ // 2 else: a = 10**16 summ += a xorr ^= a b = c = xorr - summ // 2 print(3) print(a, b, c)
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
import sys INF = 10**10 T = int(input()) for ti in range(T): n = int(input()) A = input().split() A = [int(k) for k in A] x, s = 0, 0 for ai in A: s += ai x ^= ai print(2) print(str(x) + " " + str(s + x))
IMPORT ASSIGN VAR BIN_OP NUMBER NUMBER 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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR BIN_OP VAR VAR
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
q = int(input()) for _ in range(q): n = int(input()) a = [int(x) for x in input().split()] b = 0 for x in a: b = b ^ x c = sum(a) + b print("2") print(b, c)
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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
for x in range(int(input())): n = int(input()) ls = list(map(int, input().split())) sum = 0 xorSum = 0 for y in ls: sum += y xorSum ^= y app = [] if sum == xorSum << 1: print("0\n") continue app.append((1 << sum.bit_length() + 1) - sum) sum += app[0] xorSum ^= app[0] val = abs(sum - (xorSum << 1)) // 2 app.append(val) app.append(val) print(len(app)) print(" ".join(map(str, app)))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
t = int(input()) while t != 0: n = int(input()) list1 = list(map(int, input().split())) s, x = 0, 0 for i in range(n): x = x ^ list1[i] s = s + list1[i] print(2) print(x, x + s) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
def xsum(a): result = 0 for aa in a: result ^= aa return result def solve(): n = int(input()) a = list(map(int, input().split())) x, y = sum(a), xsum(a) print(2) print(y, x + y) def main(): t = int(input()) for _ in range(t): solve() main()
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) total = sum(a) ans = a[0] for i in range(1, n): ans = ans ^ a[i] if total == 2 * ans: print(0) print("") continue x = ans if total % 2 == 1: nums = [3] ans = ans ^ 3 nums += [ans] total = total + 3 + ans ans = 0 nums += [total] print(3) print(" ".join(str(k) for k in nums)) continue else: nums = [ans] total += ans print(2) print(nums[0], total)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR LIST VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER VAR LIST VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) s = a[0] + 0 xs = a[0] + 0 for i in range(n - 1): s += a[i + 1] xs ^= a[i + 1] if s == 2 * xs: print(0) print() else: res = [] res.append(xs) s += xs xs ^= xs res.append(s) xs ^= s s += s print(len(res)) print(*res)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
for _ in range(int(input())): a = int(input()) s1 = list(map(int, input().split())) xx = 0 for i in range(a): xx ^= s1[i] ss = sum(s1) if 2 * xx == ss: print("0") print() elif xx == 0: print("1") print(ss) else: print("2") print(xx, sum(s1) + xx)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
q = int(input()) while q: n = int(input()) a = list(map(int, input().split())) xorr = 0 summ = 0 for i in range(n): xorr = xorr ^ a[i] summ += a[i] if 2 * xorr == summ: print(0) print() elif 2 * xorr > summ: if (2 * xorr - summ) % 2 == 0: print(2) print((2 * xorr - summ) // 2, (2 * xorr - summ) // 2) else: print(2) print(xorr, summ + xorr) else: print(2) print(xorr, summ + xorr) q -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF BIN_OP NUMBER VAR VAR IF BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
def xor(l): s = 0 for i in range(len(l)): s ^= l[i] return s for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) x = xor(l) s = sum(l) if 2 * x == s: print(0) print() else: print(2) print(x, s + x)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
t = int(input()) for i in range(0, t): n = int(input()) b = input().split(" ") s = 0 x = 0 numeros = [] for j in range(0, n): b[j] = int(b[j]) s += b[j] x = x ^ b[j] if s == x * 2: pass elif s % 2 == 0 and s <= x * 2: numeros.append(int((2 * x - s) / 2)) numeros.append(int((2 * x - s) / 2)) else: numeros.append(int(s % 2 + 2**50)) x = x ^ s % 2 + 2**50 s += s % 2 + 2**50 numeros.append(int((2 * x - s) / 2)) numeros.append(int((2 * x - s) / 2)) print(len(numeros)) if len(numeros) != 0: for j in range(0, len(numeros)): if j != len(numeros) - 1: print(numeros[j], end=" ") else: print(numeros[j]) else: print("")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
t = int(input()) for _ in range(t): n = int(input()) a = list(input().split()) a = [int(x) for x in a] s = sum(a) xor = 0 for x in a: xor ^= x if s == 2 * xor: print(0) print() elif s % 2 == 0 and s < 2 * xor: print(2) print(int((2 * xor - s) / 2), int((2 * xor - s) / 2)) elif s % 2 == 1 and s < 2 * xor: if s + 1 < 2 * (xor ^ 1): print(3) print(1, int((2 * (xor ^ 1) - s - 1) / 2), int((2 * (xor ^ 1) - s - 1) / 2)) else: a = 2 * (s + 1) + 1 print(3) print(a, int((2 * (xor ^ a) - s - a) / 2), int((2 * (xor ^ a) - s - a) / 2)) elif s % 2 == 0 and s > 2 * xor: a = 2 * (s + 1) print(3) print(a, int((2 * (xor ^ a) - s - a) / 2), int((2 * (xor ^ a) - s - a) / 2)) elif s % 2 == 1 and s > 2 * xor: a = 2 * (s + 1) + 1 print(3) print(a, int((2 * (xor ^ a) - s - a) / 2), int((2 * (xor ^ a) - s - a) / 2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR IF BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR VAR VAR VAR NUMBER
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
q = int(input()) for _ in range(q): n = int(input()) sum = 0 a = list(map(int, input().split())) for i in range(0, n): sum += a[i] x = a[0] for i in range(1, n): x ^= a[i] print("2") sum += x print(x, sum)
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING VAR VAR EXPR FUNC_CALL VAR VAR VAR
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
t = int(input()) while t: t -= 1 n = int(input()) a = list(map(int, input().split())) s = sum(a) x = 0 for i in a: x ^= i if x * 2 == s: print(0) print() continue print(2) f = x se = s + x print(f, se)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
t = int(input()) for _ in range(t): input() arr = tuple(map(int, input().split())) xor = 0 for ele in arr: xor = xor ^ ele print(2) print(xor, xor + sum(arr))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
def xor_of_array(n): res = 0 for i in n: res = res ^ i return res for _ in [0] * int(input()): lens = int(input()) arrs = [int(x) for x in input().split()] sum_arrs = sum(arrs) xor_arrs = xor_of_array(arrs) print(2) print(xor_arrs, xor_arrs + sum_arrs)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR FOR VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
t = int(input()) while t > 0: n = int(input()) list = [int(i) for i in input().split()] som = 0 xor = 0 for i in range(n): xor ^= list[i] som += list[i] if som == 2 * xor: print(0) print() else: print(2) print(xor, som + xor) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
for _ in range(int(input())): n = int(input()) l = [*map(int, input().split())] total = sum(l) xor = 0 for i in l: xor ^= i if total == 2 * xor: print(0) print() elif xor == 0: print(3) print(total + 2, 1, 1) else: print(2) print(xor, xor + total)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) a_sum = 0 a_xor = 0 for x in a: a_sum += x a_xor ^= x if a_sum == 2 * a_xor: print(0) print() else: b1 = a_xor a_sum += b1 a_xor ^= b1 assert a_sum % 2 == 0 assert a_xor == 0 p = 1 while p <= a_sum: p *= 2 b1 += p b2 = 0 a_sum += p a_xor = p i = 1 while i <= p: if a_sum % (2 * i): b2 += i // 2 a_sum += i i *= 2 print("3") print(b1, b2, b2) a_sum = 0 a_xor = 0 for x in a + [b1, b2, b2]: a_sum += x a_xor ^= x assert a_sum == 2 * a_xor
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR BIN_OP VAR LIST VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP NUMBER VAR
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
h = int(input()) while h > 0: n = int(input()) h -= 1 s = 0 x = 0 k = list(map(int, input().split())) for l in k: s += l x = x ^ l print(2) print(x, s + x)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
t = int(input()) while t: t -= 1 n = int(input()) a = list(map(int, input().strip().split(" "))) y = sum(a) x = a[0] for i in a[1:]: x ^= i if y == 2 * x: print(0) print() elif x == 0: print(1) print(y) else: print(2) print(x, y + x)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR NUMBER VAR VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) ans = [] val = 0 for i in a: val ^= i if val > 0: ans.append(val) ans.append(sum(a) + val) else: ans.append(sum(a)) print(len(ans)) print(*ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
t = int(input()) LARGE = 2 << 55 for _ in range(t): n = int(input()) l = list(map(int, input().split())) l.append(LARGE) s = sum(l) if s % 2: s += 1 l[-1] += 1 x = 0 for v in l: x ^= v assert s < 2 * x diff = 2 * x - s print(3) print(l[-1], diff // 2, diff // 2)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
for _ in range(int(input())): n = int(input()) l = [int(i) for i in input().split(" ", n - 1)] s = 0 x = 0 for i in range(len(l)): s += l[i] x = x ^ l[i] print(2) print(x, s + x)
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 VAR FUNC_CALL FUNC_CALL VAR STRING BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
N = int(input()) for _ in range(N): n = int(input()) k = 0 seq = list(map(int, input().split())) s = sum(seq) for i in seq: k ^= i if k * 2 == s: print(0) print() continue ans = [] if k: ans.append(k) s += k ans.append(s) print(len(ans)) print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST IF VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
def stats(a): x, s = 0, 0 for v in a: x ^= v s += v return x, s for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) x, s = stats(a) print(2) print(x, s + x)
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
t = int(input()) for _ in range(t): n = int(input()) a = [int(x) for x in input().split()] actXor = 0 for i in a: actXor ^= i suma = sum(a) if suma == 2 * actXor: print(0) print("") else: print(2) print(actXor, suma + actXor)
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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
T = int(input()) def solve(): N = int(input()) A = list(map(int, input().split())) xor = 0 sm = 0 for a in A: xor ^= a sm += a print(2) print(xor, sm + xor) for _ in range(T): solve()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
def main(): def solve(): n = int(input()) aa = [int(a) for a in input().split()] sum = 0 xor = 0 for a in aa: sum += a xor ^= a print(2) print(xor, xor + sum) q = int(input()) for _ in range(q): solve() main()
FUNC_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
t = int(input()) for q in range(t): n = int(input()) a = list(map(int, input().split())) ans1 = 0 ans2 = 0 for i in range(len(a)): ans1 += a[i] ans2 = ans2 ^ a[i] v = 2 print(3) if ans1 % 2 == 1: c2 = ans2 c1 = ans1 c1 += 2**55 + 1 c2 = c2 ^ 2**55 + 1 ans2 = ans2 ^ 2**55 + 1 ans2 = ans2 * 2 ans1 += 2**55 + 1 u = (ans2 - ans1) // 2 c1 += u + u c2 = c2 ^ u c2 = c2 ^ u print(2**55 + 1, u, u) else: ans2 = ans2 ^ 2**55 ans2 = ans2 * 2 ans1 += 2**55 c2 = ans2 c1 = ans1 u = (ans2 - ans1) // 2 print(2**55, u, u)
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER VAR VAR
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split())) res = 0 sa = 0 for i in a: res ^= i sa += i if sa % 2: mnum = (1 << 59) - 1 else: mnum = 1 << 59 res = (mnum ^ res) * 2 snum = (res - sa - mnum) // 2 print(3) print(mnum, snum, snum)
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
def solve(arr): xor = 0 for i in arr: xor ^= i return [xor, sum(arr) + xor] T = int(input()) for i in range(T): _ = int(input()) arr = list(map(int, input().split())) print(len(solve(arr))) print(" ".join(map(str, solve(arr))))
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR RETURN LIST VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR FUNC_CALL VAR VAR
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
for tc in [0] * int(input()): n = int(input()) l = list(map(int, input().split())) x = l[0] for i in l[1:]: x = x ^ i xx = sum(l) if 2 * x == xx: print(0) print() else: print(2) print(x, xx + x)
FOR VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplus 6)$. At the same time, array $[1, 2, 1, 3]$ isn't good, as $1 + 2 + 1 + 3 = 7 \neq 2\cdot 1 = 2\cdot(1\oplus 2 \oplus 1 \oplus 3)$. You are given an array of length $n$: $a_1, a_2, \dots, a_n$. Append at most $3$ elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). The description of the test cases follows. The first line of each test case contains a single integer $n$ $(1\le n \le 10^5)$Β β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0\le a_i \le 10^9$)Β β€” the elements of the array. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case, output two lines. In the first line, output a single integer $s$ ($0\le s\le 3$)Β β€” the number of elements you want to append. In the second line, output $s$ integers $b_1, \dots, b_s$ ($0\le b_i \le 10^{18}$)Β β€” the elements you want to append to the array. If there are different solutions, you are allowed to output any of them. -----Example----- Input 3 4 1 2 3 6 1 8 2 1 1 Output 0 2 4 4 3 2 6 2 -----Note----- In the first test case of the example, the sum of all numbers is $12$, and their $\oplus$ is $6$, so the condition is already satisfied. In the second test case of the example, after adding $4, 4$, the array becomes $[8, 4, 4]$. The sum of numbers in it is $16$, $\oplus$ of numbers in it is $8$.
t = int(input()) z = [] k = [] for i in range(t): x = [] n = int(input()) a = list(map(int, input().split())) sum1 = sum(a) xor = 0 for j in range(len(a)): xor = xor ^ a[j] if sum1 == 2 * xor: z.append(0) else: x.append(xor + sum1) x.append(xor) k.append(x) z.append(2) j = 0 for i in range(len(z)): if z[i] == 0: print(z[i]) print() else: print(z[i]) print(k[j][0], end=" ") print(k[j][1]) j += 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER
Xorq has invented an encryption algorithm which uses bitwise XOR operations extensively. This encryption algorithm uses a sequence of non-negative integers $x=[x[1],x[2]\cdots x[n]]$ as its key. To implement this algorithm efficiently, Xorq needs to find maximum value of $(a\oplus x_j)$ for given integers $\class{ML__boldsymbol}{\boldsymbol{a}}$, $\boldsymbol{l}$ and $\textbf{r}$, such that, $l\leq j\leq r$. Help Xorq implement this function. For example, $x=[3,5,9]$, $\boldsymbol{a}=4$, $l=1$ and $r=3$. We test each $x[j]$ for all values of $j$ between $\boldsymbol{l}$ and $\textbf{r}$ inclusive: j x[j] x[j]^4 1 3 7 2 5 1 3 9 13 Our maximum value is $13$. Function Description Complete the xorKey function in the editor below. It should return an integer array where each value is the response to a query. xorKey has the following parameters: x: a list of integers queries: a two dimensional array where each element is an integer array that consists of $a[i],l[i],r[i]$ for the $i^{\mbox{th}}$ query at indices $\mathbf{0,1}$ and $2$ respectively. Input Format The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of test cases. The first line of each test case contains two space-separated integers $n$ and $\textit{q}$, the size of the integer array $\boldsymbol{x}$ and the number of queries against the test case. The next line contains $n$ space-separated integers $x[j]$. Each of next $\textit{q}$ lines describes a query which consists of three integers $a[i],\ l[i]$ and $r[i]$. Constraints $1\leq n\leq100000$ $1\leq q\leq50000$ $0\leq x[j],a[i]\leq2^{15}$ $1\leq l[i],r[i]\leq n$ Output Format For each query, print the maximum value for $\left(a[i]\oplus x[j]\right)$, such that, $l[i]\leq j\leq r[i]$ on a new line. Sample Input 0 1 15 8 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 10 6 10 1023 7 7 33 5 8 182 5 10 181 1 13 5 10 15 99 8 9 33 10 14 Sample Output 0 13 1016 41 191 191 15 107 47 Explanation 0 First Query (10 6 10): $x_6\oplus10=12,x_7\oplus10=13,x_8\oplus10=2,x_9\oplus10=3,x_{10}\oplus10=0$. The maximum is $13$. Second Query (1023 7 7): $x_7\oplus1023=1016$ Third Query (33 5 8): $x_5\oplus33=36,x_6\oplus33=39,x_7\oplus33=38,x_8\oplus33=41$ Fourth Query (182 5 10): $\textbf{x}_5\oplus182=179,\textbf{x}_6\oplus182=176,\textbf{x}_7\oplus182=177,\textbf{x}_8\oplus182=190,\textbf{x}_9\oplus182=191,\textbf{x}_{20}\oplus182=188$
for _ in range(int(input())): N, Q = map(int, input().split()) x = list(map(int, input().split())) assert len(x) == N queries = [] for j in range(Q): a, p, q = map(int, input().split()) assert 1 <= p <= q <= N queries.append((q - 1, p - 1, a, j)) assert len(queries) == Q queries.sort() answers = [0] * Q maxi = [-1] * 65536 qnxt = 0 for i in range(N): xi = x[i] assert 0 <= xi < 32768 k = xi + 32768 while k > 0: if maxi[k] < i: maxi[k] = i k //= 2 while qnxt < Q and queries[qnxt][0] == i: q, p, a, j = queries[qnxt] qnxt += 1 k = 1 b = 14 while b >= 0: prefer = 1 - (a >> b) & 1 k = 2 * k + prefer if maxi[k] < p: k ^= 1 assert maxi[k] >= p b -= 1 assert k >= 32768 answers[j] = a ^ k - 32768 for v in answers: print(v)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR
Xorq has invented an encryption algorithm which uses bitwise XOR operations extensively. This encryption algorithm uses a sequence of non-negative integers $x=[x[1],x[2]\cdots x[n]]$ as its key. To implement this algorithm efficiently, Xorq needs to find maximum value of $(a\oplus x_j)$ for given integers $\class{ML__boldsymbol}{\boldsymbol{a}}$, $\boldsymbol{l}$ and $\textbf{r}$, such that, $l\leq j\leq r$. Help Xorq implement this function. For example, $x=[3,5,9]$, $\boldsymbol{a}=4$, $l=1$ and $r=3$. We test each $x[j]$ for all values of $j$ between $\boldsymbol{l}$ and $\textbf{r}$ inclusive: j x[j] x[j]^4 1 3 7 2 5 1 3 9 13 Our maximum value is $13$. Function Description Complete the xorKey function in the editor below. It should return an integer array where each value is the response to a query. xorKey has the following parameters: x: a list of integers queries: a two dimensional array where each element is an integer array that consists of $a[i],l[i],r[i]$ for the $i^{\mbox{th}}$ query at indices $\mathbf{0,1}$ and $2$ respectively. Input Format The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of test cases. The first line of each test case contains two space-separated integers $n$ and $\textit{q}$, the size of the integer array $\boldsymbol{x}$ and the number of queries against the test case. The next line contains $n$ space-separated integers $x[j]$. Each of next $\textit{q}$ lines describes a query which consists of three integers $a[i],\ l[i]$ and $r[i]$. Constraints $1\leq n\leq100000$ $1\leq q\leq50000$ $0\leq x[j],a[i]\leq2^{15}$ $1\leq l[i],r[i]\leq n$ Output Format For each query, print the maximum value for $\left(a[i]\oplus x[j]\right)$, such that, $l[i]\leq j\leq r[i]$ on a new line. Sample Input 0 1 15 8 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 10 6 10 1023 7 7 33 5 8 182 5 10 181 1 13 5 10 15 99 8 9 33 10 14 Sample Output 0 13 1016 41 191 191 15 107 47 Explanation 0 First Query (10 6 10): $x_6\oplus10=12,x_7\oplus10=13,x_8\oplus10=2,x_9\oplus10=3,x_{10}\oplus10=0$. The maximum is $13$. Second Query (1023 7 7): $x_7\oplus1023=1016$ Third Query (33 5 8): $x_5\oplus33=36,x_6\oplus33=39,x_7\oplus33=38,x_8\oplus33=41$ Fourth Query (182 5 10): $\textbf{x}_5\oplus182=179,\textbf{x}_6\oplus182=176,\textbf{x}_7\oplus182=177,\textbf{x}_8\oplus182=190,\textbf{x}_9\oplus182=191,\textbf{x}_{20}\oplus182=188$
def build_trie(sequence): root = [None, None, [], []] for idx, item in enumerate(sequence): current = root for shift in range(14, -1, -1): bit = item >> shift & 1 if current[bit] is None: current[bit] = [None, None, [], []] current[bit + 2].append(idx) current = current[bit] return root def range_in_ordered_list(ordlist, minrange, maxrange): min_index = 0 max_index = len(ordlist) while True: index = min_index + (max_index - min_index >> 1) value = ordlist[index] if value >= minrange and value <= maxrange: return True if max_index <= min_index + 1: return False if value >= maxrange: max_index = index elif value < minrange: min_index = index def get_max_xor_in_trie(nums, root, a, minrange, maxrange): besta = 32767 & ~a for shift in range(14, 0, -1): bit = besta >> shift & 1 if root[bit] == None or not range_in_ordered_list( root[bit + 2], minrange, maxrange ): bit = bit ^ 1 root = root[bit] bit = besta & 1 if root[bit] == None or not range_in_ordered_list( root[bit + 2], minrange, maxrange ): bit = bit ^ 1 return nums[root[bit + 2][0]] ^ a t = int(input().strip()) for ti in range(t): n, q = [int(x) for x in input().strip().split()] numbers = [int(x) for x in input().strip().split()] root = build_trie(numbers) for i in range(q): ai, pi, qi = [int(x) for x in input().strip().split()] res0 = get_max_xor_in_trie(numbers, root, ai, pi - 1, qi - 1) print(res0)
FUNC_DEF ASSIGN VAR LIST NONE NONE LIST LIST FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NONE ASSIGN VAR VAR LIST NONE NONE LIST LIST EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR VAR RETURN NUMBER IF VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NONE FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NONE FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Xorq has invented an encryption algorithm which uses bitwise XOR operations extensively. This encryption algorithm uses a sequence of non-negative integers $x=[x[1],x[2]\cdots x[n]]$ as its key. To implement this algorithm efficiently, Xorq needs to find maximum value of $(a\oplus x_j)$ for given integers $\class{ML__boldsymbol}{\boldsymbol{a}}$, $\boldsymbol{l}$ and $\textbf{r}$, such that, $l\leq j\leq r$. Help Xorq implement this function. For example, $x=[3,5,9]$, $\boldsymbol{a}=4$, $l=1$ and $r=3$. We test each $x[j]$ for all values of $j$ between $\boldsymbol{l}$ and $\textbf{r}$ inclusive: j x[j] x[j]^4 1 3 7 2 5 1 3 9 13 Our maximum value is $13$. Function Description Complete the xorKey function in the editor below. It should return an integer array where each value is the response to a query. xorKey has the following parameters: x: a list of integers queries: a two dimensional array where each element is an integer array that consists of $a[i],l[i],r[i]$ for the $i^{\mbox{th}}$ query at indices $\mathbf{0,1}$ and $2$ respectively. Input Format The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of test cases. The first line of each test case contains two space-separated integers $n$ and $\textit{q}$, the size of the integer array $\boldsymbol{x}$ and the number of queries against the test case. The next line contains $n$ space-separated integers $x[j]$. Each of next $\textit{q}$ lines describes a query which consists of three integers $a[i],\ l[i]$ and $r[i]$. Constraints $1\leq n\leq100000$ $1\leq q\leq50000$ $0\leq x[j],a[i]\leq2^{15}$ $1\leq l[i],r[i]\leq n$ Output Format For each query, print the maximum value for $\left(a[i]\oplus x[j]\right)$, such that, $l[i]\leq j\leq r[i]$ on a new line. Sample Input 0 1 15 8 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 10 6 10 1023 7 7 33 5 8 182 5 10 181 1 13 5 10 15 99 8 9 33 10 14 Sample Output 0 13 1016 41 191 191 15 107 47 Explanation 0 First Query (10 6 10): $x_6\oplus10=12,x_7\oplus10=13,x_8\oplus10=2,x_9\oplus10=3,x_{10}\oplus10=0$. The maximum is $13$. Second Query (1023 7 7): $x_7\oplus1023=1016$ Third Query (33 5 8): $x_5\oplus33=36,x_6\oplus33=39,x_7\oplus33=38,x_8\oplus33=41$ Fourth Query (182 5 10): $\textbf{x}_5\oplus182=179,\textbf{x}_6\oplus182=176,\textbf{x}_7\oplus182=177,\textbf{x}_8\oplus182=190,\textbf{x}_9\oplus182=191,\textbf{x}_{20}\oplus182=188$
def normalized_bin(x): x = [int(t) for t in bin(x)[2:]] return [0] * (15 - len(x)) + x def add_list(data, L, f, t, p): if L[f][1] & p: data[1] = {"w": data["w"] if "w" in data else sorted(i for i, v in L[f:t])} if p > 1: add_list(data[1], L, f, t, p >> 1) return if not L[t - 1][1] & p: data[0] = {"w": data["w"] if "w" in data else sorted(i for i, v in L[f:t])} if p > 1: add_list(data[0], L, f, t, p >> 1) return l = f r = t - 1 while l < r: mi = l + r >> 1 m = L[mi][1] if not m & p: l = mi + 1 else: r = mi - 1 if L[l][1] & p: m = l if l <= f or not L[l - 1][1] & p else l - 1 else: m = l + 1 data[0] = {"w": sorted(i for i, v in L[f:m])} data[1] = {"w": sorted(i for i, v in L[m:t])} p >>= 1 if p: add_list(data[0], L, f, m, p) add_list(data[1], L, m, t, p) t = int(input()) for _ in range(t): n, q = [int(tmp) for tmp in input().strip().split()] x_list = [int(t) for t in input().strip().split()] L = list(enumerate(x_list, start=1)) L.sort(key=lambda t: t[1]) data = dict() add_list(data, L, 0, len(L), 1 << 14) for _ in range(q): a, p, q = [int(tmp) for tmp in input().strip().split()] tmp = data for d in normalized_bin(a): if 1 - d in tmp: if d not in tmp: tmp = tmp[1 - d] else: idxes = tmp[1 - d]["w"] l = 0 r = len(idxes) - 1 while l <= r: mi = l + r >> 1 m = idxes[mi] if p > m: l = mi + 1 elif q < m: r = mi - 1 else: tmp = tmp[1 - d] break else: tmp = tmp[d] else: tmp = tmp[d] print(a ^ x_list[tmp["w"][0] - 1])
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER RETURN BIN_OP BIN_OP LIST NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR VAR FUNC_DEF IF BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER DICT STRING STRING VAR VAR STRING FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER RETURN IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER DICT STRING STRING VAR VAR STRING FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER RETURN ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER DICT STRING FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER DICT STRING FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR 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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR BIN_OP NUMBER VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR STRING NUMBER NUMBER
Xorq has invented an encryption algorithm which uses bitwise XOR operations extensively. This encryption algorithm uses a sequence of non-negative integers $x=[x[1],x[2]\cdots x[n]]$ as its key. To implement this algorithm efficiently, Xorq needs to find maximum value of $(a\oplus x_j)$ for given integers $\class{ML__boldsymbol}{\boldsymbol{a}}$, $\boldsymbol{l}$ and $\textbf{r}$, such that, $l\leq j\leq r$. Help Xorq implement this function. For example, $x=[3,5,9]$, $\boldsymbol{a}=4$, $l=1$ and $r=3$. We test each $x[j]$ for all values of $j$ between $\boldsymbol{l}$ and $\textbf{r}$ inclusive: j x[j] x[j]^4 1 3 7 2 5 1 3 9 13 Our maximum value is $13$. Function Description Complete the xorKey function in the editor below. It should return an integer array where each value is the response to a query. xorKey has the following parameters: x: a list of integers queries: a two dimensional array where each element is an integer array that consists of $a[i],l[i],r[i]$ for the $i^{\mbox{th}}$ query at indices $\mathbf{0,1}$ and $2$ respectively. Input Format The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of test cases. The first line of each test case contains two space-separated integers $n$ and $\textit{q}$, the size of the integer array $\boldsymbol{x}$ and the number of queries against the test case. The next line contains $n$ space-separated integers $x[j]$. Each of next $\textit{q}$ lines describes a query which consists of three integers $a[i],\ l[i]$ and $r[i]$. Constraints $1\leq n\leq100000$ $1\leq q\leq50000$ $0\leq x[j],a[i]\leq2^{15}$ $1\leq l[i],r[i]\leq n$ Output Format For each query, print the maximum value for $\left(a[i]\oplus x[j]\right)$, such that, $l[i]\leq j\leq r[i]$ on a new line. Sample Input 0 1 15 8 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 10 6 10 1023 7 7 33 5 8 182 5 10 181 1 13 5 10 15 99 8 9 33 10 14 Sample Output 0 13 1016 41 191 191 15 107 47 Explanation 0 First Query (10 6 10): $x_6\oplus10=12,x_7\oplus10=13,x_8\oplus10=2,x_9\oplus10=3,x_{10}\oplus10=0$. The maximum is $13$. Second Query (1023 7 7): $x_7\oplus1023=1016$ Third Query (33 5 8): $x_5\oplus33=36,x_6\oplus33=39,x_7\oplus33=38,x_8\oplus33=41$ Fourth Query (182 5 10): $\textbf{x}_5\oplus182=179,\textbf{x}_6\oplus182=176,\textbf{x}_7\oplus182=177,\textbf{x}_8\oplus182=190,\textbf{x}_9\oplus182=191,\textbf{x}_{20}\oplus182=188$
from sys import stderr MAXBITS = 15 def main(): ncases = int(input()) for case in range(ncases): arrsize, nqueries = readints() arr = readints() assert arrsize == len(arr) finder = XORkeyfinder(arr) for query in range(nqueries): a, start, stop = readints() print(finder.findmax(a, start - 1, stop)) def readints(): return [int(f) for f in input().split()] class XORkeyfinder: def __init__(self, arr): self.tbl = [] self.arr = arr for i in range(MAXBITS): shift = MAXBITS - i - 1 prev = [None] * (2 << i) row = [len(arr)] * len(arr) chain = [None] * len(arr) for loc, x in enumerate(arr): x = x >> shift p = prev[x ^ 1] while p is not None: row[p] = loc p = chain[p] prev[x ^ 1] = None chain[loc] = prev[x] prev[x] = loc self.tbl.append(row) def findmax(self, a, start, stop, MAXBITS=MAXBITS): arr, tbl = self.arr, self.tbl comp = ~a best, bestloc = arr[start], start for i, row in enumerate(tbl): test = 1 << MAXBITS - i - 1 if comp & test != best & test: newloc = row[bestloc] if newloc < stop: best, bestloc = arr[newloc], newloc return best ^ a main()
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NONE BIN_OP NUMBER VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NONE FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER WHILE VAR NONE ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NONE ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR RETURN BIN_OP VAR VAR EXPR FUNC_CALL VAR
Given two arrays A and B each of length N. Find the value \sum_{i=1}^N\sum_{j=1}^N \max(A_{i}\oplus B_{j},A_{i}\& B_{j}). Here \oplus and \& denote the [bitwise XOR operation] and [bitwise AND operation] respectively. ------ 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 line of each test case contains an integer N - the length of arrays A and B. - The second line of each test case contains N space-separated integers A_{1},A_{2},…,A_{N} representing the array A. - The third line of each test case contains N space-separated integers B_{1},B_{2},…,B_{N} representing the array B. ------ Output Format ------ For each test case, output the value \sum_{i=1}^N\sum_{j=1}^N \max(A_{i}\oplus B_{j},A_{i}\& B_{j}). ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $0 ≀ A_{i}, B_{i} < 2^{20}$ - Sum of $N$ does not exceed $2\cdot 10^{5}$ over all test cases. ----- Sample Input 1 ------ 3 2 3 4 1 2 1 0 0 3 2 4 3 1 2 1 ----- Sample Output 1 ------ 15 0 30 ----- explanation 1 ------ - Test Case $1$: For the given arrays, the value is: $\max(3\oplus 1,3\& 1) + \max(3\oplus 2,3\& 2) + \max(4\oplus 1,4\& 1) + \max(4\oplus 2,4\& 2) = 2 + 2 + 5 + 6 = 15$. - Test Case $2$: For the given arrays, the value is: $\max(0\oplus 0,0\& 0) = 0$. - Test Case $3$: For the given arrays, the value is: $\max(2\oplus 1,2\& 1) + \max(2\oplus 2,2\& 2) + \max(2\oplus 1,2\& 1) + \max(4\oplus 1,4\& 1) + \max(4\oplus 2,4\& 2) + \max(4\oplus 1,4\& 1) + \max(3\oplus 1,3\& 1) + \max(3\oplus 2,3\& 2) + \max(3\oplus 1,3\& 1)$ $= 3 + 2 + 3 + 5 + 6 + 5 + 2 + 2 + 2 = 30$.
import sys input = sys.stdin.readline for t in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) setbit = [(0) for i in range(20)] msbbit = [(0) for i in range(20)] mat = [[(0) for i in range(20)] for j in range(20)] tot = 0 for i in range(n): tot += a[i] k = -1 for j in range(20): if a[i] & 1 << j != 0: setbit[j] += 1 k = j if k != -1: msbbit[k] += 1 for j in range(20): if a[i] & 1 << j != 0: mat[k][j] += 1 ans = 0 for i in range(n): k = -1 for j in range(20): if b[i] & 1 << j != 0: k = j if k == -1: ans += tot continue for j in range(20): if b[i] & 1 << j: ans += (1 << j) * mat[k][j] ans += (1 << j) * (n - msbbit[k] - (setbit[j] - mat[k][j])) else: ans += (1 << j) * (setbit[j] - mat[k][j]) sys.stdout.write(str(ans) + "\n")
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING
Given two arrays A and B each of length N. Find the value \sum_{i=1}^N\sum_{j=1}^N \max(A_{i}\oplus B_{j},A_{i}\& B_{j}). Here \oplus and \& denote the [bitwise XOR operation] and [bitwise AND operation] respectively. ------ 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 line of each test case contains an integer N - the length of arrays A and B. - The second line of each test case contains N space-separated integers A_{1},A_{2},…,A_{N} representing the array A. - The third line of each test case contains N space-separated integers B_{1},B_{2},…,B_{N} representing the array B. ------ Output Format ------ For each test case, output the value \sum_{i=1}^N\sum_{j=1}^N \max(A_{i}\oplus B_{j},A_{i}\& B_{j}). ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $0 ≀ A_{i}, B_{i} < 2^{20}$ - Sum of $N$ does not exceed $2\cdot 10^{5}$ over all test cases. ----- Sample Input 1 ------ 3 2 3 4 1 2 1 0 0 3 2 4 3 1 2 1 ----- Sample Output 1 ------ 15 0 30 ----- explanation 1 ------ - Test Case $1$: For the given arrays, the value is: $\max(3\oplus 1,3\& 1) + \max(3\oplus 2,3\& 2) + \max(4\oplus 1,4\& 1) + \max(4\oplus 2,4\& 2) = 2 + 2 + 5 + 6 = 15$. - Test Case $2$: For the given arrays, the value is: $\max(0\oplus 0,0\& 0) = 0$. - Test Case $3$: For the given arrays, the value is: $\max(2\oplus 1,2\& 1) + \max(2\oplus 2,2\& 2) + \max(2\oplus 1,2\& 1) + \max(4\oplus 1,4\& 1) + \max(4\oplus 2,4\& 2) + \max(4\oplus 1,4\& 1) + \max(3\oplus 1,3\& 1) + \max(3\oplus 2,3\& 2) + \max(3\oplus 1,3\& 1)$ $= 3 + 2 + 3 + 5 + 6 + 5 + 2 + 2 + 2 = 30$.
def get_msb(n): ans = -1 for j in range(21): if 1 << j & n: ans = j return ans for _ in range(int(input())): N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) msb = [0] * 21 bits = [0] * 21 bit_table = [([0] * 21) for j in range(21)] s = 0 for i in range(N): a = A[i] s += a k = get_msb(a) if k != -1: msb[k] += 1 for j in range(k + 1): if 1 << j & a: bits[j] += 1 bit_table[k][j] += 1 res = 0 for i in range(N): if B[i] == 0: res += s else: k = get_msb(B[i]) for j in range(21): if 1 << j & B[i]: res += (1 << j) * bit_table[k][j] res += (1 << j) * (N - bits[j] - msb[k] + bit_table[k][j]) else: res += (1 << j) * (bits[j] - bit_table[k][j]) print(res)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Given an array A_{1}, A_{2} \ldots A_{N}, find the minimum number of operations (possibly zero) required to convert all integers in A to 0. In one operation, you choose a non-negative integer p (p β‰₯ 0), select at most K indices in the array A, and for each selected index i, replace A_{i} with A_{i}\oplus 2^{p}. Here, \oplus denotes bitwise XOR. ------ Subtasks ------ Subtask #1 (100 points): Original Constraints ------ Input Format ------ - The first line contains an integer T - the number of test cases. Then T test cases follow. - The first line of each test case contains two integers N, K - the size of the array and the maximum number of elements you can select in an operation. - The second line of each test case contains N integers A_{1}, A_{2} \ldots A_{N}. ------ Output Format ------ For each test case, output the minimum number of operations to make all elements of the array 0. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N, K ≀ 10^{5}$ $0 ≀ A_{i} ≀ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$ ----- Sample Input 1 ------ 1 3 2 3 6 10 ----- Sample Output 1 ------ 5 ----- explanation 1 ------ Here is one way to achieve $[0, 0, 0]$ from $[3, 6, 10]$ in $5$ operations: 1. Choose $p = 0$ and indices $\{1\}$. Now $A$ becomes $[2, 6, 10]$. 2. Choose $p = 1$ and indices $\{1,2\}$. Now $A$ becomes $[0, 4, 10]$. 3. Choose $p = 1$ and indices $\{3\}$. Now $A$ becomes $[0, 4, 8]$. 4. Choose $p = 2$ and indices $\{2\}$. Now $A$ becomes $[0, 0, 8]$. 5. Choose $p = 3$ and indices $\{3\}$. Now $A$ becomes $[0, 0, 0]$. It can be shown that at least $5$ operations are required.
t = int(input()) for i in range(t): n, ki = map(int, input().split()) a = list(map(int, input().split())) l = [] for j in range(n): l.append(bin(a[j]).replace("0b", "")) for b in range(n): l[b] = int(l[b]) ans = 0 m = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ] for x in range(0, n): for k in range(0, 31): if l[x] != 0: m[k] += l[x] % 10 l[x] = l[x] // 10 for z in range(0, 31): if m[z] % ki == 0: ans += m[z] // ki else: ans += m[z] // ki + 1 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR VAR STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR 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 FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Given an array A_{1}, A_{2} \ldots A_{N}, find the minimum number of operations (possibly zero) required to convert all integers in A to 0. In one operation, you choose a non-negative integer p (p β‰₯ 0), select at most K indices in the array A, and for each selected index i, replace A_{i} with A_{i}\oplus 2^{p}. Here, \oplus denotes bitwise XOR. ------ Subtasks ------ Subtask #1 (100 points): Original Constraints ------ Input Format ------ - The first line contains an integer T - the number of test cases. Then T test cases follow. - The first line of each test case contains two integers N, K - the size of the array and the maximum number of elements you can select in an operation. - The second line of each test case contains N integers A_{1}, A_{2} \ldots A_{N}. ------ Output Format ------ For each test case, output the minimum number of operations to make all elements of the array 0. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N, K ≀ 10^{5}$ $0 ≀ A_{i} ≀ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$ ----- Sample Input 1 ------ 1 3 2 3 6 10 ----- Sample Output 1 ------ 5 ----- explanation 1 ------ Here is one way to achieve $[0, 0, 0]$ from $[3, 6, 10]$ in $5$ operations: 1. Choose $p = 0$ and indices $\{1\}$. Now $A$ becomes $[2, 6, 10]$. 2. Choose $p = 1$ and indices $\{1,2\}$. Now $A$ becomes $[0, 4, 10]$. 3. Choose $p = 1$ and indices $\{3\}$. Now $A$ becomes $[0, 4, 8]$. 4. Choose $p = 2$ and indices $\{2\}$. Now $A$ becomes $[0, 0, 8]$. 5. Choose $p = 3$ and indices $\{3\}$. Now $A$ becomes $[0, 0, 0]$. It can be shown that at least $5$ operations are required.
no_of_cases = int(input()) for i in range(0, no_of_cases): lenght, operation = map(int, input().split()) arr = list(map(int, input().split())) steps = 0 for k in range(0, 32): count = 0 for index in range(0, lenght): if arr[index] % 2 == 0: arr[index] = arr[index] / 2 else: count += 1 arr[index] = arr[index] // 2 steps += count / operation if count % operation == 0 else count // operation + 1 print(int(steps))
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 VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Given an array A_{1}, A_{2} \ldots A_{N}, find the minimum number of operations (possibly zero) required to convert all integers in A to 0. In one operation, you choose a non-negative integer p (p β‰₯ 0), select at most K indices in the array A, and for each selected index i, replace A_{i} with A_{i}\oplus 2^{p}. Here, \oplus denotes bitwise XOR. ------ Subtasks ------ Subtask #1 (100 points): Original Constraints ------ Input Format ------ - The first line contains an integer T - the number of test cases. Then T test cases follow. - The first line of each test case contains two integers N, K - the size of the array and the maximum number of elements you can select in an operation. - The second line of each test case contains N integers A_{1}, A_{2} \ldots A_{N}. ------ Output Format ------ For each test case, output the minimum number of operations to make all elements of the array 0. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N, K ≀ 10^{5}$ $0 ≀ A_{i} ≀ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$ ----- Sample Input 1 ------ 1 3 2 3 6 10 ----- Sample Output 1 ------ 5 ----- explanation 1 ------ Here is one way to achieve $[0, 0, 0]$ from $[3, 6, 10]$ in $5$ operations: 1. Choose $p = 0$ and indices $\{1\}$. Now $A$ becomes $[2, 6, 10]$. 2. Choose $p = 1$ and indices $\{1,2\}$. Now $A$ becomes $[0, 4, 10]$. 3. Choose $p = 1$ and indices $\{3\}$. Now $A$ becomes $[0, 4, 8]$. 4. Choose $p = 2$ and indices $\{2\}$. Now $A$ becomes $[0, 0, 8]$. 5. Choose $p = 3$ and indices $\{3\}$. Now $A$ becomes $[0, 0, 0]$. It can be shown that at least $5$ operations are required.
we = int(input()) for i in range(we): n, k = map(int, input().split()) l = list(map(int, input().split())) c = 0 g = [] for i in l: d = str(bin(i)) d = d[2:] g.append([d, len(d)]) if len(d) > c: c = len(d) r = [] for i in g: y = [] for j in range(c - i[1]): y.append("0") for j in i[0]: y.append(j) r.append(y) s = 0 for i in range(c): f = 0 for j in range(len(l)): if r[j][i] == "1": f += 1 if f % k != 0: s = s + 1 + f // k else: s = s + f // k print(s)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Given an array A_{1}, A_{2} \ldots A_{N}, find the minimum number of operations (possibly zero) required to convert all integers in A to 0. In one operation, you choose a non-negative integer p (p β‰₯ 0), select at most K indices in the array A, and for each selected index i, replace A_{i} with A_{i}\oplus 2^{p}. Here, \oplus denotes bitwise XOR. ------ Subtasks ------ Subtask #1 (100 points): Original Constraints ------ Input Format ------ - The first line contains an integer T - the number of test cases. Then T test cases follow. - The first line of each test case contains two integers N, K - the size of the array and the maximum number of elements you can select in an operation. - The second line of each test case contains N integers A_{1}, A_{2} \ldots A_{N}. ------ Output Format ------ For each test case, output the minimum number of operations to make all elements of the array 0. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N, K ≀ 10^{5}$ $0 ≀ A_{i} ≀ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$ ----- Sample Input 1 ------ 1 3 2 3 6 10 ----- Sample Output 1 ------ 5 ----- explanation 1 ------ Here is one way to achieve $[0, 0, 0]$ from $[3, 6, 10]$ in $5$ operations: 1. Choose $p = 0$ and indices $\{1\}$. Now $A$ becomes $[2, 6, 10]$. 2. Choose $p = 1$ and indices $\{1,2\}$. Now $A$ becomes $[0, 4, 10]$. 3. Choose $p = 1$ and indices $\{3\}$. Now $A$ becomes $[0, 4, 8]$. 4. Choose $p = 2$ and indices $\{2\}$. Now $A$ becomes $[0, 0, 8]$. 5. Choose $p = 3$ and indices $\{3\}$. Now $A$ becomes $[0, 0, 0]$. It can be shown that at least $5$ operations are required.
try: for i in range(int(input())): n, k = map(int, input().split()) arr = list(map(int, input().split())) binary = [] for i in range(0, 31): binary.append(0) for j in range(n): if arr[j] % 2 != 0: binary[i] += 1 arr[j] = arr[j] // 2 ans = 0 for i in range(0, 31): if binary[i] % k == 0: ans += binary[i] // k else: ans += binary[i] // k + 1 print(ans) except: pass
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Given an array A_{1}, A_{2} \ldots A_{N}, find the minimum number of operations (possibly zero) required to convert all integers in A to 0. In one operation, you choose a non-negative integer p (p β‰₯ 0), select at most K indices in the array A, and for each selected index i, replace A_{i} with A_{i}\oplus 2^{p}. Here, \oplus denotes bitwise XOR. ------ Subtasks ------ Subtask #1 (100 points): Original Constraints ------ Input Format ------ - The first line contains an integer T - the number of test cases. Then T test cases follow. - The first line of each test case contains two integers N, K - the size of the array and the maximum number of elements you can select in an operation. - The second line of each test case contains N integers A_{1}, A_{2} \ldots A_{N}. ------ Output Format ------ For each test case, output the minimum number of operations to make all elements of the array 0. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N, K ≀ 10^{5}$ $0 ≀ A_{i} ≀ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$ ----- Sample Input 1 ------ 1 3 2 3 6 10 ----- Sample Output 1 ------ 5 ----- explanation 1 ------ Here is one way to achieve $[0, 0, 0]$ from $[3, 6, 10]$ in $5$ operations: 1. Choose $p = 0$ and indices $\{1\}$. Now $A$ becomes $[2, 6, 10]$. 2. Choose $p = 1$ and indices $\{1,2\}$. Now $A$ becomes $[0, 4, 10]$. 3. Choose $p = 1$ and indices $\{3\}$. Now $A$ becomes $[0, 4, 8]$. 4. Choose $p = 2$ and indices $\{2\}$. Now $A$ becomes $[0, 0, 8]$. 5. Choose $p = 3$ and indices $\{3\}$. Now $A$ becomes $[0, 0, 0]$. It can be shown that at least $5$ operations are required.
t = int(input()) while t > 0: n, k = map(int, input().split()) l = list(map(int, input().split())) bit = [(0) for i in range(32)] for i in l: for x in range(0, 32): val = i & 1 << x if val != 0: bit[x] += 1 ans = 0 for i in bit: if i % k == 0: ans += i // k else: ans += i // k + 1 print(ans) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Given an array A_{1}, A_{2} \ldots A_{N}, find the minimum number of operations (possibly zero) required to convert all integers in A to 0. In one operation, you choose a non-negative integer p (p β‰₯ 0), select at most K indices in the array A, and for each selected index i, replace A_{i} with A_{i}\oplus 2^{p}. Here, \oplus denotes bitwise XOR. ------ Subtasks ------ Subtask #1 (100 points): Original Constraints ------ Input Format ------ - The first line contains an integer T - the number of test cases. Then T test cases follow. - The first line of each test case contains two integers N, K - the size of the array and the maximum number of elements you can select in an operation. - The second line of each test case contains N integers A_{1}, A_{2} \ldots A_{N}. ------ Output Format ------ For each test case, output the minimum number of operations to make all elements of the array 0. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N, K ≀ 10^{5}$ $0 ≀ A_{i} ≀ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$ ----- Sample Input 1 ------ 1 3 2 3 6 10 ----- Sample Output 1 ------ 5 ----- explanation 1 ------ Here is one way to achieve $[0, 0, 0]$ from $[3, 6, 10]$ in $5$ operations: 1. Choose $p = 0$ and indices $\{1\}$. Now $A$ becomes $[2, 6, 10]$. 2. Choose $p = 1$ and indices $\{1,2\}$. Now $A$ becomes $[0, 4, 10]$. 3. Choose $p = 1$ and indices $\{3\}$. Now $A$ becomes $[0, 4, 8]$. 4. Choose $p = 2$ and indices $\{2\}$. Now $A$ becomes $[0, 0, 8]$. 5. Choose $p = 3$ and indices $\{3\}$. Now $A$ becomes $[0, 0, 0]$. It can be shown that at least $5$ operations are required.
def gcd(a, b): if b == 0: return a return gcd(b, a % b) t = int(input()) while t: t -= 1 a, b = input().split() a, b = int(a), int(b) lis = list(map(int, input().split())) bit = [(0) for _ in range(32)] for i in range(32): for j in lis: if j & 1 << i: bit[i] += 1 cnt = 0 for i in bit: cnt += (i + b - 1) // b print(cnt)
FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Given an array A_{1}, A_{2} \ldots A_{N}, find the minimum number of operations (possibly zero) required to convert all integers in A to 0. In one operation, you choose a non-negative integer p (p β‰₯ 0), select at most K indices in the array A, and for each selected index i, replace A_{i} with A_{i}\oplus 2^{p}. Here, \oplus denotes bitwise XOR. ------ Subtasks ------ Subtask #1 (100 points): Original Constraints ------ Input Format ------ - The first line contains an integer T - the number of test cases. Then T test cases follow. - The first line of each test case contains two integers N, K - the size of the array and the maximum number of elements you can select in an operation. - The second line of each test case contains N integers A_{1}, A_{2} \ldots A_{N}. ------ Output Format ------ For each test case, output the minimum number of operations to make all elements of the array 0. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N, K ≀ 10^{5}$ $0 ≀ A_{i} ≀ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$ ----- Sample Input 1 ------ 1 3 2 3 6 10 ----- Sample Output 1 ------ 5 ----- explanation 1 ------ Here is one way to achieve $[0, 0, 0]$ from $[3, 6, 10]$ in $5$ operations: 1. Choose $p = 0$ and indices $\{1\}$. Now $A$ becomes $[2, 6, 10]$. 2. Choose $p = 1$ and indices $\{1,2\}$. Now $A$ becomes $[0, 4, 10]$. 3. Choose $p = 1$ and indices $\{3\}$. Now $A$ becomes $[0, 4, 8]$. 4. Choose $p = 2$ and indices $\{2\}$. Now $A$ becomes $[0, 0, 8]$. 5. Choose $p = 3$ and indices $\{3\}$. Now $A$ becomes $[0, 0, 0]$. It can be shown that at least $5$ operations are required.
test_case = int(input()) for i in range(test_case): n, k = map(int, input().split()) lst = tuple(map(int, input().split())) binary_cnt = [0] * 32 for j in lst: count = 0 while j > 0: if j & 1 == 1: binary_cnt[count] += 1 j = j // 2 count += 1 ans = 0 for l in binary_cnt: if l > 0: ka = min(l, k) if l % ka == 0: ans += l // ka else: ans += l // ka + 1 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Given an array A_{1}, A_{2} \ldots A_{N}, find the minimum number of operations (possibly zero) required to convert all integers in A to 0. In one operation, you choose a non-negative integer p (p β‰₯ 0), select at most K indices in the array A, and for each selected index i, replace A_{i} with A_{i}\oplus 2^{p}. Here, \oplus denotes bitwise XOR. ------ Subtasks ------ Subtask #1 (100 points): Original Constraints ------ Input Format ------ - The first line contains an integer T - the number of test cases. Then T test cases follow. - The first line of each test case contains two integers N, K - the size of the array and the maximum number of elements you can select in an operation. - The second line of each test case contains N integers A_{1}, A_{2} \ldots A_{N}. ------ Output Format ------ For each test case, output the minimum number of operations to make all elements of the array 0. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N, K ≀ 10^{5}$ $0 ≀ A_{i} ≀ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$ ----- Sample Input 1 ------ 1 3 2 3 6 10 ----- Sample Output 1 ------ 5 ----- explanation 1 ------ Here is one way to achieve $[0, 0, 0]$ from $[3, 6, 10]$ in $5$ operations: 1. Choose $p = 0$ and indices $\{1\}$. Now $A$ becomes $[2, 6, 10]$. 2. Choose $p = 1$ and indices $\{1,2\}$. Now $A$ becomes $[0, 4, 10]$. 3. Choose $p = 1$ and indices $\{3\}$. Now $A$ becomes $[0, 4, 8]$. 4. Choose $p = 2$ and indices $\{2\}$. Now $A$ becomes $[0, 0, 8]$. 5. Choose $p = 3$ and indices $\{3\}$. Now $A$ becomes $[0, 0, 0]$. It can be shown that at least $5$ operations are required.
def decimalToBinary(n): return bin(n).replace("0b", "") def count(A, K): A_bin = [] p = len(str(decimalToBinary(max(A)))) for i in A: A_bin.append(str(decimalToBinary(i)).rjust(p, "0")) ans = 0 for i in range(p): count = 0 for j in A_bin: if j[i] == "1": count += 1 ans += (count + K - 1) // K return ans T = int(input()) for _ in range(T): N, K = [int(x) for x in input().split()] A = [int(y) for y in input().split()] print(count(A, K))
FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR VAR STRING STRING FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR STRING VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN VAR 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 ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Given an array A_{1}, A_{2} \ldots A_{N}, find the minimum number of operations (possibly zero) required to convert all integers in A to 0. In one operation, you choose a non-negative integer p (p β‰₯ 0), select at most K indices in the array A, and for each selected index i, replace A_{i} with A_{i}\oplus 2^{p}. Here, \oplus denotes bitwise XOR. ------ Subtasks ------ Subtask #1 (100 points): Original Constraints ------ Input Format ------ - The first line contains an integer T - the number of test cases. Then T test cases follow. - The first line of each test case contains two integers N, K - the size of the array and the maximum number of elements you can select in an operation. - The second line of each test case contains N integers A_{1}, A_{2} \ldots A_{N}. ------ Output Format ------ For each test case, output the minimum number of operations to make all elements of the array 0. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N, K ≀ 10^{5}$ $0 ≀ A_{i} ≀ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$ ----- Sample Input 1 ------ 1 3 2 3 6 10 ----- Sample Output 1 ------ 5 ----- explanation 1 ------ Here is one way to achieve $[0, 0, 0]$ from $[3, 6, 10]$ in $5$ operations: 1. Choose $p = 0$ and indices $\{1\}$. Now $A$ becomes $[2, 6, 10]$. 2. Choose $p = 1$ and indices $\{1,2\}$. Now $A$ becomes $[0, 4, 10]$. 3. Choose $p = 1$ and indices $\{3\}$. Now $A$ becomes $[0, 4, 8]$. 4. Choose $p = 2$ and indices $\{2\}$. Now $A$ becomes $[0, 0, 8]$. 5. Choose $p = 3$ and indices $\{3\}$. Now $A$ becomes $[0, 0, 0]$. It can be shown that at least $5$ operations are required.
n = int(input()) for i in range(n): N, P = map(int, input().split()) l = list(map(int, input().split())) a = 0 q = [] for i in range(N): p = bin(l[i]) p = p[2:] W = len(p) q.append((32 - W) * "0" + p) for i in range(32): c = 0 for j in range(N): if q[j][i] == "1": c += 1 if c % P == 0: a += c // P else: a += c // P + 1 print(a)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR STRING VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Given an array A_{1}, A_{2} \ldots A_{N}, find the minimum number of operations (possibly zero) required to convert all integers in A to 0. In one operation, you choose a non-negative integer p (p β‰₯ 0), select at most K indices in the array A, and for each selected index i, replace A_{i} with A_{i}\oplus 2^{p}. Here, \oplus denotes bitwise XOR. ------ Subtasks ------ Subtask #1 (100 points): Original Constraints ------ Input Format ------ - The first line contains an integer T - the number of test cases. Then T test cases follow. - The first line of each test case contains two integers N, K - the size of the array and the maximum number of elements you can select in an operation. - The second line of each test case contains N integers A_{1}, A_{2} \ldots A_{N}. ------ Output Format ------ For each test case, output the minimum number of operations to make all elements of the array 0. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N, K ≀ 10^{5}$ $0 ≀ A_{i} ≀ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$ ----- Sample Input 1 ------ 1 3 2 3 6 10 ----- Sample Output 1 ------ 5 ----- explanation 1 ------ Here is one way to achieve $[0, 0, 0]$ from $[3, 6, 10]$ in $5$ operations: 1. Choose $p = 0$ and indices $\{1\}$. Now $A$ becomes $[2, 6, 10]$. 2. Choose $p = 1$ and indices $\{1,2\}$. Now $A$ becomes $[0, 4, 10]$. 3. Choose $p = 1$ and indices $\{3\}$. Now $A$ becomes $[0, 4, 8]$. 4. Choose $p = 2$ and indices $\{2\}$. Now $A$ becomes $[0, 0, 8]$. 5. Choose $p = 3$ and indices $\{3\}$. Now $A$ becomes $[0, 0, 0]$. It can be shown that at least $5$ operations are required.
for t in range(int(input())): N, k = map(int, input().split()) l = list(map(int, input().split())) data = {} for x in l: b = str(bin(x)) w = b[2:][::-1] q = 0 for i in w: if i == "1": try: data[q] += 1 except: data[q] = 1 q += 1 ans = 0 for i in data.keys(): if data[i] % k == 0: ans += data[i] // k else: ans += data[i] // k + 1 print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Given an array A_{1}, A_{2} \ldots A_{N}, find the minimum number of operations (possibly zero) required to convert all integers in A to 0. In one operation, you choose a non-negative integer p (p β‰₯ 0), select at most K indices in the array A, and for each selected index i, replace A_{i} with A_{i}\oplus 2^{p}. Here, \oplus denotes bitwise XOR. ------ Subtasks ------ Subtask #1 (100 points): Original Constraints ------ Input Format ------ - The first line contains an integer T - the number of test cases. Then T test cases follow. - The first line of each test case contains two integers N, K - the size of the array and the maximum number of elements you can select in an operation. - The second line of each test case contains N integers A_{1}, A_{2} \ldots A_{N}. ------ Output Format ------ For each test case, output the minimum number of operations to make all elements of the array 0. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N, K ≀ 10^{5}$ $0 ≀ A_{i} ≀ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$ ----- Sample Input 1 ------ 1 3 2 3 6 10 ----- Sample Output 1 ------ 5 ----- explanation 1 ------ Here is one way to achieve $[0, 0, 0]$ from $[3, 6, 10]$ in $5$ operations: 1. Choose $p = 0$ and indices $\{1\}$. Now $A$ becomes $[2, 6, 10]$. 2. Choose $p = 1$ and indices $\{1,2\}$. Now $A$ becomes $[0, 4, 10]$. 3. Choose $p = 1$ and indices $\{3\}$. Now $A$ becomes $[0, 4, 8]$. 4. Choose $p = 2$ and indices $\{2\}$. Now $A$ becomes $[0, 0, 8]$. 5. Choose $p = 3$ and indices $\{3\}$. Now $A$ becomes $[0, 0, 0]$. It can be shown that at least $5$ operations are required.
t = int(input()) for _ in range(t): inn = input() n, k = map(int, inn.split(" ")) inn = input() arr = list(map(int, inn.split(" "))) total = 0 res = 0 for i in range(0, 32): total = 0 for j in range(0, len(arr)): if arr[j] & 1: total += 1 arr[j] = arr[j] >> 1 if total % k == 0: res += total // k else: res += total // k + 1 print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Given an array A_{1}, A_{2} \ldots A_{N}, find the minimum number of operations (possibly zero) required to convert all integers in A to 0. In one operation, you choose a non-negative integer p (p β‰₯ 0), select at most K indices in the array A, and for each selected index i, replace A_{i} with A_{i}\oplus 2^{p}. Here, \oplus denotes bitwise XOR. ------ Subtasks ------ Subtask #1 (100 points): Original Constraints ------ Input Format ------ - The first line contains an integer T - the number of test cases. Then T test cases follow. - The first line of each test case contains two integers N, K - the size of the array and the maximum number of elements you can select in an operation. - The second line of each test case contains N integers A_{1}, A_{2} \ldots A_{N}. ------ Output Format ------ For each test case, output the minimum number of operations to make all elements of the array 0. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N, K ≀ 10^{5}$ $0 ≀ A_{i} ≀ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$ ----- Sample Input 1 ------ 1 3 2 3 6 10 ----- Sample Output 1 ------ 5 ----- explanation 1 ------ Here is one way to achieve $[0, 0, 0]$ from $[3, 6, 10]$ in $5$ operations: 1. Choose $p = 0$ and indices $\{1\}$. Now $A$ becomes $[2, 6, 10]$. 2. Choose $p = 1$ and indices $\{1,2\}$. Now $A$ becomes $[0, 4, 10]$. 3. Choose $p = 1$ and indices $\{3\}$. Now $A$ becomes $[0, 4, 8]$. 4. Choose $p = 2$ and indices $\{2\}$. Now $A$ becomes $[0, 0, 8]$. 5. Choose $p = 3$ and indices $\{3\}$. Now $A$ becomes $[0, 0, 0]$. It can be shown that at least $5$ operations are required.
t = int(input()) while t: t -= 1 ans = 0 N, K = input().split() n = int(N) k = int(K) arr = [int(i) for i in input().split()] for i in range(32): count = 0 for j in range(n): if arr[j] != 0: if arr[j] & 1: count += 1 arr[j] = int(arr[j] / 2) ans += int((count + k - 1) / k) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Given an array A_{1}, A_{2} \ldots A_{N}, find the minimum number of operations (possibly zero) required to convert all integers in A to 0. In one operation, you choose a non-negative integer p (p β‰₯ 0), select at most K indices in the array A, and for each selected index i, replace A_{i} with A_{i}\oplus 2^{p}. Here, \oplus denotes bitwise XOR. ------ Subtasks ------ Subtask #1 (100 points): Original Constraints ------ Input Format ------ - The first line contains an integer T - the number of test cases. Then T test cases follow. - The first line of each test case contains two integers N, K - the size of the array and the maximum number of elements you can select in an operation. - The second line of each test case contains N integers A_{1}, A_{2} \ldots A_{N}. ------ Output Format ------ For each test case, output the minimum number of operations to make all elements of the array 0. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N, K ≀ 10^{5}$ $0 ≀ A_{i} ≀ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$ ----- Sample Input 1 ------ 1 3 2 3 6 10 ----- Sample Output 1 ------ 5 ----- explanation 1 ------ Here is one way to achieve $[0, 0, 0]$ from $[3, 6, 10]$ in $5$ operations: 1. Choose $p = 0$ and indices $\{1\}$. Now $A$ becomes $[2, 6, 10]$. 2. Choose $p = 1$ and indices $\{1,2\}$. Now $A$ becomes $[0, 4, 10]$. 3. Choose $p = 1$ and indices $\{3\}$. Now $A$ becomes $[0, 4, 8]$. 4. Choose $p = 2$ and indices $\{2\}$. Now $A$ becomes $[0, 0, 8]$. 5. Choose $p = 3$ and indices $\{3\}$. Now $A$ becomes $[0, 0, 0]$. It can be shown that at least $5$ operations are required.
t = int(input()) while t: t -= 1 l = [int(i) for i in input().split(" ")] n = l[0] k = l[1] a = [int(i) for i in input().split(" ")] sm = 0 for _ in range(32): count = 0 for i in range(n): if a[i] != 0: count += a[i] & 1 a[i] = a[i] >> 1 sm = sm + (count + k - 1) // k print(sm)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Given an array A_{1}, A_{2} \ldots A_{N}, find the minimum number of operations (possibly zero) required to convert all integers in A to 0. In one operation, you choose a non-negative integer p (p β‰₯ 0), select at most K indices in the array A, and for each selected index i, replace A_{i} with A_{i}\oplus 2^{p}. Here, \oplus denotes bitwise XOR. ------ Subtasks ------ Subtask #1 (100 points): Original Constraints ------ Input Format ------ - The first line contains an integer T - the number of test cases. Then T test cases follow. - The first line of each test case contains two integers N, K - the size of the array and the maximum number of elements you can select in an operation. - The second line of each test case contains N integers A_{1}, A_{2} \ldots A_{N}. ------ Output Format ------ For each test case, output the minimum number of operations to make all elements of the array 0. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N, K ≀ 10^{5}$ $0 ≀ A_{i} ≀ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$ ----- Sample Input 1 ------ 1 3 2 3 6 10 ----- Sample Output 1 ------ 5 ----- explanation 1 ------ Here is one way to achieve $[0, 0, 0]$ from $[3, 6, 10]$ in $5$ operations: 1. Choose $p = 0$ and indices $\{1\}$. Now $A$ becomes $[2, 6, 10]$. 2. Choose $p = 1$ and indices $\{1,2\}$. Now $A$ becomes $[0, 4, 10]$. 3. Choose $p = 1$ and indices $\{3\}$. Now $A$ becomes $[0, 4, 8]$. 4. Choose $p = 2$ and indices $\{2\}$. Now $A$ becomes $[0, 0, 8]$. 5. Choose $p = 3$ and indices $\{3\}$. Now $A$ becomes $[0, 0, 0]$. It can be shown that at least $5$ operations are required.
for _ in range(int(input())): n, k = map(int, input().split(" ")) arr = list(map(int, input().split(" "))) carr = [(0) for i in range(32)] for i in arr: bnum = bin(i)[2:][::-1] for j in range(len(bnum)): carr[j] += int(bnum[j]) ans = 0 for i in carr: ans += (i + k - 1) // k print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Given an array A_{1}, A_{2} \ldots A_{N}, find the minimum number of operations (possibly zero) required to convert all integers in A to 0. In one operation, you choose a non-negative integer p (p β‰₯ 0), select at most K indices in the array A, and for each selected index i, replace A_{i} with A_{i}\oplus 2^{p}. Here, \oplus denotes bitwise XOR. ------ Subtasks ------ Subtask #1 (100 points): Original Constraints ------ Input Format ------ - The first line contains an integer T - the number of test cases. Then T test cases follow. - The first line of each test case contains two integers N, K - the size of the array and the maximum number of elements you can select in an operation. - The second line of each test case contains N integers A_{1}, A_{2} \ldots A_{N}. ------ Output Format ------ For each test case, output the minimum number of operations to make all elements of the array 0. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N, K ≀ 10^{5}$ $0 ≀ A_{i} ≀ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$ ----- Sample Input 1 ------ 1 3 2 3 6 10 ----- Sample Output 1 ------ 5 ----- explanation 1 ------ Here is one way to achieve $[0, 0, 0]$ from $[3, 6, 10]$ in $5$ operations: 1. Choose $p = 0$ and indices $\{1\}$. Now $A$ becomes $[2, 6, 10]$. 2. Choose $p = 1$ and indices $\{1,2\}$. Now $A$ becomes $[0, 4, 10]$. 3. Choose $p = 1$ and indices $\{3\}$. Now $A$ becomes $[0, 4, 8]$. 4. Choose $p = 2$ and indices $\{2\}$. Now $A$ becomes $[0, 0, 8]$. 5. Choose $p = 3$ and indices $\{3\}$. Now $A$ becomes $[0, 0, 0]$. It can be shown that at least $5$ operations are required.
t = int(input()) for _ in range(t): n, k = map(int, input().split()) a = list(map(int, input().split())) s = [(0) for i in range(32)] for i in a: temp = bin(i).replace("b", "0") l = 0 for i in range(len(temp) - 1, -1, -1): s[31 - l] += int(temp[i]) l += 1 ans = 0 for i in s: if i > 0: if i > k: if i % k == 0: ans += i // k else: ans += i // k + 1 else: ans += 1 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR BIN_OP NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER IF VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Given an array A_{1}, A_{2} \ldots A_{N}, find the minimum number of operations (possibly zero) required to convert all integers in A to 0. In one operation, you choose a non-negative integer p (p β‰₯ 0), select at most K indices in the array A, and for each selected index i, replace A_{i} with A_{i}\oplus 2^{p}. Here, \oplus denotes bitwise XOR. ------ Subtasks ------ Subtask #1 (100 points): Original Constraints ------ Input Format ------ - The first line contains an integer T - the number of test cases. Then T test cases follow. - The first line of each test case contains two integers N, K - the size of the array and the maximum number of elements you can select in an operation. - The second line of each test case contains N integers A_{1}, A_{2} \ldots A_{N}. ------ Output Format ------ For each test case, output the minimum number of operations to make all elements of the array 0. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N, K ≀ 10^{5}$ $0 ≀ A_{i} ≀ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$ ----- Sample Input 1 ------ 1 3 2 3 6 10 ----- Sample Output 1 ------ 5 ----- explanation 1 ------ Here is one way to achieve $[0, 0, 0]$ from $[3, 6, 10]$ in $5$ operations: 1. Choose $p = 0$ and indices $\{1\}$. Now $A$ becomes $[2, 6, 10]$. 2. Choose $p = 1$ and indices $\{1,2\}$. Now $A$ becomes $[0, 4, 10]$. 3. Choose $p = 1$ and indices $\{3\}$. Now $A$ becomes $[0, 4, 8]$. 4. Choose $p = 2$ and indices $\{2\}$. Now $A$ becomes $[0, 0, 8]$. 5. Choose $p = 3$ and indices $\{3\}$. Now $A$ becomes $[0, 0, 0]$. It can be shown that at least $5$ operations are required.
T = int(input()) while T: n, k = map(int, input().split(" ")) arr = map(int, input().split(" ")) ans = 0 d = {} for i in arr: bn = bin(i).replace("0b", "")[::-1] for j in range(len(bn)): if bn[j] == "0": continue if j in d: d[j] += 1 else: d[j] = 1 for key, itm in d.items(): if itm <= k: ans += 1 else: while itm > k: itm = itm - k ans += 1 if itm > 0: ans += 1 print(ans) T -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING STRING NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Given an array A_{1}, A_{2} \ldots A_{N}, find the minimum number of operations (possibly zero) required to convert all integers in A to 0. In one operation, you choose a non-negative integer p (p β‰₯ 0), select at most K indices in the array A, and for each selected index i, replace A_{i} with A_{i}\oplus 2^{p}. Here, \oplus denotes bitwise XOR. ------ Subtasks ------ Subtask #1 (100 points): Original Constraints ------ Input Format ------ - The first line contains an integer T - the number of test cases. Then T test cases follow. - The first line of each test case contains two integers N, K - the size of the array and the maximum number of elements you can select in an operation. - The second line of each test case contains N integers A_{1}, A_{2} \ldots A_{N}. ------ Output Format ------ For each test case, output the minimum number of operations to make all elements of the array 0. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N, K ≀ 10^{5}$ $0 ≀ A_{i} ≀ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$ ----- Sample Input 1 ------ 1 3 2 3 6 10 ----- Sample Output 1 ------ 5 ----- explanation 1 ------ Here is one way to achieve $[0, 0, 0]$ from $[3, 6, 10]$ in $5$ operations: 1. Choose $p = 0$ and indices $\{1\}$. Now $A$ becomes $[2, 6, 10]$. 2. Choose $p = 1$ and indices $\{1,2\}$. Now $A$ becomes $[0, 4, 10]$. 3. Choose $p = 1$ and indices $\{3\}$. Now $A$ becomes $[0, 4, 8]$. 4. Choose $p = 2$ and indices $\{2\}$. Now $A$ becomes $[0, 0, 8]$. 5. Choose $p = 3$ and indices $\{3\}$. Now $A$ becomes $[0, 0, 0]$. It can be shown that at least $5$ operations are required.
for _ in range(int(input())): n, k = map(int, input().split()) a = [*map(int, input().split())] q = [0] * 32 for i in a: p = 0 while i: q[p] += i & 1 i >>= 1 p += 1 print(sum((i + k - 1) // k for i in q))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Given an array A_{1}, A_{2} \ldots A_{N}, find the minimum number of operations (possibly zero) required to convert all integers in A to 0. In one operation, you choose a non-negative integer p (p β‰₯ 0), select at most K indices in the array A, and for each selected index i, replace A_{i} with A_{i}\oplus 2^{p}. Here, \oplus denotes bitwise XOR. ------ Subtasks ------ Subtask #1 (100 points): Original Constraints ------ Input Format ------ - The first line contains an integer T - the number of test cases. Then T test cases follow. - The first line of each test case contains two integers N, K - the size of the array and the maximum number of elements you can select in an operation. - The second line of each test case contains N integers A_{1}, A_{2} \ldots A_{N}. ------ Output Format ------ For each test case, output the minimum number of operations to make all elements of the array 0. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N, K ≀ 10^{5}$ $0 ≀ A_{i} ≀ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$ ----- Sample Input 1 ------ 1 3 2 3 6 10 ----- Sample Output 1 ------ 5 ----- explanation 1 ------ Here is one way to achieve $[0, 0, 0]$ from $[3, 6, 10]$ in $5$ operations: 1. Choose $p = 0$ and indices $\{1\}$. Now $A$ becomes $[2, 6, 10]$. 2. Choose $p = 1$ and indices $\{1,2\}$. Now $A$ becomes $[0, 4, 10]$. 3. Choose $p = 1$ and indices $\{3\}$. Now $A$ becomes $[0, 4, 8]$. 4. Choose $p = 2$ and indices $\{2\}$. Now $A$ becomes $[0, 0, 8]$. 5. Choose $p = 3$ and indices $\{3\}$. Now $A$ becomes $[0, 0, 0]$. It can be shown that at least $5$ operations are required.
for _ in range(int(input())): n, k = map(int, input().split()) a = list(map(int, input().split())) bin = [0] * 32 for y in range(32): for j in a: if j & 1 << y: bin[y] += 1 res = 0 for i in bin: if i % k == 0: res += i // k else: res += i // k + 1 print(res)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Given an array A_{1}, A_{2} \ldots A_{N}, find the minimum number of operations (possibly zero) required to convert all integers in A to 0. In one operation, you choose a non-negative integer p (p β‰₯ 0), select at most K indices in the array A, and for each selected index i, replace A_{i} with A_{i}\oplus 2^{p}. Here, \oplus denotes bitwise XOR. ------ Subtasks ------ Subtask #1 (100 points): Original Constraints ------ Input Format ------ - The first line contains an integer T - the number of test cases. Then T test cases follow. - The first line of each test case contains two integers N, K - the size of the array and the maximum number of elements you can select in an operation. - The second line of each test case contains N integers A_{1}, A_{2} \ldots A_{N}. ------ Output Format ------ For each test case, output the minimum number of operations to make all elements of the array 0. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N, K ≀ 10^{5}$ $0 ≀ A_{i} ≀ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$ ----- Sample Input 1 ------ 1 3 2 3 6 10 ----- Sample Output 1 ------ 5 ----- explanation 1 ------ Here is one way to achieve $[0, 0, 0]$ from $[3, 6, 10]$ in $5$ operations: 1. Choose $p = 0$ and indices $\{1\}$. Now $A$ becomes $[2, 6, 10]$. 2. Choose $p = 1$ and indices $\{1,2\}$. Now $A$ becomes $[0, 4, 10]$. 3. Choose $p = 1$ and indices $\{3\}$. Now $A$ becomes $[0, 4, 8]$. 4. Choose $p = 2$ and indices $\{2\}$. Now $A$ becomes $[0, 0, 8]$. 5. Choose $p = 3$ and indices $\{3\}$. Now $A$ becomes $[0, 0, 0]$. It can be shown that at least $5$ operations are required.
t = int(input()) while t > 0: t -= 1 n, k = map(int, input().split()) arr = list(map(int, input().split())) lst = [0] * 32 for x in arr: i = 0 while x: lst[i] += x & 1 x >>= 1 i += 1 ans = 0 for x in lst: ans += (x + k - 1) // k print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Given an array A_{1}, A_{2} \ldots A_{N}, find the minimum number of operations (possibly zero) required to convert all integers in A to 0. In one operation, you choose a non-negative integer p (p β‰₯ 0), select at most K indices in the array A, and for each selected index i, replace A_{i} with A_{i}\oplus 2^{p}. Here, \oplus denotes bitwise XOR. ------ Subtasks ------ Subtask #1 (100 points): Original Constraints ------ Input Format ------ - The first line contains an integer T - the number of test cases. Then T test cases follow. - The first line of each test case contains two integers N, K - the size of the array and the maximum number of elements you can select in an operation. - The second line of each test case contains N integers A_{1}, A_{2} \ldots A_{N}. ------ Output Format ------ For each test case, output the minimum number of operations to make all elements of the array 0. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N, K ≀ 10^{5}$ $0 ≀ A_{i} ≀ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$ ----- Sample Input 1 ------ 1 3 2 3 6 10 ----- Sample Output 1 ------ 5 ----- explanation 1 ------ Here is one way to achieve $[0, 0, 0]$ from $[3, 6, 10]$ in $5$ operations: 1. Choose $p = 0$ and indices $\{1\}$. Now $A$ becomes $[2, 6, 10]$. 2. Choose $p = 1$ and indices $\{1,2\}$. Now $A$ becomes $[0, 4, 10]$. 3. Choose $p = 1$ and indices $\{3\}$. Now $A$ becomes $[0, 4, 8]$. 4. Choose $p = 2$ and indices $\{2\}$. Now $A$ becomes $[0, 0, 8]$. 5. Choose $p = 3$ and indices $\{3\}$. Now $A$ becomes $[0, 0, 0]$. It can be shown that at least $5$ operations are required.
t = int(input()) for i in range(t): n, k = map(int, input().split()) a = list(map(int, input().split())) op_num = 0 p = 0 while p != -1: ones_to_change = 0 for j in range(n): if a[j]: ones_to_change += a[j] % 2 a[j] //= 2 op_num += -(-ones_to_change // k) p += 1 if any(a): continue break print(op_num)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Given an array A_{1}, A_{2} \ldots A_{N}, find the minimum number of operations (possibly zero) required to convert all integers in A to 0. In one operation, you choose a non-negative integer p (p β‰₯ 0), select at most K indices in the array A, and for each selected index i, replace A_{i} with A_{i}\oplus 2^{p}. Here, \oplus denotes bitwise XOR. ------ Subtasks ------ Subtask #1 (100 points): Original Constraints ------ Input Format ------ - The first line contains an integer T - the number of test cases. Then T test cases follow. - The first line of each test case contains two integers N, K - the size of the array and the maximum number of elements you can select in an operation. - The second line of each test case contains N integers A_{1}, A_{2} \ldots A_{N}. ------ Output Format ------ For each test case, output the minimum number of operations to make all elements of the array 0. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N, K ≀ 10^{5}$ $0 ≀ A_{i} ≀ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$ ----- Sample Input 1 ------ 1 3 2 3 6 10 ----- Sample Output 1 ------ 5 ----- explanation 1 ------ Here is one way to achieve $[0, 0, 0]$ from $[3, 6, 10]$ in $5$ operations: 1. Choose $p = 0$ and indices $\{1\}$. Now $A$ becomes $[2, 6, 10]$. 2. Choose $p = 1$ and indices $\{1,2\}$. Now $A$ becomes $[0, 4, 10]$. 3. Choose $p = 1$ and indices $\{3\}$. Now $A$ becomes $[0, 4, 8]$. 4. Choose $p = 2$ and indices $\{2\}$. Now $A$ becomes $[0, 0, 8]$. 5. Choose $p = 3$ and indices $\{3\}$. Now $A$ becomes $[0, 0, 0]$. It can be shown that at least $5$ operations are required.
t = int(input()) for i in range(t): x = input().split() n, k = tuple(map(int, x)) x = input().split() a = list(map(int, x)) ele = [] for j in range(0, 31): ele.append(0) for p in range(0, n): if a[p] % 2 != 0: ele[j] += 1 a[p] = int(a[p] / 2) res = 0 for j in range(0, 31): if ele[j] % k == 0: res += ele[j] / k else: res += int(ele[j] / k) + 1 print(int(res))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Given an array A_{1}, A_{2} \ldots A_{N}, find the minimum number of operations (possibly zero) required to convert all integers in A to 0. In one operation, you choose a non-negative integer p (p β‰₯ 0), select at most K indices in the array A, and for each selected index i, replace A_{i} with A_{i}\oplus 2^{p}. Here, \oplus denotes bitwise XOR. ------ Subtasks ------ Subtask #1 (100 points): Original Constraints ------ Input Format ------ - The first line contains an integer T - the number of test cases. Then T test cases follow. - The first line of each test case contains two integers N, K - the size of the array and the maximum number of elements you can select in an operation. - The second line of each test case contains N integers A_{1}, A_{2} \ldots A_{N}. ------ Output Format ------ For each test case, output the minimum number of operations to make all elements of the array 0. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N, K ≀ 10^{5}$ $0 ≀ A_{i} ≀ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$ ----- Sample Input 1 ------ 1 3 2 3 6 10 ----- Sample Output 1 ------ 5 ----- explanation 1 ------ Here is one way to achieve $[0, 0, 0]$ from $[3, 6, 10]$ in $5$ operations: 1. Choose $p = 0$ and indices $\{1\}$. Now $A$ becomes $[2, 6, 10]$. 2. Choose $p = 1$ and indices $\{1,2\}$. Now $A$ becomes $[0, 4, 10]$. 3. Choose $p = 1$ and indices $\{3\}$. Now $A$ becomes $[0, 4, 8]$. 4. Choose $p = 2$ and indices $\{2\}$. Now $A$ becomes $[0, 0, 8]$. 5. Choose $p = 3$ and indices $\{3\}$. Now $A$ becomes $[0, 0, 0]$. It can be shown that at least $5$ operations are required.
for _ in range(int(input())): N, K = map(int, input().split()) cnt = [0] * 30 A = [*map(int, input().split())] for x in A: for j in range(30): if x >> j & 1: cnt[j] += 1 print(sum((x + K - 1) // K for x in cnt))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Given an array A_{1}, A_{2} \ldots A_{N}, find the minimum number of operations (possibly zero) required to convert all integers in A to 0. In one operation, you choose a non-negative integer p (p β‰₯ 0), select at most K indices in the array A, and for each selected index i, replace A_{i} with A_{i}\oplus 2^{p}. Here, \oplus denotes bitwise XOR. ------ Subtasks ------ Subtask #1 (100 points): Original Constraints ------ Input Format ------ - The first line contains an integer T - the number of test cases. Then T test cases follow. - The first line of each test case contains two integers N, K - the size of the array and the maximum number of elements you can select in an operation. - The second line of each test case contains N integers A_{1}, A_{2} \ldots A_{N}. ------ Output Format ------ For each test case, output the minimum number of operations to make all elements of the array 0. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N, K ≀ 10^{5}$ $0 ≀ A_{i} ≀ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$ ----- Sample Input 1 ------ 1 3 2 3 6 10 ----- Sample Output 1 ------ 5 ----- explanation 1 ------ Here is one way to achieve $[0, 0, 0]$ from $[3, 6, 10]$ in $5$ operations: 1. Choose $p = 0$ and indices $\{1\}$. Now $A$ becomes $[2, 6, 10]$. 2. Choose $p = 1$ and indices $\{1,2\}$. Now $A$ becomes $[0, 4, 10]$. 3. Choose $p = 1$ and indices $\{3\}$. Now $A$ becomes $[0, 4, 8]$. 4. Choose $p = 2$ and indices $\{2\}$. Now $A$ becomes $[0, 0, 8]$. 5. Choose $p = 3$ and indices $\{3\}$. Now $A$ becomes $[0, 0, 0]$. It can be shown that at least $5$ operations are required.
t = int(input()) final = [] for _ in range(t): n, k = map(int, input().split()) a = list(map(int, input().split())) max_len = len(bin(max(a))[2:]) for x in range(n): a[x] = bin(a[x])[2:] for x in range(n): if len(a[x]) < max_len: p = max_len - len(a[x]) a[x] = "0" * p + a[x] ans = 0 for x in range(max_len): count = 0 for y in range(n): if a[y][x] == "1": count += 1 if int(count / k) == count / k: ans += int(count / k) else: ans += int(count / k) + 1 final.append(ans) for _ in range(t): print(final[_])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP STRING VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Given an array A_{1}, A_{2} \ldots A_{N}, find the minimum number of operations (possibly zero) required to convert all integers in A to 0. In one operation, you choose a non-negative integer p (p β‰₯ 0), select at most K indices in the array A, and for each selected index i, replace A_{i} with A_{i}\oplus 2^{p}. Here, \oplus denotes bitwise XOR. ------ Subtasks ------ Subtask #1 (100 points): Original Constraints ------ Input Format ------ - The first line contains an integer T - the number of test cases. Then T test cases follow. - The first line of each test case contains two integers N, K - the size of the array and the maximum number of elements you can select in an operation. - The second line of each test case contains N integers A_{1}, A_{2} \ldots A_{N}. ------ Output Format ------ For each test case, output the minimum number of operations to make all elements of the array 0. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N, K ≀ 10^{5}$ $0 ≀ A_{i} ≀ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$ ----- Sample Input 1 ------ 1 3 2 3 6 10 ----- Sample Output 1 ------ 5 ----- explanation 1 ------ Here is one way to achieve $[0, 0, 0]$ from $[3, 6, 10]$ in $5$ operations: 1. Choose $p = 0$ and indices $\{1\}$. Now $A$ becomes $[2, 6, 10]$. 2. Choose $p = 1$ and indices $\{1,2\}$. Now $A$ becomes $[0, 4, 10]$. 3. Choose $p = 1$ and indices $\{3\}$. Now $A$ becomes $[0, 4, 8]$. 4. Choose $p = 2$ and indices $\{2\}$. Now $A$ becomes $[0, 0, 8]$. 5. Choose $p = 3$ and indices $\{3\}$. Now $A$ becomes $[0, 0, 0]$. It can be shown that at least $5$ operations are required.
t = int(input()) for _ in range(t): n, k = input().split() n = int(n) k = int(k) arr = list(map(int, input().split())) count_arr = [(0) for _ in range(32)] for v in arr: for i in range(32): if v & 1 << i: count_arr[i] += 1 ans = 0 for i in range(32): if count_arr[i] >= k: ans += count_arr[i] // k if count_arr[i] % k != 0: ans += 1 elif count_arr[i] != 0: ans += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Given an array A_{1}, A_{2} \ldots A_{N}, find the minimum number of operations (possibly zero) required to convert all integers in A to 0. In one operation, you choose a non-negative integer p (p β‰₯ 0), select at most K indices in the array A, and for each selected index i, replace A_{i} with A_{i}\oplus 2^{p}. Here, \oplus denotes bitwise XOR. ------ Subtasks ------ Subtask #1 (100 points): Original Constraints ------ Input Format ------ - The first line contains an integer T - the number of test cases. Then T test cases follow. - The first line of each test case contains two integers N, K - the size of the array and the maximum number of elements you can select in an operation. - The second line of each test case contains N integers A_{1}, A_{2} \ldots A_{N}. ------ Output Format ------ For each test case, output the minimum number of operations to make all elements of the array 0. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N, K ≀ 10^{5}$ $0 ≀ A_{i} ≀ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$ ----- Sample Input 1 ------ 1 3 2 3 6 10 ----- Sample Output 1 ------ 5 ----- explanation 1 ------ Here is one way to achieve $[0, 0, 0]$ from $[3, 6, 10]$ in $5$ operations: 1. Choose $p = 0$ and indices $\{1\}$. Now $A$ becomes $[2, 6, 10]$. 2. Choose $p = 1$ and indices $\{1,2\}$. Now $A$ becomes $[0, 4, 10]$. 3. Choose $p = 1$ and indices $\{3\}$. Now $A$ becomes $[0, 4, 8]$. 4. Choose $p = 2$ and indices $\{2\}$. Now $A$ becomes $[0, 0, 8]$. 5. Choose $p = 3$ and indices $\{3\}$. Now $A$ becomes $[0, 0, 0]$. It can be shown that at least $5$ operations are required.
t = int(input()) for _ in range(t): n, k = map(int, input().split()) l = [int(i) for i in input().split()] binary = [] for i in l: binary.append(bin(i).replace("0b", "")) res = [(0) for i in range(32)] for i in range(n): tmp = binary[i] c = 31 for i in range(len(tmp) - 1, -1, -1): if tmp[i] == "1": res[c] += 1 c -= 1 ans = 0 for i in res: if i > 0: if i % k == 0: ans += i // k else: ans += i // k + 1 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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR STRING STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Given an array A_{1}, A_{2} \ldots A_{N}, find the minimum number of operations (possibly zero) required to convert all integers in A to 0. In one operation, you choose a non-negative integer p (p β‰₯ 0), select at most K indices in the array A, and for each selected index i, replace A_{i} with A_{i}\oplus 2^{p}. Here, \oplus denotes bitwise XOR. ------ Subtasks ------ Subtask #1 (100 points): Original Constraints ------ Input Format ------ - The first line contains an integer T - the number of test cases. Then T test cases follow. - The first line of each test case contains two integers N, K - the size of the array and the maximum number of elements you can select in an operation. - The second line of each test case contains N integers A_{1}, A_{2} \ldots A_{N}. ------ Output Format ------ For each test case, output the minimum number of operations to make all elements of the array 0. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N, K ≀ 10^{5}$ $0 ≀ A_{i} ≀ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$ ----- Sample Input 1 ------ 1 3 2 3 6 10 ----- Sample Output 1 ------ 5 ----- explanation 1 ------ Here is one way to achieve $[0, 0, 0]$ from $[3, 6, 10]$ in $5$ operations: 1. Choose $p = 0$ and indices $\{1\}$. Now $A$ becomes $[2, 6, 10]$. 2. Choose $p = 1$ and indices $\{1,2\}$. Now $A$ becomes $[0, 4, 10]$. 3. Choose $p = 1$ and indices $\{3\}$. Now $A$ becomes $[0, 4, 8]$. 4. Choose $p = 2$ and indices $\{2\}$. Now $A$ becomes $[0, 0, 8]$. 5. Choose $p = 3$ and indices $\{3\}$. Now $A$ becomes $[0, 0, 0]$. It can be shown that at least $5$ operations are required.
for _ in range(int(input())): n, k = map(int, input().split()) x = list(map(int, input().split())) xd = {} for i in range(n): if x[i] > 0: temp = bin(x[i])[2:] for j in range(len(temp) - 1, -1, -1): if temp[j] == "1": xd[len(temp) - 1 - j] = xd.setdefault(len(temp) - 1 - j, 0) + 1 ans = 0 for i in xd.values(): if i % k > 0: ans += i // k + 1 else: ans += i // k print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Given an array A_{1}, A_{2} \ldots A_{N}, find the minimum number of operations (possibly zero) required to convert all integers in A to 0. In one operation, you choose a non-negative integer p (p β‰₯ 0), select at most K indices in the array A, and for each selected index i, replace A_{i} with A_{i}\oplus 2^{p}. Here, \oplus denotes bitwise XOR. ------ Subtasks ------ Subtask #1 (100 points): Original Constraints ------ Input Format ------ - The first line contains an integer T - the number of test cases. Then T test cases follow. - The first line of each test case contains two integers N, K - the size of the array and the maximum number of elements you can select in an operation. - The second line of each test case contains N integers A_{1}, A_{2} \ldots A_{N}. ------ Output Format ------ For each test case, output the minimum number of operations to make all elements of the array 0. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N, K ≀ 10^{5}$ $0 ≀ A_{i} ≀ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$ ----- Sample Input 1 ------ 1 3 2 3 6 10 ----- Sample Output 1 ------ 5 ----- explanation 1 ------ Here is one way to achieve $[0, 0, 0]$ from $[3, 6, 10]$ in $5$ operations: 1. Choose $p = 0$ and indices $\{1\}$. Now $A$ becomes $[2, 6, 10]$. 2. Choose $p = 1$ and indices $\{1,2\}$. Now $A$ becomes $[0, 4, 10]$. 3. Choose $p = 1$ and indices $\{3\}$. Now $A$ becomes $[0, 4, 8]$. 4. Choose $p = 2$ and indices $\{2\}$. Now $A$ becomes $[0, 0, 8]$. 5. Choose $p = 3$ and indices $\{3\}$. Now $A$ becomes $[0, 0, 0]$. It can be shown that at least $5$ operations are required.
import sys for i in range(int(input())): n, k = map(int, input().split()) a = list(map(int, sys.stdin.readline().split())) m = max(a) if m == 0: print(0) continue m = len("{0:b}".format(m)) for x in range(n): a[x] = "{0:b}".format(a[x]) a[x] = "0" * (m - len(a[x])) + a[x] r = [0] * m for x in range(m): for l in a: if l[x] == "1": r[x] += 1 ans = 0 for x in r: while x > 0: ans += 1 x -= k print(ans)
IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL STRING VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR STRING VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR WHILE VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
t = int(input()) for _ in range(t): n = int(input()) bl = list(map(int, input().split())) agg = 0 flag = True for i in range(n - 1): if bl[i] ^ bl[i + 1] > bl[i + 1]: flag = False break temp = "{0:b}".format(bl[i]) agg += temp.count("1") if flag: agg = 2**agg print(agg % 1000000007) else: print(0)
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR VAR VAR FUNC_CALL VAR STRING IF VAR ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
import sys T = int(sys.stdin.readline()) for _ in range(T): N = int(sys.stdin.readline()) B = list(map(int, sys.stdin.readline().split())) k = 0 for i in range(len(B) - 1): if bin(B[i] & ~B[i + 1]).count("1") > 0: k = -1 break k += bin(B[i] & B[i + 1]).count("1") if k == -1: print(0) else: print(2**k % 1000000007)
IMPORT 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
def check(n): c = 0 while n != 0: c += 1 n = n & n - 1 return pow(2, c) for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) m = 1 mod = 1000000007 f = 0 f1 = 0 for i in range(n - 1): if l[i] & l[i + 1] != l[i]: f1 = 1 break c1 = check(l[i]) m = m % mod * (c1 % mod) % mod if f1 == 1: print(0) else: print(m)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
m = pow(10, 9) + 7 t = int(input()) while t > 0: n = int(input()) a = list(map(int, input().split())) c = 1 f = a[0] for i in range(1, n): p = f q = a[i] g = p & q if g != p: c = 0 break f = a[i] c = c * pow(2, bin(g)[2:].count("1")) % m print(c) t = t - 1
ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
for _ in range(int(input())): n = int(input()) x = list(map(int, input().split())) k = 0 p = int(1000000000.0 + 7) for i in range(n - 1): if bin(x[i] & ~x[i + 1]).count("1") > 0: k = -1 break else: k += bin(x[i]).count("1") if k == -1: print(0) else: print(pow(2, k, p))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR VAR VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
def no_of_ones(x): exp = 0 for ele in bin(x)[2:]: if ele == "1": exp += 1 return exp for i in range(int(input())): size = int(input()) arr = [int(i) for i in input().split()] result = 0 ans = 1 for i in range(size - 1): result += no_of_ones(arr[i]) poss = True for i in range(size - 1): if arr[i] & arr[i + 1] != arr[i]: poss = False break print(pow(2, result, 1000000007) if poss else 0)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR STRING VAR NUMBER RETURN VAR 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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER VAR NUMBER NUMBER
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
def solve(n, b): for i in range(n - 1): if b[i] & b[i + 1] != b[i]: print(0) return x = 0 for i in range(n - 1): x += bin(b[i]).count("1") ans = 1 while x: if x > 30: ans *= twopow[30] ans %= mod x -= 30 else: ans *= twopow[x] ans %= mod x = 0 print(ans % mod) mod = 10**9 + 7 twopow = {x: ((1 << x) % mod) for x in range(35)} for _ in range(int(input())): n = int(input()) b = list(map(int, input().split())) solve(n, b)
FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR VAR VAR STRING ASSIGN VAR NUMBER WHILE VAR IF VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
t = int(input()) for _ in range(t): n = int(input()) str1 = input().split(" ") a = [int(num) for num in str1] sum1 = 1 M = 1000000007 count = 0 for i in range(0, len(a) - 1, 1): if bin(a[i] & ~a[i + 1]).count("1") > 0: count = -1 break count += bin(a[i] & a[i + 1]).count("1") if count == -1: sum1 = 0 else: sum1 = 2**count % M print(sum1)
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 FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
t = int(input()) while t: t -= 1 n = int(input()) d = [int(i) for i in input().split()] a = [bin(i) for i in d] count = 1 mod = 10**9 + 7 for i in range(1, n): c = a[i - 1].count("1") count *= pow(2, c, mod) count = count % mod flag = 0 for i in range(1, n): if d[i - 1] | d[i] != d[i]: flag = 1 print(0) break if flag == 0: print(count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
t = int(input()) while t: n = int(input()) bArr = [int(x) for x in input().split()] valid = True for i in range(1, len(bArr)): if bArr[i] & bArr[i - 1] != bArr[i - 1]: valid = False if not valid: print(0) t -= 1 continue mod = 10**9 + 7 total_ways = 1 for i in range(1, len(bArr)): setbitsCount = bin(bArr[i - 1]).count("1") total_ways = total_ways * pow(2, setbitsCount, mod) % mod print(total_ways % mod) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
def power(x, y, p): res = 1 x = x % p while y > 0: if y & 1 == 1: res = res * x % p y = y >> 1 x = x * x % p return res def countSetBits(n): count = 0 while n: count += n & 1 n >>= 1 return count t = int(input()) while t: t -= 1 n = int(input()) po = 0 a = list(map(int, input().split())) valid = True for i in range(n - 1): if a[i] & a[i + 1] != a[i]: print(0) valid = False break if not valid: continue for i in range(n - 1): po += countSetBits(a[i] & a[i + 1]) print(power(2, po, 1000000007))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR NUMBER
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
m = 10**9 + 7 def cs(n, count): while n: count += n & 1 n >>= 1 return count for _ in range(int(input())): n, b, a = int(input()), list(map(int, input().split())), 1 for i in range(1, n): if b[i] & b[i - 1] == b[i - 1]: a = a * int(pow(2, cs(b[i - 1], 0))) % m else: a = 0 break print(a)
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
from sys import stdin, stdout def result(arr): M = 10**9 + 7 for i in range(n - 1): if arr[i] & arr[i + 1] != arr[i]: return 0 c = 0 for i in range(n): c += bin(arr[i]).count("1") c -= bin(arr[-1]).count("1") ans = 2 ** (c % M) % M return ans for _ in range(int(stdin.readline())): n = int(stdin.readline()) arr = list(map(int, stdin.readline().split())) print(result(arr))
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR STRING VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
M = 10**9 + 7 t = int(input()) for _ in range(t): n = int(input()) l = list(map(int, input().split())) count = 0 f = 0 for i in range(1, n): if l[i] < l[i - 1]: f = 1 break x = bin(l[i] & l[i - 1]) count = count + x.count("1") if f: print("0") continue print(2**count % M)
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR STRING IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
mod = 1000000007 tc = int(input()) for _ in range(tc): n = int(input()) b = list(map(int, input().split())) count = 0 for i in range(1, n): if b[i - 1] & b[i] == b[i - 1]: count += bin(b[i - 1]).count("1") else: print(0) break else: ans = 2**count % mod print(ans)
ASSIGN VAR NUMBER 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
def solve(lis, n): cnt = 0 for i in range(1, n): val = lis[i] & lis[i - 1] if val != lis[i - 1]: return -1 for i in range(32): if 1 << i & val > 0: cnt += 1 return 2**cnt % mod for t in range(int(input())): n = int(input()) lis = list(map(int, input().split())) mod = int(1000000000.0) + 7 ans = solve(lis, n) print(0 if ans == -1 else ans)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER RETURN BIN_OP BIN_OP NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
t = int(input()) while t > 0: n = int(input()) b = list(map(int, input().split())) ans = 1 for i in range(n - 1): if b[i] > b[i + 1]: ans = 0 break ans = ans * (1 << bin(b[i]).count("1")) % (10**9 + 7) print(ans % (10**9 + 7)) t = t - 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER FUNC_CALL FUNC_CALL VAR VAR VAR STRING BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
def c(s): r = 0 while s > 0: if s & 1 == 1: r += 1 s >>= 1 return r b = [1] * 40 for i in range(1, 40): b[i] = b[i - 1] * 2 % 1000000007 t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) s = a[0] p = 1 for i in range(1, n): if ~a[i] & s > 0: p = 0 break m = c(s) p *= b[m] p %= 1000000007 s = s | a[i] print(p)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
t = int(input()) def bitcount(n): count = 0 while n > 0: count = count + 1 n = n & n - 1 return count def exponent(a, b, modi): if b == 0: return 1 elif b == 1: return a % modi else: r = exponent(a, b // 2, modi) if b % 2 == 0: return r * r % modi else: return r * r % modi * a % modi while t > 0: n = int(input()) x = input().split() count = 0 r = -1 old = 0 flag = 0 for i in range(len(x) - 1): old = r r = bitcount(int(x[i])) if old > r: flag = -1 break count += r if flag == 0: modi = 1000000007 ans = exponent(2, count, modi) print(ans) else: print("0") t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING VAR NUMBER
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
from sys import stdin def power(b, p, m): if p == 0: return 1 else: x = power(b, p // 2, m) % m x = x * x % m if p % 2 == 0: return x % m else: return x * b % m for _ in range(int(stdin.readline())): n = int(stdin.readline()) arr = list(map(int, stdin.readline().split())) s = 0 flag = False for i in range(1, n): if bin(arr[i - 1]).count("1") > bin(arr[i]).count("1"): print("0") flag = True break s += bin(arr[i - 1]).count("1") if not flag: print(power(2, s, 1000000007))
FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING FUNC_CALL FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR NUMBER
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
for _ in range(int(input())): N = int(input()) array = list(map(int, input().split())) ans = 1 Binary = [bin(array[0]).count("1")] for i in range(1, N): T = array[i] a = array[i - 1] Binary.append(bin(array[i]).count("1")) test = bin(T & a).count("1") if Binary[i - 1] > test: ans = 0 break ans = ans * (2**test % (10**9 + 7)) % (10**9 + 7) print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR VAR STRING IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
for i in range(int(input())): n = int(input()) sum1 = 1 l = list(map(int, input().split())) for i in range(1, n): z = l[i] & l[i - 1] str1 = bin(z).replace("0b", "") cnt1 = str1.count("1") if l[i] | l[i - 1] > l[i]: sum1 = 0 break sum1 = sum1 * 2**cnt1 sum1 = sum1 % 1000000007 print(sum1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
for _ in range(int(input())): n = int(input()) b = list(map(int, input().split())) count = 0 flag = 0 for i in range(1, n): if b[i] < b[i - 1]: flag = 1 break x = bin(b[i] & b[i - 1]) count = count + x.count("1") if flag == 1: print("0") else: print(pow(2, count, 10**9 + 7))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
def bi(n): count = 0 while n: count += 1 n = n & n - 1 return count t = int(input()) for q in range(t): n = int(input()) b = list(map(int, input().split())) ans = 1 mod = 10**9 + 7 end = 0 for i in range(1, n): if b[i] | b[i - 1] != b[i]: end = 1 print(0) break else: k = bi(b[i] & b[i - 1]) ans = ans * 2**k % mod if end == 0: print(ans)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
def setbit(n): cnt = 0 for i in range(32): if n & 1 << i: cnt += 1 return cnt def power(n): res = 1 a = 2 while n > 0: if n & 1: res = res * a % 1000000007 a = a * a % 1000000007 n >>= 1 return res for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) flag, bit = 1, 0 for i in range(1, n): if arr[i - 1] & arr[i] == arr[i - 1]: bit += setbit(arr[i - 1]) else: flag = 0 print(0) break if flag: print(power(bit))
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) c = 0 a = 1 for i in range(1, n): p = l[i - 1] & l[i] if p != l[i - 1]: a = 0 break else: c += bin(p).count("1") if a == 0: print(0) else: print(2**c % (10**9 + 7))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
t = int(input()) for _ in range(t): n = int(input()) falg = 1 s = [int(x) for x in input().split()] sum = 0 for i in range(1, len(s)): if s[i - 1] & s[i] != s[i - 1]: falg = 0 break else: sum += bin(s[i - 1] & s[i]).count("1") if falg != 0: print(pow(2, sum, 1000000007)) else: print(0)
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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
mod = 10**9 + 7 def check_0(a, b): if a > b: return False else: a = bin(a)[2:] b = bin(b)[2:] a = "0" * (len(b) - len(a)) + a b1 = True for x in range(len(b)): if b[x] == "0": if a[x] == "1": b1 = False break return b1 for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) ans = 1 b = True for i in range(1, n): if not check_0(arr[i - 1], arr[i]): b = False print(0) break else: ones = bin(arr[i] & arr[i - 1]).count("1") prod = 2**ones % mod ans = ans % mod * prod % mod if b: print(ans)
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR STRING ASSIGN VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
def countSetBits(N): count = 0 while N: N &= N - 1 count += 1 return count def main(): T = int(input()) mod = int(1000000000.0 + 7) for _ in range(T): N = int(input()) B = list(map(int, input().split())) ans = 1 for i in range(N): if i > 0 and B[i] & B[i - 1] != B[i - 1]: ans = 0 break if i <= N - 2: ans = ans % mod * (pow(2, countSetBits(B[i]), mod) % mod) % mod print(ans) main()
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
mod = 10**9 + 7 for _ in range(int(input())): N = int(input()) arr = list(map(int, input().split())) setb = lambda x: bin(x).count("1") ans = 1 mult = [] for i in range(1, N): if arr[i] & arr[i - 1] != arr[i - 1]: mult.clear() break mult.append(setb(arr[i] & arr[i - 1])) ans = pow(2, sum(mult), mod) if not mult: print(0) else: print(ans)
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequence of integers $A_1, A_2, \ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \ldots, B_N$, where $B_i = \bigvee_{j=1}^i A_j$ for each valid $i$ and $\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence. Now, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the number of possible sequences $A$ modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 25$ - $1 \le N \le 5 \cdot 10^4$ - $0 \le B_i < 2^{30}$ for each valid $i$ -----Example Input----- 2 2 2 3 4 2 6 7 7 -----Example Output----- 2 64 -----Explanation----- Example case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.
import sys m = 1000000000.0 + 7 def countSetBits(n): count = 0 while n: n &= n - 1 count += 1 return count t = int(input()) for _ in range(t): n = int(input()) nums = list(map(int, input().split())) ans = 1 flag = 0 for i in range(n - 1): if nums[i] > nums[i + 1]: flag = 1 break ans = ans % m * pow(2, countSetBits(nums[i])) % m % m if flag: print(0) else: print(int(ans))
IMPORT ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR