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$.
for nt in range(int(input())): n = int(input()) l = list(map(int, input().split())) s = sum(l) e = l[0] for i in range(1, n): e = e ^ l[i] if s == 2 * e: print(0) print() else: print(2) print(e, s + e)
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 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$.
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline write = sys.stdout.write def ii(): return int(readline()) def mi(): return map(int, readline().rstrip().split()) def li(): return list(readline().rstrip()) def lmi(): return list(map(int, readline().rstrip().split())) def end(*arg): print(*arg) sys.exit() def main(): t = ii() for _ in range(t): n = ii() a = lmi() s = sum(a) x = 0 for i in range(n): x ^= a[i] if s != 2 * x: k1 = x s += k1 k2 = s print(2) print(k1, k2) else: print(0) print() return main()
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR RETURN 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 _ in range(T): n = int(input()) li = input().split() sm = 0 xor = 0 for i in range(n): sm = sm + int(li[i]) xor = xor ^ int(li[i]) if 2 * xor == sm: print("0") print("") else: print("2") s = "" s = str(xor) + " " sm = sm + xor s = s + str(sm) print(s)
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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP 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())): n = int(input()) l = list(map(int, input().split())) s = 0 x = 0 for i in range(n): s += l[i] x = x ^ l[i] if s == 2 * x: print(0) print() elif x == 0: print(3) print(2, 2, s + 4) else: 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP 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 NUMBER NUMBER BIN_OP VAR 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$.
import sys def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int, minp().split()) def solve(): n = mint() a = list(mints()) x = 0 y = 0 for i in a: x += i y ^= i if x == 2 * y: print(0) print() else: print(2) print(y, x + y) for i in range(mint()): solve()
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR 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$.
def list_xor(arr): a = 0 for i in arr: a = a ^ i return a def find_numbers(arr): s = sum(arr) x = list_xor(arr) b = [] b.append(x) k = x x = x ^ k s = s + k if x != 0: raise Exception if s % 2 == 0: k = s b.append(s) s = s + k x = x ^ k if s != 2 * x: raise Exception(str(s) + " " + str(x)) return b else: b.append(1) s = s + 1 x = x ^ 1 if s % 2 != 0: raise Exception k = s / 2 - 1 b.append(k) s = s + k x = x ^ k if s != 2 * x: raise Exception return b t = int(input()) for _ in range(t): size = int(input()) array = [int(i) for i in input().split()] nums = find_numbers(array) print(len(nums)) print(" ".join([str(i) for i in nums]))
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR RETURN VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP NUMBER VAR VAR 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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$.
t = int(input()) i = 0 while i < t: n = int(input()) arr = list(map(int, input().split())) a = sum(arr) s = 0 for x in arr: s = s ^ x if a == 2 * s: print(0) print() else: print(2) print(s, a + s) i = i + 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP 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 ASSIGN VAR 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$.
def xor(a): ans = 0 for i in range(n): ans ^= a[i] return ans t = int(input()) for _ in range(t): n = int(input()) a = [int(i) for i in input().split()] ans = [] sm = sum(a) xora = xor(a) if sm == 2 * xora: pass elif xor(a) == 0: ans.append(sm) else: ans.append(xora) ans.append(sm + xora) print(len(ans)) for i in ans: print(i, end=" ") print()
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP NUMBER VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING 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 xor(arr): if len(arr) == 1: return arr[0] else: ans = arr[0] ^ arr[1] for i in range(2, len(arr)): ans = ans ^ arr[i] return ans t = int(input()) for i in range(t): n = int(input()) arr = [int(i) for i in input().split()] s = sum(arr) x = xor(arr) if s == 2 * x: print(0) print(" ") else: print(2) print(x, s + x)
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL 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$.
for test in range(int(input())): k = int(input()) c1 = list(map(int, input().split())) x = 0 s = sum(c1) answer = [] for i in c1: x ^= i if s == 2 * x: print(0) print() continue elif s % 2 == 0: answer = [x, x + s] print(2) print(answer[0], answer[1]) elif s % 2 == 1: s += 1 x ^= 1 answer = [1, x, x + s] print(3) print(answer[0], answer[1], answer[2])
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 VAR ASSIGN VAR LIST 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 ASSIGN VAR LIST VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER 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$.
import sys input = sys.stdin.buffer.readline t = int(input()) for _ in range(t): n = int(input()) a = [int(x) for x in input().split()] ps = sum(a) xor = 0 for x in a: xor = xor ^ x xx = 2**59 | xor z = 2 * 2**59 - xx - ps print(3) print("{} {} {}".format(xx, z // 2, z // 2))
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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR 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$.
T = int(input()) for t in range(T): n = int(input()) a = [int(x) for x in input().split()] print(2) x = sum(a) y = a[0] for i in range(1, n): y = y ^ a[i] x += y print(x, y)
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 EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR 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$.
import sys input = sys.stdin.readline def swaparr(arr, a, b): temp = arr[a] arr[a] = arr[b] arr[b] = temp def gcd(a, b): if b == 0: return a return gcd(b, a % b) def nCr(n, k): if k > n - k: k = n - k res = 1 for i in range(k): res = res * (n - i) res = res / (i + 1) return int(res) def upper_bound(a, x, lo=0): hi = len(a) while lo < hi: mid = (lo + hi) // 2 if a[mid] < x: lo = mid + 1 else: hi = mid return lo def primefs(n): primes = {} while n % 2 == 0 and n > 0: primes[2] = primes.get(2, 0) + 1 n = n // 2 for i in range(3, int(n**0.5) + 2, 2): while n % i == 0 and n > 0: primes[i] = primes.get(i, 0) + 1 n = n // i if n > 2: primes[n] = primes.get(n, 0) + 1 return primes def power(x, y, p): res = 1 x = x % p if x == 0: return 0 while y > 0: if y & 1 == 1: res = res * x % p y = y >> 1 x = x * x % p return res def swap(a, b): temp = a a = b b = temp return a, b def find(x, link): p = x while p != link[p]: p = link[p] while x != p: nex = link[x] link[x] = p x = nex return p def union(x, y, link, size): x = find(x, link) y = find(y, link) if size[x] < size[y]: x, y = swap(x, y) if x != y: size[x] += size[y] link[y] = x def sieve(n): prime = [(True) for i in range(n + 1)] p = 2 while p * p <= n: if prime[p] == True: for i in range(p * p, n + 1, p): prime[i] = False p += 1 return prime MAXN = int(1000000.0 + 5) def spf_sieve(): spf[1] = 1 for i in range(2, MAXN): spf[i] = i for i in range(4, MAXN, 2): spf[i] = 2 for i in range(3, ceil(MAXN**0.5), 2): if spf[i] == i: for j in range(i * i, MAXN, i): if spf[j] == j: spf[j] = i def factoriazation(x): ret = {} while x != 1: ret[spf[x]] = ret.get(spf[x], 0) + 1 x = x // spf[x] return ret def int_array(): return list(map(int, input().strip().split())) def str_array(): return input().strip().split() MOD = int(1000000000.0) + 7 CMOD = 998244353 INF = float("inf") NINF = -float("inf") for _ in range(int(input())): n = int(input()) a = int_array() x = sum(a) y = a[0] for i in a[1:]: y = y ^ i print(2) print(y, x + y)
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR FUNC_DEF NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR DICT WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR WHILE VAR VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR DICT WHILE VAR NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR NUMBER 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$.
def proc_case(a): sum = 0 xor = 0 for i in a: sum += i xor ^= i if sum == xor * 2: return 0, [] if xor == 0: return 1, [sum] return 2, [xor, xor + sum] cases_num = int(input()) for _ in range(cases_num): _ = input() a = [int(i) for i in input().split(" ")] c, nums = proc_case(a) print(f"{c}\n{' '.join([str(i) for i in nums])}")
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER RETURN NUMBER LIST IF VAR NUMBER RETURN NUMBER LIST VAR RETURN NUMBER LIST VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING FUNC_CALL STRING 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 zz = 1 sys.setrecursionlimit(10**5) if zz: input = sys.stdin.readline else: sys.stdin = open("input.txt", "r") sys.stdout = open("all.txt", "w") di = [[-1, 0], [1, 0], [0, 1], [0, -1]] def fori(n): return [fi() for i in range(n)] def inc(d, c, x=1): d[c] = d[c] + x if c in d else x def ii(): return input().rstrip() def li(): return [int(xx) for xx in input().split()] def fli(): return [float(x) for x in input().split()] def comp(a, b): if a > b: return 2 return 2 if a == b else 0 def gi(): return [xx for xx in input().split()] def gtc(tc, ans): print("Case #" + str(tc) + ":", ans) def cil(n, m): return n // m + int(n % m > 0) def fi(): return int(input()) def pro(a): return reduce(lambda a, b: a * b, a) def swap(a, i, j): a[i], a[j] = a[j], a[i] def si(): return list(input().rstrip()) def mi(): return map(int, input().split()) def gh(): sys.stdout.flush() def isvalid(i, j, n, m): return 0 <= i < n and 0 <= j < m def bo(i): return ord(i) - ord("a") def graph(n, m): for i in range(m): x, y = mi() a[x].append(y) a[y].append(x) t = fi() uu = t while t > 0: t -= 1 n = fi() a = li() s = x = 0 for i in range(n): s += a[i] x ^= a[i] print(2) print(x, s + x)
IMPORT ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN NUMBER RETURN VAR VAR NUMBER NUMBER FUNC_DEF RETURN VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING FUNC_CALL VAR VAR STRING VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_DEF RETURN NUMBER VAR VAR NUMBER VAR VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR 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$.
def f(l): print(len(l)) print(" ".join(list(map(str, l)))) t = int(input()) for ii in range(t): n = int(input()) a = list(map(int, input().split())) xor = 0 s = 0 for a1 in a: xor ^= a1 s += a1 res = [] tmp = 4 - s % 4 + 1000000000000000 a.append(tmp) res.append(tmp) s += tmp xor ^= tmp ss = s // 2 if ss == xor: f(res) elif ss < xor: tmp = xor - ss res.append(tmp) res.append(tmp) a.append(tmp) a.append(tmp) f(res)
FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR 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())): n = int(input()) a = [int(i) for i in input().split()] s = sum(a) add = [] xor = 0 for i in a: xor ^= i if s == 2 * xor: pass elif xor == 0: add.append(s) else: add.append(xor) s += xor add.append(s) print(len(add)) print(*add)
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 FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR BIN_OP NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR 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$.
import sys class CMakeGood: def solve(self): for _ in range(int(input())): n = int(input()) a = [int(_) for _ in input().split()] sm = sum(a) xor = 0 for i in range(n): xor ^= a[i] print(2) print(xor, sm + xor) solver = CMakeGood() input = sys.stdin.readline solver.solve()
IMPORT CLASS_DEF FUNC_DEF 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 FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN 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$.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) s = sum(a) / 2 ans = 0 for x in a: ans ^= x if ans == s: print(0) print() else: ans = a[0] s = a[0] for x in range(1, n): ans ^= a[x] s += a[x] elem1 = ans elem2 = s + ans if elem1 == 0: print(1) print(elem2) else: print(2) print(elem1, elem2)
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 VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER 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 i in range(t): n = int(input()) ar = [int(x) for x in input().split()] sm = 0 xor = 0 for j in range(n): sm += ar[j] xor ^= ar[j] if sm == 2 * xor: print("0") else: print("2") print(xor, sm + xor, end=" ") print()
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 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 STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR STRING 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())): input() a = list(map(int, input().split())) print(2) ans1 = 0 for ai in a: ans1 ^= ai a.append(ans1) print(ans1, sum(a))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR 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 i in range(int(input())): a = input() arr = list(map(int, input().split())) ok, nook = arr[0], arr[0] for j in range(1, len(arr)): ok += arr[j] nook ^= arr[j] if nook == 0: print(1) print(ok) else: print(2) print(nook, nook + ok)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR VAR VAR 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$.
t = int(input()) for i in range(t): n = int(input()) a = [int(x) for x in input().split()] suma = sum(a) xor = a[0] for j in range(1, n): xor = xor ^ a[j] if suma == xor * 2: print(0) print() else: print(2) print(str(xor) + " " + str(suma + 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 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 VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL 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$.
t = int(input()) for i in range(t): n = int(input()) ls = [] x = 0 ls = [int(a) for a in input().split()] for j in range(n): x = x ^ ls[j] sm = sum(ls) an = [] an.append(x) an.append(sm + x) print(len(an)) for a in an: print(a)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR 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 dcb(num): res = "" temp = num % 2 temp1 = int(num / 2) if temp1 < 2: res += str(temp) + str(temp1) return res else: res += str(temp) return res + dcb(temp1) t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) sum1 = 0 xor1 = 0 for i in range(n): sum1 += a[i] xor1 = xor1 ^ a[i] res = [] if sum1 % 2 == 1: if xor1 == 1: res.append(3) sum1 += 3 xor1 = xor1 ^ 3 else: res.append(1) sum1 += 1 xor1 = xor1 ^ 1 if xor1 == 0: res.append(2) xor1 = 2 sum1 += 2 sum2 = 2 * xor1 if sum2 == sum1: print(len(res)) for i in res: print(i, end=" ") print() elif sum2 > sum1: diff = int((sum2 - sum1) / 2) res.append(diff) res.append(diff) print(len(res)) for i in res: print(i, end=" ") print() else: res.append(xor1) sum1 += xor1 res.append(sum1) print(len(res)) for i in res: print(i, end=" ") print()
FUNC_DEF ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR VAR FUNC_CALL VAR VAR RETURN BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR LIST IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING 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 _ in range(t): n = int(input()) A = list(map(int, input().split())) S = sum(A) X = 0 for a in A: X = X ^ a if S % 2 == 0: b_1 = 10**15 S += b_1 X = X ^ b_1 b_2 = (X * 2 - S) // 2 print(3) print(b_1, b_2, b_2) else: b_1 = 10**15 + 1 S += b_1 X = X ^ b_1 b_2 = (X * 2 - S) // 2 print(3) print(b_1, b_2, b_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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER 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 input = sys.stdin.readline for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) c = sum(a) xor = 0 for i in a: xor ^= i add = [] if xor << 1 != c: add = [str(xor), str(c + xor)] print(len(add)) print(" ".join(add))
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 VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR LIST IF BIN_OP VAR NUMBER VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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 i in range(int(input())): n, s, xor = input(), 0, 0 for j in map(int, input().split()): xor ^= j s += j print("0\n " if s == 2 * xor else "2\n" + str(xor) + " " + str(s + xor))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP NUMBER VAR STRING BIN_OP BIN_OP BIN_OP STRING 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$.
for _ in range(int(input())): n = int(input()) l = list(map(int, input().split(" "))) xor = 0 for i in l: xor ^= i print(2) print(xor, xor + sum(l))
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 STRING ASSIGN VAR NUMBER FOR VAR VAR 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$.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) s = 0 x = 0 for i in range(n): s += a[i] x ^= a[i] if s == 2 * x: print("0") print() else: print(2) print(" ".join([str(x), str(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 FUNC_CALL 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 STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING LIST FUNC_CALL VAR VAR 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$.
t = int(input()) def cry(elem): y = 0 for i in elem: y ^= i return y def roar(stuff, indx): s[indx] += 1 for i in range(t): p = 1 c = 0 n = int(input()) a = list(map(int, input().split())) s, x = [0, 0, 0] + list(map(int, bin(sum(a))[2:])), list(map(int, bin(cry(a))[2:])) x = [(0) for i in range(len(s) - len(x) - 1)] + x nextsum, nextxor = False, False ans = 0 if s[-1] == 1: ans += 1 nextsum, nextxor = True, True for i in range(-1, -len(x), -1): p *= 2 se, xe = s[i - 1], x[i] if nextsum: if se == 0: se = 1 nextsum = False else: se = 0 nextsum = True if nextxor: xe = 1 - xe nextxor = False if se != xe: ans += p c += 1 if se == 0: se = 1 else: se = 0 nextsum = True nextxor = True print(1, ans, sep="\n")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR RETURN VAR FUNC_DEF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN 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 BIN_OP LIST NUMBER NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR IF VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER 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$.
import sys input = sys.stdin.readline t = int(input()) inf = 10**18 for _ in range(t): n = int(input()) it = list(map(int, input().split())) x = sum(it) y = it[0] for i in range(1, n): y = y ^ it[i] if x % 2 == 0: x += inf y = (y ^ inf) * 2 print(3) print(inf, (y - x) // 2, (y - x) // 2) else: x += inf - 1 y = (y ^ inf - 1) * 2 print(3) print(inf - 1, (y - x) // 2, (y - x) // 2)
IMPORT ASSIGN VAR VAR 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 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 BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP 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 main(): n = int(input()) lst = list(map(int, input().split())) sum = 0 xor = 0 for i in lst: sum += i xor = xor ^ i if sum == 2 * xor: print(0) print() else: sum += xor print(2) print(xor, sum) t = int(input()) for i in range(t): main()
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 ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL 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$.
t = int(input()) for i in range(t): n = int(input()) arr = list(map(int, input().split())) s = 0 j = 0 for i in range(n): s += arr[i] j ^= arr[i] if s == 2 * j: print(0) print() else: print(3) if s % 2 == 0: val = pow(2, 48) j = j ^ val s = s + val print((2 * j - s) // 2, (2 * j - s) // 2, val) else: val = pow(2, 48) + 1 j = j ^ val s = s + val print((2 * j - s) // 2, (2 * j - s) // 2, val)
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 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 IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER BIN_OP BIN_OP BIN_OP NUMBER 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$.
for _ in range(int(input())): n = int(input()) a = [int(i) for i in input().split()] s = sum(a) add = [] xor = 0 for i in a: xor ^= i print("2") print(xor, s + xor)
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 FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING 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("")) mat = [] for i in range(t): input("") mat.append(list(map(int, input().split()))) for i in range(t): y = mat[i] s = sum(y) x = 0 for i in range(len(y)): x = x ^ y[i] print(2) print(x, s + x)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR 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 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$.
def to_2(x): ans = [] while x > 0: ans.append(x % 2) x //= 2 return ans[::-1] def to_10(arr): ans = 0 cur = 1 for i in arr: ans += i * cur cur <<= 1 return ans t = int(input()) for kkk in range(t): n = int(input()) a = list(map(int, input().split())) ss = sum(a) xx = 0 for i in range(n): xx ^= a[i] xx <<= 1 ss1 = to_2(ss) ss1.reverse() xx1 = to_2(xx) xx1.reverse() kek1 = [(0) for i in range(50)] kek2 = [(0) for i in range(50)] kek3 = [(0) for i in range(50)] cur = 0 cnt = 0 while True: sum_is_ended = False xor_is_ended = False cursum = 0 curxor = 0 if cur >= len(ss1): sum_is_ended = True ss1.append(0) cursum = 0 else: cursum = ss1[cur] if cur >= len(xx1): xor_is_ended = True xx1.append(0) curxor = 0 else: curxor = xx1[cur] if xor_is_ended and sum_is_ended: break if cursum == curxor: pass elif cursum == 1 and curxor == 0: kek1[cur] = 1 if len(xx1) <= cur + 1: xx1.append(0) xx1[cur + 1] += 1 xx1[cur + 1] %= 2 ost = 0 ss1[cur] += 1 if ss1[cur] == 2: ost = 1 ss1[cur] = 0 j = 1 while ost: if len(ss1) <= cur + j: ss1.append(0) ss1[cur + j] += 1 if ss1[cur + j] == 2: ost = 1 ss1[cur + j] = 0 j += 1 else: break else: kek2[cur - 1] = 1 kek3[cur - 1] = 1 ost = 0 ss1[cur] = 1 cur += 1 print(3) print(to_10(kek1), to_10(kek2), to_10(kek3))
FUNC_DEF ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR 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 FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR IF VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR IF FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR 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$.
t = int(input()) for i in range(t): n = int(input()) a = [int(i) for i in input().split()] s = 0 xr = 0 for i in a: xr = xr ^ i s = s + i iin = 55 A = 1 << iin if s % 2 == 1: A += 1 s += A xr ^= A B = (2 * xr - s) // 2 print(3) print(A, B, B)
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 ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER 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 rli(): return list(map(int, input().split())) def solve(): rli() nums = rli() ans = sum(nums) t1 = 0 for n in nums: t1 = t1 ^ n ans += t1 print(2) print(ans, t1) def main(): s = rli()[0] for i in range(s): solve() main()
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER 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 i in range(t): n = int(input()) a = list(map(int, input().strip().split())) b = 0 for j in a: b = b ^ j if b == 0: print(1) print(sum(a)) else: print(2) print(b, sum(a) + b)
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 FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER 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$.
t = int(input()) while t != 0: t -= 1 n = int(input()) a = list(map(int, input().split())) x = a[0] s = a[0] y = z = 0 for i in range(1, n): s += a[i] x = x ^ a[i] if s == 2 * x: print(0) print() elif s % 2 == 0 and s == x: y = z = int(s / 2) print(2) print(y, z) else: y = x z = x + s print(2) print(y, z)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER 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 ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP 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 VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER 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 i in range(t): y = 0 n = int(input()) c = list(map(int, input().split())) for j in range(n): y = y ^ c[j] y = int(y) ch = y % 2 d = 800 * sum(c) u = 10 * d + ch p = (2 * (u ^ y) - u - sum(c)) // 2 print(3) print(u, p, p)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR VAR VAR FUNC_CALL 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$.
t = int(input()) while t != 0: t -= 1 n = int(input()) ar = list(map(int, input().split())) s = sum(ar) ele = 0 for it in ar: ele ^= it s += ele print("2\n{0} {1}".format(ele, s))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER 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 VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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()) a = list(map(int, input().split())) xor = 0 s = 0 for each in a: xor = xor ^ each s = s + each if s == 2 * xor: print(0) else: print(2) a.append(xor) s = s + xor print(xor, s) 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 ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR 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$.
t = int(input()) for rwuer in range(t): n = int(input()) l = list(map(int, input().split())) x = l[0] s = l[0] for i in range(1, n): x = x ^ l[i] s += l[i] c = max(s, x) * 100 if (s + c) % 2 == 1: c += 1 aplusb = 2 * (x ^ c) - (s + c) a = aplusb // 2 b = a print(3) print(a, 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR 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$.
t = int(input()) for i in range(0, t): n = int(input()) b1 = [int(x) for x in input().split()] resultado = b1[0] suma = b1[0] for i in range(1, n): resultado = resultado ^ b1[i] suma += b1[i] if 2 * resultado == suma: print(0) print() else: print(2) suma += resultado print(resultado, "", suma)
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 VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER 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 EXPR FUNC_CALL VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR STRING 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 z in range(t): n = int(input()) arr = list(map(int, input().split())) xor = arr[0] for i in range(1, n): xor = xor ^ arr[i] print("2") print(xor, sum(arr) + 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 VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR 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$.
from sys import stdin MAX = 10**9 + 1 def input(): return stdin.readline() for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) axor = asum = a[0] for i in range(1, n): asum += a[i] axor ^= a[i] if asum == 2 * axor: print(0) print("") else: print(2) print(axor, asum + axor)
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL 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 VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR 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$.
from sys import stdin def input(): return stdin.readline()[:-1] def intput(): return int(input()) def sinput(): return input().split() def intsput(): return map(int, sinput()) debugging = False def dprint(*args): if debugging: print(*args) else: pass t = intput() for _ in range(t): n = intput() a = list(intsput()) places = [0] * 70 for x in a: br = bin(x)[2:][::-1] for i in range(len(br)): if br[i] == "1": places[i] += 1 b1 = 2**54 for i in range(54): if places[i] % 2: b1 += 2**i b2seed = 2**55 - sum(a) - b1 b2seed = bin(b2seed)[2:][::-1] b2 = [""] * 100 for i in range(len(b2seed)): if b2seed[i] == "1": b2[i - 1] = "1" else: b2[i - 1] = "0" b2 = int("".join(b2)[::-1], 2) print(3) print(b1, b2, b2)
FUNC_DEF RETURN FUNC_CALL VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST STRING NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER 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$.
t = int(input()) for test in range(t): n = int(input()) arr = list(map(int, input().split())) s = sum(arr) x = 0 for i in arr: x = x ^ i print("2") res = str(x) + " " + str(x + s) print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR BIN_OP 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())): n = int(input()) xor = 0 suma = 0 a = list(map(int, input().strip().split())) for i in range(n): xor = xor ^ a[i] suma = sum(a) if suma == 2 * xor: print(0) print() else: print(2) print(xor, end=" ") print(suma + xor)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL 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 STRING EXPR 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$.
def compute(S, X): A = (S - X) // 2 a = 0 b = 0 for i in range(64): Xi = X & 1 << i Ai = A & 1 << i if Xi == 0 and Ai == 0: pass elif Xi == 0 and Ai > 0: a = 1 << i | a b = 1 << i | b elif Xi > 0 and Ai == 0: a = 1 << i | a else: return return a, b t = int(input()) for _ in range(t): n = int(input()) l = list(map(int, input().split())) Sum = sum(l) xr = 0 for x in l: xr = xr ^ x a, b = compute(2**60 - Sum - xr, 2**60 // 2) l.append(xr) l.append(a) l.append(b) xr = 0 for x in l: xr = xr ^ x print(3) print(*l[-3:])
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR RETURN RETURN 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 FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER NUMBER VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL 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 makeitgood(n, ll): sum = 0 cishu = 0 tmp = 0 resultarray = [] for i in range(0, n): sum = sum + ll[i] tmp = tmp ^ ll[i] if sum == 2 * tmp: return 0, None if sum % 2 != 0: app = 4 * sum + 1 resultarray.append(app) tmp = tmp ^ app sum = sum + app cishu = cishu + 1 else: app = 4 * sum resultarray.append(app) tmp = tmp ^ app sum = sum + app cishu = cishu + 1 if sum == 2 * tmp: return cishu, resultarray else: cha = int((2 * tmp - sum) / 2) resultarray.append(cha) resultarray.append(cha) cishu = cishu + 2 return cishu, resultarray tests = int(input()) for i in range(0, tests): numberlen = int(input()) numbers = input().split() numberss = list(map(int, numbers)) elementnumber, elements = makeitgood(numberlen, numberss) print(elementnumber) if elements == None: print(" ") else: for e in range(0, len(elements)): if e == len(elements) - 1: print(elements[e]) else: print(elements[e], end=" ")
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR BIN_OP NUMBER VAR RETURN NUMBER NONE IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP NUMBER VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR VAR 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NONE EXPR FUNC_CALL VAR STRING 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 EXPR FUNC_CALL VAR VAR 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$.
inp = lambda cast=int: [cast(x) for x in input().split()] printf = lambda s="", *args, **kwargs: print(str(s).format(*args), flush=True, **kwargs) (t,) = inp() for _ in range(t): (n,) = inp() A = inp() s = sum(A) x = 0 for a in A: x ^= a print(2) print(x, x + s)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR 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$.
t = int(input()) while t > 0: n = int(input()) Sum = 0 sum_xor = 0 A = [int(x) for x in input().split()] for x in A: Sum += x sum_xor = sum_xor ^ x if Sum == 2 * sum_xor: print("0\n") t -= 1 continue if sum_xor != 0: y = sum_xor b = Sum + y print(2) print(str(y) + " " + str(b)) else: a = Sum print(1) print(a) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL 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 [0] * int(input()): n = int(input()) S = 0 X = 0 for i in list(map(int, input().split())): S += i X ^= i print(2) print(str(X) + " " + str(S + X))
FOR VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL 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$.
for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) x = s = l[0] for i in range(1, n): x ^= l[i] s += l[i] if 2 * x == s: print(0) else: p = s - x a = b = c = 0 a = x b = s + x print(3) print(a, b, c)
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 VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR VAR IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR 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$.
x = int(input()) for i in range(x): s = 0 m = 0 y = int(input()) z = list(map(int, input().split(" "))) for i in range(y): s = s + z[i] m = m ^ z[i] print(2) print(m, s + m)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING 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
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())) x = 0 for u in A: x ^= u s = sum(A) + x print(2, x, s)
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 VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR 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 _ in range(t): n = int(input()) prod, su = 0, 0 ai = list(map(int, input().split())) for e in ai: prod ^= e su += e ans = [prod, prod + su] 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 VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST VAR BIN_OP 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 i in " " * int(input()): n = int(input()) L = list(map(int, input().split())) x = 0 for i in L: x = x ^ i x *= 2 s = sum(L) if s == x: print(0) print() elif s < x: if (x - s) % 2 == 0: print(2) print((x - s) // 2, (x - s) // 2) else: if x - s > 3: print(3) print(1, (x - s - 3) // 2, (x - s - 3) // 2) if x - s == 3: print(1) print(1) if x - s == 1: print(3) print(1, x // 2 - 1, s + x // 2) elif x == 0: print(1) print(s) else: print(2) print(x // 2, s + x // 2)
FOR VAR BIN_OP STRING 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 VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR 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$.
import sys input = sys.stdin.buffer.readline t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) xor = a[0] for el in a[1:]: xor ^= el num_1 = xor num_2 = sum(a) + xor print(2) print(num_1, num_2)
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 VAR NUMBER FOR VAR VAR NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER 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 i in range(t): n = int(input()) A = list(map(int, input().split())) B = [0] * 70 for j in range(n): k = A[j] l = 0 while k != 0: if k % 2 == 1: B[l] += 1 k //= 2 l += 1 Bh = B[:] C = [0] * 70 for i in range(len(B)): if C[i] == 1: if B[i] % 2 == 0: B[i] += 1 elif B[i] % 2 == 1: B[i] += 1 k = B[i] - C[i] l = i while k != 0: if k % 2 == 1: if C[l] == 0: C[l] = 1 else: ii = l while C[ii] == 1: C[ii] = 0 ii += 1 C[ii] = 1 k //= 2 l += 1 ans = [] for ii in range(3): if Bh == B: break aa = 0 for jj in range(len(B)): if B[jj] - Bh[jj] > 0: aa += 2**jj B[jj] -= 1 ans.append(aa) print(len(ans)) print(" ".join([str(ii) for ii in 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR BIN_OP NUMBER VAR VAR VAR NUMBER 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 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$.
from sys import stdin input = stdin.readline for _ in range(int(input())): n = int(input()) s = 0 p = 0 for i in map(int, input().split()): s += i p ^= i if s == p * 2: print(0, "\n") else: print(2) print(p, s + p)
ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER 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()) for _ in range(t): n = int(input()) arr = [int(i) for i in input().split()] sum_arr = sum(arr) xor_arr = 0 for i in range(n): xor_arr = xor_arr ^ arr[i] ans = [] ans.append(xor_arr) y = sum_arr + xor_arr ans.append(y) 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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP 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$.
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) total = sum(a) xor = 0 for i in range(n): xor ^= a[i] if total == 2 * xor: print(0) print() continue goal = 2**50 x = goal * 2 - total y = goal ^ xor ans1 = y ans2 = (x - y) // 2 print(3) print(ans1, ans2, ans2) if total + ans1 + ans2 * 2 != 2 * (xor ^ ans1 ^ ans2 ^ ans2): raise Exception("hoge")
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 FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR 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(map(int, input().rstrip().split())) s = sum(a) c = 0 for i in a: c = c ^ i if s == 2 * c: print(0) print() else: ans = [] s += c ans.append(c) ans.append(s) print(2) print(str(c) + " " + str(s))
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING 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()) while t: t = t - 1 n = int(input()) arr = [int(s) for s in input().split()] S = sum(arr) if n >= 2: X = arr[0] ^ arr[1] for i in range(2, n): X = X ^ arr[i] else: X = arr[0] print("2") print(S + X, X)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR BIN_OP 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 IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP 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()) ans = [] def solve(l): s = sum(l) xr = 0 for i in l: xr ^= i if s == 2 * xr: return "0\n" else: return "2\n{} {}".format(xr, s + xr) for _ in range(t): n = int(input()) l = [int(i) for i in input().split()] ans.append(solve(l)) for s in ans: print(s)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR BIN_OP NUMBER VAR RETURN STRING RETURN FUNC_CALL STRING VAR BIN_OP VAR 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR 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$.
x = int(input()) for i in range(x): t = int(input()) r = list(map(int, input().strip().split())) totalsum = sum(r) for i in range(t - 1): y = r.pop() r[0] = r[0] ^ y finalxor = r[0] print("2") print(str(finalxor) + " " + str(finalxor + totalsum))
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR STRING 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$.
t = int(input()) for i in range(t): n = int(input()) A = [int(j) for j in input().split()] summ = sum(A) bsum = A[0] for k in range(1, n): bsum ^= A[k] if summ == 2 * bsum: print(0) print() else: d = abs(summ - bsum) * 100 if d == 0: d = 100 if summ % 2 == 1: g1 = d + 1 summ += d + 1 bsum ^= d + 1 else: g1 = d summ += d bsum ^= d ds = abs(summ - 2 * bsum) // 2 g2 = ds g3 = ds print(3) print(g1, g2, g3)
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 FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR 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$.
I = input for _ in range(int(I())): n = int(I()) a = list(map(int, I().split(" "))) s = sum(a) x = a[0] if n > 1: x = a[0] ^ a[1] for i in range(2, n): x = x ^ a[i] if (s + x) % 2 == 0: print(2) print(x, s + x) else: print(3) f1 = s + x f = f1 + 1 l = 0 if f % 2 == 0: l = f + 1 else: l = f - 1 print(x, 1, l)
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 STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP 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$.
for _ in " " * int(input()): a = int(input()) x = 0 s = 0 for i in map(int, input().split()): x ^= i s += i print(2) print(x, s + x)
FOR VAR BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR 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$.
for i in range(int(input())): n = int(input()) (*a,) = map(int, input().split()) print(3) s = sum(a) x = 0 for i in a: x ^= i b = (1 << 55) - 2 ^ x print(b, (2 * ((1 << 55) - 2) - s - b) // 2, (2 * ((1 << 55) - 2) - s - b) // 2)
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 FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER 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 solve(): x = int(input()) s = list(map(int, input().split())) xr = 0 for n in s: xr ^= n sm = sum(s) print(2) print(xr, sm + xr) for n in range(int(input())): solve()
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 FOR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR 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()) l = list(map(int, input().split())) a = sum(l) xor = l[0] for i in range(1, n): xor ^= l[i] l.append(xor) a += l[-1] l.append(a) print(2) for i in range(len(l) - 1, len(l) - 3, -1): print(l[i], end=" ") print()
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 VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR STRING 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 _ in range(t): n = int(input()) a = list(map(int, input().split())) s = sum(a) x = 0 for i in range(n): x = x ^ a[i] diff = abs(x * 2 - s) if x * 2 == s: print("0\n") elif x == 0: print("1") print("{}".format(s)) else: print("2") print("{} {}".format(x, s + x))
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 FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING 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$.
Ans = [] for j in range(int(input())): n = int(input()) A = list(map(int, input().split())) x = A[0] for i in range(1, len(A)): x ^= A[i] z1 = x Ans.append([z1, sum(A) + z1]) for a in Ans: print(2) print(*a)
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR LIST VAR BIN_OP FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR NUMBER 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())): n = int(input()) li = list(map(int, input().split())) a = sum(li) b = 0 for i in li: b ^= i if a == 2 * b: print(0) print("") else: ans = 2 if a % 2 == 1: ans += 1 a += 1 b ^= 1 print(ans) if ans == 3: print(1, end=" ") if a > 2 * b: print(b, a + b) else: print(abs(a - 2 * b) // 2, abs(a - 2 * b) // 2)
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 NUMBER FOR VAR VAR VAR VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER 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$.
t = int(input()) for _ in range(t): n = int(input()) nn = [int(i) for i in input().split()] x = 0 for i in nn: x ^= i ats = [] if 2 * x == sum(nn): print(len(ats)) print() else: ne = sum(nn) + x print(2) print(x, ne)
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 LIST IF BIN_OP NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER 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$.
def isKthBitSet(n, k): if n & 1 << k - 1: return True else: return False t = int(input()) while t: n = int(input()) a = input().split() for i in range(n): a[i] = int(a[i]) x = sum(a) y = 0 ls = [(0) for i in range(36)] for i in range(n): y = y ^ a[i] for j in range(36): if isKthBitSet(a[i], j + 1): ls[j] += 1 if x == 2 * y: print(0) print() elif x < 2 * y: if (2 * y - x) % 2 == 0: print(2) print((2 * y - x) // 2, (2 * y - x) // 2) elif ls[0] % 2 == 0: print(3) print(1, (2 * y - x + 1) // 2, (2 * y - x + 1) // 2) elif 2 * y - x == 1: print(3) print(2**58 + 1, (2**59 - 2**58 - 2) // 2, (2**59 - 2**58 - 2) // 2) else: print(3) print(1, (2 * y - x - 3) // 2, (2 * y - x - 3) // 2) elif (x - 2 * y) % 2 == 0: print(3) d = x - 2 * y print(2**58, (2**59 - 2**58 - d) // 2, (2**59 - 2**58 - d) // 2) elif ls[0] % 2 == 0: print(3) d = x - 2 * y print(2**58 + 1, (2**59 - 2**58 - d + 1) // 2, (2**59 - 2**58 - d + 1) // 2) else: print(3) d = x - 2 * y print(2**58 + 1, (2**59 - 2**58 - d - 3) // 2, (2**59 - 2**58 - d - 3) // 2) t -= 1
FUNC_DEF IF BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR BIN_OP NUMBER 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 IF BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER BIN_OP BIN_OP BIN_OP BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER NUMBER NUMBER BIN_OP BIN_OP BIN_OP BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER BIN_OP BIN_OP BIN_OP BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER VAR NUMBER NUMBER 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$.
import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ def solve(): n = int(input()) a = list(map(int, input().split())) sa = sum(a) xa = 0 for i in a: xa ^= i b0 = xa b1 = sa + xa print(2) print(b0, b1) t = int(input()) for i in range(t): solve()
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR 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 FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL 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$.
t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split())) k = sum(a) d = [0] * 40 for j in range(n): s = "" l = a[j] while l != 0: s += str(l % 2) l = l // 2 for u in range(len(s)): if s[u] == "1": d[u] += 1 p = 0 for j in range(40): d[j] = d[j] % 2 if d[j] == 1: p += 2**j k += p print(2) print(p, k)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR VAR VAR WHILE VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP NUMBER VAR VAR VAR EXPR FUNC_CALL VAR NUMBER 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 c in range(t): n = int(input()) s, xr = 0, 0 for i in input().split(): x = int(i) s += x xr ^= x if s == xr * 2: print(0) print() else: print(2) print(xr, s + xr)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER 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$.
from sys import stdin t = int(stdin.readline().strip()) for caso in range(t): n = int(stdin.readline().strip()) s = list(map(int, stdin.readline().strip().split())) y = s[0] xor = s[0] for i in range(1, n): xor = xor ^ s[i] y += s[i] ans = [] ans.append(xor) y += xor ans.append(y) print(2) print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER 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()) x = 2**57 for _ in range(T): input() a = list(map(int, input().split())) s = sum(a) o = 0 for i in a: o ^= i print(3) u = x ^ o z = x - (s + u) // 2 print(x ^ o, z, z)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER 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 FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP 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$.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) xor = 0 for i in a: xor ^= i s = sum(a) if xor * 2 == s: print(0) print() elif 2 * xor - s >= 0 and (2 * xor - s) % 2 == 0: print(2) print((2 * xor - s) // 2, (2 * xor - s) // 2) elif (2 * xor - s) % 2 == 1: print(3) xor ^= 2**55 - 1 s += 2**55 - 1 print(2**55 - 1, (2 * xor - s) // 2, (2 * xor - s) // 2) else: print(3) xor ^= 2**55 s += 2**55 print(2**55, (2 * xor - s) // 2, (2 * xor - s) // 2)
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 VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF BIN_OP BIN_OP NUMBER VAR VAR NUMBER 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 IF BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER 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 VAR BIN_OP NUMBER NUMBER VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER BIN_OP BIN_OP BIN_OP NUMBER 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$.
import itertools as it import sys t = int(input()) for _ in range(t): n = int(input()) s, x = 0, 0 for v in map(int, input().split()): s += v x ^= v print(2) print(x, s + x)
IMPORT 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 VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR 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$.
for _ in range(int(input())): N = int(input()) L = list(map(int, input().split())) XOR = 0 SUM = 0 for i in range(N): XOR = XOR ^ L[i] SUM = SUM + L[i] XOR = XOR * 2 if XOR == SUM: print("0") print("\n") else: XOR = XOR // 2 a = XOR b = SUM + XOR print("2") print(a, b)
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 VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP 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$.
import sys t = int(sys.stdin.readline().rstrip()) def main(): for _ in range(t): n = int(sys.stdin.readline().rstrip()) (*a,) = map(int, sys.stdin.readline().split()) s = 0 xor = 0 for i in range(n): s += a[i] xor ^= a[i] yield 2 yield "{0} {1}".format(xor, s + xor) ans = main() print(*ans, sep="\n")
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL 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 EXPR NUMBER EXPR FUNC_CALL STRING VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR 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$.
for _ in range(int(input())): n = int(input()) s = 0 x = 0 l = list(map(int, input().split())) for i in range(n): s += l[i] x = x ^ l[i] diff = 2 * x - s if s == 2 * x: print(0) else: 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR 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().strip()) for _ in range(T): n = int(input().strip()) l = list(map(int, input().strip().split())) s, x = 0, 0 for i in range(len(l)): s += l[i] x ^= l[i] print(2) print(x, s + x)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR 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$.
kl = int(input()) for l in range(kl): n = int(input()) sm = 0 smd = 0 for i in input().split(): i = int(i) sm += i smd = smd ^ i print(2) print(smd, sm + smd)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL 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$.
import sys def solution(a, n): s = sum(a) p = 1 while p <= s: p <<= 1 p <<= 1 if s & 1 == 1: p |= 1 xor = p for d in a: xor ^= d xor <<= 1 x = xor - s - p >> 1 return p, x, x def main(): case_num = int(input()) for k in range(case_num): n = int(input()) a = [int(i) for i in input().strip().split()] foo = solution(a, n) sys.stdout.write("%d\n" % len(foo)) sys.stdout.write("%s\n" % " ".join([str(i) for i in foo])) main()
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR FOR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER RETURN VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL STRING FUNC_CALL VAR VAR 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$.
for tc in range(int(input())): n = int(input()) ls = list(map(int, input().split())) xr = 0 sm = sum(ls) for e in ls: xr ^= e nadd = 2**50 + sm % 2 sm += nadd xr = 2 * (xr ^ nadd) rem = (xr - sm) // 2 print(3) print(nadd, rem, rem)
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 VAR FOR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP 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$.
import sys input = sys.stdin.readline def iin(): return int(input()) def lin(): return list(map(int, input().split())) def main(): t = iin() while t: t -= 1 n = iin() a = lin() ans = [] sm = sum(a) xsm = 0 for i in a: xsm ^= i if sm != 2 * xsm: if xsm != 0: ans.append(xsm) sm += xsm ans.append(sm) print(len(ans)) print(*ans) main()
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR BIN_OP NUMBER VAR IF VAR NUMBER 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 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 subsIns(): for _ in range(t): n = int(input()) (*a,) = [int(x) for x in input().split()] sum1 = sum(a) xor = 0 for ele in a: xor ^= ele if sum1 == 2 * xor: yield 0 yield "" elif xor == 0: yield 1 yield sum1 else: yield 2 yield str(xor) + " " + str(xor + sum1) t = int(input()) ans = subsIns() print(*ans, sep="\n")
FUNC_DEF 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 FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR BIN_OP NUMBER VAR EXPR NUMBER EXPR STRING IF VAR NUMBER EXPR NUMBER EXPR VAR EXPR NUMBER EXPR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR 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()) arr = [] for _ in range(t): n = int(input()) ar = list(map(int, input().strip().split())) sm, xor = 0, 0 for i in range(n): sm += ar[i] xor ^= ar[i] arr.append([sm, xor]) for i in range(t): if arr[i][0] == 2 * arr[i][1]: print(0, end="\n\n") elif arr[i][1] == 0: print(1) print(arr[i][0]) else: print(2) print(arr[i][1], arr[i][0] + arr[i][1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST 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 FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING IF VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER 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$.
t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split())) s = 2 xor = 0 summ = sum(a) for j in range(n): xor = xor ^ a[j] ans = [] ans.append(xor) ans.append(xor + summ) print(s) 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR 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 dtob(x): ans = "" while x > 0: ans = str(x % 2) + ans x = x // 2 return ans def xor(a, b): dif = abs(len(a) - len(b)) c = "" if len(a) < len(b): a = "0" * dif + a else: b = "0" * dif + b for i in range(len(a)): if a[i] != b[i]: c += "1" else: c += "0" return c def btod(x): x = int(x) ans = 0 counter = 0 while x > 0: ans += x % 10 * 2**counter x //= 10 counter += 1 return ans t = int(input()) for i in range(t): l = int(input()) nums = list(map(int, input().split())) bix = "0" for j in range(l): bix = xor(bix, dtob(nums[j])) dx = btod(bix) nums.append(dx) nums.append(sum(nums)) print(2) print(nums[-2], nums[-1])
FUNC_DEF ASSIGN VAR STRING WHILE VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR STRING VAR STRING RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR 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 STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER