description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
"Humankind cannot gain anything without first giving something in return. To obtain, something of equal value must be lost. That is alchemy's first law of Equivalent Exchange. In those days, we really believed that to be the world's one, and only truth." -- Alphonse Elric Now, here we have an equivalent exchange law for triangles which states that two right-angled isosceles triangles of the same color can be made into a square of the same color using Alchemy. You are given N$N$ right-angled isosceles colored triangles numbered from 1$1$ to N$N$. For each triangle, the two equal sides have a length of 1$1$ unit. The Color of i$i$-th triangle is given by Ci$C_i$. To create a tower, we choose some consecutive (2×k)+1$2 \times k)+1$ triangles for any k≥0$k \geq 0$. We then pick some 2×k$2 \times k$ of them (these need not be consecutive), and form k$k$ pairs of triangles such that both triangles in pair have the same color. Also, each of the 2×k$2 \times k$ should be in exactly one pair. Then the two triangles in each pair are joined using Alchemy (following the law of equivalent exchange for triangles) to form squares and these k$k$ squares are placed one upon other. The one remaining triangle is placed as a roof to the tower. This results in a tower of the height of k$k$. Find the maximum height of the tower that can be formed. In other words, you should select the largest consecutive segment of triangles, such that you can form a tower using every single one of those triangles. In particular, you leave out one triangle, which will form the roof, and the other triangles should all be paired up such that both triangles in a pair have the same colour. -----Input:----- - The first line contains T$T$, the number of test cases. Then the test cases follow. - For every test case, the first line contains N$N$ denoting the number of triangles. - For every test case, the second line contains N$N$ space-separated integers Ci$C_{i}$ denoting the color of the triangles. ( 1≤i≤N$1 \leq i \leq N$). -----Output:----- For every test case, output a single integer denoting the maximum height of the tower that can be formed. -----Constraints----- - 1≤T≤100$1 \leq T \leq 100$ - 1≤N≤105$1 \leq N \leq 10^{5}$ - 1≤Ci≤30$1 \leq C_{i} \leq 30$ - Sum of N$N$ over all test cases doesn't exceed 5×105$5\times 10^{5}$ -----Sample Input:----- 4 14 5 4 2 2 3 2 1 3 2 7 4 9 9 9 3 1 2 1 3 1 1 1 5 1 2 3 4 1 -----Sample Output:----- 3 1 1 0 -----EXPLANATION:----- - #1$1$: The subarray [2,2,3,2,1,3,2]$[2, 2, 3, 2, 1, 3, 2]$ results in a tower of height 3$3$. - #2$2$: The subarray [1,2,1]$[ 1, 2, 1 ]$ results in a tower of height 1$1$. - #3$3$: The subarray [1,1,1]$[ 1, 1, 1 ]$ results in a tower of height 1$1$. - #4$4$: The subarrays [1]$[ 1 ]$, [2]$[ 2 ]$ , [3]$[ 3 ]$, [4]$[ 4 ]$ and [1]$[ 1 ]$ all results in a tower of height 0$0$. The above tower is possible by subarray [2,2,3,2,1,3,2]$[2, 2, 3, 2, 1, 3, 2]$ resulting in a height of 3$3$ in test case 1$1$.
for t in range(int(input())): n = int(input()) l = [(int(j) - 1) for j in input().split()] d = dict() st = 0 d[st] = -1 ans = 1 for i in range(n): st = st ^ 1 << l[i] for j in range(30): st1 = st st1 = st1 ^ 1 << j if st1 in d and d[st1] != i - 1: ans = max(ans, i - d[st1]) if st not in d: d[st] = i print(ans // 2)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
"Humankind cannot gain anything without first giving something in return. To obtain, something of equal value must be lost. That is alchemy's first law of Equivalent Exchange. In those days, we really believed that to be the world's one, and only truth." -- Alphonse Elric Now, here we have an equivalent exchange law for triangles which states that two right-angled isosceles triangles of the same color can be made into a square of the same color using Alchemy. You are given N$N$ right-angled isosceles colored triangles numbered from 1$1$ to N$N$. For each triangle, the two equal sides have a length of 1$1$ unit. The Color of i$i$-th triangle is given by Ci$C_i$. To create a tower, we choose some consecutive (2×k)+1$2 \times k)+1$ triangles for any k≥0$k \geq 0$. We then pick some 2×k$2 \times k$ of them (these need not be consecutive), and form k$k$ pairs of triangles such that both triangles in pair have the same color. Also, each of the 2×k$2 \times k$ should be in exactly one pair. Then the two triangles in each pair are joined using Alchemy (following the law of equivalent exchange for triangles) to form squares and these k$k$ squares are placed one upon other. The one remaining triangle is placed as a roof to the tower. This results in a tower of the height of k$k$. Find the maximum height of the tower that can be formed. In other words, you should select the largest consecutive segment of triangles, such that you can form a tower using every single one of those triangles. In particular, you leave out one triangle, which will form the roof, and the other triangles should all be paired up such that both triangles in a pair have the same colour. -----Input:----- - The first line contains T$T$, the number of test cases. Then the test cases follow. - For every test case, the first line contains N$N$ denoting the number of triangles. - For every test case, the second line contains N$N$ space-separated integers Ci$C_{i}$ denoting the color of the triangles. ( 1≤i≤N$1 \leq i \leq N$). -----Output:----- For every test case, output a single integer denoting the maximum height of the tower that can be formed. -----Constraints----- - 1≤T≤100$1 \leq T \leq 100$ - 1≤N≤105$1 \leq N \leq 10^{5}$ - 1≤Ci≤30$1 \leq C_{i} \leq 30$ - Sum of N$N$ over all test cases doesn't exceed 5×105$5\times 10^{5}$ -----Sample Input:----- 4 14 5 4 2 2 3 2 1 3 2 7 4 9 9 9 3 1 2 1 3 1 1 1 5 1 2 3 4 1 -----Sample Output:----- 3 1 1 0 -----EXPLANATION:----- - #1$1$: The subarray [2,2,3,2,1,3,2]$[2, 2, 3, 2, 1, 3, 2]$ results in a tower of height 3$3$. - #2$2$: The subarray [1,2,1]$[ 1, 2, 1 ]$ results in a tower of height 1$1$. - #3$3$: The subarray [1,1,1]$[ 1, 1, 1 ]$ results in a tower of height 1$1$. - #4$4$: The subarrays [1]$[ 1 ]$, [2]$[ 2 ]$ , [3]$[ 3 ]$, [4]$[ 4 ]$ and [1]$[ 1 ]$ all results in a tower of height 0$0$. The above tower is possible by subarray [2,2,3,2,1,3,2]$[2, 2, 3, 2, 1, 3, 2]$ resulting in a height of 3$3$ in test case 1$1$.
def answers(): answ, x = 0, 0 e = dict() e[x] = -1 for i in range(n): x ^= 1 << a[i] - 1 if x not in e.keys(): e[x] = i for j in range(30): answ = max(answ, i - e.get(x ^ 1 << j, i)) return answ // 2 for T in range(int(input())): n = int(input()) a = list(map(int, input().split())) print(answers())
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR NUMBER IF VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR VAR RETURN 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
"Humankind cannot gain anything without first giving something in return. To obtain, something of equal value must be lost. That is alchemy's first law of Equivalent Exchange. In those days, we really believed that to be the world's one, and only truth." -- Alphonse Elric Now, here we have an equivalent exchange law for triangles which states that two right-angled isosceles triangles of the same color can be made into a square of the same color using Alchemy. You are given N$N$ right-angled isosceles colored triangles numbered from 1$1$ to N$N$. For each triangle, the two equal sides have a length of 1$1$ unit. The Color of i$i$-th triangle is given by Ci$C_i$. To create a tower, we choose some consecutive (2×k)+1$2 \times k)+1$ triangles for any k≥0$k \geq 0$. We then pick some 2×k$2 \times k$ of them (these need not be consecutive), and form k$k$ pairs of triangles such that both triangles in pair have the same color. Also, each of the 2×k$2 \times k$ should be in exactly one pair. Then the two triangles in each pair are joined using Alchemy (following the law of equivalent exchange for triangles) to form squares and these k$k$ squares are placed one upon other. The one remaining triangle is placed as a roof to the tower. This results in a tower of the height of k$k$. Find the maximum height of the tower that can be formed. In other words, you should select the largest consecutive segment of triangles, such that you can form a tower using every single one of those triangles. In particular, you leave out one triangle, which will form the roof, and the other triangles should all be paired up such that both triangles in a pair have the same colour. -----Input:----- - The first line contains T$T$, the number of test cases. Then the test cases follow. - For every test case, the first line contains N$N$ denoting the number of triangles. - For every test case, the second line contains N$N$ space-separated integers Ci$C_{i}$ denoting the color of the triangles. ( 1≤i≤N$1 \leq i \leq N$). -----Output:----- For every test case, output a single integer denoting the maximum height of the tower that can be formed. -----Constraints----- - 1≤T≤100$1 \leq T \leq 100$ - 1≤N≤105$1 \leq N \leq 10^{5}$ - 1≤Ci≤30$1 \leq C_{i} \leq 30$ - Sum of N$N$ over all test cases doesn't exceed 5×105$5\times 10^{5}$ -----Sample Input:----- 4 14 5 4 2 2 3 2 1 3 2 7 4 9 9 9 3 1 2 1 3 1 1 1 5 1 2 3 4 1 -----Sample Output:----- 3 1 1 0 -----EXPLANATION:----- - #1$1$: The subarray [2,2,3,2,1,3,2]$[2, 2, 3, 2, 1, 3, 2]$ results in a tower of height 3$3$. - #2$2$: The subarray [1,2,1]$[ 1, 2, 1 ]$ results in a tower of height 1$1$. - #3$3$: The subarray [1,1,1]$[ 1, 1, 1 ]$ results in a tower of height 1$1$. - #4$4$: The subarrays [1]$[ 1 ]$, [2]$[ 2 ]$ , [3]$[ 3 ]$, [4]$[ 4 ]$ and [1]$[ 1 ]$ all results in a tower of height 0$0$. The above tower is possible by subarray [2,2,3,2,1,3,2]$[2, 2, 3, 2, 1, 3, 2]$ resulting in a height of 3$3$ in test case 1$1$.
for t in range(int(input())): n = int(input()) c = list(map(int, input().split())) dictionary = {(0): 0} parity = 0 k = 0 for i in range(n): parity ^= 1 << c[i] - 1 if parity not in dictionary: dictionary[parity] = i + 1 for j in range(30): x = parity ^ 1 << j if x in dictionary: k = max(k, i - dictionary[x]) print(k // 2)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
"Humankind cannot gain anything without first giving something in return. To obtain, something of equal value must be lost. That is alchemy's first law of Equivalent Exchange. In those days, we really believed that to be the world's one, and only truth." -- Alphonse Elric Now, here we have an equivalent exchange law for triangles which states that two right-angled isosceles triangles of the same color can be made into a square of the same color using Alchemy. You are given N$N$ right-angled isosceles colored triangles numbered from 1$1$ to N$N$. For each triangle, the two equal sides have a length of 1$1$ unit. The Color of i$i$-th triangle is given by Ci$C_i$. To create a tower, we choose some consecutive (2×k)+1$2 \times k)+1$ triangles for any k≥0$k \geq 0$. We then pick some 2×k$2 \times k$ of them (these need not be consecutive), and form k$k$ pairs of triangles such that both triangles in pair have the same color. Also, each of the 2×k$2 \times k$ should be in exactly one pair. Then the two triangles in each pair are joined using Alchemy (following the law of equivalent exchange for triangles) to form squares and these k$k$ squares are placed one upon other. The one remaining triangle is placed as a roof to the tower. This results in a tower of the height of k$k$. Find the maximum height of the tower that can be formed. In other words, you should select the largest consecutive segment of triangles, such that you can form a tower using every single one of those triangles. In particular, you leave out one triangle, which will form the roof, and the other triangles should all be paired up such that both triangles in a pair have the same colour. -----Input:----- - The first line contains T$T$, the number of test cases. Then the test cases follow. - For every test case, the first line contains N$N$ denoting the number of triangles. - For every test case, the second line contains N$N$ space-separated integers Ci$C_{i}$ denoting the color of the triangles. ( 1≤i≤N$1 \leq i \leq N$). -----Output:----- For every test case, output a single integer denoting the maximum height of the tower that can be formed. -----Constraints----- - 1≤T≤100$1 \leq T \leq 100$ - 1≤N≤105$1 \leq N \leq 10^{5}$ - 1≤Ci≤30$1 \leq C_{i} \leq 30$ - Sum of N$N$ over all test cases doesn't exceed 5×105$5\times 10^{5}$ -----Sample Input:----- 4 14 5 4 2 2 3 2 1 3 2 7 4 9 9 9 3 1 2 1 3 1 1 1 5 1 2 3 4 1 -----Sample Output:----- 3 1 1 0 -----EXPLANATION:----- - #1$1$: The subarray [2,2,3,2,1,3,2]$[2, 2, 3, 2, 1, 3, 2]$ results in a tower of height 3$3$. - #2$2$: The subarray [1,2,1]$[ 1, 2, 1 ]$ results in a tower of height 1$1$. - #3$3$: The subarray [1,1,1]$[ 1, 1, 1 ]$ results in a tower of height 1$1$. - #4$4$: The subarrays [1]$[ 1 ]$, [2]$[ 2 ]$ , [3]$[ 3 ]$, [4]$[ 4 ]$ and [1]$[ 1 ]$ all results in a tower of height 0$0$. The above tower is possible by subarray [2,2,3,2,1,3,2]$[2, 2, 3, 2, 1, 3, 2]$ resulting in a height of 3$3$ in test case 1$1$.
for _ in range(int(input())): input() cs = [(int(x) - 1) for x in input().split()] first = {(0): 0} last = {} v = 0 for i, c in enumerate(cs): v ^= 1 << c if v not in first: first[v] = i + 1 last[v] = i + 1 ans = max( last.get(v ^ 1 << c, 0) - i for c in range(max(cs) + 1) for v, i in first.items() ) assert ans % 2 == 1 print(ans // 2)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
def function(N): if N < 3: return -1 if N % 2 != 0: return " ".join([str(i) for i in range(1, N + 1)]) else: return " ".join(["2", "3", "1"] + [str(i) for i in range(4, N + 1)]) def main(): T = int(input()) for _ in range(T): N = int(input()) val = function(N) print(val) main()
FUNC_DEF IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER RETURN FUNC_CALL STRING BIN_OP LIST STRING STRING STRING FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR 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 VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
for i in range(int(input())): n = int(input()) if n == 2: print(-1) elif n % 2 != 0: for i in range(1, n + 1): print(i, end=" ") print() else: ll = [] co = [2, 3, 1, 4] if n <= 4: ll = co[:n] else: ll.extend(co) for j in range(5, n + 1): ll.append(j) for k in ll: print(k, end=" ") print()
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 IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
t = int(input()) while t != 0: n = int(input()) if n == 2: print(-1) t = t - 1 continue l = [] if n % 2 == 1: for i in range(1, n + 1): l.append(i) print(*l) else: x = 1 for i in range(0, n): l.append(x) x = x + 1 l[0] = 2 l[1] = 3 l[2] = 1 print(*l) t = t - 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
for i in range(int(input())): n = int(input()) if n == 2: print(-1) elif n & 1 == 1: print(*list(range(1, n + 1))) elif n & 1 == 0: print(2, 3, 1, end=" ") print(*list(range(4, n + 1)))
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 IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
for _ in range(int(input())): N = int(input()) if N == 2: print(-1) elif N % 2: print(*range(1, N + 1)) else: print(2, 3, 1, 4, *range(5, N + 1))
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 IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
for _ in range(int(input())): n = int(input()) if n == 2: print(-1) elif n % 2 == 1: q = [] for i in range(1, n + 1): q.append(i) print(*q) else: q = [] for i in range(1, n + 1): q.append(i) g = q.pop() q.insert(1, g) print(*q)
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 IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
from itertools import permutations x = int(input()) for y in range(x): def main(l, n): main_list = [] for k in range(n - 1): main_list.append(abs(l[k] - l[k + 1])) return xorOfArray(main_list, n) def xorOfArray(main_list, n): xor_arr = 0 for i in range(n - 1): xor_arr = xor_arr ^ main_list[i] return xor_arr n = int(input()) if n == 2: print(-1) else: perm = permutations(list(range(1, n + 1))) for a in perm: ans = main(a, n) if ans == 0: for j in a: print(j, end=" ") print() break else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
for _ in range(int(input())): n = int(input()) if n == 2: print(-1) elif n % 2 != 0: for i in range(1, n + 1): print(i, end=" ") else: l = [2, 3, 1, 4] for i in l: print(i, end=" ") for i in range(5, n + 1): print(i, end=" ") print()
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 IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
for tc in range(int(input())): n = int(input()) if n == 2: print(-1) elif n % 2 == 0: ans = [2, 3, 1, 4] for i in range(n - 4): ans.append(5 + i) print(*ans) else: print(*[i for i in range(1, n + 1)])
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 IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
for i in range(int(input())): x = int(input()) if x == 2: print(-1) elif x % 2 == 1: a = [i for i in range(x, 0, -1)] print(*a) else: b = [i for i in range(5, x + 1)] c = [2, 3, 1, 4] print(*c, end=" ") print(*b)
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 IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
t = input() for c in range(0, int(t)): n = int(input()) res = [] for i in range(n): res.append(i + 1) if n == 2: print(-1) elif n % 2 == 0: temp = res[-1] res[-1] = res[-3] res[-3] = temp temp = res[-1] res[-1] = res[-2] res[-2] = temp print(*res) else: print(*res)
ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
for _ in range(int(input())): n = int(input()) if n == 2: print(-1) else: if n % 2: print(*range(1, n + 1)) else: l = list(range(1, n + 1)) l.insert(1, l.pop()) print(*l) print()
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 IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
for _ in range(int(input())): n = int(input()) if n % 2 != 0: temp = list(range(n, 0, -1)) print(*temp) elif n == 2: print(-1) else: li = [2, 3, 1, 4] if n == 4: print(*li) else: li += range(5, n + 1) print(*li)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
t = int(input()) for i in range(t): n = int(input()) a = [] for j in range(n): a.append(j + 1) if n % 2 != 0: print(*a) elif n <= 2: print(-1) else: a[0] = 2 a[1] = 3 a[2] = 1 print(*a)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
def inparr(): tmparr = [int(i) for i in input().split()] return tmparr for _ in range(int(input())): N = int(input()) if N % 2: bstr = "1" for i in range(2, N + 1): bstr += f" {i}" print(bstr) elif N >= 4: bstr = "2 3 1 4" for i in range(5, N + 1): bstr += f" {i}" print(bstr) else: print(-1)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR STRING VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR STRING VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
T = int(input()) for i in range(T): n = int(input()) lst = [] if n == 2: print(-1) elif n % 2 != 0: for i in range(1, n + 1): lst.append(str(i)) else: lst.extend(["2", "3", "1", "4"]) for i in range(5, n + 1): lst.append(str(i)) print(" ".join(lst))
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 IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST STRING STRING STRING STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
tests = int(input()) for i in range(tests): n = int(input()) ans = [] if n == 2: ans = [-1] elif n & 1: ans = [i for i in range(n, 0, -1)] else: ans = [i for i in range(n, 4, -1)] ans.extend([4, 1, 3, 2]) 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 LIST IF VAR NUMBER ASSIGN VAR LIST NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
for i in range(int(input())): n = int(input()) list1 = [2, 3, 1] list2 = [3, 2, 1] if n == 2: print(-1) elif n == 3: for x in list2: print(x, end=" ") print("") elif n % 2 != 0: for x in range(1, n + 1): print(x, end=" ") print(" ") elif n > 3: for x in list1: print(x, end=" ") for x in range(4, n + 1): print(x, end=" ") print("")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
t = int(input()) for _ in range(t): n = int(input()) if n == 2: print(-1) elif n % 2 == 0: a = [2, 3, 1, 4] for i in range(5, n + 1): a.append(i) print(*a) else: a = [*range(1, n + 1)] print(*a)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
from itertools import permutations def xor(a, s): temp = abs(s[0] - s[1]) for i in range(1, a - 1): temp = temp ^ abs(s[i] - s[i + 1]) if temp == 0: return True return False for _ in range(int(input())): n = int(input()) if n % 2 != 0: print(*list(range(n, 0, -1))) else: flag = [-1] perm = permutations(list(range(1, n + 1))) for i in perm: if xor(n, i): flag = list(i) break print(*flag)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
for _ in range(int(input())): n = int(input()) if n % 2 != 0: print(" ".join([str(i) for i in range(1, n + 1)])) elif n == 2: print(-1) elif n == 4: print("1 4 2 3") else: li = [str(n - 1), str(n), str(n - 3), str(n - 2), str(n - 4)] + [ str(i) for i in range(n - 5, 0, -1) ] print(" ".join(li))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
for _ in range(int(input())): n = int(input()) if n % 2 == 1: for i in range(1, n + 1): print(i, end=" ") print() else: if n == 2: print(-1) continue for i in range(1, n - 2): print(i, end=" ") a = n b = n - 1 c = n - 2 print(n, n - 2, n - 1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
t = int(input()) for _ in range(t): n = int(input()) if n == 2: print(-1) elif n % 2: arr = [i for i in range(1, n + 1)] print(*arr) else: arr = [i for i in range(1, n + 1)] arr[0] = 2 arr[1] = 3 arr[2] = 1 print(*arr)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
for _ in range(int(input())): n = int(input()) if n <= 2: print(-1) continue else: if n % 2 != 0: for i in range(n, 0, -1): print(i, end=" ") else: print("2 3 1 4", end=" ") for i in range(1, n - 3): print(i + 4, end=" ") print()
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 IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
vojj = int(input()) for vishnesh in range(vojj): n = int(input()) if n % 2: for i in range(1, n + 1): print(i, end=" ") print() elif n == 2: print(-1) else: for i in range(1, n - 2): print(i, end=" ") print(n, end=" ") print(n - 2, end=" ") print(n - 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
for _ in range(int(input())): n = int(input()) if n == 2: print(-1) continue a = [(x + 1) for x in range(n)] if n & 1 == 0: a[0], a[1], a[2] = a[1], a[2], a[0] print(*a)
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 ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
t = int(input()) for i in range(0, t): lst = [] n = int(input()) if n == 2: print(-1) continue if n % 2 != 0: for k in range(n, 0, -1): lst.append(k) print(*lst, sep=" ") else: for j in range(1, n - 2): lst.append(j) lst.append(n) lst.append(n - 2) lst.append(n - 1) print(*lst, sep=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
p = int(input()) for i in range(p): n = int(input()) if n == 2: print("-1") elif n == 4: print("2 3 1 4") elif n % 2 != 0: l = [] for i in range(1, n + 1): l.append(i) print(*l) elif n % 2 == 0: l = [2, 3, 1, 4] for i in range(5, n + 1): l.append(i) print(*l)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
for _ in range(int(input())): n = int(input()) if n == 2: print(-1) elif n % 2 == 1: a = list(range(1, n + 1)) print(*a) continue elif n == 4: a = [2, 3, 1, 4] print(*a) continue else: a = [2, 3, 1, 4] b = list(range(5, n + 1)) a.extend(b) print(*a)
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 IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
for _ in range(int(input())): n = int(input()) if n == 2: print(-1) elif n % 2: print(*[c for c in range(1, n + 1)]) else: ans = [c for c in range(1, n + 1)] temp = ans[-3:] temp1 = [temp[2], temp[0], temp[1]] print(*list(ans[:-3] + temp1))
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 IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
n = int(input()) a = [] for i in range(n): l = int(input()) a.append(l) for i in a: if i == 2: print(-1) elif i % 2: print(*list(range(1, i + 1))) else: n = [(i - j) for j in range(i)] res = n[:-4] + [4, 1, 3, 2] print(*res)
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 EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER LIST NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
sl = int(input()) while sl: sl -= 1 n = int(input()) if n == 2: print(-1) elif n == 4: print(4, 1, 3, 2) elif n % 2 == 1: for i in range(n): print(i + 1, end=" ") print() else: for i in range(n - 4): print(n - i, end=" ") print(4, 1, 3, 2)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
for _ in range(int(input())): n = int(input()) if n == 2: print(-1) else: if n % 2: print(*range(1, n + 1)) elif n % 4 == 0: a = range(1, n // 2 + 1) b = range(n, n // 2, -1) for i in range(n): if i % 2: print(a[i // 2], end=" ") else: print(b[i // 2], end=" ") else: for i in range(n): if i == 0: print(1, end=" ") elif i == 1: print(n, end=" ") else: print(i, end=" ") print()
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 IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
n = int(input()) while n: n -= 1 N = int(input()) if N == 2 or N == 1 or N == 0: print(-1) elif N % 2: l = [int(x) for x in range(1, N + 1)] print(*l) else: ans = list(range(N, 3, -1)) + [1, 3, 2] print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER LIST NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
for _ in range(int(input())): n = int(input()) result = [2, 3, 1, 4] if n == 2: print(-1) elif n % 2 == 1: print(*[i for i in range(1, n + 1)]) else: for i in range(5, n + 1): result.append(i) print(*result)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
testcases = int(input()) for i in range(testcases): n = int(input()) if n % 2 == 1: for i in range(n, 0, -1): print(i, end=" ") print() else: if n == 2: print(-1) continue for i in range(n, 3, -1): print(i, end=" ") print("1 3 2")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING
You are given an integer N. Construct a permutation A of length N which is attractive. A permutation is called attractive if the [bitwise XOR] of all absolute differences of adjacent pairs of elements is equal to 0. Formally, a permutation A = [A_{1}, A_{2}, \ldots, A_{N}] of length N is said to be attractive if: |A_{1}-A_{2}| \oplus |A_{2}-A_{3}| \oplus \ldots \oplus |A_{N-1} - A_{N}| = 0 where \oplus denotes the bitwise XOR operation. Output any attractive permutation of length N. If no attractive permutation exists, print -1 instead. Note: A permutation of length N is an array A = [A_{1}, A_{2}, \ldots, A_{N}] such that every integer from 1 to N occurs exactly once in A. For example, [1, 2, 3] and [2, 3, 1] are permutations of length 3, but [1, 2, 1], [4, 1, 2], and [2, 3, 1, 4] are not. ------ Input Format ------ - The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows. - Each test case consists of a single line of input, containing one integer N. ------ Output Format ------ For each test case, output on a single line an attractive permutation of N integers, or -1 if no attractive permutation exists. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ - Sum of $N$ over all cases won't exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 3 6 ----- Sample Output 1 ------ 3 2 1 5 2 3 6 4 1 ----- explanation 1 ------ Test Case $1$: $ |3-2| \oplus |2-1| = 1 \oplus 1 = 0$ Note that there are other correct answers — for example, $[1, 2, 3]$ would also be accepted as correct. Test Case $2$: $ |5-2| \oplus |2-3| \oplus |3-6| \oplus |6-4| \oplus |4-1| = 3 \oplus 1 \oplus 3 \oplus 2 \oplus 3 = 0$
for _ in range(int(input())): m = int(input()) if m == 2: print(-1) else: ans = [*range(1, m + 1)] if m % 2 == 0: ans[m - 1], ans[m - 2], ans[m - 3] = m - 1, m - 2, m print(*ans)
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 ASSIGN VAR LIST FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Raj is a math pro and number theory expert. One day, he met his age-old friend Chef. Chef claimed to be better at number theory than Raj, so Raj gave him some fuzzy problems to solve. In one of those problems, he gave Chef a 3$3$-tuple of non-negative integers (a0,b0,c0)$(a_0, b_0, c_0)$ and told Chef to convert it to another tuple (x,y,z)$(x, y, z)$. Chef may perform the following operations any number of times (including zero) on his current tuple (a,b,c)$(a, b, c)$, in any order: - Choose one element of this tuple, i.e. a$a$, b$b$ or c$c$. Either add 1$1$ to that element or subtract 1$1$ from it. The cost of this operation is 1$1$. - Merge: Change the tuple to (a−1,b−1,c+1)$(a-1, b-1, c+1)$, (a−1,b+1,c−1)$(a-1, b+1, c-1)$ or (a+1,b−1,c−1)$(a+1, b-1, c-1)$, i.e. add 1$1$ to one element and subtract 1$1$ from the other two. The cost of this operation is 0$0$. - Split: Change the tuple to (a−1,b+1,c+1)$(a-1, b+1, c+1)$, (a+1,b−1,c+1)$(a+1, b-1, c+1)$ or (a+1,b+1,c−1)$(a+1, b+1, c-1)$, i.e. subtract 1$1$ from one element and add 1$1$ to the other two. The cost of this operation is also 0$0$. After each operation, all elements of Chef's tuple must be non-negative. It is not allowed to perform an operation that would make one or more elements of this tuple negative. Can you help Chef find the minimum cost of converting the tuple (a0,b0,c0)$(a_0, b_0, c_0)$ to the tuple (x,y,z)$(x, y, z)$? It can be easily proved that it is always possible to convert any tuple of non-negative integers to any other. -----Input----- - The first line of the input contains a single integer T$T$ denoting the number of test cases. The description of T$T$ test cases follows. - The first and only line of each test case contains six space-separated integers a0$a_0$, b0$b_0$, c0$c_0$, x$x$, y$y$ and z$z$. -----Output----- For each test case, print a single line containing one integer ― the minimum cost. -----Constraints----- - 1≤T≤105$1 \le T \le 10^5$ - 0≤a0,b0,c0,x,y,z≤1018$0 \le a_0, b_0, c_0, x, y, z \le 10^{18}$ -----Subtasks----- Subtask #1 (20 points): 0≤a0,b0,c0,x,y,z≤100$0 \le a_0, b_0, c_0, x, y, z \le 100$ Subtask #2 (80 points): original constraints -----Example Input----- 2 1 1 1 2 2 2 1 2 3 2 4 2 -----Example Output----- 0 1 -----Explanation----- Example case 1: The tuple (1,1,1)$(1, 1, 1)$ can be converted to (2,2,2)$(2, 2, 2)$ using only three Split operations, with cost 0$0$: (1,1,1)→(2,0,2)→(1,1,3)→(2,2,2)$(1, 1, 1) \rightarrow (2, 0, 2) \rightarrow (1, 1, 3) \rightarrow (2, 2, 2)$. Example case 2: We can use one addition operation and one Split operation: (1,2,3)→(1,3,3)→(2,4,2)$(1, 2, 3) \rightarrow (1, 3, 3) \rightarrow (2, 4, 2)$.
t = int(input()) for _ in range(t): arr1 = [int(i) for i in input().split()] a, b, c = arr1[:3] x, y, z = arr1[3:] ans = 0 if arr1[:3] == arr1[3:]: print(0) elif (a == 0 and b == 0 and c == 0) and (x == 0 and y == 0 and z == 0): print(0) else: ans = 0 a1 = a % 2 b1 = b % 2 c1 = c % 2 x1 = x % 2 y1 = y % 2 z1 = z % 2 a2 = (x - a) % 2 b2 = (y - b) % 2 c2 = (z - c) % 2 if a == 0 and b == 0 and c == 0: if x1 + y1 + z1 == 1 or x1 + y1 + z1 == 2: ans = 1 else: ans = 2 elif x == 0 and y == 0 and z == 0: if a1 + b1 + c1 == 1 or a1 + b1 + c1 == 2: ans = 1 else: ans = 2 elif a2 != b2 or b2 != c2: ans = 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Raj is a math pro and number theory expert. One day, he met his age-old friend Chef. Chef claimed to be better at number theory than Raj, so Raj gave him some fuzzy problems to solve. In one of those problems, he gave Chef a 3$3$-tuple of non-negative integers (a0,b0,c0)$(a_0, b_0, c_0)$ and told Chef to convert it to another tuple (x,y,z)$(x, y, z)$. Chef may perform the following operations any number of times (including zero) on his current tuple (a,b,c)$(a, b, c)$, in any order: - Choose one element of this tuple, i.e. a$a$, b$b$ or c$c$. Either add 1$1$ to that element or subtract 1$1$ from it. The cost of this operation is 1$1$. - Merge: Change the tuple to (a−1,b−1,c+1)$(a-1, b-1, c+1)$, (a−1,b+1,c−1)$(a-1, b+1, c-1)$ or (a+1,b−1,c−1)$(a+1, b-1, c-1)$, i.e. add 1$1$ to one element and subtract 1$1$ from the other two. The cost of this operation is 0$0$. - Split: Change the tuple to (a−1,b+1,c+1)$(a-1, b+1, c+1)$, (a+1,b−1,c+1)$(a+1, b-1, c+1)$ or (a+1,b+1,c−1)$(a+1, b+1, c-1)$, i.e. subtract 1$1$ from one element and add 1$1$ to the other two. The cost of this operation is also 0$0$. After each operation, all elements of Chef's tuple must be non-negative. It is not allowed to perform an operation that would make one or more elements of this tuple negative. Can you help Chef find the minimum cost of converting the tuple (a0,b0,c0)$(a_0, b_0, c_0)$ to the tuple (x,y,z)$(x, y, z)$? It can be easily proved that it is always possible to convert any tuple of non-negative integers to any other. -----Input----- - The first line of the input contains a single integer T$T$ denoting the number of test cases. The description of T$T$ test cases follows. - The first and only line of each test case contains six space-separated integers a0$a_0$, b0$b_0$, c0$c_0$, x$x$, y$y$ and z$z$. -----Output----- For each test case, print a single line containing one integer ― the minimum cost. -----Constraints----- - 1≤T≤105$1 \le T \le 10^5$ - 0≤a0,b0,c0,x,y,z≤1018$0 \le a_0, b_0, c_0, x, y, z \le 10^{18}$ -----Subtasks----- Subtask #1 (20 points): 0≤a0,b0,c0,x,y,z≤100$0 \le a_0, b_0, c_0, x, y, z \le 100$ Subtask #2 (80 points): original constraints -----Example Input----- 2 1 1 1 2 2 2 1 2 3 2 4 2 -----Example Output----- 0 1 -----Explanation----- Example case 1: The tuple (1,1,1)$(1, 1, 1)$ can be converted to (2,2,2)$(2, 2, 2)$ using only three Split operations, with cost 0$0$: (1,1,1)→(2,0,2)→(1,1,3)→(2,2,2)$(1, 1, 1) \rightarrow (2, 0, 2) \rightarrow (1, 1, 3) \rightarrow (2, 2, 2)$. Example case 2: We can use one addition operation and one Split operation: (1,2,3)→(1,3,3)→(2,4,2)$(1, 2, 3) \rightarrow (1, 3, 3) \rightarrow (2, 4, 2)$.
for _ in range(int(input())): a, b, c, x, y, z = map(int, input().split()) if a == 0 and b == 0 and c == 0 and x == 0 and y == 0 and z == 0: print(0) continue ans = 0 if a == 0 and b == 0 and c == 0: st = set((abs(x - a) % 2, abs(y - b) % 2, abs(z - c) % 2)) if st == {0, 1}: ans = 1 else: ans = 2 elif x == 0 and y == 0 and z == 0: st = set((abs(x - a) % 2, abs(y - b) % 2, abs(z - c) % 2)) if st == {0, 1}: ans = 1 else: ans = 2 else: st = set((abs(x - a) % 2, abs(y - b) % 2, abs(z - c) % 2)) if st == {0, 1}: ans = 1 print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Raj is a math pro and number theory expert. One day, he met his age-old friend Chef. Chef claimed to be better at number theory than Raj, so Raj gave him some fuzzy problems to solve. In one of those problems, he gave Chef a 3$3$-tuple of non-negative integers (a0,b0,c0)$(a_0, b_0, c_0)$ and told Chef to convert it to another tuple (x,y,z)$(x, y, z)$. Chef may perform the following operations any number of times (including zero) on his current tuple (a,b,c)$(a, b, c)$, in any order: - Choose one element of this tuple, i.e. a$a$, b$b$ or c$c$. Either add 1$1$ to that element or subtract 1$1$ from it. The cost of this operation is 1$1$. - Merge: Change the tuple to (a−1,b−1,c+1)$(a-1, b-1, c+1)$, (a−1,b+1,c−1)$(a-1, b+1, c-1)$ or (a+1,b−1,c−1)$(a+1, b-1, c-1)$, i.e. add 1$1$ to one element and subtract 1$1$ from the other two. The cost of this operation is 0$0$. - Split: Change the tuple to (a−1,b+1,c+1)$(a-1, b+1, c+1)$, (a+1,b−1,c+1)$(a+1, b-1, c+1)$ or (a+1,b+1,c−1)$(a+1, b+1, c-1)$, i.e. subtract 1$1$ from one element and add 1$1$ to the other two. The cost of this operation is also 0$0$. After each operation, all elements of Chef's tuple must be non-negative. It is not allowed to perform an operation that would make one or more elements of this tuple negative. Can you help Chef find the minimum cost of converting the tuple (a0,b0,c0)$(a_0, b_0, c_0)$ to the tuple (x,y,z)$(x, y, z)$? It can be easily proved that it is always possible to convert any tuple of non-negative integers to any other. -----Input----- - The first line of the input contains a single integer T$T$ denoting the number of test cases. The description of T$T$ test cases follows. - The first and only line of each test case contains six space-separated integers a0$a_0$, b0$b_0$, c0$c_0$, x$x$, y$y$ and z$z$. -----Output----- For each test case, print a single line containing one integer ― the minimum cost. -----Constraints----- - 1≤T≤105$1 \le T \le 10^5$ - 0≤a0,b0,c0,x,y,z≤1018$0 \le a_0, b_0, c_0, x, y, z \le 10^{18}$ -----Subtasks----- Subtask #1 (20 points): 0≤a0,b0,c0,x,y,z≤100$0 \le a_0, b_0, c_0, x, y, z \le 100$ Subtask #2 (80 points): original constraints -----Example Input----- 2 1 1 1 2 2 2 1 2 3 2 4 2 -----Example Output----- 0 1 -----Explanation----- Example case 1: The tuple (1,1,1)$(1, 1, 1)$ can be converted to (2,2,2)$(2, 2, 2)$ using only three Split operations, with cost 0$0$: (1,1,1)→(2,0,2)→(1,1,3)→(2,2,2)$(1, 1, 1) \rightarrow (2, 0, 2) \rightarrow (1, 1, 3) \rightarrow (2, 2, 2)$. Example case 2: We can use one addition operation and one Split operation: (1,2,3)→(1,3,3)→(2,4,2)$(1, 2, 3) \rightarrow (1, 3, 3) \rightarrow (2, 4, 2)$.
def ch(a, b, c, d, e, f): d1, d2, d3 = abs(a - d), abs(b - e), abs(c - f) if a + b + c == 0 or d + e + f == 0: print(2) if d1 % 2 == d2 % 2 and d2 % 2 == d3 % 2 else print(1) else: print(0) if (d1 % 2 + d2 % 2 + d3 % 2) % 3 == 0 else print(1) for z in range(int(input())): a, b, c, d, e, f = map(int, input().split()) print(0) if a == d and b == e and c == f else ch(a, b, c, d, e, f)
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER EXPR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
power = [1] def solve(d, m): bit = 0 for i in range(31, -1, -1): bit = i if 1 << i & d: break dp = [] for i in range(35): l = [] for j in range(35): l.append(0) dp.append(l) save = [] for i in range(0, bit + 1): save.append(min(d, power[i + 1] - 1) - power[i] + 1) for i in range(0, bit + 1): dp[1][i] = save[i] ans = 0 for i in range(2, bit + 2): prod = 0 for j in range(0, bit + 1): dp[i][j] = save[j] * prod prod = prod + dp[i - 1][j] for i in range(1, bit + 2): for j in range(0, bit + 1): ans = ans + dp[i][j] print(ans % m) for i in range(31): power.append(power[-1] * 2) for _ in range(int(input())): d, m = list(map(int, input().split())) solve(d, m)
ASSIGN VAR LIST NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR IF BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
t = int(input()) powers_of_two = set(2**n for n in range(100)) def f(d): if d < 4: return 2 * d - 1 if d in powers_of_two: return 2 * f(d - 1) + 1 bpo2b = max(x for x in powers_of_two if x < d) bpov = f(bpo2b - 1) return (bpov + 1) * (d - bpo2b + 2) - 1 for _ in range(t): d, m = [int(x) for x in input().split()] print(f(d) % m)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR RETURN BIN_OP BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
t = int(input()) while t > 0: n, m = input().split() n = int(n) m = int(m) i = 0 j = 0 while pow(2, i) <= n: i = i + 1 i = i - 1 ans = 1 while i > j: x = pow(2, j + 1) - pow(2, j) + 1 ans = ans * x j = j + 1 if pow(2, j) != n: x = n - pow(2, j) + 2 ans = ans * x else: ans = ans * 2 ans = (ans - 1) % m print(ans) t = t - 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
a = [0] * 31 a[0] = 1 for i in range(1, 31): a[i] = a[i - 1] + (a[i - 1] + 1) * 2**i d = [(2**i - 1, a[i - 1], i) for i in range(1, 31)] t = int(input()) for i in range(t): m, n = map(int, input().split()) for j in range(31): if m < d[j][0]: st = d[j - 1][0] base = d[j - 1][1] ans = base + (base + 1) * (m - st) print(ans % n) break
ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
for _ in range(int(input())): d, m = map(int, input().split()) ans = 1 for i in range(30): v = 1 << i if v > d: break ans = ans % m * (min(2 * v - 1, d) - v + 2) % m % m ans -= 1 if ans < 0: ans += m print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
T = int(input()) for _ in range(T): d, m = map(int, input().split()) dp = [0] * 31 dp[1] = 1 dp[0] = 1 bit = int.bit_length(d) for i in range(2, bit + 1): delta = min(d, (1 << i) - 1) - (1 << i - 1) + 1 for j in range(i): dp[i] = (dp[i] + delta * dp[j]) % m ans = sum(dp[1:]) % m print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
import sys def main(): import sys input = sys.stdin.readline t = int(input()) for _ in range(t): d, m = map(int, input().split()) k = 0 d_ = d while d_: d_ //= 2 k += 1 mod = [1] * (k + 1) for i in range(k): mod[i + 1] = mod[i] * 2 % m a = 1 a_ = 1 for i in range(k - 1): a = ((a + 1) * mod[i] + a) % m a_ = a_ * (mod[i] + 1) ans = (a + a_ * (d - 2 ** (k - 1))) % m print(ans) main()
IMPORT FUNC_DEF IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
diff = [ 1, 2, 6, 30, 270, 4590, 151470, 9845550, 1270075950, 326409519150, 167448083323950, 171634285407048750, 351678650799042888750, 1440827432323678715208750, 11804699153027899713705288750, 193419995622362136809061156168750, 6338179836549184861096125026493768750, 415385291947923928241656745861322122568750, 54445796371490233046418674650281074571453768750, 14272693289804307141953423466197932293533748208968750, 7483016092218210387147618435669447724244515314732016968750, 7846518564929894393124088296418962486345141135175754157040968750, 16455349947998422816223361143099916435126171767057238357700938736968750, 69018756563639524810199724759309695003431877873427010129896835849161712968750, 578971362478555590578564702913468141293043681615930678018743766275800587865072968750, 9713528185088384989699735569319787229060054436949379642077594234206388311339895917552968750, 325931930680159813215085467278457656151751249580970683591656616532864564764837677792504613872968750, 21872921935204203083476386587051932254904294121710668174110199005260776140087248465890690144278186992968750, 2935733908737393289118998032840171152315103469364055477401647506224160426299896350950582393407700602433604592968750, 788055073422318460553391364327552351229921407801025731449664420886192848475127496020051969190549898533439961070865392968750, ] t = int(input()) while t > 0: t -= 1 d, m = map(int, input().split()) diff_mod = [] for elm in diff: diff_mod.append(elm % m) now = 1 cnt = 0 add = 0 tmp = d while tmp > 0: tmp -= now if tmp < 0: tmp += now break add += diff_mod[cnt] * now % m add %= m now *= 2 cnt += 1 add += diff_mod[cnt] * tmp % m print(add % m)
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
def solve(): d, m = map(int, input().split()) res = 1 % m pw2 = 1 for _ in range(1, 31): np = pw2 * 2 if np > d: res = res * (d + 1 - pw2 + 1) % m break else: res = res * (np - pw2 + 1) % m pw2 = np return (res - 1 + m) % m t = int(input()) for _ in range(t): print(solve())
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
t = int(input()) while t: t -= 1 n, m = [int(i) for i in input().split()] i = 1 ans = [] while i < n + 1: if n - i >= i - 1: ans.append(i) else: ans.append(n - i + 1) i *= 2 p = 1 for i in ans: p *= i + 1 print((p - 1) % m)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
import sys for _ in range(int(sys.stdin.readline())): d, m = map(int, sys.stdin.readline().split()) i = 0 while 1 << i <= d: i += 1 prod = 1 for j in range(i - 1): prod *= (1 << j) + 1 prod %= m prod *= d + 2 - (1 << i - 1) prod %= m print((prod - 1) % m)
IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
def kr(a, md): ans = 1 for i in a: ans *= i ans %= mod return ans for t in range(int(input())): num, mod = map(int, input().split()) a = [1] * 31 step = 1 hod = 0 while num > 0: if num > step: a[hod] += step num -= step else: a[hod] += num num = 0 hod += 1 step *= 2 print((kr(a, mod) - 1) % mod)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
def func(a): b = 1 c = 1 d = 1 for i in range(1, a + 1): c = 2 * b + 1 d = 2**i - 1 if i != a: b = c + (b + 1) * d return b, c for _ in range(int(input())): d, m = list(map(int, input().split())) s = 1 while 1 > 0: if 2**s > d: break s = s + 1 s = s - 1 b, c = func(s) print(((d - 2**s) * (b + 1) + c) % m)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE NUMBER NUMBER IF BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
for _ in range(int(input())): d, m = list(map(lambda x: int(x), input().split())) p = 1 ans = 1 while True: if p * 2 <= d: ans = ans * (1 + p) p = p * 2 else: ans = ans * (1 + d - p + 1) break ans %= m print((ans - 1 + m) % m)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
for _ in range(int(input())): d, m = map(int, input().split()) power2 = 1 total = 1 while 2 * power2 + 1 <= d: total = (total + (power2 + 1) % m * ((total + 1) % m) % m) % m power2 = power2 * 2 + 1 total = (total + (d - power2) * ((total + 1) % m) % m) % m print(total)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
import sys def main(): import sys input = sys.stdin.readline for _ in range(int(input())): d, mod = map(int, input().split()) LV = d.bit_length() ans = 0 for lv in range(1, LV): new = (ans + 1) * (1 << lv - 1) % mod ans += new ans %= mod n = d - (1 << LV - 1) + 1 new = (ans + 1) * n % mod ans += new ans %= mod print(ans) main()
IMPORT FUNC_DEF IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
for _ in range(int(input())): n, m = map(int, input().split()) ans = 1 power = 1 while power * 2 + 1 <= n: ans = ((ans + power + 1) % m + ans * (power + 1) % m) % m power = power * 2 + 1 ans = ((ans + n - power - 1 + 1) % m + ans * (n - power - 1 + 1) % m) % m print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
def calc(d, n, m, max_n): f = [([0] * max_n) for i in range(n)] for i in range(max_n - 1): f[0][i] = 2 ** (i + 1) - 2**i f[0][max_n - 1] = d - 2 ** (max_n - 1) + 1 for i in range(1, n): k = 0 for j in range(0, max_n - 1): f[i][j] = k * 2**j % m k = (k + f[i - 1][j]) % m f[i][max_n - 1] = k * f[0][max_n - 1] return sum(f[n - 1]) % m def solve(d, m): max_n = 1 while 2**max_n <= d: max_n += 1 res = 0 for n in range(1, max_n + 1): res = (res + calc(d, n, m, max_n)) % m return res def main(): T = int(input()) for _ in range(T): d, m = [int(x) for x in input().split()] print(solve(d, m)) main()
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
t = int(input()) while t: t -= 1 n, m = map(int, input().split()) x = bin(n)[2:] r = 1 for i in range(len(x)): x = min(2 ** (i + 1) - 1, n) - 2**i + 2 r = r * x print((r - 1) % m)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
import sys def RL(): return map(int, sys.stdin.readline().rstrip().split()) def N(): return int(input()) for _ in range(N()): d, m = RL() bl = d.bit_length() sm = 1 res = [1] lst = d - ((1 << bl - 1) - 1) for i in range(2, bl + 1): num = (1 << i) - (1 << i - 1) if i == bl: num = lst res.append(num * res[-1] + res[-1] + num) print(res[-1] % m)
IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
t = int(input()) for _ in range(t): d, m = list(map(int, input().split())) a = 1 sz = len(bin(d)) - 2 for l in range(sz): a += a * (d + 1 - (1 << l) if l == sz - 1 else 1 << l) print((a - 1) % m)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
e = [(1 << i) for i in range(0, 31)] for i in range(int(input())): d, m = map(int, input().split()) x = {(0): 1, (1): 3} if 1 == d: print(1 % m) continue if 2 == d: print(3 % m) continue j = 1 s = 3 p = 2 while d >= e[j + 1]: s = abs(p) * (e[j] - 1) + x[j] p = s s = s + s + 1 p = s - p x[j + 1] = s j += 1 if d - e[j] != 0: d = d - e[j] s = s + abs(p) * d s = s % m print(s % m)
ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER IF NUMBER VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR IF NUMBER VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
t = int(input()) for _ in range(t): d, m = map(int, input().split()) l = len(bin(d)) - 2 f = 0 for i in range(2, l + 1): f = (2 ** (i - 2) + f * (1 + 2 ** (i - 2))) % m ans = d - 2 ** (l - 1) + 1 + f * (d - 2 ** (l - 1) + 2) ans %= m print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
t = int(input()) for q in range(t): n, m = map(int, input().split()) st = 1 ans = 1 while st <= n: ans *= min(st * 2 - st + 1, n - st + 2) st *= 2 print((ans - 1) % m)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
for _ in range(int(input())): d, mod = map(int, input().split()) s = 0 ind = [] for i in range(41): if s + (1 << i) < d: s += 1 << i ind.append(1 << i) else: ind.append(d - s) break def vie(roots, n): coeff = [0] * (n + 1) coeff[n] = 1 for i in range(1, n + 1): for j in range(n - i - 1, n): coeff[j] += -1 * roots[i - 1] * coeff[j + 1] coeff = coeff[::-1] return coeff an = 0 ans = vie(ind, len(ind)) for i in range(1, len(ans)): an += abs(ans[i] // ans[0]) an %= mod print(an)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
import sys input = sys.stdin.readline Q = int(input()) Query = [list(map(int, input().split())) for _ in range(Q)] for D, mod in Query: L = D.bit_length() A = [] for i in range(L - 1): A.append(1 << i) A.append(D - (1 << L - 1) + 1) ans = 1 for a in A: ans = ans * (a + 1) % mod print((ans - 1) % mod)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
import sys from itertools import accumulate def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [([c] * b) for i in range(a)] def list3d(a, b, c, d): return [[([d] * c) for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[([e] * d) for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") INF = 10**18 MOD = 10**9 + 7 for _ in range(INT()): D, MOD = MAP() N = D.bit_length() bitln = [0] * (N + 1) for i in range(1, N + 1): if D >= 2**i: bitln[i] = 2 ** (i - 1) else: need = D - 2 ** (i - 1) + 1 bitln[i] = need break dp = list2d(N + 1, N + 1, 0) dp[0][0] = 1 for i in range(N): for j in range(N + 1): for k in range(j + 1, N + 1): dp[i + 1][k] += dp[i][j] * bitln[k] dp[i + 1][k] %= MOD ans = 0 for i in range(1, N + 1): ans += sum(dp[i]) ans %= MOD print(ans)
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF NONE RETURN VAR NONE FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP NUMBER VAR ASSIGN VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
t = int(input()) while t: d, m = map(int, input().split()) power = [1] for i in range(50): power.append(power[-1] * 2 % m) ans = 1 for i in range(1, 32): if d >= 2**i: ans *= power[i - 1] + 1 ans %= m else: ans *= d - power[i - 1] + 2 ans %= m break print((ans - 1) % m) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR BIN_OP NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
from sys import gettrace, stdin if not gettrace(): def input(): return next(stdin)[:-1] def modInt(mod): class ModInt: def __init__(self, value): self.value = value % mod def __int__(self): return self.value def __eq__(self, other): return self.value == other.value def __hash__(self): return hash(self.value) def __add__(self, other): return ModInt(self.value + int(other)) def __sub__(self, other): return ModInt(self.value - int(other)) def __mul__(self, other): return ModInt(self.value * int(other)) def __floordiv__(self, other): return ModInt(self.value // int(other)) def __truediv__(self, other): return ModInt(self.value * pow(int(other), mod - 2, mod)) def __repr__(self): return repr(self.value) return ModInt def main(): def solve(): d, m = map(int, input().split()) ModInt = modInt(m) v = 1 res = ModInt(1) while v <= d // 2: res *= v + 1 v *= 2 res = res * (d - v + 2) - 1 print(int(res)) q = int(input()) for _ in range(q): solve() main()
IF FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR VAR FUNC_DEF RETURN VAR FUNC_DEF RETURN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF RETURN FUNC_CALL VAR VAR RETURN VAR FUNC_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
def msb(x): return len(bin(x)) - 2 def solve(): d, mod = map(int, input().split()) way = 1 for i in range(msb(d) - 1): way += way * (1 << i) way += way * (d + 1 - (1 << msb(d) - 1)) print((way - 1) % mod) for _ in range(int(input())): solve()
FUNC_DEF RETURN BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
t = int(input()) maxd = 32 for case_num in range(t): d, m = map(int, input().split(" ")) cnt = [0] * maxd num = 2 i = 1 while num - 1 <= d: cnt[i] = num // 2 num *= 2 i += 1 cnt[i] = d - num // 2 + 1 ans = 1 for l in range(1, maxd): ans = ans * (cnt[l] + 1) % m ans = (ans - 1 + m) % m print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
def log(x): p = 0 v = 1 while v <= x: p += 1 v *= 2 return p ans = [] def ps(arr, m): n = len(arr) ans = 1 for i in range(0, n): ans = ans * ((arr[i] + 1) % m) % m return ans - 1 for _ in range(int(input())): [d, m] = [int(i) for i in input().split()] s = log(d) pt = 0 vals = [(0) for i in range(s)] while pt < s - 1: vals[pt] = pow(2, pt, m) pt += 1 vals[s - 1] = d - pow(2, s - 1, m) + 1 a = ps(vals, m) if a >= 0: ans.append(str(a)) else: ans.append(str(m + a)) print("\n".join(ans))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR LIST FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR RETURN BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham. You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one. ------ 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 two space-separated integers $N$ and $K$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$. ------ Output ------ For each test case, print a single line containing one integer ― the smallest possible value of $X$. ------ Constraints ------ $1 ≤ T ≤ 1,000$ $1 ≤ N ≤ 10^{5}$ $1 ≤ K ≤ 30$ $1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$ the sum of $N$ over all test cases does not exceed $10^{5}$ ------ Subtasks ------ Subtask #1 (50 points): $K ≤ 2$ Subtask #2 (50 points): original constraints ----- Sample Input 1 ------ 1 4 1 3 4 5 1 ----- Sample Output 1 ------ 4 ----- explanation 1 ------ Example case 1: Exactly one bit in $X$ should be $1$. Our options are: - If $X = 1$, $S = 1+0+1+1 = 3$. - If $X = 2$, $S = 2+0+0+0 = 2$. - If $X = 4$, $S = 0+4+4+0 = 8$. - For any greater valid $X$, $S = 0$. The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
for _ in range(int(input())): n, k = map(int, input().split()) arr = list(map(int, input().split())) set_bits = [0] * 30 for i in arr: x = bin(i)[2:] x = x[::-1] for j in range(len(x)): if x[j] == "1": set_bits[j] += 1 dct = {} for i in range(30): cal = set_bits[i] * 2**i set_bits[i] = [i, cal] if cal in dct: dct[cal].append(i) else: dct[cal] = [i] set_bits.sort(key=lambda y: y[1], reverse=True) ans = 0 chc = list(range(30)) l = 0 for i in range(k): if set_bits[i][1] == 0: ans += 2 ** chc[l] l += 1 else: mn = min(dct[set_bits[i][1]]) ans += 2**mn chc.remove(mn) dct[set_bits[i][1]].remove(mn) print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR LIST VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham. You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one. ------ 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 two space-separated integers $N$ and $K$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$. ------ Output ------ For each test case, print a single line containing one integer ― the smallest possible value of $X$. ------ Constraints ------ $1 ≤ T ≤ 1,000$ $1 ≤ N ≤ 10^{5}$ $1 ≤ K ≤ 30$ $1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$ the sum of $N$ over all test cases does not exceed $10^{5}$ ------ Subtasks ------ Subtask #1 (50 points): $K ≤ 2$ Subtask #2 (50 points): original constraints ----- Sample Input 1 ------ 1 4 1 3 4 5 1 ----- Sample Output 1 ------ 4 ----- explanation 1 ------ Example case 1: Exactly one bit in $X$ should be $1$. Our options are: - If $X = 1$, $S = 1+0+1+1 = 3$. - If $X = 2$, $S = 2+0+0+0 = 2$. - If $X = 4$, $S = 0+4+4+0 = 8$. - For any greater valid $X$, $S = 0$. The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
class SlotInfo: pos = 0 count = 0 unitValue = 0 totalValue = 0 def __repr__(self): return repr(self.__dict__) def debug(*args, **kwargs): pass def main(): noOfTests = int(input()) for i in range(noOfTests): print(runATest(i)) def runATest(_testIndex): [aCount, oneBitCount] = [int(x) for x in input().split()] if aCount == 0 or oneBitCount == 0: return 0 aList = [int(x) for x in input().split()] maxA = max(aList) maxABinStr = "{0:0b}".format(maxA) bitscape = len(maxABinStr) debug(maxA=maxA, maxABinStr=maxABinStr, bitscape=bitscape, oneBitCount=oneBitCount) if bitscape <= oneBitCount: return int("1" * oneBitCount, 2) slotInfoList = [] for i in range(bitscape): slotInfo = SlotInfo() slotInfo.pos = i slotInfo.unitValue = 2**i slotInfoList.append(slotInfo) for i in aList: iStr = "{0:0b}".format(i) for j in range(len(iStr)): value = iStr[-1 - j] if value == "1": slotInfo = slotInfoList[j] slotInfo.count += 1 for slotInfo in slotInfoList: slotInfo.totalValue = ( slotInfo.unitValue * slotInfo.count + (99 - slotInfo.pos) / 100 ) slotInfoList.sort(key=lambda x: x.totalValue, reverse=True) debug(slotInfoList) xList = ["0"] * bitscape for i in range(oneBitCount): slotInfo = slotInfoList[i] xList[bitscape - slotInfoList[i].pos - 1] = "1" debug(xList) output = int("".join(xList), 2) return output main()
CLASS_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR RETURN FUNC_CALL VAR BIN_OP STRING VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VAR IF VAR STRING ASSIGN VAR VAR VAR VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham. You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one. ------ 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 two space-separated integers $N$ and $K$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$. ------ Output ------ For each test case, print a single line containing one integer ― the smallest possible value of $X$. ------ Constraints ------ $1 ≤ T ≤ 1,000$ $1 ≤ N ≤ 10^{5}$ $1 ≤ K ≤ 30$ $1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$ the sum of $N$ over all test cases does not exceed $10^{5}$ ------ Subtasks ------ Subtask #1 (50 points): $K ≤ 2$ Subtask #2 (50 points): original constraints ----- Sample Input 1 ------ 1 4 1 3 4 5 1 ----- Sample Output 1 ------ 4 ----- explanation 1 ------ Example case 1: Exactly one bit in $X$ should be $1$. Our options are: - If $X = 1$, $S = 1+0+1+1 = 3$. - If $X = 2$, $S = 2+0+0+0 = 2$. - If $X = 4$, $S = 0+4+4+0 = 8$. - For any greater valid $X$, $S = 0$. The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
for _ in range(int(input())): n, k = map(int, input().split()) count = [0] * 30 ar = list(map(int, input().split())) for elm in ar: for i in range(30): if elm & 1 << i > 0: count[i] += 1 val = [] for i in range(30): val.append((-count[i] * (1 << i), i)) val.sort() ans = 0 for i in range(k): ans = ans | 1 << val[i][1] print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham. You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one. ------ 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 two space-separated integers $N$ and $K$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$. ------ Output ------ For each test case, print a single line containing one integer ― the smallest possible value of $X$. ------ Constraints ------ $1 ≤ T ≤ 1,000$ $1 ≤ N ≤ 10^{5}$ $1 ≤ K ≤ 30$ $1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$ the sum of $N$ over all test cases does not exceed $10^{5}$ ------ Subtasks ------ Subtask #1 (50 points): $K ≤ 2$ Subtask #2 (50 points): original constraints ----- Sample Input 1 ------ 1 4 1 3 4 5 1 ----- Sample Output 1 ------ 4 ----- explanation 1 ------ Example case 1: Exactly one bit in $X$ should be $1$. Our options are: - If $X = 1$, $S = 1+0+1+1 = 3$. - If $X = 2$, $S = 2+0+0+0 = 2$. - If $X = 4$, $S = 0+4+4+0 = 8$. - For any greater valid $X$, $S = 0$. The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
for test in range(int(input())): n, k = map(int, input().split()) a = [0] * 30 for A in input().split(): A = int(A) for i in range(30): if 1 << i & A: a[i] += 1 << i ans = 0 for i in sorted(list(range(30)), key=lambda i: (-a[i], i))[:k]: ans |= 1 << i print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham. You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one. ------ 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 two space-separated integers $N$ and $K$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$. ------ Output ------ For each test case, print a single line containing one integer ― the smallest possible value of $X$. ------ Constraints ------ $1 ≤ T ≤ 1,000$ $1 ≤ N ≤ 10^{5}$ $1 ≤ K ≤ 30$ $1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$ the sum of $N$ over all test cases does not exceed $10^{5}$ ------ Subtasks ------ Subtask #1 (50 points): $K ≤ 2$ Subtask #2 (50 points): original constraints ----- Sample Input 1 ------ 1 4 1 3 4 5 1 ----- Sample Output 1 ------ 4 ----- explanation 1 ------ Example case 1: Exactly one bit in $X$ should be $1$. Our options are: - If $X = 1$, $S = 1+0+1+1 = 3$. - If $X = 2$, $S = 2+0+0+0 = 2$. - If $X = 4$, $S = 0+4+4+0 = 8$. - For any greater valid $X$, $S = 0$. The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
t = int(input()) for _ in range(t): n, k = map(int, input().split()) l = list(map(int, input().split())) d = {} for j in range(30): c = 0 t = 1 << j for i in l: if i & t: c += 1 d[j] = c * 2**j sd = sorted(d.items(), key=lambda x: x[1], reverse=True) ans = 0 for i in range(k): ans += 2 ** sd[i][0] print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham. You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one. ------ 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 two space-separated integers $N$ and $K$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$. ------ Output ------ For each test case, print a single line containing one integer ― the smallest possible value of $X$. ------ Constraints ------ $1 ≤ T ≤ 1,000$ $1 ≤ N ≤ 10^{5}$ $1 ≤ K ≤ 30$ $1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$ the sum of $N$ over all test cases does not exceed $10^{5}$ ------ Subtasks ------ Subtask #1 (50 points): $K ≤ 2$ Subtask #2 (50 points): original constraints ----- Sample Input 1 ------ 1 4 1 3 4 5 1 ----- Sample Output 1 ------ 4 ----- explanation 1 ------ Example case 1: Exactly one bit in $X$ should be $1$. Our options are: - If $X = 1$, $S = 1+0+1+1 = 3$. - If $X = 2$, $S = 2+0+0+0 = 2$. - If $X = 4$, $S = 0+4+4+0 = 8$. - For any greater valid $X$, $S = 0$. The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
for _ in range(int(input())): values = [[0, 2**i] for i in range(30)] n, k = map(int, input().split()) arr = list(map(int, input().split())) for a in arr: for value in values: value[0] += value[1] & a values.sort(key=lambda x: x[0], reverse=True) ans = 0 for i in range(k): ans = ans | values[i][1] print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR FOR VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham. You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one. ------ 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 two space-separated integers $N$ and $K$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$. ------ Output ------ For each test case, print a single line containing one integer ― the smallest possible value of $X$. ------ Constraints ------ $1 ≤ T ≤ 1,000$ $1 ≤ N ≤ 10^{5}$ $1 ≤ K ≤ 30$ $1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$ the sum of $N$ over all test cases does not exceed $10^{5}$ ------ Subtasks ------ Subtask #1 (50 points): $K ≤ 2$ Subtask #2 (50 points): original constraints ----- Sample Input 1 ------ 1 4 1 3 4 5 1 ----- Sample Output 1 ------ 4 ----- explanation 1 ------ Example case 1: Exactly one bit in $X$ should be $1$. Our options are: - If $X = 1$, $S = 1+0+1+1 = 3$. - If $X = 2$, $S = 2+0+0+0 = 2$. - If $X = 4$, $S = 0+4+4+0 = 8$. - For any greater valid $X$, $S = 0$. The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
t = int(input()) while t: s = input().split() n, k = int(s[0]), int(s[1]) a = input().split() for i in range(n): a[i] = int(a[i]) count = [] for i in range(31): count.append(0) for i in a: bit = 0 while i != 0: if i % 2 == 1: count[bit] += 1 i = i // 2 bit += 1 contribution = dict() for i in range(31): contribution[i] = count[i] * 2**i contribution = sorted(contribution.items(), key=lambda x: x[1], reverse=True) x = 0 for i in range(k): x += 2 ** contribution[i][0] print(x) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham. You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one. ------ 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 two space-separated integers $N$ and $K$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$. ------ Output ------ For each test case, print a single line containing one integer ― the smallest possible value of $X$. ------ Constraints ------ $1 ≤ T ≤ 1,000$ $1 ≤ N ≤ 10^{5}$ $1 ≤ K ≤ 30$ $1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$ the sum of $N$ over all test cases does not exceed $10^{5}$ ------ Subtasks ------ Subtask #1 (50 points): $K ≤ 2$ Subtask #2 (50 points): original constraints ----- Sample Input 1 ------ 1 4 1 3 4 5 1 ----- Sample Output 1 ------ 4 ----- explanation 1 ------ Example case 1: Exactly one bit in $X$ should be $1$. Our options are: - If $X = 1$, $S = 1+0+1+1 = 3$. - If $X = 2$, $S = 2+0+0+0 = 2$. - If $X = 4$, $S = 0+4+4+0 = 8$. - For any greater valid $X$, $S = 0$. The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
t = int(input()) while t > 0: n, k = map(int, input().split()) arr = [int(x) for x in input().split()] brep = [] length = 30 for ele in arr: brep.append("0" * (length - len(bin(ele)[2:])) + bin(ele)[2:]) dic = dict() for i in range(0, length): count = 0 for ele in brep: if ele[length - i - 1] == "1": count += 1 dic[i] = count * pow(2, i) dic = sorted(dic.items(), key=lambda kv: (-kv[1], kv[0])) print(sum(pow(2, ele[0]) for ele in dic[:k])) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER STRING VAR NUMBER ASSIGN VAR VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham. You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one. ------ 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 two space-separated integers $N$ and $K$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$. ------ Output ------ For each test case, print a single line containing one integer ― the smallest possible value of $X$. ------ Constraints ------ $1 ≤ T ≤ 1,000$ $1 ≤ N ≤ 10^{5}$ $1 ≤ K ≤ 30$ $1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$ the sum of $N$ over all test cases does not exceed $10^{5}$ ------ Subtasks ------ Subtask #1 (50 points): $K ≤ 2$ Subtask #2 (50 points): original constraints ----- Sample Input 1 ------ 1 4 1 3 4 5 1 ----- Sample Output 1 ------ 4 ----- explanation 1 ------ Example case 1: Exactly one bit in $X$ should be $1$. Our options are: - If $X = 1$, $S = 1+0+1+1 = 3$. - If $X = 2$, $S = 2+0+0+0 = 2$. - If $X = 4$, $S = 0+4+4+0 = 8$. - For any greater valid $X$, $S = 0$. The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
t = int(input()) while t > 0: n, k = list(map(int, input().split())) a = list(map(int, input().split())) d = [0] * 35 for i in range(n): c = a[i] i = 0 while c > 0: e = c % 2 z = e * pow(2, i) d[i] += z c = c // 2 i += 1 sum1 = 0 for i in range(k): max1 = -1 z = 0 for j in range(30): if d[j] > max1: max1 = d[j] z = j sum1 += pow(2, z) d[z] = -1 print(sum1) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham. You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one. ------ 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 two space-separated integers $N$ and $K$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$. ------ Output ------ For each test case, print a single line containing one integer ― the smallest possible value of $X$. ------ Constraints ------ $1 ≤ T ≤ 1,000$ $1 ≤ N ≤ 10^{5}$ $1 ≤ K ≤ 30$ $1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$ the sum of $N$ over all test cases does not exceed $10^{5}$ ------ Subtasks ------ Subtask #1 (50 points): $K ≤ 2$ Subtask #2 (50 points): original constraints ----- Sample Input 1 ------ 1 4 1 3 4 5 1 ----- Sample Output 1 ------ 4 ----- explanation 1 ------ Example case 1: Exactly one bit in $X$ should be $1$. Our options are: - If $X = 1$, $S = 1+0+1+1 = 3$. - If $X = 2$, $S = 2+0+0+0 = 2$. - If $X = 4$, $S = 0+4+4+0 = 8$. - For any greater valid $X$, $S = 0$. The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
for _ in range(int(input())): n, k = list(map(int, input().split())) l = list(map(int, input().split())) l1 = [0] * 32 for t in l: for i in range(32): if t % 2 == 1: l1[i] += 2**i t = t // 2 if t == 0: break l2 = l1[:] l2.sort() l3 = l2[32 - k :] ans = 0 for i in l3: a = l1.index(i) ans += 2**a l1[a] = -1 print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham. You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one. ------ 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 two space-separated integers $N$ and $K$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$. ------ Output ------ For each test case, print a single line containing one integer ― the smallest possible value of $X$. ------ Constraints ------ $1 ≤ T ≤ 1,000$ $1 ≤ N ≤ 10^{5}$ $1 ≤ K ≤ 30$ $1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$ the sum of $N$ over all test cases does not exceed $10^{5}$ ------ Subtasks ------ Subtask #1 (50 points): $K ≤ 2$ Subtask #2 (50 points): original constraints ----- Sample Input 1 ------ 1 4 1 3 4 5 1 ----- Sample Output 1 ------ 4 ----- explanation 1 ------ Example case 1: Exactly one bit in $X$ should be $1$. Our options are: - If $X = 1$, $S = 1+0+1+1 = 3$. - If $X = 2$, $S = 2+0+0+0 = 2$. - If $X = 4$, $S = 0+4+4+0 = 8$. - For any greater valid $X$, $S = 0$. The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
def decimalToBinary(n): return bin(n).replace("0b", "") for _ in range(int(input())): N, K = map(int, input().split()) array = list(map(int, input().split())) for j in range(0, len(array)): ans = decimalToBinary(array[j]) array[j] = "0" * (30 - len(ans)) + ans lookup = {} for i in range(30): if i not in lookup: lookup[i] = 0 for i in range(len(array)): for j in range(len(array[i])): if array[i][j] == "1": lookup[29 - j] += 1 answer = list(lookup.values()) for j in range(len(answer)): answer[j] = [answer[j] * 2**j, j] answer.sort(key=lambda x: x[0], reverse=True) ans = answer[:K] total = 0 for i in range(len(ans)): total += 2 ** ans[i][1] print(total)
FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR VAR STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP STRING BIN_OP NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR STRING VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST BIN_OP VAR VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham. You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one. ------ 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 two space-separated integers $N$ and $K$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$. ------ Output ------ For each test case, print a single line containing one integer ― the smallest possible value of $X$. ------ Constraints ------ $1 ≤ T ≤ 1,000$ $1 ≤ N ≤ 10^{5}$ $1 ≤ K ≤ 30$ $1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$ the sum of $N$ over all test cases does not exceed $10^{5}$ ------ Subtasks ------ Subtask #1 (50 points): $K ≤ 2$ Subtask #2 (50 points): original constraints ----- Sample Input 1 ------ 1 4 1 3 4 5 1 ----- Sample Output 1 ------ 4 ----- explanation 1 ------ Example case 1: Exactly one bit in $X$ should be $1$. Our options are: - If $X = 1$, $S = 1+0+1+1 = 3$. - If $X = 2$, $S = 2+0+0+0 = 2$. - If $X = 4$, $S = 0+4+4+0 = 8$. - For any greater valid $X$, $S = 0$. The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
t = int(input()) while t != 0: t = t - 1 n, k = map(int, input().split()) a = list(map(int, input().split())) a1 = [0] * 30 for i in a: s1 = bin(i) n1 = len(s1) for j in range(n1 - 1, 1, -1): a1[n1 - 1 - j] = a1[n1 - 1 - j] + int(s1[j]) flag = 1 for i in range(30): a1[i] = a1[i] * flag flag = flag * 2 a2 = list() for i in range(30): a3 = list() a3.append(a1[i]) a3.append(i) a2.append(a3) a2.sort(key=lambda ff: (-ff[0], ff[1])) sum1 = 0 for i in range(k): sum1 = sum1 + pow(2, a2[i][1]) print(sum1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham. You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one. ------ 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 two space-separated integers $N$ and $K$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$. ------ Output ------ For each test case, print a single line containing one integer ― the smallest possible value of $X$. ------ Constraints ------ $1 ≤ T ≤ 1,000$ $1 ≤ N ≤ 10^{5}$ $1 ≤ K ≤ 30$ $1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$ the sum of $N$ over all test cases does not exceed $10^{5}$ ------ Subtasks ------ Subtask #1 (50 points): $K ≤ 2$ Subtask #2 (50 points): original constraints ----- Sample Input 1 ------ 1 4 1 3 4 5 1 ----- Sample Output 1 ------ 4 ----- explanation 1 ------ Example case 1: Exactly one bit in $X$ should be $1$. Our options are: - If $X = 1$, $S = 1+0+1+1 = 3$. - If $X = 2$, $S = 2+0+0+0 = 2$. - If $X = 4$, $S = 0+4+4+0 = 8$. - For any greater valid $X$, $S = 0$. The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
try: t = int(input()) for _ in range(t): n, z = map(int, input().split()) l = [int(a) for a in input().split()] b = [bin(c)[2:] for c in l] m = max(len(i) for i in b) final_sum = [] for j in range(m): k = sum(2**j & i for i in l) final_sum.append((-k, j)) final_sum.sort() h = len(final_sum) for i in range(h, 32): final_sum.append((0, i)) ans = 0 for i in range(z): ans += 2 ** final_sum[i][1] print(ans) except: pass
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham. You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one. ------ 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 two space-separated integers $N$ and $K$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$. ------ Output ------ For each test case, print a single line containing one integer ― the smallest possible value of $X$. ------ Constraints ------ $1 ≤ T ≤ 1,000$ $1 ≤ N ≤ 10^{5}$ $1 ≤ K ≤ 30$ $1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$ the sum of $N$ over all test cases does not exceed $10^{5}$ ------ Subtasks ------ Subtask #1 (50 points): $K ≤ 2$ Subtask #2 (50 points): original constraints ----- Sample Input 1 ------ 1 4 1 3 4 5 1 ----- Sample Output 1 ------ 4 ----- explanation 1 ------ Example case 1: Exactly one bit in $X$ should be $1$. Our options are: - If $X = 1$, $S = 1+0+1+1 = 3$. - If $X = 2$, $S = 2+0+0+0 = 2$. - If $X = 4$, $S = 0+4+4+0 = 8$. - For any greater valid $X$, $S = 0$. The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
t = int(input()) def isSet(elem, k): if elem & 1 << k: return 1 return 0 for _ in range(t): n, k = map(int, input().split()) x = list(map(int, input().split())) gem = [0] * 30 kii = [0] * 30 for i in range(len(x)): for j in range(30): if isSet(x[i], j): gem[j] += 1 for i in range(30): kii[i] = gem[i] * 2**i z = [] for i in range(k): r = max(kii) indo = kii.index(r) z.append(indo) kii[indo] = -1 ans = 0 for ele in z: ans += 1 << ele print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF BIN_OP VAR BIN_OP NUMBER VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham. You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one. ------ 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 two space-separated integers $N$ and $K$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$. ------ Output ------ For each test case, print a single line containing one integer ― the smallest possible value of $X$. ------ Constraints ------ $1 ≤ T ≤ 1,000$ $1 ≤ N ≤ 10^{5}$ $1 ≤ K ≤ 30$ $1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$ the sum of $N$ over all test cases does not exceed $10^{5}$ ------ Subtasks ------ Subtask #1 (50 points): $K ≤ 2$ Subtask #2 (50 points): original constraints ----- Sample Input 1 ------ 1 4 1 3 4 5 1 ----- Sample Output 1 ------ 4 ----- explanation 1 ------ Example case 1: Exactly one bit in $X$ should be $1$. Our options are: - If $X = 1$, $S = 1+0+1+1 = 3$. - If $X = 2$, $S = 2+0+0+0 = 2$. - If $X = 4$, $S = 0+4+4+0 = 8$. - For any greater valid $X$, $S = 0$. The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
t = int(input()) for _ in range(t): n, k = map(int, input().split(" ")) arr = list(map(int, input().split(" "))) bit_set = [0] * 30 for i in range(30): for j in arr: if j & 1 << i: bit_set[i] += 1 sum_arr = [] digit_arr = [] for i in range(30): dig = 0 | 1 << i digit_arr.append(dig) sum_arr.append(dig * bit_set[i]) sum_digit = list(zip(sum_arr, digit_arr)) sum_digit.sort(key=lambda x: x[0], reverse=True) x = 0 for i in range(k): x += sum_digit[i][1] print(x)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham. You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one. ------ 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 two space-separated integers $N$ and $K$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$. ------ Output ------ For each test case, print a single line containing one integer ― the smallest possible value of $X$. ------ Constraints ------ $1 ≤ T ≤ 1,000$ $1 ≤ N ≤ 10^{5}$ $1 ≤ K ≤ 30$ $1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$ the sum of $N$ over all test cases does not exceed $10^{5}$ ------ Subtasks ------ Subtask #1 (50 points): $K ≤ 2$ Subtask #2 (50 points): original constraints ----- Sample Input 1 ------ 1 4 1 3 4 5 1 ----- Sample Output 1 ------ 4 ----- explanation 1 ------ Example case 1: Exactly one bit in $X$ should be $1$. Our options are: - If $X = 1$, $S = 1+0+1+1 = 3$. - If $X = 2$, $S = 2+0+0+0 = 2$. - If $X = 4$, $S = 0+4+4+0 = 8$. - For any greater valid $X$, $S = 0$. The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
for _ in range(int(input())): n, k = map(int, input().split()) a = list(map(int, input().split())) c = [0] * 30 for i in range(n): b = bin(a[i]).replace("0b", "") b = b[::-1] for j in range(len(b)): c[j] += int(b[j]) for i in range(30): c[i] = c[i] * 2**i d = [[i, c[i]] for i in range(30)] d = sorted(d, key=lambda x: (x[1], -x[0])) e = [(0) for i in range(30)] for i in range(k): e[d[30 - i - 1][0]] = 1 ans = "".join(str(i) for i in e) ans = ans[::-1] print(int(ans, 2))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR VAR STRING STRING ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR LIST VAR VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham. You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one. ------ 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 two space-separated integers $N$ and $K$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$. ------ Output ------ For each test case, print a single line containing one integer ― the smallest possible value of $X$. ------ Constraints ------ $1 ≤ T ≤ 1,000$ $1 ≤ N ≤ 10^{5}$ $1 ≤ K ≤ 30$ $1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$ the sum of $N$ over all test cases does not exceed $10^{5}$ ------ Subtasks ------ Subtask #1 (50 points): $K ≤ 2$ Subtask #2 (50 points): original constraints ----- Sample Input 1 ------ 1 4 1 3 4 5 1 ----- Sample Output 1 ------ 4 ----- explanation 1 ------ Example case 1: Exactly one bit in $X$ should be $1$. Our options are: - If $X = 1$, $S = 1+0+1+1 = 3$. - If $X = 2$, $S = 2+0+0+0 = 2$. - If $X = 4$, $S = 0+4+4+0 = 8$. - For any greater valid $X$, $S = 0$. The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
def insert(a): for i in range(1, len(a)): key = a[i].copy() j = i - 1 while j >= 0 and a[j][1] >= key[1]: a[j + 1][0] = a[j][0] a[j + 1][1] = a[j][1] j -= 1 a[j + 1][0] = key[0] a[j + 1][1] = key[1] return a for _ in range(int(input())): n, k = map(int, input().split()) a = list(map(int, input().split())) c = [0] * 30 for i in range(n): b = bin(a[i]).replace("0b", "") b = b[::-1] for j in range(len(b)): c[j] += int(b[j]) for i in range(30): c[i] = c[i] * 2**i d = [[i, c[i]] for i in range(30)] d = insert(d) e = [(0) for i in range(30)] for i in range(k): e[d[30 - i - 1][0]] = 1 ans = "".join(str(i) for i in e) ans = ans[::-1] print(int(ans, 2))
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR VAR STRING STRING ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR LIST VAR VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham. You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one. ------ 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 two space-separated integers $N$ and $K$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$. ------ Output ------ For each test case, print a single line containing one integer ― the smallest possible value of $X$. ------ Constraints ------ $1 ≤ T ≤ 1,000$ $1 ≤ N ≤ 10^{5}$ $1 ≤ K ≤ 30$ $1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$ the sum of $N$ over all test cases does not exceed $10^{5}$ ------ Subtasks ------ Subtask #1 (50 points): $K ≤ 2$ Subtask #2 (50 points): original constraints ----- Sample Input 1 ------ 1 4 1 3 4 5 1 ----- Sample Output 1 ------ 4 ----- explanation 1 ------ Example case 1: Exactly one bit in $X$ should be $1$. Our options are: - If $X = 1$, $S = 1+0+1+1 = 3$. - If $X = 2$, $S = 2+0+0+0 = 2$. - If $X = 4$, $S = 0+4+4+0 = 8$. - For any greater valid $X$, $S = 0$. The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
for _ in range(int(input())): n, k = map(int, input().split()) l = list(map(int, input().split())) mask = 1 t = [0] * 30 for j in range(30): for i, x in enumerate(l): if x & mask << j: t[j] += 1 c = 1 for i, x in enumerate(t): t[i] *= c c *= 2 t = sorted(zip(t, range(30)), key=lambda x: (-x[0], x[1])) ans = [0] * 30 for i in range(k): x = t[i][1] ans[x] = 1 ans = ans[::-1] s = "" for i in ans: s += str(i) print(int(s, 2))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham. You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one. ------ 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 two space-separated integers $N$ and $K$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$. ------ Output ------ For each test case, print a single line containing one integer ― the smallest possible value of $X$. ------ Constraints ------ $1 ≤ T ≤ 1,000$ $1 ≤ N ≤ 10^{5}$ $1 ≤ K ≤ 30$ $1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$ the sum of $N$ over all test cases does not exceed $10^{5}$ ------ Subtasks ------ Subtask #1 (50 points): $K ≤ 2$ Subtask #2 (50 points): original constraints ----- Sample Input 1 ------ 1 4 1 3 4 5 1 ----- Sample Output 1 ------ 4 ----- explanation 1 ------ Example case 1: Exactly one bit in $X$ should be $1$. Our options are: - If $X = 1$, $S = 1+0+1+1 = 3$. - If $X = 2$, $S = 2+0+0+0 = 2$. - If $X = 4$, $S = 0+4+4+0 = 8$. - For any greater valid $X$, $S = 0$. The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
for _ in range(int(input())): N, K = [int(i) for i in input().split(" ")] A = [int(i) for i in input().split(" ")] H = max(A) sett = len(str(bin(H))) - 2 tab = [0] * sett for i in range(N): for j in range(1, len(str(bin(A[i]))) - 1): if str(bin(A[i]))[-j] == "1": tab[j - 1] += 1 for i in range(len(tab)): tab[i] *= 2**i D = [] for i in tab: D += [i] Inex = [] tab.sort() TruthTable = [True] * len(D) for i in range(1, K + 1): for j in range(len(D)): if TruthTable[j]: if D[j] == tab[-i]: TruthTable[j] = False Inex += [j] break final = 0 if len(Inex) == K: for i in Inex: final += 2**i elif K > sett: for i in range(K): final += 2**i print(final)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR STRING VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR LIST FOR VAR VAR VAR LIST VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR LIST VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR FOR VAR VAR VAR BIN_OP NUMBER VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham. You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one. ------ 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 two space-separated integers $N$ and $K$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$. ------ Output ------ For each test case, print a single line containing one integer ― the smallest possible value of $X$. ------ Constraints ------ $1 ≤ T ≤ 1,000$ $1 ≤ N ≤ 10^{5}$ $1 ≤ K ≤ 30$ $1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$ the sum of $N$ over all test cases does not exceed $10^{5}$ ------ Subtasks ------ Subtask #1 (50 points): $K ≤ 2$ Subtask #2 (50 points): original constraints ----- Sample Input 1 ------ 1 4 1 3 4 5 1 ----- Sample Output 1 ------ 4 ----- explanation 1 ------ Example case 1: Exactly one bit in $X$ should be $1$. Our options are: - If $X = 1$, $S = 1+0+1+1 = 3$. - If $X = 2$, $S = 2+0+0+0 = 2$. - If $X = 4$, $S = 0+4+4+0 = 8$. - For any greater valid $X$, $S = 0$. The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
for _ in range(int(input())): n, k = map(int, input().split()) arr = list(map(int, input().split())) bins = [] bit = [0] * 30 ans = [0] * 30 w = [i for i in range(29, -1, -1)] for i in range(n): b = bin(arr[i])[2:] bins.append("0" * (30 - len(b)) + b) for i in range(30): count = 0 for j in range(n): if bins[j][i] == "1": count += 1 bit[i] = 2 ** (29 - i) * count x = zip(bit, w) x = sorted(x, key=lambda x: (-x[0], x[1])) i = 0 while k > 0: k -= 1 ans[29 - x[i][1]] = 1 i += 1 ans = "".join(str(i) for i in ans) print(int(ans, 2))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP NUMBER FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham. You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one. ------ 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 two space-separated integers $N$ and $K$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$. ------ Output ------ For each test case, print a single line containing one integer ― the smallest possible value of $X$. ------ Constraints ------ $1 ≤ T ≤ 1,000$ $1 ≤ N ≤ 10^{5}$ $1 ≤ K ≤ 30$ $1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$ the sum of $N$ over all test cases does not exceed $10^{5}$ ------ Subtasks ------ Subtask #1 (50 points): $K ≤ 2$ Subtask #2 (50 points): original constraints ----- Sample Input 1 ------ 1 4 1 3 4 5 1 ----- Sample Output 1 ------ 4 ----- explanation 1 ------ Example case 1: Exactly one bit in $X$ should be $1$. Our options are: - If $X = 1$, $S = 1+0+1+1 = 3$. - If $X = 2$, $S = 2+0+0+0 = 2$. - If $X = 4$, $S = 0+4+4+0 = 8$. - For any greater valid $X$, $S = 0$. The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
for test in range(int(input())): bits = [(0) for i in range(32)] n, k = map(int, input().split()) l = list(map(int, input().split())) for i in l: c = 0 t = i while t: if t & 1: bits[c] += 1 c += 1 t >>= 1 val = [(bits[i] * 2**i) for i in range(32)] dup = [(bits[i] * 2**i) for i in range(32)] dup.sort(reverse=True) b = [(0) for i in range(32)] res = 0 tem = [] for i in dup[:k]: for j in range(32): if i == val[j] and b[j] == 0: b[j] = 1 tem.append(j) for i in tem[:k]: res = res | 1 << i print(res)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham. You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one. ------ 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 two space-separated integers $N$ and $K$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$. ------ Output ------ For each test case, print a single line containing one integer ― the smallest possible value of $X$. ------ Constraints ------ $1 ≤ T ≤ 1,000$ $1 ≤ N ≤ 10^{5}$ $1 ≤ K ≤ 30$ $1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$ the sum of $N$ over all test cases does not exceed $10^{5}$ ------ Subtasks ------ Subtask #1 (50 points): $K ≤ 2$ Subtask #2 (50 points): original constraints ----- Sample Input 1 ------ 1 4 1 3 4 5 1 ----- Sample Output 1 ------ 4 ----- explanation 1 ------ Example case 1: Exactly one bit in $X$ should be $1$. Our options are: - If $X = 1$, $S = 1+0+1+1 = 3$. - If $X = 2$, $S = 2+0+0+0 = 2$. - If $X = 4$, $S = 0+4+4+0 = 8$. - For any greater valid $X$, $S = 0$. The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
def f(n): l = [] while n > 0: l.append(n % 2) n = n // 2 return l t = int(input()) while t > 0: t = t - 1 n, k = map(int, input().split()) a = input() A = list(map(int, list(a.split()))) y = 0 d = [0] * 30 for i in range(n): l = f(A[i]) m = len(l) y = max(y, m) for j in range(m): if l[j] == 1: d[j] = d[j] + 1 val = [((1 << i) * d[i]) for i in range(30)] s = 0 while k > 0: k = k - 1 i = val.index(max(val)) s = s + (1 << i) val[i] = -1 print(s)
FUNC_DEF ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham. You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one. ------ 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 two space-separated integers $N$ and $K$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$. ------ Output ------ For each test case, print a single line containing one integer ― the smallest possible value of $X$. ------ Constraints ------ $1 ≤ T ≤ 1,000$ $1 ≤ N ≤ 10^{5}$ $1 ≤ K ≤ 30$ $1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$ the sum of $N$ over all test cases does not exceed $10^{5}$ ------ Subtasks ------ Subtask #1 (50 points): $K ≤ 2$ Subtask #2 (50 points): original constraints ----- Sample Input 1 ------ 1 4 1 3 4 5 1 ----- Sample Output 1 ------ 4 ----- explanation 1 ------ Example case 1: Exactly one bit in $X$ should be $1$. Our options are: - If $X = 1$, $S = 1+0+1+1 = 3$. - If $X = 2$, $S = 2+0+0+0 = 2$. - If $X = 4$, $S = 0+4+4+0 = 8$. - For any greater valid $X$, $S = 0$. The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
T = int(input()) for _ in range(T): n, k = map(int, input().split()) a = list(map(int, input().split())) l = [] for i in range(31): s = 0 for j in range(n): if a[j] & 1 << i: s += 1 l.append((s * (1 << i), 1 << i)) l.sort(key=lambda x: (-x[0], x[1])) x = l[:k] ans = 0 for i in range(k): ans += x[i][1] print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham. You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one. ------ 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 two space-separated integers $N$ and $K$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$. ------ Output ------ For each test case, print a single line containing one integer ― the smallest possible value of $X$. ------ Constraints ------ $1 ≤ T ≤ 1,000$ $1 ≤ N ≤ 10^{5}$ $1 ≤ K ≤ 30$ $1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$ the sum of $N$ over all test cases does not exceed $10^{5}$ ------ Subtasks ------ Subtask #1 (50 points): $K ≤ 2$ Subtask #2 (50 points): original constraints ----- Sample Input 1 ------ 1 4 1 3 4 5 1 ----- Sample Output 1 ------ 4 ----- explanation 1 ------ Example case 1: Exactly one bit in $X$ should be $1$. Our options are: - If $X = 1$, $S = 1+0+1+1 = 3$. - If $X = 2$, $S = 2+0+0+0 = 2$. - If $X = 4$, $S = 0+4+4+0 = 8$. - For any greater valid $X$, $S = 0$. The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
t = int(input()) for _ in range(t): n, b = map(int, input().split()) arr = list(map(int, input().split())) o = 0 for i in range(n): o |= arr[i] m = {} for k in range(0, 30): m[k] = 0 for i in range(n): s = bin(arr[i])[2:][::-1] for j in range(len(s)): if s[j] == "1": m[j] += 2**j a1 = sorted(zip(m.values(), m.keys()), key=lambda x: (x[0], -x[1]), reverse=True) a2 = a1[::-1] ans1 = 0 for v, p in a1: if b: ans1 += 2**p b -= 1 print(ans1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR