description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You are given a weighted tree with $n$ vertices. Recall that a tree is a connected graph without any cycles. A weighted tree is a tree in which each edge has a certain weight. The tree is undirected, it doesn't have a root. Since trees bore you, you decided to challenge yourself and play a game on the given tree. In a move, you can travel from a node to one of its neighbors (another node it has a direct edge with). You start with a variable $x$ which is initially equal to $0$. When you pass through edge $i$, $x$ changes its value to $x ~\mathsf{XOR}~ w_i$ (where $w_i$ is the weight of the $i$-th edge). Your task is to go from vertex $a$ to vertex $b$, but you are allowed to enter node $b$ if and only if after traveling to it, the value of $x$ will become $0$. In other words, you can travel to node $b$ only by using an edge $i$ such that $x ~\mathsf{XOR}~ w_i = 0$. Once you enter node $b$ the game ends and you win. Additionally, you can teleport at most once at any point in time to any vertex except vertex $b$. You can teleport from any vertex, even from $a$. Answer with "YES" if you can reach vertex $b$ from $a$, and "NO" otherwise. Note that $\mathsf{XOR}$ represents the bitwise XOR operation . -----Input----- The first line contains a single integer $t$ ($1 \leq t \leq 1000$) β€” the number of test cases. The first line of each test case contains three integers $n$, $a$, and $b$ ($2 \leq n \leq 10^5$), ($1 \leq a, b \leq n; a \ne b$) β€” the number of vertices, and the starting and desired ending node respectively. Each of the next $n-1$ lines denotes an edge of the tree. Edge $i$ is denoted by three integers $u_i$, $v_i$ and $w_i$ β€” the labels of vertices it connects ($1 \leq u_i, v_i \leq n; u_i \ne v_i; 1 \leq w_i \leq 10^9$) and the weight of the respective edge. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case output "YES" if you can reach vertex $b$, and "NO" otherwise. -----Examples----- Input 3 5 1 4 1 3 1 2 3 2 4 3 3 3 5 1 2 1 2 1 2 2 6 2 3 1 2 1 2 3 1 3 4 1 4 5 3 5 6 5 Output YES NO YES -----Note----- For the first test case, we can travel from node $1$ to node $3$, $x$ changing from $0$ to $1$, then we travel from node $3$ to node $2$, $x$ becoming equal to $3$. Now, we can teleport to node $3$ and travel from node $3$ to node $4$, reaching node $b$, since $x$ became equal to $0$ in the end, so we should answer "YES". For the second test case, we have no moves, since we can't teleport to node $b$ and the only move we have is to travel to node $2$ which is impossible since $x$ wouldn't be equal to $0$ when reaching it, so we should answer "NO".
def solve(): n, a, b = tuple(map(int, input().split())) graph = [[] for _ in range(n + 1)] for _ in range(n - 1): u, v, w = tuple(map(int, input().split())) graph[u].append((v, w)) graph[v].append((u, w)) tfb = {} queue = [(b, 0)] visited = [False] * (n + 1) while len(queue) > 0: cur, w = queue.pop(0) visited[cur] = True for node, wn in graph[cur]: if not visited[node]: wn ^= w tfb[wn] = True queue.append((node, wn)) queue = [(a, 0)] visited = [False] * (n + 1) while len(queue) > 0: cur, w = queue.pop(0) if tfb.get(w) is not None: print("YES") return visited[cur] = True for node, wn in graph[cur]: if node == b and w ^ wn == 0: print("YES") return if node != b and not visited[node]: wn ^= w queue.append((node, wn)) print("NO") t = int(input()) for _ in range(t): solve()
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR LIST VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NONE EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given a weighted tree with $n$ vertices. Recall that a tree is a connected graph without any cycles. A weighted tree is a tree in which each edge has a certain weight. The tree is undirected, it doesn't have a root. Since trees bore you, you decided to challenge yourself and play a game on the given tree. In a move, you can travel from a node to one of its neighbors (another node it has a direct edge with). You start with a variable $x$ which is initially equal to $0$. When you pass through edge $i$, $x$ changes its value to $x ~\mathsf{XOR}~ w_i$ (where $w_i$ is the weight of the $i$-th edge). Your task is to go from vertex $a$ to vertex $b$, but you are allowed to enter node $b$ if and only if after traveling to it, the value of $x$ will become $0$. In other words, you can travel to node $b$ only by using an edge $i$ such that $x ~\mathsf{XOR}~ w_i = 0$. Once you enter node $b$ the game ends and you win. Additionally, you can teleport at most once at any point in time to any vertex except vertex $b$. You can teleport from any vertex, even from $a$. Answer with "YES" if you can reach vertex $b$ from $a$, and "NO" otherwise. Note that $\mathsf{XOR}$ represents the bitwise XOR operation . -----Input----- The first line contains a single integer $t$ ($1 \leq t \leq 1000$) β€” the number of test cases. The first line of each test case contains three integers $n$, $a$, and $b$ ($2 \leq n \leq 10^5$), ($1 \leq a, b \leq n; a \ne b$) β€” the number of vertices, and the starting and desired ending node respectively. Each of the next $n-1$ lines denotes an edge of the tree. Edge $i$ is denoted by three integers $u_i$, $v_i$ and $w_i$ β€” the labels of vertices it connects ($1 \leq u_i, v_i \leq n; u_i \ne v_i; 1 \leq w_i \leq 10^9$) and the weight of the respective edge. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case output "YES" if you can reach vertex $b$, and "NO" otherwise. -----Examples----- Input 3 5 1 4 1 3 1 2 3 2 4 3 3 3 5 1 2 1 2 1 2 2 6 2 3 1 2 1 2 3 1 3 4 1 4 5 3 5 6 5 Output YES NO YES -----Note----- For the first test case, we can travel from node $1$ to node $3$, $x$ changing from $0$ to $1$, then we travel from node $3$ to node $2$, $x$ becoming equal to $3$. Now, we can teleport to node $3$ and travel from node $3$ to node $4$, reaching node $b$, since $x$ became equal to $0$ in the end, so we should answer "YES". For the second test case, we have no moves, since we can't teleport to node $b$ and the only move we have is to travel to node $2$ which is impossible since $x$ wouldn't be equal to $0$ when reaching it, so we should answer "NO".
t = int(input()) for _ in range(t): def sol(): n, a, b = map(int, input().split()) a -= 1 b -= 1 edges = [[] for i in range(n)] for i in range(n - 1): v1, v2, w = map(int, input().split()) v1 -= 1 v2 -= 1 edges[v1].append((v2, w)) edges[v2].append((v1, w)) from_a = set([0]) from_b = set() visited = [(False) for _ in range(n)] hack = [False] def dfs(vc, ccur, from_arr): stack = [(vc, ccur)] while stack: v, cur = stack.pop() visited[v] = True for to, we in edges[v]: if not visited[to] and to == b and cur ^ we == 0: hack[0] = True if not visited[to] and to != b: from_arr.add(cur ^ we) stack.append((to, cur ^ we)) dfs(a, 0, from_a) if hack[0]: return "YES" visited = [(False) for _ in range(n)] dfs(b, 0, from_b) p = set(from_a).intersection(set(from_b)) if p: return "YES" else: return "NO" print(sol())
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER FUNC_DEF ASSIGN VAR LIST VAR VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR IF VAR NUMBER RETURN STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR RETURN STRING RETURN STRING EXPR FUNC_CALL VAR FUNC_CALL VAR
You are given a weighted tree with $n$ vertices. Recall that a tree is a connected graph without any cycles. A weighted tree is a tree in which each edge has a certain weight. The tree is undirected, it doesn't have a root. Since trees bore you, you decided to challenge yourself and play a game on the given tree. In a move, you can travel from a node to one of its neighbors (another node it has a direct edge with). You start with a variable $x$ which is initially equal to $0$. When you pass through edge $i$, $x$ changes its value to $x ~\mathsf{XOR}~ w_i$ (where $w_i$ is the weight of the $i$-th edge). Your task is to go from vertex $a$ to vertex $b$, but you are allowed to enter node $b$ if and only if after traveling to it, the value of $x$ will become $0$. In other words, you can travel to node $b$ only by using an edge $i$ such that $x ~\mathsf{XOR}~ w_i = 0$. Once you enter node $b$ the game ends and you win. Additionally, you can teleport at most once at any point in time to any vertex except vertex $b$. You can teleport from any vertex, even from $a$. Answer with "YES" if you can reach vertex $b$ from $a$, and "NO" otherwise. Note that $\mathsf{XOR}$ represents the bitwise XOR operation . -----Input----- The first line contains a single integer $t$ ($1 \leq t \leq 1000$) β€” the number of test cases. The first line of each test case contains three integers $n$, $a$, and $b$ ($2 \leq n \leq 10^5$), ($1 \leq a, b \leq n; a \ne b$) β€” the number of vertices, and the starting and desired ending node respectively. Each of the next $n-1$ lines denotes an edge of the tree. Edge $i$ is denoted by three integers $u_i$, $v_i$ and $w_i$ β€” the labels of vertices it connects ($1 \leq u_i, v_i \leq n; u_i \ne v_i; 1 \leq w_i \leq 10^9$) and the weight of the respective edge. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case output "YES" if you can reach vertex $b$, and "NO" otherwise. -----Examples----- Input 3 5 1 4 1 3 1 2 3 2 4 3 3 3 5 1 2 1 2 1 2 2 6 2 3 1 2 1 2 3 1 3 4 1 4 5 3 5 6 5 Output YES NO YES -----Note----- For the first test case, we can travel from node $1$ to node $3$, $x$ changing from $0$ to $1$, then we travel from node $3$ to node $2$, $x$ becoming equal to $3$. Now, we can teleport to node $3$ and travel from node $3$ to node $4$, reaching node $b$, since $x$ became equal to $0$ in the end, so we should answer "YES". For the second test case, we have no moves, since we can't teleport to node $b$ and the only move we have is to travel to node $2$ which is impossible since $x$ wouldn't be equal to $0$ when reaching it, so we should answer "NO".
t = int(input()) def dfs(graph, src, terminate=None): visited = set() xor = [(-1) for i in range(len(graph))] xor[src] = 0 stack = [src] visited.add(src) while stack: u = stack.pop() if u == terminate: continue for v, w in graph[u]: if v not in visited: if xor[v] ^ w == 0 or v != terminate: xor[v] = xor[u] ^ w visited.add(v) stack.append(v) return xor def solve(): n, a, b = map(int, input().split()) adj = [[] for i in range(n)] for i in range(n - 1): u, v, w = map(int, input().split()) adj[u - 1].append((v - 1, w)) adj[v - 1].append((u - 1, w)) x1 = dfs(adj, a - 1, terminate=b - 1) x2 = dfs(adj, b - 1) aa = set() for i, xx in enumerate(x1): if i == b - 1 and xx == 0: print("YES") return else: aa.add(xx) bb = set() for i, xx in enumerate(x2): if i != b - 1: bb.add(xx) for x in aa: if x in bb and x != -1: print("YES") return print("NO") for _ in range(t): solve()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF NONE ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST VAR EXPR FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR FOR VAR VAR VAR VAR IF VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
mod = 10**9 + 7 T = int(input()) for t in range(T): N = int(input()) A = [int(x) for x in input().split()] tot = 0 b = 0 for x in A: b |= x p = pow(2, N - 1, mod) while b: if b & 1: tot = (tot + p) % mod p = p * 2 % mod b >>= 1 print(tot)
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR WHILE VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
for _ in range(int(input())): M = int(input()) - 1 t = 0 for m in input().split(): t |= int(m) print((t << M) % 1000000007)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
T = int(input().strip()) for t in range(0, T): N = int(input().strip()) A = list(map(int, input().strip().split(" "))) B = [bin(a)[2:] for a in A] mx = max(A) ndx = A.index(mx) mxlen = len(B[ndx]) C = [("0" * (mxlen - len(b)) + b) for b in B] s = "" for i in range(0, mxlen): b = "0" for c in C: if c[i] == "1": b = "1" break s += b bwOR = int(s, 2) print(2 ** (N - 1) * bwOR % (10**9 + 7))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER 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 STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR STRING FOR VAR VAR IF VAR VAR STRING ASSIGN VAR STRING VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
import sys T = int(sys.stdin.readline()) for case in range(T): N = int(sys.stdin.readline()) OR = 0 for a in [int(X) for X in sys.stdin.readline().split()]: OR |= a print(2 ** (N - 1) * OR % 1000000007)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
for _ in range(int(input())): n = int(input()) a = [int(x) for x in input().split()] b = 0 for i in a: b |= i print(b * 2 ** (n - 1) % 1000000007)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
T = int(input()) for T_i in range(T): n = int(input()) s = [int(x) for x in input().split()] ans = 0 for i in range(0, 32): for c in s: c = bin(c)[2:].zfill(32) if c[-i - 1] == "1": ans += 2**i * 2 ** (n - 1) ans %= 1000000007 break 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 NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
t = int(input()) for i in range(t): n = int(input()) a = [int(number) for number in input().split()] a_or = a[0] for j in range(1, len(a)): a_or = a_or | a[j] print(2 ** (n - 1) * a_or % (10**9 + 7))
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 VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
T = int(input()) for t in range(T): n = int(input()) l = list(map(int, input().split())) OR = 0 for e in l: OR = OR | e ret = OR for i in range(n - 1): ret = ret * 2 % 1000000007 print(ret)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
t = int(input()) for loop in range(t): num = int(input()) elements = [] elements = [int(x) for x in input().strip().split(" ")] sum = elements[0] for x in elements[1:]: sum = sum | x sum = sum * 2 ** (num - 1) result = sum % (10**9 + 7) print(result)
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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
t = int(input()) for i in range(0, t): n = int(input()) OR = 0 temp = input() arr = temp.split(" ") for j in arr: OR = OR | int(j) print(OR * pow(2, n - 1, 1000000007) % 1000000007)
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 NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
M = 10**9 + 7 for t in range(int(input())): input() s = list(map(int, input().split())) a = 0 for i in range(32): if any(x & 1 << i for x in s): a = (a + pow(2, len(s) - 1, M) * (1 << i)) % M print(a)
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
T = int(input()) for t in range(T): n = int(input()) A = map(int, input().split()) multiplicand = 2 ** (n - 1) % (10**9 + 7) m = 0 for a in A: m = m | a m = m % (10**9 + 7) ans = multiplicand * m % (10**9 + 7) 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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
mod = int(1000000000.0) + 7 t = int(input()) for k in range(t): n = int(input()) a = [int(i) for i in input().split(" ")] sor = 0 for i in range(n): sor |= a[i] sor = (1 << n - 1) * sor % mod print(sor)
ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
T = int(input()) mod = 10**9 + 7 for _ in range(T): N = int(input()) a = [int(ns) for ns in str(input()).split()] ans = a[0] for i in range(1, N): ans = ans | a[i] print(ans * 2 ** (N - 1) % mod)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER 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 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 BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
t = int(input()) while t > 0: t -= 1 numbers = [] total = int(input()) numbers = input().split() numbers = [int(x) for x in numbers] ans = numbers[0] for i in numbers[1:]: ans = ans | i sum = ans * pow(2, total - 1) sum = sum % 1000000007 print(sum)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
M = 1000000007 tests = int(input().strip()) for i in range(0, tests): n = int(input().strip()) a = [int(x.strip()) for x in input().strip().split()] b0 = [(0) for y in range(0, 32)] b1 = [(0) for y in range(0, 32)] for k in range(0, n): for j in range(0, 32): if a[k] & 1 << j: tmp = b1[j] b1[j] = (b1[j] + 1 + b0[j]) % M b0[j] = (b0[j] + tmp) % M else: b1[j] = (b1[j] + b1[j]) % M b0[j] = (1 + b0[j] + b0[j]) % M cum = 0 for j in range(0, 32): val = (1 << j) * b1[j] % M cum = (cum + val) % M print(cum)
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER 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 NUMBER VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
md = 10**9 + 7 for _ in range(int(input())): N = int(input()) arr = list(map(int, input().split())) xsum = 0 for i in range(N): xsum |= arr[i] for _ in range(N - 1): xsum = xsum * 2 % md print(xsum)
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
import itertools no_cases = int(input()) results = [] for a0 in range(no_cases): list_size = int(input()) test_case = input().split() test_case = list(map(int, test_case)) result = 0 for a in test_case: result |= a results.append(result * pow(2, list_size - 1) % 1000000007) for a in results: print(a)
IMPORT 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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
t = int(input()) for _ in range(t): n = int(input()) arr = list(map(int, input().split())) xor_sum = 0 for i in range(n): xor_sum |= arr[i] pwr = 1 << n - 1 print(pwr * xor_sum % 1000000007)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
t = int(input()) for i in range(t): n = int(input()) arr = list(map(int, input().split())) total = 0 for a in arr: total |= a total *= pow(2, n - 1) total %= 1000000007 print(total)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
def solve(X): s = 0 for x in X: s |= x return s * 2 ** (len(X) - 1) % (10**9 + 7) T = int(input()) for _ in range(T): N = int(input()) X = [int(_) for _ in input().split()] print(solve(X))
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR RETURN BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
def my_bin(n): return str(bin(n))[2:] modulo = 10**9 + 7 for t in range(int(input())): n = int(input()) a = list(map(int, input().split())) bits = [] for e in a: b = reversed(my_bin(e)) for ind, bit in enumerate(b): if len(bits) <= ind: bits.append(int(bit)) else: bits[ind] = bits[ind] or int(bit) res = 0 for ind, bit in enumerate(bits): res += bit * 2 ** (ind + n - 1) res %= modulo print(res)
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
import _functools as ft import _operator as op bigprime = 1000000007 bbbits = lambda n: [(1 if d == "1" else 0) for d in bin(n)[2:][::-1]] def main(): tc = int(input()) for case in range(tc): n = int(input()) ex = list(map(int, input().split())) x = ft.reduce(op.or_, ex, 0) k = pow(2, n - 1, bigprime) print(sum(k * (1 << i) for i, d in enumerate(bbbits(x)) if d) % bigprime) main()
IMPORT IMPORT ASSIGN VAR NUMBER ASSIGN VAR VAR STRING NUMBER NUMBER VAR FUNC_CALL VAR VAR NUMBER NUMBER 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
X = 10**9 + 7 T = int(input()) for t in range(0, T): N = int(input()) var = input().split() arr = [] ored = 0 for i in range(0, N): arr.append(int(var[i])) ored |= arr[i] answer = ored * (1 << N - 1) % X print(answer)
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER 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 LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
T = int(input()) for _ in range(T): N = int(input()) A = list(map(int, input().split())) ans = 0 for b in map(lambda i: 1 << i, range(40)): has = any(map(lambda a: a & b, A)) if has: ans += b * 2 ** (N - 1) ans %= 1000000007 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 FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
mod = 1000000007 for _ in range(int(input())): N = int(input()) A = list(map(int, input().split())) ans = 0 for a in A: ans |= a ans %= mod ans = ans * ((1 << N - 1) % mod) % mod print(ans)
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
def func(): t = int(input()) for i in range(t): n = int(input()) arr = [int(x) for x in input().split()] orr = 0 for j in range(n): orr = orr | arr[j] res = orr * 2 ** (n - 1) % 1000000007 print(res) func()
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 VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
t = int(input()) for _ in range(t): input() nums = [int(num) for num in input().split()] orValue = 0 for value in nums: orValue |= value result = (1 << len(nums) - 1) * orValue moduleValue = pow(10, 9) + 7 print(result % moduleValue)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR 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 BIN_OP BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
numOfCase = int(input()) for noc in range(numOfCase): _l = int(input()) l = list(map(lambda s: int(s), input().split(" "))) res = pow(2, len(l) - 1) % 1000000007 tmp = 0 for n in l: tmp = tmp | n tmp = tmp % 1000000007 res = res * tmp % 1000000007 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
nc = int(input()) MOD = 1000000007 for ca in range(nc): n = int(input()) aList = [int(t) for t in input().split()] res = 0 for i in range(31): b = 1 << i popu = sum(1 for a in aList if a & b != 0) if popu: v = pow(2, i + n - 1, MOD) res = (res + v) % MOD print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER 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 FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
MOD = 1000000007 t = int(input()) for k in range(t): n = int(input()) a = list(map(int, input().split())) res = 0 for i in range(n): res = (res | a[i]) % MOD print(res * 2 ** (n - 1) % MOD)
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
for t in range(int(input())): n = int(input()) a = list(map(int, input().split())) x = 0 for i in a: x = x | i print(pow(2, n - 1, 10**9 + 7) * x % (10**9 + 7))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
t = int(input()) for i in range(t): n = int(input()) a = input().split() ans = 0 for j in range(n): ans = ans | int(a[j]) ans = ans * pow(2, n - 1, 1000000007) % 1000000007 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 FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
T = int(input()) for _ in range(T): input() A = [int(i) for i in input().split(" ")] sum = 0 for a in A: sum = (sum | a) % 1000000007 sum = sum * 2 ** (len(A) - 1) % 1000000007 print(sum)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
from itertools import * for _ in range(int(input())): n = int(input()) a = list(int(x) for x in input().strip().split(" ")) l = list() s = 0 for x in a: s = s | x print(s * 2 ** (n - 1) % (10**9 + 7))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
import itertools T = int(input()) for test in range(T): n = int(input()) S = {int(inp) for inp in input().strip().split(" ")} A = 0 for s in S: A |= s answer = 0 d = -1 while A: if A & 1: answer += pow(2, n + d, 1000000007) if answer > 1000000007: answer -= 1000000007 A >>= 1 d += 1 print(answer)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
for tests in range(int(input())): n = int(input()) a = [int(i) for i in input().split()] i = a[0] for j in a[1:]: i = i | j i = i * 2 ** (n - 1) print(i % (10**9 + 7))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
nth = lambda x, i: x >> i & 1 M = 10**9 + 7 for _ in range(int(input())): n = int(input()) l = [int(x) for x in input().split()] s = 0 for j in range(32): a, b = 0, 0 for x in reversed(l): if nth(x, j) == 1: a, b = a + b + 1, b + a else: a, b = 2 * a, 2 * b + 1 a %= M b %= M s = (s + (a << j) % M) % M print(s)
ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
MOD = 10**9 + 7 def xorSum(things): setS = list(things) result = 0 d = 0 n = len(setS) while 2**d < MOD: reducedBit = False for i in range(n): num = setS[i] reducedBit |= num % 2 == 1 setS[i] = setS[i] >> 1 result = (result + 2**d * 2 ** (n - 1) * reducedBit) % MOD d += 1 return result % MOD testLen = int(input()) inputs = [] for i in range(testLen): inputLen = int(input()) inputSet = [int(num) for num in input().split(" ")] inputs.append(inputSet) outputs = [xorSum(inputSet) for inputSet in inputs] for output in outputs: print(output)
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN BIN_OP VAR VAR 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 VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
import sys def poweroftwo(n): val = 1 yield val for i in range(n): val *= 2 yield val r = sys.stdin.readline text = r() t = int(text) for i in range(t): text = r() n = int(text) text = r() tmp = 0 for num in map(int, text.split()): tmp |= num for i in range(n - 1): tmp *= 2 if i % 20 == 0: tmp %= 1000000007 print(tmp % 1000000007)
IMPORT FUNC_DEF ASSIGN VAR NUMBER EXPR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
T = int(input()) for t in range(T): N = int(input()) a = [int(x) for x in input().split()] b = 0 for ia in a: b = b | ia b = bin(b)[:1:-1] s = 0 p = 2 ** (N - 1) for i in range(len(b)): if b[i] == "1": s = (s + p) % 1000000007 p *= 2 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 VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
def xor_sum(n, nums): mask = 0 for i in nums: mask = (mask | i) % (10**9 + 7) mask *= 2 ** (n - 1) return mask % (10**9 + 7) cases = [(int(input()), [int(i) for i in input().split()]) for j in range(int(input()))] for case in cases: print(xor_sum(case[0], case[1]))
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER RETURN BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
t = int(input()) for i in range(t): n = int(input()) a = [0] * 100000 h = 1 a = list(map(int, input().split())) sum = a[0] for j in range(1, n): h = h * 2 % 1000000007 sum = sum | a[j] b = sum * h % 1000000007 print(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 BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER 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 BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
import sys T = int(input().strip()) for _ in range(T): n = int(input().strip()) arr = [int(x) for x in input().strip().split()] temp = 0 for element in arr: temp |= element print(temp * 2 ** (n - 1) % (10**9 + 7))
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
def mod_pow(a, b, p): res = 1 cur = a while b: if b % 2: res = res * cur % p b //= 2 cur = cur * cur % p return res t = int(input()) mod = 10**9 + 7 pows = [] pow2 = 1 reverses = [] for i in range(100001): pows.append(pow2) pow2 *= 2 pow2 %= mod reverses.append(mod_pow(i, mod - 2, mod)) for tt in range(t): bits = [0] * 30 n = int(input()) a = list(map(int, input().split())) for x in a: for i, bit in enumerate(reversed(bin(x)[2:])): bits[i] += int(bit) result_bits = [] for bit in bits: count = 0 current_nCr = 1 for i in range(1, bit + 1): current_nCr = current_nCr * (bit + 1 - i) * reverses[i] % mod if i % 2 == 0: continue count += current_nCr % mod * pows[n - bit] % mod result_bits.append(count % mod) sum = 0 for i, bit in enumerate(result_bits): sum += bit * pows[i] sum %= mod print(sum % mod)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER 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 VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
Modulo = 10**9 + 7 T = int(input()) while T: T = T - 1 N = int(input()) ar = [int(i) for i in input().split()] SetOR = 0 for x in ar: SetOR = SetOR | x SetOR = SetOR % Modulo Power2 = pow(2, N - 1, Modulo) res = Power2 * SetOR % Modulo print(res)
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER 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 NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
MOD_VAL = 10**9 + 7 def work(inputs): for current_input in inputs: total_nums = len(current_input) res = [(0) for _ in range(32)] for num in current_input: for bit in range(32): if 1 << bit & num: res[bit] += 1 final_res = 0 for bit in range(32): if res[bit]: final_res = (final_res + 2 ** (total_nums - 1 + bit)) % MOD_VAL print(final_res) inputs = [] for _ in range(int(input())): cnt = int(input()) tmp = input().split() assert len(tmp) == cnt inputs.append([int(x) for x in tmp]) work(inputs)
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $\textbf{arr}$ known as $ar r'$. The set $ar r'$ can be expressed as: $\textit{Xor}\textit{Sum}(ar\textbf{r})=\sum\limits_{i=1}^{2^n-1}XOR(ar\textbf{r}_i^{\prime})=XOR(ar\textbf{r}_1^{\prime})+XOR(ar\textbf{r}_2^{\prime})+\cdots+XOR(ar\textbf{r}_{2^n-2}^{\prime})+XOB(ar\textbf{r}_{2^n-1}^{\prime})$ For example: Given set $arr=\{n_1,n_2,n_3\}$ The set of possible non-empty subsets is: $ar r'=\{\{n_1\},\{n_2\},\{n_3\},\{n_1,n_2\},\{n_1,n_3\},\{n_2,n_3\},\{n_1,n_2,n_3\}\}$ The $\textit{XorSum}$ of these non-empty subsets is then calculated as follows: $\textit{XorSum(arr)}$ = $n_1+n_2+n_3+(n_1\oplus n_2)+(n_1\oplus n_3)+(n_2\oplus n_3)+(n_1\oplus n_2\oplus n_3)$ Given a list of $n$ space-separated integers, determine and print $XorSum\%(10^9+7)$. For example, $arr=\{3,4\}$. There are three possible subsets, $ar r'=\{\{3\},\{4\},\{3,4\}\}$. The XOR of $ar r'[1]=3$, of $ar r'[2]=4$ and of $ar r[3]=3\oplus4=7$. The XorSum is the sum of these: $3+4+7=14$ and $14\%(10^9+7)=14$. Note: The cardinality of powerset$\left(n\right)$ is $2^{n}$, so the set of non-empty subsets of set $\textbf{arr}$ of size $n$ contains $2^n-1$ subsets. Function Description Complete the xoringNinja function in the editor below. It should return an integer that represents the XorSum of the input array, modulo $(10^9+7)$. xoringNinja has the following parameter(s): arr: an integer array Input Format The first line contains an integer $\mathbf{T}$, the number of test cases. Each test case consists of two lines: - The first line contains an integer $n$, the size of the set $\textbf{arr}$. - The second line contains $n$ space-separated integers $arr\left[i\right]$. Constraints $1\leq T\leq5$ $1\leq n\leq10^5$ $0\leq\textit{arr}[i]\leq10^9,\ 1\leq i\leq n$ Output Format For each test case, print its $XorSum\%(10^9+7)$ on a new line. The $i^{\mbox{th}}$ line should contain the output for the $i^{\mbox{th}}$ test case. Sample Input 0 1 3 1 2 3 Sample Output 0 12 Explanation 0 The input set, $S=\{1,2,3\}$, has $7$ possible non-empty subsets: $S'=\{\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}\}$. We then determine the $XOR$ of each subset in $S^{\prime}$: $XOR(\{1\})=1$ $XOR(\{2\})=2$ $XOR(\{3\})=3$ $XOR(\{1,2\})=1\oplus2=3$ $XOR(\{2,3\})=2\oplus3=1$ $XOR(\{1,3\}=1\oplus3=2$ $XOR(\text{{1,2,3}}=1\oplus2\oplus3=0$ Then sum the results of the $XOR$ of each individual subset in $S^{\prime}$, resulting in $\textit{XorSum}=12$ and $12\%(10^9+7)=12$. Sample Input 1 2 4 1 2 4 8 5 1 2 3 5 100 Sample Output 1 120 1648
def pow2mod(n, mod): result = 1 i = 2**15 while n >= 15: result = result * i % mod n -= 15 while n > 0: result = result * 2 % mod n -= 1 return result def solve(L): bitMask = 0 mod = 1000000007 for x in L: bitMask |= x a = pow2mod(len(L) - 1, mod) return a * bitMask % mod t = int(input()) for i in range(0, t): n = int(input()) L = [int(x) for x in input().split()] print(solve(L))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR RETURN BIN_OP BIN_OP VAR 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 VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
The Wingman gains the attention of a prospective partner for their friend, by tapping them on the shoulder, and then stating only the line "Haaaaave you met Ted?" (substituting the name of "Ted", the main protagonist of the show, with the name of the single person), and then walking away, leaving the newly acquainted pair to continue a conversation. Welcome to the world of 2030, where the process has undergone a technical twist. The people now contact only through systems that use unsigned 31-bit passkeys. The entire arrangement is rather simple, to be honest and the passkeys are just binary representations of unique ids attached to each system. So, as to establish a connection analogous to the random tap on the shoulder, you must join the two ids. This joining takes time equal to the hamming distance (Read the PS) between the passkeys. Find the minimum time in which any two systems can get connected. All the ids are stored in form of a set S. S is characterized by following properties: The xor operation is closed in the set, i.e. for any a,b belonging to S, their xor, c=a^b also belongs to S None of the numbers are repeated. Input Format: First line contains T, the number of test cases Each test case contains two lines. The first line has a single integer N. The second line contains N space separated integers representing the set S. Output Format: A single line for each test case containing the answer as explained in the statement. Constraints: 1 ≀ n ≀ 10^5 s[i] is an unsigned 31 bit integer. 1 ≀ T ≀ 3 Notes: 1. None of the numbers are repeated in the set S. 2. S does not contain 0. PS: http://en.wikipedia.org/wiki/Hamming_distance SAMPLE INPUT 2 3 1 2 3 7 1 2 3 4 5 6 7 SAMPLE OUTPUT 1 1 Explanation The set contains 3 numbers. S = {1, 2, 3} Now, 1 ^ 2= 3, exists in set 1 ^ 3 = 2, exists in set 2 ^ 3 = 1, exists in set Thus, the stated property holds. Now, the passkeys are as follows: - For system with id = 1 : passkey = 01 - For system with id = 2 : passkey = 10 - For system with id = 3 : passkey = 11 (Note that all passkeys have equal length i.e. 31 the prefix zeroes are not displayed for clarity) We consider all pairs, now... id = 1 and id = 2, hamming distance = 2 id = 1 and id = 3, hamming distance = 1 id = 3 and id = 2, hamming distance = 1 Thus, the required answer is 1.
t = int(input()) while t > 0: n = int(input()) arr = input().split() mind = 9999999999999999999999999999999999 for i in arr: ans = bin(int(i)).count("1") mind = min(ans, mind) print(mind) 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 FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
The Wingman gains the attention of a prospective partner for their friend, by tapping them on the shoulder, and then stating only the line "Haaaaave you met Ted?" (substituting the name of "Ted", the main protagonist of the show, with the name of the single person), and then walking away, leaving the newly acquainted pair to continue a conversation. Welcome to the world of 2030, where the process has undergone a technical twist. The people now contact only through systems that use unsigned 31-bit passkeys. The entire arrangement is rather simple, to be honest and the passkeys are just binary representations of unique ids attached to each system. So, as to establish a connection analogous to the random tap on the shoulder, you must join the two ids. This joining takes time equal to the hamming distance (Read the PS) between the passkeys. Find the minimum time in which any two systems can get connected. All the ids are stored in form of a set S. S is characterized by following properties: The xor operation is closed in the set, i.e. for any a,b belonging to S, their xor, c=a^b also belongs to S None of the numbers are repeated. Input Format: First line contains T, the number of test cases Each test case contains two lines. The first line has a single integer N. The second line contains N space separated integers representing the set S. Output Format: A single line for each test case containing the answer as explained in the statement. Constraints: 1 ≀ n ≀ 10^5 s[i] is an unsigned 31 bit integer. 1 ≀ T ≀ 3 Notes: 1. None of the numbers are repeated in the set S. 2. S does not contain 0. PS: http://en.wikipedia.org/wiki/Hamming_distance SAMPLE INPUT 2 3 1 2 3 7 1 2 3 4 5 6 7 SAMPLE OUTPUT 1 1 Explanation The set contains 3 numbers. S = {1, 2, 3} Now, 1 ^ 2= 3, exists in set 1 ^ 3 = 2, exists in set 2 ^ 3 = 1, exists in set Thus, the stated property holds. Now, the passkeys are as follows: - For system with id = 1 : passkey = 01 - For system with id = 2 : passkey = 10 - For system with id = 3 : passkey = 11 (Note that all passkeys have equal length i.e. 31 the prefix zeroes are not displayed for clarity) We consider all pairs, now... id = 1 and id = 2, hamming distance = 2 id = 1 and id = 3, hamming distance = 1 id = 3 and id = 2, hamming distance = 1 Thus, the required answer is 1.
def cnt(x): res = 0 while x: x = x & x - 1 res += 1 return res for _ in range(eval(input())): n = eval(input()) a = [cnt(x) for x in map(int, input().split())] print(min(a))
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
The Wingman gains the attention of a prospective partner for their friend, by tapping them on the shoulder, and then stating only the line "Haaaaave you met Ted?" (substituting the name of "Ted", the main protagonist of the show, with the name of the single person), and then walking away, leaving the newly acquainted pair to continue a conversation. Welcome to the world of 2030, where the process has undergone a technical twist. The people now contact only through systems that use unsigned 31-bit passkeys. The entire arrangement is rather simple, to be honest and the passkeys are just binary representations of unique ids attached to each system. So, as to establish a connection analogous to the random tap on the shoulder, you must join the two ids. This joining takes time equal to the hamming distance (Read the PS) between the passkeys. Find the minimum time in which any two systems can get connected. All the ids are stored in form of a set S. S is characterized by following properties: The xor operation is closed in the set, i.e. for any a,b belonging to S, their xor, c=a^b also belongs to S None of the numbers are repeated. Input Format: First line contains T, the number of test cases Each test case contains two lines. The first line has a single integer N. The second line contains N space separated integers representing the set S. Output Format: A single line for each test case containing the answer as explained in the statement. Constraints: 1 ≀ n ≀ 10^5 s[i] is an unsigned 31 bit integer. 1 ≀ T ≀ 3 Notes: 1. None of the numbers are repeated in the set S. 2. S does not contain 0. PS: http://en.wikipedia.org/wiki/Hamming_distance SAMPLE INPUT 2 3 1 2 3 7 1 2 3 4 5 6 7 SAMPLE OUTPUT 1 1 Explanation The set contains 3 numbers. S = {1, 2, 3} Now, 1 ^ 2= 3, exists in set 1 ^ 3 = 2, exists in set 2 ^ 3 = 1, exists in set Thus, the stated property holds. Now, the passkeys are as follows: - For system with id = 1 : passkey = 01 - For system with id = 2 : passkey = 10 - For system with id = 3 : passkey = 11 (Note that all passkeys have equal length i.e. 31 the prefix zeroes are not displayed for clarity) We consider all pairs, now... id = 1 and id = 2, hamming distance = 2 id = 1 and id = 3, hamming distance = 1 id = 3 and id = 2, hamming distance = 1 Thus, the required answer is 1.
def bit(c): count = 0 for i in range(32): if c & 1 != 0: count += 1 c = c >> 1 if c == 0: break return count t = eval(input()) for _ in range(t): ar = [] n = eval(input()) ar = list(map(int, input().split())) ans = 100 for i in ar: temp = bit(i) if ans > temp: ans = temp print(ans)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
The Wingman gains the attention of a prospective partner for their friend, by tapping them on the shoulder, and then stating only the line "Haaaaave you met Ted?" (substituting the name of "Ted", the main protagonist of the show, with the name of the single person), and then walking away, leaving the newly acquainted pair to continue a conversation. Welcome to the world of 2030, where the process has undergone a technical twist. The people now contact only through systems that use unsigned 31-bit passkeys. The entire arrangement is rather simple, to be honest and the passkeys are just binary representations of unique ids attached to each system. So, as to establish a connection analogous to the random tap on the shoulder, you must join the two ids. This joining takes time equal to the hamming distance (Read the PS) between the passkeys. Find the minimum time in which any two systems can get connected. All the ids are stored in form of a set S. S is characterized by following properties: The xor operation is closed in the set, i.e. for any a,b belonging to S, their xor, c=a^b also belongs to S None of the numbers are repeated. Input Format: First line contains T, the number of test cases Each test case contains two lines. The first line has a single integer N. The second line contains N space separated integers representing the set S. Output Format: A single line for each test case containing the answer as explained in the statement. Constraints: 1 ≀ n ≀ 10^5 s[i] is an unsigned 31 bit integer. 1 ≀ T ≀ 3 Notes: 1. None of the numbers are repeated in the set S. 2. S does not contain 0. PS: http://en.wikipedia.org/wiki/Hamming_distance SAMPLE INPUT 2 3 1 2 3 7 1 2 3 4 5 6 7 SAMPLE OUTPUT 1 1 Explanation The set contains 3 numbers. S = {1, 2, 3} Now, 1 ^ 2= 3, exists in set 1 ^ 3 = 2, exists in set 2 ^ 3 = 1, exists in set Thus, the stated property holds. Now, the passkeys are as follows: - For system with id = 1 : passkey = 01 - For system with id = 2 : passkey = 10 - For system with id = 3 : passkey = 11 (Note that all passkeys have equal length i.e. 31 the prefix zeroes are not displayed for clarity) We consider all pairs, now... id = 1 and id = 2, hamming distance = 2 id = 1 and id = 3, hamming distance = 1 id = 3 and id = 2, hamming distance = 1 Thus, the required answer is 1.
t = eval(input()) i = 0 while i < t: n = eval(input()) x = input().split(" ") k = 0 mini = 10000000 while k < n: ctr = 0 num = int(x[k]) while num != 0: if num % 2 == 1: ctr = ctr + 1 num = num / 2 if ctr <= mini: mini = ctr k = k + 1 print(mini) 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 FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
The Wingman gains the attention of a prospective partner for their friend, by tapping them on the shoulder, and then stating only the line "Haaaaave you met Ted?" (substituting the name of "Ted", the main protagonist of the show, with the name of the single person), and then walking away, leaving the newly acquainted pair to continue a conversation. Welcome to the world of 2030, where the process has undergone a technical twist. The people now contact only through systems that use unsigned 31-bit passkeys. The entire arrangement is rather simple, to be honest and the passkeys are just binary representations of unique ids attached to each system. So, as to establish a connection analogous to the random tap on the shoulder, you must join the two ids. This joining takes time equal to the hamming distance (Read the PS) between the passkeys. Find the minimum time in which any two systems can get connected. All the ids are stored in form of a set S. S is characterized by following properties: The xor operation is closed in the set, i.e. for any a,b belonging to S, their xor, c=a^b also belongs to S None of the numbers are repeated. Input Format: First line contains T, the number of test cases Each test case contains two lines. The first line has a single integer N. The second line contains N space separated integers representing the set S. Output Format: A single line for each test case containing the answer as explained in the statement. Constraints: 1 ≀ n ≀ 10^5 s[i] is an unsigned 31 bit integer. 1 ≀ T ≀ 3 Notes: 1. None of the numbers are repeated in the set S. 2. S does not contain 0. PS: http://en.wikipedia.org/wiki/Hamming_distance SAMPLE INPUT 2 3 1 2 3 7 1 2 3 4 5 6 7 SAMPLE OUTPUT 1 1 Explanation The set contains 3 numbers. S = {1, 2, 3} Now, 1 ^ 2= 3, exists in set 1 ^ 3 = 2, exists in set 2 ^ 3 = 1, exists in set Thus, the stated property holds. Now, the passkeys are as follows: - For system with id = 1 : passkey = 01 - For system with id = 2 : passkey = 10 - For system with id = 3 : passkey = 11 (Note that all passkeys have equal length i.e. 31 the prefix zeroes are not displayed for clarity) We consider all pairs, now... id = 1 and id = 2, hamming distance = 2 id = 1 and id = 3, hamming distance = 1 id = 3 and id = 2, hamming distance = 1 Thus, the required answer is 1.
import sys t = int(input()) for i in range(t): n = int(input()) s = list(map(int, input().strip().split(" "))) ans = sys.maxsize for i in range(n): temp = s[i] cnt = 0 while temp: temp = temp & temp - 1 cnt += 1 ans = min(ans, cnt) print(ans)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Chef's professor gave him homework to find a permutation of length 2^{N} such that each integer from 0 to 2^{N} - 1 appears exactly once in the permutation and the maximum [bitwise XOR] of any even length subarray is minimized. Chef wonders how many such permutations are there. Help Chef to find out the number of permutations modulo (10^{9} + 7), satisfying the above conditions and also help him find one such permutation. ------ Input Format ------ - First-line will contain T, the number of test cases. Then the test cases follow. - The only line of each test case contains an integer N. ------ Output Format ------ - For each test case, print two lines of output. - In the first line, print the number of permutations modulo (10^{9}+7), for which maximum bitwise xor of any even-length subarray is minimized. - In the next line, print 2^{N} space-separated numbers denoting any such permutation. ------ Constraints ------ $1 ≀ T ≀ 18$ $1 ≀ N ≀ 18$ - Sum of $2^{N}$ over all test cases does not exceed $10^{6}$ ----- Sample Input 1 ------ 2 1 2 ----- Sample Output 1 ------ 2 0 1 8 3 2 0 1 ----- explanation 1 ------ Test case $1$: There are two optimal permutations: $[0,1]$ and $[1,0]$. Test case $2$: The maximum xor value of any even-sized subarray will be $2$ and there are $8$ such permutations.
f = [] for i in range(0, 3 * 10**5): f.append(0) mod = 10**9 + 7 f[0] = 1 for i in range(1, 3 * 10**5): f[i] = i * f[i - 1] % mod t = int(input()) while t: t -= 1 n = int(input()) n = 1 << n if n == 2: print(2) else: print(4 * f[n // 2] % mod) for j in range(n // 2): if j & 1: print(j, j + n // 2, end=" ") else: print(j + n // 2, j, end=" ") print("\n")
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR STRING EXPR FUNC_CALL VAR STRING
Chef's professor gave him homework to find a permutation of length 2^{N} such that each integer from 0 to 2^{N} - 1 appears exactly once in the permutation and the maximum [bitwise XOR] of any even length subarray is minimized. Chef wonders how many such permutations are there. Help Chef to find out the number of permutations modulo (10^{9} + 7), satisfying the above conditions and also help him find one such permutation. ------ Input Format ------ - First-line will contain T, the number of test cases. Then the test cases follow. - The only line of each test case contains an integer N. ------ Output Format ------ - For each test case, print two lines of output. - In the first line, print the number of permutations modulo (10^{9}+7), for which maximum bitwise xor of any even-length subarray is minimized. - In the next line, print 2^{N} space-separated numbers denoting any such permutation. ------ Constraints ------ $1 ≀ T ≀ 18$ $1 ≀ N ≀ 18$ - Sum of $2^{N}$ over all test cases does not exceed $10^{6}$ ----- Sample Input 1 ------ 2 1 2 ----- Sample Output 1 ------ 2 0 1 8 3 2 0 1 ----- explanation 1 ------ Test case $1$: There are two optimal permutations: $[0,1]$ and $[1,0]$. Test case $2$: The maximum xor value of any even-sized subarray will be $2$ and there are $8$ such permutations.
mod = 10**9 + 7 for i in range(int(input())): n = int(input()) if n == 1: print(2) print(0, 1) else: n = 1 << n ans = 4 for i in range(1, int(n / 2) + 1): ans = ans * i % mod print(ans) print(0, end=" ") for i in range(1, int(n / 2)): if i & 1: print(i, n >> 1 ^ i, end=" ") else: print(n >> 1 ^ i, i, end=" ") print(n >> 1)
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
from sys import stdin, stdout def parity(n): return bin(n)[2:].count("1") % 2 t = int(stdin.readline()) for _ in range(t): x = [0, 0] s = set() n = int(stdin.readline()) for i in range(n): z = int(stdin.readline()) par = parity(z) if s == set(): x[par] += 1 s.add(z) elif z not in s: se = set() if par == 1: e, o = x x[1] += e x[0] += o else: e, o = x x[1] += o x[0] += e for j in s: se.add(j ^ z) s = s.union(se) s.add(z) x[par] += 1 print(x[0], x[1])
FUNC_DEF RETURN BIN_OP FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
def cnt_bits(x): result = 0 while x > 0: if x % 2 == 1: result += 1 x //= 2 return result t = int(input()) for i in range(t): l = set() q = int(input()) odd = 0 even = 0 for j in range(q): a = int(input()) if not a in l: new = set() for b in l: new.add(b ^ a) if cnt_bits(b ^ a) % 2 == 1: odd += 1 else: even += 1 l.add(a) if cnt_bits(a) % 2 == 1: odd += 1 else: even += 1 l |= new print(str(even) + " " + str(odd))
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
def bitcount(n): ans = 0 while n: ans += n & 1 n >>= 1 return ans for _ in range(int(input())): q = int(input()) a = {0} e, o = 0, 0 for i in range(q): x = int(input()) if x not in a: y = set() for j in a: y.add(j ^ x) if bitcount(j ^ x) & 1: o += 1 else: e += 1 a |= y print(e, o)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
def countSetBits(n): count = 0 while n: count += n & 1 n >>= 1 return count a = int(input()) while a != 0: b = int(input()) mylist = list() ev, od = 0, 0 for i in range(b): c = int(input()) fla = 0 for j in range(len(mylist)): if c == mylist[j]: print(ev, od) fla = 1 break if fla == 1: continue temp = list() for j in range(len(mylist)): if c != mylist[j]: mylist.append(c ^ mylist[j]) r = c ^ mylist[j] p = countSetBits(r) if p % 2 == 0: ev += 1 else: od += 1 mylist.append(c) p = countSetBits(mylist[len(mylist) - 1]) if p % 2 == 0: ev += 1 else: od += 1 print(ev, od) a -= 1
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
t = int(input()) for _ in range(t): q = int(input()) s = [] e, o = 0, 0 for __ in range(q): x = int(input()) d = [] if x not in s and x not in d: for i in s: xo = i ^ x if xo not in s and xo not in d: d.append(xo) if bin(xo).count("1") % 2 == 0: e += 1 else: o += 1 s.append(x) if bin(x).count("1") % 2 == 0: e += 1 else: o += 1 for i in d: s.append(i) print(e, o)
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 VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST IF VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL FUNC_CALL VAR VAR STRING NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL FUNC_CALL VAR VAR STRING NUMBER NUMBER VAR NUMBER VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
for h in range(int(input())): l = set() n = 0 od = 0 for i in range(int(input())): x = int(input()) if x in l: print(n, "", od) elif len(l) - 2 * n == 1: if x in l: print(n, "", od) else: for j in list(l): l.add(x ^ j) n = 2 * n + 1 od = 2 * od print(n, "", od) l.add(x) else: for j in list(l): l.add(x ^ j) if bin(x ^ j).count("1") % 2 == 0: n = n + 1 else: od += 1 l.add(x) if bin(x).count("1") % 2 == 0: n = n + 1 else: od += 1 print(n, "", od)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR STRING VAR IF BIN_OP FUNC_CALL VAR VAR BIN_OP NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR STRING VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR STRING VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP FUNC_CALL FUNC_CALL VAR BIN_OP VAR VAR STRING NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL FUNC_CALL VAR VAR STRING NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR STRING VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
def get_xor(a, b): return a ^ b def get_side(val): c = 0 while val: c += 1 val &= val - 1 if c % 2 == 0: return True else: return False for _ in range(int(input())): q = int(input()) check = {} l = [] e, o = 0, 0 for __ in range(q): x = int(input()) if check.get(x) == None: for j in range(len(l)): val = get_xor(x, l[j]) if not check.get(val): l.append(val) check[val] = 0 if get_side(val): e += 1 else: o += 1 if check.get(x) == None: l.append(x) check[x] = 0 if get_side(x): e += 1 else: o += 1 print(e, o)
FUNC_DEF RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NONE FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NONE EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
def countSetBits(n): count = 0 while n: count += n & 1 n >>= 1 return count a = int(input()) while a != 0: b = int(input()) mylist = list() for i in range(b): c = int(input()) ev, od = 0, 0 for j in range(len(mylist)): if c != mylist[j]: mylist.append(c ^ mylist[j]) mylist.append(c) mylist = list(set(mylist)) for j in range(len(mylist)): p = countSetBits(mylist[j]) if p % 2 == 0: ev += 1 else: od += 1 print(ev, od) a -= 1
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN 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 FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
t = int(input()) for i in range(t): var1 = list() q = int(input()) count1 = 0 count2 = 0 var2 = set() for j in range(q): x = int(input()) if x not in var2: l = len(var1) for m in range(l): n = var1[m] ^ x var2.add(n) var1.append(n) s2 = bin(n).count("1") if s2 % 2 == 0: count1 = count1 + 1 else: count2 = count2 + 1 var1.append(x) var2.add(x) s2 = bin(x).count("1") if s2 % 2 == 0: count1 = count1 + 1 else: count2 = count2 + 1 print(count1, count2)
ASSIGN VAR FUNC_CALL 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
def eo(n): cnt = 0 while n: n &= n - 1 cnt += 1 return cnt def xor(a, b): ans = a ^ b return ans for _ in range(int(input())): arr = [] even = 0 odd = 0 check = {} for _ in range(int(input())): x = int(input()) if check.get(x) == None: for i in range(len(arr)): y = xor(x, arr[i]) if check.get(y) == None: check[y] = 0 arr.append(y) j = eo(y) if j % 2 == 0: even += 1 else: odd += 1 if check.get(x) == None: check[x] = 0 arr.append(x) j = eo(x) if j % 2 == 0: even += 1 else: odd += 1 print(even, odd)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NONE FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
t = int(input()) for l in range(t): n = int(input()) seti = set() x = [] even = 0 odd = 0 while n != 0: a = int(input()) if a not in seti: seti.add(a) x.append(a) k = bin(a).count("1") if k % 2 == 0: even += 1 else: odd += 1 for i in range(len(x)): xor = a ^ x[i] if xor not in seti: seti.add(xor) x.append(xor) p = bin(xor).count("1") if p % 2 == 0: even += 1 else: odd += 1 print(even - 1, odd) n -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
def sb(num): c = bin(num).count("1") if c % 2 == 0: return True else: return False for _ in range(int(input())): s1 = {} l = [] od = 0 ev = 0 for _ in range(int(input())): e = int(input()) if s1.get(e) == None: for k in range(len(l)): v = l[k] ^ e if s1.get(v) == None: s1[v] = 0 l.append(v) if sb(v): ev = ev + 1 else: od = od + 1 if s1.get(e) == None: s1[e] = 0 l.append(e) if sb(e): ev = ev + 1 else: od = od + 1 print(ev, od)
FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NONE FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
def checkEvenParity(x): parity = 0 while x != 0: x = x & x - 1 parity += 1 if parity % 2 == 0: return True else: return False for _ in range(int(input())): q = int(input()) ans = 0 l = [] s = set() e = 0 o = 0 for i in range(q): x = int(input()) if x in s: print(e, o) continue else: ans = ans ^ x if ans in s: print(e, o) continue else: l.append(x) s.add(x) if checkEvenParity(x): e += 1 else: o += 1 l1 = len(l) for i in range(l1 - 1): temp = x ^ l[i] l.append(temp) s.add(temp) if checkEvenParity(temp): e += 1 else: o += 1 print(e, o)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
def bit(x): return bin(x).count("1") for _ in range(int(input())): q = int(input()) e, o = 0, 0 b = int(input()) lst = [] s = set() lst.append(b) s.add(b) if bit(b) % 2 == 0: e += 1 else: o += 1 print(e, o) for i in range(q - 1): x = int(input()) if x not in s: lst.append(x) s.add(x) if bit(x) % 2 == 0: e += 1 else: o += 1 length = len(lst) for idx in range(length - 1): a = x ^ lst[idx] lst.append(a) s.add(a) if bit(a) % 2 == 0: e += 1 else: o += 1 print(e, o)
FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
def cbs(num): binary = bin(num) setBits = [ones for ones in binary[2:] if ones == "1"] return len(setBits) t = int(input()) for _ in range(t): n = int(input()) s = set() e = 0 o = 0 for _ in range(n): a = int(input()) if a not in s: for i in list(s): g = a ^ i if g not in s: b = cbs(g) if b % 2: o += 1 elif b > 0: e += 1 s.add(g) b = cbs(a) if b % 2: o += 1 elif b > 0: e += 1 s.add(a) print(e, o)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR STRING RETURN 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
for _ in range(int(input())): s = set() s1 = set() n = int(input()) for i in range(n): e = int(input()) if e not in s: for j in s: s1.add(e ^ j) s.add(e) s = s.union(s1) even = 0 odd = 0 for j in s: c = bin(j).count("1") if c % 2 == 0: even = even + 1 else: odd = odd + 1 print(even, odd)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
def getParity(n): parity = 0 while n: parity = ~parity n = n & n - 1 return parity testCases = int(input()) for x in range(testCases): oddCount = 0 evenCount = 0 integers = [] check = {} lines = int(input()) for x in range(lines): newInt = int(input()) if check.get(newInt) == None: for y in integers: xorInt = newInt ^ y if check.get(xorInt) == None: integers.append(xorInt) check[xorInt] = 0 if getParity(xorInt) == 0: evenCount += 1 else: oddCount += 1 integers.append(newInt) check[newInt] = 0 if getParity(newInt) == 0: evenCount += 1 else: oddCount += 1 print(evenCount, oddCount) else: print(evenCount, oddCount)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NONE FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR NONE EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
P = [(0) for x in range(131072)] P[1] = 1 for k in range(2, 131072): if k % 2 == 0: P[k] = P[k // 2] else: P[k] = 1 - P[k - 1] for _ in range(int(input())): Q = int(input()) S = set() OC = 0 EC = 0 for k in range(Q): x = int(input()) if x not in S: l = list(S) S.add(x) if P[x] == 1: OC += 1 else: EC += 1 for Y in l: v = x ^ Y S.add(v) if P[v] == 1: OC += 1 else: EC += 1 print(EC, OC)
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
T = int(input()) for a in range(T): Q = int(input()) l2 = [] for _ in range(Q): even = 0 odd = 0 l3 = [] z = int(input()) if z not in l2: for w in l2: l3.append(w ^ z) l3.append(z) l2.extend(l3) for q in l2: x = str(bin(q)) if x.count("1") % 2 == 0: even += 1 else: odd += 1 print(even, end=" ") print(odd)
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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR STRING NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
for _ in range(int(input())): q = int(input()) s = set() odd = 0 even = 0 for a in range(q): x = int(input()) temp_list = [] if x not in s: c = int(bin(x).count("1")) if c & 1: odd = odd + 1 else: even = even + 1 for elem in s: t = elem ^ x if t in s: continue temp_list.append(t) c = int(bin(t).count("1")) if c & 1: odd = odd + 1 else: even = even + 1 s.add(x) for e in temp_list: s.add(e) print(even, odd)
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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST IF VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR STRING IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR STRING IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
def check(Num): s1 = 0 while Num: Num = Num & Num - 1 s1 += 1 return s1 for t in range(int(input())): s = set() even_ones = 0 odd_ones = 0 Q = int(input()) while Q: X = int(input()) if X in s: Q -= 1 print(even_ones, odd_ones) continue s1 = set() for elem in s: s1.add(elem ^ X) for elem in s1: s.add(elem) par = check(X) if par % 2: even_ones, odd_ones = (even_ones + odd_ones, odd_ones + even_ones + 1) else: even_ones, odd_ones = (even_ones + even_ones + 1, odd_ones + odd_ones) print(even_ones, odd_ones) Q -= 1 s.add(X)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
T = int(input()) for t in range(T): odd = 0 even = 0 q = int(input()) s = set() for i in range(q): x = int(input()) if not x in s: for j in s.copy(): s.add(x ^ j) if bin(x ^ j).count("1") % 2: odd += 1 else: even += 1 s.add(x) if bin(x).count("1") % 2: odd += 1 else: even += 1 print(str(even) + " " + str(odd))
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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP FUNC_CALL FUNC_CALL VAR BIN_OP VAR VAR STRING NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL FUNC_CALL VAR VAR STRING NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
def one(n): co = 0 while n: co += n & 1 n >>= 1 return co def xor(x, y): return (x | y) & (~x | ~y) for t in range(int(input())): q = int(input()) s = set() ev = od = 0 while q > 0: n = int(input()) if n not in s: co = one(n) if co % 2 == 0: ev += 1 else: od += 1 for i in list(s): new = xor(i, n) if new not in s: co = one(new) if co % 2 == 0: ev += 1 else: od += 1 s.add(new) s.add(n) print(ev, od) q -= 1
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR BIN_OP 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 ASSIGN VAR VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
def oddct(x): s = bin(x)[2:] if s.count("1") % 2 == 0: return False return True for t in range(int(input())): s = set() q = int(input()) e = 0 o = 0 for i in range(q): x = int(input()) if x not in s: s1 = set() for y in s: q = x ^ y s1.add(q) if oddct(q) == 1: o += 1 else: e += 1 s.add(x) s = s | s1 if oddct(x) == 1: o += 1 else: e += 1 else: pass print(e, o)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR STRING NUMBER NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
T = int(input()) for test_cases in range(0, T): Q = int(input()) S = set([]) even = 0 odd = 0 while Q > 0: X = int(input()) if X not in S: P = S.copy() for i in P: if i != X: S.add(i ^ X) S.add(X) P = S - P for _ in P: if bin(_).count("1") % 2 == 0: even = even + 1 else: odd = odd + 1 print("%d %d" % (even, odd)) Q = Q - 1
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 LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR VAR IF BIN_OP FUNC_CALL FUNC_CALL VAR VAR STRING NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
for _ in range(int(input())): arr = [] even = 0 odd = 0 check = {} for _ in range(int(input())): x = int(input()) if check.get(x) == None: for i in range(len(arr)): val = x ^ arr[i] if check.get(val) == None: check[val] = 0 arr.append(val) j = bin(val).count("1") if j % 2 == 0: even += 1 else: odd += 1 if check.get(x) == None: check[x] = 0 arr.append(x) j = bin(x).count("1") if j % 2 == 0: even += 1 else: odd += 1 print(even, odd)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NONE FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
def BitCount(n): if n == 0: return 0 else: return 1 + BitCount(n & n - 1) for _ in range(int(input())): s = set() e = o = 0 for t in range(int(input())): x = int(input()) s1 = set() if len(s) == 0: s.add(x) if BitCount(x) % 2 == 0: e += 1 else: o += 1 if x not in s: for v in s: if x != v: y = x ^ v if BitCount(y) % 2 == 0: e += 1 else: o += 1 s1.add(y) if BitCount(x) % 2 == 0: e += 1 else: o += 1 s.add(x) s = s | s1 print(e, o)
FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
def findParity(x): a = bin(x).count("1") return a % 2 for _ in range(int(input())): e = 0 o = 0 s = set() for xyz in range(int(input())): x = int(input()) if x not in s: n = set(s) for i in s: if i ^ x not in s: par = findParity(i ^ x) n.add(i ^ x) if par == 0: e += 1 else: o += 1 s = n par = findParity(x) if par == 0: e += 1 else: o += 1 s.add(x) print(e, o)
FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING RETURN BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
arr = [True] * 140000 for i in range(1, 140000): if bin(i).count("1") % 2 == 1: arr[i] = False t = int(input()) for _ in range(t): s = set() odd = 0 even = 0 q = int(input()) for _ in range(q): n = int(input()) a = set() if n not in s: s.add(n) if arr[n]: even, odd = even + 1 + even, odd + odd else: even, odd = even + odd, odd + even + 1 for i in s: if i != n: temp = i ^ n a.add(temp) s = s.union(a) print(even, odd)
ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP FUNC_CALL FUNC_CALL VAR VAR STRING NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
ijk = [] ik = {} uj = "Cp1" ugh = "Contest2" ugh = 90 t = int(input()) while t > 0: t -= 1 q = int(input()) x = set() e = 0 o = 0 ij = 0 while q > 0: q -= 1 k = int(input()) if k in x: print(e, o) continue y = list(x) ij += 10 for i in y: if i != k: x.add(i ^ k) x.add(k) pq = x.difference(set(y)) for i in pq: cnts = 0 while i: i = i & i - 1 cnts += 1 ij += 19 if cnts % 2 == 0: e += 1 else: o += 1 print(e, o) ij += 90
ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
for _ in range(int(input())): odd, even = 0, 0 M = [0] * 200077 M[0] = 1 q = int(input()) for _ in range(q): x = int(input()) if M[x] == 0: for i in range(0, 131072): if M[i] == 1 and M[i ^ x] == 0: M[i ^ x] = 1 cnt = bin(i ^ x).count("1") if cnt & 1: odd += 1 else: even += 1 print(even, odd)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR VAR STRING IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
def countSetBits(n): count = 0 while n: dig = n % 2 if dig: count += 1 n //= 2 return count for t in range(int(input())): s = set() e = o = 0 for q in range(int(input())): x = int(input()) if x in s: print(e, o) continue t = set() for y in s: val = x ^ y t.add(val) if countSetBits(val) % 2: o += 1 else: e += 1 for y in t: s.add(y) s.add(x) if countSetBits(x) % 2: o += 1 else: e += 1 print(e, o)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
import sys def fop(s): sys.stdout.write(str(s) + "\n") def fip(): return sys.stdin.readline() fintinp = lambda: int(fip()) def flistinp(func=int): return list(map(func, fip().split())) def fnsepline(n, func=str): return [func(fip()) for _ in range(n)] def even(x): x = bin(x).count("1") return x % 2 == 0 for _ in range(fintinp()): q = fintinp() o = e = 0 nums = set() for qn in range(q): qn = fintinp() if qn not in nums: if even(qn): e += 1 else: o += 1 for n in set(nums): x = n ^ qn if x not in nums: if even(x): e += 1 else: o += 1 nums.add(x) nums.add(qn) print(e, o)
IMPORT FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING RETURN BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
def check_even_parity(num): parity = 0 while num != 0: num = num & num - 1 parity = parity + 1 if parity % 2 == 0: return True else: return False t = int(input()) for i in range(t): q = int(input()) number_dict = {} evens = 0 odds = 0 calculated_elements = 0 number_set = [] for j in range(q): x = int(input()) if x not in number_dict: for number in number_set: xor_res = x ^ number if xor_res not in number_dict: if check_even_parity(xor_res): evens = evens + 1 else: odds = odds + 1 number_dict[xor_res] = 1 number_set.append(xor_res) if check_even_parity(x): evens = evens + 1 else: odds = odds + 1 number_dict[x] = 1 number_set.append(x) print(str(evens) + " " + str(odds))
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
for t in range(int(input())): s = set() even = odd = 0 for q in range(int(input())): x = int(input()) if x not in s: for val in list(s): xorVal = val ^ x if xorVal not in s: s.add(xorVal) numberOfBits = bin(xorVal).count("1") if numberOfBits % 2 == 0: even = even + 1 else: odd = odd + 1 numberOfBits = bin(x).count("1") if numberOfBits % 2 == 0: even = even + 1 else: odd = odd + 1 s.add(x) print(even, odd)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
import sys t = int(input()) def popcount(x): count = 0 while x: count += x & 1 x >>= 1 return count while t: q = int(input()) s = set() even, odd = 0, 0 while q: x = int(input()) if x not in s: tmp = list(s) for y in tmp: s.add(y ^ x) if popcount(y ^ x) % 2 == 0: even += 1 else: odd += 1 if popcount(x) % 2 == 0: even += 1 else: odd += 1 s.add(x) q -= 1 sys.stdout.write(str(even) + " " + str(odd) + "\n") t -= 1
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING VAR NUMBER
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
for _ in range(int(input())): q = int(input()) s = set() ex = set() e = 0 o = 0 for _ in range(q): x = int(input()) if x in s: print(e, " ", o) continue for j in s: if j != x: ex.add(x ^ j) s = s.union(ex) s.add(x) ex.clear() if e == 0 and o == 0: if str(bin(x)).count("1") % 2 == 1: o += 1 else: e += 1 print(e, " ", o) continue if str(bin(x)).count("1") % 2 == 0: o = o + o e = e + e e += 1 else: e1 = e + o o = o + e e = e1 o += 1 print(e, " ", o)
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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR STRING VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER IF BIN_OP FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR STRING NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR STRING VAR IF BIN_OP FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR STRING NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
def parity(n): b = str(bin(n)) p = b.count("1") if p % 2 != 0: return 0 else: return 1 for i1 in range(0, int(input())): q = int(input()) d = [] count = 0 way = 0 p = dict() for i in range(0, q): n = int(input()) p[n] = p.get(n, 0) + 1 if p[n] == 1: if parity(n) == 1: count = count + 1 else: way = way + 1 d.append(n) for j in d[:-1]: b = j ^ n d.append(b) p[b] = p.get(b, 0) + 1 if p[b] == 1: if parity(b) == 1: count = count + 1 else: way = way + 1 print(str(count) + " " + str(way))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
t = int(input()) def sb(num): s = bin(num) c = 0 for i in s: if i == "1": c = c + 1 if c % 2 == 0: return True else: return False while t > 0: t = t - 1 q = int(input()) s1 = {} l = [] od = 0 ev = 0 for i in range(0, q): e = int(input()) if s1.get(e) == None: for k in range(len(l)): if l[k] != e: v = l[k] ^ e if s1.get(v) == None: s1[v] = 0 l.append(v) if sb(v): ev = ev + 1 else: od = od + 1 if s1.get(e) == None: s1[e] = 0 l.append(e) if sb(e): ev = ev + 1 else: od = od + 1 print(ev, end=" ") print(od)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NONE FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
def bin(n): count = 0 while n: count += n & 1 n >>= 1 return count t = int(input()) for i in range(t): n = int(input()) e = 0 o = 0 dic = dict() for j in range(n): a = int(input()) lst = list() if j == 0: dic[a] = 1 m = bin(a) if m % 2 == 0: e += 1 else: o += 1 print(e, o) elif a not in dic and j > 0: for k in dic: lst.append(k ^ a) m = bin(k ^ a) if m % 2 == 0: e += 1 else: o += 1 for l in lst: dic[l] = 1 dic[a] = 1 m = bin(a) if m % 2 == 0: e += 1 else: o += 1 print(e, o) else: print(e, o)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
def count(n): cnt = 0 while n > 0: if 1 & n == 1: cnt += 1 n >>= 1 return cnt t = int(input()) for i in range(t): dict = {} q = int(input()) e = 0 o = 0 for i1 in range(q): x = int(input()) if i1 == 0: dict[x] = count(x) if dict[x] % 2 == 0: e += 1 else: o += 1 elif not x in dict.keys(): dict[x] = count(x) if dict[x] % 2 == 0: e += 1 else: o += 1 dict2 = {} for j in dict: if j != x and not j ^ x in dict.keys(): dict2[j ^ x] = count(j ^ x) if dict2[j ^ x] % 2 == 0: e += 1 else: o += 1 dict.update(dict2) print(e, o)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR VAR BIN_OP VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation). - Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively. Note that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $Q$. - Each of the next $Q$ lines contains a single integer $X$ describing a query. -----Output----- For each query, print a single line containing two space-separated integers $E$ and $O$. -----Constraints----- - $1 \le T \le 5$ - $1 \le Q, X \le 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le Q \le 1,000$ - $1 \le X \le 128$ Subtask #2 (70 points): original constraints -----Example Input----- 1 3 4 2 7 -----Example Output----- 0 1 1 2 3 4 -----Explanation----- Example case 1: - Initially, the set is empty: $S = \{\}$. - After the first query, $S = \{4\}$, so there is only one element with an odd number of $1$-s in the binary representation ("100"). - After the second query, $S = \{4,2,6\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is "110") and the other two elements have an odd number of $1$-s. - After the third query, $S = \{4,2,6,7,3,5,1\}$.
def binary_one_count(n): if n > 1: return n % 2 + binary_one_count(n // 2) return n t = int(input()) for _ in range(t): mylist = [0] * 100001 q = int(input()) even, odd, s = 0, 0, set() for _ in range(q): x = int(input()) if x not in s: for i in s.copy(): s.add(i ^ x) if binary_one_count(i ^ x) % 2 == 0: even += 1 else: odd += 1 s.add(x) if binary_one_count(x) % 2 == 0: even += 1 else: odd += 1 print(even, odd)
FUNC_DEF IF VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR